atom.io 0.18.0 → 0.18.1
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/{chunk-OEVFAUPE.js → chunk-IZHOMSXA.js} +53 -11
- package/dist/chunk-IZHOMSXA.js.map +1 -0
- package/dist/chunk-JDUNWJFB.js +18 -0
- package/dist/chunk-JDUNWJFB.js.map +1 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js.map +1 -1
- package/internal/dist/index.cjs +64 -34
- package/internal/dist/index.cjs.map +1 -1
- package/internal/dist/index.d.ts +1 -1
- package/internal/dist/index.js +64 -34
- package/internal/dist/index.js.map +1 -1
- package/internal/src/atom/delete-atom.ts +7 -6
- package/internal/src/caching.ts +6 -6
- package/internal/src/ingest-updates/ingest-atom-update.ts +6 -2
- package/internal/src/set-state/copy-mutable-if-needed.ts +5 -0
- package/internal/src/set-state/emit-update.ts +25 -11
- package/internal/src/set-state/set-atom.ts +4 -3
- package/internal/src/transaction/apply-transaction.ts +0 -1
- package/internal/src/transaction/set-epoch-number.ts +0 -1
- package/json/src/index.ts +3 -3
- package/package.json +241 -241
- package/react-devtools/dist/index.cjs.map +1 -1
- package/react-devtools/dist/index.js +1 -15
- package/react-devtools/dist/index.js.map +1 -1
- package/react-devtools/src/StateEditor.tsx +6 -6
- package/react-devtools/src/StateIndex.tsx +2 -2
- package/react-devtools/src/Updates.tsx +1 -1
- package/react-devtools/src/index.ts +3 -3
- package/realtime/dist/index.cjs +50 -2
- package/realtime/dist/index.cjs.map +1 -1
- package/realtime/dist/index.d.ts +110 -3
- package/realtime/dist/index.js +47 -4
- package/realtime/dist/index.js.map +1 -1
- package/realtime/src/index.ts +1 -0
- package/realtime/src/realtime-continuity.ts +14 -4
- package/realtime/src/shared-room-store.ts +48 -0
- package/realtime-client/dist/index.cjs +113 -200
- package/realtime-client/dist/index.cjs.map +1 -1
- package/realtime-client/dist/index.d.ts +2 -5
- package/realtime-client/dist/index.js +17 -161
- package/realtime-client/dist/index.js.map +1 -1
- package/realtime-client/src/index.ts +0 -2
- package/realtime-client/src/pull-mutable-atom-family-member.ts +5 -5
- package/realtime-client/src/realtime-client-stores/client-main-store.ts +10 -0
- package/realtime-client/src/sync-continuity.ts +56 -9
- package/realtime-react/dist/index.cjs +51 -26
- package/realtime-react/dist/index.cjs.map +1 -1
- package/realtime-react/dist/index.d.ts +2 -6
- package/realtime-react/dist/index.js +2 -17
- package/realtime-react/dist/index.js.map +1 -1
- package/realtime-react/src/index.ts +0 -2
- package/realtime-server/dist/index.cjs +399 -327
- package/realtime-server/dist/index.cjs.map +1 -1
- package/realtime-server/dist/index.d.ts +55 -60
- package/realtime-server/dist/index.js +394 -319
- package/realtime-server/dist/index.js.map +1 -1
- package/realtime-server/src/index.ts +2 -4
- package/realtime-server/src/ipc-sockets/child-socket.ts +135 -0
- package/realtime-server/src/ipc-sockets/custom-socket.ts +90 -0
- package/realtime-server/src/ipc-sockets/index.ts +3 -0
- package/realtime-server/src/ipc-sockets/parent-socket.ts +185 -0
- package/realtime-server/src/realtime-continuity-synchronizer.ts +225 -96
- package/realtime-server/src/realtime-server-stores/index.ts +2 -1
- package/realtime-server/src/realtime-server-stores/realtime-continuity-store.ts +50 -31
- package/realtime-server/src/realtime-server-stores/server-room-external-actions.ts +64 -0
- package/realtime-server/src/realtime-server-stores/server-room-external-store.ts +42 -0
- package/realtime-server/src/realtime-server-stores/server-sync-store.ts +49 -26
- package/realtime-testing/dist/index.cjs +8 -6
- package/realtime-testing/dist/index.cjs.map +1 -1
- package/realtime-testing/dist/index.d.ts +1 -0
- package/realtime-testing/dist/index.js +7 -6
- package/realtime-testing/dist/index.js.map +1 -1
- package/realtime-testing/src/setup-realtime-test.tsx +8 -6
- package/src/logger.ts +5 -1
- package/dist/chunk-OEVFAUPE.js.map +0 -1
- package/realtime-client/src/sync-server-action.ts +0 -168
- package/realtime-client/src/sync-state.ts +0 -19
- package/realtime-react/src/use-sync-server-action.ts +0 -17
- package/realtime-react/src/use-sync.ts +0 -17
- package/realtime-server/src/ipc-socket.ts +0 -230
- package/realtime-server/src/realtime-action-synchronizer.ts +0 -164
- package/realtime-server/src/realtime-server-stores/server-room-store.ts +0 -97
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var Internal = require('atom.io/internal');
|
|
4
4
|
var json = require('atom.io/json');
|
|
5
5
|
var AtomIO = require('atom.io');
|
|
6
6
|
var realtimeClient = require('atom.io/realtime-client');
|
|
@@ -23,13 +23,13 @@ function _interopNamespace(e) {
|
|
|
23
23
|
return Object.freeze(n);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
var
|
|
26
|
+
var Internal__namespace = /*#__PURE__*/_interopNamespace(Internal);
|
|
27
27
|
var AtomIO__namespace = /*#__PURE__*/_interopNamespace(AtomIO);
|
|
28
28
|
|
|
29
29
|
// realtime-client/src/pull-atom.ts
|
|
30
30
|
function pullAtom(token, socket, store) {
|
|
31
31
|
const setServedValue = (data) => {
|
|
32
|
-
|
|
32
|
+
Internal.setIntoStore(token, data, store);
|
|
33
33
|
};
|
|
34
34
|
socket.on(`serve:${token.key}`, setServedValue);
|
|
35
35
|
socket.emit(`sub:${token.key}`);
|
|
@@ -47,7 +47,7 @@ function pullAtomFamilyMember(token, socket, store) {
|
|
|
47
47
|
const { key: familyKey, subKey: serializedSubKey } = token.family;
|
|
48
48
|
const subKey = json.parseJson(serializedSubKey);
|
|
49
49
|
socket == null ? void 0 : socket.on(`serve:${token.key}`, (data) => {
|
|
50
|
-
|
|
50
|
+
Internal.setIntoStore(token, data, store);
|
|
51
51
|
});
|
|
52
52
|
socket == null ? void 0 : socket.emit(`sub:${familyKey}`, subKey);
|
|
53
53
|
return () => {
|
|
@@ -56,15 +56,15 @@ function pullAtomFamilyMember(token, socket, store) {
|
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
58
|
function pullMutableAtom(token, socket, store) {
|
|
59
|
-
const jsonToken =
|
|
60
|
-
const updateToken =
|
|
59
|
+
const jsonToken = Internal.getJsonToken(token);
|
|
60
|
+
const updateToken = Internal.getUpdateToken(token);
|
|
61
61
|
socket.on(`init:${token.key}`, (data) => {
|
|
62
|
-
|
|
62
|
+
Internal.setIntoStore(jsonToken, data, store);
|
|
63
63
|
});
|
|
64
64
|
socket.on(
|
|
65
65
|
`next:${token.key}`,
|
|
66
66
|
(data) => {
|
|
67
|
-
|
|
67
|
+
Internal.setIntoStore(updateToken, data, store);
|
|
68
68
|
}
|
|
69
69
|
);
|
|
70
70
|
socket.emit(`sub:${token.key}`);
|
|
@@ -82,21 +82,21 @@ function pullMutableAtomFamilyMember(token, socket, store) {
|
|
|
82
82
|
}
|
|
83
83
|
const { key: familyKey, subKey: serializedSubKey } = token.family;
|
|
84
84
|
const subKey = json.parseJson(serializedSubKey);
|
|
85
|
-
socket
|
|
86
|
-
const jsonToken =
|
|
87
|
-
|
|
85
|
+
socket.on(`init:${token.key}`, (data) => {
|
|
86
|
+
const jsonToken = Internal.getJsonToken(token);
|
|
87
|
+
Internal.setIntoStore(jsonToken, data, store);
|
|
88
88
|
});
|
|
89
|
-
socket
|
|
89
|
+
socket.on(
|
|
90
90
|
`next:${token.key}`,
|
|
91
91
|
(data) => {
|
|
92
|
-
const trackerToken =
|
|
93
|
-
|
|
92
|
+
const trackerToken = Internal.getUpdateToken(token);
|
|
93
|
+
Internal.setIntoStore(trackerToken, data, store);
|
|
94
94
|
}
|
|
95
95
|
);
|
|
96
|
-
socket
|
|
96
|
+
socket.emit(`sub:${familyKey}`, subKey);
|
|
97
97
|
return () => {
|
|
98
|
-
socket
|
|
99
|
-
socket
|
|
98
|
+
socket.off(`serve:${token.key}`);
|
|
99
|
+
socket.emit(`unsub:${token.key}`);
|
|
100
100
|
};
|
|
101
101
|
}
|
|
102
102
|
|
|
@@ -164,7 +164,7 @@ function pullSelectorFamilyMember(token, socket, store) {
|
|
|
164
164
|
}
|
|
165
165
|
function pushState(token, socket, store) {
|
|
166
166
|
socket.emit(`claim:${token.key}`);
|
|
167
|
-
|
|
167
|
+
Internal__namespace.subscribeToState(
|
|
168
168
|
token,
|
|
169
169
|
({ newValue }) => {
|
|
170
170
|
socket.emit(`pub:${token.key}`, newValue);
|
|
@@ -177,6 +177,23 @@ function pushState(token, socket, store) {
|
|
|
177
177
|
socket.emit(`unclaim:${token.key}`);
|
|
178
178
|
};
|
|
179
179
|
}
|
|
180
|
+
|
|
181
|
+
// __unstable__/web-effects/src/storage.ts
|
|
182
|
+
var persistAtom = (storage) => ({ stringify, parse }) => (key) => ({ setSelf, onSet }) => {
|
|
183
|
+
const savedValue = storage.getItem(key);
|
|
184
|
+
if (savedValue != null)
|
|
185
|
+
setSelf(parse(savedValue));
|
|
186
|
+
onSet(({ newValue }) => {
|
|
187
|
+
if (newValue == null) {
|
|
188
|
+
storage.removeItem(key);
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
storage.setItem(key, stringify(newValue));
|
|
192
|
+
});
|
|
193
|
+
};
|
|
194
|
+
var lazyLocalStorageEffect = persistAtom(localStorage)(JSON);
|
|
195
|
+
|
|
196
|
+
// realtime-client/src/realtime-client-stores/client-main-store.ts
|
|
180
197
|
var myIdState__INTERNAL = AtomIO__namespace.atom({
|
|
181
198
|
key: `mySocketId__INTERNAL`,
|
|
182
199
|
default: void 0
|
|
@@ -185,6 +202,12 @@ var myIdState = AtomIO__namespace.selector({
|
|
|
185
202
|
key: `mySocketId`,
|
|
186
203
|
get: ({ get }) => get(myIdState__INTERNAL)
|
|
187
204
|
});
|
|
205
|
+
var usernameEffects = typeof window === `undefined` ? [] : [lazyLocalStorageEffect(`myUsername`)];
|
|
206
|
+
var myUsernameState = AtomIO__namespace.atom({
|
|
207
|
+
key: `myUsername`,
|
|
208
|
+
default: null,
|
|
209
|
+
effects: usernameEffects
|
|
210
|
+
});
|
|
188
211
|
var optimisticUpdateQueue = AtomIO__namespace.atom({
|
|
189
212
|
key: `updateQueue`,
|
|
190
213
|
default: []
|
|
@@ -196,7 +219,7 @@ var confirmedUpdateQueue = AtomIO__namespace.atom(
|
|
|
196
219
|
}
|
|
197
220
|
);
|
|
198
221
|
function serverAction(token, socket, store) {
|
|
199
|
-
const unsubscribeFromLocalUpdates =
|
|
222
|
+
const unsubscribeFromLocalUpdates = Internal__namespace.subscribeToTransaction(
|
|
200
223
|
token,
|
|
201
224
|
(clientUpdate) => {
|
|
202
225
|
socket.emit(`tx-run:${token.key}`, clientUpdate);
|
|
@@ -210,9 +233,10 @@ function serverAction(token, socket, store) {
|
|
|
210
233
|
}
|
|
211
234
|
function syncContinuity(continuity, socket, store) {
|
|
212
235
|
const continuityKey = continuity.key;
|
|
213
|
-
const optimisticUpdates =
|
|
214
|
-
const confirmedUpdates =
|
|
236
|
+
const optimisticUpdates = Internal.getFromStore(realtimeClient.optimisticUpdateQueue, store);
|
|
237
|
+
const confirmedUpdates = Internal.getFromStore(realtimeClient.confirmedUpdateQueue, store);
|
|
215
238
|
const initializeContinuity = (epoch, payload) => {
|
|
239
|
+
socket.off(`continuity-init:${continuityKey}`, initializeContinuity);
|
|
216
240
|
let i = 0;
|
|
217
241
|
let k = ``;
|
|
218
242
|
let v = null;
|
|
@@ -221,18 +245,26 @@ function syncContinuity(continuity, socket, store) {
|
|
|
221
245
|
k = x;
|
|
222
246
|
} else {
|
|
223
247
|
v = x;
|
|
224
|
-
|
|
248
|
+
if (`type` in k && k.type === `mutable_atom`) {
|
|
249
|
+
k = Internal.getJsonToken(k);
|
|
250
|
+
}
|
|
251
|
+
Internal.setIntoStore(k, v, store);
|
|
225
252
|
}
|
|
226
253
|
i++;
|
|
227
254
|
}
|
|
228
|
-
|
|
255
|
+
Internal.setEpochNumberOfContinuity(continuityKey, epoch, store);
|
|
229
256
|
};
|
|
230
257
|
socket.off(`continuity-init:${continuityKey}`);
|
|
231
258
|
socket.on(`continuity-init:${continuityKey}`, initializeContinuity);
|
|
232
259
|
const registerAndAttemptConfirmedUpdate = (confirmedUpdate) => {
|
|
233
260
|
function reconcileEpoch(optimisticUpdate, confirmedUpdate2) {
|
|
234
|
-
store.logger.info(
|
|
235
|
-
|
|
261
|
+
store.logger.info(
|
|
262
|
+
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
263
|
+
`continuity`,
|
|
264
|
+
continuityKey,
|
|
265
|
+
`reconciling updates`
|
|
266
|
+
);
|
|
267
|
+
Internal.setIntoStore(
|
|
236
268
|
realtimeClient.optimisticUpdateQueue,
|
|
237
269
|
(queue) => {
|
|
238
270
|
queue.shift();
|
|
@@ -261,9 +293,17 @@ function syncContinuity(continuity, socket, store) {
|
|
|
261
293
|
`thought update #${confirmedUpdate2.epoch} was ${optimisticUpdate.key}:${optimisticUpdate.id}, but it was actually ${confirmedUpdate2.key}:${confirmedUpdate2.id}`
|
|
262
294
|
);
|
|
263
295
|
}
|
|
296
|
+
store.logger.info(
|
|
297
|
+
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
298
|
+
`continuity`,
|
|
299
|
+
continuityKey,
|
|
300
|
+
`updates do not match`,
|
|
301
|
+
optimisticUpdate,
|
|
302
|
+
confirmedUpdate2
|
|
303
|
+
);
|
|
264
304
|
const reversedOptimisticUpdates = optimisticUpdates.toReversed();
|
|
265
305
|
for (const subsequentOptimistic of reversedOptimisticUpdates) {
|
|
266
|
-
|
|
306
|
+
Internal.ingestTransactionUpdate(`oldValue`, subsequentOptimistic, store);
|
|
267
307
|
}
|
|
268
308
|
store.logger.info(
|
|
269
309
|
`\u23EA`,
|
|
@@ -272,7 +312,7 @@ function syncContinuity(continuity, socket, store) {
|
|
|
272
312
|
`undid optimistic updates:`,
|
|
273
313
|
reversedOptimisticUpdates
|
|
274
314
|
);
|
|
275
|
-
|
|
315
|
+
Internal.ingestTransactionUpdate(`oldValue`, optimisticUpdate, store);
|
|
276
316
|
store.logger.info(
|
|
277
317
|
`\u23EA`,
|
|
278
318
|
`continuity`,
|
|
@@ -280,7 +320,7 @@ function syncContinuity(continuity, socket, store) {
|
|
|
280
320
|
`undid zeroth optimistic update`,
|
|
281
321
|
optimisticUpdate
|
|
282
322
|
);
|
|
283
|
-
|
|
323
|
+
Internal.ingestTransactionUpdate(`newValue`, confirmedUpdate2, store);
|
|
284
324
|
store.logger.info(
|
|
285
325
|
`\u23E9`,
|
|
286
326
|
`continuity`,
|
|
@@ -295,7 +335,7 @@ function syncContinuity(continuity, socket, store) {
|
|
|
295
335
|
key: subsequentOptimistic.key
|
|
296
336
|
};
|
|
297
337
|
const { id, params } = subsequentOptimistic;
|
|
298
|
-
|
|
338
|
+
Internal.actUponStore(token, id, store)(...params);
|
|
299
339
|
}
|
|
300
340
|
store.logger.info(
|
|
301
341
|
`\u23E9`,
|
|
@@ -306,7 +346,7 @@ function syncContinuity(continuity, socket, store) {
|
|
|
306
346
|
);
|
|
307
347
|
}
|
|
308
348
|
store.logger.info(
|
|
309
|
-
`\u2696\uFE0F`,
|
|
349
|
+
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
310
350
|
`continuity`,
|
|
311
351
|
continuityKey,
|
|
312
352
|
`integrating confirmed update`,
|
|
@@ -315,14 +355,14 @@ function syncContinuity(continuity, socket, store) {
|
|
|
315
355
|
const zerothOptimisticUpdate = optimisticUpdates[0];
|
|
316
356
|
if (zerothOptimisticUpdate) {
|
|
317
357
|
store.logger.info(
|
|
318
|
-
`\u2696\uFE0F`,
|
|
358
|
+
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
319
359
|
`continuity`,
|
|
320
360
|
continuityKey,
|
|
321
361
|
`has optimistic updates to reconcile`
|
|
322
362
|
);
|
|
323
363
|
if (confirmedUpdate.epoch === zerothOptimisticUpdate.epoch) {
|
|
324
364
|
store.logger.info(
|
|
325
|
-
`\u2696\uFE0F`,
|
|
365
|
+
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
326
366
|
`continuity`,
|
|
327
367
|
continuityKey,
|
|
328
368
|
`epoch of confirmed update #${confirmedUpdate.epoch} matches zeroth optimistic update`
|
|
@@ -338,7 +378,7 @@ function syncContinuity(continuity, socket, store) {
|
|
|
338
378
|
}
|
|
339
379
|
} else {
|
|
340
380
|
store.logger.info(
|
|
341
|
-
`\u2696\uFE0F`,
|
|
381
|
+
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
342
382
|
`continuity`,
|
|
343
383
|
continuityKey,
|
|
344
384
|
`epoch of confirmed update #${confirmedUpdate.epoch} does not match zeroth optimistic update #${zerothOptimisticUpdate.epoch}`
|
|
@@ -354,7 +394,7 @@ function syncContinuity(continuity, socket, store) {
|
|
|
354
394
|
`pushing confirmed update to queue`,
|
|
355
395
|
confirmedUpdate
|
|
356
396
|
);
|
|
357
|
-
|
|
397
|
+
Internal.setIntoStore(
|
|
358
398
|
realtimeClient.confirmedUpdateQueue,
|
|
359
399
|
(queue) => {
|
|
360
400
|
queue.push(confirmedUpdate);
|
|
@@ -367,13 +407,13 @@ function syncContinuity(continuity, socket, store) {
|
|
|
367
407
|
}
|
|
368
408
|
} else {
|
|
369
409
|
store.logger.info(
|
|
370
|
-
`\u2696\uFE0F`,
|
|
410
|
+
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
371
411
|
`continuity`,
|
|
372
412
|
continuityKey,
|
|
373
413
|
`has no optimistic updates to deal with`
|
|
374
414
|
);
|
|
375
|
-
const continuityEpoch =
|
|
376
|
-
const isRoot =
|
|
415
|
+
const continuityEpoch = Internal.getEpochNumberOfContinuity(continuityKey, store);
|
|
416
|
+
const isRoot = Internal.isRootStore(store);
|
|
377
417
|
if (isRoot && continuityEpoch === confirmedUpdate.epoch - 1) {
|
|
378
418
|
store.logger.info(
|
|
379
419
|
`\u2705`,
|
|
@@ -381,12 +421,12 @@ function syncContinuity(continuity, socket, store) {
|
|
|
381
421
|
continuityKey,
|
|
382
422
|
`integrating update #${confirmedUpdate.epoch} (${confirmedUpdate.key} ${confirmedUpdate.id})`
|
|
383
423
|
);
|
|
384
|
-
|
|
424
|
+
Internal.ingestTransactionUpdate(`newValue`, confirmedUpdate, store);
|
|
385
425
|
socket.emit(`ack:${continuityKey}`, confirmedUpdate.epoch);
|
|
386
|
-
|
|
426
|
+
Internal.setEpochNumberOfContinuity(continuityKey, confirmedUpdate.epoch, store);
|
|
387
427
|
} else if (isRoot && continuityEpoch !== void 0) {
|
|
388
428
|
store.logger.info(
|
|
389
|
-
`\u2696\uFE0F`,
|
|
429
|
+
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
390
430
|
`continuity`,
|
|
391
431
|
continuityKey,
|
|
392
432
|
`received update #${confirmedUpdate.epoch} but still waiting for update #${continuityEpoch + 1}`,
|
|
@@ -412,7 +452,7 @@ function syncContinuity(continuity, socket, store) {
|
|
|
412
452
|
continuityKey,
|
|
413
453
|
`pushing confirmed update #${confirmedUpdate.epoch} to queue`
|
|
414
454
|
);
|
|
415
|
-
|
|
455
|
+
Internal.setIntoStore(
|
|
416
456
|
realtimeClient.confirmedUpdateQueue,
|
|
417
457
|
(queue) => {
|
|
418
458
|
queue.push(confirmedUpdate);
|
|
@@ -428,8 +468,8 @@ function syncContinuity(continuity, socket, store) {
|
|
|
428
468
|
socket.off(`tx-new:${continuityKey}`);
|
|
429
469
|
socket.on(`tx-new:${continuityKey}`, registerAndAttemptConfirmedUpdate);
|
|
430
470
|
const unsubscribeFunctions = continuity.actions.map((transaction) => {
|
|
431
|
-
|
|
432
|
-
const unsubscribeFromTransactionUpdates =
|
|
471
|
+
Internal.assignTransactionToContinuity(continuityKey, transaction.key, store);
|
|
472
|
+
const unsubscribeFromTransactionUpdates = Internal.subscribeToTransaction(
|
|
433
473
|
transaction,
|
|
434
474
|
(clientUpdate) => {
|
|
435
475
|
store.logger.info(
|
|
@@ -448,7 +488,7 @@ function syncContinuity(continuity, socket, store) {
|
|
|
448
488
|
continuityKey,
|
|
449
489
|
`enqueuing new optimistic update`
|
|
450
490
|
);
|
|
451
|
-
|
|
491
|
+
Internal.setIntoStore(
|
|
452
492
|
realtimeClient.optimisticUpdateQueue,
|
|
453
493
|
(queue) => {
|
|
454
494
|
queue.push(clientUpdate);
|
|
@@ -464,7 +504,7 @@ function syncContinuity(continuity, socket, store) {
|
|
|
464
504
|
continuityKey,
|
|
465
505
|
`replacing existing optimistic update at index ${optimisticUpdateIndex}`
|
|
466
506
|
);
|
|
467
|
-
|
|
507
|
+
Internal.setIntoStore(
|
|
468
508
|
realtimeClient.optimisticUpdateQueue,
|
|
469
509
|
(queue) => {
|
|
470
510
|
queue[optimisticUpdateIndex] = clientUpdate;
|
|
@@ -473,177 +513,52 @@ function syncContinuity(continuity, socket, store) {
|
|
|
473
513
|
store
|
|
474
514
|
);
|
|
475
515
|
}
|
|
476
|
-
socket.emit(`tx-run:${continuityKey}`,
|
|
516
|
+
socket.emit(`tx-run:${continuityKey}`, {
|
|
517
|
+
id: clientUpdate.id,
|
|
518
|
+
key: transaction.key,
|
|
519
|
+
params: clientUpdate.params
|
|
520
|
+
});
|
|
477
521
|
},
|
|
478
522
|
`tx-run:${continuityKey}`,
|
|
479
523
|
store
|
|
480
524
|
);
|
|
481
525
|
return unsubscribeFromTransactionUpdates;
|
|
482
526
|
});
|
|
483
|
-
socket.
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
for (const
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
};
|
|
491
|
-
}
|
|
492
|
-
function syncAction(token, socket, 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);
|
|
496
|
-
const unsubscribeFromLocalUpdates = Internal3__namespace.subscribeToTransaction(
|
|
497
|
-
token,
|
|
498
|
-
(clientUpdate) => {
|
|
499
|
-
const optimisticUpdateQueueIndex = optimisticQueue.findIndex(
|
|
500
|
-
(update) => update.id === clientUpdate.id
|
|
501
|
-
);
|
|
502
|
-
if (optimisticUpdateQueueIndex === -1) {
|
|
503
|
-
Internal3__namespace.setIntoStore(
|
|
504
|
-
optimisticUpdateQueue,
|
|
505
|
-
(queue) => {
|
|
506
|
-
queue.push(clientUpdate);
|
|
507
|
-
queue.sort((a, b) => a.epoch - b.epoch);
|
|
508
|
-
return queue;
|
|
509
|
-
},
|
|
510
|
-
store
|
|
511
|
-
);
|
|
527
|
+
socket.on(`reveal:${continuityKey}`, (revealed) => {
|
|
528
|
+
let i = 0;
|
|
529
|
+
let k = ``;
|
|
530
|
+
let v = null;
|
|
531
|
+
for (const x of revealed) {
|
|
532
|
+
if (i % 2 === 0) {
|
|
533
|
+
k = x;
|
|
512
534
|
} else {
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
(queue) => {
|
|
516
|
-
queue[optimisticUpdateQueueIndex] = clientUpdate;
|
|
517
|
-
return queue;
|
|
518
|
-
},
|
|
519
|
-
store
|
|
520
|
-
);
|
|
521
|
-
}
|
|
522
|
-
socket.emit(`tx-run:${token.key}`, clientUpdate);
|
|
523
|
-
},
|
|
524
|
-
`tx-run:${token.key}`,
|
|
525
|
-
store
|
|
526
|
-
);
|
|
527
|
-
const reconcileUpdates = (optimisticUpdate, confirmedUpdate) => {
|
|
528
|
-
Internal3__namespace.setIntoStore(
|
|
529
|
-
optimisticUpdateQueue,
|
|
530
|
-
(queue) => {
|
|
531
|
-
queue.shift();
|
|
532
|
-
return queue;
|
|
533
|
-
},
|
|
534
|
-
store
|
|
535
|
-
);
|
|
536
|
-
if (optimisticUpdate.id === confirmedUpdate.id) {
|
|
537
|
-
const clientResult = JSON.stringify(optimisticUpdate.updates);
|
|
538
|
-
const serverResult = JSON.stringify(confirmedUpdate.updates);
|
|
539
|
-
if (clientResult === serverResult) {
|
|
540
|
-
store.logger.info(
|
|
541
|
-
`\u2705`,
|
|
542
|
-
`transaction`,
|
|
543
|
-
token.key,
|
|
544
|
-
`results for ${optimisticUpdate.id} match between client and server`
|
|
545
|
-
);
|
|
546
|
-
socket.emit(`tx-ack:${token.key}`, confirmedUpdate.epoch);
|
|
547
|
-
return;
|
|
535
|
+
v = x;
|
|
536
|
+
Internal.setIntoStore(k, v, store);
|
|
548
537
|
}
|
|
549
|
-
|
|
550
|
-
store.logger.info(
|
|
551
|
-
`\u274C`,
|
|
552
|
-
`transaction`,
|
|
553
|
-
token.key,
|
|
554
|
-
`${store.config.name} thought update #${confirmedUpdate.epoch} was ${optimisticUpdate.key}:${optimisticUpdate.id}, but it was actually ${confirmedUpdate.key}:${confirmedUpdate.id}`
|
|
555
|
-
);
|
|
556
|
-
}
|
|
557
|
-
for (const subsequentOptimistic of optimisticQueue.toReversed()) {
|
|
558
|
-
Internal3__namespace.ingestTransactionUpdate(`oldValue`, subsequentOptimistic, store);
|
|
559
|
-
}
|
|
560
|
-
Internal3__namespace.ingestTransactionUpdate(`oldValue`, optimisticUpdate, store);
|
|
561
|
-
Internal3__namespace.ingestTransactionUpdate(`newValue`, confirmedUpdate, store);
|
|
562
|
-
socket.emit(`tx-ack:${token.key}`, confirmedUpdate.epoch);
|
|
563
|
-
for (const subsequentOptimistic of optimisticQueue) {
|
|
564
|
-
const token2 = Object.assign(
|
|
565
|
-
{ type: `transaction` },
|
|
566
|
-
subsequentOptimistic
|
|
567
|
-
);
|
|
568
|
-
const { id, params } = subsequentOptimistic;
|
|
569
|
-
Internal3__namespace.actUponStore(token2, id, store)(...params);
|
|
538
|
+
i++;
|
|
570
539
|
}
|
|
571
|
-
};
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
for (const nextConfirmed of confirmedQueue) {
|
|
578
|
-
const nextOptimistic = optimisticQueue[0];
|
|
579
|
-
if (nextConfirmed.epoch === nextOptimistic.epoch) {
|
|
580
|
-
reconcileUpdates(nextOptimistic, nextConfirmed);
|
|
581
|
-
} else {
|
|
582
|
-
break;
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
} else {
|
|
586
|
-
const hasEnqueuedOptimisticUpdate = optimisticQueue.some(
|
|
587
|
-
(update) => update.epoch === confirmedUpdate.epoch
|
|
588
|
-
);
|
|
589
|
-
if (hasEnqueuedOptimisticUpdate) {
|
|
590
|
-
Internal3__namespace.setIntoStore(
|
|
591
|
-
confirmedUpdateQueue,
|
|
592
|
-
(queue) => {
|
|
593
|
-
queue.push(confirmedUpdate);
|
|
594
|
-
queue.sort((a, b) => a.epoch - b.epoch);
|
|
595
|
-
return queue;
|
|
596
|
-
},
|
|
597
|
-
store
|
|
598
|
-
);
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
} else {
|
|
602
|
-
const continuityEpoch = Internal3__namespace.getEpochNumberOfAction(token.key, store);
|
|
603
|
-
if (Internal3__namespace.isRootStore(store) && continuityEpoch === confirmedUpdate.epoch - 1) {
|
|
604
|
-
Internal3__namespace.ingestTransactionUpdate(`newValue`, confirmedUpdate, store);
|
|
605
|
-
socket.emit(`tx-ack:${token.key}`, confirmedUpdate.epoch);
|
|
606
|
-
Internal3__namespace.setEpochNumberOfAction(token.key, confirmedUpdate.epoch, store);
|
|
607
|
-
} else if (Internal3__namespace.isRootStore(store)) {
|
|
608
|
-
store.logger.info(
|
|
609
|
-
`\u274C`,
|
|
610
|
-
`transaction`,
|
|
611
|
-
token.key,
|
|
612
|
-
`received out-of-order update from server`,
|
|
613
|
-
{
|
|
614
|
-
clientEpoch: store.transactionMeta.epoch,
|
|
615
|
-
serverEpoch: confirmedUpdate.epoch
|
|
616
|
-
}
|
|
617
|
-
);
|
|
540
|
+
});
|
|
541
|
+
socket.on(
|
|
542
|
+
`conceal:${continuityKey}`,
|
|
543
|
+
(concealed) => {
|
|
544
|
+
for (const token of concealed) {
|
|
545
|
+
Internal.deleteAtom(token, store);
|
|
618
546
|
}
|
|
619
547
|
}
|
|
620
|
-
|
|
621
|
-
socket.
|
|
622
|
-
socket.on(`tx-new:${token.key}`, registerAndAttemptConfirmedUpdate);
|
|
623
|
-
socket.emit(`tx-sub:${token.key}`);
|
|
624
|
-
const unsubscribeFromIncomingUpdates = () => {
|
|
625
|
-
socket.off(`tx-new:${token.key}`, registerAndAttemptConfirmedUpdate);
|
|
626
|
-
socket.emit(`tx-unsub:${token.key}`);
|
|
627
|
-
};
|
|
628
|
-
return () => {
|
|
629
|
-
unsubscribeFromLocalUpdates();
|
|
630
|
-
unsubscribeFromIncomingUpdates();
|
|
631
|
-
};
|
|
632
|
-
}
|
|
633
|
-
function syncState(token, socket, store) {
|
|
634
|
-
const setServedValue = (data) => {
|
|
635
|
-
Internal3.setIntoStore(token, data, store);
|
|
636
|
-
};
|
|
637
|
-
socket.on(`value:${token.key}`, setServedValue);
|
|
638
|
-
socket.emit(`get:${token.key}`);
|
|
548
|
+
);
|
|
549
|
+
socket.emit(`get:${continuityKey}`);
|
|
639
550
|
return () => {
|
|
640
|
-
socket.off(`
|
|
551
|
+
socket.off(`continuity-init:${continuityKey}`);
|
|
552
|
+
socket.off(`tx-new:${continuityKey}`);
|
|
553
|
+
for (const unsubscribe of unsubscribeFunctions)
|
|
554
|
+
unsubscribe();
|
|
641
555
|
};
|
|
642
556
|
}
|
|
643
557
|
|
|
644
558
|
exports.confirmedUpdateQueue = confirmedUpdateQueue;
|
|
645
559
|
exports.myIdState = myIdState;
|
|
646
560
|
exports.myIdState__INTERNAL = myIdState__INTERNAL;
|
|
561
|
+
exports.myUsernameState = myUsernameState;
|
|
647
562
|
exports.optimisticUpdateQueue = optimisticUpdateQueue;
|
|
648
563
|
exports.pullAtom = pullAtom;
|
|
649
564
|
exports.pullAtomFamilyMember = pullAtomFamilyMember;
|
|
@@ -653,8 +568,6 @@ exports.pullSelector = pullSelector;
|
|
|
653
568
|
exports.pullSelectorFamilyMember = pullSelectorFamilyMember;
|
|
654
569
|
exports.pushState = pushState;
|
|
655
570
|
exports.serverAction = serverAction;
|
|
656
|
-
exports.syncAction = syncAction;
|
|
657
571
|
exports.syncContinuity = syncContinuity;
|
|
658
|
-
exports.syncState = syncState;
|
|
659
572
|
//# sourceMappingURL=out.js.map
|
|
660
573
|
//# sourceMappingURL=index.cjs.map
|