@nexim/alpine 1.1.3 → 1.1.4

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/CHANGELOG.md CHANGED
@@ -3,6 +3,10 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [1.1.4](https://github.com/the-nexim/nanolib/compare/@nexim/alpine@1.1.3...@nexim/alpine@1.1.4) (2025-04-21)
7
+
8
+ **Note:** Version bump only for package @nexim/alpine
9
+
6
10
  ## [1.1.3](https://github.com/the-nexim/nanolib/compare/@nexim/alpine@1.1.2...@nexim/alpine@1.1.3) (2025-01-09)
7
11
 
8
12
  ### Code Refactoring
package/README.md CHANGED
@@ -21,101 +21,10 @@ npm install @nexim/alpine
21
21
  yarn add @nexim/alpine
22
22
  ```
23
23
 
24
- ## API
24
+ ## Documentation
25
25
 
26
- ### alpineStoreGenerator
26
+ Read full documentation [here](./docs/README.md).
27
27
 
28
- Generates an Alpine.js store with a default value.
28
+ ## TODO
29
29
 
30
- #### Example Usage
31
-
32
- ```ts
33
- import {alpineStoreGenerator} from '@nexim/alpine';
34
-
35
- const store = alpineStoreGenerator({
36
- name: 'user',
37
- defaultValue: {type: 'root'},
38
- });
39
-
40
- console.log(store.type); // Output: root
41
- ```
42
-
43
- ### AlpineStore
44
-
45
- Provides a Alpine.js pure store implementation with logger.
46
-
47
- #### Constructor
48
-
49
- Creates an instance of `AlpineStore`.
50
-
51
- - **config**: The configuration object for the store.
52
- - **name**: The name of the store.
53
- - **defaultValue**: The default value of the store.
54
-
55
- ### Properties
56
-
57
- - **store**: alpine store proxy.
58
-
59
- #### Example Usage
60
-
61
- ```ts
62
- import {AlpineStore} from '@nexim/alpine';
63
-
64
- const {store} = new AlpineStore({
65
- name: 'myStore',
66
- defaultValue: {data: 'root'},
67
- });
68
-
69
- console.log(store.data); // Output: { data: 'root' }
70
- store.data = 'user';
71
-
72
- console.log(store.data); // Output: { data: 'user' }
73
- ```
74
-
75
- ### AlpineStoreWithBackup
76
-
77
- Extends `AlpineStore` to add backup and restore functionality with local storage support and expiration handling.
78
-
79
- #### Constructor
80
-
81
- Creates an instance of `AlpineStoreWithBackup`.
82
-
83
- - **config**: The configuration object for the store.
84
- - **name**: The name of the store.
85
- - **version**: The version of the store.
86
- - **defaultValue**: The default value of the store.
87
- - **expireDuration**: Optional. The duration after which the store expires.
88
-
89
- ### Properties
90
-
91
- - **store**: alpine store proxy.
92
-
93
- #### Methods
94
-
95
- - **save()**: Saves the current data to local storage. If the data is null, it clears the stored data. Also updates the expiration time.
96
- - **clear()**: Clears the local storage and set default value to store.
97
-
98
- #### Example Usage
99
-
100
- ```ts
101
- import {AlpineStoreWithBackup} from '@nexim/alpine';
102
-
103
- const storeWithBackup = new AlpineStoreWithBackup({
104
- name: 'myStoreWithBackup',
105
- version: 1,
106
- defaultValue: {data: 'root'},
107
- expireDuration: '1d',
108
- });
109
-
110
- storeWithBackup.store.data = 'user';
111
-
112
- storeWithBackup.save();
113
- console.log(storeWithBackup.store.data); // Output: { data: 'user' }
114
-
115
- storeWithBackup.clear();
116
- console.log(storeWithBackup.store.data); // Output: { data: 'root' }
117
- ```
118
-
119
- ### TODO
120
-
121
- - Analyze [@alwatr/context](https://github.com/Alwatr/flux/tree/next/packages/context) for use here.
30
+ - [ ] Analyze [@alwatr/context](https://github.com/Alwatr/flux/tree/next/packages/context) for use here.
package/dist/main.cjs CHANGED
@@ -1,4 +1,4 @@
1
- /* @nexim/alpine v1.1.3 */
1
+ /* @nexim/alpine v1.1.4 */
2
2
  "use strict";
3
3
  var __create = Object.create;
4
4
  var __defProp = Object.defineProperty;
@@ -39,8 +39,8 @@ module.exports = __toCommonJS(main_exports);
39
39
  var import_package_tracer = require("@alwatr/package-tracer");
40
40
 
41
41
  // src/store/store-generator.ts
42
- var import_logger = require("@alwatr/logger");
43
42
  var import_alpinejs = __toESM(require("alpinejs"), 1);
43
+ var import_logger = require("@alwatr/logger");
44
44
  var logger = (0, import_logger.createLogger)("@nexim/alpine");
45
45
  function alpineStoreGenerator(config) {
46
46
  logger.logMethodArgs?.("alpineStoreGenerator", { config });
@@ -58,7 +58,7 @@ var AlpineStore = class {
58
58
  * @param config - Configuration object.
59
59
  *
60
60
  * @example
61
- * ```
61
+ * ```ts
62
62
  * import {AlpineStore} from '@nexim/alpine';
63
63
  *
64
64
  * const {store} = new AlpineStore({
@@ -79,8 +79,8 @@ var AlpineStore = class {
79
79
  };
80
80
 
81
81
  // src/store/store-with-backup.ts
82
- var import_local_storage = require("@alwatr/local-storage");
83
82
  var import_parse_duration = require("@alwatr/parse-duration");
83
+ var import_local_storage = require("@alwatr/local-storage");
84
84
  var schemaVersion = 1;
85
85
  var AlpineStoreWithBackup = class extends AlpineStore {
86
86
  /**
@@ -89,7 +89,7 @@ var AlpineStoreWithBackup = class extends AlpineStore {
89
89
  * @param config__ - Configuration object.
90
90
  *
91
91
  * @example
92
- * ```
92
+ * ```ts
93
93
  * import {AlpineStoreWithBackup} from '@nexim/alpine';
94
94
  *
95
95
  * const storeWithBackup = new AlpineStoreWithBackup({
@@ -115,8 +115,8 @@ var AlpineStoreWithBackup = class extends AlpineStore {
115
115
  * Keys for storing data and expire time in local storage with version.
116
116
  */
117
117
  this.localStorageKey__ = {
118
- data: `[${"@nexim/alpine"}:data:sv${schemaVersion}]:${this.config__.name}`,
119
- expireTime: `[${"@nexim/alpine"}:expire-time:sv${schemaVersion}]:${this.config__.name}`
118
+ data: `[${"@nexim/alpine"}:data:sv${schemaVersion.toString()}]:${this.config__.name}`,
119
+ expireTime: `[${"@nexim/alpine"}:expire-time:sv${schemaVersion.toString()}]:${this.config__.name}`
120
120
  };
121
121
  if (this.config__.expireDuration != null) {
122
122
  this.handleDataExpiration__();
@@ -190,6 +190,5 @@ var AlpineStoreWithBackup = class extends AlpineStore {
190
190
  };
191
191
 
192
192
  // src/main.ts
193
- __dev_mode__: import_package_tracer.packageTracer.add("@nexim/alpine", "1.1.3");
194
- /*! For license information please see main.cjs.LEGAL.txt */
193
+ __dev_mode__: import_package_tracer.packageTracer.add("@nexim/alpine", "1.1.4");
195
194
  //# sourceMappingURL=main.cjs.map
package/dist/main.cjs.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/main.ts", "../src/store/store-generator.ts", "../src/store/store.ts", "../src/store/store-with-backup.ts"],
4
- "sourcesContent": ["import {packageTracer} from '@alwatr/package-tracer';\n\n__dev_mode__: packageTracer.add(__package_name__, __package_version__);\n\nexport * from './store/store-generator.js';\nexport * from './store/store.js';\nexport * from './store/store-with-backup.js';\n", "import {createLogger} from '@alwatr/logger';\nimport alpine from 'alpinejs';\n\nconst logger = createLogger(__package_name__);\n\n/**\n * alpineStoreGenerator Options.\n *\n * @typeParam T - The type of the default value.\n */\nexport type AlpineStoreGeneratorOptions<T extends DictionaryReq> = {\n /**\n * The name of the store.\n */\n name: string;\n\n /**\n * The default value of the store.\n */\n defaultValue: T;\n};\n\n/**\n * Generates an Alpine.js store with default value.\n *\n * @typeParam T - The type of the data.\n *\n * @param config - The configuration object for the store.\n * @returns - The initialized store instance.\n *\n * @remarks\n *\n * This function uses Alpine.js to create a reactive store with a default value.\n * The store is identified by a unique name and can be accessed and manipulated\n * throughout the application. Alpine.js stores provide a simple way to manage\n * data in your application, making it easy to keep your UI in sync with your data.\n *\n * @see {@link https://alpinejs.dev/globals/alpine-store}\n *\n * @example\n * ```\n * const store = alpineStoreGenerator({\n * name: 'user',\n * defaultValue: {type: 'root'},\n * });\n *\n * console.log(store.type); // Output: root\n *```\n */\nexport function alpineStoreGenerator<T extends DictionaryReq>(config: AlpineStoreGeneratorOptions<T>): T {\n logger.logMethodArgs?.('alpineStoreGenerator', {config});\n\n alpine.store(config.name, config.defaultValue);\n\n // Get store Proxy\n const store = alpine.store(config.name) as T;\n return store;\n}\n", "import {type AlwatrLogger, createLogger} from '@alwatr/logger';\n\nimport {alpineStoreGenerator} from './store-generator.js';\n\n/**\n * AlpineStore Options.\n *\n * @typeParam T - The type of the store value.\n * @param name - The name of the store.\n * @param defaultValue - The default value of the store.\n */\nexport type AlpineStoreOptions<T extends DictionaryReq> = {\n name: string;\n defaultValue: T;\n};\n\n/**\n * Provides a Alpine.js pure store implementation with logger.\n */\nexport class AlpineStore<T extends DictionaryReq> {\n /**\n * The store's data.\n */\n store: T;\n\n protected logger_: AlwatrLogger;\n\n /**\n * Provides a Alpine.js pure store implementation with logger.\n *\n * @param config - Configuration object.\n *\n * @example\n * ```\n * import {AlpineStore} from '@nexim/alpine';\n *\n * const {store} = new AlpineStore({\n * name: 'myStore',\n * defaultValue: {data: 'root'},\n * });\n * console.log(store.data); // Output: { data: 'root' }\n *\n * store.data = 'user';\n * console.log(store.data); // Output: { data: 'user' }\n * ```\n */\n constructor(config: AlpineStoreOptions<T>) {\n this.logger_ = createLogger(`${__package_name__}:${config.name}`);\n this.logger_.logMethodArgs?.('constructor', config);\n\n this.store = alpineStoreGenerator(config);\n }\n}\n", "import {localJsonStorage} from '@alwatr/local-storage';\nimport {parseDuration, type Duration} from '@alwatr/parse-duration';\n\nimport {AlpineStore} from './store.js';\n\n/**\n * Type for the store's data to extends from them.\n */\nexport type AlpineStoreWithBackupType = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n data: DictionaryReq<any> | null;\n};\n\n/**\n * AlpineStoreWithBackup Options.\n *\n * @typeParam T - The type of the store value.\n *\n * @param name - The name of the store.\n * @param version - The version of the store.\n * @param defaultValue - The default value of the store.\n * @param expireDuration - Optional. The duration after which the store expires.\n */\nexport type AlpineStoreWithBackupOptions<T extends AlpineStoreWithBackupType> = {\n name: string;\n version: number;\n defaultValue: T;\n expireDuration?: Duration;\n};\n\n/**\n * Version of the schema for storing data in local storage.\n *\n * Change when this schema changes.\n */\nconst schemaVersion = 1;\n\n/**\n * Provides a Alpine.js store implementation with backup and expiration.\n */\nexport class AlpineStoreWithBackup<T extends AlpineStoreWithBackupType> extends AlpineStore<T> {\n /**\n * Keys for storing data and expire time in local storage with version.\n */\n private localStorageKey__ = {\n data: `[${__package_name__}:data:sv${schemaVersion}]:${this.config__.name}`,\n expireTime: `[${__package_name__}:expire-time:sv${schemaVersion}]:${this.config__.name}`,\n };\n\n /**\n * Provides a Alpine.js store implementation with backup and expiration.\n *\n * @param config__ - Configuration object.\n *\n * @example\n * ```\n * import {AlpineStoreWithBackup} from '@nexim/alpine';\n *\n * const storeWithBackup = new AlpineStoreWithBackup({\n * name: 'myStoreWithBackup',\n * version: 1,\n * defaultValue: {data: 'root'},\n * expireDuration: '1d',\n * });\n *\n * storeWithBackup.store.data = 'user';\n *\n * storeWithBackup.save();\n * console.log(storeWithBackup.store.data); // Output: { data: 'user' }\n *\n * storeWithBackup.clear();\n * console.log(storeWithBackup.store.data); // Output: { data: 'root' }\n * ```\n */\n constructor(private config__: AlpineStoreWithBackupOptions<T>) {\n super(config__);\n\n if (this.config__.expireDuration != null) {\n this.handleDataExpiration__();\n }\n\n this.load__();\n }\n\n /**\n * Saves the current data to local storage. If the data is null, it clears the stored data.\n *\n * Also updates the expiration time.\n */\n save(): void {\n this.logger_.logMethodArgs?.('save', {data: this.store.data});\n\n if (this.store.data === null) {\n this.clear();\n return;\n }\n\n localJsonStorage.setItem(this.localStorageKey__.data, this.store.data, this.config__.version);\n this.updateExpireTime__();\n }\n\n /**\n * Clears the stored data.\n */\n clear(): void {\n this.logger_.logMethod?.('clear');\n\n localJsonStorage.removeItem(this.localStorageKey__.data, this.config__.version);\n localJsonStorage.removeItem(this.localStorageKey__.expireTime, this.config__.version);\n\n this.store = this.config__.defaultValue;\n }\n\n /**\n * Handles the expiration duration by checking if the stored data has expired.\n * If expired, it clears the stored data.\n */\n private handleDataExpiration__(): void {\n this.logger_.logMethod?.('handleDataExpiration__');\n\n // FIXME: use null if not set, after local storage new version.\n const expireDuration = localJsonStorage.getItem<{time: number}>(\n this.localStorageKey__.expireTime,\n {time: -1},\n this.config__.version,\n ).time;\n\n if (expireDuration !== -1 && expireDuration < Date.now()) {\n this.clear();\n }\n }\n\n /**\n * Loads data from local storage and updates the store's data.\n *\n * When data is not found or invalid in local storage, it uses the default value.\n *\n * FIXME: remove `NonNullable` from `<T['data']>`, after local storage new version.\n */\n private load__(): void {\n this.logger_.logMethod?.('load__');\n\n const newData = localJsonStorage.getItem<NonNullable<T['data']>>(\n this.localStorageKey__.data,\n this.config__.defaultValue.data as NonNullable<T['data']>,\n this.config__.version,\n ) as T['data'];\n this.store.data = newData;\n }\n\n /**\n * Updates the expiration time in local storage to the current time plus the configured expiration duration.\n */\n private updateExpireTime__(): void {\n if (this.config__.expireDuration == null) return;\n this.logger_.logMethod?.('updateExpireTime__');\n\n const newExpireTime = Date.now() + parseDuration(this.config__.expireDuration);\n localJsonStorage.setItem(this.localStorageKey__.expireTime, {time: newExpireTime}, this.config__.version);\n\n this.logger_.logOther?.('updated_expire_time', {newExpireTime});\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAA4B;;;ACA5B,oBAA2B;AAC3B,sBAAmB;AAEnB,IAAM,aAAS,4BAAa,eAAgB;AA8CrC,SAAS,qBAA8C,QAA2C;AACvG,SAAO,gBAAgB,wBAAwB,EAAC,OAAM,CAAC;AAEvD,kBAAAA,QAAO,MAAM,OAAO,MAAM,OAAO,YAAY;AAG7C,QAAM,QAAQ,gBAAAA,QAAO,MAAM,OAAO,IAAI;AACtC,SAAO;AACT;;;ACzDA,IAAAC,iBAA8C;AAmBvC,IAAM,cAAN,MAA2C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA2BhD,YAAY,QAA+B;AACzC,SAAK,cAAU,6BAAa,GAAG,eAAgB,IAAI,OAAO,IAAI,EAAE;AAChE,S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;AAAA,EAMQ,yBAA+B;AACrC,SAAK,QAAQ,YAAY,wBAAwB;AAGjD,UAAM,iBAAiB,sCAAiB;AAAA,MACtC,KAAK,kBAAkB;AAAA,MACvB,EAAC,MAAM,GAAE;AAAA,MACT,KAAK,SAAS;AAAA,IAChB,EAAE;AAEF,QAAI,mBAAmB,MAAM,iBAAiB,KAAK,IAAI,GAAG;AACxD,WAAK,MAAM;AAAA,IACb;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASQ,SAAe;AACrB,SAAK,QAAQ,YAAY,QAAQ;AAEjC,UAAM,UAAU,sCAAiB;AAAA,MAC/B,KAAK,kBAAkB;AAAA,MACvB,KAAK,SAAS,aAAa;AAAA,MAC3B,KAAK,SAAS;AAAA,IAChB;AACA,SAAK,MAAM,OAAO;AAAA,EACpB;AAAA;AAAA;AAAA;AAAA,EAKQ,qBAA2B;AACjC,QAAI,KAAK,SAAS,kBAAkB,KAAM;AAC1C,SAAK,QAAQ,YAAY,oBAAoB;AAE7C,UAAM,gBAAgB,KAAK,IAAI,QAAI,qCAAc,KAAK,SAAS,cAAc;AAC7E,0CAAiB,QAAQ,KAAK,kBAAkB,YAAY,EAAC,MAAM,cAAa,GAAG,KAAK,SAAS,OAAO;AAExG,SAAK,QAAQ,WAAW,uBAAuB,EAAC,cAAa,CAAC;AAAA,EAChE;AACF;;;AHhKA,aAAc,qCAAc,IAAI,iBAAkB,OAAmB;",
4
+ "sourcesContent": ["import { packageTracer } from '@alwatr/package-tracer';\n\n__dev_mode__: packageTracer.add(__package_name__, __package_version__);\n\nexport * from './store/store-generator.js';\nexport * from './store/store.js';\nexport * from './store/store-with-backup.js';\n", "import alpine from 'alpinejs';\nimport { createLogger } from '@alwatr/logger';\n\nconst logger = createLogger(__package_name__);\n\n/**\n * alpineStoreGenerator Options.\n *\n * @typeParam T - The type of the default value.\n */\nexport type AlpineStoreGeneratorOptions<T extends DictionaryReq> = {\n /**\n * The name of the store.\n */\n name: string;\n\n /**\n * The default value of the store.\n */\n defaultValue: T;\n};\n\n/**\n * Generates an Alpine.js store with default value.\n *\n * @typeParam T - The type of the data.\n *\n * @param config - The configuration object for the store.\n * @returns - The initialized store instance.\n *\n * @remarks\n *\n * This function uses Alpine.js to create a reactive store with a default value.\n * The store is identified by a unique name and can be accessed and manipulated\n * throughout the application. Alpine.js stores provide a simple way to manage\n * data in your application, making it easy to keep your UI in sync with your data.\n *\n * @see {@link https://alpinejs.dev/globals/alpine-store}\n *\n * @example\n * ```ts\n * const store = alpineStoreGenerator({\n * name: 'user',\n * defaultValue: {type: 'root'},\n * });\n *\n * console.log(store.type); // Output: root\n *```\n */\nexport function alpineStoreGenerator<T extends DictionaryReq>(config: AlpineStoreGeneratorOptions<T>): T {\n logger.logMethodArgs?.('alpineStoreGenerator', { config });\n\n alpine.store(config.name, config.defaultValue);\n\n // Get store Proxy\n const store = alpine.store(config.name) as T;\n return store;\n}\n", "import { type AlwatrLogger, createLogger } from '@alwatr/logger';\n\nimport { alpineStoreGenerator } from './store-generator.js';\n\n/**\n * AlpineStore Options.\n *\n * @typeParam T - The type of the store value.\n */\nexport type AlpineStoreOptions<T extends DictionaryReq> = {\n /**\n * The name of the store.\n */\n name: string;\n\n /**\n * The default value of the store.\n */\n defaultValue: T;\n};\n\n/**\n * Provides a Alpine.js pure store implementation with logger.\n */\nexport class AlpineStore<T extends DictionaryReq> {\n /**\n * The store's data.\n */\n store: T;\n\n protected logger_: AlwatrLogger;\n\n /**\n * Provides a Alpine.js pure store implementation with logger.\n *\n * @param config - Configuration object.\n *\n * @example\n * ```ts\n * import {AlpineStore} from '@nexim/alpine';\n *\n * const {store} = new AlpineStore({\n * name: 'myStore',\n * defaultValue: {data: 'root'},\n * });\n * console.log(store.data); // Output: { data: 'root' }\n *\n * store.data = 'user';\n * console.log(store.data); // Output: { data: 'user' }\n * ```\n */\n constructor(config: AlpineStoreOptions<T>) {\n this.logger_ = createLogger(`${__package_name__}:${config.name}`);\n this.logger_.logMethodArgs?.('constructor', config);\n\n this.store = alpineStoreGenerator(config);\n }\n}\n", "import { type Duration, parseDuration } from '@alwatr/parse-duration';\nimport { AlpineStore } from './store.js';\nimport { localJsonStorage } from '@alwatr/local-storage';\n\n/**\n * Type for the store's data to extends from them.\n */\nexport type AlpineStoreWithBackupType = {\n data: DictionaryReq | null;\n};\n\n/**\n * AlpineStoreWithBackup Options.\n *\n * @typeParam T - The type of the store value.\n */\nexport type AlpineStoreWithBackupOptions<T extends AlpineStoreWithBackupType> = {\n /**\n * The name of the store.\n */\n name: string;\n\n /**\n * The version of the store.\n */\n version: number;\n\n /**\n * The default value of the store.\n */\n defaultValue: T;\n\n /**\n * Optional. The duration after which the store expires.\n */\n expireDuration?: Duration;\n};\n\n/**\n * Version of the schema for storing data in local storage.\n *\n * Change when this schema changes.\n */\nconst schemaVersion = 1;\n\n/**\n * Provides a Alpine.js store implementation with backup and expiration.\n */\nexport class AlpineStoreWithBackup<T extends AlpineStoreWithBackupType> extends AlpineStore<T> {\n /**\n * Keys for storing data and expire time in local storage with version.\n */\n private localStorageKey__ = {\n data: `[${__package_name__}:data:sv${schemaVersion.toString()}]:${this.config__.name}`,\n expireTime: `[${__package_name__}:expire-time:sv${schemaVersion.toString()}]:${this.config__.name}`,\n };\n\n /**\n * Provides a Alpine.js store implementation with backup and expiration.\n *\n * @param config__ - Configuration object.\n *\n * @example\n * ```ts\n * import {AlpineStoreWithBackup} from '@nexim/alpine';\n *\n * const storeWithBackup = new AlpineStoreWithBackup({\n * name: 'myStoreWithBackup',\n * version: 1,\n * defaultValue: {data: 'root'},\n * expireDuration: '1d',\n * });\n *\n * storeWithBackup.store.data = 'user';\n *\n * storeWithBackup.save();\n * console.log(storeWithBackup.store.data); // Output: { data: 'user' }\n *\n * storeWithBackup.clear();\n * console.log(storeWithBackup.store.data); // Output: { data: 'root' }\n * ```\n */\n constructor(private config__: AlpineStoreWithBackupOptions<T>) {\n super(config__);\n\n if (this.config__.expireDuration != null) {\n this.handleDataExpiration__();\n }\n\n this.load__();\n }\n\n /**\n * Saves the current data to local storage. If the data is null, it clears the stored data.\n *\n * Also updates the expiration time.\n */\n save(): void {\n this.logger_.logMethodArgs?.('save', { data: this.store.data });\n\n if (this.store.data === null) {\n this.clear();\n return;\n }\n\n localJsonStorage.setItem(this.localStorageKey__.data, this.store.data, this.config__.version);\n this.updateExpireTime__();\n }\n\n /**\n * Clears the stored data.\n */\n clear(): void {\n this.logger_.logMethod?.('clear');\n\n localJsonStorage.removeItem(this.localStorageKey__.data, this.config__.version);\n localJsonStorage.removeItem(this.localStorageKey__.expireTime, this.config__.version);\n\n this.store = this.config__.defaultValue;\n }\n\n /**\n * Handles the expiration duration by checking if the stored data has expired.\n * If expired, it clears the stored data.\n */\n private handleDataExpiration__(): void {\n this.logger_.logMethod?.('handleDataExpiration__');\n\n // FIXME: use null if not set, after local storage new version.\n const expireDuration = localJsonStorage.getItem<{ time: number }>(\n this.localStorageKey__.expireTime,\n { time: -1 },\n this.config__.version,\n ).time;\n\n if (expireDuration !== -1 && expireDuration < Date.now()) {\n this.clear();\n }\n }\n\n /**\n * Loads data from local storage and updates the store's data.\n *\n * When data is not found or invalid in local storage, it uses the default value.\n *\n * FIXME: remove `NonNullable` from `<T['data']>`, after local storage new version.\n */\n private load__(): void {\n this.logger_.logMethod?.('load__');\n\n const newData = localJsonStorage.getItem<NonNullable<T['data']>>(\n this.localStorageKey__.data,\n this.config__.defaultValue.data as NonNullable<T['data']>,\n this.config__.version,\n ) as T['data'];\n this.store.data = newData;\n }\n\n /**\n * Updates the expiration time in local storage to the current time plus the configured expiration duration.\n */\n private updateExpireTime__(): void {\n if (this.config__.expireDuration == null) return;\n this.logger_.logMethod?.('updateExpireTime__');\n\n const newExpireTime = Date.now() + parseDuration(this.config__.expireDuration);\n localJsonStorage.setItem(this.localStorageKey__.expireTime, { time: newExpireTime }, this.config__.version);\n\n this.logger_.logOther?.('updated_expire_time', { newExpireTime });\n }\n}\n"],
5
+ "mappings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K,SAAS,kBAAkB,KAAM;AAC1C,SAAK,QAAQ,YAAY,oBAAoB;AAE7C,UAAM,gBAAgB,KAAK,IAAI,QAAI,qCAAc,KAAK,SAAS,cAAc;AAC7E,0CAAiB,QAAQ,KAAK,kBAAkB,YAAY,EAAE,MAAM,cAAc,GAAG,KAAK,SAAS,OAAO;AAE1G,SAAK,QAAQ,WAAW,uBAAuB,EAAE,cAAc,CAAC;AAAA,EAClE;AACF;;;AHxKA,aAAc,qCAAc,IAAI,iBAAkB,OAAmB;",
6
6
  "names": ["alpine", "import_logger"]
7
7
  }
