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.
- package/CHANGELOG.md +73 -12
- package/CONTRIBUTING.md +10 -1
- package/README.md +48 -293
- package/SECURITY.md +6 -6
- package/dist/chunks/setup-context-3G3Hy1ep.js +909 -0
- package/dist/dictionaries/plugin-subscription-event.d.ts +20 -0
- package/dist/{core/Store.d.ts → enhanced-store/EnhancedStore.d.ts} +24 -29
- package/dist/enhanced-store/define-a-store.d.ts +64 -0
- package/dist/enhanced-store/setup-context.d.ts +27 -0
- package/dist/events/EventsEmitter.d.ts +9 -0
- package/dist/events/EventsSubscriber.d.ts +32 -0
- package/dist/events/EventsSubscription.d.ts +13 -0
- package/dist/events/StoreEvent.d.ts +6 -0
- package/dist/events/StoresEventsSubscriptionsRegistry.d.ts +31 -0
- package/dist/events/event.d.ts +8 -0
- package/dist/factories/events-registry.d.ts +9 -0
- package/dist/factories/events-subscriber.d.ts +11 -0
- package/dist/factories/messenger-registry.d.ts +16 -0
- package/dist/factories/plugin-subscriber.d.ts +17 -0
- package/dist/helpers.js +204 -312
- package/dist/lib/helpers.d.ts +9 -0
- package/dist/lib/main.d.ts +3 -12
- package/dist/orchestration/ExecutionPolicy.d.ts +15 -0
- package/dist/orchestration/PluginOrchestrator.d.ts +41 -0
- package/dist/orchestration/SubscriberScheduler.d.ts +31 -0
- package/dist/pinia-plugin-subscription.js +31 -426
- package/dist/plugins/createPlugin.d.ts +3 -13
- package/dist/services/messenger.d.ts +28 -0
- package/dist/services/messengerProvider.d.ts +45 -0
- package/dist/store-hooks/StoreHooksBinder.d.ts +20 -0
- package/dist/store-hooks/StoreHooksRegistry.d.ts +34 -0
- package/dist/{core/PluginSubscriber.d.ts → subscribers/StoreSubscriber.d.ts} +39 -28
- package/dist/tracing/TraceGroupHelper.d.ts +27 -0
- package/dist/tracing/TraceableEmitter.d.ts +60 -0
- package/dist/tracing/TraceableEventsSubscriber.d.ts +21 -0
- package/dist/tracing/TraceableStoreEventsSubscriber.d.ts +16 -0
- package/dist/tracing/trace-groups.d.ts +9 -0
- package/dist/types/core.d.ts +12 -0
- package/dist/types/events.d.ts +24 -0
- package/dist/types/index.d.ts +8 -34
- package/dist/types/messenger.d.ts +20 -0
- package/dist/types/plugin.d.ts +39 -20
- package/dist/types/store.d.ts +1 -9
- package/dist/types/trace.d.ts +35 -75
- package/dist/utils/constants.d.ts +4 -0
- package/dist/utils/events.d.ts +3 -0
- package/dist/utils/id.d.ts +20 -0
- package/dist/utils/store.d.ts +9 -93
- package/docs/authoring-plugins.md +330 -78
- package/docs/using-plugins.md +89 -53
- package/package.json +14 -8
- package/dist/chunks/constantes-CaTNAbzX.js +0 -261
- package/dist/chunks/constantes-CaTNAbzX.js.map +0 -1
- package/dist/core/PluginSubscription.d.ts +0 -92
- package/dist/core/RollbackStateSnapshotsHandler.d.ts +0 -65
- package/dist/factories/console-trace-listener.d.ts +0 -7
- package/dist/factories/state-snapshot.d.ts +0 -3
- package/dist/factories/trace-listener.d.ts +0 -16
- package/dist/factories/trace-registry.d.ts +0 -17
- package/dist/helpers/index.d.ts +0 -9
- package/dist/helpers.js.map +0 -1
- package/dist/pinia-plugin-subscription.js.map +0 -1
- package/dist/plugins/createHydrationPlugin.d.ts +0 -10
- package/dist/system/Tracer.d.ts +0 -20
- package/dist/system/log.d.ts +0 -35
- package/dist/tests/defineAStore.test-d.d.ts +0 -1
- package/dist/tests/storeOptionsExtensions.test-d.d.ts +0 -12
- package/dist/types/comparison.d.ts +0 -3
- package/dist/types/list.d.ts +0 -13
- package/dist/types/log.d.ts +0 -8
- package/dist/types/resourceId.d.ts +0 -4
- package/dist/utils/Performance.d.ts +0 -9
- package/dist/utils/constantes.d.ts +0 -1
- package/dist/utils/deep-clone.d.ts +0 -7
- package/dist/utils/defineStoreId.d.ts +0 -1
- package/dist/utils/object.d.ts +0 -4
- 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
|
|
3
|
-
var
|
|
4
|
-
import {
|
|
5
|
-
import { P as
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
);
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
"
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
125
|
+
get onAction() {
|
|
126
|
+
if (this._onAction)
|
|
127
|
+
return () => ({
|
|
128
|
+
store: this.store,
|
|
129
|
+
callback: this._onAction
|
|
130
|
+
});
|
|
149
131
|
}
|
|
150
|
-
|
|
151
|
-
|
|
132
|
+
set onAction(t) {
|
|
133
|
+
this._onAction = t;
|
|
152
134
|
}
|
|
153
|
-
|
|
154
|
-
return this.
|
|
135
|
+
get options() {
|
|
136
|
+
return this._options;
|
|
155
137
|
}
|
|
156
|
-
|
|
157
|
-
this.
|
|
158
|
-
this.getStyleDefinition(),
|
|
159
|
-
r
|
|
160
|
-
);
|
|
138
|
+
get state() {
|
|
139
|
+
return this._store.$state;
|
|
161
140
|
}
|
|
162
|
-
|
|
163
|
-
this.
|
|
164
|
-
this.getStyleDefinition("error"),
|
|
165
|
-
r
|
|
166
|
-
);
|
|
141
|
+
set state(t) {
|
|
142
|
+
this._store.$state = t;
|
|
167
143
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
return [r];
|
|
171
|
-
if (Array.isArray(r))
|
|
172
|
-
return [r.shift(), ...r ?? []];
|
|
144
|
+
get store() {
|
|
145
|
+
return this._store;
|
|
173
146
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
147
|
+
get storeSubscribe() {
|
|
148
|
+
if (this._storeSubscribe)
|
|
149
|
+
return () => ({
|
|
150
|
+
store: this.store,
|
|
151
|
+
callback: this._storeSubscribe
|
|
152
|
+
});
|
|
179
153
|
}
|
|
180
|
-
|
|
181
|
-
|
|
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
|
-
|
|
188
|
-
this.
|
|
157
|
+
get tracer() {
|
|
158
|
+
return !this._tracer && this._createTracer && (this._tracer = this._createTracer(), this._tracer.scope = this.store.$id), this._tracer;
|
|
189
159
|
}
|
|
190
|
-
|
|
191
|
-
|
|
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
|
-
|
|
194
|
-
|
|
163
|
+
addSubscription(t, e, r) {
|
|
164
|
+
this._subscriptions[t] = { subscription: e, ...r ?? {} };
|
|
195
165
|
}
|
|
196
|
-
|
|
197
|
-
E(
|
|
198
|
-
this.generateStyle(o),
|
|
199
|
-
this.rebuildArgs(n, o.icon)
|
|
200
|
-
);
|
|
166
|
+
afterHydration() {
|
|
201
167
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
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
|
-
|
|
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
|
-
|
|
220
|
-
return this.
|
|
184
|
+
getStatePropertyValue(t) {
|
|
185
|
+
return this.getValue(this.state[t]);
|
|
221
186
|
}
|
|
222
|
-
|
|
223
|
-
this.
|
|
187
|
+
getSubscriptions() {
|
|
188
|
+
if (!h(this._subscriptions))
|
|
189
|
+
return this._subscriptions;
|
|
224
190
|
}
|
|
225
|
-
|
|
226
|
-
return
|
|
191
|
+
getValue(t) {
|
|
192
|
+
return t?.__v_isRef ? t.value : t;
|
|
227
193
|
}
|
|
228
|
-
|
|
229
|
-
|
|
194
|
+
hasDeniedFirstChar(t) {
|
|
195
|
+
return f(t);
|
|
230
196
|
}
|
|
231
|
-
|
|
232
|
-
this.
|
|
197
|
+
static hasRequiredKeys(t) {
|
|
198
|
+
return !this._requiredKeysValidation || !h(this._requiredKeys) && this._requiredKeys[this._requiredKeysValidation]((e) => !!t[e]);
|
|
233
199
|
}
|
|
234
|
-
|
|
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
|
-
|
|
327
|
-
|
|
204
|
+
initializeEventsRegistry(t) {
|
|
205
|
+
this._createTracer = t?.createTracer, this._eventsRegistry = t?.eventsRegistry;
|
|
328
206
|
}
|
|
329
|
-
|
|
330
|
-
return
|
|
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
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
hasTraceListeners: n
|
|
220
|
+
name: n,
|
|
221
|
+
invoke: s,
|
|
222
|
+
...t
|
|
337
223
|
};
|
|
338
224
|
}
|
|
339
225
|
export {
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
P as
|
|
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';
|
package/dist/lib/main.d.ts
CHANGED
|
@@ -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 {
|
|
6
|
-
export
|
|
7
|
-
export
|
|
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
|
+
}
|