@alwatr/local-storage 9.4.0 → 9.4.5

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/dist/facade.d.ts CHANGED
@@ -21,5 +21,5 @@ import type { LocalStorageProviderConfig } from './type.js';
21
21
  * console.log(currentSettings); // { theme: 'dark', notifications: false }
22
22
  * ```
23
23
  */
24
- export declare function createLocalStorageProvider<T extends JsonValue>(config: LocalStorageProviderConfig): LocalStorageProvider<T>;
24
+ export declare function createLocalStorageProvider<T>(config: LocalStorageProviderConfig): LocalStorageProvider<T>;
25
25
  //# sourceMappingURL=facade.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"facade.d.ts","sourceRoot":"","sources":["../src/facade.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,oBAAoB,EAAC,MAAM,6BAA6B,CAAC;AAEjE,OAAO,KAAK,EAAC,0BAA0B,EAAC,MAAM,WAAW,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,0BAA0B,CAAC,CAAC,SAAS,SAAS,EAAE,MAAM,EAAE,0BAA0B,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAE3H"}
1
+ {"version":3,"file":"facade.d.ts","sourceRoot":"","sources":["../src/facade.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,oBAAoB,EAAC,MAAM,6BAA6B,CAAC;AAEjE,OAAO,KAAK,EAAC,0BAA0B,EAAC,MAAM,WAAW,CAAC;AAE1D;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,0BAA0B,CAAC,CAAC,EAAE,MAAM,EAAE,0BAA0B,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAEzG"}
@@ -18,7 +18,7 @@ import type { LocalStorageProviderConfig } from './type.js';
18
18
  * console.log(currentSettings); // { theme: 'dark', notifications: false }
19
19
  * ```
20
20
  */
