@nexim/alpine 0.0.1 → 1.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/CHANGELOG.md +14 -0
- package/README.md +40 -0
- package/dist/main.cjs +45 -13
- package/dist/main.cjs.map +3 -3
- package/dist/main.d.ts +1 -0
- package/dist/main.d.ts.map +1 -1
- package/dist/main.mjs +44 -13
- package/dist/main.mjs.map +4 -4
- package/dist/store/store-with-backup.d.ts +4 -7
- package/dist/store/store-with-backup.d.ts.map +1 -1
- package/dist/store/store.d.ts +41 -0
- package/dist/store/store.d.ts.map +1 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,20 @@
|
|
|
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.0.0](https://github.com/the-nexim/nanolib/compare/@nexim/alpine@1.0.0-alpha.0...@nexim/alpine@1.0.0) (2024-12-12)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* **alpine/store-with-backup:** load process ([2486cea](https://github.com/the-nexim/nanolib/commit/2486cea693e1101c6bd9fd47410a96cc6e225bd5)) by @njfamirm
|
|
11
|
+
* **alpine:** expiation data handling ([77eecce](https://github.com/the-nexim/nanolib/commit/77eecce118b11c2b00f9a90a5de2d74d11e67b2a)) by @njfamirm
|
|
12
|
+
* **alpine:** use generator in the store class ([c3b9768](https://github.com/the-nexim/nanolib/commit/c3b9768e9958f85ac244db4c3c5a0cb2e96c64fc)) by @njfamirm
|
|
13
|
+
|
|
14
|
+
## [1.0.0-alpha.0](https://github.com/the-nexim/nanolib/compare/@nexim/alpine@0.0.1...@nexim/alpine@1.0.0-alpha.0) (2024-12-10)
|
|
15
|
+
|
|
16
|
+
### Features
|
|
17
|
+
|
|
18
|
+
* **alpine:** add store class ([8f12bd1](https://github.com/the-nexim/nanolib/commit/8f12bd1edfee62e4e92c1bbef67584b4aea05533)) by @
|
|
19
|
+
|
|
6
20
|
## 0.0.1 (2024-12-10)
|
|
7
21
|
|
|
8
22
|
### Code Refactoring
|
package/README.md
CHANGED
|
@@ -40,6 +40,38 @@ const store = alpineStoreGenerator({
|
|
|
40
40
|
console.log(store.type); // Output: root
|
|
41
41
|
```
|
|
42
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
|
+
|
|
43
75
|
### AlpineStoreWithBackup
|
|
44
76
|
|
|
45
77
|
Extends `AlpineStore` to add backup and restore functionality with local storage support and expiration handling.
|
|
@@ -54,6 +86,10 @@ Creates an instance of `AlpineStoreWithBackup`.
|
|
|
54
86
|
- **defaultValue**: The default value of the store.
|
|
55
87
|
- **expireDuration**: Optional. The duration after which the store expires.
|
|
56
88
|
|
|
89
|
+
### Properties
|
|
90
|
+
|
|
91
|
+
- **store**: alpine store proxy.
|
|
92
|
+
|
|
57
93
|
#### Methods
|
|
58
94
|
|
|
59
95
|
- **save()**: Saves the current data to local storage. If the data is null, it clears the stored data. Also updates the expiration time.
|
|
@@ -79,3 +115,7 @@ console.log(storeWithBackup.store.data); // Output: { data: 'user' }
|
|
|
79
115
|
storeWithBackup.clear();
|
|
80
116
|
console.log(storeWithBackup.store.data); // Output: { data: 'root' }
|
|
81
117
|
```
|
|
118
|
+
|
|
119
|
+
### TODO
|
|
120
|
+
|
|
121
|
+
- 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
|
|
1
|
+
/* @nexim/alpine v1.0.0 */
|
|
2
2
|
"use strict";
|
|
3
3
|
var __create = Object.create;
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
@@ -31,6 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
// src/main.ts
|
|
32
32
|
var main_exports = {};
|
|
33
33
|
__export(main_exports, {
|
|
34
|
+
AlpineStore: () => AlpineStore,
|
|
34
35
|
AlpineStoreWithBackup: () => AlpineStoreWithBackup,
|
|
35
36
|
alpineStoreGenerator: () => alpineStoreGenerator
|
|
36
37
|
});
|
|
@@ -42,18 +43,44 @@ var import_logger = require("@alwatr/logger");
|
|
|
42
43
|
var import_alpinejs = __toESM(require("alpinejs"), 1);
|
|
43
44
|
var logger = (0, import_logger.createLogger)("@nexim/alpine");
|
|
44
45
|
function alpineStoreGenerator(config) {
|
|
45
|
-
logger.logMethodArgs?.("alpineStoreGenerator", config);
|
|
46
|
+
logger.logMethodArgs?.("alpineStoreGenerator", { config });
|
|
46
47
|
import_alpinejs.default.store(config.name, config.defaultValue);
|
|
47
48
|
const store = import_alpinejs.default.store(config.name);
|
|
48
49
|
return store;
|
|
49
50
|
}
|
|
50
51
|
|
|
52
|
+
// src/store/store.ts
|
|
53
|
+
var import_logger2 = require("@alwatr/logger");
|
|
54
|
+
var AlpineStore = class {
|
|
55
|
+
/**
|
|
56
|
+
* Provides a Alpine.js pure store implementation with logger.
|
|
57
|
+
*
|
|
58
|
+
* @param {AlpineStoreOptions} config - Configuration object.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* import {AlpineStore} from '@nexim/alpine';
|
|
62
|
+
*
|
|
63
|
+
* const {store} = new AlpineStore({
|
|
64
|
+
* name: 'myStore',
|
|
65
|
+
* defaultValue: {data: 'root'},
|
|
66
|
+
* });
|
|
67
|
+
* console.log(store.data); // Output: { data: 'root' }
|
|
68
|
+
*
|
|
69
|
+
* store.data = 'user';
|
|
70
|
+
* console.log(store.data); // Output: { data: 'user' }
|
|
71
|
+
*/
|
|
72
|
+
constructor(config) {
|
|
73
|
+
this.logger_ = (0, import_logger2.createLogger)(`${"@nexim/alpine"}:${config.name}`);
|
|
74
|
+
this.logger_.logMethodArgs?.("constructor", config);
|
|
75
|
+
this.store = alpineStoreGenerator(config);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
51
79
|
// src/store/store-with-backup.ts
|
|
52
80
|
var import_local_storage = require("@alwatr/local-storage");
|
|
53
|
-
var import_logger2 = require("@alwatr/logger");
|
|
54
81
|
var import_parse_duration = require("@alwatr/parse-duration");
|
|
55
82
|
var schemaVersion = 1;
|
|
56
|
-
var AlpineStoreWithBackup = class {
|
|
83
|
+
var AlpineStoreWithBackup = class extends AlpineStore {
|
|
57
84
|
/**
|
|
58
85
|
* Provides a Alpine.js store implementation with backup and expiration.
|
|
59
86
|
*
|
|
@@ -78,6 +105,7 @@ var AlpineStoreWithBackup = class {
|
|
|
78
105
|
* console.log(storeWithBackup.store.data); // Output: { data: 'root' }
|
|
79
106
|
*/
|
|
80
107
|
constructor(config__) {
|
|
108
|
+
super(config__);
|
|
81
109
|
this.config__ = config__;
|
|
82
110
|
/**
|
|
83
111
|
* Keys for storing data and expire time in local storage with version.
|
|
@@ -86,10 +114,7 @@ var AlpineStoreWithBackup = class {
|
|
|
86
114
|
data: `[${"@nexim/alpine"}:data:sv${schemaVersion}]:${this.config__.name}`,
|
|
87
115
|
expireTime: `[${"@nexim/alpine"}:expire-time:sv${schemaVersion}]:${this.config__.name}`
|
|
88
116
|
};
|
|
89
|
-
this.
|
|
90
|
-
this.logger_.logMethodArgs?.("constructor", config__);
|
|
91
|
-
this.store = config__.defaultValue;
|
|
92
|
-
if (this.config__.expireDuration !== null) {
|
|
117
|
+
if (this.config__.expireDuration != null) {
|
|
93
118
|
this.handleDataExpiration__();
|
|
94
119
|
}
|
|
95
120
|
this.load__();
|
|
@@ -125,10 +150,10 @@ var AlpineStoreWithBackup = class {
|
|
|
125
150
|
this.logger_.logMethod?.("handleDataExpiration__");
|
|
126
151
|
const expireDuration = import_local_storage.localJsonStorage.getItem(
|
|
127
152
|
this.localStorageKey__.expireTime,
|
|
128
|
-
{ time:
|
|
153
|
+
{ time: -1 },
|
|
129
154
|
this.config__.version
|
|
130
155
|
).time;
|
|
131
|
-
if (expireDuration < Date.now()) {
|
|
156
|
+
if (expireDuration !== -1 && expireDuration < Date.now()) {
|
|
132
157
|
this.clear();
|
|
133
158
|
}
|
|
134
159
|
}
|
|
@@ -136,11 +161,17 @@ var AlpineStoreWithBackup = class {
|
|
|
136
161
|
* Loads data from local storage and updates the store's data.
|
|
137
162
|
*
|
|
138
163
|
* When data is not found or invalid in local storage, it uses the default value.
|
|
164
|
+
*
|
|
165
|
+
* FIXME: remove `NonNullable` from <T['data']>, after local storage new version.
|
|
139
166
|
*/
|
|
140
167
|
load__() {
|
|
141
168
|
this.logger_.logMethod?.("load__");
|
|
142
|
-
const newData = import_local_storage.localJsonStorage.getItem(
|
|
143
|
-
|
|
169
|
+
const newData = import_local_storage.localJsonStorage.getItem(
|
|
170
|
+
this.localStorageKey__.data,
|
|
171
|
+
this.config__.defaultValue.data,
|
|
172
|
+
this.config__.version
|
|
173
|
+
);
|
|
174
|
+
this.store.data = newData;
|
|
144
175
|
}
|
|
145
176
|
/**
|
|
146
177
|
* Updates the expiration time in local storage to the current time plus the configured expiration duration.
|
|
@@ -155,9 +186,10 @@ var AlpineStoreWithBackup = class {
|
|
|
155
186
|
};
|
|
156
187
|
|
|
157
188
|
// src/main.ts
|
|
158
|
-
__dev_mode__: import_package_tracer.packageTracer.add("@nexim/alpine", "0.0
|
|
189
|
+
__dev_mode__: import_package_tracer.packageTracer.add("@nexim/alpine", "1.0.0");
|
|
159
190
|
// Annotate the CommonJS export names for ESM import in node:
|
|
160
191
|
0 && (module.exports = {
|
|
192
|
+
AlpineStore,
|
|
161
193
|
AlpineStoreWithBackup,
|
|
162
194
|
alpineStoreGenerator
|
|
163
195
|
});
|
package/dist/main.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/main.ts", "../src/store/store-generator.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-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 * @template T - The type of the default value.\n * @property {string} name - The name of the store.\n * @property {T} defaultValue - The default value of the store.\n */\nexport type AlpineStoreGeneratorOptions<T extends DictionaryReq> = {\n name: string;\n defaultValue: T;\n};\n\n/**\n * Generates an Alpine.js store with default value.\n *\n * @template T - The type of the data.\n * @param {AlpineStoreGeneratorOptions} config - The configuration object for the store.\n * @returns {T} - The initialized store instance.\n *\n * @example\n * const store = alpineStoreGenerator({\n * name: 'user',\n * defaultValue: {type: 'root'},\n * });\n *\n * console.log(store.type); // Output: root\n *\n * @description\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 https://alpinejs.dev/globals/alpine-store\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 {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAA4B;;;ACA5B,oBAA2B;AAC3B,sBAAmB;AAEnB,IAAM,aAAS,4BAAa,eAAgB;AAqCrC,SAAS,qBAA8C,QAA2C;AACvG,SAAO,gBAAgB,wBAAwB,
|
|
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 * @template T - The type of the default value.\n * @property {string} name - The name of the store.\n * @property {T} defaultValue - The default value of the store.\n */\nexport type AlpineStoreGeneratorOptions<T extends DictionaryReq> = {\n name: string;\n defaultValue: T;\n};\n\n/**\n * Generates an Alpine.js store with default value.\n *\n * @template T - The type of the data.\n * @param {AlpineStoreGeneratorOptions} config - The configuration object for the store.\n * @returns {T} - The initialized store instance.\n *\n * @example\n * const store = alpineStoreGenerator({\n * name: 'user',\n * defaultValue: {type: 'root'},\n * });\n *\n * console.log(store.type); // Output: root\n *\n * @description\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 https://alpinejs.dev/globals/alpine-store\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 * @template T - The type of the store value.\n * @param {string} name - The name of the store.\n * @param {T} 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 {AlpineStoreOptions} config - Configuration object.\n *\n * @example\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 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 * @template T - The type of the store value.\n * @param {string} name - The name of the store.\n * @param {number} version - The version of the store.\n * @param {T} defaultValue - The default value of the store.\n * @param {Duration} [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 {AlpineStoreWithBackupOptions} config__ - Configuration object.\n *\n * @example\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 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;AAqCrC,SAAS,qBAA8C,QAA2C;AACvG,SAAO,gBAAgB,wBAAwB,EAAC,OAAM,CAAC;AAEvD,kBAAAA,QAAO,MAAM,OAAO,MAAM,OAAO,YAAY;AAG7C,Q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logger"]
|
|
7
7
|
}
|
package/dist/main.d.ts
CHANGED
package/dist/main.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAIA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC"}
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAIA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,kBAAkB,CAAC;AACjC,cAAc,8BAA8B,CAAC"}
|
package/dist/main.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* @nexim/alpine
|
|
1
|
+
/* @nexim/alpine v1.0.0 */
|
|
2
2
|
|
|
3
3
|
// src/main.ts
|
|
4
4
|
import { packageTracer } from "@alwatr/package-tracer";
|
|
@@ -8,18 +8,44 @@ import { createLogger } from "@alwatr/logger";
|
|
|
8
8
|
import alpine from "alpinejs";
|
|
9
9
|
var logger = createLogger("@nexim/alpine");
|
|
10
10
|
function alpineStoreGenerator(config) {
|
|
11
|
-
logger.logMethodArgs?.("alpineStoreGenerator", config);
|
|
11
|
+
logger.logMethodArgs?.("alpineStoreGenerator", { config });
|
|
12
12
|
alpine.store(config.name, config.defaultValue);
|
|
13
13
|
const store = alpine.store(config.name);
|
|
14
14
|
return store;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
// src/store/store.ts
|
|
18
|
+
import { createLogger as createLogger2 } from "@alwatr/logger";
|
|
19
|
+
var AlpineStore = class {
|
|
20
|
+
/**
|
|
21
|
+
* Provides a Alpine.js pure store implementation with logger.
|
|
22
|
+
*
|
|
23
|
+
* @param {AlpineStoreOptions} config - Configuration object.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* import {AlpineStore} from '@nexim/alpine';
|
|
27
|
+
*
|
|
28
|
+
* const {store} = new AlpineStore({
|
|
29
|
+
* name: 'myStore',
|
|
30
|
+
* defaultValue: {data: 'root'},
|
|
31
|
+
* });
|
|
32
|
+
* console.log(store.data); // Output: { data: 'root' }
|
|
33
|
+
*
|
|
34
|
+
* store.data = 'user';
|
|
35
|
+
* console.log(store.data); // Output: { data: 'user' }
|
|
36
|
+
*/
|
|
37
|
+
constructor(config) {
|
|
38
|
+
this.logger_ = createLogger2(`${"@nexim/alpine"}:${config.name}`);
|
|
39
|
+
this.logger_.logMethodArgs?.("constructor", config);
|
|
40
|
+
this.store = alpineStoreGenerator(config);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
17
44
|
// src/store/store-with-backup.ts
|
|
18
45
|
import { localJsonStorage } from "@alwatr/local-storage";
|
|
19
|
-
import { createLogger as createLogger2 } from "@alwatr/logger";
|
|
20
46
|
import { parseDuration } from "@alwatr/parse-duration";
|
|
21
47
|
var schemaVersion = 1;
|
|
22
|
-
var AlpineStoreWithBackup = class {
|
|
48
|
+
var AlpineStoreWithBackup = class extends AlpineStore {
|
|
23
49
|
/**
|
|
24
50
|
* Provides a Alpine.js store implementation with backup and expiration.
|
|
25
51
|
*
|
|
@@ -44,6 +70,7 @@ var AlpineStoreWithBackup = class {
|
|
|
44
70
|
* console.log(storeWithBackup.store.data); // Output: { data: 'root' }
|
|
45
71
|
*/
|
|
46
72
|
constructor(config__) {
|
|
73
|
+
super(config__);
|
|
47
74
|
this.config__ = config__;
|
|
48
75
|
/**
|
|
49
76
|
* Keys for storing data and expire time in local storage with version.
|
|
@@ -52,10 +79,7 @@ var AlpineStoreWithBackup = class {
|
|
|
52
79
|
data: `[${"@nexim/alpine"}:data:sv${schemaVersion}]:${this.config__.name}`,
|
|
53
80
|
expireTime: `[${"@nexim/alpine"}:expire-time:sv${schemaVersion}]:${this.config__.name}`
|
|
54
81
|
};
|
|
55
|
-
this.
|
|
56
|
-
this.logger_.logMethodArgs?.("constructor", config__);
|
|
57
|
-
this.store = config__.defaultValue;
|
|
58
|
-
if (this.config__.expireDuration !== null) {
|
|
82
|
+
if (this.config__.expireDuration != null) {
|
|
59
83
|
this.handleDataExpiration__();
|
|
60
84
|
}
|
|
61
85
|
this.load__();
|
|
@@ -91,10 +115,10 @@ var AlpineStoreWithBackup = class {
|
|
|
91
115
|
this.logger_.logMethod?.("handleDataExpiration__");
|
|
92
116
|
const expireDuration = localJsonStorage.getItem(
|
|
93
117
|
this.localStorageKey__.expireTime,
|
|
94
|
-
{ time:
|
|
118
|
+
{ time: -1 },
|
|
95
119
|
this.config__.version
|
|
96
120
|
).time;
|
|
97
|
-
if (expireDuration < Date.now()) {
|
|
121
|
+
if (expireDuration !== -1 && expireDuration < Date.now()) {
|
|
98
122
|
this.clear();
|
|
99
123
|
}
|
|
100
124
|
}
|
|
@@ -102,11 +126,17 @@ var AlpineStoreWithBackup = class {
|
|
|
102
126
|
* Loads data from local storage and updates the store's data.
|
|
103
127
|
*
|
|
104
128
|
* When data is not found or invalid in local storage, it uses the default value.
|
|
129
|
+
*
|
|
130
|
+
* FIXME: remove `NonNullable` from <T['data']>, after local storage new version.
|
|
105
131
|
*/
|
|
106
132
|
load__() {
|
|
107
133
|
this.logger_.logMethod?.("load__");
|
|
108
|
-
const newData = localJsonStorage.getItem(
|
|
109
|
-
|
|
134
|
+
const newData = localJsonStorage.getItem(
|
|
135
|
+
this.localStorageKey__.data,
|
|
136
|
+
this.config__.defaultValue.data,
|
|
137
|
+
this.config__.version
|
|
138
|
+
);
|
|
139
|
+
this.store.data = newData;
|
|
110
140
|
}
|
|
111
141
|
/**
|
|
112
142
|
* Updates the expiration time in local storage to the current time plus the configured expiration duration.
|
|
@@ -121,8 +151,9 @@ var AlpineStoreWithBackup = class {
|
|
|
121
151
|
};
|
|
122
152
|
|
|
123
153
|
// src/main.ts
|
|
124
|
-
__dev_mode__: packageTracer.add("@nexim/alpine", "0.0
|
|
154
|
+
__dev_mode__: packageTracer.add("@nexim/alpine", "1.0.0");
|
|
125
155
|
export {
|
|
156
|
+
AlpineStore,
|
|
126
157
|
AlpineStoreWithBackup,
|
|
127
158
|
alpineStoreGenerator
|
|
128
159
|
};
|
package/dist/main.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/main.ts", "../src/store/store-generator.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-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 * @template T - The type of the default value.\n * @property {string} name - The name of the store.\n * @property {T} defaultValue - The default value of the store.\n */\nexport type AlpineStoreGeneratorOptions<T extends DictionaryReq> = {\n name: string;\n defaultValue: T;\n};\n\n/**\n * Generates an Alpine.js store with default value.\n *\n * @template T - The type of the data.\n * @param {AlpineStoreGeneratorOptions} config - The configuration object for the store.\n * @returns {T} - The initialized store instance.\n *\n * @example\n * const store = alpineStoreGenerator({\n * name: 'user',\n * defaultValue: {type: 'root'},\n * });\n *\n * console.log(store.type); // Output: root\n *\n * @description\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 https://alpinejs.dev/globals/alpine-store\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 {
|
|
5
|
-
"mappings": ";;;AAAA,SAAQ,qBAAoB;;;ACA5B,SAAQ,oBAAmB;AAC3B,OAAO,YAAY;AAEnB,IAAM,SAAS,aAAa,eAAgB;AAqCrC,SAAS,qBAA8C,QAA2C;AACvG,SAAO,gBAAgB,wBAAwB,
|
|
6
|
-
"names": ["createLogger"]
|
|
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 * @template T - The type of the default value.\n * @property {string} name - The name of the store.\n * @property {T} defaultValue - The default value of the store.\n */\nexport type AlpineStoreGeneratorOptions<T extends DictionaryReq> = {\n name: string;\n defaultValue: T;\n};\n\n/**\n * Generates an Alpine.js store with default value.\n *\n * @template T - The type of the data.\n * @param {AlpineStoreGeneratorOptions} config - The configuration object for the store.\n * @returns {T} - The initialized store instance.\n *\n * @example\n * const store = alpineStoreGenerator({\n * name: 'user',\n * defaultValue: {type: 'root'},\n * });\n *\n * console.log(store.type); // Output: root\n *\n * @description\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 https://alpinejs.dev/globals/alpine-store\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 * @template T - The type of the store value.\n * @param {string} name - The name of the store.\n * @param {T} 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 {AlpineStoreOptions} config - Configuration object.\n *\n * @example\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 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 * @template T - The type of the store value.\n * @param {string} name - The name of the store.\n * @param {number} version - The version of the store.\n * @param {T} defaultValue - The default value of the store.\n * @param {Duration} [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 {AlpineStoreWithBackupOptions} config__ - Configuration object.\n *\n * @example\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 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,SAAQ,qBAAoB;;;ACA5B,SAAQ,oBAAmB;AAC3B,OAAO,YAAY;AAEnB,IAAM,SAAS,aAAa,eAAgB;AAqCrC,SAAS,qBAA8C,QAA2C;AACvG,SAAO,gBAAgB,wBAAwB,EAAC,OAAM,CAAC;AAEvD,SAAO,MAAM,OAAO,MAAM,OAAO,YAAY;AAG7C,QAAM,QAAQ,OAAO,MAAM,OAAO,IAAI;AACtC,SAAO;AACT;;;AChDA,SAA2B,gBAAAA,qBAAmB;AAmBvC,IAAM,cAAN,MAA2C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAyBhD,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;;;AClDA,SAAQ,wBAAuB;AAC/B,SAAQ,qBAAmC;AAiC3C,IAAM,gBAAg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ACT,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,EAAC,MAAM,cAAa,GAAG,KAAK,SAAS,OAAO;AAExG,SAAK,QAAQ,WAAW,uBAAuB,EAAC,cAAa,CAAC;AAAA,EAChE;AACF;;;AH7JA,aAAc,eAAc,IAAI,iBAAkB,OAAmB;",
|
|
6
|
+
"names": ["createLogger", "createLogger"]
|
|
7
7
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type AlwatrLogger } from '@alwatr/logger';
|
|
2
1
|
import { type Duration } from '@alwatr/parse-duration';
|
|
2
|
+
import { AlpineStore } from './store.js';
|
|
3
3
|
/**
|
|
4
4
|
* Type for the store's data to extends from them.
|
|
5
5
|
*/
|
|
@@ -24,13 +24,8 @@ export type AlpineStoreWithBackupOptions<T extends AlpineStoreWithBackupType> =
|
|
|
24
24
|
/**
|
|
25
25
|
* Provides a Alpine.js store implementation with backup and expiration.
|
|
26
26
|
*/
|
|
27
|
-
export declare class AlpineStoreWithBackup<T extends AlpineStoreWithBackupType> {
|
|
27
|
+
export declare class AlpineStoreWithBackup<T extends AlpineStoreWithBackupType> extends AlpineStore<T> {
|
|
28
28
|
private config__;
|
|
29
|
-
/**
|
|
30
|
-
* The store's data.
|
|
31
|
-
*/
|
|
32
|
-
store: T;
|
|
33
|
-
protected logger_: AlwatrLogger;
|
|
34
29
|
/**
|
|
35
30
|
* Keys for storing data and expire time in local storage with version.
|
|
36
31
|
*/
|
|
@@ -78,6 +73,8 @@ export declare class AlpineStoreWithBackup<T extends AlpineStoreWithBackupType>
|
|
|
78
73
|
* Loads data from local storage and updates the store's data.
|
|
79
74
|
*
|
|
80
75
|
* When data is not found or invalid in local storage, it uses the default value.
|
|
76
|
+
*
|
|
77
|
+
* FIXME: remove `NonNullable` from <T['data']>, after local storage new version.
|
|
81
78
|
*/
|
|
82
79
|
private load__;
|
|
83
80
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store-with-backup.d.ts","sourceRoot":"","sources":["../../src/store/store-with-backup.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
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;;;;;;;;GAQG;AACH,MAAM,MAAM,4BAA4B,CAAC,CAAC,SAAS,yBAAyB,IAAI;IAC9E,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,CAAC,CAAC;IAChB,cAAc,CAAC,EAAE,QAAQ,CAAC;CAC3B,CAAC;AASF;;GAEG;AACH,qBAAa,qBAAqB,CAAC,CAAC,SAAS,yBAAyB,CAAE,SAAQ,WAAW,CAAC,CAAC,CAAC;IAgChF,OAAO,CAAC,QAAQ;IA/B5B;;OAEG;IACH,OAAO,CAAC,iBAAiB,CAGvB;IAEF;;;;;;;;;;;;;;;;;;;;;;OAsBG;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"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type AlwatrLogger } from '@alwatr/logger';
|
|
2
|
+
/**
|
|
3
|
+
* AlpineStore Options.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The type of the store value.
|
|
6
|
+
* @param {string} name - The name of the store.
|
|
7
|
+
* @param {T} defaultValue - The default value of the store.
|
|
8
|
+
*/
|
|
9
|
+
export type AlpineStoreOptions<T extends DictionaryReq> = {
|
|
10
|
+
name: string;
|
|
11
|
+
defaultValue: T;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Provides a Alpine.js pure store implementation with logger.
|
|
15
|
+
*/
|
|
16
|
+
export declare class AlpineStore<T extends DictionaryReq> {
|
|
17
|
+
/**
|
|
18
|
+
* The store's data.
|
|
19
|
+
*/
|
|
20
|
+
store: T;
|
|
21
|
+
protected logger_: AlwatrLogger;
|
|
22
|
+
/**
|
|
23
|
+
* Provides a Alpine.js pure store implementation with logger.
|
|
24
|
+
*
|
|
25
|
+
* @param {AlpineStoreOptions} config - Configuration object.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* import {AlpineStore} from '@nexim/alpine';
|
|
29
|
+
*
|
|
30
|
+
* const {store} = new AlpineStore({
|
|
31
|
+
* name: 'myStore',
|
|
32
|
+
* defaultValue: {data: 'root'},
|
|
33
|
+
* });
|
|
34
|
+
* console.log(store.data); // Output: { data: 'root' }
|
|
35
|
+
*
|
|
36
|
+
* store.data = 'user';
|
|
37
|
+
* console.log(store.data); // Output: { data: 'user' }
|
|
38
|
+
*/
|
|
39
|
+
constructor(config: AlpineStoreOptions<T>);
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=store.d.ts.map
|
|
@@ -0,0 +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;;;;;;;;;;;;;;;;OAgBG;gBACS,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC;CAM1C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nexim/alpine",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Utility functions to enhance Alpine.js usage with backup support.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"alpinejs",
|
|
@@ -74,5 +74,5 @@
|
|
|
74
74
|
"publishConfig": {
|
|
75
75
|
"access": "public"
|
|
76
76
|
},
|
|
77
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "55a344189ea4df8dba3fe6bc939dd877a2862154"
|
|
78
78
|
}
|