effector-storage 6.1.1 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/README.md +7 -40
  2. package/async-storage/index.cjs.map +1 -1
  3. package/async-storage/index.d.cts +24 -0
  4. package/async-storage/index.d.ts +14 -18
  5. package/async-storage/index.js.flow +6 -5
  6. package/async-storage/index.js.map +1 -1
  7. package/async-storage/package.json +15 -2
  8. package/broadcast/index.cjs.map +1 -1
  9. package/broadcast/index.d.cts +94 -0
  10. package/broadcast/index.d.ts +63 -85
  11. package/broadcast/index.js.flow +23 -25
  12. package/broadcast/index.js.map +1 -1
  13. package/broadcast/package.json +15 -2
  14. package/core/index.cjs +1 -1
  15. package/core/index.cjs.map +1 -1
  16. package/core/index.d.cts +77 -0
  17. package/core/index.d.ts +53 -66
  18. package/core/index.js +1 -1
  19. package/core/index.js.flow +14 -14
  20. package/core/index.js.map +1 -1
  21. package/core/package.json +15 -2
  22. package/index.d.cts +97 -0
  23. package/index.d.ts +68 -99
  24. package/index.js.flow +27 -28
  25. package/local/index.d.cts +99 -0
  26. package/local/index.d.ts +67 -90
  27. package/local/index.js.flow +25 -27
  28. package/local/package.json +15 -2
  29. package/log/index.cjs.map +1 -1
  30. package/log/index.d.cts +19 -0
  31. package/log/index.d.ts +11 -11
  32. package/log/index.js.flow +6 -5
  33. package/log/index.js.map +1 -1
  34. package/log/package.json +15 -2
  35. package/memory/index.d.cts +95 -0
  36. package/memory/index.d.ts +63 -82
  37. package/memory/index.js.flow +23 -25
  38. package/memory/package.json +15 -2
  39. package/nil/index.cjs.map +1 -1
  40. package/nil/index.d.cts +18 -0
  41. package/nil/index.d.ts +10 -10
  42. package/nil/index.js.flow +6 -5
  43. package/nil/index.js.map +1 -1
  44. package/nil/package.json +15 -2
  45. package/package.json +101 -57
  46. package/query/index.cjs.map +1 -1
  47. package/query/index.d.cts +108 -0
  48. package/query/index.d.ts +75 -104
  49. package/query/index.js.flow +30 -28
  50. package/query/index.js.map +1 -1
  51. package/query/package.json +15 -2
  52. package/session/index.d.cts +99 -0
  53. package/session/index.d.ts +67 -90
  54. package/session/index.js.flow +25 -27
  55. package/session/package.json +15 -2
  56. package/storage/index.cjs.map +1 -1
  57. package/storage/index.d.cts +23 -0
  58. package/storage/index.d.ts +15 -22
  59. package/storage/index.js.flow +7 -6
  60. package/storage/index.js.map +1 -1
  61. package/storage/package.json +15 -2
  62. package/tools/index.cjs.map +1 -1
  63. package/tools/{index.cjs.d.ts → index.d.cts} +33 -58
  64. package/tools/index.d.ts +33 -58
  65. package/tools/index.js.flow +13 -10
  66. package/tools/index.js.map +1 -1
  67. package/tools/package.json +15 -2
  68. package/async-storage/index.cjs.d.ts +0 -28
  69. package/broadcast/index.cjs.d.ts +0 -116
  70. package/core/index.cjs.d.ts +0 -90
  71. package/index.cjs.d.ts +0 -128
  72. package/local/index.cjs.d.ts +0 -122
  73. package/log/index.cjs.d.ts +0 -19
  74. package/memory/index.cjs.d.ts +0 -114
  75. package/nil/index.cjs.d.ts +0 -18
  76. package/query/index.cjs.d.ts +0 -137
  77. package/rn/async/index.cjs +0 -2
  78. package/rn/async/index.cjs.d.ts +0 -120
  79. package/rn/async/index.cjs.map +0 -1
  80. package/rn/async/index.d.ts +0 -120
  81. package/rn/async/index.js +0 -2
  82. package/rn/async/index.js.flow +0 -135
  83. package/rn/async/index.js.map +0 -1
  84. package/rn/async/package.json +0 -8
  85. package/rn/encrypted/index.cjs +0 -2
  86. package/rn/encrypted/index.cjs.d.ts +0 -120
  87. package/rn/encrypted/index.cjs.map +0 -1
  88. package/rn/encrypted/index.d.ts +0 -120
  89. package/rn/encrypted/index.js +0 -2
  90. package/rn/encrypted/index.js.flow +0 -137
  91. package/rn/encrypted/index.js.map +0 -1
  92. package/rn/encrypted/package.json +0 -8
  93. package/session/index.cjs.d.ts +0 -122
  94. package/storage/index.cjs.d.ts +0 -30
