pinia-plugin-subscription 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.2.1]
9
+
10
+ ### Fixed
11
+ - Kept deferred action subscribers attached to the correct store after hydration, and scoped action/reset callbacks to each store so disposal and recreation do not leak callbacks.
12
+ - Preserved existing refs with falsy values when adding setup-store state.
13
+ - Made `stateKeys: []` restore the full state in both explicit and automatic rollback.
14
+
8
15
  ## [0.2.0]
9
16
 
10
17
  ### Added
@@ -23,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
23
30
  - Fixed store typings lost when defining stores with `defineAStore`, `defineAStoreCtx`, `defineAStoreSetup` or `defineAStoreOptionApi`: state, getters and actions are now inferred from the store definition (setup function return or options object), exactly like pinia's `defineStore`, so IDEs list store members and display action prototypes. Explicit store/state generics (e.g. `defineAStore<Sto, Sta>`) remain supported for plugin-augmented stores and now type the store returned by `useStore()` — they were previously intersected onto the store definition itself, which left the returned store loosely typed.
24
31
  - Added the public `DefineAStoreDefinition<Sto, Sta>` type: the store definition returned when explicit store/state generics are provided. It extends pinia's `StoreDefinition` so it stays assignable wherever a standard store definition is expected.
25
32
  - Widened the `getDefineAStoreSetupContext` parameter to accept any store object, so fully inferred stores (without index signatures) can be passed without a cast.
33
+ - Fixed stores defined with explicit generics (`defineAStore<Sto, Sta>` / `defineAStoreCtx<Sto, Sta>`) exposing every non-state member as `any`: the state was intersected with pinia's `StateTree`, whose `any` index signature widened actions and broke IDE autocompletion. The state is now mapped through the new public `StrictStateTree<Sta>` type.
26
34
 
27
35
  ## [0.2.0-beta.0]
28
36
 
package/README.md CHANGED
@@ -9,6 +9,8 @@ This project provides:
9
9
  - the `$reset` method on all stores modified by the plugin;
10
10
  - automatic state rollback on action failure via the `rollbackAfterFailure` store option and the `$rollbackAfterFailure` method.
11
11
 
12
+ Deferred subscribers attach their action and reset callbacks to their own store after hydration; disposing a store removes its callbacks. For both rollback APIs, `stateKeys: []` restores the full state on failure.
13
+
12
14
  ## Tested & maintained
13
15
 
