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,28 +1,8 @@
1
1
  'use strict';
2
2
 
3
- var AtomIO = require('atom.io');
3
+ var atom_io = require('atom.io');
4
4
  var json = require('atom.io/json');
5
5
 
6
- function _interopNamespace(e) {
7
- if (e && e.__esModule) return e;
8
- var n = Object.create(null);
9
- if (e) {
10
- Object.keys(e).forEach(function (k) {
11
- if (k !== 'default') {
12
- var d = Object.getOwnPropertyDescriptor(e, k);
13
- Object.defineProperty(n, k, d.get ? d : {
14
- enumerable: true,
15
- get: function () { return e[k]; }
16
- });
17
- }
18
- });
19
- }
20
- n.default = e;
21
- return Object.freeze(n);
22
- }
23
-
24
- var AtomIO__namespace = /*#__PURE__*/_interopNamespace(AtomIO);
25
-
26
6
  var __defProp = Object.defineProperty;
27
7
  var __defProps = Object.defineProperties;
28
8
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
@@ -141,13 +121,13 @@ var applyTransaction = (output, store) => {
141
121
  (_d = store.config.logger) == null ? void 0 : _d.info(`\u{1F527}`, `add atom "${newAtom.key}"`);
142
122
  }
143
123
  }
144
- AtomIO.setState(token, newValue, store);
124
+ atom_io.setState(token, newValue, store);
145
125
  }
146
126
  const myTransaction = withdraw(
147
127
  { key: store.transactionStatus.key, type: `transaction` },
148
128
  store
149
129
  );
