atom.io 0.8.0 → 0.8.2

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 (73) hide show
  1. package/dist/index.d.mts +8 -5
  2. package/dist/index.d.ts +8 -5
  3. package/dist/index.js +67 -72
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +34 -38
  6. package/dist/index.mjs.map +1 -1
  7. package/internal/dist/index.d.mts +27 -33
  8. package/internal/dist/index.d.ts +27 -33
  9. package/internal/dist/index.js +45 -69
  10. package/internal/dist/index.js.map +1 -1
  11. package/internal/dist/index.mjs +34 -39
  12. package/internal/dist/index.mjs.map +1 -1
  13. package/internal/src/caching.ts +12 -5
  14. package/internal/src/future.ts +2 -4
  15. package/internal/src/mutable/create-mutable-atom-family.ts +4 -4
  16. package/internal/src/mutable/create-mutable-atom.ts +6 -5
  17. package/internal/src/mutable/is-atom-token-mutable.ts +3 -3
  18. package/internal/src/mutable/tracker-family.ts +4 -4
  19. package/internal/src/mutable/tracker.ts +20 -19
  20. package/internal/src/operation.ts +5 -2
  21. package/internal/src/selector/create-read-write-selector.ts +2 -2
  22. package/internal/src/selector/register-selector.ts +2 -2
  23. package/internal/src/set-state/{set-atom-state.ts → set-atom.ts} +1 -1
  24. package/internal/src/set-state/set-selector-state.ts +1 -12
  25. package/internal/src/set-state/set-state-internal.ts +4 -5
  26. package/internal/src/store/withdraw-new-family-member.ts +7 -7
  27. package/internal/src/store/withdraw.ts +15 -9
  28. package/internal/src/subscribe/subscribe-to-root-atoms.ts +1 -1
  29. package/internal/src/timeline/add-atom-to-timeline.ts +2 -2
  30. package/internal/src/transaction/apply-transaction.ts +1 -1
  31. package/internal/src/transaction/redo-transaction.ts +1 -1
  32. package/internal/src/transaction/undo-transaction.ts +1 -1
  33. package/package.json +11 -8
  34. package/react-devtools/dist/index.d.mts +4 -4
  35. package/react-devtools/dist/index.d.ts +4 -4
  36. package/react-devtools/dist/index.js +3 -3
  37. package/react-devtools/dist/index.js.map +1 -1
  38. package/react-devtools/dist/index.mjs +3 -3
  39. package/react-devtools/dist/index.mjs.map +1 -1
  40. package/realtime-client/dist/index.d.mts +21 -0
  41. package/realtime-client/dist/index.d.ts +21 -0
  42. package/realtime-client/dist/index.js +173 -0
  43. package/realtime-client/dist/index.js.map +1 -0
  44. package/realtime-client/dist/index.mjs +144 -0
  45. package/realtime-client/dist/index.mjs.map +1 -0
  46. package/realtime-client/package.json +15 -0
  47. package/realtime-client/src/index.ts +7 -0
  48. package/realtime-client/src/realtime-state.ts +10 -0
  49. package/realtime-client/src/use-pull-family-member.ts +26 -0
  50. package/realtime-client/src/use-pull-mutable-family-member.ts +38 -0
  51. package/realtime-client/src/use-pull-mutable.ts +32 -0
  52. package/realtime-client/src/use-pull.ts +19 -0
  53. package/realtime-client/src/use-push.ts +25 -0
  54. package/realtime-client/src/use-server-action.ts +49 -0
  55. package/realtime-server/dist/index.d.mts +25 -0
  56. package/realtime-server/dist/index.d.ts +25 -0
  57. package/realtime-server/dist/index.js +316 -0
  58. package/realtime-server/dist/index.js.map +1 -0
  59. package/realtime-server/dist/index.mjs +289 -0
  60. package/realtime-server/dist/index.mjs.map +1 -0
  61. package/realtime-server/package.json +15 -0
  62. package/realtime-server/src/README.md +33 -0
  63. package/realtime-server/src/hook-composition/expose-family.ts +105 -0
  64. package/realtime-server/src/hook-composition/expose-mutable-family.ts +127 -0
  65. package/realtime-server/src/hook-composition/expose-mutable.ts +45 -0
  66. package/realtime-server/src/hook-composition/expose-single.ts +39 -0
  67. package/realtime-server/src/hook-composition/index.ts +14 -0
  68. package/realtime-server/src/hook-composition/receive-state.ts +30 -0
  69. package/realtime-server/src/hook-composition/receive-transaction.ts +37 -0
  70. package/realtime-server/src/index.ts +1 -0
  71. package/src/get-set.ts +48 -0
  72. package/src/index.ts +3 -60
  73. package/src/subscribe.ts +3 -3
