@schukai/monster 3.71.2 → 3.72.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.
Files changed (117) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/package.json +1 -1
  3. package/source/components/datatable/dataset.mjs +272 -272
  4. package/source/components/datatable/datasource/dom.mjs +1 -1
  5. package/source/components/datatable/datasource/rest.mjs +408 -410
  6. package/source/components/datatable/filter.mjs +0 -1
  7. package/source/components/datatable/style/datatable.pcss +7 -5
  8. package/source/components/datatable/style/embedded-pagination.pcss +1 -1
  9. package/source/components/datatable/style/pagination.pcss +1 -1
  10. package/source/components/datatable/stylesheet/change-button.mjs +2 -4
  11. package/source/components/datatable/stylesheet/column-bar.mjs +2 -4
  12. package/source/components/datatable/stylesheet/dataset.mjs +2 -4
  13. package/source/components/datatable/stylesheet/datasource.mjs +1 -3
  14. package/source/components/datatable/stylesheet/datatable.mjs +2 -4
  15. package/source/components/datatable/stylesheet/embedded-pagination.mjs +1 -1
  16. package/source/components/datatable/stylesheet/filter-button.mjs +1 -3
  17. package/source/components/datatable/stylesheet/filter-controls-defaults.mjs +14 -7
  18. package/source/components/datatable/stylesheet/filter-date-range.mjs +1 -3
  19. package/source/components/datatable/stylesheet/filter-range.mjs +1 -3
  20. package/source/components/datatable/stylesheet/filter.mjs +2 -4
  21. package/source/components/datatable/stylesheet/pagination.mjs +2 -4
  22. package/source/components/datatable/stylesheet/save-button.mjs +2 -4
  23. package/source/components/datatable/stylesheet/select-filter.mjs +2 -4
  24. package/source/components/datatable/stylesheet/status.mjs +2 -4
  25. package/source/components/form/context-error.mjs +0 -2
  26. package/source/components/form/context-help.mjs +1 -2
  27. package/source/components/form/field-set.mjs +219 -219
  28. package/source/components/form/form.mjs +137 -187
  29. package/source/components/form/reload.mjs +211 -211
  30. package/source/components/form/select.mjs +12 -13
  31. package/source/components/form/style/field-set.pcss +2 -2
  32. package/source/components/form/style/form.pcss +8 -0
  33. package/source/components/form/stylesheet/action-button.mjs +2 -4
  34. package/source/components/form/stylesheet/api-button.mjs +1 -3
  35. package/source/components/form/stylesheet/button-bar.mjs +2 -4
  36. package/source/components/form/stylesheet/button.mjs +2 -4
  37. package/source/components/form/stylesheet/confirm-button.mjs +2 -4
  38. package/source/components/form/stylesheet/context-error.mjs +2 -4
  39. package/source/components/form/stylesheet/context-help.mjs +2 -4
  40. package/source/components/form/stylesheet/field-set.mjs +14 -7
  41. package/source/components/form/stylesheet/form.mjs +1 -1
  42. package/source/components/form/stylesheet/message-state-button.mjs +1 -3
  43. package/source/components/form/stylesheet/popper-button.mjs +2 -4
  44. package/source/components/form/stylesheet/select.mjs +14 -7
  45. package/source/components/form/stylesheet/state-button.mjs +2 -4
  46. package/source/components/form/stylesheet/tree-select.mjs +1 -3
  47. package/source/components/host/stylesheet/call-button.mjs +2 -4
  48. package/source/components/host/stylesheet/config-manager.mjs +1 -3
  49. package/source/components/host/stylesheet/host.mjs +2 -4
  50. package/source/components/host/stylesheet/overlay.mjs +2 -4
  51. package/source/components/host/stylesheet/toggle-button.mjs +2 -4
  52. package/source/components/host/stylesheet/viewer.mjs +2 -4
  53. package/source/components/layout/style/collapse.pcss +2 -2
  54. package/source/components/layout/style/details.pcss +2 -2
  55. package/source/components/layout/stylesheet/collapse.mjs +14 -7
  56. package/source/components/layout/stylesheet/details.mjs +2 -4
  57. package/source/components/layout/stylesheet/panel.mjs +2 -4
  58. package/source/components/layout/stylesheet/popper.mjs +2 -4
  59. package/source/components/layout/stylesheet/split-panel.mjs +1 -3
  60. package/source/components/layout/stylesheet/tabs.mjs +2 -4
  61. package/source/components/layout/stylesheet/width-toggle.mjs +1 -3
  62. package/source/components/navigation/stylesheet/table-of-content.mjs +2 -4
  63. package/source/components/notify/stylesheet/message.mjs +2 -4
  64. package/source/components/notify/stylesheet/notify.mjs +2 -4
  65. package/source/components/state/stylesheet/log.mjs +2 -4
  66. package/source/components/state/stylesheet/state.mjs +2 -4
  67. package/source/components/style/control.pcss +5 -0
  68. package/source/components/style/data-grid.pcss +2 -2
  69. package/source/components/style/mixin/typography.pcss +7 -1
  70. package/source/components/style/normalize.pcss +1 -1
  71. package/source/components/stylesheet/badge.mjs +1 -3
  72. package/source/components/stylesheet/border.mjs +1 -3
  73. package/source/components/stylesheet/button.mjs +1 -3
  74. package/source/components/stylesheet/card.mjs +1 -3
  75. package/source/components/stylesheet/color.mjs +1 -3
  76. package/source/components/stylesheet/common.mjs +1 -3
  77. package/source/components/stylesheet/control.mjs +2 -4
  78. package/source/components/stylesheet/data-grid.mjs +2 -4
  79. package/source/components/stylesheet/display.mjs +1 -3
  80. package/source/components/stylesheet/floating-ui.mjs +1 -3
  81. package/source/components/stylesheet/form.mjs +13 -6
  82. package/source/components/stylesheet/host.mjs +1 -3
  83. package/source/components/stylesheet/icons.mjs +1 -3
  84. package/source/components/stylesheet/mixin/badge.mjs +1 -3
  85. package/source/components/stylesheet/mixin/button.mjs +1 -3
  86. package/source/components/stylesheet/mixin/form.mjs +13 -6
  87. package/source/components/stylesheet/mixin/hover.mjs +1 -3
  88. package/source/components/stylesheet/mixin/icon.mjs +1 -3
  89. package/source/components/stylesheet/mixin/media.mjs +1 -3
  90. package/source/components/stylesheet/mixin/property.mjs +13 -6
  91. package/source/components/stylesheet/mixin/skeleton.mjs +1 -3
  92. package/source/components/stylesheet/mixin/spinner.mjs +1 -3
  93. package/source/components/stylesheet/mixin/typography.mjs +1 -3
  94. package/source/components/stylesheet/normalize.mjs +1 -3
  95. package/source/components/stylesheet/popper.mjs +1 -3
  96. package/source/components/stylesheet/property.mjs +2 -4
  97. package/source/components/stylesheet/ripple.mjs +1 -3
  98. package/source/components/stylesheet/skeleton.mjs +1 -3
  99. package/source/components/stylesheet/space.mjs +1 -3
  100. package/source/components/stylesheet/spinner.mjs +1 -3
  101. package/source/components/stylesheet/table.mjs +1 -3
  102. package/source/components/stylesheet/theme.mjs +1 -3
  103. package/source/components/stylesheet/typography.mjs +13 -6
  104. package/source/components/tree-menu/dragable-tree-menu.mjs +693 -0
  105. package/source/components/tree-menu/style/tree-menu.pcss +69 -42
  106. package/source/components/tree-menu/stylesheet/tree-menu.mjs +8 -17
  107. package/source/components/tree-menu/tree-menu.mjs +468 -532
  108. package/source/data/datasource/server/restapi.mjs +194 -191
  109. package/source/data/datasource/server.mjs +107 -105
  110. package/source/data/diff.mjs +1 -1
  111. package/source/dom/customelement.mjs +2 -6
  112. package/source/dom/slotted.mjs +89 -85
  113. package/test/cases/components/host/details.mjs +1 -1
  114. package/test/cases/components/host/host.mjs +1 -1
  115. package/test/cases/components/host/overlay.mjs +1 -1
  116. package/test/cases/dom/customcontrol.mjs +1 -1
  117. package/test/cases/dom/customelement.mjs +2 -2
