atom.io 0.34.1 → 0.35.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 (53) hide show
  1. package/dist/internal/index.d.ts +32 -41
  2. package/dist/internal/index.d.ts.map +1 -1
  3. package/dist/internal/index.js +106 -128
  4. package/dist/internal/index.js.map +1 -1
  5. package/dist/json/index.d.ts +19 -7
  6. package/dist/json/index.d.ts.map +1 -1
  7. package/dist/json/index.js +4 -0
  8. package/dist/json/index.js.map +1 -1
  9. package/dist/main/index.d.ts +704 -788
  10. package/dist/main/index.d.ts.map +1 -1
  11. package/dist/main/index.js +61 -33
  12. package/dist/main/index.js.map +1 -1
  13. package/dist/react-devtools/index.js +10 -10
  14. package/dist/react-devtools/index.js.map +1 -1
  15. package/dist/realtime/index.d.ts.map +1 -1
  16. package/dist/realtime/index.js +3 -5
  17. package/dist/realtime/index.js.map +1 -1
  18. package/dist/realtime-client/index.js +10 -10
  19. package/dist/realtime-client/index.js.map +1 -1
  20. package/dist/realtime-server/index.d.ts.map +1 -1
  21. package/dist/realtime-server/index.js +8 -10
  22. package/dist/realtime-server/index.js.map +1 -1
  23. package/package.json +12 -12
  24. package/src/internal/atom/create-regular-atom.ts +1 -0
  25. package/src/internal/atom/index.ts +0 -1
  26. package/src/internal/families/index.ts +0 -1
  27. package/src/internal/index.ts +111 -89
  28. package/src/internal/join/join-internal.ts +3 -4
  29. package/src/internal/mutable/create-mutable-atom-family.ts +0 -1
  30. package/src/internal/mutable/create-mutable-atom.ts +1 -1
  31. package/src/internal/selector/register-selector.ts +2 -2
  32. package/src/json/entries.ts +10 -3
  33. package/src/json/index.ts +40 -17
  34. package/src/main/atom.ts +68 -115
  35. package/src/main/dispose-state.ts +0 -2
  36. package/src/main/find-state.ts +3 -9
  37. package/src/main/get-state.ts +0 -2
  38. package/src/main/index.ts +1 -176
  39. package/src/main/join.ts +12 -20
  40. package/src/main/reset-state.ts +0 -2
  41. package/src/main/selector.ts +5 -72
  42. package/src/main/set-state.ts +1 -4
  43. package/src/main/silo.ts +14 -5
  44. package/src/main/subscribe.ts +0 -7
  45. package/src/main/timeline.ts +24 -32
  46. package/src/main/tokens.ts +247 -0
  47. package/src/main/transaction.ts +17 -55
  48. package/src/main/validators.ts +1 -1
  49. package/src/react-devtools/store.ts +61 -45
  50. package/src/realtime/shared-room-store.ts +3 -5
  51. package/src/realtime-server/realtime-server-stores/server-user-store.ts +3 -5
  52. package/src/internal/atom/create-standalone-atom.ts +0 -39
  53. package/src/internal/families/create-atom-family.ts +0 -38
@@ -6,11 +6,15 @@ import {
6
6
  import type { Canonical } from "atom.io/json"
7
7
 
8
8
  import type {
9
+ ReadonlyHeldSelectorFamilyToken,
9
10
  ReadonlyHeldSelectorToken,
11
+ ReadonlyPureSelectorFamilyToken,
10
12
  ReadonlyPureSelectorToken,
13
+ WritableHeldSelectorFamilyToken,
11
14
  WritableHeldSelectorToken,
15
+ WritablePureSelectorFamilyToken,
12
16
  WritablePureSelectorToken,
13
- } from "."
17
+ } from "./tokens"
14
18
  import type { Read, Write } from "./transaction"
15
19
 
