pinia-plugin-subscription 1.0.0-beta.13 → 1.0.0-beta.15
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 +29 -12
- package/CONTRIBUTING.md +10 -1
- package/README.md +11 -9
- package/SECURITY.md +2 -2
- package/dist/chunks/{PluginSubscription-Bkqj4uSK.js → PluginSubscription-GJDsym1O.js} +253 -247
- package/dist/core/PluginSubscriber.d.ts +1 -1
- package/dist/core/PluginSubscription.d.ts +13 -12
- package/dist/core/Store.d.ts +1 -1
- package/dist/helpers/index.d.ts +0 -4
- package/dist/helpers.js +56 -651
- package/dist/pinia-plugin-subscription.js +4 -5
- package/dist/system/TraceEmitter.d.ts +1 -2
- package/dist/types/index.d.ts +1 -2
- package/dist/types/plugin.d.ts +2 -3
- package/dist/types/trace.d.ts +30 -109
- package/dist/utils/traceGroups.d.ts +9 -7
- package/docs/authoring-plugins.md +13 -7
- package/docs/using-plugins.md +28 -19
- package/package.json +9 -4
- package/dist/chunks/PluginSubscription-Bkqj4uSK.js.map +0 -1
- package/dist/factories/console-trace-listener.d.ts +0 -7
- package/dist/factories/trace-listener.d.ts +0 -10
- package/dist/factories/trace-registry.d.ts +0 -2
- package/dist/helpers.js.map +0 -1
- package/dist/pinia-plugin-subscription.js.map +0 -1
- package/dist/system/Tracer.d.ts +0 -23
- package/dist/system/log/console-group.d.ts +0 -8
- package/dist/system/log/console.d.ts +0 -18
- package/dist/system/log/index.d.ts +0 -2
- package/dist/system/log/log-trace.d.ts +0 -8
- package/dist/system/log/print-array.d.ts +0 -7
- package/dist/system/log/print-error.d.ts +0 -6
- package/dist/system/log/print-object.d.ts +0 -1
- package/dist/system/log/print-trace-payload.d.ts +0 -1
- package/dist/system/log/print-trace.d.ts +0 -9
- package/dist/system/log/trace-console.d.ts +0 -9
- 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/environment.d.ts +0 -7
- package/dist/utils/object.d.ts +0 -4
- package/dist/utils/redact.d.ts +0 -15
- package/docs/tracing.md +0 -185
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { P as i } from "./chunks/PluginSubscription-
|
|
2
|
-
import { p as d, d as s, b,
|
|
1
|
+
import { P as i } from "./chunks/PluginSubscription-GJDsym1O.js";
|
|
2
|
+
import { p as d, d as s, a as b, b as l } from "./chunks/PluginSubscription-GJDsym1O.js";
|
|
3
3
|
function u(r, n) {
|
|
4
4
|
const e = new i(r, n);
|
|
5
5
|
return e.plugin.bind(e);
|
|
6
6
|
}
|
|
7
|
-
function
|
|
7
|
+
function o(r, n) {
|
|
8
8
|
const e = new i(r, {
|
|
9
9
|
execution: n?.execution,
|
|
10
10
|
hydrationScheduler: n?.hydrationScheduler,
|
|
@@ -15,10 +15,9 @@ function c(r, n) {
|
|
|
15
15
|
}
|
|
16
16
|
export {
|
|
17
17
|
d as PLUGIN_NAME,
|
|
18
|
-
|
|
18
|
+
o as createHydrationPlugin,
|
|
19
19
|
u as createPlugin,
|
|
20
20
|
s as defineAStore,
|
|
21
21
|
b as defineAStoreCtx,
|
|
22
22
|
l as getEnhancedStore
|
|
23
23
|
};
|
|
24
|
-
//# sourceMappingURL=pinia-plugin-subscription.js.map
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type Tracer from '
|
|
2
|
-
import type { TracePayload } from '../types/trace';
|
|
1
|
+
import type { TracePayload, Tracer } from '../types/trace';
|
|
3
2
|
/**
|
|
4
3
|
* Base class for objects emitting structured trace events.
|
|
5
4
|
* Subclasses provide `_className` and may override `tracer` to build it lazily.
|
package/dist/types/index.d.ts
CHANGED
|
@@ -26,8 +26,7 @@ export type StyleDefinitions = Record<LogType, Record<StyleDefinitionKeys, strin
|
|
|
26
26
|
export type ConsoleStyleDefinition = StyleDefinition;
|
|
27
27
|
export type ConsoleStyleDefinitionKeys = StyleDefinitionKeys;
|
|
28
28
|
export type ConsoleStyleDefinitions = StyleDefinitions;
|
|
29
|
-
export type {
|
|
30
|
-
export type { TraceEvent, TraceEventMetadata, TraceFilter, TraceHandler, TraceLevel, TraceListener, TraceListenerRemover, TracePayload, TraceRedactOptions, TraceRegistry, TracerOptions, TracerRegistryOptions } from './trace';
|
|
29
|
+
export type { TraceEvent, TraceEventMetadata, TraceHandler, TraceLevel, TracePayload, TraceSide, Tracer, TracerHandler } from './trace';
|
|
31
30
|
export type { CustomStore, DefineAStoreSetupContext, DefineAStoreSetupExtensions, EmptyExtensions, RollbackActionParams, RollbackAfterFailureParams, StatePropertyValue, StoreOptions, StoreOptionsPropertyValue } from './store';
|
|
32
31
|
export type { NativePiniaSubscription, NativePiniaSubscriptionReturn, PluginExecutionEnvironment, PluginExecutionOptions, PluginHydrationTiming, PluginRuntimeEnvironment, PluginStoreOptions, PluginSubscriberInvoke, PluginHydrationScheduler, PluginSubscription, PluginSubscriptionOptions, PluginSubscriptions, StoreClassConstructorParams, StoreMutationSubscription, StoreMutationSubscriptionCallback, StoreMutationSubscriptionReturn, StoreOnActionCallbackParameters, StoreOnActionSubscription, StoreOnActionSubscriptionCallback, StoreOnActionSubscriptionReturn, } from './plugin';
|
|
33
32
|
export type { PluginSubscriberInterface };
|
package/dist/types/plugin.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { PiniaPluginContext, StateTree, Store, SubscriptionCallbackMutation } from "pinia";
|
|
2
2
|
import type { StoreOptions } from "./store";
|
|
3
3
|
import type { PluginSubscriberInterface } from ".";
|
|
4
|
-
import Tracer from "
|
|
5
|
-
import type { TracerHandler } from "./trace";
|
|
4
|
+
import type { Tracer, TracerHandler } from "./trace";
|
|
6
5
|
export type CreateStateSnapshotKeys = (keyof StateTree)[] | 'all';
|
|
7
6
|
export type PluginHydrationScheduler = (callback: () => void) => void;
|
|
8
7
|
export type PluginHydrationTiming = 'defer' | 'immediate';
|
|
@@ -30,7 +29,7 @@ export interface PluginStoreOptions {
|
|
|
30
29
|
export interface PluginSubscriptionOptions {
|
|
31
30
|
/**
|
|
32
31
|
* Tracer handler for the plugin subscriber.
|
|
33
|
-
*
|
|
32
|
+
* Provided by a tracing package such as `pinia-plugin-subscription-devtools`; tracing is inactive without it.
|
|
34
33
|
*/
|
|
35
34
|
tracerHandler?: TracerHandler;
|
|
36
35
|
/**
|
package/dist/types/trace.d.ts
CHANGED
|
@@ -1,20 +1,4 @@
|
|
|
1
1
|
import type { AnyObject } from './index';
|
|
2
|
-
import type Tracer from '../system/Tracer';
|
|
3
|
-
export interface AddTraceListenerOptions {
|
|
4
|
-
context?: boolean;
|
|
5
|
-
filterMode?: TraceListenerFilterMode;
|
|
6
|
-
groupBy?: TraceListenerGroupBy;
|
|
7
|
-
}
|
|
8
|
-
export interface ConsoleTraceEventArgs extends Omit<TraceEvent, 'level' | 'timestamp'> {
|
|
9
|
-
}
|
|
10
|
-
export type ConsoleTraceEvent = Array<string | ConsoleTraceEventArgs>;
|
|
11
|
-
/**
|
|
12
|
-
* A trace listener that supports grouping of trace events.
|
|
13
|
-
*/
|
|
14
|
-
export interface ConsoleTraceGroupListener extends Omit<TraceListener, 'filter'> {
|
|
15
|
-
createGroup: (key: string) => void;
|
|
16
|
-
logGroup: (key: string) => void;
|
|
17
|
-
}
|
|
18
2
|
/**
|
|
19
3
|
* Severity of a trace event.
|
|
20
4
|
* `error` events are delivered to matching listeners, or reported with `console.error` when none match.
|
|
@@ -25,7 +9,12 @@ export type TraceLevel = 'debug' | 'error';
|
|
|
25
9
|
* Filters receive this object so that discarded events never allocate a payload.
|
|
26
10
|
*/
|
|
27
11
|
export interface TraceEventMetadata {
|
|
28
|
-
/** Identifier
|
|
12
|
+
/** Identifier of the store action this event belongs to, shared by every event of the same action. */
|
|
13
|
+
actionId?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Group (lifecycle) this event belongs to. It is a `/` separated path whose prefixes are the parent groups,
|
|
16
|
+
* e.g. `cart/onAction:add#3/after`, see `traceGroups`.
|
|
17
|
+
*/
|
|
29
18
|
groupId?: string;
|
|
30
19
|
/** Label describing the event, e.g. `Subscription:Delivery`. */
|
|
31
20
|
label: string;
|
|
@@ -44,117 +33,49 @@ export interface TraceEventMetadata {
|
|
|
44
33
|
export interface TraceEvent extends TraceEventMetadata {
|
|
45
34
|
error?: unknown;
|
|
46
35
|
payload?: AnyObject;
|
|
36
|
+
/** Monotonic position of the event in its registry. Set when a journal is enabled. */
|
|
37
|
+
seq?: number;
|
|
38
|
+
/** Environment that emitted the event. Set when a journal is enabled. */
|
|
39
|
+
side?: TraceSide;
|
|
47
40
|
timestamp: number;
|
|
48
41
|
}
|
|
49
|
-
/**
|
|
50
|
-
export type
|
|
51
|
-
type TraceFilterCriterionComparator = 'equals' | 'contains' | 'startsWith' | 'endsWith';
|
|
52
|
-
export interface TraceFilterCriterion {
|
|
53
|
-
comparator: TraceFilterCriterionComparator;
|
|
54
|
-
target: keyof TraceEventMetadata;
|
|
55
|
-
value: string;
|
|
56
|
-
}
|
|
57
|
-
export interface TraceFilterFactoryCriterion extends Omit<TraceFilterCriterion, 'comparator'> {
|
|
58
|
-
comparator?: TraceFilterCriterionComparator;
|
|
59
|
-
}
|
|
60
|
-
export type TraceFilterFactoryParam = {
|
|
61
|
-
handler?: TraceHandler;
|
|
62
|
-
filter: TraceFilter | TraceFilterFactoryCriterion[];
|
|
63
|
-
};
|
|
42
|
+
/** Environment that emitted a trace event. */
|
|
43
|
+
export type TraceSide = 'client' | 'server';
|
|
64
44
|
/**
|
|
65
45
|
* Event data. Prefer the function form: it is only invoked when a listener
|
|
66
46
|
* actually consumes the event, keeping unobserved tracing allocation free.
|
|
67
47
|
*/
|
|
68
48
|
export type TracePayload = AnyObject | (() => AnyObject);
|
|
69
|
-
/**
|
|
70
|
-
* Determines whether a trace event should be delivered to a listener.
|
|
71
|
-
* @param event The metadata of the trace event.
|
|
72
|
-
* @returns `true` if the event should be delivered to the listener, otherwise `false`.
|
|
73
|
-
*/
|
|
74
|
-
export type TraceFilter = (event: TraceEventMetadata) => boolean;
|
|
75
|
-
export interface TraceGroupListener extends ConsoleTraceGroupListener, Pick<TraceListener, 'filter'> {
|
|
76
|
-
groupBy: TraceListenerGroupBy;
|
|
77
|
-
}
|
|
78
49
|
/**
|
|
79
50
|
* Handles a trace event.
|
|
80
51
|
* @param event The resolved trace event to handle.
|
|
81
52
|
*/
|
|
82
53
|
export type TraceHandler = (event: TraceEvent) => void;
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
54
|
+
/**
|
|
55
|
+
* Emits structured trace events. Implemented by tracing packages such as `pinia-plugin-subscription-devtools`.
|
|
56
|
+
* The plugin only emits: it never reads, stores or displays events.
|
|
57
|
+
*/
|
|
58
|
+
export interface Tracer {
|
|
59
|
+
/** Instance the emitted events belong to, usually a Pinia `store.$id`. */
|
|
60
|
+
scope?: string;
|
|
61
|
+
readonly source: string;
|
|
62
|
+
debug: (label: string, namespace: string, payload?: TracePayload, scope?: string) => void;
|
|
63
|
+
error: (label: string, namespace: string, error: unknown, payload?: TracePayload, scope?: string) => void;
|
|
88
64
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
export type TraceRegistry = {
|
|
94
|
-
/**
|
|
95
|
-
* Registers a trace listener and returns its remover.
|
|
96
|
-
* Listeners are evaluated in registration order.
|
|
97
|
-
* @param listenerDef The listener definition or filter criteria.
|
|
98
|
-
* @param options Context, filter mode and grouping options.
|
|
99
|
-
* @returns A function that removes the registered listener when called.
|
|
100
|
-
*/
|
|
101
|
-
addListener: (listenerDef: TraceFilterFactoryParam | TraceFilterFactoryCriterion[], options?: AddTraceListenerOptions) => TraceListenerRemover;
|
|
102
|
-
/**
|
|
103
|
-
* Registers a listener for the specified scopes and returns its remover.
|
|
104
|
-
* @param scopes The scopes to listen for.
|
|
105
|
-
* @param context Whether to print the plugin context to the console. Defaults to true.
|
|
106
|
-
* @returns A function that removes the registered listener when called.
|
|
107
|
-
*/
|
|
108
|
-
addScopesListener: (scopes: string[], context?: boolean) => TraceListenerRemover;
|
|
109
|
-
/**
|
|
110
|
-
* Clears all registered trace listeners.
|
|
111
|
-
*/
|
|
112
|
-
clearTraceListeners: () => void;
|
|
113
|
-
/**
|
|
114
|
-
* Checks if there are any registered trace listeners.
|
|
115
|
-
* @returns True if there are registered trace listeners, otherwise false.
|
|
116
|
-
*/
|
|
117
|
-
hasTraceListeners: () => boolean;
|
|
118
|
-
/** Handler to pass to the plugin through `PluginSubscriptionOptions.tracerHandler`. */
|
|
119
|
-
tracerHandler: TracerHandler;
|
|
120
|
-
};
|
|
65
|
+
/**
|
|
66
|
+
* Contract between the plugin and a tracing package, passed through `PluginSubscriptionOptions.tracerHandler`.
|
|
67
|
+
* Without a handler, tracing is inactive and costs nothing.
|
|
68
|
+
*/
|
|
121
69
|
export interface TracerHandler {
|
|
122
|
-
/**
|
|
70
|
+
/** Closes the group of the event's group key. */
|
|
123
71
|
closeGroup: (payload: TraceEvent) => void;
|
|
124
72
|
/**
|
|
125
73
|
* Creates a new tracer instance.
|
|
126
74
|
* @param source The source of the tracer, usually the class name.
|
|
127
|
-
* @param options Optional tracer options.
|
|
128
75
|
*/
|
|
129
|
-
createTracer: (source: string
|
|
130
|
-
/** Reports whether this handler currently
|
|
76
|
+
createTracer: (source: string) => Tracer;
|
|
77
|
+
/** Reports whether this handler currently consumes events. Lets the plugin skip building them when `false`. */
|
|
131
78
|
hasTraceListeners?: () => boolean;
|
|
132
|
-
/** Opens a group for the event's group key
|
|
79
|
+
/** Opens a group for the event's group key. */
|
|
133
80
|
startGroup: (payload: TraceEvent) => void;
|
|
134
81
|
}
|
|
135
|
-
export interface TraceRedactOptions {
|
|
136
|
-
/** Replaces the default key list instead of extending it when `false`. Defaults to `true`. */
|
|
137
|
-
includeDefaults?: boolean;
|
|
138
|
-
/** Additional keys to mask: strings match exactly (case-insensitive), regular expressions match anywhere in the key. */
|
|
139
|
-
keys?: Array<string | RegExp>;
|
|
140
|
-
/** Value substituted for masked values. Defaults to `[REDACTED]`. */
|
|
141
|
-
replacement?: string;
|
|
142
|
-
}
|
|
143
|
-
export interface TracerRegistryOptions {
|
|
144
|
-
/**
|
|
145
|
-
* Whether listeners can be registered. When `false`, `addListener()` is a no-op and tracing stays inactive.
|
|
146
|
-
* Defaults to `false` in production builds (`process.env.NODE_ENV === 'production'`), `true` otherwise.
|
|
147
|
-
*/
|
|
148
|
-
enabled?: boolean;
|
|
149
|
-
/**
|
|
150
|
-
* Masks sensitive values (passwords, tokens, secrets...) of event payloads before they reach any listener.
|
|
151
|
-
* Opt-in: `true` uses the default key list, an object customizes it. Redaction works on a copy.
|
|
152
|
-
*/
|
|
153
|
-
redact?: boolean | TraceRedactOptions;
|
|
154
|
-
}
|
|
155
|
-
export interface TracerOptions {
|
|
156
|
-
/** Transforms the resolved payload before it is delivered to listeners. */
|
|
157
|
-
redactor?: (payload: AnyObject) => AnyObject;
|
|
158
|
-
scope?: string;
|
|
159
|
-
}
|
|
160
|
-
export {};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
export declare const traceGroups: {
|
|
2
|
+
onAction: (storeId: string, actionName: string, callId: number) => string;
|
|
3
|
+
onActionAfter: (storeId: string, actionName: string, callId: number) => string;
|
|
4
|
+
onActionError: (storeId: string, actionName: string, callId: number) => string;
|
|
5
|
+
onMutation: (storeId: string, callId: number) => string;
|
|
6
|
+
plugin: (storeId: string) => string;
|
|
7
|
+
pluginDeferred: (storeId: string, subscriberName: string, callId: number) => string;
|
|
8
|
+
reset: (storeId: string, callId: number) => string;
|
|
9
|
+
};
|
|
@@ -400,13 +400,19 @@ class CartStore extends Store {
|
|
|
400
400
|
}
|
|
401
401
|
```
|
|
402
402
|
|
|
403
|
-
`
|
|
404
|
-
`pinia-plugin-subscription/
|
|
405
|
-
`
|
|
406
|
-
`
|
|
403
|
+
The plugin only emits events: it provides the `Tracer` and `TracerHandler`
|
|
404
|
+
types (from `pinia-plugin-subscription/types`) and ignores tracing when no
|
|
405
|
+
`tracerHandler` is configured. Consuming events is the job of the separate
|
|
406
|
+
`pinia-plugin-subscription-devtools` package, which provides
|
|
407
|
+
`createTracerRegistry()`. Register event criteria with `addListener()` (with
|
|
408
|
+
your own `handler`) and pass the registry's `tracerHandler` through
|
|
409
|
+
`createPlugin()` options to consume plugin and store events.
|
|
407
410
|
Criteria target event metadata and support `equals`, `contains`, `startsWith`
|
|
408
|
-
and `endsWith` comparisons. See the
|
|
409
|
-
|
|
411
|
+
and `endsWith` comparisons. See the
|
|
412
|
+
[Tracing documentation](../packages/devtools/docs/tracing.md) for filtering,
|
|
413
|
+
redaction, production safety and error reporting. To test your plugin's
|
|
414
|
+
traces, install it as a development dependency, or provide a minimal
|
|
415
|
+
`TracerHandler` of your own.
|
|
410
416
|
|
|
411
417
|
## Typing per-store options: `StoreOptionsExtensions` (TypeScript)
|
|
412
418
|
|
|
@@ -580,7 +586,7 @@ resolve the package to `src/`, so no build is needed. See also
|
|
|
580
586
|
| Environment-aware hydration | [`demo/plugins/demoPluginEnvironmentHydration.ts`](../demo/plugins/demoPluginEnvironmentHydration.ts), [`demo/core/VisitorEnvironmentStore.ts`](../demo/core/VisitorEnvironmentStore.ts), [`demo/stores/visitor-environment.ts`](../demo/stores/visitor-environment.ts), [`demo/entry-server.ts`](../demo/entry-server.ts) | One store hydrated by a server-only subscriber (awaited before render and serialization) and a client-only `hydration: 'defer'` subscriber; each is skipped in the other environment; traces via `Store.trace()` and the `onMutation` group |
|
|
581
587
|
| Enhanced store | [`demo/stores/enhanced-store.ts`](../demo/stores/enhanced-store.ts), [`demo/components/EnhancedExample.vue`](../demo/components/EnhancedExample.vue) | `defineAStoreCtx` + `getEnhancedStore` consuming the `DemoStore` augmentations |
|
|
582
588
|
| Option typing | [`demo/types/plugin.ts`](../demo/types/plugin.ts) | Extending `StoreOptions` with plugin options |
|
|
583
|
-
| Registration & tracing | [`demo/
|
|
589
|
+
| Registration & tracing | [`demo/app.ts`](../demo/app.ts) | `createPlugin()` with several subscribers, `createTraceDevtools()` from `pinia-plugin-subscription-devtools` |
|
|
584
590
|
| Rollback | [`demo/stores/rollback-snapshot.ts`](../demo/stores/rollback-snapshot.ts), [`demo/components/Example.vue`](../demo/components/Example.vue) | `rollbackAfterFailure` option vs manual `$rollbackAfterFailure()` |
|
|
585
591
|
|
|
586
592
|
Open the browser console to see the trace output of the
|
package/docs/using-plugins.md
CHANGED
|
@@ -22,8 +22,9 @@ Plugins built on `pinia-plugin-subscription` share a common contract:
|
|
|
22
22
|
- **`$reset` on registered stores** — every store registered by the plugin
|
|
23
23
|
gains a `$reset()` method that restores its initial state, including
|
|
24
24
|
setup-style stores where pinia does not provide one natively.
|
|
25
|
-
- **Runtime-filtered tracing** —
|
|
26
|
-
source, namespace, scope, or
|
|
25
|
+
- **Runtime-filtered tracing** — with `pinia-plugin-subscription-devtools`,
|
|
26
|
+
register trace listeners and filter events by source, namespace, scope, or
|
|
27
|
+
level.
|
|
27
28
|
- **SSR-safe execution** — each plugin declares where (`client`, `server`
|
|
28
29
|
or `both`) and when (`immediate` or deferred after hydration) it runs.
|
|
29
30
|
- **State rollback on action failure** — actions listed in the
|
|
@@ -325,41 +326,49 @@ try {
|
|
|
325
326
|
|
|
326
327
|
## Tracing
|
|
327
328
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
329
|
+
Tracing is provided by the separate `pinia-plugin-subscription-devtools`
|
|
330
|
+
package (`npm install -D pinia-plugin-subscription-devtools`); the plugin
|
|
331
|
+
emits nothing without it. See its
|
|
332
|
+
[Tracing documentation](../packages/devtools/docs/tracing.md) for the full
|
|
333
|
+
guide. Tracing is disabled by default in production builds and can mask
|
|
334
|
+
sensitive payload keys with `createTracerRegistry({ redact: true })`.
|
|
331
335
|
|
|
332
336
|
Register listeners independently from plugin construction:
|
|
333
337
|
|
|
334
338
|
```js
|
|
335
339
|
import {
|
|
336
340
|
createTracerRegistry
|
|
337
|
-
} from 'pinia-plugin-subscription
|
|
341
|
+
} from 'pinia-plugin-subscription-devtools'
|
|
338
342
|
import {
|
|
339
343
|
createPlugin
|
|
340
344
|
} from 'pinia-plugin-subscription'
|
|
341
345
|
|
|
342
346
|
const traceGroupsRegistry = createTracerRegistry()
|
|
343
347
|
|
|
344
|
-
traceGroupsRegistry.addListener(
|
|
345
|
-
{ target: 'scope', value: 'cart' }
|
|
346
|
-
|
|
348
|
+
traceGroupsRegistry.addListener({
|
|
349
|
+
filter: [{ target: 'scope', value: 'cart' }],
|
|
350
|
+
handler: event => myLogger.debug(event)
|
|
351
|
+
})
|
|
347
352
|
|
|
348
353
|
pinia.use(createPlugin([myStoreSubscriber], {
|
|
349
354
|
tracerHandler: traceGroupsRegistry.tracerHandler
|
|
350
355
|
}))
|
|
351
356
|
```
|
|
352
357
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
358
|
+
Criteria can target a source, namespace, store scope, or trace level and
|
|
359
|
+
support the `equals`, `contains`, `startsWith` and `endsWith` comparators.
|
|
360
|
+
Criteria use `every` by default; pass `{ filterMode: 'some' }` to match any
|
|
361
|
+
criterion. The `handler` receives every matching event; nothing is printed
|
|
362
|
+
to the console by the package.
|
|
357
363
|
|
|
358
364
|
```js
|
|
359
|
-
traceGroupsRegistry.addListener(
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
365
|
+
traceGroupsRegistry.addListener({
|
|
366
|
+
filter: [
|
|
367
|
+
{ target: 'scope', value: 'cart' },
|
|
368
|
+
{ target: 'namespace', comparator: 'startsWith', value: 'pluginsubscription:subscription:' }
|
|
369
|
+
],
|
|
370
|
+
handler: event => myLogger.debug(event)
|
|
371
|
+
}, { filterMode: 'every' })
|
|
363
372
|
```
|
|
364
373
|
|
|
365
374
|
## SSR / Nuxt
|
|
@@ -379,7 +388,7 @@ finishes.
|
|
|
379
388
|
import { createSSRApp } from 'vue'
|
|
380
389
|
import { createPinia } from 'pinia'
|
|
381
390
|
import { createPlugin } from 'pinia-plugin-subscription'
|
|
382
|
-
import { createTracerRegistry } from 'pinia-plugin-subscription
|
|
391
|
+
import { createTracerRegistry } from 'pinia-plugin-subscription-devtools'
|
|
383
392
|
import App from './App.vue'
|
|
384
393
|
import { subscribers } from './subscribers'
|
|
385
394
|
|
|
@@ -388,7 +397,7 @@ export function createRequestApp(traceCriteria) {
|
|
|
388
397
|
const pinia = createPinia()
|
|
389
398
|
const traceGroupsRegistry = createTracerRegistry()
|
|
390
399
|
|
|
391
|
-
traceGroupsRegistry.addListener(traceCriteria)
|
|
400
|
+
traceGroupsRegistry.addListener({ filter: traceCriteria, handler: logTrace })
|
|
392
401
|
pinia.use(createPlugin(subscribers, {
|
|
393
402
|
tracerHandler: traceGroupsRegistry.tracerHandler
|
|
394
403
|
}))
|
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.15",
|
|
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,
|
|
@@ -71,8 +71,9 @@
|
|
|
71
71
|
"dev:library": "vite",
|
|
72
72
|
"test": "vitest",
|
|
73
73
|
"coverage": "vitest run --coverage",
|
|
74
|
-
"build": "vitest
|
|
75
|
-
"
|
|
74
|
+
"build": "vitest run && npm run build:library && npm run build -w pinia-plugin-subscription-devtools",
|
|
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",
|
|
76
77
|
"bundle:check": "vite build --config vite.config.ts && node scripts/measure-bundle.mjs",
|
|
77
78
|
"build:demo": "vite --config vite.demo.config.ts build",
|
|
78
79
|
"preview": "vite preview --config vite.demo.config.ts"
|
|
@@ -94,6 +95,7 @@
|
|
|
94
95
|
"@vitejs/plugin-vue": "^6.0.1",
|
|
95
96
|
"@vitest/coverage-v8": "^4.0.15",
|
|
96
97
|
"@vue/tsconfig": "^0.8.1",
|
|
98
|
+
"jsdom": "^30.1.3",
|
|
97
99
|
"pinia": "^3.0.2",
|
|
98
100
|
"pinia-plugin-extending-store": "^0.1.6-beta.2",
|
|
99
101
|
"typescript": "~5.9.3",
|
|
@@ -101,5 +103,8 @@
|
|
|
101
103
|
"vitest": "^4.0.15",
|
|
102
104
|
"vue": "^3.5.24",
|
|
103
105
|
"vue-tsc": "^3.1.4"
|
|
104
|
-
}
|
|
106
|
+
},
|
|
107
|
+
"workspaces": [
|
|
108
|
+
"packages/*"
|
|
109
|
+
]
|
|
105
110
|
}
|