atom.io 0.21.1 → 0.23.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 (116) hide show
  1. package/data/dist/index.cjs +152 -63
  2. package/data/dist/index.d.ts +6 -0
  3. package/data/dist/index.js +3 -3
  4. package/data/src/join.ts +164 -51
  5. package/data/src/struct-family.ts +2 -2
  6. package/dist/chunk-6MLFYN32.js +18 -0
  7. package/dist/{chunk-HITX3MO4.js → chunk-7DT3PVS3.js} +151 -62
  8. package/dist/{chunk-RT43TVKP.js → chunk-GVHKIJ3G.js} +1 -1
  9. package/dist/chunk-OAYGID5B.js +27 -0
  10. package/dist/index.cjs +4 -18
  11. package/dist/index.d.ts +71 -28
  12. package/dist/index.js +6 -19
  13. package/ephemeral/dist/index.cjs +11 -0
  14. package/ephemeral/dist/index.js +9 -0
  15. package/ephemeral/package.json +16 -0
  16. package/ephemeral/src/index.ts +1 -0
  17. package/eslint-plugin/dist/index.cjs +155 -1
  18. package/eslint-plugin/dist/index.js +155 -1
  19. package/eslint-plugin/src/rules/index.ts +1 -0
  20. package/eslint-plugin/src/rules/lifespan.ts +203 -0
  21. package/eslint-plugin/src/rules/synchronous-selector-dependencies.ts +1 -65
  22. package/eslint-plugin/src/walk.ts +73 -0
  23. package/immortal/dist/index.cjs +260 -0
  24. package/immortal/dist/index.js +212 -0
  25. package/immortal/package.json +16 -0
  26. package/immortal/src/index.ts +3 -0
  27. package/immortal/src/make-molecule.ts +222 -0
  28. package/immortal/src/molecule.ts +167 -0
  29. package/immortal/src/seek-state.ts +73 -0
  30. package/internal/dist/index.cjs +1242 -837
  31. package/internal/dist/index.d.ts +135 -22
  32. package/internal/dist/index.js +1215 -838
  33. package/internal/src/atom/create-regular-atom.ts +0 -2
  34. package/internal/src/atom/create-standalone-atom.ts +6 -2
  35. package/internal/src/atom/dispose-atom.ts +26 -3
  36. package/internal/src/families/create-readonly-selector-family.ts +15 -10
  37. package/internal/src/families/create-regular-atom-family.ts +20 -21
  38. package/internal/src/families/create-writable-selector-family.ts +13 -9
  39. package/{src/dispose.ts → internal/src/families/dispose-from-store.ts} +7 -4
  40. package/internal/src/families/find-in-store.ts +11 -6
  41. package/internal/src/families/index.ts +3 -0
  42. package/internal/src/families/init-family-member.ts +112 -0
  43. package/internal/src/families/seek-in-store.ts +123 -0
  44. package/internal/src/get-state/get-from-store.ts +2 -2
  45. package/internal/src/ingest-updates/index.ts +1 -0
  46. package/internal/src/ingest-updates/ingest-creation-disposal.ts +104 -0
  47. package/internal/src/ingest-updates/ingest-transaction-update.ts +26 -4
  48. package/internal/src/mutable/create-mutable-atom-family.ts +22 -24
  49. package/internal/src/mutable/create-mutable-atom.ts +3 -3
  50. package/internal/src/mutable/get-json-family.ts +2 -2
  51. package/internal/src/mutable/get-json-token.ts +26 -12
  52. package/internal/src/mutable/tracker-family.ts +21 -19
  53. package/internal/src/not-found-error.ts +16 -3
  54. package/internal/src/selector/create-readonly-selector.ts +2 -3
  55. package/internal/src/selector/create-standalone-selector.ts +6 -2
  56. package/internal/src/selector/create-writable-selector.ts +2 -3
  57. package/internal/src/selector/dispose-selector.ts +68 -24
  58. package/internal/src/selector/register-selector.ts +10 -5
  59. package/internal/src/set-state/set-into-store.ts +2 -2
  60. package/internal/src/set-state/stow-update.ts +5 -1
  61. package/internal/src/store/deposit.ts +41 -7
  62. package/internal/src/store/index.ts +0 -1
  63. package/internal/src/store/store.ts +29 -5
  64. package/internal/src/store/withdraw.ts +28 -1
  65. package/internal/src/subscribe/subscribe-to-state.ts +2 -2
  66. package/internal/src/timeline/add-atom-to-timeline.ts +206 -182
  67. package/internal/src/timeline/create-timeline.ts +181 -60
  68. package/internal/src/timeline/time-travel.ts +20 -0
  69. package/internal/src/transaction/apply-transaction.ts +2 -12
  70. package/internal/src/transaction/build-transaction.ts +16 -2
  71. package/introspection/dist/index.cjs +40 -53
  72. package/introspection/dist/index.js +40 -53
  73. package/introspection/src/attach-atom-index.ts +38 -48
  74. package/introspection/src/attach-selector-index.ts +45 -50
  75. package/introspection/src/attach-timeline-family.ts +1 -0
  76. package/json/dist/index.cjs +40 -6
  77. package/json/dist/index.js +44 -9
  78. package/json/src/select-json-family.ts +47 -9
  79. package/package.json +30 -10
  80. package/react/dist/index.cjs +1 -1
  81. package/react/dist/index.js +1 -1
  82. package/react/src/use-json.ts +1 -1
  83. package/react-devtools/dist/index.cjs +69 -57
  84. package/react-devtools/dist/index.js +62 -49
  85. package/react-devtools/src/StateIndex.tsx +2 -1
  86. package/react-devtools/src/TimelineIndex.tsx +17 -14
  87. package/react-devtools/src/TransactionIndex.tsx +7 -7
  88. package/react-devtools/src/Updates.tsx +41 -32
  89. package/realtime-client/dist/index.cjs +3 -3
  90. package/realtime-client/dist/index.js +3 -3
  91. package/realtime-client/src/pull-mutable-atom-family-member.ts +1 -1
  92. package/realtime-client/src/pull-mutable-atom.ts +1 -1
  93. package/realtime-client/src/sync-continuity.ts +1 -2
  94. package/realtime-react/dist/index.cjs +1 -1
  95. package/realtime-react/dist/index.js +1 -1
  96. package/realtime-server/dist/index.cjs +39 -27
  97. package/realtime-server/dist/index.d.ts +1 -1
  98. package/realtime-server/dist/index.js +27 -16
  99. package/realtime-server/src/realtime-continuity-synchronizer.ts +5 -3
  100. package/realtime-server/src/realtime-mutable-family-provider.ts +2 -1
  101. package/realtime-server/src/realtime-mutable-provider.ts +1 -1
  102. package/realtime-server/src/realtime-server-stores/server-sync-store.ts +21 -11
  103. package/realtime-testing/dist/index.cjs +7 -2
  104. package/realtime-testing/dist/index.js +8 -5
  105. package/realtime-testing/src/setup-realtime-test.tsx +5 -2
  106. package/src/atom.ts +19 -7
  107. package/src/dispose-state.ts +10 -0
  108. package/src/index.ts +5 -2
  109. package/src/selector.ts +13 -7
  110. package/src/silo.ts +3 -3
  111. package/src/subscribe.ts +8 -4
  112. package/src/timeline.ts +18 -1
  113. package/src/transaction.ts +59 -4
  114. package/dist/chunk-BF4MVQF6.js +0 -44
  115. package/internal/src/store/withdraw-new-family-member.ts +0 -69
  116. /package/{src → ephemeral/src}/find-state.ts +0 -0
