atom.io 0.18.0 → 0.18.1

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/dist/{chunk-OEVFAUPE.js → chunk-IZHOMSXA.js} +53 -11
  2. package/dist/chunk-IZHOMSXA.js.map +1 -0
  3. package/dist/chunk-JDUNWJFB.js +18 -0
  4. package/dist/chunk-JDUNWJFB.js.map +1 -0
  5. package/dist/index.cjs.map +1 -1
  6. package/dist/index.d.ts +5 -1
  7. package/dist/index.js.map +1 -1
  8. package/internal/dist/index.cjs +64 -34
  9. package/internal/dist/index.cjs.map +1 -1
  10. package/internal/dist/index.d.ts +1 -1
  11. package/internal/dist/index.js +64 -34
  12. package/internal/dist/index.js.map +1 -1
  13. package/internal/src/atom/delete-atom.ts +7 -6
  14. package/internal/src/caching.ts +6 -6
  15. package/internal/src/ingest-updates/ingest-atom-update.ts +6 -2
  16. package/internal/src/set-state/copy-mutable-if-needed.ts +5 -0
  17. package/internal/src/set-state/emit-update.ts +25 -11
  18. package/internal/src/set-state/set-atom.ts +4 -3
  19. package/internal/src/transaction/apply-transaction.ts +0 -1
  20. package/internal/src/transaction/set-epoch-number.ts +0 -1
  21. package/json/src/index.ts +3 -3
  22. package/package.json +241 -241
  23. package/react-devtools/dist/index.cjs.map +1 -1
  24. package/react-devtools/dist/index.js +1 -15
  25. package/react-devtools/dist/index.js.map +1 -1
  26. package/react-devtools/src/StateEditor.tsx +6 -6
  27. package/react-devtools/src/StateIndex.tsx +2 -2
  28. package/react-devtools/src/Updates.tsx +1 -1
  29. package/react-devtools/src/index.ts +3 -3
  30. package/realtime/dist/index.cjs +50 -2
  31. package/realtime/dist/index.cjs.map +1 -1
  32. package/realtime/dist/index.d.ts +110 -3
  33. package/realtime/dist/index.js +47 -4
  34. package/realtime/dist/index.js.map +1 -1
  35. package/realtime/src/index.ts +1 -0
  36. package/realtime/src/realtime-continuity.ts +14 -4
  37. package/realtime/src/shared-room-store.ts +48 -0
  38. package/realtime-client/dist/index.cjs +113 -200
  39. package/realtime-client/dist/index.cjs.map +1 -1
  40. package/realtime-client/dist/index.d.ts +2 -5
  41. package/realtime-client/dist/index.js +17 -161
  42. package/realtime-client/dist/index.js.map +1 -1
  43. package/realtime-client/src/index.ts +0 -2
  44. package/realtime-client/src/pull-mutable-atom-family-member.ts +5 -5
  45. package/realtime-client/src/realtime-client-stores/client-main-store.ts +10 -0
  46. package/realtime-client/src/sync-continuity.ts +56 -9
  47. package/realtime-react/dist/index.cjs +51 -26
  48. package/realtime-react/dist/index.cjs.map +1 -1
  49. package/realtime-react/dist/index.d.ts +2 -6
  50. package/realtime-react/dist/index.js +2 -17
  51. package/realtime-react/dist/index.js.map +1 -1
  52. package/realtime-react/src/index.ts +0 -2
  53. package/realtime-server/dist/index.cjs +399 -327
  54. package/realtime-server/dist/index.cjs.map +1 -1
  55. package/realtime-server/dist/index.d.ts +55 -60
  56. package/realtime-server/dist/index.js +394 -319
  57. package/realtime-server/dist/index.js.map +1 -1
  58. package/realtime-server/src/index.ts +2 -4
  59. package/realtime-server/src/ipc-sockets/child-socket.ts +135 -0
  60. package/realtime-server/src/ipc-sockets/custom-socket.ts +90 -0
  61. package/realtime-server/src/ipc-sockets/index.ts +3 -0
  62. package/realtime-server/src/ipc-sockets/parent-socket.ts +185 -0
  63. package/realtime-server/src/realtime-continuity-synchronizer.ts +225 -96
  64. package/realtime-server/src/realtime-server-stores/index.ts +2 -1
  65. package/realtime-server/src/realtime-server-stores/realtime-continuity-store.ts +50 -31
  66. package/realtime-server/src/realtime-server-stores/server-room-external-actions.ts +64 -0
  67. package/realtime-server/src/realtime-server-stores/server-room-external-store.ts +42 -0
  68. package/realtime-server/src/realtime-server-stores/server-sync-store.ts +49 -26
  69. package/realtime-testing/dist/index.cjs +8 -6
  70. package/realtime-testing/dist/index.cjs.map +1 -1
  71. package/realtime-testing/dist/index.d.ts +1 -0
  72. package/realtime-testing/dist/index.js +7 -6
  73. package/realtime-testing/dist/index.js.map +1 -1
  74. package/realtime-testing/src/setup-realtime-test.tsx +8 -6
  75. package/src/logger.ts +5 -1
  76. package/dist/chunk-OEVFAUPE.js.map +0 -1
  77. package/realtime-client/src/sync-server-action.ts +0 -168
  78. package/realtime-client/src/sync-state.ts +0 -19
  79. package/realtime-react/src/use-sync-server-action.ts +0 -17
  80. package/realtime-react/src/use-sync.ts +0 -17
  81. package/realtime-server/src/ipc-socket.ts +0 -230
  82. package/realtime-server/src/realtime-action-synchronizer.ts +0 -164
  83. package/realtime-server/src/realtime-server-stores/server-room-store.ts +0 -97
