atom.io 0.34.2 → 0.36.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/dist/eslint-plugin/index.d.ts +2 -18
  2. package/dist/eslint-plugin/index.d.ts.map +1 -1
  3. package/dist/eslint-plugin/index.js +4 -141
  4. package/dist/eslint-plugin/index.js.map +1 -1
  5. package/dist/internal/index.d.ts +74 -77
  6. package/dist/internal/index.d.ts.map +1 -1
  7. package/dist/internal/index.js +197 -202
  8. package/dist/internal/index.js.map +1 -1
  9. package/dist/json/index.d.ts +9 -17
  10. package/dist/json/index.d.ts.map +1 -1
  11. package/dist/json/index.js +3 -33
  12. package/dist/json/index.js.map +1 -1
  13. package/dist/main/index.d.ts +689 -795
  14. package/dist/main/index.d.ts.map +1 -1
  15. package/dist/main/index.js +55 -23
  16. package/dist/main/index.js.map +1 -1
  17. package/dist/react/index.d.ts +4 -4
  18. package/dist/react/index.d.ts.map +1 -1
  19. package/dist/react/index.js.map +1 -1
  20. package/dist/react-devtools/index.d.ts.map +1 -1
  21. package/dist/react-devtools/index.js +10 -10
  22. package/dist/react-devtools/index.js.map +1 -1
  23. package/dist/realtime/index.d.ts +4 -4
  24. package/dist/realtime/index.d.ts.map +1 -1
  25. package/dist/realtime/index.js +5 -11
  26. package/dist/realtime/index.js.map +1 -1
  27. package/dist/realtime-client/index.d.ts +2 -2
  28. package/dist/realtime-client/index.d.ts.map +1 -1
  29. package/dist/realtime-client/index.js +10 -10
  30. package/dist/realtime-client/index.js.map +1 -1
  31. package/dist/realtime-react/index.d.ts +2 -2
  32. package/dist/realtime-react/index.d.ts.map +1 -1
  33. package/dist/realtime-react/index.js.map +1 -1
  34. package/dist/realtime-server/index.d.ts +18 -18
  35. package/dist/realtime-server/index.d.ts.map +1 -1
  36. package/dist/realtime-server/index.js +13 -19
  37. package/dist/realtime-server/index.js.map +1 -1
  38. package/dist/transceivers/set-rtx/index.d.ts +1 -1
  39. package/dist/transceivers/set-rtx/index.d.ts.map +1 -1
  40. package/dist/transceivers/set-rtx/index.js.map +1 -1
  41. package/package.json +7 -7
  42. package/src/eslint-plugin/index.ts +0 -1
  43. package/src/eslint-plugin/rules/explicit-state-types.ts +8 -1
  44. package/src/eslint-plugin/rules/index.ts +0 -1
  45. package/src/internal/atom/create-regular-atom.ts +1 -0
  46. package/src/internal/atom/dispose-atom.ts +1 -0
  47. package/src/internal/atom/index.ts +0 -1
  48. package/src/internal/families/find-in-store.ts +4 -5
  49. package/src/internal/families/get-family-of-token.ts +4 -5
  50. package/src/internal/families/index.ts +0 -1
  51. package/src/internal/families/init-family-member.ts +3 -4
  52. package/src/internal/families/seek-in-store.ts +4 -5
  53. package/src/internal/get-state/read-or-compute-value.ts +14 -2
  54. package/src/internal/index.ts +116 -96
  55. package/src/internal/ingest-updates/ingest-creation-disposal.ts +18 -15
  56. package/src/internal/ingest-updates/ingest-selector-update.ts +9 -5
  57. package/src/internal/join/get-internal-relations-from-store.ts +2 -2
  58. package/src/internal/join/join-internal.ts +6 -18
  59. package/src/internal/molecule.ts +1 -0
  60. package/src/internal/mutable/create-mutable-atom-family.ts +37 -21
  61. package/src/internal/mutable/create-mutable-atom.ts +17 -13
  62. package/src/internal/mutable/get-json-family.ts +7 -6
  63. package/src/internal/mutable/get-json-token.ts +6 -13
  64. package/src/internal/mutable/get-update-family.ts +7 -8
  65. package/src/internal/mutable/get-update-token.ts +5 -9
  66. package/src/internal/mutable/tracker-family.ts +10 -13
  67. package/src/internal/mutable/tracker.ts +66 -90
  68. package/src/internal/mutable/transceiver.ts +35 -8
  69. package/src/internal/selector/dispose-selector.ts +9 -9
  70. package/src/internal/selector/register-selector.ts +2 -2
  71. package/src/internal/set-state/copy-mutable-if-needed.ts +8 -6
  72. package/src/internal/set-state/reset-atom-or-selector.ts +11 -4
  73. package/src/internal/set-state/set-atom.ts +1 -1
  74. package/src/internal/store/counterfeit.ts +3 -4
  75. package/src/internal/store/deposit.ts +7 -9
  76. package/src/internal/store/store.ts +2 -2
  77. package/src/internal/store/withdraw.ts +7 -11
  78. package/src/json/entries.ts +7 -7
  79. package/src/json/index.ts +0 -2
  80. package/src/main/atom.ts +68 -127
  81. package/src/main/dispose-state.ts +4 -6
  82. package/src/main/find-state.ts +6 -13
  83. package/src/main/get-state.ts +0 -2
  84. package/src/main/index.ts +1 -176
  85. package/src/main/join.ts +2 -9
  86. package/src/main/logger.ts +7 -7
  87. package/src/main/reset-state.ts +0 -2
  88. package/src/main/selector.ts +5 -72
  89. package/src/main/set-state.ts +1 -4
  90. package/src/main/silo.ts +14 -5
  91. package/src/main/subscribe.ts +0 -7
  92. package/src/main/timeline.ts +1 -18
  93. package/src/main/tokens.ts +245 -0
  94. package/src/main/transaction.ts +28 -60
  95. package/src/main/validators.ts +2 -2
  96. package/src/react/use-json.ts +15 -25
  97. package/src/react-devtools/store.ts +61 -45
  98. package/src/realtime/shared-room-store.ts +12 -25
  99. package/src/realtime-client/pull-mutable-atom-family-member.ts +5 -9
  100. package/src/realtime-client/pull-mutable-atom.ts +5 -9
  101. package/src/realtime-react/use-pull-mutable-atom.ts +3 -5
  102. package/src/realtime-react/use-pull-mutable-family-member.ts +3 -4
  103. package/src/realtime-server/realtime-mutable-family-provider.ts +3 -4
  104. package/src/realtime-server/realtime-mutable-provider.ts +2 -3
  105. package/src/realtime-server/realtime-server-stores/server-room-external-actions.ts +6 -5
  106. package/src/realtime-server/realtime-server-stores/server-user-store.ts +9 -18
  107. package/src/transceivers/set-rtx/set-rtx.ts +1 -1
  108. package/src/eslint-plugin/rules/synchronous-selector-dependencies.ts +0 -140
  109. package/src/eslint-plugin/walk.ts +0 -81
  110. package/src/internal/atom/create-standalone-atom.ts +0 -39
  111. package/src/internal/families/create-atom-family.ts +0 -38
  112. package/src/json/select-json-family.ts +0 -55
  113. package/src/json/select-json.ts +0 -19
