atom.io 0.21.1 → 0.23.0

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 (116) hide show
  1. package/data/dist/index.cjs +152 -63
  2. package/data/dist/index.d.ts +6 -0
  3. package/data/dist/index.js +3 -3
  4. package/data/src/join.ts +164 -51
  5. package/data/src/struct-family.ts +2 -2
  6. package/dist/chunk-6MLFYN32.js +18 -0
  7. package/dist/{chunk-HITX3MO4.js → chunk-7DT3PVS3.js} +151 -62
  8. package/dist/{chunk-RT43TVKP.js → chunk-GVHKIJ3G.js} +1 -1
  9. package/dist/chunk-OAYGID5B.js +27 -0
  10. package/dist/index.cjs +4 -18
  11. package/dist/index.d.ts +71 -28
  12. package/dist/index.js +6 -19
  13. package/ephemeral/dist/index.cjs +11 -0
  14. package/ephemeral/dist/index.js +9 -0
  15. package/ephemeral/package.json +16 -0
  16. package/ephemeral/src/index.ts +1 -0
  17. package/eslint-plugin/dist/index.cjs +155 -1
  18. package/eslint-plugin/dist/index.js +155 -1
  19. package/eslint-plugin/src/rules/index.ts +1 -0
  20. package/eslint-plugin/src/rules/lifespan.ts +203 -0
  21. package/eslint-plugin/src/rules/synchronous-selector-dependencies.ts +1 -65
  22. package/eslint-plugin/src/walk.ts +73 -0
  23. package/immortal/dist/index.cjs +260 -0
  24. package/immortal/dist/index.js +212 -0
  25. package/immortal/package.json +16 -0
  26. package/immortal/src/index.ts +3 -0
  27. package/immortal/src/make-molecule.ts +222 -0
  28. package/immortal/src/molecule.ts +167 -0
  29. package/immortal/src/seek-state.ts +73 -0
  30. package/internal/dist/index.cjs +1242 -837
  31. package/internal/dist/index.d.ts +135 -22
  32. package/internal/dist/index.js +1215 -838
  33. package/internal/src/atom/create-regular-atom.ts +0 -2
  34. package/internal/src/atom/create-standalone-atom.ts +6 -2
  35. package/internal/src/atom/dispose-atom.ts +26 -3
  36. package/internal/src/families/create-readonly-selector-family.ts +15 -10
  37. package/internal/src/families/create-regular-atom-family.ts +20 -21
  38. package/internal/src/families/create-writable-selector-family.ts +13 -9
  39. package/{src/dispose.ts → internal/src/families/dispose-from-store.ts} +7 -4
  40. package/internal/src/families/find-in-store.ts +11 -6
  41. package/internal/src/families/index.ts +3 -0
  42. package/internal/src/families/init-family-member.ts +112 -0
  43. package/internal/src/families/seek-in-store.ts +123 -0
  44. package/internal/src/get-state/get-from-store.ts +2 -2
  45. package/internal/src/ingest-updates/index.ts +1 -0
  46. package/internal/src/ingest-updates/ingest-creation-disposal.ts +104 -0
  47. package/internal/src/ingest-updates/ingest-transaction-update.ts +26 -4
  48. package/internal/src/mutable/create-mutable-atom-family.ts +22 -24
  49. package/internal/src/mutable/create-mutable-atom.ts +3 -3
  50. package/internal/src/mutable/get-json-family.ts +2 -2
  51. package/internal/src/mutable/get-json-token.ts +26 -12
  52. package/internal/src/mutable/tracker-family.ts +21 -19
  53. package/internal/src/not-found-error.ts +16 -3
  54. package/internal/src/selector/create-readonly-selector.ts +2 -3
  55. package/internal/src/selector/create-standalone-selector.ts +6 -2
  56. package/internal/src/selector/create-writable-selector.ts +2 -3
  57. package/internal/src/selector/dispose-selector.ts +68 -24
  58. package/internal/src/selector/register-selector.ts +10 -5
  59. package/internal/src/set-state/set-into-store.ts +2 -2
  60. package/internal/src/set-state/stow-update.ts +5 -1
  61. package/internal/src/store/deposit.ts +41 -7
  62. package/internal/src/store/index.ts +0 -1
  63. package/internal/src/store/store.ts +29 -5
  64. package/internal/src/store/withdraw.ts +28 -1
  65. package/internal/src/subscribe/subscribe-to-state.ts +2 -2
  66. package/internal/src/timeline/add-atom-to-timeline.ts +206 -182
  67. package/internal/src/timeline/create-timeline.ts +181 -60
  68. package/internal/src/timeline/time-travel.ts +20 -0
  69. package/internal/src/transaction/apply-transaction.ts +2 -12
  70. package/internal/src/transaction/build-transaction.ts +16 -2
  71. package/introspection/dist/index.cjs +40 -53
  72. package/introspection/dist/index.js +40 -53
  73. package/introspection/src/attach-atom-index.ts +38 -48
  74. package/introspection/src/attach-selector-index.ts +45 -50
  75. package/introspection/src/attach-timeline-family.ts +1 -0
  76. package/json/dist/index.cjs +40 -6
  77. package/json/dist/index.js +44 -9
  78. package/json/src/select-json-family.ts +47 -9
  79. package/package.json +30 -10
  80. package/react/dist/index.cjs +1 -1
  81. package/react/dist/index.js +1 -1
  82. package/react/src/use-json.ts +1 -1
  83. package/react-devtools/dist/index.cjs +69 -57
  84. package/react-devtools/dist/index.js +62 -49
  85. package/react-devtools/src/StateIndex.tsx +2 -1
  86. package/react-devtools/src/TimelineIndex.tsx +17 -14
  87. package/react-devtools/src/TransactionIndex.tsx +7 -7
  88. package/react-devtools/src/Updates.tsx +41 -32
  89. package/realtime-client/dist/index.cjs +3 -3
  90. package/realtime-client/dist/index.js +3 -3
  91. package/realtime-client/src/pull-mutable-atom-family-member.ts +1 -1
  92. package/realtime-client/src/pull-mutable-atom.ts +1 -1
  93. package/realtime-client/src/sync-continuity.ts +1 -2
  94. package/realtime-react/dist/index.cjs +1 -1
  95. package/realtime-react/dist/index.js +1 -1
  96. package/realtime-server/dist/index.cjs +39 -27
  97. package/realtime-server/dist/index.d.ts +1 -1
  98. package/realtime-server/dist/index.js +27 -16
  99. package/realtime-server/src/realtime-continuity-synchronizer.ts +5 -3
  100. package/realtime-server/src/realtime-mutable-family-provider.ts +2 -1
  101. package/realtime-server/src/realtime-mutable-provider.ts +1 -1
  102. package/realtime-server/src/realtime-server-stores/server-sync-store.ts +21 -11
  103. package/realtime-testing/dist/index.cjs +7 -2
  104. package/realtime-testing/dist/index.js +8 -5
  105. package/realtime-testing/src/setup-realtime-test.tsx +5 -2
  106. package/src/atom.ts +19 -7
  107. package/src/dispose-state.ts +10 -0
  108. package/src/index.ts +5 -2
  109. package/src/selector.ts +13 -7
  110. package/src/silo.ts +3 -3
  111. package/src/subscribe.ts +8 -4
  112. package/src/timeline.ts +18 -1
  113. package/src/transaction.ts +59 -4
  114. package/dist/chunk-BF4MVQF6.js +0 -44
  115. package/internal/src/store/withdraw-new-family-member.ts +0 -69
  116. /package/{src → ephemeral/src}/find-state.ts +0 -0
