@exodus/atoms 3.3.0 → 3.4.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/package.json +2 -2
- package/src/countdown-lock.js +12 -5
- package/src/enhancers/combine.js +2 -2
- package/src/factories/keystore.js +38 -0
- package/src/index.js +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/atoms",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.1",
|
|
4
4
|
"main": "src/index.js",
|
|
5
5
|
"author": "Exodus Movement Inc.",
|
|
6
6
|
"scripts": {
|
|
@@ -33,5 +33,5 @@
|
|
|
33
33
|
"eslint": "^8.33.0",
|
|
34
34
|
"jest": "^29.1.2"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "0c9ed53bfe02b1d0dc0666bc83c0bd1dcd8f5e36"
|
|
37
37
|
}
|
package/src/countdown-lock.js
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
import pDefer from 'p-defer'
|
|
2
2
|
|
|
3
|
-
const createCountdownLock = (
|
|
4
|
-
if (
|
|
3
|
+
const createCountdownLock = (keys) => {
|
|
4
|
+
if (!Array.isArray(keys)) throw new Error('lock keys must be an array')
|
|
5
|
+
|
|
6
|
+
for (const key of keys) {
|
|
7
|
+
if (typeof key !== 'string') throw new Error(`lock keys must be all strings. Invalid ${key}`)
|
|
8
|
+
}
|
|
5
9
|
|
|
6
10
|
const deferred = pDefer()
|
|
11
|
+
|
|
12
|
+
const unlockedKeys = []
|
|
13
|
+
|
|
7
14
|
return {
|
|
8
15
|
promise: deferred.promise,
|
|
9
|
-
unlock: () => {
|
|
10
|
-
if (
|
|
16
|
+
unlock: (key) => {
|
|
17
|
+
if (!unlockedKeys.includes(key)) unlockedKeys.push(key)
|
|
11
18
|
|
|
12
|
-
if (
|
|
19
|
+
if (unlockedKeys.length === keys.length) {
|
|
13
20
|
deferred.resolve()
|
|
14
21
|
return true
|
|
15
22
|
}
|
package/src/enhancers/combine.js
CHANGED
|
@@ -4,7 +4,7 @@ import createSimpleObserver from '../simple-observer'
|
|
|
4
4
|
|
|
5
5
|
const combine = (atoms) => {
|
|
6
6
|
const { notify, observe } = createSimpleObserver()
|
|
7
|
-
const countdownLock = createCountdownLock(Object.keys(atoms)
|
|
7
|
+
const countdownLock = createCountdownLock(Object.keys(atoms))
|
|
8
8
|
|
|
9
9
|
let values = {}
|
|
10
10
|
|
|
@@ -14,7 +14,7 @@ const combine = (atoms) => {
|
|
|
14
14
|
...values,
|
|
15
15
|
[name]: value,
|
|
16
16
|
}
|
|
17
|
-
if (countdownLock.unlock()) await notify(values)
|
|
17
|
+
if (countdownLock.unlock(name)) await notify(values)
|
|
18
18
|
})
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import enforceObservableRules from '../enforce-rules'
|
|
2
|
+
import createSimpleObserver from '../simple-observer'
|
|
3
|
+
|
|
4
|
+
const createKeystoreAtom = ({
|
|
5
|
+
keystore,
|
|
6
|
+
config: {
|
|
7
|
+
//
|
|
8
|
+
key,
|
|
9
|
+
defaultValue,
|
|
10
|
+
isSoleWriter,
|
|
11
|
+
getOpts,
|
|
12
|
+
setOpts,
|
|
13
|
+
deleteOpts,
|
|
14
|
+
},
|
|
15
|
+
}) => {
|
|
16
|
+
const { notify, observe } = createSimpleObserver({ enable: isSoleWriter })
|
|
17
|
+
|
|
18
|
+
const set = async (value) => {
|
|
19
|
+
if (value == null) {
|
|
20
|
+
await keystore.deleteSecret(key, deleteOpts)
|
|
21
|
+
} else {
|
|
22
|
+
await keystore.setSecret(key, value, setOpts)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (isSoleWriter) await notify(value)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const get = () => keystore.getSecret(key, getOpts)
|
|
29
|
+
|
|
30
|
+
return enforceObservableRules({
|
|
31
|
+
get,
|
|
32
|
+
set,
|
|
33
|
+
observe,
|
|
34
|
+
defaultValue,
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default createKeystoreAtom
|
package/src/index.js
CHANGED
|
@@ -4,6 +4,7 @@ export { default as createFusionAtomFactory } from './factories/fusion'
|
|
|
4
4
|
export { default as createStorageAtomFactory } from './factories/storage'
|
|
5
5
|
export { default as createLocalConfigAtomFactory } from './factories/local-config'
|
|
6
6
|
export { default as createRemoteConfigAtomFactory } from './factories/remote-config'
|
|
7
|
+
export { default as createKeystoreAtom } from './factories/keystore'
|
|
7
8
|
export { default as fromEventEmitter } from './event-emitter'
|
|
8
9
|
export { default as compute } from './enhancers/compute'
|
|
9
10
|
export { default as blockUntil } from './enhancers/block-until'
|