14
16
  The package is fully tested with [Vitest](https://vitest.dev/): runtime behavior, type-level contracts (`*.test-d.ts`) and performance regressions are covered, and coverage reports are available in `coverage/`. The full test suite and the build run on every push and pull request through [GitHub Actions](.github/workflows/ci.yml).
@@ -1,9 +1,9 @@
1
1
  var f = Object.defineProperty;
2
2
  var S = (s, t, e) => t in s ? f(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
3
3
  var n = (s, t, e) => S(s, typeof t != "symbol" ? t + "" : t, e);
4
- import { ref as b, toRef as y } from "vue";
4
+ import { isRef as b, ref as y, toRef as C } from "vue";
5
5
  import { defineStore as g } from "pinia";
6
- class H {
6
+ class L {
7
7
  constructor(t, e, r) {
8
8
  n(this, "_console");
9
9
  n(this, "_createInstance");
@@ -57,7 +57,7 @@ class H {
57
57
  return this._storeInstance = this._createInstance(t, { ...e, ...this.pluginOptions }, r, this.console), this._storeInstance ? (this._subscriptions = this._storeInstance.getSubscriptions(), this._storeMutationSubscription = this._storeInstance.storeSubscribe, this._storeOnActionSubscription = this._storeInstance.onAction, this.pluginCreated && this.pluginCreated(t), !0) : !1;
58
58
  }
59
59
  }
60
- class C {
60
+ class A {
61
61
  constructor(t, e) {
62
62
  n(this, "_console");
63
63
  n(this, "_debug", !1);
@@ -82,35 +82,35 @@ class C {
82
82
  this.console.error(...t);
83
83
  }
84
84
  }
85
- const p = /* @__PURE__ */ new WeakMap(), c = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new WeakSet(), A = 50;
86
- function O(s) {
85
+ const p = /* @__PURE__ */ new WeakMap(), c = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new WeakSet(), O = 50;
86
+ function x(s) {
87
87
  return s?.storeOptions?.debug === !0;
88
88
  }
89
89
  function h(s, t, e) {
90
- if (!O(t))
90
+ if (!x(t))
91
91
  return;
92
92
  const r = c.size;
93
- console.debug(`[defineAStoreSetup] ${s} - ${e} (contextsById=${r})`), r >= A && console.warn(`[defineAStoreSetup] contextsById reached ${r} entries`);
93
+ console.debug(`[defineAStoreSetup] ${s} - ${e} (contextsById=${r})`), r >= O && console.warn(`[defineAStoreSetup] contextsById reached ${r} entries`);
94
94
  }
95
- function x(s, t, e) {
95
+ function $(s, t, e) {
96
96
  if (l.has(s) || typeof s.$dispose != "function")
97
97
  return;
98
98
  const r = s.$dispose;
99
99
  s.$dispose = (...o) => (p.delete(s), c.delete(t), h(t, e, "dispose cleanup"), r.apply(s, o)), l.add(s);
100
100
  }
101
- function L(s, t, e) {
101
+ function N(s, t, e) {
102
102
  const r = e ? { storeOptions: e } : {};
103
103
  return typeof t == "function" ? d(
104
104
  s,
105
105
  t,
106
106
  r
107
- ) : $(
107
+ ) : m(
108
108
  s,
109
109
  t,
110
110
  r
111
111
  );
112
112
  }
113
- function N(s, t, e) {
113
+ function T(s, t, e) {
114
114
  const r = e ? { storeOptions: { ...e, enhancedStore: !0 } } : { storeOptions: { enhancedStore: !0 } };
115
115
  return d(
116
116
  s,
@@ -130,39 +130,39 @@ function d(s, t, e) {
130
130
  return Object.assign(((...u) => {
131
131
  o && (c.set(s, r), h(s, e, "registered context by id"));
132
132
  const a = i(...u);
133
- return o && (p.set(a, r), c.delete(s), h(s, e, "moved context to weak map"), x(a, s, e)), a;
133
+ return o && (p.set(a, r), c.delete(s), h(s, e, "moved context to weak map"), $(a, s, e)), a;
134
134
  }), i);
135
135
  }
136
- function $(s, t, e) {
136
+ function m(s, t, e) {
137
137
  return e && (t = { ...t, ...e ?? {} }), g(s, t);
138
138
  }
139
- const m = /* @__PURE__ */ new Set(["_", "$"]);
140
- function I(s) {
141
- return m.has(s[0]);
142
- }
139
+ const I = /* @__PURE__ */ new Set(["_", "$"]);
143
140
  function w(s) {
141
+ return I.has(s[0]);
142
+ }
143
+ function E(s) {
144
144
  const t = s;
145
145
  return p.get(s) ?? (typeof t?.$id == "string" ? c.get(t.$id) : void 0);
146
146
  }
147
- function E(s) {
147
+ function k(s) {
148
148
  const t = s.extensions.enhancedStore ?? s.extensions.extending;
149
149
  if (!t)
150
150
  throw new Error(`${s.id}Store - getEnhancedStore - Error: enhanced store is required`);
151
151
  return t;
152
152
  }
153
- function k(s, t) {
153
+ function M(s, t) {
154
154
  s.extensions.enhancedStore = t, s.extensions.extending = t;
155
155
  }
156
- function T(s) {
157
- return console.warn(`${s.id}Store - getExtendingStore is deprecated. Use getEnhancedStore instead.`), E(s);
156
+ function W(s) {
157
+ return console.warn(`${s.id}Store - getExtendingStore is deprecated. Use getEnhancedStore instead.`), k(s);
158
158
  }
159
- function W(s, t) {
159
+ function F(s, t) {
160
160
  return `${s}-${t.$id}`;
161
161
  }
162
- function M(s) {
162
+ function P(s) {
163
163
  return s ? Array.isArray(s) ? s.length === 0 : typeof s == "object" ? Object.keys(s).length === 0 : typeof s == "string" ? s.trim() === "" : !1 : !(typeof s == "boolean" || typeof s == "number");
164
164
  }
165
- class P extends C {
165
+ class q extends A {
166
166
  constructor(e, r, o = !1, i) {
167
167
  super(o, i);
168
168
  n(this, "_className", "Store");
@@ -172,8 +172,8 @@ class P extends C {
172
172
  n(this, "_subscriptions", {});
173
173
  n(this, "_storeSubscribe");
174
174
  if (this._options = r.storeOptions, this._store = e, this._options?.enhancedStore) {
175
- const u = w(this.store);
176
- u && k(u, this.store);
175
+ const u = E(this.store);
176
+ u && M(u, this.store);
177
177
  }
178
178
  }
179
179
  get onAction() {
@@ -209,7 +209,7 @@ class P extends C {
209
209
  this._storeSubscribe = e;
210
210
  }
211
211
  addToState(e, r) {
212
- this.isOptionApi() || r?.value || (r = b(r)), this.state[e] = r, this.store[e] = y(this.state, e);
212
+ this.isOptionApi() || b(r) || (r = y(r)), this.state[e] = r, this.store[e] = C(this.state, e);
213
213
  }
214
214
  addSubscription(e, r, o) {
215
215
  this._subscriptions[e] = { subscription: r, ...o ?? {} };
@@ -227,14 +227,14 @@ class P extends C {
227
227
  return this.getValue(this.state[e]);
228
228
  }
229
229
  getSubscriptions() {
230
- if (!M(this._subscriptions))
230
+ if (!P(this._subscriptions))
231
231
  return this._subscriptions;
232
232
  }
233
233
  getValue(e) {
234
234
  return e?.__v_isRef ? e.value : e;
235
235
  }
236
236
  hasDeniedFirstChar(e) {
237
- return I(e);
237
+ return w(e);
238
238
  }
239
239
  static hasRequiredKeys(e) {
240
240
  return this._requiredKeys !== void 0 && this._requiredKeys?.every((r) => !!e[r]);
@@ -251,9 +251,9 @@ class P extends C {
251
251
  return Object.prototype.hasOwnProperty.call(this.store, e);
252
252
  }
253
253
  }
254
- n(P, "_requiredKeys");
255
- const _ = "pinia-plugin-subscription", q = (s, t = "white") => `background-color: ${s}; color: ${t}; padding: 1px; margin-right: 5px; font-size: 12px`;
256
- function B(s, t) {
254
+ n(q, "_requiredKeys");
255
+ const _ = "pinia-plugin-subscription", B = (s, t = "white") => `background-color: ${s}; color: ${t}; padding: 1px; margin-right: 5px; font-size: 12px`;
256
+ function D(s, t) {
257
257
  if (!s)
258
258
  throw new Error("Style instructions are required");
259
259
  console.log(
@@ -263,7 +263,7 @@ function B(s, t) {
263
263
  ...t
264
264
  );
265
265
  }
266
- class D {
266
+ class K {
267
267
  constructor() {
268
268
  n(this, "_bgColor", "#ffec73");
269
269
  n(this, "_color", "green");
@@ -280,7 +280,7 @@ class D {
280
280
  return ` [${e} ${_}] - ${t} `;
281
281
  }
282
282
  generateStyle(t) {
283
- return q(t.bgColor, t.color);
283
+ return B(t.bgColor, t.color);
284
284
  }
285
285
  getStyleDefinition(t) {
286
286
  return this._styles[t ?? "info"];
@@ -304,34 +304,34 @@ class D {
304
304
  return [this.formatMessage(t.shift(), e), ...t ?? []];
305
305
  }
306
306
  useLog(t, e) {
307
- B(
307
+ D(
308
308
  this.generateStyle(t),
309
309
  this.rebuildArgs(e, t.icon)
310
310
  );
311
311
  }
312
312
  }
313
- class K extends D {
313
+ class R extends K {
314
314
  constructor() {
315
315
  super(...arguments);
316
316
  n(this, "_pluginName", _);
317
317
  }
318
318
  }
319
- const F = new K();
319
+ const V = new R();
320
320
  export {
321
- D as C,
322
- C as D,
323
- F as P,
324
- P as S,
325
- H as a,
326
- N as b,
327
- w as c,
328
- L as d,
329
- E as e,
330
- T as f,
331
- W as g,
332
- I as h,
333
- M as i,
321
+ K as C,
322
+ A as D,
323
+ V as P,
324
+ q as S,
325
+ L as a,
326
+ T as b,
327
+ E as c,
328
+ N as d,
329
+ k as e,
330
+ W as f,
331
+ F as g,
332
+ w as h,
333
+ P as i,
334
334
  _ as p,
335
- k as s
335
+ M as s
336
336
  };
337
- //# sourceMappingURL=index-VL_PgzVK.js.map
337
+ //# sourceMappingURL=index-DKdl-fiq.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index-VL_PgzVK.js","sources":["../../src/core/PluginSubscriber.ts","../../src/system/Debug.ts","../../src/utils/store.ts","../../src/utils/validation/index.ts","../../src/core/Store.ts","../../src/utils/constantes.ts","../../src/system/log.ts"],"sourcesContent":["import Store from \"./Store\";\nimport type { PiniaPluginContext, Store as PiniaStore } from \"pinia\";\nimport type { AnyObject } from \"../types\";\nimport type {\n PluginExecutionOptions,\n PluginHydrationScheduler,\n PluginSubscriber as PluginSubscriberInterface,\n PluginSubscriptions,\n StoreMutationSubscription,\n StoreOnActionSubscription\n} from \"../types/plugin\";\nimport type { Console } from \"../types/log\";\n\n\ntype CreateInstance<Instance = Store> = (store: PiniaStore, options: AnyObject, debug: boolean, customConsole?: Console) => Instance | undefined\n\n\nexport default abstract class PluginSubscriber<Instance extends Store> implements PluginSubscriberInterface {\n private _console?: Console\n private _createInstance: CreateInstance\n private _name: string\n private _pluginOptions?: AnyObject\n private _storeInstance?: Instance\n protected _resetStoreCallback?: (store?: PiniaStore) => void\n private _storeOnActionSubscription?: StoreOnActionSubscription\n private _storeMutationSubscription?: StoreMutationSubscription\n private _subscriptions?: PluginSubscriptions\n protected pluginCreated?: (store: PiniaStore) => void\n public execution?: PluginExecutionOptions\n public hydrationScheduler?: PluginHydrationScheduler\n\n\n get console(): Console {\n return this._console ?? console\n }\n\n get name(): string {\n return this._name;\n }\n\n get storeInstance(): Instance | undefined {\n return this._storeInstance\n }\n\n get pluginOptions(): AnyObject {\n return this._pluginOptions ?? {};\n }\n\n set pluginOptions(options: AnyObject | undefined) {\n this._pluginOptions = options;\n }\n\n get resetStoreCallback(): ((store?: PiniaStore) => void) | undefined {\n return this._resetStoreCallback as ((store?: PiniaStore) => void) | undefined;\n }\n\n get storeOnActionSubscription(): StoreOnActionSubscription | undefined {\n return this._storeOnActionSubscription;\n }\n\n get storeMutationSubscription(): StoreMutationSubscription | undefined {\n return this._storeMutationSubscription;\n }\n\n get subscriptions(): PluginSubscriptions | undefined {\n return this._subscriptions\n }\n\n set subscriptions(subscriptions: PluginSubscriptions) {\n this._subscriptions = subscriptions\n }\n\n\n constructor(pluginName: string, createInstanceFunction: CreateInstance, pluginConsole?: Console) {\n this._name = pluginName\n this._createInstance = createInstanceFunction\n\n if (pluginConsole) {\n this._console = pluginConsole\n }\n }\n\n\n public afterHydration(context: PiniaPluginContext, debug: boolean): void | Promise<void> {\n return\n }\n\n public hydrate(context: PiniaPluginContext, debug: boolean): void | Promise<void> {\n return\n }\n\n public invoke(\n { store, options }: PiniaPluginContext,\n debug: boolean\n ): boolean {\n this._storeInstance = this._createInstance(store, { ...options, ...this.pluginOptions }, debug, this.console) as Instance\n\n if (!this._storeInstance) {\n return false\n }\n\n this._subscriptions = this._storeInstance.getSubscriptions()\n this._storeMutationSubscription = this._storeInstance.storeSubscribe\n this._storeOnActionSubscription = this._storeInstance.onAction\n\n if (this.pluginCreated) {\n this.pluginCreated(store)\n }\n\n return true\n }\n}","import type { Console } from \"../types/log\"\n\nexport default abstract class Debug {\n protected abstract _className: string\n private _console?: Console\n private _debug: boolean = false\n\n get console(): Console {\n return this._console ?? console\n }\n set console(customConsole: Console) {\n this._console = customConsole\n }\n\n get debug(): boolean { return this._debug }\n set debug(debug: boolean) { this._debug = debug }\n\n constructor(debug: boolean, customConsole?: Console) {\n this._debug = debug\n\n if (customConsole) {\n this._console = customConsole\n }\n }\n\n\n debugLog(...args: any): void {\n if (this._debug) {\n if (Array.isArray(args)) {\n args[0] = `${this._className} - ${args[0]}`\n }\n this.console.log(...args)\n }\n }\n\n logError(...args: any): void {\n this.console.error(...args)\n }\n}","import { defineStore } from \"pinia\"\nimport type {\n DefineSetupStoreOptions,\n DefineStoreOptions,\n SetupStoreDefinition,\n StateTree,\n Store,\n StoreDefinition,\n _ExtractActionsFromSetupStore,\n _ExtractGettersFromSetupStore,\n _ExtractStateFromSetupStore,\n _GettersTree\n} from \"pinia\"\nimport type { AnyObject } from \"../types\"\nimport type {\n DefineAStoreDefinition,\n DefineAStoreSetupContext,\n EmptyExtensions,\n PluginStoreOptions,\n StoreOptions\n} from \"../types/store\"\n\n\nexport const itemState = {\n '@id': undefined,\n id: undefined\n}\n\ntype DefineAStoreSetup<SS, TExtraExtensions extends Record<string, unknown> = EmptyExtensions> =\n (ctx: DefineAStoreSetupContext<SS, TExtraExtensions>) => SS\n\n/**\n * Options parameter of pinia's `defineStore()` for setup stores, derived from\n * the setup function return type.\n */\ntype DefineAStoreSetupOptions<Id extends string, SS> = DefineSetupStoreOptions<\n Id,\n _ExtractStateFromSetupStore<SS>,\n _ExtractGettersFromSetupStore<SS>,\n _ExtractActionsFromSetupStore<SS>\n>\n\nconst defineAStoreSetupContexts = new WeakMap<object, DefineAStoreSetupContext<AnyObject>>()\nconst defineAStoreSetupContextsById = new Map<string, DefineAStoreSetupContext<AnyObject>>()\nconst setupContextDisposeWrappedStores = new WeakSet<object>()\nconst setupContextMapWarnThreshold = 50\n\nfunction isSetupContextDebugEnabled(options: PluginStoreOptions): boolean {\n return options?.storeOptions?.debug === true\n}\n\nfunction logSetupContextMapSizes(id: string, options: PluginStoreOptions, action: string): void {\n if (!isSetupContextDebugEnabled(options)) {\n return\n }\n\n const setupContextByIdSize = defineAStoreSetupContextsById.size\n console.debug(`[defineAStoreSetup] ${id} - ${action} (contextsById=${setupContextByIdSize})`)\n\n if (setupContextByIdSize >= setupContextMapWarnThreshold) {\n console.warn(`[defineAStoreSetup] contextsById reached ${setupContextByIdSize} entries`)\n }\n}\n\nfunction registerSetupContextCleanupOnDispose(\n store: AnyObject,\n id: string,\n options: PluginStoreOptions\n): void {\n if (setupContextDisposeWrappedStores.has(store) || typeof store.$dispose !== 'function') {\n return\n }\n\n const originalDispose = store.$dispose as (...args: unknown[]) => unknown\n store.$dispose = (...args: unknown[]) => {\n defineAStoreSetupContexts.delete(store)\n defineAStoreSetupContextsById.delete(id)\n logSetupContextMapSizes(id, options, 'dispose cleanup')\n return originalDispose.apply(store, args)\n }\n setupContextDisposeWrappedStores.add(store)\n}\n\n/**\n * Define a store with the setup API. State, getters and actions are inferred\n * from the setup function return, exactly like pinia's `defineStore`, so\n * store members are listed by IDEs and action prototypes are preserved.\n * @template Id The type of the store identifier.\n * @template SS The type of the setup function return.\n * @param id The unique identifier for the store.\n * @param storeDefinition The setup function defining the store.\n * @param options Optional store options.\n * @returns The defined store.\n */\nexport function defineAStore<Id extends string, SS>(\n id: Id,\n storeDefinition: (ctx?: DefineAStoreSetupContext<AnyObject>) => SS,\n options?: StoreOptions\n): SetupStoreDefinition<Id, SS>\n/**\n * Define a store with the options API, mirroring pinia's `defineStore` inference.\n * @template Id The type of the store identifier.\n * @template S The type of the store's state.\n * @template G The type of the store's getters.\n * @template A The type of the store's actions.\n * @param id The unique identifier for the store.\n * @param storeDefinition The store options definition.\n * @param options Optional store options.\n * @returns The defined store.\n */\nexport function defineAStore<Id extends string, S extends StateTree = {}, G extends _GettersTree<S> = {}, A = {}>(\n id: Id,\n storeDefinition: Omit<DefineStoreOptions<Id, S, G, A>, 'id'>,\n options?: StoreOptions\n): StoreDefinition<Id, S, G, A>\n/**\n * Define a store with explicit store/state types, e.g. when plugins augment\n * the store with members not returned by the setup function.\n * @template Sto The type of the store.\n * @template Sta The type of the store's state.\n * @param id The unique identifier for the store.\n * @param storeDefinition The store definition, either as an options object or a setup function.\n * @param options Optional store options.\n * @returns The defined store.\n */\nexport function defineAStore<Sto, Sta>(\n id: string,\n storeDefinition:\n | Omit<DefineStoreOptions<string, StateTree & Sta, AnyObject, Partial<Sto>>, 'id'>\n | ((ctx?: DefineAStoreSetupContext<Sto & Sta>) => AnyObject),\n options?: StoreOptions\n): DefineAStoreDefinition<Sto, Sta>\nexport function defineAStore(\n id: string,\n storeDefinition:\n | Omit<DefineStoreOptions<string, StateTree, AnyObject, AnyObject>, 'id'>\n | DefineAStoreSetup<AnyObject>,\n options?: StoreOptions\n): StoreDefinition {\n const storeOptions: PluginStoreOptions = options ? { storeOptions: options } : {} as PluginStoreOptions\n\n return (typeof storeDefinition === 'function'\n ? defineAStoreSetup(\n id,\n storeDefinition as DefineAStoreSetup<AnyObject>,\n storeOptions\n )\n : defineAStoreOptionApi(\n id,\n storeDefinition,\n storeOptions\n )) as StoreDefinition\n}\n\n/**\n * Define a store with a required, fully typed setup context. State, getters\n * and actions are inferred from the setup function return.\n * @template Id The type of the store identifier.\n * @template SS The type of the setup function return.\n * @template TExtraExtensions The type of the store's extra extensions.\n * @param id The unique identifier for the store.\n * @param storeDefinition The setup function defining the store.\n * @param options Optional store options.\n * @returns The defined store with setup context.\n */\nexport function defineAStoreCtx<Id extends string, SS, TExtraExtensions extends Record<string, unknown> = EmptyExtensions>(\n id: Id,\n storeDefinition: (ctx: DefineAStoreSetupContext<AnyObject, TExtraExtensions>) => SS,\n options?: StoreOptions\n): SetupStoreDefinition<Id, SS>\n/**\n * Define a store with a setup context and explicit store/state types, e.g.\n * when plugins augment the store with members not returned by the setup function.\n * @template Sto The type of the store.\n * @template Sta The type of the store's state.\n * @template TExtraExtensions The type of the store's extra extensions.\n * @param id The unique identifier for the store.\n * @param storeDefinition The setup function defining the store.\n * @param options Optional store options.\n * @returns The defined store with setup context.\n */\nexport function defineAStoreCtx<Sto, Sta, TExtraExtensions extends Record<string, unknown> = EmptyExtensions>(\n id: string,\n storeDefinition: (ctx: DefineAStoreSetupContext<Sto & Sta, TExtraExtensions>) => AnyObject,\n options?: StoreOptions\n): DefineAStoreDefinition<Sto, Sta>\nexport function defineAStoreCtx(\n id: string,\n storeDefinition: DefineAStoreSetup<AnyObject, any>,\n options?: StoreOptions\n): StoreDefinition {\n const storeOptions: PluginStoreOptions = options\n ? { storeOptions: { ...options, enhancedStore: true } }\n : { storeOptions: { enhancedStore: true } } as PluginStoreOptions\n\n return defineAStoreSetup(\n id,\n storeDefinition,\n storeOptions\n ) as StoreDefinition\n}\n\nexport function defineAStoreSetup<Id extends string, SS>(\n id: Id,\n storeDefinition: DefineAStoreSetup<SS>,\n options: PluginStoreOptions\n): SetupStoreDefinition<Id, SS> {\n const setupContext: DefineAStoreSetupContext<SS> = {\n id,\n extensions: {}\n }\n\n const shouldStoreSetupContext = options?.storeOptions?.enhancedStore === true\n\n // `storeOptions` augments pinia's DefineStoreOptionsBase (see createPlugin.ts);\n // the assertion stays valid in compilation units where the augmentation is not loaded.\n const useStore = defineStore(\n id,\n () => storeDefinition(setupContext),\n options as unknown as DefineAStoreSetupOptions<Id, SS>\n )\n\n return Object.assign(((...args: Parameters<typeof useStore>) => {\n if (shouldStoreSetupContext) {\n defineAStoreSetupContextsById.set(id, setupContext as DefineAStoreSetupContext<AnyObject>)\n logSetupContextMapSizes(id, options, 'registered context by id')\n }\n\n const store = useStore(...args)\n\n if (shouldStoreSetupContext) {\n defineAStoreSetupContexts.set(store, setupContext as DefineAStoreSetupContext<AnyObject>)\n defineAStoreSetupContextsById.delete(id)\n logSetupContextMapSizes(id, options, 'moved context to weak map')\n registerSetupContextCleanupOnDispose(store as AnyObject, id, options)\n }\n\n return store\n }) as typeof useStore, useStore)\n}\n\nexport function defineAStoreOptionApi<Id extends string, S extends StateTree = {}, G extends _GettersTree<S> = {}, A = {}>(\n id: Id,\n storeDefinition: Omit<DefineStoreOptions<Id, S, G, A>, 'id'>,\n options?: PluginStoreOptions\n): StoreDefinition<Id, S, G, A> {\n if (options) {\n storeDefinition = { ...storeDefinition, ...(options ?? {}) }\n }\n\n return defineStore(id, storeDefinition)\n}\n\nconst deniedFirstChar = new Set<string>(['_', '$'])\n\n/**\n * Check if a property has a denied first character : ['_', '$'].\n * @param property The property name to check.\n * @returns True if the property has a denied first character, false otherwise.\n */\nexport function hasDeniedFirstChar(property: string): boolean {\n return deniedFirstChar.has(property[0] as string)\n}\n\n/**\n * Get the setup context associated with a store instance (or pending store id).\n * @param store The store instance, or an object exposing the store `$id`.\n * @returns The setup context when the store was defined with `enhancedStore` enabled, undefined otherwise.\n */\nexport function getDefineAStoreSetupContext(store: object): DefineAStoreSetupContext<AnyObject> | undefined {\n const storeRecord = store as AnyObject\n\n return defineAStoreSetupContexts.get(store)\n ?? (typeof storeRecord?.$id === 'string'\n ? defineAStoreSetupContextsById.get(storeRecord.$id)\n : undefined)\n}\n\n/**\n * Get the enhanced store from the context.\n * @template TEnhancedStore The type of the enhanced store.\n * @param ctx The context containing the extensions.\n * @returns The enhanced store casted to the specified types.\n */\nexport function getEnhancedStore<TEnhancedStore>(\n ctx: DefineAStoreSetupContext<TEnhancedStore>\n): TEnhancedStore {\n const enhancedStore = ctx.extensions.enhancedStore ?? ctx.extensions.extending\n\n if (!enhancedStore) {\n throw new Error(`${ctx.id}Store - getEnhancedStore - Error: enhanced store is required`)\n }\n\n return enhancedStore\n}\n\n/**\n * Set the enhanced store in context with deprecated alias support.\n * @template TEnhancedStore The type of the enhanced store.\n * @param ctx The context containing the extensions.\n * @param store The store to expose as enhancement.\n */\nexport function setEnhancedStore<TEnhancedStore>(\n ctx: DefineAStoreSetupContext<TEnhancedStore>,\n store: TEnhancedStore\n): void {\n ctx.extensions.enhancedStore = store\n ctx.extensions.extending = store\n}\n\n/**\n * @deprecated Use getEnhancedStore instead.\n */\nexport function getExtendingStore<TEnhancedStore>(\n ctx: DefineAStoreSetupContext<TEnhancedStore>\n): TEnhancedStore {\n console.warn(`${ctx.id}Store - getExtendingStore is deprecated. Use getEnhancedStore instead.`)\n return getEnhancedStore<TEnhancedStore>(ctx)\n}\n\n/**\n * Get the storage key for a given action and store combination.\n * @param actionName The name of the action.\n * @param store The Pinia store instance.\n * @returns The storage key for the action and store combination.\n */\nexport function getActionStoreKey(actionName: string, store: Store): string {\n return `${actionName}-${store.$id}`\n}","export function isEmpty(value: any): boolean {\n if (!value) {\n return (typeof value === 'boolean' || typeof value === 'number') ? false : true\n }\n\n if (Array.isArray(value)) {\n return value.length === 0\n }\n\n if (typeof value === 'object') {\n return Object.keys(value).length === 0\n }\n\n if (typeof value === 'string') {\n return value.trim() === ''\n }\n\n return false\n}","import { ref, toRef, type Ref } from \"vue\"\nimport Debug from \"../system/Debug\"\nimport { getDefineAStoreSetupContext, hasDeniedFirstChar, setEnhancedStore } from \"../utils/store\"\nimport { isEmpty } from \"../utils/validation\"\n\nimport type {\n PluginSubscriptions,\n StoreMutationSubscription,\n StoreMutationSubscriptionCallback,\n StoreMutationSubscriptionReturn,\n StoreOnActionSubscription,\n StoreOnActionSubscriptionCallback,\n StoreOnActionSubscriptionReturn\n} from \"../types/plugin\"\nimport type { Store as PiniaStore, StateTree } from \"pinia\"\nimport type { Console } from \"../types/log\"\nimport type { AnyObject, PluginSubscriberInterface } from \"../types\"\nimport type { StoreOptions, StatePropertyValue } from \"../types/store\"\n\n\nexport default class Store extends Debug {\n protected _className = 'Store'\n private _onAction?: StoreOnActionSubscriptionCallback\n private _options: StoreOptions\n private _store: PiniaStore\n private _subscriptions: PluginSubscriptions = {}\n private _storeSubscribe?: StoreMutationSubscriptionCallback\n\n protected static _requiredKeys?: string[]\n\n get onAction(): StoreOnActionSubscription | undefined {\n if (!this._onAction) {\n return\n }\n\n return () => ({\n store: this.store as PiniaStore,\n callback: this._onAction\n }) as StoreOnActionSubscriptionReturn\n }\n\n set onAction(onAction: StoreOnActionSubscriptionCallback) {\n this._onAction = onAction\n }\n\n get options(): StoreOptions { return this._options }\n\n get state(): StateTree { return this._store.$state }\n\n set state(state: StateTree) { this._store.$state = state }\n\n get store(): AnyObject { return this._store }\n\n get storeSubscribe(): StoreMutationSubscription | undefined {\n if (!this._storeSubscribe) {\n return\n }\n\n return () => ({\n store: this.store as PiniaStore,\n callback: this._storeSubscribe\n }) as StoreMutationSubscriptionReturn\n }\n\n set storeSubscribe(storeSubscribe: StoreMutationSubscriptionCallback) {\n this._storeSubscribe = storeSubscribe\n }\n\n\n constructor(store: PiniaStore, options: AnyObject, debug: boolean = false, customConsole?: Console) {\n super(debug, customConsole)\n this._options = options.storeOptions\n this._store = store\n\n if (this._options?.enhancedStore) {\n const ctx = getDefineAStoreSetupContext(this.store)\n\n if (ctx) {\n setEnhancedStore(ctx, this.store)\n }\n }\n }\n\n /**\n * Add property to state\n * @param name \n * @param value \n */\n addToState(name: string, value?: StatePropertyValue): void {\n if (!this.isOptionApi()) {\n if (!(value as Ref)?.value) {\n value = ref<StatePropertyValue>(value)\n }\n }\n\n this.state[name] = value\n this.store[name] = toRef(this.state, name)\n }\n\n addSubscription(\n pluginName: string,\n subscription: PluginSubscriberInterface,\n options?: { subscriptionOptions?: StoreOptions, stores?: PiniaStore[] }\n ): void {\n this._subscriptions[pluginName] = { subscription, ...(options ?? {}) }\n }\n\n afterHydration(): void | Promise<void> {\n return\n }\n\n /**\n * Create and return a class instance\n * @param store \n * @param options \n * @param debug \n * @returns \n */\n static customizeStore<Instance extends Store>(\n store: PiniaStore,\n options: AnyObject,\n debug: boolean = false,\n customConsole?: Console\n ): Instance | undefined {\n if (options.storeOptions && this.hasRequiredKeys(options.storeOptions)) {\n return new this(store, options, debug, customConsole) as Instance\n }\n }\n\n getOption(optionName: keyof StoreOptions) {\n return this.options && (this.options as StoreOptions)[optionName]\n }\n\n getStatePropertyValue(propertyName: string) {\n return this.getValue(this.state[propertyName])\n }\n\n getSubscriptions(): PluginSubscriptions | undefined {\n if (isEmpty(this._subscriptions)) {\n return\n }\n\n return this._subscriptions\n }\n\n getValue(value: any) {\n return value?.__v_isRef ? value.value : value\n }\n\n protected hasDeniedFirstChar(property: string): boolean {\n return hasDeniedFirstChar(property)\n }\n\n protected static hasRequiredKeys(options: AnyObject): boolean {\n return this._requiredKeys !== undefined && this._requiredKeys?.every(requiredKey => !!options[requiredKey])\n }\n\n hydrate(): void | Promise<void> {\n return\n }\n\n isOptionApi(): boolean { return this.store._isOptionsAPI }\n\n stateHas(property: string): boolean { return Object.prototype.hasOwnProperty.call(this.state, property) }\n\n storeHas(property: string): boolean { return Object.prototype.hasOwnProperty.call(this.store, property) }\n}","export const pluginName: string = 'pinia-plugin-subscription'","import { pluginName } from '../utils/constantes'\nimport type { Console, LogType, StyleDefinition, StyleDefinitions } from '../types/log'\n\n\nconst style = (bgColor: string, color: string = 'white') =>\n `background-color: ${bgColor}; color: ${color}; padding: 1px; margin-right: 5px; font-size: 12px`\n\n\nexport function log(logStyle: string, args: any) {\n if (!logStyle) {\n throw new Error('Style instructions are required')\n }\n\n console.log(\n '%c%s',\n logStyle,\n args.shift(),\n ...args\n )\n}\n\nexport abstract class CustomConsole implements Console {\n protected _bgColor: string = '#ffec73'\n protected _color: string = 'green'\n protected _icon: string = '🍍⚡'\n protected _errorBgColor: string = '#d24545'\n protected _errorColor: string = 'white'\n protected _errorIcon: string = '🍍⚠️'\n protected abstract _pluginName: string\n protected _styles: StyleDefinitions = {\n error: { bgColor: this._errorBgColor, color: this._errorColor, icon: this._errorIcon },\n info: { bgColor: this._bgColor, color: this._color, icon: this._icon }\n }\n\n protected formatMessage(message: string, icon: string): string {\n return ` [${icon} ${pluginName}] - ${message} `\n }\n\n protected generateStyle(styleDefinition: StyleDefinition): string {\n return style(styleDefinition.bgColor, styleDefinition.color)\n }\n\n protected getStyleDefinition(messageType?: LogType): StyleDefinition {\n return this._styles[messageType ?? 'info']\n }\n\n log(...args: any) {\n this.useLog(\n this.getStyleDefinition(),\n args\n )\n }\n\n error(...args: any) {\n const logType = 'error'\n this.useLog(\n this.getStyleDefinition(logType),\n args\n )\n }\n\n protected rebuildArgs(args: string | any[], icon: string) {\n if (typeof args === 'string') {\n return [this.formatMessage(args, icon)]\n }\n\n if (Array.isArray(args)) {\n return [this.formatMessage(args.shift(), icon), ...(args ?? [])]\n }\n }\n\n protected useLog(styleDefinition: StyleDefinition, args: any) {\n log(\n this.generateStyle(styleDefinition),\n this.rebuildArgs(args, styleDefinition.icon)\n )\n }\n}\n\nclass PluginConsoleClass extends CustomConsole {\n protected _pluginName: string = pluginName\n}\n\nexport const PluginConsole = new PluginConsoleClass()"],"names":["PluginSubscriber","pluginName","createInstanceFunction","pluginConsole","__publicField","options","subscriptions","context","debug","store","Debug","customConsole","args","defineAStoreSetupContexts","defineAStoreSetupContextsById","setupContextDisposeWrappedStores","setupContextMapWarnThreshold","isSetupContextDebugEnabled","logSetupContextMapSizes","id","action","setupContextByIdSize","registerSetupContextCleanupOnDispose","originalDispose","defineAStore","storeDefinition","storeOptions","defineAStoreSetup","defineAStoreOptionApi","defineAStoreCtx","setupContext","shouldStoreSetupContext","useStore","defineStore","deniedFirstChar","hasDeniedFirstChar","property","getDefineAStoreSetupContext","storeRecord","getEnhancedStore","ctx","enhancedStore","setEnhancedStore","getExtendingStore","getActionStoreKey","actionName","isEmpty","value","Store","onAction","state","storeSubscribe","name","ref","subscription","optionName","propertyName","requiredKey","style","bgColor","color","log","logStyle","CustomConsole","message","icon","styleDefinition","messageType","PluginConsoleClass","PluginConsole"],"mappings":";;;;;AAiBA,MAA8BA,EAA8E;AAAA,EAwDxG,YAAYC,GAAoBC,GAAwCC,GAAyB;AAvDzF,IAAAC,EAAA;AACA,IAAAA,EAAA;AACA,IAAAA,EAAA;AACA,IAAAA,EAAA;AACA,IAAAA,EAAA;AACE,IAAAA,EAAA;AACF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OACJsD,GAAAtD,GAAA;AACJ,IAAAiD;AAAA,MAEU,KAAA,cAAkCK,CAAc;AAAA,MACtD,KAAI,iBAA0B,IAAA;AAAA,IAC1B;AAAA,EAAsC;AAG1C;AACI,MAAAE,UAA2BL,EAAc;AAAA,EAAzC;AAAA;AAA+D,IAAA3D,EAAA,qBACnEH;AAAA;AAAA;AACJ,MAEUoE,IAAO,IAAkCD,EAAW;"}
1
+ {"version":3,"file":"index-DKdl-fiq.js","sources":["../../src/core/PluginSubscriber.ts","../../src/system/Debug.ts","../../src/utils/store.ts","../../src/utils/validation/index.ts","../../src/core/Store.ts","../../src/utils/constantes.ts","../../src/system/log.ts"],"sourcesContent":["import Store from \"./Store\";\nimport type { PiniaPluginContext, Store as PiniaStore } from \"pinia\";\nimport type { AnyObject } from \"../types\";\nimport type {\n PluginExecutionOptions,\n PluginHydrationScheduler,\n PluginSubscriber as PluginSubscriberInterface,\n PluginSubscriptions,\n StoreMutationSubscription,\n StoreOnActionSubscription\n} from \"../types/plugin\";\nimport type { Console } from \"../types/log\";\n\n\ntype CreateInstance<Instance = Store> = (store: PiniaStore, options: AnyObject, debug: boolean, customConsole?: Console) => Instance | undefined\n\n\nexport default abstract class PluginSubscriber<Instance extends Store> implements PluginSubscriberInterface {\n private _console?: Console\n private _createInstance: CreateInstance\n private _name: string\n private _pluginOptions?: AnyObject\n private _storeInstance?: Instance\n protected _resetStoreCallback?: (store?: PiniaStore) => void\n private _storeOnActionSubscription?: StoreOnActionSubscription\n private _storeMutationSubscription?: StoreMutationSubscription\n private _subscriptions?: PluginSubscriptions\n protected pluginCreated?: (store: PiniaStore) => void\n public execution?: PluginExecutionOptions\n public hydrationScheduler?: PluginHydrationScheduler\n\n\n get console(): Console {\n return this._console ?? console\n }\n\n get name(): string {\n return this._name;\n }\n\n get storeInstance(): Instance | undefined {\n return this._storeInstance\n }\n\n get pluginOptions(): AnyObject {\n return this._pluginOptions ?? {};\n }\n\n set pluginOptions(options: AnyObject | undefined) {\n this._pluginOptions = options;\n }\n\n get resetStoreCallback(): ((store?: PiniaStore) => void) | undefined {\n return this._resetStoreCallback as ((store?: PiniaStore) => void) | undefined;\n }\n\n get storeOnActionSubscription(): StoreOnActionSubscription | undefined {\n return this._storeOnActionSubscription;\n }\n\n get storeMutationSubscription(): StoreMutationSubscription | undefined {\n return this._storeMutationSubscription;\n }\n\n get subscriptions(): PluginSubscriptions | undefined {\n return this._subscriptions\n }\n\n set subscriptions(subscriptions: PluginSubscriptions) {\n this._subscriptions = subscriptions\n }\n\n\n constructor(pluginName: string, createInstanceFunction: CreateInstance, pluginConsole?: Console) {\n this._name = pluginName\n this._createInstance = createInstanceFunction\n\n if (pluginConsole) {\n this._console = pluginConsole\n }\n }\n\n\n public afterHydration(context: PiniaPluginContext, debug: boolean): void | Promise<void> {\n return\n }\n\n public hydrate(context: PiniaPluginContext, debug: boolean): void | Promise<void> {\n return\n }\n\n public invoke(\n { store, options }: PiniaPluginContext,\n debug: boolean\n ): boolean {\n this._storeInstance = this._createInstance(store, { ...options, ...this.pluginOptions }, debug, this.console) as Instance\n\n if (!this._storeInstance) {\n return false\n }\n\n this._subscriptions = this._storeInstance.getSubscriptions()\n this._storeMutationSubscription = this._storeInstance.storeSubscribe\n this._storeOnActionSubscription = this._storeInstance.onAction\n\n if (this.pluginCreated) {\n this.pluginCreated(store)\n }\n\n return true\n }\n}","import type { Console } from \"../types/log\"\n\nexport default abstract class Debug {\n protected abstract _className: string\n private _console?: Console\n private _debug: boolean = false\n\n get console(): Console {\n return this._console ?? console\n }\n set console(customConsole: Console) {\n this._console = customConsole\n }\n\n get debug(): boolean { return this._debug }\n set debug(debug: boolean) { this._debug = debug }\n\n constructor(debug: boolean, customConsole?: Console) {\n this._debug = debug\n\n if (customConsole) {\n this._console = customConsole\n }\n }\n\n\n debugLog(...args: any): void {\n if (this._debug) {\n if (Array.isArray(args)) {\n args[0] = `${this._className} - ${args[0]}`\n }\n this.console.log(...args)\n }\n }\n\n logError(...args: any): void {\n this.console.error(...args)\n }\n}","import { defineStore } from \"pinia\"\nimport type {\n DefineSetupStoreOptions,\n DefineStoreOptions,\n SetupStoreDefinition,\n StateTree,\n Store,\n StoreDefinition,\n _ExtractActionsFromSetupStore,\n _ExtractGettersFromSetupStore,\n _ExtractStateFromSetupStore,\n _GettersTree\n} from \"pinia\"\nimport type { AnyObject } from \"../types\"\nimport type {\n DefineAStoreDefinition,\n DefineAStoreSetupContext,\n EmptyExtensions,\n PluginStoreOptions,\n StoreOptions\n} from \"../types/store\"\n\n\nexport const itemState = {\n '@id': undefined,\n id: undefined\n}\n\ntype DefineAStoreSetup<SS, TExtraExtensions extends Record<string, unknown> = EmptyExtensions> =\n (ctx: DefineAStoreSetupContext<SS, TExtraExtensions>) => SS\n\n/**\n * Options parameter of pinia's `defineStore()` for setup stores, derived from\n * the setup function return type.\n */\ntype DefineAStoreSetupOptions<Id extends string, SS> = DefineSetupStoreOptions<\n Id,\n _ExtractStateFromSetupStore<SS>,\n _ExtractGettersFromSetupStore<SS>,\n _ExtractActionsFromSetupStore<SS>\n>\n\nconst defineAStoreSetupContexts = new WeakMap<object, DefineAStoreSetupContext<AnyObject>>()\nconst defineAStoreSetupContextsById = new Map<string, DefineAStoreSetupContext<AnyObject>>()\nconst setupContextDisposeWrappedStores = new WeakSet<object>()\nconst setupContextMapWarnThreshold = 50\n\nfunction isSetupContextDebugEnabled(options: PluginStoreOptions): boolean {\n return options?.storeOptions?.debug === true\n}\n\nfunction logSetupContextMapSizes(id: string, options: PluginStoreOptions, action: string): void {\n if (!isSetupContextDebugEnabled(options)) {\n return\n }\n\n const setupContextByIdSize = defineAStoreSetupContextsById.size\n console.debug(`[defineAStoreSetup] ${id} - ${action} (contextsById=${setupContextByIdSize})`)\n\n if (setupContextByIdSize >= setupContextMapWarnThreshold) {\n console.warn(`[defineAStoreSetup] contextsById reached ${setupContextByIdSize} entries`)\n }\n}\n\nfunction registerSetupContextCleanupOnDispose(\n store: AnyObject,\n id: string,\n options: PluginStoreOptions\n): void {\n if (setupContextDisposeWrappedStores.has(store) || typeof store.$dispose !== 'function') {\n return\n }\n\n const originalDispose = store.$dispose as (...args: unknown[]) => unknown\n store.$dispose = (...args: unknown[]) => {\n defineAStoreSetupContexts.delete(store)\n defineAStoreSetupContextsById.delete(id)\n logSetupContextMapSizes(id, options, 'dispose cleanup')\n return originalDispose.apply(store, args)\n }\n setupContextDisposeWrappedStores.add(store)\n}\n\n/**\n * Define a store with the setup API. State, getters and actions are inferred\n * from the setup function return, exactly like pinia's `defineStore`, so\n * store members are listed by IDEs and action prototypes are preserved.\n * @template Id The type of the store identifier.\n * @template SS The type of the setup function return.\n * @param id The unique identifier for the store.\n * @param storeDefinition The setup function defining the store.\n * @param options Optional store options.\n * @returns The defined store.\n */\nexport function defineAStore<Id extends string, SS>(\n id: Id,\n storeDefinition: (ctx?: DefineAStoreSetupContext<AnyObject>) => SS,\n options?: StoreOptions\n): SetupStoreDefinition<Id, SS>\n/**\n * Define a store with the options API, mirroring pinia's `defineStore` inference.\n * @template Id The type of the store identifier.\n * @template S The type of the store's state.\n * @template G The type of the store's getters.\n * @template A The type of the store's actions.\n * @param id The unique identifier for the store.\n * @param storeDefinition The store options definition.\n * @param options Optional store options.\n * @returns The defined store.\n */\nexport function defineAStore<Id extends string, S extends StateTree = {}, G extends _GettersTree<S> = {}, A = {}>(\n id: Id,\n storeDefinition: Omit<DefineStoreOptions<Id, S, G, A>, 'id'>,\n options?: StoreOptions\n): StoreDefinition<Id, S, G, A>\n/**\n * Define a store with explicit store/state types, e.g. when plugins augment\n * the store with members not returned by the setup function.\n * @template Sto The type of the store.\n * @template Sta The type of the store's state.\n * @param id The unique identifier for the store.\n * @param storeDefinition The store definition, either as an options object or a setup function.\n * @param options Optional store options.\n * @returns The defined store.\n */\nexport function defineAStore<Sto, Sta>(\n id: string,\n storeDefinition:\n | Omit<DefineStoreOptions<string, StateTree & Sta, AnyObject, Partial<Sto>>, 'id'>\n | ((ctx?: DefineAStoreSetupContext<Sto & Sta>) => AnyObject),\n options?: StoreOptions\n): DefineAStoreDefinition<Sto, Sta>\nexport function defineAStore(\n id: string,\n storeDefinition:\n | Omit<DefineStoreOptions<string, StateTree, AnyObject, AnyObject>, 'id'>\n | DefineAStoreSetup<AnyObject>,\n options?: StoreOptions\n): StoreDefinition {\n const storeOptions: PluginStoreOptions = options ? { storeOptions: options } : {} as PluginStoreOptions\n\n return (typeof storeDefinition === 'function'\n ? defineAStoreSetup(\n id,\n storeDefinition as DefineAStoreSetup<AnyObject>,\n storeOptions\n )\n : defineAStoreOptionApi(\n id,\n storeDefinition,\n storeOptions\n )) as StoreDefinition\n}\n\n/**\n * Define a store with a required, fully typed setup context. State, getters\n * and actions are inferred from the setup function return.\n * @template Id The type of the store identifier.\n * @template SS The type of the setup function return.\n * @template TExtraExtensions The type of the store's extra extensions.\n * @param id The unique identifier for the store.\n * @param storeDefinition The setup function defining the store.\n * @param options Optional store options.\n * @returns The defined store with setup context.\n */\nexport function defineAStoreCtx<Id extends string, SS, TExtraExtensions extends Record<string, unknown> = EmptyExtensions>(\n id: Id,\n storeDefinition: (ctx: DefineAStoreSetupContext<AnyObject, TExtraExtensions>) => SS,\n options?: StoreOptions\n): SetupStoreDefinition<Id, SS>\n/**\n * Define a store with a setup context and explicit store/state types, e.g.\n * when plugins augment the store with members not returned by the setup function.\n * @template Sto The type of the store.\n * @template Sta The type of the store's state.\n * @template TExtraExtensions The type of the store's extra extensions.\n * @param id The unique identifier for the store.\n * @param storeDefinition The setup function defining the store.\n * @param options Optional store options.\n * @returns The defined store with setup context.\n */\nexport function defineAStoreCtx<Sto, Sta, TExtraExtensions extends Record<string, unknown> = EmptyExtensions>(\n id: string,\n storeDefinition: (ctx: DefineAStoreSetupContext<Sto & Sta, TExtraExtensions>) => AnyObject,\n options?: StoreOptions\n): DefineAStoreDefinition<Sto, Sta>\nexport function defineAStoreCtx(\n id: string,\n storeDefinition: DefineAStoreSetup<AnyObject, any>,\n options?: StoreOptions\n): StoreDefinition {\n const storeOptions: PluginStoreOptions = options\n ? { storeOptions: { ...options, enhancedStore: true } }\n : { storeOptions: { enhancedStore: true } } as PluginStoreOptions\n\n return defineAStoreSetup(\n id,\n storeDefinition,\n storeOptions\n ) as StoreDefinition\n}\n\nexport function defineAStoreSetup<Id extends string, SS>(\n id: Id,\n storeDefinition: DefineAStoreSetup<SS>,\n options: PluginStoreOptions\n): SetupStoreDefinition<Id, SS> {\n const setupContext: DefineAStoreSetupContext<SS> = {\n id,\n extensions: {}\n }\n\n const shouldStoreSetupContext = options?.storeOptions?.enhancedStore === true\n\n // `storeOptions` augments pinia's DefineStoreOptionsBase (see createPlugin.ts);\n // the assertion stays valid in compilation units where the augmentation is not loaded.\n const useStore = defineStore(\n id,\n () => storeDefinition(setupContext),\n options as unknown as DefineAStoreSetupOptions<Id, SS>\n )\n\n return Object.assign(((...args: Parameters<typeof useStore>) => {\n if (shouldStoreSetupContext) {\n defineAStoreSetupContextsById.set(id, setupContext as DefineAStoreSetupContext<AnyObject>)\n logSetupContextMapSizes(id, options, 'registered context by id')\n }\n\n const store = useStore(...args)\n\n if (shouldStoreSetupContext) {\n defineAStoreSetupContexts.set(store, setupContext as DefineAStoreSetupContext<AnyObject>)\n defineAStoreSetupContextsById.delete(id)\n logSetupContextMapSizes(id, options, 'moved context to weak map')\n registerSetupContextCleanupOnDispose(store as AnyObject, id, options)\n }\n\n return store\n }) as typeof useStore, useStore)\n}\n\nexport function defineAStoreOptionApi<Id extends string, S extends StateTree = {}, G extends _GettersTree<S> = {}, A = {}>(\n id: Id,\n storeDefinition: Omit<DefineStoreOptions<Id, S, G, A>, 'id'>,\n options?: PluginStoreOptions\n): StoreDefinition<Id, S, G, A> {\n if (options) {\n storeDefinition = { ...storeDefinition, ...(options ?? {}) }\n }\n\n return defineStore(id, storeDefinition)\n}\n\nconst deniedFirstChar = new Set<string>(['_', '$'])\n\n/**\n * Check if a property has a denied first character : ['_', '$'].\n * @param property The property name to check.\n * @returns True if the property has a denied first character, false otherwise.\n */\nexport function hasDeniedFirstChar(property: string): boolean {\n return deniedFirstChar.has(property[0] as string)\n}\n\n/**\n * Get the setup context associated with a store instance (or pending store id).\n * @param store The store instance, or an object exposing the store `$id`.\n * @returns The setup context when the store was defined with `enhancedStore` enabled, undefined otherwise.\n */\nexport function getDefineAStoreSetupContext(store: object): DefineAStoreSetupContext<AnyObject> | undefined {\n const storeRecord = store as AnyObject\n\n return defineAStoreSetupContexts.get(store)\n ?? (typeof storeRecord?.$id === 'string'\n ? defineAStoreSetupContextsById.get(storeRecord.$id)\n : undefined)\n}\n\n/**\n * Get the enhanced store from the context.\n * @template TEnhancedStore The type of the enhanced store.\n * @param ctx The context containing the extensions.\n * @returns The enhanced store casted to the specified types.\n */\nexport function getEnhancedStore<TEnhancedStore>(\n ctx: DefineAStoreSetupContext<TEnhancedStore>\n): TEnhancedStore {\n const enhancedStore = ctx.extensions.enhancedStore ?? ctx.extensions.extending\n\n if (!enhancedStore) {\n throw new Error(`${ctx.id}Store - getEnhancedStore - Error: enhanced store is required`)\n }\n\n return enhancedStore\n}\n\n/**\n * Set the enhanced store in context with deprecated alias support.\n * @template TEnhancedStore The type of the enhanced store.\n * @param ctx The context containing the extensions.\n * @param store The store to expose as enhancement.\n */\nexport function setEnhancedStore<TEnhancedStore>(\n ctx: DefineAStoreSetupContext<TEnhancedStore>,\n store: TEnhancedStore\n): void {\n ctx.extensions.enhancedStore = store\n ctx.extensions.extending = store\n}\n\n/**\n * @deprecated Use getEnhancedStore instead.\n */\nexport function getExtendingStore<TEnhancedStore>(\n ctx: DefineAStoreSetupContext<TEnhancedStore>\n): TEnhancedStore {\n console.warn(`${ctx.id}Store - getExtendingStore is deprecated. Use getEnhancedStore instead.`)\n return getEnhancedStore<TEnhancedStore>(ctx)\n}\n\n/**\n * Get the storage key for a given action and store combination.\n * @param actionName The name of the action.\n * @param store The Pinia store instance.\n * @returns The storage key for the action and store combination.\n */\nexport function getActionStoreKey(actionName: string, store: Store): string {\n return `${actionName}-${store.$id}`\n}","export function isEmpty(value: any): boolean {\n if (!value) {\n return (typeof value === 'boolean' || typeof value === 'number') ? false : true\n }\n\n if (Array.isArray(value)) {\n return value.length === 0\n }\n\n if (typeof value === 'object') {\n return Object.keys(value).length === 0\n }\n\n if (typeof value === 'string') {\n return value.trim() === ''\n }\n\n return false\n}","import { isRef, ref, toRef } from \"vue\"\nimport Debug from \"../system/Debug\"\nimport { getDefineAStoreSetupContext, hasDeniedFirstChar, setEnhancedStore } from \"../utils/store\"\nimport { isEmpty } from \"../utils/validation\"\n\nimport type {\n PluginSubscriptions,\n StoreMutationSubscription,\n StoreMutationSubscriptionCallback,\n StoreMutationSubscriptionReturn,\n StoreOnActionSubscription,\n StoreOnActionSubscriptionCallback,\n StoreOnActionSubscriptionReturn\n} from \"../types/plugin\"\nimport type { Store as PiniaStore, StateTree } from \"pinia\"\nimport type { Console } from \"../types/log\"\nimport type { AnyObject, PluginSubscriberInterface } from \"../types\"\nimport type { StoreOptions, StatePropertyValue } from \"../types/store\"\n\n\nexport default class Store extends Debug {\n protected _className = 'Store'\n private _onAction?: StoreOnActionSubscriptionCallback\n private _options: StoreOptions\n private _store: PiniaStore\n private _subscriptions: PluginSubscriptions = {}\n private _storeSubscribe?: StoreMutationSubscriptionCallback\n\n protected static _requiredKeys?: string[]\n\n get onAction(): StoreOnActionSubscription | undefined {\n if (!this._onAction) {\n return\n }\n\n return () => ({\n store: this.store as PiniaStore,\n callback: this._onAction\n }) as StoreOnActionSubscriptionReturn\n }\n\n set onAction(onAction: StoreOnActionSubscriptionCallback) {\n this._onAction = onAction\n }\n\n get options(): StoreOptions { return this._options }\n\n get state(): StateTree { return this._store.$state }\n\n set state(state: StateTree) { this._store.$state = state }\n\n get store(): AnyObject { return this._store }\n\n get storeSubscribe(): StoreMutationSubscription | undefined {\n if (!this._storeSubscribe) {\n return\n }\n\n return () => ({\n store: this.store as PiniaStore,\n callback: this._storeSubscribe\n }) as StoreMutationSubscriptionReturn\n }\n\n set storeSubscribe(storeSubscribe: StoreMutationSubscriptionCallback) {\n this._storeSubscribe = storeSubscribe\n }\n\n\n constructor(store: PiniaStore, options: AnyObject, debug: boolean = false, customConsole?: Console) {\n super(debug, customConsole)\n this._options = options.storeOptions\n this._store = store\n\n if (this._options?.enhancedStore) {\n const ctx = getDefineAStoreSetupContext(this.store)\n\n if (ctx) {\n setEnhancedStore(ctx, this.store)\n }\n }\n }\n\n /**\n * Add property to state\n * @param name \n * @param value \n */\n addToState(name: string, value?: StatePropertyValue): void {\n if (!this.isOptionApi()) {\n if (!isRef(value)) {\n value = ref<StatePropertyValue>(value)\n }\n }\n\n this.state[name] = value\n this.store[name] = toRef(this.state, name)\n }\n\n addSubscription(\n pluginName: string,\n subscription: PluginSubscriberInterface,\n options?: { subscriptionOptions?: StoreOptions, stores?: PiniaStore[] }\n ): void {\n this._subscriptions[pluginName] = { subscription, ...(options ?? {}) }\n }\n\n afterHydration(): void | Promise<void> {\n return\n }\n\n /**\n * Create and return a class instance\n * @param store \n * @param options \n * @param debug \n * @returns \n */\n static customizeStore<Instance extends Store>(\n store: PiniaStore,\n options: AnyObject,\n debug: boolean = false,\n customConsole?: Console\n ): Instance | undefined {\n if (options.storeOptions && this.hasRequiredKeys(options.storeOptions)) {\n return new this(store, options, debug, customConsole) as Instance\n }\n }\n\n getOption(optionName: keyof StoreOptions) {\n return this.options && (this.options as StoreOptions)[optionName]\n }\n\n getStatePropertyValue(propertyName: string) {\n return this.getValue(this.state[propertyName])\n }\n\n getSubscriptions(): PluginSubscriptions | undefined {\n if (isEmpty(this._subscriptions)) {\n return\n }\n\n return this._subscriptions\n }\n\n getValue(value: any) {\n return value?.__v_isRef ? value.value : value\n }\n\n protected hasDeniedFirstChar(property: string): boolean {\n return hasDeniedFirstChar(property)\n }\n\n protected static hasRequiredKeys(options: AnyObject): boolean {\n return this._requiredKeys !== undefined && this._requiredKeys?.every(requiredKey => !!options[requiredKey])\n }\n\n hydrate(): void | Promise<void> {\n return\n }\n\n isOptionApi(): boolean { return this.store._isOptionsAPI }\n\n stateHas(property: string): boolean { return Object.prototype.hasOwnProperty.call(this.state, property) }\n\n storeHas(property: string): boolean { return Object.prototype.hasOwnProperty.call(this.store, property) }\n}","export const pluginName: string = 'pinia-plugin-subscription'","import { pluginName } from '../utils/constantes'\nimport type { Console, LogType, StyleDefinition, StyleDefinitions } from '../types/log'\n\n\nconst style = (bgColor: string, color: string = 'white') =>\n `background-color: ${bgColor}; color: ${color}; padding: 1px; margin-right: 5px; font-size: 12px`\n\n\nexport function log(logStyle: string, args: any) {\n if (!logStyle) {\n throw new Error('Style instructions are required')\n }\n\n console.log(\n '%c%s',\n logStyle,\n args.shift(),\n ...args\n )\n}\n\nexport abstract class CustomConsole implements Console {\n protected _bgColor: string = '#ffec73'\n protected _color: string = 'green'\n protected _icon: string = '🍍⚡'\n protected _errorBgColor: string = '#d24545'\n protected _errorColor: string = 'white'\n protected _errorIcon: string = '🍍⚠️'\n protected abstract _pluginName: string\n protected _styles: StyleDefinitions = {\n error: { bgColor: this._errorBgColor, color: this._errorColor, icon: this._errorIcon },\n info: { bgColor: this._bgColor, color: this._color, icon: this._icon }\n }\n\n protected formatMessage(message: string, icon: string): string {\n return ` [${icon} ${pluginName}] - ${message} `\n }\n\n protected generateStyle(styleDefinition: StyleDefinition): string {\n return style(styleDefinition.bgColor, styleDefinition.color)\n }\n\n protected getStyleDefinition(messageType?: LogType): StyleDefinition {\n return this._styles[messageType ?? 'info']\n }\n\n log(...args: any) {\n this.useLog(\n this.getStyleDefinition(),\n args\n )\n }\n\n error(...args: any) {\n const logType = 'error'\n this.useLog(\n this.getStyleDefinition(logType),\n args\n )\n }\n\n protected rebuildArgs(args: string | any[], icon: string) {\n if (typeof args === 'string') {\n return [this.formatMessage(args, icon)]\n }\n\n if (Array.isArray(args)) {\n return [this.formatMessage(args.shift(), icon), ...(args ?? [])]\n }\n }\n\n protected useLog(styleDefinition: StyleDefinition, args: any) {\n log(\n this.generateStyle(styleDefinition),\n this.rebuildArgs(args, styleDefinition.icon)\n )\n }\n}\n\nclass PluginConsoleClass extends CustomConsole {\n protected _pluginName: string = pluginName\n}\n\nexport const PluginConsole = new PluginConsoleClass()"],"names":["PluginSubscriber","pluginName","createInstanceFunction","pluginConsole","__publicField","options","subscriptions","context","debug","store","Debug","customConsole","args","defineAStoreSetupContexts","defineAStoreSetupContextsById","setupContextDisposeWrappedStores","setupContextMapWarnThreshold","isSetupContextDebugEnabled","logSetupContextMapSizes","id","action","setupContextByIdSize","registerSetupContextCleanupOnDispose","originalDispose","defineAStore","storeDefinition","storeOptions","defineAStoreSetup","defineAStoreOptionApi","defineAStoreCtx","setupContext","shouldStoreSetupContext","useStore","defineStore","deniedFirstChar","hasDeniedFirstChar","property","getDefineAStoreSetupContext","storeRecord","getEnhancedStore","ctx","enhancedStore","setEnhancedStore","getExtendingStore","getActionStoreKey","actionName","isEmpty","value","Store","onAction","state","storeSubscribe","name","isRef","ref","subscription","optionName","propertyName","requiredKey","style","bgColor","color","log","logStyle","CustomConsole","message","icon","styleDefinition","messageType","PluginConsoleClass","PluginConsole"],"mappings":";;;;;AAiBA,MAA8BA,EAA8E;AAAA,EAwDxG,YAAYC,GAAoBC,GAAwCC,GAAyB;AAvDzF,IAAAC,EAAA;AACA,IAAAA,EAAA;AACA,IAAAA,EAAA;AACA,IAAAA,EAAA;AACA,IAAAA,EAAA;AACE,IAAAA,EAAA;AACF,IAAAA,EAAA;AACA,IAAAA,EAAA;AACA,IAAAA,EAAA;AACE,IAAAA,EAAA;AACH,IAAAA,EAAA;AACA,IAAAA,EAAA;AA6CH,SAAK,QAAQH,GACb,KAAK,kBAAkBC,GAEnBC,MACA,KAAK,WAAWA;AAAA,EAExB;AAAA,EAhDA,IAAI,UAAmB;AACnB,WAAO,KAAK,YAAY;AAAA,EAC5B;AAAA,EAEA,IAAI,OAAe;AACf,WAAO,KAAK;AAAA,EAChB;AAAA,EAEA,IAAI,gBAAsC;AACtC,WAAO,KAAK;AAAA,EAChB;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A,EAAA,iBACR;AAAA,MACP,OAAA,EAAA,SAAA,KAAA,eAAA,OAAA,KAAA,aAAA,MAAA,KAAA,WAAA;AAAA,MACJ,MAAA,EAAA,SAAA,KAAA,UAAA,OAAA,KAAA,QAAA,MAAA,KAAA,MAAA;AAAA,IAEO;AAAA;AAAA,EACO,cAAmB6D,GAAAC,GAAA;AACnB,WAAiB,KAAAA,CAAA,IAAAjE,CAAA,OAAAgE,CAAA;AAAA,EACjB;AAAA,EACA,iBAAwB;AACxB,WAAAN,EAAsBQ,EAAA,SAAAA,EAAA,KAAA;AAAA,EACtB;AAAA,EAEA,mBAA4BC,GAAA;AAClC,WAAO,KAAE,QAASA,WAAoB;AAAA,EAA+C;AAAA,EAChB,OACzExD,GAAA;AAEU,SAAA;AAAA,MACN,KAAO,mBAAa;AAAA,MACxBA;AAAA,IAEU;AAAA,EACN;AAAA,EACJ,SAAAA,GAAA;AAGI,SAAA;AAAA,MACJ,KAAA,0BAAA;AAAA;IAGI;AAAA,EAAK;AAAA,EACuB,YACxBA,GAAAsD,GAAA;AAAA,QACJ,OAAAtD,KAAA;AACJ,aAAA,CAAA,KAAA,cAAAA,GAAAsD,CAAA,CAAA;AAGI,QAAA,MAAM,QAAUtD,CAAA;AAChB,aAAK,CAAA,KAAA,cAAAA,EAAA,MAAA,GAAAsD,CAAA,GAAA,GAAAtD,KAAA,CAAA,CAAA;AAAA,EAC8B;AAAA,EAC/B,OACJuD,GAAAvD,GAAA;AACJ,IAAAkD;AAAA,MAEU,KAAA,cAAkCK,CAAc;AAAA,MACtD,KAAI,iBAA0B,IAAA;AAAA,IAC1B;AAAA,EAAsC;AAG1C;AACI,MAAAE,UAA2BL,EAAc;AAAA,EAAzC;AAAA;AAA+D,IAAA5D,EAAA,qBACnEH;AAAA;AAAA;AACJ,MAEUqE,IAAO,IAAkCD,EAAW;"}
@@ -5,11 +5,13 @@ export default class PluginSubscription extends Debug {
5
5
  protected _className: string;
6
6
  private _hydrationScheduler;
7
7
  private _onActionSubscriptions;
8
+ private _onActionStores;
8
9
  private _onActionAfterSubscriptions;
9
10
  private _onActionOnErrorSubscriptions;
10
11
  private _options?;
11
12
  private _pluginDebug?;
12
13
  private _resetStoreCallback;
14
+ private _disposedStores;
13
15
  private _storeRollbackSnapshotsHandler;
14
16
  private _subscribers;
15
17
  private _subscribersDelivered;
package/dist/helpers.js CHANGED
@@ -1,4 +1,4 @@
1
- import { C as a, a as r, S as e, i } from "./chunks/index-VL_PgzVK.js";
1
+ import { C as a, a as r, S as e, i } from "./chunks/index-DKdl-fiq.js";
2
2
  export {
3
3
  a as CustomConsole,
4
4
  r as PluginSubscriber,
@@ -1,9 +1,9 @@
1
- var g = Object.defineProperty;
2
- var E = (n, s, t) => s in n ? g(n, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[s] = t;
3
- var a = (n, s, t) => E(n, typeof s != "symbol" ? s + "" : s, t);
4
- import { h as O, g as f, D as m, i as y, P as C } from "./chunks/index-VL_PgzVK.js";
5
- import { C as T, p as W, a as L, S as I, d as q, b as G, c as U, e as z, f as B, s as J } from "./chunks/index-VL_PgzVK.js";
6
- import { toRaw as _ } from "vue";
1
+ var E = Object.defineProperty;
2
+ var O = (n, s, t) => s in n ? E(n, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[s] = t;
3
+ var c = (n, s, t) => O(n, typeof s != "symbol" ? s + "" : s, t);
4
+ import { h as C, g as S, D as m, i as _, P as $ } from "./chunks/index-DKdl-fiq.js";
5
+ import { C as T, p as L, a as I, S as q, d as z, b as G, c as U, e as B, f as J, s as Q } from "./chunks/index-DKdl-fiq.js";
6
+ import { toRaw as A } from "vue";
7
7
  function u(n) {
8
8
  if (typeof structuredClone == "function")
9
9
  try {
@@ -29,33 +29,33 @@ function u(n) {
29
29
  s[t] = u(e);
30
30
  return s;
31
31
  }
32
- function $(n, s = "all") {
32
+ function w(n, s = "all") {
33
33
  if (Array.isArray(s)) {
34
34
  const t = {};
35
35
  for (const e of s)
36
- e in n && (t[e] = u(_(n[e])));
36
+ e in n && (t[e] = u(A(n[e])));
37
37
  return t;
38
38
  }
39
39
  if (s !== "all")
40
40
  throw new Error(`Invalid keys parameter: ${s}`);
41
- return u(_(n));
41
+ return u(A(n));
42
42
  }
43
- class v {
43
+ class R {
44
44
  constructor() {
45
- a(this, "_stateSnapshots", /* @__PURE__ */ new Map());
46
- a(this, "_storeHasRollbackSnapshots", /* @__PURE__ */ new Set());
47
- a(this, "_storeRollbackSnapshotsParams", /* @__PURE__ */ new Map());
45
+ c(this, "_stateSnapshots", /* @__PURE__ */ new Map());
46
+ c(this, "_storeHasRollbackSnapshots", /* @__PURE__ */ new Set());
47
+ c(this, "_storeRollbackSnapshotsParams", /* @__PURE__ */ new Map());
48
48
  }
49
49
  addRollbackAction(s) {
50
50
  typeof s.$rollbackAfterFailure != "function" && (s.$rollbackAfterFailure = async ({ action: t, stateKeys: e }, i = []) => {
51
51
  const r = s[t];
52
- if (typeof r != "function" || O(t))
52
+ if (typeof r != "function" || C(t))
53
53
  return;
54
54
  const o = !e || e.length === 0 ? "all" : e, h = this.saveStateSnapshot(s, t, o);
55
55
  try {
56
56
  await r.apply(s, i);
57
- } catch (c) {
58
- throw this.patchStore(h, s), c;
57
+ } catch (a) {
58
+ throw this.patchStore(h, s), a;
59
59
  } finally {
60
60
  this.removeStateSnapshot(h);
61
61
  }
@@ -63,17 +63,17 @@ class v {
63
63
  }
64
64
  createOnActionCallbacks(s, t) {
65
65
  const e = this._storeRollbackSnapshotsParams.get(
66
- f(s, t)
66
+ S(s, t)
67
67
  );
68
- if (!e || e.length === 0)
68
+ if (!e)
69
69
  return;
70
- const i = this.saveStateSnapshot(t, s, e);
70
+ const i = e.length === 0 ? "all" : e, r = this.saveStateSnapshot(t, s, i);
71
71
  return {
72
72
  after: () => {
73
- this.removeStateSnapshot(i);
73
+ this.removeStateSnapshot(r);
74
74
  },
75
75
  onError: () => {
76
- this.patchStore(i, t), this.removeStateSnapshot(i);
76
+ this.patchStore(r, t), this.removeStateSnapshot(r);
77
77
  }
78
78
  };
79
79
  }
@@ -81,7 +81,7 @@ class v {
81
81
  const e = s?.storeOptions?.rollbackAfterFailure;
82
82
  e && !this._storeHasRollbackSnapshots.has(t.$id) && (Object.keys(e).forEach((i) => {
83
83
  this._storeRollbackSnapshotsParams.set(
84
- f(i, t),
84
+ S(i, t),
85
85
  e[i]
86
86
  );
87
87
  }), this._storeHasRollbackSnapshots.add(t.$id)), this.addRollbackAction(t);
@@ -107,7 +107,7 @@ class v {
107
107
  s && this._stateSnapshots.delete(s);
108
108
  }
109
109
  saveStateSnapshot(s, t, e) {
110
- const i = $(
110
+ const i = w(
111
111
  s.$state,
112
112
  e
113
113
  ), r = /* @__PURE__ */ Symbol(`${s.$id}:${t}`);
@@ -117,11 +117,11 @@ class v {
117
117
  return this._storeHasRollbackSnapshots.has(s.$id);
118
118
  }
119
119
  }
120
- const A = "PluginSubscription", P = {
120
+ const k = "PluginSubscription", v = {
121
121
  environment: "both",
122
122
  hydration: "immediate"
123
123
  };
124
- function R(n) {
124
+ function P(n) {
125
125
  if (typeof window < "u" && typeof window.requestAnimationFrame == "function") {
126
126
  window.requestAnimationFrame(() => globalThis.setTimeout(n, 0));
127
127
  return;
@@ -131,49 +131,52 @@ function R(n) {
131
131
  function D(n) {
132
132
  return n !== void 0 && !Array.isArray(n);
133
133
  }
134
- class k extends m {
134
+ class g extends m {
135
135
  constructor(t, e, i) {
136
136
  const r = Array.isArray(e) ? e : void 0, o = D(e) ? e : i;
137
- super(Array.isArray(r) && !!r?.includes(A), C);
138
- a(this, "_className", A);
139
- a(this, "_hydrationScheduler");
140
- a(this, "_onActionSubscriptions", []);
141
- a(this, "_onActionAfterSubscriptions", {});
142
- a(this, "_onActionOnErrorSubscriptions", {});
143
- a(this, "_options");
144
- a(this, "_pluginDebug");
145
- a(this, "_resetStoreCallback", []);
146
- a(this, "_storeRollbackSnapshotsHandler", new v());
147
- a(this, "_subscribers", []);
148
- a(this, "_subscribersDelivered", /* @__PURE__ */ new Set());
149
- a(this, "_subscribersScheduled", /* @__PURE__ */ new Set());
150
- a(this, "_subscriptions", []);
151
- a(this, "_subscriptionsDelivered", /* @__PURE__ */ new Set());
152
- a(this, "_subscriptionsScheduled", /* @__PURE__ */ new Set());
153
- this._hydrationScheduler = o?.hydrationScheduler ?? R, this._options = o, this._pluginDebug = Array.isArray(r) ? r : void 0, this._subscribers = t;
137
+ super(Array.isArray(r) && !!r?.includes(k), $);
138
+ c(this, "_className", k);
139
+ c(this, "_hydrationScheduler");
140
+ c(this, "_onActionSubscriptions", /* @__PURE__ */ new Map());
141
+ c(this, "_onActionStores", /* @__PURE__ */ new Set());
142
+ c(this, "_onActionAfterSubscriptions", {});
143
+ c(this, "_onActionOnErrorSubscriptions", {});
144
+ c(this, "_options");
145
+ c(this, "_pluginDebug");
146
+ c(this, "_resetStoreCallback", /* @__PURE__ */ new Map());
147
+ c(this, "_disposedStores", /* @__PURE__ */ new WeakSet());
148
+ c(this, "_storeRollbackSnapshotsHandler", new R());
149
+ c(this, "_subscribers", []);
150
+ c(this, "_subscribersDelivered", /* @__PURE__ */ new Set());
151
+ c(this, "_subscribersScheduled", /* @__PURE__ */ new Set());
152
+ c(this, "_subscriptions", []);
153
+ c(this, "_subscriptionsDelivered", /* @__PURE__ */ new Set());
154
+ c(this, "_subscriptionsScheduled", /* @__PURE__ */ new Set());
155
+ this._hydrationScheduler = o?.hydrationScheduler ?? P, this._options = o, this._pluginDebug = Array.isArray(r) ? r : void 0, this._subscribers = t;
154
156
  }
155
157
  set subscribers(t) {
156
158
  this._subscribers = t;
157
159
  }
158
160
  get subscriptions() {
159
- if (!y(this._subscriptions))
161
+ if (!_(this._subscriptions))
160
162
  return this._subscriptions;
161
163
  }
162
164
  addOnActionAfterCallback(t, e, i) {
163
- const r = f(t, e);
165
+ const r = S(t, e);
164
166
  this._onActionAfterSubscriptions[r] || (this._onActionAfterSubscriptions[r] = []), this._onActionAfterSubscriptions[r]?.push(i);
165
167
  }
166
168
  addOnActionOnErrorCallback(t, e, i) {
167
- const r = f(t, e);
169
+ const r = S(t, e);
168
170
  this._onActionOnErrorSubscriptions[r] || (this._onActionOnErrorSubscriptions[r] = []), this._onActionOnErrorSubscriptions[r]?.push(i);
169
171
  }
170
- addResetStoreCallback(t) {
171
- this._resetStoreCallback.push(t);
172
+ addResetStoreCallback(t, e) {
173
+ this._resetStoreCallback.has(t) || this._resetStoreCallback.set(t, /* @__PURE__ */ new Set()), this._resetStoreCallback.get(t).add(e);
172
174
  }
173
175
  clearOnActionCallbacksSubscriptions(t) {
174
176
  delete this._onActionAfterSubscriptions[t], delete this._onActionOnErrorSubscriptions[t];
175
177
  }
176
178
  clearStoreTracking(t) {
179
+ this._onActionSubscriptions.delete(t), this._onActionStores.delete(t), this._resetStoreCallback.delete(t);
177
180
  const e = `-${t.$id}`;
178
181
  for (const i of Array.from(this._subscribersDelivered))
179
182
  i.endsWith(e) && this._subscribersDelivered.delete(i);
@@ -216,7 +219,7 @@ class k extends m {
216
219
  }
217
220
  definePluginExecution(t) {
218
221
  return {
219
- ...P,
222
+ ...v,
220
223
  ...this._options?.execution ?? {},
221
224
  ...t.execution ?? {},
222
225
  ...this._options?.subscriberExecution?.[t.name] ?? {}
@@ -232,25 +235,29 @@ class k extends m {
232
235
  return `${t}-${e.$id}`;
233
236
  }
234
237
  executeResetStoreCallbacks(t) {
235
- this._resetStoreCallback.forEach((e) => e(t));
238
+ this._resetStoreCallback.get(t)?.forEach((e) => e(t));
236
239
  }
237
240
  executeStoreOnActionSubscription(t) {
238
- const e = this._onActionSubscriptions, i = this._storeRollbackSnapshotsHandler.storeHasRollbackSnapshots(t);
239
- !e?.length && !i || t.$onAction(({ after: r, args: o, name: h, onError: c }) => {
240
- const l = f(h, t);
241
- this.debugLog(`storeOnActionSubscription ${l}`, { args: o, name: h, store: t }), i && this.createRollbackSnapshot(h, t), e?.length && e.forEach((b) => b({
241
+ if (this._onActionStores.has(t) || typeof t.$onAction != "function")
242
+ return;
243
+ const e = this._onActionSubscriptions.get(t), i = this._storeRollbackSnapshotsHandler.storeHasRollbackSnapshots(t);
244
+ !e?.size && !i || (this._onActionStores.add(t), t.$onAction(({ after: r, args: o, name: h, onError: a }) => {
245
+ const l = S(h, t);
246
+ this.debugLog(`storeOnActionSubscription ${l}`, { args: o, name: h, store: t }), this._storeRollbackSnapshotsHandler.storeHasRollbackSnapshots(t) && this.createRollbackSnapshot(h, t);
247
+ const d = this._onActionSubscriptions.get(t);
248
+ d?.size && d.forEach((b) => b({
242
249
  after: this.createOnActionAfterCallbackCollector(h, t),
243
250
  args: o,
244
251
  name: h,
245
252
  onError: this.createOnActionOnErrorCallbackCollector(h, t)
246
253
  }));
247
- const d = this._onActionAfterSubscriptions[l], S = this._onActionOnErrorSubscriptions[l];
248
- this.clearOnActionCallbacksSubscriptions(l), d?.length && r((b) => {
249
- d.forEach((p) => p(b));
250
- }), S?.length && c((b) => {
251
- S.forEach((p) => p(b));
254
+ const p = this._onActionAfterSubscriptions[l], y = this._onActionOnErrorSubscriptions[l];
255
+ this.clearOnActionCallbacksSubscriptions(l), p?.length && r((b) => {
256
+ p.forEach((f) => f(b));
257
+ }), y?.length && a((b) => {
258
+ y.forEach((f) => f(b));
252
259
  });
253
- });
260
+ }));
254
261
  }
255
262
  executeSubscriber(t, e) {
256
263
  const i = this.defineSubscriberKey(e, t.store), r = this.definePluginDebug(e);
@@ -263,19 +270,19 @@ class k extends m {
263
270
  let o;
264
271
  try {
265
272
  o = e.hydrate?.(t, r);
266
- } catch (c) {
267
- this.logError(c, t.store, t.options);
273
+ } catch (a) {
274
+ this.logError(a, t.store, t.options);
268
275
  return;
269
276
  }
270
277
  const h = () => {
271
278
  try {
272
- const c = e.afterHydration?.(t, r);
273
- c && typeof c.then == "function" && c.catch((l) => this.logError(l, t.store, t.options));
274
- } catch (c) {
275
- this.logError(c, t.store, t.options);
279
+ const a = e.afterHydration?.(t, r);
280
+ a && typeof a.then == "function" && a.catch((l) => this.logError(l, t.store, t.options));
281
+ } catch (a) {
282
+ this.logError(a, t.store, t.options);
276
283
  }
277
284
  };
278
- o && typeof o.then == "function" ? o.then(() => h()).catch((c) => this.logError(c, t.store, t.options)) : h(), e.subscriptions && this.subscriptionDelivery(t, e.subscriptions), e.storeMutationSubscription && this.storeMutationSubscription(e.storeMutationSubscription), this.storeOnActionSubscription(e), e.resetStoreCallback && this.addResetStoreCallback(e.resetStoreCallback);
285
+ o && typeof o.then == "function" ? o.then(() => h()).catch((a) => this.logError(a, t.store, t.options)) : h(), e.subscriptions && this.subscriptionDelivery(t, e.subscriptions), e.storeMutationSubscription && this.storeMutationSubscription(e.storeMutationSubscription), this.storeOnActionSubscription(e), e.resetStoreCallback && this.addResetStoreCallback(t.store, e.resetStoreCallback);
279
286
  }
280
287
  executeSubscriberSafely(t, e) {
281
288
  try {
@@ -315,14 +322,14 @@ class k extends m {
315
322
  queueSubscriberExecution(t, e, i) {
316
323
  const r = this.defineHydrationScheduler(e);
317
324
  this._subscribersScheduled.add(i), r(() => {
318
- this._subscribersScheduled.delete(i), this.executeSubscriberSafely(t, e);
325
+ this._disposedStores.has(t.store) || (this._subscribersScheduled.delete(i), this.executeSubscriberSafely(t, e));
319
326
  });
320
327
  }
321
328
  registerStoreCleanup(t) {
322
- if (this._onActionSubscriptions = [], typeof t.$dispose != "function")
329
+ if (typeof t.$dispose != "function")
323
330
  return;
324
331
  const e = t.$dispose.bind(t), i = t;
325
- i.__piniaPluginSubscriptionDisposed || (i.__piniaPluginSubscriptionDisposed = !0, t.$dispose = () => (this.clearStoreTracking(t), this._storeRollbackSnapshotsHandler.clearStoreTracking(t), e()));
332
+ i.__piniaPluginSubscriptionDisposed || (i.__piniaPluginSubscriptionDisposed = !0, t.$dispose = () => (this._disposedStores.add(t), this.clearStoreTracking(t), this._storeRollbackSnapshotsHandler.clearStoreTracking(t), e()));
326
333
  }
327
334
  rewriteResetStore({ store: t }, e) {
328
335
  const i = u(e);
@@ -339,7 +346,7 @@ class k extends m {
339
346
  }
340
347
  storeOnActionSubscription(t) {
341
348
  const { store: e, callback: i } = t?.storeOnActionSubscription?.() ?? {};
342
- !e || !i || this._onActionSubscriptions.push(i);
349
+ !e || !i || (this._onActionSubscriptions.has(e) || this._onActionSubscriptions.set(e, /* @__PURE__ */ new Set()), this._onActionSubscriptions.get(e).add(i), this.executeStoreOnActionSubscription(e));
343
350
  }
344
351
  storeMutationSubscription(t) {
345
352
  const { store: e, callback: i } = t();
@@ -352,9 +359,9 @@ class k extends m {
352
359
  const o = this.defineSubscriptionKey(i, t.store), h = this.definePluginExecution(r.subscription);
353
360
  if (!(this._subscriptionsDelivered.has(o) || this._subscriptionsScheduled.has(o)) && this.shouldInvokePlugin(h)) {
354
361
  if (this.shouldScheduleAfterHydration(h)) {
355
- const c = this.defineHydrationScheduler(r.subscription);
356
- this._subscriptionsScheduled.add(o), c(() => {
357
- this._subscriptionsScheduled.delete(o), this.subscriptionDeliverySafely(t, i, r);
362
+ const a = this.defineHydrationScheduler(r.subscription);
363
+ this._subscriptionsScheduled.add(o), a(() => {
364
+ this._disposedStores.has(t.store) || (this._subscriptionsScheduled.delete(o), this.subscriptionDeliverySafely(t, i, r));
358
365
  });
359
366
  return;
360
367
  }
@@ -366,7 +373,7 @@ class k extends m {
366
373
  try {
367
374
  if (this._subscriptionsDelivered.has(this.defineSubscriptionKey(i, t)))
368
375
  return;
369
- const { subscription: o, subscriptionOptions: h, stores: c } = r;
376
+ const { subscription: o, subscriptionOptions: h, stores: a } = r;
370
377
  this.debugLog(`subscriptionDelivery() - store: ${t.$id}`, [
371
378
  "pluginName:",
372
379
  i,
@@ -375,7 +382,7 @@ class k extends m {
375
382
  "options:",
376
383
  r,
377
384
  "stores:",
378
- c
385
+ a
379
386
  ]);
380
387
  const l = {
381
388
  storeOptions: { ...e?.storeOptions ?? {}, ...h }
@@ -383,7 +390,7 @@ class k extends m {
383
390
  o.invoke(
384
391
  { store: t, options: { ...e, ...l } },
385
392
  this.debug
386
- ), this._subscriptionsDelivered.add(this.defineSubscriptionKey(i, t)), y(c) || c?.forEach(
393
+ ), this._subscriptionsDelivered.add(this.defineSubscriptionKey(i, t)), _(a) || a?.forEach(
387
394
  (d) => o.invoke(
388
395
  {
389
396
  store: d,
@@ -401,12 +408,12 @@ class k extends m {
401
408
  }
402
409
  }
403
410
  }
404
- function j(n, s) {
405
- const t = new k(n, s);
411
+ function K(n, s) {
412
+ const t = new g(n, s);
406
413
  return t.plugin.bind(t);
407
414
  }
408
- function K(n, s) {
409
- const t = new k(n, s?.debug, {
415
+ function M(n, s) {
416
+ const t = new g(n, s?.debug, {
410
417
  execution: s?.execution,
411
418
  hydrationScheduler: s?.hydrationScheduler,
412
419
  runtimeEnvironment: s?.runtimeEnvironment,
@@ -416,18 +423,18 @@ function K(n, s) {
416
423
  }
417
424
  export {
418
425
  T as CustomConsole,
419
- W as PLUGIN_NAME,
420
- L as PluginSubscriber,
421
- k as PluginSubscription,
422
- I as Store,
423
- K as createHydrationPlugin,
424
- j as createPlugin,
425
- q as defineAStore,
426
+ L as PLUGIN_NAME,
427
+ I as PluginSubscriber,
428
+ g as PluginSubscription,
429
+ q as Store,
430
+ M as createHydrationPlugin,
431
+ K as createPlugin,
432
+ z as defineAStore,
426
433
  G as defineAStoreCtx,
427
434
  U as getDefineAStoreSetupContext,
428
- z as getEnhancedStore,
429
- B as getExtendingStore,
430
- y as isEmpty,
431
- J as setEnhancedStore
435
+ B as getEnhancedStore,
436
+ J as getExtendingStore,
437
+ _ as isEmpty,
438
+ Q as setEnhancedStore
432
439
  };
433
440
  //# sourceMappingURL=pinia-plugin-subscription.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"pinia-plugin-subscription.js","sources":["../src/utils/deep-clone.ts","../src/factories/state-snapshot.ts","../src/core/RollbackStateSnapshotsHandler.ts","../src/core/PluginSubscription.ts"],"sourcesContent":["/**\n * Deeply clones the provided value, handling objects, arrays, maps, and sets. Uses `structuredClone` if available, otherwise falls back to a manual deep clone.\n * @template T The type of the value to deep clone.\n * @param value The value to deep clone.\n * @returns A deep clone of the provided value.\n */\nexport function deepClone<T>(value: T): T {\n if (typeof structuredClone === 'function') {\n try {\n return structuredClone(value)\n } catch {\n // fall through to the safe manual clone below\n }\n }\n\n if (value === null || typeof value !== 'object') {\n return value\n }\n\n if (value instanceof Map) {\n return new Map(\n Array.from(value.entries(), ([key, entryValue]) => [deepClone(key), deepClone(entryValue)])\n ) as T\n }\n\n if (value instanceof Set) {\n return new Set(Array.from(value.values(), entryValue => deepClone(entryValue))) as T\n }\n\n if (Array.isArray(value)) {\n return value.map(item => deepClone(item)) as T\n }\n\n if (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null) {\n return Object.fromEntries(\n Object.entries(value as Record<string, unknown>).map(([key, item]) => [key, deepClone(item)])\n ) as T\n }\n\n const clonedObject = Object.create(Object.getPrototypeOf(value)) as Record<string, unknown>\n for (const [key, item] of Object.entries(value as Record<string, unknown>)) {\n clonedObject[key] = deepClone(item)\n }\n\n return clonedObject as T\n}","import { toRaw } from 'vue'\nimport { deepClone } from '../utils/deep-clone'\n\nimport type { StateTree } from 'pinia'\nimport type { CreateStateSnapshotKeys } from '../types/plugin'\n\n\nexport function createStateSnapshot(state: StateTree, keys: CreateStateSnapshotKeys = 'all') {\n if (Array.isArray(keys)) {\n const clonedState: Partial<StateTree> = {}\n for (const key of keys) {\n if (key in state) {\n clonedState[key] = deepClone(toRaw(state[key]))\n }\n }\n return clonedState\n }\n\n if (keys !== 'all') {\n throw new Error(`Invalid keys parameter: ${keys}`)\n }\n\n return deepClone(toRaw(state))\n}","import { createStateSnapshot } from \"../factories/state-snapshot\"\nimport { getActionStoreKey, hasDeniedFirstChar } from '../utils/store'\n\nimport type { PiniaPluginContext, StateTree, Store } from 'pinia'\nimport type { AnyObject } from '../types'\nimport type { CreateStateSnapshotKeys } from '../types/plugin'\nimport type { RollbackActionParams } from '../types/store'\n\n\n/**\n * Handles rollback state snapshots for Pinia stores.\n * This class provides methods to add rollback actions to stores,\n * create rollback snapshots, and manage the state snapshots internally.\n */\nexport default class RollbackStateSnapshotsHandler {\n private _stateSnapshots: Map<symbol, StateTree> = new Map()\n private _storeHasRollbackSnapshots: Set<string> = new Set()\n private _storeRollbackSnapshotsParams: Map<string, CreateStateSnapshotKeys> = new Map()\n\n\n /**\n * Adds a rollback action to the given store.\n * This method extends the store with a $rollbackAfterFailure function that handles rollback logic for actions.\n * The action arguments are forwarded through apply(), so they must be provided as a single array.\n * @param {Store} store The store to which the rollback action will be added.\n * @returns void\n */\n addRollbackAction(store: Store): void {\n if (typeof store.$rollbackAfterFailure === 'function') {\n return\n }\n\n store.$rollbackAfterFailure = async ({ action, stateKeys }: RollbackActionParams, args: any[] = []) => {\n const actionFn = (store as AnyObject)[action]\n if (typeof actionFn !== 'function' || hasDeniedFirstChar(action)) {\n return\n }\n\n const keys: CreateStateSnapshotKeys = !stateKeys || stateKeys.length === 0 ? 'all' : stateKeys\n\n const snapshotKey = this.saveStateSnapshot(store, action, keys)\n try {\n await actionFn.apply(store, args)\n } catch (error) {\n this.patchStore(snapshotKey, store)\n throw error\n } finally {\n this.removeStateSnapshot(snapshotKey)\n }\n }\n }\n\n /**\n * Creates a rollback snapshot for the specified action and store.\n * This snapshot can be used to restore the store's state in case of an error during the action execution.\n * @param {string} actionName The name of the action for which the rollback snapshot is created.\n * @param {Store} store The Pinia store instance.\n * @returns An object containing `after` and `onError` callbacks for handling the rollback, or `undefined` if no snapshot is created.\n */\n createOnActionCallbacks(\n actionName: string,\n store: Store\n ): {\n after: () => void,\n onError: () => void\n } | undefined {\n const stateKeys = this._storeRollbackSnapshotsParams.get(\n getActionStoreKey(actionName, store)\n )\n\n if (!stateKeys || stateKeys.length === 0) {\n return\n }\n\n const snapshotKey = this.saveStateSnapshot(store, actionName, stateKeys)\n\n return {\n after: () => { this.removeStateSnapshot(snapshotKey) },\n onError: () => {\n this.patchStore(snapshotKey, store)\n this.removeStateSnapshot(snapshotKey)\n }\n }\n }\n\n /**\n * Initializes the rollback state snapshots handler from the given Pinia plugin context.\n * This method extracts the rollback snapshot parameters from the store options and stores them internally.\n * @param {PiniaPluginContext} param0 The Pinia plugin context containing the store and its options.\n * @returns void\n */\n initFromPluginContext({ options, store }: PiniaPluginContext) {\n const rollbackSnapshotParams = options?.storeOptions?.rollbackAfterFailure as Record<string, CreateStateSnapshotKeys>\n if (rollbackSnapshotParams && !this._storeHasRollbackSnapshots.has(store.$id)) {\n Object.keys(rollbackSnapshotParams).forEach(key => {\n this._storeRollbackSnapshotsParams.set(\n getActionStoreKey(key, store),\n rollbackSnapshotParams[key]\n )\n })\n this._storeHasRollbackSnapshots.add(store.$id)\n }\n this.addRollbackAction(store)\n }\n\n /**\n * Clears all rollback tracking data for the given store.\n * Must be called when the store is disposed to avoid memory leaks with dynamically created stores.\n * @param {Store} store The disposed Pinia store instance.\n * @returns void\n */\n clearStoreTracking(store: Store): void {\n const suffix = `-${store.$id}`\n\n for (const key of Array.from(this._storeRollbackSnapshotsParams.keys())) {\n if (key.endsWith(suffix)) {\n this._storeRollbackSnapshotsParams.delete(key)\n }\n }\n\n this._storeHasRollbackSnapshots.delete(store.$id)\n\n for (const snapshotKey of Array.from(this._stateSnapshots.keys())) {\n if (snapshotKey.description?.startsWith(`${store.$id}:`)) {\n this._stateSnapshots.delete(snapshotKey)\n }\n }\n }\n\n private patchStore(snapshotKey: symbol, store: Store): void {\n const stateSnapshot = this._stateSnapshots.get(snapshotKey)\n if (!stateSnapshot) {\n return\n }\n\n try {\n store.$patch(stateSnapshot)\n } catch (error) {\n console.error(`Failed to patch store with snapshot ${String(snapshotKey)}`, error)\n }\n }\n\n /**\n * Removes a state snapshot identified by the given snapshot key from the internal state snapshot tracking.\n * @param snapshotKey The key of the state snapshot to be removed.\n * @returns void\n */\n private removeStateSnapshot(snapshotKey?: symbol): void {\n if (!snapshotKey) {\n return\n }\n\n this._stateSnapshots.delete(snapshotKey)\n }\n\n /**\n * Saves the current state snapshot for a given store and action.\n * @param store The Pinia store instance.\n * @param actionName The name of the action being executed.\n * @param stateKeys The state keys to include in the snapshot, or 'all' for the full state.\n * @returns A unique symbol key representing the saved snapshot.\n */\n private saveStateSnapshot(store: Store, actionName: string, stateKeys: CreateStateSnapshotKeys): symbol {\n const stateSnapshot = createStateSnapshot(\n store.$state,\n stateKeys\n )\n\n const snapshotKey = Symbol(`${store.$id}:${actionName}`)\n this._stateSnapshots.set(snapshotKey, stateSnapshot)\n return snapshotKey\n }\n\n /**\n * Checks if the given store has rollback snapshots.\n * @param store The Pinia store instance.\n * @returns True if the store has rollback snapshots, false otherwise.\n */\n storeHasRollbackSnapshots(store: Store): boolean {\n return this._storeHasRollbackSnapshots.has(store.$id)\n }\n}","import Debug from \"../system/Debug\"\nimport RollbackStateSnapshotsHandler from \"./RollbackStateSnapshotsHandler\"\nimport { deepClone } from '../utils/deep-clone'\nimport { getActionStoreKey } from '../utils/store'\nimport { PluginConsole } from \"../system/log\"\nimport { isEmpty } from \"../utils/validation\"\n\nimport type { PiniaPluginContext, StateTree, Store, SubscriptionCallbackMutation } from \"pinia\"\nimport type { AnyObject } from \"../types\"\nimport type {\n PluginExecutionOptions,\n PluginHydrationScheduler,\n PluginRuntimeEnvironment,\n PluginSubscriber,\n PluginSubscription as PluginSubscriptionDefinition,\n PluginSubscriptionOptions,\n PluginSubscriptions,\n StoreMutationSubscription,\n StoreOnActionAfterCallbackParameter,\n StoreOnActionSubscriptionCallback\n} from \"../types/plugin\"\n\n\nconst className = 'PluginSubscription'\nconst defaultPluginExecution: Required<PluginExecutionOptions> = {\n environment: 'both',\n hydration: 'immediate'\n}\n\nfunction defaultHydrationScheduler(callback: () => void): void {\n if (typeof window !== 'undefined' && typeof window.requestAnimationFrame === 'function') {\n window.requestAnimationFrame(() => globalThis.setTimeout(callback, 0))\n return\n }\n\n globalThis.setTimeout(callback, 0)\n}\n\nfunction isPluginSubscriptionOptions(\n value: PluginSubscriptionOptions | string[] | undefined\n): value is PluginSubscriptionOptions {\n return value !== undefined && !Array.isArray(value)\n}\n\n\nexport default class PluginSubscription extends Debug {\n protected _className: string = className\n private _hydrationScheduler: PluginHydrationScheduler\n private _onActionSubscriptions: StoreOnActionSubscriptionCallback[] = []\n private _onActionAfterSubscriptions: Record<string, StoreOnActionAfterCallbackParameter[]> = {}\n private _onActionOnErrorSubscriptions: Record<string, Array<(error: unknown) => void>> = {}\n private _options?: PluginSubscriptionOptions\n private _pluginDebug?: string[]\n private _resetStoreCallback: Function[] = []\n private _storeRollbackSnapshotsHandler: RollbackStateSnapshotsHandler = new RollbackStateSnapshotsHandler()\n private _subscribers: PluginSubscriber[] = []\n private _subscribersDelivered: Set<string> = new Set()\n private _subscribersScheduled: Set<string> = new Set()\n private _subscriptions: PluginSubscriptions[] = []\n private _subscriptionsDelivered: Set<string> = new Set()\n private _subscriptionsScheduled: Set<string> = new Set()\n\n set subscribers(subscribers: PluginSubscriber[]) {\n this._subscribers = subscribers\n }\n\n get subscriptions(): PluginSubscriptions[] | undefined {\n if (!isEmpty(this._subscriptions)) {\n return this._subscriptions\n }\n }\n\n constructor(\n subscribers: PluginSubscriber[],\n debugOrOptions?: PluginSubscriptionOptions | string[],\n pluginOptions?: PluginSubscriptionOptions\n ) {\n const debug = Array.isArray(debugOrOptions) ? debugOrOptions : undefined\n const options = isPluginSubscriptionOptions(debugOrOptions) ? debugOrOptions : pluginOptions\n\n super(Array.isArray(debug) && !!debug?.includes(className), PluginConsole)\n this._hydrationScheduler = options?.hydrationScheduler ?? defaultHydrationScheduler\n this._options = options\n this._pluginDebug = Array.isArray(debug) ? debug : undefined\n this._subscribers = subscribers\n }\n\n\n private addOnActionAfterCallback(actionName: string, store: Store, callback: StoreOnActionAfterCallbackParameter): void {\n const key = getActionStoreKey(actionName, store)\n if (!this._onActionAfterSubscriptions[key]) {\n this._onActionAfterSubscriptions[key] = []\n }\n this._onActionAfterSubscriptions[key]?.push(callback)\n }\n\n private addOnActionOnErrorCallback(actionName: string, store: Store, callback: (error: unknown) => void): void {\n const key = getActionStoreKey(actionName, store)\n if (!this._onActionOnErrorSubscriptions[key]) {\n this._onActionOnErrorSubscriptions[key] = []\n }\n this._onActionOnErrorSubscriptions[key]?.push(callback)\n }\n\n private addResetStoreCallback(callback: Function): void {\n this._resetStoreCallback.push(callback)\n }\n\n private clearOnActionCallbacksSubscriptions(storageKey: string): void {\n delete this._onActionAfterSubscriptions[storageKey]\n delete this._onActionOnErrorSubscriptions[storageKey]\n }\n\n private clearStoreTracking(store: Store): void {\n const suffix = `-${store.$id}`\n\n for (const key of Array.from(this._subscribersDelivered)) {\n if (key.endsWith(suffix)) {\n this._subscribersDelivered.delete(key)\n }\n }\n\n for (const key of Array.from(this._subscribersScheduled)) {\n if (key.endsWith(suffix)) {\n this._subscribersScheduled.delete(key)\n }\n }\n\n for (const key of Array.from(this._subscriptionsDelivered)) {\n if (key.endsWith(suffix)) {\n this._subscriptionsDelivered.delete(key)\n }\n }\n\n for (const key of Array.from(this._subscriptionsScheduled)) {\n if (key.endsWith(suffix)) {\n this._subscriptionsScheduled.delete(key)\n }\n }\n\n for (const key of Object.keys(this._onActionAfterSubscriptions)) {\n if (key.endsWith(suffix)) {\n delete this._onActionAfterSubscriptions[key]\n }\n }\n\n for (const key of Object.keys(this._onActionOnErrorSubscriptions)) {\n if (key.endsWith(suffix)) {\n delete this._onActionOnErrorSubscriptions[key]\n }\n }\n }\n\n /**\n * Creates a callback collector for the specified action and store.\n * @param actionName The name of the action to collect callbacks for.\n * @param store The store instance associated with the action.\n * @returns A function that collects callbacks for the specified action and store.\n */\n private createOnActionAfterCallbackCollector(actionName: string, store: Store) {\n return (callback: StoreOnActionAfterCallbackParameter) => {\n this.addOnActionAfterCallback(actionName, store, callback)\n }\n }\n\n /**\n * Creates a callback collector for the specified action and store that handles errors.\n * @param actionName The name of the action to collect error callbacks for.\n * @param store The store instance associated with the action.\n * @returns A function that collects error callbacks for the specified action and store.\n */\n private createOnActionOnErrorCallbackCollector(actionName: string, store: Store) {\n return (callback: (error: unknown) => void) => {\n this.addOnActionOnErrorCallback(actionName, store, callback)\n }\n }\n\n /**\n * Rolls back the state snapshot for a given action if an error occurs, and removes the snapshot after the action completes or fails.\n * @param actionName The name of the action being executed.\n * @param store The Pinia store instance.\n * @returns void\n */\n private createRollbackSnapshot(\n actionName: string,\n store: Store\n ) {\n const {\n after,\n onError\n } = this._storeRollbackSnapshotsHandler.createOnActionCallbacks(\n actionName,\n store\n ) ?? {}\n\n if (!after || !onError) {\n return\n }\n\n this.addOnActionAfterCallback(actionName, store, after)\n this.addOnActionOnErrorCallback(actionName, store, onError)\n }\n\n private defineCurrentEnvironment(): PluginRuntimeEnvironment {\n return this._options?.runtimeEnvironment\n ?? (typeof window === 'undefined' ? 'server' : 'client')\n }\n\n private definePluginDebug(subscriber: PluginSubscriber): boolean {\n return !!this._pluginDebug?.includes(subscriber.name)\n }\n\n private definePluginExecution(subscriber: PluginSubscriber): Required<PluginExecutionOptions> {\n return {\n ...defaultPluginExecution,\n ...(this._options?.execution ?? {}),\n ...(subscriber.execution ?? {}),\n ...(this._options?.subscriberExecution?.[subscriber.name] ?? {}),\n }\n }\n\n private defineHydrationScheduler(subscriber: PluginSubscriber | PluginSubscriptionDefinition['subscription']): PluginHydrationScheduler {\n return subscriber.hydrationScheduler ?? this._hydrationScheduler\n }\n\n private defineSubscriberKey(subscriber: PluginSubscriber, store: Store): string {\n return `${subscriber.name}-${store.$id}`\n }\n\n private defineSubscriptionKey(pluginName: string, store: Store): string {\n return `${pluginName}-${store.$id}`\n }\n\n private executeResetStoreCallbacks(store: Store): void {\n this._resetStoreCallback.forEach(callback => callback(store))\n }\n\n /**\n * Executes the store's onAction subscription for the given plugin subscriber.\n * @param store The Pinia store instance.\n * @param subscriber The plugin subscriber.\n * @returns void\n */\n private executeStoreOnActionSubscription(store: Store): void {\n const onActionSubscriptions = this._onActionSubscriptions\n const hasRollbackSnapshots = this._storeRollbackSnapshotsHandler.storeHasRollbackSnapshots(store)\n\n if (!onActionSubscriptions?.length && !hasRollbackSnapshots) {\n return\n }\n\n store.$onAction(({ after, args, name, onError }) => {\n const storageKey = getActionStoreKey(name, store)\n this.debugLog(`storeOnActionSubscription ${storageKey}`, { args, name, store })\n\n if (hasRollbackSnapshots) {\n this.createRollbackSnapshot(name, store)\n }\n\n if (onActionSubscriptions?.length) {\n onActionSubscriptions.forEach(callback => callback({\n after: this.createOnActionAfterCallbackCollector(name, store),\n args,\n name,\n onError: this.createOnActionOnErrorCallbackCollector(name, store)\n }))\n }\n\n const afterCallbacks = this._onActionAfterSubscriptions[storageKey]\n const onErrorCallbacks = this._onActionOnErrorSubscriptions[storageKey]\n\n this.clearOnActionCallbacksSubscriptions(storageKey)\n\n if (afterCallbacks?.length) {\n after((result) => {\n afterCallbacks.forEach(callback => callback(result))\n })\n }\n if (onErrorCallbacks?.length) {\n onError((error) => {\n onErrorCallbacks.forEach(callback => callback(error))\n })\n }\n })\n }\n\n private executeSubscriber(context: PiniaPluginContext, subscriber: PluginSubscriber): void {\n const subscriberKey = this.defineSubscriberKey(subscriber, context.store)\n const debug = this.definePluginDebug(subscriber)\n\n if (this._subscribersDelivered.has(subscriberKey)) {\n return\n }\n\n if (\n !subscriber.invoke(\n context,\n debug\n )) {\n return\n }\n\n this._subscribersDelivered.add(subscriberKey)\n\n let hydrateResult: void | Promise<void>\n\n try {\n hydrateResult = subscriber.hydrate?.(context, debug)\n } catch (error) {\n this.logError(error, context.store, context.options)\n return\n }\n\n const runAfterHydration = () => {\n try {\n const afterHydration = subscriber.afterHydration?.(context, debug)\n if (afterHydration && typeof (afterHydration as Promise<void>).then === 'function') {\n ; (afterHydration as Promise<void>).catch(error => this.logError(error, context.store, context.options))\n }\n } catch (error) {\n this.logError(error, context.store, context.options)\n }\n }\n\n if (hydrateResult && typeof (hydrateResult as Promise<void>).then === 'function') {\n ; (hydrateResult as Promise<void>)\n .then(() => runAfterHydration())\n .catch(error => this.logError(error, context.store, context.options))\n } else {\n runAfterHydration()\n }\n\n if (subscriber.subscriptions) {\n this.subscriptionDelivery(context, subscriber.subscriptions)\n }\n\n if (subscriber.storeMutationSubscription) {\n this.storeMutationSubscription(subscriber.storeMutationSubscription)\n }\n\n this.storeOnActionSubscription(subscriber)\n\n if (subscriber.resetStoreCallback) {\n this.addResetStoreCallback(subscriber.resetStoreCallback)\n }\n }\n\n private executeSubscriberSafely(context: PiniaPluginContext, subscriber: PluginSubscriber): void {\n try {\n this.executeSubscriber(context, subscriber)\n } catch (e) {\n this.logError(e, context.store, context.options)\n }\n }\n\n plugin({ store, options }: PiniaPluginContext) {\n if (!this._subscribers.length) {\n return\n }\n\n this.debugLog(`plugin() - ${store.$id}`, [\n 'subscriber:', this._subscribers,\n 'store:', store,\n 'options:', options\n ])\n\n try {\n this._subscribers.forEach(\n subscriber => {\n const subscriberKey = this.defineSubscriberKey(subscriber, store)\n const execution = this.definePluginExecution(subscriber)\n\n if (\n this._subscribersDelivered.has(subscriberKey)\n || this._subscribersScheduled.has(subscriberKey)\n ) {\n return\n }\n\n if (!this.shouldInvokePlugin(execution)) {\n return\n }\n\n if (this.shouldScheduleAfterHydration(execution)) {\n this.queueSubscriberExecution({ store, options } as PiniaPluginContext, subscriber, subscriberKey)\n return\n }\n\n this.executeSubscriber({ store, options } as PiniaPluginContext, subscriber)\n }\n )\n\n this.rewriteResetStore({ store } as PiniaPluginContext, store.$state)\n this._storeRollbackSnapshotsHandler.initFromPluginContext({ store, options } as PiniaPluginContext)\n this.executeStoreOnActionSubscription(store)\n this.registerStoreCleanup(store)\n } catch (e) {\n this.logError(e, store, options)\n }\n }\n\n private queueSubscriberExecution(\n context: PiniaPluginContext,\n subscriber: PluginSubscriber,\n subscriberKey: string\n ): void {\n const scheduler = this.defineHydrationScheduler(subscriber)\n\n this._subscribersScheduled.add(subscriberKey)\n scheduler(() => {\n this._subscribersScheduled.delete(subscriberKey)\n this.executeSubscriberSafely(context, subscriber)\n })\n }\n\n private registerStoreCleanup(store: Store): void {\n this._onActionSubscriptions = []\n if (typeof store.$dispose !== 'function') {\n return\n }\n\n const dispose = store.$dispose.bind(store)\n const scopedStore = store as AnyObject\n\n if (scopedStore.__piniaPluginSubscriptionDisposed) {\n return\n }\n\n scopedStore.__piniaPluginSubscriptionDisposed = true\n store.$dispose = () => {\n this.clearStoreTracking(store)\n this._storeRollbackSnapshotsHandler.clearStoreTracking(store)\n return dispose()\n }\n }\n\n private rewriteResetStore({ store }: PiniaPluginContext, initState: StateTree): void {\n const safeState = deepClone(initState)\n\n store.$reset = () => {\n this.debugLog('rewriteResetStore()', { initState: safeState, store })\n\n this.executeResetStoreCallbacks(store)\n\n store.$patch(deepClone(safeState))\n }\n }\n\n private shouldInvokePlugin(execution: Required<PluginExecutionOptions>): boolean {\n const currentEnvironment = this.defineCurrentEnvironment()\n\n return execution.environment === 'both' || execution.environment === currentEnvironment\n }\n\n private shouldScheduleAfterHydration(execution: Required<PluginExecutionOptions>): boolean {\n return this.defineCurrentEnvironment() === 'client' && execution.hydration === 'defer'\n }\n\n private storeOnActionSubscription(subscriber: PluginSubscriber): void {\n const { store, callback } = subscriber?.storeOnActionSubscription?.() ?? {}\n\n if (!store || !callback) {\n return\n }\n\n this._onActionSubscriptions.push(callback)\n }\n\n private storeMutationSubscription(subscription: StoreMutationSubscription): void {\n const { store, callback } = subscription()\n\n store.$subscribe((mutation: SubscriptionCallbackMutation<StateTree>) => {\n this.debugLog(`$subscribe ${store.$id}`, { mutation, store })\n callback(mutation)\n })\n }\n\n private subscriptionDelivery(\n context: PiniaPluginContext,\n pluginSubscriptions: PluginSubscriptions\n ): void {\n Object.entries(pluginSubscriptions).forEach(([pluginName, pluginSubscription]) => {\n const subscriptionKey = this.defineSubscriptionKey(pluginName, context.store)\n const execution = this.definePluginExecution(pluginSubscription.subscription)\n\n if (\n this._subscriptionsDelivered.has(subscriptionKey)\n || this._subscriptionsScheduled.has(subscriptionKey)\n ) {\n return\n }\n\n if (!this.shouldInvokePlugin(execution)) {\n return\n }\n\n if (this.shouldScheduleAfterHydration(execution)) {\n const scheduler = this.defineHydrationScheduler(pluginSubscription.subscription)\n\n this._subscriptionsScheduled.add(subscriptionKey)\n scheduler(() => {\n this._subscriptionsScheduled.delete(subscriptionKey)\n this.subscriptionDeliverySafely(context, pluginName, pluginSubscription)\n })\n return\n }\n\n this.subscriptionDeliverySafely(context, pluginName, pluginSubscription)\n })\n }\n\n private subscriptionDeliverySafely(\n { store, options }: PiniaPluginContext,\n pluginName: string,\n pluginSubscription: PluginSubscriptionDefinition\n ): void {\n try {\n if (this._subscriptionsDelivered.has(this.defineSubscriptionKey(pluginName, store))) {\n return\n }\n\n const { subscription, subscriptionOptions, stores } = pluginSubscription\n\n this.debugLog(`subscriptionDelivery() - store: ${store.$id}`, [\n 'pluginName:', pluginName,\n 'subscription:', subscription,\n 'options:', pluginSubscription,\n 'stores:', stores\n ])\n\n const pluginOptions = {\n storeOptions: { ...((options as AnyObject)?.storeOptions ?? {}), ...subscriptionOptions }\n } as AnyObject\n\n subscription.invoke(\n { store, options: { ...options, ...pluginOptions } } as PiniaPluginContext,\n this.debug\n )\n this._subscriptionsDelivered.add(this.defineSubscriptionKey(pluginName, store))\n\n if (!isEmpty(stores)) {\n stores?.forEach(\n store => subscription.invoke(\n {\n store,\n options: {\n ...options,\n ...pluginOptions,\n ...((store as AnyObject)?.storeOptions ?? {})\n }\n } as PiniaPluginContext,\n this.debug\n )\n )\n }\n } catch (e) {\n this.logError(`subscriptionDelivery()`, e, store, options)\n }\n }\n}"],"names":["deepClone","value","key","entryValue","item","clonedObject","createStateSnapshot","state","keys","clonedState","toRaw","RollbackStateSnapshotsHandler","__publicField","store","action","stateKeys","args","actionFn","hasDeniedFirstChar","snapshotKey","error","actionName","getActionStoreKey","options","rollbackSnapshotParams","suffix","stateSnapshot","className","defaultPluginExecution","defaultHydrationScheduler","callback","isPluginSubscriptionOptions","PluginSubscription","Debug","subscribers","debugOrOptions","pluginOptions","debug","PluginConsole","storageKey","after","onError","subscriber","pluginName","onActionSubscriptions","hasRollbackSnapshots","name","afterCallbacks","onErrorCallbacks","result","context","subscriberKey","hydrateResult","runAfterHydration","afterHydration","e","execution","scheduler","dispose","scopedStore","initState","safeState","currentEnvironment","subscription","mutation","pluginSubscriptions","pluginSubscription","subscriptionKey","subscriptionOptions","stores","isEmpty","store2","createPlugin","createHydrationPlugin","hydrationPlugin"],"mappings":";;;;;;AAMO,SAASA,EAAaC,GAAa;AACtC,MAAI,OAAO,mBAAoB;AAC3B,QAAI;AACA,aAAO,gBAAgBA,CAAK;AAAA,IAChC,QAAQ;AAAA,IAER;AAGJ,MAAIA,MAAU,QAAQ,OAAOA,KAAU;AACnC,WAAOA;AAGX,MAAIA,aAAiB;AACjB,WAAO,IAAI;AAAA,MACP,MAAM,KAAKA,EAAM,QAAA,GAAW,CAAC,CAACC,GAAKC,CAAU,MAAM,CAACH,EAAUE,CAAG,GAAGF,EAAUG,CAAU,CAAC,CAAC;AAAA,IAAA;AAIlG,MAAIF,aAAiB;AACjB,WAAO,IAAI,IAAI,MAAM,KAAKA,EAAM,OAAA,GAAU,CAAAE,MAAcH,EAAUG,CAAU,CAAC,CAAC;AAGlF,MAAI,MAAM,QAAQF,CAAK;AACnB,WAAOA,EAAM,IAAI,CAAAG,MAAQJ,EAAUI,CAAI,CAAC;AAG5C,MAAI,OAAO,eAAeH,CAAK,MAAM,OAAO,aAAa,OAAO,eAAeA,CAAK,MAAM;AACtF,WAAO,OAAO;AAAA,MACV,OAAO,QAAQA,CAAgC,EAAE,IAAI,CAAC,CAACC,GAAKE,CAAI,MAAM,CAACF,GAAKF,EAAUI,CAAI,CAAC,CAAC;AAAA,IAAA;AAIpG,QAAMC,IAAe,OAAO,OAAO,OAAO,eAAeJ,CAAK,CAAC;AAC/D,aAAW,CAACC,GAAKE,CAAI,KAAK,OAAO,QAAQH,CAAgC;AACrE,IAAAI,EAAaH,CAAG,IAAIF,EAAUI,CAAI;AAGtC,SAAOC;AACX;ACtCO,SAASC,EAAoBC,GAAkBC,IAAgC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AEAA,GAAK;AAAA,QACT,CAAAE,MAAAR,EAAA;AAAA,UAEQ;AAAA,YACI;YAEF;cACG,GAAAxC;AAAA,cACI,GAAAa;AAAA,cACZ,GAAAmC,GAAA,gBAAA,CAAA;AAAA,YACL;AAAA,UAEQ;AAAA,UAIG,KAAA;AAAA,QACH;AAAA,MACA;AAAA,IAMI,SAAAhB,GAAA;AACJ,WAAA,SAAA,0BAAAA,GAAA1C,GAAAU,CAAA;AAAA,IAEA;AAAA,EACI;AAAA;AAIA,SAAAiD,EAAMtC;AAEN,QAAAgC,IAAK,IAAAlC,KAA2CK,CAAA;AAChD,SAAA6B,EAAgB,OAAA,KAAAA,CAAA;AACZ;AACuE,SAC1EO,EAAAvC,GAAAX,GAAA;AACD,QAAAmD,IAAA,IAAA1C,EAAAE,GAAAX,GAAA,OAAA;AAAA,IAAA,WACJA,GAAA;AAAA,IAEA,oBAAKA,GAAA;AAAA,IACT,oBAACA,GAAA;AAAA,IACL,qBAAAA,GAAA;AAAA,EAEQ,CAAA;AAKJ,SAAImD,EAAA,OAAA,KAAAA,CAAA;AACA;"}
1
+ {"version":3,"file":"pinia-plugin-subscription.js","sources":["../src/utils/deep-clone.ts","../src/factories/state-snapshot.ts","../src/core/RollbackStateSnapshotsHandler.ts","../src/core/PluginSubscription.ts"],"sourcesContent":["/**\n * Deeply clones the provided value, handling objects, arrays, maps, and sets. Uses `structuredClone` if available, otherwise falls back to a manual deep clone.\n * @template T The type of the value to deep clone.\n * @param value The value to deep clone.\n * @returns A deep clone of the provided value.\n */\nexport function deepClone<T>(value: T): T {\n if (typeof structuredClone === 'function') {\n try {\n return structuredClone(value)\n } catch {\n // fall through to the safe manual clone below\n }\n }\n\n if (value === null || typeof value !== 'object') {\n return value\n }\n\n if (value instanceof Map) {\n return new Map(\n Array.from(value.entries(), ([key, entryValue]) => [deepClone(key), deepClone(entryValue)])\n ) as T\n }\n\n if (value instanceof Set) {\n return new Set(Array.from(value.values(), entryValue => deepClone(entryValue))) as T\n }\n\n if (Array.isArray(value)) {\n return value.map(item => deepClone(item)) as T\n }\n\n if (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null) {\n return Object.fromEntries(\n Object.entries(value as Record<string, unknown>).map(([key, item]) => [key, deepClone(item)])\n ) as T\n }\n\n const clonedObject = Object.create(Object.getPrototypeOf(value)) as Record<string, unknown>\n for (const [key, item] of Object.entries(value as Record<string, unknown>)) {\n clonedObject[key] = deepClone(item)\n }\n\n return clonedObject as T\n}","import { toRaw } from 'vue'\nimport { deepClone } from '../utils/deep-clone'\n\nimport type { StateTree } from 'pinia'\nimport type { CreateStateSnapshotKeys } from '../types/plugin'\n\n\nexport function createStateSnapshot(state: StateTree, keys: CreateStateSnapshotKeys = 'all') {\n if (Array.isArray(keys)) {\n const clonedState: Partial<StateTree> = {}\n for (const key of keys) {\n if (key in state) {\n clonedState[key] = deepClone(toRaw(state[key]))\n }\n }\n return clonedState\n }\n\n if (keys !== 'all') {\n throw new Error(`Invalid keys parameter: ${keys}`)\n }\n\n return deepClone(toRaw(state))\n}","import { createStateSnapshot } from \"../factories/state-snapshot\"\nimport { getActionStoreKey, hasDeniedFirstChar } from '../utils/store'\n\nimport type { PiniaPluginContext, StateTree, Store } from 'pinia'\nimport type { AnyObject } from '../types'\nimport type { CreateStateSnapshotKeys } from '../types/plugin'\nimport type { RollbackActionParams } from '../types/store'\n\n\n/**\n * Handles rollback state snapshots for Pinia stores.\n * This class provides methods to add rollback actions to stores,\n * create rollback snapshots, and manage the state snapshots internally.\n */\nexport default class RollbackStateSnapshotsHandler {\n private _stateSnapshots: Map<symbol, StateTree> = new Map()\n private _storeHasRollbackSnapshots: Set<string> = new Set()\n private _storeRollbackSnapshotsParams: Map<string, CreateStateSnapshotKeys> = new Map()\n\n\n /**\n * Adds a rollback action to the given store.\n * This method extends the store with a $rollbackAfterFailure function that handles rollback logic for actions.\n * The action arguments are forwarded through apply(), so they must be provided as a single array.\n * @param {Store} store The store to which the rollback action will be added.\n * @returns void\n */\n addRollbackAction(store: Store): void {\n if (typeof store.$rollbackAfterFailure === 'function') {\n return\n }\n\n store.$rollbackAfterFailure = async ({ action, stateKeys }: RollbackActionParams, args: any[] = []) => {\n const actionFn = (store as AnyObject)[action]\n if (typeof actionFn !== 'function' || hasDeniedFirstChar(action)) {\n return\n }\n\n const keys: CreateStateSnapshotKeys = !stateKeys || stateKeys.length === 0 ? 'all' : stateKeys\n\n const snapshotKey = this.saveStateSnapshot(store, action, keys)\n try {\n await actionFn.apply(store, args)\n } catch (error) {\n this.patchStore(snapshotKey, store)\n throw error\n } finally {\n this.removeStateSnapshot(snapshotKey)\n }\n }\n }\n\n /**\n * Creates a rollback snapshot for the specified action and store.\n * This snapshot can be used to restore the store's state in case of an error during the action execution.\n * @param {string} actionName The name of the action for which the rollback snapshot is created.\n * @param {Store} store The Pinia store instance.\n * @returns An object containing `after` and `onError` callbacks for handling the rollback, or `undefined` if no snapshot is created.\n */\n createOnActionCallbacks(\n actionName: string,\n store: Store\n ): {\n after: () => void,\n onError: () => void\n } | undefined {\n const stateKeys = this._storeRollbackSnapshotsParams.get(\n getActionStoreKey(actionName, store)\n )\n\n if (!stateKeys) {\n return\n }\n\n const keys: CreateStateSnapshotKeys = stateKeys.length === 0 ? 'all' : stateKeys\n const snapshotKey = this.saveStateSnapshot(store, actionName, keys)\n\n return {\n after: () => { this.removeStateSnapshot(snapshotKey) },\n onError: () => {\n this.patchStore(snapshotKey, store)\n this.removeStateSnapshot(snapshotKey)\n }\n }\n }\n\n /**\n * Initializes the rollback state snapshots handler from the given Pinia plugin context.\n * This method extracts the rollback snapshot parameters from the store options and stores them internally.\n * @param {PiniaPluginContext} param0 The Pinia plugin context containing the store and its options.\n * @returns void\n */\n initFromPluginContext({ options, store }: PiniaPluginContext) {\n const rollbackSnapshotParams = options?.storeOptions?.rollbackAfterFailure as Record<string, CreateStateSnapshotKeys>\n if (rollbackSnapshotParams && !this._storeHasRollbackSnapshots.has(store.$id)) {\n Object.keys(rollbackSnapshotParams).forEach(key => {\n this._storeRollbackSnapshotsParams.set(\n getActionStoreKey(key, store),\n rollbackSnapshotParams[key]\n )\n })\n this._storeHasRollbackSnapshots.add(store.$id)\n }\n this.addRollbackAction(store)\n }\n\n /**\n * Clears all rollback tracking data for the given store.\n * Must be called when the store is disposed to avoid memory leaks with dynamically created stores.\n * @param {Store} store The disposed Pinia store instance.\n * @returns void\n */\n clearStoreTracking(store: Store): void {\n const suffix = `-${store.$id}`\n\n for (const key of Array.from(this._storeRollbackSnapshotsParams.keys())) {\n if (key.endsWith(suffix)) {\n this._storeRollbackSnapshotsParams.delete(key)\n }\n }\n\n this._storeHasRollbackSnapshots.delete(store.$id)\n\n for (const snapshotKey of Array.from(this._stateSnapshots.keys())) {\n if (snapshotKey.description?.startsWith(`${store.$id}:`)) {\n this._stateSnapshots.delete(snapshotKey)\n }\n }\n }\n\n private patchStore(snapshotKey: symbol, store: Store): void {\n const stateSnapshot = this._stateSnapshots.get(snapshotKey)\n if (!stateSnapshot) {\n return\n }\n\n try {\n store.$patch(stateSnapshot)\n } catch (error) {\n console.error(`Failed to patch store with snapshot ${String(snapshotKey)}`, error)\n }\n }\n\n /**\n * Removes a state snapshot identified by the given snapshot key from the internal state snapshot tracking.\n * @param snapshotKey The key of the state snapshot to be removed.\n * @returns void\n */\n private removeStateSnapshot(snapshotKey?: symbol): void {\n if (!snapshotKey) {\n return\n }\n\n this._stateSnapshots.delete(snapshotKey)\n }\n\n /**\n * Saves the current state snapshot for a given store and action.\n * @param store The Pinia store instance.\n * @param actionName The name of the action being executed.\n * @param stateKeys The state keys to include in the snapshot, or 'all' for the full state.\n * @returns A unique symbol key representing the saved snapshot.\n */\n private saveStateSnapshot(store: Store, actionName: string, stateKeys: CreateStateSnapshotKeys): symbol {\n const stateSnapshot = createStateSnapshot(\n store.$state,\n stateKeys\n )\n\n const snapshotKey = Symbol(`${store.$id}:${actionName}`)\n this._stateSnapshots.set(snapshotKey, stateSnapshot)\n return snapshotKey\n }\n\n /**\n * Checks if the given store has rollback snapshots.\n * @param store The Pinia store instance.\n * @returns True if the store has rollback snapshots, false otherwise.\n */\n storeHasRollbackSnapshots(store: Store): boolean {\n return this._storeHasRollbackSnapshots.has(store.$id)\n }\n}","import Debug from \"../system/Debug\"\nimport RollbackStateSnapshotsHandler from \"./RollbackStateSnapshotsHandler\"\nimport { deepClone } from '../utils/deep-clone'\nimport { getActionStoreKey } from '../utils/store'\nimport { PluginConsole } from \"../system/log\"\nimport { isEmpty } from \"../utils/validation\"\n\nimport type { PiniaPluginContext, StateTree, Store, SubscriptionCallbackMutation } from \"pinia\"\nimport type { AnyObject } from \"../types\"\nimport type {\n PluginExecutionOptions,\n PluginHydrationScheduler,\n PluginRuntimeEnvironment,\n PluginSubscriber,\n PluginSubscription as PluginSubscriptionDefinition,\n PluginSubscriptionOptions,\n PluginSubscriptions,\n StoreMutationSubscription,\n StoreOnActionAfterCallbackParameter,\n StoreOnActionSubscriptionCallback\n} from \"../types/plugin\"\n\n\nconst className = 'PluginSubscription'\nconst defaultPluginExecution: Required<PluginExecutionOptions> = {\n environment: 'both',\n hydration: 'immediate'\n}\n\nfunction defaultHydrationScheduler(callback: () => void): void {\n if (typeof window !== 'undefined' && typeof window.requestAnimationFrame === 'function') {\n window.requestAnimationFrame(() => globalThis.setTimeout(callback, 0))\n return\n }\n\n globalThis.setTimeout(callback, 0)\n}\n\nfunction isPluginSubscriptionOptions(\n value: PluginSubscriptionOptions | string[] | undefined\n): value is PluginSubscriptionOptions {\n return value !== undefined && !Array.isArray(value)\n}\n\n\nexport default class PluginSubscription extends Debug {\n protected _className: string = className\n private _hydrationScheduler: PluginHydrationScheduler\n private _onActionSubscriptions: Map<Store, Set<StoreOnActionSubscriptionCallback>> = new Map()\n private _onActionStores: Set<Store> = new Set()\n private _onActionAfterSubscriptions: Record<string, StoreOnActionAfterCallbackParameter[]> = {}\n private _onActionOnErrorSubscriptions: Record<string, Array<(error: unknown) => void>> = {}\n private _options?: PluginSubscriptionOptions\n private _pluginDebug?: string[]\n private _resetStoreCallback: Map<Store, Set<NonNullable<PluginSubscriber['resetStoreCallback']>>> = new Map()\n private _disposedStores: WeakSet<Store> = new WeakSet()\n private _storeRollbackSnapshotsHandler: RollbackStateSnapshotsHandler = new RollbackStateSnapshotsHandler()\n private _subscribers: PluginSubscriber[] = []\n private _subscribersDelivered: Set<string> = new Set()\n private _subscribersScheduled: Set<string> = new Set()\n private _subscriptions: PluginSubscriptions[] = []\n private _subscriptionsDelivered: Set<string> = new Set()\n private _subscriptionsScheduled: Set<string> = new Set()\n\n set subscribers(subscribers: PluginSubscriber[]) {\n this._subscribers = subscribers\n }\n\n get subscriptions(): PluginSubscriptions[] | undefined {\n if (!isEmpty(this._subscriptions)) {\n return this._subscriptions\n }\n }\n\n constructor(\n subscribers: PluginSubscriber[],\n debugOrOptions?: PluginSubscriptionOptions | string[],\n pluginOptions?: PluginSubscriptionOptions\n ) {\n const debug = Array.isArray(debugOrOptions) ? debugOrOptions : undefined\n const options = isPluginSubscriptionOptions(debugOrOptions) ? debugOrOptions : pluginOptions\n\n super(Array.isArray(debug) && !!debug?.includes(className), PluginConsole)\n this._hydrationScheduler = options?.hydrationScheduler ?? defaultHydrationScheduler\n this._options = options\n this._pluginDebug = Array.isArray(debug) ? debug : undefined\n this._subscribers = subscribers\n }\n\n\n private addOnActionAfterCallback(actionName: string, store: Store, callback: StoreOnActionAfterCallbackParameter): void {\n const key = getActionStoreKey(actionName, store)\n if (!this._onActionAfterSubscriptions[key]) {\n this._onActionAfterSubscriptions[key] = []\n }\n this._onActionAfterSubscriptions[key]?.push(callback)\n }\n\n private addOnActionOnErrorCallback(actionName: string, store: Store, callback: (error: unknown) => void): void {\n const key = getActionStoreKey(actionName, store)\n if (!this._onActionOnErrorSubscriptions[key]) {\n this._onActionOnErrorSubscriptions[key] = []\n }\n this._onActionOnErrorSubscriptions[key]?.push(callback)\n }\n\n private addResetStoreCallback(store: Store, callback: NonNullable<PluginSubscriber['resetStoreCallback']>): void {\n if (!this._resetStoreCallback.has(store)) {\n this._resetStoreCallback.set(store, new Set())\n }\n this._resetStoreCallback.get(store)!.add(callback)\n }\n\n private clearOnActionCallbacksSubscriptions(storageKey: string): void {\n delete this._onActionAfterSubscriptions[storageKey]\n delete this._onActionOnErrorSubscriptions[storageKey]\n }\n\n private clearStoreTracking(store: Store): void {\n this._onActionSubscriptions.delete(store)\n this._onActionStores.delete(store)\n this._resetStoreCallback.delete(store)\n const suffix = `-${store.$id}`\n\n for (const key of Array.from(this._subscribersDelivered)) {\n if (key.endsWith(suffix)) {\n this._subscribersDelivered.delete(key)\n }\n }\n\n for (const key of Array.from(this._subscribersScheduled)) {\n if (key.endsWith(suffix)) {\n this._subscribersScheduled.delete(key)\n }\n }\n\n for (const key of Array.from(this._subscriptionsDelivered)) {\n if (key.endsWith(suffix)) {\n this._subscriptionsDelivered.delete(key)\n }\n }\n\n for (const key of Array.from(this._subscriptionsScheduled)) {\n if (key.endsWith(suffix)) {\n this._subscriptionsScheduled.delete(key)\n }\n }\n\n for (const key of Object.keys(this._onActionAfterSubscriptions)) {\n if (key.endsWith(suffix)) {\n delete this._onActionAfterSubscriptions[key]\n }\n }\n\n for (const key of Object.keys(this._onActionOnErrorSubscriptions)) {\n if (key.endsWith(suffix)) {\n delete this._onActionOnErrorSubscriptions[key]\n }\n }\n }\n\n /**\n * Creates a callback collector for the specified action and store.\n * @param actionName The name of the action to collect callbacks for.\n * @param store The store instance associated with the action.\n * @returns A function that collects callbacks for the specified action and store.\n */\n private createOnActionAfterCallbackCollector(actionName: string, store: Store) {\n return (callback: StoreOnActionAfterCallbackParameter) => {\n this.addOnActionAfterCallback(actionName, store, callback)\n }\n }\n\n /**\n * Creates a callback collector for the specified action and store that handles errors.\n * @param actionName The name of the action to collect error callbacks for.\n * @param store The store instance associated with the action.\n * @returns A function that collects error callbacks for the specified action and store.\n */\n private createOnActionOnErrorCallbackCollector(actionName: string, store: Store) {\n return (callback: (error: unknown) => void) => {\n this.addOnActionOnErrorCallback(actionName, store, callback)\n }\n }\n\n /**\n * Rolls back the state snapshot for a given action if an error occurs, and removes the snapshot after the action completes or fails.\n * @param actionName The name of the action being executed.\n * @param store The Pinia store instance.\n * @returns void\n */\n private createRollbackSnapshot(\n actionName: string,\n store: Store\n ) {\n const {\n after,\n onError\n } = this._storeRollbackSnapshotsHandler.createOnActionCallbacks(\n actionName,\n store\n ) ?? {}\n\n if (!after || !onError) {\n return\n }\n\n this.addOnActionAfterCallback(actionName, store, after)\n this.addOnActionOnErrorCallback(actionName, store, onError)\n }\n\n private defineCurrentEnvironment(): PluginRuntimeEnvironment {\n return this._options?.runtimeEnvironment\n ?? (typeof window === 'undefined' ? 'server' : 'client')\n }\n\n private definePluginDebug(subscriber: PluginSubscriber): boolean {\n return !!this._pluginDebug?.includes(subscriber.name)\n }\n\n private definePluginExecution(subscriber: PluginSubscriber): Required<PluginExecutionOptions> {\n return {\n ...defaultPluginExecution,\n ...(this._options?.execution ?? {}),\n ...(subscriber.execution ?? {}),\n ...(this._options?.subscriberExecution?.[subscriber.name] ?? {}),\n }\n }\n\n private defineHydrationScheduler(subscriber: PluginSubscriber | PluginSubscriptionDefinition['subscription']): PluginHydrationScheduler {\n return subscriber.hydrationScheduler ?? this._hydrationScheduler\n }\n\n private defineSubscriberKey(subscriber: PluginSubscriber, store: Store): string {\n return `${subscriber.name}-${store.$id}`\n }\n\n private defineSubscriptionKey(pluginName: string, store: Store): string {\n return `${pluginName}-${store.$id}`\n }\n\n private executeResetStoreCallbacks(store: Store): void {\n this._resetStoreCallback.get(store)?.forEach(callback => callback(store))\n }\n\n /**\n * Executes the store's onAction subscription for the given plugin subscriber.\n * @param store The Pinia store instance.\n * @param subscriber The plugin subscriber.\n * @returns void\n */\n private executeStoreOnActionSubscription(store: Store): void {\n if (this._onActionStores.has(store) || typeof store.$onAction !== 'function') {\n return\n }\n const onActionSubscriptions = this._onActionSubscriptions.get(store)\n const hasRollbackSnapshots = this._storeRollbackSnapshotsHandler.storeHasRollbackSnapshots(store)\n\n if (!onActionSubscriptions?.size && !hasRollbackSnapshots) {\n return\n }\n\n this._onActionStores.add(store)\n store.$onAction(({ after, args, name, onError }) => {\n const storageKey = getActionStoreKey(name, store)\n this.debugLog(`storeOnActionSubscription ${storageKey}`, { args, name, store })\n\n if (this._storeRollbackSnapshotsHandler.storeHasRollbackSnapshots(store)) {\n this.createRollbackSnapshot(name, store)\n }\n\n const callbacks = this._onActionSubscriptions.get(store)\n if (callbacks?.size) {\n callbacks.forEach(callback => callback({\n after: this.createOnActionAfterCallbackCollector(name, store),\n args,\n name,\n onError: this.createOnActionOnErrorCallbackCollector(name, store)\n }))\n }\n\n const afterCallbacks = this._onActionAfterSubscriptions[storageKey]\n const onErrorCallbacks = this._onActionOnErrorSubscriptions[storageKey]\n\n this.clearOnActionCallbacksSubscriptions(storageKey)\n\n if (afterCallbacks?.length) {\n after((result) => {\n afterCallbacks.forEach(callback => callback(result))\n })\n }\n if (onErrorCallbacks?.length) {\n onError((error) => {\n onErrorCallbacks.forEach(callback => callback(error))\n })\n }\n })\n }\n\n private executeSubscriber(context: PiniaPluginContext, subscriber: PluginSubscriber): void {\n const subscriberKey = this.defineSubscriberKey(subscriber, context.store)\n const debug = this.definePluginDebug(subscriber)\n\n if (this._subscribersDelivered.has(subscriberKey)) {\n return\n }\n\n if (\n !subscriber.invoke(\n context,\n debug\n )) {\n return\n }\n\n this._subscribersDelivered.add(subscriberKey)\n\n let hydrateResult: void | Promise<void>\n\n try {\n hydrateResult = subscriber.hydrate?.(context, debug)\n } catch (error) {\n this.logError(error, context.store, context.options)\n return\n }\n\n const runAfterHydration = () => {\n try {\n const afterHydration = subscriber.afterHydration?.(context, debug)\n if (afterHydration && typeof (afterHydration as Promise<void>).then === 'function') {\n ; (afterHydration as Promise<void>).catch(error => this.logError(error, context.store, context.options))\n }\n } catch (error) {\n this.logError(error, context.store, context.options)\n }\n }\n\n if (hydrateResult && typeof (hydrateResult as Promise<void>).then === 'function') {\n ; (hydrateResult as Promise<void>)\n .then(() => runAfterHydration())\n .catch(error => this.logError(error, context.store, context.options))\n } else {\n runAfterHydration()\n }\n\n if (subscriber.subscriptions) {\n this.subscriptionDelivery(context, subscriber.subscriptions)\n }\n\n if (subscriber.storeMutationSubscription) {\n this.storeMutationSubscription(subscriber.storeMutationSubscription)\n }\n\n this.storeOnActionSubscription(subscriber)\n\n if (subscriber.resetStoreCallback) {\n this.addResetStoreCallback(context.store, subscriber.resetStoreCallback)\n }\n }\n\n private executeSubscriberSafely(context: PiniaPluginContext, subscriber: PluginSubscriber): void {\n try {\n this.executeSubscriber(context, subscriber)\n } catch (e) {\n this.logError(e, context.store, context.options)\n }\n }\n\n plugin({ store, options }: PiniaPluginContext) {\n if (!this._subscribers.length) {\n return\n }\n\n this.debugLog(`plugin() - ${store.$id}`, [\n 'subscriber:', this._subscribers,\n 'store:', store,\n 'options:', options\n ])\n\n try {\n this._subscribers.forEach(\n subscriber => {\n const subscriberKey = this.defineSubscriberKey(subscriber, store)\n const execution = this.definePluginExecution(subscriber)\n\n if (\n this._subscribersDelivered.has(subscriberKey)\n || this._subscribersScheduled.has(subscriberKey)\n ) {\n return\n }\n\n if (!this.shouldInvokePlugin(execution)) {\n return\n }\n\n if (this.shouldScheduleAfterHydration(execution)) {\n this.queueSubscriberExecution({ store, options } as PiniaPluginContext, subscriber, subscriberKey)\n return\n }\n\n this.executeSubscriber({ store, options } as PiniaPluginContext, subscriber)\n }\n )\n\n this.rewriteResetStore({ store } as PiniaPluginContext, store.$state)\n this._storeRollbackSnapshotsHandler.initFromPluginContext({ store, options } as PiniaPluginContext)\n this.executeStoreOnActionSubscription(store)\n this.registerStoreCleanup(store)\n } catch (e) {\n this.logError(e, store, options)\n }\n }\n\n private queueSubscriberExecution(\n context: PiniaPluginContext,\n subscriber: PluginSubscriber,\n subscriberKey: string\n ): void {\n const scheduler = this.defineHydrationScheduler(subscriber)\n\n this._subscribersScheduled.add(subscriberKey)\n scheduler(() => {\n if (this._disposedStores.has(context.store)) {\n return\n }\n this._subscribersScheduled.delete(subscriberKey)\n this.executeSubscriberSafely(context, subscriber)\n })\n }\n\n private registerStoreCleanup(store: Store): void {\n if (typeof store.$dispose !== 'function') {\n return\n }\n\n const dispose = store.$dispose.bind(store)\n const scopedStore = store as AnyObject\n\n if (scopedStore.__piniaPluginSubscriptionDisposed) {\n return\n }\n\n scopedStore.__piniaPluginSubscriptionDisposed = true\n store.$dispose = () => {\n this._disposedStores.add(store)\n this.clearStoreTracking(store)\n this._storeRollbackSnapshotsHandler.clearStoreTracking(store)\n return dispose()\n }\n }\n\n private rewriteResetStore({ store }: PiniaPluginContext, initState: StateTree): void {\n const safeState = deepClone(initState)\n\n store.$reset = () => {\n this.debugLog('rewriteResetStore()', { initState: safeState, store })\n\n this.executeResetStoreCallbacks(store)\n\n store.$patch(deepClone(safeState))\n }\n }\n\n private shouldInvokePlugin(execution: Required<PluginExecutionOptions>): boolean {\n const currentEnvironment = this.defineCurrentEnvironment()\n\n return execution.environment === 'both' || execution.environment === currentEnvironment\n }\n\n private shouldScheduleAfterHydration(execution: Required<PluginExecutionOptions>): boolean {\n return this.defineCurrentEnvironment() === 'client' && execution.hydration === 'defer'\n }\n\n private storeOnActionSubscription(subscriber: PluginSubscriber): void {\n const { store, callback } = subscriber?.storeOnActionSubscription?.() ?? {}\n\n if (!store || !callback) {\n return\n }\n\n if (!this._onActionSubscriptions.has(store)) {\n this._onActionSubscriptions.set(store, new Set())\n }\n this._onActionSubscriptions.get(store)!.add(callback)\n this.executeStoreOnActionSubscription(store)\n }\n\n private storeMutationSubscription(subscription: StoreMutationSubscription): void {\n const { store, callback } = subscription()\n\n store.$subscribe((mutation: SubscriptionCallbackMutation<StateTree>) => {\n this.debugLog(`$subscribe ${store.$id}`, { mutation, store })\n callback(mutation)\n })\n }\n\n private subscriptionDelivery(\n context: PiniaPluginContext,\n pluginSubscriptions: PluginSubscriptions\n ): void {\n Object.entries(pluginSubscriptions).forEach(([pluginName, pluginSubscription]) => {\n const subscriptionKey = this.defineSubscriptionKey(pluginName, context.store)\n const execution = this.definePluginExecution(pluginSubscription.subscription)\n\n if (\n this._subscriptionsDelivered.has(subscriptionKey)\n || this._subscriptionsScheduled.has(subscriptionKey)\n ) {\n return\n }\n\n if (!this.shouldInvokePlugin(execution)) {\n return\n }\n\n if (this.shouldScheduleAfterHydration(execution)) {\n const scheduler = this.defineHydrationScheduler(pluginSubscription.subscription)\n\n this._subscriptionsScheduled.add(subscriptionKey)\n scheduler(() => {\n if (this._disposedStores.has(context.store)) {\n return\n }\n this._subscriptionsScheduled.delete(subscriptionKey)\n this.subscriptionDeliverySafely(context, pluginName, pluginSubscription)\n })\n return\n }\n\n this.subscriptionDeliverySafely(context, pluginName, pluginSubscription)\n })\n }\n\n private subscriptionDeliverySafely(\n { store, options }: PiniaPluginContext,\n pluginName: string,\n pluginSubscription: PluginSubscriptionDefinition\n ): void {\n try {\n if (this._subscriptionsDelivered.has(this.defineSubscriptionKey(pluginName, store))) {\n return\n }\n\n const { subscription, subscriptionOptions, stores } = pluginSubscription\n\n this.debugLog(`subscriptionDelivery() - store: ${store.$id}`, [\n 'pluginName:', pluginName,\n 'subscription:', subscription,\n 'options:', pluginSubscription,\n 'stores:', stores\n ])\n\n const pluginOptions = {\n storeOptions: { ...((options as AnyObject)?.storeOptions ?? {}), ...subscriptionOptions }\n } as AnyObject\n\n subscription.invoke(\n { store, options: { ...options, ...pluginOptions } } as PiniaPluginContext,\n this.debug\n )\n this._subscriptionsDelivered.add(this.defineSubscriptionKey(pluginName, store))\n\n if (!isEmpty(stores)) {\n stores?.forEach(\n store => subscription.invoke(\n {\n store,\n options: {\n ...options,\n ...pluginOptions,\n ...((store as AnyObject)?.storeOptions ?? {})\n }\n } as PiniaPluginContext,\n this.debug\n )\n )\n }\n } catch (e) {\n this.logError(`subscriptionDelivery()`, e, store, options)\n }\n }\n}"],"names":["deepClone","value","key","entryValue","item","clonedObject","createStateSnapshot","state","keys","clonedState","toRaw","RollbackStateSnapshotsHandler","__publicField","store","action","stateKeys","args","actionFn","hasDeniedFirstChar","snapshotKey","error","actionName","getActionStoreKey","options","rollbackSnapshotParams","suffix","stateSnapshot","className","defaultPluginExecution","defaultHydrationScheduler","callback","isPluginSubscriptionOptions","PluginSubscription","Debug","subscribers","debugOrOptions","pluginOptions","debug","PluginConsole","storageKey","after","onError","subscriber","pluginName","onActionSubscriptions","hasRollbackSnapshots","name","callbacks","afterCallbacks","onErrorCallbacks","result","context","subscriberKey","hydrateResult","runAfterHydration","afterHydration","e","execution","scheduler","dispose","scopedStore","initState","safeState","currentEnvironment","subscription","mutation","pluginSubscriptions","pluginSubscription","subscriptionKey","subscriptionOptions","stores","isEmpty","store2","createPlugin","createHydrationPlugin","hydrationPlugin"],"mappings":";;;;;;AAMO,SAASA,EAAaC,GAAa;AACtC,MAAI,OAAO,mBAAoB;AAC3B,QAAI;AACA,aAAO,gBAAgBA,CAAK;AAAA,IAChC,QAAQ;AAAA,IAER;AAGJ,MAAIA,MAAU,QAAQ,OAAOA,KAAU;AACnC,WAAOA;AAGX,MAAIA,aAAiB;AACjB,WAAO,IAAI;AAAA,MACP,MAAM,KAAKA,EAAM,QAAA,GAAW,CAAC,CAACC,GAAKC,CAAU,MAAM,CAACH,EAAUE,CAAG,GAAGF,EAAUG,CAAU,CAAC,CAAC;AAAA,IAAA;AAIlG,MAAIF,aAAiB;AACjB,WAAO,IAAI,IAAI,MAAM,KAAKA,EAAM,OAAA,GAAU,CAAAE,MAAcH,EAAUG,CAAU,CAAC,CAAC;AAGlF,MAAI,MAAM,QAAQF,CAAK;AACnB,WAAOA,EAAM,IAAI,CAAAG,MAAQJ,EAAUI,CAAI,CAAC;AAG5C,MAAI,OAAO,eAAeH,CAAK,MAAM,OAAO,aAAa,OAAO,eAAeA,CAAK,MAAM;AACtF,WAAO,OAAO;AAAA,MACV,OAAO,QAAQA,CAAgC,EAAE,IAAI,CAAC,CAACC,GAAKE,CAAI,MAAM,CAACF,GAAKF,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1B;AAAA,UACA;AAAA,UAGF;QAGA;AAAA,MACJ;AAAA,IAGI,SAAAhB,GAAA;AACJ,WAAA,SAAA,0BAAAA,GAAA3C,GAAAU,CAAA;AAAA,IAEA;AAAA,EACI;AAEA;AAEI,SAAAkD,EAASvC,GAAgBG,GAAI;AACzB,QAAA8B,IAAA,IAAAnC,EAAAE,GAAAG,CAAA;AAAA,SAAA8B,EACJ,OAAA,KAAAA,CAAA;AACA;AACuE,SAC1EO,EAAAxC,GAAAX,GAAA;AACD,QAAAoD,IAAA,IAAA3C,EAAAE,GAAAX,GAAA,OAAA;AAAA,IAAA,WACJA,GAAA;AAAA,IAEA,oBAAKA,GAAA;AAAA,IACT,oBAACA,GAAA;AAAA,IACL,qBAAAA,GAAA;AAAA,EAEQ,CAAA;AAKJ,SAAIoD,EAAA,OAAA,KAAAA,CAAA;AACA;"}
@@ -19,7 +19,7 @@ export type ConsoleStyleDefinition = StyleDefinition;
19
19
  export type ConsoleStyleDefinitionKeys = StyleDefinitionKeys;
20
20
  export type ConsoleStyleDefinitions = StyleDefinitions;
21
21
  export type { List, ListTypes, ListTypesMap, PartialList } from './list';
22
- export type { CustomStore, DefineAStoreDefinition, DefineAStoreSetupContext, DefineAStoreSetupExtensions, EmptyExtensions, PluginStoreOptions, StatePropertyValue, StoreOptions, StoreOptionsExtensions, StoreOptionsPropertyValue } from './store';
22
+ export type { CustomStore, DefineAStoreDefinition, DefineAStoreSetupContext, DefineAStoreSetupExtensions, EmptyExtensions, PluginStoreOptions, StatePropertyValue, StoreOptions, StoreOptionsExtensions, StoreOptionsPropertyValue, StrictStateTree } from './store';
23
23
  export type { NativePiniaSubscription, NativePiniaSubscriptionReturn, PluginExecutionEnvironment, PluginExecutionOptions, PluginHydrationScheduler, PluginHydrationTiming, PluginRuntimeEnvironment, PluginSubscriber, PluginSubscription, PluginSubscriptionOptions, PluginSubscriptions, StoreMutationSubscription, StoreMutationSubscriptionCallback, StoreMutationSubscriptionReturn, StoreOnActionCallbackParameters, StoreOnActionSubscription, StoreOnActionSubscriptionCallback, StoreOnActionSubscriptionReturn, } from './plugin';
24
24
  export interface PluginSubscriberInterface {
25
25
  console?: Console;
@@ -13,15 +13,22 @@ export type CustomStore<TStore, TState> = Store & TStore & TState & PiniaCustomP
13
13
  * prototypes. It extends pinia's `StoreDefinition` to stay assignable
14
14
  * wherever a standard store definition is expected.
15
15
  */
16
- export interface DefineAStoreDefinition<TStore, TState, Id extends string = string> extends StoreDefinition<Id, StateTree & TState> {
16
+ export interface DefineAStoreDefinition<TStore, TState, Id extends string = string> extends StoreDefinition<Id, StrictStateTree<TState>> {
17
17
  /**
18
18
  * Returns a store, creates it if necessary.
19
19
  *
20
20
  * @param pinia - Pinia instance to retrieve the store
21
21
  * @param hot - dev only hot module replacement
22
22
  */
23
- (pinia?: Pinia | null, hot?: StoreGeneric): Store<Id, StateTree & TState> & TStore;
23
+ (pinia?: Pinia | null, hot?: StoreGeneric): Store<Id, StrictStateTree<TState>> & TStore;
24
24
  }
25
+ /**
26
+ * Maps a state interface to a pinia `StateTree` without intersecting it with
27
+ * `StateTree` itself, whose `any` index signature would widen every store member to `any`.
28
+ */
29
+ export type StrictStateTree<TState> = {
30
+ [K in keyof TState]: TState[K];
31
+ } extends infer S extends StateTree ? S : never;
25
32
  export type EmptyExtensions = Record<never, never>;
26
33
  export interface DefineAStoreSetupExtensions<TEnhancedStore> {
27
34
  /**
@@ -89,7 +89,7 @@ pinia.use(createPlugin([myStoreSubscriber]))
89
89
  | `hydrate` | `(context, debug) => void \| Promise<void>` | SSR-safe initialization hook; guaranteed to run before `afterHydration`. |
90
90
  | `afterHydration` | `(context, debug) => void \| Promise<void>` | Post-hydration lifecycle hook. |
91
91
  | `resetStoreCallback` | `(store?: Store) => void` | Custom logic executed when a registered store is reset. |
92
- | `storeOnActionSubscription` | `{ store, callback }` (getter) | Action subscription forwarded to pinia's `$onAction`. |
92
+ | `storeOnActionSubscription` | `{ store, callback }` (getter) | Action subscription forwarded to the returned store's `$onAction`, including after deferred hydration; removed on store disposal. |
93
93
  | `storeMutationSubscription` | `{ store, callback }` (getter) | Mutation subscription forwarded to pinia's `$subscribe`. |
94
94
  | `subscriptions` | `Record<string, PluginSubscription>` | Plugin-specific subscription functions exposed to other plugins. |
95
95
  | `console` | `Console` | Custom console used for debug logging. |
@@ -283,7 +283,7 @@ the snapshot is restored through `$patch`, so partial mutations are rolled
283
283
  back. The snapshot is always discarded once the action completes or fails.
284
284
 
285
285
  Only the actions listed in `rollbackAfterFailure` are snapshotted, so
286
- unrelated actions pay no cloning cost. Use `'all'` instead of a key list to
286
+ unrelated actions pay no cloning cost. Use `'all'` or `[]` instead of a key list to
287
287
  snapshot the full state — prefer explicit keys for large states.
288
288
 
289
289
  Action names starting with `_` or `$` are rejected to protect internal store
@@ -310,7 +310,8 @@ try {
310
310
 
311
311
  - `params.action` — the name of the action to execute.
312
312
  - `params.stateKeys` — optional; the state keys to snapshot, or `'all'`
313
- (default when omitted or empty).
313
+ (default when omitted or empty). An empty array also means the full state
314
+ for automatic rollback configured in store options.
314
315
  - `args` — optional; the action arguments, provided as a single array
315
316
  (forwarded to the action via `apply()`).
316
317
  - The original error is rethrown after the state is restored.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinia-plugin-subscription",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Pinia plugin for Vue.js that helps building Pinia plugins by centralizing subscriber registration and providing a Store base class for store helpers.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -92,6 +92,8 @@
92
92
  "@vitest/coverage-v8": "^4.0.15",
93
93
  "@vue/tsconfig": "^0.8.1",
94
94
  "pinia": "^3.0.2",
95
+ "pinia-plugin-action-flow": "^0.1.1",
96
+ "pinia-plugin-extending-store": "^0.1.5-beta.0",
95
97
  "typescript": "~5.9.3",
96
98
  "vite": "^7.2.4",
97
99
  "vitest": "^4.0.15",