atom.io 0.36.3 → 0.37.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/dist/data/index.d.ts.map +1 -1
  2. package/dist/data/index.js.map +1 -1
  3. package/dist/eslint-plugin/index.js +1 -2
  4. package/dist/eslint-plugin/index.js.map +1 -1
  5. package/dist/internal/index.d.ts +66 -98
  6. package/dist/internal/index.d.ts.map +1 -1
  7. package/dist/internal/index.js +543 -504
  8. package/dist/internal/index.js.map +1 -1
  9. package/dist/introspection/index.d.ts +2 -2
  10. package/dist/introspection/index.d.ts.map +1 -1
  11. package/dist/introspection/index.js +1 -1
  12. package/dist/introspection/index.js.map +1 -1
  13. package/dist/json/index.d.ts +2 -1
  14. package/dist/json/index.d.ts.map +1 -1
  15. package/dist/json/index.js.map +1 -1
  16. package/dist/main/index.d.ts +154 -139
  17. package/dist/main/index.d.ts.map +1 -1
  18. package/dist/main/index.js.map +1 -1
  19. package/dist/react/index.d.ts.map +1 -1
  20. package/dist/react/index.js.map +1 -1
  21. package/dist/react-devtools/index.d.ts.map +1 -1
  22. package/dist/react-devtools/index.js +54 -56
  23. package/dist/react-devtools/index.js.map +1 -1
  24. package/dist/realtime/index.d.ts.map +1 -1
  25. package/dist/realtime/index.js.map +1 -1
  26. package/dist/realtime-client/index.d.ts +3 -3
  27. package/dist/realtime-client/index.d.ts.map +1 -1
  28. package/dist/realtime-client/index.js +6 -6
  29. package/dist/realtime-client/index.js.map +1 -1
  30. package/dist/realtime-react/index.d.ts.map +1 -1
  31. package/dist/realtime-react/index.js.map +1 -1
  32. package/dist/realtime-server/index.d.ts +5 -5
  33. package/dist/realtime-server/index.d.ts.map +1 -1
  34. package/dist/realtime-server/index.js +10 -12
  35. package/dist/realtime-server/index.js.map +1 -1
  36. package/dist/realtime-testing/index.d.ts.map +1 -1
  37. package/dist/realtime-testing/index.js.map +1 -1
  38. package/dist/transceivers/set-rtx/index.d.ts +1 -1
  39. package/dist/transceivers/set-rtx/index.d.ts.map +1 -1
  40. package/dist/transceivers/set-rtx/index.js +1 -3
  41. package/dist/transceivers/set-rtx/index.js.map +1 -1
  42. package/dist/use-o-DXPncKmZ.js.map +1 -1
  43. package/dist/web/index.d.ts +2 -2
  44. package/dist/web/index.d.ts.map +1 -1
  45. package/dist/web/index.js.map +1 -1
  46. package/package.json +5 -5
  47. package/src/internal/atom/dispose-atom.ts +5 -4
  48. package/src/internal/caching.ts +1 -1
  49. package/src/internal/families/create-readonly-held-selector-family.ts +3 -5
  50. package/src/internal/families/create-readonly-pure-selector-family.ts +3 -5
  51. package/src/internal/families/create-regular-atom-family.ts +3 -6
  52. package/src/internal/families/create-writable-held-selector-family.ts +3 -5
  53. package/src/internal/families/create-writable-pure-selector-family.ts +3 -5
  54. package/src/internal/families/find-in-store.ts +17 -34
  55. package/src/internal/families/init-family-member.ts +5 -87
  56. package/src/internal/families/mint-in-store.ts +74 -0
  57. package/src/internal/get-state/read-or-compute-value.ts +4 -2
  58. package/src/internal/index.ts +19 -18
  59. package/src/internal/ingest-updates/ingest-atom-update.ts +7 -7
  60. package/src/internal/ingest-updates/ingest-creation-disposal.ts +11 -11
  61. package/src/internal/ingest-updates/ingest-selector-update.ts +8 -4
  62. package/src/internal/ingest-updates/ingest-transaction-update.ts +5 -6
  63. package/src/internal/install-into-store.ts +2 -2
  64. package/src/internal/join/join-internal.ts +1 -1
  65. package/src/internal/molecule.ts +12 -9
  66. package/src/internal/mutable/create-mutable-atom-family.ts +3 -6
  67. package/src/internal/mutable/tracker.ts +2 -2
  68. package/src/internal/mutable/transceiver.ts +6 -4
  69. package/src/internal/operation.ts +17 -14
  70. package/src/internal/selector/create-readonly-held-selector.ts +9 -7
  71. package/src/internal/selector/create-readonly-pure-selector.ts +8 -5
  72. package/src/internal/selector/create-writable-held-selector.ts +12 -21
  73. package/src/internal/selector/create-writable-pure-selector.ts +15 -28
  74. package/src/internal/selector/dispose-selector.ts +6 -1
  75. package/src/internal/selector/get-selector-dependency-keys.ts +2 -6
  76. package/src/internal/selector/register-selector.ts +64 -74
  77. package/src/internal/selector/trace-selector-atoms.ts +2 -2
  78. package/src/internal/selector/update-selector-atoms.ts +2 -2
  79. package/src/internal/set-state/dispatch-state-update.ts +101 -0
  80. package/src/internal/set-state/operate-on-store.ts +126 -0
  81. package/src/internal/set-state/reset-atom-or-selector.ts +24 -15
  82. package/src/internal/set-state/set-atom-or-selector.ts +9 -4
  83. package/src/internal/set-state/set-atom.ts +4 -49
  84. package/src/internal/set-state/set-into-store.ts +11 -77
  85. package/src/internal/set-state/set-selector.ts +35 -0
  86. package/src/internal/store/store.ts +4 -4
  87. package/src/internal/subscribe/subscribe-in-store.ts +3 -3
  88. package/src/internal/subscribe/subscribe-to-timeline.ts +2 -2
  89. package/src/internal/timeline/create-timeline.ts +57 -101
  90. package/src/internal/timeline/time-travel.ts +1 -1
  91. package/src/internal/transaction/abort-transaction.ts +1 -1
  92. package/src/internal/transaction/apply-transaction.ts +7 -7
  93. package/src/internal/transaction/build-transaction.ts +10 -9
  94. package/src/internal/transaction/create-transaction.ts +4 -3
  95. package/src/internal/transaction/index.ts +6 -2
  96. package/src/introspection/attach-introspection-states.ts +2 -2
  97. package/src/introspection/attach-transaction-logs.ts +13 -6
  98. package/src/json/index.ts +3 -1
  99. package/src/main/atom.ts +2 -1
  100. package/src/main/events.ts +109 -0
  101. package/src/main/get-state.ts +1 -1
  102. package/src/main/index.ts +3 -0
  103. package/src/main/subscribe.ts +9 -19
  104. package/src/main/timeline.ts +3 -21
  105. package/src/main/transaction.ts +0 -65
  106. package/src/main/validators.ts +8 -2
  107. package/src/react-devtools/TimelineIndex.tsx +1 -1
  108. package/src/react-devtools/TransactionIndex.tsx +5 -3
  109. package/src/react-devtools/Updates.tsx +54 -46
  110. package/src/realtime-client/continuity/register-and-attempt-confirmed-update.ts +20 -10
  111. package/src/realtime-client/realtime-client-stores/client-sync-store.ts +4 -4
  112. package/src/realtime-client/sync-continuity.ts +1 -1
  113. package/src/realtime-server/continuity/prepare-to-serve-transaction-request.ts +14 -8
  114. package/src/realtime-server/continuity/prepare-to-track-client-acknowledgement.ts +5 -2
  115. package/src/realtime-server/continuity/subscribe-to-continuity-actions.ts +1 -1
  116. package/src/realtime-server/realtime-action-receiver.ts +6 -3
  117. package/src/realtime-server/realtime-server-stores/server-sync-store.ts +13 -16
  118. package/src/transceivers/set-rtx/set-rtx.ts +1 -3
  119. package/src/web/persist-sync.ts +2 -2
  120. package/src/internal/set-state/emit-update.ts +0 -40