16
20
  export type WritablePureSelectorOptions<T> = {
@@ -47,7 +51,6 @@ export type WritableHeldSelectorOptions<T extends object> = {
47
51
  }
48
52
 
49
53
  /**
50
- * @public
51
54
  * Declare a selector. The value of a selector should depend
52
55
  * on the value of atoms or other selectors in the store, and
53
56
  * should be recycled when a root atom of the selector is set.
@@ -68,7 +71,6 @@ export function selector<T extends object>(
68
71
  options: WritableHeldSelectorOptions<T>,
69
72
  ): WritableHeldSelectorToken<T>
70
73
  /**
71
- * @public
72
74
  * Declare a selector. The value of a selector should depend
73
75
  * on the value of atoms or other selectors in the store,
74
76
  * and should be recycled when a root atom of the selector is set.
@@ -87,7 +89,6 @@ export function selector<T extends object>(
87
89
  options: ReadonlyHeldSelectorOptions<T>,
88
90
  ): ReadonlyHeldSelectorToken<T>
89
91
  /**
90
- * @public
91
92
  * Declare a selector. The value of a selector should depend
92
93
  * on the value of atoms or other selectors in the store.
93
94
  *
@@ -107,7 +108,6 @@ export function selector<T>(
107
108
  options: WritablePureSelectorOptions<T>,
108
109
  ): WritablePureSelectorToken<T>
109
110
  /**
110
- * @public
111
111
  * Declare a selector. The value of a selector should depend
112
112
  * on the value of atoms or other selectors in the store.
113
113
  *
@@ -138,7 +138,6 @@ export function selector(
138
138
  return createStandaloneSelector(IMPLICIT.STORE, options)
139
139
  }
140
140
 
141
- /** @public */
142
141
  export type WritablePureSelectorFamilyOptions<T, K extends Canonical> = {
143
142
  /** The unique identifier of the family */
144
143
  key: string
@@ -147,14 +146,12 @@ export type WritablePureSelectorFamilyOptions<T, K extends Canonical> = {
147
146
  /** For each instantiated family member, a function that sets its value */
148
147
  set: (key: K) => Write<(newValue: T) => void>
149
148
  }
150
- /** @public */
151
149
  export type ReadonlyPureSelectorFamilyOptions<T, K extends Canonical> = {
152
150
  /** The unique identifier of the family */
153
151
  key: string
154
152
  /** For each instantiated family member, a function that computes its value */
155
153
  get: (key: K) => Read<() => T>
156
154
  }
157
- /** @public */
158
155
  export type WritableHeldSelectorFamilyOptions<
159
156
  T extends object,
160
157
  K extends Canonical,
@@ -168,7 +165,6 @@ export type WritableHeldSelectorFamilyOptions<
168
165
  /** For each instantiated family member, a function that sets its value */
169
166
  set: (key: K) => Write<(newValue: T) => void>
170
167
  }
171
- /** @public */
172
168
  export type ReadonlyHeldSelectorFamilyOptions<
173
169
  T extends object,
174
170
  K extends Canonical,
@@ -181,67 +177,7 @@ export type ReadonlyHeldSelectorFamilyOptions<
181
177
  get: (key: K) => Read<(permanent: T) => void>
182
178
  }
183
179
 