package/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
- import * as Internal from 'atom.io/internal';
2
- import { Transceiver, Subject, Store, EnvironmentData, Timeline, TimelineAtomUpdate, TimelineSelectorUpdate, TimelineTransactionUpdate } from 'atom.io/internal';
1
+ import { Transceiver, Subject, Store, EnvironmentData, Timeline, TimelineAtomUpdate, TimelineMoleculeCreation, TimelineMoleculeDisposal, TimelineSelectorUpdate, TimelineStateCreation, TimelineStateDisposal, TimelineTransactionUpdate } from 'atom.io/internal';
3
2
  import { Json, JsonInterface } from 'atom.io/json';
4
- import { MutableAtomFamilyToken as MutableAtomFamilyToken$1, MutableAtomToken as MutableAtomToken$1, RegularAtomFamilyToken as RegularAtomFamilyToken$1, RegularAtomToken as RegularAtomToken$1, WritableSelectorFamilyToken as WritableSelectorFamilyToken$1, WritableSelectorToken as WritableSelectorToken$1, ReadonlySelectorFamilyToken as ReadonlySelectorFamilyToken$1, ReadonlySelectorToken as ReadonlySelectorToken$1, WritableFamilyToken as WritableFamilyToken$1, WritableToken as WritableToken$1, ReadableFamilyToken as ReadableFamilyToken$1, ReadableToken as ReadableToken$1 } from 'atom.io';
3
+ import { findState } from 'atom.io/ephemeral';
4
+ import { MoleculeToken, MoleculeFamilyToken, seekState, makeMolecule } from 'atom.io/immortal';
5
+ import { 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';
5
6
 
6
7
  type Effectors<T> = {
7
8
  setSelf: <V extends T>(next: V | ((oldValue: T) => V)) => void;
@@ -33,10 +34,13 @@ type RegularAtomFamilyToken<T, K extends Json.Serializable> = {
33
34
  __T?: T;
34
35
  __K?: K;
35
36
  };
36
- type RegularAtomFamilyTokenWithCall<T, K extends Json.Serializable> = RegularAtomFamilyToken<T, K> & /** @deprecated Prefer the `findState`, `findInStore`, or `find` functions. */ ((key: K) => RegularAtomToken<T>);
37
+ type RegularAtomFamilyTokenWithCall<T, K extends Json.Serializable> = RegularAtomFamilyToken<T, K> & {
38
+ /** @deprecated In ephemeral stores, prefer the `findState`, `findInStore`, or `find` functions. In immortal stores, prefer the `seekState`, `seekInStore`, or `seek` functions. */
39
+ (key: K): RegularAtomToken<T>;
40
+ };
37
41
  type RegularAtomFamily<T, K extends Json.Serializable> = RegularAtomFamilyToken<T, K> & {
38
42
  (key: K): RegularAtomToken<T>;
39
- subject: Subject<RegularAtomToken<T>>;
43
+ subject: Subject<StateCreation<AtomToken<T>> | StateDisposal<AtomToken<T>>>;
40
44
  install: (store: Store) => void;
41
45
  };
42
46
  type MutableAtomFamilyOptions<T extends Transceiver<any>, J extends Json.Serializable, K extends Json.Serializable> = JsonInterface<T, J> & {
@@ -52,10 +56,13 @@ type MutableAtomFamilyToken<T extends Transceiver<any>, J extends Json.Serializa
52
56
  __J?: J;
53
57
  __K?: K;
54
58
  };
55
- type MutableAtomFamilyTokenWithCall<T extends Transceiver<any>, J extends Json.Serializable, K extends Json.Serializable> = MutableAtomFamilyToken<T, J, K> & /** @deprecated Prefer the `findState`, `findInStore`, or `find` functions. */ ((key: K) => MutableAtomToken<T, J>);
59
+ type MutableAtomFamilyTokenWithCall<T extends Transceiver<any>, J extends Json.Serializable, K extends Json.Serializable> = MutableAtomFamilyToken<T, J, K> & {
60
+ /** @deprecated In ephemeral stores, prefer the `findState`, `findInStore`, or `find` functions. In immortal stores, prefer the `seekState`, `seekInStore`, or `seek` functions. */
61
+ (key: K): MutableAtomToken<T, J>;
62
+ };
56
63
  type MutableAtomFamily<T extends Transceiver<any>, J extends Json.Serializable, K extends Json.Serializable> = JsonInterface<T, J> & MutableAtomFamilyToken<T, J, K> & {
57
64
  (key: K): MutableAtomToken<T, J>;
58
- subject: Subject<MutableAtomToken<T, J>>;
65
+ subject: Subject<StateCreation<MutableAtomToken<T, J>> | StateDisposal<MutableAtomToken<T, J>>>;
59
66
  install: (store: Store) => void;
60
67
  };
61
68
  type AtomFamily<T, K extends Json.Serializable = Json.Serializable> = MutableAtomFamily<T extends Transceiver<any> ? T : never, any, K> | RegularAtomFamily<T, K>;
@@ -68,8 +75,32 @@ type TransactionToken<F extends Func> = {
68
75
  type: `transaction`;
69
76
  __F?: F;
70
77
  };
71
- type TransactionUpdateContent = KeyedStateUpdate<unknown> | TransactionUpdate<Func>;
78
+ type StateCreation<Token extends ReadableToken<any>> = {
79
+ type: `state_creation`;
80
+ token: Token;
81
+ };
82
+ type StateDisposal<Token extends ReadableToken<any>> = {
83
+ type: `state_disposal`;
84
+ token: Token;
85
+ value?: TokenType<Token>;
86
+ };
87
+ type MoleculeCreation<Key extends Json.Serializable> = {
88
+ type: `molecule_creation`;
89
+ token: MoleculeToken<Key, any, any>;
90
+ family: MoleculeFamilyToken<Key, any, any>;
91
+ context: MoleculeToken<any, any, any>[];
92
+ params: any[];
93
+ };
94
+ type MoleculeDisposal<Key extends Json.Serializable> = {
95
+ type: `molecule_disposal`;
96
+ token: MoleculeToken<Key, any, any>;
97
+ family: MoleculeFamilyToken<any, any, any>;
98
+ context: MoleculeToken<any, any, any>[];
99
+ familyKeys: string[];
100
+ };
101
+ type TransactionUpdateContent = KeyedStateUpdate<unknown> | MoleculeCreation<any> | MoleculeDisposal<any> | StateCreation<ReadableToken<unknown>> | StateDisposal<ReadableToken<unknown>> | TransactionUpdate<Func>;
72
102
  type TransactionUpdate<F extends Func> = {
103
+ type: `transaction_update`;
73
104
  key: string;
74
105
  id: string;
75
106
  epoch: number;
@@ -78,18 +109,24 @@ type TransactionUpdate<F extends Func> = {
78
109
  output: ReturnType<F>;
79
110
  };
80
111
  type Transactors = Readonly<{
81
- get: <S>(state: ReadonlySelectorToken<S> | WritableToken<S>) => S;
112
+ get: <S>(state: ReadableToken<S>) => S;
82
113
  set: <S, New extends S>(state: WritableToken<S>, newValue: New | ((oldValue: S) => New)) => void;
83
114
  find: typeof findState;
115
+ seek: typeof seekState;
116
+ json: <T extends Transceiver<any>, J extends Json.Serializable>(state: MutableAtomToken<T, J>) => WritableSelectorToken<J>;
84
117
  }>;
85
118
  type TransactorsWithRunAndEnv = Readonly<{
86
119
  get: <S>(state: ReadonlySelectorToken<S> | WritableToken<S>) => S;
87
120
  set: <S, New extends S>(state: WritableToken<S>, newValue: New | ((oldValue: S) => New)) => void;
88
121
  find: typeof findState;
122
+ seek: typeof seekState;
123
+ json: <T extends Transceiver<any>, J extends Json.Serializable>(state: MutableAtomToken<T, J>) => WritableSelectorToken<J>;
124
+ make: typeof makeMolecule;
125
+ dispose: typeof disposeState;
89
126
  run: typeof runTransaction;
90
127
  env: () => EnvironmentData;
91
128
  }>;
92
- type ReadonlyTransactors = Pick<Transactors, `find` | `get`>;
129
+ type ReadonlyTransactors = Pick<Transactors, `find` | `get` | `json` | `seek`>;
93
130
  type Read<F extends Func> = (transactors: ReadonlyTransactors, ...parameters: Parameters<F>) => ReturnType<F>;
94
131
  type Write<F extends Func> = (transactors: Transactors, ...parameters: Parameters<F>) => ReturnType<F>;
95
132
  type Transact<F extends Func> = (transactors: TransactorsWithRunAndEnv, ...parameters: Parameters<F>) => ReturnType<F>;
@@ -127,10 +164,13 @@ type WritableSelectorFamilyToken<T, K extends Json.Serializable> = {
127
164
  __T?: T;
128
165
  __K?: K;
129
166
  };
130
- type WritableSelectorFamilyTokenWithCall<T, K extends Json.Serializable> = WritableSelectorFamilyToken<T, K> & /** @deprecated Prefer the `findState`, `findInStore`, or `find` functions. */ ((key: K) => WritableSelectorToken<T>);
167
+ type WritableSelectorFamilyTokenWithCall<T, K extends Json.Serializable> = WritableSelectorFamilyToken<T, K> & {
168
+ /** @deprecated In ephemeral stores, prefer the `findState`, `findInStore`, or `find` functions. In immortal stores, prefer the `seekState`, `seekInStore`, or `seek` functions. */
169
+ (key: K): WritableSelectorToken<T>;
170
+ };
131
171
  type WritableSelectorFamily<T, K extends Json.Serializable> = WritableSelectorFamilyToken<T, K> & {
132
172
  (key: K): WritableSelectorToken<T>;
133
- subject: Subject<WritableSelectorToken<T>>;
173
+ subject: Subject<StateCreation<WritableSelectorToken<T>> | StateDisposal<WritableSelectorToken<T>>>;
134
174
  install: (store: Store) => void;
135
175
  };
136
176
  type ReadonlySelectorFamilyToken<T, K extends Json.Serializable> = {
@@ -139,11 +179,14 @@ type ReadonlySelectorFamilyToken<T, K extends Json.Serializable> = {
139
179
  __T?: T;
140
180
  __K?: K;
141
181
  };
142
- type ReadonlySelectorFamilyTokenWithCall<T, K extends Json.Serializable> = ReadonlySelectorFamilyToken<T, K> & /** @deprecated Prefer the `findState`, `findInStore`, or `find` functions. */ ((key: K) => ReadonlySelectorToken<T>);
182
+ type ReadonlySelectorFamilyTokenWithCall<T, K extends Json.Serializable> = ReadonlySelectorFamilyToken<T, K> & {
183
+ /** @deprecated In ephemeral stores, prefer the `findState`, `findInStore`, or `find` functions. In immortal stores, prefer the `seekState`, `seekInStore`, or `seek` functions. */
184
+ (key: K): ReadonlySelectorToken<T>;
185
+ };
143
186
  type ReadonlySelectorFamily<T, K extends Json.Serializable> = ((key: K) => ReadonlySelectorToken<T>) & {
144
187
  key: string;
145
188
  type: `readonly_selector_family`;
146
- subject: Subject<ReadonlySelectorToken<T>>;
189
+ subject: Subject<StateCreation<ReadonlySelectorToken<T>> | StateDisposal<ReadonlySelectorToken<T>>>;
147
190
  install: (store: Store) => void;
148
191
  __T?: T;
149
192
  __K?: K;
@@ -153,14 +196,7 @@ type SelectorFamilyToken<T, K extends Json.Serializable> = ReadonlySelectorFamil
153
196
  declare function selectorFamily<T, K extends Json.Serializable>(options: WritableSelectorFamilyOptions<T, K>): WritableSelectorFamilyTokenWithCall<T, K>;
154
197
  declare function selectorFamily<T, K extends Json.Serializable>(options: ReadonlySelectorFamilyOptions<T, K>): ReadonlySelectorFamilyTokenWithCall<T, K>;
155
198
 
156
- declare function disposeState(token: ReadableToken<any>, store?: Internal.Store): void;
157
-
158
- declare function findState<T extends Transceiver<any>, J extends Json.Serializable, K extends Json.Serializable, Key extends K>(token: MutableAtomFamilyToken$1<T, J, K>, key: Key): MutableAtomToken$1<T, J>;
159
- declare function findState<T, K extends Json.Serializable, Key extends K>(token: RegularAtomFamilyToken$1<T, K>, key: Key): RegularAtomToken$1<T>;
160
- declare function findState<T, K extends Json.Serializable, Key extends K>(token: WritableSelectorFamilyToken$1<T, K>, key: Key): WritableSelectorToken$1<T>;
161
- declare function findState<T, K extends Json.Serializable, Key extends K>(token: ReadonlySelectorFamilyToken$1<T, K>, key: Key): ReadonlySelectorToken$1<T>;
162
- declare function findState<T, K extends Json.Serializable, Key extends K>(token: WritableFamilyToken$1<T, K>, key: Key): WritableToken$1<T>;
163
- declare function findState<T, K extends Json.Serializable, Key extends K>(token: ReadableFamilyToken$1<T, K>, key: Key): ReadableToken$1<T>;
199
+ declare function disposeState(token: MoleculeToken<any, any, any> | ReadableToken<any>): void;
164
200
 
165
201
  declare function getState<T>(token: ReadableToken<T>): T;
166
202
 
@@ -250,17 +286,18 @@ declare class Silo {
250
286
  subscribe: typeof subscribe;
251
287
  undo: typeof undo;
252
288
  redo: typeof redo;
253
- constructor(name: string, fromStore?: Store | null);
289
+ constructor(config: Store[`config`], fromStore?: Store | null);
254
290
  }
255
291
 
256
292
  type StateUpdate<T> = {
257
293
  newValue: T;
258
294
  oldValue: T;
259
295
  };
260
- type KeyedStateUpdate<T> = StateUpdate<T> & {
296
+ type KeyedStateUpdate<T> = Flat<StateUpdate<T> & {
261
297
  key: string;
298
+ type: `atom_update` | `selector_update`;
262
299
  family?: FamilyMetadata;
263
- };
300
+ }>;
264
301
  type UpdateHandler<T> = (update: StateUpdate<T>) => void;
265
302
  type TransactionUpdateHandler<F extends Func> = (data: TransactionUpdate<F>) => void;
266
303
  declare function subscribe<T>(token: ReadableToken<T>, handleUpdate: UpdateHandler<T>, key?: string, store?: Store): () => void;
@@ -268,6 +305,7 @@ declare function subscribe<F extends Func>(token: TransactionToken<F>, handleUpd
268
305
  declare function subscribe<M extends TimelineManageable>(token: TimelineToken<M>, handleUpdate: (update: TimelineUpdate<M> | `redo` | `undo`) => void, key?: string, store?: Store): () => void;
269
306
 
270
307
  type TimelineManageable = AtomFamilyToken<any, any> | AtomToken<any>;
308
+ type AtomOnly<M extends TimelineManageable> = M extends AtomFamilyToken<any, any> ? AtomToken<any> : M extends AtomToken<any> ? M : never;
271
309
  type TimelineToken<M> = {
272
310
  key: string;
273
311
  type: `timeline`;
@@ -275,10 +313,10 @@ type TimelineToken<M> = {
275
313
  };
276
314
  type TimelineOptions<ManagedAtom extends TimelineManageable> = {
277
315
  key: string;
278
- atoms: ManagedAtom[];
316
+ scope: (ManagedAtom | MoleculeFamilyToken<any, any, any>)[];
279
317
  shouldCapture?: (update: TimelineUpdate<ManagedAtom>, timeline: Timeline<TimelineManageable>) => boolean;
280
318
  };
281
- type TimelineUpdate<ManagedAtom extends TimelineManageable> = TimelineAtomUpdate<ManagedAtom> | TimelineSelectorUpdate<ManagedAtom> | TimelineTransactionUpdate;
319
+ type TimelineUpdate<ManagedAtom extends TimelineManageable> = TimelineAtomUpdate<ManagedAtom> | TimelineMoleculeCreation<any> | TimelineMoleculeDisposal<any> | TimelineSelectorUpdate<ManagedAtom> | TimelineStateCreation<AtomOnly<ManagedAtom>> | TimelineStateDisposal<AtomOnly<ManagedAtom>> | TimelineTransactionUpdate;
282
320
  declare const timeline: <ManagedAtom extends TimelineManageable>(options: TimelineOptions<ManagedAtom>) => TimelineToken<ManagedAtom>;
283
321
  declare const redo: (tl: TimelineToken<any>) => void;
284
322
  declare const undo: (tl: TimelineToken<any>) => void;
@@ -298,6 +336,11 @@ declare function belongsTo<Family extends WritableFamilyToken$1<any, any>>(famil
298
336
  declare function belongsTo<Family extends ReadableFamilyToken$1<any, any>>(family: Family, unknownToken: ReadableToken$1<any>): unknownToken is ReadableToken$1<TokenType<Family>>;
299
337
 
300
338
  type Func = (...parameters: any[]) => any;
339
+ type Flat<R extends {
340
+ [K in PropertyKey]: any;
341
+ }> = {
342
+ [K in keyof R]: R[K];
343
+ };
301
344
  type RegularAtomToken<T> = {
302
345
  key: string;
303
346
  type: `atom`;
@@ -336,4 +379,4 @@ type FamilyMetadata = {
336
379
  subKey: string;
337
380
  };
338
381
 
339
- export { type AtomEffect, type AtomFamily, type AtomFamilyToken, AtomIOLogger, type AtomToken, type Effectors, type FamilyMetadata, type Func, type KeyedStateUpdate, LOG_LEVELS, type LogFilter, type LogFn, type LogLevel, type Logger, type LoggerIcon, type MutableAtomFamily, type MutableAtomFamilyOptions, type MutableAtomFamilyToken, type MutableAtomFamilyTokenWithCall, type MutableAtomOptions, type MutableAtomToken, type Read, type ReadableFamily, type ReadableFamilyToken, type ReadableToken, type ReadonlySelectorFamily, type ReadonlySelectorFamilyOptions, type ReadonlySelectorFamilyToken, type ReadonlySelectorFamilyTokenWithCall, type ReadonlySelectorOptions, type ReadonlySelectorToken, type ReadonlyTransactors, type RegularAtomFamily, type RegularAtomFamilyOptions, type RegularAtomFamilyToken, type RegularAtomFamilyTokenWithCall, type RegularAtomOptions, type RegularAtomToken, type SelectorFamily, type SelectorFamilyToken, type SelectorToken, Silo, type StateUpdate, 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 Transactors, type TransactorsWithRunAndEnv, type UpdateHandler, type WritableFamily, type WritableFamilyToken, type WritableSelectorFamily, type WritableSelectorFamilyOptions, type WritableSelectorFamilyToken, type WritableSelectorFamilyTokenWithCall, type WritableSelectorOptions, type WritableSelectorToken, type WritableToken, type Write, atom, atomFamily, belongsTo, disposeState, findState, getState, isToken, redo, runTransaction, selector, selectorFamily, setState, simpleLog, simpleLogger, subscribe, timeline, transaction, undo };
382
+ export { type AtomEffect, type AtomFamily, type AtomFamilyToken, AtomIOLogger, type AtomOnly, type AtomToken, type Effectors, type FamilyMetadata, type Flat, type Func, type KeyedStateUpdate, LOG_LEVELS, type LogFilter, type LogFn, type LogLevel, type Logger, type LoggerIcon, type MoleculeCreation, type MoleculeDisposal, type MutableAtomFamily, type MutableAtomFamilyOptions, type MutableAtomFamilyToken, type MutableAtomFamilyTokenWithCall, type MutableAtomOptions, type MutableAtomToken, type Read, type ReadableFamily, type ReadableFamilyToken, type ReadableToken, type ReadonlySelectorFamily, type ReadonlySelectorFamilyOptions, type ReadonlySelectorFamilyToken, type ReadonlySelectorFamilyTokenWithCall, type ReadonlySelectorOptions, type ReadonlySelectorToken, type ReadonlyTransactors, type RegularAtomFamily, type RegularAtomFamilyOptions, type RegularAtomFamilyToken, type RegularAtomFamilyTokenWithCall, type RegularAtomOptions, type RegularAtomToken, type SelectorFamily, type SelectorFamilyToken, type SelectorToken, Silo, type StateCreation, type StateDisposal, type StateUpdate, 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 Transactors, type TransactorsWithRunAndEnv, type UpdateHandler, type WritableFamily, type WritableFamilyToken, type WritableSelectorFamily, type WritableSelectorFamilyOptions, type WritableSelectorFamilyToken, type WritableSelectorFamilyTokenWithCall, 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
1
  export { getState } from './chunk-PNIHPILQ.js';
2
2
  import './chunk-F2X4B4VY.js';
3
3
  import * as Internal from 'atom.io/internal';
4
- import { createStandaloneAtom, IMPLICIT, createAtomFamily, findInStore, createStandaloneSelector, createSelectorFamily, Store, createTransaction, createTimeline, getFromStore, setIntoStore, timeTravel, subscribeToTimeline, subscribeToTransaction, subscribeToState, arbitrary, actUponStore } from 'atom.io/internal';
4
+ import { createStandaloneAtom, IMPLICIT, createAtomFamily, createStandaloneSelector, createSelectorFamily, Store, createTransaction, createTimeline, findInStore, getFromStore, setIntoStore, timeTravel, subscribeToTimeline, subscribeToTransaction, subscribeToState, arbitrary, actUponStore } from 'atom.io/internal';
5
5
 
6
6
  function atom(options) {
7
7
  return createStandaloneAtom(options, IMPLICIT.STORE);
@@ -9,21 +9,8 @@ function atom(options) {
9
9
  function atomFamily(options) {
10
10
  return createAtomFamily(options, IMPLICIT.STORE);
11
11
  }
12
- function disposeState(token, store = Internal.IMPLICIT.STORE) {
13
- switch (token.type) {
14
- case `atom`:
15
- case `mutable_atom`:
16
- Internal.disposeAtom(token, store);
17
- break;
18
- case `selector`:
19
- case `readonly_selector`:
20
- Internal.disposeSelector(token, store);
21
- break;
22
- }
23
- }
24
- function findState(token, key) {
25
- const state = findInStore(token, key, IMPLICIT.STORE);
26
- return state;
12
+ function disposeState(token) {
13
+ Internal.disposeFromStore(token, Internal.IMPLICIT.STORE);
27
14
  }
28
15
 
29
16
  // src/logger.ts
@@ -74,8 +61,8 @@ function setState(token, value) {
74
61
  Internal.setIntoStore(token, value, Internal.IMPLICIT.STORE);
75
62
  }
76
63
  var Silo = class {
77
- constructor(name, fromStore = null) {
78
- const s = new Store(name, fromStore);
64
+ constructor(config, fromStore = null) {
65
+ const s = new Store(config, fromStore);
79
66
  function _atom(options) {
80
67
  return createStandaloneAtom(options, s);
81
68
  }
@@ -141,4 +128,4 @@ function belongsTo(family, unknownToken) {
141
128
  return family.key === ((_a = unknownToken.family) == null ? void 0 : _a.key);
142
129
  }
143
130
 
144
- export { AtomIOLogger, LOG_LEVELS, Silo, atom, atomFamily, belongsTo, disposeState, findState, isToken, redo, runTransaction, selector, selectorFamily, setState, simpleLog, simpleLogger, subscribe, timeline, transaction, undo };
131
+ export { AtomIOLogger, LOG_LEVELS, Silo, atom, atomFamily, belongsTo, disposeState, isToken, redo, runTransaction, selector, selectorFamily, setState, simpleLog, simpleLogger, subscribe, timeline, transaction, undo };
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ var internal = require('atom.io/internal');
4
+
5
+ // ephemeral/src/find-state.ts
6
+ function findState(token, key) {
7
+ const state = internal.findInStore(token, key, internal.IMPLICIT.STORE);
8
+ return state;
9
+ }
10
+
11
+ exports.findState = findState;
@@ -0,0 +1,9 @@
1
+ import '../../dist/chunk-F2X4B4VY.js';
2
+ import { findInStore, IMPLICIT } from 'atom.io/internal';
3
+
4
+ function findState(token, key) {
5
+ const state = findInStore(token, key, IMPLICIT.STORE);
6
+ return state;
7
+ }
8
+
9
+ export { findState };
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "atom.io-ephemeral",
3
+ "type": "module",
4
+ "private": true,
5
+ "main": "dist/index.cjs",
6
+ "module": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "browser": "./dist/index.js",
12
+ "require": "./dist/index.cjs",
13
+ "types": "./dist/index.d.ts"
14
+ }
15
+ }
16
+ }
@@ -0,0 +1 @@
1
+ export * from "./find-state"
@@ -14,6 +14,7 @@ var __export = (target, all) => {
14
14
  var rules_exports = {};
15
15
  __export(rules_exports, {
16
16
  explicitStateTypes: () => explicitStateTypes,
17
+ lifespan: () => lifespan,
17
18
  synchronousSelectorDependencies: () => synchronousSelectorDependencies
18
19
  });
19
20
  var createRule = utils.ESLintUtils.RuleCreator(
@@ -66,7 +67,7 @@ var explicitStateTypes = createRule({
66
67
  }
67
68
  });
68
69
 
69
- // eslint-plugin/src/rules/synchronous-selector-dependencies.ts
70
+ // eslint-plugin/src/walk.ts
70
71
  function walk(node, callback, depth = 0) {
71
72
  callback(node, depth);
72
73
  switch (node.type) {
@@ -125,8 +126,161 @@ function walk(node, callback, depth = 0) {
125
126
  walk(node.object, callback, depth);
126
127
  walk(node.property, callback, depth);
127
128
  break;
129
+ case `CallExpression`:
130
+ walk(node.callee, callback, depth);
131
+ for (const argument of node.arguments) {
132
+ walk(argument, callback, depth);
133
+ }
134
+ break;
128
135
  }
129
136
  }
137
+
138
+ // eslint-plugin/src/rules/lifespan.ts
139
+ var lifespan = {
140
+ meta: {
141
+ type: `problem`,
142
+ docs: {
143
+ description: `atom.io provides tools for short-lived (ephemeral) and long-lived (immortal) stores. This rule allows you to guard against unsafe usage of tools for the other type of store.`,
144
+ category: `Possible Errors`,
145
+ recommended: false,
146
+ url: ``
147
+ // URL to documentation page for this rule
148
+ },
149
+ schema: [
150
+ {
151
+ type: `string`,
152
+ enum: [`ephemeral`, `immortal`],
153
+ default: `ephemeral`
154
+ }
155
+ ]
156
+ },
157
+ create(context) {
158
+ var _a;
159
+ const storeLifespan = (_a = context.options[0]) != null ? _a : `ephemeral`;
160
+ return {
161
+ ImportDeclaration(node) {
162
+ const importSource = node.source.value;
163
+ if (!importSource.startsWith(`atom.io/`)) {
164
+ return;
165
+ }
166
+ const [_, subPackageName] = importSource.split(`/`);
167
+ if (storeLifespan === `immortal` && subPackageName === `ephemeral`) {
168
+ context.report({
169
+ node,
170
+ message: `do not import from "${importSource}" in an ${storeLifespan} store`
171
+ });
172
+ }
173
+ },
174
+ CallExpression(node) {
175
+ if (storeLifespan === `ephemeral`) {
176
+ return;
177
+ }
178
+ const functionCallee = node.callee.type === `Identifier` ? node.callee : void 0;
179
+ const methodCallee = node.callee.type === `MemberExpression` && node.callee.property.type === `Identifier` ? node.callee.property : void 0;
180
+ const callee = functionCallee != null ? functionCallee : methodCallee;
181
+ if (callee === void 0) {
182
+ return;
183
+ }
184
+ if (callee.name === `findState`) {
185
+ context.report({
186
+ node,
187
+ message: `do not use findState in an ${storeLifespan} store`
188
+ });
189
+ }
190
+ const storeProcedures = [];
191
+ if (callee.name === `selector` || callee.name === `selectorFamily` || callee.name === `transaction`) {
192
+ if (node.arguments[0].type === `ObjectExpression`) {
193
+ const argProperties = node.arguments[0].properties;
194
+ switch (callee.name) {
195
+ case `selector`:
196
+ case `selectorFamily`:
197
+ {
198
+ const getAndSetProps = argProperties.filter(
199
+ (prop) => {
200
+ return `key` in prop && `name` in prop.key && (prop.key.name === `get` || prop.key.name === `set`);
201
+ }
202
+ );
203
+ switch (callee.name) {
204
+ case `selector`:
205
+ {
206
+ for (const prop of getAndSetProps) {
207
+ if (prop.value.type === `FunctionExpression` || prop.value.type === `ArrowFunctionExpression`) {
208
+ storeProcedures.push(prop.value);
209
+ }
210
+ }
211
+ }
212
+ break;
213
+ case `selectorFamily`:
214
+ {
215
+ for (const prop of getAndSetProps) {
216
+ const { value } = prop;
217
+ if (value.type === `FunctionExpression` || value.type === `ArrowFunctionExpression`) {
218
+ if (value.body.type === `BlockStatement`) {
219
+ for (const statement of value.body.body) {
220
+ if (statement.type === `ReturnStatement` && statement.argument && (statement.argument.type === `FunctionExpression` || statement.argument.type === `ArrowFunctionExpression`)) {
221
+ storeProcedures.push(statement.argument);
222
+ }
223
+ }
224
+ } else if (value.body.type === `FunctionExpression` || value.body.type === `ArrowFunctionExpression`) {
225
+ storeProcedures.push(value.body);
226
+ }
227
+ }
228
+ }
229
+ }
230
+ break;
231
+ }
232
+ }
233
+ break;
234
+ case `transaction`:
235
+ {
236
+ const doProp = argProperties.find(
237
+ (prop) => {
238
+ return `key` in prop && `name` in prop.key && prop.key.name === `do`;
239
+ }
240
+ );
241
+ if (doProp) {
242
+ if (doProp.value.type === `FunctionExpression` || doProp.value.type === `ArrowFunctionExpression`) {
243
+ storeProcedures.push(doProp.value);
244
+ }
245
+ }
246
+ }
247
+ break;
248
+ }
249
+ }
250
+ }
251
+ for (const storeProcedure of storeProcedures) {
252
+ const transactorsParam = storeProcedure.params[0];
253
+ const nonDestructuredTransactorsName = transactorsParam && `name` in transactorsParam ? transactorsParam.name : void 0;
254
+ walk(storeProcedure.body, (n) => {
255
+ if (n.type === `CallExpression`) {
256
+ let willReport = false;
257
+ switch (n.callee.type) {
258
+ case `MemberExpression`:
259
+ if (n.callee.object.type === `Identifier` && n.callee.object.name === nonDestructuredTransactorsName && n.callee.property.type === `Identifier` && n.callee.property.name === `find`) {
260
+ willReport = true;
261
+ }
262
+ break;
263
+ case `Identifier`:
264
+ if (n.callee.name === `find`) {
265
+ willReport = true;
266
+ }
267
+ break;
268
+ }
269
+ if (willReport) {
270
+ context.report({
271
+ node: n,
272
+ message: `Using find in a transactor is not allowed in an immortal store.`
273
+ });
274
+ }
275
+ }
276
+ });
277
+ }
278
+ }
279
+ };
280
+ }
281
+ };
282
+
283
+ // eslint-plugin/src/rules/synchronous-selector-dependencies.ts
130
284
  var synchronousSelectorDependencies = {
131
285
  meta: {
132
286
  type: `problem`,
@@ -5,6 +5,7 @@ import { ESLintUtils } from '@typescript-eslint/utils';
5
5
  var rules_exports = {};
6
6
  __export(rules_exports, {
7
7
  explicitStateTypes: () => explicitStateTypes,
8
+ lifespan: () => lifespan,
8
9
  synchronousSelectorDependencies: () => synchronousSelectorDependencies
9
10
  });
10
11
  var createRule = ESLintUtils.RuleCreator(
@@ -57,7 +58,7 @@ var explicitStateTypes = createRule({
57
58
  }
58
59
  });
59
60
 
60
- // eslint-plugin/src/rules/synchronous-selector-dependencies.ts
61
+ // eslint-plugin/src/walk.ts
61
62
  function walk(node, callback, depth = 0) {
62
63
  callback(node, depth);
63
64
  switch (node.type) {
@@ -116,8 +117,161 @@ function walk(node, callback, depth = 0) {
116
117
  walk(node.object, callback, depth);
117
118
  walk(node.property, callback, depth);
118
119
  break;
120
+ case `CallExpression`:
121
+ walk(node.callee, callback, depth);
122
+ for (const argument of node.arguments) {
123
+ walk(argument, callback, depth);
124
+ }
125
+ break;
119
126
  }
120
127
  }
128
+
129
+ // eslint-plugin/src/rules/lifespan.ts
130
+ var lifespan = {
131
+ meta: {
132
+ type: `problem`,
133
+ docs: {
134
+ description: `atom.io provides tools for short-lived (ephemeral) and long-lived (immortal) stores. This rule allows you to guard against unsafe usage of tools for the other type of store.`,
135
+ category: `Possible Errors`,
136
+ recommended: false,
137
+ url: ``
138
+ // URL to documentation page for this rule
139
+ },
140
+ schema: [
141
+ {
142
+ type: `string`,
143
+ enum: [`ephemeral`, `immortal`],
144
+ default: `ephemeral`
145
+ }
146
+ ]
147
+ },
148
+ create(context) {
149
+ var _a;
150
+ const storeLifespan = (_a = context.options[0]) != null ? _a : `ephemeral`;
151
+ return {
152
+ ImportDeclaration(node) {
153
+ const importSource = node.source.value;
154
+ if (!importSource.startsWith(`atom.io/`)) {
155
+ return;
156
+ }
157
+ const [_, subPackageName] = importSource.split(`/`);
158
+ if (storeLifespan === `immortal` && subPackageName === `ephemeral`) {
159
+ context.report({
160
+ node,
161
+ message: `do not import from "${importSource}" in an ${storeLifespan} store`
162
+ });
163
+ }
164
+ },
165
+ CallExpression(node) {
166
+ if (storeLifespan === `ephemeral`) {
167
+ return;
168
+ }
169
+ const functionCallee = node.callee.type === `Identifier` ? node.callee : void 0;
170
+ const methodCallee = node.callee.type === `MemberExpression` && node.callee.property.type === `Identifier` ? node.callee.property : void 0;
171
+ const callee = functionCallee != null ? functionCallee : methodCallee;
172
+ if (callee === void 0) {
173
+ return;
174
+ }
175
+ if (callee.name === `findState`) {
176
+ context.report({
177
+ node,
178
+ message: `do not use findState in an ${storeLifespan} store`
179
+ });
180
+ }
181
+ const storeProcedures = [];
182
+ if (callee.name === `selector` || callee.name === `selectorFamily` || callee.name === `transaction`) {
183
+ if (node.arguments[0].type === `ObjectExpression`) {
184
+ const argProperties = node.arguments[0].properties;
185
+ switch (callee.name) {
186
+ case `selector`:
187
+ case `selectorFamily`:
188
+ {
189
+ const getAndSetProps = argProperties.filter(
190
+ (prop) => {
191
+ return `key` in prop && `name` in prop.key && (prop.key.name === `get` || prop.key.name === `set`);
192
+ }
193
+ );
194
+ switch (callee.name) {
195
+ case `selector`:
196
+ {
197
+ for (const prop of getAndSetProps) {
198
+ if (prop.value.type === `FunctionExpression` || prop.value.type === `ArrowFunctionExpression`) {
199
+ storeProcedures.push(prop.value);
200
+ }
201
+ }
202
+ }
203
+ break;
204
+ case `selectorFamily`:
205
+ {
206
+ for (const prop of getAndSetProps) {
207
+ const { value } = prop;
208
+ if (value.type === `FunctionExpression` || value.type === `ArrowFunctionExpression`) {
209
+ if (value.body.type === `BlockStatement`) {
210
+ for (const statement of value.body.body) {
211
+ if (statement.type === `ReturnStatement` && statement.argument && (statement.argument.type === `FunctionExpression` || statement.argument.type === `ArrowFunctionExpression`)) {
212
+ storeProcedures.push(statement.argument);
213
+ }
214
+ }
215
+ } else if (value.body.type === `FunctionExpression` || value.body.type === `ArrowFunctionExpression`) {
216
+ storeProcedures.push(value.body);
217
+ }
218
+ }
219
+ }
220
+ }
221
+ break;
222
+ }
223
+ }
224
+ break;
225
+ case `transaction`:
226
+ {
227
+ const doProp = argProperties.find(
228
+ (prop) => {
229
+ return `key` in prop && `name` in prop.key && prop.key.name === `do`;
230
+ }
231
+ );
232
+ if (doProp) {
233
+ if (doProp.value.type === `FunctionExpression` || doProp.value.type === `ArrowFunctionExpression`) {
234
+ storeProcedures.push(doProp.value);
235
+ }
236
+ }
237
+ }
238
+ break;
239
+ }
240
+ }
241
+ }
242
+ for (const storeProcedure of storeProcedures) {
243
+ const transactorsParam = storeProcedure.params[0];
244
+ const nonDestructuredTransactorsName = transactorsParam && `name` in transactorsParam ? transactorsParam.name : void 0;
245
+ walk(storeProcedure.body, (n) => {
246
+ if (n.type === `CallExpression`) {
247
+ let willReport = false;
248
+ switch (n.callee.type) {
249
+ case `MemberExpression`:
250
+ if (n.callee.object.type === `Identifier` && n.callee.object.name === nonDestructuredTransactorsName && n.callee.property.type === `Identifier` && n.callee.property.name === `find`) {
251
+ willReport = true;
252
+ }
253
+ break;
254
+ case `Identifier`:
255
+ if (n.callee.name === `find`) {
256
+ willReport = true;
257
+ }
258
+ break;
259
+ }
260
+ if (willReport) {
261
+ context.report({
262
+ node: n,
263
+ message: `Using find in a transactor is not allowed in an immortal store.`
264
+ });
265
+ }
266
+ }
267
+ });
268
+ }
269
+ }
270
+ };
271
+ }
272
+ };
273
+
274
+ // eslint-plugin/src/rules/synchronous-selector-dependencies.ts
121
275
  var synchronousSelectorDependencies = {
122
276
  meta: {
123
277
  type: `problem`,