pinia-plugin-subscription 1.0.0-beta.12 → 1.0.0-beta.13

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,9 +1,9 @@
1
- var R = Object.defineProperty;
2
- var T = (i, s, t) => s in i ? R(i, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[s] = t;
3
- var a = (i, s, t) => T(i, typeof s != "symbol" ? s + "" : s, t);
4
- import { toRaw as O } from "vue";
5
- import { defineStore as m } from "pinia";
6
- function d(i) {
1
+ var H = Object.defineProperty;
2
+ var R = (i, s, t) => s in i ? H(i, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[s] = t;
3
+ var u = (i, s, t) => R(i, typeof s != "symbol" ? s + "" : s, t);
4
+ import { toRaw as m } from "vue";
5
+ import { defineStore as C } from "pinia";
6
+ function l(i) {
7
7
  if (typeof structuredClone == "function")
8
8
  try {
9
9
  return structuredClone(i);
@@ -13,31 +13,31 @@ function d(i) {
13
13
  return i;
14
14
  if (i instanceof Map)
15
15
  return new Map(
16
- Array.from(i.entries(), ([t, e]) => [d(t), d(e)])
16
+ Array.from(i.entries(), ([t, e]) => [l(t), l(e)])
17
17
  );
18
18
  if (i instanceof Set)
19
- return new Set(Array.from(i.values(), (t) => d(t)));
19
+ return new Set(Array.from(i.values(), (t) => l(t)));
20
20
  if (Array.isArray(i))
21
- return i.map((t) => d(t));
21
+ return i.map((t) => l(t));
22
22
  if (Object.getPrototypeOf(i) === Object.prototype || Object.getPrototypeOf(i) === null)
23
23
  return Object.fromEntries(
24
- Object.entries(i).map(([t, e]) => [t, d(e)])
24
+ Object.entries(i).map(([t, e]) => [t, l(e)])
25
25
  );
26
26
  const s = Object.create(Object.getPrototypeOf(i));
27
27
  for (const [t, e] of Object.entries(i))
28
- s[t] = d(e);
28
+ s[t] = l(e);
29
29
  return s;
30
30
  }
31
- function x(i, s = "all") {
31
+ function G(i, s = "all") {
32
32
  if (Array.isArray(s)) {
33
33
  const t = {};
34
34
  for (const e of s)
35
- e in i && (t[e] = d(O(i[e])));
35
+ e in i && (t[e] = l(m(i[e])));
36
36
  return t;
37
37
  }
38
38
  if (s !== "all")
39
39
  throw new Error(`Invalid keys parameter: ${s}`);
40
- return d(O(i));
40
+ return l(m(i));
41
41
  }
42
42
  const A = /* @__PURE__ */ new WeakMap(), b = /* @__PURE__ */ new Map(), E = /* @__PURE__ */ new WeakSet();
43
43
  function P(i, s) {
@@ -46,19 +46,19 @@ function P(i, s) {
46
46
  const t = i.$dispose;
47
47
  i.$dispose = (...e) => (A.delete(i), b.delete(s), t.apply(i, e)), E.add(i);
48
48
  }
49
- function U(i, s, t) {
49
+ function B(i, s, t) {
50
50
  const e = t ? { storeOptions: t } : {};
51
51
  return typeof s == "function" ? w(
52
52
  i,
53
53
  s,
54
54
  e
55
- ) : v(
55
+ ) : x(
56
56
  i,
57
57
  s,
58
58
  e
59
59
  );
60
60
  }
61
- function B(i, s, t) {
61
+ function J(i, s, t) {
62
62
  const e = t ? { storeOptions: { ...t, enhancedStore: !0 } } : { storeOptions: { enhancedStore: !0 } };
63
63
  return w(
64
64
  i,
@@ -67,38 +67,38 @@ function B(i, s, t) {
67
67
  );
68
68
  }
69
69
  function w(i, s, t) {
70
- const e = {
71
- id: i,
72
- extensions: {}
73
- }, r = t?.storeOptions?.enhancedStore === !0, n = m(
70
+ let e;
71
+ const r = t?.storeOptions?.enhancedStore === !0, n = C(
74
72
  i,
75
- () => s(e),
73
+ () => (e = {
74
+ id: i,
75
+ extensions: {}
76
+ }, r && b.set(i, e), s(e)),
76
77
  t
77
78
  );
78
- return Object.assign(((...c) => {
79
- r && b.set(i, e);
80
- const o = n(...c);
81
- return r && (A.set(o, e), b.delete(i), P(o, i)), o;
79
+ return Object.assign(((...o) => {
80
+ const c = n(...o);
81
+ return r && e && (A.set(c, e), b.delete(i), P(c, i)), c;
82
82
  }), n);
83
83
  }
84
- function v(i, s, t) {
85
- return t && (s = { ...s, ...t ?? {} }), m(i, s);
84
+ function x(i, s, t) {
85
+ return t && (s = { ...s, ...t ?? {} }), C(i, s);
86
86
  }
87
- const G = /* @__PURE__ */ new Set(["_", "$"]);
87
+ const v = /* @__PURE__ */ new Set(["_", "$"]);
88
88
  function D(i) {
89
- return G.has(i[0]);
89
+ return v.has(i[0]);
90
90
  }
91
- function J(i) {
91
+ function Q(i) {
92
92
  const s = i;
93
93
  return A.get(i) ?? (typeof s?.$id == "string" ? b.get(s.$id) : void 0);
94
94
  }
95
- function Q(i) {
95
+ function V(i) {
96
96
  const s = i.extensions.enhancedStore ?? i.extensions.extending;
97
97
  if (!s)
98
98
  throw new Error(`${i.id}Store - getEnhancedStore - Error: enhanced store is required`);
99
99
  return s;
100
100
  }
101
- function V(i, s) {
101
+ function X(i, s) {
102
102
  i.extensions.enhancedStore = s, i.extensions.extending = s;
103
103
  }
104
104
  function f(i, s) {
@@ -113,22 +113,22 @@ function _(i, s) {
113
113
  }
114
114
  class j {
115
115
  constructor() {
116
- a(this, "_stateSnapshots", /* @__PURE__ */ new Map());
117
- a(this, "_storeHasRollbackSnapshots", /* @__PURE__ */ new Set());
118
- a(this, "_storeRollbackSnapshotsParams", /* @__PURE__ */ new Map());
116
+ u(this, "_stateSnapshots", /* @__PURE__ */ new Map());
117
+ u(this, "_storeHasRollbackSnapshots", /* @__PURE__ */ new Set());
118
+ u(this, "_storeRollbackSnapshotsParams", /* @__PURE__ */ new Map());
119
119
  }
120
120
  addRollbackAction(s) {
121
121
  typeof s.$rollbackAfterFailure != "function" && (s.$rollbackAfterFailure = async ({ action: t, stateKeys: e }, r = []) => {
122
122
  const n = s[t];
123
123
  if (typeof n != "function" || D(t))
124
124
  return;
125
- const c = !e || e.length === 0 ? "all" : e, o = this.saveStateSnapshot(s, t, c);
125
+ const o = !e || e.length === 0 ? "all" : e, c = this.saveStateSnapshot(s, t, o);
126
126
  try {
127
127
  await n.apply(s, r);
128
- } catch (u) {
129
- throw this.patchStore(o, s), u;
128
+ } catch (a) {
129
+ throw this.patchStore(c, s), a;
130
130
  } finally {
131
- this.removeStateSnapshot(o);
131
+ this.removeStateSnapshot(c);
132
132
  }
133
133
  });
134
134
  }
@@ -138,7 +138,7 @@ class j {
138
138
  );
139
139
  if (!e)
140
140
  return;
141
- const r = e.length === 0 ? "all" : e, n = this.saveStateSnapshot(t, s, r);
141
+ const r = e.length === 0 || e[0] === "all" ? "all" : e, n = this.saveStateSnapshot(t, s, r);
142
142
  return {
143
143
  after: () => {
144
144
  this.removeStateSnapshot(n);
@@ -179,7 +179,7 @@ class j {
179
179
  s && this._stateSnapshots.delete(s);
180
180
  }
181
181
  saveStateSnapshot(s, t, e) {
182
- const r = x(
182
+ const r = G(
183
183
  s.$state,
184
184
  e
185
185
  ), n = Symbol(f(t, s));
@@ -189,10 +189,10 @@ class j {
189
189
  return this._storeHasRollbackSnapshots.has(s.$id);
190
190
  }
191
191
  }
192
- class F {
192
+ class I {
193
193
  constructor() {
194
- a(this, "_tracer");
195
- a(this, "_traceOptions", {
194
+ u(this, "_tracer");
195
+ u(this, "_traceOptions", {
196
196
  addClassNameToLabel: !0
197
197
  });
198
198
  }
@@ -210,62 +210,62 @@ class F {
210
210
  n && (s = this.traceLabelFormatter(s), n.debug(s, r ?? s.toLowerCase(), e, t));
211
211
  }
212
212
  traceError(s, t, e, r, n) {
213
- const c = this.tracer;
214
- c ? (s = this.traceLabelFormatter(s), c.error(s, n ?? s.toLowerCase(), t, r, e)) : console.error(t);
213
+ const o = this.tracer;
214
+ o ? (s = this.traceLabelFormatter(s), o.error(s, n ?? s.toLowerCase(), t, r, e)) : console.error(t);
215
215
  }
216
216
  traceLabelFormatter(s) {
217
217
  return this.classNameAddedToTraceNamespace ? `${this._className}:${s}` : s;
218
218
  }
219
219
  }
220
- function C(i) {
220
+ function O(i) {
221
221
  return i ? Array.isArray(i) ? i.length === 0 : typeof i == "object" ? Object.keys(i).length === 0 : typeof i == "string" ? i.trim() === "" : !1 : !(typeof i == "boolean" || typeof i == "number");
222
222
  }
223
- const I = "pinia-plugin-subscription", M = "PluginSubscription", X = M.toLowerCase(), l = {
223
+ const F = "pinia-plugin-subscription", T = "PluginSubscription", Y = T.toLowerCase(), d = {
224
224
  onActionAfter: (i) => `store:onAction:after:${i}`,
225
225
  onActionError: (i) => `store:onAction:onError:${i}`,
226
226
  onMutation: (i) => `store:onMutation:${i}`,
227
227
  reset: (i) => `store:reset:${i}`
228
- }, K = M, W = {
228
+ }, K = T, W = {
229
229
  environment: "both",
230
230
  hydration: "immediate"
231
- };
232
- function L(i) {
231
+ }, L = 2500;
232
+ function N(i) {
233
233
  if (typeof window < "u" && typeof window.requestAnimationFrame == "function") {
234
234
  window.requestAnimationFrame(() => globalThis.setTimeout(i, 0));
235
235
  return;
236
236
  }
237
237
  globalThis.setTimeout(i, 0);
238
238
  }
239
- class Y extends F {
239
+ class Z extends I {
240
240
  constructor(t, e) {
241
241
  super();
242
- a(this, "_className", K);
243
- a(this, "_hydrationScheduler");
244
- a(this, "_onActionSubscriptions", /* @__PURE__ */ new Map());
245
- a(this, "_onActionSubscriptionsTraces", /* @__PURE__ */ new Map());
246
- a(this, "_onActionStores", /* @__PURE__ */ new Set());
247
- a(this, "_onActionAfterSubscriptions", {});
248
- a(this, "_onActionOnErrorSubscriptions", {});
249
- a(this, "_onMutationSubscriptions", /* @__PURE__ */ new Map());
250
- a(this, "_onMutationSubscriptionsTraces", /* @__PURE__ */ new Map());
251
- a(this, "_onMutationUnsubscribes", /* @__PURE__ */ new Map());
252
- a(this, "_options");
253
- a(this, "_resetStoreCallback", /* @__PURE__ */ new Map());
254
- a(this, "_disposedStores", /* @__PURE__ */ new WeakSet());
255
- a(this, "_storeRollbackSnapshotsHandler", new j());
256
- a(this, "_subscribers", []);
257
- a(this, "_subscribersDelivered", /* @__PURE__ */ new Set());
258
- a(this, "_subscribersScheduled", /* @__PURE__ */ new Set());
259
- a(this, "_subscriptions", []);
260
- a(this, "_subscriptionsDelivered", /* @__PURE__ */ new Set());
261
- a(this, "_subscriptionsScheduled", /* @__PURE__ */ new Set());
262
- this._hydrationScheduler = e?.hydrationScheduler ?? L, this._options = e, this._subscribers = t, this.initializeTracer();
242
+ u(this, "_className", K);
243
+ u(this, "_hydrationScheduler");
244
+ u(this, "_onActionSubscriptions", /* @__PURE__ */ new Map());
245
+ u(this, "_onActionSubscriptionsTraces", /* @__PURE__ */ new Map());
246
+ u(this, "_onActionStores", /* @__PURE__ */ new Set());
247
+ u(this, "_onActionAfterSubscriptions", {});
248
+ u(this, "_onActionOnErrorSubscriptions", {});
249
+ u(this, "_onMutationSubscriptions", /* @__PURE__ */ new Map());
250
+ u(this, "_onMutationSubscriptionsTraces", /* @__PURE__ */ new Map());
251
+ u(this, "_onMutationUnsubscribes", /* @__PURE__ */ new Map());
252
+ u(this, "_options");
253
+ u(this, "_resetStoreCallback", /* @__PURE__ */ new Map());
254
+ u(this, "_disposedStores", /* @__PURE__ */ new WeakSet());
255
+ u(this, "_storeRollbackSnapshotsHandler", new j());
256
+ u(this, "_subscribers", []);
257
+ u(this, "_subscribersDelivered", /* @__PURE__ */ new Set());
258
+ u(this, "_subscribersScheduled", /* @__PURE__ */ new Set());
259
+ u(this, "_subscriptions", []);
260
+ u(this, "_subscriptionsDelivered", /* @__PURE__ */ new Set());
261
+ u(this, "_subscriptionsScheduled", /* @__PURE__ */ new Set());
262
+ this._hydrationScheduler = e?.hydrationScheduler ?? N, this._options = e, this._subscribers = t, this.initializeTracer();
263
263
  }
264
264
  set subscribers(t) {
265
265
  this._subscribers = t;
266
266
  }
267
267
  get subscriptions() {
268
- if (!C(this._subscriptions))
268
+ if (!O(this._subscriptions))
269
269
  return this._subscriptions;
270
270
  }
271
271
  addOnActionAfterCallback(t, e, r) {
@@ -345,32 +345,32 @@ class Y extends F {
345
345
  if (this._onActionStores.has(t) || typeof t.$onAction != "function")
346
346
  return;
347
347
  const e = this._onActionSubscriptions.get(t), r = this._storeRollbackSnapshotsHandler.storeHasRollbackSnapshots(t);
348
- !e?.size && !r || (this._onActionStores.add(t), t.$onAction(({ after: n, args: c, name: o, onError: u }) => {
348
+ !e?.size && !r || (this._onActionStores.add(t), t.$onAction(({ after: n, args: o, name: c, onError: a }) => {
349
349
  const h = this._onActionSubscriptions.get(t);
350
350
  if (!h?.size)
351
351
  return;
352
- this.traceGroupStart(() => ({ args: c }), t.$id, `store:onAction:${o}`);
352
+ this.traceGroupStart(() => ({ args: o }), t.$id, `store:onAction:${c}`);
353
353
  let p = !1;
354
354
  const k = () => {
355
355
  p || (p = !0, this.traceGroupEnd({}, t.$id));
356
356
  };
357
357
  try {
358
- const S = f(o, t);
359
- this._storeRollbackSnapshotsHandler.storeHasRollbackSnapshots(t) && this.createRollbackSnapshot(o, t);
358
+ const S = f(c, t);
359
+ this._storeRollbackSnapshotsHandler.storeHasRollbackSnapshots(t) && this.createRollbackSnapshot(c, t);
360
360
  const $ = [];
361
- h.forEach((H) => {
361
+ h.forEach((M) => {
362
362
  const g = this.runCallbackSafely(
363
- () => H({
364
- after: this.createOnActionAfterCallbackCollector(o, t),
365
- args: c,
366
- name: o,
367
- onError: this.createOnActionOnErrorCallbackCollector(o, t)
363
+ () => M({
364
+ after: this.createOnActionAfterCallbackCollector(c, t),
365
+ args: o,
366
+ name: c,
367
+ onError: this.createOnActionOnErrorCallbackCollector(c, t)
368
368
  }),
369
369
  "store:onAction:callback:error",
370
370
  t.$id
371
371
  );
372
372
  g && $.push(g);
373
- }), this.endGroupAfter($, k), this.executeStoreOnActionAfterCallbacks(n, S, t, o), this.executeStoreOnActionOnErrorCallbacks(u, S, t, o), this.clearOnActionCallbacksSubscriptions(S);
373
+ }), this.endGroupAfter($, k), this.executeStoreOnActionAfterCallbacks(n, S, t, c), this.executeStoreOnActionOnErrorCallbacks(a, S, t, c), this.clearOnActionCallbacksSubscriptions(S);
374
374
  } catch (S) {
375
375
  throw k(), S;
376
376
  }
@@ -378,15 +378,15 @@ class Y extends F {
378
378
  }
379
379
  runCallbackSafely(t, e, r, n) {
380
380
  try {
381
- const c = t();
382
- if (c && typeof c.then == "function")
383
- return Promise.resolve(c).then(
381
+ const o = t();
382
+ if (o && typeof o.then == "function")
383
+ return Promise.resolve(o).then(
384
384
  () => {
385
385
  },
386
- (o) => this.traceError(e, o, r, n)
386
+ (c) => this.traceError(e, c, r, n)
387
387
  );
388
- } catch (c) {
389
- this.traceError(e, c, r, n);
388
+ } catch (o) {
389
+ this.traceError(e, o, r, n);
390
390
  }
391
391
  }
392
392
  endGroupAfter(t, e) {
@@ -394,44 +394,44 @@ class Y extends F {
394
394
  r.length ? Promise.all(r).then(e) : e();
395
395
  }
396
396
  executeStoreOnActionAfterCallbacks(t, e, r, n) {
397
- const c = this._onActionAfterSubscriptions[e];
398
- c?.length && t((o) => {
397
+ const o = this._onActionAfterSubscriptions[e];
398
+ o?.length && t((c) => {
399
399
  this.traceGroupStart(
400
400
  () => ({
401
- groupId: l.onActionAfter(r.$id),
402
- result: o
401
+ groupId: d.onActionAfter(r.$id),
402
+ result: c
403
403
  }),
404
404
  r.$id,
405
405
  `store:onAction:after:${n}`
406
406
  );
407
- const u = c.map((h) => this.runCallbackSafely(
408
- () => h(o),
407
+ const a = o.map((h) => this.runCallbackSafely(
408
+ () => h(c),
409
409
  "storeOnActionAfterCallbacks",
410
410
  r.$id,
411
411
  () => ({ "action name": n })
412
412
  ));
413
- this.endGroupAfter(u, () => this.traceGroupEnd(() => ({ groupId: l.onActionAfter(r.$id) }), r.$id));
413
+ this.endGroupAfter(a, () => this.traceGroupEnd(() => ({ groupId: d.onActionAfter(r.$id) }), r.$id));
414
414
  });
415
415
  }
416
416
  executeStoreOnActionOnErrorCallbacks(t, e, r, n) {
417
- const c = this._onActionOnErrorSubscriptions[e];
418
- c?.length && t((o) => {
417
+ const o = this._onActionOnErrorSubscriptions[e];
418
+ o?.length && t((c) => {
419
419
  this.traceGroupStart(
420
420
  () => ({
421
421
  "action name": n,
422
- error: o,
423
- groupId: l.onActionError(r.$id)
422
+ error: c,
423
+ groupId: d.onActionError(r.$id)
424
424
  }),
425
425
  r.$id,
426
426
  `store:onAction:onError:${n}`
427
427
  );
428
- const u = c.map((h) => this.runCallbackSafely(
429
- () => h(o),
428
+ const a = o.map((h) => this.runCallbackSafely(
429
+ () => h(c),
430
430
  "store:onAction:onError:error",
431
431
  r.$id,
432
- () => ({ groupId: l.onActionError(r.$id) })
432
+ () => ({ groupId: d.onActionError(r.$id) })
433
433
  ));
434
- this.endGroupAfter(u, () => this.traceGroupEnd(() => ({ groupId: l.onActionError(r.$id) }), r.$id));
434
+ this.endGroupAfter(a, () => this.traceGroupEnd(() => ({ groupId: d.onActionError(r.$id) }), r.$id));
435
435
  });
436
436
  }
437
437
  executeSubscriber(t, e) {
@@ -442,31 +442,33 @@ class Y extends F {
442
442
  let n;
443
443
  try {
444
444
  n = e.hydrate?.(t);
445
- } catch (o) {
446
- this.traceError("subscriber:hydrate", o, t.store.$id);
445
+ } catch (a) {
446
+ this.traceError("subscriber:hydrate", a, t.store.$id);
447
447
  return;
448
448
  }
449
- const c = () => {
449
+ const o = () => {
450
450
  try {
451
- const o = e.afterHydration?.(t);
452
- o && typeof o.then == "function" && o.catch(
453
- (u) => this.traceError("subscriber:afterHydration", u, t.store.$id)
454
- );
455
- } catch (o) {
456
- this.traceError("subscriber:afterHydration", o, t.store.$id);
451
+ const a = e.afterHydration?.(t);
452
+ if (a && typeof a.then == "function")
453
+ return a.catch(
454
+ (h) => this.traceError("subscriber:afterHydration", h, t.store.$id)
455
+ );
456
+ } catch (a) {
457
+ this.traceError("subscriber:afterHydration", a, t.store.$id);
457
458
  }
458
459
  };
459
- n && typeof n.then == "function" ? n.then(() => c()).catch((o) => this.traceError("subscriber:hydrate", o, t.store.$id)) : c(), e.subscriptions && this.subscriptionDelivery(t, e.subscriptions), e.storeMutationSubscription && this.storeMutationSubscription(e, e.storeMutationSubscription), this.storeOnActionSubscription(e, t), e.resetStoreCallback && this.addResetStoreCallback(t.store, e.resetStoreCallback);
460
+ let c;
461
+ return n && typeof n.then == "function" ? c = n.then(() => o()).catch((a) => this.traceError("subscriber:hydrate", a, t.store.$id)) : c = o(), e.subscriptions && this.subscriptionDelivery(t, e.subscriptions), e.storeMutationSubscription && this.storeMutationSubscription(e, e.storeMutationSubscription), this.storeOnActionSubscription(e, t), e.resetStoreCallback && this.addResetStoreCallback(t.store, e.resetStoreCallback), c;
460
462
  }
461
463
  executeSubscriberSafely(t, e) {
462
464
  try {
463
- this.executeSubscriber(t, e);
465
+ return this.executeSubscriber(t, e);
464
466
  } catch (r) {
465
467
  this.traceError("subscriber:execute", r, t.store.$id);
466
468
  }
467
469
  }
468
470
  initializeTracer() {
469
- this._options?.tracerHandler && (this._tracer = this._options.tracerHandler.createTracer(I));
471
+ this._options?.tracerHandler && (this._tracer = this._options.tracerHandler.createTracer(F));
470
472
  }
471
473
  plugin({ store: t, options: e }) {
472
474
  if (!this._subscribers.length)
@@ -488,10 +490,10 @@ class Y extends F {
488
490
  try {
489
491
  this._subscribers.forEach(
490
492
  (n) => {
491
- const c = this.defineSubscriberKey(n, t), o = this.definePluginExecution(n);
492
- if (!(this._subscribersDelivered.has(c) || this._subscribersScheduled.has(c)) && this.shouldInvokePlugin(o)) {
493
- if (this.shouldScheduleAfterHydration(o)) {
494
- this.queueSubscriberExecution({ store: t, options: e }, n, c);
493
+ const o = this.defineSubscriberKey(n, t), c = this.definePluginExecution(n);
494
+ if (!(this._subscribersDelivered.has(o) || this._subscribersScheduled.has(o)) && this.shouldInvokePlugin(c)) {
495
+ if (this.shouldScheduleAfterHydration(c)) {
496
+ this.queueSubscriberExecution({ store: t, options: e }, n, o);
495
497
  return;
496
498
  }
497
499
  this.executeSubscriber({ store: t, options: e }, n);
@@ -506,9 +508,33 @@ class Y extends F {
506
508
  queueSubscriberExecution(t, e, r) {
507
509
  const n = this.defineHydrationScheduler(e);
508
510
  this._subscribersScheduled.add(r), n(() => {
509
- this._disposedStores.has(t.store) || (this._subscribersScheduled.delete(r), this.executeSubscriberSafely(t, e));
511
+ if (this._disposedStores.has(t.store))
512
+ return;
513
+ this._subscribersScheduled.delete(r);
514
+ const o = t.store.$id;
515
+ this.traceGroupStart(() => ({ subscriber: e.name }), o, "subscriber:deferred");
516
+ const c = () => this.traceGroupEnd(() => ({}), o);
517
+ let a;
518
+ try {
519
+ a = this.executeSubscriberSafely(t, e);
520
+ } finally {
521
+ a ? this.closeGroupWhenSettled(a, c, o, e.name) : c();
522
+ }
510
523
  });
511
524
  }
525
+ closeGroupWhenSettled(t, e, r, n) {
526
+ let o = !1;
527
+ const c = () => {
528
+ o || (o = !0, globalThis.clearTimeout(h), e());
529
+ }, a = this._options?.deferredTraceGroupTimeout ?? L, h = globalThis.setTimeout(() => {
530
+ o || (this.traceError(
531
+ "subscriber:deferred:timeout",
532
+ new Error(`Subscriber "${n}" hydration still pending after ${a}ms`),
533
+ r
534
+ ), c());
535
+ }, a);
536
+ t.then(c, c);
537
+ }
512
538
  registerStoreCleanup(t) {
513
539
  if (typeof t.$dispose != "function")
514
540
  return;
@@ -516,13 +542,13 @@ class Y extends F {
516
542
  r.__piniaPluginSubscriptionDisposed || (r.__piniaPluginSubscriptionDisposed = !0, t.$dispose = () => (this._disposedStores.add(t), this.clearStoreTracking(t), this._storeRollbackSnapshotsHandler.clearStoreTracking(t), e()));
517
543
  }
518
544
  rewriteResetStore({ store: t }, e) {
519
- const r = d(e);
545
+ const r = l(e);
520
546
  t.$reset = () => {
521
- this.traceGroupStart(() => ({ initialState: r, groupId: l.reset(t.$id) }), t.$id, "store:reset");
547
+ this.traceGroupStart(() => ({ initialState: r, groupId: d.reset(t.$id) }), t.$id, "store:reset");
522
548
  try {
523
- this.executeResetStoreCallbacks(t), t.$patch(d(r));
549
+ this.executeResetStoreCallbacks(t), t.$patch(l(r));
524
550
  } finally {
525
- this.traceGroupEnd(() => ({ initialState: r, groupId: l.reset(t.$id) }), t.$id);
551
+ this.traceGroupEnd(() => ({ initialState: r, groupId: d.reset(t.$id) }), t.$id);
526
552
  }
527
553
  };
528
554
  }
@@ -541,33 +567,33 @@ class Y extends F {
541
567
  const { store: r, callback: n } = e();
542
568
  if (!r || !n || (this._onMutationSubscriptions.has(r) || this._onMutationSubscriptions.set(r, /* @__PURE__ */ new Set()), this._onMutationSubscriptions.get(r).add(n), this._onMutationSubscriptionsTraces.get(r.$id)?.push(t.name), this._onMutationUnsubscribes.has(r)))
543
569
  return;
544
- const c = r.$subscribe(async (o) => {
545
- const u = this._onMutationSubscriptions.get(r);
546
- if (u?.size) {
547
- this.traceGroupStart(() => ({ mutation: o, groupId: l.onMutation(r.$id) }), r.$id, "store:onMutation");
570
+ const o = r.$subscribe(async (c) => {
571
+ const a = this._onMutationSubscriptions.get(r);
572
+ if (a?.size) {
573
+ this.traceGroupStart(() => ({ mutation: c, groupId: d.onMutation(r.$id) }), r.$id, "store:onMutation");
548
574
  try {
549
- await Promise.all([...u].map(async (h) => {
575
+ await Promise.all([...a].map(async (h) => {
550
576
  try {
551
- await h(o);
577
+ await h(c);
552
578
  } catch (p) {
553
579
  this.traceError("store:onMutation", p, r.$id);
554
580
  }
555
581
  }));
556
582
  } finally {
557
- this.traceGroupEnd(() => ({ mutation: o, groupId: l.onMutation(r.$id) }), r.$id);
583
+ this.traceGroupEnd(() => ({ mutation: c, groupId: d.onMutation(r.$id) }), r.$id);
558
584
  }
559
585
  }
560
586
  });
561
- this._onMutationUnsubscribes.set(r, c);
587
+ this._onMutationUnsubscribes.set(r, o);
562
588
  }
563
589
  subscriptionDelivery(t, e) {
564
590
  Object.entries(e).forEach(([r, n]) => {
565
- const c = this.defineSubscriptionKey(r, t.store), o = this.definePluginExecution(n.subscription);
566
- if (!(this._subscriptionsDelivered.has(c) || this._subscriptionsScheduled.has(c)) && this.shouldInvokePlugin(o)) {
567
- if (this.shouldScheduleAfterHydration(o)) {
568
- const u = this.defineHydrationScheduler(n.subscription);
569
- this._subscriptionsScheduled.add(c), u(() => {
570
- this._disposedStores.has(t.store) || (this._subscriptionsScheduled.delete(c), this.subscriptionDeliverySafely(t, r, n));
591
+ const o = this.defineSubscriptionKey(r, t.store), c = this.definePluginExecution(n.subscription);
592
+ if (!(this._subscriptionsDelivered.has(o) || this._subscriptionsScheduled.has(o)) && this.shouldInvokePlugin(c)) {
593
+ if (this.shouldScheduleAfterHydration(c)) {
594
+ const a = this.defineHydrationScheduler(n.subscription);
595
+ this._subscriptionsScheduled.add(o), a(() => {
596
+ this._disposedStores.has(t.store) || (this._subscriptionsScheduled.delete(o), this.subscriptionDeliverySafely(t, r, n));
571
597
  });
572
598
  return;
573
599
  }
@@ -579,19 +605,19 @@ class Y extends F {
579
605
  try {
580
606
  if (this._subscriptionsDelivered.has(this.defineSubscriptionKey(r, t)))
581
607
  return;
582
- const { subscription: c, subscriptionOptions: o, stores: u } = n;
608
+ const { subscription: o, subscriptionOptions: c, stores: a } = n;
583
609
  this.trace("Subscription:delivery", t.$id, () => ({
584
610
  pluginName: r,
585
- subscription: c,
586
- subscriptionOptions: o
611
+ subscription: o,
612
+ subscriptionOptions: c
587
613
  }));
588
614
  const h = {
589
- storeOptions: { ...e?.storeOptions ?? {}, ...o }
615
+ storeOptions: { ...e?.storeOptions ?? {}, ...c }
590
616
  };
591
- c.invoke(
617
+ o.invoke(
592
618
  { store: t, options: { ...e, ...h } }
593
- ), this._subscriptionsDelivered.add(this.defineSubscriptionKey(r, t)), C(u) || u?.forEach(
594
- (p) => c.invoke({
619
+ ), this._subscriptionsDelivered.add(this.defineSubscriptionKey(r, t)), O(a) || a?.forEach(
620
+ (p) => o.invoke({
595
621
  store: p,
596
622
  options: {
597
623
  ...e,
@@ -600,8 +626,8 @@ class Y extends F {
600
626
  }
601
627
  })
602
628
  );
603
- } catch (c) {
604
- this.traceError("subscription:delivery", c, t.$id);
629
+ } catch (o) {
630
+ this.traceError("subscription:delivery", o, t.$id);
605
631
  }
606
632
  }
607
633
  traceGroupEnd(t, e) {
@@ -620,17 +646,17 @@ class Y extends F {
620
646
  }
621
647
  }
622
648
  export {
623
- Y as P,
624
- F as T,
625
- X as a,
626
- B as b,
627
- Q as c,
628
- U as d,
629
- J as g,
649
+ Z as P,
650
+ I as T,
651
+ Y as a,
652
+ J as b,
653
+ V as c,
654
+ B as d,
655
+ Q as g,
630
656
  D as h,
631
- C as i,
632
- I as p,
633
- V as s,
634
- l as t
657
+ O as i,
658
+ F as p,
659
+ X as s,
660
+ d as t
635
661
  };
636
- //# sourceMappingURL=PluginSubscription-BbN48iuP.js.map
662
+ //# sourceMappingURL=PluginSubscription-Bkqj4uSK.js.map