atom.io 0.40.6 → 0.40.7

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 (163) hide show
  1. package/README.md +1 -1
  2. package/dist/data/index.d.ts +1 -1
  3. package/dist/employ-socket-D6wgByWh.js +12 -0
  4. package/dist/employ-socket-D6wgByWh.js.map +1 -0
  5. package/dist/has-role-hv4-hJMw.js +1149 -0
  6. package/dist/has-role-hv4-hJMw.js.map +1 -0
  7. package/dist/internal/index.d.ts +248 -248
  8. package/dist/internal/index.d.ts.map +1 -1
  9. package/dist/internal/index.js +570 -1712
  10. package/dist/internal/index.js.map +1 -1
  11. package/dist/introspection/index.d.ts +1 -1
  12. package/dist/is-fn-DY1wZ-md.js +10 -0
  13. package/dist/is-fn-DY1wZ-md.js.map +1 -0
  14. package/dist/main/index.d.ts +33 -33
  15. package/dist/main/index.d.ts.map +1 -1
  16. package/dist/main/index.js +2 -2
  17. package/dist/main/index.js.map +1 -1
  18. package/dist/mutex-store-CSvxY9i3.js +11 -0
  19. package/dist/mutex-store-CSvxY9i3.js.map +1 -0
  20. package/dist/react/index.d.ts +5 -5
  21. package/dist/react/index.d.ts.map +1 -1
  22. package/dist/react/index.js.map +1 -1
  23. package/dist/react-devtools/index.js +7 -7
  24. package/dist/react-devtools/index.js.map +1 -1
  25. package/dist/realtime/index.d.ts +7 -15
  26. package/dist/realtime/index.d.ts.map +1 -1
  27. package/dist/realtime/index.js +3 -33
  28. package/dist/realtime/index.js.map +1 -1
  29. package/dist/realtime-client/index.d.ts +5 -5
  30. package/dist/realtime-client/index.d.ts.map +1 -1
  31. package/dist/realtime-client/index.js +92 -69
  32. package/dist/realtime-client/index.js.map +1 -1
  33. package/dist/realtime-react/index.d.ts +17 -10
  34. package/dist/realtime-react/index.d.ts.map +1 -1
  35. package/dist/realtime-react/index.js +41 -41
  36. package/dist/realtime-react/index.js.map +1 -1
  37. package/dist/realtime-server/index.d.ts +60 -53
  38. package/dist/realtime-server/index.d.ts.map +1 -1
  39. package/dist/realtime-server/index.js +592 -485
  40. package/dist/realtime-server/index.js.map +1 -1
  41. package/dist/realtime-testing/index.d.ts +1 -2
  42. package/dist/realtime-testing/index.d.ts.map +1 -1
  43. package/dist/realtime-testing/index.js +25 -18
  44. package/dist/realtime-testing/index.js.map +1 -1
  45. package/dist/shared-room-store-COGGKqes.js +32 -0
  46. package/dist/shared-room-store-COGGKqes.js.map +1 -0
  47. package/dist/shared-room-store-D2o4ZLjC.d.ts +15 -0
  48. package/dist/shared-room-store-D2o4ZLjC.d.ts.map +1 -0
  49. package/dist/web/index.d.ts +3 -3
  50. package/dist/web/index.d.ts.map +1 -1
  51. package/dist/web/index.js +4 -3
  52. package/dist/web/index.js.map +1 -1
  53. package/package.json +12 -12
  54. package/src/internal/atom/create-regular-atom.ts +5 -4
  55. package/src/internal/atom/dispose-atom.ts +7 -2
  56. package/src/internal/atom/has-role.ts +3 -3
  57. package/src/internal/caching.ts +4 -2
  58. package/src/internal/families/create-readonly-held-selector-family.ts +2 -1
  59. package/src/internal/families/create-readonly-pure-selector-family.ts +5 -2
  60. package/src/internal/families/create-regular-atom-family.ts +2 -1
  61. package/src/internal/families/create-writable-held-selector-family.ts +2 -1
  62. package/src/internal/families/create-writable-pure-selector-family.ts +5 -2
  63. package/src/internal/families/dispose-from-store.ts +4 -4
  64. package/src/internal/families/find-in-store.ts +10 -10
  65. package/src/internal/families/get-family-of-token.ts +2 -2
  66. package/src/internal/families/index.ts +1 -0
  67. package/src/internal/families/mint-in-store.ts +54 -19
  68. package/src/internal/families/seek-in-store.ts +1 -1
  69. package/src/internal/get-state/get-fallback.ts +2 -2
  70. package/src/internal/get-state/get-from-store.ts +5 -5
  71. package/src/internal/get-state/read-or-compute-value.ts +1 -1
  72. package/src/internal/get-state/reduce-reference.ts +8 -6
  73. package/src/internal/index.ts +2 -220
  74. package/src/internal/molecule.ts +1 -2
  75. package/src/internal/mutable/create-mutable-atom-family.ts +3 -2
  76. package/src/internal/mutable/create-mutable-atom.ts +4 -2
  77. package/src/internal/mutable/get-json-family.ts +1 -1
  78. package/src/internal/mutable/get-update-family.ts +1 -1
  79. package/src/internal/mutable/tracker-family.ts +2 -1
  80. package/src/internal/mutable/tracker.ts +5 -8
  81. package/src/internal/safe-compute.ts +1 -1
  82. package/src/internal/selector/create-readonly-held-selector.ts +2 -1
  83. package/src/internal/selector/create-readonly-pure-selector.ts +2 -1
  84. package/src/internal/selector/create-writable-held-selector.ts +2 -1
  85. package/src/internal/selector/create-writable-pure-selector.ts +2 -1
  86. package/src/internal/selector/dispose-selector.ts +3 -2
  87. package/src/internal/selector/register-selector.ts +8 -5
  88. package/src/internal/selector/trace-selector-atoms.ts +2 -1
  89. package/src/internal/set-state/dispatch-state-update.ts +3 -2
  90. package/src/internal/set-state/evict-downstream.ts +1 -1
  91. package/src/internal/set-state/operate-on-store.ts +16 -22
  92. package/src/internal/set-state/reset-atom-or-selector.ts +5 -3
  93. package/src/internal/set-state/reset-in-store.ts +5 -5
  94. package/src/internal/set-state/set-atom-or-selector.ts +2 -2
  95. package/src/internal/set-state/set-atom.ts +4 -2
  96. package/src/internal/set-state/set-into-store.ts +21 -39
  97. package/src/internal/set-state/set-selector.ts +3 -2
  98. package/src/internal/state-types.ts +228 -0
  99. package/src/internal/store/deposit.ts +4 -4
  100. package/src/internal/store/index.ts +0 -1
  101. package/src/internal/store/store.ts +9 -9
  102. package/src/internal/store/withdraw.ts +4 -4
  103. package/src/internal/subscribe/recall-state.ts +1 -1
  104. package/src/internal/subscribe/subscribe-to-root-atoms.ts +1 -12
  105. package/src/internal/subscribe/subscribe-to-transaction.ts +3 -2
  106. package/src/internal/transaction/build-transaction.ts +3 -2
  107. package/src/internal/transaction/index.ts +1 -23
  108. package/src/internal/transaction/is-root-store.ts +4 -1
  109. package/src/internal/transaction/transaction-meta-progress.ts +22 -0
  110. package/src/main/atom.ts +1 -2
  111. package/src/main/find-state.ts +5 -5
  112. package/src/main/get-state.ts +4 -4
  113. package/src/main/realm.ts +2 -2
  114. package/src/main/set-state.ts +10 -10
  115. package/src/react/parse-state-overloads.ts +3 -3
  116. package/src/react/use-i.ts +6 -4
  117. package/src/react/use-loadable.ts +4 -10
  118. package/src/react/use-o.ts +6 -4
  119. package/src/react-devtools/store.ts +6 -6
  120. package/src/realtime/index.ts +1 -0
  121. package/src/realtime/mutex-store.ts +11 -0
  122. package/src/realtime/realtime-continuity.ts +1 -5
  123. package/src/realtime-client/pull-atom-family-member.ts +14 -17
  124. package/src/realtime-client/pull-atom.ts +1 -1
  125. package/src/realtime-client/pull-mutable-atom-family-member.ts +16 -12
  126. package/src/realtime-client/pull-selector-family-member.ts +8 -35
  127. package/src/realtime-client/pull-selector-roots.ts +90 -0
  128. package/src/realtime-client/pull-selector.ts +2 -27
  129. package/src/realtime-client/push-state.ts +33 -5
  130. package/src/realtime-client/realtime-client-stores/client-main-store.ts +2 -5
  131. package/src/realtime-react/index.ts +2 -1
  132. package/src/realtime-react/realtime-context.tsx +9 -5
  133. package/src/realtime-react/use-pull-atom-family-member.ts +2 -3
  134. package/src/realtime-react/use-pull-mutable-family-member.ts +2 -3
  135. package/src/realtime-react/use-pull-selector-family-member.ts +5 -6
  136. package/src/realtime-react/use-push.ts +7 -3
  137. package/src/realtime-react/use-realtime-service.ts +11 -11
  138. package/src/realtime-react/use-single-effect.ts +11 -14
  139. package/src/realtime-server/{realtime-server-stores/server-sync-store.ts → continuity/continuity-store.ts} +1 -1
  140. package/src/realtime-server/continuity/prepare-to-sync-realtime-continuity.ts +1 -1
  141. package/src/realtime-server/continuity/prepare-to-track-client-acknowledgement.ts +3 -5
  142. package/src/realtime-server/continuity/subscribe-to-continuity-actions.ts +1 -1
  143. package/src/realtime-server/employ-socket.ts +14 -0
  144. package/src/realtime-server/index.ts +2 -20
  145. package/src/realtime-server/ipc-sockets/child-socket.ts +125 -66
  146. package/src/realtime-server/ipc-sockets/custom-socket.ts +16 -14
  147. package/src/realtime-server/ipc-sockets/parent-socket.ts +81 -58
  148. package/src/realtime-server/realtime-family-provider.ts +78 -29
  149. package/src/realtime-server/realtime-mutable-family-provider.ts +80 -31
  150. package/src/realtime-server/realtime-mutable-provider.ts +30 -22
  151. package/src/realtime-server/realtime-server-stores/index.ts +0 -2
  152. package/src/realtime-server/realtime-server-stores/server-room-external-store.ts +77 -36
  153. package/src/realtime-server/realtime-server-stores/server-user-store.ts +12 -1
  154. package/src/realtime-server/realtime-state-provider.ts +30 -29
  155. package/src/realtime-server/realtime-state-receiver.ts +62 -16
  156. package/src/realtime-server/server-config.ts +9 -0
  157. package/src/realtime-server/socket-interface.ts +14 -0
  158. package/src/realtime-testing/setup-realtime-test.tsx +56 -23
  159. package/src/web/index.ts +1 -1
  160. package/src/web/{persist-sync.ts → storage-sync.ts} +5 -2
  161. package/src/internal/store/mint-or-counterfeit.ts +0 -108
  162. package/src/realtime-react/on-mount.ts +0 -5
  163. package/src/realtime-server/realtime-server-stores/server-room-external-actions.ts +0 -79
