atom.io 0.31.1 → 0.32.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 (162) hide show
  1. package/data/dist/index.d.ts +3 -154
  2. package/data/dist/index.js +11 -559
  3. package/data/src/index.ts +0 -2
  4. package/data/src/struct-family.ts +1 -1
  5. package/data/src/struct.ts +1 -2
  6. package/dist/chunk-3PQTWLQQ.js +83 -0
  7. package/dist/chunk-3ZFTRSNG.js +523 -0
  8. package/dist/chunk-4LWKCEW3.js +14 -0
  9. package/dist/chunk-KVI5OBF2.js +153 -0
  10. package/dist/{chunk-Y5MBNTVU.js → chunk-UQEYZ3OI.js} +1814 -721
  11. package/dist/chunk-UYYKOGZQ.js +1034 -0
  12. package/dist/chunk-VRJP2PCU.js +631 -0
  13. package/dist/chunk-X7SD2NXU.js +108 -0
  14. package/dist/index.d.ts +137 -12
  15. package/dist/index.js +1 -228
  16. package/eslint-plugin/dist/index.d.ts +1 -30
  17. package/eslint-plugin/dist/index.js +3 -149
  18. package/eslint-plugin/src/index.ts +0 -1
  19. package/eslint-plugin/src/rules/explicit-state-types.ts +1 -0
  20. package/eslint-plugin/src/rules/index.ts +0 -1
  21. package/eslint-plugin/src/rules/synchronous-selector-dependencies.ts +1 -0
  22. package/eslint-plugin/src/walk.ts +1 -0
  23. package/internal/dist/index.d.ts +129 -58
  24. package/internal/dist/index.js +1 -1
  25. package/internal/src/atom/create-regular-atom.ts +3 -3
  26. package/internal/src/atom/dispose-atom.ts +4 -13
  27. package/internal/src/atom/is-default.ts +3 -3
  28. package/internal/src/caching.ts +5 -5
  29. package/internal/src/capitalize.ts +3 -0
  30. package/internal/src/families/create-readonly-selector-family.ts +5 -6
  31. package/internal/src/families/create-writable-selector-family.ts +1 -4
  32. package/internal/src/families/dispose-from-store.ts +3 -13
  33. package/internal/src/get-state/get-from-store.ts +2 -2
  34. package/internal/src/get-state/read-or-compute-value.ts +1 -1
  35. package/internal/src/index.ts +2 -0
  36. package/internal/src/install-into-store.ts +1 -1
  37. package/internal/src/join/edit-relations-in-store.ts +32 -0
  38. package/internal/src/join/find-relations-in-store.ts +124 -0
  39. package/internal/src/join/get-internal-relations-from-store.ts +14 -0
  40. package/internal/src/join/get-join.ts +31 -0
  41. package/internal/src/join/index.ts +5 -0
  42. package/{data/src/join.ts → internal/src/join/join-internal.ts} +21 -430
  43. package/internal/src/junction.ts +7 -4
  44. package/internal/src/keys.ts +7 -7
  45. package/internal/src/mutable/create-mutable-atom-family.ts +1 -1
  46. package/internal/src/mutable/create-mutable-atom.ts +3 -3
  47. package/internal/src/mutable/get-json-token.ts +1 -1
  48. package/internal/src/mutable/tracker-family.ts +19 -17
  49. package/internal/src/mutable/tracker.ts +8 -8
  50. package/internal/src/pretty-print.ts +1 -1
  51. package/internal/src/selector/create-readonly-selector.ts +3 -7
  52. package/internal/src/selector/create-writable-selector.ts +4 -4
  53. package/internal/src/selector/dispose-selector.ts +20 -11
  54. package/internal/src/selector/get-selector-dependency-keys.ts +1 -1
  55. package/internal/src/selector/register-selector.ts +6 -9
  56. package/internal/src/selector/trace-selector-atoms.ts +2 -2
  57. package/internal/src/set-state/copy-mutable-if-needed.ts +1 -1
  58. package/internal/src/set-state/emit-update.ts +4 -2
  59. package/internal/src/set-state/evict-downstream.ts +1 -1
  60. package/internal/src/set-state/set-atom-or-selector.ts +1 -1
  61. package/internal/src/set-state/set-atom.ts +10 -10
  62. package/internal/src/set-state/set-into-store.ts +2 -2
  63. package/internal/src/set-state/stow-update.ts +1 -1
  64. package/internal/src/store/store.ts +1 -1
  65. package/internal/src/store/withdraw.ts +22 -22
  66. package/internal/src/subscribe/recall-state.ts +1 -1
  67. package/internal/src/subscribe/subscribe-in-store.ts +3 -3
  68. package/internal/src/subscribe/subscribe-to-root-atoms.ts +3 -3
  69. package/internal/src/subscribe/subscribe-to-state.ts +5 -5
  70. package/internal/src/subscribe/subscribe-to-timeline.ts +3 -3
  71. package/internal/src/subscribe/subscribe-to-transaction.ts +3 -3
  72. package/internal/src/timeline/create-timeline.ts +19 -38
  73. package/internal/src/timeline/time-travel.ts +2 -1
  74. package/internal/src/transaction/act-upon-store.ts +2 -2
  75. package/internal/src/transaction/apply-transaction.ts +5 -5
  76. package/internal/src/transaction/assign-transaction-to-continuity.ts +1 -1
  77. package/internal/src/transaction/build-transaction.ts +5 -8
  78. package/internal/src/transaction/create-transaction.ts +3 -3
  79. package/internal/src/transaction/get-epoch-number.ts +3 -3
  80. package/internal/src/transaction/set-epoch-number.ts +2 -2
  81. package/introspection/dist/index.js +2 -620
  82. package/json/dist/index.d.ts +2 -2
  83. package/json/dist/index.js +1 -80
  84. package/json/src/select-json-family.ts +3 -14
  85. package/package.json +31 -49
  86. package/react/dist/index.js +2 -82
  87. package/react/src/use-o.ts +1 -1
  88. package/react/src/use-tl.ts +2 -2
  89. package/react-devtools/dist/index.css +16 -14
  90. package/react-devtools/dist/index.js +31 -18
  91. package/react-devtools/src/Updates.tsx +12 -0
  92. package/react-devtools/src/devtools.scss +16 -14
  93. package/react-devtools/src/json-editor/editors-by-type/utilities/cast-to-json.ts +2 -1
  94. package/realtime/dist/index.d.ts +1 -2
  95. package/realtime/dist/index.js +2 -107
  96. package/realtime/src/realtime-continuity.ts +3 -2
  97. package/realtime/src/shared-room-store.ts +1 -2
  98. package/realtime-client/dist/index.d.ts +9 -9
  99. package/realtime-client/dist/index.js +3 -509
  100. package/realtime-client/src/continuity/register-and-attempt-confirmed-update.ts +3 -3
  101. package/realtime-client/src/continuity/use-conceal-state.ts +1 -1
  102. package/realtime-client/src/pull-atom-family-member.ts +2 -2
  103. package/realtime-client/src/pull-atom.ts +2 -2
  104. package/realtime-client/src/pull-mutable-atom-family-member.ts +2 -2
  105. package/realtime-client/src/pull-mutable-atom.ts +2 -2
  106. package/realtime-client/src/pull-selector-family-member.ts +4 -4
  107. package/realtime-client/src/pull-selector.ts +4 -4
  108. package/realtime-client/src/push-state.ts +5 -10
  109. package/realtime-client/src/server-action.ts +4 -4
  110. package/realtime-client/src/sync-continuity.ts +6 -6
  111. package/realtime-react/dist/index.js +5 -154
  112. package/realtime-react/src/use-pull-atom-family-member.ts +1 -1
  113. package/realtime-react/src/use-pull-atom.ts +1 -1
  114. package/realtime-react/src/use-pull-mutable-atom.ts +1 -1
  115. package/realtime-react/src/use-pull-mutable-family-member.ts +1 -1
  116. package/realtime-react/src/use-pull-selector-family-member.ts +1 -1
  117. package/realtime-react/src/use-pull-selector.ts +1 -1
  118. package/realtime-react/src/use-push.ts +1 -1
  119. package/realtime-react/src/use-server-action.ts +2 -2
  120. package/realtime-react/src/use-sync-continuity.ts +1 -1
  121. package/realtime-server/dist/index.d.ts +2 -4
  122. package/realtime-server/dist/index.js +3 -1001
  123. package/realtime-server/src/continuity/prepare-to-serve-transaction-request.ts +1 -1
  124. package/realtime-server/src/continuity/prepare-to-sync-realtime-continuity.ts +3 -3
  125. package/realtime-server/src/continuity/subscribe-to-continuity-actions.ts +2 -2
  126. package/realtime-server/src/continuity/subscribe-to-continuity-perpectives.ts +2 -2
  127. package/realtime-server/src/ipc-sockets/child-socket.ts +2 -0
  128. package/realtime-server/src/realtime-action-receiver.ts +1 -1
  129. package/realtime-server/src/realtime-family-provider.ts +2 -2
  130. package/realtime-server/src/realtime-mutable-family-provider.ts +2 -2
  131. package/realtime-server/src/realtime-mutable-provider.ts +2 -2
  132. package/realtime-server/src/realtime-server-stores/server-room-external-actions.ts +2 -1
  133. package/realtime-server/src/realtime-server-stores/server-room-external-store.ts +1 -1
  134. package/realtime-server/src/realtime-server-stores/server-sync-store.ts +10 -2
  135. package/realtime-server/src/realtime-server-stores/server-user-store.ts +1 -2
  136. package/realtime-server/src/realtime-state-provider.ts +2 -2
  137. package/realtime-testing/dist/index.js +20 -22
  138. package/realtime-testing/src/setup-realtime-test.tsx +2 -1
  139. package/src/index.ts +4 -0
  140. package/src/join.ts +218 -0
  141. package/src/silo.ts +4 -4
  142. package/src/timeline.ts +1 -1
  143. package/src/transaction.ts +4 -8
  144. package/transceivers/set-rtx/dist/index.d.ts +4 -3
  145. package/transceivers/set-rtx/dist/index.js +1 -215
  146. package/transceivers/set-rtx/src/set-rtx.ts +4 -7
  147. package/web/dist/index.js +1 -15
  148. package/data/src/until.ts +0 -15
  149. package/ephemeral/dist/index.d.ts +0 -67
  150. package/ephemeral/dist/index.js +0 -9
  151. package/ephemeral/package.json +0 -13
  152. package/ephemeral/src/index.ts +0 -1
  153. package/eslint-plugin/src/rules/lifespan.ts +0 -203
  154. package/immortal/dist/index.d.ts +0 -12
  155. package/immortal/dist/index.js +0 -9
  156. package/immortal/package.json +0 -13
  157. package/immortal/src/index.ts +0 -1
  158. package/immortal/src/seek-state.ts +0 -60
  159. package/react-devtools/src/json-editor/assets/Untitled-1.ai +2 -1436
  160. package/react-devtools/src/json-editor/assets/data-vis.ai +1 -1548
  161. package/react-devtools/src/json-editor/comp/json-editor-sketches.ai +5 -1449
  162. /package/{ephemeral/src → src}/find-state.ts +0 -0
