atom.io 0.32.3 → 0.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (362) hide show
  1. package/dist/chunk-Cl8Af3a2.js +11 -0
  2. package/dist/data/index.d.ts +28 -0
  3. package/dist/data/index.d.ts.map +1 -0
  4. package/dist/data/index.js +66 -0
  5. package/dist/data/index.js.map +1 -0
  6. package/dist/devtools-CAg2k57t.js +0 -0
  7. package/dist/devtools-Jyn42mZm.css +311 -0
  8. package/dist/devtools-Jyn42mZm.css.map +1 -0
  9. package/dist/eslint-plugin/index.d.ts +36 -0
  10. package/dist/eslint-plugin/index.d.ts.map +1 -0
  11. package/dist/eslint-plugin/index.js +196 -0
  12. package/dist/eslint-plugin/index.js.map +1 -0
  13. package/{internal/dist → dist/internal}/index.d.ts +497 -377
  14. package/dist/internal/index.d.ts.map +1 -0
  15. package/dist/internal/index.js +3213 -0
  16. package/dist/internal/index.js.map +1 -0
  17. package/dist/introspection/index.d.ts +153 -0
  18. package/dist/introspection/index.d.ts.map +1 -0
  19. package/dist/introspection/index.js +520 -0
  20. package/dist/introspection/index.js.map +1 -0
  21. package/{json/dist → dist/json}/index.d.ts +38 -32
  22. package/dist/json/index.d.ts.map +1 -0
  23. package/dist/json/index.js +75 -0
  24. package/dist/json/index.js.map +1 -0
  25. package/dist/main/index.d.ts +691 -0
  26. package/dist/main/index.d.ts.map +1 -0
  27. package/dist/main/index.js +237 -0
  28. package/dist/main/index.js.map +1 -0
  29. package/{react/dist → dist/react}/index.d.ts +22 -11
  30. package/dist/react/index.d.ts.map +1 -0
  31. package/dist/react/index.js +91 -0
  32. package/dist/react/index.js.map +1 -0
  33. package/dist/react-devtools/index.d.ts +194 -0
  34. package/dist/react-devtools/index.d.ts.map +1 -0
  35. package/dist/react-devtools/index.js +1274 -0
  36. package/dist/react-devtools/index.js.map +1 -0
  37. package/dist/realtime/index.d.ts +55 -0
  38. package/dist/realtime/index.d.ts.map +1 -0
  39. package/dist/realtime/index.js +113 -0
  40. package/dist/realtime/index.js.map +1 -0
  41. package/dist/realtime-client/index.d.ts +81 -0
  42. package/dist/realtime-client/index.d.ts.map +1 -0
  43. package/dist/realtime-client/index.js +376 -0
  44. package/dist/realtime-client/index.js.map +1 -0
  45. package/dist/realtime-react/index.d.ts +68 -0
  46. package/dist/realtime-react/index.d.ts.map +1 -0
  47. package/dist/realtime-react/index.js +182 -0
  48. package/dist/realtime-react/index.js.map +1 -0
  49. package/dist/realtime-server/index.d.ts +190 -0
  50. package/dist/realtime-server/index.d.ts.map +1 -0
  51. package/dist/realtime-server/index.js +795 -0
  52. package/dist/realtime-server/index.js.map +1 -0
  53. package/dist/realtime-testing/index.d.ts +60 -0
  54. package/dist/realtime-testing/index.d.ts.map +1 -0
  55. package/dist/realtime-testing/index.js +181 -0
  56. package/dist/realtime-testing/index.js.map +1 -0
  57. package/dist/transceivers/set-rtx/index.d.ts +44 -0
  58. package/dist/transceivers/set-rtx/index.d.ts.map +1 -0
  59. package/dist/transceivers/set-rtx/index.js +204 -0
  60. package/dist/transceivers/set-rtx/index.js.map +1 -0
  61. package/dist/web/index.d.ts +15 -0
  62. package/dist/web/index.d.ts.map +1 -0
  63. package/dist/web/index.js +16 -0
  64. package/dist/web/index.js.map +1 -0
  65. package/package.json +70 -122
  66. package/{data/src → src/data}/struct.ts +1 -0
  67. package/{eslint-plugin/src → src/eslint-plugin}/index.ts +3 -1
  68. package/{eslint-plugin/src → src/eslint-plugin}/rules/explicit-state-types.ts +6 -1
  69. package/{eslint-plugin/src → src/eslint-plugin}/rules/synchronous-selector-dependencies.ts +14 -1
  70. package/{internal/src → src/internal}/families/create-writable-selector-family.ts +4 -2
  71. package/{internal/src → src/internal}/families/index.ts +2 -0
  72. package/{internal/src → src/internal}/index.ts +1 -0
  73. package/{internal/src → src/internal}/join/find-relations-in-store.ts +12 -0
  74. package/{internal/src → src/internal}/junction.ts +3 -2
  75. package/{internal/src → src/internal}/lazy-map.ts +1 -1
  76. package/{internal/src → src/internal}/mutable/tracker-family.ts +2 -5
  77. package/{internal/src → src/internal}/mutable/tracker.ts +15 -9
  78. package/{internal/src → src/internal}/selector/register-selector.ts +2 -1
  79. package/{internal/src → src/internal}/store/store.ts +68 -53
  80. package/{internal/src → src/internal}/subject.ts +1 -1
  81. package/{internal/src → src/internal}/transaction/build-transaction.ts +2 -1
  82. package/{introspection/src → src/introspection}/auditor.ts +1 -1
  83. package/{introspection/src → src/introspection}/differ.ts +12 -1
  84. package/{introspection/src → src/introspection}/refinery.ts +18 -3
  85. package/{json/src → src/json}/entries.ts +1 -1
  86. package/{json/src → src/json}/select-json-family.ts +1 -1
  87. package/src/{realm.ts → main/realm.ts} +1 -1
  88. package/src/{silo.ts → main/silo.ts} +1 -1
  89. package/src/{transaction.ts → main/transaction.ts} +1 -1
  90. package/{react/src → src/react}/store-context.tsx +3 -1
  91. package/{react/src → src/react}/use-i.ts +3 -5
  92. package/{react-devtools/src → src/react-devtools}/AtomIODevtools.tsx +1 -1
  93. package/{react-devtools/src → src/react-devtools}/Button.tsx +3 -1
  94. package/{react-devtools/src → src/react-devtools}/Updates.tsx +5 -1
  95. package/src/react-devtools/devtools.css +308 -0
  96. package/{react-devtools/src → src/react-devtools}/json-editor/developer-interface.tsx +2 -2
  97. package/{react-devtools/src → src/react-devtools}/json-editor/editors-by-type/utilities/cast-json.ts +2 -2
  98. package/{react-devtools/src → src/react-devtools}/json-editor/editors-by-type/utilities/object-properties.ts +3 -3
  99. package/{react-devtools/src → src/react-devtools}/json-editor/json-editor-internal.tsx +4 -2
  100. package/{react-devtools/src → src/react-devtools}/store.ts +3 -2
  101. package/{realtime/src → src/realtime}/shared-room-store.ts +28 -5
  102. package/src/realtime-client/realtime-client-stores/client-main-store.ts +23 -0
  103. package/src/realtime-client/realtime-client-stores/client-sync-store.ts +15 -0
  104. package/{realtime-react/src → src/realtime-react}/index.ts +1 -0
  105. package/{realtime-react/src → src/realtime-react}/on-mount.ts +1 -1
  106. package/{realtime-react/src → src/realtime-react}/realtime-context.tsx +5 -4
  107. package/{realtime-react/src → src/realtime-react}/use-single-effect.ts +3 -2
  108. package/{realtime-server/src → src/realtime-server}/ipc-sockets/child-socket.ts +1 -1
  109. package/{realtime-server/src → src/realtime-server}/realtime-server-stores/server-room-external-actions.ts +20 -19
  110. package/{realtime-server/src → src/realtime-server}/realtime-server-stores/server-room-external-store.ts +12 -7
  111. package/{realtime-server/src → src/realtime-server}/realtime-server-stores/server-sync-store.ts +13 -4
  112. package/{realtime-server/src → src/realtime-server}/realtime-server-stores/server-user-store.ts +26 -8
  113. package/{transceivers/set-rtx/src → src/transceivers/set-rtx}/set-rtx.ts +2 -2
  114. package/data/dist/index.d.ts +0 -31
  115. package/data/dist/index.js +0 -69
  116. package/data/package.json +0 -13
  117. package/dist/chunk-2XDFCXGB.js +0 -109
  118. package/dist/chunk-35NB2XZU.js +0 -4501
  119. package/dist/chunk-4LWKCEW3.js +0 -14
  120. package/dist/chunk-EF4S7H42.js +0 -526
  121. package/dist/chunk-LTLDKXDN.js +0 -153
  122. package/dist/chunk-MENOYVPP.js +0 -83
  123. package/dist/chunk-RGUNRT72.js +0 -634
  124. package/dist/chunk-TS76LQVD.js +0 -1035
  125. package/dist/chunk-XWL6SNVU.js +0 -7
  126. package/dist/index.d.ts +0 -701
  127. package/dist/index.js +0 -2
  128. package/eslint-plugin/dist/index.d.ts +0 -64
  129. package/eslint-plugin/dist/index.js +0 -238
  130. package/eslint-plugin/package.json +0 -13
  131. package/internal/dist/index.js +0 -2
  132. package/internal/package.json +0 -13
  133. package/introspection/dist/index.d.ts +0 -149
  134. package/introspection/dist/index.js +0 -3
  135. package/introspection/package.json +0 -13
  136. package/json/dist/index.js +0 -2
  137. package/json/package.json +0 -13
  138. package/react/dist/index.js +0 -3
  139. package/react/package.json +0 -13
  140. package/react-devtools/dist/index.css +0 -309
  141. package/react-devtools/dist/index.d.ts +0 -160
  142. package/react-devtools/dist/index.js +0 -1481
  143. package/react-devtools/package.json +0 -13
  144. package/react-devtools/src/devtools.scss +0 -309
  145. package/realtime/dist/index.d.ts +0 -51
  146. package/realtime/dist/index.js +0 -3
  147. package/realtime/package.json +0 -13
  148. package/realtime-client/dist/index.d.ts +0 -41
  149. package/realtime-client/dist/index.js +0 -4
  150. package/realtime-client/package.json +0 -13
  151. package/realtime-client/src/realtime-client-stores/client-main-store.ts +0 -20
  152. package/realtime-client/src/realtime-client-stores/client-sync-store.ts +0 -15
  153. package/realtime-react/dist/index.d.ts +0 -39
  154. package/realtime-react/dist/index.js +0 -6
  155. package/realtime-react/package.json +0 -13
  156. package/realtime-server/dist/index.d.ts +0 -139
  157. package/realtime-server/dist/index.js +0 -4
  158. package/realtime-server/package.json +0 -13
  159. package/realtime-testing/dist/index.d.ts +0 -59
  160. package/realtime-testing/dist/index.js +0 -198
  161. package/realtime-testing/package.json +0 -13
  162. package/transceivers/set-rtx/dist/index.d.ts +0 -41
  163. package/transceivers/set-rtx/dist/index.js +0 -2
  164. package/transceivers/set-rtx/package.json +0 -13
  165. package/web/dist/index.d.ts +0 -9
  166. package/web/dist/index.js +0 -2
  167. package/web/package.json +0 -13
  168. /package/{data/src → src/data}/dict.ts +0 -0
  169. /package/{data/src → src/data}/index.ts +0 -0
  170. /package/{data/src → src/data}/struct-family.ts +0 -0
  171. /package/{eslint-plugin/src → src/eslint-plugin}/rules/index.ts +0 -0
  172. /package/{eslint-plugin/src → src/eslint-plugin}/walk.ts +0 -0
  173. /package/{internal/src → src/internal}/arbitrary.ts +0 -0
  174. /package/{internal/src → src/internal}/atom/create-regular-atom.ts +0 -0
  175. /package/{internal/src → src/internal}/atom/create-standalone-atom.ts +0 -0
  176. /package/{internal/src → src/internal}/atom/dispose-atom.ts +0 -0
  177. /package/{internal/src → src/internal}/atom/index.ts +0 -0
  178. /package/{internal/src → src/internal}/atom/is-default.ts +0 -0
  179. /package/{internal/src → src/internal}/caching.ts +0 -0
  180. /package/{internal/src → src/internal}/capitalize.ts +0 -0
  181. /package/{internal/src → src/internal}/families/create-atom-family.ts +0 -0
  182. /package/{internal/src → src/internal}/families/create-readonly-selector-family.ts +0 -0
  183. /package/{internal/src → src/internal}/families/create-regular-atom-family.ts +0 -0
  184. /package/{internal/src → src/internal}/families/create-selector-family.ts +0 -0
  185. /package/{internal/src → src/internal}/families/dispose-from-store.ts +0 -0
  186. /package/{internal/src → src/internal}/families/find-in-store.ts +0 -0
  187. /package/{internal/src → src/internal}/families/get-family-of-token.ts +0 -0
  188. /package/{internal/src → src/internal}/families/init-family-member.ts +0 -0
  189. /package/{internal/src → src/internal}/families/seek-in-store.ts +0 -0
  190. /package/{internal/src → src/internal}/future.ts +0 -0
  191. /package/{internal/src → src/internal}/get-environment-data.ts +0 -0
  192. /package/{internal/src → src/internal}/get-state/get-from-store.ts +0 -0
  193. /package/{internal/src → src/internal}/get-state/index.ts +0 -0
  194. /package/{internal/src → src/internal}/get-state/read-or-compute-value.ts +0 -0
  195. /package/{internal/src → src/internal}/get-trace.ts +0 -0
  196. /package/{internal/src → src/internal}/ingest-updates/index.ts +0 -0
  197. /package/{internal/src → src/internal}/ingest-updates/ingest-atom-update.ts +0 -0
  198. /package/{internal/src → src/internal}/ingest-updates/ingest-creation-disposal.ts +0 -0
  199. /package/{internal/src → src/internal}/ingest-updates/ingest-selector-update.ts +0 -0
  200. /package/{internal/src → src/internal}/ingest-updates/ingest-transaction-update.ts +0 -0
  201. /package/{internal/src → src/internal}/install-into-store.ts +0 -0
  202. /package/{internal/src → src/internal}/join/edit-relations-in-store.ts +0 -0
  203. /package/{internal/src → src/internal}/join/get-internal-relations-from-store.ts +0 -0
  204. /package/{internal/src → src/internal}/join/get-join.ts +0 -0
  205. /package/{internal/src → src/internal}/join/index.ts +0 -0
  206. /package/{internal/src → src/internal}/join/join-internal.ts +0 -0
  207. /package/{internal/src → src/internal}/keys.ts +0 -0
  208. /package/{internal/src → src/internal}/lineage.ts +0 -0
  209. /package/{internal/src → src/internal}/molecule.ts +0 -0
  210. /package/{internal/src → src/internal}/mutable/create-mutable-atom-family.ts +0 -0
  211. /package/{internal/src → src/internal}/mutable/create-mutable-atom.ts +0 -0
  212. /package/{internal/src → src/internal}/mutable/get-json-family.ts +0 -0
  213. /package/{internal/src → src/internal}/mutable/get-json-token.ts +0 -0
  214. /package/{internal/src → src/internal}/mutable/get-update-family.ts +0 -0
  215. /package/{internal/src → src/internal}/mutable/get-update-token.ts +0 -0
  216. /package/{internal/src → src/internal}/mutable/index.ts +0 -0
  217. /package/{internal/src → src/internal}/mutable/transceiver.ts +0 -0
  218. /package/{internal/src → src/internal}/not-found-error.ts +0 -0
  219. /package/{internal/src → src/internal}/operation.ts +0 -0
  220. /package/{internal/src → src/internal}/pretty-print.ts +0 -0
  221. /package/{internal/src → src/internal}/reserved-keys.ts +0 -0
  222. /package/{internal/src → src/internal}/selector/create-readonly-selector.ts +0 -0
  223. /package/{internal/src → src/internal}/selector/create-standalone-selector.ts +0 -0
  224. /package/{internal/src → src/internal}/selector/create-writable-selector.ts +0 -0
  225. /package/{internal/src → src/internal}/selector/dispose-selector.ts +0 -0
  226. /package/{internal/src → src/internal}/selector/get-selector-dependency-keys.ts +0 -0
  227. /package/{internal/src → src/internal}/selector/index.ts +0 -0
  228. /package/{internal/src → src/internal}/selector/trace-selector-atoms.ts +0 -0
  229. /package/{internal/src → src/internal}/selector/update-selector-atoms.ts +0 -0
  230. /package/{internal/src → src/internal}/set-state/become.ts +0 -0
  231. /package/{internal/src → src/internal}/set-state/copy-mutable-if-needed.ts +0 -0
  232. /package/{internal/src → src/internal}/set-state/emit-update.ts +0 -0
  233. /package/{internal/src → src/internal}/set-state/evict-downstream.ts +0 -0
  234. /package/{internal/src → src/internal}/set-state/index.ts +0 -0
  235. /package/{internal/src → src/internal}/set-state/set-atom-or-selector.ts +0 -0
  236. /package/{internal/src → src/internal}/set-state/set-atom.ts +0 -0
  237. /package/{internal/src → src/internal}/set-state/set-into-store.ts +0 -0
  238. /package/{internal/src → src/internal}/store/circular-buffer.ts +0 -0
  239. /package/{internal/src → src/internal}/store/counterfeit.ts +0 -0
  240. /package/{internal/src → src/internal}/store/deposit.ts +0 -0
  241. /package/{internal/src → src/internal}/store/index.ts +0 -0
  242. /package/{internal/src → src/internal}/store/withdraw.ts +0 -0
  243. /package/{internal/src → src/internal}/subscribe/index.ts +0 -0
  244. /package/{internal/src → src/internal}/subscribe/recall-state.ts +0 -0
  245. /package/{internal/src → src/internal}/subscribe/subscribe-in-store.ts +0 -0
  246. /package/{internal/src → src/internal}/subscribe/subscribe-to-root-atoms.ts +0 -0
  247. /package/{internal/src → src/internal}/subscribe/subscribe-to-state.ts +0 -0
  248. /package/{internal/src → src/internal}/subscribe/subscribe-to-timeline.ts +0 -0
  249. /package/{internal/src → src/internal}/subscribe/subscribe-to-transaction.ts +0 -0
  250. /package/{internal/src → src/internal}/timeline/create-timeline.ts +0 -0
  251. /package/{internal/src → src/internal}/timeline/index.ts +0 -0
  252. /package/{internal/src → src/internal}/timeline/time-travel.ts +0 -0
  253. /package/{internal/src → src/internal}/transaction/abort-transaction.ts +0 -0
  254. /package/{internal/src → src/internal}/transaction/act-upon-store.ts +0 -0
  255. /package/{internal/src → src/internal}/transaction/apply-transaction.ts +0 -0
  256. /package/{internal/src → src/internal}/transaction/assign-transaction-to-continuity.ts +0 -0
  257. /package/{internal/src → src/internal}/transaction/create-transaction.ts +0 -0
  258. /package/{internal/src → src/internal}/transaction/get-epoch-number.ts +0 -0
  259. /package/{internal/src → src/internal}/transaction/index.ts +0 -0
  260. /package/{internal/src → src/internal}/transaction/is-root-store.ts +0 -0
  261. /package/{internal/src → src/internal}/transaction/set-epoch-number.ts +0 -0
  262. /package/{internal/src → src/internal}/utility-types.ts +0 -0
  263. /package/{introspection/src → src/introspection}/attach-atom-index.ts +0 -0
  264. /package/{introspection/src → src/introspection}/attach-introspection-states.ts +0 -0
  265. /package/{introspection/src → src/introspection}/attach-selector-index.ts +0 -0
  266. /package/{introspection/src → src/introspection}/attach-timeline-family.ts +0 -0
  267. /package/{introspection/src → src/introspection}/attach-timeline-index.ts +0 -0
  268. /package/{introspection/src → src/introspection}/attach-transaction-index.ts +0 -0
  269. /package/{introspection/src → src/introspection}/attach-transaction-logs.ts +0 -0
  270. /package/{introspection/src → src/introspection}/attach-type-selectors.ts +0 -0
  271. /package/{introspection/src → src/introspection}/index.ts +0 -0
  272. /package/{introspection/src → src/introspection}/sprawl.ts +0 -0
  273. /package/{json/src → src/json}/index.ts +0 -0
  274. /package/{json/src → src/json}/select-json.ts +0 -0
  275. /package/src/{atom.ts → main/atom.ts} +0 -0
  276. /package/src/{dispose-state.ts → main/dispose-state.ts} +0 -0
  277. /package/src/{find-state.ts → main/find-state.ts} +0 -0
  278. /package/src/{get-state.ts → main/get-state.ts} +0 -0
  279. /package/src/{index.ts → main/index.ts} +0 -0
  280. /package/src/{join.ts → main/join.ts} +0 -0
  281. /package/src/{logger.ts → main/logger.ts} +0 -0
  282. /package/src/{selector.ts → main/selector.ts} +0 -0
  283. /package/src/{set-state.ts → main/set-state.ts} +0 -0
  284. /package/src/{subscribe.ts → main/subscribe.ts} +0 -0
  285. /package/src/{timeline.ts → main/timeline.ts} +0 -0
  286. /package/src/{validators.ts → main/validators.ts} +0 -0
  287. /package/{react/src → src/react}/index.ts +0 -0
  288. /package/{react/src → src/react}/parse-state-overloads.ts +0 -0
  289. /package/{react/src → src/react}/use-json.ts +0 -0
  290. /package/{react/src → src/react}/use-o.ts +0 -0
  291. /package/{react/src → src/react}/use-tl.ts +0 -0
  292. /package/{react-devtools/src → src/react-devtools}/StateEditor.tsx +0 -0
  293. /package/{react-devtools/src → src/react-devtools}/StateIndex.tsx +0 -0
  294. /package/{react-devtools/src → src/react-devtools}/TimelineIndex.tsx +0 -0
  295. /package/{react-devtools/src → src/react-devtools}/TransactionIndex.tsx +0 -0
  296. /package/{react-devtools/src → src/react-devtools}/elastic-input/ElasticInput.tsx +0 -0
  297. /package/{react-devtools/src → src/react-devtools}/elastic-input/NumberInput.tsx +0 -0
  298. /package/{react-devtools/src → src/react-devtools}/elastic-input/TextInput.tsx +0 -0
  299. /package/{react-devtools/src → src/react-devtools}/elastic-input/index.ts +0 -0
  300. /package/{react-devtools/src → src/react-devtools}/error-boundary/DefaultFallback.tsx +0 -0
  301. /package/{react-devtools/src → src/react-devtools}/error-boundary/ReactErrorBoundary.tsx +0 -0
  302. /package/{react-devtools/src → src/react-devtools}/error-boundary/index.ts +0 -0
  303. /package/{react-devtools/src → src/react-devtools}/index.ts +0 -0
  304. /package/{react-devtools/src → src/react-devtools}/json-editor/default-components.tsx +0 -0
  305. /package/{react-devtools/src → src/react-devtools}/json-editor/editors-by-type/array-editor.tsx +0 -0
  306. /package/{react-devtools/src → src/react-devtools}/json-editor/editors-by-type/non-json.tsx +0 -0
  307. /package/{react-devtools/src → src/react-devtools}/json-editor/editors-by-type/object-editor.tsx +0 -0
  308. /package/{react-devtools/src → src/react-devtools}/json-editor/editors-by-type/primitive-editors.tsx +0 -0
  309. /package/{react-devtools/src → src/react-devtools}/json-editor/editors-by-type/utilities/array-elements.ts +0 -0
  310. /package/{react-devtools/src → src/react-devtools}/json-editor/editors-by-type/utilities/cast-to-json.ts +0 -0
  311. /package/{react-devtools/src → src/react-devtools}/json-editor/index.ts +0 -0
  312. /package/{react-devtools/src → src/react-devtools}/json-editor/todo.md +0 -0
  313. /package/{realtime/src → src/realtime}/index.ts +0 -0
  314. /package/{realtime/src → src/realtime}/realtime-continuity.ts +0 -0
  315. /package/{realtime-client/src → src/realtime-client}/continuity/index.ts +0 -0
  316. /package/{realtime-client/src → src/realtime-client}/continuity/register-and-attempt-confirmed-update.ts +0 -0
  317. /package/{realtime-client/src → src/realtime-client}/continuity/use-conceal-state.ts +0 -0
  318. /package/{realtime-client/src → src/realtime-client}/continuity/use-reveal-state.ts +0 -0
  319. /package/{realtime-client/src → src/realtime-client}/index.ts +0 -0
  320. /package/{realtime-client/src → src/realtime-client}/pull-atom-family-member.ts +0 -0
  321. /package/{realtime-client/src → src/realtime-client}/pull-atom.ts +0 -0
  322. /package/{realtime-client/src → src/realtime-client}/pull-mutable-atom-family-member.ts +0 -0
  323. /package/{realtime-client/src → src/realtime-client}/pull-mutable-atom.ts +0 -0
  324. /package/{realtime-client/src → src/realtime-client}/pull-selector-family-member.ts +0 -0
  325. /package/{realtime-client/src → src/realtime-client}/pull-selector.ts +0 -0
  326. /package/{realtime-client/src → src/realtime-client}/push-state.ts +0 -0
  327. /package/{realtime-client/src → src/realtime-client}/realtime-client-stores/index.ts +0 -0
  328. /package/{realtime-client/src → src/realtime-client}/server-action.ts +0 -0
  329. /package/{realtime-client/src → src/realtime-client}/sync-continuity.ts +0 -0
  330. /package/{realtime-react/src → src/realtime-react}/use-pull-atom-family-member.ts +0 -0
  331. /package/{realtime-react/src → src/realtime-react}/use-pull-atom.ts +0 -0
  332. /package/{realtime-react/src → src/realtime-react}/use-pull-mutable-atom.ts +0 -0
  333. /package/{realtime-react/src → src/realtime-react}/use-pull-mutable-family-member.ts +0 -0
  334. /package/{realtime-react/src → src/realtime-react}/use-pull-selector-family-member.ts +0 -0
  335. /package/{realtime-react/src → src/realtime-react}/use-pull-selector.ts +0 -0
  336. /package/{realtime-react/src → src/realtime-react}/use-push.ts +0 -0
  337. /package/{realtime-react/src → src/realtime-react}/use-realtime-service.ts +0 -0
  338. /package/{realtime-react/src → src/realtime-react}/use-server-action.ts +0 -0
  339. /package/{realtime-react/src → src/realtime-react}/use-sync-continuity.ts +0 -0
  340. /package/{realtime-server/src → src/realtime-server}/README.md +0 -0
  341. /package/{realtime-server/src → src/realtime-server}/continuity/prepare-to-send-initial-payload.ts +0 -0
  342. /package/{realtime-server/src → src/realtime-server}/continuity/prepare-to-serve-transaction-request.ts +0 -0
  343. /package/{realtime-server/src → src/realtime-server}/continuity/prepare-to-sync-realtime-continuity.ts +0 -0
  344. /package/{realtime-server/src → src/realtime-server}/continuity/prepare-to-track-client-acknowledgement.ts +0 -0
  345. /package/{realtime-server/src → src/realtime-server}/continuity/subscribe-to-continuity-actions.ts +0 -0
  346. /package/{realtime-server/src → src/realtime-server}/continuity/subscribe-to-continuity-perpectives.ts +0 -0
  347. /package/{realtime-server/src → src/realtime-server}/index.ts +0 -0
  348. /package/{realtime-server/src → src/realtime-server}/ipc-sockets/custom-socket.ts +0 -0
  349. /package/{realtime-server/src → src/realtime-server}/ipc-sockets/index.ts +0 -0
  350. /package/{realtime-server/src → src/realtime-server}/ipc-sockets/parent-socket.ts +0 -0
  351. /package/{realtime-server/src → src/realtime-server}/realtime-action-receiver.ts +0 -0
  352. /package/{realtime-server/src → src/realtime-server}/realtime-family-provider.ts +0 -0
  353. /package/{realtime-server/src → src/realtime-server}/realtime-mutable-family-provider.ts +0 -0
  354. /package/{realtime-server/src → src/realtime-server}/realtime-mutable-provider.ts +0 -0
  355. /package/{realtime-server/src → src/realtime-server}/realtime-server-stores/index.ts +0 -0
  356. /package/{realtime-server/src → src/realtime-server}/realtime-state-provider.ts +0 -0
  357. /package/{realtime-server/src → src/realtime-server}/realtime-state-receiver.ts +0 -0
  358. /package/{realtime-testing/src → src/realtime-testing}/index.ts +0 -0
  359. /package/{realtime-testing/src → src/realtime-testing}/setup-realtime-test.tsx +0 -0
  360. /package/{transceivers/set-rtx/src → src/transceivers/set-rtx}/index.ts +0 -0
  361. /package/{web/src → src/web}/index.ts +0 -0
  362. /package/{web/src → src/web}/persist-sync.ts +0 -0
