atom.io 0.17.0 → 0.18.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.cjs +62 -40
- package/data/dist/index.cjs.map +1 -1
- package/data/dist/index.d.ts +8 -2
- package/data/dist/index.js +64 -42
- package/data/dist/index.js.map +1 -1
- package/data/src/dict.ts +8 -4
- package/data/src/join.ts +74 -33
- package/data/src/struct-family.ts +18 -17
- package/dist/chunk-OEVFAUPE.js +289 -0
- package/dist/chunk-OEVFAUPE.js.map +1 -0
- package/dist/index.cjs +4 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +62 -51
- package/dist/index.js +5 -11
- package/dist/index.js.map +1 -1
- package/internal/dist/index.cjs +163 -64
- package/internal/dist/index.cjs.map +1 -1
- package/internal/dist/index.d.ts +94 -70
- package/internal/dist/index.js +155 -59
- package/internal/dist/index.js.map +1 -1
- package/internal/src/arbitrary.ts +3 -0
- package/internal/src/caching.ts +8 -6
- package/internal/src/families/find-in-store.ts +16 -0
- package/internal/src/get-environment-data.ts +4 -7
- package/internal/src/index.ts +6 -5
- package/internal/src/ingest-updates/ingest-transaction-update.ts +0 -1
- package/internal/src/selector/create-standalone-selector.ts +0 -2
- package/internal/src/set-state/set-atom.ts +14 -18
- package/internal/src/store/store.ts +14 -2
- package/internal/src/store/withdraw.ts +72 -2
- package/internal/src/subscribe/subscribe-to-timeline.ts +2 -2
- package/internal/src/subscribe/subscribe-to-transaction.ts +2 -2
- package/internal/src/timeline/create-timeline.ts +12 -1
- package/internal/src/transaction/act-upon-store.ts +19 -0
- package/internal/src/transaction/apply-transaction.ts +7 -1
- package/internal/src/transaction/assign-transaction-to-continuity.ts +18 -0
- package/internal/src/transaction/build-transaction.ts +7 -6
- package/internal/src/transaction/create-transaction.ts +1 -1
- package/internal/src/transaction/get-epoch-number.ts +40 -0
- package/internal/src/transaction/index.ts +10 -1
- package/internal/src/transaction/set-epoch-number.ts +31 -0
- package/introspection/dist/index.cjs.map +1 -1
- package/introspection/dist/index.d.ts +3 -3
- package/introspection/dist/index.js.map +1 -1
- package/introspection/src/attach-introspection-states.ts +6 -2
- package/introspection/src/attach-timeline-family.ts +5 -2
- package/introspection/src/attach-transaction-logs.ts +2 -2
- package/json/dist/index.d.ts +3 -1
- package/json/src/index.ts +6 -2
- package/package.json +24 -13
- package/react/dist/index.cjs.map +1 -1
- package/react/dist/index.d.ts +1 -1
- package/react/dist/index.js.map +1 -1
- package/react/src/use-json.ts +1 -1
- package/react-devtools/dist/index.cjs +131 -134
- package/react-devtools/dist/index.cjs.map +1 -1
- package/react-devtools/dist/index.css +2 -2
- package/react-devtools/dist/index.css.map +1 -1
- package/react-devtools/dist/index.d.ts +3 -3
- package/react-devtools/dist/index.js +103 -106
- package/react-devtools/dist/index.js.map +1 -1
- package/react-devtools/src/StateEditor.tsx +6 -6
- package/react-devtools/src/StateIndex.tsx +2 -5
- package/react-devtools/src/TimelineIndex.tsx +3 -3
- package/react-devtools/src/TransactionIndex.tsx +9 -8
- package/react-devtools/src/Updates.tsx +1 -1
- package/react-devtools/src/index.ts +4 -4
- package/realtime/dist/index.cjs +72 -0
- package/realtime/dist/index.cjs.map +1 -0
- package/realtime/dist/index.d.ts +39 -0
- package/realtime/dist/index.js +68 -0
- package/realtime/dist/index.js.map +1 -0
- package/realtime/package.json +16 -0
- package/realtime/src/index.ts +1 -0
- package/realtime/src/realtime-continuity.ts +152 -0
- package/realtime-client/dist/index.cjs +389 -48
- package/realtime-client/dist/index.cjs.map +1 -1
- package/realtime-client/dist/index.d.ts +16 -9
- package/realtime-client/dist/index.js +100 -37
- package/realtime-client/dist/index.js.map +1 -1
- package/realtime-client/src/index.ts +8 -5
- package/realtime-client/src/{pull-family-member.ts → pull-atom-family-member.ts} +2 -2
- package/realtime-client/src/{pull-state.ts → pull-atom.ts} +2 -2
- package/realtime-client/src/{pull-mutable-family-member.ts → pull-mutable-atom-family-member.ts} +1 -1
- package/realtime-client/src/{pull-mutable.ts → pull-mutable-atom.ts} +1 -1
- package/realtime-client/src/pull-selector-family-member.ts +42 -0
- package/realtime-client/src/pull-selector.ts +38 -0
- package/realtime-client/src/realtime-client-stores/client-main-store.ts +2 -2
- package/realtime-client/src/realtime-client-stores/client-sync-store.ts +7 -7
- package/realtime-client/src/sync-continuity.ts +321 -0
- package/realtime-client/src/sync-server-action.ts +18 -20
- package/realtime-react/dist/index.cjs +330 -15
- package/realtime-react/dist/index.cjs.map +1 -1
- package/realtime-react/dist/index.d.ts +26 -6
- package/realtime-react/dist/index.js +43 -12
- package/realtime-react/dist/index.js.map +1 -1
- package/realtime-react/src/index.ts +6 -3
- package/realtime-react/src/use-pull-atom-family-member.ts +21 -0
- package/realtime-react/src/{use-pull-family-member.ts → use-pull-atom.ts} +6 -5
- package/realtime-react/src/{use-pull-mutable.ts → use-pull-mutable-atom.ts} +4 -3
- package/realtime-react/src/use-pull-mutable-family-member.ts +9 -4
- package/realtime-react/src/use-pull-selector-family-member.ts +21 -0
- package/realtime-react/src/{use-pull.ts → use-pull-selector.ts} +7 -5
- package/realtime-react/src/use-push.ts +3 -2
- package/realtime-react/src/use-server-action.ts +3 -2
- package/realtime-react/src/use-sync-continuity.ts +12 -0
- package/realtime-react/src/use-sync-server-action.ts +3 -2
- package/realtime-server/dist/index.cjs +568 -242
- package/realtime-server/dist/index.cjs.map +1 -1
- package/realtime-server/dist/index.d.ts +124 -49
- package/realtime-server/dist/index.js +555 -238
- package/realtime-server/dist/index.js.map +1 -1
- package/realtime-server/src/index.ts +18 -2
- package/realtime-server/src/ipc-socket.ts +230 -0
- package/realtime-server/src/realtime-action-receiver.ts +8 -5
- package/realtime-server/src/realtime-action-synchronizer.ts +40 -28
- package/realtime-server/src/realtime-continuity-synchronizer.ts +247 -0
- package/realtime-server/src/realtime-family-provider.ts +30 -71
- package/realtime-server/src/realtime-mutable-family-provider.ts +24 -86
- package/realtime-server/src/realtime-server-stores/index.ts +3 -1
- package/realtime-server/src/realtime-server-stores/realtime-continuity-store.ts +90 -0
- package/realtime-server/src/realtime-server-stores/server-room-store.ts +97 -0
- package/realtime-server/src/realtime-server-stores/server-sync-store.ts +2 -72
- package/realtime-server/src/realtime-server-stores/server-user-store.ts +14 -29
- package/realtime-server/src/realtime-state-receiver.ts +0 -1
- package/realtime-testing/dist/index.cjs +28 -28
- package/realtime-testing/dist/index.cjs.map +1 -1
- package/realtime-testing/dist/index.js +28 -27
- package/realtime-testing/dist/index.js.map +1 -1
- package/realtime-testing/src/setup-realtime-test.tsx +38 -28
- package/src/atom.ts +49 -31
- package/src/logger.ts +10 -5
- package/src/selector.ts +44 -25
- package/src/subscribe.ts +2 -1
- package/src/timeline.ts +4 -4
- package/src/transaction.ts +13 -17
- package/src/validators.ts +15 -9
- package/dist/chunk-H4Q5FTPZ.js +0 -11
- package/dist/chunk-H4Q5FTPZ.js.map +0 -1
- package/internal/src/set-state/copy-mutable-in-transaction.ts +0 -19
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
var Internal3 = require('atom.io/internal');
|
|
4
4
|
var json = require('atom.io/json');
|
|
5
5
|
var AtomIO = require('atom.io');
|
|
6
|
+
var realtimeClient = require('atom.io/realtime-client');
|
|
6
7
|
|
|
7
8
|
function _interopNamespace(e) {
|
|
8
9
|
if (e && e.__esModule) return e;
|
|
@@ -25,8 +26,8 @@ function _interopNamespace(e) {
|
|
|
25
26
|
var Internal3__namespace = /*#__PURE__*/_interopNamespace(Internal3);
|
|
26
27
|
var AtomIO__namespace = /*#__PURE__*/_interopNamespace(AtomIO);
|
|
27
28
|
|
|
28
|
-
// realtime-client/src/pull-
|
|
29
|
-
function
|
|
29
|
+
// realtime-client/src/pull-atom.ts
|
|
30
|
+
function pullAtom(token, socket, store) {
|
|
30
31
|
const setServedValue = (data) => {
|
|
31
32
|
Internal3.setIntoStore(token, data, store);
|
|
32
33
|
};
|
|
@@ -37,7 +38,7 @@ function pullState(token, socket, store) {
|
|
|
37
38
|
socket.emit(`unsub:${token.key}`);
|
|
38
39
|
};
|
|
39
40
|
}
|
|
40
|
-
function
|
|
41
|
+
function pullAtomFamilyMember(token, socket, store) {
|
|
41
42
|
if (!(`family` in token)) {
|
|
42
43
|
console.error(`Token is not a family member:`, token);
|
|
43
44
|
return () => {
|
|
@@ -54,7 +55,7 @@ function pullFamilyMember(token, socket, store) {
|
|
|
54
55
|
socket == null ? void 0 : socket.emit(`unsub:${token.key}`);
|
|
55
56
|
};
|
|
56
57
|
}
|
|
57
|
-
function
|
|
58
|
+
function pullMutableAtom(token, socket, store) {
|
|
58
59
|
const jsonToken = Internal3.getJsonToken(token);
|
|
59
60
|
const updateToken = Internal3.getUpdateToken(token);
|
|
60
61
|
socket.on(`init:${token.key}`, (data) => {
|
|
@@ -73,7 +74,7 @@ function pullMutableState(token, socket, store) {
|
|
|
73
74
|
socket.emit(`unsub:${token.key}`);
|
|
74
75
|
};
|
|
75
76
|
}
|
|
76
|
-
function
|
|
77
|
+
function pullMutableAtomFamilyMember(token, socket, store) {
|
|
77
78
|
if (!(`family` in token)) {
|
|
78
79
|
console.error(`Token is not a family member:`, token);
|
|
79
80
|
return () => {
|
|
@@ -98,6 +99,69 @@ function pullMutableFamilyMember(token, socket, store) {
|
|
|
98
99
|
socket == null ? void 0 : socket.emit(`unsub:${token.key}`);
|
|
99
100
|
};
|
|
100
101
|
}
|
|
102
|
+
|
|
103
|
+
// realtime-client/src/pull-selector.ts
|
|
104
|
+
function pullSelector(token, socket, store) {
|
|
105
|
+
const atomKeys = store.selectorAtoms.getRelatedKeys(token.key);
|
|
106
|
+
const unsubscribes = [];
|
|
107
|
+
if (atomKeys) {
|
|
108
|
+
for (const atomKey of atomKeys) {
|
|
109
|
+
const atom3 = store.atoms.get(atomKey);
|
|
110
|
+
if (!atom3) {
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
switch (atom3.type) {
|
|
114
|
+
case `atom`: {
|
|
115
|
+
unsubscribes.push(pullAtom(atom3, socket, store));
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
case `mutable_atom`: {
|
|
119
|
+
unsubscribes.push(pullMutableAtom(atom3, socket, store));
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return () => {
|
|
126
|
+
for (const unsubscribe of unsubscribes) {
|
|
127
|
+
unsubscribe();
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// realtime-client/src/pull-selector-family-member.ts
|
|
133
|
+
function pullSelectorFamilyMember(token, socket, store) {
|
|
134
|
+
if (!(`family` in token)) {
|
|
135
|
+
console.error(`Token is not a family member:`, token);
|
|
136
|
+
return () => {
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
const atomKeys = store.selectorAtoms.getRelatedKeys(token.key);
|
|
140
|
+
const unsubscribes = [];
|
|
141
|
+
if (atomKeys) {
|
|
142
|
+
for (const atomKey of atomKeys) {
|
|
143
|
+
const atom3 = store.atoms.get(atomKey);
|
|
144
|
+
if (!atom3) {
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
switch (atom3.type) {
|
|
148
|
+
case `atom`: {
|
|
149
|
+
unsubscribes.push(pullAtomFamilyMember(atom3, socket, store));
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
case `mutable_atom`: {
|
|
153
|
+
unsubscribes.push(pullMutableAtomFamilyMember(atom3, socket, store));
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return () => {
|
|
160
|
+
for (const unsubscribe of unsubscribes) {
|
|
161
|
+
unsubscribe();
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
}
|
|
101
165
|
function pushState(token, socket, store) {
|
|
102
166
|
socket.emit(`claim:${token.key}`);
|
|
103
167
|
Internal3__namespace.subscribeToState(
|
|
@@ -113,6 +177,24 @@ function pushState(token, socket, store) {
|
|
|
113
177
|
socket.emit(`unclaim:${token.key}`);
|
|
114
178
|
};
|
|
115
179
|
}
|
|
180
|
+
var myIdState__INTERNAL = AtomIO__namespace.atom({
|
|
181
|
+
key: `mySocketId__INTERNAL`,
|
|
182
|
+
default: void 0
|
|
183
|
+
});
|
|
184
|
+
var myIdState = AtomIO__namespace.selector({
|
|
185
|
+
key: `mySocketId`,
|
|
186
|
+
get: ({ get }) => get(myIdState__INTERNAL)
|
|
187
|
+
});
|
|
188
|
+
var optimisticUpdateQueue = AtomIO__namespace.atom({
|
|
189
|
+
key: `updateQueue`,
|
|
190
|
+
default: []
|
|
191
|
+
});
|
|
192
|
+
var confirmedUpdateQueue = AtomIO__namespace.atom(
|
|
193
|
+
{
|
|
194
|
+
key: `serverConfirmedUpdateQueue`,
|
|
195
|
+
default: []
|
|
196
|
+
}
|
|
197
|
+
);
|
|
116
198
|
function serverAction(token, socket, store) {
|
|
117
199
|
const unsubscribeFromLocalUpdates = Internal3__namespace.subscribeToTransaction(
|
|
118
200
|
token,
|
|
@@ -126,35 +208,291 @@ function serverAction(token, socket, store) {
|
|
|
126
208
|
unsubscribeFromLocalUpdates();
|
|
127
209
|
};
|
|
128
210
|
}
|
|
129
|
-
|
|
130
|
-
key
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
211
|
+
function syncContinuity(continuity, socket, store) {
|
|
212
|
+
const continuityKey = continuity.key;
|
|
213
|
+
const optimisticUpdates = Internal3.getFromStore(realtimeClient.optimisticUpdateQueue, store);
|
|
214
|
+
const confirmedUpdates = Internal3.getFromStore(realtimeClient.confirmedUpdateQueue, store);
|
|
215
|
+
const initializeContinuity = (epoch, payload) => {
|
|
216
|
+
let i = 0;
|
|
217
|
+
let k = ``;
|
|
218
|
+
let v = null;
|
|
219
|
+
for (const x of payload) {
|
|
220
|
+
if (i % 2 === 0) {
|
|
221
|
+
k = x;
|
|
222
|
+
} else {
|
|
223
|
+
v = x;
|
|
224
|
+
Internal3.setIntoStore(k, v, store);
|
|
225
|
+
}
|
|
226
|
+
i++;
|
|
227
|
+
}
|
|
228
|
+
Internal3.setEpochNumberOfContinuity(continuityKey, epoch, store);
|
|
229
|
+
};
|
|
230
|
+
socket.off(`continuity-init:${continuityKey}`);
|
|
231
|
+
socket.on(`continuity-init:${continuityKey}`, initializeContinuity);
|
|
232
|
+
const registerAndAttemptConfirmedUpdate = (confirmedUpdate) => {
|
|
233
|
+
function reconcileEpoch(optimisticUpdate, confirmedUpdate2) {
|
|
234
|
+
store.logger.info(`\u2696\uFE0F`, `continuity`, continuityKey, `reconciling updates`);
|
|
235
|
+
Internal3.setIntoStore(
|
|
236
|
+
realtimeClient.optimisticUpdateQueue,
|
|
237
|
+
(queue) => {
|
|
238
|
+
queue.shift();
|
|
239
|
+
return queue;
|
|
240
|
+
},
|
|
241
|
+
store
|
|
242
|
+
);
|
|
243
|
+
if (optimisticUpdate.id === confirmedUpdate2.id) {
|
|
244
|
+
const clientResult = JSON.stringify(optimisticUpdate.updates);
|
|
245
|
+
const serverResult = JSON.stringify(confirmedUpdate2.updates);
|
|
246
|
+
if (clientResult === serverResult) {
|
|
247
|
+
store.logger.info(
|
|
248
|
+
`\u2705`,
|
|
249
|
+
`continuity`,
|
|
250
|
+
continuityKey,
|
|
251
|
+
`results for ${optimisticUpdate.id} match between client and server`
|
|
252
|
+
);
|
|
253
|
+
socket.emit(`ack:${continuityKey}`, confirmedUpdate2.epoch);
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
} else {
|
|
257
|
+
store.logger.info(
|
|
258
|
+
`\u274C`,
|
|
259
|
+
`continuity`,
|
|
260
|
+
continuityKey,
|
|
261
|
+
`thought update #${confirmedUpdate2.epoch} was ${optimisticUpdate.key}:${optimisticUpdate.id}, but it was actually ${confirmedUpdate2.key}:${confirmedUpdate2.id}`
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
const reversedOptimisticUpdates = optimisticUpdates.toReversed();
|
|
265
|
+
for (const subsequentOptimistic of reversedOptimisticUpdates) {
|
|
266
|
+
Internal3.ingestTransactionUpdate(`oldValue`, subsequentOptimistic, store);
|
|
267
|
+
}
|
|
268
|
+
store.logger.info(
|
|
269
|
+
`\u23EA`,
|
|
270
|
+
`continuity`,
|
|
271
|
+
continuityKey,
|
|
272
|
+
`undid optimistic updates:`,
|
|
273
|
+
reversedOptimisticUpdates
|
|
274
|
+
);
|
|
275
|
+
Internal3.ingestTransactionUpdate(`oldValue`, optimisticUpdate, store);
|
|
276
|
+
store.logger.info(
|
|
277
|
+
`\u23EA`,
|
|
278
|
+
`continuity`,
|
|
279
|
+
continuityKey,
|
|
280
|
+
`undid zeroth optimistic update`,
|
|
281
|
+
optimisticUpdate
|
|
282
|
+
);
|
|
283
|
+
Internal3.ingestTransactionUpdate(`newValue`, confirmedUpdate2, store);
|
|
284
|
+
store.logger.info(
|
|
285
|
+
`\u23E9`,
|
|
286
|
+
`continuity`,
|
|
287
|
+
continuityKey,
|
|
288
|
+
`applied confirmed update`,
|
|
289
|
+
confirmedUpdate2
|
|
290
|
+
);
|
|
291
|
+
socket.emit(`ack:${continuityKey}`, confirmedUpdate2.epoch);
|
|
292
|
+
for (const subsequentOptimistic of optimisticUpdates) {
|
|
293
|
+
const token = {
|
|
294
|
+
type: `transaction`,
|
|
295
|
+
key: subsequentOptimistic.key
|
|
296
|
+
};
|
|
297
|
+
const { id, params } = subsequentOptimistic;
|
|
298
|
+
Internal3.actUponStore(token, id, store)(...params);
|
|
299
|
+
}
|
|
300
|
+
store.logger.info(
|
|
301
|
+
`\u23E9`,
|
|
302
|
+
`continuity`,
|
|
303
|
+
continuityKey,
|
|
304
|
+
`reapplied subsequent optimistic updates:`,
|
|
305
|
+
optimisticUpdates
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
store.logger.info(
|
|
309
|
+
`\u2696\uFE0F`,
|
|
310
|
+
`continuity`,
|
|
311
|
+
continuityKey,
|
|
312
|
+
`integrating confirmed update`,
|
|
313
|
+
{ confirmedUpdate, confirmedUpdates, optimisticUpdates }
|
|
314
|
+
);
|
|
315
|
+
const zerothOptimisticUpdate = optimisticUpdates[0];
|
|
316
|
+
if (zerothOptimisticUpdate) {
|
|
317
|
+
store.logger.info(
|
|
318
|
+
`\u2696\uFE0F`,
|
|
319
|
+
`continuity`,
|
|
320
|
+
continuityKey,
|
|
321
|
+
`has optimistic updates to reconcile`
|
|
322
|
+
);
|
|
323
|
+
if (confirmedUpdate.epoch === zerothOptimisticUpdate.epoch) {
|
|
324
|
+
store.logger.info(
|
|
325
|
+
`\u2696\uFE0F`,
|
|
326
|
+
`continuity`,
|
|
327
|
+
continuityKey,
|
|
328
|
+
`epoch of confirmed update #${confirmedUpdate.epoch} matches zeroth optimistic update`
|
|
329
|
+
);
|
|
330
|
+
reconcileEpoch(zerothOptimisticUpdate, confirmedUpdate);
|
|
331
|
+
for (const nextConfirmed of confirmedUpdates) {
|
|
332
|
+
const nextOptimistic = optimisticUpdates[0];
|
|
333
|
+
if (nextConfirmed.epoch === (nextOptimistic == null ? void 0 : nextOptimistic.epoch)) {
|
|
334
|
+
reconcileEpoch(nextOptimistic, nextConfirmed);
|
|
335
|
+
} else {
|
|
336
|
+
break;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
} else {
|
|
340
|
+
store.logger.info(
|
|
341
|
+
`\u2696\uFE0F`,
|
|
342
|
+
`continuity`,
|
|
343
|
+
continuityKey,
|
|
344
|
+
`epoch of confirmed update #${confirmedUpdate.epoch} does not match zeroth optimistic update #${zerothOptimisticUpdate.epoch}`
|
|
345
|
+
);
|
|
346
|
+
const confirmedUpdateIsAlreadyEnqueued = confirmedUpdates.some(
|
|
347
|
+
(update) => update.epoch === confirmedUpdate.epoch
|
|
348
|
+
);
|
|
349
|
+
if (!confirmedUpdateIsAlreadyEnqueued) {
|
|
350
|
+
store.logger.info(
|
|
351
|
+
`\u{1F448}`,
|
|
352
|
+
`continuity`,
|
|
353
|
+
continuityKey,
|
|
354
|
+
`pushing confirmed update to queue`,
|
|
355
|
+
confirmedUpdate
|
|
356
|
+
);
|
|
357
|
+
Internal3.setIntoStore(
|
|
358
|
+
realtimeClient.confirmedUpdateQueue,
|
|
359
|
+
(queue) => {
|
|
360
|
+
queue.push(confirmedUpdate);
|
|
361
|
+
queue.sort((a, b) => a.epoch - b.epoch);
|
|
362
|
+
return queue;
|
|
363
|
+
},
|
|
364
|
+
store
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
} else {
|
|
369
|
+
store.logger.info(
|
|
370
|
+
`\u2696\uFE0F`,
|
|
371
|
+
`continuity`,
|
|
372
|
+
continuityKey,
|
|
373
|
+
`has no optimistic updates to deal with`
|
|
374
|
+
);
|
|
375
|
+
const continuityEpoch = Internal3.getEpochNumberOfContinuity(continuityKey, store);
|
|
376
|
+
const isRoot = Internal3.isRootStore(store);
|
|
377
|
+
if (isRoot && continuityEpoch === confirmedUpdate.epoch - 1) {
|
|
378
|
+
store.logger.info(
|
|
379
|
+
`\u2705`,
|
|
380
|
+
`continuity`,
|
|
381
|
+
continuityKey,
|
|
382
|
+
`integrating update #${confirmedUpdate.epoch} (${confirmedUpdate.key} ${confirmedUpdate.id})`
|
|
383
|
+
);
|
|
384
|
+
Internal3.ingestTransactionUpdate(`newValue`, confirmedUpdate, store);
|
|
385
|
+
socket.emit(`ack:${continuityKey}`, confirmedUpdate.epoch);
|
|
386
|
+
Internal3.setEpochNumberOfContinuity(continuityKey, confirmedUpdate.epoch, store);
|
|
387
|
+
} else if (isRoot && continuityEpoch !== void 0) {
|
|
388
|
+
store.logger.info(
|
|
389
|
+
`\u2696\uFE0F`,
|
|
390
|
+
`continuity`,
|
|
391
|
+
continuityKey,
|
|
392
|
+
`received update #${confirmedUpdate.epoch} but still waiting for update #${continuityEpoch + 1}`,
|
|
393
|
+
{
|
|
394
|
+
clientEpoch: continuityEpoch,
|
|
395
|
+
serverEpoch: confirmedUpdate.epoch
|
|
396
|
+
}
|
|
397
|
+
);
|
|
398
|
+
const confirmedUpdateIsAlreadyEnqueued = confirmedUpdates.some(
|
|
399
|
+
(update) => update.epoch === confirmedUpdate.epoch
|
|
400
|
+
);
|
|
401
|
+
if (confirmedUpdateIsAlreadyEnqueued) {
|
|
402
|
+
store.logger.info(
|
|
403
|
+
`\u{1F44D}`,
|
|
404
|
+
`continuity`,
|
|
405
|
+
continuityKey,
|
|
406
|
+
`confirmed update #${confirmedUpdate.epoch} is already enqueued`
|
|
407
|
+
);
|
|
408
|
+
} else {
|
|
409
|
+
store.logger.info(
|
|
410
|
+
`\u{1F448}`,
|
|
411
|
+
`continuity`,
|
|
412
|
+
continuityKey,
|
|
413
|
+
`pushing confirmed update #${confirmedUpdate.epoch} to queue`
|
|
414
|
+
);
|
|
415
|
+
Internal3.setIntoStore(
|
|
416
|
+
realtimeClient.confirmedUpdateQueue,
|
|
417
|
+
(queue) => {
|
|
418
|
+
queue.push(confirmedUpdate);
|
|
419
|
+
queue.sort((a, b) => a.epoch - b.epoch);
|
|
420
|
+
return queue;
|
|
421
|
+
},
|
|
422
|
+
store
|
|
423
|
+
);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
socket.off(`tx-new:${continuityKey}`);
|
|
429
|
+
socket.on(`tx-new:${continuityKey}`, registerAndAttemptConfirmedUpdate);
|
|
430
|
+
const unsubscribeFunctions = continuity.actions.map((transaction) => {
|
|
431
|
+
Internal3.assignTransactionToContinuity(continuityKey, transaction.key, store);
|
|
432
|
+
const unsubscribeFromTransactionUpdates = Internal3.subscribeToTransaction(
|
|
433
|
+
transaction,
|
|
434
|
+
(clientUpdate) => {
|
|
435
|
+
store.logger.info(
|
|
436
|
+
`\u{1F91E}`,
|
|
437
|
+
`continuity`,
|
|
438
|
+
continuityKey,
|
|
439
|
+
`enqueuing optimistic update`
|
|
440
|
+
);
|
|
441
|
+
const optimisticUpdateIndex = optimisticUpdates.findIndex(
|
|
442
|
+
(update) => update.id === clientUpdate.id
|
|
443
|
+
);
|
|
444
|
+
if (optimisticUpdateIndex === -1) {
|
|
445
|
+
store.logger.info(
|
|
446
|
+
`\u{1F91E}`,
|
|
447
|
+
`continuity`,
|
|
448
|
+
continuityKey,
|
|
449
|
+
`enqueuing new optimistic update`
|
|
450
|
+
);
|
|
451
|
+
Internal3.setIntoStore(
|
|
452
|
+
realtimeClient.optimisticUpdateQueue,
|
|
453
|
+
(queue) => {
|
|
454
|
+
queue.push(clientUpdate);
|
|
455
|
+
queue.sort((a, b) => a.epoch - b.epoch);
|
|
456
|
+
return queue;
|
|
457
|
+
},
|
|
458
|
+
store
|
|
459
|
+
);
|
|
460
|
+
} else {
|
|
461
|
+
store.logger.info(
|
|
462
|
+
`\u{1F91E}`,
|
|
463
|
+
`continuity`,
|
|
464
|
+
continuityKey,
|
|
465
|
+
`replacing existing optimistic update at index ${optimisticUpdateIndex}`
|
|
466
|
+
);
|
|
467
|
+
Internal3.setIntoStore(
|
|
468
|
+
realtimeClient.optimisticUpdateQueue,
|
|
469
|
+
(queue) => {
|
|
470
|
+
queue[optimisticUpdateIndex] = clientUpdate;
|
|
471
|
+
return queue;
|
|
472
|
+
},
|
|
473
|
+
store
|
|
474
|
+
);
|
|
475
|
+
}
|
|
476
|
+
socket.emit(`tx-run:${continuityKey}`, clientUpdate);
|
|
477
|
+
},
|
|
478
|
+
`tx-run:${continuityKey}`,
|
|
479
|
+
store
|
|
480
|
+
);
|
|
481
|
+
return unsubscribeFromTransactionUpdates;
|
|
482
|
+
});
|
|
483
|
+
socket.emit(`get:${continuityKey}`);
|
|
484
|
+
return () => {
|
|
485
|
+
socket.off(`continuity-init:${continuityKey}`);
|
|
486
|
+
socket.off(`tx-new:${continuityKey}`);
|
|
487
|
+
for (const unsubscribe of unsubscribeFunctions)
|
|
488
|
+
unsubscribe();
|
|
489
|
+
socket.emit(`unsub:${continuityKey}`);
|
|
490
|
+
};
|
|
149
491
|
}
|
|
150
|
-
|
|
151
|
-
// realtime-client/src/sync-server-action.ts
|
|
152
492
|
function syncAction(token, socket, store) {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
);
|
|
157
|
-
const confirmedQueue = Internal3__namespace.getFromStore(confirmedUpdateQueueState, store);
|
|
493
|
+
Internal3__namespace.assignTransactionToContinuity(`default`, token.key, store);
|
|
494
|
+
const optimisticQueue = Internal3__namespace.getFromStore(optimisticUpdateQueue, store);
|
|
495
|
+
const confirmedQueue = Internal3__namespace.getFromStore(confirmedUpdateQueue, store);
|
|
158
496
|
const unsubscribeFromLocalUpdates = Internal3__namespace.subscribeToTransaction(
|
|
159
497
|
token,
|
|
160
498
|
(clientUpdate) => {
|
|
@@ -163,7 +501,7 @@ function syncAction(token, socket, store) {
|
|
|
163
501
|
);
|
|
164
502
|
if (optimisticUpdateQueueIndex === -1) {
|
|
165
503
|
Internal3__namespace.setIntoStore(
|
|
166
|
-
|
|
504
|
+
optimisticUpdateQueue,
|
|
167
505
|
(queue) => {
|
|
168
506
|
queue.push(clientUpdate);
|
|
169
507
|
queue.sort((a, b) => a.epoch - b.epoch);
|
|
@@ -171,25 +509,24 @@ function syncAction(token, socket, store) {
|
|
|
171
509
|
},
|
|
172
510
|
store
|
|
173
511
|
);
|
|
174
|
-
socket.emit(`tx-run:${token.key}`, clientUpdate);
|
|
175
512
|
} else {
|
|
176
513
|
Internal3__namespace.setIntoStore(
|
|
177
|
-
|
|
514
|
+
optimisticUpdateQueue,
|
|
178
515
|
(queue) => {
|
|
179
516
|
queue[optimisticUpdateQueueIndex] = clientUpdate;
|
|
180
517
|
return queue;
|
|
181
518
|
},
|
|
182
519
|
store
|
|
183
520
|
);
|
|
184
|
-
socket.emit(`tx-run:${token.key}`, clientUpdate);
|
|
185
521
|
}
|
|
522
|
+
socket.emit(`tx-run:${token.key}`, clientUpdate);
|
|
186
523
|
},
|
|
187
524
|
`tx-run:${token.key}`,
|
|
188
525
|
store
|
|
189
526
|
);
|
|
190
527
|
const reconcileUpdates = (optimisticUpdate, confirmedUpdate) => {
|
|
191
528
|
Internal3__namespace.setIntoStore(
|
|
192
|
-
|
|
529
|
+
optimisticUpdateQueue,
|
|
193
530
|
(queue) => {
|
|
194
531
|
queue.shift();
|
|
195
532
|
return queue;
|
|
@@ -229,7 +566,7 @@ function syncAction(token, socket, store) {
|
|
|
229
566
|
subsequentOptimistic
|
|
230
567
|
);
|
|
231
568
|
const { id, params } = subsequentOptimistic;
|
|
232
|
-
|
|
569
|
+
Internal3__namespace.actUponStore(token2, id, store)(...params);
|
|
233
570
|
}
|
|
234
571
|
};
|
|
235
572
|
const registerAndAttemptConfirmedUpdate = (confirmedUpdate) => {
|
|
@@ -251,7 +588,7 @@ function syncAction(token, socket, store) {
|
|
|
251
588
|
);
|
|
252
589
|
if (hasEnqueuedOptimisticUpdate) {
|
|
253
590
|
Internal3__namespace.setIntoStore(
|
|
254
|
-
|
|
591
|
+
confirmedUpdateQueue,
|
|
255
592
|
(queue) => {
|
|
256
593
|
queue.push(confirmedUpdate);
|
|
257
594
|
queue.sort((a, b) => a.epoch - b.epoch);
|
|
@@ -262,11 +599,12 @@ function syncAction(token, socket, store) {
|
|
|
262
599
|
}
|
|
263
600
|
}
|
|
264
601
|
} else {
|
|
265
|
-
|
|
602
|
+
const continuityEpoch = Internal3__namespace.getEpochNumberOfAction(token.key, store);
|
|
603
|
+
if (Internal3__namespace.isRootStore(store) && continuityEpoch === confirmedUpdate.epoch - 1) {
|
|
266
604
|
Internal3__namespace.ingestTransactionUpdate(`newValue`, confirmedUpdate, store);
|
|
267
605
|
socket.emit(`tx-ack:${token.key}`, confirmedUpdate.epoch);
|
|
268
|
-
|
|
269
|
-
} else if (isRootStore(store)) {
|
|
606
|
+
Internal3__namespace.setEpochNumberOfAction(token.key, confirmedUpdate.epoch, store);
|
|
607
|
+
} else if (Internal3__namespace.isRootStore(store)) {
|
|
270
608
|
store.logger.info(
|
|
271
609
|
`\u274C`,
|
|
272
610
|
`transaction`,
|
|
@@ -303,17 +641,20 @@ function syncState(token, socket, store) {
|
|
|
303
641
|
};
|
|
304
642
|
}
|
|
305
643
|
|
|
306
|
-
exports.
|
|
644
|
+
exports.confirmedUpdateQueue = confirmedUpdateQueue;
|
|
307
645
|
exports.myIdState = myIdState;
|
|
308
646
|
exports.myIdState__INTERNAL = myIdState__INTERNAL;
|
|
309
|
-
exports.
|
|
310
|
-
exports.
|
|
311
|
-
exports.
|
|
312
|
-
exports.
|
|
313
|
-
exports.
|
|
647
|
+
exports.optimisticUpdateQueue = optimisticUpdateQueue;
|
|
648
|
+
exports.pullAtom = pullAtom;
|
|
649
|
+
exports.pullAtomFamilyMember = pullAtomFamilyMember;
|
|
650
|
+
exports.pullMutableAtom = pullMutableAtom;
|
|
651
|
+
exports.pullMutableAtomFamilyMember = pullMutableAtomFamilyMember;
|
|
652
|
+
exports.pullSelector = pullSelector;
|
|
653
|
+
exports.pullSelectorFamilyMember = pullSelectorFamilyMember;
|
|
314
654
|
exports.pushState = pushState;
|
|
315
655
|
exports.serverAction = serverAction;
|
|
316
656
|
exports.syncAction = syncAction;
|
|
657
|
+
exports.syncContinuity = syncContinuity;
|
|
317
658
|
exports.syncState = syncState;
|
|
318
659
|
//# sourceMappingURL=out.js.map
|
|
319
660
|
//# sourceMappingURL=index.cjs.map
|