atom.io 0.27.4 → 0.28.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 (134) hide show
  1. package/data/dist/index.d.ts +31 -29
  2. package/data/dist/index.js +65 -81
  3. package/data/src/dict.ts +9 -12
  4. package/data/src/join.ts +30 -33
  5. package/data/src/struct-family.ts +17 -23
  6. package/data/src/struct.ts +9 -12
  7. package/dist/{chunk-JRENM6KL.js → chunk-BX3MTH2Z.js} +482 -385
  8. package/dist/chunk-D52JNVER.js +721 -0
  9. package/dist/chunk-EUVKUTW3.js +89 -0
  10. package/dist/index.d.ts +4 -3
  11. package/dist/index.js +35 -53
  12. package/ephemeral/dist/index.js +1 -1
  13. package/ephemeral/src/find-state.ts +1 -1
  14. package/immortal/dist/index.js +2 -2
  15. package/immortal/src/seek-state.ts +2 -2
  16. package/internal/dist/index.d.ts +141 -87
  17. package/internal/dist/index.js +1 -1
  18. package/internal/src/atom/create-regular-atom.ts +3 -3
  19. package/internal/src/atom/create-standalone-atom.ts +7 -5
  20. package/internal/src/atom/dispose-atom.ts +2 -9
  21. package/internal/src/families/create-atom-family.ts +5 -5
  22. package/internal/src/families/create-readonly-selector-family.ts +20 -9
  23. package/internal/src/families/create-regular-atom-family.ts +15 -6
  24. package/internal/src/families/create-selector-family.ts +5 -5
  25. package/internal/src/families/create-writable-selector-family.ts +20 -10
  26. package/internal/src/families/dispose-from-store.ts +43 -29
  27. package/internal/src/families/find-in-store.ts +28 -18
  28. package/internal/src/families/init-family-member.ts +9 -9
  29. package/internal/src/families/seek-in-store.ts +10 -10
  30. package/internal/src/get-state/get-from-store.ts +70 -47
  31. package/internal/src/ingest-updates/ingest-atom-update.ts +1 -1
  32. package/internal/src/ingest-updates/ingest-creation-disposal.ts +15 -6
  33. package/internal/src/molecule/create-molecule-family.ts +1 -1
  34. package/internal/src/molecule/dispose-molecule.ts +7 -18
  35. package/internal/src/molecule/grow-molecule-in-store.ts +1 -1
  36. package/internal/src/molecule/make-molecule-in-store.ts +5 -5
  37. package/internal/src/mutable/create-mutable-atom-family.ts +15 -6
  38. package/internal/src/mutable/create-mutable-atom.ts +3 -3
  39. package/internal/src/mutable/get-json-token.ts +2 -2
  40. package/internal/src/mutable/tracker-family.ts +3 -3
  41. package/internal/src/mutable/tracker.ts +14 -18
  42. package/internal/src/pretty-print.ts +1 -16
  43. package/internal/src/selector/create-readonly-selector.ts +2 -2
  44. package/internal/src/selector/create-standalone-selector.ts +5 -5
  45. package/internal/src/selector/create-writable-selector.ts +2 -2
  46. package/internal/src/selector/dispose-selector.ts +2 -9
  47. package/internal/src/selector/register-selector.ts +9 -9
  48. package/internal/src/set-state/set-into-store.ts +23 -33
  49. package/internal/src/store/circular-buffer.ts +34 -0
  50. package/internal/src/store/counterfeit.ts +109 -0
  51. package/internal/src/store/deposit.ts +67 -13
  52. package/internal/src/store/index.ts +1 -0
  53. package/internal/src/store/store.ts +4 -1
  54. package/internal/src/store/withdraw.ts +15 -10
  55. package/internal/src/subscribe/index.ts +2 -0
  56. package/internal/src/subscribe/subscribe-in-store.ts +62 -0
  57. package/internal/src/timeline/time-travel.ts +1 -1
  58. package/internal/src/transaction/build-transaction.ts +7 -6
  59. package/introspection/dist/index.d.ts +84 -4
  60. package/introspection/dist/index.js +1 -413
  61. package/introspection/src/attach-atom-index.ts +5 -8
  62. package/introspection/src/attach-introspection-states.ts +7 -4
  63. package/introspection/src/attach-selector-index.ts +6 -8
  64. package/introspection/src/attach-timeline-family.ts +25 -28
  65. package/introspection/src/attach-timeline-index.ts +5 -8
  66. package/introspection/src/attach-transaction-index.ts +5 -8
  67. package/introspection/src/attach-transaction-logs.ts +21 -27
  68. package/introspection/src/attach-type-selectors.ts +26 -0
  69. package/introspection/src/differ.ts +167 -0
  70. package/introspection/src/index.ts +2 -0
  71. package/introspection/src/refinery.ts +100 -0
  72. package/json/dist/index.d.ts +31 -30
  73. package/json/dist/index.js +2 -80
  74. package/json/src/entries.ts +6 -0
  75. package/json/src/index.ts +47 -6
  76. package/json/src/select-json-family.ts +4 -4
  77. package/json/src/select-json.ts +6 -9
  78. package/package.json +17 -8
  79. package/react/dist/index.js +7 -7
  80. package/react/src/parse-state-overloads.ts +2 -2
  81. package/react/src/use-i.ts +1 -1
  82. package/react/src/use-json.ts +2 -2
  83. package/react/src/use-o.ts +2 -2
  84. package/react-devtools/dist/index.d.ts +1 -91
  85. package/react-devtools/dist/index.js +285 -414
  86. package/react-devtools/src/AtomIODevtools.tsx +2 -2
  87. package/react-devtools/src/StateEditor.tsx +20 -12
  88. package/react-devtools/src/StateIndex.tsx +8 -26
  89. package/react-devtools/src/TimelineIndex.tsx +3 -3
  90. package/react-devtools/src/TransactionIndex.tsx +6 -6
  91. package/react-devtools/src/Updates.tsx +1 -4
  92. package/react-devtools/src/index.ts +0 -71
  93. package/react-devtools/src/store.ts +51 -0
  94. package/realtime/dist/index.d.ts +7 -7
  95. package/realtime/dist/index.js +18 -22
  96. package/realtime/src/realtime-continuity.ts +27 -35
  97. package/realtime-client/dist/index.js +59 -65
  98. package/realtime-client/src/pull-atom-family-member.ts +1 -1
  99. package/realtime-client/src/pull-atom.ts +1 -1
  100. package/realtime-client/src/pull-mutable-atom-family-member.ts +3 -3
  101. package/realtime-client/src/pull-mutable-atom.ts +3 -3
  102. package/realtime-client/src/realtime-client-stores/client-main-store.ts +6 -6
  103. package/realtime-client/src/sync-continuity.ts +55 -53
  104. package/realtime-react/dist/index.js +3 -3
  105. package/realtime-react/src/use-pull-atom-family-member.ts +1 -1
  106. package/realtime-react/src/use-pull-mutable-family-member.ts +1 -1
  107. package/realtime-react/src/use-pull-selector-family-member.ts +1 -1
  108. package/realtime-server/dist/index.js +72 -36
  109. package/realtime-server/src/realtime-continuity-synchronizer.ts +57 -93
  110. package/realtime-server/src/realtime-family-provider.ts +3 -3
  111. package/realtime-server/src/realtime-mutable-family-provider.ts +5 -5
  112. package/realtime-server/src/realtime-mutable-provider.ts +2 -2
  113. package/realtime-server/src/realtime-state-provider.ts +1 -1
  114. package/realtime-server/src/realtime-state-receiver.ts +1 -1
  115. package/realtime-testing/dist/index.d.ts +2 -0
  116. package/realtime-testing/dist/index.js +57 -15
  117. package/realtime-testing/src/setup-realtime-test.tsx +66 -16
  118. package/src/atom.ts +2 -2
  119. package/src/dispose-state.ts +2 -2
  120. package/src/get-state.ts +9 -13
  121. package/src/molecule.ts +1 -1
  122. package/src/selector.ts +2 -2
  123. package/src/set-state.ts +10 -7
  124. package/src/silo.ts +29 -55
  125. package/src/subscribe.ts +3 -23
  126. package/src/timeline.ts +2 -2
  127. package/web/dist/index.d.ts +9 -0
  128. package/{dist/chunk-H6EDLPKH.js → web/dist/index.js} +5 -4
  129. package/web/package.json +13 -0
  130. package/web/src/index.ts +1 -0
  131. package/web/src/persist-sync.ts +25 -0
  132. package/dist/chunk-AK23DRMD.js +0 -21
  133. package/dist/chunk-IW6WYRS7.js +0 -140
  134. package/internal/src/families/throw-in-case-of-conflicting-family.ts +0 -18
