@schukai/monster 3.100.17 → 3.100.18

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
@@ -2,6 +2,17 @@
2
2
 
3
3
 
4
4
 
5
+ ## [3.100.18] - 2025-01-20
6
+
7
+ ### Bug Fixes
8
+
9
+ - set request header if not set
10
+ ### Changes
11
+
12
+ - update tests
13
+
14
+
15
+
5
16
  ## [3.100.17] - 2025-01-20
6
17
 
7
18
  ### Bug Fixes
package/package.json CHANGED
@@ -1 +1 @@
1
- {"author":"schukai GmbH","dependencies":{"@floating-ui/dom":"^1.6.13","@popperjs/core":"^2.11.8"},"description":"Monster is a simple library for creating fast, robust and lightweight websites.","homepage":"https://monsterjs.org/","keywords":["framework","web","dom","css","sass","mobile-first","app","front-end","templates","schukai","core","shopcloud","alvine","monster","buildmap","stack","observer","observable","uuid","node","nodelist","css-in-js","logger","log","theme"],"license":"AGPL 3.0","main":"source/monster.mjs","module":"source/monster.mjs","name":"@schukai/monster","repository":{"type":"git","url":"https://gitlab.schukai.com/oss/libraries/javascript/monster.git"},"type":"module","version":"3.100.17"}
1
+ {"author":"schukai GmbH","dependencies":{"@floating-ui/dom":"^1.6.13","@popperjs/core":"^2.11.8"},"description":"Monster is a simple library for creating fast, robust and lightweight websites.","homepage":"https://monsterjs.org/","keywords":["framework","web","dom","css","sass","mobile-first","app","front-end","templates","schukai","core","shopcloud","alvine","monster","buildmap","stack","observer","observable","uuid","node","nodelist","css-in-js","logger","log","theme"],"license":"AGPL 3.0","main":"source/monster.mjs","module":"source/monster.mjs","name":"@schukai/monster","repository":{"type":"git","url":"https://gitlab.schukai.com/oss/libraries/javascript/monster.git"},"type":"module","version":"3.100.18"}
@@ -12,15 +12,15 @@
12
12
  * SPDX-License-Identifier: AGPL-3.0
13
13
  */
14
14
 
15
- import { internalSymbol, instanceSymbol } from "../../../constants.mjs";
16
- import { isObject, isFunction, isArray } from "../../../types/is.mjs";
17
- import { diff } from "../../diff.mjs";
18
- import { Server } from "../server.mjs";
19
- import { WriteError } from "./restapi/writeerror.mjs";
20
- import { DataFetchError } from "./restapi/data-fetch-error.mjs";
21
- import { clone } from "../../../util/clone.mjs";
15
+ import {internalSymbol, instanceSymbol} from "../../../constants.mjs";
16
+ import {isObject, isFunction, isArray} from "../../../types/is.mjs";
17
+ import {diff} from "../../diff.mjs";
18
+ import {Server} from "../server.mjs";
19
+ import {WriteError} from "./restapi/writeerror.mjs";
20
+ import {DataFetchError} from "./restapi/data-fetch-error.mjs";
21
+ import {clone} from "../../../util/clone.mjs";
22
22
 
23
- export { RestAPI };
23
+ export {RestAPI};
24
24
 
25
25
  /**
26
26
  * @type {symbol}
@@ -28,7 +28,7 @@ export { RestAPI };
28
28
  * @since 3.12.0
29
29
  */
30
30
  const rawDataSymbol = Symbol.for(
31
- "@schukai/monster/data/datasource/server/restapi/rawdata",
31
+ "@schukai/monster/data/datasource/server/restapi/rawdata",
32
32
  );
33
33
 
34
34
  /**
@@ -41,159 +41,159 @@ const rawDataSymbol = Symbol.for(
41
41
  * @summary The RestAPI is a class that binds a REST API server.
42
42
  */