184
- export type WritablePureSelectorFamilyToken<T, K extends Canonical> = {
185
- /** The unique identifier of the family */
186
- key: string
187
- /** Discriminator */
188
- type: `writable_pure_selector_family`
189
- /** Never present. This is a marker that preserves the type of the value of each family member */
190
- __T?: T
191
- /** Never present. This is a marker that preserves the type of keys used for each family member */
192
- __K?: K
193
- }
194
- export type ReadonlyPureSelectorFamilyToken<T, K extends Canonical> = {
195
- /** The unique identifier of the family */
196
- key: string
197
- /** Discriminator */
198
- type: `readonly_pure_selector_family`
199
- /** Never present. This is a marker that preserves the type of the value of each family member */
200
- __T?: T
201
- /** Never present. This is a marker that preserves the type of keys used for each family member */
202
- __K?: K
203
- }
204
- export type WritableHeldSelectorFamilyToken<T, K extends Canonical> = {
205
- /** The unique identifier of the family */
206
- key: string
207
- /** Discriminator */
208
- type: `writable_held_selector_family`
209
- /** Never present. This is a marker that preserves the type of the value of each family member */
210
- __T?: T
211
- /** Never present. This is a marker that preserves the type of keys used for each family member */
212
- __K?: K
213
- }
214
- export type ReadonlyHeldSelectorFamilyToken<T, K extends Canonical> = {
215
- /** The unique identifier of the family */
216
- key: string
217
- /** Discriminator */
218
- type: `readonly_held_selector_family`
219
- /** Never present. This is a marker that preserves the type of the value of each family member */
220
- __T?: T
221
- /** Never present. This is a marker that preserves the type of keys used for each family member */
222
- __K?: K
223
- }
224
-
225
- export type PureSelectorFamilyToken<T, K extends Canonical> =
226
- | ReadonlyPureSelectorFamilyToken<T, K>
227
- | WritablePureSelectorFamilyToken<T, K>
228
- export type HeldSelectorFamilyToken<T, K extends Canonical> =
229
- | ReadonlyHeldSelectorFamilyToken<T, K>
230
- | WritableHeldSelectorFamilyToken<T, K>
231
- export type ReadonlySelectorFamilyToken<T, K extends Canonical> =
232
- | ReadonlyHeldSelectorFamilyToken<T, K>
233
- | ReadonlyPureSelectorFamilyToken<T, K>
234
-
235
- export type WritableSelectorFamilyToken<T, K extends Canonical> =
236
- | WritableHeldSelectorFamilyToken<T, K>
237
- | WritablePureSelectorFamilyToken<T, K>
238
-
239
- export type SelectorFamilyToken<T, K extends Canonical> =
240
- | HeldSelectorFamilyToken<T, K>
241
- | PureSelectorFamilyToken<T, K>
242
-
243
180
  /**
244
- * @public
245
181
  * Create a family of selectors, allowing for the dynamic creation and disposal of selectors.
246
182
  *
247
183
  * The value of a held selector should depend on the value of atoms or other selectors in the store,
@@ -263,7 +199,6 @@ export function selectorFamily<T extends object, K extends Canonical>(
263
199
  options: WritableHeldSelectorFamilyOptions<T, K>,
264
200
  ): WritableHeldSelectorFamilyToken<T, K>
265
201
  /**
266
- * @public
267
202
  * Create a family of selectors, allowing for the dynamic creation and disposal of selectors.
268
203
  *
269
204
  * The value of a held selector should depend on the value of atoms or other selectors in the store,
@@ -283,7 +218,6 @@ export function selectorFamily<T extends object, K extends Canonical>(
283
218
  options: ReadonlyHeldSelectorFamilyOptions<T, K>,
284
219
  ): ReadonlyHeldSelectorFamilyToken<T, K>
285
220
  /**
286
- * @public
287
221
  * Create a family of selectors, allowing for the dynamic creation and disposal of selectors.
288
222
  *
289
223
  * The value of a selector should depend on the value of atoms or other selectors in the store.
@@ -304,7 +238,6 @@ export function selectorFamily<T, K extends Canonical>(
304
238
  options: WritablePureSelectorFamilyOptions<T, K>,
305
239
  ): WritablePureSelectorFamilyToken<T, K>
306
240
  /**
307
- * @public
308
241
  * Create a family of selectors, allowing for the dynamic creation and disposal of selectors.
309
242
  *
310
243
  * The value of a selector should depend on the value of atoms or other selectors in the store.
@@ -1,10 +1,9 @@
1
1
  import * as Internal from "atom.io/internal"
2
2
  import type { Canonical } from "atom.io/json"
3
3
 
4
- import type { WritableFamilyToken, WritableToken } from "."
4
+ import type { WritableFamilyToken, WritableToken } from "./tokens"
5
5
 
6
6
  /**
7
- * @public
8
7
  * A function that sets the value of a state.
9
8
  * @param oldValue - The current value of the state.
10
9
  * @returns
@@ -13,7 +12,6 @@ import type { WritableFamilyToken, WritableToken } from "."
13
12
  export type Setter<T, New extends T> = (oldValue: T) => New
14
13
 
15
14
  /**
16
- * @public
17
15
  * Set the value of a state into the implicit store.
18
16
  * @param token - An atom or writable selector token.
19
17
  * @param value - The new value of the state.
@@ -26,7 +24,6 @@ export function setState<T, New extends T>(
26
24
  ): void
27
25
 
28
26
  /**
29
- * @public
30
27
  * Set the value of a state into the implicit store.
31
28
  * @param token - An atom family or writable selector family token.
32
29
  * @param key - The unique key of the state to set.
package/src/main/silo.ts CHANGED
@@ -2,9 +2,11 @@ import type { findState } from "atom.io"
2
2
  import {
3
3
  actUponStore,
4
4
  arbitrary,
5
- createAtomFamily,
5
+ createMutableAtom,
6
+ createMutableAtomFamily,
7
+ createRegularAtom,
8
+ createRegularAtomFamily,
6
9
  createSelectorFamily,
7
- createStandaloneAtom,
8
10
  createStandaloneSelector,
9
11
  createTimeline,
10
12
  createTransaction,
@@ -30,7 +32,7 @@ import type {
30
32
  timeline,
31
33
  undo,
32
34
  } from "."
33
- import type { atom, atomFamily } from "./atom"
35
+ import type { atom, atomFamily, mutableAtom, mutableAtomFamily } from "./atom"
34
36
  import type { resetState } from "./reset-state"
35
37
  import type { selector, selectorFamily } from "./selector"
36
38
  import type { runTransaction, transaction } from "./transaction"
@@ -38,7 +40,9 @@ import type { runTransaction, transaction } from "./transaction"
38
40
  export class Silo {
39
41
  public store: Store
40
42
  public atom: typeof atom
43
+ public mutableAtom: typeof mutableAtom
41
44
  public atomFamily: typeof atomFamily
45
+ public mutableAtomFamily: typeof mutableAtomFamily
42
46
  public selector: typeof selector
43
47
  public selectorFamily: typeof selectorFamily
44
48
  public transaction: typeof transaction
@@ -57,9 +61,14 @@ export class Silo {
57
61
  public constructor(config: Store[`config`], fromStore: Store | null = null) {
58
62
  const s = (this.store = new Store(config, fromStore))
59
63
  this.atom = ((options: Parameters<typeof atom>[0]) =>
60
- createStandaloneAtom(s, options)) as typeof atom
64
+ createRegularAtom(s, options, undefined)) as typeof atom
65
+ this.mutableAtom = ((options: Parameters<typeof mutableAtom>[0]) =>
66
+ createMutableAtom(s, options, undefined)) as typeof mutableAtom
61
67
  this.atomFamily = ((options: Parameters<typeof atomFamily>[0]) =>
62
- createAtomFamily(s, options)) as typeof atomFamily
68
+ createRegularAtomFamily(s, options)) as typeof atomFamily
69
+ this.mutableAtomFamily = ((
70
+ options: Parameters<typeof mutableAtomFamily>[0],
71
+ ) => createMutableAtomFamily(s, options)) as typeof mutableAtomFamily
63
72
  this.selector = ((options: Parameters<typeof selector>[0]) =>
64
73
  createStandaloneSelector(s, options)) as typeof selector
65
74
  this.selectorFamily = ((options: Parameters<typeof selectorFamily>[0]) =>
@@ -11,9 +11,7 @@ import type {
11
11
  TransactionUpdate,
12
12
  } from "."
13
13
 
14
- /** @public */
15
14
  export type StateUpdate<T> = { newValue: T; oldValue: T }
