effector-storage 6.0.0 → 6.0.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.
Files changed (55) hide show
  1. package/README.md +24 -15
  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/core/index.cjs.d.ts +1 -1
  6. package/core/index.d.ts +1 -1
  7. package/core/index.js.flow +1 -1
  8. package/index.cjs.d.ts +2 -1
  9. package/index.cjs.map +1 -1
  10. package/index.d.ts +2 -1
  11. package/index.js.flow +2 -1
  12. package/index.js.map +1 -1
  13. package/local/index.cjs.d.ts +10 -5
  14. package/local/index.cjs.map +1 -1
  15. package/local/index.d.ts +10 -5
  16. package/local/index.js.flow +14 -5
  17. package/local/index.js.map +1 -1
  18. package/log/index.cjs.d.ts +1 -1
  19. package/log/index.d.ts +1 -1
  20. package/log/index.js.flow +1 -1
  21. package/memory/index.cjs.d.ts +12 -7
  22. package/memory/index.cjs.map +1 -1
  23. package/memory/index.d.ts +12 -7
  24. package/memory/index.js.flow +19 -10
  25. package/memory/index.js.map +1 -1
  26. package/nil/index.cjs.d.ts +1 -1
  27. package/nil/index.d.ts +1 -1
  28. package/nil/index.js.flow +1 -1
  29. package/package.json +1 -1
  30. package/query/index.cjs.d.ts +10 -5
  31. package/query/index.cjs.map +1 -1
  32. package/query/index.d.ts +10 -5
  33. package/query/index.js.flow +14 -5
  34. package/query/index.js.map +1 -1
  35. package/rn/async/index.cjs.d.ts +10 -5
  36. package/rn/async/index.cjs.map +1 -1
  37. package/rn/async/index.d.ts +10 -5
  38. package/rn/async/index.js.flow +14 -5
  39. package/rn/async/index.js.map +1 -1
  40. package/rn/encrypted/index.cjs.d.ts +15 -5
  41. package/rn/encrypted/index.cjs.map +1 -1
  42. package/rn/encrypted/index.d.ts +15 -5
  43. package/rn/encrypted/index.js.flow +19 -5
  44. package/rn/encrypted/index.js.map +1 -1
  45. package/session/index.cjs.d.ts +10 -5
  46. package/session/index.cjs.map +1 -1
  47. package/session/index.d.ts +10 -5
  48. package/session/index.js.flow +14 -5
  49. package/session/index.js.map +1 -1
  50. package/storage/index.cjs.d.ts +1 -1
  51. package/storage/index.d.ts +1 -1
  52. package/storage/index.js.flow +1 -1
  53. package/tools/index.cjs.d.ts +1 -1
  54. package/tools/index.d.ts +1 -1
  55. package/tools/index.js.flow +1 -1
@@ -11,13 +11,17 @@ declare interface StorageAdapter {
11
11
  key: string,
12
12
  update: (raw?: any) => any
13
13
  ): {
14
- get(raw?: any, ctx?: any): State | Promise<State>,
14
+ get(raw?: any, ctx?: any): State | Promise<State | void> | void,
15
15
  set(value: State, ctx?: any): void,
16
16
  ...
17
17
  };
18
18
  keyArea?: any;
19
19
  noop?: boolean;
20
20
  }
21
+ declare interface StorageAdapterFactory<AdapterConfig> {
22
+ (config?: AdapterConfig): StorageAdapter;
23
+ factory: true;
24
+ }
21
25
  declare type Contract<Data> =
22
26
  | ((raw: mixed) => boolean)
