atom.io 0.17.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/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-IZHOMSXA.js +331 -0
- 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 +4 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +66 -51
- package/dist/index.js +5 -11
- package/dist/index.js.map +1 -1
- package/internal/dist/index.cjs +187 -58
- package/internal/dist/index.cjs.map +1 -1
- package/internal/dist/index.d.ts +95 -71
- package/internal/dist/index.js +179 -53
- package/internal/dist/index.js.map +1 -1
- package/internal/src/arbitrary.ts +3 -0
- package/internal/src/atom/delete-atom.ts +7 -6
- package/internal/src/caching.ts +6 -4
- 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-atom-update.ts +6 -2
- 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/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 +15 -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 +6 -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 +30 -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 +4 -0
- package/package.json +241 -230
- 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 +91 -108
- package/react-devtools/dist/index.js.map +1 -1
- package/react-devtools/src/StateEditor.tsx +4 -4
- package/react-devtools/src/StateIndex.tsx +1 -4
- package/react-devtools/src/TimelineIndex.tsx +3 -3
- package/react-devtools/src/TransactionIndex.tsx +9 -8
- package/react-devtools/src/index.ts +2 -2
- package/realtime/dist/index.cjs +120 -0
- package/realtime/dist/index.cjs.map +1 -0
- package/realtime/dist/index.d.ts +146 -0
- package/realtime/dist/index.js +111 -0
- package/realtime/dist/index.js.map +1 -0
- package/realtime/package.json +16 -0
- package/realtime/src/index.ts +2 -0
- package/realtime/src/realtime-continuity.ts +162 -0
- package/realtime/src/shared-room-store.ts +48 -0
- package/realtime-client/dist/index.cjs +424 -170
- package/realtime-client/dist/index.cjs.map +1 -1
- package/realtime-client/dist/index.d.ts +15 -11
- package/realtime-client/dist/index.js +96 -177
- package/realtime-client/dist/index.js.map +1 -1
- package/realtime-client/src/index.ts +8 -7
- 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} +6 -6
- 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 +12 -2
- package/realtime-client/src/realtime-client-stores/client-sync-store.ts +7 -7
- package/realtime-client/src/sync-continuity.ts +368 -0
- package/realtime-react/dist/index.cjs +367 -27
- package/realtime-react/dist/index.cjs.map +1 -1
- package/realtime-react/dist/index.d.ts +24 -8
- package/realtime-react/dist/index.js +38 -22
- package/realtime-react/dist/index.js.map +1 -1
- package/realtime-react/src/index.ts +6 -5
- package/realtime-react/src/use-pull-atom-family-member.ts +21 -0
- package/realtime-react/src/{use-sync.ts → use-pull-atom.ts} +4 -4
- 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-server/dist/index.cjs +769 -371
- package/realtime-server/dist/index.cjs.map +1 -1
- package/realtime-server/dist/index.d.ts +130 -60
- package/realtime-server/dist/index.js +753 -361
- package/realtime-server/dist/index.js.map +1 -1
- package/realtime-server/src/index.ts +17 -3
- 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-action-receiver.ts +8 -5
- package/realtime-server/src/realtime-continuity-synchronizer.ts +376 -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 +4 -1
- package/realtime-server/src/realtime-server-stores/realtime-continuity-store.ts +109 -0
- 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 +51 -98
- 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 +34 -32
- package/realtime-testing/dist/index.cjs.map +1 -1
- package/realtime-testing/dist/index.d.ts +1 -0
- package/realtime-testing/dist/index.js +33 -31
- package/realtime-testing/dist/index.js.map +1 -1
- package/realtime-testing/src/setup-realtime-test.tsx +44 -32
- package/src/atom.ts +49 -31
- package/src/logger.ts +14 -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
- package/realtime-client/src/sync-server-action.ts +0 -170
- package/realtime-client/src/sync-state.ts +0 -19
- package/realtime-react/src/use-pull-family-member.ts +0 -16
- package/realtime-react/src/use-sync-server-action.ts +0 -16
- package/realtime-server/src/realtime-action-synchronizer.ts +0 -152
|
@@ -1,8 +1,9 @@
|
|
|
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
|
+
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
|
|
26
|
+
var Internal__namespace = /*#__PURE__*/_interopNamespace(Internal);
|
|
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
|
+
Internal.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
|
+
Internal.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
|
-
const jsonToken =
|
|
59
|
-
const updateToken =
|
|
58
|
+
function pullMutableAtom(token, socket, store) {
|
|
59
|
+
const jsonToken = Internal.getJsonToken(token);
|
|
60
|
+
const updateToken = Internal.getUpdateToken(token);
|
|
60
61
|
socket.on(`init:${token.key}`, (data) => {
|
|
61
|
-
|
|
62
|
+
Internal.setIntoStore(jsonToken, data, store);
|
|
62
63
|
});
|
|
63
64
|
socket.on(
|
|
64
65
|
`next:${token.key}`,
|
|
65
66
|
(data) => {
|
|
66
|
-
|
|
67
|
+
Internal.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 () => {
|
|
@@ -81,26 +82,89 @@ function pullMutableFamilyMember(token, socket, store) {
|
|
|
81
82
|
}
|
|
82
83
|
const { key: familyKey, subKey: serializedSubKey } = token.family;
|
|
83
84
|
const subKey = json.parseJson(serializedSubKey);
|
|
84
|
-
socket
|
|
85
|
-
const jsonToken =
|
|
86
|
-
|
|
85
|
+
socket.on(`init:${token.key}`, (data) => {
|
|
86
|
+
const jsonToken = Internal.getJsonToken(token);
|
|
87
|
+
Internal.setIntoStore(jsonToken, data, store);
|
|
87
88
|
});
|
|
88
|
-
socket
|
|
89
|
+
socket.on(
|
|
89
90
|
`next:${token.key}`,
|
|
90
91
|
(data) => {
|
|
91
|
-
const trackerToken =
|
|
92
|
-
|
|
92
|
+
const trackerToken = Internal.getUpdateToken(token);
|
|
93
|
+
Internal.setIntoStore(trackerToken, data, store);
|
|
93
94
|
}
|
|
94
95
|
);
|
|
95
|
-
socket
|
|
96
|
+
socket.emit(`sub:${familyKey}`, subKey);
|
|
96
97
|
return () => {
|
|
97
|
-
socket
|
|
98
|
-
socket
|
|
98
|
+
socket.off(`serve:${token.key}`);
|
|
99
|
+
socket.emit(`unsub:${token.key}`);
|
|
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
|
+
}
|
|
99
163
|
};
|
|
100
164
|
}
|
|
101
165
|
function pushState(token, socket, store) {
|
|
102
166
|
socket.emit(`claim:${token.key}`);
|
|
103
|
-
|
|
167
|
+
Internal__namespace.subscribeToState(
|
|
104
168
|
token,
|
|
105
169
|
({ newValue }) => {
|
|
106
170
|
socket.emit(`pub:${token.key}`, newValue);
|
|
@@ -113,145 +177,225 @@ function pushState(token, socket, store) {
|
|
|
113
177
|
socket.emit(`unclaim:${token.key}`);
|
|
114
178
|
};
|
|
115
179
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
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
|
|
129
197
|
var myIdState__INTERNAL = AtomIO__namespace.atom({
|
|
130
|
-
key: `
|
|
198
|
+
key: `mySocketId__INTERNAL`,
|
|
131
199
|
default: void 0
|
|
132
200
|
});
|
|
133
201
|
var myIdState = AtomIO__namespace.selector({
|
|
134
|
-
key: `
|
|
202
|
+
key: `mySocketId`,
|
|
135
203
|
get: ({ get }) => get(myIdState__INTERNAL)
|
|
136
204
|
});
|
|
137
|
-
var
|
|
138
|
-
|
|
139
|
-
|
|
205
|
+
var usernameEffects = typeof window === `undefined` ? [] : [lazyLocalStorageEffect(`myUsername`)];
|
|
206
|
+
var myUsernameState = AtomIO__namespace.atom({
|
|
207
|
+
key: `myUsername`,
|
|
208
|
+
default: null,
|
|
209
|
+
effects: usernameEffects
|
|
140
210
|
});
|
|
141
|
-
var
|
|
142
|
-
key: `
|
|
211
|
+
var optimisticUpdateQueue = AtomIO__namespace.atom({
|
|
212
|
+
key: `updateQueue`,
|
|
143
213
|
default: []
|
|
144
214
|
});
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
const optimisticQueue = Internal3__namespace.getFromStore(
|
|
154
|
-
optimisticUpdateQueueState,
|
|
155
|
-
store
|
|
156
|
-
);
|
|
157
|
-
const confirmedQueue = Internal3__namespace.getFromStore(confirmedUpdateQueueState, store);
|
|
158
|
-
const unsubscribeFromLocalUpdates = Internal3__namespace.subscribeToTransaction(
|
|
215
|
+
var confirmedUpdateQueue = AtomIO__namespace.atom(
|
|
216
|
+
{
|
|
217
|
+
key: `serverConfirmedUpdateQueue`,
|
|
218
|
+
default: []
|
|
219
|
+
}
|
|
220
|
+
);
|
|
221
|
+
function serverAction(token, socket, store) {
|
|
222
|
+
const unsubscribeFromLocalUpdates = Internal__namespace.subscribeToTransaction(
|
|
159
223
|
token,
|
|
160
224
|
(clientUpdate) => {
|
|
161
|
-
|
|
162
|
-
(update) => update.id === clientUpdate.id
|
|
163
|
-
);
|
|
164
|
-
if (optimisticUpdateQueueIndex === -1) {
|
|
165
|
-
Internal3__namespace.setIntoStore(
|
|
166
|
-
optimisticUpdateQueueState,
|
|
167
|
-
(queue) => {
|
|
168
|
-
queue.push(clientUpdate);
|
|
169
|
-
queue.sort((a, b) => a.epoch - b.epoch);
|
|
170
|
-
return queue;
|
|
171
|
-
},
|
|
172
|
-
store
|
|
173
|
-
);
|
|
174
|
-
socket.emit(`tx-run:${token.key}`, clientUpdate);
|
|
175
|
-
} else {
|
|
176
|
-
Internal3__namespace.setIntoStore(
|
|
177
|
-
optimisticUpdateQueueState,
|
|
178
|
-
(queue) => {
|
|
179
|
-
queue[optimisticUpdateQueueIndex] = clientUpdate;
|
|
180
|
-
return queue;
|
|
181
|
-
},
|
|
182
|
-
store
|
|
183
|
-
);
|
|
184
|
-
socket.emit(`tx-run:${token.key}`, clientUpdate);
|
|
185
|
-
}
|
|
225
|
+
socket.emit(`tx-run:${token.key}`, clientUpdate);
|
|
186
226
|
},
|
|
187
|
-
`tx-run:${token.key}`,
|
|
227
|
+
`tx-run:${token.key}:${socket.id}`,
|
|
188
228
|
store
|
|
189
229
|
);
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
230
|
+
return () => {
|
|
231
|
+
unsubscribeFromLocalUpdates();
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
function syncContinuity(continuity, socket, store) {
|
|
235
|
+
const continuityKey = continuity.key;
|
|
236
|
+
const optimisticUpdates = Internal.getFromStore(realtimeClient.optimisticUpdateQueue, store);
|
|
237
|
+
const confirmedUpdates = Internal.getFromStore(realtimeClient.confirmedUpdateQueue, store);
|
|
238
|
+
const initializeContinuity = (epoch, payload) => {
|
|
239
|
+
socket.off(`continuity-init:${continuityKey}`, initializeContinuity);
|
|
240
|
+
let i = 0;
|
|
241
|
+
let k = ``;
|
|
242
|
+
let v = null;
|
|
243
|
+
for (const x of payload) {
|
|
244
|
+
if (i % 2 === 0) {
|
|
245
|
+
k = x;
|
|
246
|
+
} else {
|
|
247
|
+
v = x;
|
|
248
|
+
if (`type` in k && k.type === `mutable_atom`) {
|
|
249
|
+
k = Internal.getJsonToken(k);
|
|
250
|
+
}
|
|
251
|
+
Internal.setIntoStore(k, v, store);
|
|
252
|
+
}
|
|
253
|
+
i++;
|
|
254
|
+
}
|
|
255
|
+
Internal.setEpochNumberOfContinuity(continuityKey, epoch, store);
|
|
256
|
+
};
|
|
257
|
+
socket.off(`continuity-init:${continuityKey}`);
|
|
258
|
+
socket.on(`continuity-init:${continuityKey}`, initializeContinuity);
|
|
259
|
+
const registerAndAttemptConfirmedUpdate = (confirmedUpdate) => {
|
|
260
|
+
function reconcileEpoch(optimisticUpdate, confirmedUpdate2) {
|
|
261
|
+
store.logger.info(
|
|
262
|
+
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
263
|
+
`continuity`,
|
|
264
|
+
continuityKey,
|
|
265
|
+
`reconciling updates`
|
|
266
|
+
);
|
|
267
|
+
Internal.setIntoStore(
|
|
268
|
+
realtimeClient.optimisticUpdateQueue,
|
|
269
|
+
(queue) => {
|
|
270
|
+
queue.shift();
|
|
271
|
+
return queue;
|
|
272
|
+
},
|
|
273
|
+
store
|
|
274
|
+
);
|
|
275
|
+
if (optimisticUpdate.id === confirmedUpdate2.id) {
|
|
276
|
+
const clientResult = JSON.stringify(optimisticUpdate.updates);
|
|
277
|
+
const serverResult = JSON.stringify(confirmedUpdate2.updates);
|
|
278
|
+
if (clientResult === serverResult) {
|
|
279
|
+
store.logger.info(
|
|
280
|
+
`\u2705`,
|
|
281
|
+
`continuity`,
|
|
282
|
+
continuityKey,
|
|
283
|
+
`results for ${optimisticUpdate.id} match between client and server`
|
|
284
|
+
);
|
|
285
|
+
socket.emit(`ack:${continuityKey}`, confirmedUpdate2.epoch);
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
} else {
|
|
203
289
|
store.logger.info(
|
|
204
|
-
`\
|
|
205
|
-
`
|
|
206
|
-
|
|
207
|
-
`
|
|
290
|
+
`\u274C`,
|
|
291
|
+
`continuity`,
|
|
292
|
+
continuityKey,
|
|
293
|
+
`thought update #${confirmedUpdate2.epoch} was ${optimisticUpdate.key}:${optimisticUpdate.id}, but it was actually ${confirmedUpdate2.key}:${confirmedUpdate2.id}`
|
|
208
294
|
);
|
|
209
|
-
socket.emit(`tx-ack:${token.key}`, confirmedUpdate.epoch);
|
|
210
|
-
return;
|
|
211
295
|
}
|
|
212
|
-
} else {
|
|
213
296
|
store.logger.info(
|
|
214
|
-
`\
|
|
215
|
-
`
|
|
216
|
-
|
|
217
|
-
|
|
297
|
+
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
298
|
+
`continuity`,
|
|
299
|
+
continuityKey,
|
|
300
|
+
`updates do not match`,
|
|
301
|
+
optimisticUpdate,
|
|
302
|
+
confirmedUpdate2
|
|
218
303
|
);
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
304
|
+
const reversedOptimisticUpdates = optimisticUpdates.toReversed();
|
|
305
|
+
for (const subsequentOptimistic of reversedOptimisticUpdates) {
|
|
306
|
+
Internal.ingestTransactionUpdate(`oldValue`, subsequentOptimistic, store);
|
|
307
|
+
}
|
|
308
|
+
store.logger.info(
|
|
309
|
+
`\u23EA`,
|
|
310
|
+
`continuity`,
|
|
311
|
+
continuityKey,
|
|
312
|
+
`undid optimistic updates:`,
|
|
313
|
+
reversedOptimisticUpdates
|
|
314
|
+
);
|
|
315
|
+
Internal.ingestTransactionUpdate(`oldValue`, optimisticUpdate, store);
|
|
316
|
+
store.logger.info(
|
|
317
|
+
`\u23EA`,
|
|
318
|
+
`continuity`,
|
|
319
|
+
continuityKey,
|
|
320
|
+
`undid zeroth optimistic update`,
|
|
321
|
+
optimisticUpdate
|
|
322
|
+
);
|
|
323
|
+
Internal.ingestTransactionUpdate(`newValue`, confirmedUpdate2, store);
|
|
324
|
+
store.logger.info(
|
|
325
|
+
`\u23E9`,
|
|
326
|
+
`continuity`,
|
|
327
|
+
continuityKey,
|
|
328
|
+
`applied confirmed update`,
|
|
329
|
+
confirmedUpdate2
|
|
330
|
+
);
|
|
331
|
+
socket.emit(`ack:${continuityKey}`, confirmedUpdate2.epoch);
|
|
332
|
+
for (const subsequentOptimistic of optimisticUpdates) {
|
|
333
|
+
const token = {
|
|
334
|
+
type: `transaction`,
|
|
335
|
+
key: subsequentOptimistic.key
|
|
336
|
+
};
|
|
337
|
+
const { id, params } = subsequentOptimistic;
|
|
338
|
+
Internal.actUponStore(token, id, store)(...params);
|
|
339
|
+
}
|
|
340
|
+
store.logger.info(
|
|
341
|
+
`\u23E9`,
|
|
342
|
+
`continuity`,
|
|
343
|
+
continuityKey,
|
|
344
|
+
`reapplied subsequent optimistic updates:`,
|
|
345
|
+
optimisticUpdates
|
|
230
346
|
);
|
|
231
|
-
const { id, params } = subsequentOptimistic;
|
|
232
|
-
AtomIO__namespace.runTransaction(token2, id, store)(...params);
|
|
233
347
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
348
|
+
store.logger.info(
|
|
349
|
+
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
350
|
+
`continuity`,
|
|
351
|
+
continuityKey,
|
|
352
|
+
`integrating confirmed update`,
|
|
353
|
+
{ confirmedUpdate, confirmedUpdates, optimisticUpdates }
|
|
354
|
+
);
|
|
355
|
+
const zerothOptimisticUpdate = optimisticUpdates[0];
|
|
237
356
|
if (zerothOptimisticUpdate) {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
357
|
+
store.logger.info(
|
|
358
|
+
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
359
|
+
`continuity`,
|
|
360
|
+
continuityKey,
|
|
361
|
+
`has optimistic updates to reconcile`
|
|
362
|
+
);
|
|
363
|
+
if (confirmedUpdate.epoch === zerothOptimisticUpdate.epoch) {
|
|
364
|
+
store.logger.info(
|
|
365
|
+
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
366
|
+
`continuity`,
|
|
367
|
+
continuityKey,
|
|
368
|
+
`epoch of confirmed update #${confirmedUpdate.epoch} matches zeroth optimistic update`
|
|
369
|
+
);
|
|
370
|
+
reconcileEpoch(zerothOptimisticUpdate, confirmedUpdate);
|
|
371
|
+
for (const nextConfirmed of confirmedUpdates) {
|
|
372
|
+
const nextOptimistic = optimisticUpdates[0];
|
|
373
|
+
if (nextConfirmed.epoch === (nextOptimistic == null ? void 0 : nextOptimistic.epoch)) {
|
|
374
|
+
reconcileEpoch(nextOptimistic, nextConfirmed);
|
|
244
375
|
} else {
|
|
245
376
|
break;
|
|
246
377
|
}
|
|
247
378
|
}
|
|
248
379
|
} else {
|
|
249
|
-
|
|
380
|
+
store.logger.info(
|
|
381
|
+
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
382
|
+
`continuity`,
|
|
383
|
+
continuityKey,
|
|
384
|
+
`epoch of confirmed update #${confirmedUpdate.epoch} does not match zeroth optimistic update #${zerothOptimisticUpdate.epoch}`
|
|
385
|
+
);
|
|
386
|
+
const confirmedUpdateIsAlreadyEnqueued = confirmedUpdates.some(
|
|
250
387
|
(update) => update.epoch === confirmedUpdate.epoch
|
|
251
388
|
);
|
|
252
|
-
if (
|
|
253
|
-
|
|
254
|
-
|
|
389
|
+
if (!confirmedUpdateIsAlreadyEnqueued) {
|
|
390
|
+
store.logger.info(
|
|
391
|
+
`\u{1F448}`,
|
|
392
|
+
`continuity`,
|
|
393
|
+
continuityKey,
|
|
394
|
+
`pushing confirmed update to queue`,
|
|
395
|
+
confirmedUpdate
|
|
396
|
+
);
|
|
397
|
+
Internal.setIntoStore(
|
|
398
|
+
realtimeClient.confirmedUpdateQueue,
|
|
255
399
|
(queue) => {
|
|
256
400
|
queue.push(confirmedUpdate);
|
|
257
401
|
queue.sort((a, b) => a.epoch - b.epoch);
|
|
@@ -262,58 +406,168 @@ function syncAction(token, socket, store) {
|
|
|
262
406
|
}
|
|
263
407
|
}
|
|
264
408
|
} else {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
409
|
+
store.logger.info(
|
|
410
|
+
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
411
|
+
`continuity`,
|
|
412
|
+
continuityKey,
|
|
413
|
+
`has no optimistic updates to deal with`
|
|
414
|
+
);
|
|
415
|
+
const continuityEpoch = Internal.getEpochNumberOfContinuity(continuityKey, store);
|
|
416
|
+
const isRoot = Internal.isRootStore(store);
|
|
417
|
+
if (isRoot && continuityEpoch === confirmedUpdate.epoch - 1) {
|
|
270
418
|
store.logger.info(
|
|
271
|
-
`\
|
|
272
|
-
`
|
|
273
|
-
|
|
274
|
-
`
|
|
419
|
+
`\u2705`,
|
|
420
|
+
`continuity`,
|
|
421
|
+
continuityKey,
|
|
422
|
+
`integrating update #${confirmedUpdate.epoch} (${confirmedUpdate.key} ${confirmedUpdate.id})`
|
|
423
|
+
);
|
|
424
|
+
Internal.ingestTransactionUpdate(`newValue`, confirmedUpdate, store);
|
|
425
|
+
socket.emit(`ack:${continuityKey}`, confirmedUpdate.epoch);
|
|
426
|
+
Internal.setEpochNumberOfContinuity(continuityKey, confirmedUpdate.epoch, store);
|
|
427
|
+
} else if (isRoot && continuityEpoch !== void 0) {
|
|
428
|
+
store.logger.info(
|
|
429
|
+
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
430
|
+
`continuity`,
|
|
431
|
+
continuityKey,
|
|
432
|
+
`received update #${confirmedUpdate.epoch} but still waiting for update #${continuityEpoch + 1}`,
|
|
275
433
|
{
|
|
276
|
-
clientEpoch:
|
|
434
|
+
clientEpoch: continuityEpoch,
|
|
277
435
|
serverEpoch: confirmedUpdate.epoch
|
|
278
436
|
}
|
|
279
437
|
);
|
|
438
|
+
const confirmedUpdateIsAlreadyEnqueued = confirmedUpdates.some(
|
|
439
|
+
(update) => update.epoch === confirmedUpdate.epoch
|
|
440
|
+
);
|
|
441
|
+
if (confirmedUpdateIsAlreadyEnqueued) {
|
|
442
|
+
store.logger.info(
|
|
443
|
+
`\u{1F44D}`,
|
|
444
|
+
`continuity`,
|
|
445
|
+
continuityKey,
|
|
446
|
+
`confirmed update #${confirmedUpdate.epoch} is already enqueued`
|
|
447
|
+
);
|
|
448
|
+
} else {
|
|
449
|
+
store.logger.info(
|
|
450
|
+
`\u{1F448}`,
|
|
451
|
+
`continuity`,
|
|
452
|
+
continuityKey,
|
|
453
|
+
`pushing confirmed update #${confirmedUpdate.epoch} to queue`
|
|
454
|
+
);
|
|
455
|
+
Internal.setIntoStore(
|
|
456
|
+
realtimeClient.confirmedUpdateQueue,
|
|
457
|
+
(queue) => {
|
|
458
|
+
queue.push(confirmedUpdate);
|
|
459
|
+
queue.sort((a, b) => a.epoch - b.epoch);
|
|
460
|
+
return queue;
|
|
461
|
+
},
|
|
462
|
+
store
|
|
463
|
+
);
|
|
464
|
+
}
|
|
280
465
|
}
|
|
281
466
|
}
|
|
282
467
|
};
|
|
283
|
-
socket.off(`tx-new:${
|
|
284
|
-
socket.on(`tx-new:${
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
468
|
+
socket.off(`tx-new:${continuityKey}`);
|
|
469
|
+
socket.on(`tx-new:${continuityKey}`, registerAndAttemptConfirmedUpdate);
|
|
470
|
+
const unsubscribeFunctions = continuity.actions.map((transaction) => {
|
|
471
|
+
Internal.assignTransactionToContinuity(continuityKey, transaction.key, store);
|
|
472
|
+
const unsubscribeFromTransactionUpdates = Internal.subscribeToTransaction(
|
|
473
|
+
transaction,
|
|
474
|
+
(clientUpdate) => {
|
|
475
|
+
store.logger.info(
|
|
476
|
+
`\u{1F91E}`,
|
|
477
|
+
`continuity`,
|
|
478
|
+
continuityKey,
|
|
479
|
+
`enqueuing optimistic update`
|
|
480
|
+
);
|
|
481
|
+
const optimisticUpdateIndex = optimisticUpdates.findIndex(
|
|
482
|
+
(update) => update.id === clientUpdate.id
|
|
483
|
+
);
|
|
484
|
+
if (optimisticUpdateIndex === -1) {
|
|
485
|
+
store.logger.info(
|
|
486
|
+
`\u{1F91E}`,
|
|
487
|
+
`continuity`,
|
|
488
|
+
continuityKey,
|
|
489
|
+
`enqueuing new optimistic update`
|
|
490
|
+
);
|
|
491
|
+
Internal.setIntoStore(
|
|
492
|
+
realtimeClient.optimisticUpdateQueue,
|
|
493
|
+
(queue) => {
|
|
494
|
+
queue.push(clientUpdate);
|
|
495
|
+
queue.sort((a, b) => a.epoch - b.epoch);
|
|
496
|
+
return queue;
|
|
497
|
+
},
|
|
498
|
+
store
|
|
499
|
+
);
|
|
500
|
+
} else {
|
|
501
|
+
store.logger.info(
|
|
502
|
+
`\u{1F91E}`,
|
|
503
|
+
`continuity`,
|
|
504
|
+
continuityKey,
|
|
505
|
+
`replacing existing optimistic update at index ${optimisticUpdateIndex}`
|
|
506
|
+
);
|
|
507
|
+
Internal.setIntoStore(
|
|
508
|
+
realtimeClient.optimisticUpdateQueue,
|
|
509
|
+
(queue) => {
|
|
510
|
+
queue[optimisticUpdateIndex] = clientUpdate;
|
|
511
|
+
return queue;
|
|
512
|
+
},
|
|
513
|
+
store
|
|
514
|
+
);
|
|
515
|
+
}
|
|
516
|
+
socket.emit(`tx-run:${continuityKey}`, {
|
|
517
|
+
id: clientUpdate.id,
|
|
518
|
+
key: transaction.key,
|
|
519
|
+
params: clientUpdate.params
|
|
520
|
+
});
|
|
521
|
+
},
|
|
522
|
+
`tx-run:${continuityKey}`,
|
|
523
|
+
store
|
|
524
|
+
);
|
|
525
|
+
return unsubscribeFromTransactionUpdates;
|
|
526
|
+
});
|
|
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;
|
|
534
|
+
} else {
|
|
535
|
+
v = x;
|
|
536
|
+
Internal.setIntoStore(k, v, store);
|
|
537
|
+
}
|
|
538
|
+
i++;
|
|
539
|
+
}
|
|
540
|
+
});
|
|
541
|
+
socket.on(
|
|
542
|
+
`conceal:${continuityKey}`,
|
|
543
|
+
(concealed) => {
|
|
544
|
+
for (const token of concealed) {
|
|
545
|
+
Internal.deleteAtom(token, store);
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
);
|
|
549
|
+
socket.emit(`get:${continuityKey}`);
|
|
301
550
|
return () => {
|
|
302
|
-
socket.off(`
|
|
551
|
+
socket.off(`continuity-init:${continuityKey}`);
|
|
552
|
+
socket.off(`tx-new:${continuityKey}`);
|
|
553
|
+
for (const unsubscribe of unsubscribeFunctions)
|
|
554
|
+
unsubscribe();
|
|
303
555
|
};
|
|
304
556
|
}
|
|
305
557
|
|
|
306
|
-
exports.
|
|
558
|
+
exports.confirmedUpdateQueue = confirmedUpdateQueue;
|
|
307
559
|
exports.myIdState = myIdState;
|
|
308
560
|
exports.myIdState__INTERNAL = myIdState__INTERNAL;
|
|
309
|
-
exports.
|
|
310
|
-
exports.
|
|
311
|
-
exports.
|
|
312
|
-
exports.
|
|
313
|
-
exports.
|
|
561
|
+
exports.myUsernameState = myUsernameState;
|
|
562
|
+
exports.optimisticUpdateQueue = optimisticUpdateQueue;
|
|
563
|
+
exports.pullAtom = pullAtom;
|
|
564
|
+
exports.pullAtomFamilyMember = pullAtomFamilyMember;
|
|
565
|
+
exports.pullMutableAtom = pullMutableAtom;
|
|
566
|
+
exports.pullMutableAtomFamilyMember = pullMutableAtomFamilyMember;
|
|
567
|
+
exports.pullSelector = pullSelector;
|
|
568
|
+
exports.pullSelectorFamilyMember = pullSelectorFamilyMember;
|
|
314
569
|
exports.pushState = pushState;
|
|
315
570
|
exports.serverAction = serverAction;
|
|
316
|
-
exports.
|
|
317
|
-
exports.syncState = syncState;
|
|
571
|
+
exports.syncContinuity = syncContinuity;
|
|
318
572
|
//# sourceMappingURL=out.js.map
|
|
319
573
|
//# sourceMappingURL=index.cjs.map
|