@@ -1,30 +1,3 @@
1
- import type {
2
- FamilyMetadata,
3
- MutableAtomFamilyToken,
4
- MutableAtomToken,
5
- ReadonlyHeldSelectorFamilyToken,
6
- ReadonlyHeldSelectorToken,
7
- ReadonlyPureSelectorFamilyToken,
8
- ReadonlyPureSelectorToken,
9
- RegularAtomFamilyToken,
10
- RegularAtomToken,
11
- StateLifecycleEvent,
12
- StateUpdate,
13
- WritableHeldSelectorFamilyToken,
14
- WritableHeldSelectorToken,
15
- WritablePureSelectorFamilyToken,
16
- WritablePureSelectorToken,
17
- } from "atom.io"
18
- import type { Canonical } from "atom.io/json"
19
-
20
- import type { internalRole } from "./atom/has-role"
21
- import type { ConstructorOf, Transceiver } from "./mutable"
22
- import type { Store } from "./store"
23
- import type { Subject } from "./subject"
24
- import type { Timeline } from "./timeline"
25
- import type { RootStore, Transaction } from "./transaction"
26
- import type { Ctor, Flat } from "./utility-types"
27
-
28
1
  export * from "./arbitrary"
29
2
  export * from "./atom"
30
3
  export * from "./caching"
