atom.io 0.16.3 → 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 +36 -57
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +64 -53
- package/dist/index.js +15 -36
- package/dist/index.js.map +1 -1
- package/internal/dist/index.cjs +211 -81
- package/internal/dist/index.cjs.map +1 -1
- package/internal/dist/index.d.ts +100 -72
- package/internal/dist/index.js +200 -75
- package/internal/dist/index.js.map +1 -1
- package/internal/src/arbitrary.ts +3 -0
- package/internal/src/atom/create-regular-atom.ts +2 -3
- 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/get-state/get-from-store.ts +14 -0
- package/internal/src/get-state/index.ts +2 -0
- package/internal/src/{read-or-compute-value.ts → get-state/read-or-compute-value.ts} +3 -3
- package/internal/src/index.ts +7 -6
- package/internal/src/ingest-updates/ingest-atom-update.ts +2 -2
- package/internal/src/ingest-updates/ingest-transaction-update.ts +0 -1
- package/internal/src/mutable/create-mutable-atom.ts +3 -4
- package/internal/src/mutable/tracker.ts +18 -13
- package/internal/src/selector/create-standalone-selector.ts +0 -2
- package/internal/src/selector/register-selector.ts +1 -1
- package/internal/src/set-state/index.ts +1 -0
- package/internal/src/set-state/set-atom.ts +15 -19
- package/internal/src/set-state/set-into-store.ts +24 -0
- package/internal/src/store/store.ts +14 -2
- package/internal/src/store/withdraw.ts +72 -2
- package/internal/src/subscribe/subscribe-to-root-atoms.ts +1 -1
- 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 +11 -8
- 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 +3 -3
- package/react/dist/index.cjs.map +1 -1
- package/react/dist/index.d.ts +1 -1
- package/react/dist/index.js +5 -5
- package/react/dist/index.js.map +1 -1
- package/react/src/use-i.ts +2 -3
- package/react/src/use-json.ts +1 -1
- package/react/src/use-o.ts +3 -4
- 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 +403 -59
- package/realtime-client/dist/index.cjs.map +1 -1
- package/realtime-client/dist/index.d.ts +16 -9
- package/realtime-client/dist/index.js +114 -48
- 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} +5 -5
- package/realtime-client/src/{pull-state.ts → pull-atom.ts} +5 -5
- package/realtime-client/src/{pull-mutable-family-member.ts → pull-mutable-atom-family-member.ts} +5 -5
- package/realtime-client/src/{pull-mutable.ts → pull-mutable-atom.ts} +5 -5
- 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 +22 -21
- package/realtime-client/src/sync-state.ts +3 -3
- 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.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-family-member.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 +582 -256
- package/realtime-server/dist/index.cjs.map +1 -1
- package/realtime-server/dist/index.d.ts +124 -49
- package/realtime-server/dist/index.js +566 -249
- 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 +53 -35
- package/realtime-server/src/realtime-continuity-synchronizer.ts +247 -0
- package/realtime-server/src/realtime-family-provider.ts +37 -73
- package/realtime-server/src/realtime-mutable-family-provider.ts +26 -87
- package/realtime-server/src/realtime-mutable-provider.ts +3 -2
- 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-provider.ts +3 -3
- package/realtime-server/src/realtime-state-receiver.ts +2 -3
- package/realtime-server/src/realtime-state-synchronizer.ts +3 -3
- 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/get-state.ts +2 -11
- package/src/logger.ts +10 -5
- package/src/selector.ts +44 -25
- package/src/set-state.ts +1 -13
- package/src/silo.ts +7 -3
- 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
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var AtomIO7 = require('atom.io');
|
|
4
|
-
var json = require('atom.io/json');
|
|
5
3
|
var Internal3 = require('atom.io/internal');
|
|
4
|
+
var json = require('atom.io/json');
|
|
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;
|
|
@@ -22,13 +23,13 @@ function _interopNamespace(e) {
|
|
|
22
23
|
return Object.freeze(n);
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
var AtomIO7__namespace = /*#__PURE__*/_interopNamespace(AtomIO7);
|
|
26
26
|
var Internal3__namespace = /*#__PURE__*/_interopNamespace(Internal3);
|
|
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
|
};
|
|
33
34
|
socket.on(`serve:${token.key}`, setServedValue);
|
|
34
35
|
socket.emit(`sub:${token.key}`);
|
|
@@ -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 () => {
|
|
@@ -46,7 +47,7 @@ function pullFamilyMember(token, socket, store) {
|
|
|
46
47
|
const { key: familyKey, subKey: serializedSubKey } = token.family;
|
|
47
48
|
const subKey = json.parseJson(serializedSubKey);
|
|
48
49
|
socket == null ? void 0 : socket.on(`serve:${token.key}`, (data) => {
|
|
49
|
-
|
|
50
|
+
Internal3.setIntoStore(token, data, store);
|
|
50
51
|
});
|
|
51
52
|
socket == null ? void 0 : socket.emit(`sub:${familyKey}`, subKey);
|
|
52
53
|
return () => {
|
|
@@ -54,16 +55,16 @@ 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) => {
|
|
61
|
-
|
|
62
|
+
Internal3.setIntoStore(jsonToken, data, store);
|
|
62
63
|
});
|
|
63
64
|
socket.on(
|
|
64
65
|
`next:${token.key}`,
|
|
65
66
|
(data) => {
|
|
66
|
-
|
|
67
|
+
Internal3.setIntoStore(updateToken, data, store);
|
|
67
68
|
}
|
|
68
69
|
);
|
|
69
70
|
socket.emit(`sub:${token.key}`);
|
|
@@ -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 () => {
|
|
@@ -83,13 +84,13 @@ function pullMutableFamilyMember(token, socket, store) {
|
|
|
83
84
|
const subKey = json.parseJson(serializedSubKey);
|
|
84
85
|
socket == null ? void 0 : socket.on(`init:${token.key}`, (data) => {
|
|
85
86
|
const jsonToken = Internal3.getJsonToken(token);
|
|
86
|
-
|
|
87
|
+
Internal3.setIntoStore(jsonToken, data, store);
|
|
87
88
|
});
|
|
88
89
|
socket == null ? void 0 : socket.on(
|
|
89
90
|
`next:${token.key}`,
|
|
90
91
|
(data) => {
|
|
91
92
|
const trackerToken = Internal3.getUpdateToken(token);
|
|
92
|
-
|
|
93
|
+
Internal3.setIntoStore(trackerToken, data, store);
|
|
93
94
|
}
|
|
94
95
|
);
|
|
95
96
|
socket == null ? void 0 : socket.emit(`sub:${familyKey}`, subKey);
|
|
@@ -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,32 +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
|
-
const
|
|
493
|
+
Internal3__namespace.assignTransactionToContinuity(`default`, token.key, store);
|
|
494
|
+
const optimisticQueue = Internal3__namespace.getFromStore(optimisticUpdateQueue, store);
|
|
495
|
+
const confirmedQueue = Internal3__namespace.getFromStore(confirmedUpdateQueue, store);
|
|
155
496
|
const unsubscribeFromLocalUpdates = Internal3__namespace.subscribeToTransaction(
|
|
156
497
|
token,
|
|
157
498
|
(clientUpdate) => {
|
|
@@ -159,8 +500,8 @@ function syncAction(token, socket, store) {
|
|
|
159
500
|
(update) => update.id === clientUpdate.id
|
|
160
501
|
);
|
|
161
502
|
if (optimisticUpdateQueueIndex === -1) {
|
|
162
|
-
|
|
163
|
-
|
|
503
|
+
Internal3__namespace.setIntoStore(
|
|
504
|
+
optimisticUpdateQueue,
|
|
164
505
|
(queue) => {
|
|
165
506
|
queue.push(clientUpdate);
|
|
166
507
|
queue.sort((a, b) => a.epoch - b.epoch);
|
|
@@ -168,25 +509,24 @@ function syncAction(token, socket, store) {
|
|
|
168
509
|
},
|
|
169
510
|
store
|
|
170
511
|
);
|
|
171
|
-
socket.emit(`tx-run:${token.key}`, clientUpdate);
|
|
172
512
|
} else {
|
|
173
|
-
|
|
174
|
-
|
|
513
|
+
Internal3__namespace.setIntoStore(
|
|
514
|
+
optimisticUpdateQueue,
|
|
175
515
|
(queue) => {
|
|
176
516
|
queue[optimisticUpdateQueueIndex] = clientUpdate;
|
|
177
517
|
return queue;
|
|
178
518
|
},
|
|
179
519
|
store
|
|
180
520
|
);
|
|
181
|
-
socket.emit(`tx-run:${token.key}`, clientUpdate);
|
|
182
521
|
}
|
|
522
|
+
socket.emit(`tx-run:${token.key}`, clientUpdate);
|
|
183
523
|
},
|
|
184
524
|
`tx-run:${token.key}`,
|
|
185
525
|
store
|
|
186
526
|
);
|
|
187
527
|
const reconcileUpdates = (optimisticUpdate, confirmedUpdate) => {
|
|
188
|
-
|
|
189
|
-
|
|
528
|
+
Internal3__namespace.setIntoStore(
|
|
529
|
+
optimisticUpdateQueue,
|
|
190
530
|
(queue) => {
|
|
191
531
|
queue.shift();
|
|
192
532
|
return queue;
|
|
@@ -226,7 +566,7 @@ function syncAction(token, socket, store) {
|
|
|
226
566
|
subsequentOptimistic
|
|
227
567
|
);
|
|
228
568
|
const { id, params } = subsequentOptimistic;
|
|
229
|
-
|
|
569
|
+
Internal3__namespace.actUponStore(token2, id, store)(...params);
|
|
230
570
|
}
|
|
231
571
|
};
|
|
232
572
|
const registerAndAttemptConfirmedUpdate = (confirmedUpdate) => {
|
|
@@ -247,8 +587,8 @@ function syncAction(token, socket, store) {
|
|
|
247
587
|
(update) => update.epoch === confirmedUpdate.epoch
|
|
248
588
|
);
|
|
249
589
|
if (hasEnqueuedOptimisticUpdate) {
|
|
250
|
-
|
|
251
|
-
|
|
590
|
+
Internal3__namespace.setIntoStore(
|
|
591
|
+
confirmedUpdateQueue,
|
|
252
592
|
(queue) => {
|
|
253
593
|
queue.push(confirmedUpdate);
|
|
254
594
|
queue.sort((a, b) => a.epoch - b.epoch);
|
|
@@ -259,11 +599,12 @@ function syncAction(token, socket, store) {
|
|
|
259
599
|
}
|
|
260
600
|
}
|
|
261
601
|
} else {
|
|
262
|
-
|
|
602
|
+
const continuityEpoch = Internal3__namespace.getEpochNumberOfAction(token.key, store);
|
|
603
|
+
if (Internal3__namespace.isRootStore(store) && continuityEpoch === confirmedUpdate.epoch - 1) {
|
|
263
604
|
Internal3__namespace.ingestTransactionUpdate(`newValue`, confirmedUpdate, store);
|
|
264
605
|
socket.emit(`tx-ack:${token.key}`, confirmedUpdate.epoch);
|
|
265
|
-
|
|
266
|
-
} else if (isRootStore(store)) {
|
|
606
|
+
Internal3__namespace.setEpochNumberOfAction(token.key, confirmedUpdate.epoch, store);
|
|
607
|
+
} else if (Internal3__namespace.isRootStore(store)) {
|
|
267
608
|
store.logger.info(
|
|
268
609
|
`\u274C`,
|
|
269
610
|
`transaction`,
|
|
@@ -291,7 +632,7 @@ function syncAction(token, socket, store) {
|
|
|
291
632
|
}
|
|
292
633
|
function syncState(token, socket, store) {
|
|
293
634
|
const setServedValue = (data) => {
|
|
294
|
-
|
|
635
|
+
Internal3.setIntoStore(token, data, store);
|
|
295
636
|
};
|
|
296
637
|
socket.on(`value:${token.key}`, setServedValue);
|
|
297
638
|
socket.emit(`get:${token.key}`);
|
|
@@ -300,17 +641,20 @@ function syncState(token, socket, store) {
|
|
|
300
641
|
};
|
|
301
642
|
}
|
|
302
643
|
|
|
303
|
-
exports.
|
|
644
|
+
exports.confirmedUpdateQueue = confirmedUpdateQueue;
|
|
304
645
|
exports.myIdState = myIdState;
|
|
305
646
|
exports.myIdState__INTERNAL = myIdState__INTERNAL;
|
|
306
|
-
exports.
|
|
307
|
-
exports.
|
|
308
|
-
exports.
|
|
309
|
-
exports.
|
|
310
|
-
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;
|
|
311
654
|
exports.pushState = pushState;
|
|
312
655
|
exports.serverAction = serverAction;
|
|
313
656
|
exports.syncAction = syncAction;
|
|
657
|
+
exports.syncContinuity = syncContinuity;
|
|
314
658
|
exports.syncState = syncState;
|
|
315
659
|
//# sourceMappingURL=out.js.map
|
|
316
660
|
//# sourceMappingURL=index.cjs.map
|