atom.io 0.6.9 → 0.8.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 (170) hide show
  1. package/README.md +21 -2
  2. package/dist/index.d.mts +34 -421
  3. package/dist/index.d.ts +34 -421
  4. package/dist/index.js +248 -23
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +209 -4
  7. package/dist/index.mjs.map +1 -1
  8. package/internal/dist/index.d.mts +364 -0
  9. package/internal/dist/index.d.ts +364 -0
  10. package/internal/dist/index.js +1906 -0
  11. package/internal/dist/index.js.map +1 -0
  12. package/internal/dist/index.mjs +1830 -0
  13. package/internal/dist/index.mjs.map +1 -0
  14. package/internal/package.json +15 -0
  15. package/internal/src/atom/create-atom.ts +75 -0
  16. package/internal/src/atom/delete-atom.ts +10 -0
  17. package/internal/src/atom/index.ts +3 -0
  18. package/internal/src/atom/is-default.ts +37 -0
  19. package/internal/src/caching.ts +38 -0
  20. package/internal/src/families/create-atom-family.ts +59 -0
  21. package/internal/src/families/create-readonly-selector-family.ts +45 -0
  22. package/internal/src/families/create-selector-family.ts +67 -0
  23. package/internal/src/families/index.ts +3 -0
  24. package/internal/src/future.ts +39 -0
  25. package/internal/src/get-state-internal.ts +23 -0
  26. package/internal/src/index.ts +14 -0
  27. package/internal/src/mutable/create-mutable-atom-family.ts +25 -0
  28. package/internal/src/mutable/create-mutable-atom.ts +49 -0
  29. package/internal/src/mutable/get-json-token.ts +22 -0
  30. package/internal/src/mutable/get-update-token.ts +20 -0
  31. package/internal/src/mutable/index.ts +17 -0
  32. package/internal/src/mutable/is-atom-token-mutable.ts +7 -0
  33. package/internal/src/mutable/tracker-family.ts +61 -0
  34. package/internal/src/mutable/tracker.ts +164 -0
  35. package/internal/src/mutable/transceiver.ts +110 -0
  36. package/internal/src/operation.ts +68 -0
  37. package/internal/src/selector/create-read-write-selector.ts +65 -0
  38. package/internal/src/selector/create-readonly-selector.ts +49 -0
  39. package/internal/src/selector/create-selector.ts +65 -0
  40. package/internal/src/selector/index.ts +5 -0
  41. package/internal/src/selector/lookup-selector-sources.ts +20 -0
  42. package/internal/src/selector/register-selector.ts +61 -0
  43. package/internal/src/selector/trace-selector-atoms.ts +45 -0
  44. package/internal/src/selector/update-selector-atoms.ts +34 -0
  45. package/internal/src/set-state/become.ts +10 -0
  46. package/internal/src/set-state/copy-mutable-if-needed.ts +23 -0
  47. package/internal/src/set-state/copy-mutable-in-transaction.ts +59 -0
  48. package/internal/src/set-state/copy-mutable-into-new-store.ts +34 -0
  49. package/internal/src/set-state/emit-update.ts +23 -0
  50. package/internal/src/set-state/evict-downstream.ts +39 -0
  51. package/internal/src/set-state/index.ts +2 -0
  52. package/internal/src/set-state/set-atom-state.ts +38 -0
  53. package/internal/src/set-state/set-selector-state.ts +19 -0
  54. package/internal/src/set-state/set-state-internal.ts +18 -0
  55. package/internal/src/set-state/stow-update.ts +42 -0
  56. package/internal/src/store/deposit.ts +43 -0
  57. package/internal/src/store/index.ts +5 -0
  58. package/internal/src/store/lookup.ts +26 -0
  59. package/internal/src/store/store.ts +154 -0
  60. package/internal/src/store/withdraw-new-family-member.ts +53 -0
  61. package/internal/src/store/withdraw.ts +113 -0
  62. package/internal/src/subject.ts +21 -0
  63. package/internal/src/subscribe/index.ts +1 -0
  64. package/internal/src/subscribe/recall-state.ts +19 -0
  65. package/internal/src/subscribe/subscribe-to-root-atoms.ts +47 -0
  66. package/internal/src/timeline/add-atom-to-timeline.ts +189 -0
  67. package/internal/src/timeline/index.ts +3 -0
  68. package/internal/src/timeline/time-travel-internal.ts +91 -0
  69. package/internal/src/timeline/timeline-internal.ts +115 -0
  70. package/internal/src/transaction/abort-transaction.ts +12 -0
  71. package/internal/src/transaction/apply-transaction.ts +64 -0
  72. package/internal/src/transaction/build-transaction.ts +39 -0
  73. package/internal/src/transaction/index.ts +26 -0
  74. package/internal/src/transaction/redo-transaction.ts +22 -0
  75. package/internal/src/transaction/transaction-internal.ts +64 -0
  76. package/internal/src/transaction/undo-transaction.ts +22 -0
  77. package/introspection/dist/index.d.mts +3 -197
  78. package/introspection/dist/index.d.ts +3 -197
  79. package/introspection/dist/index.js +329 -4
  80. package/introspection/dist/index.js.map +1 -1
  81. package/introspection/dist/index.mjs +310 -4
  82. package/introspection/dist/index.mjs.map +1 -1
  83. package/introspection/src/attach-atom-index.ts +84 -0
  84. package/introspection/src/attach-introspection-states.ts +38 -0
  85. package/introspection/src/attach-selector-index.ts +90 -0
  86. package/introspection/src/attach-timeline-family.ts +59 -0
  87. package/introspection/src/attach-timeline-index.ts +38 -0
  88. package/introspection/src/attach-transaction-index.ts +40 -0
  89. package/introspection/src/attach-transaction-logs.ts +43 -0
  90. package/introspection/src/index.ts +20 -0
  91. package/json/dist/index.d.mts +10 -2
  92. package/json/dist/index.d.ts +10 -2
  93. package/json/dist/index.js +83 -26
  94. package/json/dist/index.js.map +1 -1
  95. package/json/dist/index.mjs +74 -3
  96. package/json/dist/index.mjs.map +1 -1
  97. package/json/src/index.ts +5 -0
  98. package/json/src/select-json-family.ts +35 -0
  99. package/json/src/select-json.ts +22 -0
  100. package/package.json +103 -63
  101. package/react/dist/index.d.mts +9 -17
  102. package/react/dist/index.d.ts +9 -17
  103. package/react/dist/index.js +44 -27
  104. package/react/dist/index.js.map +1 -1
  105. package/react/dist/index.mjs +24 -4
  106. package/react/dist/index.mjs.map +1 -1
  107. package/react/src/index.ts +2 -0
  108. package/react/src/store-context.tsx +12 -0
  109. package/react/src/store-hooks.ts +36 -0
  110. package/react-devtools/dist/index.css +50 -1
  111. package/react-devtools/dist/index.css.map +1 -1
  112. package/react-devtools/dist/index.d.mts +104 -71
  113. package/react-devtools/dist/index.d.ts +104 -71
  114. package/react-devtools/dist/index.js +2821 -45
  115. package/react-devtools/dist/index.js.map +1 -1
  116. package/react-devtools/dist/index.mjs +2790 -11
  117. package/react-devtools/dist/index.mjs.map +1 -1
  118. package/react-devtools/src/AtomIODevtools.tsx +109 -0
  119. package/react-devtools/src/Button.tsx +23 -0
  120. package/react-devtools/src/StateEditor.tsx +75 -0
  121. package/react-devtools/src/StateIndex.tsx +159 -0
  122. package/react-devtools/src/TimelineIndex.tsx +88 -0
  123. package/react-devtools/src/TransactionIndex.tsx +70 -0
  124. package/react-devtools/src/Updates.tsx +150 -0
  125. package/react-devtools/src/devtools.scss +310 -0
  126. package/react-devtools/src/index.ts +72 -0
  127. package/realtime-react/dist/index.d.mts +8 -22
  128. package/realtime-react/dist/index.d.ts +8 -22
  129. package/realtime-react/dist/index.js +87 -32
  130. package/realtime-react/dist/index.js.map +1 -1
  131. package/realtime-react/dist/index.mjs +62 -6
  132. package/realtime-react/dist/index.mjs.map +1 -1
  133. package/realtime-react/src/index.ts +7 -0
  134. package/realtime-react/src/realtime-context.tsx +29 -0
  135. package/realtime-react/src/use-pull-family-member.ts +15 -0
  136. package/realtime-react/src/use-pull-mutable-family-member.ts +20 -0
  137. package/realtime-react/src/use-pull-mutable.ts +17 -0
  138. package/realtime-react/src/use-pull.ts +15 -0
  139. package/realtime-react/src/use-push.ts +19 -0
  140. package/realtime-react/src/use-server-action.ts +18 -0
  141. package/realtime-testing/dist/index.d.mts +49 -0
  142. package/realtime-testing/dist/index.d.ts +49 -0
  143. package/realtime-testing/dist/index.js +147 -0
  144. package/realtime-testing/dist/index.js.map +1 -0
  145. package/realtime-testing/dist/index.mjs +116 -0
  146. package/realtime-testing/dist/index.mjs.map +1 -0
  147. package/realtime-testing/src/index.ts +1 -0
  148. package/realtime-testing/src/setup-realtime-test.tsx +161 -0
  149. package/src/atom.ts +64 -9
  150. package/src/index.ts +29 -31
  151. package/src/logger.ts +3 -3
  152. package/src/selector.ts +3 -3
  153. package/src/silo.ts +29 -20
  154. package/src/subscribe.ts +3 -3
  155. package/src/timeline.ts +2 -2
  156. package/transceivers/set-rtx/dist/index.d.mts +39 -0
  157. package/transceivers/set-rtx/dist/index.d.ts +39 -0
  158. package/transceivers/set-rtx/dist/index.js +213 -0
  159. package/transceivers/set-rtx/dist/index.js.map +1 -0
  160. package/transceivers/set-rtx/dist/index.mjs +211 -0
  161. package/transceivers/set-rtx/dist/index.mjs.map +1 -0
  162. package/{realtime → transceivers/set-rtx}/package.json +1 -1
  163. package/transceivers/set-rtx/src/index.ts +1 -0
  164. package/transceivers/set-rtx/src/set-rtx.ts +242 -0
  165. package/realtime/dist/index.d.mts +0 -23
  166. package/realtime/dist/index.d.ts +0 -23
  167. package/realtime/dist/index.js +0 -32
  168. package/realtime/dist/index.js.map +0 -1
  169. package/realtime/dist/index.mjs +0 -7
  170. package/realtime/dist/index.mjs.map +0 -1
