effector-storage 5.0.0 → 6.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 +77 -12
- package/async-storage/index.cjs +1 -1
- package/async-storage/index.cjs.d.ts +12 -5
- package/async-storage/index.cjs.map +1 -1
- package/async-storage/index.d.ts +12 -5
- package/async-storage/index.js +1 -1
- package/async-storage/index.js.flow +21 -4
- package/async-storage/index.js.map +1 -1
- package/async-storage/package.json +1 -0
- package/core/index.cjs +2 -0
- package/core/index.cjs.d.ts +90 -0
- package/core/index.cjs.map +1 -0
- package/core/index.d.ts +90 -0
- package/core/index.js +2 -0
- package/core/index.js.flow +113 -0
- package/core/index.js.map +1 -0
- package/core/package.json +8 -0
- package/index.cjs +1 -1
- package/index.cjs.d.ts +53 -12
- package/index.cjs.map +1 -1
- package/index.d.ts +53 -12
- package/index.js +1 -1
- package/index.js.flow +60 -10
- package/index.js.map +1 -1
- package/local/index.cjs +1 -1
- package/local/index.cjs.d.ts +36 -11
- package/local/index.cjs.map +1 -1
- package/local/index.d.ts +36 -11
- package/local/index.js +1 -1
- package/local/index.js.flow +40 -9
- package/local/index.js.map +1 -1
- package/local/package.json +1 -0
- package/log/index.cjs +2 -0
- package/log/index.cjs.d.ts +19 -0
- package/log/index.cjs.map +1 -0
- package/log/index.d.ts +19 -0
- package/log/index.js +2 -0
- package/log/index.js.flow +31 -0
- package/log/index.js.map +1 -0
- package/log/package.json +8 -0
- package/memory/index.cjs +1 -1
- package/memory/index.cjs.d.ts +33 -5
- package/memory/index.cjs.map +1 -1
- package/memory/index.d.ts +33 -5
- package/memory/index.js +1 -1
- package/memory/index.js.flow +33 -3
- package/memory/index.js.map +1 -1
- package/memory/package.json +1 -0
- package/nil/index.cjs +1 -1
- package/nil/index.cjs.d.ts +16 -6
- package/nil/index.cjs.map +1 -1
- package/nil/index.d.ts +16 -6
- package/nil/index.js +1 -1
- package/nil/index.js.flow +24 -4
- package/nil/index.js.map +1 -1
- package/nil/package.json +1 -0
- package/package.json +20 -4
- package/query/index.cjs +1 -1
- package/query/index.cjs.d.ts +41 -18
- package/query/index.cjs.map +1 -1
- package/query/index.d.ts +41 -18
- package/query/index.js +1 -1
- package/query/index.js.flow +41 -11
- package/query/index.js.map +1 -1
- package/query/package.json +1 -0
- package/rn/async/index.cjs +1 -1
- package/rn/async/index.cjs.d.ts +31 -9
- package/rn/async/index.cjs.map +1 -1
- package/rn/async/index.d.ts +31 -9
- package/rn/async/index.js +1 -1
- package/rn/async/index.js.flow +35 -7
- package/rn/async/index.js.map +1 -1
- package/rn/async/package.json +1 -0
- package/rn/encrypted/index.cjs +1 -1
- package/rn/encrypted/index.cjs.d.ts +26 -9
- package/rn/encrypted/index.cjs.map +1 -1
- package/rn/encrypted/index.d.ts +26 -9
- package/rn/encrypted/index.js +1 -1
- package/rn/encrypted/index.js.flow +32 -7
- package/rn/encrypted/index.js.map +1 -1
- package/rn/encrypted/package.json +1 -0
- package/session/index.cjs +1 -1
- package/session/index.cjs.d.ts +36 -11
- package/session/index.cjs.map +1 -1
- package/session/index.d.ts +36 -11
- package/session/index.js +1 -1
- package/session/index.js.flow +40 -9
- package/session/index.js.map +1 -1
- package/session/package.json +1 -0
- package/storage/index.cjs +1 -1
- package/storage/index.cjs.d.ts +17 -6
- package/storage/index.cjs.map +1 -1
- package/storage/index.d.ts +17 -6
- package/storage/index.js +1 -1
- package/storage/index.js.flow +24 -5
- package/storage/index.js.map +1 -1
- package/storage/package.json +1 -0
- package/tools/index.cjs +2 -0
- package/tools/index.cjs.d.ts +125 -0
- package/tools/index.cjs.map +1 -0
- package/tools/index.d.ts +125 -0
- package/tools/index.js +2 -0
- package/tools/index.js.flow +101 -0
- package/tools/index.js.map +1 -0
- package/tools/package.json +8 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for index
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// see https://gist.github.com/thecotne/6e5969f4aaf8f253985ed36b30ac9fe0
|
|
9
|
+
type $FlowGen$If<X: boolean, Then, Else = empty> = $Call<
|
|
10
|
+
((true, Then, Else) => Then) & ((false, Then, Else) => Else),
|
|
11
|
+
X,
|
|
12
|
+
Then,
|
|
13
|
+
Else
|
|
14
|
+
>
|
|
15
|
+
|
|
16
|
+
type $FlowGen$Assignable<A, B> = $Call<
|
|
17
|
+
((...r: [B]) => true) & ((...r: [A]) => false),
|
|
18
|
+
A
|
|
19
|
+
>
|
|
20
|
+
|
|
21
|
+
import { Store, Effect, Event } from 'effector'
|
|
22
|
+
declare interface StorageAdapter {
|
|
23
|
+
<State>(
|
|
24
|
+
key: string,
|
|
25
|
+
update: (raw?: any) => any
|
|
26
|
+
): {
|
|
27
|
+
get(raw?: any, ctx?: any): State | Promise<State>,
|
|
28
|
+
set(value: State, ctx?: any): void,
|
|
29
|
+
...
|
|
30
|
+
};
|
|
31
|
+
keyArea?: any;
|
|
32
|
+
noop?: boolean;
|
|
33
|
+
}
|
|
34
|
+
declare interface StorageAdapterFactory<AdapterConfig> {
|
|
35
|
+
(config?: AdapterConfig): StorageAdapter;
|
|
36
|
+
factory: true;
|
|
37
|
+
}
|
|
38
|
+
declare function async<A: StorageAdapter | StorageAdapterFactory<any>>(
|
|
39
|
+
adapter: A
|
|
40
|
+
): $FlowGen$If<
|
|
41
|
+
$FlowGen$Assignable<A, StorageAdapterFactory<T>>,
|
|
42
|
+
StorageAdapterFactory<T>,
|
|
43
|
+
StorageAdapter
|
|
44
|
+
>
|
|
45
|
+
declare function either<
|
|
46
|
+
A1: StorageAdapter | StorageAdapterFactory<any>,
|
|
47
|
+
A2: StorageAdapter | StorageAdapterFactory<any>
|
|
48
|
+
>(
|
|
49
|
+
one: A1,
|
|
50
|
+
another: A2
|
|
51
|
+
): $FlowGen$If<
|
|
52
|
+
$FlowGen$Assignable<A1, StorageAdapterFactory<T1>>,
|
|
53
|
+
$FlowGen$If<
|
|
54
|
+
$FlowGen$Assignable<A2, StorageAdapterFactory<T2>>,
|
|
55
|
+
StorageAdapterFactory<{ ...T1, ...T2 }>,
|
|
56
|
+
StorageAdapterFactory<T1>
|
|
57
|
+
>,
|
|
58
|
+
$FlowGen$If<
|
|
59
|
+
$FlowGen$Assignable<A2, StorageAdapterFactory<T2>>,
|
|
60
|
+
StorageAdapterFactory<T2>,
|
|
61
|
+
StorageAdapter
|
|
62
|
+
>
|
|
63
|
+
>
|
|
64
|
+
declare interface CacheAdapterInstance {
|
|
65
|
+
get: Effect<
|
|
66
|
+
{
|
|
67
|
+
key: string,
|
|
68
|
+
...
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
value: mixed,
|
|
72
|
+
cachedAt: number,
|
|
73
|
+
...
|
|
74
|
+
} | null
|
|
75
|
+
>;
|
|
76
|
+
set: Effect<
|
|
77
|
+
{
|
|
78
|
+
key: string,
|
|
79
|
+
value: mixed,
|
|
80
|
+
...
|
|
81
|
+
},
|
|
82
|
+
void
|
|
83
|
+
>;
|
|
84
|
+
purge: Event<void>;
|
|
85
|
+
unset: Effect<
|
|
86
|
+
{
|
|
87
|
+
key: string,
|
|
88
|
+
...
|
|
89
|
+
},
|
|
90
|
+
void
|
|
91
|
+
>;
|
|
92
|
+
}
|
|
93
|
+
declare type CacheAdapter = {
|
|
94
|
+
__: {
|
|
95
|
+
$instance: Store<CacheAdapterInstance>,
|
|
96
|
+
...
|
|
97
|
+
},
|
|
98
|
+
...
|
|
99
|
+
} & CacheAdapterInstance
|
|
100
|
+
declare function farcached(adapter: CacheAdapter, keyArea?: any): StorageAdapter
|
|
101
|
+
declare export { async, either, farcached }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","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) => any\n ) => {\n const { get, set } = adapter<State>(key, update)\n return {\n get: (value: State) => Promise.resolve(value).then(get),\n set: (value?: any) => Promise.resolve(value).then(set),\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":["async","adapterOrFactory","isFactory","create","config","adapter","asyncAdapter","key","update","get","set","value","Promise","resolve","then","keyArea","noop","factory","either","one","another","isFactory1","isFactory2","adapter1","adapter2","farcached","farfetchedAdapter","attach","source","__","$instance","instance","persisted","effect"],"mappings":"kCAYO,SAASA,EACdC,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,IAAME,GAAiBC,QAAQC,QAAQF,GAAOG,KAAKL,GACnDC,IAAMC,GAAgBC,QAAQC,QAAQF,GAAOG,KAAKJ,GACnD,EAKH,OAFAJ,EAAaS,QAAUV,EAAQU,QAC/BT,EAAaU,KAAOX,EAAQW,KACrBV,CACT,CAEA,OApBAH,EAAOc,SAAU,EAoBVf,EAAYC,EAASA,GAC9B,CCQO,SAASe,EACdC,EACAC,GAEA,IAAMC,EAAa,YAAaF,EAC1BG,EAAa,YAAaF,EAGhC,SAASjB,EAAOC,GACd,IAAMmB,EAAWF,EAAaF,EAAIf,GAAUe,EACtCK,EAAWF,EAAaF,EAAQhB,GAAUgB,EAChD,OAAOG,EAASP,KAAOQ,EAAWD,CACpC,CAEA,OAPApB,EAAOc,SAAU,EAOVI,GAAcC,EAAanB,EAASA,GAC7C,CChCO,SAASsB,EACdpB,EACAU,GAEA,IAAMW,EAA4CnB,IACzC,CACLE,IAAKkB,EAAO,CACVC,OAAQvB,EAAQwB,GAAGC,UACnB9B,aAAa+B,GACX,IAAMC,QAAkBD,EAAStB,IAAI,CAAEF,QACvC,OAAOyB,GAAWrB,KACpB,IAEFD,IAAKiB,EAAO,CACVC,OAAQvB,EAAQwB,GAAGC,UACnB9B,OAAYiC,MAACF,EAAwBpB,IAC5BoB,EAASrB,IAAI,CAAEH,MAAKI,cAOnC,OADAe,EAAkBX,QAAUA,GAAWV,EAChCqB,CACT"}
|