atom.io 0.31.0 → 0.31.1

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 (36) hide show
  1. package/dist/{chunk-42UH5F5Q.js → chunk-Y5MBNTVU.js} +240 -32
  2. package/dist/index.d.ts +236 -104
  3. package/dist/index.js +90 -5
  4. package/ephemeral/dist/index.d.ts +35 -25
  5. package/ephemeral/src/find-state.ts +35 -25
  6. package/internal/dist/index.d.ts +15 -10
  7. package/internal/dist/index.js +1 -2
  8. package/internal/src/families/find-in-store.ts +1 -6
  9. package/internal/src/index.ts +17 -9
  10. package/internal/src/ingest-updates/ingest-creation-disposal.ts +2 -3
  11. package/internal/src/install-into-store.ts +48 -0
  12. package/internal/src/molecule.ts +299 -0
  13. package/internal/src/not-found-error.ts +8 -30
  14. package/internal/src/pretty-print.ts +1 -12
  15. package/internal/src/selector/register-selector.ts +1 -8
  16. package/internal/src/store/deposit.ts +10 -8
  17. package/internal/src/store/withdraw.ts +15 -34
  18. package/json/dist/index.js +1 -2
  19. package/package.json +5 -5
  20. package/realtime-server/src/ipc-sockets/child-socket.ts +0 -1
  21. package/realtime-server/src/realtime-server-stores/server-room-external-actions.ts +1 -1
  22. package/realtime-testing/dist/index.js +3 -4
  23. package/realtime-testing/src/setup-realtime-test.tsx +4 -4
  24. package/src/atom.ts +53 -29
  25. package/src/dispose-state.ts +12 -2
  26. package/src/get-state.ts +16 -0
  27. package/src/index.ts +73 -3
  28. package/src/realm.ts +169 -0
  29. package/src/selector.ts +20 -0
  30. package/src/set-state.ts +16 -8
  31. package/src/silo.ts +9 -3
  32. package/transceivers/set-rtx/dist/index.js +4 -1
  33. package/transceivers/set-rtx/src/set-rtx.ts +4 -1
  34. package/dist/chunk-ICGFFQ3H.js +0 -272
  35. package/src/allocate.ts +0 -443
  36. package/src/molecule.ts +0 -16
package/dist/index.d.ts CHANGED
@@ -1,47 +1,71 @@
1
- import { Transceiver, Func, EnvironmentData, Store, Each, Flat, Timeline, TimelineAtomUpdate, TimelineMoleculeCreation, TimelineMoleculeDisposal, TimelineSelectorUpdate, TimelineStateCreation, TimelineStateDisposal, TimelineTransactionUpdate } from 'atom.io/internal';
1
+ import { Transceiver, Func, EnvironmentData, Timeline, TimelineAtomUpdate, TimelineMoleculeCreation, TimelineMoleculeDisposal, TimelineSelectorUpdate, TimelineStateCreation, TimelineStateDisposal, TimelineTransactionUpdate, Store, Each, Flat } from 'atom.io/internal';
2
2
  import { Json, JsonInterface, Canonical, stringified } from 'atom.io/json';
3
3
  import { getState as getState$1, setState as setState$1, ReadableFamilyToken as ReadableFamilyToken$1, ReadableToken as ReadableToken$1, RegularAtomToken as RegularAtomToken$1, MutableAtomToken as MutableAtomToken$1, WritableSelectorToken as WritableSelectorToken$1, ReadonlySelectorToken as ReadonlySelectorToken$1, WritableToken as WritableToken$1, RegularAtomFamilyToken as RegularAtomFamilyToken$1, MutableAtomFamilyToken as MutableAtomFamilyToken$1, WritableSelectorFamilyToken as WritableSelectorFamilyToken$1, ReadonlySelectorFamilyToken as ReadonlySelectorFamilyToken$1, WritableFamilyToken as WritableFamilyToken$1 } from 'atom.io';
4
4
  import { findState } from 'atom.io/ephemeral';
5
5
  import { seekState } from 'atom.io/immortal';
6
6
 
7
+ /**
8
+ * @public
9
+ * Create a mutable atom, a global reactive variable in the implicit store
10
+ *
11
+ * The value of a mutable atom must be some kind of {@link Transceiver}.
12
+ *
13
+ * @param options - {@link MutableAtomOptions}.
14
+ * @returns
15
+ * A reference to the atom created: a {@link MutableAtomToken}
16
+ * @overload Mutable
17
+ */
18
+ declare function atom<T extends Transceiver<any>, J extends Json.Serializable>(options: MutableAtomOptions<T, J>): MutableAtomToken<T, J>;
19
+ /**
20
+ * @public
21
+ * Create a regular atom, a global reactive variable in the implicit store
22
+ * @param options - {@link RegularAtomOptions}.
23
+ * @returns
24
+ * A reference to the atom created: a {@link RegularAtomToken}
25
+ * @overload Regular
26
+ */
27
+ declare function atom<T>(options: RegularAtomOptions<T>): RegularAtomToken<T>;
28
+ /** @public */
7
29
  type Effectors<T> = {
8
- setSelf: <V extends T>(next: V | ((oldValue: T) => V)) => void;
30
+ /**
31
+ * Set the value of the atom
32
+ * @param next - The new value of the atom, or a setter function
33
+ */
34
+ setSelf: <New extends T>(next: New | Setter<T, New>) => void;
35
+ /** Subscribe to changes to the atom */
9
36
  onSet: (callback: (options: {
10
37
  newValue: T;
11
38
  oldValue: T;
12
39
  }) => void) => void;
13
40
  };
