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

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.
Files changed (47) hide show
  1. package/CHANGELOG.md +29 -12
  2. package/CONTRIBUTING.md +10 -1
  3. package/README.md +11 -9
  4. package/SECURITY.md +2 -2
  5. package/dist/chunks/{PluginSubscription-Bkqj4uSK.js → PluginSubscription-GJDsym1O.js} +253 -247
  6. package/dist/core/PluginSubscriber.d.ts +1 -1
  7. package/dist/core/PluginSubscription.d.ts +13 -12
  8. package/dist/core/Store.d.ts +1 -1
  9. package/dist/helpers/index.d.ts +0 -4
  10. package/dist/helpers.js +56 -651
  11. package/dist/pinia-plugin-subscription.js +4 -5
  12. package/dist/system/TraceEmitter.d.ts +1 -2
  13. package/dist/types/index.d.ts +1 -2
  14. package/dist/types/plugin.d.ts +2 -3
  15. package/dist/types/trace.d.ts +30 -109
  16. package/dist/utils/traceGroups.d.ts +9 -7
  17. package/docs/authoring-plugins.md +13 -7
  18. package/docs/using-plugins.md +28 -19
  19. package/package.json +9 -4
  20. package/dist/chunks/PluginSubscription-Bkqj4uSK.js.map +0 -1
  21. package/dist/factories/console-trace-listener.d.ts +0 -7
  22. package/dist/factories/trace-listener.d.ts +0 -10
  23. package/dist/factories/trace-registry.d.ts +0 -2
  24. package/dist/helpers.js.map +0 -1
  25. package/dist/pinia-plugin-subscription.js.map +0 -1
  26. package/dist/system/Tracer.d.ts +0 -23
  27. package/dist/system/log/console-group.d.ts +0 -8
  28. package/dist/system/log/console.d.ts +0 -18
  29. package/dist/system/log/index.d.ts +0 -2
  30. package/dist/system/log/log-trace.d.ts +0 -8
  31. package/dist/system/log/print-array.d.ts +0 -7
  32. package/dist/system/log/print-error.d.ts +0 -6
  33. package/dist/system/log/print-object.d.ts +0 -1
  34. package/dist/system/log/print-trace-payload.d.ts +0 -1
  35. package/dist/system/log/print-trace.d.ts +0 -9
  36. package/dist/system/log/trace-console.d.ts +0 -9
  37. package/dist/tests/defineAStore.test-d.d.ts +0 -1
  38. package/dist/tests/storeOptionsExtensions.test-d.d.ts +0 -12
  39. package/dist/types/comparison.d.ts +0 -3
  40. package/dist/types/list.d.ts +0 -13
  41. package/dist/types/log.d.ts +0 -8
  42. package/dist/types/resourceId.d.ts +0 -4
  43. package/dist/utils/Performance.d.ts +0 -9
  44. package/dist/utils/environment.d.ts +0 -7
  45. package/dist/utils/object.d.ts +0 -4
  46. package/dist/utils/redact.d.ts +0 -15
  47. package/docs/tracing.md +0 -185
