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
|
@@ -27,7 +27,7 @@ Two authoring styles are available:
|
|
|
27
27
|
no classes.
|
|
28
28
|
2. **`PluginSubscriber` abstract class + `Store` subclass** — recommended
|
|
29
29
|
for richer plugins: the `Store` subclass wraps the pinia store with
|
|
30
|
-
helpers (state extension, subscriptions,
|
|
30
|
+
helpers (state extension, subscriptions, structured tracing).
|
|
31
31
|
|
|
32
32
|
## Your first subscriber: a plain object
|
|
33
33
|
|
|
@@ -37,7 +37,7 @@ Two authoring styles are available:
|
|
|
37
37
|
export const myStoreSubscriber = {
|
|
38
38
|
name: 'my-plugin',
|
|
39
39
|
|
|
40
|
-
invoke: (context
|
|
40
|
+
invoke: (context) => {
|
|
41
41
|
// context contains `store`, `options`, `pinia`
|
|
42
42
|
console.log('store registered', context.store.$id)
|
|
43
43
|
|
|
@@ -58,7 +58,7 @@ import type { PluginSubscriberInterface } from 'pinia-plugin-subscription'
|
|
|
58
58
|
export const myStoreSubscriber: PluginSubscriberInterface = {
|
|
59
59
|
name: 'my-plugin',
|
|
60
60
|
|
|
61
|
-
invoke: (context
|
|
61
|
+
invoke: (context) => {
|
|
62
62
|
console.log('store registered', context.store.$id)
|
|
63
63
|
|
|
64
64
|
return true
|
|
@@ -82,17 +82,16 @@ pinia.use(createPlugin([myStoreSubscriber]))
|
|
|
82
82
|
|
|
83
83
|
| Member | Type | Description |
|
|
84
84
|
| --- | --- | --- |
|
|
85
|
-
| `name` (required) | `string` | Unique plugin name
|
|
86
|
-
| `invoke` (required) | `(context: PiniaPluginContext
|
|
85
|
+
| `name` (required) | `string` | Unique plugin name. |
|
|
86
|
+
| `invoke` (required) | `(context: PiniaPluginContext) => boolean` | Called when a store is registered. Return `false` to skip the store. |
|
|
87
87
|
| `execution` | `PluginExecutionOptions` | Where/when the subscriber runs — see [Execution policy & SSR](#execution-policy--ssr). |
|
|
88
88
|
| `hydrationScheduler` | `(run: () => void) => void` | Custom scheduler used when hydration is deferred. |
|
|
89
|
-
| `hydrate` | `(context
|
|
90
|
-
| `afterHydration` | `(context
|
|
89
|
+
| `hydrate` | `(context) => void \| Promise<void>` | SSR-safe initialization hook; guaranteed to run before `afterHydration`. |
|
|
90
|
+
| `afterHydration` | `(context) => void \| Promise<void>` | Post-hydration lifecycle hook. |
|
|
91
91
|
| `resetStoreCallback` | `(store?: Store) => void` | Custom logic executed when a registered store is reset. |
|
|
92
92
|
| `storeOnActionSubscription` | `{ store, callback }` (getter) | Action subscription forwarded to the returned store's `$onAction`, including after deferred hydration; removed on store disposal. |
|
|
93
93
|
| `storeMutationSubscription` | `{ store, callback }` (getter) | Mutation subscription forwarded to pinia's `$subscribe`. |
|
|
94
94
|
| `subscriptions` | `Record<string, PluginSubscription>` | Plugin-specific subscription functions exposed to other plugins. |
|
|
95
|
-
| `console` | `Console` | Custom console used for debug logging. |
|
|
96
95
|
|
|
97
96
|
All members except `name` and `invoke` are optional.
|
|
98
97
|
|
|
@@ -117,7 +116,7 @@ checks when they call your plugin's custom methods.
|
|
|
117
116
|
Constructor:
|
|
118
117
|
|
|
119
118
|
```ts
|
|
120
|
-
constructor(pluginName: string, createInstance: CreateInstance
|
|
119
|
+
constructor(pluginName: string, createInstance: CreateInstance)
|
|
121
120
|
```
|
|
122
121
|
|
|
123
122
|
| Member | Kind | Description |
|
|
@@ -136,20 +135,19 @@ constructor(pluginName: string, createInstance: CreateInstance, pluginConsole?:
|
|
|
136
135
|
import { PluginSubscriber, Store } from 'pinia-plugin-subscription'
|
|
137
136
|
|
|
138
137
|
class MyPlugin extends Store {
|
|
139
|
-
constructor(store, options
|
|
140
|
-
super(store, options
|
|
138
|
+
constructor(store, options) {
|
|
139
|
+
super(store, options)
|
|
141
140
|
this.doSomething()
|
|
142
141
|
}
|
|
143
142
|
|
|
144
143
|
doSomething() {
|
|
145
|
-
this.
|
|
144
|
+
this.trace('my-plugin:doSomething', () => ({ storeId: this.store.$id }))
|
|
146
145
|
}
|
|
147
146
|
}
|
|
148
147
|
|
|
149
148
|
class MyPluginSubscriber extends PluginSubscriber {
|
|
150
149
|
constructor() {
|
|
151
|
-
super('my-plugin', (store, options
|
|
152
|
-
new MyPlugin(store, options, debug, customConsole))
|
|
150
|
+
super('my-plugin', (store, options) => new MyPlugin(store, options))
|
|
153
151
|
}
|
|
154
152
|
}
|
|
155
153
|
|
|
@@ -165,13 +163,13 @@ class MyPlugin extends Store {
|
|
|
165
163
|
protected override _className: string = 'MyPlugin'
|
|
166
164
|
protected static override _requiredKeys?: string[] = ['my-plugin-option']
|
|
167
165
|
|
|
168
|
-
constructor(store, options
|
|
169
|
-
super(store, options
|
|
166
|
+
constructor(store, options) {
|
|
167
|
+
super(store, options)
|
|
170
168
|
this.doSomething()
|
|
171
169
|
}
|
|
172
170
|
|
|
173
171
|
doSomething(): void {
|
|
174
|
-
this.
|
|
172
|
+
this.trace('my-plugin:doSomething', () => ({ storeId: this.store.$id }))
|
|
175
173
|
}
|
|
176
174
|
}
|
|
177
175
|
|
|
@@ -195,7 +193,7 @@ export const myStoreSubscriber = new MyPluginSubscriber()
|
|
|
195
193
|
|
|
196
194
|
`Store` wraps a pinia store (`PiniaStore`) and exposes:
|
|
197
195
|
|
|
198
|
-
**Properties:** `
|
|
196
|
+
**Properties:** `options`, `state`, `store`.
|
|
199
197
|
|
|
200
198
|
**Methods:**
|
|
201
199
|
|
|
@@ -208,8 +206,9 @@ export const myStoreSubscriber = new MyPluginSubscriber()
|
|
|
208
206
|
| `getStatePropertyValue(propertyName)` | Reads a state property, unwrapping refs. |
|
|
209
207
|
| `storeSubscribe` (getter/setter) | Factory for pinia's `$subscribe` (`{ store, callback }`). |
|
|
210
208
|
| `onAction` (getter/setter) | Factory for pinia's `$onAction` (`{ store, callback }`). |
|
|
211
|
-
| `static customizeStore(store, options
|
|
212
|
-
| `
|
|
209
|
+
| `static customizeStore(store, options)` | Recommended factory; guarded by `_requiredKeys` (see above). |
|
|
210
|
+
| `trace(namespace, payload?)` | Emits a structured trace event scoped to the store. |
|
|
211
|
+
| `traceError(namespace, error, payload?)` | Emits an error event, or rethrows it when no listener matches. |
|
|
213
212
|
| `stateHas(property)` / `storeHas(property)` | Safe `hasOwnProperty` checks on state / store. |
|
|
214
213
|
| `getValue(value)` | Unwraps a ref or returns the value as-is. |
|
|
215
214
|
| `isOptionApi()` | Whether the store uses the options API. |
|
|
@@ -234,7 +233,7 @@ export const persistedStateSubscriber = {
|
|
|
234
233
|
hydrationScheduler: (run) => {
|
|
235
234
|
nextTick(() => run())
|
|
236
235
|
},
|
|
237
|
-
invoke: (context
|
|
236
|
+
invoke: (context) => {
|
|
238
237
|
// ...
|
|
239
238
|
return true
|
|
240
239
|
}
|
|
@@ -256,7 +255,7 @@ export const persistedStateSubscriber: PluginSubscriberInterface = {
|
|
|
256
255
|
hydrationScheduler: (run) => {
|
|
257
256
|
nextTick(() => run())
|
|
258
257
|
},
|
|
259
|
-
invoke: (context
|
|
258
|
+
invoke: (context) => {
|
|
260
259
|
// ...
|
|
261
260
|
return true
|
|
262
261
|
}
|
|
@@ -395,7 +394,7 @@ Guidelines:
|
|
|
395
394
|
- Always declare **optional** keys with names specific enough to avoid
|
|
396
395
|
collisions (prefer `myPluginOption` over `options`).
|
|
397
396
|
- At runtime, merged options are delivered to your subscriber's
|
|
398
|
-
`invoke(context
|
|
397
|
+
`invoke(context)` through `context.options.storeOptions` — no
|
|
399
398
|
extra wiring needed.
|
|
400
399
|
- Never redeclare `DefineStoreOptionsBase` or `PiniaCustomProperties`; only
|
|
401
400
|
this package owns those augmentations.
|
package/docs/using-plugins.md
CHANGED
|
@@ -22,8 +22,8 @@ Plugins built on `pinia-plugin-subscription` share a common contract:
|
|
|
22
22
|
- **`$reset` on registered stores** — every store registered by the plugin
|
|
23
23
|
gains a `$reset()` method that restores its initial state, including
|
|
24
24
|
setup-style stores where pinia does not provide one natively.
|
|
25
|
-
- **
|
|
26
|
-
|
|
25
|
+
- **Runtime-filtered tracing** — register trace listeners and filter events by
|
|
26
|
+
source, namespace, scope, or level.
|
|
27
27
|
- **SSR-safe execution** — each plugin declares where (`client`, `server`
|
|
28
28
|
or `both`) and when (`immediate` or deferred after hydration) it runs.
|
|
29
29
|
- **State rollback on action failure** — actions listed in the
|
|
@@ -46,15 +46,14 @@ Compatible plugins expose **subscribers** that are passed to
|
|
|
46
46
|
```js
|
|
47
47
|
import { createApp } from 'vue'
|
|
48
48
|
import { createPinia } from 'pinia'
|
|
49
|
-
import { createPlugin
|
|
49
|
+
import { createPlugin } from 'pinia-plugin-subscription'
|
|
50
50
|
import { myStoreSubscriber } from './plugins/my-store'
|
|
51
51
|
import App from './App.vue'
|
|
52
52
|
|
|
53
53
|
const app = createApp(App)
|
|
54
54
|
const pinia = createPinia()
|
|
55
55
|
|
|
56
|
-
|
|
57
|
-
pinia.use(createPlugin([myStoreSubscriber], [PLUGIN_NAME]))
|
|
56
|
+
pinia.use(createPlugin([myStoreSubscriber]))
|
|
58
57
|
|
|
59
58
|
app.use(pinia)
|
|
60
59
|
app.mount('#app')
|
|
@@ -66,12 +65,12 @@ The TypeScript version is identical — `createPlugin()` is fully typed and
|
|
|
66
65
|
requires no generics:
|
|
67
66
|
|
|
68
67
|
```ts
|
|
69
|
-
import { createPlugin
|
|
68
|
+
import { createPlugin } from 'pinia-plugin-subscription'
|
|
70
69
|
import type { PluginSubscriberInterface } from 'pinia-plugin-subscription'
|
|
71
70
|
|
|
72
71
|
const subscribers: PluginSubscriberInterface[] = [myStoreSubscriber]
|
|
73
72
|
|
|
74
|
-
pinia.use(createPlugin(subscribers
|
|
73
|
+
pinia.use(createPlugin(subscribers))
|
|
75
74
|
```
|
|
76
75
|
|
|
77
76
|
## Defining stores: `defineAStore`
|
|
@@ -232,9 +231,7 @@ export const useMyStore = defineAStoreCtx('myStore', (ctx) => {
|
|
|
232
231
|
|
|
233
232
|
`defineAStoreCtx()` enables the `enhancedStore` store option automatically.
|
|
234
233
|
The internal setup-context lookup is cleaned up as soon as the store is
|
|
235
|
-
associated (and on store dispose), which limits map growth over time.
|
|
236
|
-
`storeOptions.debug` is `true`, setup-context map size transitions are
|
|
237
|
-
logged for observability.
|
|
234
|
+
associated (and on store dispose), which limits map growth over time.
|
|
238
235
|
|
|
239
236
|
## `$reset` on registered stores
|
|
240
237
|
|
|
@@ -316,17 +313,27 @@ try {
|
|
|
316
313
|
(forwarded to the action via `apply()`).
|
|
317
314
|
- The original error is rethrown after the state is restored.
|
|
318
315
|
|
|
319
|
-
##
|
|
316
|
+
## Tracing
|
|
320
317
|
|
|
321
|
-
|
|
322
|
-
`createPlugin()`:
|
|
318
|
+
Register listeners independently from plugin construction:
|
|
323
319
|
|
|
324
320
|
```js
|
|
325
|
-
|
|
321
|
+
import {
|
|
322
|
+
addTraceListener,
|
|
323
|
+
createConsoleTraceListener,
|
|
324
|
+
createPlugin
|
|
325
|
+
} from 'pinia-plugin-subscription'
|
|
326
|
+
|
|
327
|
+
addTraceListener({
|
|
328
|
+
...createConsoleTraceListener(),
|
|
329
|
+
filter: event => event.scope === 'cart'
|
|
330
|
+
})
|
|
331
|
+
|
|
332
|
+
pinia.use(createPlugin([myStoreSubscriber]))
|
|
326
333
|
```
|
|
327
334
|
|
|
328
|
-
|
|
329
|
-
|
|
335
|
+
Filters run in real time and can target a source, namespace, store scope, or
|
|
336
|
+
trace level without passing diagnostic options through subscribers.
|
|
330
337
|
|
|
331
338
|
## SSR / Nuxt
|
|
332
339
|
|
|
@@ -334,16 +341,47 @@ The package is SSR-safe by design. Each compatible plugin declares its own
|
|
|
334
341
|
execution policy, so nothing browser-only runs on the server unless the
|
|
335
342
|
plugin explicitly allows it.
|
|
336
343
|
|
|
344
|
+
For request isolation, create the app, Pinia instance, trace registry, and
|
|
345
|
+
plugin inside the per-request app factory. Do not store the registry or the
|
|
346
|
+
`createPlugin()` result at module scope: both retain request-associated
|
|
347
|
+
listeners or plugin state. A new registry per request also avoids races
|
|
348
|
+
between concurrent requests; do not clear a shared registry when one request
|
|
349
|
+
finishes.
|
|
350
|
+
|
|
351
|
+
```js
|
|
352
|
+
import { createSSRApp } from 'vue'
|
|
353
|
+
import { createPinia } from 'pinia'
|
|
354
|
+
import { createPlugin, createTracerRegistry } from 'pinia-plugin-subscription'
|
|
355
|
+
import App from './App.vue'
|
|
356
|
+
import { subscribers } from './subscribers'
|
|
357
|
+
|
|
358
|
+
export function createRequestApp(traceListener) {
|
|
359
|
+
const app = createSSRApp(App)
|
|
360
|
+
const pinia = createPinia()
|
|
361
|
+
const traceRegistry = createTracerRegistry()
|
|
362
|
+
|
|
363
|
+
traceRegistry.addTraceListener(traceListener)
|
|
364
|
+
pinia.use(createPlugin(subscribers, {
|
|
365
|
+
createTracer: traceRegistry.createTracer
|
|
366
|
+
}))
|
|
367
|
+
app.use(pinia)
|
|
368
|
+
|
|
369
|
+
return { app, pinia }
|
|
370
|
+
}
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
Call `createRequestApp()` once for each incoming SSR request. The request's
|
|
374
|
+
listener is then reachable only through that request's registry and plugin.
|
|
375
|
+
|
|
337
376
|
When a plugin needs a runtime-specific scheduler or environment override —
|
|
338
377
|
without forcing every app to re-declare the plugin's execution policy —
|
|
339
378
|
register it through the dedicated hydration helper:
|
|
340
379
|
|
|
341
380
|
```js
|
|
342
381
|
import { nextTick } from 'vue'
|
|
343
|
-
import { createHydrationPlugin
|
|
382
|
+
import { createHydrationPlugin } from 'pinia-plugin-subscription'
|
|
344
383
|
|
|
345
384
|
pinia.use(createHydrationPlugin([persistedStateSubscriber], {
|
|
346
|
-
debug: [PLUGIN_NAME],
|
|
347
385
|
hydrationScheduler: (run) => {
|
|
348
386
|
nextTick(() => run())
|
|
349
387
|
}
|
|
@@ -355,7 +393,6 @@ pinia.use(createHydrationPlugin([persistedStateSubscriber], {
|
|
|
355
393
|
|
|
356
394
|
| Option | Type | Description |
|
|
357
395
|
| --- | --- | --- |
|
|
358
|
-
| `debug` | `string[]` | Plugin names to debug. |
|
|
359
396
|
| `execution` | `PluginExecutionOptions` | Global execution policy override. |
|
|
360
397
|
| `hydrationScheduler` | `(run: () => void) => void` | Scheduler used for deferred hydration. |
|
|
361
398
|
| `runtimeEnvironment` | `'client' \| 'server'` | Forces the runtime environment. |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pinia-plugin-subscription",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-beta.0",
|
|
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,
|
|
@@ -69,7 +69,8 @@
|
|
|
69
69
|
"dev:library": "vite",
|
|
70
70
|
"test": "vitest",
|
|
71
71
|
"coverage": "vitest run --coverage",
|
|
72
|
-
"build": "vitest && vite build && tsc --emitDeclarationOnly --outDir dist && node scripts/measure-bundle.mjs",
|
|
72
|
+
"build": "vitest && vite build && tsc --emitDeclarationOnly --outDir dist && npm run check:leaks && node scripts/measure-bundle.mjs",
|
|
73
|
+
"check:leaks": "node scripts/check-dist-leaks.mjs",
|
|
73
74
|
"bundle:check": "vite build --config vite.config.ts && node scripts/measure-bundle.mjs",
|
|
74
75
|
"build:demo": "vite --config vite.demo.config.ts build",
|
|
75
76
|
"preview": "vite preview --config vite.demo.config.ts"
|
|
@@ -1,337 +0,0 @@
|
|
|
1
|
-
var f = Object.defineProperty;
|
|
2
|
-
var S = (s, t, e) => t in s ? f(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
|
|
3
|
-
var n = (s, t, e) => S(s, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
-
import { isRef as b, ref as y, toRef as C } from "vue";
|
|
5
|
-
import { defineStore as g } from "pinia";
|
|
6
|
-
class L {
|
|
7
|
-
constructor(t, e, r) {
|
|
8
|
-
n(this, "_console");
|
|
9
|
-
n(this, "_createInstance");
|
|
10
|
-
n(this, "_name");
|
|
11
|
-
n(this, "_pluginOptions");
|
|
12
|
-
n(this, "_storeInstance");
|
|
13
|
-
n(this, "_resetStoreCallback");
|
|
14
|
-
n(this, "_storeOnActionSubscription");
|
|
15
|
-
n(this, "_storeMutationSubscription");
|
|
16
|
-
n(this, "_subscriptions");
|
|
17
|
-
n(this, "pluginCreated");
|
|
18
|
-
n(this, "execution");
|
|
19
|
-
n(this, "hydrationScheduler");
|
|
20
|
-
this._name = t, this._createInstance = e, r && (this._console = r);
|
|
21
|
-
}
|
|
22
|
-
get console() {
|
|
23
|
-
return this._console ?? console;
|
|
24
|
-
}
|
|
25
|
-
get name() {
|
|
26
|
-
return this._name;
|
|
27
|
-
}
|
|
28
|
-
get storeInstance() {
|
|
29
|
-
return this._storeInstance;
|
|
30
|
-
}
|
|
31
|
-
get pluginOptions() {
|
|
32
|
-
return this._pluginOptions ?? {};
|
|
33
|
-
}
|
|
34
|
-
set pluginOptions(t) {
|
|
35
|
-
this._pluginOptions = t;
|
|
36
|
-
}
|
|
37
|
-
get resetStoreCallback() {
|
|
38
|
-
return this._resetStoreCallback;
|
|
39
|
-
}
|
|
40
|
-
get storeOnActionSubscription() {
|
|
41
|
-
return this._storeOnActionSubscription;
|
|
42
|
-
}
|
|
43
|
-
get storeMutationSubscription() {
|
|
44
|
-
return this._storeMutationSubscription;
|
|
45
|
-
}
|
|
46
|
-
get subscriptions() {
|
|
47
|
-
return this._subscriptions;
|
|
48
|
-
}
|
|
49
|
-
set subscriptions(t) {
|
|
50
|
-
this._subscriptions = t;
|
|
51
|
-
}
|
|
52
|
-
afterHydration(t, e) {
|
|
53
|
-
}
|
|
54
|
-
hydrate(t, e) {
|
|
55
|
-
}
|
|
56
|
-
invoke({ store: t, options: e }, r) {
|
|
57
|
-
return this._storeInstance = this._createInstance(t, { ...e, ...this.pluginOptions }, r, this.console), this._storeInstance ? (this._subscriptions = this._storeInstance.getSubscriptions(), this._storeMutationSubscription = this._storeInstance.storeSubscribe, this._storeOnActionSubscription = this._storeInstance.onAction, this.pluginCreated && this.pluginCreated(t), !0) : !1;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
class A {
|
|
61
|
-
constructor(t, e) {
|
|
62
|
-
n(this, "_console");
|
|
63
|
-
n(this, "_debug", !1);
|
|
64
|
-
this._debug = t, e && (this._console = e);
|
|
65
|
-
}
|
|
66
|
-
get console() {
|
|
67
|
-
return this._console ?? console;
|
|
68
|
-
}
|
|
69
|
-
set console(t) {
|
|
70
|
-
this._console = t;
|
|
71
|
-
}
|
|
72
|
-
get debug() {
|
|
73
|
-
return this._debug;
|
|
74
|
-
}
|
|
75
|
-
set debug(t) {
|
|
76
|
-
this._debug = t;
|
|
77
|
-
}
|
|
78
|
-
debugLog(...t) {
|
|
79
|
-
this._debug && (Array.isArray(t) && (t[0] = `${this._className} - ${t[0]}`), this.console.log(...t));
|
|
80
|
-
}
|
|
81
|
-
logError(...t) {
|
|
82
|
-
this.console.error(...t);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
const p = /* @__PURE__ */ new WeakMap(), c = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new WeakSet(), O = 50;
|
|
86
|
-
function x(s) {
|
|
87
|
-
return s?.storeOptions?.debug === !0;
|
|
88
|
-
}
|
|
89
|
-
function h(s, t, e) {
|
|
90
|
-
if (!x(t))
|
|
91
|
-
return;
|
|
92
|
-
const r = c.size;
|
|
93
|
-
console.debug(`[defineAStoreSetup] ${s} - ${e} (contextsById=${r})`), r >= O && console.warn(`[defineAStoreSetup] contextsById reached ${r} entries`);
|
|
94
|
-
}
|
|
95
|
-
function $(s, t, e) {
|
|
96
|
-
if (l.has(s) || typeof s.$dispose != "function")
|
|
97
|
-
return;
|
|
98
|
-
const r = s.$dispose;
|
|
99
|
-
s.$dispose = (...o) => (p.delete(s), c.delete(t), h(t, e, "dispose cleanup"), r.apply(s, o)), l.add(s);
|
|
100
|
-
}
|
|
101
|
-
function N(s, t, e) {
|
|
102
|
-
const r = e ? { storeOptions: e } : {};
|
|
103
|
-
return typeof t == "function" ? d(
|
|
104
|
-
s,
|
|
105
|
-
t,
|
|
106
|
-
r
|
|
107
|
-
) : m(
|
|
108
|
-
s,
|
|
109
|
-
t,
|
|
110
|
-
r
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
function T(s, t, e) {
|
|
114
|
-
const r = e ? { storeOptions: { ...e, enhancedStore: !0 } } : { storeOptions: { enhancedStore: !0 } };
|
|
115
|
-
return d(
|
|
116
|
-
s,
|
|
117
|
-
t,
|
|
118
|
-
r
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
function d(s, t, e) {
|
|
122
|
-
const r = {
|
|
123
|
-
id: s,
|
|
124
|
-
extensions: {}
|
|
125
|
-
}, o = e?.storeOptions?.enhancedStore === !0, i = g(
|
|
126
|
-
s,
|
|
127
|
-
() => t(r),
|
|
128
|
-
e
|
|
129
|
-
);
|
|
130
|
-
return Object.assign(((...u) => {
|
|
131
|
-
o && (c.set(s, r), h(s, e, "registered context by id"));
|
|
132
|
-
const a = i(...u);
|
|
133
|
-
return o && (p.set(a, r), c.delete(s), h(s, e, "moved context to weak map"), $(a, s, e)), a;
|
|
134
|
-
}), i);
|
|
135
|
-
}
|
|
136
|
-
function m(s, t, e) {
|
|
137
|
-
return e && (t = { ...t, ...e ?? {} }), g(s, t);
|
|
138
|
-
}
|
|
139
|
-
const I = /* @__PURE__ */ new Set(["_", "$"]);
|
|
140
|
-
function w(s) {
|
|
141
|
-
return I.has(s[0]);
|
|
142
|
-
}
|
|
143
|
-
function E(s) {
|
|
144
|
-
const t = s;
|
|
145
|
-
return p.get(s) ?? (typeof t?.$id == "string" ? c.get(t.$id) : void 0);
|
|
146
|
-
}
|
|
147
|
-
function k(s) {
|
|
148
|
-
const t = s.extensions.enhancedStore ?? s.extensions.extending;
|
|
149
|
-
if (!t)
|
|
150
|
-
throw new Error(`${s.id}Store - getEnhancedStore - Error: enhanced store is required`);
|
|
151
|
-
return t;
|
|
152
|
-
}
|
|
153
|
-
function M(s, t) {
|
|
154
|
-
s.extensions.enhancedStore = t, s.extensions.extending = t;
|
|
155
|
-
}
|
|
156
|
-
function W(s) {
|
|
157
|
-
return console.warn(`${s.id}Store - getExtendingStore is deprecated. Use getEnhancedStore instead.`), k(s);
|
|
158
|
-
}
|
|
159
|
-
function F(s, t) {
|
|
160
|
-
return `${s}-${t.$id}`;
|
|
161
|
-
}
|
|
162
|
-
function P(s) {
|
|
163
|
-
return s ? Array.isArray(s) ? s.length === 0 : typeof s == "object" ? Object.keys(s).length === 0 : typeof s == "string" ? s.trim() === "" : !1 : !(typeof s == "boolean" || typeof s == "number");
|
|
164
|
-
}
|
|
165
|
-
class q extends A {
|
|
166
|
-
constructor(e, r, o = !1, i) {
|
|
167
|
-
super(o, i);
|
|
168
|
-
n(this, "_className", "Store");
|
|
169
|
-
n(this, "_onAction");
|
|
170
|
-
n(this, "_options");
|
|
171
|
-
n(this, "_store");
|
|
172
|
-
n(this, "_subscriptions", {});
|
|
173
|
-
n(this, "_storeSubscribe");
|
|
174
|
-
if (this._options = r.storeOptions, this._store = e, this._options?.enhancedStore) {
|
|
175
|
-
const u = E(this.store);
|
|
176
|
-
u && M(u, this.store);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
get onAction() {
|
|
180
|
-
if (this._onAction)
|
|
181
|
-
return () => ({
|
|
182
|
-
store: this.store,
|
|
183
|
-
callback: this._onAction
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
set onAction(e) {
|
|
187
|
-
this._onAction = e;
|
|
188
|
-
}
|
|
189
|
-
get options() {
|
|
190
|
-
return this._options;
|
|
191
|
-
}
|
|
192
|
-
get state() {
|
|
193
|
-
return this._store.$state;
|
|
194
|
-
}
|
|
195
|
-
set state(e) {
|
|
196
|
-
this._store.$state = e;
|
|
197
|
-
}
|
|
198
|
-
get store() {
|
|
199
|
-
return this._store;
|
|
200
|
-
}
|
|
201
|
-
get storeSubscribe() {
|
|
202
|
-
if (this._storeSubscribe)
|
|
203
|
-
return () => ({
|
|
204
|
-
store: this.store,
|
|
205
|
-
callback: this._storeSubscribe
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
set storeSubscribe(e) {
|
|
209
|
-
this._storeSubscribe = e;
|
|
210
|
-
}
|
|
211
|
-
addToState(e, r) {
|
|
212
|
-
this.isOptionApi() || b(r) || (r = y(r)), this.state[e] = r, this.store[e] = C(this.state, e);
|
|
213
|
-
}
|
|
214
|
-
addSubscription(e, r, o) {
|
|
215
|
-
this._subscriptions[e] = { subscription: r, ...o ?? {} };
|
|
216
|
-
}
|
|
217
|
-
afterHydration() {
|
|
218
|
-
}
|
|
219
|
-
static customizeStore(e, r, o = !1, i) {
|
|
220
|
-
if (r.storeOptions && this.hasRequiredKeys(r.storeOptions))
|
|
221
|
-
return new this(e, r, o, i);
|
|
222
|
-
}
|
|
223
|
-
getOption(e) {
|
|
224
|
-
return this.options && this.options[e];
|
|
225
|
-
}
|
|
226
|
-
getStatePropertyValue(e) {
|
|
227
|
-
return this.getValue(this.state[e]);
|
|
228
|
-
}
|
|
229
|
-
getSubscriptions() {
|
|
230
|
-
if (!P(this._subscriptions))
|
|
231
|
-
return this._subscriptions;
|
|
232
|
-
}
|
|
233
|
-
getValue(e) {
|
|
234
|
-
return e?.__v_isRef ? e.value : e;
|
|
235
|
-
}
|
|
236
|
-
hasDeniedFirstChar(e) {
|
|
237
|
-
return w(e);
|
|
238
|
-
}
|
|
239
|
-
static hasRequiredKeys(e) {
|
|
240
|
-
return this._requiredKeys !== void 0 && this._requiredKeys?.every((r) => !!e[r]);
|
|
241
|
-
}
|
|
242
|
-
hydrate() {
|
|
243
|
-
}
|
|
244
|
-
isOptionApi() {
|
|
245
|
-
return this.store._isOptionsAPI;
|
|
246
|
-
}
|
|
247
|
-
stateHas(e) {
|
|
248
|
-
return Object.prototype.hasOwnProperty.call(this.state, e);
|
|
249
|
-
}
|
|
250
|
-
storeHas(e) {
|
|
251
|
-
return Object.prototype.hasOwnProperty.call(this.store, e);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
n(q, "_requiredKeys");
|
|
255
|
-
const _ = "pinia-plugin-subscription", B = (s, t = "white") => `background-color: ${s}; color: ${t}; padding: 1px; margin-right: 5px; font-size: 12px`;
|
|
256
|
-
function D(s, t) {
|
|
257
|
-
if (!s)
|
|
258
|
-
throw new Error("Style instructions are required");
|
|
259
|
-
console.log(
|
|
260
|
-
"%c%s",
|
|
261
|
-
s,
|
|
262
|
-
t.shift(),
|
|
263
|
-
...t
|
|
264
|
-
);
|
|
265
|
-
}
|
|
266
|
-
class K {
|
|
267
|
-
constructor() {
|
|
268
|
-
n(this, "_bgColor", "#ffec73");
|
|
269
|
-
n(this, "_color", "green");
|
|
270
|
-
n(this, "_icon", "🍍⚡");
|
|
271
|
-
n(this, "_errorBgColor", "#d24545");
|
|
272
|
-
n(this, "_errorColor", "white");
|
|
273
|
-
n(this, "_errorIcon", "🍍⚠️");
|
|
274
|
-
n(this, "_styles", {
|
|
275
|
-
error: { bgColor: this._errorBgColor, color: this._errorColor, icon: this._errorIcon },
|
|
276
|
-
info: { bgColor: this._bgColor, color: this._color, icon: this._icon }
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
formatMessage(t, e) {
|
|
280
|
-
return ` [${e} ${_}] - ${t} `;
|
|
281
|
-
}
|
|
282
|
-
generateStyle(t) {
|
|
283
|
-
return B(t.bgColor, t.color);
|
|
284
|
-
}
|
|
285
|
-
getStyleDefinition(t) {
|
|
286
|
-
return this._styles[t ?? "info"];
|
|
287
|
-
}
|
|
288
|
-
log(...t) {
|
|
289
|
-
this.useLog(
|
|
290
|
-
this.getStyleDefinition(),
|
|
291
|
-
t
|
|
292
|
-
);
|
|
293
|
-
}
|
|
294
|
-
error(...t) {
|
|
295
|
-
this.useLog(
|
|
296
|
-
this.getStyleDefinition("error"),
|
|
297
|
-
t
|
|
298
|
-
);
|
|
299
|
-
}
|
|
300
|
-
rebuildArgs(t, e) {
|
|
301
|
-
if (typeof t == "string")
|
|
302
|
-
return [this.formatMessage(t, e)];
|
|
303
|
-
if (Array.isArray(t))
|
|
304
|
-
return [this.formatMessage(t.shift(), e), ...t ?? []];
|
|
305
|
-
}
|
|
306
|
-
useLog(t, e) {
|
|
307
|
-
D(
|
|
308
|
-
this.generateStyle(t),
|
|
309
|
-
this.rebuildArgs(e, t.icon)
|
|
310
|
-
);
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
class R extends K {
|
|
314
|
-
constructor() {
|
|
315
|
-
super(...arguments);
|
|
316
|
-
n(this, "_pluginName", _);
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
const V = new R();
|
|
320
|
-
export {
|
|
321
|
-
K as C,
|
|
322
|
-
A as D,
|
|
323
|
-
V as P,
|
|
324
|
-
q as S,
|
|
325
|
-
L as a,
|
|
326
|
-
T as b,
|
|
327
|
-
E as c,
|
|
328
|
-
N as d,
|
|
329
|
-
k as e,
|
|
330
|
-
W as f,
|
|
331
|
-
F as g,
|
|
332
|
-
w as h,
|
|
333
|
-
P as i,
|
|
334
|
-
_ as p,
|
|
335
|
-
M as s
|
|
336
|
-
};
|
|
337
|
-
//# sourceMappingURL=index-DKdl-fiq.js.map
|