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
@@ -422,7 +422,8 @@ var Subject = class {
422
422
  this.subscribers.delete(key);
423
423
  }
424
424
  next(value) {
425
- for (const subscriber of this.subscribers.values()) {
425
+ const subscribers = this.subscribers.values();
426
+ for (const subscriber of subscribers) {
426
427
  subscriber(value);
427
428
  }
428
429
  }
@@ -1407,7 +1408,8 @@ var Tracker = class {
1407
1408
  }
1408
1409
  initializeState(mutableState, store) {
1409
1410
  const latestUpdateStateKey = `*${mutableState.key}`;
1410
- deleteAtom({ type: `atom`, key: latestUpdateStateKey }, store);
1411
+ store.atoms.delete(latestUpdateStateKey);
1412
+ store.valueMap.delete(latestUpdateStateKey);
1411
1413
  const familyMetaData = mutableState.family ? {
1412
1414
  key: `*${mutableState.family.key}`,
1413
1415
  subKey: mutableState.family.subKey
@@ -1420,6 +1422,10 @@ var Tracker = class {
1420
1422
  familyMetaData,
1421
1423
  store
1422
1424
  );
1425
+ if (store.parent) {
1426
+ const parentValue = store.parent.valueMap.get(latestUpdateStateKey);
1427
+ store.valueMap.set(latestUpdateStateKey, parentValue);
1428
+ }
1423
1429
  return latestUpdateState;
1424
1430
  }
1425
1431
  observeCore(mutableState, latestUpdateState, store) {
@@ -1500,7 +1506,7 @@ var Tracker = class {
1500
1506
  () => {
1501
1507
  unsubscribe();
1502
1508
  const mutable = getState(mutableState, store);
1503
- const updateNumber = mutable.getUpdateNumber(newValue);
1509
+ const updateNumber = newValue === null ? -1 : mutable.getUpdateNumber(newValue);
1504
1510
  const eventOffset = updateNumber - mutable.cacheUpdateNumber;
1505
1511
  if (newValue && eventOffset === 1) {
1506
1512
  setState(
@@ -1575,6 +1581,9 @@ function createAtomFamily(options, store) {
1575
1581
  subject
1576
1582
  }
1577
1583
  );
1584
+ if (`mutable` in options && typeof options.mutable === `boolean`) {
1585
+ Object.assign(atomFamily2, { mutable: options.mutable });
1586
+ }
1578
1587
  const target = newest(store);
1579
1588
  target.families.set(options.key, atomFamily2);
1580
1589
  return atomFamily2;
@@ -1729,19 +1738,19 @@ var getUpdateToken = (mutableAtomToken) => {
1729
1738
  return updateToken;
1730
1739
  };
1731
1740
 
1732
- // internal/src/mutable/is-atom-token-mutable.ts
1733
- function isAtomTokenMutable(token) {
1734
- return token.key.endsWith(`::mutable`);
1735
- }
1741
+ // internal/src/mutable/get-update-family.ts
1742
+ var getUpdateFamily = (mutableAtomFamily, store) => {
1743
+ const target = newest(store);
1744
+ const key = `*${mutableAtomFamily.key}`;
1745
+ const updateFamily = target.families.get(key);
1746
+ return updateFamily;
1747
+ };
1736
1748
 
1737
1749
  // internal/src/mutable/transceiver.ts
1738
1750
  function isTransceiver(value) {
1739
1751
  return typeof value === `object` && value !== null && `do` in value && `undo` in value && `subscribe` in value;
1740
1752
  }
1741
1753
 
1742
- // internal/src/mutable/index.ts
1743
- var isAtomMutable = (atom2) => `isMutable` in atom2;
1744
-
1745
1754
  // internal/src/atom/is-default.ts
1746
1755
  var isAtomDefault = (key, store) => {
1747
1756
  const core = newest(store);
@@ -1910,7 +1919,13 @@ var NotFoundError = class extends Error {
1910
1919
 
1911
1920
  // internal/src/timeline/add-atom-to-timeline.ts
1912
1921
  var addAtomToTimeline = (atomToken, tl, store) => {
1913
- const atom2 = withdraw(atomToken, store);
1922
+ let maybeAtom = withdraw(atomToken, store);
1923
+ if (maybeAtom == null ? void 0 : maybeAtom.mutable) {
1924
+ console.log(`adding transceiver to timeline`, atomToken.key);
1925
+ const updateToken = getUpdateToken(atomToken);
1926
+ maybeAtom = withdraw(updateToken, store);
1927
+ }
1928
+ const atom2 = maybeAtom;
1914
1929
  if (atom2 === void 0) {
1915
1930
  throw new Error(
1916
1931
  `Cannot subscribe to atom "${atomToken.key}" because it has not been initialized in store "${store.config.name}"`
@@ -2100,6 +2115,30 @@ var addAtomToTimeline = (atomToken, tl, store) => {
2100
2115
  });
2101
2116
  };
2102
2117
 
2118
+ // internal/src/mutable/is-mutable.ts
2119
+ function isMutable(atomOrTokenOrFamily, store) {
2120
+ if (`mutable` in atomOrTokenOrFamily) {
2121
+ return atomOrTokenOrFamily.mutable;
2122
+ }
2123
+ if (atomOrTokenOrFamily.type === `atom_family`) {
2124
+ return false;
2125
+ }
2126
+ if (`default` in atomOrTokenOrFamily) {
2127
+ return false;
2128
+ }
2129
+ if (!store) {
2130
+ throw new Error(`Cannot check mutability without a store`);
2131
+ }
2132
+ const atom2 = withdraw(atomOrTokenOrFamily, store);
2133
+ if (!atom2) {
2134
+ throw new Error(`Cannot check mutability without an atom`);
2135
+ }
2136
+ if (`mutable` in atom2) {
2137
+ return atom2.mutable;
2138
+ }
2139
+ return false;
2140
+ }
2141
+
2103
2142
  // internal/src/timeline/create-timeline.ts
2104
2143
  function createTimeline(options, store, data) {
2105
2144
  var _a, _b;
@@ -2118,20 +2157,26 @@ function createTimeline(options, store, data) {
2118
2157
  if (options.shouldCapture) {
2119
2158
  tl.shouldCapture = options.shouldCapture;
2120
2159
  }
2160
+ const timelineKey = options.key;
2121
2161
  const target = newest(store);
2122
2162
  for (const tokenOrFamily of options.atoms) {
2123
- const timelineKey = target.timelineAtoms.getRelatedKey(tokenOrFamily.key);
2124
- if (timelineKey) {
2163
+ let atomKey = tokenOrFamily.key;
2164
+ const existingTimelineKey = target.timelineAtoms.getRelatedKey(atomKey);
2165
+ if (existingTimelineKey) {
2125
2166
  store.logger.error(
2126
2167
  `\u274C`,
2127
2168
  `timeline`,
2128
2169
  options.key,
2129
- `Failed to add atom "${tokenOrFamily.key}" because it already belongs to timeline "${timelineKey}"`
2170
+ `Failed to add atom "${atomKey}" because it already belongs to timeline "${existingTimelineKey}"`
2130
2171
  );
2131
2172
  continue;
2132
2173
  }
2133
2174
  if (tokenOrFamily.type === `atom_family`) {
2134
- const family = tokenOrFamily;
2175
+ let family = tokenOrFamily;
2176
+ if (isMutable(family)) {
2177
+ family = getUpdateFamily(family, store);
2178
+ atomKey = family.key;
2179
+ }
2135
2180
  family.subject.subscribe(`timeline:${options.key}`, (token2) => {
2136
2181
  addAtomToTimeline(token2, tl, store);
2137
2182
  });
@@ -2141,31 +2186,51 @@ function createTimeline(options, store, data) {
2141
2186
  }
2142
2187
  }
2143
2188
  } else {
2144
- const token2 = tokenOrFamily;
2145
- if (`family` in token2 && token2.family) {
2189
+ let atom2 = withdraw(tokenOrFamily, store);
2190
+ if (atom2 === void 0) {
2191
+ store.logger.error(
2192
+ `\u274C`,
2193
+ `timeline`,
2194
+ options.key,
2195
+ `Failed to add atom "${atomKey}" because it does not exist in the store`
2196
+ );
2197
+ continue;
2198
+ }
2199
+ if (isMutable(atom2)) {
2200
+ const updateAtom = withdraw(getUpdateToken(atom2), store);
2201
+ if (updateAtom === void 0) {
2202
+ store.logger.error(
2203
+ `\u274C`,
2204
+ `timeline`,
2205
+ options.key,
2206
+ `Failed to add update atom "${atomKey}" because it does not exist in the store`
2207
+ );
2208
+ continue;
2209
+ }
2210
+ atom2 = updateAtom;
2211
+ atomKey = atom2.key;
2212
+ }
2213
+ if (`family` in atom2) {
2146
2214
  const familyTimelineKey = target.timelineAtoms.getRelatedKey(
2147
- token2.family.key
2215
+ atom2.family.key
2148
2216
  );
2149
2217
  if (familyTimelineKey) {
2150
2218
  store.logger.error(
2151
2219
  `\u274C`,
2152
2220
  `timeline`,
2153
2221
  options.key,
2154
- `Failed to add atom "${token2.key}" because its family "${token2.family.key}" already belongs to timeline "${familyTimelineKey}"`
2222
+ `Failed to add atom "${atom2.key}" because its family "${atom2.family.key}" already belongs to timeline "${familyTimelineKey}"`
2155
2223
  );
2156
2224
  continue;
2157
2225
  }
2158
2226
  }
2159
- addAtomToTimeline(token2, tl, store);
2227
+ addAtomToTimeline(atom2, tl, store);
2160
2228
  }
2161
- target.timelineAtoms = target.timelineAtoms.set({
2162
- atomKey: tokenOrFamily.key,
2163
- timelineKey: options.key
2164
- });
2229
+ target.timelineAtoms.set({ atomKey, timelineKey });
2165
2230
  }
2166
2231
  store.timelines.set(options.key, tl);
2167
2232
  const token = {
2168
- key: options.key,
2233
+ key: timelineKey,
2169
2234
  type: `timeline`
2170
2235
  };
2171
2236
  store.subject.timelineCreation.next(token);
@@ -2511,6 +2576,6 @@ var selectJsonFamily = (atomFamily2, transform, store = IMPLICIT.STORE) => {
2511
2576
  return jsonFamily;
2512
2577
  };
2513
2578
 
2514
- export { AtomIOLogger, FamilyTracker, Future, IMPLICIT, JSON_DEFAULTS, JSON_TYPE_NAMES, Junction, LOG_LEVELS, LazyMap, NotFoundError, Silo, StatefulSubject, Store, Subject, TRANSACTION_PHASES, Tracker, __objRest, __restKey, __spreadProps, __spreadValues, abortTransaction, addAtomToTimeline, applyTransaction, atom, atomFamily, become, buildTransaction, cacheValue, clearStore, closeOperation, createAtom, createAtomFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelectorFamily, createSelector, createSelectorFamily, createTimeline, createTransaction, deleteAtom, deleteSelector, deposit, dispose, eldest, evictCachedValue, getJsonFamily, getJsonToken, getSelectorDependencyKeys, getState, getUpdateToken, isAtomDefault, isAtomKey, isAtomMutable, isAtomTokenMutable, isBoolean, isDone, isNull, isNumber, isPrimitive, isReadonlySelectorKey, isSelectorDefault, isSelectorKey, isStateKey, isString, isTransceiver, isValueCached, markAtomAsDefault, markAtomAsNotDefault, markDone, newest, openOperation, parseJson, readCachedValue, readOrComputeValue, redo, redoTransactionUpdate, registerSelector, runTransaction, selectJson, selectJsonFamily, selector, selectorFamily, setAtomOrSelector, setState, simpleLog, simpleLogger, stringSetJsonInterface, stringifyJson, subscribe, subscribeToRootAtoms, subscribeToState, subscribeToTimeline, subscribeToTransaction, timeTravel, timeline, traceAllSelectorAtoms, traceSelectorAtoms, transaction, undo, undoTransactionUpdate, updateSelectorAtoms, withdraw, withdrawNewFamilyMember };
2579
+ export { AtomIOLogger, FamilyTracker, Future, IMPLICIT, JSON_DEFAULTS, JSON_TYPE_NAMES, Junction, LOG_LEVELS, LazyMap, NotFoundError, Silo, StatefulSubject, Store, Subject, TRANSACTION_PHASES, Tracker, __objRest, __restKey, __spreadProps, __spreadValues, abortTransaction, addAtomToTimeline, applyTransaction, atom, atomFamily, become, buildTransaction, cacheValue, clearStore, closeOperation, createAtom, createAtomFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelectorFamily, createSelector, createSelectorFamily, createTimeline, createTransaction, deleteAtom, deleteSelector, deposit, dispose, eldest, evictCachedValue, getJsonFamily, getJsonToken, getSelectorDependencyKeys, getState, getUpdateFamily, getUpdateToken, isAtomDefault, isAtomKey, isBoolean, isDone, isNull, isNumber, isPrimitive, isReadonlySelectorKey, isSelectorDefault, isSelectorKey, isStateKey, isString, isTransceiver, isValueCached, markAtomAsDefault, markAtomAsNotDefault, markDone, newest, openOperation, parseJson, readCachedValue, readOrComputeValue, redo, redoTransactionUpdate, registerSelector, runTransaction, selectJson, selectJsonFamily, selector, selectorFamily, setAtomOrSelector, setState, simpleLog, simpleLogger, stringSetJsonInterface, stringifyJson, subscribe, subscribeToRootAtoms, subscribeToState, subscribeToTimeline, subscribeToTransaction, timeTravel, timeline, traceAllSelectorAtoms, traceSelectorAtoms, transaction, undo, undoTransactionUpdate, updateSelectorAtoms, withdraw, withdrawNewFamilyMember };
2515
2580
  //# sourceMappingURL=out.js.map
2516
- //# sourceMappingURL=chunk-TE3ZSTQ6.js.map
2581
+ //# sourceMappingURL=chunk-PURABO5G.js.map