memorio 2.5.3 → 2.6.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.
@@ -0,0 +1,108 @@
1
+ # Code of Conduct - memorio
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to make participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, sex characteristics, gender identity and expression,
9
+ level of experience, education, socio-economic status, nationality, personal
10
+ appearance, race, religion, or sexual identity and orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to a positive environment for our
15
+ community include:
16
+
17
+ * Demonstrating empathy and kindness toward other people
18
+ * Being respectful of differing opinions, viewpoints, and experiences
19
+ * Giving and gracefully accepting constructive feedback
20
+ * Accepting responsibility and apologizing to those affected by our mistakes,
21
+ and learning from the experience
22
+ * Focusing on what is best not just for us as individuals, but for the
23
+ overall community
24
+
25
+ Examples of unacceptable behavior include:
26
+
27
+ * The use of sexualized language or imagery, and sexual attention or advances
28
+ * Trolling, insulting or derogatory comments, and personal or political attacks
29
+ * Public or private harassment
30
+ * Publishing others' private information, such as a physical or email
31
+ address, without their explicit permission
32
+ * Other conduct which could reasonably be considered inappropriate in a
33
+ professional setting
34
+
35
+ ## Our Responsibilities
36
+
37
+ Project maintainers are responsible for clarifying and enforcing our standards of
38
+ acceptable behavior and will take appropriate and fair corrective action in
39
+ response to any behavior that they deem inappropriate,
40
+ threatening, offensive, or harmful.
41
+
42
+ Project maintainers have the right and responsibility to remove, edit, or reject
43
+ comments, commits, code, wiki edits, issues, and other contributions that are
44
+ not aligned to this Code of Conduct, and will
45
+ communicate reasons for moderation decisions when appropriate.
46
+
47
+ ## Scope
48
+
49
+ This Code of Conduct applies within all community spaces, and also applies when
50
+ an individual is officially representing the community in public spaces.
51
+ Examples of representing our community include using an official e-mail address,
52
+ posting via an official social media account, or acting as an appointed
53
+ representative at an online or offline event.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported to the community leaders responsible for enforcement at <dariopassariello@gmail.com>.
59
+ All complaints will be reviewed and investigated promptly and fairly.
60
+
61
+ All community leaders are obligated to respect the privacy and security of the
62
+ reporter of any incident.
63
+
64
+ ## Enforcement Guidelines
65
+
66
+ Community leaders will follow these Community Impact Guidelines in determining
67
+ the consequences for any action they deem in violation of this Code of Conduct:
68
+
69
+ ### 1. Correction
70
+
71
+ **Community Impact**: Use of inappropriate language or other behavior deemed
72
+ unprofessional or unwelcome in the community.
73
+
74
+ **Consequence**: A private, written warning from community leaders, providing
75
+ clarity around the nature of the violation and an explanation of why the
76
+ behavior was inappropriate. A public apology may be requested.
77
+
78
+ ### 2. Warning
79
+
80
+ **Community Impact**: A violation through a single incident or series
81
+ of actions.
82
+
83
+ **Consequence**: A warning with consequences for continued behavior. No
84
+ interaction with the people involved, including unsolicited interaction with
85
+ those enforcing the Code of Conduct, for a specified period of time. This
86
+ includes avoiding interactions in community spaces as well as external channels
87
+ like social media. Violating these terms may lead to a temporary or
88
+ permanent ban.
89
+
90
+ ### 3. Temporary Ban
91
+
92
+ **Community Impact**: A serious violation of community standards, including
93
+ sustained inappropriate behavior.
94
+
95
+ **Consequence**: A temporary ban from any sort of interaction or public
96
+ communication with the community for a specified period of time. No public or
97
+ private interaction with the people involved, including unsolicited interaction
98
+ with those enforcing the Code of Conduct, is allowed during this period.
99
+ Violating these terms may lead to a permanent ban.
100
+
101
+ ### 4. Permanent Ban
102
+
103
+ **Community Impact**: Demonstrating a pattern of violation of community
104
+ standards, including sustained inappropriate behavior, harassment of an
105
+ individual, or aggression toward or disparagement of classes of individuals.
106
+
107
+ **Consequence**: A permanent ban from any sort of public interaction within
108
+ the community.
@@ -0,0 +1,108 @@
1
+ # Contributing
2
+
3
+ First off, thanks for taking the time to contribute!
4
+
5
+ All types of contributions are encouraged and valued. See the [Table of Contents](contributing.md#table-of-contents) for different ways to help and details about how this project handles them. Please make sure to read the relevant section before making your contribution. It will make it a lot easier for us maintainers and smooth out the experience for all involved. The community looks forward to your contributions.
6
+
7
+ > And if you like the project, but just don't have time to contribute, that's fine. There are other easy ways to support the project and show your appreciation, which we would also be very happy about:
8
+ >
9
+ > * Star the project
10
+ > * Tweet about it
11
+ > * Refer this project in your project's readme
12
+ > * Mention the project at local meetups and tell your friends/colleagues
13
+
14
+ ## Table of Contents
15
+
16
+ * [Code of Conduct](contributing.md#code-of-conduct)
17
+ * [I Have a Question](contributing.md#i-have-a-question)
18
+ * [I Want To Contribute](contributing.md#i-want-to-contribute)
19
+ * [Reporting Bugs](contributing.md#reporting-bugs)
20
+ * [Suggesting Enhancements](contributing.md#suggesting-enhancements)
21
+ * [Your First Code Contribution](contributing.md#your-first-code-contribution)
22
+ * [Improving The Documentation](contributing.md#improving-the-documentation)
23
+ * [Style guides](contributing.md#styleguides)
24
+ * [Commit Messages](contributing.md#commit-messages)
25
+ * [Join The Project Team](contributing.md#join-the-project-team)
26
+
27
+ ## Code of Conduct
28
+
29
+ This project and everyone participating in it is governed by the [memorio Code of Conduct](https://github.com/a51-dev/a51.memorio/blob/CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code. Please report unacceptable behavior to [dariopassariello@gmail.com](mailto:dariopassariello@gmail.com).
30
+
31
+ ## I Have a Question
32
+
33
+ > If you want to ask a question, we assume that you have read the available [Documentation](https://a51.gitbook.io/memorio/).
34
+
35
+ Before you ask a question, it is best to search for existing [Issues](https://github.com/a51-dev/a51.memorio/issues) that might help you. In case you have found a suitable issue and still need clarification, you can write your question in this issue. It is also advisable to search the internet for answers first.
36
+
37
+ If you then still feel the need to ask a question and need clarification, we recommend the following:
38
+
39
+ * Open an [Issue](https://github.com/a51-dev/a51.memorio/issues/new).
40
+ * Provide as much context as you can about what you're running into.
41
+ * Provide project and platform versions (nodejs, npm, etc), depending on what seems relevant.
42
+
43
+ We will then take care of the issue as soon as possible.
44
+
45
+ ## I Want To Contribute
46
+
47
+ > ### Legal Notice
48
+ >
49
+ > When contributing to this project, you must agree that you have authored 100% of the content, that you have the necessary rights to the content and that the content you contribute may be provided under the project license.
50
+
51
+ ### Reporting Bugs
52
+
53
+ #### Before Submitting a Bug Report
54
+
55
+ A good bug report shouldn't leave others needing to chase you up for more information. Therefore, we ask you to investigate carefully, collect information and describe the issue in detail in your report. Please complete the following steps in advance to help us fix any potential bug as fast as possible.
56
+
57
+ * Make sure that you are using the latest version.
58
+ * Determine if your bug is really a bug and not an error on your side e.g. using incompatible environment components/versions (Make sure that you have read the [documentation](https://a51.gitbook.io/memorio/). If you are looking for support, you might want to check [this section](contributing.md#i-have-a-question)).
59
+ * To see if other users have experienced (and potentially already solved) the same issue you are having, check if there is not already a bug report existing for your bug or error in the [bug tracker](https://github.com/a51-dev/a51.memorio/issues?q=label%3Abug).
60
+ * Also make sure to search the internet (including Stack Overflow) to see if users outside of the GitHub community have discussed the issue.
61
+ * Collect information about the bug:
62
+ * Stack trace (Traceback)
63
+ * OS, Platform and Version (Windows, Linux, macOS, x86, ARM)
64
+ * Version of the interpreter, compiler, SDK, runtime environment, package manager, depending on what seems relevant.
65
+ * Possibly your input and the output
66
+ * Can you reliably reproduce the issue? And can you also reproduce it with older versions?
67
+
68
+ #### How Do I Submit a Good Bug Report?
69
+
70
+ > You must never report security related issues, vulnerabilities or bugs including sensitive information to the issue tracker, or elsewhere in public. Instead sensitive bugs must be sent by email to [dariopassariello@gmail.com](mailto:dariopassariello@gmail.com).
71
+
72
+ We use GitHub issues to track bugs and errors. If you run into an issue with the project:
73
+
74
+ * Open an [Issue](https://github.com/a51-dev/a51.memorio/issues/new). (Since we can't be sure at this point whether it is a bug or not, we ask you not to talk about a bug yet and not to label the issue.)
75
+ * Explain the behavior you would expect and the actual behavior.
76
+ * Please provide as much context as possible and describe the _reproduction steps_ that someone else can follow to recreate the issue on their own. This usually includes your code. For good bug reports you should isolate the problem and create a reduced test case.
77
+ * Provide the information you collected in the previous section.
78
+
79
+ Once it's filed:
80
+
81
+ * The project team will label the issue accordingly.
82
+ * A team member will try to reproduce the issue with your provided steps. If there are no reproduction steps or no obvious way to reproduce the issue, the team will ask you for those steps and mark the issue as `needs-repro`. Bugs with the `needs-repro` tag will not be addressed until they are reproduced.
83
+ * If the team is able to reproduce the issue, it will be marked `needs-fix`, as well as possibly other tags (such as `critical`), and the issue will be left to be [implemented by someone](contributing.md#your-first-code-contribution).
84
+
85
+ ### Suggesting Enhancements
86
+
87
+ This section guides you through submitting an enhancement suggestion for memorio, **including completely new features and minor improvements to existing functionality**. Following these guidelines will help maintainers and the community to understand your suggestion and find related suggestions.
88
+
89
+ #### Before Submitting an Enhancement
90
+
91
+ * Make sure that you are using the latest version.
92
+ * Read the [documentation](https://a51.gitbook.io/memorio/) carefully and find out if the functionality is already covered, maybe by an individual configuration.
93
+ * Perform a [search](https://github.com/a51-dev/a51.memorio/issues) to see if the enhancement has already been suggested. If it has, add a comment to the existing issue instead of opening a new one.
94
+ * Find out whether your idea fits with the scope and aims of the project. It's up to you to make a strong case to convince the project's developers of the merits of this feature. Keep in mind that we want features that will be useful to the majority of our users and not just a small subset. If you're just targeting a minority of users, consider writing an add-on/plugin library.
95
+
96
+ #### How Do I Submit a Good Enhancement Suggestion?
97
+
98
+ Enhancement suggestions are tracked as [GitHub issues](https://github.com/a51-dev/a51.memorio/issues).
99
+
100
+ * Use a **clear and descriptive title** for the issue to identify the suggestion.
101
+ * Provide a **step-by-step description of the suggested enhancement** in as many details as possible.
102
+ * **Describe the current behavior** and **explain which behavior you expected to see instead** and why. At this point you can also tell which alternatives do not work for you.
103
+ * You may want to **include screenshots or screen recordings** which help you demonstrate the steps or point out the part which the suggestion is related to. You can use [screentogif](https://www.screentogif.com/) to record GIFs on macOS and Windows, and the built-in [screen recorder in GNOME](https://help.gnome.org/users/gnome-help/stable/screen-shot-record.html.en) or [SimpleScreenRecorder](https://github.com/MaartenBaert/ssr) on Linux.
104
+ * **Explain why this enhancement would be useful** to most boilerplate users. You may also want to point out the other projects that solved it better and which could serve as inspiration.
105
+
106
+ ## Join The Project Team
107
+
108
+ Please send email to <dariopassariello@gmail.com>
package/COPYRIGHT.md ADDED
@@ -0,0 +1,6 @@
1
+ # Copyright
2
+
3
+ Copyright (c) 2025, Dario Passariello. All rights reserved.
4
+ <https://dario.passariello.ca>
5
+
6
+ This software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.
package/README.md CHANGED
@@ -3,17 +3,26 @@
3
3
  > A lightweight, type-safe state management library for JavaScript applications
4
4
 
5
5
  [![version](https://img.shields.io/npm/v/memorio.svg)](https://npmjs.org/package/memorio)
6
+ [![install size](https://img.shields.io/badge/dynamic/json?url=https://packagephobia.com/v2/api.json?p=memorio&query=$.install.pretty&label=install%20size&style=flat-square)](https://packagephobia.now.sh/result?p=memorio)
6
7
  [![downloads](https://img.shields.io/npm/dm/memorio.svg)](https://npmjs.org/package/memorio)
7
8
 
8
- ![TypeScript](https://img.shields.io/badge/TypeScript-gray?logo=typescript)
9
+ ![Snyk](https://img.shields.io/badge/Snyk-gray?logo=Snyk)
10
+ [![Known Vulnerabilities](https://snyk.io/test/npm/memorio/badge.svg)](https://snyk.io/test/npm/memorio)
11
+ [![Socket Badge](https://socket.dev/api/badge/npm/package/memorio)](https://socket.dev/npm/package/memorio)
12
+
9
13
  ![Node.js](https://img.shields.io/badge/Node.js-gray?logo=node.js)
10
- ![Jest](https://img.shields.io/badge/Jest-gray?logo=jest)
11
- ![ESLint](https://img.shields.io/badge/ESLint-gray?logo=eslint)
14
+ ![React](https://img.shields.io/badge/React-gray?logo=React)
15
+ ![Javascript](https://img.shields.io/badge/Javascript-gray?logo=Javascript)
16
+ ![TypeScript](https://img.shields.io/badge/TypeScript-gray?logo=typescript)
12
17
  ![esbuild](https://img.shields.io/badge/esbuild-gray?logo=esbuild)
13
18
 
14
- ![License](https://img.shields.io/badge/license-MIT-blue.svg)
19
+ ![Jest](https://img.shields.io/badge/Jest-gray?logo=jest)
20
+ ![ESLint](https://img.shields.io/badge/Eslint-gray?logo=eslint)
21
+ ![Playwright](https://img.shields.io/badge/Playwright-gray?logo=playwright)
22
+
23
+ [![GitBook](https://img.shields.io/static/v1?message=Documented%20on%20GitBook&logo=gitbook&logoColor=ffffff&label=%20&labelColor=5c5c5c&color=3F89A1)](https://a51.gitbook.io/memorio)
15
24
 
16
- License is MIT - free to use, modify, and distribute
25
+ ---
17
26
 
18
27
  ## Table of Contents
19
28
 
package/SECURITY.md ADDED
@@ -0,0 +1,3 @@
1
+ # Security
2
+
3
+ Please email [@passariello](https://github.com/passariello) or see https://dario.passariello.ca/contact/ if you have a potential security vulnerability to report.
package/index.cjs ADDED
@@ -0,0 +1,3 @@
1
+ 'use strict';
2
+
3
+ var __getOwnPropNames=Object.getOwnPropertyNames;var __esm=(fn,res)=>function __init(){return fn&&(res=(0, fn[__getOwnPropNames(fn)[0]])(fn=0)),res};var db_create_exports={};var init_db_create=__esm({"functions/idb/tools/db.create.ts"(){idb.db.create=(dbName,ver=1)=>{return new Promise((resolve,reject)=>{if(!idb.db.support()){return reject(new Error("IndexedDB not supported"))}const request=globalThis.indexedDB.open(dbName,ver);request.onerror=()=>{console.debug(`IndexedDB error: ${request.error?.message}`);reject(request.error);};request.onsuccess=()=>{console.debug(`Database ${dbName} connected successfully`);idb.db.list();resolve(request.result);};request.onupgradeneeded=()=>{console.debug(`Database ${dbName} upgrade/creation initiated`);};})};}});var db_list_exports={};var init_db_list=__esm({"functions/idb/tools/db.list.ts"(){idb.db.list=async()=>{if(!("indexedDB"in globalThis)||!indexedDB.databases)return [];try{const result=await indexedDB.databases();globalThis.idbases=result||[];await idb.db.size();return globalThis.idbases}catch(err){console.error("Error listing databases:",err);return []}};idb.db.list();}});var db_exist_exports={};var init_db_exist=__esm({"functions/idb/tools/db.exist.ts"(){idb.db.exist=storeName=>{return idbases?.some(db=>db.name===storeName)};}});var db_quota_exports={};var init_db_quota=__esm({"functions/idb/tools/db.quota.ts"(){idb.db.quota=()=>{return navigator.storage.estimate()};}});var db_delete_exports={};var init_db_delete=__esm({"functions/idb/tools/db.delete.ts"(){idb.db.delete=storeName=>{return new Promise((resolve,reject)=>{console.debug(`Removing database ${storeName}...`);const performDelete=()=>{const request=indexedDB.deleteDatabase(storeName);request.onsuccess=()=>{console.debug(`${storeName} database removed successfully`);idb.db.list();resolve();};request.onerror=()=>{console.error(`Error removing ${storeName}:`,request.error);reject(request.error);};request.onblocked=()=>{console.warn(`Deletion of ${storeName} is blocked. Please close other tabs.`);};};if(confirm(`Are you sure you want to remove the "${storeName}" database?`)){performDelete();}else {console.debug("Database deletion cancelled by user.");resolve();}})};}});var db_size_exports={};var init_db_size=__esm({"functions/idb/tools/db.size.ts"(){idb.db.size=async()=>{if(!idbases||idbases.length===0)return;for(let i=0;i<idbases.length;i++){const dbInfo=idbases[i];try{const db=await idb.db.create(dbInfo.name,dbInfo.version);const tableNames=Array.from(db.objectStoreNames);let totalDbSize=0;for(const tableName of tableNames){const tableSize=await idb.table.size(db,tableName);totalDbSize+=tableSize;}dbInfo.size=totalDbSize;db.close();}catch(err){console.debug(`Could not calculate size for ${dbInfo.name}:`,err);}}};}});var db_version_exports={};var init_db_version=__esm({"functions/idb/tools/db.version.ts"(){idb.db.version=storeName=>{let idbVer=0;for(const v of idbases){if(v.name===storeName)idbVer=v.version;break}return idbVer};}});var db_support_exports={};var init_db_support=__esm({"functions/idb/tools/db.support.ts"(){idb.db.support=()=>{const isSupported="indexedDB"in globalThis;if(!isSupported){console.debug("Your environment doesn't support IndexedDB");}return isSupported};}});var table_create_exports={};var init_table_create=__esm({"functions/idb/tools/table.create.ts"(){idb.table.create=(dbName,dbTable)=>{return new Promise(async(resolve,reject)=>{try{const currentVersion=Number(idb.db.version(dbName))||0;const nextVersion=currentVersion+1;const request=indexedDB.open(dbName,nextVersion);request.onupgradeneeded=e=>{const db=e.target.result;if(!db.objectStoreNames.contains(dbTable)){const store2=db.createObjectStore(dbTable,{keyPath:"id",autoIncrement:true});store2.createIndex("id","id",{unique:true});store2.createIndex("data","data",{unique:false});console.debug(`Table ${dbTable} created in ${dbName}`);}};request.onsuccess=()=>{request.result.close();idb.db.list();resolve();};request.onerror=()=>{console.error(`Error creating table ${dbTable}:`,request.error);reject(request.error);};}catch(err){console.error("Critical error in table.create:",err);reject(err);}})};}});var table_size_exports={};var init_table_size=__esm({"functions/idb/tools/table.size.ts"(){idb.table.size=(db,table)=>{return new Promise((resolve,reject)=>{if(!db)return reject(new Error("Database instance is required"));if(!db.objectStoreNames.contains(table))return resolve(0);let size=0;let count=0;const transaction=db.transaction([table],"readonly");const store2=transaction.objectStore(table);const request=store2.openCursor();request.onsuccess=async event=>{const cursor=event.target.result;if(cursor){try{const value=cursor.value;size+=JSON.stringify(value).length;}catch(e){console.debug("Error stringifying IDB value tracking size:",e);}count++;if(count%200===0){await new Promise(resolve2=>setTimeout(resolve2,0));}cursor.continue();}else {resolve(size);}};request.onerror=()=>{reject(request.error);};})};}});var data_delete_exports={};var init_data_delete=__esm({"functions/idb/crud/data.delete.ts"(){idb.data.delete=(storeName,table,key)=>{return new Promise((resolve,reject)=>{const request=indexedDB.open(storeName);request.onsuccess=()=>{const db=request.result;if(!db.objectStoreNames.contains(table)){db.close();return reject(new Error(`Table ${table} not found`))}const transaction=db.transaction(table,"readwrite");const objectStore=transaction.objectStore(table);const deleteRequest=objectStore.delete(key);deleteRequest.onsuccess=()=>{db.close();console.debug(`Record ${key} deleted from ${table}`);resolve();};deleteRequest.onerror=()=>{db.close();reject(deleteRequest.error);};};request.onerror=()=>reject(request.error);})};idb.data.delete.all=(storeName,table)=>{return new Promise((resolve,reject)=>{const request=indexedDB.open(storeName);request.onsuccess=event=>{const db=event.target.result;if(!db.objectStoreNames.contains(table)){db.close();return reject(new Error(`Table ${table} not found`))}const transaction=db.transaction(table,"readwrite");const store2=transaction.objectStore(table);const clearRequest=store2.clear();clearRequest.onsuccess=()=>{db.close();console.debug(`All data cleared from ${table}`);resolve();};clearRequest.onerror=()=>{db.close();reject(clearRequest.error);};};request.onerror=()=>reject(request.error);})};}});var data_set_exports={};var init_data_set=__esm({"functions/idb/crud/data.set.ts"(){idb.data.set=(storeName,table,value)=>{return new Promise((resolve,reject)=>{const request=indexedDB.open(storeName);request.onsuccess=()=>{const db=request.result;if(!db.objectStoreNames.contains(table)){db.close();return reject(new Error(`Table ${table} does not exist in ${storeName}`))}const transaction=db.transaction(table,"readwrite");const objectStore=transaction.objectStore(table);const putRequest=objectStore.put(value);putRequest.onsuccess=()=>{db.close();console.debug(`Data saved in ${storeName}.${table}`);resolve(putRequest.result);};putRequest.onerror=e=>{db.close();console.debug(`Database insert error: ${putRequest.error?.message}`);reject(putRequest.error);};};request.onerror=()=>{reject(request.error);};})};}});var data_get_exports={};var init_data_get=__esm({"functions/idb/crud/data.get.ts"(){idb.data.get=(storeName,table,key)=>{return new Promise((resolve,reject)=>{const request=indexedDB.open(storeName);request.onsuccess=event=>{const db=event.target.result;if(!db.objectStoreNames.contains(table)){db.close();return reject(new Error(`Table ${table} not found in ${storeName}`))}const transaction=db.transaction(table,"readonly");const store2=transaction.objectStore(table);const getRequest=store2.get(key);getRequest.onsuccess=()=>{db.close();resolve(getRequest.result);};getRequest.onerror=()=>{db.close();reject(getRequest.error);};};request.onerror=()=>{reject(request.error);};})};}});var package_default={version:"2.6.0"};Object.defineProperty(globalThis,"memorio",{value:{},writable:false,configurable:true,enumerable:false});Object.defineProperty(globalThis,"events",{value:{},writable:true,enumerable:false});Object.defineProperty(memorio,"version",{writable:false,enumerable:false,value:package_default.version});var protect=["list","state","store","idb","observer","useObserver","remove","removeAll"];Object.defineProperty(memorio,"dispatch",{writable:false,enumerable:false,value:{set:(name,value={})=>{globalThis.dispatchEvent(new CustomEvent(String(name),value));},listen:(name,cb=null,flag=false)=>{if(globalThis.observer?.list?.[name]?.length>0)globalThis.observer?.remove?.(name);const exec=cb?e=>setTimeout(()=>cb(e),1):void 0;if(exec)globalThis.addEventListener(name,exec);if(exec)globalThis.events[name]=exec;},remove:name=>{const listener=globalThis.events?.[name];if(listener){globalThis.removeEventListener(name,listener);delete globalThis.events[name];}}}});memorio.propertyName=(container,object)=>{const t=String(object).replace("() => ","");return t};Object.defineProperty(memorio,"objPath",{writable:false,enumerable:false,value:(prop,object,separator=".")=>{const path=object.concat(prop).join(separator);if(globalThis.memorio._tracking){globalThis.memorio._trackedPaths?.add("state."+path);}return path}});globalThis.memorio._tracking=false;globalThis.memorio._trackedPaths=new Set;globalThis.memorio._locked=false;var buildProxy=(obj,callback,tree=[])=>{const event=name=>{try{globalThis.memorio?.dispatch?.set?.(name,{detail:{name}});}catch(e){}return};return new Proxy(obj,{get(target,prop){if(prop==="__path"){return tree.length>0?"state."+tree.join("."):"state"}if(prop==="list"){console.debug('Some state could be hidden when you use "state.list". Use "state" to see the complete list ');return JSON.parse(JSON.stringify(globalThis.state))}if(globalThis.memorio._tracking&&typeof prop==="string"){const path=tree.length>0?"state."+tree.concat(prop).join("."):"state."+prop;globalThis.memorio._trackedPaths?.add(path);}if(prop==="remove"){return key=>{delete target[key];return true}}if(prop==="removeAll"){return ()=>{try{for(const key in target){if(typeof target[key]!=="function"&&!["list","remove","removeAll"].includes(key)){if(!Object.isFrozen(target[key]))delete target[key];delete target[key];}}}catch(error){console.debug(error);}return}}if(Object.isFrozen(target[prop]))return target[prop];if(prop==="lock"||prop==="unlock"){const value=Reflect.get(target,prop);if(value)return value}try{const value=Reflect.get(target,prop);if(value&&typeof value==="object"&&["Array","Object"].includes(value.constructor.name)){return buildProxy(value,callback,tree.concat(prop))}return value}catch(error){console.error("Error: ",error);return void 0}},set(target,key,value){if(globalThis.memorio._locked){console.error("Error: state is locked. Use state.unlock() to enable modifications.");return false}if(protect.includes(key)){console.error("key "+key+" is protected");return false}if(target[key]&&typeof target[key]==="object"&&Object.isFrozen(target[key])){console.error(`Error: state '${key}' is locked`);return false}if(target[key]&&typeof target[key]==="object"&&target[key].__locked){console.error(`Error: state '${key}' is locked. Use state.${key}.unlock() to enable modifications.`);return false}try{const path=globalThis.memorio.objPath?.(key,tree)??key;callback({action:"set",path,target,newValue:value,previousValue:Reflect.get(target,key)});event("state."+path);Reflect.set(target,key,value);if(target[key]&&typeof target[key]==="object"){const rawValue=target[key];if(rawValue&&typeof rawValue==="object"){try{Object.defineProperty(rawValue,"__locked",{writable:true,enumerable:false,configurable:false,value:false});Object.defineProperty(rawValue,"lock",{writable:false,enumerable:false,configurable:false,value:()=>{Object.defineProperty(rawValue,"__locked",{writable:true,enumerable:false,configurable:false,value:true});console.info(`State '${key}' is now locked.`);}});Object.defineProperty(rawValue,"unlock",{writable:false,enumerable:false,configurable:false,value:()=>{Object.defineProperty(rawValue,"__locked",{writable:true,enumerable:false,configurable:false,value:false});console.info(`State '${key}' is now unlocked.`);}});}catch(defineError){}}}return true}catch(error){console.error("Error in set trap:",error);return false}},deleteProperty(target,prop){try{const path=globalThis.memorio.objPath?.(prop,tree);callback({action:"delete",path,target});return Reflect.deleteProperty(target,prop)}catch(error){console.error("Error in deleteProperty trap:",error);return false}},ownKeys(target){return Reflect.ownKeys(target)},getOwnPropertyDescriptor(target,prop){return Reflect.getOwnPropertyDescriptor(target,prop)}})};!globalThis?.state?globalThis.state=buildProxy({},()=>{}):globalThis.state=state;globalThis.state.lock=()=>{globalThis.memorio._locked=true;console.info("State is now locked. All modifications are blocked.");};globalThis.state.unlock=()=>{globalThis.memorio._locked=false;console.info("State is now unlocked. Modifications are allowed.");};Object.defineProperty(globalThis,"state",{enumerable:false,configurable:true});if(!globalThis.observer){globalThis.observer=null;}Object.defineProperty(globalThis,"observer",{enumerable:false,configurable:true});var observerFunction=(s,cb=null,option=true)=>{console.warn('DEPRECATED: "observer" is deprecated and will be removed in future versions. Please use "useObserver" instead.');try{const checkStateOrStore=s2=>{const t=s2.split(".");if(t[0]!=="state"){console.error(`Observer Error: You need to declare 'state.' or 'store.'. The '${s2}' string is incorrect!`);return false}return true};if(!checkStateOrStore(s))return}catch(error){console.error(error);return}if(!s&&!cb){console.error("Observer Error: You need to setup observer correctly, Some parameters are missed!");return}if(!s&&cb){console.error(`Observer Error: You need to declare what state need to be monitored as string like 'state.test'.`);return}if(s&&!cb){const f=({detail:{name:String(s)}});const obs=globalThis.observer;if(obs?.list?.[s])globalThis.memorio.dispatch.remove(f);if(!obs?.list?.[s])globalThis.memorio.dispatch.listen(f);console.debug("called: ",s);return}if(s&&cb){if(typeof s!=="string"||typeof cb!=="function"){console.error(`Observer Error: name of state need to be a 'string' like 'state.test' and the callback need to be a 'function'`);return}const obs=globalThis.observer;if(obs?.list?.[s])globalThis.memorio.dispatch.remove(s,cb,option);if(!obs?.list?.[s])globalThis.memorio.dispatch.listen(s,cb,option);return}};globalThis.observer=observerFunction;Object.defineProperties(globalThis.observer,{list:{get:()=>globalThis.events},remove:{value:name=>{if(!name)return;globalThis.memorio.dispatch.remove(name);delete globalThis.events[name];return}},removeAll:{get:()=>{const obs=globalThis.observer;const list=obs?.list;if(list){Object.keys(list).forEach(key=>{obs?.remove?.(key);});}return true}}});Object.freeze(observer);if(!globalThis.useObserver)globalThis.useObserver=null;Object.defineProperty(globalThis,"useObserver",{value:null,writable:true,enumerable:false,configurable:true});globalThis.useObserver=((func,deps)=>{if(!deps||typeof func!=="function"){return ()=>{}}const handlers=[];const depList=Array.isArray(deps)&&!deps.__path?deps:[deps];try{depList.forEach(dep=>{let t="";if(typeof dep==="function"){const propName=globalThis.memorio.propertyName;if(typeof propName==="function"){const result=propName(globalThis.state,dep);if(result)t=result;}}else if(typeof dep==="object"&&dep!==null){t=dep.__path||(typeof dep.toString==="function"&&dep.toString()!=="[object Object]"?dep.toString():"");}else if(typeof dep==="string"&&(dep.startsWith("state.")||dep.startsWith("store."))){t=dep;}if(t){t=t.replace(/^(\(\)\s*=>\s*)/,"").replace(/^globalThis\./,"").replace(/^state\./,"");const path=t.startsWith("store.")||t.startsWith("state.")?t:"state."+t;globalThis.memorio.dispatch.listen(path,()=>func());handlers.push(path);}else {globalThis.memorio._trackedPaths?.clear();globalThis.memorio._tracking=true;try{func();}catch(e){}globalThis.memorio._tracking=false;globalThis.memorio._trackedPaths?.forEach(path=>{if(!handlers.includes(path)){console.info(`useObserver: [Auto-Discovery] -> "${path}"`);globalThis.memorio.dispatch.listen(path,()=>func());handlers.push(path);}});}});if(handlers.length>0){console.info(`useObserver: Monitoring ${handlers.length} paths.`);}else {console.warn(`useObserver: No paths resolved for monitoring. Check your dependencies!`);}return ()=>{handlers.forEach(path=>{if(globalThis.memorio.dispatch&&typeof globalThis.memorio.dispatch.remove==="function"){globalThis.memorio.dispatch.remove(path);console.debug(`useObserver: Stopped monitoring "${path}"`);}});}}catch(err){console.debug("useObserver Error:",err);return ()=>{}}});Object.freeze(globalThis.useObserver);Object.defineProperty(globalThis,"store",{value:new Proxy({},{}),enumerable:false,configurable:true});Object.defineProperties(store,{get:{value:name=>{if(!name)return;try{const item=globalThis.localStorage.getItem(name);if(item)return JSON.parse(item);return item}catch(err){console.debug(`Error parsing store item '${name}':`,err);}return null}},set:{value:(name,value)=>{if(!name)return;try{if(value===null||value===void 0)globalThis.localStorage.setItem(name,JSON.stringify(null));else if(typeof value==="object"||typeof value==="number"||typeof value==="boolean"||typeof value==="string")globalThis.localStorage.setItem(name,JSON.stringify(value));else if(typeof value==="function")console.debug("It's not secure to store functions.");}catch(err){console.debug(`Error setting store item '${name}':`,err);}return null}},remove:{value:name=>{if(!name)return;if(globalThis.localStorage.getItem(name)){globalThis.localStorage.removeItem(name);return true}return false}},delete:{value:name=>{store.remove(name);return true}},removeAll:{value:()=>{globalThis.localStorage.clear();return true}},clearAll:{value:()=>{store.removeAll();return true}},quota:{value:async()=>{if(globalThis.navigator&&"storage"in globalThis.navigator&&"estimate"in globalThis.navigator.storage){return globalThis.navigator.storage.estimate().then(({usage,quota})=>{const u=usage??0;const q=quota??0;if(u&&q)console.debug(`Using ${u/1024} out of ${q/1024} Mb.`);return [u/1024,q/1024]}).catch(err=>{console.debug("Error estimating quota:",err);return [0,0]})}return [0,0]}},size:{value:()=>{let totalSize=0;Object.keys(globalThis.localStorage).forEach(key=>{const item=globalThis.localStorage.getItem(key);if(item)totalSize+=item.length;});return totalSize}}});Object.freeze(store);Object.defineProperty(globalThis,"session",{value:new Proxy({},{}),enumerable:false,configurable:true});Object.defineProperties(session,{get:{value:name=>{if(!name)return;try{const item=globalThis.sessionStorage.getItem(name);if(item)return JSON.parse(item);return item}catch(err){console.debug(`Error parsing session item '${name}':`,err);}return}},set:{value:(name,value)=>{if(!name)return;try{if(value===null||value===void 0)globalThis.sessionStorage.setItem(name,JSON.stringify(null));else if(typeof value==="object"||typeof value==="number"||typeof value==="boolean"||typeof value==="string")globalThis.sessionStorage.setItem(name,JSON.stringify(value));else if(typeof value==="function")console.debug("It's not secure to session functions.");}catch(err){console.debug(`Error setting session item '${name}':`,err);}return}},remove:{value:name=>{if(!name)return;if(globalThis.sessionStorage.getItem(name)){globalThis.sessionStorage.removeItem(name);return true}return}},delete:{value:name=>{session.remove(name);return true}},removeAll:{value:()=>{globalThis.sessionStorage.clear();return true}},clearAll:{value:()=>{session.removeAll();return true}},quota:{value:async()=>{if(globalThis.navigator&&"storage"in globalThis.navigator&&"estimate"in globalThis.navigator.storage){return globalThis.navigator.storage.estimate().then(({usage,quota})=>{const u=usage??0;const q=quota??0;if(u&&q)console.debug(`Using ${u/1024} out of ${q/1024} Mb.`);return [u/1024,q/1024]}).catch(err=>{console.debug("Error estimating quota:",err);return [0,0]})}return [0,0]}},size:{value:()=>{let totalSize=0;Object.keys(globalThis.sessionStorage).forEach(key=>{const item=globalThis.sessionStorage.getItem(key);if(item)totalSize+=item.length;});return totalSize}}});Object.freeze(session);var cacheData={};Object.defineProperty(globalThis,"cache",{value:new Proxy({},{get(target,prop){const key=prop;if(key==="get")return name=>cacheData[name];if(key==="set")return (name,value)=>{cacheData[name]=value;};if(key==="remove")return name=>{delete cacheData[name];return true};if(key==="removeAll")return ()=>{Object.keys(cacheData).forEach(k=>delete cacheData[k]);return true};if(key==="clear")return ()=>{Object.keys(cacheData).forEach(k=>delete cacheData[k]);return true};return cacheData[key]},set(target,prop,value){cacheData[prop]=value;return true},deleteProperty(target,prop){delete cacheData[prop];return true}}),enumerable:false,configurable:true});Object.freeze(cache);(async()=>{Object.defineProperty(globalThis,"idb",{value:{db:{},table:{},data:{}},writable:true,configurable:true,enumerable:false});Object.defineProperty(globalThis,"idbases",{value:[],writable:true,configurable:true,enumerable:false});await Promise.all([Promise.resolve().then(()=>(init_db_create(),db_create_exports)),Promise.resolve().then(()=>(init_db_list(),db_list_exports)),Promise.resolve().then(()=>(init_db_exist(),db_exist_exports)),Promise.resolve().then(()=>(init_db_quota(),db_quota_exports)),Promise.resolve().then(()=>(init_db_delete(),db_delete_exports)),Promise.resolve().then(()=>(init_db_size(),db_size_exports)),Promise.resolve().then(()=>(init_db_version(),db_version_exports)),Promise.resolve().then(()=>(init_db_support(),db_support_exports)),Promise.resolve().then(()=>(init_table_create(),table_create_exports)),Promise.resolve().then(()=>(init_table_size(),table_size_exports)),Promise.resolve().then(()=>(init_data_delete(),data_delete_exports)),Promise.resolve().then(()=>(init_data_set(),data_set_exports)),Promise.resolve().then(()=>(init_data_get(),data_get_exports))]);Object.preventExtensions(idb);Object.seal(idb);Object.freeze(idb);})();
package/index.js CHANGED
@@ -1 +1 @@
1
- var l=(e,r)=>()=>(e&&(r=e(e=0)),r);var p,h=l(()=>{p={name:"memorio",version:"2.5.3",type:"module",private:!1,main:"index.js",license:"MIT",typings:"./types/*",description:"Memorio, State + Observer and Store for an easy life",copyright:"Copyright (c) 2025 Dario Passariello",homepage:"https://a51.gitbook.io/memorio",author:{name:"Dario Passariello",url:"https://dario.passariello.ca/",email:"dariopassariello@gmail.com"},support:{name:"Dario Passariello",url:"https://github.com/passariello/",email:"dariopassariello@gmail.com"},contributors:[{name:"Dario Passariello",email:"dariopassarielloa@gmail.com"},{name:"Valeria Cala Scaglitta",email:"valeriacalascaglitta@gmail.com"}],keywords:["biglogic","a51","memorio","state","store","observer","useObserver","dario","passariello"],funding:[{type:"patreon",url:"https://www.patreon.com/passariello"}],typing:["types/*"],exports:{".":{types:"./types/index.d.ts",import:"./index.js",default:"./index.js"},"./types/*":"./types/*"},scripts:{build:"rimraf dist && node ./esbuild.config.mjs",watch:'rimraf dist && nodemon --watch * --exec "npm run build "',"npm:publish":"npm run build && npm publish ./dist",test:"cd tests && npm run test",lint:"cd tests && npm run lint",tsc:"tsc --noEmit"},devDependencies:{"@types/node":"25.3.3",esbuild:"0.27.3","esbuild-node-externals":"1.20.1","esbuild-plugin-alias":"0.2.1","esbuild-plugin-copy":"2.1.1",rimraf:"6.1.3",typescript:"5.9.3"}}});var y,m=l(()=>{"use strict";a();h();Object.defineProperty(globalThis,"memorio",{value:{},writable:!1,configurable:!0,enumerable:!1});Object.defineProperty(globalThis,"events",{value:{},writable:!0,enumerable:!1});Object.defineProperty(memorio,"version",{writable:!1,enumerable:!1,value:p.version});y=["list","state","store","idb","observer","useObserver","remove","removeAll"]});var v=l(()=>{"use strict";a();Object.defineProperty(memorio,"dispatch",{writable:!1,enumerable:!1,value:{set:(e,r={})=>{globalThis.dispatchEvent(new CustomEvent(String(e),r))},listen:(e,r=null,o=!1)=>{globalThis.observer?.list?.[e]?.length>0&&globalThis.observer?.remove?.(e);let i=r?t=>setTimeout(()=>r(t),1):void 0;i&&globalThis.addEventListener(e,i),i&&(globalThis.events[e]=i)},remove:e=>{let r=globalThis.events?.[e];r&&(globalThis.removeEventListener(e,r),delete globalThis.events[e])}}})});var T=l(()=>{"use strict";a();memorio.propertyName=(e,r)=>String(r).replace("() => ","")});var P,O=l(()=>{"use strict";a();m();Object.defineProperty(memorio,"objPath",{writable:!1,enumerable:!1,value:(e,r,o=".")=>{let i=r.concat(e).join(o);return globalThis.memorio._tracking&&globalThis.memorio._trackedPaths?.add("state."+i),i}});globalThis.memorio._tracking=!1;globalThis.memorio._trackedPaths=new Set;globalThis.memorio._locked=!1;P=(e,r,o=[])=>{let i=t=>{try{globalThis.memorio?.dispatch?.set?.(t,{detail:{name:t}})}catch{}};return new Proxy(e,{get(t,s){if(s==="__path")return o.length>0?"state."+o.join("."):"state";if(s==="list")return console.debug('Some state could be hidden when you use "state.list". Use "state" to see the complete list '),JSON.parse(JSON.stringify(globalThis.state));if(globalThis.memorio._tracking&&typeof s=="string"){let n=o.length>0?"state."+o.concat(s).join("."):"state."+s;globalThis.memorio._trackedPaths?.add(n)}if(s==="remove")return n=>(delete t[n],!0);if(s==="removeAll")return()=>{try{for(let n in t)typeof t[n]!="function"&&!["list","remove","removeAll"].includes(n)&&(Object.isFrozen(t[n])||delete t[n],delete t[n])}catch(n){console.debug(n)}};if(Object.isFrozen(t[s]))return t[s];if(s==="lock"||s==="unlock"){let n=Reflect.get(t,s);if(n)return n}try{let n=Reflect.get(t,s);return n&&typeof n=="object"&&["Array","Object"].includes(n.constructor.name)?P(n,r,o.concat(s)):n}catch(n){console.error("Error: ",n);return}},set(t,s,n){if(globalThis.memorio._locked)return console.error("Error: state is locked. Use state.unlock() to enable modifications."),!1;if(y.includes(s))return console.error("key "+s+" is protected"),!1;if(t[s]&&typeof t[s]=="object"&&Object.isFrozen(t[s]))return console.error(`Error: state '${s}' is locked`),!1;if(t[s]&&typeof t[s]=="object"&&t[s].__locked)return console.error(`Error: state '${s}' is locked. Use state.${s}.unlock() to enable modifications.`),!1;try{let u=globalThis.memorio.objPath?.(s,o)??s;if(r({action:"set",path:u,target:t,newValue:n,previousValue:Reflect.get(t,s)}),i("state."+u),Reflect.set(t,s,n),t[s]&&typeof t[s]=="object"){let b=t[s];if(b&&typeof b=="object")try{Object.defineProperty(b,"__locked",{writable:!0,enumerable:!1,configurable:!1,value:!1}),Object.defineProperty(b,"lock",{writable:!1,enumerable:!1,configurable:!1,value:()=>{Object.defineProperty(b,"__locked",{writable:!0,enumerable:!1,configurable:!1,value:!0}),console.info(`State '${s}' is now locked.`)}}),Object.defineProperty(b,"unlock",{writable:!1,enumerable:!1,configurable:!1,value:()=>{Object.defineProperty(b,"__locked",{writable:!0,enumerable:!1,configurable:!1,value:!1}),console.info(`State '${s}' is now unlocked.`)}})}catch{}}return!0}catch(u){return console.error("Error in set trap:",u),!1}},deleteProperty(t,s){try{let n=globalThis.memorio.objPath?.(s,o);return r({action:"delete",path:n,target:t}),Reflect.deleteProperty(t,s)}catch(n){return console.error("Error in deleteProperty trap:",n),!1}},ownKeys(t){return Reflect.ownKeys(t)},getOwnPropertyDescriptor(t,s){return Reflect.getOwnPropertyDescriptor(t,s)}})};globalThis?.state?globalThis.state=state:globalThis.state=P({},()=>{});globalThis.state.lock=()=>{globalThis.memorio._locked=!0,console.info("State is now locked. All modifications are blocked.")};globalThis.state.unlock=()=>{globalThis.memorio._locked=!1,console.info("State is now unlocked. Modifications are allowed.")};Object.defineProperty(globalThis,"state",{enumerable:!1,configurable:!0})});var F,S=l(()=>{"use strict";a();globalThis.observer||(globalThis.observer=null);Object.defineProperty(globalThis,"observer",{enumerable:!1,configurable:!0});F=(e,r=null,o=!0)=>{console.warn('DEPRECATED: "observer" is deprecated and will be removed in future versions. Please use "useObserver" instead.');try{if(!(t=>t.split(".")[0]!=="state"?(console.error(`Observer Error: You need to declare 'state.' or 'store.'. The '${t}' string is incorrect!`),!1):!0)(e))return}catch(i){console.error(i);return}if(!e&&!r){console.error("Observer Error: You need to setup observer correctly, Some parameters are missed!");return}if(!e&&r){console.error("Observer Error: You need to declare what state need to be monitored as string like 'state.test'.");return}if(e&&!r){let i=(String(e),{detail:{name:String(e)}}),t=globalThis.observer;t?.list?.[e]&&globalThis.memorio.dispatch.remove(i),t?.list?.[e]||globalThis.memorio.dispatch.listen(i),console.debug("called: ",e);return}if(e&&r){if(typeof e!="string"||typeof r!="function"){console.error("Observer Error: name of state need to be a 'string' like 'state.test' and the callback need to be a 'function'");return}let i=globalThis.observer;i?.list?.[e]&&globalThis.memorio.dispatch.remove(e,r,o),i?.list?.[e]||globalThis.memorio.dispatch.listen(e,r,o);return}};globalThis.observer=F;Object.defineProperties(globalThis.observer,{list:{get:()=>globalThis.events},remove:{value:e=>{e&&(globalThis.memorio.dispatch.remove(e),delete globalThis.events[e])}},removeAll:{get:()=>{let e=globalThis.observer,r=e?.list;return r&&Object.keys(r).forEach(o=>{e?.remove?.(o)}),!0}}});Object.freeze(observer)});var w=l(()=>{"use strict";a();globalThis.useObserver||(globalThis.useObserver=null);Object.defineProperty(globalThis,"useObserver",{value:null,writable:!0,enumerable:!1,configurable:!0});globalThis.useObserver=((e,r)=>{if(!r||typeof e!="function")return()=>{};let o=[],i=Array.isArray(r)&&!r.__path?r:[r];try{return i.forEach(t=>{let s="";if(typeof t=="function"){let n=globalThis.memorio.propertyName;if(typeof n=="function"){let u=n(globalThis.state,t);u&&(s=u)}}else typeof t=="object"&&t!==null?s=t.__path||(typeof t.toString=="function"&&t.toString()!=="[object Object]"?t.toString():""):typeof t=="string"&&(t.startsWith("state.")||t.startsWith("store."))&&(s=t);if(s){s=s.replace(/^(\(\)\s*=>\s*)/,"").replace(/^globalThis\./,"").replace(/^state\./,"");let n=s.startsWith("store.")||s.startsWith("state.")?s:"state."+s;globalThis.memorio.dispatch.listen(n,()=>e()),o.push(n)}else{globalThis.memorio._trackedPaths?.clear(),globalThis.memorio._tracking=!0;try{e()}catch{}globalThis.memorio._tracking=!1,globalThis.memorio._trackedPaths?.forEach(n=>{o.includes(n)||(console.info(`useObserver: [Auto-Discovery] -> "${n}"`),globalThis.memorio.dispatch.listen(n,()=>e()),o.push(n))})}}),o.length>0?console.info(`useObserver: Monitoring ${o.length} paths.`):console.warn("useObserver: No paths resolved for monitoring. Check your dependencies!"),()=>{o.forEach(t=>{globalThis.memorio.dispatch&&typeof globalThis.memorio.dispatch.remove=="function"&&(globalThis.memorio.dispatch.remove(t),console.debug(`useObserver: Stopped monitoring "${t}"`))})}}catch(t){return console.debug("useObserver Error:",t),()=>{}}});Object.freeze(globalThis.useObserver)});var j=l(()=>{"use strict";a();Object.defineProperty(globalThis,"store",{value:new Proxy({},{}),enumerable:!1,configurable:!0});Object.defineProperties(store,{get:{value:e=>{if(e){try{let r=globalThis.localStorage.getItem(e);return r&&JSON.parse(r)}catch(r){console.debug(`Error parsing store item '${e}':`,r)}return null}}},set:{value:(e,r)=>{if(e){try{r==null?globalThis.localStorage.setItem(e,JSON.stringify(null)):typeof r=="object"||typeof r=="number"||typeof r=="boolean"||typeof r=="string"?globalThis.localStorage.setItem(e,JSON.stringify(r)):typeof r=="function"&&console.debug("It's not secure to store functions.")}catch(o){console.debug(`Error setting store item '${e}':`,o)}return null}}},remove:{value:e=>{if(e)return globalThis.localStorage.getItem(e)?(globalThis.localStorage.removeItem(e),!0):!1}},delete:{value:e=>(store.remove(e),!0)},removeAll:{value:()=>(globalThis.localStorage.clear(),!0)},clearAll:{value:()=>(store.removeAll(),!0)},quota:{value:async()=>globalThis.navigator&&"storage"in globalThis.navigator&&"estimate"in globalThis.navigator.storage?globalThis.navigator.storage.estimate().then(({usage:e,quota:r})=>{let o=e??0,i=r??0;return o&&i&&console.debug(`Using ${o/1024} out of ${i/1024} Mb.`),[o/1024,i/1024]}).catch(e=>(console.debug("Error estimating quota:",e),[0,0])):[0,0]},size:{value:()=>{let e=0;return Object.keys(globalThis.localStorage).forEach(r=>{let o=globalThis.localStorage.getItem(r);o&&(e+=o.length)}),e}}});Object.freeze(store)});var x=l(()=>{"use strict";a();Object.defineProperty(globalThis,"session",{value:new Proxy({},{}),enumerable:!1,configurable:!0});Object.defineProperties(session,{get:{value:e=>{if(e)try{let r=globalThis.sessionStorage.getItem(e);return r&&JSON.parse(r)}catch(r){console.debug(`Error parsing session item '${e}':`,r)}}},set:{value:(e,r)=>{if(e)try{r==null?globalThis.sessionStorage.setItem(e,JSON.stringify(null)):typeof r=="object"||typeof r=="number"||typeof r=="boolean"||typeof r=="string"?globalThis.sessionStorage.setItem(e,JSON.stringify(r)):typeof r=="function"&&console.debug("It's not secure to session functions.")}catch(o){console.debug(`Error setting session item '${e}':`,o)}}},remove:{value:e=>{if(e&&globalThis.sessionStorage.getItem(e))return globalThis.sessionStorage.removeItem(e),!0}},delete:{value:e=>(session.remove(e),!0)},removeAll:{value:()=>(globalThis.sessionStorage.clear(),!0)},clearAll:{value:()=>(session.removeAll(),!0)},quota:{value:async()=>globalThis.navigator&&"storage"in globalThis.navigator&&"estimate"in globalThis.navigator.storage?globalThis.navigator.storage.estimate().then(({usage:e,quota:r})=>{let o=e??0,i=r??0;return o&&i&&console.debug(`Using ${o/1024} out of ${i/1024} Mb.`),[o/1024,i/1024]}).catch(e=>(console.debug("Error estimating quota:",e),[0,0])):[0,0]},size:{value:()=>{let e=0;return Object.keys(globalThis.sessionStorage).forEach(r=>{let o=globalThis.sessionStorage.getItem(r);o&&(e+=o.length)}),e}}});Object.freeze(session)});var d,E=l(()=>{"use strict";a();d={};Object.defineProperty(globalThis,"cache",{value:new Proxy({},{get(e,r){let o=r;return o==="get"?i=>d[i]:o==="set"?(i,t)=>{d[i]=t}:o==="remove"?i=>(delete d[i],!0):o==="removeAll"?()=>(Object.keys(d).forEach(i=>delete d[i]),!0):o==="clear"?()=>(Object.keys(d).forEach(i=>delete d[i]),!0):d[o]},set(e,r,o){return d[r]=o,!0},deleteProperty(e,r){return delete d[r],!0}}),enumerable:!1,configurable:!0});Object.freeze(cache)});var U={};var D=l(()=>{"use strict";a();idb.db.create=(e,r=1)=>new Promise((o,i)=>{if(!idb.db.support())return i(new Error("IndexedDB not supported"));let t=globalThis.indexedDB.open(e,r);t.onerror=()=>{console.debug(`IndexedDB error: ${t.error?.message}`),i(t.error)},t.onsuccess=()=>{console.debug(`Database ${e} connected successfully`),idb.db.list(),o(t.result)},t.onupgradeneeded=()=>{console.debug(`Database ${e} upgrade/creation initiated`)}})});var W={};var $=l(()=>{"use strict";a();idb.db.list=async()=>{if(!("indexedDB"in globalThis)||!indexedDB.databases)return[];try{let e=await indexedDB.databases();return globalThis.idbases=e||[],await idb.db.size(),globalThis.idbases}catch(e){return console.error("Error listing databases:",e),[]}};idb.db.list()});var Y={};var k=l(()=>{"use strict";a();idb.db.exist=e=>idbases?.some(r=>r.name===e)});var L={};var _=l(()=>{"use strict";a();idb.db.quota=()=>navigator.storage.estimate()});var K={};var I=l(()=>{"use strict";a();idb.db.delete=e=>new Promise((r,o)=>{console.debug(`Removing database ${e}...`);let i=()=>{let t=indexedDB.deleteDatabase(e);t.onsuccess=()=>{console.debug(`${e} database removed successfully`),idb.db.list(),r()},t.onerror=()=>{console.error(`Error removing ${e}:`,t.error),o(t.error)},t.onblocked=()=>{console.warn(`Deletion of ${e} is blocked. Please close other tabs.`)}};confirm(`Are you sure you want to remove the "${e}" database?`)?i():(console.debug("Database deletion cancelled by user."),r())})});var G={};var q=l(()=>{"use strict";a();idb.db.size=async()=>{if(!(!idbases||idbases.length===0))for(let e=0;e<idbases.length;e++){let r=idbases[e];try{let o=await idb.db.create(r.name,r.version),i=Array.from(o.objectStoreNames),t=0;for(let s of i){let n=await idb.table.size(o,s);t+=n}r.size=t,o.close()}catch(o){console.debug(`Could not calculate size for ${r.name}:`,o)}}}});var H={};var z=l(()=>{"use strict";a();idb.db.version=e=>{let r=0;for(let o of idbases){o.name===e&&(r=o.version);break}return r}});var Q={};var A=l(()=>{"use strict";a();idb.db.support=()=>{let e="indexedDB"in globalThis;return e||console.debug("Your environment doesn't support IndexedDB"),e}});var X={};var B=l(()=>{"use strict";a();idb.table.create=(e,r)=>new Promise(async(o,i)=>{try{let s=(Number(idb.db.version(e))||0)+1,n=indexedDB.open(e,s);n.onupgradeneeded=u=>{let b=u.target.result;if(!b.objectStoreNames.contains(r)){let c=b.createObjectStore(r,{keyPath:"id",autoIncrement:!0});c.createIndex("id","id",{unique:!0}),c.createIndex("data","data",{unique:!1}),console.debug(`Table ${r} created in ${e}`)}},n.onsuccess=()=>{n.result.close(),idb.db.list(),o()},n.onerror=()=>{console.error(`Error creating table ${r}:`,n.error),i(n.error)}}catch(t){console.error("Critical error in table.create:",t),i(t)}})});var Z={};var R=l(()=>{"use strict";a();idb.table.size=(e,r)=>new Promise((o,i)=>{if(!e)return i(new Error("Database instance is required"));if(!e.objectStoreNames.contains(r))return o(0);let t=0,s=0,b=e.transaction([r],"readonly").objectStore(r).openCursor();b.onsuccess=async c=>{let g=c.target.result;if(g){try{let f=g.value;t+=JSON.stringify(f).length}catch(f){console.debug("Error stringifying IDB value tracking size:",f)}s++,s%200===0&&await new Promise(f=>setTimeout(f,0)),g.continue()}else o(t)},b.onerror=()=>{i(b.error)}})});var ee={};var N=l(()=>{"use strict";a();idb.data.delete=(e,r,o)=>new Promise((i,t)=>{let s=indexedDB.open(e);s.onsuccess=()=>{let n=s.result;if(!n.objectStoreNames.contains(r))return n.close(),t(new Error(`Table ${r} not found`));let c=n.transaction(r,"readwrite").objectStore(r).delete(o);c.onsuccess=()=>{n.close(),console.debug(`Record ${o} deleted from ${r}`),i()},c.onerror=()=>{n.close(),t(c.error)}},s.onerror=()=>t(s.error)});idb.data.delete.all=(e,r)=>new Promise((o,i)=>{let t=indexedDB.open(e);t.onsuccess=s=>{let n=s.target.result;if(!n.objectStoreNames.contains(r))return n.close(),i(new Error(`Table ${r} not found`));let c=n.transaction(r,"readwrite").objectStore(r).clear();c.onsuccess=()=>{n.close(),console.debug(`All data cleared from ${r}`),o()},c.onerror=()=>{n.close(),i(c.error)}},t.onerror=()=>i(t.error)})});var re={};var C=l(()=>{"use strict";a();idb.data.set=(e,r,o)=>new Promise((i,t)=>{let s=indexedDB.open(e);s.onsuccess=()=>{let n=s.result;if(!n.objectStoreNames.contains(r))return n.close(),t(new Error(`Table ${r} does not exist in ${e}`));let c=n.transaction(r,"readwrite").objectStore(r).put(o);c.onsuccess=()=>{n.close(),console.debug(`Data saved in ${e}.${r}`),i(c.result)},c.onerror=g=>{n.close(),console.debug(`Database insert error: ${c.error?.message}`),t(c.error)}},s.onerror=()=>{t(s.error)}})});var te={};var J=l(()=>{"use strict";a();idb.data.get=(e,r,o)=>new Promise((i,t)=>{let s=indexedDB.open(e);s.onsuccess=n=>{let u=n.target.result;if(!u.objectStoreNames.contains(r))return u.close(),t(new Error(`Table ${r} not found in ${e}`));let g=u.transaction(r,"readonly").objectStore(r).get(o);g.onsuccess=()=>{u.close(),i(g.result)},g.onerror=()=>{u.close(),t(g.error)}},s.onerror=()=>{t(s.error)}})});var V=l(()=>{"use strict";a();(async()=>(Object.defineProperty(globalThis,"idb",{value:{db:{},table:{},data:{}},writable:!0,configurable:!0,enumerable:!1}),Object.defineProperty(globalThis,"idbases",{value:[],writable:!0,configurable:!0,enumerable:!1}),await Promise.all([Promise.resolve().then(()=>(D(),U)),Promise.resolve().then(()=>($(),W)),Promise.resolve().then(()=>(k(),Y)),Promise.resolve().then(()=>(_(),L)),Promise.resolve().then(()=>(I(),K)),Promise.resolve().then(()=>(q(),G)),Promise.resolve().then(()=>(z(),H)),Promise.resolve().then(()=>(A(),Q)),Promise.resolve().then(()=>(B(),X)),Promise.resolve().then(()=>(R(),Z)),Promise.resolve().then(()=>(N(),ee)),Promise.resolve().then(()=>(C(),re)),Promise.resolve().then(()=>(J(),te))]),Object.preventExtensions(idb),Object.seal(idb),Object.freeze(idb)))()});var a=l(()=>{m();v();T();O();S();w();j();x();E();V()});a();
1
+ var __getOwnPropNames=Object.getOwnPropertyNames;var __esm=(fn,res)=>function __init(){return fn&&(res=(0, fn[__getOwnPropNames(fn)[0]])(fn=0)),res};var db_create_exports={};var init_db_create=__esm({"functions/idb/tools/db.create.ts"(){idb.db.create=(dbName,ver=1)=>{return new Promise((resolve,reject)=>{if(!idb.db.support()){return reject(new Error("IndexedDB not supported"))}const request=globalThis.indexedDB.open(dbName,ver);request.onerror=()=>{console.debug(`IndexedDB error: ${request.error?.message}`);reject(request.error);};request.onsuccess=()=>{console.debug(`Database ${dbName} connected successfully`);idb.db.list();resolve(request.result);};request.onupgradeneeded=()=>{console.debug(`Database ${dbName} upgrade/creation initiated`);};})};}});var db_list_exports={};var init_db_list=__esm({"functions/idb/tools/db.list.ts"(){idb.db.list=async()=>{if(!("indexedDB"in globalThis)||!indexedDB.databases)return [];try{const result=await indexedDB.databases();globalThis.idbases=result||[];await idb.db.size();return globalThis.idbases}catch(err){console.error("Error listing databases:",err);return []}};idb.db.list();}});var db_exist_exports={};var init_db_exist=__esm({"functions/idb/tools/db.exist.ts"(){idb.db.exist=storeName=>{return idbases?.some(db=>db.name===storeName)};}});var db_quota_exports={};var init_db_quota=__esm({"functions/idb/tools/db.quota.ts"(){idb.db.quota=()=>{return navigator.storage.estimate()};}});var db_delete_exports={};var init_db_delete=__esm({"functions/idb/tools/db.delete.ts"(){idb.db.delete=storeName=>{return new Promise((resolve,reject)=>{console.debug(`Removing database ${storeName}...`);const performDelete=()=>{const request=indexedDB.deleteDatabase(storeName);request.onsuccess=()=>{console.debug(`${storeName} database removed successfully`);idb.db.list();resolve();};request.onerror=()=>{console.error(`Error removing ${storeName}:`,request.error);reject(request.error);};request.onblocked=()=>{console.warn(`Deletion of ${storeName} is blocked. Please close other tabs.`);};};if(confirm(`Are you sure you want to remove the "${storeName}" database?`)){performDelete();}else {console.debug("Database deletion cancelled by user.");resolve();}})};}});var db_size_exports={};var init_db_size=__esm({"functions/idb/tools/db.size.ts"(){idb.db.size=async()=>{if(!idbases||idbases.length===0)return;for(let i=0;i<idbases.length;i++){const dbInfo=idbases[i];try{const db=await idb.db.create(dbInfo.name,dbInfo.version);const tableNames=Array.from(db.objectStoreNames);let totalDbSize=0;for(const tableName of tableNames){const tableSize=await idb.table.size(db,tableName);totalDbSize+=tableSize;}dbInfo.size=totalDbSize;db.close();}catch(err){console.debug(`Could not calculate size for ${dbInfo.name}:`,err);}}};}});var db_version_exports={};var init_db_version=__esm({"functions/idb/tools/db.version.ts"(){idb.db.version=storeName=>{let idbVer=0;for(const v of idbases){if(v.name===storeName)idbVer=v.version;break}return idbVer};}});var db_support_exports={};var init_db_support=__esm({"functions/idb/tools/db.support.ts"(){idb.db.support=()=>{const isSupported="indexedDB"in globalThis;if(!isSupported){console.debug("Your environment doesn't support IndexedDB");}return isSupported};}});var table_create_exports={};var init_table_create=__esm({"functions/idb/tools/table.create.ts"(){idb.table.create=(dbName,dbTable)=>{return new Promise(async(resolve,reject)=>{try{const currentVersion=Number(idb.db.version(dbName))||0;const nextVersion=currentVersion+1;const request=indexedDB.open(dbName,nextVersion);request.onupgradeneeded=e=>{const db=e.target.result;if(!db.objectStoreNames.contains(dbTable)){const store2=db.createObjectStore(dbTable,{keyPath:"id",autoIncrement:true});store2.createIndex("id","id",{unique:true});store2.createIndex("data","data",{unique:false});console.debug(`Table ${dbTable} created in ${dbName}`);}};request.onsuccess=()=>{request.result.close();idb.db.list();resolve();};request.onerror=()=>{console.error(`Error creating table ${dbTable}:`,request.error);reject(request.error);};}catch(err){console.error("Critical error in table.create:",err);reject(err);}})};}});var table_size_exports={};var init_table_size=__esm({"functions/idb/tools/table.size.ts"(){idb.table.size=(db,table)=>{return new Promise((resolve,reject)=>{if(!db)return reject(new Error("Database instance is required"));if(!db.objectStoreNames.contains(table))return resolve(0);let size=0;let count=0;const transaction=db.transaction([table],"readonly");const store2=transaction.objectStore(table);const request=store2.openCursor();request.onsuccess=async event=>{const cursor=event.target.result;if(cursor){try{const value=cursor.value;size+=JSON.stringify(value).length;}catch(e){console.debug("Error stringifying IDB value tracking size:",e);}count++;if(count%200===0){await new Promise(resolve2=>setTimeout(resolve2,0));}cursor.continue();}else {resolve(size);}};request.onerror=()=>{reject(request.error);};})};}});var data_delete_exports={};var init_data_delete=__esm({"functions/idb/crud/data.delete.ts"(){idb.data.delete=(storeName,table,key)=>{return new Promise((resolve,reject)=>{const request=indexedDB.open(storeName);request.onsuccess=()=>{const db=request.result;if(!db.objectStoreNames.contains(table)){db.close();return reject(new Error(`Table ${table} not found`))}const transaction=db.transaction(table,"readwrite");const objectStore=transaction.objectStore(table);const deleteRequest=objectStore.delete(key);deleteRequest.onsuccess=()=>{db.close();console.debug(`Record ${key} deleted from ${table}`);resolve();};deleteRequest.onerror=()=>{db.close();reject(deleteRequest.error);};};request.onerror=()=>reject(request.error);})};idb.data.delete.all=(storeName,table)=>{return new Promise((resolve,reject)=>{const request=indexedDB.open(storeName);request.onsuccess=event=>{const db=event.target.result;if(!db.objectStoreNames.contains(table)){db.close();return reject(new Error(`Table ${table} not found`))}const transaction=db.transaction(table,"readwrite");const store2=transaction.objectStore(table);const clearRequest=store2.clear();clearRequest.onsuccess=()=>{db.close();console.debug(`All data cleared from ${table}`);resolve();};clearRequest.onerror=()=>{db.close();reject(clearRequest.error);};};request.onerror=()=>reject(request.error);})};}});var data_set_exports={};var init_data_set=__esm({"functions/idb/crud/data.set.ts"(){idb.data.set=(storeName,table,value)=>{return new Promise((resolve,reject)=>{const request=indexedDB.open(storeName);request.onsuccess=()=>{const db=request.result;if(!db.objectStoreNames.contains(table)){db.close();return reject(new Error(`Table ${table} does not exist in ${storeName}`))}const transaction=db.transaction(table,"readwrite");const objectStore=transaction.objectStore(table);const putRequest=objectStore.put(value);putRequest.onsuccess=()=>{db.close();console.debug(`Data saved in ${storeName}.${table}`);resolve(putRequest.result);};putRequest.onerror=e=>{db.close();console.debug(`Database insert error: ${putRequest.error?.message}`);reject(putRequest.error);};};request.onerror=()=>{reject(request.error);};})};}});var data_get_exports={};var init_data_get=__esm({"functions/idb/crud/data.get.ts"(){idb.data.get=(storeName,table,key)=>{return new Promise((resolve,reject)=>{const request=indexedDB.open(storeName);request.onsuccess=event=>{const db=event.target.result;if(!db.objectStoreNames.contains(table)){db.close();return reject(new Error(`Table ${table} not found in ${storeName}`))}const transaction=db.transaction(table,"readonly");const store2=transaction.objectStore(table);const getRequest=store2.get(key);getRequest.onsuccess=()=>{db.close();resolve(getRequest.result);};getRequest.onerror=()=>{db.close();reject(getRequest.error);};};request.onerror=()=>{reject(request.error);};})};}});var package_default={version:"2.6.0"};Object.defineProperty(globalThis,"memorio",{value:{},writable:false,configurable:true,enumerable:false});Object.defineProperty(globalThis,"events",{value:{},writable:true,enumerable:false});Object.defineProperty(memorio,"version",{writable:false,enumerable:false,value:package_default.version});var protect=["list","state","store","idb","observer","useObserver","remove","removeAll"];Object.defineProperty(memorio,"dispatch",{writable:false,enumerable:false,value:{set:(name,value={})=>{globalThis.dispatchEvent(new CustomEvent(String(name),value));},listen:(name,cb=null,flag=false)=>{if(globalThis.observer?.list?.[name]?.length>0)globalThis.observer?.remove?.(name);const exec=cb?e=>setTimeout(()=>cb(e),1):void 0;if(exec)globalThis.addEventListener(name,exec);if(exec)globalThis.events[name]=exec;},remove:name=>{const listener=globalThis.events?.[name];if(listener){globalThis.removeEventListener(name,listener);delete globalThis.events[name];}}}});memorio.propertyName=(container,object)=>{const t=String(object).replace("() => ","");return t};Object.defineProperty(memorio,"objPath",{writable:false,enumerable:false,value:(prop,object,separator=".")=>{const path=object.concat(prop).join(separator);if(globalThis.memorio._tracking){globalThis.memorio._trackedPaths?.add("state."+path);}return path}});globalThis.memorio._tracking=false;globalThis.memorio._trackedPaths=new Set;globalThis.memorio._locked=false;var buildProxy=(obj,callback,tree=[])=>{const event=name=>{try{globalThis.memorio?.dispatch?.set?.(name,{detail:{name}});}catch(e){}return};return new Proxy(obj,{get(target,prop){if(prop==="__path"){return tree.length>0?"state."+tree.join("."):"state"}if(prop==="list"){console.debug('Some state could be hidden when you use "state.list". Use "state" to see the complete list ');return JSON.parse(JSON.stringify(globalThis.state))}if(globalThis.memorio._tracking&&typeof prop==="string"){const path=tree.length>0?"state."+tree.concat(prop).join("."):"state."+prop;globalThis.memorio._trackedPaths?.add(path);}if(prop==="remove"){return key=>{delete target[key];return true}}if(prop==="removeAll"){return ()=>{try{for(const key in target){if(typeof target[key]!=="function"&&!["list","remove","removeAll"].includes(key)){if(!Object.isFrozen(target[key]))delete target[key];delete target[key];}}}catch(error){console.debug(error);}return}}if(Object.isFrozen(target[prop]))return target[prop];if(prop==="lock"||prop==="unlock"){const value=Reflect.get(target,prop);if(value)return value}try{const value=Reflect.get(target,prop);if(value&&typeof value==="object"&&["Array","Object"].includes(value.constructor.name)){return buildProxy(value,callback,tree.concat(prop))}return value}catch(error){console.error("Error: ",error);return void 0}},set(target,key,value){if(globalThis.memorio._locked){console.error("Error: state is locked. Use state.unlock() to enable modifications.");return false}if(protect.includes(key)){console.error("key "+key+" is protected");return false}if(target[key]&&typeof target[key]==="object"&&Object.isFrozen(target[key])){console.error(`Error: state '${key}' is locked`);return false}if(target[key]&&typeof target[key]==="object"&&target[key].__locked){console.error(`Error: state '${key}' is locked. Use state.${key}.unlock() to enable modifications.`);return false}try{const path=globalThis.memorio.objPath?.(key,tree)??key;callback({action:"set",path,target,newValue:value,previousValue:Reflect.get(target,key)});event("state."+path);Reflect.set(target,key,value);if(target[key]&&typeof target[key]==="object"){const rawValue=target[key];if(rawValue&&typeof rawValue==="object"){try{Object.defineProperty(rawValue,"__locked",{writable:true,enumerable:false,configurable:false,value:false});Object.defineProperty(rawValue,"lock",{writable:false,enumerable:false,configurable:false,value:()=>{Object.defineProperty(rawValue,"__locked",{writable:true,enumerable:false,configurable:false,value:true});console.info(`State '${key}' is now locked.`);}});Object.defineProperty(rawValue,"unlock",{writable:false,enumerable:false,configurable:false,value:()=>{Object.defineProperty(rawValue,"__locked",{writable:true,enumerable:false,configurable:false,value:false});console.info(`State '${key}' is now unlocked.`);}});}catch(defineError){}}}return true}catch(error){console.error("Error in set trap:",error);return false}},deleteProperty(target,prop){try{const path=globalThis.memorio.objPath?.(prop,tree);callback({action:"delete",path,target});return Reflect.deleteProperty(target,prop)}catch(error){console.error("Error in deleteProperty trap:",error);return false}},ownKeys(target){return Reflect.ownKeys(target)},getOwnPropertyDescriptor(target,prop){return Reflect.getOwnPropertyDescriptor(target,prop)}})};!globalThis?.state?globalThis.state=buildProxy({},()=>{}):globalThis.state=state;globalThis.state.lock=()=>{globalThis.memorio._locked=true;console.info("State is now locked. All modifications are blocked.");};globalThis.state.unlock=()=>{globalThis.memorio._locked=false;console.info("State is now unlocked. Modifications are allowed.");};Object.defineProperty(globalThis,"state",{enumerable:false,configurable:true});if(!globalThis.observer){globalThis.observer=null;}Object.defineProperty(globalThis,"observer",{enumerable:false,configurable:true});var observerFunction=(s,cb=null,option=true)=>{console.warn('DEPRECATED: "observer" is deprecated and will be removed in future versions. Please use "useObserver" instead.');try{const checkStateOrStore=s2=>{const t=s2.split(".");if(t[0]!=="state"){console.error(`Observer Error: You need to declare 'state.' or 'store.'. The '${s2}' string is incorrect!`);return false}return true};if(!checkStateOrStore(s))return}catch(error){console.error(error);return}if(!s&&!cb){console.error("Observer Error: You need to setup observer correctly, Some parameters are missed!");return}if(!s&&cb){console.error(`Observer Error: You need to declare what state need to be monitored as string like 'state.test'.`);return}if(s&&!cb){const f=({detail:{name:String(s)}});const obs=globalThis.observer;if(obs?.list?.[s])globalThis.memorio.dispatch.remove(f);if(!obs?.list?.[s])globalThis.memorio.dispatch.listen(f);console.debug("called: ",s);return}if(s&&cb){if(typeof s!=="string"||typeof cb!=="function"){console.error(`Observer Error: name of state need to be a 'string' like 'state.test' and the callback need to be a 'function'`);return}const obs=globalThis.observer;if(obs?.list?.[s])globalThis.memorio.dispatch.remove(s,cb,option);if(!obs?.list?.[s])globalThis.memorio.dispatch.listen(s,cb,option);return}};globalThis.observer=observerFunction;Object.defineProperties(globalThis.observer,{list:{get:()=>globalThis.events},remove:{value:name=>{if(!name)return;globalThis.memorio.dispatch.remove(name);delete globalThis.events[name];return}},removeAll:{get:()=>{const obs=globalThis.observer;const list=obs?.list;if(list){Object.keys(list).forEach(key=>{obs?.remove?.(key);});}return true}}});Object.freeze(observer);if(!globalThis.useObserver)globalThis.useObserver=null;Object.defineProperty(globalThis,"useObserver",{value:null,writable:true,enumerable:false,configurable:true});globalThis.useObserver=((func,deps)=>{if(!deps||typeof func!=="function"){return ()=>{}}const handlers=[];const depList=Array.isArray(deps)&&!deps.__path?deps:[deps];try{depList.forEach(dep=>{let t="";if(typeof dep==="function"){const propName=globalThis.memorio.propertyName;if(typeof propName==="function"){const result=propName(globalThis.state,dep);if(result)t=result;}}else if(typeof dep==="object"&&dep!==null){t=dep.__path||(typeof dep.toString==="function"&&dep.toString()!=="[object Object]"?dep.toString():"");}else if(typeof dep==="string"&&(dep.startsWith("state.")||dep.startsWith("store."))){t=dep;}if(t){t=t.replace(/^(\(\)\s*=>\s*)/,"").replace(/^globalThis\./,"").replace(/^state\./,"");const path=t.startsWith("store.")||t.startsWith("state.")?t:"state."+t;globalThis.memorio.dispatch.listen(path,()=>func());handlers.push(path);}else {globalThis.memorio._trackedPaths?.clear();globalThis.memorio._tracking=true;try{func();}catch(e){}globalThis.memorio._tracking=false;globalThis.memorio._trackedPaths?.forEach(path=>{if(!handlers.includes(path)){console.info(`useObserver: [Auto-Discovery] -> "${path}"`);globalThis.memorio.dispatch.listen(path,()=>func());handlers.push(path);}});}});if(handlers.length>0){console.info(`useObserver: Monitoring ${handlers.length} paths.`);}else {console.warn(`useObserver: No paths resolved for monitoring. Check your dependencies!`);}return ()=>{handlers.forEach(path=>{if(globalThis.memorio.dispatch&&typeof globalThis.memorio.dispatch.remove==="function"){globalThis.memorio.dispatch.remove(path);console.debug(`useObserver: Stopped monitoring "${path}"`);}});}}catch(err){console.debug("useObserver Error:",err);return ()=>{}}});Object.freeze(globalThis.useObserver);Object.defineProperty(globalThis,"store",{value:new Proxy({},{}),enumerable:false,configurable:true});Object.defineProperties(store,{get:{value:name=>{if(!name)return;try{const item=globalThis.localStorage.getItem(name);if(item)return JSON.parse(item);return item}catch(err){console.debug(`Error parsing store item '${name}':`,err);}return null}},set:{value:(name,value)=>{if(!name)return;try{if(value===null||value===void 0)globalThis.localStorage.setItem(name,JSON.stringify(null));else if(typeof value==="object"||typeof value==="number"||typeof value==="boolean"||typeof value==="string")globalThis.localStorage.setItem(name,JSON.stringify(value));else if(typeof value==="function")console.debug("It's not secure to store functions.");}catch(err){console.debug(`Error setting store item '${name}':`,err);}return null}},remove:{value:name=>{if(!name)return;if(globalThis.localStorage.getItem(name)){globalThis.localStorage.removeItem(name);return true}return false}},delete:{value:name=>{store.remove(name);return true}},removeAll:{value:()=>{globalThis.localStorage.clear();return true}},clearAll:{value:()=>{store.removeAll();return true}},quota:{value:async()=>{if(globalThis.navigator&&"storage"in globalThis.navigator&&"estimate"in globalThis.navigator.storage){return globalThis.navigator.storage.estimate().then(({usage,quota})=>{const u=usage??0;const q=quota??0;if(u&&q)console.debug(`Using ${u/1024} out of ${q/1024} Mb.`);return [u/1024,q/1024]}).catch(err=>{console.debug("Error estimating quota:",err);return [0,0]})}return [0,0]}},size:{value:()=>{let totalSize=0;Object.keys(globalThis.localStorage).forEach(key=>{const item=globalThis.localStorage.getItem(key);if(item)totalSize+=item.length;});return totalSize}}});Object.freeze(store);Object.defineProperty(globalThis,"session",{value:new Proxy({},{}),enumerable:false,configurable:true});Object.defineProperties(session,{get:{value:name=>{if(!name)return;try{const item=globalThis.sessionStorage.getItem(name);if(item)return JSON.parse(item);return item}catch(err){console.debug(`Error parsing session item '${name}':`,err);}return}},set:{value:(name,value)=>{if(!name)return;try{if(value===null||value===void 0)globalThis.sessionStorage.setItem(name,JSON.stringify(null));else if(typeof value==="object"||typeof value==="number"||typeof value==="boolean"||typeof value==="string")globalThis.sessionStorage.setItem(name,JSON.stringify(value));else if(typeof value==="function")console.debug("It's not secure to session functions.");}catch(err){console.debug(`Error setting session item '${name}':`,err);}return}},remove:{value:name=>{if(!name)return;if(globalThis.sessionStorage.getItem(name)){globalThis.sessionStorage.removeItem(name);return true}return}},delete:{value:name=>{session.remove(name);return true}},removeAll:{value:()=>{globalThis.sessionStorage.clear();return true}},clearAll:{value:()=>{session.removeAll();return true}},quota:{value:async()=>{if(globalThis.navigator&&"storage"in globalThis.navigator&&"estimate"in globalThis.navigator.storage){return globalThis.navigator.storage.estimate().then(({usage,quota})=>{const u=usage??0;const q=quota??0;if(u&&q)console.debug(`Using ${u/1024} out of ${q/1024} Mb.`);return [u/1024,q/1024]}).catch(err=>{console.debug("Error estimating quota:",err);return [0,0]})}return [0,0]}},size:{value:()=>{let totalSize=0;Object.keys(globalThis.sessionStorage).forEach(key=>{const item=globalThis.sessionStorage.getItem(key);if(item)totalSize+=item.length;});return totalSize}}});Object.freeze(session);var cacheData={};Object.defineProperty(globalThis,"cache",{value:new Proxy({},{get(target,prop){const key=prop;if(key==="get")return name=>cacheData[name];if(key==="set")return (name,value)=>{cacheData[name]=value;};if(key==="remove")return name=>{delete cacheData[name];return true};if(key==="removeAll")return ()=>{Object.keys(cacheData).forEach(k=>delete cacheData[k]);return true};if(key==="clear")return ()=>{Object.keys(cacheData).forEach(k=>delete cacheData[k]);return true};return cacheData[key]},set(target,prop,value){cacheData[prop]=value;return true},deleteProperty(target,prop){delete cacheData[prop];return true}}),enumerable:false,configurable:true});Object.freeze(cache);(async()=>{Object.defineProperty(globalThis,"idb",{value:{db:{},table:{},data:{}},writable:true,configurable:true,enumerable:false});Object.defineProperty(globalThis,"idbases",{value:[],writable:true,configurable:true,enumerable:false});await Promise.all([Promise.resolve().then(()=>(init_db_create(),db_create_exports)),Promise.resolve().then(()=>(init_db_list(),db_list_exports)),Promise.resolve().then(()=>(init_db_exist(),db_exist_exports)),Promise.resolve().then(()=>(init_db_quota(),db_quota_exports)),Promise.resolve().then(()=>(init_db_delete(),db_delete_exports)),Promise.resolve().then(()=>(init_db_size(),db_size_exports)),Promise.resolve().then(()=>(init_db_version(),db_version_exports)),Promise.resolve().then(()=>(init_db_support(),db_support_exports)),Promise.resolve().then(()=>(init_table_create(),table_create_exports)),Promise.resolve().then(()=>(init_table_size(),table_size_exports)),Promise.resolve().then(()=>(init_data_delete(),data_delete_exports)),Promise.resolve().then(()=>(init_data_set(),data_set_exports)),Promise.resolve().then(()=>(init_data_get(),data_get_exports))]);Object.preventExtensions(idb);Object.seal(idb);Object.freeze(idb);})();
package/package.json CHANGED
@@ -1,77 +1,79 @@
1
- {
2
- "name": "memorio",
3
- "version": "2.5.3",
4
- "type": "module",
5
- "private": false,
6
- "main": "index.js",
7
- "license": "MIT",
8
- "typings": "./types/*",
9
- "description": "Memorio, State + Observer and Store for an easy life",
10
- "copyright": "Copyright (c) 2025 Dario Passariello",
11
- "homepage": "https://a51.gitbook.io/memorio",
12
- "author": {
13
- "name": "Dario Passariello",
14
- "url": "https://dario.passariello.ca/",
15
- "email": "dariopassariello@gmail.com"
16
- },
17
- "support": {
18
- "name": "Dario Passariello",
19
- "url": "https://github.com/passariello/",
20
- "email": "dariopassariello@gmail.com"
21
- },
22
- "contributors": [
23
- {
24
- "name": "Dario Passariello",
25
- "email": "dariopassarielloa@gmail.com"
26
- },
27
- {
28
- "name": "Valeria Cala Scaglitta",
29
- "email": "valeriacalascaglitta@gmail.com"
30
- }
31
- ],
32
- "keywords": [
33
- "biglogic",
34
- "a51",
35
- "memorio",
36
- "state",
37
- "store",
38
- "observer",
39
- "useObserver",
40
- "dario",
41
- "passariello"
42
- ],
43
- "funding": [
44
- {
45
- "type": "patreon",
46
- "url": "https://www.patreon.com/passariello"
47
- }
48
- ],
49
- "typing": [
50
- "types/*"
51
- ],
52
- "exports": {
53
- ".": {
54
- "types": "./types/index.d.ts",
55
- "import": "./index.js",
56
- "default": "./index.js"
57
- },
58
- "./types/*": "./types/*"
59
- },
60
- "scripts": {
61
- "build": "rimraf dist && node ./esbuild.config.mjs",
62
- "watch": "rimraf dist && nodemon --watch * --exec \"npm run build \"",
63
- "npm:publish": "npm run build && npm publish ./dist",
64
- "test": "cd tests && npm run test",
65
- "lint": "cd tests && npm run lint",
66
- "tsc": "tsc --noEmit"
67
- },
68
- "devDependencies": {
69
- "@types/node": "25.3.3",
70
- "esbuild": "0.27.3",
71
- "esbuild-node-externals": "1.20.1",
72
- "esbuild-plugin-alias": "0.2.1",
73
- "esbuild-plugin-copy": "2.1.1",
74
- "rimraf": "6.1.3",
75
- "typescript": "5.9.3"
76
- }
77
- }
1
+ {
2
+ "name": "memorio",
3
+ "version": "2.6.0",
4
+ "description": "Memorio, State + Observer, Store and iDB for an easy life",
5
+ "main": "./index.cjs",
6
+ "browser": "./index.cjs",
7
+ "types": "./index.d.ts",
8
+ "typing": "./types/*",
9
+ "homepage": "https://a51.gitbook.io/memorio",
10
+ "license": "MIT",
11
+ "copyright": "Dario Passariello",
12
+ "author": "Dario Passariello",
13
+ "contributors": [
14
+ {
15
+ "name": "Dario Passariello",
16
+ "email": "dariopassarielloa@gmail.com"
17
+ },
18
+ {
19
+ "name": "Valeria Cala Scaglitta",
20
+ "email": "valeriacalascaglitta@gmail.com"
21
+ }
22
+ ],
23
+ "keywords": [
24
+ "elements",
25
+ "ui",
26
+ "ux",
27
+ "inputs",
28
+ "buttons",
29
+ "frontend",
30
+ "gui",
31
+ "styles",
32
+ "customization"
33
+ ],
34
+ "funding": [
35
+ {
36
+ "type": "patreon",
37
+ "url": "https://www.patreon.com/passariello"
38
+ }
39
+ ],
40
+ "engines": {
41
+ "node": ">=18.0.0"
42
+ },
43
+ "files": [
44
+ "**/*"
45
+ ],
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "git+https://github.com/a51-dev/a51.memorio.git"
49
+ },
50
+ "bugs": {
51
+ "url": "https://github.com/a51-dev/a51.memorio/issues"
52
+ },
53
+ "support": {
54
+ "name": "Dario Passariello",
55
+ "url": "https://dario.passariello.ca/",
56
+ "email": "dariopassariello@gmail.com"
57
+ },
58
+ "peerDependenciesMeta": {
59
+ "react": {
60
+ "optional": false
61
+ },
62
+ "react-dom": {
63
+ "optional": false
64
+ },
65
+ "jquery": {
66
+ "optional": false
67
+ }
68
+ },
69
+ "module": "./index.js",
70
+ "exports": {
71
+ ".": {
72
+ "import": "./index.js",
73
+ "require": "./index.cjs",
74
+ "types": "./index.d.ts"
75
+ },
76
+ "./types/*": "./types/*"
77
+ },
78
+ "typings": "./index.d.ts"
79
+ }
@@ -61,4 +61,12 @@ globalThis.events = globalThis.events || {}
61
61
  // Initialize idbases if not exists
62
62
  globalThis.idbases = globalThis.idbases || []
63
63
 
64
+ interface Window {
65
+ [key: string]: any
66
+ }
67
+
68
+ interface globalThis {
69
+ [key: string]: any
70
+ }
71
+
64
72
  export { }