atom.io 0.6.8 → 0.7.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 (214) hide show
  1. package/README.md +21 -2
  2. package/dist/index.d.mts +42 -461
  3. package/dist/index.d.ts +42 -461
  4. package/dist/index.js +128 -1792
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +75 -1742
  7. package/dist/index.mjs.map +1 -1
  8. package/internal/dist/index.d.mts +342 -0
  9. package/internal/dist/index.d.ts +342 -0
  10. package/internal/dist/index.js +1873 -0
  11. package/internal/dist/index.js.map +1 -0
  12. package/internal/dist/index.mjs +1798 -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/{src/internal → internal/src/atom}/is-default.ts +4 -2
  19. package/internal/src/caching.ts +21 -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/get-state-internal.ts +23 -0
  25. package/internal/src/index.ts +13 -0
  26. package/internal/src/mutable/create-mutable-atom-family.ts +25 -0
  27. package/internal/src/mutable/create-mutable-atom.ts +49 -0
  28. package/internal/src/mutable/get-json-token.ts +22 -0
  29. package/internal/src/mutable/get-update-token.ts +20 -0
  30. package/internal/src/mutable/index.ts +17 -0
  31. package/internal/src/mutable/is-atom-token-mutable.ts +7 -0
  32. package/internal/src/mutable/tracker-family.ts +61 -0
  33. package/internal/src/mutable/tracker.ts +164 -0
  34. package/internal/src/mutable/transceiver.ts +110 -0
  35. package/internal/src/operation.ts +68 -0
  36. package/{src/internal → internal/src}/selector/create-read-write-selector.ts +10 -13
  37. package/{src/internal → internal/src}/selector/create-readonly-selector.ts +9 -8
  38. package/internal/src/selector/create-selector.ts +65 -0
  39. package/{src/internal → internal/src}/selector/index.ts +1 -0
  40. package/internal/src/selector/lookup-selector-sources.ts +20 -0
  41. package/{src/internal → internal/src}/selector/register-selector.ts +13 -9
  42. package/{src/internal → internal/src}/selector/trace-selector-atoms.ts +4 -2
  43. package/{src/internal → internal/src}/selector/update-selector-atoms.ts +4 -3
  44. package/internal/src/set-state/become.ts +10 -0
  45. package/internal/src/set-state/copy-mutable-if-needed.ts +23 -0
  46. package/internal/src/set-state/copy-mutable-in-transaction.ts +59 -0
  47. package/internal/src/set-state/copy-mutable-into-new-store.ts +34 -0
  48. package/internal/src/set-state/emit-update.ts +23 -0
  49. package/internal/src/set-state/evict-downstream.ts +39 -0
  50. package/internal/src/set-state/index.ts +2 -0
  51. package/internal/src/set-state/set-atom-state.ts +38 -0
  52. package/internal/src/set-state/set-selector-state.ts +19 -0
  53. package/internal/src/set-state/set-state-internal.ts +18 -0
  54. package/internal/src/set-state/stow-update.ts +42 -0
  55. package/internal/src/store/deposit.ts +43 -0
  56. package/internal/src/store/index.ts +5 -0
  57. package/internal/src/store/lookup.ts +26 -0
  58. package/internal/src/store/store.ts +154 -0
  59. package/internal/src/store/withdraw-new-family-member.ts +53 -0
  60. package/internal/src/store/withdraw.ts +113 -0
  61. package/internal/src/subject.ts +21 -0
  62. package/internal/src/subscribe/index.ts +1 -0
  63. package/internal/src/subscribe/recall-state.ts +19 -0
  64. package/internal/src/subscribe/subscribe-to-root-atoms.ts +47 -0
  65. package/{src/internal → internal/src}/timeline/add-atom-to-timeline.ts +50 -29
  66. package/internal/src/timeline/index.ts +3 -0
  67. package/{src/internal → internal/src/timeline}/time-travel-internal.ts +6 -6
  68. package/{src/internal → internal/src/timeline}/timeline-internal.ts +20 -12
  69. package/{src/internal → internal/src}/transaction/abort-transaction.ts +1 -1
  70. package/{src/internal → internal/src}/transaction/apply-transaction.ts +25 -18
  71. package/{src/internal → internal/src}/transaction/build-transaction.ts +12 -6
  72. package/{src/internal → internal/src}/transaction/index.ts +3 -2
  73. package/{src/internal → internal/src}/transaction/redo-transaction.ts +4 -5
  74. package/{src/internal → internal/src/transaction}/transaction-internal.ts +16 -13
  75. package/{src/internal → internal/src}/transaction/undo-transaction.ts +4 -5
  76. package/introspection/dist/index.d.mts +12 -260
  77. package/introspection/dist/index.d.ts +12 -260
  78. package/introspection/dist/index.js +125 -140
  79. package/introspection/dist/index.js.map +1 -1
  80. package/introspection/dist/index.mjs +103 -116
  81. package/introspection/dist/index.mjs.map +1 -1
  82. package/{src/introspection → introspection/src}/attach-atom-index.ts +41 -30
  83. package/{src/introspection → introspection/src}/attach-introspection-states.ts +6 -10
  84. package/introspection/src/attach-selector-index.ts +90 -0
  85. package/{src/introspection → introspection/src}/attach-timeline-family.ts +16 -16
  86. package/introspection/src/attach-timeline-index.ts +38 -0
  87. package/introspection/src/attach-transaction-index.ts +40 -0
  88. package/{src/introspection → introspection/src}/attach-transaction-logs.ts +11 -8
  89. package/json/dist/index.d.mts +41 -2
  90. package/json/dist/index.d.ts +41 -2
  91. package/json/dist/index.js +88 -48
  92. package/json/dist/index.js.map +1 -1
  93. package/json/dist/index.mjs +76 -13
  94. package/json/dist/index.mjs.map +1 -1
  95. package/json/src/index.ts +5 -0
  96. package/json/src/select-json-family.ts +35 -0
  97. package/json/src/select-json.ts +22 -0
  98. package/package.json +105 -57
  99. package/react/dist/index.d.mts +9 -17
  100. package/react/dist/index.d.ts +9 -17
  101. package/react/dist/index.js +45 -77
  102. package/react/dist/index.js.map +1 -1
  103. package/react/dist/index.mjs +18 -34
  104. package/react/dist/index.mjs.map +1 -1
  105. package/react/src/store-context.tsx +12 -0
  106. package/react/src/store-hooks.ts +36 -0
  107. package/react-devtools/dist/index.css +1 -1
  108. package/react-devtools/dist/index.css.map +1 -1
  109. package/react-devtools/dist/index.d.mts +199 -230
  110. package/react-devtools/dist/index.d.ts +199 -230
  111. package/react-devtools/dist/index.js +610 -2466
  112. package/react-devtools/dist/index.js.map +1 -1
  113. package/react-devtools/dist/index.mjs +543 -2401
  114. package/react-devtools/dist/index.mjs.map +1 -1
  115. package/{src/react-devtools → react-devtools/src}/AtomIODevtools.tsx +5 -3
  116. package/{src/react-devtools → react-devtools/src}/Button.tsx +2 -3
  117. package/{src/react-devtools → react-devtools/src}/StateEditor.tsx +3 -2
  118. package/{src/react-devtools → react-devtools/src}/StateIndex.tsx +7 -4
  119. package/{src/react-devtools → react-devtools/src}/TimelineIndex.tsx +7 -11
  120. package/{src/react-devtools → react-devtools/src}/TransactionIndex.tsx +4 -4
  121. package/{src/react-devtools → react-devtools/src}/Updates.tsx +9 -4
  122. package/{src/react-devtools → react-devtools/src}/index.ts +5 -5
  123. package/realtime-react/dist/index.d.mts +9 -25
  124. package/realtime-react/dist/index.d.ts +9 -25
  125. package/realtime-react/dist/index.js +75 -193
  126. package/realtime-react/dist/index.js.map +1 -1
  127. package/realtime-react/dist/index.mjs +44 -148
  128. package/realtime-react/dist/index.mjs.map +1 -1
  129. package/realtime-react/src/index.ts +7 -0
  130. package/{src/realtime-react → realtime-react/src}/realtime-context.tsx +3 -4
  131. package/realtime-react/src/use-pull-family-member.ts +15 -0
  132. package/realtime-react/src/use-pull-mutable-family-member.ts +20 -0
  133. package/realtime-react/src/use-pull-mutable.ts +17 -0
  134. package/realtime-react/src/use-pull.ts +15 -0
  135. package/realtime-react/src/use-push.ts +19 -0
  136. package/realtime-react/src/use-server-action.ts +18 -0
  137. package/realtime-testing/dist/index.d.mts +49 -0
  138. package/realtime-testing/dist/index.d.ts +49 -0
  139. package/realtime-testing/dist/index.js +147 -0
  140. package/realtime-testing/dist/index.js.map +1 -0
  141. package/realtime-testing/dist/index.mjs +116 -0
  142. package/realtime-testing/dist/index.mjs.map +1 -0
  143. package/{src/realtime-testing → realtime-testing/src}/setup-realtime-test.tsx +10 -8
  144. package/src/atom.ts +64 -8
  145. package/src/index.ts +36 -29
  146. package/src/logger.ts +7 -7
  147. package/src/selector.ts +5 -5
  148. package/src/silo.ts +49 -43
  149. package/src/subscribe.ts +27 -22
  150. package/src/timeline.ts +9 -4
  151. package/src/transaction.ts +3 -4
  152. package/transceivers/set-rtx/dist/index.d.mts +39 -0
  153. package/transceivers/set-rtx/dist/index.d.ts +39 -0
  154. package/transceivers/set-rtx/dist/index.js +213 -0
  155. package/transceivers/set-rtx/dist/index.js.map +1 -0
  156. package/transceivers/set-rtx/dist/index.mjs +211 -0
  157. package/transceivers/set-rtx/dist/index.mjs.map +1 -0
  158. package/{realtime → transceivers/set-rtx}/package.json +1 -1
  159. package/transceivers/set-rtx/src/index.ts +1 -0
  160. package/transceivers/set-rtx/src/set-rtx.ts +242 -0
  161. package/realtime/dist/index.d.mts +0 -25
  162. package/realtime/dist/index.d.ts +0 -25
  163. package/realtime/dist/index.js +0 -190
  164. package/realtime/dist/index.js.map +0 -1
  165. package/realtime/dist/index.mjs +0 -151
  166. package/realtime/dist/index.mjs.map +0 -1
  167. package/src/internal/atom-internal.ts +0 -54
  168. package/src/internal/families-internal.ts +0 -144
  169. package/src/internal/get.ts +0 -129
  170. package/src/internal/index.ts +0 -15
  171. package/src/internal/operation.ts +0 -139
  172. package/src/internal/selector/lookup-selector-sources.ts +0 -16
  173. package/src/internal/selector-internal.ts +0 -58
  174. package/src/internal/set.ts +0 -99
  175. package/src/internal/store.ts +0 -151
  176. package/src/internal/subscribe-internal.ts +0 -88
  177. package/src/internal/timeline/index.ts +0 -1
  178. package/src/introspection/attach-selector-index.ts +0 -77
  179. package/src/introspection/attach-timeline-index.ts +0 -36
  180. package/src/introspection/attach-transaction-index.ts +0 -38
  181. package/src/json/index.ts +0 -1
  182. package/src/json/select-json.ts +0 -18
  183. package/src/react/store-context.tsx +0 -13
  184. package/src/react/store-hooks.ts +0 -47
  185. package/src/react-explorer/AtomIOExplorer.tsx +0 -218
  186. package/src/react-explorer/explorer-effects.ts +0 -20
  187. package/src/react-explorer/explorer-states.ts +0 -217
  188. package/src/react-explorer/index.ts +0 -23
  189. package/src/react-explorer/space-states.ts +0 -72
  190. package/src/react-explorer/view-states.ts +0 -41
  191. package/src/realtime/README.md +0 -33
  192. package/src/realtime/hook-composition/expose-family.ts +0 -101
  193. package/src/realtime/hook-composition/expose-single.ts +0 -38
  194. package/src/realtime/hook-composition/expose-timeline.ts +0 -60
  195. package/src/realtime/hook-composition/index.ts +0 -12
  196. package/src/realtime/hook-composition/receive-state.ts +0 -29
  197. package/src/realtime/hook-composition/receive-transaction.ts +0 -18
  198. package/src/realtime/index.ts +0 -1
  199. package/src/realtime-react/index.ts +0 -3
  200. package/src/realtime-react/realtime-hooks.ts +0 -39
  201. package/src/realtime-react/realtime-state.ts +0 -10
  202. package/src/realtime-react/use-pull-family-member.ts +0 -26
  203. package/src/realtime-react/use-pull-family.ts +0 -24
  204. package/src/realtime-react/use-pull.ts +0 -24
  205. package/src/realtime-react/use-push.ts +0 -27
  206. package/src/realtime-react/use-server-action.ts +0 -33
  207. package/src/tracker/index.ts +0 -3
  208. package/src/tracker/tracker.ts +0 -61
  209. package/src/web-effects/index.ts +0 -1
  210. package/src/web-effects/storage.ts +0 -30
  211. /package/{src/introspection → introspection/src}/index.ts +0 -0
  212. /package/{src/react → react/src}/index.ts +0 -0
  213. /package/{src/react-devtools → react-devtools/src}/devtools.scss +0 -0
  214. /package/{src/realtime-testing → realtime-testing/src}/index.ts +0 -0
