atom.io 0.8.0 → 0.8.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 (38) 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 +2 -2
  34. package/react-devtools/dist/index.d.mts +4 -4
  35. package/react-devtools/dist/index.d.ts +4 -4
  36. package/src/get-set.ts +48 -0
  37. package/src/index.ts +3 -60
  38. package/src/subscribe.ts +3 -3
package/dist/index.d.mts CHANGED
@@ -1,3 +1,4 @@
1
+ import * as Internal from 'atom.io/internal';
1
2
  import { Transceiver, Subject, Store, TimelineAtomUpdate, TimelineSelectorUpdate, TimelineTransactionUpdate } from 'atom.io/internal';
2
3
  import { Json, JsonInterface } from 'atom.io/json';
3
4
 
@@ -41,6 +42,12 @@ type MutableAtomFamily<Core extends Transceiver<any>, SerializableCore extends J
41
42
  declare function atomFamily<T extends Transceiver<any>, J extends Json.Serializable, K extends Json.Serializable>(options: MutableAtomFamilyOptions<T, J, K>): MutableAtomFamily<T, J, K>;
42
43
  declare function atomFamily<T, K extends Json.Serializable>(options: AtomFamilyOptions<T, K>): AtomFamily<T, K>;
43
44
 
45
+ declare const getState: <T>(token: ReadonlySelectorToken<T> | StateToken<T>, store?: Internal.Store) => T;
46
+ declare const setState: <T, New extends T>(token: StateToken<T>, value: New | ((oldValue: T) => New), store?: Internal.Store) => void;
47
+ declare class NotFoundError extends Error {
48
+ constructor(token: ReadonlySelectorToken<any> | StateToken<any>, store: Internal.Store);
49
+ }
50
+
44
51
  declare const NO_OP: () => void;
45
52
  type Logger = Pick<Console, `error` | `info` | `warn`>;
46
53
  declare const LOG_LEVELS: ReadonlyArray<keyof Logger>;
@@ -177,9 +184,5 @@ type FamilyMetadata = {
177
184
  key: string;
178
185
  subKey: string;
179
186
  };
180
- declare const capitalize: (str: string) => string;
181
- declare const getState: <T>(token: ReadonlySelectorToken<T> | StateToken<T>, store?: Store) => T;
182
- declare const setState: <T, New extends T>(token: StateToken<T>, value: New | ((oldValue: T) => New), store?: Store) => void;
183
- declare const isDefault: (token: ReadonlySelectorToken<unknown> | StateToken<unknown>, store?: Store) => boolean;
184
187
 
185
- export { AtomEffect, AtomFamily, AtomFamilyOptions, AtomOptions, AtomToken, Effectors, FamilyMetadata, KeyedStateUpdate, LOG_LEVELS, Logger, MutableAtomFamily, MutableAtomFamilyOptions, MutableAtomOptions, MutableAtomToken, NO_OP, Read, ReadonlySelectorFamily, ReadonlySelectorFamilyOptions, ReadonlySelectorOptions, ReadonlySelectorToken, ReadonlyTransactors, SelectorFamily, SelectorFamilyOptions, SelectorOptions, SelectorToken, Silo, StateToken, StateUpdate, TimelineOptions, TimelineToken, TimelineUpdate, TransactionIO, TransactionOptions, TransactionToken, TransactionUpdate, TransactionUpdateHandler, Transactors, UpdateHandler, Write, atom, atomFamily, capitalize, getState, isDefault, redo, runTransaction, selector, selectorFamily, setLogLevel, setState, subscribe, subscribeToTimeline, subscribeToTransaction, timeline, transaction, undo, useLogger, ƒn };
188
+ export { AtomEffect, AtomFamily, AtomFamilyOptions, AtomOptions, AtomToken, Effectors, FamilyMetadata, KeyedStateUpdate, LOG_LEVELS, Logger, MutableAtomFamily, MutableAtomFamilyOptions, MutableAtomOptions, MutableAtomToken, NO_OP, NotFoundError, Read, ReadonlySelectorFamily, ReadonlySelectorFamilyOptions, ReadonlySelectorOptions, ReadonlySelectorToken, ReadonlyTransactors, SelectorFamily, SelectorFamilyOptions, SelectorOptions, SelectorToken, Silo, StateToken, StateUpdate, TimelineOptions, TimelineToken, TimelineUpdate, TransactionIO, TransactionOptions, TransactionToken, TransactionUpdate, TransactionUpdateHandler, Transactors, UpdateHandler, Write, atom, atomFamily, getState, redo, runTransaction, selector, selectorFamily, setLogLevel, setState, subscribe, subscribeToTimeline, subscribeToTransaction, timeline, transaction, undo, useLogger, ƒn };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import * as Internal from 'atom.io/internal';
1
2
  import { Transceiver, Subject, Store, TimelineAtomUpdate, TimelineSelectorUpdate, TimelineTransactionUpdate } from 'atom.io/internal';
2
3
  import { Json, JsonInterface } from 'atom.io/json';
3
4
 
@@ -41,6 +42,12 @@ type MutableAtomFamily<Core extends Transceiver<any>, SerializableCore extends J
41
42
  declare function atomFamily<T extends Transceiver<any>, J extends Json.Serializable, K extends Json.Serializable>(options: MutableAtomFamilyOptions<T, J, K>): MutableAtomFamily<T, J, K>;
42
43
  declare function atomFamily<T, K extends Json.Serializable>(options: AtomFamilyOptions<T, K>): AtomFamily<T, K>;
43
44
 
45
+ declare const getState: <T>(token: ReadonlySelectorToken<T> | StateToken<T>, store?: Internal.Store) => T;
46
+ declare const setState: <T, New extends T>(token: StateToken<T>, value: New | ((oldValue: T) => New), store?: Internal.Store) => void;
47
+ declare class NotFoundError extends Error {
48
+ constructor(token: ReadonlySelectorToken<any> | StateToken<any>, store: Internal.Store);
49
+ }
50
+
44
51
  declare const NO_OP: () => void;
45
52
  type Logger = Pick<Console, `error` | `info` | `warn`>;
46
53
  declare const LOG_LEVELS: ReadonlyArray<keyof Logger>;
@@ -177,9 +184,5 @@ type FamilyMetadata = {
177
184
  key: string;
178
185
  subKey: string;
179
186
  };
180
- declare const capitalize: (str: string) => string;
181
- declare const getState: <T>(token: ReadonlySelectorToken<T> | StateToken<T>, store?: Store) => T;
182
- declare const setState: <T, New extends T>(token: StateToken<T>, value: New | ((oldValue: T) => New), store?: Store) => void;
183
- declare const isDefault: (token: ReadonlySelectorToken<unknown> | StateToken<unknown>, store?: Store) => boolean;
184
187
 
185
- export { AtomEffect, AtomFamily, AtomFamilyOptions, AtomOptions, AtomToken, Effectors, FamilyMetadata, KeyedStateUpdate, LOG_LEVELS, Logger, MutableAtomFamily, MutableAtomFamilyOptions, MutableAtomOptions, MutableAtomToken, NO_OP, Read, ReadonlySelectorFamily, ReadonlySelectorFamilyOptions, ReadonlySelectorOptions, ReadonlySelectorToken, ReadonlyTransactors, SelectorFamily, SelectorFamilyOptions, SelectorOptions, SelectorToken, Silo, StateToken, StateUpdate, TimelineOptions, TimelineToken, TimelineUpdate, TransactionIO, TransactionOptions, TransactionToken, TransactionUpdate, TransactionUpdateHandler, Transactors, UpdateHandler, Write, atom, atomFamily, capitalize, getState, isDefault, redo, runTransaction, selector, selectorFamily, setLogLevel, setState, subscribe, subscribeToTimeline, subscribeToTransaction, timeline, transaction, undo, useLogger, ƒn };
188
+ export { AtomEffect, AtomFamily, AtomFamilyOptions, AtomOptions, AtomToken, Effectors, FamilyMetadata, KeyedStateUpdate, LOG_LEVELS, Logger, MutableAtomFamily, MutableAtomFamilyOptions, MutableAtomOptions, MutableAtomToken, NO_OP, NotFoundError, Read, ReadonlySelectorFamily, ReadonlySelectorFamilyOptions, ReadonlySelectorOptions, ReadonlySelectorToken, ReadonlyTransactors, SelectorFamily, SelectorFamilyOptions, SelectorOptions, SelectorToken, Silo, StateToken, StateUpdate, TimelineOptions, TimelineToken, TimelineUpdate, TransactionIO, TransactionOptions, TransactionToken, TransactionUpdate, TransactionUpdateHandler, Transactors, UpdateHandler, Write, atom, atomFamily, getState, redo, runTransaction, selector, selectorFamily, setLogLevel, setState, subscribe, subscribeToTimeline, subscribeToTransaction, timeline, transaction, undo, useLogger, ƒn };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var IO = require('atom.io/internal');
3
+ var Internal = require('atom.io/internal');
4
4
 
