@terraforge/terraform 0.0.27 → 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 +30 -9
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -315,9 +315,26 @@ const hasInputValue = (value) => typeof value !== "undefined";
315
315
  const shouldIncludeFieldForComparison = (schema, inputValue) => {
316
316
  return schema.required || hasInputValue(inputValue);
317
317
  };
318
+ const isContainerSchema = (schema) => {
319
+ return [
320
+ "array",
321
+ "record",
322
+ "object",
323
+ "array-object"
324
+ ].includes(schema.type);
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
+ };
318
335
  const normalizeStateForComparison = (schema, state, inputState) => {
319
336
  if (!shouldIncludeFieldForComparison(schema, inputState)) return;
320
- if ((schema.optional || schema.computed) && (state === null || typeof state === "undefined") && isEmptyOutputValue(inputState)) state = inputState;
337
+ if ((state === null || typeof state === "undefined") && isContainerSchema(schema) && isEmptyOutputValue(inputState)) state = inputState;
321
338
  if (state === null || typeof state === "undefined") return state;
322
339
  if (schema.type === "array") {
323
340
  if (!Array.isArray(state)) return state;
@@ -339,21 +356,25 @@ const normalizeStateForComparison = (schema, state, inputState) => {
339
356
  }
340
357
  if (schema.type === "object") {
341
358
  if (typeof state !== "object" || state === null) return state;
342
- return Object.fromEntries(Object.entries(schema.properties).flatMap(([key, prop]) => {
359
+ const normalized = Object.fromEntries(Object.entries(schema.properties).flatMap(([key, prop]) => {
343
360
  const stateValue = state[camelCase(key)];
344
- const normalized = normalizeStateForComparison(prop, stateValue, inputState && typeof inputState === "object" ? inputState[camelCase(key)] : void 0);
345
- if (typeof normalized === "undefined") return [];
346
- 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]];
347
364
  }));
365
+ if (Object.keys(normalized).length === 0 && isEmptyStructuralInput(inputState)) return normalizeStateForComparison(schema, inputState, inputState);
366
+ return normalized;
348
367
  }
349
368
  if (schema.type === "array-object") {
350
369
  if (typeof state !== "object" || state === null) return state;
351
- return Object.fromEntries(Object.entries(schema.properties).flatMap(([key, prop]) => {
370
+ const normalized = Object.fromEntries(Object.entries(schema.properties).flatMap(([key, prop]) => {
352
371
  const stateValue = state[camelCase(key)];
353
- const normalized = normalizeStateForComparison(prop, stateValue, inputState && typeof inputState === "object" ? inputState[camelCase(key)] : void 0);
354
- if (typeof normalized === "undefined") return [];
355
- 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]];
356
375
  }));
376
+ if (Object.keys(normalized).length === 0 && isEmptyStructuralInput(inputState)) return normalizeStateForComparison(schema, inputState, inputState);
377
+ return normalized;
357
378
  }
358
379
  if (schema.type === "string") {
359
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.27",
3
+ "version": "0.0.29",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",