atom.io 0.20.3 → 0.21.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 (51) hide show
  1. package/data/dist/index.cjs +4 -4
  2. package/data/dist/index.js +1 -1
  3. package/data/src/join.ts +3 -8
  4. package/dist/{chunk-SMZRGPN6.js → chunk-HITX3MO4.js} +2 -2
  5. package/dist/chunk-PNIHPILQ.js +8 -0
  6. package/dist/{chunk-2AIFLP2B.js → chunk-RT43TVKP.js} +2 -2
  7. package/dist/index.cjs +4 -4
  8. package/dist/index.d.ts +2 -2
  9. package/dist/index.js +5 -7
  10. package/internal/dist/index.cjs +56 -74
  11. package/internal/dist/index.d.ts +11 -7
  12. package/internal/dist/index.js +55 -73
  13. package/internal/src/atom/create-regular-atom.ts +1 -1
  14. package/internal/src/atom/dispose-atom.ts +42 -0
  15. package/internal/src/atom/index.ts +1 -1
  16. package/internal/src/future.ts +6 -20
  17. package/internal/src/get-state/get-from-store.ts +1 -2
  18. package/internal/src/mutable/tracker.ts +2 -24
  19. package/internal/src/operation.ts +0 -1
  20. package/internal/src/selector/{delete-selector.ts → dispose-selector.ts} +3 -2
  21. package/internal/src/selector/index.ts +1 -1
  22. package/internal/src/store/deposit.ts +5 -0
  23. package/internal/src/store/store.ts +5 -1
  24. package/internal/src/subscribe/recall-state.ts +3 -3
  25. package/internal/src/subscribe/subscribe-to-state.ts +16 -3
  26. package/introspection/dist/index.cjs +251 -119
  27. package/introspection/dist/index.d.ts +43 -6
  28. package/introspection/dist/index.js +226 -96
  29. package/introspection/src/attach-atom-index.ts +68 -47
  30. package/introspection/src/attach-introspection-states.ts +0 -1
  31. package/introspection/src/attach-selector-index.ts +76 -59
  32. package/introspection/src/attach-timeline-family.ts +2 -17
  33. package/introspection/src/auditor.ts +135 -0
  34. package/introspection/src/index.ts +8 -18
  35. package/package.json +12 -12
  36. package/react-devtools/dist/index.cjs +3 -3
  37. package/react-devtools/dist/index.d.ts +5 -5
  38. package/react-devtools/dist/index.js +4 -4
  39. package/react-devtools/src/StateIndex.tsx +8 -27
  40. package/realtime-client/dist/index.cjs +1 -1
  41. package/realtime-client/dist/index.js +1 -1
  42. package/realtime-client/src/sync-continuity.ts +2 -2
  43. package/realtime-react/dist/index.cjs +1 -1
  44. package/realtime-react/dist/index.js +1 -1
  45. package/realtime-server/dist/index.cjs +2 -2
  46. package/realtime-server/dist/index.js +1 -1
  47. package/realtime-testing/dist/index.cjs +4 -4
  48. package/realtime-testing/dist/index.js +1 -1
  49. package/src/dispose.ts +3 -3
  50. package/src/validators.ts +0 -6
  51. package/internal/src/atom/delete-atom.ts +0 -40
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var Internal = require('atom.io/internal');
3
+ var Internal2 = require('atom.io/internal');
4
4
 
5
5
  function _interopNamespace(e) {
6
6
  if (e && e.__esModule) return e;
@@ -20,11 +20,9 @@ function _interopNamespace(e) {
20
20
  return Object.freeze(n);
21
21
  }
22
22
 
23
- var Internal__namespace = /*#__PURE__*/_interopNamespace(Internal);
23
+ var Internal2__namespace = /*#__PURE__*/_interopNamespace(Internal2);
24
24
 
25
25
  var __defProp = Object.defineProperty;
26
- var __defProps = Object.defineProperties;
27
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
28
26
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
29
27
  var __hasOwnProp = Object.prototype.hasOwnProperty;
30
28
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
@@ -40,67 +38,90 @@ var __spreadValues = (a, b) => {
40
38
  }
41
39
  return a;
42
40
  };