@@ -0,0 +1,89 @@
1
+ import { createWritableSelectorFamily } from './chunk-BX3MTH2Z.js';
2
+ import { createStandaloneSelector, IMPLICIT, growMoleculeInStore, initFamilyMemberInStore, withdraw, seekInStore } from 'atom.io/internal';
3
+
4
+ // json/src/entries.ts
5
+ function fromEntries(entries) {
6
+ return Object.fromEntries(entries);
7
+ }
8
+ function toEntries(obj) {
9
+ return Object.entries(obj);
10
+ }
11
+ var selectJson = (atom, transform, store = IMPLICIT.STORE) => {
12
+ return createStandaloneSelector(store, {
13
+ key: `${atom.key}:JSON`,
14
+ get: ({ get }) => transform.toJson(get(atom)),
15
+ set: ({ set }, newValue) => {
16
+ set(atom, transform.fromJson(newValue));
17
+ }
18
+ });
19
+ };
20
+ function selectJsonFamily(atomFamilyToken, transform, store = IMPLICIT.STORE) {
21
+ const jsonFamily = createWritableSelectorFamily(
22
+ store,
23
+ {
24
+ key: `${atomFamilyToken.key}:JSON`,
25
+ get: (key) => ({ seek, get }) => {
26
+ const existingState = seek(atomFamilyToken, key);
27
+ if (existingState) {
28
+ return transform.toJson(get(existingState));
29
+ }
30
+ const stringKey = stringifyJson(key);
31
+ const molecule = store.molecules.get(stringKey);
32
+ if (molecule) {
33
+ const atom = growMoleculeInStore(molecule, atomFamilyToken, store);
34
+ return transform.toJson(get(atom));
35
+ }
36
+ if (store.config.lifespan === `immortal`) {
37
+ throw new Error(`No molecule found for key "${stringKey}"`);
38
+ }
39
+ const newToken = initFamilyMemberInStore(store, atomFamilyToken, key);
40
+ return transform.toJson(get(newToken));
41
+ },
42
+ set: (key) => ({ seek, set }, newValue) => {
43
+ const existingState = seek(atomFamilyToken, key);
44
+ if (existingState) {
45
+ set(existingState, transform.fromJson(newValue));
46
+ } else {
47
+ const stringKey = stringifyJson(key);
48
+ const molecule = store.molecules.get(stringKey);
49
+ if (molecule) {
50
+ const atom = growMoleculeInStore(molecule, atomFamilyToken, store);
51
+ set(atom, transform.fromJson(newValue));
52
+ } else {
53
+ if (store.config.lifespan === `immortal`) {
54
+ throw new Error(`No molecule found for key "${stringKey}"`);
55
+ }
56
+ set(
57
+ initFamilyMemberInStore(store, atomFamilyToken, key),
58
+ transform.fromJson(newValue)
59
+ );
60
+ }
61
+ }
62
+ }
63
+ },
64
+ [`mutable`, `json`]
65
+ );
66
+ const atomFamily = withdraw(atomFamilyToken, store);
67
+ atomFamily.subject.subscribe(
68
+ `store=${store.config.name}::json-selector-family`,
69
+ (event) => {
70
+ if (event.token.family) {
71
+ seekInStore(store, jsonFamily, parseJson(event.token.family.subKey));
72
+ }
73
+ }
74
+ );
75
+ return jsonFamily;
76
+ }
77
+
78
+ // json/src/index.ts
79
+ var parseJson = (str) => JSON.parse(str);
80
+ var stringifyJson = (json) => JSON.stringify(json);
81
+ var JSON_PROTOTYPES = [Array, Boolean, Number, Object, String];
82
+ var isJson = (input) => {
83
+ if (input === null) return true;
84
+ if (input === void 0) return false;
85
+ const prototype = Object.getPrototypeOf(input);
86
+ return JSON_PROTOTYPES.includes(prototype);
87
+ };
88
+
89
+ export { fromEntries, isJson, parseJson, selectJson, selectJsonFamily, stringifyJson, toEntries };
package/dist/index.d.ts CHANGED
@@ -341,6 +341,7 @@ declare class Silo {
341
341
  redo: typeof redo;
342
342
  moleculeFamily: typeof moleculeFamily;
343
343
  makeMolecule: typeof makeMolecule;
344
+ runTransaction: typeof runTransaction;
344
345
  constructor(config: Store[`config`], fromStore?: Store | null);
345
346
  }
