pinia-plugin-subscription 1.0.0-beta.2 → 1.0.0-beta.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +73 -12
- package/CONTRIBUTING.md +10 -1
- package/README.md +48 -293
- package/SECURITY.md +6 -6
- package/dist/chunks/setup-context-3G3Hy1ep.js +909 -0
- package/dist/dictionaries/plugin-subscription-event.d.ts +20 -0
- package/dist/{core/Store.d.ts → enhanced-store/EnhancedStore.d.ts} +24 -29
- package/dist/enhanced-store/define-a-store.d.ts +64 -0
- package/dist/enhanced-store/setup-context.d.ts +27 -0
- package/dist/events/EventsEmitter.d.ts +9 -0
- package/dist/events/EventsSubscriber.d.ts +32 -0
- package/dist/events/EventsSubscription.d.ts +13 -0
- package/dist/events/StoreEvent.d.ts +6 -0
- package/dist/events/StoresEventsSubscriptionsRegistry.d.ts +31 -0
- package/dist/events/event.d.ts +8 -0
- package/dist/factories/events-registry.d.ts +9 -0
- package/dist/factories/events-subscriber.d.ts +11 -0
- package/dist/factories/messenger-registry.d.ts +16 -0
- package/dist/factories/plugin-subscriber.d.ts +17 -0
- package/dist/helpers.js +204 -312
- package/dist/lib/helpers.d.ts +9 -0
- package/dist/lib/main.d.ts +3 -12
- package/dist/orchestration/ExecutionPolicy.d.ts +15 -0
- package/dist/orchestration/PluginOrchestrator.d.ts +41 -0
- package/dist/orchestration/SubscriberScheduler.d.ts +31 -0
- package/dist/pinia-plugin-subscription.js +31 -426
- package/dist/plugins/createPlugin.d.ts +3 -13
- package/dist/services/messenger.d.ts +28 -0
- package/dist/services/messengerProvider.d.ts +45 -0
- package/dist/store-hooks/StoreHooksBinder.d.ts +20 -0
- package/dist/store-hooks/StoreHooksRegistry.d.ts +34 -0
- package/dist/{core/PluginSubscriber.d.ts → subscribers/StoreSubscriber.d.ts} +39 -28
- package/dist/tracing/TraceGroupHelper.d.ts +27 -0
- package/dist/tracing/TraceableEmitter.d.ts +60 -0
- package/dist/tracing/TraceableEventsSubscriber.d.ts +21 -0
- package/dist/tracing/TraceableStoreEventsSubscriber.d.ts +16 -0
- package/dist/tracing/trace-groups.d.ts +9 -0
- package/dist/types/core.d.ts +12 -0
- package/dist/types/events.d.ts +24 -0
- package/dist/types/index.d.ts +8 -34
- package/dist/types/messenger.d.ts +20 -0
- package/dist/types/plugin.d.ts +39 -20
- package/dist/types/store.d.ts +1 -9
- package/dist/types/trace.d.ts +35 -75
- package/dist/utils/constants.d.ts +4 -0
- package/dist/utils/events.d.ts +3 -0
- package/dist/utils/id.d.ts +20 -0
- package/dist/utils/store.d.ts +9 -93
- package/docs/authoring-plugins.md +330 -78
- package/docs/using-plugins.md +89 -53
- package/package.json +14 -8
- package/dist/chunks/constantes-CaTNAbzX.js +0 -261
- package/dist/chunks/constantes-CaTNAbzX.js.map +0 -1
- package/dist/core/PluginSubscription.d.ts +0 -92
- package/dist/core/RollbackStateSnapshotsHandler.d.ts +0 -65
- package/dist/factories/console-trace-listener.d.ts +0 -7
- package/dist/factories/state-snapshot.d.ts +0 -3
- package/dist/factories/trace-listener.d.ts +0 -16
- package/dist/factories/trace-registry.d.ts +0 -17
- package/dist/helpers/index.d.ts +0 -9
- package/dist/helpers.js.map +0 -1
- package/dist/pinia-plugin-subscription.js.map +0 -1
- package/dist/plugins/createHydrationPlugin.d.ts +0 -10
- package/dist/system/Tracer.d.ts +0 -20
- package/dist/system/log.d.ts +0 -35
- package/dist/tests/defineAStore.test-d.d.ts +0 -1
- package/dist/tests/storeOptionsExtensions.test-d.d.ts +0 -12
- package/dist/types/comparison.d.ts +0 -3
- package/dist/types/list.d.ts +0 -13
- package/dist/types/log.d.ts +0 -8
- package/dist/types/resourceId.d.ts +0 -4
- package/dist/utils/Performance.d.ts +0 -9
- package/dist/utils/constantes.d.ts +0 -1
- package/dist/utils/deep-clone.d.ts +0 -7
- package/dist/utils/defineStoreId.d.ts +0 -1
- package/dist/utils/object.d.ts +0 -4
- package/dist/utils/validation/object.d.ts +0 -9
package/docs/using-plugins.md
CHANGED
|
@@ -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
|
|
16
|
+
## What compatible plugins can use
|
|
17
17
|
|
|
18
|
-
Plugins built on `pinia-plugin-subscription`
|
|
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
|
-
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
- **
|
|
26
|
-
|
|
27
|
-
- **
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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 {
|
|
69
|
+
import type { StoreSubscriberInterface } from 'pinia-plugin-subscription/types'
|
|
70
70
|
|
|
71
|
-
const subscribers:
|
|
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
|
|
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
|
-
|
|
239
|
-
|
|
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
|
-
|
|
248
|
-
|
|
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
|
-
|
|
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
|
|
280
|
-
|
|
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
|
-
|
|
292
|
-
method to run
|
|
293
|
-
|
|
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
|
|
358
|
+
} from 'pinia-plugin-subscription-devtools'
|
|
325
359
|
import {
|
|
326
360
|
createPlugin
|
|
327
361
|
} from 'pinia-plugin-subscription'
|
|
328
362
|
|
|
329
|
-
const
|
|
363
|
+
const traceGroupsRegistry = createTracerRegistry()
|
|
330
364
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
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
|
-
|
|
371
|
+
tracerHandler: traceGroupsRegistry.tracerHandler
|
|
338
372
|
}))
|
|
339
373
|
```
|
|
340
374
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
`
|
|
345
|
-
|
|
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
|
-
|
|
382
|
+
traceGroupsRegistry.addListener({
|
|
350
383
|
filter: [
|
|
351
384
|
{ target: 'scope', value: 'cart' },
|
|
352
|
-
{ target: 'namespace', comparator: 'startsWith', value: '
|
|
353
|
-
]
|
|
354
|
-
|
|
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
|
|
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(
|
|
412
|
+
export function createRequestApp(traceCriteria) {
|
|
379
413
|
const app = createSSRApp(App)
|
|
380
414
|
const pinia = createPinia()
|
|
381
|
-
const
|
|
415
|
+
const traceGroupsRegistry = createTracerRegistry()
|
|
382
416
|
|
|
383
|
-
|
|
417
|
+
traceGroupsRegistry.addListener({ filter: traceCriteria, handler: logTrace })
|
|
384
418
|
pinia.use(createPlugin(subscribers, {
|
|
385
|
-
|
|
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
|
-
|
|
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 {
|
|
436
|
+
import { createPlugin } from 'pinia-plugin-subscription'
|
|
403
437
|
|
|
404
|
-
pinia.use(
|
|
438
|
+
pinia.use(createPlugin([persistedStateSubscriber], {
|
|
405
439
|
hydrationScheduler: (run) => {
|
|
406
440
|
nextTick(() => run())
|
|
407
441
|
}
|
|
408
442
|
}))
|
|
409
443
|
```
|
|
410
444
|
|
|
411
|
-
`
|
|
412
|
-
`
|
|
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.
|
|
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
|
|
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
|
|
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 &&
|
|
73
|
-
"
|
|
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-
|
|
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
|