@lomray/react-mobx-manager 3.7.1 → 4.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lomray/react-mobx-manager",
3
- "version": "3.7.1",
3
+ "version": "4.0.0",
4
4
  "description": "This package provides Mobx stores manager for react.",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -1,5 +1,5 @@
1
1
  import { IStorage } from "../types.js";
2
- interface ICookiesStorageOptions {
2
+ interface ICookiesStorageAttributes {
3
3
  expires?: number | Date | undefined;
4
4
  path?: string | undefined;
5
5
  domain?: string | undefined;
@@ -9,29 +9,37 @@ interface ICookiesStorageOptions {
9
9
  }
10
10
  interface ICookieStorage {
11
11
  get: (key: string) => string | null | undefined;
12
- set: (key: string, value: string, options: ICookiesStorageOptions) => any;
13
- remove: (key: string, options: ICookiesStorageOptions) => any;
12
+ set: (key: string, value: string, options: ICookiesStorageAttributes) => any;
13
+ remove: (key: string, options: ICookiesStorageAttributes) => any;
14
+ }
15
+ interface ICookiesStorageOptions {
16
+ storage: ICookieStorage;
17
+ globalKey?: string;
18
+ cookieAttr?: ICookiesStorageAttributes;
14
19
  }
15
20
  /**
16
21
  * Cookie storage for mobx store manager
17
22
  */
18
23
  declare class CookieStorage implements IStorage {
19
- globalKey: string;
24
+ /**
25
+ * Cookie storage key
26
+ */
27
+ protected globalKey: string;
20
28
  /**
21
29
  * @protected
22
30
  */
23
31
  protected storage: ICookieStorage;
24
32
  /**
25
- * Cookie options
33
+ * Cookie attributes
26
34
  */
27
- protected options: ICookiesStorageOptions;
35
+ protected cookieAttr: ICookiesStorageAttributes;
28
36
  /**
29
37
  * @constructor
30
38
  */
31
39
  /**
32
40
  * @constructor
33
41
  */
34
- constructor(storage: ICookieStorage, options?: ICookiesStorageOptions);
42
+ constructor({ storage, cookieAttr, globalKey }: ICookiesStorageOptions);
35
43
  /**
36
44
  * @inheritDoc
37
45
  */
@@ -1,2 +1,2 @@
1
- class t{globalKey="stores";storage;options;constructor(t,s={}){this.storage=t,this.options=s}get(){try{return JSON.parse(this.storage.get(this.globalKey)||"{}")}catch(t){return{}}}flush(){return this.storage.remove(this.globalKey,this.options)}set(t){return this.storage.set(this.globalKey,JSON.stringify(t||"{}"),this.options)}}export{t as default};
1
+ class t{globalKey;storage;cookieAttr;constructor({storage:t,cookieAttr:e,globalKey:s}){this.storage=t,this.cookieAttr=e??{},this.globalKey=s??"stores"}get(){try{return JSON.parse(this.storage.get(this.globalKey)||"{}")}catch(t){return{}}}flush(){return this.storage.remove(this.globalKey,this.cookieAttr)}set(t){return this.storage.set(this.globalKey,JSON.stringify(t||"{}"),this.cookieAttr)}}export{t as default};
2
2
  //# sourceMappingURL=cookie-storage.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"cookie-storage.js","sources":["../../src/storages/cookie-storage.ts"],"sourcesContent":["import type { IStorage } from '../types';\n\ninterface ICookiesStorageOptions {\n expires?: number | Date | undefined;\n path?: string | undefined;\n domain?: string | undefined;\n secure?: boolean | undefined;\n sameSite?: 'strict' | 'Strict' | 'lax' | 'Lax' | 'none' | 'None' | undefined;\n [property: string]: any;\n}\n\ninterface ICookieStorage {\n get: (key: string) => string | null | undefined;\n set: (key: string, value: string, options: ICookiesStorageOptions) => any;\n remove: (key: string, options: ICookiesStorageOptions) => any;\n}\n\n/**\n * Cookie storage for mobx store manager\n */\nclass CookieStorage implements IStorage {\n globalKey = 'stores';\n\n /**\n * @protected\n */\n protected storage: ICookieStorage;\n\n /**\n * Cookie options\n */\n protected options: ICookiesStorageOptions;\n\n /**\n * @constructor\n */\n constructor(storage: ICookieStorage, options: ICookiesStorageOptions = {}) {\n this.storage = storage;\n this.options = options;\n }\n\n /**\n * @inheritDoc\n */\n public get(): Record<string, any> | Promise<Record<string, any> | undefined> {\n try {\n return JSON.parse(this.storage.get(this.globalKey) || '{}') as Record<string, any>;\n } catch (e) {\n return {};\n }\n }\n\n /**\n * @inheritDoc\n */\n public flush(): void | Promise<any> {\n return this.storage.remove(this.globalKey, this.options);\n }\n\n /**\n * @inheritDoc\n */\n public set(value: Record<string, any> | undefined): void {\n return this.storage.set(this.globalKey, JSON.stringify(value || '{}'), this.options);\n }\n}\n\nexport default CookieStorage;\n"],"names":["CookieStorage","globalKey","storage","options","constructor","this","get","JSON","parse","e","flush","remove","set","value","stringify"],"mappings":"AAoBA,MAAMA,EACJC,UAAY,SAKFC,QAKAC,QAKVC,YAAYF,EAAyBC,EAAkC,IACrEE,KAAKH,QAAUA,EACfG,KAAKF,QAAUA,CAChB,CAKMG,MACL,IACE,OAAOC,KAAKC,MAAMH,KAAKH,QAAQI,IAAID,KAAKJ,YAAc,KACvD,CAAC,MAAOQ,GACP,MAAO,EACR,CACF,CAKMC,QACL,OAAOL,KAAKH,QAAQS,OAAON,KAAKJ,UAAWI,KAAKF,QACjD,CAKMS,IAAIC,GACT,OAAOR,KAAKH,QAAQU,IAAIP,KAAKJ,UAAWM,KAAKO,UAAUD,GAAS,MAAOR,KAAKF,QAC7E"}
1
+ {"version":3,"file":"cookie-storage.js","sources":["../../src/storages/cookie-storage.ts"],"sourcesContent":["import type { IStorage } from '../types';\n\ninterface ICookiesStorageAttributes {\n expires?: number | Date | undefined;\n path?: string | undefined;\n domain?: string | undefined;\n secure?: boolean | undefined;\n sameSite?: 'strict' | 'Strict' | 'lax' | 'Lax' | 'none' | 'None' | undefined;\n [property: string]: any;\n}\n\ninterface ICookieStorage {\n get: (key: string) => string | null | undefined;\n set: (key: string, value: string, options: ICookiesStorageAttributes) => any;\n remove: (key: string, options: ICookiesStorageAttributes) => any;\n}\n\ninterface ICookiesStorageOptions {\n storage: ICookieStorage;\n globalKey?: string;\n cookieAttr?: ICookiesStorageAttributes;\n}\n\n/**\n * Cookie storage for mobx store manager\n */\nclass CookieStorage implements IStorage {\n /**\n * Cookie storage key\n */\n protected globalKey: string;\n\n /**\n * @protected\n */\n protected storage: ICookieStorage;\n\n /**\n * Cookie attributes\n */\n protected cookieAttr: ICookiesStorageAttributes;\n\n /**\n * @constructor\n */\n constructor({ storage, cookieAttr, globalKey }: ICookiesStorageOptions) {\n this.storage = storage;\n this.cookieAttr = cookieAttr ?? {};\n this.globalKey = globalKey ?? 'stores';\n }\n\n /**\n * @inheritDoc\n */\n public get(): Record<string, any> | Promise<Record<string, any> | undefined> {\n try {\n return JSON.parse(this.storage.get(this.globalKey) || '{}') as Record<string, any>;\n } catch (e) {\n return {};\n }\n }\n\n /**\n * @inheritDoc\n */\n public flush(): void | Promise<any> {\n return this.storage.remove(this.globalKey, this.cookieAttr);\n }\n\n /**\n * @inheritDoc\n */\n public set(value: Record<string, any> | undefined): void {\n return this.storage.set(this.globalKey, JSON.stringify(value || '{}'), this.cookieAttr);\n }\n}\n\nexport default CookieStorage;\n"],"names":["CookieStorage","globalKey","storage","cookieAttr","constructor","this","get","JSON","parse","e","flush","remove","set","value","stringify"],"mappings":"AA0BA,MAAMA,EAIMC,UAKAC,QAKAC,WAKVC,aAAYF,QAAEA,EAAOC,WAAEA,EAAUF,UAAEA,IACjCI,KAAKH,QAAUA,EACfG,KAAKF,WAAaA,GAAc,GAChCE,KAAKJ,UAAYA,GAAa,QAC/B,CAKMK,MACL,IACE,OAAOC,KAAKC,MAAMH,KAAKH,QAAQI,IAAID,KAAKJ,YAAc,KACvD,CAAC,MAAOQ,GACP,MAAO,EACR,CACF,CAKMC,QACL,OAAOL,KAAKH,QAAQS,OAAON,KAAKJ,UAAWI,KAAKF,WACjD,CAKMS,IAAIC,GACT,OAAOR,KAAKH,QAAQU,IAAIP,KAAKJ,UAAWM,KAAKO,UAAUD,GAAS,MAAOR,KAAKF,WAC7E"}
@@ -1,9 +1,16 @@
1
1
  import { IStorage } from "../types.js";
2
+ interface ILocalStorageOptions {
3
+ globalKey?: string;
4
+ storage?: Storage;
5
+ }
2
6
  /**
3
7
  * Local storage for mobx store manager
4
8
  */
5
9
  declare class LocalStorage implements IStorage {
6
- globalKey: string;
10
+ /**
11
+ * Local storage key
12
+ */
13
+ protected globalKey: string;
7
14
  /**
8
15
  * @protected
9
16
  */
@@ -14,7 +21,7 @@ declare class LocalStorage implements IStorage {
14
21
  /**
15
22
  * @constructor
16
23
  */
17
- constructor(storage?: Storage);
24
+ constructor({ storage, globalKey }?: ILocalStorageOptions);
18
25
  /**
19
26
  * @inheritDoc
20
27
  */
@@ -1,2 +1,2 @@
1
- class t{globalKey="stores";storage;constructor(t=localStorage){this.storage=t}get(){try{return JSON.parse(this.storage.getItem(this.globalKey)||"{}")}catch(t){return{}}}flush(){return this.storage.removeItem(this.globalKey)}set(t){return this.storage.setItem(this.globalKey,JSON.stringify(t||"{}"))}}export{t as default};
1
+ class t{globalKey;storage;constructor({storage:t,globalKey:e}={}){this.storage=t??localStorage,this.globalKey=e??"stores"}get(){try{return JSON.parse(this.storage.getItem(this.globalKey)||"{}")}catch(t){return{}}}flush(){return this.storage.removeItem(this.globalKey)}set(t){return this.storage.setItem(this.globalKey,JSON.stringify(t||"{}"))}}export{t as default};
2
2
  //# sourceMappingURL=local-storage.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"local-storage.js","sources":["../../src/storages/local-storage.ts"],"sourcesContent":["import type { IStorage } from '../types';\n\n/**\n * Local storage for mobx store manager\n */\nclass LocalStorage implements IStorage {\n globalKey = 'stores';\n\n /**\n * @protected\n */\n protected storage: Storage;\n\n /**\n * @constructor\n */\n constructor(storage: Storage = localStorage) {\n this.storage = storage;\n }\n\n /**\n * @inheritDoc\n */\n get(): Record<string, any> | Promise<Record<string, any> | undefined> {\n try {\n return JSON.parse(this.storage.getItem(this.globalKey) || '{}') as Record<string, any>;\n } catch (e) {\n return {};\n }\n }\n\n /**\n * @inheritDoc\n */\n flush(): void | Promise<any> {\n return this.storage.removeItem(this.globalKey);\n }\n\n /**\n * @inheritDoc\n */\n set(value: Record<string, any> | undefined): void {\n return this.storage.setItem(this.globalKey, JSON.stringify(value || '{}'));\n }\n}\n\nexport default LocalStorage;\n"],"names":["LocalStorage","globalKey","storage","constructor","localStorage","this","get","JSON","parse","getItem","e","flush","removeItem","set","value","setItem","stringify"],"mappings":"AAKA,MAAMA,EACJC,UAAY,SAKFC,QAKVC,YAAYD,EAAmBE,cAC7BC,KAAKH,QAAUA,CAChB,CAKDI,MACE,IACE,OAAOC,KAAKC,MAAMH,KAAKH,QAAQO,QAAQJ,KAAKJ,YAAc,KAC3D,CAAC,MAAOS,GACP,MAAO,EACR,CACF,CAKDC,QACE,OAAON,KAAKH,QAAQU,WAAWP,KAAKJ,UACrC,CAKDY,IAAIC,GACF,OAAOT,KAAKH,QAAQa,QAAQV,KAAKJ,UAAWM,KAAKS,UAAUF,GAAS,MACrE"}
1
+ {"version":3,"file":"local-storage.js","sources":["../../src/storages/local-storage.ts"],"sourcesContent":["import type { IStorage } from '../types';\n\ninterface ILocalStorageOptions {\n globalKey?: string;\n storage?: Storage;\n}\n\n/**\n * Local storage for mobx store manager\n */\nclass LocalStorage implements IStorage {\n /**\n * Local storage key\n */\n protected globalKey: string;\n\n /**\n * @protected\n */\n protected storage: Storage;\n\n /**\n * @constructor\n */\n constructor({ storage, globalKey }: ILocalStorageOptions = {}) {\n this.storage = storage ?? localStorage;\n this.globalKey = globalKey ?? 'stores';\n }\n\n /**\n * @inheritDoc\n */\n get(): Record<string, any> | Promise<Record<string, any> | undefined> {\n try {\n return JSON.parse(this.storage.getItem(this.globalKey) || '{}') as Record<string, any>;\n } catch (e) {\n return {};\n }\n }\n\n /**\n * @inheritDoc\n */\n flush(): void | Promise<any> {\n return this.storage.removeItem(this.globalKey);\n }\n\n /**\n * @inheritDoc\n */\n set(value: Record<string, any> | undefined): void {\n return this.storage.setItem(this.globalKey, JSON.stringify(value || '{}'));\n }\n}\n\nexport default LocalStorage;\n"],"names":["LocalStorage","globalKey","storage","constructor","this","localStorage","get","JSON","parse","getItem","e","flush","removeItem","set","value","setItem","stringify"],"mappings":"AAUA,MAAMA,EAIMC,UAKAC,QAKVC,aAAYD,QAAEA,EAAOD,UAAEA,GAAoC,CAAA,GACzDG,KAAKF,QAAUA,GAAWG,aAC1BD,KAAKH,UAAYA,GAAa,QAC/B,CAKDK,MACE,IACE,OAAOC,KAAKC,MAAMJ,KAAKF,QAAQO,QAAQL,KAAKH,YAAc,KAC3D,CAAC,MAAOS,GACP,MAAO,EACR,CACF,CAKDC,QACE,OAAOP,KAAKF,QAAQU,WAAWR,KAAKH,UACrC,CAKDY,IAAIC,GACF,OAAOV,KAAKF,QAAQa,QAAQX,KAAKH,UAAWM,KAAKS,UAAUF,GAAS,MACrE"}