atom.io 0.40.6 → 0.40.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. package/README.md +1 -1
  2. package/dist/data/index.d.ts +1 -1
  3. package/dist/data/index.js +1 -2
  4. package/dist/data/index.js.map +1 -1
  5. package/dist/employ-socket-D6wgByWh.js +12 -0
  6. package/dist/employ-socket-D6wgByWh.js.map +1 -0
  7. package/dist/eslint-plugin/index.js.map +1 -1
  8. package/dist/has-role-CMlaUlaf.js +1133 -0
  9. package/dist/has-role-CMlaUlaf.js.map +1 -0
  10. package/dist/internal/index.d.ts +248 -248
  11. package/dist/internal/index.d.ts.map +1 -1
  12. package/dist/internal/index.js +590 -1803
  13. package/dist/internal/index.js.map +1 -1
  14. package/dist/introspection/index.d.ts +1 -1
  15. package/dist/introspection/index.d.ts.map +1 -1
  16. package/dist/introspection/index.js +13 -32
  17. package/dist/introspection/index.js.map +1 -1
  18. package/dist/is-fn-DY1wZ-md.js +10 -0
  19. package/dist/is-fn-DY1wZ-md.js.map +1 -0
  20. package/dist/json/index.d.ts.map +1 -1
  21. package/dist/json/index.js.map +1 -1
  22. package/dist/main/index.d.ts +33 -33
  23. package/dist/main/index.d.ts.map +1 -1
  24. package/dist/main/index.js +3 -4
  25. package/dist/main/index.js.map +1 -1
  26. package/dist/mutex-store-CSvxY9i3.js +11 -0
  27. package/dist/mutex-store-CSvxY9i3.js.map +1 -0
  28. package/dist/react/index.d.ts +5 -5
  29. package/dist/react/index.d.ts.map +1 -1
  30. package/dist/react/index.js.map +1 -1
  31. package/dist/react-devtools/index.d.ts.map +1 -1
  32. package/dist/react-devtools/index.js +9 -11
  33. package/dist/react-devtools/index.js.map +1 -1
  34. package/dist/realtime/index.d.ts +7 -15
  35. package/dist/realtime/index.d.ts.map +1 -1
  36. package/dist/realtime/index.js +4 -35
  37. package/dist/realtime/index.js.map +1 -1
  38. package/dist/realtime-client/index.d.ts +6 -9
  39. package/dist/realtime-client/index.d.ts.map +1 -1
  40. package/dist/realtime-client/index.js +96 -88
  41. package/dist/realtime-client/index.js.map +1 -1
  42. package/dist/realtime-react/index.d.ts +17 -13
  43. package/dist/realtime-react/index.d.ts.map +1 -1
  44. package/dist/realtime-react/index.js +39 -50
  45. package/dist/realtime-react/index.js.map +1 -1
  46. package/dist/realtime-server/index.d.ts +83 -84
  47. package/dist/realtime-server/index.d.ts.map +1 -1
  48. package/dist/realtime-server/index.js +604 -543
  49. package/dist/realtime-server/index.js.map +1 -1
  50. package/dist/realtime-testing/index.d.ts +5 -4
  51. package/dist/realtime-testing/index.d.ts.map +1 -1
  52. package/dist/realtime-testing/index.js +35 -22
  53. package/dist/realtime-testing/index.js.map +1 -1
  54. package/dist/shared-room-store-BfW3nWif.js +31 -0
  55. package/dist/shared-room-store-BfW3nWif.js.map +1 -0
  56. package/dist/shared-room-store-D2o4ZLjC.d.ts +15 -0
  57. package/dist/shared-room-store-D2o4ZLjC.d.ts.map +1 -0
  58. package/dist/transceivers/set-rtx/index.d.ts.map +1 -1
  59. package/dist/transceivers/set-rtx/index.js +4 -8
  60. package/dist/transceivers/set-rtx/index.js.map +1 -1
  61. package/dist/web/index.d.ts +3 -3
  62. package/dist/web/index.d.ts.map +1 -1
  63. package/dist/web/index.js +4 -3
  64. package/dist/web/index.js.map +1 -1
  65. package/package.json +13 -13
  66. package/src/internal/atom/create-regular-atom.ts +5 -4
  67. package/src/internal/atom/dispose-atom.ts +7 -2
  68. package/src/internal/atom/has-role.ts +3 -3
  69. package/src/internal/caching.ts +4 -2
  70. package/src/internal/families/create-readonly-held-selector-family.ts +2 -1
  71. package/src/internal/families/create-readonly-pure-selector-family.ts +5 -2
  72. package/src/internal/families/create-regular-atom-family.ts +2 -1
  73. package/src/internal/families/create-writable-held-selector-family.ts +2 -1
  74. package/src/internal/families/create-writable-pure-selector-family.ts +5 -2
  75. package/src/internal/families/dispose-from-store.ts +4 -4
  76. package/src/internal/families/find-in-store.ts +10 -10
  77. package/src/internal/families/get-family-of-token.ts +2 -2
  78. package/src/internal/families/index.ts +1 -0
  79. package/src/internal/families/mint-in-store.ts +54 -19
  80. package/src/internal/families/seek-in-store.ts +1 -1
  81. package/src/internal/get-state/get-fallback.ts +2 -2
  82. package/src/internal/get-state/get-from-store.ts +5 -5
  83. package/src/internal/get-state/read-or-compute-value.ts +1 -1
  84. package/src/internal/get-state/reduce-reference.ts +8 -6
  85. package/src/internal/index.ts +2 -220
  86. package/src/internal/molecule.ts +1 -2
  87. package/src/internal/mutable/create-mutable-atom-family.ts +3 -2
  88. package/src/internal/mutable/create-mutable-atom.ts +4 -2
  89. package/src/internal/mutable/get-json-family.ts +1 -1
  90. package/src/internal/mutable/get-update-family.ts +1 -1
  91. package/src/internal/mutable/tracker-family.ts +2 -1
  92. package/src/internal/mutable/tracker.ts +71 -59
  93. package/src/internal/safe-compute.ts +1 -1
  94. package/src/internal/selector/create-readonly-held-selector.ts +2 -1
  95. package/src/internal/selector/create-readonly-pure-selector.ts +2 -1
  96. package/src/internal/selector/create-writable-held-selector.ts +2 -1
  97. package/src/internal/selector/create-writable-pure-selector.ts +2 -1
  98. package/src/internal/selector/dispose-selector.ts +3 -2
  99. package/src/internal/selector/register-selector.ts +8 -5
  100. package/src/internal/selector/trace-selector-atoms.ts +2 -1
  101. package/src/internal/set-state/dispatch-state-update.ts +3 -2
  102. package/src/internal/set-state/evict-downstream.ts +1 -1
  103. package/src/internal/set-state/operate-on-store.ts +16 -22
  104. package/src/internal/set-state/reset-atom-or-selector.ts +5 -3
  105. package/src/internal/set-state/reset-in-store.ts +5 -5
  106. package/src/internal/set-state/set-atom-or-selector.ts +2 -2
  107. package/src/internal/set-state/set-atom.ts +4 -2
  108. package/src/internal/set-state/set-into-store.ts +21 -39
  109. package/src/internal/set-state/set-selector.ts +3 -2
  110. package/src/internal/state-types.ts +228 -0
  111. package/src/internal/store/deposit.ts +4 -4
  112. package/src/internal/store/index.ts +0 -1
  113. package/src/internal/store/store.ts +9 -9
  114. package/src/internal/store/withdraw.ts +4 -4
  115. package/src/internal/subscribe/recall-state.ts +1 -1
  116. package/src/internal/subscribe/subscribe-to-root-atoms.ts +1 -12
  117. package/src/internal/subscribe/subscribe-to-state.ts +9 -0
  118. package/src/internal/subscribe/subscribe-to-transaction.ts +3 -2
  119. package/src/internal/transaction/build-transaction.ts +3 -2
  120. package/src/internal/transaction/index.ts +1 -23
  121. package/src/internal/transaction/is-root-store.ts +4 -1
  122. package/src/internal/transaction/transaction-meta-progress.ts +22 -0
  123. package/src/main/atom.ts +1 -2
  124. package/src/main/find-state.ts +5 -5
  125. package/src/main/get-state.ts +4 -4
  126. package/src/main/realm.ts +2 -2
  127. package/src/main/set-state.ts +10 -10
  128. package/src/react/parse-state-overloads.ts +3 -3
  129. package/src/react/use-i.ts +6 -4
  130. package/src/react/use-loadable.ts +4 -10
  131. package/src/react/use-o.ts +6 -4
  132. package/src/react-devtools/store.ts +6 -6
  133. package/src/realtime/index.ts +1 -0
  134. package/src/realtime/mutex-store.ts +11 -0
  135. package/src/realtime/realtime-continuity.ts +1 -5
  136. package/src/realtime-client/index.ts +0 -1
  137. package/src/realtime-client/pull-atom-family-member.ts +14 -17
  138. package/src/realtime-client/pull-atom.ts +1 -1
  139. package/src/realtime-client/pull-mutable-atom-family-member.ts +16 -12
  140. package/src/realtime-client/pull-selector-family-member.ts +8 -35
  141. package/src/realtime-client/pull-selector-roots.ts +90 -0
  142. package/src/realtime-client/pull-selector.ts +2 -27
  143. package/src/realtime-client/push-state.ts +33 -5
  144. package/src/realtime-client/realtime-client-stores/client-main-store.ts +2 -5
  145. package/src/realtime-react/index.ts +2 -2
  146. package/src/realtime-react/realtime-context.tsx +9 -5
  147. package/src/realtime-react/use-pull-atom-family-member.ts +2 -3
  148. package/src/realtime-react/use-pull-mutable-family-member.ts +2 -3
  149. package/src/realtime-react/use-pull-selector-family-member.ts +5 -6
  150. package/src/realtime-react/use-push.ts +7 -3
  151. package/src/realtime-react/use-realtime-service.ts +11 -11
  152. package/src/realtime-react/use-single-effect.ts +11 -14
  153. package/src/realtime-server/{realtime-server-stores/server-sync-store.ts → continuity/continuity-store.ts} +2 -27
  154. package/src/realtime-server/continuity/provide-continuity.ts +50 -0
  155. package/src/realtime-server/continuity/{subscribe-to-continuity-actions.ts → provide-outcomes.ts} +15 -13
  156. package/src/realtime-server/continuity/{subscribe-to-continuity-perpectives.ts → provide-perspectives.ts} +10 -8
  157. package/src/realtime-server/continuity/{prepare-to-send-initial-payload.ts → provide-startup-payloads.ts} +6 -4
  158. package/src/realtime-server/continuity/receive-action-requests.ts +68 -0
  159. package/src/realtime-server/continuity/track-acknowledgements.ts +46 -0
  160. package/src/realtime-server/employ-socket.ts +14 -0
  161. package/src/realtime-server/index.ts +3 -22
  162. package/src/realtime-server/ipc-sockets/child-socket.ts +125 -66
  163. package/src/realtime-server/ipc-sockets/custom-socket.ts +16 -14
  164. package/src/realtime-server/ipc-sockets/parent-socket.ts +98 -69
  165. package/src/realtime-server/realtime-family-provider.ts +78 -29
  166. package/src/realtime-server/realtime-mutable-family-provider.ts +80 -31
  167. package/src/realtime-server/realtime-mutable-provider.ts +30 -22
  168. package/src/realtime-server/realtime-server-stores/index.ts +0 -2
  169. package/src/realtime-server/realtime-server-stores/server-room-external-store.ts +77 -36
  170. package/src/realtime-server/realtime-server-stores/server-user-store.ts +12 -1
  171. package/src/realtime-server/realtime-state-provider.ts +30 -29
  172. package/src/realtime-server/realtime-state-receiver.ts +62 -16
  173. package/src/realtime-server/server-config.ts +8 -0
  174. package/src/realtime-server/socket-interface.ts +14 -0
  175. package/src/realtime-testing/setup-realtime-test.tsx +70 -31
  176. package/src/web/index.ts +1 -1
  177. package/src/web/{persist-sync.ts → storage-sync.ts} +5 -2
  178. package/src/internal/store/mint-or-counterfeit.ts +0 -108
  179. package/src/realtime-client/server-action.ts +0 -23
  180. package/src/realtime-react/on-mount.ts +0 -5
  181. package/src/realtime-react/use-server-action.ts +0 -19
  182. package/src/realtime-server/continuity/prepare-to-serve-transaction-request.ts +0 -59
  183. package/src/realtime-server/continuity/prepare-to-sync-realtime-continuity.ts +0 -145
  184. package/src/realtime-server/continuity/prepare-to-track-client-acknowledgement.ts +0 -41
  185. package/src/realtime-server/realtime-action-receiver.ts +0 -40
  186. package/src/realtime-server/realtime-server-stores/server-room-external-actions.ts +0 -79
@@ -1,6 +1,6 @@
1
+ import { mutexAtoms } from "../mutex-store-CSvxY9i3.js";
2
+ import { DEFAULT_USER_IN_ROOM_META, roomIndex, usersInMyRoomView, usersInRooms, usersInThisRoomIndex } from "../shared-room-store-BfW3nWif.js";
1
3
  import { IMPLICIT, assignTransactionToContinuity, setEpochNumberOfContinuity } from "atom.io/internal";
2
- import { getInternalRelations, join, mutableAtom, selectorFamily } from "atom.io";
3
- import { SetRTX } from "atom.io/transceivers/set-rtx";
4
4
 
5
5
  //#region src/realtime/realtime-continuity.ts
6
6
  var InvariantMap = class extends Map {
@@ -14,9 +14,6 @@ var InvariantMap = class extends Map {
14
14
  }
15
15
  return super.set(key, value);
16
16
  }
17
- clear() {
18
- throw new Error(`Cannot clear an InvariantMap`);
19
- }
20
17
  };
