atom.io 0.40.1 → 0.40.3

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 (98) hide show
  1. package/dist/data/index.d.ts +1 -1
  2. package/dist/data/index.d.ts.map +1 -1
  3. package/dist/data/index.js.map +1 -1
  4. package/dist/internal/index.d.ts +155 -144
  5. package/dist/internal/index.d.ts.map +1 -1
  6. package/dist/internal/index.js +91 -39
  7. package/dist/internal/index.js.map +1 -1
  8. package/dist/introspection/index.d.ts +4 -4
  9. package/dist/introspection/index.d.ts.map +1 -1
  10. package/dist/introspection/index.js.map +1 -1
  11. package/dist/main/index.d.ts +80 -56
  12. package/dist/main/index.d.ts.map +1 -1
  13. package/dist/main/index.js.map +1 -1
  14. package/dist/react/index.d.ts +11 -11
  15. package/dist/react/index.d.ts.map +1 -1
  16. package/dist/react/index.js.map +1 -1
  17. package/dist/react-devtools/index.d.ts.map +1 -1
  18. package/dist/react-devtools/index.js.map +1 -1
  19. package/package.json +1 -1
  20. package/src/data/struct.ts +2 -2
  21. package/src/internal/atom/create-regular-atom.ts +8 -7
  22. package/src/internal/atom/dispose-atom.ts +6 -3
  23. package/src/internal/atom/has-role.ts +1 -1
  24. package/src/internal/caching.ts +15 -15
  25. package/src/internal/events/ingest-creation-disposal.ts +1 -1
  26. package/src/internal/families/create-readonly-held-selector-family.ts +6 -7
  27. package/src/internal/families/create-readonly-pure-selector-family.ts +23 -17
  28. package/src/internal/families/create-regular-atom-family.ts +17 -15
  29. package/src/internal/families/create-selector-family.ts +9 -9
  30. package/src/internal/families/create-writable-held-selector-family.ts +6 -7
  31. package/src/internal/families/create-writable-pure-selector-family.ts +24 -18
  32. package/src/internal/families/dispose-from-store.ts +10 -7
  33. package/src/internal/families/find-in-store.ts +23 -23
  34. package/src/internal/families/get-family-of-token.ts +17 -17
  35. package/src/internal/families/mint-in-store.ts +11 -11
  36. package/src/internal/families/seek-in-store.ts +26 -26
  37. package/src/internal/get-state/get-fallback.ts +8 -8
  38. package/src/internal/get-state/get-from-store.ts +17 -12
  39. package/src/internal/get-state/read-or-compute-value.ts +78 -14
  40. package/src/internal/get-state/reduce-reference.ts +10 -10
  41. package/src/internal/index.ts +58 -53
  42. package/src/internal/join/join-internal.ts +15 -6
  43. package/src/internal/mutable/create-mutable-atom-family.ts +7 -8
  44. package/src/internal/mutable/get-json-family.ts +3 -2
  45. package/src/internal/mutable/get-update-family.ts +7 -5
  46. package/src/internal/mutable/tracker-family.ts +5 -1
  47. package/src/internal/mutable/tracker.ts +5 -1
  48. package/src/internal/operation.ts +4 -2
  49. package/src/internal/selector/create-readonly-pure-selector.ts +8 -6
  50. package/src/internal/selector/create-standalone-selector.ts +10 -10
  51. package/src/internal/selector/create-writable-pure-selector.ts +9 -7
  52. package/src/internal/selector/dispose-selector.ts +2 -2
  53. package/src/internal/selector/register-selector.ts +2 -2
  54. package/src/internal/selector/trace-selector-atoms.ts +3 -3
  55. package/src/internal/selector/update-selector-atoms.ts +1 -1
  56. package/src/internal/set-state/dispatch-state-update.ts +9 -5
  57. package/src/internal/set-state/evict-downstream.ts +4 -1
  58. package/src/internal/set-state/operate-on-store.ts +16 -10
  59. package/src/internal/set-state/reset-atom-or-selector.ts +7 -7
  60. package/src/internal/set-state/reset-in-store.ts +9 -6
  61. package/src/internal/set-state/set-atom-or-selector.ts +1 -1
  62. package/src/internal/set-state/set-atom.ts +1 -1
  63. package/src/internal/set-state/set-into-store.ts +10 -7
  64. package/src/internal/set-state/set-selector.ts +1 -1
  65. package/src/internal/store/deposit.ts +38 -30
  66. package/src/internal/store/mint-or-counterfeit.ts +23 -23
  67. package/src/internal/store/store.ts +9 -9
  68. package/src/internal/store/withdraw.ts +68 -62
  69. package/src/internal/subscribe/recall-state.ts +4 -1
  70. package/src/internal/subscribe/subscribe-to-root-atoms.ts +2 -2
  71. package/src/internal/subscribe/subscribe-to-state.ts +4 -4
  72. package/src/internal/timeline/create-timeline.ts +5 -5
  73. package/src/internal/utility-types.ts +2 -0
  74. package/src/introspection/attach-atom-index.ts +2 -2
  75. package/src/introspection/attach-selector-index.ts +4 -2
  76. package/src/introspection/attach-timeline-family.ts +13 -11
  77. package/src/introspection/attach-timeline-index.ts +1 -1
  78. package/src/introspection/attach-transaction-index.ts +1 -1
  79. package/src/introspection/attach-transaction-logs.ts +4 -2
  80. package/src/introspection/attach-type-selectors.ts +2 -1
  81. package/src/introspection/index.ts +3 -5
  82. package/src/main/atom.ts +15 -9
  83. package/src/main/events.ts +25 -23
  84. package/src/main/get-state.ts +10 -8
  85. package/src/main/reset-state.ts +4 -4
  86. package/src/main/selector.ts +41 -24
  87. package/src/main/set-state.ts +8 -4
  88. package/src/main/timeline.ts +5 -3
  89. package/src/main/tokens.ts +72 -44
  90. package/src/main/validators.ts +4 -4
  91. package/src/react/parse-state-overloads.ts +10 -10
  92. package/src/react/use-i.ts +6 -6
  93. package/src/react/use-loadable.ts +15 -15
  94. package/src/react/use-o.ts +9 -9
  95. package/src/react-devtools/StateEditor.tsx +5 -3
  96. package/src/react-devtools/StateIndex.tsx +6 -4
  97. package/src/react-devtools/Updates.tsx +1 -1
  98. package/src/react-devtools/store.ts +16 -7
