@strapi/utils 4.8.0 → 4.8.2

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/lib/env-helper.js CHANGED
@@ -71,6 +71,26 @@ const utils = {
71
71
  const value = process.env[key];
72
72
  return new Date(value);
73
73
  },
74
+
75
+ /**
76
+ * Gets a value from env that matches oneOf provided values
77
+ * @param {string} key
78
+ * @param {string[]} expectedValues
79
+ * @param {string|undefined} defaultValue
80
+ * @returns {string|undefined}
81
+ */
82
+ oneOf(key, expectedValues, defaultValue) {
83
+ if (!expectedValues) {
84
+ throw new Error(`env.oneOf requires expectedValues`);
85
+ }
86
+
87
+ if (defaultValue && !expectedValues.includes(defaultValue)) {
88
+ throw new Error(`env.oneOf requires defaultValue to be included in expectedValues`);
89
+ }
90
+
91
+ const rawValue = env(key, defaultValue);
92
+ return expectedValues.includes(rawValue) ? rawValue : defaultValue;
93
+ },
74
94
  };
75
95
 
76
96
  Object.assign(env, utils);
@@ -160,6 +160,8 @@ const populate = traverseFactory()
160
160
  const { components } = attribute;
161
161
  const { on, ...properties } = value;
162
162
 
163
+ const newValue = {};
164
+
163
165
  // Handle legacy DZ params
164
166
  let newProperties = properties;
165
167
 
@@ -168,11 +170,15 @@ const populate = traverseFactory()
168
170
  newProperties = await recurse(visitor, { schema: componentSchema, path }, newProperties);
169
171
  }
170
172
 
173
+ Object.assign(newValue, newProperties);
174
+
171
175
  // Handle new morph fragment syntax
172
- const newOn = await recurse(visitor, { schema, path }, { on });
176
+ if (on) {
177
+ const newOn = await recurse(visitor, { schema, path }, { on });
173
178
 
174
- // Recompose both syntaxes
175
- const newValue = { ...newOn, ...newProperties };
179
+ // Recompose both syntaxes
180
+ Object.assign(newValue, newOn);
181
+ }
176
182
 
177
183
  set(key, newValue);
178
184
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/utils",
3
- "version": "4.8.0",
3
+ "version": "4.8.2",
4
4
  "description": "Shared utilities for the Strapi packages",
5
5
  "keywords": [
6
6
  "strapi",
@@ -46,5 +46,5 @@
46
46
  "node": ">=14.19.1 <=18.x.x",
47
47
  "npm": ">=6.0.0"
48
48
  },
49
- "gitHead": "e239e408f99c9e61e6d02b38f01632ce67412f2a"
49
+ "gitHead": "cc73bed97b19d44f7c7999ab44f1a4288590d7ab"
50
50
  }