Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More โ†’
Socket
Sign inDemoInstall
Socket

pinia

Package Overview
Dependencies
Maintainers
1
Versions
119
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pinia - npm Package Compare versions

Comparing version 2.0.0-alpha.13 to 2.0.0-alpha.14

65

CHANGELOG.md

@@ -0,1 +1,64 @@

# [2.0.0-alpha.14](https://github.com/posva/pinia/compare/v2.0.0-alpha.13...v2.0.0-alpha.14) (2021-05-03)
### Features
- **devtools:** work with stores added before app.use ([#444](https://github.com/posva/pinia/issues/444)) ([21f917f](https://github.com/posva/pinia/commit/21f917f057522b7e2ff70fa8517c5941c644a577))
- **devtools:** add getters to devtools ([c4bf761](https://github.com/posva/pinia/commit/c4bf761e95b79a0831061e490ba1d69802bc9d95))
- mark getters as readonly ([fcbeb95](https://github.com/posva/pinia/commit/fcbeb95cdd7f2b7d58731392d707183b311863ff))
- **plugins:** allow chaining ([3a49d34](https://github.com/posva/pinia/commit/3a49d34f5d30c1d346243df0d043a0709b2a4861))
- **mapHelpers:** warn on array mapStores ([d385bd9](https://github.com/posva/pinia/commit/d385bd98b136be15b6aa3ac6c2c8ca9261af4635))
- pass options to context in plugins ([c8ad19f](https://github.com/posva/pinia/commit/c8ad19f6a959751d456aca93cd670d6b18064d50))
- **types:** expose PiniaPluginContext ([94d12e7](https://github.com/posva/pinia/commit/94d12e7f127125c8aa915262471e07aae9d881bf))
- add plugin api wip ([50bc807](https://github.com/posva/pinia/commit/50bc807dce932c5cbe02612505535f05dfe6325a))
- **plugins:** allow void return ([5ef7140](https://github.com/posva/pinia/commit/5ef71407764384bef13a4f46fd001beade387d24))
- **plugins:** pass a context object to plugins instead of app ([bcb4ec3](https://github.com/posva/pinia/commit/bcb4ec3422635dd57f655e58f72a9a7a1c7dba0d))
- add plugin api wip ([b5c928d](https://github.com/posva/pinia/commit/b5c928da20efc532de84d8b8498d56f306a40e03))
### Performance Improvements
- **store:** reuse store instances when possible ([14f5a5f](https://github.com/posva/pinia/commit/14f5a5fd21677e7e5673443c35eeadbe2bdd8f05))
### BREAKING CHANGES
- **store:** getters now receive the state as their first argument and it's properly typed so you can write getters with arrow functions:
```js
defineStore({
state: () => ({ n: 0 }),
getters: {
double: (state) => state.n * 2,
},
})
```
To access other getters, you must still use the syntax that uses `this` **but it is now necessary to explicitly type the getter return type**. The same limitation exists in Vue for computed properties and it's a known limitation in TypeScript:
```ts
defineStore({
state: () => ({ n: 0 }),
getters: {
double: (state) => state.n * 2,
// the `: number` is necessary when accessing `this` inside of
// a getter
doublePlusOne(state): number {
return this.double + 1
},
},
})
```
For more information, refer to [the updated documentation for getters](https://pinia.esm.dev/core-concepts/getters.html).
- **plugins:** To improve the plugin api capabilities, `pinia.use()`
now receives a context object instead of just `app`:
```js
// replace
pinia.use((app) => {})
// with
pinia.use(({ app }) => {})
```
Check the new documentation for [Plugins](https://pinia.esm.dev/core-concepts/plugins.html)!
# [2.0.0-alpha.13](https://github.com/posva/pinia/compare/v2.0.0-alpha.12...v2.0.0-alpha.13) (2021-04-10)

@@ -138,2 +201,2 @@

- `getters` no longer receive parameters, access the store instance via `this`:
directly call `this.myState` to read state and other getters.
directly call `this.myState` to read state and other getters. **Update 2021-04-02**: `getters` receive the state again as the first parameter
/*!
* pinia v2.0.0-alpha.13
* pinia v2.0.0-alpha.14
* (c) 2021 Eduardo San Martin Morote

@@ -43,2 +43,8 @@ * @license MIT

const storesMap = new WeakMap();
/**
* Expose the client-side application instance used for devtools
*/
let clientAppPromise;
const getClientApp = () => clientAppPromise ||
(clientAppPromise = new Promise((resolve) => (resolve)));
const piniaSymbol = ((process.env.NODE_ENV !== 'production')

@@ -61,13 +67,9 @@ ? Symbol('pinia')

install(app) {
localApp = app;
pinia._a = localApp = app;
// pinia._a = app
app.provide(piniaSymbol, pinia);
app.config.globalProperties.$pinia = pinia;
toBeInstalled.forEach((plugin) => _p.push(plugin.bind(null, localApp)));
toBeInstalled.forEach((plugin) => _p.push(plugin));
},
use(plugin) {
/* istanbul ignore next */
if ((process.env.NODE_ENV !== 'production') && !false) {
console.warn(`[๐Ÿ]: The plugin API has plans to change to bring better extensibility. "pinia.use()" signature will change in the next release. It is recommended to avoid using this API.`);
}
if (!localApp) {

@@ -77,6 +79,9 @@ toBeInstalled.push(plugin);

else {
_p.push(plugin.bind(null, localApp));
_p.push(plugin);
}
return this;
},
_p,
// it's actually undefined here
_a: localApp,
state,

@@ -96,2 +101,177 @@ };

function getDevtoolsGlobalHook() {
return getTarget().__VUE_DEVTOOLS_GLOBAL_HOOK__;
}
function getTarget() {
// @ts-ignore
return typeof navigator !== 'undefined'
? window
: typeof global !== 'undefined'
? global
: {};
}
const HOOK_SETUP = 'devtools-plugin:setup';
function setupDevtoolsPlugin(pluginDescriptor, setupFn) {
const hook = getDevtoolsGlobalHook();
if (hook) {
hook.emit(HOOK_SETUP, pluginDescriptor, setupFn);
}
else {
const target = getTarget();
const list = target.__VUE_DEVTOOLS_PLUGINS__ = target.__VUE_DEVTOOLS_PLUGINS__ || [];
list.push({
pluginDescriptor,
setupFn
});
}
}
function formatDisplay(display) {
return {
_custom: {
display,
},
};
}
/**
* Registered stores used for devtools.
*/
const registeredStores = /*#__PURE__*/ new Set();
function toastMessage(message, type) {
const piniaMessage = '๐Ÿ ' + message;
if (typeof __VUE_DEVTOOLS_TOAST__ === 'function') {
__VUE_DEVTOOLS_TOAST__(piniaMessage, type);
}
else if (type === 'error') {
console.error(piniaMessage);
}
else if (type === 'warning') {
console.warn(piniaMessage);
}
else {
console.log(piniaMessage);
}
}
let isAlreadyInstalled;
const componentStateTypes = [];
function addDevtools(app, store) {
registeredStores.add(store);
componentStateTypes.push('๐Ÿ ' + store.$id);
setupDevtoolsPlugin({
id: 'dev.esm.pinia',
label: 'Pinia ๐Ÿ',
logo: 'https://pinia.esm.dev/logo.svg',
packageName: 'pinia',
homepage: 'https://pinia.esm.dev',
componentStateTypes,
app,
}, (api) => {
// watch(router.currentRoute, () => {
// // @ts-ignore
// api.notifyComponentUpdate()
// })
const mutationsLayerId = 'pinia:mutations';
const piniaInspectorId = 'pinia';
if (!isAlreadyInstalled) {
api.on.inspectComponent((payload, ctx) => {
if (payload.instanceData) {
payload.instanceData.state.push({
type: '๐Ÿ ' + store.$id,
key: 'state',
editable: false,
value: store.$state,
});
}
});
api.addTimelineLayer({
id: mutationsLayerId,
label: `Pinia ๐Ÿ`,
color: 0xe5df88,
});
api.addInspector({
id: piniaInspectorId,
label: 'Pinia ๐Ÿ',
icon: 'storage',
treeFilterPlaceholder: 'Search stores',
});
isAlreadyInstalled = true;
}
else {
api.notifyComponentUpdate();
api.sendInspectorTree(piniaInspectorId);
api.sendInspectorState(piniaInspectorId);
}
store.$subscribe((mutation, state) => {
// rootStore.state[store.id] = state
const data = {
store: formatDisplay(mutation.storeName),
// type: formatDisplay(mutation.type),
};
if (mutation.payload) {
data.payload = mutation.payload;
}
api.notifyComponentUpdate();
api.sendInspectorState(piniaInspectorId);
api.addTimelineEvent({
layerId: mutationsLayerId,
event: {
time: Date.now(),
title: mutation.type,
data,
},
});
});
api.on.getInspectorTree((payload) => {
if (payload.app === app && payload.inspectorId === piniaInspectorId) {
const stores = Array.from(registeredStores);
payload.rootNodes = (payload.filter
? stores.filter((store) => store.$id.toLowerCase().includes(payload.filter.toLowerCase()))
: stores).map(formatStoreForInspectorTree);
}
});
api.on.getInspectorState((payload) => {
if (payload.app === app && payload.inspectorId === piniaInspectorId) {
const stores = Array.from(registeredStores);
const store = stores.find((store) => store.$id === payload.nodeId);
if (store) {
payload.state = {
options: formatStoreForInspectorState(store),
};
}
else {
toastMessage(`store "${payload.nodeId}" not found`, 'error');
}
}
});
// trigger an update so it can display new registered stores
// @ts-ignore
api.notifyComponentUpdate();
toastMessage(`"${store.$id}" store installed`);
});
}
function formatStoreForInspectorTree(store) {
return {
id: store.$id,
label: store.$id,
tags: [],
};
}
function formatStoreForInspectorState(store) {
const fields = [
{ editable: false, key: 'id', value: formatDisplay(store.$id) },
{ editable: true, key: 'state', value: store.$state },
{
editable: false,
key: 'getters',
value: (store._getters || []).reduce((getters, key) => {
getters[key] = store[key];
return getters;
}, {}),
},
];
return fields;
}
function innerPatch(target, patchToApply) {

@@ -199,2 +379,6 @@ // TODO: get all keys like symbols as well

};
const injectionSymbol = (process.env.NODE_ENV !== 'production')
? Symbol(`PiniaStore(${$id})`)
: /* istanbul ignore next */
Symbol();
return [

@@ -210,2 +394,3 @@ storeWithState,

},
injectionSymbol,
];

@@ -225,9 +410,11 @@ }

*/
function buildStoreToUse(partialStore, descriptor, $id, getters = {}, actions = {}) {
function buildStoreToUse(partialStore, descriptor, $id, getters = {}, actions = {}, options) {
const pinia = getActivePinia();
const computedGetters = {};
for (const getterName in getters) {
// @ts-ignore: it's only readonly for the users
computedGetters[getterName] = vue.computed(() => {
setActivePinia(pinia);
// eslint-disable-next-line @typescript-eslint/no-use-before-define
// @ts-expect-error: the argument count is correct
return getters[getterName].call(store, store);

@@ -244,4 +431,3 @@ });

}
const extensions = pinia._p.reduce((extended, extender) => assign({}, extended, extender()), {});
const store = vue.reactive(assign({}, extensions, partialStore,
const store = vue.reactive(assign({}, partialStore,
// using this means no new properties can be added as state

@@ -253,6 +439,11 @@ computedFromState(pinia.state, $id), computedGetters, wrappedActions));

Object.defineProperty(store, '$state', descriptor);
if (IS_CLIENT && false && (process.env.NODE_ENV !== 'production')) {
store._getters = Object.keys(getters);
}
// apply all plugins
pinia._p.forEach((extender) => {
assign(store, extender({ store, app: pinia._a, pinia, options }));
});
return store;
}
// only warn the dev once
let isDevWarned;
/**

@@ -265,4 +456,7 @@ * Creates a `useStore` function that retrieves the store instance

function useStore(pinia) {
const hasInstance = vue.getCurrentInstance();
// only run provide when pinia hasn't been manually passed
const shouldProvide = hasInstance && !pinia;
// avoid injecting if `useStore` when not possible
pinia = pinia || (vue.getCurrentInstance() && vue.inject(piniaSymbol));
pinia = pinia || (hasInstance && vue.inject(piniaSymbol));
if (pinia)

@@ -279,19 +473,23 @@ setActivePinia(pinia);

stores.set(id, storeAndDescriptor);
const store = buildStoreToUse(storeAndDescriptor[0], storeAndDescriptor[1], id, getters, actions);
const store = buildStoreToUse(storeAndDescriptor[0], storeAndDescriptor[1], id, getters, actions,
// @ts-expect-error: because of the extend on Actions
options);
// allow children to reuse this store instance to avoid creating a new
// store for each child
if (shouldProvide) {
vue.provide(storeAndDescriptor[2], store);
}
if (IS_CLIENT &&
false &&
(process.env.NODE_ENV !== 'production') /*|| __FEATURE_PROD_DEVTOOLS__*/) {
/* istanbul ignore else */
if (!isDevWarned && !false) {
isDevWarned = true;
console.warn(`[๐Ÿ]: store was instantiated before calling\n` +
`app.use(pinia)\n` +
`Make sure to install pinia's plugin by using createPinia:\n` +
`https://github.com/posva/pinia/tree/v2#install-the-plugin\n` +
`It will enable devtools and overall a better developer experience.`);
}
getClientApp().then((app) => addDevtools(app, store));
}
return store;
}
return buildStoreToUse(storeAndDescriptor[0], storeAndDescriptor[1], id, getters, actions);
return (
// null avoids the warning for not found injection key
(hasInstance && vue.inject(storeAndDescriptor[2], null)) ||
buildStoreToUse(storeAndDescriptor[0], storeAndDescriptor[1], id, getters, actions,
// @ts-expect-error: because of the extend on Actions
options));
}

@@ -343,2 +541,11 @@ // needed by map helpers

function mapStores(...stores) {
if ((process.env.NODE_ENV !== 'production') && Array.isArray(stores[0])) {
console.warn(`[๐Ÿ]: Directly pass all stores to "mapStores()" without putting them in an array:\n` +
`Replace\n` +
`\tmapStores([useAuthStore, useCartStore])\n` +
`with\n` +
`\tmapStores(useAuthStore, useCartStore)\n` +
`This will fail in production if not fixed.`);
stores = stores[0];
}
return stores.reduce((reduced, useStore) => {

@@ -420,2 +627,3 @@ // @ts-ignore: $id is added by defineStore

? keysOrMapper.reduce((reduced, key) => {
// @ts-ignore
reduced[key] = {

@@ -422,0 +630,0 @@ get() {

/*!
* pinia v2.0.0-alpha.13
* pinia v2.0.0-alpha.14
* (c) 2021 Eduardo San Martin Morote

@@ -37,2 +37,8 @@ * @license MIT

const storesMap = new WeakMap();
/**
* Expose the client-side application instance used for devtools
*/
let clientAppPromise;
const getClientApp = () => clientAppPromise ||
(clientAppPromise = new Promise((resolve) => (resolve)));
const piniaSymbol = (/* istanbul ignore next */

@@ -53,7 +59,7 @@ Symbol());

install(app) {
localApp = app;
pinia._a = localApp = app;
// pinia._a = app
app.provide(piniaSymbol, pinia);
app.config.globalProperties.$pinia = pinia;
toBeInstalled.forEach((plugin) => _p.push(plugin.bind(null, localApp)));
toBeInstalled.forEach((plugin) => _p.push(plugin));
},

@@ -65,6 +71,9 @@ use(plugin) {

else {
_p.push(plugin.bind(null, localApp));
_p.push(plugin);
}
return this;
},
_p,
// it's actually undefined here
_a: localApp,
state,

@@ -84,2 +93,177 @@ };

function getDevtoolsGlobalHook() {
return getTarget().__VUE_DEVTOOLS_GLOBAL_HOOK__;
}
function getTarget() {
// @ts-ignore
return typeof navigator !== 'undefined'
? window
: typeof global !== 'undefined'
? global
: {};
}
const HOOK_SETUP = 'devtools-plugin:setup';
function setupDevtoolsPlugin(pluginDescriptor, setupFn) {
const hook = getDevtoolsGlobalHook();
if (hook) {
hook.emit(HOOK_SETUP, pluginDescriptor, setupFn);
}
else {
const target = getTarget();
const list = target.__VUE_DEVTOOLS_PLUGINS__ = target.__VUE_DEVTOOLS_PLUGINS__ || [];
list.push({
pluginDescriptor,
setupFn
});
}
}
function formatDisplay(display) {
return {
_custom: {
display,
},
};
}
/**
* Registered stores used for devtools.
*/
const registeredStores = /*#__PURE__*/ new Set();
function toastMessage(message, type) {
const piniaMessage = '๐Ÿ ' + message;
if (typeof __VUE_DEVTOOLS_TOAST__ === 'function') {
__VUE_DEVTOOLS_TOAST__(piniaMessage, type);
}
else if (type === 'error') {
console.error(piniaMessage);
}
else if (type === 'warning') {
console.warn(piniaMessage);
}
else {
console.log(piniaMessage);
}
}
let isAlreadyInstalled;
const componentStateTypes = [];
function addDevtools(app, store) {
registeredStores.add(store);
componentStateTypes.push('๐Ÿ ' + store.$id);
setupDevtoolsPlugin({
id: 'dev.esm.pinia',
label: 'Pinia ๐Ÿ',
logo: 'https://pinia.esm.dev/logo.svg',
packageName: 'pinia',
homepage: 'https://pinia.esm.dev',
componentStateTypes,
app,
}, (api) => {
// watch(router.currentRoute, () => {
// // @ts-ignore
// api.notifyComponentUpdate()
// })
const mutationsLayerId = 'pinia:mutations';
const piniaInspectorId = 'pinia';
if (!isAlreadyInstalled) {
api.on.inspectComponent((payload, ctx) => {
if (payload.instanceData) {
payload.instanceData.state.push({
type: '๐Ÿ ' + store.$id,
key: 'state',
editable: false,
value: store.$state,
});
}
});
api.addTimelineLayer({
id: mutationsLayerId,
label: `Pinia ๐Ÿ`,
color: 0xe5df88,
});
api.addInspector({
id: piniaInspectorId,
label: 'Pinia ๐Ÿ',
icon: 'storage',
treeFilterPlaceholder: 'Search stores',
});
isAlreadyInstalled = true;
}
else {
api.notifyComponentUpdate();
api.sendInspectorTree(piniaInspectorId);
api.sendInspectorState(piniaInspectorId);
}
store.$subscribe((mutation, state) => {
// rootStore.state[store.id] = state
const data = {
store: formatDisplay(mutation.storeName),
// type: formatDisplay(mutation.type),
};
if (mutation.payload) {
data.payload = mutation.payload;
}
api.notifyComponentUpdate();
api.sendInspectorState(piniaInspectorId);
api.addTimelineEvent({
layerId: mutationsLayerId,
event: {
time: Date.now(),
title: mutation.type,
data,
},
});
});
api.on.getInspectorTree((payload) => {
if (payload.app === app && payload.inspectorId === piniaInspectorId) {
const stores = Array.from(registeredStores);
payload.rootNodes = (payload.filter
? stores.filter((store) => store.$id.toLowerCase().includes(payload.filter.toLowerCase()))
: stores).map(formatStoreForInspectorTree);
}
});
api.on.getInspectorState((payload) => {
if (payload.app === app && payload.inspectorId === piniaInspectorId) {
const stores = Array.from(registeredStores);
const store = stores.find((store) => store.$id === payload.nodeId);
if (store) {
payload.state = {
options: formatStoreForInspectorState(store),
};
}
else {
toastMessage(`store "${payload.nodeId}" not found`, 'error');
}
}
});
// trigger an update so it can display new registered stores
// @ts-ignore
api.notifyComponentUpdate();
toastMessage(`"${store.$id}" store installed`);
});
}
function formatStoreForInspectorTree(store) {
return {
id: store.$id,
label: store.$id,
tags: [],
};
}
function formatStoreForInspectorState(store) {
const fields = [
{ editable: false, key: 'id', value: formatDisplay(store.$id) },
{ editable: true, key: 'state', value: store.$state },
{
editable: false,
key: 'getters',
value: (store._getters || []).reduce((getters, key) => {
getters[key] = store[key];
return getters;
}, {}),
},
];
return fields;
}
function innerPatch(target, patchToApply) {

@@ -187,2 +371,4 @@ // TODO: get all keys like symbols as well

};
const injectionSymbol = /* istanbul ignore next */
Symbol();
return [

@@ -198,2 +384,3 @@ storeWithState,

},
injectionSymbol,
];

@@ -213,9 +400,11 @@ }

*/
function buildStoreToUse(partialStore, descriptor, $id, getters = {}, actions = {}) {
function buildStoreToUse(partialStore, descriptor, $id, getters = {}, actions = {}, options) {
const pinia = getActivePinia();
const computedGetters = {};
for (const getterName in getters) {
// @ts-ignore: it's only readonly for the users
computedGetters[getterName] = vue.computed(() => {
setActivePinia(pinia);
// eslint-disable-next-line @typescript-eslint/no-use-before-define
// @ts-expect-error: the argument count is correct
return getters[getterName].call(store, store);

@@ -232,4 +421,3 @@ });

}
const extensions = pinia._p.reduce((extended, extender) => assign({}, extended, extender()), {});
const store = vue.reactive(assign({}, extensions, partialStore,
const store = vue.reactive(assign({}, partialStore,
// using this means no new properties can be added as state

@@ -241,6 +429,11 @@ computedFromState(pinia.state, $id), computedGetters, wrappedActions));

Object.defineProperty(store, '$state', descriptor);
if (IS_CLIENT && false && false) {
store._getters = Object.keys(getters);
}
// apply all plugins
pinia._p.forEach((extender) => {
assign(store, extender({ store, app: pinia._a, pinia, options }));
});
return store;
}
// only warn the dev once
let isDevWarned;
/**

@@ -253,4 +446,7 @@ * Creates a `useStore` function that retrieves the store instance

function useStore(pinia) {
const hasInstance = vue.getCurrentInstance();
// only run provide when pinia hasn't been manually passed
const shouldProvide = hasInstance && !pinia;
// avoid injecting if `useStore` when not possible
pinia = pinia || (vue.getCurrentInstance() && vue.inject(piniaSymbol));
pinia = pinia || (hasInstance && vue.inject(piniaSymbol));
if (pinia)

@@ -267,19 +463,23 @@ setActivePinia(pinia);

stores.set(id, storeAndDescriptor);
const store = buildStoreToUse(storeAndDescriptor[0], storeAndDescriptor[1], id, getters, actions);
const store = buildStoreToUse(storeAndDescriptor[0], storeAndDescriptor[1], id, getters, actions,
// @ts-expect-error: because of the extend on Actions
options);
// allow children to reuse this store instance to avoid creating a new
// store for each child
if (shouldProvide) {
vue.provide(storeAndDescriptor[2], store);
}
if (IS_CLIENT &&
false &&
false /*|| __FEATURE_PROD_DEVTOOLS__*/) {
/* istanbul ignore else */
if (!isDevWarned && !false) {
isDevWarned = true;
console.warn(`[๐Ÿ]: store was instantiated before calling\n` +
`app.use(pinia)\n` +
`Make sure to install pinia's plugin by using createPinia:\n` +
`https://github.com/posva/pinia/tree/v2#install-the-plugin\n` +
`It will enable devtools and overall a better developer experience.`);
}
getClientApp().then((app) => addDevtools(app, store));
}
return store;
}
return buildStoreToUse(storeAndDescriptor[0], storeAndDescriptor[1], id, getters, actions);
return (
// null avoids the warning for not found injection key
(hasInstance && vue.inject(storeAndDescriptor[2], null)) ||
buildStoreToUse(storeAndDescriptor[0], storeAndDescriptor[1], id, getters, actions,
// @ts-expect-error: because of the extend on Actions
options));
}

@@ -407,2 +607,3 @@ // needed by map helpers

? keysOrMapper.reduce((reduced, key) => {
// @ts-ignore
reduced[key] = {

@@ -409,0 +610,0 @@ get() {

@@ -24,3 +24,3 @@ import { App } from 'vue';

*/
export declare function defineStore<Id extends string, S extends StateTree, G, A>(options: DefineStoreOptions<Id, S, G, A>): StoreDefinition<Id, S, G, A>;
export declare function defineStore<Id extends string, S extends StateTree, G extends GettersTree<S>, A>(options: DefineStoreOptions<Id, S, G, A>): StoreDefinition<Id, S, G, A>;

@@ -31,6 +31,18 @@ /**

*/
export declare interface DefineStoreOptions<Id extends string, S extends StateTree, G, A> {
export declare interface DefineStoreOptions<Id extends string, S extends StateTree, G extends GettersTree<S>, A> {
/**
* Unique string key to identify the store across the application.
*/
id: Id;
/**
* Function to create a fresh state.
*/
state?: () => S;
/**
* Optional object of getters.
*/
getters?: G & ThisType<S & StoreWithGetters<G> & PiniaCustomProperties>;
/**
* Optional object of actions.
*/
actions?: A & ThisType<A & S & StoreWithState<Id, S> & StoreWithGetters<G> & PiniaCustomProperties>;

@@ -42,8 +54,10 @@ }

*/
declare type GenericStore = Store<string, StateTree, Record<string, Method>, Record<string, Method>>;
export declare type GenericStore = Store<string, StateTree, GettersTree<StateTree>, Record<string, _Method>>;
/**
* Generic version of `StoreDefinition`.
* Type of an object of Getters that infers the argument
*
* @internal
*/
declare type GenericStoreDefinition = StoreDefinition<string, StateTree, Record<string, Method>, Record<string, Method>>;
export declare type GettersTree<S extends StateTree> = Record<string, ((state: S) => any) | (() => any)>;

@@ -75,3 +89,3 @@ /**

*/
export declare function mapActions<Id extends string, S extends StateTree, G, A, KeyMapper extends Record<string, keyof A>>(useStore: StoreDefinition<Id, S, G, A>, keyMapper: KeyMapper): MapActionsObjectReturn<A, KeyMapper>;
export declare function mapActions<Id extends string, S extends StateTree, G extends GettersTree<S>, A, KeyMapper extends Record<string, keyof A>>(useStore: StoreDefinition<Id, S, G, A>, keyMapper: KeyMapper): _MapActionsObjectReturn<A, KeyMapper>;

@@ -101,9 +115,15 @@ /**

*/
export declare function mapActions<Id extends string, S extends StateTree, G, A>(useStore: StoreDefinition<Id, S, G, A>, keys: Array<keyof A>): MapActionsReturn<A>;
export declare function mapActions<Id extends string, S extends StateTree, G extends GettersTree<S>, A>(useStore: StoreDefinition<Id, S, G, A>, keys: Array<keyof A>): _MapActionsReturn<A>;
declare type MapActionsObjectReturn<A, T extends Record<string, keyof A>> = {
/**
* @internal
*/
export declare type _MapActionsObjectReturn<A, T extends Record<string, keyof A>> = {
[key in keyof T]: Store<string, StateTree, {}, A>[T[key]];
};
declare type MapActionsReturn<A> = {
/**
* @internal
*/
export declare type _MapActionsReturn<A> = {
[key in keyof A]: Store<string, StateTree, {}, A>[key];

@@ -154,3 +174,3 @@ };

*/
export declare function mapState<Id extends string, S extends StateTree, G, A, KeyMapper extends Record<string, keyof S | keyof G | ((store: Store<Id, S, G, A>) => any)>>(useStore: StoreDefinition<Id, S, G, A>, keyMapper: KeyMapper): MapStateObjectReturn<Id, S, G, A, KeyMapper>;
export declare function mapState<Id extends string, S extends StateTree, G extends GettersTree<S>, A, KeyMapper extends Record<string, keyof S | keyof G | ((store: Store<Id, S, G, A>) => any)>>(useStore: StoreDefinition<Id, S, G, A>, keyMapper: KeyMapper): _MapStateObjectReturn<Id, S, G, A, KeyMapper>;

@@ -180,9 +200,15 @@ /**

*/
export declare function mapState<Id extends string, S extends StateTree, G, A>(useStore: StoreDefinition<Id, S, G, A>, keys: Array<keyof S | keyof G>): MapStateReturn<S, G>;
export declare function mapState<Id extends string, S extends StateTree, G extends GettersTree<S>, A>(useStore: StoreDefinition<Id, S, G, A>, keys: Array<keyof S | keyof G>): _MapStateReturn<S, G>;
declare type MapStateObjectReturn<Id extends string, S extends StateTree, G, A, T extends Record<string, keyof S | keyof G | ((store: Store<Id, S, G, A>) => any)>> = {
/**
* @internal
*/
export declare type _MapStateObjectReturn<Id extends string, S extends StateTree, G extends GettersTree<S>, A, T extends Record<string, keyof S | keyof G | ((store: Store<Id, S, G, A>) => any)>> = {
[key in keyof T]: () => T[key] extends (store: GenericStore) => infer R ? R : T[key] extends keyof S | keyof G ? Store<Id, S, G, A>[T[key]] : never;
};
declare type MapStateReturn<S extends StateTree, G> = {
/**
* @internal
*/
export declare type _MapStateReturn<S extends StateTree, G extends GettersTree<S>> = {
[key in keyof S | keyof G]: () => Store<string, S, G, {}>[key];

@@ -213,3 +239,3 @@ };

*/
export declare function mapStores<Stores extends GenericStoreDefinition[]>(...stores: [...Stores]): Spread<Stores>;
export declare function mapStores<Stores extends any[]>(...stores: [...Stores]): _Spread<Stores>;

@@ -233,3 +259,3 @@ /**

*/
export declare function mapWritableState<Id extends string, S extends StateTree, G, A, KeyMapper extends Record<string, keyof S>>(useStore: StoreDefinition<Id, S, G, A>, keyMapper: KeyMapper): MapWritableStateObjectReturn<S, KeyMapper>;
export declare function mapWritableState<Id extends string, S extends StateTree, G extends GettersTree<S>, A, KeyMapper extends Record<string, keyof S>>(useStore: StoreDefinition<Id, S, G, A>, keyMapper: KeyMapper): _MapWritableStateObjectReturn<S, KeyMapper>;

@@ -244,5 +270,8 @@ /**

*/
export declare function mapWritableState<Id extends string, S extends StateTree, G, A>(useStore: StoreDefinition<Id, S, G, A>, keys: Array<keyof S>): MapWritableStateReturn<S>;
export declare function mapWritableState<Id extends string, S extends StateTree, G extends GettersTree<S>, A>(useStore: StoreDefinition<Id, S, G, A>, keys: Array<keyof S>): _MapWritableStateReturn<S>;
declare type MapWritableStateObjectReturn<S extends StateTree, T extends Record<string, keyof S>> = {
/**
* @internal
*/
export declare type _MapWritableStateObjectReturn<S extends StateTree, T extends Record<string, keyof S>> = {
[key in keyof T]: {

@@ -254,3 +283,6 @@ get: () => Store<string, S, {}, {}>[T[key]];

declare type MapWritableStateReturn<S extends StateTree> = {
/**
* @internal
*/
export declare type _MapWritableStateReturn<S extends StateTree> = {
[key in keyof S]: {

@@ -262,3 +294,8 @@ get: () => Store<string, S, {}, {}>[key];

declare type Method = (...args: any[]) => any;
/**
* Generic type for a function that can infer arguments and return type
*
* @internal
*/
export declare type _Method = (...args: any[]) => any;

@@ -279,3 +316,3 @@ /**

*/
use(plugin: PiniaStorePlugin): void;
use(plugin: PiniaStorePlugin): Pinia;
/**

@@ -286,3 +323,9 @@ * Installed store plugins

*/
_p: Array<() => Partial<PiniaCustomProperties>>;
_p: Array<PiniaStorePlugin>;
/**
* App linked to this Pinia instance
*
* @internal
*/
_a: App;
}

@@ -293,10 +336,38 @@

*/
export declare interface PiniaCustomProperties<Id extends string = string, S extends StateTree = StateTree, G = Record<string, Method>, A = Record<string, Method>> {
export declare interface PiniaCustomProperties<Id extends string = string, S extends StateTree = StateTree, G extends GettersTree<S> = GettersTree<S>, A = Record<string, _Method>> {
}
/**
* Context argument passed to Pinia plugins.
*/
export declare interface PiniaPluginContext<Id extends string = string, S extends StateTree = StateTree, G extends GettersTree<S> = GettersTree<S>, A = Record<string, _Method>> {
/**
* pinia instance.
*/
pinia: Pinia;
/**
* Current app created with `Vue.createApp()`.
*/
app: App;
/**
* Current store being extended.
*/
store: Store<Id, S, G, A>;
/**
* Current store being extended.
*/
options: DefineStoreOptions<Id, S, G, A>;
}
/**
* Plugin to extend every store
*/
export declare interface PiniaStorePlugin {
(app: App): Partial<PiniaCustomProperties>;
/**
* Plugin to extend every store. Returns an object to extend the store or
* nothing.
*
* @param context - Context
*/
(context: PiniaPluginContext): Partial<PiniaCustomProperties> | void;
}

@@ -321,3 +392,6 @@

declare type Spread<A extends readonly any[]> = A extends [infer L, ...infer R] ? StoreObject<L> & Spread<R> : unknown;
/**
* @internal
*/
export declare type _Spread<A extends readonly any[]> = A extends [infer L, ...infer R] ? _StoreObject<L> & _Spread<R> : unknown;

@@ -332,3 +406,3 @@ /**

*/
export declare type Store<Id extends string, S extends StateTree, G, A> = StoreWithState<Id, S> & S & StoreWithGetters<G> & StoreWithActions<A> & PiniaCustomProperties<Id, S, G, A>;
export declare type Store<Id extends string, S extends StateTree, G extends GettersTree<S>, A> = StoreWithState<Id, S> & S & StoreWithGetters<G> & StoreWithActions<A> & PiniaCustomProperties<Id, S, G, A>;

@@ -338,8 +412,19 @@ /**

*/
declare interface StoreDefinition<Id extends string, S extends StateTree, G, A> {
export declare interface StoreDefinition<Id extends string, S extends StateTree, G extends GettersTree<S>, A> {
/**
* Returns a store, creates it if necessary.
*
* @param pinia - Pinia instance to retrieve the store
*/
(pinia?: Pinia | null | undefined): Store<Id, S, G, A>;
/**
* Id of the store. Used by map helpers.
*/
$id: Id;
}
declare type StoreObject<S> = S extends StoreDefinition<infer Ids, infer State, infer Getters, infer Actions> ? {
/**
* @internal
*/
export declare type _StoreObject<S> = S extends StoreDefinition<infer Ids, infer State, infer Getters, infer Actions> ? {
[Id in `${Ids}${'suffix' extends keyof MapStoresCustomization ? MapStoresCustomization['suffix'] : 'Store'}`]: () => Store<Id extends `${infer RealId}${'suffix' extends keyof MapStoresCustomization ? MapStoresCustomization['suffix'] : 'Store'}` ? RealId : string, State, Getters, Actions>;

@@ -350,2 +435,3 @@ } : {};

* Store augmented for actions
*
* @internal

@@ -359,6 +445,7 @@ */

* Store augmented with getters
*
* @internal
*/
export declare type StoreWithGetters<G> = {
[k in keyof G]: G[k] extends (this: infer This, store?: any) => infer R ? R : never;
readonly [k in keyof G]: G[k] extends (...args: any[]) => infer R ? R : never;
};

@@ -386,2 +473,8 @@

/**
* Used by devtools plugin to retrieve getters. Removed in production
*
* @internal
*/
_getters?: string[];
/**
* Applies a state patch to current state. Allows passing nested values

@@ -388,0 +481,0 @@ *

99

dist/pinia.esm-browser.js
/*!
* pinia v2.0.0-alpha.13
* pinia v2.0.0-alpha.14
* (c) 2021 Eduardo San Martin Morote
* @license MIT
*/
import { ref, warn, getCurrentInstance, inject, computed, reactive, watch, onUnmounted } from 'vue';
import { ref, warn, getCurrentInstance, inject, provide, computed, reactive, watch, onUnmounted } from 'vue';

@@ -40,7 +40,9 @@ const IS_CLIENT = typeof window !== 'undefined';

/**
* Client-side application instance used for devtools
* Expose the client-side application instance used for devtools
*/
let clientApp; /*#__PURE__*/
const setClientApp = (app) => (clientApp = app);
const getClientApp = () => clientApp;
let clientAppPromise;
let resolveApp;
const setClientApp = (app) => resolveApp && resolveApp(app);
const getClientApp = () => clientAppPromise ||
(clientAppPromise = new Promise((resolve) => (resolveApp = resolve)));
const piniaSymbol = (Symbol('pinia')

@@ -61,3 +63,3 @@ );

install(app) {
localApp = app;
pinia._a = localApp = app;
// pinia._a = app

@@ -74,9 +76,5 @@ app.provide(piniaSymbol, pinia);

}
toBeInstalled.forEach((plugin) => _p.push(plugin.bind(null, localApp)));
toBeInstalled.forEach((plugin) => _p.push(plugin));
},
use(plugin) {
/* istanbul ignore next */
{
console.warn(`[๐Ÿ]: The plugin API has plans to change to bring better extensibility. "pinia.use()" signature will change in the next release. It is recommended to avoid using this API.`);
}
if (!localApp) {

@@ -86,6 +84,9 @@ toBeInstalled.push(plugin);

else {
_p.push(plugin.bind(null, localApp));
_p.push(plugin);
}
return this;
},
_p,
// it's actually undefined here
_a: localApp,
state,

@@ -268,2 +269,10 @@ };

{ editable: true, key: 'state', value: store.$state },
{
editable: false,
key: 'getters',
value: (store._getters || []).reduce((getters, key) => {
getters[key] = store[key];
return getters;
}, {}),
},
];

@@ -375,2 +384,4 @@ return fields;

};
const injectionSymbol = Symbol(`PiniaStore(${$id})`)
;
return [

@@ -386,2 +397,3 @@ storeWithState,

},
injectionSymbol,
];

@@ -401,9 +413,11 @@ }

*/
function buildStoreToUse(partialStore, descriptor, $id, getters = {}, actions = {}) {
function buildStoreToUse(partialStore, descriptor, $id, getters = {}, actions = {}, options) {
const pinia = getActivePinia();
const computedGetters = {};
for (const getterName in getters) {
// @ts-ignore: it's only readonly for the users
computedGetters[getterName] = computed(() => {
setActivePinia(pinia);
// eslint-disable-next-line @typescript-eslint/no-use-before-define
// @ts-expect-error: the argument count is correct
return getters[getterName].call(store, store);

@@ -420,4 +434,3 @@ });

}
const extensions = pinia._p.reduce((extended, extender) => assign({}, extended, extender()), {});
const store = reactive(assign({}, extensions, partialStore,
const store = reactive(assign({}, partialStore,
// using this means no new properties can be added as state

@@ -429,6 +442,11 @@ computedFromState(pinia.state, $id), computedGetters, wrappedActions));

Object.defineProperty(store, '$state', descriptor);
if (IS_CLIENT && true && true) {
store._getters = Object.keys(getters);
}
// apply all plugins
pinia._p.forEach((extender) => {
assign(store, extender({ store, app: pinia._a, pinia, options }));
});
return store;
}
// only warn the dev once
let isDevWarned;
/**

@@ -441,4 +459,7 @@ * Creates a `useStore` function that retrieves the store instance

function useStore(pinia) {
const hasInstance = getCurrentInstance();
// only run provide when pinia hasn't been manually passed
const shouldProvide = hasInstance && !pinia;
// avoid injecting if `useStore` when not possible
pinia = pinia || (getCurrentInstance() && inject(piniaSymbol));
pinia = pinia || (hasInstance && inject(piniaSymbol));
if (pinia)

@@ -455,23 +476,23 @@ setActivePinia(pinia);

stores.set(id, storeAndDescriptor);
const store = buildStoreToUse(storeAndDescriptor[0], storeAndDescriptor[1], id, getters, actions);
const store = buildStoreToUse(storeAndDescriptor[0], storeAndDescriptor[1], id, getters, actions,
// @ts-expect-error: because of the extend on Actions
options);
// allow children to reuse this store instance to avoid creating a new
// store for each child
if (shouldProvide) {
provide(storeAndDescriptor[2], store);
}
if (IS_CLIENT &&
true &&
true /*|| __FEATURE_PROD_DEVTOOLS__*/) {
const app = getClientApp();
/* istanbul ignore else */
if (app) {
addDevtools(app, store);
}
else if (!isDevWarned && !false) {
isDevWarned = true;
console.warn(`[๐Ÿ]: store was instantiated before calling\n` +
`app.use(pinia)\n` +
`Make sure to install pinia's plugin by using createPinia:\n` +
`https://github.com/posva/pinia/tree/v2#install-the-plugin\n` +
`It will enable devtools and overall a better developer experience.`);
}
getClientApp().then((app) => addDevtools(app, store));
}
return store;
}
return buildStoreToUse(storeAndDescriptor[0], storeAndDescriptor[1], id, getters, actions);
return (
// null avoids the warning for not found injection key
(hasInstance && inject(storeAndDescriptor[2], null)) ||
buildStoreToUse(storeAndDescriptor[0], storeAndDescriptor[1], id, getters, actions,
// @ts-expect-error: because of the extend on Actions
options));
}

@@ -523,2 +544,11 @@ // needed by map helpers

function mapStores(...stores) {
if (Array.isArray(stores[0])) {
console.warn(`[๐Ÿ]: Directly pass all stores to "mapStores()" without putting them in an array:\n` +
`Replace\n` +
`\tmapStores([useAuthStore, useCartStore])\n` +
`with\n` +
`\tmapStores(useAuthStore, useCartStore)\n` +
`This will fail in production if not fixed.`);
stores = stores[0];
}
return stores.reduce((reduced, useStore) => {

@@ -600,2 +630,3 @@ // @ts-ignore: $id is added by defineStore

? keysOrMapper.reduce((reduced, key) => {
// @ts-ignore
reduced[key] = {

@@ -602,0 +633,0 @@ get() {

/*!
* pinia v2.0.0-alpha.13
* pinia v2.0.0-alpha.14
* (c) 2021 Eduardo San Martin Morote
* @license MIT
*/
import { ref, warn, getCurrentInstance, inject, computed, reactive, watch, onUnmounted } from 'vue';
import { ref, warn, getCurrentInstance, inject, provide, computed, reactive, watch, onUnmounted } from 'vue';

@@ -40,7 +40,9 @@ const IS_CLIENT = typeof window !== 'undefined';

/**
* Client-side application instance used for devtools
* Expose the client-side application instance used for devtools
*/
let clientApp; /*#__PURE__*/
const setClientApp = (app) => (clientApp = app);
const getClientApp = () => clientApp;
let clientAppPromise;
let resolveApp;
const setClientApp = (app) => resolveApp && resolveApp(app);
const getClientApp = () => clientAppPromise ||
(clientAppPromise = new Promise((resolve) => (resolveApp = resolve)));
const piniaSymbol = ((process.env.NODE_ENV !== 'production')

@@ -63,3 +65,3 @@ ? Symbol('pinia')

install(app) {
localApp = app;
pinia._a = localApp = app;
// pinia._a = app

@@ -76,9 +78,5 @@ app.provide(piniaSymbol, pinia);

}
toBeInstalled.forEach((plugin) => _p.push(plugin.bind(null, localApp)));
toBeInstalled.forEach((plugin) => _p.push(plugin));
},
use(plugin) {
/* istanbul ignore next */
if ((process.env.NODE_ENV !== 'production') && !(process.env.NODE_ENV === 'test')) {
console.warn(`[๐Ÿ]: The plugin API has plans to change to bring better extensibility. "pinia.use()" signature will change in the next release. It is recommended to avoid using this API.`);
}
if (!localApp) {

@@ -88,6 +86,9 @@ toBeInstalled.push(plugin);

else {
_p.push(plugin.bind(null, localApp));
_p.push(plugin);
}
return this;
},
_p,
// it's actually undefined here
_a: localApp,
state,

@@ -270,2 +271,10 @@ };

{ editable: true, key: 'state', value: store.$state },
{
editable: false,
key: 'getters',
value: (store._getters || []).reduce((getters, key) => {
getters[key] = store[key];
return getters;
}, {}),
},
];

@@ -377,2 +386,6 @@ return fields;

};
const injectionSymbol = (process.env.NODE_ENV !== 'production')
? Symbol(`PiniaStore(${$id})`)
: /* istanbul ignore next */
Symbol();
return [

@@ -388,2 +401,3 @@ storeWithState,

},
injectionSymbol,
];

@@ -403,9 +417,11 @@ }

*/
function buildStoreToUse(partialStore, descriptor, $id, getters = {}, actions = {}) {
function buildStoreToUse(partialStore, descriptor, $id, getters = {}, actions = {}, options) {
const pinia = getActivePinia();
const computedGetters = {};
for (const getterName in getters) {
// @ts-ignore: it's only readonly for the users
computedGetters[getterName] = computed(() => {
setActivePinia(pinia);
// eslint-disable-next-line @typescript-eslint/no-use-before-define
// @ts-expect-error: the argument count is correct
return getters[getterName].call(store, store);

@@ -422,4 +438,3 @@ });

}
const extensions = pinia._p.reduce((extended, extender) => assign({}, extended, extender()), {});
const store = reactive(assign({}, extensions, partialStore,
const store = reactive(assign({}, partialStore,
// using this means no new properties can be added as state

@@ -431,6 +446,11 @@ computedFromState(pinia.state, $id), computedGetters, wrappedActions));

Object.defineProperty(store, '$state', descriptor);
if (IS_CLIENT && true && (process.env.NODE_ENV !== 'production')) {
store._getters = Object.keys(getters);
}
// apply all plugins
pinia._p.forEach((extender) => {
assign(store, extender({ store, app: pinia._a, pinia, options }));
});
return store;
}
// only warn the dev once
let isDevWarned;
/**

@@ -443,4 +463,7 @@ * Creates a `useStore` function that retrieves the store instance

function useStore(pinia) {
const hasInstance = getCurrentInstance();
// only run provide when pinia hasn't been manually passed
const shouldProvide = hasInstance && !pinia;
// avoid injecting if `useStore` when not possible
pinia = pinia || (getCurrentInstance() && inject(piniaSymbol));
pinia = pinia || (hasInstance && inject(piniaSymbol));
if (pinia)

@@ -457,23 +480,23 @@ setActivePinia(pinia);

stores.set(id, storeAndDescriptor);
const store = buildStoreToUse(storeAndDescriptor[0], storeAndDescriptor[1], id, getters, actions);
const store = buildStoreToUse(storeAndDescriptor[0], storeAndDescriptor[1], id, getters, actions,
// @ts-expect-error: because of the extend on Actions
options);
// allow children to reuse this store instance to avoid creating a new
// store for each child
if (shouldProvide) {
provide(storeAndDescriptor[2], store);
}
if (IS_CLIENT &&
true &&
(process.env.NODE_ENV !== 'production') /*|| __FEATURE_PROD_DEVTOOLS__*/) {
const app = getClientApp();
/* istanbul ignore else */
if (app) {
addDevtools(app, store);
}
else if (!isDevWarned && !(process.env.NODE_ENV === 'test')) {
isDevWarned = true;
console.warn(`[๐Ÿ]: store was instantiated before calling\n` +
`app.use(pinia)\n` +
`Make sure to install pinia's plugin by using createPinia:\n` +
`https://github.com/posva/pinia/tree/v2#install-the-plugin\n` +
`It will enable devtools and overall a better developer experience.`);
}
getClientApp().then((app) => addDevtools(app, store));
}
return store;
}
return buildStoreToUse(storeAndDescriptor[0], storeAndDescriptor[1], id, getters, actions);
return (
// null avoids the warning for not found injection key
(hasInstance && inject(storeAndDescriptor[2], null)) ||
buildStoreToUse(storeAndDescriptor[0], storeAndDescriptor[1], id, getters, actions,
// @ts-expect-error: because of the extend on Actions
options));
}

@@ -525,2 +548,11 @@ // needed by map helpers

function mapStores(...stores) {
if ((process.env.NODE_ENV !== 'production') && Array.isArray(stores[0])) {
console.warn(`[๐Ÿ]: Directly pass all stores to "mapStores()" without putting them in an array:\n` +
`Replace\n` +
`\tmapStores([useAuthStore, useCartStore])\n` +
`with\n` +
`\tmapStores(useAuthStore, useCartStore)\n` +
`This will fail in production if not fixed.`);
stores = stores[0];
}
return stores.reduce((reduced, useStore) => {

@@ -602,2 +634,3 @@ // @ts-ignore: $id is added by defineStore

? keysOrMapper.reduce((reduced, key) => {
// @ts-ignore
reduced[key] = {

@@ -604,0 +637,0 @@ get() {

/*!
* pinia v2.0.0-alpha.13
* pinia v2.0.0-alpha.14
* (c) 2021 Eduardo San Martin Morote

@@ -41,7 +41,9 @@ * @license MIT

/**
* Client-side application instance used for devtools
* Expose the client-side application instance used for devtools
*/
let clientApp; /*#__PURE__*/
const setClientApp = (app) => (clientApp = app);
const getClientApp = () => clientApp;
let clientAppPromise;
let resolveApp;
const setClientApp = (app) => resolveApp && resolveApp(app);
const getClientApp = () => clientAppPromise ||
(clientAppPromise = new Promise((resolve) => (resolveApp = resolve)));
const piniaSymbol = (Symbol('pinia')

@@ -62,3 +64,3 @@ );

install(app) {
localApp = app;
pinia._a = localApp = app;
// pinia._a = app

@@ -75,9 +77,5 @@ app.provide(piniaSymbol, pinia);

}
toBeInstalled.forEach((plugin) => _p.push(plugin.bind(null, localApp)));
toBeInstalled.forEach((plugin) => _p.push(plugin));
},
use(plugin) {
/* istanbul ignore next */
{
console.warn(`[๐Ÿ]: The plugin API has plans to change to bring better extensibility. "pinia.use()" signature will change in the next release. It is recommended to avoid using this API.`);
}
if (!localApp) {

@@ -87,6 +85,9 @@ toBeInstalled.push(plugin);

else {
_p.push(plugin.bind(null, localApp));
_p.push(plugin);
}
return this;
},
_p,
// it's actually undefined here
_a: localApp,
state,

@@ -269,2 +270,10 @@ };

{ editable: true, key: 'state', value: store.$state },
{
editable: false,
key: 'getters',
value: (store._getters || []).reduce((getters, key) => {
getters[key] = store[key];
return getters;
}, {}),
},
];

@@ -376,2 +385,4 @@ return fields;

};
const injectionSymbol = Symbol(`PiniaStore(${$id})`)
;
return [

@@ -387,2 +398,3 @@ storeWithState,

},
injectionSymbol,
];

@@ -402,9 +414,11 @@ }

*/
function buildStoreToUse(partialStore, descriptor, $id, getters = {}, actions = {}) {
function buildStoreToUse(partialStore, descriptor, $id, getters = {}, actions = {}, options) {
const pinia = getActivePinia();
const computedGetters = {};
for (const getterName in getters) {
// @ts-ignore: it's only readonly for the users
computedGetters[getterName] = vue.computed(() => {
setActivePinia(pinia);
// eslint-disable-next-line @typescript-eslint/no-use-before-define
// @ts-expect-error: the argument count is correct
return getters[getterName].call(store, store);

@@ -421,4 +435,3 @@ });

}
const extensions = pinia._p.reduce((extended, extender) => assign({}, extended, extender()), {});
const store = vue.reactive(assign({}, extensions, partialStore,
const store = vue.reactive(assign({}, partialStore,
// using this means no new properties can be added as state

@@ -430,6 +443,11 @@ computedFromState(pinia.state, $id), computedGetters, wrappedActions));

Object.defineProperty(store, '$state', descriptor);
if (IS_CLIENT && true && true) {
store._getters = Object.keys(getters);
}
// apply all plugins
pinia._p.forEach((extender) => {
assign(store, extender({ store, app: pinia._a, pinia, options }));
});
return store;
}
// only warn the dev once
let isDevWarned;
/**

@@ -442,4 +460,7 @@ * Creates a `useStore` function that retrieves the store instance

function useStore(pinia) {
const hasInstance = vue.getCurrentInstance();
// only run provide when pinia hasn't been manually passed
const shouldProvide = hasInstance && !pinia;
// avoid injecting if `useStore` when not possible
pinia = pinia || (vue.getCurrentInstance() && vue.inject(piniaSymbol));
pinia = pinia || (hasInstance && vue.inject(piniaSymbol));
if (pinia)

@@ -456,23 +477,23 @@ setActivePinia(pinia);

stores.set(id, storeAndDescriptor);
const store = buildStoreToUse(storeAndDescriptor[0], storeAndDescriptor[1], id, getters, actions);
const store = buildStoreToUse(storeAndDescriptor[0], storeAndDescriptor[1], id, getters, actions,
// @ts-expect-error: because of the extend on Actions
options);
// allow children to reuse this store instance to avoid creating a new
// store for each child
if (shouldProvide) {
vue.provide(storeAndDescriptor[2], store);
}
if (IS_CLIENT &&
true &&
true /*|| __FEATURE_PROD_DEVTOOLS__*/) {
const app = getClientApp();
/* istanbul ignore else */
if (app) {
addDevtools(app, store);
}
else if (!isDevWarned && !false) {
isDevWarned = true;
console.warn(`[๐Ÿ]: store was instantiated before calling\n` +
`app.use(pinia)\n` +
`Make sure to install pinia's plugin by using createPinia:\n` +
`https://github.com/posva/pinia/tree/v2#install-the-plugin\n` +
`It will enable devtools and overall a better developer experience.`);
}
getClientApp().then((app) => addDevtools(app, store));
}
return store;
}
return buildStoreToUse(storeAndDescriptor[0], storeAndDescriptor[1], id, getters, actions);
return (
// null avoids the warning for not found injection key
(hasInstance && vue.inject(storeAndDescriptor[2], null)) ||
buildStoreToUse(storeAndDescriptor[0], storeAndDescriptor[1], id, getters, actions,
// @ts-expect-error: because of the extend on Actions
options));
}

@@ -524,2 +545,11 @@ // needed by map helpers

function mapStores(...stores) {
if (Array.isArray(stores[0])) {
console.warn(`[๐Ÿ]: Directly pass all stores to "mapStores()" without putting them in an array:\n` +
`Replace\n` +
`\tmapStores([useAuthStore, useCartStore])\n` +
`with\n` +
`\tmapStores(useAuthStore, useCartStore)\n` +
`This will fail in production if not fixed.`);
stores = stores[0];
}
return stores.reduce((reduced, useStore) => {

@@ -601,2 +631,3 @@ // @ts-ignore: $id is added by defineStore

? keysOrMapper.reduce((reduced, key) => {
// @ts-ignore
reduced[key] = {

@@ -603,0 +634,0 @@ get() {

/*!
* pinia v2.0.0-alpha.13
* pinia v2.0.0-alpha.14
* (c) 2021 Eduardo San Martin Morote
* @license MIT
*/
var Pinia=function(t,e){"use strict";const n="undefined"!=typeof window;let r;const o=t=>r=t,c=()=>r,s=new WeakMap;let u;const i=Symbol();function a(t){return t&&"object"==typeof t&&"[object Object]"===Object.prototype.toString.call(t)&&"function"!=typeof t.toJSON}function f(t,e){for(const n in e){const r=e[n],o=t[n];t[n]=a(o)&&a(r)?f(o,r):r}return t}const{assign:l}=Object;function p(t,n=(()=>({})),r){const o=c();o.state.value[t]=r||n();let s=!0,u=[];return[{$id:t,_p:o,$patch:function(e){let n,r={};s=!1,"function"==typeof e?(e(o.state.value[t]),n="๐Ÿงฉ patch"):(f(o.state.value[t],e),r=e,n="โคต๏ธ patch"),s=!0,u.forEach(e=>{e({storeName:t,type:n,payload:r},o.state.value[t])})},$subscribe:function(n){u.push(n);const r=e.watch(()=>o.state.value[t],e=>{s&&n({storeName:t,type:"๐Ÿงฉ in place",payload:{}},e)},{deep:!0,flush:"sync"}),c=()=>{const t=u.indexOf(n);t>-1&&(u.splice(t,1),r())};return e.getCurrentInstance()&&e.onUnmounted(c),c},$reset:function(){o.state.value[t]=n()}},{get:()=>o.state.value[t],set:e=>{s=!1,o.state.value[t]=e,s=!0}}]}function d(t,n,r,s={},u={}){const i=c(),a={};for(const t in s)a[t]=e.computed(()=>(o(i),s[t].call(d,d)));const f={};for(const t in u)f[t]=function(){return o(i),u[t].apply(d,arguments)};const p=i._p.reduce((t,e)=>l({},t,e()),{}),d=e.reactive(l({},p,t,function(t,n){const r={},o=t.value[n];for(const c in o)r[c]=e.computed({get:()=>t.value[n][c],set:e=>t.value[n][c]=e});return r}(i.state,r),a,f));return Object.defineProperty(d,"$state",n),d}function y(t){const{id:n,state:r,getters:u,actions:a}=t;function f(t){(t=t||e.getCurrentInstance()&&e.inject(i))&&o(t),t=c();let f=s.get(t);f||s.set(t,f=new Map);let l=f.get(n);if(!l){l=p(n,r,t.state.value[n]),f.set(n,l);const e=d(l[0],l[1],n,u,a);return e}return d(l[0],l[1],n,u,a)}return f.$id=n,f}function h(t,e){const n="_pStores"in t?t._pStores:t._pStores={},r=e.$id;return n[r]||(n[r]=e(t.$pinia))}let b="Store";function v(t,e){return Array.isArray(e)?e.reduce((e,n)=>(e[n]=function(){return h(this,t)[n]},e),{}):Object.keys(e).reduce((n,r)=>(n[r]=function(){const n=h(this,t),o=e[r];return"function"==typeof o?o.call(this,n):n[o]},n),{})}const S=v;return t.createPinia=function(){const t=e.ref({});let r,c=[];const s=[],a={install(t){r=t,t.provide(i,a),t.config.globalProperties.$pinia=a,n&&((t=>{u=t})(t),o(a)),s.forEach(t=>c.push(t.bind(null,r)))},use(t){r?c.push(t.bind(null,r)):s.push(t)},_p:c,state:t};return a},t.createStore=t=>(console.warn('[๐Ÿ]: "createStore" has been deprecated and will be removed on the sable release, use "defineStore" instead.'),y(t)),t.defineStore=y,t.mapActions=function(t,e){return Array.isArray(e)?e.reduce((e,n)=>(e[n]=function(...e){return h(this,t)[n](...e)},e),{}):Object.keys(e).reduce((n,r)=>(n[r]=function(...n){return h(this,t)[e[r]](...n)},n),{})},t.mapGetters=S,t.mapState=v,t.mapStores=function(...t){return t.reduce((t,e)=>(t[e.$id+b]=function(){return h(this,e)},t),{})},t.mapWritableState=function(t,e){return Array.isArray(e)?e.reduce((e,n)=>(e[n]={get(){return h(this,t)[n]},set(e){return h(this,t)[n]=e}},e),{}):Object.keys(e).reduce((n,r)=>(n[r]={get(){return h(this,t)[e[r]]},set(n){return h(this,t)[e[r]]=n}},n),{})},t.setActivePinia=o,t.setMapStoreSuffix=function(t){b=t},Object.defineProperty(t,"__esModule",{value:!0}),t}({},Vue);
var Pinia=function(t,e){"use strict";const n="undefined"!=typeof window;let r;const o=t=>r=t,s=()=>r,c=new WeakMap;let i;const u=Symbol();function a(t){return t&&"object"==typeof t&&"[object Object]"===Object.prototype.toString.call(t)&&"function"!=typeof t.toJSON}function f(t,e){for(const n in e){const r=e[n],o=t[n];t[n]=a(o)&&a(r)?f(o,r):r}return t}const{assign:p}=Object;function l(t,n=(()=>({})),r){const o=s();o.state.value[t]=r||n();let c=!0,i=[];return[{$id:t,_p:o,$patch:function(e){let n,r={};c=!1,"function"==typeof e?(e(o.state.value[t]),n="๐Ÿงฉ patch"):(f(o.state.value[t],e),r=e,n="โคต๏ธ patch"),c=!0,i.forEach(e=>{e({storeName:t,type:n,payload:r},o.state.value[t])})},$subscribe:function(n){i.push(n);const r=e.watch(()=>o.state.value[t],e=>{c&&n({storeName:t,type:"๐Ÿงฉ in place",payload:{}},e)},{deep:!0,flush:"sync"}),s=()=>{const t=i.indexOf(n);t>-1&&(i.splice(t,1),r())};return e.getCurrentInstance()&&e.onUnmounted(s),s},$reset:function(){o.state.value[t]=n()}},{get:()=>o.state.value[t],set:e=>{c=!1,o.state.value[t]=e,c=!0}},Symbol()]}function d(t,n,r,c={},i={},u){const a=s(),f={};for(const t in c)f[t]=e.computed(()=>(o(a),c[t].call(d,d)));const l={};for(const t in i)l[t]=function(){return o(a),i[t].apply(d,arguments)};const d=e.reactive(p({},t,function(t,n){const r={},o=t.value[n];for(const s in o)r[s]=e.computed({get:()=>t.value[n][s],set:e=>t.value[n][s]=e});return r}(a.state,r),f,l));return Object.defineProperty(d,"$state",n),a._p.forEach(t=>{p(d,t({store:d,app:a._a,pinia:a,options:u}))}),d}function h(t){const{id:n,state:r,getters:i,actions:a}=t;function f(f){const p=e.getCurrentInstance(),h=p&&!f;(f=f||p&&e.inject(u))&&o(f),f=s();let y=c.get(f);y||c.set(f,y=new Map);let b=y.get(n);if(!b){b=l(n,r,f.state.value[n]),y.set(n,b);const o=d(b[0],b[1],n,i,a,t);return h&&e.provide(b[2],o),o}return p&&e.inject(b[2],null)||d(b[0],b[1],n,i,a,t)}return f.$id=n,f}function y(t,e){const n="_pStores"in t?t._pStores:t._pStores={},r=e.$id;return n[r]||(n[r]=e(t.$pinia))}let b="Store";function v(t,e){return Array.isArray(e)?e.reduce((e,n)=>(e[n]=function(){return y(this,t)[n]},e),{}):Object.keys(e).reduce((n,r)=>(n[r]=function(){const n=y(this,t),o=e[r];return"function"==typeof o?o.call(this,n):n[o]},n),{})}const S=v;return t.createPinia=function(){const t=e.ref({});let r,s=[];const c=[],a={install(t){a._a=r=t,t.provide(u,a),t.config.globalProperties.$pinia=a,n&&((t=>{i&&i(t)})(t),o(a)),c.forEach(t=>s.push(t))},use(t){return r?s.push(t):c.push(t),this},_p:s,_a:r,state:t};return a},t.createStore=t=>(console.warn('[๐Ÿ]: "createStore" has been deprecated and will be removed on the sable release, use "defineStore" instead.'),h(t)),t.defineStore=h,t.mapActions=function(t,e){return Array.isArray(e)?e.reduce((e,n)=>(e[n]=function(...e){return y(this,t)[n](...e)},e),{}):Object.keys(e).reduce((n,r)=>(n[r]=function(...n){return y(this,t)[e[r]](...n)},n),{})},t.mapGetters=S,t.mapState=v,t.mapStores=function(...t){return t.reduce((t,e)=>(t[e.$id+b]=function(){return y(this,e)},t),{})},t.mapWritableState=function(t,e){return Array.isArray(e)?e.reduce((e,n)=>(e[n]={get(){return y(this,t)[n]},set(e){return y(this,t)[n]=e}},e),{}):Object.keys(e).reduce((n,r)=>(n[r]={get(){return y(this,t)[e[r]]},set(n){return y(this,t)[e[r]]=n}},n),{})},t.setActivePinia=o,t.setMapStoreSuffix=function(t){b=t},Object.defineProperty(t,"__esModule",{value:!0}),t}({},Vue);
{
"name": "pinia",
"version": "2.0.0-alpha.13",
"version": "2.0.0-alpha.14",
"description": "Intuitive, type safe and flexible Store for Vue",

@@ -65,3 +65,3 @@ "main": "dist/pinia.cjs.js",

"devDependencies": {
"@microsoft/api-extractor": "7.13.2",
"@microsoft/api-extractor": "7.15.0",
"@nuxt/types": "^2.15.4",

@@ -72,7 +72,8 @@ "@rollup/plugin-alias": "^3.1.2",

"@rollup/plugin-replace": "^2.4.2",
"@types/jest": "^26.0.22",
"@types/node": "^14.14.37",
"@vue/devtools-api": "^6.0.0-beta.7",
"@sucrase/jest-plugin": "^2.1.0",
"@types/jest": "^26.0.23",
"@types/node": "^14.14.43",
"@vue/devtools-api": "^6.0.0-beta.8",
"@vue/server-renderer": "^3.0.11",
"@vue/test-utils": "^2.0.0-rc.4",
"@vue/test-utils": "^2.0.0-rc.6",
"brotli": "^1.3.2",

@@ -87,8 +88,7 @@ "codecov": "^3.8.1",

"rimraf": "^3.0.2",
"rollup": "^2.44.0",
"rollup": "^2.46.0",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-typescript2": "^0.30.0",
"ts-jest": "^26.5.4",
"typescript": "^4.2.3",
"vitepress": "^0.12.2",
"typescript": "^4.2.4",
"vitepress": "^0.13.2",
"vue": "^3.0.11",

@@ -95,0 +95,0 @@ "yorkie": "^2.0.0"

@@ -61,2 +61,6 @@ <p align="center">

</a>
<a href="https://birdeatsbug.com/?utm_source=vuerouter&utm_medium=sponsor&utm_campaign=silver" target="_blank" rel="noopener noreferrer">
<img src="https://static.birdeatsbug.com/general/bird-logotype-150x27.svg" alt="Bird Eats bug" height="42px">
</a>
</p>

@@ -63,0 +67,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with โšก๏ธ by Socket Inc