@@ -12,14 +12,14 @@
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";
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
21
 
22
- export {RestAPI};
22
+ export { RestAPI };
23
23
 
24
24
  /**
25
25
  * @type {symbol}
@@ -28,10 +28,9 @@ 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
-
35
34
  /**
36
35
  * The RestAPI is a class that enables a REST API server.
37
36
  *
@@ -43,145 +42,146 @@ const rawDataSymbol = Symbol.for(
43
42
  * @summary The RestAPI is a class that binds a REST API server.
44
43
  */
45
44
  class RestAPI extends Server {
46
- /**
47
- *
48
- * @param {Object} [options] options contains definitions for the datasource.
49
- */
50
- constructor(options) {
51
- super();
52
-
53
- if (isObject(options)) {
54
- this.setOptions(options);
55
- }
56
- }
57
-
58
- /**
59
- * This method is called by the `instanceof` operator.
60
- * @returns {symbol}
61
- * @since 2.1.0
62
- */
63
- static get [instanceSymbol]() {
64
- return Symbol.for("@schukai/monster/data/datasource/server/restapi");
65
- }
66
-
67
- /**
68
- * @property {Object} write={} Options
69
- * @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}
70
- * @property {string} write.init.method=POST
71
- * @property {Object} write.init.headers Object containing any custom headers that you want to apply to the request.
72
- * @property {string} write.responseCallback Callback function to be executed after the request has been completed.
73
- * @property {string} write.acceptedStatus=[200,201]
74
- * @property {string} write.url URL
75
- * @property {Object} write.mapping the mapping is applied before writing.
76
- * @property {String} write.mapping.transformer Transformer to select the appropriate entries
77
- * @property {Monster.Data.Datasource~exampleCallback[]} write.mapping.callback with the help of the callback, the structures can be adjusted before writing.
78
- * @property {Object} write.report
79
- * @property {String} write.report.path Path to validations
80
- * @property {Object} write.partial
81
- * @property {Function} write.partial.callback Callback function to be executed after the request has been completed. (obj, diffResult) => obj
82
- * @property {Object} write.sheathing
83
- * @property {Object} write.sheathing.object Object to be wrapped
84
- * @property {string} write.sheathing.path Path to the data
85
- * @property {Object} read={} Options
86
- * @property {Object} read.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}
87
- * @property {string} read.init.method=GET
88
- * @property {string} read.acceptedStatus=[200]
89
- * @property {string} read.url URL
90
- * @property {Object} read.mapping the mapping is applied after reading.
91
- * @property {String} read.mapping.transformer Transformer to select the appropriate entries
92
- * @property {Monster.Data.Datasource~exampleCallback[]} read.mapping.callback with the help of the callback, the structures can be adjusted after reading.
93
- */
94
- get defaults() {
95
- return Object.assign({}, super.defaults, {
96
- write: {
97
- init: {
98
- method: "POST",
99
- },
100
- responseCallback: undefined,
101
- acceptedStatus: [200, 201],
102
- url: null,
103
- mapping: {
104
- transformer: undefined,
105
- callbacks: [],
106
- },
107
- sheathing: {
108
- object: undefined,
109
- path: undefined,
110
- },
111
- report: {
112
- path: undefined,
113
- },
114
-
115
- partial: {
116
- callback: null,
117
- }
118
- },
119
- read: {
120
- init: {
121
- method: "GET",
122
- },
123
- responseCallback: undefined,
124
- acceptedStatus: [200],
125
- url: null,
126
- mapping: {
127
- transformer: undefined,
128
- callbacks: [],
129
- },
130
- },
131
- });
132
- }
133
-
134
- /**
135
- * @return {Promise}
136
- * @throws {Error} the options does not contain a valid json definition
137
- * @throws {TypeError} value is not a object
138
- * @throws {Error} the data cannot be read
139
- */
140
- read() {
141
- let init = this.getOption("read.init");
142
- if (!isObject(init)) init = {};
143
- if (!init["method"]) init["method"] = "GET";
144
-
145
- let callback = this.getOption("read.responseCallback");
146
- if (!callback) {
147
- callback = (obj) => {
148
- this.set(this.transformServerPayload.call(this, obj));
149
- };
150
- }
151
-
152
- return fetchData.call(this, init, "read", callback);
153
- }
154
-
155
- /**
156
- * @return {Promise}
157
- * @throws {WriteError} the data cannot be written
158
- */
159
- write() {
160
- let init = this.getOption("write.init");
161
- if (!isObject(init)) init = {};
162
- if (typeof init["headers"] !== "object") {
163
- init["headers"] = {
164
- "Content-Type": "application/json",
165
- };
166
- }
167
- if (!init["method"]) init["method"] = "POST";
168
-
169
- const obj = this.prepareServerPayload(this.get());
170
- init["body"] = JSON.stringify(obj);
171
-
172
- const callback = this.getOption("write.responseCallback");
173
- return fetchData.call(this, init, "write", callback);
174
- }
175
-
176
- /**
177
- * @return {RestAPI}
178
- */
179
- getClone() {
180
- return new RestAPI(
181
- this[internalSymbol].getRealSubject()["options"].read,
182
- this[internalSymbol].getRealSubject()["options"].write,
183
- );
184
- }
45
+ /**
46
+ *
47
+ * @param {Object} [options] options contains definitions for the datasource.
48
+ */
49
+ constructor(options) {
50
+ super();
51
+
52
+ if (isObject(options)) {
53
+ this.setOptions(options);
54
+ }
55
+ }
56
+
57
+ /**
58
+ * This method is called by the `instanceof` operator.
59
+ * @returns {symbol}
60
+ * @since 2.1.0
61
+ */
62
+ static get [instanceSymbol]() {
63
+ return Symbol.for("@schukai/monster/data/datasource/server/restapi");
64
+ }
65
+
66
+ /**
67
+ * @property {Object} write={} Options
68
+ * @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}
69
+ * @property {string} write.init.method=POST
70
+ * @property {Object} write.init.headers Object containing any custom headers that you want to apply to the request.
71
+ * @property {string} write.responseCallback Callback function to be executed after the request has been completed.
72
+ * @property {string} write.acceptedStatus=[200,201]
73
+ * @property {string} write.url URL
74
+ * @property {Object} write.mapping the mapping is applied before writing.
75
+ * @property {String} write.mapping.transformer Transformer to select the appropriate entries
76
+ * @property {Monster.Data.Datasource~exampleCallback[]} write.mapping.callback with the help of the callback, the structures can be adjusted before writing.
77
+ * @property {Object} write.report
78
+ * @property {String} write.report.path Path to validations
79
+ * @property {Object} write.partial
80
+ * @property {Function} write.partial.callback Callback function to be executed after the request has been completed. (obj, diffResult) => obj
81
+ * @property {Object} write.sheathing
82
+ * @property {Object} write.sheathing.object Object to be wrapped
83
+ * @property {string} write.sheathing.path Path to the data
84
+ * @property {Object} read={} Options
85
+ * @property {Object} read.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}
86
+ * @property {string} read.init.method=GET
87
+ * @property {string} read.acceptedStatus=[200]
88
+ * @property {string} read.url URL
89
+ * @property {Object} read.mapping the mapping is applied after reading.
90
+ * @property {String} read.mapping.transformer Transformer to select the appropriate entries
91
+ * @property {Monster.Data.Datasource~exampleCallback[]} read.mapping.callback with the help of the callback, the structures can be adjusted after reading.
92
+ */
93
+ get defaults() {
94
+ return Object.assign({}, super.defaults, {
95
+ write: {
96
+ init: {
97
+ method: "POST",
98
+ },
99
+ responseCallback: undefined,
100
+ acceptedStatus: [200, 201],
101
+ url: null,
102
+ mapping: {
103
+ transformer: undefined,
104
+ callbacks: [],
105
+ },
106
+ sheathing: {
107
+ object: undefined,
108
+ path: undefined,
109
+ },
110
+ report: {
111
+ path: undefined,
112
+ },
113
+
114
+ partial: {
115
+ callback: null,
116
+ },
117
+ },
118
+ read: {
119
+ init: {
120
+ method: "GET",
121
+ },
122
+ path: null,
123
+ responseCallback: undefined,
124
+ acceptedStatus: [200],
125
+ url: null,
126
+ mapping: {
127
+ transformer: undefined,
128
+ callbacks: [],
129
+ },
130
+ },
131
+ });
132
+ }
133
+
134
+ /**
135
+ * @return {Promise}
136
+ * @throws {Error} the options does not contain a valid json definition
137
+ * @throws {TypeError} value is not a object
138
+ * @throws {Error} the data cannot be read
139
+ */
140
+ read() {
141
+ let init = this.getOption("read.init");
142
+ if (!isObject(init)) init = {};
143
+ if (!init["method"]) init["method"] = "GET";
144
+
145
+ let callback = this.getOption("read.responseCallback");
146
+ if (!callback) {
147
+ callback = (obj) => {
148
+ this.set(this.transformServerPayload.call(this, obj));
149
+ };
150
+ }
151
+
152
+ return fetchData.call(this, init, "read", callback);
153
+ }
154
+
155
+ /**
156
+ * @return {Promise}
157
+ * @throws {WriteError} the data cannot be written
158
+ */
159
+ write() {
160
+ let init = this.getOption("write.init");
161
+ if (!isObject(init)) init = {};
162
+ if (typeof init["headers"] !== "object") {
163
+ init["headers"] = {
164
+ "Content-Type": "application/json",
165
+ };
166
+ }
167
+ if (!init["method"]) init["method"] = "POST";
168
+
169
+ const obj = this.prepareServerPayload(this.get());
170
+ init["body"] = JSON.stringify(obj);
171
+
172
+ const callback = this.getOption("write.responseCallback");
173
+ return fetchData.call(this, init, "write", callback);
174
+ }
175
+
176
+ /**
177
+ * @return {RestAPI}
178
+ */
179
+ getClone() {
180
+ return new RestAPI(
181
+ this[internalSymbol].getRealSubject()["options"].read,
182
+ this[internalSymbol].getRealSubject()["options"].write,
183
+ );
184
+ }
185
185
  }
