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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/CHANGELOG.md +73 -12
  2. package/CONTRIBUTING.md +10 -1
  3. package/README.md +48 -293
  4. package/SECURITY.md +6 -6
  5. package/dist/chunks/setup-context-3G3Hy1ep.js +909 -0
  6. package/dist/dictionaries/plugin-subscription-event.d.ts +20 -0
  7. package/dist/{core/Store.d.ts → enhanced-store/EnhancedStore.d.ts} +24 -29
  8. package/dist/enhanced-store/define-a-store.d.ts +64 -0
  9. package/dist/enhanced-store/setup-context.d.ts +27 -0
  10. package/dist/events/EventsEmitter.d.ts +9 -0
  11. package/dist/events/EventsSubscriber.d.ts +32 -0
  12. package/dist/events/EventsSubscription.d.ts +13 -0
  13. package/dist/events/StoreEvent.d.ts +6 -0
  14. package/dist/events/StoresEventsSubscriptionsRegistry.d.ts +31 -0
  15. package/dist/events/event.d.ts +8 -0
  16. package/dist/factories/events-registry.d.ts +9 -0
  17. package/dist/factories/events-subscriber.d.ts +11 -0
  18. package/dist/factories/messenger-registry.d.ts +16 -0
  19. package/dist/factories/plugin-subscriber.d.ts +17 -0
  20. package/dist/helpers.js +204 -312
  21. package/dist/lib/helpers.d.ts +9 -0
  22. package/dist/lib/main.d.ts +3 -12
  23. package/dist/orchestration/ExecutionPolicy.d.ts +15 -0
  24. package/dist/orchestration/PluginOrchestrator.d.ts +41 -0
  25. package/dist/orchestration/SubscriberScheduler.d.ts +31 -0
  26. package/dist/pinia-plugin-subscription.js +31 -426
  27. package/dist/plugins/createPlugin.d.ts +3 -13
  28. package/dist/services/messenger.d.ts +28 -0
  29. package/dist/services/messengerProvider.d.ts +45 -0
  30. package/dist/store-hooks/StoreHooksBinder.d.ts +20 -0
  31. package/dist/store-hooks/StoreHooksRegistry.d.ts +34 -0
  32. package/dist/{core/PluginSubscriber.d.ts → subscribers/StoreSubscriber.d.ts} +39 -28
  33. package/dist/tracing/TraceGroupHelper.d.ts +27 -0
  34. package/dist/tracing/TraceableEmitter.d.ts +60 -0
  35. package/dist/tracing/TraceableEventsSubscriber.d.ts +21 -0
  36. package/dist/tracing/TraceableStoreEventsSubscriber.d.ts +16 -0
  37. package/dist/tracing/trace-groups.d.ts +9 -0
  38. package/dist/types/core.d.ts +12 -0
  39. package/dist/types/events.d.ts +24 -0
  40. package/dist/types/index.d.ts +8 -34
  41. package/dist/types/messenger.d.ts +20 -0
  42. package/dist/types/plugin.d.ts +39 -20
  43. package/dist/types/store.d.ts +1 -9
  44. package/dist/types/trace.d.ts +35 -75
  45. package/dist/utils/constants.d.ts +4 -0
  46. package/dist/utils/events.d.ts +3 -0
  47. package/dist/utils/id.d.ts +20 -0
  48. package/dist/utils/store.d.ts +9 -93
  49. package/docs/authoring-plugins.md +330 -78
  50. package/docs/using-plugins.md +89 -53
  51. package/package.json +14 -8
  52. package/dist/chunks/constantes-CaTNAbzX.js +0 -261
  53. package/dist/chunks/constantes-CaTNAbzX.js.map +0 -1
  54. package/dist/core/PluginSubscription.d.ts +0 -92
  55. package/dist/core/RollbackStateSnapshotsHandler.d.ts +0 -65
  56. package/dist/factories/console-trace-listener.d.ts +0 -7
  57. package/dist/factories/state-snapshot.d.ts +0 -3
  58. package/dist/factories/trace-listener.d.ts +0 -16
  59. package/dist/factories/trace-registry.d.ts +0 -17
  60. package/dist/helpers/index.d.ts +0 -9
  61. package/dist/helpers.js.map +0 -1
  62. package/dist/pinia-plugin-subscription.js.map +0 -1
  63. package/dist/plugins/createHydrationPlugin.d.ts +0 -10
  64. package/dist/system/Tracer.d.ts +0 -20
  65. package/dist/system/log.d.ts +0 -35
  66. package/dist/tests/defineAStore.test-d.d.ts +0 -1
  67. package/dist/tests/storeOptionsExtensions.test-d.d.ts +0 -12
  68. package/dist/types/comparison.d.ts +0 -3
  69. package/dist/types/list.d.ts +0 -13
  70. package/dist/types/log.d.ts +0 -8
  71. package/dist/types/resourceId.d.ts +0 -4
  72. package/dist/utils/Performance.d.ts +0 -9
  73. package/dist/utils/constantes.d.ts +0 -1
  74. package/dist/utils/deep-clone.d.ts +0 -7
  75. package/dist/utils/defineStoreId.d.ts +0 -1
  76. package/dist/utils/object.d.ts +0 -4
  77. package/dist/utils/validation/object.d.ts +0 -9
