diff --git a/packages/@jsonql/client/package.json b/packages/@jsonql/client/package.json index e5cd0edcc05ed8ec444f661122d1125f2fe5a36c..6adaa410b548d0fd147df15c609f9899cc887d04 100644 --- a/packages/@jsonql/client/package.json +++ b/packages/@jsonql/client/package.json @@ -1,6 +1,6 @@ { "name": "@jsonql/client", - "version": "0.3.1", + "version": "0.3.2", "description": "jsonql js http and socket client for browser with multiple API for different framework", "main": "dist/jsonql-client.cjs.js", "module": "index.js", @@ -48,7 +48,7 @@ "license": "MIT", "dependencies": { "flyio": "^0.6.14", - "jsonql-client": "^1.5.20" + "jsonql-client": "^1.5.21" }, "optionalDependencies": { "@jsonql/ws": "^1.0.11" diff --git a/packages/@jsonql/client/vue/vuex.js b/packages/@jsonql/client/vue/vuex.js index 171e7a664060c41b751792ddb705a7b2026f6e29..1877eeb3efd7e071154f1cb73b7f905198cc1aef 100644 --- a/packages/@jsonql/client/vue/vuex.js +++ b/packages/@jsonql/client/vue/vuex.js @@ -14,14 +14,19 @@ const ucword = str => ( * @param {object} contract the contract object * @param {object} jsonqlClient static version * @param {boolean} [prefix=true] add prefix or not + * @return {array} actions, names */ function getActions(contract, jsonqlClient, prefix = true) { + const availableTypes = ['query', 'mutation', 'auth'] let actions = {} - const target = ['query', 'mutation', 'auth'] + let names = {} for (let name in contract) { - if (target.indexOf(name) > -1) { + if (availableTypes.indexOf(name) > -1) { for (let resolverName in contract[name]) { let actionName = prefix === false ? resolverName : name + ucword(resolverName) + // keep the name for export + names[actionName] = null + // define actions actions[actionName] = (ctx, ...args) => { return Reflect.apply(jsonqlClient[name], jsonqlClient, [resolverName].concat(args)) .then(result => { @@ -36,7 +41,7 @@ function getActions(contract, jsonqlClient, prefix = true) { } } } - return actions + return [ actions, names ] } /** @@ -46,14 +51,15 @@ function getActions(contract, jsonqlClient, prefix = true) { * @return {object} the Vuex store object */ function getJsonqlVuexModule(Fly, config) { - const { prefix, contract, debugOn } = config // could be undefined but we want false boolean + const { prefix, contract } = config // could be undefined but we want false boolean const jsonqlClient = jsonqlStaticClient(Fly, config) + const [ actions, names ] = getActions(contract, jsonqlClient, prefix) // just create the structure on the fly return { namespaced: true, state: { - result: {}, - error: {} + result: names, + error: names }, mutations: { addToResult(state, { name, result }) { @@ -64,7 +70,7 @@ function getJsonqlVuexModule(Fly, config) { } }, // because jsonql are all async call, everything will be create as actions - actions: getActions(contract, jsonqlClient, prefix), + actions: actions, getters: { getJsonqlResult: (state) => (name) => { return state.result[name]