@@ -1,189 +1,36 @@
1
- import { Refinement } from 'fp-ts/Refinement';
2
- import { AtomToken as AtomToken$1, ReadonlySelectorToken as ReadonlySelectorToken$1, SelectorToken as SelectorToken$1 } from 'atom.io';
1
+ import * as atom_io from 'atom.io';
2
+ import { FamilyMetadata, ƒn, TransactionUpdate, StateToken, TimelineUpdate, StateUpdate, AtomFamily, ReadonlySelectorFamily, SelectorFamily, AtomToken, ReadonlySelectorToken, SelectorToken, TransactionToken, TimelineToken, Logger } from 'atom.io';
3
+ import { Json } from 'atom.io/json';
3
4
 
4
- type PlainObject = Record<keyof any, unknown>;
5
-
6
- type ƒn = (...parameters: any[]) => any;
7
-
8
- type JsonInterface<T, J extends Serializable = Serializable> = {
9
- toJson: (t: T) => J;
10
- fromJson: (json: J) => T;
11
- };
12
-
13
- type primitive = boolean | number | string | null;
14
-
15
- type Serializable = primitive | Readonly<{
16
- [key: string]: Serializable;
17
- }> | ReadonlyArray<Serializable>;
18
- type Object$1<Key extends string = string, Value extends Serializable = Serializable> = Record<Key, Value>;
19
-
20
- type Identified = {
21
- id: string;
22
- };
23
-
24
- declare const RELATION_TYPES: readonly ["1:1", "1:n", "n:n"];
25
- type RelationType = typeof RELATION_TYPES[number];
26
- type RelationData<CONTENT extends Object$1 | null = null, A extends string = `from`, B extends string = `to`> = {
27
- contents: Object$1<string, CONTENT>;
28
- relations: Object$1<string, string[]>;
29
- relationType: RelationType;
30
- a: A;
31
- b: B;
32
- };
33
- type IsRelationDataOptions<CONTENT extends Object$1 | null = null, A extends string = `from`, B extends string = `to`> = {
34
- from?: A;
35
- to?: B;
36
- isContent?: (json: Serializable) => json is CONTENT;
37
- };
38
-
39
- type NullSafeUnion<Base, Extension> = Extension extends null ? Base : Base & Extension;
40
- type NullSafeRest<MaybeArg, IfArg = MaybeArg> = MaybeArg extends null ? [] | [undefined] : [IfArg];
5
+ type ClassSignature = abstract new (...args: any) => any;
41
6
 