@@ -4,6 +4,7 @@ var json = require('atom.io/json');
4
4
  var internal = require('atom.io/internal');
5
5
  var setRtx = require('atom.io/transceivers/set-rtx');
6
6
  var AtomIO = require('atom.io');
7
+ require('atom.io/immortal');
7
8
  var realtime = require('atom.io/realtime');
8
9
  var data = require('atom.io/data');
9
10
  var child_process = require('child_process');
@@ -406,12 +407,12 @@ function findRelationsInStore(token, key, store) {
406
407
  relations = {
407
408
  get [keyAB]() {
408
409
  const familyAB = myJoin.states[keyAB];
409
- const state = internal.findInStore(familyAB, key, store);
410
+ const state = myJoin.retrieve(familyAB, key);
410
411
  return state;
411
412
  },
412
413
  get [keyBA]() {
413
414
  const familyBA = myJoin.states[keyBA];
414
- const state = internal.findInStore(familyBA, key, store);
415
+ const state = myJoin.retrieve(familyBA, key);
415
416
  return state;
416
417
  }
417
418
  };
@@ -421,12 +422,12 @@ function findRelationsInStore(token, key, store) {
421
422
  Object.assign(relations, {
422
423
  get [entryAB]() {
423
424
  const familyAB = myJoin.states[entryAB];
424
- const state = internal.findInStore(familyAB, key, store);
425
+ const state = myJoin.retrieve(familyAB, key);
425
426
  return state;
426
427
  },
427
428
  get [entryBA]() {
428
429
  const familyBA = myJoin.states[entryBA];
429
- const state = internal.findInStore(familyBA, key, store);
430
+ const state = myJoin.retrieve(familyBA, key);
430
431
  return state;
431
432
  }
432
433
  });
@@ -439,12 +440,12 @@ function findRelationsInStore(token, key, store) {
439
440
  relations = {
440
441
  get [keyAB]() {
441
442
  const familyAB = myJoin.states[keyAB];
442
- const state = internal.findInStore(familyAB, key, store);
443
+ const state = myJoin.retrieve(familyAB, key);
443
444
  return state;
444
445
  },
445
446
  get [keysBA]() {
446
447
  const familyBA = myJoin.states[keysBA];
447
- const state = internal.findInStore(familyBA, key, store);
448
+ const state = myJoin.retrieve(familyBA, key);
448
449
  return state;
449
450
  }
450
451
  };
@@ -454,12 +455,12 @@ function findRelationsInStore(token, key, store) {
454
455
  Object.assign(relations, {
455
456
  get [entryAB]() {
456
457
  const familyAB = myJoin.states[entryAB];
457
- const state = internal.findInStore(familyAB, key, store);
458
+ const state = myJoin.retrieve(familyAB, key);
458
459
  return state;
459
460
  },
460
461
  get [entriesBA]() {
461
462
  const familyBA = myJoin.states[entriesBA];
462
- const state = internal.findInStore(familyBA, key, store);
463
+ const state = myJoin.retrieve(familyBA, key);
463
464
  return state;
464
465
  }
465
466
  });
@@ -472,12 +473,12 @@ function findRelationsInStore(token, key, store) {
472
473
  relations = {
473
474
  get [keysAB]() {
474
475
  const familyAB = myJoin.states[keysAB];
475
- const state = internal.findInStore(familyAB, key, store);
476
+ const state = myJoin.retrieve(familyAB, key);
476
477
  return state;
477
478
  },
478
479
  get [keysBA]() {
479
480
  const familyBA = myJoin.states[keysBA];
480
- const state = internal.findInStore(familyBA, key, store);
481
+ const state = myJoin.retrieve(familyBA, key);
481
482
  return state;
482
483
  }
483
484
  };
@@ -487,12 +488,12 @@ function findRelationsInStore(token, key, store) {
487
488
  Object.assign(relations, {
488
489
  get [entriesAB]() {
489
490
  const familyAB = myJoin.states[entriesAB];
490
- const state = internal.findInStore(familyAB, key, store);
491
+ const state = myJoin.retrieve(familyAB, key);
491
492
  return state;
492
493
  },
493
494
  get [entriesBA]() {
494
495
  const familyBA = myJoin.states[entriesBA];
495
- const state = internal.findInStore(familyBA, key, store);
496
+ const state = myJoin.retrieve(familyBA, key);
496
497
  return state;
497
498
  }
498
499
  });
@@ -642,19 +643,29 @@ var destroyRoomTX = AtomIO__namespace.transaction({
642
643
  });
643
644
  function redactTransactionUpdateContent(visibleStateKeys, updates) {
644
645
  return updates.map((update) => {
645
- if (`newValue` in update) {
646
- return update;
646
+ switch (update.type) {
647
+ case `transaction_update`: {
648
+ const redacted = redactTransactionUpdateContent(
649
+ visibleStateKeys,
650
+ update.updates
651
+ );
652
+ return __spreadProps(__spreadValues({}, update), { updates: redacted });
653
+ }
654
+ default:
655
+ return update;
647
656
  }
648
- const redacted = redactTransactionUpdateContent(
649
- visibleStateKeys,
650
- update.updates
651
- );
652
- return __spreadProps(__spreadValues({}, update), { updates: redacted });
653
657
  }).filter((update) => {
654
- if (`newValue` in update) {
655
- return visibleStateKeys.includes(update.key);
658
+ switch (update.type) {
659
+ case `atom_update`:
660
+ case `selector_update`:
661
+ return visibleStateKeys.includes(update.key);
662
+ case `state_creation`:
663
+ return visibleStateKeys.includes(update.token.key);
664
+ case `molecule_creation`:
665
+ return true;
666
+ case `transaction_update`:
667
+ return true;
656
668
  }
657
- return true;
658
669
  });
659
670
  }
660
671
  var actionOcclusionAtoms = AtomIO.atomFamily({
@@ -767,7 +778,7 @@ function realtimeContinuitySynchronizer({
767
778
  (token) => !newKeys.includes(token.key)
768
779
  );
769
780
  const revealed = newValue.filter((token) => !oldKeys.includes(token.key)).flatMap((token) => {
770
- const resourceToken = token.type === `mutable_atom` ? internal.getJsonToken(token) : token;
781
+ const resourceToken = token.type === `mutable_atom` ? internal.getJsonToken(token, store) : token;
771
782
  const resource = internal.getFromStore(resourceToken, store);
772
783
  return [resourceToken, resource];
773
784
  });
@@ -800,7 +811,7 @@ function realtimeContinuitySynchronizer({
800
811
  var _a;
801
812
  const initialPayload = [];
802
813
  for (const atom2 of continuity.globals) {
803
- const resourceToken = atom2.type === `mutable_atom` ? internal.getJsonToken(atom2) : atom2;
814
+ const resourceToken = atom2.type === `mutable_atom` ? internal.getJsonToken(atom2, store) : atom2;
804
815
  initialPayload.push(resourceToken, internal.getFromStore(atom2, store));
805
816
  }
806
817
  for (const perspective of continuity.perspectives) {
@@ -813,7 +824,7 @@ function realtimeContinuitySynchronizer({
813
824
  userView
814
825
  });
815
826
  for (const visibleToken of userView) {
816
- const resourceToken = visibleToken.type === `mutable_atom` ? internal.getJsonToken(visibleToken) : visibleToken;
827
+ const resourceToken = visibleToken.type === `mutable_atom` ? internal.getJsonToken(visibleToken, store) : visibleToken;
817
828
  const resource = internal.getFromStore(resourceToken, store);
818
829
  initialPayload.push(resourceToken, resource);
819
830
  }
@@ -1003,7 +1014,8 @@ function realtimeMutableFamilyProvider({
1003
1014
  for (const exposedSubKey of exposedSubKeys) {
1004
1015
  if (json.stringifyJson(exposedSubKey) === json.stringifyJson(subKey)) {
1005
1016
  const token = internal.findInStore(family, subKey, store);
1006
- const jsonToken = internal.getJsonToken(token);
1017
+ internal.getFromStore(token, store);
1018
+ const jsonToken = internal.getJsonToken(token, store);
1007
1019
  const updateToken = internal.getUpdateToken(token);
1008
1020
  socket.emit(`init:${token.key}`, internal.getFromStore(jsonToken, store));
1009
1021
  const unsubscribe = internal.subscribeToState(
@@ -1038,7 +1050,7 @@ function realtimeMutableProvider({
1038
1050
  }) {
1039
1051
  return function mutableProvider(token) {
1040
1052
  let unsubscribeFromStateUpdates = null;
1041
- const jsonToken = internal.getJsonToken(token);
1053
+ const jsonToken = internal.getJsonToken(token, store);
1042
1054
  const trackerToken = internal.getUpdateToken(token);
1043
1055
  const fillUnsubRequest = () => {
1044
1056
  socket.off(`unsub:${token.key}`, fillUnsubRequest);
@@ -112,7 +112,7 @@ declare function redactTransactionUpdateContent(visibleStateKeys: string[], upda
112
112
  declare const actionOcclusionAtoms: AtomIO.RegularAtomFamilyTokenWithCall<{
113
113
  occlude: (updates: TransactionUpdateContent[]) => TransactionUpdateContent[];
114
114
  }, string>;
115
- declare const userUnacknowledgedQueues: AtomIO.RegularAtomFamilyTokenWithCall<Pick<TransactionUpdate<any>, "key" | "epoch" | "id" | "updates" | "output">[], string>;
115
+ declare const userUnacknowledgedQueues: AtomIO.RegularAtomFamilyTokenWithCall<Pick<TransactionUpdate<any>, "key" | "id" | "epoch" | "updates" | "output">[], string>;
116
116
 
117
117
  declare const socketAtoms: AtomIO.RegularAtomFamilyTokenWithCall<Socket | null, string>;
118
118
  declare const socketIndex: AtomIO.MutableAtomToken<SetRTX<string>, SetRTXJson<string>>;
@@ -1,4 +1,4 @@
1
- import { findRelationsInStore } from '../../dist/chunk-HITX3MO4.js';
1
+ import { findRelationsInStore } from '../../dist/chunk-7DT3PVS3.js';
2
2
  import '../../dist/chunk-FTONNX2R.js';
3
3
  import { __spreadProps, __spreadValues } from '../../dist/chunk-F2X4B4VY.js';
4
4
  import { parseJson, stringifyJson } from 'atom.io/json';
@@ -472,19 +472,29 @@ var destroyRoomTX = AtomIO.transaction({
472
472
  });
473
473
  function redactTransactionUpdateContent(visibleStateKeys, updates) {
474
474
  return updates.map((update) => {
475
- if (`newValue` in update) {
476
- return update;
475
+ switch (update.type) {
476
+ case `transaction_update`: {
477
+ const redacted = redactTransactionUpdateContent(
478
+ visibleStateKeys,
479
+ update.updates
480
+ );
481
+ return __spreadProps(__spreadValues({}, update), { updates: redacted });
482
+ }
483
+ default:
484
+ return update;
477
485
  }
478
- const redacted = redactTransactionUpdateContent(
479
- visibleStateKeys,
480
- update.updates
481
- );
482
- return __spreadProps(__spreadValues({}, update), { updates: redacted });
483
486
  }).filter((update) => {
484
- if (`newValue` in update) {
485
- return visibleStateKeys.includes(update.key);
487
+ switch (update.type) {
488
+ case `atom_update`:
489
+ case `selector_update`:
490
+ return visibleStateKeys.includes(update.key);
491
+ case `state_creation`:
492
+ return visibleStateKeys.includes(update.token.key);
493
+ case `molecule_creation`:
494
+ return true;
495
+ case `transaction_update`:
496
+ return true;
486
497
  }
487
- return true;
488
498
  });
489
499
  }
490
500
  var actionOcclusionAtoms = atomFamily({
@@ -597,7 +607,7 @@ function realtimeContinuitySynchronizer({
597
607
  (token) => !newKeys.includes(token.key)
598
608
  );
599
609
  const revealed = newValue.filter((token) => !oldKeys.includes(token.key)).flatMap((token) => {
600
- const resourceToken = token.type === `mutable_atom` ? getJsonToken(token) : token;
610
+ const resourceToken = token.type === `mutable_atom` ? getJsonToken(token, store) : token;
601
611
  const resource = getFromStore(resourceToken, store);
602
612
  return [resourceToken, resource];
603
613
  });
@@ -630,7 +640,7 @@ function realtimeContinuitySynchronizer({
630
640
  var _a;
631
641
  const initialPayload = [];
632
642
  for (const atom2 of continuity.globals) {
633
- const resourceToken = atom2.type === `mutable_atom` ? getJsonToken(atom2) : atom2;
643
+ const resourceToken = atom2.type === `mutable_atom` ? getJsonToken(atom2, store) : atom2;
634
644
  initialPayload.push(resourceToken, getFromStore(atom2, store));
635
645
  }
636
646
  for (const perspective of continuity.perspectives) {
@@ -643,7 +653,7 @@ function realtimeContinuitySynchronizer({
643
653
  userView
644
654
  });
645
655
  for (const visibleToken of userView) {
646
- const resourceToken = visibleToken.type === `mutable_atom` ? getJsonToken(visibleToken) : visibleToken;
656
+ const resourceToken = visibleToken.type === `mutable_atom` ? getJsonToken(visibleToken, store) : visibleToken;
647
657
  const resource = getFromStore(resourceToken, store);
648
658
  initialPayload.push(resourceToken, resource);
649
659
  }
@@ -833,7 +843,8 @@ function realtimeMutableFamilyProvider({
833
843
  for (const exposedSubKey of exposedSubKeys) {
834
844
  if (stringifyJson(exposedSubKey) === stringifyJson(subKey)) {
835
845
  const token = findInStore(family, subKey, store);
836
- const jsonToken = getJsonToken(token);
846
+ getFromStore(token, store);
847
+ const jsonToken = getJsonToken(token, store);
837
848
  const updateToken = getUpdateToken(token);
838
849
  socket.emit(`init:${token.key}`, getFromStore(jsonToken, store));
839
850
  const unsubscribe = subscribeToState(
@@ -868,7 +879,7 @@ function realtimeMutableProvider({
868
879
  }) {
869
880
  return function mutableProvider(token) {
870
881
  let unsubscribeFromStateUpdates = null;
871
- const jsonToken = getJsonToken(token);
882
+ const jsonToken = getJsonToken(token, store);
872
883
  const trackerToken = getUpdateToken(token);
873
884
  const fillUnsubRequest = () => {
874
885
  socket.off(`unsub:${token.key}`, fillUnsubRequest);
@@ -106,7 +106,9 @@ export function realtimeContinuitySynchronizer({
106
106
  .filter((token) => !oldKeys.includes(token.key))
107
107
  .flatMap((token) => {
108
108
  const resourceToken =
109
- token.type === `mutable_atom` ? getJsonToken(token) : token
109
+ token.type === `mutable_atom`
110
+ ? getJsonToken(token, store)
111
+ : token
110
112
  const resource = getFromStore(resourceToken, store)
111
113
  return [resourceToken, resource]
112
114
  })
@@ -139,7 +141,7 @@ export function realtimeContinuitySynchronizer({
139
141
  const initialPayload: Json.Serializable[] = []
140
142
  for (const atom of continuity.globals) {
141
143
  const resourceToken =
142
- atom.type === `mutable_atom` ? getJsonToken(atom) : atom
144
+ atom.type === `mutable_atom` ? getJsonToken(atom, store) : atom
143
145
  initialPayload.push(resourceToken, getFromStore(atom, store))
144
146
  }
145
147
  for (const perspective of continuity.perspectives) {
@@ -154,7 +156,7 @@ export function realtimeContinuitySynchronizer({
154
156
  for (const visibleToken of userView) {
155
157
  const resourceToken =
156
158
  visibleToken.type === `mutable_atom`
157
- ? getJsonToken(visibleToken)
159
+ ? getJsonToken(visibleToken, store)
158
160
  : visibleToken
159
161
  const resource = getFromStore(resourceToken, store)
160
162
 
@@ -44,7 +44,8 @@ export function realtimeMutableFamilyProvider({
44
44
  for (const exposedSubKey of exposedSubKeys) {
45
45
  if (stringifyJson(exposedSubKey) === stringifyJson(subKey)) {
46
46
  const token = findInStore(family, subKey, store)
47
- const jsonToken = getJsonToken(token)
47
+ getFromStore(token, store)
48
+ const jsonToken = getJsonToken(token, store)
48
49
  const updateToken = getUpdateToken(token)
49
50
  socket.emit(`init:${token.key}`, getFromStore(jsonToken, store))
50
51
  const unsubscribe = subscribeToState(
@@ -22,7 +22,7 @@ export function realtimeMutableProvider({
22
22
  >(token: AtomIO.MutableAtomToken<Core, SerializableCore>): () => void {
23
23
  let unsubscribeFromStateUpdates: (() => void) | null = null
24
24
 
25
- const jsonToken = getJsonToken(token)
25
+ const jsonToken = getJsonToken(token, store)
26
26
  const trackerToken = getUpdateToken(token)
27
27
 
28
28
  const fillUnsubRequest = () => {
@@ -1,5 +1,5 @@
1
1
  import type { TransactionUpdate, TransactionUpdateContent } from "atom.io"
2
- import { atomFamily, selectorFamily } from "atom.io"
2
+ import { atomFamily } from "atom.io"
3
3
 
4
4
  // export const completeUpdateAtoms = atomFamily<
5
5
  // TransactionUpdate<any> | null,
@@ -15,20 +15,30 @@ export function redactTransactionUpdateContent(
15
15
  ): TransactionUpdateContent[] {
16
16
  return updates
17
17
  .map((update): TransactionUpdateContent => {
18
- if (`newValue` in update) {
19
- return update
18
+ switch (update.type) {
19
+ case `transaction_update`: {
20
+ const redacted = redactTransactionUpdateContent(
21
+ visibleStateKeys,
22
+ update.updates,
23
+ )
24
+ return { ...update, updates: redacted }
25
+ }
26
+ default:
27
+ return update
20
28
  }
21
- const redacted = redactTransactionUpdateContent(
22
- visibleStateKeys,
23
- update.updates,
24
- )
25
- return { ...update, updates: redacted }
26
29
  })
27
30
  .filter((update) => {
28
- if (`newValue` in update) {
29
- return visibleStateKeys.includes(update.key)
31
+ switch (update.type) {
32
+ case `atom_update`:
33
+ case `selector_update`:
34
+ return visibleStateKeys.includes(update.key)
35
+ case `state_creation`:
36
+ return visibleStateKeys.includes(update.token.key)
37
+ case `molecule_creation`:
38
+ return true
39
+ case `transaction_update`:
40
+ return true
30
41
  }
31
- return true
32
42
  })
33
43
  }
34
44
 
@@ -11,6 +11,8 @@ var RTS = require('atom.io/realtime-server');
11
11
  var Happy = require('happy-dom');
12
12
  var SocketIO = require('socket.io');
13
13
  var socket_ioClient = require('socket.io-client');
14
+ require('atom.io/immortal');
15
+ require('atom.io/json');
14
16
  require('atom.io/transceivers/set-rtx');
15
17
  var jsxRuntime = require('react/jsx-runtime');
16
18
 
@@ -143,7 +145,10 @@ AtomIO__namespace.atom(
143
145
  var testNumber = 0;
144
146
  var setupRealtimeTestServer = (options) => {
145
147
  ++testNumber;
146
- const silo = new AtomIO__namespace.Silo(`SERVER-${testNumber}`, internal.IMPLICIT.STORE);
148
+ const silo = new AtomIO__namespace.Silo(
149
+ { name: `SERVER-${testNumber}`, lifespan: `ephemeral` },
150
+ internal.IMPLICIT.STORE
151
+ );
147
152
  const httpServer = http__namespace.createServer((_, res) => res.end(`Hello World!`));
148
153
  const address = httpServer.listen(options.port).address();
149
154
  const port = typeof address === `string` ? null : address === null ? null : address.port;
@@ -198,7 +203,7 @@ var setupRealtimeTestClient = (options, name, port) => {
198
203
  const socket = socket_ioClient.io(`http://localhost:${port}/`, {
199
204
  auth: { token: `test`, username: `${name}-${testNumber}` }
200
205
  });
201
- const silo = new AtomIO__namespace.Silo(name, internal.IMPLICIT.STORE);
206
+ const silo = new AtomIO__namespace.Silo({ name, lifespan: `ephemeral` }, internal.IMPLICIT.STORE);
202
207
  for (const [key, value] of silo.store.valueMap.entries()) {
203
208
  if (Array.isArray(value)) {
204
209
  silo.store.valueMap.set(key, [...value]);
@@ -1,8 +1,8 @@
1
- import { myUsernameState } from '../../dist/chunk-O47EQUM6.js';
2
- import { editRelationsInStore } from '../../dist/chunk-HITX3MO4.js';
3
- import '../../dist/chunk-FTONNX2R.js';
4
1
  import { recordToEntries } from '../../dist/chunk-3V3VWQ7X.js';
2
+ import { myUsernameState } from '../../dist/chunk-O47EQUM6.js';
5
3
  import '../../dist/chunk-BWWVY5O5.js';
4
+ import { editRelationsInStore } from '../../dist/chunk-7DT3PVS3.js';
5
+ import '../../dist/chunk-FTONNX2R.js';
6
6
  import { __spreadProps, __spreadValues } from '../../dist/chunk-F2X4B4VY.js';
7
7
  import * as http from 'http';
8
8
  import { render, prettyDOM } from '@testing-library/react';
@@ -20,7 +20,10 @@ import { jsx } from 'react/jsx-runtime';
20
20
  var testNumber = 0;
21
21
  var setupRealtimeTestServer = (options) => {
22
22
  ++testNumber;
23
- const silo = new AtomIO.Silo(`SERVER-${testNumber}`, IMPLICIT.STORE);
23
+ const silo = new AtomIO.Silo(
24
+ { name: `SERVER-${testNumber}`, lifespan: `ephemeral` },
25
+ IMPLICIT.STORE
26
+ );
24
27
  const httpServer = http.createServer((_, res) => res.end(`Hello World!`));
25
28
  const address = httpServer.listen(options.port).address();
26
29
  const port = typeof address === `string` ? null : address === null ? null : address.port;
@@ -75,7 +78,7 @@ var setupRealtimeTestClient = (options, name, port) => {
75
78
  const socket = io(`http://localhost:${port}/`, {
76
79
  auth: { token: `test`, username: `${name}-${testNumber}` }
77
80
  });
78
- const silo = new AtomIO.Silo(name, IMPLICIT.STORE);
81
+ const silo = new AtomIO.Silo({ name, lifespan: `ephemeral` }, IMPLICIT.STORE);
79
82
  for (const [key, value] of silo.store.valueMap.entries()) {
80
83
  if (Array.isArray(value)) {
81
84
  silo.store.valueMap.set(key, [...value]);
@@ -76,7 +76,10 @@ export const setupRealtimeTestServer = (
76
76
  options: TestSetupOptions,
77
77
  ): RealtimeTestServer => {
78
78
  ++testNumber
79
- const silo = new AtomIO.Silo(`SERVER-${testNumber}`, IMPLICIT.STORE)
79
+ const silo = new AtomIO.Silo(
80
+ { name: `SERVER-${testNumber}`, lifespan: `ephemeral` },
81
+ IMPLICIT.STORE,
82
+ )
80
83
 
81
84
  const httpServer = http.createServer((_, res) => res.end(`Hello World!`))
82
85
  const address = httpServer.listen(options.port).address()
@@ -139,7 +142,7 @@ export const setupRealtimeTestClient = (
139
142
  const socket: ClientSocket = io(`http://localhost:${port}/`, {
140
143
  auth: { token: `test`, username: `${name}-${testNumber}` },
141
144
  })
142
- const silo = new AtomIO.Silo(name, IMPLICIT.STORE)
145
+ const silo = new AtomIO.Silo({ name, lifespan: `ephemeral` }, IMPLICIT.STORE)
143
146
  for (const [key, value] of silo.store.valueMap.entries()) {
144
147
  if (Array.isArray(value)) {
145
148
  silo.store.valueMap.set(key, [...value])
package/src/atom.ts CHANGED
@@ -6,7 +6,13 @@ import {
6
6
  } from "atom.io/internal"
7
7
  import type { Json, JsonInterface } from "atom.io/json"
8
8
 
9
- import type { AtomToken, MutableAtomToken, RegularAtomToken } from "."
9
+ import type {
10
+ AtomToken,
11
+ MutableAtomToken,
12
+ RegularAtomToken,
13
+ StateCreation,
14
+ StateDisposal,
15
+ } from "."
10
16
 
11
17
  export type Effectors<T> = {
12
18
  setSelf: <V extends T>(next: V | ((oldValue: T) => V)) => void
@@ -57,14 +63,17 @@ export type RegularAtomFamilyTokenWithCall<
57
63
  K extends Json.Serializable,
58
64
  > =
59
65
  & RegularAtomFamilyToken<T, K>
60
- & /** @deprecated Prefer the `findState`, `findInStore`, or `find` functions. */
61
- ((key: K) => RegularAtomToken<T>)
66
+ & {
67
+ /** @deprecated In ephemeral stores, prefer the `findState`, `findInStore`, or `find` functions. In immortal stores, prefer the `seekState`, `seekInStore`, or `seek` functions. */
68
+ /* eslint-disable-next-line @typescript-eslint/prefer-function-type */
69
+ (key: K): RegularAtomToken<T>
70
+ }
62
71
  // biome-ignore format: intersection
63
72
  export type RegularAtomFamily<T, K extends Json.Serializable> =
64
73
  & RegularAtomFamilyToken<T, K>
65
74
  & {
66
75
  (key: K): RegularAtomToken<T>
67
- subject: Subject<RegularAtomToken<T>>
76
+ subject: Subject<StateCreation<AtomToken<T>> | StateDisposal<AtomToken<T>>>
68
77
  install: (store: Store) => void
69
78
  }
70
79
 
@@ -100,8 +109,11 @@ export type MutableAtomFamilyTokenWithCall<
100
109
  K extends Json.Serializable,
101
110
  > =
102
111
  & MutableAtomFamilyToken<T, J, K>
103
- & /** @deprecated Prefer the `findState`, `findInStore`, or `find` functions. */
104
- ((key: K) => MutableAtomToken<T, J>)
112
+ & {
113
+ /** @deprecated In ephemeral stores, prefer the `findState`, `findInStore`, or `find` functions. In immortal stores, prefer the `seekState`, `seekInStore`, or `seek` functions. */
114
+ /* eslint-disable-next-line @typescript-eslint/prefer-function-type */
115
+ (key: K): MutableAtomToken<T, J>
116
+ }
105
117
  // biome-ignore format: intersection
106
118
  export type MutableAtomFamily<
107
119
  T extends Transceiver<any>,
@@ -112,7 +124,7 @@ export type MutableAtomFamily<
112
124
  & MutableAtomFamilyToken<T, J, K>
113
125
  & {
114
126
  (key: K): MutableAtomToken<T, J>
115
- subject: Subject<MutableAtomToken<T, J>>
127
+ subject: Subject<StateCreation<MutableAtomToken<T, J>> | StateDisposal<MutableAtomToken<T, J>>>
116
128
  install: (store: Store) => void
117
129
  }
118
130
 
@@ -0,0 +1,10 @@
1
+ import type { MoleculeToken } from "atom.io/immortal"
2
+ import * as Internal from "atom.io/internal"
3
+
4
+ import type { ReadableToken } from "."
5
+
6
+ export function disposeState(
7
+ token: MoleculeToken<any, any, any> | ReadableToken<any>,
8
+ ): void {
9
+ Internal.disposeFromStore(token, Internal.IMPLICIT.STORE)
10
+ }
package/src/index.ts CHANGED
@@ -10,8 +10,7 @@ import type {
10
10
  } from "./selector"
11
11
 
12
12
  export * from "./atom"
13
- export * from "./dispose"
14
- export * from "./find-state"
13
+ export * from "./dispose-state"
15
14
  export * from "./get-state"
16
15
  export * from "./logger"
17
16
  export * from "./selector"
@@ -24,6 +23,10 @@ export * from "./validators"
24
23
 
25
24
  export type Func = (...parameters: any[]) => any
26
25
 
26
+ export type Flat<R extends { [K in PropertyKey]: any }> = {
27
+ [K in keyof R]: R[K]
28
+ }
29
+
27
30
  export type RegularAtomToken<T> = {
28
31
  key: string
29
32
  type: `atom`
package/src/selector.ts CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  import type { Json } from "atom.io/json"
8
8
 
9
9
  import type { ReadonlySelectorToken, WritableSelectorToken } from "."
10
- import type { Read, Write } from "./transaction"
10
+ import type { Read, StateCreation, StateDisposal, Write } from "./transaction"
11
11
 
12
12
  export type WritableSelectorOptions<T> = {
13
13
  key: string
@@ -53,14 +53,17 @@ export type WritableSelectorFamilyTokenWithCall<
53
53
  K extends Json.Serializable,
54
54
  > =
55
55
  & WritableSelectorFamilyToken<T, K>
56
- & /** @deprecated Prefer the `findState`, `findInStore`, or `find` functions. */
57
- ((key: K) => WritableSelectorToken<T>)
56
+ & {
57
+ /** @deprecated In ephemeral stores, prefer the `findState`, `findInStore`, or `find` functions. In immortal stores, prefer the `seekState`, `seekInStore`, or `seek` functions. */
58
+ /* eslint-disable-next-line @typescript-eslint/prefer-function-type */
59
+ (key: K): WritableSelectorToken<T>
60
+ }
58
61
  // biome-ignore format: intersection
59
62
  export type WritableSelectorFamily<T, K extends Json.Serializable> =
60
63
  & WritableSelectorFamilyToken<T, K>
61
64
  & {
62
65
  (key: K): WritableSelectorToken<T>
63
- subject: Subject<WritableSelectorToken<T>>
66
+ subject: Subject<StateCreation<WritableSelectorToken<T>> | StateDisposal<WritableSelectorToken<T>>>
64
67
  install: (store: Store) => void
65
68
  }
66
69
 
@@ -76,15 +79,18 @@ export type ReadonlySelectorFamilyTokenWithCall<
76
79
  K extends Json.Serializable,
77
80
  > =
78
81
  & ReadonlySelectorFamilyToken<T, K>
79
- & /** @deprecated Prefer the `findState`, `findInStore`, or `find` functions. */
80
- ((key: K) => ReadonlySelectorToken<T>)
82
+ & {
83
+ /** @deprecated In ephemeral stores, prefer the `findState`, `findInStore`, or `find` functions. In immortal stores, prefer the `seekState`, `seekInStore`, or `seek` functions. */
84
+ /* eslint-disable-next-line @typescript-eslint/prefer-function-type */
85
+ (key: K): ReadonlySelectorToken<T>
86
+ }
81
87
  // biome-ignore format: intersection
82
88
  export type ReadonlySelectorFamily<T, K extends Json.Serializable> =
83
89
  & ((key: K) => ReadonlySelectorToken<T>)
84
90
  & {
85
91
  key: string
86
92
  type: `readonly_selector_family`
87
- subject: Subject<ReadonlySelectorToken<T>>
93
+ subject: Subject<StateCreation<ReadonlySelectorToken<T>> | StateDisposal<ReadonlySelectorToken<T>>>
88
94
  install: (store: Store) => void
89
95
  __T?: T
90
96
  __K?: K
package/src/silo.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { findState } from "atom.io/ephemeral"
1
2
  import type { Transceiver } from "atom.io/internal"
2
3
  import {
3
4
  createAtomFamily,
@@ -16,7 +17,6 @@ import type { Json } from "atom.io/json"
16
17
 
17
18
  import type {
18
19
  AtomToken,
19
- findState,
20
20
  getState,
21
21
  MutableAtomFamily,
22
22
  MutableAtomFamilyOptions,
@@ -50,8 +50,8 @@ export class Silo {
50
50
  public subscribe: typeof subscribe
51
51
  public undo: typeof undo
52
52
  public redo: typeof redo
53
- public constructor(name: string, fromStore: Store | null = null) {
54
- const s = new Store(name, fromStore)
53
+ public constructor(config: Store[`config`], fromStore: Store | null = null) {
54
+ const s = new Store(config, fromStore)
55
55
  function _atom<T>(options: RegularAtomOptions<T>): RegularAtomToken<T>
56
56
  function _atom<T extends Transceiver<any>, J extends Json.Serializable>(
57
57
  options: MutableAtomOptions<T, J>,
package/src/subscribe.ts CHANGED
@@ -9,6 +9,7 @@ import {
9
9
 
10
10
  import type {
11
11
  FamilyMetadata,
12
+ Flat,
12
13
  Func,
13
14
  ReadableToken,
14
15
  TimelineManageable,
@@ -19,10 +20,13 @@ import type {
19
20
  } from "."
20
21
 
21
22
  export type StateUpdate<T> = { newValue: T; oldValue: T }
22
- export type KeyedStateUpdate<T> = StateUpdate<T> & {
23
- key: string
24
- family?: FamilyMetadata
25
- }
23
+ export type KeyedStateUpdate<T> = Flat<
24
+ StateUpdate<T> & {
25
+ key: string
26
+ type: `atom_update` | `selector_update`
27
+ family?: FamilyMetadata
28
+ }
29
+ >
26
30
  export type UpdateHandler<T> = (update: StateUpdate<T>) => void
27
31
 
28
32
  export type TransactionUpdateHandler<F extends Func> = (