Skip to content

Commit

Permalink
chore(release): 4.0.0 [skip ci]
Browse files Browse the repository at this point in the history
# [4.0.0](v3.0.1...v4.0.0) (2022-02-26)

### Bug Fixes

* improve meta data typings ([#61](#61)) ([9a881d3](9a881d3))

### Features

* allow for default merging via a special return value ([658d1fd](658d1fd))
* allow for implicit default merging ([1d5e617](1d5e617))
* allow for skipping properties completely via a special return value ([#64](#64)) ([676f2f6](676f2f6))

### BREAKING CHANGES

* MetaMetaData now must extends DeepMergeBuiltInMetaData
  • Loading branch information
semantic-release-bot committed Feb 26, 2022
1 parent beae8b8 commit 52457da
Show file tree
Hide file tree
Showing 6 changed files with 474 additions and 116 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
# Changelog
All notable changes to this project will be documented in this file. Dates are displayed in UTC.

# [4.0.0](https://github.com/RebeccaStevens/deepmerge-ts/compare/v3.0.1...v4.0.0) (2022-02-26)


### Bug Fixes

* improve meta data typings ([#61](https://github.com/RebeccaStevens/deepmerge-ts/issues/61)) ([9a881d3](https://github.com/RebeccaStevens/deepmerge-ts/commit/9a881d3e55762da03b0d0f465d7e958d81fd0958))


### Features

* allow for default merging via a special return value ([658d1fd](https://github.com/RebeccaStevens/deepmerge-ts/commit/658d1fd454fe095e6c7f2be22ccf4823fe0ea6ef))
* allow for implicit default merging ([1d5e617](https://github.com/RebeccaStevens/deepmerge-ts/commit/1d5e617bc4980f64a75fa9da1397979b2310fc06))
* allow for skipping properties completely via a special return value ([#64](https://github.com/RebeccaStevens/deepmerge-ts/issues/64)) ([676f2f6](https://github.com/RebeccaStevens/deepmerge-ts/commit/676f2f6593d6baf0e1b31f29c83bac7c392e7ce2))


### BREAKING CHANGES

* MetaMetaData now must extends DeepMergeBuiltInMetaData

## [3.0.1](https://github.com/RebeccaStevens/deepmerge-ts/compare/v3.0.0...v3.0.1) (2022-02-22)


Expand Down
236 changes: 195 additions & 41 deletions dist/deno/deepmerge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,21 @@ import {
} from "./utils.ts";

const defaultMergeFunctions = {
mergeMaps,
mergeSets,
mergeArrays,
mergeRecords,
mergeMaps: defaultMergeMaps,
mergeSets: defaultMergeSets,
mergeArrays: defaultMergeArrays,
mergeRecords: defaultMergeRecords,
mergeOthers: leaf,
} as const;

/**
* Special values that tell deepmerge-ts to perform a certain action.
*/
const actions = {
defaultMerge: Symbol("deepmerge-ts: default merge"),
skip: Symbol("deepmerge-ts: skip"),
} as const;

/**
* The default function to update meta data.
*/
Expand Down Expand Up @@ -87,9 +95,7 @@ export function deepmergeCustom<
export function deepmergeCustom<
PMF extends Partial<DeepMergeMergeFunctionsURIs>,
MetaData,
MetaMetaData extends Readonly<
Record<PropertyKey, unknown>
> = DeepMergeBuiltInMetaData
MetaMetaData extends DeepMergeBuiltInMetaData = DeepMergeBuiltInMetaData
>(
options: DeepMergeOptions<MetaData, MetaMetaData>,
rootMetaData?: MetaData
Expand All @@ -100,7 +106,7 @@ export function deepmergeCustom<
export function deepmergeCustom<
PMF extends Partial<DeepMergeMergeFunctionsURIs>,
MetaData,
MetaMetaData extends Readonly<Record<PropertyKey, unknown>>
MetaMetaData extends DeepMergeBuiltInMetaData
>(
options: DeepMergeOptions<MetaData, MetaMetaData>,
rootMetaData?: MetaData
Expand Down Expand Up @@ -140,7 +146,7 @@ export function deepmergeCustom<
*
* @param options - The options the user specified
*/
function getUtils<M, MM extends Readonly<Record<PropertyKey, unknown>>>(
function getUtils<M, MM extends DeepMergeBuiltInMetaData>(
options: DeepMergeOptions<M, MM>,
customizedDeepmerge: DeepMergeMergeFunctionUtils<M, MM>["deepmerge"]
): DeepMergeMergeFunctionUtils<M, MM> {
Expand All @@ -164,6 +170,8 @@ function getUtils<M, MM extends Readonly<Record<PropertyKey, unknown>>>(
MM
>["metaDataUpdater"],
deepmerge: customizedDeepmerge,
useImplicitDefaultMerging: options.enableImplicitDefaultMerging ?? false,
actions,
};
}

Expand All @@ -177,17 +185,17 @@ function mergeUnknowns<
U extends DeepMergeMergeFunctionUtils<M, MM>,
MF extends DeepMergeMergeFunctionsURIs,
M,
MM extends Readonly<Record<PropertyKey, unknown>>
MM extends DeepMergeBuiltInMetaData
>(values: Ts, utils: U, meta: M | undefined): DeepMergeHKT<Ts, MF, M> {
if (values.length === 0) {
return undefined as DeepMergeHKT<Ts, MF, M>;
}
if (values.length === 1) {
return utils.mergeFunctions.mergeOthers(
values,
utils,
meta
) as DeepMergeHKT<Ts, MF, M>;
return mergeOthers<U, M, MM>(values, utils, meta) as DeepMergeHKT<
Ts,
MF,
M
>;
}

const type = getObjectType(values[0]);
Expand All @@ -200,49 +208,49 @@ function mergeUnknowns<
continue;
}

return utils.mergeFunctions.mergeOthers(
values,
utils,
meta
) as DeepMergeHKT<Ts, MF, M>;
return mergeOthers<U, M, MM>(values, utils, meta) as DeepMergeHKT<
Ts,
MF,
M
>;
}
}

switch (type) {
case ObjectType.RECORD:
return utils.mergeFunctions.mergeRecords(
return mergeRecords<U, MF, M, MM>(
values as ReadonlyArray<Readonly<Record<PropertyKey, unknown>>>,
utils,
meta
) as DeepMergeHKT<Ts, MF, M>;

case ObjectType.ARRAY:
return utils.mergeFunctions.mergeArrays(
return mergeArrays<U, M, MM>(
values as ReadonlyArray<Readonly<ReadonlyArray<unknown>>>,
utils,
meta
) as DeepMergeHKT<Ts, MF, M>;

case ObjectType.SET:
return utils.mergeFunctions.mergeSets(
return mergeSets<U, M, MM>(
values as ReadonlyArray<Readonly<ReadonlySet<unknown>>>,
utils,
meta
) as DeepMergeHKT<Ts, MF, M>;

case ObjectType.MAP:
return utils.mergeFunctions.mergeMaps(
return mergeMaps<U, M, MM>(
values as ReadonlyArray<Readonly<ReadonlyMap<unknown, unknown>>>,
utils,
meta
) as DeepMergeHKT<Ts, MF, M>;

default:
return utils.mergeFunctions.mergeOthers(
values,
utils,
meta
) as DeepMergeHKT<Ts, MF, M>;
return mergeOthers<U, M, MM>(values, utils, meta) as DeepMergeHKT<
Ts,
MF,
M
>;
}
}

Expand All @@ -252,6 +260,148 @@ function mergeUnknowns<
* @param values - The records.
*/
function mergeRecords<
U extends DeepMergeMergeFunctionUtils<M, MM>,
MF extends DeepMergeMergeFunctionsURIs,
M,
MM extends DeepMergeBuiltInMetaData
>(
values: ReadonlyArray<Readonly<Record<PropertyKey, unknown>>>,
utils: U,
meta: M | undefined
) {
const result = utils.mergeFunctions.mergeRecords(values, utils, meta);

if (
result === actions.defaultMerge ||
(utils.useImplicitDefaultMerging &&
result === undefined &&
utils.mergeFunctions.mergeRecords !==
utils.defaultMergeFunctions.mergeRecords)
) {
return utils.defaultMergeFunctions.mergeRecords<
ReadonlyArray<Readonly<Record<PropertyKey, unknown>>>,
U,
MF,
M,
MM
>(values, utils, meta);
}

return result;
}

/**
* Merge arrays.
*
* @param values - The arrays.
*/
function mergeArrays<
U extends DeepMergeMergeFunctionUtils<M, MM>,
M,
MM extends DeepMergeBuiltInMetaData
>(
values: ReadonlyArray<Readonly<ReadonlyArray<unknown>>>,
utils: U,
meta: M | undefined
) {
const result = utils.mergeFunctions.mergeArrays(values, utils, meta);

if (
result === actions.defaultMerge ||
(utils.useImplicitDefaultMerging &&
result === undefined &&
utils.mergeFunctions.mergeArrays !==
utils.defaultMergeFunctions.mergeArrays)
) {
return utils.defaultMergeFunctions.mergeArrays(values);
}
return result;
}

/**
* Merge sets.
*
* @param values - The sets.
*/
function mergeSets<
U extends DeepMergeMergeFunctionUtils<M, MM>,
M,
MM extends DeepMergeBuiltInMetaData
>(
values: ReadonlyArray<Readonly<ReadonlySet<unknown>>>,
utils: U,
meta: M | undefined
) {
const result = utils.mergeFunctions.mergeSets(values, utils, meta);

if (
result === actions.defaultMerge ||
(utils.useImplicitDefaultMerging &&
result === undefined &&
utils.mergeFunctions.mergeSets !== utils.defaultMergeFunctions.mergeSets)
) {
return utils.defaultMergeFunctions.mergeSets(values);
}
return result;
}

/**
* Merge maps.
*
* @param values - The maps.
*/
function mergeMaps<
U extends DeepMergeMergeFunctionUtils<M, MM>,
M,
MM extends DeepMergeBuiltInMetaData
>(
values: ReadonlyArray<Readonly<ReadonlyMap<unknown, unknown>>>,
utils: U,
meta: M | undefined
) {
const result = utils.mergeFunctions.mergeMaps(values, utils, meta);

if (
result === actions.defaultMerge ||
(utils.useImplicitDefaultMerging &&
result === undefined &&
utils.mergeFunctions.mergeMaps !== utils.defaultMergeFunctions.mergeMaps)
) {
return utils.defaultMergeFunctions.mergeMaps(values);
}
return result;
}

/**
* Merge other things.
*
* @param values - The other things.
*/
function mergeOthers<
U extends DeepMergeMergeFunctionUtils<M, MM>,
M,
MM extends DeepMergeBuiltInMetaData
>(values: ReadonlyArray<unknown>, utils: U, meta: M | undefined) {
const result = utils.mergeFunctions.mergeOthers(values, utils, meta);

if (
result === actions.defaultMerge ||
(utils.useImplicitDefaultMerging &&
result === undefined &&
utils.mergeFunctions.mergeOthers !==
utils.defaultMergeFunctions.mergeOthers)
) {
return utils.defaultMergeFunctions.mergeOthers(values);
}
return result;
}

/**
* The default strategy to merge records.
*
* @param values - The records.
*/
function defaultMergeRecords<
Ts extends ReadonlyArray<Record<PropertyKey, unknown>>,
U extends DeepMergeMergeFunctionUtils<M, MM>,
MF extends DeepMergeMergeFunctionsURIs,
Expand All @@ -278,11 +428,17 @@ function mergeRecords<
parents: values,
} as unknown as MM);

result[key] = mergeUnknowns<ReadonlyArray<unknown>, U, MF, M, MM>(
const propertyResult = mergeUnknowns<ReadonlyArray<unknown>, U, MF, M, MM>(
propValues,
utils,
updatedMeta
);

if (propertyResult === actions.skip) {
continue;
}

result[key] = propertyResult;
}

/* eslint-enable functional/no-loop-statement, functional/no-conditional-statement */
Expand All @@ -291,11 +447,11 @@ function mergeRecords<
}

/**
* Merge arrays.
* The default strategy to merge arrays.
*
* @param values - The arrays.
*/
function mergeArrays<
function defaultMergeArrays<
Ts extends ReadonlyArray<ReadonlyArray<unknown>>,
MF extends DeepMergeMergeFunctionsURIs,
M
Expand All @@ -304,31 +460,29 @@ function mergeArrays<
}

/**
* Merge sets.
* The default strategy to merge sets.
*
* @param values - The sets.
*/
function mergeSets<Ts extends ReadonlyArray<Readonly<ReadonlySet<unknown>>>>(
values: Ts
) {
function defaultMergeSets<
Ts extends ReadonlyArray<Readonly<ReadonlySet<unknown>>>
>(values: Ts) {
return new Set(getIterableOfIterables(values)) as DeepMergeSetsDefaultHKT<Ts>;
}

/**
* Merge maps.
* The default strategy to merge maps.
*
* @param values - The maps.
*/
function mergeMaps<
function defaultMergeMaps<
Ts extends ReadonlyArray<Readonly<ReadonlyMap<unknown, unknown>>>
>(values: Ts) {
return new Map(getIterableOfIterables(values)) as DeepMergeMapsDefaultHKT<Ts>;
}

/**
* Merge "other" things.
*
* @param values - The values.
* Get the last value in the given array.
*/
function leaf<Ts extends ReadonlyArray<unknown>>(values: Ts) {
return values[values.length - 1];
Expand Down
Loading

0 comments on commit 52457da

Please sign in to comment.