pinia-plugin-subscription 0.2.0-beta.0 → 0.2.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 +28 -1
- package/README.md +49 -341
- package/dist/chunks/{index-D-rnwSJk.js → index-DKdl-fiq.js} +52 -58
- package/dist/chunks/index-DKdl-fiq.js.map +1 -0
- package/dist/core/PluginSubscription.d.ts +2 -0
- package/dist/core/RollbackStateSnapshotsHandler.d.ts +1 -0
- package/dist/helpers.js +2 -1
- package/dist/helpers.js.map +1 -0
- package/dist/lib/main.d.ts +1 -1
- package/dist/pinia-plugin-subscription.js +103 -161
- package/dist/pinia-plugin-subscription.js.map +1 -0
- package/dist/plugins/createPlugin.d.ts +4 -1
- package/dist/tests/defineAStore.test-d.d.ts +1 -0
- package/dist/tests/storeOptionsExtensions.test-d.d.ts +12 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/store.d.ts +39 -2
- package/dist/utils/deep-clone.d.ts +6 -0
- package/dist/utils/store.d.ts +77 -8
- package/docs/authoring-plugins.md +408 -0
- package/docs/using-plugins.md +375 -0
- package/package.json +4 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { h as
|
|
5
|
-
import { C as T, p as
|
|
6
|
-
import { toRaw as
|
|
1
|
+
var E = Object.defineProperty;
|
|
2
|
+
var O = (n, s, t) => s in n ? E(n, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[s] = t;
|
|
3
|
+
var c = (n, s, t) => O(n, typeof s != "symbol" ? s + "" : s, t);
|
|
4
|
+
import { h as C, g as S, D as m, i as _, P as $ } from "./chunks/index-DKdl-fiq.js";
|
|
5
|
+
import { C as T, p as L, a as I, S as q, d as z, b as G, c as U, e as B, f as J, s as Q } from "./chunks/index-DKdl-fiq.js";
|
|
6
|
+
import { toRaw as A } from "vue";
|
|
7
7
|
function u(n) {
|
|
8
8
|
if (typeof structuredClone == "function")
|
|
9
9
|
try {
|
|
@@ -29,88 +29,63 @@ function u(n) {
|
|
|
29
29
|
s[t] = u(e);
|
|
30
30
|
return s;
|
|
31
31
|
}
|
|
32
|
-
function
|
|
32
|
+
function w(n, s = "all") {
|
|
33
33
|
if (Array.isArray(s)) {
|
|
34
34
|
const t = {};
|
|
35
35
|
for (const e of s)
|
|
36
|
-
e in n && (t[e] = u(
|
|
36
|
+
e in n && (t[e] = u(A(n[e])));
|
|
37
37
|
return t;
|
|
38
38
|
}
|
|
39
39
|
if (s !== "all")
|
|
40
40
|
throw new Error(`Invalid keys parameter: ${s}`);
|
|
41
|
-
return u(
|
|
41
|
+
return u(A(n));
|
|
42
42
|
}
|
|
43
|
-
class
|
|
43
|
+
class R {
|
|
44
44
|
constructor() {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Adds a rollback action to the given store.
|
|
51
|
-
* This method extends the store with a $rollbackAfterFailure function that handles rollback logic for actions.
|
|
52
|
-
* @param {Store} store The store to which the rollback action will be added.
|
|
53
|
-
* @returns void
|
|
54
|
-
*/
|
|
45
|
+
c(this, "_stateSnapshots", /* @__PURE__ */ new Map());
|
|
46
|
+
c(this, "_storeHasRollbackSnapshots", /* @__PURE__ */ new Set());
|
|
47
|
+
c(this, "_storeRollbackSnapshotsParams", /* @__PURE__ */ new Map());
|
|
48
|
+
}
|
|
55
49
|
addRollbackAction(s) {
|
|
56
|
-
typeof s.$rollbackAfterFailure != "function" && (s.$rollbackAfterFailure = async ({ action: t, stateKeys: e },
|
|
50
|
+
typeof s.$rollbackAfterFailure != "function" && (s.$rollbackAfterFailure = async ({ action: t, stateKeys: e }, i = []) => {
|
|
57
51
|
const r = s[t];
|
|
58
|
-
if (typeof r != "function" ||
|
|
52
|
+
if (typeof r != "function" || C(t))
|
|
59
53
|
return;
|
|
60
54
|
const o = !e || e.length === 0 ? "all" : e, h = this.saveStateSnapshot(s, t, o);
|
|
61
55
|
try {
|
|
62
56
|
await r.apply(s, i);
|
|
63
|
-
} catch (
|
|
64
|
-
throw this.patchStore(h, s),
|
|
57
|
+
} catch (a) {
|
|
58
|
+
throw this.patchStore(h, s), a;
|
|
65
59
|
} finally {
|
|
66
60
|
this.removeStateSnapshot(h);
|
|
67
61
|
}
|
|
68
62
|
});
|
|
69
63
|
}
|
|
70
|
-
/**
|
|
71
|
-
* Creates a rollback snapshot for the specified action and store.
|
|
72
|
-
* This snapshot can be used to restore the store's state in case of an error during the action execution.
|
|
73
|
-
* @param {string} actionName The name of the action for which the rollback snapshot is created.
|
|
74
|
-
* @param {Store} store The Pinia store instance.
|
|
75
|
-
* @returns An object containing `after` and `onError` callbacks for handling the rollback, or `undefined` if no snapshot is created.
|
|
76
|
-
*/
|
|
77
64
|
createOnActionCallbacks(s, t) {
|
|
78
65
|
const e = this._storeRollbackSnapshotsParams.get(
|
|
79
|
-
|
|
66
|
+
S(s, t)
|
|
80
67
|
);
|
|
81
|
-
if (!e
|
|
68
|
+
if (!e)
|
|
82
69
|
return;
|
|
83
|
-
const i = this.saveStateSnapshot(t, s,
|
|
70
|
+
const i = e.length === 0 ? "all" : e, r = this.saveStateSnapshot(t, s, i);
|
|
84
71
|
return {
|
|
85
72
|
after: () => {
|
|
86
|
-
this.removeStateSnapshot(
|
|
73
|
+
this.removeStateSnapshot(r);
|
|
87
74
|
},
|
|
88
75
|
onError: () => {
|
|
89
|
-
this.patchStore(
|
|
76
|
+
this.patchStore(r, t), this.removeStateSnapshot(r);
|
|
90
77
|
}
|
|
91
78
|
};
|
|
92
79
|
}
|
|
93
|
-
/**
|
|
94
|
-
* Initializes the rollback state snapshots handler from the given Pinia plugin context.
|
|
95
|
-
* This method extracts the rollback snapshot parameters from the store options and stores them internally.
|
|
96
|
-
* @param {PiniaPluginContext} param0 The Pinia plugin context containing the store and its options.
|
|
97
|
-
* @returns void
|
|
98
|
-
*/
|
|
99
80
|
initFromPluginContext({ options: s, store: t }) {
|
|
100
81
|
const e = s?.storeOptions?.rollbackAfterFailure;
|
|
101
82
|
e && !this._storeHasRollbackSnapshots.has(t.$id) && (Object.keys(e).forEach((i) => {
|
|
102
83
|
this._storeRollbackSnapshotsParams.set(
|
|
103
|
-
|
|
84
|
+
S(i, t),
|
|
104
85
|
e[i]
|
|
105
86
|
);
|
|
106
87
|
}), this._storeHasRollbackSnapshots.add(t.$id)), this.addRollbackAction(t);
|
|
107
88
|
}
|
|
108
|
-
/**
|
|
109
|
-
* Clears all rollback tracking data for the given store.
|
|
110
|
-
* Must be called when the store is disposed to avoid memory leaks with dynamically created stores.
|
|
111
|
-
* @param {Store} store The disposed Pinia store instance.
|
|
112
|
-
* @returns void
|
|
113
|
-
*/
|
|
114
89
|
clearStoreTracking(s) {
|
|
115
90
|
const t = `-${s.$id}`;
|
|
116
91
|
for (const e of Array.from(this._storeRollbackSnapshotsParams.keys()))
|
|
@@ -128,42 +103,25 @@ class v {
|
|
|
128
103
|
console.error(`Failed to patch store with snapshot ${String(s)}`, i);
|
|
129
104
|
}
|
|
130
105
|
}
|
|
131
|
-
/**
|
|
132
|
-
* Removes a state snapshot identified by the given snapshot key from the internal state snapshot tracking.
|
|
133
|
-
* @param snapshotKey The key of the state snapshot to be removed.
|
|
134
|
-
* @returns void
|
|
135
|
-
*/
|
|
136
106
|
removeStateSnapshot(s) {
|
|
137
107
|
s && this._stateSnapshots.delete(s);
|
|
138
108
|
}
|
|
139
|
-
/**
|
|
140
|
-
* Saves the current state snapshot for a given store and action.
|
|
141
|
-
* @param store The Pinia store instance.
|
|
142
|
-
* @param actionName The name of the action being executed.
|
|
143
|
-
* @param stateKeys The state keys to include in the snapshot, or 'all' for the full state.
|
|
144
|
-
* @returns A unique symbol key representing the saved snapshot.
|
|
145
|
-
*/
|
|
146
109
|
saveStateSnapshot(s, t, e) {
|
|
147
|
-
const i =
|
|
110
|
+
const i = w(
|
|
148
111
|
s.$state,
|
|
149
112
|
e
|
|
150
113
|
), r = /* @__PURE__ */ Symbol(`${s.$id}:${t}`);
|
|
151
114
|
return this._stateSnapshots.set(r, i), r;
|
|
152
115
|
}
|
|
153
|
-
/**
|
|
154
|
-
* Checks if the given store has rollback snapshots.
|
|
155
|
-
* @param store The Pinia store instance.
|
|
156
|
-
* @returns True if the store has rollback snapshots, false otherwise.
|
|
157
|
-
*/
|
|
158
116
|
storeHasRollbackSnapshots(s) {
|
|
159
117
|
return this._storeHasRollbackSnapshots.has(s.$id);
|
|
160
118
|
}
|
|
161
119
|
}
|
|
162
|
-
const
|
|
120
|
+
const k = "PluginSubscription", v = {
|
|
163
121
|
environment: "both",
|
|
164
122
|
hydration: "immediate"
|
|
165
123
|
};
|
|
166
|
-
function
|
|
124
|
+
function P(n) {
|
|
167
125
|
if (typeof window < "u" && typeof window.requestAnimationFrame == "function") {
|
|
168
126
|
window.requestAnimationFrame(() => globalThis.setTimeout(n, 0));
|
|
169
127
|
return;
|
|
@@ -173,49 +131,52 @@ function R(n) {
|
|
|
173
131
|
function D(n) {
|
|
174
132
|
return n !== void 0 && !Array.isArray(n);
|
|
175
133
|
}
|
|
176
|
-
class
|
|
134
|
+
class g extends m {
|
|
177
135
|
constructor(t, e, i) {
|
|
178
136
|
const r = Array.isArray(e) ? e : void 0, o = D(e) ? e : i;
|
|
179
|
-
super(Array.isArray(r) && !!r?.includes(
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
this
|
|
137
|
+
super(Array.isArray(r) && !!r?.includes(k), $);
|
|
138
|
+
c(this, "_className", k);
|
|
139
|
+
c(this, "_hydrationScheduler");
|
|
140
|
+
c(this, "_onActionSubscriptions", /* @__PURE__ */ new Map());
|
|
141
|
+
c(this, "_onActionStores", /* @__PURE__ */ new Set());
|
|
142
|
+
c(this, "_onActionAfterSubscriptions", {});
|
|
143
|
+
c(this, "_onActionOnErrorSubscriptions", {});
|
|
144
|
+
c(this, "_options");
|
|
145
|
+
c(this, "_pluginDebug");
|
|
146
|
+
c(this, "_resetStoreCallback", /* @__PURE__ */ new Map());
|
|
147
|
+
c(this, "_disposedStores", /* @__PURE__ */ new WeakSet());
|
|
148
|
+
c(this, "_storeRollbackSnapshotsHandler", new R());
|
|
149
|
+
c(this, "_subscribers", []);
|
|
150
|
+
c(this, "_subscribersDelivered", /* @__PURE__ */ new Set());
|
|
151
|
+
c(this, "_subscribersScheduled", /* @__PURE__ */ new Set());
|
|
152
|
+
c(this, "_subscriptions", []);
|
|
153
|
+
c(this, "_subscriptionsDelivered", /* @__PURE__ */ new Set());
|
|
154
|
+
c(this, "_subscriptionsScheduled", /* @__PURE__ */ new Set());
|
|
155
|
+
this._hydrationScheduler = o?.hydrationScheduler ?? P, this._options = o, this._pluginDebug = Array.isArray(r) ? r : void 0, this._subscribers = t;
|
|
196
156
|
}
|
|
197
157
|
set subscribers(t) {
|
|
198
158
|
this._subscribers = t;
|
|
199
159
|
}
|
|
200
160
|
get subscriptions() {
|
|
201
|
-
if (!
|
|
161
|
+
if (!_(this._subscriptions))
|
|
202
162
|
return this._subscriptions;
|
|
203
163
|
}
|
|
204
164
|
addOnActionAfterCallback(t, e, i) {
|
|
205
|
-
const r =
|
|
165
|
+
const r = S(t, e);
|
|
206
166
|
this._onActionAfterSubscriptions[r] || (this._onActionAfterSubscriptions[r] = []), this._onActionAfterSubscriptions[r]?.push(i);
|
|
207
167
|
}
|
|
208
168
|
addOnActionOnErrorCallback(t, e, i) {
|
|
209
|
-
const r =
|
|
169
|
+
const r = S(t, e);
|
|
210
170
|
this._onActionOnErrorSubscriptions[r] || (this._onActionOnErrorSubscriptions[r] = []), this._onActionOnErrorSubscriptions[r]?.push(i);
|
|
211
171
|
}
|
|
212
|
-
addResetStoreCallback(t) {
|
|
213
|
-
this._resetStoreCallback.
|
|
172
|
+
addResetStoreCallback(t, e) {
|
|
173
|
+
this._resetStoreCallback.has(t) || this._resetStoreCallback.set(t, /* @__PURE__ */ new Set()), this._resetStoreCallback.get(t).add(e);
|
|
214
174
|
}
|
|
215
175
|
clearOnActionCallbacksSubscriptions(t) {
|
|
216
176
|
delete this._onActionAfterSubscriptions[t], delete this._onActionOnErrorSubscriptions[t];
|
|
217
177
|
}
|
|
218
178
|
clearStoreTracking(t) {
|
|
179
|
+
this._onActionSubscriptions.delete(t), this._onActionStores.delete(t), this._resetStoreCallback.delete(t);
|
|
219
180
|
const e = `-${t.$id}`;
|
|
220
181
|
for (const i of Array.from(this._subscribersDelivered))
|
|
221
182
|
i.endsWith(e) && this._subscribersDelivered.delete(i);
|
|
@@ -230,34 +191,16 @@ class k extends m {
|
|
|
230
191
|
for (const i of Object.keys(this._onActionOnErrorSubscriptions))
|
|
231
192
|
i.endsWith(e) && delete this._onActionOnErrorSubscriptions[i];
|
|
232
193
|
}
|
|
233
|
-
/**
|
|
234
|
-
* Creates a callback collector for the specified action and store.
|
|
235
|
-
* @param actionName The name of the action to collect callbacks for.
|
|
236
|
-
* @param store The store instance associated with the action.
|
|
237
|
-
* @returns A function that collects callbacks for the specified action and store.
|
|
238
|
-
*/
|
|
239
194
|
createOnActionAfterCallbackCollector(t, e) {
|
|
240
195
|
return (i) => {
|
|
241
196
|
this.addOnActionAfterCallback(t, e, i);
|
|
242
197
|
};
|
|
243
198
|
}
|
|
244
|
-
/**
|
|
245
|
-
* Creates a callback collector for the specified action and store that handles errors.
|
|
246
|
-
* @param actionName The name of the action to collect error callbacks for.
|
|
247
|
-
* @param store The store instance associated with the action.
|
|
248
|
-
* @returns A function that collects error callbacks for the specified action and store.
|
|
249
|
-
*/
|
|
250
199
|
createOnActionOnErrorCallbackCollector(t, e) {
|
|
251
200
|
return (i) => {
|
|
252
201
|
this.addOnActionOnErrorCallback(t, e, i);
|
|
253
202
|
};
|
|
254
203
|
}
|
|
255
|
-
/**
|
|
256
|
-
* Rolls back the state snapshot for a given action if an error occurs, and removes the snapshot after the action completes or fails.
|
|
257
|
-
* @param actionName The name of the action being executed.
|
|
258
|
-
* @param store The Pinia store instance.
|
|
259
|
-
* @returns void
|
|
260
|
-
*/
|
|
261
204
|
createRollbackSnapshot(t, e) {
|
|
262
205
|
const {
|
|
263
206
|
after: i,
|
|
@@ -276,7 +219,7 @@ class k extends m {
|
|
|
276
219
|
}
|
|
277
220
|
definePluginExecution(t) {
|
|
278
221
|
return {
|
|
279
|
-
...
|
|
222
|
+
...v,
|
|
280
223
|
...this._options?.execution ?? {},
|
|
281
224
|
...t.execution ?? {},
|
|
282
225
|
...this._options?.subscriberExecution?.[t.name] ?? {}
|
|
@@ -292,31 +235,29 @@ class k extends m {
|
|
|
292
235
|
return `${t}-${e.$id}`;
|
|
293
236
|
}
|
|
294
237
|
executeResetStoreCallbacks(t) {
|
|
295
|
-
this._resetStoreCallback.forEach((e) => e(t));
|
|
296
|
-
}
|
|
297
|
-
/**
|
|
298
|
-
* Executes the store's onAction subscription for the given plugin subscriber.
|
|
299
|
-
* @param store The Pinia store instance.
|
|
300
|
-
* @param subscriber The plugin subscriber.
|
|
301
|
-
* @returns void
|
|
302
|
-
*/
|
|
238
|
+
this._resetStoreCallback.get(t)?.forEach((e) => e(t));
|
|
239
|
+
}
|
|
303
240
|
executeStoreOnActionSubscription(t) {
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
241
|
+
if (this._onActionStores.has(t) || typeof t.$onAction != "function")
|
|
242
|
+
return;
|
|
243
|
+
const e = this._onActionSubscriptions.get(t), i = this._storeRollbackSnapshotsHandler.storeHasRollbackSnapshots(t);
|
|
244
|
+
!e?.size && !i || (this._onActionStores.add(t), t.$onAction(({ after: r, args: o, name: h, onError: a }) => {
|
|
245
|
+
const l = S(h, t);
|
|
246
|
+
this.debugLog(`storeOnActionSubscription ${l}`, { args: o, name: h, store: t }), this._storeRollbackSnapshotsHandler.storeHasRollbackSnapshots(t) && this.createRollbackSnapshot(h, t);
|
|
247
|
+
const d = this._onActionSubscriptions.get(t);
|
|
248
|
+
d?.size && d.forEach((b) => b({
|
|
308
249
|
after: this.createOnActionAfterCallbackCollector(h, t),
|
|
309
250
|
args: o,
|
|
310
251
|
name: h,
|
|
311
252
|
onError: this.createOnActionOnErrorCallbackCollector(h, t)
|
|
312
253
|
}));
|
|
313
|
-
const
|
|
314
|
-
this.clearOnActionCallbacksSubscriptions(l),
|
|
315
|
-
|
|
316
|
-
}),
|
|
317
|
-
|
|
254
|
+
const p = this._onActionAfterSubscriptions[l], y = this._onActionOnErrorSubscriptions[l];
|
|
255
|
+
this.clearOnActionCallbacksSubscriptions(l), p?.length && r((b) => {
|
|
256
|
+
p.forEach((f) => f(b));
|
|
257
|
+
}), y?.length && a((b) => {
|
|
258
|
+
y.forEach((f) => f(b));
|
|
318
259
|
});
|
|
319
|
-
});
|
|
260
|
+
}));
|
|
320
261
|
}
|
|
321
262
|
executeSubscriber(t, e) {
|
|
322
263
|
const i = this.defineSubscriberKey(e, t.store), r = this.definePluginDebug(e);
|
|
@@ -329,19 +270,19 @@ class k extends m {
|
|
|
329
270
|
let o;
|
|
330
271
|
try {
|
|
331
272
|
o = e.hydrate?.(t, r);
|
|
332
|
-
} catch (
|
|
333
|
-
this.logError(
|
|
273
|
+
} catch (a) {
|
|
274
|
+
this.logError(a, t.store, t.options);
|
|
334
275
|
return;
|
|
335
276
|
}
|
|
336
277
|
const h = () => {
|
|
337
278
|
try {
|
|
338
|
-
const
|
|
339
|
-
|
|
340
|
-
} catch (
|
|
341
|
-
this.logError(
|
|
279
|
+
const a = e.afterHydration?.(t, r);
|
|
280
|
+
a && typeof a.then == "function" && a.catch((l) => this.logError(l, t.store, t.options));
|
|
281
|
+
} catch (a) {
|
|
282
|
+
this.logError(a, t.store, t.options);
|
|
342
283
|
}
|
|
343
284
|
};
|
|
344
|
-
o && typeof o.then == "function" ? o.then(() => h()).catch((
|
|
285
|
+
o && typeof o.then == "function" ? o.then(() => h()).catch((a) => this.logError(a, t.store, t.options)) : h(), e.subscriptions && this.subscriptionDelivery(t, e.subscriptions), e.storeMutationSubscription && this.storeMutationSubscription(e.storeMutationSubscription), this.storeOnActionSubscription(e), e.resetStoreCallback && this.addResetStoreCallback(t.store, e.resetStoreCallback);
|
|
345
286
|
}
|
|
346
287
|
executeSubscriberSafely(t, e) {
|
|
347
288
|
try {
|
|
@@ -381,14 +322,14 @@ class k extends m {
|
|
|
381
322
|
queueSubscriberExecution(t, e, i) {
|
|
382
323
|
const r = this.defineHydrationScheduler(e);
|
|
383
324
|
this._subscribersScheduled.add(i), r(() => {
|
|
384
|
-
this._subscribersScheduled.delete(i), this.executeSubscriberSafely(t, e);
|
|
325
|
+
this._disposedStores.has(t.store) || (this._subscribersScheduled.delete(i), this.executeSubscriberSafely(t, e));
|
|
385
326
|
});
|
|
386
327
|
}
|
|
387
328
|
registerStoreCleanup(t) {
|
|
388
|
-
if (
|
|
329
|
+
if (typeof t.$dispose != "function")
|
|
389
330
|
return;
|
|
390
331
|
const e = t.$dispose.bind(t), i = t;
|
|
391
|
-
i.__piniaPluginSubscriptionDisposed || (i.__piniaPluginSubscriptionDisposed = !0, t.$dispose = () => (this.clearStoreTracking(t), this._storeRollbackSnapshotsHandler.clearStoreTracking(t), e()));
|
|
332
|
+
i.__piniaPluginSubscriptionDisposed || (i.__piniaPluginSubscriptionDisposed = !0, t.$dispose = () => (this._disposedStores.add(t), this.clearStoreTracking(t), this._storeRollbackSnapshotsHandler.clearStoreTracking(t), e()));
|
|
392
333
|
}
|
|
393
334
|
rewriteResetStore({ store: t }, e) {
|
|
394
335
|
const i = u(e);
|
|
@@ -405,7 +346,7 @@ class k extends m {
|
|
|
405
346
|
}
|
|
406
347
|
storeOnActionSubscription(t) {
|
|
407
348
|
const { store: e, callback: i } = t?.storeOnActionSubscription?.() ?? {};
|
|
408
|
-
!e || !i || this._onActionSubscriptions.
|
|
349
|
+
!e || !i || (this._onActionSubscriptions.has(e) || this._onActionSubscriptions.set(e, /* @__PURE__ */ new Set()), this._onActionSubscriptions.get(e).add(i), this.executeStoreOnActionSubscription(e));
|
|
409
350
|
}
|
|
410
351
|
storeMutationSubscription(t) {
|
|
411
352
|
const { store: e, callback: i } = t();
|
|
@@ -418,9 +359,9 @@ class k extends m {
|
|
|
418
359
|
const o = this.defineSubscriptionKey(i, t.store), h = this.definePluginExecution(r.subscription);
|
|
419
360
|
if (!(this._subscriptionsDelivered.has(o) || this._subscriptionsScheduled.has(o)) && this.shouldInvokePlugin(h)) {
|
|
420
361
|
if (this.shouldScheduleAfterHydration(h)) {
|
|
421
|
-
const
|
|
422
|
-
this._subscriptionsScheduled.add(o),
|
|
423
|
-
this._subscriptionsScheduled.delete(o), this.subscriptionDeliverySafely(t, i, r);
|
|
362
|
+
const a = this.defineHydrationScheduler(r.subscription);
|
|
363
|
+
this._subscriptionsScheduled.add(o), a(() => {
|
|
364
|
+
this._disposedStores.has(t.store) || (this._subscriptionsScheduled.delete(o), this.subscriptionDeliverySafely(t, i, r));
|
|
424
365
|
});
|
|
425
366
|
return;
|
|
426
367
|
}
|
|
@@ -432,7 +373,7 @@ class k extends m {
|
|
|
432
373
|
try {
|
|
433
374
|
if (this._subscriptionsDelivered.has(this.defineSubscriptionKey(i, t)))
|
|
434
375
|
return;
|
|
435
|
-
const { subscription: o, subscriptionOptions: h, stores:
|
|
376
|
+
const { subscription: o, subscriptionOptions: h, stores: a } = r;
|
|
436
377
|
this.debugLog(`subscriptionDelivery() - store: ${t.$id}`, [
|
|
437
378
|
"pluginName:",
|
|
438
379
|
i,
|
|
@@ -441,7 +382,7 @@ class k extends m {
|
|
|
441
382
|
"options:",
|
|
442
383
|
r,
|
|
443
384
|
"stores:",
|
|
444
|
-
|
|
385
|
+
a
|
|
445
386
|
]);
|
|
446
387
|
const l = {
|
|
447
388
|
storeOptions: { ...e?.storeOptions ?? {}, ...h }
|
|
@@ -449,7 +390,7 @@ class k extends m {
|
|
|
449
390
|
o.invoke(
|
|
450
391
|
{ store: t, options: { ...e, ...l } },
|
|
451
392
|
this.debug
|
|
452
|
-
), this._subscriptionsDelivered.add(this.defineSubscriptionKey(i, t)),
|
|
393
|
+
), this._subscriptionsDelivered.add(this.defineSubscriptionKey(i, t)), _(a) || a?.forEach(
|
|
453
394
|
(d) => o.invoke(
|
|
454
395
|
{
|
|
455
396
|
store: d,
|
|
@@ -467,12 +408,12 @@ class k extends m {
|
|
|
467
408
|
}
|
|
468
409
|
}
|
|
469
410
|
}
|
|
470
|
-
function
|
|
471
|
-
const t = new
|
|
411
|
+
function K(n, s) {
|
|
412
|
+
const t = new g(n, s);
|
|
472
413
|
return t.plugin.bind(t);
|
|
473
414
|
}
|
|
474
|
-
function
|
|
475
|
-
const t = new
|
|
415
|
+
function M(n, s) {
|
|
416
|
+
const t = new g(n, s?.debug, {
|
|
476
417
|
execution: s?.execution,
|
|
477
418
|
hydrationScheduler: s?.hydrationScheduler,
|
|
478
419
|
runtimeEnvironment: s?.runtimeEnvironment,
|
|
@@ -482,17 +423,18 @@ function K(n, s) {
|
|
|
482
423
|
}
|
|
483
424
|
export {
|
|
484
425
|
T as CustomConsole,
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
426
|
+
L as PLUGIN_NAME,
|
|
427
|
+
I as PluginSubscriber,
|
|
428
|
+
g as PluginSubscription,
|
|
429
|
+
q as Store,
|
|
430
|
+
M as createHydrationPlugin,
|
|
431
|
+
K as createPlugin,
|
|
432
|
+
z as defineAStore,
|
|
492
433
|
G as defineAStoreCtx,
|
|
493
434
|
U as getDefineAStoreSetupContext,
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
435
|
+
B as getEnhancedStore,
|
|
436
|
+
J as getExtendingStore,
|
|
437
|
+
_ as isEmpty,
|
|
438
|
+
Q as setEnhancedStore
|
|
498
439
|
};
|
|
440
|
+
//# sourceMappingURL=pinia-plugin-subscription.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pinia-plugin-subscription.js","sources":["../src/utils/deep-clone.ts","../src/factories/state-snapshot.ts","../src/core/RollbackStateSnapshotsHandler.ts","../src/core/PluginSubscription.ts"],"sourcesContent":["/**\n * Deeply clones the provided value, handling objects, arrays, maps, and sets. Uses `structuredClone` if available, otherwise falls back to a manual deep clone.\n * @template T The type of the value to deep clone.\n * @param value The value to deep clone.\n * @returns A deep clone of the provided value.\n */\nexport function deepClone<T>(value: T): T {\n if (typeof structuredClone === 'function') {\n try {\n return structuredClone(value)\n } catch {\n // fall through to the safe manual clone below\n }\n }\n\n if (value === null || typeof value !== 'object') {\n return value\n }\n\n if (value instanceof Map) {\n return new Map(\n Array.from(value.entries(), ([key, entryValue]) => [deepClone(key), deepClone(entryValue)])\n ) as T\n }\n\n if (value instanceof Set) {\n return new Set(Array.from(value.values(), entryValue => deepClone(entryValue))) as T\n }\n\n if (Array.isArray(value)) {\n return value.map(item => deepClone(item)) as T\n }\n\n if (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null) {\n return Object.fromEntries(\n Object.entries(value as Record<string, unknown>).map(([key, item]) => [key, deepClone(item)])\n ) as T\n }\n\n const clonedObject = Object.create(Object.getPrototypeOf(value)) as Record<string, unknown>\n for (const [key, item] of Object.entries(value as Record<string, unknown>)) {\n clonedObject[key] = deepClone(item)\n }\n\n return clonedObject as T\n}","import { toRaw } from 'vue'\nimport { deepClone } from '../utils/deep-clone'\n\nimport type { StateTree } from 'pinia'\nimport type { CreateStateSnapshotKeys } from '../types/plugin'\n\n\nexport function createStateSnapshot(state: StateTree, keys: CreateStateSnapshotKeys = 'all') {\n if (Array.isArray(keys)) {\n const clonedState: Partial<StateTree> = {}\n for (const key of keys) {\n if (key in state) {\n clonedState[key] = deepClone(toRaw(state[key]))\n }\n }\n return clonedState\n }\n\n if (keys !== 'all') {\n throw new Error(`Invalid keys parameter: ${keys}`)\n }\n\n return deepClone(toRaw(state))\n}","import { createStateSnapshot } from \"../factories/state-snapshot\"\nimport { getActionStoreKey, hasDeniedFirstChar } from '../utils/store'\n\nimport type { PiniaPluginContext, StateTree, Store } from 'pinia'\nimport type { AnyObject } from '../types'\nimport type { CreateStateSnapshotKeys } from '../types/plugin'\nimport type { RollbackActionParams } from '../types/store'\n\n\n/**\n * Handles rollback state snapshots for Pinia stores.\n * This class provides methods to add rollback actions to stores,\n * create rollback snapshots, and manage the state snapshots internally.\n */\nexport default class RollbackStateSnapshotsHandler {\n private _stateSnapshots: Map<symbol, StateTree> = new Map()\n private _storeHasRollbackSnapshots: Set<string> = new Set()\n private _storeRollbackSnapshotsParams: Map<string, CreateStateSnapshotKeys> = new Map()\n\n\n /**\n * Adds a rollback action to the given store.\n * This method extends the store with a $rollbackAfterFailure function that handles rollback logic for actions.\n * The action arguments are forwarded through apply(), so they must be provided as a single array.\n * @param {Store} store The store to which the rollback action will be added.\n * @returns void\n */\n addRollbackAction(store: Store): void {\n if (typeof store.$rollbackAfterFailure === 'function') {\n return\n }\n\n store.$rollbackAfterFailure = async ({ action, stateKeys }: RollbackActionParams, args: any[] = []) => {\n const actionFn = (store as AnyObject)[action]\n if (typeof actionFn !== 'function' || hasDeniedFirstChar(action)) {\n return\n }\n\n const keys: CreateStateSnapshotKeys = !stateKeys || stateKeys.length === 0 ? 'all' : stateKeys\n\n const snapshotKey = this.saveStateSnapshot(store, action, keys)\n try {\n await actionFn.apply(store, args)\n } catch (error) {\n this.patchStore(snapshotKey, store)\n throw error\n } finally {\n this.removeStateSnapshot(snapshotKey)\n }\n }\n }\n\n /**\n * Creates a rollback snapshot for the specified action and store.\n * This snapshot can be used to restore the store's state in case of an error during the action execution.\n * @param {string} actionName The name of the action for which the rollback snapshot is created.\n * @param {Store} store The Pinia store instance.\n * @returns An object containing `after` and `onError` callbacks for handling the rollback, or `undefined` if no snapshot is created.\n */\n createOnActionCallbacks(\n actionName: string,\n store: Store\n ): {\n after: () => void,\n onError: () => void\n } | undefined {\n const stateKeys = this._storeRollbackSnapshotsParams.get(\n getActionStoreKey(actionName, store)\n )\n\n if (!stateKeys) {\n return\n }\n\n const keys: CreateStateSnapshotKeys = stateKeys.length === 0 ? 'all' : stateKeys\n const snapshotKey = this.saveStateSnapshot(store, actionName, keys)\n\n return {\n after: () => { this.removeStateSnapshot(snapshotKey) },\n onError: () => {\n this.patchStore(snapshotKey, store)\n this.removeStateSnapshot(snapshotKey)\n }\n }\n }\n\n /**\n * Initializes the rollback state snapshots handler from the given Pinia plugin context.\n * This method extracts the rollback snapshot parameters from the store options and stores them internally.\n * @param {PiniaPluginContext} param0 The Pinia plugin context containing the store and its options.\n * @returns void\n */\n initFromPluginContext({ options, store }: PiniaPluginContext) {\n const rollbackSnapshotParams = options?.storeOptions?.rollbackAfterFailure as Record<string, CreateStateSnapshotKeys>\n if (rollbackSnapshotParams && !this._storeHasRollbackSnapshots.has(store.$id)) {\n Object.keys(rollbackSnapshotParams).forEach(key => {\n this._storeRollbackSnapshotsParams.set(\n getActionStoreKey(key, store),\n rollbackSnapshotParams[key]\n )\n })\n this._storeHasRollbackSnapshots.add(store.$id)\n }\n this.addRollbackAction(store)\n }\n\n /**\n * Clears all rollback tracking data for the given store.\n * Must be called when the store is disposed to avoid memory leaks with dynamically created stores.\n * @param {Store} store The disposed Pinia store instance.\n * @returns void\n */\n clearStoreTracking(store: Store): void {\n const suffix = `-${store.$id}`\n\n for (const key of Array.from(this._storeRollbackSnapshotsParams.keys())) {\n if (key.endsWith(suffix)) {\n this._storeRollbackSnapshotsParams.delete(key)\n }\n }\n\n this._storeHasRollbackSnapshots.delete(store.$id)\n\n for (const snapshotKey of Array.from(this._stateSnapshots.keys())) {\n if (snapshotKey.description?.startsWith(`${store.$id}:`)) {\n this._stateSnapshots.delete(snapshotKey)\n }\n }\n }\n\n private patchStore(snapshotKey: symbol, store: Store): void {\n const stateSnapshot = this._stateSnapshots.get(snapshotKey)\n if (!stateSnapshot) {\n return\n }\n\n try {\n store.$patch(stateSnapshot)\n } catch (error) {\n console.error(`Failed to patch store with snapshot ${String(snapshotKey)}`, error)\n }\n }\n\n /**\n * Removes a state snapshot identified by the given snapshot key from the internal state snapshot tracking.\n * @param snapshotKey The key of the state snapshot to be removed.\n * @returns void\n */\n private removeStateSnapshot(snapshotKey?: symbol): void {\n if (!snapshotKey) {\n return\n }\n\n this._stateSnapshots.delete(snapshotKey)\n }\n\n /**\n * Saves the current state snapshot for a given store and action.\n * @param store The Pinia store instance.\n * @param actionName The name of the action being executed.\n * @param stateKeys The state keys to include in the snapshot, or 'all' for the full state.\n * @returns A unique symbol key representing the saved snapshot.\n */\n private saveStateSnapshot(store: Store, actionName: string, stateKeys: CreateStateSnapshotKeys): symbol {\n const stateSnapshot = createStateSnapshot(\n store.$state,\n stateKeys\n )\n\n const snapshotKey = Symbol(`${store.$id}:${actionName}`)\n this._stateSnapshots.set(snapshotKey, stateSnapshot)\n return snapshotKey\n }\n\n /**\n * Checks if the given store has rollback snapshots.\n * @param store The Pinia store instance.\n * @returns True if the store has rollback snapshots, false otherwise.\n */\n storeHasRollbackSnapshots(store: Store): boolean {\n return this._storeHasRollbackSnapshots.has(store.$id)\n }\n}","import Debug from \"../system/Debug\"\nimport RollbackStateSnapshotsHandler from \"./RollbackStateSnapshotsHandler\"\nimport { deepClone } from '../utils/deep-clone'\nimport { getActionStoreKey } from '../utils/store'\nimport { PluginConsole } from \"../system/log\"\nimport { isEmpty } from \"../utils/validation\"\n\nimport type { PiniaPluginContext, StateTree, Store, SubscriptionCallbackMutation } from \"pinia\"\nimport type { AnyObject } from \"../types\"\nimport type {\n PluginExecutionOptions,\n PluginHydrationScheduler,\n PluginRuntimeEnvironment,\n PluginSubscriber,\n PluginSubscription as PluginSubscriptionDefinition,\n PluginSubscriptionOptions,\n PluginSubscriptions,\n StoreMutationSubscription,\n StoreOnActionAfterCallbackParameter,\n StoreOnActionSubscriptionCallback\n} from \"../types/plugin\"\n\n\nconst className = 'PluginSubscription'\nconst defaultPluginExecution: Required<PluginExecutionOptions> = {\n environment: 'both',\n hydration: 'immediate'\n}\n\nfunction defaultHydrationScheduler(callback: () => void): void {\n if (typeof window !== 'undefined' && typeof window.requestAnimationFrame === 'function') {\n window.requestAnimationFrame(() => globalThis.setTimeout(callback, 0))\n return\n }\n\n globalThis.setTimeout(callback, 0)\n}\n\nfunction isPluginSubscriptionOptions(\n value: PluginSubscriptionOptions | string[] | undefined\n): value is PluginSubscriptionOptions {\n return value !== undefined && !Array.isArray(value)\n}\n\n\nexport default class PluginSubscription extends Debug {\n protected _className: string = className\n private _hydrationScheduler: PluginHydrationScheduler\n private _onActionSubscriptions: Map<Store, Set<StoreOnActionSubscriptionCallback>> = new Map()\n private _onActionStores: Set<Store> = new Set()\n private _onActionAfterSubscriptions: Record<string, StoreOnActionAfterCallbackParameter[]> = {}\n private _onActionOnErrorSubscriptions: Record<string, Array<(error: unknown) => void>> = {}\n private _options?: PluginSubscriptionOptions\n private _pluginDebug?: string[]\n private _resetStoreCallback: Map<Store, Set<NonNullable<PluginSubscriber['resetStoreCallback']>>> = new Map()\n private _disposedStores: WeakSet<Store> = new WeakSet()\n private _storeRollbackSnapshotsHandler: RollbackStateSnapshotsHandler = new RollbackStateSnapshotsHandler()\n private _subscribers: PluginSubscriber[] = []\n private _subscribersDelivered: Set<string> = new Set()\n private _subscribersScheduled: Set<string> = new Set()\n private _subscriptions: PluginSubscriptions[] = []\n private _subscriptionsDelivered: Set<string> = new Set()\n private _subscriptionsScheduled: Set<string> = new Set()\n\n set subscribers(subscribers: PluginSubscriber[]) {\n this._subscribers = subscribers\n }\n\n get subscriptions(): PluginSubscriptions[] | undefined {\n if (!isEmpty(this._subscriptions)) {\n return this._subscriptions\n }\n }\n\n constructor(\n subscribers: PluginSubscriber[],\n debugOrOptions?: PluginSubscriptionOptions | string[],\n pluginOptions?: PluginSubscriptionOptions\n ) {\n const debug = Array.isArray(debugOrOptions) ? debugOrOptions : undefined\n const options = isPluginSubscriptionOptions(debugOrOptions) ? debugOrOptions : pluginOptions\n\n super(Array.isArray(debug) && !!debug?.includes(className), PluginConsole)\n this._hydrationScheduler = options?.hydrationScheduler ?? defaultHydrationScheduler\n this._options = options\n this._pluginDebug = Array.isArray(debug) ? debug : undefined\n this._subscribers = subscribers\n }\n\n\n private addOnActionAfterCallback(actionName: string, store: Store, callback: StoreOnActionAfterCallbackParameter): void {\n const key = getActionStoreKey(actionName, store)\n if (!this._onActionAfterSubscriptions[key]) {\n this._onActionAfterSubscriptions[key] = []\n }\n this._onActionAfterSubscriptions[key]?.push(callback)\n }\n\n private addOnActionOnErrorCallback(actionName: string, store: Store, callback: (error: unknown) => void): void {\n const key = getActionStoreKey(actionName, store)\n if (!this._onActionOnErrorSubscriptions[key]) {\n this._onActionOnErrorSubscriptions[key] = []\n }\n this._onActionOnErrorSubscriptions[key]?.push(callback)\n }\n\n private addResetStoreCallback(store: Store, callback: NonNullable<PluginSubscriber['resetStoreCallback']>): void {\n if (!this._resetStoreCallback.has(store)) {\n this._resetStoreCallback.set(store, new Set())\n }\n this._resetStoreCallback.get(store)!.add(callback)\n }\n\n private clearOnActionCallbacksSubscriptions(storageKey: string): void {\n delete this._onActionAfterSubscriptions[storageKey]\n delete this._onActionOnErrorSubscriptions[storageKey]\n }\n\n private clearStoreTracking(store: Store): void {\n this._onActionSubscriptions.delete(store)\n this._onActionStores.delete(store)\n this._resetStoreCallback.delete(store)\n const suffix = `-${store.$id}`\n\n for (const key of Array.from(this._subscribersDelivered)) {\n if (key.endsWith(suffix)) {\n this._subscribersDelivered.delete(key)\n }\n }\n\n for (const key of Array.from(this._subscribersScheduled)) {\n if (key.endsWith(suffix)) {\n this._subscribersScheduled.delete(key)\n }\n }\n\n for (const key of Array.from(this._subscriptionsDelivered)) {\n if (key.endsWith(suffix)) {\n this._subscriptionsDelivered.delete(key)\n }\n }\n\n for (const key of Array.from(this._subscriptionsScheduled)) {\n if (key.endsWith(suffix)) {\n this._subscriptionsScheduled.delete(key)\n }\n }\n\n for (const key of Object.keys(this._onActionAfterSubscriptions)) {\n if (key.endsWith(suffix)) {\n delete this._onActionAfterSubscriptions[key]\n }\n }\n\n for (const key of Object.keys(this._onActionOnErrorSubscriptions)) {\n if (key.endsWith(suffix)) {\n delete this._onActionOnErrorSubscriptions[key]\n }\n }\n }\n\n /**\n * Creates a callback collector for the specified action and store.\n * @param actionName The name of the action to collect callbacks for.\n * @param store The store instance associated with the action.\n * @returns A function that collects callbacks for the specified action and store.\n */\n private createOnActionAfterCallbackCollector(actionName: string, store: Store) {\n return (callback: StoreOnActionAfterCallbackParameter) => {\n this.addOnActionAfterCallback(actionName, store, callback)\n }\n }\n\n /**\n * Creates a callback collector for the specified action and store that handles errors.\n * @param actionName The name of the action to collect error callbacks for.\n * @param store The store instance associated with the action.\n * @returns A function that collects error callbacks for the specified action and store.\n */\n private createOnActionOnErrorCallbackCollector(actionName: string, store: Store) {\n return (callback: (error: unknown) => void) => {\n this.addOnActionOnErrorCallback(actionName, store, callback)\n }\n }\n\n /**\n * Rolls back the state snapshot for a given action if an error occurs, and removes the snapshot after the action completes or fails.\n * @param actionName The name of the action being executed.\n * @param store The Pinia store instance.\n * @returns void\n */\n private createRollbackSnapshot(\n actionName: string,\n store: Store\n ) {\n const {\n after,\n onError\n } = this._storeRollbackSnapshotsHandler.createOnActionCallbacks(\n actionName,\n store\n ) ?? {}\n\n if (!after || !onError) {\n return\n }\n\n this.addOnActionAfterCallback(actionName, store, after)\n this.addOnActionOnErrorCallback(actionName, store, onError)\n }\n\n private defineCurrentEnvironment(): PluginRuntimeEnvironment {\n return this._options?.runtimeEnvironment\n ?? (typeof window === 'undefined' ? 'server' : 'client')\n }\n\n private definePluginDebug(subscriber: PluginSubscriber): boolean {\n return !!this._pluginDebug?.includes(subscriber.name)\n }\n\n private definePluginExecution(subscriber: PluginSubscriber): Required<PluginExecutionOptions> {\n return {\n ...defaultPluginExecution,\n ...(this._options?.execution ?? {}),\n ...(subscriber.execution ?? {}),\n ...(this._options?.subscriberExecution?.[subscriber.name] ?? {}),\n }\n }\n\n private defineHydrationScheduler(subscriber: PluginSubscriber | PluginSubscriptionDefinition['subscription']): PluginHydrationScheduler {\n return subscriber.hydrationScheduler ?? this._hydrationScheduler\n }\n\n private defineSubscriberKey(subscriber: PluginSubscriber, store: Store): string {\n return `${subscriber.name}-${store.$id}`\n }\n\n private defineSubscriptionKey(pluginName: string, store: Store): string {\n return `${pluginName}-${store.$id}`\n }\n\n private executeResetStoreCallbacks(store: Store): void {\n this._resetStoreCallback.get(store)?.forEach(callback => callback(store))\n }\n\n /**\n * Executes the store's onAction subscription for the given plugin subscriber.\n * @param store The Pinia store instance.\n * @param subscriber The plugin subscriber.\n * @returns void\n */\n private executeStoreOnActionSubscription(store: Store): void {\n if (this._onActionStores.has(store) || typeof store.$onAction !== 'function') {\n return\n }\n const onActionSubscriptions = this._onActionSubscriptions.get(store)\n const hasRollbackSnapshots = this._storeRollbackSnapshotsHandler.storeHasRollbackSnapshots(store)\n\n if (!onActionSubscriptions?.size && !hasRollbackSnapshots) {\n return\n }\n\n this._onActionStores.add(store)\n store.$onAction(({ after, args, name, onError }) => {\n const storageKey = getActionStoreKey(name, store)\n this.debugLog(`storeOnActionSubscription ${storageKey}`, { args, name, store })\n\n if (this._storeRollbackSnapshotsHandler.storeHasRollbackSnapshots(store)) {\n this.createRollbackSnapshot(name, store)\n }\n\n const callbacks = this._onActionSubscriptions.get(store)\n if (callbacks?.size) {\n callbacks.forEach(callback => callback({\n after: this.createOnActionAfterCallbackCollector(name, store),\n args,\n name,\n onError: this.createOnActionOnErrorCallbackCollector(name, store)\n }))\n }\n\n const afterCallbacks = this._onActionAfterSubscriptions[storageKey]\n const onErrorCallbacks = this._onActionOnErrorSubscriptions[storageKey]\n\n this.clearOnActionCallbacksSubscriptions(storageKey)\n\n if (afterCallbacks?.length) {\n after((result) => {\n afterCallbacks.forEach(callback => callback(result))\n })\n }\n if (onErrorCallbacks?.length) {\n onError((error) => {\n onErrorCallbacks.forEach(callback => callback(error))\n })\n }\n })\n }\n\n private executeSubscriber(context: PiniaPluginContext, subscriber: PluginSubscriber): void {\n const subscriberKey = this.defineSubscriberKey(subscriber, context.store)\n const debug = this.definePluginDebug(subscriber)\n\n if (this._subscribersDelivered.has(subscriberKey)) {\n return\n }\n\n if (\n !subscriber.invoke(\n context,\n debug\n )) {\n return\n }\n\n this._subscribersDelivered.add(subscriberKey)\n\n let hydrateResult: void | Promise<void>\n\n try {\n hydrateResult = subscriber.hydrate?.(context, debug)\n } catch (error) {\n this.logError(error, context.store, context.options)\n return\n }\n\n const runAfterHydration = () => {\n try {\n const afterHydration = subscriber.afterHydration?.(context, debug)\n if (afterHydration && typeof (afterHydration as Promise<void>).then === 'function') {\n ; (afterHydration as Promise<void>).catch(error => this.logError(error, context.store, context.options))\n }\n } catch (error) {\n this.logError(error, context.store, context.options)\n }\n }\n\n if (hydrateResult && typeof (hydrateResult as Promise<void>).then === 'function') {\n ; (hydrateResult as Promise<void>)\n .then(() => runAfterHydration())\n .catch(error => this.logError(error, context.store, context.options))\n } else {\n runAfterHydration()\n }\n\n if (subscriber.subscriptions) {\n this.subscriptionDelivery(context, subscriber.subscriptions)\n }\n\n if (subscriber.storeMutationSubscription) {\n this.storeMutationSubscription(subscriber.storeMutationSubscription)\n }\n\n this.storeOnActionSubscription(subscriber)\n\n if (subscriber.resetStoreCallback) {\n this.addResetStoreCallback(context.store, subscriber.resetStoreCallback)\n }\n }\n\n private executeSubscriberSafely(context: PiniaPluginContext, subscriber: PluginSubscriber): void {\n try {\n this.executeSubscriber(context, subscriber)\n } catch (e) {\n this.logError(e, context.store, context.options)\n }\n }\n\n plugin({ store, options }: PiniaPluginContext) {\n if (!this._subscribers.length) {\n return\n }\n\n this.debugLog(`plugin() - ${store.$id}`, [\n 'subscriber:', this._subscribers,\n 'store:', store,\n 'options:', options\n ])\n\n try {\n this._subscribers.forEach(\n subscriber => {\n const subscriberKey = this.defineSubscriberKey(subscriber, store)\n const execution = this.definePluginExecution(subscriber)\n\n if (\n this._subscribersDelivered.has(subscriberKey)\n || this._subscribersScheduled.has(subscriberKey)\n ) {\n return\n }\n\n if (!this.shouldInvokePlugin(execution)) {\n return\n }\n\n if (this.shouldScheduleAfterHydration(execution)) {\n this.queueSubscriberExecution({ store, options } as PiniaPluginContext, subscriber, subscriberKey)\n return\n }\n\n this.executeSubscriber({ store, options } as PiniaPluginContext, subscriber)\n }\n )\n\n this.rewriteResetStore({ store } as PiniaPluginContext, store.$state)\n this._storeRollbackSnapshotsHandler.initFromPluginContext({ store, options } as PiniaPluginContext)\n this.executeStoreOnActionSubscription(store)\n this.registerStoreCleanup(store)\n } catch (e) {\n this.logError(e, store, options)\n }\n }\n\n private queueSubscriberExecution(\n context: PiniaPluginContext,\n subscriber: PluginSubscriber,\n subscriberKey: string\n ): void {\n const scheduler = this.defineHydrationScheduler(subscriber)\n\n this._subscribersScheduled.add(subscriberKey)\n scheduler(() => {\n if (this._disposedStores.has(context.store)) {\n return\n }\n this._subscribersScheduled.delete(subscriberKey)\n this.executeSubscriberSafely(context, subscriber)\n })\n }\n\n private registerStoreCleanup(store: Store): void {\n if (typeof store.$dispose !== 'function') {\n return\n }\n\n const dispose = store.$dispose.bind(store)\n const scopedStore = store as AnyObject\n\n if (scopedStore.__piniaPluginSubscriptionDisposed) {\n return\n }\n\n scopedStore.__piniaPluginSubscriptionDisposed = true\n store.$dispose = () => {\n this._disposedStores.add(store)\n this.clearStoreTracking(store)\n this._storeRollbackSnapshotsHandler.clearStoreTracking(store)\n return dispose()\n }\n }\n\n private rewriteResetStore({ store }: PiniaPluginContext, initState: StateTree): void {\n const safeState = deepClone(initState)\n\n store.$reset = () => {\n this.debugLog('rewriteResetStore()', { initState: safeState, store })\n\n this.executeResetStoreCallbacks(store)\n\n store.$patch(deepClone(safeState))\n }\n }\n\n private shouldInvokePlugin(execution: Required<PluginExecutionOptions>): boolean {\n const currentEnvironment = this.defineCurrentEnvironment()\n\n return execution.environment === 'both' || execution.environment === currentEnvironment\n }\n\n private shouldScheduleAfterHydration(execution: Required<PluginExecutionOptions>): boolean {\n return this.defineCurrentEnvironment() === 'client' && execution.hydration === 'defer'\n }\n\n private storeOnActionSubscription(subscriber: PluginSubscriber): void {\n const { store, callback } = subscriber?.storeOnActionSubscription?.() ?? {}\n\n if (!store || !callback) {\n return\n }\n\n if (!this._onActionSubscriptions.has(store)) {\n this._onActionSubscriptions.set(store, new Set())\n }\n this._onActionSubscriptions.get(store)!.add(callback)\n this.executeStoreOnActionSubscription(store)\n }\n\n private storeMutationSubscription(subscription: StoreMutationSubscription): void {\n const { store, callback } = subscription()\n\n store.$subscribe((mutation: SubscriptionCallbackMutation<StateTree>) => {\n this.debugLog(`$subscribe ${store.$id}`, { mutation, store })\n callback(mutation)\n })\n }\n\n private subscriptionDelivery(\n context: PiniaPluginContext,\n pluginSubscriptions: PluginSubscriptions\n ): void {\n Object.entries(pluginSubscriptions).forEach(([pluginName, pluginSubscription]) => {\n const subscriptionKey = this.defineSubscriptionKey(pluginName, context.store)\n const execution = this.definePluginExecution(pluginSubscription.subscription)\n\n if (\n this._subscriptionsDelivered.has(subscriptionKey)\n || this._subscriptionsScheduled.has(subscriptionKey)\n ) {\n return\n }\n\n if (!this.shouldInvokePlugin(execution)) {\n return\n }\n\n if (this.shouldScheduleAfterHydration(execution)) {\n const scheduler = this.defineHydrationScheduler(pluginSubscription.subscription)\n\n this._subscriptionsScheduled.add(subscriptionKey)\n scheduler(() => {\n if (this._disposedStores.has(context.store)) {\n return\n }\n this._subscriptionsScheduled.delete(subscriptionKey)\n this.subscriptionDeliverySafely(context, pluginName, pluginSubscription)\n })\n return\n }\n\n this.subscriptionDeliverySafely(context, pluginName, pluginSubscription)\n })\n }\n\n private subscriptionDeliverySafely(\n { store, options }: PiniaPluginContext,\n pluginName: string,\n pluginSubscription: PluginSubscriptionDefinition\n ): void {\n try {\n if (this._subscriptionsDelivered.has(this.defineSubscriptionKey(pluginName, store))) {\n return\n }\n\n const { subscription, subscriptionOptions, stores } = pluginSubscription\n\n this.debugLog(`subscriptionDelivery() - store: ${store.$id}`, [\n 'pluginName:', pluginName,\n 'subscription:', subscription,\n 'options:', pluginSubscription,\n 'stores:', stores\n ])\n\n const pluginOptions = {\n storeOptions: { ...((options as AnyObject)?.storeOptions ?? {}), ...subscriptionOptions }\n } as AnyObject\n\n subscription.invoke(\n { store, options: { ...options, ...pluginOptions } } as PiniaPluginContext,\n this.debug\n )\n this._subscriptionsDelivered.add(this.defineSubscriptionKey(pluginName, store))\n\n if (!isEmpty(stores)) {\n stores?.forEach(\n store => subscription.invoke(\n {\n store,\n options: {\n ...options,\n ...pluginOptions,\n ...((store as AnyObject)?.storeOptions ?? {})\n }\n } as PiniaPluginContext,\n this.debug\n )\n )\n }\n } catch (e) {\n this.logError(`subscriptionDelivery()`, e, store, options)\n }\n }\n}"],"names":["deepClone","value","key","entryValue","item","clonedObject","createStateSnapshot","state","keys","clonedState","toRaw","RollbackStateSnapshotsHandler","__publicField","store","action","stateKeys","args","actionFn","hasDeniedFirstChar","snapshotKey","error","actionName","getActionStoreKey","options","rollbackSnapshotParams","suffix","stateSnapshot","className","defaultPluginExecution","defaultHydrationScheduler","callback","isPluginSubscriptionOptions","PluginSubscription","Debug","subscribers","debugOrOptions","pluginOptions","debug","PluginConsole","storageKey","after","onError","subscriber","pluginName","onActionSubscriptions","hasRollbackSnapshots","name","callbacks","afterCallbacks","onErrorCallbacks","result","context","subscriberKey","hydrateResult","runAfterHydration","afterHydration","e","execution","scheduler","dispose","scopedStore","initState","safeState","currentEnvironment","subscription","mutation","pluginSubscriptions","pluginSubscription","subscriptionKey","subscriptionOptions","stores","isEmpty","store2","createPlugin","createHydrationPlugin","hydrationPlugin"],"mappings":";;;;;;AAMO,SAASA,EAAaC,GAAa;AACtC,MAAI,OAAO,mBAAoB;AAC3B,QAAI;AACA,aAAO,gBAAgBA,CAAK;AAAA,IAChC,QAAQ;AAAA,IAER;AAGJ,MAAIA,MAAU,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|
|
9
9
|
* Added to every store when the plugin is active.
|
|
10
|
+
*
|
|
11
|
+
* @param params The action name and the state keys to snapshot.
|
|
12
|
+
* @param args The action arguments, passed as a single array (forwarded via `apply`).
|
|
10
13
|
*/
|
|
11
|
-
$rollbackAfterFailure: (params: RollbackActionParams,
|
|
14
|
+
$rollbackAfterFailure: (params: RollbackActionParams, args?: any[]) => Promise<void>;
|
|
12
15
|
}
|
|
13
16
|
interface DefineStoreOptionsBase<S, Store> {
|
|
14
17
|
storeOptions?: StoreOptions;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compile-only contract for the centralized store-options extension point.
|
|
3
|
+
* Simulates a subscriber plugin augmenting the contract through interface
|
|
4
|
+
* merging, instead of redeclaring pinia's `DefineStoreOptionsBase` (which
|
|
5
|
+
* would raise TS2717 on type mismatch in consumer projects).
|
|
6
|
+
*/
|
|
7
|
+
declare module '../types' {
|
|
8
|
+
interface StoreOptionsExtensions {
|
|
9
|
+
testExtension?: string;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export {};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export type ConsoleStyleDefinition = StyleDefinition;
|
|
|
19
19
|
export type ConsoleStyleDefinitionKeys = StyleDefinitionKeys;
|
|
20
20
|
export type ConsoleStyleDefinitions = StyleDefinitions;
|
|
21
21
|
export type { List, ListTypes, ListTypesMap, PartialList } from './list';
|
|
22
|
-
export type { CustomStore, DefineAStoreSetupContext, DefineAStoreSetupExtensions, EmptyExtensions, PluginStoreOptions, StatePropertyValue, StoreOptions, StoreOptionsPropertyValue } from './store';
|
|
22
|
+
export type { CustomStore, DefineAStoreDefinition, DefineAStoreSetupContext, DefineAStoreSetupExtensions, EmptyExtensions, PluginStoreOptions, StatePropertyValue, StoreOptions, StoreOptionsExtensions, StoreOptionsPropertyValue, StrictStateTree } from './store';
|
|
23
23
|
export type { NativePiniaSubscription, NativePiniaSubscriptionReturn, PluginExecutionEnvironment, PluginExecutionOptions, PluginHydrationScheduler, PluginHydrationTiming, PluginRuntimeEnvironment, PluginSubscriber, PluginSubscription, PluginSubscriptionOptions, PluginSubscriptions, StoreMutationSubscription, StoreMutationSubscriptionCallback, StoreMutationSubscriptionReturn, StoreOnActionCallbackParameters, StoreOnActionSubscription, StoreOnActionSubscriptionCallback, StoreOnActionSubscriptionReturn, } from './plugin';
|
|
24
24
|
export interface PluginSubscriberInterface {
|
|
25
25
|
console?: Console;
|