pinia-plugin-subscription 0.2.1 → 1.0.0-beta.0
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 +32 -1
- package/README.md +247 -3
- package/SECURITY.md +19 -1
- package/dist/chunks/constantes-BsD73jkk.js +245 -0
- package/dist/chunks/constantes-BsD73jkk.js.map +1 -0
- package/dist/core/PluginSubscriber.d.ts +36 -8
- package/dist/core/PluginSubscription.d.ts +20 -5
- package/dist/core/Store.d.ts +92 -11
- package/dist/factories/trace-registry.d.ts +6 -0
- package/dist/helpers/index.d.ts +5 -0
- package/dist/helpers.js +181 -5
- package/dist/helpers.js.map +1 -1
- package/dist/lib/main.d.ts +1 -3
- package/dist/pinia-plugin-subscription.js +207 -215
- package/dist/pinia-plugin-subscription.js.map +1 -1
- package/dist/plugins/createHydrationPlugin.d.ts +7 -0
- package/dist/plugins/createPlugin.d.ts +9 -2
- package/dist/system/Tracer.d.ts +20 -0
- package/dist/system/createConsoleTraceListener.d.ts +6 -0
- package/dist/types/index.d.ts +16 -5
- package/dist/types/plugin.d.ts +45 -6
- package/dist/types/store.d.ts +3 -5
- package/dist/types/trace.d.ts +80 -0
- package/docs/authoring-plugins.md +22 -23
- package/docs/using-plugins.md +56 -19
- package/package.json +3 -2
- package/dist/chunks/index-DKdl-fiq.js +0 -337
- package/dist/chunks/index-DKdl-fiq.js.map +0 -1
- package/dist/system/Debug.d.ts +0 -13
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constantes-BsD73jkk.js","sources":["../../src/core/PluginSubscriber.ts","../../src/utils/store.ts","../../src/utils/validation/index.ts","../../src/core/Store.ts"],"sourcesContent":["import Store from \"./Store\";\nimport type { PiniaPluginContext, Store as PiniaStore } from \"pinia\";\nimport type { AnyObject } from \"../types\";\nimport type {\n PluginExecutionOptions,\n PluginHydrationScheduler,\n PluginSubscriber as PluginSubscriberInterface,\n PluginSubscriptions,\n StoreMutationSubscription,\n StoreOnActionSubscription\n} from \"../types/plugin\";\nimport type Tracer from \"../system/Tracer\";\n\n\n\ntype CreateInstance<Instance = Store> = (store: PiniaStore, options: AnyObject) => Instance | undefined\n\n\n/**\n * Type definition for the function used to create an instance of a store.\n * @template Instance The type of the store instance, defaulting to the base Store class.\n * @param store The Pinia store for which the instance is being created.\n * @param options Additional options for creating the store instance.\n * @returns The created store instance or undefined if creation fails.\n */\nexport default abstract class PluginSubscriber<Instance extends Store> implements PluginSubscriberInterface {\n private _createInstance: CreateInstance\n private _name: string\n private _pluginOptions?: AnyObject\n private _storeInstance?: Instance\n /** Callback function to reset the store instance, if needed. */\n protected _resetStoreCallback?: (store?: PiniaStore) => void\n private _storeOnActionSubscription?: StoreOnActionSubscription\n private _storeMutationSubscription?: StoreMutationSubscription\n private _subscriptions?: PluginSubscriptions\n /**\n * Called when the plugin subscriber has been created for a specific store.\n * This callback can be used to perform any initialization or setup required for the plugin subscriber.\n */\n protected pluginCreated?: (store: PiniaStore) => void\n /** Options for the plugin subscriber's execution. */\n public execution?: PluginExecutionOptions\n /** Scheduler for handling the hydration process of the plugin subscriber. */\n public hydrationScheduler?: PluginHydrationScheduler\n\n\n get name(): string {\n return this._name;\n }\n\n get storeInstance(): Instance | undefined {\n return this._storeInstance\n }\n\n get pluginOptions(): AnyObject {\n return this._pluginOptions ?? {};\n }\n\n set pluginOptions(options: AnyObject | undefined) {\n this._pluginOptions = options;\n }\n\n get resetStoreCallback(): ((store?: PiniaStore) => void) | undefined {\n return this._resetStoreCallback as ((store?: PiniaStore) => void) | undefined;\n }\n\n get storeOnActionSubscription(): StoreOnActionSubscription | undefined {\n return this._storeOnActionSubscription;\n }\n\n get storeMutationSubscription(): StoreMutationSubscription | undefined {\n return this._storeMutationSubscription;\n }\n\n get subscriptions(): PluginSubscriptions | undefined {\n return this._subscriptions\n }\n\n set subscriptions(subscriptions: PluginSubscriptions) {\n this._subscriptions = subscriptions\n }\n\n\n constructor(pluginName: string, createInstanceFunction: CreateInstance) {\n this._name = pluginName\n this._createInstance = createInstanceFunction\n }\n\n /**\n * Called after the store has been hydrated.\n * @param context The Pinia plugin context containing the store and options.\n * @returns A promise that resolves when the post-hydration process is complete, or void if synchronous.\n */\n public afterHydration(context: PiniaPluginContext): void | Promise<void> {\n return\n }\n\n /**\n * Called when the plugin subscriber needs to hydrate its state.\n * @param context The Pinia plugin context containing the store and options.\n * @returns A promise that resolves when the hydration process is complete, or void if synchronous.\n */\n public hydrate(context: PiniaPluginContext): void | Promise<void> {\n return\n }\n\n /**\n * Invokes the plugin subscriber with the given context and optional tracer creation function.\n * @param context The Pinia plugin context containing the store and options.\n * @param createTracer Optional function to create a tracer for the plugin.\n * @returns True if the plugin was successfully invoked, otherwise false.\n */\n public invoke({ store, options }: PiniaPluginContext, createTracer?: (name: string) => Tracer): boolean {\n this._storeInstance = this._createInstance(store, { ...options, ...this.pluginOptions, createTracer }) as Instance\n\n if (!this._storeInstance) {\n return false\n }\n\n this._subscriptions = this._storeInstance.getSubscriptions()\n this._storeMutationSubscription = this._storeInstance.storeSubscribe\n this._storeOnActionSubscription = this._storeInstance.onAction\n\n if (this.pluginCreated) {\n this.pluginCreated(store)\n }\n\n return true\n }\n}","import { defineStore } from \"pinia\"\nimport type {\n DefineSetupStoreOptions,\n DefineStoreOptions,\n SetupStoreDefinition,\n StateTree,\n Store,\n StoreDefinition,\n _ExtractActionsFromSetupStore,\n _ExtractGettersFromSetupStore,\n _ExtractStateFromSetupStore,\n _GettersTree\n} from \"pinia\"\nimport type { AnyObject } from \"../types\"\nimport type {\n DefineAStoreDefinition,\n DefineAStoreSetupContext,\n EmptyExtensions,\n PluginStoreOptions,\n StoreOptions\n} from \"../types/store\"\n\n\nexport const itemState = {\n '@id': undefined,\n id: undefined\n}\n\ntype DefineAStoreSetup<SS, TExtraExtensions extends Record<string, unknown> = EmptyExtensions> =\n (ctx: DefineAStoreSetupContext<SS, TExtraExtensions>) => SS\n\n/**\n * Options parameter of pinia's `defineStore()` for setup stores, derived from\n * the setup function return type.\n */\ntype DefineAStoreSetupOptions<Id extends string, SS> = DefineSetupStoreOptions<\n Id,\n _ExtractStateFromSetupStore<SS>,\n _ExtractGettersFromSetupStore<SS>,\n _ExtractActionsFromSetupStore<SS>\n>\n\nconst defineAStoreSetupContexts = new WeakMap<object, DefineAStoreSetupContext<AnyObject>>()\nconst defineAStoreSetupContextsById = new Map<string, DefineAStoreSetupContext<AnyObject>>()\nconst setupContextDisposeWrappedStores = new WeakSet<object>()\n\nfunction registerSetupContextCleanupOnDispose(\n store: AnyObject,\n id: string\n): void {\n if (setupContextDisposeWrappedStores.has(store) || typeof store.$dispose !== 'function') {\n return\n }\n\n const originalDispose = store.$dispose as (...args: unknown[]) => unknown\n store.$dispose = (...args: unknown[]) => {\n defineAStoreSetupContexts.delete(store)\n defineAStoreSetupContextsById.delete(id)\n return originalDispose.apply(store, args)\n }\n setupContextDisposeWrappedStores.add(store)\n}\n\n/**\n * Define a store with the setup API. State, getters and actions are inferred\n * from the setup function return, exactly like pinia's `defineStore`, so\n * store members are listed by IDEs and action prototypes are preserved.\n * @template Id The type of the store identifier.\n * @template SS The type of the setup function return.\n * @param id The unique identifier for the store.\n * @param storeDefinition The setup function defining the store.\n * @param options Optional store options.\n * @returns The defined store.\n */\nexport function defineAStore<Id extends string, SS>(\n id: Id,\n storeDefinition: (ctx?: DefineAStoreSetupContext<AnyObject>) => SS,\n options?: StoreOptions\n): SetupStoreDefinition<Id, SS>\n/**\n * Define a store with the options API, mirroring pinia's `defineStore` inference.\n * @template Id The type of the store identifier.\n * @template S The type of the store's state.\n * @template G The type of the store's getters.\n * @template A The type of the store's actions.\n * @param id The unique identifier for the store.\n * @param storeDefinition The store options definition.\n * @param options Optional store options.\n * @returns The defined store.\n */\nexport function defineAStore<Id extends string, S extends StateTree = {}, G extends _GettersTree<S> = {}, A = {}>(\n id: Id,\n storeDefinition: Omit<DefineStoreOptions<Id, S, G, A>, 'id'>,\n options?: StoreOptions\n): StoreDefinition<Id, S, G, A>\n/**\n * Define a store with explicit store/state types, e.g. when plugins augment\n * the store with members not returned by the setup function.\n * @template Sto The type of the store.\n * @template Sta The type of the store's state.\n * @param id The unique identifier for the store.\n * @param storeDefinition The store definition, either as an options object or a setup function.\n * @param options Optional store options.\n * @returns The defined store.\n */\nexport function defineAStore<Sto, Sta>(\n id: string,\n storeDefinition:\n | Omit<DefineStoreOptions<string, StateTree & Sta, AnyObject, Partial<Sto>>, 'id'>\n | ((ctx?: DefineAStoreSetupContext<Sto & Sta>) => AnyObject),\n options?: StoreOptions\n): DefineAStoreDefinition<Sto, Sta>\nexport function defineAStore(\n id: string,\n storeDefinition:\n | Omit<DefineStoreOptions<string, StateTree, AnyObject, AnyObject>, 'id'>\n | DefineAStoreSetup<AnyObject>,\n options?: StoreOptions\n): StoreDefinition {\n const storeOptions: PluginStoreOptions = options ? { storeOptions: options } : {} as PluginStoreOptions\n\n return (typeof storeDefinition === 'function'\n ? defineAStoreSetup(\n id,\n storeDefinition as DefineAStoreSetup<AnyObject>,\n storeOptions\n )\n : defineAStoreOptionApi(\n id,\n storeDefinition,\n storeOptions\n )) as StoreDefinition\n}\n\n/**\n * Define a store with a required, fully typed setup context. State, getters\n * and actions are inferred from the setup function return.\n * @template Id The type of the store identifier.\n * @template SS The type of the setup function return.\n * @template TExtraExtensions The type of the store's extra extensions.\n * @param id The unique identifier for the store.\n * @param storeDefinition The setup function defining the store.\n * @param options Optional store options.\n * @returns The defined store with setup context.\n */\nexport function defineAStoreCtx<Id extends string, SS, TExtraExtensions extends Record<string, unknown> = EmptyExtensions>(\n id: Id,\n storeDefinition: (ctx: DefineAStoreSetupContext<AnyObject, TExtraExtensions>) => SS,\n options?: StoreOptions\n): SetupStoreDefinition<Id, SS>\n/**\n * Define a store with a setup context and explicit store/state types, e.g.\n * when plugins augment the store with members not returned by the setup function.\n * @template Sto The type of the store.\n * @template Sta The type of the store's state.\n * @template TExtraExtensions The type of the store's extra extensions.\n * @param id The unique identifier for the store.\n * @param storeDefinition The setup function defining the store.\n * @param options Optional store options.\n * @returns The defined store with setup context.\n */\nexport function defineAStoreCtx<Sto, Sta, TExtraExtensions extends Record<string, unknown> = EmptyExtensions>(\n id: string,\n storeDefinition: (ctx: DefineAStoreSetupContext<Sto & Sta, TExtraExtensions>) => AnyObject,\n options?: StoreOptions\n): DefineAStoreDefinition<Sto, Sta>\nexport function defineAStoreCtx(\n id: string,\n storeDefinition: DefineAStoreSetup<AnyObject, any>,\n options?: StoreOptions\n): StoreDefinition {\n const storeOptions: PluginStoreOptions = options\n ? { storeOptions: { ...options, enhancedStore: true } }\n : { storeOptions: { enhancedStore: true } } as PluginStoreOptions\n\n return defineAStoreSetup(\n id,\n storeDefinition,\n storeOptions\n ) as StoreDefinition\n}\n\nexport function defineAStoreSetup<Id extends string, SS>(\n id: Id,\n storeDefinition: DefineAStoreSetup<SS>,\n options: PluginStoreOptions\n): SetupStoreDefinition<Id, SS> {\n const setupContext: DefineAStoreSetupContext<SS> = {\n id,\n extensions: {}\n }\n\n const shouldStoreSetupContext = options?.storeOptions?.enhancedStore === true\n\n // `storeOptions` augments pinia's DefineStoreOptionsBase (see createPlugin.ts);\n // the assertion stays valid in compilation units where the augmentation is not loaded.\n const useStore = defineStore(\n id,\n () => storeDefinition(setupContext),\n options as unknown as DefineAStoreSetupOptions<Id, SS>\n )\n\n return Object.assign(((...args: Parameters<typeof useStore>) => {\n if (shouldStoreSetupContext) {\n defineAStoreSetupContextsById.set(id, setupContext as DefineAStoreSetupContext<AnyObject>)\n }\n\n const store = useStore(...args)\n\n if (shouldStoreSetupContext) {\n defineAStoreSetupContexts.set(store, setupContext as DefineAStoreSetupContext<AnyObject>)\n defineAStoreSetupContextsById.delete(id)\n registerSetupContextCleanupOnDispose(store as AnyObject, id)\n }\n\n return store\n }) as typeof useStore, useStore)\n}\n\nexport function defineAStoreOptionApi<Id extends string, S extends StateTree = {}, G extends _GettersTree<S> = {}, A = {}>(\n id: Id,\n storeDefinition: Omit<DefineStoreOptions<Id, S, G, A>, 'id'>,\n options?: PluginStoreOptions\n): StoreDefinition<Id, S, G, A> {\n if (options) {\n storeDefinition = { ...storeDefinition, ...(options ?? {}) }\n }\n\n return defineStore(id, storeDefinition)\n}\n\nconst deniedFirstChar = new Set<string>(['_', '$'])\n\n/**\n * Check if a property has a denied first character : ['_', '$'].\n * @param property The property name to check.\n * @returns True if the property has a denied first character, false otherwise.\n */\nexport function hasDeniedFirstChar(property: string): boolean {\n return deniedFirstChar.has(property[0] as string)\n}\n\n/**\n * Get the setup context associated with a store instance (or pending store id).\n * @param store The store instance, or an object exposing the store `$id`.\n * @returns The setup context when the store was defined with `enhancedStore` enabled, undefined otherwise.\n */\nexport function getDefineAStoreSetupContext(store: object): DefineAStoreSetupContext<AnyObject> | undefined {\n const storeRecord = store as AnyObject\n\n return defineAStoreSetupContexts.get(store)\n ?? (typeof storeRecord?.$id === 'string'\n ? defineAStoreSetupContextsById.get(storeRecord.$id)\n : undefined)\n}\n\n/**\n * Get the enhanced store from the context.\n * @template TEnhancedStore The type of the enhanced store.\n * @param ctx The context containing the extensions.\n * @returns The enhanced store casted to the specified types.\n */\nexport function getEnhancedStore<TEnhancedStore>(\n ctx: DefineAStoreSetupContext<TEnhancedStore>\n): TEnhancedStore {\n const enhancedStore = ctx.extensions.enhancedStore ?? ctx.extensions.extending\n\n if (!enhancedStore) {\n throw new Error(`${ctx.id}Store - getEnhancedStore - Error: enhanced store is required`)\n }\n\n return enhancedStore\n}\n\n/**\n * Set the enhanced store in context with deprecated alias support.\n * @template TEnhancedStore The type of the enhanced store.\n * @param ctx The context containing the extensions.\n * @param store The store to expose as enhancement.\n */\nexport function setEnhancedStore<TEnhancedStore>(\n ctx: DefineAStoreSetupContext<TEnhancedStore>,\n store: TEnhancedStore\n): void {\n ctx.extensions.enhancedStore = store\n ctx.extensions.extending = store\n}\n\n/**\n * @deprecated Use getEnhancedStore instead.\n */\nexport function getExtendingStore<TEnhancedStore>(\n ctx: DefineAStoreSetupContext<TEnhancedStore>\n): TEnhancedStore {\n console.warn(`${ctx.id}Store - getExtendingStore is deprecated. Use getEnhancedStore instead.`)\n return getEnhancedStore<TEnhancedStore>(ctx)\n}\n\n/**\n * Get the storage key for a given action and store combination.\n * @param actionName The name of the action.\n * @param store The Pinia store instance.\n * @returns The storage key for the action and store combination.\n */\nexport function getActionStoreKey(actionName: string, store: Store): string {\n return `${actionName}-${store.$id}`\n}","export function isEmpty(value: any): boolean {\n if (!value) {\n return (typeof value === 'boolean' || typeof value === 'number') ? false : true\n }\n\n if (Array.isArray(value)) {\n return value.length === 0\n }\n\n if (typeof value === 'object') {\n return Object.keys(value).length === 0\n }\n\n if (typeof value === 'string') {\n return value.trim() === ''\n }\n\n return false\n}","import { isRef, ref, toRef, type Ref } from \"vue\"\nimport Tracer from \"../system/Tracer\"\nimport { getDefineAStoreSetupContext, hasDeniedFirstChar, setEnhancedStore } from \"../utils/store\"\nimport { isEmpty } from \"../utils/validation\"\n\nimport type {\n PluginSubscriptionOptions,\n PluginSubscriptions,\n StoreMutationSubscription,\n StoreMutationSubscriptionCallback,\n StoreMutationSubscriptionReturn,\n StoreOnActionSubscription,\n StoreOnActionSubscriptionCallback,\n StoreOnActionSubscriptionReturn\n} from \"../types/plugin\"\nimport type { Store as PiniaStore, StateTree } from \"pinia\"\nimport type { TracePayload } from \"../types/trace\"\nimport type { AnyObject, PluginSubscriberInterface } from \"../types\"\nimport type { StoreOptions, StatePropertyValue, PluginStoreOptions } from \"../types/store\"\n\n/**\n * Base class for a Pinia store with enhanced capabilities.\n * Provides structured tracing, plugin subscriptions, and state management utilities.\n */\nexport default class Store {\n protected _className = 'Store'\n private _onAction?: StoreOnActionSubscriptionCallback\n private _options: StoreOptions\n private _store: PiniaStore\n private _subscriptions: PluginSubscriptions = {}\n private _storeSubscribe?: StoreMutationSubscriptionCallback\n private _tracer?: Tracer\n private _createTracer?: PluginSubscriptionOptions['createTracer']\n\n protected static _requiredKeys?: string[]\n\n get onAction(): StoreOnActionSubscription | undefined {\n if (!this._onAction) {\n return\n }\n\n return () => ({\n store: this.store as PiniaStore,\n callback: this._onAction\n }) as StoreOnActionSubscriptionReturn\n }\n\n set onAction(onAction: StoreOnActionSubscriptionCallback) {\n this._onAction = onAction\n }\n\n get options(): StoreOptions { return this._options }\n\n get state(): StateTree { return this._store.$state }\n\n set state(state: StateTree) { this._store.$state = state }\n\n get store(): AnyObject { return this._store }\n\n get storeSubscribe(): StoreMutationSubscription | undefined {\n if (!this._storeSubscribe) {\n return\n }\n\n return () => ({\n store: this.store as PiniaStore,\n callback: this._storeSubscribe\n }) as StoreMutationSubscriptionReturn\n }\n\n set storeSubscribe(storeSubscribe: StoreMutationSubscriptionCallback) {\n this._storeSubscribe = storeSubscribe\n }\n\n /**\n * Returns the structured trace emitter of this store.\n * Built lazily so that subclasses overriding `_className` are reflected.\n */\n protected get tracer(): Tracer | undefined {\n if (!this._tracer && this._createTracer) {\n this._tracer = this._createTracer(this._className)\n this._tracer.scope = this.store.$id\n }\n\n return this._tracer\n }\n\n constructor(store: PiniaStore, options: PluginStoreOptions & PluginSubscriptionOptions) {\n this._options = options.storeOptions\n this._store = store\n this.initializeTracer(options)\n\n if (this._options?.enhancedStore) {\n const ctx = getDefineAStoreSetupContext(this.store)\n\n if (ctx) {\n setEnhancedStore(ctx, this.store)\n }\n }\n }\n\n /**\n * Adds a property to the state of this store.\n * @param name The name of the property to add.\n * @param value The value of the property to add.\n */\n addToState(name: string, value?: StatePropertyValue): void {\n if (!this.isOptionApi()) {\n if (!isRef(value)) {\n value = ref<StatePropertyValue>(value)\n }\n }\n\n this.state[name] = value\n this.store[name] = toRef(this.state, name)\n }\n\n /**\n * Adds a subscription for a specific plugin to this store.\n * @param pluginName The name of the plugin for which the subscription is being added.\n * @param subscription The subscription callback or object to add.\n * @param options Additional options for the subscription, including subscription options and target stores.\n */\n addSubscription(\n pluginName: string,\n subscription: PluginSubscriberInterface,\n options?: { subscriptionOptions?: StoreOptions, stores?: PiniaStore[] }\n ): void {\n this._subscriptions[pluginName] = { subscription, ...(options ?? {}) }\n }\n\n /**\n * Called after the store has been hydrated.\n * @returns A promise that resolves when the post-hydration process is complete, or void if synchronous.\n */\n afterHydration(): void | Promise<void> {\n return\n }\n\n /**\n * Create and return a class instance\n * @param store \n * @param options \n * @returns \n */\n static customizeStore<Instance extends Store>(\n store: PiniaStore,\n options: PluginStoreOptions & PluginSubscriptionOptions\n ): Instance | undefined {\n if (options.storeOptions && this.hasRequiredKeys(options.storeOptions)) {\n return new this(store, options) as Instance\n }\n }\n\n /**\n * Retrieves the value of a specific store option.\n * @param optionName The name of the store option to retrieve.\n * @returns The value of the specified store option, or undefined if not found.\n */\n getOption(optionName: keyof StoreOptions) {\n return this.options && (this.options as StoreOptions)[optionName]\n }\n\n /**\n * Retrieves the value of a specific state property.\n * @param propertyName The name of the state property to retrieve.\n * @returns The value of the specified state property, or undefined if not found.\n */\n getStatePropertyValue(propertyName: string) {\n return this.getValue(this.state[propertyName])\n }\n\n /**\n * Retrieves all plugin subscriptions for this store.\n * @returns An object containing all plugin subscriptions, or undefined if there are none.\n */\n getSubscriptions(): PluginSubscriptions | undefined {\n if (isEmpty(this._subscriptions)) {\n return\n }\n\n return this._subscriptions\n }\n\n /**\n * Retrieves the actual value from a potentially reactive reference.\n * @param value The value to unwrap.\n * @returns The unwrapped value if it is a reactive reference, otherwise the original value.\n */\n getValue(value: any) {\n return value?.__v_isRef ? value.value : value\n }\n\n /**\n * Checks if the given property name has a denied first character.\n * @param property The property name to check.\n * @returns True if the property name has a denied first character, otherwise false.\n */\n protected hasDeniedFirstChar(property: string): boolean {\n return hasDeniedFirstChar(property)\n }\n\n /**\n * Checks if the given options object has all the required keys.\n * @param options The options object to check.\n * @returns True if all required keys are present, otherwise false.\n */\n protected static hasRequiredKeys(options: AnyObject): boolean {\n return this._requiredKeys !== undefined && this._requiredKeys?.every(requiredKey => !!options[requiredKey])\n }\n\n /**\n * Hydrates the store, potentially performing asynchronous operations.\n * @returns void or a Promise that resolves when hydration is complete.\n */\n hydrate(): void | Promise<void> {\n return\n }\n\n /**\n * Initializes the tracer for plugin subscriptions if the createTracer option is provided.\n * @param options The plugin subscription options containing the createTracer function.\n */\n private initializeTracer(options: PluginSubscriptionOptions) {\n this._createTracer = options?.createTracer\n }\n\n /**\n * Checks if the store is using the Options API.\n * @returns True if the store is using the Options API, otherwise false.\n */\n isOptionApi(): boolean { return this.store._isOptionsAPI }\n\n /**\n * Checks if the state object has the specified property.\n * @param property The property name to check.\n * @returns True if the state object has the property, otherwise false.\n */\n stateHas(property: string): boolean { return Object.prototype.hasOwnProperty.call(this.state, property) }\n\n /**\n * Checks if the store object has the specified property.\n * @param property The property name to check.\n * @returns True if the store object has the property, otherwise false.\n */\n storeHas(property: string): boolean { return Object.prototype.hasOwnProperty.call(this.store, property) }\n\n /**\n * Emits a structured trace event scoped to this store.\n * Prefer the factory form for `payload`: it is only resolved when consumed.\n */\n trace(namespace: string, payload?: TracePayload): void {\n if (this.tracer) {\n this.tracer.debug(namespace, payload)\n }\n }\n\n /**\n * Emits a structured error event, or rethrows it when no listener matches.\n */\n traceError(namespace: string, error: unknown, payload?: TracePayload): void {\n if (this.tracer) {\n this.tracer.error(namespace, error, payload)\n } else {\n console.error(error)\n }\n }\n}"],"names":["PluginSubscriber","pluginName","createInstanceFunction","__publicField","options","subscriptions","context","store","createTracer","defineAStoreSetupContexts","defineAStoreSetupContextsById","setupContextDisposeWrappedStores","registerSetupContextCleanupOnDispose","id","originalDispose","args","storeOptions","storeDefinition","defineAStoreSetup","defineAStoreOptionApi","defineAStoreCtx","setupContext","shouldStoreSetupContext","useStore","defineStore","deniedFirstChar","property","getDefineAStoreSetupContext","storeRecord","getEnhancedStore","ctx","enhancedStore","setEnhancedStore","getExtendingStore","getActionStoreKey","actionName","isEmpty","value","Store","onAction","state","storeSubscribe","name","isRef","ref","subscription","optionName","propertyName","hasDeniedFirstChar","requiredKey","namespace","payload","error"],"mappings":";;;;;AAyBA,MAA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ACpC;AAAA,EAAA,WAAAD,GAAAE,GAAAD,GAAA;AAAA,IAAA,KAAA,qBAMA,MAAoDD,GAAAE,GAAAD,CAAA,IAE5C,QAAA,MAAAC,CAAA;AAAA,EAGJ;AAAY;AD1KhBjD,EAXGmC,GAWH;AC2KA,MAAArC,IAAA;"}
|
|
@@ -2,22 +2,34 @@ import Store from "./Store";
|
|
|
2
2
|
import type { PiniaPluginContext, Store as PiniaStore } from "pinia";
|
|
3
3
|
import type { AnyObject } from "../types";
|
|
4
4
|
import type { PluginExecutionOptions, PluginHydrationScheduler, PluginSubscriber as PluginSubscriberInterface, PluginSubscriptions, StoreMutationSubscription, StoreOnActionSubscription } from "../types/plugin";
|
|
5
|
-
import type
|
|
6
|
-
type CreateInstance<Instance = Store> = (store: PiniaStore, options: AnyObject
|
|
5
|
+
import type Tracer from "../system/Tracer";
|
|
6
|
+
type CreateInstance<Instance = Store> = (store: PiniaStore, options: AnyObject) => Instance | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* Type definition for the function used to create an instance of a store.
|
|
9
|
+
* @template Instance The type of the store instance, defaulting to the base Store class.
|
|
10
|
+
* @param store The Pinia store for which the instance is being created.
|
|
11
|
+
* @param options Additional options for creating the store instance.
|
|
12
|
+
* @returns The created store instance or undefined if creation fails.
|
|
13
|
+
*/
|
|
7
14
|
export default abstract class PluginSubscriber<Instance extends Store> implements PluginSubscriberInterface {
|
|
8
|
-
private _console?;
|
|
9
15
|
private _createInstance;
|
|
10
16
|
private _name;
|
|
11
17
|
private _pluginOptions?;
|
|
12
18
|
private _storeInstance?;
|
|
19
|
+
/** Callback function to reset the store instance, if needed. */
|
|
13
20
|
protected _resetStoreCallback?: (store?: PiniaStore) => void;
|
|
14
21
|
private _storeOnActionSubscription?;
|
|
15
22
|
private _storeMutationSubscription?;
|
|
16
23
|
private _subscriptions?;
|
|
24
|
+
/**
|
|
25
|
+
* Called when the plugin subscriber has been created for a specific store.
|
|
26
|
+
* This callback can be used to perform any initialization or setup required for the plugin subscriber.
|
|
27
|
+
*/
|
|
17
28
|
protected pluginCreated?: (store: PiniaStore) => void;
|
|
29
|
+
/** Options for the plugin subscriber's execution. */
|
|
18
30
|
execution?: PluginExecutionOptions;
|
|
31
|
+
/** Scheduler for handling the hydration process of the plugin subscriber. */
|
|
19
32
|
hydrationScheduler?: PluginHydrationScheduler;
|
|
20
|
-
get console(): Console;
|
|
21
33
|
get name(): string;
|
|
22
34
|
get storeInstance(): Instance | undefined;
|
|
23
35
|
get pluginOptions(): AnyObject;
|
|
@@ -27,9 +39,25 @@ export default abstract class PluginSubscriber<Instance extends Store> implement
|
|
|
27
39
|
get storeMutationSubscription(): StoreMutationSubscription | undefined;
|
|
28
40
|
get subscriptions(): PluginSubscriptions | undefined;
|
|
29
41
|
set subscriptions(subscriptions: PluginSubscriptions);
|
|
30
|
-
constructor(pluginName: string, createInstanceFunction: CreateInstance
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
42
|
+
constructor(pluginName: string, createInstanceFunction: CreateInstance);
|
|
43
|
+
/**
|
|
44
|
+
* Called after the store has been hydrated.
|
|
45
|
+
* @param context The Pinia plugin context containing the store and options.
|
|
46
|
+
* @returns A promise that resolves when the post-hydration process is complete, or void if synchronous.
|
|
47
|
+
*/
|
|
48
|
+
afterHydration(context: PiniaPluginContext): void | Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Called when the plugin subscriber needs to hydrate its state.
|
|
51
|
+
* @param context The Pinia plugin context containing the store and options.
|
|
52
|
+
* @returns A promise that resolves when the hydration process is complete, or void if synchronous.
|
|
53
|
+
*/
|
|
54
|
+
hydrate(context: PiniaPluginContext): void | Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Invokes the plugin subscriber with the given context and optional tracer creation function.
|
|
57
|
+
* @param context The Pinia plugin context containing the store and options.
|
|
58
|
+
* @param createTracer Optional function to create a tracer for the plugin.
|
|
59
|
+
* @returns True if the plugin was successfully invoked, otherwise false.
|
|
60
|
+
*/
|
|
61
|
+
invoke({ store, options }: PiniaPluginContext, createTracer?: (name: string) => Tracer): boolean;
|
|
34
62
|
}
|
|
35
63
|
export {};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import Debug from "../system/Debug";
|
|
2
1
|
import type { PiniaPluginContext } from "pinia";
|
|
3
2
|
import type { PluginSubscriber, PluginSubscriptionOptions, PluginSubscriptions } from "../types/plugin";
|
|
4
|
-
export default class PluginSubscription
|
|
3
|
+
export default class PluginSubscription {
|
|
5
4
|
protected _className: string;
|
|
6
5
|
private _hydrationScheduler;
|
|
7
6
|
private _onActionSubscriptions;
|
|
@@ -9,7 +8,6 @@ export default class PluginSubscription extends Debug {
|
|
|
9
8
|
private _onActionAfterSubscriptions;
|
|
10
9
|
private _onActionOnErrorSubscriptions;
|
|
11
10
|
private _options?;
|
|
12
|
-
private _pluginDebug?;
|
|
13
11
|
private _resetStoreCallback;
|
|
14
12
|
private _disposedStores;
|
|
15
13
|
private _storeRollbackSnapshotsHandler;
|
|
@@ -19,9 +17,10 @@ export default class PluginSubscription extends Debug {
|
|
|
19
17
|
private _subscriptions;
|
|
20
18
|
private _subscriptionsDelivered;
|
|
21
19
|
private _subscriptionsScheduled;
|
|
20
|
+
private _tracer?;
|
|
22
21
|
set subscribers(subscribers: PluginSubscriber[]);
|
|
23
22
|
get subscriptions(): PluginSubscriptions[] | undefined;
|
|
24
|
-
constructor(subscribers: PluginSubscriber[],
|
|
23
|
+
constructor(subscribers: PluginSubscriber[], options?: PluginSubscriptionOptions);
|
|
25
24
|
private addOnActionAfterCallback;
|
|
26
25
|
private addOnActionOnErrorCallback;
|
|
27
26
|
private addResetStoreCallback;
|
|
@@ -49,7 +48,6 @@ export default class PluginSubscription extends Debug {
|
|
|
49
48
|
*/
|
|
50
49
|
private createRollbackSnapshot;
|
|
51
50
|
private defineCurrentEnvironment;
|
|
52
|
-
private definePluginDebug;
|
|
53
51
|
private definePluginExecution;
|
|
54
52
|
private defineHydrationScheduler;
|
|
55
53
|
private defineSubscriberKey;
|
|
@@ -64,6 +62,14 @@ export default class PluginSubscription extends Debug {
|
|
|
64
62
|
private executeStoreOnActionSubscription;
|
|
65
63
|
private executeSubscriber;
|
|
66
64
|
private executeSubscriberSafely;
|
|
65
|
+
private initializeTracer;
|
|
66
|
+
/**
|
|
67
|
+
* Invokes the plugin with the given Pinia plugin context, executing all relevant subscribers safely.
|
|
68
|
+
* @param param0 The Pinia plugin context containing the store and options.
|
|
69
|
+
* @param param0.store The Pinia store instance.
|
|
70
|
+
* @param param0.options The options passed to the Pinia store.
|
|
71
|
+
* @returns void
|
|
72
|
+
*/
|
|
67
73
|
plugin({ store, options }: PiniaPluginContext): void;
|
|
68
74
|
private queueSubscriberExecution;
|
|
69
75
|
private registerStoreCleanup;
|
|
@@ -74,4 +80,13 @@ export default class PluginSubscription extends Debug {
|
|
|
74
80
|
private storeMutationSubscription;
|
|
75
81
|
private subscriptionDelivery;
|
|
76
82
|
private subscriptionDeliverySafely;
|
|
83
|
+
/**
|
|
84
|
+
* Emits a structured trace event.
|
|
85
|
+
* Prefer the factory form for `payload`: it is only resolved when consumed.
|
|
86
|
+
*/
|
|
87
|
+
private trace;
|
|
88
|
+
/**
|
|
89
|
+
* Emits a structured error event, or rethrows it when no listener matches.
|
|
90
|
+
*/
|
|
91
|
+
private traceError;
|
|
77
92
|
}
|
package/dist/core/Store.d.ts
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type { PluginSubscriptions, StoreMutationSubscription, StoreMutationSubscriptionCallback, StoreOnActionSubscription, StoreOnActionSubscriptionCallback } from "../types/plugin";
|
|
1
|
+
import Tracer from "../system/Tracer";
|
|
2
|
+
import type { PluginSubscriptionOptions, PluginSubscriptions, StoreMutationSubscription, StoreMutationSubscriptionCallback, StoreOnActionSubscription, StoreOnActionSubscriptionCallback } from "../types/plugin";
|
|
3
3
|
import type { Store as PiniaStore, StateTree } from "pinia";
|
|
4
|
-
import type {
|
|
4
|
+
import type { TracePayload } from "../types/trace";
|
|
5
5
|
import type { AnyObject, PluginSubscriberInterface } from "../types";
|
|
6
|
-
import type { StoreOptions, StatePropertyValue } from "../types/store";
|
|
7
|
-
|
|
6
|
+
import type { StoreOptions, StatePropertyValue, PluginStoreOptions } from "../types/store";
|
|
7
|
+
/**
|
|
8
|
+
* Base class for a Pinia store with enhanced capabilities.
|
|
9
|
+
* Provides structured tracing, plugin subscriptions, and state management utilities.
|
|
10
|
+
*/
|
|
11
|
+
export default class Store {
|
|
8
12
|
protected _className: string;
|
|
9
13
|
private _onAction?;
|
|
10
14
|
private _options;
|
|
11
15
|
private _store;
|
|
12
16
|
private _subscriptions;
|
|
13
17
|
private _storeSubscribe?;
|
|
18
|
+
private _tracer?;
|
|
19
|
+
private _createTracer?;
|
|
14
20
|
protected static _requiredKeys?: string[];
|
|
15
21
|
get onAction(): StoreOnActionSubscription | undefined;
|
|
16
22
|
set onAction(onAction: StoreOnActionSubscriptionCallback);
|
|
@@ -20,34 +26,109 @@ export default class Store extends Debug {
|
|
|
20
26
|
get store(): AnyObject;
|
|
21
27
|
get storeSubscribe(): StoreMutationSubscription | undefined;
|
|
22
28
|
set storeSubscribe(storeSubscribe: StoreMutationSubscriptionCallback);
|
|
23
|
-
constructor(store: PiniaStore, options: AnyObject, debug?: boolean, customConsole?: Console);
|
|
24
29
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
|
|
30
|
+
* Returns the structured trace emitter of this store.
|
|
31
|
+
* Built lazily so that subclasses overriding `_className` are reflected.
|
|
32
|
+
*/
|
|
33
|
+
protected get tracer(): Tracer | undefined;
|
|
34
|
+
constructor(store: PiniaStore, options: PluginStoreOptions & PluginSubscriptionOptions);
|
|
35
|
+
/**
|
|
36
|
+
* Adds a property to the state of this store.
|
|
37
|
+
* @param name The name of the property to add.
|
|
38
|
+
* @param value The value of the property to add.
|
|
28
39
|
*/
|
|
29
40
|
addToState(name: string, value?: StatePropertyValue): void;
|
|
41
|
+
/**
|
|
42
|
+
* Adds a subscription for a specific plugin to this store.
|
|
43
|
+
* @param pluginName The name of the plugin for which the subscription is being added.
|
|
44
|
+
* @param subscription The subscription callback or object to add.
|
|
45
|
+
* @param options Additional options for the subscription, including subscription options and target stores.
|
|
46
|
+
*/
|
|
30
47
|
addSubscription(pluginName: string, subscription: PluginSubscriberInterface, options?: {
|
|
31
48
|
subscriptionOptions?: StoreOptions;
|
|
32
49
|
stores?: PiniaStore[];
|
|
33
50
|
}): void;
|
|
51
|
+
/**
|
|
52
|
+
* Called after the store has been hydrated.
|
|
53
|
+
* @returns A promise that resolves when the post-hydration process is complete, or void if synchronous.
|
|
54
|
+
*/
|
|
34
55
|
afterHydration(): void | Promise<void>;
|
|
35
56
|
/**
|
|
36
57
|
* Create and return a class instance
|
|
37
58
|
* @param store
|
|
38
59
|
* @param options
|
|
39
|
-
* @param debug
|
|
40
60
|
* @returns
|
|
41
61
|
*/
|
|
42
|
-
static customizeStore<Instance extends Store>(store: PiniaStore, options:
|
|
62
|
+
static customizeStore<Instance extends Store>(store: PiniaStore, options: PluginStoreOptions & PluginSubscriptionOptions): Instance | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* Retrieves the value of a specific store option.
|
|
65
|
+
* @param optionName The name of the store option to retrieve.
|
|
66
|
+
* @returns The value of the specified store option, or undefined if not found.
|
|
67
|
+
*/
|
|
43
68
|
getOption(optionName: keyof StoreOptions): import("../types").StoreOptionsPropertyValue;
|
|
69
|
+
/**
|
|
70
|
+
* Retrieves the value of a specific state property.
|
|
71
|
+
* @param propertyName The name of the state property to retrieve.
|
|
72
|
+
* @returns The value of the specified state property, or undefined if not found.
|
|
73
|
+
*/
|
|
44
74
|
getStatePropertyValue(propertyName: string): any;
|
|
75
|
+
/**
|
|
76
|
+
* Retrieves all plugin subscriptions for this store.
|
|
77
|
+
* @returns An object containing all plugin subscriptions, or undefined if there are none.
|
|
78
|
+
*/
|
|
45
79
|
getSubscriptions(): PluginSubscriptions | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* Retrieves the actual value from a potentially reactive reference.
|
|
82
|
+
* @param value The value to unwrap.
|
|
83
|
+
* @returns The unwrapped value if it is a reactive reference, otherwise the original value.
|
|
84
|
+
*/
|
|
46
85
|
getValue(value: any): any;
|
|
86
|
+
/**
|
|
87
|
+
* Checks if the given property name has a denied first character.
|
|
88
|
+
* @param property The property name to check.
|
|
89
|
+
* @returns True if the property name has a denied first character, otherwise false.
|
|
90
|
+
*/
|
|
47
91
|
protected hasDeniedFirstChar(property: string): boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Checks if the given options object has all the required keys.
|
|
94
|
+
* @param options The options object to check.
|
|
95
|
+
* @returns True if all required keys are present, otherwise false.
|
|
96
|
+
*/
|
|
48
97
|
protected static hasRequiredKeys(options: AnyObject): boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Hydrates the store, potentially performing asynchronous operations.
|
|
100
|
+
* @returns void or a Promise that resolves when hydration is complete.
|
|
101
|
+
*/
|
|
49
102
|
hydrate(): void | Promise<void>;
|
|
103
|
+
/**
|
|
104
|
+
* Initializes the tracer for plugin subscriptions if the createTracer option is provided.
|
|
105
|
+
* @param options The plugin subscription options containing the createTracer function.
|
|
106
|
+
*/
|
|
107
|
+
private initializeTracer;
|
|
108
|
+
/**
|
|
109
|
+
* Checks if the store is using the Options API.
|
|
110
|
+
* @returns True if the store is using the Options API, otherwise false.
|
|
111
|
+
*/
|
|
50
112
|
isOptionApi(): boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Checks if the state object has the specified property.
|
|
115
|
+
* @param property The property name to check.
|
|
116
|
+
* @returns True if the state object has the property, otherwise false.
|
|
117
|
+
*/
|
|
51
118
|
stateHas(property: string): boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Checks if the store object has the specified property.
|
|
121
|
+
* @param property The property name to check.
|
|
122
|
+
* @returns True if the store object has the property, otherwise false.
|
|
123
|
+
*/
|
|
52
124
|
storeHas(property: string): boolean;
|
|
125
|
+
/**
|
|
126
|
+
* Emits a structured trace event scoped to this store.
|
|
127
|
+
* Prefer the factory form for `payload`: it is only resolved when consumed.
|
|
128
|
+
*/
|
|
129
|
+
trace(namespace: string, payload?: TracePayload): void;
|
|
130
|
+
/**
|
|
131
|
+
* Emits a structured error event, or rethrows it when no listener matches.
|
|
132
|
+
*/
|
|
133
|
+
traceError(namespace: string, error: unknown, payload?: TracePayload): void;
|
|
53
134
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { TraceRegistry } from '../types/trace';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a registry for managing trace listeners and creating tracers.
|
|
4
|
+
* @returns An object containing methods to add and clear trace listeners, and to create tracers.
|
|
5
|
+
*/
|
|
6
|
+
export declare function createTracerRegistry(): TraceRegistry;
|
package/dist/helpers/index.d.ts
CHANGED
|
@@ -2,3 +2,8 @@ export { default as PluginSubscriber } from '../core/PluginSubscriber';
|
|
|
2
2
|
export { default as Store } from '../core/Store';
|
|
3
3
|
export { CustomConsole } from '../system/log';
|
|
4
4
|
export { isEmpty } from '../utils/validation';
|
|
5
|
+
export type { Console, LogType, StyleDefinition, StyleDefinitionKeys, StyleDefinitions, ConsoleStyleDefinition, ConsoleStyleDefinitionKeys, ConsoleStyleDefinitions } from "../types";
|
|
6
|
+
export type { TraceEvent, TraceEventMetadata, TraceFilter, TraceHandler, TraceLevel, TraceListener, TraceListenerRemover, TracePayload, TraceRegistry, TracerOptions } from "../types/trace";
|
|
7
|
+
export { createTracerRegistry } from "../factories/trace-registry";
|
|
8
|
+
export { default as Tracer } from "../system/Tracer";
|
|
9
|
+
export { createConsoleTraceListener } from "../system/createConsoleTraceListener";
|
package/dist/helpers.js
CHANGED
|
@@ -1,8 +1,184 @@
|
|
|
1
|
-
|
|
1
|
+
var g = Object.defineProperty;
|
|
2
|
+
var p = (e, r, o) => r in e ? g(e, r, { enumerable: !0, configurable: !0, writable: !0, value: o }) : e[r] = o;
|
|
3
|
+
var t = (e, r, o) => p(e, typeof r != "symbol" ? r + "" : r, o);
|
|
4
|
+
import { p as h } from "./chunks/constantes-BsD73jkk.js";
|
|
5
|
+
import { P as E, S as M, i as B } from "./chunks/constantes-BsD73jkk.js";
|
|
6
|
+
const d = (e, r = "white") => `background-color: ${e}; color: ${r}; padding: 1px; margin-right: 5px; font-size: 12px`;
|
|
7
|
+
function _(e, r) {
|
|
8
|
+
if (!e)
|
|
9
|
+
throw new Error("Style instructions are required");
|
|
10
|
+
console.log(
|
|
11
|
+
"%c%s",
|
|
12
|
+
e,
|
|
13
|
+
r.shift(),
|
|
14
|
+
...r
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
class y {
|
|
18
|
+
constructor() {
|
|
19
|
+
t(this, "_bgColor", "#ffec73");
|
|
20
|
+
t(this, "_color", "green");
|
|
21
|
+
t(this, "_icon", "🍍⚡");
|
|
22
|
+
t(this, "_errorBgColor", "#d24545");
|
|
23
|
+
t(this, "_errorColor", "white");
|
|
24
|
+
t(this, "_errorIcon", "🍍⚠️");
|
|
25
|
+
t(this, "_styles", {
|
|
26
|
+
error: { bgColor: this._errorBgColor, color: this._errorColor, icon: this._errorIcon },
|
|
27
|
+
info: { bgColor: this._bgColor, color: this._color, icon: this._icon }
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
formatMessage(r, o) {
|
|
31
|
+
return ` [${o} ${h}] - ${r} `;
|
|
32
|
+
}
|
|
33
|
+
generateStyle(r) {
|
|
34
|
+
return d(r.bgColor, r.color);
|
|
35
|
+
}
|
|
36
|
+
getStyleDefinition(r) {
|
|
37
|
+
return this._styles[r ?? "info"];
|
|
38
|
+
}
|
|
39
|
+
log(...r) {
|
|
40
|
+
this.useLog(
|
|
41
|
+
this.getStyleDefinition(),
|
|
42
|
+
r
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
error(...r) {
|
|
46
|
+
this.useLog(
|
|
47
|
+
this.getStyleDefinition("error"),
|
|
48
|
+
r
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
rebuildArgs(r, o) {
|
|
52
|
+
if (typeof r == "string")
|
|
53
|
+
return [this.formatMessage(r, o)];
|
|
54
|
+
if (Array.isArray(r))
|
|
55
|
+
return [this.formatMessage(r.shift(), o), ...r ?? []];
|
|
56
|
+
}
|
|
57
|
+
useLog(r, o) {
|
|
58
|
+
_(
|
|
59
|
+
this.generateStyle(r),
|
|
60
|
+
this.rebuildArgs(o, r.icon)
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
class m extends y {
|
|
65
|
+
constructor() {
|
|
66
|
+
super(...arguments);
|
|
67
|
+
t(this, "_pluginName", h);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const C = new m();
|
|
71
|
+
function b(e) {
|
|
72
|
+
if (typeof e != "function")
|
|
73
|
+
return e;
|
|
74
|
+
try {
|
|
75
|
+
return e();
|
|
76
|
+
} catch (r) {
|
|
77
|
+
return { __tracePayloadError: r };
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
class T {
|
|
81
|
+
constructor(r, o, s = {}) {
|
|
82
|
+
t(this, "_listeners", []);
|
|
83
|
+
t(this, "_scope");
|
|
84
|
+
t(this, "_source");
|
|
85
|
+
this._scope = s.scope, this._source = r, this._listeners = o;
|
|
86
|
+
}
|
|
87
|
+
get scope() {
|
|
88
|
+
return this._scope;
|
|
89
|
+
}
|
|
90
|
+
set scope(r) {
|
|
91
|
+
this._scope = r;
|
|
92
|
+
}
|
|
93
|
+
get source() {
|
|
94
|
+
return this._source;
|
|
95
|
+
}
|
|
96
|
+
debug(r, o, s) {
|
|
97
|
+
this.emit("debug", r, o, s);
|
|
98
|
+
}
|
|
99
|
+
error(r, o, s, n) {
|
|
100
|
+
this.emit("error", r, s, n, o);
|
|
101
|
+
}
|
|
102
|
+
emit(r, o, s, n, i) {
|
|
103
|
+
if (this._listeners.length === 0) {
|
|
104
|
+
r === "error" && console.error("Unhandled error trace event:", i);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const a = {
|
|
108
|
+
level: r,
|
|
109
|
+
namespace: o,
|
|
110
|
+
scope: n ?? this._scope,
|
|
111
|
+
source: this._source
|
|
112
|
+
}, u = this._listeners.filter((c) => {
|
|
113
|
+
if (!c.filter)
|
|
114
|
+
return !0;
|
|
115
|
+
try {
|
|
116
|
+
return c.filter(a);
|
|
117
|
+
} catch (l) {
|
|
118
|
+
return console.error("Error in trace listener filter:", l), !1;
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
if (u.length === 0) {
|
|
122
|
+
r === "error" && console.error("Unhandled error trace event:", i);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const f = {
|
|
126
|
+
...a,
|
|
127
|
+
...i !== void 0 && { error: i },
|
|
128
|
+
...s !== void 0 && { payload: b(s) },
|
|
129
|
+
timestamp: Date.now()
|
|
130
|
+
};
|
|
131
|
+
for (const c of u)
|
|
132
|
+
try {
|
|
133
|
+
c.handler(f);
|
|
134
|
+
} catch (l) {
|
|
135
|
+
console.error("Error in trace listener:", l);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function S() {
|
|
140
|
+
const e = [];
|
|
141
|
+
function r(n) {
|
|
142
|
+
return e.push(n), () => {
|
|
143
|
+
const i = e.indexOf(n);
|
|
144
|
+
i !== -1 && e.splice(i, 1);
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
function o() {
|
|
148
|
+
e.length = 0;
|
|
149
|
+
}
|
|
150
|
+
function s() {
|
|
151
|
+
return e.length > 0;
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
addTraceListener: r,
|
|
155
|
+
clearTraceListeners: o,
|
|
156
|
+
createTracer: (n, i = {}) => new T(n, e, i),
|
|
157
|
+
hasTraceListeners: s
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
function $(e) {
|
|
161
|
+
return e.scope ? `${e.source} - ${e.namespace} [${e.scope}]` : `${e.source} - ${e.namespace}`;
|
|
162
|
+
}
|
|
163
|
+
function w(e = C) {
|
|
164
|
+
return {
|
|
165
|
+
handler(r) {
|
|
166
|
+
const o = [$(r)];
|
|
167
|
+
if (r.error !== void 0 && o.push(r.error), r.payload !== void 0 && (Array.isArray(r.payload) ? o.push(...r.payload) : o.push(r.payload)), r.level === "error") {
|
|
168
|
+
e.error(...o);
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
e.log(...o);
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
}
|
|
2
175
|
export {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
176
|
+
y as CustomConsole,
|
|
177
|
+
E as PluginSubscriber,
|
|
178
|
+
M as Store,
|
|
179
|
+
T as Tracer,
|
|
180
|
+
w as createConsoleTraceListener,
|
|
181
|
+
S as createTracerRegistry,
|
|
182
|
+
B as isEmpty
|
|
7
183
|
};
|
|
8
184
|
//# sourceMappingURL=helpers.js.map
|
package/dist/helpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
1
|
+
{"version":3,"file":"helpers.js","sources":["../src/system/log.ts","../src/system/Tracer.ts","../src/factories/trace-registry.ts","../src/system/createConsoleTraceListener.ts"],"sourcesContent":["import { pluginName } from '../utils/constantes'\nimport type { Console, LogType, StyleDefinition, StyleDefinitions } from '../types/log'\n\n\nconst style = (bgColor: string, color: string = 'white') =>\n `background-color: ${bgColor}; color: ${color}; padding: 1px; margin-right: 5px; font-size: 12px`\n\n\nexport function log(logStyle: string, args: any) {\n if (!logStyle) {\n throw new Error('Style instructions are required')\n }\n\n console.log(\n '%c%s',\n logStyle,\n args.shift(),\n ...args\n )\n}\n\nexport abstract class CustomConsole implements Console {\n protected _bgColor: string = '#ffec73'\n protected _color: string = 'green'\n protected _icon: string = '🍍⚡'\n protected _errorBgColor: string = '#d24545'\n protected _errorColor: string = 'white'\n protected _errorIcon: string = '🍍⚠️'\n protected abstract _pluginName: string\n protected _styles: StyleDefinitions = {\n error: { bgColor: this._errorBgColor, color: this._errorColor, icon: this._errorIcon },\n info: { bgColor: this._bgColor, color: this._color, icon: this._icon }\n }\n\n protected formatMessage(message: string, icon: string): string {\n return ` [${icon} ${pluginName}] - ${message} `\n }\n\n protected generateStyle(styleDefinition: StyleDefinition): string {\n return style(styleDefinition.bgColor, styleDefinition.color)\n }\n\n protected getStyleDefinition(messageType?: LogType): StyleDefinition {\n return this._styles[messageType ?? 'info']\n }\n\n log(...args: any) {\n this.useLog(\n this.getStyleDefinition(),\n args\n )\n }\n\n error(...args: any) {\n const logType = 'error'\n this.useLog(\n this.getStyleDefinition(logType),\n args\n )\n }\n\n protected rebuildArgs(args: string | any[], icon: string) {\n if (typeof args === 'string') {\n return [this.formatMessage(args, icon)]\n }\n\n if (Array.isArray(args)) {\n return [this.formatMessage(args.shift(), icon), ...(args ?? [])]\n }\n }\n\n protected useLog(styleDefinition: StyleDefinition, args: any) {\n log(\n this.generateStyle(styleDefinition),\n this.rebuildArgs(args, styleDefinition.icon)\n )\n }\n}\n\nclass PluginConsoleClass extends CustomConsole {\n protected _pluginName: string = pluginName\n}\n\nexport const PluginConsole = new PluginConsoleClass()","import type { AnyObject } from '../types'\nimport type {\n TraceEvent,\n TraceEventMetadata,\n TraceLevel,\n TraceListener,\n TraceListenerRemover,\n TracePayload,\n TracerOptions,\n} from '../types/trace'\n\nfunction resolvePayload(payload: TracePayload): AnyObject | undefined {\n if (typeof payload !== 'function') {\n return payload\n }\n\n try {\n return payload()\n } catch (error) {\n return { __tracePayloadError: error }\n }\n}\n\n/**\n * Emits structured trace events.\n *\n * Nothing is allocated when no listener matches:\n * the payload is a factory resolved only once a consumer is known.\n */\nexport default class Tracer {\n private readonly _listeners: TraceListener[] = []\n private _scope?: string\n private readonly _source: string\n\n constructor(source: string, listeners: TraceListener[], options: TracerOptions = {}) {\n this._scope = options.scope\n this._source = source\n this._listeners = listeners\n }\n\n get scope(): string | undefined {\n return this._scope\n }\n\n set scope(scope: string | undefined) {\n this._scope = scope\n }\n\n get source(): string {\n return this._source\n }\n\n debug(namespace: string, payload?: TracePayload, scope?: string): void {\n this.emit('debug', namespace, payload, scope)\n }\n\n /** Relays the error to matching listeners, or reports it when none match. */\n error(namespace: string, error: unknown, payload?: TracePayload, scope?: string): void {\n this.emit('error', namespace, payload, scope, error)\n }\n\n private emit(\n level: TraceLevel,\n namespace: string,\n payload?: TracePayload,\n scope?: string,\n error?: unknown\n ): void {\n if (this._listeners.length === 0) {\n if (level === 'error') {\n console.error('Unhandled error trace event:', error)\n }\n return\n }\n\n const metadata: TraceEventMetadata = {\n level,\n namespace,\n scope: scope ?? this._scope,\n source: this._source\n }\n\n const matched = this._listeners.filter(listener => {\n if (!listener.filter) {\n return true\n }\n\n try {\n return listener.filter(metadata)\n } catch (error) {\n console.error('Error in trace listener filter:', error)\n return false\n }\n })\n\n if (matched.length === 0) {\n if (level === 'error') {\n console.error('Unhandled error trace event:', error)\n }\n return\n }\n\n const event: TraceEvent = {\n ...metadata,\n ...(error !== undefined && { error }),\n ...(payload !== undefined && { payload: resolvePayload(payload) }),\n timestamp: Date.now()\n }\n\n for (const listener of matched) {\n try {\n listener.handler(event)\n } catch (error) {\n // a faulty listener must never break the traced code\n console.error('Error in trace listener:', error)\n }\n }\n }\n}\n","import Tracer from '../system/Tracer'\nimport type { TraceListener, TraceListenerRemover, TraceRegistry, TracerOptions } from '../types/trace'\n\n/**\n * Creates a registry for managing trace listeners and creating tracers.\n * @returns An object containing methods to add and clear trace listeners, and to create tracers.\n */\nexport function createTracerRegistry(): TraceRegistry {\n const listeners: TraceListener[] = []\n\n /**\n * Registers a trace listener and returns its remover.\n * Listeners are evaluated in registration order.\n * @param listener The trace listener to register.\n * @returns A function that removes the registered listener when called.\n */\n function addTraceListener(listener: TraceListener): TraceListenerRemover {\n listeners.push(listener)\n\n return () => {\n const index = listeners.indexOf(listener)\n\n if (index !== -1) {\n listeners.splice(index, 1)\n }\n }\n }\n\n /**\n * Clears all registered trace listeners.\n */\n function clearTraceListeners(): void {\n listeners.length = 0\n }\n\n /**\n * Checks if there are any registered trace listeners.\n * @returns True if there are registered trace listeners, otherwise false.\n */\n function hasTraceListeners(): boolean {\n return listeners.length > 0\n }\n\n return {\n addTraceListener,\n clearTraceListeners,\n createTracer: (source: string, options: TracerOptions = {}) => new Tracer(source, listeners, options),\n hasTraceListeners\n }\n}","import { PluginConsole } from './log'\n\nimport type { Console } from '../types/log'\nimport type { TraceEvent, TraceListener } from '../types/trace'\n\nfunction formatTraceLabel(event: TraceEvent): string {\n return event.scope\n ? `${event.source} - ${event.namespace} [${event.scope}]`\n : `${event.source} - ${event.namespace}`\n}\n\n/**\n * Creates an opt-in trace listener that reproduces the former console output.\n */\nexport function createConsoleTraceListener(target: Console = PluginConsole): TraceListener {\n return {\n handler(event): void {\n const args: unknown[] = [formatTraceLabel(event)]\n\n if (event.error !== undefined) {\n args.push(event.error)\n }\n\n if (event.payload !== undefined) {\n if (Array.isArray(event.payload)) {\n args.push(...event.payload)\n } else {\n args.push(event.payload)\n }\n }\n\n if (event.level === 'error') {\n target.error(...args)\n return\n }\n\n target.log(...args)\n }\n }\n}\n"],"names":["style","bgColor","color","log","logStyle","args","CustomConsole","__publicField","message","icon","pluginName","styleDefinition","messageType","PluginConsoleClass","PluginConsole","resolvePayload","payload","error","Tracer","source","listeners","options","scope","namespace","level","metadata","matched","listener","event","createTracerRegistry","addTraceListener","index","clearTraceListeners","hasTraceListeners","formatTraceLabel","createConsoleTraceListener","target"],"mappings":";;;;;AAIA,MAAMA,IAAQ,CAACC,GAAiBC,IAAgB,YAC5C,qBAAqBD,CAAO,YAAYC,CAAK;AAG1C,SAASC,EAAIC,GAAkBC,GAAW;AAC7C,MAAI,CAACD;AACD,UAAM,IAAI,MAAM,iCAAiC;AAGrD,UAAQ;AAAA,IACJ;AAAA,IACAA;AAAA,IACAC,EAAK,MAAA;AAAA,I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EAAiBN,GAA2B;AACjD,SAAOA,EAAM,QACP,GAAGA,EAAM,MAAM,MAAMA,EAAM,SAAS,KAAKA,EAAM,KAAK,MACpD,GAAGA,EAAM,MAAM,MAAMA,EAAM,SAAS;AAC9C;AAKO,SAASO,EAA2BC,IAAkBtB,GAA8B;AACvF,SAAO;AAAA,IACH,QAAQc,GAAa;AACjB,YAAMvB,IAAkB,CAAC6B,EAAiBN,CAAK,CAAC;AAchD,UAZIA,EAAM,UAAU,UAChBvB,EAAK,KAAKuB,EAAM,KAAK,GAGrBA,EAAM,YAAY,WACd,MAAM,QAAQA,EAAM,OAAO,IAC3BvB,EAAK,KAAK,GAAGuB,EAAM,OAAO,IAE1BvB,EAAK,KAAKuB,EAAM,OAAO,IAI3BA,EAAM,UAAU,SAAS;AACzB,QAAAQ,EAAO,MAAM,GAAG/B,CAAI;AACpB;AAAA,MACJ;AAEA,MAAA+B,EAAO,IAAI,GAAG/B,CAAI;AAAA,IACtB;AAAA,EAAA;AAER;"}
|
package/dist/lib/main.d.ts
CHANGED
|
@@ -3,12 +3,10 @@ import PluginSubscription from '../core/PluginSubscription';
|
|
|
3
3
|
import Store from '../core/Store';
|
|
4
4
|
export { createPlugin } from "../plugins/createPlugin";
|
|
5
5
|
export { createHydrationPlugin } from "../plugins/createHydrationPlugin";
|
|
6
|
-
export type { AnyObject,
|
|
6
|
+
export type { AnyObject, CustomStore, DefineAStoreSetupContext, DefineAStoreSetupExtensions, EmptyExtensions, PluginExecutionEnvironment, PluginExecutionOptions, PluginHydrationScheduler, PluginHydrationTiming, PluginRuntimeEnvironment, PluginStoreOptions, PluginSubscriptionOptions, PluginSubscriberInterface, PluginSubscriptionDefinition, PluginSubscriptions, StatePropertyValue, StoreOptions, StoreOptionsExtensions, StoreOptionsPropertyValue, StoreMutationSubscription, StoreMutationSubscriptionCallback, StoreOnActionCallbackParameters, StoreOnActionSubscription, StoreOnActionSubscriptionCallback, NativePiniaSubscription, NativePiniaSubscriptionReturn } from "../types";
|
|
7
7
|
export type { StoreMutationSubscriptionReturn, StoreOnActionSubscriptionReturn } from "../types/plugin";
|
|
8
8
|
export type { RollbackActionParams, RollbackAfterFailureParams } from "../types/store";
|
|
9
9
|
export { defineAStore, defineAStoreCtx, getDefineAStoreSetupContext, getEnhancedStore, getExtendingStore, setEnhancedStore } from "../utils/store";
|
|
10
|
-
export { CustomConsole } from "../system/log";
|
|
11
|
-
export { isEmpty } from "../utils/validation";
|
|
12
10
|
export { pluginName as PLUGIN_NAME } from "../utils/constantes";
|
|
13
11
|
export { PluginSubscriber };
|
|
14
12
|
export { PluginSubscription };
|