package/src/main/index.ts CHANGED
@@ -1,14 +1,3 @@
1
- import type { Transceiver } from "atom.io/internal"
2
- import type { Canonical, Json, stringified } from "atom.io/json"
3
-
4
- import type { AtomFamilyToken } from "./atom"
5
- import type {
6
- SelectorFamilyToken,
7
- WritableSelectorFamilyToken,
8
- } from "./selector"
9
- import type { TimelineToken } from "./timeline"
10
- import type { TransactionToken } from "./transaction"
11
-
12
1
  export * from "./atom"
13
2
  export * from "./dispose-state"
14
3
  export * from "./find-state"
@@ -22,175 +11,11 @@ export * from "./set-state"
22
11
  export * from "./silo"
23
12
  export * from "./subscribe"
24
13
  export * from "./timeline"
14
+ export type * from "./tokens"
25
15
  export * from "./transaction"
26
16
  export * from "./validators"
27
17
 
28
18
  /**
29
- * @public
30
- * A token is an object that uniquely identifies a particular state, family, timeline, or transaction.
31
- *
32
- * While they represent one of these resources, they are not the resource itself. Think of them like paper currency representing money in the bank.
33
- *
34
- * Tokens are returned from resource creation functions, such as {@link atom} and {@link transaction}.
35
- *
36
- * Tokens can be used as parameters to functions that take a token, such as {@link getState}, {@link setState}, or {@link runTransaction}.
37
- *
38
- * Tokens are fully serializable, so they can be passed between processes.
39
- */
40
- export type AtomIOToken =
41
- | ReadableFamilyToken<any, any>
42
- | ReadableToken<any>
43
- | TimelineToken<any>
44
- | TransactionToken<any>
45
-
46
- /** @public */
47
- export type RegularAtomToken<T, K extends Canonical = any> = {
48
- /** The unique identifier of the atom. */
49
- key: string
50
- /** Discriminator. */
51
- type: `atom`
52
- /** Present if the atom belongs to a family. */
53
- family?: FamilyMetadata<K>
54
- /** Never present. This is a marker that preserves the type of the atom's value. */
55
- __T?: T
56
- }
57
- /** @public */
58
- export type MutableAtomToken<
59
- T extends Transceiver<any>,
60
- J extends Json.Serializable,
61
- K extends Canonical = any,
62
- > = {
63
- /** The unique identifier of the atom. */
64
- key: string
65
- /** Discriminator. */
66
- type: `mutable_atom`
67
- /** Present if the atom belongs to a family. */
68
- family?: FamilyMetadata<K>
69
- /** Never present. This is a marker that preserves the JSON form of the atom's transceiver value. */
70
- __J?: J
71
- /** Never present. This is a marker that preserves the type of the atom's transceiver value. */
72
- __U?: T extends Transceiver<infer Update> ? Update : never
73
- }
74
- /** @public */
75
- export type AtomToken<T, K extends Canonical = any> =
76
- | MutableAtomToken<T extends Transceiver<any> ? T : never, any, K>
77
- | RegularAtomToken<T, K>
78
-
79
- /** @public */
80
- export type WritablePureSelectorToken<T, K extends Canonical = any> = {
81
- /** The unique identifier of the selector. */
82
- key: string
83
- /** Discriminator. */
84
- type: `writable_pure_selector`
85
- /** Present if the selector belongs to a family. */
86
- family?: FamilyMetadata<K>
87
- /** Never present. This is a marker that preserves the type of the selector's value. */
88
- __T?: T
89
- }
90
- /** @public */
91
- export type WritableHeldSelectorToken<T, K extends Canonical = any> = {
92
- /** The unique identifier of the selector. */
93
- key: string
94
- /** Discriminator. */
95
- type: `writable_held_selector`
96
- /** Present if the selector belongs to a family. */
97
- family?: FamilyMetadata<K>
98
- /** Never present. This is a marker that preserves the type of the selector's value. */
99
- __T?: T
100
- }
101
- /** @public */
102
- export type ReadonlyPureSelectorToken<T, K extends Canonical = any> = {
103
- /** The unique identifier of the selector. */
104
- key: string
105
- /** Discriminator. */
106
- type: `readonly_pure_selector`
107
- /** Present if the selector belongs to a family. */
108
- family?: FamilyMetadata<K>
109
- /** Never present. This is a marker that preserves the type of the selector's value. */
110
- __T?: T
111
- }
112
- /** @public */
113
- export type ReadonlyHeldSelectorToken<T, K extends Canonical = any> = {
114
- /** The unique identifier of the selector. */
115
- key: string
116
- /** Discriminator. */
117
- type: `readonly_held_selector`
118
- /** Present if the selector belongs to a family. */
119
- family?: FamilyMetadata<K>
120
- /** Never present. This is a marker that preserves the type of the selector's value. */
121
- __T?: T
122
- }
123
-
124
- /** @public */
125
- export type PureSelectorToken<T, K extends Canonical = any> =
126
- | ReadonlyPureSelectorToken<T, K>
127
- | WritablePureSelectorToken<T, K>
128
-
129
- /** @public */
130
- export type HeldSelectorToken<T, K extends Canonical = any> =
131
- | ReadonlyHeldSelectorToken<T, K>
132
- | WritableHeldSelectorToken<T, K>
133
-
134
- /** @public */
135
- export type ReadonlySelectorToken<T, K extends Canonical = any> =
136
- | ReadonlyHeldSelectorToken<T, K>
137
- | ReadonlyPureSelectorToken<T, K>
138
-
139
- /** @public */
140
- export type WritableSelectorToken<T, K extends Canonical = any> =
141
- | WritableHeldSelectorToken<T, K>
142
- | WritablePureSelectorToken<T, K>
143
-
144
- /** @public */
145
- export type SelectorToken<T, K extends Canonical = any> =
146
- | ReadonlyHeldSelectorToken<T, K>
147
- | ReadonlyPureSelectorToken<T, K>
148
- | WritableHeldSelectorToken<T, K>
149
- | WritablePureSelectorToken<T, K>
150
-
151
- /**
152
- * @public
153
- * These states can be set.
154
- */
155
- export type WritableToken<T, K extends Canonical = any> =
156
- | AtomToken<T, K>
157
- | WritableSelectorToken<T, K>
158
- /**
159
- * @public
160
- * These states cannot be set.
161
- */
162
- export type ReadableToken<T, K extends Canonical = any> =
163
- | AtomToken<T, K>
164
- | SelectorToken<T, K>
165
-
166
- /**
167
- * @public
168
- * States belonging to this family can be set.
169
- */
170
- export type WritableFamilyToken<T, K extends Canonical> =
171
- | AtomFamilyToken<T, K>
172
- | WritableSelectorFamilyToken<T, K>
173
- /**
174
- * @public
175
- * States belonging to this family cannot be set.
176
- */
177
- export type ReadableFamilyToken<T, K extends Canonical> =
178
- | AtomFamilyToken<T, K>
179
- | SelectorFamilyToken<T, K>
180
-
181
- /**
182
- * @public
183
- * Identifies a state's connection to its family.
184
- */
185
- export type FamilyMetadata<K extends Canonical = any> = {
186
- /** The family's unique key. */
187
- key: string
188
- /** The family member's unique identifier, in the form of a string. */
189
- subKey: stringified<K>
190
- }
191
-
192
- /**
193
- * @public
194
19
  * Loadable is used to type atoms or selectors that may at some point be initialized to or set to a {@link Promise}.
195
20
  *
196
21
  * When a Promise is cached as the value of a state in atom.io, that state will be automatically set to the resolved value of the Promise when it is resolved.
package/src/main/join.ts CHANGED
@@ -14,9 +14,8 @@ import {
14
14
  IMPLICIT,
15
15
  } from "atom.io/internal"
16
16
  import type { Json } from "atom.io/json"
17
- import type { SetRTX, SetRTXJson } from "atom.io/transceivers/set-rtx"
17
+ import type { SetRTX } from "atom.io/transceivers/set-rtx"
18
18
 
19
- /** @public */
20
19
  // biome-ignore format: intersection