21
- export declare class LocalStorageProvider<T extends JsonValue> {
21
+ export declare class LocalStorageProvider<T> {
22
22
  static readonly version: string;
23
23
  private readonly key__;
24
24
  protected readonly logger_: import("@alwatr/logger").AlwatrLogger;
@@ -1 +1 @@
1
- {"version":3,"file":"local-storage.provider.d.ts","sourceRoot":"","sources":["../src/local-storage.provider.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,0BAA0B,EAAC,MAAM,WAAW,CAAC;AAE1D;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,oBAAoB,CAAC,CAAC,SAAS,SAAS;IACnD,gBAAuB,OAAO,SAAuB;IAErD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,SAAS,CAAC,QAAQ,CAAC,OAAO,wCAAC;gBAEf,MAAM,EAAE,0BAA0B;IAO9C;;;;OAIG;WACW,MAAM,CAAC,MAAM,EAAE,0BAA0B,GAAG,MAAM;IAIhE;;OAEG;WACW,4BAA4B,CAAC,MAAM,EAAE,0BAA0B,GAAG,IAAI;IAUpF;;;;;;;;;;;;OAYG;WACW,GAAG,CAAC,MAAM,EAAE,0BAA0B,GAAG,OAAO;IAK9D;;;;;;;;;;;;OAYG;IACI,GAAG,IAAI,OAAO;IAIrB;;;OAGG;IACI,IAAI,IAAI,CAAC,GAAG,IAAI;IA0BvB;;OAEG;IACI,KAAK,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI;IAmB5B;;OAEG;IACI,MAAM,IAAI,IAAI;CAGtB"}
1
+ {"version":3,"file":"local-storage.provider.d.ts","sourceRoot":"","sources":["../src/local-storage.provider.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,0BAA0B,EAAC,MAAM,WAAW,CAAC;AAE1D;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,oBAAoB,CAAC,CAAC;IACjC,gBAAuB,OAAO,SAAuB;IAErD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,SAAS,CAAC,QAAQ,CAAC,OAAO,wCAAC;gBAEf,MAAM,EAAE,0BAA0B;IAO9C;;;;OAIG;WACW,MAAM,CAAC,MAAM,EAAE,0BAA0B,GAAG,MAAM;IAIhE;;OAEG;WACW,4BAA4B,CAAC,MAAM,EAAE,0BAA0B,GAAG,IAAI;IAUpF;;;;;;;;;;;;OAYG;WACW,GAAG,CAAC,MAAM,EAAE,0BAA0B,GAAG,OAAO;IAK9D;;;;;;;;;;;;OAYG;IACI,GAAG,IAAI,OAAO;IAIrB;;;OAGG;IACI,IAAI,IAAI,CAAC,GAAG,IAAI;IAwBvB;;OAEG;IACI,KAAK,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI;IAiB5B;;OAEG;IACI,MAAM,IAAI,IAAI;CAGtB"}
package/dist/main.js CHANGED
@@ -1,5 +1,5 @@
1
- /* 📦 @alwatr/local-storage v9.4.0 */
2
- import{createLogger as z}from"@alwatr/logger";class j{static version="9.4.0";key__;logger_;constructor(x){this.logger_=z(`local-storage-provider: ${x.name}, v: ${x.schemaVersion}`),this.logger_.logMethodArgs?.("constructor",{config:x}),this.key__=j.getKey(x),j.clearPreviousStorageVersions(x)}static getKey(x){return`${x.name}.v${x.schemaVersion}`}static clearPreviousStorageVersions(x){if(x.schemaVersion<1)return;for(let b=0;b<x.schemaVersion;b++){let q=j.getKey({name:x.name,schemaVersion:b});localStorage.removeItem(q)}}static has(x){let b=j.getKey(x);return localStorage.getItem(b)!==null}has(){return localStorage.getItem(this.key__)!==null}read(){let x=null;try{x=localStorage.getItem(this.key__)}catch(b){this.logger_.error("read","read_local_storage_error",{err:b})}if(!x)return this.logger_.logMethod?.("read//no_value"),null;try{let b=JSON.parse(x);return this.logger_.logMethodFull?.("read//value",void 0,{parsedValue:b}),b}catch(b){return this.logger_.error("read","read_parse_error",{err:b}),null}}write(x){this.logger_.logMethodArgs?.("write",{value:x});let b;try{b=JSON.stringify(x)}catch(q){throw this.logger_.error("write","write_stringify_error",{err:q}),Error("write_stringify_error")}try{localStorage.setItem(this.key__,b)}catch(q){this.logger_.error("write","write_local_storage_error",{err:q})}}remove(){localStorage.removeItem(this.key__)}}function E(x){return new j(x)}export{E as createLocalStorageProvider,j as LocalStorageProvider};
1
+ /* 📦 @alwatr/local-storage v9.4.5 */
2
+ import{createLogger as z}from"@alwatr/logger";class j{static version="9.4.5";key__;logger_;constructor(x){this.logger_=z(`local-storage-provider: ${x.name}, v: ${x.schemaVersion}`),this.logger_.logMethodArgs?.("constructor",{config:x}),this.key__=j.getKey(x),j.clearPreviousStorageVersions(x)}static getKey(x){return`${x.name}.v${x.schemaVersion}`}static clearPreviousStorageVersions(x){if(x.schemaVersion<1)return;for(let b=0;b<x.schemaVersion;b++){let q=j.getKey({name:x.name,schemaVersion:b});localStorage.removeItem(q)}}static has(x){let b=j.getKey(x);return localStorage.getItem(b)!==null}has(){return localStorage.getItem(this.key__)!==null}read(){let x=null;try{x=localStorage.getItem(this.key__)}catch(b){this.logger_.error("read","read_local_storage_error",{err:b})}if(!x)return this.logger_.logMethod?.("read//no_value"),null;try{let b=JSON.parse(x);return this.logger_.logMethodFull?.("read//value",void 0,{parsedValue:b}),b}catch(b){return this.logger_.error("read","read_parse_error",{err:b}),null}}write(x){this.logger_.logMethodArgs?.("write",{value:x});let b;try{b=JSON.stringify(x)}catch(q){throw this.logger_.error("write","write_stringify_error",{err:q}),Error("write_stringify_error")}try{localStorage.setItem(this.key__,b)}catch(q){this.logger_.error("write","write_local_storage_error",{err:q})}}remove(){localStorage.removeItem(this.key__)}}function E(x){return new j(x)}export{E as createLocalStorageProvider,j as LocalStorageProvider};
3
3
 
4
- //# debugId=2CCB360A35B7E47364756E2164756E21
4
+ //# debugId=61791411B8B0946E64756E2164756E21
5
5
  //# sourceMappingURL=main.js.map
package/dist/main.js.map CHANGED
@@ -2,10 +2,10 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/local-storage.provider.ts", "../src/facade.ts"],
4
4
  "sourcesContent": [
5
- "import {createLogger} from '@alwatr/logger';\n\nimport type {LocalStorageProviderConfig} from './type.js';\n\n/**\n * A provider class for managing a specific, versioned item in localStorage.\n * It encapsulates the logic for key generation, serialization, and migration.\n *\n * @example\n * ```typescript\n * const userSettings = new LocalStorageProvider({\n * name: 'user-settings',\n * version: 1\n * });\n *\n * // Write new settings\n * userSettings.write({ theme: 'dark', notifications: false });\n *\n * // Read the current settings\n * const currentSettings = userSettings.read();\n * console.log(currentSettings); // { theme: 'dark', notifications: false }\n * ```\n */\nexport class LocalStorageProvider<T extends JsonValue> {\n public static readonly version = __package_version__;\n\n private readonly key__: string;\n protected readonly logger_;\n\n constructor(config: LocalStorageProviderConfig) {\n this.logger_ = createLogger(`local-storage-provider: ${config.name}, v: ${config.schemaVersion}`);\n this.logger_.logMethodArgs?.('constructor', {config});\n this.key__ = LocalStorageProvider.getKey(config);\n LocalStorageProvider.clearPreviousStorageVersions(config);\n }\n\n /**\n * Generates the versioned storage key.\n * @param meta - An object containing the name and schemaVersion.\n * @returns The versioned key string.\n */\n public static getKey(config: LocalStorageProviderConfig): string {\n return `${config.name}.v${config.schemaVersion}`;\n }\n\n /**\n * Manages data migration by removing all previous versions of the item.\n */\n public static clearPreviousStorageVersions(config: LocalStorageProviderConfig): void {\n if (config.schemaVersion < 1) return;\n\n // Iterate from v1 up to the version just before the current one and remove them.\n for (let i = 0; i < config.schemaVersion; i++) {\n const oldKey = LocalStorageProvider.getKey({name: config.name, schemaVersion: i});\n localStorage.removeItem(oldKey);\n }\n }\n\n /**\n * Checks if a versioned item exists in localStorage for the given configuration.\n * This static method allows checking for the existence of a specific versioned item\n * without instantiating the provider.\n *\n * @param config - The configuration object containing the name and schemaVersion.\n * @returns `true` if the item exists in localStorage, otherwise `false`.\n *\n * @example\n * ```typescript\n * const exists = LocalStorageProvider.has({ name: 'user-form', schemaVersion: 1 });\n * ```\n */\n public static has(config: LocalStorageProviderConfig): boolean {\n const key = LocalStorageProvider.getKey(config);\n return localStorage.getItem(key) !== null;\n }\n\n /**\n * Checks if the current versioned item exists in localStorage.\n *\n * @returns `true` if the item exists in localStorage, otherwise `false`.\n *\n * @example\n * ```typescript\n * const provider = new LocalStorageProvider({ name: 'profile', schemaVersion: 2 });\n * if (provider.has()) {\n * // Item exists\n * }\n * ```\n */\n public has(): boolean {\n return localStorage.getItem(this.key__) !== null;\n }\n\n /**\n * Reads and parses the value from localStorage.\n * If the item doesn't exist or is invalid JSON, returns null.\n */\n public read(): T | null {\n let value: string | null = null;\n\n try {\n value = localStorage.getItem(this.key__);\n }\n catch (err) {\n this.logger_.error('read', 'read_local_storage_error', {err});\n }\n\n if (!value) {\n this.logger_.logMethod?.('read//no_value');\n return null;\n }\n\n try {\n const parsedValue = JSON.parse(value) as T;\n this.logger_.logMethodFull?.('read//value', undefined, {parsedValue});\n return parsedValue;\n }\n catch (err) {\n this.logger_.error('read', 'read_parse_error', {err});\n return null;\n }\n }\n\n /**\n * Serializes and writes a value to localStorage.\n */\n public write(value: T): void {\n this.logger_.logMethodArgs?.('write', {value});\n let valueStr: string;\n try {\n valueStr = JSON.stringify(value);\n }\n catch (err) {\n this.logger_.error('write', 'write_stringify_error', {err});\n throw new Error('write_stringify_error');\n }\n\n try {\n localStorage.setItem(this.key__, valueStr);\n }\n catch (err) {\n this.logger_.error('write', 'write_local_storage_error', {err});\n }\n }\n\n /**\n * Removes the item from localStorage.\n */\n public remove(): void {\n localStorage.removeItem(this.key__);\n }\n}\n",
6
- "import {LocalStorageProvider} from './local-storage.provider.js';\n\nimport type {LocalStorageProviderConfig} from './type.js';\n\n/**\n * Factory function to create a new LocalStorageProvider.\n *\n * @param config - The configuration for the provider.\n * @returns An instance of LocalStorageProvider.\n *\n * @example\n * ```typescript\n * const userSettings = createLocalStorageProvider({\n * name: 'user-settings',\n * schemaVersion: 1\n * });\n *\n * // Write new settings\n * userSettings.write({ theme: 'dark', notifications: false });\n *\n * // Read the current settings\n * const currentSettings = userSettings.read();\n * console.log(currentSettings); // { theme: 'dark', notifications: false }\n * ```\n */\nexport function createLocalStorageProvider<T extends JsonValue>(config: LocalStorageProviderConfig): LocalStorageProvider<T> {\n return new LocalStorageProvider<T>(config);\n}\n"
5
+ "import {createLogger} from '@alwatr/logger';\n\nimport type {LocalStorageProviderConfig} from './type.js';\n\n/**\n * A provider class for managing a specific, versioned item in localStorage.\n * It encapsulates the logic for key generation, serialization, and migration.\n *\n * @example\n * ```typescript\n * const userSettings = new LocalStorageProvider({\n * name: 'user-settings',\n * version: 1\n * });\n *\n * // Write new settings\n * userSettings.write({ theme: 'dark', notifications: false });\n *\n * // Read the current settings\n * const currentSettings = userSettings.read();\n * console.log(currentSettings); // { theme: 'dark', notifications: false }\n * ```\n */\nexport class LocalStorageProvider<T> {\n public static readonly version = __package_version__;\n\n private readonly key__: string;\n protected readonly logger_;\n\n constructor(config: LocalStorageProviderConfig) {\n this.logger_ = createLogger(`local-storage-provider: ${config.name}, v: ${config.schemaVersion}`);\n this.logger_.logMethodArgs?.('constructor', {config});\n this.key__ = LocalStorageProvider.getKey(config);\n LocalStorageProvider.clearPreviousStorageVersions(config);\n }\n\n /**\n * Generates the versioned storage key.\n * @param meta - An object containing the name and schemaVersion.\n * @returns The versioned key string.\n */\n public static getKey(config: LocalStorageProviderConfig): string {\n return `${config.name}.v${config.schemaVersion}`;\n }\n\n /**\n * Manages data migration by removing all previous versions of the item.\n */\n public static clearPreviousStorageVersions(config: LocalStorageProviderConfig): void {\n if (config.schemaVersion < 1) return;\n\n // Iterate from v1 up to the version just before the current one and remove them.\n for (let i = 0; i < config.schemaVersion; i++) {\n const oldKey = LocalStorageProvider.getKey({name: config.name, schemaVersion: i});\n localStorage.removeItem(oldKey);\n }\n }\n\n /**\n * Checks if a versioned item exists in localStorage for the given configuration.\n * This static method allows checking for the existence of a specific versioned item\n * without instantiating the provider.\n *\n * @param config - The configuration object containing the name and schemaVersion.\n * @returns `true` if the item exists in localStorage, otherwise `false`.\n *\n * @example\n * ```typescript\n * const exists = LocalStorageProvider.has({ name: 'user-form', schemaVersion: 1 });\n * ```\n */\n public static has(config: LocalStorageProviderConfig): boolean {\n const key = LocalStorageProvider.getKey(config);\n return localStorage.getItem(key) !== null;\n }\n\n /**\n * Checks if the current versioned item exists in localStorage.\n *\n * @returns `true` if the item exists in localStorage, otherwise `false`.\n *\n * @example\n * ```typescript\n * const provider = new LocalStorageProvider({ name: 'profile', schemaVersion: 2 });\n * if (provider.has()) {\n * // Item exists\n * }\n * ```\n */\n public has(): boolean {\n return localStorage.getItem(this.key__) !== null;\n }\n\n /**\n * Reads and parses the value from localStorage.\n * If the item doesn't exist or is invalid JSON, returns null.\n */\n public read(): T | null {\n let value: string | null = null;\n\n try {\n value = localStorage.getItem(this.key__);\n } catch (err) {\n this.logger_.error('read', 'read_local_storage_error', {err});\n }\n\n if (!value) {\n this.logger_.logMethod?.('read//no_value');\n return null;\n }\n\n try {\n const parsedValue = JSON.parse(value) as T;\n this.logger_.logMethodFull?.('read//value', undefined, {parsedValue});\n return parsedValue;\n } catch (err) {\n this.logger_.error('read', 'read_parse_error', {err});\n return null;\n }\n }\n\n /**\n * Serializes and writes a value to localStorage.\n */\n public write(value: T): void {\n this.logger_.logMethodArgs?.('write', {value});\n let valueStr: string;\n try {\n valueStr = JSON.stringify(value);\n } catch (err) {\n this.logger_.error('write', 'write_stringify_error', {err});\n throw new Error('write_stringify_error');\n }\n\n try {\n localStorage.setItem(this.key__, valueStr);\n } catch (err) {\n this.logger_.error('write', 'write_local_storage_error', {err});\n }\n }\n\n /**\n * Removes the item from localStorage.\n */\n public remove(): void {\n localStorage.removeItem(this.key__);\n }\n}\n",
6
+ "import {LocalStorageProvider} from './local-storage.provider.js';\n\nimport type {LocalStorageProviderConfig} from './type.js';\n\n/**\n * Factory function to create a new LocalStorageProvider.\n *\n * @param config - The configuration for the provider.\n * @returns An instance of LocalStorageProvider.\n *\n * @example\n * ```typescript\n * const userSettings = createLocalStorageProvider({\n * name: 'user-settings',\n * schemaVersion: 1\n * });\n *\n * // Write new settings\n * userSettings.write({ theme: 'dark', notifications: false });\n *\n * // Read the current settings\n * const currentSettings = userSettings.read();\n * console.log(currentSettings); // { theme: 'dark', notifications: false }\n * ```\n */\nexport function createLocalStorageProvider<T>(config: LocalStorageProviderConfig): LocalStorageProvider<T> {\n return new LocalStorageProvider<T>(config);\n}\n"
7
7
  ],
8
- "mappings": ";AAAA,uBAAQ,uBAuBD,MAAM,CAA0C,OAC9B,SAAU,QAEhB,MACE,QAEnB,WAAW,CAAC,EAAoC,CAC9C,KAAK,QAAU,EAAa,2BAA2B,EAAO,YAAY,EAAO,eAAe,EAChG,KAAK,QAAQ,gBAAgB,cAAe,CAAC,QAAM,CAAC,EACpD,KAAK,MAAQ,EAAqB,OAAO,CAAM,EAC/C,EAAqB,6BAA6B,CAAM,QAQ5C,OAAM,CAAC,EAA4C,CAC/D,MAAO,GAAG,EAAO,SAAS,EAAO,sBAMrB,6BAA4B,CAAC,EAA0C,CACnF,GAAI,EAAO,cAAgB,EAAG,OAG9B,QAAS,EAAI,EAAG,EAAI,EAAO,cAAe,IAAK,CAC7C,IAAM,EAAS,EAAqB,OAAO,CAAC,KAAM,EAAO,KAAM,cAAe,CAAC,CAAC,EAChF,aAAa,WAAW,CAAM,SAiBpB,IAAG,CAAC,EAA6C,CAC7D,IAAM,EAAM,EAAqB,OAAO,CAAM,EAC9C,OAAO,aAAa,QAAQ,CAAG,IAAM,KAgBhC,GAAG,EAAY,CACpB,OAAO,aAAa,QAAQ,KAAK,KAAK,IAAM,KAOvC,IAAI,EAAa,CACtB,IAAI,EAAuB,KAE3B,GAAI,CACF,EAAQ,aAAa,QAAQ,KAAK,KAAK,EAEzC,MAAO,EAAK,CACV,KAAK,QAAQ,MAAM,OAAQ,2BAA4B,CAAC,KAAG,CAAC,EAG9D,GAAI,CAAC,EAEH,OADA,KAAK,QAAQ,YAAY,gBAAgB,EAClC,KAGT,GAAI,CACF,IAAM,EAAc,KAAK,MAAM,CAAK,EAEpC,OADA,KAAK,QAAQ,gBAAgB,cAAe,OAAW,CAAC,aAAW,CAAC,EAC7D,EAET,MAAO,EAAK,CAEV,OADA,KAAK,QAAQ,MAAM,OAAQ,mBAAoB,CAAC,KAAG,CAAC,EAC7C,MAOJ,KAAK,CAAC,EAAgB,CAC3B,KAAK,QAAQ,gBAAgB,QAAS,CAAC,OAAK,CAAC,EAC7C,IAAI,EACJ,GAAI,CACF,EAAW,KAAK,UAAU,CAAK,EAEjC,MAAO,EAAK,CAEV,MADA,KAAK,QAAQ,MAAM,QAAS,wBAAyB,CAAC,KAAG,CAAC,EAChD,MAAM,uBAAuB,EAGzC,GAAI,CACF,aAAa,QAAQ,KAAK,MAAO,CAAQ,EAE3C,MAAO,EAAK,CACV,KAAK,QAAQ,MAAM,QAAS,4BAA6B,CAAC,KAAG,CAAC,GAO3D,MAAM,EAAS,CACpB,aAAa,WAAW,KAAK,KAAK,EAEtC,CC9HO,SAAS,CAA+C,CAAC,EAA6D,CAC3H,OAAO,IAAI,EAAwB,CAAM",
9
- "debugId": "2CCB360A35B7E47364756E2164756E21",
8
+ "mappings": ";AAAA,uBAAQ,uBAuBD,MAAM,CAAwB,OACZ,SAAU,QAEhB,MACE,QAEnB,WAAW,CAAC,EAAoC,CAC9C,KAAK,QAAU,EAAa,2BAA2B,EAAO,YAAY,EAAO,eAAe,EAChG,KAAK,QAAQ,gBAAgB,cAAe,CAAC,QAAM,CAAC,EACpD,KAAK,MAAQ,EAAqB,OAAO,CAAM,EAC/C,EAAqB,6BAA6B,CAAM,QAQ5C,OAAM,CAAC,EAA4C,CAC/D,MAAO,GAAG,EAAO,SAAS,EAAO,sBAMrB,6BAA4B,CAAC,EAA0C,CACnF,GAAI,EAAO,cAAgB,EAAG,OAG9B,QAAS,EAAI,EAAG,EAAI,EAAO,cAAe,IAAK,CAC7C,IAAM,EAAS,EAAqB,OAAO,CAAC,KAAM,EAAO,KAAM,cAAe,CAAC,CAAC,EAChF,aAAa,WAAW,CAAM,SAiBpB,IAAG,CAAC,EAA6C,CAC7D,IAAM,EAAM,EAAqB,OAAO,CAAM,EAC9C,OAAO,aAAa,QAAQ,CAAG,IAAM,KAgBhC,GAAG,EAAY,CACpB,OAAO,aAAa,QAAQ,KAAK,KAAK,IAAM,KAOvC,IAAI,EAAa,CACtB,IAAI,EAAuB,KAE3B,GAAI,CACF,EAAQ,aAAa,QAAQ,KAAK,KAAK,EACvC,MAAO,EAAK,CACZ,KAAK,QAAQ,MAAM,OAAQ,2BAA4B,CAAC,KAAG,CAAC,EAG9D,GAAI,CAAC,EAEH,OADA,KAAK,QAAQ,YAAY,gBAAgB,EAClC,KAGT,GAAI,CACF,IAAM,EAAc,KAAK,MAAM,CAAK,EAEpC,OADA,KAAK,QAAQ,gBAAgB,cAAe,OAAW,CAAC,aAAW,CAAC,EAC7D,EACP,MAAO,EAAK,CAEZ,OADA,KAAK,QAAQ,MAAM,OAAQ,mBAAoB,CAAC,KAAG,CAAC,EAC7C,MAOJ,KAAK,CAAC,EAAgB,CAC3B,KAAK,QAAQ,gBAAgB,QAAS,CAAC,OAAK,CAAC,EAC7C,IAAI,EACJ,GAAI,CACF,EAAW,KAAK,UAAU,CAAK,EAC/B,MAAO,EAAK,CAEZ,MADA,KAAK,QAAQ,MAAM,QAAS,wBAAyB,CAAC,KAAG,CAAC,EAChD,MAAM,uBAAuB,EAGzC,GAAI,CACF,aAAa,QAAQ,KAAK,MAAO,CAAQ,EACzC,MAAO,EAAK,CACZ,KAAK,QAAQ,MAAM,QAAS,4BAA6B,CAAC,KAAG,CAAC,GAO3D,MAAM,EAAS,CACpB,aAAa,WAAW,KAAK,KAAK,EAEtC,CC1HO,SAAS,CAA6B,CAAC,EAA6D,CACzG,OAAO,IAAI,EAAwB,CAAM",
9
+ "debugId": "61791411B8B0946E64756E2164756E21",
10
10
  "names": []
11
11
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alwatr/local-storage",
3
- "version": "9.4.0",
3
+ "version": "9.4.5",
4
4
  "description": "A modern, simple, and robust solution for managing versioned JSON objects in the browser's `localStorage`. This package provides a clean, class-based API with a factory function to ensure your application's data persistence is safe, maintainable, and future-proof.",
5
5
  "license": "MPL-2.0",
6
6
  "author": "S. Ali Mihandoost <ali.mihandoost@gmail.com> (https://ali.mihandoost.com)",
@@ -21,11 +21,11 @@
21
21
  },
22
22
  "sideEffects": false,
23
23
  "dependencies": {
24
- "@alwatr/logger": "9.4.0"
24
+ "@alwatr/logger": "9.4.5"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@alwatr/nano-build": "9.3.0",
28
- "@alwatr/standard": "9.4.0",
28
+ "@alwatr/standard": "9.4.5",
29
29
  "@alwatr/type-helper": "9.1.1",
30
30
  "typescript": "^6.0.2"
31
31
  },
@@ -73,5 +73,5 @@
73
73
  "utility",
74
74
  "versioning"
75
75
  ],
76
- "gitHead": "662f1047fc2a1b53a00902028d6cebfd04b52dd5"
76
+ "gitHead": "26e30d3e766cb9e2274a61d5259677643f8ca18d"
77
77
  }
package/src/facade.ts CHANGED
@@ -23,6 +23,6 @@ import type {LocalStorageProviderConfig} from './type.js';
23
23
  * console.log(currentSettings); // { theme: 'dark', notifications: false }
24
24
  * ```
25
25
  */
26
- export function createLocalStorageProvider<T extends JsonValue>(config: LocalStorageProviderConfig): LocalStorageProvider<T> {
26
+ export function createLocalStorageProvider<T>(config: LocalStorageProviderConfig): LocalStorageProvider<T> {
27
27
  return new LocalStorageProvider<T>(config);
28
28
  }
@@ -21,7 +21,7 @@ import type {LocalStorageProviderConfig} from './type.js';
21
21
  * console.log(currentSettings); // { theme: 'dark', notifications: false }
22
22
  * ```
23
23
  */
24
- export class LocalStorageProvider<T extends JsonValue> {
24
+ export class LocalStorageProvider<T> {
25
25
  public static readonly version = __package_version__;
26
26
 
27
27
  private readonly key__: string;
@@ -100,8 +100,7 @@ export class LocalStorageProvider<T extends JsonValue> {
100
100
 
101
101
  try {
102
102
  value = localStorage.getItem(this.key__);
103
- }
104
- catch (err) {
103
+ } catch (err) {
105
104
  this.logger_.error('read', 'read_local_storage_error', {err});
106
105
  }
107
106
 
@@ -114,8 +113,7 @@ export class LocalStorageProvider<T extends JsonValue> {
114
113
  const parsedValue = JSON.parse(value) as T;
115
114
  this.logger_.logMethodFull?.('read//value', undefined, {parsedValue});
116
115
  return parsedValue;
117
- }
118
- catch (err) {
116
+ } catch (err) {
119
117
  this.logger_.error('read', 'read_parse_error', {err});
120
118
  return null;
121
119
  }
@@ -129,16 +127,14 @@ export class LocalStorageProvider<T extends JsonValue> {
129
127
  let valueStr: string;
130
128
  try {
131
129
  valueStr = JSON.stringify(value);
132
- }
133
- catch (err) {
130
+ } catch (err) {
134
131
  this.logger_.error('write', 'write_stringify_error', {err});
135
132
  throw new Error('write_stringify_error');
136
133
  }
137
134
 
138
135
  try {
139
136
  localStorage.setItem(this.key__, valueStr);
140
- }
141
- catch (err) {
137
+ } catch (err) {
142
138
  this.logger_.error('write', 'write_local_storage_error', {err});
143
139
  }
144
140
  }