43
43
  class RestAPI extends Server {
44
- /**
45
- *
46
- * @param {Object} [options] options contains definitions for the datasource.
47
- */
48
- constructor(options) {
49
- super();
50
-
51
- if (isObject(options)) {
52
- this.setOptions(options);
53
- }
54
- }
55
-
56
- /**
57
- * This method is called by the `instanceof` operator.
58
- * @return {symbol}
59
- * @since 2.1.0
60
- */
61
- static get [instanceSymbol]() {
62
- return Symbol.for("@schukai/monster/data/datasource/server/restapi");
63
- }
64
-
65
- /**
66
- * @property {Object} write={} Options
67
- * @property {Object} write.init={} An option 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}
68
- * @property {string} write.init.method=POST
69
- * @property {Object} write.init.headers Object containing any custom headers that you want to apply to the request.
70
- * @property {string} write.responseCallback Callback function to be executed after the request has been completed.
71
- * @property {string} write.acceptedStatus=[200,201]
72
- * @property {string} write.url URL
73
- * @property {Object} write.mapping the mapping is applied before writing.
74
- * @property {String} write.mapping.transformer Transformer to select the appropriate entries
75
- * @property {exampleCallback[]} write.mapping.callback with the help of the callback, the structures can be adjusted before writing.
76
- * @property {Object} write.report
77
- * @property {String} write.report.path Path to validations
78
- * @property {Object} write.partial
79
- * @property {Function} write.partial.callback Callback function to be executed after the request has been completed. (obj, diffResult) => obj
80
- * @property {Object} write.sheathing
81
- * @property {Object} write.sheathing.object Object to be wrapped
82
- * @property {string} write.sheathing.path Path to the data
83
- * @property {Object} read={} Options
84
- * @property {Object} read.init={} An option 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}
85
- * @property {string} read.init.method=GET
86
- * @property {array} read.acceptedStatus=[200]
87
- * @property {string} read.url URL
88
- * @property {Object} read.mapping the mapping is applied after reading.
89
- * @property {String} read.mapping.transformer Transformer to select the appropriate entries
90
- * @property {exampleCallback[]} read.mapping.callback with the help of the callback, the structures can be adjusted after reading.
91
- */
92
- get defaults() {
93
- return Object.assign({}, super.defaults, {
94
- write: {
95
- init: {
96
- method: "POST",
97
- headers: null,
98
- },
99
- responseCallback: null,
100
- acceptedStatus: [200, 201],
101
- url: null,
102
- mapping: {
103
- transformer: null,
104
- callbacks: [],
105
- },
106
- sheathing: {
107
- object: null,
108
- path: null,
109
- },
110
- report: {
111
- path: null,
112
- },
113
-
114
- partial: {
115
- callback: null,
116
- },
117
- },
118
- read: {
119
- init: {
120
- method: "GET",
121
- headers: null,
122
- },
123
- path: null,
124
- responseCallback: null,
125
- acceptedStatus: [200],
126
- url: null,
127
- mapping: {
128
- transformer: null,
129
- callbacks: [],
130
- },
131
- },
132
- });
133
- }
134
-
135
- /**
136
- * @return {Promise}
137
- * @throws {Error} the options does not contain a valid json definition
138
- * @throws {TypeError} value is not a object
139
- * @throws {Error} the data cannot be read
140
- */
141
- read() {
142
- let init = this.getOption("read.init");
143
- if (!isObject(init)) init = {};
144
- if (!init["method"]) init["method"] = "GET";
145
- if (typeof init["headers"] !== "object") {
146
- init["headers"] = {
147
- "Accept": "application/json",
148
- };
149
- }
150
-
151
- let callback = this.getOption("read.responseCallback");
152
- if (!callback) {
153
- callback = (obj) => {
154
- this.set(this.transformServerPayload.call(this, obj));
155
- };
156
- }
157
-
158
- return fetchData.call(this, init, "read", callback);
159
- }
160
-
161
- /**
162
- * @return {Promise}
163
- * @throws {WriteError} the data cannot be written
164
- */
165
- write() {
166
- let init = this.getOption("write.init");
167
- if (!isObject(init)) init = {};
168
- if (typeof init["headers"] !== "object") {
169
- init["headers"] = {
170
- "Content-Type": "application/json",
171
- "Accept": "application/json",
172
- };
173
- }
174
- if (!init["method"]) init["method"] = "POST";
175
-
176
- const obj = this.prepareServerPayload(this.get());
177
- init["body"] = JSON.stringify(obj);
178
-
179
- const callback = this.getOption("write.responseCallback");
180
- return fetchData.call(this, init, "write", callback);
181
- }
182
-
183
- /**
184
- * @return {RestAPI}
185
- */
186
- getClone() {
187
- const api = new RestAPI();
188
-
189
- const read = clone(this[internalSymbol].getRealSubject()["options"].read);
190
- const write = clone(this[internalSymbol].getRealSubject()["options"].write);
191
-
192
- api.setOption("read", read);
193
- api.setOption("write", write);
194
-
195
- return api;
196
- }
44
+ /**
45
+ *
46
+ * @param {Object} [options] options contains definitions for the datasource.
47
+ */
48
+ constructor(options) {
49
+ super();
50
+
51
+ if (isObject(options)) {
52
+ this.setOptions(options);
53
+ }
54
+ }
55
+
56
+ /**
57
+ * This method is called by the `instanceof` operator.
58
+ * @return {symbol}
59
+ * @since 2.1.0
60
+ */
61
+ static get [instanceSymbol]() {
62
+ return Symbol.for("@schukai/monster/data/datasource/server/restapi");
63
+ }
64
+
65
+ /**
66
+ * @property {Object} write={} Options
67
+ * @property {Object} write.init={} An option 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}
68
+ * @property {string} write.init.method=POST
69
+ * @property {Headers} write.init.headers Object containing any custom headers that you want to apply to the request.
70
+ * @property {string} write.responseCallback Callback function to be executed after the request has been completed.
71
+ * @property {string} write.acceptedStatus=[200,201]
72
+ * @property {string} write.url URL
73
+ * @property {Object} write.mapping the mapping is applied before writing.
74
+ * @property {String} write.mapping.transformer Transformer to select the appropriate entries
75
+ * @property {exampleCallback[]} write.mapping.callback with the help of the callback, the structures can be adjusted before writing.
76
+ * @property {Object} write.report
77
+ * @property {String} write.report.path Path to validations
78
+ * @property {Object} write.partial
79
+ * @property {Function} write.partial.callback Callback function to be executed after the request has been completed. (obj, diffResult) => obj
80
+ * @property {Object} write.sheathing
81
+ * @property {Object} write.sheathing.object Object to be wrapped
82
+ * @property {string} write.sheathing.path Path to the data
83
+ * @property {Object} read={} Options
84
+ * @property {Object} read.init={} An option 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}
85
+ * @property {string} read.init.method=GET
86
+ * @property {array} read.acceptedStatus=[200]
87
+ * @property {string} read.url URL
88
+ * @property {Object} read.mapping the mapping is applied after reading.
89
+ * @property {String} read.mapping.transformer Transformer to select the appropriate entries
90
+ * @property {exampleCallback[]} read.mapping.callback with the help of the callback, the structures can be adjusted after reading.
91
+ */
92
+ get defaults() {
93
+ return Object.assign({}, super.defaults, {
94
+ write: {
95
+ init: {
96
+ method: "POST",
97
+ headers: null,
98
+ },
99
+ responseCallback: null,
100
+ acceptedStatus: [200, 201],
101
+ url: null,
102
+ mapping: {
103
+ transformer: null,
104
+ callbacks: [],
105
+ },
106
+ sheathing: {
107
+ object: null,
108
+ path: null,
109
+ },
110
+ report: {
111
+ path: null,
112
+ },
113
+
114
+ partial: {
115
+ callback: null,
116
+ },
117
+ },
118
+ read: {
119
+ init: {
120
+ method: "GET",
121
+ headers: null,
122
+ },
123
+ path: null,
124
+ responseCallback: null,
125
+ acceptedStatus: [200],
126
+ url: null,
127
+ mapping: {
128
+ transformer: null,
129
+ callbacks: [],
130
+ },
131
+ },
132
+ });
133
+ }
134
+
135
+ /**
136
+ * @return {Promise}
137
+ * @throws {Error} the options does not contain a valid json definition
138
+ * @throws {TypeError} value is not a object
139
+ * @throws {Error} the data cannot be read
140
+ */
141
+ read() {
142
+ let init = this.getOption("read.init");
143
+ if (!isObject(init)) init = {};
144
+ if (!(init["headers"] instanceof Headers)) {
145
+ init["headers"] = new Headers();
146
+ init["headers"].append("Accept", "application/json");
147
+ init["headers"].append("X-Requested-With", "XMLHttpRequest");
148
+ }
149
+
150
+ if (!init["method"]) init["method"] = "GET";
151
+
152
+ let callback = this.getOption("read.responseCallback");
153
+ if (!callback) {
154
+ callback = (obj) => {
155
+ this.set(this.transformServerPayload.call(this, obj));
156
+ };
157
+ }
158
+
159
+ return fetchData.call(this, init, "read", callback);
160
+ }
161
+
162
+ /**
163
+ * @return {Promise}
164
+ * @throws {WriteError} the data cannot be written
165
+ */
166
+ write() {
167
+ let init = this.getOption("write.init");
168
+ if (!isObject(init)) init = {};
169
+ if (!(init["headers"] instanceof Headers)) {
170
+ init["headers"] = new Headers();
171
+ init["headers"].append("Accept", "application/json");
172
+ init["headers"].append("Content-Type", "application/json");
173
+ }
174
+ if (!init["method"]) init["method"] = "POST";
175
+
176
+ const obj = this.prepareServerPayload(this.get());
177
+ init["body"] = JSON.stringify(obj);
178
+
179
+ const callback = this.getOption("write.responseCallback");
180
+ return fetchData.call(this, init, "write", callback);
181
+ }
182
+
183
+ /**
184
+ * @return {RestAPI}
185
+ */
186
+ getClone() {
187
+ const api = new RestAPI();
188
+
189
+ const read = clone(this[internalSymbol].getRealSubject()["options"].read);
190
+ const write = clone(this[internalSymbol].getRealSubject()["options"].write);
191
+
192
+ api.setOption("read", read);
193
+ api.setOption("write", write);
194
+
195
+ return api;
196
+ }
197
197
  }