346
347
 
@@ -355,9 +356,9 @@ type KeyedStateUpdate<T> = Flat<StateUpdate<T> & {
355
356
  }>;
356
357
  type UpdateHandler<T> = (update: StateUpdate<T>) => void;
357
358
  type TransactionUpdateHandler<F extends Func> = (data: TransactionUpdate<F>) => void;
358
- declare function subscribe<T>(token: ReadableToken<T>, handleUpdate: UpdateHandler<T>, key?: string, store?: Store): () => void;
359
- declare function subscribe<F extends Func>(token: TransactionToken<F>, handleUpdate: TransactionUpdateHandler<F>, key?: string, store?: Store): () => void;
360
- declare function subscribe<M extends TimelineManageable>(token: TimelineToken<M>, handleUpdate: (update: TimelineUpdate<M> | `redo` | `undo`) => void, key?: string, store?: Store): () => void;
359
+ declare function subscribe<T>(token: ReadableToken<T>, handleUpdate: UpdateHandler<T>, key?: string): () => void;
360
+ declare function subscribe<F extends Func>(token: TransactionToken<F>, handleUpdate: TransactionUpdateHandler<F>, key?: string): () => void;
361
+ declare function subscribe<M extends TimelineManageable>(token: TimelineToken<M>, handleUpdate: (update: TimelineUpdate<M> | `redo` | `undo`) => void, key?: string): () => void;
361
362
 
