atom.io 0.35.0 → 0.36.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 (94) 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 +47 -41
  6. package/dist/internal/index.d.ts.map +1 -1
  7. package/dist/internal/index.js +95 -78
  8. package/dist/internal/index.js.map +1 -1
  9. package/dist/json/index.d.ts +2 -10
  10. package/dist/json/index.d.ts.map +1 -1
  11. package/dist/json/index.js +1 -31
  12. package/dist/json/index.js.map +1 -1
  13. package/dist/main/index.d.ts +24 -23
  14. package/dist/main/index.d.ts.map +1 -1
  15. package/dist/main/index.js +9 -9
  16. package/dist/main/index.js.map +1 -1
  17. package/dist/react/index.d.ts +4 -4
  18. package/dist/react/index.d.ts.map +1 -1
  19. package/dist/react/index.js.map +1 -1
  20. package/dist/react-devtools/index.d.ts.map +1 -1
  21. package/dist/realtime/index.d.ts +4 -4
  22. package/dist/realtime/index.d.ts.map +1 -1
  23. package/dist/realtime/index.js +2 -6
  24. package/dist/realtime/index.js.map +1 -1
  25. package/dist/realtime-client/index.d.ts +2 -2
  26. package/dist/realtime-client/index.d.ts.map +1 -1
  27. package/dist/realtime-client/index.js.map +1 -1
  28. package/dist/realtime-react/index.d.ts +2 -2
  29. package/dist/realtime-react/index.d.ts.map +1 -1
  30. package/dist/realtime-react/index.js.map +1 -1
  31. package/dist/realtime-server/index.d.ts +18 -18
  32. package/dist/realtime-server/index.d.ts.map +1 -1
  33. package/dist/realtime-server/index.js +5 -9
  34. package/dist/realtime-server/index.js.map +1 -1
  35. package/dist/transceivers/set-rtx/index.d.ts +1 -1
  36. package/dist/transceivers/set-rtx/index.d.ts.map +1 -1
  37. package/dist/transceivers/set-rtx/index.js.map +1 -1
  38. package/package.json +5 -5
  39. package/src/eslint-plugin/index.ts +0 -1
  40. package/src/eslint-plugin/rules/explicit-state-types.ts +8 -1
  41. package/src/eslint-plugin/rules/index.ts +0 -1
  42. package/src/internal/atom/dispose-atom.ts +1 -0
  43. package/src/internal/families/find-in-store.ts +4 -5
  44. package/src/internal/families/get-family-of-token.ts +4 -5
  45. package/src/internal/families/init-family-member.ts +3 -4
  46. package/src/internal/families/seek-in-store.ts +4 -5
  47. package/src/internal/get-state/read-or-compute-value.ts +14 -2
  48. package/src/internal/index.ts +19 -21
  49. package/src/internal/ingest-updates/ingest-creation-disposal.ts +18 -15
  50. package/src/internal/ingest-updates/ingest-selector-update.ts +9 -5
  51. package/src/internal/join/get-internal-relations-from-store.ts +2 -2
  52. package/src/internal/join/join-internal.ts +3 -14
  53. package/src/internal/molecule.ts +1 -0
  54. package/src/internal/mutable/create-mutable-atom-family.ts +37 -20
  55. package/src/internal/mutable/create-mutable-atom.ts +16 -12
  56. package/src/internal/mutable/get-json-family.ts +7 -6
  57. package/src/internal/mutable/get-json-token.ts +6 -13
  58. package/src/internal/mutable/get-update-family.ts +7 -8
  59. package/src/internal/mutable/get-update-token.ts +5 -9
  60. package/src/internal/mutable/tracker-family.ts +10 -13
  61. package/src/internal/mutable/tracker.ts +66 -90
  62. package/src/internal/mutable/transceiver.ts +35 -8
  63. package/src/internal/selector/dispose-selector.ts +9 -9
  64. package/src/internal/set-state/copy-mutable-if-needed.ts +8 -6
  65. package/src/internal/set-state/reset-atom-or-selector.ts +11 -4
  66. package/src/internal/set-state/set-atom.ts +1 -1
  67. package/src/internal/store/counterfeit.ts +3 -4
  68. package/src/internal/store/deposit.ts +7 -9
  69. package/src/internal/store/store.ts +2 -2
  70. package/src/internal/store/withdraw.ts +7 -11
  71. package/src/json/index.ts +0 -2
  72. package/src/main/atom.ts +24 -36
  73. package/src/main/dispose-state.ts +4 -4
  74. package/src/main/find-state.ts +3 -4
  75. package/src/main/join.ts +2 -2
  76. package/src/main/logger.ts +7 -7
  77. package/src/main/tokens.ts +9 -11
  78. package/src/main/transaction.ts +11 -5
  79. package/src/main/validators.ts +1 -1
  80. package/src/react/use-json.ts +15 -25
  81. package/src/realtime/shared-room-store.ts +11 -22
  82. package/src/realtime-client/pull-mutable-atom-family-member.ts +5 -9
  83. package/src/realtime-client/pull-mutable-atom.ts +5 -9
  84. package/src/realtime-react/use-pull-mutable-atom.ts +3 -5
  85. package/src/realtime-react/use-pull-mutable-family-member.ts +3 -4
  86. package/src/realtime-server/realtime-mutable-family-provider.ts +3 -4
  87. package/src/realtime-server/realtime-mutable-provider.ts +2 -3
  88. package/src/realtime-server/realtime-server-stores/server-room-external-actions.ts +6 -5
  89. package/src/realtime-server/realtime-server-stores/server-user-store.ts +8 -15
  90. package/src/transceivers/set-rtx/set-rtx.ts +1 -1
  91. package/src/eslint-plugin/rules/synchronous-selector-dependencies.ts +0 -140
  92. package/src/eslint-plugin/walk.ts +0 -81
  93. package/src/json/select-json-family.ts +0 -55
  94. package/src/json/select-json.ts +0 -19
