atom.io 0.4.1 → 0.6.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 (101) hide show
  1. package/README.md +38 -10
  2. package/dist/index.d.mts +614 -0
  3. package/dist/index.d.ts +130 -77
  4. package/dist/index.js +584 -347
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +582 -347
  7. package/dist/index.mjs.map +1 -1
  8. package/json/dist/index.d.mts +18 -0
  9. package/json/dist/index.d.ts +18 -0
  10. package/json/dist/index.js +51 -0
  11. package/json/dist/index.js.map +1 -0
  12. package/json/dist/index.mjs +15 -0
  13. package/json/dist/index.mjs.map +1 -0
  14. package/json/package.json +15 -0
  15. package/package.json +43 -9
  16. package/react/dist/index.d.mts +24 -0
  17. package/react/dist/index.d.ts +18 -11
  18. package/react/dist/index.js +45 -21
  19. package/react/dist/index.js.map +1 -1
  20. package/react/dist/index.mjs +31 -21
  21. package/react/dist/index.mjs.map +1 -1
  22. package/react-devtools/dist/index.d.mts +15 -0
  23. package/react-devtools/dist/index.d.ts +4 -4
  24. package/react-devtools/dist/index.js +1 -1
  25. package/react-devtools/dist/index.js.map +1 -1
  26. package/react-devtools/dist/index.mjs +1 -1
  27. package/react-devtools/dist/index.mjs.map +1 -1
  28. package/realtime/dist/index.d.mts +27 -0
  29. package/realtime/dist/index.d.ts +27 -0
  30. package/realtime/dist/index.js +191 -0
  31. package/realtime/dist/index.js.map +1 -0
  32. package/realtime/dist/index.mjs +152 -0
  33. package/realtime/dist/index.mjs.map +1 -0
  34. package/realtime/package.json +15 -0
  35. package/realtime-react/dist/index.d.mts +45 -0
  36. package/realtime-react/dist/index.d.ts +45 -0
  37. package/realtime-react/dist/index.js +213 -0
  38. package/realtime-react/dist/index.js.map +1 -0
  39. package/realtime-react/dist/index.mjs +168 -0
  40. package/realtime-react/dist/index.mjs.map +1 -0
  41. package/realtime-react/package.json +15 -0
  42. package/src/index.ts +21 -5
  43. package/src/internal/atom-internal.ts +1 -1
  44. package/src/internal/families-internal.ts +3 -3
  45. package/src/internal/get.ts +39 -15
  46. package/src/internal/index.ts +2 -0
  47. package/src/internal/meta/meta-state.ts +1 -1
  48. package/src/internal/operation.ts +3 -1
  49. package/src/internal/selector/create-read-write-selector.ts +62 -0
  50. package/src/internal/selector/create-readonly-selector.ts +52 -0
  51. package/src/internal/selector/index.ts +4 -0
  52. package/src/internal/selector/lookup-selector-sources.ts +16 -0
  53. package/src/internal/selector/register-selector.ts +57 -0
  54. package/src/internal/selector/trace-selector-atoms.ts +43 -0
  55. package/src/internal/selector/update-selector-atoms.ts +33 -0
  56. package/src/internal/selector-internal.ts +9 -197
  57. package/src/internal/set.ts +1 -1
  58. package/src/internal/store.ts +44 -17
  59. package/src/internal/subscribe-internal.ts +6 -1
  60. package/src/internal/time-travel-internal.ts +7 -7
  61. package/src/internal/timeline/add-atom-to-timeline.ts +164 -0
  62. package/src/internal/timeline/index.ts +1 -0
  63. package/src/internal/timeline-internal.ts +39 -146
  64. package/src/internal/transaction/abort-transaction.ts +12 -0
  65. package/src/internal/transaction/apply-transaction.ts +54 -0
  66. package/src/internal/transaction/build-transaction.ts +33 -0
  67. package/src/internal/transaction/index.ts +25 -0
  68. package/src/internal/transaction/redo-transaction.ts +23 -0
  69. package/src/internal/transaction/undo-transaction.ts +23 -0
  70. package/src/internal/transaction-internal.ts +16 -133
  71. package/src/json/index.ts +1 -0
  72. package/src/json/select-json.ts +18 -0
  73. package/src/react/index.ts +2 -46
  74. package/src/react/store-context.tsx +14 -0
  75. package/src/react/store-hooks.ts +48 -0
  76. package/src/react-devtools/AtomIODevtools.tsx +1 -1
  77. package/src/react-explorer/AtomIOExplorer.tsx +2 -2
  78. package/src/react-explorer/explorer-states.ts +5 -5
  79. package/src/react-explorer/index.ts +1 -1
  80. package/src/react-explorer/space-states.ts +8 -9
  81. package/src/realtime/README.md +33 -0
  82. package/src/realtime/hook-composition/expose-family.ts +101 -0
  83. package/src/realtime/hook-composition/expose-single.ts +38 -0
  84. package/src/realtime/hook-composition/index.ts +12 -0
  85. package/src/realtime/hook-composition/receive-state.ts +29 -0
  86. package/src/realtime/hook-composition/receive-transaction.ts +18 -0
  87. package/src/realtime/index.ts +1 -0
  88. package/src/realtime-react/index.ts +3 -0
  89. package/src/realtime-react/realtime-context.tsx +31 -0
  90. package/src/realtime-react/realtime-hooks.ts +39 -0
  91. package/src/realtime-react/realtime-state.ts +10 -0
  92. package/src/realtime-react/use-pull-family-member.ts +27 -0
  93. package/src/realtime-react/use-pull-family.ts +25 -0
  94. package/src/realtime-react/use-pull.ts +23 -0
  95. package/src/realtime-react/use-push.ts +26 -0
  96. package/src/realtime-react/use-server-action.ts +34 -0
  97. package/src/selector.ts +9 -6
  98. package/src/silo.ts +53 -0
  99. package/src/subscribe.ts +42 -2
  100. package/src/timeline.ts +10 -0
  101. package/src/transaction.ts +24 -12
