@terraforge/terraform 0.0.18 → 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.
Files changed (2) hide show
  1. package/dist/index.mjs +19 -5
  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;
@@ -2044,7 +2054,7 @@ const formatInputState = (schema, state, includeSchemaFields = true, path = [])
2044
2054
  throw new Error(`Unknown schema type: ${schema.type}`);
2045
2055
  };
2046
2056
  const formatOutputState = (schema, state, path = []) => {
2047
- if (state === null) return null;
2057
+ if (state === null || state === void 0) return null;
2048
2058
  if (schema.type === "array") {
2049
2059
  if (Array.isArray(state)) return state.map((item, i) => formatOutputState(schema.item, item, [...path, i]));
2050
2060
  throw new IncorrectType(schema.type, path);
@@ -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
- object[camelCase(key)] = formatOutputState(prop, value, [...path, key]);
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
- object[camelCase(key)] = formatOutputState(prop, value, [...path, key]);
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;
@@ -2137,7 +2151,7 @@ const createPlugin5 = async ({ server, client }) => {
2137
2151
  proposedNewState: encodeDynamicValue(preparedProposedState),
2138
2152
  config: encodeDynamicValue(preparedConfigState)
2139
2153
  });
2140
- const plannedState = decodeDynamicValue(plan.plannedState);
2154
+ const plannedState = formatOutputState(schema$1, decodeDynamicValue(plan.plannedState));
2141
2155
  return {
2142
2156
  requiresReplace: filterRequiresReplace(formatAttributePath(plan.requiresReplace), preparedPriorState, preparedProposedState),
2143
2157
  plannedState
@@ -2213,7 +2227,7 @@ const createPlugin6 = async ({ server, client }) => {
2213
2227
  proposedNewState: encodeDynamicValue(preparedProposedState),
2214
2228
  config: encodeDynamicValue(configState)
2215
2229
  });
2216
- const plannedState = decodeDynamicValue(plan.plannedState);
2230
+ const plannedState = formatOutputState(schema$1, decodeDynamicValue(plan.plannedState));
2217
2231
  return {
2218
2232
  requiresReplace: filterRequiresReplace(formatAttributePath(plan.requiresReplace), preparedPriorState, preparedProposedState),
2219
2233
  plannedState
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@terraforge/terraform",
3
- "version": "0.0.18",
3
+ "version": "0.0.20",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",