atom.io 0.15.3 → 0.15.5

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 (125) hide show
  1. package/data/dist/index.cjs +29 -16
  2. package/data/dist/index.cjs.map +1 -1
  3. package/data/dist/index.js +30 -17
  4. package/data/dist/index.js.map +1 -1
  5. package/data/src/join.ts +15 -2
  6. package/dist/index.cjs +32 -6
  7. package/dist/index.cjs.map +1 -1
  8. package/dist/index.d.ts +153 -85
  9. package/dist/index.js +157 -1
  10. package/dist/index.js.map +1 -1
  11. package/internal/dist/index.cjs +98 -159
  12. package/internal/dist/index.cjs.map +1 -1
  13. package/internal/dist/index.d.ts +44 -32
  14. package/internal/dist/index.js +89 -105
  15. package/internal/dist/index.js.map +1 -1
  16. package/internal/src/atom/create-regular-atom.ts +1 -1
  17. package/internal/src/get-environment-data.ts +18 -0
  18. package/internal/src/index.ts +2 -0
  19. package/internal/src/ingest-updates/index.ts +3 -0
  20. package/internal/src/ingest-updates/ingest-atom-update.ts +14 -0
  21. package/internal/src/ingest-updates/ingest-selector-update.ts +17 -0
  22. package/internal/src/ingest-updates/ingest-transaction-update.ts +22 -0
  23. package/internal/src/mutable/tracker.ts +4 -4
  24. package/internal/src/not-found-error.ts +3 -8
  25. package/internal/src/operation.ts +4 -4
  26. package/internal/src/selector/create-read-write-selector.ts +6 -4
  27. package/internal/src/selector/create-readonly-selector.ts +3 -3
  28. package/internal/src/selector/register-selector.ts +6 -4
  29. package/internal/src/selector/update-selector-atoms.ts +2 -2
  30. package/internal/src/store/deposit.ts +5 -5
  31. package/internal/src/store/store.ts +4 -4
  32. package/internal/src/store/withdraw-new-family-member.ts +8 -11
  33. package/internal/src/store/withdraw.ts +11 -12
  34. package/internal/src/subscribe/subscribe-to-state.ts +2 -2
  35. package/internal/src/subscribe/subscribe-to-timeline.ts +4 -4
  36. package/internal/src/timeline/add-atom-to-timeline.ts +7 -7
  37. package/internal/src/timeline/create-timeline.ts +29 -21
  38. package/internal/src/timeline/time-travel.ts +19 -45
  39. package/internal/src/transaction/apply-transaction.ts +5 -51
  40. package/internal/src/transaction/build-transaction.ts +9 -2
  41. package/internal/src/transaction/create-transaction.ts +4 -4
  42. package/internal/src/transaction/index.ts +2 -2
  43. package/introspection/dist/index.cjs +9 -9
  44. package/introspection/dist/index.cjs.map +1 -1
  45. package/introspection/dist/index.d.ts +6 -6
  46. package/introspection/dist/index.js +9 -9
  47. package/introspection/dist/index.js.map +1 -1
  48. package/introspection/src/attach-atom-index.ts +4 -4
  49. package/introspection/src/attach-introspection-states.ts +2 -2
  50. package/introspection/src/attach-selector-index.ts +4 -4
  51. package/introspection/src/attach-timeline-family.ts +6 -6
  52. package/introspection/src/attach-timeline-index.ts +6 -4
  53. package/introspection/src/attach-transaction-index.ts +1 -1
  54. package/introspection/src/index.ts +1 -1
  55. package/package.json +11 -12
  56. package/react/dist/index.cjs.map +1 -1
  57. package/react/dist/index.d.ts +4 -4
  58. package/react/dist/index.js.map +1 -1
  59. package/react/src/store-hooks.ts +5 -5
  60. package/react-devtools/dist/index.cjs +7 -9
  61. package/react-devtools/dist/index.cjs.map +1 -1
  62. package/react-devtools/dist/index.d.ts +10 -265
  63. package/react-devtools/dist/index.js +7 -9
  64. package/react-devtools/dist/index.js.map +1 -1
  65. package/react-devtools/src/StateEditor.tsx +3 -3
  66. package/react-devtools/src/StateIndex.tsx +3 -3
  67. package/react-devtools/src/TimelineIndex.tsx +2 -2
  68. package/react-devtools/src/Updates.tsx +1 -1
  69. package/realtime-client/dist/index.cjs +68 -66
  70. package/realtime-client/dist/index.cjs.map +1 -1
  71. package/realtime-client/dist/index.d.ts +8 -7
  72. package/realtime-client/dist/index.js +63 -62
  73. package/realtime-client/dist/index.js.map +1 -1
  74. package/realtime-client/src/pull-family-member.ts +1 -1
  75. package/realtime-client/src/pull.ts +1 -1
  76. package/realtime-client/src/push.ts +2 -3
  77. package/realtime-client/src/realtime-state.ts +11 -3
  78. package/realtime-client/src/server-action.ts +65 -65
  79. package/realtime-react/dist/index.cjs +90 -56
  80. package/realtime-react/dist/index.cjs.map +1 -1
  81. package/realtime-react/dist/index.d.ts +11 -6
  82. package/realtime-react/dist/index.js +89 -55
  83. package/realtime-react/dist/index.js.map +1 -1
  84. package/realtime-react/src/on-mount.ts +23 -0
  85. package/realtime-react/src/realtime-context.tsx +14 -6
  86. package/realtime-react/src/use-pull-family-member.ts +5 -8
  87. package/realtime-react/src/use-pull-mutable-family-member.ts +4 -7
  88. package/realtime-react/src/use-pull-mutable.ts +4 -7
  89. package/realtime-react/src/use-pull.ts +5 -8
  90. package/realtime-react/src/use-push.ts +5 -9
  91. package/realtime-react/src/use-realtime-service.ts +30 -0
  92. package/realtime-react/src/use-server-action.ts +8 -8
  93. package/realtime-server/dist/index.cjs +109 -40
  94. package/realtime-server/dist/index.cjs.map +1 -1
  95. package/realtime-server/dist/index.d.ts +7 -6
  96. package/realtime-server/dist/index.js +90 -39
  97. package/realtime-server/dist/index.js.map +1 -1
  98. package/realtime-server/src/hook-composition/expose-family.ts +2 -2
  99. package/realtime-server/src/hook-composition/expose-mutable-family.ts +1 -1
  100. package/realtime-server/src/hook-composition/expose-single.ts +1 -1
  101. package/realtime-server/src/hook-composition/index.ts +2 -1
  102. package/realtime-server/src/hook-composition/receive-state.ts +2 -2
  103. package/realtime-server/src/hook-composition/receive-transaction.ts +13 -32
  104. package/realtime-server/src/hook-composition/sync-transaction.ts +92 -0
  105. package/realtime-testing/dist/index.cjs +3 -3
  106. package/realtime-testing/dist/index.cjs.map +1 -1
  107. package/realtime-testing/dist/index.js +2 -2
  108. package/realtime-testing/dist/index.js.map +1 -1
  109. package/realtime-testing/src/setup-realtime-test.tsx +4 -3
  110. package/src/atom.ts +30 -7
  111. package/src/dispose.ts +2 -2
  112. package/src/find-state.ts +64 -0
  113. package/src/get-state.ts +2 -2
  114. package/src/index.ts +23 -0
  115. package/src/logger.ts +1 -0
  116. package/src/selector.ts +16 -0
  117. package/src/set-state.ts +2 -2
  118. package/src/silo.ts +2 -2
  119. package/src/subscribe.ts +7 -11
  120. package/src/timeline.ts +20 -12
  121. package/src/transaction.ts +31 -12
  122. package/src/validators.ts +74 -0
  123. package/dist/chunk-K22LR3V6.js +0 -138
  124. package/dist/chunk-K22LR3V6.js.map +0 -1
  125. package/internal/src/set-state/copy-mutable-into-new-store.ts +0 -34
