atom.io 0.40.6 → 0.40.8

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 (186) hide show
  1. package/README.md +1 -1
  2. package/dist/data/index.d.ts +1 -1
  3. package/dist/data/index.js +1 -2
  4. package/dist/data/index.js.map +1 -1
  5. package/dist/employ-socket-D6wgByWh.js +12 -0
  6. package/dist/employ-socket-D6wgByWh.js.map +1 -0
  7. package/dist/eslint-plugin/index.js.map +1 -1
  8. package/dist/has-role-CMlaUlaf.js +1133 -0
  9. package/dist/has-role-CMlaUlaf.js.map +1 -0
  10. package/dist/internal/index.d.ts +248 -248
  11. package/dist/internal/index.d.ts.map +1 -1
  12. package/dist/internal/index.js +590 -1803
  13. package/dist/internal/index.js.map +1 -1
  14. package/dist/introspection/index.d.ts +1 -1
  15. package/dist/introspection/index.d.ts.map +1 -1
  16. package/dist/introspection/index.js +13 -32
  17. package/dist/introspection/index.js.map +1 -1
  18. package/dist/is-fn-DY1wZ-md.js +10 -0
  19. package/dist/is-fn-DY1wZ-md.js.map +1 -0
  20. package/dist/json/index.d.ts.map +1 -1
  21. package/dist/json/index.js.map +1 -1
  22. package/dist/main/index.d.ts +33 -33
  23. package/dist/main/index.d.ts.map +1 -1
  24. package/dist/main/index.js +3 -4
  25. package/dist/main/index.js.map +1 -1
  26. package/dist/mutex-store-CSvxY9i3.js +11 -0
  27. package/dist/mutex-store-CSvxY9i3.js.map +1 -0
  28. package/dist/react/index.d.ts +5 -5
  29. package/dist/react/index.d.ts.map +1 -1
  30. package/dist/react/index.js.map +1 -1
  31. package/dist/react-devtools/index.d.ts.map +1 -1
  32. package/dist/react-devtools/index.js +9 -11
  33. package/dist/react-devtools/index.js.map +1 -1
  34. package/dist/realtime/index.d.ts +7 -15
  35. package/dist/realtime/index.d.ts.map +1 -1
  36. package/dist/realtime/index.js +4 -35
  37. package/dist/realtime/index.js.map +1 -1
  38. package/dist/realtime-client/index.d.ts +6 -9
  39. package/dist/realtime-client/index.d.ts.map +1 -1
  40. package/dist/realtime-client/index.js +96 -88
  41. package/dist/realtime-client/index.js.map +1 -1
  42. package/dist/realtime-react/index.d.ts +17 -13
  43. package/dist/realtime-react/index.d.ts.map +1 -1
  44. package/dist/realtime-react/index.js +39 -50
  45. package/dist/realtime-react/index.js.map +1 -1
  46. package/dist/realtime-server/index.d.ts +83 -84
  47. package/dist/realtime-server/index.d.ts.map +1 -1
  48. package/dist/realtime-server/index.js +604 -543
  49. package/dist/realtime-server/index.js.map +1 -1
  50. package/dist/realtime-testing/index.d.ts +5 -4
  51. package/dist/realtime-testing/index.d.ts.map +1 -1
  52. package/dist/realtime-testing/index.js +35 -22
  53. package/dist/realtime-testing/index.js.map +1 -1
  54. package/dist/shared-room-store-BfW3nWif.js +31 -0
  55. package/dist/shared-room-store-BfW3nWif.js.map +1 -0
  56. package/dist/shared-room-store-D2o4ZLjC.d.ts +15 -0
  57. package/dist/shared-room-store-D2o4ZLjC.d.ts.map +1 -0
  58. package/dist/transceivers/set-rtx/index.d.ts.map +1 -1
  59. package/dist/transceivers/set-rtx/index.js +4 -8
  60. package/dist/transceivers/set-rtx/index.js.map +1 -1
  61. package/dist/web/index.d.ts +3 -3
  62. package/dist/web/index.d.ts.map +1 -1
  63. package/dist/web/index.js +4 -3
  64. package/dist/web/index.js.map +1 -1
  65. package/package.json +13 -13
  66. package/src/internal/atom/create-regular-atom.ts +5 -4
  67. package/src/internal/atom/dispose-atom.ts +7 -2
  68. package/src/internal/atom/has-role.ts +3 -3
  69. package/src/internal/caching.ts +4 -2
  70. package/src/internal/families/create-readonly-held-selector-family.ts +2 -1
  71. package/src/internal/families/create-readonly-pure-selector-family.ts +5 -2
  72. package/src/internal/families/create-regular-atom-family.ts +2 -1
  73. package/src/internal/families/create-writable-held-selector-family.ts +2 -1
  74. package/src/internal/families/create-writable-pure-selector-family.ts +5 -2
  75. package/src/internal/families/dispose-from-store.ts +4 -4
  76. package/src/internal/families/find-in-store.ts +10 -10
  77. package/src/internal/families/get-family-of-token.ts +2 -2
  78. package/src/internal/families/index.ts +1 -0
  79. package/src/internal/families/mint-in-store.ts +54 -19
  80. package/src/internal/families/seek-in-store.ts +1 -1
  81. package/src/internal/get-state/get-fallback.ts +2 -2
  82. package/src/internal/get-state/get-from-store.ts +5 -5
  83. package/src/internal/get-state/read-or-compute-value.ts +1 -1
  84. package/src/internal/get-state/reduce-reference.ts +8 -6
  85. package/src/internal/index.ts +2 -220
  86. package/src/internal/molecule.ts +1 -2
  87. package/src/internal/mutable/create-mutable-atom-family.ts +3 -2
  88. package/src/internal/mutable/create-mutable-atom.ts +4 -2
  89. package/src/internal/mutable/get-json-family.ts +1 -1
  90. package/src/internal/mutable/get-update-family.ts +1 -1
  91. package/src/internal/mutable/tracker-family.ts +2 -1
  92. package/src/internal/mutable/tracker.ts +71 -59
  93. package/src/internal/safe-compute.ts +1 -1
  94. package/src/internal/selector/create-readonly-held-selector.ts +2 -1
  95. package/src/internal/selector/create-readonly-pure-selector.ts +2 -1
  96. package/src/internal/selector/create-writable-held-selector.ts +2 -1
  97. package/src/internal/selector/create-writable-pure-selector.ts +2 -1
  98. package/src/internal/selector/dispose-selector.ts +3 -2
  99. package/src/internal/selector/register-selector.ts +8 -5
  100. package/src/internal/selector/trace-selector-atoms.ts +2 -1
  101. package/src/internal/set-state/dispatch-state-update.ts +3 -2
  102. package/src/internal/set-state/evict-downstream.ts +1 -1
  103. package/src/internal/set-state/operate-on-store.ts +16 -22
  104. package/src/internal/set-state/reset-atom-or-selector.ts +5 -3
  105. package/src/internal/set-state/reset-in-store.ts +5 -5
  106. package/src/internal/set-state/set-atom-or-selector.ts +2 -2
  107. package/src/internal/set-state/set-atom.ts +4 -2
  108. package/src/internal/set-state/set-into-store.ts +21 -39
  109. package/src/internal/set-state/set-selector.ts +3 -2
  110. package/src/internal/state-types.ts +228 -0
  111. package/src/internal/store/deposit.ts +4 -4
  112. package/src/internal/store/index.ts +0 -1
  113. package/src/internal/store/store.ts +9 -9
  114. package/src/internal/store/withdraw.ts +4 -4
  115. package/src/internal/subscribe/recall-state.ts +1 -1
  116. package/src/internal/subscribe/subscribe-to-root-atoms.ts +1 -12
  117. package/src/internal/subscribe/subscribe-to-state.ts +9 -0
  118. package/src/internal/subscribe/subscribe-to-transaction.ts +3 -2
  119. package/src/internal/transaction/build-transaction.ts +3 -2
  120. package/src/internal/transaction/index.ts +1 -23
  121. package/src/internal/transaction/is-root-store.ts +4 -1
  122. package/src/internal/transaction/transaction-meta-progress.ts +22 -0
  123. package/src/main/atom.ts +1 -2
  124. package/src/main/find-state.ts +5 -5
  125. package/src/main/get-state.ts +4 -4
  126. package/src/main/realm.ts +2 -2
  127. package/src/main/set-state.ts +10 -10
  128. package/src/react/parse-state-overloads.ts +3 -3
  129. package/src/react/use-i.ts +6 -4
  130. package/src/react/use-loadable.ts +4 -10
  131. package/src/react/use-o.ts +6 -4
  132. package/src/react-devtools/store.ts +6 -6
  133. package/src/realtime/index.ts +1 -0
  134. package/src/realtime/mutex-store.ts +11 -0
  135. package/src/realtime/realtime-continuity.ts +1 -5
  136. package/src/realtime-client/index.ts +0 -1
  137. package/src/realtime-client/pull-atom-family-member.ts +14 -17
  138. package/src/realtime-client/pull-atom.ts +1 -1
  139. package/src/realtime-client/pull-mutable-atom-family-member.ts +16 -12
  140. package/src/realtime-client/pull-selector-family-member.ts +8 -35
  141. package/src/realtime-client/pull-selector-roots.ts +90 -0
  142. package/src/realtime-client/pull-selector.ts +2 -27
  143. package/src/realtime-client/push-state.ts +33 -5
  144. package/src/realtime-client/realtime-client-stores/client-main-store.ts +2 -5
  145. package/src/realtime-react/index.ts +2 -2
  146. package/src/realtime-react/realtime-context.tsx +9 -5
  147. package/src/realtime-react/use-pull-atom-family-member.ts +2 -3
  148. package/src/realtime-react/use-pull-mutable-family-member.ts +2 -3
  149. package/src/realtime-react/use-pull-selector-family-member.ts +5 -6
  150. package/src/realtime-react/use-push.ts +7 -3
  151. package/src/realtime-react/use-realtime-service.ts +11 -11
  152. package/src/realtime-react/use-single-effect.ts +11 -14
  153. package/src/realtime-server/{realtime-server-stores/server-sync-store.ts → continuity/continuity-store.ts} +2 -27
  154. package/src/realtime-server/continuity/provide-continuity.ts +50 -0
  155. package/src/realtime-server/continuity/{subscribe-to-continuity-actions.ts → provide-outcomes.ts} +15 -13
  156. package/src/realtime-server/continuity/{subscribe-to-continuity-perpectives.ts → provide-perspectives.ts} +10 -8
  157. package/src/realtime-server/continuity/{prepare-to-send-initial-payload.ts → provide-startup-payloads.ts} +6 -4
  158. package/src/realtime-server/continuity/receive-action-requests.ts +68 -0
  159. package/src/realtime-server/continuity/track-acknowledgements.ts +46 -0
  160. package/src/realtime-server/employ-socket.ts +14 -0
  161. package/src/realtime-server/index.ts +3 -22
  162. package/src/realtime-server/ipc-sockets/child-socket.ts +125 -66
  163. package/src/realtime-server/ipc-sockets/custom-socket.ts +16 -14
  164. package/src/realtime-server/ipc-sockets/parent-socket.ts +98 -69
  165. package/src/realtime-server/realtime-family-provider.ts +78 -29
  166. package/src/realtime-server/realtime-mutable-family-provider.ts +80 -31
  167. package/src/realtime-server/realtime-mutable-provider.ts +30 -22
  168. package/src/realtime-server/realtime-server-stores/index.ts +0 -2
  169. package/src/realtime-server/realtime-server-stores/server-room-external-store.ts +77 -36
  170. package/src/realtime-server/realtime-server-stores/server-user-store.ts +12 -1
  171. package/src/realtime-server/realtime-state-provider.ts +30 -29
  172. package/src/realtime-server/realtime-state-receiver.ts +62 -16
  173. package/src/realtime-server/server-config.ts +8 -0
  174. package/src/realtime-server/socket-interface.ts +14 -0
  175. package/src/realtime-testing/setup-realtime-test.tsx +70 -31
  176. package/src/web/index.ts +1 -1
  177. package/src/web/{persist-sync.ts → storage-sync.ts} +5 -2
  178. package/src/internal/store/mint-or-counterfeit.ts +0 -108
  179. package/src/realtime-client/server-action.ts +0 -23
  180. package/src/realtime-react/on-mount.ts +0 -5
  181. package/src/realtime-react/use-server-action.ts +0 -19
  182. package/src/realtime-server/continuity/prepare-to-serve-transaction-request.ts +0 -59
  183. package/src/realtime-server/continuity/prepare-to-sync-realtime-continuity.ts +0 -145
  184. package/src/realtime-server/continuity/prepare-to-track-client-acknowledgement.ts +0 -41
  185. package/src/realtime-server/realtime-action-receiver.ts +0 -40
  186. package/src/realtime-server/realtime-server-stores/server-room-external-actions.ts +0 -79
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["process","roomArgumentsAtoms: RegularAtomFamilyToken<RoomArguments, string>","roomSelectors: ReadonlyPureSelectorFamilyToken<\n\tLoadable<ChildSocket<any, any>>,\n\tstring\n>","createRoomTX: AtomIO.TransactionToken<\n\t(\n\t\troomKey: RoomKey,\n\t\tscript: string,\n\t\toptions?: string[],\n\t) => Loadable<ChildSocket<any, any>>\n>","args: RoomArguments","joinRoomTX: AtomIO.TransactionToken<\n\t(roomId: string, userId: string, enteredAtEpoch: number) => UserInRoomMeta\n>","leaveRoomTX: AtomIO.TransactionToken<\n\t(roomId: string, userId: string) => void\n>","destroyRoomTX: AtomIO.TransactionToken<(roomKey: RoomKey) => void>","redactorAtoms: RegularAtomFamilyToken<\n\t{\n\t\tocclude: (updates: TransactionSubEvent[]) => TransactionSubEvent[]\n\t},\n\tUserKey\n>","userUnacknowledgedQueues: RegularAtomFamilyToken<\n\tContinuitySyncTransactionUpdate[],\n\tUserKey\n>","socketAtoms: RegularAtomFamilyToken<Socket | null, SocketKey>","socketIndex: MutableAtomToken<SetRTX<SocketKey>>","userIndex: MutableAtomToken<SetRTX<UserKey>>","usersOfSockets: JoinToken<\n\t`user`,\n\tUserKey,\n\t`socket`,\n\tSocketKey,\n\t`1:1`\n>","initialPayload: Json.Serializable[]","unsubscribeFunctions: (() => void)[]","unsubFns: (() => void)[]","socket: Socket | null","unsubscribeFunctions: (() => void)[]","unsubscribeFromStateUpdates: (() => void) | null","unsubscribeFromStateUpdates: (() => void) | undefined"],"sources":["../../src/realtime-server/ipc-sockets/custom-socket.ts","../../src/realtime-server/ipc-sockets/child-socket.ts","../../src/realtime-server/ipc-sockets/parent-socket.ts","../../src/realtime-server/realtime-server-stores/server-room-external-store.ts","../../src/realtime-server/realtime-server-stores/server-room-external-actions.ts","../../src/realtime-server/realtime-server-stores/server-sync-store.ts","../../src/realtime-server/realtime-server-stores/server-user-store.ts","../../src/realtime-server/continuity/prepare-to-send-initial-payload.ts","../../src/realtime-server/continuity/prepare-to-serve-transaction-request.ts","../../src/realtime-server/continuity/prepare-to-track-client-acknowledgement.ts","../../src/realtime-server/continuity/subscribe-to-continuity-actions.ts","../../src/realtime-server/continuity/subscribe-to-continuity-perpectives.ts","../../src/realtime-server/continuity/prepare-to-sync-realtime-continuity.ts","../../src/realtime-server/realtime-action-receiver.ts","../../src/realtime-server/realtime-family-provider.ts","../../src/realtime-server/realtime-mutable-family-provider.ts","../../src/realtime-server/realtime-mutable-provider.ts","../../src/realtime-server/realtime-state-provider.ts","../../src/realtime-server/realtime-state-receiver.ts"],"sourcesContent":["import type { Json, stringified } from \"atom.io/json\"\n\nimport type { Socket } from \"..\"\n\nexport type Events = Json.Object<string, Json.Serializable[]>\n\nexport type StringifiedEvent<\n\tKey extends string,\n\tParams extends Json.Serializable[],\n> = stringified<[Key, ...Params]>\n\nexport interface EventBuffer<\n\tKey extends string,\n\tParams extends Json.Serializable[],\n> extends Buffer {\n\ttoString(): StringifiedEvent<Key, Params>\n}\n\nexport class CustomSocket<I extends Events, O extends Events> implements Socket {\n\tprotected listeners: Map<keyof O, Set<(...args: Json.Array) => void>>\n\tprotected globalListeners: Set<(event: string, ...args: Json.Array) => void>\n\tprotected handleEvent<Event extends keyof I>(\n\t\tevent: string,\n\t\t...args: I[Event]\n\t): void {\n\t\tfor (const listener of this.globalListeners) {\n\t\t\tlistener(event, ...args)\n\t\t}\n\t\tconst listeners = this.listeners.get(event)\n\t\tif (listeners) {\n\t\t\tfor (const listener of listeners) {\n\t\t\t\tlistener(...args)\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic id = `no_id_retrieved`\n\tpublic emit: <Event extends keyof I>(\n\t\tevent: Event,\n\t\t...args: I[Event]\n\t) => CustomSocket<I, O>\n\n\tpublic constructor(\n\t\temit: <Event extends keyof I>(\n\t\t\tevent: Event,\n\t\t\t...args: I[Event]\n\t\t) => CustomSocket<I, O>,\n\t) {\n\t\tthis.emit = emit\n\t\tthis.listeners = new Map()\n\t\tthis.globalListeners = new Set()\n\t}\n\n\tpublic on<Event extends keyof O>(\n\t\tevent: Event,\n\t\tlistener: (...args: O[Event]) => void,\n\t): this {\n\t\tconst listeners = this.listeners.get(event)\n\t\tif (listeners) {\n\t\t\tlisteners.add(listener)\n\t\t} else {\n\t\t\tthis.listeners.set(event, new Set([listener]))\n\t\t}\n\t\treturn this\n\t}\n\n\tpublic onAny(listener: (event: string, ...args: Json.Array) => void): this {\n\t\tthis.globalListeners.add(listener)\n\t\treturn this\n\t}\n\n\tpublic off<Event extends keyof O>(\n\t\tevent: Event,\n\t\tlistener?: (...args: O[Event]) => void,\n\t): this {\n\t\tconst listeners = this.listeners.get(event)\n\t\tif (listeners) {\n\t\t\tif (listener) {\n\t\t\t\tlisteners.delete(listener)\n\t\t\t} else {\n\t\t\t\tthis.listeners.delete(event)\n\t\t\t}\n\t\t}\n\t\treturn this\n\t}\n\n\tpublic offAny(listener: (event: string, ...args: Json.Array) => void): this {\n\t\tthis.globalListeners.delete(listener)\n\t\treturn this\n\t}\n}\n","import type { ChildProcessWithoutNullStreams } from \"node:child_process\"\n\nimport type { Json } from \"atom.io/json\"\nimport { parseJson } from \"atom.io/json\"\n\nimport type { EventBuffer, Events } from \"./custom-socket\"\nimport { CustomSocket } from \"./custom-socket\"\n\n/* eslint-disable no-console */\n\nexport class ChildSocket<\n\tI extends Events,\n\tO extends Events,\n> extends CustomSocket<I, O> {\n\tprotected incompleteData = ``\n\tprotected unprocessedEvents: string[] = []\n\tprotected incompleteLog = ``\n\tprotected unprocessedLogs: string[] = []\n\n\tpublic id = `#####`\n\n\tpublic process: ChildProcessWithoutNullStreams\n\tpublic key: string\n\tpublic logger: Pick<Console, `error` | `info` | `warn`>\n\n\tprotected handleLog(arg: Json.Serializable): void {\n\t\tif (Array.isArray(arg)) {\n\t\t\tconst [level, ...rest] = arg\n\t\t\tswitch (level) {\n\t\t\t\tcase `i`:\n\t\t\t\t\tthis.logger.info(...rest)\n\t\t\t\t\tbreak\n\t\t\t\tcase `w`:\n\t\t\t\t\tthis.logger.warn(...rest)\n\t\t\t\t\tbreak\n\t\t\t\tcase `e`:\n\t\t\t\t\tthis.logger.error(...rest)\n\t\t\t\t\tbreak\n\t\t\t\tdefault:\n\t\t\t\t\treturn\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic constructor(\n\t\tprocess: ChildProcessWithoutNullStreams,\n\t\tkey: string,\n\t\tlogger?: Pick<Console, `error` | `info` | `warn`>,\n\t) {\n\t\tsuper((event, ...args) => {\n\t\t\tconst stringifiedEvent = JSON.stringify([event, ...args]) + `\\x03`\n\t\t\tconst errorHandler = (err: { code: string }) => {\n\t\t\t\tif (err.code === `EPIPE`) {\n\t\t\t\t\tconsole.error(`EPIPE error during write`, this.process.stdin)\n\t\t\t\t}\n\t\t\t\tthis.process.stdin.removeListener(`error`, errorHandler)\n\t\t\t}\n\n\t\t\tthis.process.stdin.once(`error`, errorHandler)\n\t\t\tthis.process.stdin.write(stringifiedEvent)\n\n\t\t\treturn this\n\t\t})\n\t\tthis.process = process\n\t\tthis.key = key\n\t\tthis.logger = logger ?? {\n\t\t\tinfo: (...args: unknown[]) => {\n\t\t\t\tconsole.info(this.id, this.key, ...args)\n\t\t\t},\n\t\t\twarn: (...args: unknown[]) => {\n\t\t\t\tconsole.warn(this.id, this.key, ...args)\n\t\t\t},\n\t\t\terror: (...args: unknown[]) => {\n\t\t\t\tconsole.error(this.id, this.key, ...args)\n\t\t\t},\n\t\t}\n\t\tthis.process.stdout.on(\n\t\t\t`data`,\n\t\t\t<Event extends keyof I>(buffer: EventBuffer<string, I[Event]>) => {\n\t\t\t\tconst chunk = buffer.toString()\n\n\t\t\t\tif (chunk === `ALIVE`) {\n\t\t\t\t\t// console.log(chunk)\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tthis.unprocessedEvents.push(...chunk.split(`\\x03`))\n\t\t\t\t// console.log(`🤓`, chunk.length)\n\t\t\t\t// console.log(`🤓`, this.unprocessedEvents.length)\n\t\t\t\t// console.log(`🤓`, ...this.unprocessedEvents.map((x) => x.length))\n\t\t\t\tconst newInput = this.unprocessedEvents.shift()\n\t\t\t\tthis.incompleteData += newInput ?? ``\n\t\t\t\ttry {\n\t\t\t\t\tif (this.incompleteData.startsWith(`error`)) {\n\t\t\t\t\t\tconsole.log(`❗`, this.incompleteData)\n\t\t\t\t\t}\n\t\t\t\t\tlet parsedEvent = parseJson(this.incompleteData)\n\t\t\t\t\tthis.handleEvent(...(parsedEvent as [string, ...I[keyof I]]))\n\t\t\t\t\twhile (this.unprocessedEvents.length > 0) {\n\t\t\t\t\t\tconst event = this.unprocessedEvents.shift()\n\t\t\t\t\t\tif (event) {\n\t\t\t\t\t\t\tif (this.unprocessedEvents.length === 0) {\n\t\t\t\t\t\t\t\tthis.incompleteData = event\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tparsedEvent = parseJson(event)\n\t\t\t\t\t\t\tthis.handleEvent(...(parsedEvent as [string, ...I[keyof I]]))\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tthis.incompleteData = ``\n\t\t\t\t} catch (error) {\n\t\t\t\t\tconsole.warn(`⚠️----------------⚠️`)\n\t\t\t\t\tconsole.warn(this.incompleteData)\n\t\t\t\t\tconsole.warn(`⚠️----------------⚠️`)\n\t\t\t\t\tconsole.error(error)\n\t\t\t\t}\n\t\t\t},\n\t\t)\n\t\tthis.process.stderr.on(`data`, (buf) => {\n\t\t\tconst chunk = buf.toString()\n\t\t\tthis.unprocessedLogs.push(...chunk.split(`\\x03`))\n\t\t\t// console.log(`🤫`, chunk.length)\n\t\t\t// console.log(`🤫`, this.unprocessedLogs.length)\n\t\t\t// console.log(`🤫`, ...this.unprocessedLogs.map((x) => x.length))\n\t\t\tconst newInput = this.unprocessedLogs.shift()\n\t\t\tthis.incompleteLog += newInput ?? ``\n\t\t\ttry {\n\t\t\t\tlet parsedLog = parseJson(this.incompleteLog)\n\t\t\t\t// console.log(`🤫`, parsedLog)\n\t\t\t\tthis.handleLog(parsedLog)\n\t\t\t\twhile (this.unprocessedLogs.length > 0) {\n\t\t\t\t\tthis.incompleteLog = this.unprocessedLogs.shift() ?? ``\n\t\t\t\t\tif (this.incompleteLog) {\n\t\t\t\t\t\tparsedLog = parseJson(this.incompleteLog)\n\t\t\t\t\t\tthis.handleLog(parsedLog)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tconsole.error(`❌❌❌`)\n\t\t\t\tconsole.error(this.incompleteLog)\n\t\t\t\tconsole.error(error)\n\t\t\t\tconsole.error(`❌❌❌️`)\n\t\t\t}\n\t\t})\n\t\tif (process.pid) {\n\t\t\tthis.id = process.pid.toString()\n\t\t}\n\t}\n}\n","import { Subject } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport { parseJson, stringifyJson } from \"atom.io/json\"\nimport { SetRTX } from \"atom.io/transceivers/set-rtx\"\n\nimport type { EventBuffer, Events } from \"./custom-socket\"\nimport { CustomSocket } from \"./custom-socket\"\n\nexport class SubjectSocket<\n\tI extends Events,\n\tO extends Events,\n> extends CustomSocket<I, O> {\n\tpublic in: Subject<[string, ...Json.Serializable[]]>\n\tpublic out: Subject<[string, ...Json.Serializable[]]>\n\tpublic id = `no_id_retrieved`\n\tpublic disposalFunctions: (() => void)[] = []\n\n\tpublic constructor(id: string) {\n\t\tsuper((...args) => {\n\t\t\tthis.out.next(args as any)\n\t\t\treturn this\n\t\t})\n\t\tthis.id = id\n\t\tthis.in = new Subject()\n\t\tthis.out = new Subject()\n\t\tthis.in.subscribe(`socket`, (event) => {\n\t\t\tthis.handleEvent(...(event as [string, ...I[keyof I]]))\n\t\t})\n\t}\n\n\tpublic dispose(): void {\n\t\tfor (const dispose of this.disposalFunctions) {\n\t\t\tdispose()\n\t\t}\n\t}\n}\n\nexport class ParentSocket<\n\tI extends Events & {\n\t\t[id in string as `relay:${id}`]: [string, ...Json.Serializable[]]\n\t},\n\tO extends Events & {\n\t\t[id in string as `user:${id}`]: [string, ...Json.Serializable[]]\n\t} & {\n\t\t/* eslint-disable quotes */\n\t\t\"user-joins\": [string]\n\t\t\"user-leaves\": [string]\n\t\t/* eslint-enable quotes */\n\t},\n> extends CustomSocket<I, O> {\n\tprotected incompleteData = ``\n\tprotected unprocessedEvents: string[] = []\n\tprotected relays: Map<string, SubjectSocket<any, any>>\n\tprotected relayServices: ((\n\t\tsocket: SubjectSocket<any, any>,\n\t) => (() => void) | void)[]\n\tprotected process: NodeJS.Process\n\n\tpublic id = `#####`\n\n\tprotected log(...args: any[]): void {\n\t\tthis.process.stderr.write(\n\t\t\tstringifyJson(\n\t\t\t\targs.map((arg) =>\n\t\t\t\t\targ instanceof SetRTX\n\t\t\t\t\t\t? `{ ${arg.toJSON().members.join(` | `)} }`\n\t\t\t\t\t\t: arg,\n\t\t\t\t),\n\t\t\t) + `\\x03`,\n\t\t)\n\t}\n\tpublic logger = {\n\t\tinfo: (...args: any[]): void => {\n\t\t\tthis.log(`i`, ...args)\n\t\t},\n\t\twarn: (...args: any[]): void => {\n\t\t\tthis.log(`w`, ...args)\n\t\t},\n\t\terror: (...args: any[]): void => {\n\t\t\tthis.log(`e`, ...args)\n\t\t},\n\t}\n\n\tpublic constructor() {\n\t\tsuper((event, ...args) => {\n\t\t\tconst stringifiedEvent = JSON.stringify([event, ...args])\n\t\t\tthis.process.stdout.write(stringifiedEvent + `\\x03`)\n\t\t\treturn this\n\t\t})\n\t\tthis.process = process\n\t\tthis.process.stdin.resume()\n\t\tthis.relays = new Map()\n\t\tthis.relayServices = []\n\t\t// this.logger.info(`🔗`, `uplink`, process.pid)\n\n\t\tthis.process.stdin.on(\n\t\t\t`data`,\n\t\t\t<Event extends keyof I>(buffer: EventBuffer<string, I[Event]>) => {\n\t\t\t\tconst chunk = buffer.toString()\n\t\t\t\tthis.unprocessedEvents.push(...chunk.split(`\\x03`))\n\t\t\t\tconst newInput = this.unprocessedEvents.shift()\n\t\t\t\tthis.incompleteData += newInput ?? ``\n\n\t\t\t\ttry {\n\t\t\t\t\tconst parsedData = parseJson(this.incompleteData)\n\t\t\t\t\tthis.logger.info(`🎰`, `received`, parsedData)\n\t\t\t\t\tthis.handleEvent(...(parsedData as [string, ...I[keyof I]]))\n\t\t\t\t\twhile (this.unprocessedEvents.length > 0) {\n\t\t\t\t\t\tconst event = this.unprocessedEvents.shift()\n\t\t\t\t\t\tif (event) {\n\t\t\t\t\t\t\tif (this.unprocessedEvents.length === 0) {\n\t\t\t\t\t\t\t\tthis.incompleteData = event\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tconst parsedEvent = parseJson(event)\n\t\t\t\t\t\t\tthis.handleEvent(...(parsedEvent as [string, ...I[keyof I]]))\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tthis.incompleteData = ``\n\t\t\t\t} catch (thrown) {\n\t\t\t\t\tif (thrown instanceof Error) {\n\t\t\t\t\t\tthis.logger.error(`❗`, thrown.message, thrown.cause, thrown.stack)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t)\n\n\t\tthis.on(`exit`, () => {\n\t\t\tthis.logger.info(`🔥`, this.id, `received \"exit\"`)\n\t\t\tprocess.exit(0)\n\t\t})\n\t\tprocess.on(`exit`, (code) => {\n\t\t\tthis.logger.info(`🔥`, this.id, `exited with code ${code}`)\n\t\t})\n\t\tprocess.on(`end`, () => {\n\t\t\tthis.logger.info(`🔥`, this.id, `ended`)\n\t\t\tprocess.exit(0)\n\t\t})\n\t\tprocess.on(`SIGTERM`, () => {\n\t\t\tthis.logger.error(`🔥`, this.id, `terminated`)\n\t\t\tprocess.exit(0)\n\t\t})\n\t\tprocess.on(`SIGINT`, () => {\n\t\t\tthis.logger.error(`🔥`, this.id, `interrupted`)\n\t\t\tprocess.exit(0)\n\t\t})\n\n\t\tif (process.pid) {\n\t\t\tthis.id = process.pid?.toString()\n\t\t}\n\n\t\tthis.on(`user-joins`, (username) => {\n\t\t\tthis.logger.info(`👤`, `user`, username, `joined`)\n\t\t\tconst relay = new SubjectSocket(`user:${username}`)\n\t\t\tthis.relays.set(username, relay)\n\t\t\tthis.logger.info(\n\t\t\t\t`🔗`,\n\t\t\t\t`attaching services:`,\n\t\t\t\t`[${[...this.relayServices.keys()].join(`, `)}]`,\n\t\t\t)\n\t\t\tfor (const attachServices of this.relayServices) {\n\t\t\t\tconst cleanup = attachServices(relay)\n\t\t\t\tif (cleanup) {\n\t\t\t\t\trelay.disposalFunctions.push(cleanup)\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.on(`user:${username}`, (...data) => {\n\t\t\t\trelay.in.next(data)\n\t\t\t})\n\t\t\trelay.out.subscribe(`socket`, (data) => {\n\t\t\t\tthis.emit(...(data as [string, ...I[keyof I]]))\n\t\t\t})\n\t\t})\n\n\t\tthis.on(`user-leaves`, (username) => {\n\t\t\tconst relay = this.relays.get(username)\n\t\t\tthis.off(`relay:${username}`)\n\t\t\tif (relay) {\n\t\t\t\trelay.dispose()\n\t\t\t\tthis.relays.delete(username)\n\t\t\t}\n\t\t})\n\n\t\tprocess.stdout.write(`ALIVE`)\n\t}\n\n\tpublic relay(\n\t\tattachServices: (socket: SubjectSocket<any, any>) => (() => void) | void,\n\t): void {\n\t\tthis.logger.info(`🔗`, `running relay method`)\n\t\tthis.relayServices.push(attachServices)\n\t}\n}\n","import type { ChildProcessWithoutNullStreams } from \"node:child_process\"\nimport { spawn } from \"node:child_process\"\n\nimport type {\n\tLoadable,\n\tReadonlyPureSelectorFamilyToken,\n\tRegularAtomFamilyToken,\n} from \"atom.io\"\nimport { atomFamily, selectorFamily } from \"atom.io\"\n\nimport { ChildSocket } from \"../ipc-sockets\"\n\nexport type RoomArguments =\n\t| [script: string, options: string[]]\n\t| [script: string]\n\nexport const roomArgumentsAtoms: RegularAtomFamilyToken<RoomArguments, string> =\n\tatomFamily<RoomArguments, string>({\n\t\tkey: `roomArguments`,\n\t\tdefault: [`echo`, [`Hello World!`]],\n\t})\n\nexport const roomSelectors: ReadonlyPureSelectorFamilyToken<\n\tLoadable<ChildSocket<any, any>>,\n\tstring\n> = selectorFamily<Loadable<ChildSocket<any, any>>, string>({\n\tkey: `room`,\n\tget:\n\t\t(roomId) =>\n\t\tasync ({ get, find }) => {\n\t\t\tconst argumentsState = find(roomArgumentsAtoms, roomId)\n\t\t\tconst args = get(argumentsState)\n\t\t\tconst [script, options] = args\n\t\t\tconst child = await new Promise<ChildProcessWithoutNullStreams>(\n\t\t\t\t(resolve) => {\n\t\t\t\t\tconst room = spawn(script, options, { env: process.env })\n\t\t\t\t\tconst resolver = (data: Buffer) => {\n\t\t\t\t\t\tif (data.toString() === `ALIVE`) {\n\t\t\t\t\t\t\troom.stdout.off(`data`, resolver)\n\t\t\t\t\t\t\tresolve(room)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\troom.stdout.on(`data`, resolver)\n\t\t\t\t},\n\t\t\t)\n\t\t\treturn new ChildSocket(child, roomId)\n\t\t},\n})\n","import type { Loadable } from \"atom.io\"\nimport * as AtomIO from \"atom.io\"\nimport { editRelationsInStore } from \"atom.io/internal\"\nimport type { UserInRoomMeta } from \"atom.io/realtime\"\nimport { roomIndex, usersInRooms } from \"atom.io/realtime\"\n\nimport type { ChildSocket } from \"../ipc-sockets\"\nimport type { RoomArguments } from \"./server-room-external-store\"\nimport { roomArgumentsAtoms, roomSelectors } from \"./server-room-external-store\"\nimport type { RoomKey } from \"./server-user-store\"\n\nexport const createRoomTX: AtomIO.TransactionToken<\n\t(\n\t\troomKey: RoomKey,\n\t\tscript: string,\n\t\toptions?: string[],\n\t) => Loadable<ChildSocket<any, any>>\n> = AtomIO.transaction({\n\tkey: `createRoom`,\n\tdo: ({ get, set, find }, roomId, script, options) => {\n\t\tconst args: RoomArguments = options ? [script, options] : [script]\n\t\tconst roomArgumentsState = find(roomArgumentsAtoms, roomId)\n\t\tset(roomArgumentsState, args)\n\t\tset(roomIndex, (s) => s.add(roomId))\n\t\tconst roomState = find(roomSelectors, roomId)\n\t\tconst room = get(roomState)\n\t\treturn room\n\t},\n})\nexport type CreateRoomIO = AtomIO.TransactionIO<typeof createRoomTX>\n\nexport const joinRoomTX: AtomIO.TransactionToken<\n\t(roomId: string, userId: string, enteredAtEpoch: number) => UserInRoomMeta\n> = AtomIO.transaction({\n\tkey: `joinRoom`,\n\tdo: (tools, roomId, userId, enteredAtEpoch) => {\n\t\tconst meta = { enteredAtEpoch }\n\t\teditRelationsInStore(\n\t\t\tusersInRooms,\n\t\t\t(relations) => {\n\t\t\t\trelations.set({ room: roomId, user: userId }, meta)\n\t\t\t},\n\t\t\ttools.env().store,\n\t\t)\n\t\treturn meta\n\t},\n})\nexport type JoinRoomIO = AtomIO.TransactionIO<typeof joinRoomTX>\n\nexport const leaveRoomTX: AtomIO.TransactionToken<\n\t(roomId: string, userId: string) => void\n> = AtomIO.transaction({\n\tkey: `leaveRoom`,\n\tdo: (tools, roomId, userId) => {\n\t\teditRelationsInStore(\n\t\t\tusersInRooms,\n\t\t\t(relations) => {\n\t\t\t\trelations.delete({ room: roomId, user: userId })\n\t\t\t},\n\t\t\ttools.env().store,\n\t\t)\n\t},\n})\nexport type LeaveRoomIO = AtomIO.TransactionIO<typeof leaveRoomTX>\n\nexport const destroyRoomTX: AtomIO.TransactionToken<(roomKey: RoomKey) => void> =\n\tAtomIO.transaction({\n\t\tkey: `destroyRoom`,\n\t\tdo: (tools, roomKey) => {\n\t\t\teditRelationsInStore(\n\t\t\t\tusersInRooms,\n\t\t\t\t(relations) => {\n\t\t\t\t\trelations.delete({ room: roomKey })\n\t\t\t\t},\n\t\t\t\ttools.env().store,\n\t\t\t)\n\t\t\ttools.set(roomIndex, (s) => (s.delete(roomKey), s))\n\t\t},\n\t})\n","import type {\n\tRegularAtomFamilyToken,\n\tTransactionOutcomeEvent,\n\tTransactionSubEvent,\n} from \"atom.io\"\nimport { atomFamily } from \"atom.io\"\n\nimport type { UserKey } from \"./server-user-store\"\n\n// export const completeUpdateAtoms = atomFamily<\n// \tTransactionUpdate<any> | null,\n// \tstring\n// >({\n// \tkey: `completeUpdate`,\n// \tdefault: null,\n// })\n\nexport function redactTransactionUpdateContent(\n\tvisibleStateKeys: string[],\n\tupdates: TransactionSubEvent[],\n): TransactionSubEvent[] {\n\treturn updates\n\t\t.map((update): TransactionSubEvent => {\n\t\t\tswitch (update.type) {\n\t\t\t\tcase `transaction_outcome`: {\n\t\t\t\t\tconst redacted = redactTransactionUpdateContent(\n\t\t\t\t\t\tvisibleStateKeys,\n\t\t\t\t\t\tupdate.subEvents,\n\t\t\t\t\t)\n\t\t\t\t\treturn { ...update, subEvents: redacted }\n\t\t\t\t}\n\t\t\t\tcase `atom_update`:\n\t\t\t\tcase `molecule_creation`:\n\t\t\t\tcase `molecule_disposal`:\n\t\t\t\tcase `molecule_transfer`:\n\t\t\t\tcase `state_creation`:\n\t\t\t\tcase `state_disposal`:\n\t\t\t\t\treturn update\n\t\t\t}\n\t\t})\n\t\t.filter((update) => {\n\t\t\tswitch (update.type) {\n\t\t\t\tcase `atom_update`:\n\t\t\t\tcase `state_creation`:\n\t\t\t\tcase `state_disposal`:\n\t\t\t\t\treturn visibleStateKeys.includes(update.token.key)\n\t\t\t\tcase `molecule_creation`:\n\t\t\t\tcase `transaction_outcome`:\n\t\t\t\tcase `molecule_disposal`:\n\t\t\t\tcase `molecule_transfer`:\n\t\t\t\t\treturn true\n\t\t\t}\n\t\t})\n}\n\nexport const redactorAtoms: RegularAtomFamilyToken<\n\t{\n\t\tocclude: (updates: TransactionSubEvent[]) => TransactionSubEvent[]\n\t},\n\tUserKey\n> = atomFamily<\n\t{\n\t\tocclude: (updates: TransactionSubEvent[]) => TransactionSubEvent[]\n\t},\n\tUserKey\n>({\n\tkey: `redactor`,\n\tdefault: { occlude: (updates) => updates },\n})\n// export const redactedUpdateSelectors = selectorFamily<\n// \tTransactionUpdate<any> | null,\n// \t[transactionKey: string, updateId: string]\n// >({\n// \tkey: `redactedUpdate`,\n// \tget:\n// \t\t([transactionKey, updateId]) =>\n// \t\t({ get, find }) => {\n// \t\t\tconst update = get(find(completeUpdateAtoms, updateId))\n// \t\t\tconst { filter } = get(find(transactionRedactorAtoms, transactionKey))\n\n// \t\t\tif (update && filter) {\n// \t\t\t\treturn { ...update, updates: filter(update.updates) }\n// \t\t\t}\n// \t\t\treturn null\n// \t\t},\n// })\n\nexport type ContinuitySyncTransactionUpdate = Pick<\n\tTransactionOutcomeEvent<any>,\n\t`epoch` | `id` | `output` | `subEvents` | `token`\n>\nexport const userUnacknowledgedQueues: RegularAtomFamilyToken<\n\tContinuitySyncTransactionUpdate[],\n\tUserKey\n> = atomFamily<ContinuitySyncTransactionUpdate[], UserKey>({\n\tkey: `unacknowledgedUpdates`,\n\tdefault: () => [],\n})\n","import type {\n\tHierarchy,\n\tJoinToken,\n\tMutableAtomToken,\n\tRegularAtomFamilyToken,\n} from \"atom.io\"\nimport { atomFamily, join, mutableAtom } from \"atom.io\"\nimport { SetRTX } from \"atom.io/transceivers/set-rtx\"\n\nimport type { Socket } from \"..\"\n\nexport type SocketKey = `socket::${string}`\nexport type UserKey = `user::${string}`\nexport type RoomKey = `room::${string}`\n\nexport type SocketSystemHierarchy = Hierarchy<\n\t[\n\t\t{\n\t\t\tabove: `root`\n\t\t\tbelow: [UserKey, SocketKey, RoomKey]\n\t\t},\n\t]\n>\n\nexport const socketAtoms: RegularAtomFamilyToken<Socket | null, SocketKey> =\n\tatomFamily<Socket | null, SocketKey>({\n\t\tkey: `sockets`,\n\t\tdefault: null,\n\t})\n\nexport const socketIndex: MutableAtomToken<SetRTX<SocketKey>> = mutableAtom<\n\tSetRTX<SocketKey>\n>({\n\tkey: `socketsIndex`,\n\tclass: SetRTX,\n})\nexport const userIndex: MutableAtomToken<SetRTX<UserKey>> = mutableAtom<\n\tSetRTX<UserKey>\n>({\n\tkey: `usersIndex`,\n\tclass: SetRTX,\n})\nexport const usersOfSockets: JoinToken<\n\t`user`,\n\tUserKey,\n\t`socket`,\n\tSocketKey,\n\t`1:1`\n> = join({\n\tkey: `usersOfSockets`,\n\tbetween: [`user`, `socket`],\n\tcardinality: `1:1`,\n\tisAType: (s): s is UserKey => s.startsWith(`user::`),\n\tisBType: (s): s is SocketKey => s.startsWith(`socket::`),\n})\n","import type { Store } from \"atom.io/internal\"\nimport {\n\tfindInStore,\n\tgetFromStore,\n\tgetJsonToken,\n\tisRootStore,\n} from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport type { ContinuityToken } from \"atom.io/realtime\"\n\nimport type { Socket, UserKey } from \"..\"\n\nexport function prepareToSendInitialPayload(\n\tstore: Store,\n\tcontinuity: ContinuityToken,\n\tuserKey: UserKey,\n\tsocket: Socket | null,\n): () => void {\n\tconst continuityKey = continuity.key\n\treturn function sendInitialPayload(): void {\n\t\tconst initialPayload: Json.Serializable[] = []\n\t\tfor (const atom of continuity.globals) {\n\t\t\tconst resourceToken =\n\t\t\t\tatom.type === `mutable_atom` ? getJsonToken(store, atom) : atom\n\t\t\tconst resource = getFromStore(store, resourceToken)\n\t\t\tinitialPayload.push(resourceToken, resource)\n\t\t}\n\t\tfor (const perspective of continuity.perspectives) {\n\t\t\tconst { viewAtoms, resourceAtoms } = perspective\n\t\t\tconst userViewState = findInStore(store, viewAtoms, userKey)\n\t\t\tconst userView = getFromStore(store, userViewState)\n\t\t\tstore.logger.info(`👁`, `atom`, resourceAtoms.key, `${userKey} can see`, {\n\t\t\t\tviewAtoms,\n\t\t\t\tresourceAtoms,\n\t\t\t\tuserView,\n\t\t\t})\n\t\t\tfor (const visibleToken of userView) {\n\t\t\t\tconst resourceToken =\n\t\t\t\t\tvisibleToken.type === `mutable_atom`\n\t\t\t\t\t\t? getJsonToken(store, visibleToken)\n\t\t\t\t\t\t: visibleToken\n\t\t\t\tconst resource = getFromStore(store, resourceToken)\n\n\t\t\t\tinitialPayload.push(resourceToken, resource)\n\t\t\t}\n\t\t}\n\n\t\tconst epoch = isRootStore(store)\n\t\t\t? (store.transactionMeta.epoch.get(continuityKey) ?? null)\n\t\t\t: null\n\n\t\tsocket?.emit(`continuity-init:${continuityKey}`, epoch, initialPayload)\n\t}\n}\n","import type { TransactionOutcomeEvent, TransactionToken } from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { actUponStore } from \"atom.io/internal\"\nimport type { Json, JsonIO } from \"atom.io/json\"\nimport type { ContinuityToken } from \"atom.io/realtime\"\n\nexport function prepareToServeTransactionRequest(\n\tstore: Store,\n\tcontinuity: ContinuityToken,\n\tuserKey: string,\n): (\n\tevent: Json.Serializable &\n\t\tPick<\n\t\t\tTransactionOutcomeEvent<TransactionToken<JsonIO>>,\n\t\t\t`id` | `params` | `token`\n\t\t>,\n) => void {\n\tconst continuityKey = continuity.key\n\treturn function serveTransactionRequest(txOutcome) {\n\t\tstore.logger.info(`🛎️`, `continuity`, continuityKey, `received`, txOutcome)\n\t\tconst transactionKey = txOutcome.token.key\n\t\tconst updateId = txOutcome.id\n\t\tconst performanceKey = `tx-run:${transactionKey}:${updateId}`\n\t\tconst performanceKeyStart = `${performanceKey}:start`\n\t\tconst performanceKeyEnd = `${performanceKey}:end`\n\t\tperformance.mark(performanceKeyStart)\n\t\ttry {\n\t\t\tactUponStore(\n\t\t\t\tstore,\n\t\t\t\t{ type: `transaction`, key: transactionKey },\n\t\t\t\tupdateId,\n\t\t\t)(...txOutcome.params)\n\t\t} catch (thrown) {\n\t\t\tif (thrown instanceof Error) {\n\t\t\t\tstore.logger.error(\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`failed to run transaction ${transactionKey} from ${userKey} with update ${updateId}`,\n\t\t\t\t\tthrown.message,\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t\tperformance.mark(performanceKeyEnd)\n\t\tconst metric = performance.measure(\n\t\t\tperformanceKey,\n\t\t\tperformanceKeyStart,\n\t\t\tperformanceKeyEnd,\n\t\t)\n\t\tstore?.logger.info(\n\t\t\t`🚀`,\n\t\t\t`transaction`,\n\t\t\ttransactionKey,\n\t\t\tupdateId,\n\t\t\tuserKey,\n\t\t\tmetric.duration,\n\t\t)\n\t}\n}\n","import type { Store } from \"atom.io/internal\"\nimport { setIntoStore } from \"atom.io/internal\"\nimport type { ContinuityToken } from \"atom.io/realtime\"\n\nimport type {\n\tContinuitySyncTransactionUpdate,\n\tUserKey,\n} from \"../realtime-server-stores\"\nimport { userUnacknowledgedQueues } from \"../realtime-server-stores\"\n\nexport function prepareToTrackClientAcknowledgement(\n\tstore: Store,\n\tcontinuity: ContinuityToken,\n\tuserKey: UserKey,\n\tuserUnacknowledgedUpdates: ContinuitySyncTransactionUpdate[],\n): (epoch: number) => void {\n\tconst continuityKey = continuity.key\n\treturn function trackClientAcknowledgement(epoch) {\n\t\tstore.logger.info(\n\t\t\t`👍`,\n\t\t\t`continuity`,\n\t\t\tcontinuityKey,\n\t\t\t`${userKey} acknowledged epoch ${epoch}`,\n\t\t)\n\t\tconst isUnacknowledged = userUnacknowledgedUpdates[0]?.epoch === epoch\n\t\tif (isUnacknowledged) {\n\t\t\tsetIntoStore(store, userUnacknowledgedQueues, userKey, (updates) => {\n\t\t\t\tupdates.shift()\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`${userKey} unacknowledged update queue now has`,\n\t\t\t\t\tupdates.length,\n\t\t\t\t\t`items`,\n\t\t\t\t)\n\t\t\t\treturn updates\n\t\t\t})\n\t\t}\n\t}\n}\n","import type { Store } from \"atom.io/internal\"\nimport {\n\tfindInStore,\n\tgetFromStore,\n\tgetUpdateToken,\n\tsetIntoStore,\n\tsubscribeToTransaction,\n} from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport type { ContinuityToken } from \"atom.io/realtime\"\n\nimport type { Socket, UserKey } from \"..\"\nimport {\n\tredactTransactionUpdateContent,\n\tuserUnacknowledgedQueues,\n} from \"../realtime-server-stores\"\n\nexport function subscribeToContinuityActions(\n\tstore: Store,\n\tcontinuity: ContinuityToken,\n\tuserKey: UserKey,\n\tsocket: Socket | null,\n): (() => void)[] {\n\tconst continuityKey = continuity.key\n\tconst unsubscribeFunctions: (() => void)[] = []\n\n\tfor (const transaction of continuity.actions) {\n\t\tconst unsubscribeFromTransaction = subscribeToTransaction(\n\t\t\tstore,\n\t\t\ttransaction,\n\t\t\t`sync-continuity:${continuityKey}:${userKey}`,\n\t\t\t(update) => {\n\t\t\t\ttry {\n\t\t\t\t\tconst visibleKeys = continuity.globals\n\t\t\t\t\t\t.map((atom) => {\n\t\t\t\t\t\t\tif (atom.type === `atom`) {\n\t\t\t\t\t\t\t\treturn atom.key\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn getUpdateToken(atom).key\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.concat(\n\t\t\t\t\t\t\tcontinuity.perspectives.flatMap((perspective) => {\n\t\t\t\t\t\t\t\tconst { viewAtoms } = perspective\n\t\t\t\t\t\t\t\tconst userPerspectiveTokenState = findInStore(\n\t\t\t\t\t\t\t\t\tstore,\n\t\t\t\t\t\t\t\t\tviewAtoms,\n\t\t\t\t\t\t\t\t\tuserKey,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tconst visibleTokens = getFromStore(\n\t\t\t\t\t\t\t\t\tstore,\n\t\t\t\t\t\t\t\t\tuserPerspectiveTokenState,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\treturn visibleTokens.map((token) => {\n\t\t\t\t\t\t\t\t\tconst key =\n\t\t\t\t\t\t\t\t\t\ttoken.type === `mutable_atom` ? `*` + token.key : token.key\n\t\t\t\t\t\t\t\t\treturn key\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t)\n\t\t\t\t\tconst redactedUpdates = redactTransactionUpdateContent(\n\t\t\t\t\t\tvisibleKeys,\n\t\t\t\t\t\tupdate.subEvents,\n\t\t\t\t\t)\n\t\t\t\t\tconst redactedUpdate = {\n\t\t\t\t\t\t...update,\n\t\t\t\t\t\tupdates: redactedUpdates,\n\t\t\t\t\t}\n\t\t\t\t\tsetIntoStore(store, userUnacknowledgedQueues, userKey, (updates) => {\n\t\t\t\t\t\tif (redactedUpdate) {\n\t\t\t\t\t\t\tupdates.push(redactedUpdate)\n\t\t\t\t\t\t\tupdates.sort((a, b) => a.epoch - b.epoch)\n\t\t\t\t\t\t\tstore.logger.info(\n\t\t\t\t\t\t\t\t`👍`,\n\t\t\t\t\t\t\t\t`continuity`,\n\t\t\t\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t\t\t\t`${userKey} unacknowledged update queue now has`,\n\t\t\t\t\t\t\t\tupdates.length,\n\t\t\t\t\t\t\t\t`items`,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn updates\n\t\t\t\t\t})\n\n\t\t\t\t\tsocket?.emit(\n\t\t\t\t\t\t`tx-new:${continuityKey}`,\n\t\t\t\t\t\tredactedUpdate as Json.Serializable,\n\t\t\t\t\t)\n\t\t\t\t} catch (thrown) {\n\t\t\t\t\tif (thrown instanceof Error) {\n\t\t\t\t\t\tstore.logger.error(\n\t\t\t\t\t\t\t`❌`,\n\t\t\t\t\t\t\t`continuity`,\n\t\t\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t\t\t`${userKey} failed to send update from transaction ${transaction.key} to ${userKey}`,\n\t\t\t\t\t\t\tthrown.message,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t)\n\t\tunsubscribeFunctions.push(unsubscribeFromTransaction)\n\t}\n\treturn unsubscribeFunctions\n}\n","import type { Store } from \"atom.io/internal\"\nimport {\n\tfindInStore,\n\tgetFromStore,\n\tgetJsonToken,\n\tsubscribeToState,\n} from \"atom.io/internal\"\nimport type { ContinuityToken } from \"atom.io/realtime\"\n\nimport type { Socket } from \"..\"\nimport type { UserKey } from \"../realtime-server-stores\"\n\nexport function subscribeToContinuityPerspectives(\n\tstore: Store,\n\tcontinuity: ContinuityToken,\n\tuserKey: UserKey,\n\tsocket: Socket | null,\n): (() => void)[] {\n\tconst continuityKey = continuity.key\n\tconst unsubFns: (() => void)[] = []\n\tfor (const perspective of continuity.perspectives) {\n\t\tconst { viewAtoms } = perspective\n\t\tconst userViewState = findInStore(store, viewAtoms, userKey)\n\t\tconst unsubscribeFromUserView = subscribeToState(\n\t\t\tstore,\n\t\t\tuserViewState,\n\t\t\t`sync-continuity:${continuityKey}:${userKey}:perspective:${perspective.resourceAtoms.key}`,\n\t\t\t({ oldValue, newValue }) => {\n\t\t\t\tconst oldKeys = oldValue?.map((token) => token.key)\n\t\t\t\tconst newKeys = newValue.map((token) => token.key)\n\t\t\t\tconst concealed = oldValue?.filter(\n\t\t\t\t\t(token) => !newKeys.includes(token.key),\n\t\t\t\t)\n\t\t\t\tconst revealed = newValue\n\t\t\t\t\t.filter((token) => !oldKeys?.includes(token.key))\n\t\t\t\t\t.flatMap((token) => {\n\t\t\t\t\t\tconst resourceToken =\n\t\t\t\t\t\t\ttoken.type === `mutable_atom` ? getJsonToken(store, token) : token\n\t\t\t\t\t\tconst resource = getFromStore(store, resourceToken)\n\t\t\t\t\t\treturn [resourceToken, resource]\n\t\t\t\t\t})\n\t\t\t\tstore.logger.info(\n\t\t\t\t\t`👁`,\n\t\t\t\t\t`atom`,\n\t\t\t\t\tperspective.resourceAtoms.key,\n\t\t\t\t\t`${userKey} has a new perspective`,\n\t\t\t\t\t{ oldKeys, newKeys, revealed, concealed },\n\t\t\t\t)\n\t\t\t\tif (revealed.length > 0) {\n\t\t\t\t\tsocket?.emit(`reveal:${continuityKey}`, revealed)\n\t\t\t\t}\n\t\t\t\tif (concealed && concealed.length > 0) {\n\t\t\t\t\tsocket?.emit(`conceal:${continuityKey}`, concealed)\n\t\t\t\t}\n\t\t\t},\n\t\t)\n\t\tunsubFns.push(unsubscribeFromUserView)\n\t}\n\treturn unsubFns\n}\n","import {\n\tfindInStore,\n\tfindRelationsInStore,\n\tgetFromStore,\n\tIMPLICIT,\n\tsubscribeToState,\n} from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport type { ContinuityToken } from \"atom.io/realtime\"\n\nimport type { ServerConfig, Socket } from \"..\"\nimport { socketAtoms, usersOfSockets } from \"..\"\nimport { userUnacknowledgedQueues } from \"../realtime-server-stores\"\nimport { prepareToSendInitialPayload } from \"./prepare-to-send-initial-payload\"\nimport { prepareToServeTransactionRequest } from \"./prepare-to-serve-transaction-request\"\nimport { prepareToTrackClientAcknowledgement } from \"./prepare-to-track-client-acknowledgement\"\nimport { subscribeToContinuityActions } from \"./subscribe-to-continuity-actions\"\nimport { subscribeToContinuityPerspectives } from \"./subscribe-to-continuity-perpectives\"\n\nexport type ExposeRealtimeContinuity = (\n\tcontinuity: ContinuityToken,\n) => () => void\nexport function prepareToExposeRealtimeContinuity({\n\tsocket: initialSocket,\n\tstore = IMPLICIT.STORE,\n}: ServerConfig): ExposeRealtimeContinuity {\n\treturn function syncRealtimeContinuity(continuity) {\n\t\tlet socket: Socket | null = initialSocket\n\n\t\tconst continuityKey = continuity.key\n\t\tconst userKeyState = findRelationsInStore(\n\t\t\tusersOfSockets,\n\t\t\t`socket::${socket.id}`,\n\t\t\tstore,\n\t\t).userKeyOfSocket\n\t\tconst userKey = getFromStore(store, userKeyState)\n\t\tif (!userKey) {\n\t\t\tstore.logger.error(\n\t\t\t\t`❌`,\n\t\t\t\t`continuity`,\n\t\t\t\tcontinuityKey,\n\t\t\t\t`Tried to create a synchronizer for a socket (${socket.id}) that is not connected to a user.`,\n\t\t\t)\n\t\t\treturn () => {}\n\t\t}\n\n\t\tconst socketKeyState = findRelationsInStore(\n\t\t\tusersOfSockets,\n\t\t\tuserKey,\n\t\t\tstore,\n\t\t).socketKeyOfUser\n\t\tconst _unsubscribeFromSocketTracking = subscribeToState(\n\t\t\tstore,\n\t\t\tsocketKeyState,\n\t\t\t`sync-continuity:${continuityKey}:${userKey}`,\n\t\t\t({ newValue: newSocketKey }) => {\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`seeing ${userKey} on new socket ${newSocketKey}`,\n\t\t\t\t)\n\t\t\t\tif (newSocketKey === null) {\n\t\t\t\t\tstore.logger.warn(\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`User (${userKey}) is not connected to a socket, waiting for them to reappear.`,\n\t\t\t\t\t)\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tconst newSocketState = findInStore(store, socketAtoms, newSocketKey)\n\t\t\t\tconst newSocket = getFromStore(store, newSocketState)\n\t\t\t\tsocket = newSocket\n\t\t\t\tfor (const unacknowledgedUpdate of userUnacknowledgedUpdates) {\n\t\t\t\t\tsocket?.emit(\n\t\t\t\t\t\t`tx-new:${continuityKey}`,\n\t\t\t\t\t\tunacknowledgedUpdate as Json.Serializable,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t},\n\t\t)\n\n\t\tconst userUnacknowledgedUpdates = getFromStore(\n\t\t\tstore,\n\t\t\tuserUnacknowledgedQueues,\n\t\t\tuserKey,\n\t\t)\n\n\t\tconst unsubscribeFunctions: (() => void)[] = []\n\n\t\tconst unsubscribeFromPerspectives = subscribeToContinuityPerspectives(\n\t\t\tstore,\n\t\t\tcontinuity,\n\t\t\tuserKey,\n\t\t\tsocket,\n\t\t)\n\t\tconst unsubscribeFromTransactions = subscribeToContinuityActions(\n\t\t\tstore,\n\t\t\tcontinuity,\n\t\t\tuserKey,\n\t\t\tsocket,\n\t\t)\n\t\tunsubscribeFunctions.push(\n\t\t\t...unsubscribeFromPerspectives,\n\t\t\t...unsubscribeFromTransactions,\n\t\t)\n\n\t\tconst sendInitialPayload = prepareToSendInitialPayload(\n\t\t\tstore,\n\t\t\tcontinuity,\n\t\t\tuserKey,\n\t\t\tinitialSocket,\n\t\t)\n\n\t\tsocket.off(`get:${continuityKey}`, sendInitialPayload)\n\t\tsocket.on(`get:${continuityKey}`, sendInitialPayload)\n\n\t\tconst fillTransactionRequest = prepareToServeTransactionRequest(\n\t\t\tstore,\n\t\t\tcontinuity,\n\t\t\tuserKey,\n\t\t)\n\n\t\tsocket.off(`tx-run:${continuityKey}`, fillTransactionRequest)\n\t\tsocket.on(`tx-run:${continuityKey}`, fillTransactionRequest)\n\n\t\tconst trackClientAcknowledgement = prepareToTrackClientAcknowledgement(\n\t\t\tstore,\n\t\t\tcontinuity,\n\t\t\tuserKey,\n\t\t\tuserUnacknowledgedUpdates,\n\t\t)\n\n\t\tsocket?.on(`ack:${continuityKey}`, trackClientAcknowledgement)\n\n\t\treturn () => {\n\t\t\t// clearInterval(retryTimeout)\n\t\t\tfor (const unsubscribe of unsubscribeFunctions) unsubscribe()\n\t\t\tsocket?.off(`ack:${continuityKey}`, trackClientAcknowledgement)\n\t\t\tsocket?.off(`get:${continuityKey}`, sendInitialPayload)\n\t\t\tsocket?.off(`tx-run:${continuityKey}`, fillTransactionRequest)\n\t\t}\n\t}\n}\n","import type { TransactionOutcomeEvent, TransactionToken } from \"atom.io\"\nimport { actUponStore, IMPLICIT } from \"atom.io/internal\"\nimport type { JsonIO } from \"atom.io/json\"\n\nimport type { ServerConfig } from \".\"\n\nexport type ActionReceiver = ReturnType<typeof realtimeActionReceiver>\nexport function realtimeActionReceiver({\n\tsocket,\n\tstore = IMPLICIT.STORE,\n}: ServerConfig) {\n\treturn function actionReceiver<F extends JsonIO>(\n\t\ttx: TransactionToken<F>,\n\t): () => void {\n\t\tconst fillTransactionRequest = (\n\t\t\tupdate: Pick<\n\t\t\t\tTransactionOutcomeEvent<TransactionToken<F>>,\n\t\t\t\t`id` | `params`\n\t\t\t>,\n\t\t) => {\n\t\t\tconst performanceKey = `tx-run:${tx.key}:${update.id}`\n\t\t\tconst performanceKeyStart = `${performanceKey}:start`\n\t\t\tconst performanceKeyEnd = `${performanceKey}:end`\n\t\t\tperformance.mark(performanceKeyStart)\n\t\t\tactUponStore<F>(store, tx, update.id)(...update.params)\n\t\t\tperformance.mark(performanceKeyEnd)\n\t\t\tconst metric = performance.measure(\n\t\t\t\tperformanceKey,\n\t\t\t\tperformanceKeyStart,\n\t\t\t\tperformanceKeyEnd,\n\t\t\t)\n\t\t\tstore?.logger.info(`🚀`, `transaction`, tx.key, update.id, metric.duration)\n\t\t}\n\t\tsocket.on(`tx-run:${tx.key}`, fillTransactionRequest)\n\n\t\treturn () => {\n\t\t\tsocket.off(`tx-run:${tx.key}`, fillTransactionRequest)\n\t\t}\n\t}\n}\n","import type * as AtomIO from \"atom.io\"\nimport {\n\tfindInStore,\n\tgetFromStore,\n\tIMPLICIT,\n\tsubscribeToState,\n} from \"atom.io/internal\"\nimport type { Canonical, Json } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport type { ServerConfig } from \".\"\n\nexport type FamilyProvider = ReturnType<typeof realtimeAtomFamilyProvider>\nexport function realtimeAtomFamilyProvider({\n\tsocket,\n\tstore = IMPLICIT.STORE,\n}: ServerConfig) {\n\treturn function familyProvider<\n\t\tJ extends Json.Serializable,\n\t\tK extends Canonical,\n\t>(\n\t\tfamily: AtomIO.RegularAtomFamilyToken<J, K>,\n\t\tindex: AtomIO.ReadableToken<Iterable<K>>,\n\t): () => void {\n\t\tconst unsubCallbacksByKey = new Map<string, () => void>()\n\n\t\tconst fillUnsubRequest = (key: string) => {\n\t\t\tsocket.off(`unsub:${key}`, fillUnsubRequest)\n\t\t\tconst unsub = unsubCallbacksByKey.get(key)\n\t\t\tif (unsub) {\n\t\t\t\tunsub()\n\t\t\t\tunsubCallbacksByKey.delete(key)\n\t\t\t}\n\t\t}\n\n\t\tconst fillSubRequest = (subKey: K) => {\n\t\t\tconst exposedSubKeys = getFromStore(store, index)\n\t\t\tfor (const exposedSubKey of exposedSubKeys) {\n\t\t\t\tif (stringifyJson(exposedSubKey) === stringifyJson(subKey)) {\n\t\t\t\t\tconst token = findInStore(store, family, subKey)\n\t\t\t\t\tsocket.emit(`serve:${token.key}`, getFromStore(store, token))\n\t\t\t\t\tconst unsubscribe = subscribeToState(\n\t\t\t\t\t\tstore,\n\t\t\t\t\t\ttoken,\n\t\t\t\t\t\t`expose-family:${family.key}:${socket.id}`,\n\t\t\t\t\t\t({ newValue }) => {\n\t\t\t\t\t\t\tsocket.emit(`serve:${token.key}`, newValue)\n\t\t\t\t\t\t},\n\t\t\t\t\t)\n\t\t\t\t\tunsubCallbacksByKey.set(token.key, unsubscribe)\n\t\t\t\t\tsocket.on(`unsub:${token.key}`, () => {\n\t\t\t\t\t\tfillUnsubRequest(token.key)\n\t\t\t\t\t})\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tsocket.on(`sub:${family.key}`, fillSubRequest)\n\n\t\treturn () => {\n\t\t\tsocket.off(`sub:${family.key}`, fillSubRequest)\n\n\t\t\tfor (const [, unsub] of unsubCallbacksByKey) {\n\t\t\t\tunsub()\n\t\t\t}\n\t\t\tunsubCallbacksByKey.clear()\n\t\t}\n\t}\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Transceiver } from \"atom.io/internal\"\nimport {\n\tfindInStore,\n\tgetFromStore,\n\tgetJsonToken,\n\tgetUpdateToken,\n\tIMPLICIT,\n\tsubscribeToState,\n} from \"atom.io/internal\"\nimport type { Canonical } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport type { ServerConfig } from \".\"\n\nexport type MutableFamilyProvider = ReturnType<\n\ttypeof realtimeMutableFamilyProvider\n>\nexport function realtimeMutableFamilyProvider({\n\tsocket,\n\tstore = IMPLICIT.STORE,\n}: ServerConfig) {\n\treturn function mutableFamilyProvider<\n\t\tT extends Transceiver<any, any, any>,\n\t\tK extends Canonical,\n\t>(\n\t\tfamily: AtomIO.MutableAtomFamilyToken<T, K>,\n\t\tindex: AtomIO.ReadableToken<Iterable<K>>,\n\t): () => void {\n\t\tconst unsubCallbacksByKey = new Map<string, () => void>()\n\n\t\tconst fillUnsubRequest = (key: string) => {\n\t\t\tsocket.off(`unsub:${key}`, fillUnsubRequest)\n\t\t\tconst unsub = unsubCallbacksByKey.get(key)\n\t\t\tif (unsub) {\n\t\t\t\tunsub()\n\t\t\t\tunsubCallbacksByKey.delete(key)\n\t\t\t}\n\t\t}\n\n\t\tconst fillSubRequest = (subKey: K) => {\n\t\t\tconst exposedSubKeys = getFromStore(store, index)\n\t\t\tfor (const exposedSubKey of exposedSubKeys) {\n\t\t\t\tif (stringifyJson(exposedSubKey) === stringifyJson(subKey)) {\n\t\t\t\t\tconst token = findInStore(store, family, subKey)\n\t\t\t\t\tgetFromStore(store, token)\n\t\t\t\t\tconst jsonToken = getJsonToken(store, token)\n\t\t\t\t\tconst updateToken = getUpdateToken(token)\n\t\t\t\t\tsocket.emit(`init:${token.key}`, getFromStore(store, jsonToken))\n\t\t\t\t\tconst unsubscribe = subscribeToState(\n\t\t\t\t\t\tstore,\n\t\t\t\t\t\tupdateToken,\n\t\t\t\t\t\t`expose-family:${family.key}:${socket.id}`,\n\t\t\t\t\t\t({ newValue }) => {\n\t\t\t\t\t\t\tsocket.emit(`next:${token.key}`, newValue)\n\t\t\t\t\t\t},\n\t\t\t\t\t)\n\t\t\t\t\tunsubCallbacksByKey.set(token.key, unsubscribe)\n\t\t\t\t\tsocket.on(`unsub:${token.key}`, () => {\n\t\t\t\t\t\tfillUnsubRequest(token.key)\n\t\t\t\t\t})\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tsocket.on(`sub:${family.key}`, fillSubRequest)\n\n\t\treturn () => {\n\t\t\tsocket.off(`sub:${family.key}`, fillSubRequest)\n\t\t\tfor (const [, unsub] of unsubCallbacksByKey) {\n\t\t\t\tunsub()\n\t\t\t}\n\t\t\tunsubCallbacksByKey.clear()\n\t\t}\n\t}\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Transceiver } from \"atom.io/internal\"\nimport {\n\tgetFromStore,\n\tgetJsonToken,\n\tgetUpdateToken,\n\tIMPLICIT,\n\tsubscribeToState,\n} from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { ServerConfig } from \".\"\n\nexport type MutableProvider = ReturnType<typeof realtimeMutableProvider>\nexport function realtimeMutableProvider({\n\tsocket,\n\tstore = IMPLICIT.STORE,\n}: ServerConfig) {\n\treturn function mutableProvider<\n\t\tCore extends Transceiver<any, Json.Serializable, Json.Serializable>,\n\t>(token: AtomIO.MutableAtomToken<Core>): () => void {\n\t\tlet unsubscribeFromStateUpdates: (() => void) | null = null\n\n\t\tconst jsonToken = getJsonToken(store, token)\n\t\tconst trackerToken = getUpdateToken(token)\n\n\t\tconst fillUnsubRequest = () => {\n\t\t\tsocket.off(`unsub:${token.key}`, fillUnsubRequest)\n\t\t\tunsubscribeFromStateUpdates?.()\n\t\t\tunsubscribeFromStateUpdates = null\n\t\t}\n\n\t\tconst fillSubRequest = () => {\n\t\t\tsocket.emit(`init:${token.key}`, getFromStore(store, jsonToken))\n\t\t\tunsubscribeFromStateUpdates = subscribeToState(\n\t\t\t\tstore,\n\t\t\t\ttrackerToken,\n\t\t\t\t`expose-single:${socket.id}`,\n\t\t\t\t({ newValue }) => {\n\t\t\t\t\tsocket.emit(`next:${token.key}`, newValue)\n\t\t\t\t},\n\t\t\t)\n\t\t\tsocket.on(`unsub:${token.key}`, fillUnsubRequest)\n\t\t}\n\n\t\tsocket.on(`sub:${token.key}`, fillSubRequest)\n\n\t\treturn () => {\n\t\t\tsocket.off(`sub:${token.key}`, fillSubRequest)\n\t\t\tunsubscribeFromStateUpdates?.()\n\t\t}\n\t}\n}\n","import type * as AtomIO from \"atom.io\"\nimport { getFromStore, IMPLICIT, subscribeToState } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { ServerConfig } from \".\"\n\nexport type StateProvider = ReturnType<typeof realtimeStateProvider>\nexport function realtimeStateProvider({\n\tsocket,\n\tstore = IMPLICIT.STORE,\n}: ServerConfig) {\n\treturn function stateProvider<J extends Json.Serializable>(\n\t\ttoken: AtomIO.WritableToken<J>,\n\t): () => void {\n\t\tlet unsubscribeFromStateUpdates: (() => void) | undefined\n\n\t\tconst fillSubRequest = () => {\n\t\t\tsocket.emit(`serve:${token.key}`, getFromStore(store, token))\n\n\t\t\tunsubscribeFromStateUpdates = subscribeToState(\n\t\t\t\tstore,\n\t\t\t\ttoken,\n\t\t\t\t`expose-single:${socket.id}`,\n\t\t\t\t({ newValue }) => {\n\t\t\t\t\tsocket.emit(`serve:${token.key}`, newValue)\n\t\t\t\t},\n\t\t\t)\n\n\t\t\tconst fillUnsubRequest = () => {\n\t\t\t\tsocket.off(`unsub:${token.key}`, fillUnsubRequest)\n\t\t\t\tif (unsubscribeFromStateUpdates) {\n\t\t\t\t\tunsubscribeFromStateUpdates()\n\t\t\t\t\tunsubscribeFromStateUpdates = undefined\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tsocket.on(`unsub:${token.key}`, fillUnsubRequest)\n\t\t}\n\n\t\tsocket.on(`sub:${token.key}`, fillSubRequest)\n\n\t\treturn () => {\n\t\t\tsocket.off(`sub:${token.key}`, fillSubRequest)\n\t\t\tif (unsubscribeFromStateUpdates) {\n\t\t\t\tunsubscribeFromStateUpdates()\n\t\t\t\tunsubscribeFromStateUpdates = undefined\n\t\t\t}\n\t\t}\n\t}\n}\n","import type { WritableToken } from \"atom.io\"\nimport { IMPLICIT, setIntoStore } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { ServerConfig } from \".\"\n\nexport type StateReceiver = ReturnType<typeof realtimeStateReceiver>\nexport function realtimeStateReceiver({\n\tsocket,\n\tstore = IMPLICIT.STORE,\n}: ServerConfig) {\n\treturn function stateReceiver<J extends Json.Serializable>(\n\t\ttoken: WritableToken<J>,\n\t): () => void {\n\t\tconst publish = (newValue: J) => {\n\t\t\tsetIntoStore(store, token, newValue)\n\t\t}\n\n\t\tconst fillPubUnclaim = () => {\n\t\t\tsocket.off(`pub:${token.key}`, publish)\n\t\t\tsocket.off(`unclaim:${token.key}`, fillPubUnclaim)\n\t\t}\n\t\tconst fillPubClaim = () => {\n\t\t\tsocket.on(`pub:${token.key}`, publish)\n\t\t\tsocket.on(`unclaim:${token.key}`, fillPubUnclaim)\n\t\t}\n\n\t\tsocket.on(`claim:${token.key}`, fillPubClaim)\n\n\t\treturn () => {\n\t\t\tsocket.off(`claim:${token.key}`, fillPubClaim)\n\t\t\tsocket.off(`pub:${token.key}`, publish)\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;AAkBA,IAAa,eAAb,MAAgF;CAC/E,AAAU;CACV,AAAU;CACV,AAAU,YACT,OACA,GAAG,MACI;AACP,OAAK,MAAM,YAAY,KAAK,gBAC3B,UAAS,OAAO,GAAG;EAEpB,MAAM,YAAY,KAAK,UAAU,IAAI;AACrC,MAAI,UACH,MAAK,MAAM,YAAY,UACtB,UAAS,GAAG;;CAKf,AAAO,KAAK;CACZ,AAAO;CAKP,AAAO,YACN,MAIC;AACD,OAAK,OAAO;AACZ,OAAK,4BAAY,IAAI;AACrB,OAAK,kCAAkB,IAAI;;CAG5B,AAAO,GACN,OACA,UACO;EACP,MAAM,YAAY,KAAK,UAAU,IAAI;AACrC,MAAI,UACH,WAAU,IAAI;MAEd,MAAK,UAAU,IAAI,OAAO,IAAI,IAAI,CAAC;AAEpC,SAAO;;CAGR,AAAO,MAAM,UAA8D;AAC1E,OAAK,gBAAgB,IAAI;AACzB,SAAO;;CAGR,AAA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,SAAS,SACD;AAChB,QAAO,SAAS,cACf,OACa;EACb,MAAM,WAAW,aAAgB;AAChC,gBAAa,OAAO,OAAO;;EAG5B,MAAM,uBAAuB;AAC5B,UAAO,IAAI,OAAO,MAAM,OAAO;AAC/B,UAAO,IAAI,WAAW,MAAM,OAAO;;EAEpC,MAAM,qBAAqB;AAC1B,UAAO,GAAG,OAAO,MAAM,OAAO;AAC9B,UAAO,GAAG,WAAW,MAAM,OAAO;;AAGnC,SAAO,GAAG,SAAS,MAAM,OAAO;AAEhC,eAAa;AACZ,UAAO,IAAI,SAAS,MAAM,OAAO;AACjC,UAAO,IAAI,OAAO,MAAM,OAAO"}
1
+ {"version":3,"file":"index.js","names":["redactorAtoms: RegularAtomFamilyToken<\n\t{\n\t\tocclude: (updates: TransactionSubEvent[]) => TransactionSubEvent[]\n\t},\n\tUserKey\n>","unacknowledgedUpdatesAtoms: RegularAtomFamilyToken<\n\tContinuitySyncTransactionUpdate[],\n\tUserKey\n>","transaction","initialPayload: Json.Serializable[]","ROOMS: Map<\n\tstring,\n\tChildSocket<any, any, ChildProcessWithoutNullStreams>\n>","joinRoomTX: TransactionToken<\n\t(roomId: string, userId: string, enteredAtEpoch: number) => UserInRoomMeta\n>","leaveRoomTX: TransactionToken<\n\t(roomId: string, userId: string) => void\n>","destroyRoomTX: TransactionToken<(roomKey: RoomKey) => void>","socketAtoms: RegularAtomFamilyToken<Socket | null, SocketKey>","socketIndex: MutableAtomToken<SetRTX<SocketKey>>","userIndex: MutableAtomToken<SetRTX<UserKey>>","usersOfSockets: JoinToken<\n\t`user`,\n\tUserKey,\n\t`socket`,\n\tSocketKey,\n\t`1:1`\n>","userMutualSituationalAwarenessIndexes: PureSelectorFamilyToken<\n\tUserKey[],\n\tUserKey\n>"],"sources":["../../src/realtime-server/continuity/continuity-store.ts","../../src/realtime-server/continuity/provide-outcomes.ts","../../src/realtime-server/continuity/provide-perspectives.ts","../../src/realtime-server/continuity/provide-startup-payloads.ts","../../src/realtime-server/continuity/receive-action-requests.ts","../../src/realtime-server/continuity/track-acknowledgements.ts","../../src/realtime-server/continuity/provide-continuity.ts","../../src/realtime-server/ipc-sockets/custom-socket.ts","../../src/realtime-server/ipc-sockets/child-socket.ts","../../src/realtime-server/ipc-sockets/parent-socket.ts","../../src/realtime-server/realtime-family-provider.ts","../../src/realtime-server/realtime-mutable-family-provider.ts","../../src/realtime-server/realtime-mutable-provider.ts","../../src/realtime-server/realtime-server-stores/server-room-external-store.ts","../../src/realtime-server/realtime-server-stores/server-user-store.ts","../../src/realtime-server/realtime-state-provider.ts","../../src/realtime-server/realtime-state-receiver.ts"],"sourcesContent":["import type {\n\tRegularAtomFamilyToken,\n\tTransactionOutcomeEvent,\n\tTransactionSubEvent,\n} from \"atom.io\"\nimport { atomFamily } from \"atom.io\"\n\nimport type { UserKey } from \"../realtime-server-stores/server-user-store\"\n\nexport function redactTransactionUpdateContent(\n\tvisibleStateKeys: string[],\n\tupdates: TransactionSubEvent[],\n): TransactionSubEvent[] {\n\treturn updates\n\t\t.map((update): TransactionSubEvent => {\n\t\t\tswitch (update.type) {\n\t\t\t\tcase `transaction_outcome`: {\n\t\t\t\t\tconst redacted = redactTransactionUpdateContent(\n\t\t\t\t\t\tvisibleStateKeys,\n\t\t\t\t\t\tupdate.subEvents,\n\t\t\t\t\t)\n\t\t\t\t\treturn { ...update, subEvents: redacted }\n\t\t\t\t}\n\t\t\t\tcase `atom_update`:\n\t\t\t\tcase `molecule_creation`:\n\t\t\t\tcase `molecule_disposal`:\n\t\t\t\tcase `molecule_transfer`:\n\t\t\t\tcase `state_creation`:\n\t\t\t\tcase `state_disposal`:\n\t\t\t\t\treturn update\n\t\t\t}\n\t\t})\n\t\t.filter((update) => {\n\t\t\tswitch (update.type) {\n\t\t\t\tcase `atom_update`:\n\t\t\t\tcase `state_creation`:\n\t\t\t\tcase `state_disposal`:\n\t\t\t\t\treturn visibleStateKeys.includes(update.token.key)\n\t\t\t\tcase `molecule_creation`:\n\t\t\t\tcase `transaction_outcome`:\n\t\t\t\tcase `molecule_disposal`:\n\t\t\t\tcase `molecule_transfer`:\n\t\t\t\t\treturn true\n\t\t\t}\n\t\t})\n}\n\nexport const redactorAtoms: RegularAtomFamilyToken<\n\t{\n\t\tocclude: (updates: TransactionSubEvent[]) => TransactionSubEvent[]\n\t},\n\tUserKey\n> = atomFamily<\n\t{\n\t\tocclude: (updates: TransactionSubEvent[]) => TransactionSubEvent[]\n\t},\n\tUserKey\n>({\n\tkey: `redactor`,\n\tdefault: { occlude: (updates) => updates },\n})\n\nexport type ContinuitySyncTransactionUpdate = Pick<\n\tTransactionOutcomeEvent<any>,\n\t`epoch` | `id` | `output` | `subEvents` | `token`\n>\nexport const unacknowledgedUpdatesAtoms: RegularAtomFamilyToken<\n\tContinuitySyncTransactionUpdate[],\n\tUserKey\n> = atomFamily<ContinuitySyncTransactionUpdate[], UserKey>({\n\tkey: `unacknowledgedUpdates`,\n\tdefault: () => [],\n})\n","import type { Store } from \"atom.io/internal\"\nimport {\n\tfindInStore,\n\tgetFromStore,\n\tgetUpdateToken,\n\tsetIntoStore,\n\tsubscribeToTransaction,\n} from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport type { ContinuityToken } from \"atom.io/realtime\"\n\nimport type { Socket, UserKey } from \"..\"\nimport {\n\tredactTransactionUpdateContent,\n\tunacknowledgedUpdatesAtoms,\n} from \"./continuity-store\"\n\nexport function provideOutcomes(\n\tstore: Store,\n\tsocket: Socket,\n\tcontinuity: ContinuityToken,\n\tuserKey: UserKey,\n): () => void {\n\tconst continuityKey = continuity.key\n\tconst unsubscribeFunctions = new Set<() => void>()\n\n\tfor (const transaction of continuity.actions) {\n\t\tconst unsubscribeFromTransaction = subscribeToTransaction(\n\t\t\tstore,\n\t\t\ttransaction,\n\t\t\t`sync-continuity:${continuityKey}:${userKey}`,\n\t\t\t(outcomes) => {\n\t\t\t\ttry {\n\t\t\t\t\tconst visibleKeys = continuity.globals\n\t\t\t\t\t\t.map((atom) => {\n\t\t\t\t\t\t\tif (atom.type === `atom`) {\n\t\t\t\t\t\t\t\treturn atom.key\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn getUpdateToken(atom).key\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.concat(\n\t\t\t\t\t\t\tcontinuity.perspectives.flatMap((perspective) => {\n\t\t\t\t\t\t\t\tconst { viewAtoms } = perspective\n\t\t\t\t\t\t\t\tconst userPerspectiveTokenState = findInStore(\n\t\t\t\t\t\t\t\t\tstore,\n\t\t\t\t\t\t\t\t\tviewAtoms,\n\t\t\t\t\t\t\t\t\tuserKey,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tconst visibleTokens = getFromStore(\n\t\t\t\t\t\t\t\t\tstore,\n\t\t\t\t\t\t\t\t\tuserPerspectiveTokenState,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\treturn visibleTokens.map((token) => {\n\t\t\t\t\t\t\t\t\tconst key =\n\t\t\t\t\t\t\t\t\t\ttoken.type === `mutable_atom` ? `*` + token.key : token.key\n\t\t\t\t\t\t\t\t\treturn key\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t)\n\t\t\t\t\tconst redactedUpdates = redactTransactionUpdateContent(\n\t\t\t\t\t\tvisibleKeys,\n\t\t\t\t\t\toutcomes.subEvents,\n\t\t\t\t\t)\n\t\t\t\t\tconst redactedUpdate = {\n\t\t\t\t\t\t...outcomes,\n\t\t\t\t\t\tupdates: redactedUpdates,\n\t\t\t\t\t}\n\t\t\t\t\tsetIntoStore(store, unacknowledgedUpdatesAtoms, userKey, (updates) => {\n\t\t\t\t\t\tif (redactedUpdate) {\n\t\t\t\t\t\t\tupdates.push(redactedUpdate)\n\t\t\t\t\t\t\tupdates.sort((a, b) => a.epoch - b.epoch)\n\t\t\t\t\t\t\tstore.logger.info(\n\t\t\t\t\t\t\t\t`👍`,\n\t\t\t\t\t\t\t\t`continuity`,\n\t\t\t\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t\t\t\t`${userKey} unacknowledged update queue now has`,\n\t\t\t\t\t\t\t\tupdates.length,\n\t\t\t\t\t\t\t\t`items`,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn updates\n\t\t\t\t\t})\n\n\t\t\t\t\tsocket.emit(\n\t\t\t\t\t\t`tx-new:${continuityKey}`,\n\t\t\t\t\t\tredactedUpdate as Json.Serializable,\n\t\t\t\t\t)\n\t\t\t\t} catch (thrown) {\n\t\t\t\t\tif (thrown instanceof Error) {\n\t\t\t\t\t\tstore.logger.error(\n\t\t\t\t\t\t\t`❌`,\n\t\t\t\t\t\t\t`continuity`,\n\t\t\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t\t\t`${userKey} failed to send update from transaction ${transaction.key} to ${userKey}`,\n\t\t\t\t\t\t\tthrown.message,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t)\n\t\tunsubscribeFunctions.add(unsubscribeFromTransaction)\n\t}\n\treturn () => {\n\t\tfor (const unsubscribe of unsubscribeFunctions) unsubscribe()\n\t}\n}\n","import type { Store } from \"atom.io/internal\"\nimport {\n\tfindInStore,\n\tgetFromStore,\n\tgetJsonToken,\n\tsubscribeToState,\n} from \"atom.io/internal\"\nimport type { ContinuityToken } from \"atom.io/realtime\"\n\nimport type { Socket } from \"..\"\nimport type { UserKey } from \"../realtime-server-stores\"\n\nexport function providePerspectives(\n\tstore: Store,\n\tsocket: Socket,\n\tcontinuity: ContinuityToken,\n\tuserKey: UserKey,\n): () => void {\n\tconst continuityKey = continuity.key\n\tconst unsubFns = new Set<() => void>()\n\tfor (const perspective of continuity.perspectives) {\n\t\tconst { viewAtoms } = perspective\n\t\tconst userViewState = findInStore(store, viewAtoms, userKey)\n\t\tconst unsubscribeFromUserView = subscribeToState(\n\t\t\tstore,\n\t\t\tuserViewState,\n\t\t\t`sync-continuity:${continuityKey}:${userKey}:perspective:${perspective.resourceAtoms.key}`,\n\t\t\t({ oldValue, newValue }) => {\n\t\t\t\tconst oldKeys = oldValue?.map((token) => token.key)\n\t\t\t\tconst newKeys = newValue.map((token) => token.key)\n\t\t\t\tconst concealed = oldValue?.filter(\n\t\t\t\t\t(token) => !newKeys.includes(token.key),\n\t\t\t\t)\n\t\t\t\tconst revealed = newValue\n\t\t\t\t\t.filter((token) => !oldKeys?.includes(token.key))\n\t\t\t\t\t.flatMap((token) => {\n\t\t\t\t\t\tconst resourceToken =\n\t\t\t\t\t\t\ttoken.type === `mutable_atom` ? getJsonToken(store, token) : token\n\t\t\t\t\t\tconst resource = getFromStore(store, resourceToken)\n\t\t\t\t\t\treturn [resourceToken, resource]\n\t\t\t\t\t})\n\t\t\t\tstore.logger.info(\n\t\t\t\t\t`👁`,\n\t\t\t\t\t`atom`,\n\t\t\t\t\tperspective.resourceAtoms.key,\n\t\t\t\t\t`${userKey} has a new perspective`,\n\t\t\t\t\t{ oldKeys, newKeys, revealed, concealed },\n\t\t\t\t)\n\t\t\t\tif (revealed.length > 0) {\n\t\t\t\t\tsocket.emit(`reveal:${continuityKey}`, revealed)\n\t\t\t\t}\n\t\t\t\tif (concealed && concealed.length > 0) {\n\t\t\t\t\tsocket.emit(`conceal:${continuityKey}`, concealed)\n\t\t\t\t}\n\t\t\t},\n\t\t)\n\t\tunsubFns.add(unsubscribeFromUserView)\n\t}\n\treturn () => {\n\t\tfor (const unsubscribe of unsubFns) unsubscribe()\n\t}\n}\n","import type { Store } from \"atom.io/internal\"\nimport {\n\tfindInStore,\n\tgetFromStore,\n\tgetJsonToken,\n\tisRootStore,\n} from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport type { ContinuityToken } from \"atom.io/realtime\"\n\nimport type { Socket, UserKey } from \"..\"\nimport { employSocket } from \"../employ-socket\"\n\nexport function provideStartupPayloads(\n\tstore: Store,\n\tsocket: Socket,\n\tcontinuity: ContinuityToken,\n\tuserKey: UserKey,\n): () => void {\n\tconst continuityKey = continuity.key\n\tfunction sendInitialPayload(): void {\n\t\tconst initialPayload: Json.Serializable[] = []\n\t\tfor (const atom of continuity.globals) {\n\t\t\tconst resourceToken =\n\t\t\t\tatom.type === `mutable_atom` ? getJsonToken(store, atom) : atom\n\t\t\tconst resource = getFromStore(store, resourceToken)\n\t\t\tinitialPayload.push(resourceToken, resource)\n\t\t}\n\t\tfor (const perspective of continuity.perspectives) {\n\t\t\tconst { viewAtoms, resourceAtoms } = perspective\n\t\t\tconst userViewState = findInStore(store, viewAtoms, userKey)\n\t\t\tconst userView = getFromStore(store, userViewState)\n\t\t\tstore.logger.info(`👁`, `atom`, resourceAtoms.key, `${userKey} can see`, {\n\t\t\t\tviewAtoms,\n\t\t\t\tresourceAtoms,\n\t\t\t\tuserView,\n\t\t\t})\n\t\t\tfor (const visibleToken of userView) {\n\t\t\t\tconst resourceToken =\n\t\t\t\t\tvisibleToken.type === `mutable_atom`\n\t\t\t\t\t\t? getJsonToken(store, visibleToken)\n\t\t\t\t\t\t: visibleToken\n\t\t\t\tconst resource = getFromStore(store, resourceToken)\n\n\t\t\t\tinitialPayload.push(resourceToken, resource)\n\t\t\t}\n\t\t}\n\n\t\tconst epoch = isRootStore(store)\n\t\t\t? (store.transactionMeta.epoch.get(continuityKey) ?? null)\n\t\t\t: null\n\n\t\tsocket.emit(`continuity-init:${continuityKey}`, epoch, initialPayload)\n\t}\n\treturn employSocket(socket, `get:${continuityKey}`, sendInitialPayload)\n}\n","import type { TransactionOutcomeEvent, TransactionToken } from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { actUponStore } from \"atom.io/internal\"\nimport type { Json, JsonIO } from \"atom.io/json\"\nimport type { ContinuityToken } from \"atom.io/realtime\"\n\nimport { employSocket } from \"../employ-socket\"\nimport type { Socket } from \"../socket-interface\"\n\nexport function receiveActionRequests(\n\tstore: Store,\n\tsocket: Socket,\n\tcontinuity: ContinuityToken,\n\tuserKey: string,\n): () => void {\n\tconst continuityKey = continuity.key\n\n\treturn employSocket(\n\t\tsocket,\n\t\t`tx-run:${continuityKey}`,\n\t\tfunction serveTransactionRequest(\n\t\t\ttxOutcome: Json.Serializable &\n\t\t\t\tPick<\n\t\t\t\t\tTransactionOutcomeEvent<TransactionToken<JsonIO>>,\n\t\t\t\t\t`id` | `params` | `token`\n\t\t\t\t>,\n\t\t) {\n\t\t\tstore.logger.info(`🛎️`, `continuity`, continuityKey, `received`, txOutcome)\n\t\t\tconst transactionKey = txOutcome.token.key\n\t\t\tconst updateId = txOutcome.id\n\t\t\tconst performanceKey = `tx-run:${transactionKey}:${updateId}`\n\t\t\tconst performanceKeyStart = `${performanceKey}:start`\n\t\t\tconst performanceKeyEnd = `${performanceKey}:end`\n\t\t\tperformance.mark(performanceKeyStart)\n\t\t\ttry {\n\t\t\t\tactUponStore(\n\t\t\t\t\tstore,\n\t\t\t\t\t{ type: `transaction`, key: transactionKey },\n\t\t\t\t\tupdateId,\n\t\t\t\t)(...txOutcome.params)\n\t\t\t} catch (thrown) {\n\t\t\t\tif (thrown instanceof Error) {\n\t\t\t\t\tstore.logger.error(\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`failed to run transaction ${transactionKey} from ${userKey} with update ${updateId}`,\n\t\t\t\t\t\tthrown.message,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t\tperformance.mark(performanceKeyEnd)\n\t\t\tconst metric = performance.measure(\n\t\t\t\tperformanceKey,\n\t\t\t\tperformanceKeyStart,\n\t\t\t\tperformanceKeyEnd,\n\t\t\t)\n\t\t\tstore.logger.info(\n\t\t\t\t`🚀`,\n\t\t\t\t`transaction`,\n\t\t\t\ttransactionKey,\n\t\t\t\tupdateId,\n\t\t\t\tuserKey,\n\t\t\t\tmetric.duration,\n\t\t\t)\n\t\t},\n\t)\n}\n","import type { Store } from \"atom.io/internal\"\nimport { getFromStore, setIntoStore } from \"atom.io/internal\"\nimport type { ContinuityToken } from \"atom.io/realtime\"\n\nimport { employSocket } from \"../employ-socket\"\nimport type { UserKey } from \"../realtime-server-stores\"\nimport type { Socket } from \"../socket-interface\"\nimport { unacknowledgedUpdatesAtoms } from \"./continuity-store\"\n\nexport function trackAcknowledgements(\n\tstore: Store,\n\tsocket: Socket,\n\tcontinuity: ContinuityToken,\n\tuserKey: UserKey,\n): () => void {\n\tconst continuityKey = continuity.key\n\tconst userUnacknowledgedUpdates = getFromStore(\n\t\tstore,\n\t\tunacknowledgedUpdatesAtoms,\n\t\tuserKey,\n\t)\n\tfunction trackClientAcknowledgement(epoch: number): void {\n\t\tstore.logger.info(\n\t\t\t`👍`,\n\t\t\t`continuity`,\n\t\t\tcontinuityKey,\n\t\t\t`${userKey} acknowledged epoch ${epoch}`,\n\t\t)\n\t\tconst isUnacknowledged = userUnacknowledgedUpdates[0]?.epoch === epoch\n\t\tif (isUnacknowledged) {\n\t\t\tsetIntoStore(store, unacknowledgedUpdatesAtoms, userKey, (updates) => {\n\t\t\t\tupdates.shift()\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`${userKey} unacknowledged update queue now has`,\n\t\t\t\t\tupdates.length,\n\t\t\t\t\t`items`,\n\t\t\t\t)\n\t\t\t\treturn updates\n\t\t\t})\n\t\t}\n\t}\n\treturn employSocket(socket, `ack:${continuityKey}`, trackClientAcknowledgement)\n}\n","import { getFromStore, IMPLICIT } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport type { ContinuityToken } from \"atom.io/realtime\"\n\nimport type { ServerConfig, UserKey } from \"..\"\nimport { unacknowledgedUpdatesAtoms } from \"./continuity-store\"\nimport { provideOutcomes } from \"./provide-outcomes\"\nimport { providePerspectives } from \"./provide-perspectives\"\nimport { provideStartupPayloads } from \"./provide-startup-payloads\"\nimport { receiveActionRequests } from \"./receive-action-requests\"\nimport { trackAcknowledgements } from \"./track-acknowledgements\"\n\nexport type ProvideContinuity = (\n\tcontinuity: ContinuityToken,\n\tuserKey: UserKey,\n) => () => void\nexport function prepareToProvideContinuity({\n\tsocket,\n\tstore = IMPLICIT.STORE,\n}: ServerConfig): ProvideContinuity {\n\treturn function syncRealtimeContinuity(continuity, userKey) {\n\t\tconst continuityKey = continuity.key\n\n\t\tconst unacknowledgedUpdates = getFromStore(\n\t\t\tstore,\n\t\t\tunacknowledgedUpdatesAtoms,\n\t\t\tuserKey,\n\t\t)\n\t\tfor (const unacknowledgedUpdate of unacknowledgedUpdates) {\n\t\t\tsocket.emit(\n\t\t\t\t`tx-new:${continuityKey}`,\n\t\t\t\tunacknowledgedUpdate as Json.Serializable,\n\t\t\t)\n\t\t}\n\n\t\tconst subscriptions = new Set<() => void>()\n\t\tconst clearSubscriptions = () => {\n\t\t\tfor (const unsubscribe of subscriptions) unsubscribe()\n\t\t\tsubscriptions.clear()\n\t\t}\n\n\t\tsubscriptions.add(providePerspectives(store, socket, continuity, userKey))\n\t\tsubscriptions.add(provideOutcomes(store, socket, continuity, userKey))\n\t\tsubscriptions.add(provideStartupPayloads(store, socket, continuity, userKey))\n\t\tsubscriptions.add(receiveActionRequests(store, socket, continuity, userKey))\n\t\tsubscriptions.add(trackAcknowledgements(store, socket, continuity, userKey))\n\n\t\treturn clearSubscriptions\n\t}\n}\n","import type { Json, stringified } from \"atom.io/json\"\n\nimport type { Socket } from \"../socket-interface\"\n\nexport type Events = Json.Object<string, Json.Serializable[]>\n\nexport type EventPayload<\n\treceiveRelay extends Events,\n\tK extends string & keyof receiveRelay = string & keyof receiveRelay,\n> = [string, ...receiveRelay[K]]\n\nexport interface EventBuffer<\n\tE extends Events,\n\tK extends string & keyof E = string & keyof E,\n> extends Buffer {\n\ttoString(): stringified<EventPayload<E, K>>\n}\n\nexport abstract class CustomSocket<I extends Events, O extends Events>\n\timplements Socket\n{\n\tprotected listeners: Map<keyof O, Set<(...args: Json.Array) => void>>\n\tprotected globalListeners: Set<(event: string, ...args: Json.Array) => void>\n\tprotected handleEvent<K extends string & keyof I>(\n\t\t...args: EventPayload<I, K>\n\t): void {\n\t\tconst [event, ...rest] = args\n\t\tfor (const listener of this.globalListeners) {\n\t\t\tlistener(event, ...rest)\n\t\t}\n\t\tconst listeners = this.listeners.get(event)\n\t\tif (listeners) {\n\t\t\tfor (const listener of listeners) {\n\t\t\t\tlistener(...rest)\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic id = `no_id_retrieved`\n\tpublic emit: <Event extends keyof I>(\n\t\tevent: Event,\n\t\t...args: I[Event]\n\t) => CustomSocket<I, O>\n\n\tpublic constructor(\n\t\temit: <Event extends keyof I>(\n\t\t\tevent: Event,\n\t\t\t...args: I[Event]\n\t\t) => CustomSocket<I, O>,\n\t) {\n\t\tthis.emit = emit\n\t\tthis.listeners = new Map()\n\t\tthis.globalListeners = new Set()\n\t}\n\n\tpublic on<Event extends keyof O>(\n\t\tevent: Event,\n\t\tlistener: (...args: O[Event]) => void,\n\t): this {\n\t\tconst listeners = this.listeners.get(event)\n\t\tif (listeners) {\n\t\t\tlisteners.add(listener)\n\t\t} else {\n\t\t\tthis.listeners.set(event, new Set([listener]))\n\t\t}\n\t\treturn this\n\t}\n\n\tpublic onAny(listener: (event: string, ...args: Json.Array) => void): this {\n\t\tthis.globalListeners.add(listener)\n\t\treturn this\n\t}\n\n\tpublic off<Event extends keyof O>(\n\t\tevent: Event,\n\t\tlistener?: (...args: O[Event]) => void,\n\t): this {\n\t\tconst listeners = this.listeners.get(event)\n\t\tif (listeners) {\n\t\t\tif (listener) {\n\t\t\t\tlisteners.delete(listener)\n\t\t\t} else {\n\t\t\t\tthis.listeners.delete(event)\n\t\t\t}\n\t\t}\n\t\treturn this\n\t}\n\n\tpublic offAny(listener: (event: string, ...args: Json.Array) => void): this {\n\t\tthis.globalListeners.delete(listener)\n\t\treturn this\n\t}\n}\n","import type { Readable, Writable } from \"node:stream\"\n\nimport type { Json, stringified } from \"atom.io/json\"\nimport { parseJson } from \"atom.io/json\"\n\nimport type { EventBuffer, EventPayload, Events } from \"./custom-socket\"\nimport { CustomSocket } from \"./custom-socket\"\n\n/* eslint-disable no-console */\n\nexport type ChildProcess = {\n\tpid?: number | undefined\n\tstdin: Writable\n\tstdout: Readable\n\tstderr: Readable\n}\n\nexport type StderrLog = [`e` | `i` | `w`, ...Json.Array]\n\nexport class ChildSocket<\n\tI extends Events,\n\tO extends Events,\n\tP extends ChildProcess = ChildProcess,\n> extends CustomSocket<I, O> {\n\tprotected incompleteData = ``\n\tprotected unprocessedEvents: string[] = []\n\tprotected incompleteLog = ``\n\tprotected unprocessedLogs: string[] = []\n\n\tpublic id = `#####`\n\n\tpublic proc: P\n\tpublic key: string\n\tpublic logger: Pick<Console, `error` | `info` | `warn`>\n\n\tprotected handleLog(log: StderrLog): void {\n\t\tif (Array.isArray(log)) {\n\t\t\tconst [level, ...rest] = log\n\t\t\tswitch (level) {\n\t\t\t\tcase `i`:\n\t\t\t\t\tthis.logger.info(...rest)\n\t\t\t\t\tbreak\n\t\t\t\tcase `w`:\n\t\t\t\t\tthis.logger.warn(...rest)\n\t\t\t\t\tbreak\n\t\t\t\tcase `e`:\n\t\t\t\t\tthis.logger.error(...rest)\n\t\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic constructor(\n\t\tproc: P,\n\t\tkey: string,\n\t\tlogger?: Pick<Console, `error` | `info` | `warn`>,\n\t) {\n\t\tsuper((event, ...args) => {\n\t\t\tconst stringifiedEvent = JSON.stringify([event, ...args]) + `\\x03`\n\t\t\tconst errorHandler = (err: { code: string }) => {\n\t\t\t\tif (err.code === `EPIPE`) {\n\t\t\t\t\tconsole.error(`EPIPE error during write`, this.proc.stdin)\n\t\t\t\t}\n\t\t\t\tthis.proc.stdin.removeListener(`error`, errorHandler)\n\t\t\t}\n\n\t\t\tthis.proc.stdin.once(`error`, errorHandler)\n\t\t\tthis.proc.stdin.write(stringifiedEvent)\n\n\t\t\treturn this\n\t\t})\n\t\tthis.proc = proc\n\t\tthis.key = key\n\t\tthis.logger = logger ?? {\n\t\t\tinfo: (...args: unknown[]) => {\n\t\t\t\tconsole.info(this.id, this.key, ...args)\n\t\t\t},\n\t\t\twarn: (...args: unknown[]) => {\n\t\t\t\tconsole.warn(this.id, this.key, ...args)\n\t\t\t},\n\t\t\terror: (...args: unknown[]) => {\n\t\t\t\tconsole.error(this.id, this.key, ...args)\n\t\t\t},\n\t\t}\n\t\tthis.proc.stdout.on(\n\t\t\t`data`,\n\t\t\t<K extends string & keyof I>(buffer: EventBuffer<I, K>) => {\n\t\t\t\tconst chunk = buffer.toString()\n\n\t\t\t\tif (chunk === `ALIVE`) {\n\t\t\t\t\tthis.logger.info(chunk)\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tconst pieces = chunk.split(`\\x03`)\n\t\t\t\tconst initialMaybeWellFormed = pieces[0]\n\t\t\t\tpieces[0] = this.incompleteData + initialMaybeWellFormed\n\t\t\t\tlet idx = 0\n\t\t\t\tfor (const piece of pieces) {\n\t\t\t\t\tif (piece === ``) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst jsonPiece = parseJson(piece as stringified<EventPayload<I, K>>)\n\t\t\t\t\t\tthis.handleEvent(...jsonPiece)\n\t\t\t\t\t\tthis.incompleteData = ``\n\t\t\t\t\t} catch (thrown0) {\n\t\t\t\t\t\tif (thrown0 instanceof Error) {\n\t\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\t`❌ Malformed data received from child process`,\n\t\t\t\t\t\t\t\t\t``,\n\t\t\t\t\t\t\t\t\tpiece,\n\t\t\t\t\t\t\t\t\t``,\n\t\t\t\t\t\t\t\t\tthrown0.message,\n\t\t\t\t\t\t\t\t].join(`\\n❌\\t`),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tif (idx === 0) {\n\t\t\t\t\t\t\t\tthis.incompleteData = piece\n\t\t\t\t\t\t\t\tconst maybeActualJsonPiece = parseJson(\n\t\t\t\t\t\t\t\t\tinitialMaybeWellFormed as stringified<EventPayload<I, K>>,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tthis.handleEvent(...maybeActualJsonPiece)\n\t\t\t\t\t\t\t\tthis.incompleteData = ``\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tthis.incompleteData += piece\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} catch (thrown1) {\n\t\t\t\t\t\t\tif (thrown1 instanceof Error) {\n\t\t\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\t\t`❌ Malformed data received from child process`,\n\t\t\t\t\t\t\t\t\t\t``,\n\t\t\t\t\t\t\t\t\t\tinitialMaybeWellFormed,\n\t\t\t\t\t\t\t\t\t\t``,\n\t\t\t\t\t\t\t\t\t\tthrown1.message,\n\t\t\t\t\t\t\t\t\t].join(`\\n❌\\t`),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t++idx\n\t\t\t\t}\n\t\t\t},\n\t\t)\n\t\tthis.proc.stderr.on(`data`, (buffer: Buffer) => {\n\t\t\tconst chunk = buffer.toString()\n\t\t\tconst pieces = chunk.split(`\\x03`)\n\t\t\tconst initialMaybeWellFormed = pieces[0]\n\t\t\tpieces[0] = this.incompleteData + initialMaybeWellFormed\n\t\t\tlet idx = 0\n\t\t\tfor (const piece of pieces) {\n\t\t\t\tif (piece === ``) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\tconst jsonPiece = parseJson(piece as stringified<StderrLog>)\n\t\t\t\t\tthis.handleLog(jsonPiece)\n\t\t\t\t\tthis.incompleteData = ``\n\t\t\t\t} catch (thrown0) {\n\t\t\t\t\tif (thrown0 instanceof Error) {\n\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t`❌ Malformed log received from child process`,\n\t\t\t\t\t\t\t\t``,\n\t\t\t\t\t\t\t\tpiece,\n\t\t\t\t\t\t\t\t``,\n\t\t\t\t\t\t\t\tthrown0.message,\n\t\t\t\t\t\t\t].join(`\\n❌\\t`),\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t\ttry {\n\t\t\t\t\t\tif (idx === 0) {\n\t\t\t\t\t\t\tthis.incompleteData = piece\n\t\t\t\t\t\t\tconst maybeActualJsonPiece = parseJson(\n\t\t\t\t\t\t\t\tinitialMaybeWellFormed as stringified<StderrLog>,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tthis.handleLog(maybeActualJsonPiece)\n\t\t\t\t\t\t\tthis.incompleteData = ``\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthis.incompleteData += piece\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch (thrown1) {\n\t\t\t\t\t\tif (thrown1 instanceof Error) {\n\t\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\t`❌ Malformed log received from child process...`,\n\t\t\t\t\t\t\t\t\t``,\n\t\t\t\t\t\t\t\t\tinitialMaybeWellFormed,\n\t\t\t\t\t\t\t\t\t``,\n\t\t\t\t\t\t\t\t\tthrown1.message,\n\t\t\t\t\t\t\t\t].join(`\\n❌\\t`),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t++idx\n\t\t\t}\n\t\t})\n\t\tif (proc.pid) {\n\t\t\tthis.id = proc.pid.toString()\n\t\t}\n\t}\n}\n","import type { Readable, Writable } from \"node:stream\"\n\nimport { Subject } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport { parseJson, stringifyJson } from \"atom.io/json\"\nimport { SetRTX } from \"atom.io/transceivers/set-rtx\"\n\nimport type { UserKey } from \"../realtime-server-stores\"\nimport type { StderrLog } from \"./child-socket\"\nimport type { EventBuffer, EventPayload, Events } from \"./custom-socket\"\nimport { CustomSocket } from \"./custom-socket\"\n\nexport class SubjectSocket<\n\tI extends Events,\n\tO extends Events,\n> extends CustomSocket<I, O> {\n\tpublic in: Subject<EventPayload<I>>\n\tpublic out: Subject<EventPayload<O>>\n\tpublic id = `no_id_retrieved`\n\tpublic disposalFunctions: (() => void)[] = []\n\n\tpublic constructor(id: string) {\n\t\tsuper((...args) => {\n\t\t\tthis.out.next(args as any)\n\t\t\treturn this\n\t\t})\n\t\tthis.id = id\n\t\tthis.in = new Subject()\n\t\tthis.out = new Subject()\n\t\tthis.in.subscribe(`socket`, (event) => {\n\t\t\tthis.handleEvent(...event)\n\t\t})\n\t}\n\n\tpublic dispose(): void {\n\t\tfor (const dispose of this.disposalFunctions) {\n\t\t\tdispose()\n\t\t}\n\t}\n}\n\nexport type ParentProcess = {\n\tpid?: number | undefined\n\tstdin: Readable\n\tstdout: Writable\n\tstderr: Writable\n\texit: (code?: number) => void\n}\n\nexport class ParentSocket<\n\tI extends Events & {\n\t\t[id in string as `relay::${id}`]: [string, ...Json.Array[]]\n\t},\n\tO extends Events & {\n\t\t[id in string as `user::${id}`]: [string, ...Json.Array[]]\n\t} & {\n\t\t/* eslint-disable quotes */\n\t\t\"user-joins\": [key: UserKey]\n\t\t\"user-leaves\": [key: UserKey]\n\t\t/* eslint-enable quotes */\n\t},\n\tP extends ParentProcess = ParentProcess,\n> extends CustomSocket<I, O> {\n\tprotected incompleteData = ``\n\tprotected unprocessedEvents: string[] = []\n\tprotected relays: Map<string, SubjectSocket<any, any>>\n\tprotected relayServices: ((\n\t\tsocket: SubjectSocket<any, any>,\n\t\tuserKey: UserKey,\n\t) => (() => void) | void)[]\n\tpublic proc: P\n\n\tpublic id = `#####`\n\n\tprotected log(...args: StderrLog): void {\n\t\tthis.proc.stderr.write(\n\t\t\tstringifyJson(\n\t\t\t\targs.map((arg) =>\n\t\t\t\t\targ instanceof SetRTX\n\t\t\t\t\t\t? `{ ${arg.toJSON().members.join(` | `)} }`\n\t\t\t\t\t\t: arg,\n\t\t\t\t),\n\t\t\t) + `\\x03`,\n\t\t)\n\t}\n\tpublic logger = {\n\t\tinfo: (...args: Json.Array): void => {\n\t\t\tthis.log(`i`, ...args)\n\t\t},\n\t\twarn: (...args: Json.Array): void => {\n\t\t\tthis.log(`w`, ...args)\n\t\t},\n\t\terror: (...args: Json.Array): void => {\n\t\t\tthis.log(`e`, ...args)\n\t\t},\n\t}\n\n\tpublic constructor(proc: P) {\n\t\tsuper((event, ...args) => {\n\t\t\tconst stringifiedEvent = JSON.stringify([event, ...args])\n\t\t\tthis.proc.stdout.write(stringifiedEvent + `\\x03`)\n\t\t\treturn this\n\t\t})\n\t\tthis.proc = proc\n\t\tthis.proc.stdin.resume()\n\t\tthis.relays = new Map()\n\t\tthis.relayServices = []\n\n\t\tthis.proc.stdin.on(\n\t\t\t`data`,\n\t\t\t<K extends string & keyof I>(buffer: EventBuffer<I, K>) => {\n\t\t\t\tconst chunk = buffer.toString()\n\t\t\t\tconst pieces = chunk.split(`\\x03`)\n\t\t\t\tconst initialMaybeWellFormed = pieces[0]\n\t\t\t\tpieces[0] = this.incompleteData + initialMaybeWellFormed\n\t\t\t\tlet idx = 0\n\t\t\t\tfor (const piece of pieces) {\n\t\t\t\t\tif (piece === ``) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst jsonPiece = parseJson(piece)\n\t\t\t\t\t\tthis.logger.info(`🎰`, `received`, jsonPiece)\n\t\t\t\t\t\tthis.handleEvent(...(jsonPiece as EventPayload<I>))\n\t\t\t\t\t\tthis.incompleteData = ``\n\t\t\t\t\t} catch (thrown0) {\n\t\t\t\t\t\tif (thrown0 instanceof Error) {\n\t\t\t\t\t\t\tthis.logger.error(\n\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\t`received malformed data from parent process:`,\n\t\t\t\t\t\t\t\t\t``,\n\t\t\t\t\t\t\t\t\tpiece,\n\t\t\t\t\t\t\t\t\t``,\n\t\t\t\t\t\t\t\t\tthrown0.message,\n\t\t\t\t\t\t\t\t].join(`\\n❌\\t`),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tif (idx === 0) {\n\t\t\t\t\t\t\t\tthis.incompleteData = piece\n\t\t\t\t\t\t\t\tconst maybeActualJsonPiece = parseJson(initialMaybeWellFormed)\n\t\t\t\t\t\t\t\tthis.logger.info(`🎰`, `received`, maybeActualJsonPiece)\n\t\t\t\t\t\t\t\tthis.handleEvent(...(maybeActualJsonPiece as EventPayload<I>))\n\t\t\t\t\t\t\t\tthis.incompleteData = ``\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tthis.incompleteData += piece\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} catch (thrown1) {\n\t\t\t\t\t\t\tif (thrown1 instanceof Error) {\n\t\t\t\t\t\t\t\tthis.logger.error(\n\t\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\t\t`received malformed data from parent process:`,\n\t\t\t\t\t\t\t\t\t\t``,\n\t\t\t\t\t\t\t\t\t\tinitialMaybeWellFormed,\n\t\t\t\t\t\t\t\t\t\t``,\n\t\t\t\t\t\t\t\t\t\tthrown1.message,\n\t\t\t\t\t\t\t\t\t].join(`\\n❌\\t`),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t++idx\n\t\t\t\t}\n\t\t\t},\n\t\t)\n\n\t\tthis.on(`exit`, () => {\n\t\t\tthis.logger.info(`🔥`, this.id, `received \"exit\"`)\n\t\t\tthis.proc.exit(0)\n\t\t})\n\n\t\tif (this.proc.pid) {\n\t\t\tthis.id = this.proc.pid?.toString()\n\t\t}\n\n\t\tthis.on(`user-joins`, (username: string) => {\n\t\t\tthis.logger.info(`👤`, `user`, username, `joined`)\n\t\t\tconst userKey = `user::${username}` satisfies UserKey\n\t\t\tconst relay = new SubjectSocket(userKey)\n\t\t\tthis.relays.set(username, relay)\n\t\t\tthis.logger.info(\n\t\t\t\t`🔗`,\n\t\t\t\t`attaching services:`,\n\t\t\t\t`[${[...this.relayServices.keys()].join(`, `)}]`,\n\t\t\t)\n\t\t\tfor (const attachRelay of this.relayServices) {\n\t\t\t\tconst cleanupRelay = attachRelay(relay, userKey)\n\t\t\t\tif (cleanupRelay) {\n\t\t\t\t\trelay.disposalFunctions.push(cleanupRelay)\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.on(userKey, (...data) => {\n\t\t\t\trelay.in.next(data)\n\t\t\t})\n\t\t\trelay.out.subscribe(`socket`, (data) => {\n\t\t\t\tthis.emit(...(data as [string, ...I[keyof I]]))\n\t\t\t})\n\t\t})\n\n\t\tthis.on(`user-leaves`, (username) => {\n\t\t\tconst relay = this.relays.get(username)\n\t\t\tthis.off(`relay:${username}`)\n\t\t\tif (relay) {\n\t\t\t\trelay.dispose()\n\t\t\t\tthis.relays.delete(username)\n\t\t\t}\n\t\t})\n\n\t\tthis.proc.stdout.write(`ALIVE`)\n\t}\n\n\tpublic receiveRelay(\n\t\tattachServices: (\n\t\t\tsocket: SubjectSocket<any, any>,\n\t\t\tuserKey: UserKey,\n\t\t) => (() => void) | void,\n\t): void {\n\t\tthis.logger.info(`🔗`, `running relay method`)\n\t\tthis.relayServices.push(attachServices)\n\t}\n}\n","import type * as AtomIO from \"atom.io\"\nimport {\n\tfindInStore,\n\tgetFromStore,\n\tIMPLICIT,\n\tsubscribeToState,\n} from \"atom.io/internal\"\nimport type { Canonical, Json, stringified } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport type { ServerConfig } from \".\"\nimport { employSocket } from \"./employ-socket\"\n\nexport type FamilyProvider = ReturnType<typeof realtimeAtomFamilyProvider>\nexport function realtimeAtomFamilyProvider({\n\tsocket,\n\tstore = IMPLICIT.STORE,\n}: ServerConfig) {\n\treturn function familyProvider<\n\t\tJ extends Json.Serializable,\n\t\tK extends Canonical,\n\t>(\n\t\tfamily: AtomIO.RegularAtomFamilyToken<J, K>,\n\t\tindex: AtomIO.ReadableToken<Iterable<K>>,\n\t): () => void {\n\t\tconst coreSubscriptions = new Set<() => void>()\n\t\tconst clearCoreSubscriptions = () => {\n\t\t\tfor (const unsub of coreSubscriptions) unsub()\n\t\t\tcoreSubscriptions.clear()\n\t\t}\n\t\tconst familyMemberSubscriptionsWanted = new Set<stringified<K>>()\n\t\tconst familyMemberSubscriptions = new Map<string, () => void>()\n\t\tconst clearFamilySubscriptions = () => {\n\t\t\tfor (const unsub of familyMemberSubscriptions.values()) unsub()\n\t\t\tfamilyMemberSubscriptions.clear()\n\t\t}\n\n\t\tconst fillUnsubRequest = (key: string) => {\n\t\t\tconst unsubUnsub = familyMemberSubscriptions.get(`${key}:unsub`)\n\t\t\tif (unsubUnsub) {\n\t\t\t\tunsubUnsub()\n\t\t\t\tfamilyMemberSubscriptions.delete(`${key}:unsub`)\n\t\t\t}\n\t\t\tconst unsub = familyMemberSubscriptions.get(key)\n\t\t\tif (unsub) {\n\t\t\t\tunsub()\n\t\t\t\tfamilyMemberSubscriptions.delete(key)\n\t\t\t}\n\t\t}\n\n\t\tconst exposeFamilyMembers = (subKey: K) => {\n\t\t\tconst token = findInStore(store, family, subKey)\n\t\t\tgetFromStore(store, token)\n\t\t\tsocket.emit(`serve:${token.key}`, getFromStore(store, token))\n\t\t\tfamilyMemberSubscriptions.set(\n\t\t\t\ttoken.key,\n\t\t\t\tsubscribeToState(\n\t\t\t\t\tstore,\n\t\t\t\t\ttoken,\n\t\t\t\t\t`expose-family:${family.key}:${socket.id}`,\n\t\t\t\t\t({ newValue }) => {\n\t\t\t\t\t\tsocket.emit(`serve:${token.key}`, newValue)\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\t)\n\t\t\tfamilyMemberSubscriptions.set(\n\t\t\t\t`${token.key}:unsub`,\n\t\t\t\temploySocket(socket, `unsub:${token.key}`, () => {\n\t\t\t\t\tfillUnsubRequest(token.key)\n\t\t\t\t}),\n\t\t\t)\n\t\t}\n\n\t\tconst isAvailable = (exposedSubKeys: Iterable<K>, subKey: K): boolean => {\n\t\t\tfor (const exposedSubKey of exposedSubKeys) {\n\t\t\t\tif (stringifyJson(exposedSubKey) === stringifyJson(subKey)) {\n\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn false\n\t\t}\n\n\t\tconst start = () => {\n\t\t\tcoreSubscriptions.add(\n\t\t\t\temploySocket(socket, `sub:${family.key}`, (subKey: K) => {\n\t\t\t\t\tconst exposedSubKeys = getFromStore(store, index)\n\t\t\t\t\tconst shouldExpose = isAvailable(exposedSubKeys, subKey)\n\t\t\t\t\tif (shouldExpose) {\n\t\t\t\t\t\texposeFamilyMembers(subKey)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tfamilyMemberSubscriptionsWanted.add(stringifyJson(subKey))\n\t\t\t\t\t\tsocket.emit(`unavailable:${family.key}`, subKey)\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t)\n\t\t\tcoreSubscriptions.add(\n\t\t\t\tsubscribeToState(\n\t\t\t\t\tstore,\n\t\t\t\t\tindex,\n\t\t\t\t\t`expose-family:${family.key}:${socket.id}`,\n\t\t\t\t\t({ newValue: newExposedSubKeys }) => {\n\t\t\t\t\t\tfor (const subKey of newExposedSubKeys) {\n\t\t\t\t\t\t\tif (familyMemberSubscriptionsWanted.has(stringifyJson(subKey))) {\n\t\t\t\t\t\t\t\texposeFamilyMembers(subKey)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\t)\n\t\t}\n\n\t\tstart()\n\n\t\treturn () => {\n\t\t\tclearCoreSubscriptions()\n\t\t\tclearFamilySubscriptions()\n\t\t}\n\t}\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Transceiver } from \"atom.io/internal\"\nimport {\n\tfindInStore,\n\tgetFromStore,\n\tgetJsonToken,\n\tgetUpdateToken,\n\tIMPLICIT,\n\tsubscribeToState,\n} from \"atom.io/internal\"\nimport type { Canonical, stringified } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport type { ServerConfig } from \".\"\nimport { employSocket } from \"./employ-socket\"\n\nexport type MutableFamilyProvider = ReturnType<\n\ttypeof realtimeMutableFamilyProvider\n>\nexport function realtimeMutableFamilyProvider({\n\tsocket,\n\tstore = IMPLICIT.STORE,\n}: ServerConfig) {\n\treturn function mutableFamilyProvider<\n\t\tT extends Transceiver<any, any, any>,\n\t\tK extends Canonical,\n\t>(\n\t\tfamily: AtomIO.MutableAtomFamilyToken<T, K>,\n\t\tindex: AtomIO.ReadableToken<Iterable<K>>,\n\t): () => void {\n\t\tconst coreSubscriptions = new Set<() => void>()\n\t\tconst clearCoreSubscriptions = () => {\n\t\t\tfor (const unsub of coreSubscriptions) unsub()\n\t\t\tcoreSubscriptions.clear()\n\t\t}\n\t\tconst familyMemberSubscriptionsWanted = new Set<stringified<K>>()\n\t\tconst familyMemberSubscriptions = new Map<string, () => void>()\n\t\tconst clearFamilySubscriptions = () => {\n\t\t\tfor (const unsub of familyMemberSubscriptions.values()) unsub()\n\t\t\tfamilyMemberSubscriptions.clear()\n\t\t}\n\n\t\tconst fillUnsubRequest = (key: string) => {\n\t\t\tconst unsubUnsub = familyMemberSubscriptions.get(`${key}:unsub`)\n\t\t\tif (unsubUnsub) {\n\t\t\t\tunsubUnsub()\n\t\t\t\tfamilyMemberSubscriptions.delete(`${key}:unsub`)\n\t\t\t}\n\t\t\tconst unsub = familyMemberSubscriptions.get(key)\n\t\t\tif (unsub) {\n\t\t\t\tunsub()\n\t\t\t\tfamilyMemberSubscriptions.delete(key)\n\t\t\t}\n\t\t}\n\n\t\tconst exposeFamilyMembers = (subKey: K) => {\n\t\t\tconst token = findInStore(store, family, subKey)\n\t\t\tgetFromStore(store, token)\n\t\t\tconst jsonToken = getJsonToken(store, token)\n\t\t\tconst updateToken = getUpdateToken(token)\n\t\t\tsocket.emit(`init:${token.key}`, getFromStore(store, jsonToken))\n\t\t\tfamilyMemberSubscriptions.set(\n\t\t\t\ttoken.key,\n\t\t\t\tsubscribeToState(\n\t\t\t\t\tstore,\n\t\t\t\t\tupdateToken,\n\t\t\t\t\t`expose-family:${family.key}:${socket.id}`,\n\t\t\t\t\t({ newValue }) => {\n\t\t\t\t\t\tsocket.emit(`next:${token.key}`, newValue)\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\t)\n\t\t\tfamilyMemberSubscriptions.set(\n\t\t\t\t`${token.key}:unsub`,\n\t\t\t\temploySocket(socket, `unsub:${token.key}`, () => {\n\t\t\t\t\tfillUnsubRequest(token.key)\n\t\t\t\t}),\n\t\t\t)\n\t\t}\n\n\t\tconst isAvailable = (exposedSubKeys: Iterable<K>, subKey: K): boolean => {\n\t\t\tfor (const exposedSubKey of exposedSubKeys) {\n\t\t\t\tif (stringifyJson(exposedSubKey) === stringifyJson(subKey)) {\n\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn false\n\t\t}\n\n\t\tconst start = () => {\n\t\t\tcoreSubscriptions.add(\n\t\t\t\temploySocket(socket, `sub:${family.key}`, (subKey: K) => {\n\t\t\t\t\tconst exposedSubKeys = getFromStore(store, index)\n\t\t\t\t\tconst shouldExpose = isAvailable(exposedSubKeys, subKey)\n\t\t\t\t\tif (shouldExpose) {\n\t\t\t\t\t\texposeFamilyMembers(subKey)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tfamilyMemberSubscriptionsWanted.add(stringifyJson(subKey))\n\t\t\t\t\t\tsocket.emit(`unavailable:${family.key}`, subKey)\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t)\n\t\t\tcoreSubscriptions.add(\n\t\t\t\tsubscribeToState(\n\t\t\t\t\tstore,\n\t\t\t\t\tindex,\n\t\t\t\t\t`expose-family:${family.key}:${socket.id}`,\n\t\t\t\t\t({ newValue: newExposedSubKeys }) => {\n\t\t\t\t\t\tfor (const subKey of newExposedSubKeys) {\n\t\t\t\t\t\t\tif (familyMemberSubscriptionsWanted.has(stringifyJson(subKey))) {\n\t\t\t\t\t\t\t\texposeFamilyMembers(subKey)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\t)\n\t\t}\n\n\t\tstart()\n\n\t\treturn () => {\n\t\t\tclearCoreSubscriptions()\n\t\t\tclearFamilySubscriptions()\n\t\t}\n\t}\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Transceiver } from \"atom.io/internal\"\nimport {\n\tgetFromStore,\n\tgetJsonToken,\n\tgetUpdateToken,\n\tIMPLICIT,\n\tsubscribeToState,\n} from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { ServerConfig } from \".\"\nimport { employSocket } from \"./employ-socket\"\n\nexport type MutableProvider = ReturnType<typeof realtimeMutableProvider>\nexport function realtimeMutableProvider({\n\tsocket,\n\tstore = IMPLICIT.STORE,\n}: ServerConfig) {\n\treturn function mutableProvider<\n\t\tCore extends Transceiver<any, Json.Serializable, Json.Serializable>,\n\t>(token: AtomIO.MutableAtomToken<Core>): () => void {\n\t\tconst subscriptions = new Set<() => void>()\n\t\tconst clearSubscriptions = () => {\n\t\t\tfor (const unsub of subscriptions) unsub()\n\t\t\tsubscriptions.clear()\n\t\t}\n\n\t\tconst jsonToken = getJsonToken(store, token)\n\t\tconst trackerToken = getUpdateToken(token)\n\n\t\tconst start = () => {\n\t\t\tsubscriptions.add(\n\t\t\t\temploySocket(socket, `sub:${token.key}`, () => {\n\t\t\t\t\tclearSubscriptions()\n\t\t\t\t\tsocket.emit(`init:${token.key}`, getFromStore(store, jsonToken))\n\t\t\t\t\tsubscriptions.add(\n\t\t\t\t\t\tsubscribeToState(\n\t\t\t\t\t\t\tstore,\n\t\t\t\t\t\t\ttrackerToken,\n\t\t\t\t\t\t\t`expose-single:${socket.id}`,\n\t\t\t\t\t\t\t({ newValue }) => {\n\t\t\t\t\t\t\t\tsocket.emit(`next:${token.key}`, newValue)\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t),\n\t\t\t\t\t)\n\t\t\t\t\tsubscriptions.add(\n\t\t\t\t\t\temploySocket(socket, `unsub:${token.key}`, () => {\n\t\t\t\t\t\t\tclearSubscriptions()\n\t\t\t\t\t\t\tstart()\n\t\t\t\t\t\t}),\n\t\t\t\t\t)\n\t\t\t\t}),\n\t\t\t)\n\t\t}\n\n\t\tstart()\n\n\t\treturn clearSubscriptions\n\t}\n}\n","import type { ChildProcessWithoutNullStreams } from \"node:child_process\"\nimport { spawn } from \"node:child_process\"\n\nimport type { TransactionIO, TransactionToken } from \"atom.io\"\nimport { transaction } from \"atom.io\"\nimport { editRelationsInStore } from \"atom.io/internal\"\nimport type { UserInRoomMeta } from \"atom.io/realtime/shared-room-store\"\nimport { roomIndex, usersInRooms } from \"atom.io/realtime/shared-room-store\"\n\nimport { ChildSocket } from \"../ipc-sockets\"\nimport type { RoomKey } from \"./server-user-store\"\n\nexport const ROOMS: Map<\n\tstring,\n\tChildSocket<any, any, ChildProcessWithoutNullStreams>\n> = new Map()\n\nexport async function spawnRoom(\n\troomId: string,\n\tscript: string,\n\toptions: string[],\n): Promise<ChildSocket<any, any>> {\n\tconst child = await new Promise<ChildProcessWithoutNullStreams>((resolve) => {\n\t\tconst room = spawn(script, options, { env: process.env })\n\t\tconst resolver = (data: Buffer) => {\n\t\t\tif (data.toString() === `ALIVE`) {\n\t\t\t\troom.stdout.off(`data`, resolver)\n\t\t\t\tresolve(room)\n\t\t\t}\n\t\t}\n\t\troom.stdout.on(`data`, resolver)\n\t})\n\tROOMS.set(roomId, new ChildSocket(child, roomId))\n\treturn new ChildSocket(child, roomId)\n}\n\nexport const joinRoomTX: TransactionToken<\n\t(roomId: string, userId: string, enteredAtEpoch: number) => UserInRoomMeta\n> = transaction({\n\tkey: `joinRoom`,\n\tdo: (tools, roomId, userId, enteredAtEpoch) => {\n\t\tconst meta = { enteredAtEpoch }\n\t\teditRelationsInStore(\n\t\t\tusersInRooms,\n\t\t\t(relations) => {\n\t\t\t\trelations.set({ room: roomId, user: userId }, meta)\n\t\t\t},\n\t\t\ttools.env().store,\n\t\t)\n\t\treturn meta\n\t},\n})\nexport type JoinRoomIO = TransactionIO<typeof joinRoomTX>\n\nexport const leaveRoomTX: TransactionToken<\n\t(roomId: string, userId: string) => void\n> = transaction({\n\tkey: `leaveRoom`,\n\tdo: ({ env }, roomId, userId) => {\n\t\teditRelationsInStore(\n\t\t\tusersInRooms,\n\t\t\t(relations) => {\n\t\t\t\trelations.delete({ room: roomId, user: userId })\n\t\t\t},\n\t\t\tenv().store,\n\t\t)\n\t},\n})\nexport type LeaveRoomIO = TransactionIO<typeof leaveRoomTX>\n\nexport const destroyRoomTX: TransactionToken<(roomKey: RoomKey) => void> =\n\ttransaction({\n\t\tkey: `destroyRoom`,\n\t\tdo: ({ set, env }, roomId) => {\n\t\t\teditRelationsInStore(\n\t\t\t\tusersInRooms,\n\t\t\t\t(relations) => {\n\t\t\t\t\trelations.delete({ room: roomId })\n\t\t\t\t},\n\t\t\t\tenv().store,\n\t\t\t)\n\t\t\tset(roomIndex, (s) => (s.delete(roomId), s))\n\t\t\tconst room = ROOMS.get(roomId)\n\t\t\tif (room) {\n\t\t\t\troom.emit(`exit`)\n\t\t\t\tROOMS.delete(roomId)\n\t\t\t}\n\t\t},\n\t})\n","import type {\n\tHierarchy,\n\tJoinToken,\n\tMutableAtomToken,\n\tPureSelectorFamilyToken,\n\tRegularAtomFamilyToken,\n} from \"atom.io\"\nimport { atomFamily, join, mutableAtom, selectorFamily } from \"atom.io\"\nimport { SetRTX } from \"atom.io/transceivers/set-rtx\"\n\nimport type { Socket } from \"..\"\n\nexport type SocketKey = `socket::${string}`\nexport type UserKey = `user::${string}`\nexport type RoomKey = `room::${string}`\n\nexport type SocketSystemHierarchy = Hierarchy<\n\t[\n\t\t{\n\t\t\tabove: `root`\n\t\t\tbelow: [UserKey, SocketKey, RoomKey]\n\t\t},\n\t]\n>\n\nexport const socketAtoms: RegularAtomFamilyToken<Socket | null, SocketKey> =\n\tatomFamily<Socket | null, SocketKey>({\n\t\tkey: `sockets`,\n\t\tdefault: null,\n\t})\n\nexport const socketIndex: MutableAtomToken<SetRTX<SocketKey>> = mutableAtom<\n\tSetRTX<SocketKey>\n>({\n\tkey: `socketsIndex`,\n\tclass: SetRTX,\n})\nexport const userIndex: MutableAtomToken<SetRTX<UserKey>> = mutableAtom<\n\tSetRTX<UserKey>\n>({\n\tkey: `usersIndex`,\n\tclass: SetRTX,\n})\nexport const usersOfSockets: JoinToken<\n\t`user`,\n\tUserKey,\n\t`socket`,\n\tSocketKey,\n\t`1:1`\n> = join({\n\tkey: `usersOfSockets`,\n\tbetween: [`user`, `socket`],\n\tcardinality: `1:1`,\n\tisAType: (s): s is UserKey => s.startsWith(`user::`),\n\tisBType: (s): s is SocketKey => s.startsWith(`socket::`),\n})\n\nexport const userMutualSituationalAwarenessIndexes: PureSelectorFamilyToken<\n\tUserKey[],\n\tUserKey\n> = selectorFamily<UserKey[], UserKey>({\n\tkey: `userMutualSituationalAwarenessIndexes`,\n\tget: (userId) => () => {\n\t\treturn [userId]\n\t},\n})\n","import type * as AtomIO from \"atom.io\"\nimport { getFromStore, IMPLICIT, subscribeToState } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { ServerConfig } from \".\"\nimport { employSocket } from \"./employ-socket\"\n\nexport type StateProvider = ReturnType<typeof realtimeStateProvider>\nexport function realtimeStateProvider({\n\tsocket,\n\tstore = IMPLICIT.STORE,\n}: ServerConfig) {\n\treturn function stateProvider<J extends Json.Serializable>(\n\t\ttoken: AtomIO.WritableToken<J>,\n\t): () => void {\n\t\tconst subscriptions = new Set<() => void>()\n\t\tconst clearSubscriptions = () => {\n\t\t\tfor (const unsub of subscriptions) unsub()\n\t\t\tsubscriptions.clear()\n\t\t}\n\n\t\tconst start = () => {\n\t\t\tsubscriptions.add(\n\t\t\t\temploySocket(socket, `sub:${token.key}`, () => {\n\t\t\t\t\tclearSubscriptions()\n\t\t\t\t\tsocket.emit(`serve:${token.key}`, getFromStore(store, token))\n\t\t\t\t\tsubscriptions.add(\n\t\t\t\t\t\tsubscribeToState(\n\t\t\t\t\t\t\tstore,\n\t\t\t\t\t\t\ttoken,\n\t\t\t\t\t\t\t`expose-single:${socket.id}`,\n\t\t\t\t\t\t\t({ newValue }) => {\n\t\t\t\t\t\t\t\tsocket.emit(`serve:${token.key}`, newValue)\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t),\n\t\t\t\t\t)\n\t\t\t\t\tsubscriptions.add(\n\t\t\t\t\t\temploySocket(socket, `unsub:${token.key}`, () => {\n\t\t\t\t\t\t\tclearSubscriptions()\n\t\t\t\t\t\t\tstart()\n\t\t\t\t\t\t}),\n\t\t\t\t\t)\n\t\t\t\t}),\n\t\t\t)\n\t\t}\n\n\t\tstart()\n\n\t\treturn clearSubscriptions\n\t}\n}\n","import type { WritableToken } from \"atom.io\"\nimport {\n\tfindInStore,\n\tgetFromStore,\n\tIMPLICIT,\n\tsetIntoStore,\n\tsubscribeToState,\n} from \"atom.io/internal\"\nimport {\n\toperateOnStore,\n\tOWN_OP,\n} from \"atom.io/internal/set-state/operate-on-store\"\nimport type { Json } from \"atom.io/json\"\nimport { mutexAtoms } from \"atom.io/realtime/mutex-store\"\n\nimport type { ServerConfig } from \".\"\nimport { employSocket } from \"./employ-socket\"\n\nexport type StateReceiver = ReturnType<typeof realtimeStateReceiver>\nexport function realtimeStateReceiver({\n\tsocket,\n\tstore = IMPLICIT.STORE,\n}: ServerConfig) {\n\treturn function stateReceiver<S extends Json.Serializable, C extends S>(\n\t\tclientToken: WritableToken<C>,\n\t\tserverToken: WritableToken<S> = clientToken,\n\t): () => void {\n\t\tconst mutexAtom = findInStore(store, mutexAtoms, serverToken.key)\n\n\t\tconst subscriptions = new Set<() => void>()\n\t\tconst clearSubscriptions = () => {\n\t\t\tfor (const unsub of subscriptions) unsub()\n\t\t\tsubscriptions.clear()\n\t\t}\n\n\t\tconst permitPublish = () => {\n\t\t\tclearSubscriptions()\n\t\t\tsubscriptions.add(\n\t\t\t\temploySocket(socket, `pub:${clientToken.key}`, (newValue) => {\n\t\t\t\t\tsetIntoStore(store, serverToken, newValue as C)\n\t\t\t\t}),\n\t\t\t)\n\t\t\tsubscriptions.add(\n\t\t\t\temploySocket(socket, `unclaim:${clientToken.key}`, () => {\n\t\t\t\t\tsetIntoStore(store, mutexAtom, false)\n\t\t\t\t\tclearSubscriptions()\n\t\t\t\t\tstart()\n\t\t\t\t}),\n\t\t\t)\n\t\t}\n\n\t\tconst start = () => {\n\t\t\tsubscriptions.add(\n\t\t\t\temploySocket(socket, `claim:${clientToken.key}`, () => {\n\t\t\t\t\tif (getFromStore(store, mutexAtom)) {\n\t\t\t\t\t\tclearSubscriptions()\n\t\t\t\t\t\tsubscriptions.add(\n\t\t\t\t\t\t\tsubscribeToState(store, mutexAtom, socket.id!, () => {\n\t\t\t\t\t\t\t\tconst currentValue = getFromStore(store, mutexAtom)\n\t\t\t\t\t\t\t\tif (currentValue === false) {\n\t\t\t\t\t\t\t\t\toperateOnStore(OWN_OP, store, mutexAtom, true)\n\t\t\t\t\t\t\t\t\tpermitPublish()\n\t\t\t\t\t\t\t\t\tsocket.emit(`claim-result:${clientToken.key}`, true)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t)\n\t\t\t\t\t\tsocket.emit(`claim-result:${clientToken.key}`, false)\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t\tsetIntoStore(store, mutexAtom, true)\n\t\t\t\t\tpermitPublish()\n\t\t\t\t\tsocket.emit(`claim-result:${clientToken.key}`, true)\n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,CACF;;AAGF,SAAO;AAEP,SAAO"}
@@ -1,20 +1,21 @@
1
1
  import * as AtomIO from "atom.io";
2
2
  import * as React$1 from "react";
3
3
  import { RenderResult } from "@testing-library/react";
4
+ import * as RTS from "atom.io/realtime-server";
4
5
  import * as SocketIO from "socket.io";
5
- import { Socket } from "socket.io-client";
6
+ import { Socket as Socket$1 } from "socket.io-client";
6
7
 
7
8
  //#region src/realtime-testing/setup-realtime-test.d.ts
8
9
  type TestSetupOptions = {
9
- port: number;
10
10
  immortal?: {
11
11
  server?: boolean;
12
12
  };
13
13
  server: (tools: {
14
14
  socket: SocketIO.Socket;
15
15
  silo: AtomIO.Silo;
16
+ userKey: RTS.UserKey;
16
17
  enableLogging: () => void;
17
- }) => void;
18
+ }) => (() => void) | void;
18
19
  };
