pinia-plugin-subscription 0.2.1 → 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.
@@ -1,158 +1,153 @@
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
- function u(n) {
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(n);
10
+ return structuredClone(r);
11
11
  } catch {
12
12
  }
13
- if (n === null || typeof n != "object")
14
- return n;
15
- if (n instanceof Map)
13
+ if (r === null || typeof r != "object")
14
+ return r;
15
+ if (r instanceof Map)
16
16
  return new Map(
17
- Array.from(n.entries(), ([t, e]) => [u(t), u(e)])
17
+ Array.from(r.entries(), ([e, i]) => [h(e), h(i)])
18
18
  );
19
- if (n instanceof Set)
20
- return new Set(Array.from(n.values(), (t) => u(t)));
21
- if (Array.isArray(n))
22
- return n.map((t) => u(t));
23
- if (Object.getPrototypeOf(n) === Object.prototype || Object.getPrototypeOf(n) === null)
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(n).map(([t, e]) => [t, u(e)])
25
+ Object.entries(r).map(([e, i]) => [e, h(i)])
26
26
  );
27
- const s = Object.create(Object.getPrototypeOf(n));
28
- for (const [t, e] of Object.entries(n))
29
- s[t] = u(e);
30
- return s;
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 w(n, s = "all") {
33
- if (Array.isArray(s)) {
34
- const t = {};
35
- for (const e of s)
36
- e in n && (t[e] = u(A(n[e])));
37
- return t;
38
- }
39
- if (s !== "all")
40
- throw new Error(`Invalid keys parameter: ${s}`);
41
- return u(A(n));
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 R {
43
+ class $ {
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(s) {
50
- typeof s.$rollbackAfterFailure != "function" && (s.$rollbackAfterFailure = async ({ action: t, stateKeys: e }, i = []) => {
51
- const r = s[t];
52
- if (typeof r != "function" || C(t))
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 = !e || e.length === 0 ? "all" : e, h = this.saveStateSnapshot(s, t, o);
54
+ const o = !i || i.length === 0 ? "all" : i, a = this.saveStateSnapshot(t, e, o);
55
55
  try {
56
- await r.apply(s, i);
57
- } catch (a) {
58
- throw this.patchStore(h, s), a;
56
+ await n.apply(t, s);
57
+ } catch (l) {
58
+ throw this.patchStore(a, t), l;
59
59
  } finally {
60
- this.removeStateSnapshot(h);
60
+ this.removeStateSnapshot(a);
61
61
  }
62
62
  });
63
63
  }
64
- createOnActionCallbacks(s, t) {
65
- const e = this._storeRollbackSnapshotsParams.get(
66
- S(s, t)
64
+ createOnActionCallbacks(t, e) {
65
+ const i = this._storeRollbackSnapshotsParams.get(
66
+ b(t, e)
67
67
  );
68
- if (!e)
68
+ if (!i)
69
69
  return;
70
- const i = e.length === 0 ? "all" : e, r = this.saveStateSnapshot(t, s, i);
70
+ const s = i.length === 0 ? "all" : i, n = this.saveStateSnapshot(e, t, s);
71
71
  return {
72
72
  after: () => {
73
- this.removeStateSnapshot(r);
73
+ this.removeStateSnapshot(n);
74
74
  },
75
75
  onError: () => {
76
- this.patchStore(r, t), this.removeStateSnapshot(r);
76
+ this.patchStore(n, e), this.removeStateSnapshot(n);
77
77
  }
78
78
  };
79
79
  }
80
- initFromPluginContext({ options: s, store: t }) {
81
- const e = s?.storeOptions?.rollbackAfterFailure;
82
- e && !this._storeHasRollbackSnapshots.has(t.$id) && (Object.keys(e).forEach((i) => {
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
- S(i, t),
85
- e[i]
84
+ b(s, e),
85
+ i[s]
86
86
  );
87
- }), this._storeHasRollbackSnapshots.add(t.$id)), this.addRollbackAction(t);
88
- }
89
- clearStoreTracking(s) {
90
- const t = `-${s.$id}`;
91
- for (const e of Array.from(this._storeRollbackSnapshotsParams.keys()))
92
- e.endsWith(t) && this._storeRollbackSnapshotsParams.delete(e);
93
- this._storeHasRollbackSnapshots.delete(s.$id);
94
- for (const e of Array.from(this._stateSnapshots.keys()))
95
- e.description?.startsWith(`${s.$id}:`) && this._stateSnapshots.delete(e);
96
- }
97
- patchStore(s, t) {
98
- const e = this._stateSnapshots.get(s);
99
- if (e)
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
- t.$patch(e);
102
- } catch (i) {
103
- console.error(`Failed to patch store with snapshot ${String(s)}`, i);
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(s) {
107
- s && this._stateSnapshots.delete(s);
106
+ removeStateSnapshot(t) {
107
+ t && this._stateSnapshots.delete(t);
108
108
  }
109
- saveStateSnapshot(s, t, e) {
110
- const i = w(
111
- s.$state,
112
- e
113
- ), r = /* @__PURE__ */ Symbol(`${s.$id}:${t}`);
114
- return this._stateSnapshots.set(r, i), r;
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(s) {
117
- return this._storeHasRollbackSnapshots.has(s.$id);
116
+ storeHasRollbackSnapshots(t) {
117
+ return this._storeHasRollbackSnapshots.has(t.$id);
118
118
  }
119
119
  }
120
- const k = "PluginSubscription", v = {
120
+ const m = "PluginSubscription", C = {
121
121
  environment: "both",
122
122
  hydration: "immediate"
123
123
  };
124
- function P(n) {
124
+ function w(r) {
125
125
  if (typeof window < "u" && typeof window.requestAnimationFrame == "function") {
126
- window.requestAnimationFrame(() => globalThis.setTimeout(n, 0));
126
+ window.requestAnimationFrame(() => globalThis.setTimeout(r, 0));
127
127
  return;
128
128
  }
129
- globalThis.setTimeout(n, 0);
130
- }
131
- function D(n) {
132
- return n !== void 0 && !Array.isArray(n);
129
+ globalThis.setTimeout(r, 0);
133
130
  }
134
- class g extends m {
135
- constructor(t, e, i) {
136
- const r = Array.isArray(e) ? e : void 0, o = D(e) ? e : i;
137
- super(Array.isArray(r) && !!r?.includes(k), $);
138
- c(this, "_className", k);
131
+ class A {
132
+ constructor(t, e) {
133
+ c(this, "_className", m);
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 R());
142
+ c(this, "_storeRollbackSnapshotsHandler", new $());
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._hydrationScheduler = o?.hydrationScheduler ?? P, this._options = o, this._pluginDebug = Array.isArray(r) ? r : void 0, this._subscribers = t;
149
+ c(this, "_tracer");
150
+ this._hydrationScheduler = e?.hydrationScheduler ?? w, 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 r = S(t, e);
166
- this._onActionAfterSubscriptions[r] || (this._onActionAfterSubscriptions[r] = []), this._onActionAfterSubscriptions[r]?.push(i);
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 r = S(t, e);
170
- this._onActionOnErrorSubscriptions[r] || (this._onActionOnErrorSubscriptions[r] = []), this._onActionOnErrorSubscriptions[r]?.push(i);
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: r
202
+ onError: s
208
203
  } = this._storeRollbackSnapshotsHandler.createOnActionCallbacks(
209
204
  t,
210
205
  e
211
206
  ) ?? {};
212
- !i || !r || (this.addOnActionAfterCallback(t, e, i), this.addOnActionOnErrorCallback(t, e, r));
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
- ...v,
214
+ ...C,
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: 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({
249
- after: this.createOnActionAfterCallbackCollector(h, t),
250
- args: o,
251
- name: h,
252
- onError: this.createOnActionOnErrorCallbackCollector(h, 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)
253
249
  }));
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));
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));
259
255
  });
260
256
  }));
261
257
  }
