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.
- package/README.md +7 -40
- package/async-storage/index.cjs.map +1 -1
- package/async-storage/index.d.cts +24 -0
- package/async-storage/index.d.ts +14 -18
- package/async-storage/index.js.flow +6 -5
- package/async-storage/index.js.map +1 -1
- package/async-storage/package.json +15 -2
- package/broadcast/index.cjs.map +1 -1
- package/broadcast/index.d.cts +94 -0
- package/broadcast/index.d.ts +63 -85
- package/broadcast/index.js.flow +23 -25
- package/broadcast/index.js.map +1 -1
- package/broadcast/package.json +15 -2
- package/core/index.cjs +1 -1
- package/core/index.cjs.map +1 -1
- package/core/index.d.cts +77 -0
- package/core/index.d.ts +53 -66
- package/core/index.js +1 -1
- package/core/index.js.flow +14 -14
- package/core/index.js.map +1 -1
- package/core/package.json +15 -2
- package/index.d.cts +97 -0
- package/index.d.ts +68 -99
- package/index.js.flow +27 -28
- package/local/index.d.cts +99 -0
- package/local/index.d.ts +67 -90
- package/local/index.js.flow +25 -27
- package/local/package.json +15 -2
- package/log/index.cjs.map +1 -1
- package/log/index.d.cts +19 -0
- package/log/index.d.ts +11 -11
- package/log/index.js.flow +6 -5
- package/log/index.js.map +1 -1
- package/log/package.json +15 -2
- package/memory/index.d.cts +95 -0
- package/memory/index.d.ts +63 -82
- package/memory/index.js.flow +23 -25
- package/memory/package.json +15 -2
- package/nil/index.cjs.map +1 -1
- package/nil/index.d.cts +18 -0
- package/nil/index.d.ts +10 -10
- package/nil/index.js.flow +6 -5
- package/nil/index.js.map +1 -1
- package/nil/package.json +15 -2
- package/package.json +101 -57
- package/query/index.cjs.map +1 -1
- package/query/index.d.cts +108 -0
- package/query/index.d.ts +75 -104
- package/query/index.js.flow +30 -28
- package/query/index.js.map +1 -1
- package/query/package.json +15 -2
- package/session/index.d.cts +99 -0
- package/session/index.d.ts +67 -90
- package/session/index.js.flow +25 -27
- package/session/package.json +15 -2
- package/storage/index.cjs.map +1 -1
- package/storage/index.d.cts +23 -0
- package/storage/index.d.ts +15 -22
- package/storage/index.js.flow +7 -6
- package/storage/index.js.map +1 -1
- package/storage/package.json +15 -2
- package/tools/index.cjs.map +1 -1
- package/tools/{index.cjs.d.ts → index.d.cts} +33 -58
- package/tools/index.d.ts +33 -58
- package/tools/index.js.flow +13 -10
- package/tools/index.js.map +1 -1
- package/tools/package.json +15 -2
- package/async-storage/index.cjs.d.ts +0 -28
- package/broadcast/index.cjs.d.ts +0 -116
- package/core/index.cjs.d.ts +0 -90
- package/index.cjs.d.ts +0 -128
- package/local/index.cjs.d.ts +0 -122
- package/log/index.cjs.d.ts +0 -19
- package/memory/index.cjs.d.ts +0 -114
- package/nil/index.cjs.d.ts +0 -18
- package/query/index.cjs.d.ts +0 -137
- package/rn/async/index.cjs +0 -2
- package/rn/async/index.cjs.d.ts +0 -120
- package/rn/async/index.cjs.map +0 -1
- package/rn/async/index.d.ts +0 -120
- package/rn/async/index.js +0 -2
- package/rn/async/index.js.flow +0 -135
- package/rn/async/index.js.map +0 -1
- package/rn/async/package.json +0 -8
- package/rn/encrypted/index.cjs +0 -2
- package/rn/encrypted/index.cjs.d.ts +0 -120
- package/rn/encrypted/index.cjs.map +0 -1
- package/rn/encrypted/index.d.ts +0 -120
- package/rn/encrypted/index.js +0 -2
- package/rn/encrypted/index.js.flow +0 -137
- package/rn/encrypted/index.js.map +0 -1
- package/rn/encrypted/package.json +0 -8
- package/session/index.cjs.d.ts +0 -122
- 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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
13
|
-
|
|
12
|
+
(config?: AdapterConfig): StorageAdapter;
|
|
13
|
+
factory: true;
|
|
14
14
|
}
|
|
15
|
-
type Contract<Data> =
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
20
|
+
key: string;
|
|
21
|
+
keyPrefix: string;
|
|
22
|
+
operation: 'set' | 'get';
|
|
23
|
+
value: State;
|
|
24
|
+
};
|
|
27
25
|
type Fail<Err> = {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
type Finally<State, Err> =
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
|
|
55
|
+
store: Store<State>;
|
|
60
56
|
}
|
|
61
57
|
interface ConfigJustSourceTarget<State> {
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
-
|
|
100
|
-
|
|
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
|
-
|
|
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 };
|
package/query/index.js.flow
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
* @flow
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import { Unit, Store, Event, Effect, Subscription } from
|
|
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) =>
|
|
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:
|
|
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:
|
|
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:
|
|
51
|
+
status: "done",
|
|
52
52
|
...
|
|
53
53
|
},
|
|
54
54
|
}
|
|
55
55
|
| {
|
|
56
56
|
...Fail<Err>,
|
|
57
57
|
...{
|
|
58
|
-
status:
|
|
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 =
|
|
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
|
-
|
|
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
|
+
};
|
package/query/index.js.map
CHANGED
|
@@ -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) =>
|
|
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"}
|
package/query/package.json
CHANGED
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"sideEffects": false,
|
|
4
|
-
"
|
|
4
|
+
"types": "index.d.ts",
|
|
5
5
|
"module": "index.js",
|
|
6
|
+
"main": "index.cjs",
|
|
6
7
|
"react-native": "index.js",
|
|
7
|
-
"
|
|
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 };
|