remove datatypediff

This commit is contained in:
Ben Irvin 2023-01-30 10:15:47 +01:00
parent 12b0807384
commit e027d73fe3
3 changed files with 13 additions and 43 deletions

View File

@ -372,11 +372,12 @@ class TransferEngine<
}
if (diff.kind === 'modified') {
return `Schema value changed at "${path}": "${diff.values[0]}" (${diff.types[0]}) => "${diff.values[1]}" (${diff.types[1]})`;
}
// eslint-disable-next-line eqeqeq
if (diff.values[0] == diff.values[1]) {
return `Schema has differing data types at "${path}": "${diff.values[0]}" (${diff.types[0]}) => "${diff.values[1]}" (${diff.types[1]})`;
}
if (diff.kind === 'dataType') {
return `Schema has differing data types at "${path}": "${diff.values[0]}" (${diff.types[0]}) => "${diff.values[1]}" (${diff.types[1]})`;
return `Schema value changed at "${path}": "${diff.values[0]}" (${diff.types[0]}) => "${diff.values[1]}" (${diff.types[1]})`;
}
throw new TransferEngineValidationError(`Invalid diff found for "${uid}"`, {

View File

@ -11,16 +11,14 @@ const strategies = {
strict(diffs: Diff[]) {
const isIgnorableDiff = (diff: Diff) => {
return (
// Ignore cases where one field is missing and the other is falsey
(diff.kind === 'dataType' && diff.types.includes('undefined')) ||
// Ignore cases where...
(diff.path.length === 3 &&
// Root property must be attributes
diff.path[0] === 'attributes' &&
// Need a valid string attribute name
typeof diff.path[1] === 'string' &&
// The diff must be on ignorable attribute properties
['private', 'required', 'configurable'].includes(diff.path[2]))
diff.path.length === 3 &&
// Root property must be attributes
diff.path[0] === 'attributes' &&
// Need a valid string attribute name
typeof diff.path[1] === 'string' &&
// The diff must be on ignorable attribute properties
['private', 'required', 'configurable'].includes(diff.path[2])
);
};

View File

@ -2,14 +2,6 @@ import { isArray, isObject, zip, isEqual, uniq } from 'lodash/fp';
const createContext = (): Context => ({ path: [] });
const isLooselyEqual = (a: unknown, b: unknown) => {
// eslint-disable-next-line eqeqeq
if (a == b) {
return true;
}
return false;
};
/**
* Compute differences between two JSON objects and returns them
*
@ -46,16 +38,6 @@ export const diff = (a: unknown, b: unknown, ctx: Context = createContext()): Di
return diffs;
};
const dataType = () => {
diffs.push({
kind: 'dataType',
path,
types: [aType, bType],
values: [a, b],
});
return diffs;
};
if (isArray(a) && isArray(b)) {
let k = 0;
@ -87,10 +69,6 @@ export const diff = (a: unknown, b: unknown, ctx: Context = createContext()): Di
}
if (!isEqual(a, b)) {
if (isLooselyEqual(a, b)) {
return dataType();
}
if (aType === 'undefined') {
return added();
}
@ -126,14 +104,7 @@ export interface DeletedDiff<T = unknown> {
value: T;
}
export interface DataTypeDiff<T = unknown, P = unknown> {
kind: 'dataType';
path: string[];
types: [string, string];
values: [T, P];
}
export type Diff = AddedDiff | ModifiedDiff | DeletedDiff | DataTypeDiff;
export type Diff = AddedDiff | ModifiedDiff | DeletedDiff;
export interface Context {
path: string[];