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