atom.io 0.36.0 → 0.36.2

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 (105) hide show
  1. package/dist/internal/index.d.ts +93 -73
  2. package/dist/internal/index.d.ts.map +1 -1
  3. package/dist/internal/index.js +233 -248
  4. package/dist/internal/index.js.map +1 -1
  5. package/dist/introspection/index.d.ts +5 -6
  6. package/dist/introspection/index.d.ts.map +1 -1
  7. package/dist/introspection/index.js +2 -3
  8. package/dist/introspection/index.js.map +1 -1
  9. package/dist/main/index.d.ts +29 -37
  10. package/dist/main/index.d.ts.map +1 -1
  11. package/dist/main/index.js +8 -9
  12. package/dist/main/index.js.map +1 -1
  13. package/dist/react/index.d.ts +2 -2
  14. package/dist/react/index.d.ts.map +1 -1
  15. package/dist/react/index.js.map +1 -1
  16. package/dist/react-devtools/index.d.ts.map +1 -1
  17. package/dist/react-devtools/index.js.map +1 -1
  18. package/dist/realtime-client/index.d.ts +7 -8
  19. package/dist/realtime-client/index.d.ts.map +1 -1
  20. package/dist/realtime-client/index.js +3 -4
  21. package/dist/realtime-client/index.js.map +1 -1
  22. package/dist/realtime-react/index.d.ts +4 -4
  23. package/dist/realtime-react/index.d.ts.map +1 -1
  24. package/dist/realtime-react/index.js.map +1 -1
  25. package/dist/realtime-server/index.d.ts +2 -2
  26. package/dist/realtime-server/index.d.ts.map +1 -1
  27. package/dist/realtime-server/index.js.map +1 -1
  28. package/dist/transceivers/set-rtx/index.d.ts +9 -2
  29. package/dist/transceivers/set-rtx/index.d.ts.map +1 -1
  30. package/dist/transceivers/set-rtx/index.js +3 -0
  31. package/dist/transceivers/set-rtx/index.js.map +1 -1
  32. package/package.json +3 -3
  33. package/src/internal/atom/create-regular-atom.ts +5 -5
  34. package/src/internal/atom/has-role.ts +12 -0
  35. package/src/internal/atom/index.ts +1 -0
  36. package/src/internal/caching.ts +60 -41
  37. package/src/internal/families/find-in-store.ts +1 -1
  38. package/src/internal/families/get-family-of-token.ts +1 -1
  39. package/src/internal/families/init-family-member.ts +1 -1
  40. package/src/internal/families/seek-in-store.ts +1 -1
  41. package/src/internal/get-state/read-or-compute-value.ts +26 -21
  42. package/src/internal/index.ts +8 -8
  43. package/src/internal/join/create-join.ts +3 -2
  44. package/src/internal/join/join-internal.ts +7 -4
  45. package/src/internal/mutable/create-mutable-atom-family.ts +6 -5
  46. package/src/internal/mutable/create-mutable-atom.ts +1 -1
  47. package/src/internal/mutable/get-json-family.ts +1 -1
  48. package/src/internal/mutable/get-json-token.ts +1 -1
  49. package/src/internal/mutable/get-update-family.ts +1 -1
  50. package/src/internal/mutable/get-update-token.ts +1 -1
  51. package/src/internal/mutable/tracker-family.ts +27 -31
  52. package/src/internal/mutable/tracker.ts +29 -23
  53. package/src/internal/mutable/transceiver.ts +11 -10
  54. package/src/internal/selector/create-readonly-held-selector.ts +2 -2
  55. package/src/internal/selector/create-readonly-pure-selector.ts +2 -2
  56. package/src/internal/selector/create-writable-held-selector.ts +3 -4
  57. package/src/internal/selector/create-writable-pure-selector.ts +3 -3
  58. package/src/internal/set-state/evict-downstream.ts +17 -15
  59. package/src/internal/set-state/index.ts +1 -0
  60. package/src/internal/set-state/reset-in-store.ts +6 -50
  61. package/src/internal/set-state/set-atom.ts +17 -24
  62. package/src/internal/set-state/set-into-store.ts +29 -13
  63. package/src/internal/store/counterfeit.ts +1 -1
  64. package/src/internal/store/deposit.ts +7 -8
  65. package/src/internal/store/store.ts +6 -6
  66. package/src/internal/store/withdraw.ts +8 -8
  67. package/src/internal/subscribe/subscribe-in-store.ts +8 -8
  68. package/src/internal/subscribe/subscribe-to-timeline.ts +2 -2
  69. package/src/internal/subscribe/subscribe-to-transaction.ts +2 -2
  70. package/src/internal/timeline/create-timeline.ts +3 -3
  71. package/src/internal/transaction/act-upon-store.ts +2 -2
  72. package/src/internal/transaction/apply-transaction.ts +2 -2
  73. package/src/internal/transaction/build-transaction.ts +2 -2
  74. package/src/internal/transaction/create-transaction.ts +3 -3
  75. package/src/internal/transaction/index.ts +2 -2
  76. package/src/internal/transaction/is-root-store.ts +4 -2
  77. package/src/internal/utility-types.ts +1 -1
  78. package/src/introspection/attach-introspection-states.ts +3 -3
  79. package/src/introspection/attach-transaction-index.ts +4 -4
  80. package/src/introspection/attach-transaction-logs.ts +4 -4
  81. package/src/introspection/auditor.ts +3 -3
  82. package/src/main/atom.ts +4 -4
  83. package/src/main/dispose-state.ts +4 -3
  84. package/src/main/find-state.ts +1 -1
  85. package/src/main/get-state.ts +6 -5
  86. package/src/main/reset-state.ts +3 -3
  87. package/src/main/set-state.ts +3 -3
  88. package/src/main/subscribe.ts +3 -3
  89. package/src/main/tokens.ts +9 -18
  90. package/src/main/transaction.ts +13 -15
  91. package/src/react/use-json.ts +5 -5
  92. package/src/react-devtools/TransactionIndex.tsx +3 -3
  93. package/src/react-devtools/Updates.tsx +2 -2
  94. package/src/realtime-client/continuity/register-and-attempt-confirmed-update.ts +2 -2
  95. package/src/realtime-client/pull-mutable-atom-family-member.ts +8 -13
  96. package/src/realtime-client/pull-mutable-atom.ts +5 -8
  97. package/src/realtime-client/push-state.ts +6 -5
  98. package/src/realtime-client/server-action.ts +5 -4
  99. package/src/realtime-react/use-pull-mutable-atom.ts +1 -1
  100. package/src/realtime-react/use-pull-mutable-family-member.ts +1 -1
  101. package/src/realtime-react/use-server-action.ts +2 -2
  102. package/src/realtime-server/realtime-mutable-family-provider.ts +1 -1
  103. package/src/realtime-server/realtime-mutable-provider.ts +1 -1
  104. package/src/transceivers/set-rtx/set-rtx.ts +14 -1
  105. package/src/internal/set-state/copy-mutable-if-needed.ts +0 -29
