@exodus/atoms 10.0.0 → 10.2.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 +14 -0
- package/lib/enhancers/combine.d.ts +3 -3
- package/lib/enhancers/difference.d.ts +13 -3
- package/lib/enhancers/difference.js +10 -2
- package/lib/enhancers/filter.d.ts +6 -2
- package/lib/factories/storage.d.ts +10 -4
- package/lib/factories/storage.js +5 -2
- package/lib/utils/types.d.ts +3 -0
- package/package.json +5 -4
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,20 @@
|
|
|
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
|
+
## [10.2.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/atoms@10.1.0...@exodus/atoms@10.2.0) (2026-03-23)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- feat(atoms): difference with skipInitial option (#15641)
|
|
11
|
+
|
|
12
|
+
- feat: convert wallet-accounts feature to TypeScript (#15556)
|
|
13
|
+
|
|
14
|
+
## [10.1.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/atoms@10.0.0...@exodus/atoms@10.1.0) (2026-01-29)
|
|
15
|
+
|
|
16
|
+
### Features
|
|
17
|
+
|
|
18
|
+
- feat: infer result atom in `filter`, accept readonly atoms (#15069)
|
|
19
|
+
|
|
6
20
|
## [10.0.0](https://github.com/ExodusMovement/exodus-hydra/compare/@exodus/atoms@9.0.3...@exodus/atoms@10.0.0) (2025-10-08)
|
|
7
21
|
|
|
8
22
|
### ⚠ BREAKING CHANGES
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AnyAtom, ReadonlyAtom } from '../utils/types.js';
|
|
2
2
|
type CombinedValue<T> = {
|
|
3
|
-
[Key in keyof T]: T[Key] extends
|
|
3
|
+
[Key in keyof T]: T[Key] extends AnyAtom<infer U> ? U : never;
|
|
4
4
|
};
|
|
5
5
|
declare const combine: <T, U extends {
|
|
6
|
-
[key: string]:
|
|
6
|
+
[key: string]: AnyAtom<T>;
|
|
7
7
|
}>(atoms: U) => ReadonlyAtom<CombinedValue<U>>;
|
|
8
8
|
export default combine;
|
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
import type { Atom } from '../utils/types.js';
|
|
2
2
|
type Diff<T> = {
|
|
3
|
-
previous
|
|
3
|
+
previous: T | undefined;
|
|
4
4
|
current: T;
|
|
5
5
|
};
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
type NonInitialDiff<T> = {
|
|
7
|
+
previous: T;
|
|
8
|
+
current: T;
|
|
9
|
+
};
|
|
10
|
+
type Options = {
|
|
11
|
+
skipInitial?: boolean;
|
|
12
|
+
};
|
|
13
|
+
type DiffForOptions<T, O extends Options | undefined> = O extends {
|
|
14
|
+
skipInitial: true;
|
|
15
|
+
} ? NonInitialDiff<T> : Diff<T>;
|
|
16
|
+
declare const difference: <T, O extends Options | undefined = undefined>(atom: Atom<T>, options?: O) => Omit<Atom<T>, "observe"> & {
|
|
17
|
+
observe: Atom<DiffForOptions<T, O>>["observe"];
|
|
8
18
|
};
|
|
9
19
|
export default difference;
|
|
@@ -1,12 +1,20 @@
|
|
|
1
|
-
const difference = (atom) => {
|
|
1
|
+
const difference = (atom, options) => {
|
|
2
2
|
const observe = (callback) => {
|
|
3
3
|
let prev;
|
|
4
|
+
let initialValueAssigned = false;
|
|
4
5
|
const selector = (value) => {
|
|
5
6
|
const p = prev;
|
|
6
7
|
prev = value;
|
|
7
8
|
return { previous: p, current: value };
|
|
8
9
|
};
|
|
9
|
-
return atom.observe((value) =>
|
|
10
|
+
return atom.observe((value) => {
|
|
11
|
+
const diffWrappedValue = selector(value);
|
|
12
|
+
if (options?.skipInitial && !initialValueAssigned) {
|
|
13
|
+
initialValueAssigned = true;
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
return callback(diffWrappedValue);
|
|
17
|
+
});
|
|
10
18
|
};
|
|
11
19
|
return {
|
|
12
20
|
...atom,
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
1
|
+
import type { AnyAtom, AtomValue, SetAtomValue } from '../utils/types.js';
|
|
2
|
+
type Predicate<A extends AnyAtom, S extends AtomValue<A>> = ((value: AtomValue<A>) => value is S) | ((value: AtomValue<A>) => unknown);
|
|
3
|
+
type FilteredValue<A extends AnyAtom, P extends Predicate<A, any>> = P extends ((value: AtomValue<A>) => value is infer S extends AtomValue<A>) ? S : AtomValue<A>;
|
|
4
|
+
type ResultAtom<A extends AnyAtom, P extends Predicate<A, any>> = SetAtomValue<A, FilteredValue<A, P>>;
|
|
5
|
+
export default function filter<A extends AnyAtom, S extends AtomValue<A>, P extends Predicate<A, S>>(atom: A, predicate: P): ResultAtom<A, P>;
|
|
6
|
+
export {};
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import type { Atom } from '../utils/types.js';
|
|
2
2
|
import type { Storage } from '@exodus/storage-interface';
|
|
3
|
-
type FactoryParams<T> = {
|
|
4
|
-
storage: Storage<T>;
|
|
5
|
-
};
|
|
6
3
|
type Params<D> = {
|
|
7
4
|
key: string;
|
|
8
5
|
defaultValue?: D;
|
|
6
|
+
isSoleWriter?: boolean;
|
|
9
7
|
};
|
|
10
|
-
declare
|
|
8
|
+
declare function createStorageAtomFactory<T>(params: {
|
|
9
|
+
storage: Storage<T>;
|
|
10
|
+
}): ReturnType<typeof _createStorageAtomFactory<T>>;
|
|
11
|
+
declare function createStorageAtomFactory<T = unknown>(params: {
|
|
12
|
+
storage: Storage;
|
|
13
|
+
}): ReturnType<typeof _createStorageAtomFactory<T>>;
|
|
14
|
+
declare const _createStorageAtomFactory: <T = unknown>({ storage }: {
|
|
15
|
+
storage: Storage;
|
|
16
|
+
}) => {
|
|
11
17
|
(opts: Omit<Params<unknown>, "defaultValue">): Atom<T | undefined>;
|
|
12
18
|
<D extends T>(opts: Params<D>): Atom<T | D>;
|
|
13
19
|
};
|
package/lib/factories/storage.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import createSimpleObserver from '../simple-observer.js';
|
|
2
2
|
import enforceObservableRules from '../enforce-rules.js';
|
|
3
|
-
|
|
3
|
+
function createStorageAtomFactory({ storage, }) {
|
|
4
|
+
return _createStorageAtomFactory({ storage });
|
|
5
|
+
}
|
|
6
|
+
const _createStorageAtomFactory = ({ storage }) => {
|
|
4
7
|
function createStorageAtom({ key, defaultValue }) {
|
|
5
8
|
let version = 0;
|
|
6
9
|
const { notify, observe, listeners } = createSimpleObserver({ enable: true });
|
|
@@ -35,7 +38,7 @@ const createStorageAtomFactory = ({ storage }) => {
|
|
|
35
38
|
return cached;
|
|
36
39
|
}
|
|
37
40
|
const currentVersion = version;
|
|
38
|
-
const value = await storage.get(key);
|
|
41
|
+
const value = (await storage.get(key));
|
|
39
42
|
if (currentVersion !== version) {
|
|
40
43
|
return get();
|
|
41
44
|
}
|
package/lib/utils/types.d.ts
CHANGED
|
@@ -26,3 +26,6 @@ export interface Keystore {
|
|
|
26
26
|
deleteSecret(key: string, options?: object): Promise<string>;
|
|
27
27
|
}
|
|
28
28
|
export type Logger = Pick<Console, 'trace' | 'debug' | 'error' | 'info' | 'log' | 'warn'>;
|
|
29
|
+
export type AnyAtom<V = any> = Atom<V> | ReadonlyAtom<V>;
|
|
30
|
+
export type AtomValue<A extends AnyAtom> = A extends AnyAtom<infer V> ? V : never;
|
|
31
|
+
export type SetAtomValue<A extends AnyAtom, V> = A extends Atom<any> ? Atom<V> : A extends ReadonlyAtom<any> ? ReadonlyAtom<V> : never;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/atoms",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.2.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",
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"scripts": {
|
|
13
13
|
"build": "run -T tsc -p tsconfig.build.json",
|
|
14
14
|
"clean": "run -T tsc --build --clean",
|
|
15
|
-
"test": "run -T exodus-test --jest --esbuild",
|
|
15
|
+
"test": "run -T exodus-test --jest --esbuild && run test:types",
|
|
16
|
+
"test:types": "tsc -p tsconfig.json --noEmit",
|
|
16
17
|
"lint": "run -T eslint .",
|
|
17
18
|
"lint:fix": "yarn lint --fix",
|
|
18
19
|
"prepublishOnly": "yarn run -T build --scope @exodus/atoms"
|
|
@@ -45,7 +46,7 @@
|
|
|
45
46
|
"@exodus/atom-tests": "^1.0.0",
|
|
46
47
|
"@exodus/deferring-storage": "^1.0.2",
|
|
47
48
|
"@exodus/storage-encrypted": "^1.5.1",
|
|
48
|
-
"@exodus/storage-memory": "^2.
|
|
49
|
+
"@exodus/storage-memory": "^2.4.0",
|
|
49
50
|
"@types/jest": "^29.5.11",
|
|
50
51
|
"@types/json-stringify-safe": "^5.0.3",
|
|
51
52
|
"@types/lodash": "^4.14.200",
|
|
@@ -55,5 +56,5 @@
|
|
|
55
56
|
"publishConfig": {
|
|
56
57
|
"provenance": false
|
|
57
58
|
},
|
|
58
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "ac175d43359e60fe2b201bf72c889c8ec501dc86"
|
|
59
60
|
}
|