@@ -0,0 +1,41 @@
|
||||
function canonical(value: unknown): unknown {
|
||||
if (Array.isArray(value)) return value.map(canonical);
|
||||
if (value !== null && typeof value === 'object') {
|
||||
return Object.fromEntries(
|
||||
Object.entries(value)
|
||||
.sort(([a], [b]) => a.localeCompare(b))
|
||||
.map(([key, item]) => [key, canonical(item)]),
|
||||
);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function preparation(data: Record<string, unknown>): unknown {
|
||||
const { operation_key: _operationKey, ...fields } = data;
|
||||
return canonical({
|
||||
...fields,
|
||||
items: Array.isArray(fields.items)
|
||||
? fields.items.map((item) => {
|
||||
if (
|
||||
item !== null &&
|
||||
typeof item === 'object' &&
|
||||
!Array.isArray(item)
|
||||
) {
|
||||
const { key: _rowKey, ...values } = item;
|
||||
return values;
|
||||
}
|
||||
return item;
|
||||
})
|
||||
: fields.items,
|
||||
});
|
||||
}
|
||||
|
||||
export function hasPreparationChanges(
|
||||
initial: Record<string, unknown>,
|
||||
current: Record<string, unknown>,
|
||||
): boolean {
|
||||
return (
|
||||
JSON.stringify(preparation(initial)) !==
|
||||
JSON.stringify(preparation(current))
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user