From d57d09de0e631575a3ae739e77e58929b01c6869 Mon Sep 17 00:00:00 2001 From: Yam Marcovitz Date: Sat, 25 Sep 2021 12:50:16 +0300 Subject: [PATCH 1/5] Add access to state and getters in MutationAction --- src/mutationaction.ts | 6 +++++- test/mutationaction.ts | 12 ++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/mutationaction.ts b/src/mutationaction.ts index 1863eba..f566fc2 100644 --- a/src/mutationaction.ts +++ b/src/mutationaction.ts @@ -1,4 +1,5 @@ import { Action as Act, ActionContext, Module as Mod, Mutation as Mut, Payload, Store } from 'vuex' +import { addPropertiesToObject } from './helpers' export interface MutationActionParams { mutate?: (keyof Partial)[] @@ -26,7 +27,10 @@ function mutationActionDecoratorFactory(params: MutationAction payload: Payload ) { try { - const actionPayload = await mutactFunction.call(context, payload) + const thisObj = { context } + addPropertiesToObject(thisObj, context.state) + addPropertiesToObject(thisObj, context.getters) + const actionPayload = await mutactFunction.call(thisObj, payload) context.commit(key as string, actionPayload) } catch (e) { if (params.rawError) { diff --git a/test/mutationaction.ts b/test/mutationaction.ts index b7c75c8..d0689c8 100644 --- a/test/mutationaction.ts +++ b/test/mutationaction.ts @@ -42,6 +42,11 @@ class MyModule extends VuexModule { return {count: newcount} } + + @MutationAction({ mutate: ['count'] }) + async incrementCount() { + return { count: this.count + 1 } + } } const store = new Vuex.Store({ @@ -75,4 +80,11 @@ describe('dispatching moduleaction works', () => { await store.dispatch('changeFruit', 'Guava') expect(store.state.mm.fruit).to.equal('Guava') }) + + it('can access state', async function() { + await store.dispatch('updateCount', 0) + expect(store.state.mm.count).to.equal(0) + await store.dispatch('incrementCount') + expect(store.state.mm.count).to.equal(1) + }) }) From ceb382091d2666b4e040c1a84f7b9d44789dced7 Mon Sep 17 00:00:00 2001 From: Yam Marcovitz Date: Sat, 25 Sep 2021 12:50:58 +0300 Subject: [PATCH 2/5] 1.1.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c6de52f..447bacb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vuex-module-decorators", - "version": "1.0.1", + "version": "1.1.0", "description": "Decorators to make class-like Vuex modules", "main": "dist/cjs/index.js", "types": "dist/types/index.d.ts", From 0941d20dec2699c5877fa17fec33f3ae64d7ae19 Mon Sep 17 00:00:00 2001 From: Yam Marcovitz Date: Sat, 25 Sep 2021 12:53:15 +0300 Subject: [PATCH 3/5] Update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 89745fe..128ac4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ If `(beta)` or `(alpha)` is marked in front of any release, it can be installed as `npm install vuex-module-decorators@beta` (or alpha similar). +## 1.1.0 +- add access to state and getters in MutationAction + ## 1.0.0 ### 0.17.0 From ff4865d97a5e4f872037236c0174c46774efe69a Mon Sep 17 00:00:00 2001 From: Yam Marcovitz Date: Sat, 25 Sep 2021 13:30:47 +0300 Subject: [PATCH 4/5] Fix deployment issues --- .gitignore | 5 +- dist/cjs/index.js | 551 ++++++++++++++++++++++++ dist/cjs/index.js.map | 1 + dist/esm/index.js | 541 +++++++++++++++++++++++ dist/esm/index.js.map | 1 + dist/types/action.d.ts | 10 + dist/types/config.d.ts | 4 + dist/types/helpers.d.ts | 12 + dist/types/index.d.ts | 6 + dist/types/module/index.d.ts | 4 + dist/types/module/stateFactory.d.ts | 2 + dist/types/module/staticGenerators.d.ts | 6 + dist/types/moduleoptions.d.ts | 45 ++ dist/types/mutation.d.ts | 1 + dist/types/mutationaction.d.ts | 9 + dist/types/vuexmodule.d.ts | 22 + package.json | 2 +- 17 files changed, 1217 insertions(+), 5 deletions(-) create mode 100644 dist/cjs/index.js create mode 100644 dist/cjs/index.js.map create mode 100644 dist/esm/index.js create mode 100644 dist/esm/index.js.map create mode 100644 dist/types/action.d.ts create mode 100644 dist/types/config.d.ts create mode 100644 dist/types/helpers.d.ts create mode 100644 dist/types/index.d.ts create mode 100644 dist/types/module/index.d.ts create mode 100644 dist/types/module/stateFactory.d.ts create mode 100644 dist/types/module/staticGenerators.d.ts create mode 100644 dist/types/moduleoptions.d.ts create mode 100644 dist/types/mutation.d.ts create mode 100644 dist/types/mutationaction.d.ts create mode 100644 dist/types/vuexmodule.d.ts diff --git a/.gitignore b/.gitignore index 6326ae0..898ac0f 100644 --- a/.gitignore +++ b/.gitignore @@ -9,12 +9,9 @@ coverage/ # NodeJS node_modules/ -# Build -/dist - # Vuepress /docs/.vuepress/dist/ # Cache /.cache/ -/.rpt2_cache/ \ No newline at end of file +/.rpt2_cache/ diff --git a/dist/cjs/index.js b/dist/cjs/index.js new file mode 100644 index 0000000..bdb338f --- /dev/null +++ b/dist/cjs/index.js @@ -0,0 +1,551 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { value: true }); + +/** + * Takes the properties on object from parameter source and adds them to the object + * parameter target + * @param {object} target Object to have properties copied onto from y + * @param {object} source Object with properties to be copied to x + */ +function addPropertiesToObject(target, source) { + var _loop_1 = function (k) { + Object.defineProperty(target, k, { + get: function () { return source[k]; } + }); + }; + for (var _i = 0, _a = Object.keys(source || {}); _i < _a.length; _i++) { + var k = _a[_i]; + _loop_1(k); + } +} +/** + * Returns a namespaced name of the module to be used as a store getter + * @param module + */ +function getModuleName(module) { + if (!module._vmdModuleName) { + throw new Error("ERR_GET_MODULE_NAME : Could not get module accessor.\n Make sure your module has name, we can't make accessors for unnamed modules\n i.e. @Module({ name: 'something' })"); + } + return "vuexModuleDecorators/" + module._vmdModuleName; +} + +var VuexModule = /** @class */ (function () { + function VuexModule(module) { + this.actions = module.actions; + this.mutations = module.mutations; + this.state = module.state; + this.getters = module.getters; + this.namespaced = module.namespaced; + this.modules = module.modules; + } + return VuexModule; +}()); +function getModule(moduleClass, store) { + var moduleName = getModuleName(moduleClass); + if (store && store.getters[moduleName]) { + return store.getters[moduleName]; + } + else if (moduleClass._statics) { + return moduleClass._statics; + } + var genStatic = moduleClass._genStatic; + if (!genStatic) { + throw new Error("ERR_GET_MODULE_NO_STATICS : Could not get module accessor.\n Make sure your module has name, we can't make accessors for unnamed modules\n i.e. @Module({ name: 'something' })"); + } + var storeModule = genStatic(store); + if (store) { + store.getters[moduleName] = storeModule; + } + else { + moduleClass._statics = storeModule; + } + return storeModule; +} + +var reservedKeys = ['actions', 'getters', 'mutations', 'modules', 'state', 'namespaced', 'commit']; +function stateFactory(module) { + var state = new module.prototype.constructor({}); + var s = {}; + Object.keys(state).forEach(function (key) { + if (reservedKeys.indexOf(key) !== -1) { + if (typeof state[key] !== 'undefined') { + throw new Error("ERR_RESERVED_STATE_KEY_USED: You cannot use the following\n ['actions', 'getters', 'mutations', 'modules', 'state', 'namespaced', 'commit']\n as fields in your module. These are reserved as they have special purpose in Vuex"); + } + return; + } + if (state.hasOwnProperty(key)) { + if (typeof state[key] !== 'function') { + s[key] = state[key]; + } + } + }); + return s; +} + +/*! ***************************************************************************** +Copyright (c) Microsoft Corporation. + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. +***************************************************************************** */ + +function __awaiter(thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +} + +function __generator(thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +} + +function __spreadArrays() { + for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; + for (var r = Array(s), k = 0, i = 0; i < il; i++) + for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) + r[k] = a[j]; + return r; +} + +function staticStateGenerator(module, modOpt, statics) { + var state = modOpt.stateFactory ? module.state() : module.state; + Object.keys(state).forEach(function (key) { + if (state.hasOwnProperty(key)) { + // If not undefined or function means it is a state value + if (['undefined', 'function'].indexOf(typeof state[key]) === -1) { + Object.defineProperty(statics, key, { + get: function () { + var path = modOpt.name.split('/'); + var data = statics.store.state; + for (var _i = 0, path_1 = path; _i < path_1.length; _i++) { + var segment = path_1[_i]; + data = data[segment]; + } + return data[key]; + } + }); + } + } + }); +} +function staticGetterGenerator(module, modOpt, statics) { + Object.keys(module.getters).forEach(function (key) { + if (module.namespaced) { + Object.defineProperty(statics, key, { + get: function () { + return statics.store.getters[modOpt.name + "/" + key]; + } + }); + } + else { + Object.defineProperty(statics, key, { + get: function () { + return statics.store.getters[key]; + } + }); + } + }); +} +function staticMutationGenerator(module, modOpt, statics) { + Object.keys(module.mutations).forEach(function (key) { + if (module.namespaced) { + statics[key] = function () { + var _a; + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + (_a = statics.store).commit.apply(_a, __spreadArrays([modOpt.name + "/" + key], args)); + }; + } + else { + statics[key] = function () { + var _a; + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + (_a = statics.store).commit.apply(_a, __spreadArrays([key], args)); + }; + } + }); +} +function staticActionGenerators(module, modOpt, statics) { + Object.keys(module.actions).forEach(function (key) { + if (module.namespaced) { + statics[key] = function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + return __awaiter(this, void 0, void 0, function () { + var _a; + return __generator(this, function (_b) { + return [2 /*return*/, (_a = statics.store).dispatch.apply(_a, __spreadArrays([modOpt.name + "/" + key], args))]; + }); + }); + }; + } + else { + statics[key] = function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + return __awaiter(this, void 0, void 0, function () { + var _a; + return __generator(this, function (_b) { + return [2 /*return*/, (_a = statics.store).dispatch.apply(_a, __spreadArrays([key], args))]; + }); + }); + }; + } + }); +} + +function registerDynamicModule(module, modOpt) { + if (!modOpt.name) { + throw new Error('Name of module not provided in decorator options'); + } + if (!modOpt.store) { + throw new Error('Store not provided in decorator options when using dynamic option'); + } + modOpt.store.registerModule(modOpt.name, // TODO: Handle nested modules too in future + module, { preserveState: modOpt.preserveState || false }); +} +function addGettersToModule(targetModule, srcModule) { + Object.getOwnPropertyNames(srcModule.prototype).forEach(function (funcName) { + var descriptor = Object.getOwnPropertyDescriptor(srcModule.prototype, funcName); + if (descriptor.get && targetModule.getters) { + targetModule.getters[funcName] = function (state, getters, rootState, rootGetters) { + var thisObj = { context: { state: state, getters: getters, rootState: rootState, rootGetters: rootGetters } }; + addPropertiesToObject(thisObj, state); + addPropertiesToObject(thisObj, getters); + var got = descriptor.get.call(thisObj); + return got; + }; + } + }); +} +function moduleDecoratorFactory(moduleOptions) { + return function (constructor) { + var module = constructor; + var stateFactory$1 = function () { return stateFactory(module); }; + if (!module.state) { + module.state = moduleOptions && moduleOptions.stateFactory ? stateFactory$1 : stateFactory$1(); + } + if (!module.getters) { + module.getters = {}; + } + if (!module.namespaced) { + module.namespaced = moduleOptions && moduleOptions.namespaced; + } + var parentModule = Object.getPrototypeOf(module); + while (parentModule.name !== 'VuexModule' && parentModule.name !== '') { + addGettersToModule(module, parentModule); + parentModule = Object.getPrototypeOf(parentModule); + } + addGettersToModule(module, module); + var modOpt = moduleOptions; + if (modOpt.name) { + Object.defineProperty(constructor, '_genStatic', { + value: function (store) { + var statics = { store: store || modOpt.store }; + if (!statics.store) { + throw new Error("ERR_STORE_NOT_PROVIDED: To use getModule(), either the module\n should be decorated with store in decorator, i.e. @Module({store: store}) or\n store should be passed when calling getModule(), i.e. getModule(MyModule, this.$store)"); + } + // =========== For statics ============== + // ------ state ------- + staticStateGenerator(module, modOpt, statics); + // ------- getters ------- + if (module.getters) { + staticGetterGenerator(module, modOpt, statics); + } + // -------- mutations -------- + if (module.mutations) { + staticMutationGenerator(module, modOpt, statics); + } + // -------- actions --------- + if (module.actions) { + staticActionGenerators(module, modOpt, statics); + } + return statics; + } + }); + Object.defineProperty(constructor, '_vmdModuleName', { + value: modOpt.name + }); + } + if (modOpt.dynamic) { + registerDynamicModule(module, modOpt); + } + return constructor; + }; +} +function Module(modOrOpt) { + if (typeof modOrOpt === 'function') { + /* + * @Module decorator called without options (directly on the class definition) + */ + moduleDecoratorFactory({})(modOrOpt); + } + else { + /* + * @Module({...}) decorator called with options + */ + return moduleDecoratorFactory(modOrOpt); + } +} + +var config = {}; + +function actionDecoratorFactory(params) { + var _a = params || {}, _b = _a.commit, commit = _b === void 0 ? undefined : _b, _c = _a.rawError, rawError = _c === void 0 ? !!config.rawError : _c, _d = _a.root, root = _d === void 0 ? false : _d; + return function (target, key, descriptor) { + var module = target.constructor; + if (!module.hasOwnProperty('actions')) { + module.actions = Object.assign({}, module.actions); + } + var actionFunction = descriptor.value; + var action = function (context, payload) { + return __awaiter(this, void 0, void 0, function () { + var actionPayload, moduleName, moduleAccessor, thisObj, e_1; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + _a.trys.push([0, 5, , 6]); + actionPayload = null; + if (!module._genStatic) return [3 /*break*/, 2]; + moduleName = getModuleName(module); + moduleAccessor = context.rootGetters[moduleName] + ? context.rootGetters[moduleName] + : getModule(module); + moduleAccessor.context = context; + return [4 /*yield*/, actionFunction.call(moduleAccessor, payload)]; + case 1: + actionPayload = _a.sent(); + return [3 /*break*/, 4]; + case 2: + thisObj = { context: context }; + addPropertiesToObject(thisObj, context.state); + addPropertiesToObject(thisObj, context.getters); + return [4 /*yield*/, actionFunction.call(thisObj, payload)]; + case 3: + actionPayload = _a.sent(); + _a.label = 4; + case 4: + if (commit) { + context.commit(commit, actionPayload); + } + return [2 /*return*/, actionPayload]; + case 5: + e_1 = _a.sent(); + throw rawError + ? e_1 + : new Error('ERR_ACTION_ACCESS_UNDEFINED: Are you trying to access ' + + 'this.someMutation() or this.someGetter inside an @Action? \n' + + 'That works only in dynamic modules. \n' + + 'If not dynamic use this.context.commit("mutationName", payload) ' + + 'and this.context.getters["getterName"]' + + '\n' + + new Error("Could not perform action " + key.toString()).stack + + '\n' + + e_1.stack); + case 6: return [2 /*return*/]; + } + }); + }); + }; + module.actions[key] = root ? { root: root, handler: action } : action; + }; +} +/** + * The @Action decorator turns an async function into an Vuex action + * + * @param targetOrParams the module class + * @param key name of the action + * @param descriptor the action function descriptor + * @constructor + */ +function Action(targetOrParams, key, descriptor) { + if (!key && !descriptor) { + /* + * This is the case when `targetOrParams` is params. + * i.e. when used as - + *
+            @Action({commit: 'incrCount'})
+            async getCountDelta() {
+              return 5
+            }
+         * 
+ */ + return actionDecoratorFactory(targetOrParams); + } + else { + /* + * This is the case when @Action is called on action function + * without any params + *
+         *   @Action
+         *   async doSomething() {
+         *    ...
+         *   }
+         * 
+ */ + actionDecoratorFactory()(targetOrParams, key, descriptor); + } +} + +function Mutation(target, key, descriptor) { + var module = target.constructor; + if (!module.hasOwnProperty('mutations')) { + module.mutations = Object.assign({}, module.mutations); + } + var mutationFunction = descriptor.value; + var mutation = function (state, payload) { + mutationFunction.call(state, payload); + }; + module.mutations[key] = mutation; +} + +function mutationActionDecoratorFactory(params) { + return function (target, key, descriptor) { + var module = target.constructor; + if (!module.hasOwnProperty('mutations')) { + module.mutations = Object.assign({}, module.mutations); + } + if (!module.hasOwnProperty('actions')) { + module.actions = Object.assign({}, module.actions); + } + var mutactFunction = descriptor.value; + var action = function (context, payload) { + return __awaiter(this, void 0, void 0, function () { + var thisObj, actionPayload, e_1; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + _a.trys.push([0, 2, , 3]); + thisObj = { context: context }; + addPropertiesToObject(thisObj, context.state); + addPropertiesToObject(thisObj, context.getters); + return [4 /*yield*/, mutactFunction.call(thisObj, payload)]; + case 1: + actionPayload = _a.sent(); + context.commit(key, actionPayload); + return [3 /*break*/, 3]; + case 2: + e_1 = _a.sent(); + if (params.rawError) { + throw e_1; + } + else { + console.error('Could not perform action ' + key.toString()); + console.error(e_1); + return [2 /*return*/, Promise.reject(e_1)]; + } + case 3: return [2 /*return*/]; + } + }); + }); + }; + var mutation = function (state, payload) { + if (!params.mutate) { + params.mutate = Object.keys(payload); + } + for (var _i = 0, _a = params.mutate; _i < _a.length; _i++) { + var stateItem = _a[_i]; + if (state.hasOwnProperty(stateItem) && payload.hasOwnProperty(stateItem)) { + state[stateItem] = payload[stateItem]; + } + else { + throw new Error("ERR_MUTATE_PARAMS_NOT_IN_PAYLOAD\n In @MutationAction, mutate: ['a', 'b', ...] array keys must\n match with return type = {a: {}, b: {}, ...} and must\n also be in state."); + } + } + }; + module.actions[key] = params.root ? { root: true, handler: action } : action; + module.mutations[key] = mutation; + }; +} +/** + * The @MutationAction decorator turns this into an action that further calls a mutation + * Both the action and the mutation are generated for you + * + * @param paramsOrTarget the params or the target class + * @param key the name of the function + * @param descriptor the function body + * @constructor + */ +function MutationAction(paramsOrTarget, key, descriptor) { + if (!key && !descriptor) { + /* + * This is the case when `paramsOrTarget` is params. + * i.e. when used as - + *
+            @MutationAction({mutate: ['incrCount']})
+            async getCountDelta() {
+              return {incrCount: 5}
+            }
+         * 
+ */ + return mutationActionDecoratorFactory(paramsOrTarget); + } + else { + /* + * This is the case when `paramsOrTarget` is target. + * i.e. when used as - + *
+            @MutationAction
+            async getCountDelta() {
+              return {incrCount: 5}
+            }
+         * 
+ */ + mutationActionDecoratorFactory({})(paramsOrTarget, key, descriptor); + } +} + +exports.Action = Action; +exports.Module = Module; +exports.Mutation = Mutation; +exports.MutationAction = MutationAction; +exports.VuexModule = VuexModule; +exports.config = config; +exports.getModule = getModule; +//# sourceMappingURL=index.js.map diff --git a/dist/cjs/index.js.map b/dist/cjs/index.js.map new file mode 100644 index 0000000..2413099 --- /dev/null +++ b/dist/cjs/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../../src/helpers.ts","../../src/vuexmodule.ts","../../src/module/stateFactory.ts","../../src/module/staticGenerators.ts","../../src/module/index.ts","../../src/config.ts","../../src/action.ts","../../src/mutation.ts","../../src/mutationaction.ts"],"sourcesContent":["/**\n * Takes the properties on object from parameter source and adds them to the object\n * parameter target\n * @param {object} target Object to have properties copied onto from y\n * @param {object} source Object with properties to be copied to x\n */\nexport function addPropertiesToObject(target: any, source: any) {\n for (let k of Object.keys(source || {})) {\n Object.defineProperty(target, k, {\n get: () => source[k]\n })\n }\n}\n\n/**\n * Returns a namespaced name of the module to be used as a store getter\n * @param module\n */\nexport function getModuleName(module: any): string {\n if (!module._vmdModuleName) {\n throw new Error(`ERR_GET_MODULE_NAME : Could not get module accessor.\n Make sure your module has name, we can't make accessors for unnamed modules\n i.e. @Module({ name: 'something' })`)\n }\n return `vuexModuleDecorators/${module._vmdModuleName}`\n}\n","import {\n ActionTree,\n GetterTree,\n Module as Mod,\n ModuleTree,\n MutationTree,\n Store,\n ActionContext\n} from 'vuex'\nimport { getModuleName } from './helpers'\n\nexport class VuexModule, R = any> implements Mod {\n /*\n * To use with `extends Class` syntax along with decorators\n */\n static namespaced?: boolean\n static state?: any | (() => any)\n static getters?: GetterTree\n static actions?: ActionTree\n static mutations?: MutationTree\n static modules?: ModuleTree\n\n /*\n * To use with `new VuexModule({})` syntax\n */\n\n modules?: ModuleTree\n namespaced?: boolean\n getters?: GetterTree\n state?: S | (() => S)\n mutations?: MutationTree\n actions?: ActionTree\n context!: ActionContext\n\n constructor(module: Mod) {\n this.actions = module.actions\n this.mutations = module.mutations\n this.state = module.state\n this.getters = module.getters\n this.namespaced = module.namespaced\n this.modules = module.modules\n }\n}\ntype ConstructorOf = { new (...args: any[]): C }\n\nexport function getModule(\n moduleClass: ConstructorOf,\n store?: Store\n): M {\n const moduleName = getModuleName(moduleClass)\n if (store && store.getters[moduleName]) {\n return store.getters[moduleName]\n } else if ((moduleClass as any)._statics) {\n return (moduleClass as any)._statics\n }\n\n const genStatic: (providedStore?: Store) => M = (moduleClass as any)._genStatic\n if (!genStatic) {\n throw new Error(`ERR_GET_MODULE_NO_STATICS : Could not get module accessor.\n Make sure your module has name, we can't make accessors for unnamed modules\n i.e. @Module({ name: 'something' })`)\n }\n\n const storeModule = genStatic(store)\n\n if (store) {\n store.getters[moduleName] = storeModule\n } else {\n ;(moduleClass as any)._statics = storeModule\n }\n\n return storeModule\n}\n","import { Module as Mod } from 'vuex'\n\nconst reservedKeys = ['actions', 'getters', 'mutations', 'modules', 'state', 'namespaced', 'commit']\nexport function stateFactory(module: Function & Mod) {\n const state = new module.prototype.constructor({})\n const s = {} as S\n Object.keys(state).forEach((key: string) => {\n if (reservedKeys.indexOf(key) !== -1) {\n if (typeof state[key] !== 'undefined') {\n throw new Error(\n `ERR_RESERVED_STATE_KEY_USED: You cannot use the following\n ['actions', 'getters', 'mutations', 'modules', 'state', 'namespaced', 'commit']\n as fields in your module. These are reserved as they have special purpose in Vuex`\n )\n }\n return\n }\n if (state.hasOwnProperty(key)) {\n if (typeof state[key] !== 'function') {\n ;(s as any)[key] = state[key]\n }\n }\n })\n\n return s\n}\n","import { ActionTree, GetterTree, Module as Mod, MutationTree } from 'vuex'\nimport { DynamicModuleOptions } from '../moduleoptions'\n\nexport function staticStateGenerator(\n module: Function & Mod,\n modOpt: DynamicModuleOptions,\n statics: any\n) {\n const state: S = modOpt.stateFactory ? (module as any).state() : module.state\n Object.keys(state).forEach((key) => {\n if (state.hasOwnProperty(key)) {\n // If not undefined or function means it is a state value\n if (['undefined', 'function'].indexOf(typeof (state as any)[key]) === -1) {\n Object.defineProperty(statics, key, {\n get() {\n const path = modOpt.name.split('/')\n let data = statics.store.state\n for (let segment of path) {\n data = data[segment]\n }\n return data[key]\n }\n })\n }\n }\n })\n}\n\nexport function staticGetterGenerator(\n module: Function & Mod,\n modOpt: DynamicModuleOptions,\n statics: any\n) {\n Object.keys(module.getters as GetterTree).forEach((key) => {\n if (module.namespaced) {\n Object.defineProperty(statics, key, {\n get() {\n return statics.store.getters[`${modOpt.name}/${key}`]\n }\n })\n } else {\n Object.defineProperty(statics, key, {\n get() {\n return statics.store.getters[key]\n }\n })\n }\n })\n}\n\nexport function staticMutationGenerator(\n module: Function & Mod,\n modOpt: DynamicModuleOptions,\n statics: any\n) {\n Object.keys(module.mutations as MutationTree).forEach((key) => {\n if (module.namespaced) {\n statics[key] = function (...args: any[]) {\n statics.store.commit(`${modOpt.name}/${key}`, ...args)\n }\n } else {\n statics[key] = function (...args: any[]) {\n statics.store.commit(key, ...args)\n }\n }\n })\n}\n\nexport function staticActionGenerators(\n module: Function & Mod,\n modOpt: DynamicModuleOptions,\n statics: any\n) {\n Object.keys(module.actions as ActionTree).forEach((key) => {\n if (module.namespaced) {\n statics[key] = async function (...args: any[]) {\n return statics.store.dispatch(`${modOpt.name}/${key}`, ...args)\n }\n } else {\n statics[key] = async function (...args: any[]) {\n return statics.store.dispatch(key, ...args)\n }\n }\n })\n}\n","import { GetterTree, Module as Mod, Store } from 'vuex'\nimport { DynamicModuleOptions, ModuleOptions } from '../moduleoptions'\nimport { stateFactory as sf } from './stateFactory'\nimport { addPropertiesToObject } from '../helpers'\nimport {\n staticActionGenerators,\n staticGetterGenerator,\n staticMutationGenerator,\n staticStateGenerator\n} from './staticGenerators'\n\nfunction registerDynamicModule(module: Mod, modOpt: DynamicModuleOptions) {\n if (!modOpt.name) {\n throw new Error('Name of module not provided in decorator options')\n }\n\n if (!modOpt.store) {\n throw new Error('Store not provided in decorator options when using dynamic option')\n }\n\n modOpt.store.registerModule(\n modOpt.name, // TODO: Handle nested modules too in future\n module,\n { preserveState: modOpt.preserveState || false }\n )\n}\n\nfunction addGettersToModule(\n targetModule: Function & Mod,\n srcModule: Function & Mod\n) {\n Object.getOwnPropertyNames(srcModule.prototype).forEach((funcName: string) => {\n const descriptor = Object.getOwnPropertyDescriptor(\n srcModule.prototype,\n funcName\n ) as PropertyDescriptor\n if (descriptor.get && targetModule.getters) {\n targetModule.getters[funcName] = function (\n state: S,\n getters: GetterTree,\n rootState: any,\n rootGetters: GetterTree\n ) {\n const thisObj = { context: { state, getters, rootState, rootGetters } }\n addPropertiesToObject(thisObj, state)\n addPropertiesToObject(thisObj, getters)\n const got = (descriptor.get as Function).call(thisObj)\n return got\n }\n }\n })\n}\n\nfunction moduleDecoratorFactory(moduleOptions: ModuleOptions) {\n return function (constructor: TFunction): TFunction | void {\n const module: Function & Mod = constructor\n const stateFactory = () => sf(module)\n\n if (!module.state) {\n module.state = moduleOptions && moduleOptions.stateFactory ? stateFactory : stateFactory()\n }\n if (!module.getters) {\n module.getters = {} as GetterTree\n }\n if (!module.namespaced) {\n module.namespaced = moduleOptions && moduleOptions.namespaced\n }\n let parentModule = Object.getPrototypeOf(module)\n while (parentModule.name !== 'VuexModule' && parentModule.name !== '') {\n addGettersToModule(module, parentModule)\n parentModule = Object.getPrototypeOf(parentModule)\n }\n addGettersToModule(module, module)\n const modOpt = moduleOptions as DynamicModuleOptions\n if (modOpt.name) {\n Object.defineProperty(constructor, '_genStatic', {\n value: (store?: Store) => {\n let statics = { store: store || modOpt.store }\n if (!statics.store) {\n throw new Error(`ERR_STORE_NOT_PROVIDED: To use getModule(), either the module\n should be decorated with store in decorator, i.e. @Module({store: store}) or\n store should be passed when calling getModule(), i.e. getModule(MyModule, this.$store)`)\n }\n // =========== For statics ==============\n // ------ state -------\n staticStateGenerator(module, modOpt, statics)\n\n // ------- getters -------\n if (module.getters) {\n staticGetterGenerator(module, modOpt, statics)\n }\n\n // -------- mutations --------\n if (module.mutations) {\n staticMutationGenerator(module, modOpt, statics)\n }\n // -------- actions ---------\n if (module.actions) {\n staticActionGenerators(module, modOpt, statics)\n }\n return statics\n }\n })\n\n Object.defineProperty(constructor, '_vmdModuleName', {\n value: modOpt.name\n })\n }\n\n if (modOpt.dynamic) {\n registerDynamicModule(module, modOpt)\n }\n return constructor\n }\n}\n\nexport function Module(module: Function & Mod): void\nexport function Module(options: ModuleOptions): ClassDecorator\n\nexport function Module(modOrOpt: ModuleOptions | (Function & Mod)) {\n if (typeof (modOrOpt as any) === 'function') {\n /*\n * @Module decorator called without options (directly on the class definition)\n */\n moduleDecoratorFactory({})(modOrOpt as Function & Mod)\n } else {\n /*\n * @Module({...}) decorator called with options\n */\n return moduleDecoratorFactory(modOrOpt)\n }\n}\n","export const config: IConfig = {}\n\nexport interface IConfig {\n rawError?: boolean\n}\n","import { Action as Act, ActionContext, Module as Mod, Payload } from 'vuex'\nimport { getModule, VuexModule } from './vuexmodule'\nimport { addPropertiesToObject, getModuleName } from './helpers'\nimport { config } from './config'\n\n/**\n * Parameters that can be passed to the @Action decorator\n */\nexport interface ActionDecoratorParams {\n commit?: string\n rawError?: boolean\n root?: boolean\n}\nfunction actionDecoratorFactory(params?: ActionDecoratorParams): MethodDecorator {\n const { commit = undefined, rawError = !!config.rawError, root = false } = params || {}\n return function (target: Object, key: string | symbol, descriptor: TypedPropertyDescriptor) {\n const module = target.constructor as Mod\n if (!module.hasOwnProperty('actions')) {\n module.actions = Object.assign({}, module.actions)\n }\n const actionFunction: Function = descriptor.value\n const action: Act = async function (\n context: ActionContext,\n payload: Payload\n ) {\n try {\n let actionPayload = null\n\n if ((module as any)._genStatic) {\n const moduleName = getModuleName(module)\n const moduleAccessor = context.rootGetters[moduleName]\n ? context.rootGetters[moduleName]\n : getModule(module as typeof VuexModule)\n moduleAccessor.context = context\n actionPayload = await actionFunction.call(moduleAccessor, payload)\n } else {\n const thisObj = { context }\n addPropertiesToObject(thisObj, context.state)\n addPropertiesToObject(thisObj, context.getters)\n actionPayload = await actionFunction.call(thisObj, payload)\n }\n if (commit) {\n context.commit(commit, actionPayload)\n }\n return actionPayload\n } catch (e) {\n throw rawError\n ? e\n : new Error(\n 'ERR_ACTION_ACCESS_UNDEFINED: Are you trying to access ' +\n 'this.someMutation() or this.someGetter inside an @Action? \\n' +\n 'That works only in dynamic modules. \\n' +\n 'If not dynamic use this.context.commit(\"mutationName\", payload) ' +\n 'and this.context.getters[\"getterName\"]' +\n '\\n' +\n new Error(`Could not perform action ${key.toString()}`).stack +\n '\\n' +\n e.stack\n )\n }\n }\n module.actions![key as string] = root ? { root, handler: action } : action\n }\n}\n\nexport function Action(\n target: T,\n key: string | symbol,\n descriptor: TypedPropertyDescriptor<(...args: any[]) => R>\n): void\nexport function Action(params: ActionDecoratorParams): MethodDecorator\n\n/**\n * The @Action decorator turns an async function into an Vuex action\n *\n * @param targetOrParams the module class\n * @param key name of the action\n * @param descriptor the action function descriptor\n * @constructor\n */\nexport function Action(\n targetOrParams: T | ActionDecoratorParams,\n key?: string | symbol,\n descriptor?: TypedPropertyDescriptor<(...args: any[]) => R>\n) {\n if (!key && !descriptor) {\n /*\n * This is the case when `targetOrParams` is params.\n * i.e. when used as -\n *
\n        @Action({commit: 'incrCount'})\n        async getCountDelta() {\n          return 5\n        }\n     * 
\n */\n return actionDecoratorFactory(targetOrParams as ActionDecoratorParams)\n } else {\n /*\n * This is the case when @Action is called on action function\n * without any params\n *
\n     *   @Action\n     *   async doSomething() {\n     *    ...\n     *   }\n     * 
\n */\n actionDecoratorFactory()(targetOrParams, key!, descriptor!)\n }\n}\n","import { Module as Mod, Mutation as Mut, Payload } from 'vuex'\n\nexport function Mutation(\n target: T,\n key: string | symbol,\n descriptor: TypedPropertyDescriptor<(...args: any[]) => R>\n) {\n const module = target.constructor as Mod\n if (!module.hasOwnProperty('mutations')) {\n module.mutations = Object.assign({}, module.mutations)\n }\n const mutationFunction: Function = descriptor.value!\n const mutation: Mut = function (state: typeof target, payload: Payload) {\n mutationFunction.call(state, payload)\n }\n module.mutations![key as string] = mutation\n}\n","import { Action as Act, ActionContext, Module as Mod, Mutation as Mut, Payload, Store } from 'vuex'\nimport { addPropertiesToObject } from './helpers'\n\nexport interface MutationActionParams {\n mutate?: (keyof Partial)[]\n rawError?: boolean\n root?: boolean\n}\n\nfunction mutationActionDecoratorFactory(params: MutationActionParams) {\n return function (\n target: T,\n key: string | symbol,\n descriptor: TypedPropertyDescriptor<(...args: any[]) => Promise>>\n ) {\n const module = target.constructor as Mod\n if (!module.hasOwnProperty('mutations')) {\n module.mutations = Object.assign({}, module.mutations)\n }\n if (!module.hasOwnProperty('actions')) {\n module.actions = Object.assign({}, module.actions)\n }\n const mutactFunction = descriptor.value as (payload: any) => Promise\n\n const action: Act = async function (\n context: ActionContext,\n payload: Payload\n ) {\n try {\n const thisObj = { context }\n addPropertiesToObject(thisObj, context.state)\n addPropertiesToObject(thisObj, context.getters)\n const actionPayload = await mutactFunction.call(thisObj, payload)\n context.commit(key as string, actionPayload)\n } catch (e) {\n if (params.rawError) {\n throw e\n } else {\n console.error('Could not perform action ' + key.toString())\n console.error(e)\n return Promise.reject(e)\n }\n }\n }\n\n const mutation: Mut = function (\n state: typeof target | Store,\n payload: Payload & { [k in keyof T]: any }\n ) {\n if (!params.mutate) {\n params.mutate = Object.keys(payload) as (keyof T)[]\n }\n for (let stateItem of params.mutate) {\n if (state.hasOwnProperty(stateItem) && payload.hasOwnProperty(stateItem)) {\n ;(state as T)[stateItem] = payload[stateItem]\n } else {\n throw new Error(`ERR_MUTATE_PARAMS_NOT_IN_PAYLOAD\n In @MutationAction, mutate: ['a', 'b', ...] array keys must\n match with return type = {a: {}, b: {}, ...} and must\n also be in state.`)\n }\n }\n }\n module.actions![key as string] = params.root ? { root: true, handler: action } : action\n module.mutations![key as string] = mutation\n }\n}\n\nexport function MutationAction(\n target: { [k in keyof T]: T[k] | null },\n key: string | symbol,\n descriptor: TypedPropertyDescriptor<(...args: any[]) => Promise>\n): void\n\nexport function MutationAction(\n params: MutationActionParams\n): (\n target: T,\n key: string | symbol,\n descriptor: TypedPropertyDescriptor<(...args: any[]) => Promise>\n) => void\n\n/**\n * The @MutationAction decorator turns this into an action that further calls a mutation\n * Both the action and the mutation are generated for you\n *\n * @param paramsOrTarget the params or the target class\n * @param key the name of the function\n * @param descriptor the function body\n * @constructor\n */\nexport function MutationAction(\n paramsOrTarget: MutationActionParams | M,\n key?: string | symbol,\n descriptor?: TypedPropertyDescriptor<(...args: any[]) => Promise>>\n):\n | ((\n target: T,\n key: string | symbol,\n descriptor: TypedPropertyDescriptor<(...args: any[]) => Promise>>\n ) => void)\n | void {\n if (!key && !descriptor) {\n /*\n * This is the case when `paramsOrTarget` is params.\n * i.e. when used as -\n *
\n        @MutationAction({mutate: ['incrCount']})\n        async getCountDelta() {\n          return {incrCount: 5}\n        }\n     * 
\n */\n return mutationActionDecoratorFactory(paramsOrTarget as MutationActionParams)\n } else {\n /*\n * This is the case when `paramsOrTarget` is target.\n * i.e. when used as -\n *
\n        @MutationAction\n        async getCountDelta() {\n          return {incrCount: 5}\n        }\n     * 
\n */\n mutationActionDecoratorFactory({} as MutationActionParams)(\n paramsOrTarget as K,\n key!,\n descriptor!\n )\n }\n}\n"],"names":["stateFactory","sf"],"mappings":";;;;AAAA;;;;;;SAMgB,qBAAqB,CAAC,MAAW,EAAE,MAAW;4BACnD,CAAC;QACR,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,CAAC,EAAE;YAC/B,GAAG,EAAE,cAAM,OAAA,MAAM,CAAC,CAAC,CAAC,GAAA;SACrB,CAAC,CAAA;;IAHJ,KAAc,UAAyB,EAAzB,KAAA,MAAM,CAAC,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC,EAAzB,cAAyB,EAAzB,IAAyB;QAAlC,IAAI,CAAC,SAAA;gBAAD,CAAC;KAIT;AACH,CAAC;AAED;;;;SAIgB,aAAa,CAAC,MAAW;IACvC,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE;QAC1B,MAAM,IAAI,KAAK,CAAC,oLAEsB,CAAC,CAAA;KACxC;IACD,OAAO,0BAAwB,MAAM,CAAC,cAAgB,CAAA;AACxD;;;ICSE,oBAAY,MAAmB;QAC7B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAA;QAC7B,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAA;QACjC,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAA;QACzB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,C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A;KAC5C,CAAA;AACH,CAAC;AAgBD;;;;;;;;;SASgB,cAAc,CAC5B,cAA2C,EAC3C,GAAqB,EACrB,UAA6E;IAQ7E,IAAI,CAAC,GAAG,IAAI,CAAC,UAAU,EAAE;;;;;;;;;;;QAWvB,OAAO,8BAA8B,CAAC,cAAyC,CAAC,CAAA;KACjF;SAAM;;;;;;;;;;;QAWL,8BAA8B,CAAC,EAA6B,CAAC,CAC3D,cAAmB,EACnB,GAAI,EACJ,UAAW,CACZ,CAAA;KACF;AACH;;;;;;;;;;"} \ No newline at end of file diff --git a/dist/esm/index.js b/dist/esm/index.js new file mode 100644 index 0000000..24c8325 --- /dev/null +++ b/dist/esm/index.js @@ -0,0 +1,541 @@ +/** + * Takes the properties on object from parameter source and adds them to the object + * parameter target + * @param {object} target Object to have properties copied onto from y + * @param {object} source Object with properties to be copied to x + */ +function addPropertiesToObject(target, source) { + var _loop_1 = function (k) { + Object.defineProperty(target, k, { + get: function () { return source[k]; } + }); + }; + for (var _i = 0, _a = Object.keys(source || {}); _i < _a.length; _i++) { + var k = _a[_i]; + _loop_1(k); + } +} +/** + * Returns a namespaced name of the module to be used as a store getter + * @param module + */ +function getModuleName(module) { + if (!module._vmdModuleName) { + throw new Error("ERR_GET_MODULE_NAME : Could not get module accessor.\n Make sure your module has name, we can't make accessors for unnamed modules\n i.e. @Module({ name: 'something' })"); + } + return "vuexModuleDecorators/" + module._vmdModuleName; +} + +var VuexModule = /** @class */ (function () { + function VuexModule(module) { + this.actions = module.actions; + this.mutations = module.mutations; + this.state = module.state; + this.getters = module.getters; + this.namespaced = module.namespaced; + this.modules = module.modules; + } + return VuexModule; +}()); +function getModule(moduleClass, store) { + var moduleName = getModuleName(moduleClass); + if (store && store.getters[moduleName]) { + return store.getters[moduleName]; + } + else if (moduleClass._statics) { + return moduleClass._statics; + } + var genStatic = moduleClass._genStatic; + if (!genStatic) { + throw new Error("ERR_GET_MODULE_NO_STATICS : Could not get module accessor.\n Make sure your module has name, we can't make accessors for unnamed modules\n i.e. @Module({ name: 'something' })"); + } + var storeModule = genStatic(store); + if (store) { + store.getters[moduleName] = storeModule; + } + else { + moduleClass._statics = storeModule; + } + return storeModule; +} + +var reservedKeys = ['actions', 'getters', 'mutations', 'modules', 'state', 'namespaced', 'commit']; +function stateFactory(module) { + var state = new module.prototype.constructor({}); + var s = {}; + Object.keys(state).forEach(function (key) { + if (reservedKeys.indexOf(key) !== -1) { + if (typeof state[key] !== 'undefined') { + throw new Error("ERR_RESERVED_STATE_KEY_USED: You cannot use the following\n ['actions', 'getters', 'mutations', 'modules', 'state', 'namespaced', 'commit']\n as fields in your module. These are reserved as they have special purpose in Vuex"); + } + return; + } + if (state.hasOwnProperty(key)) { + if (typeof state[key] !== 'function') { + s[key] = state[key]; + } + } + }); + return s; +} + +/*! ***************************************************************************** +Copyright (c) Microsoft Corporation. + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. +***************************************************************************** */ + +function __awaiter(thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +} + +function __generator(thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +} + +function __spreadArrays() { + for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; + for (var r = Array(s), k = 0, i = 0; i < il; i++) + for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) + r[k] = a[j]; + return r; +} + +function staticStateGenerator(module, modOpt, statics) { + var state = modOpt.stateFactory ? module.state() : module.state; + Object.keys(state).forEach(function (key) { + if (state.hasOwnProperty(key)) { + // If not undefined or function means it is a state value + if (['undefined', 'function'].indexOf(typeof state[key]) === -1) { + Object.defineProperty(statics, key, { + get: function () { + var path = modOpt.name.split('/'); + var data = statics.store.state; + for (var _i = 0, path_1 = path; _i < path_1.length; _i++) { + var segment = path_1[_i]; + data = data[segment]; + } + return data[key]; + } + }); + } + } + }); +} +function staticGetterGenerator(module, modOpt, statics) { + Object.keys(module.getters).forEach(function (key) { + if (module.namespaced) { + Object.defineProperty(statics, key, { + get: function () { + return statics.store.getters[modOpt.name + "/" + key]; + } + }); + } + else { + Object.defineProperty(statics, key, { + get: function () { + return statics.store.getters[key]; + } + }); + } + }); +} +function staticMutationGenerator(module, modOpt, statics) { + Object.keys(module.mutations).forEach(function (key) { + if (module.namespaced) { + statics[key] = function () { + var _a; + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + (_a = statics.store).commit.apply(_a, __spreadArrays([modOpt.name + "/" + key], args)); + }; + } + else { + statics[key] = function () { + var _a; + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + (_a = statics.store).commit.apply(_a, __spreadArrays([key], args)); + }; + } + }); +} +function staticActionGenerators(module, modOpt, statics) { + Object.keys(module.actions).forEach(function (key) { + if (module.namespaced) { + statics[key] = function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + return __awaiter(this, void 0, void 0, function () { + var _a; + return __generator(this, function (_b) { + return [2 /*return*/, (_a = statics.store).dispatch.apply(_a, __spreadArrays([modOpt.name + "/" + key], args))]; + }); + }); + }; + } + else { + statics[key] = function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + return __awaiter(this, void 0, void 0, function () { + var _a; + return __generator(this, function (_b) { + return [2 /*return*/, (_a = statics.store).dispatch.apply(_a, __spreadArrays([key], args))]; + }); + }); + }; + } + }); +} + +function registerDynamicModule(module, modOpt) { + if (!modOpt.name) { + throw new Error('Name of module not provided in decorator options'); + } + if (!modOpt.store) { + throw new Error('Store not provided in decorator options when using dynamic option'); + } + modOpt.store.registerModule(modOpt.name, // TODO: Handle nested modules too in future + module, { preserveState: modOpt.preserveState || false }); +} +function addGettersToModule(targetModule, srcModule) { + Object.getOwnPropertyNames(srcModule.prototype).forEach(function (funcName) { + var descriptor = Object.getOwnPropertyDescriptor(srcModule.prototype, funcName); + if (descriptor.get && targetModule.getters) { + targetModule.getters[funcName] = function (state, getters, rootState, rootGetters) { + var thisObj = { context: { state: state, getters: getters, rootState: rootState, rootGetters: rootGetters } }; + addPropertiesToObject(thisObj, state); + addPropertiesToObject(thisObj, getters); + var got = descriptor.get.call(thisObj); + return got; + }; + } + }); +} +function moduleDecoratorFactory(moduleOptions) { + return function (constructor) { + var module = constructor; + var stateFactory$1 = function () { return stateFactory(module); }; + if (!module.state) { + module.state = moduleOptions && moduleOptions.stateFactory ? stateFactory$1 : stateFactory$1(); + } + if (!module.getters) { + module.getters = {}; + } + if (!module.namespaced) { + module.namespaced = moduleOptions && moduleOptions.namespaced; + } + var parentModule = Object.getPrototypeOf(module); + while (parentModule.name !== 'VuexModule' && parentModule.name !== '') { + addGettersToModule(module, parentModule); + parentModule = Object.getPrototypeOf(parentModule); + } + addGettersToModule(module, module); + var modOpt = moduleOptions; + if (modOpt.name) { + Object.defineProperty(constructor, '_genStatic', { + value: function (store) { + var statics = { store: store || modOpt.store }; + if (!statics.store) { + throw new Error("ERR_STORE_NOT_PROVIDED: To use getModule(), either the module\n should be decorated with store in decorator, i.e. @Module({store: store}) or\n store should be passed when calling getModule(), i.e. getModule(MyModule, this.$store)"); + } + // =========== For statics ============== + // ------ state ------- + staticStateGenerator(module, modOpt, statics); + // ------- getters ------- + if (module.getters) { + staticGetterGenerator(module, modOpt, statics); + } + // -------- mutations -------- + if (module.mutations) { + staticMutationGenerator(module, modOpt, statics); + } + // -------- actions --------- + if (module.actions) { + staticActionGenerators(module, modOpt, statics); + } + return statics; + } + }); + Object.defineProperty(constructor, '_vmdModuleName', { + value: modOpt.name + }); + } + if (modOpt.dynamic) { + registerDynamicModule(module, modOpt); + } + return constructor; + }; +} +function Module(modOrOpt) { + if (typeof modOrOpt === 'function') { + /* + * @Module decorator called without options (directly on the class definition) + */ + moduleDecoratorFactory({})(modOrOpt); + } + else { + /* + * @Module({...}) decorator called with options + */ + return moduleDecoratorFactory(modOrOpt); + } +} + +var config = {}; + +function actionDecoratorFactory(params) { + var _a = params || {}, _b = _a.commit, commit = _b === void 0 ? undefined : _b, _c = _a.rawError, rawError = _c === void 0 ? !!config.rawError : _c, _d = _a.root, root = _d === void 0 ? false : _d; + return function (target, key, descriptor) { + var module = target.constructor; + if (!module.hasOwnProperty('actions')) { + module.actions = Object.assign({}, module.actions); + } + var actionFunction = descriptor.value; + var action = function (context, payload) { + return __awaiter(this, void 0, void 0, function () { + var actionPayload, moduleName, moduleAccessor, thisObj, e_1; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + _a.trys.push([0, 5, , 6]); + actionPayload = null; + if (!module._genStatic) return [3 /*break*/, 2]; + moduleName = getModuleName(module); + moduleAccessor = context.rootGetters[moduleName] + ? context.rootGetters[moduleName] + : getModule(module); + moduleAccessor.context = context; + return [4 /*yield*/, actionFunction.call(moduleAccessor, payload)]; + case 1: + actionPayload = _a.sent(); + return [3 /*break*/, 4]; + case 2: + thisObj = { context: context }; + addPropertiesToObject(thisObj, context.state); + addPropertiesToObject(thisObj, context.getters); + return [4 /*yield*/, actionFunction.call(thisObj, payload)]; + case 3: + actionPayload = _a.sent(); + _a.label = 4; + case 4: + if (commit) { + context.commit(commit, actionPayload); + } + return [2 /*return*/, actionPayload]; + case 5: + e_1 = _a.sent(); + throw rawError + ? e_1 + : new Error('ERR_ACTION_ACCESS_UNDEFINED: Are you trying to access ' + + 'this.someMutation() or this.someGetter inside an @Action? \n' + + 'That works only in dynamic modules. \n' + + 'If not dynamic use this.context.commit("mutationName", payload) ' + + 'and this.context.getters["getterName"]' + + '\n' + + new Error("Could not perform action " + key.toString()).stack + + '\n' + + e_1.stack); + case 6: return [2 /*return*/]; + } + }); + }); + }; + module.actions[key] = root ? { root: root, handler: action } : action; + }; +} +/** + * The @Action decorator turns an async function into an Vuex action + * + * @param targetOrParams the module class + * @param key name of the action + * @param descriptor the action function descriptor + * @constructor + */ +function Action(targetOrParams, key, descriptor) { + if (!key && !descriptor) { + /* + * This is the case when `targetOrParams` is params. + * i.e. when used as - + *
+            @Action({commit: 'incrCount'})
+            async getCountDelta() {
+              return 5
+            }
+         * 
+ */ + return actionDecoratorFactory(targetOrParams); + } + else { + /* + * This is the case when @Action is called on action function + * without any params + *
+         *   @Action
+         *   async doSomething() {
+         *    ...
+         *   }
+         * 
+ */ + actionDecoratorFactory()(targetOrParams, key, descriptor); + } +} + +function Mutation(target, key, descriptor) { + var module = target.constructor; + if (!module.hasOwnProperty('mutations')) { + module.mutations = Object.assign({}, module.mutations); + } + var mutationFunction = descriptor.value; + var mutation = function (state, payload) { + mutationFunction.call(state, payload); + }; + module.mutations[key] = mutation; +} + +function mutationActionDecoratorFactory(params) { + return function (target, key, descriptor) { + var module = target.constructor; + if (!module.hasOwnProperty('mutations')) { + module.mutations = Object.assign({}, module.mutations); + } + if (!module.hasOwnProperty('actions')) { + module.actions = Object.assign({}, module.actions); + } + var mutactFunction = descriptor.value; + var action = function (context, payload) { + return __awaiter(this, void 0, void 0, function () { + var thisObj, actionPayload, e_1; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + _a.trys.push([0, 2, , 3]); + thisObj = { context: context }; + addPropertiesToObject(thisObj, context.state); + addPropertiesToObject(thisObj, context.getters); + return [4 /*yield*/, mutactFunction.call(thisObj, payload)]; + case 1: + actionPayload = _a.sent(); + context.commit(key, actionPayload); + return [3 /*break*/, 3]; + case 2: + e_1 = _a.sent(); + if (params.rawError) { + throw e_1; + } + else { + console.error('Could not perform action ' + key.toString()); + console.error(e_1); + return [2 /*return*/, Promise.reject(e_1)]; + } + case 3: return [2 /*return*/]; + } + }); + }); + }; + var mutation = function (state, payload) { + if (!params.mutate) { + params.mutate = Object.keys(payload); + } + for (var _i = 0, _a = params.mutate; _i < _a.length; _i++) { + var stateItem = _a[_i]; + if (state.hasOwnProperty(stateItem) && payload.hasOwnProperty(stateItem)) { + state[stateItem] = payload[stateItem]; + } + else { + throw new Error("ERR_MUTATE_PARAMS_NOT_IN_PAYLOAD\n In @MutationAction, mutate: ['a', 'b', ...] array keys must\n match with return type = {a: {}, b: {}, ...} and must\n also be in state."); + } + } + }; + module.actions[key] = params.root ? { root: true, handler: action } : action; + module.mutations[key] = mutation; + }; +} +/** + * The @MutationAction decorator turns this into an action that further calls a mutation + * Both the action and the mutation are generated for you + * + * @param paramsOrTarget the params or the target class + * @param key the name of the function + * @param descriptor the function body + * @constructor + */ +function MutationAction(paramsOrTarget, key, descriptor) { + if (!key && !descriptor) { + /* + * This is the case when `paramsOrTarget` is params. + * i.e. when used as - + *
+            @MutationAction({mutate: ['incrCount']})
+            async getCountDelta() {
+              return {incrCount: 5}
+            }
+         * 
+ */ + return mutationActionDecoratorFactory(paramsOrTarget); + } + else { + /* + * This is the case when `paramsOrTarget` is target. + * i.e. when used as - + *
+            @MutationAction
+            async getCountDelta() {
+              return {incrCount: 5}
+            }
+         * 
+ */ + mutationActionDecoratorFactory({})(paramsOrTarget, key, descriptor); + } +} + +export { Action, Module, Mutation, MutationAction, VuexModule, config, getModule }; +//# sourceMappingURL=index.js.map diff --git a/dist/esm/index.js.map b/dist/esm/index.js.map new file mode 100644 index 0000000..df97bac --- /dev/null +++ b/dist/esm/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../../src/helpers.ts","../../src/vuexmodule.ts","../../src/module/stateFactory.ts","../../src/module/staticGenerators.ts","../../src/module/index.ts","../../src/config.ts","../../src/action.ts","../../src/mutation.ts","../../src/mutationaction.ts"],"sourcesContent":["/**\n * Takes the properties on object from parameter source and adds them to the object\n * parameter target\n * @param {object} target Object to have properties copied onto from y\n * @param {object} source Object with properties to be copied to x\n */\nexport function addPropertiesToObject(target: any, source: any) {\n for (let k of Object.keys(source || {})) {\n Object.defineProperty(target, k, {\n get: () => source[k]\n })\n }\n}\n\n/**\n * Returns a namespaced name of the module to be used as a store getter\n * @param module\n */\nexport function getModuleName(module: any): string {\n if (!module._vmdModuleName) {\n throw new Error(`ERR_GET_MODULE_NAME : Could not get module accessor.\n Make sure your module has name, we can't make accessors for unnamed modules\n i.e. @Module({ name: 'something' })`)\n }\n return `vuexModuleDecorators/${module._vmdModuleName}`\n}\n","import {\n ActionTree,\n GetterTree,\n Module as Mod,\n ModuleTree,\n MutationTree,\n Store,\n ActionContext\n} from 'vuex'\nimport { getModuleName } from './helpers'\n\nexport class VuexModule, R = any> implements Mod {\n /*\n * To use with `extends Class` syntax along with decorators\n */\n static namespaced?: boolean\n static state?: any | (() => any)\n static getters?: GetterTree\n static actions?: ActionTree\n static mutations?: MutationTree\n static modules?: ModuleTree\n\n /*\n * To use with `new VuexModule({})` syntax\n */\n\n modules?: ModuleTree\n namespaced?: boolean\n getters?: GetterTree\n state?: S | (() => S)\n mutations?: MutationTree\n actions?: ActionTree\n context!: ActionContext\n\n constructor(module: Mod) {\n this.actions = module.actions\n this.mutations = module.mutations\n this.state = module.state\n this.getters = module.getters\n this.namespaced = module.namespaced\n this.modules = module.modules\n }\n}\ntype ConstructorOf = { new (...args: any[]): C }\n\nexport function getModule(\n moduleClass: ConstructorOf,\n store?: Store\n): M {\n const moduleName = getModuleName(moduleClass)\n if (store && store.getters[moduleName]) {\n return store.getters[moduleName]\n } else if ((moduleClass as any)._statics) {\n return (moduleClass as any)._statics\n }\n\n const genStatic: (providedStore?: Store) => M = (moduleClass as any)._genStatic\n if (!genStatic) {\n throw new Error(`ERR_GET_MODULE_NO_STATICS : Could not get module accessor.\n Make sure your module has name, we can't make accessors for unnamed modules\n i.e. @Module({ name: 'something' })`)\n }\n\n const storeModule = genStatic(store)\n\n if (store) {\n store.getters[moduleName] = storeModule\n } else {\n ;(moduleClass as any)._statics = storeModule\n }\n\n return storeModule\n}\n","import { Module as Mod } from 'vuex'\n\nconst reservedKeys = ['actions', 'getters', 'mutations', 'modules', 'state', 'namespaced', 'commit']\nexport function stateFactory(module: Function & Mod) {\n const state = new module.prototype.constructor({})\n const s = {} as S\n Object.keys(state).forEach((key: string) => {\n if (reservedKeys.indexOf(key) !== -1) {\n if (typeof state[key] !== 'undefined') {\n throw new Error(\n `ERR_RESERVED_STATE_KEY_USED: You cannot use the following\n ['actions', 'getters', 'mutations', 'modules', 'state', 'namespaced', 'commit']\n as fields in your module. These are reserved as they have special purpose in Vuex`\n )\n }\n return\n }\n if (state.hasOwnProperty(key)) {\n if (typeof state[key] !== 'function') {\n ;(s as any)[key] = state[key]\n }\n }\n })\n\n return s\n}\n","import { ActionTree, GetterTree, Module as Mod, MutationTree } from 'vuex'\nimport { DynamicModuleOptions } from '../moduleoptions'\n\nexport function staticStateGenerator(\n module: Function & Mod,\n modOpt: DynamicModuleOptions,\n statics: any\n) {\n const state: S = modOpt.stateFactory ? (module as any).state() : module.state\n Object.keys(state).forEach((key) => {\n if (state.hasOwnProperty(key)) {\n // If not undefined or function means it is a state value\n if (['undefined', 'function'].indexOf(typeof (state as any)[key]) === -1) {\n Object.defineProperty(statics, key, {\n get() {\n const path = modOpt.name.split('/')\n let data = statics.store.state\n for (let segment of path) {\n data = data[segment]\n }\n return data[key]\n }\n })\n }\n }\n })\n}\n\nexport function staticGetterGenerator(\n module: Function & Mod,\n modOpt: DynamicModuleOptions,\n statics: any\n) {\n Object.keys(module.getters as GetterTree).forEach((key) => {\n if (module.namespaced) {\n Object.defineProperty(statics, key, {\n get() {\n return statics.store.getters[`${modOpt.name}/${key}`]\n }\n })\n } else {\n Object.defineProperty(statics, key, {\n get() {\n return statics.store.getters[key]\n }\n })\n }\n })\n}\n\nexport function staticMutationGenerator(\n module: Function & Mod,\n modOpt: DynamicModuleOptions,\n statics: any\n) {\n Object.keys(module.mutations as MutationTree).forEach((key) => {\n if (module.namespaced) {\n statics[key] = function (...args: any[]) {\n statics.store.commit(`${modOpt.name}/${key}`, ...args)\n }\n } else {\n statics[key] = function (...args: any[]) {\n statics.store.commit(key, ...args)\n }\n }\n })\n}\n\nexport function staticActionGenerators(\n module: Function & Mod,\n modOpt: DynamicModuleOptions,\n statics: any\n) {\n Object.keys(module.actions as ActionTree).forEach((key) => {\n if (module.namespaced) {\n statics[key] = async function (...args: any[]) {\n return statics.store.dispatch(`${modOpt.name}/${key}`, ...args)\n }\n } else {\n statics[key] = async function (...args: any[]) {\n return statics.store.dispatch(key, ...args)\n }\n }\n })\n}\n","import { GetterTree, Module as Mod, Store } from 'vuex'\nimport { DynamicModuleOptions, ModuleOptions } from '../moduleoptions'\nimport { stateFactory as sf } from './stateFactory'\nimport { addPropertiesToObject } from '../helpers'\nimport {\n staticActionGenerators,\n staticGetterGenerator,\n staticMutationGenerator,\n staticStateGenerator\n} from './staticGenerators'\n\nfunction registerDynamicModule(module: Mod, modOpt: DynamicModuleOptions) {\n if (!modOpt.name) {\n throw new Error('Name of module not provided in decorator options')\n }\n\n if (!modOpt.store) {\n throw new Error('Store not provided in decorator options when using dynamic option')\n }\n\n modOpt.store.registerModule(\n modOpt.name, // TODO: Handle nested modules too in future\n module,\n { preserveState: modOpt.preserveState || false }\n )\n}\n\nfunction addGettersToModule(\n targetModule: Function & Mod,\n srcModule: Function & Mod\n) {\n Object.getOwnPropertyNames(srcModule.prototype).forEach((funcName: string) => {\n const descriptor = Object.getOwnPropertyDescriptor(\n srcModule.prototype,\n funcName\n ) as PropertyDescriptor\n if (descriptor.get && targetModule.getters) {\n targetModule.getters[funcName] = function (\n state: S,\n getters: GetterTree,\n rootState: any,\n rootGetters: GetterTree\n ) {\n const thisObj = { context: { state, getters, rootState, rootGetters } }\n addPropertiesToObject(thisObj, state)\n addPropertiesToObject(thisObj, getters)\n const got = (descriptor.get as Function).call(thisObj)\n return got\n }\n }\n })\n}\n\nfunction moduleDecoratorFactory(moduleOptions: ModuleOptions) {\n return function (constructor: TFunction): TFunction | void {\n const module: Function & Mod = constructor\n const stateFactory = () => sf(module)\n\n if (!module.state) {\n module.state = moduleOptions && moduleOptions.stateFactory ? stateFactory : stateFactory()\n }\n if (!module.getters) {\n module.getters = {} as GetterTree\n }\n if (!module.namespaced) {\n module.namespaced = moduleOptions && moduleOptions.namespaced\n }\n let parentModule = Object.getPrototypeOf(module)\n while (parentModule.name !== 'VuexModule' && parentModule.name !== '') {\n addGettersToModule(module, parentModule)\n parentModule = Object.getPrototypeOf(parentModule)\n }\n addGettersToModule(module, module)\n const modOpt = moduleOptions as DynamicModuleOptions\n if (modOpt.name) {\n Object.defineProperty(constructor, '_genStatic', {\n value: (store?: Store) => {\n let statics = { store: store || modOpt.store }\n if (!statics.store) {\n throw new Error(`ERR_STORE_NOT_PROVIDED: To use getModule(), either the module\n should be decorated with store in decorator, i.e. @Module({store: store}) or\n store should be passed when calling getModule(), i.e. getModule(MyModule, this.$store)`)\n }\n // =========== For statics ==============\n // ------ state -------\n staticStateGenerator(module, modOpt, statics)\n\n // ------- getters -------\n if (module.getters) {\n staticGetterGenerator(module, modOpt, statics)\n }\n\n // -------- mutations --------\n if (module.mutations) {\n staticMutationGenerator(module, modOpt, statics)\n }\n // -------- actions ---------\n if (module.actions) {\n staticActionGenerators(module, modOpt, statics)\n }\n return statics\n }\n })\n\n Object.defineProperty(constructor, '_vmdModuleName', {\n value: modOpt.name\n })\n }\n\n if (modOpt.dynamic) {\n registerDynamicModule(module, modOpt)\n }\n return constructor\n }\n}\n\nexport function Module(module: Function & Mod): void\nexport function Module(options: ModuleOptions): ClassDecorator\n\nexport function Module(modOrOpt: ModuleOptions | (Function & Mod)) {\n if (typeof (modOrOpt as any) === 'function') {\n /*\n * @Module decorator called without options (directly on the class definition)\n */\n moduleDecoratorFactory({})(modOrOpt as Function & Mod)\n } else {\n /*\n * @Module({...}) decorator called with options\n */\n return moduleDecoratorFactory(modOrOpt)\n }\n}\n","export const config: IConfig = {}\n\nexport interface IConfig {\n rawError?: boolean\n}\n","import { Action as Act, ActionContext, Module as Mod, Payload } from 'vuex'\nimport { getModule, VuexModule } from './vuexmodule'\nimport { addPropertiesToObject, getModuleName } from './helpers'\nimport { config } from './config'\n\n/**\n * Parameters that can be passed to the @Action decorator\n */\nexport interface ActionDecoratorParams {\n commit?: string\n rawError?: boolean\n root?: boolean\n}\nfunction actionDecoratorFactory(params?: ActionDecoratorParams): MethodDecorator {\n const { commit = undefined, rawError = !!config.rawError, root = false } = params || {}\n return function (target: Object, key: string | symbol, descriptor: TypedPropertyDescriptor) {\n const module = target.constructor as Mod\n if (!module.hasOwnProperty('actions')) {\n module.actions = Object.assign({}, module.actions)\n }\n const actionFunction: Function = descriptor.value\n const action: Act = async function (\n context: ActionContext,\n payload: Payload\n ) {\n try {\n let actionPayload = null\n\n if ((module as any)._genStatic) {\n const moduleName = getModuleName(module)\n const moduleAccessor = context.rootGetters[moduleName]\n ? context.rootGetters[moduleName]\n : getModule(module as typeof VuexModule)\n moduleAccessor.context = context\n actionPayload = await actionFunction.call(moduleAccessor, payload)\n } else {\n const thisObj = { context }\n addPropertiesToObject(thisObj, context.state)\n addPropertiesToObject(thisObj, context.getters)\n actionPayload = await actionFunction.call(thisObj, payload)\n }\n if (commit) {\n context.commit(commit, actionPayload)\n }\n return actionPayload\n } catch (e) {\n throw rawError\n ? e\n : new Error(\n 'ERR_ACTION_ACCESS_UNDEFINED: Are you trying to access ' +\n 'this.someMutation() or this.someGetter inside an @Action? \\n' +\n 'That works only in dynamic modules. \\n' +\n 'If not dynamic use this.context.commit(\"mutationName\", payload) ' +\n 'and this.context.getters[\"getterName\"]' +\n '\\n' +\n new Error(`Could not perform action ${key.toString()}`).stack +\n '\\n' +\n e.stack\n )\n }\n }\n module.actions![key as string] = root ? { root, handler: action } : action\n }\n}\n\nexport function Action(\n target: T,\n key: string | symbol,\n descriptor: TypedPropertyDescriptor<(...args: any[]) => R>\n): void\nexport function Action(params: ActionDecoratorParams): MethodDecorator\n\n/**\n * The @Action decorator turns an async function into an Vuex action\n *\n * @param targetOrParams the module class\n * @param key name of the action\n * @param descriptor the action function descriptor\n * @constructor\n */\nexport function Action(\n targetOrParams: T | ActionDecoratorParams,\n key?: string | symbol,\n descriptor?: TypedPropertyDescriptor<(...args: any[]) => R>\n) {\n if (!key && !descriptor) {\n /*\n * This is the case when `targetOrParams` is params.\n * i.e. when used as -\n *
\n        @Action({commit: 'incrCount'})\n        async getCountDelta() {\n          return 5\n        }\n     * 
\n */\n return actionDecoratorFactory(targetOrParams as ActionDecoratorParams)\n } else {\n /*\n * This is the case when @Action is called on action function\n * without any params\n *
\n     *   @Action\n     *   async doSomething() {\n     *    ...\n     *   }\n     * 
\n */\n actionDecoratorFactory()(targetOrParams, key!, descriptor!)\n }\n}\n","import { Module as Mod, Mutation as Mut, Payload } from 'vuex'\n\nexport function Mutation(\n target: T,\n key: string | symbol,\n descriptor: TypedPropertyDescriptor<(...args: any[]) => R>\n) {\n const module = target.constructor as Mod\n if (!module.hasOwnProperty('mutations')) {\n module.mutations = Object.assign({}, module.mutations)\n }\n const mutationFunction: Function = descriptor.value!\n const mutation: Mut = function (state: typeof target, payload: Payload) {\n mutationFunction.call(state, payload)\n }\n module.mutations![key as string] = mutation\n}\n","import { Action as Act, ActionContext, Module as Mod, Mutation as Mut, Payload, Store } from 'vuex'\nimport { addPropertiesToObject } from './helpers'\n\nexport interface MutationActionParams {\n mutate?: (keyof Partial)[]\n rawError?: boolean\n root?: boolean\n}\n\nfunction mutationActionDecoratorFactory(params: MutationActionParams) {\n return function (\n target: T,\n key: string | symbol,\n descriptor: TypedPropertyDescriptor<(...args: any[]) => Promise>>\n ) {\n const module = target.constructor as Mod\n if (!module.hasOwnProperty('mutations')) {\n module.mutations = Object.assign({}, module.mutations)\n }\n if (!module.hasOwnProperty('actions')) {\n module.actions = Object.assign({}, module.actions)\n }\n const mutactFunction = descriptor.value as (payload: any) => Promise\n\n const action: Act = async function (\n context: ActionContext,\n payload: Payload\n ) {\n try {\n const thisObj = { context }\n addPropertiesToObject(thisObj, context.state)\n addPropertiesToObject(thisObj, context.getters)\n const actionPayload = await mutactFunction.call(thisObj, payload)\n context.commit(key as string, actionPayload)\n } catch (e) {\n if (params.rawError) {\n throw e\n } else {\n console.error('Could not perform action ' + key.toString())\n console.error(e)\n return Promise.reject(e)\n }\n }\n }\n\n const mutation: Mut = function (\n state: typeof target | Store,\n payload: Payload & { [k in keyof T]: any }\n ) {\n if (!params.mutate) {\n params.mutate = Object.keys(payload) as (keyof T)[]\n }\n for (let stateItem of params.mutate) {\n if (state.hasOwnProperty(stateItem) && payload.hasOwnProperty(stateItem)) {\n ;(state as T)[stateItem] = payload[stateItem]\n } else {\n throw new Error(`ERR_MUTATE_PARAMS_NOT_IN_PAYLOAD\n In @MutationAction, mutate: ['a', 'b', ...] array keys must\n match with return type = {a: {}, b: {}, ...} and must\n also be in state.`)\n }\n }\n }\n module.actions![key as string] = params.root ? { root: true, handler: action } : action\n module.mutations![key as string] = mutation\n }\n}\n\nexport function MutationAction(\n target: { [k in keyof T]: T[k] | null },\n key: string | symbol,\n descriptor: TypedPropertyDescriptor<(...args: any[]) => Promise>\n): void\n\nexport function MutationAction(\n params: MutationActionParams\n): (\n target: T,\n key: string | symbol,\n descriptor: TypedPropertyDescriptor<(...args: any[]) => Promise>\n) => void\n\n/**\n * The @MutationAction decorator turns this into an action that further calls a mutation\n * Both the action and the mutation are generated for you\n *\n * @param paramsOrTarget the params or the target class\n * @param key the name of the function\n * @param descriptor the function body\n * @constructor\n */\nexport function MutationAction(\n paramsOrTarget: MutationActionParams | M,\n key?: string | symbol,\n descriptor?: TypedPropertyDescriptor<(...args: any[]) => Promise>>\n):\n | ((\n target: T,\n key: string | symbol,\n descriptor: TypedPropertyDescriptor<(...args: any[]) => Promise>>\n ) => void)\n | void {\n if (!key && !descriptor) {\n /*\n * This is the case when `paramsOrTarget` is params.\n * i.e. when used as -\n *
\n        @MutationAction({mutate: ['incrCount']})\n        async getCountDelta() {\n          return {incrCount: 5}\n        }\n     * 
\n */\n return mutationActionDecoratorFactory(paramsOrTarget as MutationActionParams)\n } else {\n /*\n * This is the case when `paramsOrTarget` is target.\n * i.e. when used as -\n *
\n        @MutationAction\n        async getCountDelta() {\n          return {incrCount: 5}\n        }\n     * 
\n */\n mutationActionDecoratorFactory({} as MutationActionParams)(\n paramsOrTarget as K,\n key!,\n descriptor!\n )\n }\n}\n"],"names":["stateFactory","sf"],"mappings":"AAAA;;;;;;SAMgB,qBAAqB,CAAC,MAAW,EAAE,MAAW;4BACnD,CAAC;QACR,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,CAAC,EAAE;YAC/B,GAAG,EAAE,cAAM,OAAA,MAAM,CAAC,CAAC,CAAC,GAAA;SACrB,CAAC,CAAA;;IAHJ,KAAc,UAAyB,EAAzB,KAAA,MAAM,CAAC,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC,EAAzB,cAAyB,EAAzB,IAAyB;QAAlC,IAAI,CAAC,SAAA;gBAAD,CAAC;KAIT;AACH,CAAC;AAED;;;;SAIgB,aAAa,CAAC,MAAW;IACvC,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE;QAC1B,MAAM,IAAI,KAAK,CAAC,oLAEsB,CAAC,CAAA;KACxC;IACD,OAAO,0BAAwB,MAAM,CAAC,cAAgB,CAAA;AACxD;;;ICSE,oBAAY,MAAmB;QAC7B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAA;QAC7B,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAA;QACjC,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAA;QACzB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAA;QAC7B,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAA;QACnC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAA;KAC9B;IACH,iBAAC;AAAD,CAAC,IAAA;SAGe,SAAS,CACvB,WAA6B,EAC7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CAAC,cAAyC,CAAC,CAAA;KACjF;SAAM;;;;;;;;;;;QAWL,8BAA8B,CAAC,EAA6B,CAAC,CAC3D,cAAmB,EACnB,GAAI,EACJ,UAAW,CACZ,CAAA;KACF;AACH;;;;"} \ No newline at end of file diff --git a/dist/types/action.d.ts b/dist/types/action.d.ts new file mode 100644 index 0000000..748b59e --- /dev/null +++ b/dist/types/action.d.ts @@ -0,0 +1,10 @@ +/** + * Parameters that can be passed to the @Action decorator + */ +export interface ActionDecoratorParams { + commit?: string; + rawError?: boolean; + root?: boolean; +} +export declare function Action(target: T, key: string | symbol, descriptor: TypedPropertyDescriptor<(...args: any[]) => R>): void; +export declare function Action(params: ActionDecoratorParams): MethodDecorator; diff --git a/dist/types/config.d.ts b/dist/types/config.d.ts new file mode 100644 index 0000000..574c762 --- /dev/null +++ b/dist/types/config.d.ts @@ -0,0 +1,4 @@ +export declare const config: IConfig; +export interface IConfig { + rawError?: boolean; +} diff --git a/dist/types/helpers.d.ts b/dist/types/helpers.d.ts new file mode 100644 index 0000000..ea77db9 --- /dev/null +++ b/dist/types/helpers.d.ts @@ -0,0 +1,12 @@ +/** + * Takes the properties on object from parameter source and adds them to the object + * parameter target + * @param {object} target Object to have properties copied onto from y + * @param {object} source Object with properties to be copied to x + */ +export declare function addPropertiesToObject(target: any, source: any): void; +/** + * Returns a namespaced name of the module to be used as a store getter + * @param module + */ +export declare function getModuleName(module: any): string; diff --git a/dist/types/index.d.ts b/dist/types/index.d.ts new file mode 100644 index 0000000..a80b761 --- /dev/null +++ b/dist/types/index.d.ts @@ -0,0 +1,6 @@ +export { VuexModule, getModule } from './vuexmodule'; +export { Module } from './module'; +export { Action } from './action'; +export { Mutation } from './mutation'; +export { MutationAction } from './mutationaction'; +export { config } from './config'; diff --git a/dist/types/module/index.d.ts b/dist/types/module/index.d.ts new file mode 100644 index 0000000..b7a32f6 --- /dev/null +++ b/dist/types/module/index.d.ts @@ -0,0 +1,4 @@ +import { Module as Mod } from 'vuex'; +import { ModuleOptions } from '../moduleoptions'; +export declare function Module(module: Function & Mod): void; +export declare function Module(options: ModuleOptions): ClassDecorator; diff --git a/dist/types/module/stateFactory.d.ts b/dist/types/module/stateFactory.d.ts new file mode 100644 index 0000000..38857d9 --- /dev/null +++ b/dist/types/module/stateFactory.d.ts @@ -0,0 +1,2 @@ +import { Module as Mod } from 'vuex'; +export declare function stateFactory(module: Function & Mod): S; diff --git a/dist/types/module/staticGenerators.d.ts b/dist/types/module/staticGenerators.d.ts new file mode 100644 index 0000000..efe9cba --- /dev/null +++ b/dist/types/module/staticGenerators.d.ts @@ -0,0 +1,6 @@ +import { Module as Mod } from 'vuex'; +import { DynamicModuleOptions } from '../moduleoptions'; +export declare function staticStateGenerator(module: Function & Mod, modOpt: DynamicModuleOptions, statics: any): void; +export declare function staticGetterGenerator(module: Function & Mod, modOpt: DynamicModuleOptions, statics: any): void; +export declare function staticMutationGenerator(module: Function & Mod, modOpt: DynamicModuleOptions, statics: any): void; +export declare function staticActionGenerators(module: Function & Mod, modOpt: DynamicModuleOptions, statics: any): void; diff --git a/dist/types/moduleoptions.d.ts b/dist/types/moduleoptions.d.ts new file mode 100644 index 0000000..eddd249 --- /dev/null +++ b/dist/types/moduleoptions.d.ts @@ -0,0 +1,45 @@ +import { Store } from 'vuex'; +/** + * Options to pass to the @Module decorator + */ +export interface StaticModuleOptions { + /** + * name of module, if being namespaced + */ + name?: string; + /** + * whether or not the module is namespaced + */ + namespaced?: boolean; + /** + * Whether to generate a plain state object, or a state factory for the module + */ + stateFactory?: boolean; +} +export interface DynamicModuleOptions { + /** + * If this is a dynamic module (added to store after store is created) + */ + dynamic: true; + /** + * The store into which this module will be injected + */ + store: Store; + /** + * name of module, compulsory for dynamic modules + */ + name: string; + /** + * If this is enabled it will preserve the state when loading the module + */ + preserveState?: boolean; + /** + * whether or not the module is namespaced + */ + namespaced?: boolean; + /** + * Whether to generate a plain state object, or a state factory for the module + */ + stateFactory?: boolean; +} +export declare type ModuleOptions = StaticModuleOptions | DynamicModuleOptions; diff --git a/dist/types/mutation.d.ts b/dist/types/mutation.d.ts new file mode 100644 index 0000000..dd33b6f --- /dev/null +++ b/dist/types/mutation.d.ts @@ -0,0 +1 @@ +export declare function Mutation(target: T, key: string | symbol, descriptor: TypedPropertyDescriptor<(...args: any[]) => R>): void; diff --git a/dist/types/mutationaction.d.ts b/dist/types/mutationaction.d.ts new file mode 100644 index 0000000..1678feb --- /dev/null +++ b/dist/types/mutationaction.d.ts @@ -0,0 +1,9 @@ +export interface MutationActionParams { + mutate?: (keyof Partial)[]; + rawError?: boolean; + root?: boolean; +} +export declare function MutationAction(target: { + [k in keyof T]: T[k] | null; +}, key: string | symbol, descriptor: TypedPropertyDescriptor<(...args: any[]) => Promise>): void; +export declare function MutationAction(params: MutationActionParams): (target: T, key: string | symbol, descriptor: TypedPropertyDescriptor<(...args: any[]) => Promise>) => void; diff --git a/dist/types/vuexmodule.d.ts b/dist/types/vuexmodule.d.ts new file mode 100644 index 0000000..5ec5e04 --- /dev/null +++ b/dist/types/vuexmodule.d.ts @@ -0,0 +1,22 @@ +import { ActionTree, GetterTree, Module as Mod, ModuleTree, MutationTree, Store, ActionContext } from 'vuex'; +export declare class VuexModule, R = any> implements Mod { + static namespaced?: boolean; + static state?: any | (() => any); + static getters?: GetterTree; + static actions?: ActionTree; + static mutations?: MutationTree; + static modules?: ModuleTree; + modules?: ModuleTree; + namespaced?: boolean; + getters?: GetterTree; + state?: S | (() => S); + mutations?: MutationTree; + actions?: ActionTree; + context: ActionContext; + constructor(module: Mod); +} +declare type ConstructorOf = { + new (...args: any[]): C; +}; +export declare function getModule(moduleClass: ConstructorOf, store?: Store): M; +export {}; diff --git a/package.json b/package.json index 447bacb..79baab2 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ }, "peerDependencies": { "vue": ">=2", - "vuex": "3" + "vuex": ">=3" }, "homepage": "https://github.com/championswimmer/vuex-module-decorators#readme", "devDependencies": { From a3b526819da1626cd47604340b204402db162915 Mon Sep 17 00:00:00 2001 From: Yam Marcovitz Date: Sat, 25 Sep 2021 13:32:25 +0300 Subject: [PATCH 5/5] 1.1.1 --- CHANGELOG.md | 3 +++ package.json | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 128ac4a..4b75e36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ If `(beta)` or `(alpha)` is marked in front of any release, it can be installed as `npm install vuex-module-decorators@beta` (or alpha similar). +## 1.1.1 +- fix deployment issues when installing directly from git + ## 1.1.0 - add access to state and getters in MutationAction diff --git a/package.json b/package.json index 79baab2..72c2074 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vuex-module-decorators", - "version": "1.1.0", + "version": "1.1.1", "description": "Decorators to make class-like Vuex modules", "main": "dist/cjs/index.js", "types": "dist/types/index.d.ts",