@terraforge/terraform 0.0.19 → 0.0.20
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/dist/index.mjs +16 -2
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1997,6 +1997,16 @@ var IncorrectType = class extends TypeError {
|
|
|
1997
1997
|
super(`${path.join(".")} should be a ${type}`);
|
|
1998
1998
|
}
|
|
1999
1999
|
};
|
|
2000
|
+
const isEmptyOutputValue = (value) => {
|
|
2001
|
+
if (value === null || typeof value === "undefined") return true;
|
|
2002
|
+
if (Array.isArray(value)) return value.length === 0;
|
|
2003
|
+
if (typeof value === "object") return Object.keys(value).length === 0;
|
|
2004
|
+
return false;
|
|
2005
|
+
};
|
|
2006
|
+
const shouldOmitOutputValue = (schema, value) => {
|
|
2007
|
+
if (!(schema.optional || schema.computed)) return false;
|
|
2008
|
+
return isEmptyOutputValue(value);
|
|
2009
|
+
};
|
|
2000
2010
|
const formatInputState = (schema, state, includeSchemaFields = true, path = []) => {
|
|
2001
2011
|
if (state === null) return null;
|
|
2002
2012
|
if (typeof state === "undefined") return null;
|
|
@@ -2062,7 +2072,9 @@ const formatOutputState = (schema, state, path = []) => {
|
|
|
2062
2072
|
const object = {};
|
|
2063
2073
|
for (const [key, prop] of Object.entries(schema.properties)) {
|
|
2064
2074
|
const value = state[key];
|
|
2065
|
-
|
|
2075
|
+
const formatted = formatOutputState(prop, value, [...path, key]);
|
|
2076
|
+
if (shouldOmitOutputValue(prop, formatted)) continue;
|
|
2077
|
+
object[camelCase(key)] = formatted;
|
|
2066
2078
|
}
|
|
2067
2079
|
return object;
|
|
2068
2080
|
}
|
|
@@ -2073,7 +2085,9 @@ const formatOutputState = (schema, state, path = []) => {
|
|
|
2073
2085
|
const object = {};
|
|
2074
2086
|
for (const [key, prop] of Object.entries(schema.properties)) {
|
|
2075
2087
|
const value = state[0][key];
|
|
2076
|
-
|
|
2088
|
+
const formatted = formatOutputState(prop, value, [...path, key]);
|
|
2089
|
+
if (shouldOmitOutputValue(prop, formatted)) continue;
|
|
2090
|
+
object[camelCase(key)] = formatted;
|
|
2077
2091
|
}
|
|
2078
2092
|
return object;
|
|
2079
2093
|
} else return null;
|