@atoapayments/pinia-store-lifecycle-manager 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,8 @@
1
+ <p align="center">
2
+ <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>
3
+ <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>
4
+ </p>
5
+
1
6
  # Pinia Store Lifecycle Manager
2
7
 
3
8
  A 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.
package/dist/index.cjs CHANGED
@@ -1,242 +1,7 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ 'use strict';
19
2
 
20
- // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
23
- PiniaStoreLifecycleManager: () => PiniaStoreLifecycleManager
24
- });
25
- module.exports = __toCommonJS(src_exports);
3
+ var vue = require('vue');
26
4
 
27
- // src/utils.ts
28
- function debugLog(storeId, message, data) {
29
- console.log(`\u{1F504} [${storeId}] ${message}`, data ? data : "");
30
- }
31
- function devWarnNonWritable(storeId, propertyName) {
32
- console.warn(
33
- `\u{1F504} \u{1F6AB} [${storeId}] Skipped non-writable property '${propertyName}'. Avoid including non-writable computed properties in clean or reConfigure options.`
34
- );
35
- }
36
- function devError(storeId, message, error) {
37
- console.error(
38
- `\u{1F504} [PiniaStoreLifecycleManager] (${storeId}) ${message}`,
39
- error
40
- );
41
- }
5
+ function t(i,e,o){console.log(`\u{1F504} [${i}] ${e}`,o||"");}function u(i,e){console.warn(`\u{1F504} \u{1F6AB} [${i}] Skipped non-writable property '${e}'. Avoid including non-writable computed properties in clean or reConfigure options.`);}function b(i,e,o){console.error(`\u{1F504} [PiniaStoreLifecycleManager] (${i}) ${e}`,o);}var m=({options:i,store:e},o,n)=>{if((typeof window>"u"||typeof document>"u")&&!n?.enableSSR){n?.enableDebugLogs&&t(e.$id,"PiniaStoreLifecycleManager is not running on the client side.");return}if(!e.$state.hasOwnProperty("hasStoreLifecycleManagerListener")&&(!n?.disableAutoRegister&&i.lifecycleOptions?.disableListener!==!0||n?.disableAutoRegister&&i.lifecycleOptions?.disableListener===!1)){let a=vue.ref(!0);e.$state._hasStoreLifecycleManagerListener=a,n?.enableDebugLogs&&t(e.$id,"Attaching PiniaStoreLifecycleManager listener"),o({reset:L,reconfigure:$,refresh:S}),e._hasStoreLifecycleManagerListener=vue.toRef(e.$state,"_hasStoreLifecycleManagerListener"),n?.enableDebugLogs&&t(e.$id,"PiniaStoreLifecycleManager listener attached successfully");}else n?.enableDebugLogs&&t(e.$id,"Skipping PiniaStoreLifecycleManager listener attachment",{reason:e.$state.hasStoreLifecycleManagerListener?"Already attached":"Disabled by configuration"});function L(){if(n?.enableDebugLogs&&t(e.$id,"Initiating reset state operation",i.lifecycleOptions?.clean),!i.lifecycleOptions?.clean){n?.enableDebugLogs&&t(e.$id,"Reset state operation skipped: No clean options defined");return}let a=typeof i.lifecycleOptions.clean=="function"?i.lifecycleOptions.clean.length>0?i.lifecycleOptions.clean(e):i.lifecycleOptions.clean():i.lifecycleOptions.clean;a&&Object.keys(a).forEach(r=>{if(vue.isReadonly(e[r])){n?.enableDebugLogs&&u(e.$id,r);return}let c=e[r];try{e[r]=a[r],n?.enableDebugLogs&&t(e.$id,`Reset state: Updated '${r}'`,{oldValue:c,newValue:e[r]});}catch(f){b(e.$id,`Failed to reset state for key '${r}'`,f);}}),n?.enableDebugLogs&&t(e.$id,"Reset state operation completed");}function $(){if(n?.enableDebugLogs&&t(e.$id,"Initiating reconfigure state operation",i.lifecycleOptions?.reConfigure),!i.lifecycleOptions?.reConfigure){n?.enableDebugLogs&&t(e.$id,"Reconfigure state operation skipped: No reconfigure options defined");return}let a=typeof i.lifecycleOptions.reConfigure=="function"?i.lifecycleOptions.reConfigure.length>0?i.lifecycleOptions.reConfigure(e):i.lifecycleOptions.reConfigure():i.lifecycleOptions.reConfigure;a&&Object.keys(a).forEach(r=>{if(vue.isReadonly(e[r])){n?.enableDebugLogs&&u(e.$id,r);return}let c=e[r];try{e[r]=a[r],n?.enableDebugLogs&&t(e.$id,`Reconfigure state: Updated '${r}'`,{oldValue:c,newValue:e[r]});}catch(f){b(e.$id,`Failed to reconfigure state for key '${r}'`,f);}}),n?.enableDebugLogs&&t(e.$id,"Reconfigure state operation completed");}function S(a){let{mode:r,includeResetOnlyActions:c=!1}=a;if(n?.enableDebugLogs&&t(e.$id,"Initiating refresh action",{mode:r,includeResetOnlyActions:c,refreshOptions:i.lifecycleOptions?.refresh}),!i.lifecycleOptions?.refresh){n?.enableDebugLogs&&t(e.$id,"Refresh action skipped: No refresh options defined");return}let f=typeof i.lifecycleOptions.refresh=="function"?i.lifecycleOptions.refresh.length>0?i.lifecycleOptions.refresh(e):i.lifecycleOptions.refresh():i.lifecycleOptions.refresh;if(f&&typeof f=="object"){let p=Object.fromEntries(Object.entries(f).filter(([l,g])=>{let d=g?.resetOnly??!1,s=r==="full"?!c||c&&d:!d;return n?.enableDebugLogs&&t(e.$id,`Filtering refresh action: ${l}`,{shouldInclude:s,mode:r,includeResetOnlyActions:c,actionResetOnly:d}),s}));Object.entries(p).forEach(([l,g])=>{let s=e[l];if(s){let y=g?.params??[];n?.enableDebugLogs&&t(e.$id,`Executing refresh action: ${l}`,{params:y}),s(...y);}else n?.enableDebugLogs&&t(e.$id,`Skipped non-existent refresh action: ${l}`);});}else n?.enableDebugLogs&&t(e.$id,"Refresh action skipped: Invalid refresh result");n?.enableDebugLogs&&t(e.$id,"Refresh action completed");}};
42
6
 
