@terraforge/terraform 0.0.28 → 0.0.29

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 +21 -8
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -323,6 +323,15 @@ const isContainerSchema = (schema) => {
323
323
  "array-object"
324
324
  ].includes(schema.type);
325
325
  };
326
+ const isEmptyStructuralInput = (value) => {
327
+ if (value === null || typeof value === "undefined") return true;
328
+ if (Array.isArray(value)) return value.every((item) => isEmptyStructuralInput(item));
329
+ if (typeof value === "object") {
330
+ const entries = Object.values(value);
331
+ return entries.length > 0 && entries.every((item) => isEmptyStructuralInput(item));
332
+ }
333
+ return false;
334
+ };
326
335
  const normalizeStateForComparison = (schema, state, inputState) => {
327
336
  if (!shouldIncludeFieldForComparison(schema, inputState)) return;
328
337
  if ((state === null || typeof state === "undefined") && isContainerSchema(schema) && isEmptyOutputValue(inputState)) state = inputState;
@@ -347,21 +356,25 @@ const normalizeStateForComparison = (schema, state, inputState) => {
347
356
  }
348
357
  if (schema.type === "object") {
349
358
  if (typeof state !== "object" || state === null) return state;
350
- return Object.fromEntries(Object.entries(schema.properties).flatMap(([key, prop]) => {
359
+ const normalized = Object.fromEntries(Object.entries(schema.properties).flatMap(([key, prop]) => {
351
360
  const stateValue = state[camelCase(key)];
352
- const normalized = normalizeStateForComparison(prop, stateValue, inputState && typeof inputState === "object" ? inputState[camelCase(key)] : void 0);
353
- if (typeof normalized === "undefined") return [];
354
- return [[camelCase(key), normalized]];
361
+ const normalized$1 = normalizeStateForComparison(prop, stateValue, inputState && typeof inputState === "object" ? inputState[camelCase(key)] : void 0);
362
+ if (typeof normalized$1 === "undefined") return [];
363
+ return [[camelCase(key), normalized$1]];
355
364
  }));
365
+ if (Object.keys(normalized).length === 0 && isEmptyStructuralInput(inputState)) return normalizeStateForComparison(schema, inputState, inputState);
366
+ return normalized;
356
367
  }
357
368
  if (schema.type === "array-object") {
358
369
  if (typeof state !== "object" || state === null) return state;
359
- return Object.fromEntries(Object.entries(schema.properties).flatMap(([key, prop]) => {
370
+ const normalized = Object.fromEntries(Object.entries(schema.properties).flatMap(([key, prop]) => {
360
371
  const stateValue = state[camelCase(key)];
361
- const normalized = normalizeStateForComparison(prop, stateValue, inputState && typeof inputState === "object" ? inputState[camelCase(key)] : void 0);
362
- if (typeof normalized === "undefined") return [];
363
- return [[camelCase(key), normalized]];
372
+ const normalized$1 = normalizeStateForComparison(prop, stateValue, inputState && typeof inputState === "object" ? inputState[camelCase(key)] : void 0);
373
+ if (typeof normalized$1 === "undefined") return [];
374
+ return [[camelCase(key), normalized$1]];
364
375
  }));
376
+ if (Object.keys(normalized).length === 0 && isEmptyStructuralInput(inputState)) return normalizeStateForComparison(schema, inputState, inputState);
377
+ return normalized;
365
378
  }
366
379
  if (schema.type === "string") {
367
380
  if (typeof state === "string") return tryNormalizeJsonString(state);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@terraforge/terraform",
3
- "version": "0.0.28",
3
+ "version": "0.0.29",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",