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/session/index.d.ts
CHANGED
|
@@ -1,122 +1,99 @@
|
|
|
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
66
|
interface ConfigPersist extends ConfigPersist$1 {
|
|
73
|
-
|
|
74
|
-
|
|
67
|
+
sync?: boolean | 'force';
|
|
68
|
+
timeout?: number;
|
|
75
69
|
}
|
|
76
70
|
interface SessionStorageConfig {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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> {
|
|
82
80
|
}
|
|
83
|
-
interface ConfigStore<State, Err = Error>
|
|
84
|
-
extends SessionStorageConfig,
|
|
85
|
-
ConfigStore$1<State, Err> {}
|
|
86
|
-
interface ConfigSourceTarget<State, Err = Error>
|
|
87
|
-
extends SessionStorageConfig,
|
|
88
|
-
ConfigSourceTarget$1<State, Err> {}
|
|
89
81
|
interface Persist {
|
|
90
|
-
|
|
91
|
-
|
|
82
|
+
<State, Err = Error>(config: ConfigSourceTarget<State, Err>): Subscription;
|
|
83
|
+
<State, Err = Error>(config: ConfigStore<State, Err>): Subscription;
|
|
92
84
|
}
|
|
93
|
-
declare function session(config?: SessionStorageConfig): StorageAdapter
|
|
85
|
+
declare function session(config?: SessionStorageConfig): StorageAdapter;
|
|
94
86
|
declare namespace session {
|
|
95
|
-
|
|
87
|
+
var factory: true;
|
|
96
88
|
}
|
|
97
89
|
/**
|
|
98
90
|
* Creates custom partially applied `persist`
|
|
99
91
|
* with predefined `sessionStorage` adapter
|
|
100
92
|
*/
|
|
101
|
-
declare function createPersist(defaults?: ConfigPersist): Persist
|
|
93
|
+
declare function createPersist(defaults?: ConfigPersist): Persist;
|
|
102
94
|
/**
|
|
103
95
|
* Default partially applied `persist`
|
|
104
96
|
*/
|
|
105
|
-
declare const persist: Persist
|
|
97
|
+
declare const persist: Persist;
|
|
106
98
|
|
|
107
|
-
export {
|
|
108
|
-
ConfigPersist,
|
|
109
|
-
ConfigSourceTarget,
|
|
110
|
-
ConfigStore,
|
|
111
|
-
Contract,
|
|
112
|
-
Done,
|
|
113
|
-
Fail,
|
|
114
|
-
Finally,
|
|
115
|
-
Persist,
|
|
116
|
-
SessionStorageConfig,
|
|
117
|
-
StorageAdapter,
|
|
118
|
-
StorageAdapterFactory,
|
|
119
|
-
createPersist,
|
|
120
|
-
persist,
|
|
121
|
-
session,
|
|
122
|
-
}
|
|
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 };
|
package/session/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,44 +87,44 @@ 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 ConfigPersist = {
|
|
97
|
-
sync?: boolean |
|
|
97
|
+
sync?: boolean | "force",
|
|
98
98
|
timeout?: number,
|
|
99
99
|
...
|
|
100
|
-
} & ConfigPersist$1
|
|
100
|
+
} & ConfigPersist$1;
|
|
101
101
|
declare interface SessionStorageConfig {
|
|
102
|
-
sync?: boolean |
|
|
102
|
+
sync?: boolean | "force";
|
|
103
103
|
serialize?: (value: any) => string;
|
|
104
104
|
deserialize?: (value: string) => any;
|
|
105
105
|
timeout?: number;
|
|
106
106
|
def?: any;
|
|
107
107
|
}
|
|
108
108
|
declare type ConfigStore<State, Err = Error> = { ... } & SessionStorageConfig &
|
|
109
|
-
ConfigStore$1<State, Err
|
|
109
|
+
ConfigStore$1<State, Err>;
|
|
110
110
|
declare type ConfigSourceTarget<State, Err = Error> = {
|
|
111
111
|
...
|
|
112
112
|
} & SessionStorageConfig &
|
|
113
|
-
ConfigSourceTarget$1<State, Err
|
|
113
|
+
ConfigSourceTarget$1<State, Err>;
|
|
114
114
|
declare interface Persist {
|
|
115
115
|
<State, Err>(config: ConfigSourceTarget<State, Err>): Subscription;
|
|
116
116
|
<State, Err>(config: ConfigStore<State, Err>): Subscription;
|
|
117
117
|
}
|
|
118
|
-
declare var session: typeof npm$namespace$session
|
|
118
|
+
declare var session: typeof npm$namespace$session;
|
|
119
119
|
|
|
120
120
|
declare var npm$namespace$session: {|
|
|
121
121
|
(config?: SessionStorageConfig): StorageAdapter,
|
|
122
122
|
factory: typeof session$factory,
|
|
123
|
-
|}
|
|
124
|
-
declare var session$factory: true
|
|
125
|
-
declare function createPersist(defaults?: ConfigPersist): Persist
|
|
126
|
-
declare var persist: Persist
|
|
127
|
-
|
|
123
|
+
|};
|
|
124
|
+
declare var session$factory: true;
|
|
125
|
+
declare function createPersist(defaults?: ConfigPersist): Persist;
|
|
126
|
+
declare var persist: Persist;
|
|
127
|
+
export type {
|
|
128
128
|
ConfigPersist,
|
|
129
129
|
ConfigSourceTarget,
|
|
130
130
|
ConfigStore,
|
|
@@ -136,7 +136,5 @@ declare export {
|
|
|
136
136
|
SessionStorageConfig,
|
|
137
137
|
StorageAdapter,
|
|
138
138
|
StorageAdapterFactory,
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
session,
|
|
142
|
-
}
|
|
139
|
+
};
|
|
140
|
+
declare export { createPersist, persist, session };
|
package/session/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/storage/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/storage/index.ts"],"sourcesContent":["import type { StorageAdapter } from '../types'\n\nexport interface StorageConfig {\n storage: () => Storage\n sync?: boolean | 'force'\n serialize?: (value: any) => string\n deserialize?: (value: string) => any\n timeout?: number\n def?: any\n}\n\n/**\n * Creates generic `Storage` adapter\n */\nstorage.factory = true as const\nexport function storage({\n storage,\n sync = false,\n serialize = JSON.stringify,\n deserialize = JSON.parse,\n timeout,\n def,\n}: StorageConfig): StorageAdapter {\n const adapter: StorageAdapter = <State>(\n key: string,\n update: (raw?: any) =>
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/storage/index.ts"],"sourcesContent":["import type { StorageAdapter } from '../types'\n\nexport interface StorageConfig {\n storage: () => Storage\n sync?: boolean | 'force'\n serialize?: (value: any) => string\n deserialize?: (value: string) => any\n timeout?: number\n def?: any\n}\n\n/**\n * Creates generic `Storage` adapter\n */\nstorage.factory = true as const\nexport function storage({\n storage,\n sync = false,\n serialize = JSON.stringify,\n deserialize = JSON.parse,\n timeout,\n def,\n}: StorageConfig): StorageAdapter {\n const adapter: StorageAdapter = <State>(\n key: string,\n update: (raw?: any) => void\n ) => {\n let scheduled: ReturnType<typeof setTimeout> | undefined\n let unsaved: State\n let to: Storage\n\n // flush unsaved changes to Storage\n const flush = () => to.setItem(key, serialize(unsaved))\n\n // postponed flush unsaved changes to Storage\n const postponed = (e?: BeforeUnloadEvent | 1) => {\n scheduled = clearTimeout(scheduled) as undefined\n if (e) flush()\n\n // according to documentation, it is recommended to remove 'beforeunload' listener\n // as soon as possible to minimize the effect on performance\n // https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event\n if (typeof removeEventListener !== 'undefined') {\n removeEventListener('beforeunload', postponed)\n }\n }\n\n // schedule postponed flush unsaved changes to Storage\n const schedule = () => {\n scheduled = setTimeout(postponed, timeout, 1)\n\n // according to documentation, it is recommended to add 'beforeunload' listener\n // ONLY when it is necessary, when there are actually unsaved changes\n // https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event\n if (typeof addEventListener !== 'undefined') {\n addEventListener('beforeunload', postponed)\n }\n }\n\n if (sync && typeof addEventListener !== 'undefined') {\n addEventListener('storage', (e) => {\n // I hope storage is accessible in case 'storage' event is happening\n // so calling `storage()` should not throw security exception here\n if (e.storageArea === storage()) {\n // call `get` function with new value or undefined in case of force update\n if (e.key === key) update(sync === 'force' ? undefined : e.newValue)\n\n // `key` attribute is `null` when the change is caused by the storage `clear()` method\n if (e.key === null) update(null)\n }\n })\n }\n\n return {\n get(raw?: string | null) {\n postponed() // cancel postponed flush\n const item = raw !== undefined ? raw : storage().getItem(key)\n return item === null\n ? def !== undefined\n ? def\n : raw // 'undefined' when pickup, 'null' when clear\n : deserialize(item)\n },\n\n set(value: State) {\n unsaved = value\n to = storage()\n if (timeout === undefined) {\n flush()\n } else if (!scheduled) {\n schedule()\n }\n },\n }\n }\n\n try {\n adapter.keyArea = storage()\n } catch (error) {\n // do nothing\n }\n\n return adapter\n}\n"],"names":["storage","sync","serialize","JSON","stringify","deserialize","parse","timeout","def","adapter","key","update","scheduled","unsaved","to","flush","setItem","postponed","e","clearTimeout","removeEventListener","addEventListener","storageArea","undefined","newValue","get","raw","item","getItem","set","value","setTimeout","keyArea","error","factory"],"mappings":"aAeO,SAASA,GAAQA,QACtBA,EAAOC,KACPA,GAAO,EAAKC,UACZA,EAAYC,KAAKC,UAASC,YAC1BA,EAAcF,KAAKG,MAAKC,QACxBA,EAAOC,IACPA,IAEA,IAAMC,EAA0BA,CAC9BC,EACAC,KAEA,IAAIC,EACAC,EACAC,EAGEC,EAAQA,IAAMD,EAAGE,QAAQN,EAAKR,EAAUW,IAGxCI,EAAaC,IACjBN,EAAYO,aAAaP,GACrBM,GAAGH,IAK4B,oBAAxBK,qBACTA,oBAAoB,eAAgBH,EACtC,EA6BF,OAdIhB,GAAoC,oBAArBoB,kBACjBA,iBAAiB,WAAYH,IAGvBA,EAAEI,cAAgBtB,MAEhBkB,EAAER,MAAQA,GAAKC,EAAgB,UAATV,OAAmBsB,EAAYL,EAAEM,UAG7C,OAAVN,EAAER,KAAcC,EAAO,MAC7B,IAIG,CACLc,GAAAA,CAAIC,GACFT,IACA,IAAMU,OAAeJ,IAARG,EAAoBA,EAAM1B,IAAU4B,QAAQlB,GACzD,OAAgB,OAATiB,OACKJ,IAARf,EACEA,EACAkB,EACFrB,EAAYsB,EACjB,EAEDE,GAAAA,CAAIC,GACFjB,EAAUiB,EACVhB,EAAKd,SACWuB,IAAZhB,EACFQ,IACUH,IAxCdA,EAAYmB,WAAWd,EAAWV,EAAS,GAKX,oBAArBc,kBACTA,iBAAiB,eAAgBJ,GAqCnC,EACD,EAGH,IACER,EAAQuB,QAAUhC,GACnB,CAAC,MAAOiC,GACP,CAGF,OAAOxB,CACT,CAzFAT,EAAQkC,SAAU"}
|
|
@@ -0,0 +1,23 @@
|
|
|
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 StorageConfig {
|
|
11
|
+
storage: () => Storage;
|
|
12
|
+
sync?: boolean | 'force';
|
|
13
|
+
serialize?: (value: any) => string;
|
|
14
|
+
deserialize?: (value: string) => any;
|
|
15
|
+
timeout?: number;
|
|
16
|
+
def?: any;
|
|
17
|
+
}
|
|
18
|
+
declare function storage({ storage, sync, serialize, deserialize, timeout, def, }: StorageConfig): StorageAdapter;
|
|
19
|
+
declare namespace storage {
|
|
20
|
+
var factory: true;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { type StorageConfig, storage };
|
package/storage/index.d.ts
CHANGED
|
@@ -1,30 +1,23 @@
|
|
|
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 StorageConfig {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
storage: () => Storage;
|
|
12
|
+
sync?: boolean | 'force';
|
|
13
|
+
serialize?: (value: any) => string;
|
|
14
|
+
deserialize?: (value: string) => any;
|
|
15
|
+
timeout?: number;
|
|
16
|
+
def?: any;
|
|
17
17
|
}
|
|
18
|
-
declare function storage({
|
|
19
|
-
storage,
|
|
20
|
-
sync,
|
|
21
|
-
serialize,
|
|
22
|
-
deserialize,
|
|
23
|
-
timeout,
|
|
24
|
-
def,
|
|
25
|
-
}: StorageConfig): StorageAdapter
|
|
18
|
+
declare function storage({ storage, sync, serialize, deserialize, timeout, def, }: StorageConfig): StorageAdapter;
|
|
26
19
|
declare namespace storage {
|
|
27
|
-
|
|
20
|
+
var factory: true;
|
|
28
21
|
}
|
|
29
22
|
|
|
30
|
-
export { StorageConfig, storage }
|
|
23
|
+
export { type StorageConfig, storage };
|
package/storage/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,
|
|
@@ -19,17 +19,18 @@ declare interface StorageAdapter {
|
|
|
19
19
|
}
|
|
20
20
|
declare interface StorageConfig {
|
|
21
21
|
storage: () => Storage;
|
|
22
|
-
sync?: boolean |
|
|
22
|
+
sync?: boolean | "force";
|
|
23
23
|
serialize?: (value: any) => string;
|
|
24
24
|
deserialize?: (value: string) => any;
|
|
25
25
|
timeout?: number;
|
|
26
26
|
def?: any;
|
|
27
27
|
}
|
|
28
|
-
declare var storage: typeof npm$namespace$storage
|
|
28
|
+
declare var storage: typeof npm$namespace$storage;
|
|
29
29
|
|
|
30
30
|
declare var npm$namespace$storage: {|
|
|
31
31
|
(x: StorageConfig): StorageAdapter,
|
|
32
32
|
factory: typeof storage$factory,
|
|
33
|
-
|}
|
|
34
|
-
declare var storage$factory: true
|
|
35
|
-
|
|
33
|
+
|};
|
|
34
|
+
declare var storage$factory: true;
|
|
35
|
+
export type { StorageConfig };
|
|
36
|
+
declare export { storage };
|
package/storage/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/storage/index.ts"],"sourcesContent":["import type { StorageAdapter } from '../types'\n\nexport interface StorageConfig {\n storage: () => Storage\n sync?: boolean | 'force'\n serialize?: (value: any) => string\n deserialize?: (value: string) => any\n timeout?: number\n def?: any\n}\n\n/**\n * Creates generic `Storage` adapter\n */\nstorage.factory = true as const\nexport function storage({\n storage,\n sync = false,\n serialize = JSON.stringify,\n deserialize = JSON.parse,\n timeout,\n def,\n}: StorageConfig): StorageAdapter {\n const adapter: StorageAdapter = <State>(\n key: string,\n update: (raw?: any) =>
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/storage/index.ts"],"sourcesContent":["import type { StorageAdapter } from '../types'\n\nexport interface StorageConfig {\n storage: () => Storage\n sync?: boolean | 'force'\n serialize?: (value: any) => string\n deserialize?: (value: string) => any\n timeout?: number\n def?: any\n}\n\n/**\n * Creates generic `Storage` adapter\n */\nstorage.factory = true as const\nexport function storage({\n storage,\n sync = false,\n serialize = JSON.stringify,\n deserialize = JSON.parse,\n timeout,\n def,\n}: StorageConfig): StorageAdapter {\n const adapter: StorageAdapter = <State>(\n key: string,\n update: (raw?: any) => void\n ) => {\n let scheduled: ReturnType<typeof setTimeout> | undefined\n let unsaved: State\n let to: Storage\n\n // flush unsaved changes to Storage\n const flush = () => to.setItem(key, serialize(unsaved))\n\n // postponed flush unsaved changes to Storage\n const postponed = (e?: BeforeUnloadEvent | 1) => {\n scheduled = clearTimeout(scheduled) as undefined\n if (e) flush()\n\n // according to documentation, it is recommended to remove 'beforeunload' listener\n // as soon as possible to minimize the effect on performance\n // https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event\n if (typeof removeEventListener !== 'undefined') {\n removeEventListener('beforeunload', postponed)\n }\n }\n\n // schedule postponed flush unsaved changes to Storage\n const schedule = () => {\n scheduled = setTimeout(postponed, timeout, 1)\n\n // according to documentation, it is recommended to add 'beforeunload' listener\n // ONLY when it is necessary, when there are actually unsaved changes\n // https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event\n if (typeof addEventListener !== 'undefined') {\n addEventListener('beforeunload', postponed)\n }\n }\n\n if (sync && typeof addEventListener !== 'undefined') {\n addEventListener('storage', (e) => {\n // I hope storage is accessible in case 'storage' event is happening\n // so calling `storage()` should not throw security exception here\n if (e.storageArea === storage()) {\n // call `get` function with new value or undefined in case of force update\n if (e.key === key) update(sync === 'force' ? undefined : e.newValue)\n\n // `key` attribute is `null` when the change is caused by the storage `clear()` method\n if (e.key === null) update(null)\n }\n })\n }\n\n return {\n get(raw?: string | null) {\n postponed() // cancel postponed flush\n const item = raw !== undefined ? raw : storage().getItem(key)\n return item === null\n ? def !== undefined\n ? def\n : raw // 'undefined' when pickup, 'null' when clear\n : deserialize(item)\n },\n\n set(value: State) {\n unsaved = value\n to = storage()\n if (timeout === undefined) {\n flush()\n } else if (!scheduled) {\n schedule()\n }\n },\n }\n }\n\n try {\n adapter.keyArea = storage()\n } catch (error) {\n // do nothing\n }\n\n return adapter\n}\n"],"names":["storage","sync","serialize","JSON","stringify","deserialize","parse","timeout","def","adapter","key","update","scheduled","unsaved","to","flush","setItem","postponed","e","clearTimeout","removeEventListener","addEventListener","storageArea","undefined","newValue","get","raw","item","getItem","set","value","setTimeout","keyArea","error","factory"],"mappings":"AAeO,SAASA,GAAQA,QACtBA,EAAOC,KACPA,GAAO,EAAKC,UACZA,EAAYC,KAAKC,UAASC,YAC1BA,EAAcF,KAAKG,MAAKC,QACxBA,EAAOC,IACPA,IAEA,IAAMC,EAA0BA,CAC9BC,EACAC,KAEA,IAAIC,EACAC,EACAC,EAGEC,EAAQA,IAAMD,EAAGE,QAAQN,EAAKR,EAAUW,IAGxCI,EAAaC,IACjBN,EAAYO,aAAaP,GACrBM,GAAGH,IAK4B,oBAAxBK,qBACTA,oBAAoB,eAAgBH,EACtC,EA6BF,OAdIhB,GAAoC,oBAArBoB,kBACjBA,iBAAiB,WAAYH,IAGvBA,EAAEI,cAAgBtB,MAEhBkB,EAAER,MAAQA,GAAKC,EAAgB,UAATV,OAAmBsB,EAAYL,EAAEM,UAG7C,OAAVN,EAAER,KAAcC,EAAO,MAC7B,IAIG,CACLc,GAAAA,CAAIC,GACFT,IACA,IAAMU,OAAeJ,IAARG,EAAoBA,EAAM1B,IAAU4B,QAAQlB,GACzD,OAAgB,OAATiB,OACKJ,IAARf,EACEA,EACAkB,EACFrB,EAAYsB,EACjB,EAEDE,GAAAA,CAAIC,GACFjB,EAAUiB,EACVhB,EAAKd,SACWuB,IAAZhB,EACFQ,IACUH,IAxCdA,EAAYmB,WAAWd,EAAWV,EAAS,GAKX,oBAArBc,kBACTA,iBAAiB,eAAgBJ,GAqCnC,EACD,EAGH,IACER,EAAQuB,QAAUhC,GACnB,CAAC,MAAOiC,GACP,CAGF,OAAOxB,CACT,CAzFAT,EAAQkC,SAAU"}
|
package/storage/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/tools/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/tools/async.ts","../../src/tools/either.ts","../../src/tools/farcached.ts"],"sourcesContent":["import type { StorageAdapter, StorageAdapterFactory } from '../types'\n\n/**\n * Makes synchronous storage adapter asynchronous\n */\n\nexport function async<A extends StorageAdapter | StorageAdapterFactory<any>>(\n adapter: A\n): A extends StorageAdapterFactory<infer T>\n ? StorageAdapterFactory<T>\n : StorageAdapter\n\nexport function async<T>(\n adapterOrFactory: StorageAdapter | StorageAdapterFactory<T>\n): StorageAdapter | StorageAdapterFactory<T> {\n const isFactory = 'factory' in adapterOrFactory\n\n create.factory = true as const\n function create(config?: T) {\n const adapter = isFactory ? adapterOrFactory(config) : adapterOrFactory\n\n const asyncAdapter: StorageAdapter = <State>(\n key: string,\n update: (raw?: any) =>
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/tools/async.ts","../../src/tools/either.ts","../../src/tools/farcached.ts"],"sourcesContent":["import type { StorageAdapter, StorageAdapterFactory } from '../types'\n\n/**\n * Makes synchronous storage adapter asynchronous\n */\n\nexport function async<A extends StorageAdapter | StorageAdapterFactory<any>>(\n adapter: A\n): A extends StorageAdapterFactory<infer T>\n ? StorageAdapterFactory<T>\n : StorageAdapter\n\nexport function async<T>(\n adapterOrFactory: StorageAdapter | StorageAdapterFactory<T>\n): StorageAdapter | StorageAdapterFactory<T> {\n const isFactory = 'factory' in adapterOrFactory\n\n create.factory = true as const\n function create(config?: T) {\n const adapter = isFactory ? adapterOrFactory(config) : adapterOrFactory\n\n const asyncAdapter: StorageAdapter = <State>(\n key: string,\n update: (raw?: any) => void\n ) => {\n const { get, set } = adapter<State>(key, update)\n return {\n get: async (value?: any, ctx?: any) => get(await value, ctx),\n set: async (value: State, ctx?: any) => set(await value, ctx),\n }\n }\n\n asyncAdapter.keyArea = adapter.keyArea\n asyncAdapter.noop = adapter.noop\n return asyncAdapter\n }\n\n return isFactory ? create : create()\n}\n","import type { StorageAdapter, StorageAdapterFactory } from '../types'\n\n/**\n * Returns first adapter, if it is not noop, and second otherwise.\n *\n * In this example,\n * - adapter for localStorage will be used in browser environment,\n * - logging adapter will be used in node environment\n *\n * persist({\n * store: $store,\n * adapter: either(local(), log()),\n * key: 'store'\n * })\n *\n * could be also used with factories\n *\n * persist({\n * store: $store,\n * adapter: either(local, log),\n * key: 'store'\n * })\n *\n * or even mixed\n *\n * persist({\n * store: $store,\n * adapter: either(local, log()),\n * key: 'store'\n * })\n */\n\nexport function either<\n A1 extends StorageAdapter | StorageAdapterFactory<any>,\n A2 extends StorageAdapter | StorageAdapterFactory<any>,\n>(\n one: A1,\n another: A2\n): A1 extends StorageAdapterFactory<infer T1>\n ? A2 extends StorageAdapterFactory<infer T2>\n ? StorageAdapterFactory<T1 & T2>\n : StorageAdapterFactory<T1>\n : A2 extends StorageAdapterFactory<infer T2>\n ? StorageAdapterFactory<T2>\n : StorageAdapter\n\nexport function either<T1, T2>(\n one: StorageAdapter | StorageAdapterFactory<T1>,\n another: StorageAdapter | StorageAdapterFactory<T2>\n): StorageAdapter | StorageAdapterFactory<T1 & T2> {\n const isFactory1 = 'factory' in one\n const isFactory2 = 'factory' in another\n\n create.factory = true as const\n function create(config?: T1 & T2) {\n const adapter1 = isFactory1 ? one(config) : one\n const adapter2 = isFactory2 ? another(config) : another\n return adapter1.noop ? adapter2 : adapter1\n }\n\n return isFactory1 || isFactory2 ? create : create()\n}\n","import type { StorageAdapter } from '../types'\nimport type { CacheAdapter } from '@farfetched/core'\nimport { attach } from 'effector'\n\n/**\n * Wraps @farfetched/core cache adapter to be used as `persist` adapter :)\n * @see https://farfetched.pages.dev/api/operators/cache.html\n *\n * persist({\n * store: $store,\n * adapter: farcached(localStorageCache({ maxAge: '15m' })),\n * key: 'store'\n * })\n *\n * Out of the box Farfetched provides 4 cache adapters:\n * - `inMemoryCache`\n * - `sessionStorageCache`\n * - `localStorageCache`\n * - `voidCache` (this one is noop)\n *\n * From real usage point of view, using Farfetched cache adapters could be useful,\n * when you need logic for cache invalidation, because all of provided adapters\n * have `maxAge` option.\n *\n * Also, you could use Farfetched cache adapters to inject different\n * cache adapters with `fork` using `cache.__.$instance` internal store.\n * @see https://farfetched.pages.dev/recipes/server_cache.html#inject-adapter\n */\n\nexport function farcached(\n adapter: CacheAdapter,\n keyArea?: any\n): StorageAdapter {\n const farfetchedAdapter: StorageAdapter = <State>(key: string) => {\n return {\n get: attach({\n source: adapter.__.$instance,\n async effect(instance: CacheAdapter) {\n const persisted = await instance.get({ key })\n return persisted?.value as State\n },\n } as any),\n set: attach({\n source: adapter.__.$instance,\n async effect(instance: CacheAdapter, value?: any) {\n return instance.set({ key, value })\n },\n } as any),\n }\n }\n\n farfetchedAdapter.keyArea = keyArea ?? adapter\n return farfetchedAdapter\n}\n"],"names":["adapterOrFactory","isFactory","create","config","adapter","asyncAdapter","key","update","get","set","async","value","ctx","keyArea","noop","factory","one","another","isFactory1","isFactory2","adapter1","adapter2","farfetchedAdapter","attach","source","__","$instance","effect","instance","persisted"],"mappings":"qDAYO,SACLA,GAEA,IAAMC,EAAY,YAAaD,EAG/B,SAASE,EAAOC,GACd,IAAMC,EAAUH,EAAYD,EAAiBG,GAAUH,EAEjDK,EAA+BA,CACnCC,EACAC,KAEA,IAAMC,IAAEA,EAAGC,IAAEA,GAAQL,EAAeE,EAAKC,GACzC,MAAO,CACLC,IAAKE,MAAOC,EAAaC,IAAcJ,QAAUG,EAAOC,GACxDH,IAAKC,MAAOC,EAAcC,IAAcH,QAAUE,EAAOC,GAC1D,EAKH,OAFAP,EAAaQ,QAAUT,EAAQS,QAC/BR,EAAaS,KAAOV,EAAQU,KACrBT,CACT,CAEA,OApBAH,EAAOa,SAAU,EAoBVd,EAAYC,EAASA,GAC9B,iBCQO,SACLc,EACAC,GAEA,IAAMC,EAAa,YAAaF,EAC1BG,EAAa,YAAaF,EAGhC,SAASf,EAAOC,GACd,IAAMiB,EAAWF,EAAaF,EAAIb,GAAUa,EACtCK,EAAWF,EAAaF,EAAQd,GAAUc,EAChD,OAAOG,EAASN,KAAOO,EAAWD,CACpC,CAEA,OAPAlB,EAAOa,SAAU,EAOVG,GAAcC,EAAajB,EAASA,GAC7C,oBChCO,SACLE,EACAS,GAEA,IAAMS,EAA4ChB,IACzC,CACLE,IAAKe,EAAAA,OAAO,CACVC,OAAQpB,EAAQqB,GAAGC,UACnB,YAAMC,CAAOC,GACX,IAAMC,QAAkBD,EAASpB,IAAI,CAAEF,QACvC,OAAOuB,GAAWlB,KACpB,IAEFF,IAAKc,EAAAA,OAAO,CACVC,OAAQpB,EAAQqB,GAAGC,UACnBhB,OAAYiB,MAACC,EAAwBjB,IAC5BiB,EAASnB,IAAI,CAAEH,MAAKK,cAOnC,OADAW,EAAkBT,QAAUA,GAAWT,EAChCkB,CACT"}
|