atom.io 0.25.6 → 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/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.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 +18 -50
- 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
|
@@ -1,965 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var json = require('atom.io/json');
|
|
4
|
-
var internal = require('atom.io/internal');
|
|
5
|
-
var setRtx = require('atom.io/transceivers/set-rtx');
|
|
6
|
-
var data = require('atom.io/data');
|
|
7
|
-
var AtomIO = require('atom.io');
|
|
8
|
-
var realtime = require('atom.io/realtime');
|
|
9
|
-
var child_process = require('child_process');
|
|
10
|
-
|
|
11
|
-
function _interopNamespace(e) {
|
|
12
|
-
if (e && e.__esModule) return e;
|
|
13
|
-
var n = Object.create(null);
|
|
14
|
-
if (e) {
|
|
15
|
-
Object.keys(e).forEach(function (k) {
|
|
16
|
-
if (k !== 'default') {
|
|
17
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
18
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
get: function () { return e[k]; }
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
n.default = e;
|
|
26
|
-
return Object.freeze(n);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
var AtomIO__namespace = /*#__PURE__*/_interopNamespace(AtomIO);
|
|
30
|
-
|
|
31
|
-
var __defProp = Object.defineProperty;
|
|
32
|
-
var __defProps = Object.defineProperties;
|
|
33
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
34
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
35
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
36
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
37
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
38
|
-
var __spreadValues = (a, b) => {
|
|
39
|
-
for (var prop in b || (b = {}))
|
|
40
|
-
if (__hasOwnProp.call(b, prop))
|
|
41
|
-
__defNormalProp(a, prop, b[prop]);
|
|
42
|
-
if (__getOwnPropSymbols)
|
|
43
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
44
|
-
if (__propIsEnum.call(b, prop))
|
|
45
|
-
__defNormalProp(a, prop, b[prop]);
|
|
46
|
-
}
|
|
47
|
-
return a;
|
|
48
|
-
};
|
|
49
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
50
|
-
|
|
51
|
-
// realtime-server/src/ipc-sockets/custom-socket.ts
|
|
52
|
-
var CustomSocket = class {
|
|
53
|
-
constructor(emit) {
|
|
54
|
-
this.emit = emit;
|
|
55
|
-
this.id = `no_id_retrieved`;
|
|
56
|
-
this.listeners = /* @__PURE__ */ new Map();
|
|
57
|
-
this.globalListeners = /* @__PURE__ */ new Set();
|
|
58
|
-
}
|
|
59
|
-
handleEvent(event, ...args) {
|
|
60
|
-
for (const listener of this.globalListeners) {
|
|
61
|
-
listener(event, ...args);
|
|
62
|
-
}
|
|
63
|
-
const listeners = this.listeners.get(event);
|
|
64
|
-
if (listeners) {
|
|
65
|
-
for (const listener of listeners) {
|
|
66
|
-
listener(...args);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
on(event, listener) {
|
|
71
|
-
const listeners = this.listeners.get(event);
|
|
72
|
-
if (listeners) {
|
|
73
|
-
listeners.add(listener);
|
|
74
|
-
} else {
|
|
75
|
-
this.listeners.set(event, /* @__PURE__ */ new Set([listener]));
|
|
76
|
-
}
|
|
77
|
-
return this;
|
|
78
|
-
}
|
|
79
|
-
onAny(listener) {
|
|
80
|
-
this.globalListeners.add(listener);
|
|
81
|
-
return this;
|
|
82
|
-
}
|
|
83
|
-
off(event, listener) {
|
|
84
|
-
const listeners = this.listeners.get(event);
|
|
85
|
-
if (listeners) {
|
|
86
|
-
if (listener) {
|
|
87
|
-
listeners.delete(listener);
|
|
88
|
-
} else {
|
|
89
|
-
this.listeners.delete(event);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return this;
|
|
93
|
-
}
|
|
94
|
-
offAny(listener) {
|
|
95
|
-
this.globalListeners.delete(listener);
|
|
96
|
-
return this;
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
// realtime-server/src/ipc-sockets/child-socket.ts
|
|
101
|
-
var ChildSocket = class extends CustomSocket {
|
|
102
|
-
constructor(process2, key, logger = console) {
|
|
103
|
-
super((event, ...args) => {
|
|
104
|
-
const stringifiedEvent = JSON.stringify([event, ...args]) + ``;
|
|
105
|
-
const errorHandler = (err) => {
|
|
106
|
-
if (err.code === `EPIPE`) {
|
|
107
|
-
console.error(`EPIPE error during write`, this.process.stdin);
|
|
108
|
-
}
|
|
109
|
-
this.process.stdin.removeListener(`error`, errorHandler);
|
|
110
|
-
};
|
|
111
|
-
this.process.stdin.once(`error`, errorHandler);
|
|
112
|
-
this.process.stdin.write(stringifiedEvent);
|
|
113
|
-
return this;
|
|
114
|
-
});
|
|
115
|
-
this.process = process2;
|
|
116
|
-
this.key = key;
|
|
117
|
-
this.logger = logger;
|
|
118
|
-
this.incompleteData = ``;
|
|
119
|
-
this.unprocessedEvents = [];
|
|
120
|
-
this.incompleteLog = ``;
|
|
121
|
-
this.unprocessedLogs = [];
|
|
122
|
-
this.id = `#####`;
|
|
123
|
-
this.process = process2;
|
|
124
|
-
this.process.stdout.on(
|
|
125
|
-
`data`,
|
|
126
|
-
(buffer) => {
|
|
127
|
-
const chunk = buffer.toString();
|
|
128
|
-
if (chunk === `\u2728`) {
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
this.unprocessedEvents.push(...chunk.split(``));
|
|
132
|
-
const newInput = this.unprocessedEvents.shift();
|
|
133
|
-
this.incompleteData += newInput != null ? newInput : ``;
|
|
134
|
-
try {
|
|
135
|
-
if (this.incompleteData.startsWith(`error`)) {
|
|
136
|
-
console.log(`\u2757`, this.incompleteData);
|
|
137
|
-
}
|
|
138
|
-
let parsedEvent = json.parseJson(this.incompleteData);
|
|
139
|
-
this.handleEvent(...parsedEvent);
|
|
140
|
-
while (this.unprocessedEvents.length > 0) {
|
|
141
|
-
const event = this.unprocessedEvents.shift();
|
|
142
|
-
if (event) {
|
|
143
|
-
if (this.unprocessedEvents.length === 0) {
|
|
144
|
-
this.incompleteData = event;
|
|
145
|
-
}
|
|
146
|
-
parsedEvent = json.parseJson(event);
|
|
147
|
-
this.handleEvent(...parsedEvent);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
this.incompleteData = ``;
|
|
151
|
-
} catch (error) {
|
|
152
|
-
console.warn(`\u26A0\uFE0F----------------\u26A0\uFE0F`);
|
|
153
|
-
console.warn(this.incompleteData);
|
|
154
|
-
console.warn(`\u26A0\uFE0F----------------\u26A0\uFE0F`);
|
|
155
|
-
console.error(error);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
);
|
|
159
|
-
this.process.stderr.on(`data`, (buf) => {
|
|
160
|
-
var _a;
|
|
161
|
-
const chunk = buf.toString();
|
|
162
|
-
this.unprocessedLogs.push(...chunk.split(``));
|
|
163
|
-
const newInput = this.unprocessedLogs.shift();
|
|
164
|
-
this.incompleteLog += newInput != null ? newInput : ``;
|
|
165
|
-
try {
|
|
166
|
-
let parsedLog = json.parseJson(this.incompleteLog);
|
|
167
|
-
this.handleLog(parsedLog);
|
|
168
|
-
while (this.unprocessedLogs.length > 0) {
|
|
169
|
-
this.incompleteLog = (_a = this.unprocessedLogs.shift()) != null ? _a : ``;
|
|
170
|
-
if (this.incompleteLog) {
|
|
171
|
-
parsedLog = json.parseJson(this.incompleteLog);
|
|
172
|
-
this.handleLog(parsedLog);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
} catch (error) {
|
|
176
|
-
console.error(`\u274C\u274C\u274C`);
|
|
177
|
-
console.error(this.incompleteLog);
|
|
178
|
-
console.error(error);
|
|
179
|
-
console.error(`\u274C\u274C\u274C\uFE0F`);
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
if (process2.pid) {
|
|
183
|
-
this.id = process2.pid.toString();
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
handleLog(arg) {
|
|
187
|
-
if (Array.isArray(arg)) {
|
|
188
|
-
const [level, ...rest] = arg;
|
|
189
|
-
switch (level) {
|
|
190
|
-
case `i`:
|
|
191
|
-
this.logger.info(this.id, this.key, ...rest);
|
|
192
|
-
break;
|
|
193
|
-
case `w`:
|
|
194
|
-
this.logger.warn(this.id, this.key, ...rest);
|
|
195
|
-
break;
|
|
196
|
-
case `e`:
|
|
197
|
-
this.logger.error(this.id, this.key, ...rest);
|
|
198
|
-
break;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
var SubjectSocket = class extends CustomSocket {
|
|
204
|
-
constructor(id) {
|
|
205
|
-
super((...args) => {
|
|
206
|
-
this.out.next(args);
|
|
207
|
-
return this;
|
|
208
|
-
});
|
|
209
|
-
this.id = `no_id_retrieved`;
|
|
210
|
-
this.disposalFunctions = [];
|
|
211
|
-
this.id = id;
|
|
212
|
-
this.in = new internal.Subject();
|
|
213
|
-
this.out = new internal.Subject();
|
|
214
|
-
this.in.subscribe(`socket`, (event) => {
|
|
215
|
-
this.handleEvent(...event);
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
dispose() {
|
|
219
|
-
for (const dispose of this.disposalFunctions) {
|
|
220
|
-
dispose();
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
};
|
|
224
|
-
var ParentSocket = class extends CustomSocket {
|
|
225
|
-
constructor() {
|
|
226
|
-
var _a;
|
|
227
|
-
super((event, ...args) => {
|
|
228
|
-
const stringifiedEvent = JSON.stringify([event, ...args]);
|
|
229
|
-
this.process.stdout.write(stringifiedEvent + ``);
|
|
230
|
-
return this;
|
|
231
|
-
});
|
|
232
|
-
this.incompleteData = ``;
|
|
233
|
-
this.unprocessedEvents = [];
|
|
234
|
-
this.id = `#####`;
|
|
235
|
-
this.logger = {
|
|
236
|
-
info: (...args) => {
|
|
237
|
-
this.log(`i`, ...args);
|
|
238
|
-
},
|
|
239
|
-
warn: (...args) => {
|
|
240
|
-
this.log(`w`, ...args);
|
|
241
|
-
},
|
|
242
|
-
error: (...args) => {
|
|
243
|
-
this.log(`e`, ...args);
|
|
244
|
-
}
|
|
245
|
-
};
|
|
246
|
-
this.process = process;
|
|
247
|
-
this.process.stdin.resume();
|
|
248
|
-
this.relays = /* @__PURE__ */ new Map();
|
|
249
|
-
this.relayServices = [];
|
|
250
|
-
this.process.stdin.on(
|
|
251
|
-
`data`,
|
|
252
|
-
(buffer) => {
|
|
253
|
-
const chunk = buffer.toString();
|
|
254
|
-
this.unprocessedEvents.push(...chunk.split(``));
|
|
255
|
-
const newInput = this.unprocessedEvents.shift();
|
|
256
|
-
this.incompleteData += newInput != null ? newInput : ``;
|
|
257
|
-
try {
|
|
258
|
-
const parsedData = json.parseJson(this.incompleteData);
|
|
259
|
-
this.logger.info(`\u{1F3B0}`, `received`, parsedData);
|
|
260
|
-
this.handleEvent(...parsedData);
|
|
261
|
-
while (this.unprocessedEvents.length > 0) {
|
|
262
|
-
const event = this.unprocessedEvents.shift();
|
|
263
|
-
if (event) {
|
|
264
|
-
if (this.unprocessedEvents.length === 0) {
|
|
265
|
-
this.incompleteData = event;
|
|
266
|
-
}
|
|
267
|
-
const parsedEvent = json.parseJson(event);
|
|
268
|
-
this.handleEvent(...parsedEvent);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
this.incompleteData = ``;
|
|
272
|
-
} catch (thrown) {
|
|
273
|
-
if (thrown instanceof Error) {
|
|
274
|
-
this.logger.error(`\u2757`, thrown.message, thrown.cause, thrown.stack);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
);
|
|
279
|
-
this.on(`exit`, () => {
|
|
280
|
-
this.logger.info(`\u{1F525}`, this.id, `received "exit"`);
|
|
281
|
-
process.exit(0);
|
|
282
|
-
});
|
|
283
|
-
process.on(`exit`, (code) => {
|
|
284
|
-
this.logger.info(`\u{1F525}`, this.id, `exited with code ${code}`);
|
|
285
|
-
});
|
|
286
|
-
process.on(`end`, () => {
|
|
287
|
-
this.logger.info(`\u{1F525}`, this.id, `ended`);
|
|
288
|
-
process.exit(0);
|
|
289
|
-
});
|
|
290
|
-
process.on(`SIGTERM`, () => {
|
|
291
|
-
this.logger.error(`\u{1F525}`, this.id, `terminated`);
|
|
292
|
-
process.exit(0);
|
|
293
|
-
});
|
|
294
|
-
process.on(`SIGINT`, () => {
|
|
295
|
-
this.logger.error(`\u{1F525}`, this.id, `interrupted`);
|
|
296
|
-
process.exit(0);
|
|
297
|
-
});
|
|
298
|
-
if (process.pid) {
|
|
299
|
-
this.id = (_a = process.pid) == null ? void 0 : _a.toString();
|
|
300
|
-
}
|
|
301
|
-
this.on(`user-joins`, (username) => {
|
|
302
|
-
this.logger.info(`\u{1F464}`, `user`, username, `joined`);
|
|
303
|
-
const relay = new SubjectSocket(`user:${username}`);
|
|
304
|
-
this.relays.set(username, relay);
|
|
305
|
-
this.logger.info(
|
|
306
|
-
`\u{1F517}`,
|
|
307
|
-
`attaching services:`,
|
|
308
|
-
`[${[...this.relayServices.keys()].join(`, `)}]`
|
|
309
|
-
);
|
|
310
|
-
for (const attachServices of this.relayServices) {
|
|
311
|
-
const cleanup = attachServices(relay);
|
|
312
|
-
if (cleanup) {
|
|
313
|
-
relay.disposalFunctions.push(cleanup);
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
this.on(`user:${username}`, (...data) => {
|
|
317
|
-
relay.in.next(data);
|
|
318
|
-
});
|
|
319
|
-
relay.out.subscribe(`socket`, (data) => {
|
|
320
|
-
this.emit(...data);
|
|
321
|
-
});
|
|
322
|
-
});
|
|
323
|
-
this.on(`user-leaves`, (username) => {
|
|
324
|
-
const relay = this.relays.get(username);
|
|
325
|
-
this.off(`relay:${username}`);
|
|
326
|
-
if (relay) {
|
|
327
|
-
relay.dispose();
|
|
328
|
-
this.relays.delete(username);
|
|
329
|
-
}
|
|
330
|
-
});
|
|
331
|
-
process.stdout.write(`\u2728`);
|
|
332
|
-
}
|
|
333
|
-
log(...args) {
|
|
334
|
-
this.process.stderr.write(
|
|
335
|
-
json.stringifyJson(
|
|
336
|
-
args.map(
|
|
337
|
-
(arg) => arg instanceof setRtx.SetRTX ? `{ ${arg.toJSON().members.join(` | `)} }` : arg
|
|
338
|
-
)
|
|
339
|
-
) + ``
|
|
340
|
-
);
|
|
341
|
-
}
|
|
342
|
-
relay(attachServices) {
|
|
343
|
-
this.logger.info(`\u{1F517}`, `running relay method`);
|
|
344
|
-
this.relayServices.push(attachServices);
|
|
345
|
-
}
|
|
346
|
-
};
|
|
347
|
-
function realtimeActionReceiver({
|
|
348
|
-
socket,
|
|
349
|
-
store = internal.IMPLICIT.STORE
|
|
350
|
-
}) {
|
|
351
|
-
return function actionReceiver(tx) {
|
|
352
|
-
const fillTransactionRequest = (update) => {
|
|
353
|
-
const performanceKey = `tx-run:${tx.key}:${update.id}`;
|
|
354
|
-
const performanceKeyStart = `${performanceKey}:start`;
|
|
355
|
-
const performanceKeyEnd = `${performanceKey}:end`;
|
|
356
|
-
performance.mark(performanceKeyStart);
|
|
357
|
-
internal.actUponStore(tx, update.id, store)(...update.params);
|
|
358
|
-
performance.mark(performanceKeyEnd);
|
|
359
|
-
const metric = performance.measure(
|
|
360
|
-
performanceKey,
|
|
361
|
-
performanceKeyStart,
|
|
362
|
-
performanceKeyEnd
|
|
363
|
-
);
|
|
364
|
-
store == null ? void 0 : store.logger.info(`\u{1F680}`, `transaction`, tx.key, update.id, metric.duration);
|
|
365
|
-
};
|
|
366
|
-
socket.on(`tx-run:${tx.key}`, fillTransactionRequest);
|
|
367
|
-
return () => {
|
|
368
|
-
socket.off(`tx-run:${tx.key}`, fillTransactionRequest);
|
|
369
|
-
};
|
|
370
|
-
};
|
|
371
|
-
}
|
|
372
|
-
var roomArgumentsAtoms = AtomIO.atomFamily({
|
|
373
|
-
key: `roomArguments`,
|
|
374
|
-
default: [`echo`, [`Hello World!`]]
|
|
375
|
-
});
|
|
376
|
-
var roomSelectors = AtomIO.selectorFamily({
|
|
377
|
-
key: `room`,
|
|
378
|
-
get: (roomId) => async ({ get, find }) => {
|
|
379
|
-
const argumentsState = find(roomArgumentsAtoms, roomId);
|
|
380
|
-
const args = get(argumentsState);
|
|
381
|
-
const [script, options] = args;
|
|
382
|
-
const child = await new Promise(
|
|
383
|
-
(resolve) => {
|
|
384
|
-
const room = child_process.spawn(script, options, { env: process.env });
|
|
385
|
-
const resolver = (data) => {
|
|
386
|
-
if (data.toString() === `\u2728`) {
|
|
387
|
-
room.stdout.off(`data`, resolver);
|
|
388
|
-
resolve(room);
|
|
389
|
-
}
|
|
390
|
-
};
|
|
391
|
-
room.stdout.on(`data`, resolver);
|
|
392
|
-
}
|
|
393
|
-
);
|
|
394
|
-
return new ChildSocket(child, roomId);
|
|
395
|
-
}
|
|
396
|
-
});
|
|
397
|
-
|
|
398
|
-
// realtime-server/src/realtime-server-stores/server-room-external-actions.ts
|
|
399
|
-
var createRoomTX = AtomIO__namespace.transaction({
|
|
400
|
-
key: `createRoom`,
|
|
401
|
-
do: ({ get, set, find }, roomId, script, options) => {
|
|
402
|
-
const args = options ? [script, options] : [script];
|
|
403
|
-
const roomArgumentsState = find(roomArgumentsAtoms, roomId);
|
|
404
|
-
set(roomArgumentsState, args);
|
|
405
|
-
set(realtime.roomIndex, (s) => s.add(roomId));
|
|
406
|
-
const roomState = find(roomSelectors, roomId);
|
|
407
|
-
const room = get(roomState);
|
|
408
|
-
return room;
|
|
409
|
-
}
|
|
410
|
-
});
|
|
411
|
-
var joinRoomTX = AtomIO__namespace.transaction({
|
|
412
|
-
key: `joinRoom`,
|
|
413
|
-
do: (tools, roomId, userId, enteredAtEpoch) => {
|
|
414
|
-
const meta = { enteredAtEpoch };
|
|
415
|
-
data.editRelationsInStore(
|
|
416
|
-
realtime.usersInRooms,
|
|
417
|
-
(relations) => {
|
|
418
|
-
relations.set({ room: roomId, user: userId }, meta);
|
|
419
|
-
},
|
|
420
|
-
tools.env().store
|
|
421
|
-
);
|
|
422
|
-
return meta;
|
|
423
|
-
}
|
|
424
|
-
});
|
|
425
|
-
var leaveRoomTX = AtomIO__namespace.transaction({
|
|
426
|
-
key: `leaveRoom`,
|
|
427
|
-
do: (tools, roomId, userId) => {
|
|
428
|
-
data.editRelationsInStore(
|
|
429
|
-
realtime.usersInRooms,
|
|
430
|
-
(relations) => {
|
|
431
|
-
relations.delete({ room: roomId, user: userId });
|
|
432
|
-
},
|
|
433
|
-
tools.env().store
|
|
434
|
-
);
|
|
435
|
-
}
|
|
436
|
-
});
|
|
437
|
-
var destroyRoomTX = AtomIO__namespace.transaction({
|
|
438
|
-
key: `destroyRoom`,
|
|
439
|
-
do: (tools, roomId) => {
|
|
440
|
-
data.editRelationsInStore(
|
|
441
|
-
realtime.usersInRooms,
|
|
442
|
-
(relations) => {
|
|
443
|
-
relations.delete({ room: roomId });
|
|
444
|
-
},
|
|
445
|
-
tools.env().store
|
|
446
|
-
);
|
|
447
|
-
tools.set(realtime.roomIndex, (s) => (s.delete(roomId), s));
|
|
448
|
-
}
|
|
449
|
-
});
|
|
450
|
-
function redactTransactionUpdateContent(visibleStateKeys, updates) {
|
|
451
|
-
return updates.map((update) => {
|
|
452
|
-
switch (update.type) {
|
|
453
|
-
case `transaction_update`: {
|
|
454
|
-
const redacted = redactTransactionUpdateContent(
|
|
455
|
-
visibleStateKeys,
|
|
456
|
-
update.updates
|
|
457
|
-
);
|
|
458
|
-
return __spreadProps(__spreadValues({}, update), { updates: redacted });
|
|
459
|
-
}
|
|
460
|
-
default:
|
|
461
|
-
return update;
|
|
462
|
-
}
|
|
463
|
-
}).filter((update) => {
|
|
464
|
-
switch (update.type) {
|
|
465
|
-
case `atom_update`:
|
|
466
|
-
case `selector_update`:
|
|
467
|
-
return visibleStateKeys.includes(update.key);
|
|
468
|
-
case `state_creation`:
|
|
469
|
-
return visibleStateKeys.includes(update.token.key);
|
|
470
|
-
case `molecule_creation`:
|
|
471
|
-
return true;
|
|
472
|
-
case `transaction_update`:
|
|
473
|
-
return true;
|
|
474
|
-
}
|
|
475
|
-
});
|
|
476
|
-
}
|
|
477
|
-
var actionOcclusionAtoms = AtomIO.atomFamily({
|
|
478
|
-
key: `transactionRedactor`,
|
|
479
|
-
default: { occlude: (updates) => updates }
|
|
480
|
-
});
|
|
481
|
-
var userUnacknowledgedQueues = AtomIO.atomFamily({
|
|
482
|
-
key: `unacknowledgedUpdates`,
|
|
483
|
-
default: () => []
|
|
484
|
-
});
|
|
485
|
-
var socketAtoms = AtomIO.atomFamily({
|
|
486
|
-
key: `sockets`,
|
|
487
|
-
default: null
|
|
488
|
-
});
|
|
489
|
-
var socketIndex = AtomIO.atom({
|
|
490
|
-
key: `socketsIndex`,
|
|
491
|
-
mutable: true,
|
|
492
|
-
default: () => new setRtx.SetRTX(),
|
|
493
|
-
toJson: (set) => set.toJSON(),
|
|
494
|
-
fromJson: (json) => setRtx.SetRTX.fromJSON(json)
|
|
495
|
-
});
|
|
496
|
-
var userIndex = AtomIO.atom({
|
|
497
|
-
key: `usersIndex`,
|
|
498
|
-
mutable: true,
|
|
499
|
-
default: () => new setRtx.SetRTX(),
|
|
500
|
-
toJson: (set) => set.toJSON(),
|
|
501
|
-
fromJson: (json) => setRtx.SetRTX.fromJSON(json)
|
|
502
|
-
});
|
|
503
|
-
var usersOfSockets = data.join({
|
|
504
|
-
key: `usersOfSockets`,
|
|
505
|
-
between: [`user`, `socket`],
|
|
506
|
-
cardinality: `1:1`
|
|
507
|
-
});
|
|
508
|
-
|
|
509
|
-
// realtime-server/src/realtime-continuity-synchronizer.ts
|
|
510
|
-
function realtimeContinuitySynchronizer({
|
|
511
|
-
socket: initialSocket,
|
|
512
|
-
store = internal.IMPLICIT.STORE
|
|
513
|
-
}) {
|
|
514
|
-
return function synchronizer(continuity) {
|
|
515
|
-
let socket = initialSocket;
|
|
516
|
-
const continuityKey = continuity.key;
|
|
517
|
-
const userKeyState = data.findRelationsInStore(
|
|
518
|
-
usersOfSockets,
|
|
519
|
-
socket.id,
|
|
520
|
-
store
|
|
521
|
-
).userKeyOfSocket;
|
|
522
|
-
const userKey = internal.getFromStore(userKeyState, store);
|
|
523
|
-
if (!userKey) {
|
|
524
|
-
store.logger.error(
|
|
525
|
-
`\u274C`,
|
|
526
|
-
`continuity`,
|
|
527
|
-
continuityKey,
|
|
528
|
-
`Tried to create a synchronizer for a socket (${socket.id}) that is not connected to a user.`
|
|
529
|
-
);
|
|
530
|
-
return () => {
|
|
531
|
-
};
|
|
532
|
-
}
|
|
533
|
-
const socketKeyState = data.findRelationsInStore(
|
|
534
|
-
usersOfSockets,
|
|
535
|
-
userKey,
|
|
536
|
-
store
|
|
537
|
-
).socketKeyOfUser;
|
|
538
|
-
internal.subscribeToState(
|
|
539
|
-
socketKeyState,
|
|
540
|
-
({ newValue: newSocketKey }) => {
|
|
541
|
-
store.logger.info(
|
|
542
|
-
`\u{1F44B}`,
|
|
543
|
-
`continuity`,
|
|
544
|
-
continuityKey,
|
|
545
|
-
`seeing ${userKey} on new socket ${newSocketKey}`
|
|
546
|
-
);
|
|
547
|
-
if (newSocketKey === null) {
|
|
548
|
-
store.logger.error(
|
|
549
|
-
`\u274C`,
|
|
550
|
-
`continuity`,
|
|
551
|
-
continuityKey,
|
|
552
|
-
`Tried to create a synchronizer for a user (${userKey}) that is not connected to a socket.`
|
|
553
|
-
);
|
|
554
|
-
return;
|
|
555
|
-
}
|
|
556
|
-
const newSocketState = internal.findInStore(socketAtoms, newSocketKey, store);
|
|
557
|
-
const newSocket = internal.getFromStore(newSocketState, store);
|
|
558
|
-
socket = newSocket;
|
|
559
|
-
},
|
|
560
|
-
`sync-continuity:${continuityKey}:${userKey}`,
|
|
561
|
-
store
|
|
562
|
-
);
|
|
563
|
-
const userUnacknowledgedQueue = internal.findInStore(
|
|
564
|
-
userUnacknowledgedQueues,
|
|
565
|
-
userKey,
|
|
566
|
-
store
|
|
567
|
-
);
|
|
568
|
-
internal.getFromStore(
|
|
569
|
-
userUnacknowledgedQueue,
|
|
570
|
-
store
|
|
571
|
-
);
|
|
572
|
-
const unsubscribeFunctions = [];
|
|
573
|
-
const revealPerspectives = () => {
|
|
574
|
-
const unsubFns = [];
|
|
575
|
-
for (const perspective of continuity.perspectives) {
|
|
576
|
-
const { viewAtoms } = perspective;
|
|
577
|
-
const userViewState = internal.findInStore(viewAtoms, userKey, store);
|
|
578
|
-
const unsubscribe = internal.subscribeToState(
|
|
579
|
-
userViewState,
|
|
580
|
-
({ oldValue, newValue }) => {
|
|
581
|
-
const oldKeys = oldValue.map((token) => token.key);
|
|
582
|
-
const newKeys = newValue.map((token) => token.key);
|
|
583
|
-
const concealed = oldValue.filter(
|
|
584
|
-
(token) => !newKeys.includes(token.key)
|
|
585
|
-
);
|
|
586
|
-
const revealed = newValue.filter((token) => !oldKeys.includes(token.key)).flatMap((token) => {
|
|
587
|
-
const resourceToken = token.type === `mutable_atom` ? internal.getJsonToken(token, store) : token;
|
|
588
|
-
const resource = internal.getFromStore(resourceToken, store);
|
|
589
|
-
return [resourceToken, resource];
|
|
590
|
-
});
|
|
591
|
-
store.logger.info(
|
|
592
|
-
`\u{1F441}`,
|
|
593
|
-
`atom`,
|
|
594
|
-
perspective.resourceAtoms.key,
|
|
595
|
-
`${userKey} has a new perspective`,
|
|
596
|
-
{ oldKeys, newKeys, revealed, concealed }
|
|
597
|
-
);
|
|
598
|
-
if (revealed.length > 0) {
|
|
599
|
-
socket == null ? void 0 : socket.emit(`reveal:${continuityKey}`, revealed);
|
|
600
|
-
}
|
|
601
|
-
if (concealed.length > 0) {
|
|
602
|
-
socket == null ? void 0 : socket.emit(`conceal:${continuityKey}`, concealed);
|
|
603
|
-
}
|
|
604
|
-
},
|
|
605
|
-
`sync-continuity:${continuityKey}:${userKey}:perspective:${perspective.resourceAtoms.key}`,
|
|
606
|
-
store
|
|
607
|
-
);
|
|
608
|
-
unsubFns.push(unsubscribe);
|
|
609
|
-
}
|
|
610
|
-
return () => {
|
|
611
|
-
for (const unsubscribe of unsubFns) unsubscribe();
|
|
612
|
-
};
|
|
613
|
-
};
|
|
614
|
-
const unsubscribeFromPerspectives = revealPerspectives();
|
|
615
|
-
const sendInitialPayload = () => {
|
|
616
|
-
var _a;
|
|
617
|
-
const initialPayload = [];
|
|
618
|
-
for (const atom2 of continuity.globals) {
|
|
619
|
-
const resourceToken = atom2.type === `mutable_atom` ? internal.getJsonToken(atom2, store) : atom2;
|
|
620
|
-
initialPayload.push(resourceToken, internal.getFromStore(atom2, store));
|
|
621
|
-
}
|
|
622
|
-
for (const perspective of continuity.perspectives) {
|
|
623
|
-
const { viewAtoms, resourceAtoms } = perspective;
|
|
624
|
-
const userViewState = internal.findInStore(viewAtoms, userKey, store);
|
|
625
|
-
const userView = internal.getFromStore(userViewState, store);
|
|
626
|
-
store.logger.info(`\u{1F441}`, `atom`, resourceAtoms.key, `${userKey} can see`, {
|
|
627
|
-
viewAtoms,
|
|
628
|
-
resourceAtoms,
|
|
629
|
-
userView
|
|
630
|
-
});
|
|
631
|
-
for (const visibleToken of userView) {
|
|
632
|
-
const resourceToken = visibleToken.type === `mutable_atom` ? internal.getJsonToken(visibleToken, store) : visibleToken;
|
|
633
|
-
const resource = internal.getFromStore(resourceToken, store);
|
|
634
|
-
initialPayload.push(resourceToken, resource);
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
const epoch = internal.isRootStore(store) ? (_a = store.transactionMeta.epoch.get(continuityKey)) != null ? _a : null : null;
|
|
638
|
-
socket == null ? void 0 : socket.emit(`continuity-init:${continuityKey}`, epoch, initialPayload);
|
|
639
|
-
for (const transaction2 of continuity.actions) {
|
|
640
|
-
const unsubscribeFromTransaction = internal.subscribeToTransaction(
|
|
641
|
-
transaction2,
|
|
642
|
-
(update) => {
|
|
643
|
-
try {
|
|
644
|
-
const visibleKeys = continuity.globals.map((atom2) => atom2.key).concat(
|
|
645
|
-
continuity.perspectives.flatMap((perspective) => {
|
|
646
|
-
const { viewAtoms } = perspective;
|
|
647
|
-
const userPerspectiveTokenState = internal.findInStore(
|
|
648
|
-
viewAtoms,
|
|
649
|
-
userKey,
|
|
650
|
-
store
|
|
651
|
-
);
|
|
652
|
-
const visibleTokens = internal.getFromStore(
|
|
653
|
-
userPerspectiveTokenState,
|
|
654
|
-
store
|
|
655
|
-
);
|
|
656
|
-
return visibleTokens.map((token) => {
|
|
657
|
-
const key = token.type === `mutable_atom` ? `*` + token.key : token.key;
|
|
658
|
-
return key;
|
|
659
|
-
});
|
|
660
|
-
})
|
|
661
|
-
);
|
|
662
|
-
const redactedUpdates = redactTransactionUpdateContent(
|
|
663
|
-
visibleKeys,
|
|
664
|
-
update.updates
|
|
665
|
-
);
|
|
666
|
-
const redactedUpdate = __spreadProps(__spreadValues({}, update), {
|
|
667
|
-
updates: redactedUpdates
|
|
668
|
-
});
|
|
669
|
-
socket == null ? void 0 : socket.emit(
|
|
670
|
-
`tx-new:${continuityKey}`,
|
|
671
|
-
redactedUpdate
|
|
672
|
-
);
|
|
673
|
-
} catch (thrown) {
|
|
674
|
-
if (thrown instanceof Error) {
|
|
675
|
-
store.logger.error(
|
|
676
|
-
`\u274C`,
|
|
677
|
-
`continuity`,
|
|
678
|
-
continuityKey,
|
|
679
|
-
`failed to send update from transaction ${transaction2.key} to ${userKey}`,
|
|
680
|
-
thrown.message
|
|
681
|
-
);
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
|
-
},
|
|
685
|
-
`sync-continuity:${continuityKey}:${userKey}`,
|
|
686
|
-
store
|
|
687
|
-
);
|
|
688
|
-
unsubscribeFunctions.push(unsubscribeFromTransaction);
|
|
689
|
-
}
|
|
690
|
-
};
|
|
691
|
-
socket.off(`get:${continuityKey}`, sendInitialPayload);
|
|
692
|
-
socket.on(`get:${continuityKey}`, sendInitialPayload);
|
|
693
|
-
const fillTransactionRequest = (update) => {
|
|
694
|
-
store.logger.info(`\u{1F6CE}\uFE0F`, `continuity`, continuityKey, `received`, update);
|
|
695
|
-
const transactionKey = update.key;
|
|
696
|
-
const updateId = update.id;
|
|
697
|
-
const performanceKey = `tx-run:${transactionKey}:${updateId}`;
|
|
698
|
-
const performanceKeyStart = `${performanceKey}:start`;
|
|
699
|
-
const performanceKeyEnd = `${performanceKey}:end`;
|
|
700
|
-
performance.mark(performanceKeyStart);
|
|
701
|
-
try {
|
|
702
|
-
internal.actUponStore(
|
|
703
|
-
{ type: `transaction`, key: transactionKey },
|
|
704
|
-
updateId,
|
|
705
|
-
store
|
|
706
|
-
)(...update.params);
|
|
707
|
-
} catch (thrown) {
|
|
708
|
-
if (thrown instanceof Error) {
|
|
709
|
-
store.logger.error(
|
|
710
|
-
`\u274C`,
|
|
711
|
-
`continuity`,
|
|
712
|
-
continuityKey,
|
|
713
|
-
`failed to run transaction ${transactionKey} with update ${updateId}`,
|
|
714
|
-
thrown.message
|
|
715
|
-
);
|
|
716
|
-
}
|
|
717
|
-
}
|
|
718
|
-
performance.mark(performanceKeyEnd);
|
|
719
|
-
const metric = performance.measure(
|
|
720
|
-
performanceKey,
|
|
721
|
-
performanceKeyStart,
|
|
722
|
-
performanceKeyEnd
|
|
723
|
-
);
|
|
724
|
-
store == null ? void 0 : store.logger.info(
|
|
725
|
-
`\u{1F680}`,
|
|
726
|
-
`transaction`,
|
|
727
|
-
transactionKey,
|
|
728
|
-
updateId,
|
|
729
|
-
metric.duration
|
|
730
|
-
);
|
|
731
|
-
const valuesOfCardsViewKey = `valuesOfCardsView("${userKey}")`;
|
|
732
|
-
const rootsOfCardValueView = store.selectorAtoms.getRelatedKeys(valuesOfCardsViewKey);
|
|
733
|
-
const myCardValueView = store.valueMap.get(valuesOfCardsViewKey);
|
|
734
|
-
store.logger.info(
|
|
735
|
-
`\u{1F441}`,
|
|
736
|
-
`continuity`,
|
|
737
|
-
continuityKey,
|
|
738
|
-
`seeing ${userKey} card values`,
|
|
739
|
-
{
|
|
740
|
-
valuesOfCardsViewKey,
|
|
741
|
-
rootsOfCardValueView,
|
|
742
|
-
myCardValueView
|
|
743
|
-
}
|
|
744
|
-
);
|
|
745
|
-
};
|
|
746
|
-
socket.off(`tx-run:${continuityKey}`, fillTransactionRequest);
|
|
747
|
-
socket.on(`tx-run:${continuityKey}`, fillTransactionRequest);
|
|
748
|
-
return () => {
|
|
749
|
-
for (const unsubscribe of unsubscribeFunctions) unsubscribe();
|
|
750
|
-
unsubscribeFromPerspectives();
|
|
751
|
-
socket == null ? void 0 : socket.off(`get:${continuityKey}`, sendInitialPayload);
|
|
752
|
-
socket == null ? void 0 : socket.off(`tx-run:${continuityKey}`, fillTransactionRequest);
|
|
753
|
-
};
|
|
754
|
-
};
|
|
755
|
-
}
|
|
756
|
-
function realtimeAtomFamilyProvider({
|
|
757
|
-
socket,
|
|
758
|
-
store = internal.IMPLICIT.STORE
|
|
759
|
-
}) {
|
|
760
|
-
return function familyProvider(family, index) {
|
|
761
|
-
const unsubCallbacksByKey = /* @__PURE__ */ new Map();
|
|
762
|
-
const fillUnsubRequest = (key) => {
|
|
763
|
-
socket.off(`unsub:${key}`, fillUnsubRequest);
|
|
764
|
-
const unsub = unsubCallbacksByKey.get(key);
|
|
765
|
-
if (unsub) {
|
|
766
|
-
unsub();
|
|
767
|
-
unsubCallbacksByKey.delete(key);
|
|
768
|
-
}
|
|
769
|
-
};
|
|
770
|
-
const fillSubRequest = (subKey) => {
|
|
771
|
-
const exposedSubKeys = internal.getFromStore(index, store);
|
|
772
|
-
for (const exposedSubKey of exposedSubKeys) {
|
|
773
|
-
if (json.stringifyJson(exposedSubKey) === json.stringifyJson(subKey)) {
|
|
774
|
-
const token = internal.findInStore(family, subKey, store);
|
|
775
|
-
socket.emit(`serve:${token.key}`, internal.getFromStore(token, store));
|
|
776
|
-
const unsubscribe = internal.subscribeToState(
|
|
777
|
-
token,
|
|
778
|
-
({ newValue }) => {
|
|
779
|
-
socket.emit(`serve:${token.key}`, newValue);
|
|
780
|
-
},
|
|
781
|
-
`expose-family:${family.key}:${socket.id}`,
|
|
782
|
-
store
|
|
783
|
-
);
|
|
784
|
-
unsubCallbacksByKey.set(token.key, unsubscribe);
|
|
785
|
-
socket.on(`unsub:${token.key}`, () => {
|
|
786
|
-
fillUnsubRequest(token.key);
|
|
787
|
-
});
|
|
788
|
-
break;
|
|
789
|
-
}
|
|
790
|
-
}
|
|
791
|
-
};
|
|
792
|
-
socket.on(`sub:${family.key}`, fillSubRequest);
|
|
793
|
-
return () => {
|
|
794
|
-
socket.off(`sub:${family.key}`, fillSubRequest);
|
|
795
|
-
for (const [, unsub] of unsubCallbacksByKey) {
|
|
796
|
-
unsub();
|
|
797
|
-
}
|
|
798
|
-
unsubCallbacksByKey.clear();
|
|
799
|
-
};
|
|
800
|
-
};
|
|
801
|
-
}
|
|
802
|
-
function realtimeMutableFamilyProvider({
|
|
803
|
-
socket,
|
|
804
|
-
store = internal.IMPLICIT.STORE
|
|
805
|
-
}) {
|
|
806
|
-
return function mutableFamilyProvider(family, index) {
|
|
807
|
-
const unsubCallbacksByKey = /* @__PURE__ */ new Map();
|
|
808
|
-
const fillUnsubRequest = (key) => {
|
|
809
|
-
socket.off(`unsub:${key}`, fillUnsubRequest);
|
|
810
|
-
const unsub = unsubCallbacksByKey.get(key);
|
|
811
|
-
if (unsub) {
|
|
812
|
-
unsub();
|
|
813
|
-
unsubCallbacksByKey.delete(key);
|
|
814
|
-
}
|
|
815
|
-
};
|
|
816
|
-
const fillSubRequest = (subKey) => {
|
|
817
|
-
const exposedSubKeys = internal.getFromStore(index, store);
|
|
818
|
-
for (const exposedSubKey of exposedSubKeys) {
|
|
819
|
-
if (json.stringifyJson(exposedSubKey) === json.stringifyJson(subKey)) {
|
|
820
|
-
const token = internal.findInStore(family, subKey, store);
|
|
821
|
-
internal.getFromStore(token, store);
|
|
822
|
-
const jsonToken = internal.getJsonToken(token, store);
|
|
823
|
-
const updateToken = internal.getUpdateToken(token);
|
|
824
|
-
socket.emit(`init:${token.key}`, internal.getFromStore(jsonToken, store));
|
|
825
|
-
const unsubscribe = internal.subscribeToState(
|
|
826
|
-
updateToken,
|
|
827
|
-
({ newValue }) => {
|
|
828
|
-
socket.emit(`next:${token.key}`, newValue);
|
|
829
|
-
},
|
|
830
|
-
`expose-family:${family.key}:${socket.id}`,
|
|
831
|
-
store
|
|
832
|
-
);
|
|
833
|
-
unsubCallbacksByKey.set(token.key, unsubscribe);
|
|
834
|
-
socket.on(`unsub:${token.key}`, () => {
|
|
835
|
-
fillUnsubRequest(token.key);
|
|
836
|
-
});
|
|
837
|
-
break;
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
};
|
|
841
|
-
socket.on(`sub:${family.key}`, fillSubRequest);
|
|
842
|
-
return () => {
|
|
843
|
-
socket.off(`sub:${family.key}`, fillSubRequest);
|
|
844
|
-
for (const [, unsub] of unsubCallbacksByKey) {
|
|
845
|
-
unsub();
|
|
846
|
-
}
|
|
847
|
-
unsubCallbacksByKey.clear();
|
|
848
|
-
};
|
|
849
|
-
};
|
|
850
|
-
}
|
|
851
|
-
function realtimeMutableProvider({
|
|
852
|
-
socket,
|
|
853
|
-
store = internal.IMPLICIT.STORE
|
|
854
|
-
}) {
|
|
855
|
-
return function mutableProvider(token) {
|
|
856
|
-
let unsubscribeFromStateUpdates = null;
|
|
857
|
-
const jsonToken = internal.getJsonToken(token, store);
|
|
858
|
-
const trackerToken = internal.getUpdateToken(token);
|
|
859
|
-
const fillUnsubRequest = () => {
|
|
860
|
-
socket.off(`unsub:${token.key}`, fillUnsubRequest);
|
|
861
|
-
unsubscribeFromStateUpdates == null ? void 0 : unsubscribeFromStateUpdates();
|
|
862
|
-
unsubscribeFromStateUpdates = null;
|
|
863
|
-
};
|
|
864
|
-
const fillSubRequest = () => {
|
|
865
|
-
socket.emit(`init:${token.key}`, internal.getFromStore(jsonToken, store));
|
|
866
|
-
unsubscribeFromStateUpdates = internal.subscribeToState(
|
|
867
|
-
trackerToken,
|
|
868
|
-
({ newValue }) => {
|
|
869
|
-
socket.emit(`next:${token.key}`, newValue);
|
|
870
|
-
},
|
|
871
|
-
`expose-single:${socket.id}`,
|
|
872
|
-
store
|
|
873
|
-
);
|
|
874
|
-
socket.on(`unsub:${token.key}`, fillUnsubRequest);
|
|
875
|
-
};
|
|
876
|
-
socket.on(`sub:${token.key}`, fillSubRequest);
|
|
877
|
-
return () => {
|
|
878
|
-
socket.off(`sub:${token.key}`, fillSubRequest);
|
|
879
|
-
unsubscribeFromStateUpdates == null ? void 0 : unsubscribeFromStateUpdates();
|
|
880
|
-
};
|
|
881
|
-
};
|
|
882
|
-
}
|
|
883
|
-
function realtimeStateProvider({
|
|
884
|
-
socket,
|
|
885
|
-
store = internal.IMPLICIT.STORE
|
|
886
|
-
}) {
|
|
887
|
-
return function stateProvider(token) {
|
|
888
|
-
let unsubscribeFromStateUpdates;
|
|
889
|
-
const fillSubRequest = () => {
|
|
890
|
-
socket.emit(`serve:${token.key}`, internal.getFromStore(token, store));
|
|
891
|
-
unsubscribeFromStateUpdates = internal.subscribeToState(
|
|
892
|
-
token,
|
|
893
|
-
({ newValue }) => {
|
|
894
|
-
socket.emit(`serve:${token.key}`, newValue);
|
|
895
|
-
},
|
|
896
|
-
`expose-single:${socket.id}`,
|
|
897
|
-
store
|
|
898
|
-
);
|
|
899
|
-
const fillUnsubRequest = () => {
|
|
900
|
-
socket.off(`unsub:${token.key}`, fillUnsubRequest);
|
|
901
|
-
if (unsubscribeFromStateUpdates) {
|
|
902
|
-
unsubscribeFromStateUpdates();
|
|
903
|
-
unsubscribeFromStateUpdates = void 0;
|
|
904
|
-
}
|
|
905
|
-
};
|
|
906
|
-
socket.on(`unsub:${token.key}`, fillUnsubRequest);
|
|
907
|
-
};
|
|
908
|
-
socket.on(`sub:${token.key}`, fillSubRequest);
|
|
909
|
-
return () => {
|
|
910
|
-
socket.off(`sub:${token.key}`, fillSubRequest);
|
|
911
|
-
if (unsubscribeFromStateUpdates) {
|
|
912
|
-
unsubscribeFromStateUpdates();
|
|
913
|
-
unsubscribeFromStateUpdates = void 0;
|
|
914
|
-
}
|
|
915
|
-
};
|
|
916
|
-
};
|
|
917
|
-
}
|
|
918
|
-
function realtimeStateReceiver({
|
|
919
|
-
socket,
|
|
920
|
-
store = internal.IMPLICIT.STORE
|
|
921
|
-
}) {
|
|
922
|
-
return function stateReceiver(token) {
|
|
923
|
-
const publish = (newValue) => {
|
|
924
|
-
internal.setIntoStore(token, newValue, store);
|
|
925
|
-
};
|
|
926
|
-
const fillPubUnclaim = () => {
|
|
927
|
-
socket.off(`pub:${token.key}`, publish);
|
|
928
|
-
socket.off(`unclaim:${token.key}`, fillPubUnclaim);
|
|
929
|
-
};
|
|
930
|
-
const fillPubClaim = () => {
|
|
931
|
-
socket.on(`pub:${token.key}`, publish);
|
|
932
|
-
socket.on(`unclaim:${token.key}`, fillPubUnclaim);
|
|
933
|
-
};
|
|
934
|
-
socket.on(`claim:${token.key}`, fillPubClaim);
|
|
935
|
-
return () => {
|
|
936
|
-
socket.off(`claim:${token.key}`, fillPubClaim);
|
|
937
|
-
socket.off(`pub:${token.key}`, publish);
|
|
938
|
-
};
|
|
939
|
-
};
|
|
940
|
-
}
|
|
941
|
-
|
|
942
|
-
exports.ChildSocket = ChildSocket;
|
|
943
|
-
exports.CustomSocket = CustomSocket;
|
|
944
|
-
exports.ParentSocket = ParentSocket;
|
|
945
|
-
exports.SubjectSocket = SubjectSocket;
|
|
946
|
-
exports.actionOcclusionAtoms = actionOcclusionAtoms;
|
|
947
|
-
exports.createRoomTX = createRoomTX;
|
|
948
|
-
exports.destroyRoomTX = destroyRoomTX;
|
|
949
|
-
exports.joinRoomTX = joinRoomTX;
|
|
950
|
-
exports.leaveRoomTX = leaveRoomTX;
|
|
951
|
-
exports.realtimeActionReceiver = realtimeActionReceiver;
|
|
952
|
-
exports.realtimeAtomFamilyProvider = realtimeAtomFamilyProvider;
|
|
953
|
-
exports.realtimeContinuitySynchronizer = realtimeContinuitySynchronizer;
|
|
954
|
-
exports.realtimeMutableFamilyProvider = realtimeMutableFamilyProvider;
|
|
955
|
-
exports.realtimeMutableProvider = realtimeMutableProvider;
|
|
956
|
-
exports.realtimeStateProvider = realtimeStateProvider;
|
|
957
|
-
exports.realtimeStateReceiver = realtimeStateReceiver;
|
|
958
|
-
exports.redactTransactionUpdateContent = redactTransactionUpdateContent;
|
|
959
|
-
exports.roomArgumentsAtoms = roomArgumentsAtoms;
|
|
960
|
-
exports.roomSelectors = roomSelectors;
|
|
961
|
-
exports.socketAtoms = socketAtoms;
|
|
962
|
-
exports.socketIndex = socketIndex;
|
|
963
|
-
exports.userIndex = userIndex;
|
|
964
|
-
exports.userUnacknowledgedQueues = userUnacknowledgedQueues;
|
|
965
|
-
exports.usersOfSockets = usersOfSockets;
|