@terraforge/terraform 0.0.28 → 0.0.30

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 +25 -12
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -323,15 +323,24 @@ const isContainerSchema = (schema) => {
323
323
  "array-object"
324
324
  ].includes(schema.type);
325
325
  };
326
- const normalizeStateForComparison = (schema, state, inputState) => {
326
+ const isEmptyStructuralInput = (value) => {
327
+ if (value === null || typeof value === "undefined") return true;
328
+ if (Array.isArray(value)) return value.length === 0 || 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
+ };
335
+ const normalizeStateForComparison = (schema, state, inputState, allowStructuralFallback = true) => {
327
336
  if (!shouldIncludeFieldForComparison(schema, inputState)) return;
328
- if ((state === null || typeof state === "undefined") && isContainerSchema(schema) && isEmptyOutputValue(inputState)) state = inputState;
337
+ if (allowStructuralFallback && (state === null || typeof state === "undefined") && isContainerSchema(schema) && isEmptyStructuralInput(inputState)) state = inputState;
329
338
  if (state === null || typeof state === "undefined") return state;
330
339
  if (schema.type === "array") {
331
340
  if (!Array.isArray(state)) return state;
332
341
  const filtered = state.map((item, index) => {
333
342
  const inputItem = Array.isArray(inputState) ? inputState[index] : void 0;
334
- return normalizeStateForComparison(schema.item, item, inputItem);
343
+ return normalizeStateForComparison(schema.item, item, inputItem, allowStructuralFallback);
335
344
  }).filter((item) => typeof item !== "undefined");
336
345
  if (schema.collectionKind === "set") return sortStateValues(uniqueStateValues(filtered.filter((item) => item !== null)));
337
346
  return filtered;
@@ -340,28 +349,32 @@ const normalizeStateForComparison = (schema, state, inputState) => {
340
349
  if (typeof state !== "object" || state === null) return state;
341
350
  return Object.fromEntries(Object.entries(state).flatMap(([key, value]) => {
342
351
  const inputValue = inputState && typeof inputState === "object" ? inputState[key] : void 0;
343
- const normalized = normalizeStateForComparison(schema.item, value, inputValue);
352
+ const normalized = normalizeStateForComparison(schema.item, value, inputValue, allowStructuralFallback);
344
353
  if (typeof normalized === "undefined") return [];
345
354
  return [[key, normalized]];
346
355
  }));
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, allowStructuralFallback);
362
+ if (typeof normalized$1 === "undefined") return [];
363
+ return [[camelCase(key), normalized$1]];
355
364
  }));
365
+ if (allowStructuralFallback && Object.keys(normalized).length === 0 && isEmptyStructuralInput(inputState)) return normalizeStateForComparison(schema, inputState, inputState, false);
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, allowStructuralFallback);
373
+ if (typeof normalized$1 === "undefined") return [];
374
+ return [[camelCase(key), normalized$1]];
364
375
  }));
376
+ if (allowStructuralFallback && Object.keys(normalized).length === 0 && isEmptyStructuralInput(inputState)) return normalizeStateForComparison(schema, inputState, inputState, false);
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.30",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",