atom.io 0.14.3 → 0.14.5

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