@@ -320,7 +320,7 @@ declare function createStandaloneAtom<T extends Transceiver<any>, J extends Json
320
320
 
321
321
  declare function createRegularAtom<T>(options: MutableAtomOptions<any, any> | RegularAtomOptions<T>, family: FamilyMetadata | undefined, store: Store): RegularAtomToken<T>;
322
322
 
323
- declare function deleteAtom(atomToken: RegularAtomToken<unknown>, store: Store): void;
323
+ declare function deleteAtom(atomToken: AtomToken<unknown>, store: Store): void;
324
324
 
325
325
  declare const isAtomDefault: (key: string, store: Store) => boolean;
326
326
  declare const markAtomAsDefault: (key: string, store: Store) => void;
@@ -268,6 +268,24 @@ var Future = class extends Promise {
268
268
  }
269
269
  };
270
270
 
271
+ // internal/src/set-state/copy-mutable-if-needed.ts
272
+ function copyMutableIfNeeded(atom, origin, target) {
273
+ const originValue = origin.valueMap.get(atom.key);
274
+ const targetValue = target.valueMap.get(atom.key);
275
+ if (originValue === targetValue) {
276
+ if (originValue === void 0) {
277
+ return typeof atom.default === `function` ? atom.default() : atom.default;
278
+ }
279
+ origin.logger.info(`\u{1F4C3}`, `atom`, `${atom.key}`, `copying`);
280
+ const jsonValue = atom.toJson(originValue);
281
+ const copiedValue = atom.fromJson(jsonValue);
282
+ target.valueMap.set(atom.key, copiedValue);
283
+ new Tracker(atom, origin);
284
+ return copiedValue;
285
+ }
286
+ return targetValue;
287
+ }
288
+
271
289
  // internal/src/caching.ts