186
186
 
187
187
  /**
@@ -192,47 +192,50 @@ class RestAPI extends Server {
192
192
  * @returns {Promise<string>}
193
193
  */
194
194
  function fetchData(init, key, callback) {
195
- let response;
196
-
197
- return fetch(this.getOption(`${key}.url`), init)
198
- .then((resp) => {
199
- response = resp;
200
-
201
- const acceptedStatus = this.getOption(`${key}.acceptedStatus`, [200]).map(Number);
202
-
203
- if (acceptedStatus.indexOf(resp.status) === -1) {
204
- throw new DataFetchError(
205
- `the response does not contain an accepted status (actual: ${resp.status}).`,
206
- response,
207
- );
208
- }
209
-
210
- return resp.text();
211
- })
212
- .then((body) => {
213
- let obj;
214
-
215
- try {
216
- obj = JSON.parse(body);
217
-
218
- response[rawDataSymbol] = obj;
219
- } catch (e) {
220
- if (body.length > 100) {
221
- body = `${body.substring(0, 97)}...`;
222
- }
223
-
224
- throw new DataFetchError(
225
- `the response does not contain a valid json (actual: ${body}).`,
226
- response,
227
- );
228
- }
229
-
230
- if (callback && isFunction(callback)) {
231
- callback(obj);
232
- }
233
-
234
- return response;
235
- }).catch((e) => {
236
- throw e;
237
- });
195
+ let response;
196
+
197
+ return fetch(this.getOption(`${key}.url`), init)
198
+ .then((resp) => {
199
+ response = resp;
200
+
201
+ const acceptedStatus = this.getOption(`${key}.acceptedStatus`, [200]).map(
202
+ Number,
203
+ );
204
+
205
+ if (acceptedStatus.indexOf(resp.status) === -1) {
206
+ throw new DataFetchError(
207
+ `the response does not contain an accepted status (actual: ${resp.status}).`,
208
+ response,
209
+ );
210
+ }
211
+
212
+ return resp.text();
213
+ })
214
+ .then((body) => {
215
+ let obj;
216
+
217
+ try {
218
+ obj = JSON.parse(body);
219
+
220
+ response[rawDataSymbol] = obj;
221
+ } catch (e) {
222
+ if (body.length > 100) {
223
+ body = `${body.substring(0, 97)}...`;
224
+ }
225
+
226
+ throw new DataFetchError(
227
+ `the response does not contain a valid json (actual: ${body}).`,
228
+ response,
229
+ );
230
+ }
231
+
232
+ if (callback && isFunction(callback)) {
233
+ callback(obj);
234
+ }
235
+
236
+ return response;
237
+ })
238
+ .catch((e) => {
239
+ throw e;
240
+ });
238
241
  }
