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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,43 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [Unreleased]
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
+ ### Added
14
+ - Added `createTracerRegistry()` to create isolated trace listeners and tracers for each application or Pinia instance
15
+ - Added the `Tracer` class and registry methods `addTraceListener()`, `clearTraceListeners()` and `hasTraceListeners()`
16
+ - Added metadata-based trace filter criteria with `equals`, `contains`, `startsWith` and `endsWith` comparators, combined with `every` or `some`
17
+ - Added `createConsoleTraceListener()` as an opt-in console sink for trace events
18
+ - Added `trace()` and `traceError()` to `Store` and `PluginSubscription`
19
+ - Added trace types: `TraceEvent`, `TraceEventMetadata`, `TraceFilter`, `TraceHandler`, `TraceLevel`, `TraceListener`, `TraceListenerRemover`, `TracePayload`, `TracerOptions`
20
+ - Added `check:leaks` script and `scripts/check-dist-leaks.mjs`, guarding published artifacts against non-peer dependency imports in `dist/` (`.js` and `.d.ts`)
21
+ - Added the leak guard to `npm run build` and to the CI workflow
22
+ - Added unit tests covering the tracing system and the leak detection logic
23
+
24
+ ### Changed
25
+ - Clarified that SSR tracing registries and plugin instances must be created per request, and added coverage for listener isolation between registries
26
+ - Replaced the `Debug` abstract class with composition: `Store` and `PluginSubscription` no longer extend it and now own a `Tracer`
27
+ - `createPlugin()` accepts `PluginSubscriptionOptions`, including a `createTracer` factory to connect a tracer registry to plugin and store trace events
28
+ - Trace errors with no matching listener, and failures in listener filters or handlers, are now reported with `console.error` instead of rethrowing the original error
29
+ - Deprecated `createHydrationPlugin()` in favor of `createPlugin()` with hydration options
30
+ - Trace payloads are now lazily resolved, so unobserved tracing no longer builds log arguments
31
+ - Internal events now derive namespaces from trace labels, with `PluginSubscription` prefixed by default; store events carry `store.$id` as `scope`
32
+ - `Tracer` now delegates all output decisions to listeners and no longer owns a console or an enabled state
33
+ - Error events are delivered to matching listeners and reported with `console.error` when none match
34
+ - Store trace labels can include the store class name by default, and callers can override the event namespace
35
+ - Excluded `scripts/**` from coverage thresholds, as build tooling is not shipped to consumers
36
+
37
+ ### Removed
38
+ - **Breaking:** removed `debugLog()` and `logError()` from `Store` and `PluginSubscription` — use `trace()` and `traceError()` instead (see the migration snippet in `README.md`)
39
+ - **Breaking:** removed the obsolete `debug` and custom-console arguments from `createPlugin()`, `PluginSubscription`, `PluginSubscriber`, `Store`, and `Store.customizeStore()`
40
+ - **Breaking:** removed the `debug` argument from subscriber `invoke()`, `hydrate()`, and `afterHydration()` hooks; tracing is now configured exclusively through listeners
41
+ - **Breaking:** removed the legacy `debug` and `console` accessors from `Store` and `PluginSubscription`
42
+ - Removed the internal `src/system/Debug.ts` abstract class (was never publicly exported)
43
+ - **Breaking:** replaced module-global trace-listener functions with methods on a `createTracerRegistry()` instance
44
+
8
45
  ## [0.2.1]
9
46
 
10
47
  ### Fixed
@@ -97,7 +134,6 @@ Minor change
97
134
  - `getDefineAStoreSetupContext()` now falls back to store ID lookup during plugin execution timing.
98
135
  - `defineAStoreSetup()` now stores setup contexts only for stores with `storeOptions.enhancedStore = true`.
99
136
  - `defineAStoreSetup()` now removes ID-indexed setup contexts after weak-map registration and on store disposal.