16
- /** @public */
17
15
  export type KeyedStateUpdate<T> = Flat<
18
16
  StateUpdate<T> & {
19
17
  key: string
@@ -21,15 +19,12 @@ export type KeyedStateUpdate<T> = Flat<
21
19
  family?: FamilyMetadata
22
20
  }
23
21
  >
24
- /** @public */
25
22
  export type UpdateHandler<T> = (update: StateUpdate<T>) => void
26
- /** @public */
27
23
  export type TransactionUpdateHandler<F extends Func> = (
28
24
  data: TransactionUpdate<F>,
29
25
  ) => void
30
26
 
31
27
  /**
32
- * @public
33
28
  * Subscribe to a state in the implicit store
34
29
  * @param token - The token of the state to subscribe to
35
30
  * @param handleUpdate - A function that will be called when the state is updated
@@ -43,7 +38,6 @@ export function subscribe<T>(
43
38
  key?: string,
44
39
  ): () => void
45
40
  /**
46
- * @public
47
41
  * Subscribe to a transaction in the implicit store
48
42
  * @param token - The token of the transaction to subscribe to
49
43
  * @param handleUpdate - A function that will be called when the transaction succeeds
@@ -57,7 +51,6 @@ export function subscribe<F extends Func>(
57
51
  key?: string,
58
52
  ): () => void
59
53
  /**
60
- * @public
61
54
  * Subscribe to a timeline in the implicit store
62
55
  * @param token - The token of the timeline to subscribe to
63
56
  * @param handleUpdate - A function that will be called when a new update is available
@@ -10,11 +10,9 @@ import type {
10
10
  } from "atom.io/internal"
11
11
  import { createTimeline, IMPLICIT, timeTravel } from "atom.io/internal"
12
12
 
13
- import type { AtomFamilyToken, AtomToken } from "."
13
+ import type { AtomFamilyToken, AtomToken, TimelineToken } from "."
14
14
 
15
- /** @public */
16
15
  export type TimelineManageable = AtomFamilyToken<any, any> | AtomToken<any>
