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.
- package/CHANGELOG.md +29 -12
- package/CONTRIBUTING.md +10 -1
- package/README.md +11 -9
- package/SECURITY.md +2 -2
- package/dist/chunks/{PluginSubscription-Bkqj4uSK.js → PluginSubscription-GJDsym1O.js} +253 -247
- package/dist/core/PluginSubscriber.d.ts +1 -1
- package/dist/core/PluginSubscription.d.ts +13 -12
- package/dist/core/Store.d.ts +1 -1
- package/dist/helpers/index.d.ts +0 -4
- package/dist/helpers.js +56 -651
- package/dist/pinia-plugin-subscription.js +4 -5
- package/dist/system/TraceEmitter.d.ts +1 -2
- package/dist/types/index.d.ts +1 -2
- package/dist/types/plugin.d.ts +2 -3
- package/dist/types/trace.d.ts +30 -109
- package/dist/utils/traceGroups.d.ts +9 -7
- package/docs/authoring-plugins.md +13 -7
- package/docs/using-plugins.md +28 -19
- package/package.json +9 -4
- package/dist/chunks/PluginSubscription-Bkqj4uSK.js.map +0 -1
- package/dist/factories/console-trace-listener.d.ts +0 -7
- package/dist/factories/trace-listener.d.ts +0 -10
- package/dist/factories/trace-registry.d.ts +0 -2
- package/dist/helpers.js.map +0 -1
- package/dist/pinia-plugin-subscription.js.map +0 -1
- package/dist/system/Tracer.d.ts +0 -23
- package/dist/system/log/console-group.d.ts +0 -8
- package/dist/system/log/console.d.ts +0 -18
- package/dist/system/log/index.d.ts +0 -2
- package/dist/system/log/log-trace.d.ts +0 -8
- package/dist/system/log/print-array.d.ts +0 -7
- package/dist/system/log/print-error.d.ts +0 -6
- package/dist/system/log/print-object.d.ts +0 -1
- package/dist/system/log/print-trace-payload.d.ts +0 -1
- package/dist/system/log/print-trace.d.ts +0 -9
- package/dist/system/log/trace-console.d.ts +0 -9
- package/dist/tests/defineAStore.test-d.d.ts +0 -1
- package/dist/tests/storeOptionsExtensions.test-d.d.ts +0 -12
- package/dist/types/comparison.d.ts +0 -3
- package/dist/types/list.d.ts +0 -13
- package/dist/types/log.d.ts +0 -8
- package/dist/types/resourceId.d.ts +0 -4
- package/dist/utils/Performance.d.ts +0 -9
- package/dist/utils/environment.d.ts +0 -7
- package/dist/utils/object.d.ts +0 -4
- package/dist/utils/redact.d.ts +0 -15
- package/docs/tracing.md +0 -185
|
@@ -1,144 +1,144 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var u = (
|
|
4
|
-
import { toRaw as
|
|
5
|
-
import { defineStore as
|
|
6
|
-
function
|
|
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(
|
|
9
|
+
return structuredClone(s);
|
|
10
10
|
} catch {
|
|
11
11
|
}
|
|
12
|
-
if (
|
|
13
|
-
return
|
|
14
|
-
if (
|
|
12
|
+
if (s === null || typeof s != "object")
|
|
13
|
+
return s;
|
|
14
|
+
if (s instanceof Map)
|
|
15
15
|
return new Map(
|
|
16
|
-
Array.from(
|
|
16
|
+
Array.from(s.entries(), ([t, e]) => [f(t), f(e)])
|
|
17
17
|
);
|
|
18
|
-
if (
|
|
19
|
-
return new Set(Array.from(
|
|
20
|
-
if (Array.isArray(
|
|
21
|
-
return
|
|
22
|
-
if (Object.getPrototypeOf(
|
|
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(
|
|
24
|
+
Object.entries(s).map(([t, e]) => [t, f(e)])
|
|
25
25
|
);
|
|
26
|
-
const
|
|
27
|
-
for (const [t, e] of Object.entries(
|
|
28
|
-
|
|
29
|
-
return
|
|
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
|
|
32
|
-
if (Array.isArray(
|
|
31
|
+
function D(s, i = "all") {
|
|
32
|
+
if (Array.isArray(i)) {
|
|
33
33
|
const t = {};
|
|
34
|
-
for (const e of
|
|
35
|
-
e in
|
|
34
|
+
for (const e of i)
|
|
35
|
+
e in s && (t[e] = f(w(s[e])));
|
|
36
36
|
return t;
|
|
37
37
|
}
|
|
38
|
-
if (
|
|
39
|
-
throw new Error(`Invalid keys parameter: ${
|
|
40
|
-
return
|
|
38
|
+
if (i !== "all")
|
|
39
|
+
throw new Error(`Invalid keys parameter: ${i}`);
|
|
40
|
+
return f(w(s));
|
|
41
41
|
}
|
|
42
|
-
const
|
|
43
|
-
function
|
|
44
|
-
if (
|
|
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 =
|
|
47
|
-
|
|
46
|
+
const t = s.$dispose;
|
|
47
|
+
s.$dispose = (...e) => ($.delete(s), _.delete(i), t.apply(s, e)), T.add(s);
|
|
48
48
|
}
|
|
49
|
-
function
|
|
49
|
+
function Y(s, i, t) {
|
|
50
50
|
const e = t ? { storeOptions: t } : {};
|
|
51
|
-
return typeof
|
|
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
|
|
61
|
+
function Z(s, i, t) {
|
|
62
62
|
const e = t ? { storeOptions: { ...t, enhancedStore: !0 } } : { storeOptions: { enhancedStore: !0 } };
|
|
63
|
-
return
|
|
64
|
-
i,
|
|
63
|
+
return G(
|
|
65
64
|
s,
|
|
65
|
+
i,
|
|
66
66
|
e
|
|
67
67
|
);
|
|
68
68
|
}
|
|
69
|
-
function
|
|
69
|
+
function G(s, i, t) {
|
|
70
70
|
let e;
|
|
71
|
-
const r = t?.storeOptions?.enhancedStore === !0, n =
|
|
72
|
-
|
|
71
|
+
const r = t?.storeOptions?.enhancedStore === !0, n = R(
|
|
72
|
+
s,
|
|
73
73
|
() => (e = {
|
|
74
|
-
id:
|
|
74
|
+
id: s,
|
|
75
75
|
extensions: {}
|
|
76
|
-
}, r &&
|
|
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 && (
|
|
81
|
+
return r && e && ($.set(c, e), _.delete(s), j(c, s)), c;
|
|
82
82
|
}), n);
|
|
83
83
|
}
|
|
84
|
-
function
|
|
85
|
-
return t && (
|
|
84
|
+
function I(s, i, t) {
|
|
85
|
+
return t && (i = { ...i, ...t ?? {} }), R(s, i);
|
|
86
86
|
}
|
|
87
|
-
const
|
|
88
|
-
function
|
|
89
|
-
return
|
|
87
|
+
const F = /* @__PURE__ */ new Set(["_", "$"]);
|
|
88
|
+
function K(s) {
|
|
89
|
+
return F.has(s[0]);
|
|
90
90
|
}
|
|
91
|
-
function
|
|
92
|
-
const
|
|
93
|
-
return
|
|
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
|
|
96
|
-
const
|
|
97
|
-
if (!
|
|
98
|
-
throw new Error(`${
|
|
99
|
-
return
|
|
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
|
|
102
|
-
|
|
101
|
+
function rt(s, i) {
|
|
102
|
+
s.extensions.enhancedStore = i, s.extensions.extending = i;
|
|
103
103
|
}
|
|
104
|
-
function
|
|
105
|
-
return
|
|
104
|
+
function S(s, i) {
|
|
105
|
+
return k(s, i);
|
|
106
106
|
}
|
|
107
|
-
function
|
|
108
|
-
const
|
|
109
|
-
return `${
|
|
107
|
+
function g(s) {
|
|
108
|
+
const i = String(s.$id);
|
|
109
|
+
return `${i.length}:${i}:`;
|
|
110
110
|
}
|
|
111
|
-
function
|
|
112
|
-
return `${
|
|
111
|
+
function k(s, i) {
|
|
112
|
+
return `${g(i)}${s.length}:${s}`;
|
|
113
113
|
}
|
|
114
|
-
class
|
|
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(
|
|
121
|
-
typeof
|
|
122
|
-
const n =
|
|
123
|
-
if (typeof n != "function" ||
|
|
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(
|
|
125
|
+
const o = !e || e.length === 0 ? "all" : e, c = this.saveStateSnapshot(i, t, o);
|
|
126
126
|
try {
|
|
127
|
-
await n.apply(
|
|
127
|
+
await n.apply(i, r);
|
|
128
128
|
} catch (a) {
|
|
129
|
-
throw this.patchStore(c,
|
|
129
|
+
throw this.patchStore(c, i), a;
|
|
130
130
|
} finally {
|
|
131
131
|
this.removeStateSnapshot(c);
|
|
132
132
|
}
|
|
133
133
|
});
|
|
134
134
|
}
|
|
135
|
-
createOnActionCallbacks(
|
|
135
|
+
createOnActionCallbacks(i, t) {
|
|
136
136
|
const e = this._storeRollbackSnapshotsParams.get(
|
|
137
|
-
|
|
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,
|
|
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:
|
|
152
|
-
const e =
|
|
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
|
-
|
|
156
|
+
S(r, t),
|
|
157
157
|
n
|
|
158
158
|
);
|
|
159
159
|
}), this._storeHasRollbackSnapshots.add(t.$id)), this.addRollbackAction(t);
|
|
160
160
|
}
|
|
161
|
-
clearStoreTracking(
|
|
162
|
-
const t =
|
|
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(
|
|
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(
|
|
170
|
-
const e = this._stateSnapshots.get(
|
|
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(
|
|
175
|
+
console.error(`Failed to patch store with snapshot ${String(i)}`, r);
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
|
-
removeStateSnapshot(
|
|
179
|
-
|
|
178
|
+
removeStateSnapshot(i) {
|
|
179
|
+
i && this._stateSnapshots.delete(i);
|
|
180
180
|
}
|
|
181
|
-
saveStateSnapshot(
|
|
182
|
-
const r =
|
|
183
|
-
|
|
181
|
+
saveStateSnapshot(i, t, e) {
|
|
182
|
+
const r = D(
|
|
183
|
+
i.$state,
|
|
184
184
|
e
|
|
185
|
-
), n = Symbol(
|
|
185
|
+
), n = Symbol(S(t, i));
|
|
186
186
|
return this._stateSnapshots.set(n, r), n;
|
|
187
187
|
}
|
|
188
|
-
storeHasRollbackSnapshots(
|
|
189
|
-
return this._storeHasRollbackSnapshots.has(
|
|
188
|
+
storeHasRollbackSnapshots(i) {
|
|
189
|
+
return this._storeHasRollbackSnapshots.has(i.$id);
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
|
-
class
|
|
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(
|
|
203
|
-
this._traceOptions.addClassNameToLabel =
|
|
202
|
+
set classNameAddedToTraceNamespace(i) {
|
|
203
|
+
this._traceOptions.addClassNameToLabel = i;
|
|
204
204
|
}
|
|
205
205
|
get tracer() {
|
|
206
206
|
return this._tracer;
|
|
207
207
|
}
|
|
208
|
-
trace(
|
|
208
|
+
trace(i, t, e, r) {
|
|
209
209
|
const n = this.tracer;
|
|
210
|
-
n && (
|
|
210
|
+
n && (i = this.traceLabelFormatter(i), n.debug(i, r ?? i.toLowerCase(), e, t));
|
|
211
211
|
}
|
|
212
|
-
traceError(
|
|
212
|
+
traceError(i, t, e, r, n) {
|
|
213
213
|
const o = this.tracer;
|
|
214
|
-
o ? (
|
|
214
|
+
o ? (i = this.traceLabelFormatter(i), o.error(i, n ?? i.toLowerCase(), t, r, e)) : console.error(t);
|
|
215
215
|
}
|
|
216
|
-
traceLabelFormatter(
|
|
217
|
-
return this.classNameAddedToTraceNamespace ? `${this._className}:${
|
|
216
|
+
traceLabelFormatter(i) {
|
|
217
|
+
return this.classNameAddedToTraceNamespace ? `${this._className}:${i}` : i;
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
|
-
function
|
|
221
|
-
return
|
|
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
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
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
|
-
},
|
|
232
|
-
function
|
|
234
|
+
}, B = 2500;
|
|
235
|
+
function J(s) {
|
|
233
236
|
if (typeof window < "u" && typeof window.requestAnimationFrame == "function") {
|
|
234
|
-
window.requestAnimationFrame(() => globalThis.setTimeout(
|
|
237
|
+
window.requestAnimationFrame(() => globalThis.setTimeout(s, 0));
|
|
235
238
|
return;
|
|
236
239
|
}
|
|
237
|
-
globalThis.setTimeout(
|
|
240
|
+
globalThis.setTimeout(s, 0);
|
|
238
241
|
}
|
|
239
|
-
class
|
|
242
|
+
class it extends q {
|
|
240
243
|
constructor(t, e) {
|
|
241
244
|
super();
|
|
242
|
-
u(this, "_className",
|
|
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
|
|
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 ??
|
|
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 (!
|
|
272
|
+
if (!M(this._subscriptions))
|
|
269
273
|
return this._subscriptions;
|
|
270
274
|
}
|
|
271
275
|
addOnActionAfterCallback(t, e, r) {
|
|
272
|
-
const n =
|
|
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 =
|
|
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 =
|
|
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
|
-
...
|
|
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
|
|
353
|
+
return k(t.name, e);
|
|
337
354
|
}
|
|
338
355
|
defineSubscriptionKey(t, e) {
|
|
339
|
-
return
|
|
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.
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
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
|
|
380
|
+
const b = S(c, t);
|
|
359
381
|
this._storeRollbackSnapshotsHandler.storeHasRollbackSnapshots(t) && this.createRollbackSnapshot(c, t);
|
|
360
|
-
const
|
|
361
|
-
h.forEach((
|
|
362
|
-
const
|
|
363
|
-
() =>
|
|
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
|
-
|
|
373
|
-
}), this.endGroupAfter(
|
|
374
|
-
} catch (
|
|
375
|
-
throw
|
|
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
|
-
|
|
380
|
-
|
|
381
|
-
|
|
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
|
-
|
|
402
|
-
|
|
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
|
|
408
|
-
() => h
|
|
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(
|
|
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
|
|
418
|
-
|
|
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:
|
|
423
|
-
groupId:
|
|
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
|
|
429
|
-
() => h
|
|
436
|
+
const d = a.map((p) => this.runCallbackSafely(
|
|
437
|
+
() => p(h),
|
|
430
438
|
"store:onAction:onError:error",
|
|
431
439
|
r.$id,
|
|
432
|
-
() => ({ groupId:
|
|
440
|
+
() => ({ actionId: o, groupId: l.onActionError(r.$id, n, c) })
|
|
433
441
|
));
|
|
434
|
-
this.endGroupAfter(
|
|
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(
|
|
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
|
-
|
|
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
|
-
(
|
|
493
|
-
const
|
|
494
|
-
if (!(this._subscribersDelivered.has(
|
|
495
|
-
if (this.shouldScheduleAfterHydration(
|
|
496
|
-
this.queueSubscriberExecution({ store: t, options: e },
|
|
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 },
|
|
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 (
|
|
504
|
-
this.traceError("plugin:invoke",
|
|
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
|
|
517
|
-
let
|
|
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
|
-
|
|
524
|
+
h = this.executeSubscriberSafely(t, e);
|
|
520
525
|
} finally {
|
|
521
|
-
|
|
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 =
|
|
537
|
+
const r = f(e);
|
|
546
538
|
t.$reset = () => {
|
|
547
|
-
|
|
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(
|
|
542
|
+
this.executeResetStoreCallbacks(t), t.$patch(f(r));
|
|
550
543
|
} finally {
|
|
551
|
-
this.traceGroupEnd(() => ({
|
|
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
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
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)),
|
|
620
|
-
(
|
|
621
|
-
store:
|
|
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
|
-
...
|
|
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
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
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
|