package/dist/main.mjs CHANGED
@@ -1,11 +1,11 @@
1
- /* @nexim/alpine v1.1.3 */
1
+ /* @nexim/alpine v1.1.4 */
2
2
 
3
3
  // src/main.ts
4
4
  import { packageTracer } from "@alwatr/package-tracer";
5
5
 
6
6
  // src/store/store-generator.ts
7
- import { createLogger } from "@alwatr/logger";
8
7
  import alpine from "alpinejs";
8
+ import { createLogger } from "@alwatr/logger";
9
9
  var logger = createLogger("@nexim/alpine");
10
10
  function alpineStoreGenerator(config) {
11
11
  logger.logMethodArgs?.("alpineStoreGenerator", { config });
@@ -23,7 +23,7 @@ var AlpineStore = class {
23
23
  * @param config - Configuration object.
24
24
  *
25
25
  * @example
26
- * ```
26
+ * ```ts
27
27
  * import {AlpineStore} from '@nexim/alpine';
28
28
  *
29
29
  * const {store} = new AlpineStore({
@@ -44,8 +44,8 @@ var AlpineStore = class {
44
44
  };
45
45
 
46
46
  // src/store/store-with-backup.ts
47
- import { localJsonStorage } from "@alwatr/local-storage";
48
47
  import { parseDuration } from "@alwatr/parse-duration";
48
+ import { localJsonStorage } from "@alwatr/local-storage";
49
49
  var schemaVersion = 1;
50
50
  var AlpineStoreWithBackup = class extends AlpineStore {
51
51
  /**
@@ -54,7 +54,7 @@ var AlpineStoreWithBackup = class extends AlpineStore {
54
54
  * @param config__ - Configuration object.
55
55
  *
56
56
  * @example
57
- * ```
57
+ * ```ts
58
58
  * import {AlpineStoreWithBackup} from '@nexim/alpine';
59
59
  *
60
60
  * const storeWithBackup = new AlpineStoreWithBackup({
@@ -80,8 +80,8 @@ var AlpineStoreWithBackup = class extends AlpineStore {
80
80
  * Keys for storing data and expire time in local storage with version.
81
81
  */
82
82
  this.localStorageKey__ = {
83
- data: `[${"@nexim/alpine"}:data:sv${schemaVersion}]:${this.config__.name}`,
84
- expireTime: `[${"@nexim/alpine"}:expire-time:sv${schemaVersion}]:${this.config__.name}`
83
+ data: `[${"@nexim/alpine"}:data:sv${schemaVersion.toString()}]:${this.config__.name}`,
84
+ expireTime: `[${"@nexim/alpine"}:expire-time:sv${schemaVersion.toString()}]:${this.config__.name}`
85
85
  };
86
86
  if (this.config__.expireDuration != null) {
87
87
  this.handleDataExpiration__();
@@ -155,11 +155,10 @@ var AlpineStoreWithBackup = class extends AlpineStore {
155
155
  };
156
156
 
157
157
  // src/main.ts
158
- __dev_mode__: packageTracer.add("@nexim/alpine", "1.1.3");
158
+ __dev_mode__: packageTracer.add("@nexim/alpine", "1.1.4");
159
159
  export {
160
160
  AlpineStore,
161
161
  AlpineStoreWithBackup,
162
162
  alpineStoreGenerator
163
163
  };
164
- /*! For license information please see main.mjs.LEGAL.txt */
165
164
  //# sourceMappingURL=main.mjs.map
package/dist/main.mjs.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/main.ts", "../src/store/store-generator.ts", "../src/store/store.ts", "../src/store/store-with-backup.ts"],
4
- "sourcesContent": ["import {packageTracer} from '@alwatr/package-tracer';\n\n__dev_mode__: packageTracer.add(__package_name__, __package_version__);\n\nexport * from './store/store-generator.js';\nexport * from './store/store.js';\nexport * from './store/store-with-backup.js';\n", "import {createLogger} from '@alwatr/logger';\nimport alpine from 'alpinejs';\n\nconst logger = createLogger(__package_name__);\n\n/**\n * alpineStoreGenerator Options.\n *\n * @typeParam T - The type of the default value.\n */\nexport type AlpineStoreGeneratorOptions<T extends DictionaryReq> = {\n /**\n * The name of the store.\n */\n name: string;\n\n /**\n * The default value of the store.\n */\n defaultValue: T;\n};\n\n/**\n * Generates an Alpine.js store with default value.\n *\n * @typeParam T - The type of the data.\n *\n * @param config - The configuration object for the store.\n * @returns - The initialized store instance.\n *\n * @remarks\n *\n * This function uses Alpine.js to create a reactive store with a default value.\n * The store is identified by a unique name and can be accessed and manipulated\n * throughout the application. Alpine.js stores provide a simple way to manage\n * data in your application, making it easy to keep your UI in sync with your data.\n *\n * @see {@link https://alpinejs.dev/globals/alpine-store}\n *\n * @example\n * ```\n * const store = alpineStoreGenerator({\n * name: 'user',\n * defaultValue: {type: 'root'},\n * });\n *\n * console.log(store.type); // Output: root\n *```\n */\nexport function alpineStoreGenerator<T extends DictionaryReq>(config: AlpineStoreGeneratorOptions<T>): T {\n logger.logMethodArgs?.('alpineStoreGenerator', {config});\n\n alpine.store(config.name, config.defaultValue);\n\n // Get store Proxy\n const store = alpine.store(config.name) as T;\n return store;\n}\n", "import {type AlwatrLogger, createLogger} from '@alwatr/logger';\n\nimport {alpineStoreGenerator} from './store-generator.js';\n\n/**\n * AlpineStore Options.\n *\n * @typeParam T - The type of the store value.\n * @param name - The name of the store.\n * @param defaultValue - The default value of the store.\n */\nexport type AlpineStoreOptions<T extends DictionaryReq> = {\n name: string;\n defaultValue: T;\n};\n\n/**\n * Provides a Alpine.js pure store implementation with logger.\n */\nexport class AlpineStore<T extends DictionaryReq> {\n /**\n * The store's data.\n */\n store: T;\n\n protected logger_: AlwatrLogger;\n\n /**\n * Provides a Alpine.js pure store implementation with logger.\n *\n * @param config - Configuration object.\n *\n * @example\n * ```\n * import {AlpineStore} from '@nexim/alpine';\n *\n * const {store} = new AlpineStore({\n * name: 'myStore',\n * defaultValue: {data: 'root'},\n * });\n * console.log(store.data); // Output: { data: 'root' }\n *\n * store.data = 'user';\n * console.log(store.data); // Output: { data: 'user' }\n * ```\n */\n constructor(config: AlpineStoreOptions<T>) {\n this.logger_ = createLogger(`${__package_name__}:${config.name}`);\n this.logger_.logMethodArgs?.('constructor', config);\n\n this.store = alpineStoreGenerator(config);\n }\n}\n", "import {localJsonStorage} from '@alwatr/local-storage';\nimport {parseDuration, type Duration} from '@alwatr/parse-duration';\n\nimport {AlpineStore} from './store.js';\n\n/**\n * Type for the store's data to extends from them.\n */\nexport type AlpineStoreWithBackupType = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n data: DictionaryReq<any> | null;\n};\n\n/**\n * AlpineStoreWithBackup Options.\n *\n * @typeParam T - The type of the store value.\n *\n * @param name - The name of the store.\n * @param version - The version of the store.\n * @param defaultValue - The default value of the store.\n * @param expireDuration - Optional. The duration after which the store expires.\n */\nexport type AlpineStoreWithBackupOptions<T extends AlpineStoreWithBackupType> = {\n name: string;\n version: number;\n defaultValue: T;\n expireDuration?: Duration;\n};\n\n/**\n * Version of the schema for storing data in local storage.\n *\n * Change when this schema changes.\n */\nconst schemaVersion = 1;\n\n/**\n * Provides a Alpine.js store implementation with backup and expiration.\n */\nexport class AlpineStoreWithBackup<T extends AlpineStoreWithBackupType> extends AlpineStore<T> {\n /**\n * Keys for storing data and expire time in local storage with version.\n */\n private localStorageKey__ = {\n data: `[${__package_name__}:data:sv${schemaVersion}]:${this.config__.name}`,\n expireTime: `[${__package_name__}:expire-time:sv${schemaVersion}]:${this.config__.name}`,\n };\n\n /**\n * Provides a Alpine.js store implementation with backup and expiration.\n *\n * @param config__ - Configuration object.\n *\n * @example\n * ```\n * import {AlpineStoreWithBackup} from '@nexim/alpine';\n *\n * const storeWithBackup = new AlpineStoreWithBackup({\n * name: 'myStoreWithBackup',\n * version: 1,\n * defaultValue: {data: 'root'},\n * expireDuration: '1d',\n * });\n *\n * storeWithBackup.store.data = 'user';\n *\n * storeWithBackup.save();\n * console.log(storeWithBackup.store.data); // Output: { data: 'user' }\n *\n * storeWithBackup.clear();\n * console.log(storeWithBackup.store.data); // Output: { data: 'root' }\n * ```\n */\n constructor(private config__: AlpineStoreWithBackupOptions<T>) {\n super(config__);\n\n if (this.config__.expireDuration != null) {\n this.handleDataExpiration__();\n }\n\n this.load__();\n }\n\n /**\n * Saves the current data to local storage. If the data is null, it clears the stored data.\n *\n * Also updates the expiration time.\n */\n save(): void {\n this.logger_.logMethodArgs?.('save', {data: this.store.data});\n\n if (this.store.data === null) {\n this.clear();\n return;\n }\n\n localJsonStorage.setItem(this.localStorageKey__.data, this.store.data, this.config__.version);\n this.updateExpireTime__();\n }\n\n /**\n * Clears the stored data.\n */\n clear(): void {\n this.logger_.logMethod?.('clear');\n\n localJsonStorage.removeItem(this.localStorageKey__.data, this.config__.version);\n localJsonStorage.removeItem(this.localStorageKey__.expireTime, this.config__.version);\n\n this.store = this.config__.defaultValue;\n }\n\n /**\n * Handles the expiration duration by checking if the stored data has expired.\n * If expired, it clears the stored data.\n */\n private handleDataExpiration__(): void {\n this.logger_.logMethod?.('handleDataExpiration__');\n\n // FIXME: use null if not set, after local storage new version.\n const expireDuration = localJsonStorage.getItem<{time: number}>(\n this.localStorageKey__.expireTime,\n {time: -1},\n this.config__.version,\n ).time;\n\n if (expireDuration !== -1 && expireDuration < Date.now()) {\n this.clear();\n }\n }\n\n /**\n * Loads data from local storage and updates the store's data.\n *\n * When data is not found or invalid in local storage, it uses the default value.\n *\n * FIXME: remove `NonNullable` from `<T['data']>`, after local storage new version.\n */\n private load__(): void {\n this.logger_.logMethod?.('load__');\n\n const newData = localJsonStorage.getItem<NonNullable<T['data']>>(\n this.localStorageKey__.data,\n this.config__.defaultValue.data as NonNullable<T['data']>,\n this.config__.version,\n ) as T['data'];\n this.store.data = newData;\n }\n\n /**\n * Updates the expiration time in local storage to the current time plus the configured expiration duration.\n */\n private updateExpireTime__(): void {\n if (this.config__.expireDuration == null) return;\n this.logger_.logMethod?.('updateExpireTime__');\n\n const newExpireTime = Date.now() + parseDuration(this.config__.expireDuration);\n localJsonStorage.setItem(this.localStorageKey__.expireTime, {time: newExpireTime}, this.config__.version);\n\n this.logger_.logOther?.('updated_expire_time', {newExpireTime});\n }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AAE7C,UAAM,gBAAgB,KAAK,IAAI,IAAI,cAAc,KAAK,SAAS,cAAc;AAC7E,qBAAiB,QAAQ,KAAK,kBAAkB,YAAY,EAAC,MAAM,cAAa,GAAG,KAAK,SAAS,OAAO;AAExG,SAAK,QAAQ,WAAW,uBAAuB,EAAC,cAAa,CAAC;AAAA,EAChE;AACF;;;AHhKA,aAAc,eAAc,IAAI,iBAAkB,OAAmB;",
4
+ "sourcesContent": ["import { packageTracer } from '@alwatr/package-tracer';\n\n__dev_mode__: packageTracer.add(__package_name__, __package_version__);\n\nexport * from './store/store-generator.js';\nexport * from './store/store.js';\nexport * from './store/store-with-backup.js';\n", "import alpine from 'alpinejs';\nimport { createLogger } from '@alwatr/logger';\n\nconst logger = createLogger(__package_name__);\n\n/**\n * alpineStoreGenerator Options.\n *\n * @typeParam T - The type of the default value.\n */\nexport type AlpineStoreGeneratorOptions<T extends DictionaryReq> = {\n /**\n * The name of the store.\n */\n name: string;\n\n /**\n * The default value of the store.\n */\n defaultValue: T;\n};\n\n/**\n * Generates an Alpine.js store with default value.\n *\n * @typeParam T - The type of the data.\n *\n * @param config - The configuration object for the store.\n * @returns - The initialized store instance.\n *\n * @remarks\n *\n * This function uses Alpine.js to create a reactive store with a default value.\n * The store is identified by a unique name and can be accessed and manipulated\n * throughout the application. Alpine.js stores provide a simple way to manage\n * data in your application, making it easy to keep your UI in sync with your data.\n *\n * @see {@link https://alpinejs.dev/globals/alpine-store}\n *\n * @example\n * ```ts\n * const store = alpineStoreGenerator({\n * name: 'user',\n * defaultValue: {type: 'root'},\n * });\n *\n * console.log(store.type); // Output: root\n *```\n */\nexport function alpineStoreGenerator<T extends DictionaryReq>(config: AlpineStoreGeneratorOptions<T>): T {\n logger.logMethodArgs?.('alpineStoreGenerator', { config });\n\n alpine.store(config.name, config.defaultValue);\n\n // Get store Proxy\n const store = alpine.store(config.name) as T;\n return store;\n}\n", "import { type AlwatrLogger, createLogger } from '@alwatr/logger';\n\nimport { alpineStoreGenerator } from './store-generator.js';\n\n/**\n * AlpineStore Options.\n *\n * @typeParam T - The type of the store value.\n */\nexport type AlpineStoreOptions<T extends DictionaryReq> = {\n /**\n * The name of the store.\n */\n name: string;\n\n /**\n * The default value of the store.\n */\n defaultValue: T;\n};\n\n/**\n * Provides a Alpine.js pure store implementation with logger.\n */\nexport class AlpineStore<T extends DictionaryReq> {\n /**\n * The store's data.\n */\n store: T;\n\n protected logger_: AlwatrLogger;\n\n /**\n * Provides a Alpine.js pure store implementation with logger.\n *\n * @param config - Configuration object.\n *\n * @example\n * ```ts\n * import {AlpineStore} from '@nexim/alpine';\n *\n * const {store} = new AlpineStore({\n * name: 'myStore',\n * defaultValue: {data: 'root'},\n * });\n * console.log(store.data); // Output: { data: 'root' }\n *\n * store.data = 'user';\n * console.log(store.data); // Output: { data: 'user' }\n * ```\n */\n constructor(config: AlpineStoreOptions<T>) {\n this.logger_ = createLogger(`${__package_name__}:${config.name}`);\n this.logger_.logMethodArgs?.('constructor', config);\n\n this.store = alpineStoreGenerator(config);\n }\n}\n", "import { type Duration, parseDuration } from '@alwatr/parse-duration';\nimport { AlpineStore } from './store.js';\nimport { localJsonStorage } from '@alwatr/local-storage';\n\n/**\n * Type for the store's data to extends from them.\n */\nexport type AlpineStoreWithBackupType = {\n data: DictionaryReq | null;\n};\n\n/**\n * AlpineStoreWithBackup Options.\n *\n * @typeParam T - The type of the store value.\n */\nexport type AlpineStoreWithBackupOptions<T extends AlpineStoreWithBackupType> = {\n /**\n * The name of the store.\n */\n name: string;\n\n /**\n * The version of the store.\n */\n version: number;\n\n /**\n * The default value of the store.\n */\n defaultValue: T;\n\n /**\n * Optional. The duration after which the store expires.\n */\n expireDuration?: Duration;\n};\n\n/**\n * Version of the schema for storing data in local storage.\n *\n * Change when this schema changes.\n */\nconst schemaVersion = 1;\n\n/**\n * Provides a Alpine.js store implementation with backup and expiration.\n */\nexport class AlpineStoreWithBackup<T extends AlpineStoreWithBackupType> extends AlpineStore<T> {\n /**\n * Keys for storing data and expire time in local storage with version.\n */\n private localStorageKey__ = {\n data: `[${__package_name__}:data:sv${schemaVersion.toString()}]:${this.config__.name}`,\n expireTime: `[${__package_name__}:expire-time:sv${schemaVersion.toString()}]:${this.config__.name}`,\n };\n\n /**\n * Provides a Alpine.js store implementation with backup and expiration.\n *\n * @param config__ - Configuration object.\n *\n * @example\n * ```ts\n * import {AlpineStoreWithBackup} from '@nexim/alpine';\n *\n * const storeWithBackup = new AlpineStoreWithBackup({\n * name: 'myStoreWithBackup',\n * version: 1,\n * defaultValue: {data: 'root'},\n * expireDuration: '1d',\n * });\n *\n * storeWithBackup.store.data = 'user';\n *\n * storeWithBackup.save();\n * console.log(storeWithBackup.store.data); // Output: { data: 'user' }\n *\n * storeWithBackup.clear();\n * console.log(storeWithBackup.store.data); // Output: { data: 'root' }\n * ```\n */\n constructor(private config__: AlpineStoreWithBackupOptions<T>) {\n super(config__);\n\n if (this.config__.expireDuration != null) {\n this.handleDataExpiration__();\n }\n\n this.load__();\n }\n\n /**\n * Saves the current data to local storage. If the data is null, it clears the stored data.\n *\n * Also updates the expiration time.\n */\n save(): void {\n this.logger_.logMethodArgs?.('save', { data: this.store.data });\n\n if (this.store.data === null) {\n this.clear();\n return;\n }\n\n localJsonStorage.setItem(this.localStorageKey__.data, this.store.data, this.config__.version);\n this.updateExpireTime__();\n }\n\n /**\n * Clears the stored data.\n */\n clear(): void {\n this.logger_.logMethod?.('clear');\n\n localJsonStorage.removeItem(this.localStorageKey__.data, this.config__.version);\n localJsonStorage.removeItem(this.localStorageKey__.expireTime, this.config__.version);\n\n this.store = this.config__.defaultValue;\n }\n\n /**\n * Handles the expiration duration by checking if the stored data has expired.\n * If expired, it clears the stored data.\n */\n private handleDataExpiration__(): void {\n this.logger_.logMethod?.('handleDataExpiration__');\n\n // FIXME: use null if not set, after local storage new version.\n const expireDuration = localJsonStorage.getItem<{ time: number }>(\n this.localStorageKey__.expireTime,\n { time: -1 },\n this.config__.version,\n ).time;\n\n if (expireDuration !== -1 && expireDuration < Date.now()) {\n this.clear();\n }\n }\n\n /**\n * Loads data from local storage and updates the store's data.\n *\n * When data is not found or invalid in local storage, it uses the default value.\n *\n * FIXME: remove `NonNullable` from `<T['data']>`, after local storage new version.\n */\n private load__(): void {\n this.logger_.logMethod?.('load__');\n\n const newData = localJsonStorage.getItem<NonNullable<T['data']>>(\n this.localStorageKey__.data,\n this.config__.defaultValue.data as NonNullable<T['data']>,\n this.config__.version,\n ) as T['data'];\n this.store.data = newData;\n }\n\n /**\n * Updates the expiration time in local storage to the current time plus the configured expiration duration.\n */\n private updateExpireTime__(): void {\n if (this.config__.expireDuration == null) return;\n this.logger_.logMethod?.('updateExpireTime__');\n\n const newExpireTime = Date.now() + parseDuration(this.config__.expireDuration);\n localJsonStorage.setItem(this.localStorageKey__.expireTime, { time: newExpireTime }, this.config__.version);\n\n this.logger_.logOther?.('updated_expire_time', { newExpireTime });\n }\n}\n"],
5
+ "mappings": ";;;AAAA,SAAS,qBAAqB;;;ACA9B,OAAO,YAAY;AACnB,SAAS,oBAAoB;AAE7B,IAAM,SAAS,aAAa,eAAgB;AA8CrC,SAAS,qBAA8C,QAA2C;AACvG,SAAO,gBAAgB,wBAAwB,EAAE,OAAO,CAAC;AAEzD,SAAO,MAAM,OAAO,MAAM,OAAO,YAAY;AAG7C,QAAM,QAAQ,OAAO,MAAM,OAAO,IAAI;AACtC,SAAO;AACT;;;ACzDA,SAA4B,gBAAAA,qBAAoB;AAwBzC,IAAM,cAAN,MAA2C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA2BhD,YAAY,QAA+B;AACzC,SAAK,UAAUC,cAAa,GAAG,eAAgB,IAAI,OAAO,IAAI,EAAE;AAChE,SAAK,QAAQ,gBAAgB,eAAe,MAAM;AAElD,SAAK,QAAQ,qBAAqB,MAAM;AAAA,EAC1C;AACF;;;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BAAwB;AAGjD,UAAM,iBAAiB,iBAAiB;AAAA,MACtC,KAAK,kBAAkB;AAAA,MACvB,EAAE,MAAM,GAAG;AAAA,MACX,KAAK,SAAS;AAAA,IAChB,EAAE;AAEF,QAAI,mBAAmB,MAAM,iBAAiB,KAAK,IAAI,GAAG;AACxD,WAAK,MAAM;AAAA,IACb;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASQ,SAAe;AACrB,SAAK,QAAQ,YAAY,QAAQ;AAEjC,UAAM,UAAU,iBAAiB;AAAA,MAC/B,KAAK,kBAAkB;AAAA,MACvB,KAAK,SAAS,aAAa;AAAA,MAC3B,KAAK,SAAS;AAAA,IAChB;AACA,SAAK,MAAM,OAAO;AAAA,EACpB;AAAA;AAAA;AAAA;AAAA,EAKQ,qBAA2B;AACjC,QAAI,KAAK,SAAS,kBAAkB,KAAM;AAC1C,SAAK,QAAQ,YAAY,oBAAoB;AAE7C,UAAM,gBAAgB,KAAK,IAAI,IAAI,cAAc,KAAK,SAAS,cAAc;AAC7E,qBAAiB,QAAQ,KAAK,kBAAkB,YAAY,EAAE,MAAM,cAAc,GAAG,KAAK,SAAS,OAAO;AAE1G,SAAK,QAAQ,WAAW,uBAAuB,EAAE,cAAc,CAAC;AAAA,EAClE;AACF;;;AHxKA,aAAc,eAAc,IAAI,iBAAkB,OAAmB;",
6
6
  "names": ["createLogger", "createLogger"]
7
7
  }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=main.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.test.d.ts","sourceRoot":"","sources":["../src/main.test.js"],"names":[],"mappings":""}
@@ -31,7 +31,7 @@ export type AlpineStoreGeneratorOptions<T extends DictionaryReq> = {
31
31
  * @see {@link https://alpinejs.dev/globals/alpine-store}
32
32
  *
33
33
  * @example
34
- * ```
34
+ * ```ts
35
35
  * const store = alpineStoreGenerator({
36
36
  * name: 'user',
37
37
  * defaultValue: {type: 'root'},
@@ -4,22 +4,29 @@ import { AlpineStore } from './store.js';
4
4
  * Type for the store's data to extends from them.
5
5
  */
6
6
  export type AlpineStoreWithBackupType = {
7
- data: DictionaryReq<any> | null;
7
+ data: DictionaryReq | null;
8
8
  };
9
9
  /**
10
10
  * AlpineStoreWithBackup Options.
11
11
  *
12
12
  * @typeParam T - The type of the store value.
13
- *
14
- * @param name - The name of the store.
15
- * @param version - The version of the store.
16
- * @param defaultValue - The default value of the store.
17
- * @param expireDuration - Optional. The duration after which the store expires.
18
13
  */
19
14
  export type AlpineStoreWithBackupOptions<T extends AlpineStoreWithBackupType> = {
15
+ /**
16
+ * The name of the store.
17
+ */
20
18
  name: string;
19
+ /**
20
+ * The version of the store.
21
+ */
21
22
  version: number;
23
+ /**
24
+ * The default value of the store.
25
+ */
22
26
  defaultValue: T;
27
+ /**
28
+ * Optional. The duration after which the store expires.
29
+ */
23
30
  expireDuration?: Duration;
24
31
  };
25
32
  /**
@@ -37,7 +44,7 @@ export declare class AlpineStoreWithBackup<T extends AlpineStoreWithBackupType>
37
44
  * @param config__ - Configuration object.
38
45
  *
39
46
  * @example
40
- * ```
47
+ * ```ts
41
48
  * import {AlpineStoreWithBackup} from '@nexim/alpine';
42
49
  *
43
50
  * const storeWithBackup = new AlpineStoreWithBackup({
@@ -1 +1 @@
1
- {"version":3,"file":"store-with-backup.d.ts","sourceRoot":"","sources":["../../src/store/store-with-backup.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,KAAK,QAAQ,EAAC,MAAM,wBAAwB,CAAC;AAEpE,OAAO,EAAC,WAAW,EAAC,MAAM,YAAY,CAAC;AAEvC;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG;IAEtC,IAAI,EAAE,aAAa,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;CACjC,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,MAAM,4BAA4B,CAAC,CAAC,SAAS,yBAAyB,IAAI;IAC9E,IAAI,EAAE,MAAM,C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kChF,OAAO,CAAC,QAAQ;IAjC5B;;OAEG;IACH,OAAO,CAAC,iBAAiB,CAGvB;IAEF;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;gBACiB,QAAQ,EAAE,4BAA4B,CAAC,CAAC,CAAC;IAU7D;;;;OAIG;IACH,IAAI,IAAI,IAAI;IAYZ;;OAEG;IACH,KAAK,IAAI,IAAI;IASb;;;OAGG;IACH,OAAO,CAAC,sBAAsB;IAe9B;;;;;;OAMG;IACH,OAAO,CAAC,MAAM;IAWd;;OAEG;IACH,OAAO,CAAC,kBAAkB;CAS3B"}
@@ -3,11 +3,15 @@ import { type AlwatrLogger } from '@alwatr/logger';
3
3
  * AlpineStore Options.
4
4
  *
5
5
  * @typeParam T - The type of the store value.
6
- * @param name - The name of the store.
7
- * @param defaultValue - The default value of the store.
8
6
  */
9
7
  export type AlpineStoreOptions<T extends DictionaryReq> = {
8
+ /**
9
+ * The name of the store.
10
+ */
10
11
  name: string;
12
+ /**
13
+ * The default value of the store.
14
+ */
11
15
  defaultValue: T;
12
16
  };
13
17
  /**
@@ -25,7 +29,7 @@ export declare class AlpineStore<T extends DictionaryReq> {
25
29
  * @param config - Configuration object.
26
30
  *
27
31
  * @example
28
- * ```
32
+ * ```ts
29
33
  * import {AlpineStore} from '@nexim/alpine';
30
34
  *
31
35
  * const {store} = new AlpineStore({
@@ -1 +1 @@
1
- {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/store/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,YAAY,EAAe,MAAM,gBAAgB,CAAC;AAI/D;;;;;;GAMG;AACH,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,aAAa,IAAI;IACxD,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,CAAC,CAAC;CACjB,CAAC;AAEF;;GAEG;AACH,qBAAa,WAAW,CAAC,CAAC,SAAS,aAAa;IAC9C;;OAEG;IACH,KAAK,EAAE,CAAC,CAAC;IAET,SAAS,CAAC,OAAO,EAAE,YAAY,CAAC;IAEhC;;;;;;;;;;;;;;;;;;OAkBG;gBACS,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC;CAM1C"}
1
+ {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/store/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAgB,MAAM,gBAAgB,CAAC;AAIjE;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,aAAa,IAAI;IACxD;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,YAAY,EAAE,CAAC,CAAC;CACjB,CAAC;AAEF;;GAEG;AACH,qBAAa,WAAW,CAAC,CAAC,SAAS,aAAa;IAC9C;;OAEG;IACH,KAAK,EAAE,CAAC,CAAC;IAET,SAAS,CAAC,OAAO,EAAE,YAAY,CAAC;IAEhC;;;;;;;;;;;;;;;;;;OAkBG;gBACS,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC;CAM1C"}
package/docs/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # @nexim/alpine
2
+
3
+ ## Classes
4
+
5
+ | Class | Description |
6
+ | --------------------------------------------------------- | --------------------------------------------------------------------- |
7
+ | [AlpineStore](classes/AlpineStore.md) | Provides a Alpine.js pure store implementation with logger. |
8
+ | [AlpineStoreWithBackup](classes/AlpineStoreWithBackup.md) | Provides a Alpine.js store implementation with backup and expiration. |
9
+
10
+ ## Type Aliases
11
+
12
+ | Type Alias | Description |
13
+ | ---------------------------------------------------------------------------- | ----------------------------------------------- |
14
+ | [AlpineStoreGeneratorOptions](type-aliases/AlpineStoreGeneratorOptions.md) | alpineStoreGenerator Options. |
15
+ | [AlpineStoreOptions](type-aliases/AlpineStoreOptions.md) | AlpineStore Options. |
16
+ | [AlpineStoreWithBackupOptions](type-aliases/AlpineStoreWithBackupOptions.md) | AlpineStoreWithBackup Options. |
17
+ | [AlpineStoreWithBackupType](type-aliases/AlpineStoreWithBackupType.md) | Type for the store's data to extends from them. |
18
+
19
+ ## Functions
20
+
21
+ | Function | Description |
22
+ | --------------------------------------------------------- | ------------------------------------------------ |
23
+ | [alpineStoreGenerator](functions/alpineStoreGenerator.md) | Generates an Alpine.js store with default value. |
@@ -0,0 +1,55 @@
1
+ [@nexim/alpine](../README.md) / AlpineStore
2
+
3
+ # Class: AlpineStore\<T\>
4
+
5
+ Provides a Alpine.js pure store implementation with logger.
6
+
7
+ ## Extended by
8
+
9
+ - [`AlpineStoreWithBackup`](AlpineStoreWithBackup.md)
10
+
11
+ ## Type Parameters
12
+
13
+ | Type Parameter |
14
+ | ----------------------------- |
15
+ | `T` _extends_ `DictionaryReq` |
16
+
17
+ ## Constructors
18
+
19
+ ### Constructor
20
+
21
+ > **new AlpineStore**\<`T`\>(`config`: [`AlpineStoreOptions`](../type-aliases/AlpineStoreOptions.md)\<`T`\>): `AlpineStore`\<`T`\>
22
+
23
+ Provides a Alpine.js pure store implementation with logger.
24
+
25
+ #### Parameters
26
+
27
+ | Parameter | Type | Description |
28
+ | --------- | -------------------------------------------------------------------- | --------------------- |
29
+ | `config` | [`AlpineStoreOptions`](../type-aliases/AlpineStoreOptions.md)\<`T`\> | Configuration object. |
30
+
31
+ #### Returns
32
+
33
+ `AlpineStore`\<`T`\>
34
+
35
+ #### Example
36
+
37
+ ```ts
38
+ import { AlpineStore } from '@nexim/alpine';
39
+
40
+ const { store } = new AlpineStore({
41
+ name: 'myStore',
42
+ defaultValue: { data: 'root' },
43
+ });
44
+ console.log(store.data); // Output: { data: 'root' }
45
+
46
+ store.data = 'user';
47
+ console.log(store.data); // Output: { data: 'user' }
48
+ ```
49
+
50
+ ## Properties
51
+
52
+ | Property | Modifier | Type | Description |
53
+ | ------------------------------ | ----------- | -------------- | ----------------- |
54
+ | <a id="logger_"></a> `logger_` | `protected` | `AlwatrLogger` | - |
55
+ | <a id="store"></a> `store` | `public` | `T` | The store's data. |
@@ -0,0 +1,91 @@
1
+ [@nexim/alpine](../README.md) / AlpineStoreWithBackup
2
+
3
+ # Class: AlpineStoreWithBackup\<T\>
4
+
5
+ Provides a Alpine.js store implementation with backup and expiration.
6
+
7
+ ## Extends
8
+
9
+ - [`AlpineStore`](AlpineStore.md)\<`T`\>
10
+
11
+ ## Type Parameters
12
+
13
+ | Type Parameter |
14
+ | ----------------------------------------------------------------------------------------- |
15
+ | `T` _extends_ [`AlpineStoreWithBackupType`](../type-aliases/AlpineStoreWithBackupType.md) |
16
+
17
+ ## Constructors
18
+
19
+ ### Constructor
20
+
21
+ > **new AlpineStoreWithBackup**\<`T`\>(`config__`: [`AlpineStoreWithBackupOptions`](../type-aliases/AlpineStoreWithBackupOptions.md)\<`T`\>): `AlpineStoreWithBackup`\<`T`\>
22
+
23
+ Provides a Alpine.js store implementation with backup and expiration.
24
+
25
+ #### Parameters
26
+
27
+ | Parameter | Type | Description |
28
+ | ---------- | ---------------------------------------------------------------------------------------- | --------------------- |
29
+ | `config__` | [`AlpineStoreWithBackupOptions`](../type-aliases/AlpineStoreWithBackupOptions.md)\<`T`\> | Configuration object. |
30
+
31
+ #### Returns
32
+
33
+ `AlpineStoreWithBackup`\<`T`\>
34
+
35
+ #### Example
36
+
37
+ ```ts
38
+ import { AlpineStoreWithBackup } from '@nexim/alpine';
39
+
40
+ const storeWithBackup = new AlpineStoreWithBackup({
41
+ name: 'myStoreWithBackup',
42
+ version: 1,
43
+ defaultValue: { data: 'root' },
44
+ expireDuration: '1d',
45
+ });
46
+
47
+ storeWithBackup.store.data = 'user';
48
+
49
+ storeWithBackup.save();
50
+ console.log(storeWithBackup.store.data); // Output: { data: 'user' }
51
+
52
+ storeWithBackup.clear();
53
+ console.log(storeWithBackup.store.data); // Output: { data: 'root' }
54
+ ```
55
+
56
+ #### Overrides
57
+
58
+ [`AlpineStore`](AlpineStore.md).[`constructor`](AlpineStore.md#constructor)
59
+
60
+ ## Properties
61
+
62
+ | Property | Modifier | Type | Description | Inherited from |
63
+ | ------------------------------ | ----------- | -------------- | ----------------- | ------------------------------------------------------------------- |
64
+ | <a id="logger_"></a> `logger_` | `protected` | `AlwatrLogger` | - | [`AlpineStore`](AlpineStore.md).[`logger_`](AlpineStore.md#logger_) |
65
+ | <a id="store"></a> `store` | `public` | `T` | The store's data. | [`AlpineStore`](AlpineStore.md).[`store`](AlpineStore.md#store) |
66
+
67
+ ## Methods
68
+
69
+ ### clear()
70
+
71
+ > **clear**(): `void`
72
+
73
+ Clears the stored data.
74
+
75
+ #### Returns
76
+
77
+ `void`
78
+
79
+ ---
80
+
81
+ ### save()
82
+
83
+ > **save**(): `void`
84
+
85
+ Saves the current data to local storage. If the data is null, it clears the stored data.
86
+
87
+ Also updates the expiration time.
88
+
89
+ #### Returns
90
+
91
+ `void`
@@ -0,0 +1,47 @@
1
+ [@nexim/alpine](../README.md) / alpineStoreGenerator
2
+
3
+ # Function: alpineStoreGenerator()
4
+
5
+ > **alpineStoreGenerator**\<`T`\>(`config`: [`AlpineStoreGeneratorOptions`](../type-aliases/AlpineStoreGeneratorOptions.md)\<`T`\>): `T`
6
+
7
+ Generates an Alpine.js store with default value.
8
+
9
+ ## Type Parameters
10
+
11
+ | Type Parameter | Description |
12
+ | -------------------------------------- | --------------------- |
13
+ | `T` _extends_ `DictionaryReq`\<`any`\> | The type of the data. |
14
+
15
+ ## Parameters
16
+
17
+ | Parameter | Type | Description |
18
+ | --------- | -------------------------------------------------------------------------------------- | --------------------------------------- |
19
+ | `config` | [`AlpineStoreGeneratorOptions`](../type-aliases/AlpineStoreGeneratorOptions.md)\<`T`\> | The configuration object for the store. |
20
+
21
+ ## Returns
22
+
23
+ `T`
24
+
25
+ - The initialized store instance.
26
+
27
+ ## Remarks
28
+
29
+ This function uses Alpine.js to create a reactive store with a default value.
30
+ The store is identified by a unique name and can be accessed and manipulated
31
+ throughout the application. Alpine.js stores provide a simple way to manage
32
+ data in your application, making it easy to keep your UI in sync with your data.
33
+
34
+ ## See
35
+
36
+ [https://alpinejs.dev/globals/alpine-store](https://alpinejs.dev/globals/alpine-store)
37
+
38
+ ## Example
39
+
40
+ ```ts
41
+ const store = alpineStoreGenerator({
42
+ name: 'user',
43
+ defaultValue: { type: 'root' },
44
+ });
45
+
46
+ console.log(store.type); // Output: root
47
+ ```
@@ -0,0 +1,29 @@
1
+ [@nexim/alpine](../README.md) / AlpineStoreGeneratorOptions
2
+
3
+ # Type Alias: AlpineStoreGeneratorOptions\<T\>
4
+
5
+ > **AlpineStoreGeneratorOptions**\<`T`\> = `object`
6
+
7
+ alpineStoreGenerator Options.
8
+
9
+ ## Type Parameters
10
+
11
+ | Type Parameter | Description |
12
+ | ----------------------------- | ------------------------------ |
13
+ | `T` _extends_ `DictionaryReq` | The type of the default value. |
14
+
15
+ ## Properties
16
+
17
+ ### defaultValue
18
+
19
+ > **defaultValue**: `T`
20
+
21
+ The default value of the store.
22
+
23
+ ---
24
+
25
+ ### name
26
+
27
+ > **name**: `string`
28
+
29
+ The name of the store.
@@ -0,0 +1,29 @@
1
+ [@nexim/alpine](../README.md) / AlpineStoreOptions
2
+
3
+ # Type Alias: AlpineStoreOptions\<T\>
4
+
5
+ > **AlpineStoreOptions**\<`T`\> = `object`
6
+
7
+ AlpineStore Options.
8
+
9
+ ## Type Parameters
10
+
11
+ | Type Parameter | Description |
12
+ | ----------------------------- | ---------------------------- |
13
+ | `T` _extends_ `DictionaryReq` | The type of the store value. |
14
+
15
+ ## Properties
16
+
17
+ ### defaultValue
18
+
19
+ > **defaultValue**: `T`
20
+
21
+ The default value of the store.
22
+
23
+ ---
24
+
25
+ ### name
26
+
27
+ > **name**: `string`
28
+
29
+ The name of the store.
@@ -0,0 +1,45 @@
1
+ [@nexim/alpine](../README.md) / AlpineStoreWithBackupOptions
2
+
3
+ # Type Alias: AlpineStoreWithBackupOptions\<T\>
4
+
5
+ > **AlpineStoreWithBackupOptions**\<`T`\> = `object`
6
+
7
+ AlpineStoreWithBackup Options.
8
+
9
+ ## Type Parameters
10
+
11
+ | Type Parameter | Description |
12
+ | ------------------------------------------------------------------------- | ---------------------------- |
13
+ | `T` _extends_ [`AlpineStoreWithBackupType`](AlpineStoreWithBackupType.md) | The type of the store value. |
14
+
15
+ ## Properties
16
+
17
+ ### defaultValue
18
+
19
+ > **defaultValue**: `T`
20
+
21
+ The default value of the store.
22
+
23
+ ---
24
+
25
+ ### expireDuration?
26
+
27
+ > `optional` **expireDuration**: `Duration`
28
+
29
+ Optional. The duration after which the store expires.
30
+
31
+ ---
32
+
33
+ ### name
34
+
35
+ > **name**: `string`
36
+
37
+ The name of the store.
38
+
39
+ ---
40
+
41
+ ### version
42
+
43
+ > **version**: `number`
44
+
45
+ The version of the store.
@@ -0,0 +1,13 @@
1
+ [@nexim/alpine](../README.md) / AlpineStoreWithBackupType
2
+
3
+ # Type Alias: AlpineStoreWithBackupType
4
+
5
+ > **AlpineStoreWithBackupType** = `object`
6
+
7
+ Type for the store's data to extends from them.
8
+
9
+ ## Properties
10
+
11
+ ### data
12
+
13
+ > **data**: `DictionaryReq` \| `null`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nexim/alpine",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "description": "Utility functions to enhance Alpine.js usage with backup support.",
5
5
  "keywords": [
6
6
  "alpinejs",
@@ -41,24 +41,28 @@
41
41
  ],
42
42
  "scripts": {
43
43
  "build": "wireit",
44
+ "doc": "wireit",
44
45
  "test": "wireit",
45
46
  "watch": "wireit"
46
47
  },
47
48
  "dependencies": {
48
- "@alwatr/local-storage": "^5.0.0",
49
- "@alwatr/logger": "^5.0.0",
50
- "@alwatr/package-tracer": "^5.0.0",
51
- "@alwatr/parse-duration": "^5.0.0",
52
- "alpinejs": "^3.14.8"
49
+ "@alwatr/local-storage": "^5.5.3",
50
+ "@alwatr/logger": "^5.5.3",
51
+ "@alwatr/package-tracer": "^5.5.3",
52
+ "@alwatr/parse-duration": "^5.5.4",
53
+ "alpinejs": "^3.14.9"
53
54
  },
54
55
  "devDependencies": {
55
- "@alwatr/nano-build": "^5.0.0",
56
- "@alwatr/type-helper": "^5.0.0",
57
- "@nexim/typescript-config": "^2.0.0",
56
+ "@alwatr/nano-build": "^5.5.3",
57
+ "@alwatr/type-helper": "^5.4.1",
58
+ "@nexim/typescript-config": "^2.0.1",
58
59
  "@types/alpinejs": "^3.13.11",
59
60
  "ava": "^6.2.0",
60
- "typescript": "^5.7.2",
61
- "wireit": "^0.14.9"
61
+ "typedoc": "^0.28.3",
62
+ "typedoc-plugin-markdown": "^4.6.2",
63
+ "typedoc-plugin-no-inherit": "^1.6.1",
64
+ "typescript": "^5.8.3",
65
+ "wireit": "^0.14.12"
62
66
  },
63
67
  "publishConfig": {
64
68
  "access": "public"
@@ -77,7 +81,7 @@
77
81
  ]
78
82
  },
79
83
  "build:es": {
80
- "command": "nano-build --preset=module",
84
+ "command": "yarn nano-build --preset=module",
81
85
  "files": [
82
86
  "src",
83
87
  "tsconfig.json"
@@ -103,9 +107,12 @@
103
107
  ]
104
108
  },
105
109
  "watch:es": {
106
- "command": "nano-build --preset=module -- --watch",
110
+ "command": "yarn nano-build --preset=module -- --watch",
107
111
  "service": true
112
+ },
113
+ "doc": {
114
+ "command": "typedoc"
108
115
  }
109
116
  },
110
- "gitHead": "67de35829cde30ef70d87361d7f104762f6ccfd5"
117
+ "gitHead": "f20da89af20ee0c17c96e1ea15c6dfd831717ee6"
111
118
  }
File without changes
File without changes