@dchighs/dc-config-mapper 0.1.3 → 0.1.4

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.
@@ -20,22 +20,32 @@ class DataCompiler {
20
20
  }
21
21
  return "";
22
22
  }
23
- processIdsSuffix({ context, data, key, prefix }) {
23
+ processIdsSuffix({ context, data, dataCopy, key, prefix }) {
24
24
  const baseKey = key.slice(prefix.length).slice(0, -this.idsSuffix.length);
25
25
  const pluralizedKey = (0, pluralize_1.default)(baseKey);
26
26
  if (context[pluralizedKey]) {
27
- const relatedItems = context[pluralizedKey]
28
- .filter((item) => data[key].includes(item.id))
29
- .map((item) => (0, lodash_1.isObject)(item) ? this.compile({ data: item, context: context }) : item);
27
+ const idList = dataCopy[key];
28
+ const contextItems = context[pluralizedKey];
29
+ const relatedItems = idList
30
+ .map(id => {
31
+ const foundItem = contextItems.find(item => item.id === id);
32
+ if (!foundItem) {
33
+ return null;
34
+ }
35
+ return (0, lodash_1.isObject)(foundItem)
36
+ ? this.compile({ data: { ...foundItem }, context: context })
37
+ : foundItem;
38
+ })
39
+ .filter(item => item !== null);
30
40
  data[`${prefix}${pluralizedKey}`] = relatedItems;
31
41
  delete data[key];
32
42
  }
33
43
  }
34
- processIdSuffix({ context, data, key, prefix }) {
44
+ processIdSuffix({ context, data, key, prefix, dataCopy }) {
35
45
  const baseKey = key.slice(prefix.length).slice(0, -this.idSuffix.length);
36
46
  const pluralizedKey = (0, pluralize_1.default)(baseKey);
37
47
  if (context[pluralizedKey]) {
38
- const foundItem = context[pluralizedKey].find((item) => item.id === data[key]);
48
+ const foundItem = context[pluralizedKey].find((item) => item.id === dataCopy[key]);
39
49
  data[`${prefix}${baseKey}`] = foundItem ? this.compile({ data: foundItem, context: context }) : null;
40
50
  delete data[key];
41
51
  }
@@ -60,14 +70,16 @@ class DataCompiler {
60
70
  if (key.endsWith(this.idsSuffix) && Array.isArray(value)) {
61
71
  this.processIdsSuffix({
62
72
  data: data,
73
+ dataCopy: dataCopy,
63
74
  key: key,
64
75
  prefix: matchedPrefix,
65
- context: context
76
+ context: context,
66
77
  });
67
78
  }
68
79
  else if (key.endsWith(this.idSuffix) && value) {
69
80
  this.processIdSuffix({
70
81
  data: data,
82
+ dataCopy: dataCopy,
71
83
  key: key,
72
84
  prefix: matchedPrefix,
73
85
  context: context
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dchighs/dc-config-mapper",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "A opined library to restructure and populate configuration for Dragon City.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",