@@ -13,22 +13,22 @@ the [plugin authoring guide](authoring-plugins.md) instead.
13
13
  > annotations and generics. Types are always optional at runtime — they only
14
14
  > add autocompletion and compile-time checks.
15
15
 
16
- ## What every compatible plugin guarantees
16
+ ## What compatible plugins can use
17
17
 
18
- Plugins built on `pinia-plugin-subscription` share a common contract:
18
+ Plugins built on `pinia-plugin-subscription` use the shared subscriber
19
+ registration and execution infrastructure:
19
20
 
20
21
  - **Single registration point** — all subscribers are registered through one
21
22
  `createPlugin()` call.
22
- - **`$reset` on registered stores** — every store registered by the plugin
23
- gains a `$reset()` method that restores its initial state, including
24
- setup-style stores where pinia does not provide one natively.
25
- - **Runtime-filtered tracing** — register trace listeners and filter events by
26
- source, namespace, scope, or level.
27
- - **SSR-safe execution** — each plugin declares where (`client`, `server`
28
- or `both`) and when (`immediate` or deferred after hydration) it runs.
29
- - **State rollback on action failure** — actions listed in the
30
- `rollbackAfterFailure` store option automatically restore their state
31
- snapshot when they throw.
23
+ - **Configurable execution** — subscribers can declare their runtime
24
+ environment (`client`, `server` or `both`) and whether they run immediately
25
+ or after client hydration.
26
+ - **Optional tracing** — the core emits structured events when a
27
+ `tracerHandler` is configured; a compatible tracing plugin can consume them.
28
+ - **Optional reset and rollback** — `pinia-plugin-state-snapshots` can add
29
+ `$reset` to setup-style stores and restore configured state when an action
30
+ fails. Reset wrapping is opt-in; it is not provided automatically to every
31
+ store or by every compatible plugin.
32
32
 
33
33
  ## Installation
34
34
 
@@ -66,9 +66,9 @@ requires no generics:
66
66
 
67
67
  ```ts
68
68
  import { createPlugin } from 'pinia-plugin-subscription'
69
- import type { PluginSubscriberInterface } from 'pinia-plugin-subscription'
69
+ import type { StoreSubscriberInterface } from 'pinia-plugin-subscription/types'
70
70
 
71
- const subscribers: PluginSubscriberInterface[] = [myStoreSubscriber]
71
+ const subscribers: StoreSubscriberInterface[] = [myStoreSubscriber]
72
72
 
73
73
  pinia.use(createPlugin(subscribers))
74
74
  ```
@@ -90,7 +90,7 @@ defineAStore<Sto, Sta>(id, storeDefinition, options?) // explicit typings
90
90
  | --- | --- | --- |
91
91
  | `id` | `string` | Unique store identifier — same as pinia's `defineStore()`. |
92
92
  | `storeDefinition` | options object \| setup function | Same shape as pinia's `defineStore()`: an options object (`state`, `getters`, `actions`) or a setup function returning state and actions. |
93
- | `options` | `StoreOptions` (optional) | Per-store plugin options: the built-in `rollbackAfterFailure` key, plus any key contributed by installed plugins through `StoreOptionsExtensions`. |
93
+ | `options` | `StoreOptions` (optional) | Per-store options contributed by installed plugins through `StoreOptionsExtensions`. |
94
94
 
95
95
  ### Type parameters (TypeScript only)
96
96
 
