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