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

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 (53) hide show
  1. package/CHANGELOG.md +14 -2
  2. package/README.md +15 -4
  3. package/dist/chunks/trace-registry-Cm_2un0x.js +1009 -0
  4. package/dist/chunks/trace-registry-Cm_2un0x.js.map +1 -0
  5. package/dist/chunks/traceGroups-DfxYkUpm.js +105 -0
  6. package/dist/chunks/traceGroups-DfxYkUpm.js.map +1 -0
  7. package/dist/core/PluginSubscription.d.ts +13 -12
  8. package/dist/devtools/components.d.ts +40 -0
  9. package/dist/devtools/index.d.ts +9 -0
  10. package/dist/devtools/model.d.ts +17 -0
  11. package/dist/devtools/styles.d.ts +1 -0
  12. package/dist/devtools.js +377 -0
  13. package/dist/devtools.js.map +1 -0
  14. package/dist/factories/trace-listener.d.ts +6 -7
  15. package/dist/factories/trace-registry.d.ts +1 -1
  16. package/dist/helpers/index.d.ts +2 -2
  17. package/dist/helpers.js +50 -638
  18. package/dist/helpers.js.map +1 -1
  19. package/dist/pinia-plugin-subscription.js +44 -18
  20. package/dist/pinia-plugin-subscription.js.map +1 -1
  21. package/dist/system/TraceJournal.d.ts +6 -0
  22. package/dist/system/Tracer.d.ts +6 -2
  23. package/dist/types/devtools.d.ts +60 -0
  24. package/dist/types/index.d.ts +2 -2
  25. package/dist/types/plugin.d.ts +6 -0
  26. package/dist/types/trace.d.ts +79 -21
  27. package/dist/utils/constants.d.ts +2 -1
  28. package/dist/utils/toSerializable.d.ts +10 -0
  29. package/dist/utils/traceContext.d.ts +7 -0
  30. package/dist/utils/traceGroups.d.ts +11 -7
  31. package/docs/authoring-plugins.md +2 -2
  32. package/docs/tracing.md +119 -28
  33. package/docs/using-plugins.md +17 -12
  34. package/package.json +9 -1
  35. package/dist/chunks/PluginSubscription-Bkqj4uSK.js +0 -662
  36. package/dist/chunks/PluginSubscription-Bkqj4uSK.js.map +0 -1
  37. package/dist/factories/console-trace-listener.d.ts +0 -7
  38. package/dist/system/log/console-group.d.ts +0 -8
  39. package/dist/system/log/console.d.ts +0 -18
  40. package/dist/system/log/index.d.ts +0 -2
  41. package/dist/system/log/log-trace.d.ts +0 -8
  42. package/dist/system/log/print-array.d.ts +0 -7
  43. package/dist/system/log/print-error.d.ts +0 -6
  44. package/dist/system/log/print-object.d.ts +0 -1
  45. package/dist/system/log/print-trace-payload.d.ts +0 -1
  46. package/dist/system/log/print-trace.d.ts +0 -9
  47. package/dist/system/log/trace-console.d.ts +0 -9
  48. package/dist/types/comparison.d.ts +0 -3
  49. package/dist/types/list.d.ts +0 -13
  50. package/dist/types/log.d.ts +0 -8
  51. package/dist/types/resourceId.d.ts +0 -4
  52. package/dist/utils/Performance.d.ts +0 -9
  53. package/dist/utils/object.d.ts +0 -4
