pinia-plugin-subscription 1.0.0-beta.2 → 1.0.0-beta.20

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.
Files changed (77) hide show
  1. package/CHANGELOG.md +73 -12
  2. package/CONTRIBUTING.md +10 -1
  3. package/README.md +48 -293
  4. package/SECURITY.md +6 -6
  5. package/dist/chunks/setup-context-3G3Hy1ep.js +909 -0
  6. package/dist/dictionaries/plugin-subscription-event.d.ts +20 -0
  7. package/dist/{core/Store.d.ts → enhanced-store/EnhancedStore.d.ts} +24 -29
  8. package/dist/enhanced-store/define-a-store.d.ts +64 -0
  9. package/dist/enhanced-store/setup-context.d.ts +27 -0
  10. package/dist/events/EventsEmitter.d.ts +9 -0
  11. package/dist/events/EventsSubscriber.d.ts +32 -0
  12. package/dist/events/EventsSubscription.d.ts +13 -0
  13. package/dist/events/StoreEvent.d.ts +6 -0
  14. package/dist/events/StoresEventsSubscriptionsRegistry.d.ts +31 -0
  15. package/dist/events/event.d.ts +8 -0
  16. package/dist/factories/events-registry.d.ts +9 -0
  17. package/dist/factories/events-subscriber.d.ts +11 -0
  18. package/dist/factories/messenger-registry.d.ts +16 -0
  19. package/dist/factories/plugin-subscriber.d.ts +17 -0
  20. package/dist/helpers.js +204 -312
  21. package/dist/lib/helpers.d.ts +9 -0
  22. package/dist/lib/main.d.ts +3 -12
  23. package/dist/orchestration/ExecutionPolicy.d.ts +15 -0
  24. package/dist/orchestration/PluginOrchestrator.d.ts +41 -0
  25. package/dist/orchestration/SubscriberScheduler.d.ts +31 -0
  26. package/dist/pinia-plugin-subscription.js +31 -426
  27. package/dist/plugins/createPlugin.d.ts +3 -13
  28. package/dist/services/messenger.d.ts +28 -0
  29. package/dist/services/messengerProvider.d.ts +45 -0
  30. package/dist/store-hooks/StoreHooksBinder.d.ts +20 -0
  31. package/dist/store-hooks/StoreHooksRegistry.d.ts +34 -0
  32. package/dist/{core/PluginSubscriber.d.ts → subscribers/StoreSubscriber.d.ts} +39 -28
  33. package/dist/tracing/TraceGroupHelper.d.ts +27 -0
  34. package/dist/tracing/TraceableEmitter.d.ts +60 -0
  35. package/dist/tracing/TraceableEventsSubscriber.d.ts +21 -0
  36. package/dist/tracing/TraceableStoreEventsSubscriber.d.ts +16 -0
  37. package/dist/tracing/trace-groups.d.ts +9 -0
  38. package/dist/types/core.d.ts +12 -0
  39. package/dist/types/events.d.ts +24 -0
  40. package/dist/types/index.d.ts +8 -34
  41. package/dist/types/messenger.d.ts +20 -0
  42. package/dist/types/plugin.d.ts +39 -20
  43. package/dist/types/store.d.ts +1 -9
  44. package/dist/types/trace.d.ts +35 -75
  45. package/dist/utils/constants.d.ts +4 -0
  46. package/dist/utils/events.d.ts +3 -0
  47. package/dist/utils/id.d.ts +20 -0
  48. package/dist/utils/store.d.ts +9 -93
  49. package/docs/authoring-plugins.md +330 -78
  50. package/docs/using-plugins.md +89 -53
  51. package/package.json +14 -8
  52. package/dist/chunks/constantes-CaTNAbzX.js +0 -261
  53. package/dist/chunks/constantes-CaTNAbzX.js.map +0 -1
  54. package/dist/core/PluginSubscription.d.ts +0 -92
  55. package/dist/core/RollbackStateSnapshotsHandler.d.ts +0 -65
  56. package/dist/factories/console-trace-listener.d.ts +0 -7
  57. package/dist/factories/state-snapshot.d.ts +0 -3
  58. package/dist/factories/trace-listener.d.ts +0 -16
  59. package/dist/factories/trace-registry.d.ts +0 -17
  60. package/dist/helpers/index.d.ts +0 -9
  61. package/dist/helpers.js.map +0 -1
  62. package/dist/pinia-plugin-subscription.js.map +0 -1
  63. package/dist/plugins/createHydrationPlugin.d.ts +0 -10
  64. package/dist/system/Tracer.d.ts +0 -20
  65. package/dist/system/log.d.ts +0 -35
  66. package/dist/tests/defineAStore.test-d.d.ts +0 -1
  67. package/dist/tests/storeOptionsExtensions.test-d.d.ts +0 -12
  68. package/dist/types/comparison.d.ts +0 -3
  69. package/dist/types/list.d.ts +0 -13
  70. package/dist/types/log.d.ts +0 -8
  71. package/dist/types/resourceId.d.ts +0 -4
  72. package/dist/utils/Performance.d.ts +0 -9
  73. package/dist/utils/constantes.d.ts +0 -1
  74. package/dist/utils/deep-clone.d.ts +0 -7
  75. package/dist/utils/defineStoreId.d.ts +0 -1
  76. package/dist/utils/object.d.ts +0 -4
  77. package/dist/utils/validation/object.d.ts +0 -9
