effector-storage 6.1.0 → 7.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.
Files changed (94) hide show
  1. package/README.md +7 -40
  2. package/async-storage/index.cjs.map +1 -1
  3. package/async-storage/index.d.cts +24 -0
  4. package/async-storage/index.d.ts +14 -18
  5. package/async-storage/index.js.flow +6 -5
  6. package/async-storage/index.js.map +1 -1
  7. package/async-storage/package.json +15 -2
  8. package/broadcast/index.cjs.map +1 -1
  9. package/broadcast/index.d.cts +94 -0
  10. package/broadcast/index.d.ts +63 -85
  11. package/broadcast/index.js.flow +23 -25
  12. package/broadcast/index.js.map +1 -1
  13. package/broadcast/package.json +15 -2
  14. package/core/index.cjs +1 -1
  15. package/core/index.cjs.map +1 -1
  16. package/core/index.d.cts +77 -0
  17. package/core/index.d.ts +53 -66
  18. package/core/index.js +1 -1
  19. package/core/index.js.flow +14 -14
  20. package/core/index.js.map +1 -1
  21. package/core/package.json +15 -2
  22. package/index.d.cts +97 -0
  23. package/index.d.ts +68 -99
  24. package/index.js.flow +27 -28
  25. package/local/index.d.cts +99 -0
  26. package/local/index.d.ts +67 -90
  27. package/local/index.js.flow +25 -27
  28. package/local/package.json +15 -2
  29. package/log/index.cjs.map +1 -1
  30. package/log/index.d.cts +19 -0
  31. package/log/index.d.ts +11 -11
  32. package/log/index.js.flow +6 -5
  33. package/log/index.js.map +1 -1
  34. package/log/package.json +15 -2
  35. package/memory/index.d.cts +95 -0
  36. package/memory/index.d.ts +63 -82
  37. package/memory/index.js.flow +23 -25
  38. package/memory/package.json +15 -2
  39. package/nil/index.cjs.map +1 -1
  40. package/nil/index.d.cts +18 -0
  41. package/nil/index.d.ts +10 -10
  42. package/nil/index.js.flow +6 -5
  43. package/nil/index.js.map +1 -1
  44. package/nil/package.json +15 -2
  45. package/package.json +101 -57
  46. package/query/index.cjs.map +1 -1
  47. package/query/index.d.cts +108 -0
  48. package/query/index.d.ts +75 -104
  49. package/query/index.js.flow +30 -28
  50. package/query/index.js.map +1 -1
  51. package/query/package.json +15 -2
  52. package/session/index.d.cts +99 -0
  53. package/session/index.d.ts +67 -90
  54. package/session/index.js.flow +25 -27
  55. package/session/package.json +15 -2
  56. package/storage/index.cjs.map +1 -1
  57. package/storage/index.d.cts +23 -0
  58. package/storage/index.d.ts +15 -22
  59. package/storage/index.js.flow +7 -6
  60. package/storage/index.js.map +1 -1
  61. package/storage/package.json +15 -2
  62. package/tools/index.cjs.map +1 -1
  63. package/tools/{index.cjs.d.ts → index.d.cts} +33 -58
  64. package/tools/index.d.ts +33 -58
  65. package/tools/index.js.flow +13 -10
  66. package/tools/index.js.map +1 -1
  67. package/tools/package.json +15 -2
  68. package/async-storage/index.cjs.d.ts +0 -28
  69. package/broadcast/index.cjs.d.ts +0 -116
  70. package/core/index.cjs.d.ts +0 -90
  71. package/index.cjs.d.ts +0 -128
  72. package/local/index.cjs.d.ts +0 -122
  73. package/log/index.cjs.d.ts +0 -19
  74. package/memory/index.cjs.d.ts +0 -114
  75. package/nil/index.cjs.d.ts +0 -18
  76. package/query/index.cjs.d.ts +0 -137
  77. package/rn/async/index.cjs +0 -2
  78. package/rn/async/index.cjs.d.ts +0 -120
  79. package/rn/async/index.cjs.map +0 -1
  80. package/rn/async/index.d.ts +0 -120
  81. package/rn/async/index.js +0 -2
  82. package/rn/async/index.js.flow +0 -135
  83. package/rn/async/index.js.map +0 -1
  84. package/rn/async/package.json +0 -8
  85. package/rn/encrypted/index.cjs +0 -2
  86. package/rn/encrypted/index.cjs.d.ts +0 -120
  87. package/rn/encrypted/index.cjs.map +0 -1
  88. package/rn/encrypted/index.d.ts +0 -120
  89. package/rn/encrypted/index.js +0 -2
  90. package/rn/encrypted/index.js.flow +0 -137
  91. package/rn/encrypted/index.js.map +0 -1
  92. package/rn/encrypted/package.json +0 -8
  93. package/session/index.cjs.d.ts +0 -122
  94. package/storage/index.cjs.d.ts +0 -30