@@ -12,15 +12,14 @@
12
12
  * SPDX-License-Identifier: AGPL-3.0
13
13
  */
14
14
 
15
- import {instanceSymbol} from "../../constants.mjs";
16
- import {isArray, isFunction, isObject} from "../../types/is.mjs";
17
- import {Datasource} from "../datasource.mjs";
18
- import {diff} from "../diff.mjs";
19
- import {Pathfinder} from "../pathfinder.mjs";
20
- import {Pipe} from "../pipe.mjs";
21
-
22
- export {Server};
15
+ import { instanceSymbol } from "../../constants.mjs";
16
+ import { isArray, isFunction, isObject } from "../../types/is.mjs";
17
+ import { Datasource } from "../datasource.mjs";
18
+ import { diff } from "../diff.mjs";
19
+ import { Pathfinder } from "../pathfinder.mjs";
20
+ import { Pipe } from "../pipe.mjs";
23
21
 
22
+ export { Server };
24
23
 
25
24
  /**
26
25
  * @private
@@ -38,82 +37,85 @@ const serverVersionSymbol = Symbol("serverVersion");
38
37
  * @summary The Server class encapsulates the access to a server datasource
39
38
  */
40
39
  class Server extends Datasource {
41
- /**
42
- * This method is called by the `instanceof` operator.
43
- * @returns {symbol}
44
- */
45
- static get [instanceSymbol]() {
46
- return Symbol.for("@schukai/monster/data/datasource/server");
47
- }
48
-
49
- /**
50
- * This prepares the data that comes from the server.
51
- * Should not be called directly.
52
- *
53
- * @private
54
- * @param {Object} payload
55
- * @returns {Object}
56
- */
57
- transformServerPayload(payload) {
58
- payload = doTransform.call(this, "read", payload);
59
- this[serverVersionSymbol] = payload;
60
-
61
- const dataPath = this.getOption("read.path");
62
- if (dataPath) {
63
- payload = new Pathfinder(payload).getVia(dataPath);
64
- }
65
-
66
- return payload;
67
- }
68
-
69
- /**
70
- * This prepares the data for writing and should not be called directly.
71
- *
72
- * @private
73
- * @param {Object} payload
74
- * @returns {Object}
75
- */
76
- prepareServerPayload(payload) {
77
- payload = doTransform.call(this, "write", payload);
78
- payload = doDiff.call(this, payload);
79
-
80
- const sheathingObject = this.getOption("write.sheathing.object");
81
- const sheathingPath = this.getOption("write.sheathing.path");
82
-
83
- if (sheathingObject && sheathingPath) {
84
- const sub = payload;
85
- payload = sheathingObject;
86
- new Pathfinder(payload).setVia(sheathingPath, sub);
87
- }
88
-
89
- return payload;
90
- }
40
+ /**
41
+ * This method is called by the `instanceof` operator.
42
+ * @returns {symbol}
43
+ */
44
+ static get [instanceSymbol]() {
45
+ return Symbol.for("@schukai/monster/data/datasource/server");
46
+ }
47
+
48
+ /**
49
+ * This prepares the data that comes from the server.
50
+ * Should not be called directly.
51
+ *
52
+ * @private
53
+ * @param {Object} payload
54
+ * @returns {Object}
55
+ */
56
+ transformServerPayload(payload) {
57
+ payload = doTransform.call(this, "read", payload);
58
+ this[serverVersionSymbol] = payload;
59
+
60
+ const dataPath = this.getOption("read.path");
61
+ if (dataPath) {
62
+ payload = new Pathfinder(payload).getVia(dataPath);
63
+ }
64
+
65
+ return payload;
66
+ }
67
+
68
+ /**
69
+ * This prepares the data for writing and should not be called directly.
70
+ *
71
+ * @private
72
+ * @param {Object} payload
73
+ * @returns {Object}
74
+ */
75
+ prepareServerPayload(payload) {
76
+ payload = doTransform.call(this, "write", payload);
77
+ payload = doDiff.call(this, payload);
78
+
79
+ const sheathingObject = this.getOption("write.sheathing.object");
80
+ const sheathingPath = this.getOption("write.sheathing.path");
81
+
82
+ if (sheathingObject && sheathingPath) {
83
+ const sub = payload;
84
+ payload = sheathingObject;
85
+ new Pathfinder(payload).setVia(sheathingPath, sub);
86
+ }
87
+
88
+ return payload;
89
+ }
91
90
  }
