@schukai/monster 3.10.1 → 3.11.0
Sign up to get free protection for your applications and to get access to all the features.
package/package.json
CHANGED
@@ -49,6 +49,7 @@ class RestAPI extends Server {
|
|
49
49
|
* @property {Object} write.init={} An options object containing any custom settings that you want to apply to the request. The parameters are identical to those of the {@link https://developer.mozilla.org/en-US/docs/Web/API/Request/Request|Request constructor}
|
50
50
|
* @property {string} write.init.method=POST
|
51
51
|
* @property {Object} write.init.headers Object containing any custom headers that you want to apply to the request.
|
52
|
+
* @property {string} write.responseCallback Callback function to be executed after the request has been completed.
|
52
53
|
* @property {string} write.acceptedStatus=[200,201]
|
53
54
|
* @property {string} write.url URL
|
54
55
|
* @property {Object} write.mapping the mapping is applied before writing.
|
@@ -74,6 +75,7 @@ class RestAPI extends Server {
|
|
74
75
|
init: {
|
75
76
|
method: "POST",
|
76
77
|
},
|
78
|
+
responseCallback: undefined,
|
77
79
|
acceptedStatus: [200, 201],
|
78
80
|
url: undefined,
|
79
81
|
mapping: {
|
@@ -92,6 +94,7 @@ class RestAPI extends Server {
|
|
92
94
|
init: {
|
93
95
|
method: "GET",
|
94
96
|
},
|
97
|
+
responseCallback: undefined,
|
95
98
|
acceptedStatus: [200],
|
96
99
|
url: undefined,
|
97
100
|
mapping: {
|
@@ -115,9 +118,12 @@ class RestAPI extends Server {
|
|
115
118
|
if (!isObject(init)) init = {};
|
116
119
|
if (!init["method"]) init["method"] = "GET";
|
117
120
|
|
118
|
-
|
121
|
+
let callback = self.getOption("read.responseCallback");
|
122
|
+
if(!callback) callback = (obj) => {
|
119
123
|
self.set(self.transformServerPayload.call(self, obj));
|
120
|
-
}
|
124
|
+
};
|
125
|
+
|
126
|
+
return fetchData.call(this, "read", callback);
|
121
127
|
}
|
122
128
|
|
123
129
|
/**
|
@@ -139,7 +145,8 @@ class RestAPI extends Server {
|
|
139
145
|
let obj = self.prepareServerPayload(self.get());
|
140
146
|
init["body"] = JSON.stringify(obj);
|
141
147
|
|
142
|
-
|
148
|
+
let callback = self.getOption("write.responseCallback");
|
149
|
+
return fetchData.call(this, init, "write", callback);
|
143
150
|
}
|
144
151
|
|
145
152
|
/**
|
package/source/types/version.mjs
CHANGED
package/test/cases/monster.mjs
CHANGED