150
- if (myTransaction === null) {
130
+ if (myTransaction === void 0) {
151
131
  throw new Error(
152
132
  `Transaction "${store.transactionStatus.key}" not found. Absurd. How is this running?`
153
133
  );
@@ -403,8 +383,8 @@ function transaction__INTERNAL(options, store = IMPLICIT.STORE) {
403
383
  try {
404
384
  const output = options.do(
405
385
  {
406
- get: (token2) => AtomIO.getState(token2, store),
407
- set: (token2, value) => AtomIO.setState(token2, value, store)
386
+ get: (token2) => atom_io.getState(token2, store),
387
+ set: (token2, value) => atom_io.setState(token2, value, store)
408
388
  },
409
389
  ...params
410
390
  );
@@ -435,12 +415,12 @@ var redoTransactionUpdate = (update, store) => {
435
415
  for (const { key, newValue } of update.atomUpdates) {
436
416
  const token = { key, type: `atom` };
437
417
  const state = withdraw(token, store);
438
- if (state === null) {
418
+ if (state === void 0) {
439
419
  throw new Error(
440
420
  `State "${token.key}" not found in this store. This is surprising, because we are navigating the history of the store.`
441
421
  );
442
422
  }
443
- AtomIO.setState(state, newValue, store);
423
+ atom_io.setState(state, newValue, store);
444
424
  }
445
425
  };
446
426
  var undoTransactionUpdate = (update, store) => {
@@ -449,12 +429,12 @@ var undoTransactionUpdate = (update, store) => {
449
429
  for (const { key, oldValue } of update.atomUpdates) {
450
430
  const token = { key, type: `atom` };
451
431
  const state = withdraw(token, store);
452
- if (state === null) {
432
+ if (state === void 0) {
453
433
  throw new Error(
454
434
  `State "${token.key}" not found in this store. This is surprising, because we are navigating the history of the store.`
455
435
  );
456
436
  }
457
- AtomIO.setState(state, oldValue, store);
437
+ atom_io.setState(state, oldValue, store);
458
438
  }
459
439
  };
460
440
 
@@ -565,7 +545,7 @@ var clearStore = (store = IMPLICIT.STORE) => {
565
545
  // src/timeline/add-atom-to-timeline.ts
566
546
  var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
567
547
  const atom = withdraw(atomToken, store);
568
- if (atom === null) {
548
+ if (atom === void 0) {
569
549
  throw new Error(
570
550
  `Cannot subscribe to atom "${atomToken.key}" because it has not been initialized in store "${store.config.name}"`
571
551
  );
@@ -597,7 +577,7 @@ var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
597
577
  { key: currentTransactionKey, type: `transaction` },
598
578
  store
599
579
  );
600
- if (currentTransaction === null) {
580
+ if (currentTransaction === void 0) {
601
581
  throw new Error(
602
582
  `Transaction "${currentTransactionKey}" not found in store "${store.config.name}". This is surprising, because we are in the application phase of "${currentTransactionKey}".`
603
583
  );
@@ -731,14 +711,14 @@ var redo__INTERNAL = (token, store = IMPLICIT.STORE) => {
731
711
  switch (update.type) {
732
712
  case `atom_update`: {
733
713
  const { key, newValue } = update;
734
- AtomIO.setState({ key, type: `atom` }, newValue, store);
714
+ atom_io.setState({ key, type: `atom` }, newValue, store);
735
715
  break;
736
716
  }
737
717
  case `selector_update`:
738
718
  case `transaction_update`: {
739
719
  for (const atomUpdate of update.atomUpdates) {
740
720
  const { key, newValue } = atomUpdate;
741
- AtomIO.setState({ key, type: `atom` }, newValue, store);
721
+ atom_io.setState({ key, type: `atom` }, newValue, store);
742
722
  }
743
723
  break;
744
724
  }
@@ -772,14 +752,14 @@ var undo__INTERNAL = (token, store = IMPLICIT.STORE) => {
772
752
  switch (update.type) {
773
753
  case `atom_update`: {
774
754
  const { key, oldValue } = update;
775
- AtomIO.setState({ key, type: `atom` }, oldValue, store);
755
+ atom_io.setState({ key, type: `atom` }, oldValue, store);
776
756
  break;
777
757
  }
778
758
  case `selector_update`:
779
759
  case `transaction_update`: {
780
760
  for (const atomUpdate of [...update.atomUpdates].reverse()) {
781
761
  const { key, oldValue } = atomUpdate;
782
- AtomIO.setState({ key, type: `atom` }, oldValue, store);
762
+ atom_io.setState({ key, type: `atom` }, oldValue, store);
783
763
  }
784
764
  break;
785
765
  }
@@ -896,7 +876,7 @@ function withdraw(token, store) {
896
876
  return state;
897
877
  }
898
878
  }
899
- return null;
879
+ return void 0;
900
880
  }
901
881
 
902
882
  // src/store/withdraw-new-family-member.ts
@@ -915,7 +895,7 @@ function withdrawNewFamilyMember(token, store) {
915
895
  return state;
916
896
  }
917
897
  }
918
- return null;
898
+ return void 0;
919
899
  }
920
900
 
921
901
  // src/caching.ts
@@ -930,6 +910,12 @@ var cacheValue = (key, value, subject, store = IMPLICIT.STORE) => {
930
910
  future.then((value2) => {
931
911
  cacheValue(key, value2, subject, store);
932
912
  subject.next({ newValue: value2, oldValue: value2 });
913
+ }).catch((error) => {
914
+ var _a;
915
+ (_a = store.config.logger) == null ? void 0 : _a.error(
916
+ `Promised value for "${key}" rejected:`,
917
+ error
918
+ );
933
919
  });
934
920
  } else {
935
921
  target(store).valueMap.set(key, value);
@@ -965,7 +951,7 @@ var Tracker = class {
965
951
  return latestUpdateState;
966
952
  }
967
953
  observeCore(mutableState, latestUpdateState, store = IMPLICIT.STORE) {
968
- const originalInnerValue = AtomIO__namespace.getState(mutableState, store);
954
+ const originalInnerValue = atom_io.getState(mutableState, store);
969
955
  this.unsubscribeFromInnerValue = originalInnerValue.subscribe(
970
956
  `tracker:${store.config.name}:${store.transactionStatus.phase === `idle` ? `main` : store.transactionStatus.key}`,
971
957
  (update) => {
@@ -973,12 +959,12 @@ var Tracker = class {
973
959
  mutableState.key,
974
960
  () => {
975
961
  unsubscribe();
976
- AtomIO__namespace.setState(latestUpdateState, update, store);
962
+ atom_io.setState(latestUpdateState, update, store);
977
963
  }
978
964
  );
979
965
  }
980
966
  );
981
- AtomIO__namespace.subscribe(
967
+ atom_io.subscribe(
982
968
  mutableState,
983
969
  (update) => {
984
970
  var _a;
@@ -991,7 +977,7 @@ var Tracker = class {
991
977
  mutableState.key,
992
978
  () => {
993
979
  unsubscribe();
994
- AtomIO__namespace.setState(latestUpdateState, update2, store);
980
+ atom_io.setState(latestUpdateState, update2, store);
995
981
  }
996
982
  );
997
983
  }
@@ -1003,7 +989,7 @@ var Tracker = class {
1003
989
  );
1004
990
  }
1005
991
  updateCore(mutableState, latestUpdateState, store = IMPLICIT.STORE) {
1006
- AtomIO__namespace.subscribe(
992
+ atom_io.subscribe(
1007
993
  latestUpdateState,
1008
994
  ({ newValue, oldValue }) => {
1009
995
  const timelineId = store.timelineAtoms.getRelatedKey(
@@ -1012,11 +998,11 @@ var Tracker = class {
1012
998
  if (timelineId) {
1013
999
  const timelineData = store.timelines.get(timelineId);
1014
1000
  if (timelineData == null ? void 0 : timelineData.timeTraveling) {
1015
- const unsubscribe2 = AtomIO__namespace.subscribeToTimeline(
1001
+ const unsubscribe2 = atom_io.subscribeToTimeline(
1016
1002
  { key: timelineId, type: `timeline` },
1017
1003
  (update) => {
1018
1004
  unsubscribe2();
1019
- AtomIO__namespace.setState(
1005
+ atom_io.setState(
1020
1006
  mutableState,
1021
1007
  (transceiver) => {
1022
1008
  if (update === `redo` && newValue) {
@@ -1038,7 +1024,7 @@ var Tracker = class {
1038
1024
  () => {
1039
1025
  unsubscribe();
1040
1026
  if (newValue) {
1041
- AtomIO__namespace.setState(
1027
+ atom_io.setState(
1042
1028
  mutableState,
1043
1029
  (transceiver) => (transceiver.do(newValue), transceiver),
1044
1030
  store
@@ -1062,7 +1048,7 @@ function createMutableAtom(options, store = IMPLICIT.STORE) {
1062
1048
  const coreState = createAtom(options, void 0, store);
1063
1049
  new Tracker(coreState, store);
1064
1050
  const jsonState = json.selectJson(coreState, options, store);
1065
- AtomIO__namespace.subscribe(
1051
+ atom_io.subscribe(
1066
1052
  jsonState,
1067
1053
  () => {
1068
1054
  var _a2;
@@ -1150,7 +1136,7 @@ var openOperation = (token, store) => {
1150
1136
  (_a = store.config.logger) == null ? void 0 : _a.error(
1151
1137
  `\u274C failed to setState to "${token.key}" during a setState for "${core.operation.token.key}"`
1152
1138
  );
1153
- throw Symbol(`violation`);
1139
+ return `rejection`;
1154
1140
  }
1155
1141
  core.operation = {
1156
1142
  open: true,
@@ -1328,8 +1314,8 @@ var stowUpdate = (state, update, store) => {
1328
1314
  logger == null ? void 0 : logger.info(`\u{1F4DD} ${key} stowed (`, update.oldValue, `->`, update.newValue, `)`);
1329
1315
  };
1330
1316
 
1331
- // src/set-state/set-atom-state.ts
1332
- var setAtomState = (atom, next, store = IMPLICIT.STORE) => {
1317
+ // src/set-state/set-atom.ts
1318
+ var setAtom = (atom, next, store = IMPLICIT.STORE) => {
1333
1319
  var _a, _b;
1334
1320
  const oldValue = getState__INTERNAL(atom, store);
1335
1321
  let newValue = copyMutableIfWithinTransaction(atom, store);
@@ -1352,22 +1338,12 @@ var setAtomState = (atom, next, store = IMPLICIT.STORE) => {
1352
1338
  }
1353
1339
  };
1354
1340
 
1355
- // src/set-state/set-selector-state.ts
1356
- var setSelectorState = (selector, next, store = IMPLICIT.STORE) => {
1357
- var _a, _b;
1358
- const oldValue = getState__INTERNAL(selector, store);
1359
- const newValue = become(next)(oldValue);
1360
- (_a = store.config.logger) == null ? void 0 : _a.info(`<< setting selector "${selector.key}" to`, newValue);
1361
- (_b = store.config.logger) == null ? void 0 : _b.info(` || propagating change made to "${selector.key}"`);
1362
- selector.set(newValue);
1363
- };
1364
-
1365
1341
  // src/set-state/set-state-internal.ts
1366
1342
  var setState__INTERNAL = (state, value, store = IMPLICIT.STORE) => {
1367
- if (`set` in state) {
1368
- setSelectorState(state, value, store);
1343
+ if (state.type === `selector`) {
1344
+ state.set(value);
1369
1345
  } else {
1370
- setAtomState(state, value, store);
1346
+ setAtom(state, value, store);
1371
1347
  }
1372
1348
  };
1373
1349
 
@@ -1433,7 +1409,7 @@ var registerSelector = (selectorKey, store = IMPLICIT.STORE) => ({
1433
1409
  const core = target(store);
1434
1410
  const alreadyRegistered = core.selectorGraph.getRelationEntries({ downstreamSelectorKey: selectorKey }).some(([_, { source }]) => source === dependency.key);
1435
1411
  const dependencyState = withdraw(dependency, store);
1436
- if (dependencyState === null) {
1412
+ if (dependencyState === void 0) {
1437
1413
  throw new Error(
1438
1414
  `State "${dependency.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`
1439
1415
  );
@@ -1465,7 +1441,7 @@ var registerSelector = (selectorKey, store = IMPLICIT.STORE) => ({
1465
1441
  },
1466
1442
  set: (stateToken, newValue) => {
1467
1443
  const state = withdraw(stateToken, store);
1468
- if (state === null) {
1444
+ if (state === void 0) {
1469
1445
  throw new Error(
1470
1446
  `State "${stateToken.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`
1471
1447
  );
@@ -1487,14 +1463,14 @@ var createReadWriteSelector = (options, family, store, core) => {
1487
1463
  const setSelf = (next) => {
1488
1464
  var _a2;
1489
1465
  const oldValue = getSelf();
1466
+ const newValue = become(next)(oldValue);
1490
1467
  (_a2 = store.config.logger) == null ? void 0 : _a2.info(
1491
1468
  ` <- "${options.key}" went (`,
1492
1469
  oldValue,
1493
1470
  `->`,
1494
- next,
1471
+ newValue,
1495
1472
  `)`
1496
1473
  );
1497
- const newValue = become(next)(oldValue);
1498
1474
  cacheValue(options.key, newValue, subject, store);
1499
1475
  markDone(options.key, store);
1500
1476
  if (store.transactionStatus.phase === `idle`) {
@@ -1780,8 +1756,8 @@ function createAtom(options, family, store = IMPLICIT.STORE) {
1780
1756
  const token = deposit(newAtom);
1781
1757
  for (const effect of (_e = options.effects) != null ? _e : []) {
1782
1758
  effect({
1783
- setSelf: (next) => AtomIO.setState(token, next, store),
1784
- onSet: (handle) => AtomIO.subscribe(token, handle, `effect[${subject.subscribers.size}]`, store)
1759
+ setSelf: (next) => atom_io.setState(token, next, store),
1760
+ onSet: (handle) => atom_io.subscribe(token, handle, `effect[${subject.subscribers.size}]`, store)
1785
1761
  });
1786
1762
  }
1787
1763
  store.subject.atomCreation.next(token);
@@ -1814,7 +1790,7 @@ var recallState = (state, store = IMPLICIT.STORE) => {
1814
1790
  var subscribeToRootAtoms = (state, store) => {
1815
1791
  const dependencySubscriptions = `default` in state ? null : traceAllSelectorAtoms(state.key, store).map((atomToken) => {
1816
1792
  const atom = withdraw(atomToken, store);
1817
- if (atom === null) {
1793
+ if (atom === void 0) {
1818
1794
  throw new Error(
1819
1795
  `Atom "${atomToken.key}", a dependency of selector "${state.key}", not found in store "${store.config.name}".`
1820
1796
  );