atom.io 0.31.0 → 0.32.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/data/dist/index.d.ts +867 -101
- package/data/dist/index.js +10 -558
- package/data/src/index.ts +0 -2
- package/data/src/struct-family.ts +1 -1
- package/data/src/struct.ts +1 -2
- package/dist/chunk-354XQWHH.js +153 -0
- package/dist/chunk-4LWKCEW3.js +14 -0
- package/dist/chunk-5F2V7S3B.js +83 -0
- package/dist/chunk-ECOMOMUN.js +631 -0
- package/dist/{chunk-42UH5F5Q.js → chunk-GY2XQYZY.js} +2051 -755
- package/dist/chunk-NF7FJKJD.js +107 -0
- package/dist/chunk-R3ZUK5EH.js +1024 -0
- package/dist/chunk-Z2UJW4NQ.js +523 -0
- package/dist/index.d.ts +855 -127
- package/dist/index.js +1 -143
- package/eslint-plugin/dist/index.d.ts +1 -30
- package/eslint-plugin/dist/index.js +0 -146
- package/eslint-plugin/src/index.ts +0 -1
- package/eslint-plugin/src/rules/index.ts +0 -1
- package/internal/dist/index.d.ts +794 -70
- package/internal/dist/index.js +1 -2
- package/internal/src/atom/create-regular-atom.ts +3 -3
- package/internal/src/atom/dispose-atom.ts +4 -13
- package/internal/src/atom/is-default.ts +3 -3
- package/internal/src/caching.ts +5 -5
- package/internal/src/capitalize.ts +3 -0
- package/internal/src/families/create-readonly-selector-family.ts +5 -6
- package/internal/src/families/create-writable-selector-family.ts +1 -4
- package/internal/src/families/dispose-from-store.ts +3 -13
- package/internal/src/families/find-in-store.ts +1 -6
- package/internal/src/get-state/get-from-store.ts +2 -2
- package/internal/src/get-state/read-or-compute-value.ts +1 -1
- package/internal/src/index.ts +19 -9
- package/internal/src/ingest-updates/ingest-creation-disposal.ts +2 -3
- package/internal/src/install-into-store.ts +48 -0
- package/internal/src/join/edit-relations-in-store.ts +32 -0
- package/internal/src/join/find-relations-in-store.ts +124 -0
- package/internal/src/join/get-internal-relations-from-store.ts +14 -0
- package/internal/src/join/get-join.ts +31 -0
- package/internal/src/join/index.ts +5 -0
- package/{data/src/join.ts → internal/src/join/join-internal.ts} +20 -429
- package/internal/src/keys.ts +7 -7
- package/internal/src/molecule.ts +299 -0
- package/internal/src/mutable/create-mutable-atom-family.ts +1 -1
- package/internal/src/mutable/create-mutable-atom.ts +3 -3
- package/internal/src/mutable/get-json-token.ts +1 -1
- package/internal/src/mutable/tracker-family.ts +19 -17
- package/internal/src/mutable/tracker.ts +8 -8
- package/internal/src/not-found-error.ts +8 -30
- package/internal/src/pretty-print.ts +2 -13
- package/internal/src/selector/create-readonly-selector.ts +3 -7
- package/internal/src/selector/create-writable-selector.ts +4 -4
- package/internal/src/selector/dispose-selector.ts +20 -11
- package/internal/src/selector/get-selector-dependency-keys.ts +1 -1
- package/internal/src/selector/register-selector.ts +7 -17
- package/internal/src/selector/trace-selector-atoms.ts +2 -2
- package/internal/src/set-state/copy-mutable-if-needed.ts +1 -1
- package/internal/src/set-state/emit-update.ts +1 -1
- package/internal/src/set-state/evict-downstream.ts +1 -1
- package/internal/src/set-state/set-atom-or-selector.ts +1 -1
- package/internal/src/set-state/set-atom.ts +10 -10
- package/internal/src/set-state/set-into-store.ts +2 -2
- package/internal/src/set-state/stow-update.ts +1 -1
- package/internal/src/store/deposit.ts +10 -8
- package/internal/src/store/store.ts +1 -1
- package/internal/src/store/withdraw.ts +34 -53
- package/internal/src/subscribe/recall-state.ts +1 -1
- package/internal/src/subscribe/subscribe-in-store.ts +3 -3
- package/internal/src/subscribe/subscribe-to-root-atoms.ts +3 -3
- package/internal/src/subscribe/subscribe-to-state.ts +5 -5
- package/internal/src/subscribe/subscribe-to-timeline.ts +3 -3
- package/internal/src/subscribe/subscribe-to-transaction.ts +3 -3
- package/internal/src/timeline/create-timeline.ts +17 -37
- package/internal/src/transaction/act-upon-store.ts +2 -2
- package/internal/src/transaction/apply-transaction.ts +5 -5
- package/internal/src/transaction/assign-transaction-to-continuity.ts +1 -1
- package/internal/src/transaction/build-transaction.ts +5 -8
- package/internal/src/transaction/create-transaction.ts +3 -3
- package/internal/src/transaction/get-epoch-number.ts +3 -3
- package/internal/src/transaction/set-epoch-number.ts +2 -2
- package/introspection/dist/index.d.ts +922 -6
- package/introspection/dist/index.js +2 -620
- package/json/dist/index.d.ts +899 -5
- package/json/dist/index.js +1 -81
- package/json/src/select-json-family.ts +3 -14
- package/package.json +27 -45
- package/react/dist/index.d.ts +921 -3
- package/react/dist/index.js +2 -82
- package/react/src/use-o.ts +1 -1
- package/react/src/use-tl.ts +2 -2
- package/react-devtools/dist/index.css +16 -14
- package/react-devtools/dist/index.d.ts +26 -1
- package/react-devtools/dist/index.js +6 -6
- package/react-devtools/src/devtools.scss +16 -14
- package/realtime/dist/index.d.ts +202 -8
- package/realtime/dist/index.js +2 -107
- package/realtime/src/realtime-continuity.ts +2 -2
- package/realtime/src/shared-room-store.ts +1 -2
- package/realtime-client/dist/index.d.ts +960 -22
- package/realtime-client/dist/index.js +3 -509
- package/realtime-client/src/continuity/register-and-attempt-confirmed-update.ts +3 -3
- package/realtime-client/src/continuity/use-conceal-state.ts +1 -1
- package/realtime-client/src/pull-atom-family-member.ts +2 -2
- package/realtime-client/src/pull-atom.ts +2 -2
- package/realtime-client/src/pull-mutable-atom-family-member.ts +2 -2
- package/realtime-client/src/pull-mutable-atom.ts +2 -2
- package/realtime-client/src/pull-selector-family-member.ts +4 -4
- package/realtime-client/src/pull-selector.ts +4 -4
- package/realtime-client/src/push-state.ts +5 -10
- package/realtime-client/src/server-action.ts +4 -4
- package/realtime-client/src/sync-continuity.ts +6 -6
- package/realtime-react/dist/index.d.ts +166 -12
- package/realtime-react/dist/index.js +5 -154
- package/realtime-react/src/use-pull-atom-family-member.ts +1 -1
- package/realtime-react/src/use-pull-atom.ts +1 -1
- package/realtime-react/src/use-pull-mutable-atom.ts +1 -1
- package/realtime-react/src/use-pull-mutable-family-member.ts +1 -1
- package/realtime-react/src/use-pull-selector-family-member.ts +1 -1
- package/realtime-react/src/use-pull-selector.ts +1 -1
- package/realtime-react/src/use-push.ts +1 -1
- package/realtime-react/src/use-server-action.ts +2 -2
- package/realtime-react/src/use-sync-continuity.ts +1 -1
- package/realtime-server/dist/index.d.ts +971 -28
- package/realtime-server/dist/index.js +3 -1001
- package/realtime-server/src/continuity/prepare-to-serve-transaction-request.ts +1 -1
- package/realtime-server/src/continuity/prepare-to-sync-realtime-continuity.ts +3 -3
- package/realtime-server/src/continuity/subscribe-to-continuity-actions.ts +2 -2
- package/realtime-server/src/continuity/subscribe-to-continuity-perpectives.ts +2 -2
- package/realtime-server/src/ipc-sockets/child-socket.ts +0 -1
- package/realtime-server/src/realtime-action-receiver.ts +1 -1
- package/realtime-server/src/realtime-family-provider.ts +2 -2
- package/realtime-server/src/realtime-mutable-family-provider.ts +2 -2
- package/realtime-server/src/realtime-mutable-provider.ts +2 -2
- package/realtime-server/src/realtime-server-stores/server-room-external-actions.ts +2 -1
- package/realtime-server/src/realtime-server-stores/server-room-external-store.ts +1 -1
- package/realtime-server/src/realtime-server-stores/server-user-store.ts +1 -2
- package/realtime-server/src/realtime-state-provider.ts +2 -2
- package/realtime-testing/dist/index.d.ts +1091 -3
- package/realtime-testing/dist/index.js +23 -26
- package/realtime-testing/src/setup-realtime-test.tsx +6 -5
- package/src/atom.ts +53 -29
- package/src/dispose-state.ts +12 -2
- package/{ephemeral/src → src}/find-state.ts +35 -25
- package/src/get-state.ts +16 -0
- package/src/index.ts +77 -3
- package/src/join.ts +218 -0
- package/src/realm.ts +169 -0
- package/src/selector.ts +20 -0
- package/src/set-state.ts +16 -8
- package/src/silo.ts +13 -7
- package/src/timeline.ts +1 -1
- package/src/transaction.ts +4 -8
- package/transceivers/set-rtx/dist/index.d.ts +37 -2
- package/transceivers/set-rtx/dist/index.js +1 -212
- package/transceivers/set-rtx/src/set-rtx.ts +4 -1
- package/web/dist/index.d.ts +30 -1
- package/web/dist/index.js +1 -15
- package/data/src/until.ts +0 -15
- package/dist/chunk-ICGFFQ3H.js +0 -272
- package/ephemeral/dist/index.d.ts +0 -57
- package/ephemeral/dist/index.js +0 -9
- package/ephemeral/package.json +0 -13
- package/ephemeral/src/index.ts +0 -1
- package/eslint-plugin/src/rules/lifespan.ts +0 -203
- package/immortal/dist/index.d.ts +0 -12
- package/immortal/dist/index.js +0 -9
- package/immortal/package.json +0 -13
- package/immortal/src/index.ts +0 -1
- package/immortal/src/seek-state.ts +0 -60
- package/src/allocate.ts +0 -443
- package/src/molecule.ts +0 -16
|
@@ -1,510 +1,4 @@
|
|
|
1
|
+
export { confirmedUpdateQueue, myIdState, myIdState__INTERNAL, myUsernameState, optimisticUpdateQueue, pullAtom, pullAtomFamilyMember, pullMutableAtom, pullMutableAtomFamilyMember, pullSelector, pullSelectorFamilyMember, pushState, serverAction, syncContinuity, useConcealState, useRegisterAndAttemptConfirmedUpdate, useRevealState } from '../../dist/chunk-Z2UJW4NQ.js';
|
|
2
|
+
import '../../dist/chunk-4LWKCEW3.js';
|
|
3
|
+
import '../../dist/chunk-GY2XQYZY.js';
|
|
1
4
|
import '../../dist/chunk-XWL6SNVU.js';
|
|
2
|
-
import * as Internal from 'atom.io/internal';
|
|
3
|
-
import { setIntoStore, getEpochNumberOfContinuity, isRootStore, ingestTransactionUpdate, setEpochNumberOfContinuity, disposeAtom, getJsonToken, getUpdateToken, getFromStore, assignTransactionToContinuity, subscribeToTransaction, actUponStore } from 'atom.io/internal';
|
|
4
|
-
import { confirmedUpdateQueue, optimisticUpdateQueue } from 'atom.io/realtime-client';
|
|
5
|
-
import { parseJson } from 'atom.io/json';
|
|
6
|
-
import * as AtomIO from 'atom.io';
|
|
7
|
-
import { persistSync } from 'atom.io/web';
|
|
8
|
-
|
|
9
|
-
var useRegisterAndAttemptConfirmedUpdate = (store, continuityKey, socket, optimisticUpdates, confirmedUpdates) => (confirmed) => {
|
|
10
|
-
function reconcileEpoch(optimisticUpdate, confirmedUpdate) {
|
|
11
|
-
store.logger.info(
|
|
12
|
-
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
13
|
-
`continuity`,
|
|
14
|
-
continuityKey,
|
|
15
|
-
`reconciling updates`
|
|
16
|
-
);
|
|
17
|
-
setIntoStore(store, optimisticUpdateQueue, (queue) => {
|
|
18
|
-
queue.shift();
|
|
19
|
-
return queue;
|
|
20
|
-
});
|
|
21
|
-
if (optimisticUpdate.id === confirmedUpdate.id) {
|
|
22
|
-
const clientResult = JSON.stringify(optimisticUpdate.updates);
|
|
23
|
-
const serverResult = JSON.stringify(confirmedUpdate.updates);
|
|
24
|
-
if (clientResult === serverResult) {
|
|
25
|
-
store.logger.info(
|
|
26
|
-
`\u2705`,
|
|
27
|
-
`continuity`,
|
|
28
|
-
continuityKey,
|
|
29
|
-
`results for ${optimisticUpdate.id} match between client and server`
|
|
30
|
-
);
|
|
31
|
-
socket.emit(`ack:${continuityKey}`, confirmedUpdate.epoch);
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
} else {
|
|
35
|
-
store.logger.info(
|
|
36
|
-
`\u274C`,
|
|
37
|
-
`continuity`,
|
|
38
|
-
continuityKey,
|
|
39
|
-
`thought update #${confirmedUpdate.epoch} was ${optimisticUpdate.key}:${optimisticUpdate.id}, but it was actually ${confirmedUpdate.key}:${confirmedUpdate.id}`
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
store.logger.info(
|
|
43
|
-
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
44
|
-
`continuity`,
|
|
45
|
-
continuityKey,
|
|
46
|
-
`updates do not match`,
|
|
47
|
-
optimisticUpdate,
|
|
48
|
-
confirmedUpdate
|
|
49
|
-
);
|
|
50
|
-
const reversedOptimisticUpdates = optimisticUpdates.toReversed();
|
|
51
|
-
for (const subsequentOptimistic of reversedOptimisticUpdates) {
|
|
52
|
-
ingestTransactionUpdate(`oldValue`, subsequentOptimistic, store);
|
|
53
|
-
}
|
|
54
|
-
store.logger.info(
|
|
55
|
-
`\u23EA`,
|
|
56
|
-
`continuity`,
|
|
57
|
-
continuityKey,
|
|
58
|
-
`undid optimistic updates:`,
|
|
59
|
-
reversedOptimisticUpdates
|
|
60
|
-
);
|
|
61
|
-
ingestTransactionUpdate(`oldValue`, optimisticUpdate, store);
|
|
62
|
-
store.logger.info(
|
|
63
|
-
`\u23EA`,
|
|
64
|
-
`continuity`,
|
|
65
|
-
continuityKey,
|
|
66
|
-
`undid zeroth optimistic update`,
|
|
67
|
-
optimisticUpdate
|
|
68
|
-
);
|
|
69
|
-
ingestTransactionUpdate(`newValue`, confirmedUpdate, store);
|
|
70
|
-
store.logger.info(
|
|
71
|
-
`\u23E9`,
|
|
72
|
-
`continuity`,
|
|
73
|
-
continuityKey,
|
|
74
|
-
`applied confirmed update`,
|
|
75
|
-
confirmedUpdate
|
|
76
|
-
);
|
|
77
|
-
socket.emit(`ack:${continuityKey}`, confirmedUpdate.epoch);
|
|
78
|
-
for (const subsequentOptimistic of optimisticUpdates) {
|
|
79
|
-
const token = {
|
|
80
|
-
type: `transaction`,
|
|
81
|
-
key: subsequentOptimistic.key
|
|
82
|
-
};
|
|
83
|
-
const { id, params } = subsequentOptimistic;
|
|
84
|
-
actUponStore(token, id, store)(...params);
|
|
85
|
-
}
|
|
86
|
-
store.logger.info(
|
|
87
|
-
`\u23E9`,
|
|
88
|
-
`continuity`,
|
|
89
|
-
continuityKey,
|
|
90
|
-
`reapplied subsequent optimistic updates:`,
|
|
91
|
-
optimisticUpdates
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
store.logger.info(
|
|
95
|
-
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
96
|
-
`continuity`,
|
|
97
|
-
continuityKey,
|
|
98
|
-
`integrating confirmed update`,
|
|
99
|
-
{ confirmedUpdate: confirmed, confirmedUpdates, optimisticUpdates }
|
|
100
|
-
);
|
|
101
|
-
const zerothOptimisticUpdate = optimisticUpdates[0];
|
|
102
|
-
if (zerothOptimisticUpdate) {
|
|
103
|
-
store.logger.info(
|
|
104
|
-
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
105
|
-
`continuity`,
|
|
106
|
-
continuityKey,
|
|
107
|
-
`has optimistic updates to reconcile`
|
|
108
|
-
);
|
|
109
|
-
if (confirmed.epoch === zerothOptimisticUpdate.epoch) {
|
|
110
|
-
store.logger.info(
|
|
111
|
-
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
112
|
-
`continuity`,
|
|
113
|
-
continuityKey,
|
|
114
|
-
`epoch of confirmed update #${confirmed.epoch} matches zeroth optimistic update`
|
|
115
|
-
);
|
|
116
|
-
reconcileEpoch(zerothOptimisticUpdate, confirmed);
|
|
117
|
-
for (const nextConfirmed of confirmedUpdates) {
|
|
118
|
-
const nextOptimistic = optimisticUpdates[0];
|
|
119
|
-
if (nextConfirmed.epoch === nextOptimistic?.epoch) {
|
|
120
|
-
reconcileEpoch(nextOptimistic, nextConfirmed);
|
|
121
|
-
} else {
|
|
122
|
-
break;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
} else {
|
|
126
|
-
store.logger.info(
|
|
127
|
-
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
128
|
-
`continuity`,
|
|
129
|
-
continuityKey,
|
|
130
|
-
`epoch of confirmed update #${confirmed.epoch} does not match zeroth optimistic update #${zerothOptimisticUpdate.epoch}`
|
|
131
|
-
);
|
|
132
|
-
const confirmedUpdateIsAlreadyEnqueued = confirmedUpdates.some(
|
|
133
|
-
(update) => update.epoch === confirmed.epoch
|
|
134
|
-
);
|
|
135
|
-
if (!confirmedUpdateIsAlreadyEnqueued) {
|
|
136
|
-
store.logger.info(
|
|
137
|
-
`\u{1F448}`,
|
|
138
|
-
`continuity`,
|
|
139
|
-
continuityKey,
|
|
140
|
-
`pushing confirmed update to queue`,
|
|
141
|
-
confirmed
|
|
142
|
-
);
|
|
143
|
-
setIntoStore(store, confirmedUpdateQueue, (queue) => {
|
|
144
|
-
queue.push(confirmed);
|
|
145
|
-
queue.sort((a, b) => a.epoch - b.epoch);
|
|
146
|
-
return queue;
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
} else {
|
|
151
|
-
store.logger.info(
|
|
152
|
-
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
153
|
-
`continuity`,
|
|
154
|
-
continuityKey,
|
|
155
|
-
`has no optimistic updates to deal with`
|
|
156
|
-
);
|
|
157
|
-
const continuityEpoch = getEpochNumberOfContinuity(continuityKey, store);
|
|
158
|
-
const isRoot = isRootStore(store);
|
|
159
|
-
if (isRoot && continuityEpoch === confirmed.epoch - 1) {
|
|
160
|
-
store.logger.info(
|
|
161
|
-
`\u2705`,
|
|
162
|
-
`continuity`,
|
|
163
|
-
continuityKey,
|
|
164
|
-
`integrating update #${confirmed.epoch} (${confirmed.key} ${confirmed.id})`
|
|
165
|
-
);
|
|
166
|
-
ingestTransactionUpdate(`newValue`, confirmed, store);
|
|
167
|
-
socket.emit(`ack:${continuityKey}`, confirmed.epoch);
|
|
168
|
-
setEpochNumberOfContinuity(continuityKey, confirmed.epoch, store);
|
|
169
|
-
} else if (isRoot && continuityEpoch !== undefined) {
|
|
170
|
-
store.logger.info(
|
|
171
|
-
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
172
|
-
`continuity`,
|
|
173
|
-
continuityKey,
|
|
174
|
-
`received update #${confirmed.epoch} but still waiting for update #${continuityEpoch + 1}`,
|
|
175
|
-
{
|
|
176
|
-
clientEpoch: continuityEpoch,
|
|
177
|
-
serverEpoch: confirmed.epoch
|
|
178
|
-
}
|
|
179
|
-
);
|
|
180
|
-
const confirmedUpdateIsAlreadyEnqueued = confirmedUpdates.some(
|
|
181
|
-
(update) => update.epoch === confirmed.epoch
|
|
182
|
-
);
|
|
183
|
-
if (confirmedUpdateIsAlreadyEnqueued) {
|
|
184
|
-
store.logger.info(
|
|
185
|
-
`\u{1F44D}`,
|
|
186
|
-
`continuity`,
|
|
187
|
-
continuityKey,
|
|
188
|
-
`confirmed update #${confirmed.epoch} is already enqueued`
|
|
189
|
-
);
|
|
190
|
-
} else {
|
|
191
|
-
store.logger.info(
|
|
192
|
-
`\u{1F448}`,
|
|
193
|
-
`continuity`,
|
|
194
|
-
continuityKey,
|
|
195
|
-
`pushing confirmed update #${confirmed.epoch} to queue`
|
|
196
|
-
);
|
|
197
|
-
setIntoStore(store, confirmedUpdateQueue, (queue) => {
|
|
198
|
-
queue.push(confirmed);
|
|
199
|
-
queue.sort((a, b) => a.epoch - b.epoch);
|
|
200
|
-
return queue;
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
};
|
|
206
|
-
function useConcealState(store) {
|
|
207
|
-
return (concealed) => {
|
|
208
|
-
for (const token of concealed) {
|
|
209
|
-
disposeAtom(token, store);
|
|
210
|
-
}
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
function useRevealState(store) {
|
|
214
|
-
return (revealed) => {
|
|
215
|
-
let i = 0;
|
|
216
|
-
let k;
|
|
217
|
-
let v;
|
|
218
|
-
for (const x of revealed) {
|
|
219
|
-
if (i % 2 === 0) {
|
|
220
|
-
k = x;
|
|
221
|
-
} else {
|
|
222
|
-
v = x;
|
|
223
|
-
setIntoStore(store, k, v);
|
|
224
|
-
}
|
|
225
|
-
i++;
|
|
226
|
-
}
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
function pullAtom(token, socket, store) {
|
|
230
|
-
const setServedValue = (data) => {
|
|
231
|
-
setIntoStore(store, token, data);
|
|
232
|
-
};
|
|
233
|
-
socket.on(`serve:${token.key}`, setServedValue);
|
|
234
|
-
socket.emit(`sub:${token.key}`);
|
|
235
|
-
return () => {
|
|
236
|
-
socket.off(`serve:${token.key}`, setServedValue);
|
|
237
|
-
socket.emit(`unsub:${token.key}`);
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
function pullAtomFamilyMember(token, socket, store) {
|
|
241
|
-
if (!(`family` in token)) {
|
|
242
|
-
console.error(`Token is not a family member:`, token);
|
|
243
|
-
return () => {
|
|
244
|
-
};
|
|
245
|
-
}
|
|
246
|
-
const { key: familyKey, subKey: serializedSubKey } = token.family;
|
|
247
|
-
const subKey = parseJson(serializedSubKey);
|
|
248
|
-
socket?.on(`serve:${token.key}`, (data) => {
|
|
249
|
-
setIntoStore(store, token, data);
|
|
250
|
-
});
|
|
251
|
-
socket?.emit(`sub:${familyKey}`, subKey);
|
|
252
|
-
return () => {
|
|
253
|
-
socket?.off(`serve:${token.key}`);
|
|
254
|
-
socket?.emit(`unsub:${token.key}`);
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
function pullMutableAtom(token, socket, store) {
|
|
258
|
-
const jsonToken = getJsonToken(store, token);
|
|
259
|
-
const updateToken = getUpdateToken(token);
|
|
260
|
-
socket.on(`init:${token.key}`, (data) => {
|
|
261
|
-
setIntoStore(store, jsonToken, data);
|
|
262
|
-
});
|
|
263
|
-
socket.on(
|
|
264
|
-
`next:${token.key}`,
|
|
265
|
-
(data) => {
|
|
266
|
-
setIntoStore(store, updateToken, data);
|
|
267
|
-
}
|
|
268
|
-
);
|
|
269
|
-
socket.emit(`sub:${token.key}`);
|
|
270
|
-
return () => {
|
|
271
|
-
socket.off(`init:${token.key}`);
|
|
272
|
-
socket.off(`next:${token.key}`);
|
|
273
|
-
socket.emit(`unsub:${token.key}`);
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
function pullMutableAtomFamilyMember(token, socket, store) {
|
|
277
|
-
if (!(`family` in token)) {
|
|
278
|
-
console.error(`Token is not a family member:`, token);
|
|
279
|
-
return () => {
|
|
280
|
-
};
|
|
281
|
-
}
|
|
282
|
-
const { key: familyKey, subKey: serializedSubKey } = token.family;
|
|
283
|
-
const subKey = parseJson(serializedSubKey);
|
|
284
|
-
socket.on(`init:${token.key}`, (data) => {
|
|
285
|
-
const jsonToken = getJsonToken(store, token);
|
|
286
|
-
setIntoStore(store, jsonToken, data);
|
|
287
|
-
});
|
|
288
|
-
socket.on(
|
|
289
|
-
`next:${token.key}`,
|
|
290
|
-
(data) => {
|
|
291
|
-
const trackerToken = getUpdateToken(token);
|
|
292
|
-
setIntoStore(store, trackerToken, data);
|
|
293
|
-
}
|
|
294
|
-
);
|
|
295
|
-
socket.emit(`sub:${familyKey}`, subKey);
|
|
296
|
-
return () => {
|
|
297
|
-
socket.off(`serve:${token.key}`);
|
|
298
|
-
socket.emit(`unsub:${token.key}`);
|
|
299
|
-
};
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
// realtime-client/src/pull-selector.ts
|
|
303
|
-
function pullSelector(token, socket, store) {
|
|
304
|
-
const atomKeys = store.selectorAtoms.getRelatedKeys(token.key);
|
|
305
|
-
const unsubscribes = [];
|
|
306
|
-
if (atomKeys) {
|
|
307
|
-
for (const atomKey of atomKeys) {
|
|
308
|
-
const atom3 = store.atoms.get(atomKey);
|
|
309
|
-
if (!atom3) {
|
|
310
|
-
continue;
|
|
311
|
-
}
|
|
312
|
-
switch (atom3.type) {
|
|
313
|
-
case `atom`: {
|
|
314
|
-
unsubscribes.push(pullAtom(atom3, socket, store));
|
|
315
|
-
break;
|
|
316
|
-
}
|
|
317
|
-
case `mutable_atom`: {
|
|
318
|
-
unsubscribes.push(pullMutableAtom(atom3, socket, store));
|
|
319
|
-
break;
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
return () => {
|
|
325
|
-
for (const unsubscribe of unsubscribes) {
|
|
326
|
-
unsubscribe();
|
|
327
|
-
}
|
|
328
|
-
};
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
// realtime-client/src/pull-selector-family-member.ts
|
|
332
|
-
function pullSelectorFamilyMember(token, socket, store) {
|
|
333
|
-
if (!(`family` in token)) {
|
|
334
|
-
console.error(`Token is not a family member:`, token);
|
|
335
|
-
return () => {
|
|
336
|
-
};
|
|
337
|
-
}
|
|
338
|
-
const atomKeys = store.selectorAtoms.getRelatedKeys(token.key);
|
|
339
|
-
const unsubscribes = [];
|
|
340
|
-
if (atomKeys) {
|
|
341
|
-
for (const atomKey of atomKeys) {
|
|
342
|
-
const atom3 = store.atoms.get(atomKey);
|
|
343
|
-
if (!atom3) {
|
|
344
|
-
continue;
|
|
345
|
-
}
|
|
346
|
-
switch (atom3.type) {
|
|
347
|
-
case `atom`: {
|
|
348
|
-
unsubscribes.push(pullAtomFamilyMember(atom3, socket, store));
|
|
349
|
-
break;
|
|
350
|
-
}
|
|
351
|
-
case `mutable_atom`: {
|
|
352
|
-
unsubscribes.push(pullMutableAtomFamilyMember(atom3, socket, store));
|
|
353
|
-
break;
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
return () => {
|
|
359
|
-
for (const unsubscribe of unsubscribes) {
|
|
360
|
-
unsubscribe();
|
|
361
|
-
}
|
|
362
|
-
};
|
|
363
|
-
}
|
|
364
|
-
function pushState(token, socket, store) {
|
|
365
|
-
socket.emit(`claim:${token.key}`);
|
|
366
|
-
Internal.subscribeToState(
|
|
367
|
-
token,
|
|
368
|
-
({ newValue }) => {
|
|
369
|
-
socket.emit(`pub:${token.key}`, newValue);
|
|
370
|
-
},
|
|
371
|
-
`push`,
|
|
372
|
-
store
|
|
373
|
-
);
|
|
374
|
-
return () => {
|
|
375
|
-
socket.off(`pub:${token.key}`);
|
|
376
|
-
socket.emit(`unclaim:${token.key}`);
|
|
377
|
-
};
|
|
378
|
-
}
|
|
379
|
-
var myIdState__INTERNAL = AtomIO.atom({
|
|
380
|
-
key: `mySocketId__INTERNAL`,
|
|
381
|
-
default: undefined
|
|
382
|
-
});
|
|
383
|
-
var myIdState = AtomIO.selector({
|
|
384
|
-
key: `mySocketId`,
|
|
385
|
-
get: ({ get }) => get(myIdState__INTERNAL)
|
|
386
|
-
});
|
|
387
|
-
var myUsernameState = AtomIO.atom({
|
|
388
|
-
key: `myName`,
|
|
389
|
-
default: null,
|
|
390
|
-
effects: typeof window === `undefined` ? [] : [persistSync(window.localStorage, JSON, `myUsername`)]
|
|
391
|
-
});
|
|
392
|
-
var optimisticUpdateQueue2 = AtomIO.atom({
|
|
393
|
-
key: `updateQueue`,
|
|
394
|
-
default: []
|
|
395
|
-
});
|
|
396
|
-
var confirmedUpdateQueue2 = AtomIO.atom(
|
|
397
|
-
{
|
|
398
|
-
key: `serverConfirmedUpdateQueue`,
|
|
399
|
-
default: []
|
|
400
|
-
}
|
|
401
|
-
);
|
|
402
|
-
function serverAction(token, socket, store) {
|
|
403
|
-
const unsubscribeFromLocalUpdates = Internal.subscribeToTransaction(
|
|
404
|
-
token,
|
|
405
|
-
(clientUpdate) => {
|
|
406
|
-
socket.emit(`tx-run:${token.key}`, clientUpdate);
|
|
407
|
-
},
|
|
408
|
-
`tx-run:${token.key}:${socket.id}`,
|
|
409
|
-
store
|
|
410
|
-
);
|
|
411
|
-
return () => {
|
|
412
|
-
unsubscribeFromLocalUpdates();
|
|
413
|
-
};
|
|
414
|
-
}
|
|
415
|
-
function syncContinuity(continuity, socket, store) {
|
|
416
|
-
const continuityKey = continuity.key;
|
|
417
|
-
const optimisticUpdates = getFromStore(store, optimisticUpdateQueue);
|
|
418
|
-
const confirmedUpdates = getFromStore(store, confirmedUpdateQueue);
|
|
419
|
-
const initializeContinuity = (epoch, payload) => {
|
|
420
|
-
socket.off(`continuity-init:${continuityKey}`, initializeContinuity);
|
|
421
|
-
let i = 0;
|
|
422
|
-
let k;
|
|
423
|
-
let v;
|
|
424
|
-
for (const x of payload) {
|
|
425
|
-
if (i % 2 === 0) {
|
|
426
|
-
k = x;
|
|
427
|
-
} else {
|
|
428
|
-
v = x;
|
|
429
|
-
if (`type` in k && k.type === `mutable_atom`) {
|
|
430
|
-
k = getJsonToken(store, k);
|
|
431
|
-
}
|
|
432
|
-
setIntoStore(store, k, v);
|
|
433
|
-
}
|
|
434
|
-
i++;
|
|
435
|
-
}
|
|
436
|
-
setEpochNumberOfContinuity(continuityKey, epoch, store);
|
|
437
|
-
};
|
|
438
|
-
socket.off(`continuity-init:${continuityKey}`);
|
|
439
|
-
socket.on(`continuity-init:${continuityKey}`, initializeContinuity);
|
|
440
|
-
const registerAndAttemptConfirmedUpdate = useRegisterAndAttemptConfirmedUpdate(
|
|
441
|
-
store,
|
|
442
|
-
continuityKey,
|
|
443
|
-
socket,
|
|
444
|
-
optimisticUpdates,
|
|
445
|
-
confirmedUpdates
|
|
446
|
-
);
|
|
447
|
-
socket.off(`tx-new:${continuityKey}`);
|
|
448
|
-
socket.on(`tx-new:${continuityKey}`, registerAndAttemptConfirmedUpdate);
|
|
449
|
-
const unsubscribeFunctions = continuity.actions.map((transaction) => {
|
|
450
|
-
assignTransactionToContinuity(continuityKey, transaction.key, store);
|
|
451
|
-
const unsubscribeFromTransactionUpdates = subscribeToTransaction(
|
|
452
|
-
transaction,
|
|
453
|
-
(clientUpdate) => {
|
|
454
|
-
store.logger.info(
|
|
455
|
-
`\u{1F91E}`,
|
|
456
|
-
`continuity`,
|
|
457
|
-
continuityKey,
|
|
458
|
-
`enqueuing optimistic update`
|
|
459
|
-
);
|
|
460
|
-
const optimisticUpdateIndex = optimisticUpdates.findIndex(
|
|
461
|
-
(update) => update.id === clientUpdate.id
|
|
462
|
-
);
|
|
463
|
-
if (optimisticUpdateIndex === -1) {
|
|
464
|
-
store.logger.info(
|
|
465
|
-
`\u{1F91E}`,
|
|
466
|
-
`continuity`,
|
|
467
|
-
continuityKey,
|
|
468
|
-
`enqueuing new optimistic update`
|
|
469
|
-
);
|
|
470
|
-
setIntoStore(store, optimisticUpdateQueue, (queue) => {
|
|
471
|
-
queue.push(clientUpdate);
|
|
472
|
-
queue.sort((a, b) => a.epoch - b.epoch);
|
|
473
|
-
return queue;
|
|
474
|
-
});
|
|
475
|
-
} else {
|
|
476
|
-
store.logger.info(
|
|
477
|
-
`\u{1F91E}`,
|
|
478
|
-
`continuity`,
|
|
479
|
-
continuityKey,
|
|
480
|
-
`replacing existing optimistic update at index ${optimisticUpdateIndex}`
|
|
481
|
-
);
|
|
482
|
-
setIntoStore(store, optimisticUpdateQueue, (queue) => {
|
|
483
|
-
queue[optimisticUpdateIndex] = clientUpdate;
|
|
484
|
-
return queue;
|
|
485
|
-
});
|
|
486
|
-
}
|
|
487
|
-
socket.emit(`tx-run:${continuityKey}`, {
|
|
488
|
-
id: clientUpdate.id,
|
|
489
|
-
key: transaction.key,
|
|
490
|
-
params: clientUpdate.params
|
|
491
|
-
});
|
|
492
|
-
},
|
|
493
|
-
`tx-run:${continuityKey}`,
|
|
494
|
-
store
|
|
495
|
-
);
|
|
496
|
-
return unsubscribeFromTransactionUpdates;
|
|
497
|
-
});
|
|
498
|
-
const revealState = useRevealState(store);
|
|
499
|
-
const concealState = useConcealState(store);
|
|
500
|
-
socket.on(`reveal:${continuityKey}`, revealState);
|
|
501
|
-
socket.on(`conceal:${continuityKey}`, concealState);
|
|
502
|
-
socket.emit(`get:${continuityKey}`);
|
|
503
|
-
return () => {
|
|
504
|
-
socket.off(`continuity-init:${continuityKey}`);
|
|
505
|
-
socket.off(`tx-new:${continuityKey}`);
|
|
506
|
-
for (const unsubscribe of unsubscribeFunctions) unsubscribe();
|
|
507
|
-
};
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
export { confirmedUpdateQueue2 as confirmedUpdateQueue, myIdState, myIdState__INTERNAL, myUsernameState, optimisticUpdateQueue2 as optimisticUpdateQueue, pullAtom, pullAtomFamilyMember, pullMutableAtom, pullMutableAtomFamilyMember, pullSelector, pullSelectorFamilyMember, pushState, serverAction, syncContinuity, useConcealState, useRegisterAndAttemptConfirmedUpdate, useRevealState };
|
|
@@ -102,7 +102,7 @@ export const useRegisterAndAttemptConfirmedUpdate =
|
|
|
102
102
|
key: subsequentOptimistic.key,
|
|
103
103
|
} as const
|
|
104
104
|
const { id, params } = subsequentOptimistic
|
|
105
|
-
actUponStore(token, id
|
|
105
|
+
actUponStore(store, token, id)(...params)
|
|
106
106
|
}
|
|
107
107
|
store.logger.info(
|
|
108
108
|
`⏩`,
|
|
@@ -177,7 +177,7 @@ export const useRegisterAndAttemptConfirmedUpdate =
|
|
|
177
177
|
continuityKey,
|
|
178
178
|
`has no optimistic updates to deal with`,
|
|
179
179
|
)
|
|
180
|
-
const continuityEpoch = getEpochNumberOfContinuity(
|
|
180
|
+
const continuityEpoch = getEpochNumberOfContinuity(store, continuityKey)
|
|
181
181
|
const isRoot = isRootStore(store)
|
|
182
182
|
|
|
183
183
|
if (isRoot && continuityEpoch === confirmed.epoch - 1) {
|
|
@@ -189,7 +189,7 @@ export const useRegisterAndAttemptConfirmedUpdate =
|
|
|
189
189
|
)
|
|
190
190
|
ingestTransactionUpdate(`newValue`, confirmed, store)
|
|
191
191
|
socket.emit(`ack:${continuityKey}`, confirmed.epoch)
|
|
192
|
-
setEpochNumberOfContinuity(continuityKey, confirmed.epoch
|
|
192
|
+
setEpochNumberOfContinuity(store, continuityKey, confirmed.epoch)
|
|
193
193
|
} else if (isRoot && continuityEpoch !== undefined) {
|
|
194
194
|
store.logger.info(
|
|
195
195
|
`🧑⚖️`,
|
|
@@ -7,9 +7,9 @@ import type { Socket } from "socket.io-client"
|
|
|
7
7
|
/* eslint-disable no-console */
|
|
8
8
|
|
|
9
9
|
export function pullAtomFamilyMember<J extends Json.Serializable>(
|
|
10
|
-
token: AtomIO.RegularAtomToken<J>,
|
|
11
|
-
socket: Socket,
|
|
12
10
|
store: Store,
|
|
11
|
+
socket: Socket,
|
|
12
|
+
token: AtomIO.RegularAtomToken<J>,
|
|
13
13
|
): () => void {
|
|
14
14
|
if (!(`family` in token)) {
|
|
15
15
|
console.error(`Token is not a family member:`, token)
|
|
@@ -4,9 +4,9 @@ import type { Json } from "atom.io/json"
|
|
|
4
4
|
import type { Socket } from "socket.io-client"
|
|
5
5
|
|
|
6
6
|
export function pullAtom<J extends Json.Serializable>(
|
|
7
|
-
token: AtomIO.RegularAtomToken<J>,
|
|
8
|
-
socket: Socket,
|
|
9
7
|
store: Store,
|
|
8
|
+
socket: Socket,
|
|
9
|
+
token: AtomIO.RegularAtomToken<J>,
|
|
10
10
|
): () => void {
|
|
11
11
|
const setServedValue = (data: J) => {
|
|
12
12
|
setIntoStore(store, token, data)
|
|
@@ -11,9 +11,9 @@ export function pullMutableAtomFamilyMember<
|
|
|
11
11
|
T extends Transceiver<any>,
|
|
12
12
|
J extends Json.Serializable,
|
|
13
13
|
>(
|
|
14
|
-
token: AtomIO.MutableAtomToken<T, J>,
|
|
15
|
-
socket: Socket,
|
|
16
14
|
store: Store,
|
|
15
|
+
socket: Socket,
|
|
16
|
+
token: AtomIO.MutableAtomToken<T, J>,
|
|
17
17
|
): () => void {
|
|
18
18
|
if (!(`family` in token)) {
|
|
19
19
|
console.error(`Token is not a family member:`, token)
|
|
@@ -8,9 +8,9 @@ export function pullMutableAtom<
|
|
|
8
8
|
T extends Transceiver<any>,
|
|
9
9
|
J extends Json.Serializable,
|
|
10
10
|
>(
|
|
11
|
-
token: AtomIO.MutableAtomToken<T, J>,
|
|
12
|
-
socket: Socket,
|
|
13
11
|
store: Store,
|
|
12
|
+
socket: Socket,
|
|
13
|
+
token: AtomIO.MutableAtomToken<T, J>,
|
|
14
14
|
): () => void {
|
|
15
15
|
const jsonToken = getJsonToken(store, token)
|
|
16
16
|
const updateToken = getUpdateToken(token)
|
|
@@ -8,9 +8,9 @@ import { pullMutableAtomFamilyMember } from "./pull-mutable-atom-family-member"
|
|
|
8
8
|
/* eslint-disable no-console */
|
|
9
9
|
|
|
10
10
|
export function pullSelectorFamilyMember<T>(
|
|
11
|
-
token: AtomIO.SelectorToken<T>,
|
|
12
|
-
socket: Socket,
|
|
13
11
|
store: Store,
|
|
12
|
+
socket: Socket,
|
|
13
|
+
token: AtomIO.SelectorToken<T>,
|
|
14
14
|
): () => void {
|
|
15
15
|
if (!(`family` in token)) {
|
|
16
16
|
console.error(`Token is not a family member:`, token)
|
|
@@ -26,11 +26,11 @@ export function pullSelectorFamilyMember<T>(
|
|
|
26
26
|
}
|
|
27
27
|
switch (atom.type) {
|
|
28
28
|
case `atom`: {
|
|
29
|
-
unsubscribes.push(pullAtomFamilyMember(
|
|
29
|
+
unsubscribes.push(pullAtomFamilyMember(store, socket, atom))
|
|
30
30
|
break
|
|
31
31
|
}
|
|
32
32
|
case `mutable_atom`: {
|
|
33
|
-
unsubscribes.push(pullMutableAtomFamilyMember(
|
|
33
|
+
unsubscribes.push(pullMutableAtomFamilyMember(store, socket, atom))
|
|
34
34
|
break
|
|
35
35
|
}
|
|
36
36
|
}
|
|
@@ -6,9 +6,9 @@ import { pullAtom } from "./pull-atom"
|
|
|
6
6
|
import { pullMutableAtom } from "./pull-mutable-atom"
|
|
7
7
|
|
|
8
8
|
export function pullSelector<T>(
|
|
9
|
-
token: AtomIO.SelectorToken<T>,
|
|
10
|
-
socket: Socket,
|
|
11
9
|
store: Store,
|
|
10
|
+
socket: Socket,
|
|
11
|
+
token: AtomIO.SelectorToken<T>,
|
|
12
12
|
): () => void {
|
|
13
13
|
const atomKeys = store.selectorAtoms.getRelatedKeys(token.key)
|
|
14
14
|
const unsubscribes: Array<() => void> = []
|
|
@@ -20,11 +20,11 @@ export function pullSelector<T>(
|
|
|
20
20
|
}
|
|
21
21
|
switch (atom.type) {
|
|
22
22
|
case `atom`: {
|
|
23
|
-
unsubscribes.push(pullAtom(
|
|
23
|
+
unsubscribes.push(pullAtom(store, socket, atom))
|
|
24
24
|
break
|
|
25
25
|
}
|
|
26
26
|
case `mutable_atom`: {
|
|
27
|
-
unsubscribes.push(pullMutableAtom(
|
|
27
|
+
unsubscribes.push(pullMutableAtom(store, socket, atom))
|
|
28
28
|
break
|
|
29
29
|
}
|
|
30
30
|
}
|
|
@@ -4,19 +4,14 @@ import type { Json } from "atom.io/json"
|
|
|
4
4
|
import type { Socket } from "socket.io-client"
|
|
5
5
|
|
|
6
6
|
export function pushState<J extends Json.Serializable>(
|
|
7
|
-
token: AtomIO.WritableToken<J>,
|
|
8
|
-
socket: Socket,
|
|
9
7
|
store: Internal.Store,
|
|
8
|
+
socket: Socket,
|
|
9
|
+
token: AtomIO.WritableToken<J>,
|
|
10
10
|
): () => void {
|
|
11
11
|
socket.emit(`claim:${token.key}`)
|
|
12
|
-
Internal.subscribeToState(
|
|
13
|
-
token
|
|
14
|
-
|
|
15
|
-
socket.emit(`pub:${token.key}`, newValue)
|
|
16
|
-
},
|
|
17
|
-
`push`,
|
|
18
|
-
store,
|
|
19
|
-
)
|
|
12
|
+
Internal.subscribeToState(store, token, `push`, ({ newValue }) => {
|
|
13
|
+
socket.emit(`pub:${token.key}`, newValue)
|
|
14
|
+
})
|
|
20
15
|
return () => {
|
|
21
16
|
socket.off(`pub:${token.key}`)
|
|
22
17
|
socket.emit(`unclaim:${token.key}`)
|
|
@@ -3,17 +3,17 @@ import * as Internal from "atom.io/internal"
|
|
|
3
3
|
import type { Socket } from "socket.io-client"
|
|
4
4
|
|
|
5
5
|
export function serverAction<F extends Internal.Func>(
|
|
6
|
-
token: AtomIO.TransactionToken<F>,
|
|
7
|
-
socket: Socket,
|
|
8
6
|
store: Internal.Store,
|
|
7
|
+
socket: Socket,
|
|
8
|
+
token: AtomIO.TransactionToken<F>,
|
|
9
9
|
): () => void {
|
|
10
10
|
const unsubscribeFromLocalUpdates = Internal.subscribeToTransaction(
|
|
11
|
+
store,
|
|
11
12
|
token,
|
|
13
|
+
`tx-run:${token.key}:${socket.id}`,
|
|
12
14
|
(clientUpdate) => {
|
|
13
15
|
socket.emit(`tx-run:${token.key}`, clientUpdate)
|
|
14
16
|
},
|
|
15
|
-
`tx-run:${token.key}:${socket.id}`,
|
|
16
|
-
store,
|
|
17
17
|
)
|
|
18
18
|
|
|
19
19
|
return () => {
|