100
- - `defineAStoreSetup()` now logs setup-context map size transitions when `storeOptions.debug = true`.
101
137
  - Public exports now include `defineAStoreCtx`, `getEnhancedStore`, and `setEnhancedStore`.
102
138
  - GitHub Actions now publishes GitHub pre-releases to npm with the `beta` dist-tag.
103
139
 
package/README.md CHANGED
@@ -47,15 +47,14 @@ Register the plugin in your `main.ts`:
47
47
  ```js
48
48
  import { createApp } from 'vue'
49
49
  import { createPinia } from 'pinia'
50
- import { createPlugin, PLUGIN_NAME } from 'pinia-plugin-subscription'
50
+ import { createPlugin } from 'pinia-plugin-subscription'
51
51
  import { myStoreSubscriber } from './plugins/my-store'
52
52
  import App from './App.vue'
53
53
 
54
54
  const app = createApp(App)
55
55
  const pinia = createPinia()
56
56
 
57
- // Register plugin (subscribers array, plugins to debug)
58
- pinia.use(createPlugin([myStoreSubscriber], [PLUGIN_NAME]))
57
+ pinia.use(createPlugin([myStoreSubscriber]))
59
58
 
60
59
  app.use(pinia)
61
60
  app.mount('#app')
@@ -63,6 +62,114 @@ app.mount('#app')
63
62
 
64
63
  ### Import subpaths
65
64
 
65
+ ## Usage — Examples
66
+
67
+ **1) Subscriber using a `Store` subclass:**
68
+
69
+ ```typescript
70
+ import PluginSubscriber from 'pinia-plugin-subscription'
71
+ import { Store } from 'pinia-plugin-subscription'
72
+
73
+ class MyPlugin extends Store {
74
+ protected override _className: string = 'MyPlugin'
75
+ protected static override _requiredKeys?: string[] | undefined = ['my-plugin-option']
76
+
77
+ constructor(store, options) {
78
+ super(store, options)
79
+ this.doSomething()
80
+ }
81
+ }
82
+
83
+ class MyPluginSubscriber extends PluginSubscriber<MyPlugin> {
84
+ constructor() {
85
+ super('my-plugin', MyPlugin.customizeStore.bind(MyPlugin))
86
+ }
87
+ }
88
+
89
+ export const myStoreSubscriber = new MyPluginSubscriber()
90
+ ```
91
+
92
+ **2) Simple subscriber implementing `PluginSubscriberInterface`:**
93
+
94
+ ```typescript
95
+ import type { PluginSubscriberInterface } from 'pinia-plugin-subscription'
96
+
97
+ export const myStoreSubscriber: PluginSubscriberInterface = {
98
+ name: 'my-plugin',
99
+
100
+ invoke: (context) => {
101
+ // context contains `store`, `options`, `pinia`
102
+ console.log('store registered', context.store.$id)
103
+
104
+ return true
105
+ },
106
+
107
+ resetStoreCallback: (store) => {
108
+ console.log('store reset:', store.$id)
109
+ }
110
+ }
111
+ ```
112
+
113
+ ## Advanced Features
114
+
115
+ - **Structured tracing:** Subscribe to typed trace events and filter them at runtime, per store or per namespace — see [Tracing](#tracing).
116
+ - **Reset callbacks:** Define `resetStoreCallback` to run custom logic when a store is reset.
117
+ - **SSR and hydration control:** Configure whether each subscribed plugin runs on the server, the client, or only after client hydration.
118
+ - **Lifecycle safety:** Internal hydration ordering is now guarded so `hydrate()` completes before `afterHydration()` and disposed stores do not retain stale subscriber metadata.
119
+
120
+ ## API Reference
121
+
122
+ ### `createPlugin(subscribers: PluginSubscriber[], options?: PluginSubscriptionOptions): PiniaPlugin`
123
+
124
+ Creates and returns a Pinia plugin from the provided `subscribers`. Each subscriber is invoked when a store is registered. The optional `options` configure execution, hydration and tracing.
125
+
126
+ ### `createHydrationPlugin(subscribers: PluginSubscriber[], options?: PluginSubscriptionOptions): PiniaPlugin`
127
+
128
+ Deprecated. Use `createPlugin()` with hydration options instead. This helper remains available for compatibility.
129
+
130
+ ```typescript
131
+ import { createPlugin } from 'pinia-plugin-subscription'
132
+
133
+ pinia.use(createPlugin([
134
+ persistedStateSubscriber
135
+ ], {
136
+ hydrationScheduler: (run) => {
137
+ nextTick(() => run())
138
+ }
139
+ }))
140
+ ```
141
+
142
+ ### SSR / Nuxt hydration control
143
+
144
+ The source of truth for hydration policy stays on the subscriber itself. For example, a client-only plugin should declare its execution directly:
145
+
146
+ ```typescript
147
+ export const persistedStateSubscriber: PluginSubscriberInterface = {
148
+ name: 'persisted-state',
149
+ execution: {
150
+ environment: 'client',
151
+ hydration: 'defer',
152
+ },
153
+ hydrationScheduler: (run) => {
154
+ nextTick(() => run())
155
+ },
156
+ invoke: (context) => {
157
+ // ...
158
+ return true
159
+ }
160
+ }
161
+ ```
162
+
163
+ Available execution options:
164
+
165
+ - `environment: 'both' | 'client' | 'server'` — controls where the subscriber is allowed to run.
166
+ - `hydration: 'immediate' | 'defer'` — on the client, `defer` schedules execution after hydration.
167
+ - `hydrationScheduler` can be provided on a subscriber or through `createPlugin()` options to override execution timing when needed.
168
+
169
+ ### SSR / Nuxt best practices
170
+
171
+ `pinia-plugin-subscription` is SSR-safe by design, but the runtime policy still needs to match the actual app lifecycle.
172
+
66
173
  For helper-only imports, the package exposes an additive subpath kept separate from the default library API:
67
174
 
68
175
  ```ts
