Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions docs/content/3.plugins/1.introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ import { piniaOrmPlugin } from './plugins'

const app = createApp({})
const pinia = createPinia()
const piniaOrm = createORM()
piniaOrm().use(piniaOrmPlugin)
const piniaOrm = createORM({
plugins: [
piniaOrmPlugin()
],
})
pinia.use(piniaOrm)
app.use(pinia)
setActivePinia(pinia)
Expand Down
22 changes: 14 additions & 8 deletions docs/content/3.plugins/2.axios/1.guide/1.setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ or you use `pinaOrmPluginAxios`. It depends if you want to pass options on initi
import axios from 'axios'

const pinia = createPinia()
const piniaOrm = createORM()
piniaOrm().use(createPiniaOrmAxios({
axios
}))
const piniaOrm = createORM({
plugins: [
createPiniaOrmAxios({
axios,
}),
],
})
pinia.use(piniaOrm)
```
```js{}[Vue2]
Expand All @@ -43,10 +46,13 @@ or you use `pinaOrmPluginAxios`. It depends if you want to pass options on initi

Vue.use(PiniaVuePlugin)
const pinia = createPinia()
const piniaOrm = createORM()
piniaOrm().use(createPiniaOrmAxios({
axios
}))
const piniaOrm = createORM({
plugins: [
createPiniaOrmAxios({
axios,
}),
],
})
pinia.use(piniaOrm)
```
::
Expand Down
15 changes: 9 additions & 6 deletions docs/content/3.plugins/2.axios/1.guide/2.configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ import axios from 'axios'
import { createORM } from 'pinia-orm'
import { createPiniaOrmPluginAxios } from '@pinia-orm/axios'

const piniaOrm = createORM()
piniaOrm().use(createPiniaOrmPluginAxios({
axios,
headers: { 'X-Requested-With': 'XMLHttpRequest' },
baseURL: 'https://example.com/api/'
}))
const piniaOrm = createORM({
plugins: [
createPiniaOrmAxios({
axios,
headers: { 'X-Requested-With': 'XMLHttpRequest' },
baseURL: 'https://example.com/api/',
}),
],
})
```

### Model Configuration
Expand Down
11 changes: 7 additions & 4 deletions packages/axios/test/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ beforeAll(() => {
beforeEach(() => {
const app = createApp({})
const pinia = createPinia()
const piniaOrm = createORM()
piniaOrm().use(createPiniaOrmAxios({
axios,
}))
const piniaOrm = createORM({
plugins: [
createPiniaOrmAxios({
axios,
}),
],
})
pinia.use(piniaOrm)
app.use(pinia)
setActivePinia(pinia)
Expand Down
13 changes: 5 additions & 8 deletions packages/pinia-orm/src/store/Store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface CacheConfigOptions {
export interface InstallOptions {
model?: ModelConfigOptions
cache?: CacheConfigOptions | boolean
plugins?: PiniaOrmPlugin[]
}

export interface FilledInstallOptions {
Expand All @@ -37,13 +38,9 @@ export interface CreatePiniaOrm {
export function createORM (options?: InstallOptions): PiniaPlugin {
config.model = { ...CONFIG_DEFAULTS.model, ...options?.model }
config.cache = options?.cache === false ? false : { ...CONFIG_DEFAULTS.cache, ...(options?.cache !== true && options?.cache) }
const orm = () => {
function use (plugin: PiniaOrmPlugin) {
plugins.push(plugin)
}
return {
use,
}

if (options?.plugins) {
options.plugins.forEach(plugin => plugins.push(plugin))
}
return orm
return () => {}
}
5 changes: 1 addition & 4 deletions packages/pinia-orm/tests/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ interface Entities {
export function createPiniaORM (options?: InstallOptions, plugins?: PiniaOrmPlugin[]) {
const app = createApp({})
const pinia = createPinia()
const piniaOrm = createORM(options)
if (plugins) {
plugins.forEach(plugin => piniaOrm().use(plugin))
}
const piniaOrm = createORM({ ...options, plugins })
pinia.use(piniaOrm)
app.use(pinia)
setActivePinia(pinia)
Expand Down
18 changes: 18 additions & 0 deletions playgrounds/nuxt3/orm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { createPinia } from 'pinia';
import { createORM } from 'pinia-orm';
import { createPiniaOrmAxios } from '@pinia-orm/axios';
import axios from 'axios';

export default {
setup() {
const pinia = createPinia();
const piniaOrm = createORM({
plugins: [
createPiniaOrmAxios({
axios,
})
]
});
pinia.use(piniaOrm);
},
};
4 changes: 3 additions & 1 deletion playgrounds/nuxt3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
"start": "node .output/server/index.mjs"
},
"devDependencies": {
"@pinia-orm/nuxt": "^1.7.0",
"@pinia-orm/axios": "workspace:*",
"@pinia-orm/nuxt": "workspace:*",
"@pinia/nuxt": "^0.5.1",
"nuxt": "^3.11.2",
"pinia": "^2.1.7",
"pinia-orm": "workspace:*"
},
"dependencies": {
"axios": "^1.7.2",
"nanoid": "^4.0.0",
"uuid": "^8.3.2"
}
Expand Down
26 changes: 8 additions & 18 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.