@exodus/atoms 8.1.0 → 9.0.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.
- package/CHANGELOG.md +25 -0
- package/lib/effects/wait-until.d.ts +1 -1
- package/lib/enforce-rules.d.ts +3 -3
- package/lib/enforce-rules.js +14 -5
- package/lib/enhancers/block-until.d.ts +1 -1
- package/lib/enhancers/combine.d.ts +1 -1
- package/lib/enhancers/compute.d.ts +1 -1
- package/lib/enhancers/dedupe.d.ts +1 -1
- package/lib/enhancers/difference.d.ts +1 -1
- package/lib/enhancers/filter.d.ts +1 -1
- package/lib/enhancers/merge-with-value.d.ts +1 -1
- package/lib/enhancers/optimistic-notifier.d.ts +1 -1
- package/lib/enhancers/read-only.d.ts +1 -1
- package/lib/enhancers/swallow-observer-errors.d.ts +1 -1
- package/lib/enhancers/timeout-observers.d.ts +1 -1
- package/lib/enhancers/warn-on-same-value-set.d.ts +1 -1
- package/lib/enhancers/with-serialization.d.ts +1 -1
- package/lib/enhancers/with-storage-cache.d.ts +2 -2
- package/lib/enhancers/with-storage-cache.js +2 -1
- package/lib/event-emitter.d.ts +1 -1
- package/lib/factories/keystore.d.ts +1 -1
- package/lib/factories/memory.d.ts +1 -1
- package/lib/factories/observer.d.ts +1 -1
- package/lib/factories/sequenced-keystore.d.ts +1 -1
- package/lib/factories/storage.d.ts +2 -3
- package/lib/factories/storage.js +26 -26
- package/lib/index.d.ts +1 -1
- package/lib/simple-observer.d.ts +1 -1
- package/lib/utils/guards.d.ts +1 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,31 @@
|
|
|
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
|
+
## [9.0.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/atoms@8.1.1...@exodus/atoms@9.0.0) (2024-09-26)
|
|
7
|
+
|
|
8
|
+
### ⚠ BREAKING CHANGES
|
|
9
|
+
|
|
10
|
+
- remove isSoleWriter from storage atom factory (#9423)
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
- don't allow get to proceed after unsubscribe ([#9441](https://github.com/ExodusMovement/exodus-hydra/issues/9441)) ([33bc642](https://github.com/ExodusMovement/exodus-hydra/commit/33bc642ad6ec32e1f31711f9dfe435d235eaca56))
|
|
15
|
+
- remove isSoleWriter from storage atom factory ([#9423](https://github.com/ExodusMovement/exodus-hydra/issues/9423)) ([ab90ee1](https://github.com/ExodusMovement/exodus-hydra/commit/ab90ee13a819058c0f23c37008da2bebf4439157))
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
- storage atom race condition ([#9403](https://github.com/ExodusMovement/exodus-hydra/issues/9403)) ([bf30d0c](https://github.com/ExodusMovement/exodus-hydra/commit/bf30d0cc90632459b6b0b9fd76fac191d20ddd0b))
|
|
20
|
+
|
|
21
|
+
### Performance Improvements
|
|
22
|
+
|
|
23
|
+
- reduce underlying storage reads ([#9418](https://github.com/ExodusMovement/exodus-hydra/issues/9418)) ([f3c0c23](https://github.com/ExodusMovement/exodus-hydra/commit/f3c0c232b120977a27565636f4d1a6ca9fc90b4a))
|
|
24
|
+
|
|
25
|
+
## [8.1.1](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/atoms@8.1.0...@exodus/atoms@8.1.1) (2024-09-09)
|
|
26
|
+
|
|
27
|
+
### Bug Fixes
|
|
28
|
+
|
|
29
|
+
- **atoms:** actively clear cache upon reset ([#8709](https://github.com/ExodusMovement/exodus-hydra/issues/8709)) ([d159c00](https://github.com/ExodusMovement/exodus-hydra/commit/d159c0020519379a4b477a52b82494b6f93c704e))
|
|
30
|
+
|
|
6
31
|
## [8.1.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/atoms@8.0.0...@exodus/atoms@8.1.0) (2024-08-10)
|
|
7
32
|
|
|
8
33
|
### Features
|
package/lib/enforce-rules.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Atom } from './utils/types.js';
|
|
1
|
+
import type { Atom } from './utils/types.js';
|
|
2
2
|
type Params<T> = {
|
|
3
|
-
|
|
3
|
+
makeGetNonConcurrent?: boolean;
|
|
4
4
|
getInitialized?: () => boolean;
|
|
5
5
|
defaultValue?: T;
|
|
6
6
|
set: (value: T) => Promise<void>;
|
|
7
7
|
} & Omit<Atom<T>, 'set' | 'reset'>;
|
|
8
|
-
declare const enforceObservableRules: <T>({ defaultValue,
|
|
8
|
+
declare const enforceObservableRules: <T>({ defaultValue, makeGetNonConcurrent, getInitialized, ...atom }: Params<T>) => Atom<T>;
|
|
9
9
|
export default enforceObservableRules;
|
package/lib/enforce-rules.js
CHANGED
|
@@ -14,26 +14,31 @@ const withChangeDetection = (listener) => {
|
|
|
14
14
|
await listener(currentValue);
|
|
15
15
|
};
|
|
16
16
|
};
|
|
17
|
-
const enforceObservableRules = ({ defaultValue,
|
|
17
|
+
const enforceObservableRules = ({ defaultValue, makeGetNonConcurrent = false, getInitialized = () => true, ...atom }) => {
|
|
18
18
|
const enqueue = makeConcurrent((fn) => fn(), { concurrency: 1 });
|
|
19
19
|
const postProcessValue = (value = defaultValue) => value && typeof value === 'object' ? freeze(value) : value;
|
|
20
|
-
const
|
|
21
|
-
|
|
20
|
+
const nonConcurrentGet = makeGetNonConcurrent
|
|
21
|
+
? makeConcurrent(atom.get)
|
|
22
|
+
: atom.get;
|
|
23
|
+
const get = () => nonConcurrentGet().then(postProcessValue);
|
|
22
24
|
const observe = (listener) => {
|
|
23
25
|
let called = false;
|
|
24
26
|
let valueEmittedFromGet;
|
|
27
|
+
let subscribed = true;
|
|
25
28
|
listener = withChangeDetection(listener);
|
|
26
29
|
const publishSerially = (value) => {
|
|
27
30
|
called = true;
|
|
28
31
|
return enqueue(() => listener(value));
|
|
29
32
|
};
|
|
30
|
-
|
|
33
|
+
nonConcurrentGet().then((value) => {
|
|
34
|
+
if (!subscribed)
|
|
35
|
+
return;
|
|
31
36
|
if (!called) {
|
|
32
37
|
valueEmittedFromGet = value;
|
|
33
38
|
publishSerially(postProcessValue(value));
|
|
34
39
|
}
|
|
35
40
|
});
|
|
36
|
-
|
|
41
|
+
const unsubscribe = atom.observe((value) => {
|
|
37
42
|
if (valueEmittedFromGet !== undefined) {
|
|
38
43
|
const isAlreadyEmitted = value === valueEmittedFromGet;
|
|
39
44
|
valueEmittedFromGet = undefined;
|
|
@@ -43,6 +48,10 @@ const enforceObservableRules = ({ defaultValue, makeGetConcurrent = false, getIn
|
|
|
43
48
|
}
|
|
44
49
|
return publishSerially(postProcessValue(value));
|
|
45
50
|
});
|
|
51
|
+
return () => {
|
|
52
|
+
unsubscribe();
|
|
53
|
+
subscribed = false;
|
|
54
|
+
};
|
|
46
55
|
};
|
|
47
56
|
const set = makeConcurrent(async (value) => {
|
|
48
57
|
if (isSetter(value)) {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Atom } from '../utils/types.js';
|
|
1
|
+
import type { Atom } from '../utils/types.js';
|
|
2
2
|
export default function filter<T>(atom: Atom<T>, predicate: (value: T) => boolean): Atom<T>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import createStorageAtomFactory from '../factories/storage.js';
|
|
2
2
|
const getCacheAtom = ({ storage, key }) => {
|
|
3
3
|
const createStorageAtom = createStorageAtomFactory({ storage });
|
|
4
|
-
return createStorageAtom({ key
|
|
4
|
+
return createStorageAtom({ key });
|
|
5
5
|
};
|
|
6
6
|
const enhanceAtom = (params) => {
|
|
7
7
|
const { atom, logger } = params;
|
|
@@ -50,6 +50,7 @@ const enhanceAtom = (params) => {
|
|
|
50
50
|
const reset = async () => {
|
|
51
51
|
try {
|
|
52
52
|
await atom.reset();
|
|
53
|
+
await cacheAtom.reset();
|
|
53
54
|
}
|
|
54
55
|
catch (error) {
|
|
55
56
|
logger.warn('Failed to write to atom, is it a readonly atom? Clearing cache...', error);
|
package/lib/event-emitter.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { Atom } from '../utils/types.js';
|
|
2
|
-
import { Storage } from '@exodus/storage-interface';
|
|
1
|
+
import type { Atom } from '../utils/types.js';
|
|
2
|
+
import type { Storage } from '@exodus/storage-interface';
|
|
3
3
|
type FactoryParams<T> = {
|
|
4
4
|
storage: Storage<T>;
|
|
5
5
|
};
|
|
6
6
|
type Params<D> = {
|
|
7
7
|
key: string;
|
|
8
8
|
defaultValue?: D;
|
|
9
|
-
isSoleWriter?: boolean;
|
|
10
9
|
};
|
|
11
10
|
declare const createStorageAtomFactory: <T>({ storage }: FactoryParams<T>) => {
|
|
12
11
|
(opts: Omit<Params<unknown>, "defaultValue">): Atom<T | undefined>;
|
package/lib/factories/storage.js
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
1
|
import createSimpleObserver from '../simple-observer.js';
|
|
2
2
|
import enforceObservableRules from '../enforce-rules.js';
|
|
3
|
-
import pDefer from 'p-defer';
|
|
4
3
|
const createStorageAtomFactory = ({ storage }) => {
|
|
5
|
-
function createStorageAtom({ key, defaultValue
|
|
6
|
-
|
|
4
|
+
function createStorageAtom({ key, defaultValue }) {
|
|
5
|
+
let version = 0;
|
|
6
|
+
const { notify, observe } = createSimpleObserver({ enable: true });
|
|
7
7
|
let canUseCached = false;
|
|
8
8
|
let cached;
|
|
9
|
-
let
|
|
9
|
+
let pendingWrite;
|
|
10
10
|
const set = async (value) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
version++;
|
|
12
|
+
pendingWrite = (async () => {
|
|
13
|
+
if (value === undefined) {
|
|
14
|
+
await storage.delete(key);
|
|
15
|
+
canUseCached = false;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
await storage.set(key, value);
|
|
19
|
+
canUseCached = true;
|
|
20
|
+
}
|
|
21
21
|
cached = value;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
pendingWrite = undefined;
|
|
23
|
+
})();
|
|
24
|
+
await pendingWrite;
|
|
25
|
+
await notify(value);
|
|
25
26
|
};
|
|
26
27
|
const get = async () => {
|
|
27
|
-
if (
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
if (writePromiseDefer) {
|
|
31
|
-
await writePromiseDefer.promise;
|
|
28
|
+
if (pendingWrite) {
|
|
29
|
+
await pendingWrite;
|
|
32
30
|
}
|
|
33
31
|
if (canUseCached) {
|
|
34
32
|
return cached;
|
|
35
33
|
}
|
|
34
|
+
const currentVersion = version;
|
|
36
35
|
const value = await storage.get(key);
|
|
37
|
-
if (
|
|
38
|
-
|
|
39
|
-
canUseCached = true;
|
|
36
|
+
if (currentVersion !== version) {
|
|
37
|
+
return get();
|
|
40
38
|
}
|
|
39
|
+
cached = value;
|
|
40
|
+
canUseCached = true;
|
|
41
41
|
return value;
|
|
42
42
|
};
|
|
43
43
|
return enforceObservableRules({
|
|
@@ -45,7 +45,7 @@ const createStorageAtomFactory = ({ storage }) => {
|
|
|
45
45
|
set,
|
|
46
46
|
observe,
|
|
47
47
|
defaultValue,
|
|
48
|
-
|
|
48
|
+
makeGetNonConcurrent: true,
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
51
|
return createStorageAtom;
|
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/lib/simple-observer.d.ts
CHANGED
package/lib/utils/guards.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Setter } from './types.js';
|
|
1
|
+
import type { Setter } from './types.js';
|
|
2
2
|
export declare function isSetter<T>(value: T | Setter<T>): value is Setter<T>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/atoms",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0",
|
|
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 .
|
|
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,13 @@
|
|
|
41
40
|
},
|
|
42
41
|
"devDependencies": {
|
|
43
42
|
"@exodus/atom-tests": "^1.0.0",
|
|
44
|
-
"@exodus/storage-
|
|
43
|
+
"@exodus/storage-encrypted": "^1.4.1",
|
|
44
|
+
"@exodus/storage-memory": "^2.2.1",
|
|
45
45
|
"@types/jest": "^29.5.11",
|
|
46
46
|
"@types/json-stringify-safe": "^5.0.3",
|
|
47
47
|
"@types/lodash": "^4.14.200",
|
|
48
48
|
"@types/minimalistic-assert": "^1.0.2",
|
|
49
49
|
"events": "^3.3.0"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "bbcb4c47a53d1770a36213ba77fa1f46bccc8d64"
|
|
52
52
|
}
|