@@ -3,7 +3,7 @@ import type {
3
3
  TimelineUpdate,
4
4
  TransactionUpdate,
5
5
  } from "atom.io"
6
- import type { Func } from "atom.io/internal"
6
+ import type { Fn } from "atom.io/internal"
7
7
  import { discoverType, prettyJson } from "atom.io/introspection"
8
8
  import { stringifyJson } from "atom.io/json"
9
9
  import * as React from "react"
@@ -37,7 +37,7 @@ const AtomUpdateFC: React.FC<{
37
37
 
38
38
  const TransactionUpdateFC: React.FC<{
39
39
  serialNumber: number
40
- transactionUpdate: TransactionUpdate<Func>
40
+ transactionUpdate: TransactionUpdate<Fn>
41
41
  }> = ({ serialNumber, transactionUpdate }) => {
42
42
  return (
43
43
  <article
@@ -1,5 +1,5 @@
1
1
  import type * as AtomIO from "atom.io"
2
- import type { Func, Store } from "atom.io/internal"
2
+ import type { Fn, Store } from "atom.io/internal"
3
3
  import {
4
4
  actUponStore,
5
5
  getEpochNumberOfContinuity,
@@ -22,7 +22,7 @@ export const useRegisterAndAttemptConfirmedUpdate =
22
22
  optimisticUpdates: AtomIO.TransactionUpdate<any>[],
23
23
  confirmedUpdates: AtomIO.TransactionUpdate<any>[],
24
24
  ) =>
25
- (confirmed: AtomIO.TransactionUpdate<Func>): void => {
25
+ (confirmed: AtomIO.TransactionUpdate<Fn>): void => {
26
26
  function reconcileEpoch(
27
27
  optimisticUpdate: AtomIO.TransactionUpdate<any>,
28
28
  confirmedUpdate: AtomIO.TransactionUpdate<any>,
@@ -1,16 +1,14 @@
1
1
  import type * as AtomIO from "atom.io"
2
- import type { AsJSON, Store, Transceiver } from "atom.io/internal"
2
+ import type { AsJSON, SignalFrom, Store, Transceiver } from "atom.io/internal"
3
3
  import { getJsonToken, getUpdateToken, setIntoStore } from "atom.io/internal"
4
4
  import { parseJson } from "atom.io/json"
5
5
  import type { Socket } from "socket.io-client"
6
6
 
7
7
  /* eslint-disable no-console */
8
8
 
9
- export function pullMutableAtomFamilyMember<T extends Transceiver<any, any>>(
10
- store: Store,
11
- socket: Socket,
12
- token: AtomIO.MutableAtomToken<T>,
13
- ): () => void {
9
+ export function pullMutableAtomFamilyMember<
10
+ T extends Transceiver<any, any, any>,
11
+ >(store: Store, socket: Socket, token: AtomIO.MutableAtomToken<T>): () => void {
14
12
  if (!(`family` in token)) {
15
13
  console.error(`Token is not a family member:`, token)
16
14
  return () => {}
@@ -21,13 +19,10 @@ export function pullMutableAtomFamilyMember<T extends Transceiver<any, any>>(
21
19
  const jsonToken = getJsonToken(store, token)
22
20
  setIntoStore(store, jsonToken, data)
23
21
  })
24
- socket.on(
25
- `next:${token.key}`,
26
- (data: T extends Transceiver<infer Signal, any> ? Signal : never) => {
27
- const trackerToken = getUpdateToken(token)
28
- setIntoStore(store, trackerToken, data)
29
- },
30
- )
22
+ socket.on(`next:${token.key}`, (data: SignalFrom<T>) => {
23
+ const trackerToken = getUpdateToken(token)
24
+ setIntoStore(store, trackerToken, data)
25
+ })
31
26
  socket.emit(`sub:${familyKey}`, subKey)
32
27
  return () => {
33
28
  socket.off(`serve:${token.key}`)
@@ -1,9 +1,9 @@
1
1
  import type * as AtomIO from "atom.io"
2
- import type { AsJSON, Store, Transceiver } from "atom.io/internal"
2
+ import type { AsJSON, SignalFrom, Store, Transceiver } from "atom.io/internal"
3
3
  import { getJsonToken, getUpdateToken, setIntoStore } from "atom.io/internal"
4
4
  import type { Socket } from "socket.io-client"
5
5
 
6
- export function pullMutableAtom<T extends Transceiver<any, any>>(
6
+ export function pullMutableAtom<T extends Transceiver<any, any, any>>(
7
7
  store: Store,
8
8
  socket: Socket,
9
9
  token: AtomIO.MutableAtomToken<T>,
@@ -13,12 +13,9 @@ export function pullMutableAtom<T extends Transceiver<any, any>>(
13
13
  socket.on(`init:${token.key}`, (data: AsJSON<T>) => {
14
14
  setIntoStore(store, jsonToken, data)
15
15
  })
16
- socket.on(
17
- `next:${token.key}`,
18
- (data: T extends Transceiver<infer Update, any> ? Update : never) => {
19
- setIntoStore(store, updateToken, data)
20
- },
21
- )
16
+ socket.on(`next:${token.key}`, (data: SignalFrom<T>) => {
17
+ setIntoStore(store, updateToken, data)
18
+ })
22
19
  socket.emit(`sub:${token.key}`)
23
20
  return () => {
24
21
  socket.off(`init:${token.key}`)
@@ -1,15 +1,16 @@
1
- import type * as AtomIO from "atom.io"
2
- import * as Internal from "atom.io/internal"
1
+ import type { WritableToken } from "atom.io"
2
+ import type { Store } from "atom.io/internal"
3
+ import { subscribeToState } from "atom.io/internal"
3
4
  import type { Json } from "atom.io/json"
4
5
  import type { Socket } from "socket.io-client"
5
6
 
6
7
  export function pushState<J extends Json.Serializable>(
7
- store: Internal.Store,
8
+ store: Store,
8
9
  socket: Socket,
9
- token: AtomIO.WritableToken<J>,
10
+ token: WritableToken<J>,
10
11
  ): () => void {
11
12
  socket.emit(`claim:${token.key}`)
12
- Internal.subscribeToState(store, token, `push`, ({ newValue }) => {
13
+ subscribeToState(store, token, `push`, ({ newValue }) => {
13
14
  socket.emit(`pub:${token.key}`, newValue)
14
15
  })
15
16
  return () => {
@@ -1,13 +1,14 @@
1
1
  import type * as AtomIO from "atom.io"
2
- import * as Internal from "atom.io/internal"
2
+ import type { Fn, Store } from "atom.io/internal"
3
+ import { subscribeToTransaction } from "atom.io/internal"
3
4
  import type { Socket } from "socket.io-client"
4
5
 
5
- export function serverAction<F extends Internal.Func>(
6
- store: Internal.Store,
6
+ export function serverAction<F extends Fn>(
7
+ store: Store,
7
8
  socket: Socket,
8
9
  token: AtomIO.TransactionToken<F>,
9
10
  ): () => void {
10
- const unsubscribeFromLocalUpdates = Internal.subscribeToTransaction(
11
+ const unsubscribeFromLocalUpdates = subscribeToTransaction(
11
12
  store,
12
13
  token,
13
14
  `tx-run:${token.key}:${socket.id}`,
@@ -6,7 +6,7 @@ import * as React from "react"
6
6
 
7
7
  import { useRealtimeService } from "./use-realtime-service"
8
8
 
9
- export function usePullMutable<T extends Transceiver<any, any>>(
9
+ export function usePullMutable<T extends Transceiver<any, any, any>>(
10
10
  token: AtomIO.MutableAtomToken<T>,
11
11
  ): T {
12
12
  const store = React.useContext(StoreContext)
@@ -9,7 +9,7 @@ import * as React from "react"
9
9
  import { useRealtimeService } from "./use-realtime-service"
10
10
 
11
11
  export function usePullMutableAtomFamilyMember<
12
- T extends Transceiver<any, any>,
12
+ T extends Transceiver<any, any, any>,
13
13
  K extends Canonical,
14
14
  Key extends K,
15
15
  >(familyToken: AtomIO.MutableAtomFamilyToken<T, K>, key: Key): T {
@@ -1,5 +1,5 @@
1
1
  import type * as AtomIO from "atom.io"
2
- import type { Func } from "atom.io/internal"
2
+ import type { Fn } from "atom.io/internal"
3
3
  import { actUponStore, arbitrary } from "atom.io/internal"
4
4
  import { StoreContext } from "atom.io/react"
5
5
  import * as RTC from "atom.io/realtime-client"
@@ -7,7 +7,7 @@ import * as React from "react"
7
7
 
8
8
  import { useRealtimeService } from "./use-realtime-service"
9
9
 
10
- export function useServerAction<F extends Func>(
10
+ export function useServerAction<F extends Fn>(
11
11
  token: AtomIO.TransactionToken<F>,
12
12
  ): (...parameters: Parameters<F>) => ReturnType<F> {
13
13
  const store = React.useContext(StoreContext)
@@ -21,7 +21,7 @@ export function realtimeMutableFamilyProvider({
21
21
  store = IMPLICIT.STORE,
22
22
  }: ServerConfig) {
23
23
  return function mutableFamilyProvider<
24
- T extends Transceiver<any, any>,
24
+ T extends Transceiver<any, any, any>,
25
25
  K extends Canonical,
26
26
  >(
27
27
  family: AtomIO.MutableAtomFamilyToken<T, K>,
@@ -17,7 +17,7 @@ export function realtimeMutableProvider({
17
17
  store = IMPLICIT.STORE,
18
18
  }: ServerConfig) {
19
19
  return function mutableProvider<
20
- Core extends Transceiver<Json.Serializable, Json.Serializable>,
20
+ Core extends Transceiver<any, Json.Serializable, Json.Serializable>,
21
21
  >(token: AtomIO.MutableAtomToken<Core>): () => void {
22
22
  let unsubscribeFromStateUpdates: (() => void) | null = null
23
23
 
@@ -7,6 +7,13 @@ export type SetUpdateType = `add` | `clear` | `del` | `tx`
7
7
  export type SetUpdate = `${SetUpdateType}:${string}`
8
8
  export type NumberedSetUpdate = `${number}=${SetUpdate}`
9
9
 
10
+ export interface SetRTXView<P extends primitive> extends ReadonlySet<P> {
11
+ readonly cache: ReadonlyArray<NumberedSetUpdate | null>
12
+ readonly cacheLimit: number
13
+ readonly cacheIdx: number
14
+ readonly cacheUpdateNumber: number
15
+ }
16
+
10
17
  export interface SetRTXJson<P extends primitive> extends Json.Object {
11
18
  members: P[]
12
19
  cache: (NumberedSetUpdate | null)[]
@@ -16,7 +23,9 @@ export interface SetRTXJson<P extends primitive> extends Json.Object {
16
23
  }
17
24
  export class SetRTX<P extends primitive>
18
25
  extends Set<P>
19
- implements Transceiver<NumberedSetUpdate, SetRTXJson<P>>, Lineage
26
+ implements
27
+ Transceiver<SetRTXView<P>, NumberedSetUpdate, SetRTXJson<P>>,
28
+ Lineage
20
29
  {
21
30
  public mode: TransceiverMode = `record`
22
31
  public readonly subject: Subject<SetUpdate> = new Subject<SetUpdate>()
@@ -42,6 +51,10 @@ export class SetRTX<P extends primitive>
42
51
  }
43
52
  }
44
53
 
54
+ public view(): SetRTXView<P> {
55
+ return this
56
+ }
57
+
45
58
  public toJSON(): SetRTXJson<P> {
46
59
  return {
47
60
  members: [...this],
@@ -1,29 +0,0 @@
1
- import type { MutableAtom, Transceiver } from ".."
2
- import { Tracker } from "../mutable"
3
- import type { Store } from "../store"
4
-
5
- export function copyMutableIfNeeded<T extends Transceiver<any, any>>(
6
- target: Store,
7
- atom: MutableAtom<T>,
8
- origin: Store,
9
- ): T {
10
- const originValue = origin.valueMap.get(atom.key) as
11
- | Transceiver<any, any>
12
- | undefined
13
- const targetValue = target.valueMap.get(atom.key)
14
-
15
- if (originValue !== targetValue) {
16
- return targetValue
17
- }
18
-
19
- if (originValue === undefined) {
20
- return new atom.class()
21
- }
22
-
23
- origin.logger.info(`📃`, `atom`, atom.key, `copying`)
24
- const jsonValue = originValue.toJSON()
25
- const copiedValue = atom.class.fromJSON(jsonValue)
26
- target.valueMap.set(atom.key, copiedValue)
27
- new Tracker(atom, origin)
28
- return copiedValue
29
- }