41
+ /**
42
+ * @public
43
+ * A function that runs side effects when the atom is set
44
+ * @param tools - {@link Effectors} that can be used to run side effects
45
+ * @returns
46
+ * Optionally, a cleanup function that will be called when the atom is disposed
47
+ */
14
48
  type AtomEffect<T> = (tools: Effectors<T>) => (() => void) | void;
49
+ /** @public */
15
50
  type RegularAtomOptions<T> = {
51
+ /** The unique identifier of the atom */
16
52
  key: string;
53
+ /** The starting value of the atom */
17
54
  default: T | (() => T);
55
+ /** Hooks used to run side effects when the atom is set */
18
56
  effects?: AtomEffect<T>[];
19
57
  };
20
58
  type MutableAtomOptions<T extends Transceiver<any>, J extends Json.Serializable> = JsonInterface<T, J> & Omit<RegularAtomOptions<T>, `default`> & {
21
59
  default: () => T;
22
60
  mutable: true;
23
61
  };
24
- /**
25
- * @public
26
- * Declare a mutable global reactive variable.
27
- * @param options - Configuration for this mutable atom.
28
- * @returns
29
- * The token for your mutable atom.
30
- * @overload Mutable
31
- */
32
- declare function atom<T extends Transceiver<any>, J extends Json.Serializable>(options: MutableAtomOptions<T, J>): MutableAtomToken<T, J>;
33
- /**
34
- * @public
35
- * Declare a regular global reactive variable.
36
- * @param options - Configuration for this regular atom.
37
- * @returns
38
- * The token for your regular atom.
39
- * @overload Regular
40
- */
41
- declare function atom<T>(options: RegularAtomOptions<T>): RegularAtomToken<T>;
62
+ /** @public */
42
63
  type RegularAtomFamilyOptions<T, K extends Canonical> = {
64
+ /** The unique identifier of the atom family */
43
65
  key: string;
66
+ /** The starting value of the atom family */
44
67
  default: T | ((key: K) => T);
68
+ /** Hooks used to run side effects when an atom in the family is set */
45
69
  effects?: (key: K) => AtomEffect<T>[];
46
70
  };
