pinia-plugin-subscription 0.2.0-beta.0 → 0.2.0

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,7 +5,26 @@ 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]
8
+ ## [0.2.0]
9
+
10
+ ### Added
11
+ - Added `StoreOptionsExtensions`, a centralized extension point for per-store plugin options: subscriber plugins can now type their own `storeOptions` keys through interface merging (`declare module 'pinia-plugin-subscription/types'`) instead of redeclaring pinia's `DefineStoreOptionsBase`, which would raise TS2717 type-conflict errors in consumer projects.
12
+ - Enabled Vitest typecheck tests (`*.test-d.ts`) so the `StoreOptionsExtensions` merging contract is validated at compile time alongside the runtime test suite.
13
+ - Added `docs/using-plugins.md`, a consumer-oriented guide: plugin registration, `defineAStore` / `defineAStoreCtx` reference (including TypeScript generics with JavaScript-first examples), `$reset`, state rollback, and SSR / Nuxt registration through `createHydrationPlugin`.
14
+ - Added `docs/authoring-plugins.md`, a plugin-author guide: `PluginSubscriberInterface` reference, the `PluginSubscriber` abstract class (including its `Instance` type parameter), the `Store` base class, execution policy & SSR best practices, and `StoreOptionsExtensions` augmentation.
15
+ - Documented the testing setup and the trust & supply-chain practices (GPG-signed commits, review-gated merges, npm provenance) in the README.
16
+
17
+ ### Changed
18
+ - Restructured the documentation around the package's two audiences: the README is now a lightweight entry point that routes readers to the dedicated consumer and plugin-author guides.
19
+ - Added the `docs/` directory to the published package files so both guides ship with the npm tarball.
20
+
21
+ ### Fixed
22
+ - Aligned the `$rollbackAfterFailure` public type with its implementation: action arguments are now passed as a single array (`$rollbackAfterFailure(params, [arg1, arg2])`, forwarded via `apply()`), instead of the documented variadic form that threw `TypeError: CreateListFromArrayLike called on non-object` at runtime.
23
+ - Fixed store typings lost when defining stores with `defineAStore`, `defineAStoreCtx`, `defineAStoreSetup` or `defineAStoreOptionApi`: state, getters and actions are now inferred from the store definition (setup function return or options object), exactly like pinia's `defineStore`, so IDEs list store members and display action prototypes. Explicit store/state generics (e.g. `defineAStore<Sto, Sta>`) remain supported for plugin-augmented stores and now type the store returned by `useStore()` — they were previously intersected onto the store definition itself, which left the returned store loosely typed.
24
+ - Added the public `DefineAStoreDefinition<Sto, Sta>` type: the store definition returned when explicit store/state generics are provided. It extends pinia's `StoreDefinition` so it stays assignable wherever a standard store definition is expected.
25
+ - Widened the `getDefineAStoreSetupContext` parameter to accept any store object, so fully inferred stores (without index signatures) can be passed without a cast.
26
+
27
+ ## [0.2.0-beta.0]
9
28
 
10
29
  ### Added
11
30
  - Added automatic state rollback on action failure via the `rollbackAfterFailure` store option: the declared state keys are snapshotted before the action runs and restored through `$patch` when the action throws (sync or async).
package/README.md CHANGED
@@ -1,377 +1,83 @@
1
- # pinia-plugin-subscription
1
+ # pinia-plugin-subscription
2
2
 
3
- Pinia plugin for Vue.js that helps building Pinia plugins by centralizing subscriber registration and providing a `Store` base class for store helpers.
3
+ Pinia plugin for Vue.js that helps building Pinia plugins by centralizing subscriber registration and providing a `Store` base class for store helpers.
4
4
 
5
- This project provides:
6
- - a lightweight mechanism to declare "subscribers" that are invoked when stores are registered or updated by Pinia;
7
- - a `Store` base class (helper wrapper) to ease interacting with Pinia stores from subscribers or other plugin code;
8
- - an API to create a Pinia plugin from a list of subscribers;
9
- - the $reset method to all stores modified by the plugin;
10
- - automatic state rollback on action failure via the `rollbackAfterFailure` store option and the `$rollbackAfterFailure` method.
5
+ This project provides:
6
+ - a lightweight mechanism to declare "subscribers" that are invoked when stores are registered or updated by Pinia;
7
+ - a `Store` base class (helper wrapper) to ease interacting with Pinia stores from subscribers or other plugin code;
8
+ - an API to create a Pinia plugin from a list of subscribers;
9
+ - the `$reset` method on all stores modified by the plugin;
10
+ - automatic state rollback on action failure via the `rollbackAfterFailure` store option and the `$rollbackAfterFailure` method.
11
11
 