@@ -121,6 +121,7 @@ returned object):
121
121
  ```js
122
122
  import { ref } from 'vue'
123
123
  import { defineAStore } from 'pinia-plugin-subscription'
124
+ import 'pinia-plugin-state-snapshots'
124
125
 
125
126
  export const useCounterStore = defineAStore('counter', () => {
126
127
  const count = ref(0)
@@ -229,14 +230,27 @@ export const useMyStore = defineAStoreCtx('myStore', (ctx) => {
229
230
  })
230
231
  ```
231
232
 
233
+ Without explicit generics, the enhanced-store properties are `unknown`, since
234
+ the type added by a plugin cannot be inferred from this store's setup return.
235
+ Pass the enhanced-store type through `<Sto, Sta>` (with the behavior and state
236
+ interfaces) when it is known, or use `getEnhancedStore<YourEnhancedStore>(ctx)`.
237
+ Provide `TExtraExtensions` as a third generic when adding custom extension keys.
238
+
232
239
  `defineAStoreCtx()` enables the `enhancedStore` store option automatically.
233
240
  The internal setup-context lookup is cleaned up as soon as the store is
234
241
  associated (and on store dispose), which limits map growth over time.
235
242
 
243
+ > The enhanced store is attached once plugins have run, after the setup
244
+ > function returns: call getEnhancedStore() lazily (inside actions), not
245
+ > during setup. See [`demo/stores/enhanced-store.ts`](../demo/stores/enhanced-store.ts).
246
+
236
247
  ## `$reset` on registered stores
237
248
 
238
- Every store registered by the plugin exposes `$reset()`, which restores the
239
- initial state captured at registration — including for setup-style stores:
249
+ Register `StateSnapshotsSubscriber` and enable its `overrideReset` option to
250
+ add `$reset()` to a store. The wrapper restores a fresh copy of the initial
251
+ state captured at registration, including for setup-style stores. Enable it
252
+ globally on the subscriber or per store (see the
253
+ [state-snapshots documentation](../packages/state-snapshots/README.md)):
240
254
 
241
255
  ```js
242
256
  const store = useCounterStore()
@@ -244,18 +258,24 @@ store.increment()
244
258
  store.$reset() // state is back to its initial value
245
259
  ```
246
260
 
247
- Each compatible plugin may also run custom logic on reset — see the plugin's
248
- own documentation.
261
+ When the wrapper is installed, callbacks registered with `$onResetStore()`
262
+ run after the state is restored. A store option `onReset` also runs after
263
+ restoration. When `rollbackAfterFailure` enables the subscriber for a store,
264
+ an `onReset` callback enables the reset wrapper even without `overrideReset`.
265
+ `onReset` alone does not activate the subscriber.
249
266
 
250
267
  ## State rollback on action failure
251
268
 
252
- The plugin can automatically restore the previous state when an action
269
+ Install `pinia-plugin-state-snapshots` and register `StateSnapshotsSubscriber`
270
+ with `createPlugin` (see its [README](../packages/state-snapshots/README.md)).
271
+ The subscriber can automatically restore the previous state when an action
253
272
  throws. Declare the state keys to snapshot per action via the
254
273
  `rollbackAfterFailure` store option:
255
274
 
256
275
  ```js
257
276
  import { ref } from 'vue'
258
277
  import { defineAStore } from 'pinia-plugin-subscription'
278
+ import 'pinia-plugin-state-snapshots'
259
279
 
260
280
  export const useMyStore = defineAStore('myStore', () => {
261
281
  const count = ref(0)
@@ -276,8 +296,13 @@ export const useMyStore = defineAStore('myStore', () => {
276
296
 
277
297
  Before a configured action runs, the declared state keys are snapshotted.
278
298
  If the action throws (synchronously or by rejecting its returned promise),
279
- the snapshot is restored through `$patch`, so partial mutations are rolled
280
- back. The snapshot is always discarded once the action completes or fails.
299
+ the snapshot is restored through a `$patch` mutation. The snapshot is always
300
+ discarded once the action completes or fails. Supported values, error handling,
301
+ and identity limitations are documented in the package README.
302
+ If snapshot creation fails, the error is logged and the action still runs
303
+ without that rollback snapshot. If automatic restoration fails, the failure
304
+ and original action error are logged together, and the original action error
305
+ is propagated; the state may be partially restored.
281
306
 
282
307
  Only the actions listed in `rollbackAfterFailure` are snapshotted, so
283
308
  unrelated actions pay no cloning cost. Use `'all'` or `[]` instead of a key list to
@@ -288,9 +313,11 @@ methods.
288
313
 
289
314
  ### Manual rollback with `$rollbackAfterFailure`
290
315
 
291
- Every store registered by the plugin also exposes a `$rollbackAfterFailure`
292
- method to run any action with an explicit snapshot/rollback wrapper, without
293
- declaring it in the store options:
316
+ Stores with `overrideReset` or `rollbackAfterFailure` enabled expose a
317
+ `$rollbackAfterFailure` method to run an action with an explicit snapshot.
318
+ Use `rollbackAfterFailure: true` to enable manual rollback without configuring
319
+ automatic snapshots. The global type augmentation does not guarantee that the
320
+ method is installed on stores without these options:
294
321
 
295
322
  ```js