@@ -19,13 +19,23 @@ export const useRegisterAndAttemptConfirmedUpdate =
19
19
  store: Store,
20
20
  continuityKey: string,
21
21
  socket: Socket,
22
- optimisticUpdates: AtomIO.TransactionUpdate<any>[],
23
- confirmedUpdates: AtomIO.TransactionUpdate<any>[],
22
+ optimisticUpdates: AtomIO.TransactionOutcomeEvent<
23
+ AtomIO.TransactionToken<Fn>
24
+ >[],
25
+ confirmedUpdates: AtomIO.TransactionOutcomeEvent<
26
+ AtomIO.TransactionToken<Fn>
27
+ >[],
24
28
  ) =>
25
- (confirmed: AtomIO.TransactionUpdate<Fn>): void => {
29
+ (
30
+ confirmed: AtomIO.TransactionOutcomeEvent<AtomIO.TransactionToken<Fn>>,
31
+ ): void => {
26
32
  function reconcileEpoch(
27
- optimisticUpdate: AtomIO.TransactionUpdate<any>,
28
- confirmedUpdate: AtomIO.TransactionUpdate<any>,
33
+ optimisticUpdate: AtomIO.TransactionOutcomeEvent<
34
+ AtomIO.TransactionToken<Fn>
35
+ >,
36
+ confirmedUpdate: AtomIO.TransactionOutcomeEvent<
37
+ AtomIO.TransactionToken<Fn>
38
+ >,
29
39
  ): void {
30
40
  store.logger.info(
31
41
  `🧑‍⚖️`,
@@ -38,8 +48,8 @@ export const useRegisterAndAttemptConfirmedUpdate =
38
48
  return queue
39
49
  })
40
50
  if (optimisticUpdate.id === confirmedUpdate.id) {
41
- const clientResult = JSON.stringify(optimisticUpdate.updates)
42
- const serverResult = JSON.stringify(confirmedUpdate.updates)
51
+ const clientResult = JSON.stringify(optimisticUpdate.subEvents)
52
+ const serverResult = JSON.stringify(confirmedUpdate.subEvents)
43
53
  if (clientResult === serverResult) {
44
54
  store.logger.info(
45
55
  `✅`,
@@ -56,7 +66,7 @@ export const useRegisterAndAttemptConfirmedUpdate =
56
66
  `❌`,
57
67
  `continuity`,
58
68
  continuityKey,
59
- `thought update #${confirmedUpdate.epoch} was ${optimisticUpdate.key}:${optimisticUpdate.id}, but it was actually ${confirmedUpdate.key}:${confirmedUpdate.id}`,
69
+ `thought update #${confirmedUpdate.epoch} was ${optimisticUpdate.token.key}:${optimisticUpdate.id}, but it was actually ${confirmedUpdate.token.key}:${confirmedUpdate.id}`,
60
70
  )
61
71
  }
62
72
  store.logger.info(
@@ -99,7 +109,7 @@ export const useRegisterAndAttemptConfirmedUpdate =
99
109
  for (const subsequentOptimistic of optimisticUpdates) {
100
110
  const token = {
101
111
  type: `transaction`,
102
- key: subsequentOptimistic.key,
112
+ key: subsequentOptimistic.token.key,
103
113
  } as const
104
114
  const { id, params } = subsequentOptimistic
105
115
  actUponStore(store, token, id)(...params)
@@ -188,7 +198,7 @@ export const useRegisterAndAttemptConfirmedUpdate =
188
198
  `✅`,
189
199
  `continuity`,
190
200
  continuityKey,
191
- `integrating update #${confirmed.epoch} (${confirmed.key} ${confirmed.id})`,
201
+ `integrating update #${confirmed.epoch} (${confirmed.token.key} ${confirmed.id})`,
192
202
  )
193
203
  ingestTransactionUpdate(`newValue`, confirmed, store)
194
204
  socket.emit(`ack:${continuityKey}`, confirmed.epoch)
@@ -1,15 +1,15 @@
1
1
  import * as AtomIO from "atom.io"
2
2
 
3
3
  export const optimisticUpdateQueue: AtomIO.RegularAtomToken<
4
- AtomIO.TransactionUpdate<any>[]
5
- > = AtomIO.atom<AtomIO.TransactionUpdate<any>[]>({
4
+ AtomIO.TransactionOutcomeEvent<any>[]
5
+ > = AtomIO.atom<AtomIO.TransactionOutcomeEvent<any>[]>({
6
6
  key: `updateQueue`,
7
7
  default: () => [],
8
8
  })
9
9
 
10
10
  export const confirmedUpdateQueue: AtomIO.RegularAtomToken<
11
- AtomIO.TransactionUpdate<any>[]
12
- > = AtomIO.atom<AtomIO.TransactionUpdate<any>[]>({
11
+ AtomIO.TransactionOutcomeEvent<any>[]
12
+ > = AtomIO.atom<AtomIO.TransactionOutcomeEvent<any>[]>({
13
13
  key: `serverConfirmedUpdateQueue`,
14
14
  default: () => [],
15
15
  })
@@ -102,7 +102,7 @@ export function syncContinuity(
102
102
  }
103
103
  socket.emit(`tx-run:${continuityKey}`, {
104
104
  id: clientUpdate.id,
105
- key: transaction.key,
105
+ token: transaction,
106
106
  params: clientUpdate.params,
107
107
  })
108
108
  },
@@ -1,19 +1,25 @@
1
- import type { TransactionUpdate } from "atom.io"
1
+ import type { TransactionOutcomeEvent, TransactionToken } from "atom.io"
2
2
  import type { Store } from "atom.io/internal"
3
3
  import { actUponStore } from "atom.io/internal"
4
- import type { JsonIO } from "atom.io/json"
4
+ import type { Json, JsonIO } from "atom.io/json"
5
5
  import type { ContinuityToken } from "atom.io/realtime"
6
6
 
7
7
  export function prepareToServeTransactionRequest(
8
8
  store: Store,
9
9
  continuity: ContinuityToken,
10
10
  userKey: string,
11
- ): (update: Pick<TransactionUpdate<JsonIO>, `id` | `key` | `params`>) => void {
11
+ ): (
12
+ event: Json.Serializable &
13
+ Pick<
14
+ TransactionOutcomeEvent<TransactionToken<JsonIO>>,
15
+ `id` | `params` | `token`
16
+ >,
17
+ ) => void {
12
18
  const continuityKey = continuity.key
13
- return function serveTransactionRequest(update) {
14
- store.logger.info(`🛎️`, `continuity`, continuityKey, `received`, update)
15
- const transactionKey = update.key
16
- const updateId = update.id
19
+ return function serveTransactionRequest(txOutcome) {
20
+ store.logger.info(`🛎️`, `continuity`, continuityKey, `received`, txOutcome)
21
+ const transactionKey = txOutcome.token.key
22
+ const updateId = txOutcome.id
17
23
  const performanceKey = `tx-run:${transactionKey}:${updateId}`
18
24
  const performanceKeyStart = `${performanceKey}:start`
19
25
  const performanceKeyEnd = `${performanceKey}:end`
@@ -23,7 +29,7 @@ export function prepareToServeTransactionRequest(
23
29
  store,
24
30
  { type: `transaction`, key: transactionKey },
25
31
  updateId,
26
- )(...update.params)
32
+ )(...txOutcome.params)
27
33
  } catch (thrown) {
28
34
  if (thrown instanceof Error) {
29
35
  store.logger.error(
@@ -2,13 +2,16 @@ import type { Store } from "atom.io/internal"
2
2
  import { setIntoStore } from "atom.io/internal"
3
3
  import type { ContinuityToken } from "atom.io/realtime"
4
4
 
5
- import type { ContinuitySyncTransactionUpdate } from "../realtime-server-stores"
5
+ import type {
6
+ ContinuitySyncTransactionUpdate,
7
+ UserKey,
8
+ } from "../realtime-server-stores"
6
9
  import { userUnacknowledgedQueues } from "../realtime-server-stores"
7
10
 
8
11
  export function prepareToTrackClientAcknowledgement(
9
12
  store: Store,
10
13
  continuity: ContinuityToken,
11
- userKey: string,
14
+ userKey: UserKey,
12
15
  userUnacknowledgedUpdates: ContinuitySyncTransactionUpdate[],
13
16
  ): (epoch: number) => void {
14
17
  const continuityKey = continuity.key
@@ -59,7 +59,7 @@ export function subscribeToContinuityActions(
59
59
  )
60
60
  const redactedUpdates = redactTransactionUpdateContent(
61
61
  visibleKeys,
62
- update.updates,
62
+ update.subEvents,
63
63
  )
64
64
  const redactedUpdate = {
65
65
  ...update,
@@ -1,4 +1,4 @@
1
- import type * as AtomIO from "atom.io"
1
+ import type { TransactionOutcomeEvent, TransactionToken } from "atom.io"
2
2
  import { actUponStore, IMPLICIT } from "atom.io/internal"
3
3
  import type { JsonIO } from "atom.io/json"
4
4
 
@@ -10,10 +10,13 @@ export function realtimeActionReceiver({
10
10
  store = IMPLICIT.STORE,
11
11
  }: ServerConfig) {
12
12
  return function actionReceiver<F extends JsonIO>(
13
- tx: AtomIO.TransactionToken<F>,
13
+ tx: TransactionToken<F>,
14
14
  ): () => void {
15
15
  const fillTransactionRequest = (
16
- update: Pick<AtomIO.TransactionUpdate<F>, `id` | `params`>,
16
+ update: Pick<
17
+ TransactionOutcomeEvent<TransactionToken<F>>,
18
+ `id` | `params`
19
+ >,
17
20
  ) => {
18
21
  const performanceKey = `tx-run:${tx.key}:${update.id}`
19
22
  const performanceKeyStart = `${performanceKey}:start`
@@ -1,7 +1,7 @@
1
1
  import type {
2
2
  RegularAtomFamilyToken,
3
- TransactionUpdate,
4
- TransactionUpdateContent,
3
+ TransactionOutcomeEvent,
4
+ TransactionSubEvent,
5
5
  } from "atom.io"
6
6
  import { atomFamily } from "atom.io"
7
7
 
@@ -17,20 +17,19 @@ import type { UserKey } from "./server-user-store"
17
17
 
18
18
  export function redactTransactionUpdateContent(
19
19
  visibleStateKeys: string[],
20
- updates: TransactionUpdateContent[],
21
- ): TransactionUpdateContent[] {
20
+ updates: TransactionSubEvent[],
21
+ ): TransactionSubEvent[] {
22
22
  return updates
23
- .map((update): TransactionUpdateContent => {
23
+ .map((update): TransactionSubEvent => {
24
24
  switch (update.type) {
25
- case `transaction_update`: {
25
+ case `transaction_outcome`: {
26
26
  const redacted = redactTransactionUpdateContent(
27
27
  visibleStateKeys,
28
- update.updates,
28
+ update.subEvents,
29
29
  )
30
- return { ...update, updates: redacted }
30
+ return { ...update, subEvents: redacted }
31
31
  }
32
32
  case `atom_update`:
33
- case `selector_update`:
34
33
  case `molecule_creation`:
35
34
  case `molecule_disposal`:
36
35
  case `molecule_transfer`:
@@ -42,13 +41,11 @@ export function redactTransactionUpdateContent(
42
41
  .filter((update) => {
43
42
  switch (update.type) {
44
43
  case `atom_update`:
45
- case `selector_update`:
46
- return visibleStateKeys.includes(update.key)
47
44
  case `state_creation`:
48
45
  case `state_disposal`:
49
46
  return visibleStateKeys.includes(update.token.key)
50
47
  case `molecule_creation`:
51
- case `transaction_update`:
48
+ case `transaction_outcome`:
52
49
  case `molecule_disposal`:
53
50
  case `molecule_transfer`:
54
51
  return true
@@ -58,12 +55,12 @@ export function redactTransactionUpdateContent(
58
55
 
59
56
  export const redactorAtoms: RegularAtomFamilyToken<
60
57
  {
61
- occlude: (updates: TransactionUpdateContent[]) => TransactionUpdateContent[]
58
+ occlude: (updates: TransactionSubEvent[]) => TransactionSubEvent[]
62
59
  },
63
60
  UserKey
64
61
  > = atomFamily<
65
62
  {
66
- occlude: (updates: TransactionUpdateContent[]) => TransactionUpdateContent[]
63
+ occlude: (updates: TransactionSubEvent[]) => TransactionSubEvent[]
67
64
  },
68
65
  UserKey
69
66
  >({
@@ -89,8 +86,8 @@ export const redactorAtoms: RegularAtomFamilyToken<
89
86
  // })
90
87
 
91
88
  export type ContinuitySyncTransactionUpdate = Pick<
92
- TransactionUpdate<any>,
93
- `epoch` | `id` | `key` | `output` | `updates`
89
+ TransactionOutcomeEvent<any>,
90
+ `epoch` | `id` | `output` | `subEvents` | `token`
94
91
  >
95
92
  export const userUnacknowledgedQueues: RegularAtomFamilyToken<
96
93
  ContinuitySyncTransactionUpdate[],
@@ -51,9 +51,7 @@ export class SetRTX<P extends primitive>
51
51
  }
52
52
  }
53
53
 
54
- public view(): SetRTXView<P> {
55
- return this
56
- }
54
+ public readonly READONLY_VIEW: SetRTXView<P> = this
57
55
 
58
56
  public toJSON(): SetRTXJson<P> {
59
57
  return {
@@ -1,7 +1,7 @@
1
- import type { AtomEffect } from "atom.io"
1
+ import type { AtomEffect, ViewOf } from "atom.io"
2
2
 
3
3
  export type StringInterface<T> = {
4
- stringify: (t: T) => string
4
+ stringify: (t: ViewOf<T>) => string
5
5
  parse: (s: string) => T
6
6
  }
7
7
 
@@ -1,40 +0,0 @@
1
- import type { StateUpdate } from "atom.io"
2
-
3
- import type { Atom, Selector, Store } from ".."
4
-
5
- export const emitUpdate = <T>(
6
- store: Store,
7
- state: Atom<T> | Selector<T>,
8
- update: StateUpdate<T>,
9
- ): void => {
10
- switch (state.type) {
11
- case `mutable_atom`:
12
- store.logger.info(
13
- `📢`,
14
- state.type,
15
- state.key,
16
- `is now (`,
17
- update.newValue,
18
- `) subscribers:`,
19
- state.subject.subscribers,
20
- )
21
- break
22
- case `atom`:
23
- case `writable_pure_selector`:
24
- case `readonly_pure_selector`:
25
- case `writable_held_selector`:
26
- case `readonly_held_selector`:
27
- store.logger.info(
28
- `📢`,
29
- state.type,
30
- state.key,
31
- `went (`,
32
- update.oldValue,
33
- `->`,
34
- update.newValue,
35
- `) subscribers:`,
36
- state.subject.subscribers,
37
- )
38
- }
39
- state.subject.next(update)
40
- }