42 lines
894 B
TypeScript
42 lines
894 B
TypeScript
import { isDeepStrictEqual } from 'node:util';
|
|
|
|
const TRACKED_FIELDS = [
|
|
'code',
|
|
'name',
|
|
'commonName',
|
|
'description',
|
|
'type',
|
|
'parent',
|
|
'operationalArea',
|
|
'operatorCompany',
|
|
'informationStatus',
|
|
'operationalStatus',
|
|
'organizationProfile',
|
|
'organizationMemberships',
|
|
'externalIdentifiers',
|
|
'sourceDocuments',
|
|
'legalRights',
|
|
'attributes',
|
|
'geometry',
|
|
'media',
|
|
'provenance',
|
|
] as const;
|
|
|
|
export function changedSnapshotFields(
|
|
previous: Record<string, unknown> | null,
|
|
current: Record<string, unknown>,
|
|
): string[] {
|
|
if (!previous) {
|
|
return TRACKED_FIELDS.filter((field) => {
|
|
const value = current[field];
|
|
return value !== null && value !== undefined && !(
|
|
Array.isArray(value) && value.length === 0
|
|
);
|
|
});
|
|
}
|
|
|
|
return TRACKED_FIELDS.filter(
|
|
(field) => !isDeepStrictEqual(previous[field], current[field]),
|
|
);
|
|
}
|