@@ -1,144 +1,144 @@
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) {
1
+ var x = Object.defineProperty;
2
+ var v = (s, i, t) => i in s ? x(s, i, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[i] = t;
3
+ var u = (s, i, t) => v(s, typeof i != "symbol" ? i + "" : i, t);
4
+ import { toRaw as w } from "vue";
5
+ import { defineStore as R } from "pinia";
6
+ function f(s) {
7
7
  if (typeof structuredClone == "function")
8
8
  try {
9
- return structuredClone(i);
9
+ return structuredClone(s);
10
10
  } catch {
11
11
  }
12
- if (i === null || typeof i != "object")
13
- return i;
14
- if (i instanceof Map)
12
+ if (s === null || typeof s != "object")
13
+ return s;
14
+ if (s instanceof Map)
15
15
  return new Map(
16
- Array.from(i.entries(), ([t, e]) => [l(t), l(e)])
16
+ Array.from(s.entries(), ([t, e]) => [f(t), f(e)])
17
17
  );
18
- if (i instanceof Set)
19
- return new Set(Array.from(i.values(), (t) => l(t)));
20
- if (Array.isArray(i))
21
- return i.map((t) => l(t));
22
- if (Object.getPrototypeOf(i) === Object.prototype || Object.getPrototypeOf(i) === null)
18
+ if (s instanceof Set)
19
+ return new Set(Array.from(s.values(), (t) => f(t)));
20
+ if (Array.isArray(s))
21
+ return s.map((t) => f(t));
22
+ if (Object.getPrototypeOf(s) === Object.prototype || Object.getPrototypeOf(s) === null)
23
23
  return Object.fromEntries(
24
- Object.entries(i).map(([t, e]) => [t, l(e)])
24
+ Object.entries(s).map(([t, e]) => [t, f(e)])
25
25
  );
26
- const s = Object.create(Object.getPrototypeOf(i));
27
- for (const [t, e] of Object.entries(i))
28
- s[t] = l(e);
29
- return s;
26
+ const i = Object.create(Object.getPrototypeOf(s));
27
+ for (const [t, e] of Object.entries(s))
28
+ i[t] = f(e);
29
+ return i;
30
30
  }
31
- function G(i, s = "all") {
32
- if (Array.isArray(s)) {
31
+ function D(s, i = "all") {
32
+ if (Array.isArray(i)) {
33
33
  const t = {};
34
- for (const e of s)
35
- e in i && (t[e] = l(m(i[e])));
34
+ for (const e of i)
35
+ e in s && (t[e] = f(w(s[e])));
36
36
  return t;
37
37
  }
38
- if (s !== "all")
39
- throw new Error(`Invalid keys parameter: ${s}`);
40
- return l(m(i));
38
+ if (i !== "all")
39
+ throw new Error(`Invalid keys parameter: ${i}`);
40
+ return f(w(s));
41
41
  }
42
- const A = /* @__PURE__ */ new WeakMap(), b = /* @__PURE__ */ new Map(), E = /* @__PURE__ */ new WeakSet();
43
- function P(i, s) {
44
- if (E.has(i) || typeof i.$dispose != "function")
42
+ const $ = /* @__PURE__ */ new WeakMap(), _ = /* @__PURE__ */ new Map(), T = /* @__PURE__ */ new WeakSet();
43
+ function j(s, i) {
44
+ if (T.has(s) || typeof s.$dispose != "function")
45
45
  return;
46
- const t = i.$dispose;
47
- i.$dispose = (...e) => (A.delete(i), b.delete(s), t.apply(i, e)), E.add(i);
46
+ const t = s.$dispose;
47
+ s.$dispose = (...e) => ($.delete(s), _.delete(i), t.apply(s, e)), T.add(s);
48
48
  }
49
- function B(i, s, t) {
49
+ function Y(s, i, t) {
50
50
  const e = t ? { storeOptions: t } : {};
51
- return typeof s == "function" ? w(
52
- i,
51
+ return typeof i == "function" ? G(
53
52
  s,
54
- e
55
- ) : x(
56
53
  i,
54
+ e
55
+ ) : I(
57
56
  s,
57
+ i,
58
58
  e
59
59
  );
60
60
  }
61
- function J(i, s, t) {
61
+ function Z(s, i, t) {
62
62
  const e = t ? { storeOptions: { ...t, enhancedStore: !0 } } : { storeOptions: { enhancedStore: !0 } };
63
- return w(
64
- i,
63
+ return G(
65
64
  s,
65
+ i,
66
66
  e
67
67
  );
68
68
  }
69
- function w(i, s, t) {
69
+ function G(s, i, t) {
70
70
  let e;
71
- const r = t?.storeOptions?.enhancedStore === !0, n = C(
72
- i,
71
+ const r = t?.storeOptions?.enhancedStore === !0, n = R(
72
+ s,
73
73
  () => (e = {
74
- id: i,
74
+ id: s,
75
75
  extensions: {}
76
- }, r && b.set(i, e), s(e)),
76
+ }, r && _.set(s, e), i(e)),
77
77
  t
78
78
  );
79
79
  return Object.assign(((...o) => {
80
80
  const c = n(...o);
81
- return r && e && (A.set(c, e), b.delete(i), P(c, i)), c;
81
+ return r && e && ($.set(c, e), _.delete(s), j(c, s)), c;
82
82
  }), n);
83
83
  }
84
- function x(i, s, t) {
85
- return t && (s = { ...s, ...t ?? {} }), C(i, s);
84
+ function I(s, i, t) {
85
+ return t && (i = { ...i, ...t ?? {} }), R(s, i);
86
86
  }
87
- const v = /* @__PURE__ */ new Set(["_", "$"]);
88
- function D(i) {
89
- return v.has(i[0]);
87
+ const F = /* @__PURE__ */ new Set(["_", "$"]);
88
+ function K(s) {
89
+ return F.has(s[0]);
90
90
  }
91
- function Q(i) {
92
- const s = i;
93
- return A.get(i) ?? (typeof s?.$id == "string" ? b.get(s.$id) : void 0);
91
+ function tt(s) {
92
+ const i = s;
93
+ return $.get(s) ?? (typeof i?.$id == "string" ? _.get(i.$id) : void 0);
94
94
  }
95
- function V(i) {
96
- const s = i.extensions.enhancedStore ?? i.extensions.extending;
97
- if (!s)
98
- throw new Error(`${i.id}Store - getEnhancedStore - Error: enhanced store is required`);
99
- return s;
95
+ function et(s) {
96
+ const i = s.extensions.enhancedStore ?? s.extensions.extending;
97
+ if (!i)
98
+ throw new Error(`${s.id}Store - getEnhancedStore - Error: enhanced store is required`);
99
+ return i;
100
100
  }
101
- function X(i, s) {
102
- i.extensions.enhancedStore = s, i.extensions.extending = s;
101
+ function rt(s, i) {
102
+ s.extensions.enhancedStore = i, s.extensions.extending = i;
103
103
  }
104
- function f(i, s) {
105
- return _(i, s);
104
+ function S(s, i) {
105
+ return k(s, i);
106
106
  }
107
- function y(i) {
108
- const s = String(i.$id);
109
- return `${s.length}:${s}:`;
107
+ function g(s) {
108
+ const i = String(s.$id);
109
+ return `${i.length}:${i}:`;
110
110
  }
111
- function _(i, s) {
112
- return `${y(s)}${i.length}:${i}`;
111
+ function k(s, i) {
112
+ return `${g(i)}${s.length}:${s}`;
113
113
  }
114
- class j {
114
+ class W {
115
115
  constructor() {
116
116
  u(this, "_stateSnapshots", /* @__PURE__ */ new Map());
117
117
  u(this, "_storeHasRollbackSnapshots", /* @__PURE__ */ new Set());
118
118
  u(this, "_storeRollbackSnapshotsParams", /* @__PURE__ */ new Map());
119
119
  }
120
- addRollbackAction(s) {
121
- typeof s.$rollbackAfterFailure != "function" && (s.$rollbackAfterFailure = async ({ action: t, stateKeys: e }, r = []) => {
122
- const n = s[t];
123
- if (typeof n != "function" || D(t))
120
+ addRollbackAction(i) {
121
+ typeof i.$rollbackAfterFailure != "function" && (i.$rollbackAfterFailure = async ({ action: t, stateKeys: e }, r = []) => {
122
+ const n = i[t];
123
+ if (typeof n != "function" || K(t))
124
124
  return;
125
- const o = !e || e.length === 0 ? "all" : e, c = this.saveStateSnapshot(s, t, o);
125
+ const o = !e || e.length === 0 ? "all" : e, c = this.saveStateSnapshot(i, t, o);
126
126
  try {
127
- await n.apply(s, r);
127
+ await n.apply(i, r);
128
128
  } catch (a) {
129
- throw this.patchStore(c, s), a;
129
+ throw this.patchStore(c, i), a;
130
130
  } finally {
131
131
  this.removeStateSnapshot(c);
132
132
  }
133
133
  });
134
134
  }
135
- createOnActionCallbacks(s, t) {
135
+ createOnActionCallbacks(i, t) {
136
136
  const e = this._storeRollbackSnapshotsParams.get(
137
- f(s, t)
137
+ S(i, t)
138
138
  );
139
139
  if (!e)
140
140
  return;
141
- const r = e.length === 0 || e[0] === "all" ? "all" : e, n = this.saveStateSnapshot(t, s, r);
141
+ const r = e.length === 0 || e[0] === "all" ? "all" : e, n = this.saveStateSnapshot(t, i, r);
142
142
  return {
143
143
  after: () => {
144
144
  this.removeStateSnapshot(n);
@@ -148,48 +148,48 @@ class j {
148
148
  }
149
149
  };
150
150
  }
151
- initFromPluginContext({ options: s, store: t }) {
152
- const e = s?.storeOptions?.rollbackAfterFailure;
151
+ initFromPluginContext({ options: i, store: t }) {
152
+ const e = i?.storeOptions?.rollbackAfterFailure;
153
153
  e && !this._storeHasRollbackSnapshots.has(t.$id) && (Object.keys(e).forEach((r) => {
154
154
  const n = e[r];
155
155
  n && this._storeRollbackSnapshotsParams.set(
156
- f(r, t),
156
+ S(r, t),
157
157
  n
158
158
  );
159
159
  }), this._storeHasRollbackSnapshots.add(t.$id)), this.addRollbackAction(t);
160
160
  }
161
- clearStoreTracking(s) {
162
- const t = y(s);
161
+ clearStoreTracking(i) {
162
+ const t = g(i);
163
163
  for (const e of Array.from(this._storeRollbackSnapshotsParams.keys()))
164
164
  e.startsWith(t) && this._storeRollbackSnapshotsParams.delete(e);
165
- this._storeHasRollbackSnapshots.delete(s.$id);
165
+ this._storeHasRollbackSnapshots.delete(i.$id);
166
166
  for (const e of Array.from(this._stateSnapshots.keys()))
167
167
  e.description?.startsWith(t) && this._stateSnapshots.delete(e);
168
168
  }
169
- patchStore(s, t) {
170
- const e = this._stateSnapshots.get(s);
169
+ patchStore(i, t) {
170
+ const e = this._stateSnapshots.get(i);
171
171
  if (e)
172
172
  try {
173
173
  t.$patch(e);
174
174
  } catch (r) {
175
- console.error(`Failed to patch store with snapshot ${String(s)}`, r);
175
+ console.error(`Failed to patch store with snapshot ${String(i)}`, r);
176
176
  }
177
177
  }
178
- removeStateSnapshot(s) {
179
- s && this._stateSnapshots.delete(s);
178
+ removeStateSnapshot(i) {
179
+ i && this._stateSnapshots.delete(i);
180
180
  }
181
- saveStateSnapshot(s, t, e) {
182
- const r = G(
183
- s.$state,
181
+ saveStateSnapshot(i, t, e) {
182
+ const r = D(
183
+ i.$state,
184
184
  e
185
- ), n = Symbol(f(t, s));
185
+ ), n = Symbol(S(t, i));
186
186
  return this._stateSnapshots.set(n, r), n;
187
187
  }
188
- storeHasRollbackSnapshots(s) {
189
- return this._storeHasRollbackSnapshots.has(s.$id);
188
+ storeHasRollbackSnapshots(i) {
189
+ return this._storeHasRollbackSnapshots.has(i.$id);
190
190
  }
191
191
  }
192
- class I {
192
+ class q {
193
193
  constructor() {
194
194
  u(this, "_tracer");
195
195
  u(this, "_traceOptions", {
@@ -199,50 +199,54 @@ class I {
199
199
  get classNameAddedToTraceNamespace() {
200
200
  return this._traceOptions.addClassNameToLabel === !0;
201
201
  }
202
- set classNameAddedToTraceNamespace(s) {
203
- this._traceOptions.addClassNameToLabel = s;
202
+ set classNameAddedToTraceNamespace(i) {
203
+ this._traceOptions.addClassNameToLabel = i;
204
204
  }
205
205
  get tracer() {
206
206
  return this._tracer;
207
207
  }
208
- trace(s, t, e, r) {
208
+ trace(i, t, e, r) {
209
209
  const n = this.tracer;
210
- n && (s = this.traceLabelFormatter(s), n.debug(s, r ?? s.toLowerCase(), e, t));
210
+ n && (i = this.traceLabelFormatter(i), n.debug(i, r ?? i.toLowerCase(), e, t));
211
211
  }
212
- traceError(s, t, e, r, n) {
212
+ traceError(i, t, e, r, n) {
213
213
  const o = this.tracer;
214
- o ? (s = this.traceLabelFormatter(s), o.error(s, n ?? s.toLowerCase(), t, r, e)) : console.error(t);
214
+ o ? (i = this.traceLabelFormatter(i), o.error(i, n ?? i.toLowerCase(), t, r, e)) : console.error(t);
215
215
  }
216
- traceLabelFormatter(s) {
217
- return this.classNameAddedToTraceNamespace ? `${this._className}:${s}` : s;
216
+ traceLabelFormatter(i) {
217
+ return this.classNameAddedToTraceNamespace ? `${this._className}:${i}` : i;
218
218
  }
219
219
  }
220
- function O(i) {
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");
220
+ function M(s) {
221
+ return s ? Array.isArray(s) ? s.length === 0 : typeof s == "object" ? Object.keys(s).length === 0 : typeof s == "string" ? s.trim() === "" : !1 : !(typeof s == "boolean" || typeof s == "number");
222
222
  }
223
- const F = "pinia-plugin-subscription", T = "PluginSubscription", Y = T.toLowerCase(), d = {
224
- onActionAfter: (i) => `store:onAction:after:${i}`,
225
- onActionError: (i) => `store:onAction:onError:${i}`,
226
- onMutation: (i) => `store:onMutation:${i}`,
227
- reset: (i) => `store:reset:${i}`
228
- }, K = T, W = {
223
+ const L = "pinia-plugin-subscription", N = "PluginSubscription", y = (s, i, t) => `${s}/onAction:${i}#${t}`, H = (s) => `${s}/plugin`, l = {
224
+ onAction: y,
225
+ onActionAfter: (s, i, t) => `${y(s, i, t)}/after`,
226
+ onActionError: (s, i, t) => `${y(s, i, t)}/onError`,
227
+ onMutation: (s, i) => `${s}/onMutation#${i}`,
228
+ plugin: H,
229
+ pluginDeferred: (s, i, t) => `${H(s)}/deferred:${i}#${t}`,
230
+ reset: (s, i) => `${s}/reset#${i}`
231
+ }, z = N, U = {
229
232
  environment: "both",
230
233
  hydration: "immediate"
231
- }, L = 2500;
232
- function N(i) {
234
+ }, B = 2500;
235
+ function J(s) {
233
236
  if (typeof window < "u" && typeof window.requestAnimationFrame == "function") {
234
- window.requestAnimationFrame(() => globalThis.setTimeout(i, 0));
237
+ window.requestAnimationFrame(() => globalThis.setTimeout(s, 0));
235
238
  return;
236
239
  }
237
- globalThis.setTimeout(i, 0);
240
+ globalThis.setTimeout(s, 0);
238
241
  }
239
- class Z extends I {
242
+ class it extends q {
240
243
  constructor(t, e) {
241
244
  super();
242
- u(this, "_className", K);
245
+ u(this, "_className", z);
243
246
  u(this, "_hydrationScheduler");
244
247
  u(this, "_onActionSubscriptions", /* @__PURE__ */ new Map());
245
248
  u(this, "_onActionSubscriptionsTraces", /* @__PURE__ */ new Map());
249
+ u(this, "_actionSeq", 0);
246
250
  u(this, "_onActionStores", /* @__PURE__ */ new Set());
247
251
  u(this, "_onActionAfterSubscriptions", {});
248
252
  u(this, "_onActionOnErrorSubscriptions", {});
@@ -252,28 +256,28 @@ class Z extends I {
252
256
  u(this, "_options");
253
257
  u(this, "_resetStoreCallback", /* @__PURE__ */ new Map());
254
258
  u(this, "_disposedStores", /* @__PURE__ */ new WeakSet());
255
- u(this, "_storeRollbackSnapshotsHandler", new j());
259
+ u(this, "_storeRollbackSnapshotsHandler", new W());
256
260
  u(this, "_subscribers", []);
257
261
  u(this, "_subscribersDelivered", /* @__PURE__ */ new Set());
258
262
  u(this, "_subscribersScheduled", /* @__PURE__ */ new Set());
259
263
  u(this, "_subscriptions", []);
260
264
  u(this, "_subscriptionsDelivered", /* @__PURE__ */ new Set());
261
265
  u(this, "_subscriptionsScheduled", /* @__PURE__ */ new Set());
262
- this._hydrationScheduler = e?.hydrationScheduler ?? N, this._options = e, this._subscribers = t, this.initializeTracer();
266
+ this._hydrationScheduler = e?.hydrationScheduler ?? J, this._options = e, this._subscribers = t, this.initializeTracer();
263
267
  }
264
268
  set subscribers(t) {
265
269
  this._subscribers = t;
266
270
  }
267
271
  get subscriptions() {
268
- if (!O(this._subscriptions))
272
+ if (!M(this._subscriptions))
269
273
  return this._subscriptions;
270
274
  }
271
275
  addOnActionAfterCallback(t, e, r) {
272
- const n = f(t, e);
276
+ const n = S(t, e);
273
277
  this._onActionAfterSubscriptions[n] || (this._onActionAfterSubscriptions[n] = []), this._onActionAfterSubscriptions[n]?.push(r);
274
278
  }
275
279
  addOnActionOnErrorCallback(t, e, r) {
276
- const n = f(t, e);
280
+ const n = S(t, e);
277
281
  this._onActionOnErrorSubscriptions[n] || (this._onActionOnErrorSubscriptions[n] = []), this._onActionOnErrorSubscriptions[n]?.push(r);
278
282
  }
279
283
  addResetStoreCallback(t, e) {
@@ -284,7 +288,7 @@ class Z extends I {
284
288
  }
285
289
  clearStoreTracking(t) {
286
290
  this._onActionSubscriptions.delete(t), this._onActionStores.delete(t), this._onMutationUnsubscribes.get(t)?.(), this._onMutationUnsubscribes.delete(t), this._onMutationSubscriptions.delete(t), this._resetStoreCallback.delete(t), this._onActionSubscriptionsTraces.delete(t.$id), this._onMutationSubscriptionsTraces.delete(t.$id);
287
- const e = y(t);
291
+ const e = g(t);
288
292
  for (const r of Array.from(this._subscribersDelivered))
289
293
  r.startsWith(e) && this._subscribersDelivered.delete(r);
290
294
  for (const r of Array.from(this._subscribersScheduled))
@@ -298,6 +302,19 @@ class Z extends I {
298
302
  for (const r of Object.keys(this._onActionOnErrorSubscriptions))
299
303
  r.startsWith(e) && delete this._onActionOnErrorSubscriptions[r];
300
304
  }
305
+ closeGroupWhenSettled(t, e, r, n) {
306
+ let o = !1;
307
+ const c = () => {
308
+ o || (o = !0, globalThis.clearTimeout(h), e());
309
+ }, a = this._options?.deferredTraceGroupTimeout ?? B, h = globalThis.setTimeout(() => {
310
+ o || (this.traceError(
311
+ "subscriber:deferred:timeout",
312
+ new Error(`Subscriber "${n}" hydration still pending after ${a}ms`),
313
+ r
314
+ ), c());
315
+ }, a);
316
+ t.then(c, c);
317
+ }
301
318
  createOnActionAfterCallbackCollector(t, e) {
302
319
  return (r) => {
303
320
  this.addOnActionAfterCallback(t, e, r);
@@ -323,7 +340,7 @@ class Z extends I {
323
340
  }
324
341
  definePluginExecution(t) {
325
342
  return {
326
- ...W,
343
+ ...U,
327
344
  ...this._options?.execution ?? {},
328
345
  ...t.execution ?? {},
329
346
  ...this._options?.subscriberExecution?.[t.name] ?? {}
@@ -333,10 +350,14 @@ class Z extends I {
333
350
  return t.hydrationScheduler ?? this._hydrationScheduler;
334
351
  }
335
352
  defineSubscriberKey(t, e) {
336
- return _(t.name, e);
353
+ return k(t.name, e);
337
354
  }
338
355
  defineSubscriptionKey(t, e) {
339
- return _(t, e);
356
+ return k(t, e);
357
+ }
358
+ endGroupAfter(t, e) {
359
+ const r = t.filter((n) => !!n);
360
+ r.length ? Promise.all(r).then(e) : e();
340
361
  }
341
362
  executeResetStoreCallbacks(t) {
342
363
  this._resetStoreCallback.get(t)?.forEach((e) => e(t));
@@ -349,89 +370,76 @@ class Z extends I {
349
370
  const h = this._onActionSubscriptions.get(t);
350
371
  if (!h?.size)
351
372
  return;
352
- this.traceGroupStart(() => ({ args: o }), t.$id, `store:onAction:${c}`);
353
- let p = !1;
354
- const k = () => {
355
- p || (p = !0, this.traceGroupEnd({}, t.$id));
373
+ const d = ++this._actionSeq, p = `${t.$id}#${d}`, A = l.onAction(t.$id, c, d);
374
+ this.traceGroupStart(() => ({ actionId: p, args: o, groupId: A }), t.$id, `store:onAction:${c}`);
375
+ let O = !1;
376
+ const E = () => {
377
+ O || (O = !0, this.traceGroupEnd({ groupId: A }, t.$id));
356
378
  };
357
379
  try {
358
- const S = f(c, t);
380
+ const b = S(c, t);
359
381
  this._storeRollbackSnapshotsHandler.storeHasRollbackSnapshots(t) && this.createRollbackSnapshot(c, t);
360
- const $ = [];
361
- h.forEach((M) => {
362
- const g = this.runCallbackSafely(
363
- () => M({
382
+ const m = [];
383
+ h.forEach((P) => {
384
+ const C = this.runCallbackSafely(
385
+ () => P({
364
386
  after: this.createOnActionAfterCallbackCollector(c, t),
365
387
  args: o,
366
388
  name: c,
367
389
  onError: this.createOnActionOnErrorCallbackCollector(c, t)
368
390
  }),
369
391
  "store:onAction:callback:error",
370
- t.$id
392
+ t.$id,
393
+ () => ({ actionId: p, groupId: A })
371
394
  );
372
- g && $.push(g);
373
- }), this.endGroupAfter($, k), this.executeStoreOnActionAfterCallbacks(n, S, t, c), this.executeStoreOnActionOnErrorCallbacks(a, S, t, c), this.clearOnActionCallbacksSubscriptions(S);
374
- } catch (S) {
375
- throw k(), S;
395
+ C && m.push(C);
396
+ }), this.endGroupAfter(m, E), this.executeStoreOnActionAfterCallbacks(n, b, t, c, p, d), this.executeStoreOnActionOnErrorCallbacks(a, b, t, c, p, d), this.clearOnActionCallbacksSubscriptions(b);
397
+ } catch (b) {
398
+ throw E(), b;
376
399
  }
377
400
  }));
378
401
  }
379
- runCallbackSafely(t, e, r, n) {
380
- try {
381
- const o = t();
382
- if (o && typeof o.then == "function")
383
- return Promise.resolve(o).then(
384
- () => {
385
- },
386
- (c) => this.traceError(e, c, r, n)
387
- );
388
- } catch (o) {
389
- this.traceError(e, o, r, n);
390
- }
391
- }
392
- endGroupAfter(t, e) {
393
- const r = t.filter((n) => !!n);
394
- r.length ? Promise.all(r).then(e) : e();
395
- }
396
- executeStoreOnActionAfterCallbacks(t, e, r, n) {
397
- const o = this._onActionAfterSubscriptions[e];
398
- o?.length && t((c) => {
402
+ executeStoreOnActionAfterCallbacks(t, e, r, n, o, c) {
403
+ const a = this._onActionAfterSubscriptions[e];
404
+ a?.length && t((h) => {
399
405
  this.traceGroupStart(
400
406
  () => ({
401
- groupId: d.onActionAfter(r.$id),
402
- result: c
407
+ actionId: o,
408
+ groupId: l.onActionAfter(r.$id, n, c),
409
+ result: h
403
410
  }),
404
411
  r.$id,
405
412
  `store:onAction:after:${n}`
406
413
  );
407
- const a = o.map((h) => this.runCallbackSafely(
408
- () => h(c),
414
+ const d = a.map((p) => this.runCallbackSafely(
415
+ () => p(h),
409
416
  "storeOnActionAfterCallbacks",
410
417
  r.$id,
411
- () => ({ "action name": n })
418
+ () => ({ actionId: o, "action name": n, groupId: l.onActionAfter(r.$id, n, c) })
412
419
  ));
413
- this.endGroupAfter(a, () => this.traceGroupEnd(() => ({ groupId: d.onActionAfter(r.$id) }), r.$id));
420
+ this.endGroupAfter(d, () => this.traceGroupEnd(() => ({ groupId: l.onActionAfter(r.$id, n, c) }), r.$id));
414
421
  });
415
422
  }
416
- executeStoreOnActionOnErrorCallbacks(t, e, r, n) {
417
- const o = this._onActionOnErrorSubscriptions[e];
418
- o?.length && t((c) => {
423
+ executeStoreOnActionOnErrorCallbacks(t, e, r, n, o, c) {
424
+ const a = this._onActionOnErrorSubscriptions[e];
425
+ a?.length && t((h) => {
419
426
  this.traceGroupStart(
420
427
  () => ({
428
+ actionId: o,
421
429
  "action name": n,
422
- error: c,
423
- groupId: d.onActionError(r.$id)
430
+ error: h,
431
+ groupId: l.onActionError(r.$id, n, c)
424
432
  }),
425
433
  r.$id,
426
434
  `store:onAction:onError:${n}`
427
435
  );
428
- const a = o.map((h) => this.runCallbackSafely(
429
- () => h(c),
436
+ const d = a.map((p) => this.runCallbackSafely(
437
+ () => p(h),
430
438
  "store:onAction:onError:error",
431
439
  r.$id,
432
- () => ({ groupId: d.onActionError(r.$id) })
440
+ () => ({ actionId: o, groupId: l.onActionError(r.$id, n, c) })
433
441
  ));
434
- this.endGroupAfter(a, () => this.traceGroupEnd(() => ({ groupId: d.onActionError(r.$id) }), r.$id));
442
+ this.endGroupAfter(d, () => this.traceGroupEnd(() => ({ groupId: l.onActionError(r.$id, n, c) }), r.$id));
435
443
  });
436
444
  }
437
445
  executeSubscriber(t, e) {
@@ -468,7 +476,7 @@ class Z extends I {
468
476
  }
469
477
  }
470
478
  initializeTracer() {
471
- this._options?.tracerHandler && (this._tracer = this._options.tracerHandler.createTracer(F));
479
+ this._options?.tracerHandler && (this._tracer = this._options.tracerHandler.createTracer(L));
472
480
  }
473
481
  plugin({ store: t, options: e }) {
474
482
  if (!this._subscribers.length)
@@ -476,12 +484,9 @@ class Z extends I {
476
484
  const r = {
477
485
  $onAction: [],
478
486
  $subscribe: []
479
- };
487
+ }, n = l.plugin(t.$id);
480
488
  this.traceGroupStart(() => ({
481
- environment: {
482
- current: this.defineCurrentEnvironment(),
483
- ...this._options?.execution ?? {}
484
- },
489
+ groupId: n,
485
490
  subscribers: this._subscribers,
486
491
  "hooks subscriptions": r,
487
492
  store: t,
@@ -489,21 +494,21 @@ class Z extends I {
489
494
  }), t.$id), this._onActionSubscriptionsTraces.set(t.$id, r.$onAction), this._onMutationSubscriptionsTraces.set(t.$id, r.$subscribe);
490
495
  try {
491
496
  this._subscribers.forEach(
492
- (n) => {
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);
497
+ (o) => {
498
+ const c = this.defineSubscriberKey(o, t), a = this.definePluginExecution(o);
499
+ if (!(this._subscribersDelivered.has(c) || this._subscribersScheduled.has(c)) && this.shouldInvokePlugin(a)) {
500
+ if (this.shouldScheduleAfterHydration(a)) {
501
+ this.queueSubscriberExecution({ store: t, options: e }, o, c);
497
502
  return;
498
503
  }
499
- this.executeSubscriber({ store: t, options: e }, n);
504
+ this.executeSubscriber({ store: t, options: e }, o);
500
505
  }
501
506
  }
502
507
  ), this.rewriteResetStore({ store: t }, t.$state), this._storeRollbackSnapshotsHandler.initFromPluginContext({ store: t, options: e }), this.executeStoreOnActionSubscription(t), this.registerStoreCleanup(t);
503
- } catch (n) {
504
- this.traceError("plugin:invoke", n, t.$id);
508
+ } catch (o) {
509
+ this.traceError("plugin:invoke", o, t.$id);
505
510
  }
506
- this.traceGroupEnd(() => ({}), t.$id);
511
+ this.traceGroupEnd(() => ({ groupId: n }), t.$id);
507
512
  }
508
513
  queueSubscriberExecution(t, e, r) {
509
514
  const n = this.defineHydrationScheduler(e);
@@ -511,30 +516,17 @@ class Z extends I {
511
516
  if (this._disposedStores.has(t.store))
512
517
  return;
513
518
  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;
519
+ const o = t.store.$id, c = l.pluginDeferred(o, e.name, ++this._actionSeq);
520
+ this.traceGroupStart(() => ({ groupId: c, subscriber: e.name }), o, "subscriber:deferred");
521
+ const a = () => this.traceGroupEnd(() => ({ groupId: c }), o);
522
+ let h;
518
523
  try {
519
- a = this.executeSubscriberSafely(t, e);
524
+ h = this.executeSubscriberSafely(t, e);
520
525
  } finally {
521
- a ? this.closeGroupWhenSettled(a, c, o, e.name) : c();
526
+ h ? this.closeGroupWhenSettled(h, a, o, e.name) : a();
522
527
  }
523
528
  });
524
529
  }
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
- }
538
530
  registerStoreCleanup(t) {
539
531
  if (typeof t.$dispose != "function")
540
532
  return;
@@ -542,16 +534,30 @@ class Z extends I {
542
534
  r.__piniaPluginSubscriptionDisposed || (r.__piniaPluginSubscriptionDisposed = !0, t.$dispose = () => (this._disposedStores.add(t), this.clearStoreTracking(t), this._storeRollbackSnapshotsHandler.clearStoreTracking(t), e()));
543
535
  }
544
536
  rewriteResetStore({ store: t }, e) {
545
- const r = l(e);
537
+ const r = f(e);
546
538
  t.$reset = () => {
547
- this.traceGroupStart(() => ({ initialState: r, groupId: d.reset(t.$id) }), t.$id, "store:reset");
539
+ const n = l.reset(t.$id, ++this._actionSeq);
540
+ this.traceGroupStart(() => ({ initialState: r, groupId: n }), t.$id, "store:reset");
548
541
  try {
549
- this.executeResetStoreCallbacks(t), t.$patch(l(r));
542
+ this.executeResetStoreCallbacks(t), t.$patch(f(r));
550
543
  } finally {
551
- this.traceGroupEnd(() => ({ initialState: r, groupId: d.reset(t.$id) }), t.$id);
544
+ this.traceGroupEnd(() => ({ groupId: n }), t.$id);
552
545
  }
553
546
  };
554
547
  }
548
+ runCallbackSafely(t, e, r, n) {
549
+ try {
550
+ const o = t();
551
+ if (o && typeof o.then == "function")
552
+ return Promise.resolve(o).then(
553
+ () => {
554
+ },
555
+ (c) => this.traceError(e, c, r, n)
556
+ );
557
+ } catch (o) {
558
+ this.traceError(e, o, r, n);
559
+ }
560
+ }
555
561
  shouldInvokePlugin(t) {
556
562
  const e = this.defineCurrentEnvironment();
557
563
  return t.environment === "both" || t.environment === e;
@@ -569,19 +575,20 @@ class Z extends I {
569
575
  return;
570
576
  const o = r.$subscribe(async (c) => {
571
577
  const a = this._onMutationSubscriptions.get(r);
572
- if (a?.size) {
573
- this.traceGroupStart(() => ({ mutation: c, groupId: d.onMutation(r.$id) }), r.$id, "store:onMutation");
574
- try {
575
- await Promise.all([...a].map(async (h) => {
576
- try {
577
- await h(c);
578
- } catch (p) {
579
- this.traceError("store:onMutation", p, r.$id);
580
- }
581
- }));
582
- } finally {
583
- this.traceGroupEnd(() => ({ mutation: c, groupId: d.onMutation(r.$id) }), r.$id);
584
- }
578
+ if (!a?.size)
579
+ return;
580
+ const h = l.onMutation(r.$id, ++this._actionSeq);
581
+ this.traceGroupStart(() => ({ mutation: c, groupId: h }), r.$id, "store:onMutation");
582
+ try {
583
+ await Promise.all([...a].map(async (d) => {
584
+ try {
585
+ await d(c);
586
+ } catch (p) {
587
+ this.traceError("store:onMutation", p, r.$id, () => ({ groupId: h }));
588
+ }
589
+ }));
590
+ } finally {
591
+ this.traceGroupEnd(() => ({ groupId: h }), r.$id);
585
592
  }
586
593
  });
587
594
  this._onMutationUnsubscribes.set(r, o);
@@ -607,6 +614,7 @@ class Z extends I {
607
614
  return;
608
615
  const { subscription: o, subscriptionOptions: c, stores: a } = n;
609
616
  this.trace("Subscription:delivery", t.$id, () => ({
617
+ groupId: l.plugin(t.$id),
610
618
  pluginName: r,
611
619
  subscription: o,
612
620
  subscriptionOptions: c
@@ -616,18 +624,18 @@ class Z extends I {
616
624
  };
617
625
  o.invoke(
618
626
  { store: t, options: { ...e, ...h } }
619
- ), this._subscriptionsDelivered.add(this.defineSubscriptionKey(r, t)), O(a) || a?.forEach(
620
- (p) => o.invoke({
621
- store: p,
627
+ ), this._subscriptionsDelivered.add(this.defineSubscriptionKey(r, t)), M(a) || a?.forEach(
628
+ (d) => o.invoke({
629
+ store: d,
622
630
  options: {
623
631
  ...e,
624
632
  ...h,
625
- ...p?.storeOptions ?? {}
633
+ ...d?.storeOptions ?? {}
626
634
  }
627
635
  })
628
636
  );
629
637
  } catch (o) {
630
- this.traceError("subscription:delivery", o, t.$id);
638
+ this.traceError("subscription:delivery", o, t.$id, () => ({ groupId: l.plugin(t.$id) }));
631
639
  }
632
640
  }
633
641
  traceGroupEnd(t, e) {
@@ -646,17 +654,15 @@ class Z extends I {
646
654
  }
647
655
  }
648
656
  export {
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,
656
- D as h,
657
- O as i,
658
- F as p,
659
- X as s,
660
- d as t
657
+ it as P,
658
+ q as T,
659
+ Z as a,
660
+ et as b,
661
+ Y as d,
662
+ tt as g,
663
+ K as h,
664
+ M as i,
665
+ L as p,
666
+ rt as s,
667
+ l as t
661
668
  };
662
- //# sourceMappingURL=PluginSubscription-Bkqj4uSK.js.map