92
91
 
93
92
  /**
94
- *
93
+ *
95
94
  * @param obj
96
95
  * @returns {*}
97
96
  */
98
97
  function doDiff(obj) {
99
- if (this[serverVersionSymbol] === null || this[serverVersionSymbol] === undefined) {
100
- return obj;
101
- }
102
-
103
- const callback = this.getOption("write.partial.callback");
104
- if (!isFunction(callback)) {
105
- return obj;
106
- }
107
-
108
- const results = diff(this[serverVersionSymbol], obj);
109
- if (!results) {
110
- return obj;
111
- }
112
-
113
- obj = callback(obj, results);
114
- this[serverVersionSymbol] = obj;
115
-
116
- return obj;
98
+ if (
99
+ this[serverVersionSymbol] === null ||
100
+ this[serverVersionSymbol] === undefined
101
+ ) {
102
+ return obj;
103
+ }
104
+
105
+ const callback = this.getOption("write.partial.callback");
106
+ if (!isFunction(callback)) {
107
+ return obj;
108
+ }
109
+
110
+ const results = diff(this[serverVersionSymbol], obj);
111
+ if (!results) {
112
+ return obj;
113
+ }
114
+
115
+ obj = callback(obj, results);
116
+ this[serverVersionSymbol] = obj;
117
+
118
+ return obj;
117
119
  }
