pinia-plugin-subscription 0.1.6 → 0.1.7-beta.1
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 +12 -0
- package/README.md +76 -0
- package/dist/chunks/index-ByASkYCc.js +338 -0
- package/dist/core/Store.d.ts +53 -0
- package/dist/helpers/index.d.ts +4 -0
- package/dist/helpers.js +7 -0
- package/dist/lib/main.d.ts +14 -0
- package/dist/pinia-plugin-subscription.js +203 -1906
- package/dist/plugins/createHydrationPlugin.d.ts +3 -0
- package/dist/plugins/createPlugin.d.ts +11 -0
- package/dist/plugins/pluginSubscriber.d.ts +35 -0
- package/dist/plugins/pluginSubscription.d.ts +40 -0
- package/dist/system/Debug.d.ts +13 -0
- package/dist/system/log.d.ts +24 -0
- package/dist/types/comparison.d.ts +3 -0
- package/dist/types/index.d.ts +6 -143
- package/dist/types/list.d.ts +13 -0
- package/dist/types/log.d.ts +8 -0
- package/dist/types/plugin.d.ts +53 -0
- package/dist/types/resourceId.d.ts +4 -0
- package/dist/types/store.d.ts +27 -0
- package/dist/utils/Performance.d.ts +9 -0
- package/dist/utils/constantes.d.ts +1 -0
- package/dist/utils/defineStoreId.d.ts +1 -0
- package/dist/utils/object.d.ts +4 -0
- package/dist/utils/store.d.ts +31 -0
- package/dist/utils/validation/index.d.ts +1 -0
- package/dist/utils/validation/object.d.ts +9 -0
- package/package.json +36 -9
- package/dist/pinia-plugin-subscription.umd.cjs +0 -5
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PiniaPlugin } from "pinia";
|
|
2
|
+
import type { PluginSubscriber } from "../types/plugin";
|
|
3
|
+
import type { StoreOptions } from "../types/store";
|
|
4
|
+
export declare function createPlugin(subscribers: PluginSubscriber[], debug?: string[]): PiniaPlugin;
|
|
5
|
+
declare module 'pinia' {
|
|
6
|
+
interface PiniaCustomProperties {
|
|
7
|
+
}
|
|
8
|
+
interface DefineStoreOptionsBase<S, Store> {
|
|
9
|
+
storeOptions?: StoreOptions;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import Store from "../core/Store";
|
|
2
|
+
import type { PiniaPluginContext, Store as PiniaStore } from "pinia";
|
|
3
|
+
import type { AnyObject } from "../types";
|
|
4
|
+
import type { PluginExecutionOptions, PluginHydrationScheduler, PluginSubscriber as PluginSubscriberInterface, PluginSubscriptions, StoreMutationSubscription, StoreOnActionSubscription } from "../types/plugin";
|
|
5
|
+
import type { Console } from "../types/log";
|
|
6
|
+
type CreateInstance<Instance = Store> = (store: PiniaStore, options: AnyObject, debug: boolean, customConsole?: Console) => Instance | undefined;
|
|
7
|
+
export default abstract class PluginSubscriber<Instance extends Store> implements PluginSubscriberInterface {
|
|
8
|
+
private _console?;
|
|
9
|
+
private _createInstance;
|
|
10
|
+
private _name;
|
|
11
|
+
private _pluginOptions?;
|
|
12
|
+
private _storeInstance?;
|
|
13
|
+
protected _resetStoreCallback?: (store?: PiniaStore) => void;
|
|
14
|
+
private _storeOnActionSubscription?;
|
|
15
|
+
private _storeMutationSubscription?;
|
|
16
|
+
private _subscriptions?;
|
|
17
|
+
protected pluginCreated?: (store: PiniaStore) => void;
|
|
18
|
+
execution?: PluginExecutionOptions;
|
|
19
|
+
hydrationScheduler?: PluginHydrationScheduler;
|
|
20
|
+
get console(): Console;
|
|
21
|
+
get name(): string;
|
|
22
|
+
get storeInstance(): Instance | undefined;
|
|
23
|
+
get pluginOptions(): AnyObject;
|
|
24
|
+
set pluginOptions(options: AnyObject | undefined);
|
|
25
|
+
get resetStoreCallback(): ((store?: PiniaStore) => void) | undefined;
|
|
26
|
+
get storeOnActionSubscription(): StoreOnActionSubscription | undefined;
|
|
27
|
+
get storeMutationSubscription(): StoreMutationSubscription | undefined;
|
|
28
|
+
get subscriptions(): PluginSubscriptions | undefined;
|
|
29
|
+
set subscriptions(subscriptions: PluginSubscriptions);
|
|
30
|
+
constructor(pluginName: string, createInstanceFunction: CreateInstance, pluginConsole?: Console);
|
|
31
|
+
hydrate(context: PiniaPluginContext, debug: boolean): void | Promise<void>;
|
|
32
|
+
afterHydration(context: PiniaPluginContext, debug: boolean): void | Promise<void>;
|
|
33
|
+
invoke({ store, options }: PiniaPluginContext, debug: boolean): boolean;
|
|
34
|
+
}
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import Debug from "../system/Debug";
|
|
2
|
+
import type { PiniaPluginContext } from "pinia";
|
|
3
|
+
import type { PluginSubscriber, PluginSubscriptionOptions, PluginSubscriptions } from "../types/plugin";
|
|
4
|
+
export default class PluginSubscription extends Debug {
|
|
5
|
+
protected _className: string;
|
|
6
|
+
private _hydrationScheduler;
|
|
7
|
+
private _options?;
|
|
8
|
+
private _pluginDebug?;
|
|
9
|
+
private _resetStoreCallback;
|
|
10
|
+
private _subscribers;
|
|
11
|
+
private _subscribersDelivered;
|
|
12
|
+
private _subscribersScheduled;
|
|
13
|
+
private _subscriptions;
|
|
14
|
+
private _subscriptionsDelivered;
|
|
15
|
+
private _subscriptionsScheduled;
|
|
16
|
+
set subscribers(subscribers: PluginSubscriber[]);
|
|
17
|
+
get subscriptions(): PluginSubscriptions[] | undefined;
|
|
18
|
+
constructor(subscribers: PluginSubscriber[], debugOrOptions?: PluginSubscriptionOptions | string[], pluginOptions?: PluginSubscriptionOptions);
|
|
19
|
+
private addResetStoreCallback;
|
|
20
|
+
private defineCurrentEnvironment;
|
|
21
|
+
private definePluginDebug;
|
|
22
|
+
private definePluginExecution;
|
|
23
|
+
private defineHydrationScheduler;
|
|
24
|
+
private defineSubscriberKey;
|
|
25
|
+
private defineSubscriptionKey;
|
|
26
|
+
private executeResetStoreCallbacks;
|
|
27
|
+
private executeSubscriber;
|
|
28
|
+
private executeSubscriberSafely;
|
|
29
|
+
private queueSubscriberExecution;
|
|
30
|
+
private shouldInvokePlugin;
|
|
31
|
+
private shouldScheduleAfterHydration;
|
|
32
|
+
plugin({ store, options }: PiniaPluginContext): void;
|
|
33
|
+
private rewriteResetStore;
|
|
34
|
+
private registerStoreCleanup;
|
|
35
|
+
private clearStoreTracking;
|
|
36
|
+
private storeOnActionSubscription;
|
|
37
|
+
private storeMutationSubscription;
|
|
38
|
+
private subscriptionDelivery;
|
|
39
|
+
private subscriptionDeliverySafely;
|
|
40
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Console } from "../types/log";
|
|
2
|
+
export default abstract class Debug {
|
|
3
|
+
protected abstract _className: string;
|
|
4
|
+
private _console?;
|
|
5
|
+
private _debug;
|
|
6
|
+
get console(): Console;
|
|
7
|
+
set console(customConsole: Console);
|
|
8
|
+
get debug(): boolean;
|
|
9
|
+
set debug(debug: boolean);
|
|
10
|
+
constructor(debug: boolean, customConsole?: Console);
|
|
11
|
+
debugLog(...args: any): void;
|
|
12
|
+
logError(...args: any): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Console, LogType, StyleDefinition, StyleDefinitions } from '../types/log';
|
|
2
|
+
export declare function log(logStyle: string, args: any): void;
|
|
3
|
+
export declare abstract class CustomConsole implements Console {
|
|
4
|
+
protected _bgColor: string;
|
|
5
|
+
protected _color: string;
|
|
6
|
+
protected _icon: string;
|
|
7
|
+
protected _errorBgColor: string;
|
|
8
|
+
protected _errorColor: string;
|
|
9
|
+
protected _errorIcon: string;
|
|
10
|
+
protected abstract _pluginName: string;
|
|
11
|
+
protected _styles: StyleDefinitions;
|
|
12
|
+
protected formatMessage(message: string, icon: string): string;
|
|
13
|
+
protected generateStyle(styleDefinition: StyleDefinition): string;
|
|
14
|
+
protected getStyleDefinition(messageType?: LogType): StyleDefinition;
|
|
15
|
+
log(...args: any): void;
|
|
16
|
+
error(...args: any): void;
|
|
17
|
+
protected rebuildArgs(args: string | any[], icon: string): any[] | undefined;
|
|
18
|
+
protected useLog(styleDefinition: StyleDefinition, args: any): void;
|
|
19
|
+
}
|
|
20
|
+
declare class PluginConsoleClass extends CustomConsole {
|
|
21
|
+
protected _pluginName: string;
|
|
22
|
+
}
|
|
23
|
+
export declare const PluginConsole: PluginConsoleClass;
|
|
24
|
+
export {};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { PiniaPluginContext, Store as PiniaStore } from 'pinia';
|
|
2
|
+
import type { PluginExecutionOptions, PluginHydrationScheduler, PluginSubscriptions, StoreMutationSubscription, StoreOnActionSubscription } from './plugin';
|
|
3
|
+
import type { StoreOptions } from './store';
|
|
3
4
|
export interface AnyObject {
|
|
4
5
|
[key: number | string | symbol]: any;
|
|
5
6
|
}
|
|
@@ -17,51 +18,9 @@ export type StyleDefinitions = Record<LogType, Record<StyleDefinitionKeys, strin
|
|
|
17
18
|
export type ConsoleStyleDefinition = StyleDefinition;
|
|
18
19
|
export type ConsoleStyleDefinitionKeys = StyleDefinitionKeys;
|
|
19
20
|
export type ConsoleStyleDefinitions = StyleDefinitions;
|
|
20
|
-
type
|
|
21
|
-
type
|
|
22
|
-
type
|
|
23
|
-
export type CustomStore<TStore, TState> = PiniaStore & TStore & TState & PiniaCustomProperties & StoreDefinition;
|
|
24
|
-
export interface PluginStoreOptions {
|
|
25
|
-
storeOptions: StoreOptions;
|
|
26
|
-
}
|
|
27
|
-
export type EmptyExtensions = Record<never, never>;
|
|
28
|
-
export interface DefineAStoreSetupExtensions<TEnhancedStore> {
|
|
29
|
-
/**
|
|
30
|
-
* @deprecated Use enhancedStore instead.
|
|
31
|
-
*/
|
|
32
|
-
extending?: TEnhancedStore;
|
|
33
|
-
enhancedStore?: TEnhancedStore;
|
|
34
|
-
}
|
|
35
|
-
export interface DefineAStoreSetupContext<TEnhancedStore, TExtraExtensions extends Record<string, unknown> = EmptyExtensions> {
|
|
36
|
-
id: string;
|
|
37
|
-
extensions: DefineAStoreSetupExtensions<TEnhancedStore> & TExtraExtensions;
|
|
38
|
-
}
|
|
39
|
-
export type StatePropertyValue = StdStatePropertyValue | Ref<StdStatePropertyValue> | StdStatePropertyValue[] | Ref<StdStatePropertyValue[]> | Ref<StdStatePropertyValue>[];
|
|
40
|
-
export type StoreOptions = Record<string, StoreOptionsPropertyValue>;
|
|
41
|
-
export type StoreOptionsPropertyValue = OptionBaseProperty | OptionBaseProperty[] | ObjectBaseProperty | ObjectBaseProperty[];
|
|
42
|
-
export type PluginHydrationScheduler = (callback: () => void) => void;
|
|
43
|
-
export type PluginHydrationTiming = 'defer' | 'immediate';
|
|
44
|
-
export type PluginRuntimeEnvironment = 'client' | 'server';
|
|
45
|
-
export type PluginExecutionEnvironment = PluginRuntimeEnvironment | 'both';
|
|
46
|
-
export interface PluginExecutionOptions {
|
|
47
|
-
environment?: PluginExecutionEnvironment;
|
|
48
|
-
hydration?: PluginHydrationTiming;
|
|
49
|
-
}
|
|
50
|
-
export interface PluginSubscriptionOptions {
|
|
51
|
-
execution?: PluginExecutionOptions;
|
|
52
|
-
hydrationScheduler?: PluginHydrationScheduler;
|
|
53
|
-
runtimeEnvironment?: PluginRuntimeEnvironment;
|
|
54
|
-
subscriberExecution?: Record<string, PluginExecutionOptions>;
|
|
55
|
-
}
|
|
56
|
-
export interface NativePiniaSubscriptionReturn<Callback> {
|
|
57
|
-
store: PiniaStore;
|
|
58
|
-
callback: Callback;
|
|
59
|
-
}
|
|
60
|
-
export interface StoreOnActionCallbackParameters {
|
|
61
|
-
after: Function;
|
|
62
|
-
args: any[] | object;
|
|
63
|
-
name: string;
|
|
64
|
-
}
|
|
21
|
+
export type { List, ListTypes, ListTypesMap, PartialList } from './list';
|
|
22
|
+
export type { CustomStore, DefineAStoreSetupContext, DefineAStoreSetupExtensions, EmptyExtensions, PluginStoreOptions, StatePropertyValue, StoreOptions, StoreOptionsPropertyValue } from './store';
|
|
23
|
+
export type { NativePiniaSubscription, NativePiniaSubscriptionReturn, PluginExecutionEnvironment, PluginExecutionOptions, PluginHydrationScheduler, PluginHydrationTiming, PluginRuntimeEnvironment, PluginSubscriber, PluginSubscription, PluginSubscriptionOptions, PluginSubscriptions, StoreMutationSubscription, StoreMutationSubscriptionCallback, StoreMutationSubscriptionReturn, StoreOnActionCallbackParameters, StoreOnActionSubscription, StoreOnActionSubscriptionCallback, StoreOnActionSubscriptionReturn, } from './plugin';
|
|
65
24
|
export interface PluginSubscriberInterface {
|
|
66
25
|
console?: Console;
|
|
67
26
|
execution?: PluginExecutionOptions;
|
|
@@ -80,99 +39,3 @@ export interface PluginSubscriptionDefinition {
|
|
|
80
39
|
subscription: PluginSubscriberInterface;
|
|
81
40
|
subscriptionOptions?: StoreOptions;
|
|
82
41
|
}
|
|
83
|
-
export type PluginSubscriptions = Record<string, PluginSubscriptionDefinition>;
|
|
84
|
-
export type NativePiniaSubscription<Callback> = () => NativePiniaSubscriptionReturn<Callback>;
|
|
85
|
-
export type StoreOnActionSubscriptionCallback = (params: StoreOnActionCallbackParameters) => void;
|
|
86
|
-
export type StoreOnActionSubscription = NativePiniaSubscription<StoreOnActionSubscriptionCallback>;
|
|
87
|
-
export type StoreMutationSubscriptionCallback = (mutation: SubscriptionCallbackMutation<StateTree>) => void;
|
|
88
|
-
export type StoreMutationSubscription = NativePiniaSubscription<StoreMutationSubscriptionCallback>;
|
|
89
|
-
export declare const PLUGIN_NAME: string;
|
|
90
|
-
export declare function createPlugin(subscribers: PluginSubscriberInterface[], debug?: string[]): PiniaPlugin;
|
|
91
|
-
export declare function createHydrationPlugin(subscribers: PluginSubscriberInterface[], options?: PluginSubscriptionOptions): PiniaPlugin;
|
|
92
|
-
export declare function defineAStore<Sto, Sta>(id: string, storeDefinition: Omit<DefineStoreOptions<string, StateTree & Sta, AnyObject, Partial<Sto>>, 'id'>, options?: StoreOptions): StoreDefinition & Sta & Sto;
|
|
93
|
-
export declare function defineAStore<Sto, Sta>(id: string, storeDefinition: (ctx?: DefineAStoreSetupContext<AnyObject>) => AnyObject, options?: StoreOptions): StoreDefinition & Sta & Sto;
|
|
94
|
-
export declare function defineAStoreCtx<Sto, Sta>(id: string, storeDefinition: (ctx: DefineAStoreSetupContext<Sto & Sta>) => AnyObject, options?: StoreOptions): StoreDefinition & Sta & Sto;
|
|
95
|
-
export declare function defineAStoreCtx<Sto, Sta, TExtraExtensions extends Record<string, unknown>>(id: string, storeDefinition: (ctx: DefineAStoreSetupContext<Sto & Sta, TExtraExtensions>) => AnyObject, options?: StoreOptions): StoreDefinition & Sta & Sto;
|
|
96
|
-
export declare function getDefineAStoreSetupContext(store: AnyObject): DefineAStoreSetupContext<AnyObject> | undefined;
|
|
97
|
-
export declare function getEnhancedStore<TEnhancedStore>(ctx: DefineAStoreSetupContext<TEnhancedStore>): TEnhancedStore;
|
|
98
|
-
export declare function setEnhancedStore<TEnhancedStore>(ctx: DefineAStoreSetupContext<TEnhancedStore>, store: TEnhancedStore): void;
|
|
99
|
-
/**
|
|
100
|
-
* @deprecated Use getEnhancedStore instead.
|
|
101
|
-
*/
|
|
102
|
-
export declare function getExtendingStore<TEnhancedStore>(ctx: DefineAStoreSetupContext<TEnhancedStore>): TEnhancedStore;
|
|
103
|
-
export declare function isEmpty(value: any): boolean;
|
|
104
|
-
export declare abstract class Debug {
|
|
105
|
-
protected abstract _className: string;
|
|
106
|
-
console: Console;
|
|
107
|
-
debug: boolean;
|
|
108
|
-
constructor(debug: boolean, customConsole?: Console);
|
|
109
|
-
debugLog(...args: any): void;
|
|
110
|
-
logError(...args: any): void;
|
|
111
|
-
}
|
|
112
|
-
export declare abstract class CustomConsole implements Console {
|
|
113
|
-
protected _bgColor: string;
|
|
114
|
-
protected _color: string;
|
|
115
|
-
protected _icon: string;
|
|
116
|
-
protected _errorBgColor: string;
|
|
117
|
-
protected _errorColor: string;
|
|
118
|
-
protected _errorIcon: string;
|
|
119
|
-
protected abstract _pluginName: string;
|
|
120
|
-
log(...args: any): void;
|
|
121
|
-
error(...args: any): void;
|
|
122
|
-
}
|
|
123
|
-
export declare abstract class PluginSubscriber<Instance extends Store> implements PluginSubscriberInterface {
|
|
124
|
-
console: Console;
|
|
125
|
-
execution?: PluginExecutionOptions;
|
|
126
|
-
hydrate(context: PiniaPluginContext, debug: boolean): void | Promise<void>;
|
|
127
|
-
hydrationScheduler?: PluginHydrationScheduler;
|
|
128
|
-
name: string;
|
|
129
|
-
pluginOptions: AnyObject;
|
|
130
|
-
resetStoreCallback?: (store?: PiniaStore) => void;
|
|
131
|
-
storeOnActionSubscription?: StoreOnActionSubscription;
|
|
132
|
-
storeMutationSubscription?: StoreMutationSubscription;
|
|
133
|
-
subscriptions?: PluginSubscriptions;
|
|
134
|
-
afterHydration(context: PiniaPluginContext, debug: boolean): void | Promise<void>;
|
|
135
|
-
protected pluginCreated?: (store: PiniaStore) => void;
|
|
136
|
-
protected _resetStoreCallback?: (store?: PiniaStore) => void;
|
|
137
|
-
constructor(pluginName: string, createInstanceFunction: (store: PiniaStore, options: AnyObject, debug: boolean, customConsole?: Console) => Instance | undefined, pluginConsole?: Console);
|
|
138
|
-
invoke(context: PiniaPluginContext, debug: boolean): boolean;
|
|
139
|
-
get storeInstance(): Instance | undefined;
|
|
140
|
-
}
|
|
141
|
-
export declare class PluginSubscription extends Debug {
|
|
142
|
-
protected _className: string;
|
|
143
|
-
constructor(subscribers: PluginSubscriberInterface[], debug?: string[], pluginOptions?: PluginSubscriptionOptions);
|
|
144
|
-
plugin(context: PiniaPluginContext): void;
|
|
145
|
-
}
|
|
146
|
-
export declare class Store extends Debug {
|
|
147
|
-
protected static _requiredKeys?: string[];
|
|
148
|
-
protected _className: string;
|
|
149
|
-
onAction: StoreOnActionSubscription | undefined;
|
|
150
|
-
readonly options: StoreOptions;
|
|
151
|
-
state: StateTree;
|
|
152
|
-
storeSubscribe: StoreMutationSubscriptionCallback | undefined;
|
|
153
|
-
readonly store: AnyObject;
|
|
154
|
-
hydrate(): void | Promise<void>;
|
|
155
|
-
afterHydration(): void | Promise<void>;
|
|
156
|
-
constructor(store: PiniaStore, options: AnyObject, debug?: boolean, customConsole?: Console);
|
|
157
|
-
addSubscription(pluginName: string, subscription: PluginSubscriberInterface, options?: {
|
|
158
|
-
subscriptionOptions?: StoreOptions;
|
|
159
|
-
stores?: PiniaStore[];
|
|
160
|
-
}): void;
|
|
161
|
-
addToState(name: string, value?: StatePropertyValue): void;
|
|
162
|
-
static customizeStore<Instance extends Store>(store: PiniaStore, options: AnyObject, debug?: boolean, customConsole?: Console): Instance | undefined;
|
|
163
|
-
getOption(optionName: keyof StoreOptions): StoreOptionsPropertyValue;
|
|
164
|
-
getStatePropertyValue(propertyName: string): StatePropertyValue;
|
|
165
|
-
getSubscriptions(): PluginSubscriptions | undefined;
|
|
166
|
-
getValue(value: any): any;
|
|
167
|
-
hasDeniedFirstChar(property: string): boolean;
|
|
168
|
-
protected static hasRequiredKeys(options: AnyObject): boolean;
|
|
169
|
-
isOptionApi(): boolean;
|
|
170
|
-
stateHas(property: string): boolean;
|
|
171
|
-
storeHas(property: string): boolean;
|
|
172
|
-
}
|
|
173
|
-
declare module 'pinia' {
|
|
174
|
-
interface DefineStoreOptionsBase<S, Store> {
|
|
175
|
-
storeOptions?: StoreOptions;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type ListTypes = "0" | "1" | "2" | "3" | "4" | "5";
|
|
2
|
+
export interface List {
|
|
3
|
+
'@id'?: string | number;
|
|
4
|
+
id?: number;
|
|
5
|
+
name?: string;
|
|
6
|
+
type?: ListTypes;
|
|
7
|
+
}
|
|
8
|
+
export type PartialList = Omit<List, '@id' | 'id' | 'name' | 'type'> & {
|
|
9
|
+
id?: number;
|
|
10
|
+
name?: string;
|
|
11
|
+
type?: ListTypes;
|
|
12
|
+
};
|
|
13
|
+
export type ListTypesMap = Record<ListTypes, string>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface Console {
|
|
2
|
+
log(...args: any): void;
|
|
3
|
+
error(...args: any): void;
|
|
4
|
+
}
|
|
5
|
+
export type LogType = 'error' | 'info';
|
|
6
|
+
export type StyleDefinition = Record<StyleDefinitionKeys, string>;
|
|
7
|
+
export type StyleDefinitionKeys = 'bgColor' | 'color' | 'icon';
|
|
8
|
+
export type StyleDefinitions = Record<LogType, Record<StyleDefinitionKeys, string>>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { PiniaPluginContext, StateTree, Store, SubscriptionCallbackMutation } from "pinia";
|
|
2
|
+
import type { StoreOptions } from "./store";
|
|
3
|
+
import type { Console, PluginSubscriberInterface } from ".";
|
|
4
|
+
export type PluginHydrationScheduler = (callback: () => void) => void;
|
|
5
|
+
export type PluginHydrationTiming = 'defer' | 'immediate';
|
|
6
|
+
export type PluginRuntimeEnvironment = 'client' | 'server';
|
|
7
|
+
export type PluginExecutionEnvironment = PluginRuntimeEnvironment | 'both';
|
|
8
|
+
export interface PluginExecutionOptions {
|
|
9
|
+
environment?: PluginExecutionEnvironment;
|
|
10
|
+
hydration?: PluginHydrationTiming;
|
|
11
|
+
}
|
|
12
|
+
export interface PluginSubscriptionOptions {
|
|
13
|
+
debug?: string[];
|
|
14
|
+
execution?: PluginExecutionOptions;
|
|
15
|
+
hydrationScheduler?: PluginHydrationScheduler;
|
|
16
|
+
runtimeEnvironment?: PluginRuntimeEnvironment;
|
|
17
|
+
subscriberExecution?: Record<string, PluginExecutionOptions>;
|
|
18
|
+
}
|
|
19
|
+
export interface PluginSubscriber {
|
|
20
|
+
console?: Console;
|
|
21
|
+
execution?: PluginExecutionOptions;
|
|
22
|
+
hydrate?: (context: PiniaPluginContext, debug: boolean) => void | Promise<void>;
|
|
23
|
+
hydrationScheduler?: PluginHydrationScheduler;
|
|
24
|
+
invoke: (context: PiniaPluginContext, debug: boolean) => boolean;
|
|
25
|
+
name: string;
|
|
26
|
+
resetStoreCallback?: (store?: Store) => void;
|
|
27
|
+
storeOnActionSubscription?: StoreOnActionSubscription;
|
|
28
|
+
storeMutationSubscription?: StoreMutationSubscription;
|
|
29
|
+
subscriptions?: PluginSubscriptions;
|
|
30
|
+
afterHydration?: (context: PiniaPluginContext, debug: boolean) => void | Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
export interface NativePiniaSubscriptionReturn<Callback> {
|
|
33
|
+
store: Store;
|
|
34
|
+
callback: Callback;
|
|
35
|
+
}
|
|
36
|
+
export interface StoreOnActionCallbackParameters {
|
|
37
|
+
after: Function;
|
|
38
|
+
args: any[] | object;
|
|
39
|
+
name: string;
|
|
40
|
+
}
|
|
41
|
+
export interface PluginSubscription {
|
|
42
|
+
stores?: Store[];
|
|
43
|
+
subscription: PluginSubscriberInterface;
|
|
44
|
+
subscriptionOptions?: StoreOptions;
|
|
45
|
+
}
|
|
46
|
+
export type PluginSubscriptions = Record<string, PluginSubscription>;
|
|
47
|
+
export type NativePiniaSubscription<Callback> = () => NativePiniaSubscriptionReturn<Callback>;
|
|
48
|
+
export type StoreOnActionSubscriptionCallback = (params: StoreOnActionCallbackParameters) => void;
|
|
49
|
+
export type StoreOnActionSubscriptionReturn = NativePiniaSubscriptionReturn<StoreOnActionSubscriptionCallback>;
|
|
50
|
+
export type StoreOnActionSubscription = NativePiniaSubscription<StoreOnActionSubscriptionCallback>;
|
|
51
|
+
export type StoreMutationSubscriptionCallback = (mutation: SubscriptionCallbackMutation<StateTree>) => void;
|
|
52
|
+
export type StoreMutationSubscriptionReturn = NativePiniaSubscriptionReturn<StoreMutationSubscriptionCallback>;
|
|
53
|
+
export type StoreMutationSubscription = NativePiniaSubscription<StoreMutationSubscriptionCallback>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { AnyObject } from ".";
|
|
2
|
+
import type { PiniaCustomProperties, Store, StoreDefinition } from "pinia";
|
|
3
|
+
import type { Ref } from "vue";
|
|
4
|
+
export type CustomStore<TStore, TState> = Store & TStore & TState & PiniaCustomProperties & StoreDefinition;
|
|
5
|
+
export type EmptyExtensions = Record<never, never>;
|
|
6
|
+
export interface DefineAStoreSetupExtensions<TEnhancedStore> {
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated Use enhancedStore instead.
|
|
9
|
+
*/
|
|
10
|
+
extending?: TEnhancedStore;
|
|
11
|
+
enhancedStore?: TEnhancedStore;
|
|
12
|
+
}
|
|
13
|
+
export interface DefineAStoreSetupContext<TEnhancedStore, TExtraExtensions extends Record<string, unknown> = EmptyExtensions> {
|
|
14
|
+
id: string;
|
|
15
|
+
extensions: DefineAStoreSetupExtensions<TEnhancedStore> & TExtraExtensions;
|
|
16
|
+
}
|
|
17
|
+
export type DefineAugmentedStore<TStore, TState> = (args?: any) => CustomStore<TStore, TState>;
|
|
18
|
+
export type ObjectBaseProperty = Record<string, OptionBaseProperty | OptionBaseProperty[]>;
|
|
19
|
+
export type OptionBaseProperty = string | number | boolean | null | undefined | object | Function;
|
|
20
|
+
export interface PluginStoreOptions {
|
|
21
|
+
storeOptions: StoreOptions;
|
|
22
|
+
}
|
|
23
|
+
export type StatePropertyValue = StdStatePropertyValue | Ref<StdStatePropertyValue> | StdStatePropertyValue[] | Ref<StdStatePropertyValue[]> | Ref<StdStatePropertyValue>[];
|
|
24
|
+
type StdStatePropertyValue = AnyObject | boolean | null | number | string | undefined;
|
|
25
|
+
export type StoreOptions = Record<string, StoreOptionsPropertyValue>;
|
|
26
|
+
export type StoreOptionsPropertyValue = OptionBaseProperty | OptionBaseProperty[] | ObjectBaseProperty | ObjectBaseProperty[];
|
|
27
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const pluginName: string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function defineStoreId(prefix: string, id: string): string;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { AnyObject } from "../types";
|
|
2
|
+
import type { Comparison } from "../types/comparison";
|
|
3
|
+
export declare function arrayObjectFindAllBy<T extends AnyObject>(arrayOfObject: T[], findBy: Partial<T>, comparison?: Comparison): T[];
|
|
4
|
+
export declare function arrayObjectFindBy<T extends AnyObject>(arrayOfObject: T[], findBy: Partial<T>): T | undefined;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { DefineStoreOptions, StateTree, StoreDefinition } from "pinia";
|
|
2
|
+
import type { AnyObject } from "../types";
|
|
3
|
+
import type { DefineAStoreSetupContext, EmptyExtensions, PluginStoreOptions, StoreOptions } from "../types/store";
|
|
4
|
+
export declare const itemState: {
|
|
5
|
+
'@id': undefined;
|
|
6
|
+
id: undefined;
|
|
7
|
+
};
|
|
8
|
+
type DefineAStoreSetup<TEnhancedStore, TExtraExtensions extends Record<string, unknown> = EmptyExtensions> = (ctx: DefineAStoreSetupContext<TEnhancedStore, TExtraExtensions>) => AnyObject;
|
|
9
|
+
export declare function defineAStore<Sto, Sta>(id: string, storeDefinition: Omit<DefineStoreOptions<string, StateTree & Sta, AnyObject, Partial<Sto>>, 'id'> | ((ctx?: DefineAStoreSetupContext<AnyObject>) => AnyObject), options?: StoreOptions): StoreDefinition & Sta & Sto;
|
|
10
|
+
export declare function defineAStoreCtx<Sto, Sta, TExtraExtensions extends Record<string, unknown> = EmptyExtensions>(id: string, storeDefinition: DefineAStoreSetup<Sto & Sta, TExtraExtensions>, options?: StoreOptions): StoreDefinition & Sta & Sto;
|
|
11
|
+
export declare function defineAStoreSetup(id: string, storeDefinition: DefineAStoreSetup<AnyObject>, options: PluginStoreOptions): StoreDefinition<string, Pick<AnyObject, keyof AnyObject>, Pick<AnyObject, keyof AnyObject>, Pick<AnyObject, keyof AnyObject>>;
|
|
12
|
+
export declare function defineAStoreOptionApi(id: string, storeDefinition: AnyObject, options?: PluginStoreOptions): StoreDefinition<string, {}, {}, {}>;
|
|
13
|
+
export declare function hasDeniedFirstChar(property: string): boolean;
|
|
14
|
+
export declare function getDefineAStoreSetupContext(store: AnyObject): DefineAStoreSetupContext<AnyObject> | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Get the enhanced store from the context.
|
|
17
|
+
* @param ctx The context containing the extensions.
|
|
18
|
+
* @returns The enhanced store casted to the specified types.
|
|
19
|
+
*/
|
|
20
|
+
export declare function getEnhancedStore<TEnhancedStore>(ctx: DefineAStoreSetupContext<TEnhancedStore>): TEnhancedStore;
|
|
21
|
+
/**
|
|
22
|
+
* Set the enhanced store in context with deprecated alias support.
|
|
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
|
+
/**
|
|
28
|
+
* @deprecated Use getEnhancedStore instead.
|
|
29
|
+
*/
|
|
30
|
+
export declare function getExtendingStore<TEnhancedStore>(ctx: DefineAStoreSetupContext<TEnhancedStore>): TEnhancedStore;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isEmpty(value: any): boolean;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AnyObject } from "../../types";
|
|
2
|
+
/**
|
|
3
|
+
* Compares objects to determine if they are identical
|
|
4
|
+
* @param {object} object1
|
|
5
|
+
* @param {object} object2
|
|
6
|
+
* @param {array} excludedKeys - name of properties not to be compared
|
|
7
|
+
* @returns {boolean} areIdentical
|
|
8
|
+
*/
|
|
9
|
+
export declare const areIdentical: (object1: AnyObject, object2: AnyObject, excludedKeys?: Set<string>) => boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pinia-plugin-subscription",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7-beta.1",
|
|
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,
|
|
@@ -26,13 +26,29 @@
|
|
|
26
26
|
],
|
|
27
27
|
"exports": {
|
|
28
28
|
".": {
|
|
29
|
-
"types": "./dist/
|
|
30
|
-
"import": "./dist/pinia-plugin-subscription.js"
|
|
31
|
-
|
|
29
|
+
"types": "./dist/lib/main.d.ts",
|
|
30
|
+
"import": "./dist/pinia-plugin-subscription.js"
|
|
31
|
+
},
|
|
32
|
+
"./helpers": {
|
|
33
|
+
"types": "./dist/helpers/index.d.ts",
|
|
34
|
+
"import": "./dist/helpers.js"
|
|
35
|
+
},
|
|
36
|
+
"./types": {
|
|
37
|
+
"types": "./dist/types/index.d.ts"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"main": "./dist/pinia-plugin-subscription.js",
|
|
41
|
+
"types": "./dist/lib/main.d.ts",
|
|
42
|
+
"typesVersions": {
|
|
43
|
+
"*": {
|
|
44
|
+
"helpers": [
|
|
45
|
+
"./dist/helpers/index.d.ts"
|
|
46
|
+
],
|
|
47
|
+
"types": [
|
|
48
|
+
"./dist/types/index.d.ts"
|
|
49
|
+
]
|
|
32
50
|
}
|
|
33
51
|
},
|
|
34
|
-
"main": "./dist/pinia-plugin-subscription.umd.cjs",
|
|
35
|
-
"types": "./dist/types/index.d.ts",
|
|
36
52
|
"files": [
|
|
37
53
|
"dist",
|
|
38
54
|
"CHANGELOG.md",
|
|
@@ -48,16 +64,27 @@
|
|
|
48
64
|
},
|
|
49
65
|
"scripts": {
|
|
50
66
|
"prebuild": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"",
|
|
51
|
-
"dev": "vite",
|
|
67
|
+
"dev": "vite --config vite.demo.config.ts",
|
|
68
|
+
"dev:library": "vite",
|
|
52
69
|
"test": "vitest",
|
|
53
70
|
"coverage": "vitest run --coverage",
|
|
54
|
-
"build": "vitest && vite build && tsc --emitDeclarationOnly --outDir dist",
|
|
55
|
-
"
|
|
71
|
+
"build": "vitest && vite build && tsc --emitDeclarationOnly --outDir dist && node scripts/measure-bundle.mjs",
|
|
72
|
+
"bundle:check": "vite build --config vite.config.ts && node scripts/measure-bundle.mjs",
|
|
73
|
+
"build:demo": "vite --config vite.demo.config.ts build",
|
|
74
|
+
"preview": "vite preview --config vite.demo.config.ts"
|
|
56
75
|
},
|
|
57
76
|
"peerDependencies": {
|
|
58
77
|
"pinia": "^2.0.0 || ^3.0.0",
|
|
59
78
|
"vue": "^3.0.0"
|
|
60
79
|
},
|
|
80
|
+
"peerDependenciesMeta": {
|
|
81
|
+
"pinia": {
|
|
82
|
+
"optional": false
|
|
83
|
+
},
|
|
84
|
+
"vue": {
|
|
85
|
+
"optional": false
|
|
86
|
+
}
|
|
87
|
+
},
|
|
61
88
|
"devDependencies": {
|
|
62
89
|
"@types/node": "^24.10.1",
|
|
63
90
|
"@vitejs/plugin-vue": "^6.0.1",
|