pinia-plugin-subscription 0.2.1 → 1.0.0-beta.1
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 +37 -1
- package/README.md +289 -4
- package/SECURITY.md +19 -1
- package/dist/chunks/Store-DHUAJv-P.js +257 -0
- package/dist/chunks/Store-DHUAJv-P.js.map +1 -0
- package/dist/core/PluginSubscriber.d.ts +39 -12
- package/dist/core/PluginSubscription.d.ts +20 -5
- package/dist/core/Store.d.ts +111 -12
- package/dist/factories/console-trace-listener.d.ts +7 -0
- package/dist/factories/trace-listener.d.ts +16 -0
- package/dist/factories/trace-registry.d.ts +17 -0
- package/dist/helpers/index.d.ts +5 -0
- package/dist/helpers.js +345 -5
- package/dist/helpers.js.map +1 -1
- package/dist/lib/main.d.ts +1 -3
- package/dist/pinia-plugin-subscription.js +208 -216
- 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/log.d.ts +12 -1
- package/dist/types/index.d.ts +17 -6
- package/dist/types/plugin.d.ts +119 -7
- package/dist/types/store.d.ts +3 -8
- package/dist/types/trace.d.ts +121 -0
- package/dist/utils/store.d.ts +2 -1
- package/docs/authoring-plugins.md +53 -24
- package/docs/using-plugins.md +76 -19
- package/package.json +3 -2
- package/dist/chunks/index-DKdl-fiq.js +0 -337
- package/dist/chunks/index-DKdl-fiq.js.map +0 -1
- package/dist/system/Debug.d.ts +0 -13
|
@@ -1,158 +1,153 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var c = (
|
|
4
|
-
import { h 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 _, p as g } from "./chunks/Store-DHUAJv-P.js";
|
|
5
|
+
import { P as M, S as x, d as F, a as W, b as I, c as q, e as z, s as L } from "./chunks/Store-DHUAJv-P.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 m(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 C {
|
|
44
44
|
constructor() {
|
|
45
45
|
c(this, "_stateSnapshots", /* @__PURE__ */ new Map());
|
|
46
46
|
c(this, "_storeHasRollbackSnapshots", /* @__PURE__ */ new Set());
|
|
47
47
|
c(this, "_storeRollbackSnapshotsParams", /* @__PURE__ */ new Map());
|
|
48
48
|
}
|
|
49
|
-
addRollbackAction(
|
|
50
|
-
typeof
|
|
51
|
-
const
|
|
52
|
-
if (typeof
|
|
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 (u) {
|
|
58
|
+
throw this.patchStore(a, t), u;
|
|
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
|
|
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 = m(
|
|
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 $ = "PluginSubscription", w = {
|
|
121
121
|
environment: "both",
|
|
122
122
|
hydration: "immediate"
|
|
123
123
|
};
|
|
124
|
-
function
|
|
124
|
+
function R(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(
|
|
130
|
-
}
|
|
131
|
-
function D(n) {
|
|
132
|
-
return n !== void 0 && !Array.isArray(n);
|
|
129
|
+
globalThis.setTimeout(r, 0);
|
|
133
130
|
}
|
|
134
|
-
class
|
|
135
|
-
constructor(t, e
|
|
136
|
-
|
|
137
|
-
super(Array.isArray(r) && !!r?.includes(k), $);
|
|
138
|
-
c(this, "_className", k);
|
|
131
|
+
class A {
|
|
132
|
+
constructor(t, e) {
|
|
133
|
+
c(this, "_className", $);
|
|
139
134
|
c(this, "_hydrationScheduler");
|
|
140
135
|
c(this, "_onActionSubscriptions", /* @__PURE__ */ new Map());
|
|
141
136
|
c(this, "_onActionStores", /* @__PURE__ */ new Set());
|
|
142
137
|
c(this, "_onActionAfterSubscriptions", {});
|
|
143
138
|
c(this, "_onActionOnErrorSubscriptions", {});
|
|
144
139
|
c(this, "_options");
|
|
145
|
-
c(this, "_pluginDebug");
|
|
146
140
|
c(this, "_resetStoreCallback", /* @__PURE__ */ new Map());
|
|
147
141
|
c(this, "_disposedStores", /* @__PURE__ */ new WeakSet());
|
|
148
|
-
c(this, "_storeRollbackSnapshotsHandler", new
|
|
142
|
+
c(this, "_storeRollbackSnapshotsHandler", new C());
|
|
149
143
|
c(this, "_subscribers", []);
|
|
150
144
|
c(this, "_subscribersDelivered", /* @__PURE__ */ new Set());
|
|
151
145
|
c(this, "_subscribersScheduled", /* @__PURE__ */ new Set());
|
|
152
146
|
c(this, "_subscriptions", []);
|
|
153
147
|
c(this, "_subscriptionsDelivered", /* @__PURE__ */ new Set());
|
|
154
148
|
c(this, "_subscriptionsScheduled", /* @__PURE__ */ new Set());
|
|
155
|
-
this
|
|
149
|
+
c(this, "_tracer");
|
|
150
|
+
this._hydrationScheduler = e?.hydrationScheduler ?? R, this._options = e, this._subscribers = t, this.initializeTracer();
|
|
156
151
|
}
|
|
157
152
|
set subscribers(t) {
|
|
158
153
|
this._subscribers = t;
|
|
@@ -162,12 +157,12 @@ class g extends m {
|
|
|
162
157
|
return this._subscriptions;
|
|
163
158
|
}
|
|
164
159
|
addOnActionAfterCallback(t, e, i) {
|
|
165
|
-
const
|
|
166
|
-
this._onActionAfterSubscriptions[
|
|
160
|
+
const s = b(t, e);
|
|
161
|
+
this._onActionAfterSubscriptions[s] || (this._onActionAfterSubscriptions[s] = []), this._onActionAfterSubscriptions[s]?.push(i);
|
|
167
162
|
}
|
|
168
163
|
addOnActionOnErrorCallback(t, e, i) {
|
|
169
|
-
const
|
|
170
|
-
this._onActionOnErrorSubscriptions[
|
|
164
|
+
const s = b(t, e);
|
|
165
|
+
this._onActionOnErrorSubscriptions[s] || (this._onActionOnErrorSubscriptions[s] = []), this._onActionOnErrorSubscriptions[s]?.push(i);
|
|
171
166
|
}
|
|
172
167
|
addResetStoreCallback(t, e) {
|
|
173
168
|
this._resetStoreCallback.has(t) || this._resetStoreCallback.set(t, /* @__PURE__ */ new Set()), this._resetStoreCallback.get(t).add(e);
|
|
@@ -204,22 +199,19 @@ class g extends m {
|
|
|
204
199
|
createRollbackSnapshot(t, e) {
|
|
205
200
|
const {
|
|
206
201
|
after: i,
|
|
207
|
-
onError:
|
|
202
|
+
onError: s
|
|
208
203
|
} = this._storeRollbackSnapshotsHandler.createOnActionCallbacks(
|
|
209
204
|
t,
|
|
210
205
|
e
|
|
211
206
|
) ?? {};
|
|
212
|
-
!i || !
|
|
207
|
+
!i || !s || (this.addOnActionAfterCallback(t, e, i), this.addOnActionOnErrorCallback(t, e, s));
|
|
213
208
|
}
|
|
214
209
|
defineCurrentEnvironment() {
|
|
215
210
|
return this._options?.runtimeEnvironment ?? (typeof window > "u" ? "server" : "client");
|
|
216
211
|
}
|
|
217
|
-
definePluginDebug(t) {
|
|
218
|
-
return !!this._pluginDebug?.includes(t.name);
|
|
219
|
-
}
|
|
220
212
|
definePluginExecution(t) {
|
|
221
213
|
return {
|
|
222
|
-
...
|
|
214
|
+
...w,
|
|
223
215
|
...this._options?.execution ?? {},
|
|
224
216
|
...t.execution ?? {},
|
|
225
217
|
...this._options?.subscriberExecution?.[t.name] ?? {}
|
|
@@ -241,73 +233,74 @@ class g extends m {
|
|
|
241
233
|
if (this._onActionStores.has(t) || typeof t.$onAction != "function")
|
|
242
234
|
return;
|
|
243
235
|
const e = this._onActionSubscriptions.get(t), i = this._storeRollbackSnapshotsHandler.storeHasRollbackSnapshots(t);
|
|
244
|
-
!e?.size && !i || (this._onActionStores.add(t), t.$onAction(({ after:
|
|
245
|
-
const
|
|
246
|
-
this.
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
236
|
+
!e?.size && !i || (this._onActionStores.add(t), t.$onAction(({ after: s, args: n, name: o, onError: a }) => {
|
|
237
|
+
const u = 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 l = this._onActionSubscriptions.get(t);
|
|
244
|
+
l?.size && l.forEach((d) => d({
|
|
245
|
+
after: this.createOnActionAfterCallbackCollector(o, t),
|
|
246
|
+
args: n,
|
|
247
|
+
name: o,
|
|
248
|
+
onError: this.createOnActionOnErrorCallbackCollector(o, t)
|
|
253
249
|
}));
|
|
254
|
-
const p = this._onActionAfterSubscriptions[
|
|
255
|
-
this.clearOnActionCallbacksSubscriptions(
|
|
256
|
-
p.forEach((
|
|
257
|
-
}),
|
|
258
|
-
|
|
250
|
+
const p = this._onActionAfterSubscriptions[u], f = this._onActionOnErrorSubscriptions[u];
|
|
251
|
+
this.clearOnActionCallbacksSubscriptions(u), p?.length && s((d) => {
|
|
252
|
+
p.forEach((S) => S(d));
|
|
253
|
+
}), f?.length && a((d) => {
|
|
254
|
+
f.forEach((S) => S(d));
|
|
259
255
|
});
|
|
260
256
|
}));
|
|
261
257
|
}
|
|
262
258
|
executeSubscriber(t, e) {
|
|
263
|
-
const i = this.defineSubscriberKey(e, t.store)
|
|
264
|
-
if (this._subscribersDelivered.has(i) || !e.invoke(
|
|
265
|
-
t,
|
|
266
|
-
r
|
|
267
|
-
))
|
|
259
|
+
const i = this.defineSubscriberKey(e, t.store);
|
|
260
|
+
if (this._subscribersDelivered.has(i) || !e.invoke(t, this._options?.createTracer))
|
|
268
261
|
return;
|
|
269
262
|
this._subscribersDelivered.add(i);
|
|
270
|
-
let
|
|
263
|
+
let s;
|
|
271
264
|
try {
|
|
272
|
-
|
|
273
|
-
} catch (
|
|
274
|
-
this.
|
|
265
|
+
s = e.hydrate?.(t);
|
|
266
|
+
} catch (o) {
|
|
267
|
+
this.traceError("subscriber:hydrate", o, () => ({ store: t.store, options: t.options }), t.store.$id);
|
|
275
268
|
return;
|
|
276
269
|
}
|
|
277
|
-
const
|
|
270
|
+
const n = () => {
|
|
278
271
|
try {
|
|
279
|
-
const
|
|
280
|
-
|
|
281
|
-
} catch (
|
|
282
|
-
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);
|
|
283
276
|
}
|
|
284
277
|
};
|
|
285
|
-
|
|
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);
|
|
286
279
|
}
|
|
287
280
|
executeSubscriberSafely(t, e) {
|
|
288
281
|
try {
|
|
289
282
|
this.executeSubscriber(t, e);
|
|
290
283
|
} catch (i) {
|
|
291
|
-
this.
|
|
284
|
+
this.traceError("subscriber:execute", i, () => ({ store: t.store, options: t.options }), t.store.$id);
|
|
292
285
|
}
|
|
293
286
|
}
|
|
287
|
+
initializeTracer() {
|
|
288
|
+
this._options?.createTracer && (this._tracer = this._options.createTracer(g));
|
|
289
|
+
}
|
|
294
290
|
plugin({ store: t, options: e }) {
|
|
295
291
|
if (this._subscribers.length) {
|
|
296
|
-
this.
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
"options:",
|
|
302
|
-
e
|
|
303
|
-
]);
|
|
292
|
+
this.trace("plugin", {
|
|
293
|
+
subscribers: this._subscribers,
|
|
294
|
+
store: t,
|
|
295
|
+
options: e
|
|
296
|
+
}, t.$id);
|
|
304
297
|
try {
|
|
305
298
|
this._subscribers.forEach(
|
|
306
299
|
(i) => {
|
|
307
|
-
const
|
|
308
|
-
if (!(this._subscribersDelivered.has(
|
|
309
|
-
if (this.shouldScheduleAfterHydration(
|
|
310
|
-
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);
|
|
311
304
|
return;
|
|
312
305
|
}
|
|
313
306
|
this.executeSubscriber({ store: t, options: e }, i);
|
|
@@ -315,13 +308,13 @@ class g extends m {
|
|
|
315
308
|
}
|
|
316
309
|
), this.rewriteResetStore({ store: t }, t.$state), this._storeRollbackSnapshotsHandler.initFromPluginContext({ store: t, options: e }), this.executeStoreOnActionSubscription(t), this.registerStoreCleanup(t);
|
|
317
310
|
} catch (i) {
|
|
318
|
-
this.
|
|
311
|
+
this.traceError("plugin:invoke", i, () => ({ store: t, options: e }), t.$id);
|
|
319
312
|
}
|
|
320
313
|
}
|
|
321
314
|
}
|
|
322
315
|
queueSubscriberExecution(t, e, i) {
|
|
323
|
-
const
|
|
324
|
-
this._subscribersScheduled.add(i),
|
|
316
|
+
const s = this.defineHydrationScheduler(e);
|
|
317
|
+
this._subscribersScheduled.add(i), s(() => {
|
|
325
318
|
this._disposedStores.has(t.store) || (this._subscribersScheduled.delete(i), this.executeSubscriberSafely(t, e));
|
|
326
319
|
});
|
|
327
320
|
}
|
|
@@ -332,9 +325,12 @@ class g extends m {
|
|
|
332
325
|
i.__piniaPluginSubscriptionDisposed || (i.__piniaPluginSubscriptionDisposed = !0, t.$dispose = () => (this._disposedStores.add(t), this.clearStoreTracking(t), this._storeRollbackSnapshotsHandler.clearStoreTracking(t), e()));
|
|
333
326
|
}
|
|
334
327
|
rewriteResetStore({ store: t }, e) {
|
|
335
|
-
const i =
|
|
328
|
+
const i = h(e);
|
|
336
329
|
t.$reset = () => {
|
|
337
|
-
this.
|
|
330
|
+
this.trace("store:reset", {
|
|
331
|
+
initState: i,
|
|
332
|
+
store: t
|
|
333
|
+
}, t.$id), this.executeResetStoreCallbacks(t), t.$patch(h(i));
|
|
338
334
|
};
|
|
339
335
|
}
|
|
340
336
|
shouldInvokePlugin(t) {
|
|
@@ -350,91 +346,87 @@ class g extends m {
|
|
|
350
346
|
}
|
|
351
347
|
storeMutationSubscription(t) {
|
|
352
348
|
const { store: e, callback: i } = t();
|
|
353
|
-
e.$subscribe((
|
|
354
|
-
this.
|
|
349
|
+
e.$subscribe((s) => {
|
|
350
|
+
this.trace("store:mutation", { mutation: s, store: e }, e.$id), i(s);
|
|
355
351
|
});
|
|
356
352
|
}
|
|
357
353
|
subscriptionDelivery(t, e) {
|
|
358
|
-
Object.entries(e).forEach(([i,
|
|
359
|
-
const
|
|
360
|
-
if (!(this._subscriptionsDelivered.has(
|
|
361
|
-
if (this.shouldScheduleAfterHydration(
|
|
362
|
-
const a = this.defineHydrationScheduler(
|
|
363
|
-
this._subscriptionsScheduled.add(
|
|
364
|
-
this._disposedStores.has(t.store) || (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));
|
|
365
361
|
});
|
|
366
362
|
return;
|
|
367
363
|
}
|
|
368
|
-
this.subscriptionDeliverySafely(t, i,
|
|
364
|
+
this.subscriptionDeliverySafely(t, i, s);
|
|
369
365
|
}
|
|
370
366
|
});
|
|
371
367
|
}
|
|
372
|
-
subscriptionDeliverySafely({ store: t, options: e }, i,
|
|
368
|
+
subscriptionDeliverySafely({ store: t, options: e }, i, s) {
|
|
373
369
|
try {
|
|
374
370
|
if (this._subscriptionsDelivered.has(this.defineSubscriptionKey(i, t)))
|
|
375
371
|
return;
|
|
376
|
-
const { subscription:
|
|
377
|
-
this.
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
a
|
|
386
|
-
]);
|
|
387
|
-
const l = {
|
|
388
|
-
storeOptions: { ...e?.storeOptions ?? {}, ...h }
|
|
372
|
+
const { subscription: n, subscriptionOptions: o, stores: a } = s;
|
|
373
|
+
this.trace("subscription:delivery", {
|
|
374
|
+
pluginName: i,
|
|
375
|
+
subscription: n,
|
|
376
|
+
options: o,
|
|
377
|
+
stores: a
|
|
378
|
+
}, t.$id);
|
|
379
|
+
const u = {
|
|
380
|
+
storeOptions: { ...e?.storeOptions ?? {}, ...o }
|
|
389
381
|
};
|
|
390
|
-
|
|
391
|
-
{ store: t, options: { ...e, ...
|
|
392
|
-
this.debug
|
|
382
|
+
n.invoke(
|
|
383
|
+
{ store: t, options: { ...e, ...u } }
|
|
393
384
|
), this._subscriptionsDelivered.add(this.defineSubscriptionKey(i, t)), _(a) || a?.forEach(
|
|
394
|
-
(
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
},
|
|
403
|
-
this.debug
|
|
404
|
-
)
|
|
385
|
+
(l) => n.invoke({
|
|
386
|
+
store: l,
|
|
387
|
+
options: {
|
|
388
|
+
...e,
|
|
389
|
+
...u,
|
|
390
|
+
...l?.storeOptions ?? {}
|
|
391
|
+
}
|
|
392
|
+
})
|
|
405
393
|
);
|
|
406
|
-
} catch (
|
|
407
|
-
this.
|
|
394
|
+
} catch (n) {
|
|
395
|
+
this.traceError("subscription:delivery", n, () => ({ store: t, options: e }), t.$id);
|
|
408
396
|
}
|
|
409
397
|
}
|
|
398
|
+
trace(t, e, i) {
|
|
399
|
+
this._tracer && (t = this._className + ":" + t, this._tracer.debug(t, t.toLowerCase(), e, i));
|
|
400
|
+
}
|
|
401
|
+
traceError(t, e, i, s) {
|
|
402
|
+
this._tracer ? (t = this._className + ":" + t, this._tracer.error(t, t.toLowerCase(), e, i, s)) : console.error(e);
|
|
403
|
+
}
|
|
410
404
|
}
|
|
411
|
-
function
|
|
412
|
-
const
|
|
413
|
-
return
|
|
405
|
+
function D(r, t) {
|
|
406
|
+
const e = new A(r, t);
|
|
407
|
+
return e.plugin.bind(e);
|
|
414
408
|
}
|
|
415
|
-
function
|
|
416
|
-
const
|
|
417
|
-
execution:
|
|
418
|
-
hydrationScheduler:
|
|
419
|
-
runtimeEnvironment:
|
|
420
|
-
subscriberExecution:
|
|
409
|
+
function j(r, t) {
|
|
410
|
+
const e = new A(r, {
|
|
411
|
+
execution: t?.execution,
|
|
412
|
+
hydrationScheduler: t?.hydrationScheduler,
|
|
413
|
+
runtimeEnvironment: t?.runtimeEnvironment,
|
|
414
|
+
subscriberExecution: t?.subscriberExecution
|
|
421
415
|
});
|
|
422
|
-
return
|
|
416
|
+
return e.plugin.bind(e);
|
|
423
417
|
}
|
|
424
418
|
export {
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
_ as isEmpty,
|
|
438
|
-
Q as setEnhancedStore
|
|
419
|
+
g as PLUGIN_NAME,
|
|
420
|
+
M as PluginSubscriber,
|
|
421
|
+
A as PluginSubscription,
|
|
422
|
+
x as Store,
|
|
423
|
+
j as createHydrationPlugin,
|
|
424
|
+
D as createPlugin,
|
|
425
|
+
F as defineAStore,
|
|
426
|
+
W as defineAStoreCtx,
|
|
427
|
+
I as getDefineAStoreSetupContext,
|
|
428
|
+
q as getEnhancedStore,
|
|
429
|
+
z as getExtendingStore,
|
|
430
|
+
L as setEnhancedStore
|
|
439
431
|
};
|
|
440
432
|
//# sourceMappingURL=pinia-plugin-subscription.js.map
|