198
198
 
199
199
  /**
@@ -204,49 +204,49 @@ class RestAPI extends Server {
204
204
  * @return {Promise<string>}
205
205
  */
206
206
  function fetchData(init, key, callback) {
207
- let response;
208
-
209
- return fetch(this.getOption(`${key}.url`), init)
210
- .then((resp) => {
211
- response = resp;
212
-
213
- const acceptedStatus = this.getOption(`${key}.acceptedStatus`, [200]).map(
214
- Number,
215
- );
216
-
217
- if (acceptedStatus.indexOf(resp.status) === -1) {
218
- throw new DataFetchError(
219
- `the response does not contain an accepted status (actual: ${resp.status}).`,
220
- response,
221
- );
222
- }
223
-
224
- return resp.text();
225
- })
226
- .then((body) => {
227
- let obj;
228
-
229
- try {
230
- obj = JSON.parse(body);
231
-
232
- response[rawDataSymbol] = obj;
233
- } catch (e) {
234
- if (body.length > 100) {
235
- body = `${body.substring(0, 97)}...`;
236
- }
237
-
238
- throw new DataFetchError(
239
- `the response does not contain a valid json (actual: ${body}).`,
240
- response,
241
- );
242
- }
243
-
244
- if (callback && isFunction(callback)) {
245
- callback(obj);
246
- }
247
- return response;
248
- })
249
- .catch((e) => {
250
- throw e;
251
- });
207
+ let response;
208
+
209
+ return fetch(this.getOption(`${key}.url`), init)
210
+ .then((resp) => {
211
+ response = resp;
212
+
213
+ const acceptedStatus = this.getOption(`${key}.acceptedStatus`, [200]).map(
214
+ Number,
215
+ );
216
+
217
+ if (acceptedStatus.indexOf(resp.status) === -1) {
218
+ throw new DataFetchError(
219
+ `the response does not contain an accepted status (actual: ${resp.status}).`,
220
+ response,
221
+ );
222
+ }
223
+
224
+ return resp.text();
225
+ })
226
+ .then((body) => {
227
+ let obj;
228
+
229
+ try {
230
+ obj = JSON.parse(body);
231
+
232
+ response[rawDataSymbol] = obj;
233
+ } catch (e) {
234
+ if (body.length > 100) {
235
+ body = `${body.substring(0, 97)}...`;
236
+ }
237
+
238
+ throw new DataFetchError(
239
+ `the response does not contain a valid json (actual: ${body}).`,
240
+ response,
241
+ );
242
+ }
243
+
244
+ if (callback && isFunction(callback)) {
245
+ callback(obj);
246
+ }
247
+ return response;
248
+ })
249
+ .catch((e) => {
250
+ throw e;
251
+ });
252
252
  }
