effector-storage 6.0.0 → 6.1.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.
Files changed (77) hide show
  1. package/README.md +40 -21
  2. package/async-storage/index.cjs.d.ts +1 -1
  3. package/async-storage/index.d.ts +1 -1
  4. package/async-storage/index.js.flow +1 -1
  5. package/broadcast/index.cjs +2 -0
  6. package/broadcast/index.cjs.d.ts +116 -0
  7. package/broadcast/index.cjs.map +1 -0
  8. package/broadcast/index.d.ts +116 -0
  9. package/broadcast/index.js +2 -0
  10. package/broadcast/index.js.flow +134 -0
  11. package/broadcast/index.js.map +1 -0
  12. package/broadcast/package.json +8 -0
  13. package/core/index.cjs +1 -1
  14. package/core/index.cjs.d.ts +1 -1
  15. package/core/index.cjs.map +1 -1
  16. package/core/index.d.ts +1 -1
  17. package/core/index.js +1 -1
  18. package/core/index.js.flow +1 -1
  19. package/core/index.js.map +1 -1
  20. package/index.cjs +1 -1
  21. package/index.cjs.d.ts +3 -1
  22. package/index.cjs.map +1 -1
  23. package/index.d.ts +3 -1
  24. package/index.js +1 -1
  25. package/index.js.flow +3 -1
  26. package/index.js.map +1 -1
  27. package/local/index.cjs.d.ts +10 -5
  28. package/local/index.cjs.map +1 -1
  29. package/local/index.d.ts +10 -5
  30. package/local/index.js.flow +14 -5
  31. package/local/index.js.map +1 -1
  32. package/log/index.cjs.d.ts +1 -1
  33. package/log/index.d.ts +1 -1
  34. package/log/index.js.flow +1 -1
  35. package/memory/index.cjs.d.ts +12 -7
  36. package/memory/index.cjs.map +1 -1
  37. package/memory/index.d.ts +12 -7
  38. package/memory/index.js.flow +19 -10
  39. package/memory/index.js.map +1 -1
  40. package/nil/index.cjs.d.ts +1 -1
  41. package/nil/index.d.ts +1 -1
  42. package/nil/index.js.flow +1 -1
  43. package/package.json +33 -14
  44. package/query/index.cjs +1 -1
  45. package/query/index.cjs.d.ts +12 -5
  46. package/query/index.cjs.map +1 -1
  47. package/query/index.d.ts +12 -5
  48. package/query/index.js +1 -1
  49. package/query/index.js.flow +16 -5
  50. package/query/index.js.map +1 -1
  51. package/rn/async/index.cjs.d.ts +14 -5
  52. package/rn/async/index.cjs.map +1 -1
  53. package/rn/async/index.d.ts +14 -5
  54. package/rn/async/index.js.flow +14 -5
  55. package/rn/async/index.js.map +1 -1
  56. package/rn/encrypted/index.cjs.d.ts +19 -5
  57. package/rn/encrypted/index.cjs.map +1 -1
  58. package/rn/encrypted/index.d.ts +19 -5
  59. package/rn/encrypted/index.js.flow +19 -5
  60. package/rn/encrypted/index.js.map +1 -1
  61. package/session/index.cjs.d.ts +10 -5
  62. package/session/index.cjs.map +1 -1
  63. package/session/index.d.ts +10 -5
  64. package/session/index.js.flow +14 -5
  65. package/session/index.js.map +1 -1
  66. package/storage/index.cjs.d.ts +1 -1
  67. package/storage/index.cjs.map +1 -1
  68. package/storage/index.d.ts +1 -1
  69. package/storage/index.js.flow +1 -1
  70. package/storage/index.js.map +1 -1
  71. package/tools/index.cjs +1 -1
  72. package/tools/index.cjs.d.ts +1 -1
  73. package/tools/index.cjs.map +1 -1
  74. package/tools/index.d.ts +1 -1
  75. package/tools/index.js +1 -1
  76. package/tools/index.js.flow +1 -1
  77. package/tools/index.js.map +1 -1