118
120
 
119
121
  /**
@@ -123,32 +125,32 @@ function doDiff(obj) {
123
125
  * @returns {Object}
124
126
  */
125
127
  function doTransform(type, obj) {
126
- const transformation = this.getOption(`${type}.mapping.transformer`);
127
- if (transformation !== undefined && transformation !== null) {
128
- const pipe = new Pipe(transformation);
129
- const callbacks = this.getOption(`${type}.mapping.callbacks`);
130
-
131
- if (isArray(callbacks)) {
132
- for (const callback of callbacks) {
133
- if (typeof callback === "function") {
134
- pipe.setCallback(callback);
135
- }
136
- }
137
- }
138
-
139
- if (isObject(callbacks)) {
140
- for (const key in callbacks) {
141
- if (
142
- callbacks.hasOwnProperty(key) &&
143
- typeof callbacks[key] === "function"
144
- ) {
145
- pipe.setCallback(key, callbacks[key]);
146
- }
147
- }
148
- }
149
-
150
- obj = pipe.run(obj);
151
- }
152
-
153
- return obj;
128
+ const transformation = this.getOption(`${type}.mapping.transformer`);
129
+ if (transformation !== undefined && transformation !== null) {
130
+ const pipe = new Pipe(transformation);
131
+ const callbacks = this.getOption(`${type}.mapping.callbacks`);
132
+
133
+ if (isArray(callbacks)) {
134
+ for (const callback of callbacks) {
135
+ if (typeof callback === "function") {
136
+ pipe.setCallback(callback);
137
+ }
138
+ }
139
+ }
140
+
141
+ if (isObject(callbacks)) {
142
+ for (const key in callbacks) {
143
+ if (
144
+ callbacks.hasOwnProperty(key) &&
145
+ typeof callbacks[key] === "function"
146
+ ) {
147
+ pipe.setCallback(key, callbacks[key]);
148
+ }
149
+ }
150
+ }
151
+
152
+ obj = pipe.run(obj);
153
+ }
154
+
155
+ return obj;
154
156
  }
@@ -183,4 +183,4 @@ function getOperator(a, b) {
183
183
  }
184
184
 
185
185
  return operator;
186
- }
186
+ }