@feathersjs/vuex
Version:
FeathersJS, Vue 3, and Nuxt for the artisan developer
71 lines (70 loc) • 2.43 kB
JavaScript
/*
eslint
@typescript-eslint/explicit-function-return-type: 0,
@typescript-eslint/no-explicit-any: 0
*/
import {
// Components
FeathersVuexFind, FeathersVuexGet, FeathersVuexFormWrapper, FeathersVuexInputWrapper, FeathersVuexPagination,
// Mixins
makeFindMixin, makeGetMixin,
// Composition API Utils
useFind, useGet,
// Models
models, makeBaseModel,
// Clients
clients, addClient,
// Plugin Factories
prepareMakeServicePlugin, prepareMakeAuthPlugin,
// Utils,
initAuth, hydrateApi, } from '@feathersjs/vuex-commons';
import { FeathersVuex } from './app-plugin';
import makeServiceMutations from './service-module.mutations-vue3';
import { merge } from './utils.vue3';
const defaults = {
autoRemove: false,
addOnUpsert: false,
enableEvents: true,
idField: 'id',
tempIdField: '__id',
debug: false,
keepCopiesInStore: false,
nameStyle: 'short',
paramsForServer: ['$populateParams'],
preferUpdate: false,
replaceItems: false,
serverAlias: 'api',
handleEvents: {},
skipRequestIfExists: false,
makeServiceMutations,
merge,
whitelist: [],
};
const events = ['created', 'patched', 'updated', 'removed'];
export default function feathersVuex(feathers, options) {
if (!feathers || !feathers.service) {
throw new Error('The first argument to feathersVuex must be a feathers client.');
}
// Setup the event handlers. By default they just return the value of `options.enableEvents`
defaults.handleEvents = events.reduce((obj, eventName) => {
obj[eventName] = () => options.enableEvents || true;
return obj;
}, {});
options = Object.assign({}, defaults, options);
if (!options.serverAlias) {
throw new Error(`You must provide a 'serverAlias' in the options to feathersVuex`);
}
addClient({ client: feathers, serverAlias: options.serverAlias });
const BaseModel = makeBaseModel(options);
const makeServicePlugin = prepareMakeServicePlugin(options);
const makeAuthPlugin = prepareMakeAuthPlugin(feathers, options);
return {
makeServicePlugin,
BaseModel,
makeAuthPlugin,
FeathersVuex,
models: models,
clients,
};
}
export { initAuth, hydrateApi, FeathersVuexFind, FeathersVuexGet, FeathersVuexFormWrapper, FeathersVuexInputWrapper, FeathersVuexPagination, FeathersVuex, makeFindMixin, makeGetMixin, models, clients, useFind, useGet, };