@@ -1,26 +1,22 @@
1
- import { Store, Effect, Event } from 'effector'
1
+ import { Store, Effect, EventCallable } from 'effector';
2
2
 
3
3
  interface StorageAdapter {
4
- <State>(key: string, update: (raw?: any) => any): {
5
- get(raw?: any, ctx?: any): State | Promise<State | undefined> | undefined
6
- set(value: State, ctx?: any): void
7
- }
8
- keyArea?: any
9
- noop?: boolean
4
+ <State>(key: string, update: (raw?: any) => void): {
5
+ get(raw?: any, ctx?: any): State | Promise<State | undefined> | undefined;
6
+ set(value: State, ctx?: any): void;
7
+ };
8
+ keyArea?: any;
9
+ noop?: boolean;
10
10
  }
11
11
  interface StorageAdapterFactory<AdapterConfig> {
12
- (config?: AdapterConfig): StorageAdapter
13
- factory: true
12
+ (config?: AdapterConfig): StorageAdapter;
13
+ factory: true;
14
14
  }
15
15
 
16
16
  /**
17
17
  * Makes synchronous storage adapter asynchronous
18
18
  */
19
- declare function async<A extends StorageAdapter | StorageAdapterFactory<any>>(
20
- adapter: A
21
- ): A extends StorageAdapterFactory<infer T>
22
- ? StorageAdapterFactory<T>
23
- : StorageAdapter
19
+ declare function async<A extends StorageAdapter | StorageAdapterFactory<any>>(adapter: A): A extends StorageAdapterFactory<infer T> ? StorageAdapterFactory<T> : StorageAdapter;
24
20
 
25
21
  /**
26
22
  * Returns first adapter, if it is not noop, and second otherwise.
@@ -51,49 +47,28 @@ declare function async<A extends StorageAdapter | StorageAdapterFactory<any>>(
51
47
  * key: 'store'
52
48
  * })
53
49
  */
54
- declare function either<
55
- A1 extends StorageAdapter | StorageAdapterFactory<any>,
56
- A2 extends StorageAdapter | StorageAdapterFactory<any>
57
- >(
58
- one: A1,
59
- another: A2
60
- ): A1 extends StorageAdapterFactory<infer T1>
61
- ? A2 extends StorageAdapterFactory<infer T2>
62
- ? StorageAdapterFactory<T1 & T2>
63
- : StorageAdapterFactory<T1>
64
- : A2 extends StorageAdapterFactory<infer T2>
65
- ? StorageAdapterFactory<T2>
66
- : StorageAdapter
50
+ declare function either<A1 extends StorageAdapter | StorageAdapterFactory<any>, A2 extends StorageAdapter | StorageAdapterFactory<any>>(one: A1, another: A2): A1 extends StorageAdapterFactory<infer T1> ? A2 extends StorageAdapterFactory<infer T2> ? StorageAdapterFactory<T1 & T2> : StorageAdapterFactory<T1> : A2 extends StorageAdapterFactory<infer T2> ? StorageAdapterFactory<T2> : StorageAdapter;
67
51
 
