Skip to content

Commit c44a858

Browse files
authoredFeb 27, 2025··
fix(core): rename internal deepEquals to deepEqualsIgnoreKey (#8790)
1 parent 902e2db commit c44a858

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed
 

‎packages/sanity/src/core/validation/util/deepEquals.ts ‎packages/sanity/src/core/validation/util/deepEqualsIgnoreKey.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
// works when type predicate is called inline in the condition that starts the
99
// control flow branch.
1010
// see here: https://www.typescriptlang.org/docs/handbook/2/narrowing.html
11-
export function deepEquals(a: unknown, b: unknown): boolean {
11+
export function deepEqualsIgnoreKey(a: unknown, b: unknown): boolean {
1212
if (a === b) {
1313
return true
1414
}
1515

1616
if (Array.isArray(a) && Array.isArray(b)) {
1717
if (a.length != b.length) return false
1818
for (let i = 0; i < a.length; i++) {
19-
if (!deepEquals(a[i], b[i])) {
19+
if (!deepEqualsIgnoreKey(a[i], b[i])) {
2020
return false
2121
}
2222
}
@@ -65,7 +65,7 @@ export function deepEquals(a: unknown, b: unknown): boolean {
6565
continue
6666
}
6767

68-
if (!deepEquals(a[key], b[key])) {
68+
if (!deepEqualsIgnoreKey(a[key], b[key])) {
6969
return false
7070
}
7171
}

‎packages/sanity/src/core/validation/validators/arrayValidator.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
type Validators,
66
} from '@sanity/types'
77

8-
import {deepEquals} from '../util/deepEquals'
8+
import {deepEqualsIgnoreKey} from '../util/deepEqualsIgnoreKey'
99
import {genericValidators} from './genericValidator'
1010

1111
export const arrayValidators: Validators = {
@@ -55,7 +55,7 @@ export const arrayValidators: Validators = {
5555
const paths: Path[] = []
5656
for (let i = 0; i < values.length; i++) {
5757
const value = values[i]
58-
if (allowedValues.some((expected) => deepEquals(expected, value))) {
58+
if (allowedValues.some((expected) => deepEqualsIgnoreKey(expected, value))) {
5959
continue
6060
}
6161

@@ -80,7 +80,7 @@ export const arrayValidators: Validators = {
8080
const itemA = value[x]
8181
const itemB = value[y]
8282

83-
if (!deepEquals(itemA, itemB)) {
83+
if (!deepEqualsIgnoreKey(itemA, itemB)) {
8484
continue
8585
}
8686

‎packages/sanity/src/core/validation/validators/genericValidator.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {type ValidationMarker, type Validators} from '@sanity/types'
22

33
import {type LocaleSource} from '../../i18n'
4-
import {deepEquals} from '../util/deepEquals'
4+
import {deepEqualsIgnoreKey} from '../util/deepEqualsIgnoreKey'
55
import {isLocalizedMessages, localizeMessage} from '../util/localizeMessage'
66
import {pathToString} from '../util/pathToString'
77
import {typeString} from '../util/typeString'
@@ -84,7 +84,7 @@ export const genericValidators: Validators = {
8484
const value = (valueType === 'number' || valueType === 'string') && `${actual}`
8585
const strValue = value && value.length > 30 ? `${value.slice(0, 30)}…` : value
8686

87-
return allowedValues.some((expected) => deepEquals(expected, actual))
87+
return allowedValues.some((expected) => deepEqualsIgnoreKey(expected, actual))
8888
? true
8989
: message ||
9090
i18n.t(

0 commit comments

Comments
 (0)
Please sign in to comment.