package/dist/helpers.js CHANGED
@@ -1,348 +1,240 @@
1
1
  var b = Object.defineProperty;
2
- var _ = (e, r, o) => r in e ? b(e, r, { enumerable: !0, configurable: !0, writable: !0, value: o }) : e[r] = o;
3
- var c = (e, r, o) => _(e, typeof r != "symbol" ? r + "" : r, o);
4
- import { p as y } from "./chunks/constantes-CaTNAbzX.js";
5
- import { P as G, S as q, i as P } from "./chunks/constantes-CaTNAbzX.js";
6
- const m = (e, r = "white") => `background-color: ${e}; color: ${r}; padding: 1px; margin-right: 5px; font-size: 12px`;
7
- function l(e, r) {
8
- if (Array.isArray(r) ? r.length === 0 : Object.keys(r).length === 0) {
9
- console.log(
10
- "%c%s",
11
- "color: #f86f63; padding: 1px; margin-right: 5px; font-size: 10px",
12
- `[ ${e} ] Empty`
13
- );
14
- return;
15
- }
16
- if (console.groupCollapsed(
17
- "%c%s",
18
- "color: #fafa05; padding: 1px; margin-right: 5px; font-size: 11px",
19
- `[ ${e} ]`
20
- ), Array.isArray(r))
21
- typeof r[0] == "object" ? r.forEach((t) => {
22
- t._name ? l(t._name, t) : t._id ? l(t._id, t) : console.dir(t);
23
- }) : r.forEach((t, s) => {
24
- console.log(
25
- "%c%s",
26
- "color: #cae38f; padding: 1px; margin-right: 5px; font-size: 10px",
27
- `[ ${s} ]`,
28
- t
29
- );
2
+ var p = (n, s, t) => s in n ? b(n, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[s] = t;
3
+ var i = (n, s, t) => p(n, typeof s != "symbol" ? s + "" : s, t);
4
+ import { T as S, E as d, g as a, S as g, a as l, s as y, i as h, h as f } from "./chunks/setup-context-3G3Hy1ep.js";
5
+ import { P as D, b as V, c as $, d as k, e as q, t as C } from "./chunks/setup-context-3G3Hy1ep.js";
6
+ import { isRef as E, ref as v, toRef as O } from "vue";
7
+ class _ extends S {
8
+ constructor() {
9
+ super(...arguments);
10
+ i(this, "_eventsSubscriber");
11
+ }
12
+ initEventsSubscriber(t, e) {
13
+ const r = this._eventsRegistry?.createSubscriber(t, e);
14
+ r && (this._eventsSubscriber = r);
15
+ }
16
+ addEventSubscription(t, e, r) {
17
+ if (!this._eventsSubscriber) {
18
+ this.initEventsSubscriber(r?.scope ?? this._name, [new d(t, e, r)]);
19
+ return;
20
+ }
21
+ this._eventsSubscriber.addSubscription(t, e, r);
22
+ }
23
+ }
24
+ class x extends _ {
25
+ constructor(t) {
26
+ super({ prefixLabelWithName: !0 });
27
+ i(this, "_createInstance");
28
+ i(this, "execution");
29
+ i(this, "hydrationScheduler");
30
+ i(this, "pluginCreated");
31
+ i(this, "_pluginOptions");
32
+ i(this, "_storeInstances", /* @__PURE__ */ new WeakMap());
33
+ i(this, "_storeOnActionSubscription");
34
+ i(this, "_storeMutationSubscription");
35
+ i(this, "_subscriptions");
36
+ this._createInstance = t;
37
+ }
38
+ get pluginOptions() {
39
+ return this._pluginOptions;
40
+ }
41
+ set pluginOptions(t) {
42
+ this._pluginOptions = t;
43
+ }
44
+ getStoreInstance(t) {
45
+ return this._storeInstances.get(t);
46
+ }
47
+ get storeOnActionSubscription() {
48
+ return this._storeOnActionSubscription;
49
+ }
50
+ get storeMutationSubscription() {
51
+ return this._storeMutationSubscription;
52
+ }
53
+ get subscriptions() {
54
+ return this._subscriptions;
55
+ }
56
+ set subscriptions(t) {
57
+ this._subscriptions = t;
58
+ }
59
+ afterHydration(t) {
60
+ }
61
+ hydrate(t) {
62
+ }
63
+ invoke({ store: t, options: e }, r) {
64
+ this._tracer = r?.createTracer ? r.createTracer(this.name) : void 0, this._eventsRegistry = r?.eventsRegistry;
65
+ const o = this._createInstance(t, {
66
+ ...e,
67
+ ...this.pluginOptions,
68
+ createTracer: this._tracer ? (() => this._tracer) : void 0,
69
+ eventsRegistry: this._eventsRegistry
30
70
  });
31
- else {
32
- let t = [];
33
- Object.keys(r).forEach((s) => {
34
- const i = r[s];
35
- typeof i == "object" ? Array.isArray(i) ? typeof i[0] == "object" ? l(s, i) : (console.groupCollapsed(s), console.log(i), console.groupEnd()) : l(s, Object.assign({}, i)) : i ? console.log(
36
- "%c%s",
37
- "color: #b0fa05; padding: 1px; margin-right: 5px; font-size: 10px",
38
- `[ ${s} ]`,
39
- i
40
- ) : t.push(s);
41
- }), t.length && console.log(
42
- "%c%s",
43
- "color: #f86f63; font-size: 9px",
44
- "[ Empty properties ]",
45
- t
46
- );
71
+ return o ? (this._storeInstances.set(t, o), this._subscriptions = o.getSubscriptions(), this._storeMutationSubscription = o.storeSubscribe, this._storeOnActionSubscription = o.onAction, this.pluginCreated && this.pluginCreated(t), !0) : (this._storeInstances.delete(t), !1);
47
72
  }
48
- console.groupEnd();
49
73
  }
50
- function g(e) {
51
- Object.keys(e).forEach((r) => {
52
- if (["label", "namespace", "scope", "source"].includes(r))
53
- return;
54
- const o = e[r];
55
- if (o)
56
- switch (typeof o) {
57
- case "string":
58
- console.log(
59
- "%c%s",
60
- "color: #fafa05; padding: 1px; margin-right: 5px; font-size: 10px",
61
- `[ ${r} ]`,
62
- o
63
- );
64
- break;
65
- case "object":
66
- switch (r) {
67
- case "mutation":
68
- console.groupCollapsed("[mutation]"), console.dir(o), console.groupEnd();
69
- break;
70
- case "options":
71
- l(r, o?.storeOptions ?? o);
72
- break;
73
- case "payload":
74
- g(o);
75
- break;
76
- case "store":
77
- l(r, Object.keys(o).reduce((n, t) => (t.startsWith("$") && !["$id", "$state"].includes(t) || t.startsWith("_") || (n[t] = o[t]), n), {}));
78
- break;
79
- default:
80
- l(r, o);
74
+ const c = /* @__PURE__ */ new WeakMap();
75
+ class R extends _ {
76
+ addEventSubscription(s, t, e) {
77
+ this._eventsRegistry?.subscriptionsRegistry.add(this._store, s), super.addEventSubscription(s, t, {
78
+ ...e ?? {},
79
+ scope: e?.scope ?? this._store.$id,
80
+ instanceId: a(this._store)
81
+ });
82
+ }
83
+ initEventsSubscriber(s, t) {
84
+ t?.forEach((e) => {
85
+ e.scope || (e.instanceId = a(this._store)), this._eventsRegistry?.subscriptionsRegistry.add(this._store, e.name);
86
+ }), super.initEventsSubscriber(s, t), this.onDispose(() => {
87
+ this._eventsSubscriber?.unsubscribe(), this._eventsRegistry?.subscriptionsRegistry.clear(this._store);
88
+ });
89
+ }
90
+ onDispose(s) {
91
+ c.has(this._store) || c.set(this._store, []), c.get(this._store)?.push(s);
92
+ }
93
+ onStoreDispose() {
94
+ const s = c.get(this._store);
95
+ !s || s.length === 0 || this.addEventSubscription(
96
+ g.DISPOSE,
97
+ () => {
98
+ s?.forEach((t) => {
99
+ try {
100
+ t?.(this._store);
101
+ } catch (e) {
102
+ this.traceError("store:dispose:callback:error", e, this._store.$id);
81
103
  }
82
- break;
83
- case "function":
84
- console.dir(o);
85
- break;
86
- default:
87
- console.info(o);
88
- }
89
- });
90
- }
91
- function x(e, r) {
92
- if (!e)
93
- throw new Error("Style instructions are required");
94
- console.log(
95
- "%c%s",
96
- e,
97
- r.shift(),
98
- ...r
99
- );
104
+ });
105
+ },
106
+ { scope: this._store.$id }
107
+ );
108
+ }
100
109
  }
101
- function E(e, r, o) {
102
- if (!e)
103
- throw new Error("Style instructions are required");
104
- const n = r.shift(), t = r[0];
105
- console.groupCollapsed(
106
- "%c%s",
107
- e,
108
- `${n}
109
- `,
110
- t?.source
111
- ), r.forEach((s) => {
112
- switch (typeof s) {
113
- case "string":
114
- console.info(s);
115
- break;
116
- case "object":
117
- Array.isArray(s) ? console.table(s) : g(s);
118
- break;
119
- case "function":
120
- console.dir(s);
121
- break;
122
- default:
123
- console.info(s);
110
+ class u extends R {
111
+ constructor(t, e) {
112
+ super({ prefixLabelWithName: !0 });
113
+ i(this, "_name", "Store");
114
+ i(this, "_createTracer");
115
+ i(this, "_onAction");
116
+ i(this, "_options");
117
+ i(this, "_store");
118
+ i(this, "_storeSubscribe");
119
+ i(this, "_subscriptions", {});
120
+ if (this._options = e.storeOptions, this._store = t, this.initializeEventsRegistry(e), this.trace("instance:created", this.store.$id), this._options?.enhancedStore) {
121
+ const r = l(this.store);
122
+ r && (y(r, this.store), this.trace("setup:enhancedStore:success", this.store.$id));
124
123
  }
125
- }), console.groupCollapsed(
126
- "%c%s",
127
- "color: #fafa05; padding: 1px; margin-right: 5px; font-size: 10px",
128
- "[ trace ]"
129
- ), console.trace(), console.groupEnd(), console.groupEnd();
130
- }
131
- class A {
132
- constructor() {
133
- c(this, "_bgColor", "transparent");
134
- c(this, "_color", "#f2f286");
135
- c(this, "_icon", "🍍⚡");
136
- c(this, "_errorBgColor", "#d24545");
137
- c(this, "_errorColor", "white");
138
- c(this, "_errorIcon", "🍍⚠️");
139
- c(this, "_pluginName");
140
- c(this, "_styles", {
141
- error: { bgColor: this._errorBgColor, color: this._errorColor, icon: this._errorIcon },
142
- info: { bgColor: this._bgColor, color: this._color, icon: this._icon }
143
- });
144
124
  }
145
- formatMessage(r, o) {
146
- return this._pluginName ? ` [${o} ${this._pluginName}]
147
- ${r}
148
- ` : r;
125
+ get onAction() {
126
+ if (this._onAction)
127
+ return () => ({
128
+ store: this.store,
129
+ callback: this._onAction
130
+ });
149
131
  }
150
- generateStyle(r) {
151
- return m(r.bgColor, r.color);
132
+ set onAction(t) {
133
+ this._onAction = t;
152
134
  }
153
- getStyleDefinition(r) {
154
- return this._styles[r ?? "info"];
135
+ get options() {
136
+ return this._options;
155
137
  }
156
- log(...r) {
157
- this.useLog(
158
- this.getStyleDefinition(),
159
- r
160
- );
138
+ get state() {
139
+ return this._store.$state;
161
140
  }
162
- error(...r) {
163
- this.useLog(
164
- this.getStyleDefinition("error"),
165
- r
166
- );
141
+ set state(t) {
142
+ this._store.$state = t;
167
143
  }
168
- rebuildArgs(r, o) {
169
- if (typeof r == "string")
170
- return [r];
171
- if (Array.isArray(r))
172
- return [r.shift(), ...r ?? []];
144
+ get store() {
145
+ return this._store;
173
146
  }
174
- useLog(r, o) {
175
- x(
176
- this.generateStyle(r),
177
- this.rebuildArgs(o, r.icon)
178
- );
147
+ get storeSubscribe() {
148
+ if (this._storeSubscribe)
149
+ return () => ({
150
+ store: this.store,
151
+ callback: this._storeSubscribe
152
+ });
179
153
  }
180
- }
181
- class C extends A {
182
- constructor(o) {
183
- super();
184
- c(this, "_pluginName", y);
185
- o && (this._pluginName = o);
154
+ set storeSubscribe(t) {
155
+ this._storeSubscribe = t;
186
156
  }
187
- logGroup(o, n) {
188
- this.startGroup(), this.log(o, n), this.endGroup();
157
+ get tracer() {
158
+ return !this._tracer && this._createTracer && (this._tracer = this._createTracer(), this._tracer.scope = this.store.$id), this._tracer;
189
159
  }
190
- startGroup(o) {
191
- console.group(o);
160
+ addToState(t, e) {
161
+ this.isOptionApi() || E(e) || (e = v(e)), this.state[t] = e, this.store[t] = O(this.state, t);
192
162
  }
193
- endGroup() {
194
- console.groupEnd();
163
+ addSubscription(t, e, r) {
164
+ this._subscriptions[t] = { subscription: e, ...r ?? {} };
195
165
  }
196
- useLog(o, n) {
197
- E(
198
- this.generateStyle(o),
199
- this.rebuildArgs(n, o.icon)
200
- );
166
+ afterHydration() {
201
167
  }
202
- }
203
- function $(e) {
204
- if (typeof e != "function")
205
- return e;
206
- try {
207
- return e();
208
- } catch (r) {
209
- return { __tracePayloadError: r };
168
+ static customizeStore(t, e) {
169
+ if (e.storeOptions && this.hasRequiredKeys(e.storeOptions)) {
170
+ const r = new this(t, e);
171
+ if (r) {
172
+ try {
173
+ r.init(), r.onStoreDispose();
174
+ } catch (o) {
175
+ r.traceError("plugin:initialization:failed", o, r.store.$id);
176
+ }
177
+ return r;
178
+ }
179
+ }
210
180
  }
211
- }
212
- class T {
213
- constructor(r, o, n = {}) {
214
- c(this, "_listeners", []);
215
- c(this, "_scope");
216
- c(this, "_source");
217
- this._scope = n.scope, this._source = r, this._listeners = o;
181
+ getOption(t) {
182
+ return this.options && this.options[t];
218
183
  }
219
- get scope() {
220
- return this._scope;
184
+ getStatePropertyValue(t) {
185
+ return this.getValue(this.state[t]);
221
186
  }
222
- set scope(r) {
223
- this._scope = r;
187
+ getSubscriptions() {
188
+ if (!h(this._subscriptions))
189
+ return this._subscriptions;
224
190
  }
225
- get source() {
226
- return this._source;
191
+ getValue(t) {
192
+ return t?.__v_isRef ? t.value : t;
227
193
  }
228
- debug(r, o, n, t) {
229
- this.emit("debug", r, o, n, t);
194
+ hasDeniedFirstChar(t) {
195
+ return f(t);
230
196
  }
231
- error(r, o, n, t, s) {
232
- this.emit("error", r, o, t, s, n);
197
+ static hasRequiredKeys(t) {
198
+ return !this._requiredKeysValidation || !h(this._requiredKeys) && this._requiredKeys[this._requiredKeysValidation]((e) => !!t[e]);
233
199
  }
234
- emit(r, o, n, t, s, i) {
235
- if (this._listeners.length === 0) {
236
- r === "error" && console.error("Unhandled error trace event:", i);
237
- return;
238
- }
239
- const a = {
240
- label: o,
241
- level: r,
242
- namespace: n,
243
- scope: s ?? this._scope,
244
- source: this._source
245
- }, p = this._listeners.filter((u) => {
246
- try {
247
- return u.filter(a);
248
- } catch (f) {
249
- return console.error("Error in trace listener filter:", f), !1;
250
- }
251
- });
252
- if (p.length === 0) {
253
- r === "error" && console.error("Unhandled error trace event:", i);
254
- return;
255
- }
256
- const d = {
257
- ...a,
258
- ...i !== void 0 && { error: i },
259
- ...t !== void 0 && { payload: $(t) },
260
- timestamp: Date.now()
261
- };
262
- for (const u of p)
263
- try {
264
- u.handler(d);
265
- } catch (f) {
266
- console.error("Error in trace listener:", f);
267
- }
200
+ hydrate() {
268
201
  }
269
- }
270
- function w(e) {
271
- const r = Object.keys(e).reduce((o, n) => (n !== "level" && n !== "timestamp" && (o[n] = e[n]), o), {});
272
- return [j(e), r];
273
- }
274
- function j(e) {
275
- return e.scope ? `${e.label} [${e.scope}]` : `${e.label}`;
276
- }
277
- function k(e) {
278
- return e || (e = new C()), {
279
- handler(r) {
280
- const o = r.level === "error" ? "error" : "log";
281
- e[o](...w(r));
282
- }
283
- };
284
- }
285
- function h(e, r) {
286
- return (o) => e[r](({ comparator: n = "equals", target: t, value: s }) => {
287
- const i = o[t];
288
- if (typeof i != "string") return !1;
289
- let a = !1;
290
- switch (n) {
291
- case "equals":
292
- a = i === s;
293
- break;
294
- case "contains":
295
- a = i.includes(s);
296
- break;
297
- case "startsWith":
298
- a = i.startsWith(s);
299
- break;
300
- case "endsWith":
301
- a = i.endsWith(s);
302
- break;
303
- default:
304
- a = !1;
305
- break;
306
- }
307
- return a;
308
- });
309
- }
310
- function L(e, r = "every") {
311
- return Array.isArray(e) && (e = {
312
- filter: h(e, r)
313
- }), e.filter && Array.isArray(e.filter) && (e.filter = h(e.filter, r)), (!e.filter || typeof e.filter != "function") && (e = { ...e, filter: () => !0 }), e;
314
- }
315
- function z(e, r = "every") {
316
- return e = L(e, r), e?.handler || (e = { ...e, ...k() }), e;
317
- }
318
- function N() {
319
- let e = [];
320
- function r(t, s = "every") {
321
- return (!t || !t?.handler) && (t = z(t, s)), (!("filter" in t) || typeof t.filter != "function") && (t = { ...t, filter: () => !0 }), e.push(t), () => {
322
- const i = e.indexOf(t);
323
- i !== -1 && e.splice(i, 1);
324
- };
202
+ init() {
325
203
  }
326
- function o() {
327
- e = [];
204
+ initializeEventsRegistry(t) {
205
+ this._createTracer = t?.createTracer, this._eventsRegistry = t?.eventsRegistry;
328
206
  }
329
- function n() {
330
- return e.length > 0;
207
+ isOptionApi() {
208
+ return this.store._isOptionsAPI;
331
209
  }
210
+ stateHas(t) {
211
+ return Object.prototype.hasOwnProperty.call(this.state, t);
212
+ }
213
+ storeHas(t) {
214
+ return Object.prototype.hasOwnProperty.call(this.store, t);
215
+ }
216
+ }
217
+ i(u, "_requiredKeys"), i(u, "_requiredKeysValidation", "every");
218
+ function P(n, s, t) {
332
219
  return {
333
- addTraceListener: r,
334
- clearTraceListeners: o,
335
- createTracer: (t, s = {}) => new T(t, e, s),
336
- hasTraceListeners: n
220
+ name: n,
221
+ invoke: s,
222
+ ...t
337
223
  };
338
224
  }
339
225
  export {
340
- A as CustomConsole,
341
- G as PluginSubscriber,
342
- q as Store,
343
- T as Tracer,
344
- k as createConsoleTraceListener,
345
- N as createTracerRegistry,
346
- P as isEmpty
226
+ u as EnhancedStore,
227
+ D as PLUGIN_EVENTS,
228
+ V as PluginOrchestrator,
229
+ g as STORE_EVENTS,
230
+ $ as SUBSCRIBER_EVENTS,
231
+ x as StoreSubscriber,
232
+ P as createPluginSubscriber,
233
+ k as getActionStoreKey,
234
+ l as getDefineAStoreSetupContext,
235
+ q as getStoreKeyPrefix,
236
+ f as hasDeniedFirstChar,
237
+ h as isEmpty,
238
+ y as setEnhancedStore,
239
+ C as traceGroups
347
240
  };
348
- //# sourceMappingURL=helpers.js.map
@@ -0,0 +1,9 @@
1
+ export { default as StoreSubscriber } from '../subscribers/StoreSubscriber';
2
+ export { default as PluginOrchestrator } from '../orchestration/PluginOrchestrator';
3
+ export { default as EnhancedStore } from '../enhanced-store/EnhancedStore';
4
+ export { getActionStoreKey, getStoreKeyPrefix, hasDeniedFirstChar } from '../utils/store';
5
+ export { isEmpty } from '../utils/validation';
6
+ export { createPluginSubscriber } from '../factories/plugin-subscriber';
7
+ export { getDefineAStoreSetupContext, setEnhancedStore } from "../enhanced-store/setup-context";
8
+ export { PLUGIN as PLUGIN_EVENTS, STORE as STORE_EVENTS, SUBSCRIBER as SUBSCRIBER_EVENTS } from '../dictionaries/plugin-subscription-event';
9
+ export { traceGroups } from '../tracing/trace-groups';
@@ -1,13 +1,4 @@
1
- import PluginSubscriber from '../core/PluginSubscriber';
2
- import PluginSubscription from '../core/PluginSubscription';
3
- import Store from '../core/Store';
4
1
  export { createPlugin } from "../plugins/createPlugin";
5
- export { createHydrationPlugin } from "../plugins/createHydrationPlugin";
6
- export type { AnyObject, CustomStore, DefineAStoreSetupContext, DefineAStoreSetupExtensions, EmptyExtensions, PluginExecutionEnvironment, PluginExecutionOptions, PluginHydrationScheduler, PluginHydrationTiming, PluginRuntimeEnvironment, PluginStoreOptions, PluginSubscriptionOptions, PluginSubscriberInterface, PluginSubscriptionDefinition, PluginSubscriptions, StatePropertyValue, StoreClassConstructorParams, StoreOptions, StoreOptionsExtensions, StoreOptionsPropertyValue, StoreMutationSubscription, StoreMutationSubscriptionCallback, StoreOnActionCallbackParameters, StoreOnActionSubscription, StoreOnActionSubscriptionCallback, NativePiniaSubscription, NativePiniaSubscriptionReturn } from "../types";
7
- export type { StoreMutationSubscriptionReturn, StoreOnActionSubscriptionReturn } from "../types/plugin";
8
- export type { RollbackActionParams, RollbackAfterFailureParams } from "../types/store";
9
- export { defineAStore, defineAStoreCtx, getDefineAStoreSetupContext, getEnhancedStore, getExtendingStore, setEnhancedStore } from "../utils/store";
10
- export { pluginName as PLUGIN_NAME } from "../utils/constantes";
11
- export { PluginSubscriber };
12
- export { PluginSubscription };
13
- export { Store };
2
+ export { defineAStore, defineAStoreCtx } from "../enhanced-store/define-a-store";
3
+ export { getEnhancedStore } from "../enhanced-store/setup-context";
4
+ export { pluginName as PLUGIN_NAME } from "../utils/constants";
@@ -0,0 +1,15 @@
1
+ import type { PluginExecutionOptions, PluginHydrationScheduler, PluginRuntimeEnvironment, StoreSubscriberInterface, PluginOrchestratorOptions } from "../types/plugin";
2
+ export declare const defaultPluginExecution: Required<PluginExecutionOptions>;
3
+ export declare function defaultHydrationScheduler(callback: () => void): void;
4
+ /** Stateless rules deciding whether, when and how a subscriber runs. */
5
+ export default class ExecutionPolicy {
6
+ private _hydrationScheduler;
7
+ private _options?;
8
+ constructor(_options?: PluginOrchestratorOptions);
9
+ get currentEnvironment(): PluginRuntimeEnvironment;
10
+ get hydrationScheduler(): PluginHydrationScheduler;
11
+ resolveExecution(subscriber: StoreSubscriberInterface): Required<PluginExecutionOptions>;
12
+ resolveHydrationScheduler(subscriber: Pick<StoreSubscriberInterface, 'hydrationScheduler'>): PluginHydrationScheduler;
13
+ shouldInvoke(execution: Required<PluginExecutionOptions>): boolean;
14
+ shouldScheduleAfterHydration(execution: Required<PluginExecutionOptions>): boolean;
15
+ }
@@ -0,0 +1,41 @@
1
+ import TraceableEmitter from "../tracing/TraceableEmitter";
2
+ import type { PiniaPluginContext } from "pinia";
3
+ import type { StoreSubscriberInterface, PluginOrchestratorOptions, PluginSubscriptions } from "../types/plugin";
4
+ /**
5
+ * Sequences the subscribers of a store: for each one, consults the execution policy, schedules or runs it,
6
+ * then delegates the subscriptions bookkeeping, delivery and action/mutation hooks to dedicated collaborators.
7
+ */
8
+ export default class PluginOrchestrator extends TraceableEmitter {
9
+ protected _eventsRegistry: {
10
+ emitter: import("../events/EventsEmitter").default;
11
+ createSubscriber: (id: string, eventSubscriptions?: import("../types/events").EventSubscription[]) => import("../events/EventsSubscriber").default;
12
+ subscriptionsRegistry: import("../events/StoresEventsSubscriptionsRegistry").default;
13
+ };
14
+ protected _name: string;
15
+ private _actionExecutor;
16
+ private _deliverer;
17
+ private _groups;
18
+ private _options?;
19
+ private _policy;
20
+ private _registry;
21
+ private _subscribers;
22
+ private _subscriptions;
23
+ set subscribers(subscribers: StoreSubscriberInterface[]);
24
+ get subscriptions(): PluginSubscriptions[] | undefined;
25
+ constructor(subscribers: StoreSubscriberInterface[], options?: PluginOrchestratorOptions);
26
+ /** @returns A promise settling once asynchronous hydration hooks are done, undefined when everything ran synchronously. */
27
+ private executeSubscriber;
28
+ private executeSubscriberSafely;
29
+ private initializeTracer;
30
+ /**
31
+ * Invokes the plugin with the given Pinia plugin context, executing all relevant subscribers safely.
32
+ * @param param0 The Pinia plugin context containing the store and options.
33
+ * @param param0.store The Pinia store instance.
34
+ * @param param0.options The options passed to the Pinia store.
35
+ * @returns void
36
+ */
37
+ plugin({ store, options }: PiniaPluginContext): void;
38
+ private registerMutationSubscription;
39
+ private registerOnActionSubscription;
40
+ private registerStoreCleanup;
41
+ }