Skip to content

Commit 0ae8245

Browse files
committed
[Release] 0.9.1
1 parent 395ab97 commit 0ae8245

5 files changed

+74
-29
lines changed

dist/vuex-orm-axios.common.js

+24-9
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,17 @@ var Response = /** @class */ (function () {
8585
*/
8686
Response.prototype.save = function () {
8787
return __awaiter(this, void 0, void 0, function () {
88-
var _a;
88+
var data, _a;
8989
return __generator(this, function (_b) {
9090
switch (_b.label) {
9191
case 0:
92+
data = this.getDataFromResponse();
93+
if (!this.validateData(data)) {
94+
console.warn('[Vuex ORM Axios] The response data could not be saved to the store because it\'s not an object or an array. You might want to use `dataTransformer` option to handle non-array/object response before saving it to the store.');
95+
return [2 /*return*/];
96+
}
9297
_a = this;
93-
return [4 /*yield*/, this.model.insertOrUpdate({
94-
data: this.getDataFromResponse()
95-
})];
98+
return [4 /*yield*/, this.model.insertOrUpdate({ data: data })];
9699
case 1:
97100
_a.entities = _b.sent();
98101
this.isSaved = true;
@@ -134,6 +137,12 @@ var Response = /** @class */ (function () {
134137
}
135138
return this.response.data;
136139
};
140+
/**
141+
* Validate if the given data is insertable to Vuex ORM.
142+
*/
143+
Response.prototype.validateData = function (data) {
144+
return data !== null && typeof data === 'object';
145+
};
137146
return Response;
138147
}());
139148

@@ -263,18 +272,24 @@ var Request = /** @class */ (function () {
263272
*/
264273
Request.prototype.createResponse = function (axiosResponse, config) {
265274
return __awaiter(this, void 0, void 0, function () {
266-
var response;
267-
return __generator(this, function (_a) {
268-
switch (_a.label) {
275+
var response, _a;
276+
return __generator(this, function (_b) {
277+
switch (_b.label) {
269278
case 0:
270279
response = new Response(this.model, config, axiosResponse);
271280
if (!(config.delete !== undefined)) return [3 /*break*/, 2];
272281
return [4 /*yield*/, response.delete()];
273282
case 1:
274-
_a.sent();
283+
_b.sent();
275284
return [2 /*return*/, response];
276285
case 2:
277-
config.save && response.save();
286+
_a = config.save;
287+
if (!_a) return [3 /*break*/, 4];
288+
return [4 /*yield*/, response.save()];
289+
case 3:
290+
_a = (_b.sent());
291+
_b.label = 4;
292+
case 4:
278293
return [2 /*return*/, response];
279294
}
280295
});

dist/vuex-orm-axios.esm.js

+24-9
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,17 @@ var Response = /** @class */ (function () {
8383
*/
8484
Response.prototype.save = function () {
8585
return __awaiter(this, void 0, void 0, function () {
86-
var _a;
86+
var data, _a;
8787
return __generator(this, function (_b) {
8888
switch (_b.label) {
8989
case 0:
90+
data = this.getDataFromResponse();
91+
if (!this.validateData(data)) {
92+
console.warn('[Vuex ORM Axios] The response data could not be saved to the store because it\'s not an object or an array. You might want to use `dataTransformer` option to handle non-array/object response before saving it to the store.');
93+
return [2 /*return*/];
94+
}
9095
_a = this;
91-
return [4 /*yield*/, this.model.insertOrUpdate({
92-
data: this.getDataFromResponse()
93-
})];
96+
return [4 /*yield*/, this.model.insertOrUpdate({ data: data })];
9497
case 1:
9598
_a.entities = _b.sent();
9699
this.isSaved = true;
@@ -132,6 +135,12 @@ var Response = /** @class */ (function () {
132135
}
133136
return this.response.data;
134137
};
138+
/**
139+
* Validate if the given data is insertable to Vuex ORM.
140+
*/
141+
Response.prototype.validateData = function (data) {
142+
return data !== null && typeof data === 'object';
143+
};
135144
return Response;
136145
}());
137146

@@ -261,18 +270,24 @@ var Request = /** @class */ (function () {
261270
*/
262271
Request.prototype.createResponse = function (axiosResponse, config) {
263272
return __awaiter(this, void 0, void 0, function () {
264-
var response;
265-
return __generator(this, function (_a) {
266-
switch (_a.label) {
273+
var response, _a;
274+
return __generator(this, function (_b) {
275+
switch (_b.label) {
267276
case 0:
268277
response = new Response(this.model, config, axiosResponse);
269278
if (!(config.delete !== undefined)) return [3 /*break*/, 2];
270279
return [4 /*yield*/, response.delete()];
271280
case 1:
272-
_a.sent();
281+
_b.sent();
273282
return [2 /*return*/, response];
274283
case 2:
275-
config.save && response.save();
284+
_a = config.save;
285+
if (!_a) return [3 /*break*/, 4];
286+
return [4 /*yield*/, response.save()];
287+
case 3:
288+
_a = (_b.sent());
289+
_b.label = 4;
290+
case 4:
276291
return [2 /*return*/, response];
277292
}
278293
});

dist/vuex-orm-axios.js

+24-9
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,17 @@
8989
*/
9090
Response.prototype.save = function () {
9191
return __awaiter(this, void 0, void 0, function () {
92-
var _a;
92+
var data, _a;
9393
return __generator(this, function (_b) {
9494
switch (_b.label) {
9595
case 0:
96+
data = this.getDataFromResponse();
97+
if (!this.validateData(data)) {
98+
console.warn('[Vuex ORM Axios] The response data could not be saved to the store because it\'s not an object or an array. You might want to use `dataTransformer` option to handle non-array/object response before saving it to the store.');
99+
return [2 /*return*/];
100+
}
96101
_a = this;
97-
return [4 /*yield*/, this.model.insertOrUpdate({
98-
data: this.getDataFromResponse()
99-
})];
102+
return [4 /*yield*/, this.model.insertOrUpdate({ data: data })];
100103
case 1:
101104
_a.entities = _b.sent();
102105
this.isSaved = true;
@@ -138,6 +141,12 @@
138141
}
139142
return this.response.data;
140143
};
144+
/**
145+
* Validate if the given data is insertable to Vuex ORM.
146+
*/
147+
Response.prototype.validateData = function (data) {
148+
return data !== null && typeof data === 'object';
149+
};
141150
return Response;
142151
}());
143152

@@ -267,18 +276,24 @@
267276
*/
268277
Request.prototype.createResponse = function (axiosResponse, config) {
269278
return __awaiter(this, void 0, void 0, function () {
270-
var response;
271-
return __generator(this, function (_a) {
272-
switch (_a.label) {
279+
var response, _a;
280+
return __generator(this, function (_b) {
281+
switch (_b.label) {
273282
case 0:
274283
response = new Response(this.model, config, axiosResponse);
275284
if (!(config.delete !== undefined)) return [3 /*break*/, 2];
276285
return [4 /*yield*/, response.delete()];
277286
case 1:
278-
_a.sent();
287+
_b.sent();
279288
return [2 /*return*/, response];
280289
case 2:
281-
config.save && response.save();
290+
_a = config.save;
291+
if (!_a) return [3 /*break*/, 4];
292+
return [4 /*yield*/, response.save()];
293+
case 3:
294+
_a = (_b.sent());
295+
_b.label = 4;
296+
case 4:
282297
return [2 /*return*/, response];
283298
}
284299
});

dist/vuex-orm-axios.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@vuex-orm/plugin-axios",
3-
"version": "0.9.0",
3+
"version": "0.9.1",
44
"description": "Vuex ORM plugin for adding smooth integration with axios.",
55
"main": "dist/vuex-orm-axios.common.js",
66
"module": "dist/vuex-orm-axios.esm.js",

0 commit comments

Comments
 (0)