17
- /** @public */
18
16
  export type AtomOnly<M extends TimelineManageable> = M extends AtomFamilyToken<
19
17
  any,
20
18
  any
@@ -24,17 +22,30 @@ export type AtomOnly<M extends TimelineManageable> = M extends AtomFamilyToken<
24
22
  ? M
25
23
  : never
26
24
 
27
- /** @public */
28
- export type TimelineToken<M> = {
29
- /** The unique identifier of the timeline */
30
- key: string
31
- /** Discriminator */
32
- type: `timeline`
33
- /** Never present. This is a marker that preserves the type of the managed atoms */
34
- __M?: M
25
+ /**
26
+ * If there is an update ahead of the cursor (in the future of this {@link timeline}), apply it and move the cursor to the next update
27
+ * @param timeline - A {@link TimelineToken}
28
+ */
29
+ export const redo = (timeline: TimelineToken<any>): void => {
30
+ timeTravel(IMPLICIT.STORE, `redo`, timeline)
31
+ }
32
+ /**
33
+ * Reverse the last update on the {@link timeline} and move the cursor to the previous update
34
+ * @param timeline - A {@link TimelineToken}
35
+ */
36
+ export const undo = (timeline: TimelineToken<any>): void => {
37
+ timeTravel(IMPLICIT.STORE, `undo`, timeline)
35
38
  }
36
39
 
37
- /** @public */
40
+ export type TimelineUpdate<ManagedAtom extends TimelineManageable> =
41
+ | TimelineAtomUpdate<ManagedAtom>
42
+ | TimelineMoleculeCreation
43
+ | TimelineMoleculeDisposal
44
+ | TimelineSelectorUpdate<ManagedAtom>
45
+ | TimelineStateCreation<AtomOnly<ManagedAtom>>
46
+ | TimelineStateDisposal<AtomOnly<ManagedAtom>>
47
+ | TimelineTransactionUpdate
48
+
38
49
  export type TimelineOptions<ManagedAtom extends TimelineManageable> = {
39
50
  /** The unique identifier of the timeline */
40
51
  key: string
@@ -47,19 +58,8 @@ export type TimelineOptions<ManagedAtom extends TimelineManageable> = {
47
58
  ) => boolean
48
59
  }
49
60
 
50
- /** @public */
51
- export type TimelineUpdate<ManagedAtom extends TimelineManageable> =
52
- | TimelineAtomUpdate<ManagedAtom>
53
- | TimelineMoleculeCreation
54
- | TimelineMoleculeDisposal
55
- | TimelineSelectorUpdate<ManagedAtom>
56
- | TimelineStateCreation<AtomOnly<ManagedAtom>>
57
- | TimelineStateDisposal<AtomOnly<ManagedAtom>>
58
- | TimelineTransactionUpdate
59
-
60
61
  /**
61
- * @public
62
- * Create a timeline, a mechanism for recording, undoing, and replaying changes to groups of atoms.
62
+ * Create a timeline, a mechanism for recording, undoing, and replaying changes to groups of atoms
63
63
  * @param options - {@link TimelineOptions}
64
64
  * @returns A reference to the timeline created: a {@link TimelineToken}
65
65
  */
@@ -68,11 +68,3 @@ export const timeline = <ManagedAtom extends TimelineManageable>(
68
68
  ): TimelineToken<ManagedAtom> => {
69
69
  return createTimeline(IMPLICIT.STORE, options)
70
70
  }
71
-
72
- export const redo = (tl: TimelineToken<any>): void => {
73
- timeTravel(IMPLICIT.STORE, `redo`, tl)
74
- }
75
-
76
- export const undo = (tl: TimelineToken<any>): void => {
77
- timeTravel(IMPLICIT.STORE, `undo`, tl)
78
- }
@@ -0,0 +1,247 @@
1
+ import type { Func, Transceiver } from "atom.io/internal"
2
+ import type { Canonical, Json, stringified } from "atom.io/json"
3
+
4
+ /**
5
+ * A token is an object that uniquely identifies a particular state, family, timeline, or transaction.
6
+ *
7
+ * While they represent one of these resources, they are not the resource itself. Think of them like paper currency representing money in the bank.
8
+ *
9
+ * Tokens are returned from resource creation functions, such as {@link atom} and {@link transaction}.
10
+ *
11
+ * Tokens can be used as parameters to functions that take a token, such as {@link getState}, {@link setState}, or {@link runTransaction}.
12
+ *
13
+ * Tokens are fully serializable, so they can be passed between processes.
14
+ */
15
+ export type AtomIOToken =
16
+ | ReadableFamilyToken<any, any>
17
+ | ReadableToken<any>
18
+ | TimelineToken<any>
19
+ | TransactionToken<any>
20
+
21
+ /**
22
+ * These states cannot be set.
23
+ */
24
+ export type ReadableToken<T, K extends Canonical = any> =
25
+ | AtomToken<T, K>
26
+ | SelectorToken<T, K>
27
+ /**
28
+ * These states can be set.
29
+ */
30
+ export type WritableToken<T, K extends Canonical = any> =
31
+ | AtomToken<T, K>
32
+ | WritableSelectorToken<T, K>
33
+
34
+ /**
35
+ * States belonging to this family can be gotten from the store.
36
+ */
37
+ export type ReadableFamilyToken<T, K extends Canonical> =
38
+ | AtomFamilyToken<T, K>
39
+ | SelectorFamilyToken<T, K>
40
+ /**
41
+ * States belonging to this family can be set.
42
+ */
43
+ export type WritableFamilyToken<T, K extends Canonical> =
44
+ | AtomFamilyToken<T, K>
45
+ | WritableSelectorFamilyToken<T, K>
46
+
47
+ export type TimelineToken<M> = {
48
+ /** The unique identifier of the timeline */
49
+ key: string
50
+ /** Discriminator */
51
+ type: `timeline`
52
+ /** Never present. This is a marker that preserves the type of the managed atoms */
53
+ __M?: M
54
+ }
55
+
56
+ export type TransactionToken<F extends Func> = {
57
+ /** The unique identifier of the transaction */
58
+ key: string
59
+ /** Discriminator */
60
+ type: `transaction`
61
+ /** Never present. This is a marker that preserves the type of the transaction function */
62
+ __F?: F
63
+ }
64
+
65
+ export type AtomToken<T, K extends Canonical = any> =
66
+ | MutableAtomToken<T extends Transceiver<any> ? T : never, any, K>
67
+ | RegularAtomToken<T, K>
68
+ export type RegularAtomToken<T, K extends Canonical = any> = {
69
+ /** The unique identifier of the atom. */
70
+ key: string
71
+ /** Discriminator. */
72
+ type: `atom`
73
+ /** Present if the atom belongs to a family. */
74
+ family?: FamilyMetadata<K>
75
+ /** Never present. This is a marker that preserves the type of the atom's value. */
76
+ __T?: T
77
+ }
78
+ export type MutableAtomToken<
79
+ T extends Transceiver<any>,
80
+ J extends Json.Serializable,
81
+ K extends Canonical = any,
82
+ > = {
83
+ /** The unique identifier of the atom. */
84
+ key: string
85
+ /** Discriminator. */
86
+ type: `mutable_atom`
87
+ /** Present if the atom belongs to a family. */
88
+ family?: FamilyMetadata<K>
89
+ /** Never present. This is a marker that preserves the JSON form of the atom's transceiver value. */
90
+ __J?: J
91
+ /** 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
93
+ }
94
+
95
+ export type SelectorToken<T, K extends Canonical = any> =
96
+ | ReadonlySelectorToken<T, K>
97
+ | WritableSelectorToken<T, K>
98
+ export type ReadonlySelectorToken<T, K extends Canonical = any> =
99
+ | ReadonlyHeldSelectorToken<T, K>
100
+ | ReadonlyPureSelectorToken<T, K>
101
+ export type WritableSelectorToken<T, K extends Canonical = any> =
102
+ | WritableHeldSelectorToken<T, K>
103
+ | WritablePureSelectorToken<T, K>
104
+ export type PureSelectorToken<T, K extends Canonical = any> =
105
+ | ReadonlyPureSelectorToken<T, K>
106
+ | WritablePureSelectorToken<T, K>
107
+ export type HeldSelectorToken<T, K extends Canonical = any> =
108
+ | ReadonlyHeldSelectorToken<T, K>
109
+ | WritableHeldSelectorToken<T, K>
110
+
111
+ export type WritablePureSelectorToken<T, K extends Canonical = any> = {
112
+ /** The unique identifier of the selector. */
113
+ key: string
114
+ /** Discriminator. */
115
+ type: `writable_pure_selector`
116
+ /** Present if the selector belongs to a family. */
117
+ family?: FamilyMetadata<K>
118
+ /** Never present. This is a marker that preserves the type of the selector's value. */
119
+ __T?: T
120
+ }
121
+ export type WritableHeldSelectorToken<T, K extends Canonical = any> = {
122
+ /** The unique identifier of the selector. */
123
+ key: string
124
+ /** Discriminator. */
125
+ type: `writable_held_selector`
126
+ /** Present if the selector belongs to a family. */
127
+ family?: FamilyMetadata<K>
128
+ /** Never present. This is a marker that preserves the type of the selector's value. */
129
+ __T?: T
130
+ }
131
+ export type ReadonlyPureSelectorToken<T, K extends Canonical = any> = {
132
+ /** The unique identifier of the selector. */
133
+ key: string
134
+ /** Discriminator. */
135
+ type: `readonly_pure_selector`
136
+ /** Present if the selector belongs to a family. */
137
+ family?: FamilyMetadata<K>
138
+ /** Never present. This is a marker that preserves the type of the selector's value. */
139
+ __T?: T
140
+ }
141
+ export type ReadonlyHeldSelectorToken<T, K extends Canonical = any> = {
142
+ /** The unique identifier of the selector. */
143
+ key: string
144
+ /** Discriminator. */
145
+ type: `readonly_held_selector`
146
+ /** Present if the selector belongs to a family. */
147
+ family?: FamilyMetadata<K>
148
+ /** Never present. This is a marker that preserves the type of the selector's value. */
149
+ __T?: T
150
+ }
151
+
152
+ /**
153
+ * Identifies a state's connection to its family.
154
+ */
155
+ export type FamilyMetadata<K extends Canonical = any> = {
156
+ /** The family's unique key. */
157
+ key: string
158
+ /** The family member's unique identifier, in the form of a string. */
159
+ subKey: stringified<K>
160
+ }
161
+
162
+ export type AtomFamilyToken<T, K extends Canonical = Canonical> =
163
+ | MutableAtomFamilyToken<T extends Transceiver<any> ? T : never, any, K>
164
+ | RegularAtomFamilyToken<T, K>
165
+ export type RegularAtomFamilyToken<T, K extends Canonical> = {
166
+ /** The unique identifier of the atom family */
167
+ key: string
168
+ /** Discriminator */
169
+ type: `atom_family`
170
+ /** Never present. This is a marker that preserves the type of atoms in this family */
171
+ __T?: T
172
+ /** Never present. This is a marker that preserves the type of keys used for atoms in this family */
173
+ __K?: K
174
+ }
175
+ export type MutableAtomFamilyToken<
176
+ T extends Transceiver<any>,
177
+ J extends Json.Serializable,
178
+ K extends Canonical,
179
+ > = {
180
+ /** The unique identifier of the atom family */
181
+ key: string
182
+ /** Discriminator */
183
+ type: `mutable_atom_family`
184
+ /** Never present. This is a marker that preserves the type of atoms in this family */
185
+ __T?: T
186
+ /** Never present. This is a marker that preserves the type of the JSON form of atoms in this family */
187
+ __J?: J
188
+ /** Never present. This is a marker that preserves the type of keys used for atoms in this family */
189
+ __K?: K
190
+ }
191
+
192
+ export type SelectorFamilyToken<T, K extends Canonical> =
193
+ | ReadonlySelectorFamilyToken<T, K>
194
+ | WritableSelectorFamilyToken<T, K>
195
+ export type ReadonlySelectorFamilyToken<T, K extends Canonical> =
196
+ | ReadonlyHeldSelectorFamilyToken<T, K>
197
+ | ReadonlyPureSelectorFamilyToken<T, K>
198
+ export type WritableSelectorFamilyToken<T, K extends Canonical> =
199
+ | WritableHeldSelectorFamilyToken<T, K>
200
+ | WritablePureSelectorFamilyToken<T, K>
201
+ export type PureSelectorFamilyToken<T, K extends Canonical> =
202
+ | ReadonlyPureSelectorFamilyToken<T, K>
203
+ | WritablePureSelectorFamilyToken<T, K>
204
+ export type HeldSelectorFamilyToken<T, K extends Canonical> =
205
+ | ReadonlyHeldSelectorFamilyToken<T, K>
206
+ | WritableHeldSelectorFamilyToken<T, K>
207
+
208
+ export type WritablePureSelectorFamilyToken<T, K extends Canonical> = {
209
+ /** The unique identifier of the family */
210
+ key: string
211
+ /** Discriminator */
212
+ type: `writable_pure_selector_family`
213
+ /** Never present. This is a marker that preserves the type of the value of each family member */
214
+ __T?: T
215
+ /** Never present. This is a marker that preserves the type of keys used for each family member */
216
+ __K?: K
217
+ }
218
+ export type ReadonlyPureSelectorFamilyToken<T, K extends Canonical> = {
219
+ /** The unique identifier of the family */
220
+ key: string
221
+ /** Discriminator */
222
+ type: `readonly_pure_selector_family`
223
+ /** Never present. This is a marker that preserves the type of the value of each family member */
224
+ __T?: T
225
+ /** Never present. This is a marker that preserves the type of keys used for each family member */
226
+ __K?: K
227
+ }
228
+ export type WritableHeldSelectorFamilyToken<T, K extends Canonical> = {
229
+ /** The unique identifier of the family */
230
+ key: string
231
+ /** Discriminator */
232
+ type: `writable_held_selector_family`
233
+ /** Never present. This is a marker that preserves the type of the value of each family member */
234
+ __T?: T
235
+ /** Never present. This is a marker that preserves the type of keys used for each family member */
236
+ __K?: K
237
+ }
238
+ export type ReadonlyHeldSelectorFamilyToken<T, K extends Canonical> = {
239
+ /** The unique identifier of the family */
240
+ key: string
241
+ /** Discriminator */
242
+ type: `readonly_held_selector_family`
243
+ /** Never present. This is a marker that preserves the type of the value of each family member */
244
+ __T?: T
245
+ /** Never present. This is a marker that preserves the type of keys used for each family member */
246
+ __K?: K
247
+ }