362
363
  type TimelineManageable = AtomFamilyToken<any, any> | AtomToken<any>;
363
364
  type AtomOnly<M extends TimelineManageable> = M extends AtomFamilyToken<any, any> ? AtomToken<any> : M extends AtomToken<any> ? M : never;
package/dist/index.js CHANGED
@@ -1,30 +1,26 @@
1
1
  import './chunk-XWL6SNVU.js';
2
2
  import * as Internal from 'atom.io/internal';
3
- import { createStandaloneAtom, IMPLICIT, createAtomFamily, createMoleculeFamily, makeMoleculeInStore, Molecule, createStandaloneSelector, createSelectorFamily, Store, createTransaction, createTimeline, findInStore, getFromStore, setIntoStore, disposeFromStore, timeTravel, subscribeToTimeline, subscribeToTransaction, subscribeToState, arbitrary, actUponStore } from 'atom.io/internal';
3
+ import { createStandaloneAtom, IMPLICIT, createAtomFamily, createMoleculeFamily, makeMoleculeInStore, Molecule, createStandaloneSelector, createSelectorFamily, Store, createTransaction, createTimeline, findInStore, getFromStore, setIntoStore, disposeFromStore, subscribeInStore, timeTravel, actUponStore, arbitrary } from 'atom.io/internal';
4
4
  import { stringifyJson } from 'atom.io/json';
5
5
 
6
6
  function atom(options) {
7
- return createStandaloneAtom(options, IMPLICIT.STORE);
7
+ return createStandaloneAtom(IMPLICIT.STORE, options);
8
8
  }
9
9
  function atomFamily(options) {
10
- return createAtomFamily(options, IMPLICIT.STORE);
10
+ return createAtomFamily(IMPLICIT.STORE, options);
11
11
  }
12
12
  function disposeState(token, key) {
13
13
  if (key) {
14
- Internal.disposeFromStore(token, key, Internal.IMPLICIT.STORE);
14
+ Internal.disposeFromStore(Internal.IMPLICIT.STORE, token, key);
15
15
  } else {
16
- Internal.disposeFromStore(token, Internal.IMPLICIT.STORE);
16
+ Internal.disposeFromStore(Internal.IMPLICIT.STORE, token);
17
17
  }
18
18
  }
