pinia-plugin-subscription 1.0.0-beta.12 → 1.0.0-beta.14

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 (45) hide show
  1. package/CHANGELOG.md +31 -7
  2. package/README.md +17 -4
  3. package/dist/chunks/trace-registry-Cm_2un0x.js +1009 -0
  4. package/dist/chunks/trace-registry-Cm_2un0x.js.map +1 -0
  5. package/dist/chunks/traceGroups-DfxYkUpm.js +105 -0
  6. package/dist/chunks/traceGroups-DfxYkUpm.js.map +1 -0
  7. package/dist/core/PluginSubscription.d.ts +16 -7
  8. package/dist/devtools/components.d.ts +40 -0
  9. package/dist/devtools/index.d.ts +9 -0
  10. package/dist/devtools/model.d.ts +17 -0
  11. package/dist/devtools/styles.d.ts +1 -0
  12. package/dist/devtools.js +377 -0
  13. package/dist/devtools.js.map +1 -0
  14. package/dist/factories/trace-listener.d.ts +6 -7
  15. package/dist/factories/trace-registry.d.ts +1 -1
  16. package/dist/helpers/index.d.ts +2 -2
  17. package/dist/helpers.js +50 -622
  18. package/dist/helpers.js.map +1 -1
  19. package/dist/pinia-plugin-subscription.js +44 -18
  20. package/dist/pinia-plugin-subscription.js.map +1 -1
  21. package/dist/system/TraceJournal.d.ts +6 -0
  22. package/dist/system/Tracer.d.ts +6 -2
  23. package/dist/types/devtools.d.ts +60 -0
  24. package/dist/types/index.d.ts +2 -2
  25. package/dist/types/plugin.d.ts +13 -0
  26. package/dist/types/trace.d.ts +79 -21
  27. package/dist/utils/constants.d.ts +2 -1
  28. package/dist/utils/store.d.ts +4 -1
  29. package/dist/utils/toSerializable.d.ts +10 -0
  30. package/dist/utils/traceContext.d.ts +7 -0
  31. package/dist/utils/traceGroups.d.ts +11 -7
  32. package/docs/authoring-plugins.md +24 -7
  33. package/docs/tracing.md +120 -27
  34. package/docs/using-plugins.md +29 -12
  35. package/package.json +11 -1
  36. package/dist/chunks/PluginSubscription-BbN48iuP.js +0 -636
  37. package/dist/chunks/PluginSubscription-BbN48iuP.js.map +0 -1
  38. package/dist/factories/console-trace-listener.d.ts +0 -7
  39. package/dist/system/log.d.ts +0 -28
  40. package/dist/types/comparison.d.ts +0 -3
  41. package/dist/types/list.d.ts +0 -13
  42. package/dist/types/log.d.ts +0 -8
  43. package/dist/types/resourceId.d.ts +0 -4
  44. package/dist/utils/Performance.d.ts +0 -9
  45. package/dist/utils/object.d.ts +0 -4
package/CHANGELOG.md CHANGED
@@ -7,12 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
- ### Changed
11
- - Console trace groups now prefer `payload.groupId` over the configured `groupBy` key; events sharing a key across overlapping groups are buffered until all those groups close, while events without an open group are printed immediately. See `docs/tracing.md`
12
- - `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
13
- - `storeOnActionSubscription` now receives the Pinia plugin context; action trace labels include the invoked action name
14
-
15
10
  ### Added
11
+ - `addScopesListener(scopes, context?, handler?)` accepts a custom trace handler; custom `handler` / `filter` listeners are the supported way to consume trace events, documented in `docs/tracing.md`
12
+ - `createPlugin(subscribers, { devtools: true })` automatically creates a redacting trace journal (or reuses the supplied registry journal), imports a conventional SSR snapshot, and dynamically mounts the in-page panel in development browsers; supports devtools options and is documented in `README.md` and `docs/tracing.md`
13
+ - `pinia-plugin-subscription/devtools`: `mountTraceDevtools(registry, options?)` mounts an in-page aside (Vue, Shadow DOM) reading the journal: per-store timeline with events grouped by action, client and server interleaved, filters, expandable payloads, and a Context tab; documented in `docs/tracing.md`
14
+ - `journal.serialize()` / `journal.import()` and `stringifyTraceSnapshot()` (helpers) 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 `createPlugin()` without handling it from the main module
15
+ - `createTracerRegistry({ journal, side })`: opt-in 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 `docs/tracing.md`
16
+ - 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
17
+ - 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
18
+ - 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
19
+ - Demo: `defineAStoreCtx` enhanced-store example; the demo app now resolves the package to `src/` through Vite aliases (no build needed)
20
+ - Added `pinia-plugin-subscription` to the package `keywords`
16
21
  - Added `addScopesListener(scopes, context?)` to `createTracerRegistry()` for grouping events from selected store scopes; documented in `docs/tracing.md`
17
22
  - `traceGroups` glossary, exported from `pinia-plugin-subscription/helpers`, building the `groupId` emitted by `PluginSubscription` (`onActionAfter`, `onActionError`, `onMutation`, `reset`); documented in `docs/tracing.md`
18
23
  - `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