@@ -1,5 +1,4 @@
1
- import * as AtomIO from 'atom.io';
2
- import { setState, getState, subscribe } from 'atom.io';
1
+ import { setState, getState, subscribe, subscribeToTimeline } from 'atom.io';
3
2
  import { selectJson, stringifyJson, parseJson, selectJsonFamily } from 'atom.io/json';
4
3
 
5
4
  var __defProp = Object.defineProperty;
@@ -126,7 +125,7 @@ var applyTransaction = (output, store) => {
126
125
  { key: store.transactionStatus.key, type: `transaction` },
127
126
  store
128
127
  );
129
- if (myTransaction === null) {
128
+ if (myTransaction === void 0) {
130
129
  throw new Error(
131
130
  `Transaction "${store.transactionStatus.key}" not found. Absurd. How is this running?`
132
131
  );
@@ -414,7 +413,7 @@ var redoTransactionUpdate = (update, store) => {
414
413
  for (const { key, newValue } of update.atomUpdates) {
415
414
  const token = { key, type: `atom` };
416
415
  const state = withdraw(token, store);
417
- if (state === null) {
416
+ if (state === void 0) {
418
417
  throw new Error(
419
418
  `State "${token.key}" not found in this store. This is surprising, because we are navigating the history of the store.`
420
419
  );
@@ -428,7 +427,7 @@ var undoTransactionUpdate = (update, store) => {
428
427
  for (const { key, oldValue } of update.atomUpdates) {
429
428
  const token = { key, type: `atom` };
430
429
  const state = withdraw(token, store);
431
- if (state === null) {
430
+ if (state === void 0) {
432
431
  throw new Error(
433
432
  `State "${token.key}" not found in this store. This is surprising, because we are navigating the history of the store.`
434
433
  );
@@ -544,7 +543,7 @@ var clearStore = (store = IMPLICIT.STORE) => {
544
543
  // src/timeline/add-atom-to-timeline.ts
545
544
  var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
546
545
  const atom = withdraw(atomToken, store);
547
- if (atom === null) {
546
+ if (atom === void 0) {
548
547
  throw new Error(
549
548
  `Cannot subscribe to atom "${atomToken.key}" because it has not been initialized in store "${store.config.name}"`
550
549
  );
@@ -576,7 +575,7 @@ var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
576
575
  { key: currentTransactionKey, type: `transaction` },
577
576
  store
578
577
  );
579
- if (currentTransaction === null) {
578
+ if (currentTransaction === void 0) {
580
579
  throw new Error(
581
580
  `Transaction "${currentTransactionKey}" not found in store "${store.config.name}". This is surprising, because we are in the application phase of "${currentTransactionKey}".`
582
581
  );
@@ -875,7 +874,7 @@ function withdraw(token, store) {
875
874
  return state;
876
875
  }
877
876
  }
878
- return null;
877
+ return void 0;
879
878
  }
880
879
 
881
880
  // src/store/withdraw-new-family-member.ts
@@ -894,7 +893,7 @@ function withdrawNewFamilyMember(token, store) {
894
893
  return state;
895
894
  }
896
895
  }
897
- return null;
896
+ return void 0;
898
897
  }
899
898
 
900
899
  // src/caching.ts
@@ -909,6 +908,12 @@ var cacheValue = (key, value, subject, store = IMPLICIT.STORE) => {
909
908
  future.then((value2) => {
910
909
  cacheValue(key, value2, subject, store);
911
910
  subject.next({ newValue: value2, oldValue: value2 });
911
+ }).catch((error) => {
912
+ var _a;
913
+ (_a = store.config.logger) == null ? void 0 : _a.error(
914
+ `Promised value for "${key}" rejected:`,
915
+ error
916
+ );
912
917
  });
913
918
  } else {
914
919
  target(store).valueMap.set(key, value);
@@ -944,7 +949,7 @@ var Tracker = class {
944
949
  return latestUpdateState;
945
950
  }
946
951
  observeCore(mutableState, latestUpdateState, store = IMPLICIT.STORE) {
947
- const originalInnerValue = AtomIO.getState(mutableState, store);
952
+ const originalInnerValue = getState(mutableState, store);
948
953
  this.unsubscribeFromInnerValue = originalInnerValue.subscribe(
949
954
  `tracker:${store.config.name}:${store.transactionStatus.phase === `idle` ? `main` : store.transactionStatus.key}`,
950
955
  (update) => {
@@ -952,12 +957,12 @@ var Tracker = class {
952
957
  mutableState.key,
953
958
  () => {
954
959
  unsubscribe();
955
- AtomIO.setState(latestUpdateState, update, store);
960
+ setState(latestUpdateState, update, store);
956
961
  }
957
962
  );
958
963
  }
959
964
  );
960
- AtomIO.subscribe(
965
+ subscribe(
961
966
  mutableState,
962
967
  (update) => {
963
968
  var _a;
@@ -970,7 +975,7 @@ var Tracker = class {
970
975
  mutableState.key,
971
976
  () => {
972
977
  unsubscribe();
973
- AtomIO.setState(latestUpdateState, update2, store);
978
+ setState(latestUpdateState, update2, store);
974
979
  }
975
980
  );
976
981
  }
@@ -982,7 +987,7 @@ var Tracker = class {
982
987
  );
983
988
  }
984
989
  updateCore(mutableState, latestUpdateState, store = IMPLICIT.STORE) {
985
- AtomIO.subscribe(
990
+ subscribe(
986
991
  latestUpdateState,
987
992
  ({ newValue, oldValue }) => {
988
993
  const timelineId = store.timelineAtoms.getRelatedKey(
@@ -991,11 +996,11 @@ var Tracker = class {
991
996
  if (timelineId) {
992
997
  const timelineData = store.timelines.get(timelineId);
993
998
  if (timelineData == null ? void 0 : timelineData.timeTraveling) {
994
- const unsubscribe2 = AtomIO.subscribeToTimeline(
999
+ const unsubscribe2 = subscribeToTimeline(
995
1000
  { key: timelineId, type: `timeline` },
996
1001
  (update) => {
997
1002
  unsubscribe2();
998
- AtomIO.setState(
1003
+ setState(
999
1004
  mutableState,
1000
1005
  (transceiver) => {
1001
1006
  if (update === `redo` && newValue) {
@@ -1017,7 +1022,7 @@ var Tracker = class {
1017
1022
  () => {
1018
1023
  unsubscribe();
1019
1024
  if (newValue) {
1020
- AtomIO.setState(
1025
+ setState(
1021
1026
  mutableState,
1022
1027
  (transceiver) => (transceiver.do(newValue), transceiver),
1023
1028
  store
@@ -1041,7 +1046,7 @@ function createMutableAtom(options, store = IMPLICIT.STORE) {
1041
1046
  const coreState = createAtom(options, void 0, store);
1042
1047
  new Tracker(coreState, store);
1043
1048
  const jsonState = selectJson(coreState, options, store);
1044
- AtomIO.subscribe(
1049
+ subscribe(
1045
1050
  jsonState,
1046
1051
  () => {
1047
1052
  var _a2;
@@ -1129,7 +1134,7 @@ var openOperation = (token, store) => {
1129
1134
  (_a = store.config.logger) == null ? void 0 : _a.error(
1130
1135
  `\u274C failed to setState to "${token.key}" during a setState for "${core.operation.token.key}"`
1131
1136
  );
1132
- throw Symbol(`violation`);
1137
+ return `rejection`;
1133
1138
  }
1134
1139
  core.operation = {
1135
1140
  open: true,
@@ -1307,8 +1312,8 @@ var stowUpdate = (state, update, store) => {
1307
1312
  logger == null ? void 0 : logger.info(`\u{1F4DD} ${key} stowed (`, update.oldValue, `->`, update.newValue, `)`);
1308
1313
  };
1309
1314
 
1310
- // src/set-state/set-atom-state.ts
1311
- var setAtomState = (atom, next, store = IMPLICIT.STORE) => {
1315
+ // src/set-state/set-atom.ts
1316
+ var setAtom = (atom, next, store = IMPLICIT.STORE) => {
1312
1317
  var _a, _b;
1313
1318
  const oldValue = getState__INTERNAL(atom, store);
1314
1319
  let newValue = copyMutableIfWithinTransaction(atom, store);
@@ -1331,22 +1336,12 @@ var setAtomState = (atom, next, store = IMPLICIT.STORE) => {
1331
1336
  }
1332
1337
  };
1333
1338
 
1334
- // src/set-state/set-selector-state.ts
1335
- var setSelectorState = (selector, next, store = IMPLICIT.STORE) => {
1336
- var _a, _b;
1337
- const oldValue = getState__INTERNAL(selector, store);
1338
- const newValue = become(next)(oldValue);
1339
- (_a = store.config.logger) == null ? void 0 : _a.info(`<< setting selector "${selector.key}" to`, newValue);
1340
- (_b = store.config.logger) == null ? void 0 : _b.info(` || propagating change made to "${selector.key}"`);
1341
- selector.set(newValue);
1342
- };
1343
-
1344
1339
  // src/set-state/set-state-internal.ts
1345
1340
  var setState__INTERNAL = (state, value, store = IMPLICIT.STORE) => {
1346
- if (`set` in state) {
1347
- setSelectorState(state, value, store);
1341
+ if (state.type === `selector`) {
1342
+ state.set(value);
1348
1343
  } else {
1349
- setAtomState(state, value, store);
1344
+ setAtom(state, value, store);
1350
1345
  }
1351
1346
  };
1352
1347
 
@@ -1412,7 +1407,7 @@ var registerSelector = (selectorKey, store = IMPLICIT.STORE) => ({
1412
1407
  const core = target(store);
1413
1408
  const alreadyRegistered = core.selectorGraph.getRelationEntries({ downstreamSelectorKey: selectorKey }).some(([_, { source }]) => source === dependency.key);
1414
1409
  const dependencyState = withdraw(dependency, store);
1415
- if (dependencyState === null) {
1410
+ if (dependencyState === void 0) {
1416
1411
  throw new Error(
1417
1412
  `State "${dependency.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`
1418
1413
  );
@@ -1444,7 +1439,7 @@ var registerSelector = (selectorKey, store = IMPLICIT.STORE) => ({
1444
1439
  },
1445
1440
  set: (stateToken, newValue) => {
1446
1441
  const state = withdraw(stateToken, store);
1447
- if (state === null) {
1442
+ if (state === void 0) {
1448
1443
  throw new Error(
1449
1444
  `State "${stateToken.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`
1450
1445
  );
@@ -1466,14 +1461,14 @@ var createReadWriteSelector = (options, family, store, core) => {
1466
1461
  const setSelf = (next) => {
1467
1462
  var _a2;
1468
1463
  const oldValue = getSelf();
1464
+ const newValue = become(next)(oldValue);
1469
1465
  (_a2 = store.config.logger) == null ? void 0 : _a2.info(
1470
1466
  ` <- "${options.key}" went (`,
1471
1467
  oldValue,
1472
1468
  `->`,
1473
- next,
1469
+ newValue,
1474
1470
  `)`
1475
1471
  );
1476
- const newValue = become(next)(oldValue);
1477
1472
  cacheValue(options.key, newValue, subject, store);
1478
1473
  markDone(options.key, store);
1479
1474
  if (store.transactionStatus.phase === `idle`) {
@@ -1793,7 +1788,7 @@ var recallState = (state, store = IMPLICIT.STORE) => {
1793
1788
  var subscribeToRootAtoms = (state, store) => {
1794
1789
  const dependencySubscriptions = `default` in state ? null : traceAllSelectorAtoms(state.key, store).map((atomToken) => {
1795
1790
  const atom = withdraw(atomToken, store);
1796
- if (atom === null) {
1791
+ if (atom === void 0) {
1797
1792
  throw new Error(
1798
1793
  `Atom "${atomToken.key}", a dependency of selector "${state.key}", not found in store "${store.config.name}".`
1799
1794
  );