@@ -77,10 +184,188 @@ import type { PluginSubscriptionOptions } from 'pinia-plugin-subscription/types'
77
184
 
78
185
  ## Development
79
186
 
80
- - `npm run dev` — runs the dedicated demo app. The library build remains `npm run build` and is intentionally kept separate from the demo entry. The demo ships a complete plugin-authoring example in [`src/demo/extending-pinia-store/`](src/demo/extending-pinia-store/).
187
+ This example shows the recommended pattern for SSR / Nuxt-safe plugins:
188
+
189
+ - `execution.environment` restricts the subscriber to `'both'`, `'client'`, or `'server'`
190
+ - `execution.hydration` is `'immediate'` by default and can be set to `'defer'` when the plugin must wait for client hydration
191
+ - `hydrationScheduler` lets you override the runtime scheduling behavior, for example with Nuxt/Vue `nextTick()`
192
+ - `hydrate()` / `afterHydration()` are optional lifecycle hooks for browser-only initialization and post-hydration work; they help keep SSR-sensitive logic out of constructors
193
+
194
+ ## The `Store` Class — Summary
195
+
196
+ The `Store` class (see [src/core/Store.ts](src/core/Store.ts)) is a wrapper around a `PiniaStore` providing:
197
+
198
+ - **Properties:** `options`, `state`, `store`.
199
+ - **Useful methods:**
200
+ - `addToState(name, value?)` — adds a property to store state and exposes it as a `Ref` when appropriate.
201
+ - `addSubscription(pluginName, subscription)` — registers a plugin-specific subscription function.
202
+ - `getSubscriptions()` — returns registered subscriptions.
203
+ - `storeSubscribe` (getter/setter) — factory for `store.$subscribe` ({ store, callback }).
204
+ - `onAction` (getter/setter) — factory for `onAction` ({ store, callback }).
205
+ - `static customizeStore(store, options)` — recommended factory for class instantiation.
206
+ - `trace(label, payload?, scope?, namespace?)` — emits a structured trace event, scoped to the store by default.
207
+ - `traceError(label, error, payload?, scope?, namespace?)` — emits an error event, or reports it with `console.error` when no listener matches.
208
+ - Helpers: `stateHas()`, `storeHas()`, `getValue()`.
209
+
210
+ ## Tracing
211
+
212
+ Tracing is **opt-in**, scoped to an explicit registry, and **allocation free when unused**. Create one registry per application or Pinia instance, then pass its `createTracer` factory to `createPlugin()` so plugin and store events share its listeners. For SSR, create a fresh registry, Pinia instance, and plugin instance for every request; do not keep them in module-level state or clear a shared registry at request completion, since requests may overlap. See the [SSR guide](./docs/using-plugins.md#ssr--nuxt) for an example.
213
+
214
+ ### Production safety
215
+
216
+ Tracing is **not automatically blocked in production**. Leave normal tracing disabled by default using your application's environment configuration; enable production diagnostics only deliberately and with limited scope and duration.
217
+
218
+ Events are **not automatically redacted** and may include sensitive action arguments, store state, plugin options, or error details. Filters select events by metadata; they do not sanitize payloads. Before writing to a console or forwarding to a logging service, select an allowlist of fields and redact sensitive values rather than sending complete events.
219
+
220
+ **Disabling normal tracing does not disable error reporting.** Errors can still be sent to `console.error` without a tracer or when no listener matches. See [Error reporting](#error-reporting) and the [security guidance](./SECURITY.md#tracing-and-production-logging) for precautions, including log access and retention.
221
+
222
+ ### Consuming events
223
+
224
+ ```ts
225
+ import { createPlugin } from 'pinia-plugin-subscription'
226
+ import { createTracerRegistry } from 'pinia-plugin-subscription/helpers'
227
+
228
+ const traceRegistry = createTracerRegistry()
229
+ const remove = traceRegistry.addTraceListener({
230
+ filter: (event) => event.scope === 'cart'
231
+ && event.namespace.startsWith('pluginsubscription:subscription:'),
232
+ handler: (event) => console.log(event.namespace, event.scope, event.payload)
233
+ })
234
+
235
+ pinia.use(createPlugin(subscribers, {
236
+ createTracer: traceRegistry.createTracer
237
+ }))
238
+
239
+ remove() // unsubscribe
240
+ ```
241
+
242
+ `filter` is evaluated against event metadata before the payload is resolved,
243
+ so you can narrow tracing to a single store without building discarded
244
+ payloads. Registries do not share listeners with one another.
245
+
246
+ For simple metadata filters, provide comparison criteria instead of a
247
+ callback. Supported comparators are `equals` (the default), `contains`,
248
+ `startsWith` and `endsWith`; multiple criteria use `every` by default or
249
+ `some` when requested:
250
+
251
+ ```ts
252
+ traceRegistry.addTraceListener({
253
+ filter: [
254
+ { target: 'scope', value: 'cart' },
255
+ { target: 'namespace', comparator: 'startsWith', value: 'pluginsubscription:subscription:' }
256
+ ]
257
+ }, 'every')
258
+ ```
259
+
260
+ When no `handler` is provided for criteria-based registration, the registry
261
+ uses its styled console listener.
262
+
263
+ ### Event shape
264
+
265
+ | Field | Description |
266
+ | --- | --- |
267
+ | `namespace` | Structured identifier, derived from the label by default |
268
+ | `label` | Human-readable event label |
269
+ | `source` | Source passed to `createTracer`, usually `pinia-plugin-subscription` |
270
+ | `scope` | Instance identifier, usually `store.$id` |
271
+ | `payload` | Event data, resolved only when consumed |
272
+ | `level` | `debug` or `error` |
273
+ | `timestamp` | `Date.now()` at emission |
274
+ | `error` | Present on `error` events |
275
+
276
+ By default, `Store` prefixes its class name to labels and derived namespaces.
277
+ Library events use `PluginSubscription` as their prefix (for example,
278
+ `pluginsubscription:store:mutation` and
279
+ `pluginsubscription:subscription:delivery`). Set
280
+ `classNameAddedToTraceNamespace = false` on a `Store` subclass to omit its
281
+ class prefix, or provide an explicit namespace as the fourth argument to
282
+ `trace()` / `traceError()`.
283
+
284
+ ### Emitting your own events
285
+
286
+ ```ts
287
+ class CartStore extends Store {
288
+ hydrate() {
289
+ this.trace('cart:hydrate', () => ({ items: this.state.items }))
290
+ }
291
+ }
292
+ ```
293
+
294
+ `Store.trace(label, payload?, scope?, namespace?)` and
295
+ `Store.traceError(label, error, payload?, scope?, namespace?)` emit the events.
296
+ The store class name is included in the label by default; set
297
+ `classNameAddedToTraceNamespace = false` to omit it. Unless an explicit
298
+ namespace is provided, the normalized label is used as the namespace.
299
+
300
+ Always prefer the **function form** for `payload`: it is only invoked once a
301
+ listener matches, so unobserved tracing costs nothing.
302
+
303
+ ### Console listener
304
+
305
+ Normal trace events do not write to a console. Console output for those events is an opt-in listener:
306
+
307
+ ```ts
308
+ import {
309
+ createConsoleTraceListener,
310
+ createTracerRegistry
311
+ } from 'pinia-plugin-subscription/helpers'
312
+
313
+ const traceRegistry = createTracerRegistry()
314
+ const remove = traceRegistry.addTraceListener({
315
+ ...createConsoleTraceListener(),
316
+ filter: () => true
317
+ })
318
+ ```
319
+
320
+ By default, this listener uses the styled plugin console. Pass any object exposing `log` and `error` to use another target:
321
+
322
+ Any object exposing `log` and `error` satisfies the `Console` interface, so external logging libraries can be connected without this plugin depending on them:
323
+
324
+ ```ts
325
+ const remove = traceRegistry.addTraceListener({
326
+ ...createConsoleTraceListener(myLogger),
327
+ filter: () => true
328
+ })
329
+ ```
330
+
331
+ ### Error reporting
332
+
333
+ An error is delivered to every matching listener. If no listener matches — including when listeners exist but all filters reject the event — it is reported with `console.error`; it is not rethrown. Errors thrown by filters or handlers are also reported and isolated so they do not interrupt the traced process or remaining listeners.
334
+
335
+ ### Migrating from `debugLog()` / `logError()`
336
+
337
+ These methods were removed in favour of structured events:
338
+
339
+ ```ts
340
+ // before
341
+ this.debugLog(`$subscribe ${store.$id}`, { mutation, store })
342
+ this.logError('subscriptionDelivery()', error, store, options)
343
+
344
+ // after
345
+ this.trace('store:mutation', () => ({ mutation, store }))
346
+ this.traceError('subscription:delivery', error, () => ({ store, options }))
347
+ ```
348
+
349
+ The `namespace` replaces the formatted message, store trace events are scoped to `store.$id`, and the payload becomes a factory so it is only built when a listener consumes the event.
350
+
351
+ ## Testing
352
+
353
+ - `npm run dev` — runs the dedicated demo app in [`demo/`](demo/). The library build remains `npm run build` and is intentionally kept separate from the demo entry.
81
354
  - `npm test` — runs the Vitest suite, including typecheck tests (`*.test-d.ts`) validating type-level contracts such as `StoreOptionsExtensions` merging. Coverage reports are available in `coverage/`.
82
355
  - `npm run bundle:check` — measures the emitted bundle size.
83
356
 
357
+ ### Dependency leak guard
358
+
359
+ Published artifacts must only reference **peer dependencies** (`pinia`, `vue`) and Node builtins. A `devDependency` referenced from `src/` does not fail the local build, but it breaks consumers: Vite inlines runtime imports, while `tsc` keeps bare `import type` specifiers in the emitted `.d.ts`, which consumers cannot resolve.
360
+
361
+ `npm run check:leaks` scans every built `.js` and `.d.ts` file and fails the build when a non-peer package appears:
362
+
363
+ ```bash
364
+ npm run check:leaks
365
+ ```
366
+
367
+ It runs automatically as part of `npm run build` and in CI. If it reports a leak, either remove the import from `src/`, or duplicate the required type into `src/types/`.
368
+
84
369
  ## License
85
370
 
86
371
  MIT
package/SECURITY.md CHANGED
@@ -35,7 +35,25 @@ When using pinia-plugin-subscription:
35
35
  1. **Keep Dependencies Updated:** Regularly update Pinia, Vue, and other dependencies to the latest versions
36
36
  2. **Review Plugin Code:** Always review subscriber code before using in production
37
37
  3. **Validate Store Data:** Validate data before storing in Pinia stores
38
- 4. **Debug Mode:** Disable debug mode in production (set `false` when calling `createPlugin`)
38
+
39
+ ### Tracing and Production Logging
40
+
41
+ Normal trace events are opt-in: the plugin requires an explicitly configured `createTracer` factory and matching listeners to deliver them. The plugin does not automatically detect production environments or block tracing in production. Production tracing can be useful for incident diagnosis, but should only be enabled deliberately and with controlled access to its output.
42
+
43
+ Trace events are not automatically sanitized or redacted. Depending on the event, they may contain action arguments, store state, mutations, plugin options, subscriptions, or error details. These values can include application secrets or personal data. A listener can expose them through the browser console, server logs, or an external logging service. The absence of a production block is not, by itself, a vulnerability; the disclosure risk depends on the data emitted, the logging destination, and who can access it.
44
+
45
+ When configuring tracing:
46
+
47
+ 1. **Disable Normal Tracing in Production by Default:** Use the application's environment configuration to omit `createTracer` or avoid registering normal trace listeners. Enable production diagnostics only when needed and limit their duration and scope.
48
+ 2. **Minimize Logged Data:** Select an explicit allowlist of fields and redact sensitive values before writing or forwarding events. Avoid logging complete stores, action arguments, plugin options, or raw error objects.
49
+ 3. **Do Not Treat Filters as Redaction:** Filters only select events using metadata; a matching handler receives the full event, including its resolved payload and error. Sanitize data in the handler before passing it to a logging destination.
50
+ 4. **Protect Logging Destinations:** Review external logging services, restrict access to logs, and define appropriate retention periods. Do not assume browser console output or server logs are private.
51
+
52
+ **Error reporting is separate from normal tracing.** Without a tracer, plugin and store error reporting falls back to `console.error`. With a tracer, error events also fall back to `console.error` when no listener matches, including when all filters reject the event. Exceptions thrown by listener filters or handlers are reported to `console.error` as well. Removing listeners, clearing a registry, or omitting `createTracer` therefore does not guarantee that no errors will be logged.
53
+
54
+ For production, handle error events with a matching listener that reports only sanitized details, and ensure listener filters and handlers do not throw sensitive errors. Review the application's console and error logging policy as well; do not silently discard operational errors to prevent disclosure.
55
+
56
+ See [Tracing](./README.md#tracing) for configuration and event details.
39
57
 
40
58
  ## Dependencies Security
41
59
 
@@ -0,0 +1,257 @@
1
+ var S = Object.defineProperty;
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);
4
+ import { isRef as g, ref as b, toRef as l } from "vue";
5
+ import { defineStore as p } from "pinia";
6
+ class L {
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");
19
+ this._name = t, this._createInstance = r;
20
+ }
21
+ get name() {
22
+ return this._name;
23
+ }
24
+ get storeInstance() {
25
+ return this._storeInstance;
26
+ }
27
+ get pluginOptions() {
28
+ return this._pluginOptions;
29
+ }
30
+ set pluginOptions(t) {
31
+ this._pluginOptions = t;
32
+ }
33
+ get resetStoreCallback() {
34
+ return this._resetStoreCallback;
35
+ }
36
+ get storeOnActionSubscription() {
37
+ return this._storeOnActionSubscription;
38
+ }
39
+ get storeMutationSubscription() {
40
+ return this._storeMutationSubscription;
41
+ }
42
+ get subscriptions() {
43
+ return this._subscriptions;
44
+ }
45
+ set subscriptions(t) {
46
+ this._subscriptions = t;
47
+ }
48
+ afterHydration(t) {
49
+ }
50
+ hydrate(t) {
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;
54
+ }
55
+ }
56
+ const u = /* @__PURE__ */ new WeakMap(), a = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new WeakSet();
57
+ function O(e, t) {
58
+ if (h.has(e) || typeof e.$dispose != "function")
59
+ return;
60
+ const r = e.$dispose;
61
+ e.$dispose = (...n) => (u.delete(e), a.delete(t), r.apply(e, n)), h.add(e);
62
+ }
63
+ function q(e, t, r) {
64
+ const n = r ? { storeOptions: r } : {};
65
+ return typeof t == "function" ? d(
66
+ e,
67
+ t,
68
+ n
69
+ ) : y(
70
+ e,
71
+ t,
72
+ n
73
+ );
74
+ }
75
+ function F(e, t, r) {
76
+ const n = r ? { storeOptions: { ...r, enhancedStore: !0 } } : { storeOptions: { enhancedStore: !0 } };
77
+ return d(
78
+ e,
79
+ t,
80
+ n
81
+ );
82
+ }
83
+ function d(e, t, r) {
84
+ const n = {
85
+ id: e,
86
+ extensions: {}
87
+ }, i = r?.storeOptions?.enhancedStore === !0, o = p(
88
+ e,
89
+ () => t(n),
90
+ r
91
+ );
92
+ return Object.assign(((..._) => {
93
+ i && a.set(e, n);
94
+ const c = o(..._);
95
+ return i && (u.set(c, n), a.delete(e), O(c, e)), c;
96
+ }), o);
97
+ }
98
+ function y(e, t, r) {
99
+ return r && (t = { ...t, ...r ?? {} }), p(e, t);
100
+ }
101
+ const A = /* @__PURE__ */ new Set(["_", "$"]);
102
+ function m(e) {
103
+ return A.has(e[0]);
104
+ }
105
+ function C(e) {
106
+ const t = e;
107
+ return u.get(e) ?? (typeof t?.$id == "string" ? a.get(t.$id) : void 0);
108
+ }
109
+ function x(e) {
110
+ const t = e.extensions.enhancedStore ?? e.extensions.extending;
111
+ if (!t)
112
+ throw new Error(`${e.id}Store - getEnhancedStore - Error: enhanced store is required`);
113
+ return t;
114
+ }
115
+ function T(e, t) {
116
+ e.extensions.enhancedStore = t, e.extensions.extending = t;
117
+ }
118
+ function K(e) {
119
+ return console.warn(`${e.id}Store - getExtendingStore is deprecated. Use getEnhancedStore instead.`), x(e);
120
+ }
121
+ function M(e, t) {
122
+ return `${e}-${t.$id}`;
123
+ }
124
+ function $(e) {
125
+ 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
+ }
127
+ const I = "pinia-plugin-subscription";
128
+ class w {
129
+ 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", {
138
+ addClassNameToLabel: !0
139
+ });
140
+ s(this, "_tracer");
141
+ 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);
144
+ }
145
+ }
146
+ get classNameAddedToTraceNamespace() {
147
+ return this._traceOptions.addClassNameToLabel;
148
+ }
149
+ set classNameAddedToTraceNamespace(t) {
150
+ this._traceOptions.addClassNameToLabel = t;
151
+ }
152
+ get onAction() {
153
+ if (this._onAction)
154
+ return () => ({
155
+ store: this.store,
156
+ callback: this._onAction
157
+ });
158
+ }
159
+ set onAction(t) {
160
+ this._onAction = t;
161
+ }
162
+ get options() {
163
+ return this._options;
164
+ }
165
+ get state() {
166
+ return this._store.$state;
167
+ }
168
+ set state(t) {
169
+ this._store.$state = t;
170
+ }
171
+ get store() {
172
+ return this._store;
173
+ }
174
+ get storeSubscribe() {
175
+ if (this._storeSubscribe)
176
+ return () => ({
177
+ store: this.store,
178
+ callback: this._storeSubscribe
179
+ });
180
+ }
181
+ set storeSubscribe(t) {
182
+ this._storeSubscribe = t;
183
+ }
184
+ get tracer() {
185
+ return !this._tracer && this._createTracer && (this._tracer = this._createTracer(I), this._tracer.scope = this.store.$id), this._tracer;
186
+ }
187
+ addToState(t, r) {
188
+ this.isOptionApi() || g(r) || (r = b(r)), this.state[t] = r, this.store[t] = l(this.state, t);
189
+ }
190
+ addSubscription(t, r, n) {
191
+ this._subscriptions[t] = { subscription: r, ...n ?? {} };
192
+ }
193
+ afterHydration() {
194
+ }
195
+ static customizeStore(t, r) {
196
+ if (r.storeOptions && this.hasRequiredKeys(r.storeOptions))
197
+ return new this(t, r);
198
+ }
199
+ getOption(t) {
200
+ return this.options && this.options[t];
201
+ }
202
+ getStatePropertyValue(t) {
203
+ return this.getValue(this.state[t]);
204
+ }
205
+ getSubscriptions() {
206
+ if (!$(this._subscriptions))
207
+ return this._subscriptions;
208
+ }
209
+ getValue(t) {
210
+ return t?.__v_isRef ? t.value : t;
211
+ }
212
+ hasDeniedFirstChar(t) {
213
+ return m(t);
214
+ }
215
+ static hasRequiredKeys(t) {
216
+ return this._requiredKeys !== void 0 && this._requiredKeys?.every((r) => !!t[r]);
217
+ }
218
+ hydrate() {
219
+ }
220
+ initializeTracer(t) {
221
+ this._createTracer = t?.createTracer;
222
+ }
223
+ isOptionApi() {
224
+ return this.store._isOptionsAPI;
225
+ }
226
+ stateHas(t) {
227
+ return Object.prototype.hasOwnProperty.call(this.state, t);
228
+ }
229
+ storeHas(t) {
230
+ return Object.prototype.hasOwnProperty.call(this.store, t);
231
+ }
232
+ trace(t, r, n, i) {
233
+ this.tracer && (t = this.traceLabelFormatter(t), this.tracer.debug(t, i ?? t.toLowerCase(), r, n));
234
+ }
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);
237
+ }
238
+ traceLabelFormatter(t) {
239
+ return this.classNameAddedToTraceNamespace && (t = `${this.constructor.name}:${t}`), t;
240
+ }
241
+ }
242
+ s(w, "_requiredKeys");
243
+ export {
244
+ L as P,
245
+ w as S,
246
+ F as a,
247
+ C as b,
248
+ x as c,
249
+ q as d,
250
+ K as e,
251
+ M as g,
252
+ m as h,
253
+ $ as i,
254
+ I as p,
255
+ T as s
256
+ };
257
+ //# sourceMappingURL=Store-DHUAJv-P.js.map