@@ -36,6 +9,7 @@ export * from "./get-environment-data"
36
9
  export * from "./get-state"
37
10
  export * from "./get-trace"
38
11
  export * from "./install-into-store"
12
+ export * from "./is-fn"
39
13
  export * from "./join"
40
14
  export * from "./junction"
41
15
  export * from "./keys"
@@ -48,202 +22,10 @@ export * from "./overlays"
48
22
  export * from "./reserved-keys"
49
23
  export * from "./selector"
50
24
  export * from "./set-state"
25
+ export type * from "./state-types"
51
26
  export * from "./store"
52
27
  export * from "./subject"
53
28
  export * from "./subscribe"
54
29
  export * from "./timeline"
55
30
  export * from "./transaction"
56
31
  export type * from "./utility-types"
57
-
58
- export type AtomIOState = {
59
- key: string
60
- family?: FamilyMetadata
61
- install: (store: RootStore) => void
62
- subject: Subject<StateUpdate<any>>
63
- }
64
- export type RegularAtom<T, E> = Flat<
65
- AtomIOState & {
66
- type: `atom`
67
- default: T | (() => T)
68
- cleanup?: () => void
69
- internalRoles?: internalRole[]
70
- catch?: readonly Ctor<E>[]
71
- }
72
- >
73
- export type MutableAtom<T extends Transceiver<any, any, any>> = Flat<
74
- AtomIOState & {
75
- type: `mutable_atom`
76
- class: ConstructorOf<T>
77
- cleanup?: () => void
78
- }
79
- >
80
- export type Atom<T, E> =
81
- | RegularAtom<T, E>
82
- | (T extends Transceiver<any, any, any> ? MutableAtom<T> : never)
83
-
84
- export type WritableHeldSelector<T> = Flat<
85
- AtomIOState & {
86
- type: `writable_held_selector`
87
- const: T
88
- getFrom: (target: Store) => T
89
- setSelf: (newValue: T) => void
90
- }
91
- >
92
- export type ReadonlyHeldSelector<T> = Flat<
93
- AtomIOState & {
94
- type: `readonly_held_selector`
95
- const: T
96
- getFrom: (target: Store) => T
97
- }
98
- >
99
- export type WritablePureSelector<T, E> = Flat<
100
- AtomIOState & {
101
- type: `writable_pure_selector`
102
- getFrom: (target: Store) => E | T
103
- setSelf: (newValue: T) => void
104
- catch?: readonly Ctor<E>[]
105
- }
106
- >
107
- export type ReadonlyPureSelector<T, E> = Flat<
108
- AtomIOState & {
109
- type: `readonly_pure_selector`
110
- getFrom: (target: Store) => E | T
111
- catch?: readonly Ctor<E>[]
112
- }
113
- >
114
- export type ReadonlySelector<T, E> =
115
- | ReadonlyHeldSelector<T>
116
- | ReadonlyPureSelector<T, E>
117
- export type WritableSelector<T, E> =
118
- | WritableHeldSelector<T>
119
- | WritablePureSelector<T, E>
120
- export type HeldSelector<T> = ReadonlyHeldSelector<T> | WritableHeldSelector<T>
121
- export type PureSelector<T, E> =
122
- | ReadonlyPureSelector<T, E>
123
- | WritablePureSelector<T, E>
124
- export type Selector<T, E> =
125
- | ReadonlyHeldSelector<T>
126
- | ReadonlyPureSelector<T, E>
127
- | WritableHeldSelector<T>
128
- | WritablePureSelector<T, E>
129
-
130
- export type WritableState<T, E> = Atom<T, E> | WritableSelector<T, E>
131
- export type ReadableState<T, E> = Atom<T, E> | Selector<T, E>
132
-
133
- // biome-ignore format: intersection
134
- export type RegularAtomFamily<T, K extends Canonical, E = never> =
135
- & Flat<
136
- & RegularAtomFamilyToken<T, K, E>
137
- & {
138
- create: <Key extends K>(key: Key) => RegularAtomToken<T, Key, E>
139
- default: T | ((key: K) => T)
140
- install: (store: RootStore) => void
141
- internalRoles: string[] | undefined
142
- subject: Subject<StateLifecycleEvent<RegularAtomToken<T, K, E>>>
143
- }
144
- >
145
-
146
- // biome-ignore format: intersection
147
- export type MutableAtomFamily<
148
- T extends Transceiver<any, any, any>,
149
- K extends Canonical,
150
- > =
151
- & Flat<
152
- & MutableAtomFamilyToken<T, K>
153
- & {
154
- create: <Key extends K>(key: Key) => MutableAtomToken<T, Key>
155
- class: ConstructorOf<T>
156
- install: (store: RootStore) => void
157
- internalRoles: string[] | undefined
158
- subject: Subject<StateLifecycleEvent<MutableAtomToken<T>>>
159
- }
160
- >
161
-
162
- export type AtomFamily<T, K extends Canonical, E> =
163
- | MutableAtomFamily<T extends Transceiver<any, any, any> ? T : never, K>
164
- | RegularAtomFamily<T, K, E>
165
-
166
- // biome-ignore format: intersection
167
- export type WritablePureSelectorFamily<T, K extends Canonical, E> =
168
- & Flat<
169
- & WritablePureSelectorFamilyToken<T, K, E>
170
- & {
171
- create: <Key extends K>(key: Key) => WritablePureSelectorToken<T, Key, E>
172
- default: (key: K) => T,
173
- install: (store: RootStore) => void
174
- internalRoles: string[] | undefined
175
- subject: Subject<StateLifecycleEvent<WritablePureSelectorToken<T, K, E>>>
176
- }
177
- >
178
-
179
- // biome-ignore format: intersection
180
- export type WritableHeldSelectorFamily<T , K extends Canonical> =
181
- & Flat<
182
- & WritableHeldSelectorFamilyToken<T, K>
183
- & {
184
- create: <Key extends K>(key: Key) => WritableHeldSelectorToken<T, Key>
185
- default: (key: K) => T,
186
- install: (store: RootStore) => void
187
- internalRoles: string[] | undefined
188
- subject: Subject<StateLifecycleEvent<WritableHeldSelectorToken<T, K>>>
189
- }
190
- >
191
-
192
- // biome-ignore format: intersection
193
- export type ReadonlyPureSelectorFamily<T, K extends Canonical, E> =
194
- & Flat<
195
- & ReadonlyPureSelectorFamilyToken<T, K, E>
196
- & {
197
- create: <Key extends K>(key: Key) => ReadonlyPureSelectorToken<T, Key, E>
198
- default: (key: K) => T,
199
- install: (store: RootStore) => void
200
- internalRoles: string[] | undefined
201
- subject: Subject<StateLifecycleEvent<ReadonlyPureSelectorToken<T, K, E>>>
202
- }
203
- >
204
-
205
- // biome-ignore format: intersection
206
- export type ReadonlyHeldSelectorFamily<T , K extends Canonical> =
207
- & Flat<
208
- & ReadonlyHeldSelectorFamilyToken<T, K>
209
- & {
210
- create: <Key extends K>(key: Key) => ReadonlyHeldSelectorToken<T, Key>
211
- default: (key: K) => T,
212
- install: (store: RootStore) => void
213
- internalRoles: string[] | undefined
214
- subject: Subject<StateLifecycleEvent<ReadonlyHeldSelectorToken<T>>>
215
- }
216
- >
217
-
218
- export type PureSelectorFamily<T, K extends Canonical, E> =
219
- | ReadonlyPureSelectorFamily<T, K, E>
220
- | WritablePureSelectorFamily<T, K, E>
221
-
222
- export type HeldSelectorFamily<T, K extends Canonical> =
223
- | ReadonlyHeldSelectorFamily<T, K>
224
- | WritableHeldSelectorFamily<T, K>
225
-
226
- export type ReadonlySelectorFamily<T, K extends Canonical, E> =
227
- | ReadonlyHeldSelectorFamily<T, K>
228
- | ReadonlyPureSelectorFamily<T, K, E>
229
-
230
- export type WritableSelectorFamily<T, K extends Canonical, E> =
231
- | WritableHeldSelectorFamily<T, K>
232
- | WritablePureSelectorFamily<T, K, E>
233
-
234
- export type SelectorFamily<T, K extends Canonical, E> =
235
- | HeldSelectorFamily<T, K>
236
- | PureSelectorFamily<T, K, E>
237
-
238
- export type WritableFamily<T, K extends Canonical, E> =
239
- | AtomFamily<T, K, E>
240
- | WritableSelectorFamily<T, K, E>
241
- export type ReadableFamily<T, K extends Canonical, E> =
242
- | AtomFamily<T, K, E>
243
- | SelectorFamily<T, K, E>
244
-
245
- export type AtomIOInternalResource =
246
- | ReadableFamily<any, any, any>
247
- | ReadableState<any, any>
248
- | Timeline<any>
249
- | Transaction<any>
@@ -19,7 +19,6 @@ import { getFromStore } from "./get-state"
19
19
  import { getTrace } from "./get-trace"
