@schukai/monster 4.72.0 → 4.73.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/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"author":"Volker Schukai","dependencies":{"@floating-ui/dom":"^1.7.4","@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":"4.
|
|
1
|
+
{"author":"Volker Schukai","dependencies":{"@floating-ui/dom":"^1.7.4","@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":"4.73.0"}
|
|
@@ -179,6 +179,7 @@ class Rest extends Datasource {
|
|
|
179
179
|
|
|
180
180
|
lookups: {
|
|
181
181
|
enabled: false,
|
|
182
|
+
debug: false,
|
|
182
183
|
sourcePath: "dataset",
|
|
183
184
|
request: {
|
|
184
185
|
idsParam: "ids",
|
|
@@ -732,6 +733,14 @@ function handleValidationError(error) {
|
|
|
732
733
|
.catch(() => {});
|
|
733
734
|
}
|
|
734
735
|
|
|
736
|
+
/**
|
|
737
|
+
* @private
|
|
738
|
+
* @return {boolean}
|
|
739
|
+
*/
|
|
740
|
+
function lookupDebugEnabled() {
|
|
741
|
+
return this.getOption("lookups.debug", false) === true;
|
|
742
|
+
}
|
|
743
|
+
|
|
735
744
|
/**
|
|
736
745
|
* @private
|
|
737
746
|
* @param {number} requestId
|
|
@@ -906,9 +915,22 @@ async function fetchLookupEntries(cfg, ids) {
|
|
|
906
915
|
|
|
907
916
|
const init = isObject(request.init) ? request.init : {};
|
|
908
917
|
const url = buildLookupUrl(cfg.url, ids, request);
|
|
918
|
+
const debug = lookupDebugEnabled.call(this);
|
|
919
|
+
if (debug) {
|
|
920
|
+
console.debug("[monster-datasource-rest] lookup fetch", {
|
|
921
|
+
url,
|
|
922
|
+
ids,
|
|
923
|
+
});
|
|
924
|
+
}
|
|
909
925
|
|
|
910
926
|
const response = await fetch(url, init);
|
|
911
927
|
if (!response.ok) {
|
|
928
|
+
if (debug) {
|
|
929
|
+
console.debug("[monster-datasource-rest] lookup failed", {
|
|
930
|
+
url,
|
|
931
|
+
status: response.status,
|
|
932
|
+
});
|
|
933
|
+
}
|
|
912
934
|
return new Map();
|
|
913
935
|
}
|
|
914
936
|
|
|
@@ -916,6 +938,9 @@ async function fetchLookupEntries(cfg, ids) {
|
|
|
916
938
|
try {
|
|
917
939
|
payload = await response.json();
|
|
918
940
|
} catch (_error) {
|
|
941
|
+
if (debug) {
|
|
942
|
+
console.debug("[monster-datasource-rest] lookup invalid json", { url });
|
|
943
|
+
}
|
|
919
944
|
return new Map();
|
|
920
945
|
}
|
|
921
946
|
|
|
@@ -931,6 +956,12 @@ async function fetchLookupEntries(cfg, ids) {
|
|
|
931
956
|
}
|
|
932
957
|
|
|
933
958
|
if (!isArray(entries)) {
|
|
959
|
+
if (debug) {
|
|
960
|
+
console.debug("[monster-datasource-rest] lookup no entries", {
|
|
961
|
+
url,
|
|
962
|
+
path: responseConfig.path,
|
|
963
|
+
});
|
|
964
|
+
}
|
|
934
965
|
return new Map();
|
|
935
966
|
}
|
|
936
967
|
|
|
@@ -942,6 +973,12 @@ async function fetchLookupEntries(cfg, ids) {
|
|
|
942
973
|
}
|
|
943
974
|
result.set(String(entry[idKey]), entry);
|
|
944
975
|
}
|
|
976
|
+
if (debug) {
|
|
977
|
+
console.debug("[monster-datasource-rest] lookup resolved", {
|
|
978
|
+
url,
|
|
979
|
+
entries: result.size,
|
|
980
|
+
});
|
|
981
|
+
}
|
|
945
982
|
|
|
946
983
|
return result;
|
|
947
984
|
}
|
|
@@ -955,8 +992,7 @@ async function fetchLookupEntries(cfg, ids) {
|
|
|
955
992
|
*/
|
|
956
993
|
function buildLookupUrl(url, ids, request) {
|
|
957
994
|
const idsParam = request.idsParam || "ids";
|
|
958
|
-
const
|
|
959
|
-
const idsValue = ids.join(idsSeparator);
|
|
995
|
+
const idsValue = buildLookupIdsValue(ids, request);
|
|
960
996
|
|
|
961
997
|
if (url.includes("${")) {
|
|
962
998
|
const formatter = new Formatter({ ids: idsValue });
|
|
@@ -969,6 +1005,33 @@ function buildLookupUrl(url, ids, request) {
|
|
|
969
1005
|
)}`;
|
|
970
1006
|
}
|
|
971
1007
|
|
|
1008
|
+
/**
|
|
1009
|
+
* @private
|
|
1010
|
+
* @param {string[]} ids
|
|
1011
|
+
* @param {object} request
|
|
1012
|
+
* @return {string}
|
|
1013
|
+
*/
|
|
1014
|
+
function buildLookupIdsValue(ids, request) {
|
|
1015
|
+
if (isFunction(request.queryBuilder)) {
|
|
1016
|
+
return request.queryBuilder(ids);
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
const idsTemplate = request.idsTemplate;
|
|
1020
|
+
const idsSeparator = request.idsSeparator || ",";
|
|
1021
|
+
const wrapOpen = request.wrapOpen || "";
|
|
1022
|
+
const wrapClose = request.wrapClose || "";
|
|
1023
|
+
|
|
1024
|
+
let values = ids;
|
|
1025
|
+
if (isString(idsTemplate) && idsTemplate !== "") {
|
|
1026
|
+
values = ids.map((id) => {
|
|
1027
|
+
const formatter = new Formatter({ id });
|
|
1028
|
+
return formatter.format(idsTemplate);
|
|
1029
|
+
});
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
return `${wrapOpen}${values.join(idsSeparator)}${wrapClose}`;
|
|
1033
|
+
}
|
|
1034
|
+
|
|
972
1035
|
/**
|
|
973
1036
|
* @private
|
|
974
1037
|
* @param {object} cfg
|