atom.io 0.14.0 → 0.14.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 (122) hide show
  1. package/data/dist/index.cjs +1473 -52
  2. package/data/dist/index.cjs.map +1 -1
  3. package/data/dist/index.d.cts +315 -16
  4. package/data/dist/index.js +10 -267
  5. package/data/dist/index.js.map +1 -1
  6. package/data/package.json +5 -5
  7. package/data/src/join.ts +3 -3
  8. package/dist/chunk-5VJ77LZE.js +176 -0
  9. package/dist/chunk-5VJ77LZE.js.map +1 -0
  10. package/dist/chunk-CK7GNCU5.js +309 -0
  11. package/dist/chunk-CK7GNCU5.js.map +1 -0
  12. package/dist/chunk-KW7RA7IM.js +67 -0
  13. package/dist/chunk-KW7RA7IM.js.map +1 -0
  14. package/dist/chunk-LFXB7Y6M.js +68 -0
  15. package/dist/chunk-LFXB7Y6M.js.map +1 -0
  16. package/dist/chunk-NYCVSXQB.js +181 -0
  17. package/dist/chunk-NYCVSXQB.js.map +1 -0
  18. package/dist/chunk-TE3ZSTQ6.js +2516 -0
  19. package/dist/chunk-TE3ZSTQ6.js.map +1 -0
  20. package/dist/index.cjs +2244 -55
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.d.cts +268 -21
  23. package/dist/index.js +1 -152
  24. package/dist/index.js.map +1 -1
  25. package/dist/metafile-cjs.json +1 -1
  26. package/internal/dist/index.cjs +208 -79
  27. package/internal/dist/index.cjs.map +1 -1
  28. package/internal/dist/index.d.cts +226 -27
  29. package/internal/dist/index.js +1 -2240
  30. package/internal/dist/index.js.map +1 -1
  31. package/internal/package.json +5 -5
  32. package/introspection/dist/index.cjs +1618 -46
  33. package/introspection/dist/index.cjs.map +1 -1
  34. package/introspection/dist/index.d.cts +374 -4
  35. package/introspection/dist/index.js +2 -316
  36. package/introspection/dist/index.js.map +1 -1
  37. package/introspection/package.json +5 -5
  38. package/json/dist/index.cjs +1560 -8
  39. package/json/dist/index.cjs.map +1 -1
  40. package/json/dist/index.d.cts +371 -7
  41. package/json/dist/index.js +1 -76
  42. package/json/dist/index.js.map +1 -1
  43. package/json/package.json +5 -5
  44. package/package.json +5 -4
  45. package/react/dist/index.cjs +1604 -14
  46. package/react/dist/index.cjs.map +1 -1
  47. package/react/dist/index.d.cts +375 -4
  48. package/react/dist/index.js +2 -68
  49. package/react/dist/index.js.map +1 -1
  50. package/react/package.json +5 -5
  51. package/react-devtools/dist/index.cjs +2268 -198
  52. package/react-devtools/dist/index.cjs.map +1 -1
  53. package/react-devtools/dist/index.css +2 -2
  54. package/react-devtools/dist/index.d.cts +148 -24
  55. package/react-devtools/dist/index.js +57 -297
  56. package/react-devtools/dist/index.js.map +1 -1
  57. package/react-devtools/package.json +5 -5
  58. package/realtime-client/dist/index.cjs +1585 -35
  59. package/realtime-client/dist/index.cjs.map +1 -1
  60. package/realtime-client/dist/index.d.cts +382 -12
  61. package/realtime-client/dist/index.js +2 -165
  62. package/realtime-client/dist/index.js.map +1 -1
  63. package/realtime-client/package.json +5 -5
  64. package/realtime-react/dist/index.cjs +1782 -35
  65. package/realtime-react/dist/index.cjs.map +1 -1
  66. package/realtime-react/dist/index.d.cts +49 -9
  67. package/realtime-react/dist/index.js +4 -66
  68. package/realtime-react/dist/index.js.map +1 -1
  69. package/realtime-react/package.json +5 -5
  70. package/realtime-server/dist/index.cjs +1604 -58
  71. package/realtime-server/dist/index.cjs.map +1 -1
  72. package/realtime-server/dist/index.d.cts +391 -11
  73. package/realtime-server/dist/index.js +27 -21
  74. package/realtime-server/dist/index.js.map +1 -1
  75. package/realtime-server/package.json +6 -6
  76. package/realtime-testing/dist/index.cjs +2352 -16
  77. package/realtime-testing/dist/index.cjs.map +1 -1
  78. package/realtime-testing/dist/index.d.cts +486 -3
  79. package/realtime-testing/dist/index.js +10 -31
  80. package/realtime-testing/dist/index.js.map +1 -1
  81. package/realtime-testing/package.json +5 -5
  82. package/transceivers/set-rtx/dist/index.cjs +31 -10
  83. package/transceivers/set-rtx/dist/index.cjs.map +1 -1
  84. package/transceivers/set-rtx/dist/index.d.cts +29 -3
  85. package/transceivers/set-rtx/dist/index.js +2 -3
  86. package/transceivers/set-rtx/dist/index.js.map +1 -1
  87. package/transceivers/set-rtx/package.json +6 -6
  88. package/data/dist/index.d.ts +0 -158
  89. package/data/dist/metafile-cjs.json +0 -1
  90. package/data/dist/metafile-esm.json +0 -1
  91. package/dist/index.d.ts +0 -243
  92. package/dist/metafile-esm.json +0 -1
  93. package/internal/dist/index.d.ts +0 -421
  94. package/internal/dist/metafile-cjs.json +0 -1
  95. package/internal/dist/metafile-esm.json +0 -1
  96. package/introspection/dist/index.d.ts +0 -24
  97. package/introspection/dist/metafile-cjs.json +0 -1
  98. package/introspection/dist/metafile-esm.json +0 -1
  99. package/json/dist/index.d.ts +0 -51
  100. package/json/dist/metafile-cjs.json +0 -1
  101. package/json/dist/metafile-esm.json +0 -1
  102. package/react/dist/index.d.ts +0 -23
  103. package/react/dist/metafile-cjs.json +0 -1
  104. package/react/dist/metafile-esm.json +0 -1
  105. package/react-devtools/dist/index.d.ts +0 -341
  106. package/react-devtools/dist/metafile-cjs.json +0 -1
  107. package/react-devtools/dist/metafile-esm.json +0 -1
  108. package/realtime-client/dist/index.d.ts +0 -22
  109. package/realtime-client/dist/metafile-cjs.json +0 -1
  110. package/realtime-client/dist/metafile-esm.json +0 -1
  111. package/realtime-react/dist/index.d.ts +0 -27
  112. package/realtime-react/dist/metafile-cjs.json +0 -1
  113. package/realtime-react/dist/metafile-esm.json +0 -1
  114. package/realtime-server/dist/index.d.ts +0 -25
  115. package/realtime-server/dist/metafile-cjs.json +0 -1
  116. package/realtime-server/dist/metafile-esm.json +0 -1
  117. package/realtime-testing/dist/index.d.ts +0 -49
  118. package/realtime-testing/dist/metafile-cjs.json +0 -1
  119. package/realtime-testing/dist/metafile-esm.json +0 -1
  120. package/transceivers/set-rtx/dist/index.d.ts +0 -40
  121. package/transceivers/set-rtx/dist/metafile-cjs.json +0 -1
  122. package/transceivers/set-rtx/dist/metafile-esm.json +0 -1
@@ -1,27 +1,5 @@
1
1
  'use strict';
2
2
 
3
- var Internal = require('atom.io/internal');
4
-
5
- function _interopNamespace(e) {
6
- if (e && e.__esModule) return e;
7
- var n = Object.create(null);
8
- if (e) {
9
- Object.keys(e).forEach(function (k) {
10
- if (k !== 'default') {
11
- var d = Object.getOwnPropertyDescriptor(e, k);
12
- Object.defineProperty(n, k, d.get ? d : {
13
- enumerable: true,
14
- get: function () { return e[k]; }
15
- });
16
- }
17
- });
18
- }
19
- n.default = e;
20
- return Object.freeze(n);
21
- }
22
-
23
- var Internal__namespace = /*#__PURE__*/_interopNamespace(Internal);
24
-
25
3
  var __defProp = Object.defineProperty;
26
4
  var __defProps = Object.defineProperties;
27
5
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
@@ -41,8 +19,1592 @@ var __spreadValues = (a, b) => {
41
19
  return a;
42
20
  };