@@ -156,7 +156,7 @@ function getMonsterVersion() {
156
156
  }
157
157
 
158
158
  /** don't touch, replaced by make with package.json version */
159
- monsterVersion = new Version("3.99.7");
159
+ monsterVersion = new Version("3.100.17");
160
160
 
161
161
  return monsterVersion;
162
162
  }
@@ -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.99.7")
10
+ monsterVersion = new Version("3.100.17")
11
11
 
12
12
  let m = getMonsterVersion();
13
13
 
@@ -9,8 +9,8 @@
9
9
  </head>
10
10
  <body>
11
11
  <div id="headline" style="display: flex;align-items: center;justify-content: center;flex-direction: column;">
12
- <h1 style='margin-bottom: 0.1em;'>Monster 3.99.7</h1>
13
- <div id="lastupdate" style='font-size:0.7em'>last update So 12. Jan 16:32:45 CET 2025</div>
12
+ <h1 style='margin-bottom: 0.1em;'>Monster 3.100.17</h1>
13
+ <div id="lastupdate" style='font-size:0.7em'>last update Di 21. Jan 00:44:02 CET 2025</div>
14
14
  </div>
15
15
  <div id="mocha-errors"
16
16
  style="color: red;font-weight: bold;display: flex;align-items: center;justify-content: center;flex-direction: column;margin:20px;"></div>