@schukai/monster 4.72.0 → 4.73.1

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,25 @@
2
2
 
3
3
 
4
4
 
5
+ ## [4.73.1] - 2026-01-03
6
+
7
+ ### Bug Fixes
8
+
9
+ - Enhance collectLookupIds with sourcePath parameter for flexibility
10
+ ### Changes
11
+
12
+ - update tests
13
+
14
+
15
+
16
+ ## [4.73.0] - 2026-01-03
17
+
18
+ ### Add Features
19
+
20
+ - Enhance lookup column functionality with templating and debugging options
21
+
22
+
23
+
5
24
  ## [4.72.0] - 2026-01-03
6
25
 
7
26
  ### Add Features
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.72.0"}
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.1"}
@@ -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
@@ -815,7 +824,11 @@ async function resolveRemoteLookup(requestId, name, cfg) {
815
824
  const cache = getLookupCache.call(this, name);
816
825
  const pending = getLookupPending.call(this, name);
817
826
 
818
- const ids = collectLookupIds.call(this, key);
827
+ const ids = collectLookupIds.call(
828
+ this,
829
+ key,
830
+ this.getOption("lookups.sourcePath", "dataset"),
831
+ );
819
832
  const missingIds = ids.filter((id) => !cache.has(id) && !pending.has(id));
820
833
 
821
834
  if (missingIds.length === 0) {
@@ -869,8 +882,8 @@ function applyLookupCache(requestId, cfg, cache) {
869
882
  * @param {string} key
870
883
  * @return {string[]}
871
884
  */
872
- function collectLookupIds(key) {
873
- const rows = resolveLookupRows.call(this);
885
+ function collectLookupIds(key, sourcePath) {
886
+ const rows = resolveLookupRows.call(this, undefined, sourcePath);
874
887
  if (!isArray(rows)) {
875
888
  return [];
876
889
  }
@@ -906,9 +919,22 @@ async function fetchLookupEntries(cfg, ids) {
906
919
 
907
920
  const init = isObject(request.init) ? request.init : {};
908
921
  const url = buildLookupUrl(cfg.url, ids, request);
922
+ const debug = lookupDebugEnabled.call(this);
923
+ if (debug) {
924
+ console.debug("[monster-datasource-rest] lookup fetch", {
925
+ url,
926
+ ids,
927
+ });
928
+ }
909
929
 
910
930
  const response = await fetch(url, init);
911
931
  if (!response.ok) {
932
+ if (debug) {
933
+ console.debug("[monster-datasource-rest] lookup failed", {
934
+ url,
935
+ status: response.status,
936
+ });
937
+ }
912
938
  return new Map();
913
939
  }
914
940
 
@@ -916,6 +942,9 @@ async function fetchLookupEntries(cfg, ids) {
916
942
  try {
917
943
  payload = await response.json();
918
944
  } catch (_error) {
945
+ if (debug) {
946
+ console.debug("[monster-datasource-rest] lookup invalid json", { url });
947
+ }
919
948
  return new Map();
920
949
  }
921
950
 
@@ -931,6 +960,12 @@ async function fetchLookupEntries(cfg, ids) {
931
960
  }
932
961
 
933
962
  if (!isArray(entries)) {
963
+ if (debug) {
964
+ console.debug("[monster-datasource-rest] lookup no entries", {
965
+ url,
966
+ path: responseConfig.path,
967
+ });
968
+ }
934
969
  return new Map();
935
970
  }
936
971
 
@@ -942,6 +977,12 @@ async function fetchLookupEntries(cfg, ids) {
942
977
  }
943
978
  result.set(String(entry[idKey]), entry);
944
979
  }
980
+ if (debug) {
981
+ console.debug("[monster-datasource-rest] lookup resolved", {
982
+ url,
983
+ entries: result.size,
984
+ });
985
+ }
945
986
 
946
987
  return result;
947
988
  }
@@ -955,8 +996,7 @@ async function fetchLookupEntries(cfg, ids) {
955
996
  */
956
997
  function buildLookupUrl(url, ids, request) {
957
998
  const idsParam = request.idsParam || "ids";
958
- const idsSeparator = request.idsSeparator || ",";
959
- const idsValue = ids.join(idsSeparator);
999
+ const idsValue = buildLookupIdsValue(ids, request);
960
1000
 
961
1001
  if (url.includes("${")) {
962
1002
  const formatter = new Formatter({ ids: idsValue });
@@ -969,6 +1009,33 @@ function buildLookupUrl(url, ids, request) {
969
1009
  )}`;
970
1010
  }
971
1011
 
1012
+ /**
1013
+ * @private
1014
+ * @param {string[]} ids
1015
+ * @param {object} request
1016
+ * @return {string}
1017
+ */
1018
+ function buildLookupIdsValue(ids, request) {
1019
+ if (isFunction(request.queryBuilder)) {
1020
+ return request.queryBuilder(ids);
1021
+ }
1022
+
1023
+ const idsTemplate = request.idsTemplate;
1024
+ const idsSeparator = request.idsSeparator || ",";
1025
+ const wrapOpen = request.wrapOpen || "";
1026
+ const wrapClose = request.wrapClose || "";
1027
+
1028
+ let values = ids;
1029
+ if (isString(idsTemplate) && idsTemplate !== "") {
1030
+ values = ids.map((id) => {
1031
+ const formatter = new Formatter({ id });
1032
+ return formatter.format(idsTemplate);
1033
+ });
1034
+ }
1035
+
1036
+ return `${wrapOpen}${values.join(idsSeparator)}${wrapClose}`;
1037
+ }
1038
+
972
1039
  /**
973
1040
  * @private
974
1041
  * @param {object} cfg
@@ -228,9 +228,16 @@ describe('Select', function () {
228
228
  ]);
229
229
  mocks.appendChild(select);
230
230
 
231
- setTimeout(() => {
231
+ const startedAt = Date.now();
232
+ const poll = () => {
232
233
  try {
233
234
  const options = select.getOption('options');
235
+ if (options?.[0]?.value !== 'Alpha') {
236
+ if (Date.now() - startedAt < 1500) {
237
+ return setTimeout(poll, 50);
238
+ }
239
+ }
240
+
234
241
  expect(options[0].value).to.equal('Alpha');
235
242
  expect(options[0].label).to.equal('Alpha');
236
243
  expect(options[0].visibility).to.equal('visible');
@@ -245,7 +252,9 @@ describe('Select', function () {
245
252
  }
246
253
 
247
254
  done();
248
- }, 350);
255
+ };
256
+
257
+ setTimeout(poll, 50);
249
258
  });
250
259
 
251
260
  it('should not parse options arrays with multiple string entries', function (done) {
@@ -14,11 +14,11 @@ describe('DeadMansSwitch', function () {
14
14
  const ms2 = Date.now();
15
15
 
16
16
  const diff = ms2 - ms1;
17
- if (diff < 100) {
18
- done('to short ' + diff);
19
- return;
20
- }
21
- done();
17
+ if (diff < 90) {
18
+ done(new Error('to short ' + diff));
19
+ return;
20
+ }
21
+ done();
22
22
  })
23
23
 
24
24
 
@@ -42,7 +42,7 @@ describe('DeadMansSwitch', function () {
42
42
  return;
43
43
  }
44
44
 
45
- if (diff < 600) {
45
+ if (diff < 550) {
46
46
  done(new Error('to short ' + diff));
47
47
  return;
48
48
  }
@@ -68,4 +68,4 @@ describe('DeadMansSwitch', function () {
68
68
  });
69
69
  });
70
70
 
71
- });
71
+ });