21
18
  var SyncGroup = class SyncGroup {
22
19
  type = `continuity`;
@@ -42,8 +39,7 @@ var SyncGroup = class SyncGroup {
42
39
  return token;
43
40
  }
44
41
  add(...args) {
45
- const zeroth = args[0];
46
- switch (zeroth.type) {
42
+ switch (args[0].type) {
47
43
  case `atom`:
48
44
  case `mutable_atom`:
49
45
  this.globals.push(...args);
@@ -76,32 +72,5 @@ function continuity(options) {
76
72
  }
77
73
 
78
74
  //#endregion
79
- //#region src/realtime/shared-room-store.ts
80
- const usersInThisRoomIndex = mutableAtom({
81
- key: `usersInRoomIndex`,
82
- class: SetRTX
83
- });
84
- const roomIndex = mutableAtom({
85
- key: `roomIndex`,
86
- class: SetRTX
87
- });
88
- const DEFAULT_USER_IN_ROOM_META = { enteredAtEpoch: 0 };
89
- const usersInRooms = join({
90
- key: `usersInRooms`,
91
- between: [`room`, `user`],
92
- cardinality: `1:n`,
93
- isAType: (input) => typeof input === `string`,
94
- isBType: (input) => typeof input === `string`
95
- }, DEFAULT_USER_IN_ROOM_META);
96
- const usersInMyRoomView = selectorFamily({
97
- key: `usersInMyRoomView`,
98
- get: (myUsername) => ({ find }) => {
99
- const usersInRoomsAtoms = getInternalRelations(usersInRooms);
100
- const myRoomIndex = find(usersInRoomsAtoms, myUsername);
101
- return [myRoomIndex];
102
- }
103
- });
104
-
105
- //#endregion
106
- export { DEFAULT_USER_IN_ROOM_META, InvariantMap, SyncGroup, continuity, roomIndex, usersInMyRoomView, usersInRooms, usersInThisRoomIndex };
75
+ export { DEFAULT_USER_IN_ROOM_META, InvariantMap, SyncGroup, continuity, mutexAtoms, roomIndex, usersInMyRoomView, usersInRooms, usersInThisRoomIndex };
107
76
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["usersInThisRoomIndex: MutableAtomToken<SetRTX<string>>","roomIndex: MutableAtomToken<SetRTX<string>>","DEFAULT_USER_IN_ROOM_META: UserInRoomMeta","usersInRooms: JoinToken<\n\t`room`,\n\tstring,\n\t`user`,\n\tstring,\n\t`1:n`,\n\tUserInRoomMeta\n>","usersInMyRoomView: ReadonlyPureSelectorFamilyToken<\n\tMutableAtomToken<SetRTX<string>>[],\n\tstring\n>"],"sources":["../../src/realtime/realtime-continuity.ts","../../src/realtime/shared-room-store.ts"],"sourcesContent":["import type {\n\tAtomFamilyToken,\n\tAtomToken,\n\tReadableFamilyToken,\n\tReadableToken,\n\tTokenType,\n\tTransactionToken,\n} from \"atom.io\"\nimport {\n\tassignTransactionToContinuity,\n\tIMPLICIT,\n\tsetEpochNumberOfContinuity,\n} from \"atom.io/internal\"\nimport type { Canonical } from \"atom.io/json\"\nimport type { UserKey } from \"atom.io/realtime-server\"\n\n/* eslint-disable no-console */\n\nexport class InvariantMap<K, V> extends Map<K, V> {\n\tpublic set(key: K, value: V): this {\n\t\tif (this.has(key)) {\n\t\t\tconsole.warn(`Tried to set a key that already exists in an InvariantMap`, {\n\t\t\t\tkey,\n\t\t\t\tvalue,\n\t\t\t})\n\t\t\treturn this\n\t\t}\n\t\treturn super.set(key, value)\n\t}\n\n\tpublic clear(): void {\n\t\tthrow new Error(`Cannot clear an InvariantMap`)\n\t}\n}\n\nexport type PerspectiveToken<F extends AtomFamilyToken<any>> = {\n\ttype: `realtime_perspective`\n\tresourceAtoms: F\n\tviewAtoms: ReadableFamilyToken<ReadableToken<TokenType<F>>[], UserKey>\n}\n\nexport type ContinuityToken = {\n\treadonly type: `continuity`\n\treadonly key: string\n\treadonly globals: AtomToken<any>[]\n\treadonly actions: TransactionToken<any>[]\n\treadonly perspectives: PerspectiveToken<AtomFamilyToken<any, Canonical>>[]\n}\n\nexport class SyncGroup {\n\tpublic type = `continuity` as const\n\n\tprotected globals: AtomToken<any>[] = []\n\tprotected actions: TransactionToken<any>[] = []\n\tprotected perspectives: PerspectiveToken<any>[] = []\n\tprotected readonly key: string\n\n\tprotected constructor(key: string) {\n\t\tthis.key = key\n\t}\n\n\tpublic static existing: InvariantMap<string, ContinuityToken> =\n\t\tnew InvariantMap()\n\tpublic static create(\n\t\tkey: string,\n\t\tbuilder: (group: SyncGroup) => SyncGroup,\n\t): ContinuityToken {\n\t\tconst group = new SyncGroup(key)\n\t\tconst { type, globals, actions, perspectives } = builder(group)\n\t\tconst token = { type, key, globals, actions, perspectives }\n\t\tSyncGroup.existing.set(key, token)\n\t\treturn token\n\t}\n\n\tpublic add(...atoms: AtomToken<any>[]): SyncGroup\n\tpublic add(...args: TransactionToken<any>[]): SyncGroup\n\tpublic add<\n\t\tF extends AtomFamilyToken<any>,\n\t\tT extends F extends AtomFamilyToken<infer U> ? U : never,\n\t>(\n\t\tfamily: AtomFamilyToken<T, any>,\n\t\tindex: ReadableFamilyToken<Iterable<AtomToken<T>>, string>,\n\t): SyncGroup\n\tpublic add(\n\t\t...args:\n\t\t\t| readonly AtomToken<any>[]\n\t\t\t| readonly TransactionToken<any>[]\n\t\t\t| [AtomFamilyToken<any, any>, ReadableFamilyToken<Iterable<any>, string>]\n\t): this {\n\t\tconst zeroth = args[0]\n\t\tswitch (zeroth.type) {\n\t\t\tcase `atom`:\n\t\t\tcase `mutable_atom`:\n\t\t\t\tthis.globals.push(...(args as AtomToken<any>[]))\n\t\t\t\tbreak\n\t\t\tcase `transaction`:\n\t\t\t\tthis.actions.push(...(args as TransactionToken<any>[]))\n\t\t\t\tbreak\n\t\t\tcase `atom_family`:\n\t\t\tcase `mutable_atom_family`:\n\t\t\t\t{\n\t\t\t\t\tconst [family, index] = args as [\n\t\t\t\t\t\tAtomFamilyToken<any, any>,\n\t\t\t\t\t\tReadableFamilyToken<ReadableToken<any>[], UserKey>,\n\t\t\t\t\t]\n\t\t\t\t\tthis.perspectives.push({\n\t\t\t\t\t\ttype: `realtime_perspective`,\n\t\t\t\t\t\tresourceAtoms: family,\n\t\t\t\t\t\tviewAtoms: index,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t}\n\n\t\treturn this\n\t}\n}\n\nexport type ContinuityOptions = {\n\tkey: string\n\tconfig: (group: SyncGroup) => SyncGroup\n}\n\nexport function continuity(options: ContinuityOptions): ContinuityToken {\n\tconst { key, config } = options\n\tconst token = SyncGroup.create(key, config)\n\tconst { actions } = token\n\tfor (const action of actions) {\n\t\tassignTransactionToContinuity(IMPLICIT.STORE, key, action.key)\n\t}\n\tsetEpochNumberOfContinuity(IMPLICIT.STORE, key, -1)\n\treturn token\n}\n\n// const counterStates = atomFamily<number, { c: string }>({\n// \tkey: `counter`,\n// \tdefault: 0,\n// })\n// const counterIndices = atomFamily<{ c: string }[], string>({\n// \tkey: `counterIndex`,\n// \tdefault: [],\n// })\n// const nameStates = atomFamily<number, { n: string }>({\n// \tkey: `name`,\n// \tdefault: 0,\n// })\n// const nameIndices = atomFamily<{ n: string }[], string>({\n// \tkey: `nameIndex`,\n// \tdefault: [],\n// })\n\n// const counterContinuity = continuity({\n// \tkey: `counter`,\n// \tconfig: (group) =>\n// \t\tgroup\n// \t\t\t.add(counterStates, counterIndices)\n// \t\t\t.add(nameStates, nameIndices)\n// \t\t\t.add(nameStates, nameIndices)\n// \t\t\t.add(nameStates, nameIndices),\n// })\n","import type {\n\tJoinToken,\n\tMutableAtomToken,\n\tReadonlyPureSelectorFamilyToken,\n} from \"atom.io\"\nimport { getInternalRelations, join, mutableAtom, selectorFamily } from \"atom.io\"\nimport { SetRTX } from \"atom.io/transceivers/set-rtx\"\n\nexport const usersInThisRoomIndex: MutableAtomToken<SetRTX<string>> =\n\tmutableAtom<SetRTX<string>>({\n\t\tkey: `usersInRoomIndex`,\n\t\tclass: SetRTX,\n\t})\n\nexport const roomIndex: MutableAtomToken<SetRTX<string>> = mutableAtom<\n\tSetRTX<string>\n>({\n\tkey: `roomIndex`,\n\tclass: SetRTX,\n})\n\nexport type UserInRoomMeta = {\n\tenteredAtEpoch: number\n}\nexport const DEFAULT_USER_IN_ROOM_META: UserInRoomMeta = {\n\tenteredAtEpoch: 0,\n}\nexport const usersInRooms: JoinToken<\n\t`room`,\n\tstring,\n\t`user`,\n\tstring,\n\t`1:n`,\n\tUserInRoomMeta\n> = join(\n\t{\n\t\tkey: `usersInRooms`,\n\t\tbetween: [`room`, `user`],\n\t\tcardinality: `1:n`,\n\t\tisAType: (input): input is string => typeof input === `string`,\n\t\tisBType: (input): input is string => typeof input === `string`,\n\t},\n\tDEFAULT_USER_IN_ROOM_META,\n)\n\nexport const usersInMyRoomView: ReadonlyPureSelectorFamilyToken<\n\tMutableAtomToken<SetRTX<string>>[],\n\tstring\n> = selectorFamily<MutableAtomToken<SetRTX<string>>[], string>({\n\tkey: `usersInMyRoomView`,\n\tget:\n\t\t(myUsername) =>\n\t\t({ find }) => {\n\t\t\tconst usersInRoomsAtoms = getInternalRelations(usersInRooms)\n\t\t\tconst myRoomIndex = find(usersInRoomsAtoms, myUsername)\n\t\t\treturn [myRoomIndex]\n\t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B,KAAK;CACL,OAAO;;AAGT,MAAaC,YAA8C,YAEzD;CACD,KAAK;CACL,OAAO;;AAMR,MAAaC,4BAA4C,EACxD,gBAAgB;AAEjB,MAAaC,eAOT,KACH;CACC,KAAK;CACL,SAAS,CAAC,QAAQ;CAClB,aAAa;CACb,UAAU,UAA2B,OAAO,UAAU;CACtD,UAAU,UAA2B,OAAO,UAAU;GAEvD;AAGD,MAAaC,oBAGT,eAA2D;CAC9D,KAAK;CACL,MACE,gBACA,EAAE,WAAW;EACb,MAAM,oBAAoB,qBAAqB;EAC/C,MAAM,cAAc,KAAK,mBAAmB;AAC5C,SAAO,CAAC"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/realtime/realtime-continuity.ts"],"sourcesContent":["import type {\n\tAtomFamilyToken,\n\tAtomToken,\n\tReadableFamilyToken,\n\tReadableToken,\n\tTokenType,\n\tTransactionToken,\n} from \"atom.io\"\nimport {\n\tassignTransactionToContinuity,\n\tIMPLICIT,\n\tsetEpochNumberOfContinuity,\n} from \"atom.io/internal\"\nimport type { Canonical } from \"atom.io/json\"\nimport type { UserKey } from \"atom.io/realtime-server\"\n\n/* eslint-disable no-console */\n\nexport class InvariantMap<K, V> extends Map<K, V> implements ReadonlyMap<K, V> {\n\tpublic set(key: K, value: V): this {\n\t\tif (this.has(key)) {\n\t\t\tconsole.warn(`Tried to set a key that already exists in an InvariantMap`, {\n\t\t\t\tkey,\n\t\t\t\tvalue,\n\t\t\t})\n\t\t\treturn this\n\t\t}\n\t\treturn super.set(key, value)\n\t}\n}\n\nexport type PerspectiveToken<F extends AtomFamilyToken<any>> = {\n\ttype: `realtime_perspective`\n\tresourceAtoms: F\n\tviewAtoms: ReadableFamilyToken<ReadableToken<TokenType<F>>[], UserKey>\n}\n\nexport type ContinuityToken = {\n\treadonly type: `continuity`\n\treadonly key: string\n\treadonly globals: AtomToken<any>[]\n\treadonly actions: TransactionToken<any>[]\n\treadonly perspectives: PerspectiveToken<AtomFamilyToken<any, Canonical>>[]\n}\n\nexport class SyncGroup {\n\tpublic type = `continuity` as const\n\n\tprotected globals: AtomToken<any>[] = []\n\tprotected actions: TransactionToken<any>[] = []\n\tprotected perspectives: PerspectiveToken<any>[] = []\n\tprotected readonly key: string\n\n\tprotected constructor(key: string) {\n\t\tthis.key = key\n\t}\n\n\tpublic static existing: InvariantMap<string, ContinuityToken> =\n\t\tnew InvariantMap()\n\tpublic static create(\n\t\tkey: string,\n\t\tbuilder: (group: SyncGroup) => SyncGroup,\n\t): ContinuityToken {\n\t\tconst group = new SyncGroup(key)\n\t\tconst { type, globals, actions, perspectives } = builder(group)\n\t\tconst token = { type, key, globals, actions, perspectives }\n\t\tSyncGroup.existing.set(key, token)\n\t\treturn token\n\t}\n\n\tpublic add(...atoms: AtomToken<any>[]): SyncGroup\n\tpublic add(...args: TransactionToken<any>[]): SyncGroup\n\tpublic add<\n\t\tF extends AtomFamilyToken<any>,\n\t\tT extends F extends AtomFamilyToken<infer U> ? U : never,\n\t>(\n\t\tfamily: AtomFamilyToken<T, any>,\n\t\tindex: ReadableFamilyToken<Iterable<AtomToken<T>>, string>,\n\t): SyncGroup\n\tpublic add(\n\t\t...args:\n\t\t\t| readonly AtomToken<any>[]\n\t\t\t| readonly TransactionToken<any>[]\n\t\t\t| [AtomFamilyToken<any, any>, ReadableFamilyToken<Iterable<any>, string>]\n\t): this {\n\t\tconst zeroth = args[0]\n\t\tswitch (zeroth.type) {\n\t\t\tcase `atom`:\n\t\t\tcase `mutable_atom`:\n\t\t\t\tthis.globals.push(...(args as AtomToken<any>[]))\n\t\t\t\tbreak\n\t\t\tcase `transaction`:\n\t\t\t\tthis.actions.push(...(args as TransactionToken<any>[]))\n\t\t\t\tbreak\n\t\t\tcase `atom_family`:\n\t\t\tcase `mutable_atom_family`:\n\t\t\t\t{\n\t\t\t\t\tconst [family, index] = args as [\n\t\t\t\t\t\tAtomFamilyToken<any, any>,\n\t\t\t\t\t\tReadableFamilyToken<ReadableToken<any>[], UserKey>,\n\t\t\t\t\t]\n\t\t\t\t\tthis.perspectives.push({\n\t\t\t\t\t\ttype: `realtime_perspective`,\n\t\t\t\t\t\tresourceAtoms: family,\n\t\t\t\t\t\tviewAtoms: index,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t}\n\n\t\treturn this\n\t}\n}\n\nexport type ContinuityOptions = {\n\tkey: string\n\tconfig: (group: SyncGroup) => SyncGroup\n}\n\nexport function continuity(options: ContinuityOptions): ContinuityToken {\n\tconst { key, config } = options\n\tconst token = SyncGroup.create(key, config)\n\tconst { actions } = token\n\tfor (const action of actions) {\n\t\tassignTransactionToContinuity(IMPLICIT.STORE, key, action.key)\n\t}\n\tsetEpochNumberOfContinuity(IMPLICIT.STORE, key, -1)\n\treturn token\n}\n\n// const counterStates = atomFamily<number, { c: string }>({\n// \tkey: `counter`,\n// \tdefault: 0,\n// })\n// const counterIndices = atomFamily<{ c: string }[], string>({\n// \tkey: `counterIndex`,\n// \tdefault: [],\n// })\n// const nameStates = atomFamily<number, { n: string }>({\n// \tkey: `name`,\n// \tdefault: 0,\n// })\n// const nameIndices = atomFamily<{ n: string }[], string>({\n// \tkey: `nameIndex`,\n// \tdefault: [],\n// })\n\n// const counterContinuity = continuity({\n// \tkey: `counter`,\n// \tconfig: (group) =>\n// \t\tgroup\n// \t\t\t.add(counterStates, counterIndices)\n// \t\t\t.add(nameStates, nameIndices)\n// \t\t\t.add(nameStates, nameIndices)\n// \t\t\t.add(nameStates, nameIndices),\n// })\n"],"mappings":";;;;;AAkBA,IAAa,eAAb,cAAwC,IAAuC;CAC9E,AAAO,IAAI,KAAQ,OAAgB;AAClC,MAAI,KAAK,IAAI,IAAI,EAAE;AAClB,WAAQ,KAAK,6DAA6D;IACzE;IACA;IACA,CAAC;AACF,UAAO;;AAER,SAAO,MAAM,IAAI,KAAK,MAAM;;;AAkB9B,IAAa,YAAb,MAAa,UAAU;CACtB,AAAO,OAAO;CAEd,AAAU,UAA4B,EAAE;CACxC,AAAU,UAAmC,EAAE;CAC/C,AAAU,eAAwC,EAAE;CACpD,AAAmB;CAEnB,AAAU,YAAY,KAAa;AAClC,OAAK,MAAM;;CAGZ,OAAc,WACb,IAAI,cAAc;CACnB,OAAc,OACb,KACA,SACkB;EAClB,MAAM,QAAQ,IAAI,UAAU,IAAI;EAChC,MAAM,EAAE,MAAM,SAAS,SAAS,iBAAiB,QAAQ,MAAM;EAC/D,MAAM,QAAQ;GAAE;GAAM;GAAK;GAAS;GAAS;GAAc;AAC3D,YAAU,SAAS,IAAI,KAAK,MAAM;AAClC,SAAO;;CAYR,AAAO,IACN,GAAG,MAII;AAEP,UADe,KAAK,GACL,MAAf;GACC,KAAK;GACL,KAAK;AACJ,SAAK,QAAQ,KAAK,GAAI,KAA0B;AAChD;GACD,KAAK;AACJ,SAAK,QAAQ,KAAK,GAAI,KAAiC;AACvD;GACD,KAAK;GACL,KAAK;IACJ;KACC,MAAM,CAAC,QAAQ,SAAS;AAIxB,UAAK,aAAa,KAAK;MACtB,MAAM;MACN,eAAe;MACf,WAAW;MACX,CAAC;;AAEH;;AAGF,SAAO;;;AAST,SAAgB,WAAW,SAA6C;CACvE,MAAM,EAAE,KAAK,WAAW;CACxB,MAAM,QAAQ,UAAU,OAAO,KAAK,OAAO;CAC3C,MAAM,EAAE,YAAY;AACpB,MAAK,MAAM,UAAU,QACpB,+BAA8B,SAAS,OAAO,KAAK,OAAO,IAAI;AAE/D,4BAA2B,SAAS,OAAO,KAAK,GAAG;AACnD,QAAO"}
@@ -1,7 +1,7 @@
1
1
  import { Fn, RootStore, Store, Transceiver } from "atom.io/internal";
2
- import { Json } from "atom.io/json";
3
2
  import * as AtomIO from "atom.io";
4
3
  import { AtomToken, WritableToken } from "atom.io";
4
+ import { Canonical, Json } from "atom.io/json";
5
5
  import { ContinuityToken } from "atom.io/realtime";
6
6
  import { Socket } from "atom.io/realtime-server";
7
7
  import { Socket as Socket$1 } from "socket.io-client";
@@ -16,22 +16,22 @@ declare function useConcealState(store: Store): (concealed: AtomToken<unknown>[]
16
16
  declare function useRevealState(store: Store): (revealed: Json.Array) => void;
17
17
  //#endregion
18
18
  //#region src/realtime-client/pull-atom.d.ts
19
- declare function pullAtom<J extends Json.Serializable>(store: Store, socket: Socket$1, token: AtomIO.RegularAtomToken<J>): () => void;
19
+ declare function pullAtom<J extends Json.Serializable>(store: Store, socket: Socket$1, token: AtomIO.RegularAtomToken<J, any, any>): () => void;
20
20
  //#endregion
21
21
  //#region src/realtime-client/pull-atom-family-member.d.ts
22
- declare function pullAtomFamilyMember<J extends Json.Serializable>(store: Store, socket: Socket$1, token: AtomIO.RegularAtomToken<J>): () => void;
22
+ declare function pullAtomFamilyMember<J extends Json.Serializable, K extends Canonical>(store: Store, socket: Socket$1, family: AtomIO.AtomFamilyToken<J, K, any>, key: NoInfer<K>): () => void;
23
23
  //#endregion
24
24
  //#region src/realtime-client/pull-mutable-atom.d.ts
25
25
  declare function pullMutableAtom<T extends Transceiver<any, any, any>>(store: Store, socket: Socket$1, token: AtomIO.MutableAtomToken<T>): () => void;
26
26
  //#endregion
27
27
  //#region src/realtime-client/pull-mutable-atom-family-member.d.ts
28
- declare function pullMutableAtomFamilyMember<T extends Transceiver<any, any, any>>(store: Store, socket: Socket$1, token: AtomIO.MutableAtomToken<T>): () => void;
28
+ declare function pullMutableAtomFamilyMember<T extends Transceiver<any, any, any>, K extends Canonical>(store: Store, socket: Socket$1, family: AtomIO.MutableAtomFamilyToken<T, K>, key: NoInfer<K>): () => void;
29
29
  //#endregion
30
30
  //#region src/realtime-client/pull-selector.d.ts
31
31
  declare function pullSelector<T>(store: Store, socket: Socket$1, token: AtomIO.SelectorToken<T>): () => void;
32
32
  //#endregion
33
33
  //#region src/realtime-client/pull-selector-family-member.d.ts
34
- declare function pullSelectorFamilyMember<T>(store: Store, socket: Socket$1, token: AtomIO.SelectorToken<T>): () => void;
34
+ declare function pullSelectorFamilyMember<T, K extends Canonical>(store: Store, socket: Socket$1, familyToken: AtomIO.SelectorFamilyToken<T, K>, key: NoInfer<K>): () => void;
35
35
  //#endregion
36
36
  //#region src/realtime-client/push-state.d.ts
37
37
  declare function pushState<J extends Json.Serializable>(store: Store, socket: Socket$1, token: WritableToken<J>): () => void;
@@ -45,11 +45,8 @@ declare const myUsernameState: AtomIO.RegularAtomToken<string | null>;
45
45
  declare const optimisticUpdateQueue: AtomIO.RegularAtomToken<AtomIO.TransactionOutcomeEvent<any>[]>;
46
46
  declare const confirmedUpdateQueue: AtomIO.RegularAtomToken<AtomIO.TransactionOutcomeEvent<any>[]>;
47
47
  //#endregion
48
- //#region src/realtime-client/server-action.d.ts
49
- declare function serverAction<F extends Fn>(store: Store, socket: Socket$1, token: AtomIO.TransactionToken<F>): () => void;
50
- //#endregion
51
48
  //#region src/realtime-client/sync-continuity.d.ts
52
49
  declare function syncContinuity(store: RootStore, socket: Socket$1, continuity: ContinuityToken): () => void;
53
50
  //#endregion
54
- export { confirmedUpdateQueue, myIdState, myIdState__INTERNAL, myUsernameState, optimisticUpdateQueue, pullAtom, pullAtomFamilyMember, pullMutableAtom, pullMutableAtomFamilyMember, pullSelector, pullSelectorFamilyMember, pushState, serverAction, syncContinuity, useConcealState, useRegisterAndAttemptConfirmedUpdate, useRevealState };
51
+ export { confirmedUpdateQueue, myIdState, myIdState__INTERNAL, myUsernameState, optimisticUpdateQueue, pullAtom, pullAtomFamilyMember, pullMutableAtom, pullMutableAtomFamilyMember, pullSelector, pullSelectorFamilyMember, pushState, syncContinuity, useConcealState, useRegisterAndAttemptConfirmedUpdate, useRevealState };
55
52
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":["myIdState__INTERNAL: AtomIO.RegularAtomToken<string | undefined>","myIdState: AtomIO.ReadonlyPureSelectorToken<string | undefined>","myUsernameState: AtomIO.RegularAtomToken<string | null>","optimisticUpdateQueue: AtomIO.RegularAtomToken<\n\tAtomIO.TransactionOutcomeEvent<any>[]\n>","confirmedUpdateQueue: AtomIO.RegularAtomToken<\n\tAtomIO.TransactionOutcomeEvent<any>[]\n>"],"sources":["../../src/realtime-client/continuity/register-and-attempt-confirmed-update.ts","../../src/realtime-client/continuity/use-conceal-state.ts","../../src/realtime-client/continuity/use-reveal-state.ts","../../src/realtime-client/pull-atom.ts","../../src/realtime-client/pull-atom-family-member.ts","../../src/realtime-client/pull-mutable-atom.ts","../../src/realtime-client/pull-mutable-atom-family-member.ts","../../src/realtime-client/pull-selector.ts","../../src/realtime-client/pull-selector-family-member.ts","../../src/realtime-client/push-state.ts","../../src/realtime-client/realtime-client-stores/client-main-store.ts","../../src/realtime-client/realtime-client-stores/client-sync-store.ts","../../src/realtime-client/server-action.ts","../../src/realtime-client/sync-continuity.ts"],"sourcesContent":[],"mappings":";;;;;;;;;cAea,8CAEJ,0CAEC,2BACW,MAAA,CAAO,wBACzB,MAAA,CAAO,iBAAiB,0BAEP,MAAA,CAAO,wBACxB,MAAA,CAAO,iBAAiB,uBAId,MAAA,CAAO,wBAAwB,MAAA,CAAO,iBAAiB;;;iBCxBpD,eAAA,QAAuB,oBACnB;;;iBCFJ,cAAA,QAAsB,mBACnB,IAAA,CAAK;;;iBCCR,mBAAmB,IAAA,CAAK,qBAChC,eACC,iBACD,MAAA,CAAO,iBAAiB;;;iBCAhB,+BAA+B,IAAA,CAAK,qBAC5C,eACC,iBACD,MAAA,CAAO,iBAAiB;;;iBCNhB,0BAA0B,mCAClC,eACC,iBACD,MAAA,CAAO,iBAAiB;;;iBCAhB,sCACL,mCACF,eAAe,iBAAe,MAAA,CAAO,iBAAiB;;;iBCH/C,uBACR,eACC,iBACD,MAAA,CAAO,cAAc;;;iBCDb,mCACR,eACC,iBACD,MAAA,CAAO,cAAc;;;iBCNb,oBAAoB,IAAA,CAAK,qBACjC,eACC,iBACD,cAAc;;;cCNTA,qBAAqB,MAAA,CAAO;cAK5BC,WAAW,MAAA,CAAO;cAMlBC,iBAAiB,MAAA,CAAO;;;cCZxBC,uBAAuB,MAAA,CAAO,iBAC1C,MAAA,CAAO;cAMKC,sBAAsB,MAAA,CAAO,iBACzC,MAAA,CAAO;;;iBCLQ,uBAAuB,WAC/B,eACC,iBACD,MAAA,CAAO,iBAAiB;;;iBCahB,cAAA,QACR,mBACC,sBACI"}
1
+ {"version":3,"file":"index.d.ts","names":["myIdState__INTERNAL: AtomIO.RegularAtomToken<string | undefined>","myIdState: AtomIO.ReadonlyPureSelectorToken<string | undefined>","myUsernameState: AtomIO.RegularAtomToken<string | null>","optimisticUpdateQueue: AtomIO.RegularAtomToken<\n\tAtomIO.TransactionOutcomeEvent<any>[]\n>","confirmedUpdateQueue: AtomIO.RegularAtomToken<\n\tAtomIO.TransactionOutcomeEvent<any>[]\n>"],"sources":["../../src/realtime-client/continuity/register-and-attempt-confirmed-update.ts","../../src/realtime-client/continuity/use-conceal-state.ts","../../src/realtime-client/continuity/use-reveal-state.ts","../../src/realtime-client/pull-atom.ts","../../src/realtime-client/pull-atom-family-member.ts","../../src/realtime-client/pull-mutable-atom.ts","../../src/realtime-client/pull-mutable-atom-family-member.ts","../../src/realtime-client/pull-selector.ts","../../src/realtime-client/pull-selector-family-member.ts","../../src/realtime-client/push-state.ts","../../src/realtime-client/realtime-client-stores/client-main-store.ts","../../src/realtime-client/realtime-client-stores/client-sync-store.ts","../../src/realtime-client/sync-continuity.ts"],"sourcesContent":[],"mappings":";;;;;;;;;cAea,8CAEJ,0CAEC,2BACW,MAAA,CAAO,wBACzB,MAAA,CAAO,iBAAiB,0BAEP,MAAA,CAAO,wBACxB,MAAA,CAAO,iBAAiB,uBAId,MAAA,CAAO,wBAAwB,MAAA,CAAO,iBAAiB;;;iBCxBpD,eAAA,QAAuB,oBACnB;;;iBCFJ,cAAA,QAAsB,mBACnB,IAAA,CAAK;;;iBCCR,mBAAmB,IAAA,CAAK,qBAChC,eACC,iBACD,MAAA,CAAO,iBAAiB;;;iBCHhB,+BACL,IAAA,CAAK,wBACL,kBAEH,eACC,kBACA,MAAA,CAAO,gBAAgB,GAAG,cAC7B,QAAQ;;;iBCPE,0BAA0B,mCAClC,eACC,iBACD,MAAA,CAAO,iBAAiB;;;iBCGhB,sCACL,sCACA,kBAEH,eACC,kBACA,MAAA,CAAO,uBAAuB,GAAG,SACpC,QAAQ;;;iBCZE,uBACR,eACC,iBACD,MAAA,CAAO,cAAc;;;iBCDb,sCAAsC,kBAC9C,eACC,uBACK,MAAA,CAAO,oBAAoB,GAAG,SACtC,QAAQ;;;iBCJE,oBAAoB,IAAA,CAAK,qBACjC,eACC,iBACD,cAAc;;;cCRTA,qBAAqB,MAAA,CAAO;cAK5BC,WAAW,MAAA,CAAO;cAMlBC,iBAAiB,MAAA,CAAO;;;cCZxBC,uBAAuB,MAAA,CAAO,iBAC1C,MAAA,CAAO;cAMKC,sBAAsB,MAAA,CAAO,iBACzC,MAAA,CAAO;;;iBCWQ,cAAA,QACR,mBACC,sBACI"}
@@ -1,7 +1,9 @@
1
- import { actUponStore, assignTransactionToContinuity, disposeAtom, getEpochNumberOfContinuity, getFromStore, getJsonToken, getUpdateToken, ingestTransactionOutcomeEvent, setEpochNumberOfContinuity, setIntoStore, subscribeToState, subscribeToTransaction } from "atom.io/internal";
2
- import { parseJson } from "atom.io/json";
1
+ import { mutexAtoms } from "../mutex-store-CSvxY9i3.js";
2
+ import { employSocket } from "../employ-socket-D6wgByWh.js";
3
+ import { actUponStore, assignTransactionToContinuity, disposeAtom, findInStore, getEpochNumberOfContinuity, getFamilyOfToken, getFromStore, getJsonToken, getUpdateToken, ingestTransactionOutcomeEvent, setEpochNumberOfContinuity, setIntoStore, subscribeToState, subscribeToTransaction } from "atom.io/internal";
3
4
  import * as AtomIO from "atom.io";
4
- import { persistSync } from "atom.io/web";
5
+ import { parseJson } from "atom.io/json";
6
+ import { storageSync } from "atom.io/web";
5
7
  import { confirmedUpdateQueue as confirmedUpdateQueue$1, optimisticUpdateQueue as optimisticUpdateQueue$1 } from "atom.io/realtime-client";
6
8
 
7
9
  //#region src/realtime-client/continuity/register-and-attempt-confirmed-update.ts
@@ -58,8 +60,7 @@ const useRegisterAndAttemptConfirmedUpdate = (store, continuityKey, socket, opti
58
60
  }
59
61
  } else {
60
62
  store.logger.info(`🧑‍⚖️`, `continuity`, continuityKey, `epoch of confirmed update #${confirmed.epoch} does not match zeroth optimistic update #${zerothOptimisticUpdate.epoch}`);
61
- const confirmedUpdateIsAlreadyEnqueued = confirmedUpdates.some((update) => update.epoch === confirmed.epoch);
62
- if (!confirmedUpdateIsAlreadyEnqueued) {
63
+ if (!confirmedUpdates.some((update) => update.epoch === confirmed.epoch)) {
63
64
  store.logger.info(`👈`, `continuity`, continuityKey, `pushing confirmed update to queue`, confirmed);
64
65
  setIntoStore(store, confirmedUpdateQueue$1, (queue) => {
65
66
  queue.push(confirmed);
@@ -70,8 +71,7 @@ const useRegisterAndAttemptConfirmedUpdate = (store, continuityKey, socket, opti
70
71
  }
71
72
  } else {
72
73
  store.logger.info(`🧑‍⚖️`, `continuity`, continuityKey, `has no optimistic updates to deal with`);
73
- let continuityEpoch;
74
- continuityEpoch = getEpochNumberOfContinuity(store, continuityKey);
74
+ let continuityEpoch = getEpochNumberOfContinuity(store, continuityKey);
75
75
  if (continuityEpoch === confirmed.epoch - 1) {
76
76
  store.logger.info(`✅`, `continuity`, continuityKey, `integrating update #${confirmed.epoch} (${confirmed.token.key} ${confirmed.id})`);
77
77
  ingestTransactionOutcomeEvent(store, confirmed, `newValue`);
@@ -82,8 +82,7 @@ const useRegisterAndAttemptConfirmedUpdate = (store, continuityKey, socket, opti
82
82
  clientEpoch: continuityEpoch,
83
83
  serverEpoch: confirmed.epoch
84
84
  });
85
- const confirmedUpdateIsAlreadyEnqueued = confirmedUpdates.some((update) => update.epoch === confirmed.epoch);
86
- if (confirmedUpdateIsAlreadyEnqueued) store.logger.info(`👍`, `continuity`, continuityKey, `confirmed update #${confirmed.epoch} is already enqueued`);
85
+ if (confirmedUpdates.some((update) => update.epoch === confirmed.epoch)) store.logger.info(`👍`, `continuity`, continuityKey, `confirmed update #${confirmed.epoch} is already enqueued`);
87
86
  else {
88
87
  store.logger.info(`👈`, `continuity`, continuityKey, `pushing confirmed update #${confirmed.epoch} to queue`);
89
88
  setIntoStore(store, confirmedUpdateQueue$1, (queue) => {
@@ -138,19 +137,15 @@ function pullAtom(store, socket, token) {
138
137
 
139
138
  //#endregion
140
139
  //#region src/realtime-client/pull-atom-family-member.ts
141
- function pullAtomFamilyMember(store, socket, token) {
142
- if (!(`family` in token)) {
143
- console.error(`Token is not a family member:`, token);
144
- return () => {};
145
- }
146
- const { key: familyKey, subKey: serializedSubKey } = token.family;
147
- const subKey = parseJson(serializedSubKey);
148
- socket?.on(`serve:${token.key}`, (data) => {
140
+ function pullAtomFamilyMember(store, socket, family, key) {
141
+ const token = findInStore(store, family, key);
142
+ const setServedValue = (data) => {
149
143
  setIntoStore(store, token, data);
150
- });
151
- socket?.emit(`sub:${familyKey}`, subKey);
144
+ };
145
+ socket?.on(`serve:${token.key}`, setServedValue);
146
+ socket?.emit(`sub:${family.key}`, key);
152
147
  return () => {
153
- socket?.off(`serve:${token.key}`);
148
+ socket?.off(`serve:${token.key}`, setServedValue);
154
149
  socket?.emit(`unsub:${token.key}`);
155
150
  };
156
151
  }
@@ -176,13 +171,8 @@ function pullMutableAtom(store, socket, token) {
176
171
 
177
172
  //#endregion
178
173
  //#region src/realtime-client/pull-mutable-atom-family-member.ts
179
- function pullMutableAtomFamilyMember(store, socket, token) {
180
- if (!(`family` in token)) {
181
- console.error(`Token is not a family member:`, token);
182
- return () => {};
183
- }
184
- const { key: familyKey, subKey: serializedSubKey } = token.family;
185
- const subKey = parseJson(serializedSubKey);
174
+ function pullMutableAtomFamilyMember(store, socket, family, key) {
175
+ const token = findInStore(store, family, key);
186
176
  socket.on(`init:${token.key}`, (data) => {
187
177
  const jsonToken = getJsonToken(store, token);
188
178
  setIntoStore(store, jsonToken, data);
@@ -191,7 +181,7 @@ function pullMutableAtomFamilyMember(store, socket, token) {
191
181
  const trackerToken = getUpdateToken(token);
192
182
  setIntoStore(store, trackerToken, data);
193
183
  });
194
- socket.emit(`sub:${familyKey}`, subKey);
184
+ socket.emit(`sub:${family.key}`, key);
195
185
  return () => {
196
186
  socket.off(`serve:${token.key}`);
197
187
  socket.emit(`unsub:${token.key}`);
@@ -199,62 +189,92 @@ function pullMutableAtomFamilyMember(store, socket, token) {
199
189
  }
200
190
 
201
191
  //#endregion
202
- //#region src/realtime-client/pull-selector.ts
203
- function pullSelector(store, socket, token) {
204
- const atomKeys = store.selectorAtoms.getRelatedKeys(token.key);
205
- const unsubscribes = [];
206
- if (atomKeys) for (const atomKey of atomKeys) {
207
- const atom = store.atoms.get(atomKey);
208
- if (!atom) continue;
209
- switch (atom.type) {
210
- case `atom`:
211
- unsubscribes.push(pullAtom(store, socket, atom));
212
- break;
213
- case `mutable_atom`:
214
- unsubscribes.push(pullMutableAtom(store, socket, atom));
215
- break;
192
+ //#region src/realtime-client/pull-selector-roots.ts
193
+ function pullSelectorRoots(store, socket, selectorToken) {
194
+ const atomSubscriptions = /* @__PURE__ */ new Map();
195
+ const clearAtomSubscriptions = () => {
196
+ for (const [, unsub] of atomSubscriptions) unsub();
197
+ atomSubscriptions.clear();
198
+ };
199
+ const start = () => {
200
+ const atomKeys = store.selectorAtoms.getRelatedKeys(selectorToken.key);
201
+ if (atomKeys) {
202
+ for (const [atomKey, unsub] of atomSubscriptions) if (!atomKeys.has(atomKey)) {
203
+ unsub();
204
+ atomSubscriptions.delete(atomKey);
205
+ }
206
+ for (const atomKey of atomKeys) {
207
+ if (atomSubscriptions.has(atomKey)) continue;
208
+ const atom = store.atoms.get(atomKey);
209
+ switch (atom.type) {
210
+ case `atom`:
211
+ if (atom.family) {
212
+ const { subKey: serializedSubKey } = atom.family;
213
+ const subKey = parseJson(serializedSubKey);
214
+ const family = getFamilyOfToken(store, atom);
215
+ atomSubscriptions.set(atomKey, pullAtomFamilyMember(store, socket, family, subKey));
216
+ } else atomSubscriptions.set(atomKey, pullAtom(store, socket, atom));
217
+ break;
218
+ case `mutable_atom`:
219
+ if (atom.family) {
220
+ const { subKey: serializedSubKey } = atom.family;
221
+ const subKey = parseJson(serializedSubKey);
222
+ const family = getFamilyOfToken(store, atom);
223
+ atomSubscriptions.set(atomKey, pullMutableAtomFamilyMember(store, socket, family, subKey));
224
+ } else atomSubscriptions.set(atomKey, pullMutableAtom(store, socket, atom));
225
+ break;
226
+ }
227
+ }
216
228
  }
217
- }
229
+ };
230
+ const unsubFromSelector = subscribeToState(store, selectorToken, `pull-watches-dependencies`, () => {
231
+ start();
232
+ });
233
+ start();
218
234
  return () => {
219
- for (const unsubscribe of unsubscribes) unsubscribe();
235
+ clearAtomSubscriptions();
236
+ unsubFromSelector();
220
237
  };
221
238
  }
222
239
 
240
+ //#endregion
241
+ //#region src/realtime-client/pull-selector.ts
242
+ function pullSelector(store, socket, token) {
243
+ return pullSelectorRoots(store, socket, token);
244
+ }
245
+
223
246
  //#endregion
224
247
  //#region src/realtime-client/pull-selector-family-member.ts
225
- function pullSelectorFamilyMember(store, socket, token) {
226
- if (!(`family` in token)) {
227
- console.error(`Token is not a family member:`, token);
228
- return () => {};
229
- }
230
- const atomKeys = store.selectorAtoms.getRelatedKeys(token.key);
231
- const unsubscribes = [];
232
- if (atomKeys) for (const atomKey of atomKeys) {
233
- const atom = store.atoms.get(atomKey);
234
- if (!atom) continue;
235
- switch (atom.type) {
236
- case `atom`:
237
- unsubscribes.push(pullAtomFamilyMember(store, socket, atom));
238
- break;
239
- case `mutable_atom`:
240
- unsubscribes.push(pullMutableAtomFamilyMember(store, socket, atom));
241
- break;
242
- }
243
- }
244
- return () => {
245
- for (const unsubscribe of unsubscribes) unsubscribe();
246
- };
248
+ function pullSelectorFamilyMember(store, socket, familyToken, key) {
249
+ const token = findInStore(store, familyToken, key);
250
+ return pullSelectorRoots(store, socket, token);
247
251
  }
248
252
 
249
253
  //#endregion
250
254
  //#region src/realtime-client/push-state.ts
251
255
  function pushState(store, socket, token) {
252
- socket.emit(`claim:${token.key}`);
253
- subscribeToState(store, token, `push`, ({ newValue }) => {
256
+ const publish = (newValue) => {
254
257
  socket.emit(`pub:${token.key}`, newValue);
255
- });
258
+ };
259
+ const subscriptions = /* @__PURE__ */ new Set();
260
+ const clearSubscriptions = () => {
261
+ for (const unsub of subscriptions) unsub();
262
+ subscriptions.clear();
263
+ };
264
+ const init = () => {
265
+ subscriptions.add(employSocket(socket, `claim-result:${token.key}`, (success) => {
266
+ if (!success) return;
267
+ clearSubscriptions();
268
+ setIntoStore(store, mutexAtoms, token.key, true);
269
+ subscriptions.add(subscribeToState(store, token, `push`, ({ newValue }) => {
270
+ publish(newValue);
271
+ }));
272
+ }));
273
+ socket.emit(`claim:${token.key}`);
274
+ };
275
+ init();
256
276
  return () => {
257
- socket.off(`pub:${token.key}`);
277
+ clearSubscriptions();
258
278
  socket.emit(`unclaim:${token.key}`);
259
279
  };
260
280
  }
@@ -272,7 +292,7 @@ const myIdState = AtomIO.selector({
272
292
  const myUsernameState = AtomIO.atom({
273
293
  key: `myName`,
274
294
  default: null,
275
- effects: typeof window === `undefined` ? [] : [persistSync(window.localStorage, JSON, `myUsername`)]
295
+ effects: [storageSync(globalThis.localStorage, JSON, `myUsername`)]
276
296
  });
277
297
 
278
298
  //#endregion
@@ -286,17 +306,6 @@ const confirmedUpdateQueue = AtomIO.atom({
286
306
  default: () => []
287
307
  });
288
308
 
289
- //#endregion
290
- //#region src/realtime-client/server-action.ts
291
- function serverAction(store, socket, token) {
292
- const unsubscribeFromLocalUpdates = subscribeToTransaction(store, token, `tx-run:${token.key}:${socket.id}`, (clientUpdate) => {
293
- socket.emit(`tx-run:${token.key}`, clientUpdate);
294
- });
295
- return () => {
296
- unsubscribeFromLocalUpdates();
297
- };
298
- }
299
-
300
309
  //#endregion
301
310
  //#region src/realtime-client/sync-continuity.ts
302
311
  function syncContinuity(store, socket, continuity) {
@@ -324,9 +333,9 @@ function syncContinuity(store, socket, continuity) {
324
333
  const registerAndAttemptConfirmedUpdate = useRegisterAndAttemptConfirmedUpdate(store, continuityKey, socket, optimisticUpdates, confirmedUpdates);
325
334
  socket.off(`tx-new:${continuityKey}`);
326
335
  socket.on(`tx-new:${continuityKey}`, registerAndAttemptConfirmedUpdate);
327
- const unsubscribeFunctions = continuity.actions.map((transaction) => {
328
- assignTransactionToContinuity(store, continuityKey, transaction.key);
329
- const unsubscribeFromTransactionUpdates = subscribeToTransaction(store, transaction, `tx-run:${continuityKey}`, (clientUpdate) => {
336
+ const unsubscribeFunctions = continuity.actions.map((transaction$1) => {
337
+ assignTransactionToContinuity(store, continuityKey, transaction$1.key);
338
+ return subscribeToTransaction(store, transaction$1, `tx-run:${continuityKey}`, (clientUpdate) => {
330
339
  store.logger.info(`🤞`, `continuity`, continuityKey, `enqueuing optimistic update`);
331
340
  const optimisticUpdateIndex = optimisticUpdates.findIndex((update) => update.id === clientUpdate.id);
332
341
  if (optimisticUpdateIndex === -1) {
@@ -345,11 +354,10 @@ function syncContinuity(store, socket, continuity) {
345
354
  }
346
355
  socket.emit(`tx-run:${continuityKey}`, {
347
356
  id: clientUpdate.id,
348
- token: transaction,
357
+ token: transaction$1,
349
358
  params: clientUpdate.params
350
359
  });
351
360
  });
352
- return unsubscribeFromTransactionUpdates;
353
361
  });
354
362
  const revealState = useRevealState(store);
355
363
  const concealState = useConcealState(store);
@@ -364,5 +372,5 @@ function syncContinuity(store, socket, continuity) {
364
372
  }
365
373
 
366
374
  //#endregion
367
- export { confirmedUpdateQueue, myIdState, myIdState__INTERNAL, myUsernameState, optimisticUpdateQueue, pullAtom, pullAtomFamilyMember, pullMutableAtom, pullMutableAtomFamilyMember, pullSelector, pullSelectorFamilyMember, pushState, serverAction, syncContinuity, useConcealState, useRegisterAndAttemptConfirmedUpdate, useRevealState };
375
+ export { confirmedUpdateQueue, myIdState, myIdState__INTERNAL, myUsernameState, optimisticUpdateQueue, pullAtom, pullAtomFamilyMember, pullMutableAtom, pullMutableAtomFamilyMember, pullSelector, pullSelectorFamilyMember, pushState, syncContinuity, useConcealState, useRegisterAndAttemptConfirmedUpdate, useRevealState };
368
376
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["optimisticUpdateQueue","confirmedUpdateQueue","continuityEpoch: number | undefined","k: any","v: any","unsubscribes: Array<() => void>","unsubscribes: Array<() => void>","myIdState__INTERNAL: AtomIO.RegularAtomToken<string | undefined>","myIdState: AtomIO.ReadonlyPureSelectorToken<string | undefined>","myUsernameState: AtomIO.RegularAtomToken<string | null>","optimisticUpdateQueue: AtomIO.RegularAtomToken<\n\tAtomIO.TransactionOutcomeEvent<any>[]\n>","confirmedUpdateQueue: AtomIO.RegularAtomToken<\n\tAtomIO.TransactionOutcomeEvent<any>[]\n>","optimisticUpdateQueue","confirmedUpdateQueue","k: any","v: any"],"sources":["../../src/realtime-client/continuity/register-and-attempt-confirmed-update.ts","../../src/realtime-client/continuity/use-conceal-state.ts","../../src/realtime-client/continuity/use-reveal-state.ts","../../src/realtime-client/pull-atom.ts","../../src/realtime-client/pull-atom-family-member.ts","../../src/realtime-client/pull-mutable-atom.ts","../../src/realtime-client/pull-mutable-atom-family-member.ts","../../src/realtime-client/pull-selector.ts","../../src/realtime-client/pull-selector-family-member.ts","../../src/realtime-client/push-state.ts","../../src/realtime-client/realtime-client-stores/client-main-store.ts","../../src/realtime-client/realtime-client-stores/client-sync-store.ts","../../src/realtime-client/server-action.ts","../../src/realtime-client/sync-continuity.ts"],"sourcesContent":["import type * as AtomIO from \"atom.io\"\nimport type { Fn, RootStore } from \"atom.io/internal\"\nimport {\n\tactUponStore,\n\tgetEpochNumberOfContinuity,\n\tingestTransactionOutcomeEvent,\n\tsetEpochNumberOfContinuity,\n\tsetIntoStore,\n} from \"atom.io/internal\"\nimport {\n\tconfirmedUpdateQueue,\n\toptimisticUpdateQueue,\n} from \"atom.io/realtime-client\"\nimport type { Socket } from \"atom.io/realtime-server\"\n\nexport const useRegisterAndAttemptConfirmedUpdate =\n\t(\n\t\tstore: RootStore,\n\t\tcontinuityKey: string,\n\t\tsocket: Socket,\n\t\toptimisticUpdates: AtomIO.TransactionOutcomeEvent<\n\t\t\tAtomIO.TransactionToken<Fn>\n\t\t>[],\n\t\tconfirmedUpdates: AtomIO.TransactionOutcomeEvent<\n\t\t\tAtomIO.TransactionToken<Fn>\n\t\t>[],\n\t) =>\n\t(\n\t\tconfirmed: AtomIO.TransactionOutcomeEvent<AtomIO.TransactionToken<Fn>>,\n\t): void => {\n\t\tfunction reconcileEpoch(\n\t\t\toptimisticUpdate: AtomIO.TransactionOutcomeEvent<\n\t\t\t\tAtomIO.TransactionToken<Fn>\n\t\t\t>,\n\t\t\tconfirmedUpdate: AtomIO.TransactionOutcomeEvent<\n\t\t\t\tAtomIO.TransactionToken<Fn>\n\t\t\t>,\n\t\t): void {\n\t\t\tstore.logger.info(\n\t\t\t\t`🧑‍⚖️`,\n\t\t\t\t`continuity`,\n\t\t\t\tcontinuityKey,\n\t\t\t\t`reconciling updates`,\n\t\t\t)\n\t\t\tsetIntoStore(store, optimisticUpdateQueue, (queue) => {\n\t\t\t\tqueue.shift()\n\t\t\t\treturn queue\n\t\t\t})\n\t\t\tif (optimisticUpdate.id === confirmedUpdate.id) {\n\t\t\t\tconst clientResult = JSON.stringify(optimisticUpdate.subEvents)\n\t\t\t\tconst serverResult = JSON.stringify(confirmedUpdate.subEvents)\n\t\t\t\tif (clientResult === serverResult) {\n\t\t\t\t\tstore.logger.info(\n\t\t\t\t\t\t`✅`,\n\t\t\t\t\t\t`continuity`,\n\t\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t\t`results for ${optimisticUpdate.id} match between client and server`,\n\t\t\t\t\t)\n\t\t\t\t\tsocket.emit(`ack:${continuityKey}`, confirmedUpdate.epoch)\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// id mismatch\n\t\t\t\tstore.logger.info(\n\t\t\t\t\t`❌`,\n\t\t\t\t\t`continuity`,\n\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t`thought update #${confirmedUpdate.epoch} was ${optimisticUpdate.token.key}:${optimisticUpdate.id}, but it was actually ${confirmedUpdate.token.key}:${confirmedUpdate.id}`,\n\t\t\t\t)\n\t\t\t}\n\t\t\tstore.logger.info(\n\t\t\t\t`🧑‍⚖️`,\n\t\t\t\t`continuity`,\n\t\t\t\tcontinuityKey,\n\t\t\t\t`updates do not match`,\n\t\t\t\toptimisticUpdate,\n\t\t\t\tconfirmedUpdate,\n\t\t\t)\n\t\t\tconst reversedOptimisticUpdates = optimisticUpdates.toReversed()\n\t\t\tfor (const subsequentOptimistic of reversedOptimisticUpdates) {\n\t\t\t\tingestTransactionOutcomeEvent(store, subsequentOptimistic, `oldValue`)\n\t\t\t}\n\t\t\tstore.logger.info(\n\t\t\t\t`⏪`,\n\t\t\t\t`continuity`,\n\t\t\t\tcontinuityKey,\n\t\t\t\t`undid optimistic updates:`,\n\t\t\t\treversedOptimisticUpdates,\n\t\t\t)\n\t\t\tingestTransactionOutcomeEvent(store, optimisticUpdate, `oldValue`)\n\t\t\tstore.logger.info(\n\t\t\t\t`⏪`,\n\t\t\t\t`continuity`,\n\t\t\t\tcontinuityKey,\n\t\t\t\t`undid zeroth optimistic update`,\n\t\t\t\toptimisticUpdate,\n\t\t\t)\n\t\t\tingestTransactionOutcomeEvent(store, confirmedUpdate, `newValue`)\n\t\t\tstore.logger.info(\n\t\t\t\t`⏩`,\n\t\t\t\t`continuity`,\n\t\t\t\tcontinuityKey,\n\t\t\t\t`applied confirmed update`,\n\t\t\t\tconfirmedUpdate,\n\t\t\t)\n\t\t\tsocket.emit(`ack:${continuityKey}`, confirmedUpdate.epoch)\n\n\t\t\tfor (const subsequentOptimistic of optimisticUpdates) {\n\t\t\t\tconst token = {\n\t\t\t\t\ttype: `transaction`,\n\t\t\t\t\tkey: subsequentOptimistic.token.key,\n\t\t\t\t} as const\n\t\t\t\tconst { id, params } = subsequentOptimistic\n\t\t\t\tactUponStore(store, token, id)(...params)\n\t\t\t}\n\t\t\tstore.logger.info(\n\t\t\t\t`⏩`,\n\t\t\t\t`continuity`,\n\t\t\t\tcontinuityKey,\n\t\t\t\t`reapplied subsequent optimistic updates:`,\n\t\t\t\toptimisticUpdates,\n\t\t\t)\n\t\t}\n\n\t\tstore.logger.info(\n\t\t\t`🧑‍⚖️`,\n\t\t\t`continuity`,\n\t\t\tcontinuityKey,\n\t\t\t`integrating confirmed update`,\n\t\t\t{ confirmedUpdate: confirmed, confirmedUpdates, optimisticUpdates },\n\t\t)\n\t\tconst zerothOptimisticUpdate = optimisticUpdates[0]\n\t\tif (zerothOptimisticUpdate) {\n\t\t\tstore.logger.info(\n\t\t\t\t`🧑‍⚖️`,\n\t\t\t\t`continuity`,\n\t\t\t\tcontinuityKey,\n\t\t\t\t`has optimistic updates to reconcile`,\n\t\t\t)\n\t\t\tif (confirmed.epoch === zerothOptimisticUpdate.epoch) {\n\t\t\t\tstore.logger.info(\n\t\t\t\t\t`🧑‍⚖️`,\n\t\t\t\t\t`continuity`,\n\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t`epoch of confirmed update #${confirmed.epoch} matches zeroth optimistic update`,\n\t\t\t\t)\n\t\t\t\treconcileEpoch(zerothOptimisticUpdate, confirmed)\n\t\t\t\tfor (const nextConfirmed of confirmedUpdates) {\n\t\t\t\t\tconst nextOptimistic = optimisticUpdates[0]\n\t\t\t\t\tif (nextConfirmed.epoch === nextOptimistic?.epoch) {\n\t\t\t\t\t\treconcileEpoch(nextOptimistic, nextConfirmed)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// epoch mismatch\n\t\t\t\tstore.logger.info(\n\t\t\t\t\t`🧑‍⚖️`,\n\t\t\t\t\t`continuity`,\n\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t`epoch of confirmed update #${confirmed.epoch} does not match zeroth optimistic update #${zerothOptimisticUpdate.epoch}`,\n\t\t\t\t)\n\t\t\t\tconst confirmedUpdateIsAlreadyEnqueued = confirmedUpdates.some(\n\t\t\t\t\t(update) => update.epoch === confirmed.epoch,\n\t\t\t\t)\n\t\t\t\tif (!confirmedUpdateIsAlreadyEnqueued) {\n\t\t\t\t\tstore.logger.info(\n\t\t\t\t\t\t`👈`,\n\t\t\t\t\t\t`continuity`,\n\t\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t\t`pushing confirmed update to queue`,\n\t\t\t\t\t\tconfirmed,\n\t\t\t\t\t)\n\t\t\t\t\tsetIntoStore(store, confirmedUpdateQueue, (queue) => {\n\t\t\t\t\t\tqueue.push(confirmed)\n\t\t\t\t\t\tqueue.sort((a, b) => a.epoch - b.epoch)\n\t\t\t\t\t\treturn queue\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tstore.logger.info(\n\t\t\t\t`🧑‍⚖️`,\n\t\t\t\t`continuity`,\n\t\t\t\tcontinuityKey,\n\t\t\t\t`has no optimistic updates to deal with`,\n\t\t\t)\n\t\t\tlet continuityEpoch: number | undefined\n\t\t\tcontinuityEpoch = getEpochNumberOfContinuity(store, continuityKey)\n\n\t\t\tif (continuityEpoch === confirmed.epoch - 1) {\n\t\t\t\tstore.logger.info(\n\t\t\t\t\t`✅`,\n\t\t\t\t\t`continuity`,\n\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t`integrating update #${confirmed.epoch} (${confirmed.token.key} ${confirmed.id})`,\n\t\t\t\t)\n\t\t\t\tingestTransactionOutcomeEvent(store, confirmed, `newValue`)\n\t\t\t\tsocket.emit(`ack:${continuityKey}`, confirmed.epoch)\n\t\t\t\tsetEpochNumberOfContinuity(store, continuityKey, confirmed.epoch)\n\t\t\t} else if (continuityEpoch !== undefined) {\n\t\t\t\tstore.logger.info(\n\t\t\t\t\t`🧑‍⚖️`,\n\t\t\t\t\t`continuity`,\n\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t`received update #${confirmed.epoch} but still waiting for update #${\n\t\t\t\t\t\tcontinuityEpoch + 1\n\t\t\t\t\t}`,\n\t\t\t\t\t{\n\t\t\t\t\t\tclientEpoch: continuityEpoch,\n\t\t\t\t\t\tserverEpoch: confirmed.epoch,\n\t\t\t\t\t},\n\t\t\t\t)\n\t\t\t\tconst confirmedUpdateIsAlreadyEnqueued = confirmedUpdates.some(\n\t\t\t\t\t(update) => update.epoch === confirmed.epoch,\n\t\t\t\t)\n\t\t\t\tif (confirmedUpdateIsAlreadyEnqueued) {\n\t\t\t\t\tstore.logger.info(\n\t\t\t\t\t\t`👍`,\n\t\t\t\t\t\t`continuity`,\n\t\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t\t`confirmed update #${confirmed.epoch} is already enqueued`,\n\t\t\t\t\t)\n\t\t\t\t} else {\n\t\t\t\t\tstore.logger.info(\n\t\t\t\t\t\t`👈`,\n\t\t\t\t\t\t`continuity`,\n\t\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t\t`pushing confirmed update #${confirmed.epoch} to queue`,\n\t\t\t\t\t)\n\t\t\t\t\tsetIntoStore(store, confirmedUpdateQueue, (queue) => {\n\t\t\t\t\t\tqueue.push(confirmed)\n\t\t\t\t\t\tqueue.sort((a, b) => a.epoch - b.epoch)\n\t\t\t\t\t\treturn queue\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n","import type { AtomToken } from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { disposeAtom } from \"atom.io/internal\"\n\nexport function useConcealState(store: Store) {\n\treturn (concealed: AtomToken<unknown>[]): void => {\n\t\tfor (const token of concealed) {\n\t\t\tdisposeAtom(store, token)\n\t\t}\n\t}\n}\n","import { setIntoStore, type Store } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nexport function useRevealState(store: Store) {\n\treturn (revealed: Json.Array): void => {\n\t\tlet i = 0\n\t\tlet k: any\n\t\tlet v: any\n\t\tfor (const x of revealed) {\n\t\t\tif (i % 2 === 0) {\n\t\t\t\tk = x\n\t\t\t} else {\n\t\t\t\tv = x\n\t\t\t\tsetIntoStore(store, k, v)\n\t\t\t}\n\t\t\ti++\n\t\t}\n\t}\n}\n","import type * as AtomIO from \"atom.io\"\nimport { setIntoStore, type Store } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport type { Socket } from \"socket.io-client\"\n\nexport function pullAtom<J extends Json.Serializable>(\n\tstore: Store,\n\tsocket: Socket,\n\ttoken: AtomIO.RegularAtomToken<J>,\n): () => void {\n\tconst setServedValue = (data: J) => {\n\t\tsetIntoStore(store, token, data)\n\t}\n\tsocket.on(`serve:${token.key}`, setServedValue)\n\tsocket.emit(`sub:${token.key}`)\n\treturn () => {\n\t\tsocket.off(`serve:${token.key}`, setServedValue)\n\t\tsocket.emit(`unsub:${token.key}`)\n\t}\n}\n","import type * as AtomIO from \"atom.io\"\nimport { setIntoStore, type Store } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport { parseJson } from \"atom.io/json\"\nimport type { Socket } from \"socket.io-client\"\n\n/* eslint-disable no-console */\n\nexport function pullAtomFamilyMember<J extends Json.Serializable>(\n\tstore: Store,\n\tsocket: Socket,\n\ttoken: AtomIO.RegularAtomToken<J>,\n): () => void {\n\tif (!(`family` in token)) {\n\t\tconsole.error(`Token is not a family member:`, token)\n\t\treturn () => {}\n\t}\n\tconst { key: familyKey, subKey: serializedSubKey } = token.family\n\tconst subKey = parseJson(serializedSubKey)\n\tsocket?.on(`serve:${token.key}`, (data: J) => {\n\t\tsetIntoStore(store, token, data)\n\t})\n\tsocket?.emit(`sub:${familyKey}`, subKey)\n\treturn () => {\n\t\tsocket?.off(`serve:${token.key}`)\n\t\tsocket?.emit(`unsub:${token.key}`)\n\t}\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { AsJSON, SignalFrom, Store, Transceiver } from \"atom.io/internal\"\nimport { getJsonToken, getUpdateToken, setIntoStore } from \"atom.io/internal\"\nimport type { Socket } from \"socket.io-client\"\n\nexport function pullMutableAtom<T extends Transceiver<any, any, any>>(\n\tstore: Store,\n\tsocket: Socket,\n\ttoken: AtomIO.MutableAtomToken<T>,\n): () => void {\n\tconst jsonToken = getJsonToken(store, token)\n\tconst updateToken = getUpdateToken(token)\n\tsocket.on(`init:${token.key}`, (data: AsJSON<T>) => {\n\t\tsetIntoStore(store, jsonToken, data)\n\t})\n\tsocket.on(`next:${token.key}`, (data: SignalFrom<T>) => {\n\t\tsetIntoStore(store, updateToken, data)\n\t})\n\tsocket.emit(`sub:${token.key}`)\n\treturn () => {\n\t\tsocket.off(`init:${token.key}`)\n\t\tsocket.off(`next:${token.key}`)\n\t\tsocket.emit(`unsub:${token.key}`)\n\t}\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { AsJSON, SignalFrom, Store, Transceiver } from \"atom.io/internal\"\nimport { getJsonToken, getUpdateToken, setIntoStore } from \"atom.io/internal\"\nimport { parseJson } from \"atom.io/json\"\nimport type { Socket } from \"socket.io-client\"\n\n/* eslint-disable no-console */\n\nexport function pullMutableAtomFamilyMember<\n\tT extends Transceiver<any, any, any>,\n>(store: Store, socket: Socket, token: AtomIO.MutableAtomToken<T>): () => void {\n\tif (!(`family` in token)) {\n\t\tconsole.error(`Token is not a family member:`, token)\n\t\treturn () => {}\n\t}\n\tconst { key: familyKey, subKey: serializedSubKey } = token.family\n\tconst subKey = parseJson(serializedSubKey)\n\tsocket.on(`init:${token.key}`, (data: AsJSON<T>) => {\n\t\tconst jsonToken = getJsonToken(store, token)\n\t\tsetIntoStore(store, jsonToken, data)\n\t})\n\tsocket.on(`next:${token.key}`, (data: SignalFrom<T>) => {\n\t\tconst trackerToken = getUpdateToken(token)\n\t\tsetIntoStore(store, trackerToken, data)\n\t})\n\tsocket.emit(`sub:${familyKey}`, subKey)\n\treturn () => {\n\t\tsocket.off(`serve:${token.key}`)\n\t\tsocket.emit(`unsub:${token.key}`)\n\t}\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport type { Socket } from \"socket.io-client\"\n\nimport { pullAtom } from \"./pull-atom\"\nimport { pullMutableAtom } from \"./pull-mutable-atom\"\n\nexport function pullSelector<T>(\n\tstore: Store,\n\tsocket: Socket,\n\ttoken: AtomIO.SelectorToken<T>,\n): () => void {\n\tconst atomKeys = store.selectorAtoms.getRelatedKeys(token.key)\n\tconst unsubscribes: Array<() => void> = []\n\tif (atomKeys) {\n\t\tfor (const atomKey of atomKeys) {\n\t\t\tconst atom = store.atoms.get(atomKey)\n\t\t\tif (!atom) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tswitch (atom.type) {\n\t\t\t\tcase `atom`: {\n\t\t\t\t\tunsubscribes.push(pullAtom(store, socket, atom))\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase `mutable_atom`: {\n\t\t\t\t\tunsubscribes.push(pullMutableAtom(store, socket, atom))\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn () => {\n\t\tfor (const unsubscribe of unsubscribes) {\n\t\t\tunsubscribe()\n\t\t}\n\t}\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport type { Socket } from \"socket.io-client\"\n\nimport { pullAtomFamilyMember } from \"./pull-atom-family-member\"\nimport { pullMutableAtomFamilyMember } from \"./pull-mutable-atom-family-member\"\n\n/* eslint-disable no-console */\n\nexport function pullSelectorFamilyMember<T>(\n\tstore: Store,\n\tsocket: Socket,\n\ttoken: AtomIO.SelectorToken<T>,\n): () => void {\n\tif (!(`family` in token)) {\n\t\tconsole.error(`Token is not a family member:`, token)\n\t\treturn () => {}\n\t}\n\tconst atomKeys = store.selectorAtoms.getRelatedKeys(token.key)\n\tconst unsubscribes: Array<() => void> = []\n\tif (atomKeys) {\n\t\tfor (const atomKey of atomKeys) {\n\t\t\tconst atom = store.atoms.get(atomKey)\n\t\t\tif (!atom) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tswitch (atom.type) {\n\t\t\t\tcase `atom`: {\n\t\t\t\t\tunsubscribes.push(pullAtomFamilyMember(store, socket, atom))\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase `mutable_atom`: {\n\t\t\t\t\tunsubscribes.push(pullMutableAtomFamilyMember(store, socket, atom))\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn () => {\n\t\tfor (const unsubscribe of unsubscribes) {\n\t\t\tunsubscribe()\n\t\t}\n\t}\n}\n","import type { WritableToken } from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { subscribeToState } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport type { Socket } from \"socket.io-client\"\n\nexport function pushState<J extends Json.Serializable>(\n\tstore: Store,\n\tsocket: Socket,\n\ttoken: WritableToken<J>,\n): () => void {\n\tsocket.emit(`claim:${token.key}`)\n\tsubscribeToState(store, token, `push`, ({ newValue }) => {\n\t\tsocket.emit(`pub:${token.key}`, newValue)\n\t})\n\treturn () => {\n\t\tsocket.off(`pub:${token.key}`)\n\t\tsocket.emit(`unclaim:${token.key}`)\n\t}\n}\n","import * as AtomIO from \"atom.io\"\nimport { persistSync } from \"atom.io/web\"\n\nexport const myIdState__INTERNAL: AtomIO.RegularAtomToken<string | undefined> =\n\tAtomIO.atom<string | undefined>({\n\t\tkey: `mySocketId__INTERNAL`,\n\t\tdefault: undefined,\n\t})\nexport const myIdState: AtomIO.ReadonlyPureSelectorToken<string | undefined> =\n\tAtomIO.selector<string | undefined>({\n\t\tkey: `mySocketId`,\n\t\tget: ({ get }) => get(myIdState__INTERNAL),\n\t})\n\nexport const myUsernameState: AtomIO.RegularAtomToken<string | null> =\n\tAtomIO.atom<string | null>({\n\t\tkey: `myName`,\n\t\tdefault: null,\n\t\teffects:\n\t\t\ttypeof window === `undefined`\n\t\t\t\t? []\n\t\t\t\t: [persistSync(window.localStorage, JSON, `myUsername`)],\n\t})\n","import * as AtomIO from \"atom.io\"\n\nexport const optimisticUpdateQueue: AtomIO.RegularAtomToken<\n\tAtomIO.TransactionOutcomeEvent<any>[]\n> = AtomIO.atom<AtomIO.TransactionOutcomeEvent<any>[]>({\n\tkey: `updateQueue`,\n\tdefault: () => [],\n})\n\nexport const confirmedUpdateQueue: AtomIO.RegularAtomToken<\n\tAtomIO.TransactionOutcomeEvent<any>[]\n> = AtomIO.atom<AtomIO.TransactionOutcomeEvent<any>[]>({\n\tkey: `serverConfirmedUpdateQueue`,\n\tdefault: () => [],\n})\n","import type * as AtomIO from \"atom.io\"\nimport type { Fn, Store } from \"atom.io/internal\"\nimport { subscribeToTransaction } from \"atom.io/internal\"\nimport type { Socket } from \"socket.io-client\"\n\nexport function serverAction<F extends Fn>(\n\tstore: Store,\n\tsocket: Socket,\n\ttoken: AtomIO.TransactionToken<F>,\n): () => void {\n\tconst unsubscribeFromLocalUpdates = subscribeToTransaction(\n\t\tstore,\n\t\ttoken,\n\t\t`tx-run:${token.key}:${socket.id}`,\n\t\t(clientUpdate) => {\n\t\t\tsocket.emit(`tx-run:${token.key}`, clientUpdate)\n\t\t},\n\t)\n\n\treturn () => {\n\t\tunsubscribeFromLocalUpdates()\n\t}\n}\n","import type { RootStore } from \"atom.io/internal\"\nimport {\n\tassignTransactionToContinuity,\n\tgetFromStore,\n\tgetJsonToken,\n\tsetEpochNumberOfContinuity,\n\tsetIntoStore,\n\tsubscribeToTransaction,\n} from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport type { ContinuityToken } from \"atom.io/realtime\"\nimport {\n\tconfirmedUpdateQueue,\n\toptimisticUpdateQueue,\n} from \"atom.io/realtime-client\"\nimport type { Socket } from \"socket.io-client\"\n\nimport { useRegisterAndAttemptConfirmedUpdate } from \"./continuity/register-and-attempt-confirmed-update\"\nimport { useConcealState } from \"./continuity/use-conceal-state\"\nimport { useRevealState } from \"./continuity/use-reveal-state\"\n\nexport function syncContinuity(\n\tstore: RootStore,\n\tsocket: Socket,\n\tcontinuity: ContinuityToken,\n): () => void {\n\tconst continuityKey = continuity.key\n\tconst optimisticUpdates = getFromStore(store, optimisticUpdateQueue)\n\tconst confirmedUpdates = getFromStore(store, confirmedUpdateQueue)\n\n\tconst initializeContinuity = (epoch: number, payload: Json.Array) => {\n\t\tsocket.off(`continuity-init:${continuityKey}`, initializeContinuity)\n\t\tlet i = 0\n\t\tlet k: any\n\t\tlet v: any\n\t\tfor (const x of payload) {\n\t\t\tif (i % 2 === 0) {\n\t\t\t\tk = x\n\t\t\t} else {\n\t\t\t\tv = x\n\t\t\t\tif (`type` in k && k.type === `mutable_atom`) {\n\t\t\t\t\tk = getJsonToken(store, k)\n\t\t\t\t}\n\t\t\t\tsetIntoStore(store, k, v)\n\t\t\t}\n\t\t\ti++\n\t\t}\n\t\tsetEpochNumberOfContinuity(store, continuityKey, epoch)\n\t}\n\tsocket.off(`continuity-init:${continuityKey}`)\n\tsocket.on(`continuity-init:${continuityKey}`, initializeContinuity)\n\n\tconst registerAndAttemptConfirmedUpdate = useRegisterAndAttemptConfirmedUpdate(\n\t\tstore,\n\t\tcontinuityKey,\n\t\tsocket,\n\t\toptimisticUpdates,\n\t\tconfirmedUpdates,\n\t)\n\tsocket.off(`tx-new:${continuityKey}`)\n\tsocket.on(`tx-new:${continuityKey}`, registerAndAttemptConfirmedUpdate)\n\n\tconst unsubscribeFunctions = continuity.actions.map((transaction) => {\n\t\tassignTransactionToContinuity(store, continuityKey, transaction.key)\n\t\tconst unsubscribeFromTransactionUpdates = subscribeToTransaction(\n\t\t\tstore,\n\t\t\ttransaction,\n\t\t\t`tx-run:${continuityKey}`,\n\t\t\t(clientUpdate) => {\n\t\t\t\tstore.logger.info(\n\t\t\t\t\t`🤞`,\n\t\t\t\t\t`continuity`,\n\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t`enqueuing optimistic update`,\n\t\t\t\t)\n\t\t\t\tconst optimisticUpdateIndex = optimisticUpdates.findIndex(\n\t\t\t\t\t(update) => update.id === clientUpdate.id,\n\t\t\t\t)\n\t\t\t\tif (optimisticUpdateIndex === -1) {\n\t\t\t\t\tstore.logger.info(\n\t\t\t\t\t\t`🤞`,\n\t\t\t\t\t\t`continuity`,\n\t\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t\t`enqueuing new optimistic update`,\n\t\t\t\t\t)\n\t\t\t\t\tsetIntoStore(store, optimisticUpdateQueue, (queue) => {\n\t\t\t\t\t\tqueue.push(clientUpdate)\n\t\t\t\t\t\tqueue.sort((a, b) => a.epoch - b.epoch)\n\t\t\t\t\t\treturn queue\n\t\t\t\t\t})\n\t\t\t\t} else {\n\t\t\t\t\tstore.logger.info(\n\t\t\t\t\t\t`🤞`,\n\t\t\t\t\t\t`continuity`,\n\t\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t\t`replacing existing optimistic update at index ${optimisticUpdateIndex}`,\n\t\t\t\t\t)\n\t\t\t\t\tsetIntoStore(store, optimisticUpdateQueue, (queue) => {\n\t\t\t\t\t\tqueue[optimisticUpdateIndex] = clientUpdate\n\t\t\t\t\t\treturn queue\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\tsocket.emit(`tx-run:${continuityKey}`, {\n\t\t\t\t\tid: clientUpdate.id,\n\t\t\t\t\ttoken: transaction,\n\t\t\t\t\tparams: clientUpdate.params,\n\t\t\t\t})\n\t\t\t},\n\t\t)\n\t\treturn unsubscribeFromTransactionUpdates\n\t})\n\n\tconst revealState = useRevealState(store)\n\tconst concealState = useConcealState(store)\n\tsocket.on(`reveal:${continuityKey}`, revealState)\n\tsocket.on(`conceal:${continuityKey}`, concealState)\n\n\tsocket.emit(`get:${continuityKey}`)\n\treturn () => {\n\t\tsocket.off(`continuity-init:${continuityKey}`)\n\t\tsocket.off(`tx-new:${continuityKey}`)\n\t\tfor (const unsubscribe of unsubscribeFunctions) unsubscribe()\n\t\t// socket.emit(`unsub:${continuityKey}`)\n\t}\n}\n"],"mappings":";;;;;;;AAeA,MAAa,wCAEX,OACA,eACA,QAC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BAAiB;AACrC,QAAO,GAAG,WAAW,iBAAiB;AAEtC,QAAO,KAAK,OAAO;AACnB,cAAa;AACZ,SAAO,IAAI,mBAAmB;AAC9B,SAAO,IAAI,UAAU;AACrB,OAAK,MAAM,eAAe,qBAAsB"}
1
+ {"version":3,"file":"index.js","names":["optimisticUpdateQueue","confirmedUpdateQueue","continuityEpoch: number | undefined","k: any","v: any","myIdState__INTERNAL: AtomIO.RegularAtomToken<string | undefined>","myIdState: AtomIO.ReadonlyPureSelectorToken<string | undefined>","myUsernameState: AtomIO.RegularAtomToken<string | null>","optimisticUpdateQueue: AtomIO.RegularAtomToken<\n\tAtomIO.TransactionOutcomeEvent<any>[]\n>","confirmedUpdateQueue: AtomIO.RegularAtomToken<\n\tAtomIO.TransactionOutcomeEvent<any>[]\n>","optimisticUpdateQueue","confirmedUpdateQueue","k: any","v: any","transaction"],"sources":["../../src/realtime-client/continuity/register-and-attempt-confirmed-update.ts","../../src/realtime-client/continuity/use-conceal-state.ts","../../src/realtime-client/continuity/use-reveal-state.ts","../../src/realtime-client/pull-atom.ts","../../src/realtime-client/pull-atom-family-member.ts","../../src/realtime-client/pull-mutable-atom.ts","../../src/realtime-client/pull-mutable-atom-family-member.ts","../../src/realtime-client/pull-selector-roots.ts","../../src/realtime-client/pull-selector.ts","../../src/realtime-client/pull-selector-family-member.ts","../../src/realtime-client/push-state.ts","../../src/realtime-client/realtime-client-stores/client-main-store.ts","../../src/realtime-client/realtime-client-stores/client-sync-store.ts","../../src/realtime-client/sync-continuity.ts"],"sourcesContent":["import type * as AtomIO from \"atom.io\"\nimport type { Fn, RootStore } from \"atom.io/internal\"\nimport {\n\tactUponStore,\n\tgetEpochNumberOfContinuity,\n\tingestTransactionOutcomeEvent,\n\tsetEpochNumberOfContinuity,\n\tsetIntoStore,\n} from \"atom.io/internal\"\nimport {\n\tconfirmedUpdateQueue,\n\toptimisticUpdateQueue,\n} from \"atom.io/realtime-client\"\nimport type { Socket } from \"atom.io/realtime-server\"\n\nexport const useRegisterAndAttemptConfirmedUpdate =\n\t(\n\t\tstore: RootStore,\n\t\tcontinuityKey: string,\n\t\tsocket: Socket,\n\t\toptimisticUpdates: AtomIO.TransactionOutcomeEvent<\n\t\t\tAtomIO.TransactionToken<Fn>\n\t\t>[],\n\t\tconfirmedUpdates: AtomIO.TransactionOutcomeEvent<\n\t\t\tAtomIO.TransactionToken<Fn>\n\t\t>[],\n\t) =>\n\t(\n\t\tconfirmed: AtomIO.TransactionOutcomeEvent<AtomIO.TransactionToken<Fn>>,\n\t): void => {\n\t\tfunction reconcileEpoch(\n\t\t\toptimisticUpdate: AtomIO.TransactionOutcomeEvent<\n\t\t\t\tAtomIO.TransactionToken<Fn>\n\t\t\t>,\n\t\t\tconfirmedUpdate: AtomIO.TransactionOutcomeEvent<\n\t\t\t\tAtomIO.TransactionToken<Fn>\n\t\t\t>,\n\t\t): void {\n\t\t\tstore.logger.info(\n\t\t\t\t`🧑‍⚖️`,\n\t\t\t\t`continuity`,\n\t\t\t\tcontinuityKey,\n\t\t\t\t`reconciling updates`,\n\t\t\t)\n\t\t\tsetIntoStore(store, optimisticUpdateQueue, (queue) => {\n\t\t\t\tqueue.shift()\n\t\t\t\treturn queue\n\t\t\t})\n\t\t\tif (optimisticUpdate.id === confirmedUpdate.id) {\n\t\t\t\tconst clientResult = JSON.stringify(optimisticUpdate.subEvents)\n\t\t\t\tconst serverResult = JSON.stringify(confirmedUpdate.subEvents)\n\t\t\t\tif (clientResult === serverResult) {\n\t\t\t\t\tstore.logger.info(\n\t\t\t\t\t\t`✅`,\n\t\t\t\t\t\t`continuity`,\n\t\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t\t`results for ${optimisticUpdate.id} match between client and server`,\n\t\t\t\t\t)\n\t\t\t\t\tsocket.emit(`ack:${continuityKey}`, confirmedUpdate.epoch)\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// id mismatch\n\t\t\t\tstore.logger.info(\n\t\t\t\t\t`❌`,\n\t\t\t\t\t`continuity`,\n\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t`thought update #${confirmedUpdate.epoch} was ${optimisticUpdate.token.key}:${optimisticUpdate.id}, but it was actually ${confirmedUpdate.token.key}:${confirmedUpdate.id}`,\n\t\t\t\t)\n\t\t\t}\n\t\t\tstore.logger.info(\n\t\t\t\t`🧑‍⚖️`,\n\t\t\t\t`continuity`,\n\t\t\t\tcontinuityKey,\n\t\t\t\t`updates do not match`,\n\t\t\t\toptimisticUpdate,\n\t\t\t\tconfirmedUpdate,\n\t\t\t)\n\t\t\tconst reversedOptimisticUpdates = optimisticUpdates.toReversed()\n\t\t\tfor (const subsequentOptimistic of reversedOptimisticUpdates) {\n\t\t\t\tingestTransactionOutcomeEvent(store, subsequentOptimistic, `oldValue`)\n\t\t\t}\n\t\t\tstore.logger.info(\n\t\t\t\t`⏪`,\n\t\t\t\t`continuity`,\n\t\t\t\tcontinuityKey,\n\t\t\t\t`undid optimistic updates:`,\n\t\t\t\treversedOptimisticUpdates,\n\t\t\t)\n\t\t\tingestTransactionOutcomeEvent(store, optimisticUpdate, `oldValue`)\n\t\t\tstore.logger.info(\n\t\t\t\t`⏪`,\n\t\t\t\t`continuity`,\n\t\t\t\tcontinuityKey,\n\t\t\t\t`undid zeroth optimistic update`,\n\t\t\t\toptimisticUpdate,\n\t\t\t)\n\t\t\tingestTransactionOutcomeEvent(store, confirmedUpdate, `newValue`)\n\t\t\tstore.logger.info(\n\t\t\t\t`⏩`,\n\t\t\t\t`continuity`,\n\t\t\t\tcontinuityKey,\n\t\t\t\t`applied confirmed update`,\n\t\t\t\tconfirmedUpdate,\n\t\t\t)\n\t\t\tsocket.emit(`ack:${continuityKey}`, confirmedUpdate.epoch)\n\n\t\t\tfor (const subsequentOptimistic of optimisticUpdates) {\n\t\t\t\tconst token = {\n\t\t\t\t\ttype: `transaction`,\n\t\t\t\t\tkey: subsequentOptimistic.token.key,\n\t\t\t\t} as const\n\t\t\t\tconst { id, params } = subsequentOptimistic\n\t\t\t\tactUponStore(store, token, id)(...params)\n\t\t\t}\n\t\t\tstore.logger.info(\n\t\t\t\t`⏩`,\n\t\t\t\t`continuity`,\n\t\t\t\tcontinuityKey,\n\t\t\t\t`reapplied subsequent optimistic updates:`,\n\t\t\t\toptimisticUpdates,\n\t\t\t)\n\t\t}\n\n\t\tstore.logger.info(\n\t\t\t`🧑‍⚖️`,\n\t\t\t`continuity`,\n\t\t\tcontinuityKey,\n\t\t\t`integrating confirmed update`,\n\t\t\t{ confirmedUpdate: confirmed, confirmedUpdates, optimisticUpdates },\n\t\t)\n\t\tconst zerothOptimisticUpdate = optimisticUpdates[0]\n\t\tif (zerothOptimisticUpdate) {\n\t\t\tstore.logger.info(\n\t\t\t\t`🧑‍⚖️`,\n\t\t\t\t`continuity`,\n\t\t\t\tcontinuityKey,\n\t\t\t\t`has optimistic updates to reconcile`,\n\t\t\t)\n\t\t\tif (confirmed.epoch === zerothOptimisticUpdate.epoch) {\n\t\t\t\tstore.logger.info(\n\t\t\t\t\t`🧑‍⚖️`,\n\t\t\t\t\t`continuity`,\n\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t`epoch of confirmed update #${confirmed.epoch} matches zeroth optimistic update`,\n\t\t\t\t)\n\t\t\t\treconcileEpoch(zerothOptimisticUpdate, confirmed)\n\t\t\t\tfor (const nextConfirmed of confirmedUpdates) {\n\t\t\t\t\tconst nextOptimistic = optimisticUpdates[0]\n\t\t\t\t\tif (nextConfirmed.epoch === nextOptimistic?.epoch) {\n\t\t\t\t\t\treconcileEpoch(nextOptimistic, nextConfirmed)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// epoch mismatch\n\t\t\t\tstore.logger.info(\n\t\t\t\t\t`🧑‍⚖️`,\n\t\t\t\t\t`continuity`,\n\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t`epoch of confirmed update #${confirmed.epoch} does not match zeroth optimistic update #${zerothOptimisticUpdate.epoch}`,\n\t\t\t\t)\n\t\t\t\tconst confirmedUpdateIsAlreadyEnqueued = confirmedUpdates.some(\n\t\t\t\t\t(update) => update.epoch === confirmed.epoch,\n\t\t\t\t)\n\t\t\t\tif (!confirmedUpdateIsAlreadyEnqueued) {\n\t\t\t\t\tstore.logger.info(\n\t\t\t\t\t\t`👈`,\n\t\t\t\t\t\t`continuity`,\n\t\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t\t`pushing confirmed update to queue`,\n\t\t\t\t\t\tconfirmed,\n\t\t\t\t\t)\n\t\t\t\t\tsetIntoStore(store, confirmedUpdateQueue, (queue) => {\n\t\t\t\t\t\tqueue.push(confirmed)\n\t\t\t\t\t\tqueue.sort((a, b) => a.epoch - b.epoch)\n\t\t\t\t\t\treturn queue\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tstore.logger.info(\n\t\t\t\t`🧑‍⚖️`,\n\t\t\t\t`continuity`,\n\t\t\t\tcontinuityKey,\n\t\t\t\t`has no optimistic updates to deal with`,\n\t\t\t)\n\t\t\tlet continuityEpoch: number | undefined\n\t\t\tcontinuityEpoch = getEpochNumberOfContinuity(store, continuityKey)\n\n\t\t\tif (continuityEpoch === confirmed.epoch - 1) {\n\t\t\t\tstore.logger.info(\n\t\t\t\t\t`✅`,\n\t\t\t\t\t`continuity`,\n\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t`integrating update #${confirmed.epoch} (${confirmed.token.key} ${confirmed.id})`,\n\t\t\t\t)\n\t\t\t\tingestTransactionOutcomeEvent(store, confirmed, `newValue`)\n\t\t\t\tsocket.emit(`ack:${continuityKey}`, confirmed.epoch)\n\t\t\t\tsetEpochNumberOfContinuity(store, continuityKey, confirmed.epoch)\n\t\t\t} else if (continuityEpoch !== undefined) {\n\t\t\t\tstore.logger.info(\n\t\t\t\t\t`🧑‍⚖️`,\n\t\t\t\t\t`continuity`,\n\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t`received update #${confirmed.epoch} but still waiting for update #${\n\t\t\t\t\t\tcontinuityEpoch + 1\n\t\t\t\t\t}`,\n\t\t\t\t\t{\n\t\t\t\t\t\tclientEpoch: continuityEpoch,\n\t\t\t\t\t\tserverEpoch: confirmed.epoch,\n\t\t\t\t\t},\n\t\t\t\t)\n\t\t\t\tconst confirmedUpdateIsAlreadyEnqueued = confirmedUpdates.some(\n\t\t\t\t\t(update) => update.epoch === confirmed.epoch,\n\t\t\t\t)\n\t\t\t\tif (confirmedUpdateIsAlreadyEnqueued) {\n\t\t\t\t\tstore.logger.info(\n\t\t\t\t\t\t`👍`,\n\t\t\t\t\t\t`continuity`,\n\t\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t\t`confirmed update #${confirmed.epoch} is already enqueued`,\n\t\t\t\t\t)\n\t\t\t\t} else {\n\t\t\t\t\tstore.logger.info(\n\t\t\t\t\t\t`👈`,\n\t\t\t\t\t\t`continuity`,\n\t\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t\t`pushing confirmed update #${confirmed.epoch} to queue`,\n\t\t\t\t\t)\n\t\t\t\t\tsetIntoStore(store, confirmedUpdateQueue, (queue) => {\n\t\t\t\t\t\tqueue.push(confirmed)\n\t\t\t\t\t\tqueue.sort((a, b) => a.epoch - b.epoch)\n\t\t\t\t\t\treturn queue\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n","import type { AtomToken } from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { disposeAtom } from \"atom.io/internal\"\n\nexport function useConcealState(store: Store) {\n\treturn (concealed: AtomToken<unknown>[]): void => {\n\t\tfor (const token of concealed) {\n\t\t\tdisposeAtom(store, token)\n\t\t}\n\t}\n}\n","import { setIntoStore, type Store } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nexport function useRevealState(store: Store) {\n\treturn (revealed: Json.Array): void => {\n\t\tlet i = 0\n\t\tlet k: any\n\t\tlet v: any\n\t\tfor (const x of revealed) {\n\t\t\tif (i % 2 === 0) {\n\t\t\t\tk = x\n\t\t\t} else {\n\t\t\t\tv = x\n\t\t\t\tsetIntoStore(store, k, v)\n\t\t\t}\n\t\t\ti++\n\t\t}\n\t}\n}\n","import type * as AtomIO from \"atom.io\"\nimport { setIntoStore, type Store } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport type { Socket } from \"socket.io-client\"\n\nexport function pullAtom<J extends Json.Serializable>(\n\tstore: Store,\n\tsocket: Socket,\n\ttoken: AtomIO.RegularAtomToken<J, any, any>,\n): () => void {\n\tconst setServedValue = (data: J) => {\n\t\tsetIntoStore(store, token, data)\n\t}\n\tsocket.on(`serve:${token.key}`, setServedValue)\n\tsocket.emit(`sub:${token.key}`)\n\treturn () => {\n\t\tsocket.off(`serve:${token.key}`, setServedValue)\n\t\tsocket.emit(`unsub:${token.key}`)\n\t}\n}\n","import type * as AtomIO from \"atom.io\"\nimport { findInStore, setIntoStore, type Store } from \"atom.io/internal\"\nimport type { Canonical, Json } from \"atom.io/json\"\nimport type { Socket } from \"socket.io-client\"\n\nexport function pullAtomFamilyMember<\n\tJ extends Json.Serializable,\n\tK extends Canonical,\n>(\n\tstore: Store,\n\tsocket: Socket,\n\tfamily: AtomIO.AtomFamilyToken<J, K, any>,\n\tkey: NoInfer<K>,\n): () => void {\n\tconst token = findInStore(store, family, key)\n\tconst setServedValue = (data: J) => {\n\t\tsetIntoStore(store, token, data)\n\t}\n\tsocket?.on(`serve:${token.key}`, setServedValue)\n\tsocket?.emit(`sub:${family.key}`, key)\n\treturn () => {\n\t\tsocket?.off(`serve:${token.key}`, setServedValue)\n\t\tsocket?.emit(`unsub:${token.key}`)\n\t}\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { AsJSON, SignalFrom, Store, Transceiver } from \"atom.io/internal\"\nimport { getJsonToken, getUpdateToken, setIntoStore } from \"atom.io/internal\"\nimport type { Socket } from \"socket.io-client\"\n\nexport function pullMutableAtom<T extends Transceiver<any, any, any>>(\n\tstore: Store,\n\tsocket: Socket,\n\ttoken: AtomIO.MutableAtomToken<T>,\n): () => void {\n\tconst jsonToken = getJsonToken(store, token)\n\tconst updateToken = getUpdateToken(token)\n\tsocket.on(`init:${token.key}`, (data: AsJSON<T>) => {\n\t\tsetIntoStore(store, jsonToken, data)\n\t})\n\tsocket.on(`next:${token.key}`, (data: SignalFrom<T>) => {\n\t\tsetIntoStore(store, updateToken, data)\n\t})\n\tsocket.emit(`sub:${token.key}`)\n\treturn () => {\n\t\tsocket.off(`init:${token.key}`)\n\t\tsocket.off(`next:${token.key}`)\n\t\tsocket.emit(`unsub:${token.key}`)\n\t}\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { AsJSON, SignalFrom, Store, Transceiver } from \"atom.io/internal\"\nimport {\n\tfindInStore,\n\tgetJsonToken,\n\tgetUpdateToken,\n\tsetIntoStore,\n} from \"atom.io/internal\"\nimport type { Canonical } from \"atom.io/json\"\nimport type { Socket } from \"socket.io-client\"\n\nexport function pullMutableAtomFamilyMember<\n\tT extends Transceiver<any, any, any>,\n\tK extends Canonical,\n>(\n\tstore: Store,\n\tsocket: Socket,\n\tfamily: AtomIO.MutableAtomFamilyToken<T, K>,\n\tkey: NoInfer<K>,\n): () => void {\n\tconst token = findInStore(store, family, key)\n\tsocket.on(`init:${token.key}`, (data: AsJSON<T>) => {\n\t\tconst jsonToken = getJsonToken(store, token)\n\t\tsetIntoStore(store, jsonToken, data)\n\t})\n\tsocket.on(`next:${token.key}`, (data: SignalFrom<T>) => {\n\t\tconst trackerToken = getUpdateToken(token)\n\t\tsetIntoStore(store, trackerToken, data)\n\t})\n\tsocket.emit(`sub:${family.key}`, key)\n\treturn () => {\n\t\tsocket.off(`serve:${token.key}`)\n\t\tsocket.emit(`unsub:${token.key}`)\n\t}\n}\n","import type { AtomToken, SelectorToken } from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { getFamilyOfToken, subscribeToState } from \"atom.io/internal\"\nimport { parseJson } from \"atom.io/json\"\nimport type { Socket } from \"socket.io-client\"\n\nimport { pullAtom } from \"./pull-atom\"\nimport { pullAtomFamilyMember } from \"./pull-atom-family-member\"\nimport { pullMutableAtom } from \"./pull-mutable-atom\"\nimport { pullMutableAtomFamilyMember } from \"./pull-mutable-atom-family-member\"\n\nexport function pullSelectorRoots(\n\tstore: Store,\n\tsocket: Socket,\n\tselectorToken: SelectorToken<any>,\n): () => void {\n\tconst atomSubscriptions = new Map<string, () => void>()\n\tconst clearAtomSubscriptions = () => {\n\t\tfor (const [, unsub] of atomSubscriptions) unsub()\n\t\tatomSubscriptions.clear()\n\t}\n\n\tconst start = () => {\n\t\tconst atomKeys = store.selectorAtoms.getRelatedKeys(selectorToken.key)\n\t\tif (atomKeys) {\n\t\t\tfor (const [atomKey, unsub] of atomSubscriptions) {\n\t\t\t\tif (!atomKeys.has(atomKey)) {\n\t\t\t\t\tunsub()\n\t\t\t\t\tatomSubscriptions.delete(atomKey)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor (const atomKey of atomKeys) {\n\t\t\t\tif (atomSubscriptions.has(atomKey)) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tconst atom = store.atoms.get(atomKey) as AtomToken<any, any>\n\t\t\t\tswitch (atom.type) {\n\t\t\t\t\tcase `atom`: {\n\t\t\t\t\t\tif (atom.family) {\n\t\t\t\t\t\t\tconst { subKey: serializedSubKey } = atom.family\n\t\t\t\t\t\t\tconst subKey = parseJson(serializedSubKey)\n\t\t\t\t\t\t\tconst family = getFamilyOfToken(store, atom)\n\t\t\t\t\t\t\tatomSubscriptions.set(\n\t\t\t\t\t\t\t\tatomKey,\n\t\t\t\t\t\t\t\tpullAtomFamilyMember(store, socket, family, subKey),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tatomSubscriptions.set(atomKey, pullAtom(store, socket, atom))\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase `mutable_atom`: {\n\t\t\t\t\t\tif (atom.family) {\n\t\t\t\t\t\t\tconst { subKey: serializedSubKey } = atom.family\n\t\t\t\t\t\t\tconst subKey = parseJson(serializedSubKey)\n\t\t\t\t\t\t\tconst family = getFamilyOfToken(store, atom)\n\t\t\t\t\t\t\tatomSubscriptions.set(\n\t\t\t\t\t\t\t\tatomKey,\n\t\t\t\t\t\t\t\tpullMutableAtomFamilyMember(store, socket, family, subKey),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tatomSubscriptions.set(\n\t\t\t\t\t\t\t\tatomKey,\n\t\t\t\t\t\t\t\tpullMutableAtom(store, socket, atom),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tconst unsubFromSelector = subscribeToState(\n\t\tstore,\n\t\tselectorToken,\n\t\t`pull-watches-dependencies`,\n\t\t() => {\n\t\t\tstart()\n\t\t},\n\t)\n\n\tstart()\n\n\treturn () => {\n\t\tclearAtomSubscriptions()\n\t\tunsubFromSelector()\n\t}\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport type { Socket } from \"socket.io-client\"\n\nimport { pullSelectorRoots } from \"./pull-selector-roots\"\n\nexport function pullSelector<T>(\n\tstore: Store,\n\tsocket: Socket,\n\ttoken: AtomIO.SelectorToken<T>,\n): () => void {\n\treturn pullSelectorRoots(store, socket, token)\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { findInStore } from \"atom.io/internal\"\nimport type { Canonical } from \"atom.io/json\"\nimport type { Socket } from \"socket.io-client\"\n\nimport { pullSelectorRoots } from \"./pull-selector-roots\"\n\nexport function pullSelectorFamilyMember<T, K extends Canonical>(\n\tstore: Store,\n\tsocket: Socket,\n\tfamilyToken: AtomIO.SelectorFamilyToken<T, K>,\n\tkey: NoInfer<K>,\n): () => void {\n\tconst token = findInStore(store, familyToken, key)\n\treturn pullSelectorRoots(store, socket, token)\n}\n","import type { WritableToken } from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { setIntoStore, subscribeToState } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport { mutexAtoms } from \"atom.io/realtime/mutex-store\"\nimport { employSocket } from \"atom.io/realtime-server/employ-socket\"\nimport type { Socket } from \"socket.io-client\"\n\nexport function pushState<J extends Json.Serializable>(\n\tstore: Store,\n\tsocket: Socket,\n\ttoken: WritableToken<J>,\n): () => void {\n\tconst publish = (newValue: J) => {\n\t\tsocket.emit(`pub:${token.key}`, newValue)\n\t}\n\n\tconst subscriptions = new Set<() => void>()\n\tconst clearSubscriptions = () => {\n\t\tfor (const unsub of subscriptions) unsub()\n\t\tsubscriptions.clear()\n\t}\n\n\tconst init = () => {\n\t\tsubscriptions.add(\n\t\t\temploySocket(socket, `claim-result:${token.key}`, (success: boolean) => {\n\t\t\t\tif (!success) return\n\n\t\t\t\tclearSubscriptions()\n\t\t\t\tsetIntoStore(store, mutexAtoms, token.key, true)\n\t\t\t\tsubscriptions.add(\n\t\t\t\t\tsubscribeToState(store, token, `push`, ({ newValue }) => {\n\t\t\t\t\t\tpublish(newValue)\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t}),\n\t\t)\n\n\t\tsocket.emit(`claim:${token.key}`)\n\t}\n\n\tinit()\n\n\treturn () => {\n\t\tclearSubscriptions()\n\t\tsocket.emit(`unclaim:${token.key}`)\n\t}\n}\n","import * as AtomIO from \"atom.io\"\nimport { storageSync } from \"atom.io/web\"\n\nexport const myIdState__INTERNAL: AtomIO.RegularAtomToken<string | undefined> =\n\tAtomIO.atom<string | undefined>({\n\t\tkey: `mySocketId__INTERNAL`,\n\t\tdefault: undefined,\n\t})\nexport const myIdState: AtomIO.ReadonlyPureSelectorToken<string | undefined> =\n\tAtomIO.selector<string | undefined>({\n\t\tkey: `mySocketId`,\n\t\tget: ({ get }) => get(myIdState__INTERNAL),\n\t})\n\nexport const myUsernameState: AtomIO.RegularAtomToken<string | null> =\n\tAtomIO.atom<string | null>({\n\t\tkey: `myName`,\n\t\tdefault: null,\n\t\teffects: [storageSync(globalThis.localStorage, JSON, `myUsername`)],\n\t})\n","import * as AtomIO from \"atom.io\"\n\nexport const optimisticUpdateQueue: AtomIO.RegularAtomToken<\n\tAtomIO.TransactionOutcomeEvent<any>[]\n> = AtomIO.atom<AtomIO.TransactionOutcomeEvent<any>[]>({\n\tkey: `updateQueue`,\n\tdefault: () => [],\n})\n\nexport const confirmedUpdateQueue: AtomIO.RegularAtomToken<\n\tAtomIO.TransactionOutcomeEvent<any>[]\n> = AtomIO.atom<AtomIO.TransactionOutcomeEvent<any>[]>({\n\tkey: `serverConfirmedUpdateQueue`,\n\tdefault: () => [],\n})\n","import type { RootStore } from \"atom.io/internal\"\nimport {\n\tassignTransactionToContinuity,\n\tgetFromStore,\n\tgetJsonToken,\n\tsetEpochNumberOfContinuity,\n\tsetIntoStore,\n\tsubscribeToTransaction,\n} from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport type { ContinuityToken } from \"atom.io/realtime\"\nimport {\n\tconfirmedUpdateQueue,\n\toptimisticUpdateQueue,\n} from \"atom.io/realtime-client\"\nimport type { Socket } from \"socket.io-client\"\n\nimport { useRegisterAndAttemptConfirmedUpdate } from \"./continuity/register-and-attempt-confirmed-update\"\nimport { useConcealState } from \"./continuity/use-conceal-state\"\nimport { useRevealState } from \"./continuity/use-reveal-state\"\n\nexport function syncContinuity(\n\tstore: RootStore,\n\tsocket: Socket,\n\tcontinuity: ContinuityToken,\n): () => void {\n\tconst continuityKey = continuity.key\n\tconst optimisticUpdates = getFromStore(store, optimisticUpdateQueue)\n\tconst confirmedUpdates = getFromStore(store, confirmedUpdateQueue)\n\n\tconst initializeContinuity = (epoch: number, payload: Json.Array) => {\n\t\tsocket.off(`continuity-init:${continuityKey}`, initializeContinuity)\n\t\tlet i = 0\n\t\tlet k: any\n\t\tlet v: any\n\t\tfor (const x of payload) {\n\t\t\tif (i % 2 === 0) {\n\t\t\t\tk = x\n\t\t\t} else {\n\t\t\t\tv = x\n\t\t\t\tif (`type` in k && k.type === `mutable_atom`) {\n\t\t\t\t\tk = getJsonToken(store, k)\n\t\t\t\t}\n\t\t\t\tsetIntoStore(store, k, v)\n\t\t\t}\n\t\t\ti++\n\t\t}\n\t\tsetEpochNumberOfContinuity(store, continuityKey, epoch)\n\t}\n\tsocket.off(`continuity-init:${continuityKey}`)\n\tsocket.on(`continuity-init:${continuityKey}`, initializeContinuity)\n\n\tconst registerAndAttemptConfirmedUpdate = useRegisterAndAttemptConfirmedUpdate(\n\t\tstore,\n\t\tcontinuityKey,\n\t\tsocket,\n\t\toptimisticUpdates,\n\t\tconfirmedUpdates,\n\t)\n\tsocket.off(`tx-new:${continuityKey}`)\n\tsocket.on(`tx-new:${continuityKey}`, registerAndAttemptConfirmedUpdate)\n\n\tconst unsubscribeFunctions = continuity.actions.map((transaction) => {\n\t\tassignTransactionToContinuity(store, continuityKey, transaction.key)\n\t\tconst unsubscribeFromTransactionUpdates = subscribeToTransaction(\n\t\t\tstore,\n\t\t\ttransaction,\n\t\t\t`tx-run:${continuityKey}`,\n\t\t\t(clientUpdate) => {\n\t\t\t\tstore.logger.info(\n\t\t\t\t\t`🤞`,\n\t\t\t\t\t`continuity`,\n\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t`enqueuing optimistic update`,\n\t\t\t\t)\n\t\t\t\tconst optimisticUpdateIndex = optimisticUpdates.findIndex(\n\t\t\t\t\t(update) => update.id === clientUpdate.id,\n\t\t\t\t)\n\t\t\t\tif (optimisticUpdateIndex === -1) {\n\t\t\t\t\tstore.logger.info(\n\t\t\t\t\t\t`🤞`,\n\t\t\t\t\t\t`continuity`,\n\t\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t\t`enqueuing new optimistic update`,\n\t\t\t\t\t)\n\t\t\t\t\tsetIntoStore(store, optimisticUpdateQueue, (queue) => {\n\t\t\t\t\t\tqueue.push(clientUpdate)\n\t\t\t\t\t\tqueue.sort((a, b) => a.epoch - b.epoch)\n\t\t\t\t\t\treturn queue\n\t\t\t\t\t})\n\t\t\t\t} else {\n\t\t\t\t\tstore.logger.info(\n\t\t\t\t\t\t`🤞`,\n\t\t\t\t\t\t`continuity`,\n\t\t\t\t\t\tcontinuityKey,\n\t\t\t\t\t\t`replacing existing optimistic update at index ${optimisticUpdateIndex}`,\n\t\t\t\t\t)\n\t\t\t\t\tsetIntoStore(store, optimisticUpdateQueue, (queue) => {\n\t\t\t\t\t\tqueue[optimisticUpdateIndex] = clientUpdate\n\t\t\t\t\t\treturn queue\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t\tsocket.emit(`tx-run:${continuityKey}`, {\n\t\t\t\t\tid: clientUpdate.id,\n\t\t\t\t\ttoken: transaction,\n\t\t\t\t\tparams: clientUpdate.params,\n\t\t\t\t})\n\t\t\t},\n\t\t)\n\t\treturn unsubscribeFromTransactionUpdates\n\t})\n\n\tconst revealState = useRevealState(store)\n\tconst concealState = useConcealState(store)\n\tsocket.on(`reveal:${continuityKey}`, revealState)\n\tsocket.on(`conceal:${continuityKey}`, concealState)\n\n\tsocket.emit(`get:${continuityKey}`)\n\treturn () => {\n\t\tsocket.off(`continuity-init:${continuityKey}`)\n\t\tsocket.off(`tx-new:${continuityKey}`)\n\t\tfor (const unsubscribe of unsubscribeFunctions) unsubscribe()\n\t\t// socket.emit(`unsub:${continuityKey}`)\n\t}\n}\n"],"mappings":";;;;;;;;;AAeA,MAAa,wCAEX,OACA,eACA,QACA,mBAGA,sBAKA,cACU;CACV,SAAS,eACR,kBAGA,iBAGO;AACP,QAAM,OAAO,KACZ,SACA,cACA,eACA,sBACA;AACD,eAAa,OAAOA,0BAAwB,UAAU;AACrD,SAAM,OAAO;AACb,UAAO;IACN;AACF,MAAI,iBAAiB,OAAO,gBA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