42
- declare class Join<CONTENT extends Object$1 | null = null, A extends string = `from`, B extends string = `to`> implements RelationData<CONTENT, A, B> {
43
- readonly relationType: `1:1` | `1:n` | `n:n`;
44
- readonly a: A;
45
- readonly b: B;
46
- readonly relations: Record<string, string[]>;
47
- readonly contents: Record<string, CONTENT>;
48
- constructor(json?: Partial<RelationData<CONTENT, A, B>>);
49
- toJSON(): RelationData<CONTENT, A, B>;
50
- static fromJSON<CONTENT extends Object$1 | null, A extends string, B extends string>(json: Serializable, options?: IsRelationDataOptions<CONTENT, A, B>): Join<CONTENT, A, B>;
51
- from<AA extends string>(newA: AA): Join<CONTENT, AA, B>;
52
- to<BB extends string>(newB: BB): Join<CONTENT, A, BB>;
53
- makeJsonInterface: (...params: CONTENT extends null ? [
54
- ] : [Refinement<unknown, CONTENT>]) => JsonInterface<Join<CONTENT, A, B>, RelationData<CONTENT, A, B>>;
55
- getRelatedId(id: string): string | undefined;
56
- getRelatedIds(id: string): string[];
57
- getContent(idA: string, idB: string): CONTENT | undefined;
58
- getRelationEntries(id: string): [string, CONTENT][];
59
- getRelationRecord(id: string): Record<string, CONTENT>;
60
- getRelation(id: string): NullSafeUnion<Identified, CONTENT> | undefined;
61
- getRelations(id: string): NullSafeUnion<Identified, CONTENT>[];
62
- setRelations(subject: {
63
- [from in A]: string;
64
- } | {
65
- [to in B]: string;
66
- }, relations: NullSafeUnion<Identified, CONTENT>[]): Join<CONTENT, A, B>;
67
- set(relation: {
68
- [key in A | B]: string;
69
- }, ...rest: NullSafeRest<CONTENT>): Join<CONTENT, A, B>;
70
- remove(relation: Partial<Record<A | B, string>>): Join<CONTENT, A, B>;
7
+ type RefinementStrategy = ClassSignature | Refinement$1<unknown, any>;
8
+ type Supported<Refine extends RefinementStrategy> = Refine extends Refinement$1<unknown, infer T> ? T : Refine extends ClassSignature ? InstanceType<Refine> : never;
9
+ type RefinementSupport = Record<string, RefinementStrategy>;
10
+ declare class Refinery<SupportedTypes extends RefinementSupport> {
11
+ supported: SupportedTypes;
12
+ constructor(supported: SupportedTypes);
13
+ refine(input: unknown): {
14
+ [K in keyof SupportedTypes]: {
15
+ type: K;
16
+ data: Supported<SupportedTypes[K]>;
17
+ };
18
+ }[keyof SupportedTypes] | null;
71
19
  }
72
20
 
73
- type AtomFamily<T, K extends Serializable = Serializable> = ((key: K) => AtomToken<T>) & {
74
- key: string;
75
- type: `atom_family`;
76
- subject: Subject<AtomToken<T>>;
77
- };
78
-
79
- type Logger = Pick<Console, `error` | `info` | `warn`>;
80
-
81
- type TransactionToken<_> = {
82
- key: string;
83
- type: `transaction`;
84
- __brand?: _;
85
- };
86
- type TransactionUpdate<ƒ extends ƒn> = {
87
- key: string;
88
- atomUpdates: KeyedStateUpdate<unknown>[];
89
- params: Parameters<ƒ>;
90
- output: ReturnType<ƒ>;
91
- };
92
-
93
- type ReadonlySelectorFamily<T, K extends Serializable = Serializable> = ((key: K) => ReadonlySelectorToken<T>) & {
94
- key: string;
95
- type: `readonly_selector_family`;
96
- subject: Subject<ReadonlySelectorToken<T>>;
97
- };
98
-
99
- type StateUpdate<T> = {
100
- newValue: T;
101
- oldValue: T;
102
- };
103
- type KeyedStateUpdate<T> = StateUpdate<T> & {
104
- key: string;
105
- };
106
-
107
- type TimelineToken = {
108
- key: string;
109
- type: `timeline`;
110
- };
111
- type TimelineUpdate = TimelineAtomUpdate | TimelineSelectorUpdate | TimelineTransactionUpdate;
112
-
113
- type AtomToken<_> = {
114
- key: string;
115
- type: `atom`;
116
- family?: FamilyMetadata;
117
- __brand?: _;
118
- };
119
- type SelectorToken<_> = {
120
- key: string;
121
- type: `selector`;
122
- family?: FamilyMetadata;
123
- __brand?: _;
124
- };
125
- type StateToken<T> = AtomToken<T> | SelectorToken<T>;
126
- type ReadonlySelectorToken<_> = {
127
- key: string;
128
- type: `readonly_selector`;
129
- family?: FamilyMetadata;
130
- __brand?: _;
131
- };
132
- type FamilyMetadata = {
133
- key: string;
134
- subKey: string;
135
- };
136
-
137
- type StoreCore = Pick<Store, `atoms` | `atomsThatAreDefault` | `operation` | `readonlySelectors` | `selectorAtoms` | `selectorGraph` | `selectors` | `timelineAtoms` | `timelines` | `transactions` | `valueMap`>;
138
- interface Store {
139
- atoms: Map<string, Atom<any>>;
140
- atomsThatAreDefault: Set<string>;
141
- readonlySelectors: Map<string, ReadonlySelector<any>>;
142
- selectorAtoms: Join<null, `selectorKey`, `atomKey`>;
143
- selectorGraph: Join<{
144
- source: string;
145
- }>;
146
- selectors: Map<string, Selector<any>>;
147
- timelineAtoms: Join<null, `timelineKey`, `atomKey`>;
148
- timelines: Map<string, Timeline>;
149
- transactions: Map<string, Transaction<any>>;
150
- valueMap: Map<string, any>;
151
- subject: {
152
- atomCreation: Subject<AtomToken<unknown>>;
153
- selectorCreation: Subject<ReadonlySelectorToken<unknown> | SelectorToken<unknown>>;
154
- transactionCreation: Subject<TransactionToken<ƒn>>;
155
- timelineCreation: Subject<TimelineToken>;
156
- operationStatus: Subject<OperationProgress>;
157
- };
158
- operation: OperationProgress;
159
- transactionStatus: TransactionStatus<ƒn>;
160
- config: {
161
- name: string;
162
- logger: Logger | null;
163
- logger__INTERNAL: Logger;
164
- };
21
+ interface Refinement$1<A, B extends A> {
22
+ (a: A): a is B;
165
23
  }
166
24
 
167
- type Atom<T> = {
168
- key: string;
169
- type: `atom`;
170
- family?: FamilyMetadata;
171
- subject: Subject<{
172
- newValue: T;
173
- oldValue: T;
174
- }>;
175
- default: T;
176
- };
25
+ type PlainObject = Record<keyof any, unknown>;
177
26
 
178
- type OperationProgress = {
179
- open: false;
180
- } | {
181
- open: true;
182
- done: Set<string>;
183
- prev: Map<string, any>;
184
- time: number;
185
- token: StateToken<any>;
186
- };
27
+ declare class Subject<T> {
28
+ Subscriber: (value: T) => void;
29
+ subscribers: Map<string, this[`Subscriber`]>;
30
+ subscribe(key: string, subscriber: this[`Subscriber`]): () => void;
31
+ private unsubscribe;
32
+ next(value: T): void;
33
+ }
187
34
 
188
35
  type Selector<T> = {
189
36
  key: string;
@@ -209,20 +56,130 @@ type ReadonlySelector<T> = {
209
56
  get: () => T;
210
57
  };
211
58
 
212
- type Subscriber<T> = (value: T) => void;
213
- declare class Subject<T> {
214
- subscribers: Subscriber<T>[];
215
- subscribe(subscriber: Subscriber<T>): {
216
- unsubscribe: () => void;
59
+ type Transaction<ƒ extends ƒn> = {
60
+ key: string;
61
+ type: `transaction`;
62
+ install: (store: Store) => void;
63
+ subject: Subject<TransactionUpdate<ƒ>>;
64
+ run: (...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
65
+ };
66
+
67
+ type TransactionUpdateInProgress<ƒ extends ƒn> = TransactionUpdate<ƒ> & {
68
+ phase: `applying` | `building`;
69
+ time: number;
70
+ core: StoreCore;
71
+ };
72
+ type TransactionIdle = {
73
+ phase: `idle`;
74
+ };
75
+ type TransactionStatus<ƒ extends ƒn> = TransactionIdle | TransactionUpdateInProgress<ƒ>;
76
+
77
+ type primitive = boolean | number | string | null;
78
+
79
+ type Serializable = primitive | Readonly<{
80
+ [key: string]: Serializable;
81
+ }> | ReadonlyArray<Serializable>;
82
+ type Object$1<Key extends string = string, Value extends Serializable = Serializable> = Record<Key, Value>;
83
+
84
+ type Refinement<Unrefined, Refined extends Unrefined> = (value: Unrefined) => value is Refined;
85
+ type Cardinality = `1:1` | `1:n` | `n:n`;
86
+
87
+ interface JunctionEntries<Content extends Object$1 | null> extends Object$1 {
88
+ readonly relations: [string, string[]][];
89
+ readonly contents: [string, Content][];
90
+ }
91
+ interface JunctionSchema<ASide extends string, BSide extends string> extends Object$1 {
92
+ readonly between: [a: ASide, b: BSide];
93
+ readonly cardinality: Cardinality;
94
+ }
95
+ type JunctionAdvancedConfiguration<Content extends Object$1 | null> = {
96
+ externalStore?: (Content extends null ? {
97
+ getContent?: undefined;
98
+ setContent?: undefined;
99
+ deleteContent?: undefined;
100
+ } : {
101
+ getContent: (contentKey: string) => Content | undefined;
102
+ setContent: (contentKey: string, content: Content) => void;
103
+ deleteContent: (contentKey: string) => void;
104
+ }) & {
105
+ addRelation: (a: string, b: string) => void;
106
+ deleteRelation: (a: string, b: string) => void;
107
+ getRelatedKeys: (key: string) => Set<string> | undefined;
108
+ has: (a: string, b?: string) => boolean;
217
109
  };
218
- private unsubscribe;
219
- next(value: T): void;
110
+ isContent?: Refinement<unknown, Content>;
111
+ makeContentKey?: (a: string, b: string) => string;
112
+ };
113
+ type JunctionJSON<ASide extends string, BSide extends string, Content extends Object$1 | null> = JunctionEntries<Content> & JunctionSchema<ASide, BSide>;
114
+ declare class Junction<ASide extends string, BSide extends string, Content extends Object$1 | null = null> {
115
+ readonly a: ASide;
116
+ readonly b: BSide;
117
+ readonly cardinality: Cardinality;
118
+ readonly relations: Map<string, Set<string>>;
119
+ readonly contents: Map<string, Content>;
120
+ isContent: Refinement<unknown, Content> | null;
121
+ makeContentKey: (a: string, b: string) => string;
122
+ getRelatedKeys(key: string): Set<string> | undefined;
123
+ protected addRelation(a: string, b: string): void;
124
+ protected deleteRelation(a: string, b: string): void;
125
+ protected getContentInternal(contentKey: string): Content | undefined;
126
+ protected setContent(contentKey: string, content: Content): void;
127
+ protected deleteContent(contentKey: string): void;
128
+ constructor(data: JunctionSchema<ASide, BSide> & Partial<JunctionEntries<Content>>, config?: JunctionAdvancedConfiguration<Content>);
129
+ toJSON(): JunctionJSON<ASide, BSide, Content>;
130
+ set(a: string, ...rest: Content extends null ? [b: string] : [b: string, content: Content]): this;
131
+ set(relation: {
132
+ [Key in ASide | BSide]: string;
133
+ }, ...rest: Content extends null ? [] | [b?: undefined] : [content: Content]): this;
134
+ delete(a: string, b?: string): this;
135
+ delete(relation: Record<ASide | BSide, string> | Record<ASide, string> | Record<BSide, string>, b?: undefined): this;
136
+ getRelatedKey(key: string): string | undefined;
137
+ getContent(a: string, b: string): Content | undefined;
138
+ getRelationEntries(input: Record<ASide, string> | Record<BSide, string>): [string, Content][];
139
+ has(a: string, b?: string): boolean;
140
+ }
141
+
142
+ interface Transceiver<Signal extends Json.Serializable> {
143
+ do: (update: Signal) => void;
144
+ undo: (update: Signal) => void;
145
+ subscribe: (key: string, fn: (update: Signal) => void) => () => void;
220
146
  }
221
147
 
148
+ /**
149
+ * @internal Give the tracker a transceiver state and a store, and it will
150
+ * subscribe to the transceiver's inner value. When the inner value changes,
151
+ * the tracker will update its own state to reflect the change.
152
+ */
153
+ declare class Tracker<Mutable extends Transceiver<any>> {
154
+ private Update;
155
+ private initializeState;
156
+ private unsubscribeFromInnerValue;
157
+ private observeCore;
158
+ private updateCore;
159
+ mutableState: atom_io.MutableAtomToken<Mutable, Json.Serializable>;
160
+ latestUpdateState: atom_io.AtomToken<typeof this$1.Update | null>;
161
+ constructor(mutableState: atom_io.MutableAtomToken<Mutable, Json.Serializable>, store?: Store);
162
+ }
163
+
164
+ interface MutableAtom<T> extends Atom<T> {
165
+ mutable: true;
166
+ }
167
+
168
+ type OperationProgress = {
169
+ open: false;
170
+ } | {
171
+ open: true;
172
+ done: Set<string>;
173
+ prev: Map<string, any>;
174
+ time: number;
175
+ token: StateToken<any>;
176
+ };
177
+
222
178
  type TimelineAtomUpdate = StateUpdate<unknown> & {
223
179
  key: string;
224
180
  type: `atom_update`;
225
181
  timestamp: number;
182
+ family?: FamilyMetadata;
226
183
  };
227
184
  type TimelineSelectorUpdate = {
228
185
  key: string;
@@ -236,6 +193,7 @@ type TimelineTransactionUpdate = TransactionUpdate<ƒn> & {
236
193
  timestamp: number;
237
194
  };
238
195
  type Timeline = {
196
+ type: `timeline`;
239
197
  key: string;
240
198
  at: number;
241
199
  timeTraveling: `into_future` | `into_past` | null;
@@ -246,49 +204,60 @@ type Timeline = {
246
204
  subject: Subject<TimelineAtomUpdate | TimelineSelectorUpdate | TimelineTransactionUpdate | `redo` | `undo`>;
247
205
  };
248
206
 
249
- type Transaction<ƒ extends ƒn> = {
207
+ type StoreCore = Pick<Store, `atoms` | `atomsThatAreDefault` | `families` | `operation` | `readonlySelectors` | `selectorAtoms` | `selectorGraph` | `selectors` | `timelineAtoms` | `timelines` | `trackers` | `transactions` | `valueMap`>;
208
+ declare class Store {
209
+ valueMap: Map<string, any>;
210
+ atoms: Map<string, Atom<any> | MutableAtom<any>>;
211
+ selectors: Map<string, Selector<any>>;
212
+ readonlySelectors: Map<string, ReadonlySelector<any>>;
213
+ trackers: Map<string, Tracker<Transceiver<any>>>;
214
+ families: Map<string, AtomFamily<any, any> | ReadonlySelectorFamily<any, any> | SelectorFamily<any, any>>;
215
+ timelines: Map<string, Timeline>;
216
+ transactions: Map<string, Transaction<ƒn>>;
217
+ atomsThatAreDefault: Set<string>;
218
+ timelineAtoms: Junction<"timelineKey", "atomKey", null>;
219
+ selectorAtoms: Junction<"selectorKey", "atomKey", null>;
220
+ selectorGraph: Junction<"upstreamSelectorKey", "downstreamSelectorKey", {
221
+ source: string;
222
+ }>;
223
+ subject: {
224
+ atomCreation: Subject<AtomToken<unknown>>;
225
+ selectorCreation: Subject<ReadonlySelectorToken<unknown> | SelectorToken<unknown>>;
226
+ transactionCreation: Subject<TransactionToken<ƒn>>;
227
+ timelineCreation: Subject<TimelineToken>;
228
+ operationStatus: Subject<OperationProgress>;
229
+ };
230
+ operation: OperationProgress;
231
+ transactionStatus: TransactionStatus<ƒn>;
232
+ config: {
233
+ name: string;
234
+ logger: Logger | null;
235
+ logger__INTERNAL: Logger;
236
+ };
237
+ constructor(name: string, store?: Store | null);
238
+ }
239
+
240
+ type Atom<T> = {
250
241
  key: string;
251
- type: `transaction`;
242
+ type: `atom`;
243
+ family?: FamilyMetadata;
252
244
  install: (store: Store) => void;
253
- subject: Subject<TransactionUpdate<ƒ>>;
254
- run: (...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
255
- };
256
-
257
- type TransactionUpdateInProgress<ƒ extends ƒn> = TransactionUpdate<ƒ> & {
258
- phase: `applying` | `building`;
259
- time: number;
260
- core: StoreCore;
261
- };
262
- type TransactionIdle = {
263
- phase: `idle`;
245
+ subject: Subject<{
246
+ newValue: T;
247
+ oldValue: T;
248
+ }>;
249
+ default: T;
264
250
  };
265
- type TransactionStatus<ƒ extends ƒn> = TransactionIdle | TransactionUpdateInProgress<ƒ>;
266
251
 
267
- type AtomTokenIndex = StateTokenIndex<AtomToken$1<unknown>>;
252
+ type AtomTokenIndex = StateTokenIndex<AtomToken<unknown>>;
268
253
 
269
- type FamilyNode<Token extends AtomToken$1<unknown> | ReadonlySelectorToken$1<unknown> | SelectorToken$1<unknown>> = {
254
+ type FamilyNode<Token extends AtomToken<unknown> | ReadonlySelectorToken<unknown> | SelectorToken<unknown>> = {
270
255
  key: string;
271
256
  familyMembers: Record<string, Token>;
272
257
  };
273
- type StateTokenIndex<Token extends AtomToken$1<unknown> | ReadonlySelectorToken$1<unknown> | SelectorToken$1<unknown>> = Record<string, FamilyNode<Token> | Token>;
274
-
275
- type SelectorTokenIndex = StateTokenIndex<ReadonlySelectorToken$1<unknown> | SelectorToken$1<unknown>>;
258
+ type StateTokenIndex<Token extends AtomToken<unknown> | ReadonlySelectorToken<unknown> | SelectorToken<unknown>> = Record<string, FamilyNode<Token> | Token>;
276
259
 
277
- type ClassSignature = abstract new (...args: any) => any;
278
-
279
- type RefinementStrategy = ClassSignature | Refinement<unknown, any>;
280
- type Supported<Refine extends RefinementStrategy> = Refine extends Refinement<unknown, infer T> ? T : Refine extends ClassSignature ? InstanceType<Refine> : never;
281
- type RefinementSupport = Record<string, RefinementStrategy>;
282
- declare class Refinery<SupportedTypes extends RefinementSupport> {
283
- supported: SupportedTypes;
284
- constructor(supported: SupportedTypes);
285
- refine(input: unknown): {
286
- [K in keyof SupportedTypes]: {
287
- type: K;
288
- data: Supported<SupportedTypes[K]>;
289
- };
290
- }[keyof SupportedTypes] | null;
291
- }
260
+ type SelectorTokenIndex = StateTokenIndex<ReadonlySelectorToken<unknown> | SelectorToken<unknown>>;
292
261
 
293
262
  type Delta = {
294
263
  summary: string;
@@ -317,17 +286,17 @@ declare class Differ<Leaf extends Record<string, any>, Tree extends Record<strin
317
286
 
318
287
  declare const AtomIODevtools: () => JSX.Element;
319
288
 
320
- declare const atomIndex: ReadonlySelectorToken<AtomTokenIndex>;
321
- declare const selectorIndex: ReadonlySelectorToken<SelectorTokenIndex>;
322
- declare const transactionIndex: ReadonlySelectorToken<TransactionTokenn>[]>;
323
- declare const findTransactionLogState: ReadonlySelectorFamily<TransactionUpdaten>[]>;
324
- declare const timelineIndex: ReadonlySelectorToken<TimelineToken[]>;
325
- declare const findTimelineState: ReadonlySelectorFamily<Timeline>;
326
- declare const devtoolsAreOpenState: AtomToken<boolean>;
289
+ declare const atomIndex: atom_io.ReadonlySelectorToken<AtomTokenIndex>;
290
+ declare const selectorIndex: atom_io.ReadonlySelectorToken<SelectorTokenIndex>;
291
+ declare const transactionIndex: atom_io.ReadonlySelectorToken<atom_io.TransactionToken<atom_io.ƒn>[]>;
292
+ declare const findTransactionLogState: atom_io.ReadonlySelectorFamily<atom_io.TransactionUpdate<atom_io.ƒn>[]>;
293
+ declare const timelineIndex: atom_io.ReadonlySelectorToken<atom_io.TimelineToken[]>;
294
+ declare const findTimelineState: atom_io.ReadonlySelectorFamily<Timeline>;
295
+ declare const devtoolsAreOpenState: atom_io.AtomToken<boolean>;
327
296
  type DevtoolsView = `atoms` | `selectors` | `timelines` | `transactions`;
328
- declare const devtoolsViewSelectionState: AtomToken<DevtoolsView>;
329
- declare const devtoolsViewOptionsState: AtomToken<DevtoolsView[]>;
330
- declare const findViewIsOpenState: AtomFamily<boolean, string>;
297
+ declare const devtoolsViewSelectionState: atom_io.AtomToken<DevtoolsView>;
298
+ declare const devtoolsViewOptionsState: atom_io.AtomToken<DevtoolsView[]>;
299
+ declare const findViewIsOpenState: atom_io.AtomFamily<boolean, string>;
331
300
  declare const primitiveRefinery: Refinery<{
332
301
  number: (input: unknown) => input is number;
333
302
  string: (input: unknown) => input is string;