package/src/main/atom.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ConstructorOf, Transceiver } from "atom.io/internal"
1
+ import type { ConstructorOf, Ctor, Transceiver } from "atom.io/internal"
2
2
  import {
3
3
  createMutableAtom,
4
4
  createMutableAtomFamily,
@@ -17,13 +17,15 @@ import type {
17
17
  RegularAtomToken,
18
18
  } from "./tokens"
19
19
 
20
- export type RegularAtomOptions<T> = {
20
+ export type RegularAtomOptions<T, E = never> = {
21
21
  /** The unique identifier of the atom */
22
22
  key: string
23
23
  /** The starting value of the atom */
24
24
  default: T | (() => T)
25
25
  /** Hooks used to run side effects when the atom is set */
26
- effects?: AtomEffect<T>[]
26
+ effects?: readonly AtomEffect<T>[]
27
+ /** The classes of errors that might be thrown when deriving the atom's default value */
28
+ catch?: readonly Ctor<E>[]
27
29
  }
28
30
  /**
29
31
  * Create a regular atom, a global reactive variable in the implicit store
@@ -31,7 +33,9 @@ export type RegularAtomOptions<T> = {
31
33
  * @returns
32
34
  * A reference to the atom created: a {@link RegularAtomToken}
33
35
  */
34
- export function atom<T>(options: RegularAtomOptions<T>): RegularAtomToken<T> {
36
+ export function atom<T, E = never>(
37
+ options: RegularAtomOptions<T, E>,
38
+ ): RegularAtomToken<T, any, E> {
35
39
  return createRegularAtom(IMPLICIT.STORE, options, undefined)
36
40
  }
37
41
 
@@ -41,7 +45,7 @@ export type MutableAtomOptions<T extends Transceiver<any, any, any>> = {
41
45
  /** A constructor for the atom's value */
42
46
  class: ConstructorOf<T>
43
47
  /** Hooks used to run side effects when the atom is set */
44
- effects?: AtomEffect<T>[]
48
+ effects?: readonly AtomEffect<T>[]
45
49
  }
46
50
  /**
47
51
  * Create a mutable atom, a global reactive variable in the implicit store
@@ -79,13 +83,15 @@ export type Effectors<T> = {
79
83
  onSet: (callback: (options: StateUpdate<T>) => void) => void
80
84
  }
81
85
 
82
- export type RegularAtomFamilyOptions<T, K extends Canonical> = {
86
+ export type RegularAtomFamilyOptions<T, K extends Canonical, E = never> = {
83
87
  /** The unique identifier of the atom family */
84
88
  key: string
85
89
  /** The starting value of the atom family */
86
90
  default: T | ((key: K) => T)
87
91
  /** Hooks used to run side effects when an atom in the family is set */
88
92
  effects?: (key: K) => AtomEffect<T>[]
93
+ /** The classes of errors that might be thrown when deriving the atom's default value */
94
+ catch?: readonly Ctor<E>[]
89
95
  }
90
96
  /**
91
97
  * Create a family of regular atoms, allowing for the dynamic creation and disposal of atoms.
@@ -93,9 +99,9 @@ export type RegularAtomFamilyOptions<T, K extends Canonical> = {
93
99
  * @returns
94
100
  * A reference to the atom family created: a {@link RegularAtomFamilyToken}
95
101
  */
96
- export function atomFamily<T, K extends Canonical>(
97
- options: RegularAtomFamilyOptions<T, K>,
98
- ): RegularAtomFamilyToken<T, K> {
102
+ export function atomFamily<T, K extends Canonical, E = never>(
103
+ options: RegularAtomFamilyOptions<T, K, E>,
104
+ ): RegularAtomFamilyToken<T, K, E> {
99
105
  return createRegularAtomFamily(IMPLICIT.STORE, options)
100
106
  }
101
107
 
@@ -16,14 +16,14 @@ export type StateUpdate<T> = {
16
16
  readonly newValue: ViewOf<T>
17
17
  }
18
18
 
19
- export type AtomUpdateEvent<A extends AtomToken<any>> = {
19
+ export type AtomUpdateEvent<A extends AtomToken<any, any, any>> = {
20
20
  type: `atom_update`
21
21
  token: A
22
22
  update: StateUpdate<TokenType<A>>
23
23
  timestamp: number
24
24
  }
25
25
 
26
- export type SelectorUpdateSubEvent<A extends AtomToken<any>> =
26
+ export type SelectorUpdateSubEvent<A extends AtomToken<any, any, any>> =
27
27
  | AtomUpdateEvent<A>
28
28
  | StateCreationEvent<any>
29
29
  export type TimelineSelectorUpdateEvent<A extends TimelineManageable> = {
@@ -33,36 +33,38 @@ export type TimelineSelectorUpdateEvent<A extends TimelineManageable> = {
33
33
  timestamp: number
34
34
  }
35
35
 
36
- export type StateLifecycleEvent<R extends ReadableToken<any>> =
36
+ export type StateLifecycleEvent<R extends ReadableToken<any, any, any>> =
37
37
  | StateCreationEvent<R>
38
38
  | StateDisposalEvent<R>
39
- export type StateCreationEvent<R extends ReadableToken<any>> =
39
+ export type StateCreationEvent<R extends ReadableToken<any, any, any>> =
40
40
  | ReadableStateCreationEvent<R>
41
41
  | (R extends WritableToken<any> ? WritableStateCreationEvent<R> : never)
42
- export type ReadableStateCreationEvent<R extends ReadableToken<any>> = {
43
- type: `state_creation`
44
- subType: `readable`
45
- token: R
46
- timestamp: number
47
- }
48
- export type WritableStateCreationEvent<W extends WritableToken<any>> = {
49
- type: `state_creation`
50
- subType: `writable`
51
- token: W
52
- timestamp: number
53
- value?: TokenType<W>
54
- }
55
- export type StateDisposalEvent<R extends ReadableToken<any>> =
42
+ export type ReadableStateCreationEvent<R extends ReadableToken<any, any, any>> =
43
+ {
44
+ type: `state_creation`
45
+ subType: `readable`
46
+ token: R
47
+ timestamp: number
48
+ }
49
+ export type WritableStateCreationEvent<W extends WritableToken<any, any, any>> =
50
+ {
51
+ type: `state_creation`
52
+ subType: `writable`
53
+ token: W
54
+ timestamp: number
55
+ value?: TokenType<W>
56
+ }
57
+ export type StateDisposalEvent<R extends ReadableToken<any, any, any>> =
56
58
  | AtomDisposalEvent<R>
57
59
  | SelectorDisposalEvent<R>
58
- export type AtomDisposalEvent<R extends ReadableToken<any>> = {
60
+ export type AtomDisposalEvent<R extends ReadableToken<any, any, any>> = {
59
61
  type: `state_disposal`
60
62
  subType: `atom`
61
63
  token: R
62
64
  value: TokenType<R>
63
65
  timestamp: number
64
66
  }
65
- export type SelectorDisposalEvent<R extends ReadableToken<any>> = {
67
+ export type SelectorDisposalEvent<R extends ReadableToken<any, any, any>> = {
66
68
  type: `state_disposal`
67
69
  subType: `selector`
68
70
  token: R
@@ -94,12 +96,12 @@ export type MoleculeTransferEvent = {
94
96
  }
95
97
 
96
98
  export type TransactionSubEvent =
97
- | AtomUpdateEvent<AtomToken<any>>
99
+ | AtomUpdateEvent<AtomToken<any, any, any>>
98
100
  | MoleculeCreationEvent
99
101
  | MoleculeDisposalEvent
100
102
  | MoleculeTransferEvent
101
- | StateCreationEvent<ReadableToken<unknown>>
102
- | StateDisposalEvent<ReadableToken<unknown>>
103
+ | StateCreationEvent<ReadableToken<unknown, any, any>>
104
+ | StateDisposalEvent<ReadableToken<unknown, any, any>>
103
105
  | TransactionOutcomeEvent<TransactionToken<any>>
104
106
 
105
107
  export type TransactionOutcomeEvent<T extends TransactionToken<any>> = {
@@ -11,7 +11,9 @@ import type { ReadableFamilyToken, ReadableToken } from "."
11
11
  * @overload Default
12
12
  * @default
13
13
  */
14
- export function getState<T>(token: ReadableToken<T>): ViewOf<T>
14
+ export function getState<T, E = never>(
15
+ token: ReadableToken<T, any, E>,
16
+ ): ViewOf<E | T>
15
17
 
16
18
  /**
17
19
  * Read or compute the current value of a state
@@ -20,15 +22,15 @@ export function getState<T>(token: ReadableToken<T>): ViewOf<T>
20
22
  * @return The current value of the state
21
23
  * @overload Streamlined
22
24
  */
23
- export function getState<T, K extends Canonical, Key extends K>(
24
- token: ReadableFamilyToken<T, K>,
25
+ export function getState<T, K extends Canonical, Key extends K, E = never>(
26
+ token: ReadableFamilyToken<T, K, E>,
25
27
  key: Key,
26
- ): ViewOf<T>
28
+ ): ViewOf<E | T>
27
29
 
28
- export function getState<T, K extends Canonical, Key extends K>(
30
+ export function getState<T, K extends Canonical, Key extends K, E = never>(
29
31
  ...params:
30
- | [token: ReadableFamilyToken<T, K>, key: Key]
31
- | [token: ReadableToken<T>]
32
- ): any {
32
+ | [token: ReadableFamilyToken<T, K, E>, key: Key]
33
+ | [token: ReadableToken<T, any, E>]
34
+ ): ViewOf<E | T> {
33
35
  return getFromStore(IMPLICIT.STORE, ...params)
34
36
  }
@@ -9,7 +9,7 @@ import type { WritableFamilyToken, WritableToken } from "."
9
9
  * @overload Default
10
10
  * @default
11
11
  */
12
- export function resetState(token: WritableToken<any>): void
12
+ export function resetState(token: WritableToken<any, any, any>): void
13
13
  /**
14
14
  * Set the value of a state into the implicit store back to its default value.
15
15
  * @param token - An atom family or writable selector family token.
@@ -17,13 +17,13 @@ export function resetState(token: WritableToken<any>): void
17
17
  * @overload Streamlined
18
18
  */
19
19
  export function resetState<K extends Canonical>(
20
- token: WritableFamilyToken<any, K>,
20
+ token: WritableFamilyToken<any, K, any>,
21
21
  key: K,
22
22
  ): void
23
23
  export function resetState(
24
24
  ...params:
25
- | [token: WritableFamilyToken<any, Canonical>, key: Canonical]
26
- | [token: WritableToken<any>]
25
+ | [token: WritableFamilyToken<any, Canonical, any>, key: Canonical]
26
+ | [token: WritableToken<any, any, any>]
27
27
  ): void {
28
28
  resetInStore(IMPLICIT.STORE, ...params)
29
29
  }
@@ -1,3 +1,4 @@
1
+ import type { Ctor } from "atom.io/internal"
1
2
  import {
2
3
  createSelectorFamily,
3
4
  createStandaloneSelector,
@@ -17,19 +18,23 @@ import type {
17
18
  } from "./tokens"
18
19
  import type { Read, Write } from "./transaction"
19
20
 
20
- export type WritablePureSelectorOptions<T> = {
21
+ export type WritablePureSelectorOptions<T, E = never> = {
21
22
  /** The unique identifier of the selector */
22
23
  key: string
23
24
  /** For each instantiated selector, a function that computes its value */
24
25
  get: Read<() => T>
25
26
  /** For each instantiated selector, a function that sets its value */
26
27
  set: Write<(newValue: T) => void>
28
+ /** The classes of errors that might be thrown when deriving the atom's default value */
29
+ catch?: readonly Ctor<E>[]
27
30
  }
28
- export type ReadonlyPureSelectorOptions<T> = {
31
+ export type ReadonlyPureSelectorOptions<T, E = never> = {
29
32
  /** The unique identifier of the selector */
30
33
  key: string
31
34
  /** For each instantiated selector, a function that computes its value */
32
35
  get: Read<() => T>
36
+ /** The classes of errors that might be thrown when deriving the atom's default value */
37
+ catch?: readonly Ctor<E>[]
33
38
  }
34
39
  export type ReadonlyHeldSelectorOptions<T extends object> = {
35
40
  /** The unique identifier of the selector */
@@ -104,9 +109,9 @@ export function selector<T extends object>(
104
109
  * The token for your selector.
105
110
  * @overload WritablePure
106
111
  */
107
- export function selector<T>(
108
- options: WritablePureSelectorOptions<T>,
109
- ): WritablePureSelectorToken<T>
112
+ export function selector<T, E = never>(
113
+ options: WritablePureSelectorOptions<T, E>,
114
+ ): WritablePureSelectorToken<T, any, E>
110
115
  /**
111
116
  * Declare a selector. The value of a selector should depend
112
117
  * on the value of atoms or other selectors in the store.
@@ -121,36 +126,48 @@ export function selector<T>(
121
126
  * The token for your selector.
122
127
  * @overload ReadonlyPure
123
128
  */
124
- export function selector<T>(
125
- options: ReadonlyPureSelectorOptions<T>,
126
- ): ReadonlyPureSelectorToken<T>
129
+ export function selector<T, E = never>(
130
+ options: ReadonlyPureSelectorOptions<T, E>,
131
+ ): ReadonlyPureSelectorToken<T, any, E>
127
132
  export function selector(
128
133
  options:
129
134
  | ReadonlyHeldSelectorOptions<any>
130
- | ReadonlyPureSelectorOptions<any>
135
+ | ReadonlyPureSelectorOptions<any, any>
131
136
  | WritableHeldSelectorOptions<any>
132
- | WritablePureSelectorOptions<any>,
137
+ | WritablePureSelectorOptions<any, any>,
133
138
  ):
134
139
  | ReadonlyHeldSelectorToken<any>
135
- | ReadonlyPureSelectorToken<any>
140
+ | ReadonlyPureSelectorToken<any, any, any>
136
141
  | WritableHeldSelectorToken<any>
137
- | WritablePureSelectorToken<any> {
142
+ | WritablePureSelectorToken<any, any, any> {
138
143
  return createStandaloneSelector(IMPLICIT.STORE, options)
139
144
  }
140
145
 
141
- export type WritablePureSelectorFamilyOptions<T, K extends Canonical> = {
146
+ export type WritablePureSelectorFamilyOptions<
147
+ T,
148
+ K extends Canonical,
149
+ E = never,
150
+ > = {
142
151
  /** The unique identifier of the family */
143
152
  key: string
144
153
  /** For each instantiated family member, a function that computes its value */
145
154
  get: (key: K) => Read<() => T>
146
155
  /** For each instantiated family member, a function that sets its value */
147
156
  set: (key: K) => Write<(newValue: T) => void>
157
+ /** The classes of errors that might be thrown when deriving the atom's default value */
158
+ catch?: readonly Ctor<E>[]
148
159
  }
149
- export type ReadonlyPureSelectorFamilyOptions<T, K extends Canonical> = {
160
+ export type ReadonlyPureSelectorFamilyOptions<
161
+ T,
162
+ K extends Canonical,
163
+ E = never,
164
+ > = {
150
165
  /** The unique identifier of the family */
151
166
  key: string
152
167
  /** For each instantiated family member, a function that computes its value */
153
168
  get: (key: K) => Read<() => T>
169
+ /** The classes of errors that might be thrown when deriving the atom's default value */
170
+ catch?: readonly Ctor<E>[]
154
171
  }
155
172
  export type WritableHeldSelectorFamilyOptions<
156
173
  T extends object,
@@ -234,9 +251,9 @@ export function selectorFamily<T extends object, K extends Canonical>(
234
251
  * A reference to the selector family created: a {@link TransientWritableSelectorFamilyToken}
235
252
  * @overload WritablePure
236
253
  */
237
- export function selectorFamily<T, K extends Canonical>(
238
- options: WritablePureSelectorFamilyOptions<T, K>,
239
- ): WritablePureSelectorFamilyToken<T, K>
254
+ export function selectorFamily<T, K extends Canonical, E = never>(
255
+ options: WritablePureSelectorFamilyOptions<T, K, E>,
256
+ ): WritablePureSelectorFamilyToken<T, K, E>
240
257
  /**
241
258
  * Create a family of selectors, allowing for the dynamic creation and disposal of selectors.
242
259
  *
@@ -252,19 +269,19 @@ export function selectorFamily<T, K extends Canonical>(
252
269
  * A reference to the selector family created: a {@link ReadonlyPureSelectorFamilyToken}
253
270
  * @overload ReadonlyPure
254
271
  */
255
- export function selectorFamily<T, K extends Canonical>(
256
- options: ReadonlyPureSelectorFamilyOptions<T, K>,
257
- ): ReadonlyPureSelectorFamilyToken<T, K>
272
+ export function selectorFamily<T, K extends Canonical, E = never>(
273
+ options: ReadonlyPureSelectorFamilyOptions<T, K, E>,
274
+ ): ReadonlyPureSelectorFamilyToken<T, K, E>
258
275
  export function selectorFamily(
259
276
  options:
260
277
  | ReadonlyHeldSelectorFamilyOptions<any, any>
261
- | ReadonlyPureSelectorFamilyOptions<any, any>
278
+ | ReadonlyPureSelectorFamilyOptions<any, any, any>
262
279
  | WritableHeldSelectorFamilyOptions<any, any>
263
- | WritablePureSelectorFamilyOptions<any, any>,
280
+ | WritablePureSelectorFamilyOptions<any, any, any>,
264
281
  ):
265
282
  | ReadonlyHeldSelectorFamilyToken<any, any>
266
- | ReadonlyPureSelectorFamilyToken<any, any>
283
+ | ReadonlyPureSelectorFamilyToken<any, any, any>
267
284
  | WritableHeldSelectorFamilyToken<any, any>
268
- | WritablePureSelectorFamilyToken<any, any> {
285
+ | WritablePureSelectorFamilyToken<any, any, any> {
269
286
  return createSelectorFamily(IMPLICIT.STORE, options)
270
287
  }
@@ -19,7 +19,7 @@ export type Setter<T, New extends T> = (oldValue: T) => New
19
19
  * @default
20
20
  */
21
21
  export function setState<T, New extends T>(
22
- token: WritableToken<T>,
22
+ token: WritableToken<T, any, any>,
23
23
  value: New | Setter<T, New>,
24
24
  ): void
25
25
 
@@ -31,15 +31,19 @@ export function setState<T, New extends T>(
31
31
  * @overload Streamlined
32
32
  */
33
33
  export function setState<T, K extends Canonical, New extends T, Key extends K>(
34
- token: WritableFamilyToken<T, K>,
34
+ token: WritableFamilyToken<T, K, any>,
35
35
  key: Key,
36
36
  value: New | Setter<T, New>,
37
37
  ): void
38
38
 
39
39
  export function setState<T, K extends Canonical, New extends T, Key extends K>(
40
40
  ...params:
41
- | [token: WritableFamilyToken<T, K>, key: Key, value: New | Setter<T, New>]
42
- | [token: WritableToken<T>, value: New | Setter<T, New>]
41
+ | [
42
+ token: WritableFamilyToken<T, K, any>,
43
+ key: Key,
44
+ value: New | Setter<T, New>,
45
+ ]
46
+ | [token: WritableToken<T, any, any>, value: New | Setter<T, New>]
43
47
  ): void {
44
48
  setIntoStore(IMPLICIT.STORE, ...params)
45
49
  }
@@ -2,13 +2,15 @@ import { createTimeline, IMPLICIT, timeTravel } from "atom.io/internal"
2
2
 
3
3
  import type { AtomFamilyToken, AtomToken, TimelineToken } from "."
4
4
 
5
- export type TimelineManageable = AtomFamilyToken<any, any> | AtomToken<any>
5
+ export type TimelineManageable =
6
+ | AtomFamilyToken<any, any, any>
7
+ | AtomToken<any, any, any>
6
8
  export type AtomOnly<M extends TimelineManageable> = M extends AtomFamilyToken<
7
9
  any,
8
10
  any
9
11
  >
10
- ? AtomToken<any>
11
- : M extends AtomToken<any>
12
+ ? AtomToken<any, any, any>
13
+ : M extends AtomToken<any, any, any>
12
14
  ? M
13
15
  : never
14
16
 
@@ -13,31 +13,31 @@ import type { Canonical, stringified } from "atom.io/json"
13
13
  * Tokens are fully serializable, so they can be passed between processes.
14
14
  */
15
15
  export type AtomIOToken =
16
- | ReadableFamilyToken<any, any>
17
- | ReadableToken<any>
16
+ | ReadableFamilyToken<any, any, any>
17
+ | ReadableToken<any, any, any>
18
18
  | TimelineToken<any>
19
19
  | TransactionToken<any>
20
20
 
21
- export type ReadableToken<T, K extends Canonical = any> =
22
- | AtomToken<T, K>
23
- | SelectorToken<T, K>
21
+ export type ReadableToken<T, K extends Canonical = any, E = never> =
22
+ | AtomToken<T, K, E>
23
+ | SelectorToken<T, K, E>
24
24
 
25
- export type WritableToken<T, K extends Canonical = any> =
26
- | AtomToken<T, K>
27
- | WritableSelectorToken<T, K>
25
+ export type WritableToken<T, K extends Canonical = any, E = never> =
26
+ | AtomToken<T, K, E>
27
+ | WritableSelectorToken<T, K, E>
28
28
 
29
29
  /**
30
30
  * States belonging to this family can be read from the store.
31
31
  */
32
- export type ReadableFamilyToken<T, K extends Canonical> =
33
- | AtomFamilyToken<T, K>
34
- | SelectorFamilyToken<T, K>
32
+ export type ReadableFamilyToken<T, K extends Canonical, E = never> =
33
+ | AtomFamilyToken<T, K, E>
34
+ | SelectorFamilyToken<T, K, E>
35
35
  /**
36
36
  * States belonging to this family can be written directly.
37
37
  */
38
- export type WritableFamilyToken<T, K extends Canonical> =
39
- | AtomFamilyToken<T, K>
40
- | WritableSelectorFamilyToken<T, K>
38
+ export type WritableFamilyToken<T, K extends Canonical, E = never> =
39
+ | AtomFamilyToken<T, K, E>
40
+ | WritableSelectorFamilyToken<T, K, E>
41
41
 
42
42
  export type TimelineToken<M> = {
43
43
  /** The unique identifier of the timeline */
@@ -57,10 +57,10 @@ export type TransactionToken<F extends Fn> = {
57
57
  __F?: F
58
58
  }
59
59
 
60
- export type AtomToken<T, K extends Canonical = any> =
60
+ export type AtomToken<T, K extends Canonical = any, E = never> =
61
61
  | MutableAtomToken<T extends Transceiver<any, any, any> ? T : never, K>
62
- | RegularAtomToken<T, K>
63
- export type RegularAtomToken<T, K extends Canonical = any> = {
62
+ | RegularAtomToken<T, K, E>
63
+ export type RegularAtomToken<T, K extends Canonical = any, E = never> = {
64
64
  /** The unique identifier of the atom. */
65
65
  key: string
66
66
  /** Discriminator. */
@@ -69,6 +69,8 @@ export type RegularAtomToken<T, K extends Canonical = any> = {
69
69
  family?: FamilyMetadata<K>
70
70
  /** Never present. This is a marker that preserves the type of the atom's value. */
71
71
  __T?: T
72
+ /** Never present. This is a marker that preserves the type of errors this atom is capable of catching and setting as its value. */
73
+ __E?: E
72
74
  }
73
75
  export type MutableAtomToken<
74
76
  T extends Transceiver<any, any, any>,
@@ -84,23 +86,27 @@ export type MutableAtomToken<
84
86
  __J?: AsJSON<T>
85
87
  }
86
88
 
87
- export type SelectorToken<T, K extends Canonical = any> =
88
- | ReadonlySelectorToken<T, K>
89
- | WritableSelectorToken<T, K>
90
- export type ReadonlySelectorToken<T, K extends Canonical = any> =
89
+ export type SelectorToken<T, K extends Canonical = any, E = never> =
90
+ | ReadonlySelectorToken<T, K, E>
91
+ | WritableSelectorToken<T, K, E>
92
+ export type ReadonlySelectorToken<T, K extends Canonical = any, E = never> =
91
93
  | ReadonlyHeldSelectorToken<T, K>
92
- | ReadonlyPureSelectorToken<T, K>
93
- export type WritableSelectorToken<T, K extends Canonical = any> =
94
+ | ReadonlyPureSelectorToken<T, K, E>
95
+ export type WritableSelectorToken<T, K extends Canonical = any, E = never> =
94
96
  | WritableHeldSelectorToken<T, K>
95
- | WritablePureSelectorToken<T, K>
96
- export type PureSelectorToken<T, K extends Canonical = any> =
97
- | ReadonlyPureSelectorToken<T, K>
98
- | WritablePureSelectorToken<T, K>
97
+ | WritablePureSelectorToken<T, K, E>
98
+ export type PureSelectorToken<T, K extends Canonical = any, E = never> =
99
+ | ReadonlyPureSelectorToken<T, K, E>
100
+ | WritablePureSelectorToken<T, K, E>
99
101
  export type HeldSelectorToken<T, K extends Canonical = any> =
100
102
  | ReadonlyHeldSelectorToken<T, K>
101
103
  | WritableHeldSelectorToken<T, K>
102
104
 
103
- export type WritablePureSelectorToken<T, K extends Canonical = any> = {
105
+ export type WritablePureSelectorToken<
106
+ T,
107
+ K extends Canonical = any,
108
+ E = never,
109
+ > = {
104
110
  /** The unique identifier of the selector. */
105
111
  key: string
106
112
  /** Discriminator. */
@@ -109,6 +115,8 @@ export type WritablePureSelectorToken<T, K extends Canonical = any> = {
109
115
  family?: FamilyMetadata<K>
110
116
  /** Never present. This is a marker that preserves the type of the selector's value. */
111
117
  __T?: T
118
+ /** Never present. This is a marker that preserves the type of errors this selector is capable of catching and setting as its value. */
119
+ __E?: E
112
120
  }
113
121
  export type WritableHeldSelectorToken<T, K extends Canonical = any> = {
114
122
  /** The unique identifier of the selector. */
@@ -120,7 +128,11 @@ export type WritableHeldSelectorToken<T, K extends Canonical = any> = {
120
128
  /** Never present. This is a marker that preserves the type of the selector's value. */
121
129
  __T?: T
122
130
  }
123
- export type ReadonlyPureSelectorToken<T, K extends Canonical = any> = {
131
+ export type ReadonlyPureSelectorToken<
132
+ T,
133
+ K extends Canonical = any,
134
+ E = never,
135
+ > = {
124
136
  /** The unique identifier of the selector. */
125
137
  key: string
126
138
  /** Discriminator. */
@@ -129,6 +141,8 @@ export type ReadonlyPureSelectorToken<T, K extends Canonical = any> = {
129
141
  family?: FamilyMetadata<K>
130
142
  /** Never present. This is a marker that preserves the type of the selector's value. */
131
143
  __T?: T
144
+ /** Never present. This is a marker that preserves the type of errors this selector is capable of catching and setting as its value. */
145
+ __E?: E
132
146
  }
133
147
  export type ReadonlyHeldSelectorToken<T, K extends Canonical = any> = {
134
148
  /** The unique identifier of the selector. */
@@ -151,10 +165,10 @@ export type FamilyMetadata<K extends Canonical = any> = {
151
165
  subKey: stringified<K>
152
166
  }
153
167
 
154
- export type AtomFamilyToken<T, K extends Canonical = Canonical> =
168
+ export type AtomFamilyToken<T, K extends Canonical = Canonical, E = never> =
155
169
  | MutableAtomFamilyToken<T extends Transceiver<any, any, any> ? T : never, K>
156
- | RegularAtomFamilyToken<T, K>
157
- export type RegularAtomFamilyToken<T, K extends Canonical> = {
170
+ | RegularAtomFamilyToken<T, K, E>
171
+ export type RegularAtomFamilyToken<T, K extends Canonical, E = never> = {
158
172
  /** The unique identifier of the atom family */
159
173
  key: string
160
174
  /** Discriminator */
@@ -163,6 +177,8 @@ export type RegularAtomFamilyToken<T, K extends Canonical> = {
163
177
  __T?: T
164
178
  /** Never present. This is a marker that preserves the type of keys used for atoms in this family */
165
179
  __K?: K
180
+ /** Never present. This is a marker that preserves the type of errors this family is capable of catching and setting as its value. */
181
+ __E?: E
166
182
  }
167
183
  export type MutableAtomFamilyToken<
168
184
  T extends Transceiver<any, any, any>,
@@ -178,23 +194,27 @@ export type MutableAtomFamilyToken<
178
194
  __K?: K
179
195
  }
180
196
 
181
- export type SelectorFamilyToken<T, K extends Canonical> =
182
- | ReadonlySelectorFamilyToken<T, K>
183
- | WritableSelectorFamilyToken<T, K>
184
- export type ReadonlySelectorFamilyToken<T, K extends Canonical> =
197
+ export type SelectorFamilyToken<T, K extends Canonical, E = never> =
198
+ | ReadonlySelectorFamilyToken<T, K, E>
199
+ | WritableSelectorFamilyToken<T, K, E>
200
+ export type ReadonlySelectorFamilyToken<T, K extends Canonical, E = never> =
185
201
  | ReadonlyHeldSelectorFamilyToken<T, K>
186
- | ReadonlyPureSelectorFamilyToken<T, K>
187
- export type WritableSelectorFamilyToken<T, K extends Canonical> =
202
+ | ReadonlyPureSelectorFamilyToken<T, K, E>
203
+ export type WritableSelectorFamilyToken<T, K extends Canonical, E = never> =
188
204
  | WritableHeldSelectorFamilyToken<T, K>
189
- | WritablePureSelectorFamilyToken<T, K>
190
- export type PureSelectorFamilyToken<T, K extends Canonical> =
191
- | ReadonlyPureSelectorFamilyToken<T, K>
192
- | WritablePureSelectorFamilyToken<T, K>
205
+ | WritablePureSelectorFamilyToken<T, K, E>
206
+ export type PureSelectorFamilyToken<T, K extends Canonical, E = never> =
207
+ | ReadonlyPureSelectorFamilyToken<T, K, E>
208
+ | WritablePureSelectorFamilyToken<T, K, E>
193
209
  export type HeldSelectorFamilyToken<T, K extends Canonical> =
194
210
  | ReadonlyHeldSelectorFamilyToken<T, K>
195
211
  | WritableHeldSelectorFamilyToken<T, K>
196
212
 
197
- export type WritablePureSelectorFamilyToken<T, K extends Canonical> = {
213
+ export type WritablePureSelectorFamilyToken<
214
+ T,
215
+ K extends Canonical,
216
+ E = never,
217
+ > = {
198
218
  /** The unique identifier of the family */
199
219
  key: string
200
220
  /** Discriminator */
@@ -203,8 +223,14 @@ export type WritablePureSelectorFamilyToken<T, K extends Canonical> = {
203
223
  __T?: T
204
224
  /** Never present. This is a marker that preserves the type of keys used for each family member */
205
225
  __K?: K
226
+ /** Never present. This is a marker that preserves the type of errors this family is capable of catching and setting as its value. */
227
+ __E?: E
206
228
  }
207
- export type ReadonlyPureSelectorFamilyToken<T, K extends Canonical> = {
229
+ export type ReadonlyPureSelectorFamilyToken<
230
+ T,
231
+ K extends Canonical,
232
+ E = never,
233
+ > = {
208
234
  /** The unique identifier of the family */
209
235
  key: string
210
236
  /** Discriminator */
@@ -213,6 +239,8 @@ export type ReadonlyPureSelectorFamilyToken<T, K extends Canonical> = {
213
239
  __T?: T
214
240
  /** Never present. This is a marker that preserves the type of keys used for each family member */
215
241
  __K?: K
242
+ /** Never present. This is a marker that preserves the type of errors this family is capable of catching and setting as its value. */
243
+ __E?: E
216
244
  }
217
245
  export type WritableHeldSelectorFamilyToken<T, K extends Canonical> = {
218
246
  /** The unique identifier of the family */
@@ -16,8 +16,8 @@ import type {
16
16
 
17
17
  export type TokenType<
18
18
  Comparison extends
19
- | ReadableFamilyToken<any, any>
20
- | ReadableToken<any>
19
+ | ReadableFamilyToken<any, any, any>
20
+ | ReadableToken<any, any, any>
21
21
  | TransactionToken<any>,
22
22
  > = Comparison extends ReadableToken<infer RepresentedValue>
23
23
  ? RepresentedValue
@@ -27,9 +27,9 @@ export type TokenType<
27
27
  ? Fn
28
28
  : never
29
29
 
30
- export function isToken<KnownToken extends RegularAtomToken<any>>(
30
+ export function isToken<KnownToken extends RegularAtomToken<any, any, any>>(
31
31
  knownToken: KnownToken,
32
- unknownToken: ReadableToken<any>,
32
+ unknownToken: ReadableToken<any, any, any>,
33
33
  ): unknownToken is RegularAtomToken<TokenType<KnownToken>>
34
34
  export function isToken<KnownToken extends MutableAtomToken<any, any>>(
35
35
  knownToken: KnownToken,