atom.io 0.14.1 → 0.14.3

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 (83) hide show
  1. package/data/dist/index.cjs +12 -64
  2. package/data/dist/index.cjs.map +1 -1
  3. package/data/dist/index.d.cts +2 -0
  4. package/data/dist/index.d.ts +459 -0
  5. package/data/dist/index.js +1 -1
  6. package/dist/{chunk-KW7RA7IM.js → chunk-C4YZZNRH.js} +4 -4
  7. package/dist/{chunk-LFXB7Y6M.js → chunk-CWKKQKVQ.js} +2 -2
  8. package/dist/{chunk-CK7GNCU5.js → chunk-GMN5KH6A.js} +2 -2
  9. package/dist/{chunk-5VJ77LZE.js → chunk-N7ADBQJG.js} +2 -2
  10. package/dist/{chunk-TE3ZSTQ6.js → chunk-PURABO5G.js} +92 -27
  11. package/dist/chunk-PURABO5G.js.map +1 -0
  12. package/dist/index.cjs +106 -20
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.d.cts +4 -1
  15. package/dist/index.d.ts +493 -0
  16. package/dist/index.js +1 -1
  17. package/dist/metafile-cjs.json +1 -1
  18. package/dist/metafile-esm.json +1 -0
  19. package/internal/dist/index.cjs +93 -29
  20. package/internal/dist/index.cjs.map +1 -1
  21. package/internal/dist/index.d.cts +6 -4
  22. package/internal/dist/index.d.ts +622 -0
  23. package/internal/dist/index.js +1 -1
  24. package/internal/src/atom/create-atom.ts +3 -1
  25. package/internal/src/families/create-atom-family.ts +3 -4
  26. package/internal/src/mutable/get-update-family.ts +23 -0
  27. package/internal/src/mutable/index.ts +1 -4
  28. package/internal/src/mutable/is-mutable.ts +44 -0
  29. package/internal/src/mutable/tracker.ts +9 -2
  30. package/internal/src/subject.ts +2 -1
  31. package/internal/src/timeline/add-atom-to-timeline.ts +10 -1
  32. package/internal/src/timeline/create-timeline.ts +44 -16
  33. package/introspection/dist/index.cjs +12 -64
  34. package/introspection/dist/index.cjs.map +1 -1
  35. package/introspection/dist/index.d.cts +2 -0
  36. package/introspection/dist/index.d.ts +396 -0
  37. package/introspection/dist/index.js +2 -2
  38. package/json/dist/index.cjs +9 -64
  39. package/json/dist/index.cjs.map +1 -1
  40. package/json/dist/index.d.cts +2 -0
  41. package/json/dist/index.d.ts +417 -0
  42. package/json/dist/index.js +1 -1
  43. package/package.json +3 -2
  44. package/react/dist/index.cjs +9 -64
  45. package/react/dist/index.cjs.map +1 -1
  46. package/react/dist/index.d.cts +2 -0
  47. package/react/dist/index.d.ts +396 -0
  48. package/react/dist/index.js +2 -2
  49. package/react-devtools/dist/index.cjs +12 -64
  50. package/react-devtools/dist/index.cjs.map +1 -1
  51. package/react-devtools/dist/index.d.cts +2 -0
  52. package/react-devtools/dist/index.d.ts +467 -0
  53. package/react-devtools/dist/index.js +3 -3
  54. package/realtime-client/dist/index.cjs +9 -64
  55. package/realtime-client/dist/index.cjs.map +1 -1
  56. package/realtime-client/dist/index.d.cts +2 -0
  57. package/realtime-client/dist/index.d.ts +394 -0
  58. package/realtime-client/dist/index.js +2 -2
  59. package/realtime-react/dist/index.cjs +9 -64
  60. package/realtime-react/dist/index.cjs.map +1 -1
  61. package/realtime-react/dist/index.d.ts +67 -0
  62. package/realtime-react/dist/index.js +4 -4
  63. package/realtime-server/dist/index.cjs +9 -64
  64. package/realtime-server/dist/index.cjs.map +1 -1
  65. package/realtime-server/dist/index.d.cts +4 -1
  66. package/realtime-server/dist/index.d.ts +408 -0
  67. package/realtime-server/dist/index.js +1 -1
  68. package/realtime-testing/dist/index.cjs +104 -79
  69. package/realtime-testing/dist/index.cjs.map +1 -1
  70. package/realtime-testing/dist/index.d.cts +4 -1
  71. package/realtime-testing/dist/index.d.ts +535 -0
  72. package/realtime-testing/dist/index.js +4 -4
  73. package/src/atom.ts +3 -1
  74. package/transceivers/set-rtx/dist/index.cjs +2 -1
  75. package/transceivers/set-rtx/dist/index.cjs.map +1 -1
  76. package/transceivers/set-rtx/dist/index.d.ts +66 -0
  77. package/transceivers/set-rtx/dist/index.js +1 -1
  78. package/dist/chunk-TE3ZSTQ6.js.map +0 -1
  79. package/internal/src/mutable/is-atom-token-mutable.ts +0 -7
  80. /package/dist/{chunk-KW7RA7IM.js.map → chunk-C4YZZNRH.js.map} +0 -0
  81. /package/dist/{chunk-LFXB7Y6M.js.map → chunk-CWKKQKVQ.js.map} +0 -0
  82. /package/dist/{chunk-CK7GNCU5.js.map → chunk-GMN5KH6A.js.map} +0 -0
  83. /package/dist/{chunk-5VJ77LZE.js.map → chunk-N7ADBQJG.js.map} +0 -0
