atom.io 0.35.0 → 0.36.1

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 (133) hide show
  1. package/dist/eslint-plugin/index.d.ts +2 -18
  2. package/dist/eslint-plugin/index.d.ts.map +1 -1
  3. package/dist/eslint-plugin/index.js +4 -141
  4. package/dist/eslint-plugin/index.js.map +1 -1
  5. package/dist/internal/index.d.ts +100 -78
  6. package/dist/internal/index.d.ts.map +1 -1
  7. package/dist/internal/index.js +180 -163
  8. package/dist/internal/index.js.map +1 -1
  9. package/dist/introspection/index.d.ts +5 -6
  10. package/dist/introspection/index.d.ts.map +1 -1
  11. package/dist/introspection/index.js +2 -3
  12. package/dist/introspection/index.js.map +1 -1
  13. package/dist/json/index.d.ts +2 -10
  14. package/dist/json/index.d.ts.map +1 -1
  15. package/dist/json/index.js +1 -31
  16. package/dist/json/index.js.map +1 -1
  17. package/dist/main/index.d.ts +38 -39
  18. package/dist/main/index.d.ts.map +1 -1
  19. package/dist/main/index.js +15 -16
  20. package/dist/main/index.js.map +1 -1
  21. package/dist/react/index.d.ts +4 -4
  22. package/dist/react/index.d.ts.map +1 -1
  23. package/dist/react/index.js.map +1 -1
  24. package/dist/react-devtools/index.js.map +1 -1
  25. package/dist/realtime/index.d.ts +4 -4
  26. package/dist/realtime/index.d.ts.map +1 -1
  27. package/dist/realtime/index.js +2 -6
  28. package/dist/realtime/index.js.map +1 -1
  29. package/dist/realtime-client/index.d.ts +7 -8
  30. package/dist/realtime-client/index.d.ts.map +1 -1
  31. package/dist/realtime-client/index.js +3 -4
  32. package/dist/realtime-client/index.js.map +1 -1
  33. package/dist/realtime-react/index.d.ts +4 -4
  34. package/dist/realtime-react/index.d.ts.map +1 -1
  35. package/dist/realtime-react/index.js.map +1 -1
  36. package/dist/realtime-server/index.d.ts +18 -18
  37. package/dist/realtime-server/index.d.ts.map +1 -1
  38. package/dist/realtime-server/index.js +5 -9
  39. package/dist/realtime-server/index.js.map +1 -1
  40. package/dist/transceivers/set-rtx/index.d.ts +9 -2
  41. package/dist/transceivers/set-rtx/index.d.ts.map +1 -1
  42. package/dist/transceivers/set-rtx/index.js +3 -0
  43. package/dist/transceivers/set-rtx/index.js.map +1 -1
  44. package/package.json +6 -6
  45. package/src/eslint-plugin/index.ts +0 -1
  46. package/src/eslint-plugin/rules/explicit-state-types.ts +8 -1
  47. package/src/eslint-plugin/rules/index.ts +0 -1
  48. package/src/internal/atom/create-regular-atom.ts +5 -5
  49. package/src/internal/atom/dispose-atom.ts +1 -0
  50. package/src/internal/atom/has-role.ts +12 -0
  51. package/src/internal/atom/index.ts +1 -0
  52. package/src/internal/caching.ts +38 -16
  53. package/src/internal/families/find-in-store.ts +4 -5
  54. package/src/internal/families/get-family-of-token.ts +4 -5
  55. package/src/internal/families/init-family-member.ts +3 -4
  56. package/src/internal/families/seek-in-store.ts +4 -5
  57. package/src/internal/get-state/read-or-compute-value.ts +37 -16
  58. package/src/internal/index.ts +19 -21
  59. package/src/internal/ingest-updates/ingest-creation-disposal.ts +18 -15
  60. package/src/internal/ingest-updates/ingest-selector-update.ts +9 -5
  61. package/src/internal/join/get-internal-relations-from-store.ts +2 -2
  62. package/src/internal/join/join-internal.ts +10 -18
  63. package/src/internal/molecule.ts +1 -0
  64. package/src/internal/mutable/create-mutable-atom-family.ts +40 -22
  65. package/src/internal/mutable/create-mutable-atom.ts +16 -12
  66. package/src/internal/mutable/get-json-family.ts +7 -6
  67. package/src/internal/mutable/get-json-token.ts +6 -13
  68. package/src/internal/mutable/get-update-family.ts +7 -8
  69. package/src/internal/mutable/get-update-token.ts +5 -9
  70. package/src/internal/mutable/tracker-family.ts +31 -38
  71. package/src/internal/mutable/tracker.ts +86 -104
  72. package/src/internal/mutable/transceiver.ts +37 -9
  73. package/src/internal/selector/create-readonly-held-selector.ts +2 -2
  74. package/src/internal/selector/create-readonly-pure-selector.ts +2 -2
  75. package/src/internal/selector/create-writable-held-selector.ts +3 -3
  76. package/src/internal/selector/create-writable-pure-selector.ts +3 -3
  77. package/src/internal/selector/dispose-selector.ts +9 -9
  78. package/src/internal/set-state/reset-atom-or-selector.ts +11 -4
  79. package/src/internal/set-state/set-atom.ts +15 -22
  80. package/src/internal/set-state/set-into-store.ts +5 -4
  81. package/src/internal/store/counterfeit.ts +3 -4
  82. package/src/internal/store/deposit.ts +8 -11
  83. package/src/internal/store/store.ts +7 -7
  84. package/src/internal/store/withdraw.ts +8 -12
  85. package/src/internal/subscribe/subscribe-in-store.ts +2 -2
  86. package/src/internal/subscribe/subscribe-to-transaction.ts +2 -2
  87. package/src/internal/timeline/create-timeline.ts +3 -3
  88. package/src/internal/transaction/act-upon-store.ts +2 -2
  89. package/src/internal/transaction/apply-transaction.ts +2 -2
  90. package/src/internal/transaction/build-transaction.ts +2 -2
  91. package/src/internal/transaction/create-transaction.ts +3 -3
  92. package/src/internal/transaction/index.ts +2 -2
  93. package/src/internal/transaction/is-root-store.ts +4 -2
  94. package/src/internal/utility-types.ts +1 -1
  95. package/src/introspection/attach-introspection-states.ts +3 -3
  96. package/src/introspection/attach-transaction-index.ts +4 -4
  97. package/src/introspection/attach-transaction-logs.ts +4 -4
  98. package/src/introspection/auditor.ts +3 -3
  99. package/src/json/index.ts +0 -2
  100. package/src/main/atom.ts +24 -36
  101. package/src/main/dispose-state.ts +6 -5
  102. package/src/main/find-state.ts +3 -4
  103. package/src/main/get-state.ts +6 -5
  104. package/src/main/join.ts +2 -2
  105. package/src/main/logger.ts +7 -7
  106. package/src/main/reset-state.ts +3 -3
  107. package/src/main/set-state.ts +3 -3
  108. package/src/main/subscribe.ts +3 -3
  109. package/src/main/tokens.ts +8 -14
  110. package/src/main/transaction.ts +17 -13
  111. package/src/main/validators.ts +1 -1
  112. package/src/react/use-json.ts +14 -24
  113. package/src/react-devtools/TransactionIndex.tsx +3 -3
  114. package/src/react-devtools/Updates.tsx +2 -2
  115. package/src/realtime/shared-room-store.ts +11 -22
  116. package/src/realtime-client/continuity/register-and-attempt-confirmed-update.ts +2 -2
  117. package/src/realtime-client/pull-mutable-atom-family-member.ts +8 -17
  118. package/src/realtime-client/pull-mutable-atom.ts +7 -14
  119. package/src/realtime-client/push-state.ts +6 -5
  120. package/src/realtime-client/server-action.ts +5 -4
  121. package/src/realtime-react/use-pull-mutable-atom.ts +3 -5
  122. package/src/realtime-react/use-pull-mutable-family-member.ts +3 -4
  123. package/src/realtime-react/use-server-action.ts +2 -2
  124. package/src/realtime-server/realtime-mutable-family-provider.ts +3 -4
  125. package/src/realtime-server/realtime-mutable-provider.ts +2 -3
  126. package/src/realtime-server/realtime-server-stores/server-room-external-actions.ts +6 -5
  127. package/src/realtime-server/realtime-server-stores/server-user-store.ts +8 -15
  128. package/src/transceivers/set-rtx/set-rtx.ts +14 -1
  129. package/src/eslint-plugin/rules/synchronous-selector-dependencies.ts +0 -140
  130. package/src/eslint-plugin/walk.ts +0 -81
  131. package/src/internal/set-state/copy-mutable-if-needed.ts +0 -27
  132. package/src/json/select-json-family.ts +0 -55
  133. package/src/json/select-json.ts +0 -19