272
290
  function cacheValue(key, value, subject, target) {
273
291
  const currentValue = target.valueMap.get(key);
@@ -294,7 +312,12 @@ function cacheValue(key, value, subject, target) {
294
312
  return value;
295
313
  }
296
314
  var readCachedValue = (token, target) => {
297
- const value = target.valueMap.get(token.key);
315
+ let value = target.valueMap.get(token.key);
316
+ if (token.type === `mutable_atom` && isChildStore(target)) {
317
+ const { parent } = target;
318
+ const copiedValue = copyMutableIfNeeded(token, parent, target);
319
+ value = copiedValue;
320
+ }
298
321
  return value;
299
322
  };
300
323
  var evictCachedValue = (key, target) => {
@@ -541,34 +564,33 @@ var markDone = (key, store) => {
541
564
  store.operation.done.add(key);
542
565
  };
543
566
 
544
- // internal/src/set-state/copy-mutable-if-needed.ts
545
- function copyMutableIfNeeded(atom, origin, target) {
546
- const originValue = origin.valueMap.get(atom.key);
547
- const targetValue = target.valueMap.get(atom.key);
548
- if (originValue === targetValue) {
549
- origin.logger.info(`\u{1F4C3}`, `atom`, `${atom.key}`, `copying`);
550
- const jsonValue = atom.toJson(originValue);
551
- const copiedValue = atom.fromJson(jsonValue);
552
- target.valueMap.set(atom.key, copiedValue);
553
- new Tracker(atom, origin);
554
- return copiedValue;
555
- }
556
- return targetValue;
557
- }
558
-
559
567
  // internal/src/set-state/emit-update.ts
560
568
  var emitUpdate = (state, update, store) => {
561
- store.logger.info(
562
- `\u{1F4E2}`,
563
- state.type,
564
- state.key,
565
- `went (`,
566
- update.oldValue,
567
- `->`,
568
- update.newValue,
569
- `) subscribers:`,
570
- state.subject.subscribers
571
- );
569
+ switch (state.type) {
570
+ case `mutable_atom`:
571
+ store.logger.info(
572
+ `\u{1F4E2}`,
573
+ state.type,
574
+ state.key,
575
+ `is now (`,
576
+ update.newValue,
577
+ `) subscribers:`,
578
+ state.subject.subscribers
579
+ );
580
+ break;
581
+ default:
582
+ store.logger.info(
583
+ `\u{1F4E2}`,
584
+ state.type,
585
+ state.key,
586
+ `went (`,
587
+ update.oldValue,
588
+ `->`,
589
+ update.newValue,
590
+ `) subscribers:`,
591
+ state.subject.subscribers
592
+ );
593
+ }
572
594
  state.subject.next(update);
573
595
  };
574
596
 
@@ -669,14 +691,16 @@ var setAtom = (atom, next, target) => {
669
691
  stowUpdate(atom, update, target);
670
692
  } else if (atom.key.startsWith(`*`)) {
671
693
  const mutableKey = atom.key.slice(1);
672
- target.atoms.get(mutableKey);
694
+ const mutableAtom = target.atoms.get(mutableKey);
673
695
  let transceiver = target.valueMap.get(mutableKey);
674
- if (atom.type === `mutable_atom` && isChildStore(target)) {
696
+ if (mutableAtom.type === `mutable_atom` && isChildStore(target)) {
675
697
  const { parent } = target;
676
- const copiedValue = copyMutableIfNeeded(atom, parent, target);
698
+ const copiedValue = copyMutableIfNeeded(mutableAtom, parent, target);
677
699
  transceiver = copiedValue;
678
700
  }
679
- transceiver.do(update.newValue);
701
+ const accepted = transceiver.do(update.newValue) === null;
702
+ if (accepted)
703
+ evictDownStream(mutableAtom, target);
680
704
  }
681
705
  }
682
706
  };
@@ -1551,6 +1575,10 @@ function deleteAtom(atomToken, store) {
1551
1575
  target.selectorAtoms.delete(key);
1552
1576
  target.atomsThatAreDefault.delete(key);
1553
1577
  target.timelineAtoms.delete(key);
1578
+ if (atomToken.type === `mutable_atom`) {
1579
+ const updateToken = getUpdateToken(atomToken);
1580
+ deleteAtom(updateToken, store);
1581
+ }
1554
1582
  store.logger.info(`\u{1F525}`, `atom`, `${key}`, `deleted`);
1555
1583
  }
1556
1584
 
@@ -1582,7 +1610,11 @@ function getFromStore(token, store) {
1582
1610
  function ingestAtomUpdate(applying, atomUpdate, store) {
1583
1611
  const { key, newValue, oldValue } = atomUpdate;
1584
1612
  const value = applying === `newValue` ? newValue : oldValue;
1585
- setIntoStore({ key, type: `atom` }, value, store);
1613
+ const token = { key, type: `atom` };
1614
+ if (atomUpdate.family) {
1615
+ Object.assign(token, { family: atomUpdate.family });
1616
+ }
1617
+ setIntoStore(token, value, store);
1586
1618
  }
1587
1619
 
1588
1620
  // internal/src/ingest-updates/ingest-selector-update.ts
@@ -2050,7 +2082,6 @@ function setEpochNumberOfAction(transactionKey, newEpoch, store) {
2050
2082
  const continuityKey = store.transactionMeta.actionContinuities.getRelatedKey(transactionKey);
2051
2083
  if (continuityKey !== void 0) {
2052
2084
  store.transactionMeta.epoch.set(continuityKey, newEpoch);
2053
- console.log(`epoch is now`, newEpoch);
2054
2085
  }
2055
2086
  }
2056
2087
 
@@ -2102,7 +2133,6 @@ var applyTransaction = (output, store) => {
2102
2133
  }
2103
2134
  ingestTransactionUpdate(`newValue`, child.transactionMeta.update, parent);
2104
2135
  if (isRootStore(parent)) {
2105
- console.log(child.transactionMeta.update);
2106
2136
  setEpochNumberOfAction(
2107
2137
  child.transactionMeta.update.key,
2108
2138
  child.transactionMeta.update.epoch,