@@ -313,7 +313,8 @@ var Subject = class {
313
313
  this.subscribers.delete(key);
314
314
  }
315
315
  next(value) {
316
- for (const subscriber of this.subscribers.values()) {
316
+ const subscribers = this.subscribers.values();
317
+ for (const subscriber of subscribers) {
317
318
  subscriber(value);
318
319
  }
319
320
  }
@@ -1298,7 +1299,8 @@ var Tracker = class {
1298
1299
  }
1299
1300
  initializeState(mutableState, store) {
1300
1301
  const latestUpdateStateKey = `*${mutableState.key}`;
1301
- deleteAtom({ type: `atom`, key: latestUpdateStateKey }, store);
1302
+ store.atoms.delete(latestUpdateStateKey);
1303
+ store.valueMap.delete(latestUpdateStateKey);
1302
1304
  const familyMetaData = mutableState.family ? {
1303
1305
  key: `*${mutableState.family.key}`,
1304
1306
  subKey: mutableState.family.subKey
@@ -1311,6 +1313,10 @@ var Tracker = class {
1311
1313
  familyMetaData,
1312
1314
  store
1313
1315
  );
1316
+ if (store.parent) {
1317
+ const parentValue = store.parent.valueMap.get(latestUpdateStateKey);
1318
+ store.valueMap.set(latestUpdateStateKey, parentValue);
1319
+ }
1314
1320
  return latestUpdateState;
1315
1321
  }
1316
1322
  observeCore(mutableState, latestUpdateState, store) {
@@ -1391,7 +1397,7 @@ var Tracker = class {
1391
1397
  () => {
1392
1398
  unsubscribe();
1393
1399
  const mutable = getState(mutableState, store);
1394
- const updateNumber = mutable.getUpdateNumber(newValue);
1400
+ const updateNumber = newValue === null ? -1 : mutable.getUpdateNumber(newValue);
1395
1401
  const eventOffset = updateNumber - mutable.cacheUpdateNumber;
1396
1402
  if (newValue && eventOffset === 1) {
1397
1403
  setState(
@@ -1466,6 +1472,9 @@ function createAtomFamily(options, store) {
1466
1472
  subject
1467
1473
  }
1468
1474
  );
1475
+ if (`mutable` in options && typeof options.mutable === `boolean`) {
1476
+ Object.assign(atomFamily, { mutable: options.mutable });
1477
+ }
1469
1478
  const target = newest(store);
1470
1479
  target.families.set(options.key, atomFamily);
1471
1480
  return atomFamily;
@@ -1620,19 +1629,19 @@ var getUpdateToken = (mutableAtomToken) => {
1620
1629
  return updateToken;
1621
1630
  };
1622
1631
 
1623
- // internal/src/mutable/is-atom-token-mutable.ts
1624
- function isAtomTokenMutable(token) {
1625
- return token.key.endsWith(`::mutable`);
1626
- }
1632
+ // internal/src/mutable/get-update-family.ts
1633
+ var getUpdateFamily = (mutableAtomFamily, store) => {
1634
+ const target = newest(store);
1635
+ const key = `*${mutableAtomFamily.key}`;
1636
+ const updateFamily = target.families.get(key);
1637
+ return updateFamily;
1638
+ };
1627
1639
 
1628
1640
  // internal/src/mutable/transceiver.ts
1629
1641
  function isTransceiver(value) {
1630
1642
  return typeof value === `object` && value !== null && `do` in value && `undo` in value && `subscribe` in value;
1631
1643
  }
1632
1644
 
1633
- // internal/src/mutable/index.ts
1634
- var isAtomMutable = (atom) => `isMutable` in atom;
1635
-
1636
1645
  // internal/src/atom/is-default.ts
1637
1646
  var isAtomDefault = (key, store) => {
1638
1647
  const core = newest(store);
@@ -1718,7 +1727,7 @@ function createAtom(options, family, store) {
1718
1727
  }
1719
1728
 
1720
1729
  // internal/src/atom/delete-atom.ts
1721
- function deleteAtom(atomToken, store) {
1730
+ function deleteAtom2(atomToken, store) {
1722
1731
  var _a, _b;
1723
1732
  const target = newest(store);
1724
1733
  const { key } = atomToken;
@@ -1801,7 +1810,13 @@ var NotFoundError = class extends Error {
1801
1810
 
1802
1811
  // internal/src/timeline/add-atom-to-timeline.ts
1803
1812
  var addAtomToTimeline = (atomToken, tl, store) => {
1804
- const atom = withdraw(atomToken, store);
1813
+ let maybeAtom = withdraw(atomToken, store);
1814
+ if (maybeAtom == null ? void 0 : maybeAtom.mutable) {
1815
+ console.log(`adding transceiver to timeline`, atomToken.key);
1816
+ const updateToken = getUpdateToken(atomToken);
1817
+ maybeAtom = withdraw(updateToken, store);
1818
+ }
1819
+ const atom = maybeAtom;
1805
1820
  if (atom === void 0) {
1806
1821
  throw new Error(
1807
1822
  `Cannot subscribe to atom "${atomToken.key}" because it has not been initialized in store "${store.config.name}"`
@@ -1991,6 +2006,30 @@ var addAtomToTimeline = (atomToken, tl, store) => {
1991
2006
  });
1992
2007
  };
1993
2008
 
2009
+ // internal/src/mutable/is-mutable.ts
2010
+ function isMutable(atomOrTokenOrFamily, store) {
2011
+ if (`mutable` in atomOrTokenOrFamily) {
2012
+ return atomOrTokenOrFamily.mutable;
2013
+ }
2014
+ if (atomOrTokenOrFamily.type === `atom_family`) {
2015
+ return false;
2016
+ }
2017
+ if (`default` in atomOrTokenOrFamily) {
2018
+ return false;
2019
+ }
2020
+ if (!store) {
2021
+ throw new Error(`Cannot check mutability without a store`);
2022
+ }
2023
+ const atom = withdraw(atomOrTokenOrFamily, store);
2024
+ if (!atom) {
2025
+ throw new Error(`Cannot check mutability without an atom`);
2026
+ }
2027
+ if (`mutable` in atom) {
2028
+ return atom.mutable;
2029
+ }
2030
+ return false;
2031
+ }
2032
+
1994
2033
  // internal/src/timeline/create-timeline.ts
1995
2034
  function createTimeline(options, store, data) {
1996
2035
  var _a, _b;
@@ -2009,20 +2048,26 @@ function createTimeline(options, store, data) {
2009
2048
  if (options.shouldCapture) {
2010
2049
  tl.shouldCapture = options.shouldCapture;
2011
2050
  }
2051
+ const timelineKey = options.key;
2012
2052
  const target = newest(store);
2013
2053
  for (const tokenOrFamily of options.atoms) {
2014
- const timelineKey = target.timelineAtoms.getRelatedKey(tokenOrFamily.key);
2015
- if (timelineKey) {
2054
+ let atomKey = tokenOrFamily.key;
2055
+ const existingTimelineKey = target.timelineAtoms.getRelatedKey(atomKey);
2056
+ if (existingTimelineKey) {
2016
2057
  store.logger.error(
2017
2058
  `\u274C`,
2018
2059
  `timeline`,
2019
2060
  options.key,
2020
- `Failed to add atom "${tokenOrFamily.key}" because it already belongs to timeline "${timelineKey}"`
2061
+ `Failed to add atom "${atomKey}" because it already belongs to timeline "${existingTimelineKey}"`
2021
2062
  );
2022
2063
  continue;
2023
2064
  }
2024
2065
  if (tokenOrFamily.type === `atom_family`) {
2025
- const family = tokenOrFamily;
2066
+ let family = tokenOrFamily;
2067
+ if (isMutable(family)) {
2068
+ family = getUpdateFamily(family, store);
2069
+ atomKey = family.key;
2070
+ }
2026
2071
  family.subject.subscribe(`timeline:${options.key}`, (token2) => {
2027
2072
  addAtomToTimeline(token2, tl, store);
2028
2073
  });
@@ -2032,31 +2077,51 @@ function createTimeline(options, store, data) {
2032
2077
  }
2033
2078
  }
2034
2079
  } else {
2035
- const token2 = tokenOrFamily;
2036
- if (`family` in token2 && token2.family) {
2080
+ let atom = withdraw(tokenOrFamily, store);
2081
+ if (atom === void 0) {
2082
+ store.logger.error(
2083
+ `\u274C`,
2084
+ `timeline`,
2085
+ options.key,
2086
+ `Failed to add atom "${atomKey}" because it does not exist in the store`
2087
+ );
2088
+ continue;
2089
+ }
2090
+ if (isMutable(atom)) {
2091
+ const updateAtom = withdraw(getUpdateToken(atom), store);
2092
+ if (updateAtom === void 0) {
2093
+ store.logger.error(
2094
+ `\u274C`,
2095
+ `timeline`,
2096
+ options.key,
2097
+ `Failed to add update atom "${atomKey}" because it does not exist in the store`
2098
+ );
2099
+ continue;
2100
+ }
2101
+ atom = updateAtom;
2102
+ atomKey = atom.key;
2103
+ }
2104
+ if (`family` in atom) {
2037
2105
  const familyTimelineKey = target.timelineAtoms.getRelatedKey(
2038
- token2.family.key
2106
+ atom.family.key
2039
2107
  );
2040
2108
  if (familyTimelineKey) {
2041
2109
  store.logger.error(
2042
2110
  `\u274C`,
2043
2111
  `timeline`,
2044
2112
  options.key,
2045
- `Failed to add atom "${token2.key}" because its family "${token2.family.key}" already belongs to timeline "${familyTimelineKey}"`
2113
+ `Failed to add atom "${atom.key}" because its family "${atom.family.key}" already belongs to timeline "${familyTimelineKey}"`
2046
2114
  );
2047
2115
  continue;
2048
2116
  }
2049
2117
  }
2050
- addAtomToTimeline(token2, tl, store);
2118
+ addAtomToTimeline(atom, tl, store);
2051
2119
  }
2052
- target.timelineAtoms = target.timelineAtoms.set({
2053
- atomKey: tokenOrFamily.key,
2054
- timelineKey: options.key
2055
- });
2120
+ target.timelineAtoms.set({ atomKey, timelineKey });
2056
2121
  }
2057
2122
  store.timelines.set(options.key, tl);
2058
2123
  const token = {
2059
- key: options.key,
2124
+ key: timelineKey,
2060
2125
  type: `timeline`
2061
2126
  };
2062
2127
  store.subject.timelineCreation.next(token);
@@ -2395,7 +2460,7 @@ exports.createSelector = createSelector;
2395
2460
  exports.createSelectorFamily = createSelectorFamily;
2396
2461
  exports.createTimeline = createTimeline;
2397
2462
  exports.createTransaction = createTransaction;
2398
- exports.deleteAtom = deleteAtom;
2463
+ exports.deleteAtom = deleteAtom2;
2399
2464
  exports.deleteSelector = deleteSelector;
2400
2465
  exports.deposit = deposit;
2401
2466
  exports.eldest = eldest;
@@ -2403,11 +2468,10 @@ exports.evictCachedValue = evictCachedValue;
2403
2468
  exports.getJsonFamily = getJsonFamily;
2404
2469
  exports.getJsonToken = getJsonToken;
2405
2470
  exports.getSelectorDependencyKeys = getSelectorDependencyKeys;
2471
+ exports.getUpdateFamily = getUpdateFamily;
2406
2472
  exports.getUpdateToken = getUpdateToken;
2407
2473
  exports.isAtomDefault = isAtomDefault;
2408
2474
  exports.isAtomKey = isAtomKey;
2409
- exports.isAtomMutable = isAtomMutable;
2410
- exports.isAtomTokenMutable = isAtomTokenMutable;
2411
2475
  exports.isDone = isDone;
2412
2476
  exports.isReadonlySelectorKey = isReadonlySelectorKey;
2413
2477
  exports.isSelectorDefault = isSelectorDefault;