package/dist/index.d.ts CHANGED
@@ -1,6 +1,13 @@
1
1
  import * as Rx from 'rxjs';
2
2
  import { Hamt } from 'hamt_plus';
3
- import { Refinement } from 'fp-ts/Refinement';
3
+ import { Refinement } from 'fp-ts/lib/Refinement';
4
+
5
+ type ƒn = (...parameters: any[]) => any;
6
+
7
+ type JsonInterface<T, J extends Json = Json> = {
8
+ toJson: (t: T) => J;
9
+ fromJson: (json: J) => T;
10
+ };
4
11
 
5
12
  type Primitive = boolean | number | string | null;
6
13
  type Serializable = Primitive | Readonly<{
@@ -23,6 +30,11 @@ type RelationData<CONTENT extends JsonObj | null = null, A extends string = `fro
23
30
  a: A;
24
31
  b: B;
25
32
  };
33
+ type IsRelationDataOptions<CONTENT extends JsonObj | null = null, A extends string = `from`, B extends string = `to`> = {
34
+ from?: A;
35
+ to?: B;
36
+ isContent?: (json: Json) => json is CONTENT;
37
+ };
26
38
 
27
39
  type NullSafeUnion<Base, Extension> = Extension extends null ? Base : Base & Extension;
28
40
  type NullSafeRest<MaybeArg> = MaybeArg extends null ? [] | [undefined] : [MaybeArg];
@@ -35,9 +47,11 @@ declare class Join<CONTENT extends JsonObj | null = null, A extends string = `fr
35
47
  readonly contents: Record<string, CONTENT>;
36
48
  constructor(json?: Partial<RelationData<CONTENT, A, B>>);
37
49
  toJSON(): RelationData<CONTENT, A, B>;
38
- static fromJSON<CONTENT extends JsonObj | null, A extends string, B extends string>(json: Json, isContent?: Refinement<unknown, CONTENT>, a?: A, b?: B): Join<CONTENT, A, B>;
50
+ static fromJSON<CONTENT extends JsonObj | null, A extends string, B extends string>(json: Json, options?: IsRelationDataOptions<CONTENT, A, B>): Join<CONTENT, A, B>;
39
51
  from<AA extends string>(newA: AA): Join<CONTENT, AA, B>;
40
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>>;
41
55
  getRelatedId(id: string): string | undefined;
42
56
  getRelatedIds(id: string): string[];
43
57
  getContent(idA: string, idB: string): CONTENT | undefined;
@@ -66,9 +80,8 @@ interface Store {
66
80
  source: string;
67
81
  }>;
68
82
  selectors: Hamt<Selector<any>, string>;
69
- timelines: Hamt<Timeline, string>;
70
83
  timelineAtoms: Join<null, `timelineKey`, `atomKey`>;
71
- timelineStore: Hamt<TimelineData, string>;
84
+ timelines: Hamt<Timeline, string>;
72
85
  transactions: Hamt<Transaction<any>, string>;
73
86
  valueMap: Hamt<any, string>;
74
87
  subject: {
@@ -85,7 +98,7 @@ interface Store {
85
98
  logger__INTERNAL: Logger;
86
99
  };
87
100
  }
88
- declare const createStore: (name: string) => Store;
101
+ declare const createStore: (name: string, store?: Store | null) => Store;
89
102
  declare const IMPLICIT: {
90
103
  STORE_INTERNAL: Store | undefined;
91
104
  readonly STORE: Store;
@@ -131,18 +144,19 @@ type Atom<T> = {
131
144
  declare function atom__INTERNAL<T>(options: AtomOptions<T>, family?: FamilyMetadata, store?: Store): AtomToken<T>;
132
145
 
133
146
  declare function atomFamily__INTERNAL<T, K extends Serializable>(options: AtomFamilyOptions<T, K>, store?: Store): AtomFamily<T, K>;
134
- declare function readonlySelectorFamily__INTERNAL<T, K extends Serializable>(options: SelectorFamilyOptions<T, K>, store?: Store): ReadonlySelectorFamily<T, K>;
147
+ declare function readonlySelectorFamily__INTERNAL<T, K extends Serializable>(options: ReadonlySelectorFamilyOptions<T, K>, store?: Store): ReadonlySelectorFamily<T, K>;
135
148
  declare function selectorFamily__INTERNAL<T, K extends Serializable>(options: SelectorFamilyOptions<T, K>, store?: Store): SelectorFamily<T, K>;
136
149
  declare function selectorFamily__INTERNAL<T, K extends Serializable>(options: ReadonlySelectorFamilyOptions<T, K>, store?: Store): ReadonlySelectorFamily<T, K>;
137
150
 
138
151
  declare const computeSelectorState: <T>(selector: ReadonlySelector<T> | Selector<T>) => T;
139
152
  declare function lookup(key: string, store: Store): AtomToken<unknown> | ReadonlySelectorToken<unknown> | SelectorToken<unknown>;
140
- declare function withdraw<T>(token: AtomToken<T>, store: Store): Atom<T>;
141
- declare function withdraw<T>(token: SelectorToken<T>, store: Store): Selector<T>;
142
- declare function withdraw<T>(token: StateToken<T>, store: Store): Atom<T> | Selector<T>;
143
- declare function withdraw<T>(token: ReadonlySelectorToken<T>, store: Store): ReadonlySelector<T>;
144
- declare function withdraw<T>(token: TransactionToken<T>, store: Store): Transaction<T extends ƒn ? T : never>;
145
- declare function withdraw<T>(token: ReadonlySelectorToken<T> | StateToken<T>, store: Store): Atom<T> | ReadonlySelector<T> | Selector<T>;
153
+ declare function withdraw<T>(token: AtomToken<T>, store: Store): Atom<T> | null;
154
+ declare function withdraw<T>(token: SelectorToken<T>, store: Store): Selector<T> | null;
155
+ declare function withdraw<T>(token: StateToken<T>, store: Store): Atom<T> | Selector<T> | null;
156
+ declare function withdraw<T>(token: ReadonlySelectorToken<T>, store: Store): ReadonlySelector<T> | null;
157
+ declare function withdraw<T>(token: TransactionToken<T>, store: Store): Transaction<T extends ƒn ? T : never> | null;
158
+ declare function withdraw<T>(token: ReadonlySelectorToken<T> | StateToken<T>, store: Store): Atom<T> | ReadonlySelector<T> | Selector<T> | null;
159
+ declare function withdraw<T>(token: TimelineToken, store: Store): Timeline | null;
146
160
  declare function deposit<T>(state: Atom<T>): AtomToken<T>;
147
161
  declare function deposit<T>(state: Selector<T>): SelectorToken<T>;
148
162
  declare function deposit<T>(state: Atom<T> | Selector<T>): StateToken<T>;
@@ -210,32 +224,11 @@ declare const storeSelector: (selector: Selector<any>, store?: Store) => void;
210
224
  declare const storeReadonlySelector: (selector: ReadonlySelector<any>, store?: Store) => void;
211
225
  declare const hasKeyBeenUsed: (key: string, store?: Store) => boolean;
212
226
 
213
- type ƒn = (...parameters: any[]) => any;
214
- type Transactors = {
215
- get: <S>(state: ReadonlySelectorToken<S> | StateToken<S>) => S;
216
- set: <S>(state: StateToken<S>, newValue: S | ((oldValue: S) => S)) => void;
217
- };
218
- type ReadonlyTransactors = Pick<Transactors, `get`>;
219
- type Read<ƒ extends ƒn> = (transactors: ReadonlyTransactors, ...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
220
- type Write<ƒ extends ƒn> = (transactors: Transactors, ...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
221
- type TransactionOptions<ƒ extends ƒn> = {
222
- key: string;
223
- do: Write<ƒ>;
224
- };
225
- type Transaction<ƒ extends ƒn> = {
226
- key: string;
227
- type: `transaction`;
228
- run: (...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
229
- subject: Rx.Subject<TransactionUpdate<ƒ>>;
230
- };
231
- type TransactionIO<Token extends TransactionToken<any>> = Token extends TransactionToken<infer ƒ> ? ƒ : never;
232
- declare function transaction<ƒ extends ƒn>(options: TransactionOptions<ƒ>): TransactionToken<ƒ>;
233
- declare const runTransaction: <ƒ extends ƒn>(token: TransactionToken<ƒ>, store?: Store) => (...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
234
-
235
227
  type Selector<T> = {
236
228
  key: string;
237
229
  type: `selector`;
238
230
  family?: FamilyMetadata;
231
+ install: (store: Store) => void;
239
232
  subject: Rx.Subject<{
240
233
  newValue: T;
241
234
  oldValue: T;
@@ -247,19 +240,50 @@ type ReadonlySelector<T> = {
247
240
  key: string;
248
241
  type: `readonly_selector`;
249
242
  family?: FamilyMetadata;
243
+ install: (store: Store) => void;
250
244
  subject: Rx.Subject<{
251
245
  newValue: T;
252
246
  oldValue: T;
253
247
  }>;
254
248
  get: () => T;
255
249
  };
250
+ declare function selector__INTERNAL<T>(options: SelectorOptions<T>, family?: FamilyMetadata, store?: Store): SelectorToken<T>;
251
+ declare function selector__INTERNAL<T>(options: ReadonlySelectorOptions<T>, family?: FamilyMetadata, store?: Store): ReadonlySelectorToken<T>;
252
+
256
253
  declare const lookupSelectorSources: (key: string, store: Store) => (AtomToken<unknown> | ReadonlySelectorToken<unknown> | SelectorToken<unknown>)[];
254
+
255
+ type TransactionToken<_> = {
256
+ key: string;
257
+ type: `transaction`;
258
+ __brand?: _;
259
+ };
260
+ type TransactionUpdate<ƒ extends ƒn> = {
261
+ key: string;
262
+ atomUpdates: KeyedStateUpdate<unknown>[];
263
+ params: Parameters<ƒ>;
264
+ output: ReturnType<ƒ>;
265
+ };
266
+ type Transactors = {
267
+ get: <S>(state: ReadonlySelectorToken<S> | StateToken<S>) => S;
268
+ set: <S>(state: StateToken<S>, newValue: S | ((oldValue: S) => S)) => void;
269
+ };
270
+ type ReadonlyTransactors = Pick<Transactors, `get`>;
271
+ type Read<ƒ extends ƒn> = (transactors: ReadonlyTransactors, ...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
272
+ type Write<ƒ extends ƒn> = (transactors: Transactors, ...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
273
+ type TransactionOptions<ƒ extends ƒn> = {
274
+ key: string;
275
+ do: Write<ƒ>;
276
+ };
277
+ type TransactionIO<Token extends TransactionToken<any>> = Token extends TransactionToken<infer ƒ> ? ƒ : never;
278
+ declare function transaction<ƒ extends ƒn>(options: TransactionOptions<ƒ>): TransactionToken<ƒ>;
279
+ declare const runTransaction: <ƒ extends ƒn>(token: TransactionToken<ƒ>, store?: Store) => (...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
280
+
281
+ declare const registerSelector: (selectorKey: string, store?: Store) => Transactors;
282
+
257
283
  declare const traceSelectorAtoms: (selectorKey: string, dependency: ReadonlySelectorToken<unknown> | StateToken<unknown>, store: Store) => AtomToken<unknown>[];
258
284
  declare const traceAllSelectorAtoms: (selectorKey: string, store: Store) => AtomToken<unknown>[];
285
+
259
286
  declare const updateSelectorAtoms: (selectorKey: string, dependency: ReadonlySelectorToken<unknown> | StateToken<unknown>, store: Store) => void;
260
- declare const registerSelector: (selectorKey: string, store?: Store) => Transactors;
261
- declare function selector__INTERNAL<T>(options: SelectorOptions<T>, family?: FamilyMetadata, store?: Store): SelectorToken<T>;
262
- declare function selector__INTERNAL<T>(options: ReadonlySelectorOptions<T>, family?: FamilyMetadata, store?: Store): ReadonlySelectorToken<T>;
263
287
 
264
288
  declare const evictDownStream: <T>(state: Atom<T>, store?: Store) => void;
265
289
  declare const setAtomState: <T>(atom: Atom<T>, next: T | ((oldValue: T) => T), store?: Store) => void;
@@ -276,62 +300,68 @@ declare const subscribeToRootAtoms: <T>(state: ReadonlySelector<T> | Selector<T>
276
300
  declare const redo__INTERNAL: (token: TimelineToken, store?: Store) => void;
277
301
  declare const undo__INTERNAL: (token: TimelineToken, store?: Store) => void;
278
302
 
279
- type Timeline = {
303
+ type TimelineAtomUpdate = StateUpdate<unknown> & {
280
304
  key: string;
281
- type: `timeline`;
282
- next: () => void;
283
- prev: () => void;
284
- };
285
- type TimelineAtomUpdate = KeyedStateUpdate<unknown> & {
286
305
  type: `atom_update`;
306
+ timestamp: number;
287
307
  };
288
308
  type TimelineSelectorUpdate = {
289
309
  key: string;
290
310
  type: `selector_update`;
291
- atomUpdates: TimelineAtomUpdate[];
311
+ timestamp: number;
312
+ atomUpdates: Omit<TimelineAtomUpdate, `timestamp`>[];
292
313
  };
293
314
  type TimelineTransactionUpdate = TransactionUpdate<ƒn> & {
315
+ key: string;
294
316
  type: `transaction_update`;
317
+ timestamp: number;
295
318
  };
296
- type TimelineData = {
319
+ type Timeline = {
320
+ key: string;
297
321
  at: number;
298
322
  timeTraveling: boolean;
299
- history: (TimelineAtomUpdate | TimelineSelectorUpdate | TimelineTransactionUpdate)[];
323
+ history: TimelineUpdate[];
300
324
  selectorTime: number | null;
301
325
  transactionKey: string | null;
326
+ install: (store: Store) => void;
327
+ subject: Rx.Subject<TimelineAtomUpdate | TimelineSelectorUpdate | TimelineTransactionUpdate>;
302
328
  };
303
- declare function timeline__INTERNAL(options: TimelineOptions, store?: Store): TimelineToken;
329
+ declare function timeline__INTERNAL(options: TimelineOptions, store?: Store, data?: Timeline | null): TimelineToken;
304
330
 
305
- declare const TRANSACTION_PHASES: readonly ["idle", "building", "applying"];
306
- type TransactionPhase = (typeof TRANSACTION_PHASES)[number];
307
- type KeyedStateUpdate<T> = StateUpdate<T> & {
308
- key: string;
309
- };
310
- type TransactionUpdate<ƒ extends ƒn> = {
331
+ type Transaction<ƒ extends ƒn> = {
311
332
  key: string;
312
- atomUpdates: KeyedStateUpdate<unknown>[];
313
- params: Parameters<ƒ>;
314
- output: ReturnType<ƒ>;
333
+ type: `transaction`;
334
+ install: (store: Store) => void;
335
+ subject: Rx.Subject<TransactionUpdate<ƒ>>;
336
+ run: (...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
315
337
  };
338
+ declare function transaction__INTERNAL<ƒ extends ƒn>(options: TransactionOptions<ƒ>, store?: Store): TransactionToken<ƒ>;
339
+ declare const target: (store?: Store) => StoreCore;
340
+
341
+ declare const abortTransaction: (store: Store) => void;
342
+
343
+ declare const applyTransaction: <ƒ extends ƒn>(output: ReturnType<ƒ>, store: Store) => void;
344
+
345
+ declare const buildTransaction: (key: string, params: any[], store: Store) => void;
346
+
347
+ declare const redoTransactionUpdate: <ƒ extends ƒn>(update: TransactionUpdate<ƒ>, store: Store) => void;
348
+
349
+ declare const undoTransactionUpdate: <ƒ extends ƒn>(update: TransactionUpdate<ƒ>, store: Store) => void;
350
+
351
+ declare const TRANSACTION_PHASES: readonly ["idle", "building", "applying"];
352
+ type TransactionPhase = (typeof TRANSACTION_PHASES)[number];
316
353
  type TransactionUpdateInProgress<ƒ extends ƒn> = TransactionUpdate<ƒ> & {
317
354
  phase: `applying` | `building`;
355
+ time: number;
318
356
  core: StoreCore;
319
357
  };
320
358
  type TransactionIdle = {
321
359
  phase: `idle`;
322
360
  };
323
361
  type TransactionStatus<ƒ extends ƒn> = TransactionIdle | TransactionUpdateInProgress<ƒ>;
324
- declare const buildTransaction: (key: string, params: any[], store: Store) => void;
325
- declare const applyTransaction: <ƒ extends ƒn>(output: ReturnType<ƒ>, store: Store) => void;
326
- declare const undoTransactionUpdate: <ƒ extends ƒn>(update: TransactionUpdate<ƒ>, store: Store) => void;
327
- declare const redoTransactionUpdate: <ƒ extends ƒn>(update: TransactionUpdate<ƒ>, store: Store) => void;
328
- declare const abortTransaction: (store: Store) => void;
329
- declare function transaction__INTERNAL<ƒ extends ƒn>(options: TransactionOptions<ƒ>, store?: Store): TransactionToken<ƒ>;
330
- declare const target: (store?: Store) => StoreCore;
331
362
 
332
363
  type index_Atom<T> = Atom<T>;
333
364
  declare const index_IMPLICIT: typeof IMPLICIT;
334
- type index_KeyedStateUpdate<T> = KeyedStateUpdate<T>;
335
365
  type index_OperationProgress = OperationProgress;
336
366
  type index_ReadonlySelector<T> = ReadonlySelector<T>;
337
367
  type index_Selector<T> = Selector<T>;
@@ -340,13 +370,12 @@ type index_StoreCore = StoreCore;
340
370
  declare const index_TRANSACTION_PHASES: typeof TRANSACTION_PHASES;
341
371
  type index_Timeline = Timeline;
342
372
  type index_TimelineAtomUpdate = TimelineAtomUpdate;
343
- type index_TimelineData = TimelineData;
344
373
  type index_TimelineSelectorUpdate = TimelineSelectorUpdate;
345
374
  type index_TimelineTransactionUpdate = TimelineTransactionUpdate;
375
+ type index_Transaction<ƒ extends ƒn> = Transaction<ƒ>;
346
376
  type index_TransactionIdle = TransactionIdle;
347
377
  type index_TransactionPhase = TransactionPhase;
348
378
  type index_TransactionStatus<ƒ extends ƒn> = TransactionStatus<ƒ>;
349
- type index_TransactionUpdate<ƒ extends ƒn> = TransactionUpdate<ƒ>;
350
379
  type index_TransactionUpdateInProgress<ƒ extends ƒn> = TransactionUpdateInProgress<ƒ>;
351
380
  declare const index_abortTransaction: typeof abortTransaction;
352
381
  declare const index_applyTransaction: typeof applyTransaction;
@@ -404,7 +433,6 @@ declare namespace index {
404
433
  export {
405
434
  index_Atom as Atom,
406
435
  index_IMPLICIT as IMPLICIT,
407
- index_KeyedStateUpdate as KeyedStateUpdate,
408
436
  index$1 as META,
409
437
  index_OperationProgress as OperationProgress,
410
438
  index_ReadonlySelector as ReadonlySelector,
@@ -414,13 +442,12 @@ declare namespace index {
414
442
  index_TRANSACTION_PHASES as TRANSACTION_PHASES,
415
443
  index_Timeline as Timeline,
416
444
  index_TimelineAtomUpdate as TimelineAtomUpdate,
417
- index_TimelineData as TimelineData,
418
445
  index_TimelineSelectorUpdate as TimelineSelectorUpdate,
419
446
  index_TimelineTransactionUpdate as TimelineTransactionUpdate,
447
+ index_Transaction as Transaction,
420
448
  index_TransactionIdle as TransactionIdle,
421
449
  index_TransactionPhase as TransactionPhase,
422
450
  index_TransactionStatus as TransactionStatus,
423
- index_TransactionUpdate as TransactionUpdate,
424
451
  index_TransactionUpdateInProgress as TransactionUpdateInProgress,
425
452
  index_abortTransaction as abortTransaction,
426
453
  index_applyTransaction as applyTransaction,
@@ -487,15 +514,21 @@ type SelectorOptions<T> = {
487
514
  get: Read<() => T>;
488
515
  set: Write<(newValue: T) => void>;
489
516
  };
490
- type ReadonlySelectorOptions<T> = Omit<SelectorOptions<T>, `set`>;
491
- declare function selector<T>(options: ReadonlySelectorOptions<T>): ReadonlySelectorToken<T>;
517
+ type ReadonlySelectorOptions<T> = {
518
+ key: string;
519
+ get: Read<() => T>;
520
+ };
492
521
  declare function selector<T>(options: SelectorOptions<T>): SelectorToken<T>;
522
+ declare function selector<T>(options: ReadonlySelectorOptions<T>): ReadonlySelectorToken<T>;
493
523
  type SelectorFamilyOptions<T, K extends Serializable> = {
494
524
  key: string;
495
525
  get: (key: K) => Read<() => T>;
496
526
  set: (key: K) => Write<(newValue: T) => void>;
497
527
  };
498
- type ReadonlySelectorFamilyOptions<T, K extends Serializable> = Omit<SelectorFamilyOptions<T, K>, `set`>;
528
+ type ReadonlySelectorFamilyOptions<T, K extends Serializable> = {
529
+ key: string;
530
+ get: (key: K) => Read<() => T>;
531
+ };
499
532
  type SelectorFamily<T, K extends Serializable = Serializable> = ((key: K) => SelectorToken<T>) & {
500
533
  key: string;
501
534
  type: `selector_family`;
@@ -509,14 +542,34 @@ type ReadonlySelectorFamily<T, K extends Serializable = Serializable> = ((key: K
509
542
  declare function selectorFamily<T, K extends Serializable>(options: SelectorFamilyOptions<T, K>): SelectorFamily<T, K>;
510
543
  declare function selectorFamily<T, K extends Serializable>(options: ReadonlySelectorFamilyOptions<T, K>): ReadonlySelectorFamily<T, K>;
511
544
 
545
+ type Silo = ReturnType<typeof silo>;
546
+ declare const silo: (name: string, fromStore?: Store | null) => {
547
+ store: Store;
548
+ atom: typeof atom;
549
+ atomFamily: typeof atomFamily;
550
+ selector: typeof selector;
551
+ selectorFamily: typeof selectorFamily;
552
+ transaction: typeof transaction;
553
+ timeline: typeof timeline;
554
+ getState: typeof getState;
555
+ setState: typeof setState;
556
+ subscribe: typeof subscribe;
557
+ undo: typeof undo;
558
+ redo: typeof redo;
559
+ };
560
+
512
561
  type StateUpdate<T> = {
513
562
  newValue: T;
514
563
  oldValue: T;
515
564
  };
565
+ type KeyedStateUpdate<T> = StateUpdate<T> & {
566
+ key: string;
567
+ };
516
568
  type UpdateHandler<T> = (update: StateUpdate<T>) => void;
517
569
  declare const subscribe: <T>(token: ReadonlySelectorToken<T> | StateToken<T>, handleUpdate: UpdateHandler<T>, store?: Store) => (() => void);
518
570
  type TransactionUpdateHandler<ƒ extends ƒn> = (data: TransactionUpdate<ƒ>) => void;
519
571
  declare const subscribeToTransaction: <ƒ extends ƒn>(token: TransactionToken<ƒ>, handleUpdate: TransactionUpdateHandler<ƒ>, store?: Store) => (() => void);
572
+ declare const subscribeToTimeline: (token: TimelineToken, handleUpdate: (update: TimelineUpdate) => void, store?: Store) => (() => void);
520
573
 
521
574
  type TimelineToken = {
522
575
  key: string;
@@ -526,6 +579,7 @@ type TimelineOptions = {
526
579
  key: string;
527
580
  atoms: (AtomFamily<any> | AtomToken<any>)[];
528
581
  };
582
+ type TimelineUpdate = TimelineAtomUpdate | TimelineSelectorUpdate | TimelineTransactionUpdate;
529
583
  declare const timeline: (options: TimelineOptions) => TimelineToken;
530
584
  declare const redo: (token: TimelineToken) => void;
531
585
  declare const undo: (token: TimelineToken) => void;
@@ -534,28 +588,27 @@ type AtomToken<_> = {
534
588
  key: string;
535
589
  type: `atom`;
536
590
  family?: FamilyMetadata;
591
+ __brand?: _;
537
592
  };
538
593
  type SelectorToken<_> = {
539
594
  key: string;
540
595
  type: `selector`;
541
596
  family?: FamilyMetadata;
597
+ __brand?: _;
542
598
  };
543
599
  type StateToken<T> = AtomToken<T> | SelectorToken<T>;
544
600
  type ReadonlySelectorToken<_> = {
545
601
  key: string;
546
602
  type: `readonly_selector`;
547
603
  family?: FamilyMetadata;
604
+ __brand?: _;
548
605
  };
549
606
  type FamilyMetadata = {
550
607
  key: string;
551
608
  subKey: string;
552
609
  };
553
- type TransactionToken<_> = {
554
- key: string;
555
- type: `transaction`;
556
- };
557
610
  declare const getState: <T>(token: ReadonlySelectorToken<T> | StateToken<T>, store?: Store) => T;
558
611
  declare const setState: <T, New extends T>(token: StateToken<T>, value: New | ((oldValue: T) => New), store?: Store) => void;
559
612
  declare const isDefault: (token: ReadonlySelectorToken<unknown> | StateToken<unknown>, store?: Store) => boolean;
560
613
 
561
- export { AtomEffect, AtomFamily, AtomFamilyOptions, AtomOptions, AtomToken, Effectors, FamilyMetadata, LOG_LEVELS, Logger, Read, ReadonlySelectorFamily, ReadonlySelectorFamilyOptions, ReadonlySelectorOptions, ReadonlySelectorToken, ReadonlyTransactors, SelectorFamily, SelectorFamilyOptions, SelectorOptions, SelectorToken, Serializable, StateToken, StateUpdate, TimelineOptions, TimelineToken, Transaction, TransactionIO, TransactionOptions, TransactionToken, TransactionUpdateHandler, Transactors, UpdateHandler, Write, index as __INTERNAL__, atom, atomFamily, getState, isDefault, redo, runTransaction, selector, selectorFamily, setLogLevel, setState, subscribe, subscribeToTransaction, timeline, transaction, undo, useLogger, ƒn };
614
+ export { AtomEffect, AtomFamily, AtomFamilyOptions, AtomOptions, AtomToken, Effectors, FamilyMetadata, KeyedStateUpdate, LOG_LEVELS, Logger, Read, ReadonlySelectorFamily, ReadonlySelectorFamilyOptions, ReadonlySelectorOptions, ReadonlySelectorToken, ReadonlyTransactors, SelectorFamily, SelectorFamilyOptions, SelectorOptions, SelectorToken, Serializable, 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, silo, subscribe, subscribeToTimeline, subscribeToTransaction, timeline, transaction, undo, useLogger };