pinia-plugin-subscription 1.0.0-beta.13 → 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 (53) hide show
  1. package/CHANGELOG.md +14 -2
  2. package/README.md +15 -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 +13 -12
  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 -638
  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 +6 -0
  26. package/dist/types/trace.d.ts +79 -21
  27. package/dist/utils/constants.d.ts +2 -1
  28. package/dist/utils/toSerializable.d.ts +10 -0
  29. package/dist/utils/traceContext.d.ts +7 -0
  30. package/dist/utils/traceGroups.d.ts +11 -7
  31. package/docs/authoring-plugins.md +2 -2
  32. package/docs/tracing.md +119 -28
  33. package/docs/using-plugins.md +17 -12
  34. package/package.json +9 -1
  35. package/dist/chunks/PluginSubscription-Bkqj4uSK.js +0 -662
  36. package/dist/chunks/PluginSubscription-Bkqj4uSK.js.map +0 -1
  37. package/dist/factories/console-trace-listener.d.ts +0 -7
  38. package/dist/system/log/console-group.d.ts +0 -8
  39. package/dist/system/log/console.d.ts +0 -18
  40. package/dist/system/log/index.d.ts +0 -2
  41. package/dist/system/log/log-trace.d.ts +0 -8
  42. package/dist/system/log/print-array.d.ts +0 -7
  43. package/dist/system/log/print-error.d.ts +0 -6
  44. package/dist/system/log/print-object.d.ts +0 -1
  45. package/dist/system/log/print-trace-payload.d.ts +0 -1
  46. package/dist/system/log/print-trace.d.ts +0 -9
  47. package/dist/system/log/trace-console.d.ts +0 -9
  48. package/dist/types/comparison.d.ts +0 -3
  49. package/dist/types/list.d.ts +0 -13
  50. package/dist/types/log.d.ts +0 -8
  51. package/dist/types/resourceId.d.ts +0 -4
  52. package/dist/utils/Performance.d.ts +0 -9
  53. package/dist/utils/object.d.ts +0 -4
package/CHANGELOG.md CHANGED
@@ -8,6 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
8
8
  ## [Unreleased]
9
9
 
10
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`
11
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
12
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
13
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
@@ -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,9 @@ 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`
35
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`
36
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
37
43
  - `storeOnActionSubscription` now receives the Pinia plugin context; action trace labels include the invoked action name
@@ -57,6 +63,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
57
63
  - Reference implementation section lists the demo files and what each one illustrates; README links the demo and the `pinia-plugin-subscription` topic
58
64
 
59
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
60
71
  - `defineAStoreSetup` now creates a separate setup context for each Pinia store instance, preventing enhanced-store extensions from being shared across SSR requests
61
72
  - Demo plugin-added state now uses `Store.addToState()` so `pluginIsActive` is exposed and reactive on the Pinia store
62
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>()`
@@ -78,6 +89,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
78
89
  - **Breaking:** removed the legacy `debug` and `console` accessors from `Store` and `PluginSubscription`
79
90
  - Removed the internal `src/system/Debug.ts` abstract class (was never publicly exported)
80
91
  - **Breaking:** replaced module-global trace-listener functions with methods on a `createTracerRegistry()` instance
92
+ - Removed Performance monitoring utilities.
81
93
 
82
94
  ## [0.2.1]
83
95
 
package/README.md CHANGED
@@ -65,28 +65,39 @@ app.mount('#app')
65
65
 
66
66
  ## Advanced Features
67
67
 
68
- - **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).
69
- - **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).
70
72
  - **Reset callbacks:** Define `resetStoreCallback` to run custom logic when a store is reset.
71
73
  - **SSR and hydration control:** Configure whether each subscribed plugin runs on the server, the client, or only after client hydration.
72
74
  - **Lifecycle safety:** Internal hydration ordering is now guarded so `hydrate()` completes before `afterHydration()` and disposed stores do not retain stale subscriber metadata.
73
75
 
74
76
  ## Tracing
75
77
 
76
- 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.
77
79
 
78
80
  ```ts
79
81
  import { createPlugin } from 'pinia-plugin-subscription'
80
82
  import { createTracerRegistry } from 'pinia-plugin-subscription/helpers'
81
83
 
82
84
  const registry = createTracerRegistry({ redact: true })
83
- 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
+ })
84
89
 
85
90
  pinia.use(createPlugin(subscribers, { tracerHandler: registry.tracerHandler }))
86
91
  ```
87
92
 
88
93
  See the [Tracing documentation](docs/tracing.md) for filtering, redaction, production safety, event shape and error reporting.
89
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
+
90
101
  ## License
91
102
 
92
103
  MIT