68
- interface CacheAdapterInstance {
69
- get: Effect<
70
- {
71
- key: string
72
- },
73
- {
74
- value: unknown
75
- cachedAt: number
76
- } | null
77
- >
78
- set: Effect<
79
- {
80
- key: string
81
- value: unknown
82
- },
83
- void
84
- >
85
- purge: Event<void>
86
- unset: Effect<
87
- {
88
- key: string
89
- },
90
- void
91
- >
92
- }
93
- interface CacheAdapter extends CacheAdapterInstance {
94
- __: {
95
- $instance: Store<CacheAdapterInstance>
96
- }
52
+ interface CacheAdapterInstance {
53
+ get: Effect<{
54
+ key: string;
55
+ }, {
56
+ value: unknown;
57
+ cachedAt: number;
58
+ } | null>;
59
+ set: Effect<{
60
+ key: string;
61
+ value: unknown;
62
+ }, void>;
63
+ purge: EventCallable<void>;
64
+ unset: Effect<{
65
+ key: string;
66
+ }, void>;
67
+ }
68
+ interface CacheAdapter extends CacheAdapterInstance {
69
+ __: {
70
+ $instance: Store<CacheAdapterInstance>;
71
+ };
97
72
  }
98
73
 
99
74
  /**
@@ -120,6 +95,6 @@ interface CacheAdapter extends CacheAdapterInstance {
120
95
  * cache adapters with `fork` using `cache.__.$instance` internal store.
121
96
  * @see https://farfetched.pages.dev/recipes/server_cache.html#inject-adapter
122
97
  */
123
- declare function farcached(adapter: CacheAdapter, keyArea?: any): StorageAdapter
98
+ declare function farcached(adapter: CacheAdapter, keyArea?: any): StorageAdapter;
124
99
 
125
- export { async, either, farcached }
100
+ export { async, either, farcached };
package/tools/index.d.ts CHANGED
@@ -1,26 +1,22 @@
1
- import { Store, Effect, Event } from 'effector'
1
+ import { Store, Effect, EventCallable } from 'effector';
2
2
 
3
3
  interface StorageAdapter {
4
- <State>(key: string, update: (raw?: any) => any): {
5
- get(raw?: any, ctx?: any): State | Promise<State | undefined> | undefined
6
- set(value: State, ctx?: any): void
7
- }
8
- keyArea?: any
9
- noop?: boolean
4
+ <State>(key: string, update: (raw?: any) => void): {
5
+ get(raw?: any, ctx?: any): State | Promise<State | undefined> | undefined;
6
+ set(value: State, ctx?: any): void;
7
+ };
8
+ keyArea?: any;
9
+ noop?: boolean;
10
10
  }
11
11
  interface StorageAdapterFactory<AdapterConfig> {
12
- (config?: AdapterConfig): StorageAdapter
13
- factory: true
12
+ (config?: AdapterConfig): StorageAdapter;
13
+ factory: true;
14
14
  }
15
15
 
16
16
  /**
17
17
  * Makes synchronous storage adapter asynchronous
18
18
  */
19
- declare function async<A extends StorageAdapter | StorageAdapterFactory<any>>(
20
- adapter: A
21
- ): A extends StorageAdapterFactory<infer T>
22
- ? StorageAdapterFactory<T>
23
- : StorageAdapter
19
+ declare function async<A extends StorageAdapter | StorageAdapterFactory<any>>(adapter: A): A extends StorageAdapterFactory<infer T> ? StorageAdapterFactory<T> : StorageAdapter;
24
20
 
25
21
  /**
26
22
  * Returns first adapter, if it is not noop, and second otherwise.
@@ -51,49 +47,28 @@ declare function async<A extends StorageAdapter | StorageAdapterFactory<any>>(
51
47
  * key: 'store'
52
48
  * })
53
49
  */
54
- declare function either<
55
- A1 extends StorageAdapter | StorageAdapterFactory<any>,
56
- A2 extends StorageAdapter | StorageAdapterFactory<any>
57
- >(
58
- one: A1,
59
- another: A2
60
- ): A1 extends StorageAdapterFactory<infer T1>
61
- ? A2 extends StorageAdapterFactory<infer T2>
62
- ? StorageAdapterFactory<T1 & T2>
63
- : StorageAdapterFactory<T1>
64
- : A2 extends StorageAdapterFactory<infer T2>
65
- ? StorageAdapterFactory<T2>
66
- : StorageAdapter
50
+ declare function either<A1 extends StorageAdapter | StorageAdapterFactory<any>, A2 extends StorageAdapter | StorageAdapterFactory<any>>(one: A1, another: A2): A1 extends StorageAdapterFactory<infer T1> ? A2 extends StorageAdapterFactory<infer T2> ? StorageAdapterFactory<T1 & T2> : StorageAdapterFactory<T1> : A2 extends StorageAdapterFactory<infer T2> ? StorageAdapterFactory<T2> : StorageAdapter;
67
51
 
68
- interface CacheAdapterInstance {
69
- get: Effect<
70
- {
71
- key: string
72
- },
73
- {
74
- value: unknown
75
- cachedAt: number
76
- } | null
77
- >
78
- set: Effect<
79
- {
80
- key: string
81
- value: unknown
82
- },
83
- void
84
- >
85
- purge: Event<void>
86
- unset: Effect<
87
- {
88
- key: string
89
- },
90
- void
91
- >
92
- }
93
- interface CacheAdapter extends CacheAdapterInstance {
94
- __: {
95
- $instance: Store<CacheAdapterInstance>
96
- }
52
+ interface CacheAdapterInstance {
53
+ get: Effect<{
54
+ key: string;
55
+ }, {
56
+ value: unknown;
57
+ cachedAt: number;
58
+ } | null>;
59
+ set: Effect<{
60
+ key: string;
61
+ value: unknown;
62
+ }, void>;
63
+ purge: EventCallable<void>;
64
+ unset: Effect<{
65
+ key: string;
66
+ }, void>;
67
+ }
68
+ interface CacheAdapter extends CacheAdapterInstance {
69
+ __: {
70
+ $instance: Store<CacheAdapterInstance>;
71
+ };
97
72
  }
98
73
 
99
74
  /**
@@ -120,6 +95,6 @@ interface CacheAdapter extends CacheAdapterInstance {
120
95
  * cache adapters with `fork` using `cache.__.$instance` internal store.
121
96
  * @see https://farfetched.pages.dev/recipes/server_cache.html#inject-adapter
122
97
  */
123
- declare function farcached(adapter: CacheAdapter, keyArea?: any): StorageAdapter
98
+ declare function farcached(adapter: CacheAdapter, keyArea?: any): StorageAdapter;
124
99
 
125
- export { async, either, farcached }
100
+ export { async, either, farcached };
@@ -11,18 +11,18 @@ type $FlowGen$If<X: boolean, Then, Else = empty> = $Call<
11
11
  X,
12
12
  Then,
13
13
  Else
14
- >
14
+ >;
15
15
 
16
16
  type $FlowGen$Assignable<A, B> = $Call<
17
17
  ((...r: [B]) => true) & ((...r: [A]) => false),
18
18
  A
19
- >
19
+ >;
20
20
 
21
- import { Store, Effect, Event } from 'effector'
21
+ import { Store, Effect, EventCallable } from "effector";
22
22
  declare interface StorageAdapter {
23
23
  <State>(
24
24
  key: string,
25
- update: (raw?: any) => any
25
+ update: (raw?: any) => void
26
26
  ): {
27
27
  get(raw?: any, ctx?: any): State | Promise<State | void> | void,
28
28
  set(value: State, ctx?: any): void,
@@ -41,7 +41,7 @@ declare function async<A: StorageAdapter | StorageAdapterFactory<any>>(
41
41
  $FlowGen$Assignable<A, StorageAdapterFactory<T>>,
42
42
  StorageAdapterFactory<T>,
43
43
  StorageAdapter
44
- >
44
+ >;
45
45
  declare function either<
46
46
  A1: StorageAdapter | StorageAdapterFactory<any>,
47
47
  A2: StorageAdapter | StorageAdapterFactory<any>
@@ -60,7 +60,7 @@ declare function either<
60
60
  StorageAdapterFactory<T2>,
61
61
  StorageAdapter
62
62
  >
63
- >
63
+ >;
64
64
  declare interface CacheAdapterInstance {
65
65
  get: Effect<
66
66
  {
@@ -81,7 +81,7 @@ declare interface CacheAdapterInstance {
81
81
  },
82
82
  void
83
83
  >;
84
- purge: Event<void>;
84
+ purge: EventCallable<void>;
85
85
  unset: Effect<
86
86
  {
87
87
  key: string,
@@ -96,6 +96,9 @@ declare type CacheAdapter = {
96
96
  ...
97
97
  },
98
98
  ...
99
- } & CacheAdapterInstance
100
- declare function farcached(adapter: CacheAdapter, keyArea?: any): StorageAdapter
101
- declare export { async, either, farcached }
99
+ } & CacheAdapterInstance;
100
+ declare function farcached(
101
+ adapter: CacheAdapter,
102
+ keyArea?: any
103
+ ): StorageAdapter;
104
+ declare export { async, either, farcached };
@@ -1 +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: 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":["async","adapterOrFactory","isFactory","create","config","adapter","asyncAdapter","key","update","get","set","value","ctx","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,IAAKT,MAAOW,EAAaC,IAAcH,QAAUE,EAAOC,GACxDF,IAAKV,MAAOW,EAAcC,IAAcF,QAAUC,EAAOC,GAC1D,EAKH,OAFAN,EAAaO,QAAUR,EAAQQ,QAC/BP,EAAaQ,KAAOT,EAAQS,KACrBR,CACT,CAEA,OApBAH,EAAOY,SAAU,EAoBVb,EAAYC,EAASA,GAC9B,CCQO,SAASa,EACdC,EACAC,GAEA,IAAMC,EAAa,YAAaF,EAC1BG,EAAa,YAAaF,EAGhC,SAASf,EAAOC,GACd,IAAMiB,EAAWF,EAAaF,EAAIb,GAAUa,EACtCK,EAAWF,EAAaF,EAAQd,GAAUc,EAChD,OAAOG,EAASP,KAAOQ,EAAWD,CACpC,CAEA,OAPAlB,EAAOY,SAAU,EAOVI,GAAcC,EAAajB,EAASA,GAC7C,CChCO,SAASoB,EACdlB,EACAQ,GAEA,IAAMW,EAA4CjB,IACzC,CACLE,IAAKgB,EAAO,CACVC,OAAQrB,EAAQsB,GAAGC,UACnB5B,aAAa6B,GACX,IAAMC,QAAkBD,EAASpB,IAAI,CAAEF,QACvC,OAAOuB,GAAWnB,KACpB,IAEFD,IAAKe,EAAO,CACVC,OAAQrB,EAAQsB,GAAGC,UACnB5B,OAAY+B,MAACF,EAAwBlB,IAC5BkB,EAASnB,IAAI,CAAEH,MAAKI,cAOnC,OADAa,EAAkBX,QAAUA,GAAWR,EAChCmB,CACT"}
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) => 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":["async","adapterOrFactory","isFactory","create","config","adapter","asyncAdapter","key","update","get","set","value","ctx","keyArea","noop","factory","either","one","another","isFactory1","isFactory2","adapter1","adapter2","farcached","farfetchedAdapter","attach","source","__","$instance","effect","instance","persisted"],"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,IAAKT,MAAOW,EAAaC,IAAcH,QAAUE,EAAOC,GACxDF,IAAKV,MAAOW,EAAcC,IAAcF,QAAUC,EAAOC,GAC1D,EAKH,OAFAN,EAAaO,QAAUR,EAAQQ,QAC/BP,EAAaQ,KAAOT,EAAQS,KACrBR,CACT,CAEA,OApBAH,EAAOY,SAAU,EAoBVb,EAAYC,EAASA,GAC9B,CCQO,SAASa,EACdC,EACAC,GAEA,IAAMC,EAAa,YAAaF,EAC1BG,EAAa,YAAaF,EAGhC,SAASf,EAAOC,GACd,IAAMiB,EAAWF,EAAaF,EAAIb,GAAUa,EACtCK,EAAWF,EAAaF,EAAQd,GAAUc,EAChD,OAAOG,EAASP,KAAOQ,EAAWD,CACpC,CAEA,OAPAlB,EAAOY,SAAU,EAOVI,GAAcC,EAAajB,EAASA,GAC7C,CChCO,SAASoB,EACdlB,EACAQ,GAEA,IAAMW,EAA4CjB,IACzC,CACLE,IAAKgB,EAAO,CACVC,OAAQrB,EAAQsB,GAAGC,UACnB,YAAMC,CAAOC,GACX,IAAMC,QAAkBD,EAASrB,IAAI,CAAEF,QACvC,OAAOwB,GAAWpB,KACpB,IAEFD,IAAKe,EAAO,CACVC,OAAQrB,EAAQsB,GAAGC,UACnB5B,OAAY6B,MAACC,EAAwBnB,IAC5BmB,EAASpB,IAAI,CAAEH,MAAKI,cAOnC,OADAa,EAAkBX,QAAUA,GAAWR,EAChCmB,CACT"}
@@ -1,8 +1,21 @@
1
1
  {
2
2
  "type": "module",
3
3
  "sideEffects": false,
4
- "main": "index.cjs",
4
+ "types": "index.d.ts",
5
5
  "module": "index.js",
6
+ "main": "index.cjs",
6
7
  "react-native": "index.js",
7
- "types": "index.d.ts"
8
+ "exports": {
9
+ "./package.json": "./package.json",
10
+ ".": {
11
+ "import": {
12
+ "types": "./index.d.ts",
13
+ "default": "./index.js"
14
+ },
15
+ "require": {
16
+ "types": "./index.d.cts",
17
+ "default": "./index.cjs"
18
+ }
19
+ }
20
+ }
8
21
  }
@@ -1,28 +0,0 @@
1
- interface StorageAdapter {
2
- <State>(key: string, update: (raw?: any) => any): {
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 AsyncStorage {
11
- getItem: (key: string) => Promise<string | null>
12
- setItem: (key: string, value: string) => Promise<void>
13
- }
14
- interface AsyncStorageConfig {
15
- storage: () => AsyncStorage
16
- serialize?: (value: any) => string
17
- deserialize?: (value: string) => any
18
- }
19
- declare function asyncStorage({
20
- storage,
21
- serialize,
22
- deserialize,
23
- }: AsyncStorageConfig): StorageAdapter
24
- declare namespace asyncStorage {
25
- var factory: true
26
- }
27
-
28
- export { AsyncStorage, AsyncStorageConfig, asyncStorage }
@@ -1,116 +0,0 @@
1
- import { Unit, Store, Event, Effect, Subscription } from 'effector'
2
-
3
- interface StorageAdapter {
4
- <State>(key: string, update: (raw?: any) => any): {
5
- get(raw?: any, ctx?: any): State | Promise<State | undefined> | undefined
6
- set(value: State, ctx?: any): void
7
- }
8
- keyArea?: any
9
- noop?: boolean
10
- }
11
- interface StorageAdapterFactory<AdapterConfig> {
12
- (config?: AdapterConfig): StorageAdapter
13
- factory: true
14
- }
15
- type Contract<Data> =
16
- | ((raw: unknown) => raw is Data)
17
- | {
18
- isData: (raw: unknown) => raw is Data
19
- getErrorMessages: (raw: unknown) => string[]
20
- }
21
- type Done<State> = {
22
- key: string
23
- keyPrefix: string
24
- operation: 'set' | 'get'
25
- value: State
26
- }
27
- type Fail<Err> = {
28
- key: string
29
- keyPrefix: string
30
- operation: 'set' | 'get'
31
- error: Err
32
- value?: any
33
- }
34
- type Finally<State, Err> =
35
- | (Done<State> & {
36
- status: 'done'
37
- })
38
- | (Fail<Err> & {
39
- status: 'fail'
40
- })
41
- interface ConfigPersist$1 {
42
- pickup?: Unit<any>
43
- context?: Unit<any>
44
- keyPrefix?: string
45
- contract?: Contract<any>
46
- }
47
- interface ConfigCommon<State, Err = Error> {
48
- clock?: Unit<any>
49
- done?: Unit<Done<State>>
50
- fail?: Unit<Fail<Err>>
51
- finally?: Unit<Finally<State, Err>>
52
- pickup?: Unit<any>
53
- context?: Unit<any>
54
- key?: string
55
- keyPrefix?: string
56
- contract?: Contract<State | undefined>
57
- }
58
- interface ConfigJustStore<State> {
59
- store: Store<State>
60
- }
61
- interface ConfigJustSourceTarget<State> {
62
- source: Store<State> | Event<State> | Effect<State, any, any>
63
- target: Store<State> | Event<State> | Effect<State, any, any>
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
-
72
- interface BroadcastConfig {
73
- channel?: string
74
- }
75
-
76
- interface ConfigPersist extends ConfigPersist$1 {}
77
- interface ConfigStore<State, Err = Error>
78
- extends BroadcastConfig,
79
- ConfigStore$1<State, Err> {}
80
- interface ConfigSourceTarget<State, Err = Error>
81
- extends BroadcastConfig,
82
- ConfigSourceTarget$1<State, Err> {}
83
- interface Persist {
84
- <State, Err = Error>(config: ConfigSourceTarget<State, Err>): Subscription
85
- <State, Err = Error>(config: ConfigStore<State, Err>): Subscription
86
- }
87
- declare function broadcast(config?: BroadcastConfig): StorageAdapter
88
- declare namespace broadcast {
89
- var factory: true
90
- }
91
- /**
92
- * Creates custom partially applied `persist`
93
- * with predefined BroadcastChannel adapter
94
- */
95
- declare function createPersist(defaults?: ConfigPersist): Persist
96
- /**
97
- * Default partially applied `persist`
98
- */
99
- declare const persist: Persist
100
-
101
- export {
102
- BroadcastConfig,
103
- ConfigPersist,
104
- ConfigSourceTarget,
105
- ConfigStore,
106
- Contract,
107
- Done,
108
- Fail,
109
- Finally,
110
- Persist,
111
- StorageAdapter,
112
- StorageAdapterFactory,
113
- broadcast,
114
- createPersist,
115
- persist,
116
- }
@@ -1,90 +0,0 @@
1
- import { Unit, Store, Event, Effect, Subscription } from 'effector'
2
-
3
- interface StorageAdapter {
4
- <State>(key: string, update: (raw?: any) => any): {
5
- get(raw?: any, ctx?: any): State | Promise<State | undefined> | undefined
6
- set(value: State, ctx?: any): void
7
- }
8
- keyArea?: any
9
- noop?: boolean
10
- }
11
- interface StorageAdapterFactory<AdapterConfig> {
12
- (config?: AdapterConfig): StorageAdapter
13
- factory: true
14
- }
15
- type Contract<Data> =
16
- | ((raw: unknown) => raw is Data)
17
- | {
18
- isData: (raw: unknown) => raw is Data
19
- getErrorMessages: (raw: unknown) => string[]
20
- }
21
- type Done<State> = {
22
- key: string
23
- keyPrefix: string
24
- operation: 'set' | 'get'
25
- value: State
26
- }
27
- type Fail<Err> = {
28
- key: string
29
- keyPrefix: string
30
- operation: 'set' | 'get'
31
- error: Err
32
- value?: any
33
- }
34
- type Finally<State, Err> =
35
- | (Done<State> & {
36
- status: 'done'
37
- })
38
- | (Fail<Err> & {
39
- status: 'fail'
40
- })
41
- interface ConfigPersist {
42
- pickup?: Unit<any>
43
- context?: Unit<any>
44
- keyPrefix?: string
45
- contract?: Contract<any>
46
- }
47
- interface ConfigAdapter {
48
- adapter: StorageAdapter
49
- }
50
- interface ConfigAdapterFactory<AdapterConfig> {
51
- adapter: StorageAdapterFactory<AdapterConfig>
52
- }
53
- interface ConfigCommon<State, Err = Error> {
54
- clock?: Unit<any>
55
- done?: Unit<Done<State>>
56
- fail?: Unit<Fail<Err>>
57
- finally?: Unit<Finally<State, Err>>
58
- pickup?: Unit<any>
59
- context?: Unit<any>
60
- key?: string
61
- keyPrefix?: string
62
- contract?: Contract<State | undefined>
63
- }
64
- interface ConfigJustStore<State> {
65
- store: Store<State>
66
- }
67
- interface ConfigJustSourceTarget<State> {
68
- source: Store<State> | Event<State> | Effect<State, any, any>
69
- target: Store<State> | Event<State> | Effect<State, any, any>
70
- }
71
- interface ConfigStore<State, Err = Error>
72
- extends ConfigCommon<State, Err>,
73
- ConfigJustStore<State> {}
74
- interface ConfigSourceTarget<State, Err = Error>
75
- extends ConfigCommon<State, Err>,
76
- ConfigJustSourceTarget<State> {}
77
-
78
- /**
79
- * Main `persist` function
80
- */
81
- declare function persist<State, Err = Error>(
82
- config: Partial<
83
- (ConfigAdapter | ConfigAdapterFactory<any>) &
84
- ConfigPersist &
85
- ConfigStore<State, Err> &
86
- ConfigSourceTarget<State, Err>
87
- >
88
- ): Subscription
89
-
90
- export { persist }