20
20
  import { newest } from "./lineage"
21
21
  import type { Store } from "./store"
22
- import { IMPLICIT } from "./store"
23
22
  import type { RootStore } from "./transaction"
24
23
  import { createTransaction, isChildStore } from "./transaction"
25
24
 
@@ -30,8 +29,8 @@ export type Molecule<K extends Canonical> = {
30
29
  }
31
30
 
32
31
  export function makeRootMoleculeInStore<S extends string>(
32
+ store: Store,
33
33
  key: S,
34
- store: Store = IMPLICIT.STORE,
35
34
  ): S {
36
35
  const molecule = {
37
36
  key,
@@ -10,11 +10,12 @@ import { PRETTY_TOKEN_TYPES } from "atom.io"
10
10
  import type { Canonical } from "atom.io/json"
11
11
  import { stringifyJson } from "atom.io/json"
12
12
 
13
- import type { MutableAtomFamily, RootStore } from ".."
14
- import { createWritablePureSelectorFamily } from ".."
13
+ import { createWritablePureSelectorFamily } from "../families"
15
14
  import { newest } from "../lineage"
16
15
  import { createMutableAtom } from "../mutable"
16
+ import type { MutableAtomFamily } from "../state-types"
17
17
  import { Subject } from "../subject"
18
+ import type { RootStore } from "../transaction"
18
19
  import { FamilyTracker } from "./tracker-family"
19
20
  import type { AsJSON, Transceiver } from "./transceiver"
20
21
 
@@ -5,12 +5,14 @@ import type {
5
5
  UpdateHandler,
6
6
  } from "atom.io"
7
7
 
8
- import type { MutableAtom, RootStore } from ".."
9
- import { createStandaloneSelector, resetInStore, setIntoStore } from ".."
10
8
  import { newest } from "../lineage"
9
+ import { createStandaloneSelector } from "../selector"
10
+ import { resetInStore, setIntoStore } from "../set-state"
11
+ import type { MutableAtom } from "../state-types"
11
12
  import { deposit, type Store } from "../store"
12
13
  import { Subject } from "../subject"
13
14
  import { subscribeToState } from "../subscribe"
15
+ import type { RootStore } from "../transaction"
14
16
  import { Tracker } from "./tracker"
15
17
  import type { Transceiver } from "./transceiver"
16
18
 
@@ -1,8 +1,8 @@
1
1
  import type { MutableAtomFamilyToken } from "atom.io"
2
2
  import type { Canonical, Json } from "atom.io/json"
3
3
 
4
- import type { WritablePureSelectorFamily } from ".."
5
4
  import { newest } from "../lineage"
5
+ import type { WritablePureSelectorFamily } from "../state-types"
6
6
  import type { Store } from "../store"
7
7
  import type { Transceiver } from "./transceiver"
8
8
 
@@ -1,8 +1,8 @@
1
1
  import type { MutableAtomFamilyToken } from "atom.io"
2
2
  import type { Json } from "atom.io/json"
3
3
 
4
- import type { RegularAtomFamily } from ".."
5
4
  import { newest } from "../lineage"
5
+ import type { RegularAtomFamily } from "../state-types"
6
6
  import type { Store } from "../store"
7
7
  import type { SignalFrom, Transceiver } from "./transceiver"
8
8
 
@@ -2,9 +2,10 @@ import type { MutableAtomToken, StateLifecycleEvent } from "atom.io"
2
2
  import type { Canonical } from "atom.io/json"
3
3
  import { parseJson } from "atom.io/json"
4
4
 
5
- import type { MutableAtomFamily, RegularAtomFamily, RootStore } from ".."
6
5
  import { createRegularAtomFamily } from "../families"
6
+ import type { MutableAtomFamily, RegularAtomFamily } from "../state-types"
7
7
  import { withdraw } from "../store"
8
+ import type { RootStore } from "../transaction"
8
9
  import { Tracker } from "./tracker"
9
10
  import type { SignalFrom, Transceiver } from "./transceiver"
10
11
 
@@ -1,14 +1,11 @@
1
1
  import type { FamilyMetadata, MutableAtomToken, RegularAtomToken } from "atom.io"
2
2
 
3
- import type { Store } from ".."
4
- import {
5
- getFromStore,
6
- newest,
7
- setIntoStore,
8
- subscribeToState,
9
- subscribeToTimeline,
10
- } from ".."
11
3
  import { createRegularAtom } from "../atom"
4
+ import { getFromStore } from "../get-state"
5
+ import { newest } from "../lineage"
6
+ import { setIntoStore } from "../set-state"
7
+ import type { Store } from "../store"
8
+ import { subscribeToState, subscribeToTimeline } from "../subscribe"
12
9
  import { isChildStore } from "../transaction/is-root-store"
13
10
  import type { SignalFrom, Transceiver } from "./transceiver"
14
11
 
@@ -1,6 +1,6 @@
1
- import type { PureSelector, RegularAtom } from "."
2
1
  import { writeToCache } from "./caching"
3
2
  import { isFn } from "./is-fn"
3
+ import type { PureSelector, RegularAtom } from "./state-types"
4
4
  import type { Store } from "./store"
5
5
 
6
6
  export function safeCompute<T, E>(
@@ -4,11 +4,12 @@ import type {
4
4
  ReadonlyHeldSelectorToken,
5
5
  } from "atom.io"
6
6
 
7
- import type { ReadonlyHeldSelector, RootStore } from ".."
8
7
  import { writeToCache } from "../caching"
9
8
  import { newest } from "../lineage"
9
+ import type { ReadonlyHeldSelector } from "../state-types"
10
10
  import type { Store } from "../store"
11
11
  import { Subject } from "../subject"
12
+ import type { RootStore } from "../transaction"
12
13
  import { registerSelector } from "./register-selector"
13
14
 
14
15
  export function createReadonlyHeldSelector<T extends object>(
@@ -6,11 +6,12 @@ import type {
6
6
  } from "atom.io"
7
7
  import type { Canonical } from "atom.io/json"
8
8
 
9
- import type { ReadonlyPureSelector, RootStore } from ".."
10
9
  import { writeToCache } from "../caching"
11
10
  import { newest } from "../lineage"
11
+ import type { ReadonlyPureSelector } from "../state-types"
12
12
  import type { Store } from "../store"
13
13
  import { Subject } from "../subject"
14
+ import type { RootStore } from "../transaction"
14
15
  import { registerSelector } from "./register-selector"
15
16
 
16
17
  export function createReadonlyPureSelector<T, K extends Canonical, E>(
@@ -4,11 +4,12 @@ import type {
4
4
  WritableHeldSelectorToken,
5
5
  } from "atom.io"
6
6
 
7
- import type { RootStore, WritableHeldSelector } from ".."
8
7
  import { writeToCache } from "../caching"
9
8
  import { newest } from "../lineage"
9
+ import type { WritableHeldSelector } from "../state-types"
10
10
  import type { Store } from "../store"
11
11
  import { Subject } from "../subject"
12
+ import type { RootStore } from "../transaction"
12
13
  import { registerSelector } from "./register-selector"
13
14
 
14
15
  export function createWritableHeldSelector<T extends object>(
@@ -6,11 +6,12 @@ import type {
6
6
  } from "atom.io"
7
7
  import type { Canonical } from "atom.io/json"
8
8
 
9
- import type { RootStore, WritablePureSelector } from ".."
10
9
  import { writeToCache } from "../caching"
11
10
  import { newest } from "../lineage"
11
+ import type { WritablePureSelector } from "../state-types"
12
12
  import type { Store } from "../store"
13
13
  import { Subject } from "../subject"
14
+ import type { RootStore } from "../transaction"
14
15
  import { registerSelector } from "./register-selector"
15
16
 
16
17
  export function createWritablePureSelector<T, K extends Canonical, E>(
@@ -1,7 +1,8 @@
1
1
  import type { SelectorFamilyToken, SelectorToken } from "atom.io"
2
2
 
3
- import type { Store } from ".."
4
- import { isChildStore, newest, withdraw } from ".."
3
+ import { newest } from "../lineage"
4
+ import { type Store, withdraw } from "../store"
5
+ import { isChildStore } from "../transaction"
5
6
 
6
7
  export function disposeSelector(
7
8
  store: Store,
@@ -67,17 +67,20 @@ export function registerSelector(
67
67
  updateSelectorAtoms(store, selectorType, selectorKey, token, covered)
68
68
  return dependencyValue
69
69
  },
70
- set: (<T, K extends Canonical, New extends T, Key extends K>(
70
+ set: (<T, K extends Canonical>(
71
71
  ...params:
72
72
  | [
73
73
  token: WritableFamilyToken<T, K>,
74
- key: Key,
75
- value: New | ((oldValue: any) => New),
74
+ key: NoInfer<K>,
75
+ value: NoInfer<T> | ((oldValue: T) => NoInfer<T>),
76
+ ]
77
+ | [
78
+ token: WritableToken<T>,
79
+ value: NoInfer<T> | ((oldValue: T) => NoInfer<T>),
76
80
  ]
77
- | [token: WritableToken<T>, value: New | ((oldValue: T) => New)]
78
81
  ) => {
79
82
  const target = newest(store)
80
- operateOnStore(target, JOIN_OP, ...params)
83
+ operateOnStore(JOIN_OP, target, ...params)
81
84
  }) as typeof setState,
82
85
  find: ((...args: Parameters<typeof findState>) =>
83
86
  findInStore(store, ...args)) as typeof findState,
@@ -1,5 +1,6 @@
1
- import type { Atom, Store } from ".."
2
1
  import { isAtomKey } from "../keys"
2
+ import type { Atom } from "../state-types"
3
+ import type { Store } from "../store"
3
4
  import { getSelectorDependencyKeys } from "./get-selector-dependency-keys"
4
5
 
5
6
  export function traceRootSelectorAtoms(
@@ -5,14 +5,15 @@ import type {
5
5
  TimelineEvent,
6
6
  } from "atom.io"
7
7
 
8
- import type { MutableAtom, Subject, WritableFamily, WritableState } from ".."
9
- import { newest } from ".."
10
8
  import { hasRole } from "../atom"
11
9
  import { readOrComputeValue } from "../get-state"
10
+ import { newest } from "../lineage"
12
11
  import type { Transceiver } from "../mutable"
13
12
  import { isTransceiver } from "../mutable"
14
13
  import type { OpenOperation } from "../operation"
14
+ import type { MutableAtom, WritableFamily, WritableState } from "../state-types"
15
15
  import { deposit, type Store } from "../store"
16
+ import type { Subject } from "../subject"
16
17
  import { isChildStore, isRootStore } from "../transaction"
17
18
  import { evictDownstreamFromAtom } from "./evict-downstream"
18
19
  import type { ProtoUpdate } from "./operate-on-store"
@@ -1,7 +1,7 @@
1
- import type { Atom } from ".."
2
1
  import { evictCachedValue } from "../caching"
3
2
  import { newest } from "../lineage"
4
3
  import { isDone, markDone } from "../operation"
4
+ import type { Atom } from "../state-types"
5
5
  import type { Store } from "../store"
6
6
 
7
7
  export function evictDownstreamFromAtom(
@@ -1,12 +1,12 @@
1
- import type { WritableFamilyToken, WritableToken } from "atom.io"
1
+ import type { Setter, WritableFamilyToken, WritableToken } from "atom.io"
2
2
  import { type Canonical, parseJson } from "atom.io/json"
3
3
 
4
- import type { WritableFamily } from ".."
5
4
  import { seekInStore } from "../families"
6
5
  import { getFamilyOfToken } from "../families/get-family-of-token"
7
6
  import { mintInStore, MUST_CREATE } from "../families/mint-in-store"
8
7
  import type { OpenOperation } from "../operation"
9
8
  import { closeOperation, openOperation } from "../operation"
9
+ import type { WritableFamily } from "../state-types"
10
10
  import { type Store, withdraw } from "../store"
11
11
  import { dispatchOrDeferStateUpdate } from "./dispatch-state-update"
12
12
  import { resetAtomOrSelector } from "./reset-atom-or-selector"
@@ -18,32 +18,26 @@ export type ProtoUpdate<T> = { oldValue: T; newValue: T }
18
18
  export const OWN_OP: unique symbol = Symbol(`OWN_OP`)
19
19
  export const JOIN_OP: unique symbol = Symbol(`JOIN_OP`)
20
20
 
21
- export function operateOnStore<
22
- T,
23
- K extends Canonical,
24
- New extends T,
25
- Key extends K,
26
- E,
27
- >(
28
- store: Store,
21
+ export function operateOnStore<T, TT extends T, K extends Canonical, E>(
29
22
  opMode: typeof JOIN_OP | typeof OWN_OP,
23
+ store: Store,
30
24
  ...params:
31
25
  | [
32
26
  token: WritableFamilyToken<T, K, E>,
33
- key: Key,
34
- value: New | typeof RESET_STATE | ((oldValue: T) => New),
27
+ key: NoInfer<K>,
28
+ value: Setter<TT> | TT | typeof RESET_STATE,
35
29
  ]
36
30
  | [
37
- token: WritableToken<T, Key, E>,
38
- value: New | typeof RESET_STATE | ((oldValue: T) => New),
31
+ token: WritableToken<T, any, E>,
32
+ value: Setter<TT> | TT | typeof RESET_STATE,
39
33
  ]
40
34
  ): void {
41
- let existingToken: WritableToken<T, Key, E> | undefined
42
- let brandNewToken: WritableToken<T, Key, E> | undefined
43
- let token: WritableToken<T, Key, E>
35
+ let existingToken: WritableToken<T, K, E> | undefined
36
+ let brandNewToken: WritableToken<T, K, E> | undefined
37
+ let token: WritableToken<T, K, E>
44
38
  let family: WritableFamily<T, K, E> | undefined
45
- let key: Key | null
46
- let value: New | typeof RESET_STATE | ((oldValue: T) => New)
39
+ let key: K | null
40
+ let value: Setter<TT> | TT | typeof RESET_STATE
47
41
  if (params.length === 2) {
48
42
  token = params[0]
49
43
  value = params[1]
@@ -52,7 +46,7 @@ export function operateOnStore<
52
46
  key = parseJson(token.family.subKey)
53
47
  existingToken = seekInStore(store, family, key)
54
48
  if (!existingToken) {
55
- token = brandNewToken = mintInStore(store, family, key, MUST_CREATE)
49
+ token = brandNewToken = mintInStore(MUST_CREATE, store, family, key)
56
50
  } else {
57
51
  token = existingToken
58
52
  }
@@ -63,7 +57,7 @@ export function operateOnStore<
63
57
  value = params[2]
64
58
  existingToken = seekInStore(store, family, key)
65
59
  if (!existingToken) {
66
- token = brandNewToken = mintInStore(store, family, key, MUST_CREATE)
60
+ token = brandNewToken = mintInStore(MUST_CREATE, store, family, key)
67
61
  } else {
68
62
  token = existingToken
69
63
  }
@@ -90,7 +84,7 @@ export function operateOnStore<
90
84
  action,
91
85
  `from T-${rejectionTime}`,
92
86
  )
93
- operateOnStore(store, opMode, token, value)
87
+ operateOnStore(opMode, store, token, value)
94
88
  },
95
89
  )
96
90
  return
@@ -1,7 +1,9 @@
1
- import type { Atom, OpenOperation, Store, WritableState } from ".."
2
- import { traceRootSelectorAtoms } from ".."
3
1
  import { isFn } from "../is-fn"
2
+ import type { OpenOperation } from "../operation"
4
3
  import { safeCompute } from "../safe-compute"
4
+ import { traceRootSelectorAtoms } from "../selector"
5
+ import type { Atom, WritableState } from "../state-types"
6
+ import type { Store } from "../store"
5
7
  import { dispatchOrDeferStateUpdate } from "./dispatch-state-update"
6
8
  import type { ProtoUpdate } from "./operate-on-store"
7
9
  import { setAtom } from "./set-atom"
@@ -17,7 +19,7 @@ function resetAtom<T, E>(
17
19
  let def: E | T
18
20
  if (isFn(atom.default)) def = safeCompute(target, atom)
19
21
  else def = atom.default
20
- return setAtom(target, atom, def)
22
+ return setAtom<E | T>(target, atom, def)
21
23
  }
22
24
  }
23
25
  }
@@ -14,20 +14,20 @@ export function resetInStore(
14
14
  export function resetInStore<K extends Canonical>(
15
15
  store: Store,
16
16
  token: WritableFamilyToken<any, K, any>,
17
- key: K,
17
+ key: NoInfer<K>,
18
18
  ): void
19
19
 
20
- export function resetInStore<T, K extends Canonical, Key extends K>(
20
+ export function resetInStore<T, K extends Canonical>(
21
21
  store: Store,
22
22
  ...params:
23
- | [token: WritableFamilyToken<T, K, any>, key: Key]
23
+ | [token: WritableFamilyToken<T, K, any>, key: NoInfer<K>]
24
24
  | [token: WritableToken<T, any, any>]
25
25
  ): void
26
26
 
27
- export function resetInStore<T, K extends Canonical, Key extends K>(
27
+ export function resetInStore<T, K extends Canonical>(
28
28
  store: Store,
29
29
  ...params:
30
- | [token: WritableFamilyToken<T, K, any>, key: Key]
30
+ | [token: WritableFamilyToken<T, K, any>, key: NoInfer<K>]
31
31
  | [token: WritableToken<T, any, any>]
32
32
  ): void {
33
33
  const subParams = [...params, RESET_STATE] as const
@@ -1,5 +1,5 @@
1
- import type { WritableState } from ".."
2
1
  import type { OpenOperation } from "../operation"
2
+ import type { WritableState } from "../state-types"
3
3
  import type { Store } from "../store"
4
4
  import type { ProtoUpdate } from "./operate-on-store"
5
5
  import { setAtom } from "./set-atom"
@@ -8,7 +8,7 @@ import { setSelector } from "./set-selector"
8
8
  export const setAtomOrSelector = <T>(
9
9
  target: Store & { operation: OpenOperation },
10
10
  state: WritableState<T, any>,
11
- value: T | ((oldValue: T) => T),
11
+ value: NoInfer<T> | ((oldValue: T) => NoInfer<T>),
12
12
  ): ProtoUpdate<T> => {
13
13
  let protoUpdate: ProtoUpdate<T>
14
14
  switch (state.type) {
@@ -1,7 +1,9 @@
1
- import type { Atom, OpenOperation, Store } from ".."
2
1
  import { writeToCache } from "../caching"
3
2
  import { readOrComputeValue } from "../get-state/read-or-compute-value"
3
+ import type { OpenOperation } from "../operation"
4
4
  import { markDone } from "../operation"
5
+ import type { Atom } from "../state-types"
6
+ import type { Store } from "../store"
5
7
  import { become } from "./become"
6
8
  import { evictDownstreamFromAtom } from "./evict-downstream"
7
9
  import type { ProtoUpdate } from "./operate-on-store"
@@ -9,7 +11,7 @@ import type { ProtoUpdate } from "./operate-on-store"
9
11
  export const setAtom = <T>(
10
12
  target: Store & { operation: OpenOperation<any> },
11
13
  atom: Atom<T, any>,
12
- next: T | ((oldValue: T) => T),
14
+ next: NoInfer<T> | ((oldValue: T) => NoInfer<T>),
13
15
  ): ProtoUpdate<T> => {
14
16
  const oldValue = readOrComputeValue(target, atom, `mut`)
15
17
  let newValue = become(next, oldValue)