package/README.md CHANGED
@@ -17,8 +17,10 @@ Small module for [Effector](https://github.com/effector/effector) ☄️ to sync
17
17
  - [with `localStorage`](#with-localstorage)
18
18
  - [with `sessionStorage`](#with-sessionstorage)
19
19
  - [with query string](#with-query-string)
20
+ - [with `BroadcastChannel`](#with-broadcastchannel)
20
21
  - [with React Native AsyncStorage](#with-react-native-asyncstorage)
21
22
  - [with React Native EncryptedStorage](#with-react-native-encryptedstorage)
23
+ - [extra adapters](#extra-adapters)
22
24
  - [Usage with domains](#usage-with-domains)
23
25
  - [Formulae](#formulae)
24
26
  - [Units](#units)
@@ -63,7 +65,7 @@ $ npm install --save effector-storage
63
65
 
64
66
  ### with `localStorage`
65
67
 
66
- Docs: [effector-storage/local](https://github.com/yumauri/effector-storage/tree/master/src/local/README.md)
68
+ Docs: [effector-storage/local](https://github.com/yumauri/effector-storage/tree/main/src/local/README.md)
67
69
 
68
70
  ```javascript
69
71
  import { persist } from 'effector-storage/local'
@@ -79,7 +81,7 @@ Stores, persisted in `localStorage`, are automatically synced between two (or mo
79
81
 
80
82
  ### with `sessionStorage`
81
83
 
82
- Docs: [effector-storage/session](https://github.com/yumauri/effector-storage/tree/master/src/session/README.md)
84
+ Docs: [effector-storage/session](https://github.com/yumauri/effector-storage/tree/main/src/session/README.md)
83
85
 
84
86
  Same as above, just import `persist` from `'effector-storage/session'`:
85
87
 
@@ -91,7 +93,7 @@ Stores, persisted in `sessionStorage`, are synced between instances, but not bet
91
93
 
92
94
  ### with query string
93
95
 
94
- Docs: [effector-storage/query](https://github.com/yumauri/effector-storage/tree/master/src/query/README.md)
96
+ Docs: [effector-storage/query](https://github.com/yumauri/effector-storage/tree/main/src/query/README.md)
95
97
 
96
98
  You can _reflect_ plain string store value in query string parameter, using this adapter. Think of it like about synchronizing store value and query string parameter.
97
99
 
@@ -104,12 +106,21 @@ persist({ store: $id, key: 'id' })
104
106
 
105
107
  If two (or more) stores are persisted in query string with the same key — they are synced between themselves.
106
108
 
107
- ⚠️ **Note**<br>
108
- Use this only with plain string stores (`Store<string | null>`) to avoid strange unexpected behavior.
109
+ ### with `BroadcastChannel`
110
+
111
+ Docs: [effector-storage/broadcast](https://github.com/yumauri/effector-storage/tree/main/src/broadcast/README.md)
112
+
113
+ You can sync stores across different browsing contexts (tabs, windows, workers), just import `persist` from `'effector-storage/broadcast'`:
114
+
115
+ ```javascript
116
+ import { persist } from 'effector-storage/broadcast'
117
+ ```
109
118
 
110
119
  ### with React Native AsyncStorage
111
120
 
112
- Docs: [effector-storage/rn/async](https://github.com/yumauri/effector-storage/tree/master/src/rn/async/README.md)
121
+ ❗️ Deprecated and will be removed in next major release, in favor of [`@effector-storage/react-native-async-storage`](https://github.com/yumauri/effector-storage-extras/tree/main/packages/react-native-async-storage).
122
+
123
+ Docs: [effector-storage/rn/async](https://github.com/yumauri/effector-storage/tree/main/src/rn/async/README.md)
113
124
 
114
125
  ```javascript
115
126
  import { persist } from 'effector-storage/rn/async'
@@ -125,7 +136,9 @@ persist({ store: $counter })
125
136
 
126
137
  ### with React Native EncryptedStorage
127
138
 
128
- Docs: [effector-storage/rn/encrypted](https://github.com/yumauri/effector-storage/tree/master/src/rn/encrypted/README.md)
139
+ ❗️ Deprecated and will be removed in next major release, in favor of [`@effector-storage/react-native-encrypted-storage`](https://github.com/yumauri/effector-storage-extras/tree/main/packages/react-native-encrypted-storage).
140
+
141
+ Docs: [effector-storage/rn/encrypted](https://github.com/yumauri/effector-storage/tree/main/src/rn/encrypted/README.md)
129
142
 
130
143
  ```javascript
131
144
  import { persist } from 'effector-storage/rn/encrypted'
@@ -139,6 +152,10 @@ persist({ store: $counter })
139
152
 
140
153
  ⚠️ Note, that [EncryptedStorage] is asynchronous (it is based on [AsyncStorage] actually).
141
154
 
155
+ ### extra adapters
156
+
157
+ You can find a collection of useful adapters in [effector-storage-extras](https://github.com/yumauri/effector-storage-extras). That side repository was created in order to not bloat `effector-storage` with dependencies and adapters, which depends on other libraries.
158
+
142
159
  ## Usage with domains
143
160
 
144
161
  You can use `persist` inside Domain's `onCreateStore` hook:
@@ -171,7 +188,7 @@ In order to synchronize _something_, you need to specify effector units. Dependi
171
188
 
172
189
  - `store` ([_Store_]): Store to synchronize with local/session storage.
173
190
  - `source` ([_Event_] | [_Effect_] | [_Store_]): Source unit, which updates will be sent to local/session storage.
174
- - `target` ([_Event_] | [_Effect_] | [_Store_]): Target unit, which will receive updates from local/session storage (as well as initial value). Must be different than `source` to avoid circular updates — `source` updates are forwarded directly to `target`.
191
+ - `target` ([_Event_] | [_Effect_] | [_Store_]): Target unit, which will receive updates from local/session storage (as well as initial value). Must be different than `source` to avoid circular updates — `source` updates are passed directly to `target`.
175
192
 
176
193
  ### Options
177
194
 
@@ -250,14 +267,14 @@ persist({
250
267
 
251
268
  There are two gotchas with contracts:
252
269
 
253
- 1. From `effector-storage` point of view it is absolutely normal, when there is no persisted value in the storage yet. So, `undefined` value is _always valid_, event if contract is not explicitly allows it.
254
- 2. `effector-storage` does not validate data, which is written to the storage. But it will validate it nonetheless, after persisting, so, if you write invalid data to the storage, `fail` will be triggered, but data _will be_ persisted.
270
+ 1. From `effector-storage` point of view it is absolutely normal, when there is no persisted value in the storage yet. So, `undefined` value is _always valid_, even if contract does not explicitly allow it.
271
+ 2. `effector-storage` does not prevent persisting invalid data to the storage, but it will validate it nonetheless, after persisting, so, if you write invalid data to the storage, `fail` will be triggered, but data will be persisted.
255
272
 
256
273
  ### Notes
257
274
 
258
275
  Without specifying `pickup` property, calling `persist` will immediately call adapter to get initial value. In case of synchronous storage (like `localStorage` or `sessionStorage`) this action will synchronously set store value, and call `done`/`fail`/`finally` right away. You should take that into account, if you adds some logic on `done`, for example — place `persist` after that logic (see issue [#38](https://github.com/yumauri/effector-storage/issues/38) for more details).
259
276
 
260
- You can modify adapter to be asynchronous to mitigate this behavior with [`async`](https://github.com/yumauri/effector-storage/tree/master/src/tools/README.md#async) function.
277
+ You can modify adapter to be asynchronous to mitigate this behavior with [`async`](https://github.com/yumauri/effector-storage/tree/main/src/tools/README.md#async) function.
261
278
 
262
279
  ## `createPersist` factory
263
280
 
@@ -316,7 +333,7 @@ Adapter is a function, which is called by the core `persist` function, and has f
316
333
  ```typescript
317
334
  interface StorageAdapter {
318
335
  <State>(key: string, update: (raw?: any) => any): {
319
- get(raw?: any, ctx?: any): State | Promise<State>
336
+ get(raw?: any, ctx?: any): State | Promise<State | undefined> | undefined
320
337
  set(value: State, ctx?: any): void
321
338
  }
322
339
  keyArea?: any
@@ -342,7 +359,7 @@ In case it is omitted — adapter instances is used instead.
342
359
 
343
360
  #### noop
344
361
 
345
- Marks adapter as "no-op" for [`either`](https://github.com/yumauri/effector-storage/tree/master/src/tools/README.md#either) function.
362
+ Marks adapter as "no-op" for [`either`](https://github.com/yumauri/effector-storage/tree/main/src/tools/README.md#either) function.
346
363
 
347
364
  ### Synchronous storage adapter example
348
365
 
@@ -416,7 +433,7 @@ If your storage can be updated from _external source_, and doesn't have any even
416
433
  You can use optional `pickup` parameter to specify unit to trigger update (keep in mind, that when you add `pickup`, `persist` _will not_ get initial value from storage automatically):
417
434
 
418
435
  ```javascript
419
- import { createEvent, createStore, forward } from 'effector'
436
+ import { createEvent, createStore } from 'effector'
420
437
  import { persist } from 'effector-storage/session'
421
438
 
422
439
  // event, which will be used to trigger update
@@ -435,7 +452,7 @@ pickup()
435
452
  Another option, if you have your own adapter, you can add this feature right into it:
436
453
 
437
454
  ```javascript
438
- import { createEvent, createStore, forward } from 'effector'
455
+ import { createEvent, createStore } from 'effector'
439
456
  import { persist } from 'effector-storage'
440
457
 
441
458
  // event, which will be used in adapter to react to
@@ -550,12 +567,13 @@ Use this approach with caution, beware of infinite circular updates. To avoid th
550
567
 
551
568
  ## TODO
552
569
 
553
- - [x] [localStorage] support (docs: [effector-storage/local](https://github.com/yumauri/effector-storage/tree/master/src/local/README.md))
554
- - [x] [sessionStorage] support (docs: [effector-storage/session](https://github.com/yumauri/effector-storage/tree/master/src/session/README.md))
555
- - [x] [query string](https://developer.mozilla.org/en-US/docs/Web/API/Location/search) support (docs: [effector-storage/query](https://github.com/yumauri/effector-storage/tree/master/src/query/README.md))
556
- - [x] [AsyncStorage] support (docs: [effector-storage/rn/async](https://github.com/yumauri/effector-storage/tree/master/src/rn/async/README.md))
557
- - [x] [EncryptedStorage] support (docs: [effector-storage/rn/encrypted](https://github.com/yumauri/effector-storage/tree/master/src/rn/encrypted/README.md))
558
- - [ ] [IndexedDB] support
570
+ - [x] [localStorage] support (docs: [effector-storage/local](https://github.com/yumauri/effector-storage/tree/main/src/local/README.md))
571
+ - [x] [sessionStorage] support (docs: [effector-storage/session](https://github.com/yumauri/effector-storage/tree/main/src/session/README.md))
572
+ - [x] [query string](https://developer.mozilla.org/en-US/docs/Web/API/Location/search) support (docs: [effector-storage/query](https://github.com/yumauri/effector-storage/tree/main/src/query/README.md))
573
+ - [x] [BroadcastChannel] support (docs: [effector-storage/broadcast](https://github.com/yumauri/effector-storage/tree/main/src/broadcast/README.md))
574
+ - [x] [AsyncStorage] support (extras: [@effector-storage/react-native-async-storage](https://github.com/yumauri/effector-storage-extras/tree/main/packages/react-native-async-storage))
575
+ - [x] [EncryptedStorage] support (extras: [@effector-storage/react-native-encrypted-storage](https://github.com/yumauri/effector-storage-extras/tree/main/packages/react-native-encrypted-storage))
576
+ - [x] [IndexedDB] support (extras: [@effector-storage/idb-keyval](https://github.com/yumauri/effector-storage-extras/tree/main/packages/idb-keyval))
559
577
  - [ ] [Cookies] support
560
578
  - [ ] you name it support
561
579
 
@@ -569,6 +587,7 @@ Use this approach with caution, beware of infinite circular updates. To avoid th
569
587
  [sessionstorage]: https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage
570
588
  [`'storage'`]: https://developer.mozilla.org/en-US/docs/Web/API/StorageEvent
571
589
  [indexeddb]: https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API
590
+ [broadcastchannel]: https://developer.mozilla.org/en-US/docs/Web/API/BroadcastChannel
572
591
  [asyncstorage]: https://react-native-async-storage.github.io/async-storage/
573
592
  [encryptedstorage]: https://github.com/emeraldsanto/react-native-encrypted-storage
574
593
  [cookies]: https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie
@@ -1,6 +1,6 @@
1
1
  interface StorageAdapter {
2
2
  <State>(key: string, update: (raw?: any) => any): {
3
- get(raw?: any, ctx?: any): State | Promise<State>
3
+ get(raw?: any, ctx?: any): State | Promise<State | undefined> | undefined
4
4
  set(value: State, ctx?: any): void
5
5
  }
6
6
  keyArea?: any
@@ -1,6 +1,6 @@
1
1
  interface StorageAdapter {
2
2
  <State>(key: string, update: (raw?: any) => any): {
3
- get(raw?: any, ctx?: any): State | Promise<State>
3
+ get(raw?: any, ctx?: any): State | Promise<State | undefined> | undefined
4
4
  set(value: State, ctx?: any): void
5
5
  }
6
6
  keyArea?: any
@@ -10,7 +10,7 @@ declare interface StorageAdapter {
10
10
  key: string,
11
11
  update: (raw?: any) => any
12
12
  ): {
13
- get(raw?: any, ctx?: any): State | Promise<State>,
13
+ get(raw?: any, ctx?: any): State | Promise<State | void> | void,
14
14
  set(value: State, ctx?: any): void,
15
15
  ...
16
16
  };
@@ -0,0 +1,2 @@
1
+ "use strict";var e=require("../core/index.cjs"),r=require("../nil/index.cjs"),t=new Map;function a(e){return"undefined"!=typeof BroadcastChannel?function({channel:e="effector-storage"}){var r,a=t.get(e)??(r=new BroadcastChannel(e));r&&t.set(e,r);var s=(e,r)=>(a.addEventListener("message",(({data:t})=>{null==t?r((()=>{throw new Error("Unable to deserialize message")})):t.key===e&&r((()=>t.value))})),a.addEventListener("messageerror",(()=>{r((()=>{throw new Error("Unable to deserialize message")}))})),{get(e){if(e)return e()},set(r){a.postMessage({key:e,value:r})}});return s.keyArea=a,s}({...e}):r.nil({keyArea:"broadcast"})}function s(r){return t=>e.persist({adapter:a,...r,...t})}a.factory=!0;var n=s();exports.broadcast=a,exports.createPersist=s,exports.persist=n;
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1,116 @@
1
+ import { Unit, Store, Event, Effect, Subscription } from 'effector'
2
+
3
+ interface StorageAdapter {
4
+ <State>(key: string, update: (raw?: any) => any): {
5
+ get(raw?: any, ctx?: any): State | Promise<State | undefined> | undefined
6
+ set(value: State, ctx?: any): void
7
+ }
8
+ keyArea?: any
9
+ noop?: boolean
10
+ }
11
+ interface StorageAdapterFactory<AdapterConfig> {
12
+ (config?: AdapterConfig): StorageAdapter
13
+ factory: true
14
+ }
15
+ type Contract<Data> =
16
+ | ((raw: unknown) => raw is Data)
17
+ | {
18
+ isData: (raw: unknown) => raw is Data
19
+ getErrorMessages: (raw: unknown) => string[]
20
+ }
21
+ type Done<State> = {
22
+ key: string
23
+ keyPrefix: string
24
+ operation: 'set' | 'get'
25
+ value: State
26
+ }
27
+ type Fail<Err> = {
28
+ key: string
29
+ keyPrefix: string
30
+ operation: 'set' | 'get'
31
+ error: Err
32
+ value?: any
33
+ }
34
+ type Finally<State, Err> =
35
+ | (Done<State> & {
36
+ status: 'done'
37
+ })
38
+ | (Fail<Err> & {
39
+ status: 'fail'
40
+ })
41
+ interface ConfigPersist$1 {
42
+ pickup?: Unit<any>
43
+ context?: Unit<any>
44
+ keyPrefix?: string
45
+ contract?: Contract<any>
46
+ }
47
+ interface ConfigCommon<State, Err = Error> {
48
+ clock?: Unit<any>
49
+ done?: Unit<Done<State>>
50
+ fail?: Unit<Fail<Err>>
51
+ finally?: Unit<Finally<State, Err>>
52
+ pickup?: Unit<any>
53
+ context?: Unit<any>
54
+ key?: string
55
+ keyPrefix?: string
56
+ contract?: Contract<State | undefined>
57
+ }
58
+ interface ConfigJustStore<State> {
59
+ store: Store<State>
60
+ }
61
+ interface ConfigJustSourceTarget<State> {
62
+ source: Store<State> | Event<State> | Effect<State, any, any>
63
+ target: Store<State> | Event<State> | Effect<State, any, any>
64
+ }
65
+ interface ConfigStore$1<State, Err = Error>
66
+ extends ConfigCommon<State, Err>,
67
+ ConfigJustStore<State> {}
68
+ interface ConfigSourceTarget$1<State, Err = Error>
69
+ extends ConfigCommon<State, Err>,
70
+ ConfigJustSourceTarget<State> {}
71
+
72
+ interface BroadcastConfig {
73
+ channel?: string
74
+ }
75
+
76
+ interface ConfigPersist extends ConfigPersist$1 {}
77
+ interface ConfigStore<State, Err = Error>
78
+ extends BroadcastConfig,
79
+ ConfigStore$1<State, Err> {}
80
+ interface ConfigSourceTarget<State, Err = Error>
81
+ extends BroadcastConfig,
82
+ ConfigSourceTarget$1<State, Err> {}
83
+ interface Persist {
84
+ <State, Err = Error>(config: ConfigSourceTarget<State, Err>): Subscription
85
+ <State, Err = Error>(config: ConfigStore<State, Err>): Subscription
86
+ }
87
+ declare function broadcast(config?: BroadcastConfig): StorageAdapter
88
+ declare namespace broadcast {
89
+ var factory: true
90
+ }
91
+ /**
92
+ * Creates custom partially applied `persist`
93
+ * with predefined BroadcastChannel adapter
94
+ */
95
+ declare function createPersist(defaults?: ConfigPersist): Persist
96
+ /**
97
+ * Default partially applied `persist`
98
+ */
99
+ declare const persist: Persist
100
+
101
+ export {
102
+ BroadcastConfig,
103
+ ConfigPersist,
104
+ ConfigSourceTarget,
105
+ ConfigStore,
106
+ Contract,
107
+ Done,
108
+ Fail,
109
+ Finally,
110
+ Persist,
111
+ StorageAdapter,
112
+ StorageAdapterFactory,
113
+ broadcast,
114
+ createPersist,
115
+ persist,
116
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../../src/broadcast/adapter.ts","../../src/broadcast/index.ts"],"sourcesContent":["import type { StorageAdapter } from '../types'\n\nexport interface BroadcastConfig {\n channel?: string\n}\n\n/**\n * BroadcastChannel instances cache\n */\nconst channels = new Map<string, BroadcastChannel>()\n\n/**\n * BroadcastChannel adapter factory\n */\nexport function adapter({\n channel = 'effector-storage',\n}: BroadcastConfig): StorageAdapter {\n let created: BroadcastChannel | undefined\n const bus = channels.get(channel) ?? (created = new BroadcastChannel(channel))\n if (created) channels.set(channel, created)\n\n const adapter: StorageAdapter = <State>(\n key: string,\n update: (raw?: any) => any\n ) => {\n bus.addEventListener('message', ({ data }) => {\n // according to e2e tests, chromium can call `message`\n // instead of `messageerror`, with `null` as message's data\n if (data == null) {\n update(() => {\n throw new Error('Unable to deserialize message')\n })\n } else if (data.key === key) {\n update(() => {\n return data.value\n })\n }\n })\n\n // I know only one case when this event can be fired:\n // if message was sent from page to shared worker, and it contains `SharedArrayBuffer`\n // https://bugs.webkit.org/show_bug.cgi?id=171216\n bus.addEventListener('messageerror', () => {\n update(() => {\n throw new Error('Unable to deserialize message')\n })\n })\n\n return {\n get(box?: () => State | undefined) {\n if (box) return box()\n },\n\n set(value: State) {\n bus.postMessage({ key, value })\n },\n }\n }\n\n adapter.keyArea = bus\n return adapter\n}\n","import type { Subscription } from 'effector'\nimport type {\n ConfigPersist as BaseConfigPersist,\n ConfigStore as BaseConfigStore,\n ConfigSourceTarget as BaseConfigSourceTarget,\n StorageAdapter,\n} from '../types'\nimport type { BroadcastConfig } from './adapter'\nimport { persist as base } from '../core'\nimport { nil } from '../nil'\nimport { adapter } from './adapter'\n\nexport type {\n Contract,\n Done,\n Fail,\n Finally,\n StorageAdapter,\n StorageAdapterFactory,\n} from '../types'\nexport type { BroadcastConfig } from './adapter'\n\nexport interface ConfigPersist extends BaseConfigPersist {}\n\nexport interface ConfigStore<State, Err = Error>\n extends BroadcastConfig,\n BaseConfigStore<State, Err> {}\n\nexport interface ConfigSourceTarget<State, Err = Error>\n extends BroadcastConfig,\n BaseConfigSourceTarget<State, Err> {}\n\nexport interface Persist {\n <State, Err = Error>(config: ConfigSourceTarget<State, Err>): Subscription\n <State, Err = Error>(config: ConfigStore<State, Err>): Subscription\n}\n\n/**\n * Function, checking if `BroadcastChannel` exists and accessible\n */\nfunction supports() {\n return typeof BroadcastChannel !== 'undefined'\n}\n\n/**\n * Creates BroadcastChannel string adapter\n */\nbroadcast.factory = true as const\nexport function broadcast(config?: BroadcastConfig): StorageAdapter {\n return supports()\n ? adapter({\n ...config,\n })\n : nil({ keyArea: 'broadcast' })\n}\n\n/**\n * Creates custom partially applied `persist`\n * with predefined BroadcastChannel adapter\n */\nexport function createPersist(defaults?: ConfigPersist): Persist {\n return (config) =>\n base({\n adapter: broadcast,\n ...defaults,\n ...config,\n })\n}\n\n/**\n * Default partially applied `persist`\n */\nexport const persist = createPersist()\n"],"names":["channels","Map","broadcast","config","BroadcastChannel","channel","created","bus","get","set","adapter","key","update","addEventListener","data","Error","value","box","postMessage","keyArea","nil","createPersist","defaults","base","factory","persist"],"mappings":"8EASMA,EAAW,IAAIC,ICuCd,SAASC,EAAUC,GACxB,MARmC,oBAArBC,iBD3BT,UAAiBC,QACtBA,EAAU,qBAEV,IAAIC,EACEC,EAAMP,EAASQ,IAAIH,KAAaC,EAAU,IAAIF,iBAAiBC,IACjEC,GAASN,EAASS,IAAIJ,EAASC,GAEnC,IAAMI,EAA0BA,CAC9BC,EACAC,KAEAL,EAAIM,iBAAiB,WAAW,EAAGC,WAGrB,MAARA,EACFF,GAAO,KACL,MAAM,IAAIG,MAAM,gCAAgC,IAEzCD,EAAKH,MAAQA,GACtBC,GAAO,IACEE,EAAKE,OAEhB,IAMFT,EAAIM,iBAAiB,gBAAgB,KACnCD,GAAO,KACL,MAAM,IAAIG,MAAM,gCAAgC,GAChD,IAGG,CACLP,IAAIS,GACF,GAAIA,EAAK,OAAOA,GACjB,EAEDR,IAAIO,GACFT,EAAIW,YAAY,CAAEP,MAAKK,SACzB,IAKJ,OADAN,EAAQS,QAAUZ,EACXG,CACT,CCXMA,CAAQ,IACHP,IAELiB,EAAAA,IAAI,CAAED,QAAS,aACrB,CAMO,SAASE,EAAcC,GAC5B,OAAQnB,GACNoB,EAAAA,QAAK,CACHb,QAASR,KACNoB,KACAnB,GAET,CApBAD,EAAUsB,SAAU,EAyBPC,IAAAA,EAAUJ"}
@@ -0,0 +1,116 @@
1
+ import { Unit, Store, Event, Effect, Subscription } from 'effector'
2
+
3
+ interface StorageAdapter {
4
+ <State>(key: string, update: (raw?: any) => any): {
5
+ get(raw?: any, ctx?: any): State | Promise<State | undefined> | undefined
6
+ set(value: State, ctx?: any): void
7
+ }
8
+ keyArea?: any
9
+ noop?: boolean
10
+ }
11
+ interface StorageAdapterFactory<AdapterConfig> {
12
+ (config?: AdapterConfig): StorageAdapter
13
+ factory: true
14
+ }
15
+ type Contract<Data> =
16
+ | ((raw: unknown) => raw is Data)
17
+ | {
18
+ isData: (raw: unknown) => raw is Data
19
+ getErrorMessages: (raw: unknown) => string[]
20
+ }
21
+ type Done<State> = {
22
+ key: string
23
+ keyPrefix: string
24
+ operation: 'set' | 'get'
25
+ value: State
26
+ }
27
+ type Fail<Err> = {
28
+ key: string
29
+ keyPrefix: string
30
+ operation: 'set' | 'get'
31
+ error: Err
32
+ value?: any
33
+ }
34
+ type Finally<State, Err> =
35
+ | (Done<State> & {
36
+ status: 'done'
37
+ })
38
+ | (Fail<Err> & {
39
+ status: 'fail'
40
+ })
41
+ interface ConfigPersist$1 {
42
+ pickup?: Unit<any>
43
+ context?: Unit<any>
44
+ keyPrefix?: string
45
+ contract?: Contract<any>
46
+ }
47
+ interface ConfigCommon<State, Err = Error> {
48
+ clock?: Unit<any>
49
+ done?: Unit<Done<State>>
50
+ fail?: Unit<Fail<Err>>
51
+ finally?: Unit<Finally<State, Err>>
52
+ pickup?: Unit<any>
53
+ context?: Unit<any>
54
+ key?: string
55
+ keyPrefix?: string
56
+ contract?: Contract<State | undefined>
57
+ }
58
+ interface ConfigJustStore<State> {
59
+ store: Store<State>
60
+ }
61
+ interface ConfigJustSourceTarget<State> {
62
+ source: Store<State> | Event<State> | Effect<State, any, any>
63
+ target: Store<State> | Event<State> | Effect<State, any, any>
64
+ }
65
+ interface ConfigStore$1<State, Err = Error>
66
+ extends ConfigCommon<State, Err>,
67
+ ConfigJustStore<State> {}
68
+ interface ConfigSourceTarget$1<State, Err = Error>
69
+ extends ConfigCommon<State, Err>,
70
+ ConfigJustSourceTarget<State> {}
71
+
72
+ interface BroadcastConfig {
73
+ channel?: string
74
+ }
75
+
76
+ interface ConfigPersist extends ConfigPersist$1 {}
77
+ interface ConfigStore<State, Err = Error>
78
+ extends BroadcastConfig,
79
+ ConfigStore$1<State, Err> {}
80
+ interface ConfigSourceTarget<State, Err = Error>
81
+ extends BroadcastConfig,
82
+ ConfigSourceTarget$1<State, Err> {}
83
+ interface Persist {
84
+ <State, Err = Error>(config: ConfigSourceTarget<State, Err>): Subscription
85
+ <State, Err = Error>(config: ConfigStore<State, Err>): Subscription
86
+ }
87
+ declare function broadcast(config?: BroadcastConfig): StorageAdapter
88
+ declare namespace broadcast {
89
+ var factory: true
90
+ }
91
+ /**
92
+ * Creates custom partially applied `persist`
93
+ * with predefined BroadcastChannel adapter
94
+ */
95
+ declare function createPersist(defaults?: ConfigPersist): Persist
96
+ /**
97
+ * Default partially applied `persist`
98
+ */
99
+ declare const persist: Persist
100
+
101
+ export {
102
+ BroadcastConfig,
103
+ ConfigPersist,
104
+ ConfigSourceTarget,
105
+ ConfigStore,
106
+ Contract,
107
+ Done,
108
+ Fail,
109
+ Finally,
110
+ Persist,
111
+ StorageAdapter,
112
+ StorageAdapterFactory,
113
+ broadcast,
114
+ createPersist,
115
+ persist,
116
+ }
@@ -0,0 +1,2 @@
1
+ import{persist as e}from"../core/index.js";import{nil as r}from"../nil/index.js";var a=new Map;function t(e){return"undefined"!=typeof BroadcastChannel?function({channel:e="effector-storage"}){var r,t=a.get(e)??(r=new BroadcastChannel(e));r&&a.set(e,r);var n=(e,r)=>(t.addEventListener("message",(({data:a})=>{null==a?r((()=>{throw new Error("Unable to deserialize message")})):a.key===e&&r((()=>a.value))})),t.addEventListener("messageerror",(()=>{r((()=>{throw new Error("Unable to deserialize message")}))})),{get(e){if(e)return e()},set(r){t.postMessage({key:e,value:r})}});return n.keyArea=t,n}({...e}):r({keyArea:"broadcast"})}function n(r){return a=>e({adapter:t,...r,...a})}t.factory=!0;var s=n();export{t as broadcast,n as createPersist,s as persist};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,134 @@
1
+ /**
2
+ * Flowtype definitions for index
3
+ * Generated by Flowgen from a Typescript Definition
4
+ * Flowgen v1.21.0
5
+ * @flow
6
+ */
7
+
8
+ import { Unit, Store, Event, Effect, Subscription } from 'effector'
9
+ declare interface StorageAdapter {
10
+ <State>(
11
+ key: string,
12
+ update: (raw?: any) => any
13
+ ): {
14
+ get(raw?: any, ctx?: any): State | Promise<State | void> | void,
15
+ set(value: State, ctx?: any): void,
16
+ ...
17
+ };
18
+ keyArea?: any;
19
+ noop?: boolean;
20
+ }
21
+ declare interface StorageAdapterFactory<AdapterConfig> {
22
+ (config?: AdapterConfig): StorageAdapter;
23
+ factory: true;
24
+ }
25
+ declare type Contract<Data> =
26
+ | ((raw: mixed) => boolean)
27
+ | {
28
+ isData: (raw: mixed) => boolean,
29
+ getErrorMessages: (raw: mixed) => string[],
30
+ ...
31
+ }
32
+ declare type Done<State> = {
33
+ key: string,
34
+ keyPrefix: string,
35
+ operation: 'set' | 'get',
36
+ value: State,
37
+ ...
38
+ }
39
+ declare type Fail<Err> = {
40
+ key: string,
41
+ keyPrefix: string,
42
+ operation: 'set' | 'get',
43
+ error: Err,
44
+ value?: any,
45
+ ...
46
+ }
47
+ declare type Finally<State, Err> =
48
+ | {
49
+ ...Done<State>,
50
+ ...{
51
+ status: 'done',
52
+ ...
53
+ },
54
+ }
55
+ | {
56
+ ...Fail<Err>,
57
+ ...{
58
+ status: 'fail',
59
+ ...
60
+ },
61
+ }
62
+ declare interface ConfigPersist$1 {
63
+ pickup?: Unit<any>;
64
+ context?: Unit<any>;
65
+ keyPrefix?: string;
66
+ contract?: Contract<any>;
67
+ }
68
+ declare interface ConfigCommon<State, Err = Error> {
69
+ clock?: Unit<any>;
70
+ done?: Unit<Done<State>>;
71
+ fail?: Unit<Fail<Err>>;
72
+ finally?: Unit<Finally<State, Err>>;
73
+ pickup?: Unit<any>;
74
+ context?: Unit<any>;
75
+ key?: string;
76
+ keyPrefix?: string;
77
+ contract?: Contract<State | void>;
78
+ }
79
+ declare interface ConfigJustStore<State> {
80
+ store: Store<State>;
81
+ }
82
+ declare interface ConfigJustSourceTarget<State> {
83
+ source: Store<State> | Event<State> | Effect<State, any, any>;
84
+ target: Store<State> | Event<State> | Effect<State, any, any>;
85
+ }
86
+ declare type ConfigStore$1<State, Err = Error> = { ... } & ConfigCommon<
87
+ State,
88
+ Err
89
+ > &
90
+ ConfigJustStore<State>
91
+ declare type ConfigSourceTarget$1<State, Err = Error> = { ... } & ConfigCommon<
92
+ State,
93
+ Err
94
+ > &
95
+ ConfigJustSourceTarget<State>
96
+ declare interface BroadcastConfig {
97
+ channel?: string;
98
+ }
99
+ declare type ConfigPersist = { ... } & ConfigPersist$1
100
+ declare type ConfigStore<State, Err = Error> = { ... } & BroadcastConfig &
101
+ ConfigStore$1<State, Err>
102
+ declare type ConfigSourceTarget<State, Err = Error> = {
103
+ ...
104
+ } & BroadcastConfig &
105
+ ConfigSourceTarget$1<State, Err>
106
+ declare interface Persist {
107
+ <State, Err>(config: ConfigSourceTarget<State, Err>): Subscription;
108
+ <State, Err>(config: ConfigStore<State, Err>): Subscription;
109
+ }
110
+ declare var broadcast: typeof npm$namespace$broadcast
111
+
112
+ declare var npm$namespace$broadcast: {|
113
+ (config?: BroadcastConfig): StorageAdapter,
114
+ factory: typeof broadcast$factory,
115
+ |}
116
+ declare var broadcast$factory: true
117
+ declare function createPersist(defaults?: ConfigPersist): Persist
118
+ declare var persist: Persist
119
+ declare export {
120
+ BroadcastConfig,
121
+ ConfigPersist,
122
+ ConfigSourceTarget,
123
+ ConfigStore,
124
+ Contract,
125
+ Done,
126
+ Fail,
127
+ Finally,
128
+ Persist,
129
+ StorageAdapter,
130
+ StorageAdapterFactory,
131
+ broadcast,
132
+ createPersist,
133
+ persist,
134
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../src/broadcast/adapter.ts","../../src/broadcast/index.ts"],"sourcesContent":["import type { StorageAdapter } from '../types'\n\nexport interface BroadcastConfig {\n channel?: string\n}\n\n/**\n * BroadcastChannel instances cache\n */\nconst channels = new Map<string, BroadcastChannel>()\n\n/**\n * BroadcastChannel adapter factory\n */\nexport function adapter({\n channel = 'effector-storage',\n}: BroadcastConfig): StorageAdapter {\n let created: BroadcastChannel | undefined\n const bus = channels.get(channel) ?? (created = new BroadcastChannel(channel))\n if (created) channels.set(channel, created)\n\n const adapter: StorageAdapter = <State>(\n key: string,\n update: (raw?: any) => any\n ) => {\n bus.addEventListener('message', ({ data }) => {\n // according to e2e tests, chromium can call `message`\n // instead of `messageerror`, with `null` as message's data\n if (data == null) {\n update(() => {\n throw new Error('Unable to deserialize message')\n })\n } else if (data.key === key) {\n update(() => {\n return data.value\n })\n }\n })\n\n // I know only one case when this event can be fired:\n // if message was sent from page to shared worker, and it contains `SharedArrayBuffer`\n // https://bugs.webkit.org/show_bug.cgi?id=171216\n bus.addEventListener('messageerror', () => {\n update(() => {\n throw new Error('Unable to deserialize message')\n })\n })\n\n return {\n get(box?: () => State | undefined) {\n if (box) return box()\n },\n\n set(value: State) {\n bus.postMessage({ key, value })\n },\n }\n }\n\n adapter.keyArea = bus\n return adapter\n}\n","import type { Subscription } from 'effector'\nimport type {\n ConfigPersist as BaseConfigPersist,\n ConfigStore as BaseConfigStore,\n ConfigSourceTarget as BaseConfigSourceTarget,\n StorageAdapter,\n} from '../types'\nimport type { BroadcastConfig } from './adapter'\nimport { persist as base } from '../core'\nimport { nil } from '../nil'\nimport { adapter } from './adapter'\n\nexport type {\n Contract,\n Done,\n Fail,\n Finally,\n StorageAdapter,\n StorageAdapterFactory,\n} from '../types'\nexport type { BroadcastConfig } from './adapter'\n\nexport interface ConfigPersist extends BaseConfigPersist {}\n\nexport interface ConfigStore<State, Err = Error>\n extends BroadcastConfig,\n BaseConfigStore<State, Err> {}\n\nexport interface ConfigSourceTarget<State, Err = Error>\n extends BroadcastConfig,\n BaseConfigSourceTarget<State, Err> {}\n\nexport interface Persist {\n <State, Err = Error>(config: ConfigSourceTarget<State, Err>): Subscription\n <State, Err = Error>(config: ConfigStore<State, Err>): Subscription\n}\n\n/**\n * Function, checking if `BroadcastChannel` exists and accessible\n */\nfunction supports() {\n return typeof BroadcastChannel !== 'undefined'\n}\n\n/**\n * Creates BroadcastChannel string adapter\n */\nbroadcast.factory = true as const\nexport function broadcast(config?: BroadcastConfig): StorageAdapter {\n return supports()\n ? adapter({\n ...config,\n })\n : nil({ keyArea: 'broadcast' })\n}\n\n/**\n * Creates custom partially applied `persist`\n * with predefined BroadcastChannel adapter\n */\nexport function createPersist(defaults?: ConfigPersist): Persist {\n return (config) =>\n base({\n adapter: broadcast,\n ...defaults,\n ...config,\n })\n}\n\n/**\n * Default partially applied `persist`\n */\nexport const persist = createPersist()\n"],"names":["channels","Map","broadcast","config","BroadcastChannel","channel","created","bus","get","set","adapter","key","update","addEventListener","data","Error","value","box","postMessage","keyArea","nil","createPersist","defaults","base","factory","persist"],"mappings":"iFASA,IAAMA,EAAW,IAAIC,ICuCd,SAASC,EAAUC,GACxB,MARmC,oBAArBC,iBD3BT,UAAiBC,QACtBA,EAAU,qBAEV,IAAIC,EACEC,EAAMP,EAASQ,IAAIH,KAAaC,EAAU,IAAIF,iBAAiBC,IACjEC,GAASN,EAASS,IAAIJ,EAASC,GAEnC,IAAMI,EAA0BA,CAC9BC,EACAC,KAEAL,EAAIM,iBAAiB,WAAW,EAAGC,WAGrB,MAARA,EACFF,GAAO,KACL,MAAM,IAAIG,MAAM,gCAAgC,IAEzCD,EAAKH,MAAQA,GACtBC,GAAO,IACEE,EAAKE,OAEhB,IAMFT,EAAIM,iBAAiB,gBAAgB,KACnCD,GAAO,KACL,MAAM,IAAIG,MAAM,gCAAgC,GAChD,IAGG,CACLP,IAAIS,GACF,GAAIA,EAAK,OAAOA,GACjB,EAEDR,IAAIO,GACFT,EAAIW,YAAY,CAAEP,MAAKK,SACzB,IAKJ,OADAN,EAAQS,QAAUZ,EACXG,CACT,CCXMA,CAAQ,IACHP,IAELiB,EAAI,CAAED,QAAS,aACrB,CAMO,SAASE,EAAcC,GAC5B,OAAQnB,GACNoB,EAAK,CACHb,QAASR,KACNoB,KACAnB,GAET,CApBAD,EAAUsB,SAAU,EAyBPC,IAAAA,EAAUJ"}
@@ -0,0 +1,8 @@
1
+ {
2
+ "type": "module",
3
+ "sideEffects": false,
4
+ "main": "index.cjs",
5
+ "module": "index.js",
6
+ "react-native": "index.js",
7
+ "types": "index.d.ts"
8
+ }
package/core/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var e=require("effector"),r=new Map,t=e=>(r,t)=>e(t,r.ref),o=e.createEvent();o.watch((e=>console.error(e.error))),exports.persist=function(a){var{adapter:i,store:f,source:s=f,target:n=f,clock:d=s,done:c,fail:u=o,finally:l,pickup:p,context:v,key:y,keyPrefix:g="",contract:m}=a;if(!i)throw Error("Adapter is not defined");if(!s)throw Error("Store or source is not defined");if(!n)throw Error("Target is not defined");if(!y&&s.shortName===s.id)throw Error("Key or name is not defined");if(s===n&&!e.is.store(s))throw Error("Source must be different from target");void 0===a.def&&e.is.store(s)&&(a.def=s.defaultState);var k="factory"in i?i(a):i,w=y||s.shortName,h=function(t,o){var a=r.get(t);void 0===a&&(a=new Map,r.set(t,a));var i=a.get(o);return void 0!==i||(i=e.createStore(null,{serialize:"ignore"}),a.set(o,i)),i}(k.keyArea||k,g+w),E=e.createNode(),x=()=>e.clearNode(E),P=e=>({status:r="fail",params:t,result:o,error:a})=>"done"===r?{status:r,key:w,keyPrefix:g,operation:e,value:"get"===e?o:t}:{status:r,key:w,keyPrefix:g,operation:e,value:t,error:a};return e.withRegion(E,(()=>{var r=e.createStore({ref:void 0},{serialize:"ignore"}),o=k(g+w,(e=>D(e))),a=e.attach({source:r,effect:t(o.get)}),i=e.attach({source:r,effect:t(o.set)}),f=e.createEffect((e=>r=>!e||void 0===r||("isData"in e?e.isData(r):e(r))?r:(()=>{throw"getErrorMessages"in e?e.getErrorMessages(r):void 0})())(m)),y=e.createEvent(),E=y.filterMap((({status:e,key:r,keyPrefix:t,operation:o,value:a})=>"done"===e?{key:r,keyPrefix:t,operation:o,value:a}:void 0)),x=y.filterMap((({status:e,key:r,keyPrefix:t,operation:o,error:a,value:i})=>"fail"===e?{key:r,keyPrefix:t,operation:o,error:a,value:i}:void 0)),M=e.createEvent(),D=a;r.updates.watch((()=>{D=(r=>{try{return e.scopeBind(r,{safe:!0})}catch(e){return r}})(a)})),e.sample({source:s,clock:d,target:M}),e.guard({source:e.sample(h,M,((e,r)=>[r,e])),filter:([e,r])=>e!==r,target:i.prepend((([e])=>e))}),e.forward({from:[a.doneData,i],to:h}),e.sample({source:e.merge([a.doneData,h]),target:f}),e.forward({from:f.doneData,to:n}),e.forward({from:[a.finally.map(P("get")),i.finally.map(P("set")),f.fail.map(P("validate"))],to:y}),e.forward({from:x,to:u}),c&&e.forward({from:E,to:c}),l&&e.forward({from:y,to:l}),v&&r.on(v,(({ref:e},r)=>({ref:void 0===r?e:r}))),p?(e.forward({from:p,to:a.prepend((()=>{}))}),r.on(p,(({ref:e},r)=>({ref:void 0===r?e:r})))):a()})),x.unsubscribe=x};
1
+ "use strict";var e=require("effector"),r=new Map,t=e=>([r],t)=>e(t,r),a=e.createEvent();a.watch((e=>console.error(e.error))),exports.persist=function(o){var{adapter:i,store:s,source:c=s,target:n=s,clock:l=c,done:f,fail:d=a,finally:u,pickup:p,context:g,key:k,keyPrefix:v="",contract:y}=o;if(!i)throw Error("Adapter is not defined");if(!c)throw Error("Store or source is not defined");if(!n)throw Error("Target is not defined");if(!k&&c.shortName===c.id)throw Error("Key or name is not defined");if(c===n&&!e.is.store(c))throw Error("Source must be different from target");void 0===o.def&&e.is.store(c)&&(o.def=c.defaultState);var m="factory"in i?i(o):i,h=k||c.shortName,w=function(t,a){var o=r.get(t);void 0===o&&(o=new Map,r.set(t,o));var i=o.get(a);return void 0!==i||(i=e.createStore(null,{serialize:"ignore"}),o.set(a,i)),i}(m.keyArea||m,v+h),E=e.createNode(),x=()=>e.clearNode(E),P=e=>({status:r="fail",params:t,result:a,error:o})=>"done"===r?{status:r,key:h,keyPrefix:v,operation:e,value:"get"===e?a:t}:{status:r,key:h,keyPrefix:v,operation:e,value:"function"==typeof t?void 0:t,error:o};return e.withRegion(E,(()=>{var r=e.createStore([],{serialize:"ignore"}),a=m(v+h,(e=>D(e))),o=e.attach({source:r,effect:t(a.get)}),i=e.attach({source:r,effect:t(a.set)}),s=e.createEffect((e=>r=>!e||void 0===r||("isData"in e?e.isData(r):e(r))?r:(()=>{throw"getErrorMessages"in e?e.getErrorMessages(r):void 0})())(y)),k=e.createEvent(),E=k.filterMap((({status:e,key:r,keyPrefix:t,operation:a,value:o})=>"done"===e?{key:r,keyPrefix:t,operation:a,value:o}:void 0)),x=k.filterMap((({status:e,key:r,keyPrefix:t,operation:a,error:o,value:i})=>"fail"===e?{key:r,keyPrefix:t,operation:a,error:o,value:i}:void 0)),M=e.createEvent(),D=o;r.updates.watch((()=>{D=(r=>{try{return e.scopeBind(r,{safe:!0})}catch(e){return r}})(o)})),e.sample({source:c,clock:l,target:M}),e.guard({source:e.sample(w,M,((e,r)=>[r,e])),filter:([e,r])=>e!==r,target:i.prepend((([e])=>e))}),e.sample({clock:[o.doneData,i],target:w}),e.sample({clock:[o.doneData,w],target:s}),e.sample({clock:s.doneData,target:n}),e.sample({clock:[o.finally.map(P("get")),i.finally.map(P("set")),s.fail.map(P("validate"))],target:k}),u&&e.sample({clock:k,target:u}),f&&e.sample({clock:E,target:f}),e.sample({clock:x,target:d}),g&&r.on(g,(([e],r)=>[void 0===r?e:r])),p?(e.sample({clock:p,fn:()=>{},target:o}),r.on(p,(([e],r)=>[void 0===r?e:r]))):o()})),x.unsubscribe=x};
2
2
  //# sourceMappingURL=index.cjs.map
@@ -2,7 +2,7 @@ import { Unit, Store, Event, Effect, Subscription } from 'effector'
2
2
 
3
3
  interface StorageAdapter {
4
4
  <State>(key: string, update: (raw?: any) => any): {
5
- get(raw?: any, ctx?: any): State | Promise<State>
5
+ get(raw?: any, ctx?: any): State | Promise<State | undefined> | undefined
6
6
  set(value: State, ctx?: any): void
7
7
  }
8
8
  keyArea?: any