@exodus/atoms 8.0.0 → 8.1.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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,22 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [8.1.1](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/atoms@8.1.0...@exodus/atoms@8.1.1) (2024-09-09)
7
+
8
+ ### Bug Fixes
9
+
10
+ - **atoms:** actively clear cache upon reset ([#8709](https://github.com/ExodusMovement/exodus-hydra/issues/8709)) ([d159c00](https://github.com/ExodusMovement/exodus-hydra/commit/d159c0020519379a4b477a52b82494b6f93c704e))
11
+
12
+ ## [8.1.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/atoms@8.0.0...@exodus/atoms@8.1.0) (2024-08-10)
13
+
14
+ ### Features
15
+
16
+ - **atoms:** warn when using cache enhancer on atom with no setter ([#8147](https://github.com/ExodusMovement/exodus-hydra/issues/8147)) ([1511a55](https://github.com/ExodusMovement/exodus-hydra/commit/1511a5528cce33d82795b4eb06385de370e7a847))
17
+
18
+ ### Bug Fixes
19
+
20
+ - **atoms:** invalidate cache on failed writes, adjust user id analytics atom API ([#8303](https://github.com/ExodusMovement/exodus-hydra/issues/8303)) ([17537a8](https://github.com/ExodusMovement/exodus-hydra/commit/17537a8b18aff90d5e7e1b12dd7964032af7b44b))
21
+
6
22
  ## [8.0.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/atoms@7.6.1...@exodus/atoms@8.0.0) (2024-07-17)
7
23
 
8
24
  ### ⚠ BREAKING CHANGES
package/README.md CHANGED
@@ -13,6 +13,7 @@ An atom is a data source wrapper that exposes a single piece of data through 3 d
13
13
  - **get()**: read data
14
14
  - **set(newValue)**: write data
15
15
  - **observe(async (data) => {})**: observes data changes. Will be called initially with current data value. Observers are awaited in series.
16
+ - **reset()**: clear the stored value. The next `get()` call will return the default value\* and observers will be called with the default value.
16
17
 
17
18
  ## Data sources
18
19
 
@@ -1,9 +1,9 @@
1
- import { Atom, Listener } from '../utils/types.js';
1
+ import { Atom } from '../utils/types.js';
2
2
  type Diff<T> = {
3
3
  previous?: T;
4
4
  current: T;
5
5
  };
6
6
  declare const difference: <T>(atom: Atom<T>) => Omit<Atom<T>, "observe"> & {
7
- observe: (listener: Listener<Diff<T>>) => import("../utils/types.js").Unsubscribe;
7
+ observe: Atom<Diff<T>>["observe"];
8
8
  };
9
9
  export default difference;
@@ -6,6 +6,9 @@ const getCacheAtom = ({ storage, key }) => {
6
6
  const enhanceAtom = (params) => {
7
7
  const { atom, logger } = params;
8
8
  const cacheAtom = getCacheAtom(params);
9
+ if (!atom.hasOwnProperty('set')) {
10
+ logger.warn('Atom does not have a "set" method, cache will last only until the app is restarted');
11
+ }
9
12
  let hasCache = false;
10
13
  const setCache = async (fresh) => {
11
14
  try {
@@ -31,15 +34,30 @@ const enhanceAtom = (params) => {
31
34
  return fresh;
32
35
  };
33
36
  const set = async (value) => {
34
- await atom.set(value);
35
- hasCache = false;
37
+ try {
38
+ await atom.set(value);
39
+ }
40
+ catch (error) {
41
+ logger.warn('Failed to write to atom, is it a readonly atom? Clearing cache...', error);
42
+ }
43
+ finally {
44
+ hasCache = false;
45
+ }
36
46
  };
37
47
  const get = async () => {
38
48
  return hasCache ? readCache() : readFresh();
39
49
  };
40
50
  const reset = async () => {
41
- await atom.reset();
42
- hasCache = false;
51
+ try {
52
+ await atom.reset();
53
+ await cacheAtom.reset();
54
+ }
55
+ catch (error) {
56
+ logger.warn('Failed to write to atom, is it a readonly atom? Clearing cache...', error);
57
+ }
58
+ finally {
59
+ hasCache = false;
60
+ }
43
61
  };
44
62
  return { ...atom, get, set, reset };
45
63
  };
@@ -9,7 +9,7 @@ type Params<D> = {
9
9
  isSoleWriter?: boolean;
10
10
  };
11
11
  declare const createStorageAtomFactory: <T>({ storage }: FactoryParams<T>) => {
12
- (opts: Omit<Params<unknown>, 'defaultValue'>): Atom<T | undefined>;
12
+ (opts: Omit<Params<unknown>, "defaultValue">): Atom<T | undefined>;
13
13
  <D extends T>(opts: Params<D>): Atom<T | D>;
14
14
  };
15
15
  export default createStorageAtomFactory;
package/lib/index.d.ts CHANGED
@@ -22,4 +22,4 @@ export { default as withStorageCache } from './enhancers/with-storage-cache.js';
22
22
  export { default as waitUntil } from './effects/wait-until.js';
23
23
  export { default as enforceObservableRules } from './enforce-rules.js';
24
24
  export { default as fromEventEmitter } from './event-emitter.js';
25
- export { Atom, ReadonlyAtom, Listener, Unsubscribe } from './utils/types.js';
25
+ export type { Atom, ReadonlyAtom, Listener, Unsubscribe } from './utils/types.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/atoms",
3
- "version": "8.0.0",
3
+ "version": "8.1.1",
4
4
  "description": "Abstraction for encapsulating a piece of data behind a simple unified interface: get, set, observe",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -9,8 +9,8 @@
9
9
  "scripts": {
10
10
  "build": "run -T tsc --build tsconfig.build.json",
11
11
  "clean": "run -T tsc --build --clean",
12
- "test": "run -T jest",
13
- "lint": "run -T eslint . --ignore-path ../../.gitignore",
12
+ "test": "run -T exodus-test --jest --esbuild",
13
+ "lint": "run -T eslint .",
14
14
  "lint:fix": "yarn lint --fix",
15
15
  "prepublishOnly": "yarn run -T build --scope @exodus/atoms"
16
16
  },
@@ -28,7 +28,6 @@
28
28
  "url": "https://github.com/ExodusMovement/exodus-hydra/issues?q=is%3Aissue+is%3Aopen+label%3Aatoms"
29
29
  },
30
30
  "dependencies": {
31
- "@exodus/basic-utils": "^2.5.2",
32
31
  "@exodus/storage-interface": "^1.0.0",
33
32
  "delay": "^5.0.0",
34
33
  "eventemitter3": "^4.0.7",
@@ -41,12 +40,12 @@
41
40
  },
42
41
  "devDependencies": {
43
42
  "@exodus/atom-tests": "^1.0.0",
44
- "@exodus/storage-memory": "^2.1.1",
43
+ "@exodus/storage-memory": "^2.2.0",
45
44
  "@types/jest": "^29.5.11",
46
45
  "@types/json-stringify-safe": "^5.0.3",
47
46
  "@types/lodash": "^4.14.200",
48
47
  "@types/minimalistic-assert": "^1.0.2",
49
48
  "events": "^3.3.0"
50
49
  },
51
- "gitHead": "9c572ff7b092c5806e9de99a462775086689742c"
50
+ "gitHead": "d64de7579b06afe91fbded3d1f7eb29950f82e5a"
52
51
  }