5
5
  function _interopNamespace(e) {
6
6
  if (e && e.__esModule) return e;
@@ -20,7 +20,7 @@ function _interopNamespace(e) {
20
20
  return Object.freeze(n);
21
21
  }
22
22
 
23
- var IO__namespace = /*#__PURE__*/_interopNamespace(IO);
23
+ var Internal__namespace = /*#__PURE__*/_interopNamespace(Internal);
24
24
 
25
25
  var __defProp = Object.defineProperty;
26
26
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
@@ -40,23 +40,52 @@ var __spreadValues = (a, b) => {
40
40
  };
41
41
  function atom(options) {
42
42
  if (`mutable` in options) {
43
- return IO.createMutableAtom(options);
43
+ return Internal.createMutableAtom(options);
44
44
  }
45
- return IO.createAtom(options);
45
+ return Internal.createAtom(options);
46
46
  }
47
47
  function atomFamily(options) {
48
48
  if (`mutable` in options) {
49
- return IO.createMutableAtomFamily(options);
49
+ return Internal.createMutableAtomFamily(options);
50
50
  }
51
- return IO.createAtomFamily(options);
51
+ return Internal.createAtomFamily(options);
52
52
  }
53
+ var getState = (token, store = Internal__namespace.IMPLICIT.STORE) => {
54
+ var _a;
55
+ const state = (_a = Internal__namespace.withdraw(token, store)) != null ? _a : Internal__namespace.withdrawNewFamilyMember(token, store);
56
+ if (state === void 0) {
57
+ throw new NotFoundError(token, store);
58
+ }
59
+ return Internal__namespace.getState__INTERNAL(state, store);
60
+ };
61
+ var setState = (token, value, store = Internal__namespace.IMPLICIT.STORE) => {
62
+ var _a;
63
+ const rejection = Internal__namespace.openOperation(token, store);
64
+ if (rejection) {
65
+ return;
66
+ }
67
+ const state = (_a = Internal__namespace.withdraw(token, store)) != null ? _a : Internal__namespace.withdrawNewFamilyMember(token, store);
68
+ if (state === void 0) {
69
+ throw new NotFoundError(token, store);
70
+ }
71
+ Internal__namespace.setState__INTERNAL(state, value, store);
72
+ Internal__namespace.closeOperation(store);
73
+ };
74
+ var capitalize = (str) => str[0].toUpperCase() + str.slice(1);
75
+ var NotFoundError = class extends Error {
76
+ constructor(token, store) {
77
+ super(
78
+ `${capitalize(token.type)} "${token.key}" not found in store "${store.config.name}".`
79
+ );
80
+ }
81
+ };
53
82
  var NO_OP = () => void 0;
54
83
  var LOG_LEVELS = [
55
84
  `info`,
56
85
  `warn`,
57
86
  `error`
58
87
  ];
59
- var setLogLevel = (preferredLevel, store = IO.IMPLICIT.STORE) => {
88
+ var setLogLevel = (preferredLevel, store = Internal.IMPLICIT.STORE) => {
60
89
  const { logger__INTERNAL } = store.config;
61
90
  if (preferredLevel === null) {
62
91
  store.config.logger = null;
@@ -71,7 +100,7 @@ var setLogLevel = (preferredLevel, store = IO.IMPLICIT.STORE) => {
71
100
  });
72
101
  }
73
102
  };
74
- var useLogger = (logger, store = IO.IMPLICIT.STORE) => {
103
+ var useLogger = (logger, store = Internal.IMPLICIT.STORE) => {
75
104
  var _a;
76
105
  const currentLogLevel = store.config.logger === null ? null : (_a = LOG_LEVELS.find(
77
106
  (logLevel) => {
@@ -83,49 +112,49 @@ var useLogger = (logger, store = IO.IMPLICIT.STORE) => {
83
112
  setLogLevel(currentLogLevel, store);
84
113
  };
85
114
  function selector(options) {
86
- return IO.createSelector(options);
115
+ return Internal.createSelector(options);
87
116
  }
88
117
  function selectorFamily(options) {
89
- return IO.createSelectorFamily(options);
118
+ return Internal.createSelectorFamily(options);
90
119
  }
91
120
  var Silo = class {
92
121
  constructor(name, fromStore = null) {
93
- const s = new IO.Store(name, fromStore);
122
+ const s = new Internal.Store(name, fromStore);
94
123
  this.store = s;
95
124
  this.atom = (options) => {
96
125
  if (`mutable` in options) {
97
- return IO.createMutableAtom(options, s);
126
+ return Internal.createMutableAtom(options, s);
98
127
  }
99
- return IO.createAtom(options, void 0, s);
128
+ return Internal.createAtom(options, void 0, s);
100
129
  };
101
130
  this.atomFamily = (options) => {
102
131
  if (`mutable` in options) {
103
- return IO.createMutableAtomFamily(options, s);
132
+ return Internal.createMutableAtomFamily(options, s);
104
133
  }
105
- return IO.createAtomFamily(options, s);
134
+ return Internal.createAtomFamily(options, s);
106
135
  };
107
- this.selector = (options) => IO.createSelector(options, void 0, s);
108
- this.selectorFamily = (options) => IO.createSelectorFamily(options, s);
109
- this.transaction = (options) => IO.transaction__INTERNAL(options, s);
110
- this.timeline = (options) => IO.timeline__INTERNAL(options, s);
136
+ this.selector = (options) => Internal.createSelector(options, void 0, s);
137
+ this.selectorFamily = (options) => Internal.createSelectorFamily(options, s);
138
+ this.transaction = (options) => Internal.transaction__INTERNAL(options, s);
139
+ this.timeline = (options) => Internal.timeline__INTERNAL(options, s);
111
140
  this.getState = (token) => getState(token, s);
112
141
  this.setState = (token, newValue) => setState(token, newValue, s);
113
142
  this.subscribe = (token, handler, key) => subscribe(token, handler, key, s);
114
- this.undo = (token) => IO.undo__INTERNAL(token, s);
115
- this.redo = (token) => IO.redo__INTERNAL(token, s);
143
+ this.undo = (token) => Internal.undo__INTERNAL(token, s);
144
+ this.redo = (token) => Internal.redo__INTERNAL(token, s);
116
145
  }
117
146
  };
118
- function subscribe(token, handleUpdate, key = Math.random().toString(36).slice(2), store = IO.IMPLICIT.STORE) {
147
+ function subscribe(token, handleUpdate, key = Math.random().toString(36).slice(2), store = Internal.IMPLICIT.STORE) {
119
148
  var _a;
120
- const state = IO.withdraw(token, store);
121
- if (state === null) {
149
+ const state = Internal.withdraw(token, store);
150
+ if (state === void 0) {
122
151
  throw new Error(
123
152
  `State "${token.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`
124
153
  );
125
154
  }
126
155
  const unsubFunction = state.subject.subscribe(key, handleUpdate);
127
156
  (_a = store.config.logger) == null ? void 0 : _a.info(`\u{1F440} adding subscription "${key}" to "${state.key}"`);
128
- const dependencyUnsubFunctions = state.type !== `atom` ? IO.subscribeToRootAtoms(state, store) : null;
157
+ const dependencyUnsubFunctions = state.type !== `atom` ? Internal.subscribeToRootAtoms(state, store) : null;
129
158
  const unsubscribe = dependencyUnsubFunctions === null ? () => {
130
159
  var _a2;
131
160
  (_a2 = store.config.logger) == null ? void 0 : _a2.info(`\u{1F648} unsubscribe from "${state.key}"`);
@@ -142,10 +171,10 @@ function subscribe(token, handleUpdate, key = Math.random().toString(36).slice(2
142
171
  };
143
172
  return unsubscribe;
144
173
  }
145
- var subscribeToTransaction = (token, handleUpdate, key = Math.random().toString(36).slice(2), store = IO.IMPLICIT.STORE) => {
174
+ var subscribeToTransaction = (token, handleUpdate, key = Math.random().toString(36).slice(2), store = Internal.IMPLICIT.STORE) => {
146
175
  var _a;
147
- const tx = IO.withdraw(token, store);
148
- if (tx === null) {
176
+ const tx = Internal.withdraw(token, store);
177
+ if (tx === void 0) {
149
178
  throw new Error(
150
179
  `Cannot subscribe to transaction "${token.key}": transaction not found in store "${store.config.name}".`
151
180
  );
@@ -158,10 +187,10 @@ var subscribeToTransaction = (token, handleUpdate, key = Math.random().toString(
158
187
  unsubscribe();
159
188
  };
160
189
  };
161
- var subscribeToTimeline = (token, handleUpdate, key = Math.random().toString(36).slice(2), store = IO.IMPLICIT.STORE) => {
190
+ var subscribeToTimeline = (token, handleUpdate, key = Math.random().toString(36).slice(2), store = Internal.IMPLICIT.STORE) => {
162
191
  var _a;
163
- const tl = IO.withdraw(token, store);
164
- if (tl === null) {
192
+ const tl = Internal.withdraw(token, store);
193
+ if (tl === void 0) {
165
194
  throw new Error(
166
195
  `Cannot subscribe to timeline "${token.key}": timeline not found in store "${store.config.name}".`
167
196
  );
@@ -175,19 +204,19 @@ var subscribeToTimeline = (token, handleUpdate, key = Math.random().toString(36)
175
204
  };
176
205
  };
177
206
  var timeline = (options) => {
178
- return IO.timeline__INTERNAL(options);
207
+ return Internal.timeline__INTERNAL(options);
179
208
  };
180
209
  var redo = (token) => {
181
- IO.redo__INTERNAL(token, IO.IMPLICIT.STORE);
210
+ Internal.redo__INTERNAL(token, Internal.IMPLICIT.STORE);
182
211
  };
183
212
  var undo = (token) => {
184
- IO.undo__INTERNAL(token, IO.IMPLICIT.STORE);
213
+ Internal.undo__INTERNAL(token, Internal.IMPLICIT.STORE);
185
214
  };
186
215
  function transaction(options) {
187
- return IO.transaction__INTERNAL(options);
216
+ return Internal.transaction__INTERNAL(options);
188
217
  }
189
- var runTransaction = (token, store = IO.IMPLICIT.STORE) => (...parameters) => {
190
- const tx = IO.withdraw(token, store);
218
+ var runTransaction = (token, store = Internal.IMPLICIT.STORE) => (...parameters) => {
219
+ const tx = Internal.withdraw(token, store);
191
220
  if (tx) {
192
221
  return tx.run(...parameters);
193
222
  }
@@ -196,47 +225,13 @@ var runTransaction = (token, store = IO.IMPLICIT.STORE) => (...parameters) => {
196
225
  );
197
226
  };
198
227
 
199
- // src/index.ts
200
- var capitalize = (str) => str[0].toUpperCase() + str.slice(1);
201
- var getState = (token, store = IO__namespace.IMPLICIT.STORE) => {
202
- var _a;
203
- const state = (_a = IO__namespace.withdraw(token, store)) != null ? _a : IO__namespace.withdrawNewFamilyMember(token, store);
204
- if (state === null) {
205
- throw new Error(
206
- `${capitalize(token.type)} "${token.key}" not found in store "${store.config.name}".`
207
- );
208
- }
209
- return IO__namespace.getState__INTERNAL(state, store);
210
- };
211
- var setState = (token, value, store = IO__namespace.IMPLICIT.STORE) => {
212
- var _a;
213
- try {
214
- IO__namespace.openOperation(token, store);
215
- } catch (thrown) {
216
- if (!(typeof thrown === `symbol`)) {
217
- throw thrown;
218
- }
219
- return;
220
- }
221
- const state = (_a = IO__namespace.withdraw(token, store)) != null ? _a : IO__namespace.withdrawNewFamilyMember(token, store);
222
- if (state === null) {
223
- throw new Error(
224
- `${capitalize(token.type)} "${token.key}" not found in store "${store.config.name}".`
225
- );
226
- }
227
- IO__namespace.setState__INTERNAL(state, value, store);
228
- IO__namespace.closeOperation(store);
229
- };
230
- var isDefault = (token, store = IO__namespace.IMPLICIT.STORE) => token.type === `atom` ? IO__namespace.isAtomDefault(token.key, store) : IO__namespace.isSelectorDefault(token.key, store);
231
-
232
228
  exports.LOG_LEVELS = LOG_LEVELS;
233
229
  exports.NO_OP = NO_OP;
230
+ exports.NotFoundError = NotFoundError;
234
231
  exports.Silo = Silo;
235
232
  exports.atom = atom;
236
233
  exports.atomFamily = atomFamily;
237
- exports.capitalize = capitalize;
238
234
  exports.getState = getState;
239
- exports.isDefault = isDefault;
240
235
  exports.redo = redo;
241
236
  exports.runTransaction = runTransaction;
242
237
  exports.selector = selector;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/atom.ts","../src/logger.ts","../src/selector.ts","../src/silo.ts","../src/subscribe.ts","../src/timeline.ts","../src/transaction.ts"],"names":["_a","createAtom","createAtomFamily","createMutableAtom","createMutableAtomFamily","createSelector","createSelectorFamily","IMPLICIT","redo__INTERNAL","timeline__INTERNAL","undo__INTERNAL","transaction__INTERNAL","withdraw"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,YAAY,QAAQ;;;ACCpB;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AA8BA,SAAS,KACf,SACiB;AACjB,MAAI,aAAa,SAAS;AACzB,WAAO,kBAAkB,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QAC1B,IAAI,CAAC,EAAE,YAAY,IAAI,IAAI,MAAM,CAAC;AAE5B,IAAM,WAAW,CACvB,OACA,QAAkB,YAAS,UACpB;AAtDR;AAuDC,QAAM,SACL,KAAG,YAAS,OAAO,KAAK,MAAxB,YAAgC,2BAAwB,OAAO,KAAK;AACrE,MAAI,UAAU,MAAM;AACnB,UAAM,IAAI;AAAA,MACT,GAAG,WAAW,MAAM,IAAI,CAAC,KAAK,MAAM,GAAG,yBACtC,MAAM,OAAO,IACd;AAAA,IACD;AAAA,EACD;AACA,SAAU,sBAAmB,OAAO,KAAK;AAC1C;AAEO,IAAM,WAAW,CACvB,OACA,OACA,QAAkB,YAAS,UACjB;AAvEX;AAwEC,MAAI;AACH,IAAG,iBAAc,OAAO,KAAK;AAAA,EAC9B,SAAS,QAAQ;AAChB,QAAI,EAAE,OAAO,WAAW,WAAW;AAClC,YAAM;AAAA,IACP;AACA;AAAA,EACD;AACA,QAAM,SACL,KAAG,YAAS,OAAO,KAAK,MAAxB,YAAgC,2BAAwB,OAAO,KAAK;AACrE,MAAI,UAAU,MAAM;AACnB,UAAM,IAAI;AAAA,MACT,GAAG,WAAW,MAAM,IAAI,CAAC,KAAK,MAAM,GAAG,yBACtC,MAAM,OAAO,IACd;AAAA,IACD;AAAA,EACD;AACA,EAAG,sBAAmB,OAAO,OAAO,KAAK;AACzC,EAAG,kBAAe,KAAK;AACxB;AAEO,IAAM,YAAY,CACxB,OACA,QAAkB,YAAS,UAE3B,MAAM,SAAS,SACT,iBAAc,MAAM,KAAK,KAAK,IAC9B,qBAAkB,MAAM,KAAK,KAAK","sourcesContent":["import * as IO from \"atom.io/internal\"\nimport type { Store, Transceiver } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nexport * from \"./atom\"\nexport * from \"./logger\"\nexport * from \"./selector\"\nexport * from \"./silo\"\nexport { subscribe } from \"./subscribe\"\nexport * from \"./subscribe\"\nexport * from \"./timeline\"\nexport * from \"./transaction\"\n\nexport type ƒn = (...parameters: any[]) => any\n\nexport type AtomToken<_> = {\n\tkey: string\n\ttype: `atom`\n\tfamily?: FamilyMetadata\n\t__brand?: _\n}\nexport interface MutableAtomToken<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n> extends AtomToken<T> {\n\t__asJSON?: J\n\t__update?: T extends Transceiver<infer Update> ? Update : never\n}\nexport type SelectorToken<_> = {\n\tkey: string\n\ttype: `selector`\n\tfamily?: FamilyMetadata\n\t__brand?: _\n}\nexport type StateToken<T> = AtomToken<T> | SelectorToken<T>\n\nexport type ReadonlySelectorToken<_> = {\n\tkey: string\n\ttype: `readonly_selector`\n\tfamily?: FamilyMetadata\n\t__brand?: _\n}\n\nexport type FamilyMetadata = {\n\tkey: string\n\tsubKey: string\n}\n\nexport const capitalize = (str: string): string =>\n\tstr[0].toUpperCase() + str.slice(1)\n\nexport const getState = <T>(\n\ttoken: ReadonlySelectorToken<T> | StateToken<T>,\n\tstore: Store = IO.IMPLICIT.STORE,\n): T => {\n\tconst state =\n\t\tIO.withdraw(token, store) ?? IO.withdrawNewFamilyMember(token, store)\n\tif (state === null) {\n\t\tthrow new Error(\n\t\t\t`${capitalize(token.type)} \"${token.key}\" not found in store \"${\n\t\t\t\tstore.config.name\n\t\t\t}\".`,\n\t\t)\n\t}\n\treturn IO.getState__INTERNAL(state, store)\n}\n\nexport const setState = <T, New extends T>(\n\ttoken: StateToken<T>,\n\tvalue: New | ((oldValue: T) => New),\n\tstore: Store = IO.IMPLICIT.STORE,\n): void => {\n\ttry {\n\t\tIO.openOperation(token, store)\n\t} catch (thrown) {\n\t\tif (!(typeof thrown === `symbol`)) {\n\t\t\tthrow thrown\n\t\t}\n\t\treturn\n\t}\n\tconst state =\n\t\tIO.withdraw(token, store) ?? IO.withdrawNewFamilyMember(token, store)\n\tif (state === null) {\n\t\tthrow new Error(\n\t\t\t`${capitalize(token.type)} \"${token.key}\" not found in store \"${\n\t\t\t\tstore.config.name\n\t\t\t}\".`,\n\t\t)\n\t}\n\tIO.setState__INTERNAL(state, value, store)\n\tIO.closeOperation(store)\n}\n\nexport const isDefault = (\n\ttoken: ReadonlySelectorToken<unknown> | StateToken<unknown>,\n\tstore: Store = IO.IMPLICIT.STORE,\n): boolean =>\n\ttoken.type === `atom`\n\t\t? IO.isAtomDefault(token.key, store)\n\t\t: IO.isSelectorDefault(token.key, store)\n","import type { Subject, Transceiver } from \"atom.io/internal\"\nimport {\n\tcreateAtom,\n\tcreateAtomFamily,\n\tcreateMutableAtom,\n\tcreateMutableAtomFamily,\n} from \"atom.io/internal\"\nimport type { Json, JsonInterface } from \"atom.io/json\"\n\nimport type { AtomToken, MutableAtomToken } from \".\"\n\nexport type Effectors<T> = {\n\tsetSelf: <V extends T>(next: V | ((oldValue: T) => V)) => void\n\tonSet: (callback: (options: { newValue: T; oldValue: T }) => void) => void\n}\n\nexport type AtomEffect<T> = (tools: Effectors<T>) => void\n\nexport type AtomOptions<T> = {\n\tkey: string\n\tdefault: T | (() => T)\n\teffects?: AtomEffect<T>[]\n}\n// biome-ignore format: complex intersection\nexport type MutableAtomOptions<T extends Transceiver<any>, J extends Json.Serializable> = \n\t& JsonInterface<T, J>\n\t& Omit<AtomOptions<T>, `default`> \n\t& { \n\t\t\tdefault: ()\t=> T\n\t\t\tmutable: true\n\t\t}\n\nexport function atom<T extends Transceiver<any>, J extends Json.Serializable>(\n\toptions: MutableAtomOptions<T, J>,\n): MutableAtomToken<T, J>\nexport function atom<T>(options: AtomOptions<T>): AtomToken<T>\nexport function atom<T>(\n\toptions: AtomOptions<any> | MutableAtomOptions<any, any>,\n): AtomToken<any> {\n\tif (`mutable` in options) {\n\t\treturn createMutableAtom(options)\n\t}\n\treturn createAtom<T>(options)\n}\n\nexport type AtomFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tdefault: T | ((key: K) => T)\n\teffects?: (key: K) => AtomEffect<T>[]\n}\n\nexport type AtomFamily<T, K extends Json.Serializable = Json.Serializable> = ((\n\tkey: K,\n) => AtomToken<T>) & {\n\tkey: string\n\ttype: `atom_family`\n\tsubject: Subject<AtomToken<T>>\n}\n// biome-ignore format: intersection\nexport type MutableAtomFamilyOptions<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n> = \n\t& AtomFamilyOptions<T, K>\n\t& JsonInterface<T, J>\n\t& { mutable: true }\n\n// biome-ignore format: intersection\nexport type MutableAtomFamily<\n\tCore extends Transceiver<any>,\n\tSerializableCore extends Json.Serializable,\n\tKey extends Json.Serializable,\n> = \n\t& JsonInterface<Core, SerializableCore>\n\t& ((key: Key) => MutableAtomToken<Core, SerializableCore>) \n\t& {\n\t\t\tkey: `${string}::mutable`\n\t\t\ttype: `atom_family`\n\t\t\tsubject: Subject<MutableAtomToken<Core, SerializableCore>>\n\t\t}\n\nexport function atomFamily<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n>(options: MutableAtomFamilyOptions<T, J, K>): MutableAtomFamily<T, J, K>\nexport function atomFamily<T, K extends Json.Serializable>(\n\toptions: AtomFamilyOptions<T, K>,\n): AtomFamily<T, K>\nexport function atomFamily<T, K extends Json.Serializable>(\n\toptions: AtomFamilyOptions<T, K> | MutableAtomFamilyOptions<any, any, any>,\n): AtomFamily<T, K> | MutableAtomFamily<any, any, any> {\n\tif (`mutable` in options) {\n\t\treturn createMutableAtomFamily(options)\n\t}\n\treturn createAtomFamily<T, K>(options)\n}\n","import { IMPLICIT } from \"atom.io/internal\"\nimport type { Store } from \"atom.io/internal\"\n\nexport const NO_OP = (): void => undefined\n\nexport type Logger = Pick<Console, `error` | `info` | `warn`>\nexport const LOG_LEVELS: ReadonlyArray<keyof Logger> = [\n\t`info`,\n\t`warn`,\n\t`error`,\n] as const\n\nexport const setLogLevel = (\n\tpreferredLevel: `error` | `info` | `warn` | null,\n\tstore: Store = IMPLICIT.STORE,\n): void => {\n\tconst { logger__INTERNAL } = store.config\n\tif (preferredLevel === null) {\n\t\tstore.config.logger = null\n\t} else {\n\t\tstore.config.logger = { ...console }\n\t\tLOG_LEVELS.forEach((logLevel) => {\n\t\t\tif (LOG_LEVELS.indexOf(logLevel) < LOG_LEVELS.indexOf(preferredLevel)) {\n\t\t\t\t// biome-ignore lint/style/noNonNullAssertion: we just set it\n\t\t\t\tstore.config.logger![logLevel] = NO_OP\n\t\t\t} else {\n\t\t\t\t// biome-ignore lint/style/noNonNullAssertion: we just set it\n\t\t\t\tstore.config.logger![logLevel] = logger__INTERNAL[logLevel]\n\t\t\t}\n\t\t})\n\t}\n}\n\nexport const useLogger = (\n\tlogger: Logger,\n\tstore: Store = IMPLICIT.STORE,\n): void => {\n\tconst currentLogLevel =\n\t\tstore.config.logger === null\n\t\t\t? null\n\t\t\t: LOG_LEVELS.find(\n\t\t\t\t\t(logLevel) => store.config.logger?.[logLevel] !== NO_OP,\n\t\t\t ) ?? null\n\tstore.config.logger__INTERNAL = { ...logger }\n\tsetLogLevel(currentLogLevel, store)\n}\n","import type { Subject } from \"atom.io/internal\"\nimport { createSelector, createSelectorFamily } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { ReadonlySelectorToken, SelectorToken } from \".\"\nimport type { Read, Write } from \"./transaction\"\n\nexport type SelectorOptions<T> = {\n\tkey: string\n\tget: Read<() => T>\n\tset: Write<(newValue: T) => void>\n}\nexport type ReadonlySelectorOptions<T> = {\n\tkey: string\n\tget: Read<() => T>\n}\n\nexport function selector<T>(options: SelectorOptions<T>): SelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T>,\n): ReadonlySelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T> | SelectorOptions<T>,\n): ReadonlySelectorToken<T> | SelectorToken<T> {\n\treturn createSelector(options)\n}\n\nexport type SelectorFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tget: (key: K) => Read<() => T>\n\tset: (key: K) => Write<(newValue: T) => void>\n}\nexport type ReadonlySelectorFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tget: (key: K) => Read<() => T>\n}\n\nexport type SelectorFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => SelectorToken<T>) & {\n\tkey: string\n\ttype: `selector_family`\n\tsubject: Subject<SelectorToken<T>>\n}\n\nexport type ReadonlySelectorFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => ReadonlySelectorToken<T>) & {\n\tkey: string\n\ttype: `readonly_selector_family`\n\tsubject: Subject<ReadonlySelectorToken<T>>\n}\n\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: SelectorFamilyOptions<T, K>,\n): SelectorFamily<T, K>\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: ReadonlySelectorFamilyOptions<T, K>,\n): ReadonlySelectorFamily<T, K>\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: ReadonlySelectorFamilyOptions<T, K> | SelectorFamilyOptions<T, K>,\n): ReadonlySelectorFamily<T, K> | SelectorFamily<T, K> {\n\treturn createSelectorFamily(options)\n}\n","import {\n\tStore,\n\tcreateAtom,\n\tcreateAtomFamily,\n\tcreateMutableAtom,\n\tcreateMutableAtomFamily,\n\tcreateSelector,\n\tcreateSelectorFamily,\n\tredo__INTERNAL,\n\ttimeline__INTERNAL,\n\ttransaction__INTERNAL,\n\tundo__INTERNAL,\n} from \"atom.io/internal\"\n\nimport type { redo, timeline, undo } from \".\"\nimport { getState, setState, subscribe } from \".\"\nimport type { atom, atomFamily } from \"./atom\"\nimport type { selector, selectorFamily } from \"./selector\"\nimport type { transaction } from \"./transaction\"\n\nexport class Silo {\n\tpublic store: Store\n\tpublic atom: typeof atom\n\tpublic atomFamily: typeof atomFamily\n\tpublic selector: typeof selector\n\tpublic selectorFamily: typeof selectorFamily\n\tpublic transaction: typeof transaction\n\tpublic timeline: typeof timeline\n\tpublic getState: typeof getState\n\tpublic setState: typeof setState\n\tpublic subscribe: typeof subscribe\n\tpublic undo: typeof undo\n\tpublic redo: typeof redo\n\tpublic constructor(name: string, fromStore: Store | null = null) {\n\t\tconst s = new Store(name, fromStore)\n\t\tthis.store = s\n\t\tthis.atom = (options) => {\n\t\t\tif (`mutable` in options) {\n\t\t\t\treturn createMutableAtom(options, s)\n\t\t\t}\n\t\t\treturn createAtom(options, undefined, s)\n\t\t}\n\t\tthis.atomFamily = (options) => {\n\t\t\tif (`mutable` in options) {\n\t\t\t\treturn createMutableAtomFamily(options, s) as any\n\t\t\t}\n\t\t\treturn createAtomFamily(options, s)\n\t\t}\n\t\tthis.selector = (options) => createSelector(options, undefined, s) as any\n\t\tthis.selectorFamily = (options) => createSelectorFamily(options, s) as any\n\t\tthis.transaction = (options) => transaction__INTERNAL(options, s)\n\t\tthis.timeline = (options) => timeline__INTERNAL(options, s)\n\t\tthis.getState = (token) => getState(token, s)\n\t\tthis.setState = (token, newValue) => setState(token, newValue, s)\n\t\tthis.subscribe = (token, handler, key) => subscribe(token, handler, key, s)\n\t\tthis.undo = (token) => undo__INTERNAL(token, s)\n\t\tthis.redo = (token) => redo__INTERNAL(token, s)\n\t}\n}\n","import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT, subscribeToRootAtoms, withdraw } from \"atom.io/internal\"\n\nimport type {\n\tFamilyMetadata,\n\tReadonlySelectorToken,\n\tStateToken,\n\tTimelineToken,\n\tTimelineUpdate,\n\tTransactionToken,\n\tTransactionUpdate,\n\tƒn,\n} from \".\"\n\nexport type StateUpdate<T> = { newValue: T; oldValue: T }\nexport type KeyedStateUpdate<T> = StateUpdate<T> & {\n\tkey: string\n\tfamily?: FamilyMetadata\n}\nexport type UpdateHandler<T> = (update: StateUpdate<T>) => void\n\nexport function subscribe<T>(\n\ttoken: ReadonlySelectorToken<T> | StateToken<T>,\n\thandleUpdate: UpdateHandler<T>,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore: Store = IMPLICIT.STORE,\n): () => void {\n\tconst state = withdraw<T>(token, store)\n\tif (state === null) {\n\t\tthrow new Error(\n\t\t\t`State \"${token.key}\" not found in this store. Did you forget to initialize with the \"atom\" or \"selector\" function?`,\n\t\t)\n\t}\n\tconst unsubFunction = state.subject.subscribe(key, handleUpdate)\n\tstore.config.logger?.info(`👀 adding subscription \"${key}\" to \"${state.key}\"`)\n\tconst dependencyUnsubFunctions =\n\t\tstate.type !== `atom` ? subscribeToRootAtoms(state, store) : null\n\n\tconst unsubscribe =\n\t\tdependencyUnsubFunctions === null\n\t\t\t? () => {\n\t\t\t\t\tstore.config.logger?.info(`🙈 unsubscribe from \"${state.key}\"`)\n\t\t\t\t\tunsubFunction()\n\t\t\t }\n\t\t\t: () => {\n\t\t\t\t\tstore.config.logger?.info(\n\t\t\t\t\t\t`🙈 unsubscribe from \"${state.key}\" and its dependencies`,\n\t\t\t\t\t)\n\t\t\t\t\tunsubFunction()\n\t\t\t\t\tfor (const unsubFromDependency of dependencyUnsubFunctions) {\n\t\t\t\t\t\tunsubFromDependency()\n\t\t\t\t\t}\n\t\t\t }\n\n\treturn unsubscribe\n}\n\nexport type TransactionUpdateHandler<ƒ extends ƒn> = (\n\tdata: TransactionUpdate<ƒ>,\n) => void\n\nexport const subscribeToTransaction = <ƒ extends ƒn>(\n\ttoken: TransactionToken<ƒ>,\n\thandleUpdate: TransactionUpdateHandler<ƒ>,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore = IMPLICIT.STORE,\n): (() => void) => {\n\tconst tx = withdraw(token, store)\n\tif (tx === null) {\n\t\tthrow new Error(\n\t\t\t`Cannot subscribe to transaction \"${token.key}\": transaction not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n\tstore.config.logger?.info(`👀 subscribe to transaction \"${token.key}\"`)\n\tconst unsubscribe = tx.subject.subscribe(key, handleUpdate)\n\treturn () => {\n\t\tstore.config.logger?.info(`🙈 unsubscribe from transaction \"${token.key}\"`)\n\t\tunsubscribe()\n\t}\n}\n\nexport const subscribeToTimeline = (\n\ttoken: TimelineToken,\n\thandleUpdate: (update: TimelineUpdate | `redo` | `undo`) => void,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore = IMPLICIT.STORE,\n): (() => void) => {\n\tconst tl = withdraw(token, store)\n\tif (tl === null) {\n\t\tthrow new Error(\n\t\t\t`Cannot subscribe to timeline \"${token.key}\": timeline not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n\tstore.config.logger?.info(`👀 subscribe to timeline \"${token.key}\"`)\n\tconst unsubscribe = tl.subject.subscribe(key, handleUpdate)\n\treturn () => {\n\t\tstore.config.logger?.info(`🙈 unsubscribe from timeline \"${token.key}\"`)\n\t\tunsubscribe()\n\t}\n}\n","import type {\n\tTimelineAtomUpdate,\n\tTimelineSelectorUpdate,\n\tTimelineTransactionUpdate,\n} from \"atom.io/internal\"\nimport {\n\tIMPLICIT,\n\tredo__INTERNAL,\n\ttimeline__INTERNAL,\n\tundo__INTERNAL,\n} from \"atom.io/internal\"\n\nimport type { AtomFamily, AtomToken } from \".\"\n\nexport type TimelineToken = {\n\tkey: string\n\ttype: `timeline`\n}\n\nexport type TimelineOptions = {\n\tkey: string\n\tatoms: (AtomFamily<any, any> | AtomToken<any>)[]\n}\n\nexport type TimelineUpdate =\n\t| TimelineAtomUpdate\n\t| TimelineSelectorUpdate\n\t| TimelineTransactionUpdate\n\nexport const timeline = (options: TimelineOptions): TimelineToken => {\n\treturn timeline__INTERNAL(options)\n}\n\nexport const redo = (token: TimelineToken): void => {\n\tredo__INTERNAL(token, IMPLICIT.STORE)\n}\n\nexport const undo = (token: TimelineToken): void => {\n\tundo__INTERNAL(token, IMPLICIT.STORE)\n}\n","import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT, transaction__INTERNAL, withdraw } from \"atom.io/internal\"\n\nimport type { KeyedStateUpdate, ReadonlySelectorToken, StateToken, ƒn } from \".\"\n\nexport type TransactionToken<_> = {\n\tkey: string\n\ttype: `transaction`\n\t__brand?: _\n}\n\nexport type TransactionUpdate<ƒ extends ƒn> = {\n\tkey: string\n\tatomUpdates: KeyedStateUpdate<unknown>[]\n\tparams: Parameters<ƒ>\n\toutput: ReturnType<ƒ>\n}\n\nexport type Transactors = {\n\tget: <S>(state: ReadonlySelectorToken<S> | StateToken<S>) => S\n\tset: <S>(state: StateToken<S>, newValue: S | ((oldValue: S) => S)) => void\n}\nexport type ReadonlyTransactors = Pick<Transactors, `get`>\n\nexport type Read<ƒ extends ƒn> = (\n\ttransactors: ReadonlyTransactors,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type Write<ƒ extends ƒn> = (\n\ttransactors: Transactors,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type TransactionOptions<ƒ extends ƒn> = {\n\tkey: string\n\tdo: Write<ƒ>\n}\n\nexport type TransactionIO<Token extends TransactionToken<any>> =\n\tToken extends TransactionToken<infer ƒ> ? ƒ : never\n\nexport function transaction<ƒ extends ƒn>(\n\toptions: TransactionOptions<ƒ>,\n): TransactionToken<ƒ> {\n\treturn transaction__INTERNAL(options)\n}\n\nexport const runTransaction =\n\t<ƒ extends ƒn>(token: TransactionToken<ƒ>, store: Store = IMPLICIT.STORE) =>\n\t(...parameters: Parameters<ƒ>): ReturnType<ƒ> => {\n\t\tconst tx = withdraw(token, store)\n\t\tif (tx) {\n\t\t\treturn tx.run(...parameters)\n\t\t}\n\t\tthrow new Error(\n\t\t\t`Cannot run transaction \"${token.key}\": transaction not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n"]}
1
+ {"version":3,"sources":["../src/atom.ts","../src/get-set.ts","../src/logger.ts","../src/selector.ts","../src/silo.ts","../src/subscribe.ts","../src/timeline.ts","../src/transaction.ts"],"names":["IMPLICIT","_a","createAtom","createAtomFamily","createMutableAtom","createMutableAtomFamily","createSelector","createSelectorFamily","withdraw","redo__INTERNAL","timeline__INTERNAL","undo__INTERNAL","transaction__INTERNAL"],"mappings":";;;;;;;;;;;;;;;;;;AACA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EAC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ACA,cAAM,OAAO,WAAb,mBAAqB,KAAK,oCAA6B,MAAM,GAAG;AAChE,QAAM,cAAc,GAAG,QAAQ,UAAU,KAAK,YAAY;AAC1D,SAAO,MAAM;AA/Fd,QAAAP;AAgGE,KAAAA,MAAA,MAAM,OAAO,WAAb,gBAAAA,IAAqB,KAAK,wCAAiC,MAAM,GAAG;AACpE,gBAAY;AAAA,EACb;AACD;;;AC9FA;AAAA,EACC,YAAAD;AAAA,EACA,kBAAAS;AAAA,EACA,sBAAAC;AAAA,EACA,kBAAAC;AAAA,OACM;AAmBA,IAAM,WAAW,CAAC,YAA4C;AACpE,SAAOD,oBAAmB,OAAO;AAClC;AAEO,IAAM,OAAO,CAAC,UAA+B;AACnD,EAAAD,gBAAe,OAAOT,UAAS,KAAK;AACrC;AAEO,IAAM,OAAO,CAAC,UAA+B;AACnD,EAAAW,gBAAe,OAAOX,UAAS,KAAK;AACrC;;;ACtCA,SAAS,YAAAA,WAAU,yBAAAY,wBAAuB,YAAAJ,iBAAgB;AAyCnD,SAAS,YACf,SACsB;AACtB,SAAOI,uBAAsB,OAAO;AACrC;AAEO,IAAM,iBACZ,CAAe,OAA4B,QAAeZ,UAAS,UACnE,IAAI,eAA6C;AAChD,QAAM,KAAKQ,UAAS,OAAO,KAAK;AAChC,MAAI,IAAI;AACP,WAAO,GAAG,IAAI,GAAG,UAAU;AAAA,EAC5B;AACA,QAAM,IAAI;AAAA,IACT,2BAA2B,MAAM,GAAG,sCAAsC,MAAM,OAAO,IAAI;AAAA,EAC5F;AACD","sourcesContent":["import type { Subject, Transceiver } from \"atom.io/internal\"\nimport {\n\tcreateAtom,\n\tcreateAtomFamily,\n\tcreateMutableAtom,\n\tcreateMutableAtomFamily,\n} from \"atom.io/internal\"\nimport type { Json, JsonInterface } from \"atom.io/json\"\n\nimport type { AtomToken, MutableAtomToken } from \".\"\n\nexport type Effectors<T> = {\n\tsetSelf: <V extends T>(next: V | ((oldValue: T) => V)) => void\n\tonSet: (callback: (options: { newValue: T; oldValue: T }) => void) => void\n}\n\nexport type AtomEffect<T> = (tools: Effectors<T>) => void\n\nexport type AtomOptions<T> = {\n\tkey: string\n\tdefault: T | (() => T)\n\teffects?: AtomEffect<T>[]\n}\n// biome-ignore format: complex intersection\nexport type MutableAtomOptions<T extends Transceiver<any>, J extends Json.Serializable> = \n\t& JsonInterface<T, J>\n\t& Omit<AtomOptions<T>, `default`> \n\t& { \n\t\t\tdefault: ()\t=> T\n\t\t\tmutable: true\n\t\t}\n\nexport function atom<T extends Transceiver<any>, J extends Json.Serializable>(\n\toptions: MutableAtomOptions<T, J>,\n): MutableAtomToken<T, J>\nexport function atom<T>(options: AtomOptions<T>): AtomToken<T>\nexport function atom<T>(\n\toptions: AtomOptions<any> | MutableAtomOptions<any, any>,\n): AtomToken<any> {\n\tif (`mutable` in options) {\n\t\treturn createMutableAtom(options)\n\t}\n\treturn createAtom<T>(options)\n}\n\nexport type AtomFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tdefault: T | ((key: K) => T)\n\teffects?: (key: K) => AtomEffect<T>[]\n}\n\nexport type AtomFamily<T, K extends Json.Serializable = Json.Serializable> = ((\n\tkey: K,\n) => AtomToken<T>) & {\n\tkey: string\n\ttype: `atom_family`\n\tsubject: Subject<AtomToken<T>>\n}\n// biome-ignore format: intersection\nexport type MutableAtomFamilyOptions<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n> = \n\t& AtomFamilyOptions<T, K>\n\t& JsonInterface<T, J>\n\t& { mutable: true }\n\n// biome-ignore format: intersection\nexport type MutableAtomFamily<\n\tCore extends Transceiver<any>,\n\tSerializableCore extends Json.Serializable,\n\tKey extends Json.Serializable,\n> = \n\t& JsonInterface<Core, SerializableCore>\n\t& ((key: Key) => MutableAtomToken<Core, SerializableCore>) \n\t& {\n\t\t\tkey: `${string}::mutable`\n\t\t\ttype: `atom_family`\n\t\t\tsubject: Subject<MutableAtomToken<Core, SerializableCore>>\n\t\t}\n\nexport function atomFamily<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n>(options: MutableAtomFamilyOptions<T, J, K>): MutableAtomFamily<T, J, K>\nexport function atomFamily<T, K extends Json.Serializable>(\n\toptions: AtomFamilyOptions<T, K>,\n): AtomFamily<T, K>\nexport function atomFamily<T, K extends Json.Serializable>(\n\toptions: AtomFamilyOptions<T, K> | MutableAtomFamilyOptions<any, any, any>,\n): AtomFamily<T, K> | MutableAtomFamily<any, any, any> {\n\tif (`mutable` in options) {\n\t\treturn createMutableAtomFamily(options)\n\t}\n\treturn createAtomFamily<T, K>(options)\n}\n","import * as Internal from \"atom.io/internal\"\nimport type { ReadonlySelectorToken, StateToken } from \".\"\n\nexport const getState = <T>(\n\ttoken: ReadonlySelectorToken<T> | StateToken<T>,\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): T => {\n\tconst state =\n\t\tInternal.withdraw(token, store) ??\n\t\tInternal.withdrawNewFamilyMember(token, store)\n\tif (state === undefined) {\n\t\tthrow new NotFoundError(token, store)\n\t}\n\treturn Internal.getState__INTERNAL(state, store)\n}\n\nexport const setState = <T, New extends T>(\n\ttoken: StateToken<T>,\n\tvalue: New | ((oldValue: T) => New),\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): void => {\n\tconst rejection = Internal.openOperation(token, store)\n\tif (rejection) {\n\t\treturn\n\t}\n\tconst state =\n\t\tInternal.withdraw(token, store) ??\n\t\tInternal.withdrawNewFamilyMember(token, store)\n\tif (state === undefined) {\n\t\tthrow new NotFoundError(token, store)\n\t}\n\tInternal.setState__INTERNAL(state, value, store)\n\tInternal.closeOperation(store)\n}\n\nconst capitalize = (str: string) => str[0].toUpperCase() + str.slice(1)\nexport class NotFoundError extends Error {\n\tpublic constructor(\n\t\ttoken: ReadonlySelectorToken<any> | StateToken<any>,\n\t\tstore: Internal.Store,\n\t) {\n\t\tsuper(\n\t\t\t`${capitalize(token.type)} \"${token.key}\" not found in store \"${\n\t\t\t\tstore.config.name\n\t\t\t}\".`,\n\t\t)\n\t}\n}\n","import { IMPLICIT } from \"atom.io/internal\"\nimport type { Store } from \"atom.io/internal\"\n\nexport const NO_OP = (): void => undefined\n\nexport type Logger = Pick<Console, `error` | `info` | `warn`>\nexport const LOG_LEVELS: ReadonlyArray<keyof Logger> = [\n\t`info`,\n\t`warn`,\n\t`error`,\n] as const\n\nexport const setLogLevel = (\n\tpreferredLevel: `error` | `info` | `warn` | null,\n\tstore: Store = IMPLICIT.STORE,\n): void => {\n\tconst { logger__INTERNAL } = store.config\n\tif (preferredLevel === null) {\n\t\tstore.config.logger = null\n\t} else {\n\t\tstore.config.logger = { ...console }\n\t\tLOG_LEVELS.forEach((logLevel) => {\n\t\t\tif (LOG_LEVELS.indexOf(logLevel) < LOG_LEVELS.indexOf(preferredLevel)) {\n\t\t\t\t// biome-ignore lint/style/noNonNullAssertion: we just set it\n\t\t\t\tstore.config.logger![logLevel] = NO_OP\n\t\t\t} else {\n\t\t\t\t// biome-ignore lint/style/noNonNullAssertion: we just set it\n\t\t\t\tstore.config.logger![logLevel] = logger__INTERNAL[logLevel]\n\t\t\t}\n\t\t})\n\t}\n}\n\nexport const useLogger = (\n\tlogger: Logger,\n\tstore: Store = IMPLICIT.STORE,\n): void => {\n\tconst currentLogLevel =\n\t\tstore.config.logger === null\n\t\t\t? null\n\t\t\t: LOG_LEVELS.find(\n\t\t\t\t\t(logLevel) => store.config.logger?.[logLevel] !== NO_OP,\n\t\t\t ) ?? null\n\tstore.config.logger__INTERNAL = { ...logger }\n\tsetLogLevel(currentLogLevel, store)\n}\n","import type { Subject } from \"atom.io/internal\"\nimport { createSelector, createSelectorFamily } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { ReadonlySelectorToken, SelectorToken } from \".\"\nimport type { Read, Write } from \"./transaction\"\n\nexport type SelectorOptions<T> = {\n\tkey: string\n\tget: Read<() => T>\n\tset: Write<(newValue: T) => void>\n}\nexport type ReadonlySelectorOptions<T> = {\n\tkey: string\n\tget: Read<() => T>\n}\n\nexport function selector<T>(options: SelectorOptions<T>): SelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T>,\n): ReadonlySelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T> | SelectorOptions<T>,\n): ReadonlySelectorToken<T> | SelectorToken<T> {\n\treturn createSelector(options)\n}\n\nexport type SelectorFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tget: (key: K) => Read<() => T>\n\tset: (key: K) => Write<(newValue: T) => void>\n}\nexport type ReadonlySelectorFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tget: (key: K) => Read<() => T>\n}\n\nexport type SelectorFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => SelectorToken<T>) & {\n\tkey: string\n\ttype: `selector_family`\n\tsubject: Subject<SelectorToken<T>>\n}\n\nexport type ReadonlySelectorFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => ReadonlySelectorToken<T>) & {\n\tkey: string\n\ttype: `readonly_selector_family`\n\tsubject: Subject<ReadonlySelectorToken<T>>\n}\n\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: SelectorFamilyOptions<T, K>,\n): SelectorFamily<T, K>\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: ReadonlySelectorFamilyOptions<T, K>,\n): ReadonlySelectorFamily<T, K>\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: ReadonlySelectorFamilyOptions<T, K> | SelectorFamilyOptions<T, K>,\n): ReadonlySelectorFamily<T, K> | SelectorFamily<T, K> {\n\treturn createSelectorFamily(options)\n}\n","import {\n\tStore,\n\tcreateAtom,\n\tcreateAtomFamily,\n\tcreateMutableAtom,\n\tcreateMutableAtomFamily,\n\tcreateSelector,\n\tcreateSelectorFamily,\n\tredo__INTERNAL,\n\ttimeline__INTERNAL,\n\ttransaction__INTERNAL,\n\tundo__INTERNAL,\n} from \"atom.io/internal\"\n\nimport type { redo, timeline, undo } from \".\"\nimport { getState, setState, subscribe } from \".\"\nimport type { atom, atomFamily } from \"./atom\"\nimport type { selector, selectorFamily } from \"./selector\"\nimport type { transaction } from \"./transaction\"\n\nexport class Silo {\n\tpublic store: Store\n\tpublic atom: typeof atom\n\tpublic atomFamily: typeof atomFamily\n\tpublic selector: typeof selector\n\tpublic selectorFamily: typeof selectorFamily\n\tpublic transaction: typeof transaction\n\tpublic timeline: typeof timeline\n\tpublic getState: typeof getState\n\tpublic setState: typeof setState\n\tpublic subscribe: typeof subscribe\n\tpublic undo: typeof undo\n\tpublic redo: typeof redo\n\tpublic constructor(name: string, fromStore: Store | null = null) {\n\t\tconst s = new Store(name, fromStore)\n\t\tthis.store = s\n\t\tthis.atom = (options) => {\n\t\t\tif (`mutable` in options) {\n\t\t\t\treturn createMutableAtom(options, s)\n\t\t\t}\n\t\t\treturn createAtom(options, undefined, s)\n\t\t}\n\t\tthis.atomFamily = (options) => {\n\t\t\tif (`mutable` in options) {\n\t\t\t\treturn createMutableAtomFamily(options, s) as any\n\t\t\t}\n\t\t\treturn createAtomFamily(options, s)\n\t\t}\n\t\tthis.selector = (options) => createSelector(options, undefined, s) as any\n\t\tthis.selectorFamily = (options) => createSelectorFamily(options, s) as any\n\t\tthis.transaction = (options) => transaction__INTERNAL(options, s)\n\t\tthis.timeline = (options) => timeline__INTERNAL(options, s)\n\t\tthis.getState = (token) => getState(token, s)\n\t\tthis.setState = (token, newValue) => setState(token, newValue, s)\n\t\tthis.subscribe = (token, handler, key) => subscribe(token, handler, key, s)\n\t\tthis.undo = (token) => undo__INTERNAL(token, s)\n\t\tthis.redo = (token) => redo__INTERNAL(token, s)\n\t}\n}\n","import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT, subscribeToRootAtoms, withdraw } from \"atom.io/internal\"\n\nimport type {\n\tFamilyMetadata,\n\tReadonlySelectorToken,\n\tStateToken,\n\tTimelineToken,\n\tTimelineUpdate,\n\tTransactionToken,\n\tTransactionUpdate,\n\tƒn,\n} from \".\"\n\nexport type StateUpdate<T> = { newValue: T; oldValue: T }\nexport type KeyedStateUpdate<T> = StateUpdate<T> & {\n\tkey: string\n\tfamily?: FamilyMetadata\n}\nexport type UpdateHandler<T> = (update: StateUpdate<T>) => void\n\nexport function subscribe<T>(\n\ttoken: ReadonlySelectorToken<T> | StateToken<T>,\n\thandleUpdate: UpdateHandler<T>,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore: Store = IMPLICIT.STORE,\n): () => void {\n\tconst state = withdraw<T>(token, store)\n\tif (state === undefined) {\n\t\tthrow new Error(\n\t\t\t`State \"${token.key}\" not found in this store. Did you forget to initialize with the \"atom\" or \"selector\" function?`,\n\t\t)\n\t}\n\tconst unsubFunction = state.subject.subscribe(key, handleUpdate)\n\tstore.config.logger?.info(`👀 adding subscription \"${key}\" to \"${state.key}\"`)\n\tconst dependencyUnsubFunctions =\n\t\tstate.type !== `atom` ? subscribeToRootAtoms(state, store) : null\n\n\tconst unsubscribe =\n\t\tdependencyUnsubFunctions === null\n\t\t\t? () => {\n\t\t\t\t\tstore.config.logger?.info(`🙈 unsubscribe from \"${state.key}\"`)\n\t\t\t\t\tunsubFunction()\n\t\t\t }\n\t\t\t: () => {\n\t\t\t\t\tstore.config.logger?.info(\n\t\t\t\t\t\t`🙈 unsubscribe from \"${state.key}\" and its dependencies`,\n\t\t\t\t\t)\n\t\t\t\t\tunsubFunction()\n\t\t\t\t\tfor (const unsubFromDependency of dependencyUnsubFunctions) {\n\t\t\t\t\t\tunsubFromDependency()\n\t\t\t\t\t}\n\t\t\t }\n\n\treturn unsubscribe\n}\n\nexport type TransactionUpdateHandler<ƒ extends ƒn> = (\n\tdata: TransactionUpdate<ƒ>,\n) => void\n\nexport const subscribeToTransaction = <ƒ extends ƒn>(\n\ttoken: TransactionToken<ƒ>,\n\thandleUpdate: TransactionUpdateHandler<ƒ>,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore = IMPLICIT.STORE,\n): (() => void) => {\n\tconst tx = withdraw(token, store)\n\tif (tx === undefined) {\n\t\tthrow new Error(\n\t\t\t`Cannot subscribe to transaction \"${token.key}\": transaction not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n\tstore.config.logger?.info(`👀 subscribe to transaction \"${token.key}\"`)\n\tconst unsubscribe = tx.subject.subscribe(key, handleUpdate)\n\treturn () => {\n\t\tstore.config.logger?.info(`🙈 unsubscribe from transaction \"${token.key}\"`)\n\t\tunsubscribe()\n\t}\n}\n\nexport const subscribeToTimeline = (\n\ttoken: TimelineToken,\n\thandleUpdate: (update: TimelineUpdate | `redo` | `undo`) => void,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore = IMPLICIT.STORE,\n): (() => void) => {\n\tconst tl = withdraw(token, store)\n\tif (tl === undefined) {\n\t\tthrow new Error(\n\t\t\t`Cannot subscribe to timeline \"${token.key}\": timeline not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n\tstore.config.logger?.info(`👀 subscribe to timeline \"${token.key}\"`)\n\tconst unsubscribe = tl.subject.subscribe(key, handleUpdate)\n\treturn () => {\n\t\tstore.config.logger?.info(`🙈 unsubscribe from timeline \"${token.key}\"`)\n\t\tunsubscribe()\n\t}\n}\n","import type {\n\tTimelineAtomUpdate,\n\tTimelineSelectorUpdate,\n\tTimelineTransactionUpdate,\n} from \"atom.io/internal\"\nimport {\n\tIMPLICIT,\n\tredo__INTERNAL,\n\ttimeline__INTERNAL,\n\tundo__INTERNAL,\n} from \"atom.io/internal\"\n\nimport type { AtomFamily, AtomToken } from \".\"\n\nexport type TimelineToken = {\n\tkey: string\n\ttype: `timeline`\n}\n\nexport type TimelineOptions = {\n\tkey: string\n\tatoms: (AtomFamily<any, any> | AtomToken<any>)[]\n}\n\nexport type TimelineUpdate =\n\t| TimelineAtomUpdate\n\t| TimelineSelectorUpdate\n\t| TimelineTransactionUpdate\n\nexport const timeline = (options: TimelineOptions): TimelineToken => {\n\treturn timeline__INTERNAL(options)\n}\n\nexport const redo = (token: TimelineToken): void => {\n\tredo__INTERNAL(token, IMPLICIT.STORE)\n}\n\nexport const undo = (token: TimelineToken): void => {\n\tundo__INTERNAL(token, IMPLICIT.STORE)\n}\n","import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT, transaction__INTERNAL, withdraw } from \"atom.io/internal\"\n\nimport type { KeyedStateUpdate, ReadonlySelectorToken, StateToken, ƒn } from \".\"\n\nexport type TransactionToken<_> = {\n\tkey: string\n\ttype: `transaction`\n\t__brand?: _\n}\n\nexport type TransactionUpdate<ƒ extends ƒn> = {\n\tkey: string\n\tatomUpdates: KeyedStateUpdate<unknown>[]\n\tparams: Parameters<ƒ>\n\toutput: ReturnType<ƒ>\n}\n\nexport type Transactors = {\n\tget: <S>(state: ReadonlySelectorToken<S> | StateToken<S>) => S\n\tset: <S>(state: StateToken<S>, newValue: S | ((oldValue: S) => S)) => void\n}\nexport type ReadonlyTransactors = Pick<Transactors, `get`>\n\nexport type Read<ƒ extends ƒn> = (\n\ttransactors: ReadonlyTransactors,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type Write<ƒ extends ƒn> = (\n\ttransactors: Transactors,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type TransactionOptions<ƒ extends ƒn> = {\n\tkey: string\n\tdo: Write<ƒ>\n}\n\nexport type TransactionIO<Token extends TransactionToken<any>> =\n\tToken extends TransactionToken<infer ƒ> ? ƒ : never\n\nexport function transaction<ƒ extends ƒn>(\n\toptions: TransactionOptions<ƒ>,\n): TransactionToken<ƒ> {\n\treturn transaction__INTERNAL(options)\n}\n\nexport const runTransaction =\n\t<ƒ extends ƒn>(token: TransactionToken<ƒ>, store: Store = IMPLICIT.STORE) =>\n\t(...parameters: Parameters<ƒ>): ReturnType<ƒ> => {\n\t\tconst tx = withdraw(token, store)\n\t\tif (tx) {\n\t\t\treturn tx.run(...parameters)\n\t\t}\n\t\tthrow new Error(\n\t\t\t`Cannot run transaction \"${token.key}\": transaction not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n"]}
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import * as IO from 'atom.io/internal';
1
+ import * as Internal from 'atom.io/internal';
2
2
  import { createMutableAtom, createAtom, createMutableAtomFamily, createAtomFamily, IMPLICIT, createSelector, createSelectorFamily, Store, transaction__INTERNAL, timeline__INTERNAL, undo__INTERNAL, redo__INTERNAL, withdraw, subscribeToRootAtoms } from 'atom.io/internal';
3
3
 
4
4
  var __defProp = Object.defineProperty;
@@ -29,6 +29,35 @@ function atomFamily(options) {
29
29
  }
30
30
  return createAtomFamily(options);
31
31
  }
32
+ var getState = (token, store = Internal.IMPLICIT.STORE) => {
33
+ var _a;
34
+ const state = (_a = Internal.withdraw(token, store)) != null ? _a : Internal.withdrawNewFamilyMember(token, store);
35
+ if (state === void 0) {
36
+ throw new NotFoundError(token, store);
37
+ }
38
+ return Internal.getState__INTERNAL(state, store);
39
+ };
40
+ var setState = (token, value, store = Internal.IMPLICIT.STORE) => {
41
+ var _a;
42
+ const rejection = Internal.openOperation(token, store);
43
+ if (rejection) {
44
+ return;
45
+ }
46
+ const state = (_a = Internal.withdraw(token, store)) != null ? _a : Internal.withdrawNewFamilyMember(token, store);
47
+ if (state === void 0) {
48
+ throw new NotFoundError(token, store);
49
+ }
50
+ Internal.setState__INTERNAL(state, value, store);
51
+ Internal.closeOperation(store);
52
+ };
53
+ var capitalize = (str) => str[0].toUpperCase() + str.slice(1);
54
+ var NotFoundError = class extends Error {
55
+ constructor(token, store) {
56
+ super(
57
+ `${capitalize(token.type)} "${token.key}" not found in store "${store.config.name}".`
58
+ );
59
+ }
60
+ };
32
61
  var NO_OP = () => void 0;
33
62
  var LOG_LEVELS = [
34
63
  `info`,
@@ -97,7 +126,7 @@ var Silo = class {
97
126
  function subscribe(token, handleUpdate, key = Math.random().toString(36).slice(2), store = IMPLICIT.STORE) {
98
127
  var _a;
99
128
  const state = withdraw(token, store);
100
- if (state === null) {
129
+ if (state === void 0) {
101
130
  throw new Error(
102
131
  `State "${token.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`
103
132
  );
@@ -124,7 +153,7 @@ function subscribe(token, handleUpdate, key = Math.random().toString(36).slice(2
124
153
  var subscribeToTransaction = (token, handleUpdate, key = Math.random().toString(36).slice(2), store = IMPLICIT.STORE) => {
125
154
  var _a;
126
155
  const tx = withdraw(token, store);
127
- if (tx === null) {
156
+ if (tx === void 0) {
128
157
  throw new Error(
129
158
  `Cannot subscribe to transaction "${token.key}": transaction not found in store "${store.config.name}".`
130
159
  );
@@ -140,7 +169,7 @@ var subscribeToTransaction = (token, handleUpdate, key = Math.random().toString(
140
169
  var subscribeToTimeline = (token, handleUpdate, key = Math.random().toString(36).slice(2), store = IMPLICIT.STORE) => {
141
170
  var _a;
142
171
  const tl = withdraw(token, store);
143
- if (tl === null) {
172
+ if (tl === void 0) {
144
173
  throw new Error(
145
174
  `Cannot subscribe to timeline "${token.key}": timeline not found in store "${store.config.name}".`
146
175
  );
@@ -175,39 +204,6 @@ var runTransaction = (token, store = IMPLICIT.STORE) => (...parameters) => {
175
204
  );
176
205
  };
177
206
 
178
- // src/index.ts
179
- var capitalize = (str) => str[0].toUpperCase() + str.slice(1);
180
- var getState = (token, store = IO.IMPLICIT.STORE) => {
181
- var _a;
182
- const state = (_a = IO.withdraw(token, store)) != null ? _a : IO.withdrawNewFamilyMember(token, store);
183
- if (state === null) {
184
- throw new Error(
185
- `${capitalize(token.type)} "${token.key}" not found in store "${store.config.name}".`
186
- );
187
- }
188
- return IO.getState__INTERNAL(state, store);
189
- };
190
- var setState = (token, value, store = IO.IMPLICIT.STORE) => {
191
- var _a;
192
- try {
193
- IO.openOperation(token, store);
194
- } catch (thrown) {
195
- if (!(typeof thrown === `symbol`)) {
196
- throw thrown;
197
- }
198
- return;
199
- }
200
- const state = (_a = IO.withdraw(token, store)) != null ? _a : IO.withdrawNewFamilyMember(token, store);
201
- if (state === null) {
202
- throw new Error(
203
- `${capitalize(token.type)} "${token.key}" not found in store "${store.config.name}".`
204
- );
205
- }
206
- IO.setState__INTERNAL(state, value, store);
207
- IO.closeOperation(store);
208
- };
209
- var isDefault = (token, store = IO.IMPLICIT.STORE) => token.type === `atom` ? IO.isAtomDefault(token.key, store) : IO.isSelectorDefault(token.key, store);
210
-
211
- export { LOG_LEVELS, NO_OP, Silo, atom, atomFamily, capitalize, getState, isDefault, redo, runTransaction, selector, selectorFamily, setLogLevel, setState, subscribe, subscribeToTimeline, subscribeToTransaction, timeline, transaction, undo, useLogger };
207
+ export { LOG_LEVELS, NO_OP, NotFoundError, Silo, atom, atomFamily, getState, redo, runTransaction, selector, selectorFamily, setLogLevel, setState, subscribe, subscribeToTimeline, subscribeToTransaction, timeline, transaction, undo, useLogger };
212
208
  //# sourceMappingURL=out.js.map
213
209
  //# sourceMappingURL=index.mjs.map