package/query/index.d.ts CHANGED
@@ -1,137 +1,108 @@
1
- import { Unit, Store, Event, Effect, Subscription } from 'effector'
1
+ import { Unit, Store, Event, Effect, Subscription } from 'effector';
2
2
 
3
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
4
+ <State>(key: string, update: (raw?: any) => void): {
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
10
  }
11
11
  interface StorageAdapterFactory<AdapterConfig> {
12
- (config?: AdapterConfig): StorageAdapter
13
- factory: true
12
+ (config?: AdapterConfig): StorageAdapter;
13
+ factory: true;
14
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
- }
15
+ type Contract<Data> = ((raw: unknown) => raw is Data) | {
16
+ isData: (raw: unknown) => raw is Data;
17
+ getErrorMessages: (raw: unknown) => string[];
18
+ };
21
19
  type Done<State> = {
22
- key: string
23
- keyPrefix: string
24
- operation: 'set' | 'get'
25
- value: State
26
- }
20
+ key: string;
21
+ keyPrefix: string;
22
+ operation: 'set' | 'get';
23
+ value: State;
24
+ };
27
25
  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
- })
26
+ key: string;
27
+ keyPrefix: string;
28
+ operation: 'set' | 'get';
29
+ error: Err;
30
+ value?: any;
31
+ };
32
+ type Finally<State, Err> = (Done<State> & {
33
+ status: 'done';
34
+ }) | (Fail<Err> & {
35
+ status: 'fail';
36
+ });
41
37
  interface ConfigPersist$1 {
42
- pickup?: Unit<any>
43
- context?: Unit<any>
44
- keyPrefix?: string
45
- contract?: Contract<any>
38
+ pickup?: Unit<any>;
39
+ context?: Unit<any>;
40
+ keyPrefix?: string;
41
+ contract?: Contract<any>;
46
42
  }
47
43
  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>
44
+ clock?: Unit<any>;
45
+ done?: Unit<Done<State>>;
46
+ fail?: Unit<Fail<Err>>;
47
+ finally?: Unit<Finally<State, Err>>;
48
+ pickup?: Unit<any>;
49
+ context?: Unit<any>;
50
+ key?: string;
51
+ keyPrefix?: string;
52
+ contract?: Contract<State | undefined>;
57
53
  }
58
54
  interface ConfigJustStore<State> {
59
- store: Store<State>
55
+ store: Store<State>;
60
56
  }