23
27
  | {
@@ -79,6 +83,16 @@ declare interface ConfigJustSourceTarget<State> {
79
83
  source: Store<State> | Event<State> | Effect<State, any, any>;
80
84
  target: Store<State> | Event<State> | Effect<State, any, any>;
81
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>
82
96
  declare type ConfigPersist = { ... } & ConfigPersist$1
83
97
  declare interface EncryptedStorageConfig {
84
98
  serialize?: (value: any) => string;
@@ -87,13 +101,11 @@ declare interface EncryptedStorageConfig {
87
101
  declare type ConfigStore<State, Err = Error> = {
88
102
  ...
89
103
  } & EncryptedStorageConfig &
90
- ConfigCommon<State, Err> &
91
- ConfigJustStore<State>
104
+ ConfigStore$1<State, Err>
92
105
  declare type ConfigSourceTarget<State, Err = Error> = {
93
106
  ...
94
107
  } & EncryptedStorageConfig &
95
- ConfigCommon<State, Err> &
96
- ConfigJustSourceTarget<State>
108
+ ConfigSourceTarget$1<State, Err>
97
109
  declare interface Persist {
98
110
  <State, Err>(config: ConfigSourceTarget<State, Err>): Subscription;
99
111
  <State, Err>(config: ConfigStore<State, Err>): Subscription;
@@ -111,12 +123,14 @@ declare export {
111
123
  ConfigPersist,
112
124
  ConfigSourceTarget,
113
125
  ConfigStore,
126
+ Contract,
114
127
  Done,
115
128
  EncryptedStorageConfig,
116
129
  Fail,
117
130
  Finally,
118
131
  Persist,
119
132
  StorageAdapter,
133
+ StorageAdapterFactory,
120
134
  createPersist,
121
135
  encrypted,
122
136
  persist,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/rn/encrypted/index.ts"],"sourcesContent":["import type { Subscription } from 'effector'\nimport type {\n ConfigPersist as BaseConfigPersist,\n ConfigCommon,\n ConfigJustStore,\n ConfigJustSourceTarget,\n StorageAdapter,\n} from '../../types'\nimport { persist as base } from '../../core'\nimport { asyncStorage } from '../../async-storage'\nimport EncryptedStorage from 'react-native-encrypted-storage'\n\nexport type { Done, Fail, Finally, StorageAdapter } from '../../types'\n\nexport interface ConfigPersist extends BaseConfigPersist {}\n\nexport interface EncryptedStorageConfig {\n serialize?: (value: any) => string\n deserialize?: (value: string) => any\n}\n\nexport interface ConfigStore<State, Err = Error>\n extends EncryptedStorageConfig,\n ConfigCommon<State, Err>,\n ConfigJustStore<State> {}\n\nexport interface ConfigSourceTarget<State, Err = Error>\n extends EncryptedStorageConfig,\n ConfigCommon<State, Err>,\n ConfigJustSourceTarget<State> {}\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 * Creates `EncryptedStorage` adapter\n */\nencrypted.factory = true as const\nexport function encrypted(config?: EncryptedStorageConfig): StorageAdapter {\n return asyncStorage({\n storage: () => EncryptedStorage,\n ...config,\n })\n}\n\n/**\n * Creates custom partially applied `persist`\n * with predefined `EncryptedStorage` adapter\n */\nexport function createPersist(defaults?: ConfigPersist): Persist {\n return (config) =>\n base({\n adapter: encrypted,\n ...defaults,\n ...config,\n })\n}\n\n/**\n * Default partially applied `persist`\n */\nexport const persist = createPersist()\n"],"names":["encrypted","config","asyncStorage","storage","EncryptedStorage","createPersist","defaults","base","adapter","factory","persist"],"mappings":"wJAwCO,SAASA,EAAUC,GACxB,OAAOC,EAAa,CAClBC,QAASA,IAAMC,KACZH,GAEP,CAMO,SAASI,EAAcC,GAC5B,OAAQL,GACNM,EAAK,CACHC,QAASR,KACNM,KACAL,GAET,CAnBAD,EAAUS,SAAU,EAwBPC,IAAAA,EAAUL"}
1
+ {"version":3,"file":"index.js","sources":["../../../src/rn/encrypted/index.ts"],"sourcesContent":["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 { persist as base } from '../../core'\nimport { asyncStorage } from '../../async-storage'\nimport EncryptedStorage from 'react-native-encrypted-storage'\n\nexport type {\n Contract,\n Done,\n Fail,\n Finally,\n StorageAdapter,\n StorageAdapterFactory,\n} from '../../types'\n\nexport interface ConfigPersist extends BaseConfigPersist {}\n\nexport interface EncryptedStorageConfig {\n serialize?: (value: any) => string\n deserialize?: (value: string) => any\n}\n\nexport interface ConfigStore<State, Err = Error>\n extends EncryptedStorageConfig,\n BaseConfigStore<State, Err> {}\n\nexport interface ConfigSourceTarget<State, Err = Error>\n extends EncryptedStorageConfig,\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 * Creates `EncryptedStorage` adapter\n */\nencrypted.factory = true as const\nexport function encrypted(config?: EncryptedStorageConfig): StorageAdapter {\n return asyncStorage({\n storage: () => EncryptedStorage,\n ...config,\n })\n}\n\n/**\n * Creates custom partially applied `persist`\n * with predefined `EncryptedStorage` adapter\n */\nexport function createPersist(defaults?: ConfigPersist): Persist {\n return (config) =>\n base({\n adapter: encrypted,\n ...defaults,\n ...config,\n })\n}\n\n/**\n * Default partially applied `persist`\n */\nexport const persist = createPersist()\n"],"names":["encrypted","config","asyncStorage","storage","EncryptedStorage","createPersist","defaults","base","adapter","factory","persist"],"mappings":"wJA4CO,SAASA,EAAUC,GACxB,OAAOC,EAAa,CAClBC,QAASA,IAAMC,KACZH,GAEP,CAMO,SAASI,EAAcC,GAC5B,OAAQL,GACNM,EAAK,CACHC,QAASR,KACNM,KACAL,GAET,CAnBAD,EAAUS,SAAU,EAwBPC,IAAAA,EAAUL"}
@@ -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
@@ -62,6 +62,12 @@ interface ConfigJustSourceTarget<State> {
62
62
  source: Store<State> | Event<State> | Effect<State, any, any>
63
63
  target: Store<State> | Event<State> | Effect<State, any, any>
64
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> {}
65
71
 
66
72
  interface ConfigPersist extends ConfigPersist$1 {
67
73
  sync?: boolean | 'force'
@@ -76,12 +82,10 @@ interface SessionStorageConfig {
76
82
  }
77
83
  interface ConfigStore<State, Err = Error>
78
84
  extends SessionStorageConfig,
79
- ConfigCommon<State, Err>,
80
- ConfigJustStore<State> {}
85
+ ConfigStore$1<State, Err> {}
81
86
  interface ConfigSourceTarget<State, Err = Error>
82
87
  extends SessionStorageConfig,
83
- ConfigCommon<State, Err>,
84
- ConfigJustSourceTarget<State> {}
88
+ ConfigSourceTarget$1<State, Err> {}
85
89
  interface Persist {
86
90
  <State, Err = Error>(config: ConfigSourceTarget<State, Err>): Subscription
87
91
  <State, Err = Error>(config: ConfigStore<State, Err>): Subscription
@@ -104,6 +108,7 @@ export {
104
108
  ConfigPersist,
105
109
  ConfigSourceTarget,
106
110
  ConfigStore,
111
+ Contract,
107
112
  Done,
108
113
  Fail,
109
114
  Finally,
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/session/index.ts"],"sourcesContent":["import type { Subscription } from 'effector'\nimport type {\n ConfigPersist as BaseConfigPersist,\n ConfigCommon,\n ConfigJustStore,\n ConfigJustSourceTarget,\n StorageAdapter,\n} from '../types'\nimport { persist as base } from '../core'\nimport { nil } from '../nil'\nimport { storage } from '../storage'\n\nexport type {\n Done,\n Fail,\n Finally,\n StorageAdapter,\n StorageAdapterFactory,\n} from '../types'\n\nexport interface ConfigPersist extends BaseConfigPersist {\n sync?: boolean | 'force'\n timeout?: number\n}\n\nexport interface SessionStorageConfig {\n sync?: boolean | 'force'\n serialize?: (value: any) => string\n deserialize?: (value: string) => any\n timeout?: number\n def?: any\n}\n\nexport interface ConfigStore<State, Err = Error>\n extends SessionStorageConfig,\n ConfigCommon<State, Err>,\n ConfigJustStore<State> {}\n\nexport interface ConfigSourceTarget<State, Err = Error>\n extends SessionStorageConfig,\n ConfigCommon<State, Err>,\n ConfigJustSourceTarget<State> {}\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 `sessionStorage` exists\n */\nfunction supports() {\n try {\n return typeof sessionStorage !== 'undefined'\n } catch (error) {\n // accessing `sessionStorage` could throw an exception only in one case -\n // when `sessionStorage` IS supported, but blocked by security policies\n return true\n }\n}\n\n/**\n * Creates `sessionStorage` adapter\n */\nsession.factory = true as const\nexport function session(config?: SessionStorageConfig): StorageAdapter {\n return supports()\n ? storage({\n storage: () => sessionStorage,\n ...config,\n })\n : nil({ keyArea: 'session' })\n}\n\n/**\n * Creates custom partially applied `persist`\n * with predefined `sessionStorage` adapter\n */\nexport function createPersist(defaults?: ConfigPersist): Persist {\n return (config) =>\n base({\n adapter: session,\n ...defaults,\n ...config,\n })\n}\n\n/**\n * Default partially applied `persist`\n */\nexport const persist = createPersist()\n"],"names":["session","config","sessionStorage","error","supports","storage","nil","keyArea","createPersist","defaults","base","adapter","factory","persist"],"mappings":"gHAiEO,SAASA,EAAQC,GACtB,OAfF,WACE,IACE,MAAiC,oBAAnBC,cACf,CAAC,MAAOC,GAGP,OAAO,CACT,CACF,CAOSC,GACHC,UAAQ,CACNA,QAASA,IAAMH,kBACZD,IAELK,EAAAA,IAAI,CAAEC,QAAS,WACrB,CAMO,SAASC,EAAcC,GAC5B,OAAQR,GACNS,EAAAA,QAAK,CACHC,QAASX,KACNS,KACAR,GAET,CArBAD,EAAQY,SAAU,EA0BLC,IAAAA,EAAUL"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/session/index.ts"],"sourcesContent":["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 { persist as base } from '../core'\nimport { nil } from '../nil'\nimport { storage } from '../storage'\n\nexport type {\n Contract,\n Done,\n Fail,\n Finally,\n StorageAdapter,\n StorageAdapterFactory,\n} from '../types'\n\nexport interface ConfigPersist extends BaseConfigPersist {\n sync?: boolean | 'force'\n timeout?: number\n}\n\nexport interface SessionStorageConfig {\n sync?: boolean | 'force'\n serialize?: (value: any) => string\n deserialize?: (value: string) => any\n timeout?: number\n def?: any\n}\n\nexport interface ConfigStore<State, Err = Error>\n extends SessionStorageConfig,\n BaseConfigStore<State, Err> {}\n\nexport interface ConfigSourceTarget<State, Err = Error>\n extends SessionStorageConfig,\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 `sessionStorage` exists\n */\nfunction supports() {\n try {\n return typeof sessionStorage !== 'undefined'\n } catch (error) {\n // accessing `sessionStorage` could throw an exception only in one case -\n // when `sessionStorage` IS supported, but blocked by security policies\n return true\n }\n}\n\n/**\n * Creates `sessionStorage` adapter\n */\nsession.factory = true as const\nexport function session(config?: SessionStorageConfig): StorageAdapter {\n return supports()\n ? storage({\n storage: () => sessionStorage,\n ...config,\n })\n : nil({ keyArea: 'session' })\n}\n\n/**\n * Creates custom partially applied `persist`\n * with predefined `sessionStorage` adapter\n */\nexport function createPersist(defaults?: ConfigPersist): Persist {\n return (config) =>\n base({\n adapter: session,\n ...defaults,\n ...config,\n })\n}\n\n/**\n * Default partially applied `persist`\n */\nexport const persist = createPersist()\n"],"names":["session","config","sessionStorage","error","supports","storage","nil","keyArea","createPersist","defaults","base","adapter","factory","persist"],"mappings":"gHA+DO,SAASA,EAAQC,GACtB,OAfF,WACE,IACE,MAAiC,oBAAnBC,cACf,CAAC,MAAOC,GAGP,OAAO,CACT,CACF,CAOSC,GACHC,UAAQ,CACNA,QAASA,IAAMH,kBACZD,IAELK,EAAAA,IAAI,CAAEC,QAAS,WACrB,CAMO,SAASC,EAAcC,GAC5B,OAAQR,GACNS,EAAAA,QAAK,CACHC,QAASX,KACNS,KACAR,GAET,CArBAD,EAAQY,SAAU,EA0BLC,IAAAA,EAAUL"}
@@ -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
@@ -62,6 +62,12 @@ interface ConfigJustSourceTarget<State> {
62
62
  source: Store<State> | Event<State> | Effect<State, any, any>
63
63
  target: Store<State> | Event<State> | Effect<State, any, any>
64
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> {}
65
71
 
66
72
  interface ConfigPersist extends ConfigPersist$1 {
67
73
  sync?: boolean | 'force'
@@ -76,12 +82,10 @@ interface SessionStorageConfig {
76
82
  }
77
83
  interface ConfigStore<State, Err = Error>
78
84
  extends SessionStorageConfig,
79
- ConfigCommon<State, Err>,
80
- ConfigJustStore<State> {}
85
+ ConfigStore$1<State, Err> {}
81
86
  interface ConfigSourceTarget<State, Err = Error>
82
87
  extends SessionStorageConfig,
83
- ConfigCommon<State, Err>,
84
- ConfigJustSourceTarget<State> {}
88
+ ConfigSourceTarget$1<State, Err> {}
85
89
  interface Persist {
86
90
  <State, Err = Error>(config: ConfigSourceTarget<State, Err>): Subscription
87
91
  <State, Err = Error>(config: ConfigStore<State, Err>): Subscription
@@ -104,6 +108,7 @@ export {
104
108
  ConfigPersist,
105
109
  ConfigSourceTarget,
106
110
  ConfigStore,
111
+ Contract,
107
112
  Done,
108
113
  Fail,
109
114
  Finally,
@@ -11,7 +11,7 @@ declare interface StorageAdapter {
11
11
  key: string,
12
12
  update: (raw?: any) => any
13
13
  ): {
14
- get(raw?: any, ctx?: any): State | Promise<State>,
14
+ get(raw?: any, ctx?: any): State | Promise<State | void> | void,
15
15
  set(value: State, ctx?: any): void,
16
16
  ...
17
17
  };
@@ -83,6 +83,16 @@ declare interface ConfigJustSourceTarget<State> {
83
83
  source: Store<State> | Event<State> | Effect<State, any, any>;
84
84
  target: Store<State> | Event<State> | Effect<State, any, any>;
85
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>
86
96
  declare type ConfigPersist = {
87
97
  sync?: boolean | 'force',
88
98
  timeout?: number,
@@ -96,13 +106,11 @@ declare interface SessionStorageConfig {
96
106
  def?: any;
97
107
  }
98
108
  declare type ConfigStore<State, Err = Error> = { ... } & SessionStorageConfig &
99
- ConfigCommon<State, Err> &
100
- ConfigJustStore<State>
109
+ ConfigStore$1<State, Err>
101
110
  declare type ConfigSourceTarget<State, Err = Error> = {
102
111
  ...
103
112
  } & SessionStorageConfig &
104
- ConfigCommon<State, Err> &
105
- ConfigJustSourceTarget<State>
113
+ ConfigSourceTarget$1<State, Err>
106
114
  declare interface Persist {
107
115
  <State, Err>(config: ConfigSourceTarget<State, Err>): Subscription;
108
116
  <State, Err>(config: ConfigStore<State, Err>): Subscription;
@@ -120,6 +128,7 @@ declare export {
120
128
  ConfigPersist,
121
129
  ConfigSourceTarget,
122
130
  ConfigStore,
131
+ Contract,
123
132
  Done,
124
133
  Fail,
125
134
  Finally,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/session/index.ts"],"sourcesContent":["import type { Subscription } from 'effector'\nimport type {\n ConfigPersist as BaseConfigPersist,\n ConfigCommon,\n ConfigJustStore,\n ConfigJustSourceTarget,\n StorageAdapter,\n} from '../types'\nimport { persist as base } from '../core'\nimport { nil } from '../nil'\nimport { storage } from '../storage'\n\nexport type {\n Done,\n Fail,\n Finally,\n StorageAdapter,\n StorageAdapterFactory,\n} from '../types'\n\nexport interface ConfigPersist extends BaseConfigPersist {\n sync?: boolean | 'force'\n timeout?: number\n}\n\nexport interface SessionStorageConfig {\n sync?: boolean | 'force'\n serialize?: (value: any) => string\n deserialize?: (value: string) => any\n timeout?: number\n def?: any\n}\n\nexport interface ConfigStore<State, Err = Error>\n extends SessionStorageConfig,\n ConfigCommon<State, Err>,\n ConfigJustStore<State> {}\n\nexport interface ConfigSourceTarget<State, Err = Error>\n extends SessionStorageConfig,\n ConfigCommon<State, Err>,\n ConfigJustSourceTarget<State> {}\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 `sessionStorage` exists\n */\nfunction supports() {\n try {\n return typeof sessionStorage !== 'undefined'\n } catch (error) {\n // accessing `sessionStorage` could throw an exception only in one case -\n // when `sessionStorage` IS supported, but blocked by security policies\n return true\n }\n}\n\n/**\n * Creates `sessionStorage` adapter\n */\nsession.factory = true as const\nexport function session(config?: SessionStorageConfig): StorageAdapter {\n return supports()\n ? storage({\n storage: () => sessionStorage,\n ...config,\n })\n : nil({ keyArea: 'session' })\n}\n\n/**\n * Creates custom partially applied `persist`\n * with predefined `sessionStorage` adapter\n */\nexport function createPersist(defaults?: ConfigPersist): Persist {\n return (config) =>\n base({\n adapter: session,\n ...defaults,\n ...config,\n })\n}\n\n/**\n * Default partially applied `persist`\n */\nexport const persist = createPersist()\n"],"names":["session","config","sessionStorage","error","supports","storage","nil","keyArea","createPersist","defaults","base","adapter","factory","persist"],"mappings":"+HAiEO,SAASA,EAAQC,GACtB,OAfF,WACE,IACE,MAAiC,oBAAnBC,cACf,CAAC,MAAOC,GAGP,OAAO,CACT,CACF,CAOSC,GACHC,EAAQ,CACNA,QAASA,IAAMH,kBACZD,IAELK,EAAI,CAAEC,QAAS,WACrB,CAMO,SAASC,EAAcC,GAC5B,OAAQR,GACNS,EAAK,CACHC,QAASX,KACNS,KACAR,GAET,CArBAD,EAAQY,SAAU,EA0BLC,IAAAA,EAAUL"}
1
+ {"version":3,"file":"index.js","sources":["../../src/session/index.ts"],"sourcesContent":["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 { persist as base } from '../core'\nimport { nil } from '../nil'\nimport { storage } from '../storage'\n\nexport type {\n Contract,\n Done,\n Fail,\n Finally,\n StorageAdapter,\n StorageAdapterFactory,\n} from '../types'\n\nexport interface ConfigPersist extends BaseConfigPersist {\n sync?: boolean | 'force'\n timeout?: number\n}\n\nexport interface SessionStorageConfig {\n sync?: boolean | 'force'\n serialize?: (value: any) => string\n deserialize?: (value: string) => any\n timeout?: number\n def?: any\n}\n\nexport interface ConfigStore<State, Err = Error>\n extends SessionStorageConfig,\n BaseConfigStore<State, Err> {}\n\nexport interface ConfigSourceTarget<State, Err = Error>\n extends SessionStorageConfig,\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 `sessionStorage` exists\n */\nfunction supports() {\n try {\n return typeof sessionStorage !== 'undefined'\n } catch (error) {\n // accessing `sessionStorage` could throw an exception only in one case -\n // when `sessionStorage` IS supported, but blocked by security policies\n return true\n }\n}\n\n/**\n * Creates `sessionStorage` adapter\n */\nsession.factory = true as const\nexport function session(config?: SessionStorageConfig): StorageAdapter {\n return supports()\n ? storage({\n storage: () => sessionStorage,\n ...config,\n })\n : nil({ keyArea: 'session' })\n}\n\n/**\n * Creates custom partially applied `persist`\n * with predefined `sessionStorage` adapter\n */\nexport function createPersist(defaults?: ConfigPersist): Persist {\n return (config) =>\n base({\n adapter: session,\n ...defaults,\n ...config,\n })\n}\n\n/**\n * Default partially applied `persist`\n */\nexport const persist = createPersist()\n"],"names":["session","config","sessionStorage","error","supports","storage","nil","keyArea","createPersist","defaults","base","adapter","factory","persist"],"mappings":"+HA+DO,SAASA,EAAQC,GACtB,OAfF,WACE,IACE,MAAiC,oBAAnBC,cACf,CAAC,MAAOC,GAGP,OAAO,CACT,CACF,CAOSC,GACHC,EAAQ,CACNA,QAASA,IAAMH,kBACZD,IAELK,EAAI,CAAEC,QAAS,WACrB,CAMO,SAASC,EAAcC,GAC5B,OAAQR,GACNS,EAAK,CACHC,QAASX,KACNS,KACAR,GAET,CArBAD,EAAQY,SAAU,EA0BLC,IAAAA,EAAUL"}
@@ -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
  };
@@ -2,7 +2,7 @@ import { Store, Effect, Event } 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
package/tools/index.d.ts CHANGED
@@ -2,7 +2,7 @@ import { Store, Effect, Event } 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
@@ -24,7 +24,7 @@ declare interface StorageAdapter {
24
24
  key: string,
25
25
  update: (raw?: any) => any
26
26
  ): {
27
- get(raw?: any, ctx?: any): State | Promise<State>,
27
+ get(raw?: any, ctx?: any): State | Promise<State | void> | void,
28
28
  set(value: State, ctx?: any): void,
29
29
  ...
30
30
  };