@awes-io/vue-mc 0.7.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,28 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [0.9.0](https://github.com/awes-io/client/compare/@awes-io/vue-mc@0.8.0...@awes-io/vue-mc@0.9.0) (2023-11-23)
7
+
8
+
9
+ ### Features
10
+
11
+ * **vue-mc:** injectable system added ([98a6cb6](https://github.com/awes-io/client/commit/98a6cb6542122e4404817d63fa198e160dcc99b1))
12
+
13
+
14
+
15
+
16
+
17
+ # [0.8.0](https://github.com/awes-io/client/compare/@awes-io/vue-mc@0.7.0...@awes-io/vue-mc@0.8.0) (2023-08-22)
18
+
19
+
20
+ ### Features
21
+
22
+ * unused modules removed ([09334f1](https://github.com/awes-io/client/commit/09334f1677a837df5eac8c4063e4a55941fde40e))
23
+
24
+
25
+
26
+
27
+
6
28
  # [0.7.0](https://github.com/awes-io/client/compare/@awes-io/vue-mc@0.6.0...@awes-io/vue-mc@0.7.0) (2022-07-11)
7
29
 
8
30
 
package/dist/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
- import axios from 'axios';
2
1
  import { Response as Response$1, Request as Request$1, Collection, Model } from 'vue-mc';
2
+ import axios from 'axios';
3
3
  import { pathOr } from 'rambdax';
4
4
 
5
5
  function _classCallCheck(instance, Constructor) {
@@ -133,15 +133,33 @@ function _get(target, property, receiver) {
133
133
  return _get(target, property, receiver || target);
134
134
  }
135
135
 
136
+ var injections = new Map([['axios', axios]]);
137
+ var applyInjections = function applyInjections(context) {
138
+ injections.forEach(function (value, key) {
139
+ context['$' + key] = value;
140
+ });
141
+ };
142
+ function inject(key, value) {
143
+ injections.set(key, value);
144
+ }
145
+
136
146
  var Response = /*#__PURE__*/function (_VueMCResponse) {
137
147
  _inherits(Response, _VueMCResponse);
138
148
 
139
149
  var _super = _createSuper(Response);
140
150
 
141
151
  function Response() {
152
+ var _this;
153
+
142
154
  _classCallCheck(this, Response);
143
155
 
144
- return _super.apply(this, arguments);
156
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
157
+ args[_key] = arguments[_key];
158
+ }
159
+
160
+ _this = _super.call.apply(_super, [this].concat(args));
161
+ applyInjections(_assertThisInitialized(_this));
162
+ return _this;
145
163
  }
146
164
 
147
165
  _createClass(Response, [{
@@ -164,13 +182,17 @@ var Request = /*#__PURE__*/function (_VueMCRequest) {
164
182
 
165
183
  var _super = _createSuper(Request);
166
184
 
167
- function Request(config, axios) {
185
+ function Request() {
168
186
  var _this;
169
187
 
170
188
  _classCallCheck(this, Request);
171
189
 
172
- _this = _super.call(this, config);
173
- _this.axios = axios;
190
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
191
+ args[_key] = arguments[_key];
192
+ }
193
+
194
+ _this = _super.call.apply(_super, [this].concat(args));
195
+ applyInjections(_assertThisInitialized(_this));
174
196
  return _this;
175
197
  }
176
198
 
@@ -184,7 +206,7 @@ var Request = /*#__PURE__*/function (_VueMCRequest) {
184
206
  value: function send() {
185
207
  var _this2 = this;
186
208
 
187
- return this.axios.request(this.config).then(this.createResponse).catch(function (error) {
209
+ return this.$axios.request(this.config).then(this.createResponse).catch(function (error) {
188
210
  throw _this2.createError(error);
189
211
  });
190
212
  }
@@ -199,38 +221,52 @@ var BaseCollection = /*#__PURE__*/function (_Collection) {
199
221
  var _super = _createSuper(BaseCollection);
200
222
 
201
223
  function BaseCollection() {
224
+ var _this;
225
+
202
226
  _classCallCheck(this, BaseCollection);
203
227
 
204
- return _super.apply(this, arguments);
228
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
229
+ args[_key] = arguments[_key];
230
+ }
231
+
232
+ _this = _super.call.apply(_super, [this].concat(args));
233
+ applyInjections(_assertThisInitialized(_this));
234
+ return _this;
205
235
  }
206
236
 
207
237
  _createClass(BaseCollection, [{
208
238
  key: "createRequest",
209
239
  value: function createRequest(config) {
210
- return new Request(config, this.$axios);
240
+ return new Request(config);
211
241
  }
212
242
  }]);
213
243
 
214
244
  return BaseCollection;
215
245
  }(Collection);
216
246
 
217
- BaseCollection.prototype.$axios = axios;
218
-
219
247
  var BaseModel = /*#__PURE__*/function (_Model) {
220
248
  _inherits(BaseModel, _Model);
221
249
 
222
250
  var _super = _createSuper(BaseModel);
223
251
 
224
252
  function BaseModel() {
253
+ var _this;
254
+
225
255
  _classCallCheck(this, BaseModel);
226
256
 
227
- return _super.apply(this, arguments);
257
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
258
+ args[_key] = arguments[_key];
259
+ }
260
+
261
+ _this = _super.call.apply(_super, [this].concat(args));
262
+ applyInjections(_assertThisInitialized(_this));
263
+ return _this;
228
264
  }
229
265
 
230
266
  _createClass(BaseModel, [{
231
267
  key: "createRequest",
232
268
  value: function createRequest(config) {
233
- return new Request(config, this.$axios);
269
+ return new Request(config);
234
270
  }
235
271
  }, {
236
272
  key: "getDefaultMethods",
@@ -257,6 +293,4 @@ var BaseModel = /*#__PURE__*/function (_Model) {
257
293
  return BaseModel;
258
294
  }(Model);
259
295
 
260
- BaseModel.prototype.$axios = axios;
261
-
262
- export { BaseCollection, BaseModel };
296
+ export { BaseCollection, BaseModel, Request, Response, inject };
package/dist/index.js CHANGED
@@ -4,8 +4,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
6
 
7
- var axios = _interopDefault(require('axios'));
8
7
  var vueMc = require('vue-mc');
8
+ var axios = _interopDefault(require('axios'));
9
9
  var rambdax = require('rambdax');
10
10
 
11
11
  function _classCallCheck(instance, Constructor) {
@@ -139,15 +139,33 @@ function _get(target, property, receiver) {
139
139
  return _get(target, property, receiver || target);
140
140
  }
141
141
 
142
+ var injections = new Map([['axios', axios]]);
143
+ var applyInjections = function applyInjections(context) {
144
+ injections.forEach(function (value, key) {
145
+ context['$' + key] = value;
146
+ });
147
+ };
148
+ function inject(key, value) {
149
+ injections.set(key, value);
150
+ }
151
+
142
152
  var Response = /*#__PURE__*/function (_VueMCResponse) {
143
153
  _inherits(Response, _VueMCResponse);
144
154
 
145
155
  var _super = _createSuper(Response);
146
156
 
147
157
  function Response() {
158
+ var _this;
159
+
148
160
  _classCallCheck(this, Response);
149
161
 
150
- return _super.apply(this, arguments);
162
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
163
+ args[_key] = arguments[_key];
164
+ }
165
+
166
+ _this = _super.call.apply(_super, [this].concat(args));
167
+ applyInjections(_assertThisInitialized(_this));
168
+ return _this;
151
169
  }
152
170
 
153
171
  _createClass(Response, [{
@@ -170,13 +188,17 @@ var Request = /*#__PURE__*/function (_VueMCRequest) {
170
188
 
171
189
  var _super = _createSuper(Request);
172
190
 
173
- function Request(config, axios) {
191
+ function Request() {
174
192
  var _this;
175
193
 
176
194
  _classCallCheck(this, Request);
177
195
 
178
- _this = _super.call(this, config);
179
- _this.axios = axios;
196
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
197
+ args[_key] = arguments[_key];
198
+ }
199
+
200
+ _this = _super.call.apply(_super, [this].concat(args));
201
+ applyInjections(_assertThisInitialized(_this));
180
202
  return _this;
181
203
  }
182
204
 
@@ -190,7 +212,7 @@ var Request = /*#__PURE__*/function (_VueMCRequest) {
190
212
  value: function send() {
191
213
  var _this2 = this;
192
214
 
193
- return this.axios.request(this.config).then(this.createResponse).catch(function (error) {
215
+ return this.$axios.request(this.config).then(this.createResponse).catch(function (error) {
194
216
  throw _this2.createError(error);
195
217
  });
196
218
  }
@@ -205,38 +227,52 @@ var BaseCollection = /*#__PURE__*/function (_Collection) {
205
227
  var _super = _createSuper(BaseCollection);
206
228
 
207
229
  function BaseCollection() {
230
+ var _this;
231
+
208
232
  _classCallCheck(this, BaseCollection);
209
233
 
210
- return _super.apply(this, arguments);
234
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
235
+ args[_key] = arguments[_key];
236
+ }
237
+
238
+ _this = _super.call.apply(_super, [this].concat(args));
239
+ applyInjections(_assertThisInitialized(_this));
240
+ return _this;
211
241
  }
212
242
 
213
243
  _createClass(BaseCollection, [{
214
244
  key: "createRequest",
215
245
  value: function createRequest(config) {
216
- return new Request(config, this.$axios);
246
+ return new Request(config);
217
247
  }
218
248
  }]);
219
249
 
220
250
  return BaseCollection;
221
251
  }(vueMc.Collection);
222
252
 
223
- BaseCollection.prototype.$axios = axios;
224
-
225
253
  var BaseModel = /*#__PURE__*/function (_Model) {
226
254
  _inherits(BaseModel, _Model);
227
255
 
228
256
  var _super = _createSuper(BaseModel);
229
257
 
230
258
  function BaseModel() {
259
+ var _this;
260
+
231
261
  _classCallCheck(this, BaseModel);
232
262
 
233
- return _super.apply(this, arguments);
263
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
264
+ args[_key] = arguments[_key];
265
+ }
266
+
267
+ _this = _super.call.apply(_super, [this].concat(args));
268
+ applyInjections(_assertThisInitialized(_this));
269
+ return _this;
234
270
  }
235
271
 
236
272
  _createClass(BaseModel, [{
237
273
  key: "createRequest",
238
274
  value: function createRequest(config) {
239
- return new Request(config, this.$axios);
275
+ return new Request(config);
240
276
  }
241
277
  }, {
242
278
  key: "getDefaultMethods",
@@ -263,7 +299,8 @@ var BaseModel = /*#__PURE__*/function (_Model) {
263
299
  return BaseModel;
264
300
  }(vueMc.Model);
265
301
 
266
- BaseModel.prototype.$axios = axios;
267
-
268
302
  exports.BaseCollection = BaseCollection;
269
303
  exports.BaseModel = BaseModel;
304
+ exports.Request = Request;
305
+ exports.Response = Response;
306
+ exports.inject = inject;
@@ -1,62 +1,8 @@
1
- import { BaseModel, BaseCollection } from '@awes-io/vue-mc'
2
- import Request from '@awes-io/vue-mc/src/Structures/Request'
1
+ import { inject } from '@awes-io/vue-mc'
3
2
 
4
- const wrapAuthHandler = (fn, context, redirect) => {
5
- return async (...args) => {
6
- try {
7
- return await fn.apply(context, args)
8
- } catch (e) {
9
- console.log(e)
10
-
11
- if (e.name === 'ExpiredAuthSessionError') {
12
- redirect('/login')
13
- } else {
14
- throw e
15
- }
16
- }
17
- }
18
- }
19
-
20
- export default ({ $axios, $dayjs, store, app, redirect }) => {
21
- // axios
22
- BaseModel.prototype.$axios = $axios
23
- BaseCollection.prototype.$axios = $axios
24
-
25
- // request
26
- BaseModel.prototype.createRequest = function(config) {
27
- return new Request(config, $axios)
28
- }
29
- BaseCollection.prototype.createRequest = function(config) {
30
- return new Request(config, $axios)
31
- }
32
-
33
- // store
34
- BaseModel.prototype.$store = store
35
- BaseCollection.prototype.$store = store
36
-
37
- // localization
38
- const $t = app.i18n.t.bind(app.i18n)
39
- BaseModel.prototype.$t = $t
40
- BaseCollection.prototype.$t = $t
41
-
42
- // dayjs
43
- if ($dayjs) {
44
- BaseModel.prototype.$dayjs = $dayjs
45
- BaseCollection.prototype.$dayjs = $dayjs
46
- }
47
-
48
- // request overwrite to handle expired auth error
49
- const modelRequest = BaseModel.prototype.request
50
- const collectionRequest = BaseCollection.prototype.request
51
-
52
- BaseModel.prototype.request = wrapAuthHandler(
53
- modelRequest,
54
- BaseModel.prototype,
55
- redirect
56
- )
57
- BaseCollection.prototype.request = wrapAuthHandler(
58
- collectionRequest,
59
- BaseCollection.prototype,
60
- redirect
61
- )
3
+ export default ({ $axios, $dayjs, store, app }) => {
4
+ inject('axios', $axios)
5
+ inject('dayjs', $dayjs)
6
+ inject('store', store)
7
+ inject('t', app.i18n.t.bind(app.i18n))
62
8
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awes-io/vue-mc",
3
- "version": "0.7.0",
3
+ "version": "0.9.0",
4
4
  "description": "Models and collections abstract layer.",
5
5
  "homepage": "https://awes.io",
6
6
  "bugs": {
@@ -31,5 +31,15 @@
31
31
  "rollup": "^1.30.1",
32
32
  "rollup-plugin-babel": "^4.3.3"
33
33
  },
34
- "gitHead": "20130efc0ba9efdce40af425a4ee09bb5f90d84a"
34
+ "overrides": {
35
+ "vue": "2.7.14",
36
+ "vue-template-compiler": "2.7.14",
37
+ "vue-server-renderer": "2.7.14"
38
+ },
39
+ "resolutions": {
40
+ "vue": "2.7.14",
41
+ "vue-template-compiler": "2.7.14",
42
+ "vue-server-renderer": "2.7.14"
43
+ },
44
+ "gitHead": "078158dae22db6592008e4fc37c34e08ccfeb618"
35
45
  }
@@ -1,13 +1,17 @@
1
- import axios from 'axios'
2
1
  import { Collection } from 'vue-mc'
2
+ import { applyInjections } from '../injectable'
3
3
  import Request from './Request'
4
4
 
5
5
  class BaseCollection extends Collection {
6
+ constructor(...args) {
7
+ super(...args)
8
+
9
+ applyInjections(this)
10
+ }
11
+
6
12
  createRequest(config) {
7
- return new Request(config, this.$axios)
13
+ return new Request(config)
8
14
  }
9
15
  }
10
16
 
11
- BaseCollection.prototype.$axios = axios
12
-
13
17
  export default BaseCollection
@@ -1,10 +1,16 @@
1
- import axios from 'axios'
2
1
  import { Model } from 'vue-mc'
2
+ import { applyInjections } from '../injectable'
3
3
  import Request from './Request'
4
4
 
5
5
  class BaseModel extends Model {
6
+ constructor(...args) {
7
+ super(...args)
8
+
9
+ applyInjections(this)
10
+ }
11
+
6
12
  createRequest(config) {
7
- return new Request(config, this.$axios)
13
+ return new Request(config)
8
14
  }
9
15
 
10
16
  getDefaultMethods() {
@@ -27,6 +33,4 @@ class BaseModel extends Model {
27
33
  }
28
34
  }
29
35
 
30
- BaseModel.prototype.$axios = axios
31
-
32
36
  export default BaseModel
@@ -1,10 +1,12 @@
1
1
  import { Request as VueMCRequest } from 'vue-mc'
2
+ import { applyInjections } from '../injectable'
2
3
  import Response from './Response'
3
4
 
4
5
  export default class Request extends VueMCRequest {
5
- constructor(config, axios) {
6
- super(config)
7
- this.axios = axios
6
+ constructor(...args) {
7
+ super(...args)
8
+
9
+ applyInjections(this)
8
10
  }
9
11
 
10
12
  createResponse(axiosResponse) {
@@ -12,7 +14,7 @@ export default class Request extends VueMCRequest {
12
14
  }
13
15
 
14
16
  send() {
15
- return this.axios
17
+ return this.$axios
16
18
  .request(this.config)
17
19
  .then(this.createResponse)
18
20
  .catch((error) => {
@@ -1,7 +1,14 @@
1
1
  import { Response as VueMCResponse } from 'vue-mc'
2
+ import { applyInjections } from '../injectable'
2
3
  import { pathOr } from 'rambdax'
3
4
 
4
5
  export default class Response extends VueMCResponse {
6
+ constructor(...args) {
7
+ super(...args)
8
+
9
+ applyInjections(this)
10
+ }
11
+
5
12
  getData() {
6
13
  return pathOr(null, 'data.data', this.response)
7
14
  }
package/src/index.js CHANGED
@@ -1,3 +1,9 @@
1
1
  export { default as BaseCollection } from './Structures/Collection'
2
2
 
3
3
  export { default as BaseModel } from './Structures/Model'
4
+
5
+ export { default as Request } from './Structures/Request'
6
+
7
+ export { default as Response } from './Structures/Response'
8
+
9
+ export { default as inject } from './injectable'
@@ -0,0 +1,13 @@
1
+ import axios from 'axios'
2
+
3
+ const injections = new Map([['axios', axios]])
4
+
5
+ export const applyInjections = (context) => {
6
+ injections.forEach((value, key) => {
7
+ context['$' + key] = value
8
+ })
9
+ }
10
+
11
+ export default function inject(key, value) {
12
+ injections.set(key, value)
13
+ }