@@ -0,0 +1,1009 @@
1
+ var D = Object.defineProperty;
2
+ var I = (s, n, t) => n in s ? D(s, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[n] = t;
3
+ var l = (s, n, t) => I(s, typeof n != "symbol" ? n + "" : n, t);
4
+ import { toRaw as T } from "vue";
5
+ import { defineStore as G } from "pinia";
6
+ import { a as y, t as M, i as q } from "./traceGroups-DfxYkUpm.js";
7
+ function A(s) {
8
+ if (typeof structuredClone == "function")
9
+ try {
10
+ return structuredClone(s);
11
+ } catch {
12
+ }
13
+ if (s === null || typeof s != "object")
14
+ return s;
15
+ if (s instanceof Map)
16
+ return new Map(
17
+ Array.from(s.entries(), ([t, e]) => [A(t), A(e)])
18
+ );
19
+ if (s instanceof Set)
20
+ return new Set(Array.from(s.values(), (t) => A(t)));
21
+ if (Array.isArray(s))
22
+ return s.map((t) => A(t));
23
+ if (Object.getPrototypeOf(s) === Object.prototype || Object.getPrototypeOf(s) === null)
24
+ return Object.fromEntries(
25
+ Object.entries(s).map(([t, e]) => [t, A(e)])
26
+ );
27
+ const n = Object.create(Object.getPrototypeOf(s));
28
+ for (const [t, e] of Object.entries(s))
29
+ n[t] = A(e);
30
+ return n;
31
+ }
32
+ function W(s, n = "all") {
33
+ if (Array.isArray(n)) {
34
+ const t = {};
35
+ for (const e of n)
36
+ e in s && (t[e] = A(T(s[e])));
37
+ return t;
38
+ }
39
+ if (n !== "all")
40
+ throw new Error(`Invalid keys parameter: ${n}`);
41
+ return A(T(s));
42
+ }
43
+ const C = /* @__PURE__ */ new WeakMap(), $ = /* @__PURE__ */ new Map(), R = /* @__PURE__ */ new WeakSet();
44
+ function L(s, n) {
45
+ if (R.has(s) || typeof s.$dispose != "function")
46
+ return;
47
+ const t = s.$dispose;
48
+ s.$dispose = (...e) => (C.delete(s), $.delete(n), t.apply(s, e)), R.add(s);
49
+ }
50
+ function mt(s, n, t) {
51
+ const e = t ? { storeOptions: t } : {};
52
+ return typeof n == "function" ? P(
53
+ s,
54
+ n,
55
+ e
56
+ ) : F(
57
+ s,
58
+ n,
59
+ e
60
+ );
61
+ }
62
+ function Et(s, n, t) {
63
+ const e = t ? { storeOptions: { ...t, enhancedStore: !0 } } : { storeOptions: { enhancedStore: !0 } };
64
+ return P(
65
+ s,
66
+ n,
67
+ e
68
+ );
69
+ }
70
+ function P(s, n, t) {
71
+ let e;
72
+ const r = t?.storeOptions?.enhancedStore === !0, i = G(
73
+ s,
74
+ () => (e = {
75
+ id: s,
76
+ extensions: {}
77
+ }, r && $.set(s, e), n(e)),
78
+ t
79
+ );
80
+ return Object.assign(((...o) => {
81
+ const c = i(...o);
82
+ return r && e && (C.set(c, e), $.delete(s), L(c, s)), c;
83
+ }), i);
84
+ }
85
+ function F(s, n, t) {
86
+ return t && (n = { ...n, ...t ?? {} }), G(s, n);
87
+ }
88
+ const K = /* @__PURE__ */ new Set(["_", "$"]);
89
+ function N(s) {
90
+ return K.has(s[0]);
91
+ }
92
+ function $t(s) {
93
+ const n = s;
94
+ return C.get(s) ?? (typeof n?.$id == "string" ? $.get(n.$id) : void 0);
95
+ }
96
+ function Ot(s) {
97
+ const n = s.extensions.enhancedStore ?? s.extensions.extending;
98
+ if (!n)
99
+ throw new Error(`${s.id}Store - getEnhancedStore - Error: enhanced store is required`);
100
+ return n;
101
+ }
102
+ function Ct(s, n) {
103
+ s.extensions.enhancedStore = n, s.extensions.extending = n;
104
+ }
105
+ function m(s, n) {
106
+ return O(s, n);
107
+ }
108
+ function w(s) {
109
+ const n = String(s.$id);
110
+ return `${n.length}:${n}:`;
111
+ }
112
+ function O(s, n) {
113
+ return `${w(n)}${s.length}:${s}`;
114
+ }
115
+ class U {
116
+ constructor() {
117
+ l(this, "_stateSnapshots", /* @__PURE__ */ new Map());
118
+ l(this, "_storeHasRollbackSnapshots", /* @__PURE__ */ new Set());
119
+ l(this, "_storeRollbackSnapshotsParams", /* @__PURE__ */ new Map());
120
+ }
121
+ addRollbackAction(n) {
122
+ typeof n.$rollbackAfterFailure != "function" && (n.$rollbackAfterFailure = async ({ action: t, stateKeys: e }, r = []) => {
123
+ const i = n[t];
124
+ if (typeof i != "function" || N(t))
125
+ return;
126
+ const o = !e || e.length === 0 ? "all" : e, c = this.saveStateSnapshot(n, t, o);
127
+ try {
128
+ await i.apply(n, r);
129
+ } catch (u) {
130
+ throw this.patchStore(c, n), u;
131
+ } finally {
132
+ this.removeStateSnapshot(c);
133
+ }
134
+ });
135
+ }
136
+ createOnActionCallbacks(n, t) {
137
+ const e = this._storeRollbackSnapshotsParams.get(
138
+ m(n, t)
139
+ );
140
+ if (!e)
141
+ return;
142
+ const r = e.length === 0 || e[0] === "all" ? "all" : e, i = this.saveStateSnapshot(t, n, r);
143
+ return {
144
+ after: () => {
145
+ this.removeStateSnapshot(i);
146
+ },
147
+ onError: () => {
148
+ this.patchStore(i, t), this.removeStateSnapshot(i);
149
+ }
150
+ };
151
+ }
152
+ initFromPluginContext({ options: n, store: t }) {
153
+ const e = n?.storeOptions?.rollbackAfterFailure;
154
+ e && !this._storeHasRollbackSnapshots.has(t.$id) && (Object.keys(e).forEach((r) => {
155
+ const i = e[r];
156
+ i && this._storeRollbackSnapshotsParams.set(
157
+ m(r, t),
158
+ i
159
+ );
160
+ }), this._storeHasRollbackSnapshots.add(t.$id)), this.addRollbackAction(t);
161
+ }
162
+ clearStoreTracking(n) {
163
+ const t = w(n);
164
+ for (const e of Array.from(this._storeRollbackSnapshotsParams.keys()))
165
+ e.startsWith(t) && this._storeRollbackSnapshotsParams.delete(e);
166
+ this._storeHasRollbackSnapshots.delete(n.$id);
167
+ for (const e of Array.from(this._stateSnapshots.keys()))
168
+ e.description?.startsWith(t) && this._stateSnapshots.delete(e);
169
+ }
170
+ patchStore(n, t) {
171
+ const e = this._stateSnapshots.get(n);
172
+ if (e)
173
+ try {
174
+ t.$patch(e);
175
+ } catch (r) {
176
+ console.error(`Failed to patch store with snapshot ${String(n)}`, r);
177
+ }
178
+ }
179
+ removeStateSnapshot(n) {
180
+ n && this._stateSnapshots.delete(n);
181
+ }
182
+ saveStateSnapshot(n, t, e) {
183
+ const r = W(
184
+ n.$state,
185
+ e
186
+ ), i = Symbol(m(t, n));
187
+ return this._stateSnapshots.set(i, r), i;
188
+ }
189
+ storeHasRollbackSnapshots(n) {
190
+ return this._storeHasRollbackSnapshots.has(n.$id);
191
+ }
192
+ }
193
+ class z {
194
+ constructor() {
195
+ l(this, "_tracer");
196
+ l(this, "_traceOptions", {
197
+ addClassNameToLabel: !0
198
+ });
199
+ }
200
+ get classNameAddedToTraceNamespace() {
201
+ return this._traceOptions.addClassNameToLabel === !0;
202
+ }
203
+ set classNameAddedToTraceNamespace(n) {
204
+ this._traceOptions.addClassNameToLabel = n;
205
+ }
206
+ get tracer() {
207
+ return this._tracer;
208
+ }
209
+ trace(n, t, e, r) {
210
+ const i = this.tracer;
211
+ i && (n = this.traceLabelFormatter(n), i.debug(n, r ?? n.toLowerCase(), e, t));
212
+ }
213
+ traceError(n, t, e, r, i) {
214
+ const o = this.tracer;
215
+ o ? (n = this.traceLabelFormatter(n), o.error(n, i ?? n.toLowerCase(), t, r, e)) : console.error(t);
216
+ }
217
+ traceLabelFormatter(n) {
218
+ return this.classNameAddedToTraceNamespace ? `${this._className}:${n}` : n;
219
+ }
220
+ }
221
+ function v(s) {
222
+ 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");
223
+ }
224
+ const H = "pinia-plugin-subscription", j = "PluginSubscription", V = j.toLowerCase(), B = "__global__", J = j, X = {
225
+ environment: "both",
226
+ hydration: "immediate"
227
+ }, Q = 2500;
228
+ function Y(s) {
229
+ if (typeof window < "u" && typeof window.requestAnimationFrame == "function") {
230
+ window.requestAnimationFrame(() => globalThis.setTimeout(s, 0));
231
+ return;
232
+ }
233
+ globalThis.setTimeout(s, 0);
234
+ }
235
+ class wt extends z {
236
+ constructor(t, e) {
237
+ super();
238
+ l(this, "_className", J);
239
+ l(this, "_hydrationScheduler");
240
+ l(this, "_onActionSubscriptions", /* @__PURE__ */ new Map());
241
+ l(this, "_onActionSubscriptionsTraces", /* @__PURE__ */ new Map());
242
+ l(this, "_actionSeq", 0);
243
+ l(this, "_onActionStores", /* @__PURE__ */ new Set());
244
+ l(this, "_onActionAfterSubscriptions", {});
245
+ l(this, "_onActionOnErrorSubscriptions", {});
246
+ l(this, "_onMutationSubscriptions", /* @__PURE__ */ new Map());
247
+ l(this, "_onMutationSubscriptionsTraces", /* @__PURE__ */ new Map());
248
+ l(this, "_onMutationUnsubscribes", /* @__PURE__ */ new Map());
249
+ l(this, "_options");
250
+ l(this, "_resetStoreCallback", /* @__PURE__ */ new Map());
251
+ l(this, "_disposedStores", /* @__PURE__ */ new WeakSet());
252
+ l(this, "_storeRollbackSnapshotsHandler", new U());
253
+ l(this, "_subscribers", []);
254
+ l(this, "_subscribersDelivered", /* @__PURE__ */ new Set());
255
+ l(this, "_subscribersScheduled", /* @__PURE__ */ new Set());
256
+ l(this, "_subscriptions", []);
257
+ l(this, "_subscriptionsDelivered", /* @__PURE__ */ new Set());
258
+ l(this, "_subscriptionsScheduled", /* @__PURE__ */ new Set());
259
+ this._hydrationScheduler = e?.hydrationScheduler ?? Y, this._options = e, this._subscribers = t, this.initializeTracer();
260
+ }
261
+ set subscribers(t) {
262
+ this._subscribers = t;
263
+ }
264
+ get subscriptions() {
265
+ if (!v(this._subscriptions))
266
+ return this._subscriptions;
267
+ }
268
+ addOnActionAfterCallback(t, e, r) {
269
+ const i = m(t, e);
270
+ this._onActionAfterSubscriptions[i] || (this._onActionAfterSubscriptions[i] = []), this._onActionAfterSubscriptions[i]?.push(r);
271
+ }
272
+ addOnActionOnErrorCallback(t, e, r) {
273
+ const i = m(t, e);
274
+ this._onActionOnErrorSubscriptions[i] || (this._onActionOnErrorSubscriptions[i] = []), this._onActionOnErrorSubscriptions[i]?.push(r);
275
+ }
276
+ addResetStoreCallback(t, e) {
277
+ this._resetStoreCallback.has(t) || this._resetStoreCallback.set(t, /* @__PURE__ */ new Set()), this._resetStoreCallback.get(t).add(e);
278
+ }
279
+ clearOnActionCallbacksSubscriptions(t) {
280
+ delete this._onActionAfterSubscriptions[t], delete this._onActionOnErrorSubscriptions[t];
281
+ }
282
+ clearStoreTracking(t) {
283
+ 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);
284
+ const e = w(t);
285
+ for (const r of Array.from(this._subscribersDelivered))
286
+ r.startsWith(e) && this._subscribersDelivered.delete(r);
287
+ for (const r of Array.from(this._subscribersScheduled))
288
+ r.startsWith(e) && this._subscribersScheduled.delete(r);
289
+ for (const r of Array.from(this._subscriptionsDelivered))
290
+ r.startsWith(e) && this._subscriptionsDelivered.delete(r);
291
+ for (const r of Array.from(this._subscriptionsScheduled))
292
+ r.startsWith(e) && this._subscriptionsScheduled.delete(r);
293
+ for (const r of Object.keys(this._onActionAfterSubscriptions))
294
+ r.startsWith(e) && delete this._onActionAfterSubscriptions[r];
295
+ for (const r of Object.keys(this._onActionOnErrorSubscriptions))
296
+ r.startsWith(e) && delete this._onActionOnErrorSubscriptions[r];
297
+ }
298
+ closeGroupWhenSettled(t, e, r, i) {
299
+ let o = !1;
300
+ const c = () => {
301
+ o || (o = !0, globalThis.clearTimeout(a), e());
302
+ }, u = this._options?.deferredTraceGroupTimeout ?? Q, a = globalThis.setTimeout(() => {
303
+ o || (this.traceError(
304
+ "subscriber:deferred:timeout",
305
+ new Error(`Subscriber "${i}" hydration still pending after ${u}ms`),
306
+ r
307
+ ), c());
308
+ }, u);
309
+ t.then(c, c);
310
+ }
311
+ createOnActionAfterCallbackCollector(t, e) {
312
+ return (r) => {
313
+ this.addOnActionAfterCallback(t, e, r);
314
+ };
315
+ }
316
+ createOnActionOnErrorCallbackCollector(t, e) {
317
+ return (r) => {
318
+ this.addOnActionOnErrorCallback(t, e, r);
319
+ };
320
+ }
321
+ createRollbackSnapshot(t, e) {
322
+ const {
323
+ after: r,
324
+ onError: i
325
+ } = this._storeRollbackSnapshotsHandler.createOnActionCallbacks(
326
+ t,
327
+ e
328
+ ) ?? {};
329
+ !r || !i || (this.addOnActionAfterCallback(t, e, r), this.addOnActionOnErrorCallback(t, e, i), this.trace("store:onAction:rollbackSnapshot:created", e.$id));
330
+ }
331
+ defineCurrentEnvironment() {
332
+ return this._options?.runtimeEnvironment ?? (typeof window > "u" ? "server" : "client");
333
+ }
334
+ definePluginExecution(t) {
335
+ return {
336
+ ...X,
337
+ ...this._options?.execution ?? {},
338
+ ...t.execution ?? {},
339
+ ...this._options?.subscriberExecution?.[t.name] ?? {}
340
+ };
341
+ }
342
+ defineHydrationScheduler(t) {
343
+ return t.hydrationScheduler ?? this._hydrationScheduler;
344
+ }
345
+ defineSubscriberKey(t, e) {
346
+ return O(t.name, e);
347
+ }
348
+ defineSubscriptionKey(t, e) {
349
+ return O(t, e);
350
+ }
351
+ endGroupAfter(t, e) {
352
+ const r = t.filter((i) => !!i);
353
+ r.length ? Promise.all(r).then(e) : e();
354
+ }
355
+ executeResetStoreCallbacks(t) {
356
+ this._resetStoreCallback.get(t)?.forEach((e) => e(t));
357
+ }
358
+ executeStoreOnActionSubscription(t) {
359
+ if (this._onActionStores.has(t) || typeof t.$onAction != "function")
360
+ return;
361
+ const e = this._onActionSubscriptions.get(t), r = this._storeRollbackSnapshotsHandler.storeHasRollbackSnapshots(t);
362
+ !e?.size && !r || (this._onActionStores.add(t), t.$onAction(({ after: i, args: o, name: c, onError: u }) => {
363
+ const a = this._onActionSubscriptions.get(t);
364
+ if (!a?.size)
365
+ return;
366
+ const h = ++this._actionSeq, d = `${t.$id}#${h}`, f = y.onAction(t.$id, c, h);
367
+ this.traceGroupStart(() => ({ actionId: d, args: o, groupId: f }), t.$id, `store:onAction:${c}`);
368
+ let b = !1;
369
+ const k = () => {
370
+ b || (b = !0, this.traceGroupEnd({ groupId: f }, t.$id));
371
+ };
372
+ try {
373
+ const p = m(c, t);
374
+ this._storeRollbackSnapshotsHandler.storeHasRollbackSnapshots(t) && this.createRollbackSnapshot(c, t);
375
+ const S = [];
376
+ a.forEach((g) => {
377
+ const _ = this.runCallbackSafely(
378
+ () => g({
379
+ after: this.createOnActionAfterCallbackCollector(c, t),
380
+ args: o,
381
+ name: c,
382
+ onError: this.createOnActionOnErrorCallbackCollector(c, t)
383
+ }),
384
+ "store:onAction:callback:error",
385
+ t.$id,
386
+ () => ({ actionId: d, groupId: f })
387
+ );
388
+ _ && S.push(_);
389
+ }), this.endGroupAfter(S, k), this.executeStoreOnActionAfterCallbacks(i, p, t, c, d, h), this.executeStoreOnActionOnErrorCallbacks(u, p, t, c, d, h), this.clearOnActionCallbacksSubscriptions(p);
390
+ } catch (p) {
391
+ throw k(), p;
392
+ }
393
+ }));
394
+ }
395
+ executeStoreOnActionAfterCallbacks(t, e, r, i, o, c) {
396
+ const u = this._onActionAfterSubscriptions[e];
397
+ u?.length && t((a) => {
398
+ this.traceGroupStart(
399
+ () => ({
400
+ actionId: o,
401
+ groupId: y.onActionAfter(r.$id, i, c),
402
+ result: a
403
+ }),
404
+ r.$id,
405
+ `store:onAction:after:${i}`
406
+ );
407
+ const h = u.map((d) => this.runCallbackSafely(
408
+ () => d(a),
409
+ "storeOnActionAfterCallbacks",
410
+ r.$id,
411
+ () => ({ actionId: o, "action name": i, groupId: y.onActionAfter(r.$id, i, c) })
412
+ ));
413
+ this.endGroupAfter(h, () => this.traceGroupEnd(() => ({ groupId: y.onActionAfter(r.$id, i, c) }), r.$id));
414
+ });
415
+ }
416
+ executeStoreOnActionOnErrorCallbacks(t, e, r, i, o, c) {
417
+ const u = this._onActionOnErrorSubscriptions[e];
418
+ u?.length && t((a) => {
419
+ this.traceGroupStart(
420
+ () => ({
421
+ actionId: o,
422
+ "action name": i,
423
+ error: a,
424
+ groupId: y.onActionError(r.$id, i, c)
425
+ }),
426
+ r.$id,
427
+ `store:onAction:onError:${i}`
428
+ );
429
+ const h = u.map((d) => this.runCallbackSafely(
430
+ () => d(a),
431
+ "store:onAction:onError:error",
432
+ r.$id,
433
+ () => ({ actionId: o, groupId: y.onActionError(r.$id, i, c) })
434
+ ));
435
+ this.endGroupAfter(h, () => this.traceGroupEnd(() => ({ groupId: y.onActionError(r.$id, i, c) }), r.$id));
436
+ });
437
+ }
438
+ executeSubscriber(t, e) {
439
+ const r = this.defineSubscriberKey(e, t.store);
440
+ if (this._subscribersDelivered.has(r) || !e.invoke(t, this._options?.tracerHandler?.createTracer))
441
+ return;
442
+ this._subscribersDelivered.add(r);
443
+ let i;
444
+ try {
445
+ i = e.hydrate?.(t);
446
+ } catch (u) {
447
+ this.traceError("subscriber:hydrate", u, t.store.$id);
448
+ return;
449
+ }
450
+ const o = () => {
451
+ try {
452
+ const u = e.afterHydration?.(t);
453
+ if (u && typeof u.then == "function")
454
+ return u.catch(
455
+ (a) => this.traceError("subscriber:afterHydration", a, t.store.$id)
456
+ );
457
+ } catch (u) {
458
+ this.traceError("subscriber:afterHydration", u, t.store.$id);
459
+ }
460
+ };
461
+ let c;
462
+ return i && typeof i.then == "function" ? c = i.then(() => o()).catch((u) => this.traceError("subscriber:hydrate", u, 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;
463
+ }
464
+ executeSubscriberSafely(t, e) {
465
+ try {
466
+ return this.executeSubscriber(t, e);
467
+ } catch (r) {
468
+ this.traceError("subscriber:execute", r, t.store.$id);
469
+ }
470
+ }
471
+ initializeTracer() {
472
+ this._options?.tracerHandler && (this._tracer = this._options.tracerHandler.createTracer(H));
473
+ }
474
+ plugin({ store: t, options: e }) {
475
+ if (!this._subscribers.length)
476
+ return;
477
+ const r = {
478
+ $onAction: [],
479
+ $subscribe: []
480
+ }, i = y.plugin(t.$id);
481
+ this.traceGroupStart(() => ({
482
+ groupId: i,
483
+ subscribers: this._subscribers,
484
+ "hooks subscriptions": r,
485
+ store: t,
486
+ options: e
487
+ }), t.$id), this._onActionSubscriptionsTraces.set(t.$id, r.$onAction), this._onMutationSubscriptionsTraces.set(t.$id, r.$subscribe);
488
+ try {
489
+ this._subscribers.forEach(
490
+ (o) => {
491
+ const c = this.defineSubscriberKey(o, t), u = this.definePluginExecution(o);
492
+ if (!(this._subscribersDelivered.has(c) || this._subscribersScheduled.has(c)) && this.shouldInvokePlugin(u)) {
493
+ if (this.shouldScheduleAfterHydration(u)) {
494
+ this.queueSubscriberExecution({ store: t, options: e }, o, c);
495
+ return;
496
+ }
497
+ this.executeSubscriber({ store: t, options: e }, o);
498
+ }
499
+ }
500
+ ), this.rewriteResetStore({ store: t }, t.$state), this._storeRollbackSnapshotsHandler.initFromPluginContext({ store: t, options: e }), this.executeStoreOnActionSubscription(t), this.registerStoreCleanup(t);
501
+ } catch (o) {
502
+ this.traceError("plugin:invoke", o, t.$id);
503
+ }
504
+ this.traceGroupEnd(() => ({ groupId: i }), t.$id);
505
+ }
506
+ queueSubscriberExecution(t, e, r) {
507
+ const i = this.defineHydrationScheduler(e);
508
+ this._subscribersScheduled.add(r), i(() => {
509
+ if (this._disposedStores.has(t.store))
510
+ return;
511
+ this._subscribersScheduled.delete(r);
512
+ const o = t.store.$id, c = y.pluginDeferred(o, e.name, ++this._actionSeq);
513
+ this.traceGroupStart(() => ({ groupId: c, subscriber: e.name }), o, "subscriber:deferred");
514
+ const u = () => this.traceGroupEnd(() => ({ groupId: c }), o);
515
+ let a;
516
+ try {
517
+ a = this.executeSubscriberSafely(t, e);
518
+ } finally {
519
+ a ? this.closeGroupWhenSettled(a, u, o, e.name) : u();
520
+ }
521
+ });
522
+ }
523
+ registerStoreCleanup(t) {
524
+ if (typeof t.$dispose != "function")
525
+ return;
526
+ const e = t.$dispose.bind(t), r = t;
527
+ r.__piniaPluginSubscriptionDisposed || (r.__piniaPluginSubscriptionDisposed = !0, t.$dispose = () => (this._disposedStores.add(t), this.clearStoreTracking(t), this._storeRollbackSnapshotsHandler.clearStoreTracking(t), e()));
528
+ }
529
+ rewriteResetStore({ store: t }, e) {
530
+ const r = A(e);
531
+ t.$reset = () => {
532
+ const i = y.reset(t.$id, ++this._actionSeq);
533
+ this.traceGroupStart(() => ({ initialState: r, groupId: i }), t.$id, "store:reset");
534
+ try {
535
+ this.executeResetStoreCallbacks(t), t.$patch(A(r));
536
+ } finally {
537
+ this.traceGroupEnd(() => ({ groupId: i }), t.$id);
538
+ }
539
+ };
540
+ }
541
+ runCallbackSafely(t, e, r, i) {
542
+ try {
543
+ const o = t();
544
+ if (o && typeof o.then == "function")
545
+ return Promise.resolve(o).then(
546
+ () => {
547
+ },
548
+ (c) => this.traceError(e, c, r, i)
549
+ );
550
+ } catch (o) {
551
+ this.traceError(e, o, r, i);
552
+ }
553
+ }
554
+ shouldInvokePlugin(t) {
555
+ const e = this.defineCurrentEnvironment();
556
+ return t.environment === "both" || t.environment === e;
557
+ }
558
+ shouldScheduleAfterHydration(t) {
559
+ return this.defineCurrentEnvironment() === "client" && t.hydration === "defer";
560
+ }
561
+ storeOnActionSubscription(t, e) {
562
+ const { store: r, callback: i } = t?.storeOnActionSubscription?.(e) ?? {};
563
+ !r || !i || (this._onActionSubscriptions.has(r) || this._onActionSubscriptions.set(r, /* @__PURE__ */ new Set()), this._onActionSubscriptions.get(r).add(i), this._onActionSubscriptionsTraces.get(r.$id)?.push(t.name));
564
+ }
565
+ storeMutationSubscription(t, e) {
566
+ const { store: r, callback: i } = e();
567
+ if (!r || !i || (this._onMutationSubscriptions.has(r) || this._onMutationSubscriptions.set(r, /* @__PURE__ */ new Set()), this._onMutationSubscriptions.get(r).add(i), this._onMutationSubscriptionsTraces.get(r.$id)?.push(t.name), this._onMutationUnsubscribes.has(r)))
568
+ return;
569
+ const o = r.$subscribe(async (c) => {
570
+ const u = this._onMutationSubscriptions.get(r);
571
+ if (!u?.size)
572
+ return;
573
+ const a = y.onMutation(r.$id, ++this._actionSeq);
574
+ this.traceGroupStart(() => ({ mutation: c, groupId: a }), r.$id, "store:onMutation");
575
+ try {
576
+ await Promise.all([...u].map(async (h) => {
577
+ try {
578
+ await h(c);
579
+ } catch (d) {
580
+ this.traceError("store:onMutation", d, r.$id, () => ({ groupId: a }));
581
+ }
582
+ }));
583
+ } finally {
584
+ this.traceGroupEnd(() => ({ groupId: a }), r.$id);
585
+ }
586
+ });
587
+ this._onMutationUnsubscribes.set(r, o);
588
+ }
589
+ subscriptionDelivery(t, e) {
590
+ Object.entries(e).forEach(([r, i]) => {
591
+ const o = this.defineSubscriptionKey(r, t.store), c = this.definePluginExecution(i.subscription);
592
+ if (!(this._subscriptionsDelivered.has(o) || this._subscriptionsScheduled.has(o)) && this.shouldInvokePlugin(c)) {
593
+ if (this.shouldScheduleAfterHydration(c)) {
594
+ const u = this.defineHydrationScheduler(i.subscription);
595
+ this._subscriptionsScheduled.add(o), u(() => {
596
+ this._disposedStores.has(t.store) || (this._subscriptionsScheduled.delete(o), this.subscriptionDeliverySafely(t, r, i));
597
+ });
598
+ return;
599
+ }
600
+ this.subscriptionDeliverySafely(t, r, i);
601
+ }
602
+ });
603
+ }
604
+ subscriptionDeliverySafely({ store: t, options: e }, r, i) {
605
+ try {
606
+ if (this._subscriptionsDelivered.has(this.defineSubscriptionKey(r, t)))
607
+ return;
608
+ const { subscription: o, subscriptionOptions: c, stores: u } = i;
609
+ this.trace("Subscription:delivery", t.$id, () => ({
610
+ groupId: y.plugin(t.$id),
611
+ pluginName: r,
612
+ subscription: o,
613
+ subscriptionOptions: c
614
+ }));
615
+ const a = {
616
+ storeOptions: { ...e?.storeOptions ?? {}, ...c }
617
+ };
618
+ o.invoke(
619
+ { store: t, options: { ...e, ...a } }
620
+ ), this._subscriptionsDelivered.add(this.defineSubscriptionKey(r, t)), v(u) || u?.forEach(
621
+ (h) => o.invoke({
622
+ store: h,
623
+ options: {
624
+ ...e,
625
+ ...a,
626
+ ...h?.storeOptions ?? {}
627
+ }
628
+ })
629
+ );
630
+ } catch (o) {
631
+ this.traceError("subscription:delivery", o, t.$id, () => ({ groupId: y.plugin(t.$id) }));
632
+ }
633
+ }
634
+ traceGroupEnd(t, e) {
635
+ const r = this._options?.tracerHandler;
636
+ r && (r.hasTraceListeners?.() ?? !0) && r.closeGroup({
637
+ ...typeof t == "function" ? t() : t ?? {},
638
+ scope: e
639
+ });
640
+ }
641
+ traceGroupStart(t, e, r) {
642
+ const i = this._options?.tracerHandler;
643
+ i && (i.hasTraceListeners?.() ?? !0) && (t = typeof t == "function" ? t() : t ?? {}, i.startGroup({
644
+ ...t,
645
+ scope: e
646
+ }), this.trace(r ?? "context", e, t));
647
+ }
648
+ }
649
+ function Z(s) {
650
+ if (typeof s != "function")
651
+ return s;
652
+ try {
653
+ return s();
654
+ } catch (n) {
655
+ return { __tracePayloadError: n };
656
+ }
657
+ }
658
+ class tt {
659
+ constructor(n, t, e = {}) {
660
+ l(this, "_currentGroupId");
661
+ l(this, "_journal");
662
+ l(this, "_listeners", []);
663
+ l(this, "_redactor");
664
+ l(this, "_scope");
665
+ l(this, "_side");
666
+ l(this, "_source");
667
+ this._currentGroupId = e.currentGroupId, this._journal = e.journal, this._redactor = e.redactor, this._side = e.side ?? "client", this._scope = e.scope, this._source = n, this._listeners = t;
668
+ }
669
+ get scope() {
670
+ return this._scope;
671
+ }
672
+ set scope(n) {
673
+ this._scope = n;
674
+ }
675
+ get source() {
676
+ return this._source;
677
+ }
678
+ debug(n, t, e, r) {
679
+ this.emit("debug", n, t, e, r);
680
+ }
681
+ error(n, t, e, r, i) {
682
+ this.emit("error", n, t, r, i, e);
683
+ }
684
+ resolveAndRedact(n) {
685
+ const t = Z(n);
686
+ if (!this._redactor || t === void 0)
687
+ return t;
688
+ try {
689
+ return this._redactor(t);
690
+ } catch (e) {
691
+ return { __traceRedactionError: e instanceof Error ? e.message : String(e) };
692
+ }
693
+ }
694
+ buildMetadata(n, t, e, r) {
695
+ return {
696
+ label: t,
697
+ level: n,
698
+ namespace: e,
699
+ scope: r ?? this._scope,
700
+ source: this._source
701
+ };
702
+ }
703
+ matchListeners(n) {
704
+ const t = [];
705
+ for (const e of this._listeners)
706
+ try {
707
+ e.filter(n) && t.push(e);
708
+ } catch (r) {
709
+ console.error("Error in trace listener filter:", r);
710
+ }
711
+ return t;
712
+ }
713
+ emit(n, t, e, r, i, o) {
714
+ if (this._listeners.length === 0 && !this._journal) {
715
+ n === "error" && console.error("Unhandled error trace event:", o);
716
+ return;
717
+ }
718
+ const c = this.buildMetadata(n, t, e, i), u = this._listeners.length ? this.matchListeners(c) : [];
719
+ if (u.length === 0 && !this._journal) {
720
+ n === "error" && console.error("Unhandled error trace event:", o);
721
+ return;
722
+ }
723
+ const a = r !== void 0 ? this.resolveAndRedact(r) : void 0, { actionId: h, groupId: d, ...f } = a ?? {}, b = typeof d == "string" ? d : this._currentGroupId?.(c.scope), p = {
724
+ ...c,
725
+ ...typeof h == "string" && { actionId: h },
726
+ ...b !== void 0 && { groupId: b },
727
+ ...o !== void 0 && { error: o },
728
+ ...a !== void 0 && { payload: typeof h == "string" || typeof d == "string" ? f : a },
729
+ ...this._journal && { seq: this._journal.nextSeq(), side: this._side },
730
+ timestamp: Date.now()
731
+ };
732
+ this._journal?.append(p), u.length === 0 && n === "error" && console.error("Unhandled error trace event:", o);
733
+ for (const S of u)
734
+ try {
735
+ S.handler(p);
736
+ } catch (g) {
737
+ console.error("Error in trace listener:", g);
738
+ }
739
+ }
740
+ }
741
+ const et = 1e3;
742
+ function rt(s) {
743
+ return s.level === "error" || q(s);
744
+ }
745
+ function st(s, n, t) {
746
+ s.push(n);
747
+ const e = s.length - t;
748
+ return e > 0 ? (s.splice(0, e), e) : 0;
749
+ }
750
+ function nt(s) {
751
+ if (!s || typeof s != "object")
752
+ return;
753
+ const { error: n, label: t, level: e, namespace: r, payload: i, seq: o, source: c, timestamp: u } = s;
754
+ if (typeof t != "string" || typeof r != "string" || typeof c != "string" || e !== "debug" && e !== "error" || typeof o != "number" || !Number.isFinite(o) || typeof u != "number")
755
+ return;
756
+ const { actionId: a, groupId: h, scope: d } = s;
757
+ return {
758
+ ...typeof a == "string" && { actionId: a },
759
+ ...n !== void 0 && { error: n },
760
+ ...typeof h == "string" && { groupId: h },
761
+ label: t,
762
+ level: e,
763
+ namespace: r,
764
+ ...typeof i == "object" && i !== null && { payload: i },
765
+ ...typeof d == "string" && { scope: d },
766
+ seq: o,
767
+ side: "server",
768
+ source: c,
769
+ timestamp: u
770
+ };
771
+ }
772
+ function it({ maxEventsPerStore: s } = {}) {
773
+ const n = Math.max(1, Math.floor(s ?? et)), t = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Set();
774
+ let r = 0;
775
+ function i(a) {
776
+ let h = t.get(a);
777
+ return h || (h = { dropped: 0, kept: [], rings: { client: [], server: [] } }, t.set(a, h)), h;
778
+ }
779
+ function o() {
780
+ t.forEach((a) => {
781
+ a.rings.server = [], a.kept = a.kept.filter((h) => h.side !== "server");
782
+ });
783
+ }
784
+ function c() {
785
+ return [...t.keys()].flatMap((a) => u(a)).sort((a, h) => (a.seq ?? 0) - (h.seq ?? 0));
786
+ }
787
+ function u(a) {
788
+ const h = t.get(a);
789
+ return h ? [...h.kept, ...h.rings.client, ...h.rings.server].sort((d, f) => (d.seq ?? 0) - (f.seq ?? 0)) : [];
790
+ }
791
+ return {
792
+ append(a) {
793
+ const h = i(a.scope ?? B), d = rt(a) ? h.kept : h.rings[a.side ?? "client"];
794
+ h.dropped += st(d, a, n), e.forEach((f) => {
795
+ try {
796
+ f(a);
797
+ } catch (b) {
798
+ console.error("Error in trace journal listener:", b);
799
+ }
800
+ });
801
+ },
802
+ clear(a) {
803
+ a === void 0 ? t.clear() : t.delete(a);
804
+ },
805
+ getDropped: (a) => t.get(a)?.dropped ?? 0,
806
+ getEvents: u,
807
+ getScopes: () => [...t.keys()],
808
+ import(a) {
809
+ const h = a?.events;
810
+ if (!Array.isArray(h))
811
+ return 0;
812
+ const d = h.map(nt).filter((b) => !!b), f = d.reduce((b, k) => Math.max(b, k.seq ?? 0), 0);
813
+ return o(), d.forEach((b) => this.append({ ...b, seq: (b.seq ?? 0) - f - 1 })), d.length;
814
+ },
815
+ nextSeq: () => ++r,
816
+ serialize: () => ({
817
+ events: c().map(({ error: a, payload: h, ...d }) => ({
818
+ ...d,
819
+ ...a !== void 0 && { error: M(a) },
820
+ ...h !== void 0 && { payload: M(h) }
821
+ })),
822
+ version: 1
823
+ }),
824
+ subscribe(a) {
825
+ return e.add(a), () => {
826
+ e.delete(a);
827
+ };
828
+ }
829
+ };
830
+ }
831
+ const ot = () => {
832
+ };
833
+ function x(s, n = !0, t) {
834
+ return (e) => s[t](({ comparator: r = "equals", target: i, value: o }) => {
835
+ if (i === "namespace" && n && ut(e))
836
+ return !0;
837
+ const c = e[i];
838
+ if (typeof c != "string") return !1;
839
+ let u = !1;
840
+ switch (r) {
841
+ case "equals":
842
+ u = c === o;
843
+ break;
844
+ case "contains":
845
+ u = c.includes(o);
846
+ break;
847
+ case "startsWith":
848
+ u = c.startsWith(o);
849
+ break;
850
+ case "endsWith":
851
+ u = c.endsWith(o);
852
+ break;
853
+ default:
854
+ u = !1;
855
+ break;
856
+ }
857
+ return u;
858
+ });
859
+ }
860
+ function ct(s, n = !0, t = "every") {
861
+ const { handler: e = ot, filter: r } = at(s, n, t);
862
+ return { filter: r, handler: e };
863
+ }
864
+ function at(s, n = !0, t = "every") {
865
+ return Array.isArray(s) ? { filter: x(s, n, t) } : {
866
+ ...s,
867
+ filter: Array.isArray(s.filter) ? x(s.filter, n, t) : s.filter
868
+ };
869
+ }
870
+ function ut(s) {
871
+ return s?.source === H && (!s?.namespace || s.namespace.startsWith(V));
872
+ }
873
+ function ht() {
874
+ try {
875
+ return process.env.NODE_ENV === "production";
876
+ } catch {
877
+ return !1;
878
+ }
879
+ }
880
+ const dt = "[REDACTED]", lt = [
881
+ /pass(word|wd|phrase|code)|^pwd/i,
882
+ /secret/i,
883
+ /token/i,
884
+ /authorization/i,
885
+ /api[-_]?key/i,
886
+ /(private|encryption|signing|secret)[-_]?key/i,
887
+ /credential/i,
888
+ /cookie/i,
889
+ /cipher/i
890
+ ], pt = 12;
891
+ function ft(s) {
892
+ const n = /* @__PURE__ */ new Set(), t = [];
893
+ for (const e of s)
894
+ typeof e == "string" ? n.add(e.toLowerCase()) : t.push(new RegExp(e.source, e.flags.replace(/[gy]/g, "")));
895
+ return (e) => n.has(e.toLowerCase()) || t.some((r) => r.test(e));
896
+ }
897
+ function bt(s) {
898
+ return s === null || typeof s != "object" ? !1 : !(s instanceof Date || s instanceof RegExp || s instanceof Error || s instanceof Promise || s instanceof WeakMap || s instanceof WeakSet);
899
+ }
900
+ function St(s = !0) {
901
+ const { includeDefaults: n = !0, keys: t = [], replacement: e = dt } = s === !0 ? {} : s, r = ft([...n ? lt : [], ...t]);
902
+ function i(o, c, u) {
903
+ if (!bt(o))
904
+ return o;
905
+ const a = c.get(o);
906
+ if (a !== void 0)
907
+ return a;
908
+ if (u >= pt)
909
+ return "[MaxDepth]";
910
+ if (o instanceof Map) {
911
+ const d = /* @__PURE__ */ new Map();
912
+ return c.set(o, d), o.forEach((f, b) => {
913
+ d.set(b, typeof b == "string" && r(b) ? e : i(f, c, u + 1));
914
+ }), d;
915
+ }
916
+ if (o instanceof Set) {
917
+ const d = /* @__PURE__ */ new Set();
918
+ return c.set(o, d), o.forEach((f) => d.add(i(f, c, u + 1))), d;
919
+ }
920
+ if (Array.isArray(o)) {
921
+ const d = [];
922
+ return c.set(o, d), o.forEach((f) => d.push(i(f, c, u + 1))), d;
923
+ }
924
+ const h = {};
925
+ c.set(o, h);
926
+ for (const d of Object.keys(o)) {
927
+ const f = r(d) ? e : i(o[d], c, u + 1);
928
+ Object.defineProperty(h, d, {
929
+ configurable: !0,
930
+ enumerable: !0,
931
+ value: f,
932
+ writable: !0
933
+ });
934
+ }
935
+ return h;
936
+ }
937
+ return (o) => i(o, /* @__PURE__ */ new WeakMap(), 0);
938
+ }
939
+ const _t = () => {
940
+ };
941
+ function Tt({ enabled: s = !ht(), journal: n = !1, redact: t = !1, side: e } = {}) {
942
+ const r = s && n ? it(n === !0 ? {} : n) : void 0, i = e ?? (typeof window > "u" ? "server" : "client"), o = t ? St(t === !0 ? !0 : t) : void 0, c = [], u = /* @__PURE__ */ new Map(), a = (p) => {
943
+ const S = p ? u.get(p) : void 0;
944
+ return S?.[S.length - 1];
945
+ };
946
+ function h(p, { context: S = !0, filterMode: g = "every" } = {}) {
947
+ if (!s)
948
+ return _t;
949
+ const _ = ct(p, !!S, g ?? "every");
950
+ return c.push(_), () => {
951
+ const E = c.indexOf(_);
952
+ E !== -1 && c.splice(E, 1);
953
+ };
954
+ }
955
+ function d(p, S = !0, g) {
956
+ return h(
957
+ { filter: p.map((_) => ({ target: "scope", value: _ })), handler: g },
958
+ { context: S, filterMode: "some" }
959
+ );
960
+ }
961
+ function f() {
962
+ c.length = 0;
963
+ }
964
+ function b() {
965
+ return c.length > 0 || !!r;
966
+ }
967
+ function k(p, { groupId: S, scope: g }) {
968
+ if (!S || !g)
969
+ return;
970
+ const _ = u.get(g) ?? [];
971
+ if (p === "open") {
972
+ _.push(S), u.set(g, _);
973
+ return;
974
+ }
975
+ const E = _.lastIndexOf(S);
976
+ E >= 0 && _.splice(E, 1), _.length || u.delete(g);
977
+ }
978
+ return {
979
+ addListener: h,
980
+ addScopesListener: d,
981
+ clearTraceListeners: f,
982
+ journal: r,
983
+ tracerHandler: {
984
+ closeGroup: (p) => k("close", p),
985
+ createTracer: (p, S = {}) => new tt(p, c, { currentGroupId: a, journal: r, redactor: o, side: i, ...S }),
986
+ hasTraceListeners: b,
987
+ journal: r,
988
+ startGroup: (p) => k("open", p)
989
+ },
990
+ hasTraceListeners: b
991
+ };
992
+ }
993
+ export {
994
+ wt as P,
995
+ z as T,
996
+ tt as a,
997
+ ht as b,
998
+ Tt as c,
999
+ lt as d,
1000
+ mt as e,
1001
+ Et as f,
1002
+ $t as g,
1003
+ N as h,
1004
+ v as i,
1005
+ Ot as j,
1006
+ H as p,
1007
+ Ct as s
1008
+ };
1009
+ //# sourceMappingURL=trace-registry-Cm_2un0x.js.map