47
71
  type RegularAtomFamilyToken<T, K extends Canonical> = {
@@ -153,7 +177,26 @@ type ReadonlySelectorOptions<T> = {
153
177
  key: string;
154
178
  get: Read<() => T>;
155
179
  };
180
+ /**
181
+ * @public
182
+ * Declare a selector. The value of a selector should depend
183
+ * on the value of atoms or other selectors in the store.
184
+ *
185
+ * A writable selector can be "set" to a new value.
186
+ * It is advised to set its dependencies to values
187
+ * that would produce the new value of the selector.
188
+ * @param options - {@link WritableSelectorOptions}.
189
+ * @returns
190
+ * The token for your selector.
191
+ * @overload Writable
192
+ */
156
193
  declare function selector<T>(options: WritableSelectorOptions<T>): WritableSelectorToken<T>;
194
+ /**
195
+ * @public
196
+ * Declare a selector. The value of a selector should depend
197
+ * on the value of atoms or other selectors in the store.
198
+ * @param options - {@link ReadonlySelectorOptions}.
199
+ */
157
200
  declare function selector<T>(options: ReadonlySelectorOptions<T>): ReadonlySelectorToken<T>;
158
201
  type WritableSelectorFamilyOptions<T, K extends Canonical> = {
159
202
  key: string;
@@ -180,73 +223,55 @@ type SelectorFamilyToken<T, K extends Canonical> = ReadonlySelectorFamilyToken<T
180
223
  declare function selectorFamily<T, K extends Canonical>(options: WritableSelectorFamilyOptions<T, K>): WritableSelectorFamilyToken<T, K>;
181
224
  declare function selectorFamily<T, K extends Canonical>(options: ReadonlySelectorFamilyOptions<T, K>): ReadonlySelectorFamilyToken<T, K>;
182
225
 
183
- declare const $claim: unique symbol;
184
- type Claim<K extends Canonical> = K & {
185
- [$claim]?: true;
186
- };
187
- declare function allocateIntoStore<H extends Hierarchy, V extends Vassal<H>, A extends Above<V, H>>(store: Store, provenance: A, key: V, dependsOn?: `all` | `any`): Claim<V>;
188
- declare function fuseWithinStore<H extends Hierarchy, C extends CompoundFrom<H>, T extends C extends CompoundTypedKey<infer t, any, any> ? t : never, A extends C extends CompoundTypedKey<any, infer a, any> ? a : never, B extends C extends CompoundTypedKey<any, any, infer b> ? b : never>(store: Store, type: T, sideA: SingularTypedKey<A>, sideB: SingularTypedKey<B>): Claim<CompoundTypedKey<T, A, B>>;
189
- declare function deallocateFromStore<H extends Hierarchy, V extends Vassal<H>>(store: Store, claim: Claim<V>): void;
190
- declare function claimWithinStore<H extends Hierarchy, V extends Exclude<Vassal<H>, CompoundTypedKey>, A extends Above<V, H>>(store: Store, newProvenance: A, claim: Claim<V>, exclusive?: `exclusive`): Claim<V>;
191
- declare class Realm<H extends Hierarchy> {
192
- store: Store;
193
- constructor(store?: Store);
194
- allocate<V extends Vassal<H>, A extends Above<V, H>>(provenance: A, key: V, attachmentStyle?: `all` | `any`): Claim<V>;
195
- fuse<C extends CompoundFrom<H>, T extends C extends CompoundTypedKey<infer t, any, any> ? t : never, A extends C extends CompoundTypedKey<any, infer v, any> ? v : never, B extends C extends CompoundTypedKey<any, any, infer m> ? m : never>(type: T, reagentA: SingularTypedKey<A>, reagentB: SingularTypedKey<B>): Claim<CompoundTypedKey<T, A, B>>;
196
- deallocate<V extends Vassal<H>>(claim: Claim<V>): void;
197
- claim<V extends Exclude<Vassal<H>, CompoundTypedKey>, A extends Above<V, H>>(newProvenance: A, claim: Claim<V>, exclusive?: `exclusive`): Claim<V>;
198
- }
199
- declare const T$ = "T$";
200
- type T$ = typeof T$;
201
- type TypeTag<T extends string> = `${T$}--${T}`;
202
- type SingularTypedKey<T extends string = string> = `${T}::${string}`;
203
- type CompoundTypedKey<A extends string = string, B extends string = string, C extends string = string> = `${TypeTag<A>}==${SingularTypedKey<B>}++${SingularTypedKey<C>}`;
204
- type TypedKey<A extends string = string, B extends string = string, C extends string = string> = CompoundTypedKey<A, B, C> | SingularTypedKey<A>;
205
- type Scope = SingularTypedKey[];
206
- type MutualFealty = {
207
- above: Scope;
208
- below: CompoundTypedKey;
226
+ type TimelineManageable = AtomFamilyToken<any, any> | AtomToken<any>;
227
+ type AtomOnly<M extends TimelineManageable> = M extends AtomFamilyToken<any, any> ? AtomToken<any> : M extends AtomToken<any> ? M : never;
228
+ type TimelineToken<M> = {
229
+ key: string;
230
+ type: `timeline`;
231
+ __M?: M;
209
232
  };
210
- type ExclusiveFealty = {
211
- above: TypedKey | `root`;
212
- below: Scope;
233
+ type TimelineOptions<ManagedAtom extends TimelineManageable> = {
234
+ key: string;
235
+ scope: ManagedAtom[];
236
+ shouldCapture?: (update: TimelineUpdate<ManagedAtom>, timeline: Timeline<TimelineManageable>) => boolean;
213
237
  };
214
- type Fealty = ExclusiveFealty | MutualFealty;
215
- type Hierarchy<F extends Fealty[] = Fealty[]> = Each<F>;
216
- type Vassal<H extends Hierarchy> = {
217
- [K in keyof H]: H[K] extends MutualFealty ? H[K][`below`] : H[K] extends {
218
- below: Array<infer V>;
219
- } ? V extends TypedKey ? V : never : never;
220
- }[keyof H];
221
- type Above<TK extends TypedKey, H extends Hierarchy> = {
222
- [K in keyof H]: H[K] extends MutualFealty ? TK extends H[K][`below`] ? H[K][`above`] : never : H[K] extends {
223
- below: Array<infer V>;
224
- } ? TK extends V ? H[K] extends ExclusiveFealty ? H[K][`above`] : never : never : never;
225
- }[keyof H];
226
- type Below<TK extends TypedKey | TypedKey[], H extends Hierarchy> = {
227
- [K in keyof H]: H[K] extends MutualFealty ? TK extends H[K][`above`] ? H[K][`below`] : TK extends H[K][`above`][number] ? H[K][`below`] : never : H[K] extends {
228
- above: infer V;
229
- } ? TK extends V ? H[K] extends ExclusiveFealty ? H[K][`below`][number] : never : never : never;
230
- }[keyof H];
231
- type Mutuals<TK extends TypedKey | TypedKey[], H extends Hierarchy> = {
232
- [K in keyof H]: H[K] extends MutualFealty ? TK extends H[K][`above`][number] ? [mutual: Exclude<H[K][`above`][number], TK>, below: H[K][`below`]] : never : never;
233
- }[keyof H];
234
- type CompoundFrom<H extends Hierarchy> = {
235
- [K in keyof H]: H[K] extends MutualFealty ? H[K][`below`] : never;
236
- }[keyof H];
237
- declare class Anarchy {
238
- store: Store;
239
- realm: Realm<any>;
240
- constructor(store?: Store);
241
- allocate(provenance: Canonical, key: Canonical, attachmentStyle?: `all` | `any`): void;
242
- deallocate(key: Canonical): void;
243
- claim(newProvenance: Canonical, key: Canonical, exclusive?: `exclusive`): void;
244
- }
238
+ type TimelineUpdate<ManagedAtom extends TimelineManageable> = TimelineAtomUpdate<ManagedAtom> | TimelineMoleculeCreation | TimelineMoleculeDisposal | TimelineSelectorUpdate<ManagedAtom> | TimelineStateCreation<AtomOnly<ManagedAtom>> | TimelineStateDisposal<AtomOnly<ManagedAtom>> | TimelineTransactionUpdate;
239
+ declare const timeline: <ManagedAtom extends TimelineManageable>(options: TimelineOptions<ManagedAtom>) => TimelineToken<ManagedAtom>;
240
+ declare const redo: (tl: TimelineToken<any>) => void;
241
+ declare const undo: (tl: TimelineToken<any>) => void;
245
242
 
243
+ /**
244
+ * @public
245
+ * Disposes of a state in the implicit store
246
+ * @param token - The token of the state to dispose
247
+ * @overload Default
248
+ */
246
249
  declare function disposeState(token: ReadableToken<any>): void;
250
+ /**
251
+ * @public
252
+ * Disposes of a state family in the implicit store
253
+ * @param token - The token of the state family to dispose
254
+ * @param key - The unique key of the state to dispose
255
+ */
247
256
  declare function disposeState<K extends Canonical>(token: ReadableFamilyToken<any, K>, key: K): void;
248
257
 
258
+ /**
259
+ * @public
260
+ * Get the current value of a state
261
+ * @param token - The token of the state to get
262
+ * @return The current value of the state
263
+ * @overload Default
264
+ * @default
265
+ */
249
266
  declare function getState<T>(token: ReadableToken<T>): T;
267
+ /**
268
+ * @public
269
+ * Get the current value of a state family
270
+ * @param token - The token of a state family
271
+ * @param key - The unique key of the state to get
272
+ * @return The current value of the state
273
+ * @overload Streamlined
274
+ */
250
275
  declare function getState<T, K extends Canonical, Key extends K>(token: ReadableFamilyToken<T, K>, key: Key): T;
251
276
 
252
277
  declare const LoggerIconDictionary: {
@@ -319,26 +344,91 @@ declare class AtomIOLogger implements Logger {
319
344
  warn: LogFn;
320
345
  }
321
346
 
322
- declare function makeRootMoleculeInStore<S extends string>(key: S, store?: Store): S;
347
+ declare const $claim: unique symbol;
348
+ type Claim<K extends Canonical> = K & {
349
+ [$claim]?: true;
350
+ };
351
+ declare class Realm<H extends Hierarchy> {
352
+ store: Store;
353
+ constructor(store?: Store);
354
+ allocate<V extends Vassal<H>, A extends Above<V, H>>(provenance: A, key: V, attachmentStyle?: `all` | `any`): Claim<V>;
355
+ fuse<C extends CompoundFrom<H>, T extends C extends CompoundTypedKey<infer t, any, any> ? t : never, A extends C extends CompoundTypedKey<any, infer v, any> ? v : never, B extends C extends CompoundTypedKey<any, any, infer m> ? m : never>(type: T, reagentA: SingularTypedKey<A>, reagentB: SingularTypedKey<B>): Claim<CompoundTypedKey<T, A, B>>;
356
+ deallocate<V extends Vassal<H>>(claim: Claim<V>): void;
357
+ claim<V extends Exclude<Vassal<H>, CompoundTypedKey>, A extends Above<V, H>>(newProvenance: A, claim: Claim<V>, exclusive?: `exclusive`): Claim<V>;
358
+ }
359
+ declare class Anarchy {
360
+ store: Store;
361
+ realm: Realm<any>;
362
+ constructor(store?: Store);
363
+ allocate(provenance: Canonical, key: Canonical, attachmentStyle?: `all` | `any`): void;
364
+ deallocate(key: Canonical): void;
365
+ claim(newProvenance: Canonical, key: Canonical, exclusive?: `exclusive`): void;
366
+ }
367
+ declare const T$ = "T$";
368
+ type T$ = typeof T$;
369
+ type TypeTag<T extends string> = `${T$}--${T}`;
370
+ type SingularTypedKey<T extends string = string> = `${T}::${string}`;
371
+ type CompoundTypedKey<A extends string = string, B extends string = string, C extends string = string> = `${TypeTag<A>}==${SingularTypedKey<B>}++${SingularTypedKey<C>}`;
372
+ type TypedKey<A extends string = string, B extends string = string, C extends string = string> = CompoundTypedKey<A, B, C> | SingularTypedKey<A>;
373
+ type Scope = SingularTypedKey[];
374
+ type MutualFealty = {
375
+ above: Scope;
376
+ below: CompoundTypedKey;
377
+ };
378
+ type ExclusiveFealty = {
379
+ above: TypedKey | `root`;
380
+ below: Scope;
381
+ };
382
+ type Fealty = ExclusiveFealty | MutualFealty;
383
+ type Hierarchy<F extends Fealty[] = Fealty[]> = Each<F>;
384
+ type Vassal<H extends Hierarchy> = {
385
+ [K in keyof H]: H[K] extends MutualFealty ? H[K][`below`] : H[K] extends {
386
+ below: Array<infer V>;
387
+ } ? V extends TypedKey ? V : never : never;
388
+ }[keyof H];
389
+ type Above<TK extends TypedKey, H extends Hierarchy> = {
390
+ [K in keyof H]: H[K] extends MutualFealty ? TK extends H[K][`below`] ? H[K][`above`] : never : H[K] extends {
391
+ below: Array<infer V>;
392
+ } ? TK extends V ? H[K] extends ExclusiveFealty ? H[K][`above`] : never : never : never;
393
+ }[keyof H];
394
+ type Below<TK extends TypedKey | TypedKey[], H extends Hierarchy> = {
395
+ [K in keyof H]: H[K] extends MutualFealty ? TK extends H[K][`above`] ? H[K][`below`] : TK extends H[K][`above`][number] ? H[K][`below`] : never : H[K] extends {
396
+ above: infer V;
397
+ } ? TK extends V ? H[K] extends ExclusiveFealty ? H[K][`below`][number] : never : never : never;
398
+ }[keyof H];
399
+ type Mutuals<TK extends TypedKey | TypedKey[], H extends Hierarchy> = {
400
+ [K in keyof H]: H[K] extends MutualFealty ? TK extends H[K][`above`][number] ? [mutual: Exclude<H[K][`above`][number], TK>, below: H[K][`below`]] : never : never;
401
+ }[keyof H];
402
+ type CompoundFrom<H extends Hierarchy> = {
403
+ [K in keyof H]: H[K] extends MutualFealty ? H[K][`below`] : never;
404
+ }[keyof H];
323
405
 
406
+ /**
407
+ * @public
408
+ * A function that sets the value of a state.
409
+ * @param oldValue - The current value of the state.
410
+ * @returns
411
+ * The new value of the state.
412
+ */
413
+ type Setter<T, New extends T> = (oldValue: T) => New;
324
414
  /**
325
415
  * @public
326
416
  * Set the value of a state into the implicit store.
327
- * @param token - The unique identifier of the state to set.
417
+ * @param token - An atom or writable selector token.
328
418
  * @param value - The new value of the state.
329
419
  * @overload Default
330
420
  * @default
331
421
  */
332
- declare function setState<T, New extends T>(token: WritableToken<T>, value: New | ((oldValue: T) => New)): void;
422
+ declare function setState<T, New extends T>(token: WritableToken<T>, value: New | Setter<T, New>): void;
333
423
  /**
334
424
  * @public
335
425
  * Set the value of a state into the implicit store.
336
- * @param token - The unique identifier of a state family.
337
- * @param key - The key of the state to set.
426
+ * @param token - An atom family or writable selector family token.
427
+ * @param key - The unique key of the state to set.
338
428
  * @param value - The new value of the state.
339
429
  * @overload Streamlined
340
430
  */
341
- declare function setState<T, K extends Canonical, New extends T, Key extends K>(token: WritableFamilyToken<T, K>, key: Key, value: New | ((oldValue: T) => New)): void;
431
+ declare function setState<T, K extends Canonical, New extends T, Key extends K>(token: WritableFamilyToken<T, K>, key: Key, value: New | Setter<T, New>): void;
342
432
 
343
433
  declare class Silo {
344
434
  store: Store;
@@ -356,6 +446,7 @@ declare class Silo {
356
446
  undo: typeof undo;
357
447
  redo: typeof redo;
358
448
  runTransaction: typeof runTransaction;
449
+ install: (tokens: AtomIOToken[], store?: Store) => void;
359
450
  constructor(config: Store[`config`], fromStore?: Store | null);
360
451
  }
361
452
 
@@ -374,23 +465,6 @@ declare function subscribe<T>(token: ReadableToken<T>, handleUpdate: UpdateHandl
374
465
  declare function subscribe<F extends Func>(token: TransactionToken<F>, handleUpdate: TransactionUpdateHandler<F>, key?: string): () => void;
375
466
  declare function subscribe<M extends TimelineManageable>(token: TimelineToken<M>, handleUpdate: (update: TimelineUpdate<M> | `redo` | `undo`) => void, key?: string): () => void;
376
467
 
377
- type TimelineManageable = AtomFamilyToken<any, any> | AtomToken<any>;
378
- type AtomOnly<M extends TimelineManageable> = M extends AtomFamilyToken<any, any> ? AtomToken<any> : M extends AtomToken<any> ? M : never;
379
- type TimelineToken<M> = {
380
- key: string;
381
- type: `timeline`;
382
- __M?: M;
383
- };
384
- type TimelineOptions<ManagedAtom extends TimelineManageable> = {
385
- key: string;
386
- scope: ManagedAtom[];
387
- shouldCapture?: (update: TimelineUpdate<ManagedAtom>, timeline: Timeline<TimelineManageable>) => boolean;
388
- };
389
- type TimelineUpdate<ManagedAtom extends TimelineManageable> = TimelineAtomUpdate<ManagedAtom> | TimelineMoleculeCreation | TimelineMoleculeDisposal | TimelineSelectorUpdate<ManagedAtom> | TimelineStateCreation<AtomOnly<ManagedAtom>> | TimelineStateDisposal<AtomOnly<ManagedAtom>> | TimelineTransactionUpdate;
390
- declare const timeline: <ManagedAtom extends TimelineManageable>(options: TimelineOptions<ManagedAtom>) => TimelineToken<ManagedAtom>;
391
- declare const redo: (tl: TimelineToken<any>) => void;
392
- declare const undo: (tl: TimelineToken<any>) => void;
393
-
394
468
  type TokenType<Comparison extends ReadableFamilyToken$1<any, any> | ReadableToken$1<any>> = Comparison extends ReadableToken$1<infer RepresentedValue> ? RepresentedValue : Comparison extends ReadableFamilyToken$1<infer RepresentedValue, any> ? RepresentedValue : never;
395
469
  declare function isToken<KnownToken extends RegularAtomToken$1<any>>(knownToken: KnownToken, unknownToken: ReadableToken$1<any>): unknownToken is RegularAtomToken$1<TokenType<KnownToken>>;
396
470
  declare function isToken<KnownToken extends MutableAtomToken$1<any, any>>(knownToken: KnownToken, unknownToken: ReadableToken$1<any>): unknownToken is MutableAtomToken$1<TokenType<KnownToken>, any>;
@@ -405,40 +479,98 @@ declare function belongsTo<Family extends ReadonlySelectorFamilyToken$1<any, any
405
479
  declare function belongsTo<Family extends WritableFamilyToken$1<any, any>>(family: Family, unknownToken: ReadableToken$1<any>): unknownToken is WritableToken$1<TokenType<Family>>;
406
480
  declare function belongsTo<Family extends ReadableFamilyToken$1<any, any>>(family: Family, unknownToken: ReadableToken$1<any>): unknownToken is ReadableToken$1<TokenType<Family>>;
407
481
 
482
+ /**
483
+ * @public
484
+ * A token is an object that uniquely identifies a particular state, family, timeline, or transaction.
485
+ *
486
+ * While they represent one of these resources, they are not the resource itself. Think of them like paper currency representing money in the bank.
487
+ *
488
+ * Tokens are returned from resource creation functions, such as {@link atom} and {@link transaction}.
489
+ *
490
+ * Tokens can be used as parameters to functions that take a token, such as {@link getState}, {@link setState}, or {@link runTransaction}.
491
+ *
492
+ * Tokens are fully serializable, so they can be passed between processes.
493
+ */
494
+ type AtomIOToken = ReadableFamilyToken<any, any> | ReadableToken<any> | TimelineToken<any> | TransactionToken<any>;
495
+ /** @public */
408
496
  type RegularAtomToken<T, K extends Canonical = any> = {
497
+ /** The unique identifier of the atom. */
409
498
  key: string;
499
+ /** Discriminator. */
410
500
  type: `atom`;
501
+ /** Present if the atom belongs to a family. */
411
502
  family?: FamilyMetadata<K>;
503
+ /** Never present. This is a marker that preserves the type of the atom's value. */
412
504
  __T?: T;
413
505
  };
506
+ /** @public */
414
507
  type MutableAtomToken<T extends Transceiver<any>, J extends Json.Serializable, K extends Canonical = any> = {
508
+ /** The unique identifier of the atom. */
415
509
  key: string;
510
+ /** Discriminator. */
416
511
  type: `mutable_atom`;
512
+ /** Present if the atom belongs to a family. */
417
513
  family?: FamilyMetadata<K>;
514
+ /** Never present. This is a marker that preserves the JSON form of the atom's transceiver value. */
418
515
  __J?: J;
516
+ /** Never present. This is a marker that preserves the type of the atom's transceiver value. */
419
517
  __U?: T extends Transceiver<infer Update> ? Update : never;
420
518
  };
519
+ /** @public */
421
520
  type AtomToken<T, K extends Canonical = any> = MutableAtomToken<T extends Transceiver<any> ? T : never, any, K> | RegularAtomToken<T, K>;
521
+ /** @public */
422
522
  type WritableSelectorToken<T, K extends Canonical = any> = {
523
+ /** The unique identifier of the selector. */
423
524
  key: string;
525
+ /** Discriminator. */
424
526
  type: `selector`;
527
+ /** Present if the selector belongs to a family. */
425
528
  family?: FamilyMetadata<K>;
529
+ /** Never present. This is a marker that preserves the type of the selector's value. */
426
530
  __T?: T;
427
531
  };
532
+ /** @public */
428
533
  type ReadonlySelectorToken<T, K extends Canonical = any> = {
534
+ /** The unique identifier of the selector. */
429
535
  key: string;
536
+ /** Discriminator. */
430
537
  type: `readonly_selector`;
538
+ /** Present if the selector belongs to a family. */
431
539
  family?: FamilyMetadata<K>;
540
+ /** Never present. This is a marker that preserves the type of the selector's value. */
432
541
  __T?: T;
433
542
  };
543
+ /** @public */
434
544
  type SelectorToken<T, K extends Canonical = any> = ReadonlySelectorToken<T, K> | WritableSelectorToken<T, K>;
545
+ /**
546
+ * @public
547
+ * These states can be set.
548
+ */
435
549
  type WritableToken<T, K extends Canonical = any> = AtomToken<T, K> | WritableSelectorToken<T, K>;
550
+ /**
551
+ * @public
552
+ * These states cannot be set.
553
+ */
436
554
  type ReadableToken<T, K extends Canonical = any> = AtomToken<T, K> | SelectorToken<T, K>;
555
+ /**
556
+ * @public
557
+ * States belonging to this family can be set.
558
+ */
437
559
  type WritableFamilyToken<T, K extends Canonical> = AtomFamilyToken<T, K> | WritableSelectorFamilyToken<T, K>;
560
+ /**
561
+ * @public
562
+ * States belonging to this family cannot be set.
563
+ */
438
564
  type ReadableFamilyToken<T, K extends Canonical> = AtomFamilyToken<T, K> | SelectorFamilyToken<T, K>;
565
+ /**
566
+ * @public
567
+ * Identifies a state's connection to its family.
568
+ */
439
569
  type FamilyMetadata<K extends Canonical = any> = {
570
+ /** The family's unique key. */
440
571
  key: string;
572
+ /** The family member's unique identifier, in the form of a string. */
441
573
  subKey: stringified<K>;
442
574
  };
443
575
 
444
- export { $claim, type Above, type ActorToolkit, Anarchy, type AtomDisposal, type AtomEffect, type AtomFamilyToken, AtomIOLogger, type AtomOnly, type AtomToken, type Below, type Claim, type CompoundFrom, type CompoundTypedKey, type Effectors, type FamilyMetadata, type GetterToolkit, type Hierarchy, type KeyedStateUpdate, LOG_LEVELS, type LogFilter, type LogFn, type LogLevel, type Logger, type LoggerIcon, type MoleculeCreation, type MoleculeDisposal, type MoleculeTransfer, type MutableAtomFamilyOptions, type MutableAtomFamilyToken, type MutableAtomOptions, type MutableAtomToken, type Mutuals, type Read, type ReadableFamilyToken, type ReadableToken, type ReadonlySelectorFamilyOptions, type ReadonlySelectorFamilyToken, type ReadonlySelectorOptions, type ReadonlySelectorToken, Realm, type RegularAtomFamilyOptions, type RegularAtomFamilyToken, type RegularAtomOptions, type RegularAtomToken, type SelectorDisposal, type SelectorFamilyToken, type SelectorToken, type SetterToolkit, Silo, type SingularTypedKey, type StateCreation, type StateDisposal, type StateUpdate, T$, type TimelineManageable, type TimelineOptions, type TimelineToken, type TimelineUpdate, type TokenDenomination, type TokenType, type Transact, type TransactionIO, type TransactionOptions, type TransactionToken, type TransactionUpdate, type TransactionUpdateContent, type TransactionUpdateHandler, type TypeTag, type TypedKey, type UpdateHandler, type Vassal, type WritableFamilyToken, type WritableSelectorFamilyOptions, type WritableSelectorFamilyToken, type WritableSelectorOptions, type WritableSelectorToken, type WritableToken, type Write, allocateIntoStore, atom, atomFamily, belongsTo, claimWithinStore, deallocateFromStore, disposeState, fuseWithinStore, getState, isToken, makeRootMoleculeInStore, redo, runTransaction, selector, selectorFamily, setState, simpleLog, simpleLogger, subscribe, timeline, transaction, undo };
576
+ export { $claim, type Above, type ActorToolkit, Anarchy, type AtomDisposal, type AtomEffect, type AtomFamilyToken, AtomIOLogger, type AtomIOToken, type AtomOnly, type AtomToken, type Below, type Claim, type CompoundFrom, type CompoundTypedKey, type Effectors, type FamilyMetadata, type GetterToolkit, type Hierarchy, type KeyedStateUpdate, LOG_LEVELS, type LogFilter, type LogFn, type LogLevel, type Logger, type LoggerIcon, type MoleculeCreation, type MoleculeDisposal, type MoleculeTransfer, type MutableAtomFamilyOptions, type MutableAtomFamilyToken, type MutableAtomOptions, type MutableAtomToken, type Mutuals, type Read, type ReadableFamilyToken, type ReadableToken, type ReadonlySelectorFamilyOptions, type ReadonlySelectorFamilyToken, type ReadonlySelectorOptions, type ReadonlySelectorToken, Realm, type RegularAtomFamilyOptions, type RegularAtomFamilyToken, type RegularAtomOptions, type RegularAtomToken, type SelectorDisposal, type SelectorFamilyToken, type SelectorToken, type Setter, type SetterToolkit, Silo, type SingularTypedKey, type StateCreation, type StateDisposal, type StateUpdate, T$, type TimelineManageable, type TimelineOptions, type TimelineToken, type TimelineUpdate, type TokenDenomination, type TokenType, type Transact, type TransactionIO, type TransactionOptions, type TransactionToken, type TransactionUpdate, type TransactionUpdateContent, type TransactionUpdateHandler, type TypeTag, type TypedKey, type UpdateHandler, type Vassal, type WritableFamilyToken, type WritableSelectorFamilyOptions, type WritableSelectorFamilyToken, type WritableSelectorOptions, type WritableSelectorToken, type WritableToken, type Write, atom, atomFamily, belongsTo, disposeState, getState, isToken, redo, runTransaction, selector, selectorFamily, setState, simpleLog, simpleLogger, subscribe, timeline, transaction, undo };
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
- export { $claim, Anarchy, Realm, T$, allocateIntoStore, claimWithinStore, deallocateFromStore, fuseWithinStore, makeRootMoleculeInStore } from './chunk-ICGFFQ3H.js';
1
+ import { newest, isChildStore, withdraw } from './chunk-Y5MBNTVU.js';
2
2
  import './chunk-XWL6SNVU.js';
3
3
  import * as Internal from 'atom.io/internal';
4
- import { createStandaloneAtom, IMPLICIT, createAtomFamily, createStandaloneSelector, createSelectorFamily, Store, createTransaction, createTimeline, findInStore, getFromStore, setIntoStore, disposeFromStore, subscribeInStore, timeTravel, actUponStore, arbitrary } from 'atom.io/internal';
4
+ import { createStandaloneAtom, IMPLICIT, createAtomFamily, makeRootMoleculeInStore, allocateIntoStore, fuseWithinStore, deallocateFromStore, claimWithinStore, createStandaloneSelector, createSelectorFamily, Store, createTransaction, createTimeline, findInStore, getFromStore, setIntoStore, disposeFromStore, subscribeInStore, timeTravel, actUponStore, arbitrary } from 'atom.io/internal';
5
5
 
6
6
  function atom(options) {
7
7
  return createStandaloneAtom(IMPLICIT.STORE, options);
@@ -58,6 +58,54 @@ var AtomIOLogger = class {
58
58
  }
59
59
  };
60
60
  };
61
+ var $claim = Symbol(`claim`);
62
+ var Realm = class {
63
+ store;
64
+ constructor(store = IMPLICIT.STORE) {
65
+ this.store = store;
66
+ makeRootMoleculeInStore(`root`, store);
67
+ }
68
+ allocate(provenance, key, attachmentStyle) {
69
+ return allocateIntoStore(
70
+ this.store,
71
+ provenance,
72
+ key,
73
+ attachmentStyle
74
+ );
75
+ }
76
+ fuse(type, reagentA, reagentB) {
77
+ return fuseWithinStore(this.store, type, reagentA, reagentB);
78
+ }
79
+ deallocate(claim) {
80
+ deallocateFromStore(this.store, claim);
81
+ }
82
+ claim(newProvenance, claim, exclusive) {
83
+ return claimWithinStore(this.store, newProvenance, claim, exclusive);
84
+ }
85
+ };
86
+ var Anarchy = class {
87
+ store;
88
+ realm;
89
+ constructor(store = IMPLICIT.STORE) {
90
+ this.store = store;
91
+ this.realm = new Realm(store);
92
+ }
93
+ allocate(provenance, key, attachmentStyle) {
94
+ allocateIntoStore(
95
+ this.store,
96
+ provenance,
97
+ key,
98
+ attachmentStyle
99
+ );
100
+ }
101
+ deallocate(key) {
102
+ deallocateFromStore(this.store, key);
103
+ }
104
+ claim(newProvenance, key, exclusive) {
105
+ claimWithinStore(this.store, newProvenance, key, exclusive);
106
+ }
107
+ };
108
+ var T$ = `T$`;
61
109
  function selector(options) {
62
110
  return createStandaloneSelector(IMPLICIT.STORE, options);
63
111
  }
@@ -71,6 +119,40 @@ function setState(...params) {
71
119
  Internal.setIntoStore(Internal.IMPLICIT.STORE, ...params);
72
120
  }
73
121
  }
122
+
123
+ // internal/src/install-into-store.ts
124
+ function installIntoStore(tokens, target, source) {
125
+ const sourceNewest = newest(source);
126
+ if (isChildStore(sourceNewest)) {
127
+ source.logger.error(
128
+ `\u274C`,
129
+ `transaction`,
130
+ sourceNewest.transactionMeta.update.key,
131
+ `could not install the following tokens into store "${target.config.name} from "${source.config.name}":`,
132
+ tokens,
133
+ `${sourceNewest.config.name} is undergoing a transaction.`
134
+ );
135
+ return;
136
+ }
137
+ const targetNewest = newest(target);
138
+ if (isChildStore(targetNewest)) {
139
+ target.logger.error(
140
+ `\u274C`,
141
+ `transaction`,
142
+ targetNewest.transactionMeta.update.key,
143
+ `could not install the following tokens into store "${target.config.name} from "${source.config.name}":`,
144
+ tokens,
145
+ `${targetNewest.config.name} is undergoing a transaction.`
146
+ );
147
+ return;
148
+ }
149
+ for (const token of tokens) {
150
+ const resource = withdraw(token, source);
151
+ resource.install(target);
152
+ }
153
+ }
154
+
155
+ // src/silo.ts
74
156
  var Silo = class {
75
157
  store;
76
158
  atom;
@@ -87,9 +169,9 @@ var Silo = class {
87
169
  undo;
88
170
  redo;
89
171
  runTransaction;
172
+ install;
90
173
  constructor(config, fromStore = null) {
91
- const s = new Store(config, fromStore);
92
- this.store = s;
174
+ const s = this.store = new Store(config, fromStore);
93
175
  this.atom = (options) => createStandaloneAtom(s, options);
94
176
  this.atomFamily = (options) => createAtomFamily(s, options);
95
177
  this.selector = (options) => createStandaloneSelector(s, options);
@@ -112,6 +194,9 @@ var Silo = class {
112
194
  timeTravel(s, `redo`, token);
113
195
  };
114
196
  this.runTransaction = (token, id = arbitrary()) => actUponStore(token, id, s);
197
+ this.install = (tokens, source = IMPLICIT.STORE) => {
198
+ installIntoStore(tokens, s, source);
199
+ };
115
200
  }
116
201
  };
117
202
  function subscribe(token, handleUpdate, key = arbitrary()) {
@@ -141,4 +226,4 @@ function belongsTo(family, unknownToken) {
141
226
  return family.key === unknownToken.family?.key;
142
227
  }
143
228
 
144
- export { AtomIOLogger, LOG_LEVELS, Silo, atom, atomFamily, belongsTo, disposeState, getState, isToken, redo, runTransaction, selector, selectorFamily, setState, simpleLog, simpleLogger, subscribe, timeline, transaction, undo };
229
+ export { $claim, Anarchy, AtomIOLogger, LOG_LEVELS, Realm, Silo, T$, atom, atomFamily, belongsTo, disposeState, getState, isToken, redo, runTransaction, selector, selectorFamily, setState, simpleLog, simpleLogger, subscribe, timeline, transaction, undo };