61
57
  interface ConfigJustSourceTarget<State> {
62
- source: Store<State> | Event<State> | Effect<State, any, any>
63
- target: Store<State> | Event<State> | Effect<State, any, any>
58
+ source: Store<State> | Event<State> | Effect<State, any, any>;
59
+ target: Store<State> | Event<State> | Effect<State, any, any>;
60
+ }
61
+ interface ConfigStore$1<State, Err = Error> extends ConfigCommon<State, Err>, ConfigJustStore<State> {
62
+ }
63
+ interface ConfigSourceTarget$1<State, Err = Error> extends ConfigCommon<State, Err>, ConfigJustSourceTarget<State> {
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> {}
71
65
 
72
- type ChangeMethod = (params: URLSearchParams | string, erase?: boolean) => void
73
- type StateBehavior = 'keep' | 'erase'
66
+ type ChangeMethod = (params: URLSearchParams | string, erase?: boolean) => void;
67
+ type StateBehavior = 'keep' | 'erase';
74
68
  interface QueryConfig {
75
- method?: ChangeMethod
76
- state?: StateBehavior
77
- serialize?: (value: any) => string
78
- deserialize?: (value: string) => any
79
- timeout?: number
80
- def?: any
69
+ method?: ChangeMethod;
70
+ state?: StateBehavior;
71
+ serialize?: (value: any) => string;
72
+ deserialize?: (value: string) => any;
73
+ timeout?: number;
74
+ def?: any;
81
75
  }
82
- declare const pushState: ChangeMethod
83
- declare const replaceState: ChangeMethod
84
- declare const locationAssign: ChangeMethod
85
- declare const locationReplace: ChangeMethod
76
+ declare const pushState: ChangeMethod;
77
+ declare const replaceState: ChangeMethod;
78
+ declare const locationAssign: ChangeMethod;
79
+ declare const locationReplace: ChangeMethod;
86
80
 
87
81
  interface ConfigPersist extends ConfigPersist$1 {
88
- method?: ChangeMethod
89
- state?: StateBehavior
90
- timeout?: number
82
+ method?: ChangeMethod;
83
+ state?: StateBehavior;
84
+ timeout?: number;
85
+ }
86
+ interface ConfigStore<State, Err = Error> extends QueryConfig, ConfigStore$1<State, Err> {
87
+ }
88
+ interface ConfigSourceTarget<State, Err = Error> extends QueryConfig, ConfigSourceTarget$1<State, Err> {
91
89
  }
92
- interface ConfigStore<State, Err = Error>
93
- extends QueryConfig,
94
- ConfigStore$1<State, Err> {}
95
- interface ConfigSourceTarget<State, Err = Error>
96
- extends QueryConfig,
97
- ConfigSourceTarget$1<State, Err> {}
98
90
  interface Persist {
99
- <State, Err = Error>(config: ConfigSourceTarget<State, Err>): Subscription
100
- <State, Err = Error>(config: ConfigStore<State, Err>): Subscription
91
+ <State, Err = Error>(config: ConfigSourceTarget<State, Err>): Subscription;
92
+ <State, Err = Error>(config: ConfigStore<State, Err>): Subscription;
101
93
  }
102
- declare function query(config?: QueryConfig): StorageAdapter
94
+ declare function query(config?: QueryConfig): StorageAdapter;
103
95
  declare namespace query {
104
- var factory: true
96
+ var factory: true;
105
97
  }
106
98
  /**
107
99
  * Creates custom partially applied `persist`
108
100
  * with predefined `query` adapter
109
101
  */
110
- declare function createPersist(defaults?: ConfigPersist): Persist
102
+ declare function createPersist(defaults?: ConfigPersist): Persist;
111
103
  /**
112
104
  * Default partially applied `persist`
113
105
  */
114
- declare const persist: Persist
106
+ declare const persist: Persist;
115
107
 
116
- export {
117
- ChangeMethod,
118
- ConfigPersist,
119
- ConfigSourceTarget,
120
- ConfigStore,
121
- Contract,
122
- Done,
123
- Fail,
124
- Finally,
125
- Persist,
126
- QueryConfig,
127
- StateBehavior,
128
- StorageAdapter,
129
- StorageAdapterFactory,
130
- createPersist,
131
- locationAssign,
132
- locationReplace,
133
- persist,
134
- pushState,
135
- query,
136
- replaceState,
137
- }
108
+ export { type ChangeMethod, type ConfigPersist, type ConfigSourceTarget, type ConfigStore, type Contract, type Done, type Fail, type Finally, type Persist, type QueryConfig, type StateBehavior, type StorageAdapter, type StorageAdapterFactory, createPersist, locationAssign, locationReplace, persist, pushState, query, replaceState };
@@ -5,11 +5,11 @@
5
5
  * @flow
6
6
  */
7
7
 
8
- import { Unit, Store, Event, Effect, Subscription } from 'effector'
8
+ import { Unit, Store, Event, Effect, Subscription } from "effector";
9
9
  declare interface StorageAdapter {
10
10
  <State>(
11
11
  key: string,
12
- update: (raw?: any) => any
12
+ update: (raw?: any) => void
13
13
  ): {
14
14
  get(raw?: any, ctx?: any): State | Promise<State | void> | void,
15
15
  set(value: State, ctx?: any): void,
@@ -28,37 +28,37 @@ declare type Contract<Data> =
28
28
  isData: (raw: mixed) => boolean,
29
29
  getErrorMessages: (raw: mixed) => string[],
30
30
  ...
31
- }
31
+ };
32
32
  declare type Done<State> = {
33
33
  key: string,
34
34
  keyPrefix: string,
35
- operation: 'set' | 'get',
35
+ operation: "set" | "get",
36
36
  value: State,
37
37
  ...
38
- }
38
+ };
39
39
  declare type Fail<Err> = {
40
40
  key: string,
41
41
  keyPrefix: string,
42
- operation: 'set' | 'get',
42
+ operation: "set" | "get",
43
43
  error: Err,
44
44
  value?: any,
45
45
  ...
46
- }
46
+ };
47
47
  declare type Finally<State, Err> =
48
48
  | {
49
49
  ...Done<State>,
50
50
  ...{
51
- status: 'done',
51
+ status: "done",
52
52
  ...
53
53
  },
54
54
  }