@@ -1,4 +1,4 @@
1
- import { FamilyMetadata as FamilyMetadata$1, SelectorOptions, SelectorToken, ReadonlySelectorOptions, ReadonlySelectorToken, Transactors, StateToken, ƒn as _n, TransactionUpdate, TransactionOptions, TransactionToken, TransactorsWithRun, AtomToken, MutableAtomOptions, MutableAtomToken, MutableAtomFamilyOptions, MutableAtomFamily, SelectorFamily, AtomFamily, StateUpdate, TimelineUpdate, TimelineOptions, TimelineToken, ReadonlySelectorFamily, AtomIOLogger, Logger, AtomOptions, AtomFamilyOptions, ReadonlySelectorFamilyOptions, SelectorFamilyOptions, UpdateHandler, TransactionUpdateHandler } from 'atom.io';
1
+ import { FamilyMetadata as FamilyMetadata$1, SelectorOptions, SelectorToken, ReadonlySelectorOptions, ReadonlySelectorToken, Transactors, WritableToken, ƒn as _n, TransactionUpdate, TransactionOptions, TransactionToken, TransactorsWithRunAndEnv, AtomToken, ReadableToken, MutableAtomOptions, MutableAtomToken, MutableAtomFamilyOptions, MutableAtomFamily, SelectorFamily, AtomFamily, TimelineManageable, StateUpdate, TokenType, TimelineUpdate, TimelineOptions, TimelineToken, ReadonlySelectorFamily, AtomIOLogger, Logger, AtomOptions, AtomFamilyOptions, ReadonlySelectorFamilyOptions, SelectorFamilyOptions, KeyedStateUpdate, UpdateHandler, TransactionUpdateHandler } from 'atom.io';
2
2
  import { Json } from 'atom.io/json';
3
3
  import { Store as Store$1 } from 'atom.io/internal';
4
4
 
@@ -73,20 +73,20 @@ declare const registerSelector: (selectorKey: string, store: Store) => Transacto
73
73
  declare const traceSelectorAtoms: (selectorKey: string, directDependencyKey: StateKey<unknown>, store: Store) => AtomKey<unknown>[];
74
74
  declare const traceAllSelectorAtoms: (selectorKey: string, store: Store) => AtomKey<unknown>[];
75
75
 
76
- declare const updateSelectorAtoms: (selectorKey: string, dependency: ReadonlySelectorToken<unknown> | StateToken<unknown>, store: Store) => void;
76
+ declare const updateSelectorAtoms: (selectorKey: string, dependency: ReadonlySelectorToken<unknown> | WritableToken<unknown>, store: Store) => void;
77
77
 
78
78
  declare const abortTransaction: (store: Store) => void;
79
79
 
80
80
  declare const applyTransaction: <ƒ extends _n>(output: ReturnType<ƒ>, store: Store) => void;
81
81
 
82
- declare const buildTransaction: (key: string, params: any[], store: Store) => void;
82
+ declare const buildTransaction: (key: string, params: any[], store: Store, id?: string) => void;
83
83
 
