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
package/dist/index.cjs CHANGED
@@ -236,7 +236,8 @@ var Subject = class {
236
236
  this.subscribers.delete(key);
237
237
  }
238
238
  next(value) {
239
- for (const subscriber of this.subscribers.values()) {
239
+ const subscribers = this.subscribers.values();
240
+ for (const subscriber of subscribers) {
240
241
  subscriber(value);
241
242
  }
242
243
  }
@@ -1216,7 +1217,8 @@ var Tracker = class {
1216
1217
  }
1217
1218
  initializeState(mutableState, store) {
1218
1219
  const latestUpdateStateKey = `*${mutableState.key}`;
1219
- deleteAtom({ type: `atom`, key: latestUpdateStateKey }, store);
1220
+ store.atoms.delete(latestUpdateStateKey);
1221
+ store.valueMap.delete(latestUpdateStateKey);
1220
1222
  const familyMetaData = mutableState.family ? {
1221
1223
  key: `*${mutableState.family.key}`,
1222
1224
  subKey: mutableState.family.subKey
@@ -1229,6 +1231,10 @@ var Tracker = class {
1229
1231
  familyMetaData,
1230
1232
  store
1231
1233
  );
1234
+ if (store.parent) {
1235
+ const parentValue = store.parent.valueMap.get(latestUpdateStateKey);
1236
+ store.valueMap.set(latestUpdateStateKey, parentValue);
1237
+ }
1232
1238
  return latestUpdateState;
1233
1239
  }
1234
1240
  observeCore(mutableState, latestUpdateState, store) {
@@ -1309,7 +1315,7 @@ var Tracker = class {
1309
1315
  () => {
1310
1316
  unsubscribe();
1311
1317
  const mutable = getState(mutableState, store);
1312
- const updateNumber = mutable.getUpdateNumber(newValue);
1318
+ const updateNumber = newValue === null ? -1 : mutable.getUpdateNumber(newValue);
1313
1319
  const eventOffset = updateNumber - mutable.cacheUpdateNumber;
1314
1320
  if (newValue && eventOffset === 1) {
1315
1321
  setState(
@@ -1384,6 +1390,9 @@ function createAtomFamily(options, store) {
1384
1390
  subject
1385
1391
  }
1386
1392
  );
1393
+ if (`mutable` in options && typeof options.mutable === `boolean`) {
1394
+ Object.assign(atomFamily2, { mutable: options.mutable });
1395
+ }
1387
1396
  const target = newest(store);
1388
1397
  target.families.set(options.key, atomFamily2);
1389
1398
  return atomFamily2;
@@ -1502,6 +1511,27 @@ function createMutableAtomFamily(options, store) {
1502
1511
  return coreFamily;
1503
1512
  }
1504
1513
 
1514
+ // internal/src/mutable/get-update-token.ts
1515
+ var getUpdateToken = (mutableAtomToken) => {
1516
+ const key = `*${mutableAtomToken.key}`;
1517
+ const updateToken = { type: `atom`, key };
1518
+ if (mutableAtomToken.family) {
1519
+ updateToken.family = {
1520
+ key: `*${mutableAtomToken.family.key}`,
1521
+ subKey: mutableAtomToken.family.subKey
1522
+ };
1523
+ }
1524
+ return updateToken;
1525
+ };
1526
+
1527
+ // internal/src/mutable/get-update-family.ts
1528
+ var getUpdateFamily = (mutableAtomFamily, store) => {
1529
+ const target = newest(store);
1530
+ const key = `*${mutableAtomFamily.key}`;
1531
+ const updateFamily = target.families.get(key);
1532
+ return updateFamily;
1533
+ };
1534
+
1505
1535
  // internal/src/mutable/transceiver.ts
1506
1536
  function isTransceiver(value) {
1507
1537
  return typeof value === `object` && value !== null && `do` in value && `undo` in value && `subscribe` in value;
@@ -1588,7 +1618,7 @@ function createAtom(options, family, store) {
1588
1618
  }
1589
1619
 
1590
1620
  // internal/src/atom/delete-atom.ts
1591
- function deleteAtom(atomToken, store) {
1621
+ function deleteAtom2(atomToken, store) {
1592
1622
  var _a, _b;
1593
1623
  const target = newest(store);
1594
1624
  const { key } = atomToken;
@@ -1671,7 +1701,13 @@ var NotFoundError = class extends Error {
1671
1701
 
1672
1702
  // internal/src/timeline/add-atom-to-timeline.ts
1673
1703
  var addAtomToTimeline = (atomToken, tl, store) => {
1674
- const atom2 = withdraw(atomToken, store);
1704
+ let maybeAtom = withdraw(atomToken, store);
1705
+ if (maybeAtom == null ? void 0 : maybeAtom.mutable) {
1706
+ console.log(`adding transceiver to timeline`, atomToken.key);
1707
+ const updateToken = getUpdateToken(atomToken);
1708
+ maybeAtom = withdraw(updateToken, store);
1709
+ }
1710
+ const atom2 = maybeAtom;
1675
1711
  if (atom2 === void 0) {
1676
1712
  throw new Error(
1677
1713
  `Cannot subscribe to atom "${atomToken.key}" because it has not been initialized in store "${store.config.name}"`
@@ -1861,6 +1897,30 @@ var addAtomToTimeline = (atomToken, tl, store) => {
1861
1897
  });
1862
1898
  };
1863
1899
 
1900
+ // internal/src/mutable/is-mutable.ts
1901
+ function isMutable(atomOrTokenOrFamily, store) {
1902
+ if (`mutable` in atomOrTokenOrFamily) {
1903
+ return atomOrTokenOrFamily.mutable;
1904
+ }
1905
+ if (atomOrTokenOrFamily.type === `atom_family`) {
1906
+ return false;
1907
+ }
1908
+ if (`default` in atomOrTokenOrFamily) {
1909
+ return false;
1910
+ }
1911
+ if (!store) {
1912
+ throw new Error(`Cannot check mutability without a store`);
1913
+ }
1914
+ const atom2 = withdraw(atomOrTokenOrFamily, store);
1915
+ if (!atom2) {
1916
+ throw new Error(`Cannot check mutability without an atom`);
1917
+ }
1918
+ if (`mutable` in atom2) {
1919
+ return atom2.mutable;
1920
+ }
1921
+ return false;
1922
+ }
1923
+
1864
1924
  // internal/src/timeline/create-timeline.ts
1865
1925
  function createTimeline(options, store, data) {
1866
1926
  var _a, _b;
@@ -1879,20 +1939,26 @@ function createTimeline(options, store, data) {
1879
1939
  if (options.shouldCapture) {
1880
1940
  tl.shouldCapture = options.shouldCapture;
1881
1941
  }
1942
+ const timelineKey = options.key;
1882
1943
  const target = newest(store);
1883
1944
  for (const tokenOrFamily of options.atoms) {
1884
- const timelineKey = target.timelineAtoms.getRelatedKey(tokenOrFamily.key);
1885
- if (timelineKey) {
1945
+ let atomKey = tokenOrFamily.key;
1946
+ const existingTimelineKey = target.timelineAtoms.getRelatedKey(atomKey);
1947
+ if (existingTimelineKey) {
1886
1948
  store.logger.error(
1887
1949
  `\u274C`,
1888
1950
  `timeline`,
1889
1951
  options.key,
1890
- `Failed to add atom "${tokenOrFamily.key}" because it already belongs to timeline "${timelineKey}"`
1952
+ `Failed to add atom "${atomKey}" because it already belongs to timeline "${existingTimelineKey}"`
1891
1953
  );
1892
1954
  continue;
1893
1955
  }
1894
1956
  if (tokenOrFamily.type === `atom_family`) {
1895
- const family = tokenOrFamily;
1957
+ let family = tokenOrFamily;
1958
+ if (isMutable(family)) {
1959
+ family = getUpdateFamily(family, store);
1960
+ atomKey = family.key;
1961
+ }
1896
1962
  family.subject.subscribe(`timeline:${options.key}`, (token2) => {
1897
1963
  addAtomToTimeline(token2, tl, store);
1898
1964
  });
@@ -1902,31 +1968,51 @@ function createTimeline(options, store, data) {
1902
1968
  }
1903
1969
  }
1904
1970
  } else {
1905
- const token2 = tokenOrFamily;
1906
- if (`family` in token2 && token2.family) {
1971
+ let atom2 = withdraw(tokenOrFamily, store);
1972
+ if (atom2 === void 0) {
1973
+ store.logger.error(
1974
+ `\u274C`,
1975
+ `timeline`,
1976
+ options.key,
1977
+ `Failed to add atom "${atomKey}" because it does not exist in the store`
1978
+ );
1979
+ continue;
1980
+ }
1981
+ if (isMutable(atom2)) {
1982
+ const updateAtom = withdraw(getUpdateToken(atom2), store);
1983
+ if (updateAtom === void 0) {
1984
+ store.logger.error(
1985
+ `\u274C`,
1986
+ `timeline`,
1987
+ options.key,
1988
+ `Failed to add update atom "${atomKey}" because it does not exist in the store`
1989
+ );
1990
+ continue;
1991
+ }
1992
+ atom2 = updateAtom;
1993
+ atomKey = atom2.key;
1994
+ }
1995
+ if (`family` in atom2) {
1907
1996
  const familyTimelineKey = target.timelineAtoms.getRelatedKey(
1908
- token2.family.key
1997
+ atom2.family.key
1909
1998
  );
1910
1999
  if (familyTimelineKey) {
1911
2000
  store.logger.error(
1912
2001
  `\u274C`,
1913
2002
  `timeline`,
1914
2003
  options.key,
1915
- `Failed to add atom "${token2.key}" because its family "${token2.family.key}" already belongs to timeline "${familyTimelineKey}"`
2004
+ `Failed to add atom "${atom2.key}" because its family "${atom2.family.key}" already belongs to timeline "${familyTimelineKey}"`
1916
2005
  );
1917
2006
  continue;
1918
2007
  }
1919
2008
  }
1920
- addAtomToTimeline(token2, tl, store);
2009
+ addAtomToTimeline(atom2, tl, store);
1921
2010
  }
1922
- target.timelineAtoms = target.timelineAtoms.set({
1923
- atomKey: tokenOrFamily.key,
1924
- timelineKey: options.key
1925
- });
2011
+ target.timelineAtoms.set({ atomKey, timelineKey });
1926
2012
  }
1927
2013
  store.timelines.set(options.key, tl);
1928
2014
  const token = {
1929
- key: options.key,
2015
+ key: timelineKey,
1930
2016
  type: `timeline`
1931
2017
  };
1932
2018
  store.subject.timelineCreation.next(token);
@@ -2213,7 +2299,7 @@ function atomFamily(options) {
2213
2299
  function dispose(token, store = IMPLICIT.STORE) {
2214
2300
  switch (token.type) {
2215
2301
  case `atom`:
2216
- deleteAtom(token, store);
2302
+ deleteAtom2(token, store);
2217
2303
  break;
2218
2304
  case `selector`:
2219
2305
  case `readonly_selector`: