atom.io 0.40.6 → 0.40.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. package/README.md +1 -1
  2. package/dist/data/index.d.ts +1 -1
  3. package/dist/data/index.js +1 -2
  4. package/dist/data/index.js.map +1 -1
  5. package/dist/employ-socket-D6wgByWh.js +12 -0
  6. package/dist/employ-socket-D6wgByWh.js.map +1 -0
  7. package/dist/eslint-plugin/index.js.map +1 -1
  8. package/dist/has-role-CMlaUlaf.js +1133 -0
  9. package/dist/has-role-CMlaUlaf.js.map +1 -0
  10. package/dist/internal/index.d.ts +248 -248
  11. package/dist/internal/index.d.ts.map +1 -1
  12. package/dist/internal/index.js +590 -1803
  13. package/dist/internal/index.js.map +1 -1
  14. package/dist/introspection/index.d.ts +1 -1
  15. package/dist/introspection/index.d.ts.map +1 -1
  16. package/dist/introspection/index.js +13 -32
  17. package/dist/introspection/index.js.map +1 -1
  18. package/dist/is-fn-DY1wZ-md.js +10 -0
  19. package/dist/is-fn-DY1wZ-md.js.map +1 -0
  20. package/dist/json/index.d.ts.map +1 -1
  21. package/dist/json/index.js.map +1 -1
  22. package/dist/main/index.d.ts +33 -33
  23. package/dist/main/index.d.ts.map +1 -1
  24. package/dist/main/index.js +3 -4
  25. package/dist/main/index.js.map +1 -1
  26. package/dist/mutex-store-CSvxY9i3.js +11 -0
  27. package/dist/mutex-store-CSvxY9i3.js.map +1 -0
  28. package/dist/react/index.d.ts +5 -5
  29. package/dist/react/index.d.ts.map +1 -1
  30. package/dist/react/index.js.map +1 -1
  31. package/dist/react-devtools/index.d.ts.map +1 -1
  32. package/dist/react-devtools/index.js +9 -11
  33. package/dist/react-devtools/index.js.map +1 -1
  34. package/dist/realtime/index.d.ts +7 -15
  35. package/dist/realtime/index.d.ts.map +1 -1
  36. package/dist/realtime/index.js +4 -35
  37. package/dist/realtime/index.js.map +1 -1
  38. package/dist/realtime-client/index.d.ts +6 -9
  39. package/dist/realtime-client/index.d.ts.map +1 -1
  40. package/dist/realtime-client/index.js +96 -88
  41. package/dist/realtime-client/index.js.map +1 -1
  42. package/dist/realtime-react/index.d.ts +17 -13
  43. package/dist/realtime-react/index.d.ts.map +1 -1
  44. package/dist/realtime-react/index.js +39 -50
  45. package/dist/realtime-react/index.js.map +1 -1
  46. package/dist/realtime-server/index.d.ts +83 -84
  47. package/dist/realtime-server/index.d.ts.map +1 -1
  48. package/dist/realtime-server/index.js +604 -543
  49. package/dist/realtime-server/index.js.map +1 -1
  50. package/dist/realtime-testing/index.d.ts +5 -4
  51. package/dist/realtime-testing/index.d.ts.map +1 -1
  52. package/dist/realtime-testing/index.js +35 -22
  53. package/dist/realtime-testing/index.js.map +1 -1
  54. package/dist/shared-room-store-BfW3nWif.js +31 -0
  55. package/dist/shared-room-store-BfW3nWif.js.map +1 -0
  56. package/dist/shared-room-store-D2o4ZLjC.d.ts +15 -0
  57. package/dist/shared-room-store-D2o4ZLjC.d.ts.map +1 -0
  58. package/dist/transceivers/set-rtx/index.d.ts.map +1 -1
  59. package/dist/transceivers/set-rtx/index.js +4 -8
  60. package/dist/transceivers/set-rtx/index.js.map +1 -1
  61. package/dist/web/index.d.ts +3 -3
  62. package/dist/web/index.d.ts.map +1 -1
  63. package/dist/web/index.js +4 -3
  64. package/dist/web/index.js.map +1 -1
  65. package/package.json +13 -13
  66. package/src/internal/atom/create-regular-atom.ts +5 -4
  67. package/src/internal/atom/dispose-atom.ts +7 -2
  68. package/src/internal/atom/has-role.ts +3 -3
  69. package/src/internal/caching.ts +4 -2
  70. package/src/internal/families/create-readonly-held-selector-family.ts +2 -1
  71. package/src/internal/families/create-readonly-pure-selector-family.ts +5 -2
  72. package/src/internal/families/create-regular-atom-family.ts +2 -1
  73. package/src/internal/families/create-writable-held-selector-family.ts +2 -1
  74. package/src/internal/families/create-writable-pure-selector-family.ts +5 -2
  75. package/src/internal/families/dispose-from-store.ts +4 -4
  76. package/src/internal/families/find-in-store.ts +10 -10
  77. package/src/internal/families/get-family-of-token.ts +2 -2
  78. package/src/internal/families/index.ts +1 -0
  79. package/src/internal/families/mint-in-store.ts +54 -19
  80. package/src/internal/families/seek-in-store.ts +1 -1
  81. package/src/internal/get-state/get-fallback.ts +2 -2
  82. package/src/internal/get-state/get-from-store.ts +5 -5
  83. package/src/internal/get-state/read-or-compute-value.ts +1 -1
  84. package/src/internal/get-state/reduce-reference.ts +8 -6
  85. package/src/internal/index.ts +2 -220
  86. package/src/internal/molecule.ts +1 -2
  87. package/src/internal/mutable/create-mutable-atom-family.ts +3 -2
  88. package/src/internal/mutable/create-mutable-atom.ts +4 -2
  89. package/src/internal/mutable/get-json-family.ts +1 -1
  90. package/src/internal/mutable/get-update-family.ts +1 -1
  91. package/src/internal/mutable/tracker-family.ts +2 -1
  92. package/src/internal/mutable/tracker.ts +71 -59
  93. package/src/internal/safe-compute.ts +1 -1
  94. package/src/internal/selector/create-readonly-held-selector.ts +2 -1
  95. package/src/internal/selector/create-readonly-pure-selector.ts +2 -1
  96. package/src/internal/selector/create-writable-held-selector.ts +2 -1
  97. package/src/internal/selector/create-writable-pure-selector.ts +2 -1
  98. package/src/internal/selector/dispose-selector.ts +3 -2
  99. package/src/internal/selector/register-selector.ts +8 -5
  100. package/src/internal/selector/trace-selector-atoms.ts +2 -1
  101. package/src/internal/set-state/dispatch-state-update.ts +3 -2
  102. package/src/internal/set-state/evict-downstream.ts +1 -1
  103. package/src/internal/set-state/operate-on-store.ts +16 -22
  104. package/src/internal/set-state/reset-atom-or-selector.ts +5 -3
  105. package/src/internal/set-state/reset-in-store.ts +5 -5
  106. package/src/internal/set-state/set-atom-or-selector.ts +2 -2
  107. package/src/internal/set-state/set-atom.ts +4 -2
  108. package/src/internal/set-state/set-into-store.ts +21 -39
  109. package/src/internal/set-state/set-selector.ts +3 -2
  110. package/src/internal/state-types.ts +228 -0
  111. package/src/internal/store/deposit.ts +4 -4
  112. package/src/internal/store/index.ts +0 -1
  113. package/src/internal/store/store.ts +9 -9
  114. package/src/internal/store/withdraw.ts +4 -4
  115. package/src/internal/subscribe/recall-state.ts +1 -1
  116. package/src/internal/subscribe/subscribe-to-root-atoms.ts +1 -12
  117. package/src/internal/subscribe/subscribe-to-state.ts +9 -0
  118. package/src/internal/subscribe/subscribe-to-transaction.ts +3 -2
  119. package/src/internal/transaction/build-transaction.ts +3 -2
  120. package/src/internal/transaction/index.ts +1 -23
  121. package/src/internal/transaction/is-root-store.ts +4 -1
  122. package/src/internal/transaction/transaction-meta-progress.ts +22 -0
  123. package/src/main/atom.ts +1 -2
  124. package/src/main/find-state.ts +5 -5
  125. package/src/main/get-state.ts +4 -4
  126. package/src/main/realm.ts +2 -2
  127. package/src/main/set-state.ts +10 -10
  128. package/src/react/parse-state-overloads.ts +3 -3
  129. package/src/react/use-i.ts +6 -4
  130. package/src/react/use-loadable.ts +4 -10
  131. package/src/react/use-o.ts +6 -4
  132. package/src/react-devtools/store.ts +6 -6
  133. package/src/realtime/index.ts +1 -0
  134. package/src/realtime/mutex-store.ts +11 -0
  135. package/src/realtime/realtime-continuity.ts +1 -5
  136. package/src/realtime-client/index.ts +0 -1
  137. package/src/realtime-client/pull-atom-family-member.ts +14 -17
  138. package/src/realtime-client/pull-atom.ts +1 -1
  139. package/src/realtime-client/pull-mutable-atom-family-member.ts +16 -12
  140. package/src/realtime-client/pull-selector-family-member.ts +8 -35
  141. package/src/realtime-client/pull-selector-roots.ts +90 -0
  142. package/src/realtime-client/pull-selector.ts +2 -27
  143. package/src/realtime-client/push-state.ts +33 -5
  144. package/src/realtime-client/realtime-client-stores/client-main-store.ts +2 -5
  145. package/src/realtime-react/index.ts +2 -2
  146. package/src/realtime-react/realtime-context.tsx +9 -5
  147. package/src/realtime-react/use-pull-atom-family-member.ts +2 -3
  148. package/src/realtime-react/use-pull-mutable-family-member.ts +2 -3
  149. package/src/realtime-react/use-pull-selector-family-member.ts +5 -6
  150. package/src/realtime-react/use-push.ts +7 -3
  151. package/src/realtime-react/use-realtime-service.ts +11 -11
  152. package/src/realtime-react/use-single-effect.ts +11 -14
  153. package/src/realtime-server/{realtime-server-stores/server-sync-store.ts → continuity/continuity-store.ts} +2 -27
  154. package/src/realtime-server/continuity/provide-continuity.ts +50 -0
  155. package/src/realtime-server/continuity/{subscribe-to-continuity-actions.ts → provide-outcomes.ts} +15 -13
  156. package/src/realtime-server/continuity/{subscribe-to-continuity-perpectives.ts → provide-perspectives.ts} +10 -8
  157. package/src/realtime-server/continuity/{prepare-to-send-initial-payload.ts → provide-startup-payloads.ts} +6 -4
  158. package/src/realtime-server/continuity/receive-action-requests.ts +68 -0
  159. package/src/realtime-server/continuity/track-acknowledgements.ts +46 -0
  160. package/src/realtime-server/employ-socket.ts +14 -0
  161. package/src/realtime-server/index.ts +3 -22
  162. package/src/realtime-server/ipc-sockets/child-socket.ts +125 -66
  163. package/src/realtime-server/ipc-sockets/custom-socket.ts +16 -14
  164. package/src/realtime-server/ipc-sockets/parent-socket.ts +98 -69
  165. package/src/realtime-server/realtime-family-provider.ts +78 -29
  166. package/src/realtime-server/realtime-mutable-family-provider.ts +80 -31
  167. package/src/realtime-server/realtime-mutable-provider.ts +30 -22
  168. package/src/realtime-server/realtime-server-stores/index.ts +0 -2
  169. package/src/realtime-server/realtime-server-stores/server-room-external-store.ts +77 -36
  170. package/src/realtime-server/realtime-server-stores/server-user-store.ts +12 -1
  171. package/src/realtime-server/realtime-state-provider.ts +30 -29
  172. package/src/realtime-server/realtime-state-receiver.ts +62 -16
  173. package/src/realtime-server/server-config.ts +8 -0
  174. package/src/realtime-server/socket-interface.ts +14 -0
  175. package/src/realtime-testing/setup-realtime-test.tsx +70 -31
  176. package/src/web/index.ts +1 -1
  177. package/src/web/{persist-sync.ts → storage-sync.ts} +5 -2
  178. package/src/internal/store/mint-or-counterfeit.ts +0 -108
  179. package/src/realtime-client/server-action.ts +0 -23
  180. package/src/realtime-react/on-mount.ts +0 -5
  181. package/src/realtime-react/use-server-action.ts +0 -19
  182. package/src/realtime-server/continuity/prepare-to-serve-transaction-request.ts +0 -59
  183. package/src/realtime-server/continuity/prepare-to-sync-realtime-continuity.ts +0 -145
  184. package/src/realtime-server/continuity/prepare-to-track-client-acknowledgement.ts +0 -41
  185. package/src/realtime-server/realtime-action-receiver.ts +0 -40
  186. package/src/realtime-server/realtime-server-stores/server-room-external-actions.ts +0 -79
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/transceivers/set-rtx/set-rtx.ts"],"sourcesContent":[],"mappings":";;;;KAKY,aAAA;AAAA,KACA,SAAA,GADA,GACe,aADf,IAAA,MAAA,EAAA;AACA,KACA,iBAAA,GADe,GAAA,MAAA,IACkB,SADlB,EAAA;AACf,UAEK,UAFL,CAAA,UAE0B,SAFO,CAAA,SAEY,WAFZ,CAEwB,CAFxB,CAAA,CAAA;EAE7C,SAAiB,KAAA,EACA,aADA,CACc,iBADd,GAAA,IAAA,CAAA;EAAA,SAAA,UAAA,EAAA,MAAA;WAAqB,QAAA,EAAA,MAAA;WAA+B,iBAAA,EAAA,MAAA;;AACpD,UAMA,UANA,CAAA,UAMqB,SANrB,CAAA,SAMwC,IAAA,CAAK,MAN7C,CAAA;SADwC,EAQ/C,CAR+C,EAAA;UAShD;EAFT,UAAiB,EAAA,MAAA;EAAA,QAAA,EAAA,MAAA;mBAAqB,EAAA,MAAA;;AAE7B,cAKI,MALJ,CAAA,UAKqB,SALrB,CAAA,SAMA,GANA,CAMI,CANJ,CAAA,YAQP,WARO,CAQK,UARL,CAQgB,CARhB,CAAA,EAQoB,iBARpB,EAQuC,UARvC,CAQkD,CARlD,CAAA,CAAA,EASP,OATO,CAAA;QAWK,eAbgD;oBAcpC,QAAQ;EAPlC,UAAa,EAAA,MAAA;EAAA,KAAA,EAAA,CASG,iBATH,GAAA,IAAA,CAAA,EAAA;UAAiB,EAAA,MAAA;mBACjB,EAAA,MAAA;aAEY,CAAA,MAAA,CAAA,EAUI,QAVJ,CAUa,CAVb,CAAA,EAAA,UA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AA,CAAA,EAuCQ,MAvCR,CAuCe,CAvCf,CAAA;WAAX,EA+C7B,CA/C6B,CAAA,EAAA,IAAA;SAGlC,EAAA,IAAA;QACoB,CAAA,KAAA,EA6DZ,CA7DY,CAAA,EAAA,OAAA;WAAR,MAAA,EAsED,MAtEC,CAsEM,CAtEN,CAAA,GAAA,IAAA;SAuEX,MArEC,CAqEM,CArEN,CAAA,GAAA,IAAA;oBAIsB,EAkEV,SAlEU,EAAA,GAAA,IAAA;aAAT,CAAA,GAAA,EAAA,CAAA,KAAA,EAmEI,MAnEJ,CAmEW,CAnEX,CAAA,EAAA,GAAA,OAAA,CAAA,EAAA,IAAA;YAiBc,UAAA,CAAA,GAAA,EAAA,MAAA,EAAA,EAAA,EAAA,CAAA,MAAA,EAmF5B,SAnF4B,EAAA,GAAA,IAAA,CAAA,EAAA,GAAA,GAAA,IAAA;WAAX,CAAA,GAAA,EAAA,MAAA,EAAA,EAAA,EAAA,CAAA,MAAA,EAyFjB,iBAzFiB,EAAA,GAAA,IAAA,CAAA,EAAA,GAAA,GAAA,IAAA;aAEH,EA8FR,SA9FQ,CAAA,EAAA,IAAA;UAAX,MAAA;iBAUgB,CAAA,MAAA,EA6GF,iBA7GE,CAAA,EAAA,MAAA;WAA4B,EAkH3C,iBAlH2C,CAAA,EAAA,MAAA,GAAA,cAAA,GAAA,IAAA;UAAX,CAAA,MAAA,EA6J1B,SA7J0B,CAAA,EAAA,IAAA;aAAuB,EAsLrD,iBAtLqD,CAAA,EAAA,MAAA,GAAA,IAAA"}
@@ -77,8 +77,7 @@ var SetRTX = class SetRTX extends Set {
77
77
  this.transactionUpdates?.push(update);
78
78
  });