12
- The main goal is to offer a clear API for writing reusable Pinia plugins and to make it easy to extend stores from plugin code.
12
+ ## Tested & maintained
13
13
 
14
- ## Installation
14
+ The package is fully tested with [Vitest](https://vitest.dev/): runtime behavior, type-level contracts (`*.test-d.ts`) and performance regressions are covered, and coverage reports are available in `coverage/`. The full test suite and the build run on every push and pull request through [GitHub Actions](.github/workflows/ci.yml).
15
15
 
16
- Ensure Pinia is installed, then register the plugin in your `main.ts`:
16
+ ## Trust & supply chain
17
17
 
18
- For local development and runtime demos, use the dedicated demo app with `npm run dev`. The library build remains `npm run build` and is intentionally kept separate from the demo entry.
18
+ This package is **open source (MIT)** and developed in a [public repository](https://github.com/AlxBDo/pinia-plugin-subscription). You can read, audit, fork and self-host the code at any time — no vendor lock-in, no service-continuity risk.
19
19
 
20
- For helper-only imports, the package also exposes an additive subpath that is kept separate from the default library API:
20
+ Development follows these practices:
21
21
 
22
- ```typescript
23
- import { PluginSubscriber, Store } from 'pinia-plugin-subscription/helpers'
24
- ```
22
+ - **No direct pushes to `main`** — every change lands through a reviewed pull request (branch protection enforced).
23
+ - **Commits are GPG-signed** and verified on GitHub.
24
+ - **Tests and build gate every merge** — a pull request cannot merge with a failing CI run.
25
+ - **npm releases ship with provenance** — each published package is built and signed on GitHub Actions and cryptographically linked to the exact commit and CI run that built it ([example transparency log entry](https://search.sigstore.dev/?logIndex=2811656622)), so you can verify what you install.
26
+ - **Security issues are handled privately** — see [SECURITY.md](SECURITY.md) for the reporting process.
25
27
 
26
- For type-only imports, prefer the dedicated public types entry:
28
+ ## Documentation
27
29
 
28
- ```typescript
29
- import type { PluginSubscriptionOptions } from 'pinia-plugin-subscription/types'
30
+ The package serves two audiences:
31
+
32
+ | You want to… | Guide |
33
+ | --- | --- |
34
+ | Use a compatible plugin (e.g. `pinia-plugin-extending-store`, `pinia-plugin-persist-state`) or this package's built-in store features (`defineAStore`, `$reset`, state rollback) in your app | [Using compatible plugins](docs/using-plugins.md) |
35
+ | Build your own pinia plugin on top of `pinia-plugin-subscription` | [Plugin authoring guide](docs/authoring-plugins.md) |
36
+
37
+ ## Installation
38
+
39
+ ```bash
40
+ npm install pinia pinia-plugin-subscription
30
41
  ```
31
42
 
32
- ```typescript
43
+ Register the plugin in your `main.ts`:
44
+
45
+ ```js
33
46
  import { createApp } from 'vue'
34
47
  import { createPinia } from 'pinia'
35
- import { createPlugin, PLUGIN_NAME as PPS } from 'pinia-plugin-subscription'
36
- import { myStoreSubscriber } from './src/core/my-store'
48
+ import { createPlugin, PLUGIN_NAME } from 'pinia-plugin-subscription'
49
+ import { myStoreSubscriber } from './plugins/my-store'
37
50
  import App from './App.vue'
38
51
 
39
52
  const app = createApp(App)
40
53
  const pinia = createPinia()
41
54
 
42
- // Register plugin (subscribers array, debug mode)
43
- pinia.use(createPlugin([myStoreSubscriber], [PPS]))
55
+ // Register plugin (subscribers array, plugins to debug)
56
+ pinia.use(createPlugin([myStoreSubscriber], [PLUGIN_NAME]))
44
57
 
45
58
  app.use(pinia)
46
59
  app.mount('#app')
47
60
  ```
48
61
 
49
- ## Usage — Examples
50
-
51
- **1) Subscriber using a `Store` subclass:**
52
-
53
- ```typescript
54
- import PluginSubscriber from 'pinia-plugin-subscription'
55
- import { Store } from 'pinia-plugin-subscription'
56
-
57
- class MyPlugin extends Store {
58
- protected override _className: string = 'MyPlugin'
59
- protected static override _requiredKeys?: string[] | undefined = ['my-plugin-option']
60
-
61
- constructor(store, options, debug = false) {
62
- super(store, options, debug)
63
- this.doSomething()
64
- }
65
- }
66
-
67
- class MyPluginSubscriber extends PluginSubscriber<MyPlugin> {
68
- constructor() {
69
- super('my-plugin', MyPlugin.customizeStore.bind(MyPlugin))
70
- }
71
- }
72
-
73
- export const myStoreSubscriber = new MyPluginSubscriber()
74
- ```
75
-
76
- **2) Simple subscriber implementing `PluginSubscriberInterface`:**
77
-
78
- ```typescript
79
- import type { PluginSubscriberInterface } from 'pinia-plugin-subscription'
80
-
81
- export const myStoreSubscriber: PluginSubscriberInterface = {
82
- name: 'my-plugin',
83
-
84
- invoke: (context, debug) => {
85
- // context contains `store`, `options`, `pinia`
86
- console.log('store registered', context.store.$id)
87
-
88
- return true
89
- },
90
-
91
- resetStoreCallback: (store) => {
92
- console.log('store reset:', store.$id)
93
- }
94
- }
95
- ```
96
-
97
- ## Advanced Features
98
-
99
- - **Debug mode:** Specifies the name of the plugin(s) to debug as the second argument to `createPlugin` to enable detailed logging.
100
- - **Reset callbacks:** Define `resetStoreCallback` to run custom logic when a store is reset.
101
- - **SSR and hydration control:** Configure whether each subscribed plugin runs on the server, the client, or only after client hydration.
102
- - **Lifecycle safety:** Internal hydration ordering is now guarded so `hydrate()` completes before `afterHydration()` and disposed stores do not retain stale subscriber metadata.
62
+ ### Import subpaths
103
63
 
104
- ## API Reference
105
-
106
- ### `createPlugin(subscribers: PluginSubscriber[], debug?: string[]): PiniaPlugin`
107
-
108
- Creates and returns a Pinia plugin from the provided `subscribers`. Each subscriber is invoked when a store is registered.
109
-
110
- ### `createHydrationPlugin(subscribers: PluginSubscriber[], options?: PluginSubscriptionOptions): PiniaPlugin`
111
-
112
- Creates a Pinia plugin dedicated to SSR / Nuxt hydration orchestration. This helper is useful when a store plugin needs a runtime-specific scheduler or environment override without forcing every app to re-declare the plugin’s execution policy.
113
-
114
- ```typescript
115
- import { createHydrationPlugin, PLUGIN_NAME as PPS } from 'pinia-plugin-subscription'
116
-
117
- pinia.use(createHydrationPlugin([
118
- persistedStateSubscriber
119
- ], {
120
- debug: [PPS],
121
- hydrationScheduler: (run) => {
122
- nextTick(() => run())
123
- }
124
- }))
125
- ```
126
-
127
- ### SSR / Nuxt hydration control
128
-
129
- The source of truth for hydration policy stays on the subscriber itself. For example, a client-only plugin should declare its execution directly:
130
-
131
- ```typescript
132
- export const persistedStateSubscriber: PluginSubscriberInterface = {
133
- name: 'persisted-state',
134
- execution: {
135
- environment: 'client',
136
- hydration: 'defer',
137
- },
138
- hydrationScheduler: (run) => {
139
- nextTick(() => run())
140
- },
141
- invoke: (context, debug) => {
142
- // ...
143
- return true
144
- }
145
- }
146
- ```
147
-
148
- Available execution options:
149
-
150
- - `environment: 'both' | 'client' | 'server'` — controls where the subscriber is allowed to run.
151
- - `hydration: 'immediate' | 'defer'` — on the client, `defer` schedules execution after hydration.
152
- - `hydrationScheduler` can be provided either on a subscriber or via `createHydrationPlugin()` to override the execution timing when needed.
153
-
154
- ### SSR / Nuxt best practices
155
-
156
- `pinia-plugin-subscription` is SSR-safe by design, but the runtime policy still needs to match the actual app lifecycle.
157
-
158
- Use `hydration: 'defer'` when the subscriber depends on browser-only APIs, client-side cookies, localStorage, DOM access, or a hydrated app state that must exist only after the app is mounted.
159
-
160
- ```ts
161
- const persistedStateSubscriber: PluginSubscriberInterface = {
162
- name: 'persisted-state',
163
- execution: {
164
- environment: 'client',
165
- hydration: 'defer',
166
- },
167
- hydrationScheduler: (run) => nextTick(() => run()),
168
- invoke: () => true,
169
- }
170
- ```
171
-
172
- Use `runtimeEnvironment: 'server'` or `execution.environment: 'server'` when a subscriber is only valid during server-side rendering or when it should not touch browser-only objects.
64
+ For helper-only imports, the package exposes an additive subpath kept separate from the default library API:
173
65
 
174
66
  ```ts
175
- pinia.use(createHydrationPlugin([serverOnlySubscriber], {
176
- runtimeEnvironment: 'server'
177
- }))
67
+ import { PluginSubscriber, Store } from 'pinia-plugin-subscription/helpers'
178
68
  ```
179
69
 
180
- Avoid browser-only code in stores during build-time SSR. In practice, that means:
181
-
182
- - do not access `window`, `document`, `localStorage`, or `matchMedia` at module scope or during store setup when the code may run on the server,
183
- - keep browser-specific bootstrap in `hydrate()` or `afterHydration()`,
184
- - prefer environment-aware guards such as `typeof window !== 'undefined'`,
185
- - avoid doing network access or hydration reads before the client is ready unless the code is explicitly intended to run on both environments.
186
-
187
- A safe pattern is:
70
+ For type-only imports, prefer the dedicated public types entry:
188
71
 
189
72
  ```ts
190
- const mySubscriber: PluginSubscriberInterface = {
191
- name: 'safe-browser-access',
192
- execution: {
193
- environment: 'client',
194
- hydration: 'defer',
195
- },
196
- hydrate: (context) => {
197
- // safe browser access here after hydration is allowed
198
- const saved = localStorage.getItem('demo')
199
- if (saved) {
200
- context.store.$patch({ value: JSON.parse(saved) })
201
- }
202
- },
203
- invoke: () => true,
204
- }
205
- ```
206
-
207
- This keeps the server render deterministic and prevents browser-only initialization from crashing Nuxt or SSR builds.
208
-
209
- ### State rollback on action failure
210
-
211
- The plugin can automatically restore the previous state when an action throws. Declare the state keys to snapshot per action via the `rollbackAfterFailure` store option:
212
-
213
- ```typescript
214
- import { defineAStore } from 'pinia-plugin-subscription'
215
-
216
- export const useMyStore = defineAStore('myStore', () => {
217
- const count = ref(0)
218
-
219
- function riskyAction() {
220
- count.value += 1
221
- throw new Error('Something went wrong')
222
- }
223
-
224
- return { count, riskyAction }
225
- }, {
226
- rollbackAfterFailure: {
227
- // only the listed keys are snapshotted / restored (deep-cloned)
228
- riskyAction: ['count']
229
- }
230
- })
231
- ```
232
-
233
- Before a configured action runs, the declared state keys are snapshotted. If the action throws (synchronously or by rejecting its returned promise), the snapshot is restored through `$patch`, so partial mutations are rolled back. The snapshot is always discarded once the action completes or fails.
234
-
235
- Only the actions listed in `rollbackAfterFailure` are snapshotted, so unrelated actions pay no cloning cost. Use `'all'` instead of a key list to snapshot the full state — prefer explicit keys for large states.
236
-
237
- Action names starting with `_` or `$` are rejected to protect internal store methods.
238
-
239
- #### Manual rollback with `$rollbackAfterFailure`
240
-
241
- Every store registered by the plugin also exposes a `$rollbackAfterFailure` method to run any action with an explicit snapshot/rollback wrapper, without declaring it in the store options:
242
-
243
- ```typescript
244
- const store = useMyStore()
245
-
246
- try {
247
- await store.$rollbackAfterFailure(
248
- { action: 'riskyAction', stateKeys: ['count'] },
249
- // ...args forwarded to the action
250
- )
251
- } catch (error) {
252
- // the action failed and the state was restored
253
- }
254
- ```
255
-
256
- - `params.action` — the name of the action to execute.
257
- - `params.stateKeys` — optional; the state keys to snapshot, or `'all'` (default when omitted or empty).
258
- - The original error is rethrown after the state is restored.
259
-
260
- ### `defineAStoreCtx(id, setup, options?)`
261
-
262
- Use actions or access the state, added by one or more plugins, when defining the store.
263
-
264
- ```typescript
265
- import { defineAStoreCtx, getEnhancedStore } from 'pinia-plugin-subscription'
266
-
267
- type EnhancedStore = { addItem: (value: unknown) => void }
268
-
269
- export const useMyStore = defineAStoreCtx('myStore', (ctx) => {
270
- const enhanced = getEnhancedStore<EnhancedStore>(ctx)
271
-
272
- return {
273
- addViaEnhanced: (value: unknown) => enhanced.addItem(value)
274
- }
275
- })
276
- ```
277
-
278
- `ctx.extensions` now supports:
279
- - `enhancedStore`
280
-
281
- The setup context is indexed internally only when `storeOptions.enhancedStore` is set to `true` (this is enabled automatically by `defineAStoreCtx`).
282
- The temporary lookup by store id is now cleaned as soon as the weak-map association is established (and on store dispose), which limits map growth over time.
283
- When `storeOptions.debug` is `true`, setup-context map size transitions are logged for observability.
284
-
285
- ### `PluginSubscriberInterface`
286
-
287
- An object with at least an `invoke(context: PiniaPluginContext, debug?: boolean)` method, plus optional properties:
288
-
289
- - `execution?: { environment?: 'both' | 'client' | 'server'; hydration?: 'immediate' | 'defer' }`
290
- - `hydrationScheduler?: (run: () => void) => void`
291
- - `hydrate?: (context, debug) => void | Promise<void>` — optional hook for SSR-safe store initialization after the subscriber is accepted for execution
292
- - `afterHydration?: (context, debug) => void | Promise<void>` — optional lifecycle hook for post-hydration work
293
- - `resetStoreCallback?: (store?: any) => void`
294
- - `storeOnActionSubscription?: { store, callback }` (getter)
295
- - `storeMutationSubscription?: { store, callback }` (getter)
296
- - `subscriptions?: Record<string, Function>` (plugin-specific subscription functions)
297
-
298
- ## The `PluginSubscriber` Abstract Class
299
-
300
- The project provides an abstract `PluginSubscriber` implementation (see [src/core/PluginSubscriber.ts](src/core/PluginSubscriber.ts)) to simplify creating reusable subscribers.
301
-
302
- **Typical usage:**
303
-
304
- - The subscriber instantiates a `Store` (or subclass) via a factory (`MyStore.customizeStore`).
305
- - The instance exposes:
306
- - `subscriptions` (from `getSubscriptions()`)
307
- - `storeMutationSubscription` (from `storeSubscribe`)
308
- - `storeOnActionSubscription` (from `onAction`)
309
- - optional `pluginCreated(store)` hook called after initialization
310
-
311
- **Example:**
312
-
313
- ```typescript
314
- import { nextTick } from 'vue'
315
- import PluginSubscriber from 'pinia-plugin-subscription'
316
- import StoreExtension from './src/extending-pinia-store/core/StoreExtension'
317
- import { addStore } from './src/extending-pinia-store/plugins/stores'
318
-
319
- class ExtendingStoreSubscriber extends PluginSubscriber<StoreExtension> {
320
- constructor() {
321
- super('extendsPiniaStore', StoreExtension.customizeStore.bind(StoreExtension))
322
-
323
- // Controls when this subscriber may run and whether it should wait for hydration on the client.
324
- this.execution = {
325
- environment: 'client',
326
- hydration: 'defer',
327
- }
328
-
329
- // Optional framework-specific scheduler for deferred execution.
330
- this.hydrationScheduler = (run) => {
331
- nextTick(() => run())
332
- }
333
-
334
- this.pluginCreated = addStore
335
- }
336
-
337
- override hydrate() {
338
- if (typeof window === 'undefined') {
339
- return
340
- }
341
-
342
- // Safe browser-only initialization. This is only called when the policy allows it.
343
- return this.storeInstance?.hydrate?.()
344
- }
345
- }
346
-
347
- export const extendingStoreSubscriber = new ExtendingStoreSubscriber()
73
+ import type { PluginSubscriptionOptions } from 'pinia-plugin-subscription/types'
348
74
  ```
349
75
 
350
- This example shows the recommended pattern for SSR / Nuxt-safe plugins:
351
-
352
- - `execution.environment` restricts the subscriber to `'both'`, `'client'`, or `'server'`
353
- - `execution.hydration` is `'immediate'` by default and can be set to `'defer'` when the plugin must wait for client hydration
354
- - `hydrationScheduler` lets you override the runtime scheduling behavior, for example with Nuxt/Vue `nextTick()`
355
- - `hydrate()` / `afterHydration()` are optional lifecycle hooks for browser-only initialization and post-hydration work; they help keep SSR-sensitive logic out of constructors
356
-
357
- ## The `Store` Class — Summary
358
-
359
- The `Store` class (see [src/core/Store.ts](src/core/Store.ts)) is a wrapper around a `PiniaStore` providing:
360
-
361
- - **Properties:** `debug`, `options`, `state`, `store`.
362
- - **Useful methods:**
363
- - `addToState(name, value?)` — adds a property to store state and exposes it as a `Ref` when appropriate.
364
- - `addSubscription(pluginName, subscription)` — registers a plugin-specific subscription function.
365
- - `getSubscriptions()` — returns registered subscriptions.
366
- - `storeSubscribe` (getter/setter) — factory for `store.$subscribe` ({ store, callback }).
367
- - `onAction` (getter/setter) — factory for `onAction` ({ store, callback }).
368
- - `static customizeStore(store, options, debug?)` — recommended factory for class instantiation.
369
- - `debugLog(message, args)` — conditional logging.
370
- - Helpers: `stateHas()`, `storeHas()`, `getValue()`.
371
-
372
- ## Testing
76
+ ## Development
373
77
 
374
- This plugin is tested with Vitest. Coverage reports are available in the `coverage/` directory.
78
+ - `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/).
79
+ - `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/`.
80
+ - `npm run bundle:check` — measures the emitted bundle size.
375
81
 
376
82
  ## License
377
83
 
@@ -379,4 +85,4 @@ MIT
379
85
 
380
86
  ## Publishing
381
87
 
382
- Releases are published to npm via GitHub Actions. GitHub releases marked as pre-releases are published with the `beta` dist-tag using `npm publish --tag beta`; stable releases use the default `latest` tag. The workflow uses npm provenance for better supply-chain security and requires a `NPM_TOKEN` secret in the repository settings.
88
+ Releases are published to npm via GitHub Actions. GitHub releases marked as pre-releases are published with the `beta` dist-tag using `npm publish --tag beta`; stable releases use the default `latest` tag. The workflow uses npm provenance for better supply-chain security and requires a `NPM_TOKEN` secret in the repository settings.
@@ -1,9 +1,9 @@
1
1
  var f = Object.defineProperty;
2
- var b = (s, t, e) => t in s ? f(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
3
- var n = (s, t, e) => b(s, typeof t != "symbol" ? t + "" : t, e);
4
- import { ref as S, toRef as y } from "vue";
2
+ var S = (s, t, e) => t in s ? f(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
3
+ var n = (s, t, e) => S(s, typeof t != "symbol" ? t + "" : t, e);
4
+ import { ref as b, toRef as y } from "vue";
5
5
  import { defineStore as g } from "pinia";
6
- class L {
6
+ class H {
7
7
  constructor(t, e, r) {
8
8
  n(this, "_console");
9
9
  n(this, "_createInstance");
@@ -98,7 +98,7 @@ function x(s, t, e) {
98
98
  const r = s.$dispose;
99
99
  s.$dispose = (...o) => (p.delete(s), c.delete(t), h(t, e, "dispose cleanup"), r.apply(s, o)), l.add(s);
100
100
  }
101
- function N(s, t, e) {
101
+ function L(s, t, e) {
102
102
  const r = e ? { storeOptions: e } : {};
103
103
  return typeof t == "function" ? d(
104
104
  s,
@@ -110,7 +110,7 @@ function N(s, t, e) {
110
110
  r
111
111
  );
112
112
  }
113
- function R(s, t, e) {
113
+ function N(s, t, e) {
114
114
  const r = e ? { storeOptions: { ...e, enhancedStore: !0 } } : { storeOptions: { enhancedStore: !0 } };
115
115
  return d(
116
116
  s,
@@ -122,7 +122,11 @@ function d(s, t, e) {
122
122
  const r = {
123
123
  id: s,
124
124
  extensions: {}
125
- }, o = e?.storeOptions?.enhancedStore === !0, i = g(s, () => t(r), e);
125
+ }, o = e?.storeOptions?.enhancedStore === !0, i = g(
126
+ s,
127
+ () => t(r),
128
+ e
129
+ );
126
130
  return Object.assign(((...u) => {
127
131
  o && (c.set(s, r), h(s, e, "registered context by id"));
128
132
  const a = i(...u);
@@ -137,24 +141,25 @@ function I(s) {
137
141
  return m.has(s[0]);
138
142
  }
139
143
  function w(s) {
140
- return p.get(s) ?? (typeof s?.$id == "string" ? c.get(s.$id) : void 0);
144
+ const t = s;
145
+ return p.get(s) ?? (typeof t?.$id == "string" ? c.get(t.$id) : void 0);
141
146
  }
142
- function k(s) {
147
+ function E(s) {
143
148
  const t = s.extensions.enhancedStore ?? s.extensions.extending;
144
149
  if (!t)
145
150
  throw new Error(`${s.id}Store - getEnhancedStore - Error: enhanced store is required`);
146
151
  return t;
147
152
  }
148
- function M(s, t) {
153
+ function k(s, t) {
149
154
  s.extensions.enhancedStore = t, s.extensions.extending = t;
150
155
  }
151
156
  function T(s) {
152
- return k(s);
157
+ return console.warn(`${s.id}Store - getExtendingStore is deprecated. Use getEnhancedStore instead.`), E(s);
153
158
  }
154
159
  function W(s, t) {
155
160
  return `${s}-${t.$id}`;
156
161
  }
157
- function E(s) {
162
+ function M(s) {
158
163
  return s ? Array.isArray(s) ? s.length === 0 : typeof s == "object" ? Object.keys(s).length === 0 : typeof s == "string" ? s.trim() === "" : !1 : !(typeof s == "boolean" || typeof s == "number");
159
164
  }
160
165
  class P extends C {
@@ -168,7 +173,7 @@ class P extends C {
168
173
  n(this, "_storeSubscribe");
169
174
  if (this._options = r.storeOptions, this._store = e, this._options?.enhancedStore) {
170
175
  const u = w(this.store);
171
- u && M(u, this.store);
176
+ u && k(u, this.store);
172
177
  }
173
178
  }
174
179
  get onAction() {
@@ -203,26 +208,14 @@ class P extends C {
203
208
  set storeSubscribe(e) {
204
209
  this._storeSubscribe = e;
205
210
  }
206
- /**
207
- * Add property to state
208
- * @param name
209
- * @param value
210
- */
211
211
  addToState(e, r) {
212
- this.isOptionApi() || r?.value || (r = S(r)), this.state[e] = r, this.store[e] = y(this.state, e);
212
+ this.isOptionApi() || r?.value || (r = b(r)), this.state[e] = r, this.store[e] = y(this.state, e);
213
213
  }
214
214
  addSubscription(e, r, o) {
215
215
  this._subscriptions[e] = { subscription: r, ...o ?? {} };
216
216
  }
217
217
  afterHydration() {
218
218
  }
219
- /**
220
- * Create and return a class instance
221
- * @param store
222
- * @param options
223
- * @param debug
224
- * @returns
225
- */
226
219
  static customizeStore(e, r, o = !1, i) {
227
220
  if (r.storeOptions && this.hasRequiredKeys(r.storeOptions))
228
221
  return new this(e, r, o, i);
@@ -234,7 +227,7 @@ class P extends C {
234
227
  return this.getValue(this.state[e]);
235
228
  }
236
229
  getSubscriptions() {
237
- if (!E(this._subscriptions))
230
+ if (!M(this._subscriptions))
238
231
  return this._subscriptions;
239
232
  }
240
233
  getValue(e) {
@@ -329,15 +322,16 @@ export {
329
322
  C as D,
330
323
  F as P,
331
324
  P as S,
332
- L as a,
333
- R as b,
325
+ H as a,
326
+ N as b,
334
327
  w as c,
335
- N as d,
336
- k as e,
328
+ L as d,
329
+ E as e,
337
330
  T as f,
338
331
  W as g,
339
332
  I as h,
340
- E as i,
333
+ M as i,
341
334
  _ as p,
342
- M as s
335
+ k as s
343
336
  };
337
+ //# sourceMappingURL=index-VL_PgzVK.js.map