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

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 CHANGED
@@ -7,9 +7,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
- ### Changed
11
- - Moved the demo application from `src/demo/` to the repository-level `demo/` directory, separating example code from the library source and tracking the demo files in version control.
12
-
13
10
  ### Added
14
11
  - Added `createTracerRegistry()` to create isolated trace listeners and tracers for each application or Pinia instance
15
12
  - Added the `Tracer` class and registry methods `addTraceListener()`, `clearTraceListeners()` and `hasTraceListeners()`
@@ -22,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
22
19
  - Added unit tests covering the tracing system and the leak detection logic
23
20
 
24
21
  ### Changed
22
+ - Moved the demo application from `src/demo/` to the repository-level `demo/` directory, separating example code from the library source and tracking the demo files in version control.
25
23
  - Clarified that SSR tracing registries and plugin instances must be created per request, and added coverage for listener isolation between registries
26
24
  - Replaced the `Debug` abstract class with composition: `Store` and `PluginSubscription` no longer extend it and now own a `Tracer`
27
25
  - `createPlugin()` accepts `PluginSubscriptionOptions`, including a `createTracer` factory to connect a tracer registry to plugin and store trace events
@@ -1,21 +1,21 @@
1
1
  var S = Object.defineProperty;
2
2
  var f = (e, t, r) => t in e ? S(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
- var s = (e, t, r) => f(e, typeof t != "symbol" ? t + "" : t, r);
3
+ var n = (e, t, r) => f(e, typeof t != "symbol" ? t + "" : t, r);
4
4
  import { isRef as g, ref as b, toRef as l } from "vue";
5
5
  import { defineStore as p } from "pinia";
6
- class L {
6
+ class k {
7
7
  constructor(t, r) {
8
- s(this, "_createInstance");
9
- s(this, "_name");
10
- s(this, "_pluginOptions");
11
- s(this, "_storeInstance");
12
- s(this, "_resetStoreCallback");
13
- s(this, "_storeOnActionSubscription");
14
- s(this, "_storeMutationSubscription");
15
- s(this, "_subscriptions");
16
- s(this, "pluginCreated");
17
- s(this, "execution");
18
- s(this, "hydrationScheduler");
8
+ n(this, "_createInstance");
9
+ n(this, "_name");
10
+ n(this, "_pluginOptions");
11
+ n(this, "_storeInstance");
12
+ n(this, "_resetStoreCallback");
13
+ n(this, "_storeOnActionSubscription");
14
+ n(this, "_storeMutationSubscription");
15
+ n(this, "_subscriptions");
16
+ n(this, "pluginCreated");
17
+ n(this, "execution");
18
+ n(this, "hydrationScheduler");
19
19
  this._name = t, this._createInstance = r;
20
20
  }
21
21
  get name() {
@@ -49,8 +49,12 @@ class L {
49
49
  }
50
50
  hydrate(t) {
51
51
  }
52
- invoke({ store: t, options: r }, n) {
53
- return this._storeInstance = this._createInstance(t, { ...r, ...this.pluginOptions, createTracer: n }), this._storeInstance ? (this._subscriptions = this._storeInstance.getSubscriptions(), this._storeMutationSubscription = this._storeInstance.storeSubscribe, this._storeOnActionSubscription = this._storeInstance.onAction, this.pluginCreated && this.pluginCreated(t), !0) : !1;
52
+ invoke({ store: t, options: r }, s) {
53
+ return this._storeInstance = this._createInstance(t, {
54
+ ...r,
55
+ ...this.pluginOptions,
56
+ createTracer: s ? () => s?.(this.name) : void 0
57
+ }), this._storeInstance ? (this._subscriptions = this._storeInstance.getSubscriptions(), this._storeMutationSubscription = this._storeInstance.storeSubscribe, this._storeOnActionSubscription = this._storeInstance.onAction, this.pluginCreated && this.pluginCreated(t), !0) : !1;
54
58
  }
55
59
  }
56
60
  const u = /* @__PURE__ */ new WeakMap(), a = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new WeakSet();
@@ -58,41 +62,41 @@ function O(e, t) {
58
62
  if (h.has(e) || typeof e.$dispose != "function")
59
63
  return;
60
64
  const r = e.$dispose;
61
- e.$dispose = (...n) => (u.delete(e), a.delete(t), r.apply(e, n)), h.add(e);
65
+ e.$dispose = (...s) => (u.delete(e), a.delete(t), r.apply(e, s)), h.add(e);
62
66
  }
63
- function q(e, t, r) {
64
- const n = r ? { storeOptions: r } : {};
67
+ function L(e, t, r) {
68
+ const s = r ? { storeOptions: r } : {};
65
69
  return typeof t == "function" ? d(
66
70
  e,
67
71
  t,
68
- n
72
+ s
69
73
  ) : y(
70
74
  e,
71
75
  t,
72
- n
76
+ s
73
77
  );
74
78
  }
75
- function F(e, t, r) {
76
- const n = r ? { storeOptions: { ...r, enhancedStore: !0 } } : { storeOptions: { enhancedStore: !0 } };
79
+ function q(e, t, r) {
80
+ const s = r ? { storeOptions: { ...r, enhancedStore: !0 } } : { storeOptions: { enhancedStore: !0 } };
77
81
  return d(
78
82
  e,
79
83
  t,
80
- n
84
+ s
81
85
  );
82
86
  }
83
87
  function d(e, t, r) {
84
- const n = {
88
+ const s = {
85
89
  id: e,
86
90
  extensions: {}
87
91
  }, i = r?.storeOptions?.enhancedStore === !0, o = p(
88
92
  e,
89
- () => t(n),
93
+ () => t(s),
90
94
  r
91
95
  );
92
96
  return Object.assign(((..._) => {
93
- i && a.set(e, n);
97
+ i && a.set(e, s);
94
98
  const c = o(..._);
95
- return i && (u.set(c, n), a.delete(e), O(c, e)), c;
99
+ return i && (u.set(c, s), a.delete(e), O(c, e)), c;
96
100
  }), o);
97
101
  }
98
102
  function y(e, t, r) {
@@ -115,32 +119,31 @@ function x(e) {
115
119
  function T(e, t) {
116
120
  e.extensions.enhancedStore = t, e.extensions.extending = t;
117
121
  }
118
- function K(e) {
122
+ function F(e) {
119
123
  return console.warn(`${e.id}Store - getExtendingStore is deprecated. Use getEnhancedStore instead.`), x(e);
120
124
  }
121
- function M(e, t) {
125
+ function K(e, t) {
122
126
  return `${e}-${t.$id}`;
123
127
  }
124
128
  function $(e) {
125
129
  return e ? Array.isArray(e) ? e.length === 0 : typeof e == "object" ? Object.keys(e).length === 0 : typeof e == "string" ? e.trim() === "" : !1 : !(typeof e == "boolean" || typeof e == "number");
126
130
  }
127
- const I = "pinia-plugin-subscription";
128
- class w {
131
+ class I {
129
132
  constructor(t, r) {
130
- s(this, "_className", "Store");
131
- s(this, "_createTracer");
132
- s(this, "_onAction");
133
- s(this, "_options");
134
- s(this, "_store");
135
- s(this, "_storeSubscribe");
136
- s(this, "_subscriptions", {});
137
- s(this, "_traceOptions", {
133
+ n(this, "_className", "Store");
134
+ n(this, "_createTracer");
135
+ n(this, "_onAction");
136
+ n(this, "_options");
137
+ n(this, "_store");
138
+ n(this, "_storeSubscribe");
139
+ n(this, "_subscriptions", {});
140
+ n(this, "_traceOptions", {
138
141
  addClassNameToLabel: !0
139
142
  });
140
- s(this, "_tracer");
143
+ n(this, "_tracer");
141
144
  if (this._options = r.storeOptions, this._store = t, this.initializeTracer(r), this._options?.enhancedStore) {
142
- const n = C(this.store);
143
- n && T(n, this.store);
145
+ const s = C(this.store);
146
+ s && T(s, this.store);
144
147
  }
145
148
  }
146
149
  get classNameAddedToTraceNamespace() {
@@ -182,13 +185,13 @@ class w {
182
185
  this._storeSubscribe = t;
183
186
  }
184
187
  get tracer() {
185
- return !this._tracer && this._createTracer && (this._tracer = this._createTracer(I), this._tracer.scope = this.store.$id), this._tracer;
188
+ return !this._tracer && this._createTracer && (this._tracer = this._createTracer(), this._tracer.scope = this.store.$id), this._tracer;
186
189
  }
187
190
  addToState(t, r) {
188
191
  this.isOptionApi() || g(r) || (r = b(r)), this.state[t] = r, this.store[t] = l(this.state, t);
189
192
  }
190
- addSubscription(t, r, n) {
191
- this._subscriptions[t] = { subscription: r, ...n ?? {} };
193
+ addSubscription(t, r, s) {
194
+ this._subscriptions[t] = { subscription: r, ...s ?? {} };
192
195
  }
193
196
  afterHydration() {
194
197
  }
@@ -229,29 +232,30 @@ class w {
229
232
  storeHas(t) {
230
233
  return Object.prototype.hasOwnProperty.call(this.store, t);
231
234
  }
232
- trace(t, r, n, i) {
233
- this.tracer && (t = this.traceLabelFormatter(t), this.tracer.debug(t, i ?? t.toLowerCase(), r, n));
235
+ trace(t, r, s, i) {
236
+ this.tracer && (t = this.traceLabelFormatter(t), this.tracer.debug(t, i ?? t.toLowerCase(), r, s));
234
237
  }
235
- traceError(t, r, n, i, o) {
236
- this.tracer ? (t = this.traceLabelFormatter(t), this.tracer.error(t, o ?? t.toLowerCase(), r, n, i)) : console.error(r);
238
+ traceError(t, r, s, i, o) {
239
+ this.tracer ? (t = this.traceLabelFormatter(t), this.tracer.error(t, o ?? t.toLowerCase(), r, s, i)) : console.error(r);
237
240
  }
238
241
  traceLabelFormatter(t) {
239
242
  return this.classNameAddedToTraceNamespace && (t = `${this.constructor.name}:${t}`), t;
240
243
  }
241
244
  }
242
- s(w, "_requiredKeys");
245
+ n(I, "_requiredKeys");
246
+ const M = "pinia-plugin-subscription";
243
247
  export {
244
- L as P,
245
- w as S,
246
- F as a,
248
+ k as P,
249
+ I as S,
250
+ q as a,
247
251
  C as b,
248
252
  x as c,
249
- q as d,
250
- K as e,
251
- M as g,
253
+ L as d,
254
+ F as e,
255
+ K as g,
252
256
  m as h,
253
257
  $ as i,
254
- I as p,
258
+ M as p,
255
259
  T as s
256
260
  };
257
- //# sourceMappingURL=Store-DHUAJv-P.js.map
261
+ //# sourceMappingURL=constantes-CaTNAbzX.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constantes-CaTNAbzX.js","sources":["../../src/core/PluginSubscriber.ts","../../src/utils/store.ts","../../src/utils/validation/index.ts","../../src/core/Store.ts"],"sourcesContent":["import Store from \"./Store\";\nimport type { PiniaPluginContext, Store as PiniaStore } from \"pinia\";\nimport type { AnyObject } from \"../types\";\nimport type {\n PluginExecutionOptions,\n PluginHydrationScheduler,\n PluginSubscriber as PluginSubscriberInterface,\n PluginSubscriptions,\n StoreClassConstructorParams,\n StoreMutationSubscription,\n StoreOnActionSubscription\n} from \"../types/plugin\";\nimport type Tracer from \"../system/Tracer\";\n\n\n\ntype CreateInstance<Instance = Store> = (store: PiniaStore, options: StoreClassConstructorParams) => Instance | undefined\n\n\n/**\n * Type definition for the function used to create an instance of a store.\n * @template Instance The type of the store instance, defaulting to the base Store class.\n * @param store The Pinia store for which the instance is being created.\n * @param options Additional options for creating the store instance.\n * @returns The created store instance or undefined if creation fails.\n */\nexport default abstract class PluginSubscriber<Instance extends Store> implements PluginSubscriberInterface {\n private _createInstance: CreateInstance\n private _name: string\n private _pluginOptions?: StoreClassConstructorParams\n private _storeInstance?: Instance\n /** Callback function to reset the store instance, if needed. */\n protected _resetStoreCallback?: (store?: PiniaStore) => void\n private _storeOnActionSubscription?: StoreOnActionSubscription\n private _storeMutationSubscription?: StoreMutationSubscription\n private _subscriptions?: PluginSubscriptions\n /**\n * Called when the plugin subscriber has been created for a specific store.\n * This callback can be used to perform any initialization or setup required for the plugin subscriber.\n */\n protected pluginCreated?: (store: PiniaStore) => void\n /** Options for the plugin subscriber's execution. */\n public execution?: PluginExecutionOptions\n /** Scheduler for handling the hydration process of the plugin subscriber. */\n public hydrationScheduler?: PluginHydrationScheduler\n\n\n get name(): string {\n return this._name;\n }\n\n get storeInstance(): Instance | undefined {\n return this._storeInstance\n }\n\n get pluginOptions(): StoreClassConstructorParams | undefined {\n return this._pluginOptions;\n }\n\n set pluginOptions(options: StoreClassConstructorParams | undefined) {\n this._pluginOptions = options;\n }\n\n get resetStoreCallback(): ((store?: PiniaStore) => void) | undefined {\n return this._resetStoreCallback as ((store?: PiniaStore) => void) | undefined;\n }\n\n get storeOnActionSubscription(): StoreOnActionSubscription | undefined {\n return this._storeOnActionSubscription;\n }\n\n get storeMutationSubscription(): StoreMutationSubscription | undefined {\n return this._storeMutationSubscription;\n }\n\n get subscriptions(): PluginSubscriptions | undefined {\n return this._subscriptions\n }\n\n set subscriptions(subscriptions: PluginSubscriptions) {\n this._subscriptions = subscriptions\n }\n\n\n constructor(pluginName: string, createInstanceFunction: CreateInstance) {\n this._name = pluginName\n this._createInstance = createInstanceFunction\n }\n\n /**\n * Called after the store has been hydrated.\n * @param context The Pinia plugin context containing the store and options.\n * @returns A promise that resolves when the post-hydration process is complete, or void if synchronous.\n */\n public afterHydration(context: PiniaPluginContext): void | Promise<void> {\n return\n }\n\n /**\n * Called when the plugin subscriber needs to hydrate its state.\n * @param context The Pinia plugin context containing the store and options.\n * @returns A promise that resolves when the hydration process is complete, or void if synchronous.\n */\n public hydrate(context: PiniaPluginContext): void | Promise<void> {\n return\n }\n\n /**\n * Invokes the plugin subscriber with the given context and optional tracer creation function.\n * @param context The Pinia plugin context containing the store and options.\n * @param createTracer Optional function to create a tracer for the plugin.\n * @returns True if the plugin was successfully invoked, otherwise false.\n */\n public invoke({ store, options }: PiniaPluginContext, createTracer?: (name: string) => Tracer): boolean {\n this._storeInstance = this._createInstance(store, {\n ...options,\n ...this.pluginOptions,\n createTracer: createTracer ? () => createTracer?.(this.name) : undefined\n }) as Instance\n\n if (!this._storeInstance) {\n return false\n }\n\n this._subscriptions = this._storeInstance.getSubscriptions()\n this._storeMutationSubscription = this._storeInstance.storeSubscribe\n this._storeOnActionSubscription = this._storeInstance.onAction\n\n if (this.pluginCreated) {\n this.pluginCreated(store)\n }\n\n return true\n }\n}","import { defineStore } from \"pinia\"\nimport type {\n DefineSetupStoreOptions,\n DefineStoreOptions,\n SetupStoreDefinition,\n StateTree,\n Store,\n StoreDefinition,\n _ExtractActionsFromSetupStore,\n _ExtractGettersFromSetupStore,\n _ExtractStateFromSetupStore,\n _GettersTree\n} from \"pinia\"\nimport type { AnyObject } from \"../types\"\nimport type {\n DefineAStoreDefinition,\n DefineAStoreSetupContext,\n EmptyExtensions,\n StoreOptions\n} from \"../types/store\"\nimport type { PluginStoreOptions } from \"../types/plugin\"\n\n\nexport const itemState = {\n '@id': undefined,\n id: undefined\n}\n\ntype DefineAStoreSetup<SS, TExtraExtensions extends Record<string, unknown> = EmptyExtensions> =\n (ctx: DefineAStoreSetupContext<SS, TExtraExtensions>) => SS\n\n/**\n * Options parameter of pinia's `defineStore()` for setup stores, derived from\n * the setup function return type.\n */\ntype DefineAStoreSetupOptions<Id extends string, SS> = DefineSetupStoreOptions<\n Id,\n _ExtractStateFromSetupStore<SS>,\n _ExtractGettersFromSetupStore<SS>,\n _ExtractActionsFromSetupStore<SS>\n>\n\nconst defineAStoreSetupContexts = new WeakMap<object, DefineAStoreSetupContext<AnyObject>>()\nconst defineAStoreSetupContextsById = new Map<string, DefineAStoreSetupContext<AnyObject>>()\nconst setupContextDisposeWrappedStores = new WeakSet<object>()\n\nfunction registerSetupContextCleanupOnDispose(\n store: AnyObject,\n id: string\n): void {\n if (setupContextDisposeWrappedStores.has(store) || typeof store.$dispose !== 'function') {\n return\n }\n\n const originalDispose = store.$dispose as (...args: unknown[]) => unknown\n store.$dispose = (...args: unknown[]) => {\n defineAStoreSetupContexts.delete(store)\n defineAStoreSetupContextsById.delete(id)\n return originalDispose.apply(store, args)\n }\n setupContextDisposeWrappedStores.add(store)\n}\n\n/**\n * Define a store with the setup API. State, getters and actions are inferred\n * from the setup function return, exactly like pinia's `defineStore`, so\n * store members are listed by IDEs and action prototypes are preserved.\n * @template Id The type of the store identifier.\n * @template SS The type of the setup function return.\n * @param id The unique identifier for the store.\n * @param storeDefinition The setup function defining the store.\n * @param options Optional store options.\n * @returns The defined store.\n */\nexport function defineAStore<Id extends string, SS>(\n id: Id,\n storeDefinition: (ctx?: DefineAStoreSetupContext<AnyObject>) => SS,\n options?: StoreOptions\n): SetupStoreDefinition<Id, SS>\n/**\n * Define a store with the options API, mirroring pinia's `defineStore` inference.\n * @template Id The type of the store identifier.\n * @template S The type of the store's state.\n * @template G The type of the store's getters.\n * @template A The type of the store's actions.\n * @param id The unique identifier for the store.\n * @param storeDefinition The store options definition.\n * @param options Optional store options.\n * @returns The defined store.\n */\nexport function defineAStore<Id extends string, S extends StateTree = {}, G extends _GettersTree<S> = {}, A = {}>(\n id: Id,\n storeDefinition: Omit<DefineStoreOptions<Id, S, G, A>, 'id'>,\n options?: StoreOptions\n): StoreDefinition<Id, S, G, A>\n/**\n * Define a store with explicit store/state types, e.g. when plugins augment\n * the store with members not returned by the setup function.\n * @template Sto The type of the store.\n * @template Sta The type of the store's state.\n * @param id The unique identifier for the store.\n * @param storeDefinition The store definition, either as an options object or a setup function.\n * @param options Optional store options.\n * @returns The defined store.\n */\nexport function defineAStore<Sto, Sta>(\n id: string,\n storeDefinition:\n | Omit<DefineStoreOptions<string, StateTree & Sta, AnyObject, Partial<Sto>>, 'id'>\n | ((ctx?: DefineAStoreSetupContext<Sto & Sta>) => AnyObject),\n options?: StoreOptions\n): DefineAStoreDefinition<Sto, Sta>\nexport function defineAStore(\n id: string,\n storeDefinition:\n | Omit<DefineStoreOptions<string, StateTree, AnyObject, AnyObject>, 'id'>\n | DefineAStoreSetup<AnyObject>,\n options?: StoreOptions\n): StoreDefinition {\n const storeOptions: PluginStoreOptions = options ? { storeOptions: options } : {} as PluginStoreOptions\n\n return (typeof storeDefinition === 'function'\n ? defineAStoreSetup(\n id,\n storeDefinition as DefineAStoreSetup<AnyObject>,\n storeOptions\n )\n : defineAStoreOptionApi(\n id,\n storeDefinition,\n storeOptions\n )) as StoreDefinition\n}\n\n/**\n * Define a store with a required, fully typed setup context. State, getters\n * and actions are inferred from the setup function return.\n * @template Id The type of the store identifier.\n * @template SS The type of the setup function return.\n * @template TExtraExtensions The type of the store's extra extensions.\n * @param id The unique identifier for the store.\n * @param storeDefinition The setup function defining the store.\n * @param options Optional store options.\n * @returns The defined store with setup context.\n */\nexport function defineAStoreCtx<Id extends string, SS, TExtraExtensions extends Record<string, unknown> = EmptyExtensions>(\n id: Id,\n storeDefinition: (ctx: DefineAStoreSetupContext<AnyObject, TExtraExtensions>) => SS,\n options?: StoreOptions\n): SetupStoreDefinition<Id, SS>\n/**\n * Define a store with a setup context and explicit store/state types, e.g.\n * when plugins augment the store with members not returned by the setup function.\n * @template Sto The type of the store.\n * @template Sta The type of the store's state.\n * @template TExtraExtensions The type of the store's extra extensions.\n * @param id The unique identifier for the store.\n * @param storeDefinition The setup function defining the store.\n * @param options Optional store options.\n * @returns The defined store with setup context.\n */\nexport function defineAStoreCtx<Sto, Sta, TExtraExtensions extends Record<string, unknown> = EmptyExtensions>(\n id: string,\n storeDefinition: (ctx: DefineAStoreSetupContext<Sto & Sta, TExtraExtensions>) => AnyObject,\n options?: StoreOptions\n): DefineAStoreDefinition<Sto, Sta>\nexport function defineAStoreCtx(\n id: string,\n storeDefinition: DefineAStoreSetup<AnyObject, any>,\n options?: StoreOptions\n): StoreDefinition {\n const storeOptions: PluginStoreOptions = options\n ? { storeOptions: { ...options, enhancedStore: true } }\n : { storeOptions: { enhancedStore: true } } as PluginStoreOptions\n\n return defineAStoreSetup(\n id,\n storeDefinition,\n storeOptions\n ) as StoreDefinition\n}\n\nexport function defineAStoreSetup<Id extends string, SS>(\n id: Id,\n storeDefinition: DefineAStoreSetup<SS>,\n options: PluginStoreOptions\n): SetupStoreDefinition<Id, SS> {\n const setupContext: DefineAStoreSetupContext<SS> = {\n id,\n extensions: {}\n }\n\n const shouldStoreSetupContext = options?.storeOptions?.enhancedStore === true\n\n // `storeOptions` augments pinia's DefineStoreOptionsBase (see createPlugin.ts);\n // the assertion stays valid in compilation units where the augmentation is not loaded.\n const useStore = defineStore(\n id,\n () => storeDefinition(setupContext),\n options as unknown as DefineAStoreSetupOptions<Id, SS>\n )\n\n return Object.assign(((...args: Parameters<typeof useStore>) => {\n if (shouldStoreSetupContext) {\n defineAStoreSetupContextsById.set(id, setupContext as DefineAStoreSetupContext<AnyObject>)\n }\n\n const store = useStore(...args)\n\n if (shouldStoreSetupContext) {\n defineAStoreSetupContexts.set(store, setupContext as DefineAStoreSetupContext<AnyObject>)\n defineAStoreSetupContextsById.delete(id)\n registerSetupContextCleanupOnDispose(store as AnyObject, id)\n }\n\n return store\n }) as typeof useStore, useStore)\n}\n\nexport function defineAStoreOptionApi<Id extends string, S extends StateTree = {}, G extends _GettersTree<S> = {}, A = {}>(\n id: Id,\n storeDefinition: Omit<DefineStoreOptions<Id, S, G, A>, 'id'>,\n options?: PluginStoreOptions\n): StoreDefinition<Id, S, G, A> {\n if (options) {\n storeDefinition = { ...storeDefinition, ...(options ?? {}) }\n }\n\n return defineStore(id, storeDefinition)\n}\n\nconst deniedFirstChar = new Set<string>(['_', '$'])\n\n/**\n * Check if a property has a denied first character : ['_', '$'].\n * @param property The property name to check.\n * @returns True if the property has a denied first character, false otherwise.\n */\nexport function hasDeniedFirstChar(property: string): boolean {\n return deniedFirstChar.has(property[0] as string)\n}\n\n/**\n * Get the setup context associated with a store instance (or pending store id).\n * @param store The store instance, or an object exposing the store `$id`.\n * @returns The setup context when the store was defined with `enhancedStore` enabled, undefined otherwise.\n */\nexport function getDefineAStoreSetupContext(store: object): DefineAStoreSetupContext<AnyObject> | undefined {\n const storeRecord = store as AnyObject\n\n return defineAStoreSetupContexts.get(store)\n ?? (typeof storeRecord?.$id === 'string'\n ? defineAStoreSetupContextsById.get(storeRecord.$id)\n : undefined)\n}\n\n/**\n * Get the enhanced store from the context.\n * @template TEnhancedStore The type of the enhanced store.\n * @param ctx The context containing the extensions.\n * @returns The enhanced store casted to the specified types.\n */\nexport function getEnhancedStore<TEnhancedStore>(\n ctx: DefineAStoreSetupContext<TEnhancedStore>\n): TEnhancedStore {\n const enhancedStore = ctx.extensions.enhancedStore ?? ctx.extensions.extending\n\n if (!enhancedStore) {\n throw new Error(`${ctx.id}Store - getEnhancedStore - Error: enhanced store is required`)\n }\n\n return enhancedStore\n}\n\n/**\n * Set the enhanced store in context with deprecated alias support.\n * @template TEnhancedStore The type of the enhanced store.\n * @param ctx The context containing the extensions.\n * @param store The store to expose as enhancement.\n */\nexport function setEnhancedStore<TEnhancedStore>(\n ctx: DefineAStoreSetupContext<TEnhancedStore>,\n store: TEnhancedStore\n): void {\n ctx.extensions.enhancedStore = store\n ctx.extensions.extending = store\n}\n\n/**\n * @deprecated Use getEnhancedStore instead.\n */\nexport function getExtendingStore<TEnhancedStore>(\n ctx: DefineAStoreSetupContext<TEnhancedStore>\n): TEnhancedStore {\n console.warn(`${ctx.id}Store - getExtendingStore is deprecated. Use getEnhancedStore instead.`)\n return getEnhancedStore<TEnhancedStore>(ctx)\n}\n\n/**\n * Get the storage key for a given action and store combination.\n * @param actionName The name of the action.\n * @param store The Pinia store instance.\n * @returns The storage key for the action and store combination.\n */\nexport function getActionStoreKey(actionName: string, store: Store): string {\n return `${actionName}-${store.$id}`\n}","export function isEmpty(value: any): boolean {\n if (!value) {\n return (typeof value === 'boolean' || typeof value === 'number') ? false : true\n }\n\n if (Array.isArray(value)) {\n return value.length === 0\n }\n\n if (typeof value === 'object') {\n return Object.keys(value).length === 0\n }\n\n if (typeof value === 'string') {\n return value.trim() === ''\n }\n\n return false\n}","import { isRef, ref, toRef } from \"vue\"\nimport Tracer from \"../system/Tracer\"\nimport { getDefineAStoreSetupContext, hasDeniedFirstChar, setEnhancedStore } from \"../utils/store\"\nimport { isEmpty } from \"../utils/validation\"\n\nimport type {\n PluginSubscriptionOptions,\n PluginSubscriptions,\n StoreClassConstructorParams,\n StoreMutationSubscription,\n StoreMutationSubscriptionCallback,\n StoreMutationSubscriptionReturn,\n StoreOnActionSubscription,\n StoreOnActionSubscriptionCallback,\n StoreOnActionSubscriptionReturn\n} from \"../types/plugin\"\nimport type { Store as PiniaStore, StateTree } from \"pinia\"\nimport type { TracePayload } from \"../types/trace\"\nimport type { AnyObject, PluginSubscriberInterface } from \"../types\"\nimport type { StoreOptions, StatePropertyValue } from \"../types/store\"\n\n/**\n * Base class for a Pinia store with enhanced capabilities.\n * Provides structured tracing, plugin subscriptions, and state management utilities.\n * @remarks\n * This class is intended to be extended by specific store implementations\n * that require enhanced capabilities such as structured tracing and plugin subscriptions.\n */\nexport default class Store {\n protected _className = 'Store'\n private _createTracer?: () => Tracer\n private _onAction?: StoreOnActionSubscriptionCallback\n private _options: StoreOptions\n private _store: PiniaStore\n private _storeSubscribe?: StoreMutationSubscriptionCallback\n private _subscriptions: PluginSubscriptions = {}\n private _traceOptions: Record<string, boolean> = {\n /** Indicates whether to add the class name to the namespace for tracing purposes. */\n addClassNameToLabel: true,\n }\n private _tracer?: Tracer\n\n protected static _requiredKeys?: string[]\n\n get classNameAddedToTraceNamespace(): boolean {\n return this._traceOptions.addClassNameToLabel\n }\n\n set classNameAddedToTraceNamespace(value: boolean) {\n this._traceOptions.addClassNameToLabel = value\n }\n\n get onAction(): StoreOnActionSubscription | undefined {\n if (!this._onAction) {\n return\n }\n\n return () => ({\n store: this.store as PiniaStore,\n callback: this._onAction\n }) as StoreOnActionSubscriptionReturn\n }\n\n set onAction(onAction: StoreOnActionSubscriptionCallback) {\n this._onAction = onAction\n }\n\n get options(): StoreOptions { return this._options }\n\n get state(): StateTree { return this._store.$state }\n\n set state(state: StateTree) { this._store.$state = state }\n\n get store(): AnyObject { return this._store }\n\n get storeSubscribe(): StoreMutationSubscription | undefined {\n if (!this._storeSubscribe) {\n return\n }\n\n return () => ({\n store: this.store as PiniaStore,\n callback: this._storeSubscribe\n }) as StoreMutationSubscriptionReturn\n }\n\n set storeSubscribe(storeSubscribe: StoreMutationSubscriptionCallback) {\n this._storeSubscribe = storeSubscribe\n }\n\n /**\n * Returns the structured trace emitter of this store.\n * Built lazily so that subclasses overriding `_className` are reflected.\n */\n protected get tracer(): Tracer | undefined {\n if (!this._tracer && this._createTracer) {\n this._tracer = this._createTracer()\n this._tracer.scope = this.store.$id\n }\n\n return this._tracer\n }\n\n /**\n * Constructs a new instance of the store.\n * @param store The Pinia store instance.\n * @param options The plugin store options and subscription options.\n * @remarks\n * This constructor is typically called by the `customizeStore` static method\n * to create an instance of the store with the provided Pinia store and options.\n * @see PluginStoreOptions\n * @see PluginSubscriptionOptions\n */\n constructor(store: PiniaStore, options: StoreClassConstructorParams) {\n this._options = options.storeOptions as StoreOptions\n this._store = store\n this.initializeTracer(options)\n\n if (this._options?.enhancedStore) {\n const ctx = getDefineAStoreSetupContext(this.store)\n\n if (ctx) {\n setEnhancedStore(ctx, this.store)\n }\n }\n }\n\n /**\n * Adds a property to the state of this store.\n * @param name The name of the property to add.\n * @param value The value of the property to add.\n */\n addToState(name: string, value?: StatePropertyValue): void {\n if (!this.isOptionApi()) {\n if (!isRef(value)) {\n value = ref<StatePropertyValue>(value)\n }\n }\n\n this.state[name] = value\n this.store[name] = toRef(this.state, name)\n }\n\n /**\n * Adds a subscription for a specific plugin to this store.\n * @param pluginName The name of the plugin for which the subscription is being added.\n * @param subscription The subscription callback or object to add.\n * @param options Additional options for the subscription, including subscription options and target stores.\n */\n addSubscription(\n pluginName: string,\n subscription: PluginSubscriberInterface,\n options?: { subscriptionOptions?: StoreOptions, stores?: PiniaStore[] }\n ): void {\n this._subscriptions[pluginName] = { subscription, ...(options ?? {}) }\n }\n\n /**\n * Called after the store has been hydrated.\n * @returns A promise that resolves when the post-hydration process is complete, or void if synchronous.\n */\n afterHydration(): void | Promise<void> {\n return\n }\n\n /**\n * Create and return a class instance\n * @param store \n * @param options \n * @template Instance The type of the store instance being created.\n * @returns The created store instance of type `Instance`, or undefined if the required keys are not present.\n */\n static customizeStore<Instance extends Store>(\n store: PiniaStore,\n options: StoreClassConstructorParams\n ): Instance | undefined {\n if (options.storeOptions && this.hasRequiredKeys(options.storeOptions)) {\n return new this(store, options) as Instance\n }\n }\n\n /**\n * Retrieves the value of a specific store option.\n * @param optionName The name of the store option to retrieve.\n * @returns The value of the specified store option, or undefined if not found.\n */\n getOption(optionName: keyof StoreOptions) {\n return this.options && (this.options as StoreOptions)[optionName]\n }\n\n /**\n * Retrieves the value of a specific state property.\n * @param propertyName The name of the state property to retrieve.\n * @returns The value of the specified state property, or undefined if not found.\n */\n getStatePropertyValue(propertyName: string) {\n return this.getValue(this.state[propertyName])\n }\n\n /**\n * Retrieves all plugin subscriptions for this store.\n * @returns An object containing all plugin subscriptions, or undefined if there are none.\n */\n getSubscriptions(): PluginSubscriptions | undefined {\n if (isEmpty(this._subscriptions)) {\n return\n }\n\n return this._subscriptions\n }\n\n /**\n * Retrieves the actual value from a potentially reactive reference.\n * @param value The value to unwrap.\n * @returns The unwrapped value if it is a reactive reference, otherwise the original value.\n */\n getValue(value: any) {\n return value?.__v_isRef ? value.value : value\n }\n\n /**\n * Checks if the given property name has a denied first character.\n * @param property The property name to check.\n * @returns True if the property name has a denied first character, otherwise false.\n */\n protected hasDeniedFirstChar(property: string): boolean {\n return hasDeniedFirstChar(property)\n }\n\n /**\n * Checks if the given options object has all the required keys.\n * @param options The options object to check.\n * @returns True if all required keys are present, otherwise false.\n */\n protected static hasRequiredKeys(options: AnyObject): boolean {\n return this._requiredKeys !== undefined && this._requiredKeys?.every(requiredKey => !!options[requiredKey])\n }\n\n /**\n * Hydrates the store, potentially performing asynchronous operations.\n * @returns void or a Promise that resolves when hydration is complete.\n */\n hydrate(): void | Promise<void> {\n return\n }\n\n /**\n * Initializes the tracer for plugin subscriptions if the createTracer option is provided.\n * @param options The plugin subscription options containing the createTracer function.\n */\n private initializeTracer(options: Omit<PluginSubscriptionOptions, 'createTracer'> & { createTracer?: () => Tracer }) {\n this._createTracer = options?.createTracer\n }\n\n /**\n * Checks if the store is using the Options API.\n * @returns True if the store is using the Options API, otherwise false.\n */\n isOptionApi(): boolean { return this.store._isOptionsAPI }\n\n /**\n * Checks if the state object has the specified property.\n * @param property The property name to check.\n * @returns True if the state object has the property, otherwise false.\n */\n stateHas(property: string): boolean { return Object.prototype.hasOwnProperty.call(this.state, property) }\n\n /**\n * Checks if the store object has the specified property.\n * @param property The property name to check.\n * @returns True if the store object has the property, otherwise false.\n */\n storeHas(property: string): boolean { return Object.prototype.hasOwnProperty.call(this.store, property) }\n\n /**\n * Emits a structured trace event scoped to this store.\n * Prefer the factory form for `payload`: it is only resolved when consumed.\n */\n trace(label: string, payload?: TracePayload, scope?: string, namespace?: string): void {\n if (this.tracer) {\n label = this.traceLabelFormatter(label)\n this.tracer.debug(label, namespace ?? label.toLowerCase(), payload, scope)\n }\n }\n\n /**\n * Emits a structured error event, or rethrows it when no listener matches.\n */\n traceError(label: string, error: unknown, payload?: TracePayload, scope?: string, namespace?: string): void {\n if (this.tracer) {\n label = this.traceLabelFormatter(label)\n this.tracer.error(label, namespace ?? label.toLowerCase(), error, payload, scope)\n } else {\n console.error(error)\n }\n }\n\n private traceLabelFormatter(label: string): string {\n if (this.classNameAddedToTraceNamespace) {\n label = `${this.constructor.name}:${label}`\n }\n\n return label\n }\n}"],"names":["PluginSubscriber","pluginName","createInstanceFunction","__publicField","options","subscriptions","context","store","createTracer","defineAStoreSetupContexts","defineAStoreSetupContextsById","setupContextDisposeWrappedStores","registerSetupContextCleanupOnDispose","id","originalDispose","args","storeOptions","storeDefinition","defineAStoreSetup","defineAStoreOptionApi","defineAStoreCtx","setupContext","shouldStoreSetupContext","useStore","defineStore","deniedFirstChar","property","getDefineAStoreSetupContext","storeRecord","getEnhancedStore","ctx","enhancedStore","setEnhancedStore","getExtendingStore","getActionStoreKey","actionName","isEmpty","value","Store","onAction","state","storeSubscribe","name","isRef","ref","toRef","subscription","optionName","propertyName","hasDeniedFirstChar","requiredKey","label","payload","scope","namespace","error"],"mappings":";;;;;AA0BA,MAA8BA,EAA8E;AAAA,EAqDxG,YAAIC,GAAcC,GAAoC;AApD9C,IAAAC,EAAA;AACA,IAAAA,EAAA;AACA,IAAAA,EAAA;AACA,IAAAA,EAAA;AAEE,IAAAA,EAAA;AACF,IAAAA,EAAA;AACA,IAAAA,EAAA;AACA,IAAAA,EAAA;AAAA,IAAAA,EAAA;AAAA,IAAAA,EAAA;AAKE,IAAAA,EAAA;AAwCN,SAAK,QAAAF,GACT,KAAA,kBAAAC;AAAA,EAGA;AAAA,EA1CO,IAAA,OAAA;AAAA,WAAA,KAAA;AAAA,EAEA;AAAA,EAGP,IAAI,gBAAe;AACf,WAAO,KAAK;AAAA,EAChB;AAAA,EAEA,IAAI,gBAAsC;AACtC,WAAO,KAAK;AAAA,EAChB;AAAA,EAEA,IAAI,cAAAE,GAAyD;AACzD,SAAA,iBAAYA;AAAA,EAChB;AAAA,EAEA,IAAI,qBAAc;AACd,WAAK,KAAA;AAAA,EACT;AAAA,EAEA,IAAI,4BAAiE;AACjE,WAA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ChBrC,IAAA;"}
@@ -2,7 +2,7 @@ import Store from "./Store";
2
2
  import type { PiniaPluginContext, Store as PiniaStore } from "pinia";
3
3
  import type { PluginExecutionOptions, PluginHydrationScheduler, PluginSubscriber as PluginSubscriberInterface, PluginSubscriptions, StoreClassConstructorParams, StoreMutationSubscription, StoreOnActionSubscription } from "../types/plugin";
4
4
  import type Tracer from "../system/Tracer";
5
- type CreateInstance<Instance = Store> = (store: PiniaStore, options: unknown) => Instance | undefined;
5
+ type CreateInstance<Instance = Store> = (store: PiniaStore, options: StoreClassConstructorParams) => Instance | undefined;
6
6
  /**
7
7
  * Type definition for the function used to create an instance of a store.
8
8
  * @template Instance The type of the store instance, defaulting to the base Store class.
@@ -1,5 +1,5 @@
1
1
  import Tracer from "../system/Tracer";
2
- import type { PluginStoreOptions, PluginSubscriptionOptions, PluginSubscriptions, StoreClassConstructorParams, StoreMutationSubscription, StoreMutationSubscriptionCallback, StoreOnActionSubscription, StoreOnActionSubscriptionCallback } from "../types/plugin";
2
+ import type { PluginSubscriptions, StoreClassConstructorParams, StoreMutationSubscription, StoreMutationSubscriptionCallback, StoreOnActionSubscription, StoreOnActionSubscriptionCallback } from "../types/plugin";
3
3
  import type { Store as PiniaStore, StateTree } from "pinia";
4
4
  import type { TracePayload } from "../types/trace";
5
5
  import type { AnyObject, PluginSubscriberInterface } from "../types";
@@ -76,7 +76,7 @@ export default class Store {
76
76
  * @template Instance The type of the store instance being created.
77
77
  * @returns The created store instance of type `Instance`, or undefined if the required keys are not present.
78
78
  */
79
- static customizeStore<Instance extends Store>(store: PiniaStore, options: PluginStoreOptions & PluginSubscriptionOptions): Instance | undefined;
79
+ static customizeStore<Instance extends Store>(store: PiniaStore, options: StoreClassConstructorParams): Instance | undefined;
80
80
  /**
81
81
  * Retrieves the value of a specific store option.
82
82
  * @param optionName The name of the store option to retrieve.
package/dist/helpers.js CHANGED
@@ -1,8 +1,8 @@
1
1
  var b = Object.defineProperty;
2
2
  var _ = (e, r, o) => r in e ? b(e, r, { enumerable: !0, configurable: !0, writable: !0, value: o }) : e[r] = o;
3
3
  var c = (e, r, o) => _(e, typeof r != "symbol" ? r + "" : r, o);
4
- import { p as y } from "./chunks/Store-DHUAJv-P.js";
5
- import { P as G, S as q, i as P } from "./chunks/Store-DHUAJv-P.js";
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
6
  const m = (e, r = "white") => `background-color: ${e}; color: ${r}; padding: 1px; margin-right: 5px; font-size: 12px`;
7
7
  function l(e, r) {
8
8
  if (Array.isArray(r) ? r.length === 0 : Object.keys(r).length === 0) {
@@ -1,8 +1,8 @@
1
1
  var k = Object.defineProperty;
2
2
  var E = (r, t, e) => t in r ? k(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
3
3
  var c = (r, t, e) => E(r, typeof t != "symbol" ? t + "" : t, e);
4
- import { h as O, g as b, i as _, p as g } from "./chunks/Store-DHUAJv-P.js";
5
- import { P as M, S as x, d as F, a as W, b as I, c as q, e as z, s as L } from "./chunks/Store-DHUAJv-P.js";
4
+ import { h as O, g as b, i as _, p as g } from "./chunks/constantes-CaTNAbzX.js";
5
+ import { P as M, S as x, d as F, a as W, b as I, c as q, e as z, s as L } from "./chunks/constantes-CaTNAbzX.js";
6
6
  import { toRaw as y } from "vue";
7
7
  function h(r) {
8
8
  if (typeof structuredClone == "function")
@@ -24,7 +24,7 @@ export interface PluginStoreOptions {
24
24
  * Store options for the plugin subscriber.
25
25
  * @type {StoreOptions}
26
26
  */
27
- storeOptions: StoreOptions;
27
+ storeOptions?: StoreOptions;
28
28
  }
29
29
  export interface PluginSubscriptionOptions {
30
30
  /**
@@ -129,7 +129,10 @@ export interface NativePiniaSubscriptionReturn<Callback> {
129
129
  */
130
130
  callback: Callback;
131
131
  }
132
- export type StoreClassConstructorParams = PluginStoreOptions & PluginSubscriptionOptions;
132
+ export type StoreClassConstructorParams = Omit<PluginSubscriptionOptions, 'createTracer'> & {
133
+ createTracer?: () => Tracer;
134
+ storeOptions?: StoreOptions;
135
+ };
133
136
  export type StoreOnActionAfterCallbackParameter = (callback: (result?: unknown) => void) => void;
134
137
  export type StoreOnActionOnErrorCallbackParameter = (callback: (error: unknown) => void) => void;
135
138
  export interface StoreOnActionCallbackParameters {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinia-plugin-subscription",
3
- "version": "1.0.0-beta.1",
3
+ "version": "1.0.0-beta.2",
4
4
  "description": "Pinia plugin for Vue.js that helps building Pinia plugins by centralizing subscriber registration and providing a Store base class for store helpers.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -1 +0,0 @@
1
- {"version":3,"file":"Store-DHUAJv-P.js","sources":["../../src/core/PluginSubscriber.ts","../../src/utils/store.ts","../../src/utils/validation/index.ts","../../src/core/Store.ts","../../src/utils/constantes.ts"],"sourcesContent":["import Store from \"./Store\";\nimport type { PiniaPluginContext, Store as PiniaStore } from \"pinia\";\nimport type { AnyObject } from \"../types\";\nimport type {\n PluginExecutionOptions,\n PluginHydrationScheduler,\n PluginSubscriber as PluginSubscriberInterface,\n PluginSubscriptions,\n StoreClassConstructorParams,\n StoreMutationSubscription,\n StoreOnActionSubscription\n} from \"../types/plugin\";\nimport type Tracer from \"../system/Tracer\";\n\n\n\ntype CreateInstance<Instance = Store> = (store: PiniaStore, options: unknown) => Instance | undefined\n\n\n/**\n * Type definition for the function used to create an instance of a store.\n * @template Instance The type of the store instance, defaulting to the base Store class.\n * @param store The Pinia store for which the instance is being created.\n * @param options Additional options for creating the store instance.\n * @returns The created store instance or undefined if creation fails.\n */\nexport default abstract class PluginSubscriber<Instance extends Store> implements PluginSubscriberInterface {\n private _createInstance: CreateInstance\n private _name: string\n private _pluginOptions?: StoreClassConstructorParams\n private _storeInstance?: Instance\n /** Callback function to reset the store instance, if needed. */\n protected _resetStoreCallback?: (store?: PiniaStore) => void\n private _storeOnActionSubscription?: StoreOnActionSubscription\n private _storeMutationSubscription?: StoreMutationSubscription\n private _subscriptions?: PluginSubscriptions\n /**\n * Called when the plugin subscriber has been created for a specific store.\n * This callback can be used to perform any initialization or setup required for the plugin subscriber.\n */\n protected pluginCreated?: (store: PiniaStore) => void\n /** Options for the plugin subscriber's execution. */\n public execution?: PluginExecutionOptions\n /** Scheduler for handling the hydration process of the plugin subscriber. */\n public hydrationScheduler?: PluginHydrationScheduler\n\n\n get name(): string {\n return this._name;\n }\n\n get storeInstance(): Instance | undefined {\n return this._storeInstance\n }\n\n get pluginOptions(): StoreClassConstructorParams | undefined {\n return this._pluginOptions;\n }\n\n set pluginOptions(options: StoreClassConstructorParams | undefined) {\n this._pluginOptions = options;\n }\n\n get resetStoreCallback(): ((store?: PiniaStore) => void) | undefined {\n return this._resetStoreCallback as ((store?: PiniaStore) => void) | undefined;\n }\n\n get storeOnActionSubscription(): StoreOnActionSubscription | undefined {\n return this._storeOnActionSubscription;\n }\n\n get storeMutationSubscription(): StoreMutationSubscription | undefined {\n return this._storeMutationSubscription;\n }\n\n get subscriptions(): PluginSubscriptions | undefined {\n return this._subscriptions\n }\n\n set subscriptions(subscriptions: PluginSubscriptions) {\n this._subscriptions = subscriptions\n }\n\n\n constructor(pluginName: string, createInstanceFunction: CreateInstance) {\n this._name = pluginName\n this._createInstance = createInstanceFunction\n }\n\n /**\n * Called after the store has been hydrated.\n * @param context The Pinia plugin context containing the store and options.\n * @returns A promise that resolves when the post-hydration process is complete, or void if synchronous.\n */\n public afterHydration(context: PiniaPluginContext): void | Promise<void> {\n return\n }\n\n /**\n * Called when the plugin subscriber needs to hydrate its state.\n * @param context The Pinia plugin context containing the store and options.\n * @returns A promise that resolves when the hydration process is complete, or void if synchronous.\n */\n public hydrate(context: PiniaPluginContext): void | Promise<void> {\n return\n }\n\n /**\n * Invokes the plugin subscriber with the given context and optional tracer creation function.\n * @param context The Pinia plugin context containing the store and options.\n * @param createTracer Optional function to create a tracer for the plugin.\n * @returns True if the plugin was successfully invoked, otherwise false.\n */\n public invoke({ store, options }: PiniaPluginContext, createTracer?: (name: string) => Tracer): boolean {\n this._storeInstance = this._createInstance(store, { ...options, ...this.pluginOptions, createTracer }) as Instance\n\n if (!this._storeInstance) {\n return false\n }\n\n this._subscriptions = this._storeInstance.getSubscriptions()\n this._storeMutationSubscription = this._storeInstance.storeSubscribe\n this._storeOnActionSubscription = this._storeInstance.onAction\n\n if (this.pluginCreated) {\n this.pluginCreated(store)\n }\n\n return true\n }\n}","import { defineStore } from \"pinia\"\nimport type {\n DefineSetupStoreOptions,\n DefineStoreOptions,\n SetupStoreDefinition,\n StateTree,\n Store,\n StoreDefinition,\n _ExtractActionsFromSetupStore,\n _ExtractGettersFromSetupStore,\n _ExtractStateFromSetupStore,\n _GettersTree\n} from \"pinia\"\nimport type { AnyObject } from \"../types\"\nimport type {\n DefineAStoreDefinition,\n DefineAStoreSetupContext,\n EmptyExtensions,\n StoreOptions\n} from \"../types/store\"\nimport type { PluginStoreOptions } from \"../types/plugin\"\n\n\nexport const itemState = {\n '@id': undefined,\n id: undefined\n}\n\ntype DefineAStoreSetup<SS, TExtraExtensions extends Record<string, unknown> = EmptyExtensions> =\n (ctx: DefineAStoreSetupContext<SS, TExtraExtensions>) => SS\n\n/**\n * Options parameter of pinia's `defineStore()` for setup stores, derived from\n * the setup function return type.\n */\ntype DefineAStoreSetupOptions<Id extends string, SS> = DefineSetupStoreOptions<\n Id,\n _ExtractStateFromSetupStore<SS>,\n _ExtractGettersFromSetupStore<SS>,\n _ExtractActionsFromSetupStore<SS>\n>\n\nconst defineAStoreSetupContexts = new WeakMap<object, DefineAStoreSetupContext<AnyObject>>()\nconst defineAStoreSetupContextsById = new Map<string, DefineAStoreSetupContext<AnyObject>>()\nconst setupContextDisposeWrappedStores = new WeakSet<object>()\n\nfunction registerSetupContextCleanupOnDispose(\n store: AnyObject,\n id: string\n): void {\n if (setupContextDisposeWrappedStores.has(store) || typeof store.$dispose !== 'function') {\n return\n }\n\n const originalDispose = store.$dispose as (...args: unknown[]) => unknown\n store.$dispose = (...args: unknown[]) => {\n defineAStoreSetupContexts.delete(store)\n defineAStoreSetupContextsById.delete(id)\n return originalDispose.apply(store, args)\n }\n setupContextDisposeWrappedStores.add(store)\n}\n\n/**\n * Define a store with the setup API. State, getters and actions are inferred\n * from the setup function return, exactly like pinia's `defineStore`, so\n * store members are listed by IDEs and action prototypes are preserved.\n * @template Id The type of the store identifier.\n * @template SS The type of the setup function return.\n * @param id The unique identifier for the store.\n * @param storeDefinition The setup function defining the store.\n * @param options Optional store options.\n * @returns The defined store.\n */\nexport function defineAStore<Id extends string, SS>(\n id: Id,\n storeDefinition: (ctx?: DefineAStoreSetupContext<AnyObject>) => SS,\n options?: StoreOptions\n): SetupStoreDefinition<Id, SS>\n/**\n * Define a store with the options API, mirroring pinia's `defineStore` inference.\n * @template Id The type of the store identifier.\n * @template S The type of the store's state.\n * @template G The type of the store's getters.\n * @template A The type of the store's actions.\n * @param id The unique identifier for the store.\n * @param storeDefinition The store options definition.\n * @param options Optional store options.\n * @returns The defined store.\n */\nexport function defineAStore<Id extends string, S extends StateTree = {}, G extends _GettersTree<S> = {}, A = {}>(\n id: Id,\n storeDefinition: Omit<DefineStoreOptions<Id, S, G, A>, 'id'>,\n options?: StoreOptions\n): StoreDefinition<Id, S, G, A>\n/**\n * Define a store with explicit store/state types, e.g. when plugins augment\n * the store with members not returned by the setup function.\n * @template Sto The type of the store.\n * @template Sta The type of the store's state.\n * @param id The unique identifier for the store.\n * @param storeDefinition The store definition, either as an options object or a setup function.\n * @param options Optional store options.\n * @returns The defined store.\n */\nexport function defineAStore<Sto, Sta>(\n id: string,\n storeDefinition:\n | Omit<DefineStoreOptions<string, StateTree & Sta, AnyObject, Partial<Sto>>, 'id'>\n | ((ctx?: DefineAStoreSetupContext<Sto & Sta>) => AnyObject),\n options?: StoreOptions\n): DefineAStoreDefinition<Sto, Sta>\nexport function defineAStore(\n id: string,\n storeDefinition:\n | Omit<DefineStoreOptions<string, StateTree, AnyObject, AnyObject>, 'id'>\n | DefineAStoreSetup<AnyObject>,\n options?: StoreOptions\n): StoreDefinition {\n const storeOptions: PluginStoreOptions = options ? { storeOptions: options } : {} as PluginStoreOptions\n\n return (typeof storeDefinition === 'function'\n ? defineAStoreSetup(\n id,\n storeDefinition as DefineAStoreSetup<AnyObject>,\n storeOptions\n )\n : defineAStoreOptionApi(\n id,\n storeDefinition,\n storeOptions\n )) as StoreDefinition\n}\n\n/**\n * Define a store with a required, fully typed setup context. State, getters\n * and actions are inferred from the setup function return.\n * @template Id The type of the store identifier.\n * @template SS The type of the setup function return.\n * @template TExtraExtensions The type of the store's extra extensions.\n * @param id The unique identifier for the store.\n * @param storeDefinition The setup function defining the store.\n * @param options Optional store options.\n * @returns The defined store with setup context.\n */\nexport function defineAStoreCtx<Id extends string, SS, TExtraExtensions extends Record<string, unknown> = EmptyExtensions>(\n id: Id,\n storeDefinition: (ctx: DefineAStoreSetupContext<AnyObject, TExtraExtensions>) => SS,\n options?: StoreOptions\n): SetupStoreDefinition<Id, SS>\n/**\n * Define a store with a setup context and explicit store/state types, e.g.\n * when plugins augment the store with members not returned by the setup function.\n * @template Sto The type of the store.\n * @template Sta The type of the store's state.\n * @template TExtraExtensions The type of the store's extra extensions.\n * @param id The unique identifier for the store.\n * @param storeDefinition The setup function defining the store.\n * @param options Optional store options.\n * @returns The defined store with setup context.\n */\nexport function defineAStoreCtx<Sto, Sta, TExtraExtensions extends Record<string, unknown> = EmptyExtensions>(\n id: string,\n storeDefinition: (ctx: DefineAStoreSetupContext<Sto & Sta, TExtraExtensions>) => AnyObject,\n options?: StoreOptions\n): DefineAStoreDefinition<Sto, Sta>\nexport function defineAStoreCtx(\n id: string,\n storeDefinition: DefineAStoreSetup<AnyObject, any>,\n options?: StoreOptions\n): StoreDefinition {\n const storeOptions: PluginStoreOptions = options\n ? { storeOptions: { ...options, enhancedStore: true } }\n : { storeOptions: { enhancedStore: true } } as PluginStoreOptions\n\n return defineAStoreSetup(\n id,\n storeDefinition,\n storeOptions\n ) as StoreDefinition\n}\n\nexport function defineAStoreSetup<Id extends string, SS>(\n id: Id,\n storeDefinition: DefineAStoreSetup<SS>,\n options: PluginStoreOptions\n): SetupStoreDefinition<Id, SS> {\n const setupContext: DefineAStoreSetupContext<SS> = {\n id,\n extensions: {}\n }\n\n const shouldStoreSetupContext = options?.storeOptions?.enhancedStore === true\n\n // `storeOptions` augments pinia's DefineStoreOptionsBase (see createPlugin.ts);\n // the assertion stays valid in compilation units where the augmentation is not loaded.\n const useStore = defineStore(\n id,\n () => storeDefinition(setupContext),\n options as unknown as DefineAStoreSetupOptions<Id, SS>\n )\n\n return Object.assign(((...args: Parameters<typeof useStore>) => {\n if (shouldStoreSetupContext) {\n defineAStoreSetupContextsById.set(id, setupContext as DefineAStoreSetupContext<AnyObject>)\n }\n\n const store = useStore(...args)\n\n if (shouldStoreSetupContext) {\n defineAStoreSetupContexts.set(store, setupContext as DefineAStoreSetupContext<AnyObject>)\n defineAStoreSetupContextsById.delete(id)\n registerSetupContextCleanupOnDispose(store as AnyObject, id)\n }\n\n return store\n }) as typeof useStore, useStore)\n}\n\nexport function defineAStoreOptionApi<Id extends string, S extends StateTree = {}, G extends _GettersTree<S> = {}, A = {}>(\n id: Id,\n storeDefinition: Omit<DefineStoreOptions<Id, S, G, A>, 'id'>,\n options?: PluginStoreOptions\n): StoreDefinition<Id, S, G, A> {\n if (options) {\n storeDefinition = { ...storeDefinition, ...(options ?? {}) }\n }\n\n return defineStore(id, storeDefinition)\n}\n\nconst deniedFirstChar = new Set<string>(['_', '$'])\n\n/**\n * Check if a property has a denied first character : ['_', '$'].\n * @param property The property name to check.\n * @returns True if the property has a denied first character, false otherwise.\n */\nexport function hasDeniedFirstChar(property: string): boolean {\n return deniedFirstChar.has(property[0] as string)\n}\n\n/**\n * Get the setup context associated with a store instance (or pending store id).\n * @param store The store instance, or an object exposing the store `$id`.\n * @returns The setup context when the store was defined with `enhancedStore` enabled, undefined otherwise.\n */\nexport function getDefineAStoreSetupContext(store: object): DefineAStoreSetupContext<AnyObject> | undefined {\n const storeRecord = store as AnyObject\n\n return defineAStoreSetupContexts.get(store)\n ?? (typeof storeRecord?.$id === 'string'\n ? defineAStoreSetupContextsById.get(storeRecord.$id)\n : undefined)\n}\n\n/**\n * Get the enhanced store from the context.\n * @template TEnhancedStore The type of the enhanced store.\n * @param ctx The context containing the extensions.\n * @returns The enhanced store casted to the specified types.\n */\nexport function getEnhancedStore<TEnhancedStore>(\n ctx: DefineAStoreSetupContext<TEnhancedStore>\n): TEnhancedStore {\n const enhancedStore = ctx.extensions.enhancedStore ?? ctx.extensions.extending\n\n if (!enhancedStore) {\n throw new Error(`${ctx.id}Store - getEnhancedStore - Error: enhanced store is required`)\n }\n\n return enhancedStore\n}\n\n/**\n * Set the enhanced store in context with deprecated alias support.\n * @template TEnhancedStore The type of the enhanced store.\n * @param ctx The context containing the extensions.\n * @param store The store to expose as enhancement.\n */\nexport function setEnhancedStore<TEnhancedStore>(\n ctx: DefineAStoreSetupContext<TEnhancedStore>,\n store: TEnhancedStore\n): void {\n ctx.extensions.enhancedStore = store\n ctx.extensions.extending = store\n}\n\n/**\n * @deprecated Use getEnhancedStore instead.\n */\nexport function getExtendingStore<TEnhancedStore>(\n ctx: DefineAStoreSetupContext<TEnhancedStore>\n): TEnhancedStore {\n console.warn(`${ctx.id}Store - getExtendingStore is deprecated. Use getEnhancedStore instead.`)\n return getEnhancedStore<TEnhancedStore>(ctx)\n}\n\n/**\n * Get the storage key for a given action and store combination.\n * @param actionName The name of the action.\n * @param store The Pinia store instance.\n * @returns The storage key for the action and store combination.\n */\nexport function getActionStoreKey(actionName: string, store: Store): string {\n return `${actionName}-${store.$id}`\n}","export function isEmpty(value: any): boolean {\n if (!value) {\n return (typeof value === 'boolean' || typeof value === 'number') ? false : true\n }\n\n if (Array.isArray(value)) {\n return value.length === 0\n }\n\n if (typeof value === 'object') {\n return Object.keys(value).length === 0\n }\n\n if (typeof value === 'string') {\n return value.trim() === ''\n }\n\n return false\n}","import { isRef, ref, toRef } from \"vue\"\nimport Tracer from \"../system/Tracer\"\nimport { getDefineAStoreSetupContext, hasDeniedFirstChar, setEnhancedStore } from \"../utils/store\"\nimport { isEmpty } from \"../utils/validation\"\nimport { pluginName } from \"../utils/constantes\"\n\nimport type {\n PluginStoreOptions,\n PluginSubscriptionOptions,\n PluginSubscriptions,\n StoreClassConstructorParams,\n StoreMutationSubscription,\n StoreMutationSubscriptionCallback,\n StoreMutationSubscriptionReturn,\n StoreOnActionSubscription,\n StoreOnActionSubscriptionCallback,\n StoreOnActionSubscriptionReturn\n} from \"../types/plugin\"\nimport type { Store as PiniaStore, StateTree } from \"pinia\"\nimport type { TracePayload } from \"../types/trace\"\nimport type { AnyObject, PluginSubscriberInterface } from \"../types\"\nimport type { StoreOptions, StatePropertyValue } from \"../types/store\"\n\n/**\n * Base class for a Pinia store with enhanced capabilities.\n * Provides structured tracing, plugin subscriptions, and state management utilities.\n * @remarks\n * This class is intended to be extended by specific store implementations\n * that require enhanced capabilities such as structured tracing and plugin subscriptions.\n */\nexport default class Store {\n protected _className = 'Store'\n private _createTracer?: PluginSubscriptionOptions['createTracer']\n private _onAction?: StoreOnActionSubscriptionCallback\n private _options: StoreOptions\n private _store: PiniaStore\n private _storeSubscribe?: StoreMutationSubscriptionCallback\n private _subscriptions: PluginSubscriptions = {}\n private _traceOptions: Record<string, boolean> = {\n /** Indicates whether to add the class name to the namespace for tracing purposes. */\n addClassNameToLabel: true,\n }\n private _tracer?: Tracer\n\n protected static _requiredKeys?: string[]\n\n get classNameAddedToTraceNamespace(): boolean {\n return this._traceOptions.addClassNameToLabel\n }\n\n set classNameAddedToTraceNamespace(value: boolean) {\n this._traceOptions.addClassNameToLabel = value\n }\n\n get onAction(): StoreOnActionSubscription | undefined {\n if (!this._onAction) {\n return\n }\n\n return () => ({\n store: this.store as PiniaStore,\n callback: this._onAction\n }) as StoreOnActionSubscriptionReturn\n }\n\n set onAction(onAction: StoreOnActionSubscriptionCallback) {\n this._onAction = onAction\n }\n\n get options(): StoreOptions { return this._options }\n\n get state(): StateTree { return this._store.$state }\n\n set state(state: StateTree) { this._store.$state = state }\n\n get store(): AnyObject { return this._store }\n\n get storeSubscribe(): StoreMutationSubscription | undefined {\n if (!this._storeSubscribe) {\n return\n }\n\n return () => ({\n store: this.store as PiniaStore,\n callback: this._storeSubscribe\n }) as StoreMutationSubscriptionReturn\n }\n\n set storeSubscribe(storeSubscribe: StoreMutationSubscriptionCallback) {\n this._storeSubscribe = storeSubscribe\n }\n\n /**\n * Returns the structured trace emitter of this store.\n * Built lazily so that subclasses overriding `_className` are reflected.\n */\n protected get tracer(): Tracer | undefined {\n if (!this._tracer && this._createTracer) {\n this._tracer = this._createTracer(pluginName)\n this._tracer.scope = this.store.$id\n }\n\n return this._tracer\n }\n\n /**\n * Constructs a new instance of the store.\n * @param store The Pinia store instance.\n * @param options The plugin store options and subscription options.\n * @remarks\n * This constructor is typically called by the `customizeStore` static method\n * to create an instance of the store with the provided Pinia store and options.\n * @see PluginStoreOptions\n * @see PluginSubscriptionOptions\n */\n constructor(store: PiniaStore, options: StoreClassConstructorParams) {\n this._options = options.storeOptions\n this._store = store\n this.initializeTracer(options)\n\n if (this._options?.enhancedStore) {\n const ctx = getDefineAStoreSetupContext(this.store)\n\n if (ctx) {\n setEnhancedStore(ctx, this.store)\n }\n }\n }\n\n /**\n * Adds a property to the state of this store.\n * @param name The name of the property to add.\n * @param value The value of the property to add.\n */\n addToState(name: string, value?: StatePropertyValue): void {\n if (!this.isOptionApi()) {\n if (!isRef(value)) {\n value = ref<StatePropertyValue>(value)\n }\n }\n\n this.state[name] = value\n this.store[name] = toRef(this.state, name)\n }\n\n /**\n * Adds a subscription for a specific plugin to this store.\n * @param pluginName The name of the plugin for which the subscription is being added.\n * @param subscription The subscription callback or object to add.\n * @param options Additional options for the subscription, including subscription options and target stores.\n */\n addSubscription(\n pluginName: string,\n subscription: PluginSubscriberInterface,\n options?: { subscriptionOptions?: StoreOptions, stores?: PiniaStore[] }\n ): void {\n this._subscriptions[pluginName] = { subscription, ...(options ?? {}) }\n }\n\n /**\n * Called after the store has been hydrated.\n * @returns A promise that resolves when the post-hydration process is complete, or void if synchronous.\n */\n afterHydration(): void | Promise<void> {\n return\n }\n\n /**\n * Create and return a class instance\n * @param store \n * @param options \n * @template Instance The type of the store instance being created.\n * @returns The created store instance of type `Instance`, or undefined if the required keys are not present.\n */\n static customizeStore<Instance extends Store>(\n store: PiniaStore,\n options: PluginStoreOptions & PluginSubscriptionOptions\n ): Instance | undefined {\n if (options.storeOptions && this.hasRequiredKeys(options.storeOptions)) {\n return new this(store, options) as Instance\n }\n }\n\n /**\n * Retrieves the value of a specific store option.\n * @param optionName The name of the store option to retrieve.\n * @returns The value of the specified store option, or undefined if not found.\n */\n getOption(optionName: keyof StoreOptions) {\n return this.options && (this.options as StoreOptions)[optionName]\n }\n\n /**\n * Retrieves the value of a specific state property.\n * @param propertyName The name of the state property to retrieve.\n * @returns The value of the specified state property, or undefined if not found.\n */\n getStatePropertyValue(propertyName: string) {\n return this.getValue(this.state[propertyName])\n }\n\n /**\n * Retrieves all plugin subscriptions for this store.\n * @returns An object containing all plugin subscriptions, or undefined if there are none.\n */\n getSubscriptions(): PluginSubscriptions | undefined {\n if (isEmpty(this._subscriptions)) {\n return\n }\n\n return this._subscriptions\n }\n\n /**\n * Retrieves the actual value from a potentially reactive reference.\n * @param value The value to unwrap.\n * @returns The unwrapped value if it is a reactive reference, otherwise the original value.\n */\n getValue(value: any) {\n return value?.__v_isRef ? value.value : value\n }\n\n /**\n * Checks if the given property name has a denied first character.\n * @param property The property name to check.\n * @returns True if the property name has a denied first character, otherwise false.\n */\n protected hasDeniedFirstChar(property: string): boolean {\n return hasDeniedFirstChar(property)\n }\n\n /**\n * Checks if the given options object has all the required keys.\n * @param options The options object to check.\n * @returns True if all required keys are present, otherwise false.\n */\n protected static hasRequiredKeys(options: AnyObject): boolean {\n return this._requiredKeys !== undefined && this._requiredKeys?.every(requiredKey => !!options[requiredKey])\n }\n\n /**\n * Hydrates the store, potentially performing asynchronous operations.\n * @returns void or a Promise that resolves when hydration is complete.\n */\n hydrate(): void | Promise<void> {\n return\n }\n\n /**\n * Initializes the tracer for plugin subscriptions if the createTracer option is provided.\n * @param options The plugin subscription options containing the createTracer function.\n */\n private initializeTracer(options: PluginSubscriptionOptions) {\n this._createTracer = options?.createTracer\n }\n\n /**\n * Checks if the store is using the Options API.\n * @returns True if the store is using the Options API, otherwise false.\n */\n isOptionApi(): boolean { return this.store._isOptionsAPI }\n\n /**\n * Checks if the state object has the specified property.\n * @param property The property name to check.\n * @returns True if the state object has the property, otherwise false.\n */\n stateHas(property: string): boolean { return Object.prototype.hasOwnProperty.call(this.state, property) }\n\n /**\n * Checks if the store object has the specified property.\n * @param property The property name to check.\n * @returns True if the store object has the property, otherwise false.\n */\n storeHas(property: string): boolean { return Object.prototype.hasOwnProperty.call(this.store, property) }\n\n /**\n * Emits a structured trace event scoped to this store.\n * Prefer the factory form for `payload`: it is only resolved when consumed.\n */\n trace(label: string, payload?: TracePayload, scope?: string, namespace?: string): void {\n if (this.tracer) {\n label = this.traceLabelFormatter(label)\n this.tracer.debug(label, namespace ?? label.toLowerCase(), payload, scope)\n }\n }\n\n /**\n * Emits a structured error event, or rethrows it when no listener matches.\n */\n traceError(label: string, error: unknown, payload?: TracePayload, scope?: string, namespace?: string): void {\n if (this.tracer) {\n label = this.traceLabelFormatter(label)\n this.tracer.error(label, namespace ?? label.toLowerCase(), error, payload, scope)\n } else {\n console.error(error)\n }\n }\n\n private traceLabelFormatter(label: string): string {\n if (this.classNameAddedToTraceNamespace) {\n label = `${this.constructor.name}:${label}`\n }\n\n return label\n }\n}","export const pluginName: string = 'pinia-plugin-subscription'"],"names":["PluginSubscriber","pluginName","createInstanceFunction","__publicField","options","subscriptions","context","store","createTracer","defineAStoreSetupContexts","defineAStoreSetupContextsById","setupContextDisposeWrappedStores","registerSetupContextCleanupOnDispose","id","originalDispose","args","storeOptions","storeDefinition","defineAStoreSetup","defineAStoreOptionApi","defineAStoreCtx","setupContext","shouldStoreSetupContext","useStore","defineStore","deniedFirstChar","property","getDefineAStoreSetupContext","storeRecord","getEnhancedStore","ctx","enhancedStore","setEnhancedStore","getExtendingStore","getActionStoreKey","actionName","isEmpty","value","Store","onAction","state","storeSubscribe","name","isRef","ref","toRef","pluginName2","subscription","optionName","propertyName","hasDeniedFirstChar","requiredKey","label","payload","scope","namespace","error"],"mappings":";;;;;AA0BA,MAA8BA,EAA8E;AAAA,EAqDxG,YAAIC,GAAcC,GAAoC;AApD9C,IAAAC,EAAA;AACA,IAAAA,EAAA;AACA,IAAAA,EAAA;AACA,IAAAA,EAAA;AAEE,IAAAA,EAAA;AACF,IAAAA,EAAA;AACA,IAAAA,EAAA;AACA,IAAAA,EAAA;AAAA,IAAAA,EAAA;AAAA,IAAAA,EAAA;AAKE,IAAAA,EAAA;AAwCN,SAAK,QAAAF,GACT,KAAA,kBAAAC;AAAA,EAGA;AAAA,EA1CO,IAAA,OAAA;AAAA,WAAA,KAAA;AAAA,EAEA;AAAA,EAGP,IAAI,gBAAe;AACf,WAAO,KAAK;AAAA,EAChB;AAAA,EAEA,IAAI,gBAAsC;AACtC,WAAO,KAAK;AAAA,EAChB;AAAA,EAEA,IAAI,cAAAE,GAAyD;AACzD,SAAA,iBAAYA;AAAA,EAChB;AAAA,EAEA,IAAI,qBAAc;AACd,WAAK,KAAA;AAAA,EACT;AAAA,EAEA,IAAI,4BAAiE;AACjE,WAAO,KAAK;AAAA,EAChB;AAAA,EAEA,IAAI,4BAAmE;AACnE,WAAO,KAAK;AAAA,EAChB;AAAA,EAEA,IAAI;AACA,WAAO,KAAK;AAAA,EAChB;AAAA,EAEA,IAAI,cAAAC,GAAiD;AACjD,SAAA,iBAAYA;AAAA,EAChB;AAAA,EASI,eAAKC,GAAA;AAAA,EACT;AAAA,EAAA,QAAAA,GAAA;AAAA,EAAA;AAAA,E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