262
258
  executeSubscriber(t, e) {
263
- const i = this.defineSubscriberKey(e, t.store), r = this.definePluginDebug(e);
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 o;
263
+ let s;
271
264
  try {
272
- o = e.hydrate?.(t, r);
273
- } catch (a) {
274
- this.logError(a, t.store, t.options);
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 h = () => {
270
+ const n = () => {
278
271
  try {
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);
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
- 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);
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.logError(i, t.store, t.options);
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("PluginSubscription"));
289
+ }
294
290
  plugin({ store: t, options: e }) {
295
291
  if (this._subscribers.length) {
296
- this.debugLog(`plugin() - ${t.$id}`, [
297
- "subscriber:",
298
- this._subscribers,
299
- "store:",
300
- t,
301
- "options:",
302
- e
303
- ]);
292
+ this.trace("plugin:invoke", () => ({
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 r = this.defineSubscriberKey(i, t), o = this.definePluginExecution(i);
308
- if (!(this._subscribersDelivered.has(r) || this._subscribersScheduled.has(r)) && this.shouldInvokePlugin(o)) {
309
- if (this.shouldScheduleAfterHydration(o)) {
310
- this.queueSubscriberExecution({ store: t, options: e }, i, r);
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.logError(i, t, e);
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 r = this.defineHydrationScheduler(e);
324
- this._subscribersScheduled.add(i), r(() => {
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 = u(e);
328
+ const i = h(e);
336
329
  t.$reset = () => {
337
- this.debugLog("rewriteResetStore()", { initState: i, store: t }), this.executeResetStoreCallbacks(t), t.$patch(u(i));
330
+ this.trace("plugin: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((r) => {
354
- this.debugLog(`$subscribe ${e.$id}`, { mutation: r, store: e }), i(r);
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, r]) => {
359
- const o = this.defineSubscriptionKey(i, t.store), h = this.definePluginExecution(r.subscription);
360
- if (!(this._subscriptionsDelivered.has(o) || this._subscriptionsScheduled.has(o)) && this.shouldInvokePlugin(h)) {
361
- if (this.shouldScheduleAfterHydration(h)) {
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));
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, r);
364
+ this.subscriptionDeliverySafely(t, i, s);
369
365
  }
370
366
  });
371
367
  }
372
- subscriptionDeliverySafely({ store: t, options: e }, i, r) {
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: o, subscriptionOptions: h, stores: a } = r;
377
- this.debugLog(`subscriptionDelivery() - store: ${t.$id}`, [
378
- "pluginName:",
379
- i,
380
- "subscription:",
381
- o,
382
- "options:",
383
- r,
384
- "stores:",
385
- a
386
- ]);
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);
387
379
  const l = {
388
- storeOptions: { ...e?.storeOptions ?? {}, ...h }
380
+ storeOptions: { ...e?.storeOptions ?? {}, ...o }
389
381
  };
390
- o.invoke(
391
- { store: t, options: { ...e, ...l } },
392
- this.debug
382
+ n.invoke(
383
+ { store: t, options: { ...e, ...l } }
393
384
  ), this._subscriptionsDelivered.add(this.defineSubscriptionKey(i, t)), _(a) || a?.forEach(
394
- (d) => o.invoke(
395
- {
396
- store: d,
397
- options: {
398
- ...e,
399
- ...l,
400
- ...d?.storeOptions ?? {}
401
- }
402
- },
403
- this.debug
404
- )
385
+ (u) => n.invoke({
386
+ store: u,
387
+ options: {
388
+ ...e,
389
+ ...l,
390
+ ...u?.storeOptions ?? {}
391
+ }
392
+ })
405
393
  );
406
- } catch (o) {
407
- this.logError("subscriptionDelivery()", o, t, e);
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 && 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
+ }
410
404
  }
411
- function K(n, s) {
412
- const t = new g(n, s);
413
- return t.plugin.bind(t);
405
+ function H(r, t) {
406
+ const e = new A(r, t);
407
+ return e.plugin.bind(e);
414
408
  }
415
- function M(n, s) {
416
- const t = new g(n, s?.debug, {
417
- execution: s?.execution,
418
- hydrationScheduler: s?.hydrationScheduler,
419
- runtimeEnvironment: s?.runtimeEnvironment,
420
- subscriberExecution: s?.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
421
415
  });
422
- return t.plugin.bind(t);
416
+ return e.plugin.bind(e);
423
417
  }
424
418
  export {
425
- T as CustomConsole,
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,
433
- G as defineAStoreCtx,
434
- U as getDefineAStoreSetupContext,
435
- B as getEnhancedStore,
436
- J as getExtendingStore,
437
- _ as isEmpty,
438
- Q 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
439
431
  };
440
432
  //# sourceMappingURL=pinia-plugin-subscription.js.map