@@ -21,10 +26,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
21
26
  - `createTracerRegistry({ redact })`: opt-in 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
22
27
  - `createTracerRegistry({ enabled })`: 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
23
28
  - Added `createTracerRegistry()` to create isolated trace listeners and tracers for each application or Pinia instance
24
- - Added `createTracerRegistry()` to group matching trace events in the console
25
29
  - Added the `Tracer` class and registry methods `addTraceListener()`, `clearTraceListeners()` and `hasTraceListeners()`
26
30
  - Added metadata-based trace filter criteria with `equals`, `contains`, `startsWith` and `endsWith` comparators, combined with `every` or `some`
27
- - Added `createConsoleTraceListener()` as an opt-in console sink for trace events
28
31
  - Added `trace()` and `traceError()` to `Store` and `PluginSubscription`
29
32
  - Added trace types: `TraceEvent`, `TraceEventMetadata`, `TraceFilter`, `TraceHandler`, `TraceLevel`, `TraceListener`, `TraceListenerRemover`, `TracePayload`, `TracerOptions`
30
33
  - Added `check:leaks` script and `scripts/check-dist-leaks.mjs`, guarding published artifacts against non-peer dependency imports in `dist/` (`.js` and `.d.ts`)
@@ -32,6 +35,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
32
35
  - Added unit tests covering the tracing system and the leak detection logic
33
36
 
34
37
  ### Changed
38
+ - **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
39
+ - 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`
40
+ - 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`
41
+ - Console trace groups now prefer `payload.groupId` over the configured `groupBy` key; events sharing a key across overlapping groups are buffered until all those groups close, while events without an open group are printed immediately. See `docs/tracing.md`
42
+ - `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
43
+ - `storeOnActionSubscription` now receives the Pinia plugin context; action trace labels include the invoked action name
44
+ - 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
35
45
  - Moved the demo application from `src/demo/` to the repository-level `demo/` directory, separating example code from the library source and tracking the demo files in version control.
36
46
  - Clarified that SSR tracing registries and plugin instances must be created per request, and added coverage for listener isolation between registries
37
47
  - Replaced the `Debug` abstract class with composition: `Store` and `PluginSubscription` no longer extend it and now own a `Tracer`
@@ -48,7 +58,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
48
58
  - `Tracer` listener matching no longer allocates intermediate arrays beyond the matched set, and duplicated unhandled-error reporting was factored out
49
59
  - The `pluginsubscription` namespace prefix is now a shared constant (`pluginSubscriptionNamespace`) instead of a hard-coded string
50
60
 
61
+ ### Documentation
62
+ - Added `demo/README.md` mapping each use case to its demo files and docs; documented the `pinia-plugin-subscription` topic in the Ecosystem section
63
+ - Reference implementation section lists the demo files and what each one illustrates; README links the demo and the `pinia-plugin-subscription` topic
64
+
51
65
  ### Fixed
66
+ - Devtools: the aside body now scrolls inside the aside (its scrollbar was out of reach under the page one)
67
+ - Devtools: traces emitted with the `store:reset:<id>` / `store:onMutation:<id>` group ids of pinia-plugin-extending-store are merged into the plugin `reset` / `onMutation` groups
68
+ - 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
69
+ - 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
70
+ - 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
71
+ - `defineAStoreSetup` now creates a separate setup context for each Pinia store instance, preventing enhanced-store extensions from being shared across SSR requests
72
+ - Demo plugin-added state now uses `Store.addToState()` so `pluginIsActive` is exposed and reactive on the Pinia store
73
+ - `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>()`
74
+ - Demo no longer depends on git-ignored `experiment/` files nor on `src/` imports, so it runs from a fresh clone; `codeError` now fails explicitly
52
75
  - `onAction`, `after` and `onError` subscription callbacks may now be asynchronous: rejections are traced instead of becoming unhandled, and their trace groups are closed once all async callbacks have settled
53
76
  - Group listener filters receive only trace metadata, redaction safely copies own `__proto__` keys, and registry group payload factories are skipped when no listeners are registered
54
77
  - Subscriber, subscription, action and rollback tracking keys now encode store IDs and names without delimiter collisions; disposing a store removes only its own tracking entries
@@ -66,6 +89,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66
89
  - **Breaking:** removed the legacy `debug` and `console` accessors from `Store` and `PluginSubscription`
67
90
  - Removed the internal `src/system/Debug.ts` abstract class (was never publicly exported)
68
91
  - **Breaking:** replaced module-global trace-listener functions with methods on a `createTracerRegistry()` instance
92
+ - Removed Performance monitoring utilities.
69
93
 
70
94
  ## [0.2.1]
71
95
 
package/README.md CHANGED
@@ -37,6 +37,8 @@ The package serves two audiences:
37
37
  | 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
38
  | Debug stores and plugins with structured trace events | [Tracing](docs/tracing.md) |
39
39
 
40
+ A runnable example lives in [`demo/`](demo/) (`npm run dev` for SPA mode or `npm run dev:ssr` for Vite SSR). The SSR example hydrates **one store from two environments**: a server-only subscriber loads request data (awaited before rendering and serializing Pinia state) and a client-only, deferred subscriber fills browser data after hydration, with a visual timeline; see the [reference implementation](docs/authoring-plugins.md#reference-implementation). Plugins built on this package are discoverable through the [`pinia-plugin-subscription` GitHub topic](https://github.com/topics/pinia-plugin-subscription).
41
+
40
42
  ## Installation
41
43
 
42
44
  ```bash