43
- // src/plugin.ts
44
- var import_vue = require("vue");
45
- var PiniaStoreLifecycleManager = ({ options, store }, lifecycleEventHandler, pluginOptions) => {
46
- if ((typeof window === "undefined" || typeof document === "undefined") && !pluginOptions?.enableSSR) {
47
- if (pluginOptions?.enableDebugLogs) {
48
- debugLog(
49
- store.$id,
50
- "PiniaStoreLifecycleManager is not running on the client side."
51
- );
52
- }
53
- return;
54
- }
55
- if (!store.$state.hasOwnProperty("hasStoreLifecycleManagerListener") && (!pluginOptions?.disableAutoRegister && options.lifecycleOptions?.disableListener !== true || pluginOptions?.disableAutoRegister && options.lifecycleOptions?.disableListener === false)) {
56
- const _hasStoreLifecycleManagerListener = (0, import_vue.ref)(true);
57
- store.$state._hasStoreLifecycleManagerListener = _hasStoreLifecycleManagerListener;
58
- if (pluginOptions?.enableDebugLogs) {
59
- debugLog(store.$id, "Attaching PiniaStoreLifecycleManager listener");
60
- }
61
- lifecycleEventHandler({
62
- reset: resetState,
63
- reconfigure: reconfigureState,
64
- refresh: refreshState
65
- });
66
- store._hasStoreLifecycleManagerListener = (0, import_vue.toRef)(
67
- store.$state,
68
- "_hasStoreLifecycleManagerListener"
69
- );
70
- if (pluginOptions?.enableDebugLogs) {
71
- debugLog(
72
- store.$id,
73
- "PiniaStoreLifecycleManager listener attached successfully"
74
- );
75
- }
76
- } else {
77
- if (pluginOptions?.enableDebugLogs) {
78
- debugLog(
79
- store.$id,
80
- "Skipping PiniaStoreLifecycleManager listener attachment",
81
- {
82
- reason: store.$state.hasStoreLifecycleManagerListener ? "Already attached" : "Disabled by configuration"
83
- }
84
- );
85
- }
86
- }
87
- function resetState() {
88
- if (pluginOptions?.enableDebugLogs) {
89
- debugLog(
90
- store.$id,
91
- "Initiating reset state operation",
92
- options.lifecycleOptions?.clean
93
- );
94
- }
95
- if (!options.lifecycleOptions?.clean) {
96
- if (pluginOptions?.enableDebugLogs) {
97
- debugLog(
98
- store.$id,
99
- "Reset state operation skipped: No clean options defined"
100
- );
101
- }
102
- return;
103
- }
104
- const cleanOptions = typeof options.lifecycleOptions.clean === "function" ? options.lifecycleOptions.clean.length > 0 ? options.lifecycleOptions.clean(store) : options.lifecycleOptions.clean() : options.lifecycleOptions.clean;
105
- if (cleanOptions) {
106
- Object.keys(cleanOptions).forEach((key) => {
107
- if ((0, import_vue.isReadonly)(store[key])) {
108
- if (pluginOptions?.enableDebugLogs) {
109
- devWarnNonWritable(store.$id, key);
110
- }
111
- return;
112
- }
113
- const oldValue = store[key];
114
- try {
115
- store[key] = cleanOptions[key];
116
- if (pluginOptions?.enableDebugLogs) {
117
- debugLog(store.$id, `Reset state: Updated '${key}'`, {
118
- oldValue,
119
- newValue: store[key]
120
- });
121
- }
122
- } catch (error) {
123
- devError(store.$id, `Failed to reset state for key '${key}'`, error);
124
- }
125
- });
126
- }
127
- if (pluginOptions?.enableDebugLogs) {
128
- debugLog(store.$id, "Reset state operation completed");
129
- }
130
- }
131
- function reconfigureState() {
132
- if (pluginOptions?.enableDebugLogs) {
133
- debugLog(
134
- store.$id,
135
- "Initiating reconfigure state operation",
136
- options.lifecycleOptions?.reConfigure
137
- );
138
- }
139
- if (!options.lifecycleOptions?.reConfigure) {
140
- if (pluginOptions?.enableDebugLogs) {
141
- debugLog(
142
- store.$id,
143
- "Reconfigure state operation skipped: No reconfigure options defined"
144
- );
145
- }
146
- return;
147
- }
148
- const reconfigureOptions = typeof options.lifecycleOptions.reConfigure === "function" ? options.lifecycleOptions.reConfigure.length > 0 ? options.lifecycleOptions.reConfigure(store) : options.lifecycleOptions.reConfigure() : options.lifecycleOptions.reConfigure;
149
- if (reconfigureOptions) {
150
- Object.keys(reconfigureOptions).forEach((key) => {
151
- if ((0, import_vue.isReadonly)(store[key])) {
152
- if (pluginOptions?.enableDebugLogs) {
153
- devWarnNonWritable(store.$id, key);
154
- }
155
- return;
156
- }
157
- const oldValue = store[key];
158
- try {
159
- store[key] = reconfigureOptions[key];
160
- if (pluginOptions?.enableDebugLogs) {
161
- debugLog(store.$id, `Reconfigure state: Updated '${key}'`, {
162
- oldValue,
163
- newValue: store[key]
164
- });
165
- }
166
- } catch (error) {
167
- devError(
168
- store.$id,
169
- `Failed to reconfigure state for key '${key}'`,
170
- error
171
- );
172
- }
173
- });
174
- }
175
- if (pluginOptions?.enableDebugLogs) {
176
- debugLog(store.$id, "Reconfigure state operation completed");
177
- }
178
- }
179
- function refreshState(refreshOptions) {
180
- const { mode, includeResetOnlyActions = false } = refreshOptions;
181
- if (pluginOptions?.enableDebugLogs) {
182
- debugLog(store.$id, "Initiating refresh action", {
183
- mode,
184
- includeResetOnlyActions,
185
- refreshOptions: options.lifecycleOptions?.refresh
186
- });
187
- }
188
- if (!options.lifecycleOptions?.refresh) {
189
- if (pluginOptions?.enableDebugLogs) {
190
- debugLog(
191
- store.$id,
192
- "Refresh action skipped: No refresh options defined"
193
- );
194
- }
195
- return;
196
- }
197
- const refreshResult = typeof options.lifecycleOptions.refresh === "function" ? options.lifecycleOptions.refresh.length > 0 ? options.lifecycleOptions.refresh(store) : options.lifecycleOptions.refresh() : options.lifecycleOptions.refresh;
198
- if (refreshResult && typeof refreshResult === "object") {
199
- const filteredResult = Object.fromEntries(
200
- Object.entries(refreshResult).filter(([key, value]) => {
201
- const actionResetOnly = value?.resetOnly ?? false;
202
- const shouldInclude = mode === "full" ? !includeResetOnlyActions || includeResetOnlyActions && actionResetOnly : !actionResetOnly;
203
- if (pluginOptions?.enableDebugLogs) {
204
- debugLog(store.$id, `Filtering refresh action: ${key}`, {
205
- shouldInclude,
206
- mode,
207
- includeResetOnlyActions,
208
- actionResetOnly
209
- });
210
- }
211
- return shouldInclude;
212
- })
213
- );
214
- Object.entries(filteredResult).forEach(([key, value]) => {
215
- const actionKey = key;
216
- const action = store[actionKey];
217
- if (action) {
218
- const params = value?.params ?? [];
219
- if (pluginOptions?.enableDebugLogs) {
220
- debugLog(store.$id, `Executing refresh action: ${key}`, { params });
221
- }
222
- action(...params);
223
- } else {
224
- if (pluginOptions?.enableDebugLogs) {
225
- debugLog(store.$id, `Skipped non-existent refresh action: ${key}`);
226
- }
227
- }
228
- });
229
- } else {
230
- if (pluginOptions?.enableDebugLogs) {
231
- debugLog(store.$id, "Refresh action skipped: Invalid refresh result");
232
- }
233
- }
234
- if (pluginOptions?.enableDebugLogs) {
235
- debugLog(store.$id, "Refresh action completed");
236
- }
237
- }
238
- };
239
- // Annotate the CommonJS export names for ESM import in node:
240
- 0 && (module.exports = {
241
- PiniaStoreLifecycleManager
242
- });
7
+ exports.PiniaStoreLifecycleManager = m;
Binary file
Binary file
Binary file
package/dist/index.js CHANGED
@@ -1,215 +1,5 @@
1
- // src/utils.ts
2
- function debugLog(storeId, message, data) {
3
- console.log(`\u{1F504} [${storeId}] ${message}`, data ? data : "");
4
- }
5
- function devWarnNonWritable(storeId, propertyName) {
6
- console.warn(
7
- `\u{1F504} \u{1F6AB} [${storeId}] Skipped non-writable property '${propertyName}'. Avoid including non-writable computed properties in clean or reConfigure options.`
8
- );
9
- }
10
- function devError(storeId, message, error) {
11
- console.error(
12
- `\u{1F504} [PiniaStoreLifecycleManager] (${storeId}) ${message}`,
13
- error
14
- );
15
- }
1
+ import { ref, toRef, isReadonly } from 'vue';
16
2
 
