memorio 2.5.2 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Copyright
2
2
 
3
- Copyright (c) 2026, Dario Passariello. All rights reserved.
3
+ Copyright (c) 2025, Dario Passariello. All rights reserved.
4
4
  <https://dario.passariello.ca>
5
5
 
6
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
 
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Memorio Basic Example
3
+ *
4
+ * This example shows the fundamental features of Memorio:
5
+ * - State management
6
+ * - Store (localStorage)
7
+ * - Session storage
8
+ *
9
+ * Run: npx ts-node examples/basic.ts
10
+ */
11
+
12
+ import '../index'
13
+
14
+ // ============================================
15
+ // STATE - In-memory reactive state
16
+ // ============================================
17
+
18
+ // Set some state values
19
+ state.name = 'Mario'
20
+ state.age = 30
21
+ state.isActive = true
22
+ state.profile = {
23
+ email: 'mario@example.com',
24
+ avatar: 'https://example.com/mario.png'
25
+ }
26
+
27
+ // Get state values
28
+ console.log('Name:', state.name)
29
+ console.log('Age:', state.age)
30
+ console.log('Profile:', state.profile)
31
+
32
+ // List all states
33
+ console.log('All states:', state.list)
34
+
35
+ // ============================================
36
+ // STORE - Persistent localStorage
37
+ // ============================================
38
+
39
+ // Save to localStorage
40
+ store.set('username', 'mario')
41
+ store.set('preferences', { theme: 'dark', language: 'en' })
42
+ store.set('lastLogin', Date.now())
43
+
44
+ // Read from localStorage
45
+ console.log('Username:', store.get('username'))
46
+ console.log('Preferences:', store.get('preferences'))
47
+
48
+ // Get storage size
49
+ console.log('Storage size:', store.size(), 'bytes')
50
+
51
+ // ============================================
52
+ // SESSION - Temporary session storage
53
+ // ============================================
54
+
55
+ // Save session data (cleared when tab closes)
56
+ session.set('token', 'abc123xyz')
57
+ session.set('userId', 42)
58
+
59
+ // Read session data
60
+ console.log('Token:', session.get('token'))
61
+ console.log('User ID:', session.get('userId'))
62
+
63
+ // ============================================
64
+ // CLEANUP
65
+ // ============================================
66
+
67
+ // Clear specific items
68
+ store.remove('username')
69
+ session.remove('token')
70
+
71
+ // Clear all
72
+ store.removeAll()
73
+ session.removeAll()
74
+
75
+ console.log('Example complete!')
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Memorio Cache Example
3
+ *
4
+ * This example demonstrates the cache module for in-memory storage.
5
+ * Cache is perfect for temporary data that doesn't need persistence.
6
+ *
7
+ * Run: npx ts-node examples/cache.ts
8
+ */
9
+
10
+ import '../index'
11
+
12
+ // ============================================
13
+ // BASIC CACHE OPERATIONS
14
+ // ============================================
15
+
16
+ // Set values
17
+ cache.set('username', 'Mario')
18
+ cache.set('score', 1500)
19
+ cache.set('player', { name: 'Mario', level: 5 })
20
+
21
+ // Get values
22
+ console.log('Username:', cache.get('username'))
23
+ console.log('Score:', cache.get('score'))
24
+ console.log('Player:', cache.get('player'))
25
+
26
+ // Direct property access
27
+ cache.tempData = 'Hello'
28
+ console.log('Temp data:', cache.tempData)
29
+
30
+ // ============================================
31
+ // CACHE WITH OBJECTS
32
+ // ============================================
33
+
34
+ // Store complex objects
35
+ cache.set('gameState', {
36
+ level: 3,
37
+ score: 2500,
38
+ inventory: ['sword', 'shield', 'potion'],
39
+ position: { x: 100, y: 200 }
40
+ })
41
+
42
+ const gameState = cache.get('gameState')
43
+ console.log('Game level:', gameState?.level)
44
+ console.log('Inventory:', gameState?.inventory)
45
+
46
+ // ============================================
47
+ // CACHE SIZE
48
+ // ============================================
49
+
50
+ // Add multiple items
51
+ for (let i = 0; i < 10; i++) {
52
+ cache.set(`item_${i}`, { id: i, data: `item-${i}` })
53
+ }
54
+
55
+ console.log('Cache keys:', Object.keys(cache))
56
+
57
+ // ============================================
58
+ // CLEANUP
59
+ // ============================================
60
+
61
+ // Remove single item
62
+ cache.remove('username')
63
+
64
+ // Clear all cache
65
+ cache.removeAll()
66
+
67
+ // Or use clearAll alias
68
+ // cache.clearAll()
69
+
70
+ console.log('Cache after clear:', cache.get('score'))
71
+
72
+ console.log('Cache example complete!')
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Memorio IDB Example
3
+ *
4
+ * This example shows how to use IndexedDB for large data storage.
5
+ * IDB is perfect for caching, offline data, and large datasets.
6
+ *
7
+ * Run: npx ts-node examples/idb.ts
8
+ */
9
+
10
+ import '../index'
11
+
12
+ // ============================================
13
+ // CHECK SUPPORT
14
+ // ============================================
15
+
16
+ if (!idb.db.support()) {
17
+ console.log('IndexedDB not supported')
18
+ process.exit(0)
19
+ }
20
+
21
+ // ============================================
22
+ // CREATE DATABASE
23
+ // ============================================
24
+
25
+ // Create a new database
26
+ idb.db.create('myApp')
27
+
28
+ // Create tables (stores)
29
+ idb.table.create('myApp', 'users')
30
+ idb.table.create('myApp', 'products')
31
+
32
+ // ============================================
33
+ // ADD DATA
34
+ // ============================================
35
+
36
+ // Add user records
37
+ idb.data.set('myApp', 'users', {
38
+ id: 1,
39
+ name: 'Mario',
40
+ email: 'mario@example.com',
41
+ role: 'admin'
42
+ })
43
+
44
+ idb.data.set('myApp', 'users', {
45
+ id: 2,
46
+ name: 'Luigi',
47
+ email: 'luigi@example.com',
48
+ role: 'user'
49
+ })
50
+
51
+ // Add product records
52
+ idb.data.set('myApp', 'products', {
53
+ id: 1,
54
+ name: 'Super Mushroom',
55
+ price: 99,
56
+ inStock: true
57
+ })
58
+
59
+ idb.data.set('myApp', 'products', {
60
+ id: 2,
61
+ name: 'Fire Flower',
62
+ price: 199,
63
+ inStock: true
64
+ })
65
+
66
+ // ============================================
67
+ // READ DATA
68
+ // ============================================
69
+
70
+ const user1 = idb.data.get('myApp', 'users', 1)
71
+ console.log('User 1:', user1)
72
+
73
+ const product1 = idb.data.get('myApp', 'products', 1)
74
+ console.log('Product 1:', product1)
75
+
76
+ // ============================================
77
+ // DATABASE INFO
78
+ // ============================================
79
+
80
+ // List all databases
81
+ const databases = idb.db.list()
82
+ console.log('Databases:', databases)
83
+
84
+ // Check if database exists
85
+ const exists = idb.db.exist('myApp')
86
+ console.log('myApp exists:', exists)
87
+
88
+ // Get database version
89
+ const version = idb.db.version('myApp')
90
+ console.log('myApp version:', version)
91
+
92
+ // Get database size
93
+ const size = idb.db.size('myApp')
94
+ console.log('myApp size:', size, 'bytes')
95
+
96
+ // ============================================
97
+ // DELETE DATA
98
+ // ============================================
99
+
100
+ // Delete a record
101
+ idb.data.delete('myApp', 'users', 1)
102
+
103
+ // Delete entire table
104
+ // idb.table.delete('myApp', 'users');
105
+
106
+ // Delete entire database
107
+ // idb.db.delete('myApp');
108
+
109
+ console.log('IDB example complete!')
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Memorio Observer Example
3
+ *
4
+ * This example demonstrates the observer pattern for reactive state changes.
5
+ * Perfect for logging, analytics, auto-save, and UI updates.
6
+ *
7
+ * Run: npx ts-node examples/observer.ts
8
+ */
9
+
10
+ import '../index'
11
+
12
+ // ============================================
13
+ // SIMPLE OBSERVER
14
+ // ============================================
15
+
16
+ // Watch a single value
17
+ observer('state.counter', (newValue, oldValue) => {
18
+ console.log(`Counter: ${oldValue} → ${newValue}`)
19
+ })
20
+
21
+ state.counter = 0
22
+ state.counter = 1
23
+ state.counter = 2
24
+
25
+ // ============================================
26
+ // OBJECT OBSERVER
27
+ // ============================================
28
+
29
+ // Watch entire objects
30
+ observer('state.user', (newUser, oldUser) => {
31
+ console.log(`User changed: ${oldUser?.name} → ${newUser?.name}`)
32
+ })
33
+
34
+ state.user = { name: 'Mario', level: 1 }
35
+ state.user = { name: 'Luigi', level: 2 }
36
+
37
+ // ============================================
38
+ // MULTIPLE OBSERVERS
39
+ // ============================================
40
+
41
+ // Multiple observers on same path
42
+ observer('state.notifications', (count) => {
43
+ console.log(`New notification count: ${count}`)
44
+ })
45
+
46
+ // List all observers
47
+ console.log('Active observers:', observer.list)
48
+
49
+ // ============================================
50
+ // CLEANUP
51
+ // ============================================
52
+
53
+ // Remove specific observer
54
+ observer.remove('state.counter')
55
+
56
+ // Remove all observers - call remove for each path
57
+ // observer.remove('state.counter')
58
+ // observer.remove('state.notifications')
59
+
60
+ console.log('Observer example complete!')
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Memorio Session Advanced Example
3
+ *
4
+ * This example shows advanced session (sessionStorage) operations.
5
+ * Session data is cleared when the browser tab closes.
6
+ *
7
+ * Run: npx ts-node examples/session-advanced.ts
8
+ */
9
+
10
+ import '../index'
11
+
12
+ // ============================================
13
+ // AUTHENTICATION
14
+ // ============================================
15
+
16
+ // Store auth token (temporary - cleared when tab closes)
17
+ session.set('authToken', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...')
18
+ session.set('userId', 12345)
19
+
20
+ // Check if user is logged in
21
+ const token = session.get('authToken')
22
+ if (token) {
23
+ console.log('User is logged in, token:', token.substring(0, 20) + '...')
24
+ }
25
+
26
+ // ============================================
27
+ // FORM PROGRESS
28
+ // ============================================
29
+
30
+ // Save form draft
31
+ session.set('formDraft', {
32
+ name: 'Mario',
33
+ email: 'mario@example.com',
34
+ message: 'Hello world!'
35
+ })
36
+
37
+ // Restore on page refresh
38
+ const draft = session.get('formDraft')
39
+ if (draft) {
40
+ console.log('Restored draft:', draft)
41
+ }
42
+
43
+ // ============================================
44
+ // SHOPPING CART
45
+ // ============================================
46
+
47
+ // Store cart items (temporary)
48
+ session.set('cart', [
49
+ { id: 1, name: 'Super Mushroom', price: 99, qty: 2 },
50
+ { id: 2, name: 'Fire Flower', price: 199, qty: 1 }
51
+ ])
52
+
53
+ // Calculate total
54
+ const cart = session.get('cart') || []
55
+ const total = cart.reduce((sum, item) => sum + (item.price * item.qty), 0)
56
+ console.log('Cart total:', total)
57
+
58
+ // ============================================
59
+ // SESSION SIZE
60
+ // ============================================
61
+
62
+ // Get session storage size
63
+ console.log('Session size:', session.size(), 'bytes')
64
+
65
+ // ============================================
66
+ // CLEANUP
67
+ // ============================================
68
+
69
+ // Remove specific item
70
+ session.remove('formDraft')
71
+
72
+ // Clear all session data (logout)
73
+ // session.removeAll()
74
+
75
+ // Or use alias
76
+ // session.clearAll()
77
+
78
+ console.log('Session advanced example complete!')