pinia-plugin-subscription 1.0.0-beta.15 → 1.0.0-beta.16
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 +9 -18
- package/README.md +15 -5
- package/dist/chunks/PluginSubscription-BVKaiyWT.js +610 -0
- package/dist/core/PluginSubscriber.d.ts +4 -8
- package/dist/core/PluginSubscription.d.ts +2 -12
- package/dist/dictionaries/plugin-subscription-event.d.ts +15 -0
- package/dist/events/events-handler.d.ts +7 -0
- package/dist/events/events-store-handler.d.ts +8 -0
- package/dist/events/store-events-subscriber-handler.d.ts +9 -0
- package/dist/events/store-events-subscriber.d.ts +16 -0
- package/dist/factories/event-listener.d.ts +12 -0
- package/dist/factories/plugin-subscriber.d.ts +0 -1
- package/dist/helpers/index.d.ts +3 -0
- package/dist/helpers.js +56 -18
- package/dist/lib/main.d.ts +0 -1
- package/dist/pinia-plugin-subscription.js +9 -19
- package/dist/plugins/createPlugin.d.ts +1 -11
- package/dist/types/index.d.ts +2 -13
- package/dist/types/plugin-subscription-event.d.ts +4 -0
- package/dist/types/plugin.d.ts +8 -5
- package/dist/types/store.d.ts +0 -9
- package/dist/utils/store.d.ts +0 -9
- package/docs/authoring-plugins.md +18 -11
- package/docs/using-plugins.md +16 -9
- package/package.json +2 -2
- package/dist/chunks/PluginSubscription-GJDsym1O.js +0 -668
- package/dist/core/RollbackStateSnapshotsHandler.d.ts +0 -65
- package/dist/factories/state-snapshot.d.ts +0 -3
- package/dist/plugins/createHydrationPlugin.d.ts +0 -10
- package/dist/utils/defineStoreId.d.ts +0 -1
- package/dist/utils/validation/object.d.ts +0 -9
package/CHANGELOG.md
CHANGED
|
@@ -8,10 +8,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
10
|
### Added
|
|
11
|
-
- `pinia-plugin-subscription-devtools` package with `createTraceDevtools(options?)`, `createTracerRegistry()`, `mountTraceDevtools()` and the tracing documentation (`packages/devtools/docs/tracing.md`).
|
|
12
|
-
- `addScopesListener(scopes, context?, handler?)` groups events from selected store scopes and accepts a custom trace handler; custom `handler` / `filter` listeners are the supported way to consume trace events, documented in `packages/devtools/docs/tracing.md`
|
|
13
|
-
- `journal.serialize()` / `journal.import()` and `stringifyTraceSnapshot()` to carry server traces to the browser; payloads are bounded and made JSON-safe by `toSerializable`, imports are validated. The SSR demo embeds the server journal in the page and loads it through `createTraceDevtools()`
|
|
14
|
-
- `pinia-plugin-subscription-devtools`: `createTracerRegistry({ journal, side })` enables a per-store journal (`registry.journal`) recording every trace event with `seq`, `side` and the `actionId` correlating the events of one store action; ring buffer per store and side (default 1000, context and error events kept separately), `getEvents()`, `getScopes()`, `getDropped()`, `subscribe()`, `clear()`; documented in `packages/devtools/docs/tracing.md`
|
|
15
11
|
- SSR demo subscribers are now class-based (`PluginSubscriber` + a `Store` subclass) and emit traces through the tracer `PluginSubscription` provides (`this.trace()` / `this.traceError()`): hydration start/done, errors, and the `onMutation` trace group, all scoped to the store; the per-request tracer registry also listens on the server, so server traces print in the Node terminal and browser traces in the devtools console
|
|
16
12
|
- SSR demo shows a concrete case of environment-aware hydration: one store filled by a server-only subscriber (request data) and a client-only deferred subscriber (browser data), with a server/browser panel layout and a hydration timeline; the `Accept-Language` header is validated before being serialized
|
|
17
13
|
- Added a Vite SSR demo server (`npm run dev:ssr`) with per-request app/plugin instances, async server-side subscriber hydration, and Pinia state serialization for client hydration
|
|
@@ -21,11 +17,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
21
17
|
- `createPluginSubscriber(name, invoke, optionalProps?)` factory, exported from `pinia-plugin-subscription/helpers`, to build plain-object subscribers; documented in `docs/authoring-plugins.md` and used by the demo plugin
|
|
22
18
|
- Added a dedicated tracing guide, `docs/tracing.md`; the README now only presents tracing and links to it
|
|
23
19
|
- Moved the API reference, import subpaths, development, `Store` summary and testing sections from `README.md` to `docs/authoring-plugins.md`
|
|
24
|
-
- `pinia-plugin-subscription-devtools`: `createTracerRegistry({ redact })` opts into redaction of event payloads before they reach listeners. `true` masks a default list of sensitive keys (`password`, `token`, `secret`, `authorization`, API/private keys, `credential`, `cookie`, `cipher`...); an object adds custom `keys`, a `replacement`, or drops the defaults with `includeDefaults: false`. It works on a copy, covers arrays/`Map`/`Set`, handles circular references, and replaces the payload by `__traceRedactionError` if redaction fails. `defaultRedactedKeys` and `TraceRedactOptions` are exported
|
|
25
|
-
- `createTracerRegistry({ enabled })` in `pinia-plugin-subscription-devtools`: tracing is now disabled by default in production builds (`process.env.NODE_ENV === 'production'`); `addListener()` becomes a no-op unless `enabled: true` is passed. `enabled: false` forces it off in any environment. Error reporting through `console.error` is unchanged
|
|
26
|
-
- `pinia-plugin-subscription-devtools`: added `createTracerRegistry()` to create isolated trace listeners and tracers for each application or Pinia instance
|
|
27
|
-
- `pinia-plugin-subscription-devtools`: added the `Tracer` class and registry methods `addTraceListener()`, `clearTraceListeners()` and `hasTraceListeners()`
|
|
28
|
-
- `pinia-plugin-subscription-devtools`: added metadata-based trace filter criteria with `equals`, `contains`, `startsWith` and `endsWith` comparators, combined with `every` or `some`
|
|
29
20
|
- Added `trace()` and `traceError()` to `Store` and `PluginSubscription`
|
|
30
21
|
- Added trace types: `TraceEvent`, `TraceEventMetadata`, `TraceHandler`, `TraceLevel`, `TraceListener`, `TraceListenerRemover` and `TracePayload`
|
|
31
22
|
- Added `check:leaks` script and `scripts/check-dist-leaks.mjs`, guarding published artifacts against non-peer dependency imports in `dist/` (`.js` and `.d.ts`)
|
|
@@ -33,10 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
33
24
|
- Added unit tests covering the tracing system and the leak detection logic
|
|
34
25
|
|
|
35
26
|
### Changed
|
|
36
|
-
- Devtools: refs and computed attached to a trace are now displayed through their value instead of as raw objects (`toSerializable` unwraps them)
|
|
37
|
-
- **Breaking:** removed the built-in console output of traces (`createConsoleGroupTraceListener`, `ConsoleTraceGroupListener`, `TraceGroupListener`, `TraceListenerGroupBy`, the `groupBy` option of `addListener()`, and the internal console printers). Listeners now only forward events to their own `handler` (a no-op when omitted); `startGroup` / `closeGroup` only maintain the open-group stack that sets `groupId`. Fixed `tracerHandler.journal` not being exposed by the registry
|
|
38
27
|
- Trace groups follow the lifecycles of a store: `groupId` is now a `/` separated path (`<storeId>/plugin`, `<storeId>/onAction:<name>#<n>`, with `/after` and `/onError` sub-groups, `<storeId>/onMutation#<n>`, `<storeId>/reset#<n>`, `<storeId>/plugin/deferred:<subscriber>#<n>`). Every trace emitted for a store while a group is open, including those of subscribers and `Store` subclasses, joins the innermost one. `traceGroups` builders take the call counter; `TraceGroupId` is removed, and `groupId` is lifted from the payload to the event like `actionId`
|
|
39
|
-
- Devtools: the timeline nests events by lifecycle instead of by raw `actionId` (no more `#<n>` ids), events without `error` / `payload` are no longer expandable, `P` (payload) and `E` (error) chips flag the events carrying them, the floating button reads `Devtools` with a debug icon, and the Context tab lists subscribers by name (with their execution options) and shows options without `actions`
|
|
40
28
|
- `storeMutationSubscription` now supports several subscribers per store, like `storeOnActionSubscription`: a single `$subscribe` is registered per store and dispatches to every callback. A failing callback is reported through `traceError` without blocking the others, subscriber names are tracked, and the hook is unsubscribed when the store is disposed
|
|
41
29
|
- `storeOnActionSubscription` now receives the Pinia plugin context; action trace labels include the invoked action name
|
|
42
30
|
- Subscribers deferred with `hydration: 'defer'` now run inside their own trace group (label `subscriber:deferred`, keyed by store scope), which stays open until their asynchronous `hydrate()` / `afterHydration()` settle, so their traces are no longer emitted outside any group once `plugin()` has closed its `context` group. A hydration that never settles can no longer buffer the store's traces forever: the group is force-closed after `deferredTraceGroupTimeout` ms (new option, default 2500) and a `subscriber:deferred:timeout` error is traced
|
|
@@ -44,7 +32,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
44
32
|
- Clarified that SSR tracing registries and plugin instances must be created per request, and added coverage for listener isolation between registries
|
|
45
33
|
- Replaced the `Debug` abstract class with composition: `Store` and `PluginSubscription` no longer extend it and now own a `Tracer`
|
|
46
34
|
- 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
|
|
47
|
-
- Deprecated `createHydrationPlugin()` in favor of `createPlugin()` with hydration options
|
|
48
35
|
- Trace payloads are now lazily resolved, so unobserved tracing no longer builds log arguments
|
|
49
36
|
- Internal events now derive namespaces from trace labels, with `PluginSubscription` prefixed by default; store events carry `store.$id` as `scope`
|
|
50
37
|
- `Tracer` now delegates all output decisions to listeners and no longer owns a console or an enabled state
|
|
@@ -56,6 +43,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
56
43
|
- The `pluginsubscription` namespace prefix is now a shared constant (`pluginSubscriptionNamespace`) instead of a hard-coded string
|
|
57
44
|
|
|
58
45
|
### Changed (breaking)
|
|
46
|
+
- Move automatic and manual rollback, including their types, to `pinia-plugin-state-snapshots`; register its subscriber explicitly.
|
|
47
|
+
- Move `$reset` ownership and `resetStoreCallback` execution to `StateSnapshotsSubscriber`; `PluginSubscription` only provides the reset lifecycle hook.
|
|
48
|
+
- Allow store-event subscribers to opt in to error propagation; critical before-action failures abort the action and emit an error event for cleanup.
|
|
49
|
+
- removed the built-in console output of traces (`createConsoleGroupTraceListener`, `ConsoleTraceGroupListener`, `TraceGroupListener`, `TraceListenerGroupBy`, the `groupBy` option of `addListener()`, and the internal console printers). Listeners now only forward events to their own `handler` (a no-op when omitted); `startGroup` / `closeGroup` only maintain the open-group stack that sets `groupId`. Fixed `tracerHandler.journal` not being exposed by the registry
|
|
59
50
|
- The tracing solution moved to the new `pinia-plugin-subscription-devtools` package (`packages/devtools/`, same repository). `pinia-plugin-subscription` now only emits trace events through the `Tracer` / `TracerHandler` contract exported from `pinia-plugin-subscription/types`; without a `tracerHandler` it emits nothing. The compressed package drops from about 117 kB to about 50 kB, and the new package weighs about 19 kB.
|
|
60
51
|
- `createTracerRegistry`, `Tracer` (class), `defaultRedactedKeys`, `stringifyTraceSnapshot`, `getTraceGroupName` and `mountTraceDevtools` are now exported by `pinia-plugin-subscription-devtools` instead of `pinia-plugin-subscription/helpers` and `pinia-plugin-subscription/devtools`. `traceGroups` stays in `pinia-plugin-subscription/helpers`.
|
|
61
52
|
- The `Tracer` export of `pinia-plugin-subscription/helpers` is now the `Tracer` interface of `pinia-plugin-subscription/types`.
|
|
@@ -67,11 +58,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
67
58
|
- Reference implementation section lists the demo files and what each one illustrates; README links the demo and the `pinia-plugin-subscription` topic
|
|
68
59
|
|
|
69
60
|
### Fixed
|
|
70
|
-
-
|
|
71
|
-
-
|
|
72
|
-
- Devtools: the aside no longer sits under the page scrollbar (it keeps a gutter next to it) and the mouse wheel over the aside always scrolls the aside, not the page
|
|
73
|
-
- Devtools: the aside is mounted in the browser top layer (Popover API) so it stays viewport-sized and scrollable even when a page ancestor has a `transform` / `filter`; trace rows show the label first, then time, side and P / E chips on a second line
|
|
74
|
-
- Devtools: calls of a same hook (`onAction · name`, `onMutation`…) are merged into one group per store and side; groups start collapsed; events show their payload content directly (no `payload` key); wheel/touch scroll is no longer swallowed by host-page scroll locks and the scrollbar is always visible
|
|
61
|
+
- Correlate state snapshots with individual action invocations, clean them up on store disposal, and emit action completion events when actions actually settle.
|
|
62
|
+
- Publish workflow: `scripts/publish-unpublished.mjs` publishes each package (root, then workspaces) only when its `name@version` is not already on npm, so a re-run after a partial failure no longer fails on versions already published
|
|
75
63
|
- `defineAStoreSetup` now creates a separate setup context for each Pinia store instance, preventing enhanced-store extensions from being shared across SSR requests
|
|
76
64
|
- Demo plugin-added state now uses `Store.addToState()` so `pluginIsActive` is exposed and reactive on the Pinia store
|
|
77
65
|
- `defineAStoreCtx()` now types the inferred setup context's enhanced-store extensions as `unknown` instead of `AnyObject`; explicit types remain available through generics or `getEnhancedStore<T>()`
|
|
@@ -86,6 +74,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
86
74
|
|
|
87
75
|
### Removed
|
|
88
76
|
- Removed the internal `PluginConsole` singleton and the dead commented code of `system/log.ts`; `CustomConsole` stays exported from `helpers` for plugins not yet migrated to the tracer
|
|
77
|
+
- **Breaking:** removed `createHydrationPlugin()`; use `createPlugin(subscribers, options)` with the hydration and runtime options directly
|
|
78
|
+
- **Breaking:** removed `getExtendingStore()`; use `getEnhancedStore()` and `ctx.extensions.enhancedStore` instead. `getEnhancedStore()` no longer falls back to the deprecated `ctx.extensions.extending` property
|
|
79
|
+
- Removed the `itemState` export from `src/utils/store`
|
|
89
80
|
- **Breaking:** removed `debugLog()` and `logError()` from `Store` and `PluginSubscription` — use `trace()` and `traceError()` instead (see the migration snippet in `docs/tracing.md`)
|
|
90
81
|
- **Breaking:** removed the obsolete `debug` and custom-console arguments from `createPlugin()`, `PluginSubscription`, `PluginSubscriber`, `Store`, and `Store.customizeStore()`
|
|
91
82
|
- **Breaking:** removed the `debug` argument from subscriber `invoke()`, `hydrate()`, and `afterHydration()` hooks; tracing is now configured exclusively through listeners
|
package/README.md
CHANGED
|
@@ -7,9 +7,11 @@ This project provides:
|
|
|
7
7
|
- a `Store` base class (helper wrapper) to ease interacting with Pinia stores from subscribers or other plugin code;
|
|
8
8
|
- an API to create a Pinia plugin from a list of subscribers;
|
|
9
9
|
- the `$reset` method on all stores modified by the plugin;
|
|
10
|
-
-
|
|
10
|
+
- optional state rollback through the separate [`pinia-plugin-state-snapshots`](packages/state-snapshots/) package.
|
|
11
11
|
|
|
12
|
-
Deferred subscribers attach their action and reset callbacks to their own store after hydration; disposing a store removes its callbacks.
|
|
12
|
+
Deferred subscribers attach their action and reset callbacks to their own store after hydration; disposing a store removes its callbacks.
|
|
13
|
+
If a snapshot cannot be created, the state-snapshots subscriber logs the error
|
|
14
|
+
and lets the action run without that rollback snapshot.
|
|
13
15
|
|
|
14
16
|
## Tested & maintained
|
|
15
17
|
|
|
@@ -33,7 +35,7 @@ The package serves two audiences:
|
|
|
33
35
|
|
|
34
36
|
| You want to… | Guide |
|
|
35
37
|
| --- | --- |
|
|
36
|
-
| Use a compatible plugin (e.g. `pinia-plugin-extending-store`, `pinia-plugin-persist-state`) or
|
|
38
|
+
| Use a compatible plugin (e.g. `pinia-plugin-extending-store`, `pinia-plugin-persist-state`, `pinia-plugin-state-snapshots`) or built-in store features (`defineAStore`, `$reset`) | [Using compatible plugins](docs/using-plugins.md) |
|
|
37
39
|
| Build your own pinia plugin on top of `pinia-plugin-subscription` (API reference, `Store` class, import subpaths, development and testing) | [Plugin authoring guide](docs/authoring-plugins.md) |
|
|
38
40
|
| Debug stores and plugins with structured trace events | [Tracing](packages/devtools/docs/tracing.md) |
|
|
39
41
|
|
|
@@ -66,10 +68,18 @@ app.mount('#app')
|
|
|
66
68
|
## Advanced Features
|
|
67
69
|
|
|
68
70
|
- **Structured tracing:** the plugin and `Store` emit typed trace events through an optional `tracerHandler`. Tracing itself (listeners, journal, redaction, in-page panel) lives in the separate [`pinia-plugin-subscription-devtools`](packages/devtools/) package, so apps that do not debug stay lean — see [Tracing](#tracing).
|
|
69
|
-
- **Reset callbacks:** Define `resetStoreCallback` to run custom logic when a store
|
|
71
|
+
- **Reset callbacks:** Define `resetStoreCallback` to run custom logic when the registered [`StateSnapshotsSubscriber`](packages/state-snapshots/README.md) resets a store. `PluginSubscription` itself does not replace or reset the store's `$reset` method.
|
|
70
72
|
- **SSR and hydration control:** Configure whether each subscribed plugin runs on the server, the client, or only after client hydration.
|
|
71
73
|
- **Lifecycle safety:** Internal hydration ordering is now guarded so `hydrate()` completes before `afterHydration()` and disposed stores do not retain stale subscriber metadata.
|
|
72
74
|
|
|
75
|
+
For subscriber authors, store action events are emitted even without a `storeOnActionSubscription`:
|
|
76
|
+
`ACTION_BEFORE` receives `(name, invocationKey)`, `ACTION_AFTER` receives
|
|
77
|
+
`(name, invocationKey)` after success, and `ACTION_ON_ERROR` receives `(name, error, invocationKey)`
|
|
78
|
+
after failure. The symbol identifies one invocation.
|
|
79
|
+
Event subscribers may override `shouldPropagateError(event)` to make errors critical;
|
|
80
|
+
other subscriber errors continue to be logged. A critical `ACTION_BEFORE` error
|
|
81
|
+
aborts the action and emits `ACTION_ERROR` for cleanup.
|
|
82
|
+
|
|
73
83
|
## Tracing
|
|
74
84
|
|
|
75
85
|
The plugin only *emits* structured trace events; without a `tracerHandler` it emits nothing and costs nothing. Install [`pinia-plugin-subscription-devtools`](packages/devtools/) (usually as a development dependency) to consume them with filtered listeners, a per-store journal, payload redaction and an in-page panel:
|
|
@@ -95,4 +105,4 @@ MIT
|
|
|
95
105
|
|
|
96
106
|
## Publishing
|
|
97
107
|
|
|
98
|
-
Both packages (`pinia-plugin-subscription` and `pinia-plugin-subscription-devtools`) are published to npm via GitHub Actions on the same release. GitHub releases marked as pre-releases are published with the `beta` dist-tag
|
|
108
|
+
Both packages (`pinia-plugin-subscription` and `pinia-plugin-subscription-devtools`) are published to npm via GitHub Actions on the same release. GitHub releases marked as pre-releases are published with the `beta` dist-tag; stable releases use the default `latest` tag. The workflow runs `scripts/publish-unpublished.mjs`, which skips any package whose version is already on npm, so it can be safely re-run after a partial failure. It uses npm provenance for better supply-chain security and requires a `NPM_TOKEN` secret in the repository settings.
|