atom.io 0.25.5 → 0.26.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.js +33 -25
- package/data/package.json +1 -4
- package/data/src/join.ts +0 -1
- package/dist/{chunk-HYXKCFVY.js → chunk-IBTHB2PI.js} +59 -60
- package/dist/{chunk-MR5NETHW.js → chunk-IW6WYRS7.js} +4 -5
- package/dist/chunk-XWL6SNVU.js +7 -0
- package/dist/index.js +33 -21
- package/ephemeral/dist/index.js +1 -1
- package/ephemeral/package.json +1 -4
- package/eslint-plugin/dist/index.d.ts +1 -1
- package/eslint-plugin/dist/index.js +7 -8
- package/eslint-plugin/package.json +1 -4
- package/immortal/dist/index.js +1 -1
- package/immortal/package.json +1 -4
- package/internal/dist/index.js +173 -160
- package/internal/package.json +1 -4
- package/introspection/dist/index.js +32 -30
- package/introspection/package.json +1 -4
- package/json/dist/index.js +1 -1
- package/json/package.json +1 -4
- package/package.json +27 -58
- package/react/dist/index.js +2 -2
- package/react/package.json +1 -4
- package/react-devtools/dist/index.js +75 -68
- package/react-devtools/package.json +1 -4
- package/realtime/dist/index.js +8 -9
- package/realtime/package.json +1 -4
- package/realtime-client/dist/index.js +6 -6
- package/realtime-client/package.json +1 -4
- package/realtime-react/dist/index.js +9 -11
- package/realtime-react/package.json +1 -4
- package/realtime-server/dist/index.js +59 -54
- package/realtime-server/package.json +1 -4
- package/realtime-testing/dist/index.js +3 -3
- package/realtime-testing/package.json +1 -4
- package/transceivers/set-rtx/dist/index.js +11 -11
- package/transceivers/set-rtx/package.json +1 -4
- package/data/dist/index.cjs +0 -953
- package/dist/chunk-S4N6XNPH.js +0 -38
- package/dist/index.cjs +0 -215
- package/ephemeral/dist/index.cjs +0 -11
- package/eslint-plugin/dist/index.cjs +0 -388
- package/immortal/dist/index.cjs +0 -14
- package/internal/dist/index.cjs +0 -3405
- package/introspection/dist/index.cjs +0 -449
- package/json/dist/index.cjs +0 -128
- package/react/dist/index.cjs +0 -118
- package/react-devtools/dist/index.cjs +0 -2191
- package/realtime/dist/index.cjs +0 -120
- package/realtime-client/dist/index.cjs +0 -569
- package/realtime-react/dist/index.cjs +0 -189
- package/realtime-server/dist/index.cjs +0 -965
- package/realtime-testing/dist/index.cjs +0 -201
- package/transceivers/set-rtx/dist/index.cjs +0 -215
package/realtime/dist/index.cjs
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var internal = require('atom.io/internal');
|
|
4
|
-
var atom_io = require('atom.io');
|
|
5
|
-
var data = require('atom.io/data');
|
|
6
|
-
var setRtx = require('atom.io/transceivers/set-rtx');
|
|
7
|
-
|
|
8
|
-
// realtime/src/realtime-continuity.ts
|
|
9
|
-
var InvariantMap = class extends Map {
|
|
10
|
-
set(key, value) {
|
|
11
|
-
if (this.has(key)) {
|
|
12
|
-
console.warn(`Tried to set a key that already exists in an InvariantMap`, {
|
|
13
|
-
key,
|
|
14
|
-
value
|
|
15
|
-
});
|
|
16
|
-
return this;
|
|
17
|
-
}
|
|
18
|
-
return super.set(key, value);
|
|
19
|
-
}
|
|
20
|
-
clear() {
|
|
21
|
-
throw new Error(`Cannot clear an InvariantMap`);
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
var _SyncGroup = class _SyncGroup {
|
|
25
|
-
constructor(key) {
|
|
26
|
-
this.key = key;
|
|
27
|
-
this.type = `continuity`;
|
|
28
|
-
this.globals = [];
|
|
29
|
-
this.actions = [];
|
|
30
|
-
this.perspectives = [];
|
|
31
|
-
}
|
|
32
|
-
static create(key, builder) {
|
|
33
|
-
const group = new _SyncGroup(key);
|
|
34
|
-
const { type, globals, actions, perspectives } = builder(group);
|
|
35
|
-
const token = { type, key, globals, actions, perspectives };
|
|
36
|
-
_SyncGroup.existing.set(key, token);
|
|
37
|
-
return token;
|
|
38
|
-
}
|
|
39
|
-
add(...args) {
|
|
40
|
-
const zeroth = args[0];
|
|
41
|
-
if (zeroth.type === `atom` || zeroth.type === `mutable_atom`) {
|
|
42
|
-
const globals = args;
|
|
43
|
-
for (const global of globals) {
|
|
44
|
-
switch (global.type) {
|
|
45
|
-
case `atom`:
|
|
46
|
-
this.globals.push(global);
|
|
47
|
-
break;
|
|
48
|
-
case `mutable_atom`:
|
|
49
|
-
this.globals.push(internal.getUpdateToken(global));
|
|
50
|
-
break;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
} else if (zeroth.type === `transaction`) {
|
|
54
|
-
const actions = args;
|
|
55
|
-
this.actions.push(...actions);
|
|
56
|
-
} else {
|
|
57
|
-
const [family, index] = args;
|
|
58
|
-
this.perspectives.push({
|
|
59
|
-
type: `realtime_perspective`,
|
|
60
|
-
resourceAtoms: family,
|
|
61
|
-
viewAtoms: index
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
return this;
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
_SyncGroup.existing = new InvariantMap();
|
|
68
|
-
var SyncGroup = _SyncGroup;
|
|
69
|
-
function continuity(options) {
|
|
70
|
-
const { key, config } = options;
|
|
71
|
-
const token = SyncGroup.create(key, config);
|
|
72
|
-
const { actions } = token;
|
|
73
|
-
for (const action of actions) {
|
|
74
|
-
internal.assignTransactionToContinuity(key, action.key, internal.IMPLICIT.STORE);
|
|
75
|
-
}
|
|
76
|
-
internal.setEpochNumberOfContinuity(key, -1, internal.IMPLICIT.STORE);
|
|
77
|
-
return token;
|
|
78
|
-
}
|
|
79
|
-
var usersInThisRoomIndex = atom_io.atom({
|
|
80
|
-
key: `usersInRoomIndex`,
|
|
81
|
-
mutable: true,
|
|
82
|
-
default: () => new setRtx.SetRTX(),
|
|
83
|
-
toJson: (set) => set.toJSON(),
|
|
84
|
-
fromJson: (json) => setRtx.SetRTX.fromJSON(json)
|
|
85
|
-
});
|
|
86
|
-
var roomIndex = atom_io.atom({
|
|
87
|
-
key: `roomIndex`,
|
|
88
|
-
default: () => new setRtx.SetRTX(),
|
|
89
|
-
mutable: true,
|
|
90
|
-
toJson: (set) => set.toJSON(),
|
|
91
|
-
fromJson: (json) => setRtx.SetRTX.fromJSON(json)
|
|
92
|
-
});
|
|
93
|
-
var DEFAULT_USER_IN_ROOM_META = {
|
|
94
|
-
enteredAtEpoch: 0
|
|
95
|
-
};
|
|
96
|
-
var usersInRooms = data.join(
|
|
97
|
-
{
|
|
98
|
-
key: `usersInRooms`,
|
|
99
|
-
between: [`room`, `user`],
|
|
100
|
-
cardinality: `1:n`
|
|
101
|
-
},
|
|
102
|
-
DEFAULT_USER_IN_ROOM_META
|
|
103
|
-
);
|
|
104
|
-
var usersInMyRoomView = atom_io.selectorFamily({
|
|
105
|
-
key: `usersInMyRoomView`,
|
|
106
|
-
get: (myUsername) => ({ find }) => {
|
|
107
|
-
const usersInRoomsAtoms = data.getInternalRelations(usersInRooms);
|
|
108
|
-
const myRoomIndex = find(usersInRoomsAtoms, myUsername);
|
|
109
|
-
return [myRoomIndex];
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
exports.DEFAULT_USER_IN_ROOM_META = DEFAULT_USER_IN_ROOM_META;
|
|
114
|
-
exports.InvariantMap = InvariantMap;
|
|
115
|
-
exports.SyncGroup = SyncGroup;
|
|
116
|
-
exports.continuity = continuity;
|
|
117
|
-
exports.roomIndex = roomIndex;
|
|
118
|
-
exports.usersInMyRoomView = usersInMyRoomView;
|
|
119
|
-
exports.usersInRooms = usersInRooms;
|
|
120
|
-
exports.usersInThisRoomIndex = usersInThisRoomIndex;
|
|
@@ -1,569 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var Internal = 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');
|
|
7
|
-
|
|
8
|
-
function _interopNamespace(e) {
|
|
9
|
-
if (e && e.__esModule) return e;
|
|
10
|
-
var n = Object.create(null);
|
|
11
|
-
if (e) {
|
|
12
|
-
Object.keys(e).forEach(function (k) {
|
|
13
|
-
if (k !== 'default') {
|
|
14
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
15
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
16
|
-
enumerable: true,
|
|
17
|
-
get: function () { return e[k]; }
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
n.default = e;
|
|
23
|
-
return Object.freeze(n);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
var Internal__namespace = /*#__PURE__*/_interopNamespace(Internal);
|
|
27
|
-
var AtomIO__namespace = /*#__PURE__*/_interopNamespace(AtomIO);
|
|
28
|
-
|
|
29
|
-
// realtime-client/src/pull-atom.ts
|
|
30
|
-
function pullAtom(token, socket, store) {
|
|
31
|
-
const setServedValue = (data) => {
|
|
32
|
-
Internal.setIntoStore(token, data, store);
|
|
33
|
-
};
|
|
34
|
-
socket.on(`serve:${token.key}`, setServedValue);
|
|
35
|
-
socket.emit(`sub:${token.key}`);
|
|
36
|
-
return () => {
|
|
37
|
-
socket.off(`serve:${token.key}`, setServedValue);
|
|
38
|
-
socket.emit(`unsub:${token.key}`);
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
function pullAtomFamilyMember(token, socket, store) {
|
|
42
|
-
if (!(`family` in token)) {
|
|
43
|
-
console.error(`Token is not a family member:`, token);
|
|
44
|
-
return () => {
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
const { key: familyKey, subKey: serializedSubKey } = token.family;
|
|
48
|
-
const subKey = json.parseJson(serializedSubKey);
|
|
49
|
-
socket == null ? void 0 : socket.on(`serve:${token.key}`, (data) => {
|
|
50
|
-
Internal.setIntoStore(token, data, store);
|
|
51
|
-
});
|
|
52
|
-
socket == null ? void 0 : socket.emit(`sub:${familyKey}`, subKey);
|
|
53
|
-
return () => {
|
|
54
|
-
socket == null ? void 0 : socket.off(`serve:${token.key}`);
|
|
55
|
-
socket == null ? void 0 : socket.emit(`unsub:${token.key}`);
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
function pullMutableAtom(token, socket, store) {
|
|
59
|
-
const jsonToken = Internal.getJsonToken(token, store);
|
|
60
|
-
const updateToken = Internal.getUpdateToken(token);
|
|
61
|
-
socket.on(`init:${token.key}`, (data) => {
|
|
62
|
-
Internal.setIntoStore(jsonToken, data, store);
|
|
63
|
-
});
|
|
64
|
-
socket.on(
|
|
65
|
-
`next:${token.key}`,
|
|
66
|
-
(data) => {
|
|
67
|
-
Internal.setIntoStore(updateToken, data, store);
|
|
68
|
-
}
|
|
69
|
-
);
|
|
70
|
-
socket.emit(`sub:${token.key}`);
|
|
71
|
-
return () => {
|
|
72
|
-
socket.off(`init:${token.key}`);
|
|
73
|
-
socket.off(`next:${token.key}`);
|
|
74
|
-
socket.emit(`unsub:${token.key}`);
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
function pullMutableAtomFamilyMember(token, socket, store) {
|
|
78
|
-
if (!(`family` in token)) {
|
|
79
|
-
console.error(`Token is not a family member:`, token);
|
|
80
|
-
return () => {
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
const { key: familyKey, subKey: serializedSubKey } = token.family;
|
|
84
|
-
const subKey = json.parseJson(serializedSubKey);
|
|
85
|
-
socket.on(`init:${token.key}`, (data) => {
|
|
86
|
-
const jsonToken = Internal.getJsonToken(token, store);
|
|
87
|
-
Internal.setIntoStore(jsonToken, data, store);
|
|
88
|
-
});
|
|
89
|
-
socket.on(
|
|
90
|
-
`next:${token.key}`,
|
|
91
|
-
(data) => {
|
|
92
|
-
const trackerToken = Internal.getUpdateToken(token);
|
|
93
|
-
Internal.setIntoStore(trackerToken, data, store);
|
|
94
|
-
}
|
|
95
|
-
);
|
|
96
|
-
socket.emit(`sub:${familyKey}`, subKey);
|
|
97
|
-
return () => {
|
|
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
|
-
}
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
function pushState(token, socket, store) {
|
|
166
|
-
socket.emit(`claim:${token.key}`);
|
|
167
|
-
Internal__namespace.subscribeToState(
|
|
168
|
-
token,
|
|
169
|
-
({ newValue }) => {
|
|
170
|
-
socket.emit(`pub:${token.key}`, newValue);
|
|
171
|
-
},
|
|
172
|
-
`push`,
|
|
173
|
-
store
|
|
174
|
-
);
|
|
175
|
-
return () => {
|
|
176
|
-
socket.off(`pub:${token.key}`);
|
|
177
|
-
socket.emit(`unclaim:${token.key}`);
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// __unstable__/web-effects/src/storage.ts
|
|
182
|
-
var persistAtom = (storage) => ({ stringify, parse }) => (key) => ({ setSelf, onSet }) => {
|
|
183
|
-
const savedValue = storage.getItem(key);
|
|
184
|
-
if (savedValue != null) setSelf(parse(savedValue));
|
|
185
|
-
onSet(({ newValue }) => {
|
|
186
|
-
if (newValue == null) {
|
|
187
|
-
storage.removeItem(key);
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
storage.setItem(key, stringify(newValue));
|
|
191
|
-
});
|
|
192
|
-
};
|
|
193
|
-
var lazyLocalStorageEffect = persistAtom(window.localStorage)(JSON);
|
|
194
|
-
|
|
195
|
-
// realtime-client/src/realtime-client-stores/client-main-store.ts
|
|
196
|
-
var myIdState__INTERNAL = AtomIO__namespace.atom({
|
|
197
|
-
key: `mySocketId__INTERNAL`,
|
|
198
|
-
default: void 0
|
|
199
|
-
});
|
|
200
|
-
var myIdState = AtomIO__namespace.selector({
|
|
201
|
-
key: `mySocketId`,
|
|
202
|
-
get: ({ get }) => get(myIdState__INTERNAL)
|
|
203
|
-
});
|
|
204
|
-
var usernameEffects = typeof window === `undefined` ? [] : [lazyLocalStorageEffect(`myUsername`)];
|
|
205
|
-
var myUsernameState = AtomIO__namespace.atom({
|
|
206
|
-
key: `myUsername`,
|
|
207
|
-
default: null,
|
|
208
|
-
effects: usernameEffects
|
|
209
|
-
});
|
|
210
|
-
var optimisticUpdateQueue = AtomIO__namespace.atom({
|
|
211
|
-
key: `updateQueue`,
|
|
212
|
-
default: []
|
|
213
|
-
});
|
|
214
|
-
var confirmedUpdateQueue = AtomIO__namespace.atom(
|
|
215
|
-
{
|
|
216
|
-
key: `serverConfirmedUpdateQueue`,
|
|
217
|
-
default: []
|
|
218
|
-
}
|
|
219
|
-
);
|
|
220
|
-
function serverAction(token, socket, store) {
|
|
221
|
-
const unsubscribeFromLocalUpdates = Internal__namespace.subscribeToTransaction(
|
|
222
|
-
token,
|
|
223
|
-
(clientUpdate) => {
|
|
224
|
-
socket.emit(`tx-run:${token.key}`, clientUpdate);
|
|
225
|
-
},
|
|
226
|
-
`tx-run:${token.key}:${socket.id}`,
|
|
227
|
-
store
|
|
228
|
-
);
|
|
229
|
-
return () => {
|
|
230
|
-
unsubscribeFromLocalUpdates();
|
|
231
|
-
};
|
|
232
|
-
}
|
|
233
|
-
function syncContinuity(continuity, socket, store) {
|
|
234
|
-
const continuityKey = continuity.key;
|
|
235
|
-
const optimisticUpdates = Internal.getFromStore(realtimeClient.optimisticUpdateQueue, store);
|
|
236
|
-
const confirmedUpdates = Internal.getFromStore(realtimeClient.confirmedUpdateQueue, store);
|
|
237
|
-
const initializeContinuity = (epoch, payload) => {
|
|
238
|
-
socket.off(`continuity-init:${continuityKey}`, initializeContinuity);
|
|
239
|
-
let i = 0;
|
|
240
|
-
let k = ``;
|
|
241
|
-
let v = null;
|
|
242
|
-
for (const x of payload) {
|
|
243
|
-
if (i % 2 === 0) {
|
|
244
|
-
k = x;
|
|
245
|
-
} else {
|
|
246
|
-
v = x;
|
|
247
|
-
if (`type` in k && k.type === `mutable_atom`) {
|
|
248
|
-
k = Internal.getJsonToken(k, store);
|
|
249
|
-
}
|
|
250
|
-
Internal.setIntoStore(k, v, store);
|
|
251
|
-
}
|
|
252
|
-
i++;
|
|
253
|
-
}
|
|
254
|
-
Internal.setEpochNumberOfContinuity(continuityKey, epoch, store);
|
|
255
|
-
};
|
|
256
|
-
socket.off(`continuity-init:${continuityKey}`);
|
|
257
|
-
socket.on(`continuity-init:${continuityKey}`, initializeContinuity);
|
|
258
|
-
const registerAndAttemptConfirmedUpdate = (confirmed) => {
|
|
259
|
-
function reconcileEpoch(optimisticUpdate, confirmedUpdate) {
|
|
260
|
-
store.logger.info(
|
|
261
|
-
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
262
|
-
`continuity`,
|
|
263
|
-
continuityKey,
|
|
264
|
-
`reconciling updates`
|
|
265
|
-
);
|
|
266
|
-
Internal.setIntoStore(
|
|
267
|
-
realtimeClient.optimisticUpdateQueue,
|
|
268
|
-
(queue) => {
|
|
269
|
-
queue.shift();
|
|
270
|
-
return queue;
|
|
271
|
-
},
|
|
272
|
-
store
|
|
273
|
-
);
|
|
274
|
-
if (optimisticUpdate.id === confirmedUpdate.id) {
|
|
275
|
-
const clientResult = JSON.stringify(optimisticUpdate.updates);
|
|
276
|
-
const serverResult = JSON.stringify(confirmedUpdate.updates);
|
|
277
|
-
if (clientResult === serverResult) {
|
|
278
|
-
store.logger.info(
|
|
279
|
-
`\u2705`,
|
|
280
|
-
`continuity`,
|
|
281
|
-
continuityKey,
|
|
282
|
-
`results for ${optimisticUpdate.id} match between client and server`
|
|
283
|
-
);
|
|
284
|
-
socket.emit(`ack:${continuityKey}`, confirmedUpdate.epoch);
|
|
285
|
-
return;
|
|
286
|
-
}
|
|
287
|
-
} else {
|
|
288
|
-
store.logger.info(
|
|
289
|
-
`\u274C`,
|
|
290
|
-
`continuity`,
|
|
291
|
-
continuityKey,
|
|
292
|
-
`thought update #${confirmedUpdate.epoch} was ${optimisticUpdate.key}:${optimisticUpdate.id}, but it was actually ${confirmedUpdate.key}:${confirmedUpdate.id}`
|
|
293
|
-
);
|
|
294
|
-
}
|
|
295
|
-
store.logger.info(
|
|
296
|
-
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
297
|
-
`continuity`,
|
|
298
|
-
continuityKey,
|
|
299
|
-
`updates do not match`,
|
|
300
|
-
optimisticUpdate,
|
|
301
|
-
confirmedUpdate
|
|
302
|
-
);
|
|
303
|
-
const reversedOptimisticUpdates = optimisticUpdates.toReversed();
|
|
304
|
-
for (const subsequentOptimistic of reversedOptimisticUpdates) {
|
|
305
|
-
Internal.ingestTransactionUpdate(`oldValue`, subsequentOptimistic, store);
|
|
306
|
-
}
|
|
307
|
-
store.logger.info(
|
|
308
|
-
`\u23EA`,
|
|
309
|
-
`continuity`,
|
|
310
|
-
continuityKey,
|
|
311
|
-
`undid optimistic updates:`,
|
|
312
|
-
reversedOptimisticUpdates
|
|
313
|
-
);
|
|
314
|
-
Internal.ingestTransactionUpdate(`oldValue`, optimisticUpdate, store);
|
|
315
|
-
store.logger.info(
|
|
316
|
-
`\u23EA`,
|
|
317
|
-
`continuity`,
|
|
318
|
-
continuityKey,
|
|
319
|
-
`undid zeroth optimistic update`,
|
|
320
|
-
optimisticUpdate
|
|
321
|
-
);
|
|
322
|
-
Internal.ingestTransactionUpdate(`newValue`, confirmedUpdate, store);
|
|
323
|
-
store.logger.info(
|
|
324
|
-
`\u23E9`,
|
|
325
|
-
`continuity`,
|
|
326
|
-
continuityKey,
|
|
327
|
-
`applied confirmed update`,
|
|
328
|
-
confirmedUpdate
|
|
329
|
-
);
|
|
330
|
-
socket.emit(`ack:${continuityKey}`, confirmedUpdate.epoch);
|
|
331
|
-
for (const subsequentOptimistic of optimisticUpdates) {
|
|
332
|
-
const token = {
|
|
333
|
-
type: `transaction`,
|
|
334
|
-
key: subsequentOptimistic.key
|
|
335
|
-
};
|
|
336
|
-
const { id, params } = subsequentOptimistic;
|
|
337
|
-
Internal.actUponStore(token, id, store)(...params);
|
|
338
|
-
}
|
|
339
|
-
store.logger.info(
|
|
340
|
-
`\u23E9`,
|
|
341
|
-
`continuity`,
|
|
342
|
-
continuityKey,
|
|
343
|
-
`reapplied subsequent optimistic updates:`,
|
|
344
|
-
optimisticUpdates
|
|
345
|
-
);
|
|
346
|
-
}
|
|
347
|
-
store.logger.info(
|
|
348
|
-
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
349
|
-
`continuity`,
|
|
350
|
-
continuityKey,
|
|
351
|
-
`integrating confirmed update`,
|
|
352
|
-
{ confirmedUpdate: confirmed, confirmedUpdates, optimisticUpdates }
|
|
353
|
-
);
|
|
354
|
-
const zerothOptimisticUpdate = optimisticUpdates[0];
|
|
355
|
-
if (zerothOptimisticUpdate) {
|
|
356
|
-
store.logger.info(
|
|
357
|
-
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
358
|
-
`continuity`,
|
|
359
|
-
continuityKey,
|
|
360
|
-
`has optimistic updates to reconcile`
|
|
361
|
-
);
|
|
362
|
-
if (confirmed.epoch === zerothOptimisticUpdate.epoch) {
|
|
363
|
-
store.logger.info(
|
|
364
|
-
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
365
|
-
`continuity`,
|
|
366
|
-
continuityKey,
|
|
367
|
-
`epoch of confirmed update #${confirmed.epoch} matches zeroth optimistic update`
|
|
368
|
-
);
|
|
369
|
-
reconcileEpoch(zerothOptimisticUpdate, confirmed);
|
|
370
|
-
for (const nextConfirmed of confirmedUpdates) {
|
|
371
|
-
const nextOptimistic = optimisticUpdates[0];
|
|
372
|
-
if (nextConfirmed.epoch === (nextOptimistic == null ? void 0 : nextOptimistic.epoch)) {
|
|
373
|
-
reconcileEpoch(nextOptimistic, nextConfirmed);
|
|
374
|
-
} else {
|
|
375
|
-
break;
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
} else {
|
|
379
|
-
store.logger.info(
|
|
380
|
-
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
381
|
-
`continuity`,
|
|
382
|
-
continuityKey,
|
|
383
|
-
`epoch of confirmed update #${confirmed.epoch} does not match zeroth optimistic update #${zerothOptimisticUpdate.epoch}`
|
|
384
|
-
);
|
|
385
|
-
const confirmedUpdateIsAlreadyEnqueued = confirmedUpdates.some(
|
|
386
|
-
(update) => update.epoch === confirmed.epoch
|
|
387
|
-
);
|
|
388
|
-
if (!confirmedUpdateIsAlreadyEnqueued) {
|
|
389
|
-
store.logger.info(
|
|
390
|
-
`\u{1F448}`,
|
|
391
|
-
`continuity`,
|
|
392
|
-
continuityKey,
|
|
393
|
-
`pushing confirmed update to queue`,
|
|
394
|
-
confirmed
|
|
395
|
-
);
|
|
396
|
-
Internal.setIntoStore(
|
|
397
|
-
realtimeClient.confirmedUpdateQueue,
|
|
398
|
-
(queue) => {
|
|
399
|
-
queue.push(confirmed);
|
|
400
|
-
queue.sort((a, b) => a.epoch - b.epoch);
|
|
401
|
-
return queue;
|
|
402
|
-
},
|
|
403
|
-
store
|
|
404
|
-
);
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
} else {
|
|
408
|
-
store.logger.info(
|
|
409
|
-
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
410
|
-
`continuity`,
|
|
411
|
-
continuityKey,
|
|
412
|
-
`has no optimistic updates to deal with`
|
|
413
|
-
);
|
|
414
|
-
const continuityEpoch = Internal.getEpochNumberOfContinuity(continuityKey, store);
|
|
415
|
-
const isRoot = Internal.isRootStore(store);
|
|
416
|
-
if (isRoot && continuityEpoch === confirmed.epoch - 1) {
|
|
417
|
-
store.logger.info(
|
|
418
|
-
`\u2705`,
|
|
419
|
-
`continuity`,
|
|
420
|
-
continuityKey,
|
|
421
|
-
`integrating update #${confirmed.epoch} (${confirmed.key} ${confirmed.id})`
|
|
422
|
-
);
|
|
423
|
-
Internal.ingestTransactionUpdate(`newValue`, confirmed, store);
|
|
424
|
-
socket.emit(`ack:${continuityKey}`, confirmed.epoch);
|
|
425
|
-
Internal.setEpochNumberOfContinuity(continuityKey, confirmed.epoch, store);
|
|
426
|
-
} else if (isRoot && continuityEpoch !== void 0) {
|
|
427
|
-
store.logger.info(
|
|
428
|
-
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
429
|
-
`continuity`,
|
|
430
|
-
continuityKey,
|
|
431
|
-
`received update #${confirmed.epoch} but still waiting for update #${continuityEpoch + 1}`,
|
|
432
|
-
{
|
|
433
|
-
clientEpoch: continuityEpoch,
|
|
434
|
-
serverEpoch: confirmed.epoch
|
|
435
|
-
}
|
|
436
|
-
);
|
|
437
|
-
const confirmedUpdateIsAlreadyEnqueued = confirmedUpdates.some(
|
|
438
|
-
(update) => update.epoch === confirmed.epoch
|
|
439
|
-
);
|
|
440
|
-
if (confirmedUpdateIsAlreadyEnqueued) {
|
|
441
|
-
store.logger.info(
|
|
442
|
-
`\u{1F44D}`,
|
|
443
|
-
`continuity`,
|
|
444
|
-
continuityKey,
|
|
445
|
-
`confirmed update #${confirmed.epoch} is already enqueued`
|
|
446
|
-
);
|
|
447
|
-
} else {
|
|
448
|
-
store.logger.info(
|
|
449
|
-
`\u{1F448}`,
|
|
450
|
-
`continuity`,
|
|
451
|
-
continuityKey,
|
|
452
|
-
`pushing confirmed update #${confirmed.epoch} to queue`
|
|
453
|
-
);
|
|
454
|
-
Internal.setIntoStore(
|
|
455
|
-
realtimeClient.confirmedUpdateQueue,
|
|
456
|
-
(queue) => {
|
|
457
|
-
queue.push(confirmed);
|
|
458
|
-
queue.sort((a, b) => a.epoch - b.epoch);
|
|
459
|
-
return queue;
|
|
460
|
-
},
|
|
461
|
-
store
|
|
462
|
-
);
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
};
|
|
467
|
-
socket.off(`tx-new:${continuityKey}`);
|
|
468
|
-
socket.on(`tx-new:${continuityKey}`, registerAndAttemptConfirmedUpdate);
|
|
469
|
-
const unsubscribeFunctions = continuity.actions.map((transaction) => {
|
|
470
|
-
Internal.assignTransactionToContinuity(continuityKey, transaction.key, store);
|
|
471
|
-
const unsubscribeFromTransactionUpdates = Internal.subscribeToTransaction(
|
|
472
|
-
transaction,
|
|
473
|
-
(clientUpdate) => {
|
|
474
|
-
store.logger.info(
|
|
475
|
-
`\u{1F91E}`,
|
|
476
|
-
`continuity`,
|
|
477
|
-
continuityKey,
|
|
478
|
-
`enqueuing optimistic update`
|
|
479
|
-
);
|
|
480
|
-
const optimisticUpdateIndex = optimisticUpdates.findIndex(
|
|
481
|
-
(update) => update.id === clientUpdate.id
|
|
482
|
-
);
|
|
483
|
-
if (optimisticUpdateIndex === -1) {
|
|
484
|
-
store.logger.info(
|
|
485
|
-
`\u{1F91E}`,
|
|
486
|
-
`continuity`,
|
|
487
|
-
continuityKey,
|
|
488
|
-
`enqueuing new optimistic update`
|
|
489
|
-
);
|
|
490
|
-
Internal.setIntoStore(
|
|
491
|
-
realtimeClient.optimisticUpdateQueue,
|
|
492
|
-
(queue) => {
|
|
493
|
-
queue.push(clientUpdate);
|
|
494
|
-
queue.sort((a, b) => a.epoch - b.epoch);
|
|
495
|
-
return queue;
|
|
496
|
-
},
|
|
497
|
-
store
|
|
498
|
-
);
|
|
499
|
-
} else {
|
|
500
|
-
store.logger.info(
|
|
501
|
-
`\u{1F91E}`,
|
|
502
|
-
`continuity`,
|
|
503
|
-
continuityKey,
|
|
504
|
-
`replacing existing optimistic update at index ${optimisticUpdateIndex}`
|
|
505
|
-
);
|
|
506
|
-
Internal.setIntoStore(
|
|
507
|
-
realtimeClient.optimisticUpdateQueue,
|
|
508
|
-
(queue) => {
|
|
509
|
-
queue[optimisticUpdateIndex] = clientUpdate;
|
|
510
|
-
return queue;
|
|
511
|
-
},
|
|
512
|
-
store
|
|
513
|
-
);
|
|
514
|
-
}
|
|
515
|
-
socket.emit(`tx-run:${continuityKey}`, {
|
|
516
|
-
id: clientUpdate.id,
|
|
517
|
-
key: transaction.key,
|
|
518
|
-
params: clientUpdate.params
|
|
519
|
-
});
|
|
520
|
-
},
|
|
521
|
-
`tx-run:${continuityKey}`,
|
|
522
|
-
store
|
|
523
|
-
);
|
|
524
|
-
return unsubscribeFromTransactionUpdates;
|
|
525
|
-
});
|
|
526
|
-
socket.on(`reveal:${continuityKey}`, (revealed) => {
|
|
527
|
-
let i = 0;
|
|
528
|
-
let k = ``;
|
|
529
|
-
let v = null;
|
|
530
|
-
for (const x of revealed) {
|
|
531
|
-
if (i % 2 === 0) {
|
|
532
|
-
k = x;
|
|
533
|
-
} else {
|
|
534
|
-
v = x;
|
|
535
|
-
Internal.setIntoStore(k, v, store);
|
|
536
|
-
}
|
|
537
|
-
i++;
|
|
538
|
-
}
|
|
539
|
-
});
|
|
540
|
-
socket.on(
|
|
541
|
-
`conceal:${continuityKey}`,
|
|
542
|
-
(concealed) => {
|
|
543
|
-
for (const token of concealed) {
|
|
544
|
-
Internal.disposeAtom(token, store);
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
);
|
|
548
|
-
socket.emit(`get:${continuityKey}`);
|
|
549
|
-
return () => {
|
|
550
|
-
socket.off(`continuity-init:${continuityKey}`);
|
|
551
|
-
socket.off(`tx-new:${continuityKey}`);
|
|
552
|
-
for (const unsubscribe of unsubscribeFunctions) unsubscribe();
|
|
553
|
-
};
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
exports.confirmedUpdateQueue = confirmedUpdateQueue;
|
|
557
|
-
exports.myIdState = myIdState;
|
|
558
|
-
exports.myIdState__INTERNAL = myIdState__INTERNAL;
|
|
559
|
-
exports.myUsernameState = myUsernameState;
|
|
560
|
-
exports.optimisticUpdateQueue = optimisticUpdateQueue;
|
|
561
|
-
exports.pullAtom = pullAtom;
|
|
562
|
-
exports.pullAtomFamilyMember = pullAtomFamilyMember;
|
|
563
|
-
exports.pullMutableAtom = pullMutableAtom;
|
|
564
|
-
exports.pullMutableAtomFamilyMember = pullMutableAtomFamilyMember;
|
|
565
|
-
exports.pullSelector = pullSelector;
|
|
566
|
-
exports.pullSelectorFamilyMember = pullSelectorFamilyMember;
|
|
567
|
-
exports.pushState = pushState;
|
|
568
|
-
exports.serverAction = serverAction;
|
|
569
|
-
exports.syncContinuity = syncContinuity;
|