@@ -56,7 +56,7 @@ export function belongsTo<Family extends RegularAtomFamilyToken<any, any>>(
56
56
  family: Family,
57
57
  unknownToken: ReadableToken<any>,
58
58
  ): unknownToken is RegularAtomToken<TokenType<Family>>
59
- export function belongsTo<Family extends MutableAtomFamilyToken<any, any, any>>(
59
+ export function belongsTo<Family extends MutableAtomFamilyToken<any, any>>(
60
60
  family: Family,
61
61
  unknownToken: ReadableToken<any>,
62
62
  ): unknownToken is MutableAtomToken<TokenType<Family>, any>
@@ -1,8 +1,5 @@
1
- import type {
2
- MutableAtomFamilyToken,
3
- MutableAtomToken,
4
- ReadableToken,
5
- } from "atom.io"
1
+ import type { MutableAtomFamilyToken, MutableAtomToken } from "atom.io"
2
+ import type { AsJSON, Transceiver } from "atom.io/internal"
6
3
  import { findInStore, getJsonToken } from "atom.io/internal"
7
4
  import type { Canonical, Json } from "atom.io/json"
8
5
  import * as React from "react"
@@ -10,29 +7,22 @@ import * as React from "react"
10
7
  import { StoreContext } from "./store-context"
11
8
  import { useO } from "./use-o"
12
9
 
13
- export function useJSON<Serializable extends Json.Serializable>(
14
- token: MutableAtomToken<any, Serializable>,
15
- ): Serializable
10
+ export function useJSON<T extends Transceiver<any, any, any>>(
11
+ token: MutableAtomToken<T>,
12
+ ): AsJSON<T>
16
13
 
17
14
  export function useJSON<
18
- Serializable extends Json.Serializable,
19
- Key extends Canonical,
20
- >(token: MutableAtomFamilyToken<any, Serializable, Key>, key: Key): Serializable
15
+ T extends Transceiver<any, any, any>,
16
+ K extends Canonical,
17
+ >(token: MutableAtomFamilyToken<T, K>, key: K): AsJSON<T>
21
18
 
22
- export function useJSON<
23
- Serializable extends Json.Serializable,
24
- Key extends Canonical,
25
- >(
26
- token:
27
- | MutableAtomFamilyToken<any, Serializable, Key>
28
- | MutableAtomToken<any, Serializable>,
29
- key?: Key,
30
- ): Serializable {
19
+ export function useJSON(
20
+ token: MutableAtomFamilyToken<any, any> | MutableAtomToken<any>,
21
+ key?: Canonical,
22
+ ): Json.Serializable {
31
23
  const store = React.useContext(StoreContext)
32
- const stateToken: ReadableToken<any> =
33
- token.type === `mutable_atom_family`
34
- ? findInStore(store, token, key as Key)
35
- : token
24
+ const stateToken: MutableAtomToken<any> =
25
+ token.type === `mutable_atom_family` ? findInStore(store, token, key) : token
36
26
  const jsonToken = getJsonToken(store, stateToken)
37
27
  return useO(jsonToken)
38
28
  }
@@ -4,7 +4,7 @@ import type {
4
4
  TransactionToken,
5
5
  TransactionUpdate,
6
6
  } from "atom.io"
7
- import { findInStore, type Func } from "atom.io/internal"
7
+ import { findInStore, type Fn } from "atom.io/internal"
8
8
  import { useI, useO } from "atom.io/react"
9
9
  import { type FC, useContext } from "react"
10
10
 
@@ -13,9 +13,9 @@ import { DevtoolsContext } from "./store"
13
13
  import { article } from "./Updates"
14
14
 
15
15
  export const TransactionLog: FC<{
16
- token: TransactionToken<Func>
16
+ token: TransactionToken<Fn>
17
17
  isOpenState: RegularAtomToken<boolean>
18
- logState: ReadonlyPureSelectorToken<TransactionUpdate<Func>[]>
18
+ logState: ReadonlyPureSelectorToken<TransactionUpdate<Fn>[]>
19
19
  }> = ({ token, isOpenState, logState }) => {
20
20
  const log = useO(logState)
21
21
  const isOpen = useO(isOpenState)
@@ -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
@@ -4,27 +4,19 @@ import type {
4
4
  ReadonlyPureSelectorFamilyToken,
5
5
  } from "atom.io"
6
6
  import { getInternalRelations, join, mutableAtom, selectorFamily } from "atom.io"
7
- import type { SetRTXJson } from "atom.io/transceivers/set-rtx"
8
7
  import { SetRTX } from "atom.io/transceivers/set-rtx"
9
8
 
10
- export const usersInThisRoomIndex: MutableAtomToken<
11
- SetRTX<string>,
12
- SetRTXJson<string>
13
- > = mutableAtom<SetRTX<string>, SetRTXJson<string>>({
14
- key: `usersInRoomIndex`,
15
- default: () => new SetRTX<string>(),
16
- toJson: (set) => set.toJSON(),
17
- fromJson: (json) => SetRTX.fromJSON(json),
18
- })
9
+ export const usersInThisRoomIndex: MutableAtomToken<SetRTX<string>> =
10
+ mutableAtom<SetRTX<string>>({
11
+ key: `usersInRoomIndex`,
12
+ class: SetRTX,
13
+ })
19
14
 
20
- export const roomIndex: MutableAtomToken<
21
- SetRTX<string>,
22
- SetRTXJson<string>
23
- > = mutableAtom<SetRTX<string>, SetRTXJson<string>>({
15
+ export const roomIndex: MutableAtomToken<SetRTX<string>> = mutableAtom<
16
+ SetRTX<string>
17
+ >({
24
18
  key: `roomIndex`,
25
- default: () => new SetRTX<string>(),
26
- toJson: (set) => set.toJSON(),
27
- fromJson: (json) => SetRTX.fromJSON(json),
19
+ class: SetRTX,
28
20
  })
29
21
 
30
22
  export type UserInRoomMeta = {
@@ -52,12 +44,9 @@ export const usersInRooms: JoinToken<
52
44
  )
53
45
 
54
46
  export const usersInMyRoomView: ReadonlyPureSelectorFamilyToken<
55
- MutableAtomToken<SetRTX<string>, SetRTXJson<string>>[],
47
+ MutableAtomToken<SetRTX<string>>[],
56
48
  string
57
- > = selectorFamily<
58
- MutableAtomToken<SetRTX<string>, SetRTXJson<string>>[],
59
- string
60
- >({
49
+ > = selectorFamily<MutableAtomToken<SetRTX<string>>[], string>({
61
50
  key: `usersInMyRoomView`,
62
51
  get:
63
52
  (myUsername) =>
@@ -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,37 +1,28 @@
1
1
  import type * as AtomIO from "atom.io"
2
- import type { 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
- import type { Json } from "atom.io/json"
5
4
  import { parseJson } from "atom.io/json"
6
5
  import type { Socket } from "socket.io-client"
7
6
 
8
7
  /* eslint-disable no-console */
9
8
 
10
9
  export function pullMutableAtomFamilyMember<
11
- T extends Transceiver<any>,
12
- J extends Json.Serializable,
13
- >(
14
- store: Store,
15
- socket: Socket,
16
- token: AtomIO.MutableAtomToken<T, J>,
17
- ): () => void {
10
+ T extends Transceiver<any, any, any>,
11
+ >(store: Store, socket: Socket, token: AtomIO.MutableAtomToken<T>): () => void {
18
12
  if (!(`family` in token)) {
19
13
  console.error(`Token is not a family member:`, token)
20
14
  return () => {}
21
15
  }
22
16
  const { key: familyKey, subKey: serializedSubKey } = token.family
23
17
  const subKey = parseJson(serializedSubKey)
24
- socket.on(`init:${token.key}`, (data: J) => {
18
+ socket.on(`init:${token.key}`, (data: AsJSON<T>) => {
25
19
  const jsonToken = getJsonToken(store, token)
26
20
  setIntoStore(store, jsonToken, data)
27
21
  })
28
- socket.on(
29
- `next:${token.key}`,
30
- (data: T extends Transceiver<infer Signal> ? Signal : never) => {
31
- const trackerToken = getUpdateToken(token)
32
- setIntoStore(store, trackerToken, data)
33
- },
34
- )
22
+ socket.on(`next:${token.key}`, (data: SignalFrom<T>) => {
23
+ const trackerToken = getUpdateToken(token)
24
+ setIntoStore(store, trackerToken, data)
25
+ })
35
26
  socket.emit(`sub:${familyKey}`, subKey)
36
27
  return () => {
37
28
  socket.off(`serve:${token.key}`)
@@ -1,28 +1,21 @@
1
1
  import type * as AtomIO from "atom.io"
2
- import type { 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
- import type { Json } from "atom.io/json"
5
4
  import type { Socket } from "socket.io-client"
6
5
 
7
- export function pullMutableAtom<
8
- T extends Transceiver<any>,
9
- J extends Json.Serializable,
10
- >(
6
+ export function pullMutableAtom<T extends Transceiver<any, any, any>>(
11
7
  store: Store,
12
8
  socket: Socket,
13
- token: AtomIO.MutableAtomToken<T, J>,
9
+ token: AtomIO.MutableAtomToken<T>,
14
10
  ): () => void {
15
11
  const jsonToken = getJsonToken(store, token)
16
12
  const updateToken = getUpdateToken(token)
17
- socket.on(`init:${token.key}`, (data: J) => {
13
+ socket.on(`init:${token.key}`, (data: AsJSON<T>) => {
18
14
  setIntoStore(store, jsonToken, data)
19
15
  })
20
- socket.on(
21
- `next:${token.key}`,
22
- (data: T extends Transceiver<infer Update> ? Update : never) => {
23
- setIntoStore(store, updateToken, data)
24
- },
25
- )
16
+ socket.on(`next:${token.key}`, (data: SignalFrom<T>) => {
17
+ setIntoStore(store, updateToken, data)
18
+ })
26
19
  socket.emit(`sub:${token.key}`)
27
20
  return () => {
28
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}`,
@@ -1,16 +1,14 @@
1
1
  import type * as AtomIO from "atom.io"
2
2
  import type { Transceiver } from "atom.io/internal"
3
- import type { Json } from "atom.io/json"
4
3
  import { StoreContext, useO } from "atom.io/react"
5
4
  import * as RTC from "atom.io/realtime-client"
6
5
  import * as React from "react"
7
6
 
8
7
  import { useRealtimeService } from "./use-realtime-service"
9
8
 
10
- export function usePullMutable<
11
- T extends Transceiver<any>,
12
- J extends Json.Serializable,
13
- >(token: AtomIO.MutableAtomToken<T, J>): T {
9
+ export function usePullMutable<T extends Transceiver<any, any, any>>(
10
+ token: AtomIO.MutableAtomToken<T>,
11
+ ): T {
14
12
  const store = React.useContext(StoreContext)
15
13
  useRealtimeService(`pull:${token.key}`, (socket) =>
16
14
  RTC.pullMutableAtom(store, socket, token),
@@ -1,7 +1,7 @@
1
1
  import type * as AtomIO from "atom.io"
2
2
  import type { Transceiver } from "atom.io/internal"
3
3
  import { findInStore } from "atom.io/internal"
4
- import type { Canonical, Json } from "atom.io/json"
4
+ import type { Canonical } from "atom.io/json"
5
5
  import { StoreContext, useO } from "atom.io/react"
6
6
  import * as RTC from "atom.io/realtime-client"
7
7
  import * as React from "react"
@@ -9,11 +9,10 @@ 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>,
13
- J extends Json.Serializable,
12
+ T extends Transceiver<any, any, any>,
14
13
  K extends Canonical,
15
14
  Key extends K,
16
- >(familyToken: AtomIO.MutableAtomFamilyToken<T, J, K>, key: Key): T {
15
+ >(familyToken: AtomIO.MutableAtomFamilyToken<T, K>, key: Key): T {
17
16
  const store = React.useContext(StoreContext)
18
17
  const token = findInStore(store, familyToken, key)
19
18
  useRealtimeService(`pull:${token.key}`, (socket) =>
@@ -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)
@@ -8,7 +8,7 @@ import {
8
8
  IMPLICIT,
9
9
  subscribeToState,
10
10
  } from "atom.io/internal"
11
- import type { Canonical, Json } from "atom.io/json"
11
+ import type { Canonical } from "atom.io/json"
12
12
  import { stringifyJson } from "atom.io/json"
13
13
 
14
14
  import type { ServerConfig } from "."
@@ -21,11 +21,10 @@ export function realtimeMutableFamilyProvider({
21
21
  store = IMPLICIT.STORE,
22
22
  }: ServerConfig) {
23
23
  return function mutableFamilyProvider<
24
- T extends Transceiver<any>,
25
- J extends Json.Serializable,
24
+ T extends Transceiver<any, any, any>,
26
25
  K extends Canonical,
27
26
  >(
28
- family: AtomIO.MutableAtomFamilyToken<T, J, K>,
27
+ family: AtomIO.MutableAtomFamilyToken<T, K>,
29
28
  index: AtomIO.ReadableToken<Iterable<K>>,
30
29
  ): () => void {
31
30
  const unsubCallbacksByKey = new Map<string, () => void>()
@@ -17,9 +17,8 @@ export function realtimeMutableProvider({
17
17
  store = IMPLICIT.STORE,
18
18
  }: ServerConfig) {
19
19
  return function mutableProvider<
20
- Core extends Transceiver<Json.Serializable>,
21
- SerializableCore extends Json.Serializable,
22
- >(token: AtomIO.MutableAtomToken<Core, SerializableCore>): () => void {
20
+ Core extends Transceiver<any, Json.Serializable, Json.Serializable>,
21
+ >(token: AtomIO.MutableAtomToken<Core>): () => void {
23
22
  let unsubscribeFromStateUpdates: (() => void) | null = null
24
23
 
25
24
  const jsonToken = getJsonToken(store, token)
@@ -7,10 +7,11 @@ import { roomIndex, usersInRooms } from "atom.io/realtime"
7
7
  import type { ChildSocket } from "../ipc-sockets"
8
8
  import type { RoomArguments } from "./server-room-external-store"
9
9
  import { roomArgumentsAtoms, roomSelectors } from "./server-room-external-store"
10
+ import type { RoomKey } from "./server-user-store"
10
11
 
11
12
  export const createRoomTX: AtomIO.TransactionToken<
12
13
  (
13
- roomId: string,
14
+ roomKey: RoomKey,
14
15
  script: string,
15
16
  options?: string[],
16
17
  ) => Loadable<ChildSocket<any, any>>
@@ -62,17 +63,17 @@ export const leaveRoomTX: AtomIO.TransactionToken<
62
63
  })
63
64
  export type LeaveRoomIO = AtomIO.TransactionIO<typeof leaveRoomTX>
64
65
 
65
- export const destroyRoomTX: AtomIO.TransactionToken<(roomId: string) => void> =
66
+ export const destroyRoomTX: AtomIO.TransactionToken<(roomKey: RoomKey) => void> =
66
67
  AtomIO.transaction({
67
68
  key: `destroyRoom`,
68
- do: (tools, roomId) => {
69
+ do: (tools, roomKey) => {
69
70
  editRelationsInStore(
70
71
  usersInRooms,
71
72
  (relations) => {
72
- relations.delete({ room: roomId })
73
+ relations.delete({ room: roomKey })
73
74
  },
74
75
  tools.env().store,
75
76
  )
76
- tools.set(roomIndex, (s) => (s.delete(roomId), s))
77
+ tools.set(roomIndex, (s) => (s.delete(roomKey), s))
77
78
  },
78
79
  })
@@ -5,7 +5,6 @@ import type {
5
5
  RegularAtomFamilyToken,
6
6
  } from "atom.io"
7
7
  import { atomFamily, join, mutableAtom } from "atom.io"
8
- import type { SetRTXJson } from "atom.io/transceivers/set-rtx"
9
8
  import { SetRTX } from "atom.io/transceivers/set-rtx"
10
9
 
11
10
  import type { Socket } from ".."
@@ -29,23 +28,17 @@ export const socketAtoms: RegularAtomFamilyToken<Socket | null, SocketKey> =
29
28
  default: null,
30
29
  })
31
30
 
32
- export const socketIndex: MutableAtomToken<
33
- SetRTX<SocketKey>,
34
- SetRTXJson<SocketKey>
35
- > = mutableAtom<SetRTX<SocketKey>, SetRTXJson<SocketKey>>({
31
+ export const socketIndex: MutableAtomToken<SetRTX<SocketKey>> = mutableAtom<
32
+ SetRTX<SocketKey>
33
+ >({
36
34
  key: `socketsIndex`,
37
- default: () => new SetRTX(),
38
- toJson: (set) => set.toJSON(),
39
- fromJson: (json) => SetRTX.fromJSON(json),
35
+ class: SetRTX,
40
36
  })
41
- export const userIndex: MutableAtomToken<
42
- SetRTX<UserKey>,
43
- SetRTXJson<UserKey>
44
- > = mutableAtom<SetRTX<UserKey>, SetRTXJson<UserKey>>({
37
+ export const userIndex: MutableAtomToken<SetRTX<UserKey>> = mutableAtom<
38
+ SetRTX<UserKey>
39
+ >({
45
40
  key: `usersIndex`,
46
- default: () => new SetRTX(),
47
- toJson: (set) => set.toJSON(),
48
- fromJson: (json) => SetRTX.fromJSON(json),
41
+ class: SetRTX,
49
42
  })
50
43
  export const usersOfSockets: JoinToken<
51
44
  `user`,
@@ -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>, 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,140 +0,0 @@
1
- /* eslint-disable @typescript-eslint/switch-exhaustiveness-check */
2
- import type { RuleType } from "@eslint/core"
3
- import type { Rule } from "eslint"
4
- import type * as ESTree from "estree"
5
-
6
- import { walk } from "../walk"
7
-
8
- export const synchronousSelectorDependencies: {
9
- meta: {
10
- type: RuleType
11
- docs: {
12
- description: string
13
- category: string
14
- recommended: boolean
15
- url: string
16
- }
17
- schema: never[]
18
- }
19
- create(context: Rule.RuleContext): Rule.NodeListener
20
- } = {
21
- meta: {
22
- type: `problem`,
23
- docs: {
24
- description: `disallow await before calling get on the parameter's get method inside selector`,
25
- category: `Possible Errors`,
26
- recommended: false,
27
- url: ``, // URL to documentation page for this rule
28
- },
29
- schema: [], // no options
30
- },
31
- create(context) {
32
- return {
33
- CallExpression(node) {
34
- let selectorComputation: ESTree.Node | undefined
35
- if (`name` in node.callee && node.callee.name === `selectorFamily`) {
36
- if (node.arguments[0].type === `ObjectExpression`) {
37
- const selectorLookupProperty = node.arguments[0].properties.find(
38
- (prop): prop is ESTree.Property => {
39
- return (
40
- `key` in prop && `name` in prop.key && prop.key.name === `get`
41
- )
42
- },
43
- )
44
- const selectorLookup = selectorLookupProperty?.value
45
- if (
46
- selectorLookup?.type === `FunctionExpression` ||
47
- selectorLookup?.type === `ArrowFunctionExpression`
48
- ) {
49
- if (selectorLookup.body.type === `BlockStatement`) {
50
- for (const statement of selectorLookup.body.body) {
51
- if (
52
- statement.type === `ReturnStatement` &&
53
- statement.argument
54
- ) {
55
- selectorComputation = statement.argument
56
- }
57
- }
58
- } else if (
59
- selectorLookup.body.type === `FunctionExpression` ||
60
- selectorLookup.body.type === `ArrowFunctionExpression`
61
- ) {
62
- selectorComputation = selectorLookup.body
63
- }
64
- }
65
- }
66
- }
67
- if (`name` in node.callee && node.callee.name === `selector`) {
68
- if (node.arguments[0].type === `ObjectExpression`) {
69
- const selectorComputationProperty =
70
- node.arguments[0].properties.find(
71
- (prop): prop is ESTree.Property => {
72
- return (
73
- `key` in prop &&
74
- `name` in prop.key &&
75
- prop.key.name === `get`
76
- )
77
- },
78
- )
79
- selectorComputation = selectorComputationProperty?.value
80
- }
81
- }
82
- if (
83
- selectorComputation?.type === `FunctionExpression` ||
84
- selectorComputation?.type === `ArrowFunctionExpression`
85
- ) {
86
- const nonDestructuredTransactorsName =
87
- selectorComputation.params[0] &&
88
- `name` in selectorComputation.params[0]
89
- ? selectorComputation.params[0].name
90
- : undefined
91
- let awaited: number | undefined
92
- let awaitNode: ESTree.AwaitExpression | undefined
93
- walk(selectorComputation, (n, depth) => {
94
- // console.log(`${`\t`.repeat(depth)}${n.type} ${n.name ?? ``}`)
95
- if (typeof awaited === `number`) {
96
- if (awaited > depth) {
97
- awaited = undefined
98
- awaitNode = undefined
99
- }
100
- }
101
- switch (n.type) {
102
- case `AwaitExpression`:
103
- awaited = depth
104
- awaitNode = n
105
- break
106
- case `CallExpression`:
107
- if (awaitNode) {
108
- let willReport = false
109
- switch (n.callee.type) {
110
- case `MemberExpression`:
111
- if (
112
- n.callee.object.type === `Identifier` &&
113
- n.callee.object.name ===
114
- nonDestructuredTransactorsName &&
115
- n.callee.property.type === `Identifier` &&
116
- n.callee.property.name === `get`
117
- ) {
118
- willReport = true
119
- }
120
- break
121
- case `Identifier`:
122
- if (n.callee.name === `get`) {
123
- willReport = true
124
- }
125
- break
126
- }
127
- if (willReport) {
128
- context.report({
129
- node: awaitNode,
130
- message: `Using await before calling the 'get' transactor is not allowed.`,
131
- })
132
- }
133
- }
134
- }
135
- })
136
- }
137
- },
138
- }
139
- },
140
- } satisfies Rule.RuleModule