43
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
44
- var attachAtomIndex = (store = Internal.IMPLICIT.STORE) => {
45
- console.log(store.config);
46
- const atomTokenIndexState__INTERNAL = Internal.createRegularAtom(
41
+ var attachAtomIndex = (store = Internal2.IMPLICIT.STORE) => {
42
+ const atomTokenIndexState__INTERNAL = Internal2.createRegularAtom(
47
43
  {
48
44
  key: `\u{1F441}\u200D\u{1F5E8} Atom Token Index (Internal)`,
49
45
  default: () => {
50
- const defaultAtomIndex = [...store.atoms].filter(([key]) => !key.includes(`\u{1F441}\u200D\u{1F5E8}`)).reduce((acc, [key, atom]) => {
51
- acc[key] = { key, type: atom.type };
52
- return acc;
53
- }, {});
54
- return defaultAtomIndex;
46
+ const base = /* @__PURE__ */ new Map();
47
+ for (const [key, val] of store.atoms) {
48
+ if (!key.includes(`\u{1F441}\u200D\u{1F5E8}`)) {
49
+ const token = Internal2.deposit(val);
50
+ if (val.family) {
51
+ let familyNode = base.get(val.family.key);
52
+ if (!familyNode || !(`familyMembers` in familyNode)) {
53
+ familyNode = {
54
+ key: val.family.key,
55
+ familyMembers: /* @__PURE__ */ new Map()
56
+ };
57
+ base.set(val.family.key, familyNode);
58
+ }
59
+ familyNode.familyMembers.set(val.family.subKey, token);
60
+ } else {
61
+ base.set(key, token);
62
+ }
63
+ }
64
+ }
65
+ return base;
55
66
  },
56
67
  effects: [
57
68
  ({ setSelf }) => {
58
- store.on.atomCreation.subscribe(`introspection`, (atomToken) => {
59
- if (atomToken.key.includes(`\u{1F441}\u200D\u{1F5E8}`)) {
60
- return;
61
- }
62
- const set = () => setSelf((state) => {
63
- const { key, family } = atomToken;
64
- if (family) {
65
- const { key: familyKey, subKey } = family;
66
- const current = state[familyKey];
67
- if (current === void 0 || `familyMembers` in current) {
68
- const familyKeyState = current || {
69
- key: familyKey,
70
- familyMembers: {}
71
- };
72
- return __spreadProps(__spreadValues({}, state), {
73
- [familyKey]: __spreadProps(__spreadValues({}, familyKeyState), {
74
- familyMembers: __spreadProps(__spreadValues({}, familyKeyState.familyMembers), {
75
- [subKey]: atomToken
76
- })
77
- })
78
- });
79
- }
69
+ const unsubscribeFromAtomCreation = store.on.atomCreation.subscribe(
70
+ `introspection`,
71
+ (atomToken) => {
72
+ if (atomToken.key.includes(`\u{1F441}\u200D\u{1F5E8}`)) {
73
+ return;
80
74
  }
81
- return __spreadProps(__spreadValues({}, state), {
82
- [key]: atomToken
75
+ setSelf((self) => {
76
+ if (atomToken.family) {
77
+ const { key: familyKey, subKey } = atomToken.family;
78
+ let familyNode = self.get(familyKey);
79
+ if (familyNode === void 0 || !(`familyMembers` in familyNode)) {
80
+ familyNode = {
81
+ key: familyKey,
82
+ familyMembers: /* @__PURE__ */ new Map()
83
+ };
84
+ self.set(familyKey, familyNode);
85
+ }
86
+ familyNode.familyMembers.set(subKey, atomToken);
87
+ } else {
88
+ self.set(atomToken.key, atomToken);
89
+ }
90
+ return self;
83
91
  });
84
- });
85
- if (Internal.newest(store).operation.open) {
86
- const unsubscribe = store.on.operationClose.subscribe(
87
- `introspection: waiting to update atom index`,
88
- () => {
89
- unsubscribe();
90
- set();
92
+ }
93
+ );
94
+ const unsubscribeFromAtomDisposal = store.on.atomDisposal.subscribe(
95
+ `introspection`,
96
+ (atomToken) => {
97
+ setSelf((self) => {
98
+ if (atomToken.family) {
99
+ const { key: familyKey, subKey } = atomToken.family;
100
+ const familyNode = self.get(familyKey);
101
+ if (familyNode && `familyMembers` in familyNode) {
102
+ familyNode.familyMembers.delete(subKey);
103
+ if (familyNode.familyMembers.size === 0) {
104
+ self.delete(familyKey);
105
+ }
106
+ }
107
+ } else {
108
+ self.delete(atomToken.key);
91
109
  }
92
- );
93
- } else {
94
- set();
110
+ return self;
111
+ });
95
112
  }
96
- });
113
+ );
114
+ return () => {
115
+ unsubscribeFromAtomCreation();
116
+ unsubscribeFromAtomDisposal();
117
+ };
97
118
  }
98
119
  ]
99
120
  },
100
121
  void 0,
101
122
  store
102
123
  );
103
- return Internal.createStandaloneSelector(
124
+ return Internal2.createStandaloneSelector(
104
125
  {
105
126
  key: `\u{1F441}\u200D\u{1F5E8} Atom Token Index`,
106
127
  get: ({ get }) => get(atomTokenIndexState__INTERNAL)
@@ -108,80 +129,101 @@ var attachAtomIndex = (store = Internal.IMPLICIT.STORE) => {
108
129
  store
109
130
  );
110
131
  };
111
- var attachSelectorIndex = (store = Internal.IMPLICIT.STORE) => {
112
- const readonlySelectorTokenIndexState__INTERNAL = Internal.createRegularAtom(
132
+ var attachSelectorIndex = (store = Internal2.IMPLICIT.STORE) => {
133
+ const readonlySelectorTokenIndexState__INTERNAL = Internal2.createRegularAtom(
113
134
  {
114
135
  key: `\u{1F441}\u200D\u{1F5E8} Selector Token Index (Internal)`,
115
- default: () => Object.assign(
116
- [...store.readonlySelectors].filter(([key]) => !key.includes(`\u{1F441}\u200D\u{1F5E8}`)).reduce((acc, [key]) => {
117
- acc[key] = { key, type: `readonly_selector` };
118
- return acc;
119
- }, {}),
120
- [...store.selectors].reduce((acc, [key]) => {
121
- acc[key] = { key, type: `selector` };
122
- return acc;
123
- }, {})
124
- ),
136
+ default: () => {
137
+ const base = /* @__PURE__ */ new Map();
138
+ for (const map of [store.readonlySelectors, store.selectors]) {
139
+ for (const [key, val] of map) {
140
+ if (!key.includes(`\u{1F441}\u200D\u{1F5E8}`)) {
141
+ const token = Internal2.deposit(val);
142
+ if (val.family) {
143
+ let familyNode = base.get(val.family.key);
144
+ if (!familyNode || !(`familyMembers` in familyNode)) {
145
+ familyNode = {
146
+ key: val.family.key,
147
+ familyMembers: /* @__PURE__ */ new Map()
148
+ };
149
+ base.set(val.family.key, familyNode);
150
+ }
151
+ familyNode.familyMembers.set(val.family.subKey, token);
152
+ } else {
153
+ base.set(key, token);
154
+ }
155
+ }
156
+ }
157
+ }
158
+ return base;
159
+ },
125
160
  effects: [
126
161
  ({ setSelf }) => {
127
- store.on.selectorCreation.subscribe(
162
+ const unsubscribeFromSelectorCreation = store.on.selectorCreation.subscribe(
128
163
  `introspection`,
129
164
  (selectorToken) => {
130
165
  if (selectorToken.key.includes(`\u{1F441}\u200D\u{1F5E8}`)) {
131
166
  return;
132
167
  }
133
- const set = () => setSelf((state) => {
134
- const { key, family } = selectorToken;
135
- if (family) {
136
- const { key: familyKey, subKey } = family;
137
- const current = state[familyKey];
138
- if (current === void 0 || `familyMembers` in current) {
139
- const familyKeyState = current || {
168
+ setSelf((self) => {
169
+ if (selectorToken.family) {
170
+ const { key: familyKey, subKey } = selectorToken.family;
171
+ let familyNode = self.get(familyKey);
172
+ if (familyNode === void 0 || !(`familyMembers` in familyNode)) {
173
+ familyNode = {
140
174
  key: familyKey,
141
- familyMembers: {}
175
+ familyMembers: /* @__PURE__ */ new Map()
142
176
  };
143
- return __spreadProps(__spreadValues({}, state), {
144
- [familyKey]: __spreadProps(__spreadValues({}, familyKeyState), {
145
- familyMembers: __spreadProps(__spreadValues({}, familyKeyState.familyMembers), {
146
- [subKey]: selectorToken
147
- })
148
- })
149
- });
177
+ self.set(familyKey, familyNode);
150
178
  }
179
+ familyNode.familyMembers.set(subKey, selectorToken);
180
+ } else {
181
+ self.set(selectorToken.key, selectorToken);
151
182
  }
152
- return __spreadProps(__spreadValues({}, state), {
153
- [key]: selectorToken
154
- });
183
+ return self;
155
184
  });
156
- if (Internal.newest(store).operation.open) {
157
- const unsubscribe = store.on.operationClose.subscribe(
158
- `introspection: waiting to update selector index`,
159
- () => {
160
- unsubscribe();
161
- set();
185
+ }
186
+ );
187
+ const unsubscribeFromSelectorDisposal = store.on.selectorDisposal.subscribe(
188
+ `introspection`,
189
+ (selectorToken) => {
190
+ setSelf((self) => {
191
+ if (selectorToken.family) {
192
+ const { key: familyKey, subKey } = selectorToken.family;
193
+ const familyNode = self.get(familyKey);
194
+ if (familyNode && `familyMembers` in familyNode) {
195
+ familyNode.familyMembers.delete(subKey);
196
+ if (familyNode.familyMembers.size === 0) {
197
+ self.delete(familyKey);
198
+ }
162
199
  }
163
- );
164
- } else {
165
- set();
166
- }
200
+ } else {
201
+ self.delete(selectorToken.key);
202
+ }
203
+ return self;
204
+ });
167
205
  }
168
206
  );
207
+ return () => {
208
+ unsubscribeFromSelectorCreation();
209
+ unsubscribeFromSelectorDisposal();
210
+ };
169
211
  }
170
212
  ]
171
213
  },
172
214
  void 0,
173
215
  store
174
216
  );
175
- return Internal.createStandaloneSelector(
217
+ return Internal2.createStandaloneSelector(
176
218
  {
177
219
  key: `\u{1F441}\u200D\u{1F5E8} Selector Token Index`,
178
220
  get: ({ get }) => get(readonlySelectorTokenIndexState__INTERNAL)
179
221
  },
180
- Internal.IMPLICIT.STORE
222
+ Internal2.IMPLICIT.STORE
181
223
  );
182
224
  };
183
- var attachTimelineFamily = (store = Internal.IMPLICIT.STORE) => {
184
- const findTimelineLogState__INTERNAL = Internal.createRegularAtomFamily(
225
+ var attachTimelineFamily = (store = Internal2.IMPLICIT.STORE) => {
226
+ const findTimelineLogState__INTERNAL = Internal2.createRegularAtomFamily(
185
227
  {
186
228
  key: `\u{1F441}\u200D\u{1F5E8} Timeline Update Log (Internal)`,
187
229
  default: (key) => {
@@ -196,33 +238,21 @@ var attachTimelineFamily = (store = Internal.IMPLICIT.STORE) => {
196
238
  transactionKey: null,
197
239
  install: () => {
198
240
  },
199
- subject: new Internal.Subject()
241
+ subject: new Internal2.Subject()
200
242
  };
201
243
  },
202
244
  effects: (key) => [
203
245
  ({ setSelf }) => {
204
246
  const tl = store.timelines.get(key);
205
247
  tl == null ? void 0 : tl.subject.subscribe(`introspection`, (_) => {
206
- if (store.operation.open === true) {
207
- const unsubscribe = store.on.operationClose.subscribe(
208
- `introspection`,
209
- (operationClose) => {
210
- if (operationClose.open === false) {
211
- unsubscribe();
212
- setSelf(__spreadValues({}, tl));
213
- }
214
- }
215
- );
216
- } else {
217
- setSelf(__spreadValues({}, tl));
218
- }
248
+ setSelf(__spreadValues({}, tl));
219
249
  });
220
250
  }
221
251
  ]
222
252
  },
223
253
  store
224
254
  );
225
- const findTimelineLogState = Internal.createSelectorFamily(
255
+ const findTimelineLogState = Internal2.createSelectorFamily(
226
256
  {
227
257
  key: `\u{1F441}\u200D\u{1F5E8} Timeline Update Log`,
228
258
  get: (key) => ({ get }) => get(findTimelineLogState__INTERNAL(key))
@@ -231,8 +261,8 @@ var attachTimelineFamily = (store = Internal.IMPLICIT.STORE) => {
231
261
  );
232
262
  return findTimelineLogState;
233
263
  };
234
- var attachTimelineIndex = (store = Internal.IMPLICIT.STORE) => {
235
- const timelineTokenIndexState__INTERNAL = Internal.createRegularAtom(
264
+ var attachTimelineIndex = (store = Internal2.IMPLICIT.STORE) => {
265
+ const timelineTokenIndexState__INTERNAL = Internal2.createRegularAtom(
236
266
  {
237
267
  key: `\u{1F441}\u200D\u{1F5E8} Timeline Token Index (Internal)`,
238
268
  default: () => [...store.timelines].map(([key]) => {
@@ -252,7 +282,7 @@ var attachTimelineIndex = (store = Internal.IMPLICIT.STORE) => {
252
282
  void 0,
253
283
  store
254
284
  );
255
- const timelineTokenIndex = Internal.createStandaloneSelector(
285
+ const timelineTokenIndex = Internal2.createStandaloneSelector(
256
286
  {
257
287
  key: `\u{1F441}\u200D\u{1F5E8} Timeline Token Index`,
258
288
  get: ({ get }) => get(timelineTokenIndexState__INTERNAL)
@@ -261,8 +291,8 @@ var attachTimelineIndex = (store = Internal.IMPLICIT.STORE) => {
261
291
  );
262
292
  return timelineTokenIndex;
263
293
  };
264
- var attachTransactionIndex = (store = Internal.IMPLICIT.STORE) => {
265
- const transactionTokenIndexState__INTERNAL = Internal.createRegularAtom(
294
+ var attachTransactionIndex = (store = Internal2.IMPLICIT.STORE) => {
295
+ const transactionTokenIndexState__INTERNAL = Internal2.createRegularAtom(
266
296
  {
267
297
  key: `\u{1F441}\u200D\u{1F5E8} Transaction Token Index (Internal)`,
268
298
  default: () => [...store.transactions].map(([key]) => {
@@ -282,7 +312,7 @@ var attachTransactionIndex = (store = Internal.IMPLICIT.STORE) => {
282
312
  void 0,
283
313
  store
284
314
  );
285
- const transactionTokenIndex = Internal.createStandaloneSelector(
315
+ const transactionTokenIndex = Internal2.createStandaloneSelector(
286
316
  {
287
317
  key: `\u{1F441}\u200D\u{1F5E8} Transaction Token Index`,
288
318
  get: ({ get }) => get(transactionTokenIndexState__INTERNAL)
@@ -291,8 +321,8 @@ var attachTransactionIndex = (store = Internal.IMPLICIT.STORE) => {
291
321
  );
292
322
  return transactionTokenIndex;
293
323
  };
294
- var attachTransactionLogs = (store = Internal.IMPLICIT.STORE) => {
295
- const findTransactionUpdateLog = Internal.createRegularAtomFamily(
324
+ var attachTransactionLogs = (store = Internal2.IMPLICIT.STORE) => {
325
+ const findTransactionUpdateLog = Internal2.createRegularAtomFamily(
296
326
  {
297
327
  key: `\u{1F441}\u200D\u{1F5E8} Transaction Update Log (Internal)`,
298
328
  default: () => [],
@@ -309,7 +339,7 @@ var attachTransactionLogs = (store = Internal.IMPLICIT.STORE) => {
309
339
  },
310
340
  store
311
341
  );
312
- const findTransactionUpdateLogState = Internal.createSelectorFamily(
342
+ const findTransactionUpdateLogState = Internal2.createSelectorFamily(
313
343
  {
314
344
  key: `\u{1F441}\u200D\u{1F5E8} Transaction Update Log`,
315
345
  get: (key) => ({ get }) => get(findTransactionUpdateLog(key))
@@ -320,7 +350,7 @@ var attachTransactionLogs = (store = Internal.IMPLICIT.STORE) => {
320
350
  };
321
351
 
322
352
  // introspection/src/attach-introspection-states.ts
323
- var attachIntrospectionStates = (store = Internal__namespace.IMPLICIT.STORE) => {
353
+ var attachIntrospectionStates = (store = Internal2__namespace.IMPLICIT.STORE) => {
324
354
  return {
325
355
  atomIndex: attachAtomIndex(store),
326
356
  selectorIndex: attachSelectorIndex(store),
@@ -330,5 +360,107 @@ var attachIntrospectionStates = (store = Internal__namespace.IMPLICIT.STORE) =>
330
360
  findTimelineState: attachTimelineFamily(store)
331
361
  };
332
362
  };
363
+ function getState(token) {
364
+ return Internal2__namespace.getFromStore(token, Internal2__namespace.IMPLICIT.STORE);
365
+ }
366
+
367
+ // introspection/src/auditor.ts
368
+ var _Auditor = class _Auditor {
369
+ /**
370
+ * @param {Store} store - The store to audit.
371
+ */
372
+ constructor(store = Internal2__namespace.IMPLICIT.STORE) {
373
+ this.store = store;
374
+ this.auditorCreatedAt = performance.now();
375
+ this.statesCreatedAt = /* @__PURE__ */ new Map();
376
+ this.disposed = false;
377
+ this.atomIndex = attachAtomIndex(this.store);
378
+ this.selectorIndex = attachSelectorIndex(this.store);
379
+ this.unsubscribeFromAtomCreation = this.store.on.atomCreation.subscribe(
380
+ `auditor-${this.auditorCreatedAt}`,
381
+ ({ key }) => {
382
+ this.statesCreatedAt.set(key, performance.now() - this.auditorCreatedAt);
383
+ }
384
+ );
385
+ this.unsubscribeFromAtomDisposal = this.store.on.atomDisposal.subscribe(
386
+ `auditor-${this.auditorCreatedAt}`,
387
+ ({ key }) => {
388
+ this.statesCreatedAt.delete(key);
389
+ }
390
+ );
391
+ this.unsubscribeFromSelectorCreation = this.store.on.selectorCreation.subscribe(
392
+ `auditor-${this.auditorCreatedAt}`,
393
+ ({ key }) => {
394
+ this.statesCreatedAt.set(
395
+ key,
396
+ performance.now() - this.auditorCreatedAt
397
+ );
398
+ }
399
+ );
400
+ this.unsubscribeFromSelectorDisposal = this.store.on.selectorDisposal.subscribe(
401
+ `auditor-${this.auditorCreatedAt}`,
402
+ ({ key }) => {
403
+ this.statesCreatedAt.delete(key);
404
+ }
405
+ );
406
+ }
407
+ /**
408
+ * Lists all resources in the store, along with their creation time.
409
+ *
410
+ * @param {ListResourcesParam} [param] - Optional parameters for filtering the list of resources.
411
+ * @returns {readonly [ReadableToken<unknown>, number]}[] - An array of tuples, where each tuple contains a state token belonging to a family in the store and that state's creation time.
412
+ */
413
+ listResources(param = _Auditor.DEFAULT_LIST_RESOURCES_PARAM) {
414
+ if (this.disposed) {
415
+ throw new Error(`This Auditor has been disposed`);
416
+ }
417
+ const atoms = getState(this.atomIndex);
418
+ const selectors = getState(this.selectorIndex);
419
+ const atomFamilyNodes = [...atoms.values()].filter(
420
+ (node) => `familyMembers` in node
421
+ );
422
+ const selectorFamilyNodes = [...selectors.values()].filter(
423
+ (node) => `familyMembers` in node
424
+ );
425
+ const currentTime = performance.now();
426
+ const resources = [];
427
+ if (param.atomFamilies) {
428
+ for (const familyNode of atomFamilyNodes) {
429
+ const tokens = familyNode.familyMembers.values();
430
+ for (const token of tokens) {
431
+ const storedTime = this.statesCreatedAt.get(token.key);
432
+ const creationTime = storedTime != null ? storedTime : this.auditorCreatedAt;
433
+ const age = currentTime - creationTime;
434
+ resources.push([token, age]);
435
+ }
436
+ }
437
+ }
438
+ if (param.selectorFamilies) {
439
+ for (const familyNode of selectorFamilyNodes) {
440
+ const tokens = familyNode.familyMembers.values();
441
+ for (const token of tokens) {
442
+ const storedTime = this.statesCreatedAt.get(token.key);
443
+ const creationTime = storedTime != null ? storedTime : this.auditorCreatedAt;
444
+ const age = currentTime - creationTime;
445
+ resources.push([token, age]);
446
+ }
447
+ }
448
+ }
449
+ return resources;
450
+ }
451
+ [Symbol.dispose]() {
452
+ this.unsubscribeFromAtomCreation();
453
+ this.unsubscribeFromAtomDisposal();
454
+ this.unsubscribeFromSelectorCreation();
455
+ this.unsubscribeFromSelectorDisposal();
456
+ this.disposed = true;
457
+ }
458
+ };
459
+ _Auditor.DEFAULT_LIST_RESOURCES_PARAM = {
460
+ atomFamilies: true,
461
+ selectorFamilies: true
462
+ };
463
+ var Auditor = _Auditor;
333
464
 
465
+ exports.Auditor = Auditor;
334
466
  exports.attachIntrospectionStates = attachIntrospectionStates;
@@ -1,10 +1,10 @@
1
- import { AtomToken, ReadonlySelectorToken, WritableSelectorToken, TransactionToken, Func, ReadonlySelectorFamilyToken, TransactionUpdate, TimelineToken } from 'atom.io';
1
+ import { AtomToken, SelectorToken, ReadonlySelectorToken, TransactionToken, Func, ReadonlySelectorFamilyToken, TransactionUpdate, TimelineToken, ReadableToken } from 'atom.io';
2
2
  import * as Internal from 'atom.io/internal';
3
3
  import { Timeline } from 'atom.io/internal';
4
4
 
5
5
  type AtomTokenIndex = WritableTokenIndex<AtomToken<unknown>>;
6
6
 
7
- type SelectorTokenIndex = WritableTokenIndex<ReadonlySelectorToken<unknown> | WritableSelectorToken<unknown>>;
7
+ type SelectorTokenIndex = WritableTokenIndex<SelectorToken<unknown>>;
8
8
 
9
9
  declare const attachIntrospectionStates: (store?: Internal.Store) => {
10
10
  atomIndex: ReadonlySelectorToken<AtomTokenIndex>;
@@ -15,10 +15,47 @@ declare const attachIntrospectionStates: (store?: Internal.Store) => {
15
15
  findTimelineState: ReadonlySelectorFamilyToken<Timeline<any>, string>;
16
16
  };
17
17
 
18
- type FamilyNode<Token extends AtomToken<unknown> | ReadonlySelectorToken<unknown> | WritableSelectorToken<unknown>> = {
18
+ type ListResourcesParam = {
19
+ atomFamilies: boolean;
20
+ selectorFamilies: boolean;
21
+ };
22
+ /**
23
+ * Auditor is a tool for identifying lingering resources in your store that may result in memory leaks.
24
+ * @experimental
25
+ */
26
+ declare class Auditor {
27
+ readonly store: Internal.Store;
28
+ auditorCreatedAt: number;
29
+ statesCreatedAt: Map<string, number>;
30
+ readonly atomIndex: ReadonlySelectorToken<AtomTokenIndex>;
31
+ readonly selectorIndex: ReadonlySelectorToken<SelectorTokenIndex>;
32
+ disposed: boolean;
33
+ private readonly unsubscribeFromAtomCreation;
34
+ private readonly unsubscribeFromAtomDisposal;
35
+ private readonly unsubscribeFromSelectorCreation;
36
+ private readonly unsubscribeFromSelectorDisposal;
37
+ /**
38
+ * @param {Store} store - The store to audit.
39
+ */
40
+ constructor(store?: Internal.Store);
41
+ static readonly DEFAULT_LIST_RESOURCES_PARAM: {
42
+ atomFamilies: true;
43
+ selectorFamilies: true;
44
+ };
45
+ /**
46
+ * Lists all resources in the store, along with their creation time.
47
+ *
48
+ * @param {ListResourcesParam} [param] - Optional parameters for filtering the list of resources.
49
+ * @returns {readonly [ReadableToken<unknown>, number]}[] - An array of tuples, where each tuple contains a state token belonging to a family in the store and that state's creation time.
50
+ */
51
+ listResources(param?: ListResourcesParam): (readonly [ReadableToken<unknown>, number])[];
52
+ [Symbol.dispose](): void;
53
+ }
54
+
55
+ type FamilyNode<Token extends ReadableToken<unknown>> = {
19
56
  key: string;
20
- familyMembers: Record<string, Token>;
57
+ familyMembers: Map<string, Token>;
21
58
  };
22
- type WritableTokenIndex<Token extends AtomToken<unknown> | ReadonlySelectorToken<unknown> | WritableSelectorToken<unknown>> = Record<string, FamilyNode<Token> | Token>;
59
+ type WritableTokenIndex<Token extends ReadableToken<unknown>> = Map<string, FamilyNode<Token> | Token>;
23
60
 
24
- export { type FamilyNode, type WritableTokenIndex, attachIntrospectionStates };
61
+ export { Auditor, type FamilyNode, type ListResourcesParam, type WritableTokenIndex, attachIntrospectionStates };