21
20
  export type JoinOptions<
22
21
  ASide extends string,
@@ -40,7 +39,6 @@ export type JoinOptions<
40
39
  }
41
40
  > & Partial<JunctionEntriesBase<AType, BType, Content>>
42
41
 
43
- /** @public */
44
42
  export type JoinToken<
45
43
  ASide extends string,
46
44
  AType extends string,
@@ -68,7 +66,6 @@ export type JoinToken<
68
66
  }
69
67
 
70
68
  /**
71
- * @public
72
69
  * Create a join, an interface for managing relations between two sets of keys.
73
70
  *
74
71
  * Use joins when it is important to view relationships from either side.
@@ -92,7 +89,6 @@ export function join<
92
89
  defaultContent?: undefined,
93
90
  ): JoinToken<ASide, AType, BSide, BType, Cardinality, null>
94
91
  /**
95
- * @public
96
92
  * Create a join, an interface for managing relations between two sets of keys.
97
93
  *
98
94
  * Use joins when it is important to view relationships from either side.
@@ -212,7 +208,6 @@ export type JoinStates<
212
208
  : never
213
209
 
214
210
  /**
215
- * @public
216
211
  * Find the current value of a relation owned by a {@link join}
217
212
  * @param token - The token of the join
218
213
  * @param key - The key of the relation to find
@@ -235,7 +230,6 @@ export function findRelations<
235
230
  }
236
231
 
237
232
  /**
238
- * @public
239
233
  * Change one or multiple relations owned by a {@link join}
240
234
  * @param token - The token of the join
241
235
  * @param change - A function that takes a {@link Junction} interface to edit the relations
@@ -255,7 +249,6 @@ export function editRelations<
255
249
  }
256
250
 
257
251
  /**
258
- * @public
259
252
  * @param token - The token of the join
260
253
  * @returns
261
254
  * A {@link MutableAtomFamilyToken} to access the internal relations
@@ -269,6 +262,6 @@ export function getInternalRelations<
269
262
  Content extends Json.Object | null,
270
263
  >(
271
264
  token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>,
272
- ): MutableAtomFamilyToken<SetRTX<string>, SetRTXJson<string>, string> {
265
+ ): MutableAtomFamilyToken<SetRTX<string>, string> {
273
266
  return getInternalRelationsFromStore(token, IMPLICIT.STORE)
274
267
  }
@@ -105,7 +105,7 @@ export const simpleLogger: Logger = {
105
105
 
106
106
  export class AtomIOLogger implements Logger {
107
107
  public logLevel: `error` | `info` | `warn` | null
108
- private readonly filter: LogFilter | undefined
108
+ public filter: LogFilter | undefined
109
109
  private readonly logger: Logger
110
110
 
111
111
  public constructor(
@@ -119,31 +119,31 @@ export class AtomIOLogger implements Logger {
119
119
  }
120
120
 
121
121
  public error: LogFn = (...args) => {
122
- const filterResult = this.filter?.(...args) ?? true
123
122
  if (this.logLevel !== null) {
123
+ const filterResult = this.filter?.(...args) ?? true
124
124
  if (filterResult === true) {
125
125
  this.logger.error(...args)
126
- } else if (filterResult !== false) {
126
+ } else if (filterResult) {
127
127
  this.logger.error(...filterResult)
128
128
  }
129
129
  }
130
130
  }
131
131
  public info: LogFn = (...args) => {
132
- const filterResult = this.filter?.(...args) ?? true
133
132
  if (this.logLevel === `info`) {
133
+ const filterResult = this.filter?.(...args) ?? true
134
134
  if (filterResult === true) {
135
135
  this.logger.info(...args)
136
- } else if (filterResult !== false) {
136
+ } else if (filterResult) {
137
137
  this.logger.info(...filterResult)
138
138
  }
139
139
  }
140
140
  }
141
141
  public warn: LogFn = (...args) => {
142
- const filterResult = this.filter?.(...args) ?? true
143
142
  if (this.logLevel !== `error` && this.logLevel !== null) {
143
+ const filterResult = this.filter?.(...args) ?? true
144
144
  if (filterResult === true) {
145
145
  this.logger.warn(...args)
146
- } else if (filterResult !== false) {
146
+ } else if (filterResult) {
147
147
  this.logger.warn(...filterResult)
148
148
  }
149
149
  }
@@ -4,7 +4,6 @@ import type { Canonical } from "atom.io/json"
4
4
  import type { WritableFamilyToken, WritableToken } from "."
5
5
 
6
6
  /**
7
- * @public
8
7
  * Set the value of a state into the implicit store back to its default value.
9
8
  * @param token - An atom or writable selector token.
10
9
  * @overload Default
@@ -12,7 +11,6 @@ import type { WritableFamilyToken, WritableToken } from "."
12
11
  */