84
84
  type Transaction<ƒ extends _n> = {
85
85
  key: string;
86
86
  type: `transaction`;
87
87
  install: (store: Store) => void;
88
88
  subject: Subject<TransactionUpdate<ƒ>>;
89
- run: (...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
89
+ run: (parameters: Parameters<ƒ>, id?: string) => ReturnType<ƒ>;
90
90
  };
91
91
  declare function createTransaction<ƒ extends _n>(options: TransactionOptions<ƒ>, store: Store): TransactionToken<ƒ>;
92
92
 
@@ -96,15 +96,15 @@ type TransactionMeta<ƒ extends _n> = {
96
96
  phase: `applying` | `building`;
97
97
  time: number;
98
98
  update: TransactionUpdate<ƒ>;
99
- transactors: TransactorsWithRun;
99
+ transactors: TransactorsWithRunAndEnv;
100
100
  };
101
101
 
102
102
  declare function deposit<T>(state: Atom<T>): AtomToken<T>;
103
103
  declare function deposit<T>(state: Selector<T>): SelectorToken<T>;
104
- declare function deposit<T>(state: Atom<T> | Selector<T>): StateToken<T>;
104
+ declare function deposit<T>(state: Atom<T> | Selector<T>): WritableToken<T>;
105
105
  declare function deposit<T>(state: ReadonlySelector<T>): ReadonlySelectorToken<T>;
106
106
  declare function deposit<T>(state: Transaction<T extends _n ? T : never>): TransactionToken<T>;
107
- declare function deposit<T>(state: Atom<T> | ReadonlySelector<T> | Selector<T>): ReadonlySelectorToken<T> | StateToken<T>;
107
+ declare function deposit<T>(state: StateNode<T>): ReadableToken<T>;
108
108
 
109
109
  type primitive = boolean | number | string | null;
110
110
 
@@ -246,47 +246,47 @@ type OperationProgress = {
246
246
  done: Set<string>;
247
247
  prev: Map<string, any>;
248
248
  time: number;
249
- token: StateToken<any>;
249
+ token: WritableToken<any>;
250
250
  };
251
- declare const openOperation: (token: StateToken<any>, store: Store) => `rejection` | undefined;
251
+ declare const openOperation: (token: WritableToken<any>, store: Store) => `rejection` | undefined;
252
252
  declare const closeOperation: (store: Store) => void;
253
253
  declare const isDone: (key: string, store: Store) => boolean;
254
254
  declare const markDone: (key: string, store: Store) => void;
255
255
 
256
- type TimelineAtomUpdate = StateUpdate<unknown> & {
256
+ type TimelineAtomUpdate<ManagedAtom extends TimelineManageable> = StateUpdate<TokenType<ManagedAtom>> & {
257
257
  key: string;
258
258
  type: `atom_update`;
259
259
  timestamp: number;
260
260
  family?: FamilyMetadata$1;
261
261
  };
262
- type TimelineSelectorUpdate = {
262
+ type TimelineSelectorUpdate<ManagedAtom extends TimelineManageable> = {
263
263
  key: string;
264
264
  type: `selector_update`;
265
265
  timestamp: number;
266
- atomUpdates: Omit<TimelineAtomUpdate, `timestamp`>[];
266
+ atomUpdates: Omit<TimelineAtomUpdate<ManagedAtom>, `timestamp`>[];
267
267
  };
268
268
  type TimelineTransactionUpdate = TransactionUpdate<_n> & {
269
269
  key: string;
270
270
  type: `transaction_update`;
271
271
  timestamp: number;
272
272
  };
273
- type Timeline = {
273
+ type Timeline<ManagedAtom extends TimelineManageable> = {
274
274
  type: `timeline`;
275
275
  key: string;
276
276
  at: number;
277
- shouldCapture?: (update: TimelineUpdate, timeline: Timeline) => boolean;
277
+ shouldCapture?: (update: TimelineUpdate<TimelineManageable>, timeline: Timeline<ManagedAtom>) => boolean;
278
278
  timeTraveling: `into_future` | `into_past` | null;
279
- history: TimelineUpdate[];
279
+ history: TimelineUpdate<ManagedAtom>[];
280
280
  selectorTime: number | null;
281
281
  transactionKey: string | null;
282
282
  install: (store: Store) => void;
283
- subject: Subject<TimelineAtomUpdate | TimelineSelectorUpdate | TimelineTransactionUpdate | `redo` | `undo`>;
283
+ subject: Subject<TimelineAtomUpdate<ManagedAtom> | TimelineSelectorUpdate<ManagedAtom> | TimelineTransactionUpdate | `redo` | `undo`>;
284
284
  };
285
- declare function createTimeline(options: TimelineOptions, store: Store, data?: Timeline): TimelineToken;
285
+ declare function createTimeline<ManagedAtom extends TimelineManageable>(options: TimelineOptions<ManagedAtom>, store: Store, data?: Timeline<ManagedAtom>): TimelineToken<ManagedAtom>;
286
286
 
287
- declare const addAtomToTimeline: (atomToken: AtomToken<any>, tl: Timeline, store: Store) => void;
287
+ declare const addAtomToTimeline: (atomToken: AtomToken<any>, tl: Timeline<any>, store: Store) => void;
288
288
 
289
- declare const timeTravel: (direction: `backward` | `forward`, token: TimelineToken, store: Store) => void;
289
+ declare const timeTravel: (action: `redo` | `undo`, token: TimelineToken<any>, store: Store) => void;
290
290
 
291
291
  declare class Store implements Lineage {
292
292
  parent: Store | null;
@@ -297,7 +297,7 @@ declare class Store implements Lineage {
297
297
  readonlySelectors: Map<string, ReadonlySelector<any>>;
298
298
  trackers: Map<string, Tracker<Transceiver<any>>>;
299
299
  families: Map<string, AtomFamily<any, any> | ReadonlySelectorFamily<any, any> | SelectorFamily<any, any>>;
300
- timelines: Map<string, Timeline>;
300
+ timelines: Map<string, Timeline<any>>;
301
301
  transactions: Map<string, Transaction<_n>>;
302
302
  atomsThatAreDefault: Set<string>;
303
303
  timelineAtoms: Junction<"timelineKey", "atomKey", null>;
@@ -305,13 +305,13 @@ declare class Store implements Lineage {
305
305
  selectorGraph: Junction<"upstreamSelectorKey", "downstreamSelectorKey", {
306
306
  source: string;
307
307
  }>;
308
- subject: {
308
+ on: {
309
309
  atomCreation: Subject<AtomToken<unknown>>;
310
310
  selectorCreation: Subject<ReadonlySelectorToken<unknown> | SelectorToken<unknown>>;
311
311
  transactionCreation: Subject<TransactionToken<_n>>;
312
- timelineCreation: Subject<TimelineToken>;
312
+ timelineCreation: Subject<TimelineToken<unknown>>;
313
313
  transactionApplying: StatefulSubject<TransactionMeta<_n> | null>;
314
- operationStatus: Subject<OperationProgress>;
314
+ operationClose: Subject<OperationProgress>;
315
315
  };
316
316
  operation: OperationProgress;
317
317
  transactionMeta: TransactionMeta<_n> | null;
@@ -330,17 +330,17 @@ declare const clearStore: (store: Store) => void;
330
330
 
331
331
  declare function withdraw<T>(token: AtomToken<T>, store: Store): Atom<T> | undefined;
332
332
  declare function withdraw<T>(token: SelectorToken<T>, store: Store): Selector<T> | undefined;
333
- declare function withdraw<T>(token: StateToken<T>, store: Store): Atom<T> | Selector<T> | undefined;
333
+ declare function withdraw<T>(token: WritableToken<T>, store: Store): Atom<T> | Selector<T> | undefined;
334
334
  declare function withdraw<T>(token: ReadonlySelectorToken<T>, store: Store): ReadonlySelector<T> | undefined;
335
335
  declare function withdraw<T>(token: TransactionToken<T>, store: Store): Transaction<T extends _n ? T : never> | undefined;
336
- declare function withdraw<T>(token: ReadonlySelectorToken<T> | StateToken<T>, store: Store): Atom<T> | ReadonlySelector<T> | Selector<T> | undefined;
337
- declare function withdraw<T>(token: TimelineToken, store: Store): Timeline | undefined;
336
+ declare function withdraw<T>(token: ReadableToken<T>, store: Store): StateNode<T> | undefined;
337
+ declare function withdraw<T>(token: TimelineToken<T>, store: Store): Timeline<T extends TimelineManageable ? T : never> | undefined;
338
338
 
339
339
  declare function withdrawNewFamilyMember<T>(token: AtomToken<T>, store: Store): Atom<T> | undefined;
340
340
  declare function withdrawNewFamilyMember<T>(token: SelectorToken<T>, store: Store): Selector<T> | undefined;
341
341
  declare function withdrawNewFamilyMember<T>(token: ReadonlySelectorToken<T>, store: Store): ReadonlySelector<T> | undefined;
342
- declare function withdrawNewFamilyMember<T>(token: StateToken<T>, store: Store): Atom<T> | Selector<T> | undefined;
343
- declare function withdrawNewFamilyMember<T>(token: ReadonlySelectorToken<T> | StateToken<T>, store: Store): Atom<T> | ReadonlySelector<T> | Selector<T> | undefined;
342
+ declare function withdrawNewFamilyMember<T>(token: WritableToken<T>, store: Store): Atom<T> | Selector<T> | undefined;
343
+ declare function withdrawNewFamilyMember<T>(token: ReadableToken<T>, store: Store): StateNode<T> | undefined;
344
344
 
345
345
  declare function createAtom<T>(options: AtomOptions<T> | MutableAtomOptions<any, any>, family: FamilyMetadata$1 | undefined, store: Store): AtomToken<T>;
346
346
 
@@ -396,6 +396,18 @@ declare function createReadonlySelectorFamily<T, K extends Json.Serializable>(op
396
396
  declare function createSelectorFamily<T, K extends Json.Serializable>(options: SelectorFamilyOptions<T, K>, store: Store): SelectorFamily<T, K>;
397
397
  declare function createSelectorFamily<T, K extends Json.Serializable>(options: ReadonlySelectorFamilyOptions<T, K>, store: Store): ReadonlySelectorFamily<T, K>;
398
398
 
399
+ type EnvironmentData = {
400
+ runtime: `browser` | `node` | `unknown`;
401
+ store: Store;
402
+ };
403
+ declare function getEnvironmentData(store: Store): EnvironmentData;
404
+
405
+ declare function ingestAtomUpdate(applying: `newValue` | `oldValue`, atomUpdate: KeyedStateUpdate<any>, store: Store): void;
406
+
407
+ declare function ingestSelectorUpdate(applying: `newValue` | `oldValue`, selectorUpdate: TimelineSelectorUpdate<any>, store: Store): void;
408
+
409
+ declare function ingestTransactionUpdate(applying: `newValue` | `oldValue`, transactionUpdate: TransactionUpdate<any>, store: Store): void;
410
+
399
411
  declare class LazyMap<K, V> extends Map<K, V> {
400
412
  protected readonly source: Map<K, V>;
401
413
  deleted: Set<K>;
@@ -408,7 +420,7 @@ declare class LazyMap<K, V> extends Map<K, V> {
408
420
  }
409
421
 
410
422
  declare class NotFoundError extends Error {
411
- constructor(token: ReadonlySelectorToken<any> | StateToken<any>, store: Store);
423
+ constructor(token: ReadableToken<any>, store: Store);
412
424
  }
413
425
 
414
426
  declare const readOrComputeValue: <T>(state: StateNode<T>, target: Store) => T;
@@ -420,12 +432,12 @@ declare const setAtomOrSelector: <T>(state: Atom<T> | Selector<T>, value: T | ((
420
432
 
421
433
  declare const subscribeToRootAtoms: <T>(state: ReadonlySelector<T> | Selector<T>, store: Store) => (() => void)[] | null;
422
434
 
423
- declare function subscribeToState<T>(token: ReadonlySelectorToken<T> | StateToken<T>, handleUpdate: UpdateHandler<T>, key: string, store: Store): () => void;
435
+ declare function subscribeToState<T>(token: ReadableToken<T>, handleUpdate: UpdateHandler<T>, key: string, store: Store): () => void;
424
436
 
425
- declare const subscribeToTimeline: (token: TimelineToken, handleUpdate: (update: TimelineUpdate | `redo` | `undo`) => void, key: string, store: Store$1) => (() => void);
437
+ declare const subscribeToTimeline: <ManagedAtom extends TimelineManageable>(token: TimelineToken<ManagedAtom>, handleUpdate: (update: TimelineUpdate<any> | `redo` | `undo`) => void, key: string, store: Store$1) => (() => void);
426
438
 
427
439
  declare const subscribeToTransaction: <ƒ extends _n>(token: TransactionToken<ƒ>, handleUpdate: TransactionUpdateHandler<ƒ>, key: string, store: Store$1) => (() => void);
428
440
 
429
441
  type StateNode<T> = Atom<T> | ReadonlySelector<T> | Selector<T>;
430
442
 
431
- export { type Atom, type AtomKey, FamilyTracker, Future, IMPLICIT, LazyMap, type Lineage, type Modify, type MutableAtom, NotFoundError, type OperationProgress, type ReadonlySelector, type ReadonlySelectorKey, type Selector, type SelectorKey, type Signal, type StateKey, type StateNode, StatefulSubject, Store, Subject, TRANSACTION_PHASES, type Timeline, type TimelineAtomUpdate, type TimelineSelectorUpdate, type TimelineTransactionUpdate, Tracker, type Transaction, type TransactionMeta, type TransactionPhase, type Transceiver, type TransceiverMode, abortTransaction, addAtomToTimeline, applyTransaction, become, buildTransaction, cacheValue, clearStore, closeOperation, createAtom, createAtomFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelectorFamily, createRegularAtom, createRegularAtomFamily, createSelector, createSelectorFamily, createTimeline, createTransaction, deleteAtom, deleteSelector, deposit, eldest, evictCachedValue, getJsonFamily, getJsonToken, getSelectorDependencyKeys, getUpdateFamily, getUpdateToken, isAtomDefault, isAtomKey, isDone, isReadonlySelectorKey, isSelectorKey, isStateKey, isTransceiver, markAtomAsDefault, markAtomAsNotDefault, markDone, newest, openOperation, readCachedValue, readOrComputeValue, registerSelector, setAtomOrSelector, subscribeToRootAtoms, subscribeToState, subscribeToTimeline, subscribeToTransaction, timeTravel, traceAllSelectorAtoms, traceSelectorAtoms, updateSelectorAtoms, withdraw, withdrawNewFamilyMember };
443
+ export { type Atom, type AtomKey, type EnvironmentData, FamilyTracker, Future, IMPLICIT, LazyMap, type Lineage, type Modify, type MutableAtom, NotFoundError, type OperationProgress, type ReadonlySelector, type ReadonlySelectorKey, type Selector, type SelectorKey, type Signal, type StateKey, type StateNode, StatefulSubject, Store, Subject, TRANSACTION_PHASES, type Timeline, type TimelineAtomUpdate, type TimelineSelectorUpdate, type TimelineTransactionUpdate, Tracker, type Transaction, type TransactionMeta, type TransactionPhase, type Transceiver, type TransceiverMode, abortTransaction, addAtomToTimeline, applyTransaction, become, buildTransaction, cacheValue, clearStore, closeOperation, createAtom, createAtomFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelectorFamily, createRegularAtom, createRegularAtomFamily, createSelector, createSelectorFamily, createTimeline, createTransaction, deleteAtom, deleteSelector, deposit, eldest, evictCachedValue, getEnvironmentData, getJsonFamily, getJsonToken, getSelectorDependencyKeys, getUpdateFamily, getUpdateToken, ingestAtomUpdate, ingestSelectorUpdate, ingestTransactionUpdate, isAtomDefault, isAtomKey, isDone, isReadonlySelectorKey, isSelectorKey, isStateKey, isTransceiver, markAtomAsDefault, markAtomAsNotDefault, markDone, newest, openOperation, readCachedValue, readOrComputeValue, registerSelector, setAtomOrSelector, subscribeToRootAtoms, subscribeToState, subscribeToTimeline, subscribeToTransaction, timeTravel, traceAllSelectorAtoms, traceSelectorAtoms, updateSelectorAtoms, withdraw, withdrawNewFamilyMember };
@@ -1,8 +1,7 @@
1
- import { getState as getState$1, setState as setState$1, runTransaction } from '../../dist/chunk-K22LR3V6.js';
2
1
  import { Junction } from '../../dist/chunk-NYTGCPHB.js';
3
2
  import { __spreadValues, __spreadProps } from '../../dist/chunk-PZLG2HP3.js';
4
3
  import { selectJson, stringifyJson, parseJson, selectJsonFamily } from 'atom.io/json';
5
- import { AtomIOLogger, getState, setState } from 'atom.io';
4
+ import { AtomIOLogger, findInStore, getState, setState, runTransaction } from 'atom.io';
6
5
  import { withdraw as withdraw$1 } from 'atom.io/internal';
7
6
 
8
7
  // internal/src/lineage.ts
@@ -187,7 +186,7 @@ var closeOperation = (store) => {
187
186
  );
188
187
  }
189
188
  store.operation = { open: false };
190
- store.subject.operationStatus.next(store.operation);
189
+ store.on.operationClose.next(store.operation);
191
190
  };
192
191
  var isDone = (key, store) => {
193
192
  if (!store.operation.open) {
@@ -413,13 +412,13 @@ var Store = class {
413
412
  makeContentKey: (...keys) => keys.sort().join(`:`)
414
413
  }
415
414
  );
416
- this.subject = {
415
+ this.on = {
417
416
  atomCreation: new Subject(),
418
417
  selectorCreation: new Subject(),
419
418
  transactionCreation: new Subject(),
420
419
  timelineCreation: new Subject(),
421
420
  transactionApplying: new StatefulSubject(null),
422
- operationStatus: new Subject()
421
+ operationClose: new Subject()
423
422
  };
424
423
  this.operation = { open: false };
425
424
  this.transactionMeta = null;
@@ -654,24 +653,27 @@ var registerSelector = (selectorKey, store) => ({
654
653
  updateSelectorAtoms(selectorKey, dependency, store);
655
654
  return dependencyValue;
656
655
  },
657
- set: (stateToken, newValue) => {
658
- const state = withdraw(stateToken, store);
656
+ set: (WritableToken, newValue) => {
657
+ const state = withdraw(WritableToken, store);
659
658
  if (state === void 0) {
660
659
  throw new Error(
661
- `State "${stateToken.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`
660
+ `State "${WritableToken.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`
662
661
  );
663
662
  }
664
663
  setAtomOrSelector(state, newValue, store);
665
- }
664
+ },
665
+ find: (token, key) => findInStore(token, key, store)
666
666
  });
667
667
 
668
668
  // internal/src/selector/create-read-write-selector.ts
669
669
  var createReadWriteSelector = (options, family, store) => {
670
670
  const target = newest(store);
671
671
  const subject = new Subject();
672
- const { get, set } = registerSelector(options.key, store);
672
+ const transactors = registerSelector(options.key, store);
673
+ const { find, get } = transactors;
674
+ const readonlyTransactors = { find, get };
673
675
  const getSelf = () => {
674
- const value = options.get({ get });
676
+ const value = options.get(readonlyTransactors);
675
677
  cacheValue(options.key, value, subject, newest(store));
676
678
  return value;
677
679
  };
@@ -693,7 +695,7 @@ var createReadWriteSelector = (options, family, store) => {
693
695
  if (target.transactionMeta === null) {
694
696
  subject.next({ newValue, oldValue });
695
697
  }
696
- options.set({ get, set }, newValue);
698
+ options.set(transactors, newValue);
697
699
  };
698
700
  const mySelector = __spreadValues(__spreadProps(__spreadValues({}, options), {
699
701
  subject,
@@ -712,7 +714,7 @@ var createReadWriteSelector = (options, family, store) => {
712
714
  if (family) {
713
715
  token.family = family;
714
716
  }
715
- store.subject.selectorCreation.next(token);
717
+ store.on.selectorCreation.next(token);
716
718
  return token;
717
719
  };
718
720
 
@@ -720,9 +722,9 @@ var createReadWriteSelector = (options, family, store) => {
720
722
  var createReadonlySelector = (options, family, store) => {
721
723
  const target = newest(store);
722
724
  const subject = new Subject();
723
- const { get } = registerSelector(options.key, store);
725
+ const { get, find } = registerSelector(options.key, store);
724
726
  const getSelf = () => {
725
- const value = options.get({ get });
727
+ const value = options.get({ get, find });
726
728
  cacheValue(options.key, value, subject, store);
727
729
  return value;
728
730
  };
@@ -748,7 +750,7 @@ var createReadonlySelector = (options, family, store) => {
748
750
  if (family) {
749
751
  token.family = family;
750
752
  }
751
- store.subject.selectorCreation.next(token);
753
+ store.on.selectorCreation.next(token);
752
754
  return token;
753
755
  };
754
756
 
@@ -959,7 +961,7 @@ var Tracker = class {
959
961
  `tracker:${store.config.name}:${target.transactionMeta === null ? `main` : target.transactionMeta.update.key}`,
960
962
  (update) => {
961
963
  if (target.operation.open) {
962
- const unsubscribe = target.subject.operationStatus.subscribe(
964
+ const unsubscribe = target.on.operationClose.subscribe(
963
965
  mutableState.key,
964
966
  () => {
965
967
  unsubscribe();
@@ -982,7 +984,7 @@ var Tracker = class {
982
984
  `tracker:${store.config.name}:${target2.transactionMeta === null ? `main` : target2.transactionMeta.update.key}`,
983
985
  (update2) => {
984
986
  if (target2.operation.open) {
985
- const unsubscribe = target2.subject.operationStatus.subscribe(
987
+ const unsubscribe = target2.on.operationClose.subscribe(
986
988
  mutableState.key,
987
989
  () => {
988
990
  unsubscribe();
@@ -1034,7 +1036,7 @@ var Tracker = class {
1034
1036
  return;
1035
1037
  }
1036
1038
  }
1037
- const unsubscribe = store.subject.operationStatus.subscribe(
1039
+ const unsubscribe = store.on.operationClose.subscribe(
1038
1040
  latestUpdateState.key,
1039
1041
  () => {
1040
1042
  unsubscribe();
@@ -1392,7 +1394,7 @@ function createRegularAtom(options, family, store) {
1392
1394
  }
1393
1395
  };
1394
1396
  }
1395
- store.subject.atomCreation.next(token);
1397
+ store.on.atomCreation.next(token);
1396
1398
  return token;
1397
1399
  }
1398
1400
 
@@ -1405,7 +1407,7 @@ function createAtom(options, family, store) {
1405
1407
  }
1406
1408
 
1407
1409
  // internal/src/atom/delete-atom.ts
1408
- function deleteAtom2(atomToken, store) {
1410
+ function deleteAtom(atomToken, store) {
1409
1411
  var _a, _b;
1410
1412
  const target = newest(store);
1411
1413
  const { key } = atomToken;
@@ -1436,6 +1438,39 @@ function deleteAtom2(atomToken, store) {
1436
1438
  store.logger.info(`\u{1F525}`, `atom`, `${key}`, `deleted`);
1437
1439
  }
1438
1440
 
1441
+ // internal/src/get-environment-data.ts
1442
+ function getEnvironmentData(store) {
1443
+ return {
1444
+ runtime: typeof window === `undefined` ? typeof global === `object` ? `node` : `unknown` : `browser`,
1445
+ store
1446
+ };
1447
+ }
1448
+ function ingestAtomUpdate(applying, atomUpdate, store) {
1449
+ const { key, newValue, oldValue } = atomUpdate;
1450
+ const value = applying === `newValue` ? newValue : oldValue;
1451
+ setState({ key, type: `atom` }, value, store);
1452
+ }
1453
+
1454
+ // internal/src/ingest-updates/ingest-selector-update.ts
1455
+ function ingestSelectorUpdate(applying, selectorUpdate, store) {
1456
+ const updates = applying === `newValue` ? selectorUpdate.atomUpdates : [...selectorUpdate.atomUpdates].reverse();
1457
+ for (const atomUpdate of updates) {
1458
+ ingestAtomUpdate(applying, atomUpdate, store);
1459
+ }
1460
+ }
1461
+
1462
+ // internal/src/ingest-updates/ingest-transaction-update.ts
1463
+ function ingestTransactionUpdate(applying, transactionUpdate, store) {
1464
+ const updates = applying === `newValue` ? transactionUpdate.updates : [...transactionUpdate.updates].reverse();
1465
+ for (const updateFromTransaction of updates) {
1466
+ if (`newValue` in updateFromTransaction) {
1467
+ ingestAtomUpdate(applying, updateFromTransaction, store);
1468
+ } else {
1469
+ ingestTransactionUpdate(applying, updateFromTransaction, store);
1470
+ }
1471
+ }
1472
+ }
1473
+
1439
1474
  // internal/src/lazy-map.ts
1440
1475
  var LazyMap = class extends Map {
1441
1476
  constructor(source) {
@@ -1505,8 +1540,8 @@ var addAtomToTimeline = (atomToken, tl, store) => {
1505
1540
  const target = newest(store);
1506
1541
  const currentSelectorKey = store.operation.open && store.operation.token.type === `selector` ? store.operation.token.key : null;
1507
1542
  const currentSelectorTime = store.operation.open && store.operation.token.type === `selector` ? store.operation.time : null;
1508
- const currentTransactionKey = (_a = target.subject.transactionApplying.state) == null ? void 0 : _a.update.key;
1509
- const currentTransactionTime = (_b = target.subject.transactionApplying.state) == null ? void 0 : _b.time;
1543
+ const currentTransactionKey = (_a = target.on.transactionApplying.state) == null ? void 0 : _a.update.key;
1544
+ const currentTransactionTime = (_b = target.on.transactionApplying.state) == null ? void 0 : _b.time;
1510
1545
  store.logger.info(
1511
1546
  `\u23F3`,
1512
1547
  `timeline`,
@@ -1786,13 +1821,14 @@ function createTimeline(options, store, data) {
1786
1821
  key: timelineKey,
1787
1822
  type: `timeline`
1788
1823
  };
1789
- store.subject.timelineCreation.next(token);
1824
+ store.on.timelineCreation.next(token);
1790
1825
  return token;
1791
1826
  }
1792
- var timeTravel = (direction, token, store) => {
1793
- const action = direction === `forward` ? `redo` : `undo`;
1827
+
1828
+ // internal/src/timeline/time-travel.ts
1829
+ var timeTravel = (action, token, store) => {
1794
1830
  store.logger.info(
1795
- direction === `forward` ? `\u23E9` : `\u23EA`,
1831
+ action === `redo` ? `\u23E9` : `\u23EA`,
1796
1832
  `timeline`,
1797
1833
  token.key,
1798
1834
  action
@@ -1807,53 +1843,36 @@ var timeTravel = (direction, token, store) => {
1807
1843
  );
1808
1844
  return;
1809
1845
  }
1810
- if (direction === `forward` && timelineData.at === timelineData.history.length || direction === `backward` && timelineData.at === 0) {
1846
+ if (action === `redo` && timelineData.at === timelineData.history.length || action === `undo` && timelineData.at === 0) {
1811
1847
  store.logger.warn(
1812
1848
  `\u{1F481}`,
1813
1849
  `timeline`,
1814
1850
  token.key,
1815
- `Failed to ${action} at the ${direction === `forward` ? `end` : `beginning`} of timeline "${token.key}". There is nothing to ${action}.`
1851
+ `Failed to ${action} at the ${action === `redo` ? `end` : `beginning`} of timeline "${token.key}". There is nothing to ${action}.`
1816
1852
  );
1817
1853
  return;
1818
1854
  }
1819
- timelineData.timeTraveling = direction === `forward` ? `into_future` : `into_past`;
1820
- if (direction === `backward`) {
1855
+ timelineData.timeTraveling = action === `redo` ? `into_future` : `into_past`;
1856
+ if (action === `undo`) {
1821
1857
  --timelineData.at;
1822
1858
  }
1823
1859
  const update = timelineData.history[timelineData.at];
1824
- const updateValues = (atomUpdate) => {
1825
- const { key, newValue, oldValue } = atomUpdate;
1826
- const value = direction === `forward` ? newValue : oldValue;
1827
- setState({ key, type: `atom` }, value, store);
1828
- };
1829
- const updateValuesFromTransactionUpdate = (transactionUpdate) => {
1830
- const updates = direction === `forward` ? transactionUpdate.updates : [...transactionUpdate.updates].reverse();
1831
- for (const updateFromTransaction of updates) {
1832
- if (`newValue` in updateFromTransaction) {
1833
- updateValues(updateFromTransaction);
1834
- } else {
1835
- updateValuesFromTransactionUpdate(updateFromTransaction);
1836
- }
1837
- }
1838
- };
1860
+ const applying = action === `redo` ? `newValue` : `oldValue`;
1839
1861
  switch (update.type) {
1840
1862
  case `atom_update`: {
1841
- updateValues(update);
1863
+ ingestAtomUpdate(applying, update, store);
1842
1864
  break;
1843
1865
  }
1844
1866
  case `selector_update`: {
1845
- const updates = direction === `forward` ? update.atomUpdates : [...update.atomUpdates].reverse();
1846
- for (const atomUpdate of updates) {
1847
- updateValues(atomUpdate);
1848
- }
1867
+ ingestSelectorUpdate(applying, update, store);
1849
1868
  break;
1850
1869
  }
1851
1870
  case `transaction_update`: {
1852
- updateValuesFromTransactionUpdate(update);
1871
+ ingestTransactionUpdate(applying, update, store);
1853
1872
  break;
1854
1873
  }
1855
1874
  }
1856
- if (direction === `forward`) {
1875
+ if (action === `redo`) {
1857
1876
  ++timelineData.at;
1858
1877
  }
1859
1878
  timelineData.subject.next(action);
@@ -1886,44 +1905,8 @@ var abortTransaction = (store) => {
1886
1905
  );
1887
1906
  target.parent.child = null;
1888
1907
  };
1889
- function ingestAtomUpdate(update, parent, child) {
1890
- var _a, _b, _c;
1891
- const { key, newValue } = update;
1892
- const token = { key, type: `atom` };
1893
- if (!parent.valueMap.has(token.key)) {
1894
- if (token.family) {
1895
- const family = parent.families.get(token.family.key);
1896
- if (family) {
1897
- family(token.family.subKey);
1898
- }
1899
- } else {
1900
- const newAtom = child.atoms.get(token.key);
1901
- if (!newAtom) {
1902
- throw new Error(
1903
- `Absurd Error: Atom "${token.key}" not found while copying updates from transaction "${(_a = child.transactionMeta) == null ? void 0 : _a.update.key}" to store "${parent.config.name}"`
1904
- );
1905
- }
1906
- parent.atoms.set(newAtom.key, newAtom);
1907
- parent.valueMap.set(newAtom.key, newAtom.default);
1908
- parent.logger.info(
1909
- `\u{1F528}`,
1910
- `transaction`,
1911
- (_c = (_b = child.transactionMeta) == null ? void 0 : _b.update.key) != null ? _c : `???`,
1912
- `Adding atom "${newAtom.key}"`
1913
- );
1914
- }
1915
- }
1916
- setState(token, newValue, parent);
1917
- }
1918
- function ingestTransactionUpdate(transactionUpdate, parent, child) {
1919
- for (const update of transactionUpdate.updates) {
1920
- if (`newValue` in update) {
1921
- ingestAtomUpdate(update, parent, child);
1922
- } else {
1923
- ingestTransactionUpdate(update, parent, child);
1924
- }
1925
- }
1926
- }
1908
+
1909
+ // internal/src/transaction/apply-transaction.ts
1927
1910
  var applyTransaction = (output, store) => {
1928
1911
  var _a;
1929
1912
  const child = newest(store);
@@ -1940,7 +1923,7 @@ var applyTransaction = (output, store) => {
1940
1923
  child.transactionMeta.phase = `applying`;
1941
1924
  child.transactionMeta.update.output = output;
1942
1925
  parent.child = null;
1943
- parent.subject.transactionApplying.next(child.transactionMeta);
1926
+ parent.on.transactionApplying.next(child.transactionMeta);
1944
1927
  const { updates } = child.transactionMeta.update;
1945
1928
  store.logger.info(
1946
1929
  `\u{1F6C4}`,
@@ -1969,7 +1952,7 @@ var applyTransaction = (output, store) => {
1969
1952
  );
1970
1953
  }
1971
1954
  }
1972
- ingestTransactionUpdate(child.transactionMeta.update, parent, child);
1955
+ ingestTransactionUpdate(`newValue`, child.transactionMeta.update, parent);
1973
1956
  if (parent.transactionMeta === null) {
1974
1957
  const myTransaction = withdraw(
1975
1958
  { key: child.transactionMeta.update.key, type: `transaction` },
@@ -1985,16 +1968,14 @@ var applyTransaction = (output, store) => {
1985
1968
  } else {
1986
1969
  parent.transactionMeta.update.updates.push(child.transactionMeta.update);
1987
1970
  }
1988
- parent.subject.transactionApplying.next(null);
1971
+ parent.on.transactionApplying.next(null);
1989
1972
  };
1990
-
1991
- // internal/src/transaction/build-transaction.ts
1992
- var buildTransaction = (key, params, store) => {
1973
+ var buildTransaction = (key, params, store, id) => {
1993
1974
  const parent = newest(store);
1994
1975
  const child = {
1995
1976
  parent,
1996
1977
  child: null,
1997
- subject: parent.subject,
1978
+ on: parent.on,
1998
1979
  loggers: parent.loggers,
1999
1980
  logger: parent.logger,
2000
1981
  config: parent.config,
@@ -2020,14 +2001,17 @@ var buildTransaction = (key, params, store) => {
2020
2001
  time: Date.now(),
2021
2002
  update: {
2022
2003
  key,
2004
+ id: id != null ? id : Math.random().toString(36).slice(2),
2023
2005
  updates: [],
2024
2006
  params,
2025
2007
  output: void 0
2026
2008
  },
2027
2009
  transactors: {
2028
- get: (token) => getState$1(token, child),
2029
- set: (token, value) => setState$1(token, value, child),
2030
- run: (token) => runTransaction(token, child)
2010
+ get: (token) => getState(token, child),
2011
+ set: (token, value) => setState(token, value, child),
2012
+ run: (token) => runTransaction(token, child),
2013
+ find: (token, key2) => findInStore(token, key2, child),
2014
+ env: () => getEnvironmentData(child)
2031
2015
  }
2032
2016
  };
2033
2017
  parent.child = child;
@@ -2045,8 +2029,8 @@ function createTransaction(options, store) {
2045
2029
  const newTransaction = {
2046
2030
  key: options.key,
2047
2031
  type: `transaction`,
2048
- run: (...params) => {
2049
- buildTransaction(options.key, params, store);
2032
+ run: (params, id) => {
2033
+ buildTransaction(options.key, params, store, id);
2050
2034
  try {
2051
2035
  const target2 = newest(store);
2052
2036
  const { transactors } = target2.transactionMeta;
@@ -2065,13 +2049,13 @@ function createTransaction(options, store) {
2065
2049
  const target = newest(store);
2066
2050
  target.transactions.set(newTransaction.key, newTransaction);
2067
2051
  const token = deposit(newTransaction);
2068
- store.subject.transactionCreation.next(token);
2052
+ store.on.transactionCreation.next(token);
2069
2053
  return token;
2070
2054
  }
2071
2055
 
2072
2056
  // internal/src/transaction/index.ts
2073
2057
  var TRANSACTION_PHASES = [`idle`, `building`, `applying`];
2074
2058
 
2075
- export { FamilyTracker, Future, IMPLICIT, LazyMap, NotFoundError, StatefulSubject, Store, Subject, TRANSACTION_PHASES, Tracker, abortTransaction, addAtomToTimeline, applyTransaction, become, buildTransaction, cacheValue, clearStore, closeOperation, createAtom, createAtomFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelectorFamily, createRegularAtom, createRegularAtomFamily, createSelector, createSelectorFamily, createTimeline, createTransaction, deleteAtom2 as deleteAtom, deleteSelector, deposit, eldest, evictCachedValue, getJsonFamily, getJsonToken, getSelectorDependencyKeys, getUpdateFamily, getUpdateToken, isAtomDefault, isAtomKey, isDone, isReadonlySelectorKey, isSelectorKey, isStateKey, isTransceiver, markAtomAsDefault, markAtomAsNotDefault, markDone, newest, openOperation, readCachedValue, readOrComputeValue, registerSelector, setAtomOrSelector, subscribeToRootAtoms, subscribeToState, subscribeToTimeline, subscribeToTransaction, timeTravel, traceAllSelectorAtoms, traceSelectorAtoms, updateSelectorAtoms, withdraw, withdrawNewFamilyMember };
2059
+ export { FamilyTracker, Future, IMPLICIT, LazyMap, NotFoundError, StatefulSubject, Store, Subject, TRANSACTION_PHASES, Tracker, abortTransaction, addAtomToTimeline, applyTransaction, become, buildTransaction, cacheValue, clearStore, closeOperation, createAtom, createAtomFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelectorFamily, createRegularAtom, createRegularAtomFamily, createSelector, createSelectorFamily, createTimeline, createTransaction, deleteAtom, deleteSelector, deposit, eldest, evictCachedValue, getEnvironmentData, getJsonFamily, getJsonToken, getSelectorDependencyKeys, getUpdateFamily, getUpdateToken, ingestAtomUpdate, ingestSelectorUpdate, ingestTransactionUpdate, isAtomDefault, isAtomKey, isDone, isReadonlySelectorKey, isSelectorKey, isStateKey, isTransceiver, markAtomAsDefault, markAtomAsNotDefault, markDone, newest, openOperation, readCachedValue, readOrComputeValue, registerSelector, setAtomOrSelector, subscribeToRootAtoms, subscribeToState, subscribeToTimeline, subscribeToTransaction, timeTravel, traceAllSelectorAtoms, traceSelectorAtoms, updateSelectorAtoms, withdraw, withdrawNewFamilyMember };
2076
2060
  //# sourceMappingURL=out.js.map
2077
2061
  //# sourceMappingURL=index.js.map