atom.io 0.19.1 → 0.19.2
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 +99 -79
- package/data/dist/index.js +2 -2
- package/data/src/join.ts +67 -50
- package/dist/{chunk-YDOGCZ53.js → chunk-ATKDGVTV.js} +29 -29
- package/dist/{chunk-7VCCW45K.js → chunk-CC7IF7QF.js} +4 -3
- package/dist/{chunk-WX2NCOZR.js → chunk-FTONNX2R.js} +8 -8
- package/dist/{chunk-7ZR244C2.js → chunk-MSCJWACE.js} +92 -72
- package/dist/index.cjs +14 -7
- package/dist/index.d.ts +23 -35
- package/dist/index.js +14 -7
- package/internal/dist/index.cjs +55 -43
- package/internal/dist/index.d.ts +20 -20
- package/internal/dist/index.js +48 -36
- package/internal/src/atom/create-regular-atom.ts +7 -5
- package/internal/src/atom/delete-atom.ts +2 -2
- package/internal/src/families/create-readonly-selector-family.ts +2 -2
- package/internal/src/families/create-regular-atom-family.ts +1 -1
- package/internal/src/families/create-writable-selector-family.ts +1 -1
- package/internal/src/future.ts +4 -2
- package/internal/src/lineage.ts +1 -0
- package/internal/src/mutable/create-mutable-atom-family.ts +1 -1
- package/internal/src/mutable/create-mutable-atom.ts +7 -5
- package/internal/src/mutable/tracker.ts +3 -3
- package/internal/src/mutable/transceiver.ts +2 -2
- package/internal/src/selector/delete-selector.ts +1 -1
- package/internal/src/set-state/copy-mutable-if-needed.ts +1 -1
- package/internal/src/store/deposit.ts +5 -5
- package/internal/src/store/store.ts +5 -5
- package/internal/src/store/withdraw.ts +4 -5
- package/internal/src/subject.ts +3 -1
- package/internal/src/subscribe/subscribe-to-transaction.ts +4 -4
- package/internal/src/timeline/add-atom-to-timeline.ts +13 -8
- package/internal/src/timeline/create-timeline.ts +3 -4
- package/internal/src/transaction/act-upon-store.ts +5 -5
- package/internal/src/transaction/apply-transaction.ts +4 -4
- package/internal/src/transaction/build-transaction.ts +9 -6
- package/internal/src/transaction/create-transaction.ts +10 -10
- package/internal/src/transaction/index.ts +3 -3
- package/internal/src/transaction/is-root-store.ts +2 -2
- package/introspection/dist/index.d.ts +3 -3
- package/introspection/src/attach-introspection-states.ts +3 -3
- package/introspection/src/attach-transaction-index.ts +4 -4
- package/introspection/src/attach-transaction-logs.ts +8 -4
- package/json/dist/index.cjs +6 -2
- package/json/dist/index.js +6 -2
- package/json/src/select-json-family.ts +3 -2
- package/json/src/select-json.ts +3 -1
- package/package.json +243 -241
- package/react/dist/index.cjs +9 -3
- package/react/dist/index.js +9 -3
- package/react/src/use-i.ts +3 -1
- package/react/src/use-tl.ts +6 -2
- package/react-devtools/dist/index.cjs +116 -53
- package/react-devtools/dist/index.d.ts +3 -5
- package/react-devtools/dist/index.js +113 -51
- package/react-devtools/src/AtomIODevtools.tsx +3 -1
- package/react-devtools/src/Button.tsx +3 -1
- package/react-devtools/src/StateIndex.tsx +6 -2
- package/react-devtools/src/TimelineIndex.tsx +6 -2
- package/react-devtools/src/TransactionIndex.tsx +3 -3
- package/react-devtools/src/Updates.tsx +14 -6
- package/realtime/dist/index.cjs +1 -0
- package/realtime/dist/index.d.ts +2 -2
- package/realtime/dist/index.js +1 -0
- package/realtime/src/realtime-continuity.ts +4 -3
- package/realtime-client/dist/index.cjs +29 -29
- package/realtime-client/dist/index.d.ts +2 -2
- package/realtime-client/dist/index.js +1 -1
- package/realtime-client/src/server-action.ts +2 -2
- package/realtime-client/src/sync-continuity.ts +23 -23
- package/realtime-react/dist/index.cjs +29 -29
- package/realtime-react/dist/index.d.ts +2 -2
- package/realtime-react/dist/index.js +1 -1
- package/realtime-react/src/use-server-action.ts +3 -3
- package/realtime-server/dist/index.cjs +54 -44
- package/realtime-server/dist/index.d.ts +5 -5
- package/realtime-server/dist/index.js +34 -24
- package/realtime-server/src/ipc-sockets/child-socket.ts +6 -6
- package/realtime-server/src/ipc-sockets/custom-socket.ts +4 -8
- package/realtime-server/src/ipc-sockets/parent-socket.ts +13 -7
- package/realtime-server/src/realtime-action-receiver.ts +7 -5
- package/realtime-server/src/realtime-continuity-synchronizer.ts +3 -3
- package/realtime-server/src/realtime-state-receiver.ts +3 -1
- package/realtime-testing/dist/index.cjs +15 -13
- package/realtime-testing/dist/index.js +9 -7
- package/realtime-testing/src/setup-realtime-test.tsx +6 -4
- package/src/atom.ts +4 -8
- package/src/dispose.ts +1 -0
- package/src/index.ts +2 -9
- package/src/selector.ts +4 -8
- package/src/silo.ts +9 -3
- package/src/subscribe.ts +6 -6
- package/src/timeline.ts +4 -4
- package/src/transaction.ts +24 -24
- package/transceivers/set-rtx/dist/index.cjs +11 -12
- package/transceivers/set-rtx/dist/index.js +11 -12
- package/transceivers/set-rtx/src/set-rtx.ts +10 -10
|
@@ -256,8 +256,8 @@ function syncContinuity(continuity, socket, store) {
|
|
|
256
256
|
};
|
|
257
257
|
socket.off(`continuity-init:${continuityKey}`);
|
|
258
258
|
socket.on(`continuity-init:${continuityKey}`, initializeContinuity);
|
|
259
|
-
const registerAndAttemptConfirmedUpdate = (
|
|
260
|
-
function reconcileEpoch(optimisticUpdate,
|
|
259
|
+
const registerAndAttemptConfirmedUpdate = (confirmed) => {
|
|
260
|
+
function reconcileEpoch(optimisticUpdate, confirmedUpdate) {
|
|
261
261
|
store.logger.info(
|
|
262
262
|
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
263
263
|
`continuity`,
|
|
@@ -272,9 +272,9 @@ function syncContinuity(continuity, socket, store) {
|
|
|
272
272
|
},
|
|
273
273
|
store
|
|
274
274
|
);
|
|
275
|
-
if (optimisticUpdate.id ===
|
|
275
|
+
if (optimisticUpdate.id === confirmedUpdate.id) {
|
|
276
276
|
const clientResult = JSON.stringify(optimisticUpdate.updates);
|
|
277
|
-
const serverResult = JSON.stringify(
|
|
277
|
+
const serverResult = JSON.stringify(confirmedUpdate.updates);
|
|
278
278
|
if (clientResult === serverResult) {
|
|
279
279
|
store.logger.info(
|
|
280
280
|
`\u2705`,
|
|
@@ -282,7 +282,7 @@ function syncContinuity(continuity, socket, store) {
|
|
|
282
282
|
continuityKey,
|
|
283
283
|
`results for ${optimisticUpdate.id} match between client and server`
|
|
284
284
|
);
|
|
285
|
-
socket.emit(`ack:${continuityKey}`,
|
|
285
|
+
socket.emit(`ack:${continuityKey}`, confirmedUpdate.epoch);
|
|
286
286
|
return;
|
|
287
287
|
}
|
|
288
288
|
} else {
|
|
@@ -290,7 +290,7 @@ function syncContinuity(continuity, socket, store) {
|
|
|
290
290
|
`\u274C`,
|
|
291
291
|
`continuity`,
|
|
292
292
|
continuityKey,
|
|
293
|
-
`thought update #${
|
|
293
|
+
`thought update #${confirmedUpdate.epoch} was ${optimisticUpdate.key}:${optimisticUpdate.id}, but it was actually ${confirmedUpdate.key}:${confirmedUpdate.id}`
|
|
294
294
|
);
|
|
295
295
|
}
|
|
296
296
|
store.logger.info(
|
|
@@ -299,7 +299,7 @@ function syncContinuity(continuity, socket, store) {
|
|
|
299
299
|
continuityKey,
|
|
300
300
|
`updates do not match`,
|
|
301
301
|
optimisticUpdate,
|
|
302
|
-
|
|
302
|
+
confirmedUpdate
|
|
303
303
|
);
|
|
304
304
|
const reversedOptimisticUpdates = optimisticUpdates.toReversed();
|
|
305
305
|
for (const subsequentOptimistic of reversedOptimisticUpdates) {
|
|
@@ -320,15 +320,15 @@ function syncContinuity(continuity, socket, store) {
|
|
|
320
320
|
`undid zeroth optimistic update`,
|
|
321
321
|
optimisticUpdate
|
|
322
322
|
);
|
|
323
|
-
Internal.ingestTransactionUpdate(`newValue`,
|
|
323
|
+
Internal.ingestTransactionUpdate(`newValue`, confirmedUpdate, store);
|
|
324
324
|
store.logger.info(
|
|
325
325
|
`\u23E9`,
|
|
326
326
|
`continuity`,
|
|
327
327
|
continuityKey,
|
|
328
328
|
`applied confirmed update`,
|
|
329
|
-
|
|
329
|
+
confirmedUpdate
|
|
330
330
|
);
|
|
331
|
-
socket.emit(`ack:${continuityKey}`,
|
|
331
|
+
socket.emit(`ack:${continuityKey}`, confirmedUpdate.epoch);
|
|
332
332
|
for (const subsequentOptimistic of optimisticUpdates) {
|
|
333
333
|
const token = {
|
|
334
334
|
type: `transaction`,
|
|
@@ -350,7 +350,7 @@ function syncContinuity(continuity, socket, store) {
|
|
|
350
350
|
`continuity`,
|
|
351
351
|
continuityKey,
|
|
352
352
|
`integrating confirmed update`,
|
|
353
|
-
{ confirmedUpdate, confirmedUpdates, optimisticUpdates }
|
|
353
|
+
{ confirmedUpdate: confirmed, confirmedUpdates, optimisticUpdates }
|
|
354
354
|
);
|
|
355
355
|
const zerothOptimisticUpdate = optimisticUpdates[0];
|
|
356
356
|
if (zerothOptimisticUpdate) {
|
|
@@ -360,14 +360,14 @@ function syncContinuity(continuity, socket, store) {
|
|
|
360
360
|
continuityKey,
|
|
361
361
|
`has optimistic updates to reconcile`
|
|
362
362
|
);
|
|
363
|
-
if (
|
|
363
|
+
if (confirmed.epoch === zerothOptimisticUpdate.epoch) {
|
|
364
364
|
store.logger.info(
|
|
365
365
|
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
366
366
|
`continuity`,
|
|
367
367
|
continuityKey,
|
|
368
|
-
`epoch of confirmed update #${
|
|
368
|
+
`epoch of confirmed update #${confirmed.epoch} matches zeroth optimistic update`
|
|
369
369
|
);
|
|
370
|
-
reconcileEpoch(zerothOptimisticUpdate,
|
|
370
|
+
reconcileEpoch(zerothOptimisticUpdate, confirmed);
|
|
371
371
|
for (const nextConfirmed of confirmedUpdates) {
|
|
372
372
|
const nextOptimistic = optimisticUpdates[0];
|
|
373
373
|
if (nextConfirmed.epoch === (nextOptimistic == null ? void 0 : nextOptimistic.epoch)) {
|
|
@@ -381,10 +381,10 @@ function syncContinuity(continuity, socket, store) {
|
|
|
381
381
|
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
382
382
|
`continuity`,
|
|
383
383
|
continuityKey,
|
|
384
|
-
`epoch of confirmed update #${
|
|
384
|
+
`epoch of confirmed update #${confirmed.epoch} does not match zeroth optimistic update #${zerothOptimisticUpdate.epoch}`
|
|
385
385
|
);
|
|
386
386
|
const confirmedUpdateIsAlreadyEnqueued = confirmedUpdates.some(
|
|
387
|
-
(update) => update.epoch ===
|
|
387
|
+
(update) => update.epoch === confirmed.epoch
|
|
388
388
|
);
|
|
389
389
|
if (!confirmedUpdateIsAlreadyEnqueued) {
|
|
390
390
|
store.logger.info(
|
|
@@ -392,12 +392,12 @@ function syncContinuity(continuity, socket, store) {
|
|
|
392
392
|
`continuity`,
|
|
393
393
|
continuityKey,
|
|
394
394
|
`pushing confirmed update to queue`,
|
|
395
|
-
|
|
395
|
+
confirmed
|
|
396
396
|
);
|
|
397
397
|
Internal.setIntoStore(
|
|
398
398
|
realtimeClient.confirmedUpdateQueue,
|
|
399
399
|
(queue) => {
|
|
400
|
-
queue.push(
|
|
400
|
+
queue.push(confirmed);
|
|
401
401
|
queue.sort((a, b) => a.epoch - b.epoch);
|
|
402
402
|
return queue;
|
|
403
403
|
},
|
|
@@ -414,48 +414,48 @@ function syncContinuity(continuity, socket, store) {
|
|
|
414
414
|
);
|
|
415
415
|
const continuityEpoch = Internal.getEpochNumberOfContinuity(continuityKey, store);
|
|
416
416
|
const isRoot = Internal.isRootStore(store);
|
|
417
|
-
if (isRoot && continuityEpoch ===
|
|
417
|
+
if (isRoot && continuityEpoch === confirmed.epoch - 1) {
|
|
418
418
|
store.logger.info(
|
|
419
419
|
`\u2705`,
|
|
420
420
|
`continuity`,
|
|
421
421
|
continuityKey,
|
|
422
|
-
`integrating update #${
|
|
422
|
+
`integrating update #${confirmed.epoch} (${confirmed.key} ${confirmed.id})`
|
|
423
423
|
);
|
|
424
|
-
Internal.ingestTransactionUpdate(`newValue`,
|
|
425
|
-
socket.emit(`ack:${continuityKey}`,
|
|
426
|
-
Internal.setEpochNumberOfContinuity(continuityKey,
|
|
424
|
+
Internal.ingestTransactionUpdate(`newValue`, confirmed, store);
|
|
425
|
+
socket.emit(`ack:${continuityKey}`, confirmed.epoch);
|
|
426
|
+
Internal.setEpochNumberOfContinuity(continuityKey, confirmed.epoch, store);
|
|
427
427
|
} else if (isRoot && continuityEpoch !== void 0) {
|
|
428
428
|
store.logger.info(
|
|
429
429
|
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
430
430
|
`continuity`,
|
|
431
431
|
continuityKey,
|
|
432
|
-
`received update #${
|
|
432
|
+
`received update #${confirmed.epoch} but still waiting for update #${continuityEpoch + 1}`,
|
|
433
433
|
{
|
|
434
434
|
clientEpoch: continuityEpoch,
|
|
435
|
-
serverEpoch:
|
|
435
|
+
serverEpoch: confirmed.epoch
|
|
436
436
|
}
|
|
437
437
|
);
|
|
438
438
|
const confirmedUpdateIsAlreadyEnqueued = confirmedUpdates.some(
|
|
439
|
-
(update) => update.epoch ===
|
|
439
|
+
(update) => update.epoch === confirmed.epoch
|
|
440
440
|
);
|
|
441
441
|
if (confirmedUpdateIsAlreadyEnqueued) {
|
|
442
442
|
store.logger.info(
|
|
443
443
|
`\u{1F44D}`,
|
|
444
444
|
`continuity`,
|
|
445
445
|
continuityKey,
|
|
446
|
-
`confirmed update #${
|
|
446
|
+
`confirmed update #${confirmed.epoch} is already enqueued`
|
|
447
447
|
);
|
|
448
448
|
} else {
|
|
449
449
|
store.logger.info(
|
|
450
450
|
`\u{1F448}`,
|
|
451
451
|
`continuity`,
|
|
452
452
|
continuityKey,
|
|
453
|
-
`pushing confirmed update #${
|
|
453
|
+
`pushing confirmed update #${confirmed.epoch} to queue`
|
|
454
454
|
);
|
|
455
455
|
Internal.setIntoStore(
|
|
456
456
|
realtimeClient.confirmedUpdateQueue,
|
|
457
457
|
(queue) => {
|
|
458
|
-
queue.push(
|
|
458
|
+
queue.push(confirmed);
|
|
459
459
|
queue.sort((a, b) => a.epoch - b.epoch);
|
|
460
460
|
return queue;
|
|
461
461
|
},
|
|
@@ -26,8 +26,8 @@ declare const myUsernameState: AtomIO.RegularAtomToken<string | null>;
|
|
|
26
26
|
declare const optimisticUpdateQueue: AtomIO.RegularAtomToken<AtomIO.TransactionUpdate<any>[]>;
|
|
27
27
|
declare const confirmedUpdateQueue: AtomIO.RegularAtomToken<AtomIO.TransactionUpdate<any>[]>;
|
|
28
28
|
|
|
29
|
-
declare function serverAction
|
|
29
|
+
declare function serverAction<F extends AtomIO.Func>(token: AtomIO.TransactionToken<F>, socket: Socket, store: Internal.Store): () => void;
|
|
30
30
|
|
|
31
|
-
declare function syncContinuity
|
|
31
|
+
declare function syncContinuity<F extends AtomIO.Func>(continuity: ContinuityToken, socket: Socket, store: Store): () => void;
|
|
32
32
|
|
|
33
33
|
export { confirmedUpdateQueue, myIdState, myIdState__INTERNAL, myUsernameState, optimisticUpdateQueue, pullAtom, pullAtomFamilyMember, pullMutableAtom, pullMutableAtomFamilyMember, pullSelector, pullSelectorFamilyMember, pushState, serverAction, syncContinuity };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { syncContinuity } from '../../dist/chunk-
|
|
1
|
+
export { syncContinuity } from '../../dist/chunk-ATKDGVTV.js';
|
|
2
2
|
export { confirmedUpdateQueue, myIdState, myIdState__INTERNAL, myUsernameState, optimisticUpdateQueue } from '../../dist/chunk-O47EQUM6.js';
|
|
3
3
|
import '../../dist/chunk-BWWVY5O5.js';
|
|
4
4
|
import '../../dist/chunk-U2IICNHQ.js';
|
|
@@ -2,8 +2,8 @@ import type * as AtomIO from "atom.io"
|
|
|
2
2
|
import * as Internal from "atom.io/internal"
|
|
3
3
|
import type { Socket } from "socket.io-client"
|
|
4
4
|
|
|
5
|
-
export function serverAction
|
|
6
|
-
token: AtomIO.TransactionToken
|
|
5
|
+
export function serverAction<F extends AtomIO.Func>(
|
|
6
|
+
token: AtomIO.TransactionToken<F>,
|
|
7
7
|
socket: Socket,
|
|
8
8
|
store: Internal.Store,
|
|
9
9
|
): () => void {
|
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
} from "atom.io/realtime-client"
|
|
22
22
|
import type { Socket } from "socket.io-client"
|
|
23
23
|
|
|
24
|
-
export function syncContinuity
|
|
24
|
+
export function syncContinuity<F extends AtomIO.Func>(
|
|
25
25
|
continuity: ContinuityToken,
|
|
26
26
|
socket: Socket,
|
|
27
27
|
store: Store,
|
|
@@ -54,7 +54,7 @@ export function syncContinuity<ƒ extends AtomIO.ƒn>(
|
|
|
54
54
|
socket.on(`continuity-init:${continuityKey}`, initializeContinuity)
|
|
55
55
|
|
|
56
56
|
const registerAndAttemptConfirmedUpdate = (
|
|
57
|
-
|
|
57
|
+
confirmed: AtomIO.TransactionUpdate<F>,
|
|
58
58
|
) => {
|
|
59
59
|
function reconcileEpoch(
|
|
60
60
|
optimisticUpdate: AtomIO.TransactionUpdate<any>,
|
|
@@ -155,7 +155,7 @@ export function syncContinuity<ƒ extends AtomIO.ƒn>(
|
|
|
155
155
|
`continuity`,
|
|
156
156
|
continuityKey,
|
|
157
157
|
`integrating confirmed update`,
|
|
158
|
-
{ confirmedUpdate, confirmedUpdates, optimisticUpdates },
|
|
158
|
+
{ confirmedUpdate: confirmed, confirmedUpdates, optimisticUpdates },
|
|
159
159
|
)
|
|
160
160
|
const zerothOptimisticUpdate = optimisticUpdates[0]
|
|
161
161
|
if (zerothOptimisticUpdate) {
|
|
@@ -165,14 +165,14 @@ export function syncContinuity<ƒ extends AtomIO.ƒn>(
|
|
|
165
165
|
continuityKey,
|
|
166
166
|
`has optimistic updates to reconcile`,
|
|
167
167
|
)
|
|
168
|
-
if (
|
|
168
|
+
if (confirmed.epoch === zerothOptimisticUpdate.epoch) {
|
|
169
169
|
store.logger.info(
|
|
170
170
|
`🧑⚖️`,
|
|
171
171
|
`continuity`,
|
|
172
172
|
continuityKey,
|
|
173
|
-
`epoch of confirmed update #${
|
|
173
|
+
`epoch of confirmed update #${confirmed.epoch} matches zeroth optimistic update`,
|
|
174
174
|
)
|
|
175
|
-
reconcileEpoch(zerothOptimisticUpdate,
|
|
175
|
+
reconcileEpoch(zerothOptimisticUpdate, confirmed)
|
|
176
176
|
for (const nextConfirmed of confirmedUpdates) {
|
|
177
177
|
const nextOptimistic = optimisticUpdates[0]
|
|
178
178
|
if (nextConfirmed.epoch === nextOptimistic?.epoch) {
|
|
@@ -187,10 +187,10 @@ export function syncContinuity<ƒ extends AtomIO.ƒn>(
|
|
|
187
187
|
`🧑⚖️`,
|
|
188
188
|
`continuity`,
|
|
189
189
|
continuityKey,
|
|
190
|
-
`epoch of confirmed update #${
|
|
190
|
+
`epoch of confirmed update #${confirmed.epoch} does not match zeroth optimistic update #${zerothOptimisticUpdate.epoch}`,
|
|
191
191
|
)
|
|
192
192
|
const confirmedUpdateIsAlreadyEnqueued = confirmedUpdates.some(
|
|
193
|
-
(update) => update.epoch ===
|
|
193
|
+
(update) => update.epoch === confirmed.epoch,
|
|
194
194
|
)
|
|
195
195
|
if (!confirmedUpdateIsAlreadyEnqueued) {
|
|
196
196
|
store.logger.info(
|
|
@@ -198,12 +198,12 @@ export function syncContinuity<ƒ extends AtomIO.ƒn>(
|
|
|
198
198
|
`continuity`,
|
|
199
199
|
continuityKey,
|
|
200
200
|
`pushing confirmed update to queue`,
|
|
201
|
-
|
|
201
|
+
confirmed,
|
|
202
202
|
)
|
|
203
203
|
setIntoStore(
|
|
204
204
|
confirmedUpdateQueue,
|
|
205
205
|
(queue) => {
|
|
206
|
-
queue.push(
|
|
206
|
+
queue.push(confirmed)
|
|
207
207
|
queue.sort((a, b) => a.epoch - b.epoch)
|
|
208
208
|
return queue
|
|
209
209
|
},
|
|
@@ -221,50 +221,50 @@ export function syncContinuity<ƒ extends AtomIO.ƒn>(
|
|
|
221
221
|
const continuityEpoch = getEpochNumberOfContinuity(continuityKey, store)
|
|
222
222
|
const isRoot = isRootStore(store)
|
|
223
223
|
|
|
224
|
-
if (isRoot && continuityEpoch ===
|
|
224
|
+
if (isRoot && continuityEpoch === confirmed.epoch - 1) {
|
|
225
225
|
store.logger.info(
|
|
226
226
|
`✅`,
|
|
227
227
|
`continuity`,
|
|
228
228
|
continuityKey,
|
|
229
|
-
`integrating update #${
|
|
229
|
+
`integrating update #${confirmed.epoch} (${confirmed.key} ${confirmed.id})`,
|
|
230
230
|
)
|
|
231
|
-
ingestTransactionUpdate(`newValue`,
|
|
232
|
-
socket.emit(`ack:${continuityKey}`,
|
|
233
|
-
setEpochNumberOfContinuity(continuityKey,
|
|
231
|
+
ingestTransactionUpdate(`newValue`, confirmed, store)
|
|
232
|
+
socket.emit(`ack:${continuityKey}`, confirmed.epoch)
|
|
233
|
+
setEpochNumberOfContinuity(continuityKey, confirmed.epoch, store)
|
|
234
234
|
} else if (isRoot && continuityEpoch !== undefined) {
|
|
235
235
|
store.logger.info(
|
|
236
236
|
`🧑⚖️`,
|
|
237
237
|
`continuity`,
|
|
238
238
|
continuityKey,
|
|
239
|
-
`received update #${
|
|
240
|
-
|
|
241
|
-
}
|
|
239
|
+
`received update #${confirmed.epoch} but still waiting for update #${
|
|
240
|
+
continuityEpoch + 1
|
|
241
|
+
}`,
|
|
242
242
|
{
|
|
243
243
|
clientEpoch: continuityEpoch,
|
|
244
|
-
serverEpoch:
|
|
244
|
+
serverEpoch: confirmed.epoch,
|
|
245
245
|
},
|
|
246
246
|
)
|
|
247
247
|
const confirmedUpdateIsAlreadyEnqueued = confirmedUpdates.some(
|
|
248
|
-
(update) => update.epoch ===
|
|
248
|
+
(update) => update.epoch === confirmed.epoch,
|
|
249
249
|
)
|
|
250
250
|
if (confirmedUpdateIsAlreadyEnqueued) {
|
|
251
251
|
store.logger.info(
|
|
252
252
|
`👍`,
|
|
253
253
|
`continuity`,
|
|
254
254
|
continuityKey,
|
|
255
|
-
`confirmed update #${
|
|
255
|
+
`confirmed update #${confirmed.epoch} is already enqueued`,
|
|
256
256
|
)
|
|
257
257
|
} else {
|
|
258
258
|
store.logger.info(
|
|
259
259
|
`👈`,
|
|
260
260
|
`continuity`,
|
|
261
261
|
continuityKey,
|
|
262
|
-
`pushing confirmed update #${
|
|
262
|
+
`pushing confirmed update #${confirmed.epoch} to queue`,
|
|
263
263
|
)
|
|
264
264
|
setIntoStore(
|
|
265
265
|
confirmedUpdateQueue,
|
|
266
266
|
(queue) => {
|
|
267
|
-
queue.push(
|
|
267
|
+
queue.push(confirmed)
|
|
268
268
|
queue.sort((a, b) => a.epoch - b.epoch)
|
|
269
269
|
return queue
|
|
270
270
|
},
|
|
@@ -194,8 +194,8 @@ function syncContinuity(continuity, socket, store) {
|
|
|
194
194
|
};
|
|
195
195
|
socket.off(`continuity-init:${continuityKey}`);
|
|
196
196
|
socket.on(`continuity-init:${continuityKey}`, initializeContinuity);
|
|
197
|
-
const registerAndAttemptConfirmedUpdate = (
|
|
198
|
-
function reconcileEpoch(optimisticUpdate,
|
|
197
|
+
const registerAndAttemptConfirmedUpdate = (confirmed) => {
|
|
198
|
+
function reconcileEpoch(optimisticUpdate, confirmedUpdate) {
|
|
199
199
|
store.logger.info(
|
|
200
200
|
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
201
201
|
`continuity`,
|
|
@@ -210,9 +210,9 @@ function syncContinuity(continuity, socket, store) {
|
|
|
210
210
|
},
|
|
211
211
|
store
|
|
212
212
|
);
|
|
213
|
-
if (optimisticUpdate.id ===
|
|
213
|
+
if (optimisticUpdate.id === confirmedUpdate.id) {
|
|
214
214
|
const clientResult = JSON.stringify(optimisticUpdate.updates);
|
|
215
|
-
const serverResult = JSON.stringify(
|
|
215
|
+
const serverResult = JSON.stringify(confirmedUpdate.updates);
|
|
216
216
|
if (clientResult === serverResult) {
|
|
217
217
|
store.logger.info(
|
|
218
218
|
`\u2705`,
|
|
@@ -220,7 +220,7 @@ function syncContinuity(continuity, socket, store) {
|
|
|
220
220
|
continuityKey,
|
|
221
221
|
`results for ${optimisticUpdate.id} match between client and server`
|
|
222
222
|
);
|
|
223
|
-
socket.emit(`ack:${continuityKey}`,
|
|
223
|
+
socket.emit(`ack:${continuityKey}`, confirmedUpdate.epoch);
|
|
224
224
|
return;
|
|
225
225
|
}
|
|
226
226
|
} else {
|
|
@@ -228,7 +228,7 @@ function syncContinuity(continuity, socket, store) {
|
|
|
228
228
|
`\u274C`,
|
|
229
229
|
`continuity`,
|
|
230
230
|
continuityKey,
|
|
231
|
-
`thought update #${
|
|
231
|
+
`thought update #${confirmedUpdate.epoch} was ${optimisticUpdate.key}:${optimisticUpdate.id}, but it was actually ${confirmedUpdate.key}:${confirmedUpdate.id}`
|
|
232
232
|
);
|
|
233
233
|
}
|
|
234
234
|
store.logger.info(
|
|
@@ -237,7 +237,7 @@ function syncContinuity(continuity, socket, store) {
|
|
|
237
237
|
continuityKey,
|
|
238
238
|
`updates do not match`,
|
|
239
239
|
optimisticUpdate,
|
|
240
|
-
|
|
240
|
+
confirmedUpdate
|
|
241
241
|
);
|
|
242
242
|
const reversedOptimisticUpdates = optimisticUpdates.toReversed();
|
|
243
243
|
for (const subsequentOptimistic of reversedOptimisticUpdates) {
|
|
@@ -258,15 +258,15 @@ function syncContinuity(continuity, socket, store) {
|
|
|
258
258
|
`undid zeroth optimistic update`,
|
|
259
259
|
optimisticUpdate
|
|
260
260
|
);
|
|
261
|
-
internal.ingestTransactionUpdate(`newValue`,
|
|
261
|
+
internal.ingestTransactionUpdate(`newValue`, confirmedUpdate, store);
|
|
262
262
|
store.logger.info(
|
|
263
263
|
`\u23E9`,
|
|
264
264
|
`continuity`,
|
|
265
265
|
continuityKey,
|
|
266
266
|
`applied confirmed update`,
|
|
267
|
-
|
|
267
|
+
confirmedUpdate
|
|
268
268
|
);
|
|
269
|
-
socket.emit(`ack:${continuityKey}`,
|
|
269
|
+
socket.emit(`ack:${continuityKey}`, confirmedUpdate.epoch);
|
|
270
270
|
for (const subsequentOptimistic of optimisticUpdates) {
|
|
271
271
|
const token = {
|
|
272
272
|
type: `transaction`,
|
|
@@ -288,7 +288,7 @@ function syncContinuity(continuity, socket, store) {
|
|
|
288
288
|
`continuity`,
|
|
289
289
|
continuityKey,
|
|
290
290
|
`integrating confirmed update`,
|
|
291
|
-
{ confirmedUpdate, confirmedUpdates, optimisticUpdates }
|
|
291
|
+
{ confirmedUpdate: confirmed, confirmedUpdates, optimisticUpdates }
|
|
292
292
|
);
|
|
293
293
|
const zerothOptimisticUpdate = optimisticUpdates[0];
|
|
294
294
|
if (zerothOptimisticUpdate) {
|
|
@@ -298,14 +298,14 @@ function syncContinuity(continuity, socket, store) {
|
|
|
298
298
|
continuityKey,
|
|
299
299
|
`has optimistic updates to reconcile`
|
|
300
300
|
);
|
|
301
|
-
if (
|
|
301
|
+
if (confirmed.epoch === zerothOptimisticUpdate.epoch) {
|
|
302
302
|
store.logger.info(
|
|
303
303
|
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
304
304
|
`continuity`,
|
|
305
305
|
continuityKey,
|
|
306
|
-
`epoch of confirmed update #${
|
|
306
|
+
`epoch of confirmed update #${confirmed.epoch} matches zeroth optimistic update`
|
|
307
307
|
);
|
|
308
|
-
reconcileEpoch(zerothOptimisticUpdate,
|
|
308
|
+
reconcileEpoch(zerothOptimisticUpdate, confirmed);
|
|
309
309
|
for (const nextConfirmed of confirmedUpdates) {
|
|
310
310
|
const nextOptimistic = optimisticUpdates[0];
|
|
311
311
|
if (nextConfirmed.epoch === (nextOptimistic == null ? void 0 : nextOptimistic.epoch)) {
|
|
@@ -319,10 +319,10 @@ function syncContinuity(continuity, socket, store) {
|
|
|
319
319
|
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
320
320
|
`continuity`,
|
|
321
321
|
continuityKey,
|
|
322
|
-
`epoch of confirmed update #${
|
|
322
|
+
`epoch of confirmed update #${confirmed.epoch} does not match zeroth optimistic update #${zerothOptimisticUpdate.epoch}`
|
|
323
323
|
);
|
|
324
324
|
const confirmedUpdateIsAlreadyEnqueued = confirmedUpdates.some(
|
|
325
|
-
(update) => update.epoch ===
|
|
325
|
+
(update) => update.epoch === confirmed.epoch
|
|
326
326
|
);
|
|
327
327
|
if (!confirmedUpdateIsAlreadyEnqueued) {
|
|
328
328
|
store.logger.info(
|
|
@@ -330,12 +330,12 @@ function syncContinuity(continuity, socket, store) {
|
|
|
330
330
|
`continuity`,
|
|
331
331
|
continuityKey,
|
|
332
332
|
`pushing confirmed update to queue`,
|
|
333
|
-
|
|
333
|
+
confirmed
|
|
334
334
|
);
|
|
335
335
|
internal.setIntoStore(
|
|
336
336
|
RTC.confirmedUpdateQueue,
|
|
337
337
|
(queue) => {
|
|
338
|
-
queue.push(
|
|
338
|
+
queue.push(confirmed);
|
|
339
339
|
queue.sort((a, b) => a.epoch - b.epoch);
|
|
340
340
|
return queue;
|
|
341
341
|
},
|
|
@@ -352,48 +352,48 @@ function syncContinuity(continuity, socket, store) {
|
|
|
352
352
|
);
|
|
353
353
|
const continuityEpoch = internal.getEpochNumberOfContinuity(continuityKey, store);
|
|
354
354
|
const isRoot = internal.isRootStore(store);
|
|
355
|
-
if (isRoot && continuityEpoch ===
|
|
355
|
+
if (isRoot && continuityEpoch === confirmed.epoch - 1) {
|
|
356
356
|
store.logger.info(
|
|
357
357
|
`\u2705`,
|
|
358
358
|
`continuity`,
|
|
359
359
|
continuityKey,
|
|
360
|
-
`integrating update #${
|
|
360
|
+
`integrating update #${confirmed.epoch} (${confirmed.key} ${confirmed.id})`
|
|
361
361
|
);
|
|
362
|
-
internal.ingestTransactionUpdate(`newValue`,
|
|
363
|
-
socket.emit(`ack:${continuityKey}`,
|
|
364
|
-
internal.setEpochNumberOfContinuity(continuityKey,
|
|
362
|
+
internal.ingestTransactionUpdate(`newValue`, confirmed, store);
|
|
363
|
+
socket.emit(`ack:${continuityKey}`, confirmed.epoch);
|
|
364
|
+
internal.setEpochNumberOfContinuity(continuityKey, confirmed.epoch, store);
|
|
365
365
|
} else if (isRoot && continuityEpoch !== void 0) {
|
|
366
366
|
store.logger.info(
|
|
367
367
|
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
368
368
|
`continuity`,
|
|
369
369
|
continuityKey,
|
|
370
|
-
`received update #${
|
|
370
|
+
`received update #${confirmed.epoch} but still waiting for update #${continuityEpoch + 1}`,
|
|
371
371
|
{
|
|
372
372
|
clientEpoch: continuityEpoch,
|
|
373
|
-
serverEpoch:
|
|
373
|
+
serverEpoch: confirmed.epoch
|
|
374
374
|
}
|
|
375
375
|
);
|
|
376
376
|
const confirmedUpdateIsAlreadyEnqueued = confirmedUpdates.some(
|
|
377
|
-
(update) => update.epoch ===
|
|
377
|
+
(update) => update.epoch === confirmed.epoch
|
|
378
378
|
);
|
|
379
379
|
if (confirmedUpdateIsAlreadyEnqueued) {
|
|
380
380
|
store.logger.info(
|
|
381
381
|
`\u{1F44D}`,
|
|
382
382
|
`continuity`,
|
|
383
383
|
continuityKey,
|
|
384
|
-
`confirmed update #${
|
|
384
|
+
`confirmed update #${confirmed.epoch} is already enqueued`
|
|
385
385
|
);
|
|
386
386
|
} else {
|
|
387
387
|
store.logger.info(
|
|
388
388
|
`\u{1F448}`,
|
|
389
389
|
`continuity`,
|
|
390
390
|
continuityKey,
|
|
391
|
-
`pushing confirmed update #${
|
|
391
|
+
`pushing confirmed update #${confirmed.epoch} to queue`
|
|
392
392
|
);
|
|
393
393
|
internal.setIntoStore(
|
|
394
394
|
RTC.confirmedUpdateQueue,
|
|
395
395
|
(queue) => {
|
|
396
|
-
queue.push(
|
|
396
|
+
queue.push(confirmed);
|
|
397
397
|
queue.sort((a, b) => a.epoch - b.epoch);
|
|
398
398
|
return queue;
|
|
399
399
|
},
|
|
@@ -32,9 +32,9 @@ declare function usePullSelectorFamilyMember<T, K extends Json.Serializable, Key
|
|
|
32
32
|
|
|
33
33
|
declare function usePush<J extends Json.Serializable>(token: AtomIO.WritableToken<J>): <New extends J>(next: New | ((old: J) => New)) => void;
|
|
34
34
|
|
|
35
|
-
declare function useServerAction
|
|
35
|
+
declare function useServerAction<F extends AtomIO.Func>(token: AtomIO.TransactionToken<F>): (...parameters: Parameters<F>) => ReturnType<F>;
|
|
36
36
|
|
|
37
|
-
type PerspectiveToken<F extends AtomFamilyToken<any>, T extends F extends AtomFamilyToken<infer
|
|
37
|
+
type PerspectiveToken<F extends AtomFamilyToken<any>, T extends F extends AtomFamilyToken<infer U, any> ? U : never> = {
|
|
38
38
|
type: `realtime_perspective`;
|
|
39
39
|
resourceAtoms: F;
|
|
40
40
|
viewAtoms: ReadableFamilyToken<ReadableToken<T>[], string>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { syncContinuity } from '../../dist/chunk-
|
|
1
|
+
import { syncContinuity } from '../../dist/chunk-ATKDGVTV.js';
|
|
2
2
|
import '../../dist/chunk-U2IICNHQ.js';
|
|
3
3
|
import { useI, StoreContext, useO } from 'atom.io/react';
|
|
4
4
|
import * as RTC from 'atom.io/realtime-client';
|
|
@@ -6,9 +6,9 @@ import * as React from "react"
|
|
|
6
6
|
|
|
7
7
|
import { useRealtimeService } from "./use-realtime-service"
|
|
8
8
|
|
|
9
|
-
export function useServerAction
|
|
10
|
-
token: AtomIO.TransactionToken
|
|
11
|
-
): (...parameters: Parameters
|
|
9
|
+
export function useServerAction<F extends AtomIO.Func>(
|
|
10
|
+
token: AtomIO.TransactionToken<F>,
|
|
11
|
+
): (...parameters: Parameters<F>) => ReturnType<F> {
|
|
12
12
|
const store = React.useContext(StoreContext)
|
|
13
13
|
|
|
14
14
|
useRealtimeService(`tx:${token.key}`, (socket) =>
|