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
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare const PLUGIN: {
|
|
2
|
+
EXECUTION: {
|
|
3
|
+
END: string;
|
|
4
|
+
ERROR: string;
|
|
5
|
+
START: string;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
export declare const ORCHESTRATOR_PREFIX = "PPS";
|
|
9
|
+
export declare const STORE: {
|
|
10
|
+
ACTION_AFTER: string;
|
|
11
|
+
ACTION_BEFORE: string;
|
|
12
|
+
ACTION_ERROR: string;
|
|
13
|
+
ACTION_ON_ERROR: string;
|
|
14
|
+
DISPOSE: string;
|
|
15
|
+
MUTATION: string;
|
|
16
|
+
RESET: string;
|
|
17
|
+
};
|
|
18
|
+
export declare const SUBSCRIBER: {
|
|
19
|
+
INVOKED: string;
|
|
20
|
+
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type { PluginSubscriptions, StoreClassConstructorParams, StoreMutationSubscription, StoreMutationSubscriptionCallback, StoreOnActionSubscription, StoreOnActionSubscriptionCallback } from "../types/plugin";
|
|
1
|
+
import TraceableStoreEventsSubscriber from "../tracing/TraceableStoreEventsSubscriber";
|
|
3
2
|
import type { Store as PiniaStore, StateTree } from "pinia";
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
3
|
+
import type { AnyObject, StoreSubscriberInterface } from "../types";
|
|
4
|
+
import type { PluginSubscriptions, EnhancedStoreOptions, StoreMutationSubscription, StoreMutationSubscriptionCallback, StoreOnActionSubscription, StoreOnActionSubscriptionCallback } from "../types/plugin";
|
|
6
5
|
import type { StoreOptions, StatePropertyValue } from "../types/store";
|
|
6
|
+
import type { Tracer } from "../types/trace";
|
|
7
7
|
/**
|
|
8
8
|
* Base class for a Pinia store with enhanced capabilities.
|
|
9
9
|
* Provides structured tracing, plugin subscriptions, and state management utilities.
|
|
@@ -11,19 +11,16 @@ import type { StoreOptions, StatePropertyValue } from "../types/store";
|
|
|
11
11
|
* This class is intended to be extended by specific store implementations
|
|
12
12
|
* that require enhanced capabilities such as structured tracing and plugin subscriptions.
|
|
13
13
|
*/
|
|
14
|
-
export default class
|
|
15
|
-
protected
|
|
14
|
+
export default class EnhancedStore extends TraceableStoreEventsSubscriber {
|
|
15
|
+
protected _name: string;
|
|
16
16
|
private _createTracer?;
|
|
17
17
|
private _onAction?;
|
|
18
18
|
private _options;
|
|
19
|
-
|
|
19
|
+
protected _store: PiniaStore;
|
|
20
20
|
private _storeSubscribe?;
|
|
21
21
|
private _subscriptions;
|
|
22
|
-
private _traceOptions;
|
|
23
|
-
private _tracer?;
|
|
24
22
|
protected static _requiredKeys?: string[];
|
|
25
|
-
|
|
26
|
-
set classNameAddedToTraceNamespace(value: boolean);
|
|
23
|
+
protected static _requiredKeysValidation: 'every' | 'some' | false;
|
|
27
24
|
get onAction(): StoreOnActionSubscription | undefined;
|
|
28
25
|
set onAction(onAction: StoreOnActionSubscriptionCallback);
|
|
29
26
|
get options(): StoreOptions;
|
|
@@ -34,9 +31,9 @@ export default class Store {
|
|
|
34
31
|
set storeSubscribe(storeSubscribe: StoreMutationSubscriptionCallback);
|
|
35
32
|
/**
|
|
36
33
|
* Returns the structured trace emitter of this store.
|
|
37
|
-
* Built lazily
|
|
34
|
+
* Built lazily and scoped to the wrapped Pinia store.
|
|
38
35
|
*/
|
|
39
|
-
|
|
36
|
+
get tracer(): Tracer | undefined;
|
|
40
37
|
/**
|
|
41
38
|
* Constructs a new instance of the store.
|
|
42
39
|
* @param store The Pinia store instance.
|
|
@@ -45,9 +42,9 @@ export default class Store {
|
|
|
45
42
|
* This constructor is typically called by the `customizeStore` static method
|
|
46
43
|
* to create an instance of the store with the provided Pinia store and options.
|
|
47
44
|
* @see PluginStoreOptions
|
|
48
|
-
* @see
|
|
45
|
+
* @see PluginOrchestratorOptions
|
|
49
46
|
*/
|
|
50
|
-
constructor(store: PiniaStore, options:
|
|
47
|
+
constructor(store: PiniaStore, options: EnhancedStoreOptions);
|
|
51
48
|
/**
|
|
52
49
|
* Adds a property to the state of this store.
|
|
53
50
|
* @param name The name of the property to add.
|
|
@@ -60,7 +57,7 @@ export default class Store {
|
|
|
60
57
|
* @param subscription The subscription callback or object to add.
|
|
61
58
|
* @param options Additional options for the subscription, including subscription options and target stores.
|
|
62
59
|
*/
|
|
63
|
-
addSubscription(pluginName: string, subscription:
|
|
60
|
+
addSubscription(pluginName: string, subscription: StoreSubscriberInterface, options?: {
|
|
64
61
|
subscriptionOptions?: StoreOptions;
|
|
65
62
|
stores?: PiniaStore[];
|
|
66
63
|
}): void;
|
|
@@ -76,7 +73,7 @@ export default class Store {
|
|
|
76
73
|
* @template Instance The type of the store instance being created.
|
|
77
74
|
* @returns The created store instance of type `Instance`, or undefined if the required keys are not present.
|
|
78
75
|
*/
|
|
79
|
-
static customizeStore<Instance extends
|
|
76
|
+
static customizeStore<Instance extends EnhancedStore>(store: PiniaStore, options: EnhancedStoreOptions): Instance | undefined;
|
|
80
77
|
/**
|
|
81
78
|
* Retrieves the value of a specific store option.
|
|
82
79
|
* @param optionName The name of the store option to retrieve.
|
|
@@ -109,7 +106,10 @@ export default class Store {
|
|
|
109
106
|
/**
|
|
110
107
|
* Checks if the given options object has all the required keys.
|
|
111
108
|
* @param options The options object to check.
|
|
112
|
-
* @returns True if
|
|
109
|
+
* @returns True if on one of the following conditions is met:
|
|
110
|
+
* - If _requiredKeysValidation is false.
|
|
111
|
+
* - If _requiredKeysValidation is 'every', all required keys must be present.
|
|
112
|
+
* - If _requiredKeysValidation is 'some', at least one required key must be present.
|
|
113
113
|
*/
|
|
114
114
|
protected static hasRequiredKeys(options: AnyObject): boolean;
|
|
115
115
|
/**
|
|
@@ -117,11 +117,16 @@ export default class Store {
|
|
|
117
117
|
* @returns void or a Promise that resolves when hydration is complete.
|
|
118
118
|
*/
|
|
119
119
|
hydrate(): void | Promise<void>;
|
|
120
|
+
/**
|
|
121
|
+
* Initializes the store.
|
|
122
|
+
* This method can be overridden by subclasses to perform custom initialization logic.
|
|
123
|
+
*/
|
|
124
|
+
protected init(): void;
|
|
120
125
|
/**
|
|
121
126
|
* Initializes the tracer for plugin subscriptions if the createTracer option is provided.
|
|
122
127
|
* @param options The plugin subscription options containing the createTracer function.
|
|
123
128
|
*/
|
|
124
|
-
private
|
|
129
|
+
private initializeEventsRegistry;
|
|
125
130
|
/**
|
|
126
131
|
* Checks if the store is using the Options API.
|
|
127
132
|
* @returns True if the store is using the Options API, otherwise false.
|
|
@@ -139,14 +144,4 @@ export default class Store {
|
|
|
139
144
|
* @returns True if the store object has the property, otherwise false.
|
|
140
145
|
*/
|
|
141
146
|
storeHas(property: string): boolean;
|
|
142
|
-
/**
|
|
143
|
-
* Emits a structured trace event scoped to this store.
|
|
144
|
-
* Prefer the factory form for `payload`: it is only resolved when consumed.
|
|
145
|
-
*/
|
|
146
|
-
trace(label: string, payload?: TracePayload, scope?: string, namespace?: string): void;
|
|
147
|
-
/**
|
|
148
|
-
* Emits a structured error event, or rethrows it when no listener matches.
|
|
149
|
-
*/
|
|
150
|
-
traceError(label: string, error: unknown, payload?: TracePayload, scope?: string, namespace?: string): void;
|
|
151
|
-
private traceLabelFormatter;
|
|
152
147
|
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { DefineStoreOptions, SetupStoreDefinition, StateTree, StoreDefinition, _GettersTree } from "pinia";
|
|
2
|
+
import type { AnyObject } from "../types";
|
|
3
|
+
import type { DefineAStoreDefinition, DefineAStoreSetupContext, EmptyExtensions, StoreOptions } from "../types/store";
|
|
4
|
+
import type { PluginStoreOptions } from "../types/plugin";
|
|
5
|
+
/**
|
|
6
|
+
* Define a store with the setup API. State, getters and actions are inferred
|
|
7
|
+
* from the setup function return, exactly like pinia's `defineStore`, so
|
|
8
|
+
* store members are listed by IDEs and action prototypes are preserved.
|
|
9
|
+
* @template Id The type of the store identifier.
|
|
10
|
+
* @template SS The type of the setup function return.
|
|
11
|
+
* @param id The unique identifier for the store.
|
|
12
|
+
* @param storeDefinition The setup function defining the store.
|
|
13
|
+
* @param options Optional store options.
|
|
14
|
+
* @returns The defined store.
|
|
15
|
+
*/
|
|
16
|
+
export declare function defineAStore<Id extends string, SS>(id: Id, storeDefinition: (ctx?: DefineAStoreSetupContext<AnyObject>) => SS, options?: StoreOptions): SetupStoreDefinition<Id, SS>;
|
|
17
|
+
/**
|
|
18
|
+
* Define a store with the options API, mirroring pinia's `defineStore` inference.
|
|
19
|
+
* @template Id The type of the store identifier.
|
|
20
|
+
* @template S The type of the store's state.
|
|
21
|
+
* @template G The type of the store's getters.
|
|
22
|
+
* @template A The type of the store's actions.
|
|
23
|
+
* @param id The unique identifier for the store.
|
|
24
|
+
* @param storeDefinition The store options definition.
|
|
25
|
+
* @param options Optional store options.
|
|
26
|
+
* @returns The defined store.
|
|
27
|
+
*/
|
|
28
|
+
export declare function defineAStore<Id extends string, S extends StateTree = {}, G extends _GettersTree<S> = {}, A = {}>(id: Id, storeDefinition: Omit<DefineStoreOptions<Id, S, G, A>, 'id'>, options?: StoreOptions): StoreDefinition<Id, S, G, A>;
|
|
29
|
+
/**
|
|
30
|
+
* Define a store with explicit store/state types, e.g. when plugins augment
|
|
31
|
+
* the store with members not returned by the setup function.
|
|
32
|
+
* @template Sto The type of the store.
|
|
33
|
+
* @template Sta The type of the store's state.
|
|
34
|
+
* @param id The unique identifier for the store.
|
|
35
|
+
* @param storeDefinition The store definition, either as an options object or a setup function.
|
|
36
|
+
* @param options Optional store options.
|
|
37
|
+
* @returns The defined store.
|
|
38
|
+
*/
|
|
39
|
+
export declare function defineAStore<Sto, Sta>(id: string, storeDefinition: Omit<DefineStoreOptions<string, StateTree & Sta, AnyObject, Partial<Sto>>, 'id'> | ((ctx?: DefineAStoreSetupContext<Sto & Sta>) => AnyObject), options?: StoreOptions): DefineAStoreDefinition<Sto, Sta>;
|
|
40
|
+
/**
|
|
41
|
+
* Define a store with a required, fully typed setup context. State, getters
|
|
42
|
+
* and actions are inferred from the setup function return.
|
|
43
|
+
* @template Id The type of the store identifier.
|
|
44
|
+
* @template SS The type of the setup function return.
|
|
45
|
+
* @template TExtraExtensions The type of the store's extra extensions.
|
|
46
|
+
* @param id The unique identifier for the store.
|
|
47
|
+
* @param storeDefinition The setup function defining the store.
|
|
48
|
+
* @param options Optional store options.
|
|
49
|
+
* @returns The defined store with setup context.
|
|
50
|
+
*/
|
|
51
|
+
export declare function defineAStoreCtx<Id extends string, SS, TExtraExtensions extends Record<string, unknown> = EmptyExtensions>(id: Id, storeDefinition: (ctx: DefineAStoreSetupContext<unknown, TExtraExtensions>) => SS, options?: StoreOptions): SetupStoreDefinition<Id, SS>;
|
|
52
|
+
/**
|
|
53
|
+
* Define a store with a setup context and explicit store/state types, e.g.
|
|
54
|
+
* when plugins augment the store with members not returned by the setup function.
|
|
55
|
+
* @template Sto The type of the store.
|
|
56
|
+
* @template Sta The type of the store's state.
|
|
57
|
+
* @template TExtraExtensions The type of the store's extra extensions.
|
|
58
|
+
* @param id The unique identifier for the store.
|
|
59
|
+
* @param storeDefinition The setup function defining the store.
|
|
60
|
+
* @param options Optional store options.
|
|
61
|
+
* @returns The defined store with setup context.
|
|
62
|
+
*/
|
|
63
|
+
export declare function defineAStoreCtx<Sto, Sta, TExtraExtensions extends Record<string, unknown> = EmptyExtensions>(id: string, storeDefinition: (ctx: DefineAStoreSetupContext<Sto & Sta, TExtraExtensions>) => AnyObject, options?: StoreOptions): DefineAStoreDefinition<Sto, Sta>;
|
|
64
|
+
export declare function defineAStoreOptionApi<Id extends string, S extends StateTree = {}, G extends _GettersTree<S> = {}, A = {}>(id: Id, storeDefinition: Omit<DefineStoreOptions<Id, S, G, A>, 'id'>, options?: PluginStoreOptions): StoreDefinition<Id, S, G, A>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { SetupStoreDefinition } from "pinia";
|
|
2
|
+
import type { AnyObject } from "../types";
|
|
3
|
+
import type { DefineAStoreSetup, DefineAStoreSetupContext } from "../types/store";
|
|
4
|
+
import type { PluginStoreOptions } from "../types/plugin";
|
|
5
|
+
export declare function defineAStoreSetup<Id extends string, SS>(id: Id, storeDefinition: DefineAStoreSetup<SS>, options: PluginStoreOptions): SetupStoreDefinition<Id, SS>;
|
|
6
|
+
/**
|
|
7
|
+
* Get the setup context associated with a store instance (or pending store id).
|
|
8
|
+
* @param store The store instance, or an object exposing the store `$id`.
|
|
9
|
+
* @returns The setup context when the store was defined with `enhancedStore` enabled, undefined otherwise.
|
|
10
|
+
*/
|
|
11
|
+
export declare function getDefineAStoreSetupContext(store: object): DefineAStoreSetupContext<AnyObject> | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Get the enhanced store from the context.
|
|
14
|
+
* @template TEnhancedStore The type of the enhanced store.
|
|
15
|
+
* @param ctx The context containing the extensions.
|
|
16
|
+
* @returns The enhanced store casted to the specified types.
|
|
17
|
+
*/
|
|
18
|
+
export declare function getEnhancedStore<TEnhancedStore>(ctx: DefineAStoreSetupContext<TEnhancedStore>): TEnhancedStore;
|
|
19
|
+
export declare function getEnhancedStore<TEnhancedStore>(ctx: DefineAStoreSetupContext<unknown>): TEnhancedStore;
|
|
20
|
+
/**
|
|
21
|
+
* Set the enhanced store in context with deprecated alias support.
|
|
22
|
+
* @template TEnhancedStore The type of the enhanced store.
|
|
23
|
+
* @param ctx The context containing the extensions.
|
|
24
|
+
* @param store The store to expose as enhancement.
|
|
25
|
+
*/
|
|
26
|
+
export declare function setEnhancedStore<TEnhancedStore>(ctx: DefineAStoreSetupContext<TEnhancedStore>, store: TEnhancedStore): void;
|
|
27
|
+
export declare function setEnhancedStore<TEnhancedStore>(ctx: DefineAStoreSetupContext<unknown>, store: TEnhancedStore): void;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { MessengerEmitter } from '../services/messengerProvider';
|
|
2
|
+
import type Messenger from '../services/messenger';
|
|
3
|
+
/**
|
|
4
|
+
* Abstract class for emitting events.
|
|
5
|
+
* Manages event subscribers and provides methods to emit events to them.
|
|
6
|
+
*/
|
|
7
|
+
export default class EventsEmitter extends MessengerEmitter {
|
|
8
|
+
constructor(messenger: Messenger);
|
|
9
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { MessengerSubscriber } from '../services/messengerProvider';
|
|
2
|
+
import type { EventSubscription as EventSubscriptionInterface, StoreEvent, StoreEventConstructorOptions } from '../types/events';
|
|
3
|
+
import type Messenger from '../services/messenger';
|
|
4
|
+
import type { MessengerSubscriber as MessengerSubscriberInterface } from '../types/messenger';
|
|
5
|
+
/**
|
|
6
|
+
* Abstract class for subscribing to events.
|
|
7
|
+
* Manages event subscriptions and provides methods to consume events.
|
|
8
|
+
*/
|
|
9
|
+
export default class EventsSubscriber extends MessengerSubscriber implements MessengerSubscriberInterface {
|
|
10
|
+
private _subscriptions;
|
|
11
|
+
private _subscriptionsToConsume;
|
|
12
|
+
constructor(messenger: Messenger, id: string);
|
|
13
|
+
set subscriptions(subscriptions: EventSubscriptionInterface[]);
|
|
14
|
+
/**
|
|
15
|
+
* Adds a new subscription for the specified event.
|
|
16
|
+
* @param eventName The name of the event to subscribe to.
|
|
17
|
+
* @param consumer The function to be called when the event is emitted.
|
|
18
|
+
* @param options Additional options for the subscription, excluding the event name.
|
|
19
|
+
*/
|
|
20
|
+
addSubscription(eventName: string, consumer: (...args: any[]) => void, options?: StoreEventConstructorOptions): void;
|
|
21
|
+
/**
|
|
22
|
+
* Clears all subscriptions.
|
|
23
|
+
*/
|
|
24
|
+
clear(): void;
|
|
25
|
+
/**
|
|
26
|
+
* Consumes all subscriptions that match the specified event.
|
|
27
|
+
* @param event The event to consume.
|
|
28
|
+
*/
|
|
29
|
+
protected consume(event: StoreEvent): void;
|
|
30
|
+
protected isCustomer(event: StoreEvent): boolean;
|
|
31
|
+
protected initSubscriptionsToConsume(event: StoreEvent): void;
|
|
32
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import StoreEvent from './StoreEvent';
|
|
2
|
+
import type { Event as EventInterface, EventSubscription as EventSubscriptionInterface, StoreEvent as StoreEventInterface, StoreEventConstructorOptions } from '../types/events';
|
|
3
|
+
export default class EventSubscription extends StoreEvent implements EventSubscriptionInterface {
|
|
4
|
+
private _consumer;
|
|
5
|
+
constructor(eventName: string, _consumer: (...args: any[]) => void | Promise<void>, options?: StoreEventConstructorOptions);
|
|
6
|
+
/**
|
|
7
|
+
* Consumes an event by invoking the consumer function.
|
|
8
|
+
* Handles both synchronous and asynchronous consumers.
|
|
9
|
+
* @param event The event to consume.
|
|
10
|
+
*/
|
|
11
|
+
consume(event: EventInterface | StoreEventInterface): void;
|
|
12
|
+
subscribed(event: StoreEventInterface): boolean;
|
|
13
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import Event from "./event";
|
|
2
|
+
import type { StoreEventConstructorOptions } from "../types/events";
|
|
3
|
+
export default class StoreEvent extends Event {
|
|
4
|
+
instanceId?: string;
|
|
5
|
+
constructor(name: string, { payload, scope, source, instanceId }?: StoreEventConstructorOptions);
|
|
6
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Store } from "pinia";
|
|
2
|
+
/**
|
|
3
|
+
* Registry for managing store event subscriptions.
|
|
4
|
+
*/
|
|
5
|
+
export default class StoresEventsSubscriptionsRegistry {
|
|
6
|
+
private subscriptions;
|
|
7
|
+
/**
|
|
8
|
+
* Adds a subscription for the given store and event.
|
|
9
|
+
* @param store The store to add the subscription for.
|
|
10
|
+
* @param event The event to subscribe to.
|
|
11
|
+
*/
|
|
12
|
+
add(store: Store, event: string): void;
|
|
13
|
+
/**
|
|
14
|
+
* Clears all subscriptions for the given store, or all subscriptions if no store is specified.
|
|
15
|
+
* @param store The store to clear subscriptions for, or undefined to clear all subscriptions.
|
|
16
|
+
*/
|
|
17
|
+
clear(store?: Store): void;
|
|
18
|
+
/**
|
|
19
|
+
* Checks if a subscription exists for the given store and event.
|
|
20
|
+
* @param store The store to check the subscription for.
|
|
21
|
+
* @param event The event to check the subscription for.
|
|
22
|
+
* @returns True if the subscription exists, false otherwise.
|
|
23
|
+
*/
|
|
24
|
+
has(store: Store, event: string): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Removes a subscription for the given store and event.
|
|
27
|
+
* @param store The store to remove the subscription for.
|
|
28
|
+
* @param event The event to unsubscribe from.
|
|
29
|
+
*/
|
|
30
|
+
remove(store: Store, event: string): void;
|
|
31
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Event as EventInterface, EventPayload } from '../types/events';
|
|
2
|
+
export default class Event implements EventInterface {
|
|
3
|
+
name: string;
|
|
4
|
+
payload?: EventPayload;
|
|
5
|
+
scope?: string;
|
|
6
|
+
source?: string;
|
|
7
|
+
constructor(name: string, { payload, scope, source }?: Omit<EventInterface, 'name'>);
|
|
8
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import EventsEmitter from '../events/EventsEmitter';
|
|
2
|
+
import StoresEventsSubscriptionsRegistry from '../events/StoresEventsSubscriptionsRegistry';
|
|
3
|
+
import type EventSubscriber from '../events/EventsSubscriber';
|
|
4
|
+
import type { EventSubscription } from '../types/events';
|
|
5
|
+
export declare function createEventsRegistry(): {
|
|
6
|
+
emitter: EventsEmitter;
|
|
7
|
+
createSubscriber: (id: string, eventSubscriptions?: EventSubscription[]) => EventSubscriber;
|
|
8
|
+
subscriptionsRegistry: StoresEventsSubscriptionsRegistry;
|
|
9
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import EventsSubscriber from '../events/EventsSubscriber';
|
|
2
|
+
import type Messenger from '../services/messenger';
|
|
3
|
+
import type { EventSubscription as EventSubscription } from '../types/events';
|
|
4
|
+
/**
|
|
5
|
+
* Creates a events subscriber.
|
|
6
|
+
* @param messenger The messenger instance to be used by the events subscriber.
|
|
7
|
+
* @param id The unique identifier for the events subscriber.
|
|
8
|
+
* @param eventSubscriptions The list of event subscriptions to initialize the subscriber with.
|
|
9
|
+
* @returns An instance of EventsSubscriber configured for the specified store.
|
|
10
|
+
*/
|
|
11
|
+
export declare function createEventsSubscriber(messenger: Messenger, id: string, eventSubscriptions?: EventSubscription[]): EventsSubscriber;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import Messenger from '../services/messenger';
|
|
2
|
+
import type { MessengerEmitter, MessengerSubscriber } from '../services/messengerProvider';
|
|
3
|
+
/**
|
|
4
|
+
* Factory function to create a messenger registry.
|
|
5
|
+
* Provides an emitter and a method to create subscribers with unique IDs.
|
|
6
|
+
* @template S The type of the messenger subscriber.
|
|
7
|
+
* @template E [optional] The type of the messenger emitter, defaults to MessengerEmitter.
|
|
8
|
+
* @param channel The messenger channel to use for the emitter and subscribers.
|
|
9
|
+
* @param createSubscriber The factory function to create subscribers.
|
|
10
|
+
* @param Emitter The constructor for the messenger emitter..
|
|
11
|
+
* @returns An object containing the emitter and a method to create subscribers.
|
|
12
|
+
*/
|
|
13
|
+
export declare function createMessengerRegistry<S extends MessengerSubscriber, E extends MessengerEmitter = MessengerEmitter>(channel: string, createSubscriber: (messenger: Messenger) => (id: string, optionalArgs?: unknown[]) => S, Emitter: new (messenger: Messenger, channel: string) => E): {
|
|
14
|
+
emitter: E;
|
|
15
|
+
createSubscriber: (id: string, optionalArgs?: unknown[]) => S;
|
|
16
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { StoreSubscriberInterface, StoreSubscriberInvoke } from "../types/plugin";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a new plugin subscriber with the given name, invoke function, and optional properties.
|
|
4
|
+
* @param name - plugin name.
|
|
5
|
+
* @param invoke - function to invoke for the plugin subscriber.
|
|
6
|
+
* @param optionalProps - optional additional properties for the plugin subscriber.
|
|
7
|
+
* @param {Function} optionalProps.afterHydration
|
|
8
|
+
* @param {PluginExecutionOptions} optionalProps.execution
|
|
9
|
+
* @param {Function} optionalProps.hydrate
|
|
10
|
+
* @param {PluginHydrationScheduler} optionalProps.hydrationScheduler
|
|
11
|
+
* @param {StoreOnActionSubscription} optionalProps.storeOnActionSubscription
|
|
12
|
+
* @param {StoreMutationSubscription} optionalProps.storeMutationSubscription
|
|
13
|
+
* @param {PluginSubscriptions} optionalProps.subscriptions
|
|
14
|
+
* @param
|
|
15
|
+
* @returns A new plugin subscriber object.
|
|
16
|
+
*/
|
|
17
|
+
export declare function createPluginSubscriber(name: string, invoke: StoreSubscriberInvoke, optionalProps?: Omit<StoreSubscriberInterface, "name" | "invoke">): StoreSubscriberInterface;
|