@@ -63,28 +65,39 @@ app.mount('#app')
63
65
 
64
66
  ## Advanced Features
65
67
 
66
- - **Structured tracing:** Subscribe to typed trace events and filter them at runtime, per store or per namespace. Group filters receive metadata only, and the built-in registry avoids preparing group payloads when it has no listeners — see [Tracing](#tracing).
67
- - **Scope-based trace listeners:** Use `addScopesListener()` to group events from selected stores — see [Tracing](docs/tracing.md#filtering-events).
68
+ - **Structured tracing:** Subscribe to typed trace events and filter them at runtime, per store or per namespace, and consume them with your own `handler` — see [Tracing](#tracing).
69
+ - **Scope-based trace listeners:** Use `addScopesListener(scopes, context?, handler?)` to receive events from selected stores — see [Tracing](docs/tracing.md#filtering-events).
70
+ - **Trace journal:** `createTracerRegistry({ journal: true })` records every event per store (with `actionId`, `seq` and `side`) so a store trace can be read back at any time — see [Tracing](docs/tracing.md#journal).
71
+ - **In-page trace panel:** enable it with `createPlugin(subscribers, { devtools: true })` in development, or mount it manually with `mountTraceDevtools()` (from `pinia-plugin-subscription/devtools`) — see [Tracing](docs/tracing.md#in-page-trace-panel).
68
72
  - **Reset callbacks:** Define `resetStoreCallback` to run custom logic when a store is reset.
69
73
  - **SSR and hydration control:** Configure whether each subscribed plugin runs on the server, the client, or only after client hydration.
70
74
  - **Lifecycle safety:** Internal hydration ordering is now guarded so `hydrate()` completes before `afterHydration()` and disposed stores do not retain stale subscriber metadata.
71
75
 
72
76
  ## Tracing
73
77
 
74
- A built-in, opt-in debugging solution: plugins and stores emit structured trace events that you select with filters, optionally redact, and group in the console. It is disabled by default in production builds and costs nothing when unused.
78
+ A built-in, opt-in debugging solution: plugins and stores emit structured trace events that you select with filters, optionally redact, and consume with your own handler (or inspect in the devtools panel). The package no longer prints traces to the console itself. It is disabled by default in production builds and costs nothing when unused.
75
79
 
76
80
  ```ts
77
81
  import { createPlugin } from 'pinia-plugin-subscription'
78
82
  import { createTracerRegistry } from 'pinia-plugin-subscription/helpers'
79
83
 
80
84
  const registry = createTracerRegistry({ redact: true })
81
- registry.addListener([{ target: 'scope', value: 'cart' }])
85
+ registry.addListener({
86
+ filter: [{ target: 'scope', value: 'cart' }],
87
+ handler: event => console.log(event.label, event.payload)
88
+ })
82
89
 
83
90
  pinia.use(createPlugin(subscribers, { tracerHandler: registry.tracerHandler }))
84
91
  ```
85
92
 
86
93
  See the [Tracing documentation](docs/tracing.md) for filtering, redaction, production safety, event shape and error reporting.
87
94
 
95
+ For a development-only in-page trace panel, no separate registry or devtools import is needed. If the page contains a JSON script with the default ID `pinia-traces`, its SSR journal snapshot is imported automatically:
96
+
97
+ ```ts
98
+ pinia.use(createPlugin(subscribers, { devtools: true }))
99
+ ```
100
+
88
101
  ## License
89
102
 
90
103
  MIT