@schukai/monster 3.10.0 → 3.11.0

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schukai/monster",
3
- "version": "3.10.0",
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
  /**
@@ -190,10 +190,12 @@ class Translations extends Base {
190
190
  /**
191
191
  * Returns the translations for the current document.
192
192
  *
193
- * @param element
194
- * @returns {*}
195
- * @throws {Error} Element is not an HTMLElement
196
- * @throws {Error} Missing translations
193
+ * @param {HTMLElement|undefined} [element] - Element to search for translations. Default: element with objectlink @schukai/monster/i18n/translations@@link.
194
+ * @returns {Translations}
195
+ * @throws {Error} Element is not an HTMLElement.
196
+ * @throws {Error} Cannot find element with translations. Add a translations object to the document.
197
+ * @throws {Error} This element has no translations.
198
+ * @throws {Error} Missing translations.
197
199
  */
198
200
  function getDocumentTranslations(element) {
199
201
 
@@ -201,14 +203,17 @@ function getDocumentTranslations(element) {
201
203
 
202
204
  if (!(element instanceof HTMLElement)) {
203
205
  element = d.querySelector('['+ATTRIBUTE_OBJECTLINK+'~="' + translationsLinkSymbol.toString() + '"]');
206
+ if (element === null) {
207
+ throw new Error("Cannot find element with translations. Add a translations object to the document.");
208
+ }
204
209
  }
205
210
 
206
211
  if (!(element instanceof HTMLElement)) {
207
- throw new Error("Element is not an HTMLElement");
212
+ throw new Error("Element is not an HTMLElement.");
208
213
  }
209
214
 
210
215
  if (!hasObjectLink(element, translationsLinkSymbol)) {
211
- throw new Error("Missing translations");
216
+ throw new Error("This element has no translations.");
212
217
  }
213
218
 
214
219
  let obj = getLinkedObjects(element, translationsLinkSymbol);
@@ -219,7 +224,7 @@ function getDocumentTranslations(element) {
219
224
  }
220
225
  }
221
226
 
222
- throw new Error("Missing translations");
227
+ throw new Error("Missing translations.");
223
228
 
224
229
  }
225
230
 
@@ -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.0");
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.0")
10
+ monsterVersion = new Version("3.11.0")
11
11
 
12
12
  let m = getMonsterVersion();
13
13