@schukai/monster 3.10.1 → 3.11.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schukai/monster",
3
- "version": "3.10.1",
3
+ "version": "3.11.0",
4
4
  "description": "Monster is a simple library for creating fast, robust and lightweight websites.",
5
5
  "keywords": [
6
6
  "framework",
@@ -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
- return fetchData.call(this, "read", (obj) => {
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
- return fetchData.call(this, init, "write");
148
+ let callback = self.getOption("write.responseCallback");
149
+ return fetchData.call(this, init, "write", callback);
143
150
  }
144
151
 
145
152
  /**
@@ -142,7 +142,7 @@ function getMonsterVersion() {
142
142
  }
143
143
 
144
144
  /** don't touch, replaced by make with package.json version */
145
- monsterVersion = new Version("3.10.1");
145
+ monsterVersion = new Version("3.11.0");
146
146
 
147
147
  return monsterVersion;
148
148
  }
@@ -7,7 +7,7 @@ describe('Monster', function () {
7
7
  let monsterVersion
8
8
 
9
9
  /** don´t touch, replaced by make with package.json version */
10
- monsterVersion = new Version("3.10.1")
10
+ monsterVersion = new Version("3.11.0")
11
11
 
12
12
  let m = getMonsterVersion();
13
13