package/README.md CHANGED
@@ -25,8 +25,27 @@
25
25
  npm i atom.io
26
26
  ```
27
27
  ```shell
28
- pnpm add atom.io
28
+ pnpm i atom.io
29
+ ```
30
+ ```shell
31
+ bun i atom.io
29
32
  ```
30
33
  <hr>
31
34
 
32
- Reactive state graph for node and the browser inspired by [Recoil](https://recoiljs.org/).
35
+ Fine-grained reactivity for JavaScript environments.
36
+
37
+ 💙 Inspired by [Recoil](https://recoiljs.org/).
38
+
39
+ # Usage
40
+
41
+ ```typescript
42
+ import { atom } from 'atom.io'
43
+
44
+ const countState = atom({
45
+ key: 'count',
46
+ default: 0
47
+ })
48
+ // { key: 'count', type: 'atom' }
49
+
50
+
51
+ ```
package/dist/index.d.mts CHANGED
@@ -1,412 +1,5 @@
1
- type primitive = boolean | number | string | null;
2
-
3
- type Serializable = primitive | Readonly<{
4
- [key: string]: Serializable;
5
- }> | ReadonlyArray<Serializable>;
6
- type Object$1<Key extends string = string, Value extends Serializable = Serializable> = Record<Key, Value>;
7
- type Array<Element extends Serializable = Serializable> = ReadonlyArray<Element>;
8
-
9
- type json_Array<Element extends Serializable = Serializable> = Array<Element>;
10
- type json_Serializable = Serializable;
11
- declare namespace json {
12
- export {
13
- json_Array as Array,
14
- Object$1 as Object,
15
- json_Serializable as Serializable,
16
- };
17
- }
18
-
19
- type Refinement<Unrefined, Refined extends Unrefined> = (value: Unrefined) => value is Refined;
20
- type Cardinality = `1:1` | `1:n` | `n:n`;
21
-
22
- interface JunctionEntries<Content extends Object$1 | null> extends Object$1 {
23
- readonly relations: [string, string[]][];
24
- readonly contents: [string, Content][];
25
- }
26
- interface JunctionSchema<ASide extends string, BSide extends string> extends Object$1 {
27
- readonly between: [a: ASide, b: BSide];
28
- readonly cardinality: Cardinality;
29
- }
30
- type JunctionAdvancedConfiguration<Content extends Object$1 | null> = {
31
- externalStore?: (Content extends null ? {
32
- getContent?: undefined;
33
- setContent?: undefined;
34
- deleteContent?: undefined;
35
- } : {
36
- getContent: (contentKey: string) => Content | undefined;
37
- setContent: (contentKey: string, content: Content) => void;
38
- deleteContent: (g: any) => void;
39
- }) & {
40
- addRelation: (a: string, b: string) => void;
41
- deleteRelation: (a: string, b: string) => void;
42
- getRelatedKeys: (key: string) => Set<string> | undefined;
43
- has: (a: string, b?: string) => boolean;
44
- };
45
- isContent?: Refinement<unknown, Content>;
46
- makeContentKey?: (a: string, b: string) => string;
47
- };
48
- type JunctionJSON<ASide extends string, BSide extends string, Content extends Object$1 | null> = JunctionEntries<Content> & JunctionSchema<ASide, BSide>;
49
- declare class Junction<ASide extends string, BSide extends string, Content extends Object$1 | null = null> {
50
- readonly a: ASide;
51
- readonly b: BSide;
52
- readonly cardinality: Cardinality;
53
- readonly relations: Map<string, Set<string>>;
54
- readonly contents: Map<string, Content>;
55
- isContent: Refinement<unknown, Content> | null;
56
- makeContentKey: (a: string, b: string) => string;
57
- getRelatedKeys(key: string): Set<string> | undefined;
58
- protected addRelation(a: string, b: string): void;
59
- protected deleteRelation(a: string, b: string): void;
60
- protected getContentInternal(contentKey: string): Content | undefined;
61
- protected setContent(contentKey: string, content: Content): void;
62
- protected deleteContent(contentKey: string): void;
63
- constructor(data: JunctionSchema<ASide, BSide> & Partial<JunctionEntries<Content>>, config?: JunctionAdvancedConfiguration<Content>);
64
- toJSON(): JunctionJSON<ASide, BSide, Content>;
65
- set(a: string, ...rest: Content extends null ? [b: string] : [b: string, content: Content]): this;
66
- set(relation: {
67
- [Key in ASide | BSide]: string;
68
- }, ...rest: Content extends null ? [] | [b?: undefined] : [content: Content]): this;
69
- delete(a: string, b?: string): this;
70
- delete(relation: Record<ASide | BSide, string> | Record<ASide, string> | Record<BSide, string>, b?: undefined): this;
71
- getRelatedKey(key: string): string | undefined;
72
- getContent(a: string, b: string): Content | undefined;
73
- getRelationEntries(input: Record<ASide, string> | Record<BSide, string>): [string, Content][];
74
- has(a: string, b?: string): boolean;
75
- }
76
-
77
- type OperationProgress = {
78
- open: false;
79
- } | {
80
- open: true;
81
- done: Set<string>;
82
- prev: Map<string, any>;
83
- time: number;
84
- token: StateToken<any>;
85
- };
86
- declare const openOperation: (token: StateToken<any>, store: Store) => void;
87
- declare const closeOperation: (store: Store) => void;
88
- declare const isDone: (key: string, store?: Store) => boolean;
89
- declare const markDone: (key: string, store?: Store) => void;
90
-
91
- declare const lookupSelectorSources: (key: string, store: Store) => (AtomToken<unknown> | ReadonlySelectorToken<unknown> | SelectorToken<unknown>)[];
92
-
93
- declare const registerSelector: (selectorKey: string, store?: Store) => Transactors;
94
-
95
- type Subscriber<T> = (value: T) => void;
96
- declare class Subject<T> {
97
- subscribers: Map<string, Subscriber<T>>;
98
- subscribe(key: string, subscriber: Subscriber<T>): () => void;
99
- private unsubscribe;
100
- next(value: T): void;
101
- }
102
-
103
- type Selector<T> = {
104
- key: string;
105
- type: `selector`;
106
- family?: FamilyMetadata;
107
- install: (store: Store) => void;
108
- subject: Subject<{
109
- newValue: T;
110
- oldValue: T;
111
- }>;
112
- get: () => T;
113
- set: (newValue: T | ((oldValue: T) => T)) => void;
114
- };
115
- type ReadonlySelector<T> = {
116
- key: string;
117
- type: `readonly_selector`;
118
- family?: FamilyMetadata;
119
- install: (store: Store) => void;
120
- subject: Subject<{
121
- newValue: T;
122
- oldValue: T;
123
- }>;
124
- get: () => T;
125
- };
126
- declare function selector__INTERNAL<T>(options: SelectorOptions<T>, family?: FamilyMetadata, store?: Store): SelectorToken<T>;
127
- declare function selector__INTERNAL<T>(options: ReadonlySelectorOptions<T>, family?: FamilyMetadata, store?: Store): ReadonlySelectorToken<T>;
128
-
129
- declare const traceSelectorAtoms: (selectorKey: string, dependency: ReadonlySelectorToken<unknown> | StateToken<unknown>, store: Store) => AtomToken<unknown>[];
130
- declare const traceAllSelectorAtoms: (selectorKey: string, store: Store) => AtomToken<unknown>[];
131
-
132
- declare const updateSelectorAtoms: (selectorKey: string, dependency: ReadonlySelectorToken<unknown> | StateToken<unknown>, store: Store) => void;
133
-
134
- type TimelineAtomUpdate = StateUpdate<unknown> & {
135
- key: string;
136
- type: `atom_update`;
137
- timestamp: number;
138
- family?: FamilyMetadata;
139
- };
140
- type TimelineSelectorUpdate = {
141
- key: string;
142
- type: `selector_update`;
143
- timestamp: number;
144
- atomUpdates: Omit<TimelineAtomUpdate, `timestamp`>[];
145
- };
146
- type TimelineTransactionUpdate = TransactionUpdate<ƒn> & {
147
- key: string;
148
- type: `transaction_update`;
149
- timestamp: number;
150
- };
151
- type Timeline = {
152
- type: `timeline`;
153
- key: string;
154
- at: number;
155
- timeTraveling: `into_future` | `into_past` | null;
156
- history: TimelineUpdate[];
157
- selectorTime: number | null;
158
- transactionKey: string | null;
159
- install: (store: Store) => void;
160
- subject: Subject<TimelineAtomUpdate | TimelineSelectorUpdate | TimelineTransactionUpdate | `redo` | `undo`>;
161
- };
162
- declare function timeline__INTERNAL(options: TimelineOptions, store?: Store, data?: Timeline | null): TimelineToken;
163
-
164
- declare const addAtomToTimeline: (atomToken: AtomToken<any>, tl: Timeline, store?: Store) => void;
165
-
166
- declare const redo__INTERNAL: (token: TimelineToken, store?: Store) => void;
167
- declare const undo__INTERNAL: (token: TimelineToken, store?: Store) => void;
168
-
169
- type Transaction<ƒ extends ƒn> = {
170
- key: string;
171
- type: `transaction`;
172
- install: (store: Store) => void;
173
- subject: Subject<TransactionUpdate<ƒ>>;
174
- run: (...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
175
- };
176
- declare function transaction__INTERNAL<ƒ extends ƒn>(options: TransactionOptions<ƒ>, store?: Store): TransactionToken<ƒ>;
177
- declare const target: (store?: Store) => StoreCore;
178
-
179
- declare const abortTransaction: (store: Store) => void;
180
-
181
- declare const applyTransaction: <ƒ extends ƒn>(output: ReturnType<ƒ>, store: Store) => void;
182
-
183
- declare const buildTransaction: (key: string, params: any[], store: Store) => void;
184
-
185
- declare const redoTransactionUpdate: <ƒ extends ƒn>(update: TransactionUpdate<ƒ>, store: Store) => void;
186
-
187
- declare const undoTransactionUpdate: <ƒ extends ƒn>(update: TransactionUpdate<ƒ>, store: Store) => void;
188
-
189
- declare const TRANSACTION_PHASES: readonly ["idle", "building", "applying"];
190
- type TransactionPhase = typeof TRANSACTION_PHASES[number];
191
- type TransactionUpdateInProgress<ƒ extends ƒn> = TransactionUpdate<ƒ> & {
192
- phase: `applying` | `building`;
193
- time: number;
194
- core: StoreCore;
195
- };
196
- type TransactionIdle = {
197
- phase: `idle`;
198
- };
199
- type TransactionStatus<ƒ extends ƒn> = TransactionIdle | TransactionUpdateInProgress<ƒ>;
200
-
201
- declare function deposit<T>(state: Atom<T>): AtomToken<T>;
202
- declare function deposit<T>(state: Selector<T>): SelectorToken<T>;
203
- declare function deposit<T>(state: Atom<T> | Selector<T>): StateToken<T>;
204
- declare function deposit<T>(state: ReadonlySelector<T>): ReadonlySelectorToken<T>;
205
- declare function deposit<T>(state: Transaction<T extends ƒn ? T : never>): TransactionToken<T>;
206
- declare function deposit<T>(state: Atom<T> | ReadonlySelector<T> | Selector<T>): ReadonlySelectorToken<T> | StateToken<T>;
207
-
208
- declare function lookup(key: string, store: Store): AtomToken<unknown> | ReadonlySelectorToken<unknown> | SelectorToken<unknown>;
209
-
210
- declare function withdraw<T>(token: AtomToken<T>, store: Store): Atom<T> | null;
211
- declare function withdraw<T>(token: SelectorToken<T>, store: Store): Selector<T> | null;
212
- declare function withdraw<T>(token: StateToken<T>, store: Store): Atom<T> | Selector<T> | null;
213
- declare function withdraw<T>(token: ReadonlySelectorToken<T>, store: Store): ReadonlySelector<T> | null;
214
- declare function withdraw<T>(token: TransactionToken<T>, store: Store): Transaction<T extends ƒn ? T : never> | null;
215
- declare function withdraw<T>(token: ReadonlySelectorToken<T> | StateToken<T>, store: Store): Atom<T> | ReadonlySelector<T> | Selector<T> | null;
216
- declare function withdraw<T>(token: TimelineToken, store: Store): Timeline | null;
217
-
218
- type StoreCore = Pick<Store, `atoms` | `atomsThatAreDefault` | `operation` | `readonlySelectors` | `selectorAtoms` | `selectorGraph` | `selectors` | `timelineAtoms` | `timelines` | `transactions` | `valueMap`>;
219
- declare class Store {
220
- valueMap: Map<string, any>;
221
- atoms: Map<string, Atom<any>>;
222
- selectors: Map<string, Selector<any>>;
223
- readonlySelectors: Map<string, ReadonlySelector<any>>;
224
- timelines: Map<string, Timeline>;
225
- transactions: Map<string, Transaction<ƒn>>;
226
- atomsThatAreDefault: Set<string>;
227
- timelineAtoms: Junction<"timelineKey", "atomKey", null>;
228
- selectorAtoms: Junction<"selectorKey", "atomKey", null>;
229
- selectorGraph: Junction<"upstreamSelectorKey", "downstreamSelectorKey", {
230
- source: string;
231
- }>;
232
- subject: {
233
- atomCreation: Subject<AtomToken<unknown>>;
234
- selectorCreation: Subject<ReadonlySelectorToken<unknown> | SelectorToken<unknown>>;
235
- transactionCreation: Subject<TransactionToken<ƒn>>;
236
- timelineCreation: Subject<TimelineToken>;
237
- operationStatus: Subject<OperationProgress>;
238
- };
239
- operation: OperationProgress;
240
- transactionStatus: TransactionStatus<ƒn>;
241
- config: {
242
- name: string;
243
- logger: Logger | null;
244
- logger__INTERNAL: Logger;
245
- };
246
- constructor(name: string, store?: Store | null);
247
- }
248
- declare const IMPLICIT: {
249
- STORE_INTERNAL: Store | undefined;
250
- readonly STORE: Store;
251
- };
252
- declare const clearStore: (store?: Store) => void;
253
-
254
- type Atom<T> = {
255
- key: string;
256
- type: `atom`;
257
- family?: FamilyMetadata;
258
- subject: Subject<{
259
- newValue: T;
260
- oldValue: T;
261
- }>;
262
- default: T;
263
- };
264
- declare function atom__INTERNAL<T>(options: AtomOptions<T>, family?: FamilyMetadata, store?: Store): AtomToken<T>;
265
-
266
- declare const isAtomDefault: (key: string, store?: Store) => boolean;
267
- declare const markAtomAsDefault: (key: string, store?: Store) => void;
268
- declare const markAtomAsNotDefault: (key: string, store?: Store) => void;
269
- declare const isSelectorDefault: (key: string, store?: Store) => boolean;
270
-
271
- declare const cacheValue: (key: string, value: unknown, store?: Store) => void;
272
- declare const readCachedValue: <T>(key: string, store?: Store) => T;
273
- declare const isValueCached: (key: string, store?: Store) => boolean;
274
-
275
- declare function atomFamily__INTERNAL<T, K extends Serializable>(options: AtomFamilyOptions<T, K>, store?: Store): AtomFamily<T, K>;
276
-
277
- declare function readonlySelectorFamily__INTERNAL<T, K extends Serializable>(options: ReadonlySelectorFamilyOptions<T, K>, store?: Store): ReadonlySelectorFamily<T, K>;
278
-
279
- declare function selectorFamily__INTERNAL<T, K extends Serializable>(options: SelectorFamilyOptions<T, K>, store?: Store): SelectorFamily<T, K>;
280
- declare function selectorFamily__INTERNAL<T, K extends Serializable>(options: ReadonlySelectorFamilyOptions<T, K>, store?: Store): ReadonlySelectorFamily<T, K>;
281
-
282
- declare const getState__INTERNAL: <T>(state: Atom<T> | ReadonlySelector<T> | Selector<T>, store?: Store) => T;
283
-
284
- declare const setState__INTERNAL: <T>(state: Atom<T> | Selector<T>, value: T | ((oldValue: T) => T), store?: Store) => void;
285
-
286
- declare const subscribeToRootAtoms: <T>(state: ReadonlySelector<T> | Selector<T>, store: Store) => (() => void)[] | null;
287
-
288
- type index_Atom<T> = Atom<T>;
289
- declare const index_IMPLICIT: typeof IMPLICIT;
290
- type index_OperationProgress = OperationProgress;
291
- type index_ReadonlySelector<T> = ReadonlySelector<T>;
292
- type index_Selector<T> = Selector<T>;
293
- type index_Store = Store;
294
- declare const index_Store: typeof Store;
295
- type index_StoreCore = StoreCore;
296
- type index_Subject<T> = Subject<T>;
297
- declare const index_Subject: typeof Subject;
298
- declare const index_TRANSACTION_PHASES: typeof TRANSACTION_PHASES;
299
- type index_Timeline = Timeline;
300
- type index_TimelineAtomUpdate = TimelineAtomUpdate;
301
- type index_TimelineSelectorUpdate = TimelineSelectorUpdate;
302
- type index_TimelineTransactionUpdate = TimelineTransactionUpdate;
303
- type index_Transaction<ƒ extends ƒn> = Transaction<ƒ>;
304
- type index_TransactionIdle = TransactionIdle;
305
- type index_TransactionPhase = TransactionPhase;
306
- type index_TransactionStatus<ƒ extends ƒn> = TransactionStatus<ƒ>;
307
- type index_TransactionUpdateInProgress<ƒ extends ƒn> = TransactionUpdateInProgress<ƒ>;
308
- declare const index_abortTransaction: typeof abortTransaction;
309
- declare const index_addAtomToTimeline: typeof addAtomToTimeline;
310
- declare const index_applyTransaction: typeof applyTransaction;
311
- declare const index_atomFamily__INTERNAL: typeof atomFamily__INTERNAL;
312
- declare const index_atom__INTERNAL: typeof atom__INTERNAL;
313
- declare const index_buildTransaction: typeof buildTransaction;
314
- declare const index_cacheValue: typeof cacheValue;
315
- declare const index_clearStore: typeof clearStore;
316
- declare const index_closeOperation: typeof closeOperation;
317
- declare const index_deposit: typeof deposit;
318
- declare const index_getState__INTERNAL: typeof getState__INTERNAL;
319
- declare const index_isAtomDefault: typeof isAtomDefault;
320
- declare const index_isDone: typeof isDone;
321
- declare const index_isSelectorDefault: typeof isSelectorDefault;
322
- declare const index_isValueCached: typeof isValueCached;
323
- declare const index_lookup: typeof lookup;
324
- declare const index_lookupSelectorSources: typeof lookupSelectorSources;
325
- declare const index_markAtomAsDefault: typeof markAtomAsDefault;
326
- declare const index_markAtomAsNotDefault: typeof markAtomAsNotDefault;
327
- declare const index_markDone: typeof markDone;
328
- declare const index_openOperation: typeof openOperation;
329
- declare const index_readCachedValue: typeof readCachedValue;
330
- declare const index_readonlySelectorFamily__INTERNAL: typeof readonlySelectorFamily__INTERNAL;
331
- declare const index_redoTransactionUpdate: typeof redoTransactionUpdate;
332
- declare const index_redo__INTERNAL: typeof redo__INTERNAL;
333
- declare const index_registerSelector: typeof registerSelector;
334
- declare const index_selectorFamily__INTERNAL: typeof selectorFamily__INTERNAL;
335
- declare const index_selector__INTERNAL: typeof selector__INTERNAL;
336
- declare const index_setState__INTERNAL: typeof setState__INTERNAL;
337
- declare const index_subscribeToRootAtoms: typeof subscribeToRootAtoms;
338
- declare const index_target: typeof target;
339
- declare const index_timeline__INTERNAL: typeof timeline__INTERNAL;
340
- declare const index_traceAllSelectorAtoms: typeof traceAllSelectorAtoms;
341
- declare const index_traceSelectorAtoms: typeof traceSelectorAtoms;
342
- declare const index_transaction__INTERNAL: typeof transaction__INTERNAL;
343
- declare const index_undoTransactionUpdate: typeof undoTransactionUpdate;
344
- declare const index_undo__INTERNAL: typeof undo__INTERNAL;
345
- declare const index_updateSelectorAtoms: typeof updateSelectorAtoms;
346
- declare const index_withdraw: typeof withdraw;
347
- declare namespace index {
348
- export {
349
- index_Atom as Atom,
350
- index_IMPLICIT as IMPLICIT,
351
- index_OperationProgress as OperationProgress,
352
- index_ReadonlySelector as ReadonlySelector,
353
- index_Selector as Selector,
354
- index_Store as Store,
355
- index_StoreCore as StoreCore,
356
- index_Subject as Subject,
357
- index_TRANSACTION_PHASES as TRANSACTION_PHASES,
358
- index_Timeline as Timeline,
359
- index_TimelineAtomUpdate as TimelineAtomUpdate,
360
- index_TimelineSelectorUpdate as TimelineSelectorUpdate,
361
- index_TimelineTransactionUpdate as TimelineTransactionUpdate,
362
- index_Transaction as Transaction,
363
- index_TransactionIdle as TransactionIdle,
364
- index_TransactionPhase as TransactionPhase,
365
- index_TransactionStatus as TransactionStatus,
366
- index_TransactionUpdateInProgress as TransactionUpdateInProgress,
367
- index_abortTransaction as abortTransaction,
368
- index_addAtomToTimeline as addAtomToTimeline,
369
- index_applyTransaction as applyTransaction,
370
- index_atomFamily__INTERNAL as atomFamily__INTERNAL,
371
- index_atom__INTERNAL as atom__INTERNAL,
372
- index_buildTransaction as buildTransaction,
373
- index_cacheValue as cacheValue,
374
- index_clearStore as clearStore,
375
- index_closeOperation as closeOperation,
376
- index_deposit as deposit,
377
- index_getState__INTERNAL as getState__INTERNAL,
378
- index_isAtomDefault as isAtomDefault,
379
- index_isDone as isDone,
380
- index_isSelectorDefault as isSelectorDefault,
381
- index_isValueCached as isValueCached,
382
- index_lookup as lookup,
383
- index_lookupSelectorSources as lookupSelectorSources,
384
- index_markAtomAsDefault as markAtomAsDefault,
385
- index_markAtomAsNotDefault as markAtomAsNotDefault,
386
- index_markDone as markDone,
387
- index_openOperation as openOperation,
388
- index_readCachedValue as readCachedValue,
389
- index_readonlySelectorFamily__INTERNAL as readonlySelectorFamily__INTERNAL,
390
- index_redoTransactionUpdate as redoTransactionUpdate,
391
- index_redo__INTERNAL as redo__INTERNAL,
392
- index_registerSelector as registerSelector,
393
- index_selectorFamily__INTERNAL as selectorFamily__INTERNAL,
394
- index_selector__INTERNAL as selector__INTERNAL,
395
- index_setState__INTERNAL as setState__INTERNAL,
396
- index_subscribeToRootAtoms as subscribeToRootAtoms,
397
- index_target as target,
398
- index_timeline__INTERNAL as timeline__INTERNAL,
399
- index_traceAllSelectorAtoms as traceAllSelectorAtoms,
400
- index_traceSelectorAtoms as traceSelectorAtoms,
401
- index_transaction__INTERNAL as transaction__INTERNAL,
402
- index_undoTransactionUpdate as undoTransactionUpdate,
403
- index_undo__INTERNAL as undo__INTERNAL,
404
- index_updateSelectorAtoms as updateSelectorAtoms,
405
- index_withdraw as withdraw,
406
- };
407
- }
408
-
409
- type ƒn = (...parameters: any[]) => any;
1
+ import { Transceiver, Subject, Store, TimelineAtomUpdate, TimelineSelectorUpdate, TimelineTransactionUpdate } from 'atom.io/internal';
2
+ import { Json, JsonInterface } from 'atom.io/json';
410
3
 
411
4
  type Effectors<T> = {
412
5
  setSelf: <V extends T>(next: V | ((oldValue: T) => V)) => void;
@@ -420,21 +13,35 @@ type AtomOptions<T> = {
420
13
  key: string;
421
14
  default: T | (() => T);
422
15
  effects?: AtomEffect<T>[];
423
- mutable?: boolean;
424
16
  };
17
+ type MutableAtomOptions<T extends Transceiver<any>, J extends Json.Serializable> = JsonInterface<T, J> & Omit<AtomOptions<T>, `default`> & {
18
+ default: () => T;
19
+ mutable: true;
20
+ };
21
+ declare function atom<T extends Transceiver<any>, J extends Json.Serializable>(options: MutableAtomOptions<T, J>): MutableAtomToken<T, J>;
425
22
  declare function atom<T>(options: AtomOptions<T>): AtomToken<T>;
426
- type AtomFamilyOptions<T, K extends Serializable> = {
23
+ type AtomFamilyOptions<T, K extends Json.Serializable> = {
427
24
  key: string;
428
25
  default: T | ((key: K) => T);
429
26
  effects?: (key: K) => AtomEffect<T>[];
430
27
  };
431
- type AtomFamily<T, K extends Serializable = Serializable> = ((key: K) => AtomToken<T>) & {
28
+ type AtomFamily<T, K extends Json.Serializable = Json.Serializable> = ((key: K) => AtomToken<T>) & {
432
29
  key: string;
433
30
  type: `atom_family`;
434
31
  subject: Subject<AtomToken<T>>;
435
32
  };
436
- declare function atomFamily<T, K extends Serializable>(options: AtomFamilyOptions<T, K>): AtomFamily<T, K>;
33
+ type MutableAtomFamilyOptions<T extends Transceiver<any>, J extends Json.Serializable, K extends Json.Serializable> = AtomFamilyOptions<T, K> & JsonInterface<T, J> & {
34
+ mutable: true;
35
+ };
36
+ type MutableAtomFamily<Core extends Transceiver<any>, SerializableCore extends Json.Serializable, Key extends Json.Serializable> = JsonInterface<Core, SerializableCore> & ((key: Key) => MutableAtomToken<Core, SerializableCore>) & {
37
+ key: `${string}::mutable`;
38
+ type: `atom_family`;
39
+ subject: Subject<MutableAtomToken<Core, SerializableCore>>;
40
+ };
41
+ declare function atomFamily<T extends Transceiver<any>, J extends Json.Serializable, K extends Json.Serializable>(options: MutableAtomFamilyOptions<T, J, K>): MutableAtomFamily<T, J, K>;
42
+ declare function atomFamily<T, K extends Json.Serializable>(options: AtomFamilyOptions<T, K>): AtomFamily<T, K>;
437
43
 
44
+ declare const NO_OP: () => void;
438
45
  type Logger = Pick<Console, `error` | `info` | `warn`>;
439
46
  declare const LOG_LEVELS: ReadonlyArray<keyof Logger>;
440
47
  declare const setLogLevel: (preferredLevel: `error` | `info` | `warn` | null, store?: Store) => void;
@@ -477,27 +84,27 @@ type ReadonlySelectorOptions<T> = {
477
84
  };
478
85
  declare function selector<T>(options: SelectorOptions<T>): SelectorToken<T>;
479
86
  declare function selector<T>(options: ReadonlySelectorOptions<T>): ReadonlySelectorToken<T>;
480
- type SelectorFamilyOptions<T, K extends Serializable> = {
87
+ type SelectorFamilyOptions<T, K extends Json.Serializable> = {
481
88
  key: string;
482
89
  get: (key: K) => Read<() => T>;
483
90
  set: (key: K) => Write<(newValue: T) => void>;
484
91
  };
485
- type ReadonlySelectorFamilyOptions<T, K extends Serializable> = {
92
+ type ReadonlySelectorFamilyOptions<T, K extends Json.Serializable> = {
486
93
  key: string;
487
94
  get: (key: K) => Read<() => T>;
488
95
  };
489
- type SelectorFamily<T, K extends Serializable = Serializable> = ((key: K) => SelectorToken<T>) & {
96
+ type SelectorFamily<T, K extends Json.Serializable = Json.Serializable> = ((key: K) => SelectorToken<T>) & {
490
97
  key: string;
491
98
  type: `selector_family`;
492
99
  subject: Subject<SelectorToken<T>>;
493
100
  };
494
- type ReadonlySelectorFamily<T, K extends Serializable = Serializable> = ((key: K) => ReadonlySelectorToken<T>) & {
101
+ type ReadonlySelectorFamily<T, K extends Json.Serializable = Json.Serializable> = ((key: K) => ReadonlySelectorToken<T>) & {
495
102
  key: string;
496
103
  type: `readonly_selector_family`;
497
104
  subject: Subject<ReadonlySelectorToken<T>>;
498
105
  };
499
- declare function selectorFamily<T, K extends Serializable>(options: SelectorFamilyOptions<T, K>): SelectorFamily<T, K>;
500
- declare function selectorFamily<T, K extends Serializable>(options: ReadonlySelectorFamilyOptions<T, K>): ReadonlySelectorFamily<T, K>;
106
+ declare function selectorFamily<T, K extends Json.Serializable>(options: SelectorFamilyOptions<T, K>): SelectorFamily<T, K>;
107
+ declare function selectorFamily<T, K extends Json.Serializable>(options: ReadonlySelectorFamilyOptions<T, K>): ReadonlySelectorFamily<T, K>;
501
108
 
502
109
  declare class Silo {
503
110
  store: Store;
@@ -524,7 +131,7 @@ type KeyedStateUpdate<T> = StateUpdate<T> & {
524
131
  family?: FamilyMetadata;
525
132
  };
526
133
  type UpdateHandler<T> = (update: StateUpdate<T>) => void;
527
- declare const subscribe: <T>(token: ReadonlySelectorToken<T> | StateToken<T>, handleUpdate: UpdateHandler<T>, key?: string, store?: Store) => (() => void);
134
+ declare function subscribe<T>(token: ReadonlySelectorToken<T> | StateToken<T>, handleUpdate: UpdateHandler<T>, key?: string, store?: Store): () => void;
528
135
  type TransactionUpdateHandler<ƒ extends ƒn> = (data: TransactionUpdate<ƒ>) => void;
529
136
  declare const subscribeToTransaction: <ƒ extends ƒn>(token: TransactionToken<ƒ>, handleUpdate: TransactionUpdateHandler<ƒ>, key?: string, store?: Store) => (() => void);
530
137
  declare const subscribeToTimeline: (token: TimelineToken, handleUpdate: (update: TimelineUpdate | `redo` | `undo`) => void, key?: string, store?: Store) => (() => void);
@@ -542,12 +149,17 @@ declare const timeline: (options: TimelineOptions) => TimelineToken;
542
149
  declare const redo: (token: TimelineToken) => void;
543
150
  declare const undo: (token: TimelineToken) => void;
544
151
 
152
+ type ƒn = (...parameters: any[]) => any;
545
153
  type AtomToken<_> = {
546
154
  key: string;
547
155
  type: `atom`;
548
156
  family?: FamilyMetadata;
549
157
  __brand?: _;
550
158
  };
159
+ interface MutableAtomToken<T extends Transceiver<any>, J extends Json.Serializable> extends AtomToken<T> {
160
+ __asJSON?: J;
161
+ __update?: T extends Transceiver<infer Update> ? Update : never;
162
+ }
551
163
  type SelectorToken<_> = {
552
164
  key: string;
553
165
  type: `selector`;
@@ -565,8 +177,9 @@ type FamilyMetadata = {
565
177
  key: string;
566
178
  subKey: string;
567
179
  };
180
+ declare const capitalize: (str: string) => string;
568
181
  declare const getState: <T>(token: ReadonlySelectorToken<T> | StateToken<T>, store?: Store) => T;
569
182
  declare const setState: <T, New extends T>(token: StateToken<T>, value: New | ((oldValue: T) => New), store?: Store) => void;
570
183
  declare const isDefault: (token: ReadonlySelectorToken<unknown> | StateToken<unknown>, store?: Store) => boolean;
571
184
 
572
- export { AtomEffect, AtomFamily, AtomFamilyOptions, AtomOptions, AtomToken, Effectors, FamilyMetadata, json as Json, KeyedStateUpdate, LOG_LEVELS, Logger, Read, ReadonlySelectorFamily, ReadonlySelectorFamilyOptions, ReadonlySelectorOptions, ReadonlySelectorToken, ReadonlyTransactors, SelectorFamily, SelectorFamilyOptions, SelectorOptions, SelectorToken, Silo, StateToken, StateUpdate, Store, TimelineOptions, TimelineToken, TimelineUpdate, TransactionIO, TransactionOptions, TransactionToken, TransactionUpdate, TransactionUpdateHandler, Transactors, UpdateHandler, Write, index as __INTERNAL__, atom, atomFamily, getState, isDefault, redo, runTransaction, selector, selectorFamily, setLogLevel, setState, subscribe, subscribeToTimeline, subscribeToTransaction, timeline, transaction, undo, useLogger, ƒn };
185
+ export { AtomEffect, AtomFamily, AtomFamilyOptions, AtomOptions, AtomToken, Effectors, FamilyMetadata, KeyedStateUpdate, LOG_LEVELS, Logger, MutableAtomFamily, MutableAtomFamilyOptions, MutableAtomOptions, MutableAtomToken, NO_OP, Read, ReadonlySelectorFamily, ReadonlySelectorFamilyOptions, ReadonlySelectorOptions, ReadonlySelectorToken, ReadonlyTransactors, SelectorFamily, SelectorFamilyOptions, SelectorOptions, SelectorToken, Silo, StateToken, StateUpdate, TimelineOptions, TimelineToken, TimelineUpdate, TransactionIO, TransactionOptions, TransactionToken, TransactionUpdate, TransactionUpdateHandler, Transactors, UpdateHandler, Write, atom, atomFamily, capitalize, getState, isDefault, redo, runTransaction, selector, selectorFamily, setLogLevel, setState, subscribe, subscribeToTimeline, subscribeToTransaction, timeline, transaction, undo, useLogger, ƒn };