package/src/main/atom.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Transceiver } from "atom.io/internal"
1
+ import type { ConstructorOf, Transceiver } from "atom.io/internal"
2
2
  import {
3
3
  createMutableAtom,
4
4
  createMutableAtomFamily,
@@ -6,7 +6,7 @@ import {
6
6
  createRegularAtomFamily,
7
7
  IMPLICIT,
8
8
  } from "atom.io/internal"
9
- import type { Canonical, Json, JsonInterface } from "atom.io/json"
9
+ import type { Canonical } from "atom.io/json"
10
10
 
11
11
  import type { Setter } from "./set-state"
12
12
  import type {
@@ -34,20 +34,14 @@ export function atom<T>(options: RegularAtomOptions<T>): RegularAtomToken<T> {
34
34
  return createRegularAtom(IMPLICIT.STORE, options, undefined)
35
35
  }
36
36
 
37
- // biome-ignore format: intersection
38
- export type MutableAtomOptions<
39
- T extends Transceiver<any>,
40
- J extends Json.Serializable,
41
- > =
42
- & JsonInterface<T, J>
43
- & {
44
- /** The unique identifier of the atom */
45
- key: string
46
- /** A function to create an initial value for the atom */
47
- default: () => T
48
- /** Hooks used to run side effects when the atom is set */
49
- effects?: AtomEffect<T>[]
50
- }
37
+ export type MutableAtomOptions<T extends Transceiver<any, any>> = {
38
+ /** The unique identifier of the atom */
39
+ key: string
40
+ /** A constructor for the atom's value */
41
+ class: ConstructorOf<T>
42
+ /** Hooks used to run side effects when the atom is set */
43
+ effects?: AtomEffect<T>[]
44
+ }
51
45
  /**
52
46
  * Create a mutable atom, a global reactive variable in the implicit store
53
47
  *
@@ -57,10 +51,9 @@ export type MutableAtomOptions<
57
51
  * @returns
58
52
  * A reference to the atom created: a {@link MutableAtomToken}
59
53
  */
60
- export function mutableAtom<
61
- T extends Transceiver<any>,
62
- J extends Json.Serializable,
63
- >(options: MutableAtomOptions<T, J>): MutableAtomToken<T, J> {
54
+ export function mutableAtom<T extends Transceiver<any, any>>(
55
+ options: MutableAtomOptions<T>,
56
+ ): MutableAtomToken<T> {
64
57
  return createMutableAtom(IMPLICIT.STORE, options, undefined)
65
58
  }
66
59
 
@@ -105,21 +98,17 @@ export function atomFamily<T, K extends Canonical>(
105
98
  return createRegularAtomFamily(IMPLICIT.STORE, options)
106
99
  }
107
100
 
108
- // biome-ignore format: intersection
109
101
  export type MutableAtomFamilyOptions<
110
- T extends Transceiver<any>,
111
- J extends Json.Serializable,
102
+ T extends Transceiver<any, any>,
112
103
  K extends Canonical,
113
- > =
114
- & JsonInterface<T, J>
115
- & {
116
- /** The unique identifier of the atom family */
117
- key: string
118
- /** A function to create an initial value for each atom in the family */
119
- default: (key: K) => T
120
- /** Hooks used to run side effects when an atom in the family is set */
121
- effects?: (key: K) => AtomEffect<T>[]
122
- }
104
+ > = {
105
+ /** The unique identifier of the atom family */
106
+ key: string
107
+ /** The class of the transceiver to be created */
108
+ class: ConstructorOf<T>
109
+ /** Hooks used to run side effects when an atom in the family is set */
110
+ effects?: (key: K) => AtomEffect<T>[]
111
+ }
123
112
  /**
124
113
  * Create a family of mutable atoms, allowing for the dynamic creation and disposal of atoms.
125
114
  *
@@ -130,9 +119,8 @@ export type MutableAtomFamilyOptions<
130
119
  * A reference to the atom family created: a {@link MutableAtomFamilyToken}
131
120
  */
132
121
  export function mutableAtomFamily<
133
- T extends Transceiver<any>,
134
- J extends Json.Serializable,
122
+ T extends Transceiver<any, any>,
135
123
  K extends Canonical,
136
- >(options: MutableAtomFamilyOptions<T, J, K>): MutableAtomFamilyToken<T, J, K> {
124
+ >(options: MutableAtomFamilyOptions<T, K>): MutableAtomFamilyToken<T, K> {
137
125
  return createMutableAtomFamily(IMPLICIT.STORE, options)
138
126
  }
@@ -25,13 +25,13 @@ export function disposeState<K extends Canonical>(
25
25
  key: K,
26
26
  ): void
27
27
  export function disposeState(
28
- ...[token, key]:
28
+ ...params:
29
29
  | [token: ReadableFamilyToken<any, any>, key: Canonical]
30
30
  | [token: ReadableToken<any>]
31
31
  ): void {
32
- if (key) {
33
- Internal.disposeFromStore(Internal.IMPLICIT.STORE, token as any, key)
32
+ if (params.length === 2) {
33
+ Internal.disposeFromStore(Internal.IMPLICIT.STORE, ...params)
34
34
  } else {
35
- Internal.disposeFromStore(Internal.IMPLICIT.STORE, token as any)
35
+ Internal.disposeFromStore(Internal.IMPLICIT.STORE, ...params)
36
36
  }
37
37
  }
@@ -12,7 +12,7 @@ import type {
12
12
  } from "atom.io"
13
13
  import type { Transceiver } from "atom.io/internal"
14
14
  import { findInStore, IMPLICIT } from "atom.io/internal"
15
- import type { Canonical, Json } from "atom.io/json"
15
+ import type { Canonical } from "atom.io/json"
16
16
 
17
17
  import type { MutableAtomFamilyToken, RegularAtomFamilyToken } from "./tokens"
18
18
 
@@ -30,11 +30,10 @@ import type { MutableAtomFamilyToken, RegularAtomFamilyToken } from "./tokens"
30
30
  * @overload Mutable Atom
31
31
  */
32
32
  export function findState<
33
- T extends Transceiver<any>,
34
- J extends Json.Serializable,
33
+ T extends Transceiver<any, any>,
35
34
  K extends Canonical,
36
35
  Key extends K,
37
- >(token: MutableAtomFamilyToken<T, J, K>, key: Key): MutableAtomToken<T, J, K>
36
+ >(token: MutableAtomFamilyToken<T, K>, key: Key): MutableAtomToken<T, K>
38
37
  /**
39
38
  * Finds a {@link RegularAtomToken} in the store, without accessing its value.
40
39
  *
package/src/main/join.ts CHANGED
@@ -14,7 +14,7 @@ import {
14
14
  IMPLICIT,
15
15
  } from "atom.io/internal"
16
16
  import type { Json } from "atom.io/json"
17
- import type { SetRTX, SetRTXJson } from "atom.io/transceivers/set-rtx"
17
+ import type { SetRTX } from "atom.io/transceivers/set-rtx"
18
18
 
19
19
  // biome-ignore format: intersection
20
20
  export type JoinOptions<
@@ -262,6 +262,6 @@ export function getInternalRelations<
262
262
  Content extends Json.Object | null,
263
263
  >(
264
264
  token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>,
265
- ): MutableAtomFamilyToken<SetRTX<string>, SetRTXJson<string>, string> {
265
+ ): MutableAtomFamilyToken<SetRTX<string>, string> {
266
266
  return getInternalRelationsFromStore(token, IMPLICIT.STORE)
267
267
  }
@@ -105,7 +105,7 @@ export const simpleLogger: Logger = {
105
105
 
106
106
  export class AtomIOLogger implements Logger {
107
107
  public logLevel: `error` | `info` | `warn` | null
108
- private readonly filter: LogFilter | undefined
108
+ public filter: LogFilter | undefined
109
109
  private readonly logger: Logger
110
110
 
111
111
  public constructor(
@@ -119,31 +119,31 @@ export class AtomIOLogger implements Logger {
119
119
  }
120
120
 
121
121
  public error: LogFn = (...args) => {
122
- const filterResult = this.filter?.(...args) ?? true
123
122
  if (this.logLevel !== null) {
123
+ const filterResult = this.filter?.(...args) ?? true
124
124
  if (filterResult === true) {
125
125
  this.logger.error(...args)
126
- } else if (filterResult !== false) {
126
+ } else if (filterResult) {
127
127
  this.logger.error(...filterResult)
128
128
  }
129
129
  }
130
130
  }
131
131
  public info: LogFn = (...args) => {
132
- const filterResult = this.filter?.(...args) ?? true
133
132
  if (this.logLevel === `info`) {
133
+ const filterResult = this.filter?.(...args) ?? true
134
134
  if (filterResult === true) {
135
135
  this.logger.info(...args)
136
- } else if (filterResult !== false) {
136
+ } else if (filterResult) {
137
137
  this.logger.info(...filterResult)
138
138
  }
139
139
  }
140
140
  }
141
141
  public warn: LogFn = (...args) => {
142
- const filterResult = this.filter?.(...args) ?? true
143
142
  if (this.logLevel !== `error` && this.logLevel !== null) {
143
+ const filterResult = this.filter?.(...args) ?? true
144
144
  if (filterResult === true) {
145
145
  this.logger.warn(...args)
146
- } else if (filterResult !== false) {
146
+ } else if (filterResult) {
147
147
  this.logger.warn(...filterResult)
148
148
  }
149
149
  }
@@ -1,5 +1,5 @@
1
- import type { Func, Transceiver } from "atom.io/internal"
2
- import type { Canonical, Json, stringified } from "atom.io/json"
1
+ import type { AsJSON, Func, Transceiver } from "atom.io/internal"
2
+ import type { Canonical, stringified } from "atom.io/json"
3
3
 
4
4
  /**
5
5
  * A token is an object that uniquely identifies a particular state, family, timeline, or transaction.
@@ -63,7 +63,7 @@ export type TransactionToken<F extends Func> = {
63
63
  }
64
64
 
65
65
  export type AtomToken<T, K extends Canonical = any> =
66
- | MutableAtomToken<T extends Transceiver<any> ? T : never, any, K>
66
+ | MutableAtomToken<T extends Transceiver<any, any> ? T : never, K>
67
67
  | RegularAtomToken<T, K>
68
68
  export type RegularAtomToken<T, K extends Canonical = any> = {
69
69
  /** The unique identifier of the atom. */
@@ -76,8 +76,7 @@ export type RegularAtomToken<T, K extends Canonical = any> = {
76
76
  __T?: T
77
77
  }
78
78
  export type MutableAtomToken<
79
- T extends Transceiver<any>,
80
- J extends Json.Serializable,
79
+ T extends Transceiver<any, any>,
81
80
  K extends Canonical = any,
82
81
  > = {
83
82
  /** The unique identifier of the atom. */
@@ -87,9 +86,9 @@ export type MutableAtomToken<
87
86
  /** Present if the atom belongs to a family. */
88
87
  family?: FamilyMetadata<K>
89
88
  /** Never present. This is a marker that preserves the JSON form of the atom's transceiver value. */
90
- __J?: J
89
+ __J?: AsJSON<T>
91
90
  /** Never present. This is a marker that preserves the type of the atom's transceiver value. */
92
- __U?: T extends Transceiver<infer Update> ? Update : never
91
+ __U?: T extends Transceiver<infer Update, any> ? Update : never
93
92
  }
94
93
 
95
94
  export type SelectorToken<T, K extends Canonical = any> =
@@ -160,7 +159,7 @@ export type FamilyMetadata<K extends Canonical = any> = {
160
159
  }
161
160
 
162
161
  export type AtomFamilyToken<T, K extends Canonical = Canonical> =
163
- | MutableAtomFamilyToken<T extends Transceiver<any> ? T : never, any, K>
162
+ | MutableAtomFamilyToken<T extends Transceiver<any, any> ? T : never, K>
164
163
  | RegularAtomFamilyToken<T, K>
165
164
  export type RegularAtomFamilyToken<T, K extends Canonical> = {
166
165
  /** The unique identifier of the atom family */
@@ -173,8 +172,7 @@ export type RegularAtomFamilyToken<T, K extends Canonical> = {
173
172
  __K?: K
174
173
  }
175
174
  export type MutableAtomFamilyToken<
176
- T extends Transceiver<any>,
177
- J extends Json.Serializable,
175
+ T extends Transceiver<any, any>,
178
176
  K extends Canonical,
179
177
  > = {
180
178
  /** The unique identifier of the atom family */
@@ -184,7 +182,7 @@ export type MutableAtomFamilyToken<
184
182
  /** Never present. This is a marker that preserves the type of atoms in this family */
185
183
  __T?: T
186
184
  /** Never present. This is a marker that preserves the type of the JSON form of atoms in this family */
187
- __J?: J
185
+ __J?: AsJSON<T>
188
186
  /** Never present. This is a marker that preserves the type of keys used for atoms in this family */
189
187
  __K?: K
190
188
  }
@@ -1,11 +1,16 @@
1
- import type { EnvironmentData, Func, Transceiver } from "atom.io/internal"
1
+ import type {
2
+ AsJSON,
3
+ EnvironmentData,
4
+ Func,
5
+ Transceiver,
6
+ } from "atom.io/internal"
2
7
  import {
3
8
  actUponStore,
4
9
  arbitrary,
5
10
  createTransaction,
6
11
  IMPLICIT,
7
12
  } from "atom.io/internal"
8
- import type { Canonical, Json, stringified } from "atom.io/json"
13
+ import type { Canonical, stringified } from "atom.io/json"
9
14
 
10
15
  import type { disposeState } from "./dispose-state"
11
16
  import type { findState } from "./find-state"
@@ -55,6 +60,7 @@ export type MoleculeDisposal = {
55
60
  export type MoleculeTransfer = {
56
61
  type: `molecule_transfer`
57
62
  key: Canonical
63
+ exclusive: boolean
58
64
  from: Canonical[]
59
65
  to: Canonical[]
60
66
  }
@@ -85,9 +91,9 @@ export type ActorToolkit = Readonly<{
85
91
  set: typeof setState
86
92
  reset: typeof resetState
87
93
  find: typeof findState
88
- json: <T extends Transceiver<any>, J extends Json.Serializable>(
89
- state: MutableAtomToken<T, J>,
90
- ) => WritablePureSelectorToken<J>
94
+ json: <T extends Transceiver<any, any>>(
95
+ state: MutableAtomToken<T>,
96
+ ) => WritablePureSelectorToken<AsJSON<T>>
91
97
  dispose: typeof disposeState
92
98
  run: typeof runTransaction
93
99
  env: () => EnvironmentData
@@ -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>>(
11
+ token: MutableAtomToken<T>,
12
+ ): AsJSON<T>
16
13
 
17
- export function useJSON<
18
- Serializable extends Json.Serializable,
19
- Key extends Canonical,
20
- >(token: MutableAtomFamilyToken<any, Serializable, Key>, key: Key): Serializable
14
+ export function useJSON<T extends Transceiver<any, any>, K extends Canonical>(
15
+ token: MutableAtomFamilyToken<T, K>,
16
+ key: K,
17
+ ): 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,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,19 +1,15 @@
1
1
  import type * as AtomIO from "atom.io"
2
- import type { Store, Transceiver } from "atom.io/internal"
2
+ import type { AsJSON, 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
- export function pullMutableAtomFamilyMember<
11
- T extends Transceiver<any>,
12
- J extends Json.Serializable,
13
- >(
9
+ export function pullMutableAtomFamilyMember<T extends Transceiver<any, any>>(
14
10
  store: Store,
15
11
  socket: Socket,
16
- token: AtomIO.MutableAtomToken<T, J>,
12
+ token: AtomIO.MutableAtomToken<T>,
17
13
  ): () => void {
18
14
  if (!(`family` in token)) {
19
15
  console.error(`Token is not a family member:`, token)
@@ -21,13 +17,13 @@ export function pullMutableAtomFamilyMember<
21
17
  }
22
18
  const { key: familyKey, subKey: serializedSubKey } = token.family
23
19
  const subKey = parseJson(serializedSubKey)
24
- socket.on(`init:${token.key}`, (data: J) => {
20
+ socket.on(`init:${token.key}`, (data: AsJSON<T>) => {
25
21
  const jsonToken = getJsonToken(store, token)
26
22
  setIntoStore(store, jsonToken, data)
27
23
  })
28
24
  socket.on(
29
25
  `next:${token.key}`,
30
- (data: T extends Transceiver<infer Signal> ? Signal : never) => {
26
+ (data: T extends Transceiver<infer Signal, any> ? Signal : never) => {
31
27
  const trackerToken = getUpdateToken(token)
32
28
  setIntoStore(store, trackerToken, data)
33
29
  },
@@ -1,25 +1,21 @@
1
1
  import type * as AtomIO from "atom.io"
2
- import type { Store, Transceiver } from "atom.io/internal"
2
+ import type { AsJSON, 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>>(
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
16
  socket.on(
21
17
  `next:${token.key}`,
22
- (data: T extends Transceiver<infer Update> ? Update : never) => {
18
+ (data: T extends Transceiver<infer Update, any> ? Update : never) => {
23
19
  setIntoStore(store, updateToken, data)
24
20
  },
25
21
  )
@@ -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>>(
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>,
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) =>
@@ -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>,
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<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`,