13
12
  export function resetState(token: WritableToken<any>): void
14
13
  /**
15
- * @public
16
14
  * Set the value of a state into the implicit store back to its default value.
17
15
  * @param token - An atom family or writable selector family token.
18
16
  * @param key - The unique key of the state to set.
@@ -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,18 +22,7 @@ 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
35
- }
36
-
37
25
  /**
38
- * @public
39
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
40
27
  * @param timeline - A {@link TimelineToken}
41
28
  */
@@ -43,7 +30,6 @@ export const redo = (timeline: TimelineToken<any>): void => {
43
30
  timeTravel(IMPLICIT.STORE, `redo`, timeline)
44
31
  }
45
32
  /**
46
- * @public
47
33
  * Reverse the last update on the {@link timeline} and move the cursor to the previous update
48
34
  * @param timeline - A {@link TimelineToken}
49
35
  */
@@ -51,7 +37,6 @@ export const undo = (timeline: TimelineToken<any>): void => {
51
37
  timeTravel(IMPLICIT.STORE, `undo`, timeline)
52
38
  }
53
39
 
54
- /** @public */
55
40
  export type TimelineUpdate<ManagedAtom extends TimelineManageable> =
56
41
  | TimelineAtomUpdate<ManagedAtom>
57
42
  | TimelineMoleculeCreation
@@ -61,7 +46,6 @@ export type TimelineUpdate<ManagedAtom extends TimelineManageable> =
61
46
  | TimelineStateDisposal<AtomOnly<ManagedAtom>>
62
47
  | TimelineTransactionUpdate
63
48
 
64
- /** @public */
65
49
  export type TimelineOptions<ManagedAtom extends TimelineManageable> = {
66
50
  /** The unique identifier of the timeline */
67
51
  key: string
@@ -75,7 +59,6 @@ export type TimelineOptions<ManagedAtom extends TimelineManageable> = {
75
59
  }
76
60
 
77
61
  /**
78
- * @public
79
62
  * Create a timeline, a mechanism for recording, undoing, and replaying changes to groups of atoms
80
63
  * @param options - {@link TimelineOptions}
81
64
  * @returns A reference to the timeline created: a {@link TimelineToken}