{"_id":"@atoapayments/pinia-store-lifecycle-manager","_rev":"4-13fb358f19e2326fe437ae14e620b01f","name":"@atoapayments/pinia-store-lifecycle-manager","dist-tags":{"latest":"0.0.2"},"versions":{"0.0.1":{"name":"@atoapayments/pinia-store-lifecycle-manager","version":"0.0.1","keywords":["pinia","vue","store","lifecycle","management"],"author":{"name":"Tushar gupta"},"license":"MIT","_id":"@atoapayments/pinia-store-lifecycle-manager@0.0.1","maintainers":[{"name":"tushargupta224","email":"tushar@paywithatoa.co.uk"},{"name":"rvkrish","email":"vamsi@paywithatoa.co.uk"},{"name":"atoalicence","email":"licence@paywithatoa.co.uk"}],"dist":{"shasum":"897a764654e826ed9cc7ad31cb5b3cebc92c4a03","tarball":"https://registry.npmjs.org/@atoapayments/pinia-store-lifecycle-manager/-/pinia-store-lifecycle-manager-0.0.1.tgz","fileCount":6,"integrity":"sha512-A4VyDkgVrGUegrZgSd4/kof0QbWJOal8tb0CZBiUUJQrkvnCaSy3WZeef4B4aCMKS+PasYEdGeVIpa6VwoUTLw==","signatures":[{"sig":"MEYCIQD8aqrvQnogk39s01uf1jxVWuCtBy2/KRkrOzEw9tqBQwIhANKQqDkAVO49dxGj839OKvRezCDQQ4+DGZZei44Wplcb","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":38758},"main":"dist/index.js","type":"module","types":"dist/index.d.ts","gitHead":"4cc45d14304d388075665cc2063ed883f4a6c09d","scripts":{"dev":"tsup src/index.ts --format cjs,esm --dts --watch","lint":"eslint src/**/*.ts","build":"tsup src/index.ts --format cjs,esm --dts","clean":"rm -rf dist","prepublishOnly":"npm run clean && npm run build"},"_npmUser":{"name":"atoalicence","email":"licence@paywithatoa.co.uk"},"_npmVersion":"10.8.2","description":"A Pinia plugin for managing store lifecycle, including state resets and refreshes","directories":{},"_nodeVersion":"20.17.0","_hasShrinkwrap":false,"devDependencies":{"vue":"^3.5.9","tsup":"^8.3.0","pinia":"^2.2.2","eslint":"^9.11.1","typescript":"^5.6.2","@types/node":"^22.7.4","@typescript-eslint/parser":"^8.7.0","@typescript-eslint/eslint-plugin":"^8.7.0"},"peerDependencies":{"vue":"^3.0.0","pinia":"^2.0.0"},"peerDependenciesMeta":{"vue":{"optional":false},"pinia":{"optional":false}},"_npmOperationalInternal":{"tmp":"tmp/pinia-store-lifecycle-manager_0.0.1_1728053522848_0.4038183324601492","host":"s3://npm-registry-packages"}},"0.0.2":{"name":"@atoapayments/pinia-store-lifecycle-manager","version":"0.0.2","keywords":["pinia","vue","store","lifecycle","management"],"author":{"name":"Tushar gupta"},"license":"MIT","_id":"@atoapayments/pinia-store-lifecycle-manager@0.0.2","maintainers":[{"name":"tushargupta224","email":"tushar@paywithatoa.co.uk"},{"name":"rvkrish","email":"vamsi@paywithatoa.co.uk"},{"name":"atoalicence","email":"licence@paywithatoa.co.uk"}],"homepage":"https://github.com/ATOAPaymentsLimited/pinia-store-lifecycle-manager#readme","bugs":{"url":"https://github.com/ATOAPaymentsLimited/pinia-store-lifecycle-manager/issues","email":"vamsi@paywithatoa.co.uk"},"dist":{"shasum":"df5c5ec0b54519f15a418aa628f8f0282e3327a1","tarball":"https://registry.npmjs.org/@atoapayments/pinia-store-lifecycle-manager/-/pinia-store-lifecycle-manager-0.0.2.tgz","fileCount":10,"integrity":"sha512-H+hbwQu/4fXdl6Cc88THUxMSe6MRF9xC90IcFewLYRCeqaxs9aT4BgoWRn8OZuxW/Hnzn/2aGOQVQ+V+EDM/Gg==","signatures":[{"sig":"MEUCIQCqP9g91hx9YZrn/qaWuhInB67xfhMJJDoUP9LyyzjRaQIgBDehfCYHSrfZKs1FYDpNWo85lCU13JjpZ6+AyzXwzaw=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":37287},"main":"dist/index.js","type":"module","types":"dist/index.d.ts","gitHead":"4490fd7c97d315ef47ae046cd73738e7b1f3c655","scripts":{"dev":"tsup src/index.ts --format cjs,esm --dts --watch","lint":"eslint src/**/*.ts","build":"tsup src/index.ts --format cjs,esm --minify --treeshake --dts","clean":"rm -rf dist","gzipper":"gzipper compress ./dist --include cjs,cts,js,ts,d.ts","prepublishOnly":"npm run clean && npm run build && npm run gzipper"},"_npmUser":{"name":"atoalicence","email":"licence@paywithatoa.co.uk"},"repository":{"url":"git+https://github.com/ATOAPaymentsLimited/pinia-store-lifecycle-manager.git","type":"git"},"_npmVersion":"10.8.2","description":"A Pinia plugin for managing store lifecycle, including state resets and refreshes","directories":{},"_nodeVersion":"20.17.0","_hasShrinkwrap":false,"devDependencies":{"vue":"^3.5.9","tsup":"^8.3.0","pinia":"^2.2.2","eslint":"^9.11.1","gzipper":"^7.2.0","typescript":"^5.6.2","@types/node":"^22.7.4","@typescript-eslint/parser":"^8.7.0","@typescript-eslint/eslint-plugin":"^8.7.0"},"peerDependencies":{"vue":"^3.0.0","pinia":"^2.0.0"},"peerDependenciesMeta":{"vue":{"optional":false},"pinia":{"optional":false}},"_npmOperationalInternal":{"tmp":"tmp/pinia-store-lifecycle-manager_0.0.2_1728117236593_0.5426854914933277","host":"s3://npm-registry-packages"}}},"time":{"created":"2024-10-04T14:52:02.768Z","modified":"2026-03-05T06:19:51.665Z","0.0.1":"2024-10-04T14:52:03.031Z","0.0.2":"2024-10-05T08:33:56.777Z"},"bugs":{"url":"https://github.com/ATOAPaymentsLimited/pinia-store-lifecycle-manager/issues","email":"vamsi@paywithatoa.co.uk"},"author":{"name":"Tushar gupta"},"license":"MIT","homepage":"https://github.com/ATOAPaymentsLimited/pinia-store-lifecycle-manager#readme","keywords":["pinia","vue","store","lifecycle","management"],"repository":{"url":"git+https://github.com/ATOAPaymentsLimited/pinia-store-lifecycle-manager.git","type":"git"},"description":"A Pinia plugin for managing store lifecycle, including state resets and refreshes","maintainers":[{"email":"sharique@paywithatoa.co.uk","name":"shariqueatoa"},{"email":"vamsi@paywithatoa.co.uk","name":"rvkrish"},{"email":"tushar@paywithatoa.co.uk","name":"tushargupta224"},{"email":"licence@paywithatoa.co.uk","name":"atoalicence"},{"email":"tanushree@paywithatoa.co.uk","name":"anandtanu"}],"readme":"<p align=\"center\">\n  <a href=\"https://www.npmjs.org/package/@atoapayments/pinia-store-lifecycle-manager\"><img src=\"https://img.shields.io/npm/v/@atoapayments/pinia-store-lifecycle-manager.svg\" alt=\"npm\"></a>\n  <a href=\"https://unpkg.com/@atoapayments/pinia-store-lifecycle-manager/dist/index.js\"><img src=\"https://img.badgesize.io/https://unpkg.com/@atoapayments/pinia-store-lifecycle-manager/dist/index.js?compression=gzip\" alt=\"gzip size\"></a>\n</p>\n\n# Pinia Store Lifecycle Manager\n\nA robust Pinia plugin designed to manage store lifecycles seamlessly, including state resets and refreshes. Enhance your Vue applications with streamlined state management tailored for dynamic development needs.\n\n## Table of Contents\n- [Installation](#installation)\n- [Usage](#usage)\n  - [Basic Setup](#basic-setup)\n  - [Advanced Configuration](#advanced-configuration)\n- [Features](#features)\n- [Use Cases](#use-cases)\n- [API Reference](#api-reference)\n- [Why Choose Pinia Store Lifecycle Manager](#why-choose-pinia-store-lifecycle-manager)\n- [License](#license)\n\n## Installation\n\nYou can install the Pinia Store Lifecycle Manager using npm or Yarn:\n\n```bash\nnpm install @atoapayments/pinia-store-lifecycle-manager\n# or\nyarn add @atoapayments/pinia-store-lifecycle-manager\n```\n\n## Usage\n\n### Basic Setup\n\n```typescript\n//vue\nimport { createPinia } from \"pinia\";\nimport { PiniaStoreLifecycleManager } from \"pinia-store-lifecycle-manager\";\n\nconst pinia = createPinia();\npinia.use((context) => {\n  PiniaStoreLifecycleManager(context, (lifecycleEvents) => {\n    // Register your lifecycle event handlers here\n    // For example:\n    // lifecycleEvents.reset();\n    // lifecycleEvents.reconfigure();\n    // lifecycleEvents.refresh({ mode: 'full' });\n  });\n});\n```\n\n#### Nuxt\n\n```typescript\n// \\plugin\\pinia-store-lifecycle-manager.ts\nimport type { Pinia } from \"pinia\";\nimport { PiniaStoreLifecycleManager } from \"pinia-store-lifecycle-manager\";\n\nexport default defineNuxtPlugin(({ $pinia }) => {\n  ($pinia as Pinia).use((pluginContext) => {\n    return PiniaStoreLifecycleManager(\n      pluginContext,\n      (lifecycleEvents) => {\n        // Use event listeners of your choice\n        const { $listen } = useNuxtApp();\n\n        // Register event listeners\n        $listen(\"user:logOut\", () => {\n          lifecycleEvents.reset();\n        });\n        $listen(\"user:switchProfile\", () => {\n          // Reset the store and perform a full refresh when switching profile\n          lifecycleEvents.reset();\n          lifecycleEvents.refresh({\n            mode: \"full\",\n            includeResetOnlyActions: true,\n          });\n        });\n        $listen(\"user:anyEvent\", () => {\n          // Reconfigure the store and perform a partial refresh\n          lifecycleEvents.reconfigure();\n          lifecycleEvents.refresh({ mode: \"partial\" });\n        });\n      },\n      {\n        enableDebugLogs: __DEV__,\n      }\n    );\n  });\n});\n\n```\n\n### Advanced Configuration\n\n```typescript\nimport { createPinia } from \"pinia\";\nimport { PiniaStoreLifecycleManager } from \"pinia-store-lifecycle-manager\";\n\nconst pinia = createPinia();\npinia.use((context) => {\n  PiniaStoreLifecycleManager(\n    context,\n    (lifecycleEvents) => {\n      // Define custom lifecycle event handlers\n    },\n    {\n      enableDebugLogs: true,\n      enableSSR: false,\n      disableAutoRegister: false,\n    }\n  );\n});\n```\n\n## Features\n\n- **State Reset:** Easily reset the store to its initial state.\n- **Reconfiguration:** Update multiple store properties simultaneously.\n- **Data Refresh:** Refresh store data by invoking specified actions.\n- **Debug Logging:** Enable detailed logging for lifecycle events and actions.\n- **SSR Support:** Compatible with server-side rendering setups.\n\n## Use Cases\n\n- **User Authentication:** Reset store states upon user logout.\n- **Dynamic Configuration:** Reconfigure store settings based on different environments.\n- **Real-time Data Management:** Refresh store data in response to real-time events.\n- **State Management Optimization:** Streamline complex state transitions.\n\n## API Reference\n\n### Lifecycle Options\n\n```typescript\ninterface DefineStoreOptionsBase<S extends StateTree, Store> {\n  lifecycleOptions?: {\n    clean?: CleanOptions<Store> | CleanFunction<Store> | (() => CleanOptions<Store> | void);\n    reConfigure?: ReconfigureOptions<Store> | ReconfigureFunction<Store> | (() => ReconfigureOptions<Store> | void);\n    refresh?: RefreshOptions<Store> | RefreshFunction<Store> | (() => RefreshOptions<Store> | void);\n    disableListener?: boolean;\n  };\n}\n```\n\n#### Clean and Reconfigure\n\nBoth `clean` and `reConfigure` can be defined as an object, a function that takes the store as an argument, or a function that takes no arguments:\n\n```typescript\n// As an object\nclean: {\n  user: null,\n  token: '',\n  isAuthenticated: false\n}\n\n// As a function with store argument\nclean: (store) => ({\n  user: null,\n  token: '',\n  isAuthenticated: false\n})\n\n// As a function without arguments\nclean: () => ({\n  user: null,\n  token: '',\n  isAuthenticated: false\n})\n\n// Reconfigure examples (similar pattern)\nreConfigure: {\n  theme: 'dark',\n  language: 'en'\n}\n\nreConfigure: (store) => ({\n  theme: 'dark',\n  language: 'en'\n})\n\nreConfigure: () => ({\n  theme: 'dark',\n  language: 'en'\n})\n```\n\n#### Refresh\n\nThe `refresh` option can be defined as an object, a function that takes the store as an argument, or a function that takes no arguments:\n\n```typescript\n// As an object\nrefresh: {\n  fetchUserProfile: { params: [], resetOnly: false },\n  fetchUserSettings: { params: [], resetOnly: true }\n}\n\n// As a function with store argument\nrefresh: (store) => ({\n  fetchUserProfile: { params: [] },\n  fetchUserSettings: { params: [], resetOnly: true }\n})\n\n// As a function without arguments\nrefresh: () => ({\n  fetchUserProfile: { params: [] },\n  fetchUserSettings: { params: [], resetOnly: true }\n})\n```\n\n### Refresh Options\n\nWhen calling the `refresh` function, you can specify options:\n\n```typescript\ntype PiniaStoreLifecycleManagerRefreshOptions = {\n  mode: \"full\" | \"partial\";\n  includeResetOnlyActions?: boolean;\n};\n\n /**\n  * Use 'full' mode when you need to refresh all data, including reset-only actions.\n  * This is useful for major state changes, like switching user accounts.\n  *\n  * Use 'partial' mode for routine updates or when switching to a related context\n  * that doesn't require a full data refresh.\n  */\n lifecycleEvents.refresh({ mode: 'full', includeResetOnlyActions: true });\n```\n\n#### Property Exclusions\n\nThe `clean`, `reConfigure`, and `refresh` options automatically exclude certain properties to ensure safe state management:\n\n- Pinia's internal properties (starting with `$`)\n- Conventionally private properties (starting with `_`)\n- Non-writable computed properties\n- State properties defined in the store\n\nThis ensures that only appropriate properties are modified during lifecycle operations.\n\n#### Clean and Reconfigure\n\nBoth `clean` and `reConfigure` can be defined as either an object or a function:\n\n```typescript\n// As an object\nclean: {\n  user: null,\n  token: '',\n  isAuthenticated: false\n}\n\n// As a function\nclean: (store) => ({\n  previousUserId: store.user?.id,\n  user: null,\n  token: '',\n  isAuthenticated: false\n})\n\n// Reconfigure example\nreConfigure: () => ({\n  theme: 'dark',\n  language: 'en',\n})\n```\n\n#### Refresh\n\nThe `refresh` option can be defined as either an object or a function:\n\n```typescript\n// As an object\nrefresh: {\n  fetchUserProfile: { params: ['userId'] },\n  fetchUserSettings: { params: [], resetOnly: true }\n}\n\n// As a function\nrefresh: (store) => ({\n  fetchUserProfile: { params: [store.userId] },\n  fetchUserSettings: { params: [], resetOnly: true }\n})\n```\n\n#### Property Inclusions and Exclusions\n\nThe `clean` and `reConfigure` options include:\n- Data variables (including list types)\n- Writable computed properties\n\nThey automatically exclude:\n- Pinia's internal properties (starting with `$`)\n- Conventionally private properties (starting with `_`)\n- Non-writable computed properties\n- Function properties\n\nThis ensures that only appropriate properties are modified during lifecycle operations while including all relevant data types.\n\n#### Readonly Properties\n\nThe `clean` and `reConfigure` operations automatically skip readonly properties to prevent errors:\n\n- If a property is readonly or a non-writable computed property, it will not be modified during reset or reconfigure operations.\n- When debug logs are enabled, a warning with a 🚫 emoji will be issued for each skipped non-writable property, reminding developers to avoid including such properties in clean or reConfigure options.\n\nThis ensures that only modifiable properties are affected by lifecycle operations, maintaining the integrity of readonly state and computed properties.\n\n> **Open Issue / Upcoming Enhancement:** \n> We are aware that non-writable properties can currently be included in `clean` and `reConfigure` options, which is not ideal. We plan to enhance the type system to prevent this in a future update. For now, we have a runtime safety check that skips these properties and issues a warning when encountered. Please avoid including non-writable properties in your `clean` and `reConfigure` options to ensure smooth operation and prepare for future updates.\n\n## Why Choose Pinia Store Lifecycle Manager\n\n- **Seamless Integration:** Easily integrates with existing Pinia stores.\n- **Highly Customizable:** Offers flexible configuration options.\n- **Performance Optimized:** Ensures minimal overhead in state management operations.\n- **Comprehensive Logging:** Facilitates debugging through optional debug logs.\n- **Active Maintenance:** Regular updates and community support.\n\n## License\n\nMIT","readmeFilename":"README.md"}