43
21
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
44
- var attachAtomIndex = (store = Internal.IMPLICIT.STORE) => {
45
- const atomTokenIndexState__INTERNAL = Internal.createAtom(
22
+
23
+ // src/get-state.ts
24
+ function getState(token, store = IMPLICIT.STORE) {
25
+ var _a;
26
+ const state = (_a = withdraw(token, store)) != null ? _a : withdrawNewFamilyMember(token, store);
27
+ if (state === void 0) {
28
+ throw new NotFoundError(token, store);
29
+ }
30
+ return readOrComputeValue(state, store);
31
+ }
32
+
33
+ // src/logger.ts
34
+ var simpleLog = (logLevel) => (icon, tokenType, tokenKey, message, ...rest) => {
35
+ console[logLevel](`${icon} ${tokenType} "${tokenKey}" ${message}`, ...rest);
36
+ };
37
+ var simpleLogger = {
38
+ error: simpleLog(`error`),
39
+ info: simpleLog(`info`),
40
+ warn: simpleLog(`warn`)
41
+ };
42
+ var AtomIOLogger = class {
43
+ constructor(logLevel, filter, logger = simpleLogger) {
44
+ this.logLevel = logLevel;
45
+ this.filter = filter;
46
+ this.logger = logger;
47
+ this.error = (...args) => {
48
+ var _a, _b;
49
+ if (((_b = (_a = this.filter) == null ? void 0 : _a.call(this, ...args)) != null ? _b : true) && this.logLevel !== null) {
50
+ this.logger.error(...args);
51
+ }
52
+ };
53
+ this.info = (...args) => {
54
+ var _a, _b;
55
+ if (((_b = (_a = this.filter) == null ? void 0 : _a.call(this, ...args)) != null ? _b : true) && this.logLevel === `info`) {
56
+ this.logger.info(...args);
57
+ }
58
+ };
59
+ this.warn = (...args) => {
60
+ var _a, _b;
61
+ if (((_b = (_a = this.filter) == null ? void 0 : _a.call(this, ...args)) != null ? _b : true) && this.logLevel !== `error` && this.logLevel !== null) {
62
+ this.logger.warn(...args);
63
+ }
64
+ };
65
+ }
66
+ };
67
+
68
+ // src/set-state.ts
69
+ function setState(token, value, store = IMPLICIT.STORE) {
70
+ var _a;
71
+ const rejection = openOperation(token, store);
72
+ if (rejection) {
73
+ return;
74
+ }
75
+ const state = (_a = withdraw(token, store)) != null ? _a : withdrawNewFamilyMember(token, store);
76
+ if (state === void 0) {
77
+ throw new NotFoundError(token, store);
78
+ }
79
+ setAtomOrSelector(state, value, store);
80
+ closeOperation(store);
81
+ }
82
+
83
+ // internal/src/future.ts
84
+ var Future = class extends Promise {
85
+ constructor(executor) {
86
+ super((resolve, reject) => {
87
+ const pass = (value) => this.isCanceled ? reject(`canceled`) : resolve(value);
88
+ const fail = (reason) => this.isCanceled ? reject(`canceled`) : reject(reason);
89
+ if (typeof executor === `function`) {
90
+ executor(pass, fail);
91
+ } else {
92
+ executor.then(pass, fail);
93
+ }
94
+ });
95
+ this.isCanceled = false;
96
+ }
97
+ cancel() {
98
+ this.isCanceled = true;
99
+ }
100
+ };
101
+
102
+ // internal/src/lineage.ts
103
+ function newest(scion) {
104
+ while (scion.child !== null) {
105
+ scion = scion.child;
106
+ }
107
+ return scion;
108
+ }
109
+
110
+ // internal/src/caching.ts
111
+ function cacheValue(key, value, subject, store) {
112
+ const target = newest(store);
113
+ const currentValue = target.valueMap.get(key);
114
+ if (currentValue instanceof Future) {
115
+ currentValue.cancel();
116
+ }
117
+ if (value instanceof Promise) {
118
+ const future = new Future(value);
119
+ newest(store).valueMap.set(key, future);
120
+ future.then((resolved) => {
121
+ if (future.isCanceled) {
122
+ return;
123
+ }
124
+ cacheValue(key, resolved, subject, store);
125
+ subject.next({ newValue: resolved, oldValue: future });
126
+ }).catch((thrown) => {
127
+ if (thrown !== `canceled`) {
128
+ store.logger.error(`\u{1F4A5}`, `state`, key, `rejected:`, thrown);
129
+ }
130
+ });
131
+ return future;
132
+ }
133
+ target.valueMap.set(key, value);
134
+ return value;
135
+ }
136
+ var readCachedValue = (key, store) => {
137
+ return newest(store).valueMap.get(key);
138
+ };
139
+ var isValueCached = (key, store) => {
140
+ return newest(store).valueMap.has(key);
141
+ };
142
+ var evictCachedValue = (key, store) => {
143
+ const core = newest(store);
144
+ const currentValue = core.valueMap.get(key);
145
+ if (currentValue instanceof Future) {
146
+ currentValue.cancel();
147
+ }
148
+ if (core.operation.open) {
149
+ core.operation.prev.set(key, currentValue);
150
+ }
151
+ core.valueMap.delete(key);
152
+ store.logger.info(`\u{1F5D1}`, `state`, key, `evicted`);
153
+ };
154
+
155
+ // ../anvl/src/json/index.ts
156
+ var stringifyJson = (json) => JSON.stringify(json);
157
+
158
+ // json/src/select-json.ts
159
+ var selectJson = (atom, transform, store = IMPLICIT.STORE) => {
160
+ return createSelector(
161
+ {
162
+ key: `${atom.key}:JSON`,
163
+ get: ({ get }) => transform.toJson(get(atom)),
164
+ set: ({ set }, newValue) => set(atom, transform.fromJson(newValue))
165
+ },
166
+ void 0,
167
+ store
168
+ );
169
+ };
170
+
171
+ // internal/src/read-or-compute-value.ts
172
+ var readOrComputeValue = (state, store) => {
173
+ if (isValueCached(state.key, store)) {
174
+ store.logger.info(`\u{1F4D6}`, state.type, state.key, `reading cached value`);
175
+ return readCachedValue(state.key, store);
176
+ }
177
+ if (state.type !== `atom`) {
178
+ store.logger.info(`\u{1F9EE}`, state.type, state.key, `computing value`);
179
+ return state.get();
180
+ }
181
+ const fallback = state.default instanceof Function ? state.default() : state.default;
182
+ store.logger.info(
183
+ `\u{1F481}`,
184
+ `atom`,
185
+ state.key,
186
+ `could not find cached value; using default`,
187
+ fallback
188
+ );
189
+ return state.default instanceof Function ? state.default() : state.default;
190
+ };
191
+
192
+ // internal/src/operation.ts
193
+ var openOperation = (token, store) => {
194
+ const target = newest(store);
195
+ if (target.operation.open) {
196
+ store.logger.error(
197
+ `\u274C`,
198
+ token.type,
199
+ token.key,
200
+ `failed to setState during a setState for "${target.operation.token.key}"`
201
+ );
202
+ return `rejection`;
203
+ }
204
+ target.operation = {
205
+ open: true,
206
+ done: /* @__PURE__ */ new Set(),
207
+ prev: /* @__PURE__ */ new Map(),
208
+ time: Date.now(),
209
+ token
210
+ };
211
+ store.logger.info(
212
+ `\u2B55`,
213
+ token.type,
214
+ token.key,
215
+ `operation start in store "${store.config.name}"${target.transactionMeta === null ? `` : ` ${target.transactionMeta.phase} "${target.transactionMeta.update.key}"`}`
216
+ );
217
+ };
218
+ var closeOperation = (store) => {
219
+ const target = newest(store);
220
+ if (target.operation.open) {
221
+ store.logger.info(
222
+ `\u{1F534}`,
223
+ target.operation.token.type,
224
+ target.operation.token.key,
225
+ `operation done in store "${store.config.name}"`
226
+ );
227
+ }
228
+ target.operation = { open: false };
229
+ store.subject.operationStatus.next(target.operation);
230
+ };
231
+ var isDone = (key, store) => {
232
+ const target = newest(store);
233
+ if (!target.operation.open) {
234
+ store.logger.warn(
235
+ `\u{1F41E}`,
236
+ `unknown`,
237
+ key,
238
+ `isDone called outside of an operation. This is probably a bug.`
239
+ );
240
+ return true;
241
+ }
242
+ return target.operation.done.has(key);
243
+ };
244
+ var markDone = (key, store) => {
245
+ const target = newest(store);
246
+ if (!target.operation.open) {
247
+ store.logger.warn(
248
+ `\u{1F41E}`,
249
+ `unknown`,
250
+ key,
251
+ `markDone called outside of an operation. This is probably a bug.`
252
+ );
253
+ return;
254
+ }
255
+ target.operation.done.add(key);
256
+ };
257
+
258
+ // internal/src/set-state/become.ts
259
+ var become = (nextVersionOfThing) => (originalThing) => nextVersionOfThing instanceof Function ? nextVersionOfThing(
260
+ originalThing instanceof Function ? originalThing() : originalThing
261
+ ) : nextVersionOfThing;
262
+
263
+ // internal/src/subject.ts
264
+ var Subject = class {
265
+ constructor() {
266
+ this.subscribers = /* @__PURE__ */ new Map();
267
+ }
268
+ subscribe(key, subscriber) {
269
+ this.subscribers.set(key, subscriber);
270
+ const unsubscribe = () => this.unsubscribe(key);
271
+ return unsubscribe;
272
+ }
273
+ unsubscribe(key) {
274
+ this.subscribers.delete(key);
275
+ }
276
+ next(value) {
277
+ for (const subscriber of this.subscribers.values()) {
278
+ subscriber(value);
279
+ }
280
+ }
281
+ };
282
+ var StatefulSubject = class extends Subject {
283
+ constructor(initialState) {
284
+ super();
285
+ this.state = initialState;
286
+ }
287
+ next(value) {
288
+ this.state = value;
289
+ super.next(value);
290
+ }
291
+ };
292
+
293
+ // internal/src/set-state/copy-mutable-if-needed.ts
294
+ function copyMutableIfNeeded(atom, transform, origin, target) {
295
+ const originValue = origin.valueMap.get(atom.key);
296
+ const targetValue = target.valueMap.get(atom.key);
297
+ if (originValue === targetValue) {
298
+ origin.logger.info(`\u{1F4C3}`, `atom`, `${atom.key}`, `copying`);
299
+ const jsonValue = transform.toJson(originValue);
300
+ const copiedValue = transform.fromJson(jsonValue);
301
+ target.valueMap.set(atom.key, copiedValue);
302
+ new Tracker(atom, origin);
303
+ return copiedValue;
304
+ }
305
+ return targetValue;
306
+ }
307
+
308
+ // internal/src/set-state/copy-mutable-in-transaction.ts
309
+ function copyMutableIfWithinTransaction(oldValue, atom, store) {
310
+ const target = newest(store);
311
+ const parent = target.parent;
312
+ if (parent !== null) {
313
+ if (`toJson` in atom && `fromJson` in atom) {
314
+ const copiedValue = copyMutableIfNeeded(atom, atom, parent, target);
315
+ return copiedValue;
316
+ }
317
+ if (`family` in atom) {
318
+ const family = parent.families.get(atom.family.key);
319
+ if (family && family.type === `atom_family`) {
320
+ const result = copyMutableFamilyMemberWithinTransaction(
321
+ atom,
322
+ family,
323
+ parent,
324
+ target
325
+ );
326
+ if (result) {
327
+ return result;
328
+ }
329
+ }
330
+ }
331
+ }
332
+ return oldValue;
333
+ }
334
+ function copyMutableFamilyMemberWithinTransaction(atom, family, origin, target) {
335
+ if (`toJson` in family && `fromJson` in family) {
336
+ const copyCreated = copyMutableIfNeeded(atom, family, origin, target);
337
+ return copyCreated;
338
+ }
339
+ return null;
340
+ }
341
+
342
+ // internal/src/set-state/emit-update.ts
343
+ var emitUpdate = (state, update, store) => {
344
+ store.logger.info(
345
+ `\u{1F4E2}`,
346
+ state.type,
347
+ state.key,
348
+ `went (`,
349
+ update.oldValue,
350
+ `->`,
351
+ update.newValue,
352
+ `) subscribers:`,
353
+ state.subject.subscribers
354
+ );
355
+ state.subject.next(update);
356
+ };
357
+
358
+ // internal/src/set-state/evict-downstream.ts
359
+ var evictDownStream = (atom, store) => {
360
+ const target = newest(store);
361
+ const downstreamKeys = target.selectorAtoms.getRelatedKeys(atom.key);
362
+ store.logger.info(
363
+ `\u{1F9F9}`,
364
+ atom.type,
365
+ atom.key,
366
+ downstreamKeys ? `evicting ${downstreamKeys.size} states downstream:` : `no downstream states`,
367
+ downstreamKeys != null ? downstreamKeys : `to evict`
368
+ );
369
+ if (downstreamKeys) {
370
+ if (target.operation.open) {
371
+ store.logger.info(
372
+ `\u{1F9F9}`,
373
+ atom.type,
374
+ atom.key,
375
+ `[ ${[...target.operation.done].join(`, `)} ] already done`
376
+ );
377
+ }
378
+ for (const key of downstreamKeys) {
379
+ if (isDone(key, store)) {
380
+ continue;
381
+ }
382
+ evictCachedValue(key, store);
383
+ markDone(key, store);
384
+ }
385
+ }
386
+ };
387
+
388
+ // internal/src/set-state/stow-update.ts
389
+ function shouldUpdateBeStowed(key, update) {
390
+ if (isTransceiver(update.newValue)) {
391
+ return false;
392
+ }
393
+ if (key.includes(`\u{1F441}\u200D\u{1F5E8}`)) {
394
+ return false;
395
+ }
396
+ return true;
397
+ }
398
+ var stowUpdate = (state, update, store) => {
399
+ const { key } = state;
400
+ const target = newest(store);
401
+ if (target.transactionMeta === null || target.transactionMeta.phase !== `building`) {
402
+ store.logger.error(
403
+ `\u{1F41E}`,
404
+ `atom`,
405
+ key,
406
+ `stowUpdate called outside of a transaction. This is probably a bug.`
407
+ );
408
+ return;
409
+ }
410
+ const shouldStow = shouldUpdateBeStowed(key, update);
411
+ if (!shouldStow) {
412
+ return;
413
+ }
414
+ const atomUpdate = __spreadValues({ key }, update);
415
+ if (state.family) {
416
+ atomUpdate.family = state.family;
417
+ }
418
+ target.transactionMeta.update.updates.push(atomUpdate);
419
+ store.logger.info(
420
+ `\u{1F4C1}`,
421
+ `atom`,
422
+ key,
423
+ `stowed (`,
424
+ update.oldValue,
425
+ `->`,
426
+ update.newValue,
427
+ `)`
428
+ );
429
+ };
430
+
431
+ // internal/src/set-state/set-atom.ts
432
+ var setAtom = (atom, next, store) => {
433
+ const target = newest(store);
434
+ const oldValue = readOrComputeValue(atom, store);
435
+ let newValue = copyMutableIfWithinTransaction(oldValue, atom, store);
436
+ newValue = become(next)(newValue);
437
+ store.logger.info(`\u{1F4DD}`, `atom`, atom.key, `set to`, newValue);
438
+ newValue = cacheValue(atom.key, newValue, atom.subject, store);
439
+ if (isAtomDefault(atom.key, store)) {
440
+ markAtomAsNotDefault(atom.key, store);
441
+ }
442
+ markDone(atom.key, store);
443
+ evictDownStream(atom, store);
444
+ const update = { oldValue, newValue };
445
+ if (target.transactionMeta === null || target.transactionMeta.phase === `applying`) {
446
+ emitUpdate(atom, update, store);
447
+ } else {
448
+ stowUpdate(atom, update, store);
449
+ }
450
+ };
451
+
452
+ // internal/src/set-state/set-atom-or-selector.ts
453
+ var setAtomOrSelector = (state, value, store) => {
454
+ if (state.type === `selector`) {
455
+ state.set(value);
456
+ } else {
457
+ setAtom(state, value, store);
458
+ }
459
+ };
460
+
461
+ // internal/src/store/deposit.ts
462
+ function deposit(state) {
463
+ const token = {
464
+ key: state.key,
465
+ type: state.type
466
+ };
467
+ if (`family` in state) {
468
+ token.family = state.family;
469
+ }
470
+ return token;
471
+ }
472
+
473
+ // ../rel8/junction/src/junction.ts
474
+ var Junction = class {
475
+ constructor(data, config) {
476
+ this.relations = /* @__PURE__ */ new Map();
477
+ this.contents = /* @__PURE__ */ new Map();
478
+ this.makeContentKey = (a, b) => `${a}:${b}`;
479
+ var _a, _b, _c, _d;
480
+ this.a = data.between[0];
481
+ this.b = data.between[1];
482
+ this.cardinality = data.cardinality;
483
+ if (!(config == null ? void 0 : config.externalStore)) {
484
+ this.relations = new Map((_a = data.relations) == null ? void 0 : _a.map(([a, b]) => [a, new Set(b)]));
485
+ this.contents = new Map(data.contents);
486
+ }
487
+ this.isContent = (_b = config == null ? void 0 : config.isContent) != null ? _b : null;
488
+ if (config == null ? void 0 : config.makeContentKey) {
489
+ this.makeContentKey = config.makeContentKey;
490
+ }
491
+ if (config == null ? void 0 : config.externalStore) {
492
+ const externalStore = config.externalStore;
493
+ this.has = (a, b) => externalStore.has(a, b);
494
+ this.addRelation = (a, b) => {
495
+ externalStore.addRelation(a, b);
496
+ };
497
+ this.deleteRelation = (a, b) => {
498
+ externalStore.deleteRelation(a, b);
499
+ };
500
+ this.replaceRelationsSafely = (a, bs) => {
501
+ externalStore.replaceRelationsSafely(a, bs);
502
+ };
503
+ this.replaceRelationsUnsafely = (a, bs) => {
504
+ externalStore.replaceRelationsUnsafely(a, bs);
505
+ };
506
+ this.getRelatedKeys = (key) => externalStore.getRelatedKeys(key);
507
+ if (externalStore.getContent) {
508
+ this.getContentInternal = (contentKey) => {
509
+ return externalStore.getContent(contentKey);
510
+ };
511
+ this.setContent = (contentKey, content) => {
512
+ externalStore.setContent(contentKey, content);
513
+ };
514
+ this.deleteContent = (contentKey) => {
515
+ externalStore.deleteContent(contentKey);
516
+ };
517
+ }
518
+ for (const [x, ys] of (_c = data.relations) != null ? _c : []) {
519
+ for (const y of ys)
520
+ this.addRelation(x, y);
521
+ }
522
+ for (const [contentKey, content] of (_d = data.contents) != null ? _d : []) {
523
+ this.setContent(contentKey, content);
524
+ }
525
+ }
526
+ }
527
+ getRelatedKeys(key) {
528
+ return this.relations.get(key);
529
+ }
530
+ addRelation(a, b) {
531
+ let aRelations = this.relations.get(a);
532
+ let bRelations = this.relations.get(b);
533
+ if (aRelations) {
534
+ aRelations.add(b);
535
+ } else {
536
+ aRelations = /* @__PURE__ */ new Set([b]);
537
+ this.relations.set(a, aRelations);
538
+ }
539
+ if (bRelations) {
540
+ bRelations.add(a);
541
+ } else {
542
+ bRelations = /* @__PURE__ */ new Set([a]);
543
+ this.relations.set(b, bRelations);
544
+ }
545
+ }
546
+ deleteRelation(a, b) {
547
+ const aRelations = this.relations.get(a);
548
+ if (aRelations) {
549
+ aRelations.delete(b);
550
+ if (aRelations.size === 0) {
551
+ this.relations.delete(a);
552
+ }
553
+ const bRelations = this.relations.get(b);
554
+ if (bRelations) {
555
+ bRelations.delete(a);
556
+ if (bRelations.size === 0) {
557
+ this.relations.delete(b);
558
+ }
559
+ }
560
+ }
561
+ }
562
+ replaceRelationsUnsafely(a, bs) {
563
+ this.relations.set(a, new Set(bs));
564
+ for (const b of bs) {
565
+ const bRelations = /* @__PURE__ */ new Set([a]);
566
+ this.relations.set(b, bRelations);
567
+ }
568
+ }
569
+ replaceRelationsSafely(a, bs) {
570
+ const aRelationsPrev = this.relations.get(a);
571
+ if (aRelationsPrev) {
572
+ for (const b of aRelationsPrev) {
573
+ const bRelations = this.relations.get(b);
574
+ if (bRelations) {
575
+ if (bRelations.size === 1) {
576
+ this.relations.delete(b);
577
+ } else {
578
+ bRelations.delete(a);
579
+ }
580
+ this.contents.delete(this.makeContentKey(a, b));
581
+ }
582
+ }
583
+ }
584
+ this.relations.set(a, new Set(bs));
585
+ for (const b of bs) {
586
+ let bRelations = this.relations.get(b);
587
+ if (bRelations) {
588
+ bRelations.add(a);
589
+ } else {
590
+ bRelations = /* @__PURE__ */ new Set([a]);
591
+ this.relations.set(b, bRelations);
592
+ }
593
+ }
594
+ }
595
+ getContentInternal(contentKey) {
596
+ return this.contents.get(contentKey);
597
+ }
598
+ setContent(contentKey, content) {
599
+ this.contents.set(contentKey, content);
600
+ }
601
+ deleteContent(contentKey) {
602
+ this.contents.delete(contentKey);
603
+ }
604
+ toJSON() {
605
+ return {
606
+ between: [this.a, this.b],
607
+ cardinality: this.cardinality,
608
+ relations: [...this.relations.entries()].map(([a, b]) => [a, [...b]]),
609
+ contents: [...this.contents.entries()]
610
+ };
611
+ }
612
+ set(a, ...rest) {
613
+ var _a;
614
+ const b = typeof rest[0] === `string` ? rest[0] : a[this.b];
615
+ const content = ((_a = rest[1]) != null ? _a : typeof rest[0] === `string`) ? void 0 : rest[0];
616
+ a = typeof a === `string` ? a : a[this.a];
617
+ switch (this.cardinality) {
618
+ case `1:1`: {
619
+ const bPrev = this.getRelatedKey(a);
620
+ if (bPrev && bPrev !== b)
621
+ this.delete(bPrev, a);
622
+ }
623
+ case `1:n`: {
624
+ const aPrev = this.getRelatedKey(b);
625
+ if (aPrev && aPrev !== a)
626
+ this.delete(aPrev, b);
627
+ }
628
+ }
629
+ if (content) {
630
+ const contentKey = this.makeContentKey(a, b);
631
+ this.setContent(contentKey, content);
632
+ }
633
+ this.addRelation(a, b);
634
+ return this;
635
+ }
636
+ delete(x, b) {
637
+ b = typeof b === `string` ? b : x[this.b];
638
+ const a = typeof x === `string` ? x : x[this.a];
639
+ if (a === void 0 && typeof b === `string`) {
640
+ const bRelations = this.getRelatedKeys(b);
641
+ if (bRelations) {
642
+ for (const a2 of bRelations) {
643
+ this.delete(a2, b);
644
+ }
645
+ }
646
+ }
647
+ if (typeof a === `string` && b === void 0) {
648
+ const aRelations = this.getRelatedKeys(a);
649
+ if (aRelations) {
650
+ for (const b2 of aRelations) {
651
+ this.delete(a, b2);
652
+ }
653
+ }
654
+ }
655
+ if (typeof a === `string` && typeof b === `string`) {
656
+ this.deleteRelation(a, b);
657
+ const contentKey = this.makeContentKey(a, b);
658
+ this.deleteContent(contentKey);
659
+ }
660
+ return this;
661
+ }
662
+ getRelatedKey(key) {
663
+ const relations = this.getRelatedKeys(key);
664
+ if (relations) {
665
+ if (relations.size > 1) {
666
+ console.warn(
667
+ `${relations.size} related keys were found for key "${key}": (${[
668
+ ...relations
669
+ ].map((k) => `"${k}"`).join(`, `)}). Only one related key was expected.`
670
+ );
671
+ }
672
+ for (const relation of relations) {
673
+ return relation;
674
+ }
675
+ }
676
+ }
677
+ replaceRelations(a, relations, config) {
678
+ const hasContent = !Array.isArray(relations);
679
+ const bs = hasContent ? Object.keys(relations) : relations;
680
+ if (config == null ? void 0 : config.reckless) {
681
+ this.replaceRelationsUnsafely(a, bs);
682
+ } else {
683
+ this.replaceRelationsSafely(a, bs);
684
+ }
685
+ if (hasContent) {
686
+ for (const b of bs) {
687
+ const contentKey = this.makeContentKey(a, b);
688
+ const content = relations[b];
689
+ this.setContent(contentKey, content);
690
+ }
691
+ }
692
+ return this;
693
+ }
694
+ getContent(a, b) {
695
+ const contentKey = this.makeContentKey(a, b);
696
+ return this.getContentInternal(contentKey);
697
+ }
698
+ getRelationEntries(input) {
699
+ const a = input[this.a];
700
+ const b = input[this.b];
701
+ if (a !== void 0 && b === void 0) {
702
+ const aRelations = this.getRelatedKeys(a);
703
+ if (aRelations) {
704
+ return [...aRelations].map((b2) => {
705
+ var _a;
706
+ return [b2, (_a = this.getContent(a, b2)) != null ? _a : null];
707
+ });
708
+ }
709
+ }
710
+ if (a === void 0 && b !== void 0) {
711
+ const bRelations = this.getRelatedKeys(b);
712
+ if (bRelations) {
713
+ return [...bRelations].map((a2) => {
714
+ var _a;
715
+ return [a2, (_a = this.getContent(a2, b)) != null ? _a : null];
716
+ });
717
+ }
718
+ }
719
+ return [];
720
+ }
721
+ has(a, b) {
722
+ var _a;
723
+ if (b) {
724
+ const setA = this.getRelatedKeys(a);
725
+ return (_a = setA == null ? void 0 : setA.has(b)) != null ? _a : false;
726
+ }
727
+ return this.relations.has(a);
728
+ }
729
+ };
730
+
731
+ // internal/src/store/store.ts
732
+ var Store = class {
733
+ constructor(name, store = null) {
734
+ this.parent = null;
735
+ this.child = null;
736
+ this.valueMap = /* @__PURE__ */ new Map();
737
+ this.atoms = /* @__PURE__ */ new Map();
738
+ this.selectors = /* @__PURE__ */ new Map();
739
+ this.readonlySelectors = /* @__PURE__ */ new Map();
740
+ this.trackers = /* @__PURE__ */ new Map();
741
+ this.families = /* @__PURE__ */ new Map();
742
+ this.timelines = /* @__PURE__ */ new Map();
743
+ this.transactions = /* @__PURE__ */ new Map();
744
+ this.atomsThatAreDefault = /* @__PURE__ */ new Set();
745
+ this.timelineAtoms = new Junction({
746
+ between: [`timelineKey`, `atomKey`],
747
+ cardinality: `1:n`
748
+ });
749
+ this.selectorAtoms = new Junction({
750
+ between: [`selectorKey`, `atomKey`],
751
+ cardinality: `n:n`
752
+ });
753
+ this.selectorGraph = new Junction(
754
+ {
755
+ between: [`upstreamSelectorKey`, `downstreamSelectorKey`],
756
+ cardinality: `n:n`
757
+ },
758
+ {
759
+ makeContentKey: (...keys) => keys.sort().join(`:`)
760
+ }
761
+ );
762
+ this.subject = {
763
+ atomCreation: new Subject(),
764
+ selectorCreation: new Subject(),
765
+ transactionCreation: new Subject(),
766
+ timelineCreation: new Subject(),
767
+ transactionApplying: new StatefulSubject(null),
768
+ operationStatus: new Subject()
769
+ };
770
+ this.operation = { open: false };
771
+ this.transactionMeta = null;
772
+ this.config = {
773
+ name: `IMPLICIT_STORE`
774
+ };
775
+ this.loggers = [
776
+ new AtomIOLogger(`warn`, (_, __, key) => !key.includes(`\u{1F441}\u200D\u{1F5E8}`))
777
+ ];
778
+ this.logger = {
779
+ error: (...messages) => {
780
+ for (const logger of this.loggers)
781
+ logger.error(...messages);
782
+ },
783
+ info: (...messages) => {
784
+ for (const logger of this.loggers)
785
+ logger.info(...messages);
786
+ },
787
+ warn: (...messages) => {
788
+ for (const logger of this.loggers)
789
+ logger.warn(...messages);
790
+ }
791
+ };
792
+ if (store !== null) {
793
+ this.valueMap = new Map(store == null ? void 0 : store.valueMap);
794
+ this.operation = __spreadValues({}, store == null ? void 0 : store.operation);
795
+ this.transactionMeta = (store == null ? void 0 : store.transactionMeta) ? __spreadValues({}, store == null ? void 0 : store.transactionMeta) : null;
796
+ this.config = __spreadProps(__spreadValues({}, store == null ? void 0 : store.config), {
797
+ name
798
+ });
799
+ for (const [, atom] of store.atoms) {
800
+ atom.install(this);
801
+ }
802
+ for (const [, selector] of store.readonlySelectors) {
803
+ selector.install(this);
804
+ }
805
+ for (const [, selector] of store.selectors) {
806
+ selector.install(this);
807
+ }
808
+ for (const [, tx] of store.transactions) {
809
+ tx.install(this);
810
+ }
811
+ for (const [, timeline] of store.timelines) {
812
+ timeline.install(this);
813
+ }
814
+ }
815
+ }
816
+ };
817
+ var IMPLICIT = {
818
+ STORE_INTERNAL: void 0,
819
+ get STORE() {
820
+ var _a;
821
+ return (_a = this.STORE_INTERNAL) != null ? _a : this.STORE_INTERNAL = new Store(`IMPLICIT_STORE`);
822
+ }
823
+ };
824
+
825
+ // internal/src/store/withdraw.ts
826
+ function withdraw(token, store) {
827
+ var _a, _b, _c, _d;
828
+ const target = newest(store);
829
+ const state = (_d = (_c = (_b = (_a = target.atoms.get(token.key)) != null ? _a : target.selectors.get(token.key)) != null ? _b : target.readonlySelectors.get(token.key)) != null ? _c : target.transactions.get(token.key)) != null ? _d : target.timelines.get(token.key);
830
+ if (state) {
831
+ return state;
832
+ }
833
+ return void 0;
834
+ }
835
+
836
+ // internal/src/store/withdraw-new-family-member.ts
837
+ function withdrawNewFamilyMember(token, store) {
838
+ if (token.family) {
839
+ store.logger.info(
840
+ `\u{1F46A}`,
841
+ token.type,
842
+ token.key,
843
+ `creating new family member in store "${store.config.name}"`
844
+ );
845
+ const target = newest(store);
846
+ const family = target.families.get(token.family.key);
847
+ if (family) {
848
+ const jsonSubKey = JSON.parse(token.family.subKey);
849
+ family(jsonSubKey);
850
+ const state = withdraw(token, store);
851
+ return state;
852
+ }
853
+ }
854
+ return void 0;
855
+ }
856
+
857
+ // internal/src/keys.ts
858
+ var isAtomKey = (key, store) => newest(store).atoms.has(key);
859
+ var isSelectorKey = (key, store) => newest(store).selectors.has(key);
860
+ var isReadonlySelectorKey = (key, store) => newest(store).readonlySelectors.has(key);
861
+ var isStateKey = (key, store) => isAtomKey(key, store) || isSelectorKey(key, store) || isReadonlySelectorKey(key, store);
862
+
863
+ // internal/src/selector/get-selector-dependency-keys.ts
864
+ var getSelectorDependencyKeys = (key, store) => {
865
+ const sources = newest(store).selectorGraph.getRelationEntries({ downstreamSelectorKey: key }).filter(([_, { source }]) => source !== key).map(([_, { source }]) => source).filter((source) => isStateKey(source, store));
866
+ return sources;
867
+ };
868
+
869
+ // internal/src/selector/trace-selector-atoms.ts
870
+ var traceSelectorAtoms = (selectorKey, directDependencyKey, store) => {
871
+ const rootKeys = [];
872
+ const indirectDependencyKeys = getSelectorDependencyKeys(
873
+ directDependencyKey,
874
+ store
875
+ );
876
+ let depth = 0;
877
+ while (indirectDependencyKeys.length > 0) {
878
+ const indirectDependencyKey = indirectDependencyKeys.shift();
879
+ ++depth;
880
+ if (depth > 99999) {
881
+ throw new Error(
882
+ `Maximum selector dependency depth exceeded (> 99999) in selector "${selectorKey}". This is likely due to a circular dependency.`
883
+ );
884
+ }
885
+ if (!isAtomKey(indirectDependencyKey, store)) {
886
+ indirectDependencyKeys.push(
887
+ ...getSelectorDependencyKeys(indirectDependencyKey, store)
888
+ );
889
+ } else if (!rootKeys.includes(indirectDependencyKey)) {
890
+ rootKeys.push(indirectDependencyKey);
891
+ }
892
+ }
893
+ return rootKeys;
894
+ };
895
+ var traceAllSelectorAtoms = (selectorKey, store) => {
896
+ const directDependencyKeys = getSelectorDependencyKeys(selectorKey, store);
897
+ return directDependencyKeys.flatMap(
898
+ (depKey) => isAtomKey(depKey, store) ? depKey : traceSelectorAtoms(selectorKey, depKey, store)
899
+ );
900
+ };
901
+
902
+ // internal/src/selector/update-selector-atoms.ts
903
+ var updateSelectorAtoms = (selectorKey, dependency, store) => {
904
+ const target = newest(store);
905
+ if (dependency.type === `atom`) {
906
+ target.selectorAtoms.set({
907
+ selectorKey,
908
+ atomKey: dependency.key
909
+ });
910
+ store.logger.info(
911
+ `\u{1F50D}`,
912
+ `selector`,
913
+ selectorKey,
914
+ `discovers root atom "${dependency.key}"`
915
+ );
916
+ } else {
917
+ const rootKeys = traceSelectorAtoms(selectorKey, dependency.key, store);
918
+ store.logger.info(
919
+ `\u{1F50D}`,
920
+ `selector`,
921
+ selectorKey,
922
+ `discovers root atoms: [ ${rootKeys.map((key) => `"${key}"`).join(`, `)} ]`
923
+ );
924
+ for (const atomKey of rootKeys) {
925
+ target.selectorAtoms = target.selectorAtoms.set({
926
+ selectorKey,
927
+ atomKey
928
+ });
929
+ }
930
+ }
931
+ };
932
+
933
+ // internal/src/selector/register-selector.ts
934
+ var registerSelector = (selectorKey, store) => ({
935
+ get: (dependency) => {
936
+ const target = newest(store);
937
+ const alreadyRegistered = target.selectorGraph.getRelationEntries({ downstreamSelectorKey: selectorKey }).some(([_, { source }]) => source === dependency.key);
938
+ const dependencyState = withdraw(dependency, store);
939
+ if (dependencyState === void 0) {
940
+ throw new Error(
941
+ `State "${dependency.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`
942
+ );
943
+ }
944
+ const dependencyValue = readOrComputeValue(dependencyState, store);
945
+ store.logger.info(
946
+ `\u{1F50C}`,
947
+ `selector`,
948
+ selectorKey,
949
+ `registers dependency ( "${dependency.key}" =`,
950
+ dependencyValue,
951
+ `)`
952
+ );
953
+ if (!alreadyRegistered) {
954
+ target.selectorGraph.set(
955
+ {
956
+ upstreamSelectorKey: dependency.key,
957
+ downstreamSelectorKey: selectorKey
958
+ },
959
+ {
960
+ source: dependency.key
961
+ }
962
+ );
963
+ }
964
+ updateSelectorAtoms(selectorKey, dependency, store);
965
+ return dependencyValue;
966
+ },
967
+ set: (stateToken, newValue) => {
968
+ const state = withdraw(stateToken, store);
969
+ if (state === void 0) {
970
+ throw new Error(
971
+ `State "${stateToken.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`
972
+ );
973
+ }
974
+ setAtomOrSelector(state, newValue, store);
975
+ }
976
+ });
977
+
978
+ // internal/src/selector/create-read-write-selector.ts
979
+ var createReadWriteSelector = (options, family, store) => {
980
+ const target = newest(store);
981
+ const subject = new Subject();
982
+ const { get, set } = registerSelector(options.key, store);
983
+ const getSelf = () => {
984
+ const value = options.get({ get });
985
+ cacheValue(options.key, value, subject, store);
986
+ return value;
987
+ };
988
+ const setSelf = (next) => {
989
+ const oldValue = getSelf();
990
+ const newValue = become(next)(oldValue);
991
+ store.logger.info(
992
+ `\u{1F4DD}`,
993
+ `selector`,
994
+ options.key,
995
+ `set (`,
996
+ oldValue,
997
+ `->`,
998
+ newValue,
999
+ `)`
1000
+ );
1001
+ cacheValue(options.key, newValue, subject, store);
1002
+ markDone(options.key, store);
1003
+ if (target.transactionMeta === null) {
1004
+ subject.next({ newValue, oldValue });
1005
+ }
1006
+ options.set({ get, set }, newValue);
1007
+ };
1008
+ const mySelector = __spreadValues(__spreadProps(__spreadValues({}, options), {
1009
+ subject,
1010
+ install: (s) => createSelector(options, family, s),
1011
+ get: getSelf,
1012
+ set: setSelf,
1013
+ type: `selector`
1014
+ }), family && { family });
1015
+ target.selectors.set(options.key, mySelector);
1016
+ const initialValue = getSelf();
1017
+ store.logger.info(`\u2728`, mySelector.type, mySelector.key, `=`, initialValue);
1018
+ const token = {
1019
+ key: options.key,
1020
+ type: `selector`
1021
+ };
1022
+ if (family) {
1023
+ token.family = family;
1024
+ }
1025
+ store.subject.selectorCreation.next(token);
1026
+ return token;
1027
+ };
1028
+
1029
+ // internal/src/selector/create-readonly-selector.ts
1030
+ var createReadonlySelector = (options, family, store) => {
1031
+ const target = newest(store);
1032
+ const subject = new Subject();
1033
+ const { get } = registerSelector(options.key, store);
1034
+ const getSelf = () => {
1035
+ const value = options.get({ get });
1036
+ cacheValue(options.key, value, subject, store);
1037
+ return value;
1038
+ };
1039
+ const readonlySelector = __spreadValues(__spreadProps(__spreadValues({}, options), {
1040
+ subject,
1041
+ install: (s) => createSelector(options, family, s),
1042
+ get: getSelf,
1043
+ type: `readonly_selector`
1044
+ }), family && { family });
1045
+ target.readonlySelectors.set(options.key, readonlySelector);
1046
+ const initialValue = getSelf();
1047
+ store.logger.info(
1048
+ `\u2728`,
1049
+ readonlySelector.type,
1050
+ readonlySelector.key,
1051
+ `=`,
1052
+ initialValue
1053
+ );
1054
+ const token = {
1055
+ key: options.key,
1056
+ type: `readonly_selector`
1057
+ };
1058
+ if (family) {
1059
+ token.family = family;
1060
+ }
1061
+ store.subject.selectorCreation.next(token);
1062
+ return token;
1063
+ };
1064
+
1065
+ // internal/src/selector/create-selector.ts
1066
+ function createSelector(options, family, store) {
1067
+ const target = newest(store);
1068
+ const existingWritable = target.selectors.get(options.key);
1069
+ const existingReadonly = target.readonlySelectors.get(options.key);
1070
+ if (existingWritable || existingReadonly) {
1071
+ store.logger.error(
1072
+ `\u274C`,
1073
+ existingReadonly ? `readonly_selector` : `selector`,
1074
+ options.key,
1075
+ `Tried to create selector, but it already exists in the store. (Ignore if you are in development using hot module replacement.)`
1076
+ );
1077
+ }
1078
+ if (`set` in options) {
1079
+ return createReadWriteSelector(options, family, store);
1080
+ }
1081
+ return createReadonlySelector(options, family, store);
1082
+ }
1083
+
1084
+ // internal/src/selector/delete-selector.ts
1085
+ function deleteSelector(selectorToken, store) {
1086
+ const target = newest(store);
1087
+ const { key } = selectorToken;
1088
+ switch (selectorToken.type) {
1089
+ case `selector`:
1090
+ target.selectors.delete(key);
1091
+ break;
1092
+ case `readonly_selector`:
1093
+ target.readonlySelectors.delete(key);
1094
+ break;
1095
+ }
1096
+ target.valueMap.delete(key);
1097
+ target.selectorAtoms.delete(key);
1098
+ const downstreamTokens = target.selectorGraph.getRelationEntries({ upstreamSelectorKey: key }).filter(([_, { source }]) => source === key).map(
1099
+ ([downstreamSelectorKey]) => {
1100
+ var _a;
1101
+ return (_a = target.selectors.get(downstreamSelectorKey)) != null ? _a : target.readonlySelectors.get(downstreamSelectorKey);
1102
+ }
1103
+ );
1104
+ for (const downstreamToken of downstreamTokens) {
1105
+ if (downstreamToken) {
1106
+ deleteSelector(downstreamToken, store);
1107
+ }
1108
+ }
1109
+ target.selectorGraph.delete(key);
1110
+ store.logger.info(`\u{1F525}`, selectorToken.type, `${key}`, `deleted`);
1111
+ }
1112
+
1113
+ // internal/src/subscribe/recall-state.ts
1114
+ var recallState = (state, store) => {
1115
+ const target = newest(store);
1116
+ if (!target.operation.open) {
1117
+ return target.valueMap.get(state.key);
1118
+ }
1119
+ return target.operation.prev.get(state.key);
1120
+ };
1121
+
1122
+ // internal/src/subscribe/subscribe-to-root-atoms.ts
1123
+ var subscribeToRootAtoms = (state, store) => {
1124
+ const dependencySubscriptions = `default` in state ? null : traceAllSelectorAtoms(state.key, store).map((atomKey) => {
1125
+ const atom = store.atoms.get(atomKey);
1126
+ if (atom === void 0) {
1127
+ throw new Error(
1128
+ `Atom "${atomKey}", a dependency of selector "${state.key}", not found in store "${store.config.name}".`
1129
+ );
1130
+ }
1131
+ return atom.subject.subscribe(
1132
+ `${state.type}:${state.key}`,
1133
+ (atomChange) => {
1134
+ store.logger.info(
1135
+ `\u{1F4E2}`,
1136
+ state.type,
1137
+ state.key,
1138
+ `root`,
1139
+ atomKey,
1140
+ `went`,
1141
+ atomChange.oldValue,
1142
+ `->`,
1143
+ atomChange.newValue
1144
+ );
1145
+ const oldValue = recallState(state, store);
1146
+ const newValue = readOrComputeValue(state, store);
1147
+ store.logger.info(
1148
+ `\u2728`,
1149
+ state.type,
1150
+ state.key,
1151
+ `went`,
1152
+ oldValue,
1153
+ `->`,
1154
+ newValue
1155
+ );
1156
+ state.subject.next({ newValue, oldValue });
1157
+ }
1158
+ );
1159
+ });
1160
+ return dependencySubscriptions;
1161
+ };
1162
+
1163
+ // internal/src/subscribe/subscribe-to-state.ts
1164
+ function subscribeToState(token, handleUpdate, key, store) {
1165
+ const state = withdraw(token, store);
1166
+ if (state === void 0) {
1167
+ throw new Error(
1168
+ `State "${token.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`
1169
+ );
1170
+ }
1171
+ const unsubFunction = state.subject.subscribe(key, handleUpdate);
1172
+ store.logger.info(`\u{1F440}`, state.type, state.key, `Adding subscription "${key}"`);
1173
+ const dependencyUnsubFunctions = state.type !== `atom` ? subscribeToRootAtoms(state, store) : null;
1174
+ const unsubscribe = dependencyUnsubFunctions === null ? () => {
1175
+ store.logger.info(
1176
+ `\u{1F648}`,
1177
+ state.type,
1178
+ state.key,
1179
+ `Removing subscription "${key}"`
1180
+ );
1181
+ unsubFunction();
1182
+ } : () => {
1183
+ store.logger.info(
1184
+ `\u{1F648}`,
1185
+ state.type,
1186
+ state.key,
1187
+ `Removing subscription "${key}"`
1188
+ );
1189
+ unsubFunction();
1190
+ for (const unsubFromDependency of dependencyUnsubFunctions) {
1191
+ unsubFromDependency();
1192
+ }
1193
+ };
1194
+ return unsubscribe;
1195
+ }
1196
+
1197
+ // internal/src/subscribe/subscribe-to-timeline.ts
1198
+ var subscribeToTimeline = (token, handleUpdate, key, store) => {
1199
+ const tl = withdraw(token, store);
1200
+ if (tl === void 0) {
1201
+ throw new Error(
1202
+ `Cannot subscribe to timeline "${token.key}": timeline not found in store "${store.config.name}".`
1203
+ );
1204
+ }
1205
+ store.logger.info(`\u{1F440}`, `timeline`, token.key, `Adding subscription "${key}"`);
1206
+ const unsubscribe = tl.subject.subscribe(key, handleUpdate);
1207
+ return () => {
1208
+ store.logger.info(
1209
+ `\u{1F648}`,
1210
+ `timeline`,
1211
+ token.key,
1212
+ `Removing subscription "${key}" from timeline`
1213
+ );
1214
+ unsubscribe();
1215
+ };
1216
+ };
1217
+
1218
+ // internal/src/mutable/tracker.ts
1219
+ var Tracker = class {
1220
+ constructor(mutableState, store) {
1221
+ this.unsubscribeFromInnerValue = null;
1222
+ this.mutableState = mutableState;
1223
+ const target = newest(store);
1224
+ this.latestUpdateState = this.initializeState(mutableState, target);
1225
+ this.observeCore(mutableState, this.latestUpdateState, target);
1226
+ this.updateCore(mutableState, this.latestUpdateState, target);
1227
+ target.trackers.set(mutableState.key, this);
1228
+ }
1229
+ initializeState(mutableState, store) {
1230
+ const latestUpdateStateKey = `*${mutableState.key}`;
1231
+ deleteAtom({ type: `atom`, key: latestUpdateStateKey }, store);
1232
+ const familyMetaData = mutableState.family ? {
1233
+ key: `*${mutableState.family.key}`,
1234
+ subKey: mutableState.family.subKey
1235
+ } : void 0;
1236
+ const latestUpdateState = createAtom(
1237
+ {
1238
+ key: latestUpdateStateKey,
1239
+ default: null
1240
+ },
1241
+ familyMetaData,
1242
+ store
1243
+ );
1244
+ return latestUpdateState;
1245
+ }
1246
+ observeCore(mutableState, latestUpdateState, store) {
1247
+ const originalInnerValue = getState(mutableState, store);
1248
+ const target = newest(store);
1249
+ this.unsubscribeFromInnerValue = originalInnerValue.subscribe(
1250
+ `tracker:${store.config.name}:${target.transactionMeta === null ? `main` : target.transactionMeta.update.key}`,
1251
+ (update) => {
1252
+ const unsubscribe = store.subject.operationStatus.subscribe(
1253
+ mutableState.key,
1254
+ () => {
1255
+ unsubscribe();
1256
+ setState(latestUpdateState, update, store);
1257
+ }
1258
+ );
1259
+ }
1260
+ );
1261
+ subscribeToState(
1262
+ mutableState,
1263
+ (update) => {
1264
+ var _a;
1265
+ if (update.newValue !== update.oldValue) {
1266
+ (_a = this.unsubscribeFromInnerValue) == null ? void 0 : _a.call(this);
1267
+ const target2 = newest(store);
1268
+ this.unsubscribeFromInnerValue = update.newValue.subscribe(
1269
+ `tracker:${store.config.name}:${target2.transactionMeta === null ? `main` : target2.transactionMeta.update.key}`,
1270
+ (update2) => {
1271
+ const unsubscribe = store.subject.operationStatus.subscribe(
1272
+ mutableState.key,
1273
+ () => {
1274
+ unsubscribe();
1275
+ setState(latestUpdateState, update2, store);
1276
+ }
1277
+ );
1278
+ }
1279
+ );
1280
+ }
1281
+ },
1282
+ `${store.config.name}: tracker observing inner value`,
1283
+ store
1284
+ );
1285
+ }
1286
+ updateCore(mutableState, latestUpdateState, store) {
1287
+ subscribeToState(
1288
+ latestUpdateState,
1289
+ ({ newValue, oldValue }) => {
1290
+ const timelineId = store.timelineAtoms.getRelatedKey(
1291
+ latestUpdateState.key
1292
+ );
1293
+ if (timelineId) {
1294
+ const timelineData = store.timelines.get(timelineId);
1295
+ if (timelineData == null ? void 0 : timelineData.timeTraveling) {
1296
+ const unsubscribe2 = subscribeToTimeline(
1297
+ { key: timelineId, type: `timeline` },
1298
+ (update) => {
1299
+ unsubscribe2();
1300
+ setState(
1301
+ mutableState,
1302
+ (transceiver) => {
1303
+ if (update === `redo` && newValue) {
1304
+ transceiver.do(newValue);
1305
+ } else if (update === `undo` && oldValue) {
1306
+ transceiver.undo(oldValue);
1307
+ }
1308
+ return transceiver;
1309
+ },
1310
+ store
1311
+ );
1312
+ },
1313
+ `${mutableState.key}: tracker observing timeline`,
1314
+ store
1315
+ );
1316
+ return;
1317
+ }
1318
+ }
1319
+ const unsubscribe = store.subject.operationStatus.subscribe(
1320
+ latestUpdateState.key,
1321
+ () => {
1322
+ unsubscribe();
1323
+ const mutable = getState(mutableState, store);
1324
+ const updateNumber = mutable.getUpdateNumber(newValue);
1325
+ const eventOffset = updateNumber - mutable.cacheUpdateNumber;
1326
+ if (newValue && eventOffset === 1) {
1327
+ setState(
1328
+ mutableState,
1329
+ (transceiver) => (transceiver.do(newValue), transceiver),
1330
+ store
1331
+ );
1332
+ }
1333
+ }
1334
+ );
1335
+ },
1336
+ `${store.config.name}: tracker observing latest update`,
1337
+ store
1338
+ );
1339
+ }
1340
+ };
1341
+
1342
+ // internal/src/mutable/create-mutable-atom.ts
1343
+ function createMutableAtom(options, store) {
1344
+ store.logger.info(
1345
+ `\u{1F527}`,
1346
+ `atom`,
1347
+ options.key,
1348
+ `creating in store "${store.config.name}"`
1349
+ );
1350
+ const coreState = createAtom(options, void 0, store);
1351
+ new Tracker(coreState, store);
1352
+ const jsonState = selectJson(coreState, options, store);
1353
+ const target = newest(store);
1354
+ subscribeToState(
1355
+ jsonState,
1356
+ () => {
1357
+ const trackerHasBeenInitialized = newest(store).trackers.has(coreState.key);
1358
+ if (!trackerHasBeenInitialized) {
1359
+ new Tracker(coreState, store);
1360
+ }
1361
+ },
1362
+ `tracker-initializer:${store == null ? void 0 : store.config.name}:${target.transactionMeta === null ? `main` : `${target.transactionMeta.update.key}`}`,
1363
+ store
1364
+ );
1365
+ return coreState;
1366
+ }
1367
+
1368
+ // internal/src/families/create-atom-family.ts
1369
+ function createAtomFamily(options, store) {
1370
+ const subject = new Subject();
1371
+ const atomFamily = Object.assign(
1372
+ (key) => {
1373
+ const subKey = stringifyJson(key);
1374
+ const family = { key: options.key, subKey };
1375
+ const fullKey = `${options.key}(${subKey})`;
1376
+ const existing = withdraw({ key: fullKey, type: `atom` }, store);
1377
+ let token;
1378
+ if (existing) {
1379
+ token = deposit(existing);
1380
+ } else {
1381
+ const individualOptions = {
1382
+ key: fullKey,
1383
+ default: options.default instanceof Function ? options.default(key) : options.default
1384
+ };
1385
+ if (options.effects) {
1386
+ individualOptions.effects = options.effects(key);
1387
+ }
1388
+ token = createAtom(individualOptions, family, store);
1389
+ subject.next(token);
1390
+ }
1391
+ return token;
1392
+ },
1393
+ {
1394
+ key: options.key,
1395
+ type: `atom_family`,
1396
+ subject
1397
+ }
1398
+ );
1399
+ const target = newest(store);
1400
+ target.families.set(options.key, atomFamily);
1401
+ return atomFamily;
1402
+ }
1403
+
1404
+ // internal/src/families/create-readonly-selector-family.ts
1405
+ function createReadonlySelectorFamily(options, store) {
1406
+ const subject = new Subject();
1407
+ return Object.assign(
1408
+ (key) => {
1409
+ const target = newest(store);
1410
+ const subKey = stringifyJson(key);
1411
+ const family = { key: options.key, subKey };
1412
+ const fullKey = `${options.key}(${subKey})`;
1413
+ const existing = target.readonlySelectors.get(fullKey);
1414
+ if (existing) {
1415
+ return deposit(existing);
1416
+ }
1417
+ return createSelector(
1418
+ {
1419
+ key: fullKey,
1420
+ get: options.get(key)
1421
+ },
1422
+ family,
1423
+ store
1424
+ );
1425
+ },
1426
+ {
1427
+ key: options.key,
1428
+ type: `readonly_selector_family`,
1429
+ subject
1430
+ }
1431
+ );
1432
+ }
1433
+
1434
+ // internal/src/families/create-selector-family.ts
1435
+ function createSelectorFamily(options, store) {
1436
+ const isReadonly = !(`set` in options);
1437
+ if (isReadonly) {
1438
+ return createReadonlySelectorFamily(options, store);
1439
+ }
1440
+ const target = newest(store);
1441
+ const subject = new Subject();
1442
+ const selectorFamily = Object.assign(
1443
+ (key) => {
1444
+ const subKey = stringifyJson(key);
1445
+ const family = { key: options.key, subKey };
1446
+ const fullKey = `${options.key}(${subKey})`;
1447
+ const existing = target.selectors.get(fullKey);
1448
+ if (existing) {
1449
+ return deposit(existing);
1450
+ }
1451
+ const token = createSelector(
1452
+ {
1453
+ key: fullKey,
1454
+ get: options.get(key),
1455
+ set: options.set(key)
1456
+ },
1457
+ family,
1458
+ store
1459
+ );
1460
+ subject.next(token);
1461
+ return token;
1462
+ },
1463
+ {
1464
+ key: options.key,
1465
+ type: `selector_family`
1466
+ }
1467
+ );
1468
+ target.families.set(options.key, selectorFamily);
1469
+ return selectorFamily;
1470
+ }
1471
+
1472
+ // internal/src/mutable/transceiver.ts
1473
+ function isTransceiver(value) {
1474
+ return typeof value === `object` && value !== null && `do` in value && `undo` in value && `subscribe` in value;
1475
+ }
1476
+
1477
+ // internal/src/atom/is-default.ts
1478
+ var isAtomDefault = (key, store) => {
1479
+ const core = newest(store);
1480
+ return core.atomsThatAreDefault.has(key);
1481
+ };
1482
+ var markAtomAsDefault = (key, store) => {
1483
+ const core = newest(store);
1484
+ core.atomsThatAreDefault = new Set(core.atomsThatAreDefault).add(key);
1485
+ };
1486
+ var markAtomAsNotDefault = (key, store) => {
1487
+ const core = newest(store);
1488
+ core.atomsThatAreDefault = new Set(newest(store).atomsThatAreDefault);
1489
+ core.atomsThatAreDefault.delete(key);
1490
+ };
1491
+
1492
+ // internal/src/atom/create-atom.ts
1493
+ function createAtom(options, family, store) {
1494
+ store.logger.info(
1495
+ `\u{1F528}`,
1496
+ `atom`,
1497
+ options.key,
1498
+ `creating in store "${store.config.name}"`
1499
+ );
1500
+ const target = newest(store);
1501
+ const existing = target.atoms.get(options.key);
1502
+ if (existing) {
1503
+ store.logger.error(
1504
+ `\u274C`,
1505
+ `atom`,
1506
+ options.key,
1507
+ `Tried to create atom, but it already exists in the store.`,
1508
+ `(Ignore if you are in development using hot module replacement.)`
1509
+ );
1510
+ return deposit(existing);
1511
+ }
1512
+ const subject = new Subject();
1513
+ const newAtom = __spreadValues(__spreadProps(__spreadValues({}, options), {
1514
+ type: `atom`,
1515
+ install: (store2) => {
1516
+ store2.logger.info(
1517
+ `\u{1F6E0}\uFE0F`,
1518
+ `atom`,
1519
+ options.key,
1520
+ `installing in store "${store2.config.name}"`
1521
+ );
1522
+ return `mutable` in options ? createMutableAtom(options, store2) : createAtom(options, void 0, store2);
1523
+ },
1524
+ subject
1525
+ }), family && { family });
1526
+ let initialValue = options.default;
1527
+ if (options.default instanceof Function) {
1528
+ initialValue = options.default();
1529
+ }
1530
+ target.atoms.set(newAtom.key, newAtom);
1531
+ markAtomAsDefault(options.key, store);
1532
+ cacheValue(options.key, initialValue, subject, store);
1533
+ const token = deposit(newAtom);
1534
+ if (options.effects) {
1535
+ let effectIndex = 0;
1536
+ const cleanupFunctions = [];
1537
+ for (const effect of options.effects) {
1538
+ const cleanup = effect({
1539
+ setSelf: (next) => setState(token, next, store),
1540
+ onSet: (handle) => subscribeToState(token, handle, `effect[${effectIndex}]`, store)
1541
+ });
1542
+ if (cleanup) {
1543
+ cleanupFunctions.push(cleanup);
1544
+ }
1545
+ ++effectIndex;
1546
+ }
1547
+ newAtom.cleanup = () => {
1548
+ for (const cleanup of cleanupFunctions) {
1549
+ cleanup();
1550
+ }
1551
+ };
1552
+ }
1553
+ store.subject.atomCreation.next(token);
1554
+ return token;
1555
+ }
1556
+
1557
+ // internal/src/atom/delete-atom.ts
1558
+ function deleteAtom(atomToken, store) {
1559
+ var _a, _b;
1560
+ const target = newest(store);
1561
+ const { key } = atomToken;
1562
+ const atom = target.atoms.get(key);
1563
+ if (!atom) {
1564
+ store.logger.error(
1565
+ `\u274C`,
1566
+ `atom`,
1567
+ `${key}`,
1568
+ `Tried to delete atom, but it does not exist in the store.`
1569
+ );
1570
+ }
1571
+ (_a = atom == null ? void 0 : atom.cleanup) == null ? void 0 : _a.call(atom);
1572
+ target.atoms.delete(key);
1573
+ target.valueMap.delete(key);
1574
+ const selectorKeys = target.selectorAtoms.getRelatedKeys(key);
1575
+ if (selectorKeys) {
1576
+ for (const selectorKey of selectorKeys) {
1577
+ const token = (_b = target.selectors.get(selectorKey)) != null ? _b : target.readonlySelectors.get(selectorKey);
1578
+ if (token) {
1579
+ deleteSelector(token, store);
1580
+ }
1581
+ }
1582
+ }
1583
+ target.selectorAtoms.delete(key);
1584
+ target.atomsThatAreDefault.delete(key);
1585
+ target.timelineAtoms.delete(key);
1586
+ store.logger.info(`\u{1F525}`, `atom`, `${key}`, `deleted`);
1587
+ }
1588
+
1589
+ // internal/src/not-found-error.ts
1590
+ var capitalize = (str) => str[0].toUpperCase() + str.slice(1);
1591
+ function prettyPrintTokenType(token) {
1592
+ if (token.type === `readonly_selector`) {
1593
+ return `Readonly Selector`;
1594
+ }
1595
+ return capitalize(token.type);
1596
+ }
1597
+ var NotFoundError = class extends Error {
1598
+ constructor(token, store) {
1599
+ super(
1600
+ `${prettyPrintTokenType(token)} "${token.key}" not found in store "${store.config.name}".`
1601
+ );
1602
+ }
1603
+ };
1604
+
1605
+ // introspection/src/attach-atom-index.ts
1606
+ var attachAtomIndex = (store = IMPLICIT.STORE) => {
1607
+ const atomTokenIndexState__INTERNAL = createAtom(
46
1608
  {
47
1609
  key: `\u{1F441}\u200D\u{1F5E8} Atom Token Index (Internal)`,
48
1610
  default: () => {
@@ -81,7 +1643,7 @@ var attachAtomIndex = (store = Internal.IMPLICIT.STORE) => {
81
1643
  [key]: atomToken
82
1644
  });
83
1645
  });
84
- if (Internal.newest(store).operation.open) {
1646
+ if (newest(store).operation.open) {
85
1647
  const unsubscribe = store.subject.operationStatus.subscribe(
86
1648
  `introspection: waiting to update atom index`,
87
1649
  () => {
@@ -99,7 +1661,7 @@ var attachAtomIndex = (store = Internal.IMPLICIT.STORE) => {
99
1661
  void 0,
100
1662
  store
101
1663
  );
102
- return Internal.createSelector(
1664
+ return createSelector(
103
1665
  {
104
1666
  key: `\u{1F441}\u200D\u{1F5E8} Atom Token Index`,
105
1667
  get: ({ get }) => get(atomTokenIndexState__INTERNAL)
@@ -108,8 +1670,10 @@ var attachAtomIndex = (store = Internal.IMPLICIT.STORE) => {
108
1670
  store
109
1671
  );
110
1672
  };
111
- var attachSelectorIndex = (store = Internal.IMPLICIT.STORE) => {
112
- const readonlySelectorTokenIndexState__INTERNAL = Internal.createAtom(
1673
+
1674
+ // introspection/src/attach-selector-index.ts
1675
+ var attachSelectorIndex = (store = IMPLICIT.STORE) => {
1676
+ const readonlySelectorTokenIndexState__INTERNAL = createAtom(
113
1677
  {
114
1678
  key: `\u{1F441}\u200D\u{1F5E8} Selector Token Index (Internal)`,
115
1679
  default: () => Object.assign(
@@ -153,7 +1717,7 @@ var attachSelectorIndex = (store = Internal.IMPLICIT.STORE) => {
153
1717
  [key]: selectorToken
154
1718
  });
155
1719
  });
156
- if (Internal.newest(store).operation.open) {
1720
+ if (newest(store).operation.open) {
157
1721
  const unsubscribe = store.subject.operationStatus.subscribe(
158
1722
  `introspection: waiting to update selector index`,
159
1723
  () => {
@@ -172,17 +1736,19 @@ var attachSelectorIndex = (store = Internal.IMPLICIT.STORE) => {
172
1736
  void 0,
173
1737
  store
174
1738
  );
175
- return Internal.createSelector(
1739
+ return createSelector(
176
1740
  {
177
1741
  key: `\u{1F441}\u200D\u{1F5E8} Selector Token Index`,
178
1742
  get: ({ get }) => get(readonlySelectorTokenIndexState__INTERNAL)
179
1743
  },
180
1744
  void 0,
181
- Internal.IMPLICIT.STORE
1745
+ IMPLICIT.STORE
182
1746
  );
183
1747
  };
184
- var attachTimelineFamily = (store = Internal.IMPLICIT.STORE) => {
185
- const findTimelineLogState__INTERNAL = Internal.createAtomFamily(
1748
+
1749
+ // introspection/src/attach-timeline-family.ts
1750
+ var attachTimelineFamily = (store = IMPLICIT.STORE) => {
1751
+ const findTimelineLogState__INTERNAL = createAtomFamily(
186
1752
  {
187
1753
  key: `\u{1F441}\u200D\u{1F5E8} Timeline Update Log (Internal)`,
188
1754
  default: (key) => {
@@ -197,7 +1763,7 @@ var attachTimelineFamily = (store = Internal.IMPLICIT.STORE) => {
197
1763
  transactionKey: null,
198
1764
  install: () => {
199
1765
  },
200
- subject: new Internal.Subject()
1766
+ subject: new Subject()
201
1767
  };
202
1768
  },
203
1769
  effects: (key) => [
@@ -223,7 +1789,7 @@ var attachTimelineFamily = (store = Internal.IMPLICIT.STORE) => {
223
1789
  },
224
1790
  store
225
1791
  );
226
- const findTimelineLogState = Internal.createSelectorFamily(
1792
+ const findTimelineLogState = createSelectorFamily(
227
1793
  {
228
1794
  key: `\u{1F441}\u200D\u{1F5E8} Timeline Update Log`,
229
1795
  get: (key) => ({ get }) => get(findTimelineLogState__INTERNAL(key))
@@ -232,8 +1798,10 @@ var attachTimelineFamily = (store = Internal.IMPLICIT.STORE) => {
232
1798
  );
233
1799
  return findTimelineLogState;
234
1800
  };
235
- var attachTimelineIndex = (store = Internal.IMPLICIT.STORE) => {
236
- const timelineTokenIndexState__INTERNAL = Internal.createAtom(
1801
+
1802
+ // introspection/src/attach-timeline-index.ts
1803
+ var attachTimelineIndex = (store = IMPLICIT.STORE) => {
1804
+ const timelineTokenIndexState__INTERNAL = createAtom(
237
1805
  {
238
1806
  key: `\u{1F441}\u200D\u{1F5E8} Timeline Token Index (Internal)`,
239
1807
  default: () => [...store.timelines].map(([key]) => {
@@ -253,7 +1821,7 @@ var attachTimelineIndex = (store = Internal.IMPLICIT.STORE) => {
253
1821
  void 0,
254
1822
  store
255
1823
  );
256
- const timelineTokenIndex = Internal.createSelector(
1824
+ const timelineTokenIndex = createSelector(
257
1825
  {
258
1826
  key: `\u{1F441}\u200D\u{1F5E8} Timeline Token Index`,
259
1827
  get: ({ get }) => get(timelineTokenIndexState__INTERNAL)
@@ -263,8 +1831,10 @@ var attachTimelineIndex = (store = Internal.IMPLICIT.STORE) => {
263
1831
  );
264
1832
  return timelineTokenIndex;
265
1833
  };
266
- var attachTransactionIndex = (store = Internal.IMPLICIT.STORE) => {
267
- const transactionTokenIndexState__INTERNAL = Internal.createAtom(
1834
+
1835
+ // introspection/src/attach-transaction-index.ts
1836
+ var attachTransactionIndex = (store = IMPLICIT.STORE) => {
1837
+ const transactionTokenIndexState__INTERNAL = createAtom(
268
1838
  {
269
1839
  key: `\u{1F441}\u200D\u{1F5E8} Transaction Token Index (Internal)`,
270
1840
  default: () => [...store.transactions].map(([key]) => {
@@ -284,7 +1854,7 @@ var attachTransactionIndex = (store = Internal.IMPLICIT.STORE) => {
284
1854
  void 0,
285
1855
  store
286
1856
  );
287
- const transactionTokenIndex = Internal.createSelector(
1857
+ const transactionTokenIndex = createSelector(
288
1858
  {
289
1859
  key: `\u{1F441}\u200D\u{1F5E8} Transaction Token Index`,
290
1860
  get: ({ get }) => get(transactionTokenIndexState__INTERNAL)
@@ -294,8 +1864,10 @@ var attachTransactionIndex = (store = Internal.IMPLICIT.STORE) => {
294
1864
  );
295
1865
  return transactionTokenIndex;
296
1866
  };
297
- var attachTransactionLogs = (store = Internal.IMPLICIT.STORE) => {
298
- const findTransactionUpdateLog = Internal.createAtomFamily(
1867
+
1868
+ // introspection/src/attach-transaction-logs.ts
1869
+ var attachTransactionLogs = (store = IMPLICIT.STORE) => {
1870
+ const findTransactionUpdateLog = createAtomFamily(
299
1871
  {
300
1872
  key: `\u{1F441}\u200D\u{1F5E8} Transaction Update Log (Internal)`,
301
1873
  default: () => [],
@@ -312,7 +1884,7 @@ var attachTransactionLogs = (store = Internal.IMPLICIT.STORE) => {
312
1884
  },
313
1885
  store
314
1886
  );
315
- const findTransactionUpdateLogState = Internal.createSelectorFamily(
1887
+ const findTransactionUpdateLogState = createSelectorFamily(
316
1888
  {
317
1889
  key: `\u{1F441}\u200D\u{1F5E8} Transaction Update Log`,
318
1890
  get: (key) => ({ get }) => get(findTransactionUpdateLog(key))
@@ -322,8 +1894,8 @@ var attachTransactionLogs = (store = Internal.IMPLICIT.STORE) => {
322
1894
  return findTransactionUpdateLogState;
323
1895
  };
324
1896
 
325
- // src/attach-introspection-states.ts
326
- var attachIntrospectionStates = (store = Internal__namespace.IMPLICIT.STORE) => {
1897
+ // introspection/src/attach-introspection-states.ts
1898
+ var attachIntrospectionStates = (store = IMPLICIT.STORE) => {
327
1899
  return {
328
1900
  atomIndex: attachAtomIndex(store),
329
1901
  selectorIndex: attachSelectorIndex(store),