-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: provide customizable meta data to custom merge functions
fix #33
1 parent
aef30eb
commit 9831269
Showing
11 changed files
with
682 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,97 @@ | ||
import type { DeepMergeMergeFunctionsDefaults } from "@/deepmerge"; | ||
|
||
import type { DeepMergeBuiltInMetaData } from "./merging"; | ||
|
||
/** | ||
* The options the user can pass to customize deepmerge. | ||
*/ | ||
export type DeepMergeOptions = Partial<DeepMergeOptionsFull>; | ||
export type DeepMergeOptions< | ||
M, | ||
MM extends Record<PropertyKey, unknown> = DeepMergeBuiltInMetaData | ||
> = Partial<DeepMergeOptionsFull<M, MM & Partial<DeepMergeBuiltInMetaData>>>; | ||
|
||
type MetaDataUpdater<M, MM extends Record<PropertyKey, unknown>> = ( | ||
previousMeta: M | undefined, | ||
metaMeta: MM | ||
) => M; | ||
|
||
/** | ||
* All the options the user can pass to customize deepmerge. | ||
*/ | ||
type DeepMergeOptionsFull = Readonly<{ | ||
mergeRecords: DeepMergeMergeFunctions["mergeRecords"] | false; | ||
mergeArrays: DeepMergeMergeFunctions["mergeArrays"] | false; | ||
mergeMaps: DeepMergeMergeFunctions["mergeMaps"] | false; | ||
mergeSets: DeepMergeMergeFunctions["mergeSets"] | false; | ||
mergeOthers: DeepMergeMergeFunctions["mergeOthers"]; | ||
type DeepMergeOptionsFull< | ||
M, | ||
MM extends Record<PropertyKey, unknown> | ||
> = Readonly<{ | ||
mergeRecords: DeepMergeMergeFunctions<M, MM>["mergeRecords"] | false; | ||
mergeArrays: DeepMergeMergeFunctions<M, MM>["mergeArrays"] | false; | ||
mergeMaps: DeepMergeMergeFunctions<M, MM>["mergeMaps"] | false; | ||
mergeSets: DeepMergeMergeFunctions<M, MM>["mergeSets"] | false; | ||
mergeOthers: DeepMergeMergeFunctions<M, MM>["mergeOthers"]; | ||
metaDataUpdater: MetaDataUpdater<M, MM>; | ||
}>; | ||
|
||
/** | ||
* All the merge functions that deepmerge uses. | ||
*/ | ||
type DeepMergeMergeFunctions = Readonly<{ | ||
type DeepMergeMergeFunctions< | ||
M, | ||
MM extends Record<PropertyKey, unknown> | ||
> = Readonly<{ | ||
mergeRecords: < | ||
Ts extends ReadonlyArray<Readonly<Record<PropertyKey, unknown>>>, | ||
U extends DeepMergeMergeFunctionUtils | ||
U extends DeepMergeMergeFunctionUtils<M, MM> | ||
>( | ||
records: Ts, | ||
utils: U | ||
utils: U, | ||
meta: M | undefined | ||
) => unknown; | ||
|
||
mergeArrays: < | ||
Ts extends ReadonlyArray<ReadonlyArray<unknown>>, | ||
U extends DeepMergeMergeFunctionUtils | ||
U extends DeepMergeMergeFunctionUtils<M, MM> | ||
>( | ||
records: Ts, | ||
utils: U | ||
utils: U, | ||
meta: M | undefined | ||
) => unknown; | ||
|
||
mergeMaps: < | ||
Ts extends ReadonlyArray<Readonly<ReadonlyMap<unknown, unknown>>>, | ||
U extends DeepMergeMergeFunctionUtils | ||
U extends DeepMergeMergeFunctionUtils<M, MM> | ||
>( | ||
records: Ts, | ||
utils: U | ||
utils: U, | ||
meta: M | undefined | ||
) => unknown; | ||
|
||
mergeSets: < | ||
Ts extends ReadonlyArray<Readonly<ReadonlySet<unknown>>>, | ||
U extends DeepMergeMergeFunctionUtils | ||
U extends DeepMergeMergeFunctionUtils<M, MM> | ||
>( | ||
records: Ts, | ||
utils: U | ||
utils: U, | ||
meta: M | undefined | ||
) => unknown; | ||
|
||
mergeOthers: < | ||
Ts extends ReadonlyArray<unknown>, | ||
U extends DeepMergeMergeFunctionUtils | ||
U extends DeepMergeMergeFunctionUtils<M, MM> | ||
>( | ||
records: Ts, | ||
utils: U | ||
utils: U, | ||
meta: M | undefined | ||
) => unknown; | ||
}>; | ||
|
||
/** | ||
* The utils provided to the merge functions. | ||
*/ | ||
export type DeepMergeMergeFunctionUtils = Readonly<{ | ||
mergeFunctions: DeepMergeMergeFunctions; | ||
export type DeepMergeMergeFunctionUtils< | ||
M, | ||
MM extends Record<PropertyKey, unknown> | ||
> = Readonly<{ | ||
mergeFunctions: DeepMergeMergeFunctions<M, MM>; | ||
defaultMergeFunctions: DeepMergeMergeFunctionsDefaults; | ||
metaDataUpdater: MetaDataUpdater<M, MM>; | ||
deepmerge: <Ts extends ReadonlyArray<unknown>>(...values: Ts) => unknown; | ||
}>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export function areAllNumbers( | ||
values: ReadonlyArray<unknown> | ||
): values is ReadonlyArray<number> { | ||
return values.every((value) => typeof value === "number"); | ||
} | ||
|
||
export function hasProp<T, K extends PropertyKey>( | ||
value: T, | ||
prop: K | ||
): value is T & Record<K, unknown> { | ||
return typeof value === "object" && value !== null && prop in value; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters