pinia-plugin-subscription 1.0.0-beta.11 → 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.
- package/CHANGELOG.md +17 -5
- package/README.md +2 -0
- package/dist/chunks/{PluginSubscription-BbN48iuP.js → PluginSubscription-Bkqj4uSK.js} +189 -163
- package/dist/chunks/PluginSubscription-Bkqj4uSK.js.map +1 -0
- package/dist/core/PluginSubscription.d.ts +8 -0
- package/dist/helpers.js +326 -303
- package/dist/helpers.js.map +1 -1
- package/dist/pinia-plugin-subscription.js +2 -2
- package/dist/system/log/console-group.d.ts +8 -0
- package/dist/system/{log.d.ts → log/console.d.ts} +1 -11
- package/dist/system/log/index.d.ts +2 -0
- package/dist/system/log/log-trace.d.ts +8 -0
- package/dist/system/log/print-array.d.ts +7 -0
- package/dist/system/log/print-error.d.ts +6 -0
- package/dist/system/log/print-object.d.ts +1 -0
- package/dist/system/log/print-trace-payload.d.ts +1 -0
- package/dist/system/log/print-trace.d.ts +9 -0
- package/dist/system/log/trace-console.d.ts +9 -0
- package/dist/types/plugin.d.ts +7 -0
- package/dist/utils/store.d.ts +4 -1
- package/docs/authoring-plugins.md +22 -5
- package/docs/tracing.md +2 -0
- package/docs/using-plugins.md +12 -0
- package/package.json +3 -1
- package/dist/chunks/PluginSubscription-BbN48iuP.js.map +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { toRaw as
|
|
5
|
-
import { defineStore as
|
|
6
|
-
function
|
|
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]) => [
|
|
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) =>
|
|
19
|
+
return new Set(Array.from(i.values(), (t) => l(t)));
|
|
20
20
|
if (Array.isArray(i))
|
|
21
|
-
return i.map((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,
|
|
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] =
|
|
28
|
+
s[t] = l(e);
|
|
29
29
|
return s;
|
|
30
30
|
}
|
|
31
|
-
function
|
|
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] =
|
|
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
|
|
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
|
|
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
|
-
) :
|
|
55
|
+
) : x(
|
|
56
56
|
i,
|
|
57
57
|
s,
|
|
58
58
|
e
|
|
59
59
|
);
|
|
60
60
|
}
|
|
61
|
-
function
|
|
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
|
-
|
|
71
|
-
|
|
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
|
-
() =>
|
|
73
|
+
() => (e = {
|
|
74
|
+
id: i,
|
|
75
|
+
extensions: {}
|
|
76
|
+
}, r && b.set(i, e), s(e)),
|
|
76
77
|
t
|
|
77
78
|
);
|
|
78
|
-
return Object.assign(((...
|
|
79
|
-
|
|
80
|
-
|
|
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
|
|
85
|
-
return t && (s = { ...s, ...t ?? {} }),
|
|
84
|
+
function x(i, s, t) {
|
|
85
|
+
return t && (s = { ...s, ...t ?? {} }), C(i, s);
|
|
86
86
|
}
|
|
87
|
-
const
|
|
87
|
+
const v = /* @__PURE__ */ new Set(["_", "$"]);
|
|
88
88
|
function D(i) {
|
|
89
|
-
return
|
|
89
|
+
return v.has(i[0]);
|
|
90
90
|
}
|
|
91
|
-
function
|
|
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
|
|
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
|
|
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
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
|
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 (
|
|
129
|
-
throw this.patchStore(
|
|
128
|
+
} catch (a) {
|
|
129
|
+
throw this.patchStore(c, s), a;
|
|
130
130
|
} finally {
|
|
131
|
-
this.removeStateSnapshot(
|
|
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 =
|
|
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
|
|
192
|
+
class I {
|
|
193
193
|
constructor() {
|
|
194
|
-
|
|
195
|
-
|
|
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
|
|
214
|
-
|
|
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
|
|
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
|
|
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 =
|
|
228
|
+
}, K = T, W = {
|
|
229
229
|
environment: "both",
|
|
230
230
|
hydration: "immediate"
|
|
231
|
-
};
|
|
232
|
-
function
|
|
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
|
|
239
|
+
class Z extends I {
|
|
240
240
|
constructor(t, e) {
|
|
241
241
|
super();
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
this._hydrationScheduler = e?.hydrationScheduler ??
|
|
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 (!
|
|
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:
|
|
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:
|
|
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(
|
|
359
|
-
this._storeRollbackSnapshotsHandler.storeHasRollbackSnapshots(t) && this.createRollbackSnapshot(
|
|
358
|
+
const S = f(c, t);
|
|
359
|
+
this._storeRollbackSnapshotsHandler.storeHasRollbackSnapshots(t) && this.createRollbackSnapshot(c, t);
|
|
360
360
|
const $ = [];
|
|
361
|
-
h.forEach((
|
|
361
|
+
h.forEach((M) => {
|
|
362
362
|
const g = this.runCallbackSafely(
|
|
363
|
-
() =>
|
|
364
|
-
after: this.createOnActionAfterCallbackCollector(
|
|
365
|
-
args:
|
|
366
|
-
name:
|
|
367
|
-
onError: this.createOnActionOnErrorCallbackCollector(
|
|
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,
|
|
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
|
|
382
|
-
if (
|
|
383
|
-
return Promise.resolve(
|
|
381
|
+
const o = t();
|
|
382
|
+
if (o && typeof o.then == "function")
|
|
383
|
+
return Promise.resolve(o).then(
|
|
384
384
|
() => {
|
|
385
385
|
},
|
|
386
|
-
(
|
|
386
|
+
(c) => this.traceError(e, c, r, n)
|
|
387
387
|
);
|
|
388
|
-
} catch (
|
|
389
|
-
this.traceError(e,
|
|
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
|
|
398
|
-
|
|
397
|
+
const o = this._onActionAfterSubscriptions[e];
|
|
398
|
+
o?.length && t((c) => {
|
|
399
399
|
this.traceGroupStart(
|
|
400
400
|
() => ({
|
|
401
|
-
groupId:
|
|
402
|
-
result:
|
|
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
|
|
408
|
-
() => h(
|
|
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(
|
|
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
|
|
418
|
-
|
|
417
|
+
const o = this._onActionOnErrorSubscriptions[e];
|
|
418
|
+
o?.length && t((c) => {
|
|
419
419
|
this.traceGroupStart(
|
|
420
420
|
() => ({
|
|
421
421
|
"action name": n,
|
|
422
|
-
error:
|
|
423
|
-
groupId:
|
|
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
|
|
429
|
-
() => h(
|
|
428
|
+
const a = o.map((h) => this.runCallbackSafely(
|
|
429
|
+
() => h(c),
|
|
430
430
|
"store:onAction:onError:error",
|
|
431
431
|
r.$id,
|
|
432
|
-
() => ({ groupId:
|
|
432
|
+
() => ({ groupId: d.onActionError(r.$id) })
|
|
433
433
|
));
|
|
434
|
-
this.endGroupAfter(
|
|
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 (
|
|
446
|
-
this.traceError("subscriber:hydrate",
|
|
445
|
+
} catch (a) {
|
|
446
|
+
this.traceError("subscriber:hydrate", a, t.store.$id);
|
|
447
447
|
return;
|
|
448
448
|
}
|
|
449
|
-
const
|
|
449
|
+
const o = () => {
|
|
450
450
|
try {
|
|
451
|
-
const
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
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
|
-
|
|
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(
|
|
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
|
|
492
|
-
if (!(this._subscribersDelivered.has(
|
|
493
|
-
if (this.shouldScheduleAfterHydration(
|
|
494
|
-
this.queueSubscriberExecution({ store: t, options: e }, 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);
|
|
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)
|
|
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 =
|
|
545
|
+
const r = l(e);
|
|
520
546
|
t.$reset = () => {
|
|
521
|
-
this.traceGroupStart(() => ({ initialState: r, groupId:
|
|
547
|
+
this.traceGroupStart(() => ({ initialState: r, groupId: d.reset(t.$id) }), t.$id, "store:reset");
|
|
522
548
|
try {
|
|
523
|
-
this.executeResetStoreCallbacks(t), t.$patch(
|
|
549
|
+
this.executeResetStoreCallbacks(t), t.$patch(l(r));
|
|
524
550
|
} finally {
|
|
525
|
-
this.traceGroupEnd(() => ({ initialState: r, groupId:
|
|
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
|
|
545
|
-
const
|
|
546
|
-
if (
|
|
547
|
-
this.traceGroupStart(() => ({ mutation:
|
|
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([...
|
|
575
|
+
await Promise.all([...a].map(async (h) => {
|
|
550
576
|
try {
|
|
551
|
-
await h(
|
|
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:
|
|
583
|
+
this.traceGroupEnd(() => ({ mutation: c, groupId: d.onMutation(r.$id) }), r.$id);
|
|
558
584
|
}
|
|
559
585
|
}
|
|
560
586
|
});
|
|
561
|
-
this._onMutationUnsubscribes.set(r,
|
|
587
|
+
this._onMutationUnsubscribes.set(r, o);
|
|
562
588
|
}
|
|
563
589
|
subscriptionDelivery(t, e) {
|
|
564
590
|
Object.entries(e).forEach(([r, n]) => {
|
|
565
|
-
const
|
|
566
|
-
if (!(this._subscriptionsDelivered.has(
|
|
567
|
-
if (this.shouldScheduleAfterHydration(
|
|
568
|
-
const
|
|
569
|
-
this._subscriptionsScheduled.add(
|
|
570
|
-
this._disposedStores.has(t.store) || (this._subscriptionsScheduled.delete(
|
|
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:
|
|
608
|
+
const { subscription: o, subscriptionOptions: c, stores: a } = n;
|
|
583
609
|
this.trace("Subscription:delivery", t.$id, () => ({
|
|
584
610
|
pluginName: r,
|
|
585
|
-
subscription:
|
|
586
|
-
subscriptionOptions:
|
|
611
|
+
subscription: o,
|
|
612
|
+
subscriptionOptions: c
|
|
587
613
|
}));
|
|
588
614
|
const h = {
|
|
589
|
-
storeOptions: { ...e?.storeOptions ?? {}, ...
|
|
615
|
+
storeOptions: { ...e?.storeOptions ?? {}, ...c }
|
|
590
616
|
};
|
|
591
|
-
|
|
617
|
+
o.invoke(
|
|
592
618
|
{ store: t, options: { ...e, ...h } }
|
|
593
|
-
), this._subscriptionsDelivered.add(this.defineSubscriptionKey(r, t)),
|
|
594
|
-
(p) =>
|
|
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 (
|
|
604
|
-
this.traceError("subscription:delivery",
|
|
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
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
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
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
657
|
+
O as i,
|
|
658
|
+
F as p,
|
|
659
|
+
X as s,
|
|
660
|
+
d as t
|
|
635
661
|
};
|
|
636
|
-
//# sourceMappingURL=PluginSubscription-
|
|
662
|
+
//# sourceMappingURL=PluginSubscription-Bkqj4uSK.js.map
|