@schukai/monster 3.71.3 → 3.73.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +27 -0
- package/package.json +1 -1
- package/source/components/datatable/dataset.mjs +268 -272
- package/source/components/datatable/datasource/dom.mjs +2 -2
- package/source/components/datatable/datasource/rest.mjs +408 -410
- package/source/components/datatable/filter.mjs +0 -1
- package/source/components/datatable/style/datatable.pcss +7 -5
- package/source/components/datatable/style/embedded-pagination.pcss +1 -1
- package/source/components/datatable/style/pagination.pcss +1 -1
- package/source/components/datatable/stylesheet/change-button.mjs +2 -4
- package/source/components/datatable/stylesheet/column-bar.mjs +2 -4
- package/source/components/datatable/stylesheet/dataset.mjs +2 -4
- package/source/components/datatable/stylesheet/datasource.mjs +1 -3
- package/source/components/datatable/stylesheet/datatable.mjs +2 -4
- package/source/components/datatable/stylesheet/embedded-pagination.mjs +1 -1
- package/source/components/datatable/stylesheet/filter-button.mjs +1 -3
- package/source/components/datatable/stylesheet/filter-controls-defaults.mjs +14 -7
- package/source/components/datatable/stylesheet/filter-date-range.mjs +1 -3
- package/source/components/datatable/stylesheet/filter-range.mjs +1 -3
- package/source/components/datatable/stylesheet/filter.mjs +2 -4
- package/source/components/datatable/stylesheet/pagination.mjs +2 -4
- package/source/components/datatable/stylesheet/save-button.mjs +2 -4
- package/source/components/datatable/stylesheet/select-filter.mjs +2 -4
- package/source/components/datatable/stylesheet/status.mjs +2 -4
- package/source/components/form/context-help.mjs +1 -1
- package/source/components/form/field-set.mjs +219 -219
- package/source/components/form/form.mjs +309 -185
- package/source/components/form/reload.mjs +211 -211
- package/source/components/form/select.mjs +12 -13
- package/source/components/form/style/field-set.pcss +2 -2
- package/source/components/form/style/form.pcss +8 -0
- package/source/components/form/stylesheet/action-button.mjs +2 -4
- package/source/components/form/stylesheet/api-button.mjs +1 -3
- package/source/components/form/stylesheet/button-bar.mjs +2 -4
- package/source/components/form/stylesheet/button.mjs +2 -4
- package/source/components/form/stylesheet/confirm-button.mjs +2 -4
- package/source/components/form/stylesheet/context-error.mjs +2 -4
- package/source/components/form/stylesheet/context-help.mjs +2 -4
- package/source/components/form/stylesheet/field-set.mjs +14 -7
- package/source/components/form/stylesheet/form.mjs +14 -7
- package/source/components/form/stylesheet/message-state-button.mjs +1 -3
- package/source/components/form/stylesheet/popper-button.mjs +2 -4
- package/source/components/form/stylesheet/select.mjs +14 -7
- package/source/components/form/stylesheet/state-button.mjs +2 -4
- package/source/components/form/stylesheet/tree-select.mjs +1 -3
- package/source/components/host/stylesheet/call-button.mjs +2 -4
- package/source/components/host/stylesheet/config-manager.mjs +1 -3
- package/source/components/host/stylesheet/host.mjs +2 -4
- package/source/components/host/stylesheet/overlay.mjs +2 -4
- package/source/components/host/stylesheet/toggle-button.mjs +2 -4
- package/source/components/host/stylesheet/viewer.mjs +2 -4
- package/source/components/layout/style/collapse.pcss +2 -2
- package/source/components/layout/style/details.pcss +2 -2
- package/source/components/layout/stylesheet/collapse.mjs +14 -7
- package/source/components/layout/stylesheet/details.mjs +2 -4
- package/source/components/layout/stylesheet/panel.mjs +2 -4
- package/source/components/layout/stylesheet/popper.mjs +2 -4
- package/source/components/layout/stylesheet/split-panel.mjs +1 -3
- package/source/components/layout/stylesheet/tabs.mjs +2 -4
- package/source/components/layout/stylesheet/width-toggle.mjs +1 -3
- package/source/components/layout/tabs.mjs +0 -1
- package/source/components/navigation/stylesheet/table-of-content.mjs +2 -4
- package/source/components/notify/stylesheet/message.mjs +2 -4
- package/source/components/notify/stylesheet/notify.mjs +2 -4
- package/source/components/state/stylesheet/log.mjs +2 -4
- package/source/components/state/stylesheet/state.mjs +2 -4
- package/source/components/style/control.pcss +5 -0
- package/source/components/style/data-grid.pcss +2 -2
- package/source/components/style/mixin/typography.pcss +7 -1
- package/source/components/style/normalize.pcss +1 -1
- package/source/components/stylesheet/badge.mjs +1 -3
- package/source/components/stylesheet/border.mjs +1 -3
- package/source/components/stylesheet/button.mjs +1 -3
- package/source/components/stylesheet/card.mjs +1 -3
- package/source/components/stylesheet/color.mjs +1 -3
- package/source/components/stylesheet/common.mjs +1 -3
- package/source/components/stylesheet/control.mjs +2 -4
- package/source/components/stylesheet/data-grid.mjs +2 -4
- package/source/components/stylesheet/display.mjs +1 -3
- package/source/components/stylesheet/floating-ui.mjs +1 -3
- package/source/components/stylesheet/form.mjs +13 -6
- package/source/components/stylesheet/host.mjs +1 -3
- package/source/components/stylesheet/icons.mjs +1 -3
- package/source/components/stylesheet/mixin/badge.mjs +1 -3
- package/source/components/stylesheet/mixin/button.mjs +1 -3
- package/source/components/stylesheet/mixin/form.mjs +13 -6
- package/source/components/stylesheet/mixin/hover.mjs +1 -3
- package/source/components/stylesheet/mixin/icon.mjs +1 -3
- package/source/components/stylesheet/mixin/media.mjs +1 -3
- package/source/components/stylesheet/mixin/property.mjs +13 -6
- package/source/components/stylesheet/mixin/skeleton.mjs +1 -3
- package/source/components/stylesheet/mixin/spinner.mjs +1 -3
- package/source/components/stylesheet/mixin/typography.mjs +1 -3
- package/source/components/stylesheet/normalize.mjs +1 -3
- package/source/components/stylesheet/popper.mjs +1 -3
- package/source/components/stylesheet/property.mjs +2 -4
- package/source/components/stylesheet/ripple.mjs +1 -3
- package/source/components/stylesheet/skeleton.mjs +1 -3
- package/source/components/stylesheet/space.mjs +1 -3
- package/source/components/stylesheet/spinner.mjs +1 -3
- package/source/components/stylesheet/table.mjs +1 -3
- package/source/components/stylesheet/theme.mjs +1 -3
- package/source/components/stylesheet/typography.mjs +13 -6
- package/source/components/tree-menu/dragable-tree-menu.mjs +693 -0
- package/source/components/tree-menu/style/tree-menu.pcss +69 -42
- package/source/components/tree-menu/stylesheet/tree-menu.mjs +2 -4
- package/source/components/tree-menu/tree-menu.mjs +260 -331
- package/source/data/datasource/server/restapi.mjs +194 -191
- package/source/data/datasource/server.mjs +107 -105
- package/source/data/diff.mjs +1 -1
- package/source/dom/constants.mjs +18 -0
- package/source/dom/customelement.mjs +2 -6
- package/source/dom/slotted.mjs +6 -1
- package/source/dom/updater.mjs +2 -0
- package/test/cases/components/host/details.mjs +1 -1
- package/test/cases/components/host/host.mjs +1 -1
- package/test/cases/components/host/overlay.mjs +1 -1
- package/test/cases/dom/customcontrol.mjs +1 -1
- 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
|
-
|
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
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
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
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
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
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
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
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
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
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
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
|
}
|
package/source/data/diff.mjs
CHANGED