@terraforge/terraform 0.0.29 → 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.
- package/dist/index.mjs +10 -10
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -325,22 +325,22 @@ const isContainerSchema = (schema) => {
|
|
|
325
325
|
};
|
|
326
326
|
const isEmptyStructuralInput = (value) => {
|
|
327
327
|
if (value === null || typeof value === "undefined") return true;
|
|
328
|
-
if (Array.isArray(value)) return value.every((item) => isEmptyStructuralInput(item));
|
|
328
|
+
if (Array.isArray(value)) return value.length === 0 || value.every((item) => isEmptyStructuralInput(item));
|
|
329
329
|
if (typeof value === "object") {
|
|
330
330
|
const entries = Object.values(value);
|
|
331
|
-
return entries.length
|
|
331
|
+
return entries.length === 0 || entries.every((item) => isEmptyStructuralInput(item));
|
|
332
332
|
}
|
|
333
333
|
return false;
|
|
334
334
|
};
|
|
335
|
-
const normalizeStateForComparison = (schema, state, inputState) => {
|
|
335
|
+
const normalizeStateForComparison = (schema, state, inputState, allowStructuralFallback = true) => {
|
|
336
336
|
if (!shouldIncludeFieldForComparison(schema, inputState)) return;
|
|
337
|
-
if ((state === null || typeof state === "undefined") && isContainerSchema(schema) &&
|
|
337
|
+
if (allowStructuralFallback && (state === null || typeof state === "undefined") && isContainerSchema(schema) && isEmptyStructuralInput(inputState)) state = inputState;
|
|
338
338
|
if (state === null || typeof state === "undefined") return state;
|
|
339
339
|
if (schema.type === "array") {
|
|
340
340
|
if (!Array.isArray(state)) return state;
|
|
341
341
|
const filtered = state.map((item, index) => {
|
|
342
342
|
const inputItem = Array.isArray(inputState) ? inputState[index] : void 0;
|
|
343
|
-
return normalizeStateForComparison(schema.item, item, inputItem);
|
|
343
|
+
return normalizeStateForComparison(schema.item, item, inputItem, allowStructuralFallback);
|
|
344
344
|
}).filter((item) => typeof item !== "undefined");
|
|
345
345
|
if (schema.collectionKind === "set") return sortStateValues(uniqueStateValues(filtered.filter((item) => item !== null)));
|
|
346
346
|
return filtered;
|
|
@@ -349,7 +349,7 @@ const normalizeStateForComparison = (schema, state, inputState) => {
|
|
|
349
349
|
if (typeof state !== "object" || state === null) return state;
|
|
350
350
|
return Object.fromEntries(Object.entries(state).flatMap(([key, value]) => {
|
|
351
351
|
const inputValue = inputState && typeof inputState === "object" ? inputState[key] : void 0;
|
|
352
|
-
const normalized = normalizeStateForComparison(schema.item, value, inputValue);
|
|
352
|
+
const normalized = normalizeStateForComparison(schema.item, value, inputValue, allowStructuralFallback);
|
|
353
353
|
if (typeof normalized === "undefined") return [];
|
|
354
354
|
return [[key, normalized]];
|
|
355
355
|
}));
|
|
@@ -358,22 +358,22 @@ const normalizeStateForComparison = (schema, state, inputState) => {
|
|
|
358
358
|
if (typeof state !== "object" || state === null) return state;
|
|
359
359
|
const normalized = Object.fromEntries(Object.entries(schema.properties).flatMap(([key, prop]) => {
|
|
360
360
|
const stateValue = state[camelCase(key)];
|
|
361
|
-
const normalized$1 = normalizeStateForComparison(prop, stateValue, inputState && typeof inputState === "object" ? inputState[camelCase(key)] : void 0);
|
|
361
|
+
const normalized$1 = normalizeStateForComparison(prop, stateValue, inputState && typeof inputState === "object" ? inputState[camelCase(key)] : void 0, allowStructuralFallback);
|
|
362
362
|
if (typeof normalized$1 === "undefined") return [];
|
|
363
363
|
return [[camelCase(key), normalized$1]];
|
|
364
364
|
}));
|
|
365
|
-
if (Object.keys(normalized).length === 0 && isEmptyStructuralInput(inputState)) return normalizeStateForComparison(schema, inputState, inputState);
|
|
365
|
+
if (allowStructuralFallback && Object.keys(normalized).length === 0 && isEmptyStructuralInput(inputState)) return normalizeStateForComparison(schema, inputState, inputState, false);
|
|
366
366
|
return normalized;
|
|
367
367
|
}
|
|
368
368
|
if (schema.type === "array-object") {
|
|
369
369
|
if (typeof state !== "object" || state === null) return state;
|
|
370
370
|
const normalized = Object.fromEntries(Object.entries(schema.properties).flatMap(([key, prop]) => {
|
|
371
371
|
const stateValue = state[camelCase(key)];
|
|
372
|
-
const normalized$1 = normalizeStateForComparison(prop, stateValue, inputState && typeof inputState === "object" ? inputState[camelCase(key)] : void 0);
|
|
372
|
+
const normalized$1 = normalizeStateForComparison(prop, stateValue, inputState && typeof inputState === "object" ? inputState[camelCase(key)] : void 0, allowStructuralFallback);
|
|
373
373
|
if (typeof normalized$1 === "undefined") return [];
|
|
374
374
|
return [[camelCase(key), normalized$1]];
|
|
375
375
|
}));
|
|
376
|
-
if (Object.keys(normalized).length === 0 && isEmptyStructuralInput(inputState)) return normalizeStateForComparison(schema, inputState, inputState);
|
|
376
|
+
if (allowStructuralFallback && Object.keys(normalized).length === 0 && isEmptyStructuralInput(inputState)) return normalizeStateForComparison(schema, inputState, inputState, false);
|
|
377
377
|
return normalized;
|
|
378
378
|
}
|
|
379
379
|
if (schema.type === "string") {
|