pinia-plugin-subscription 0.2.0 → 1.0.0-beta.0
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 +40 -1
- package/README.md +249 -3
- package/SECURITY.md +19 -1
- package/dist/chunks/constantes-BsD73jkk.js +245 -0
- package/dist/chunks/constantes-BsD73jkk.js.map +1 -0
- package/dist/core/PluginSubscriber.d.ts +36 -8
- package/dist/core/PluginSubscription.d.ts +22 -5
- package/dist/core/Store.d.ts +92 -11
- package/dist/factories/trace-registry.d.ts +6 -0
- package/dist/helpers/index.d.ts +5 -0
- package/dist/helpers.js +181 -5
- package/dist/helpers.js.map +1 -1
- package/dist/lib/main.d.ts +1 -3
- package/dist/pinia-plugin-subscription.js +239 -240
- package/dist/pinia-plugin-subscription.js.map +1 -1
- package/dist/plugins/createHydrationPlugin.d.ts +7 -0
- package/dist/plugins/createPlugin.d.ts +9 -2
- package/dist/system/Tracer.d.ts +20 -0
- package/dist/system/createConsoleTraceListener.d.ts +6 -0
- package/dist/types/index.d.ts +16 -5
- package/dist/types/plugin.d.ts +45 -6
- package/dist/types/store.d.ts +12 -7
- package/dist/types/trace.d.ts +80 -0
- package/docs/authoring-plugins.md +23 -24
- package/docs/using-plugins.md +59 -21
- package/package.json +5 -2
- package/dist/chunks/index-VL_PgzVK.js +0 -337
- package/dist/chunks/index-VL_PgzVK.js.map +0 -1
- package/dist/system/Debug.d.ts +0 -13
|
@@ -1,179 +1,177 @@
|
|
|
1
|
-
var
|
|
2
|
-
var E = (
|
|
3
|
-
var
|
|
4
|
-
import { h as O, g as
|
|
5
|
-
import {
|
|
6
|
-
import { toRaw as
|
|
7
|
-
function
|
|
1
|
+
var k = Object.defineProperty;
|
|
2
|
+
var E = (r, t, e) => t in r ? k(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
|
|
3
|
+
var c = (r, t, e) => E(r, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
+
import { h as O, g as b, i as _ } from "./chunks/constantes-BsD73jkk.js";
|
|
5
|
+
import { p as K, P as M, S as x, d as F, a as W, b as I, c as q, e as z, s as G } from "./chunks/constantes-BsD73jkk.js";
|
|
6
|
+
import { toRaw as y } from "vue";
|
|
7
|
+
function h(r) {
|
|
8
8
|
if (typeof structuredClone == "function")
|
|
9
9
|
try {
|
|
10
|
-
return structuredClone(
|
|
10
|
+
return structuredClone(r);
|
|
11
11
|
} catch {
|
|
12
12
|
}
|
|
13
|
-
if (
|
|
14
|
-
return
|
|
15
|
-
if (
|
|
13
|
+
if (r === null || typeof r != "object")
|
|
14
|
+
return r;
|
|
15
|
+
if (r instanceof Map)
|
|
16
16
|
return new Map(
|
|
17
|
-
Array.from(
|
|
17
|
+
Array.from(r.entries(), ([e, i]) => [h(e), h(i)])
|
|
18
18
|
);
|
|
19
|
-
if (
|
|
20
|
-
return new Set(Array.from(
|
|
21
|
-
if (Array.isArray(
|
|
22
|
-
return
|
|
23
|
-
if (Object.getPrototypeOf(
|
|
19
|
+
if (r instanceof Set)
|
|
20
|
+
return new Set(Array.from(r.values(), (e) => h(e)));
|
|
21
|
+
if (Array.isArray(r))
|
|
22
|
+
return r.map((e) => h(e));
|
|
23
|
+
if (Object.getPrototypeOf(r) === Object.prototype || Object.getPrototypeOf(r) === null)
|
|
24
24
|
return Object.fromEntries(
|
|
25
|
-
Object.entries(
|
|
25
|
+
Object.entries(r).map(([e, i]) => [e, h(i)])
|
|
26
26
|
);
|
|
27
|
-
const
|
|
28
|
-
for (const [
|
|
29
|
-
|
|
30
|
-
return
|
|
27
|
+
const t = Object.create(Object.getPrototypeOf(r));
|
|
28
|
+
for (const [e, i] of Object.entries(r))
|
|
29
|
+
t[e] = h(i);
|
|
30
|
+
return t;
|
|
31
31
|
}
|
|
32
|
-
function
|
|
33
|
-
if (Array.isArray(
|
|
34
|
-
const
|
|
35
|
-
for (const
|
|
36
|
-
|
|
37
|
-
return
|
|
38
|
-
}
|
|
39
|
-
if (
|
|
40
|
-
throw new Error(`Invalid keys parameter: ${
|
|
41
|
-
return
|
|
32
|
+
function g(r, t = "all") {
|
|
33
|
+
if (Array.isArray(t)) {
|
|
34
|
+
const e = {};
|
|
35
|
+
for (const i of t)
|
|
36
|
+
i in r && (e[i] = h(y(r[i])));
|
|
37
|
+
return e;
|
|
38
|
+
}
|
|
39
|
+
if (t !== "all")
|
|
40
|
+
throw new Error(`Invalid keys parameter: ${t}`);
|
|
41
|
+
return h(y(r));
|
|
42
42
|
}
|
|
43
|
-
class
|
|
43
|
+
class $ {
|
|
44
44
|
constructor() {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
addRollbackAction(
|
|
50
|
-
typeof
|
|
51
|
-
const
|
|
52
|
-
if (typeof
|
|
45
|
+
c(this, "_stateSnapshots", /* @__PURE__ */ new Map());
|
|
46
|
+
c(this, "_storeHasRollbackSnapshots", /* @__PURE__ */ new Set());
|
|
47
|
+
c(this, "_storeRollbackSnapshotsParams", /* @__PURE__ */ new Map());
|
|
48
|
+
}
|
|
49
|
+
addRollbackAction(t) {
|
|
50
|
+
typeof t.$rollbackAfterFailure != "function" && (t.$rollbackAfterFailure = async ({ action: e, stateKeys: i }, s = []) => {
|
|
51
|
+
const n = t[e];
|
|
52
|
+
if (typeof n != "function" || O(e))
|
|
53
53
|
return;
|
|
54
|
-
const o = !
|
|
54
|
+
const o = !i || i.length === 0 ? "all" : i, a = this.saveStateSnapshot(t, e, o);
|
|
55
55
|
try {
|
|
56
|
-
await
|
|
57
|
-
} catch (
|
|
58
|
-
throw this.patchStore(
|
|
56
|
+
await n.apply(t, s);
|
|
57
|
+
} catch (l) {
|
|
58
|
+
throw this.patchStore(a, t), l;
|
|
59
59
|
} finally {
|
|
60
|
-
this.removeStateSnapshot(
|
|
60
|
+
this.removeStateSnapshot(a);
|
|
61
61
|
}
|
|
62
62
|
});
|
|
63
63
|
}
|
|
64
|
-
createOnActionCallbacks(
|
|
65
|
-
const
|
|
66
|
-
|
|
64
|
+
createOnActionCallbacks(t, e) {
|
|
65
|
+
const i = this._storeRollbackSnapshotsParams.get(
|
|
66
|
+
b(t, e)
|
|
67
67
|
);
|
|
68
|
-
if (!
|
|
68
|
+
if (!i)
|
|
69
69
|
return;
|
|
70
|
-
const i = this.saveStateSnapshot(t, s
|
|
70
|
+
const s = i.length === 0 ? "all" : i, n = this.saveStateSnapshot(e, t, s);
|
|
71
71
|
return {
|
|
72
72
|
after: () => {
|
|
73
|
-
this.removeStateSnapshot(
|
|
73
|
+
this.removeStateSnapshot(n);
|
|
74
74
|
},
|
|
75
75
|
onError: () => {
|
|
76
|
-
this.patchStore(
|
|
76
|
+
this.patchStore(n, e), this.removeStateSnapshot(n);
|
|
77
77
|
}
|
|
78
78
|
};
|
|
79
79
|
}
|
|
80
|
-
initFromPluginContext({ options:
|
|
81
|
-
const
|
|
82
|
-
|
|
80
|
+
initFromPluginContext({ options: t, store: e }) {
|
|
81
|
+
const i = t?.storeOptions?.rollbackAfterFailure;
|
|
82
|
+
i && !this._storeHasRollbackSnapshots.has(e.$id) && (Object.keys(i).forEach((s) => {
|
|
83
83
|
this._storeRollbackSnapshotsParams.set(
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
b(s, e),
|
|
85
|
+
i[s]
|
|
86
86
|
);
|
|
87
|
-
}), this._storeHasRollbackSnapshots.add(
|
|
88
|
-
}
|
|
89
|
-
clearStoreTracking(
|
|
90
|
-
const
|
|
91
|
-
for (const
|
|
92
|
-
|
|
93
|
-
this._storeHasRollbackSnapshots.delete(
|
|
94
|
-
for (const
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
patchStore(
|
|
98
|
-
const
|
|
99
|
-
if (
|
|
87
|
+
}), this._storeHasRollbackSnapshots.add(e.$id)), this.addRollbackAction(e);
|
|
88
|
+
}
|
|
89
|
+
clearStoreTracking(t) {
|
|
90
|
+
const e = `-${t.$id}`;
|
|
91
|
+
for (const i of Array.from(this._storeRollbackSnapshotsParams.keys()))
|
|
92
|
+
i.endsWith(e) && this._storeRollbackSnapshotsParams.delete(i);
|
|
93
|
+
this._storeHasRollbackSnapshots.delete(t.$id);
|
|
94
|
+
for (const i of Array.from(this._stateSnapshots.keys()))
|
|
95
|
+
i.description?.startsWith(`${t.$id}:`) && this._stateSnapshots.delete(i);
|
|
96
|
+
}
|
|
97
|
+
patchStore(t, e) {
|
|
98
|
+
const i = this._stateSnapshots.get(t);
|
|
99
|
+
if (i)
|
|
100
100
|
try {
|
|
101
|
-
|
|
102
|
-
} catch (
|
|
103
|
-
console.error(`Failed to patch store with snapshot ${String(
|
|
101
|
+
e.$patch(i);
|
|
102
|
+
} catch (s) {
|
|
103
|
+
console.error(`Failed to patch store with snapshot ${String(t)}`, s);
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
|
-
removeStateSnapshot(
|
|
107
|
-
|
|
106
|
+
removeStateSnapshot(t) {
|
|
107
|
+
t && this._stateSnapshots.delete(t);
|
|
108
108
|
}
|
|
109
|
-
saveStateSnapshot(
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
),
|
|
114
|
-
return this._stateSnapshots.set(
|
|
109
|
+
saveStateSnapshot(t, e, i) {
|
|
110
|
+
const s = g(
|
|
111
|
+
t.$state,
|
|
112
|
+
i
|
|
113
|
+
), n = /* @__PURE__ */ Symbol(`${t.$id}:${e}`);
|
|
114
|
+
return this._stateSnapshots.set(n, s), n;
|
|
115
115
|
}
|
|
116
|
-
storeHasRollbackSnapshots(
|
|
117
|
-
return this._storeHasRollbackSnapshots.has(
|
|
116
|
+
storeHasRollbackSnapshots(t) {
|
|
117
|
+
return this._storeHasRollbackSnapshots.has(t.$id);
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
|
-
const
|
|
120
|
+
const m = "PluginSubscription", C = {
|
|
121
121
|
environment: "both",
|
|
122
122
|
hydration: "immediate"
|
|
123
123
|
};
|
|
124
|
-
function
|
|
124
|
+
function w(r) {
|
|
125
125
|
if (typeof window < "u" && typeof window.requestAnimationFrame == "function") {
|
|
126
|
-
window.requestAnimationFrame(() => globalThis.setTimeout(
|
|
126
|
+
window.requestAnimationFrame(() => globalThis.setTimeout(r, 0));
|
|
127
127
|
return;
|
|
128
128
|
}
|
|
129
|
-
globalThis.setTimeout(
|
|
129
|
+
globalThis.setTimeout(r, 0);
|
|
130
130
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
a(this, "_subscriptionsDelivered", /* @__PURE__ */ new Set());
|
|
152
|
-
a(this, "_subscriptionsScheduled", /* @__PURE__ */ new Set());
|
|
153
|
-
this._hydrationScheduler = o?.hydrationScheduler ?? R, this._options = o, this._pluginDebug = Array.isArray(r) ? r : void 0, this._subscribers = t;
|
|
131
|
+
class A {
|
|
132
|
+
constructor(t, e) {
|
|
133
|
+
c(this, "_className", m);
|
|
134
|
+
c(this, "_hydrationScheduler");
|
|
135
|
+
c(this, "_onActionSubscriptions", /* @__PURE__ */ new Map());
|
|
136
|
+
c(this, "_onActionStores", /* @__PURE__ */ new Set());
|
|
137
|
+
c(this, "_onActionAfterSubscriptions", {});
|
|
138
|
+
c(this, "_onActionOnErrorSubscriptions", {});
|
|
139
|
+
c(this, "_options");
|
|
140
|
+
c(this, "_resetStoreCallback", /* @__PURE__ */ new Map());
|
|
141
|
+
c(this, "_disposedStores", /* @__PURE__ */ new WeakSet());
|
|
142
|
+
c(this, "_storeRollbackSnapshotsHandler", new $());
|
|
143
|
+
c(this, "_subscribers", []);
|
|
144
|
+
c(this, "_subscribersDelivered", /* @__PURE__ */ new Set());
|
|
145
|
+
c(this, "_subscribersScheduled", /* @__PURE__ */ new Set());
|
|
146
|
+
c(this, "_subscriptions", []);
|
|
147
|
+
c(this, "_subscriptionsDelivered", /* @__PURE__ */ new Set());
|
|
148
|
+
c(this, "_subscriptionsScheduled", /* @__PURE__ */ new Set());
|
|
149
|
+
c(this, "_tracer");
|
|
150
|
+
this._hydrationScheduler = e?.hydrationScheduler ?? w, this._options = e, this._subscribers = t, this.initializeTracer();
|
|
154
151
|
}
|
|
155
152
|
set subscribers(t) {
|
|
156
153
|
this._subscribers = t;
|
|
157
154
|
}
|
|
158
155
|
get subscriptions() {
|
|
159
|
-
if (!
|
|
156
|
+
if (!_(this._subscriptions))
|
|
160
157
|
return this._subscriptions;
|
|
161
158
|
}
|
|
162
159
|
addOnActionAfterCallback(t, e, i) {
|
|
163
|
-
const
|
|
164
|
-
this._onActionAfterSubscriptions[
|
|
160
|
+
const s = b(t, e);
|
|
161
|
+
this._onActionAfterSubscriptions[s] || (this._onActionAfterSubscriptions[s] = []), this._onActionAfterSubscriptions[s]?.push(i);
|
|
165
162
|
}
|
|
166
163
|
addOnActionOnErrorCallback(t, e, i) {
|
|
167
|
-
const
|
|
168
|
-
this._onActionOnErrorSubscriptions[
|
|
164
|
+
const s = b(t, e);
|
|
165
|
+
this._onActionOnErrorSubscriptions[s] || (this._onActionOnErrorSubscriptions[s] = []), this._onActionOnErrorSubscriptions[s]?.push(i);
|
|
169
166
|
}
|
|
170
|
-
addResetStoreCallback(t) {
|
|
171
|
-
this._resetStoreCallback.
|
|
167
|
+
addResetStoreCallback(t, e) {
|
|
168
|
+
this._resetStoreCallback.has(t) || this._resetStoreCallback.set(t, /* @__PURE__ */ new Set()), this._resetStoreCallback.get(t).add(e);
|
|
172
169
|
}
|
|
173
170
|
clearOnActionCallbacksSubscriptions(t) {
|
|
174
171
|
delete this._onActionAfterSubscriptions[t], delete this._onActionOnErrorSubscriptions[t];
|
|
175
172
|
}
|
|
176
173
|
clearStoreTracking(t) {
|
|
174
|
+
this._onActionSubscriptions.delete(t), this._onActionStores.delete(t), this._resetStoreCallback.delete(t);
|
|
177
175
|
const e = `-${t.$id}`;
|
|
178
176
|
for (const i of Array.from(this._subscribersDelivered))
|
|
179
177
|
i.endsWith(e) && this._subscribersDelivered.delete(i);
|
|
@@ -201,22 +199,19 @@ class k extends m {
|
|
|
201
199
|
createRollbackSnapshot(t, e) {
|
|
202
200
|
const {
|
|
203
201
|
after: i,
|
|
204
|
-
onError:
|
|
202
|
+
onError: s
|
|
205
203
|
} = this._storeRollbackSnapshotsHandler.createOnActionCallbacks(
|
|
206
204
|
t,
|
|
207
205
|
e
|
|
208
206
|
) ?? {};
|
|
209
|
-
!i || !
|
|
207
|
+
!i || !s || (this.addOnActionAfterCallback(t, e, i), this.addOnActionOnErrorCallback(t, e, s));
|
|
210
208
|
}
|
|
211
209
|
defineCurrentEnvironment() {
|
|
212
210
|
return this._options?.runtimeEnvironment ?? (typeof window > "u" ? "server" : "client");
|
|
213
211
|
}
|
|
214
|
-
definePluginDebug(t) {
|
|
215
|
-
return !!this._pluginDebug?.includes(t.name);
|
|
216
|
-
}
|
|
217
212
|
definePluginExecution(t) {
|
|
218
213
|
return {
|
|
219
|
-
...
|
|
214
|
+
...C,
|
|
220
215
|
...this._options?.execution ?? {},
|
|
221
216
|
...t.execution ?? {},
|
|
222
217
|
...this._options?.subscriberExecution?.[t.name] ?? {}
|
|
@@ -232,75 +227,80 @@ class k extends m {
|
|
|
232
227
|
return `${t}-${e.$id}`;
|
|
233
228
|
}
|
|
234
229
|
executeResetStoreCallbacks(t) {
|
|
235
|
-
this._resetStoreCallback.forEach((e) => e(t));
|
|
230
|
+
this._resetStoreCallback.get(t)?.forEach((e) => e(t));
|
|
236
231
|
}
|
|
237
232
|
executeStoreOnActionSubscription(t) {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
233
|
+
if (this._onActionStores.has(t) || typeof t.$onAction != "function")
|
|
234
|
+
return;
|
|
235
|
+
const e = this._onActionSubscriptions.get(t), i = this._storeRollbackSnapshotsHandler.storeHasRollbackSnapshots(t);
|
|
236
|
+
!e?.size && !i || (this._onActionStores.add(t), t.$onAction(({ after: s, args: n, name: o, onError: a }) => {
|
|
237
|
+
const l = b(o, t);
|
|
238
|
+
this.trace("plugin:onAction", () => ({
|
|
239
|
+
args: n,
|
|
240
|
+
name: o,
|
|
241
|
+
store: t
|
|
242
|
+
}), t.$id), this._storeRollbackSnapshotsHandler.storeHasRollbackSnapshots(t) && this.createRollbackSnapshot(o, t);
|
|
243
|
+
const u = this._onActionSubscriptions.get(t);
|
|
244
|
+
u?.size && u.forEach((d) => d({
|
|
245
|
+
after: this.createOnActionAfterCallbackCollector(o, t),
|
|
246
|
+
args: n,
|
|
247
|
+
name: o,
|
|
248
|
+
onError: this.createOnActionOnErrorCallbackCollector(o, t)
|
|
246
249
|
}));
|
|
247
|
-
const
|
|
248
|
-
this.clearOnActionCallbacksSubscriptions(l),
|
|
249
|
-
|
|
250
|
-
}),
|
|
251
|
-
|
|
250
|
+
const f = this._onActionAfterSubscriptions[l], p = this._onActionOnErrorSubscriptions[l];
|
|
251
|
+
this.clearOnActionCallbacksSubscriptions(l), f?.length && s((d) => {
|
|
252
|
+
f.forEach((S) => S(d));
|
|
253
|
+
}), p?.length && a((d) => {
|
|
254
|
+
p.forEach((S) => S(d));
|
|
252
255
|
});
|
|
253
|
-
});
|
|
256
|
+
}));
|
|
254
257
|
}
|
|
255
258
|
executeSubscriber(t, e) {
|
|
256
|
-
const i = this.defineSubscriberKey(e, t.store)
|
|
257
|
-
if (this._subscribersDelivered.has(i) || !e.invoke(
|
|
258
|
-
t,
|
|
259
|
-
r
|
|
260
|
-
))
|
|
259
|
+
const i = this.defineSubscriberKey(e, t.store);
|
|
260
|
+
if (this._subscribersDelivered.has(i) || !e.invoke(t, this._options?.createTracer))
|
|
261
261
|
return;
|
|
262
262
|
this._subscribersDelivered.add(i);
|
|
263
|
-
let
|
|
263
|
+
let s;
|
|
264
264
|
try {
|
|
265
|
-
|
|
266
|
-
} catch (
|
|
267
|
-
this.
|
|
265
|
+
s = e.hydrate?.(t);
|
|
266
|
+
} catch (o) {
|
|
267
|
+
this.traceError("subscriber:hydrate", o, () => ({ store: t.store, options: t.options }), t.store.$id);
|
|
268
268
|
return;
|
|
269
269
|
}
|
|
270
|
-
const
|
|
270
|
+
const n = () => {
|
|
271
271
|
try {
|
|
272
|
-
const
|
|
273
|
-
|
|
274
|
-
} catch (
|
|
275
|
-
this.
|
|
272
|
+
const o = e.afterHydration?.(t);
|
|
273
|
+
o && typeof o.then == "function" && o.catch((a) => this.traceError("subscriber:afterHydration", a, () => ({ store: t.store, options: t.options }), t.store.$id));
|
|
274
|
+
} catch (o) {
|
|
275
|
+
this.traceError("subscriber:afterHydration", o, () => ({ store: t.store, options: t.options }), t.store.$id);
|
|
276
276
|
}
|
|
277
277
|
};
|
|
278
|
-
|
|
278
|
+
s && typeof s.then == "function" ? s.then(() => n()).catch((o) => this.traceError("subscriber:hydrate", o, () => ({ store: t.store, options: t.options }), t.store.$id)) : n(), e.subscriptions && this.subscriptionDelivery(t, e.subscriptions), e.storeMutationSubscription && this.storeMutationSubscription(e.storeMutationSubscription), this.storeOnActionSubscription(e), e.resetStoreCallback && this.addResetStoreCallback(t.store, e.resetStoreCallback);
|
|
279
279
|
}
|
|
280
280
|
executeSubscriberSafely(t, e) {
|
|
281
281
|
try {
|
|
282
282
|
this.executeSubscriber(t, e);
|
|
283
283
|
} catch (i) {
|
|
284
|
-
this.
|
|
284
|
+
this.traceError("subscriber:execute", i, () => ({ store: t.store, options: t.options }), t.store.$id);
|
|
285
285
|
}
|
|
286
286
|
}
|
|
287
|
+
initializeTracer() {
|
|
288
|
+
this._options?.createTracer && (this._tracer = this._options.createTracer("PluginSubscription"));
|
|
289
|
+
}
|
|
287
290
|
plugin({ store: t, options: e }) {
|
|
288
291
|
if (this._subscribers.length) {
|
|
289
|
-
this.
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
"options:",
|
|
295
|
-
e
|
|
296
|
-
]);
|
|
292
|
+
this.trace("plugin:invoke", () => ({
|
|
293
|
+
subscribers: this._subscribers,
|
|
294
|
+
store: t,
|
|
295
|
+
options: e
|
|
296
|
+
}), t.$id);
|
|
297
297
|
try {
|
|
298
298
|
this._subscribers.forEach(
|
|
299
299
|
(i) => {
|
|
300
|
-
const
|
|
301
|
-
if (!(this._subscribersDelivered.has(
|
|
302
|
-
if (this.shouldScheduleAfterHydration(
|
|
303
|
-
this.queueSubscriberExecution({ store: t, options: e }, i,
|
|
300
|
+
const s = this.defineSubscriberKey(i, t), n = this.definePluginExecution(i);
|
|
301
|
+
if (!(this._subscribersDelivered.has(s) || this._subscribersScheduled.has(s)) && this.shouldInvokePlugin(n)) {
|
|
302
|
+
if (this.shouldScheduleAfterHydration(n)) {
|
|
303
|
+
this.queueSubscriberExecution({ store: t, options: e }, i, s);
|
|
304
304
|
return;
|
|
305
305
|
}
|
|
306
306
|
this.executeSubscriber({ store: t, options: e }, i);
|
|
@@ -308,26 +308,29 @@ class k extends m {
|
|
|
308
308
|
}
|
|
309
309
|
), this.rewriteResetStore({ store: t }, t.$state), this._storeRollbackSnapshotsHandler.initFromPluginContext({ store: t, options: e }), this.executeStoreOnActionSubscription(t), this.registerStoreCleanup(t);
|
|
310
310
|
} catch (i) {
|
|
311
|
-
this.
|
|
311
|
+
this.traceError("plugin:invoke", i, () => ({ store: t, options: e }), t.$id);
|
|
312
312
|
}
|
|
313
313
|
}
|
|
314
314
|
}
|
|
315
315
|
queueSubscriberExecution(t, e, i) {
|
|
316
|
-
const
|
|
317
|
-
this._subscribersScheduled.add(i),
|
|
318
|
-
this._subscribersScheduled.delete(i), this.executeSubscriberSafely(t, e);
|
|
316
|
+
const s = this.defineHydrationScheduler(e);
|
|
317
|
+
this._subscribersScheduled.add(i), s(() => {
|
|
318
|
+
this._disposedStores.has(t.store) || (this._subscribersScheduled.delete(i), this.executeSubscriberSafely(t, e));
|
|
319
319
|
});
|
|
320
320
|
}
|
|
321
321
|
registerStoreCleanup(t) {
|
|
322
|
-
if (
|
|
322
|
+
if (typeof t.$dispose != "function")
|
|
323
323
|
return;
|
|
324
324
|
const e = t.$dispose.bind(t), i = t;
|
|
325
|
-
i.__piniaPluginSubscriptionDisposed || (i.__piniaPluginSubscriptionDisposed = !0, t.$dispose = () => (this.clearStoreTracking(t), this._storeRollbackSnapshotsHandler.clearStoreTracking(t), e()));
|
|
325
|
+
i.__piniaPluginSubscriptionDisposed || (i.__piniaPluginSubscriptionDisposed = !0, t.$dispose = () => (this._disposedStores.add(t), this.clearStoreTracking(t), this._storeRollbackSnapshotsHandler.clearStoreTracking(t), e()));
|
|
326
326
|
}
|
|
327
327
|
rewriteResetStore({ store: t }, e) {
|
|
328
|
-
const i =
|
|
328
|
+
const i = h(e);
|
|
329
329
|
t.$reset = () => {
|
|
330
|
-
this.
|
|
330
|
+
this.trace("plugin:reset", () => ({
|
|
331
|
+
initState: i,
|
|
332
|
+
store: t
|
|
333
|
+
}), t.$id), this.executeResetStoreCallbacks(t), t.$patch(h(i));
|
|
331
334
|
};
|
|
332
335
|
}
|
|
333
336
|
shouldInvokePlugin(t) {
|
|
@@ -339,95 +342,91 @@ class k extends m {
|
|
|
339
342
|
}
|
|
340
343
|
storeOnActionSubscription(t) {
|
|
341
344
|
const { store: e, callback: i } = t?.storeOnActionSubscription?.() ?? {};
|
|
342
|
-
!e || !i || this._onActionSubscriptions.
|
|
345
|
+
!e || !i || (this._onActionSubscriptions.has(e) || this._onActionSubscriptions.set(e, /* @__PURE__ */ new Set()), this._onActionSubscriptions.get(e).add(i), this.executeStoreOnActionSubscription(e));
|
|
343
346
|
}
|
|
344
347
|
storeMutationSubscription(t) {
|
|
345
348
|
const { store: e, callback: i } = t();
|
|
346
|
-
e.$subscribe((
|
|
347
|
-
this.
|
|
349
|
+
e.$subscribe((s) => {
|
|
350
|
+
this.trace("store:mutation", () => ({ mutation: s, store: e }), e.$id), i(s);
|
|
348
351
|
});
|
|
349
352
|
}
|
|
350
353
|
subscriptionDelivery(t, e) {
|
|
351
|
-
Object.entries(e).forEach(([i,
|
|
352
|
-
const
|
|
353
|
-
if (!(this._subscriptionsDelivered.has(
|
|
354
|
-
if (this.shouldScheduleAfterHydration(
|
|
355
|
-
const
|
|
356
|
-
this._subscriptionsScheduled.add(
|
|
357
|
-
this._subscriptionsScheduled.delete(
|
|
354
|
+
Object.entries(e).forEach(([i, s]) => {
|
|
355
|
+
const n = this.defineSubscriptionKey(i, t.store), o = this.definePluginExecution(s.subscription);
|
|
356
|
+
if (!(this._subscriptionsDelivered.has(n) || this._subscriptionsScheduled.has(n)) && this.shouldInvokePlugin(o)) {
|
|
357
|
+
if (this.shouldScheduleAfterHydration(o)) {
|
|
358
|
+
const a = this.defineHydrationScheduler(s.subscription);
|
|
359
|
+
this._subscriptionsScheduled.add(n), a(() => {
|
|
360
|
+
this._disposedStores.has(t.store) || (this._subscriptionsScheduled.delete(n), this.subscriptionDeliverySafely(t, i, s));
|
|
358
361
|
});
|
|
359
362
|
return;
|
|
360
363
|
}
|
|
361
|
-
this.subscriptionDeliverySafely(t, i,
|
|
364
|
+
this.subscriptionDeliverySafely(t, i, s);
|
|
362
365
|
}
|
|
363
366
|
});
|
|
364
367
|
}
|
|
365
|
-
subscriptionDeliverySafely({ store: t, options: e }, i,
|
|
368
|
+
subscriptionDeliverySafely({ store: t, options: e }, i, s) {
|
|
366
369
|
try {
|
|
367
370
|
if (this._subscriptionsDelivered.has(this.defineSubscriptionKey(i, t)))
|
|
368
371
|
return;
|
|
369
|
-
const { subscription:
|
|
370
|
-
this.
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
r,
|
|
377
|
-
"stores:",
|
|
378
|
-
c
|
|
379
|
-
]);
|
|
372
|
+
const { subscription: n, subscriptionOptions: o, stores: a } = s;
|
|
373
|
+
this.trace("subscription:delivery", () => ({
|
|
374
|
+
pluginName: i,
|
|
375
|
+
subscription: n,
|
|
376
|
+
options: s,
|
|
377
|
+
stores: a
|
|
378
|
+
}), t.$id);
|
|
380
379
|
const l = {
|
|
381
|
-
storeOptions: { ...e?.storeOptions ?? {}, ...
|
|
380
|
+
storeOptions: { ...e?.storeOptions ?? {}, ...o }
|
|
382
381
|
};
|
|
383
|
-
|
|
384
|
-
{ store: t, options: { ...e, ...l } }
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
{
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
}
|
|
395
|
-
},
|
|
396
|
-
this.debug
|
|
397
|
-
)
|
|
382
|
+
n.invoke(
|
|
383
|
+
{ store: t, options: { ...e, ...l } }
|
|
384
|
+
), this._subscriptionsDelivered.add(this.defineSubscriptionKey(i, t)), _(a) || a?.forEach(
|
|
385
|
+
(u) => n.invoke({
|
|
386
|
+
store: u,
|
|
387
|
+
options: {
|
|
388
|
+
...e,
|
|
389
|
+
...l,
|
|
390
|
+
...u?.storeOptions ?? {}
|
|
391
|
+
}
|
|
392
|
+
})
|
|
398
393
|
);
|
|
399
|
-
} catch (
|
|
400
|
-
this.
|
|
394
|
+
} catch (n) {
|
|
395
|
+
this.traceError("subscription:delivery", n, () => ({ store: t, options: e }), t.$id);
|
|
401
396
|
}
|
|
402
397
|
}
|
|
398
|
+
trace(t, e, i) {
|
|
399
|
+
this._tracer && this._tracer.debug(t, e, i);
|
|
400
|
+
}
|
|
401
|
+
traceError(t, e, i, s) {
|
|
402
|
+
this._tracer ? this._tracer.error(t, e, i, s) : console.error(e);
|
|
403
|
+
}
|
|
403
404
|
}
|
|
404
|
-
function
|
|
405
|
-
const
|
|
406
|
-
return
|
|
405
|
+
function H(r, t) {
|
|
406
|
+
const e = new A(r, t);
|
|
407
|
+
return e.plugin.bind(e);
|
|
407
408
|
}
|
|
408
|
-
function
|
|
409
|
-
const
|
|
410
|
-
execution:
|
|
411
|
-
hydrationScheduler:
|
|
412
|
-
runtimeEnvironment:
|
|
413
|
-
subscriberExecution:
|
|
409
|
+
function D(r, t) {
|
|
410
|
+
const e = new A(r, {
|
|
411
|
+
execution: t?.execution,
|
|
412
|
+
hydrationScheduler: t?.hydrationScheduler,
|
|
413
|
+
runtimeEnvironment: t?.runtimeEnvironment,
|
|
414
|
+
subscriberExecution: t?.subscriberExecution
|
|
414
415
|
});
|
|
415
|
-
return
|
|
416
|
+
return e.plugin.bind(e);
|
|
416
417
|
}
|
|
417
418
|
export {
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
z as
|
|
429
|
-
|
|
430
|
-
y as isEmpty,
|
|
431
|
-
J as setEnhancedStore
|
|
419
|
+
K as PLUGIN_NAME,
|
|
420
|
+
M as PluginSubscriber,
|
|
421
|
+
A as PluginSubscription,
|
|
422
|
+
x as Store,
|
|
423
|
+
D as createHydrationPlugin,
|
|
424
|
+
H as createPlugin,
|
|
425
|
+
F as defineAStore,
|
|
426
|
+
W as defineAStoreCtx,
|
|
427
|
+
I as getDefineAStoreSetupContext,
|
|
428
|
+
q as getEnhancedStore,
|
|
429
|
+
z as getExtendingStore,
|
|
430
|
+
G as setEnhancedStore
|
|
432
431
|
};
|
|
433
432
|
//# sourceMappingURL=pinia-plugin-subscription.js.map
|