55
55
  | {
56
56
  ...Fail<Err>,
57
57
  ...{
58
- status: 'fail',
58
+ status: "fail",
59
59
  ...
60
60
  },
61
- }
61
+ };
62
62
  declare interface ConfigPersist$1 {
63
63
  pickup?: Unit<any>;
64
64
  context?: Unit<any>;
@@ -87,17 +87,17 @@ declare type ConfigStore$1<State, Err = Error> = { ... } & ConfigCommon<
87
87
  State,
88
88
  Err
89
89
  > &
90
- ConfigJustStore<State>
90
+ ConfigJustStore<State>;
91
91
  declare type ConfigSourceTarget$1<State, Err = Error> = { ... } & ConfigCommon<
92
92
  State,
93
93
  Err
94
94
  > &
95
- ConfigJustSourceTarget<State>
95
+ ConfigJustSourceTarget<State>;
96
96
  declare type ChangeMethod = (
97
97
  params: URLSearchParams | string,
98
98
  erase?: boolean
99
- ) => void
100
- declare type StateBehavior = 'keep' | 'erase'
99
+ ) => void;
100
+ declare type StateBehavior = "keep" | "erase";
101
101
  declare interface QueryConfig {
102
102
  method?: ChangeMethod;
103
103
  state?: StateBehavior;
@@ -106,34 +106,34 @@ declare interface QueryConfig {
106
106
  timeout?: number;
107
107
  def?: any;
108
108
  }
109
- declare var pushState: ChangeMethod
110
- declare var replaceState: ChangeMethod
111
- declare var locationAssign: ChangeMethod
112
- declare var locationReplace: ChangeMethod
109
+ declare var pushState: ChangeMethod;
110
+ declare var replaceState: ChangeMethod;
111
+ declare var locationAssign: ChangeMethod;
112
+ declare var locationReplace: ChangeMethod;
113
113
  declare type ConfigPersist = {
114
114
  method?: ChangeMethod,
115
115
  state?: StateBehavior,
116
116
  timeout?: number,
117
117
  ...
118
- } & ConfigPersist$1
118
+ } & ConfigPersist$1;
119
119
  declare type ConfigStore<State, Err = Error> = { ... } & QueryConfig &
120
- ConfigStore$1<State, Err>
120
+ ConfigStore$1<State, Err>;
121
121
  declare type ConfigSourceTarget<State, Err = Error> = { ... } & QueryConfig &
122
- ConfigSourceTarget$1<State, Err>
122
+ ConfigSourceTarget$1<State, Err>;
123
123
  declare interface Persist {
124
124
  <State, Err>(config: ConfigSourceTarget<State, Err>): Subscription;
125
125
  <State, Err>(config: ConfigStore<State, Err>): Subscription;
126
126
  }
127
- declare var query: typeof npm$namespace$query
127
+ declare var query: typeof npm$namespace$query;
128
128
 
