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
|
@@ -4,7 +4,7 @@ var react = require('atom.io/react');
|
|
|
4
4
|
var RTC = require('atom.io/realtime-client');
|
|
5
5
|
var React = require('react');
|
|
6
6
|
var jsxRuntime = require('react/jsx-runtime');
|
|
7
|
-
var
|
|
7
|
+
var internal = require('atom.io/internal');
|
|
8
8
|
|
|
9
9
|
function _interopNamespace(e) {
|
|
10
10
|
if (e && e.__esModule) return e;
|
|
@@ -26,7 +26,6 @@ function _interopNamespace(e) {
|
|
|
26
26
|
|
|
27
27
|
var RTC__namespace = /*#__PURE__*/_interopNamespace(RTC);
|
|
28
28
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
29
|
-
var AtomIO__namespace = /*#__PURE__*/_interopNamespace(AtomIO);
|
|
30
29
|
|
|
31
30
|
// realtime-react/src/realtime-context.tsx
|
|
32
31
|
var RealtimeContext = React__namespace.createContext({
|
|
@@ -102,34 +101,57 @@ function useRealtimeService(key, create) {
|
|
|
102
101
|
});
|
|
103
102
|
}
|
|
104
103
|
|
|
105
|
-
// realtime-react/src/use-pull.ts
|
|
106
|
-
function
|
|
104
|
+
// realtime-react/src/use-pull-atom.ts
|
|
105
|
+
function usePullAtom(token) {
|
|
107
106
|
const store = React__namespace.useContext(react.StoreContext);
|
|
108
107
|
useRealtimeService(
|
|
109
108
|
`pull:${token.key}`,
|
|
110
|
-
(socket) => RTC__namespace.
|
|
109
|
+
(socket) => RTC__namespace.pullAtom(token, socket, store)
|
|
111
110
|
);
|
|
111
|
+
return react.useO(token);
|
|
112
112
|
}
|
|
113
|
-
function
|
|
113
|
+
function usePullAtomFamilyMember(family, subKey) {
|
|
114
114
|
const store = React__namespace.useContext(react.StoreContext);
|
|
115
|
+
const token = internal.findInStore(family, subKey, store);
|
|
115
116
|
useRealtimeService(
|
|
116
117
|
`pull:${token.key}`,
|
|
117
|
-
(socket) => RTC__namespace.
|
|
118
|
+
(socket) => RTC__namespace.pullAtomFamilyMember(token, socket, store)
|
|
118
119
|
);
|
|
120
|
+
return react.useO(token);
|
|
119
121
|
}
|
|
120
122
|
function usePullMutable(token) {
|
|
121
123
|
const store = React__namespace.useContext(react.StoreContext);
|
|
122
124
|
useRealtimeService(
|
|
123
125
|
`pull:${token.key}`,
|
|
124
|
-
(socket) => RTC__namespace.
|
|
126
|
+
(socket) => RTC__namespace.pullMutableAtom(token, socket, store)
|
|
127
|
+
);
|
|
128
|
+
return react.useO(token);
|
|
129
|
+
}
|
|
130
|
+
function usePullMutableAtomFamilyMember(familyToken, key) {
|
|
131
|
+
const store = React__namespace.useContext(react.StoreContext);
|
|
132
|
+
const token = internal.findInStore(familyToken, key, store);
|
|
133
|
+
useRealtimeService(
|
|
134
|
+
`pull:${token.key}`,
|
|
135
|
+
(socket) => RTC__namespace.pullMutableAtomFamilyMember(token, socket, store)
|
|
136
|
+
);
|
|
137
|
+
return react.useO(token);
|
|
138
|
+
}
|
|
139
|
+
function usePullSelector(token) {
|
|
140
|
+
const store = React__namespace.useContext(react.StoreContext);
|
|
141
|
+
useRealtimeService(
|
|
142
|
+
`pull:${token.key}`,
|
|
143
|
+
(socket) => RTC__namespace.pullSelector(token, socket, store)
|
|
125
144
|
);
|
|
145
|
+
return react.useO(token);
|
|
126
146
|
}
|
|
127
|
-
function
|
|
147
|
+
function usePullSelectorFamilyMember(familyToken, key) {
|
|
128
148
|
const store = React__namespace.useContext(react.StoreContext);
|
|
149
|
+
const token = internal.findInStore(familyToken, key, store);
|
|
129
150
|
useRealtimeService(
|
|
130
151
|
`pull:${token.key}`,
|
|
131
|
-
(socket) => RTC__namespace.
|
|
152
|
+
(socket) => RTC__namespace.pullSelectorFamilyMember(token, socket, store)
|
|
132
153
|
);
|
|
154
|
+
return react.useO(token);
|
|
133
155
|
}
|
|
134
156
|
function usePush(token) {
|
|
135
157
|
const store = React__namespace.useContext(react.StoreContext);
|
|
@@ -137,6 +159,7 @@ function usePush(token) {
|
|
|
137
159
|
`push:${token.key}`,
|
|
138
160
|
(socket) => RTC__namespace.pushState(token, socket, store)
|
|
139
161
|
);
|
|
162
|
+
return react.useI(token);
|
|
140
163
|
}
|
|
141
164
|
function useServerAction(token) {
|
|
142
165
|
const store = React__namespace.useContext(react.StoreContext);
|
|
@@ -144,33 +167,350 @@ function useServerAction(token) {
|
|
|
144
167
|
`tx:${token.key}`,
|
|
145
168
|
(socket) => RTC__namespace.serverAction(token, socket, store)
|
|
146
169
|
);
|
|
147
|
-
return
|
|
170
|
+
return internal.actUponStore(token, internal.arbitrary(), store);
|
|
148
171
|
}
|
|
149
|
-
function
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
|
|
172
|
+
function syncContinuity(continuity, socket, store) {
|
|
173
|
+
const continuityKey = continuity.key;
|
|
174
|
+
const optimisticUpdates = internal.getFromStore(RTC.optimisticUpdateQueue, store);
|
|
175
|
+
const confirmedUpdates = internal.getFromStore(RTC.confirmedUpdateQueue, store);
|
|
176
|
+
const initializeContinuity = (epoch, payload) => {
|
|
177
|
+
socket.off(`continuity-init:${continuityKey}`, initializeContinuity);
|
|
178
|
+
let i = 0;
|
|
179
|
+
let k = ``;
|
|
180
|
+
let v = null;
|
|
181
|
+
for (const x of payload) {
|
|
182
|
+
if (i % 2 === 0) {
|
|
183
|
+
k = x;
|
|
184
|
+
} else {
|
|
185
|
+
v = x;
|
|
186
|
+
if (`type` in k && k.type === `mutable_atom`) {
|
|
187
|
+
k = internal.getJsonToken(k);
|
|
188
|
+
}
|
|
189
|
+
internal.setIntoStore(k, v, store);
|
|
190
|
+
}
|
|
191
|
+
i++;
|
|
192
|
+
}
|
|
193
|
+
internal.setEpochNumberOfContinuity(continuityKey, epoch, store);
|
|
194
|
+
};
|
|
195
|
+
socket.off(`continuity-init:${continuityKey}`);
|
|
196
|
+
socket.on(`continuity-init:${continuityKey}`, initializeContinuity);
|
|
197
|
+
const registerAndAttemptConfirmedUpdate = (confirmedUpdate) => {
|
|
198
|
+
function reconcileEpoch(optimisticUpdate, confirmedUpdate2) {
|
|
199
|
+
store.logger.info(
|
|
200
|
+
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
201
|
+
`continuity`,
|
|
202
|
+
continuityKey,
|
|
203
|
+
`reconciling updates`
|
|
204
|
+
);
|
|
205
|
+
internal.setIntoStore(
|
|
206
|
+
RTC.optimisticUpdateQueue,
|
|
207
|
+
(queue) => {
|
|
208
|
+
queue.shift();
|
|
209
|
+
return queue;
|
|
210
|
+
},
|
|
211
|
+
store
|
|
212
|
+
);
|
|
213
|
+
if (optimisticUpdate.id === confirmedUpdate2.id) {
|
|
214
|
+
const clientResult = JSON.stringify(optimisticUpdate.updates);
|
|
215
|
+
const serverResult = JSON.stringify(confirmedUpdate2.updates);
|
|
216
|
+
if (clientResult === serverResult) {
|
|
217
|
+
store.logger.info(
|
|
218
|
+
`\u2705`,
|
|
219
|
+
`continuity`,
|
|
220
|
+
continuityKey,
|
|
221
|
+
`results for ${optimisticUpdate.id} match between client and server`
|
|
222
|
+
);
|
|
223
|
+
socket.emit(`ack:${continuityKey}`, confirmedUpdate2.epoch);
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
} else {
|
|
227
|
+
store.logger.info(
|
|
228
|
+
`\u274C`,
|
|
229
|
+
`continuity`,
|
|
230
|
+
continuityKey,
|
|
231
|
+
`thought update #${confirmedUpdate2.epoch} was ${optimisticUpdate.key}:${optimisticUpdate.id}, but it was actually ${confirmedUpdate2.key}:${confirmedUpdate2.id}`
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
store.logger.info(
|
|
235
|
+
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
236
|
+
`continuity`,
|
|
237
|
+
continuityKey,
|
|
238
|
+
`updates do not match`,
|
|
239
|
+
optimisticUpdate,
|
|
240
|
+
confirmedUpdate2
|
|
241
|
+
);
|
|
242
|
+
const reversedOptimisticUpdates = optimisticUpdates.toReversed();
|
|
243
|
+
for (const subsequentOptimistic of reversedOptimisticUpdates) {
|
|
244
|
+
internal.ingestTransactionUpdate(`oldValue`, subsequentOptimistic, store);
|
|
245
|
+
}
|
|
246
|
+
store.logger.info(
|
|
247
|
+
`\u23EA`,
|
|
248
|
+
`continuity`,
|
|
249
|
+
continuityKey,
|
|
250
|
+
`undid optimistic updates:`,
|
|
251
|
+
reversedOptimisticUpdates
|
|
252
|
+
);
|
|
253
|
+
internal.ingestTransactionUpdate(`oldValue`, optimisticUpdate, store);
|
|
254
|
+
store.logger.info(
|
|
255
|
+
`\u23EA`,
|
|
256
|
+
`continuity`,
|
|
257
|
+
continuityKey,
|
|
258
|
+
`undid zeroth optimistic update`,
|
|
259
|
+
optimisticUpdate
|
|
260
|
+
);
|
|
261
|
+
internal.ingestTransactionUpdate(`newValue`, confirmedUpdate2, store);
|
|
262
|
+
store.logger.info(
|
|
263
|
+
`\u23E9`,
|
|
264
|
+
`continuity`,
|
|
265
|
+
continuityKey,
|
|
266
|
+
`applied confirmed update`,
|
|
267
|
+
confirmedUpdate2
|
|
268
|
+
);
|
|
269
|
+
socket.emit(`ack:${continuityKey}`, confirmedUpdate2.epoch);
|
|
270
|
+
for (const subsequentOptimistic of optimisticUpdates) {
|
|
271
|
+
const token = {
|
|
272
|
+
type: `transaction`,
|
|
273
|
+
key: subsequentOptimistic.key
|
|
274
|
+
};
|
|
275
|
+
const { id, params } = subsequentOptimistic;
|
|
276
|
+
internal.actUponStore(token, id, store)(...params);
|
|
277
|
+
}
|
|
278
|
+
store.logger.info(
|
|
279
|
+
`\u23E9`,
|
|
280
|
+
`continuity`,
|
|
281
|
+
continuityKey,
|
|
282
|
+
`reapplied subsequent optimistic updates:`,
|
|
283
|
+
optimisticUpdates
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
store.logger.info(
|
|
287
|
+
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
288
|
+
`continuity`,
|
|
289
|
+
continuityKey,
|
|
290
|
+
`integrating confirmed update`,
|
|
291
|
+
{ confirmedUpdate, confirmedUpdates, optimisticUpdates }
|
|
292
|
+
);
|
|
293
|
+
const zerothOptimisticUpdate = optimisticUpdates[0];
|
|
294
|
+
if (zerothOptimisticUpdate) {
|
|
295
|
+
store.logger.info(
|
|
296
|
+
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
297
|
+
`continuity`,
|
|
298
|
+
continuityKey,
|
|
299
|
+
`has optimistic updates to reconcile`
|
|
300
|
+
);
|
|
301
|
+
if (confirmedUpdate.epoch === zerothOptimisticUpdate.epoch) {
|
|
302
|
+
store.logger.info(
|
|
303
|
+
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
304
|
+
`continuity`,
|
|
305
|
+
continuityKey,
|
|
306
|
+
`epoch of confirmed update #${confirmedUpdate.epoch} matches zeroth optimistic update`
|
|
307
|
+
);
|
|
308
|
+
reconcileEpoch(zerothOptimisticUpdate, confirmedUpdate);
|
|
309
|
+
for (const nextConfirmed of confirmedUpdates) {
|
|
310
|
+
const nextOptimistic = optimisticUpdates[0];
|
|
311
|
+
if (nextConfirmed.epoch === (nextOptimistic == null ? void 0 : nextOptimistic.epoch)) {
|
|
312
|
+
reconcileEpoch(nextOptimistic, nextConfirmed);
|
|
313
|
+
} else {
|
|
314
|
+
break;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
} else {
|
|
318
|
+
store.logger.info(
|
|
319
|
+
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
320
|
+
`continuity`,
|
|
321
|
+
continuityKey,
|
|
322
|
+
`epoch of confirmed update #${confirmedUpdate.epoch} does not match zeroth optimistic update #${zerothOptimisticUpdate.epoch}`
|
|
323
|
+
);
|
|
324
|
+
const confirmedUpdateIsAlreadyEnqueued = confirmedUpdates.some(
|
|
325
|
+
(update) => update.epoch === confirmedUpdate.epoch
|
|
326
|
+
);
|
|
327
|
+
if (!confirmedUpdateIsAlreadyEnqueued) {
|
|
328
|
+
store.logger.info(
|
|
329
|
+
`\u{1F448}`,
|
|
330
|
+
`continuity`,
|
|
331
|
+
continuityKey,
|
|
332
|
+
`pushing confirmed update to queue`,
|
|
333
|
+
confirmedUpdate
|
|
334
|
+
);
|
|
335
|
+
internal.setIntoStore(
|
|
336
|
+
RTC.confirmedUpdateQueue,
|
|
337
|
+
(queue) => {
|
|
338
|
+
queue.push(confirmedUpdate);
|
|
339
|
+
queue.sort((a, b) => a.epoch - b.epoch);
|
|
340
|
+
return queue;
|
|
341
|
+
},
|
|
342
|
+
store
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
} else {
|
|
347
|
+
store.logger.info(
|
|
348
|
+
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
349
|
+
`continuity`,
|
|
350
|
+
continuityKey,
|
|
351
|
+
`has no optimistic updates to deal with`
|
|
352
|
+
);
|
|
353
|
+
const continuityEpoch = internal.getEpochNumberOfContinuity(continuityKey, store);
|
|
354
|
+
const isRoot = internal.isRootStore(store);
|
|
355
|
+
if (isRoot && continuityEpoch === confirmedUpdate.epoch - 1) {
|
|
356
|
+
store.logger.info(
|
|
357
|
+
`\u2705`,
|
|
358
|
+
`continuity`,
|
|
359
|
+
continuityKey,
|
|
360
|
+
`integrating update #${confirmedUpdate.epoch} (${confirmedUpdate.key} ${confirmedUpdate.id})`
|
|
361
|
+
);
|
|
362
|
+
internal.ingestTransactionUpdate(`newValue`, confirmedUpdate, store);
|
|
363
|
+
socket.emit(`ack:${continuityKey}`, confirmedUpdate.epoch);
|
|
364
|
+
internal.setEpochNumberOfContinuity(continuityKey, confirmedUpdate.epoch, store);
|
|
365
|
+
} else if (isRoot && continuityEpoch !== void 0) {
|
|
366
|
+
store.logger.info(
|
|
367
|
+
`\u{1F9D1}\u200D\u2696\uFE0F`,
|
|
368
|
+
`continuity`,
|
|
369
|
+
continuityKey,
|
|
370
|
+
`received update #${confirmedUpdate.epoch} but still waiting for update #${continuityEpoch + 1}`,
|
|
371
|
+
{
|
|
372
|
+
clientEpoch: continuityEpoch,
|
|
373
|
+
serverEpoch: confirmedUpdate.epoch
|
|
374
|
+
}
|
|
375
|
+
);
|
|
376
|
+
const confirmedUpdateIsAlreadyEnqueued = confirmedUpdates.some(
|
|
377
|
+
(update) => update.epoch === confirmedUpdate.epoch
|
|
378
|
+
);
|
|
379
|
+
if (confirmedUpdateIsAlreadyEnqueued) {
|
|
380
|
+
store.logger.info(
|
|
381
|
+
`\u{1F44D}`,
|
|
382
|
+
`continuity`,
|
|
383
|
+
continuityKey,
|
|
384
|
+
`confirmed update #${confirmedUpdate.epoch} is already enqueued`
|
|
385
|
+
);
|
|
386
|
+
} else {
|
|
387
|
+
store.logger.info(
|
|
388
|
+
`\u{1F448}`,
|
|
389
|
+
`continuity`,
|
|
390
|
+
continuityKey,
|
|
391
|
+
`pushing confirmed update #${confirmedUpdate.epoch} to queue`
|
|
392
|
+
);
|
|
393
|
+
internal.setIntoStore(
|
|
394
|
+
RTC.confirmedUpdateQueue,
|
|
395
|
+
(queue) => {
|
|
396
|
+
queue.push(confirmedUpdate);
|
|
397
|
+
queue.sort((a, b) => a.epoch - b.epoch);
|
|
398
|
+
return queue;
|
|
399
|
+
},
|
|
400
|
+
store
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
};
|
|
406
|
+
socket.off(`tx-new:${continuityKey}`);
|
|
407
|
+
socket.on(`tx-new:${continuityKey}`, registerAndAttemptConfirmedUpdate);
|
|
408
|
+
const unsubscribeFunctions = continuity.actions.map((transaction) => {
|
|
409
|
+
internal.assignTransactionToContinuity(continuityKey, transaction.key, store);
|
|
410
|
+
const unsubscribeFromTransactionUpdates = internal.subscribeToTransaction(
|
|
411
|
+
transaction,
|
|
412
|
+
(clientUpdate) => {
|
|
413
|
+
store.logger.info(
|
|
414
|
+
`\u{1F91E}`,
|
|
415
|
+
`continuity`,
|
|
416
|
+
continuityKey,
|
|
417
|
+
`enqueuing optimistic update`
|
|
418
|
+
);
|
|
419
|
+
const optimisticUpdateIndex = optimisticUpdates.findIndex(
|
|
420
|
+
(update) => update.id === clientUpdate.id
|
|
421
|
+
);
|
|
422
|
+
if (optimisticUpdateIndex === -1) {
|
|
423
|
+
store.logger.info(
|
|
424
|
+
`\u{1F91E}`,
|
|
425
|
+
`continuity`,
|
|
426
|
+
continuityKey,
|
|
427
|
+
`enqueuing new optimistic update`
|
|
428
|
+
);
|
|
429
|
+
internal.setIntoStore(
|
|
430
|
+
RTC.optimisticUpdateQueue,
|
|
431
|
+
(queue) => {
|
|
432
|
+
queue.push(clientUpdate);
|
|
433
|
+
queue.sort((a, b) => a.epoch - b.epoch);
|
|
434
|
+
return queue;
|
|
435
|
+
},
|
|
436
|
+
store
|
|
437
|
+
);
|
|
438
|
+
} else {
|
|
439
|
+
store.logger.info(
|
|
440
|
+
`\u{1F91E}`,
|
|
441
|
+
`continuity`,
|
|
442
|
+
continuityKey,
|
|
443
|
+
`replacing existing optimistic update at index ${optimisticUpdateIndex}`
|
|
444
|
+
);
|
|
445
|
+
internal.setIntoStore(
|
|
446
|
+
RTC.optimisticUpdateQueue,
|
|
447
|
+
(queue) => {
|
|
448
|
+
queue[optimisticUpdateIndex] = clientUpdate;
|
|
449
|
+
return queue;
|
|
450
|
+
},
|
|
451
|
+
store
|
|
452
|
+
);
|
|
453
|
+
}
|
|
454
|
+
socket.emit(`tx-run:${continuityKey}`, {
|
|
455
|
+
id: clientUpdate.id,
|
|
456
|
+
key: transaction.key,
|
|
457
|
+
params: clientUpdate.params
|
|
458
|
+
});
|
|
459
|
+
},
|
|
460
|
+
`tx-run:${continuityKey}`,
|
|
461
|
+
store
|
|
462
|
+
);
|
|
463
|
+
return unsubscribeFromTransactionUpdates;
|
|
153
464
|
});
|
|
154
|
-
|
|
465
|
+
socket.on(`reveal:${continuityKey}`, (revealed) => {
|
|
466
|
+
let i = 0;
|
|
467
|
+
let k = ``;
|
|
468
|
+
let v = null;
|
|
469
|
+
for (const x of revealed) {
|
|
470
|
+
if (i % 2 === 0) {
|
|
471
|
+
k = x;
|
|
472
|
+
} else {
|
|
473
|
+
v = x;
|
|
474
|
+
internal.setIntoStore(k, v, store);
|
|
475
|
+
}
|
|
476
|
+
i++;
|
|
477
|
+
}
|
|
478
|
+
});
|
|
479
|
+
socket.on(
|
|
480
|
+
`conceal:${continuityKey}`,
|
|
481
|
+
(concealed) => {
|
|
482
|
+
for (const token of concealed) {
|
|
483
|
+
internal.deleteAtom(token, store);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
);
|
|
487
|
+
socket.emit(`get:${continuityKey}`);
|
|
488
|
+
return () => {
|
|
489
|
+
socket.off(`continuity-init:${continuityKey}`);
|
|
490
|
+
socket.off(`tx-new:${continuityKey}`);
|
|
491
|
+
for (const unsubscribe of unsubscribeFunctions)
|
|
492
|
+
unsubscribe();
|
|
493
|
+
};
|
|
155
494
|
}
|
|
156
|
-
|
|
495
|
+
|
|
496
|
+
// realtime-react/src/use-sync-continuity.ts
|
|
497
|
+
function useSyncContinuity(token) {
|
|
157
498
|
const store = React__namespace.useContext(react.StoreContext);
|
|
158
|
-
useRealtimeService(
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
);
|
|
162
|
-
return react.useO(token);
|
|
499
|
+
useRealtimeService(`tx-sync:${token.key}`, (socket) => {
|
|
500
|
+
return syncContinuity(token, socket, store);
|
|
501
|
+
});
|
|
163
502
|
}
|
|
164
503
|
|
|
165
504
|
exports.RealtimeContext = RealtimeContext;
|
|
166
505
|
exports.RealtimeProvider = RealtimeProvider;
|
|
167
|
-
exports.
|
|
168
|
-
exports.
|
|
506
|
+
exports.usePullAtom = usePullAtom;
|
|
507
|
+
exports.usePullAtomFamilyMember = usePullAtomFamilyMember;
|
|
169
508
|
exports.usePullMutable = usePullMutable;
|
|
170
|
-
exports.
|
|
509
|
+
exports.usePullMutableAtomFamilyMember = usePullMutableAtomFamilyMember;
|
|
510
|
+
exports.usePullSelector = usePullSelector;
|
|
511
|
+
exports.usePullSelectorFamilyMember = usePullSelectorFamilyMember;
|
|
171
512
|
exports.usePush = usePush;
|
|
172
513
|
exports.useServerAction = useServerAction;
|
|
173
|
-
exports.
|
|
174
|
-
exports.useSyncAction = useSyncAction;
|
|
514
|
+
exports.useSyncContinuity = useSyncContinuity;
|
|
175
515
|
//# sourceMappingURL=out.js.map
|
|
176
516
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/realtime-context.tsx","../src/use-pull.ts","../src/use-realtime-service.ts","../src/use-single-effect.ts","../src/on-mount.ts","../src/use-pull-family-member.ts","../src/use-pull-mutable.ts","../src/use-pull-mutable-family-member.ts","../src/use-push.ts","../src/use-server-action.ts","../src/use-sync-server-action.ts","../src/use-sync.ts"],"names":["RTC","React","StoreContext","AtomIO"],"mappings":";AAAA,SAAS,YAAY;AACrB,YAAY,SAAS;AACrB,YAAY,WAAW;AAgCrB;AArBK,IAAM,kBAAwB,oBAAkC;AAAA,EACtE,QAAQ;AAAA,EACR,UAAU;AACX,CAAC;AAEM,IAAM,mBAGR,CAAC,EAAE,UAAU,OAAO,MAAM;AAC9B,QAAM,WAAiB,aAAO,oBAAI,IAAkC,CAAC,EAAE;AACvE,QAAM,UAAU,KAAS,uBAAmB;AAC5C,EAAM,gBAAU,MAAM;AACrB,YAAQ,iCAAQ,EAAE;AAClB,qCAAQ,GAAG,WAAW,MAAM;AAC3B,cAAQ,OAAO,EAAE;AAAA,IAClB;AACA,qCAAQ,GAAG,cAAc,MAAM;AAC9B,cAAQ,MAAS;AAAA,IAClB;AAAA,EACD,GAAG,CAAC,QAAQ,OAAO,CAAC;AACpB,SACC,oBAAC,gBAAgB,UAAhB,EAAyB,OAAO,EAAE,QAAQ,SAAS,GAClD,UACF;AAEF;;;ACpCA,SAAS,oBAAoB;AAC7B,YAAYA,UAAS;AACrB,YAAYC,YAAW;;;ACJvB,YAAYA,YAAW;;;ACAvB,YAAYA,YAAW;AAEvB,IAAM,EAAE,SAAS,IAAI,QAAQ;AAC7B,IAAM,SAAS,aAAa,iBAAiB,aAAa;AAE1D,SAAS,OAAO;AAAC;AAEV,SAAS,gBACf,QACA,MACO;AACP,MAAI,QAAQ;AACX,UAAM,UAAgB,cAAmB,IAAI;AAC7C,IAAM,iBAAU,MAAM;AAbxB;AAcG,UAAI,UAAU,QAAQ;AACtB,UAAI,YAAY,MAAM;AACrB,mBAAU,YAA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AK;AACrD;;;ACbA,SAAS,gBAAAA,eAAc,YAAY;AACnC,YAAYF,UAAS;AACrB,YAAYC,aAAW;AAIhB,SAAS,QACf,OACI;AACJ,QAAM,QAAc,mBAAWC,aAAY;AAC3C;AAAA,IAAmB,QAAQ,MAAM,GAAG;AAAA,IAAI,CAAC,WACpC,eAAU,OAAO,QAAQ,KAAK;AAAA,EACnC;AACA,SAAO,KAAK,KAAK;AAClB","sourcesContent":["import { useI } from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\nimport type { Socket } from \"socket.io-client\"\n\nexport type RealtimeReactStore = {\n\tsocket: Socket | null\n\tservices: Map<\n\t\tstring,\n\t\t[consumerCount: number, dispose: (() => void) | undefined]\n\t> | null\n}\n\nexport const RealtimeContext = React.createContext<RealtimeReactStore>({\n\tsocket: null,\n\tservices: null,\n})\n\nexport const RealtimeProvider: React.FC<{\n\tchildren: React.ReactNode\n\tsocket: Socket | null\n}> = ({ children, socket }) => {\n\tconst services = React.useRef(new Map<string, [number, () => void]>()).current\n\tconst setMyId = useI(RTC.myIdState__INTERNAL)\n\tReact.useEffect(() => {\n\t\tsetMyId(socket?.id)\n\t\tsocket?.on(`connect`, () => {\n\t\t\tsetMyId(socket.id)\n\t\t})\n\t\tsocket?.on(`disconnect`, () => {\n\t\t\tsetMyId(undefined)\n\t\t})\n\t}, [socket, setMyId])\n\treturn (\n\t\t<RealtimeContext.Provider value={{ socket, services }}>\n\t\t\t{children}\n\t\t</RealtimeContext.Provider>\n\t)\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport { StoreContext } from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\n\nimport { useRealtimeService } from \"./use-realtime-service\"\n\nexport function usePull<J extends Json.Serializable>(\n\ttoken: AtomIO.WritableToken<J>,\n): void {\n\tconst store = React.useContext(StoreContext)\n\tuseRealtimeService(`pull:${token.key}`, (socket) =>\n\t\tRTC.pullState(token, socket, store),\n\t)\n}\n","import * as React from \"react\"\nimport type { Socket } from \"socket.io-client\"\nimport { onMount } from \"./on-mount\"\nimport { RealtimeContext } from \"./realtime-context\"\n\nexport function useRealtimeService(\n\tkey: string,\n\tcreate: (socket: Socket) => (() => void) | undefined,\n): void {\n\tconst { socket, services } = React.useContext(RealtimeContext)\n\tonMount(() => {\n\t\tlet service = services?.get(key)\n\t\tif (service) {\n\t\t\tservice[0]++\n\t\t} else {\n\t\t\tconst dispose = socket ? create(socket) : undefined\n\t\t\tservice = [1, dispose]\n\t\t\tservices?.set(key, service)\n\t\t}\n\t\treturn () => {\n\t\t\tif (service) {\n\t\t\t\tservice[0]--\n\t\t\t\tif (service[0] === 0) {\n\t\t\t\t\tservice[1]?.()\n\t\t\t\t\tservices?.delete(key)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t})\n}\n","import * as React from \"react\"\n\nconst { NODE_ENV } = process.env\nconst IN_DEV = NODE_ENV === `development` || NODE_ENV === `test`\n\nfunction noop() {}\n\nexport function useSingleEffect(\n\teffect: () => (() => void) | undefined,\n\tdeps: unknown[],\n): void {\n\tif (IN_DEV) {\n\t\tconst cleanup = React.useRef<() => void>(noop)\n\t\tReact.useEffect(() => {\n\t\t\tlet dispose = cleanup.current\n\t\t\tif (dispose === noop) {\n\t\t\t\tdispose = effect() ?? noop\n\t\t\t\tcleanup.current = dispose\n\t\t\t} else {\n\t\t\t\treturn () => {\n\t\t\t\t\tdispose()\n\t\t\t\t\tcleanup.current = noop\n\t\t\t\t}\n\t\t\t}\n\t\t}, deps)\n\t} else {\n\t\tReact.useEffect(effect, deps)\n\t}\n}\n","import { useSingleEffect } from \"./use-single-effect\"\n\nexport function onMount(effect: () => (() => void) | undefined): void {\n\tuseSingleEffect(effect, [])\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport { StoreContext } from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\n\nimport { useRealtimeService } from \"./use-realtime-service\"\n\nexport function usePullFamilyMember<J extends Json.Serializable>(\n\ttoken: AtomIO.WritableToken<J>,\n): void {\n\tconst store = React.useContext(StoreContext)\n\tuseRealtimeService(`pull:${token.key}`, (socket) =>\n\t\tRTC.pullFamilyMember(token, socket, store),\n\t)\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Transceiver } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport { StoreContext } from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\n\nimport { useRealtimeService } from \"./use-realtime-service\"\n\nexport function usePullMutable<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n>(token: AtomIO.MutableAtomToken<T, J>): void {\n\tconst store = React.useContext(StoreContext)\n\tuseRealtimeService(`pull:${token.key}`, (socket) =>\n\t\tRTC.pullMutableState(token, socket, store),\n\t)\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Transceiver } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport { StoreContext } from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\n\nimport { useRealtimeService } from \"./use-realtime-service\"\n\nexport function usePullMutableFamilyMember<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n>(token: AtomIO.MutableAtomToken<T, J>): void {\n\tconst store = React.useContext(StoreContext)\n\tuseRealtimeService(`pull:${token.key}`, (socket) =>\n\t\tRTC.pullMutableFamilyMember(token, socket, store),\n\t)\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport { StoreContext } from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\n\nimport { useRealtimeService } from \"./use-realtime-service\"\n\nexport function usePush<J extends Json.Serializable>(\n\ttoken: AtomIO.WritableToken<J>,\n): void {\n\tconst store = React.useContext(StoreContext)\n\tuseRealtimeService(`push:${token.key}`, (socket) =>\n\t\tRTC.pushState(token, socket, store),\n\t)\n}\n","import * as AtomIO from \"atom.io\"\nimport { StoreContext } from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\n\nimport { useRealtimeService } from \"./use-realtime-service\"\n\nexport function useServerAction<ƒ extends AtomIO.ƒn>(\n\ttoken: AtomIO.TransactionToken<ƒ>,\n): (...parameters: Parameters<ƒ>) => ReturnType<ƒ> {\n\tconst store = React.useContext(StoreContext)\n\n\tuseRealtimeService(`tx:${token.key}`, (socket) =>\n\t\tRTC.serverAction(token, socket, store),\n\t)\n\treturn AtomIO.runTransaction(token, undefined, store)\n}\n","import * as AtomIO from \"atom.io\"\nimport { StoreContext } from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\n\nimport { useRealtimeService } from \"./use-realtime-service\"\n\nexport function useSyncAction<ƒ extends AtomIO.ƒn>(\n\ttoken: AtomIO.TransactionToken<ƒ>,\n): (...parameters: Parameters<ƒ>) => ReturnType<ƒ> {\n\tconst store = React.useContext(StoreContext)\n\tuseRealtimeService(`tx-sync:${token.key}`, (socket) => {\n\t\treturn RTC.syncAction(token, socket, store)\n\t})\n\treturn AtomIO.runTransaction(token, undefined, store)\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport { StoreContext, useO } from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\n\nimport { useRealtimeService } from \"./use-realtime-service\"\n\nexport function useSync<J extends Json.Serializable>(\n\ttoken: AtomIO.WritableToken<J>,\n): J {\n\tconst store = React.useContext(StoreContext)\n\tuseRealtimeService(`sync:${token.key}`, (socket) =>\n\t\tRTC.syncState(token, socket, store),\n\t)\n\treturn useO(token)\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/realtime-context.tsx","../src/use-pull-atom.ts","../src/use-realtime-service.ts","../src/use-single-effect.ts","../src/on-mount.ts","../src/use-pull-atom-family-member.ts","../src/use-pull-mutable-atom.ts","../src/use-pull-mutable-family-member.ts","../src/use-pull-selector.ts","../src/use-pull-selector-family-member.ts","../src/use-push.ts","../src/use-server-action.ts","../src/use-sync-continuity.ts","../../realtime-client/src/sync-continuity.ts"],"names":["RTC","React","StoreContext","useO","findInStore","useI","actUponStore","confirmedUpdate"],"mappings":";AAAA,SAAS,YAAY;AACrB,YAAY,SAAS;AACrB,YAAY,WAAW;AAgCrB;AArBK,IAAM,kBAAwB,oBAAkC;AAAA,EACtE,QAAQ;AAAA,EACR,UAAU;AACX,CAAC;AAEM,IAAM,mBAGR,CAAC,EAAE,UAAU,OAAO,MAAM;AAC9B,QAAM,WAAiB,aAAO,oBAAI,IAAkC,CAAC,EAAE;AACvE,QAAM,UAAU,KAAS,uBAAmB;AAC5C,EAAM,gBAAU,MAAM;AACrB,YAAQ,iCAAQ,EAAE;AAClB,qCAAQ,GAAG,WAAW,MAAM;AAC3B,cAAQ,OAAO,EAAE;AAAA,IAClB;AACA,qCAAQ,GAAG,cAAc,MAAM;AAC9B,cAAQ,MAAS;AAAA,IAClB;AAAA,EACD,GAAG,CAAC,QAAQ,OAAO,CAAC;AACpB,SACC,oBAAC,gBAAgB,UAAhB,EAAyB,OAAO,EAAE,QAAQ,SAAS,GAClD,UACF;AAEF;;;ACpCA,SAAS,cAAc,YAAY;AACnC,YAAYA,UAAS;AACrB,YAAYC,YAAW;;;ACJvB,YAAYA,YAAW;;;ACAvB,YAAYA,YAAW;AAEvB,IAAM,EAAE,SAAS,IAAI,QAAQ;AAC7B,IAAM,SAAS,aAAa,iBAAiB,aAAa;AAE1D,SAAS,OAAO;AAAC;AAEV,SAAS,gBACf,QACA,MACO;AACP,MAAI,QAAQ;AACX,UAAM,UAAgB,cAAmB,IAAI;AAC7C,IAAM,iBAAU,MAAM;AAbxB;AAcG,UAAI,UAAU,QAAQ;AACtB,UAAI,YAAY,MAAM;AACrB,mBAAU,YAAO,MAAP,YAAY;AACtB,gBAAQ,UAAU;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;AAAA,EAC3C,CAAC;AACF","sourcesContent":["import { useI } from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\nimport type { Socket } from \"socket.io-client\"\n\nexport type RealtimeReactStore = {\n\tsocket: Socket | null\n\tservices: Map<\n\t\tstring,\n\t\t[consumerCount: number, dispose: (() => void) | undefined]\n\t> | null\n}\n\nexport const RealtimeContext = React.createContext<RealtimeReactStore>({\n\tsocket: null,\n\tservices: null,\n})\n\nexport const RealtimeProvider: React.FC<{\n\tchildren: React.ReactNode\n\tsocket: Socket | null\n}> = ({ children, socket }) => {\n\tconst services = React.useRef(new Map<string, [number, () => void]>()).current\n\tconst setMyId = useI(RTC.myIdState__INTERNAL)\n\tReact.useEffect(() => {\n\t\tsetMyId(socket?.id)\n\t\tsocket?.on(`connect`, () => {\n\t\t\tsetMyId(socket.id)\n\t\t})\n\t\tsocket?.on(`disconnect`, () => {\n\t\t\tsetMyId(undefined)\n\t\t})\n\t}, [socket, setMyId])\n\treturn (\n\t\t<RealtimeContext.Provider value={{ socket, services }}>\n\t\t\t{children}\n\t\t</RealtimeContext.Provider>\n\t)\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport { StoreContext, useO } from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\n\nimport { useRealtimeService } from \"./use-realtime-service\"\n\nexport function usePullAtom<J extends Json.Serializable>(\n\ttoken: AtomIO.RegularAtomToken<J>,\n): J {\n\tconst store = React.useContext(StoreContext)\n\tuseRealtimeService(`pull:${token.key}`, (socket) =>\n\t\tRTC.pullAtom(token, socket, store),\n\t)\n\treturn useO(token)\n}\n","import * as React from \"react\"\nimport type { Socket } from \"socket.io-client\"\nimport { onMount } from \"./on-mount\"\nimport { RealtimeContext } from \"./realtime-context\"\n\nexport function useRealtimeService(\n\tkey: string,\n\tcreate: (socket: Socket) => (() => void) | undefined,\n): void {\n\tconst { socket, services } = React.useContext(RealtimeContext)\n\tonMount(() => {\n\t\tlet service = services?.get(key)\n\t\tif (service) {\n\t\t\tservice[0]++\n\t\t} else {\n\t\t\tconst dispose = socket ? create(socket) : undefined\n\t\t\tservice = [1, dispose]\n\t\t\tservices?.set(key, service)\n\t\t}\n\t\treturn () => {\n\t\t\tif (service) {\n\t\t\t\tservice[0]--\n\t\t\t\tif (service[0] === 0) {\n\t\t\t\t\tservice[1]?.()\n\t\t\t\t\tservices?.delete(key)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t})\n}\n","import * as React from \"react\"\n\nconst { NODE_ENV } = process.env\nconst IN_DEV = NODE_ENV === `development` || NODE_ENV === `test`\n\nfunction noop() {}\n\nexport function useSingleEffect(\n\teffect: () => (() => void) | undefined,\n\tdeps: unknown[],\n): void {\n\tif (IN_DEV) {\n\t\tconst cleanup = React.useRef<() => void>(noop)\n\t\tReact.useEffect(() => {\n\t\t\tlet dispose = cleanup.current\n\t\t\tif (dispose === noop) {\n\t\t\t\tdispose = effect() ?? noop\n\t\t\t\tcleanup.current = dispose\n\t\t\t} else {\n\t\t\t\treturn () => {\n\t\t\t\t\tdispose()\n\t\t\t\t\tcleanup.current = noop\n\t\t\t\t}\n\t\t\t}\n\t\t}, deps)\n\t} else {\n\t\tReact.useEffect(effect, deps)\n\t}\n}\n","import { useSingleEffect } from \"./use-single-effect\"\n\nexport function onMount(effect: () => (() => void) | undefined): void {\n\tuseSingleEffect(effect, [])\n}\n","import type * as AtomIO from \"atom.io\"\nimport { findInStore } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport { StoreContext, useO } from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\n\nimport { useRealtimeService } from \"./use-realtime-service\"\n\nexport function usePullAtomFamilyMember<\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n\tKey extends K,\n>(family: AtomIO.RegularAtomFamilyToken<J, K>, subKey: Key): J {\n\tconst store = React.useContext(StoreContext)\n\tconst token = findInStore(family, subKey, store)\n\tuseRealtimeService(`pull:${token.key}`, (socket) =>\n\t\tRTC.pullAtomFamilyMember(token, socket, store),\n\t)\n\treturn useO(token)\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Transceiver } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport { StoreContext, useO } from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\n\nimport { useRealtimeService } from \"./use-realtime-service\"\n\nexport function usePullMutable<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n>(token: AtomIO.MutableAtomToken<T, J>): T {\n\tconst store = React.useContext(StoreContext)\n\tuseRealtimeService(`pull:${token.key}`, (socket) =>\n\t\tRTC.pullMutableAtom(token, socket, store),\n\t)\n\treturn useO(token)\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Transceiver } from \"atom.io/internal\"\nimport { findInStore } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport { StoreContext, useO } from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\n\nimport { useRealtimeService } from \"./use-realtime-service\"\n\nexport function usePullMutableAtomFamilyMember<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n\tKey extends K,\n>(familyToken: AtomIO.MutableAtomFamilyToken<T, J, K>, key: Key): T {\n\tconst store = React.useContext(StoreContext)\n\tconst token = findInStore(familyToken, key, store)\n\tuseRealtimeService(`pull:${token.key}`, (socket) =>\n\t\tRTC.pullMutableAtomFamilyMember(token, socket, store),\n\t)\n\treturn useO(token)\n}\n","import type * as AtomIO from \"atom.io\"\nimport { findInStore } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport { StoreContext, useO } from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\n\nimport { useRealtimeService } from \"./use-realtime-service\"\n\nexport function usePullSelector<J extends Json.Serializable>(\n\ttoken: AtomIO.SelectorToken<J>,\n): J {\n\tconst store = React.useContext(StoreContext)\n\tuseRealtimeService(`pull:${token.key}`, (socket) =>\n\t\tRTC.pullSelector(token, socket, store),\n\t)\n\treturn useO(token)\n}\n","import type * as AtomIO from \"atom.io\"\nimport { findInStore } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport { StoreContext, useO } from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\n\nimport { useRealtimeService } from \"./use-realtime-service\"\n\nexport function usePullSelectorFamilyMember<\n\tT,\n\tK extends Json.Serializable,\n\tKey extends K,\n>(familyToken: AtomIO.SelectorFamilyToken<T, K>, key: Key): T {\n\tconst store = React.useContext(StoreContext)\n\tconst token = findInStore(familyToken, key, store)\n\tuseRealtimeService(`pull:${token.key}`, (socket) =>\n\t\tRTC.pullSelectorFamilyMember(token, socket, store),\n\t)\n\treturn useO(token)\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport { StoreContext, useI } from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\n\nimport { useRealtimeService } from \"./use-realtime-service\"\n\nexport function usePush<J extends Json.Serializable>(\n\ttoken: AtomIO.WritableToken<J>,\n): <New extends J>(next: New | ((old: J) => New)) => void {\n\tconst store = React.useContext(StoreContext)\n\tuseRealtimeService(`push:${token.key}`, (socket) =>\n\t\tRTC.pushState(token, socket, store),\n\t)\n\treturn useI(token)\n}\n","import type * as AtomIO from \"atom.io\"\nimport { actUponStore, arbitrary } from \"atom.io/internal\"\nimport { StoreContext } from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\n\nimport { useRealtimeService } from \"./use-realtime-service\"\n\nexport function useServerAction<ƒ extends AtomIO.ƒn>(\n\ttoken: AtomIO.TransactionToken<ƒ>,\n): (...parameters: Parameters<ƒ>) => ReturnType<ƒ> {\n\tconst store = React.useContext(StoreContext)\n\n\tuseRealtimeService(`tx:${token.key}`, (socket) =>\n\t\tRTC.serverAction(token, socket, store),\n\t)\n\treturn actUponStore(token, arbitrary(), store)\n}\n","import { StoreContext } from \"atom.io/react\"\nimport * as React from \"react\"\nimport { syncContinuity } from \"../../realtime-client/src/sync-continuity\"\nimport type { ContinuityToken } from \"../../realtime/src/realtime-continuity\"\nimport { useRealtimeService } from \"./use-realtime-service\"\n\nexport function useSyncContinuity(token: ContinuityToken): void {\n\tconst store = React.useContext(StoreContext)\n\tuseRealtimeService(`tx-sync:${token.key}`, (socket) => {\n\t\treturn syncContinuity(token, socket, store)\n\t})\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { deleteAtom } from \"atom.io/internal\"\nimport {\n\tactUponStore,\n\tassignTransactionToContinuity,\n\tgetEpochNumberOfContinuity,\n\tgetFromStore,\n\tgetJsonToken,\n\tingestTransactionUpdate,\n\tisRootStore,\n\tsetEpochNumberOfContinuity,\n\tsetIntoStore,\n\tsubscribeToTransaction,\n} from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport type { ContinuityToken } from \"atom.io/realtime\"\nimport {\n\tconfirmedUpdateQueue,\n\toptimisticUpdateQueue,\n} from \"atom.io/realtime-client\"\nimport type { Socket } from \"socket.io-client\"\n\nexport function syncContinuity<ƒ extends AtomIO.ƒn>(\n\tcontinuity: ContinuityToken,\n\tsocket: Socket,\n\tstore: Store,\n): () => void {\n\tconst continuityKey = continuity.key\n\tconst optimisticUpdates = getFromStore(optimisticUpdateQueue, store)\n\tconst confirmedUpdates = getFromStore(confirmedUpdateQueue, store)\n\n\tconst initializeContinuity = (epoch: number, payload: Json.Array) => {\n\t\tsocket.off(`continuity-init:${continuityKey}`, initializeContinuity)\n\t\tlet i = 0\n\t\tlet k: any = ``\n\t\tlet v: any = null\n\t\tfor (const x of payload) {\n\t\t\tif (i % 2 === 0) {\n\t\t\t\tk = x\n\t\t\t} else {\n\t\t\t\tv = x\n\t\t\t\t// console.log(`❗❗❗❗❗`, k, v)\n\t\t\t\tif (`type` in k && k.type === `mutable_atom`) {\n\t\t\t\t\tk = getJsonToken(k)\n\t\t\t\t}\n\t\t\t\tsetIntoStore(k, v, store)\n\t\t\t}\n\t\t\ti++\n\t\t}\n\t\tsetEpochNumberOfContinuity(continuityKey, epoch, store)\n\t}\n\tsocket.off(`continuity-init:${continuityKey}`)\n\tsocket.on(`continuity-init:${continuityKey}`, initializeContinuity)\n\n\tconst registerAndAttemptConfirmedUpdate = (\n\t\tconfirmedUpdate: AtomIO.TransactionUpdate<ƒ>,\n\t) => {\n\t\tfunction reconcileEpoch(\n\t\t\toptimisticUpdate: AtomIO.TransactionUpdate<any>,\n\t\t\tconfirmedUpdate: AtomIO.TransactionUpdate<any>,\n\t\t): void {\n\t\t\tstore.logger.info(\n\t\t\t\t`🧑⚖️`,\n\t\t\t\t`continuity`,\n\t\t\t\tcontinuityKey,\n\t\t\t\t`reconciling updates`,\n\t\t\t)\n\t\t\tsetIntoStore(\n\t\t\t\toptimisticUpdateQueue,\n\t\t\t\t(queue) => {\n\t\t\t\t\tqueue.shift()\n\t\t\t\t\treturn queue\n\t\t\t\t},\n\t\t\t\tstore,\n\t\t\t)\n\t\t\tif (optimisticUpdate.id === confirmedUpdate.id) {\n\t\t\t\tconst clientResult = JSON.stringify(optimisticUpdate.updates)\n\t\t\t\tconst serverResult = JSON.stringify(confirmedUpdate.updates)\n\t\t\t\tif (clientResult === serverResult) {\n\t\t\t\t\tstore.logger.info(\n\t\t\t\t\t\t`✅`,\n\t\t\t\t\t\t`continuity`,\n\t\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t\t`results for ${optimisticUpdate.id} match between client and server`,\n\t\t\t\t\t)\n\t\t\t\t\tsocket.emit(`ack:${continuityKey}`, confirmedUpdate.epoch)\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// id mismatch\n\t\t\t\tstore.logger.info(\n\t\t\t\t\t`❌`,\n\t\t\t\t\t`continuity`,\n\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t`thought update #${confirmedUpdate.epoch} was ${optimisticUpdate.key}:${optimisticUpdate.id}, but it was actually ${confirmedUpdate.key}:${confirmedUpdate.id}`,\n\t\t\t\t)\n\t\t\t}\n\t\t\tstore.logger.info(\n\t\t\t\t`🧑⚖️`,\n\t\t\t\t`continuity`,\n\t\t\t\tcontinuityKey,\n\t\t\t\t`updates do not match`,\n\t\t\t\toptimisticUpdate,\n\t\t\t\tconfirmedUpdate,\n\t\t\t)\n\t\t\tconst reversedOptimisticUpdates = optimisticUpdates.toReversed()\n\t\t\tfor (const subsequentOptimistic of reversedOptimisticUpdates) {\n\t\t\t\tingestTransactionUpdate(`oldValue`, subsequentOptimistic, store)\n\t\t\t}\n\t\t\tstore.logger.info(\n\t\t\t\t`⏪`,\n\t\t\t\t`continuity`,\n\t\t\t\tcontinuityKey,\n\t\t\t\t`undid optimistic updates:`,\n\t\t\t\treversedOptimisticUpdates,\n\t\t\t)\n\t\t\tingestTransactionUpdate(`oldValue`, optimisticUpdate, store)\n\t\t\tstore.logger.info(\n\t\t\t\t`⏪`,\n\t\t\t\t`continuity`,\n\t\t\t\tcontinuityKey,\n\t\t\t\t`undid zeroth optimistic update`,\n\t\t\t\toptimisticUpdate,\n\t\t\t)\n\t\t\tingestTransactionUpdate(`newValue`, confirmedUpdate, store)\n\t\t\tstore.logger.info(\n\t\t\t\t`⏩`,\n\t\t\t\t`continuity`,\n\t\t\t\tcontinuityKey,\n\t\t\t\t`applied confirmed update`,\n\t\t\t\tconfirmedUpdate,\n\t\t\t)\n\t\t\tsocket.emit(`ack:${continuityKey}`, confirmedUpdate.epoch)\n\n\t\t\tfor (const subsequentOptimistic of optimisticUpdates) {\n\t\t\t\tconst token = {\n\t\t\t\t\ttype: `transaction`,\n\t\t\t\t\tkey: subsequentOptimistic.key,\n\t\t\t\t} as const\n\t\t\t\tconst { id, params } = subsequentOptimistic\n\t\t\t\tactUponStore(token, id, store)(...params)\n\t\t\t}\n\t\t\tstore.logger.info(\n\t\t\t\t`⏩`,\n\t\t\t\t`continuity`,\n\t\t\t\tcontinuityKey,\n\t\t\t\t`reapplied subsequent optimistic updates:`,\n\t\t\t\toptimisticUpdates,\n\t\t\t)\n\t\t}\n\n\t\tstore.logger.info(\n\t\t\t`🧑⚖️`,\n\t\t\t`continuity`,\n\t\t\tcontinuityKey,\n\t\t\t`integrating confirmed update`,\n\t\t\t{ confirmedUpdate, confirmedUpdates, optimisticUpdates },\n\t\t)\n\t\tconst zerothOptimisticUpdate = optimisticUpdates[0]\n\t\tif (zerothOptimisticUpdate) {\n\t\t\tstore.logger.info(\n\t\t\t\t`🧑⚖️`,\n\t\t\t\t`continuity`,\n\t\t\t\tcontinuityKey,\n\t\t\t\t`has optimistic updates to reconcile`,\n\t\t\t)\n\t\t\tif (confirmedUpdate.epoch === zerothOptimisticUpdate.epoch) {\n\t\t\t\tstore.logger.info(\n\t\t\t\t\t`🧑⚖️`,\n\t\t\t\t\t`continuity`,\n\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t`epoch of confirmed update #${confirmedUpdate.epoch} matches zeroth optimistic update`,\n\t\t\t\t)\n\t\t\t\treconcileEpoch(zerothOptimisticUpdate, confirmedUpdate)\n\t\t\t\tfor (const nextConfirmed of confirmedUpdates) {\n\t\t\t\t\tconst nextOptimistic = optimisticUpdates[0]\n\t\t\t\t\tif (nextConfirmed.epoch === nextOptimistic?.epoch) {\n\t\t\t\t\t\treconcileEpoch(nextOptimistic, nextConfirmed)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// epoch mismatch\n\t\t\t\tstore.logger.info(\n\t\t\t\t\t`🧑⚖️`,\n\t\t\t\t\t`continuity`,\n\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t`epoch of confirmed update #${confirmedUpdate.epoch} does not match zeroth optimistic update #${zerothOptimisticUpdate.epoch}`,\n\t\t\t\t)\n\t\t\t\tconst confirmedUpdateIsAlreadyEnqueued = confirmedUpdates.some(\n\t\t\t\t\t(update) => update.epoch === confirmedUpdate.epoch,\n\t\t\t\t)\n\t\t\t\tif (!confirmedUpdateIsAlreadyEnqueued) {\n\t\t\t\t\tstore.logger.info(\n\t\t\t\t\t\t`👈`,\n\t\t\t\t\t\t`continuity`,\n\t\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t\t`pushing confirmed update to queue`,\n\t\t\t\t\t\tconfirmedUpdate,\n\t\t\t\t\t)\n\t\t\t\t\tsetIntoStore(\n\t\t\t\t\t\tconfirmedUpdateQueue,\n\t\t\t\t\t\t(queue) => {\n\t\t\t\t\t\t\tqueue.push(confirmedUpdate)\n\t\t\t\t\t\t\tqueue.sort((a, b) => a.epoch - b.epoch)\n\t\t\t\t\t\t\treturn queue\n\t\t\t\t\t\t},\n\t\t\t\t\t\tstore,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tstore.logger.info(\n\t\t\t\t`🧑⚖️`,\n\t\t\t\t`continuity`,\n\t\t\t\tcontinuityKey,\n\t\t\t\t`has no optimistic updates to deal with`,\n\t\t\t)\n\t\t\tconst continuityEpoch = getEpochNumberOfContinuity(continuityKey, store)\n\t\t\tconst isRoot = isRootStore(store)\n\n\t\t\tif (isRoot && continuityEpoch === confirmedUpdate.epoch - 1) {\n\t\t\t\tstore.logger.info(\n\t\t\t\t\t`✅`,\n\t\t\t\t\t`continuity`,\n\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t`integrating update #${confirmedUpdate.epoch} (${confirmedUpdate.key} ${confirmedUpdate.id})`,\n\t\t\t\t)\n\t\t\t\tingestTransactionUpdate(`newValue`, confirmedUpdate, store)\n\t\t\t\tsocket.emit(`ack:${continuityKey}`, confirmedUpdate.epoch)\n\t\t\t\tsetEpochNumberOfContinuity(continuityKey, confirmedUpdate.epoch, store)\n\t\t\t} else if (isRoot && continuityEpoch !== undefined) {\n\t\t\t\tstore.logger.info(\n\t\t\t\t\t`🧑⚖️`,\n\t\t\t\t\t`continuity`,\n\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t`received update #${\n\t\t\t\t\t\tconfirmedUpdate.epoch\n\t\t\t\t\t} but still waiting for update #${continuityEpoch + 1}`,\n\t\t\t\t\t{\n\t\t\t\t\t\tclientEpoch: continuityEpoch,\n\t\t\t\t\t\tserverEpoch: confirmedUpdate.epoch,\n\t\t\t\t\t},\n\t\t\t\t)\n\t\t\t\tconst confirmedUpdateIsAlreadyEnqueued = confirmedUpdates.some(\n\t\t\t\t\t(update) => update.epoch === confirmedUpdate.epoch,\n\t\t\t\t)\n\t\t\t\tif (confirmedUpdateIsAlreadyEnqueued) {\n\t\t\t\t\tstore.logger.info(\n\t\t\t\t\t\t`👍`,\n\t\t\t\t\t\t`continuity`,\n\t\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t\t`confirmed update #${confirmedUpdate.epoch} is already enqueued`,\n\t\t\t\t\t)\n\t\t\t\t} else {\n\t\t\t\t\tstore.logger.info(\n\t\t\t\t\t\t`👈`,\n\t\t\t\t\t\t`continuity`,\n\t\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t\t`pushing confirmed update #${confirmedUpdate.epoch} to queue`,\n\t\t\t\t\t)\n\t\t\t\t\tsetIntoStore(\n\t\t\t\t\t\tconfirmedUpdateQueue,\n\t\t\t\t\t\t(queue) => {\n\t\t\t\t\t\t\tqueue.push(confirmedUpdate)\n\t\t\t\t\t\t\tqueue.sort((a, b) => a.epoch - b.epoch)\n\t\t\t\t\t\t\treturn queue\n\t\t\t\t\t\t},\n\t\t\t\t\t\tstore,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tsocket.off(`tx-new:${continuityKey}`)\n\tsocket.on(`tx-new:${continuityKey}`, registerAndAttemptConfirmedUpdate)\n\n\tconst unsubscribeFunctions = continuity.actions.map((transaction) => {\n\t\tassignTransactionToContinuity(continuityKey, transaction.key, store)\n\t\tconst unsubscribeFromTransactionUpdates = subscribeToTransaction(\n\t\t\ttransaction,\n\t\t\t(clientUpdate) => {\n\t\t\t\tstore.logger.info(\n\t\t\t\t\t`🤞`,\n\t\t\t\t\t`continuity`,\n\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t`enqueuing optimistic update`,\n\t\t\t\t)\n\t\t\t\tconst optimisticUpdateIndex = optimisticUpdates.findIndex(\n\t\t\t\t\t(update) => update.id === clientUpdate.id,\n\t\t\t\t)\n\t\t\t\tif (optimisticUpdateIndex === -1) {\n\t\t\t\t\tstore.logger.info(\n\t\t\t\t\t\t`🤞`,\n\t\t\t\t\t\t`continuity`,\n\t\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t\t`enqueuing new optimistic update`,\n\t\t\t\t\t)\n\t\t\t\t\tsetIntoStore(\n\t\t\t\t\t\toptimisticUpdateQueue,\n\t\t\t\t\t\t(queue) => {\n\t\t\t\t\t\t\tqueue.push(clientUpdate)\n\t\t\t\t\t\t\tqueue.sort((a, b) => a.epoch - b.epoch)\n\t\t\t\t\t\t\treturn queue\n\t\t\t\t\t\t},\n\t\t\t\t\t\tstore,\n\t\t\t\t\t)\n\t\t\t\t} else {\n\t\t\t\t\tstore.logger.info(\n\t\t\t\t\t\t`🤞`,\n\t\t\t\t\t\t`continuity`,\n\t\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t\t`replacing existing optimistic update at index ${optimisticUpdateIndex}`,\n\t\t\t\t\t)\n\t\t\t\t\tsetIntoStore(\n\t\t\t\t\t\toptimisticUpdateQueue,\n\t\t\t\t\t\t(queue) => {\n\t\t\t\t\t\t\tqueue[optimisticUpdateIndex] = clientUpdate\n\t\t\t\t\t\t\treturn queue\n\t\t\t\t\t\t},\n\t\t\t\t\t\tstore,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tsocket.emit(`tx-run:${continuityKey}`, {\n\t\t\t\t\tid: clientUpdate.id,\n\t\t\t\t\tkey: transaction.key,\n\t\t\t\t\tparams: clientUpdate.params,\n\t\t\t\t})\n\t\t\t},\n\t\t\t`tx-run:${continuityKey}`,\n\t\t\tstore,\n\t\t)\n\t\treturn unsubscribeFromTransactionUpdates\n\t})\n\n\tsocket.on(`reveal:${continuityKey}`, (revealed: Json.Array) => {\n\t\tlet i = 0\n\t\tlet k: any = ``\n\t\tlet v: any = null\n\t\tfor (const x of revealed) {\n\t\t\tif (i % 2 === 0) {\n\t\t\t\tk = x\n\t\t\t} else {\n\t\t\t\tv = x\n\t\t\t\tsetIntoStore(k, v, store)\n\t\t\t}\n\t\t\ti++\n\t\t}\n\t})\n\tsocket.on(\n\t\t`conceal:${continuityKey}`,\n\t\t(concealed: AtomIO.AtomToken<unknown>[]) => {\n\t\t\tfor (const token of concealed) {\n\t\t\t\tdeleteAtom(token, store)\n\t\t\t}\n\t\t},\n\t)\n\n\tsocket.emit(`get:${continuityKey}`)\n\treturn () => {\n\t\tsocket.off(`continuity-init:${continuityKey}`)\n\t\tsocket.off(`tx-new:${continuityKey}`)\n\t\tfor (const unsubscribe of unsubscribeFunctions) unsubscribe()\n\t\t// socket.emit(`unsub:${continuityKey}`)\n\t}\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { Socket } from 'socket.io-client';
|
|
3
3
|
import * as AtomIO from 'atom.io';
|
|
4
|
+
import { AtomToken, TransactionToken, AtomFamilyToken, ReadableFamilyToken, ReadableToken } from 'atom.io';
|
|
4
5
|
import { Json } from 'atom.io/json';
|
|
5
6
|
import { Transceiver } from 'atom.io/internal';
|
|
6
7
|
|
|
@@ -17,20 +18,35 @@ declare const RealtimeProvider: React.FC<{
|
|
|
17
18
|
socket: Socket | null;
|
|
18
19
|
}>;
|
|
19
20
|
|
|
20
|
-
declare function
|
|
21
|
+
declare function usePullAtom<J extends Json.Serializable>(token: AtomIO.RegularAtomToken<J>): J;
|
|
21
22
|
|
|
22
|
-
declare function
|
|
23
|
+
declare function usePullAtomFamilyMember<J extends Json.Serializable, K extends Json.Serializable, Key extends K>(family: AtomIO.RegularAtomFamilyToken<J, K>, subKey: Key): J;
|
|
23
24
|
|
|
24
|
-
declare function usePullMutable<T extends Transceiver<any>, J extends Json.Serializable>(token: AtomIO.MutableAtomToken<T, J>):
|
|
25
|
+
declare function usePullMutable<T extends Transceiver<any>, J extends Json.Serializable>(token: AtomIO.MutableAtomToken<T, J>): T;
|
|
25
26
|
|
|
26
|
-
declare function
|
|
27
|
+
declare function usePullMutableAtomFamilyMember<T extends Transceiver<any>, J extends Json.Serializable, K extends Json.Serializable, Key extends K>(familyToken: AtomIO.MutableAtomFamilyToken<T, J, K>, key: Key): T;
|
|
27
28
|
|
|
28
|
-
declare function
|
|
29
|
+
declare function usePullSelector<J extends Json.Serializable>(token: AtomIO.SelectorToken<J>): J;
|
|
30
|
+
|
|
31
|
+
declare function usePullSelectorFamilyMember<T, K extends Json.Serializable, Key extends K>(familyToken: AtomIO.SelectorFamilyToken<T, K>, key: Key): T;
|
|
32
|
+
|
|
33
|
+
declare function usePush<J extends Json.Serializable>(token: AtomIO.WritableToken<J>): <New extends J>(next: New | ((old: J) => New)) => void;
|
|
29
34
|
|
|
30
35
|
declare function useServerAction<ƒ extends AtomIO.ƒn>(token: AtomIO.TransactionToken<ƒ>): (...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
|
|
31
36
|
|
|
32
|
-
|
|
37
|
+
type PerspectiveToken<F extends AtomFamilyToken<any>, T extends F extends AtomFamilyToken<infer T, any> ? T : never> = {
|
|
38
|
+
type: `realtime_perspective`;
|
|
39
|
+
resourceAtoms: F;
|
|
40
|
+
viewAtoms: ReadableFamilyToken<ReadableToken<T>[], string>;
|
|
41
|
+
};
|
|
42
|
+
type ContinuityToken = {
|
|
43
|
+
readonly type: `continuity`;
|
|
44
|
+
readonly key: string;
|
|
45
|
+
readonly globals: AtomToken<any>[];
|
|
46
|
+
readonly actions: TransactionToken<any>[];
|
|
47
|
+
readonly perspectives: PerspectiveToken<AtomFamilyToken<any, Json.Serializable>, Json.Serializable>[];
|
|
48
|
+
};
|
|
33
49
|
|
|
34
|
-
declare function
|
|
50
|
+
declare function useSyncContinuity(token: ContinuityToken): void;
|
|
35
51
|
|
|
36
|
-
export { RealtimeContext, RealtimeProvider, type RealtimeReactStore,
|
|
52
|
+
export { RealtimeContext, RealtimeProvider, type RealtimeReactStore, usePullAtom, usePullAtomFamilyMember, usePullMutable, usePullMutableAtomFamilyMember, usePullSelector, usePullSelectorFamilyMember, usePush, useServerAction, useSyncContinuity };
|