19
- function getState(token, key) {
20
- if (key) {
21
- return Internal.getFromStore(
22
- token,
23
- key,
24
- Internal.IMPLICIT.STORE
25
- );
19
+ function getState(...params) {
20
+ if (params.length === 2) {
21
+ return Internal.getFromStore(Internal.IMPLICIT.STORE, ...params);
26
22
  }
27
- return Internal.getFromStore(token, Internal.IMPLICIT.STORE);
23
+ return Internal.getFromStore(Internal.IMPLICIT.STORE, ...params);
28
24
  }
29
25
 
30
26
  // src/logger.ts
@@ -63,7 +59,7 @@ var AtomIOLogger = class {
63
59
  };
64
60
  };
65
61
  function moleculeFamily(options) {
66
- return createMoleculeFamily(options, IMPLICIT.STORE);
62
+ return createMoleculeFamily(IMPLICIT.STORE, options);
67
63
  }
68
64
  function makeMolecule(context, family, key, ...params) {
69
65
  return makeMoleculeInStore(IMPLICIT.STORE, context, family, key, ...params);
@@ -77,16 +73,16 @@ function makeRootMolecule(key, store = IMPLICIT.STORE) {
77
73
  };
78
74
  }
79
75
  function selector(options) {
80
- return createStandaloneSelector(options, IMPLICIT.STORE);
76
+ return createStandaloneSelector(IMPLICIT.STORE, options);
81
77
  }
82
78
  function selectorFamily(options) {
83
- return createSelectorFamily(options, IMPLICIT.STORE);
79
+ return createSelectorFamily(IMPLICIT.STORE, options);
84
80
  }
85
- function setState(token, p1, p2) {
86
- if (p2) {
87
- Internal.setIntoStore(token, p1, p2, Internal.IMPLICIT.STORE);
81
+ function setState(...params) {
82
+ if (params.length === 2) {
83
+ Internal.setIntoStore(Internal.IMPLICIT.STORE, ...params);
88
84
  } else {
89
- Internal.setIntoStore(token, p1, Internal.IMPLICIT.STORE);
85
+ Internal.setIntoStore(Internal.IMPLICIT.STORE, ...params);
90
86
  }
91
87
  }
92
88
  var Silo = class {
@@ -106,65 +102,51 @@ var Silo = class {
106
102
  redo;
107
103
  moleculeFamily;
108
104
  makeMolecule;
105
+ runTransaction;
109
106
  constructor(config, fromStore = null) {
110
107
  const s = new Store(config, fromStore);
111
- function _atom(options) {
112
- return createStandaloneAtom(options, s);
113
- }
114
- function _atomFamily(options) {
115
- return createAtomFamily(options, s);
116
- }
117
108
  this.store = s;
118
- this.atom = _atom;
119
- this.atomFamily = _atomFamily;
120
- this.selector = (options) => createStandaloneSelector(options, s);
121
- this.selectorFamily = (options) => createSelectorFamily(options, s);
109
+ this.atom = (options) => createStandaloneAtom(s, options);
110
+ this.atomFamily = (options) => createAtomFamily(s, options);
111
+ this.selector = (options) => createStandaloneSelector(s, options);
112
+ this.selectorFamily = (options) => createSelectorFamily(s, options);
122
113
  this.transaction = (options) => createTransaction(options, s);
123
114
  this.timeline = (options) => createTimeline(options, s);
124
- this.findState = (token, key) => findInStore(token, key, s);
125
- this.getState = (...params) => getFromStore(...params, s);
115
+ this.findState = (...params) => findInStore(s, ...params);
116
+ this.getState = (...params) => getFromStore(s, ...params);
126
117
  this.setState = (...params) => {
127
- setIntoStore(...params, s);
118
+ setIntoStore(s, ...params);
128
119
  };
129
120
  this.disposeState = (...params) => {
130
- disposeFromStore(...params, s);
121
+ disposeFromStore(s, ...params);
131
122
  };
132
- this.subscribe = (token, handler, key) => subscribe(token, handler, key, s);
123
+ this.subscribe = (...params) => subscribeInStore(s, ...params);
133
124
  this.undo = (token) => {
134
- timeTravel(`undo`, token, s);
125
+ timeTravel(s, `undo`, token);
135
126
  };
136
127
  this.redo = (token) => {
137
- timeTravel(`redo`, token, s);
128
+ timeTravel(s, `redo`, token);
138
129
  };
139
- this.moleculeFamily = (...params) => {
140
- return createMoleculeFamily(...params, s);
130
+ this.moleculeFamily = (options) => {
131
+ return createMoleculeFamily(s, options);
141
132
  };
142
133
  this.makeMolecule = (...params) => {
143
134
  return makeMoleculeInStore(s, ...params);
144
135
  };
136
+ this.runTransaction = (token, id = arbitrary()) => actUponStore(token, id, s);
145
137
  }
146
138
  };
147
- function subscribe(token, handleUpdate, key = arbitrary(), store = IMPLICIT.STORE) {
148
- switch (token.type) {
149
- case `atom`:
150
- case `mutable_atom`:
151
- case `readonly_selector`:
152
- case `selector`:
153
- return subscribeToState(token, handleUpdate, key, store);
154
- case `transaction`:
155
- return subscribeToTransaction(token, handleUpdate, key, store);
156
- case `timeline`:
157
- return subscribeToTimeline(token, handleUpdate, key, store);
158
- }
139
+ function subscribe(token, handleUpdate, key = arbitrary()) {
140
+ return subscribeInStore(IMPLICIT.STORE, token, handleUpdate, key);
159
141
  }
160
142
  var timeline = (options) => {
161
143
  return createTimeline(options, IMPLICIT.STORE);
162
144
  };
163
145
  var redo = (tl) => {
164
- timeTravel(`redo`, tl, IMPLICIT.STORE);
146
+ timeTravel(IMPLICIT.STORE, `redo`, tl);
165
147
  };
166
148
  var undo = (tl) => {
167
- timeTravel(`undo`, tl, IMPLICIT.STORE);
149
+ timeTravel(IMPLICIT.STORE, `undo`, tl);
168
150
  };
169
151
  function transaction(options) {
170
152
  return createTransaction(options, IMPLICIT.STORE);
@@ -2,7 +2,7 @@ import '../../dist/chunk-XWL6SNVU.js';
2
2
  import { findInStore, IMPLICIT } from 'atom.io/internal';
3
3
 
4
4
  function findState(token, key) {
5
- const state = findInStore(token, key, IMPLICIT.STORE);
5
+ const state = findInStore(IMPLICIT.STORE, token, key);
6
6
  return state;
7
7
  }
8
8
 
@@ -92,6 +92,6 @@ export function findState(
92
92
  token: ReadableFamilyToken<any, any>,
93
93
  key: Json.Serializable,
94
94
  ): ReadableToken<any> {
95
- const state = findInStore(token, key, IMPLICIT.STORE)
95
+ const state = findInStore(IMPLICIT.STORE, token, key)
96
96
  return state
97
97
  }
@@ -3,9 +3,9 @@ import { seekInStore, IMPLICIT } from 'atom.io/internal';
3
3
 
4
4
  function seekState(token, key) {
5
5
  if (token.type === `molecule_family`) {
6
- return seekInStore(token, key, IMPLICIT.STORE);
6
+ return seekInStore(IMPLICIT.STORE, token, key);
7
7
  }
8
- const state = seekInStore(token, key, IMPLICIT.STORE);
8
+ const state = seekInStore(IMPLICIT.STORE, token, key);
9
9
  return state;
10
10
  }
11
11
 
@@ -65,8 +65,8 @@ export function seekState(
65
65
  key: Canonical,
66
66
  ): MoleculeToken<any> | ReadableToken<any> | undefined {
67
67
  if (token.type === `molecule_family`) {
68
- return seekInStore(token, key, IMPLICIT.STORE)
68
+ return seekInStore(IMPLICIT.STORE, token, key)
69
69
  }
70
- const state = seekInStore(token, key, IMPLICIT.STORE)
70
+ const state = seekInStore(IMPLICIT.STORE, token, key)
71
71
  return state
72
72
  }