79
79
  try {
80
- const shouldCommit = run(this.child);
81
- if (shouldCommit) {
80
+ if (run(this.child)) {
82
81
  for (const update of this.transactionUpdates) this.doStep(update);
83
82
  this.cacheUpdateNumber++;
84
83
  this.emit(`tx:${this.transactionUpdates.join(`;`)}`);
@@ -129,8 +128,7 @@ var SetRTX = class SetRTX extends Set {
129
128
  const breakpoint = update.indexOf(`=`);
130
129
  const updateNumber = Number(update.substring(0, breakpoint));
131
130
  const eventOffset = updateNumber - this.cacheUpdateNumber;
132
- const isFuture = eventOffset > 0;
133
- if (isFuture) {
131
+ if (eventOffset > 0) {
134
132
  if (eventOffset === 1) {
135
133
  this.mode = `playback`;
136
134
  const innerUpdate = update.substring(breakpoint + 1);
@@ -143,8 +141,7 @@ var SetRTX = class SetRTX extends Set {
143
141
  }
144
142
  if (Math.abs(eventOffset) < this.cacheLimit) {
145
143
  const eventIdx = this.cacheIdx + eventOffset;
146
- const cachedUpdate = this.cache[eventIdx];
147
- if (cachedUpdate === update) return null;
144
+ if (this.cache[eventIdx] === update) return null;
148
145
  this.mode = `playback`;
149
146
  let done = false;
150
147
  while (!done) {
@@ -187,8 +184,7 @@ var SetRTX = class SetRTX extends Set {
187
184
  }
188
185
  undo(update) {
189
186
  const breakpoint = update.indexOf(`=`);
190
- const updateNumber = Number(update.substring(0, breakpoint));
191
- if (updateNumber === this.cacheUpdateNumber) {
187
+ if (Number(update.substring(0, breakpoint)) === this.cacheUpdateNumber) {
192
188
  this.mode = `playback`;
193
189
  const innerUpdate = update.substring(breakpoint + 1);
194
190
  this.undoStep(innerUpdate);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../src/transceivers/set-rtx/set-rtx.ts"],"sourcesContent":["import type { Lineage, Transceiver, TransceiverMode } from \"atom.io/internal\"\nimport { Subject } from \"atom.io/internal\"\nimport type { Json, primitive } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nexport type SetUpdateType = `add` | `clear` | `del` | `tx`\nexport type SetUpdate = `${SetUpdateType}:${string}`\nexport type NumberedSetUpdate = `${number}=${SetUpdate}`\n\nexport interface SetRTXView<P extends primitive> extends ReadonlySet<P> {\n\treadonly cache: ReadonlyArray<NumberedSetUpdate | null>\n\treadonly cacheLimit: number\n\treadonly cacheIdx: number\n\treadonly cacheUpdateNumber: number\n}\n\nexport interface SetRTXJson<P extends primitive> extends Json.Object {\n\tmembers: P[]\n\tcache: (NumberedSetUpdate | null)[]\n\tcacheLimit: number\n\tcacheIdx: number\n\tcacheUpdateNumber: number\n}\nexport class SetRTX<P extends primitive>\n\textends Set<P>\n\timplements\n\t\tTransceiver<SetRTXView<P>, NumberedSetUpdate, SetRTXJson<P>>,\n\t\tLineage\n{\n\tpublic mode: TransceiverMode = `record`\n\tpublic readonly subject: Subject<SetUpdate> = new Subject<SetUpdate>()\n\tpublic cacheLimit = 0\n\tpublic cache: (NumberedSetUpdate | null)[] = []\n\tpublic cacheIdx = -1\n\tpublic cacheUpdateNumber = -1\n\n\tpublic constructor(values?: Iterable<P>, cacheLimit = 0) {\n\t\tsuper(values)\n\t\tif (values instanceof SetRTX) {\n\t\t\tthis.parent = values\n\t\t\tthis.cacheUpdateNumber = values.cacheUpdateNumber\n\t\t}\n\t\tif (cacheLimit) {\n\t\t\tthis.cacheLimit = cacheLimit\n\t\t\tthis.cache = new Array(cacheLimit)\n\t\t\tthis.subscribe(`auto cache`, (update) => {\n\t\t\t\tthis.cacheIdx++\n\t\t\t\tthis.cacheIdx %= this.cacheLimit\n\t\t\t\tthis.cache[this.cacheIdx] = update\n\t\t\t})\n\t\t}\n\t}\n\n\tpublic readonly READONLY_VIEW: SetRTXView<P> = this\n\n\tpublic toJSON(): SetRTXJson<P> {\n\t\treturn {\n\t\t\tmembers: [...this],\n\t\t\tcache: this.cache,\n\t\t\tcacheLimit: this.cacheLimit,\n\t\t\tcacheIdx: this.cacheIdx,\n\t\t\tcacheUpdateNumber: this.cacheUpdateNumber,\n\t\t}\n\t}\n\n\tpublic static fromJSON<P extends primitive>(json: SetRTXJson<P>): SetRTX<P> {\n\t\tconst set = new SetRTX<P>(json.members, json.cacheLimit)\n\t\tset.cache = json.cache\n\t\tset.cacheIdx = json.cacheIdx\n\t\tset.cacheUpdateNumber = json.cacheUpdateNumber\n\t\treturn set\n\t}\n\n\tpublic add(value: P): this {\n\t\tconst result = super.add(value)\n\t\tif (this.mode === `record`) {\n\t\t\tthis.cacheUpdateNumber++\n\t\t\tthis.emit(`add:${stringifyJson<P>(value)}`)\n\t\t}\n\t\treturn result\n\t}\n\n\tpublic clear(): void {\n\t\tconst capturedContents = this.mode === `record` ? [...this] : null\n\t\tsuper.clear()\n\t\tif (capturedContents) {\n\t\t\tthis.cacheUpdateNumber++\n\t\t\tthis.emit(`clear:${JSON.stringify(capturedContents)}`)\n\t\t}\n\t}\n\n\tpublic delete(value: P): boolean {\n\t\tconst result = super.delete(value)\n\t\tif (this.mode === `record`) {\n\t\t\tthis.cacheUpdateNumber++\n\t\t\tthis.emit(`del:${stringifyJson<P>(value)}`)\n\t\t}\n\t\treturn result\n\t}\n\n\tpublic readonly parent: SetRTX<P> | null = null\n\tpublic child: SetRTX<P> | null = null\n\tpublic transactionUpdates: SetUpdate[] | null = null\n\tpublic transaction(run: (child: SetRTX<P>) => boolean): void {\n\t\tthis.mode = `transaction`\n\t\tthis.transactionUpdates = []\n\t\tthis.child = new SetRTX(this)\n\t\tconst unsubscribe = this.child._subscribe(`transaction`, (update) => {\n\t\t\tthis.transactionUpdates?.push(update)\n\t\t})\n\t\ttry {\n\t\t\tconst shouldCommit = run(this.child)\n\t\t\tif (shouldCommit) {\n\t\t\t\tfor (const update of this.transactionUpdates) {\n\t\t\t\t\tthis.doStep(update)\n\t\t\t\t}\n\t\t\t\tthis.cacheUpdateNumber++\n\t\t\t\tthis.emit(`tx:${this.transactionUpdates.join(`;`)}`)\n\t\t\t}\n\t\t} catch (thrown) {\n\t\t\t/* eslint-disable-next-line no-console */\n\t\t\tconsole.warn(\n\t\t\t\t`Did not apply transaction to SetRTX; this error was thrown:`,\n\t\t\t\tthrown,\n\t\t\t)\n\t\t\tthrow thrown\n\t\t} finally {\n\t\t\tunsubscribe()\n\t\t\tthis.child = null\n\t\t\tthis.transactionUpdates = null\n\t\t\tthis.mode = `record`\n\t\t}\n\t}\n\n\tprotected _subscribe(\n\t\tkey: string,\n\t\tfn: (update: SetUpdate) => void,\n\t): () => void {\n\t\treturn this.subject.subscribe(key, fn)\n\t}\n\tpublic subscribe(\n\t\tkey: string,\n\t\tfn: (update: NumberedSetUpdate) => void,\n\t): () => void {\n\t\treturn this.subject.subscribe(key, (update) => {\n\t\t\tfn(`${this.cacheUpdateNumber}=${update}`)\n\t\t})\n\t}\n\n\tpublic emit(update: SetUpdate): void {\n\t\tthis.subject.next(update)\n\t}\n\n\tprivate doStep(update: SetUpdate): void {\n\t\tconst typeValueBreak = update.indexOf(`:`)\n\t\tconst type = update.substring(0, typeValueBreak) as SetUpdateType\n\t\tconst value = update.substring(typeValueBreak + 1)\n\t\tswitch (type) {\n\t\t\tcase `add`:\n\t\t\t\tthis.add(JSON.parse(value))\n\t\t\t\tbreak\n\t\t\tcase `clear`:\n\t\t\t\tthis.clear()\n\t\t\t\tbreak\n\t\t\tcase `del`:\n\t\t\t\tthis.delete(JSON.parse(value))\n\t\t\t\tbreak\n\t\t\tcase `tx`:\n\t\t\t\tfor (const subUpdate of value.split(`;`)) {\n\t\t\t\t\tthis.doStep(subUpdate as SetUpdate)\n\t\t\t\t}\n\t\t}\n\t}\n\n\tpublic getUpdateNumber(update: NumberedSetUpdate): number {\n\t\tconst breakpoint = update.indexOf(`=`)\n\t\treturn Number(update.substring(0, breakpoint))\n\t}\n\n\tpublic do(update: NumberedSetUpdate): number | `OUT_OF_RANGE` | null {\n\t\tconst breakpoint = update.indexOf(`=`)\n\t\tconst updateNumber = Number(update.substring(0, breakpoint))\n\t\tconst eventOffset = updateNumber - this.cacheUpdateNumber\n\t\tconst isFuture = eventOffset > 0\n\t\tif (isFuture) {\n\t\t\tif (eventOffset === 1) {\n\t\t\t\tthis.mode = `playback`\n\t\t\t\tconst innerUpdate = update.substring(breakpoint + 1) as SetUpdate\n\t\t\t\tthis.doStep(innerUpdate)\n\t\t\t\tthis.mode = `record`\n\t\t\t\tthis.cacheUpdateNumber = updateNumber\n\t\t\t\treturn null\n\t\t\t}\n\t\t\treturn this.cacheUpdateNumber + 1\n\t\t}\n\t\tif (Math.abs(eventOffset) < this.cacheLimit) {\n\t\t\tconst eventIdx = this.cacheIdx + eventOffset\n\t\t\tconst cachedUpdate = this.cache[eventIdx]\n\t\t\tif (cachedUpdate === update) {\n\t\t\t\treturn null\n\t\t\t}\n\t\t\tthis.mode = `playback`\n\t\t\tlet done = false\n\t\t\twhile (!done) {\n\t\t\t\tthis.cacheIdx %= this.cacheLimit\n\t\t\t\tconst u = this.cache[this.cacheIdx]\n\t\t\t\tthis.cacheIdx--\n\t\t\t\tif (!u) {\n\t\t\t\t\treturn `OUT_OF_RANGE`\n\t\t\t\t}\n\t\t\t\tthis.undo(u)\n\t\t\t\tdone = this.cacheIdx === eventIdx - 1\n\t\t\t}\n\t\t\tconst innerUpdate = update.substring(breakpoint + 1) as SetUpdate\n\t\t\tthis.doStep(innerUpdate)\n\t\t\tthis.mode = `record`\n\t\t\tthis.cacheUpdateNumber = updateNumber\n\t\t\treturn null\n\t\t}\n\t\treturn `OUT_OF_RANGE`\n\t}\n\n\tpublic undoStep(update: SetUpdate): void {\n\t\tconst breakpoint = update.indexOf(`:`)\n\t\tconst type = update.substring(0, breakpoint) as SetUpdateType\n\t\tconst value = update.substring(breakpoint + 1)\n\t\tswitch (type) {\n\t\t\tcase `add`:\n\t\t\t\tthis.delete(JSON.parse(value))\n\t\t\t\tbreak\n\t\t\tcase `del`:\n\t\t\t\tthis.add(JSON.parse(value))\n\t\t\t\tbreak\n\t\t\tcase `clear`: {\n\t\t\t\tconst values = JSON.parse(value) as P[]\n\t\t\t\tfor (const v of values) this.add(v)\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase `tx`: {\n\t\t\t\tconst updates = value.split(`;`) as SetUpdate[]\n\t\t\t\tfor (let i = updates.length - 1; i >= 0; i--) {\n\t\t\t\t\tthis.undoStep(updates[i])\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic undo(update: NumberedSetUpdate): number | null {\n\t\tconst breakpoint = update.indexOf(`=`)\n\t\tconst updateNumber = Number(update.substring(0, breakpoint))\n\t\tif (updateNumber === this.cacheUpdateNumber) {\n\t\t\tthis.mode = `playback`\n\t\t\tconst innerUpdate = update.substring(breakpoint + 1) as SetUpdate\n\t\t\tthis.undoStep(innerUpdate)\n\t\t\tthis.mode = `record`\n\t\t\tthis.cacheUpdateNumber--\n\t\t\treturn null\n\t\t}\n\t\treturn this.cacheUpdateNumber\n\t}\n}\n"],"mappings":";;;;AAuBA,IAAa,SAAb,MAAa,eACJ,IAIT;CACC,AAAO,OAAwB;CAC/B,AAAgB,UAA8B,IAAI;CAClD,AAAO,aAAa;CACpB,AAAO,QAAsC;CAC7C,AAAO,WAAW;CAClB,AAAO,oBAAoB;CAE3B,AAAO,YAAY,QAAsB,aAAa,GAAG;AACxD,QAAM;AACN,MAAI,kBAAkB,QAAQ;AAC7B,QAAK,SAAS;AACd,QAAK,oBAAoB,OAAO;;AAEjC,MAAI,YAAY;AACf,QAAK,aAAa;AAClB,QAAK,QAAQ,IAAI,MAAM;AACvB,QAAK,UAAU,eAAe,WAAW;AACxC,SAAK;AACL,SAAK,YAAY,KAAK;AACtB,SAAK,MAAM,KAAK,YAAY;;;;CAK/B,AAAgB,gBAA+B;CAE/C,AAAO,SAAwB;AAC9B,SAAO;GACN,SAAS,CAAC,GAAG;GACb,OAAO,KAAK;GACZ,YAAY,KAAK;GACjB,UAAU,KAAK;GACf,mBAAmB,KAAK;;;CAI1B,OAAc,SAA8B,MAAgC;EAC3E,MAAM,MAAM,IAAI,OAAU,KAAK,SAAS,KAAK;AAC7C,MAAI,QAAQ,KAAK;AACjB,MAAI,WAAW,KAAK;AACpB,MAAI,oBAAoB,KAAK;AAC7B,SAAO;;CAGR,AAAO,IAAI,OAAgB;EAC1B,MAAM,SAAS,MAAM,IAAI;AACzB,MAAI,KAAK,SAAS,UAAU;AAC3B,QAAK;AACL,QAAK,KAAK,OAAO,cAAiB;;AAEnC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R;GACC,KAAK;AACJ,SAAK,OAAO,KAAK,MAAM;AACvB;GACD,KAAK;AACJ,SAAK,IAAI,KAAK,MAAM;AACpB;GACD,KAAK,SAAS;IACb,MAAM,SAAS,KAAK,MAAM;AAC1B,SAAK,MAAM,KAAK,OAAQ,MAAK,IAAI;AACjC;;GAED,KAAK,MAAM;IACV,MAAM,UAAU,MAAM,MAAM;AAC5B,SAAK,IAAI,IAAI,QAAQ,SAAS,GAAG,KAAK,GAAG,IACxC,MAAK,SAAS,QAAQ;;;;CAM1B,AAAO,KAAK,QAA0C;EACrD,MAAM,aAAa,OAAO,QAAQ;EAClC,MAAM,eAAe,OAAO,OAAO,UAAU,GAAG;AAChD,MAAI,iBAAiB,KAAK,mBAAmB;AAC5C,QAAK,OAAO;GACZ,MAAM,cAAc,OAAO,UAAU,aAAa;AAClD,QAAK,SAAS;AACd,QAAK,OAAO;AACZ,QAAK;AACL,UAAO;;AAER,SAAO,KAAK"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/transceivers/set-rtx/set-rtx.ts"],"sourcesContent":["import type { Lineage, Transceiver, TransceiverMode } from \"atom.io/internal\"\nimport { Subject } from \"atom.io/internal\"\nimport type { Json, primitive } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nexport type SetUpdateType = `add` | `clear` | `del` | `tx`\nexport type SetUpdate = `${SetUpdateType}:${string}`\nexport type NumberedSetUpdate = `${number}=${SetUpdate}`\n\nexport interface SetRTXView<P extends primitive> extends ReadonlySet<P> {\n\treadonly cache: ReadonlyArray<NumberedSetUpdate | null>\n\treadonly cacheLimit: number\n\treadonly cacheIdx: number\n\treadonly cacheUpdateNumber: number\n}\n\nexport interface SetRTXJson<P extends primitive> extends Json.Object {\n\tmembers: P[]\n\tcache: (NumberedSetUpdate | null)[]\n\tcacheLimit: number\n\tcacheIdx: number\n\tcacheUpdateNumber: number\n}\nexport class SetRTX<P extends primitive>\n\textends Set<P>\n\timplements\n\t\tTransceiver<SetRTXView<P>, NumberedSetUpdate, SetRTXJson<P>>,\n\t\tLineage\n{\n\tpublic mode: TransceiverMode = `record`\n\tpublic readonly subject: Subject<SetUpdate> = new Subject<SetUpdate>()\n\tpublic cacheLimit = 0\n\tpublic cache: (NumberedSetUpdate | null)[] = []\n\tpublic cacheIdx = -1\n\tpublic cacheUpdateNumber = -1\n\n\tpublic constructor(values?: Iterable<P>, cacheLimit = 0) {\n\t\tsuper(values)\n\t\tif (values instanceof SetRTX) {\n\t\t\tthis.parent = values\n\t\t\tthis.cacheUpdateNumber = values.cacheUpdateNumber\n\t\t}\n\t\tif (cacheLimit) {\n\t\t\tthis.cacheLimit = cacheLimit\n\t\t\tthis.cache = new Array(cacheLimit)\n\t\t\tthis.subscribe(`auto cache`, (update) => {\n\t\t\t\tthis.cacheIdx++\n\t\t\t\tthis.cacheIdx %= this.cacheLimit\n\t\t\t\tthis.cache[this.cacheIdx] = update\n\t\t\t})\n\t\t}\n\t}\n\n\tpublic readonly READONLY_VIEW: SetRTXView<P> = this\n\n\tpublic toJSON(): SetRTXJson<P> {\n\t\treturn {\n\t\t\tmembers: [...this],\n\t\t\tcache: this.cache,\n\t\t\tcacheLimit: this.cacheLimit,\n\t\t\tcacheIdx: this.cacheIdx,\n\t\t\tcacheUpdateNumber: this.cacheUpdateNumber,\n\t\t}\n\t}\n\n\tpublic static fromJSON<P extends primitive>(json: SetRTXJson<P>): SetRTX<P> {\n\t\tconst set = new SetRTX<P>(json.members, json.cacheLimit)\n\t\tset.cache = json.cache\n\t\tset.cacheIdx = json.cacheIdx\n\t\tset.cacheUpdateNumber = json.cacheUpdateNumber\n\t\treturn set\n\t}\n\n\tpublic add(value: P): this {\n\t\tconst result = super.add(value)\n\t\tif (this.mode === `record`) {\n\t\t\tthis.cacheUpdateNumber++\n\t\t\tthis.emit(`add:${stringifyJson<P>(value)}`)\n\t\t}\n\t\treturn result\n\t}\n\n\tpublic clear(): void {\n\t\tconst capturedContents = this.mode === `record` ? [...this] : null\n\t\tsuper.clear()\n\t\tif (capturedContents) {\n\t\t\tthis.cacheUpdateNumber++\n\t\t\tthis.emit(`clear:${JSON.stringify(capturedContents)}`)\n\t\t}\n\t}\n\n\tpublic delete(value: P): boolean {\n\t\tconst result = super.delete(value)\n\t\tif (this.mode === `record`) {\n\t\t\tthis.cacheUpdateNumber++\n\t\t\tthis.emit(`del:${stringifyJson<P>(value)}`)\n\t\t}\n\t\treturn result\n\t}\n\n\tpublic readonly parent: SetRTX<P> | null = null\n\tpublic child: SetRTX<P> | null = null\n\tpublic transactionUpdates: SetUpdate[] | null = null\n\tpublic transaction(run: (child: SetRTX<P>) => boolean): void {\n\t\tthis.mode = `transaction`\n\t\tthis.transactionUpdates = []\n\t\tthis.child = new SetRTX(this)\n\t\tconst unsubscribe = this.child._subscribe(`transaction`, (update) => {\n\t\t\tthis.transactionUpdates?.push(update)\n\t\t})\n\t\ttry {\n\t\t\tconst shouldCommit = run(this.child)\n\t\t\tif (shouldCommit) {\n\t\t\t\tfor (const update of this.transactionUpdates) {\n\t\t\t\t\tthis.doStep(update)\n\t\t\t\t}\n\t\t\t\tthis.cacheUpdateNumber++\n\t\t\t\tthis.emit(`tx:${this.transactionUpdates.join(`;`)}`)\n\t\t\t}\n\t\t} catch (thrown) {\n\t\t\t/* eslint-disable-next-line no-console */\n\t\t\tconsole.warn(\n\t\t\t\t`Did not apply transaction to SetRTX; this error was thrown:`,\n\t\t\t\tthrown,\n\t\t\t)\n\t\t\tthrow thrown\n\t\t} finally {\n\t\t\tunsubscribe()\n\t\t\tthis.child = null\n\t\t\tthis.transactionUpdates = null\n\t\t\tthis.mode = `record`\n\t\t}\n\t}\n\n\tprotected _subscribe(\n\t\tkey: string,\n\t\tfn: (update: SetUpdate) => void,\n\t): () => void {\n\t\treturn this.subject.subscribe(key, fn)\n\t}\n\tpublic subscribe(\n\t\tkey: string,\n\t\tfn: (update: NumberedSetUpdate) => void,\n\t): () => void {\n\t\treturn this.subject.subscribe(key, (update) => {\n\t\t\tfn(`${this.cacheUpdateNumber}=${update}`)\n\t\t})\n\t}\n\n\tpublic emit(update: SetUpdate): void {\n\t\tthis.subject.next(update)\n\t}\n\n\tprivate doStep(update: SetUpdate): void {\n\t\tconst typeValueBreak = update.indexOf(`:`)\n\t\tconst type = update.substring(0, typeValueBreak) as SetUpdateType\n\t\tconst value = update.substring(typeValueBreak + 1)\n\t\tswitch (type) {\n\t\t\tcase `add`:\n\t\t\t\tthis.add(JSON.parse(value))\n\t\t\t\tbreak\n\t\t\tcase `clear`:\n\t\t\t\tthis.clear()\n\t\t\t\tbreak\n\t\t\tcase `del`:\n\t\t\t\tthis.delete(JSON.parse(value))\n\t\t\t\tbreak\n\t\t\tcase `tx`:\n\t\t\t\tfor (const subUpdate of value.split(`;`)) {\n\t\t\t\t\tthis.doStep(subUpdate as SetUpdate)\n\t\t\t\t}\n\t\t}\n\t}\n\n\tpublic getUpdateNumber(update: NumberedSetUpdate): number {\n\t\tconst breakpoint = update.indexOf(`=`)\n\t\treturn Number(update.substring(0, breakpoint))\n\t}\n\n\tpublic do(update: NumberedSetUpdate): number | `OUT_OF_RANGE` | null {\n\t\tconst breakpoint = update.indexOf(`=`)\n\t\tconst updateNumber = Number(update.substring(0, breakpoint))\n\t\tconst eventOffset = updateNumber - this.cacheUpdateNumber\n\t\tconst isFuture = eventOffset > 0\n\t\tif (isFuture) {\n\t\t\tif (eventOffset === 1) {\n\t\t\t\tthis.mode = `playback`\n\t\t\t\tconst innerUpdate = update.substring(breakpoint + 1) as SetUpdate\n\t\t\t\tthis.doStep(innerUpdate)\n\t\t\t\tthis.mode = `record`\n\t\t\t\tthis.cacheUpdateNumber = updateNumber\n\t\t\t\treturn null\n\t\t\t}\n\t\t\treturn this.cacheUpdateNumber + 1\n\t\t}\n\t\tif (Math.abs(eventOffset) < this.cacheLimit) {\n\t\t\tconst eventIdx = this.cacheIdx + eventOffset\n\t\t\tconst cachedUpdate = this.cache[eventIdx]\n\t\t\tif (cachedUpdate === update) {\n\t\t\t\treturn null\n\t\t\t}\n\t\t\tthis.mode = `playback`\n\t\t\tlet done = false\n\t\t\twhile (!done) {\n\t\t\t\tthis.cacheIdx %= this.cacheLimit\n\t\t\t\tconst u = this.cache[this.cacheIdx]\n\t\t\t\tthis.cacheIdx--\n\t\t\t\tif (!u) {\n\t\t\t\t\treturn `OUT_OF_RANGE`\n\t\t\t\t}\n\t\t\t\tthis.undo(u)\n\t\t\t\tdone = this.cacheIdx === eventIdx - 1\n\t\t\t}\n\t\t\tconst innerUpdate = update.substring(breakpoint + 1) as SetUpdate\n\t\t\tthis.doStep(innerUpdate)\n\t\t\tthis.mode = `record`\n\t\t\tthis.cacheUpdateNumber = updateNumber\n\t\t\treturn null\n\t\t}\n\t\treturn `OUT_OF_RANGE`\n\t}\n\n\tpublic undoStep(update: SetUpdate): void {\n\t\tconst breakpoint = update.indexOf(`:`)\n\t\tconst type = update.substring(0, breakpoint) as SetUpdateType\n\t\tconst value = update.substring(breakpoint + 1)\n\t\tswitch (type) {\n\t\t\tcase `add`:\n\t\t\t\tthis.delete(JSON.parse(value))\n\t\t\t\tbreak\n\t\t\tcase `del`:\n\t\t\t\tthis.add(JSON.parse(value))\n\t\t\t\tbreak\n\t\t\tcase `clear`: {\n\t\t\t\tconst values = JSON.parse(value) as P[]\n\t\t\t\tfor (const v of values) this.add(v)\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase `tx`: {\n\t\t\t\tconst updates = value.split(`;`) as SetUpdate[]\n\t\t\t\tfor (let i = updates.length - 1; i >= 0; i--) {\n\t\t\t\t\tthis.undoStep(updates[i])\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic undo(update: NumberedSetUpdate): number | null {\n\t\tconst breakpoint = update.indexOf(`=`)\n\t\tconst updateNumber = Number(update.substring(0, breakpoint))\n\t\tif (updateNumber === this.cacheUpdateNumber) {\n\t\t\tthis.mode = `playback`\n\t\t\tconst innerUpdate = update.substring(breakpoint + 1) as SetUpdate\n\t\t\tthis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C,MAAM,OAAO,OAAO,UAAU,GAAG,WAAW;EAC5C,MAAM,QAAQ,OAAO,UAAU,aAAa,EAAE;AAC9C,UAAQ,MAAR;GACC,KAAK;AACJ,SAAK,OAAO,KAAK,MAAM,MAAM,CAAC;AAC9B;GACD,KAAK;AACJ,SAAK,IAAI,KAAK,MAAM,MAAM,CAAC;AAC3B;GACD,KAAK,SAAS;IACb,MAAM,SAAS,KAAK,MAAM,MAAM;AAChC,SAAK,MAAM,KAAK,OAAQ,MAAK,IAAI,EAAE;AACnC;;GAED,KAAK,MAAM;IACV,MAAM,UAAU,MAAM,MAAM,IAAI;AAChC,SAAK,IAAI,IAAI,QAAQ,SAAS,GAAG,KAAK,GAAG,IACxC,MAAK,SAAS,QAAQ,GAAG;;;;CAM7B,AAAO,KAAK,QAA0C;EACrD,MAAM,aAAa,OAAO,QAAQ,IAAI;AAEtC,MADqB,OAAO,OAAO,UAAU,GAAG,WAAW,CAAC,KACvC,KAAK,mBAAmB;AAC5C,QAAK,OAAO;GACZ,MAAM,cAAc,OAAO,UAAU,aAAa,EAAE;AACpD,QAAK,SAAS,YAAY;AAC1B,QAAK,OAAO;AACZ,QAAK;AACL,UAAO;;AAER,SAAO,KAAK"}
@@ -1,14 +1,14 @@
1
1
  import { AtomEffect, ViewOf } from "atom.io";
2
2
 
3
- //#region src/web/persist-sync.d.ts
3
+ //#region src/web/storage-sync.d.ts
4
4
  type StringInterface<T> = {
5
5
  stringify: (t: ViewOf<T>) => string;
6
6
  parse: (s: string) => T;
7
7
  };
8
- declare const persistSync: <T>(storage: Storage, {
8
+ declare const storageSync: <T>(storage: Storage | undefined, {
9
9
  stringify,
10
10
  parse
11
11
  }: StringInterface<T>, key: string) => AtomEffect<T>;
12
12
  //#endregion
13
- export { StringInterface, persistSync };
13
+ export { StringInterface, storageSync };
14
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/web/persist-sync.ts"],"sourcesContent":[],"mappings":";;;KAEY;iBACI,OAAO;EADvB,KAAY,EAAA,CAAA,CAAA,EAAA,MAAA,EAAA,GAEW,CAFX;CAAA;AACW,cAIV,WAJU,EAAA,CAAA,CAAA,CAAA,CAAA,OAAA,EAMZ,OANY,EAAA;EAAA,SAAA;EAAA;AAAA,CAAA,EAOC,eAPD,CAOiB,CAPjB,CAAA,EAAA,GAAA,EAAA,MAAA,EAAA,GASnB,UATmB,CASR,CATQ,CAAA"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/web/storage-sync.ts"],"sourcesContent":[],"mappings":";;;KAEY;iBACI,OAAO;EADvB,KAAY,EAAA,CAAA,CAAA,EAAA,MAAA,EAAA,GAEW,CAFX;CAAA;AACW,cAIV,WAJU,EAAA,CAAA,CAAA,CAAA,CAAA,OAAA,EAMZ,OANY,GAAA,SAAA,EAAA;EAAA,SAAA;EAAA;AAAA,CAAA,EAOC,eAPD,CAOiB,CAPjB,CAAA,EAAA,GAAA,EAAA,MAAA,EAAA,GASnB,UATmB,CASR,CATQ,CAAA"}
package/dist/web/index.js CHANGED
@@ -1,5 +1,6 @@
1
- //#region src/web/persist-sync.ts
2
- const persistSync = (storage, { stringify, parse }, key) => ({ setSelf, onSet }) => {
1
+ //#region src/web/storage-sync.ts
2
+ const storageSync = (storage, { stringify, parse }, key) => ({ setSelf, onSet }) => {
3
+ if (!storage) return;
3
4
  const savedValue = storage.getItem(key);
4
5
  if (savedValue != null) setSelf(parse(savedValue));
5
6
  onSet(({ newValue }) => {
@@ -12,5 +13,5 @@ const persistSync = (storage, { stringify, parse }, key) => ({ setSelf, onSet })
12
13
  };
13
14
 
14
15
  //#endregion
15
- export { persistSync };
16
+ export { storageSync };
16
17
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/web/persist-sync.ts"],"sourcesContent":["import type { AtomEffect, ViewOf } from \"atom.io\"\n\nexport type StringInterface<T> = {\n\tstringify: (t: ViewOf<T>) => string\n\tparse: (s: string) => T\n}\n\nexport const persistSync =\n\t<T>(\n\t\tstorage: Storage,\n\t\t{ stringify, parse }: StringInterface<T>,\n\t\tkey: string,\n\t): AtomEffect<T> =>\n\t({ setSelf, onSet }) => {\n\t\tconst savedValue = storage.getItem(key)\n\t\tif (savedValue != null) setSelf(parse(savedValue))\n\n\t\tonSet(({ newValue }) => {\n\t\t\tif (newValue == null) {\n\t\t\t\tstorage.removeItem(key)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tstorage.setItem(key, stringify(newValue))\n\t\t})\n\t}\n"],"mappings":";AAOA,MAAa,eAEX,SACA,EAAE,WAAW,SACb,SAEA,EAAE,SAAS,YAAY;CACvB,MAAM,aAAa,QAAQ,QAAQ;AACnC,KAAI,cAAc,KAAM,SAAQ,MAAM;AAEtC,QAAO,EAAE,eAAe;AACvB,MAAI,YAAY,MAAM;AACrB,WAAQ,WAAW;AACnB;;AAED,UAAQ,QAAQ,KAAK,UAAU"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/web/storage-sync.ts"],"sourcesContent":["import type { AtomEffect, ViewOf } from \"atom.io\"\n\nexport type StringInterface<T> = {\n\tstringify: (t: ViewOf<T>) => string\n\tparse: (s: string) => T\n}\n\nexport const storageSync =\n\t<T>(\n\t\tstorage: Storage | undefined,\n\t\t{ stringify, parse }: StringInterface<T>,\n\t\tkey: string,\n\t): AtomEffect<T> =>\n\t({ setSelf, onSet }) => {\n\t\tif (!storage) {\n\t\t\treturn\n\t\t}\n\t\tconst savedValue = storage.getItem(key)\n\t\tif (savedValue != null) setSelf(parse(savedValue))\n\n\t\tonSet(({ newValue }) => {\n\t\t\tif (newValue == null) {\n\t\t\t\tstorage.removeItem(key)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tstorage.setItem(key, stringify(newValue))\n\t\t})\n\t}\n"],"mappings":";AAOA,MAAa,eAEX,SACA,EAAE,WAAW,SACb,SAEA,EAAE,SAAS,YAAY;AACvB,KAAI,CAAC,QACJ;CAED,MAAM,aAAa,QAAQ,QAAQ,IAAI;AACvC,KAAI,cAAc,KAAM,SAAQ,MAAM,WAAW,CAAC;AAElD,QAAO,EAAE,eAAe;AACvB,MAAI,YAAY,MAAM;AACrB,WAAQ,WAAW,IAAI;AACvB;;AAED,UAAQ,QAAQ,KAAK,UAAU,SAAS,CAAC;GACxC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "atom.io",
3
- "version": "0.40.6",
3
+ "version": "0.40.8",
4
4
  "description": "Composable and testable reactive data library.",
5
5
  "homepage": "https://atom.io.fyi",
6
6
  "sideEffects": false,
@@ -61,9 +61,9 @@
61
61
  },
62
62
  "devDependencies": {
63
63
  "@eslint/core": "0.15.2",
64
- "@storybook/addon-docs": "9.1.3",
65
- "@storybook/addon-onboarding": "9.1.3",
66
- "@storybook/react-vite": "9.1.3",
64
+ "@storybook/addon-docs": "9.1.5",
65
+ "@storybook/addon-onboarding": "9.1.5",
66
+ "@storybook/react-vite": "9.1.5",
67
67
  "@testing-library/react": "16.3.0",
68
68
  "@types/bun": "npm:bun-types@1.2.21",
69
69
  "@types/eslint": "9.6.1",
@@ -72,15 +72,15 @@
72
72
  "@types/npmlog": "7.0.0",
73
73
  "@types/react": "19.1.12",
74
74
  "@types/tmp": "0.2.6",
75
- "@typescript-eslint/parser": "8.41.0",
76
- "@typescript-eslint/rule-tester": "8.41.0",
77
- "@typescript-eslint/utils": "8.41.0",
75
+ "@typescript-eslint/parser": "8.43.0",
76
+ "@typescript-eslint/rule-tester": "8.43.0",
77
+ "@typescript-eslint/utils": "8.43.0",
78
78
  "@vitest/coverage-v8": "3.2.4",
79
79
  "@vitest/ui": "3.2.4",
80
80
  "concurrently": "9.2.1",
81
81
  "drizzle-kit": "0.31.4",
82
82
  "drizzle-orm": "0.44.5",
83
- "eslint": "9.34.0",
83
+ "eslint": "9.35.0",
84
84
  "happy-dom": "18.0.1",
85
85
  "http-proxy": "1.18.1",
86
86
  "motion": "12.23.12",
@@ -94,15 +94,15 @@
94
94
  "recoverage": "0.1.11",
95
95
  "socket.io": "4.8.1",
96
96
  "socket.io-client": "4.8.1",
97
- "storybook": "9.1.3",
97
+ "storybook": "9.1.5",
98
98
  "tmp": "0.2.5",
99
- "tsdown": "0.14.2",
99
+ "tsdown": "0.15.0",
100
100
  "typescript": "5.9.2",
101
- "vite": "7.1.3",
101
+ "vite": "7.1.5",
102
102
  "vite-tsconfig-paths": "5.1.4",
103
103
  "vitest": "3.2.4",
104
104
  "zod": "3.25.76",
105
- "break-check": "0.6.14"
105
+ "break-check": "0.6.16"
106
106
  },
107
107
  "main": "./dist/main/index.js",
108
108
  "files": [
@@ -177,7 +177,7 @@
177
177
  },
178
178
  "scripts": {
179
179
  "manifest": "./__scripts__/manifest-build.node.ts",
180
- "build": "tsdown && bun ./__scripts__/build-sort.bun.ts",
180
+ "build": "tsdown",
181
181
  "lint:biome": "biome check -- .",
182
182
  "lint:eslint": "eslint -- .",
183
183
  "lint:types": "tsgo --noEmit",
@@ -6,20 +6,21 @@ import type {
6
6
  } from "atom.io"
7
7
  import type { Canonical } from "atom.io/json"
8
8
 
9
- import type { RegularAtom, RootStore } from ".."
10
- import { resetInStore, setIntoStore } from ".."
11
9
  import { newest } from "../lineage"
10
+ import { resetInStore, setIntoStore } from "../set-state"
11
+ import type { RegularAtom } from "../state-types"
12
12
  import type { Store } from "../store"
13
13
  import { deposit } from "../store"
14
14
  import { Subject } from "../subject"
15
15
  import { subscribeToState } from "../subscribe"
16
- import type { internalRole } from "./has-role"
16
+ import type { RootStore } from "../transaction"
17
+ import type { InternalRole } from "./has-role"
17
18
 
18
19
  export function createRegularAtom<T, K extends Canonical, E>(
19
20
  store: Store,
20
21
  options: RegularAtomOptions<T, E>,
21
22
  family: FamilyMetadata<K> | undefined,
22
- internalRoles?: internalRole[],
23
+ internalRoles?: InternalRole[],
23
24
  ): RegularAtomToken<T, K, E> {
24
25
  const type = `atom`
25
26
  const { key } = options
@@ -1,8 +1,13 @@
1
1
  import type { AtomDisposalEvent, AtomToken, StateLifecycleEvent } from "atom.io"
2
2
 
3
- import type { Store, Subject } from ".."
4
- import { getUpdateToken, hasRole, isChildStore, newest, withdraw } from ".."
5
3
  import { getFamilyOfToken } from "../families/get-family-of-token"
4
+ import { newest } from "../lineage"
5
+ import { getUpdateToken } from "../mutable"
6
+ import type { Store } from "../store"
7
+ import { withdraw } from "../store"
8
+ import type { Subject } from "../subject"
9
+ import { isChildStore } from "../transaction"
10
+ import { hasRole } from "./has-role"
6
11
 
7
12
  export function disposeAtom(
8
13
  store: Store,
@@ -1,9 +1,9 @@
1
- import type { Atom } from ".."
1
+ import type { Atom } from "../state-types"
2
2
 
3
3
  export const INTERNAL_ROLES = [`tracker:signal`] as const
4
- export type internalRole = (typeof INTERNAL_ROLES)[number]
4
+ export type InternalRole = (typeof INTERNAL_ROLES)[number]
5
5
 
6
- export function hasRole(atom: Atom<any, any>, role: internalRole): boolean {
6
+ export function hasRole(atom: Atom<any, any>, role: InternalRole): boolean {
7
7
  if (`internalRoles` in atom === false) {
8
8
  return false
9
9
  }
@@ -1,11 +1,13 @@
1
- import type { ReadableState, Transceiver } from "."
2
- import { closeOperation, isChildStore, openOperation, Tracker } from "."
3
1
  import { Future } from "./future"
2
+ import { Tracker, type Transceiver } from "./mutable"
3
+ import { closeOperation, openOperation } from "./operation"
4
4
  import {
5
5
  evictDownstreamFromAtom,
6
6
  evictDownstreamFromSelector,
7
7
  } from "./set-state/evict-downstream"
8
+ import type { ReadableState } from "./state-types"
8
9
  import type { Store } from "./store"
10
+ import { isChildStore } from "./transaction"
9
11
 
10
12
  export function writeToCache<T, E>(
11
13
  target: Store,
@@ -9,10 +9,11 @@ import { PRETTY_TOKEN_TYPES } from "atom.io"
9
9
  import type { Canonical } from "atom.io/json"
10
10
  import { stringifyJson } from "atom.io/json"
11
11
 
12
- import type { ReadonlyHeldSelectorFamily, RootStore } from ".."
13
12
  import { newest } from "../lineage"
14
13
  import { createReadonlyHeldSelector } from "../selector"
14
+ import type { ReadonlyHeldSelectorFamily } from "../state-types"
15
15
  import { Subject } from "../subject"
16
+ import type { RootStore } from "../transaction"
16
17
 
17
18
  export function createReadonlyHeldSelectorFamily<
18
19
  T extends object,
@@ -12,11 +12,14 @@ import { PRETTY_TOKEN_TYPES } from "atom.io"
12
12
  import type { Canonical } from "atom.io/json"
13
13
  import { stringifyJson } from "atom.io/json"
14
14
 
15
- import type { ReadonlyPureSelectorFamily, RootStore } from ".."
16
- import { findInStore, getFromStore, getJsonToken } from ".."
15
+ import { getFromStore } from "../get-state"
17
16
  import { newest } from "../lineage"
17
+ import { getJsonToken } from "../mutable"
18
18
  import { createReadonlyPureSelector } from "../selector"
19
+ import type { ReadonlyPureSelectorFamily } from "../state-types"
19
20
  import { Subject } from "../subject"
21
+ import type { RootStore } from "../transaction"
22
+ import { findInStore } from "./find-in-store"
20
23
 
21
24
  export function createReadonlyPureSelectorFamily<T, K extends Canonical, E>(
22
25
  store: RootStore,
@@ -10,11 +10,12 @@ import { PRETTY_TOKEN_TYPES } from "atom.io"
10
10
  import type { Canonical } from "atom.io/json"
11
11
  import { stringifyJson } from "atom.io/json"
12
12
 
13
- import type { RegularAtomFamily, RootStore } from ".."
14
13
  import { createRegularAtom } from "../atom"
15
14
  import { isFn } from "../is-fn"
16
15
  import { newest } from "../lineage"
16
+ import type { RegularAtomFamily } from "../state-types"
17
17
  import { Subject } from "../subject"
18
+ import type { RootStore } from "../transaction"
18
19
 
19
20
  export function createRegularAtomFamily<T, K extends Canonical, E>(
20
21
  store: RootStore,
@@ -9,11 +9,12 @@ import { PRETTY_TOKEN_TYPES } from "atom.io"
9
9
  import type { Canonical } from "atom.io/json"
10
10
  import { stringifyJson } from "atom.io/json"
11
11
 
12
- import type { RootStore, WritableHeldSelectorFamily } from ".."
13
12
  import { newest } from "../lineage"
14
13
  import { createWritableHeldSelector } from "../selector"
14
+ import type { WritableHeldSelectorFamily } from "../state-types"
15
15
  import type { Store } from "../store"
16
16
  import { Subject } from "../subject"
17
+ import type { RootStore } from "../transaction"
17
18
 
18
19
  export function createWritableHeldSelectorFamily<
19
20
  T extends object,
@@ -12,12 +12,15 @@ import { PRETTY_TOKEN_TYPES } from "atom.io"
12
12
  import type { Canonical } from "atom.io/json"
13
13
  import { stringifyJson } from "atom.io/json"
14
14
 
15
- import type { RootStore, WritablePureSelectorFamily } from ".."
16
- import { findInStore, getFromStore, getJsonToken } from ".."
15
+ import { getFromStore } from "../get-state"
17
16
  import { newest } from "../lineage"
17
+ import { getJsonToken } from "../mutable"
18
18
  import { createWritablePureSelector } from "../selector"
19
+ import type { WritablePureSelectorFamily } from "../state-types"
19
20
  import type { Store } from "../store"
20
21
  import { Subject } from "../subject"
22
+ import type { RootStore } from "../transaction"
23
+ import { findInStore } from "./find-in-store"
21
24
 
22
25
  export function createWritablePureSelectorFamily<T, K extends Canonical, E>(
23
26
  store: Store,
@@ -11,16 +11,16 @@ export function disposeFromStore(
11
11
  token: ReadableToken<any, any, any>,
12
12
  ): void
13
13
 
14
- export function disposeFromStore<K extends Canonical, Key extends K>(
14
+ export function disposeFromStore<K extends Canonical>(
15
15
  store: Store,
16
16
  token: ReadableFamilyToken<any, K, any>,
17
- key: Key,
17
+ key: NoInfer<K>,
18
18
  ): void
19
19
 
20
- export function disposeFromStore<K extends Canonical, Key extends K>(
20
+ export function disposeFromStore<K extends Canonical>(
21
21
  store: Store,
22
22
  ...params:
23
- | [token: ReadableFamilyToken<any, K, any>, key: Key]
23
+ | [token: ReadableFamilyToken<any, K, any>, key: NoInfer<K>]
24
24
  | [token: ReadableToken<any, any, any>]
25
25
  ): void
26
26
 
@@ -20,7 +20,7 @@ import type { Canonical } from "atom.io/json"
20
20
 
21
21
  import type { Transceiver } from "../mutable"
22
22
  import { type Store, withdraw } from "../store"
23
- import { mintInStore } from "./mint-in-store"
23
+ import { DO_NOT_CREATE, mintInStore } from "./mint-in-store"
24
24
  import { seekInStore } from "./seek-in-store"
25
25
 
26
26
  // seek [token 🟧] [inits ⬛]
@@ -36,49 +36,49 @@ export function findInStore<
36
36
  store: Store,
37
37
  familyToken: MutableAtomFamilyToken<T, K>,
38
38
  key: Key,
39
- ): MutableAtomToken<T, K>
39
+ ): MutableAtomToken<T, Key>
40
40
 
41
41
  export function findInStore<T, K extends Canonical, Key extends K, E>(
42
42
  store: Store,
43
43
  familyToken: RegularAtomFamilyToken<T, K, E>,
44
44
  key: Key,
45
- ): RegularAtomToken<T, K, E>
45
+ ): RegularAtomToken<T, Key, E>
46
46
 
47
47
  export function findInStore<T, K extends Canonical, Key extends K, E>(
48
48
  store: Store,
49
49
  familyToken: AtomFamilyToken<T, K, E>,
50
50
  key: Key,
51
- ): AtomToken<T, K, E>
51
+ ): AtomToken<T, Key, E>
52
52
 
53
53
  export function findInStore<T, K extends Canonical, Key extends K, E>(
54
54
  store: Store,
55
55
  familyToken: WritablePureSelectorFamilyToken<T, K, E>,
56
56
  key: Key,
57
- ): WritablePureSelectorToken<T, K, E>
57
+ ): WritablePureSelectorToken<T, Key, E>
58
58
 
59
59
  export function findInStore<T, K extends Canonical, Key extends K, E>(
60
60
  store: Store,
61
61
  familyToken: ReadonlyPureSelectorFamilyToken<T, K, E>,
62
62
  key: Key,
63
- ): ReadonlyPureSelectorToken<T, K, E>
63
+ ): ReadonlyPureSelectorToken<T, Key, E>
64
64
 
65
65
  export function findInStore<T, K extends Canonical, Key extends K, E>(
66
66
  store: Store,
67
67
  familyToken: SelectorFamilyToken<T, K, E>,
68
68
  key: Key,
69
- ): SelectorToken<T, K, E>
69
+ ): SelectorToken<T, Key, E>
70
70
 
71
71
  export function findInStore<T, K extends Canonical, Key extends K, E>(
72
72
  store: Store,
73
73
  familyToken: WritableFamilyToken<T, K, E>,
74
74
  key: Key,
75
- ): WritableToken<T, K, E>
75
+ ): WritableToken<T, Key, E>
76
76
 
77
77
  export function findInStore<T, K extends Canonical, Key extends K, E>(
78
78
  store: Store,
79
79
  familyToken: ReadableFamilyToken<T, K, E>,
80
80
  key: Key,
81
- ): ReadableToken<T, K, E>
81
+ ): ReadableToken<T, Key, E>
82
82
 
83
83
  export function findInStore(
84
84
  store: Store,
@@ -90,6 +90,6 @@ export function findInStore(
90
90
  if (existingStateToken) {
91
91
  return existingStateToken
92
92
  }
93
- const newStateToken = mintInStore(store, family, key)
93
+ const newStateToken = mintInStore(DO_NOT_CREATE, store, family, key)
94
94
  return newStateToken
95
95
  }
@@ -8,6 +8,7 @@ import type {
8
8
  } from "atom.io"
9
9
  import type { Canonical } from "atom.io/json"
10
10
 
11
+ import type { Transceiver } from "../mutable"
11
12
  import type {
12
13
  MutableAtomFamily,
13
14
  ReadableFamily,
@@ -15,8 +16,7 @@ import type {
15
16
  RegularAtomFamily,
16
17
  WritableFamily,
17
18
  WritablePureSelectorFamily,
18
- } from ".."
19
- import type { Transceiver } from "../mutable"
19
+ } from "../state-types"
20
20
  import { type Store, withdraw } from "../store"
21
21
 
22
22
  export function getFamilyOfToken<
@@ -5,4 +5,5 @@ export * from "./create-selector-family"
5
5
  export * from "./create-writable-pure-selector-family"
6
6
  export * from "./dispose-from-store"
7
7
  export * from "./find-in-store"
8
+ export * from "./get-family-of-token"
8
9
  export * from "./seek-in-store"
@@ -2,48 +2,71 @@ import type { ReadableToken, WritableToken } from "atom.io"
2
2
  import type { Canonical } from "atom.io/json"
3
3
  import { stringifyJson } from "atom.io/json"
4
4
 
5
- import type { ReadableFamily } from ".."
5
+ import type { ReadableFamily } from "../state-types"
6
6
  import type { Store } from "../store"
7
- import { COUNTERFEIT, mint } from "../store"
7
+
8
+ export const FAMILY_MEMBER_TOKEN_TYPES = {
9
+ atom_family: `atom`,
10
+ molecule_family: `molecule`,
11
+ mutable_atom_family: `mutable_atom`,
12
+ readonly_held_selector_family: `readonly_held_selector`,
13
+ readonly_pure_selector_family: `readonly_pure_selector`,
14
+ writable_held_selector_family: `writable_held_selector`,
15
+ writable_pure_selector_family: `writable_pure_selector`,
16
+ } as const
8
17
 
9
18
  export const MUST_CREATE: unique symbol = Symbol(`MUST_CREATE`)
19
+ export const DO_NOT_CREATE: unique symbol = Symbol(`DO_NOT_CREATE`)
10
20
 
11
- export function mintInStore<T, K extends Canonical, Key extends K, E>(
21
+ export function mintInStore<T, K extends Canonical, KK extends K, E>(
22
+ mustCreate: typeof DO_NOT_CREATE | typeof MUST_CREATE,
12
23
  store: Store,
13
24
  family: ReadableFamily<T, K, E>,
14
- key: Key,
15
- mustCreate?: typeof MUST_CREATE,
16
- ): WritableToken<T, Key, E>
17
- export function mintInStore<T, K extends Canonical, Key extends K, E>(
25
+ key: KK,
26
+ ): WritableToken<T, KK, E>
27
+ export function mintInStore<T, K extends Canonical, KK extends K, E>(
28
+ mustCreate: typeof DO_NOT_CREATE | typeof MUST_CREATE,
18
29
  store: Store,
19
30
  family: ReadableFamily<T, K, E>,
20
- key: Key,
21
- mustCreate?: typeof MUST_CREATE,
22
- ): ReadableToken<T, Key, E>
23
- export function mintInStore<T, K extends Canonical, Key extends K, E>(
31
+ key: KK,
32
+ ): ReadableToken<T, KK, E>
33
+ export function mintInStore<T, K extends Canonical, KK extends K, E>(
34
+ mustCreate: typeof DO_NOT_CREATE | typeof MUST_CREATE,
24
35
  store: Store,
25
36
  family: ReadableFamily<T, K, E>,
26
- key: Key,
27
- mustCreate?: typeof MUST_CREATE,
28
- ): ReadableToken<T, Key, E> {
37
+ key: KK,
38
+ ): ReadableToken<T, KK, E> {
29
39
  const stringKey = stringifyJson(key)
30
40
  const molecule = store.molecules.get(stringKey)
31
41
 
32
42
  const cannotCreate = !molecule && store.config.lifespan === `immortal`
33
43
 
34
44
  if (cannotCreate) {
45
+ const { type: familyType, key: familyKey } = family
35
46
  store.logger.warn(
36
47
  `💣`,
37
48
  `key`,
38
49
  stringKey,
39
50
  `was used to mint a counterfeit token for`,
40
- family.type,
41
- `"${family.key}"`,
51
+ familyType,
52
+ `"${familyKey}"`,
42
53
  )
43
- return mint(family, key, COUNTERFEIT)
54
+ const fullKey = `${familyKey}(${stringKey})`
55
+ const type = FAMILY_MEMBER_TOKEN_TYPES[familyType]
56
+ const stateToken: ReadableToken<T, KK, E> & { counterfeit: true } = {
57
+ counterfeit: true,
58
+ key: fullKey,
59
+ type,
60
+ family: {
61
+ key: familyKey,
62
+ subKey: stringKey,
63
+ },
64
+ }
65
+
66
+ return stateToken
44
67
  }
45
68
 
46
- let token: ReadableToken<T, Key, E>
69
+ let token: ReadableToken<T, KK, E>
47
70
  if (mustCreate === MUST_CREATE) {
48
71
  store.logger.info(
49
72
  `👪`,
@@ -57,7 +80,19 @@ export function mintInStore<T, K extends Canonical, Key extends K, E>(
57
80
  store.moleculeData.set(stringKey, family.key)
58
81
  }
59
82
  } else {
60
- token = mint(family, key)
83
+ const { type: familyType, key: familyKey } = family
84
+ const fullKey = `${familyKey}(${stringKey})`
85
+ const type = FAMILY_MEMBER_TOKEN_TYPES[familyType]
86
+ const stateToken: ReadableToken<T, KK, E> = {
87
+ key: fullKey,
88
+ type,
89
+ family: {
90
+ key: familyKey,
91
+ subKey: stringKey,
92
+ },
93
+ }
94
+
95
+ return stateToken
61
96
  }
62
97
 
63
98
  return token
@@ -19,9 +19,9 @@ import type {
19
19
  import type { Canonical } from "atom.io/json"
20
20
  import { stringifyJson } from "atom.io/json"
21
21
 
22
- import type { ReadableState } from ".."
23
22
  import { newest } from "../lineage"
24
23
  import type { Transceiver } from "../mutable"
24
+ import type { ReadableState } from "../state-types"
25
25
  import { deposit, type Store } from "../store"
26
26
 
27
27
  export function seekInStore<