296
323
  const store = useMyStore()
@@ -311,47 +338,54 @@ try {
311
338
  for automatic rollback configured in store options.
312
339
  - `args` — optional; the action arguments, provided as a single array
313
340
  (forwarded to the action via `apply()`).
314
- - The original error is rethrown after the state is restored.
341
+ - The original error is rethrown after the state is restored; if restoring fails,
342
+ an `AggregateError` contains both errors.
315
343
 
316
344
  ## Tracing
317
345
 
346
+ Tracing is provided by the separate `pinia-plugin-subscription-devtools`
347
+ package (`npm install -D pinia-plugin-subscription-devtools`); the plugin
348
+ emits nothing without it. See its
349
+ [Tracing documentation](../packages/devtools/docs/tracing.md) for the full
350
+ guide. Tracing is disabled by default in production builds and can mask
351
+ sensitive payload keys with `createTracerRegistry({ redact: true })`.
352
+
318
353
  Register listeners independently from plugin construction:
319
354
 
320
355
  ```js
321
356
  import {
322
- createConsoleTraceListener,
323
357
  createTracerRegistry
324
- } from 'pinia-plugin-subscription/helpers'
358
+ } from 'pinia-plugin-subscription-devtools'
325
359
  import {
326
360
  createPlugin
327
361
  } from 'pinia-plugin-subscription'
328
362
 
329
- const traceRegistry = createTracerRegistry()
363
+ const traceGroupsRegistry = createTracerRegistry()
330
364
 
331
- traceRegistry.addTraceListener({
332
- ...createConsoleTraceListener(),
333
- filter: event => event.scope === 'cart'
365
+ traceGroupsRegistry.addListener({
366
+ filter: [{ target: 'scope', value: 'cart' }],
367
+ handler: event => myLogger.debug(event)
334
368
  })
335
369
 
336
370
  pinia.use(createPlugin([myStoreSubscriber], {
337
- createTracer: traceRegistry.createTracer
371
+ tracerHandler: traceGroupsRegistry.tracerHandler
338
372
  }))
339
373
  ```
340
374
 
341
- Filters run in real time and can target a source, namespace, store scope, or
342
- trace level without passing diagnostic options through subscribers.
343
- You can also use comparison criteria (`equals`, `contains`, `startsWith` or
344
- `endsWith`) instead of a filter callback; criteria are combined with `every`
345
- by default or `some` when requested. If criteria are provided without a
346
- handler, the registry uses its styled console listener.
375
+ Criteria can target a source, namespace, store scope, or trace level and
376
+ support the `equals`, `contains`, `startsWith` and `endsWith` comparators.
377
+ Criteria use `every` by default; pass `{ filterMode: 'some' }` to match any
378
+ criterion. The `handler` receives every matching event; nothing is printed
379
+ to the console by the package.
347
380
 
348
381
  ```js
349
- traceRegistry.addTraceListener({
382
+ traceGroupsRegistry.addListener({
350
383
  filter: [
351
384
  { target: 'scope', value: 'cart' },
352
- { target: 'namespace', comparator: 'startsWith', value: 'pluginsubscription:subscription:' }
353
- ]
354
- }, 'every')
385
+ { target: 'namespace', comparator: 'startsWith', value: 'pluginorchestrator:subscription:' }
386
+ ],
387
+ handler: event => myLogger.debug(event)
388
+ }, { filterMode: 'every' })
355
389
  ```
356
390
 
357
391
  ## SSR / Nuxt
@@ -371,18 +405,18 @@ finishes.
371
405
  import { createSSRApp } from 'vue'
372
406
  import { createPinia } from 'pinia'
373
407
  import { createPlugin } from 'pinia-plugin-subscription'
374
- import { createTracerRegistry } from 'pinia-plugin-subscription/helpers'
408
+ import { createTracerRegistry } from 'pinia-plugin-subscription-devtools'
375
409
  import App from './App.vue'
376
410
  import { subscribers } from './subscribers'
377
411
 
378
- export function createRequestApp(traceListener) {
412
+ export function createRequestApp(traceCriteria) {
379
413
  const app = createSSRApp(App)
380
414
  const pinia = createPinia()
381
- const traceRegistry = createTracerRegistry()
415
+ const traceGroupsRegistry = createTracerRegistry()
382
416
 
383
- traceRegistry.addTraceListener(traceListener)
417
+ traceGroupsRegistry.addListener({ filter: traceCriteria, handler: logTrace })
384
418
  pinia.use(createPlugin(subscribers, {
385
- createTracer: traceRegistry.createTracer
419
+ tracerHandler: traceGroupsRegistry.tracerHandler
386
420
  }))
387
421
  app.use(pinia)
388
422
 
@@ -391,7 +425,7 @@ export function createRequestApp(traceListener) {
391
425
  ```
392
426
 
393
427
  Call `createRequestApp()` once for each incoming SSR request. The request's
394
- listener is then reachable only through that request's registry and plugin.
428
+ trace criteria are then registered only in that request's registry and plugin.
395
429
 
396
430
  When a plugin needs a runtime-specific scheduler or environment override —
397
431
  without forcing every app to re-declare the plugin's execution policy —
@@ -399,17 +433,17 @@ register it through the dedicated hydration helper:
399
433
 
400
434
  ```js
401
435
  import { nextTick } from 'vue'
402
- import { createHydrationPlugin } from 'pinia-plugin-subscription'
436
+ import { createPlugin } from 'pinia-plugin-subscription'
403
437
 
404
- pinia.use(createHydrationPlugin([persistedStateSubscriber], {
438
+ pinia.use(createPlugin([persistedStateSubscriber], {
405
439
  hydrationScheduler: (run) => {
406
440
  nextTick(() => run())
407
441
  }
408
442
  }))
409
443
  ```
410
444
 
411
- `createHydrationPlugin(subscribers, options?)` accepts
412
- `PluginSubscriptionOptions`:
445
+ `createPlugin(subscribers, options?)` accepts
446
+ `PluginOrchestratorOptions`:
413
447
 
414
448
  | Option | Type | Description |
415
449
  | --- | --- | --- |
@@ -430,3 +464,5 @@ Plugins built on `pinia-plugin-subscription`:
430
464
  - `pinia-plugin-persist-state`
431
465
 
432
466
  Check each plugin's own README for its specific store options and behavior.
467
+
468
+ Browse all compatible plugins through the [`pinia-plugin-subscription` GitHub topic](https://github.com/topics/pinia-plugin-subscription), and add the topic to your own plugin's repository (and `pinia-plugin-subscription` to its `keywords`) so users can find it. A runnable example is available in [`demo/`](../demo/README.md).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinia-plugin-subscription",
3
- "version": "1.0.0-beta.2",
3
+ "version": "1.0.0-beta.20",
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,
@@ -20,6 +20,7 @@
20
20
  "plugin",
21
21
  "store",
22
22
  "subscription",
23
+ "pinia-plugin-subscription",
23
24
  "vue3",
24
25
  "state-management",
25
26
  "typescript"
@@ -30,7 +31,7 @@
30
31
  "import": "./dist/pinia-plugin-subscription.js"
31
32
  },
32
33
  "./helpers": {
33
- "types": "./dist/helpers/index.d.ts",
34
+ "types": "./dist/lib/helpers.d.ts",
34
35
  "import": "./dist/helpers.js"
35
36
  },
36
37
  "./types": {
@@ -42,7 +43,7 @@
42
43
  "typesVersions": {
43
44
  "*": {
44
45
  "helpers": [
45
- "./dist/helpers/index.d.ts"
46
+ "./dist/lib/helpers.d.ts"
46
47
  ],
47
48
  "types": [
48
49
  "./dist/types/index.d.ts"
@@ -66,11 +67,13 @@
66
67
  "scripts": {
67
68
  "prebuild": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"",
68
69
  "dev": "vite --config vite.demo.config.ts",
70
+ "dev:ssr": "node scripts/demo-ssr-server.mjs",
69
71
  "dev:library": "vite",
70
72
  "test": "vitest",
71
73
  "coverage": "vitest run --coverage",
72
- "build": "vitest && vite build && tsc --emitDeclarationOnly --outDir dist && npm run check:leaks && node scripts/measure-bundle.mjs",
73
- "check:leaks": "node scripts/check-dist-leaks.mjs",
74
+ "build": "vitest run && npm run build:library && npm run build -w pinia-plugin-subscription-devtools && npm run build -w pinia-plugin-state-snapshots",
75
+ "build:library": "vite build && tsc --emitDeclarationOnly --outDir dist && node scripts/check-dist-leaks.mjs . && node scripts/measure-bundle.mjs",
76
+ "check:leaks": "node scripts/check-dist-leaks.mjs . && node scripts/check-dist-leaks.mjs packages/devtools",
74
77
  "bundle:check": "vite build --config vite.config.ts && node scripts/measure-bundle.mjs",
75
78
  "build:demo": "vite --config vite.demo.config.ts build",
76
79
  "preview": "vite preview --config vite.demo.config.ts"
@@ -92,13 +95,16 @@
92
95
  "@vitejs/plugin-vue": "^6.0.1",
93
96
  "@vitest/coverage-v8": "^4.0.15",
94
97
  "@vue/tsconfig": "^0.8.1",
98
+ "jsdom": "^30.1.3",
95
99
  "pinia": "^3.0.2",
96
- "pinia-plugin-action-flow": "^0.1.1",
97
- "pinia-plugin-extending-store": "^0.1.5-beta.0",
100
+ "pinia-plugin-extending-store": "^0.1.6-beta.2",
98
101
  "typescript": "~5.9.3",
99
102
  "vite": "^7.2.4",
100
103
  "vitest": "^4.0.15",
101
104
  "vue": "^3.5.24",
102
105
  "vue-tsc": "^3.1.4"
103
- }
106
+ },
107
+ "workspaces": [
108
+ "packages/*"
109
+ ]
104
110
  }
@@ -1,261 +0,0 @@
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 n = (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 k {
7
- constructor(t, r) {
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
- 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 }, 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;
58
- }
59
- }
60
- const u = /* @__PURE__ */ new WeakMap(), a = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new WeakSet();
61
- function O(e, t) {
62
- if (h.has(e) || typeof e.$dispose != "function")
63
- return;
64
- const r = e.$dispose;
65
- e.$dispose = (...s) => (u.delete(e), a.delete(t), r.apply(e, s)), h.add(e);
66
- }
67
- function L(e, t, r) {
68
- const s = r ? { storeOptions: r } : {};
69
- return typeof t == "function" ? d(
70
- e,
71
- t,
72
- s
73
- ) : y(
74
- e,
75
- t,
76
- s
77
- );
78
- }
79
- function q(e, t, r) {
80
- const s = r ? { storeOptions: { ...r, enhancedStore: !0 } } : { storeOptions: { enhancedStore: !0 } };
81
- return d(
82
- e,
83
- t,
84
- s
85
- );
86
- }
87
- function d(e, t, r) {
88
- const s = {
89
- id: e,
90
- extensions: {}
91
- }, i = r?.storeOptions?.enhancedStore === !0, o = p(
92
- e,
93
- () => t(s),
94
- r
95
- );
96
- return Object.assign(((..._) => {
97
- i && a.set(e, s);
98
- const c = o(..._);
99
- return i && (u.set(c, s), a.delete(e), O(c, e)), c;
100
- }), o);
101
- }
102
- function y(e, t, r) {
103
- return r && (t = { ...t, ...r ?? {} }), p(e, t);
104
- }
105
- const A = /* @__PURE__ */ new Set(["_", "$"]);
106
- function m(e) {
107
- return A.has(e[0]);
108
- }
109
- function C(e) {
110
- const t = e;
111
- return u.get(e) ?? (typeof t?.$id == "string" ? a.get(t.$id) : void 0);
112
- }
113
- function x(e) {
114
- const t = e.extensions.enhancedStore ?? e.extensions.extending;
115
- if (!t)
116
- throw new Error(`${e.id}Store - getEnhancedStore - Error: enhanced store is required`);
117
- return t;
118
- }
119
- function T(e, t) {
120
- e.extensions.enhancedStore = t, e.extensions.extending = t;
121
- }
122
- function F(e) {
123
- return console.warn(`${e.id}Store - getExtendingStore is deprecated. Use getEnhancedStore instead.`), x(e);
124
- }
125
- function K(e, t) {
126
- return `${e}-${t.$id}`;
127
- }
128
- function $(e) {
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");
130
- }
131
- class I {
132
- constructor(t, r) {
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", {
141
- addClassNameToLabel: !0
142
- });
143
- n(this, "_tracer");
144
- if (this._options = r.storeOptions, this._store = t, this.initializeTracer(r), this._options?.enhancedStore) {
145
- const s = C(this.store);
146
- s && T(s, this.store);
147
- }
148
- }
149
- get classNameAddedToTraceNamespace() {
150
- return this._traceOptions.addClassNameToLabel;
151
- }
152
- set classNameAddedToTraceNamespace(t) {
153
- this._traceOptions.addClassNameToLabel = t;
154
- }
155
- get onAction() {
156
- if (this._onAction)
157
- return () => ({
158
- store: this.store,
159
- callback: this._onAction
160
- });
161
- }
162
- set onAction(t) {
163
- this._onAction = t;
164
- }
165
- get options() {
166
- return this._options;
167
- }
168
- get state() {
169
- return this._store.$state;
170
- }
171
- set state(t) {
172
- this._store.$state = t;
173
- }
174
- get store() {
175
- return this._store;
176
- }
177
- get storeSubscribe() {
178
- if (this._storeSubscribe)
179
- return () => ({
180
- store: this.store,
181
- callback: this._storeSubscribe
182
- });
183
- }
184
- set storeSubscribe(t) {
185
- this._storeSubscribe = t;
186
- }
187
- get tracer() {
188
- return !this._tracer && this._createTracer && (this._tracer = this._createTracer(), this._tracer.scope = this.store.$id), this._tracer;
189
- }
190
- addToState(t, r) {
191
- this.isOptionApi() || g(r) || (r = b(r)), this.state[t] = r, this.store[t] = l(this.state, t);
192
- }
193
- addSubscription(t, r, s) {
194
- this._subscriptions[t] = { subscription: r, ...s ?? {} };
195
- }
196
- afterHydration() {
197
- }
198
- static customizeStore(t, r) {
199
- if (r.storeOptions && this.hasRequiredKeys(r.storeOptions))
200
- return new this(t, r);
201
- }
202
- getOption(t) {
203
- return this.options && this.options[t];
204
- }
205
- getStatePropertyValue(t) {
206
- return this.getValue(this.state[t]);
207
- }
208
- getSubscriptions() {
209
- if (!$(this._subscriptions))
210
- return this._subscriptions;
211
- }
212
- getValue(t) {
213
- return t?.__v_isRef ? t.value : t;
214
- }
215
- hasDeniedFirstChar(t) {
216
- return m(t);
217
- }
218
- static hasRequiredKeys(t) {
219
- return this._requiredKeys !== void 0 && this._requiredKeys?.every((r) => !!t[r]);
220
- }
221
- hydrate() {
222
- }
223
- initializeTracer(t) {
224
- this._createTracer = t?.createTracer;
225
- }
226
- isOptionApi() {
227
- return this.store._isOptionsAPI;
228
- }
229
- stateHas(t) {
230
- return Object.prototype.hasOwnProperty.call(this.state, t);
231
- }
232
- storeHas(t) {
233
- return Object.prototype.hasOwnProperty.call(this.store, t);
234
- }
235
- trace(t, r, s, i) {
236
- this.tracer && (t = this.traceLabelFormatter(t), this.tracer.debug(t, i ?? t.toLowerCase(), r, s));
237
- }
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);
240
- }
241
- traceLabelFormatter(t) {
242
- return this.classNameAddedToTraceNamespace && (t = `${this.constructor.name}:${t}`), t;
243
- }
244
- }
245
- n(I, "_requiredKeys");
246
- const M = "pinia-plugin-subscription";
247
- export {
248
- k as P,
249
- I as S,
250
- q as a,
251
- C as b,
252
- x as c,
253
- L as d,
254
- F as e,
255
- K as g,
256
- m as h,
257
- $ as i,
258
- M as p,
259
- T as s
260
- };
261
- //# sourceMappingURL=constantes-CaTNAbzX.js.map