@gecka/pinia-orm-ky
v1.0.2
Published
Ky plugin for pinia-orm
Readme
@gecka/pinia-orm-ky
A ky transport for Pinia ORM repositories. Call an endpoint, get the response normalized into the store.
const users = useKyRepo(User)
await users.api().get('users')
useRepo(User).all() // the response is already in the storeInstallation
npm install @gecka/pinia-orm-ky kyky, pinia and pinia-orm are peer dependencies. ky 1 and 2, Pinia 3 and 4,
and Pinia ORM 2 are supported.
Setup
import ky from 'ky'
import { createPinia } from 'pinia'
import { createORM } from 'pinia-orm'
import { createPiniaOrmKy } from '@gecka/pinia-orm-ky'
const pinia = createPinia()
pinia.use(createORM({
plugins: [
createPiniaOrmKy({
ky,
prefix: 'https://example.com/api', // `prefixUrl` on ky 1
dataKey: 'data',
}),
],
}))Options set here apply to every request. prefix above is a ky option,
dataKey is a plugin option, and both are accepted at the same level.
Documentation
The guide and the API reference live in docs/.
| | | |---|---| | Setup | installation, plugin registration, Nuxt | | Configurations | the four levels, base url, every option | | Usage | requests, persistence, responses, errors | | Custom Actions | named requests on a model | | API Reference | Repository, Request, Response |
Development
npm install
npm test # vitest, with coverage
npm run lint
npm run build # unbuild, to dist/
npm run size # size-limit
npm run typecheckCredits
Ported from @pinia-orm/axios.
Built with 🥥 and ☕ by Gecka — Kanaky-New Caledonia 🇳🇨
