effector-storage 7.1.0 → 8.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 +12 -9
- package/async-storage/index.cjs +1 -1
- package/async-storage/index.cjs.map +1 -1
- package/async-storage/index.d.cts +20 -9
- package/async-storage/index.d.ts +20 -9
- package/async-storage/index.js +1 -1
- package/async-storage/index.js.map +1 -1
- package/broadcast/index.cjs +1 -1
- package/broadcast/index.cjs.map +1 -1
- package/broadcast/index.d.cts +105 -26
- package/broadcast/index.d.ts +105 -26
- package/broadcast/index.js +1 -1
- package/broadcast/index.js.map +1 -1
- package/core/index.cjs +1 -1
- package/core/index.cjs.map +1 -1
- package/core/index.d.cts +99 -21
- package/core/index.d.ts +99 -21
- package/core/index.js +1 -1
- package/core/index.js.map +1 -1
- package/core/package.json +3 -0
- package/index.cjs +1 -1
- package/index.cjs.map +1 -1
- package/index.d.cts +101 -22
- package/index.d.ts +101 -22
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/local/index.cjs +1 -1
- package/local/index.cjs.map +1 -1
- package/local/index.d.cts +105 -26
- package/local/index.d.ts +105 -26
- package/local/index.js +1 -1
- package/local/index.js.map +1 -1
- package/log/index.cjs +1 -1
- package/log/index.cjs.map +1 -1
- package/log/index.d.cts +21 -9
- package/log/index.d.ts +21 -9
- package/log/index.js +1 -1
- package/log/index.js.map +1 -1
- package/memory/index.cjs +1 -1
- package/memory/index.cjs.map +1 -1
- package/memory/index.d.cts +105 -26
- package/memory/index.d.ts +105 -26
- package/memory/index.js +1 -1
- package/memory/index.js.map +1 -1
- package/nil/index.cjs +1 -1
- package/nil/index.cjs.map +1 -1
- package/nil/index.d.cts +20 -9
- package/nil/index.d.ts +20 -9
- package/nil/index.js +1 -1
- package/nil/index.js.map +1 -1
- package/package.json +3 -3
- package/query/index.cjs +1 -1
- package/query/index.cjs.map +1 -1
- package/query/index.d.cts +105 -26
- package/query/index.d.ts +105 -26
- package/query/index.js +1 -1
- package/query/index.js.map +1 -1
- package/session/index.cjs +1 -1
- package/session/index.cjs.map +1 -1
- package/session/index.d.cts +105 -26
- package/session/index.d.ts +105 -26
- package/session/index.js +1 -1
- package/session/index.js.map +1 -1
- package/storage/index.cjs +1 -1
- package/storage/index.cjs.map +1 -1
- package/storage/index.d.cts +20 -9
- package/storage/index.d.ts +20 -9
- package/storage/index.js +1 -1
- package/storage/index.js.map +1 -1
- package/tools/index.cjs +1 -1
- package/tools/index.cjs.map +1 -1
- package/tools/index.d.cts +18 -9
- package/tools/index.d.ts +18 -9
- package/tools/index.js +1 -1
- package/tools/index.js.map +1 -1
- package/tools/package.json +3 -0
- package/async-storage/index.js.flow +0 -37
- package/broadcast/index.js.flow +0 -132
- package/core/index.js.flow +0 -113
- package/index.js.flow +0 -146
- package/local/index.js.flow +0 -140
- package/log/index.js.flow +0 -32
- package/memory/index.js.flow +0 -133
- package/nil/index.js.flow +0 -31
- package/query/index.js.flow +0 -159
- package/session/index.js.flow +0 -140
- package/storage/index.js.flow +0 -36
- package/tools/index.js.flow +0 -104
package/session/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/session/index.ts"],"sourcesContent":["import type { Subscription } from 'effector'\nimport type {\n ConfigPersist as BaseConfigPersist,\n
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/session/index.ts"],"sourcesContent":["import type { Subscription } from 'effector'\nimport type {\n ConfigPersist as BaseConfigPersist,\n ConfigSourceTarget as BaseConfigSourceTarget,\n ConfigStore as BaseConfigStore,\n StorageAdapterFactory,\n} from '../types'\nimport { persist as base } from '../core'\nimport { nil } from '../nil'\nimport { storage } from '../storage'\n\nexport type {\n Adapter,\n Contract,\n DisposableAdapter,\n Done,\n Fail,\n Finally,\n StorageAdapter,\n StorageAdapterFactory,\n} from '../types'\n\nexport interface ConfigPersist extends BaseConfigPersist {\n sync?: boolean | 'force'\n timeout?: number\n}\n\nexport interface SessionStorageConfig {\n sync?: boolean | 'force'\n serialize?: (value: any) => string\n deserialize?: (value: string) => any\n timeout?: number\n def?: any\n}\n\nexport interface ConfigStore<State, Err = Error>\n extends SessionStorageConfig,\n BaseConfigStore<State, Err> {}\n\nexport interface ConfigSourceTarget<State, Err = Error>\n extends SessionStorageConfig,\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 `sessionStorage` exists\n */\nconst supports = () => {\n try {\n return typeof sessionStorage !== 'undefined'\n } catch (_error) {\n // accessing `sessionStorage` could throw an exception only in one case -\n // when `sessionStorage` IS supported, but blocked by security policies\n return true\n }\n}\n\n/**\n * Creates `sessionStorage` adapter\n */\nexport const session: StorageAdapterFactory<\n SessionStorageConfig | undefined | void\n> = (config) => {\n return supports()\n ? storage({\n storage: () => sessionStorage,\n ...config,\n })\n : nil({ keyArea: 'session' })\n}\n\n// mark as factory\nsession.factory = true\n\n/**\n * Creates custom partially applied `persist`\n * with predefined `sessionStorage` adapter\n */\nexport const createPersist =\n (defaults?: ConfigPersist): Persist =>\n (config) =>\n base({\n adapter: session,\n ...defaults,\n ...config,\n })\n\n/**\n * Default partially applied `persist`\n */\nexport const persist: Persist = /*#__PURE__*/ createPersist()\n"],"names":["session","config","supports","sessionStorage","_error","storage","nil","keyArea","factory","createPersist","defaults","base","adapter","persist"],"mappings":"+HAmDA,IAaaA,EAERC,GAfYC,MACf,IACE,MAAiC,oBAAnBC,cAChB,CAAE,MAAOC,GAGP,OAAO,CACT,GASOF,GACHG,EAAQ,CACNA,QAASA,IAAMF,kBACZF,IAELK,EAAI,CAAEC,QAAS,YAIrBP,EAAQQ,SAAU,EAMX,IAAMC,EACVC,GACAT,GACCU,EAAK,CACHC,QAASZ,KACNU,KACAT,IAMIY,eAAiCJ"}
|
package/storage/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";var e=({storage:e,sync:t=!1,serialize:r=JSON.stringify,deserialize:n=JSON.parse,timeout:i,def:o})=>{var s=(s,a)=>{var d,v,u,f,l,y=()=>u.setItem(s,r(v)),g=e=>{d=clearTimeout(d),e&&y(),f&&"undefined"!=typeof removeEventListener&&(removeEventListener("beforeunload",g),f=0)};return t&&"undefined"!=typeof addEventListener&&(l=r=>{r.storageArea===e()&&(r.key===s&&a("force"===t?void 0:r.newValue),null===r.key&&a(null))},addEventListener("storage",l)),Object.assign(()=>{f&&g(1),l&&"undefined"!=typeof removeEventListener&&removeEventListener("storage",l)},{get(t){g();var r=void 0!==t?t:e().getItem(s);return null===r?void 0!==o?o:t:n(r)},set(t){v=t,u=e(),void 0===i?y():d||(d=setTimeout(g,i,1),"undefined"!=typeof addEventListener&&(addEventListener("beforeunload",g),f=1))}})};try{s.keyArea=e()}catch(e){}return s};e.factory=!0,exports.storage=e;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
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 */\
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/storage/index.ts"],"sourcesContent":["import type { StorageAdapter, StorageAdapterFactory } 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 */\nexport const storage: StorageAdapterFactory<StorageConfig> = ({\n storage,\n sync = false,\n serialize = JSON.stringify,\n deserialize = JSON.parse,\n timeout,\n def,\n}) => {\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 let beforeunload: 0 | 1\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 (beforeunload && typeof removeEventListener !== 'undefined') {\n beforeunload = (removeEventListener('beforeunload', postponed), 0)\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 beforeunload = (addEventListener('beforeunload', postponed), 1)\n }\n }\n\n let updated: ((e: StorageEvent) => void) | undefined\n if (sync && typeof addEventListener !== 'undefined') {\n updated = (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 addEventListener('storage', updated)\n }\n\n const dispose = () => {\n if (beforeunload) postponed(1) // flush unsaved changes\n if (updated && typeof removeEventListener !== 'undefined') {\n removeEventListener('storage', updated)\n }\n }\n\n return Object.assign(dispose, {\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\n// mark as factory\nstorage.factory = true\n"],"names":["storage","sync","serialize","JSON","stringify","deserialize","parse","timeout","def","adapter","key","update","scheduled","unsaved","to","beforeunload","updated","flush","setItem","postponed","e","clearTimeout","removeEventListener","addEventListener","storageArea","undefined","newValue","Object","assign","dispose","get","raw","item","getItem","set","value","setTimeout","keyArea","_error","factory"],"mappings":"aAcO,IAAMA,EAAgDA,EAC3DA,UACAC,QAAO,EACPC,YAAYC,KAAKC,UACjBC,cAAcF,KAAKG,MACnBC,UACAC,UAEA,IAAMC,EAA0BA,CAC9BC,EACAC,KAEA,IAAIC,EACAC,EACAC,EACAC,EA8BAC,EA3BEC,EAAQA,IAAMH,EAAGI,QAAQR,EAAKR,EAAUW,IAGxCM,EAAaC,IACjBR,EAAYS,aAAaT,GACrBQ,GAAGH,IAKHF,GAA+C,oBAAxBO,sBACTA,oBAAoB,eAAgBH,GAApDJ,EAAgE,IAuCpE,OAtBId,GAAoC,oBAArBsB,mBACjBP,EAAWI,IAGLA,EAAEI,cAAgBxB,MAEhBoB,EAAEV,MAAQA,GAAKC,EAAgB,UAATV,OAAmBwB,EAAYL,EAAEM,UAG7C,OAAVN,EAAEV,KAAcC,EAAO,QAG/BY,iBAAiB,UAAWP,IAUvBW,OAAOC,OAPEC,KACVd,GAAcI,EAAU,GACxBH,GAA0C,oBAAxBM,qBACpBA,oBAAoB,UAAWN,IAIL,CAC5Bc,GAAAA,CAAIC,GACFZ,IACA,IAAMa,OAAeP,IAARM,EAAoBA,EAAM/B,IAAUiC,QAAQvB,GACzD,OAAgB,OAATsB,OACKP,IAARjB,EACEA,EACAuB,EACF1B,EAAY2B,EAClB,EAEAE,GAAAA,CAAIC,GACFtB,EAAUsB,EACVrB,EAAKd,SACWyB,IAAZlB,EACFU,IACUL,IAjDdA,EAAYwB,WAAWjB,EAAWZ,EAAS,GAKX,oBAArBgB,mBACOA,iBAAiB,eAAgBJ,GAAjDJ,EAA6D,GA8C/D,KAIJ,IACEN,EAAQ4B,QAAUrC,GACpB,CAAE,MAAOsC,GACP,CAGF,OAAO7B,GAITT,EAAQuC,SAAU"}
|
package/storage/index.d.cts
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
|
+
interface Adapter<State> {
|
|
2
|
+
get(this: void, //
|
|
3
|
+
raw?: any, ctx?: any): State | undefined | Promise<State | undefined>;
|
|
4
|
+
set(this: void, //
|
|
5
|
+
value: State, ctx?: any): void | Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
interface DisposableAdapter<State> extends Adapter<State> {
|
|
8
|
+
(): void;
|
|
9
|
+
}
|
|
1
10
|
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
|
-
};
|
|
11
|
+
<State>(key: string, update: (raw?: any) => void): Adapter<State> | DisposableAdapter<State>;
|
|
6
12
|
keyArea?: any;
|
|
7
13
|
noop?: boolean;
|
|
8
14
|
}
|
|
15
|
+
interface StorageAdapterFactory<AdapterConfig> {
|
|
16
|
+
(config: AdapterConfig): StorageAdapter;
|
|
17
|
+
factory: true;
|
|
18
|
+
}
|
|
9
19
|
|
|
10
20
|
interface StorageConfig {
|
|
11
21
|
storage: () => Storage;
|
|
@@ -15,9 +25,10 @@ interface StorageConfig {
|
|
|
15
25
|
timeout?: number;
|
|
16
26
|
def?: any;
|
|
17
27
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Creates generic `Storage` adapter
|
|
30
|
+
*/
|
|
31
|
+
declare const storage: StorageAdapterFactory<StorageConfig>;
|
|
22
32
|
|
|
23
|
-
export {
|
|
33
|
+
export { storage };
|
|
34
|
+
export type { StorageConfig };
|
package/storage/index.d.ts
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
|
+
interface Adapter<State> {
|
|
2
|
+
get(this: void, //
|
|
3
|
+
raw?: any, ctx?: any): State | undefined | Promise<State | undefined>;
|
|
4
|
+
set(this: void, //
|
|
5
|
+
value: State, ctx?: any): void | Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
interface DisposableAdapter<State> extends Adapter<State> {
|
|
8
|
+
(): void;
|
|
9
|
+
}
|
|
1
10
|
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
|
-
};
|
|
11
|
+
<State>(key: string, update: (raw?: any) => void): Adapter<State> | DisposableAdapter<State>;
|
|
6
12
|
keyArea?: any;
|
|
7
13
|
noop?: boolean;
|
|
8
14
|
}
|
|
15
|
+
interface StorageAdapterFactory<AdapterConfig> {
|
|
16
|
+
(config: AdapterConfig): StorageAdapter;
|
|
17
|
+
factory: true;
|
|
18
|
+
}
|
|
9
19
|
|
|
10
20
|
interface StorageConfig {
|
|
11
21
|
storage: () => Storage;
|
|
@@ -15,9 +25,10 @@ interface StorageConfig {
|
|
|
15
25
|
timeout?: number;
|
|
16
26
|
def?: any;
|
|
17
27
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Creates generic `Storage` adapter
|
|
30
|
+
*/
|
|
31
|
+
declare const storage: StorageAdapterFactory<StorageConfig>;
|
|
22
32
|
|
|
23
|
-
export {
|
|
33
|
+
export { storage };
|
|
34
|
+
export type { StorageConfig };
|
package/storage/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
var e=({storage:e,sync:t=!1,serialize:r=JSON.stringify,deserialize:n=JSON.parse,timeout:i,def:o})=>{var a=(a,d)=>{var s,v,u,f,l,y=()=>u.setItem(a,r(v)),m=e=>{s=clearTimeout(s),e&&y(),f&&"undefined"!=typeof removeEventListener&&(removeEventListener("beforeunload",m),f=0)};return t&&"undefined"!=typeof addEventListener&&(l=r=>{r.storageArea===e()&&(r.key===a&&d("force"===t?void 0:r.newValue),null===r.key&&d(null))},addEventListener("storage",l)),Object.assign(()=>{f&&m(1),l&&"undefined"!=typeof removeEventListener&&removeEventListener("storage",l)},{get(t){m();var r=void 0!==t?t:e().getItem(a);return null===r?void 0!==o?o:t:n(r)},set(t){v=t,u=e(),void 0===i?y():s||(s=setTimeout(m,i,1),"undefined"!=typeof addEventListener&&(addEventListener("beforeunload",m),f=1))}})};try{a.keyArea=e()}catch(e){}return a};e.factory=!0;export{e as storage};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
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 */\
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/storage/index.ts"],"sourcesContent":["import type { StorageAdapter, StorageAdapterFactory } 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 */\nexport const storage: StorageAdapterFactory<StorageConfig> = ({\n storage,\n sync = false,\n serialize = JSON.stringify,\n deserialize = JSON.parse,\n timeout,\n def,\n}) => {\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 let beforeunload: 0 | 1\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 (beforeunload && typeof removeEventListener !== 'undefined') {\n beforeunload = (removeEventListener('beforeunload', postponed), 0)\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 beforeunload = (addEventListener('beforeunload', postponed), 1)\n }\n }\n\n let updated: ((e: StorageEvent) => void) | undefined\n if (sync && typeof addEventListener !== 'undefined') {\n updated = (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 addEventListener('storage', updated)\n }\n\n const dispose = () => {\n if (beforeunload) postponed(1) // flush unsaved changes\n if (updated && typeof removeEventListener !== 'undefined') {\n removeEventListener('storage', updated)\n }\n }\n\n return Object.assign(dispose, {\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\n// mark as factory\nstorage.factory = true\n"],"names":["storage","sync","serialize","JSON","stringify","deserialize","parse","timeout","def","adapter","key","update","scheduled","unsaved","to","beforeunload","updated","flush","setItem","postponed","e","clearTimeout","removeEventListener","addEventListener","storageArea","undefined","newValue","Object","assign","dispose","get","raw","item","getItem","set","value","setTimeout","keyArea","_error","factory"],"mappings":"AAcO,IAAMA,EAAgDA,EAC3DA,UACAC,QAAO,EACPC,YAAYC,KAAKC,UACjBC,cAAcF,KAAKG,MACnBC,UACAC,UAEA,IAAMC,EAA0BA,CAC9BC,EACAC,KAEA,IAAIC,EACAC,EACAC,EACAC,EA8BAC,EA3BEC,EAAQA,IAAMH,EAAGI,QAAQR,EAAKR,EAAUW,IAGxCM,EAAaC,IACjBR,EAAYS,aAAaT,GACrBQ,GAAGH,IAKHF,GAA+C,oBAAxBO,sBACTA,oBAAoB,eAAgBH,GAApDJ,EAAgE,IAuCpE,OAtBId,GAAoC,oBAArBsB,mBACjBP,EAAWI,IAGLA,EAAEI,cAAgBxB,MAEhBoB,EAAEV,MAAQA,GAAKC,EAAgB,UAATV,OAAmBwB,EAAYL,EAAEM,UAG7C,OAAVN,EAAEV,KAAcC,EAAO,QAG/BY,iBAAiB,UAAWP,IAUvBW,OAAOC,OAPEC,KACVd,GAAcI,EAAU,GACxBH,GAA0C,oBAAxBM,qBACpBA,oBAAoB,UAAWN,IAIL,CAC5Bc,GAAAA,CAAIC,GACFZ,IACA,IAAMa,OAAeP,IAARM,EAAoBA,EAAM/B,IAAUiC,QAAQvB,GACzD,OAAgB,OAATsB,OACKP,IAARjB,EACEA,EACAuB,EACF1B,EAAY2B,EAClB,EAEAE,GAAAA,CAAIC,GACFtB,EAAUsB,EACVrB,EAAKd,SACWyB,IAAZlB,EACFU,IACUL,IAjDdA,EAAYwB,WAAWjB,EAAWZ,EAAS,GAKX,oBAArBgB,mBACOA,iBAAiB,eAAgBJ,GAAjDJ,EAA6D,GA8C/D,KAIJ,IACEN,EAAQ4B,QAAUrC,GACpB,CAAE,MAAOsC,GACP,CAGF,OAAO7B,GAITT,EAAQuC,SAAU"}
|
package/tools/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("effector");exports.async=
|
|
1
|
+
"use strict";var e=require("effector");exports.async=e=>{var r="factory"in e,t=t=>{var a=r?e(t):e,c=(e,r)=>{var{get:t,set:c}=a(e,r);return{get:async(e,r)=>t(await e,r),set:async(e,r)=>c(await e,r)}};return c.keyArea=a.keyArea,c.noop=a.noop,c};return t.factory=!0,r?t:t()},exports.either=(e,r)=>{var t="factory"in e,a="factory"in r,c=c=>{var n=t?e(c):e,s=a?r(c):r;return n.noop?s:n};return c.factory=!0,t||a?c:c()},exports.farcached=(r,t)=>{var a=t=>({get:e.attach({source:r.__.$instance,async effect(e){var r=await e.get({key:t});return r?.value}}),set:e.attach({source:r.__.$instance,effect:async(e,r)=>e.set({key:t,value:r})})});return a.keyArea=t??r,a};
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
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\
|
|
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\ntype Async = <A extends StorageAdapter | StorageAdapterFactory<any>>(\n adapter: A\n) => A extends StorageAdapterFactory<infer T>\n ? StorageAdapterFactory<T>\n : StorageAdapter\n\n/**\n * Makes synchronous storage adapter asynchronous\n */\nexport const async: Async = <T>(\n adapterOrFactory: StorageAdapter | StorageAdapterFactory<T>\n): any => {\n const isFactory = 'factory' in adapterOrFactory\n\n const create: StorageAdapterFactory<T | void> = (config) => {\n const adapter: StorageAdapter = isFactory\n ? adapterOrFactory(config as T)\n : 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 // mark as factory\n create.factory = true\n\n return isFactory ? create : create()\n}\n","import type { StorageAdapter, StorageAdapterFactory } from '../types'\n\ntype 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\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 */\nexport const either: Either = <T1, T2>(\n one: StorageAdapter | StorageAdapterFactory<T1 | void>,\n another: StorageAdapter | StorageAdapterFactory<T2 | void>\n): any => {\n const isFactory1 = 'factory' in one\n const isFactory2 = 'factory' in another\n\n const create: StorageAdapterFactory<(T1 & T2) | void> = (config) => {\n const adapter1: StorageAdapter = isFactory1 ? one(config) : one\n const adapter2: StorageAdapter = isFactory2 ? another(config) : another\n return adapter1.noop ? adapter2 : adapter1\n }\n\n // mark as factory\n create.factory = true\n\n return isFactory1 || isFactory2 ? create : create()\n}\n","import type { CacheAdapter } from '@farfetched/core'\nimport type { StorageAdapter } from '../types'\nimport { attach } from 'effector'\n\ntype Farcached = (adapter: CacheAdapter, keyArea?: any) => StorageAdapter\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 */\nexport const farcached: Farcached = (adapter, keyArea) => {\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","either","one","another","isFactory1","isFactory2","adapter1","adapter2","farcached","farfetchedAdapter","attach","source","__","$instance","effect","instance","persisted"],"mappings":"qDAYEA,IAEA,IAAMC,EAAY,YAAaD,EAEzBE,EAA2CC,IAC/C,IAAMC,EAA0BH,EAC5BD,EAAiBG,GACjBH,EAEEK,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,KAM7D,OAFAP,EAAaQ,QAAUT,EAAQS,QAC/BR,EAAaS,KAAOV,EAAQU,KACrBT,GAMT,OAFAH,EAAOa,SAAU,EAEVd,EAAYC,EAASA,oBCKAc,CAC5BC,EACAC,KAEA,IAAMC,EAAa,YAAaF,EAC1BG,EAAa,YAAaF,EAE1BhB,EAAmDC,IACvD,IAAMkB,EAA2BF,EAAaF,EAAId,GAAUc,EACtDK,EAA2BF,EAAaF,EAAQf,GAAUe,EAChE,OAAOG,EAASP,KAAOQ,EAAWD,GAMpC,OAFAnB,EAAOa,SAAU,EAEVI,GAAcC,EAAalB,EAASA,uBC/BTqB,CAACnB,EAASS,KAC5C,IAAMW,EAA4ClB,IACzC,CACLE,IAAKiB,EAAAA,OAAO,CACVC,OAAQtB,EAAQuB,GAAGC,UACnB,YAAMC,CAAOC,GACX,IAAMC,QAAkBD,EAAStB,IAAI,CAAEF,QACvC,OAAOyB,GAAWpB,KACpB,IAEFF,IAAKgB,EAAAA,OAAO,CACVC,OAAQtB,EAAQuB,GAAGC,UACnBlB,OAAYmB,MAACC,EAAwBnB,IAC5BmB,EAASrB,IAAI,CAAEH,MAAKK,cAOnC,OADAa,EAAkBX,QAAUA,GAAWT,EAChCoB"}
|
package/tools/index.d.cts
CHANGED
|
@@ -1,23 +1,31 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Effect, EventCallable, StoreWritable } from 'effector';
|
|
2
2
|
|
|
3
|
+
interface Adapter<State> {
|
|
4
|
+
get(this: void, //
|
|
5
|
+
raw?: any, ctx?: any): State | undefined | Promise<State | undefined>;
|
|
6
|
+
set(this: void, //
|
|
7
|
+
value: State, ctx?: any): void | Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
interface DisposableAdapter<State> extends Adapter<State> {
|
|
10
|
+
(): void;
|
|
11
|
+
}
|
|
3
12
|
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
|
-
};
|
|
13
|
+
<State>(key: string, update: (raw?: any) => void): Adapter<State> | DisposableAdapter<State>;
|
|
8
14
|
keyArea?: any;
|
|
9
15
|
noop?: boolean;
|
|
10
16
|
}
|
|
11
17
|
interface StorageAdapterFactory<AdapterConfig> {
|
|
12
|
-
(config
|
|
18
|
+
(config: AdapterConfig): StorageAdapter;
|
|
13
19
|
factory: true;
|
|
14
20
|
}
|
|
15
21
|
|
|
22
|
+
type Async = <A extends StorageAdapter | StorageAdapterFactory<any>>(adapter: A) => A extends StorageAdapterFactory<infer T> ? StorageAdapterFactory<T> : StorageAdapter;
|
|
16
23
|
/**
|
|
17
24
|
* Makes synchronous storage adapter asynchronous
|
|
18
25
|
*/
|
|
19
|
-
declare
|
|
26
|
+
declare const async: Async;
|
|
20
27
|
|
|
28
|
+
type 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;
|
|
21
29
|
/**
|
|
22
30
|
* Returns first adapter, if it is not noop, and second otherwise.
|
|
23
31
|
*
|
|
@@ -47,7 +55,7 @@ declare function async<A extends StorageAdapter | StorageAdapterFactory<any>>(ad
|
|
|
47
55
|
* key: 'store'
|
|
48
56
|
* })
|
|
49
57
|
*/
|
|
50
|
-
declare
|
|
58
|
+
declare const either: Either;
|
|
51
59
|
|
|
52
60
|
declare interface CacheAdapter extends CacheAdapterInstance {
|
|
53
61
|
__: {
|
|
@@ -72,6 +80,7 @@ declare interface CacheAdapterInstance {
|
|
|
72
80
|
}, void>;
|
|
73
81
|
}
|
|
74
82
|
|
|
83
|
+
type Farcached = (adapter: CacheAdapter, keyArea?: any) => StorageAdapter;
|
|
75
84
|
/**
|
|
76
85
|
* Wraps @farfetched/core cache adapter to be used as `persist` adapter :)
|
|
77
86
|
* @see https://farfetched.pages.dev/api/operators/cache.html
|
|
@@ -96,6 +105,6 @@ declare interface CacheAdapterInstance {
|
|
|
96
105
|
* cache adapters with `fork` using `cache.__.$instance` internal store.
|
|
97
106
|
* @see https://farfetched.pages.dev/recipes/server_cache.html#inject-adapter
|
|
98
107
|
*/
|
|
99
|
-
declare
|
|
108
|
+
declare const farcached: Farcached;
|
|
100
109
|
|
|
101
110
|
export { async, either, farcached };
|
package/tools/index.d.ts
CHANGED
|
@@ -1,23 +1,31 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Effect, EventCallable, StoreWritable } from 'effector';
|
|
2
2
|
|
|
3
|
+
interface Adapter<State> {
|
|
4
|
+
get(this: void, //
|
|
5
|
+
raw?: any, ctx?: any): State | undefined | Promise<State | undefined>;
|
|
6
|
+
set(this: void, //
|
|
7
|
+
value: State, ctx?: any): void | Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
interface DisposableAdapter<State> extends Adapter<State> {
|
|
10
|
+
(): void;
|
|
11
|
+
}
|
|
3
12
|
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
|
-
};
|
|
13
|
+
<State>(key: string, update: (raw?: any) => void): Adapter<State> | DisposableAdapter<State>;
|
|
8
14
|
keyArea?: any;
|
|
9
15
|
noop?: boolean;
|
|
10
16
|
}
|
|
11
17
|
interface StorageAdapterFactory<AdapterConfig> {
|
|
12
|
-
(config
|
|
18
|
+
(config: AdapterConfig): StorageAdapter;
|
|
13
19
|
factory: true;
|
|
14
20
|
}
|
|
15
21
|
|
|
22
|
+
type Async = <A extends StorageAdapter | StorageAdapterFactory<any>>(adapter: A) => A extends StorageAdapterFactory<infer T> ? StorageAdapterFactory<T> : StorageAdapter;
|
|
16
23
|
/**
|
|
17
24
|
* Makes synchronous storage adapter asynchronous
|
|
18
25
|
*/
|
|
19
|
-
declare
|
|
26
|
+
declare const async: Async;
|
|
20
27
|
|
|
28
|
+
type 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;
|
|
21
29
|
/**
|
|
22
30
|
* Returns first adapter, if it is not noop, and second otherwise.
|
|
23
31
|
*
|
|
@@ -47,7 +55,7 @@ declare function async<A extends StorageAdapter | StorageAdapterFactory<any>>(ad
|
|
|
47
55
|
* key: 'store'
|
|
48
56
|
* })
|
|
49
57
|
*/
|
|
50
|
-
declare
|
|
58
|
+
declare const either: Either;
|
|
51
59
|
|
|
52
60
|
declare interface CacheAdapter extends CacheAdapterInstance {
|
|
53
61
|
__: {
|
|
@@ -72,6 +80,7 @@ declare interface CacheAdapterInstance {
|
|
|
72
80
|
}, void>;
|
|
73
81
|
}
|
|
74
82
|
|
|
83
|
+
type Farcached = (adapter: CacheAdapter, keyArea?: any) => StorageAdapter;
|
|
75
84
|
/**
|
|
76
85
|
* Wraps @farfetched/core cache adapter to be used as `persist` adapter :)
|
|
77
86
|
* @see https://farfetched.pages.dev/api/operators/cache.html
|
|
@@ -96,6 +105,6 @@ declare interface CacheAdapterInstance {
|
|
|
96
105
|
* cache adapters with `fork` using `cache.__.$instance` internal store.
|
|
97
106
|
* @see https://farfetched.pages.dev/recipes/server_cache.html#inject-adapter
|
|
98
107
|
*/
|
|
99
|
-
declare
|
|
108
|
+
declare const farcached: Farcached;
|
|
100
109
|
|
|
101
110
|
export { async, either, farcached };
|
package/tools/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{attach as e}from"effector";
|
|
1
|
+
import{attach as e}from"effector";var r=e=>{var r="factory"in e,a=a=>{var t=r?e(a):e,n=(e,r)=>{var{get:a,set:n}=t(e,r);return{get:async(e,r)=>a(await e,r),set:async(e,r)=>n(await e,r)}};return n.keyArea=t.keyArea,n.noop=t.noop,n};return a.factory=!0,r?a:a()},a=(e,r)=>{var a="factory"in e,t="factory"in r,n=n=>{var o=a?e(n):e,c=t?r(n):r;return o.noop?c:o};return n.factory=!0,a||t?n:n()},t=(r,a)=>{var t=a=>({get:e({source:r.__.$instance,async effect(e){var r=await e.get({key:a});return r?.value}}),set:e({source:r.__.$instance,effect:async(e,r)=>e.set({key:a,value:r})})});return t.keyArea=a??r,t};export{r as async,a as either,t as farcached};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/tools/index.js.map
CHANGED
|
@@ -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\
|
|
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\ntype Async = <A extends StorageAdapter | StorageAdapterFactory<any>>(\n adapter: A\n) => A extends StorageAdapterFactory<infer T>\n ? StorageAdapterFactory<T>\n : StorageAdapter\n\n/**\n * Makes synchronous storage adapter asynchronous\n */\nexport const async: Async = <T>(\n adapterOrFactory: StorageAdapter | StorageAdapterFactory<T>\n): any => {\n const isFactory = 'factory' in adapterOrFactory\n\n const create: StorageAdapterFactory<T | void> = (config) => {\n const adapter: StorageAdapter = isFactory\n ? adapterOrFactory(config as T)\n : 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 // mark as factory\n create.factory = true\n\n return isFactory ? create : create()\n}\n","import type { StorageAdapter, StorageAdapterFactory } from '../types'\n\ntype 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\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 */\nexport const either: Either = <T1, T2>(\n one: StorageAdapter | StorageAdapterFactory<T1 | void>,\n another: StorageAdapter | StorageAdapterFactory<T2 | void>\n): any => {\n const isFactory1 = 'factory' in one\n const isFactory2 = 'factory' in another\n\n const create: StorageAdapterFactory<(T1 & T2) | void> = (config) => {\n const adapter1: StorageAdapter = isFactory1 ? one(config) : one\n const adapter2: StorageAdapter = isFactory2 ? another(config) : another\n return adapter1.noop ? adapter2 : adapter1\n }\n\n // mark as factory\n create.factory = true\n\n return isFactory1 || isFactory2 ? create : create()\n}\n","import type { CacheAdapter } from '@farfetched/core'\nimport type { StorageAdapter } from '../types'\nimport { attach } from 'effector'\n\ntype Farcached = (adapter: CacheAdapter, keyArea?: any) => StorageAdapter\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 */\nexport const farcached: Farcached = (adapter, keyArea) => {\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":"kCAWO,IAAMA,EACXC,IAEA,IAAMC,EAAY,YAAaD,EAEzBE,EAA2CC,IAC/C,IAAMC,EAA0BH,EAC5BD,EAAiBG,GACjBH,EAEEK,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,KAM7D,OAFAN,EAAaO,QAAUR,EAAQQ,QAC/BP,EAAaQ,KAAOT,EAAQS,KACrBR,GAMT,OAFAH,EAAOY,SAAU,EAEVb,EAAYC,EAASA,KCKjBa,EAAiBA,CAC5BC,EACAC,KAEA,IAAMC,EAAa,YAAaF,EAC1BG,EAAa,YAAaF,EAE1Bf,EAAmDC,IACvD,IAAMiB,EAA2BF,EAAaF,EAAIb,GAAUa,EACtDK,EAA2BF,EAAaF,EAAQd,GAAUc,EAChE,OAAOG,EAASP,KAAOQ,EAAWD,GAMpC,OAFAlB,EAAOY,SAAU,EAEVI,GAAcC,EAAajB,EAASA,KC/BhCoB,EAAuBA,CAAClB,EAASQ,KAC5C,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"}
|
package/tools/package.json
CHANGED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Flowtype definitions for index
|
|
3
|
-
* Generated by Flowgen from a Typescript Definition
|
|
4
|
-
* Flowgen v1.21.0
|
|
5
|
-
* @flow
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
declare interface StorageAdapter {
|
|
9
|
-
<State>(
|
|
10
|
-
key: string,
|
|
11
|
-
update: (raw?: any) => void
|
|
12
|
-
): {
|
|
13
|
-
get(raw?: any, ctx?: any): State | Promise<State | void> | void,
|
|
14
|
-
set(value: State, ctx?: any): void,
|
|
15
|
-
...
|
|
16
|
-
};
|
|
17
|
-
keyArea?: any;
|
|
18
|
-
noop?: boolean;
|
|
19
|
-
}
|
|
20
|
-
declare interface AsyncStorage {
|
|
21
|
-
getItem: (key: string) => Promise<string | null>;
|
|
22
|
-
setItem: (key: string, value: string) => Promise<void>;
|
|
23
|
-
}
|
|
24
|
-
declare interface AsyncStorageConfig {
|
|
25
|
-
storage: () => AsyncStorage;
|
|
26
|
-
serialize?: (value: any) => string;
|
|
27
|
-
deserialize?: (value: string) => any;
|
|
28
|
-
}
|
|
29
|
-
declare var asyncStorage: typeof npm$namespace$asyncStorage;
|
|
30
|
-
|
|
31
|
-
declare var npm$namespace$asyncStorage: {|
|
|
32
|
-
(x: AsyncStorageConfig): StorageAdapter,
|
|
33
|
-
factory: typeof asyncStorage$factory,
|
|
34
|
-
|};
|
|
35
|
-
declare var asyncStorage$factory: true;
|
|
36
|
-
export type { AsyncStorage, AsyncStorageConfig };
|
|
37
|
-
declare export { asyncStorage };
|
package/broadcast/index.js.flow
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Flowtype definitions for index
|
|
3
|
-
* Generated by Flowgen from a Typescript Definition
|
|
4
|
-
* Flowgen v1.21.0
|
|
5
|
-
* @flow
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { Unit, Store, Event, Effect, Subscription } from "effector";
|
|
9
|
-
declare interface StorageAdapter {
|
|
10
|
-
<State>(
|
|
11
|
-
key: string,
|
|
12
|
-
update: (raw?: any) => void
|
|
13
|
-
): {
|
|
14
|
-
get(raw?: any, ctx?: any): State | Promise<State | void> | void,
|
|
15
|
-
set(value: State, ctx?: any): void,
|
|
16
|
-
...
|
|
17
|
-
};
|
|
18
|
-
keyArea?: any;
|
|
19
|
-
noop?: boolean;
|
|
20
|
-
}
|
|
21
|
-
declare interface StorageAdapterFactory<AdapterConfig> {
|
|
22
|
-
(config?: AdapterConfig): StorageAdapter;
|
|
23
|
-
factory: true;
|
|
24
|
-
}
|
|
25
|
-
declare type Contract<Data> =
|
|
26
|
-
| ((raw: mixed) => boolean)
|
|
27
|
-
| {
|
|
28
|
-
isData: (raw: mixed) => boolean,
|
|
29
|
-
getErrorMessages: (raw: mixed) => string[],
|
|
30
|
-
...
|
|
31
|
-
};
|
|
32
|
-
declare type Done<State> = {
|
|
33
|
-
key: string,
|
|
34
|
-
keyPrefix: string,
|
|
35
|
-
operation: "set" | "get",
|
|
36
|
-
value: State,
|
|
37
|
-
...
|
|
38
|
-
};
|
|
39
|
-
declare type Fail<Err> = {
|
|
40
|
-
key: string,
|
|
41
|
-
keyPrefix: string,
|
|
42
|
-
operation: "set" | "get",
|
|
43
|
-
error: Err,
|
|
44
|
-
value?: any,
|
|
45
|
-
...
|
|
46
|
-
};
|
|
47
|
-
declare type Finally<State, Err> =
|
|
48
|
-
| {
|
|
49
|
-
...Done<State>,
|
|
50
|
-
...{
|
|
51
|
-
status: "done",
|
|
52
|
-
...
|
|
53
|
-
},
|
|
54
|
-
}
|
|
55
|
-
| {
|
|
56
|
-
...Fail<Err>,
|
|
57
|
-
...{
|
|
58
|
-
status: "fail",
|
|
59
|
-
...
|
|
60
|
-
},
|
|
61
|
-
};
|
|
62
|
-
declare interface ConfigPersist$1 {
|
|
63
|
-
pickup?: Unit<any>;
|
|
64
|
-
context?: Unit<any>;
|
|
65
|
-
keyPrefix?: string;
|
|
66
|
-
contract?: Contract<any>;
|
|
67
|
-
}
|
|
68
|
-
declare interface ConfigCommon<State, Err = Error> {
|
|
69
|
-
clock?: Unit<any>;
|
|
70
|
-
done?: Unit<Done<State>>;
|
|
71
|
-
fail?: Unit<Fail<Err>>;
|
|
72
|
-
finally?: Unit<Finally<State, Err>>;
|
|
73
|
-
pickup?: Unit<any>;
|
|
74
|
-
context?: Unit<any>;
|
|
75
|
-
key?: string;
|
|
76
|
-
keyPrefix?: string;
|
|
77
|
-
contract?: Contract<State | void>;
|
|
78
|
-
}
|
|
79
|
-
declare interface ConfigJustStore<State> {
|
|
80
|
-
store: Store<State>;
|
|
81
|
-
}
|
|
82
|
-
declare interface ConfigJustSourceTarget<State> {
|
|
83
|
-
source: Store<State> | Event<State> | Effect<State, any, any>;
|
|
84
|
-
target: Store<State> | Event<State> | Effect<State, any, any>;
|
|
85
|
-
}
|
|
86
|
-
declare type ConfigStore$1<State, Err = Error> = { ... } & ConfigCommon<
|
|
87
|
-
State,
|
|
88
|
-
Err
|
|
89
|
-
> &
|
|
90
|
-
ConfigJustStore<State>;
|
|
91
|
-
declare type ConfigSourceTarget$1<State, Err = Error> = { ... } & ConfigCommon<
|
|
92
|
-
State,
|
|
93
|
-
Err
|
|
94
|
-
> &
|
|
95
|
-
ConfigJustSourceTarget<State>;
|
|
96
|
-
declare interface BroadcastConfig {
|
|
97
|
-
channel?: string;
|
|
98
|
-
}
|
|
99
|
-
declare type ConfigPersist = { ... } & ConfigPersist$1;
|
|
100
|
-
declare type ConfigStore<State, Err = Error> = { ... } & BroadcastConfig &
|
|
101
|
-
ConfigStore$1<State, Err>;
|
|
102
|
-
declare type ConfigSourceTarget<State, Err = Error> = {
|
|
103
|
-
...
|
|
104
|
-
} & BroadcastConfig &
|
|
105
|
-
ConfigSourceTarget$1<State, Err>;
|
|
106
|
-
declare interface Persist {
|
|
107
|
-
<State, Err>(config: ConfigSourceTarget<State, Err>): Subscription;
|
|
108
|
-
<State, Err>(config: ConfigStore<State, Err>): Subscription;
|
|
109
|
-
}
|
|
110
|
-
declare var broadcast: typeof npm$namespace$broadcast;
|
|
111
|
-
|
|
112
|
-
declare var npm$namespace$broadcast: {|
|
|
113
|
-
(config?: BroadcastConfig): StorageAdapter,
|
|
114
|
-
factory: typeof broadcast$factory,
|
|
115
|
-
|};
|
|
116
|
-
declare var broadcast$factory: true;
|
|
117
|
-
declare function createPersist(defaults?: ConfigPersist): Persist;
|
|
118
|
-
declare var persist: Persist;
|
|
119
|
-
export type {
|
|
120
|
-
BroadcastConfig,
|
|
121
|
-
ConfigPersist,
|
|
122
|
-
ConfigSourceTarget,
|
|
123
|
-
ConfigStore,
|
|
124
|
-
Contract,
|
|
125
|
-
Done,
|
|
126
|
-
Fail,
|
|
127
|
-
Finally,
|
|
128
|
-
Persist,
|
|
129
|
-
StorageAdapter,
|
|
130
|
-
StorageAdapterFactory,
|
|
131
|
-
};
|
|
132
|
-
declare export { broadcast, createPersist, persist };
|