@@ -1,7 +1,8 @@
1
1
  import { Transceiver, Lineage, TransceiverMode, Subject } from 'atom.io/internal';
2
2
  import { primitive, Json } from 'atom.io/json';
3
3
 
4
- type SetUpdate = `add:${string}` | `clear:${string}` | `del:${string}` | `tx:${string}`;
4
+ type SetUpdateType = `add` | `clear` | `del` | `tx`;
5
+ type SetUpdate = `${SetUpdateType}:${string}`;
5
6
  type NumberedSetUpdate = `${number}=${SetUpdate}`;
6
7
  interface SetRTXJson<P extends primitive> extends Json.Object {
7
8
  members: P[];
@@ -12,7 +13,7 @@ interface SetRTXJson<P extends primitive> extends Json.Object {
12
13
  }
13
14
  declare class SetRTX<P extends primitive> extends Set<P> implements Transceiver<NumberedSetUpdate>, Lineage {
14
15
  mode: TransceiverMode;
15
- readonly subject: Subject<SetUpdate>;
16
+ readonly subject: Subject<`add:${string}` | `clear:${string}` | `del:${string}` | `tx:${string}`>;
16
17
  cacheLimit: number;
17
18
  cache: (NumberedSetUpdate | null)[];
18
19
  cacheIdx: number;
@@ -37,4 +38,4 @@ declare class SetRTX<P extends primitive> extends Set<P> implements Transceiver<
37
38
  undo(update: NumberedSetUpdate): number | null;
38
39
  }
39
40
 
40
- export { type NumberedSetUpdate, SetRTX, type SetRTXJson, type SetUpdate };
41
+ export { type NumberedSetUpdate, SetRTX, type SetRTXJson, type SetUpdate, type SetUpdateType };
@@ -1,216 +1,2 @@
1
+ export { SetRTX } from '../../../dist/chunk-UQEYZ3OI.js';
1
2
  import '../../../dist/chunk-XWL6SNVU.js';
2
- import { Subject } from 'atom.io/internal';
3
- import { stringifyJson } from 'atom.io/json';
4
-
5
- var SetRTX = class _SetRTX extends Set {
6
- mode = `record`;
7
- subject = new Subject();
8
- cacheLimit = 0;
9
- cache = [];
10
- cacheIdx = -1;
11
- cacheUpdateNumber = -1;
12
- constructor(values, cacheLimit = 0) {
13
- super(values);
14
- if (values instanceof _SetRTX) {
15
- this.parent = values;
16
- this.cacheUpdateNumber = values.cacheUpdateNumber;
17
- }
18
- if (cacheLimit) {
19
- this.cacheLimit = cacheLimit;
20
- this.cache = new Array(cacheLimit);
21
- this.subscribe(`auto cache`, (update) => {
22
- this.cacheIdx++;
23
- this.cacheIdx %= this.cacheLimit;
24
- this.cache[this.cacheIdx] = update;
25
- });
26
- }
27
- }
28
- toJSON() {
29
- return {
30
- members: [...this],
31
- cache: this.cache,
32
- cacheLimit: this.cacheLimit,
33
- cacheIdx: this.cacheIdx,
34
- cacheUpdateNumber: this.cacheUpdateNumber
35
- };
36
- }
37
- static fromJSON(json) {
38
- const set = new _SetRTX(json.members, json.cacheLimit);
39
- set.cache = json.cache;
40
- set.cacheIdx = json.cacheIdx;
41
- set.cacheUpdateNumber = json.cacheUpdateNumber;
42
- return set;
43
- }
44
- add(value) {
45
- const result = super.add(value);
46
- if (this.mode === `record`) {
47
- this.cacheUpdateNumber++;
48
- this.emit(`add:${stringifyJson(value)}`);
49
- }
50
- return result;
51
- }
52
- clear() {
53
- const capturedContents = this.mode === `record` ? [...this] : null;
54
- super.clear();
55
- if (capturedContents) {
56
- this.cacheUpdateNumber++;
57
- this.emit(`clear:${JSON.stringify(capturedContents)}`);
58
- }
59
- }
60
- delete(value) {
61
- const result = super.delete(value);
62
- if (this.mode === `record`) {
63
- this.cacheUpdateNumber++;
64
- this.emit(`del:${stringifyJson(value)}`);
65
- }
66
- return result;
67
- }
68
- parent;
69
- child = null;
70
- transactionUpdates = null;
71
- transaction(run) {
72
- this.mode = `transaction`;
73
- this.transactionUpdates = [];
74
- this.child = new _SetRTX(this);
75
- const unsubscribe = this.child._subscribe(`transaction`, (update) => {
76
- this.transactionUpdates?.push(update);
77
- });
78
- try {
79
- const shouldCommit = run(this.child);
80
- if (shouldCommit) {
81
- for (const update of this.transactionUpdates) {
82
- this.doStep(update);
83
- }
84
- this.cacheUpdateNumber++;
85
- this.emit(`tx:${this.transactionUpdates.join(`;`)}`);
86
- }
87
- } catch (thrown) {
88
- console.warn(
89
- `Did not apply transaction to SetRTX; this error was thrown:`,
90
- thrown
91
- );
92
- throw thrown;
93
- } finally {
94
- unsubscribe();
95
- this.child = null;
96
- this.transactionUpdates = null;
97
- this.mode = `record`;
98
- }
99
- }
100
- _subscribe(key, fn) {
101
- return this.subject.subscribe(key, fn);
102
- }
103
- subscribe(key, fn) {
104
- return this.subject.subscribe(key, (update) => {
105
- fn(`${this.cacheUpdateNumber}=${update}`);
106
- });
107
- }
108
- emit(update) {
109
- this.subject.next(update);
110
- }
111
- doStep(update) {
112
- const typeValueBreak = update.indexOf(`:`);
113
- const type = update.substring(0, typeValueBreak);
114
- const value = update.substring(typeValueBreak + 1);
115
- switch (type) {
116
- case `add`:
117
- this.add(JSON.parse(value));
118
- break;
119
- case `clear`:
120
- this.clear();
121
- break;
122
- case `del`:
123
- this.delete(JSON.parse(value));
124
- break;
125
- case `tx`:
126
- for (const subUpdate of value.split(`;`)) {
127
- this.doStep(subUpdate);
128
- }
129
- }
130
- }
131
- getUpdateNumber(update) {
132
- const breakpoint = update.indexOf(`=`);
133
- return Number(update.substring(0, breakpoint));
134
- }
135
- do(update) {
136
- const breakpoint = update.indexOf(`=`);
137
- const updateNumber = Number(update.substring(0, breakpoint));
138
- const eventOffset = updateNumber - this.cacheUpdateNumber;
139
- const isFuture = eventOffset > 0;
140
- if (isFuture) {
141
- if (eventOffset === 1) {
142
- this.mode = `playback`;
143
- const innerUpdate = update.substring(breakpoint + 1);
144
- this.doStep(innerUpdate);
145
- this.mode = `record`;
146
- this.cacheUpdateNumber = updateNumber;
147
- return null;
148
- }
149
- return this.cacheUpdateNumber + 1;
150
- }
151
- if (Math.abs(eventOffset) < this.cacheLimit) {
152
- const eventIdx = this.cacheIdx + eventOffset;
153
- const cachedUpdate = this.cache[eventIdx];
154
- if (cachedUpdate === update) {
155
- return null;
156
- }
157
- this.mode = `playback`;
158
- let done = false;
159
- while (!done) {
160
- this.cacheIdx %= this.cacheLimit;
161
- const u = this.cache[this.cacheIdx];
162
- this.cacheIdx--;
163
- if (!u) {
164
- return `OUT_OF_RANGE`;
165
- }
166
- this.undo(u);
167
- done = this.cacheIdx === eventIdx - 1;
168
- }
169
- const innerUpdate = update.substring(breakpoint + 1);
170
- this.doStep(innerUpdate);
171
- this.mode = `record`;
172
- this.cacheUpdateNumber = updateNumber;
173
- return null;
174
- }
175
- return `OUT_OF_RANGE`;
176
- }
177
- undoStep(update) {
178
- const breakpoint = update.indexOf(`:`);
179
- const type = update.substring(0, breakpoint);
180
- const value = update.substring(breakpoint + 1);
181
- switch (type) {
182
- case `add`:
183
- this.delete(JSON.parse(value));
184
- break;
185
- case `del`:
186
- this.add(JSON.parse(value));
187
- break;
188
- case `clear`: {
189
- const values = JSON.parse(value);
190
- for (const v of values) this.add(v);
191
- break;
192
- }
193
- case `tx`: {
194
- const updates = value.split(`;`);
195
- for (let i = updates.length - 1; i >= 0; i--) {
196
- this.undoStep(updates[i]);
197
- }
198
- }
199
- }
200
- }
201
- undo(update) {
202
- const breakpoint = update.indexOf(`=`);
203
- const updateNumber = Number(update.substring(0, breakpoint));
204
- if (updateNumber === this.cacheUpdateNumber) {
205
- this.mode = `playback`;
206
- const innerUpdate = update.substring(breakpoint + 1);
207
- this.undoStep(innerUpdate);
208
- this.mode = `record`;
209
- this.cacheUpdateNumber--;
210
- return null;
211
- }
212
- return this.cacheUpdateNumber;
213
- }
214
- };
215
-
216
- export { SetRTX };
@@ -3,11 +3,8 @@ import { Subject } from "atom.io/internal"
3
3
  import type { Json, primitive } from "atom.io/json"
4
4
  import { stringifyJson } from "atom.io/json"
5
5
 
6
- export type SetUpdate =
7
- | `add:${string}`
8
- | `clear:${string}`
9
- | `del:${string}`
10
- | `tx:${string}`
6
+ export type SetUpdateType = `add` | `clear` | `del` | `tx`
7
+ export type SetUpdate = `${SetUpdateType}:${string}`
11
8
  export type NumberedSetUpdate = `${number}=${SetUpdate}`
12
9
 
13
10
  export interface SetRTXJson<P extends primitive> extends Json.Object {
@@ -145,7 +142,7 @@ export class SetRTX<P extends primitive>
145
142
 
146
143
  private doStep(update: SetUpdate): void {
147
144
  const typeValueBreak = update.indexOf(`:`)
148
- const type = update.substring(0, typeValueBreak)
145
+ const type = update.substring(0, typeValueBreak) as SetUpdateType
149
146
  const value = update.substring(typeValueBreak + 1)
150
147
  switch (type) {
151
148
  case `add`:
@@ -214,7 +211,7 @@ export class SetRTX<P extends primitive>
214
211
 
215
212
  public undoStep(update: SetUpdate): void {
216
213
  const breakpoint = update.indexOf(`:`)
217
- const type = update.substring(0, breakpoint)
214
+ const type = update.substring(0, breakpoint) as SetUpdateType
218
215
  const value = update.substring(breakpoint + 1)
219
216
  switch (type) {
220
217
  case `add`:
package/web/dist/index.js CHANGED
@@ -1,16 +1,2 @@
1
+ export { persistSync } from '../../dist/chunk-4LWKCEW3.js';
1
2
  import '../../dist/chunk-XWL6SNVU.js';
2
-
3
- // web/src/persist-sync.ts
4
- var persistSync = (storage, { stringify, parse }, key) => ({ setSelf, onSet }) => {
5
- const savedValue = storage.getItem(key);
6
- if (savedValue != null) setSelf(parse(savedValue));
7
- onSet(({ newValue }) => {
8
- if (newValue == null) {
9
- storage.removeItem(key);
10
- return;
11
- }
12
- storage.setItem(key, stringify(newValue));
13
- });
14
- };
15
-
16
- export { persistSync };
package/data/src/until.ts DELETED
@@ -1,15 +0,0 @@
1
- export type Loadable<T> = Promise<T> | T
2
- export type Fated<T, E extends Error = Error> = Loadable<E | T>
3
-
4
- /**
5
- * Utility for handling loadable values
6
- * @param loadable Loadable value
7
- * @param fallback Fallback value until Loadable is resolved
8
- * @returns Fallback value if your loadable is a promise, otherwise the loadable's resolved value
9
- */
10
- export function until<T>(loadable: Loadable<T>, fallback: T): T {
11
- if (loadable instanceof Promise) {
12
- return fallback
13
- }
14
- return loadable
15
- }
@@ -1,67 +0,0 @@
1
- import { MutableAtomFamilyToken, MutableAtomToken, RegularAtomFamilyToken, RegularAtomToken, WritableSelectorFamilyToken, WritableSelectorToken, ReadonlySelectorFamilyToken, ReadonlySelectorToken, WritableFamilyToken, WritableToken, ReadableFamilyToken, ReadableToken } from 'atom.io';
2
- import { Transceiver } from 'atom.io/internal';
3
- import { Json, Canonical } from 'atom.io/json';
4
-
5
- /**
6
- * @public
7
- * Finds a {@link MutableAtomToken} in the store
8
- * @param token - A {@link MutableAtomFamilyToken}
9
- * @param key - The key of the state
10
- * @returns
11
- * The current value of the state
12
- * @overload Mutable Atom
13
- */
14
- declare function findState<T extends Transceiver<any>, J extends Json.Serializable, K extends Canonical, Key extends K>(token: MutableAtomFamilyToken<T, J, K>, key: Key): MutableAtomToken<T, J, K>;
15
- /**
16
- * @public
17
- * Finds a state in the store
18
- * @param token - The token of the state family
19
- * @param key - The key of the state
20
- * @returns
21
- * The current value of the state
22
- * @overload Regular Atom
23
- */
24
- declare function findState<T, K extends Canonical, Key extends K>(token: RegularAtomFamilyToken<T, K>, key: Key): RegularAtomToken<T, K>;
25
- /**
26
- * @public
27
- * Finds a state in the store
28
- * @param token - The token of the state family
29
- * @param key - The key of the state
30
- * @returns
31
- * The current value of the state
32
- * @overload Writable Selector
33
- */
34
- declare function findState<T, K extends Canonical, Key extends K>(token: WritableSelectorFamilyToken<T, K>, key: Key): WritableSelectorToken<T, K>;
35
- /**
36
- * @public
37
- * Finds a state in the store
38
- * @param token - The token of the state family
39
- * @param key - The key of the state
40
- * @returns
41
- * The current value of the state
42
- * @overload Readonly Selector
43
- */
44
- declare function findState<T, K extends Canonical, Key extends K>(token: ReadonlySelectorFamilyToken<T, K>, key: Key): ReadonlySelectorToken<T, K>;
45
- /**
46
- * @public
47
- * Finds a state in the store
48
- * @param token - The token of the state family
49
- * @param key - The key of the state
50
- * @returns
51
- * The current value of the state
52
- * @overload Writable State
53
- */
54
- declare function findState<T, K extends Canonical, Key extends K>(token: WritableFamilyToken<T, K>, key: Key): WritableToken<T, K>;
55
- /**
56
- * @public
57
- * Finds a {@link ReadableToken} in the store
58
- * @param token - A {@link ReadableFamilyToken}
59
- * @param key - The key of the state
60
- * @returns
61
- * The current value of the state
62
- * @overload Unknown
63
- * @default
64
- */
65
- declare function findState<T, K extends Canonical, Key extends K>(token: ReadableFamilyToken<T, K>, key: Key): ReadableToken<T, K>;
66
-
67
- export { findState };
@@ -1,9 +0,0 @@
1
- import '../../dist/chunk-XWL6SNVU.js';
2
- import { findInStore, IMPLICIT } from 'atom.io/internal';
3
-
4
- function findState(token, key) {
5
- const state = findInStore(IMPLICIT.STORE, token, key);
6
- return state;
7
- }
8
-
9
- export { findState };
@@ -1,13 +0,0 @@
1
- {
2
- "name": "atom.io-ephemeral",
3
- "type": "module",
4
- "private": true,
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "exports": {
8
- ".": {
9
- "import": "./dist/index.js",
10
- "types": "./dist/index.d.ts"
11
- }
12
- }
13
- }
@@ -1 +0,0 @@
1
- export * from "./find-state"
@@ -1,203 +0,0 @@
1
- import type { Rule } from "eslint"
2
- import type * as ESTree from "estree"
3
-
4
- import { walk } from "../walk"
5
-
6
- export const lifespan = {
7
- meta: {
8
- type: `problem`,
9
- docs: {
10
- 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.`,
11
- category: `Possible Errors`,
12
- recommended: false,
13
- url: ``, // URL to documentation page for this rule
14
- },
15
- schema: [
16
- {
17
- type: `string`,
18
- enum: [`ephemeral`, `immortal`],
19
- default: `ephemeral`,
20
- },
21
- ],
22
- },
23
- create(context) {
24
- const storeLifespan = (context.options[0] ?? `ephemeral`) as
25
- | `ephemeral`
26
- | `immortal`
27
- return {
28
- ImportDeclaration(node) {
29
- const importSource = node.source.value as string
30
- if (!importSource.startsWith(`atom.io/`)) {
31
- return
32
- }
33
- const [_, subPackageName] = importSource.split(`/`)
34
- if (storeLifespan === `immortal` && subPackageName === `ephemeral`) {
35
- context.report({
36
- node,
37
- message: `do not import from "${importSource}" in an ${storeLifespan} store`,
38
- })
39
- }
40
- },
41
-
42
- CallExpression(node) {
43
- if (storeLifespan === `ephemeral`) {
44
- return
45
- }
46
-
47
- const functionCallee =
48
- node.callee.type === `Identifier` ? node.callee : undefined
49
- const methodCallee =
50
- node.callee.type === `MemberExpression` &&
51
- node.callee.property.type === `Identifier`
52
- ? node.callee.property
53
- : undefined
54
- const callee = functionCallee ?? methodCallee
55
-
56
- if (callee === undefined) {
57
- return
58
- }
59
-
60
- if (callee.name === `findState`) {
61
- context.report({
62
- node,
63
- message: `do not use findState in an ${storeLifespan} store`,
64
- })
65
- }
66
-
67
- const storeProcedures: (
68
- | ESTree.ArrowFunctionExpression
69
- | ESTree.FunctionExpression
70
- )[] = []
71
- if (
72
- callee.name === `selector` ||
73
- callee.name === `selectorFamily` ||
74
- callee.name === `transaction`
75
- ) {
76
- if (node.arguments[0].type === `ObjectExpression`) {
77
- const argProperties = node.arguments[0].properties
78
- switch (callee.name) {
79
- case `selector`:
80
- case `selectorFamily`:
81
- {
82
- const getAndSetProps = argProperties.filter(
83
- (prop): prop is ESTree.Property => {
84
- return (
85
- `key` in prop &&
86
- `name` in prop.key &&
87
- (prop.key.name === `get` || prop.key.name === `set`)
88
- )
89
- },
90
- )
91
- switch (callee.name) {
92
- case `selector`:
93
- {
94
- for (const prop of getAndSetProps) {
95
- if (
96
- prop.value.type === `FunctionExpression` ||
97
- prop.value.type === `ArrowFunctionExpression`
98
- ) {
99
- storeProcedures.push(prop.value)
100
- }
101
- }
102
- }
103
- break
104
- case `selectorFamily`:
105
- {
106
- for (const prop of getAndSetProps) {
107
- const { value } = prop
108
- if (
109
- value.type === `FunctionExpression` ||
110
- value.type === `ArrowFunctionExpression`
111
- ) {
112
- if (value.body.type === `BlockStatement`) {
113
- for (const statement of value.body.body) {
114
- if (
115
- statement.type === `ReturnStatement` &&
116
- statement.argument &&
117
- (statement.argument.type ===
118
- `FunctionExpression` ||
119
- statement.argument.type ===
120
- `ArrowFunctionExpression`)
121
- ) {
122
- storeProcedures.push(statement.argument)
123
- }
124
- }
125
- } else if (
126
- value.body.type === `FunctionExpression` ||
127
- value.body.type === `ArrowFunctionExpression`
128
- ) {
129
- storeProcedures.push(value.body)
130
- }
131
- }
132
- }
133
- }
134
- break
135
- }
136
- }
137
- break
138
-
139
- case `transaction`:
140
- {
141
- const doProp = argProperties.find(
142
- (prop): prop is ESTree.Property => {
143
- return (
144
- `key` in prop &&
145
- `name` in prop.key &&
146
- prop.key.name === `do`
147
- )
148
- },
149
- )
150
- if (doProp) {
151
- if (
152
- doProp.value.type === `FunctionExpression` ||
153
- doProp.value.type === `ArrowFunctionExpression`
154
- ) {
155
- storeProcedures.push(doProp.value)
156
- }
157
- }
158
- }
159
- break
160
- }
161
- }
162
- }
163
-
164
- for (const storeProcedure of storeProcedures) {
165
- const transactorsParam = storeProcedure.params[0]
166
- const nonDestructuredTransactorsName =
167
- transactorsParam && `name` in transactorsParam
168
- ? transactorsParam.name
169
- : undefined
170
- walk(storeProcedure.body, (n) => {
171
- // console.log(`${`\t`.repeat(depth)}${n.type} ${n.name ?? ``}`)
172
- if (n.type === `CallExpression`) {
173
- let willReport = false
174
- switch (n.callee.type) {
175
- case `MemberExpression`:
176
- if (
177
- n.callee.object.type === `Identifier` &&
178
- n.callee.object.name === nonDestructuredTransactorsName &&
179
- n.callee.property.type === `Identifier` &&
180
- n.callee.property.name === `find`
181
- ) {
182
- willReport = true
183
- }
184
- break
185
- case `Identifier`:
186
- if (n.callee.name === `find`) {
187
- willReport = true
188
- }
189
- break
190
- }
191
- if (willReport) {
192
- context.report({
193
- node: n,
194
- message: `Using find in a transactor is not allowed in an immortal store.`,
195
- })
196
- }
197
- }
198
- })
199
- }
200
- },
201
- }
202
- },
203
- } satisfies Rule.RuleModule
@@ -1,12 +0,0 @@
1
- import { MutableAtomFamilyToken, MutableAtomToken, RegularAtomFamilyToken, RegularAtomToken, WritableSelectorFamilyToken, WritableSelectorToken, ReadonlySelectorFamilyToken, ReadonlySelectorToken, WritableFamilyToken, WritableToken, ReadableFamilyToken, ReadableToken } from 'atom.io';
2
- import { Transceiver } from 'atom.io/internal';
3
- import { Json, Canonical } from 'atom.io/json';
4
-
5
- declare function seekState<T extends Transceiver<any>, J extends Json.Serializable, K extends Canonical, Key extends K>(token: MutableAtomFamilyToken<T, J, K>, key: Key): MutableAtomToken<T, J, K> | undefined;
6
- declare function seekState<T, K extends Canonical, Key extends K>(token: RegularAtomFamilyToken<T, K>, key: Key): RegularAtomToken<T, K> | undefined;
7
- declare function seekState<T, K extends Canonical, Key extends K>(token: WritableSelectorFamilyToken<T, K>, key: Key): WritableSelectorToken<T, K> | undefined;
8
- declare function seekState<T, K extends Canonical, Key extends K>(token: ReadonlySelectorFamilyToken<T, K>, key: Key): ReadonlySelectorToken<T, K> | undefined;
9
- declare function seekState<T, K extends Canonical, Key extends K>(token: WritableFamilyToken<T, K>, key: Key): WritableToken<T, K> | undefined;
10
- declare function seekState<T, K extends Canonical, Key extends K>(token: ReadableFamilyToken<T, K>, key: Key): ReadableToken<T, K> | undefined;
11
-
12
- export { seekState };
@@ -1,9 +0,0 @@
1
- import '../../dist/chunk-XWL6SNVU.js';
2
- import { seekInStore, IMPLICIT } from 'atom.io/internal';
3
-
4
- function seekState(token, key) {
5
- const state = seekInStore(IMPLICIT.STORE, token, key);
6
- return state;
7
- }
8
-
9
- export { seekState };
@@ -1,13 +0,0 @@
1
- {
2
- "name": "atom.io-immortal",
3
- "type": "module",
4
- "private": true,
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "exports": {
8
- ".": {
9
- "import": "./dist/index.js",
10
- "types": "./dist/index.d.ts"
11
- }
12
- }
13
- }
@@ -1 +0,0 @@
1
- export * from "./seek-state"