@@ -0,0 +1,795 @@
1
+ import { IMPLICIT, Subject, actUponStore, editRelationsInStore, findInStore, findRelationsInStore, getFromStore, getJsonToken, getUpdateToken, isRootStore, setIntoStore, subscribeToState, subscribeToTransaction } from "atom.io/internal";
2
+ import { parseJson, stringifyJson } from "atom.io/json";
3
+ import * as AtomIO from "atom.io";
4
+ import { atom, atomFamily, join, selectorFamily } from "atom.io";
5
+ import { SetRTX } from "atom.io/transceivers/set-rtx";
6
+ import { roomIndex, usersInRooms } from "atom.io/realtime";
7
+ import { spawn } from "node:child_process";
8
+
9
+ //#region src/realtime-server/ipc-sockets/custom-socket.ts
10
+ var CustomSocket = class {
11
+ listeners;
12
+ globalListeners;
13
+ handleEvent(event, ...args) {
14
+ for (const listener of this.globalListeners) listener(event, ...args);
15
+ const listeners = this.listeners.get(event);
16
+ if (listeners) for (const listener of listeners) listener(...args);
17
+ }
18
+ id = `no_id_retrieved`;
19
+ emit;
20
+ constructor(emit) {
21
+ this.emit = emit;
22
+ this.listeners = new Map();
23
+ this.globalListeners = new Set();
24
+ }
25
+ on(event, listener) {
26
+ const listeners = this.listeners.get(event);
27
+ if (listeners) listeners.add(listener);
28
+ else this.listeners.set(event, new Set([listener]));
29
+ return this;
30
+ }
31
+ onAny(listener) {
32
+ this.globalListeners.add(listener);
33
+ return this;
34
+ }
35
+ off(event, listener) {
36
+ const listeners = this.listeners.get(event);
37
+ if (listeners) if (listener) listeners.delete(listener);
38
+ else this.listeners.delete(event);
39
+ return this;
40
+ }
41
+ offAny(listener) {
42
+ this.globalListeners.delete(listener);
43
+ return this;
44
+ }
45
+ };
46
+
47
+ //#endregion
48
+ //#region src/realtime-server/ipc-sockets/child-socket.ts
49
+ var ChildSocket = class extends CustomSocket {
50
+ incompleteData = ``;
51
+ unprocessedEvents = [];
52
+ incompleteLog = ``;
53
+ unprocessedLogs = [];
54
+ id = `#####`;
55
+ process;
56
+ key;
57
+ logger;
58
+ handleLog(arg) {
59
+ if (Array.isArray(arg)) {
60
+ const [level, ...rest] = arg;
61
+ switch (level) {
62
+ case `i`:
63
+ this.logger.info(...rest);
64
+ break;
65
+ case `w`:
66
+ this.logger.warn(...rest);
67
+ break;
68
+ case `e`:
69
+ this.logger.error(...rest);
70
+ break;
71
+ default: return;
72
+ }
73
+ }
74
+ }
75
+ constructor(process$1, key, logger) {
76
+ super((event, ...args) => {
77
+ const stringifiedEvent = JSON.stringify([event, ...args]) + `\x03`;
78
+ const errorHandler = (err) => {
79
+ if (err.code === `EPIPE`) console.error(`EPIPE error during write`, this.process.stdin);
80
+ this.process.stdin.removeListener(`error`, errorHandler);
81
+ };
82
+ this.process.stdin.once(`error`, errorHandler);
83
+ this.process.stdin.write(stringifiedEvent);
84
+ return this;
85
+ });
86
+ this.process = process$1;
87
+ this.key = key;
88
+ this.logger = logger ?? {
89
+ info: (...args) => {
90
+ console.info(this.id, this.key, ...args);
91
+ },
92
+ warn: (...args) => {
93
+ console.warn(this.id, this.key, ...args);
94
+ },
95
+ error: (...args) => {
96
+ console.error(this.id, this.key, ...args);
97
+ }
98
+ };
99
+ this.process.stdout.on(`data`, (buffer) => {
100
+ const chunk = buffer.toString();
101
+ if (chunk === `ALIVE`) return;
102
+ this.unprocessedEvents.push(...chunk.split(`\x03`));
103
+ const newInput = this.unprocessedEvents.shift();
104
+ this.incompleteData += newInput ?? ``;
105
+ try {
106
+ if (this.incompleteData.startsWith(`error`)) console.log(`❗`, this.incompleteData);
107
+ let parsedEvent = parseJson(this.incompleteData);
108
+ this.handleEvent(...parsedEvent);
109
+ while (this.unprocessedEvents.length > 0) {
110
+ const event = this.unprocessedEvents.shift();
111
+ if (event) {
112
+ if (this.unprocessedEvents.length === 0) this.incompleteData = event;
113
+ parsedEvent = parseJson(event);
114
+ this.handleEvent(...parsedEvent);
115
+ }
116
+ }
117
+ this.incompleteData = ``;
118
+ } catch (error) {
119
+ console.warn(`⚠️----------------⚠️`);
120
+ console.warn(this.incompleteData);
121
+ console.warn(`⚠️----------------⚠️`);
122
+ console.error(error);
123
+ }
124
+ });
125
+ this.process.stderr.on(`data`, (buf) => {
126
+ const chunk = buf.toString();
127
+ this.unprocessedLogs.push(...chunk.split(`\x03`));
128
+ const newInput = this.unprocessedLogs.shift();
129
+ this.incompleteLog += newInput ?? ``;
130
+ try {
131
+ let parsedLog = parseJson(this.incompleteLog);
132
+ this.handleLog(parsedLog);
133
+ while (this.unprocessedLogs.length > 0) {
134
+ this.incompleteLog = this.unprocessedLogs.shift() ?? ``;
135
+ if (this.incompleteLog) {
136
+ parsedLog = parseJson(this.incompleteLog);
137
+ this.handleLog(parsedLog);
138
+ }
139
+ }
140
+ } catch (error) {
141
+ console.error(`❌❌❌`);
142
+ console.error(this.incompleteLog);
143
+ console.error(error);
144
+ console.error(`❌❌❌️`);
145
+ }
146
+ });
147
+ if (process$1.pid) this.id = process$1.pid.toString();
148
+ }
149
+ };
150
+
151
+ //#endregion
152
+ //#region src/realtime-server/ipc-sockets/parent-socket.ts
153
+ var SubjectSocket = class extends CustomSocket {
154
+ in;
155
+ out;
156
+ id = `no_id_retrieved`;
157
+ disposalFunctions = [];
158
+ constructor(id) {
159
+ super((...args) => {
160
+ this.out.next(args);
161
+ return this;
162
+ });
163
+ this.id = id;
164
+ this.in = new Subject();
165
+ this.out = new Subject();
166
+ this.in.subscribe(`socket`, (event) => {
167
+ this.handleEvent(...event);
168
+ });
169
+ }
170
+ dispose() {
171
+ for (const dispose of this.disposalFunctions) dispose();
172
+ }
173
+ };
174
+ var ParentSocket = class extends CustomSocket {
175
+ incompleteData = ``;
176
+ unprocessedEvents = [];
177
+ relays;
178
+ relayServices;
179
+ process;
180
+ id = `#####`;
181
+ log(...args) {
182
+ this.process.stderr.write(stringifyJson(args.map((arg) => arg instanceof SetRTX ? `{ ${arg.toJSON().members.join(` | `)} }` : arg)) + `\x03`);
183
+ }
184
+ logger = {
185
+ info: (...args) => {
186
+ this.log(`i`, ...args);
187
+ },
188
+ warn: (...args) => {
189
+ this.log(`w`, ...args);
190
+ },
191
+ error: (...args) => {
192
+ this.log(`e`, ...args);
193
+ }
194
+ };
195
+ constructor() {
196
+ super((event, ...args) => {
197
+ const stringifiedEvent = JSON.stringify([event, ...args]);
198
+ this.process.stdout.write(stringifiedEvent + `\x03`);
199
+ return this;
200
+ });
201
+ this.process = process;
202
+ this.process.stdin.resume();
203
+ this.relays = new Map();
204
+ this.relayServices = [];
205
+ this.process.stdin.on(`data`, (buffer) => {
206
+ const chunk = buffer.toString();
207
+ this.unprocessedEvents.push(...chunk.split(`\x03`));
208
+ const newInput = this.unprocessedEvents.shift();
209
+ this.incompleteData += newInput ?? ``;
210
+ try {
211
+ const parsedData = parseJson(this.incompleteData);
212
+ this.logger.info(`🎰`, `received`, parsedData);
213
+ this.handleEvent(...parsedData);
214
+ while (this.unprocessedEvents.length > 0) {
215
+ const event = this.unprocessedEvents.shift();
216
+ if (event) {
217
+ if (this.unprocessedEvents.length === 0) this.incompleteData = event;
218
+ const parsedEvent = parseJson(event);
219
+ this.handleEvent(...parsedEvent);
220
+ }
221
+ }
222
+ this.incompleteData = ``;
223
+ } catch (thrown) {
224
+ if (thrown instanceof Error) this.logger.error(`❗`, thrown.message, thrown.cause, thrown.stack);
225
+ }
226
+ });
227
+ this.on(`exit`, () => {
228
+ this.logger.info(`🔥`, this.id, `received "exit"`);
229
+ process.exit(0);
230
+ });
231
+ process.on(`exit`, (code) => {
232
+ this.logger.info(`🔥`, this.id, `exited with code ${code}`);
233
+ });
234
+ process.on(`end`, () => {
235
+ this.logger.info(`🔥`, this.id, `ended`);
236
+ process.exit(0);
237
+ });
238
+ process.on(`SIGTERM`, () => {
239
+ this.logger.error(`🔥`, this.id, `terminated`);
240
+ process.exit(0);
241
+ });
242
+ process.on(`SIGINT`, () => {
243
+ this.logger.error(`🔥`, this.id, `interrupted`);
244
+ process.exit(0);
245
+ });
246
+ if (process.pid) this.id = process.pid?.toString();
247
+ this.on(`user-joins`, (username) => {
248
+ this.logger.info(`👤`, `user`, username, `joined`);
249
+ const relay = new SubjectSocket(`user:${username}`);
250
+ this.relays.set(username, relay);
251
+ this.logger.info(`🔗`, `attaching services:`, `[${[...this.relayServices.keys()].join(`, `)}]`);
252
+ for (const attachServices of this.relayServices) {
253
+ const cleanup = attachServices(relay);
254
+ if (cleanup) relay.disposalFunctions.push(cleanup);
255
+ }
256
+ this.on(`user:${username}`, (...data) => {
257
+ relay.in.next(data);
258
+ });
259
+ relay.out.subscribe(`socket`, (data) => {
260
+ this.emit(...data);
261
+ });
262
+ });
263
+ this.on(`user-leaves`, (username) => {
264
+ const relay = this.relays.get(username);
265
+ this.off(`relay:${username}`);
266
+ if (relay) {
267
+ relay.dispose();
268
+ this.relays.delete(username);
269
+ }
270
+ });
271
+ process.stdout.write(`ALIVE`);
272
+ }
273
+ relay(attachServices) {
274
+ this.logger.info(`🔗`, `running relay method`);
275
+ this.relayServices.push(attachServices);
276
+ }
277
+ };
278
+
279
+ //#endregion
280
+ //#region src/realtime-server/realtime-server-stores/server-room-external-store.ts
281
+ const roomArgumentsAtoms = atomFamily({
282
+ key: `roomArguments`,
283
+ default: [`echo`, [`Hello World!`]]
284
+ });
285
+ const roomSelectors = selectorFamily({
286
+ key: `room`,
287
+ get: (roomId) => async ({ get, find }) => {
288
+ const argumentsState = find(roomArgumentsAtoms, roomId);
289
+ const args = get(argumentsState);
290
+ const [script, options] = args;
291
+ const child = await new Promise((resolve) => {
292
+ const room = spawn(script, options, { env: process.env });
293
+ const resolver = (data) => {
294
+ if (data.toString() === `ALIVE`) {
295
+ room.stdout.off(`data`, resolver);
296
+ resolve(room);
297
+ }
298
+ };
299
+ room.stdout.on(`data`, resolver);
300
+ });
301
+ return new ChildSocket(child, roomId);
302
+ }
303
+ });
304
+
305
+ //#endregion
306
+ //#region src/realtime-server/realtime-server-stores/server-room-external-actions.ts
307
+ const createRoomTX = AtomIO.transaction({
308
+ key: `createRoom`,
309
+ do: ({ get, set, find }, roomId, script, options) => {
310
+ const args = options ? [script, options] : [script];
311
+ const roomArgumentsState = find(roomArgumentsAtoms, roomId);
312
+ set(roomArgumentsState, args);
313
+ set(roomIndex, (s) => s.add(roomId));
314
+ const roomState = find(roomSelectors, roomId);
315
+ const room = get(roomState);
316
+ return room;
317
+ }
318
+ });
319
+ const joinRoomTX = AtomIO.transaction({
320
+ key: `joinRoom`,
321
+ do: (tools, roomId, userId, enteredAtEpoch) => {
322
+ const meta = { enteredAtEpoch };
323
+ editRelationsInStore(usersInRooms, (relations) => {
324
+ relations.set({
325
+ room: roomId,
326
+ user: userId
327
+ }, meta);
328
+ }, tools.env().store);
329
+ return meta;
330
+ }
331
+ });
332
+ const leaveRoomTX = AtomIO.transaction({
333
+ key: `leaveRoom`,
334
+ do: (tools, roomId, userId) => {
335
+ editRelationsInStore(usersInRooms, (relations) => {
336
+ relations.delete({
337
+ room: roomId,
338
+ user: userId
339
+ });
340
+ }, tools.env().store);
341
+ }
342
+ });
343
+ const destroyRoomTX = AtomIO.transaction({
344
+ key: `destroyRoom`,
345
+ do: (tools, roomId) => {
346
+ editRelationsInStore(usersInRooms, (relations) => {
347
+ relations.delete({ room: roomId });
348
+ }, tools.env().store);
349
+ tools.set(roomIndex, (s) => (s.delete(roomId), s));
350
+ }
351
+ });
352
+
353
+ //#endregion
354
+ //#region src/realtime-server/realtime-server-stores/server-sync-store.ts
355
+ function redactTransactionUpdateContent(visibleStateKeys, updates) {
356
+ return updates.map((update) => {
357
+ switch (update.type) {
358
+ case `transaction_update`: {
359
+ const redacted = redactTransactionUpdateContent(visibleStateKeys, update.updates);
360
+ return {
361
+ ...update,
362
+ updates: redacted
363
+ };
364
+ }
365
+ case `atom_update`:
366
+ case `selector_update`:
367
+ case `molecule_creation`:
368
+ case `molecule_disposal`:
369
+ case `molecule_transfer`:
370
+ case `state_creation`:
371
+ case `state_disposal`: return update;
372
+ }
373
+ }).filter((update) => {
374
+ switch (update.type) {
375
+ case `atom_update`:
376
+ case `selector_update`: return visibleStateKeys.includes(update.key);
377
+ case `state_creation`:
378
+ case `state_disposal`: return visibleStateKeys.includes(update.token.key);
379
+ case `molecule_creation`:
380
+ case `transaction_update`:
381
+ case `molecule_disposal`:
382
+ case `molecule_transfer`: return true;
383
+ }
384
+ });
385
+ }
386
+ const redactorAtoms = atomFamily({
387
+ key: `redactor`,
388
+ default: { occlude: (updates) => updates }
389
+ });
390
+ const userUnacknowledgedQueues = atomFamily({
391
+ key: `unacknowledgedUpdates`,
392
+ default: () => []
393
+ });
394
+
395
+ //#endregion
396
+ //#region src/realtime-server/realtime-server-stores/server-user-store.ts
397
+ const socketAtoms = atomFamily({
398
+ key: `sockets`,
399
+ default: null
400
+ });
401
+ const socketIndex = atom({
402
+ key: `socketsIndex`,
403
+ mutable: true,
404
+ default: () => new SetRTX(),
405
+ toJson: (set) => set.toJSON(),
406
+ fromJson: (json) => SetRTX.fromJSON(json)
407
+ });
408
+ const userIndex = atom({
409
+ key: `usersIndex`,
410
+ mutable: true,
411
+ default: () => new SetRTX(),
412
+ toJson: (set) => set.toJSON(),
413
+ fromJson: (json) => SetRTX.fromJSON(json)
414
+ });
415
+ const usersOfSockets = join({
416
+ key: `usersOfSockets`,
417
+ between: [`user`, `socket`],
418
+ cardinality: `1:1`,
419
+ isAType: (s) => s.startsWith(`user::`),
420
+ isBType: (s) => s.startsWith(`socket::`)
421
+ });
422
+
423
+ //#endregion
424
+ //#region src/realtime-server/continuity/prepare-to-send-initial-payload.ts
425
+ function prepareToSendInitialPayload(store, continuity, userKey, socket) {
426
+ const continuityKey = continuity.key;
427
+ return function sendInitialPayload() {
428
+ const initialPayload = [];
429
+ for (const atom$1 of continuity.globals) {
430
+ const resourceToken = atom$1.type === `mutable_atom` ? getJsonToken(store, atom$1) : atom$1;
431
+ const resource = getFromStore(store, resourceToken);
432
+ initialPayload.push(resourceToken, resource);
433
+ }
434
+ for (const perspective of continuity.perspectives) {
435
+ const { viewAtoms, resourceAtoms } = perspective;
436
+ const userViewState = findInStore(store, viewAtoms, userKey);
437
+ const userView = getFromStore(store, userViewState);
438
+ store.logger.info(`👁`, `atom`, resourceAtoms.key, `${userKey} can see`, {
439
+ viewAtoms,
440
+ resourceAtoms,
441
+ userView
442
+ });
443
+ for (const visibleToken of userView) {
444
+ const resourceToken = visibleToken.type === `mutable_atom` ? getJsonToken(store, visibleToken) : visibleToken;
445
+ const resource = getFromStore(store, resourceToken);
446
+ initialPayload.push(resourceToken, resource);
447
+ }
448
+ }
449
+ const epoch = isRootStore(store) ? store.transactionMeta.epoch.get(continuityKey) ?? null : null;
450
+ socket?.emit(`continuity-init:${continuityKey}`, epoch, initialPayload);
451
+ };
452
+ }
453
+
454
+ //#endregion
455
+ //#region src/realtime-server/continuity/prepare-to-serve-transaction-request.ts
456
+ function prepareToServeTransactionRequest(store, continuity, userKey) {
457
+ const continuityKey = continuity.key;
458
+ return function serveTransactionRequest(update) {
459
+ store.logger.info(`🛎️`, `continuity`, continuityKey, `received`, update);
460
+ const transactionKey = update.key;
461
+ const updateId = update.id;
462
+ const performanceKey = `tx-run:${transactionKey}:${updateId}`;
463
+ const performanceKeyStart = `${performanceKey}:start`;
464
+ const performanceKeyEnd = `${performanceKey}:end`;
465
+ performance.mark(performanceKeyStart);
466
+ try {
467
+ actUponStore(store, {
468
+ type: `transaction`,
469
+ key: transactionKey
470
+ }, updateId)(...update.params);
471
+ } catch (thrown) {
472
+ if (thrown instanceof Error) store.logger.error(`❌`, `continuity`, continuityKey, `failed to run transaction ${transactionKey} from ${userKey} with update ${updateId}`, thrown.message);
473
+ }
474
+ performance.mark(performanceKeyEnd);
475
+ const metric = performance.measure(performanceKey, performanceKeyStart, performanceKeyEnd);
476
+ store?.logger.info(`🚀`, `transaction`, transactionKey, updateId, userKey, metric.duration);
477
+ };
478
+ }
479
+
480
+ //#endregion
481
+ //#region src/realtime-server/continuity/prepare-to-track-client-acknowledgement.ts
482
+ function prepareToTrackClientAcknowledgement(store, continuity, userKey, userUnacknowledgedUpdates) {
483
+ const continuityKey = continuity.key;
484
+ return function trackClientAcknowledgement(epoch) {
485
+ store.logger.info(`👍`, `continuity`, continuityKey, `${userKey} acknowledged epoch ${epoch}`);
486
+ const isUnacknowledged = userUnacknowledgedUpdates[0]?.epoch === epoch;
487
+ if (isUnacknowledged) setIntoStore(store, userUnacknowledgedQueues, userKey, (updates) => {
488
+ updates.shift();
489
+ store.logger.info(`👍`, `continuity`, continuityKey, `${userKey} unacknowledged update queue now has`, updates.length, `items`);
490
+ return updates;
491
+ });
492
+ };
493
+ }
494
+
495
+ //#endregion
496
+ //#region src/realtime-server/continuity/subscribe-to-continuity-actions.ts
497
+ function subscribeToContinuityActions(store, continuity, userKey, socket) {
498
+ const continuityKey = continuity.key;
499
+ const unsubscribeFunctions = [];
500
+ for (const transaction of continuity.actions) {
501
+ const unsubscribeFromTransaction = subscribeToTransaction(store, transaction, `sync-continuity:${continuityKey}:${userKey}`, (update) => {
502
+ try {
503
+ const visibleKeys = continuity.globals.map((atom$1) => {
504
+ if (atom$1.type === `atom`) return atom$1.key;
505
+ return getUpdateToken(atom$1).key;
506
+ }).concat(continuity.perspectives.flatMap((perspective) => {
507
+ const { viewAtoms } = perspective;
508
+ const userPerspectiveTokenState = findInStore(store, viewAtoms, userKey);
509
+ const visibleTokens = getFromStore(store, userPerspectiveTokenState);
510
+ return visibleTokens.map((token) => {
511
+ const key = token.type === `mutable_atom` ? `*` + token.key : token.key;
512
+ return key;
513
+ });
514
+ }));
515
+ const redactedUpdates = redactTransactionUpdateContent(visibleKeys, update.updates);
516
+ const redactedUpdate = {
517
+ ...update,
518
+ updates: redactedUpdates
519
+ };
520
+ setIntoStore(store, userUnacknowledgedQueues, userKey, (updates) => {
521
+ if (redactedUpdate) {
522
+ updates.push(redactedUpdate);
523
+ updates.sort((a, b) => a.epoch - b.epoch);
524
+ store.logger.info(`👍`, `continuity`, continuityKey, `${userKey} unacknowledged update queue now has`, updates.length, `items`);
525
+ }
526
+ return updates;
527
+ });
528
+ socket?.emit(`tx-new:${continuityKey}`, redactedUpdate);
529
+ } catch (thrown) {
530
+ if (thrown instanceof Error) store.logger.error(`❌`, `continuity`, continuityKey, `${userKey} failed to send update from transaction ${transaction.key} to ${userKey}`, thrown.message);
531
+ }
532
+ });
533
+ unsubscribeFunctions.push(unsubscribeFromTransaction);
534
+ }
535
+ return unsubscribeFunctions;
536
+ }
537
+
538
+ //#endregion
539
+ //#region src/realtime-server/continuity/subscribe-to-continuity-perpectives.ts
540
+ function subscribeToContinuityPerspectives(store, continuity, userKey, socket) {
541
+ const continuityKey = continuity.key;
542
+ const unsubFns = [];
543
+ for (const perspective of continuity.perspectives) {
544
+ const { viewAtoms } = perspective;
545
+ const userViewState = findInStore(store, viewAtoms, userKey);
546
+ const unsubscribeFromUserView = subscribeToState(store, userViewState, `sync-continuity:${continuityKey}:${userKey}:perspective:${perspective.resourceAtoms.key}`, ({ oldValue, newValue }) => {
547
+ const oldKeys = oldValue.map((token) => token.key);
548
+ const newKeys = newValue.map((token) => token.key);
549
+ const concealed = oldValue.filter((token) => !newKeys.includes(token.key));
550
+ const revealed = newValue.filter((token) => !oldKeys.includes(token.key)).flatMap((token) => {
551
+ const resourceToken = token.type === `mutable_atom` ? getJsonToken(store, token) : token;
552
+ const resource = getFromStore(store, resourceToken);
553
+ return [resourceToken, resource];
554
+ });
555
+ store.logger.info(`👁`, `atom`, perspective.resourceAtoms.key, `${userKey} has a new perspective`, {
556
+ oldKeys,
557
+ newKeys,
558
+ revealed,
559
+ concealed
560
+ });
561
+ if (revealed.length > 0) socket?.emit(`reveal:${continuityKey}`, revealed);
562
+ if (concealed.length > 0) socket?.emit(`conceal:${continuityKey}`, concealed);
563
+ });
564
+ unsubFns.push(unsubscribeFromUserView);
565
+ }
566
+ return unsubFns;
567
+ }
568
+
569
+ //#endregion
570
+ //#region src/realtime-server/continuity/prepare-to-sync-realtime-continuity.ts
571
+ function prepareToExposeRealtimeContinuity({ socket: initialSocket, store = IMPLICIT.STORE }) {
572
+ return function syncRealtimeContinuity(continuity) {
573
+ let socket = initialSocket;
574
+ const continuityKey = continuity.key;
575
+ const userKeyState = findRelationsInStore(usersOfSockets, `socket::${socket.id}`, store).userKeyOfSocket;
576
+ const userKey = getFromStore(store, userKeyState);
577
+ if (!userKey) {
578
+ store.logger.error(`❌`, `continuity`, continuityKey, `Tried to create a synchronizer for a socket (${socket.id}) that is not connected to a user.`);
579
+ return () => {};
580
+ }
581
+ const socketKeyState = findRelationsInStore(usersOfSockets, userKey, store).socketKeyOfUser;
582
+ const unsubscribeFromSocketTracking = subscribeToState(store, socketKeyState, `sync-continuity:${continuityKey}:${userKey}`, ({ newValue: newSocketKey }) => {
583
+ store.logger.info(`👋`, `continuity`, continuityKey, `seeing ${userKey} on new socket ${newSocketKey}`);
584
+ if (newSocketKey === null) {
585
+ store.logger.warn(`❌`, `continuity`, continuityKey, `User (${userKey}) is not connected to a socket, waiting for them to reappear.`);
586
+ return;
587
+ }
588
+ const newSocketState = findInStore(store, socketAtoms, newSocketKey);
589
+ const newSocket = getFromStore(store, newSocketState);
590
+ socket = newSocket;
591
+ for (const unacknowledgedUpdate of userUnacknowledgedUpdates) socket?.emit(`tx-new:${continuityKey}`, unacknowledgedUpdate);
592
+ });
593
+ const userUnacknowledgedUpdates = getFromStore(store, userUnacknowledgedQueues, userKey);
594
+ const unsubscribeFunctions = [];
595
+ const unsubscribeFromPerspectives = subscribeToContinuityPerspectives(store, continuity, userKey, socket);
596
+ const unsubscribeFromTransactions = subscribeToContinuityActions(store, continuity, userKey, socket);
597
+ unsubscribeFunctions.push(...unsubscribeFromPerspectives, ...unsubscribeFromTransactions);
598
+ const sendInitialPayload = prepareToSendInitialPayload(store, continuity, userKey, initialSocket);
599
+ socket.off(`get:${continuityKey}`, sendInitialPayload);
600
+ socket.on(`get:${continuityKey}`, sendInitialPayload);
601
+ const fillTransactionRequest = prepareToServeTransactionRequest(store, continuity, userKey);
602
+ socket.off(`tx-run:${continuityKey}`, fillTransactionRequest);
603
+ socket.on(`tx-run:${continuityKey}`, fillTransactionRequest);
604
+ const trackClientAcknowledgement = prepareToTrackClientAcknowledgement(store, continuity, userKey, userUnacknowledgedUpdates);
605
+ socket?.on(`ack:${continuityKey}`, trackClientAcknowledgement);
606
+ return () => {
607
+ for (const unsubscribe of unsubscribeFunctions) unsubscribe();
608
+ socket?.off(`ack:${continuityKey}`, trackClientAcknowledgement);
609
+ socket?.off(`get:${continuityKey}`, sendInitialPayload);
610
+ socket?.off(`tx-run:${continuityKey}`, fillTransactionRequest);
611
+ };
612
+ };
613
+ }
614
+
615
+ //#endregion
616
+ //#region src/realtime-server/realtime-action-receiver.ts
617
+ function realtimeActionReceiver({ socket, store = IMPLICIT.STORE }) {
618
+ return function actionReceiver(tx) {
619
+ const fillTransactionRequest = (update) => {
620
+ const performanceKey = `tx-run:${tx.key}:${update.id}`;
621
+ const performanceKeyStart = `${performanceKey}:start`;
622
+ const performanceKeyEnd = `${performanceKey}:end`;
623
+ performance.mark(performanceKeyStart);
624
+ actUponStore(store, tx, update.id)(...update.params);
625
+ performance.mark(performanceKeyEnd);
626
+ const metric = performance.measure(performanceKey, performanceKeyStart, performanceKeyEnd);
627
+ store?.logger.info(`🚀`, `transaction`, tx.key, update.id, metric.duration);
628
+ };
629
+ socket.on(`tx-run:${tx.key}`, fillTransactionRequest);
630
+ return () => {
631
+ socket.off(`tx-run:${tx.key}`, fillTransactionRequest);
632
+ };
633
+ };
634
+ }
635
+
636
+ //#endregion
637
+ //#region src/realtime-server/realtime-family-provider.ts
638
+ function realtimeAtomFamilyProvider({ socket, store = IMPLICIT.STORE }) {
639
+ return function familyProvider(family, index) {
640
+ const unsubCallbacksByKey = new Map();
641
+ const fillUnsubRequest = (key) => {
642
+ socket.off(`unsub:${key}`, fillUnsubRequest);
643
+ const unsub = unsubCallbacksByKey.get(key);
644
+ if (unsub) {
645
+ unsub();
646
+ unsubCallbacksByKey.delete(key);
647
+ }
648
+ };
649
+ const fillSubRequest = (subKey) => {
650
+ const exposedSubKeys = getFromStore(store, index);
651
+ for (const exposedSubKey of exposedSubKeys) if (stringifyJson(exposedSubKey) === stringifyJson(subKey)) {
652
+ const token = findInStore(store, family, subKey);
653
+ socket.emit(`serve:${token.key}`, getFromStore(store, token));
654
+ const unsubscribe = subscribeToState(store, token, `expose-family:${family.key}:${socket.id}`, ({ newValue }) => {
655
+ socket.emit(`serve:${token.key}`, newValue);
656
+ });
657
+ unsubCallbacksByKey.set(token.key, unsubscribe);
658
+ socket.on(`unsub:${token.key}`, () => {
659
+ fillUnsubRequest(token.key);
660
+ });
661
+ break;
662
+ }
663
+ };
664
+ socket.on(`sub:${family.key}`, fillSubRequest);
665
+ return () => {
666
+ socket.off(`sub:${family.key}`, fillSubRequest);
667
+ for (const [, unsub] of unsubCallbacksByKey) unsub();
668
+ unsubCallbacksByKey.clear();
669
+ };
670
+ };
671
+ }
672
+
673
+ //#endregion
674
+ //#region src/realtime-server/realtime-mutable-family-provider.ts
675
+ function realtimeMutableFamilyProvider({ socket, store = IMPLICIT.STORE }) {
676
+ return function mutableFamilyProvider(family, index) {
677
+ const unsubCallbacksByKey = new Map();
678
+ const fillUnsubRequest = (key) => {
679
+ socket.off(`unsub:${key}`, fillUnsubRequest);
680
+ const unsub = unsubCallbacksByKey.get(key);
681
+ if (unsub) {
682
+ unsub();
683
+ unsubCallbacksByKey.delete(key);
684
+ }
685
+ };
686
+ const fillSubRequest = (subKey) => {
687
+ const exposedSubKeys = getFromStore(store, index);
688
+ for (const exposedSubKey of exposedSubKeys) if (stringifyJson(exposedSubKey) === stringifyJson(subKey)) {
689
+ const token = findInStore(store, family, subKey);
690
+ getFromStore(store, token);
691
+ const jsonToken = getJsonToken(store, token);
692
+ const updateToken = getUpdateToken(token);
693
+ socket.emit(`init:${token.key}`, getFromStore(store, jsonToken));
694
+ const unsubscribe = subscribeToState(store, updateToken, `expose-family:${family.key}:${socket.id}`, ({ newValue }) => {
695
+ socket.emit(`next:${token.key}`, newValue);
696
+ });
697
+ unsubCallbacksByKey.set(token.key, unsubscribe);
698
+ socket.on(`unsub:${token.key}`, () => {
699
+ fillUnsubRequest(token.key);
700
+ });
701
+ break;
702
+ }
703
+ };
704
+ socket.on(`sub:${family.key}`, fillSubRequest);
705
+ return () => {
706
+ socket.off(`sub:${family.key}`, fillSubRequest);
707
+ for (const [, unsub] of unsubCallbacksByKey) unsub();
708
+ unsubCallbacksByKey.clear();
709
+ };
710
+ };
711
+ }
712
+
713
+ //#endregion
714
+ //#region src/realtime-server/realtime-mutable-provider.ts
715
+ function realtimeMutableProvider({ socket, store = IMPLICIT.STORE }) {
716
+ return function mutableProvider(token) {
717
+ let unsubscribeFromStateUpdates = null;
718
+ const jsonToken = getJsonToken(store, token);
719
+ const trackerToken = getUpdateToken(token);
720
+ const fillUnsubRequest = () => {
721
+ socket.off(`unsub:${token.key}`, fillUnsubRequest);
722
+ unsubscribeFromStateUpdates?.();
723
+ unsubscribeFromStateUpdates = null;
724
+ };
725
+ const fillSubRequest = () => {
726
+ socket.emit(`init:${token.key}`, getFromStore(store, jsonToken));
727
+ unsubscribeFromStateUpdates = subscribeToState(store, trackerToken, `expose-single:${socket.id}`, ({ newValue }) => {
728
+ socket.emit(`next:${token.key}`, newValue);
729
+ });
730
+ socket.on(`unsub:${token.key}`, fillUnsubRequest);
731
+ };
732
+ socket.on(`sub:${token.key}`, fillSubRequest);
733
+ return () => {
734
+ socket.off(`sub:${token.key}`, fillSubRequest);
735
+ unsubscribeFromStateUpdates?.();
736
+ };
737
+ };
738
+ }
739
+
740
+ //#endregion
741
+ //#region src/realtime-server/realtime-state-provider.ts
742
+ function realtimeStateProvider({ socket, store = IMPLICIT.STORE }) {
743
+ return function stateProvider(token) {
744
+ let unsubscribeFromStateUpdates;
745
+ const fillSubRequest = () => {
746
+ socket.emit(`serve:${token.key}`, getFromStore(store, token));
747
+ unsubscribeFromStateUpdates = subscribeToState(store, token, `expose-single:${socket.id}`, ({ newValue }) => {
748
+ socket.emit(`serve:${token.key}`, newValue);
749
+ });
750
+ const fillUnsubRequest = () => {
751
+ socket.off(`unsub:${token.key}`, fillUnsubRequest);
752
+ if (unsubscribeFromStateUpdates) {
753
+ unsubscribeFromStateUpdates();
754
+ unsubscribeFromStateUpdates = void 0;
755
+ }
756
+ };
757
+ socket.on(`unsub:${token.key}`, fillUnsubRequest);
758
+ };
759
+ socket.on(`sub:${token.key}`, fillSubRequest);
760
+ return () => {
761
+ socket.off(`sub:${token.key}`, fillSubRequest);
762
+ if (unsubscribeFromStateUpdates) {
763
+ unsubscribeFromStateUpdates();
764
+ unsubscribeFromStateUpdates = void 0;
765
+ }
766
+ };
767
+ };
768
+ }
769
+
770
+ //#endregion
771
+ //#region src/realtime-server/realtime-state-receiver.ts
772
+ function realtimeStateReceiver({ socket, store = IMPLICIT.STORE }) {
773
+ return function stateReceiver(token) {
774
+ const publish = (newValue) => {
775
+ setIntoStore(store, token, newValue);
776
+ };
777
+ const fillPubUnclaim = () => {
778
+ socket.off(`pub:${token.key}`, publish);
779
+ socket.off(`unclaim:${token.key}`, fillPubUnclaim);
780
+ };
781
+ const fillPubClaim = () => {
782
+ socket.on(`pub:${token.key}`, publish);
783
+ socket.on(`unclaim:${token.key}`, fillPubUnclaim);
784
+ };
785
+ socket.on(`claim:${token.key}`, fillPubClaim);
786
+ return () => {
787
+ socket.off(`claim:${token.key}`, fillPubClaim);
788
+ socket.off(`pub:${token.key}`, publish);
789
+ };
790
+ };
791
+ }
792
+
793
+ //#endregion
794
+ export { ChildSocket, CustomSocket, ParentSocket, SubjectSocket, createRoomTX, destroyRoomTX, joinRoomTX, leaveRoomTX, prepareToExposeRealtimeContinuity, realtimeActionReceiver, realtimeAtomFamilyProvider, realtimeMutableFamilyProvider, realtimeMutableProvider, realtimeStateProvider, realtimeStateReceiver, redactTransactionUpdateContent, redactorAtoms, roomArgumentsAtoms, roomSelectors, socketAtoms, socketIndex, userIndex, userUnacknowledgedQueues, usersOfSockets };
795
+ //# sourceMappingURL=index.js.map