129
129
  declare var npm$namespace$query: {|
130
130
  (config?: QueryConfig): StorageAdapter,
131
131
  factory: typeof query$factory,
132
- |}
133
- declare var query$factory: true
134
- declare function createPersist(defaults?: ConfigPersist): Persist
135
- declare var persist: Persist
136
- declare export {
132
+ |};
133
+ declare var query$factory: true;
134
+ declare function createPersist(defaults?: ConfigPersist): Persist;
135
+ declare var persist: Persist;
136
+ export type {
137
137
  ChangeMethod,
138
138
  ConfigPersist,
139
139
  ConfigSourceTarget,
@@ -147,6 +147,8 @@ declare export {
147
147
  StateBehavior,
148
148
  StorageAdapter,
149
149
  StorageAdapterFactory,
150
+ };
151
+ declare export {
150
152
  createPersist,
151
153
  locationAssign,
152
154
  locationReplace,
@@ -154,4 +156,4 @@ declare export {
154
156
  pushState,
155
157
  query,
156
158
  replaceState,
157
- }
159
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/query/adapter.ts","../../src/query/index.ts"],"sourcesContent":["import type { StorageAdapter } from '../types'\n\nexport type ChangeMethod = (\n params: URLSearchParams | string,\n erase?: boolean\n) => void\n\nexport type StateBehavior = 'keep' | 'erase'\n\nexport interface QueryConfig {\n method?: ChangeMethod\n state?: StateBehavior\n serialize?: (value: any) => string\n deserialize?: (value: string) => any\n timeout?: number\n def?: any\n}\n\nconst keyArea = Symbol() // eslint-disable-line symbol-description\n\nconst buffer = new Map<string, any>()\nlet timeoutId: ReturnType<typeof setTimeout> | undefined\nlet scheduled: number | undefined\n\n/*\n * Location change methods list\n */\n\nconst url = (params: URLSearchParams | string) =>\n location.pathname +\n (params + '' ? '?' + params : '') +\n (location.hash && location.hash !== '#' ? location.hash : '')\n\nexport const pushState: ChangeMethod = (params, erase): void =>\n history.pushState(erase ? null : history.state, '', url(params))\n\nexport const replaceState: ChangeMethod = (params, erase): void =>\n history.replaceState(erase ? null : history.state, '', url(params))\n\nexport const locationAssign: ChangeMethod = (params): void =>\n location.assign(url(params))\n\nexport const locationReplace: ChangeMethod = (params): void =>\n location.replace(url(params))\n\n/**\n * Flush buffer to actual location search params\n */\nfunction flush(method: ChangeMethod, state?: StateBehavior) {\n scheduled = undefined\n if (buffer.size) {\n const params = new URLSearchParams(location.search)\n for (const [name, value] of buffer.entries()) {\n if (value != null) {\n params.set(name, `${value}`)\n } else {\n params.delete(name)\n }\n }\n buffer.clear()\n method(params, state === 'erase')\n }\n}\n\n/**\n * Query string adapter factory\n */\nexport function adapter({\n method = pushState,\n state,\n serialize,\n deserialize,\n def = null,\n timeout,\n}: QueryConfig): StorageAdapter {\n const adapter: StorageAdapter = <State>(\n key: string,\n update: (raw?: any) => any\n ) => {\n if (typeof addEventListener !== 'undefined') {\n addEventListener('popstate', () => setTimeout(update, 0))\n }\n\n return {\n get() {\n const params = new URLSearchParams(location.search)\n const value = params.get(key)\n return value ? (deserialize ? deserialize(value) : value) : def\n },\n\n set(value: State) {\n buffer.set(key, serialize ? serialize(value) : value)\n\n if (timeout === undefined) {\n clearTimeout(timeoutId)\n return flush(method, state)\n }\n\n const deadline = Date.now() + timeout\n if (scheduled === undefined || scheduled > deadline) {\n clearTimeout(timeoutId)\n scheduled = deadline\n timeoutId = setTimeout(flush, timeout, method, state)\n }\n },\n }\n }\n\n adapter.keyArea = keyArea\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 { ChangeMethod, StateBehavior, QueryConfig } 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 { ChangeMethod, StateBehavior, QueryConfig } from './adapter'\nexport {\n locationAssign,\n locationReplace,\n pushState,\n replaceState,\n} from './adapter'\n\nexport interface ConfigPersist extends BaseConfigPersist {\n method?: ChangeMethod\n state?: StateBehavior\n timeout?: number\n}\n\nexport interface ConfigStore<State, Err = Error>\n extends QueryConfig,\n BaseConfigStore<State, Err> {}\n\nexport interface ConfigSourceTarget<State, Err = Error>\n extends QueryConfig,\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 `history` and `location` exists and accessible\n */\nfunction supports() {\n return typeof history !== 'undefined' && typeof location !== 'undefined'\n}\n\n/**\n * Creates query string adapter\n */\nquery.factory = true as const\nexport function query(config?: QueryConfig): StorageAdapter {\n return supports()\n ? adapter({\n ...config,\n })\n : nil({ keyArea: 'query' })\n}\n\n/**\n * Creates custom partially applied `persist`\n * with predefined `query` adapter\n */\nexport function createPersist(defaults?: ConfigPersist): Persist {\n return (config) =>\n base({\n adapter: query,\n ...defaults,\n ...config,\n })\n}\n\n/**\n * Default partially applied `persist`\n */\nexport const persist = createPersist()\n"],"names":["timeoutId","scheduled","keyArea","Symbol","buffer","Map","url","params","location","pathname","hash","pushState","erase","history","state","replaceState","locationAssign","assign","locationReplace","replace","flush","method","undefined","size","URLSearchParams","search","name","value","entries","set","delete","clear","query","config","serialize","deserialize","def","timeout","adapter","key","update","addEventListener","setTimeout","get","clearTimeout","deadline","Date","now","nil","createPersist","defaults","base","factory","persist"],"mappings":"iFAkBA,IAGIA,EACAC,EAJEC,EAAUC,SAEVC,EAAS,IAAIC,IAQbC,EAAOC,GACXC,SAASC,UACRF,EAAS,GAAK,IAAMA,EAAS,KAC7BC,SAASE,MAA0B,MAAlBF,SAASE,KAAeF,SAASE,KAAO,IAE/CC,EAA0BA,CAACJ,EAAQK,IAC9CC,QAAQF,UAAUC,EAAQ,KAAOC,QAAQC,MAAO,GAAIR,EAAIC,IAE7CQ,EAA6BA,CAACR,EAAQK,IACjDC,QAAQE,aAAaH,EAAQ,KAAOC,QAAQC,MAAO,GAAIR,EAAIC,IAEhDS,EAAgCT,GAC3CC,SAASS,OAAOX,EAAIC,IAETW,EAAiCX,GAC5CC,SAASW,QAAQb,EAAIC,IAKvB,SAASa,EAAMC,EAAsBP,GAEnC,GADAb,OAAYqB,EACRlB,EAAOmB,KAAM,CACf,IAAMhB,EAAS,IAAIiB,gBAAgBhB,SAASiB,QAC5C,IAAK,IAAOC,EAAMC,KAAUvB,EAAOwB,UACpB,MAATD,EACFpB,EAAOsB,IAAIH,EAAO,GAAEC,KAEpBpB,EAAOuB,OAAOJ,GAGlBtB,EAAO2B,QACPV,EAAOd,EAAkB,UAAVO,EACjB,CACF,CCJO,SAASkB,EAAMC,GACpB,MAR0B,oBAAZpB,SAA+C,oBAAbL,SDgB3C,UAAiBa,OACtBA,EAASV,EAASG,MAClBA,EAAKoB,UACLA,EAASC,YACTA,EAAWC,IACXA,EAAM,KAAIC,QACVA,IAEA,IAAMC,EAA0BA,CAC9BC,EACAC,KAEgC,oBAArBC,kBACTA,iBAAiB,YAAY,IAAMC,WAAWF,EAAQ,KAGjD,CACLG,MACE,IACMhB,EADS,IAAIH,gBAAgBhB,SAASiB,QACvBkB,IAAIJ,GACzB,OAAOZ,EAASQ,EAAcA,EAAYR,GAASA,EAASS,CAC7D,EAEDP,IAAIF,GAGF,GAFAvB,EAAOyB,IAAIU,EAAKL,EAAYA,EAAUP,GAASA,QAE/BL,IAAZe,EAEF,OADAO,aAAa5C,GACNoB,EAAMC,EAAQP,GAGvB,IAAM+B,EAAWC,KAAKC,MAAQV,QACZf,IAAdrB,GAA2BA,EAAY4C,KACzCD,aAAa5C,GACbC,EAAY4C,EACZ7C,EAAY0C,WAAWtB,EAAOiB,EAAShB,EAAQP,GAEnD,IAKJ,OADAwB,EAAQpC,QAAUA,EACXoC,CACT,CClDMA,CAAQ,IACHL,IAELe,EAAI,CAAE9C,QAAS,SACrB,CAMO,SAAS+C,EAAcC,GAC5B,OAAQjB,GACNkB,EAAK,CACHb,QAASN,KACNkB,KACAjB,GAET,CApBAD,EAAMoB,SAAU,EAyBHC,IAAAA,EAAUJ"}
1
+ {"version":3,"file":"index.js","sources":["../../src/query/adapter.ts","../../src/query/index.ts"],"sourcesContent":["import type { StorageAdapter } from '../types'\n\nexport type ChangeMethod = (\n params: URLSearchParams | string,\n erase?: boolean\n) => void\n\nexport type StateBehavior = 'keep' | 'erase'\n\nexport interface QueryConfig {\n method?: ChangeMethod\n state?: StateBehavior\n serialize?: (value: any) => string\n deserialize?: (value: string) => any\n timeout?: number\n def?: any\n}\n\nconst keyArea = Symbol() // eslint-disable-line symbol-description\n\nconst buffer = new Map<string, any>()\nlet timeoutId: ReturnType<typeof setTimeout> | undefined\nlet scheduled: number | undefined\n\n/*\n * Location change methods list\n */\n\nconst url = (params: URLSearchParams | string) =>\n location.pathname +\n (params + '' ? '?' + params : '') +\n (location.hash && location.hash !== '#' ? location.hash : '')\n\nexport const pushState: ChangeMethod = (params, erase): void =>\n history.pushState(erase ? null : history.state, '', url(params))\n\nexport const replaceState: ChangeMethod = (params, erase): void =>\n history.replaceState(erase ? null : history.state, '', url(params))\n\nexport const locationAssign: ChangeMethod = (params): void =>\n location.assign(url(params))\n\nexport const locationReplace: ChangeMethod = (params): void =>\n location.replace(url(params))\n\n/**\n * Flush buffer to actual location search params\n */\nfunction flush(method: ChangeMethod, state?: StateBehavior) {\n scheduled = undefined\n if (buffer.size) {\n const params = new URLSearchParams(location.search)\n for (const [name, value] of buffer.entries()) {\n if (value != null) {\n params.set(name, `${value}`)\n } else {\n params.delete(name)\n }\n }\n buffer.clear()\n method(params, state === 'erase')\n }\n}\n\n/**\n * Query string adapter factory\n */\nexport function adapter({\n method = pushState,\n state,\n serialize,\n deserialize,\n def = null,\n timeout,\n}: QueryConfig): StorageAdapter {\n const adapter: StorageAdapter = <State>(\n key: string,\n update: (raw?: any) => void\n ) => {\n if (typeof addEventListener !== 'undefined') {\n addEventListener('popstate', () => setTimeout(update, 0))\n }\n\n return {\n get() {\n const params = new URLSearchParams(location.search)\n const value = params.get(key)\n return value ? (deserialize ? deserialize(value) : value) : def\n },\n\n set(value: State) {\n buffer.set(key, serialize ? serialize(value) : value)\n\n if (timeout === undefined) {\n clearTimeout(timeoutId)\n return flush(method, state)\n }\n\n const deadline = Date.now() + timeout\n if (scheduled === undefined || scheduled > deadline) {\n clearTimeout(timeoutId)\n scheduled = deadline\n timeoutId = setTimeout(flush, timeout, method, state)\n }\n },\n }\n }\n\n adapter.keyArea = keyArea\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 { ChangeMethod, StateBehavior, QueryConfig } 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 { ChangeMethod, StateBehavior, QueryConfig } from './adapter'\nexport {\n locationAssign,\n locationReplace,\n pushState,\n replaceState,\n} from './adapter'\n\nexport interface ConfigPersist extends BaseConfigPersist {\n method?: ChangeMethod\n state?: StateBehavior\n timeout?: number\n}\n\nexport interface ConfigStore<State, Err = Error>\n extends QueryConfig,\n BaseConfigStore<State, Err> {}\n\nexport interface ConfigSourceTarget<State, Err = Error>\n extends QueryConfig,\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 `history` and `location` exists and accessible\n */\nfunction supports() {\n return typeof history !== 'undefined' && typeof location !== 'undefined'\n}\n\n/**\n * Creates query string adapter\n */\nquery.factory = true as const\nexport function query(config?: QueryConfig): StorageAdapter {\n return supports()\n ? adapter({\n ...config,\n })\n : nil({ keyArea: 'query' })\n}\n\n/**\n * Creates custom partially applied `persist`\n * with predefined `query` adapter\n */\nexport function createPersist(defaults?: ConfigPersist): Persist {\n return (config) =>\n base({\n adapter: query,\n ...defaults,\n ...config,\n })\n}\n\n/**\n * Default partially applied `persist`\n */\nexport const persist = createPersist()\n"],"names":["timeoutId","scheduled","keyArea","Symbol","buffer","Map","url","params","location","pathname","hash","pushState","erase","history","state","replaceState","locationAssign","assign","locationReplace","replace","flush","method","undefined","size","URLSearchParams","search","name","value","entries","set","delete","clear","query","config","serialize","deserialize","def","timeout","adapter","key","update","addEventListener","setTimeout","get","clearTimeout","deadline","Date","now","nil","createPersist","defaults","base","factory","persist"],"mappings":"iFAkBA,IAGIA,EACAC,EAJEC,EAAUC,SAEVC,EAAS,IAAIC,IAQbC,EAAOC,GACXC,SAASC,UACRF,EAAS,GAAK,IAAMA,EAAS,KAC7BC,SAASE,MAA0B,MAAlBF,SAASE,KAAeF,SAASE,KAAO,IAE/CC,EAA0BA,CAACJ,EAAQK,IAC9CC,QAAQF,UAAUC,EAAQ,KAAOC,QAAQC,MAAO,GAAIR,EAAIC,IAE7CQ,EAA6BA,CAACR,EAAQK,IACjDC,QAAQE,aAAaH,EAAQ,KAAOC,QAAQC,MAAO,GAAIR,EAAIC,IAEhDS,EAAgCT,GAC3CC,SAASS,OAAOX,EAAIC,IAETW,EAAiCX,GAC5CC,SAASW,QAAQb,EAAIC,IAKvB,SAASa,EAAMC,EAAsBP,GAEnC,GADAb,OAAYqB,EACRlB,EAAOmB,KAAM,CACf,IAAMhB,EAAS,IAAIiB,gBAAgBhB,SAASiB,QAC5C,IAAK,IAAOC,EAAMC,KAAUvB,EAAOwB,UACpB,MAATD,EACFpB,EAAOsB,IAAIH,EAAO,GAAEC,KAEpBpB,EAAOuB,OAAOJ,GAGlBtB,EAAO2B,QACPV,EAAOd,EAAkB,UAAVO,EACjB,CACF,CCJO,SAASkB,EAAMC,GACpB,MAR0B,oBAAZpB,SAA+C,oBAAbL,SDgB3C,UAAiBa,OACtBA,EAASV,EAASG,MAClBA,EAAKoB,UACLA,EAASC,YACTA,EAAWC,IACXA,EAAM,KAAIC,QACVA,IAEA,IAAMC,EAA0BA,CAC9BC,EACAC,KAEgC,oBAArBC,kBACTA,iBAAiB,YAAY,IAAMC,WAAWF,EAAQ,KAGjD,CACLG,GAAAA,GACE,IACMhB,EADS,IAAIH,gBAAgBhB,SAASiB,QACvBkB,IAAIJ,GACzB,OAAOZ,EAASQ,EAAcA,EAAYR,GAASA,EAASS,CAC7D,EAEDP,GAAAA,CAAIF,GAGF,GAFAvB,EAAOyB,IAAIU,EAAKL,EAAYA,EAAUP,GAASA,QAE/BL,IAAZe,EAEF,OADAO,aAAa5C,GACNoB,EAAMC,EAAQP,GAGvB,IAAM+B,EAAWC,KAAKC,MAAQV,QACZf,IAAdrB,GAA2BA,EAAY4C,KACzCD,aAAa5C,GACbC,EAAY4C,EACZ7C,EAAY0C,WAAWtB,EAAOiB,EAAShB,EAAQP,GAEnD,IAKJ,OADAwB,EAAQpC,QAAUA,EACXoC,CACT,CClDMA,CAAQ,IACHL,IAELe,EAAI,CAAE9C,QAAS,SACrB,CAMO,SAAS+C,EAAcC,GAC5B,OAAQjB,GACNkB,EAAK,CACHb,QAASN,KACNkB,KACAjB,GAET,CApBAD,EAAMoB,SAAU,EAyBHC,IAAAA,EAAUJ"}
@@ -1,8 +1,21 @@
1
1
  {
2
2
  "type": "module",
3
3
  "sideEffects": false,
4
- "main": "index.cjs",
4
+ "types": "index.d.ts",
5
5
  "module": "index.js",
6
+ "main": "index.cjs",
6
7
  "react-native": "index.js",
7
- "types": "index.d.ts"
8
+ "exports": {
9
+ "./package.json": "./package.json",
10
+ ".": {
11
+ "import": {
12
+ "types": "./index.d.ts",
13
+ "default": "./index.js"
14
+ },
15
+ "require": {
16
+ "types": "./index.d.cts",
17
+ "default": "./index.cjs"
18
+ }
19
+ }
20
+ }
8
21
  }
@@ -0,0 +1,99 @@
1
+ import { Unit, Store, Event, Effect, Subscription } from 'effector';
2
+
3
+ interface StorageAdapter {
4
+ <State>(key: string, update: (raw?: any) => void): {
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> = ((raw: unknown) => raw is Data) | {
16
+ isData: (raw: unknown) => raw is Data;
17
+ getErrorMessages: (raw: unknown) => string[];
18
+ };
19
+ type Done<State> = {
20
+ key: string;
21
+ keyPrefix: string;
22
+ operation: 'set' | 'get';
23
+ value: State;
24
+ };
25
+ type Fail<Err> = {
26
+ key: string;
27
+ keyPrefix: string;
28
+ operation: 'set' | 'get';
29
+ error: Err;
30
+ value?: any;
31
+ };
32
+ type Finally<State, Err> = (Done<State> & {
33
+ status: 'done';
34
+ }) | (Fail<Err> & {
35
+ status: 'fail';
36
+ });
37
+ interface ConfigPersist$1 {
38
+ pickup?: Unit<any>;
39
+ context?: Unit<any>;
40
+ keyPrefix?: string;
41
+ contract?: Contract<any>;
42
+ }
43
+ interface ConfigCommon<State, Err = Error> {
44
+ clock?: Unit<any>;
45
+ done?: Unit<Done<State>>;
46
+ fail?: Unit<Fail<Err>>;
47
+ finally?: Unit<Finally<State, Err>>;
48
+ pickup?: Unit<any>;
49
+ context?: Unit<any>;
50
+ key?: string;
51
+ keyPrefix?: string;
52
+ contract?: Contract<State | undefined>;
53
+ }
54
+ interface ConfigJustStore<State> {
55
+ store: Store<State>;
56
+ }
57
+ interface ConfigJustSourceTarget<State> {
58
+ source: Store<State> | Event<State> | Effect<State, any, any>;
59
+ target: Store<State> | Event<State> | Effect<State, any, any>;
60
+ }
61
+ interface ConfigStore$1<State, Err = Error> extends ConfigCommon<State, Err>, ConfigJustStore<State> {
62
+ }
63
+ interface ConfigSourceTarget$1<State, Err = Error> extends ConfigCommon<State, Err>, ConfigJustSourceTarget<State> {
64
+ }
65
+
66
+ interface ConfigPersist extends ConfigPersist$1 {
67
+ sync?: boolean | 'force';
68
+ timeout?: number;
69
+ }
70
+ interface SessionStorageConfig {
71
+ sync?: boolean | 'force';
72
+ serialize?: (value: any) => string;
73
+ deserialize?: (value: string) => any;
74
+ timeout?: number;
75
+ def?: any;
76
+ }
77
+ interface ConfigStore<State, Err = Error> extends SessionStorageConfig, ConfigStore$1<State, Err> {
78
+ }
79
+ interface ConfigSourceTarget<State, Err = Error> extends SessionStorageConfig, ConfigSourceTarget$1<State, Err> {
80
+ }
81
+ interface Persist {
82
+ <State, Err = Error>(config: ConfigSourceTarget<State, Err>): Subscription;
83
+ <State, Err = Error>(config: ConfigStore<State, Err>): Subscription;
84
+ }
85
+ declare function session(config?: SessionStorageConfig): StorageAdapter;
86
+ declare namespace session {
87
+ var factory: true;
88
+ }
89
+ /**
90
+ * Creates custom partially applied `persist`
91
+ * with predefined `sessionStorage` adapter
92
+ */
93
+ declare function createPersist(defaults?: ConfigPersist): Persist;
94
+ /**
95
+ * Default partially applied `persist`
96
+ */
97
+ declare const persist: Persist;
98
+
99
+ export { type ConfigPersist, type ConfigSourceTarget, type ConfigStore, type Contract, type Done, type Fail, type Finally, type Persist, type SessionStorageConfig, type StorageAdapter, type StorageAdapterFactory, createPersist, persist, session };