17
- // src/plugin.ts
18
- import { ref, toRef, isReadonly } from "vue";
19
- var PiniaStoreLifecycleManager = ({ options, store }, lifecycleEventHandler, pluginOptions) => {
20
- if ((typeof window === "undefined" || typeof document === "undefined") && !pluginOptions?.enableSSR) {
21
- if (pluginOptions?.enableDebugLogs) {
22
- debugLog(
23
- store.$id,
24
- "PiniaStoreLifecycleManager is not running on the client side."
25
- );
26
- }
27
- return;
28
- }
29
- if (!store.$state.hasOwnProperty("hasStoreLifecycleManagerListener") && (!pluginOptions?.disableAutoRegister && options.lifecycleOptions?.disableListener !== true || pluginOptions?.disableAutoRegister && options.lifecycleOptions?.disableListener === false)) {
30
- const _hasStoreLifecycleManagerListener = ref(true);
31
- store.$state._hasStoreLifecycleManagerListener = _hasStoreLifecycleManagerListener;
32
- if (pluginOptions?.enableDebugLogs) {
33
- debugLog(store.$id, "Attaching PiniaStoreLifecycleManager listener");
34
- }
35
- lifecycleEventHandler({
36
- reset: resetState,
37
- reconfigure: reconfigureState,
38
- refresh: refreshState
39
- });
40
- store._hasStoreLifecycleManagerListener = toRef(
41
- store.$state,
42
- "_hasStoreLifecycleManagerListener"
43
- );
44
- if (pluginOptions?.enableDebugLogs) {
45
- debugLog(
46
- store.$id,
47
- "PiniaStoreLifecycleManager listener attached successfully"
48
- );
49
- }
50
- } else {
51
- if (pluginOptions?.enableDebugLogs) {
52
- debugLog(
53
- store.$id,
54
- "Skipping PiniaStoreLifecycleManager listener attachment",
55
- {
56
- reason: store.$state.hasStoreLifecycleManagerListener ? "Already attached" : "Disabled by configuration"
57
- }
58
- );
59
- }
60
- }
61
- function resetState() {
62
- if (pluginOptions?.enableDebugLogs) {
63
- debugLog(
64
- store.$id,
65
- "Initiating reset state operation",
66
- options.lifecycleOptions?.clean
67
- );
68
- }
69
- if (!options.lifecycleOptions?.clean) {
70
- if (pluginOptions?.enableDebugLogs) {
71
- debugLog(
72
- store.$id,
73
- "Reset state operation skipped: No clean options defined"
74
- );
75
- }
76
- return;
77
- }
78
- const cleanOptions = typeof options.lifecycleOptions.clean === "function" ? options.lifecycleOptions.clean.length > 0 ? options.lifecycleOptions.clean(store) : options.lifecycleOptions.clean() : options.lifecycleOptions.clean;
79
- if (cleanOptions) {
80
- Object.keys(cleanOptions).forEach((key) => {
81
- if (isReadonly(store[key])) {
82
- if (pluginOptions?.enableDebugLogs) {
83
- devWarnNonWritable(store.$id, key);
84
- }
85
- return;
86
- }
87
- const oldValue = store[key];
88
- try {
89
- store[key] = cleanOptions[key];
90
- if (pluginOptions?.enableDebugLogs) {
91
- debugLog(store.$id, `Reset state: Updated '${key}'`, {
92
- oldValue,
93
- newValue: store[key]
94
- });
95
- }
96
- } catch (error) {
97
- devError(store.$id, `Failed to reset state for key '${key}'`, error);
98
- }
99
- });
100
- }
101
- if (pluginOptions?.enableDebugLogs) {
102
- debugLog(store.$id, "Reset state operation completed");
103
- }
104
- }
105
- function reconfigureState() {
106
- if (pluginOptions?.enableDebugLogs) {
107
- debugLog(
108
- store.$id,
109
- "Initiating reconfigure state operation",
110
- options.lifecycleOptions?.reConfigure
111
- );
112
- }
113
- if (!options.lifecycleOptions?.reConfigure) {
114
- if (pluginOptions?.enableDebugLogs) {
115
- debugLog(
116
- store.$id,
117
- "Reconfigure state operation skipped: No reconfigure options defined"
118
- );
119
- }
120
- return;
121
- }
122
- const reconfigureOptions = typeof options.lifecycleOptions.reConfigure === "function" ? options.lifecycleOptions.reConfigure.length > 0 ? options.lifecycleOptions.reConfigure(store) : options.lifecycleOptions.reConfigure() : options.lifecycleOptions.reConfigure;
123
- if (reconfigureOptions) {
124
- Object.keys(reconfigureOptions).forEach((key) => {
125
- if (isReadonly(store[key])) {
126
- if (pluginOptions?.enableDebugLogs) {
127
- devWarnNonWritable(store.$id, key);
128
- }
129
- return;
130
- }
131
- const oldValue = store[key];
132
- try {
133
- store[key] = reconfigureOptions[key];
134
- if (pluginOptions?.enableDebugLogs) {
135
- debugLog(store.$id, `Reconfigure state: Updated '${key}'`, {
136
- oldValue,
137
- newValue: store[key]
138
- });
139
- }
140
- } catch (error) {
141
- devError(
142
- store.$id,
143
- `Failed to reconfigure state for key '${key}'`,
144
- error
145
- );
146
- }
147
- });
148
- }
149
- if (pluginOptions?.enableDebugLogs) {
150
- debugLog(store.$id, "Reconfigure state operation completed");
151
- }
152
- }
153
- function refreshState(refreshOptions) {
154
- const { mode, includeResetOnlyActions = false } = refreshOptions;
155
- if (pluginOptions?.enableDebugLogs) {
156
- debugLog(store.$id, "Initiating refresh action", {
157
- mode,
158
- includeResetOnlyActions,
159
- refreshOptions: options.lifecycleOptions?.refresh
160
- });
161
- }
162
- if (!options.lifecycleOptions?.refresh) {
163
- if (pluginOptions?.enableDebugLogs) {
164
- debugLog(
165
- store.$id,
166
- "Refresh action skipped: No refresh options defined"
167
- );
168
- }
169
- return;
170
- }
171
- const refreshResult = typeof options.lifecycleOptions.refresh === "function" ? options.lifecycleOptions.refresh.length > 0 ? options.lifecycleOptions.refresh(store) : options.lifecycleOptions.refresh() : options.lifecycleOptions.refresh;
172
- if (refreshResult && typeof refreshResult === "object") {
173
- const filteredResult = Object.fromEntries(
174
- Object.entries(refreshResult).filter(([key, value]) => {
175
- const actionResetOnly = value?.resetOnly ?? false;
176
- const shouldInclude = mode === "full" ? !includeResetOnlyActions || includeResetOnlyActions && actionResetOnly : !actionResetOnly;
177
- if (pluginOptions?.enableDebugLogs) {
178
- debugLog(store.$id, `Filtering refresh action: ${key}`, {
179
- shouldInclude,
180
- mode,
181
- includeResetOnlyActions,
182
- actionResetOnly
183
- });
184
- }
185
- return shouldInclude;
186
- })
187
- );
188
- Object.entries(filteredResult).forEach(([key, value]) => {
189
- const actionKey = key;
190
- const action = store[actionKey];
191
- if (action) {
192
- const params = value?.params ?? [];
193
- if (pluginOptions?.enableDebugLogs) {
194
- debugLog(store.$id, `Executing refresh action: ${key}`, { params });
195
- }
196
- action(...params);
197
- } else {
198
- if (pluginOptions?.enableDebugLogs) {
199
- debugLog(store.$id, `Skipped non-existent refresh action: ${key}`);
200
- }
201
- }
202
- });
203
- } else {
204
- if (pluginOptions?.enableDebugLogs) {
205
- debugLog(store.$id, "Refresh action skipped: Invalid refresh result");
206
- }
207
- }
208
- if (pluginOptions?.enableDebugLogs) {
209
- debugLog(store.$id, "Refresh action completed");
210
- }
211
- }
212
- };
213
- export {
214
- PiniaStoreLifecycleManager
215
- };
3
+ function t(i,e,o){console.log(`\u{1F504} [${i}] ${e}`,o||"");}function u(i,e){console.warn(`\u{1F504} \u{1F6AB} [${i}] Skipped non-writable property '${e}'. Avoid including non-writable computed properties in clean or reConfigure options.`);}function b(i,e,o){console.error(`\u{1F504} [PiniaStoreLifecycleManager] (${i}) ${e}`,o);}var m=({options:i,store:e},o,n)=>{if((typeof window>"u"||typeof document>"u")&&!n?.enableSSR){n?.enableDebugLogs&&t(e.$id,"PiniaStoreLifecycleManager is not running on the client side.");return}if(!e.$state.hasOwnProperty("hasStoreLifecycleManagerListener")&&(!n?.disableAutoRegister&&i.lifecycleOptions?.disableListener!==!0||n?.disableAutoRegister&&i.lifecycleOptions?.disableListener===!1)){let a=ref(!0);e.$state._hasStoreLifecycleManagerListener=a,n?.enableDebugLogs&&t(e.$id,"Attaching PiniaStoreLifecycleManager listener"),o({reset:L,reconfigure:$,refresh:S}),e._hasStoreLifecycleManagerListener=toRef(e.$state,"_hasStoreLifecycleManagerListener"),n?.enableDebugLogs&&t(e.$id,"PiniaStoreLifecycleManager listener attached successfully");}else n?.enableDebugLogs&&t(e.$id,"Skipping PiniaStoreLifecycleManager listener attachment",{reason:e.$state.hasStoreLifecycleManagerListener?"Already attached":"Disabled by configuration"});function L(){if(n?.enableDebugLogs&&t(e.$id,"Initiating reset state operation",i.lifecycleOptions?.clean),!i.lifecycleOptions?.clean){n?.enableDebugLogs&&t(e.$id,"Reset state operation skipped: No clean options defined");return}let a=typeof i.lifecycleOptions.clean=="function"?i.lifecycleOptions.clean.length>0?i.lifecycleOptions.clean(e):i.lifecycleOptions.clean():i.lifecycleOptions.clean;a&&Object.keys(a).forEach(r=>{if(isReadonly(e[r])){n?.enableDebugLogs&&u(e.$id,r);return}let c=e[r];try{e[r]=a[r],n?.enableDebugLogs&&t(e.$id,`Reset state: Updated '${r}'`,{oldValue:c,newValue:e[r]});}catch(f){b(e.$id,`Failed to reset state for key '${r}'`,f);}}),n?.enableDebugLogs&&t(e.$id,"Reset state operation completed");}function $(){if(n?.enableDebugLogs&&t(e.$id,"Initiating reconfigure state operation",i.lifecycleOptions?.reConfigure),!i.lifecycleOptions?.reConfigure){n?.enableDebugLogs&&t(e.$id,"Reconfigure state operation skipped: No reconfigure options defined");return}let a=typeof i.lifecycleOptions.reConfigure=="function"?i.lifecycleOptions.reConfigure.length>0?i.lifecycleOptions.reConfigure(e):i.lifecycleOptions.reConfigure():i.lifecycleOptions.reConfigure;a&&Object.keys(a).forEach(r=>{if(isReadonly(e[r])){n?.enableDebugLogs&&u(e.$id,r);return}let c=e[r];try{e[r]=a[r],n?.enableDebugLogs&&t(e.$id,`Reconfigure state: Updated '${r}'`,{oldValue:c,newValue:e[r]});}catch(f){b(e.$id,`Failed to reconfigure state for key '${r}'`,f);}}),n?.enableDebugLogs&&t(e.$id,"Reconfigure state operation completed");}function S(a){let{mode:r,includeResetOnlyActions:c=!1}=a;if(n?.enableDebugLogs&&t(e.$id,"Initiating refresh action",{mode:r,includeResetOnlyActions:c,refreshOptions:i.lifecycleOptions?.refresh}),!i.lifecycleOptions?.refresh){n?.enableDebugLogs&&t(e.$id,"Refresh action skipped: No refresh options defined");return}let f=typeof i.lifecycleOptions.refresh=="function"?i.lifecycleOptions.refresh.length>0?i.lifecycleOptions.refresh(e):i.lifecycleOptions.refresh():i.lifecycleOptions.refresh;if(f&&typeof f=="object"){let p=Object.fromEntries(Object.entries(f).filter(([l,g])=>{let d=g?.resetOnly??!1,s=r==="full"?!c||c&&d:!d;return n?.enableDebugLogs&&t(e.$id,`Filtering refresh action: ${l}`,{shouldInclude:s,mode:r,includeResetOnlyActions:c,actionResetOnly:d}),s}));Object.entries(p).forEach(([l,g])=>{let s=e[l];if(s){let y=g?.params??[];n?.enableDebugLogs&&t(e.$id,`Executing refresh action: ${l}`,{params:y}),s(...y);}else n?.enableDebugLogs&&t(e.$id,`Skipped non-existent refresh action: ${l}`);});}else n?.enableDebugLogs&&t(e.$id,"Refresh action skipped: Invalid refresh result");n?.enableDebugLogs&&t(e.$id,"Refresh action completed");}};
4
+
5
+ export { m as PiniaStoreLifecycleManager };
Binary file
package/package.json CHANGED
@@ -1,7 +1,16 @@
1
1
  {
2
2
  "name": "@atoapayments/pinia-store-lifecycle-manager",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "A Pinia plugin for managing store lifecycle, including state resets and refreshes",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/ATOAPaymentsLimited/pinia-store-lifecycle-manager.git"
8
+ },
9
+ "homepage": "https://github.com/ATOAPaymentsLimited/pinia-store-lifecycle-manager#readme",
10
+ "bugs": {
11
+ "url": "https://github.com/ATOAPaymentsLimited/pinia-store-lifecycle-manager/issues",
12
+ "email": "vamsi@paywithatoa.co.uk"
13
+ },
5
14
  "type": "module",
6
15
  "main": "dist/index.js",
7
16
  "types": "dist/index.d.ts",
@@ -9,11 +18,12 @@
9
18
  "dist"
10
19
  ],
11
20
  "scripts": {
12
- "build": "tsup src/index.ts --format cjs,esm --dts",
21
+ "build": "tsup src/index.ts --format cjs,esm --minify --treeshake --dts",
13
22
  "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
14
23
  "lint": "eslint src/**/*.ts",
15
24
  "clean": "rm -rf dist",
16
- "prepublishOnly": "npm run clean && npm run build"
25
+ "gzipper": "gzipper compress ./dist --include cjs,cts,js,ts,d.ts",
26
+ "prepublishOnly": "npm run clean && npm run build && npm run gzipper"
17
27
  },
18
28
  "keywords": [
19
29
  "pinia",
@@ -29,6 +39,7 @@
29
39
  "@typescript-eslint/eslint-plugin": "^8.7.0",
30
40
  "@typescript-eslint/parser": "^8.7.0",
31
41
  "eslint": "^9.11.1",
42
+ "gzipper": "^7.2.0",
32
43
  "pinia": "^2.2.2",
33
44
  "tsup": "^8.3.0",
34
45
  "typescript": "^5.6.2",