pinia-plugin-subscription 1.0.0-beta.0 → 1.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
1
1
  var k = Object.defineProperty;
2
2
  var E = (r, t, e) => t in r ? k(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
3
3
  var c = (r, t, e) => E(r, typeof t != "symbol" ? t + "" : t, e);
4
- import { h as O, g as b, i as _ } from "./chunks/constantes-BsD73jkk.js";
5
- import { p as K, P as M, S as x, d as F, a as W, b as I, c as q, e as z, s as G } from "./chunks/constantes-BsD73jkk.js";
4
+ import { h as O, g as b, i as _, p as g } from "./chunks/constantes-CaTNAbzX.js";
5
+ import { P as M, S as x, d as F, a as W, b as I, c as q, e as z, s as L } from "./chunks/constantes-CaTNAbzX.js";
6
6
  import { toRaw as y } from "vue";
7
7
  function h(r) {
8
8
  if (typeof structuredClone == "function")
@@ -29,7 +29,7 @@ function h(r) {
29
29
  t[e] = h(i);
30
30
  return t;
31
31
  }
32
- function g(r, t = "all") {
32
+ function m(r, t = "all") {
33
33
  if (Array.isArray(t)) {
34
34
  const e = {};
35
35
  for (const i of t)
@@ -40,7 +40,7 @@ function g(r, t = "all") {
40
40
  throw new Error(`Invalid keys parameter: ${t}`);
41
41
  return h(y(r));
42
42
  }
43
- class $ {
43
+ class C {
44
44
  constructor() {
45
45
  c(this, "_stateSnapshots", /* @__PURE__ */ new Map());
46
46
  c(this, "_storeHasRollbackSnapshots", /* @__PURE__ */ new Set());
@@ -54,8 +54,8 @@ class $ {
54
54
  const o = !i || i.length === 0 ? "all" : i, a = this.saveStateSnapshot(t, e, o);
55
55
  try {
56
56
  await n.apply(t, s);
57
- } catch (l) {
58
- throw this.patchStore(a, t), l;
57
+ } catch (u) {
58
+ throw this.patchStore(a, t), u;
59
59
  } finally {
60
60
  this.removeStateSnapshot(a);
61
61
  }
@@ -107,7 +107,7 @@ class $ {
107
107
  t && this._stateSnapshots.delete(t);
108
108
  }
109
109
  saveStateSnapshot(t, e, i) {
110
- const s = g(
110
+ const s = m(
111
111
  t.$state,
112
112
  i
113
113
  ), n = /* @__PURE__ */ Symbol(`${t.$id}:${e}`);
@@ -117,11 +117,11 @@ class $ {
117
117
  return this._storeHasRollbackSnapshots.has(t.$id);
118
118
  }
119
119
  }
120
- const m = "PluginSubscription", C = {
120
+ const $ = "PluginSubscription", w = {
121
121
  environment: "both",
122
122
  hydration: "immediate"
123
123
  };
124
- function w(r) {
124
+ function R(r) {
125
125
  if (typeof window < "u" && typeof window.requestAnimationFrame == "function") {
126
126
  window.requestAnimationFrame(() => globalThis.setTimeout(r, 0));
127
127
  return;
@@ -130,7 +130,7 @@ function w(r) {
130
130
  }
131
131
  class A {
132
132
  constructor(t, e) {
133
- c(this, "_className", m);
133
+ c(this, "_className", $);
134
134
  c(this, "_hydrationScheduler");
135
135
  c(this, "_onActionSubscriptions", /* @__PURE__ */ new Map());
136
136
  c(this, "_onActionStores", /* @__PURE__ */ new Set());
@@ -139,7 +139,7 @@ class A {
139
139
  c(this, "_options");
140
140
  c(this, "_resetStoreCallback", /* @__PURE__ */ new Map());
141
141
  c(this, "_disposedStores", /* @__PURE__ */ new WeakSet());
142
- c(this, "_storeRollbackSnapshotsHandler", new $());
142
+ c(this, "_storeRollbackSnapshotsHandler", new C());
143
143
  c(this, "_subscribers", []);
144
144
  c(this, "_subscribersDelivered", /* @__PURE__ */ new Set());
145
145
  c(this, "_subscribersScheduled", /* @__PURE__ */ new Set());
@@ -147,7 +147,7 @@ class A {
147
147
  c(this, "_subscriptionsDelivered", /* @__PURE__ */ new Set());
148
148
  c(this, "_subscriptionsScheduled", /* @__PURE__ */ new Set());
149
149
  c(this, "_tracer");
150
- this._hydrationScheduler = e?.hydrationScheduler ?? w, this._options = e, this._subscribers = t, this.initializeTracer();
150
+ this._hydrationScheduler = e?.hydrationScheduler ?? R, this._options = e, this._subscribers = t, this.initializeTracer();
151
151
  }
152
152
  set subscribers(t) {
153
153
  this._subscribers = t;
@@ -211,7 +211,7 @@ class A {
211
211
  }
212
212
  definePluginExecution(t) {
213
213
  return {
214
- ...C,
214
+ ...w,
215
215
  ...this._options?.execution ?? {},
216
216
  ...t.execution ?? {},
217
217
  ...this._options?.subscriberExecution?.[t.name] ?? {}
@@ -234,24 +234,24 @@ class A {
234
234
  return;
235
235
  const e = this._onActionSubscriptions.get(t), i = this._storeRollbackSnapshotsHandler.storeHasRollbackSnapshots(t);
236
236
  !e?.size && !i || (this._onActionStores.add(t), t.$onAction(({ after: s, args: n, name: o, onError: a }) => {
237
- const l = b(o, t);
238
- this.trace("plugin:onAction", () => ({
237
+ const u = b(o, t);
238
+ this.trace("plugin:onAction", {
239
239
  args: n,
240
240
  name: o,
241
241
  store: t
242
- }), t.$id), this._storeRollbackSnapshotsHandler.storeHasRollbackSnapshots(t) && this.createRollbackSnapshot(o, t);
243
- const u = this._onActionSubscriptions.get(t);
244
- u?.size && u.forEach((d) => d({
242
+ }, t.$id), this._storeRollbackSnapshotsHandler.storeHasRollbackSnapshots(t) && this.createRollbackSnapshot(o, t);
243
+ const l = this._onActionSubscriptions.get(t);
244
+ l?.size && l.forEach((d) => d({
245
245
  after: this.createOnActionAfterCallbackCollector(o, t),
246
246
  args: n,
247
247
  name: o,
248
248
  onError: this.createOnActionOnErrorCallbackCollector(o, t)
249
249
  }));
250
- const f = this._onActionAfterSubscriptions[l], p = this._onActionOnErrorSubscriptions[l];
251
- this.clearOnActionCallbacksSubscriptions(l), f?.length && s((d) => {
252
- f.forEach((S) => S(d));
253
- }), p?.length && a((d) => {
250
+ const p = this._onActionAfterSubscriptions[u], f = this._onActionOnErrorSubscriptions[u];
251
+ this.clearOnActionCallbacksSubscriptions(u), p?.length && s((d) => {
254
252
  p.forEach((S) => S(d));
253
+ }), f?.length && a((d) => {
254
+ f.forEach((S) => S(d));
255
255
  });
256
256
  }));
257
257
  }
@@ -285,15 +285,15 @@ class A {
285
285
  }
286
286
  }
287
287
  initializeTracer() {
288
- this._options?.createTracer && (this._tracer = this._options.createTracer("PluginSubscription"));
288
+ this._options?.createTracer && (this._tracer = this._options.createTracer(g));
289
289
  }
290
290
  plugin({ store: t, options: e }) {
291
291
  if (this._subscribers.length) {
292
- this.trace("plugin:invoke", () => ({
292
+ this.trace("plugin", {
293
293
  subscribers: this._subscribers,
294
294
  store: t,
295
295
  options: e
296
- }), t.$id);
296
+ }, t.$id);
297
297
  try {
298
298
  this._subscribers.forEach(
299
299
  (i) => {
@@ -327,10 +327,10 @@ class A {
327
327
  rewriteResetStore({ store: t }, e) {
328
328
  const i = h(e);
329
329
  t.$reset = () => {
330
- this.trace("plugin:reset", () => ({
330
+ this.trace("store:reset", {
331
331
  initState: i,
332
332
  store: t
333
- }), t.$id), this.executeResetStoreCallbacks(t), t.$patch(h(i));
333
+ }, t.$id), this.executeResetStoreCallbacks(t), t.$patch(h(i));
334
334
  };
335
335
  }
336
336
  shouldInvokePlugin(t) {
@@ -347,7 +347,7 @@ class A {
347
347
  storeMutationSubscription(t) {
348
348
  const { store: e, callback: i } = t();
349
349
  e.$subscribe((s) => {
350
- this.trace("store:mutation", () => ({ mutation: s, store: e }), e.$id), i(s);
350
+ this.trace("store:mutation", { mutation: s, store: e }, e.$id), i(s);
351
351
  });
352
352
  }
353
353
  subscriptionDelivery(t, e) {
@@ -370,24 +370,24 @@ class A {
370
370
  if (this._subscriptionsDelivered.has(this.defineSubscriptionKey(i, t)))
371
371
  return;
372
372
  const { subscription: n, subscriptionOptions: o, stores: a } = s;
373
- this.trace("subscription:delivery", () => ({
373
+ this.trace("subscription:delivery", {
374
374
  pluginName: i,
375
375
  subscription: n,
376
- options: s,
376
+ options: o,
377
377
  stores: a
378
- }), t.$id);
379
- const l = {
378
+ }, t.$id);
379
+ const u = {
380
380
  storeOptions: { ...e?.storeOptions ?? {}, ...o }
381
381
  };
382
382
  n.invoke(
383
- { store: t, options: { ...e, ...l } }
383
+ { store: t, options: { ...e, ...u } }
384
384
  ), this._subscriptionsDelivered.add(this.defineSubscriptionKey(i, t)), _(a) || a?.forEach(
385
- (u) => n.invoke({
386
- store: u,
385
+ (l) => n.invoke({
386
+ store: l,
387
387
  options: {
388
388
  ...e,
389
- ...l,
390
- ...u?.storeOptions ?? {}
389
+ ...u,
390
+ ...l?.storeOptions ?? {}
391
391
  }
392
392
  })
393
393
  );
@@ -396,17 +396,17 @@ class A {
396
396
  }
397
397
  }
398
398
  trace(t, e, i) {
399
- this._tracer && this._tracer.debug(t, e, i);
399
+ this._tracer && (t = this._className + ":" + t, this._tracer.debug(t, t.toLowerCase(), e, i));
400
400
  }
401
401
  traceError(t, e, i, s) {
402
- this._tracer ? this._tracer.error(t, e, i, s) : console.error(e);
402
+ this._tracer ? (t = this._className + ":" + t, this._tracer.error(t, t.toLowerCase(), e, i, s)) : console.error(e);
403
403
  }
404
404
  }
405
- function H(r, t) {
405
+ function D(r, t) {
406
406
  const e = new A(r, t);
407
407
  return e.plugin.bind(e);
408
408
  }
409
- function D(r, t) {
409
+ function j(r, t) {
410
410
  const e = new A(r, {
411
411
  execution: t?.execution,
412
412
  hydrationScheduler: t?.hydrationScheduler,
@@ -416,17 +416,17 @@ function D(r, t) {
416
416
  return e.plugin.bind(e);
417
417
  }
418
418
  export {
419
- K as PLUGIN_NAME,
419
+ g as PLUGIN_NAME,
420
420
  M as PluginSubscriber,
421
421
  A as PluginSubscription,
422
422
  x as Store,
423
- D as createHydrationPlugin,
424
- H as createPlugin,
423
+ j as createHydrationPlugin,
424
+ D as createPlugin,
425
425
  F as defineAStore,
426
426
  W as defineAStoreCtx,
427
427
  I as getDefineAStoreSetupContext,
428
428
  q as getEnhancedStore,
429
429
  z as getExtendingStore,
430
- G as setEnhancedStore
430
+ L as setEnhancedStore
431
431
  };
432
432
  //# 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) {\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 RollbackStateSnapshotsHandler from \"./RollbackStateSnapshotsHandler\"\nimport { deepClone } from '../utils/deep-clone'\nimport { getActionStoreKey } from '../utils/store'\nimport Tracer from \"../system/Tracer\"\nimport { isEmpty } from \"../utils/validation\"\n\nimport type { PiniaPluginContext, StateTree, Store, SubscriptionCallbackMutation } from \"pinia\"\nimport type { AnyObject } from \"../types\"\nimport type { TracePayload } from \"../types/trace\"\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\nexport default class PluginSubscription {\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 _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 private _tracer?: Tracer\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 options?: PluginSubscriptionOptions\n ) {\n this._hydrationScheduler = options?.hydrationScheduler ?? defaultHydrationScheduler\n this._options = options\n this._subscribers = subscribers\n this.initializeTracer()\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 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.trace('plugin:onAction', () => ({\n args,\n name,\n store,\n }), store.$id)\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\n if (this._subscribersDelivered.has(subscriberKey)) {\n return\n }\n\n if (\n !subscriber.invoke(context, this._options?.createTracer)) {\n return\n }\n\n this._subscribersDelivered.add(subscriberKey)\n\n let hydrateResult: void | Promise<void>\n\n try {\n hydrateResult = subscriber.hydrate?.(context)\n } catch (error) {\n this.traceError('subscriber:hydrate', error, () => ({ store: context.store, options: context.options }), context.store.$id)\n return\n }\n\n const runAfterHydration = () => {\n try {\n const afterHydration = subscriber.afterHydration?.(context)\n if (afterHydration && typeof (afterHydration as Promise<void>).then === 'function') {\n ; (afterHydration as Promise<void>).catch(error => this.traceError('subscriber:afterHydration', error, () => ({ store: context.store, options: context.options }), context.store.$id))\n }\n } catch (error) {\n this.traceError('subscriber:afterHydration', error, () => ({ store: context.store, options: context.options }), context.store.$id)\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.traceError('subscriber:hydrate', error, () => ({ store: context.store, options: context.options }), context.store.$id))\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.traceError('subscriber:execute', e, () => ({ store: context.store, options: context.options }), context.store.$id)\n }\n }\n\n private initializeTracer() {\n if (this._options?.createTracer) {\n this._tracer = this._options.createTracer('PluginSubscription')\n }\n }\n\n /**\n * Invokes the plugin with the given Pinia plugin context, executing all relevant subscribers safely.\n * @param param0 The Pinia plugin context containing the store and options.\n * @param param0.store The Pinia store instance.\n * @param param0.options The options passed to the Pinia store.\n * @returns void\n */\n plugin({ store, options }: PiniaPluginContext) {\n if (!this._subscribers.length) {\n return\n }\n\n this.trace('plugin:invoke', () => ({\n subscribers: this._subscribers,\n store,\n options\n }), store.$id)\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.traceError('plugin:invoke', e, () => ({ store, options }), store.$id)\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.trace('plugin:reset', () => ({\n initState: safeState,\n store\n }), store.$id)\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.trace('store:mutation', () => ({ mutation, store }), store.$id)\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.trace('subscription:delivery', () => ({\n pluginName,\n subscription,\n options: pluginSubscription,\n stores\n }), store.$id)\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 )\n this._subscriptionsDelivered.add(this.defineSubscriptionKey(pluginName, store))\n\n if (!isEmpty(stores)) {\n stores?.forEach(\n store => subscription.invoke({\n store,\n options: {\n ...options,\n ...pluginOptions,\n ...((store as AnyObject)?.storeOptions ?? {})\n }\n } as PiniaPluginContext)\n )\n }\n } catch (e) {\n this.traceError('subscription:delivery', e, () => ({ store, options }), store.$id)\n }\n }\n\n /**\n * Emits a structured trace event.\n * Prefer the factory form for `payload`: it is only resolved when consumed.\n */\n private trace(namespace: string, payload?: TracePayload, scope?: string): void {\n if (this._tracer) {\n this._tracer.debug(namespace, payload, scope)\n }\n }\n\n /**\n * Emits a structured error event, or rethrows it when no listener matches.\n */\n private traceError(namespace: string, error: unknown, payload?: TracePayload, scope?: string): void {\n if (this._tracer) {\n this._tracer.error(namespace, error, payload, scope)\n } else {\n console.error(error)\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","PluginSubscription","subscribers","isEmpty","storageKey","after","onError","subscriber","pluginName","onActionSubscriptions","hasRollbackSnapshots","name","callbacks","afterCallbacks","onErrorCallbacks","result","context","subscriberKey","hydrateResult","runAfterHydration","afterHydration","e","execution","scheduler","scopedStore","dispose","safeState","initState","currentEnvironment","subscription","mutation","pluginSubscriptions","pluginSubscription","subscriptionKey","subscriptionOptions","stores","pluginOptions","store2","namespace","payload","scope","createPlugin","createHydrationPlugin","hydrationPlugin"],"mappings":";;;;;;AAMO,SAASA,EAAaC,GAAa;AACtC,MAAI,OAAO,mBAAoB;AAC3B,QAAI;AACA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IAAA,WACJT,GAAA;AAAA,IAEA,oBAAKA,GAAA;AAAA,IACT,oBAACA,GAAA;AAAA,IACL,qBAAAA,GAAA;AAAA,EAEQ,CAAA;AAKJ,SAAIkD,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 RollbackStateSnapshotsHandler from \"./RollbackStateSnapshotsHandler\"\nimport { deepClone } from '../utils/deep-clone'\nimport { getActionStoreKey } from '../utils/store'\nimport Tracer from \"../system/Tracer\"\nimport { isEmpty } from \"../utils/validation\"\nimport { pluginName } from \"../utils/constantes\"\n\nimport type { PiniaPluginContext, StateTree, Store, SubscriptionCallbackMutation } from \"pinia\"\nimport type { AnyObject } from \"../types\"\nimport type { TracePayload } from \"../types/trace\"\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\nexport default class PluginSubscription {\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 _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 private _tracer?: Tracer\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 options?: PluginSubscriptionOptions\n ) {\n this._hydrationScheduler = options?.hydrationScheduler ?? defaultHydrationScheduler\n this._options = options\n this._subscribers = subscribers\n this.initializeTracer()\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 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.trace('plugin:onAction', {\n args,\n name,\n store,\n }, store.$id)\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\n if (this._subscribersDelivered.has(subscriberKey)) {\n return\n }\n\n if (\n !subscriber.invoke(context, this._options?.createTracer)) {\n return\n }\n\n this._subscribersDelivered.add(subscriberKey)\n\n let hydrateResult: void | Promise<void>\n\n try {\n hydrateResult = subscriber.hydrate?.(context)\n } catch (error) {\n this.traceError('subscriber:hydrate', error, () => ({ store: context.store, options: context.options }), context.store.$id)\n return\n }\n\n const runAfterHydration = () => {\n try {\n const afterHydration = subscriber.afterHydration?.(context)\n if (afterHydration && typeof (afterHydration as Promise<void>).then === 'function') {\n ; (afterHydration as Promise<void>).catch(error => this.traceError('subscriber:afterHydration', error, () => ({ store: context.store, options: context.options }), context.store.$id))\n }\n } catch (error) {\n this.traceError('subscriber:afterHydration', error, () => ({ store: context.store, options: context.options }), context.store.$id)\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.traceError('subscriber:hydrate', error, () => ({ store: context.store, options: context.options }), context.store.$id))\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.traceError('subscriber:execute', e, () => ({ store: context.store, options: context.options }), context.store.$id)\n }\n }\n\n private initializeTracer() {\n if (this._options?.createTracer) {\n this._tracer = this._options.createTracer(pluginName)\n }\n }\n\n /**\n * Invokes the plugin with the given Pinia plugin context, executing all relevant subscribers safely.\n * @param param0 The Pinia plugin context containing the store and options.\n * @param param0.store The Pinia store instance.\n * @param param0.options The options passed to the Pinia store.\n * @returns void\n */\n plugin({ store, options }: PiniaPluginContext) {\n if (!this._subscribers.length) {\n return\n }\n\n this.trace('plugin', {\n subscribers: this._subscribers,\n store,\n options\n }, store.$id)\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.traceError('plugin:invoke', e, () => ({ store, options }), store.$id)\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.trace('store:reset', {\n initState: safeState,\n store\n }, store.$id)\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.trace('store:mutation', { mutation, store }, store.$id)\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.trace('subscription:delivery', {\n pluginName,\n subscription,\n options: subscriptionOptions,\n stores\n }, store.$id)\n\n const pluginOptions = {\n storeOptions: { ...(options?.storeOptions ?? {}), ...subscriptionOptions }\n }\n\n subscription.invoke(\n { store, options: { ...options, ...pluginOptions } } as PiniaPluginContext\n )\n this._subscriptionsDelivered.add(this.defineSubscriptionKey(pluginName, store))\n\n if (!isEmpty(stores)) {\n stores?.forEach(\n store => subscription.invoke({\n store,\n options: {\n ...options,\n ...pluginOptions,\n ...((store as AnyObject)?.storeOptions ?? {})\n }\n } as PiniaPluginContext)\n )\n }\n } catch (e) {\n this.traceError('subscription:delivery', e, () => ({ store, options }), store.$id)\n }\n }\n\n /**\n * Emits a structured trace event.\n * Prefer the factory form for `payload`: it is only resolved when consumed.\n */\n private trace(label: string, payload?: TracePayload, scope?: string): void {\n if (this._tracer) {\n label = this._className + ':' + label\n\n this._tracer.debug(label, label.toLowerCase(), payload, scope)\n }\n }\n\n /**\n * Emits a structured error event, or rethrows it when no listener matches.\n */\n private traceError(label: string, error: unknown, payload?: TracePayload, scope?: string): void {\n if (this._tracer) {\n label = this._className + ':' + label\n this._tracer.error(label, label.toLowerCase(), error, payload, scope)\n } else {\n console.error(error)\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","PluginSubscription","subscribers","isEmpty","storageKey","after","onError","subscriber","pluginName2","onActionSubscriptions","hasRollbackSnapshots","name","callbacks","afterCallbacks","onErrorCallbacks","result","context","pluginName","subscriberKey","hydrateResult","runAfterHydration","afterHydration","e","execution","scheduler","scopedStore","dispose","safeState","initState","currentEnvironment","subscription","mutation","pluginSubscriptions","pluginSubscription","subscriptionKey","subscriptionOptions","stores","pluginOptions","store2","label","payload","scope","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,OAAO;AACzF,MAAI,MAAM,QAAQA,CA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GACJ,KAAA,QAAA,MAAAA,GAAAA,EAAA,YAAA,GAAAjD,GAAAkD,GAAAC,CAAA,KAGI,QAAM,MAAAnD,CAAA;AAAA,EAGN;AACI;AACI,SAAAoD,EACJxC,GAAAT,GAAA;AACA,QAAAwC,IAAK,IAAAhC,KAA8CR,CAAA;AACnD,SAAAwC,EAAK,OAAA,KAAAA,CAAoChB;AAA8B;AAE3E,SACJ0B,EAAAzC,GAAAT,GAAA;AAEA,QAAAmD,IAAK,IAAA3C,EAAoCgB,GAAY;AAAA,IACzD,WAACxB,GAAA;AAAA,IACL,oBAAAA,GAAA;AAAA,IAEQ,oBAAAA,GACF;AAAA,IAIF,qBAAIA,GAAA;AAAA,EACA,CAAA;AACI,SAAAmD,EAAA,OAAA,KAAAA,CAAA;AAAA;"}
@@ -13,8 +13,8 @@ export default class Tracer {
13
13
  get scope(): string | undefined;
14
14
  set scope(scope: string | undefined);
15
15
  get source(): string;
16
- debug(namespace: string, payload?: TracePayload, scope?: string): void;
16
+ debug(label: string, namespace: string, payload?: TracePayload, scope?: string): void;
17
17
  /** Relays the error to matching listeners, or reports it when none match. */
18
- error(namespace: string, error: unknown, payload?: TracePayload, scope?: string): void;
18
+ error(label: string, namespace: string, error: unknown, payload?: TracePayload, scope?: string): void;
19
19
  private emit;
20
20
  }
@@ -1,5 +1,8 @@
1
1
  import type { Console, LogType, StyleDefinition, StyleDefinitions } from '../types/log';
2
+ import type { ConsoleTraceEvent } from '../types/trace';
3
+ export declare function printObject(label: string, payload: object): void;
2
4
  export declare function log(logStyle: string, args: any): void;
5
+ export declare function logTrace(logStyle: string, args: any, pluginName: string): void;
3
6
  export declare abstract class CustomConsole implements Console {
4
7
  protected _bgColor: string;
5
8
  protected _color: string;
@@ -7,7 +10,7 @@ export declare abstract class CustomConsole implements Console {
7
10
  protected _errorBgColor: string;
8
11
  protected _errorColor: string;
9
12
  protected _errorIcon: string;
10
- protected abstract _pluginName: string;
13
+ protected _pluginName?: string;
11
14
  protected _styles: StyleDefinitions;
12
15
  protected formatMessage(message: string, icon: string): string;
13
16
  protected generateStyle(styleDefinition: StyleDefinition): string;
@@ -21,4 +24,12 @@ declare class PluginConsoleClass extends CustomConsole {
21
24
  protected _pluginName: string;
22
25
  }
23
26
  export declare const PluginConsole: PluginConsoleClass;
27
+ export declare class TraceConsole extends CustomConsole {
28
+ protected _pluginName: string;
29
+ constructor(pluginName?: string);
30
+ logGroup(label: string, group: ConsoleTraceEvent[]): void;
31
+ private startGroup;
32
+ private endGroup;
33
+ protected useLog(styleDefinition: StyleDefinition, args: any): void;
34
+ }
24
35
  export {};
@@ -31,8 +31,8 @@ export type ConsoleStyleDefinitionKeys = StyleDefinitionKeys;
31
31
  export type ConsoleStyleDefinitions = StyleDefinitions;
32
32
  export type { List, ListTypes, ListTypesMap, PartialList } from './list';
33
33
  export type { TraceEvent, TraceEventMetadata, TraceFilter, TraceHandler, TraceLevel, TraceListener, TraceListenerRemover, TracePayload, TraceRegistry, TracerOptions } from './trace';
34
- export type { CustomStore, DefineAStoreSetupContext, DefineAStoreSetupExtensions, EmptyExtensions, PluginStoreOptions, StatePropertyValue, StoreOptions, StoreOptionsPropertyValue } from './store';
35
- export type { NativePiniaSubscription, NativePiniaSubscriptionReturn, PluginExecutionEnvironment, PluginExecutionOptions, PluginHydrationScheduler, PluginHydrationTiming, PluginRuntimeEnvironment, PluginSubscriber, PluginSubscription, PluginSubscriptionOptions, PluginSubscriptions, StoreMutationSubscription, StoreMutationSubscriptionCallback, StoreMutationSubscriptionReturn, StoreOnActionCallbackParameters, StoreOnActionSubscription, StoreOnActionSubscriptionCallback, StoreOnActionSubscriptionReturn, } from './plugin';
34
+ export type { CustomStore, DefineAStoreSetupContext, DefineAStoreSetupExtensions, EmptyExtensions, StatePropertyValue, StoreOptions, StoreOptionsPropertyValue } from './store';
35
+ export type { NativePiniaSubscription, NativePiniaSubscriptionReturn, PluginExecutionEnvironment, PluginExecutionOptions, PluginHydrationScheduler, PluginHydrationTiming, PluginRuntimeEnvironment, PluginStoreOptions, PluginSubscriber, PluginSubscription, PluginSubscriptionOptions, PluginSubscriptions, StoreClassConstructorParams, StoreMutationSubscription, StoreMutationSubscriptionCallback, StoreMutationSubscriptionReturn, StoreOnActionCallbackParameters, StoreOnActionSubscription, StoreOnActionSubscriptionCallback, StoreOnActionSubscriptionReturn, } from './plugin';
36
36
  export interface PluginSubscriberInterface {
37
37
  execution?: PluginExecutionOptions;
38
38
  hydrate?: (context: PiniaPluginContext) => void | Promise<void>;
@@ -8,14 +8,58 @@ export type PluginHydrationTiming = 'defer' | 'immediate';
8
8
  export type PluginRuntimeEnvironment = 'client' | 'server';
9
9
  export type PluginExecutionEnvironment = PluginRuntimeEnvironment | 'both';
10
10
  export interface PluginExecutionOptions {
11
+ /**
12
+ * Execution environment for the plugin subscriber.
13
+ * @type {PluginExecutionEnvironment | undefined}
14
+ */
11
15
  environment?: PluginExecutionEnvironment;
16
+ /**
17
+ * Hydration timing for the plugin subscriber.
18
+ * @type {PluginHydrationTiming | undefined}
19
+ */
12
20
  hydration?: PluginHydrationTiming;
13
21
  }
22
+ export interface PluginStoreOptions {
23
+ /**
24
+ * Store options for the plugin subscriber.
25
+ * @type {StoreOptions}
26
+ */
27
+ storeOptions?: StoreOptions;
28
+ }
14
29
  export interface PluginSubscriptionOptions {
30
+ /**
31
+ * Creates a new tracer instance for the plugin subscriber.
32
+ * @param source The source string used to create the tracer.
33
+ * @returns A new instance of the Tracer class.
34
+ * @see Tracer for more details on the tracer implementation.
35
+ */
15
36
  createTracer?: (source: string) => Tracer;
37
+ /**
38
+ * Execution options for the plugin subscriber.
39
+ * This determines how and when the plugin subscriber should be executed.
40
+ * @type {PluginExecutionOptions | undefined}
41
+ */
16
42
  execution?: PluginExecutionOptions;
43
+ /**
44
+ * Store options for the plugin subscriber.
45
+ * @type {StoreOptions | undefined}
46
+ */
47
+ storeOptions?: StoreOptions;
48
+ /**
49
+ * Hydration scheduler for the plugin subscriber.
50
+ * @type {PluginHydrationScheduler | undefined}
51
+ */
17
52
  hydrationScheduler?: PluginHydrationScheduler;
53
+ /**
54
+ * Runtime environment for the plugin subscriber.
55
+ * @type {PluginRuntimeEnvironment | undefined}
56
+ */
18
57
  runtimeEnvironment?: PluginRuntimeEnvironment;
58
+ /**
59
+ * Execution options for individual subscribers of the plugin.
60
+ * This allows specifying different execution configurations for different subscribers.
61
+ * @type {Record<string, PluginExecutionOptions> | undefined}
62
+ */
19
63
  subscriberExecution?: Record<string, PluginExecutionOptions>;
20
64
  }
21
65
  export interface PluginSubscriber {
@@ -69,17 +113,49 @@ export interface PluginSubscriber {
69
113
  */
70
114
  afterHydration?: (context: PiniaPluginContext) => void | Promise<void>;
71
115
  }
116
+ /**
117
+ * Return type for native Pinia subscriptions.
118
+ * @template Callback - The type of the callback function for the subscription.
119
+ */
72
120
  export interface NativePiniaSubscriptionReturn<Callback> {
121
+ /**
122
+ * The store associated with the subscription.
123
+ * @type {Store}
124
+ */
73
125
  store: Store;
126
+ /**
127
+ * The callback function for the subscription.
128
+ * @type {Callback}
129
+ */
74
130
  callback: Callback;
75
131
  }
132
+ export type StoreClassConstructorParams = Omit<PluginSubscriptionOptions, 'createTracer'> & {
133
+ createTracer?: () => Tracer;
134
+ storeOptions?: StoreOptions;
135
+ };
76
136
  export type StoreOnActionAfterCallbackParameter = (callback: (result?: unknown) => void) => void;
77
137
  export type StoreOnActionOnErrorCallbackParameter = (callback: (error: unknown) => void) => void;
78
138
  export interface StoreOnActionCallbackParameters {
139
+ /**
140
+ * Callback to be executed after the action is completed.
141
+ * @type {StoreOnActionAfterCallbackParameter}
142
+ */
79
143
  after: StoreOnActionAfterCallbackParameter;
144
+ /**
145
+ * The arguments passed to the action.
146
+ * @type {any[] | object}
147
+ */
80
148
  args: any[] | object;
149
+ /**
150
+ * The name of the action being subscribed to.
151
+ * @type {string}
152
+ */
81
153
  name: string;
82
- onError?: StoreOnActionOnErrorCallbackParameter;
154
+ /**
155
+ * Callback to be executed if an error occurs during the action.
156
+ * @type {StoreOnActionOnErrorCallbackParameter}
157
+ */
158
+ onError: StoreOnActionOnErrorCallbackParameter;
83
159
  }
84
160
  export interface PluginSubscription {
85
161
  stores?: Store[];