19
20
  type TestSetupOptions__SingleClient = TestSetupOptions & {
20
21
  client: React$1.FC;
@@ -30,7 +31,7 @@ type RealtimeTestClient = RealtimeTestTools & {
30
31
  renderResult: RenderResult;
31
32
  prettyPrint: () => void;
32
33
  enableLogging: () => void;
33
- socket: Socket;
34
+ socket: Socket$1;
34
35
  };
35
36
  type RealtimeTestClientBuilder = {
36
37
  dispose: () => void;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/realtime-testing/setup-realtime-test.tsx"],"sourcesContent":[],"mappings":";;;;;;;KA6CY,gBAAA;;EAAZ,QAAY,CAAA,EAAA;IAAA,MAAA,CAAA,EAAA,OAAA;;QAKJ,EAAA,CAAA,KAAO,EAAA;YADL,QAAA,CAAS;IAKnB,IAAY,EAJJ,MAAA,CAAO,IAIH;IAAA,aAAA,EAAA,GAAA,GAAA,IAAA;QAAiC,IAAA;;KAAjC,8BAAA,GAAiC;EAG7C,MAAY,EAFH,OAAA,CAAM,EAEH;CAAA;AACX,KADW,6BACX,CAAA,oBAAA,MAAA,CAAA,GAAA,gBAAA,GAAA;SAEQ,EAAA,QAAA,WAAA,GAAc,OAAA,CAAM,EAApB,EAAA;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AAA,CAAA,OAAA,EA0GrB,8BA1GqB,EAAA,IAAA,EAAA,MAAA,EAAA,IAAA,EAAA,MAAA,EAAA,GA6G5B,yBA7G4B;AAApB,cAoKE,YApKF,EAAA,CAAA,OAAA,EAqKD,8BArKC,EAAA,GAsKR,6BAtKQ;AAAA,cAoLE,WApLF,EAAA,CAAA,oBAAA,MAAA,CAAA,CAAA,OAAA,EAqLD,6BArLC,CAqL6B,WArL7B,CAAA,EAAA,GAsLR,4BAtLQ,CAsLqB,WAtLrB,CAAA"}
@@ -1,11 +1,12 @@
1
1
  import { IMPLICIT, clearStore, editRelationsInStore, findInStore, findRelationsInStore, getFromStore, setIntoStore } from "atom.io/internal";
2
- import { toEntries } from "atom.io/json";
3
2
  import * as AtomIO from "atom.io";
3
+ import { toEntries } from "atom.io/json";
4
+ import { SetRTX } from "atom.io/transceivers/set-rtx";
4
5
  import "react";
5
6
  import { jsx } from "react/jsx-runtime";
6
7
  import * as AR from "atom.io/react";
7
8
  import * as RTC from "atom.io/realtime-client";
8
- import * as RT from "atom.io/realtime";
9
+ import { ChildProcess } from "node:child_process";
9
10
  import * as http from "node:http";
10
11
  import { prettyDOM, render } from "@testing-library/react";
11
12
  import * as RTR from "atom.io/realtime-react";
@@ -17,15 +18,25 @@ import { io } from "socket.io-client";
17
18
  //#region src/realtime-testing/setup-realtime-test.tsx
18
19
  let testNumber = 0;
19
20
  function prefixLogger(store, prefix) {
20
- store.loggers[0] = new AtomIO.AtomIOLogger(`info`, void 0, {
21
- info: (...args) => {
22
- console.info(prefix, ...args);
21
+ store.loggers[0] = new AtomIO.AtomIOLogger(`info`, (...params) => {
22
+ let idx = 0;
23
+ for (const param of params) {
24
+ if (param instanceof SocketIO.Socket) params[idx] = `Socket:${param.id}`;
25
+ if (param instanceof RTS.ChildSocket) params[idx] = `ChildSocket:${param.id}`;
26
+ if (param instanceof ChildProcess) params[idx] = `ChildProcess:${param.pid}`;
27
+ if (param instanceof SetRTX) params[idx] = `SetRTX(${param.size}) {${[...param].join(`, `)}} at ${param.cacheIdx}`;
28
+ idx++;
29
+ }
30
+ return params;
31
+ }, {
32
+ info: (...params) => {
33
+ console.info(prefix, ...params);
23
34
  },
24
- warn: (...args) => {
25
- console.warn(prefix, ...args);
35
+ warn: (...params) => {
36
+ console.warn(prefix, ...params);
26
37
  },
27
- error: (...args) => {
28
- console.error(prefix, ...args);
38
+ error: (...params) => {
39
+ console.error(prefix, ...params);
29
40
  }
30
41
  });
31
42
  }
@@ -37,7 +48,7 @@ const setupRealtimeTestServer = (options) => {
37
48
  }, IMPLICIT.STORE);
38
49
  const socketRealm = new AtomIO.Realm(silo.store);
39
50
  const httpServer = http.createServer((_, res) => res.end(`Hello World!`));
40
- const address = httpServer.listen(options.port).address();
51
+ const address = httpServer.listen().address();
41
52
  const port = typeof address === `string` ? null : address === null ? null : address.port;
42
53
  if (port === null) throw new Error(`Could not determine port for test server`);
43
54
  const server = new SocketIO.Server(httpServer).use((socket, next) => {
@@ -55,11 +66,14 @@ const setupRealtimeTestServer = (options) => {
55
66
  next();
56
67
  } else next(/* @__PURE__ */ new Error(`Authentication error`));
57
68
  });
69
+ const socketServices = /* @__PURE__ */ new Set();
70
+ const disposeAllSocketServices = () => {
71
+ for (const disposeService of socketServices) disposeService();
72
+ };
58
73
  server.on(`connection`, (socket) => {
59
- let userKey = null;
74
+ const userKeyState = findRelationsInStore(RTS.usersOfSockets, `socket::${socket.id}`, silo.store).userKeyOfSocket;
75
+ const userKey = getFromStore(silo.store, userKeyState);
60
76
  function enableLogging() {
61
- const userKeyState = findRelationsInStore(RTS.usersOfSockets, `socket::${socket.id}`, silo.store).userKeyOfSocket;
62
- userKey = getFromStore(silo.store, userKeyState);
63
77
  prefixLogger(silo.store, `server`);
64
78
  socket.onAny((event, ...args) => {
65
79
  console.log(`🛰 `, userKey, event, ...args);
@@ -71,20 +85,20 @@ const setupRealtimeTestServer = (options) => {
71
85
  console.log(`${userKey} disconnected`);
72
86
  });
73
87
  }
74
- options.server({
88
+ const disposeServices = options.server({
75
89
  socket,
76
90
  enableLogging,
77
- silo
91
+ silo,
92
+ userKey
78
93
  });
94
+ if (disposeServices) {
95
+ socketServices.add(disposeServices);
96
+ socket.on(`disconnect`, disposeServices);
97
+ }
79
98
  });
80
99
  const dispose = async () => {
100
+ disposeAllSocketServices();
81
101
  await server.close();
82
- const roomKeys = getFromStore(silo.store, RT.roomIndex);
83
- for (const roomKey of roomKeys) {
84
- const roomState = findInStore(silo.store, RTS.roomSelectors, roomKey);
85
- const room = getFromStore(silo.store, roomState);
86
- if (room && !(room instanceof Promise)) room.process.kill();
87
- }
88
102
  silo.store.valueMap.clear();
89
103
  };
90
104
  return {
@@ -119,7 +133,6 @@ const setupRealtimeTestClient = (options, name, port) => {
119
133
  console.log(prettyDOM(renderResult.container));
120
134
  };
121
135
  const enableLogging = () => {
122
- prefixLogger(silo.store, name);
123
136
  socket.onAny((event, ...args) => {
124
137
  console.log(`📡 `, name, event, ...args);
125
138
  });
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["userKey: string | null","socket: ClientSocket"],"sources":["../../src/realtime-testing/setup-realtime-test.tsx"],"sourcesContent":["import * as http from \"node:http\"\n\nimport type { RenderResult } from \"@testing-library/react\"\nimport { prettyDOM, render } from \"@testing-library/react\"\nimport * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport {\n\tclearStore,\n\teditRelationsInStore,\n\tfindInStore,\n\tfindRelationsInStore,\n\tgetFromStore,\n\tIMPLICIT,\n\tsetIntoStore,\n} from \"atom.io/internal\"\nimport { toEntries } from \"atom.io/json\"\nimport * as AR from \"atom.io/react\"\nimport * as RT from \"atom.io/realtime\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as RTR from \"atom.io/realtime-react\"\nimport * as RTS from \"atom.io/realtime-server\"\nimport * as Happy from \"happy-dom\"\nimport * as React from \"react\"\nimport * as SocketIO from \"socket.io\"\nimport type { Socket as ClientSocket } from \"socket.io-client\"\nimport { io } from \"socket.io-client\"\n\nlet testNumber = 0\n\n/* eslint-disable no-console */\n\nfunction prefixLogger(store: Store, prefix: string) {\n\tstore.loggers[0] = new AtomIO.AtomIOLogger(`info`, undefined, {\n\t\tinfo: (...args) => {\n\t\t\tconsole.info(prefix, ...args)\n\t\t},\n\t\twarn: (...args) => {\n\t\t\tconsole.warn(prefix, ...args)\n\t\t},\n\t\terror: (...args) => {\n\t\t\tconsole.error(prefix, ...args)\n\t\t},\n\t})\n}\n\nexport type TestSetupOptions = {\n\tport: number\n\timmortal?: { server?: boolean }\n\tserver: (tools: {\n\t\tsocket: SocketIO.Socket\n\t\tsilo: AtomIO.Silo\n\t\tenableLogging: () => void\n\t}) => void\n}\nexport type TestSetupOptions__SingleClient = TestSetupOptions & {\n\tclient: React.FC\n}\nexport type TestSetupOptions__MultiClient<ClientNames extends string> =\n\tTestSetupOptions & {\n\t\tclients: {\n\t\t\t[K in ClientNames]: React.FC\n\t\t}\n\t}\n\nexport type RealtimeTestTools = {\n\tname: string\n\tsilo: AtomIO.Silo\n}\nexport type RealtimeTestClient = RealtimeTestTools & {\n\trenderResult: RenderResult\n\tprettyPrint: () => void\n\tenableLogging: () => void\n\tsocket: ClientSocket\n}\nexport type RealtimeTestClientBuilder = {\n\tdispose: () => void\n\tinit: () => RealtimeTestClient\n}\n\nexport type RealtimeTestServer = RealtimeTestTools & {\n\tdispose: () => Promise<void>\n\tport: number\n}\n\nexport type RealtimeTestAPI = {\n\tserver: RealtimeTestServer\n\tteardown: () => Promise<void>\n}\nexport type RealtimeTestAPI__SingleClient = RealtimeTestAPI & {\n\tclient: RealtimeTestClientBuilder\n}\nexport type RealtimeTestAPI__MultiClient<ClientNames extends string> =\n\tRealtimeTestAPI & {\n\t\tclients: Record<ClientNames, RealtimeTestClientBuilder>\n\t}\n\nexport const setupRealtimeTestServer = (\n\toptions: TestSetupOptions,\n): RealtimeTestServer => {\n\t++testNumber\n\tconst silo = new AtomIO.Silo(\n\t\t{\n\t\t\tname: `SERVER-${testNumber}`,\n\t\t\tlifespan: options.immortal?.server ? `immortal` : `ephemeral`,\n\t\t},\n\t\tIMPLICIT.STORE,\n\t)\n\tconst socketRealm = new AtomIO.Realm<RTS.SocketSystemHierarchy>(silo.store)\n\n\tconst httpServer = http.createServer((_, res) => res.end(`Hello World!`))\n\tconst address = httpServer.listen(options.port).address()\n\tconst port =\n\t\ttypeof address === `string` ? null : address === null ? null : address.port\n\tif (port === null) throw new Error(`Could not determine port for test server`)\n\n\tconst server = new SocketIO.Server(httpServer).use((socket, next) => {\n\t\tconst { token, username } = socket.handshake.auth\n\t\tif (token === `test` && socket.id) {\n\t\t\tconst userClaim = socketRealm.allocate(`root`, `user::${username}`)\n\t\t\tconst socketClaim = socketRealm.allocate(`root`, `socket::${socket.id}`)\n\t\t\tconst socketState = findInStore(silo.store, RTS.socketAtoms, socketClaim)\n\t\t\tsetIntoStore(silo.store, socketState, socket)\n\t\t\teditRelationsInStore(\n\t\t\t\tRTS.usersOfSockets,\n\t\t\t\t(relations) => {\n\t\t\t\t\trelations.set(userClaim, socketClaim)\n\t\t\t\t},\n\t\t\t\tsilo.store,\n\t\t\t)\n\t\t\tsetIntoStore(silo.store, RTS.userIndex, (index) => index.add(userClaim))\n\t\t\tsetIntoStore(silo.store, RTS.socketIndex, (index) =>\n\t\t\t\tindex.add(socketClaim),\n\t\t\t)\n\t\t\t// console.log(`${username} connected on ${socket.id}`)\n\t\t\tnext()\n\t\t} else {\n\t\t\tnext(new Error(`Authentication error`))\n\t\t}\n\t})\n\n\tserver.on(`connection`, (socket: SocketIO.Socket) => {\n\t\tlet userKey: string | null = null\n\t\tfunction enableLogging() {\n\t\t\tconst userKeyState = findRelationsInStore(\n\t\t\t\tRTS.usersOfSockets,\n\t\t\t\t`socket::${socket.id}`,\n\t\t\t\tsilo.store,\n\t\t\t).userKeyOfSocket\n\t\t\tuserKey = getFromStore(silo.store, userKeyState)\n\t\t\tprefixLogger(silo.store, `server`)\n\t\t\tsocket.onAny((event, ...args) => {\n\t\t\t\tconsole.log(`🛰 `, userKey, event, ...args)\n\t\t\t})\n\t\t\tsocket.onAnyOutgoing((event, ...args) => {\n\t\t\t\tconsole.log(`🛰 >>`, userKey, event, ...args)\n\t\t\t})\n\t\t\tsocket.on(`disconnect`, () => {\n\t\t\t\tconsole.log(`${userKey} disconnected`)\n\t\t\t})\n\t\t}\n\t\toptions.server({ socket, enableLogging, silo })\n\t})\n\n\tconst dispose = async () => {\n\t\tawait server.close()\n\t\tconst roomKeys = getFromStore(silo.store, RT.roomIndex)\n\t\tfor (const roomKey of roomKeys) {\n\t\t\tconst roomState = findInStore(silo.store, RTS.roomSelectors, roomKey)\n\t\t\tconst room = getFromStore(silo.store, roomState)\n\t\t\tif (room && !(room instanceof Promise)) {\n\t\t\t\troom.process.kill()\n\t\t\t}\n\t\t}\n\t\tsilo.store.valueMap.clear()\n\t}\n\n\treturn {\n\t\tname: `SERVER`,\n\t\tsilo,\n\t\tdispose,\n\t\tport,\n\t}\n}\nexport const setupRealtimeTestClient = (\n\toptions: TestSetupOptions__SingleClient,\n\tname: string,\n\tport: number,\n): RealtimeTestClientBuilder => {\n\tconst testClient = { dispose: () => {} }\n\tconst init = () => {\n\t\tconst socket: ClientSocket = io(`http://localhost:${port}/`, {\n\t\t\tauth: { token: `test`, username: `${name}-${testNumber}` },\n\t\t})\n\t\tconst silo = new AtomIO.Silo({ name, lifespan: `ephemeral` }, IMPLICIT.STORE)\n\t\tsilo.setState(RTC.myUsernameState, `${name}-${testNumber}`)\n\n\t\tconst { document } = new Happy.Window()\n\t\tdocument.body.innerHTML = `<div id=\"app\"></div>`\n\t\tconst renderResult = render(\n\t\t\t<AR.StoreProvider store={silo.store}>\n\t\t\t\t<RTR.RealtimeProvider socket={socket}>\n\t\t\t\t\t<options.client />\n\t\t\t\t</RTR.RealtimeProvider>\n\t\t\t</AR.StoreProvider>,\n\t\t\t{\n\t\t\t\tcontainer: document.querySelector(`#app`) as unknown as HTMLElement,\n\t\t\t},\n\t\t)\n\n\t\tconst prettyPrint = () => {\n\t\t\tconsole.log(prettyDOM(renderResult.container))\n\t\t}\n\n\t\tconst enableLogging = () => {\n\t\t\tprefixLogger(silo.store, name)\n\t\t\tsocket.onAny((event, ...args) => {\n\t\t\t\tconsole.log(`📡 `, name, event, ...args)\n\t\t\t})\n\t\t\tsocket.onAnyOutgoing((event, ...args) => {\n\t\t\t\tconsole.log(`📡 >>`, name, event, ...args)\n\t\t\t})\n\t\t}\n\n\t\tconst dispose = () => {\n\t\t\trenderResult.unmount()\n\t\t\tsocket.disconnect()\n\t\t\tclearStore(silo.store)\n\t\t}\n\t\ttestClient.dispose = dispose\n\n\t\treturn {\n\t\t\tname,\n\t\t\tsilo,\n\t\t\tsocket,\n\t\t\trenderResult,\n\t\t\tprettyPrint,\n\t\t\tenableLogging,\n\t\t}\n\t}\n\treturn Object.assign(testClient, { init })\n}\n\nexport const singleClient = (\n\toptions: TestSetupOptions__SingleClient,\n): RealtimeTestAPI__SingleClient => {\n\tconst server = setupRealtimeTestServer(options)\n\tconst client = setupRealtimeTestClient(options, `CLIENT`, server.port)\n\n\treturn {\n\t\tclient,\n\t\tserver,\n\t\tteardown: async () => {\n\t\t\tawait server.dispose()\n\t\t\tclient.dispose()\n\t\t},\n\t}\n}\n\nexport const multiClient = <ClientNames extends string>(\n\toptions: TestSetupOptions__MultiClient<ClientNames>,\n): RealtimeTestAPI__MultiClient<ClientNames> => {\n\tconst server = setupRealtimeTestServer(options)\n\tconst clients = toEntries(options.clients).reduce(\n\t\t(clientRecord, [name, client]) => {\n\t\t\tclientRecord[name] = setupRealtimeTestClient(\n\t\t\t\t{ ...options, client },\n\t\t\t\tname,\n\t\t\t\tserver.port,\n\t\t\t)\n\t\t\treturn clientRecord\n\t\t},\n\t\t{} as Record<ClientNames, RealtimeTestClientBuilder>,\n\t)\n\n\treturn {\n\t\tclients,\n\t\tserver,\n\t\tteardown: async () => {\n\t\t\tawait server.dispose()\n\t\t\tfor (const [, client] of toEntries(clients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M,eAAe,OACpB,oBAAC,GAAG;GAAc,OAAO,KAAK;aAC7B,oBAAC,IAAI;IAAyB;cAC7B,oBAAC,QAAQ;;MAGX,EACC,WAAW,SAAS,cAAc;EAIpC,MAAM,oBAAoB;AACzB,WAAQ,IAAI,UAAU,aAAa;;EAGpC,MAAM,sBAAsB;AAC3B,gBAAa,KAAK,OAAO;AACzB,UAAO,OAAO,OAAO,GAAG,SAAS;AAChC,YAAQ,IAAI,OAAO,MAAM,OAAO,GAAG;;AAEpC,UAAO,eAAe,OAAO,GAAG,SAAS;AACxC,YAAQ,IAAI,UAAU,MAAM,OAAO,GAAG;;;EAIxC,MAAM,gBAAgB;AACrB,gBAAa;AACb,UAAO;AACP,cAAW,KAAK;;AAEjB,aAAW,UAAU;AAErB,SAAO;GACN;GACA;GACA;GACA;GACA;GACA;;;AAGF,QAAO,OAAO,OAAO,YAAY,EAAE;;AAGpC,MAAa,gBACZ,YACmC;CACnC,MAAM,SAAS,wBAAwB;CACvC,MAAM,SAAS,wBAAwB,SAAS,UAAU,OAAO;AAEjE,QAAO;EACN;EACA;EACA,UAAU,YAAY;AACrB,SAAM,OAAO;AACb,UAAO;;;;AAKV,MAAa,eACZ,YAC+C;CAC/C,MAAM,SAAS,wBAAwB;CACvC,MAAM,UAAU,UAAU,QAAQ,SAAS,QACzC,cAAc,CAAC,MAAM,YAAY;AACjC,eAAa,QAAQ,wBACpB;GAAE,GAAG;GAAS;KACd,MACA,OAAO;AAER,SAAO;IAER;AAGD,QAAO;EACN;EACA;EACA,UAAU,YAAY;AACrB,SAAM,OAAO;AACb,QAAK,MAAM,GAAG,WAAW,UAAU,SAClC,QAAO"}
1
+ {"version":3,"file":"index.js","names":["socket: ClientSocket"],"sources":["../../src/realtime-testing/setup-realtime-test.tsx"],"sourcesContent":["import { ChildProcess } from \"node:child_process\"\nimport * as http from \"node:http\"\n\nimport type { RenderResult } from \"@testing-library/react\"\nimport { prettyDOM, render } from \"@testing-library/react\"\nimport * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport {\n\tclearStore,\n\teditRelationsInStore,\n\tfindInStore,\n\tfindRelationsInStore,\n\tgetFromStore,\n\tIMPLICIT,\n\tsetIntoStore,\n} from \"atom.io/internal\"\nimport { toEntries } from \"atom.io/json\"\nimport * as AR from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as RTR from \"atom.io/realtime-react\"\nimport * as RTS from \"atom.io/realtime-server\"\nimport { SetRTX } from \"atom.io/transceivers/set-rtx\"\nimport * as Happy from \"happy-dom\"\nimport * as React from \"react\"\nimport * as SocketIO from \"socket.io\"\nimport type { Socket as ClientSocket } from \"socket.io-client\"\nimport { io } from \"socket.io-client\"\n\nlet testNumber = 0\n\n/* eslint-disable no-console */\n\nfunction prefixLogger(store: Store, prefix: string) {\n\tstore.loggers[0] = new AtomIO.AtomIOLogger(\n\t\t`info`,\n\t\t(...params) => {\n\t\t\tlet idx = 0\n\t\t\tfor (const param of params) {\n\t\t\t\tif (param instanceof SocketIO.Socket) {\n\t\t\t\t\tparams[idx] = `Socket:${param.id}`\n\t\t\t\t}\n\t\t\t\tif (param instanceof RTS.ChildSocket) {\n\t\t\t\t\tparams[idx] = `ChildSocket:${param.id}`\n\t\t\t\t}\n\t\t\t\tif (param instanceof ChildProcess) {\n\t\t\t\t\tparams[idx] = `ChildProcess:${param.pid}`\n\t\t\t\t}\n\t\t\t\tif (param instanceof SetRTX) {\n\t\t\t\t\tparams[idx] =\n\t\t\t\t\t\t`SetRTX(${param.size}) {${[...param].join(`, `)}} at ${param.cacheIdx}`\n\t\t\t\t}\n\t\t\t\tidx++\n\t\t\t}\n\t\t\treturn params\n\t\t},\n\t\t{\n\t\t\tinfo: (...params) => {\n\t\t\t\tconsole.info(prefix, ...params)\n\t\t\t},\n\t\t\twarn: (...params) => {\n\t\t\t\tconsole.warn(prefix, ...params)\n\t\t\t},\n\t\t\terror: (...params) => {\n\t\t\t\tconsole.error(prefix, ...params)\n\t\t\t},\n\t\t},\n\t)\n}\n\nexport type TestSetupOptions = {\n\timmortal?: { server?: boolean }\n\tserver: (tools: {\n\t\tsocket: SocketIO.Socket\n\t\tsilo: AtomIO.Silo\n\t\tuserKey: RTS.UserKey\n\t\tenableLogging: () => void\n\t}) => (() => void) | void\n}\nexport type TestSetupOptions__SingleClient = TestSetupOptions & {\n\tclient: React.FC\n}\nexport type TestSetupOptions__MultiClient<ClientNames extends string> =\n\tTestSetupOptions & {\n\t\tclients: {\n\t\t\t[K in ClientNames]: React.FC\n\t\t}\n\t}\n\nexport type RealtimeTestTools = {\n\tname: string\n\tsilo: AtomIO.Silo\n}\nexport type RealtimeTestClient = RealtimeTestTools & {\n\trenderResult: RenderResult\n\tprettyPrint: () => void\n\tenableLogging: () => void\n\tsocket: ClientSocket\n}\nexport type RealtimeTestClientBuilder = {\n\tdispose: () => void\n\tinit: () => RealtimeTestClient\n}\n\nexport type RealtimeTestServer = RealtimeTestTools & {\n\tdispose: () => Promise<void>\n\tport: number\n}\n\nexport type RealtimeTestAPI = {\n\tserver: RealtimeTestServer\n\tteardown: () => Promise<void>\n}\nexport type RealtimeTestAPI__SingleClient = RealtimeTestAPI & {\n\tclient: RealtimeTestClientBuilder\n}\nexport type RealtimeTestAPI__MultiClient<ClientNames extends string> =\n\tRealtimeTestAPI & {\n\t\tclients: Record<ClientNames, RealtimeTestClientBuilder>\n\t}\n\nexport const setupRealtimeTestServer = (\n\toptions: TestSetupOptions,\n): RealtimeTestServer => {\n\t++testNumber\n\tconst silo = new AtomIO.Silo(\n\t\t{\n\t\t\tname: `SERVER-${testNumber}`,\n\t\t\tlifespan: options.immortal?.server ? `immortal` : `ephemeral`,\n\t\t},\n\t\tIMPLICIT.STORE,\n\t)\n\t// prefixLogger(silo.store, `server`)\n\tconst socketRealm = new AtomIO.Realm<RTS.SocketSystemHierarchy>(silo.store)\n\n\tconst httpServer = http.createServer((_, res) => res.end(`Hello World!`))\n\tconst address = httpServer.listen().address()\n\tconst port =\n\t\ttypeof address === `string` ? null : address === null ? null : address.port\n\tif (port === null) throw new Error(`Could not determine port for test server`)\n\n\tconst server = new SocketIO.Server(httpServer).use((socket, next) => {\n\t\tconst { token, username } = socket.handshake.auth\n\t\tif (token === `test` && socket.id) {\n\t\t\tconst userClaim = socketRealm.allocate(`root`, `user::${username}`)\n\t\t\tconst socketClaim = socketRealm.allocate(`root`, `socket::${socket.id}`)\n\t\t\tconst socketState = findInStore(silo.store, RTS.socketAtoms, socketClaim)\n\t\t\tsetIntoStore(silo.store, socketState, socket)\n\t\t\teditRelationsInStore(\n\t\t\t\tRTS.usersOfSockets,\n\t\t\t\t(relations) => {\n\t\t\t\t\trelations.set(userClaim, socketClaim)\n\t\t\t\t},\n\t\t\t\tsilo.store,\n\t\t\t)\n\t\t\tsetIntoStore(silo.store, RTS.userIndex, (index) => index.add(userClaim))\n\t\t\tsetIntoStore(silo.store, RTS.socketIndex, (index) =>\n\t\t\t\tindex.add(socketClaim),\n\t\t\t)\n\t\t\tnext()\n\t\t} else {\n\t\t\tnext(new Error(`Authentication error`))\n\t\t}\n\t})\n\n\tconst socketServices = new Set<() => void>()\n\tconst disposeAllSocketServices = () => {\n\t\tfor (const disposeService of socketServices) disposeService()\n\t}\n\n\tserver.on(`connection`, (socket: SocketIO.Socket) => {\n\t\tconst userKeyState = findRelationsInStore(\n\t\t\tRTS.usersOfSockets,\n\t\t\t`socket::${socket.id}`,\n\t\t\tsilo.store,\n\t\t).userKeyOfSocket\n\t\tconst userKey = getFromStore(silo.store, userKeyState)!\n\t\tfunction enableLogging() {\n\t\t\tprefixLogger(silo.store, `server`)\n\t\t\tsocket.onAny((event, ...args) => {\n\t\t\t\tconsole.log(`🛰 `, userKey, event, ...args)\n\t\t\t})\n\t\t\tsocket.onAnyOutgoing((event, ...args) => {\n\t\t\t\tconsole.log(`🛰 >>`, userKey, event, ...args)\n\t\t\t})\n\t\t\tsocket.on(`disconnect`, () => {\n\t\t\t\tconsole.log(`${userKey} disconnected`)\n\t\t\t})\n\t\t}\n\t\tconst disposeServices = options.server({\n\t\t\tsocket,\n\t\t\tenableLogging,\n\t\t\tsilo,\n\t\t\tuserKey,\n\t\t})\n\t\tif (disposeServices) {\n\t\t\tsocketServices.add(disposeServices)\n\t\t\tsocket.on(`disconnect`, disposeServices)\n\t\t}\n\t})\n\n\tconst dispose = async () => {\n\t\tdisposeAllSocketServices()\n\t\tawait server.close()\n\n\t\t// const roomKeys = getFromStore(silo.store, RT.roomIndex)\n\t\t// for (const roomKey of roomKeys) {\n\t\t// \tconst roomState = findInStore(silo.store, RTS.roomSelectors, roomKey)\n\t\t// \tconst room = getFromStore(silo.store, roomState)\n\t\t// \tif (room && !(room instanceof Promise)) {\n\t\t// \t\troom.process.kill()\n\t\t// \t}\n\t\t// } // ❗ POSSIBLY STILL NEEDED\n\t\tsilo.store.valueMap.clear()\n\t}\n\n\treturn {\n\t\tname: `SERVER`,\n\t\tsilo,\n\t\tdispose,\n\t\tport,\n\t}\n}\nexport const setupRealtimeTestClient = (\n\toptions: TestSetupOptions__SingleClient,\n\tname: string,\n\tport: number,\n): RealtimeTestClientBuilder => {\n\tconst testClient = { dispose: () => {} }\n\tconst init = () => {\n\t\tconst socket: ClientSocket = io(`http://localhost:${port}/`, {\n\t\t\tauth: { token: `test`, username: `${name}-${testNumber}` },\n\t\t})\n\t\tconst silo = new AtomIO.Silo({ name, lifespan: `ephemeral` }, IMPLICIT.STORE)\n\t\tsilo.setState(RTC.myUsernameState, `${name}-${testNumber}`)\n\n\t\tconst { document } = new Happy.Window()\n\t\tdocument.body.innerHTML = `<div id=\"app\"></div>`\n\t\tconst renderResult = render(\n\t\t\t<AR.StoreProvider store={silo.store}>\n\t\t\t\t<RTR.RealtimeProvider socket={socket}>\n\t\t\t\t\t<options.client />\n\t\t\t\t</RTR.RealtimeProvider>\n\t\t\t</AR.StoreProvider>,\n\t\t\t{\n\t\t\t\tcontainer: document.querySelector(`#app`) as unknown as HTMLElement,\n\t\t\t},\n\t\t)\n\n\t\tconst prettyPrint = () => {\n\t\t\tconsole.log(prettyDOM(renderResult.container))\n\t\t}\n\n\t\tconst enableLogging = () => {\n\t\t\t// prefixLogger(silo.store, name)\n\t\t\tsocket.onAny((event, ...args) => {\n\t\t\t\tconsole.log(`📡 `, name, event, ...args)\n\t\t\t})\n\t\t\tsocket.onAnyOutgoing((event, ...args) => {\n\t\t\t\tconsole.log(`📡 >>`, name, event, ...args)\n\t\t\t})\n\t\t}\n\n\t\tconst dispose = () => {\n\t\t\trenderResult.unmount()\n\t\t\tsocket.disconnect()\n\t\t\tclearStore(silo.store)\n\t\t}\n\t\ttestClient.dispose = dispose\n\n\t\treturn {\n\t\t\tname,\n\t\t\tsilo,\n\t\t\tsocket,\n\t\t\trenderResult,\n\t\t\tprettyPrint,\n\t\t\tenableLogging,\n\t\t}\n\t}\n\treturn Object.assign(testClient, { init })\n}\n\nexport const singleClient = (\n\toptions: TestSetupOptions__SingleClient,\n): RealtimeTestAPI__SingleClient => {\n\tconst server = setupRealtimeTestServer(options)\n\tconst client = setupRealtimeTestClient(options, `CLIENT`, server.port)\n\n\treturn {\n\t\tclient,\n\t\tserver,\n\t\tteardown: async () => {\n\t\t\tawait server.dispose()\n\t\t\tclient.dispose()\n\t\t},\n\t}\n}\n\nexport const multiClient = <ClientNames extends string>(\n\toptions: TestSetupOptions__MultiClient<ClientNames>,\n): RealtimeTestAPI__MultiClient<ClientNames> => {\n\tconst server = setupRealtimeTestServer(options)\n\tconst clients = toEntries(options.clients).reduce(\n\t\t(clientRecord, [name, client]) => {\n\t\t\tclientRecord[name] = setupRealtimeTestClient(\n\t\t\t\t{ ...options, client },\n\t\t\t\tname,\n\t\t\t\tserver.port,\n\t\t\t)\n\t\t\treturn clientRecord\n\t\t},\n\t\t{} as Record<ClientNames, RealtimeTestClientBuilder>,\n\t)\n\n\treturn {\n\t\tclients,\n\t\tserver,\n\t\tteardown: async () => {\n\t\t\tawait server.dispose()\n\t\t\tfor (const [, client] of toEntries(clients)) {\n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C;;AAG3C,MAAa,gBACZ,YACmC;CACnC,MAAM,SAAS,wBAAwB,QAAQ;CAC/C,MAAM,SAAS,wBAAwB,SAAS,UAAU,OAAO,KAAK;AAEtE,QAAO;EACN;EACA;EACA,UAAU,YAAY;AACrB,SAAM,OAAO,SAAS;AACtB,UAAO,SAAS;;EAEjB;;AAGF,MAAa,eACZ,YAC+C;CAC/C,MAAM,SAAS,wBAAwB,QAAQ;CAC/C,MAAM,UAAU,UAAU,QAAQ,QAAQ,CAAC,QACzC,cAAc,CAAC,MAAM,YAAY;AACjC,eAAa,QAAQ,wBACpB;GAAE,GAAG;GAAS;GAAQ,EACtB,MACA,OAAO,KACP;AACD,SAAO;IAER,EAAE,CACF;AAED,QAAO;EACN;EACA;EACA,UAAU,YAAY;AACrB,SAAM,OAAO,SAAS;AACtB,QAAK,MAAM,GAAG,WAAW,UAAU,QAAQ,CAC1C,QAAO,SAAS;;EAGlB"}
@@ -0,0 +1,31 @@
1
+ import { getInternalRelations, join, mutableAtom, selectorFamily } from "atom.io";
2
+ import { SetRTX } from "atom.io/transceivers/set-rtx";
3
+
4
+ //#region src/realtime/shared-room-store.ts
5
+ const usersInThisRoomIndex = mutableAtom({
6
+ key: `usersInRoomIndex`,
7
+ class: SetRTX
8
+ });
9
+ const roomIndex = mutableAtom({
10
+ key: `roomIndex`,
11
+ class: SetRTX
12
+ });
13
+ const DEFAULT_USER_IN_ROOM_META = { enteredAtEpoch: 0 };
14
+ const usersInRooms = join({
15
+ key: `usersInRooms`,
16
+ between: [`room`, `user`],
17
+ cardinality: `1:n`,
18
+ isAType: (input) => typeof input === `string`,
19
+ isBType: (input) => typeof input === `string`
20
+ }, DEFAULT_USER_IN_ROOM_META);
21
+ const usersInMyRoomView = selectorFamily({
22
+ key: `usersInMyRoomView`,
23
+ get: (myUsername) => ({ find }) => {
24
+ const usersInRoomsAtoms = getInternalRelations(usersInRooms);
25
+ return [find(usersInRoomsAtoms, myUsername)];
26
+ }
27
+ });
28
+
29
+ //#endregion
30
+ export { DEFAULT_USER_IN_ROOM_META, roomIndex, usersInMyRoomView, usersInRooms, usersInThisRoomIndex };
31
+ //# sourceMappingURL=shared-room-store-BfW3nWif.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared-room-store-BfW3nWif.js","names":["usersInThisRoomIndex: MutableAtomToken<SetRTX<string>>","roomIndex: MutableAtomToken<SetRTX<string>>","DEFAULT_USER_IN_ROOM_META: UserInRoomMeta","usersInRooms: JoinToken<\n\t`room`,\n\tstring,\n\t`user`,\n\tstring,\n\t`1:n`,\n\tUserInRoomMeta\n>","usersInMyRoomView: ReadonlyPureSelectorFamilyToken<\n\tMutableAtomToken<SetRTX<string>>[],\n\tstring\n>"],"sources":["../src/realtime/shared-room-store.ts"],"sourcesContent":["import type {\n\tJoinToken,\n\tMutableAtomToken,\n\tReadonlyPureSelectorFamilyToken,\n} from \"atom.io\"\nimport { getInternalRelations, join, mutableAtom, selectorFamily } from \"atom.io\"\nimport { SetRTX } from \"atom.io/transceivers/set-rtx\"\n\nexport const usersInThisRoomIndex: MutableAtomToken<SetRTX<string>> =\n\tmutableAtom<SetRTX<string>>({\n\t\tkey: `usersInRoomIndex`,\n\t\tclass: SetRTX,\n\t})\n\nexport const roomIndex: MutableAtomToken<SetRTX<string>> = mutableAtom<\n\tSetRTX<string>\n>({\n\tkey: `roomIndex`,\n\tclass: SetRTX,\n})\n\nexport type UserInRoomMeta = {\n\tenteredAtEpoch: number\n}\nexport const DEFAULT_USER_IN_ROOM_META: UserInRoomMeta = {\n\tenteredAtEpoch: 0,\n}\nexport const usersInRooms: JoinToken<\n\t`room`,\n\tstring,\n\t`user`,\n\tstring,\n\t`1:n`,\n\tUserInRoomMeta\n> = join(\n\t{\n\t\tkey: `usersInRooms`,\n\t\tbetween: [`room`, `user`],\n\t\tcardinality: `1:n`,\n\t\tisAType: (input): input is string => typeof input === `string`,\n\t\tisBType: (input): input is string => typeof input === `string`,\n\t},\n\tDEFAULT_USER_IN_ROOM_META,\n)\n\nexport const usersInMyRoomView: ReadonlyPureSelectorFamilyToken<\n\tMutableAtomToken<SetRTX<string>>[],\n\tstring\n> = selectorFamily<MutableAtomToken<SetRTX<string>>[], string>({\n\tkey: `usersInMyRoomView`,\n\tget:\n\t\t(myUsername) =>\n\t\t({ find }) => {\n\t\t\tconst usersInRoomsAtoms = getInternalRelations(usersInRooms)\n\t\t\tconst myRoomIndex = find(usersInRoomsAtoms, myUsername)\n\t\t\treturn [myRoomIndex]\n\t\t},\n})\n"],"mappings":";;;;AAQA,MAAaA,uBACZ,YAA4B;CAC3B,KAAK;CACL,OAAO;CACP,CAAC;AAEH,MAAaC,YAA8C,YAEzD;CACD,KAAK;CACL,OAAO;CACP,CAAC;AAKF,MAAaC,4BAA4C,EACxD,gBAAgB,GAChB;AACD,MAAaC,eAOT,KACH;CACC,KAAK;CACL,SAAS,CAAC,QAAQ,OAAO;CACzB,aAAa;CACb,UAAU,UAA2B,OAAO,UAAU;CACtD,UAAU,UAA2B,OAAO,UAAU;CACtD,EACD,0BACA;AAED,MAAaC,oBAGT,eAA2D;CAC9D,KAAK;CACL,MACE,gBACA,EAAE,WAAW;EACb,MAAM,oBAAoB,qBAAqB,aAAa;AAE5D,SAAO,CADa,KAAK,mBAAmB,WAAW,CACnC;;CAEtB,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { JoinToken, MutableAtomToken, ReadonlyPureSelectorFamilyToken } from "atom.io";
2
+ import { SetRTX } from "atom.io/transceivers/set-rtx";
3
+
4
+ //#region src/realtime/shared-room-store.d.ts
5
+ declare const usersInThisRoomIndex: MutableAtomToken<SetRTX<string>>;
6
+ declare const roomIndex: MutableAtomToken<SetRTX<string>>;
7
+ type UserInRoomMeta = {
8
+ enteredAtEpoch: number;
9
+ };
10
+ declare const DEFAULT_USER_IN_ROOM_META: UserInRoomMeta;
11
+ declare const usersInRooms: JoinToken<`room`, string, `user`, string, `1:n`, UserInRoomMeta>;
12
+ declare const usersInMyRoomView: ReadonlyPureSelectorFamilyToken<MutableAtomToken<SetRTX<string>>[], string>;
13
+ //#endregion
14
+ export { DEFAULT_USER_IN_ROOM_META, UserInRoomMeta, roomIndex, usersInMyRoomView, usersInRooms, usersInThisRoomIndex };
15
+ //# sourceMappingURL=shared-room-store-D2o4ZLjC.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared-room-store-D2o4ZLjC.d.ts","names":["usersInThisRoomIndex: MutableAtomToken<SetRTX<string>>","roomIndex: MutableAtomToken<SetRTX<string>>","DEFAULT_USER_IN_ROOM_META: UserInRoomMeta","usersInRooms: JoinToken<\n\t`room`,\n\tstring,\n\t`user`,\n\tstring,\n\t`1:n`,\n\tUserInRoomMeta\n>","usersInMyRoomView: ReadonlyPureSelectorFamilyToken<\n\tMutableAtomToken<SetRTX<string>>[],\n\tstring\n>"],"sources":["../src/realtime/shared-room-store.ts"],"sourcesContent":[],"mappings":";;;;cAQaA,sBAAsB,iBAAiB;cAMvCC,WAAW,iBAAiB;AAN5BD,KAaD,cAAA,GAbwC;EAAA,cAAA,EAAA,MAAA;;AAAjB,cAgBtBE,yBAhBsB,EAgBK,cAhBL;AAAA,cAmBtBC,YAnBsB,EAmBR,SAnBQ,CAAA,MAAA,EAAA,MAAA,EAAA,MAAA,EAAA,MAAA,EAAA,KAAA,EAyBlC,cAzBkC,CAAA;AAMtBF,cA+BAG,iBA/B4B,EA+BT,+BA/BS,CAgCxC,gBAhCwC,CAgCvB,MAhCuB,CAAA,MAAA,CAAA,CAAA,EAAA,EAAA,MAAA,CAAA"}