@@ -34,7 +34,7 @@ import {
3434} from '../types'
3535import { getObjectValue , isArray , isDiffAdd , isDiffRemove , isDiffReplace , isNumber , isObject , typeOf } from '../utils'
3636import { ANY_COMBINER_PATH , DiffAction , JSO_ROOT } from './constants'
37- import { addDiffObjectToContainer , diffFactory , NEVER_KEY } from './diff'
37+ import { addDiffObjectToContainer , createDiffEntry , diffFactory , NEVER_KEY } from './diff'
3838import { arrayMappingResolver , objectMappingResolver } from './mapping'
3939
4040const extractDeclarationPaths = ( jso : Record < PropertyKey , unknown > , originMetaKey : symbol , property : PropertyKey ) : JsonPath [ ] => {
@@ -156,21 +156,24 @@ const cleanUpRecursive = (ctx: NodeContext): NodeContext => {
156156}
157157
158158export const getOrCreateChildDiffAdd = ( diffUniquenessCache : EvaluationCacheService , childCtx : CompareContext ) => {
159- return diffUniquenessCache . cacheEvaluationResultByFootprint < [ unknown , string , CompareScope , typeof DiffAction . add ] , DiffEntry < DiffAdd > > ( [ childCtx . after . value , buildPathsIdentifier ( childCtx . after . declarativePaths ) , childCtx . scope , DiffAction . add ] , ( ) => {
159+ const diff = diffUniquenessCache . cacheEvaluationResultByFootprint < [ unknown , string , CompareScope , typeof DiffAction . add ] , DiffAdd > ( [ childCtx . after . value , buildPathsIdentifier ( childCtx . after . declarativePaths ) , childCtx . scope , DiffAction . add ] , ( ) => {
160160 return diffFactory . added ( childCtx )
161- } , { } as DiffEntry < DiffAdd > , ( result , guard ) => {
161+ } , { } as DiffAdd , ( result , guard ) => {
162162 Object . assign ( guard , result )
163163 return guard
164164 } )
165+
166+ return createDiffEntry ( childCtx , diff )
165167}
166168
167169export const getOrCreateChildDiffRemove = ( diffUniquenessCache : EvaluationCacheService , childCtx : CompareContext ) => {
168- return diffUniquenessCache . cacheEvaluationResultByFootprint < [ unknown , string , CompareScope , typeof DiffAction . remove ] , DiffEntry < DiffRemove > > ( [ childCtx . before . value , buildPathsIdentifier ( childCtx . before . declarativePaths ) , childCtx . scope , DiffAction . remove ] , ( ) => {
170+ const diff = diffUniquenessCache . cacheEvaluationResultByFootprint < [ unknown , string , CompareScope , typeof DiffAction . remove ] , DiffRemove > ( [ childCtx . before . value , buildPathsIdentifier ( childCtx . before . declarativePaths ) , childCtx . scope , DiffAction . remove ] , ( ) => {
169171 return diffFactory . removed ( childCtx )
170- } , { } as DiffEntry < DiffRemove > , ( result , guard ) => {
172+ } , { } as DiffRemove , ( result , guard ) => {
171173 Object . assign ( guard , result )
172174 return guard
173175 } )
176+ return createDiffEntry ( childCtx , diff )
174177}
175178
176179const adaptValues = ( beforeJso : JsonNode , beforeKey : PropertyKey , afterJso : JsonNode , afterKey : PropertyKey , adapter : AdapterResolver [ ] | undefined , options : InternalCompareOptions ) => {
@@ -235,7 +238,7 @@ const useMergeFactory = (onDiff: DiffCallback, options: InternalCompareOptions):
235238
236239 const beforeKey = unsafeKey ?? ( isArray ( beforeJso ) ? + Object . keys ( keyMap ) . pop ( ) ! : Object . keys ( keyMap ) . pop ( ) )
237240 const afterKey = keyMap [ beforeKey ]
238- const mergeKey = isArray ( mergedJso ) && isNumber ( beforeKey ) ? beforeKey : afterKey //THIS IS VERY FRAGILE. Cause this logic duplicate this line mergedJsoValue[keyInMerge] = afterValue[keyInAfter]
241+ const mergeKey = isArray ( mergedJso ) && isNumber ( beforeKey ) ? beforeKey : afterKey //gitleaks:allow //THIS IS VERY FRAGILE. Cause this logic duplicate this line mergedJsoValue[keyInMerge] = afterValue[keyInAfter]
239242
240243 // skip if node was removed
241244 if ( ! ( beforeKey in keyMap ) ) {
@@ -265,7 +268,7 @@ const useMergeFactory = (onDiff: DiffCallback, options: InternalCompareOptions):
265268
266269 const reuseResult : ReusableMergeResult = mergedJsoCache . cacheEvaluationResultByFootprint < [ typeof ctx . before . value , typeof ctx . after . value , typeof beforeDeclarativePathsId , typeof afterDeclarativePathsId , CompareScope ] , ReusableMergeResult > ( [ ctx . before . value , ctx . after . value , beforeDeclarativePathsId , afterDeclarativePathsId , ctx . scope ] , ( [ beforeValue , afterValue ] ) => {
267270 if ( ! ignoreKeyDifference && beforeKey !== afterKey ) {
268- const diffEntry = diffFactory . renamed ( ctx )
271+ const diffEntry = createDiffEntry ( ctx , diffFactory . renamed ( ctx ) )
269272 addDiff ( diffEntry . diff )
270273 addDiffObjectToContainer ( mergedJso , metaKey , [ diffEntry ] )
271274 }
@@ -279,7 +282,7 @@ const useMergeFactory = (onDiff: DiffCallback, options: InternalCompareOptions):
279282
280283 // types are different
281284 if ( typeOf ( beforeValue ) !== typeOf ( afterValue ) ) {
282- const diffEntry = diffFactory . replaced ( ctx )
285+ const diffEntry = createDiffEntry ( ctx , diffFactory . replaced ( ctx ) )
283286 addDiff ( diffEntry . diff )
284287 return { diffsToPullUp : [ diffEntry ] , mergedValue : afterValue } satisfies ReusableMergeResult
285288 }
@@ -336,7 +339,7 @@ const useMergeFactory = (onDiff: DiffCallback, options: InternalCompareOptions):
336339 diffsToPullUp : diffsToPullUp ,
337340 }
338341 if ( beforeValue !== afterValue ) {
339- const diffEntry = diffFactory . replaced ( ctx )
342+ const diffEntry = createDiffEntry ( ctx , diffFactory . replaced ( ctx ) )
340343 diffsToPullUp . push ( diffEntry )
341344 addDiff ( diffEntry . diff )
342345 }
0 commit comments