🎁 Upgrade to Feathers-Pinia 2.0 🎁
Feathers-Pinia 2.0 is almost ready for final release. Read the new documentation.Module Overview
The main module features the following exports:
Setup & Store Creation
// Setup & Store Creation
export { setupFeathersPinia } from './setup'
export { defineStore } from './service-store'
export { useAuth } from './use-auth'
setupFeathersPiniaallows global configuration ofclientsfor all apps. It can also be used to support a common set of options for the returned, wrappeddefineStorefunction. Right now it's not that useful for SSR apps, which require an alternative configuration.- defineStore sets up a Pinia store for a Feathers service.
- useAuth is a composition utility which allows you to create a highly-flexible setup stores for auth.
Composition API Utils
New APIs in v1// Composition API Utils
export { useFind, Find } from './use-find'
export { useGet, Get } from './use-get'
export { useClones } from './use-clones'
export { useClone } from './use-clone'
- useFind is a utility that assists you in implementing the Live Query pattern. Give it a set of params and you'll get back live-updating lists of
data, as well as pagination utilities likenext, andprev. It's super versatile, handling declarative and imperative workflows that support both the client- and server-side pagination. It's similar to SWR but far more intelligent, being able to reuse data between different queries. - useGet is similar to
useFindbut for thegetmethod. - useClones removes boilerplate from the clone and commit pattern. It automatically clones all component props containing a
feathers-piniainstance. - useClone is like
useClonesbut for a single prop.
Data Modeling & Associations
// Data Modeling & Associations
export { BaseModel } from './service-store'
export { associateFind } from './associate-find'
export { associateGet } from './associate-get'
- BaseModel is the base class for working with Data Modeling.
- associateFind creates an array-based relationship with another Model class
- associateGet creates a single-object-based relationship with another Model class
SSR & Storage
// SSR & Storage
export { OFetch } from './feathers-ofetch'
export { syncWithStorage } from './storage-sync'
export { clearStorage } from './clear-storage'
OFetchis a utility that combines the universal fetch utility called ofetch with the Feathers-Client. It enables compatibility with Nuxt3 with SSR enabled.syncWithStoragesynchronizes specific parts of a store's state intolocalStorageor any Storage-compatible adapter you provide.clearStorageclears data stored with the above utilities.
Learn more about these utilities in syncWithStorage
Global Reference Objects
// Global Reference Objects
export { models } from './models'
export { clients, registerClient } from './clients'
clientsstores a reference to every Feathers client provided to eithersetupFeathersPiniaordefineStore.- After setup, you can reference a
FeathersClientat any time as shown below. This might come in handy if you need to fetch data that you don't want to be reactive. That data also won't end up in the store, so it would require refetching if not manually stored somewhere. You could use this with swrv.
tsimport { clients } from 'feathers-pinia' const { api } = clients const result = await api.service('items').find({ query: {} })- After setup, you can reference a
If you call your default client
api, you won't have to provide a customclientAliasoption to thedefineStorefunction. Learn about setting up FeathersClient instances in Setup.registerClientadds a client by name to theclientsobject.registerClient('api', feathersClientInstance).modelsstores a reference to every custom model provided todefineStore.
Feathers-Vuex Migration Utils
// Feathers-Vuex Migration Utils
export { defineAuthStore } from './define-auth-store'
export { useFindWatched } from './use-find-watched'
export { useGetWatched } from './use-get-watched'
export { usePagination } from './use-pagination'
These utilities exist to assist with migration from Feathers-Vuex. Use them for migrating existing Feathers-Vuex code, but not for new development. Use the new useFind and useGet utilities for new development.
defineAuthStoresets up a single Pinia store for an authentication service. See Auth StoresuseFindWatchedis the equivalent to Feathers-Vuex'suseFindutility. See useFindWatcheduseGetWatchedis the equivalent to Feathers-Vuex'suseGetutility. See useGetWatched.usePaginationis a composition api utility that handles typical pagination logic. See usePagination