effector-storage 6.1.1 → 7.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.
- 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} +34 -58
- package/tools/index.d.ts +34 -58
- package/tools/index.js.flow +19 -16
- 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/memory/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
|
}
|
package/nil/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/nil/index.ts"],"sourcesContent":["import type { StorageAdapter } from '../types'\n\nexport interface NilConfig {\n keyArea?: any\n}\n\n/**\n * Nil/Void adapter\n */\nnil.factory = true as const\nexport function nil({ keyArea = '' }: NilConfig = {}): StorageAdapter {\n const adapter: StorageAdapter = () =>\n <any>{\n get() {}, // eslint-disable-line @typescript-eslint/no-empty-function\n set() {}, // eslint-disable-line @typescript-eslint/no-empty-function\n }\n\n adapter.keyArea = keyArea\n adapter.noop = true\n return adapter\n}\n"],"names":["nil","keyArea","adapter","get","set","noop","factory"],"mappings":"aAUO,SAASA,GAAIC,QAAEA,EAAU,IAAkB,IAChD,IAAMC,EAA0BA,KACzB,CACHC,
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/nil/index.ts"],"sourcesContent":["import type { StorageAdapter } from '../types'\n\nexport interface NilConfig {\n keyArea?: any\n}\n\n/**\n * Nil/Void adapter\n */\nnil.factory = true as const\nexport function nil({ keyArea = '' }: NilConfig = {}): StorageAdapter {\n const adapter: StorageAdapter = () =>\n <any>{\n get() {}, // eslint-disable-line @typescript-eslint/no-empty-function\n set() {}, // eslint-disable-line @typescript-eslint/no-empty-function\n }\n\n adapter.keyArea = keyArea\n adapter.noop = true\n return adapter\n}\n"],"names":["nil","keyArea","adapter","get","set","noop","factory"],"mappings":"aAUO,SAASA,GAAIC,QAAEA,EAAU,IAAkB,IAChD,IAAMC,EAA0BA,KACzB,CACHC,GAAAA,GAAQ,EACRC,GAAAA,GAAQ,IAKZ,OAFAF,EAAQD,QAAUA,EAClBC,EAAQG,MAAO,EACRH,CACT,CAXAF,EAAIM,SAAU"}
|
package/nil/index.d.cts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
interface StorageAdapter {
|
|
2
|
+
<State>(key: string, update: (raw?: any) => void): {
|
|
3
|
+
get(raw?: any, ctx?: any): State | Promise<State | undefined> | undefined;
|
|
4
|
+
set(value: State, ctx?: any): void;
|
|
5
|
+
};
|
|
6
|
+
keyArea?: any;
|
|
7
|
+
noop?: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface NilConfig {
|
|
11
|
+
keyArea?: any;
|
|
12
|
+
}
|
|
13
|
+
declare function nil({ keyArea }?: NilConfig): StorageAdapter;
|
|
14
|
+
declare namespace nil {
|
|
15
|
+
var factory: true;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { type NilConfig, nil };
|
package/nil/index.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
interface StorageAdapter {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
<State>(key: string, update: (raw?: any) => void): {
|
|
3
|
+
get(raw?: any, ctx?: any): State | Promise<State | undefined> | undefined;
|
|
4
|
+
set(value: State, ctx?: any): void;
|
|
5
|
+
};
|
|
6
|
+
keyArea?: any;
|
|
7
|
+
noop?: boolean;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
interface NilConfig {
|
|
11
|
-
|
|
11
|
+
keyArea?: any;
|
|
12
12
|
}
|
|
13
|
-
declare function nil({ keyArea }?: NilConfig): StorageAdapter
|
|
13
|
+
declare function nil({ keyArea }?: NilConfig): StorageAdapter;
|
|
14
14
|
declare namespace nil {
|
|
15
|
-
|
|
15
|
+
var factory: true;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
export { NilConfig, nil }
|
|
18
|
+
export { type NilConfig, nil };
|
package/nil/index.js.flow
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
declare interface StorageAdapter {
|
|
9
9
|
<State>(
|
|
10
10
|
key: string,
|
|
11
|
-
update: (raw?: any) =>
|
|
11
|
+
update: (raw?: any) => void
|
|
12
12
|
): {
|
|
13
13
|
get(raw?: any, ctx?: any): State | Promise<State | void> | void,
|
|
14
14
|
set(value: State, ctx?: any): void,
|
|
@@ -20,11 +20,12 @@ declare interface StorageAdapter {
|
|
|
20
20
|
declare interface NilConfig {
|
|
21
21
|
keyArea?: any;
|
|
22
22
|
}
|
|
23
|
-
declare var nil: typeof npm$namespace$nil
|
|
23
|
+
declare var nil: typeof npm$namespace$nil;
|
|
24
24
|
|
|
25
25
|
declare var npm$namespace$nil: {|
|
|
26
26
|
(x?: NilConfig): StorageAdapter,
|
|
27
27
|
factory: typeof nil$factory,
|
|
28
|
-
|}
|
|
29
|
-
declare var nil$factory: true
|
|
30
|
-
|
|
28
|
+
|};
|
|
29
|
+
declare var nil$factory: true;
|
|
30
|
+
export type { NilConfig };
|
|
31
|
+
declare export { nil };
|
package/nil/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/nil/index.ts"],"sourcesContent":["import type { StorageAdapter } from '../types'\n\nexport interface NilConfig {\n keyArea?: any\n}\n\n/**\n * Nil/Void adapter\n */\nnil.factory = true as const\nexport function nil({ keyArea = '' }: NilConfig = {}): StorageAdapter {\n const adapter: StorageAdapter = () =>\n <any>{\n get() {}, // eslint-disable-line @typescript-eslint/no-empty-function\n set() {}, // eslint-disable-line @typescript-eslint/no-empty-function\n }\n\n adapter.keyArea = keyArea\n adapter.noop = true\n return adapter\n}\n"],"names":["nil","keyArea","adapter","get","set","noop","factory"],"mappings":"AAUO,SAASA,GAAIC,QAAEA,EAAU,IAAkB,IAChD,IAAMC,EAA0BA,KACzB,CACHC,
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/nil/index.ts"],"sourcesContent":["import type { StorageAdapter } from '../types'\n\nexport interface NilConfig {\n keyArea?: any\n}\n\n/**\n * Nil/Void adapter\n */\nnil.factory = true as const\nexport function nil({ keyArea = '' }: NilConfig = {}): StorageAdapter {\n const adapter: StorageAdapter = () =>\n <any>{\n get() {}, // eslint-disable-line @typescript-eslint/no-empty-function\n set() {}, // eslint-disable-line @typescript-eslint/no-empty-function\n }\n\n adapter.keyArea = keyArea\n adapter.noop = true\n return adapter\n}\n"],"names":["nil","keyArea","adapter","get","set","noop","factory"],"mappings":"AAUO,SAASA,GAAIC,QAAEA,EAAU,IAAkB,IAChD,IAAMC,EAA0BA,KACzB,CACHC,GAAAA,GAAQ,EACRC,GAAAA,GAAQ,IAKZ,OAFAF,EAAQD,QAAUA,EAClBC,EAAQG,MAAO,EACRH,CACT,CAXAF,EAAIM,SAAU"}
|
package/nil/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
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "effector-storage",
|
|
3
3
|
"description": "Module for Effector to sync stores with different storages",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "7.1.0",
|
|
5
5
|
"author": "Victor Didenko <yumaa.verdin@gmail.com> (https://yumaa.name)",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -19,105 +19,149 @@
|
|
|
19
19
|
"localstorage",
|
|
20
20
|
"local storage",
|
|
21
21
|
"sessionstorage",
|
|
22
|
-
"session storage"
|
|
23
|
-
"react native asyncstorage",
|
|
24
|
-
"react native async storage",
|
|
25
|
-
"react native encryptedstorage",
|
|
26
|
-
"react native encrypted storage"
|
|
22
|
+
"session storage"
|
|
27
23
|
],
|
|
28
24
|
"peerDependencies": {
|
|
29
|
-
"effector": "
|
|
25
|
+
"effector": "^22.4.0 || ^23.0.0"
|
|
30
26
|
},
|
|
31
27
|
"type": "module",
|
|
32
28
|
"sideEffects": false,
|
|
33
|
-
"
|
|
29
|
+
"types": "index.d.ts",
|
|
34
30
|
"module": "index.js",
|
|
31
|
+
"main": "index.cjs",
|
|
35
32
|
"react-native": "index.js",
|
|
36
|
-
"types": "index.d.ts",
|
|
37
33
|
"exports": {
|
|
38
34
|
"./package.json": "./package.json",
|
|
39
35
|
".": {
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
|
|
36
|
+
"import": {
|
|
37
|
+
"types": "./index.d.ts",
|
|
38
|
+
"default": "./index.js"
|
|
39
|
+
},
|
|
40
|
+
"require": {
|
|
41
|
+
"types": "./index.d.cts",
|
|
42
|
+
"default": "./index.cjs"
|
|
43
|
+
}
|
|
43
44
|
},
|
|
44
45
|
"./core/package.json": "./core/package.json",
|
|
45
46
|
"./core": {
|
|
46
|
-
"
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
"import": {
|
|
48
|
+
"types": "./core/index.d.ts",
|
|
49
|
+
"default": "./core/index.js"
|
|
50
|
+
},
|
|
51
|
+
"require": {
|
|
52
|
+
"types": "./core/index.d.cts",
|
|
53
|
+
"default": "./core/index.cjs"
|
|
54
|
+
}
|
|
49
55
|
},
|
|
50
56
|
"./tools/package.json": "./tools/package.json",
|
|
51
57
|
"./tools": {
|
|
52
|
-
"
|
|
53
|
-
|
|
54
|
-
|
|
58
|
+
"import": {
|
|
59
|
+
"types": "./tools/index.d.ts",
|
|
60
|
+
"default": "./tools/index.js"
|
|
61
|
+
},
|
|
62
|
+
"require": {
|
|
63
|
+
"types": "./tools/index.d.cts",
|
|
64
|
+
"default": "./tools/index.cjs"
|
|
65
|
+
}
|
|
55
66
|
},
|
|
56
67
|
"./nil/package.json": "./nil/package.json",
|
|
57
68
|
"./nil": {
|
|
58
|
-
"
|
|
59
|
-
|
|
60
|
-
|
|
69
|
+
"import": {
|
|
70
|
+
"types": "./nil/index.d.ts",
|
|
71
|
+
"default": "./nil/index.js"
|
|
72
|
+
},
|
|
73
|
+
"require": {
|
|
74
|
+
"types": "./nil/index.d.cts",
|
|
75
|
+
"default": "./nil/index.cjs"
|
|
76
|
+
}
|
|
61
77
|
},
|
|
62
78
|
"./log/package.json": "./log/package.json",
|
|
63
79
|
"./log": {
|
|
64
|
-
"
|
|
65
|
-
|
|
66
|
-
|
|
80
|
+
"import": {
|
|
81
|
+
"types": "./log/index.d.ts",
|
|
82
|
+
"default": "./log/index.js"
|
|
83
|
+
},
|
|
84
|
+
"require": {
|
|
85
|
+
"types": "./log/index.d.cts",
|
|
86
|
+
"default": "./log/index.cjs"
|
|
87
|
+
}
|
|
67
88
|
},
|
|
68
89
|
"./local/package.json": "./local/package.json",
|
|
69
90
|
"./local": {
|
|
70
|
-
"
|
|
71
|
-
|
|
72
|
-
|
|
91
|
+
"import": {
|
|
92
|
+
"types": "./local/index.d.ts",
|
|
93
|
+
"default": "./local/index.js"
|
|
94
|
+
},
|
|
95
|
+
"require": {
|
|
96
|
+
"types": "./local/index.d.cts",
|
|
97
|
+
"default": "./local/index.cjs"
|
|
98
|
+
}
|
|
73
99
|
},
|
|
74
100
|
"./session/package.json": "./session/package.json",
|
|
75
101
|
"./session": {
|
|
76
|
-
"
|
|
77
|
-
|
|
78
|
-
|
|
102
|
+
"import": {
|
|
103
|
+
"types": "./session/index.d.ts",
|
|
104
|
+
"default": "./session/index.js"
|
|
105
|
+
},
|
|
106
|
+
"require": {
|
|
107
|
+
"types": "./session/index.d.cts",
|
|
108
|
+
"default": "./session/index.cjs"
|
|
109
|
+
}
|
|
79
110
|
},
|
|
80
111
|
"./storage/package.json": "./storage/package.json",
|
|
81
112
|
"./storage": {
|
|
82
|
-
"
|
|
83
|
-
|
|
84
|
-
|
|
113
|
+
"import": {
|
|
114
|
+
"types": "./storage/index.d.ts",
|
|
115
|
+
"default": "./storage/index.js"
|
|
116
|
+
},
|
|
117
|
+
"require": {
|
|
118
|
+
"types": "./storage/index.d.cts",
|
|
119
|
+
"default": "./storage/index.cjs"
|
|
120
|
+
}
|
|
85
121
|
},
|
|
86
122
|
"./query/package.json": "./query/package.json",
|
|
87
123
|
"./query": {
|
|
88
|
-
"
|
|
89
|
-
|
|
90
|
-
|
|
124
|
+
"import": {
|
|
125
|
+
"types": "./query/index.d.ts",
|
|
126
|
+
"default": "./query/index.js"
|
|
127
|
+
},
|
|
128
|
+
"require": {
|
|
129
|
+
"types": "./query/index.d.cts",
|
|
130
|
+
"default": "./query/index.cjs"
|
|
131
|
+
}
|
|
91
132
|
},
|
|
92
133
|
"./memory/package.json": "./memory/package.json",
|
|
93
134
|
"./memory": {
|
|
94
|
-
"
|
|
95
|
-
|
|
96
|
-
|
|
135
|
+
"import": {
|
|
136
|
+
"types": "./memory/index.d.ts",
|
|
137
|
+
"default": "./memory/index.js"
|
|
138
|
+
},
|
|
139
|
+
"require": {
|
|
140
|
+
"types": "./memory/index.d.cts",
|
|
141
|
+
"default": "./memory/index.cjs"
|
|
142
|
+
}
|
|
97
143
|
},
|
|
98
144
|
"./async-storage/package.json": "./async-storage/package.json",
|
|
99
145
|
"./async-storage": {
|
|
100
|
-
"
|
|
101
|
-
|
|
102
|
-
|
|
146
|
+
"import": {
|
|
147
|
+
"types": "./async-storage/index.d.ts",
|
|
148
|
+
"default": "./async-storage/index.js"
|
|
149
|
+
},
|
|
150
|
+
"require": {
|
|
151
|
+
"types": "./async-storage/index.d.cts",
|
|
152
|
+
"default": "./async-storage/index.cjs"
|
|
153
|
+
}
|
|
103
154
|
},
|
|
104
155
|
"./broadcast/package.json": "./broadcast/package.json",
|
|
105
156
|
"./broadcast": {
|
|
106
|
-
"
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
"import": "./rn/async/index.js"
|
|
115
|
-
},
|
|
116
|
-
"./rn/encrypted/package.json": "./rn/encrypted/package.json",
|
|
117
|
-
"./rn/encrypted": {
|
|
118
|
-
"types": "./rn/encrypted/index.d.ts",
|
|
119
|
-
"require": "./rn/encrypted/index.cjs",
|
|
120
|
-
"import": "./rn/encrypted/index.js"
|
|
157
|
+
"import": {
|
|
158
|
+
"types": "./broadcast/index.d.ts",
|
|
159
|
+
"default": "./broadcast/index.js"
|
|
160
|
+
},
|
|
161
|
+
"require": {
|
|
162
|
+
"types": "./broadcast/index.d.cts",
|
|
163
|
+
"default": "./broadcast/index.cjs"
|
|
164
|
+
}
|
|
121
165
|
}
|
|
122
166
|
}
|
|
123
167
|
}
|
package/query/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","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.cjs","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","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","assign","replace","replaceState"],"mappings":"iBAqBIA,EACAC,+DAJEC,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,IAc1D,SAASQ,EAAMC,EAAsBF,GAEnC,GADAb,OAAYgB,EACRb,EAAOc,KAAM,CACf,IAAMX,EAAS,IAAIY,gBAAgBX,SAASY,QAC5C,IAAK,IAAOC,EAAMC,KAAUlB,EAAOmB,UACpB,MAATD,EACFf,EAAOiB,IAAIH,EAAO,GAAEC,KAEpBf,EAAOkB,OAAOJ,GAGlBjB,EAAOsB,QACPV,EAAOT,EAAkB,UAAVO,EACjB,CACF,CCJO,SAASa,EAAMC,GACpB,MAR0B,oBAAZf,SAA+C,oBAAbL,SDgB3C,UAAiBQ,OACtBA,EAASL,EAASG,MAClBA,EAAKe,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,gBAAgBX,SAASY,QACvBkB,IAAIJ,GACzB,OAAOZ,EAASQ,EAAcA,EAAYR,GAASA,EAASS,CAC7D,EAEDP,GAAAA,CAAIF,GAGF,GAFAlB,EAAOoB,IAAIU,EAAKL,EAAYA,EAAUP,GAASA,QAE/BL,IAAZe,EAEF,OADAO,aAAavC,GACNe,EAAMC,EAAQF,GAGvB,IAAM0B,EAAWC,KAAKC,MAAQV,QACZf,IAAdhB,GAA2BA,EAAYuC,KACzCD,aAAavC,GACbC,EAAYuC,EACZxC,EAAYqC,WAAWtB,EAAOiB,EAAShB,EAAQF,GAEnD,IAKJ,OADAmB,EAAQ/B,QAAUA,EACX+B,CACT,CClDMA,CAAQ,IACHL,IAELe,EAAAA,IAAI,CAAEzC,QAAS,SACrB,CAMO,SAAS0C,EAAcC,GAC5B,OAAQjB,GACNkB,EAAAA,QAAK,CACHb,QAASN,KACNkB,KACAjB,GAET,CApBAD,EAAMoB,SAAU,EAyBHC,IAAAA,EAAUJ,mDD3CsBrC,GAC3CC,SAASyC,OAAO3C,EAAIC,4BAEwBA,GAC5CC,SAAS0C,QAAQ5C,EAAIC,+EAPmB4C,CAAC5C,EAAQK,IACjDC,QAAQsC,aAAavC,EAAQ,KAAOC,QAAQC,MAAO,GAAIR,EAAIC"}
|
|
@@ -0,0 +1,108 @@
|
|
|
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
|
+
type ChangeMethod = (params: URLSearchParams | string, erase?: boolean) => void;
|
|
67
|
+
type StateBehavior = 'keep' | 'erase';
|
|
68
|
+
interface QueryConfig {
|
|
69
|
+
method?: ChangeMethod;
|
|
70
|
+
state?: StateBehavior;
|
|
71
|
+
serialize?: (value: any) => string;
|
|
72
|
+
deserialize?: (value: string) => any;
|
|
73
|
+
timeout?: number;
|
|
74
|
+
def?: any;
|
|
75
|
+
}
|
|
76
|
+
declare const pushState: ChangeMethod;
|
|
77
|
+
declare const replaceState: ChangeMethod;
|
|
78
|
+
declare const locationAssign: ChangeMethod;
|
|
79
|
+
declare const locationReplace: ChangeMethod;
|
|
80
|
+
|
|
81
|
+
interface ConfigPersist extends ConfigPersist$1 {
|
|
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> {
|
|
89
|
+
}
|
|
90
|
+
interface Persist {
|
|
91
|
+
<State, Err = Error>(config: ConfigSourceTarget<State, Err>): Subscription;
|
|
92
|
+
<State, Err = Error>(config: ConfigStore<State, Err>): Subscription;
|
|
93
|
+
}
|
|
94
|
+
declare function query(config?: QueryConfig): StorageAdapter;
|
|
95
|
+
declare namespace query {
|
|
96
|
+
var factory: true;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Creates custom partially applied `persist`
|
|
100
|
+
* with predefined `query` adapter
|
|
101
|
+
*/
|
|
102
|
+
declare function createPersist(defaults?: ConfigPersist): Persist;
|
|
103
|
+
/**
|
|
104
|
+
* Default partially applied `persist`
|
|
105
|
+
*/
|
|
106
|
+
declare const persist: Persist;
|
|
107
|
+
|
|
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 };
|