From 0fd5e8c6fa4c3f5a1e12d2ac84a81940291bcffb Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Sat, 5 Oct 2024 00:12:53 +1300 Subject: [PATCH 1/2] build: remove deno and jsr --- .../workflows/{build-node.yml => build.yml} | 4 +- .github/workflows/check-dist-files.yml | 60 -- .github/workflows/release.yml | 1 + .gitignore | 1 - .releaserc.yml | 1 + README.md | 25 +- cspell.config.yml | 1 + dist/deno/LICENSE | 29 - dist/deno/README.md | 180 ---- dist/deno/actions.ts | 14 - dist/deno/deepmerge-into.ts | 420 --------- dist/deno/deepmerge.ts | 371 -------- dist/deno/defaults/general.ts | 25 - dist/deno/defaults/into.ts | 136 --- dist/deno/defaults/vanilla.ts | 137 --- dist/deno/index.ts | 32 - dist/deno/mod.ts | 1 - dist/deno/types/defaults.ts | 363 -------- dist/deno/types/index.ts | 3 - dist/deno/types/merging.ts | 208 ----- dist/deno/types/options.ts | 228 ----- dist/deno/types/utils.ts | 337 ------- dist/deno/utils.ts | 141 --- dist/node/index.cjs | 623 ------------- dist/node/index.d.cts | 849 ------------------ dist/node/index.d.mts | 849 ------------------ dist/node/index.mjs | 615 ------------- jsr.json | 5 + package.json | 28 +- pnpm-lock.yaml | 166 +--- project-dictionary.txt | 1 - tsconfig.build.deno.json | 7 - 32 files changed, 73 insertions(+), 5788 deletions(-) rename .github/workflows/{build-node.yml => build.yml} (80%) delete mode 100644 .github/workflows/check-dist-files.yml delete mode 100644 dist/deno/LICENSE delete mode 100644 dist/deno/README.md delete mode 100644 dist/deno/actions.ts delete mode 100644 dist/deno/deepmerge-into.ts delete mode 100644 dist/deno/deepmerge.ts delete mode 100644 dist/deno/defaults/general.ts delete mode 100644 dist/deno/defaults/into.ts delete mode 100644 dist/deno/defaults/vanilla.ts delete mode 100644 dist/deno/index.ts delete mode 100644 dist/deno/mod.ts delete mode 100644 dist/deno/types/defaults.ts delete mode 100644 dist/deno/types/index.ts delete mode 100644 dist/deno/types/merging.ts delete mode 100644 dist/deno/types/options.ts delete mode 100644 dist/deno/types/utils.ts delete mode 100644 dist/deno/utils.ts delete mode 100644 dist/node/index.cjs delete mode 100644 dist/node/index.d.cts delete mode 100644 dist/node/index.d.mts delete mode 100644 dist/node/index.mjs create mode 100644 jsr.json delete mode 100644 tsconfig.build.deno.json diff --git a/.github/workflows/build-node.yml b/.github/workflows/build.yml similarity index 80% rename from .github/workflows/build-node.yml rename to .github/workflows/build.yml index d670bbf5..0c5d026b 100644 --- a/.github/workflows/build-node.yml +++ b/.github/workflows/build.yml @@ -6,9 +6,9 @@ on: workflow_call: jobs: - build_node: + build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: ./.github/actions/prepare - - run: pnpm run build:node + - run: pnpm run build diff --git a/.github/workflows/check-dist-files.yml b/.github/workflows/check-dist-files.yml deleted file mode 100644 index 9a339bd8..00000000 --- a/.github/workflows/check-dist-files.yml +++ /dev/null @@ -1,60 +0,0 @@ -name: Check for dist file changes - -# From https://github.com/github/docs/blob/main/.github/workflows/triage-unallowed-contributions.yml - -on: - pull_request_target: - paths: - - "dist/**" - -permissions: - pull-requests: write - -jobs: - triage: - if: >- - ${{ - github.event.pull_request.user.login != 'semantic-release-bot' - }} - runs-on: ubuntu-latest - steps: - - name: Get files changed - uses: dorny/paths-filter@v3 - id: filter - with: - # Base branch used to get changed files - base: "main" - - # Enables setting an output in the format in `${FILTER_NAME}_files - # with the names of the matching files formatted as JSON array - list-files: json - - # Returns list of changed files matching each filter - filters: | - notAllowed: - - 'dist/**' - - # When there are changes to files we can't accept, leave a comment - # explaining this to the PR author - - name: "Comment about changes we can't accept" - if: ${{ steps.filter.outputs.notAllowed }} - uses: actions/github-script@v7 - with: - script: | - let reviewMessage = "👋 Hey there. It looks like you've modified some of the `dist` files.\nYou'll need to revert all of the changes that you've made to these files. Once you get those files reverted, we can continue with the review process. :octocat:" - let workflowFailMessage = "It looks like you've modified some of the `dist` files." - - try { - createdComment = await github.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: context.payload.number, - body: reviewMessage, - }) - - workflowFailMessage = `${workflowFailMessage} Please see ${createdComment.data.html_url} for details.` - } catch(err) { - console.log("Error creating comment.", err) - } - - core.setFailed(workflowFailMessage) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index fe79d599..08ffda5c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -7,6 +7,7 @@ on: permissions: contents: write + id-token: write issues: write pull-requests: write diff --git a/.gitignore b/.gitignore index 15fe09fa..501cab12 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ node_modules/ -/build/ /coverage/ /dist/ diff --git a/.releaserc.yml b/.releaserc.yml index b87b9692..6f514904 100644 --- a/.releaserc.yml +++ b/.releaserc.yml @@ -49,6 +49,7 @@ plugins: - dist - CHANGELOG.md - "@semantic-release/npm" + - "@sebbo2002/semantic-release-jsr" - - "@semantic-release/github" - releasedLabels: - "<%= nextRelease.channel === 'next' ? 'Status: Released on Next' : 'Status: Released' %>" diff --git a/README.md b/README.md index 795020ef..bd36123c 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ # DeepmergeTS [![npm version](https://img.shields.io/npm/v/deepmerge-ts.svg)](https://www.npmjs.com/package/deepmerge-ts) -[![deno version](https://img.shields.io/github/v/tag/RebeccaStevens/deepmerge-ts?label=deno&sort=semver)](https://deno.land/x/deepmergets) +[![jsr Version](https://img.shields.io/jsr/v/@rebeccastevens/deepmerge)](https://jsr.io/@rebeccastevens/deepmerge) [![CI](https://github.com/RebeccaStevens/deepmerge-ts/actions/workflows/release.yml/badge.svg)](https://github.com/RebeccaStevens/deepmerge-ts/actions/workflows/release.yml) [![Coverage Status](https://codecov.io/gh/RebeccaStevens/deepmerge-ts/branch/main/graph/badge.svg?token=MVpR1oAbIT)](https://codecov.io/gh/RebeccaStevens/deepmerge-ts)\ [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier) @@ -32,7 +32,7 @@ your open source software supply chain meets enterprise standards now and into t ## Installation -### Node +### npm ```sh # Install with npm @@ -43,17 +43,22 @@ pnpm add deepmerge-ts # Install with yarn yarn add deepmerge-ts + +# Install with bun +bun add deepmerge-ts ``` -### Deno +### jsr -```jsonc -// import_map.json -{ - "imports": { - "deepmerge-ts": "https://deno.land/x/deepmergets@__version__/dist/deno/index.ts", - }, -} +```sh +# Install in a node project +npx jsr add @rebeccastevens/deepmerge + +# Install in a deno project +deno add jsr:@rebeccastevens/deepmerge + +# Install in a bun project +bunx jsr add @rebeccastevens/deepmerge ``` ## Features diff --git a/cspell.config.yml b/cspell.config.yml index 3d86c053..a356336c 100644 --- a/cspell.config.yml +++ b/cspell.config.yml @@ -60,6 +60,7 @@ overrides: - filename: "**/*.yml" ignoreRegExpList: - /^\s*(?:[a-z0-9]|-|_|\"|')+:/ui # ignore keys + - /@[a-z0-9-]+\/[a-z0-9-]+/u # scoped packages - filename: ".github/(actions|workflows)/*.yml" ignoreRegExpList: diff --git a/dist/deno/LICENSE b/dist/deno/LICENSE deleted file mode 100644 index 13b6199e..00000000 --- a/dist/deno/LICENSE +++ /dev/null @@ -1,29 +0,0 @@ -BSD 3-Clause License - -Copyright (c) 2021, Rebecca Stevens -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -3. Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/dist/deno/README.md b/dist/deno/README.md deleted file mode 100644 index 795020ef..00000000 --- a/dist/deno/README.md +++ /dev/null @@ -1,180 +0,0 @@ -
- -# DeepmergeTS - -[![npm version](https://img.shields.io/npm/v/deepmerge-ts.svg)](https://www.npmjs.com/package/deepmerge-ts) -[![deno version](https://img.shields.io/github/v/tag/RebeccaStevens/deepmerge-ts?label=deno&sort=semver)](https://deno.land/x/deepmergets) -[![CI](https://github.com/RebeccaStevens/deepmerge-ts/actions/workflows/release.yml/badge.svg)](https://github.com/RebeccaStevens/deepmerge-ts/actions/workflows/release.yml) -[![Coverage Status](https://codecov.io/gh/RebeccaStevens/deepmerge-ts/branch/main/graph/badge.svg?token=MVpR1oAbIT)](https://codecov.io/gh/RebeccaStevens/deepmerge-ts)\ -[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier) -[![GitHub Discussions](https://img.shields.io/github/discussions/RebeccaStevens/deepmerge-ts?style=flat-square)](https://github.com/RebeccaStevens/deepmerge-ts/discussions) -[![BSD 3 Clause license](https://img.shields.io/github/license/RebeccaStevens/deepmerge-ts.svg?style=flat-square)](https://opensource.org/licenses/BSD-3-Clause) -[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=flat-square)](https://commitizen.github.io/cz-cli/) -[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)](https://github.com/semantic-release/semantic-release) - -Deeply merge 2 or more objects respecting type information. - -![smart merge diagram](./assets/header.png) - -
- -## Donate - -[Any donations would be much appreciated](./DONATIONS.md). 😄 - -### Enterprise Users - -`deepmerge-ts` is available as part of the Tidelift Subscription. - -Tidelift is working with the maintainers of `deepmerge-ts` and a growing network of open source maintainers to ensure -your open source software supply chain meets enterprise standards now and into the future. -[Learn more.](https://tidelift.com/subscription/pkg/npm-deepmerge-ts?utm_source=npm-deepmerge-ts&utm_medium=referral&utm_campaign=enterprise&utm_term=repo) - -## Installation - -### Node - -```sh -# Install with npm -npm install deepmerge-ts - -# Install with pnpm -pnpm add deepmerge-ts - -# Install with yarn -yarn add deepmerge-ts -``` - -### Deno - -```jsonc -// import_map.json -{ - "imports": { - "deepmerge-ts": "https://deno.land/x/deepmergets@__version__/dist/deno/index.ts", - }, -} -``` - -## Features - -- Smart merging - High performance. -- Merged output has correct typing. -- Record merging support. -- Array merging support. -- Map and Set merging support. -- Customized merging. - -## Usage - -### Example using default config - -```js -import { deepmerge } from "deepmerge-ts"; - -const x = { - record: { - prop1: "value1", - prop2: "value2", - }, - array: [1, 2, 3], - set: new Set([1, 2, 3]), - map: new Map([ - ["key1", "value1"], - ["key2", "value2"], - ]), -}; - -const y = { - record: { - prop1: "changed", - prop3: "value3", - }, - array: [2, 3, 4], - set: new Set([2, 3, 4]), - map: new Map([ - ["key2", "changed"], - ["key3", "value3"], - ]), -}; - -const z = { - record: { - prop1: undefined, - prop3: undefined, - prop2: undefined, - prop4: undefined, - }, - array: undefined, - set: undefined, - map: undefined, -}; - -const merged = deepmerge(x, y, z); - -console.log(merged); - -// Prettierfied output: -// -// Object { -// "record": Object { -// "prop1": "changed", -// "prop2": "value2", -// "prop3": "value3", -// "prop4": undefined, -// }, -// "array": Array [1, 2, 3, 2, 3, 4], -// "set": Set { 1, 2, 3, 4 }, -// "map": Map { -// "key1" => "value1", -// "key2" => "changed", -// "key3" => "value3", -// }, -// } -``` - -You can try out this example at -[codesandbox.io](https://codesandbox.io/s/deepmerge-ts-example-iltxby?file=/src/example.ts). - -### Merging into a Target - -You can use `deepmergeInto` if you want to update a target object with the merge result instead of creating a new -object. - -This function is best used with objects that are all of the same type. - -Note: If the target object's type differs from the input objects, we'll assert that the target's type has changed -(this is not done automatically with `deepmergeIntoCustom`). - -### Customized the Merging Process - -We provide a customizer function for each of our main deepmerge functions: `deepmergeCustom` and `deepmergeIntoCustom`. -You can use these to customize the details of how values should be merged together. - -See [deepmerge custom docs](./docs/deepmergeCustom.md) for more details. - -## Performance - -We use smart merging instead of the classic merging strategy which some alternative libraries use. This vastly improves -performance, both in execution time and memory usage. - -### Classic Merge (not what we do) - -With classic merging, each input is merged with the next input until all inputs are merged. - -This strategy has large performance issues when lots of items need to be merged. - -![classic merge animation](./assets/classic-merge.gif) - -### Smart Merge (what we do) - -With our smart merging, we look ahead to see what can be merged and only merge those things. - -In addition to performance improvements, this strategy merges multiple inputs at once; allowing for benefits such as -taking averages of the inputs. - -![smart merge animation](./assets/smart-merge.gif) - -## API - -See [API docs](./docs/API.md). diff --git a/dist/deno/actions.ts b/dist/deno/actions.ts deleted file mode 100644 index e597db1f..00000000 --- a/dist/deno/actions.ts +++ /dev/null @@ -1,14 +0,0 @@ -/** - * Special values that tell deepmerge to perform a certain action. - */ -export const actions = { - defaultMerge: Symbol("deepmerge-ts: default merge"), - skip: Symbol("deepmerge-ts: skip"), -} as const; - -/** - * Special values that tell deepmergeInto to perform a certain action. - */ -export const actionsInto = { - defaultMerge: actions.defaultMerge, -} as const; diff --git a/dist/deno/deepmerge-into.ts b/dist/deno/deepmerge-into.ts deleted file mode 100644 index 0abcdb2d..00000000 --- a/dist/deno/deepmerge-into.ts +++ /dev/null @@ -1,420 +0,0 @@ -import { actionsInto as actions } from "./actions.ts"; -import { - defaultFilterValues, - defaultMetaDataUpdater, -} from "./defaults/general.ts"; -import { mergeIntoFunctions as defaultMergeIntoFunctions } from "./defaults/into.ts"; -import { - type DeepMergeBuiltInMetaData, - type DeepMergeFunctionsDefaultURIs, - type DeepMergeHKT, - type DeepMergeIntoFunctionUtils, - type DeepMergeIntoOptions, - type Reference, -} from "./types/index.ts"; -import { type SimplifyObject } from "./types/utils.ts"; -import { ObjectType, getObjectType } from "./utils.ts"; - -/** - * Deeply merge objects into a target. - * - * @param target - This object will be mutated with the merge result. - * @param objects - The objects to merge into the target. - */ -export function deepmergeInto( - target: T, - ...objects: ReadonlyArray -): void; - -/** - * Deeply merge objects into a target. - * - * @param target - This object will be mutated with the merge result. - * @param objects - The objects to merge into the target. - */ -export function deepmergeInto< - Target extends object, - Ts extends ReadonlyArray, ->( - target: Target, - ...objects: Ts -): asserts target is SimplifyObject< - Target & - DeepMergeHKT< - [Target, ...Ts], - DeepMergeFunctionsDefaultURIs, - DeepMergeBuiltInMetaData - > ->; - -export function deepmergeInto< - Target extends object, - Ts extends ReadonlyArray, ->( - target: Target, - ...objects: Ts -): asserts target is SimplifyObject< - Target & - DeepMergeHKT< - [Target, ...Ts], - DeepMergeFunctionsDefaultURIs, - DeepMergeBuiltInMetaData - > -> { - return void deepmergeIntoCustom({})(target, ...objects); -} - -/** - * Deeply merge two or more objects using the given options. - * - * @param options - The options on how to customize the merge function. - */ -export function deepmergeIntoCustom( - options: DeepMergeIntoOptions< - DeepMergeBuiltInMetaData, - DeepMergeBuiltInMetaData - >, -): >( - target: Target, - ...objects: Ts -) => void; - -/** - * Deeply merge two or more objects using the given options and meta data. - * - * @param options - The options on how to customize the merge function. - * @param rootMetaData - The meta data passed to the root items' being merged. - */ -export function deepmergeIntoCustom< - BaseTs = unknown, - MetaData = DeepMergeBuiltInMetaData, - MetaMetaData extends DeepMergeBuiltInMetaData = DeepMergeBuiltInMetaData, ->( - options: DeepMergeIntoOptions, - rootMetaData?: MetaData, -): >( - target: Target, - ...objects: Ts -) => void; - -export function deepmergeIntoCustom< - BaseTs, - MetaData, - MetaMetaData extends DeepMergeBuiltInMetaData, ->( - options: DeepMergeIntoOptions, - rootMetaData?: MetaData, -): >( - target: Target, - ...objects: Ts -) => void { - /** - * The type of the customized deepmerge function. - */ - type CustomizedDeepmergeInto = < - Target extends object, - Ts extends ReadonlyArray, - >( - target: Target, - ...objects: Ts - ) => void; - - const utils: DeepMergeIntoFunctionUtils = - getIntoUtils(options, customizedDeepmergeInto as CustomizedDeepmergeInto); - - /** - * The customized deepmerge function. - */ - function customizedDeepmergeInto( - target: object, - ...objects: ReadonlyArray - ) { - mergeUnknownsInto< - ReadonlyArray, - typeof utils, - MetaData, - MetaMetaData - >({ value: target }, [target, ...objects], utils, rootMetaData); - } - - return customizedDeepmergeInto as CustomizedDeepmergeInto; -} - -/** - * The the utils that are available to the merge functions. - * - * @param options - The options the user specified - */ -function getIntoUtils< - M, - MM extends DeepMergeBuiltInMetaData = DeepMergeBuiltInMetaData, ->( - options: DeepMergeIntoOptions, - customizedDeepmergeInto: DeepMergeIntoFunctionUtils["deepmergeInto"], -): DeepMergeIntoFunctionUtils { - return { - defaultMergeFunctions: defaultMergeIntoFunctions, - mergeFunctions: { - ...defaultMergeIntoFunctions, - ...Object.fromEntries( - Object.entries(options) - .filter(([key, option]) => - Object.hasOwn(defaultMergeIntoFunctions, key), - ) - .map(([key, option]) => - option === false - ? [key, defaultMergeIntoFunctions.mergeOthers] - : [key, option], - ), - ), - } as DeepMergeIntoFunctionUtils["mergeFunctions"], - metaDataUpdater: (options.metaDataUpdater ?? - defaultMetaDataUpdater) as unknown as DeepMergeIntoFunctionUtils< - M, - MM - >["metaDataUpdater"], - deepmergeInto: customizedDeepmergeInto, - filterValues: - options.filterValues === false - ? undefined - : options.filterValues ?? defaultFilterValues, - actions, - }; -} - -/** - * Merge unknown things into a target. - * - * @param m_target - The target to merge into. - * @param values - The values. - */ -export function mergeUnknownsInto< - Ts extends ReadonlyArray, - U extends DeepMergeIntoFunctionUtils, - M, - MM extends DeepMergeBuiltInMetaData = DeepMergeBuiltInMetaData, ->( - m_target: Reference, - values: Ts, - utils: U, - meta: M | undefined, - // eslint-disable-next-line ts/no-invalid-void-type -): void | symbol { - const filteredValues = utils.filterValues?.(values, meta) ?? values; - - if (filteredValues.length === 0) { - return; - } - if (filteredValues.length === 1) { - return void mergeOthersInto( - m_target, - filteredValues, - utils, - meta, - ); - } - - const type = getObjectType(m_target.value); - - if (type !== ObjectType.NOT && type !== ObjectType.OTHER) { - for (let m_index = 1; m_index < filteredValues.length; m_index++) { - if (getObjectType(filteredValues[m_index]) === type) { - continue; - } - - return void mergeOthersInto( - m_target, - filteredValues, - utils, - meta, - ); - } - } - - switch (type) { - case ObjectType.RECORD: { - return void mergeRecordsInto( - m_target as Reference>, - filteredValues as ReadonlyArray>>, - utils, - meta, - ); - } - - case ObjectType.ARRAY: { - return void mergeArraysInto( - m_target as Reference, - filteredValues as ReadonlyArray>, - utils, - meta, - ); - } - - case ObjectType.SET: { - return void mergeSetsInto( - m_target as Reference>, - filteredValues as ReadonlyArray>>, - utils, - meta, - ); - } - - case ObjectType.MAP: { - return void mergeMapsInto( - m_target as Reference>, - filteredValues as ReadonlyArray< - Readonly> - >, - utils, - meta, - ); - } - - default: { - return void mergeOthersInto( - m_target, - filteredValues, - utils, - meta, - ); - } - } -} - -/** - * Merge records into a target record. - * - * @param m_target - The target to merge into. - * @param values - The records. - */ -function mergeRecordsInto< - U extends DeepMergeIntoFunctionUtils, - M, - MM extends DeepMergeBuiltInMetaData = DeepMergeBuiltInMetaData, ->( - m_target: Reference>, - values: ReadonlyArray>>, - utils: U, - meta: M | undefined, -) { - const action = utils.mergeFunctions.mergeRecords( - m_target, - values, - utils, - meta, - ); - - if (action === actions.defaultMerge) { - utils.defaultMergeFunctions.mergeRecords< - ReadonlyArray>>, - U, - M, - MM - >(m_target, values, utils, meta); - } -} - -/** - * Merge arrays into a target array. - * - * @param m_target - The target to merge into. - * @param values - The arrays. - */ -function mergeArraysInto< - U extends DeepMergeIntoFunctionUtils, - M, - MM extends DeepMergeBuiltInMetaData = DeepMergeBuiltInMetaData, ->( - m_target: Reference, - values: ReadonlyArray>, - utils: U, - meta: M | undefined, -) { - const action = utils.mergeFunctions.mergeArrays( - m_target, - values, - utils, - meta, - ); - - if (action === actions.defaultMerge) { - utils.defaultMergeFunctions.mergeArrays(m_target, values); - } -} - -/** - * Merge sets into a target set. - * - * @param m_target - The target to merge into. - * @param values - The sets. - */ -function mergeSetsInto< - U extends DeepMergeIntoFunctionUtils, - M, - MM extends DeepMergeBuiltInMetaData = DeepMergeBuiltInMetaData, ->( - m_target: Reference>, - values: ReadonlyArray>>, - utils: U, - meta: M | undefined, -) { - const action = utils.mergeFunctions.mergeSets(m_target, values, utils, meta); - - if (action === actions.defaultMerge) { - utils.defaultMergeFunctions.mergeSets(m_target, values); - } -} - -/** - * Merge maps into a target map. - * - * @param m_target - The target to merge into. - * @param values - The maps. - */ -function mergeMapsInto< - U extends DeepMergeIntoFunctionUtils, - M, - MM extends DeepMergeBuiltInMetaData = DeepMergeBuiltInMetaData, ->( - m_target: Reference>, - values: ReadonlyArray>>, - utils: U, - meta: M | undefined, -) { - const action = utils.mergeFunctions.mergeMaps(m_target, values, utils, meta); - - if (action === actions.defaultMerge) { - utils.defaultMergeFunctions.mergeMaps(m_target, values); - } -} - -/** - * Merge other things into a target. - * - * @param m_target - The target to merge into. - * @param values - The other things. - */ -function mergeOthersInto< - U extends DeepMergeIntoFunctionUtils, - M, - MM extends DeepMergeBuiltInMetaData = DeepMergeBuiltInMetaData, ->( - m_target: Reference, - values: ReadonlyArray, - utils: U, - meta: M | undefined, -) { - const action = utils.mergeFunctions.mergeOthers( - m_target, - values, - utils, - meta, - ); - - if ( - action === actions.defaultMerge || - m_target.value === actions.defaultMerge - ) { - utils.defaultMergeFunctions.mergeOthers(m_target, values); - } -} diff --git a/dist/deno/deepmerge.ts b/dist/deno/deepmerge.ts deleted file mode 100644 index 409074ff..00000000 --- a/dist/deno/deepmerge.ts +++ /dev/null @@ -1,371 +0,0 @@ -import { actions } from "./actions.ts"; -import { - defaultFilterValues, - defaultMetaDataUpdater, -} from "./defaults/general.ts"; -import { mergeFunctions as defaultMergeFunctions } from "./defaults/vanilla.ts"; -import { - type DeepMergeBuiltInMetaData, - type DeepMergeFunctionsDefaultURIs, - type DeepMergeFunctionsURIs, - type DeepMergeHKT, - type DeepMergeOptions, - type DeepMergeUtils, - type GetDeepMergeFunctionsURIs, -} from "./types/index.ts"; -import { ObjectType, getObjectType } from "./utils.ts"; - -/** - * Deeply merge objects. - * - * @param objects - The objects to merge. - */ -export function deepmerge>>( - ...objects: readonly [...Ts] -): DeepMergeHKT { - return deepmergeCustom({})(...objects) as DeepMergeHKT< - Ts, - DeepMergeFunctionsDefaultURIs, - DeepMergeBuiltInMetaData - >; -} - -/** - * Deeply merge two or more objects using the given options. - * - * @param options - The options on how to customize the merge function. - */ -export function deepmergeCustom< - BaseTs = unknown, - PMF extends Partial = {}, ->( - options: DeepMergeOptions, -): >( - ...objects: Ts -) => DeepMergeHKT, DeepMergeBuiltInMetaData>; - -/** - * Deeply merge two or more objects using the given options and meta data. - * - * @param options - The options on how to customize the merge function. - * @param rootMetaData - The meta data passed to the root items' being merged. - */ -export function deepmergeCustom< - BaseTs = unknown, - PMF extends Partial = {}, - MetaData = DeepMergeBuiltInMetaData, - MetaMetaData extends DeepMergeBuiltInMetaData = DeepMergeBuiltInMetaData, ->( - options: DeepMergeOptions, - rootMetaData?: MetaData, -): >( - ...objects: Ts -) => DeepMergeHKT, MetaData>; - -export function deepmergeCustom< - BaseTs, - PMF extends Partial, - MetaData, - MetaMetaData extends DeepMergeBuiltInMetaData, ->( - options: DeepMergeOptions, - rootMetaData?: MetaData, -): >( - ...objects: Ts -) => DeepMergeHKT, MetaData> { - /** - * The type of the customized deepmerge function. - */ - type CustomizedDeepmerge = >( - ...objects: Ts - ) => DeepMergeHKT, MetaData>; - - const utils: DeepMergeUtils = getUtils( - options, - customizedDeepmerge as CustomizedDeepmerge, - ); - - /** - * The customized deepmerge function. - */ - function customizedDeepmerge(...objects: ReadonlyArray) { - return mergeUnknowns< - ReadonlyArray, - typeof utils, - GetDeepMergeFunctionsURIs, - MetaData, - MetaMetaData - >(objects, utils, rootMetaData); - } - - return customizedDeepmerge as CustomizedDeepmerge; -} - -/** - * The the utils that are available to the merge functions. - * - * @param options - The options the user specified - */ -function getUtils< - M, - MM extends DeepMergeBuiltInMetaData = DeepMergeBuiltInMetaData, ->( - options: DeepMergeOptions, - customizedDeepmerge: DeepMergeUtils["deepmerge"], -): DeepMergeUtils { - return { - defaultMergeFunctions, - mergeFunctions: { - ...defaultMergeFunctions, - ...Object.fromEntries( - Object.entries(options) - .filter(([key, option]) => Object.hasOwn(defaultMergeFunctions, key)) - .map(([key, option]) => - option === false - ? [key, defaultMergeFunctions.mergeOthers] - : [key, option], - ), - ), - } as DeepMergeUtils["mergeFunctions"], - metaDataUpdater: (options.metaDataUpdater ?? - defaultMetaDataUpdater) as unknown as DeepMergeUtils< - M, - MM - >["metaDataUpdater"], - deepmerge: customizedDeepmerge, - useImplicitDefaultMerging: options.enableImplicitDefaultMerging ?? false, - filterValues: - options.filterValues === false - ? undefined - : options.filterValues ?? defaultFilterValues, - actions, - }; -} - -/** - * Merge unknown things. - * - * @param values - The values. - */ -export function mergeUnknowns< - Ts extends ReadonlyArray, - U extends DeepMergeUtils, - Fs extends DeepMergeFunctionsURIs, - M, - MM extends DeepMergeBuiltInMetaData = DeepMergeBuiltInMetaData, ->(values: Ts, utils: U, meta: M | undefined): DeepMergeHKT { - const filteredValues = utils.filterValues?.(values, meta) ?? values; - - if (filteredValues.length === 0) { - return undefined as DeepMergeHKT; - } - if (filteredValues.length === 1) { - return mergeOthers(filteredValues, utils, meta) as DeepMergeHKT< - Ts, - Fs, - M - >; - } - - const type = getObjectType(filteredValues[0]); - - if (type !== ObjectType.NOT && type !== ObjectType.OTHER) { - for (let m_index = 1; m_index < filteredValues.length; m_index++) { - if (getObjectType(filteredValues[m_index]) === type) { - continue; - } - - return mergeOthers(filteredValues, utils, meta) as DeepMergeHKT< - Ts, - Fs, - M - >; - } - } - - switch (type) { - case ObjectType.RECORD: { - return mergeRecords( - filteredValues as ReadonlyArray>>, - utils, - meta, - ) as DeepMergeHKT; - } - - case ObjectType.ARRAY: { - return mergeArrays( - filteredValues as ReadonlyArray>>, - utils, - meta, - ) as DeepMergeHKT; - } - - case ObjectType.SET: { - return mergeSets( - filteredValues as ReadonlyArray>>, - utils, - meta, - ) as DeepMergeHKT; - } - - case ObjectType.MAP: { - return mergeMaps( - filteredValues as ReadonlyArray< - Readonly> - >, - utils, - meta, - ) as DeepMergeHKT; - } - - default: { - return mergeOthers(filteredValues, utils, meta) as DeepMergeHKT< - Ts, - Fs, - M - >; - } - } -} - -/** - * Merge records. - * - * @param values - The records. - */ -function mergeRecords< - U extends DeepMergeUtils, - Fs extends DeepMergeFunctionsURIs, - M, - MM extends DeepMergeBuiltInMetaData = DeepMergeBuiltInMetaData, ->( - values: ReadonlyArray>>, - 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>>, - U, - Fs, - M, - MM - >(values, utils, meta); - } - - return result; -} - -/** - * Merge arrays. - * - * @param values - The arrays. - */ -function mergeArrays< - U extends DeepMergeUtils, - M, - MM extends DeepMergeBuiltInMetaData = DeepMergeBuiltInMetaData, ->( - values: ReadonlyArray>>, - 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 DeepMergeUtils, - M, - MM extends DeepMergeBuiltInMetaData = DeepMergeBuiltInMetaData, ->( - values: ReadonlyArray>>, - 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 DeepMergeUtils, - M, - MM extends DeepMergeBuiltInMetaData = DeepMergeBuiltInMetaData, ->( - values: ReadonlyArray>>, - 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 DeepMergeUtils, - M, - MM extends DeepMergeBuiltInMetaData = DeepMergeBuiltInMetaData, ->(values: ReadonlyArray, 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; -} diff --git a/dist/deno/defaults/general.ts b/dist/deno/defaults/general.ts deleted file mode 100644 index a9f44722..00000000 --- a/dist/deno/defaults/general.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { type DeepMergeBuiltInMetaData } from "../types/index.ts"; - -/** - * The default function to update meta data. - * - * It doesn't update the meta data. - */ -export function defaultMetaDataUpdater( - previousMeta: M, - metaMeta: DeepMergeBuiltInMetaData, -): DeepMergeBuiltInMetaData { - return metaMeta; -} - -/** - * The default function to filter values. - * - * It filters out undefined values. - */ -export function defaultFilterValues, M>( - values: Ts, - meta: M | undefined, -): unknown[] { - return values.filter((value) => value !== undefined); -} diff --git a/dist/deno/defaults/into.ts b/dist/deno/defaults/into.ts deleted file mode 100644 index e8b3edd8..00000000 --- a/dist/deno/defaults/into.ts +++ /dev/null @@ -1,136 +0,0 @@ -import { mergeUnknownsInto } from "../deepmerge-into.ts"; -import { - type DeepMergeBuiltInMetaData, - type DeepMergeIntoFunctionUtils, - type Reference, -} from "../types/index.ts"; -import { getIterableOfIterables, getKeys, objectHasProperty } from "../utils.ts"; - -/** - * The default merge functions. - */ -export type MergeFunctions = { - mergeRecords: typeof mergeRecordsInto; - mergeArrays: typeof mergeArraysInto; - mergeSets: typeof mergeSetsInto; - mergeMaps: typeof mergeMapsInto; - mergeOthers: typeof mergeOthersInto; -}; - -/** - * The default strategy to merge records into a target record. - * - * @param m_target - The result will be mutated into this record - * @param values - The records (including the target's value if there is one). - */ -function mergeRecordsInto< - Ts extends ReadonlyArray>, - U extends DeepMergeIntoFunctionUtils, - M, - MM extends DeepMergeBuiltInMetaData = DeepMergeBuiltInMetaData, ->( - m_target: Reference>, - values: Ts, - utils: U, - meta: M | undefined, -): void { - for (const key of getKeys(values)) { - const propValues = []; - - for (const value of values) { - if (objectHasProperty(value, key)) { - propValues.push(value[key]); - } - } - - if (propValues.length === 0) { - continue; - } - - const updatedMeta = utils.metaDataUpdater(meta, { - key, - parents: values, - } as unknown as MM); - - const propertyTarget: Reference = { value: propValues[0] }; - mergeUnknownsInto, U, M, MM>( - propertyTarget, - propValues, - utils, - updatedMeta, - ); - - if (key === "__proto__") { - Object.defineProperty(m_target.value, key, { - value: propertyTarget.value, - configurable: true, - enumerable: true, - writable: true, - }); - } else { - m_target.value[key] = propertyTarget.value; - } - } -} - -/** - * The default strategy to merge arrays into a target array. - * - * @param m_target - The result will be mutated into this array - * @param values - The arrays (including the target's value if there is one). - */ -function mergeArraysInto>>( - m_target: Reference, - values: Ts, -): void { - m_target.value.push(...values.slice(1).flat()); -} - -/** - * The default strategy to merge sets into a target set. - * - * @param m_target - The result will be mutated into this set - * @param values - The sets (including the target's value if there is one). - */ -function mergeSetsInto< - Ts extends ReadonlyArray>>, ->(m_target: Reference>, values: Ts): void { - for (const value of getIterableOfIterables(values.slice(1))) { - m_target.value.add(value); - } -} - -/** - * The default strategy to merge maps into a target map. - * - * @param m_target - The result will be mutated into this map - * @param values - The maps (including the target's value if there is one). - */ -function mergeMapsInto< - Ts extends ReadonlyArray>>, ->(m_target: Reference>, values: Ts): void { - for (const [key, value] of getIterableOfIterables(values.slice(1))) { - m_target.value.set(key, value); - } -} - -/** - * Set the target to the last non-undefined value. - */ -function mergeOthersInto>( - m_target: Reference, - values: Ts, -) { - m_target.value = values.at(-1); -} - -/** - * The merge functions. - */ -export const mergeIntoFunctions = { - mergeRecords: mergeRecordsInto, - mergeArrays: mergeArraysInto, - mergeSets: mergeSetsInto, - mergeMaps: mergeMapsInto, - mergeOthers: mergeOthersInto, -}; diff --git a/dist/deno/defaults/vanilla.ts b/dist/deno/defaults/vanilla.ts deleted file mode 100644 index d56ea72f..00000000 --- a/dist/deno/defaults/vanilla.ts +++ /dev/null @@ -1,137 +0,0 @@ -import { actions } from "../actions.ts"; -import { mergeUnknowns } from "../deepmerge.ts"; -import { - type DeepMergeArraysDefaultHKT, - type DeepMergeBuiltInMetaData, - type DeepMergeFunctionsURIs, - type DeepMergeMapsDefaultHKT, - type DeepMergeRecordsDefaultHKT, - type DeepMergeSetsDefaultHKT, - type DeepMergeUtils, -} from "../types/index.ts"; -import { getIterableOfIterables, getKeys, objectHasProperty } from "../utils.ts"; - -/** - * The default merge functions. - */ -export type MergeFunctions = { - mergeRecords: typeof mergeRecords; - mergeArrays: typeof mergeArrays; - mergeSets: typeof mergeSets; - mergeMaps: typeof mergeMaps; - mergeOthers: typeof mergeOthers; -}; - -/** - * The default strategy to merge records. - * - * @param values - The records. - */ -function mergeRecords< - Ts extends ReadonlyArray>, - U extends DeepMergeUtils, - Fs extends DeepMergeFunctionsURIs, - M, - MM extends DeepMergeBuiltInMetaData = DeepMergeBuiltInMetaData, ->( - values: Ts, - utils: U, - meta: M | undefined, -): DeepMergeRecordsDefaultHKT { - const result: Record = {}; - - for (const key of getKeys(values)) { - const propValues = []; - - for (const value of values) { - if (objectHasProperty(value, key)) { - propValues.push(value[key]); - } - } - - if (propValues.length === 0) { - continue; - } - - const updatedMeta = utils.metaDataUpdater(meta, { - key, - parents: values, - } as unknown as MM); - - const propertyResult = mergeUnknowns, U, Fs, M, MM>( - propValues, - utils, - updatedMeta, - ); - - if (propertyResult === actions.skip) { - continue; - } - - if (key === "__proto__") { - Object.defineProperty(result, key, { - value: propertyResult, - configurable: true, - enumerable: true, - writable: true, - }); - } else { - result[key] = propertyResult; - } - } - - return result as DeepMergeRecordsDefaultHKT; -} - -/** - * The default strategy to merge arrays. - * - * @param values - The arrays. - */ -function mergeArrays< - Ts extends ReadonlyArray>, - Fs extends DeepMergeFunctionsURIs, - M, ->(values: Ts): DeepMergeArraysDefaultHKT { - return values.flat() as DeepMergeArraysDefaultHKT; -} - -/** - * The default strategy to merge sets. - * - * @param values - The sets. - */ -function mergeSets>>>( - values: Ts, -): DeepMergeSetsDefaultHKT { - return new Set(getIterableOfIterables(values)) as DeepMergeSetsDefaultHKT; -} - -/** - * The default strategy to merge maps. - * - * @param values - The maps. - */ -function mergeMaps< - Ts extends ReadonlyArray>>, ->(values: Ts): DeepMergeMapsDefaultHKT { - return new Map(getIterableOfIterables(values)) as DeepMergeMapsDefaultHKT; -} - -/** - * Get the last non-undefined value in the given array. - */ -function mergeOthers>(values: Ts) { - return values.at(-1); -} - -/** - * The merge functions. - */ -export const mergeFunctions = { - mergeRecords, - mergeArrays, - mergeSets, - mergeMaps, - mergeOthers, -}; diff --git a/dist/deno/index.ts b/dist/deno/index.ts deleted file mode 100644 index 60bf4c05..00000000 --- a/dist/deno/index.ts +++ /dev/null @@ -1,32 +0,0 @@ -export { deepmerge, deepmergeCustom } from "./deepmerge.ts"; -export { deepmergeInto, deepmergeIntoCustom } from "./deepmerge-into.ts"; -export { - type ObjectType, - getKeys, - getObjectType, - objectHasProperty, -} from "./utils.ts"; - -export type { MergeFunctions as DeepMergeIntoFunctionsDefaults } from "./defaults/into.ts"; -export type { MergeFunctions as DeepMergeFunctionsDefaults } from "./defaults/vanilla.ts"; -export type { - DeepMergeArraysDefaultHKT, - DeepMergeBuiltInMetaData, - DeepMergeHKT, - DeepMergeLeaf, - DeepMergeLeafURI, - DeepMergeNoFilteringURI, - DeepMergeMapsDefaultHKT, - DeepMergeFunctionsDefaultURIs, - DeepMergeFunctionsURIs, - DeepMergeFunctionURItoKind, - DeepMergeUtils, - DeepMergeIntoFunctionUtils, - DeepMergeOptions, - DeepMergeIntoOptions, - DeepMergeRecordsDefaultHKT, - DeepMergeSetsDefaultHKT, - Reference as DeepMergeValueReference, - GetDeepMergeFunctionsURIs, -} from "./types/index.ts"; -export type { FilterOut } from "./types/utils.ts"; diff --git a/dist/deno/mod.ts b/dist/deno/mod.ts deleted file mode 100644 index da5ee324..00000000 --- a/dist/deno/mod.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./index.ts"; \ No newline at end of file diff --git a/dist/deno/types/defaults.ts b/dist/deno/types/defaults.ts deleted file mode 100644 index fad23b48..00000000 --- a/dist/deno/types/defaults.ts +++ /dev/null @@ -1,363 +0,0 @@ -import { - type DeepMergeFunctionURItoKind, - type DeepMergeFunctionsURIs, - type DeepMergeHKT, - type DeepMergeLeafURI, -} from "./merging.ts"; -import { - type FilterOut, - type FilterOutNever, - type FlattenTuples, - type KeyIsOptional, - type SimplifyObject, - type TransposeTuple, - type TupleToIntersection, - type TuplifyUnion, - type UnionMapKeys, - type UnionMapValues, - type UnionSetValues, -} from "./utils.ts"; - -/** - * The default merge function to merge records with. - */ -type DeepMergeRecordsDefaultURI = "DeepMergeRecordsDefaultURI"; - -/** - * The default merge function to merge arrays with. - */ -type DeepMergeArraysDefaultURI = "DeepMergeArraysDefaultURI"; - -/** - * The default merge function to merge sets with. - */ -type DeepMergeSetsDefaultURI = "DeepMergeSetsDefaultURI"; - -/** - * The default merge function to merge maps with. - */ -type DeepMergeMapsDefaultURI = "DeepMergeMapsDefaultURI"; - -/** - * The default filter values function. - */ -type DeepMergeFilterValuesDefaultURI = "DeepMergeFilterValuesDefaultURI"; - -/** - * The default merge functions to use when deep merging. - */ -export type DeepMergeFunctionsDefaultURIs = Readonly<{ - DeepMergeRecordsURI: DeepMergeRecordsDefaultURI; - DeepMergeArraysURI: DeepMergeArraysDefaultURI; - DeepMergeSetsURI: DeepMergeSetsDefaultURI; - DeepMergeMapsURI: DeepMergeMapsDefaultURI; - DeepMergeOthersURI: DeepMergeLeafURI; - DeepMergeFilterValuesURI: DeepMergeFilterValuesDefaultURI; -}>; - -type RecordEntries> = FilterOut< - TuplifyUnion< - { - [K in keyof T]: [K, T[K]]; - }[keyof T] - >, - undefined ->; - -type RecordMeta = Record; - -type RecordPropertyMeta< - Key extends PropertyKey = PropertyKey, - Value = unknown, - Optional extends boolean = boolean, -> = { - key: Key; - value: Value; - optional: Optional; -}; - -type RecordsToRecordMeta< - Ts extends ReadonlyArray>, -> = FilterOutNever<{ - [I in keyof Ts]: RecordToRecordMeta; -}>; - -type RecordToRecordMeta> = { - [K in keyof T]-?: { - key: K; - value: Required[K]; - optional: KeyIsOptional; - }; -}; - -/** - * Deep merge records. - */ -export type DeepMergeRecordsDefaultHKT< - Ts extends ReadonlyArray, - Fs extends DeepMergeFunctionsURIs, - M, -> = - Ts extends ReadonlyArray> - ? SimplifyObject< - DeepMergeRecordMetaDefaultHKTProps, Fs, M> - > - : never; - -/** - * Deep merge record props. - */ -type DeepMergeRecordMetaDefaultHKTProps< - RecordMetas, - Fs extends DeepMergeFunctionsURIs, - M, -> = - RecordMetas extends ReadonlyArray - ? CreateRecordFromMeta, Fs, M> - : never; - -type MergeRecordMeta> = - GroupValuesByKey< - FlattenTuples< - TransposeTuple< - FilterOut< - { - [I in keyof RecordMetas]: TransposeTuple< - RecordEntries - >; - }, - readonly [] - > - > - > - >; - -type GroupValuesByKey = Ts extends readonly [ - infer Keys extends ReadonlyArray, - infer Values, -] - ? { - [I in keyof Keys]: DeepMergeRecordPropertyMetaDefaultHKTGetPossible< - Keys[I], - FilterOutNever<{ - [J in keyof Values]: Values[J] extends { - key: Keys[I]; - } - ? Values[J] - : never; - }> - >; - } - : never; - -type CreateRecordFromMeta = - Ts extends ReadonlyArray - ? TupleToIntersection<{ - [I in keyof Ts]: Ts[I] extends { - key: infer Key extends PropertyKey; - values: infer Values extends ReadonlyArray; - optional: infer O extends boolean; - } - ? CreateRecordForKeyFromMeta - : never; - }> - : never; - -type CreateRecordForKeyFromMeta< - Key extends PropertyKey, - Values extends ReadonlyArray, - Optional extends boolean, - Fs extends DeepMergeFunctionsURIs, - M, -> = Optional extends true - ? { - [k in Key]+?: DeepMergeHKT; - } - : { - [k in Key]-?: DeepMergeHKT; - }; - -/** - * Get the possible types of a property. - */ -type DeepMergeRecordPropertyMetaDefaultHKTGetPossible< - Key extends PropertyKey, - Ts, -> = Ts extends readonly [ - RecordPropertyMeta, - ...ReadonlyArray, -] - ? DeepMergeRecordPropertyMetaDefaultHKTGetPossibleHelper< - Ts, - { key: Key; values: []; optional: never } - > - : never; - -/** - * Tail-recursive helper type for DeepMergeRecordPropertyMetaDefaultHKTGetPossible. - */ -type DeepMergeRecordPropertyMetaDefaultHKTGetPossibleHelper< - Ts extends readonly [ - RecordPropertyMeta, - ...ReadonlyArray, - ], - Acc extends { - key: PropertyKey; - values: ReadonlyArray; - optional: boolean; - }, -> = Ts extends [ - ...infer Rest, - { - key: infer K extends PropertyKey; - value: infer V; - optional: infer O extends boolean; - }, -] - ? Acc["optional"] extends true - ? Acc extends { values: [infer Head, ...infer AccRest] } - ? Rest extends readonly [ - RecordPropertyMeta, - ...ReadonlyArray, - ] - ? DeepMergeRecordPropertyMetaDefaultHKTGetPossibleHelper< - Rest, - { - key: K; - values: [V | Head, ...AccRest]; - optional: O; - } - > - : { - key: K; - values: [V | Head, ...AccRest]; - optional: O; - } - : Rest extends readonly [ - RecordPropertyMeta, - ...ReadonlyArray, - ] - ? DeepMergeRecordPropertyMetaDefaultHKTGetPossibleHelper< - Rest, - { - key: K; - values: [V, ...Acc["values"]]; - optional: O; - } - > - : { - key: K; - values: [V, ...Acc["values"]]; - optional: O; - } - : Rest extends readonly [ - RecordPropertyMeta, - ...ReadonlyArray, - ] - ? DeepMergeRecordPropertyMetaDefaultHKTGetPossibleHelper< - Rest, - { - key: K; - values: [V, ...Acc["values"]]; - optional: O; - } - > - : { - key: K; - values: [V, ...Acc["values"]]; - optional: O; - } - : never; - -/** - * Deep merge arrays. - */ -export type DeepMergeArraysDefaultHKT< - Ts extends ReadonlyArray, - Fs extends DeepMergeFunctionsURIs, - M, -> = DeepMergeArraysDefaultHKTHelper; - -/** - * Tail-recursive helper type for DeepMergeArraysDefaultHKT. - */ -type DeepMergeArraysDefaultHKTHelper< - Ts extends ReadonlyArray, - Fs extends DeepMergeFunctionsURIs, - M, - Acc extends ReadonlyArray, -> = Ts extends readonly [ - infer Head extends ReadonlyArray, - ...infer Rest, -] - ? Rest extends readonly [ - ReadonlyArray, - ...ReadonlyArray>, - ] - ? DeepMergeArraysDefaultHKTHelper - : [...Acc, ...Head] - : never; - -/** - * Deep merge sets. - */ -export type DeepMergeSetsDefaultHKT> = Set< - UnionSetValues ->; - -/** - * Deep merge maps. - */ -export type DeepMergeMapsDefaultHKT> = Map< - UnionMapKeys, - UnionMapValues ->; - -/** - * Filter out undefined values. - */ -export type DeepMergeFilterValuesDefaultHKT> = - FilterOut; - -/** - * Get the merge functions with defaults apply from the given subset. - */ -export type GetDeepMergeFunctionsURIs< - PMF extends Partial, -> = Readonly<{ - // prettier-ignore - DeepMergeRecordsURI: - PMF["DeepMergeRecordsURI"] extends keyof DeepMergeFunctionURItoKind - ? PMF["DeepMergeRecordsURI"] - : DeepMergeRecordsDefaultURI; - - // prettier-ignore - DeepMergeArraysURI: - PMF["DeepMergeArraysURI"] extends keyof DeepMergeFunctionURItoKind - ? PMF["DeepMergeArraysURI"] - : DeepMergeArraysDefaultURI; - - // prettier-ignore - DeepMergeSetsURI: - PMF["DeepMergeSetsURI"] extends keyof DeepMergeFunctionURItoKind - ? PMF["DeepMergeSetsURI"] - : DeepMergeSetsDefaultURI; - - // prettier-ignore - DeepMergeMapsURI: - PMF["DeepMergeMapsURI"] extends keyof DeepMergeFunctionURItoKind - ? PMF["DeepMergeMapsURI"] - : DeepMergeMapsDefaultURI; - - // prettier-ignore - DeepMergeOthersURI: - PMF["DeepMergeOthersURI"] extends keyof DeepMergeFunctionURItoKind - ? PMF["DeepMergeOthersURI"] - : DeepMergeLeafURI; - - // prettier-ignore - DeepMergeFilterValuesURI: - PMF["DeepMergeFilterValuesURI"] extends keyof DeepMergeFunctionURItoKind - ? PMF["DeepMergeFilterValuesURI"] - : DeepMergeFilterValuesDefaultURI; -}>; diff --git a/dist/deno/types/index.ts b/dist/deno/types/index.ts deleted file mode 100644 index f6ebaff2..00000000 --- a/dist/deno/types/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from "./defaults.ts"; -export * from "./merging.ts"; -export * from "./options.ts"; diff --git a/dist/deno/types/merging.ts b/dist/deno/types/merging.ts deleted file mode 100644 index a47a574a..00000000 --- a/dist/deno/types/merging.ts +++ /dev/null @@ -1,208 +0,0 @@ -import { - type DeepMergeArraysDefaultHKT, - type DeepMergeFilterValuesDefaultHKT, - type DeepMergeMapsDefaultHKT, - type DeepMergeRecordsDefaultHKT, - type DeepMergeSetsDefaultHKT, -} from "./defaults.ts"; -import { - type EveryIsArray, - type EveryIsMap, - type EveryIsRecord, - type EveryIsSet, - type IsNever, - type IsTuple, -} from "./utils.ts"; - -/** - * Mapping of merge function URIs to the merge function type. - */ -// eslint-disable-next-line ts/consistent-type-definitions -export interface DeepMergeFunctionURItoKind< - Ts extends ReadonlyArray, - Fs extends DeepMergeFunctionsURIs, - in out M, -> { - readonly DeepMergeLeafURI: DeepMergeLeaf; - readonly DeepMergeRecordsDefaultURI: DeepMergeRecordsDefaultHKT; - readonly DeepMergeArraysDefaultURI: DeepMergeArraysDefaultHKT; - readonly DeepMergeSetsDefaultURI: DeepMergeSetsDefaultHKT; - readonly DeepMergeMapsDefaultURI: DeepMergeMapsDefaultHKT; - readonly DeepMergeFilterValuesDefaultURI: DeepMergeFilterValuesDefaultHKT; - readonly DeepMergeNoFilteringURI: Ts; -} - -/** - * Get the type of the given merge function via its URI. - */ -type DeepMergeFunctionKind< - URI extends DeepMergeFunctionURIs, - Ts extends ReadonlyArray, - Fs extends DeepMergeFunctionsURIs, - M, -> = DeepMergeFunctionURItoKind[URI]; - -/** - * A union of all valid merge function URIs. - */ -type DeepMergeFunctionURIs = keyof DeepMergeFunctionURItoKind< - ReadonlyArray, - DeepMergeFunctionsURIs, - unknown ->; - -/** - * The merge functions to use when deep merging. - */ -export type DeepMergeFunctionsURIs = Readonly<{ - /** - * The merge function to merge records with. - */ - DeepMergeRecordsURI: DeepMergeFunctionURIs; - - /** - * The merge function to merge arrays with. - */ - DeepMergeArraysURI: DeepMergeFunctionURIs; - - /** - * The merge function to merge sets with. - */ - DeepMergeSetsURI: DeepMergeFunctionURIs; - - /** - * The merge function to merge maps with. - */ - DeepMergeMapsURI: DeepMergeFunctionURIs; - - /** - * The merge function to merge other things with. - */ - DeepMergeOthersURI: DeepMergeFunctionURIs; - - /** - * The function to filter values. - */ - DeepMergeFilterValuesURI: DeepMergeFunctionURIs; -}>; - -/** - * Deep merge types. - */ -export type DeepMergeHKT< - Ts extends ReadonlyArray, - Fs extends DeepMergeFunctionsURIs, - M, -> = - IsTuple extends true - ? Ts extends readonly [] - ? undefined - : DeepMergeHKTHelper, Fs, M> - : unknown; - -type DeepMergeHKTHelper = - Ts extends ReadonlyArray - ? IsTuple extends true - ? Ts extends readonly [] - ? unknown - : Ts extends readonly [infer T1] - ? T1 - : EveryIsArray extends true - ? DeepMergeArraysHKT - : EveryIsMap extends true - ? DeepMergeMapsHKT - : EveryIsSet extends true - ? DeepMergeSetsHKT - : EveryIsRecord extends true - ? DeepMergeRecordsHKT - : DeepMergeOthersHKT - : unknown - : never; - -/** - * Deep merge records. - */ -type DeepMergeRecordsHKT< - Ts extends ReadonlyArray, - Fs extends DeepMergeFunctionsURIs, - M, -> = DeepMergeFunctionKind; - -/** - * Deep merge arrays. - */ -type DeepMergeArraysHKT< - Ts extends ReadonlyArray, - Fs extends DeepMergeFunctionsURIs, - M, -> = DeepMergeFunctionKind; - -/** - * Deep merge sets. - */ -type DeepMergeSetsHKT< - Ts extends ReadonlyArray, - Fs extends DeepMergeFunctionsURIs, - M, -> = DeepMergeFunctionKind; - -/** - * Deep merge maps. - */ -type DeepMergeMapsHKT< - Ts extends ReadonlyArray, - Fs extends DeepMergeFunctionsURIs, - M, -> = DeepMergeFunctionKind; - -/** - * Deep merge other things. - */ -type DeepMergeOthersHKT< - Ts extends ReadonlyArray, - Fs extends DeepMergeFunctionsURIs, - M, -> = DeepMergeFunctionKind; - -/** - * Filter values. - */ -type FilterValuesHKT< - Ts extends ReadonlyArray, - Fs extends DeepMergeFunctionsURIs, - M, -> = DeepMergeFunctionKind; - -/** - * The merge function that returns a leaf. - */ -export type DeepMergeLeafURI = "DeepMergeLeafURI"; - -/** - * Don't filter values. - */ -export type DeepMergeNoFilteringURI = "DeepMergeNoFilteringURI"; - -/** - * Get the leaf type from many types that can't be merged. - */ -export type DeepMergeLeaf> = - Ts extends readonly [] - ? never - : Ts extends readonly [infer T] - ? T - : Ts extends readonly [...infer Rest, infer Tail] - ? IsNever extends true - ? Rest extends ReadonlyArray - ? DeepMergeLeaf - : never - : Tail - : never; - -/** - * The meta data deepmerge is able to provide. - */ -export type DeepMergeBuiltInMetaData = Readonly<{ - key: PropertyKey; - parents: ReadonlyArray>>; -}>; diff --git a/dist/deno/types/options.ts b/dist/deno/types/options.ts deleted file mode 100644 index c8b1b0c2..00000000 --- a/dist/deno/types/options.ts +++ /dev/null @@ -1,228 +0,0 @@ -import { type MergeFunctions as MergeIntoFunctions } from "../defaults/into.ts"; -import { type MergeFunctions } from "../defaults/vanilla.ts"; - -import { type DeepMergeBuiltInMetaData } from "./merging.ts"; - -/** - * The options the user can pass to customize deepmerge. - */ -export type DeepMergeOptions< - in out M, - MM extends Readonly> = {}, -> = Partial>; - -/** - * The options the user can pass to customize deepmergeInto. - */ -export type DeepMergeIntoOptions< - in out M, - MM extends Readonly> = {}, -> = Partial>; - -type MetaDataUpdater< - in out M, - MM extends DeepMergeBuiltInMetaData = DeepMergeBuiltInMetaData, -> = (previousMeta: M | undefined, metaMeta: Readonly>) => M; - -/** - * All the options the user can pass to customize deepmerge. - */ -type DeepMergeOptionsFull< - in out M, - MM extends DeepMergeBuiltInMetaData = DeepMergeBuiltInMetaData, -> = Readonly<{ - mergeRecords: DeepMergeFunctions["mergeRecords"] | false; - mergeArrays: DeepMergeFunctions["mergeArrays"] | false; - mergeMaps: DeepMergeFunctions["mergeMaps"] | false; - mergeSets: DeepMergeFunctions["mergeSets"] | false; - mergeOthers: DeepMergeFunctions["mergeOthers"]; - metaDataUpdater: MetaDataUpdater; - enableImplicitDefaultMerging: boolean; - filterValues: DeepMergeUtilityFunctions["filterValues"] | false; -}>; - -/** - * All the options the user can pass to customize deepmergeInto. - */ -type DeepMergeIntoOptionsFull< - in out M, - MM extends DeepMergeBuiltInMetaData = DeepMergeBuiltInMetaData, -> = Readonly<{ - mergeRecords: DeepMergeIntoFunctions["mergeRecords"] | false; - mergeArrays: DeepMergeIntoFunctions["mergeArrays"] | false; - mergeMaps: DeepMergeIntoFunctions["mergeMaps"] | false; - mergeSets: DeepMergeIntoFunctions["mergeSets"] | false; - mergeOthers: DeepMergeIntoFunctions["mergeOthers"]; - metaDataUpdater: MetaDataUpdater; - filterValues: DeepMergeUtilityFunctions["filterValues"] | false; -}>; - -/** - * An object that has a reference to a value. - */ -export type Reference = { - value: T; -}; - -/** - * All the utility functions that can be overridden. - */ -type DeepMergeUtilityFunctions = Readonly<{ - filterValues: >( - values: Ts, - meta: M | undefined, - ) => unknown[]; -}>; - -/** - * All the merge functions that deepmerge uses. - */ -type DeepMergeFunctions< - in M, - MM extends DeepMergeBuiltInMetaData = DeepMergeBuiltInMetaData, -> = Readonly<{ - mergeRecords: < - Ts extends ReadonlyArray>>, - U extends DeepMergeUtils, - >( - values: Ts, - utils: U, - meta: M | undefined, - ) => unknown; - - mergeArrays: < - Ts extends ReadonlyArray>, - U extends DeepMergeUtils, - >( - values: Ts, - utils: U, - meta: M | undefined, - ) => unknown; - - mergeMaps: < - Ts extends ReadonlyArray>>, - U extends DeepMergeUtils, - >( - values: Ts, - utils: U, - meta: M | undefined, - ) => unknown; - - mergeSets: < - Ts extends ReadonlyArray>>, - U extends DeepMergeUtils, - >( - values: Ts, - utils: U, - meta: M | undefined, - ) => unknown; - - mergeOthers: < - Ts extends ReadonlyArray, - U extends DeepMergeUtils, - >( - values: Ts, - utils: U, - meta: M | undefined, - ) => unknown; -}>; - -// eslint-disable-next-line ts/no-invalid-void-type -type DeepMergeIntoFunctionsReturnType = void | symbol; - -/** - * All the merge functions that deepmerge uses. - */ -type DeepMergeIntoFunctions< - in M, - MM extends DeepMergeBuiltInMetaData = DeepMergeBuiltInMetaData, -> = Readonly<{ - mergeRecords: < - Ts extends ReadonlyArray>>, - U extends DeepMergeIntoFunctionUtils, - >( - m_target: Reference>, - values: Ts, - utils: U, - meta: M | undefined, - ) => DeepMergeIntoFunctionsReturnType; - - mergeArrays: < - Ts extends ReadonlyArray>, - U extends DeepMergeIntoFunctionUtils, - >( - m_target: Reference, - values: Ts, - utils: U, - meta: M | undefined, - ) => DeepMergeIntoFunctionsReturnType; - - mergeMaps: < - Ts extends ReadonlyArray>>, - U extends DeepMergeIntoFunctionUtils, - >( - m_target: Reference>, - values: Ts, - utils: U, - meta: M | undefined, - ) => DeepMergeIntoFunctionsReturnType; - - mergeSets: < - Ts extends ReadonlyArray>>, - U extends DeepMergeIntoFunctionUtils, - >( - m_target: Reference>, - values: Ts, - utils: U, - meta: M | undefined, - ) => DeepMergeIntoFunctionsReturnType; - - mergeOthers: < - Ts extends ReadonlyArray, - U extends DeepMergeIntoFunctionUtils, - >( - m_target: Reference, - values: Ts, - utils: U, - meta: M | undefined, - ) => DeepMergeIntoFunctionsReturnType; -}>; - -/** - * The utils provided to the merge functions. - */ -export type DeepMergeUtils< - in out M, - MM extends DeepMergeBuiltInMetaData = DeepMergeBuiltInMetaData, -> = Readonly<{ - mergeFunctions: DeepMergeFunctions; - defaultMergeFunctions: MergeFunctions; - metaDataUpdater: MetaDataUpdater; - deepmerge: >(...values: Ts) => unknown; - useImplicitDefaultMerging: boolean; - filterValues: DeepMergeUtilityFunctions["filterValues"] | undefined; - actions: Readonly<{ - defaultMerge: symbol; - skip: symbol; - }>; -}>; - -/** - * The utils provided to the merge functions. - */ -export type DeepMergeIntoFunctionUtils< - in out M, - MM extends DeepMergeBuiltInMetaData = DeepMergeBuiltInMetaData, -> = Readonly<{ - mergeFunctions: DeepMergeIntoFunctions; - defaultMergeFunctions: MergeIntoFunctions; - metaDataUpdater: MetaDataUpdater; - deepmergeInto: >( - target: Target, - ...values: Ts - ) => void; - filterValues: DeepMergeUtilityFunctions["filterValues"] | undefined; - actions: Readonly<{ - defaultMerge: symbol; - }>; -}>; diff --git a/dist/deno/types/utils.ts b/dist/deno/types/utils.ts deleted file mode 100644 index 8ec7a1d0..00000000 --- a/dist/deno/types/utils.ts +++ /dev/null @@ -1,337 +0,0 @@ -/** - * Simplify a complex type such as a union or intersection of objects into a - * single object. - */ -export type SimplifyObject = { - [K in keyof T]: T[K]; -} & {}; - -/** - * Flatten a collection of tuples of tuples into a collection of tuples. - */ -export type FlattenTuples = { - [I in keyof T]: FlattenTuple; -}; - -/** - * Flatten a tuple of tuples into a single tuple. - */ -export type FlattenTuple = T extends readonly [] - ? [] - : T extends readonly [infer T0] - ? [...FlattenTuple] - : T extends readonly [infer T0, ...infer Ts] - ? [...FlattenTuple, ...FlattenTuple] - : [T]; - -/** - * Safely test whether or not the first given types extends the second. - * - * Needed in particular for testing if a type is "never". - */ -export type Is = [T1] extends [T2] ? true : false; - -/** - * Safely test whether or not the given type is "never". - */ -export type IsNever = Is; - -/** - * And operator for types. - */ -export type And = T1 extends false - ? false - : T2; - -/** - * Or operator for types. - */ -export type Or = T1 extends true - ? true - : T2; - -/** - * Not operator for types. - */ -export type Not = T extends true ? false : true; - -/** - * Check if a key is optional in the given object. - */ -export type KeyIsOptional< - K extends PropertyKey, - O extends { [Key in K]?: unknown }, -> = O extends { [Key in K]: unknown } ? false : true; - -/** - * Returns whether or not all the given types are never. - */ -export type EveryIsNever> = - Ts extends readonly [infer Head, ...infer Rest] - ? IsNever extends true - ? Rest extends ReadonlyArray - ? EveryIsNever - : true - : false - : true; - -/** - * Returns whether or not the given type a record. - */ -export type IsRecord = And< - Not>, - T extends Readonly> ? true : false ->; - -/** - * Returns whether or not all the given types are records. - */ -export type EveryIsRecord> = - Ts extends readonly [infer Head, ...infer Rest] - ? IsRecord extends true - ? Rest extends ReadonlyArray - ? EveryIsRecord - : true - : false - : true; - -/** - * Returns whether or not the given type is an array. - */ -export type IsArray = And< - Not>, - T extends ReadonlyArray ? true : false ->; - -/** - * Returns whether or not all the given types are arrays. - */ -export type EveryIsArray> = - Ts extends readonly [infer T1] - ? IsArray - : Ts extends readonly [infer Head, ...infer Rest] - ? IsArray extends true - ? Rest extends readonly [unknown, ...ReadonlyArray] - ? EveryIsArray - : false - : false - : false; - -/** - * Returns whether or not the given type is an set. - * - * Note: This may also return true for Maps. - */ -export type IsSet = And< - Not>, - T extends Readonly> ? true : false ->; - -/** - * Returns whether or not all the given types are sets. - * - * Note: This may also return true if all are maps. - */ -export type EveryIsSet> = - Ts extends Readonly - ? IsSet - : Ts extends readonly [infer Head, ...infer Rest] - ? IsSet extends true - ? Rest extends readonly [unknown, ...ReadonlyArray] - ? EveryIsSet - : false - : false - : false; - -/** - * Returns whether or not the given type is an map. - */ -export type IsMap = And< - Not>, - T extends Readonly> ? true : false ->; - -/** - * Returns whether or not all the given types are maps. - */ -export type EveryIsMap> = - Ts extends Readonly - ? IsMap - : Ts extends readonly [infer Head, ...infer Rest] - ? IsMap extends true - ? Rest extends readonly [unknown, ...ReadonlyArray] - ? EveryIsMap - : false - : false - : false; - -/** - * Union of the sets' values' types - */ -export type UnionSetValues> = - UnionSetValuesHelper; - -/** - * Tail-recursive helper type for UnionSetValues. - */ -type UnionSetValuesHelper< - Ts extends ReadonlyArray, - Acc, -> = Ts extends readonly [infer Head, ...infer Rest] - ? Head extends Readonly> - ? Rest extends ReadonlyArray - ? UnionSetValuesHelper - : Acc | V1 - : never - : Acc; - -/** - * Union of the maps' values' types - */ -export type UnionMapKeys> = - UnionMapKeysHelper; - -/** - * Tail-recursive helper type for UnionMapKeys. - */ -type UnionMapKeysHelper< - Ts extends ReadonlyArray, - Acc, -> = Ts extends readonly [infer Head, ...infer Rest] - ? Head extends Readonly> - ? Rest extends readonly [] - ? Acc | K1 - : UnionMapKeysHelper - : never - : Acc; - -/** - * Union of the maps' keys' types - */ -export type UnionMapValues> = - UnionMapValuesHelper; - -/** - * Tail-recursive helper type for UnionMapValues. - */ -type UnionMapValuesHelper< - Ts extends ReadonlyArray, - Acc, -> = Ts extends readonly [infer Head, ...infer Rest] - ? Head extends Readonly> - ? Rest extends readonly [] - ? Acc | V1 - : UnionMapValuesHelper - : never - : Acc; - -/** - * Filter out U from a tuple. - */ -export type FilterOut, U> = FilterOutHelper< - T, - U, - [] ->; - -/** - * Tail-recursive helper type for FilterOut. - */ -type FilterOutHelper< - T extends ReadonlyArray, - U, - Acc extends ReadonlyArray, -> = T extends readonly [] - ? Acc - : T extends readonly [infer Head, ...infer Rest] - ? Is extends true - ? FilterOutHelper - : FilterOutHelper - : T; - -/** - * Filter out nevers from a tuple. - */ -export type FilterOutNever = - T extends ReadonlyArray ? FilterOut : never; - -/** - * Is the type a tuple? - */ -export type IsTuple> = T extends readonly [] - ? true - : T extends readonly [unknown, ...ReadonlyArray] - ? true - : false; - -/** - * Perfrom a transpose operation on a 2D tuple. - */ -export type TransposeTuple = T extends readonly [ - ...(readonly [...unknown[]]), -] - ? T extends readonly [] - ? [] - : T extends readonly [infer X extends ReadonlyArray] - ? TransposeTupleSimpleCase - : T extends readonly [ - infer X extends ReadonlyArray, - ...infer XS extends ReadonlyArray>, - ] - ? PrependCol> - : T - : never; - -type PrependCol< - T extends ReadonlyArray, - S extends ReadonlyArray>, -> = T extends readonly [] - ? S extends readonly [] - ? [] - : never - : T extends readonly [infer X, ...infer XS] - ? S extends readonly [ - readonly [...infer Y], - ...infer YS extends ReadonlyArray>, - ] - ? [[X, ...Y], ...PrependCol] - : never - : never; - -type TransposeTupleSimpleCase = - T extends readonly [] - ? [] - : T extends readonly [infer X, ...infer XS] - ? [[X], ...TransposeTupleSimpleCase] - : never; - -/** - * Convert a tuple to an intersection of each of its types. - */ -export type TupleToIntersection> = - { - [K in keyof T]: (x: T[K]) => void; - } extends Record void> - ? I - : never; - -/** - * Convert a union to a tuple. - * - * Warning: The order of the elements is non-deterministic. - * Warning 2: The union maybe me modified by the TypeScript engine before convertion. - * Warning 3: This implementation relies on a hack/limitation in TypeScript. - */ -export type TuplifyUnion> = - IsNever extends true ? [] : [...TuplifyUnion>, L]; - -type UnionToIntersection = (U extends any ? (k: U) => void : never) extends ( - k: infer I, -) => void - ? I - : never; - -type LastOf = - UnionToIntersection T : never> extends () => infer R - ? R - : never; diff --git a/dist/deno/utils.ts b/dist/deno/utils.ts deleted file mode 100644 index a8fc2756..00000000 --- a/dist/deno/utils.ts +++ /dev/null @@ -1,141 +0,0 @@ -/** - * The different types of objects deepmerge-ts support. - */ -export const enum ObjectType { - NOT, - RECORD, - ARRAY, - SET, - MAP, - OTHER, -} - -/** - * Get the type of the given object. - * - * @param object - The object to get the type of. - * @returns The type of the given object. - */ -export function getObjectType(object: unknown): ObjectType { - if (typeof object !== "object" || object === null) { - return ObjectType.NOT; - } - - if (Array.isArray(object)) { - return ObjectType.ARRAY; - } - - if (isRecord(object)) { - return ObjectType.RECORD; - } - - if (object instanceof Set) { - return ObjectType.SET; - } - - if (object instanceof Map) { - return ObjectType.MAP; - } - - return ObjectType.OTHER; -} - -/** - * Get the keys of the given objects including symbol keys. - * - * Note: Only keys to enumerable properties are returned. - * - * @param objects - An array of objects to get the keys of. - * @returns A set containing all the keys of all the given objects. - */ -export function getKeys(objects: ReadonlyArray): Set { - const keys = new Set(); - - for (const object of objects) { - for (const key of [ - ...Object.keys(object), - ...Object.getOwnPropertySymbols(object), - ]) { - keys.add(key); - } - } - - return keys; -} - -/** - * Does the given object have the given property. - * - * @param object - The object to test. - * @param property - The property to test. - * @returns Whether the object has the property. - */ -export function objectHasProperty( - object: object, - property: PropertyKey, -): boolean { - return ( - typeof object === "object" && - Object.prototype.propertyIsEnumerable.call(object, property) - ); -} - -/** - * Get an iterable object that iterates over the given iterables. - */ -export function getIterableOfIterables( - iterables: ReadonlyArray>>, -): Iterable { - return { - *[Symbol.iterator]() { - for (const iterable of iterables) { - for (const value of iterable) { - yield value; - } - } - }, - }; -} - -const validRecordToStringValues = new Set([ - "[object Object]", - "[object Module]", -]); - -/** - * Does the given object appear to be a record. - */ -function isRecord(value: object): value is Record { - // All records are objects. - if (!validRecordToStringValues.has(Object.prototype.toString.call(value))) { - return false; - } - - const { constructor } = value; - - // If has modified constructor. - // eslint-disable-next-line ts/no-unnecessary-condition - if (constructor === undefined) { - return true; - } - - const prototype: unknown = constructor.prototype; - - // If has modified prototype. - if ( - prototype === null || - typeof prototype !== "object" || - !validRecordToStringValues.has(Object.prototype.toString.call(prototype)) - ) { - return false; - } - - // If constructor does not have an Object-specific method. - // eslint-disable-next-line sonar/prefer-single-boolean-return, no-prototype-builtins - if (!prototype.hasOwnProperty("isPrototypeOf")) { - return false; - } - - // Most likely a record. - return true; -} diff --git a/dist/node/index.cjs b/dist/node/index.cjs deleted file mode 100644 index 0d835033..00000000 --- a/dist/node/index.cjs +++ /dev/null @@ -1,623 +0,0 @@ -'use strict'; - -/** - * Special values that tell deepmerge to perform a certain action. - */ -const actions = { - defaultMerge: Symbol("deepmerge-ts: default merge"), - skip: Symbol("deepmerge-ts: skip"), -}; -/** - * Special values that tell deepmergeInto to perform a certain action. - */ -const actionsInto = { - defaultMerge: actions.defaultMerge, -}; - -/** - * The default function to update meta data. - * - * It doesn't update the meta data. - */ -function defaultMetaDataUpdater(previousMeta, metaMeta) { - return metaMeta; -} -/** - * The default function to filter values. - * - * It filters out undefined values. - */ -function defaultFilterValues(values, meta) { - return values.filter((value) => value !== undefined); -} - -/** - * The different types of objects deepmerge-ts support. - */ -var ObjectType; -(function (ObjectType) { - ObjectType[ObjectType["NOT"] = 0] = "NOT"; - ObjectType[ObjectType["RECORD"] = 1] = "RECORD"; - ObjectType[ObjectType["ARRAY"] = 2] = "ARRAY"; - ObjectType[ObjectType["SET"] = 3] = "SET"; - ObjectType[ObjectType["MAP"] = 4] = "MAP"; - ObjectType[ObjectType["OTHER"] = 5] = "OTHER"; -})(ObjectType || (ObjectType = {})); -/** - * Get the type of the given object. - * - * @param object - The object to get the type of. - * @returns The type of the given object. - */ -function getObjectType(object) { - if (typeof object !== "object" || object === null) { - return 0 /* ObjectType.NOT */; - } - if (Array.isArray(object)) { - return 2 /* ObjectType.ARRAY */; - } - if (isRecord(object)) { - return 1 /* ObjectType.RECORD */; - } - if (object instanceof Set) { - return 3 /* ObjectType.SET */; - } - if (object instanceof Map) { - return 4 /* ObjectType.MAP */; - } - return 5 /* ObjectType.OTHER */; -} -/** - * Get the keys of the given objects including symbol keys. - * - * Note: Only keys to enumerable properties are returned. - * - * @param objects - An array of objects to get the keys of. - * @returns A set containing all the keys of all the given objects. - */ -function getKeys(objects) { - const keys = new Set(); - for (const object of objects) { - for (const key of [ - ...Object.keys(object), - ...Object.getOwnPropertySymbols(object), - ]) { - keys.add(key); - } - } - return keys; -} -/** - * Does the given object have the given property. - * - * @param object - The object to test. - * @param property - The property to test. - * @returns Whether the object has the property. - */ -function objectHasProperty(object, property) { - return (typeof object === "object" && - Object.prototype.propertyIsEnumerable.call(object, property)); -} -/** - * Get an iterable object that iterates over the given iterables. - */ -function getIterableOfIterables(iterables) { - return { - *[Symbol.iterator]() { - for (const iterable of iterables) { - for (const value of iterable) { - yield value; - } - } - }, - }; -} -const validRecordToStringValues = new Set([ - "[object Object]", - "[object Module]", -]); -/** - * Does the given object appear to be a record. - */ -function isRecord(value) { - // All records are objects. - if (!validRecordToStringValues.has(Object.prototype.toString.call(value))) { - return false; - } - const { constructor } = value; - // If has modified constructor. - // eslint-disable-next-line ts/no-unnecessary-condition - if (constructor === undefined) { - return true; - } - const prototype = constructor.prototype; - // If has modified prototype. - if (prototype === null || - typeof prototype !== "object" || - !validRecordToStringValues.has(Object.prototype.toString.call(prototype))) { - return false; - } - // If constructor does not have an Object-specific method. - // eslint-disable-next-line sonar/prefer-single-boolean-return, no-prototype-builtins - if (!prototype.hasOwnProperty("isPrototypeOf")) { - return false; - } - // Most likely a record. - return true; -} - -/** - * The default strategy to merge records. - * - * @param values - The records. - */ -function mergeRecords$1(values, utils, meta) { - const result = {}; - for (const key of getKeys(values)) { - const propValues = []; - for (const value of values) { - if (objectHasProperty(value, key)) { - propValues.push(value[key]); - } - } - if (propValues.length === 0) { - continue; - } - const updatedMeta = utils.metaDataUpdater(meta, { - key, - parents: values, - }); - const propertyResult = mergeUnknowns(propValues, utils, updatedMeta); - if (propertyResult === actions.skip) { - continue; - } - if (key === "__proto__") { - Object.defineProperty(result, key, { - value: propertyResult, - configurable: true, - enumerable: true, - writable: true, - }); - } - else { - result[key] = propertyResult; - } - } - return result; -} -/** - * The default strategy to merge arrays. - * - * @param values - The arrays. - */ -function mergeArrays$1(values) { - return values.flat(); -} -/** - * The default strategy to merge sets. - * - * @param values - The sets. - */ -function mergeSets$1(values) { - return new Set(getIterableOfIterables(values)); -} -/** - * The default strategy to merge maps. - * - * @param values - The maps. - */ -function mergeMaps$1(values) { - return new Map(getIterableOfIterables(values)); -} -/** - * Get the last non-undefined value in the given array. - */ -function mergeOthers$1(values) { - return values.at(-1); -} -/** - * The merge functions. - */ -const mergeFunctions = { - mergeRecords: mergeRecords$1, - mergeArrays: mergeArrays$1, - mergeSets: mergeSets$1, - mergeMaps: mergeMaps$1, - mergeOthers: mergeOthers$1, -}; - -/** - * Deeply merge objects. - * - * @param objects - The objects to merge. - */ -function deepmerge(...objects) { - return deepmergeCustom({})(...objects); -} -function deepmergeCustom(options, rootMetaData) { - const utils = getUtils(options, customizedDeepmerge); - /** - * The customized deepmerge function. - */ - function customizedDeepmerge(...objects) { - return mergeUnknowns(objects, utils, rootMetaData); - } - return customizedDeepmerge; -} -/** - * The the utils that are available to the merge functions. - * - * @param options - The options the user specified - */ -function getUtils(options, customizedDeepmerge) { - return { - defaultMergeFunctions: mergeFunctions, - mergeFunctions: { - ...mergeFunctions, - ...Object.fromEntries(Object.entries(options) - .filter(([key, option]) => Object.hasOwn(mergeFunctions, key)) - .map(([key, option]) => option === false - ? [key, mergeFunctions.mergeOthers] - : [key, option])), - }, - metaDataUpdater: (options.metaDataUpdater ?? - defaultMetaDataUpdater), - deepmerge: customizedDeepmerge, - useImplicitDefaultMerging: options.enableImplicitDefaultMerging ?? false, - filterValues: options.filterValues === false - ? undefined - : options.filterValues ?? defaultFilterValues, - actions, - }; -} -/** - * Merge unknown things. - * - * @param values - The values. - */ -function mergeUnknowns(values, utils, meta) { - const filteredValues = utils.filterValues?.(values, meta) ?? values; - if (filteredValues.length === 0) { - return undefined; - } - if (filteredValues.length === 1) { - return mergeOthers(filteredValues, utils, meta); - } - const type = getObjectType(filteredValues[0]); - if (type !== 0 /* ObjectType.NOT */ && type !== 5 /* ObjectType.OTHER */) { - for (let m_index = 1; m_index < filteredValues.length; m_index++) { - if (getObjectType(filteredValues[m_index]) === type) { - continue; - } - return mergeOthers(filteredValues, utils, meta); - } - } - switch (type) { - case 1 /* ObjectType.RECORD */: { - return mergeRecords(filteredValues, utils, meta); - } - case 2 /* ObjectType.ARRAY */: { - return mergeArrays(filteredValues, utils, meta); - } - case 3 /* ObjectType.SET */: { - return mergeSets(filteredValues, utils, meta); - } - case 4 /* ObjectType.MAP */: { - return mergeMaps(filteredValues, utils, meta); - } - default: { - return mergeOthers(filteredValues, utils, meta); - } - } -} -/** - * Merge records. - * - * @param values - The records. - */ -function mergeRecords(values, utils, meta) { - 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(values, utils, meta); - } - return result; -} -/** - * Merge arrays. - * - * @param values - The arrays. - */ -function mergeArrays(values, utils, meta) { - 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(values, utils, meta) { - 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(values, utils, meta) { - 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(values, utils, meta) { - 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 into a target record. - * - * @param m_target - The result will be mutated into this record - * @param values - The records (including the target's value if there is one). - */ -function mergeRecordsInto$1(m_target, values, utils, meta) { - for (const key of getKeys(values)) { - const propValues = []; - for (const value of values) { - if (objectHasProperty(value, key)) { - propValues.push(value[key]); - } - } - if (propValues.length === 0) { - continue; - } - const updatedMeta = utils.metaDataUpdater(meta, { - key, - parents: values, - }); - const propertyTarget = { value: propValues[0] }; - mergeUnknownsInto(propertyTarget, propValues, utils, updatedMeta); - if (key === "__proto__") { - Object.defineProperty(m_target.value, key, { - value: propertyTarget.value, - configurable: true, - enumerable: true, - writable: true, - }); - } - else { - m_target.value[key] = propertyTarget.value; - } - } -} -/** - * The default strategy to merge arrays into a target array. - * - * @param m_target - The result will be mutated into this array - * @param values - The arrays (including the target's value if there is one). - */ -function mergeArraysInto$1(m_target, values) { - m_target.value.push(...values.slice(1).flat()); -} -/** - * The default strategy to merge sets into a target set. - * - * @param m_target - The result will be mutated into this set - * @param values - The sets (including the target's value if there is one). - */ -function mergeSetsInto$1(m_target, values) { - for (const value of getIterableOfIterables(values.slice(1))) { - m_target.value.add(value); - } -} -/** - * The default strategy to merge maps into a target map. - * - * @param m_target - The result will be mutated into this map - * @param values - The maps (including the target's value if there is one). - */ -function mergeMapsInto$1(m_target, values) { - for (const [key, value] of getIterableOfIterables(values.slice(1))) { - m_target.value.set(key, value); - } -} -/** - * Set the target to the last non-undefined value. - */ -function mergeOthersInto$1(m_target, values) { - m_target.value = values.at(-1); -} -/** - * The merge functions. - */ -const mergeIntoFunctions = { - mergeRecords: mergeRecordsInto$1, - mergeArrays: mergeArraysInto$1, - mergeSets: mergeSetsInto$1, - mergeMaps: mergeMapsInto$1, - mergeOthers: mergeOthersInto$1, -}; - -function deepmergeInto(target, ...objects) { - return void deepmergeIntoCustom({})(target, ...objects); -} -function deepmergeIntoCustom(options, rootMetaData) { - const utils = getIntoUtils(options, customizedDeepmergeInto); - /** - * The customized deepmerge function. - */ - function customizedDeepmergeInto(target, ...objects) { - mergeUnknownsInto({ value: target }, [target, ...objects], utils, rootMetaData); - } - return customizedDeepmergeInto; -} -/** - * The the utils that are available to the merge functions. - * - * @param options - The options the user specified - */ -function getIntoUtils(options, customizedDeepmergeInto) { - return { - defaultMergeFunctions: mergeIntoFunctions, - mergeFunctions: { - ...mergeIntoFunctions, - ...Object.fromEntries(Object.entries(options) - .filter(([key, option]) => Object.hasOwn(mergeIntoFunctions, key)) - .map(([key, option]) => option === false - ? [key, mergeIntoFunctions.mergeOthers] - : [key, option])), - }, - metaDataUpdater: (options.metaDataUpdater ?? - defaultMetaDataUpdater), - deepmergeInto: customizedDeepmergeInto, - filterValues: options.filterValues === false - ? undefined - : options.filterValues ?? defaultFilterValues, - actions: actionsInto, - }; -} -/** - * Merge unknown things into a target. - * - * @param m_target - The target to merge into. - * @param values - The values. - */ -function mergeUnknownsInto(m_target, values, utils, meta) { - const filteredValues = utils.filterValues?.(values, meta) ?? values; - if (filteredValues.length === 0) { - return; - } - if (filteredValues.length === 1) { - return void mergeOthersInto(m_target, filteredValues, utils, meta); - } - const type = getObjectType(m_target.value); - if (type !== 0 /* ObjectType.NOT */ && type !== 5 /* ObjectType.OTHER */) { - for (let m_index = 1; m_index < filteredValues.length; m_index++) { - if (getObjectType(filteredValues[m_index]) === type) { - continue; - } - return void mergeOthersInto(m_target, filteredValues, utils, meta); - } - } - switch (type) { - case 1 /* ObjectType.RECORD */: { - return void mergeRecordsInto(m_target, filteredValues, utils, meta); - } - case 2 /* ObjectType.ARRAY */: { - return void mergeArraysInto(m_target, filteredValues, utils, meta); - } - case 3 /* ObjectType.SET */: { - return void mergeSetsInto(m_target, filteredValues, utils, meta); - } - case 4 /* ObjectType.MAP */: { - return void mergeMapsInto(m_target, filteredValues, utils, meta); - } - default: { - return void mergeOthersInto(m_target, filteredValues, utils, meta); - } - } -} -/** - * Merge records into a target record. - * - * @param m_target - The target to merge into. - * @param values - The records. - */ -function mergeRecordsInto(m_target, values, utils, meta) { - const action = utils.mergeFunctions.mergeRecords(m_target, values, utils, meta); - if (action === actionsInto.defaultMerge) { - utils.defaultMergeFunctions.mergeRecords(m_target, values, utils, meta); - } -} -/** - * Merge arrays into a target array. - * - * @param m_target - The target to merge into. - * @param values - The arrays. - */ -function mergeArraysInto(m_target, values, utils, meta) { - const action = utils.mergeFunctions.mergeArrays(m_target, values, utils, meta); - if (action === actionsInto.defaultMerge) { - utils.defaultMergeFunctions.mergeArrays(m_target, values); - } -} -/** - * Merge sets into a target set. - * - * @param m_target - The target to merge into. - * @param values - The sets. - */ -function mergeSetsInto(m_target, values, utils, meta) { - const action = utils.mergeFunctions.mergeSets(m_target, values, utils, meta); - if (action === actionsInto.defaultMerge) { - utils.defaultMergeFunctions.mergeSets(m_target, values); - } -} -/** - * Merge maps into a target map. - * - * @param m_target - The target to merge into. - * @param values - The maps. - */ -function mergeMapsInto(m_target, values, utils, meta) { - const action = utils.mergeFunctions.mergeMaps(m_target, values, utils, meta); - if (action === actionsInto.defaultMerge) { - utils.defaultMergeFunctions.mergeMaps(m_target, values); - } -} -/** - * Merge other things into a target. - * - * @param m_target - The target to merge into. - * @param values - The other things. - */ -function mergeOthersInto(m_target, values, utils, meta) { - const action = utils.mergeFunctions.mergeOthers(m_target, values, utils, meta); - if (action === actionsInto.defaultMerge || - m_target.value === actionsInto.defaultMerge) { - utils.defaultMergeFunctions.mergeOthers(m_target, values); - } -} - -exports.deepmerge = deepmerge; -exports.deepmergeCustom = deepmergeCustom; -exports.deepmergeInto = deepmergeInto; -exports.deepmergeIntoCustom = deepmergeIntoCustom; -exports.getKeys = getKeys; -exports.getObjectType = getObjectType; -exports.objectHasProperty = objectHasProperty; diff --git a/dist/node/index.d.cts b/dist/node/index.d.cts deleted file mode 100644 index 6f4d114a..00000000 --- a/dist/node/index.d.cts +++ /dev/null @@ -1,849 +0,0 @@ -/** - * Simplify a complex type such as a union or intersection of objects into a - * single object. - */ -type SimplifyObject = { - [K in keyof T]: T[K]; -} & {}; -/** - * Flatten a collection of tuples of tuples into a collection of tuples. - */ -type FlattenTuples = { - [I in keyof T]: FlattenTuple; -}; -/** - * Flatten a tuple of tuples into a single tuple. - */ -type FlattenTuple = T extends readonly [ -] ? [ -] : T extends readonly [ - infer T0 -] ? [ - ...FlattenTuple -] : T extends readonly [ - infer T0, - ...infer Ts -] ? [ - ...FlattenTuple, - ...FlattenTuple -] : [ - T -]; -/** - * Safely test whether or not the first given types extends the second. - * - * Needed in particular for testing if a type is "never". - */ -type Is = [ - T1 -] extends [ - T2 -] ? true : false; -/** - * Safely test whether or not the given type is "never". - */ -type IsNever = Is; -/** - * And operator for types. - */ -type And = T1 extends false ? false : T2; -/** - * Not operator for types. - */ -type Not = T extends true ? false : true; -/** - * Check if a key is optional in the given object. - */ -type KeyIsOptional = O extends { - [Key in K]: unknown; -} ? false : true; -/** - * Returns whether or not the given type a record. - */ -type IsRecord = And>, T extends Readonly> ? true : false>; -/** - * Returns whether or not all the given types are records. - */ -type EveryIsRecord> = Ts extends readonly [ - infer Head, - ...infer Rest -] ? IsRecord extends true ? Rest extends ReadonlyArray ? EveryIsRecord : true : false : true; -/** - * Returns whether or not the given type is an array. - */ -type IsArray = And>, T extends ReadonlyArray ? true : false>; -/** - * Returns whether or not all the given types are arrays. - */ -type EveryIsArray> = Ts extends readonly [ - infer T1 -] ? IsArray : Ts extends readonly [ - infer Head, - ...infer Rest -] ? IsArray extends true ? Rest extends readonly [ - unknown, - ...ReadonlyArray -] ? EveryIsArray : false : false : false; -/** - * Returns whether or not the given type is an set. - * - * Note: This may also return true for Maps. - */ -type IsSet = And>, T extends Readonly> ? true : false>; -/** - * Returns whether or not all the given types are sets. - * - * Note: This may also return true if all are maps. - */ -type EveryIsSet> = Ts extends Readonly ? IsSet : Ts extends readonly [ - infer Head, - ...infer Rest -] ? IsSet extends true ? Rest extends readonly [ - unknown, - ...ReadonlyArray -] ? EveryIsSet : false : false : false; -/** - * Returns whether or not the given type is an map. - */ -type IsMap = And>, T extends Readonly> ? true : false>; -/** - * Returns whether or not all the given types are maps. - */ -type EveryIsMap> = Ts extends Readonly ? IsMap : Ts extends readonly [ - infer Head, - ...infer Rest -] ? IsMap extends true ? Rest extends readonly [ - unknown, - ...ReadonlyArray -] ? EveryIsMap : false : false : false; -/** - * Union of the sets' values' types - */ -type UnionSetValues> = UnionSetValuesHelper; -/** - * Tail-recursive helper type for UnionSetValues. - */ -type UnionSetValuesHelper, Acc> = Ts extends readonly [ - infer Head, - ...infer Rest -] ? Head extends Readonly> ? Rest extends ReadonlyArray ? UnionSetValuesHelper : Acc | V1 : never : Acc; -/** - * Union of the maps' values' types - */ -type UnionMapKeys> = UnionMapKeysHelper; -/** - * Tail-recursive helper type for UnionMapKeys. - */ -type UnionMapKeysHelper, Acc> = Ts extends readonly [ - infer Head, - ...infer Rest -] ? Head extends Readonly> ? Rest extends readonly [ -] ? Acc | K1 : UnionMapKeysHelper : never : Acc; -/** - * Union of the maps' keys' types - */ -type UnionMapValues> = UnionMapValuesHelper; -/** - * Tail-recursive helper type for UnionMapValues. - */ -type UnionMapValuesHelper, Acc> = Ts extends readonly [ - infer Head, - ...infer Rest -] ? Head extends Readonly> ? Rest extends readonly [ -] ? Acc | V1 : UnionMapValuesHelper : never : Acc; -/** - * Filter out U from a tuple. - */ -type FilterOut, U> = FilterOutHelper; -/** - * Tail-recursive helper type for FilterOut. - */ -type FilterOutHelper, U, Acc extends ReadonlyArray> = T extends readonly [ -] ? Acc : T extends readonly [ - infer Head, - ...infer Rest -] ? Is extends true ? FilterOutHelper : FilterOutHelper : T; -/** - * Filter out nevers from a tuple. - */ -type FilterOutNever = T extends ReadonlyArray ? FilterOut : never; -/** - * Is the type a tuple? - */ -type IsTuple> = T extends readonly [ -] ? true : T extends readonly [ - unknown, - ...ReadonlyArray -] ? true : false; -/** - * Perfrom a transpose operation on a 2D tuple. - */ -type TransposeTuple = T extends readonly [ - ...(readonly [ - ...unknown[] - ]) -] ? T extends readonly [ -] ? [ -] : T extends readonly [ - infer X extends ReadonlyArray -] ? TransposeTupleSimpleCase : T extends readonly [ - infer X extends ReadonlyArray, - ...infer XS extends ReadonlyArray> -] ? PrependCol> : T : never; -type PrependCol, S extends ReadonlyArray>> = T extends readonly [ -] ? S extends readonly [ -] ? [ -] : never : T extends readonly [ - infer X, - ...infer XS -] ? S extends readonly [ - readonly [ - ...infer Y - ], - ...infer YS extends ReadonlyArray> -] ? [ - [ - X, - ...Y - ], - ...PrependCol -] : never : never; -type TransposeTupleSimpleCase = T extends readonly [ -] ? [ -] : T extends readonly [ - infer X, - ...infer XS -] ? [ - [ - X - ], - ...TransposeTupleSimpleCase -] : never; -/** - * Convert a tuple to an intersection of each of its types. - */ -type TupleToIntersection> = { - [K in keyof T]: (x: T[K]) => void; -} extends Record void> ? I : never; -/** - * Convert a union to a tuple. - * - * Warning: The order of the elements is non-deterministic. - * Warning 2: The union maybe me modified by the TypeScript engine before convertion. - * Warning 3: This implementation relies on a hack/limitation in TypeScript. - */ -type TuplifyUnion> = IsNever extends true ? [ -] : [ - ...TuplifyUnion>, - L -]; -type UnionToIntersection = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never; -type LastOf = UnionToIntersection T : never> extends () => infer R ? R : never; -/** - * Mapping of merge function URIs to the merge function type. - */ -// eslint-disable-next-line ts/consistent-type-definitions -interface DeepMergeFunctionURItoKind, Fs extends DeepMergeFunctionsURIs, in out M> { - readonly DeepMergeLeafURI: DeepMergeLeaf; - readonly DeepMergeRecordsDefaultURI: DeepMergeRecordsDefaultHKT; - readonly DeepMergeArraysDefaultURI: DeepMergeArraysDefaultHKT; - readonly DeepMergeSetsDefaultURI: DeepMergeSetsDefaultHKT; - readonly DeepMergeMapsDefaultURI: DeepMergeMapsDefaultHKT; - readonly DeepMergeFilterValuesDefaultURI: DeepMergeFilterValuesDefaultHKT; - readonly DeepMergeNoFilteringURI: Ts; -} -/** - * Get the type of the given merge function via its URI. - */ -type DeepMergeFunctionKind, Fs extends DeepMergeFunctionsURIs, M> = DeepMergeFunctionURItoKind[URI]; -/** - * A union of all valid merge function URIs. - */ -type DeepMergeFunctionURIs = keyof DeepMergeFunctionURItoKind, DeepMergeFunctionsURIs, unknown>; -/** - * The merge functions to use when deep merging. - */ -type DeepMergeFunctionsURIs = Readonly<{ - /** - * The merge function to merge records with. - */ - DeepMergeRecordsURI: DeepMergeFunctionURIs; - /** - * The merge function to merge arrays with. - */ - DeepMergeArraysURI: DeepMergeFunctionURIs; - /** - * The merge function to merge sets with. - */ - DeepMergeSetsURI: DeepMergeFunctionURIs; - /** - * The merge function to merge maps with. - */ - DeepMergeMapsURI: DeepMergeFunctionURIs; - /** - * The merge function to merge other things with. - */ - DeepMergeOthersURI: DeepMergeFunctionURIs; - /** - * The function to filter values. - */ - DeepMergeFilterValuesURI: DeepMergeFunctionURIs; -}>; -/** - * Deep merge types. - */ -type DeepMergeHKT, Fs extends DeepMergeFunctionsURIs, M> = IsTuple extends true ? Ts extends readonly [ -] ? undefined : DeepMergeHKTHelper, Fs, M> : unknown; -type DeepMergeHKTHelper = Ts extends ReadonlyArray ? IsTuple extends true ? Ts extends readonly [ -] ? unknown : Ts extends readonly [ - infer T1 -] ? T1 : EveryIsArray extends true ? DeepMergeArraysHKT : EveryIsMap extends true ? DeepMergeMapsHKT : EveryIsSet extends true ? DeepMergeSetsHKT : EveryIsRecord extends true ? DeepMergeRecordsHKT : DeepMergeOthersHKT : unknown : never; -/** - * Deep merge records. - */ -type DeepMergeRecordsHKT, Fs extends DeepMergeFunctionsURIs, M> = DeepMergeFunctionKind; -/** - * Deep merge arrays. - */ -type DeepMergeArraysHKT, Fs extends DeepMergeFunctionsURIs, M> = DeepMergeFunctionKind; -/** - * Deep merge sets. - */ -type DeepMergeSetsHKT, Fs extends DeepMergeFunctionsURIs, M> = DeepMergeFunctionKind; -/** - * Deep merge maps. - */ -type DeepMergeMapsHKT, Fs extends DeepMergeFunctionsURIs, M> = DeepMergeFunctionKind; -/** - * Deep merge other things. - */ -type DeepMergeOthersHKT, Fs extends DeepMergeFunctionsURIs, M> = DeepMergeFunctionKind; -/** - * Filter values. - */ -type FilterValuesHKT, Fs extends DeepMergeFunctionsURIs, M> = DeepMergeFunctionKind; -/** - * The merge function that returns a leaf. - */ -type DeepMergeLeafURI = "DeepMergeLeafURI"; -/** - * Don't filter values. - */ -type DeepMergeNoFilteringURI = "DeepMergeNoFilteringURI"; -/** - * Get the leaf type from many types that can't be merged. - */ -type DeepMergeLeaf> = Ts extends readonly [ -] ? never : Ts extends readonly [ - infer T -] ? T : Ts extends readonly [ - ...infer Rest, - infer Tail -] ? IsNever extends true ? Rest extends ReadonlyArray ? DeepMergeLeaf : never : Tail : never; -/** - * The meta data deepmerge is able to provide. - */ -type DeepMergeBuiltInMetaData = Readonly<{ - key: PropertyKey; - parents: ReadonlyArray>>; -}>; -/** - * The default merge function to merge records with. - */ -type DeepMergeRecordsDefaultURI = "DeepMergeRecordsDefaultURI"; -/** - * The default merge function to merge arrays with. - */ -type DeepMergeArraysDefaultURI = "DeepMergeArraysDefaultURI"; -/** - * The default merge function to merge sets with. - */ -type DeepMergeSetsDefaultURI = "DeepMergeSetsDefaultURI"; -/** - * The default merge function to merge maps with. - */ -type DeepMergeMapsDefaultURI = "DeepMergeMapsDefaultURI"; -/** - * The default filter values function. - */ -type DeepMergeFilterValuesDefaultURI = "DeepMergeFilterValuesDefaultURI"; -/** - * The default merge functions to use when deep merging. - */ -type DeepMergeFunctionsDefaultURIs = Readonly<{ - DeepMergeRecordsURI: DeepMergeRecordsDefaultURI; - DeepMergeArraysURI: DeepMergeArraysDefaultURI; - DeepMergeSetsURI: DeepMergeSetsDefaultURI; - DeepMergeMapsURI: DeepMergeMapsDefaultURI; - DeepMergeOthersURI: DeepMergeLeafURI; - DeepMergeFilterValuesURI: DeepMergeFilterValuesDefaultURI; -}>; -type RecordEntries> = FilterOut, undefined>; -type RecordMeta = Record; -type RecordPropertyMeta = { - key: Key; - value: Value; - optional: Optional; -}; -type RecordsToRecordMeta>> = FilterOutNever<{ - [I in keyof Ts]: RecordToRecordMeta; -}>; -type RecordToRecordMeta> = { - [K in keyof T]-?: { - key: K; - value: Required[K]; - optional: KeyIsOptional; - }; -}; -/** - * Deep merge records. - */ -type DeepMergeRecordsDefaultHKT, Fs extends DeepMergeFunctionsURIs, M> = Ts extends ReadonlyArray> ? SimplifyObject, Fs, M>> : never; -/** - * Deep merge record props. - */ -type DeepMergeRecordMetaDefaultHKTProps = RecordMetas extends ReadonlyArray ? CreateRecordFromMeta, Fs, M> : never; -type MergeRecordMeta> = GroupValuesByKey>; -}, readonly [ -]>>>>; -type GroupValuesByKey = Ts extends readonly [ - infer Keys extends ReadonlyArray, - infer Values -] ? { - [I in keyof Keys]: DeepMergeRecordPropertyMetaDefaultHKTGetPossible>; -} : never; -type CreateRecordFromMeta = Ts extends ReadonlyArray ? TupleToIntersection<{ - [I in keyof Ts]: Ts[I] extends { - key: infer Key extends PropertyKey; - values: infer Values extends ReadonlyArray; - optional: infer O extends boolean; - } ? CreateRecordForKeyFromMeta : never; -}> : never; -type CreateRecordForKeyFromMeta, Optional extends boolean, Fs extends DeepMergeFunctionsURIs, M> = Optional extends true ? { - [k in Key]+?: DeepMergeHKT; -} : { - [k in Key]-?: DeepMergeHKT; -}; -/** - * Get the possible types of a property. - */ -type DeepMergeRecordPropertyMetaDefaultHKTGetPossible = Ts extends readonly [ - RecordPropertyMeta, - ...ReadonlyArray -] ? DeepMergeRecordPropertyMetaDefaultHKTGetPossibleHelper : never; -/** - * Tail-recursive helper type for DeepMergeRecordPropertyMetaDefaultHKTGetPossible. - */ -type DeepMergeRecordPropertyMetaDefaultHKTGetPossibleHelper -], Acc extends { - key: PropertyKey; - values: ReadonlyArray; - optional: boolean; -}> = Ts extends [ - ...infer Rest, - { - key: infer K extends PropertyKey; - value: infer V; - optional: infer O extends boolean; - } -] ? Acc["optional"] extends true ? Acc extends { - values: [ - infer Head, - ...infer AccRest - ]; -} ? Rest extends readonly [ - RecordPropertyMeta, - ...ReadonlyArray -] ? DeepMergeRecordPropertyMetaDefaultHKTGetPossibleHelper : { - key: K; - values: [ - V | Head, - ...AccRest - ]; - optional: O; -} : Rest extends readonly [ - RecordPropertyMeta, - ...ReadonlyArray -] ? DeepMergeRecordPropertyMetaDefaultHKTGetPossibleHelper : { - key: K; - values: [ - V, - ...Acc["values"] - ]; - optional: O; -} : Rest extends readonly [ - RecordPropertyMeta, - ...ReadonlyArray -] ? DeepMergeRecordPropertyMetaDefaultHKTGetPossibleHelper : { - key: K; - values: [ - V, - ...Acc["values"] - ]; - optional: O; -} : never; -/** - * Deep merge arrays. - */ -type DeepMergeArraysDefaultHKT, Fs extends DeepMergeFunctionsURIs, M> = DeepMergeArraysDefaultHKTHelper; -/** - * Tail-recursive helper type for DeepMergeArraysDefaultHKT. - */ -type DeepMergeArraysDefaultHKTHelper, Fs extends DeepMergeFunctionsURIs, M, Acc extends ReadonlyArray> = Ts extends readonly [ - infer Head extends ReadonlyArray, - ...infer Rest -] ? Rest extends readonly [ - ReadonlyArray, - ...ReadonlyArray> -] ? DeepMergeArraysDefaultHKTHelper : [ - ...Acc, - ...Head -] : never; -/** - * Deep merge sets. - */ -type DeepMergeSetsDefaultHKT> = Set>; -/** - * Deep merge maps. - */ -type DeepMergeMapsDefaultHKT> = Map, UnionMapValues>; -/** - * Filter out undefined values. - */ -type DeepMergeFilterValuesDefaultHKT> = FilterOut; -/** - * Get the merge functions with defaults apply from the given subset. - */ -type GetDeepMergeFunctionsURIs> = Readonly<{ - // prettier-ignore - DeepMergeRecordsURI: PMF["DeepMergeRecordsURI"] extends keyof DeepMergeFunctionURItoKind ? PMF["DeepMergeRecordsURI"] : DeepMergeRecordsDefaultURI; - // prettier-ignore - DeepMergeArraysURI: PMF["DeepMergeArraysURI"] extends keyof DeepMergeFunctionURItoKind ? PMF["DeepMergeArraysURI"] : DeepMergeArraysDefaultURI; - // prettier-ignore - DeepMergeSetsURI: PMF["DeepMergeSetsURI"] extends keyof DeepMergeFunctionURItoKind ? PMF["DeepMergeSetsURI"] : DeepMergeSetsDefaultURI; - // prettier-ignore - DeepMergeMapsURI: PMF["DeepMergeMapsURI"] extends keyof DeepMergeFunctionURItoKind ? PMF["DeepMergeMapsURI"] : DeepMergeMapsDefaultURI; - // prettier-ignore - DeepMergeOthersURI: PMF["DeepMergeOthersURI"] extends keyof DeepMergeFunctionURItoKind ? PMF["DeepMergeOthersURI"] : DeepMergeLeafURI; - // prettier-ignore - DeepMergeFilterValuesURI: PMF["DeepMergeFilterValuesURI"] extends keyof DeepMergeFunctionURItoKind ? PMF["DeepMergeFilterValuesURI"] : DeepMergeFilterValuesDefaultURI; -}>; -/** - * The default merge functions. - */ -type MergeFunctions = { - mergeRecords: typeof mergeRecordsInto; - mergeArrays: typeof mergeArraysInto; - mergeSets: typeof mergeSetsInto; - mergeMaps: typeof mergeMapsInto; - mergeOthers: typeof mergeOthersInto; -}; -/** - * The default strategy to merge records into a target record. - * - * @param m_target - The result will be mutated into this record - * @param values - The records (including the target's value if there is one). - */ -declare function mergeRecordsInto>, U extends DeepMergeIntoFunctionUtils, M, MM extends DeepMergeBuiltInMetaData = DeepMergeBuiltInMetaData>(m_target: Reference>, values: Ts, utils: U, meta: M | undefined): void; -/** - * The default strategy to merge arrays into a target array. - * - * @param m_target - The result will be mutated into this array - * @param values - The arrays (including the target's value if there is one). - */ -declare function mergeArraysInto>>(m_target: Reference, values: Ts): void; -/** - * The default strategy to merge sets into a target set. - * - * @param m_target - The result will be mutated into this set - * @param values - The sets (including the target's value if there is one). - */ -declare function mergeSetsInto>>>(m_target: Reference>, values: Ts): void; -/** - * The default strategy to merge maps into a target map. - * - * @param m_target - The result will be mutated into this map - * @param values - The maps (including the target's value if there is one). - */ -declare function mergeMapsInto>>>(m_target: Reference>, values: Ts): void; -/** - * Set the target to the last non-undefined value. - */ -declare function mergeOthersInto>(m_target: Reference, values: Ts): void; -type MergeIntoFunctions = MergeFunctions; -/** - * The default merge functions. - */ -type MergeFunctions$0 = { - mergeRecords: typeof mergeRecords; - mergeArrays: typeof mergeArrays; - mergeSets: typeof mergeSets; - mergeMaps: typeof mergeMaps; - mergeOthers: typeof mergeOthers; -}; -/** - * The default strategy to merge records. - * - * @param values - The records. - */ -declare function mergeRecords>, U extends DeepMergeUtils, Fs extends DeepMergeFunctionsURIs, M, MM extends DeepMergeBuiltInMetaData = DeepMergeBuiltInMetaData>(values: Ts, utils: U, meta: M | undefined): DeepMergeRecordsDefaultHKT; -/** - * The default strategy to merge arrays. - * - * @param values - The arrays. - */ -declare function mergeArrays>, Fs extends DeepMergeFunctionsURIs, M>(values: Ts): DeepMergeArraysDefaultHKT; -/** - * The default strategy to merge sets. - * - * @param values - The sets. - */ -declare function mergeSets>>>(values: Ts): DeepMergeSetsDefaultHKT; -/** - * The default strategy to merge maps. - * - * @param values - The maps. - */ -declare function mergeMaps>>>(values: Ts): DeepMergeMapsDefaultHKT; -/** - * Get the last non-undefined value in the given array. - */ -declare function mergeOthers>(values: Ts): unknown; -/** - * The options the user can pass to customize deepmerge. - */ -type DeepMergeOptions> = {}> = Partial>; -/** - * The options the user can pass to customize deepmergeInto. - */ -type DeepMergeIntoOptions> = {}> = Partial>; -type MetaDataUpdater = (previousMeta: M | undefined, metaMeta: Readonly>) => M; -/** - * All the options the user can pass to customize deepmerge. - */ -type DeepMergeOptionsFull = Readonly<{ - mergeRecords: DeepMergeFunctions["mergeRecords"] | false; - mergeArrays: DeepMergeFunctions["mergeArrays"] | false; - mergeMaps: DeepMergeFunctions["mergeMaps"] | false; - mergeSets: DeepMergeFunctions["mergeSets"] | false; - mergeOthers: DeepMergeFunctions["mergeOthers"]; - metaDataUpdater: MetaDataUpdater; - enableImplicitDefaultMerging: boolean; - filterValues: DeepMergeUtilityFunctions["filterValues"] | false; -}>; -/** - * All the options the user can pass to customize deepmergeInto. - */ -type DeepMergeIntoOptionsFull = Readonly<{ - mergeRecords: DeepMergeIntoFunctions["mergeRecords"] | false; - mergeArrays: DeepMergeIntoFunctions["mergeArrays"] | false; - mergeMaps: DeepMergeIntoFunctions["mergeMaps"] | false; - mergeSets: DeepMergeIntoFunctions["mergeSets"] | false; - mergeOthers: DeepMergeIntoFunctions["mergeOthers"]; - metaDataUpdater: MetaDataUpdater; - filterValues: DeepMergeUtilityFunctions["filterValues"] | false; -}>; -/** - * An object that has a reference to a value. - */ -type Reference = { - value: T; -}; -/** - * All the utility functions that can be overridden. - */ -type DeepMergeUtilityFunctions = Readonly<{ - filterValues: >(values: Ts, meta: M | undefined) => unknown[]; -}>; -/** - * All the merge functions that deepmerge uses. - */ -type DeepMergeFunctions = Readonly<{ - mergeRecords: >>, U extends DeepMergeUtils>(values: Ts, utils: U, meta: M | undefined) => unknown; - mergeArrays: >, U extends DeepMergeUtils>(values: Ts, utils: U, meta: M | undefined) => unknown; - mergeMaps: >>, U extends DeepMergeUtils>(values: Ts, utils: U, meta: M | undefined) => unknown; - mergeSets: >>, U extends DeepMergeUtils>(values: Ts, utils: U, meta: M | undefined) => unknown; - mergeOthers: , U extends DeepMergeUtils>(values: Ts, utils: U, meta: M | undefined) => unknown; -}>; -// eslint-disable-next-line ts/no-invalid-void-type -type DeepMergeIntoFunctionsReturnType = void | symbol; -/** - * All the merge functions that deepmerge uses. - */ -type DeepMergeIntoFunctions = Readonly<{ - mergeRecords: >>, U extends DeepMergeIntoFunctionUtils>(m_target: Reference>, values: Ts, utils: U, meta: M | undefined) => DeepMergeIntoFunctionsReturnType; - mergeArrays: >, U extends DeepMergeIntoFunctionUtils>(m_target: Reference, values: Ts, utils: U, meta: M | undefined) => DeepMergeIntoFunctionsReturnType; - mergeMaps: >>, U extends DeepMergeIntoFunctionUtils>(m_target: Reference>, values: Ts, utils: U, meta: M | undefined) => DeepMergeIntoFunctionsReturnType; - mergeSets: >>, U extends DeepMergeIntoFunctionUtils>(m_target: Reference>, values: Ts, utils: U, meta: M | undefined) => DeepMergeIntoFunctionsReturnType; - mergeOthers: , U extends DeepMergeIntoFunctionUtils>(m_target: Reference, values: Ts, utils: U, meta: M | undefined) => DeepMergeIntoFunctionsReturnType; -}>; -/** - * The utils provided to the merge functions. - */ -type DeepMergeUtils = Readonly<{ - mergeFunctions: DeepMergeFunctions; - defaultMergeFunctions: MergeFunctions$0; - metaDataUpdater: MetaDataUpdater; - deepmerge: >(...values: Ts) => unknown; - useImplicitDefaultMerging: boolean; - filterValues: DeepMergeUtilityFunctions["filterValues"] | undefined; - actions: Readonly<{ - defaultMerge: symbol; - skip: symbol; - }>; -}>; -/** - * The utils provided to the merge functions. - */ -type DeepMergeIntoFunctionUtils = Readonly<{ - mergeFunctions: DeepMergeIntoFunctions; - defaultMergeFunctions: MergeIntoFunctions; - metaDataUpdater: MetaDataUpdater; - deepmergeInto: >(target: Target, ...values: Ts) => void; - filterValues: DeepMergeUtilityFunctions["filterValues"] | undefined; - actions: Readonly<{ - defaultMerge: symbol; - }>; -}>; -/** - * Deeply merge objects. - * - * @param objects - The objects to merge. - */ -declare function deepmerge>>(...objects: readonly [ - ...Ts -]): DeepMergeHKT; -/** - * Deeply merge two or more objects using the given options. - * - * @param options - The options on how to customize the merge function. - */ -declare function deepmergeCustom = {}>(options: DeepMergeOptions): >(...objects: Ts) => DeepMergeHKT, DeepMergeBuiltInMetaData>; -/** - * Deeply merge two or more objects using the given options and meta data. - * - * @param options - The options on how to customize the merge function. - * @param rootMetaData - The meta data passed to the root items' being merged. - */ -declare function deepmergeCustom = {}, MetaData = DeepMergeBuiltInMetaData, MetaMetaData extends DeepMergeBuiltInMetaData = DeepMergeBuiltInMetaData>(options: DeepMergeOptions, rootMetaData?: MetaData): >(...objects: Ts) => DeepMergeHKT, MetaData>; -/** - * Deeply merge objects into a target. - * - * @param target - This object will be mutated with the merge result. - * @param objects - The objects to merge into the target. - */ -declare function deepmergeInto(target: T, ...objects: ReadonlyArray): void; -/** - * Deeply merge objects into a target. - * - * @param target - This object will be mutated with the merge result. - * @param objects - The objects to merge into the target. - */ -declare function deepmergeInto>(target: Target, ...objects: Ts): asserts target is SimplifyObject>; -/** - * Deeply merge two or more objects using the given options. - * - * @param options - The options on how to customize the merge function. - */ -declare function deepmergeIntoCustom(options: DeepMergeIntoOptions): >(target: Target, ...objects: Ts) => void; -/** - * Deeply merge two or more objects using the given options and meta data. - * - * @param options - The options on how to customize the merge function. - * @param rootMetaData - The meta data passed to the root items' being merged. - */ -declare function deepmergeIntoCustom(options: DeepMergeIntoOptions, rootMetaData?: MetaData): >(target: Target, ...objects: Ts) => void; -/** - * The different types of objects deepmerge-ts support. - */ -declare const enum ObjectType { - NOT = 0, - RECORD = 1, - ARRAY = 2, - SET = 3, - MAP = 4, - OTHER = 5 -} -/** - * Get the type of the given object. - * - * @param object - The object to get the type of. - * @returns The type of the given object. - */ -declare function getObjectType(object: unknown): ObjectType; -/** - * Get the keys of the given objects including symbol keys. - * - * Note: Only keys to enumerable properties are returned. - * - * @param objects - An array of objects to get the keys of. - * @returns A set containing all the keys of all the given objects. - */ -declare function getKeys(objects: ReadonlyArray): Set; -/** - * Does the given object have the given property. - * - * @param object - The object to test. - * @param property - The property to test. - * @returns Whether the object has the property. - */ -declare function objectHasProperty(object: object, property: PropertyKey): boolean; -export { deepmerge, deepmergeCustom, deepmergeInto, deepmergeIntoCustom, ObjectType, getKeys, getObjectType, objectHasProperty }; -export type { MergeFunctions as DeepMergeIntoFunctionsDefaults, MergeFunctions$0 as DeepMergeFunctionsDefaults, DeepMergeArraysDefaultHKT, DeepMergeBuiltInMetaData, DeepMergeHKT, DeepMergeLeaf, DeepMergeLeafURI, DeepMergeNoFilteringURI, DeepMergeMapsDefaultHKT, DeepMergeFunctionsDefaultURIs, DeepMergeFunctionsURIs, DeepMergeFunctionURItoKind, DeepMergeUtils, DeepMergeIntoFunctionUtils, DeepMergeOptions, DeepMergeIntoOptions, DeepMergeRecordsDefaultHKT, DeepMergeSetsDefaultHKT, Reference as DeepMergeValueReference, GetDeepMergeFunctionsURIs, FilterOut }; diff --git a/dist/node/index.d.mts b/dist/node/index.d.mts deleted file mode 100644 index 6f4d114a..00000000 --- a/dist/node/index.d.mts +++ /dev/null @@ -1,849 +0,0 @@ -/** - * Simplify a complex type such as a union or intersection of objects into a - * single object. - */ -type SimplifyObject = { - [K in keyof T]: T[K]; -} & {}; -/** - * Flatten a collection of tuples of tuples into a collection of tuples. - */ -type FlattenTuples = { - [I in keyof T]: FlattenTuple; -}; -/** - * Flatten a tuple of tuples into a single tuple. - */ -type FlattenTuple = T extends readonly [ -] ? [ -] : T extends readonly [ - infer T0 -] ? [ - ...FlattenTuple -] : T extends readonly [ - infer T0, - ...infer Ts -] ? [ - ...FlattenTuple, - ...FlattenTuple -] : [ - T -]; -/** - * Safely test whether or not the first given types extends the second. - * - * Needed in particular for testing if a type is "never". - */ -type Is = [ - T1 -] extends [ - T2 -] ? true : false; -/** - * Safely test whether or not the given type is "never". - */ -type IsNever = Is; -/** - * And operator for types. - */ -type And = T1 extends false ? false : T2; -/** - * Not operator for types. - */ -type Not = T extends true ? false : true; -/** - * Check if a key is optional in the given object. - */ -type KeyIsOptional = O extends { - [Key in K]: unknown; -} ? false : true; -/** - * Returns whether or not the given type a record. - */ -type IsRecord = And>, T extends Readonly> ? true : false>; -/** - * Returns whether or not all the given types are records. - */ -type EveryIsRecord> = Ts extends readonly [ - infer Head, - ...infer Rest -] ? IsRecord extends true ? Rest extends ReadonlyArray ? EveryIsRecord : true : false : true; -/** - * Returns whether or not the given type is an array. - */ -type IsArray = And>, T extends ReadonlyArray ? true : false>; -/** - * Returns whether or not all the given types are arrays. - */ -type EveryIsArray> = Ts extends readonly [ - infer T1 -] ? IsArray : Ts extends readonly [ - infer Head, - ...infer Rest -] ? IsArray extends true ? Rest extends readonly [ - unknown, - ...ReadonlyArray -] ? EveryIsArray : false : false : false; -/** - * Returns whether or not the given type is an set. - * - * Note: This may also return true for Maps. - */ -type IsSet = And>, T extends Readonly> ? true : false>; -/** - * Returns whether or not all the given types are sets. - * - * Note: This may also return true if all are maps. - */ -type EveryIsSet> = Ts extends Readonly ? IsSet : Ts extends readonly [ - infer Head, - ...infer Rest -] ? IsSet extends true ? Rest extends readonly [ - unknown, - ...ReadonlyArray -] ? EveryIsSet : false : false : false; -/** - * Returns whether or not the given type is an map. - */ -type IsMap = And>, T extends Readonly> ? true : false>; -/** - * Returns whether or not all the given types are maps. - */ -type EveryIsMap> = Ts extends Readonly ? IsMap : Ts extends readonly [ - infer Head, - ...infer Rest -] ? IsMap extends true ? Rest extends readonly [ - unknown, - ...ReadonlyArray -] ? EveryIsMap : false : false : false; -/** - * Union of the sets' values' types - */ -type UnionSetValues> = UnionSetValuesHelper; -/** - * Tail-recursive helper type for UnionSetValues. - */ -type UnionSetValuesHelper, Acc> = Ts extends readonly [ - infer Head, - ...infer Rest -] ? Head extends Readonly> ? Rest extends ReadonlyArray ? UnionSetValuesHelper : Acc | V1 : never : Acc; -/** - * Union of the maps' values' types - */ -type UnionMapKeys> = UnionMapKeysHelper; -/** - * Tail-recursive helper type for UnionMapKeys. - */ -type UnionMapKeysHelper, Acc> = Ts extends readonly [ - infer Head, - ...infer Rest -] ? Head extends Readonly> ? Rest extends readonly [ -] ? Acc | K1 : UnionMapKeysHelper : never : Acc; -/** - * Union of the maps' keys' types - */ -type UnionMapValues> = UnionMapValuesHelper; -/** - * Tail-recursive helper type for UnionMapValues. - */ -type UnionMapValuesHelper, Acc> = Ts extends readonly [ - infer Head, - ...infer Rest -] ? Head extends Readonly> ? Rest extends readonly [ -] ? Acc | V1 : UnionMapValuesHelper : never : Acc; -/** - * Filter out U from a tuple. - */ -type FilterOut, U> = FilterOutHelper; -/** - * Tail-recursive helper type for FilterOut. - */ -type FilterOutHelper, U, Acc extends ReadonlyArray> = T extends readonly [ -] ? Acc : T extends readonly [ - infer Head, - ...infer Rest -] ? Is extends true ? FilterOutHelper : FilterOutHelper : T; -/** - * Filter out nevers from a tuple. - */ -type FilterOutNever = T extends ReadonlyArray ? FilterOut : never; -/** - * Is the type a tuple? - */ -type IsTuple> = T extends readonly [ -] ? true : T extends readonly [ - unknown, - ...ReadonlyArray -] ? true : false; -/** - * Perfrom a transpose operation on a 2D tuple. - */ -type TransposeTuple = T extends readonly [ - ...(readonly [ - ...unknown[] - ]) -] ? T extends readonly [ -] ? [ -] : T extends readonly [ - infer X extends ReadonlyArray -] ? TransposeTupleSimpleCase : T extends readonly [ - infer X extends ReadonlyArray, - ...infer XS extends ReadonlyArray> -] ? PrependCol> : T : never; -type PrependCol, S extends ReadonlyArray>> = T extends readonly [ -] ? S extends readonly [ -] ? [ -] : never : T extends readonly [ - infer X, - ...infer XS -] ? S extends readonly [ - readonly [ - ...infer Y - ], - ...infer YS extends ReadonlyArray> -] ? [ - [ - X, - ...Y - ], - ...PrependCol -] : never : never; -type TransposeTupleSimpleCase = T extends readonly [ -] ? [ -] : T extends readonly [ - infer X, - ...infer XS -] ? [ - [ - X - ], - ...TransposeTupleSimpleCase -] : never; -/** - * Convert a tuple to an intersection of each of its types. - */ -type TupleToIntersection> = { - [K in keyof T]: (x: T[K]) => void; -} extends Record void> ? I : never; -/** - * Convert a union to a tuple. - * - * Warning: The order of the elements is non-deterministic. - * Warning 2: The union maybe me modified by the TypeScript engine before convertion. - * Warning 3: This implementation relies on a hack/limitation in TypeScript. - */ -type TuplifyUnion> = IsNever extends true ? [ -] : [ - ...TuplifyUnion>, - L -]; -type UnionToIntersection = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never; -type LastOf = UnionToIntersection T : never> extends () => infer R ? R : never; -/** - * Mapping of merge function URIs to the merge function type. - */ -// eslint-disable-next-line ts/consistent-type-definitions -interface DeepMergeFunctionURItoKind, Fs extends DeepMergeFunctionsURIs, in out M> { - readonly DeepMergeLeafURI: DeepMergeLeaf; - readonly DeepMergeRecordsDefaultURI: DeepMergeRecordsDefaultHKT; - readonly DeepMergeArraysDefaultURI: DeepMergeArraysDefaultHKT; - readonly DeepMergeSetsDefaultURI: DeepMergeSetsDefaultHKT; - readonly DeepMergeMapsDefaultURI: DeepMergeMapsDefaultHKT; - readonly DeepMergeFilterValuesDefaultURI: DeepMergeFilterValuesDefaultHKT; - readonly DeepMergeNoFilteringURI: Ts; -} -/** - * Get the type of the given merge function via its URI. - */ -type DeepMergeFunctionKind, Fs extends DeepMergeFunctionsURIs, M> = DeepMergeFunctionURItoKind[URI]; -/** - * A union of all valid merge function URIs. - */ -type DeepMergeFunctionURIs = keyof DeepMergeFunctionURItoKind, DeepMergeFunctionsURIs, unknown>; -/** - * The merge functions to use when deep merging. - */ -type DeepMergeFunctionsURIs = Readonly<{ - /** - * The merge function to merge records with. - */ - DeepMergeRecordsURI: DeepMergeFunctionURIs; - /** - * The merge function to merge arrays with. - */ - DeepMergeArraysURI: DeepMergeFunctionURIs; - /** - * The merge function to merge sets with. - */ - DeepMergeSetsURI: DeepMergeFunctionURIs; - /** - * The merge function to merge maps with. - */ - DeepMergeMapsURI: DeepMergeFunctionURIs; - /** - * The merge function to merge other things with. - */ - DeepMergeOthersURI: DeepMergeFunctionURIs; - /** - * The function to filter values. - */ - DeepMergeFilterValuesURI: DeepMergeFunctionURIs; -}>; -/** - * Deep merge types. - */ -type DeepMergeHKT, Fs extends DeepMergeFunctionsURIs, M> = IsTuple extends true ? Ts extends readonly [ -] ? undefined : DeepMergeHKTHelper, Fs, M> : unknown; -type DeepMergeHKTHelper = Ts extends ReadonlyArray ? IsTuple extends true ? Ts extends readonly [ -] ? unknown : Ts extends readonly [ - infer T1 -] ? T1 : EveryIsArray extends true ? DeepMergeArraysHKT : EveryIsMap extends true ? DeepMergeMapsHKT : EveryIsSet extends true ? DeepMergeSetsHKT : EveryIsRecord extends true ? DeepMergeRecordsHKT : DeepMergeOthersHKT : unknown : never; -/** - * Deep merge records. - */ -type DeepMergeRecordsHKT, Fs extends DeepMergeFunctionsURIs, M> = DeepMergeFunctionKind; -/** - * Deep merge arrays. - */ -type DeepMergeArraysHKT, Fs extends DeepMergeFunctionsURIs, M> = DeepMergeFunctionKind; -/** - * Deep merge sets. - */ -type DeepMergeSetsHKT, Fs extends DeepMergeFunctionsURIs, M> = DeepMergeFunctionKind; -/** - * Deep merge maps. - */ -type DeepMergeMapsHKT, Fs extends DeepMergeFunctionsURIs, M> = DeepMergeFunctionKind; -/** - * Deep merge other things. - */ -type DeepMergeOthersHKT, Fs extends DeepMergeFunctionsURIs, M> = DeepMergeFunctionKind; -/** - * Filter values. - */ -type FilterValuesHKT, Fs extends DeepMergeFunctionsURIs, M> = DeepMergeFunctionKind; -/** - * The merge function that returns a leaf. - */ -type DeepMergeLeafURI = "DeepMergeLeafURI"; -/** - * Don't filter values. - */ -type DeepMergeNoFilteringURI = "DeepMergeNoFilteringURI"; -/** - * Get the leaf type from many types that can't be merged. - */ -type DeepMergeLeaf> = Ts extends readonly [ -] ? never : Ts extends readonly [ - infer T -] ? T : Ts extends readonly [ - ...infer Rest, - infer Tail -] ? IsNever extends true ? Rest extends ReadonlyArray ? DeepMergeLeaf : never : Tail : never; -/** - * The meta data deepmerge is able to provide. - */ -type DeepMergeBuiltInMetaData = Readonly<{ - key: PropertyKey; - parents: ReadonlyArray>>; -}>; -/** - * The default merge function to merge records with. - */ -type DeepMergeRecordsDefaultURI = "DeepMergeRecordsDefaultURI"; -/** - * The default merge function to merge arrays with. - */ -type DeepMergeArraysDefaultURI = "DeepMergeArraysDefaultURI"; -/** - * The default merge function to merge sets with. - */ -type DeepMergeSetsDefaultURI = "DeepMergeSetsDefaultURI"; -/** - * The default merge function to merge maps with. - */ -type DeepMergeMapsDefaultURI = "DeepMergeMapsDefaultURI"; -/** - * The default filter values function. - */ -type DeepMergeFilterValuesDefaultURI = "DeepMergeFilterValuesDefaultURI"; -/** - * The default merge functions to use when deep merging. - */ -type DeepMergeFunctionsDefaultURIs = Readonly<{ - DeepMergeRecordsURI: DeepMergeRecordsDefaultURI; - DeepMergeArraysURI: DeepMergeArraysDefaultURI; - DeepMergeSetsURI: DeepMergeSetsDefaultURI; - DeepMergeMapsURI: DeepMergeMapsDefaultURI; - DeepMergeOthersURI: DeepMergeLeafURI; - DeepMergeFilterValuesURI: DeepMergeFilterValuesDefaultURI; -}>; -type RecordEntries> = FilterOut, undefined>; -type RecordMeta = Record; -type RecordPropertyMeta = { - key: Key; - value: Value; - optional: Optional; -}; -type RecordsToRecordMeta>> = FilterOutNever<{ - [I in keyof Ts]: RecordToRecordMeta; -}>; -type RecordToRecordMeta> = { - [K in keyof T]-?: { - key: K; - value: Required[K]; - optional: KeyIsOptional; - }; -}; -/** - * Deep merge records. - */ -type DeepMergeRecordsDefaultHKT, Fs extends DeepMergeFunctionsURIs, M> = Ts extends ReadonlyArray> ? SimplifyObject, Fs, M>> : never; -/** - * Deep merge record props. - */ -type DeepMergeRecordMetaDefaultHKTProps = RecordMetas extends ReadonlyArray ? CreateRecordFromMeta, Fs, M> : never; -type MergeRecordMeta> = GroupValuesByKey>; -}, readonly [ -]>>>>; -type GroupValuesByKey = Ts extends readonly [ - infer Keys extends ReadonlyArray, - infer Values -] ? { - [I in keyof Keys]: DeepMergeRecordPropertyMetaDefaultHKTGetPossible>; -} : never; -type CreateRecordFromMeta = Ts extends ReadonlyArray ? TupleToIntersection<{ - [I in keyof Ts]: Ts[I] extends { - key: infer Key extends PropertyKey; - values: infer Values extends ReadonlyArray; - optional: infer O extends boolean; - } ? CreateRecordForKeyFromMeta : never; -}> : never; -type CreateRecordForKeyFromMeta, Optional extends boolean, Fs extends DeepMergeFunctionsURIs, M> = Optional extends true ? { - [k in Key]+?: DeepMergeHKT; -} : { - [k in Key]-?: DeepMergeHKT; -}; -/** - * Get the possible types of a property. - */ -type DeepMergeRecordPropertyMetaDefaultHKTGetPossible = Ts extends readonly [ - RecordPropertyMeta, - ...ReadonlyArray -] ? DeepMergeRecordPropertyMetaDefaultHKTGetPossibleHelper : never; -/** - * Tail-recursive helper type for DeepMergeRecordPropertyMetaDefaultHKTGetPossible. - */ -type DeepMergeRecordPropertyMetaDefaultHKTGetPossibleHelper -], Acc extends { - key: PropertyKey; - values: ReadonlyArray; - optional: boolean; -}> = Ts extends [ - ...infer Rest, - { - key: infer K extends PropertyKey; - value: infer V; - optional: infer O extends boolean; - } -] ? Acc["optional"] extends true ? Acc extends { - values: [ - infer Head, - ...infer AccRest - ]; -} ? Rest extends readonly [ - RecordPropertyMeta, - ...ReadonlyArray -] ? DeepMergeRecordPropertyMetaDefaultHKTGetPossibleHelper : { - key: K; - values: [ - V | Head, - ...AccRest - ]; - optional: O; -} : Rest extends readonly [ - RecordPropertyMeta, - ...ReadonlyArray -] ? DeepMergeRecordPropertyMetaDefaultHKTGetPossibleHelper : { - key: K; - values: [ - V, - ...Acc["values"] - ]; - optional: O; -} : Rest extends readonly [ - RecordPropertyMeta, - ...ReadonlyArray -] ? DeepMergeRecordPropertyMetaDefaultHKTGetPossibleHelper : { - key: K; - values: [ - V, - ...Acc["values"] - ]; - optional: O; -} : never; -/** - * Deep merge arrays. - */ -type DeepMergeArraysDefaultHKT, Fs extends DeepMergeFunctionsURIs, M> = DeepMergeArraysDefaultHKTHelper; -/** - * Tail-recursive helper type for DeepMergeArraysDefaultHKT. - */ -type DeepMergeArraysDefaultHKTHelper, Fs extends DeepMergeFunctionsURIs, M, Acc extends ReadonlyArray> = Ts extends readonly [ - infer Head extends ReadonlyArray, - ...infer Rest -] ? Rest extends readonly [ - ReadonlyArray, - ...ReadonlyArray> -] ? DeepMergeArraysDefaultHKTHelper : [ - ...Acc, - ...Head -] : never; -/** - * Deep merge sets. - */ -type DeepMergeSetsDefaultHKT> = Set>; -/** - * Deep merge maps. - */ -type DeepMergeMapsDefaultHKT> = Map, UnionMapValues>; -/** - * Filter out undefined values. - */ -type DeepMergeFilterValuesDefaultHKT> = FilterOut; -/** - * Get the merge functions with defaults apply from the given subset. - */ -type GetDeepMergeFunctionsURIs> = Readonly<{ - // prettier-ignore - DeepMergeRecordsURI: PMF["DeepMergeRecordsURI"] extends keyof DeepMergeFunctionURItoKind ? PMF["DeepMergeRecordsURI"] : DeepMergeRecordsDefaultURI; - // prettier-ignore - DeepMergeArraysURI: PMF["DeepMergeArraysURI"] extends keyof DeepMergeFunctionURItoKind ? PMF["DeepMergeArraysURI"] : DeepMergeArraysDefaultURI; - // prettier-ignore - DeepMergeSetsURI: PMF["DeepMergeSetsURI"] extends keyof DeepMergeFunctionURItoKind ? PMF["DeepMergeSetsURI"] : DeepMergeSetsDefaultURI; - // prettier-ignore - DeepMergeMapsURI: PMF["DeepMergeMapsURI"] extends keyof DeepMergeFunctionURItoKind ? PMF["DeepMergeMapsURI"] : DeepMergeMapsDefaultURI; - // prettier-ignore - DeepMergeOthersURI: PMF["DeepMergeOthersURI"] extends keyof DeepMergeFunctionURItoKind ? PMF["DeepMergeOthersURI"] : DeepMergeLeafURI; - // prettier-ignore - DeepMergeFilterValuesURI: PMF["DeepMergeFilterValuesURI"] extends keyof DeepMergeFunctionURItoKind ? PMF["DeepMergeFilterValuesURI"] : DeepMergeFilterValuesDefaultURI; -}>; -/** - * The default merge functions. - */ -type MergeFunctions = { - mergeRecords: typeof mergeRecordsInto; - mergeArrays: typeof mergeArraysInto; - mergeSets: typeof mergeSetsInto; - mergeMaps: typeof mergeMapsInto; - mergeOthers: typeof mergeOthersInto; -}; -/** - * The default strategy to merge records into a target record. - * - * @param m_target - The result will be mutated into this record - * @param values - The records (including the target's value if there is one). - */ -declare function mergeRecordsInto>, U extends DeepMergeIntoFunctionUtils, M, MM extends DeepMergeBuiltInMetaData = DeepMergeBuiltInMetaData>(m_target: Reference>, values: Ts, utils: U, meta: M | undefined): void; -/** - * The default strategy to merge arrays into a target array. - * - * @param m_target - The result will be mutated into this array - * @param values - The arrays (including the target's value if there is one). - */ -declare function mergeArraysInto>>(m_target: Reference, values: Ts): void; -/** - * The default strategy to merge sets into a target set. - * - * @param m_target - The result will be mutated into this set - * @param values - The sets (including the target's value if there is one). - */ -declare function mergeSetsInto>>>(m_target: Reference>, values: Ts): void; -/** - * The default strategy to merge maps into a target map. - * - * @param m_target - The result will be mutated into this map - * @param values - The maps (including the target's value if there is one). - */ -declare function mergeMapsInto>>>(m_target: Reference>, values: Ts): void; -/** - * Set the target to the last non-undefined value. - */ -declare function mergeOthersInto>(m_target: Reference, values: Ts): void; -type MergeIntoFunctions = MergeFunctions; -/** - * The default merge functions. - */ -type MergeFunctions$0 = { - mergeRecords: typeof mergeRecords; - mergeArrays: typeof mergeArrays; - mergeSets: typeof mergeSets; - mergeMaps: typeof mergeMaps; - mergeOthers: typeof mergeOthers; -}; -/** - * The default strategy to merge records. - * - * @param values - The records. - */ -declare function mergeRecords>, U extends DeepMergeUtils, Fs extends DeepMergeFunctionsURIs, M, MM extends DeepMergeBuiltInMetaData = DeepMergeBuiltInMetaData>(values: Ts, utils: U, meta: M | undefined): DeepMergeRecordsDefaultHKT; -/** - * The default strategy to merge arrays. - * - * @param values - The arrays. - */ -declare function mergeArrays>, Fs extends DeepMergeFunctionsURIs, M>(values: Ts): DeepMergeArraysDefaultHKT; -/** - * The default strategy to merge sets. - * - * @param values - The sets. - */ -declare function mergeSets>>>(values: Ts): DeepMergeSetsDefaultHKT; -/** - * The default strategy to merge maps. - * - * @param values - The maps. - */ -declare function mergeMaps>>>(values: Ts): DeepMergeMapsDefaultHKT; -/** - * Get the last non-undefined value in the given array. - */ -declare function mergeOthers>(values: Ts): unknown; -/** - * The options the user can pass to customize deepmerge. - */ -type DeepMergeOptions> = {}> = Partial>; -/** - * The options the user can pass to customize deepmergeInto. - */ -type DeepMergeIntoOptions> = {}> = Partial>; -type MetaDataUpdater = (previousMeta: M | undefined, metaMeta: Readonly>) => M; -/** - * All the options the user can pass to customize deepmerge. - */ -type DeepMergeOptionsFull = Readonly<{ - mergeRecords: DeepMergeFunctions["mergeRecords"] | false; - mergeArrays: DeepMergeFunctions["mergeArrays"] | false; - mergeMaps: DeepMergeFunctions["mergeMaps"] | false; - mergeSets: DeepMergeFunctions["mergeSets"] | false; - mergeOthers: DeepMergeFunctions["mergeOthers"]; - metaDataUpdater: MetaDataUpdater; - enableImplicitDefaultMerging: boolean; - filterValues: DeepMergeUtilityFunctions["filterValues"] | false; -}>; -/** - * All the options the user can pass to customize deepmergeInto. - */ -type DeepMergeIntoOptionsFull = Readonly<{ - mergeRecords: DeepMergeIntoFunctions["mergeRecords"] | false; - mergeArrays: DeepMergeIntoFunctions["mergeArrays"] | false; - mergeMaps: DeepMergeIntoFunctions["mergeMaps"] | false; - mergeSets: DeepMergeIntoFunctions["mergeSets"] | false; - mergeOthers: DeepMergeIntoFunctions["mergeOthers"]; - metaDataUpdater: MetaDataUpdater; - filterValues: DeepMergeUtilityFunctions["filterValues"] | false; -}>; -/** - * An object that has a reference to a value. - */ -type Reference = { - value: T; -}; -/** - * All the utility functions that can be overridden. - */ -type DeepMergeUtilityFunctions = Readonly<{ - filterValues: >(values: Ts, meta: M | undefined) => unknown[]; -}>; -/** - * All the merge functions that deepmerge uses. - */ -type DeepMergeFunctions = Readonly<{ - mergeRecords: >>, U extends DeepMergeUtils>(values: Ts, utils: U, meta: M | undefined) => unknown; - mergeArrays: >, U extends DeepMergeUtils>(values: Ts, utils: U, meta: M | undefined) => unknown; - mergeMaps: >>, U extends DeepMergeUtils>(values: Ts, utils: U, meta: M | undefined) => unknown; - mergeSets: >>, U extends DeepMergeUtils>(values: Ts, utils: U, meta: M | undefined) => unknown; - mergeOthers: , U extends DeepMergeUtils>(values: Ts, utils: U, meta: M | undefined) => unknown; -}>; -// eslint-disable-next-line ts/no-invalid-void-type -type DeepMergeIntoFunctionsReturnType = void | symbol; -/** - * All the merge functions that deepmerge uses. - */ -type DeepMergeIntoFunctions = Readonly<{ - mergeRecords: >>, U extends DeepMergeIntoFunctionUtils>(m_target: Reference>, values: Ts, utils: U, meta: M | undefined) => DeepMergeIntoFunctionsReturnType; - mergeArrays: >, U extends DeepMergeIntoFunctionUtils>(m_target: Reference, values: Ts, utils: U, meta: M | undefined) => DeepMergeIntoFunctionsReturnType; - mergeMaps: >>, U extends DeepMergeIntoFunctionUtils>(m_target: Reference>, values: Ts, utils: U, meta: M | undefined) => DeepMergeIntoFunctionsReturnType; - mergeSets: >>, U extends DeepMergeIntoFunctionUtils>(m_target: Reference>, values: Ts, utils: U, meta: M | undefined) => DeepMergeIntoFunctionsReturnType; - mergeOthers: , U extends DeepMergeIntoFunctionUtils>(m_target: Reference, values: Ts, utils: U, meta: M | undefined) => DeepMergeIntoFunctionsReturnType; -}>; -/** - * The utils provided to the merge functions. - */ -type DeepMergeUtils = Readonly<{ - mergeFunctions: DeepMergeFunctions; - defaultMergeFunctions: MergeFunctions$0; - metaDataUpdater: MetaDataUpdater; - deepmerge: >(...values: Ts) => unknown; - useImplicitDefaultMerging: boolean; - filterValues: DeepMergeUtilityFunctions["filterValues"] | undefined; - actions: Readonly<{ - defaultMerge: symbol; - skip: symbol; - }>; -}>; -/** - * The utils provided to the merge functions. - */ -type DeepMergeIntoFunctionUtils = Readonly<{ - mergeFunctions: DeepMergeIntoFunctions; - defaultMergeFunctions: MergeIntoFunctions; - metaDataUpdater: MetaDataUpdater; - deepmergeInto: >(target: Target, ...values: Ts) => void; - filterValues: DeepMergeUtilityFunctions["filterValues"] | undefined; - actions: Readonly<{ - defaultMerge: symbol; - }>; -}>; -/** - * Deeply merge objects. - * - * @param objects - The objects to merge. - */ -declare function deepmerge>>(...objects: readonly [ - ...Ts -]): DeepMergeHKT; -/** - * Deeply merge two or more objects using the given options. - * - * @param options - The options on how to customize the merge function. - */ -declare function deepmergeCustom = {}>(options: DeepMergeOptions): >(...objects: Ts) => DeepMergeHKT, DeepMergeBuiltInMetaData>; -/** - * Deeply merge two or more objects using the given options and meta data. - * - * @param options - The options on how to customize the merge function. - * @param rootMetaData - The meta data passed to the root items' being merged. - */ -declare function deepmergeCustom = {}, MetaData = DeepMergeBuiltInMetaData, MetaMetaData extends DeepMergeBuiltInMetaData = DeepMergeBuiltInMetaData>(options: DeepMergeOptions, rootMetaData?: MetaData): >(...objects: Ts) => DeepMergeHKT, MetaData>; -/** - * Deeply merge objects into a target. - * - * @param target - This object will be mutated with the merge result. - * @param objects - The objects to merge into the target. - */ -declare function deepmergeInto(target: T, ...objects: ReadonlyArray): void; -/** - * Deeply merge objects into a target. - * - * @param target - This object will be mutated with the merge result. - * @param objects - The objects to merge into the target. - */ -declare function deepmergeInto>(target: Target, ...objects: Ts): asserts target is SimplifyObject>; -/** - * Deeply merge two or more objects using the given options. - * - * @param options - The options on how to customize the merge function. - */ -declare function deepmergeIntoCustom(options: DeepMergeIntoOptions): >(target: Target, ...objects: Ts) => void; -/** - * Deeply merge two or more objects using the given options and meta data. - * - * @param options - The options on how to customize the merge function. - * @param rootMetaData - The meta data passed to the root items' being merged. - */ -declare function deepmergeIntoCustom(options: DeepMergeIntoOptions, rootMetaData?: MetaData): >(target: Target, ...objects: Ts) => void; -/** - * The different types of objects deepmerge-ts support. - */ -declare const enum ObjectType { - NOT = 0, - RECORD = 1, - ARRAY = 2, - SET = 3, - MAP = 4, - OTHER = 5 -} -/** - * Get the type of the given object. - * - * @param object - The object to get the type of. - * @returns The type of the given object. - */ -declare function getObjectType(object: unknown): ObjectType; -/** - * Get the keys of the given objects including symbol keys. - * - * Note: Only keys to enumerable properties are returned. - * - * @param objects - An array of objects to get the keys of. - * @returns A set containing all the keys of all the given objects. - */ -declare function getKeys(objects: ReadonlyArray): Set; -/** - * Does the given object have the given property. - * - * @param object - The object to test. - * @param property - The property to test. - * @returns Whether the object has the property. - */ -declare function objectHasProperty(object: object, property: PropertyKey): boolean; -export { deepmerge, deepmergeCustom, deepmergeInto, deepmergeIntoCustom, ObjectType, getKeys, getObjectType, objectHasProperty }; -export type { MergeFunctions as DeepMergeIntoFunctionsDefaults, MergeFunctions$0 as DeepMergeFunctionsDefaults, DeepMergeArraysDefaultHKT, DeepMergeBuiltInMetaData, DeepMergeHKT, DeepMergeLeaf, DeepMergeLeafURI, DeepMergeNoFilteringURI, DeepMergeMapsDefaultHKT, DeepMergeFunctionsDefaultURIs, DeepMergeFunctionsURIs, DeepMergeFunctionURItoKind, DeepMergeUtils, DeepMergeIntoFunctionUtils, DeepMergeOptions, DeepMergeIntoOptions, DeepMergeRecordsDefaultHKT, DeepMergeSetsDefaultHKT, Reference as DeepMergeValueReference, GetDeepMergeFunctionsURIs, FilterOut }; diff --git a/dist/node/index.mjs b/dist/node/index.mjs deleted file mode 100644 index 643cef67..00000000 --- a/dist/node/index.mjs +++ /dev/null @@ -1,615 +0,0 @@ -/** - * Special values that tell deepmerge to perform a certain action. - */ -const actions = { - defaultMerge: Symbol("deepmerge-ts: default merge"), - skip: Symbol("deepmerge-ts: skip"), -}; -/** - * Special values that tell deepmergeInto to perform a certain action. - */ -const actionsInto = { - defaultMerge: actions.defaultMerge, -}; - -/** - * The default function to update meta data. - * - * It doesn't update the meta data. - */ -function defaultMetaDataUpdater(previousMeta, metaMeta) { - return metaMeta; -} -/** - * The default function to filter values. - * - * It filters out undefined values. - */ -function defaultFilterValues(values, meta) { - return values.filter((value) => value !== undefined); -} - -/** - * The different types of objects deepmerge-ts support. - */ -var ObjectType; -(function (ObjectType) { - ObjectType[ObjectType["NOT"] = 0] = "NOT"; - ObjectType[ObjectType["RECORD"] = 1] = "RECORD"; - ObjectType[ObjectType["ARRAY"] = 2] = "ARRAY"; - ObjectType[ObjectType["SET"] = 3] = "SET"; - ObjectType[ObjectType["MAP"] = 4] = "MAP"; - ObjectType[ObjectType["OTHER"] = 5] = "OTHER"; -})(ObjectType || (ObjectType = {})); -/** - * Get the type of the given object. - * - * @param object - The object to get the type of. - * @returns The type of the given object. - */ -function getObjectType(object) { - if (typeof object !== "object" || object === null) { - return 0 /* ObjectType.NOT */; - } - if (Array.isArray(object)) { - return 2 /* ObjectType.ARRAY */; - } - if (isRecord(object)) { - return 1 /* ObjectType.RECORD */; - } - if (object instanceof Set) { - return 3 /* ObjectType.SET */; - } - if (object instanceof Map) { - return 4 /* ObjectType.MAP */; - } - return 5 /* ObjectType.OTHER */; -} -/** - * Get the keys of the given objects including symbol keys. - * - * Note: Only keys to enumerable properties are returned. - * - * @param objects - An array of objects to get the keys of. - * @returns A set containing all the keys of all the given objects. - */ -function getKeys(objects) { - const keys = new Set(); - for (const object of objects) { - for (const key of [ - ...Object.keys(object), - ...Object.getOwnPropertySymbols(object), - ]) { - keys.add(key); - } - } - return keys; -} -/** - * Does the given object have the given property. - * - * @param object - The object to test. - * @param property - The property to test. - * @returns Whether the object has the property. - */ -function objectHasProperty(object, property) { - return (typeof object === "object" && - Object.prototype.propertyIsEnumerable.call(object, property)); -} -/** - * Get an iterable object that iterates over the given iterables. - */ -function getIterableOfIterables(iterables) { - return { - *[Symbol.iterator]() { - for (const iterable of iterables) { - for (const value of iterable) { - yield value; - } - } - }, - }; -} -const validRecordToStringValues = new Set([ - "[object Object]", - "[object Module]", -]); -/** - * Does the given object appear to be a record. - */ -function isRecord(value) { - // All records are objects. - if (!validRecordToStringValues.has(Object.prototype.toString.call(value))) { - return false; - } - const { constructor } = value; - // If has modified constructor. - // eslint-disable-next-line ts/no-unnecessary-condition - if (constructor === undefined) { - return true; - } - const prototype = constructor.prototype; - // If has modified prototype. - if (prototype === null || - typeof prototype !== "object" || - !validRecordToStringValues.has(Object.prototype.toString.call(prototype))) { - return false; - } - // If constructor does not have an Object-specific method. - // eslint-disable-next-line sonar/prefer-single-boolean-return, no-prototype-builtins - if (!prototype.hasOwnProperty("isPrototypeOf")) { - return false; - } - // Most likely a record. - return true; -} - -/** - * The default strategy to merge records. - * - * @param values - The records. - */ -function mergeRecords$1(values, utils, meta) { - const result = {}; - for (const key of getKeys(values)) { - const propValues = []; - for (const value of values) { - if (objectHasProperty(value, key)) { - propValues.push(value[key]); - } - } - if (propValues.length === 0) { - continue; - } - const updatedMeta = utils.metaDataUpdater(meta, { - key, - parents: values, - }); - const propertyResult = mergeUnknowns(propValues, utils, updatedMeta); - if (propertyResult === actions.skip) { - continue; - } - if (key === "__proto__") { - Object.defineProperty(result, key, { - value: propertyResult, - configurable: true, - enumerable: true, - writable: true, - }); - } - else { - result[key] = propertyResult; - } - } - return result; -} -/** - * The default strategy to merge arrays. - * - * @param values - The arrays. - */ -function mergeArrays$1(values) { - return values.flat(); -} -/** - * The default strategy to merge sets. - * - * @param values - The sets. - */ -function mergeSets$1(values) { - return new Set(getIterableOfIterables(values)); -} -/** - * The default strategy to merge maps. - * - * @param values - The maps. - */ -function mergeMaps$1(values) { - return new Map(getIterableOfIterables(values)); -} -/** - * Get the last non-undefined value in the given array. - */ -function mergeOthers$1(values) { - return values.at(-1); -} -/** - * The merge functions. - */ -const mergeFunctions = { - mergeRecords: mergeRecords$1, - mergeArrays: mergeArrays$1, - mergeSets: mergeSets$1, - mergeMaps: mergeMaps$1, - mergeOthers: mergeOthers$1, -}; - -/** - * Deeply merge objects. - * - * @param objects - The objects to merge. - */ -function deepmerge(...objects) { - return deepmergeCustom({})(...objects); -} -function deepmergeCustom(options, rootMetaData) { - const utils = getUtils(options, customizedDeepmerge); - /** - * The customized deepmerge function. - */ - function customizedDeepmerge(...objects) { - return mergeUnknowns(objects, utils, rootMetaData); - } - return customizedDeepmerge; -} -/** - * The the utils that are available to the merge functions. - * - * @param options - The options the user specified - */ -function getUtils(options, customizedDeepmerge) { - return { - defaultMergeFunctions: mergeFunctions, - mergeFunctions: { - ...mergeFunctions, - ...Object.fromEntries(Object.entries(options) - .filter(([key, option]) => Object.hasOwn(mergeFunctions, key)) - .map(([key, option]) => option === false - ? [key, mergeFunctions.mergeOthers] - : [key, option])), - }, - metaDataUpdater: (options.metaDataUpdater ?? - defaultMetaDataUpdater), - deepmerge: customizedDeepmerge, - useImplicitDefaultMerging: options.enableImplicitDefaultMerging ?? false, - filterValues: options.filterValues === false - ? undefined - : options.filterValues ?? defaultFilterValues, - actions, - }; -} -/** - * Merge unknown things. - * - * @param values - The values. - */ -function mergeUnknowns(values, utils, meta) { - const filteredValues = utils.filterValues?.(values, meta) ?? values; - if (filteredValues.length === 0) { - return undefined; - } - if (filteredValues.length === 1) { - return mergeOthers(filteredValues, utils, meta); - } - const type = getObjectType(filteredValues[0]); - if (type !== 0 /* ObjectType.NOT */ && type !== 5 /* ObjectType.OTHER */) { - for (let m_index = 1; m_index < filteredValues.length; m_index++) { - if (getObjectType(filteredValues[m_index]) === type) { - continue; - } - return mergeOthers(filteredValues, utils, meta); - } - } - switch (type) { - case 1 /* ObjectType.RECORD */: { - return mergeRecords(filteredValues, utils, meta); - } - case 2 /* ObjectType.ARRAY */: { - return mergeArrays(filteredValues, utils, meta); - } - case 3 /* ObjectType.SET */: { - return mergeSets(filteredValues, utils, meta); - } - case 4 /* ObjectType.MAP */: { - return mergeMaps(filteredValues, utils, meta); - } - default: { - return mergeOthers(filteredValues, utils, meta); - } - } -} -/** - * Merge records. - * - * @param values - The records. - */ -function mergeRecords(values, utils, meta) { - 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(values, utils, meta); - } - return result; -} -/** - * Merge arrays. - * - * @param values - The arrays. - */ -function mergeArrays(values, utils, meta) { - 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(values, utils, meta) { - 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(values, utils, meta) { - 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(values, utils, meta) { - 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 into a target record. - * - * @param m_target - The result will be mutated into this record - * @param values - The records (including the target's value if there is one). - */ -function mergeRecordsInto$1(m_target, values, utils, meta) { - for (const key of getKeys(values)) { - const propValues = []; - for (const value of values) { - if (objectHasProperty(value, key)) { - propValues.push(value[key]); - } - } - if (propValues.length === 0) { - continue; - } - const updatedMeta = utils.metaDataUpdater(meta, { - key, - parents: values, - }); - const propertyTarget = { value: propValues[0] }; - mergeUnknownsInto(propertyTarget, propValues, utils, updatedMeta); - if (key === "__proto__") { - Object.defineProperty(m_target.value, key, { - value: propertyTarget.value, - configurable: true, - enumerable: true, - writable: true, - }); - } - else { - m_target.value[key] = propertyTarget.value; - } - } -} -/** - * The default strategy to merge arrays into a target array. - * - * @param m_target - The result will be mutated into this array - * @param values - The arrays (including the target's value if there is one). - */ -function mergeArraysInto$1(m_target, values) { - m_target.value.push(...values.slice(1).flat()); -} -/** - * The default strategy to merge sets into a target set. - * - * @param m_target - The result will be mutated into this set - * @param values - The sets (including the target's value if there is one). - */ -function mergeSetsInto$1(m_target, values) { - for (const value of getIterableOfIterables(values.slice(1))) { - m_target.value.add(value); - } -} -/** - * The default strategy to merge maps into a target map. - * - * @param m_target - The result will be mutated into this map - * @param values - The maps (including the target's value if there is one). - */ -function mergeMapsInto$1(m_target, values) { - for (const [key, value] of getIterableOfIterables(values.slice(1))) { - m_target.value.set(key, value); - } -} -/** - * Set the target to the last non-undefined value. - */ -function mergeOthersInto$1(m_target, values) { - m_target.value = values.at(-1); -} -/** - * The merge functions. - */ -const mergeIntoFunctions = { - mergeRecords: mergeRecordsInto$1, - mergeArrays: mergeArraysInto$1, - mergeSets: mergeSetsInto$1, - mergeMaps: mergeMapsInto$1, - mergeOthers: mergeOthersInto$1, -}; - -function deepmergeInto(target, ...objects) { - return void deepmergeIntoCustom({})(target, ...objects); -} -function deepmergeIntoCustom(options, rootMetaData) { - const utils = getIntoUtils(options, customizedDeepmergeInto); - /** - * The customized deepmerge function. - */ - function customizedDeepmergeInto(target, ...objects) { - mergeUnknownsInto({ value: target }, [target, ...objects], utils, rootMetaData); - } - return customizedDeepmergeInto; -} -/** - * The the utils that are available to the merge functions. - * - * @param options - The options the user specified - */ -function getIntoUtils(options, customizedDeepmergeInto) { - return { - defaultMergeFunctions: mergeIntoFunctions, - mergeFunctions: { - ...mergeIntoFunctions, - ...Object.fromEntries(Object.entries(options) - .filter(([key, option]) => Object.hasOwn(mergeIntoFunctions, key)) - .map(([key, option]) => option === false - ? [key, mergeIntoFunctions.mergeOthers] - : [key, option])), - }, - metaDataUpdater: (options.metaDataUpdater ?? - defaultMetaDataUpdater), - deepmergeInto: customizedDeepmergeInto, - filterValues: options.filterValues === false - ? undefined - : options.filterValues ?? defaultFilterValues, - actions: actionsInto, - }; -} -/** - * Merge unknown things into a target. - * - * @param m_target - The target to merge into. - * @param values - The values. - */ -function mergeUnknownsInto(m_target, values, utils, meta) { - const filteredValues = utils.filterValues?.(values, meta) ?? values; - if (filteredValues.length === 0) { - return; - } - if (filteredValues.length === 1) { - return void mergeOthersInto(m_target, filteredValues, utils, meta); - } - const type = getObjectType(m_target.value); - if (type !== 0 /* ObjectType.NOT */ && type !== 5 /* ObjectType.OTHER */) { - for (let m_index = 1; m_index < filteredValues.length; m_index++) { - if (getObjectType(filteredValues[m_index]) === type) { - continue; - } - return void mergeOthersInto(m_target, filteredValues, utils, meta); - } - } - switch (type) { - case 1 /* ObjectType.RECORD */: { - return void mergeRecordsInto(m_target, filteredValues, utils, meta); - } - case 2 /* ObjectType.ARRAY */: { - return void mergeArraysInto(m_target, filteredValues, utils, meta); - } - case 3 /* ObjectType.SET */: { - return void mergeSetsInto(m_target, filteredValues, utils, meta); - } - case 4 /* ObjectType.MAP */: { - return void mergeMapsInto(m_target, filteredValues, utils, meta); - } - default: { - return void mergeOthersInto(m_target, filteredValues, utils, meta); - } - } -} -/** - * Merge records into a target record. - * - * @param m_target - The target to merge into. - * @param values - The records. - */ -function mergeRecordsInto(m_target, values, utils, meta) { - const action = utils.mergeFunctions.mergeRecords(m_target, values, utils, meta); - if (action === actionsInto.defaultMerge) { - utils.defaultMergeFunctions.mergeRecords(m_target, values, utils, meta); - } -} -/** - * Merge arrays into a target array. - * - * @param m_target - The target to merge into. - * @param values - The arrays. - */ -function mergeArraysInto(m_target, values, utils, meta) { - const action = utils.mergeFunctions.mergeArrays(m_target, values, utils, meta); - if (action === actionsInto.defaultMerge) { - utils.defaultMergeFunctions.mergeArrays(m_target, values); - } -} -/** - * Merge sets into a target set. - * - * @param m_target - The target to merge into. - * @param values - The sets. - */ -function mergeSetsInto(m_target, values, utils, meta) { - const action = utils.mergeFunctions.mergeSets(m_target, values, utils, meta); - if (action === actionsInto.defaultMerge) { - utils.defaultMergeFunctions.mergeSets(m_target, values); - } -} -/** - * Merge maps into a target map. - * - * @param m_target - The target to merge into. - * @param values - The maps. - */ -function mergeMapsInto(m_target, values, utils, meta) { - const action = utils.mergeFunctions.mergeMaps(m_target, values, utils, meta); - if (action === actionsInto.defaultMerge) { - utils.defaultMergeFunctions.mergeMaps(m_target, values); - } -} -/** - * Merge other things into a target. - * - * @param m_target - The target to merge into. - * @param values - The other things. - */ -function mergeOthersInto(m_target, values, utils, meta) { - const action = utils.mergeFunctions.mergeOthers(m_target, values, utils, meta); - if (action === actionsInto.defaultMerge || - m_target.value === actionsInto.defaultMerge) { - utils.defaultMergeFunctions.mergeOthers(m_target, values); - } -} - -export { deepmerge, deepmergeCustom, deepmergeInto, deepmergeIntoCustom, getKeys, getObjectType, objectHasProperty }; diff --git a/jsr.json b/jsr.json new file mode 100644 index 00000000..be2ff6fb --- /dev/null +++ b/jsr.json @@ -0,0 +1,5 @@ +{ + "name": "@rebeccastevens/deepmerge", + "version": "0.0.0-development", + "exports": "./src/index.ts" +} diff --git a/package.json b/package.json index 453243cb..eed24cc7 100644 --- a/package.json +++ b/package.json @@ -35,16 +35,16 @@ "type": "module", "exports": { "types": { - "import": "./dist/node/index.d.mts", - "require": "./dist/node/index.d.cts" + "import": "./dist/index.d.mts", + "require": "./dist/index.d.cts" }, - "import": "./dist/node/index.mjs", - "require": "./dist/node/index.cjs" + "import": "./dist/index.mjs", + "require": "./dist/index.cjs" }, - "main": "./dist/node/index.cjs", - "types": "./dist/node/index.d.cts", + "main": "./dist/index.cjs", + "types": "./dist/index.d.cts", "files": [ - "dist/node/", + "dist/", "package.json", "CHANGELOG.md", "LICENSE", @@ -52,10 +52,7 @@ ], "scripts": { "benchmark": "pnpm run build && cd benchmark && pnpm run benchmark; cd ..", - "build": "pnpm run build:node && pnpm run build:deno && rimraf build && if-env-defined CI || pnpm run build:assume-unchanged", - "build:assume-unchanged": "cd dist; git update-index --assume-unchanged $(git ls-files | tr '\n' ' '); cd ..", - "build:deno": "rimraf dist/deno && tsc -p tsconfig.build.deno.json && denoify", - "build:node": "rimraf dist/node types/current && rollup -c rollup.config.ts --configPlugin rollup-plugin-ts", + "build": "rimraf dist && rollup -c rollup.config.ts --configPlugin rollup-plugin-ts", "cz": "git-cz", "lint": "eslint && pnpm run lint:md && pnpm run lint:spelling && pnpm run lint:knip && pnpm run lint:packages", "lint-fix": "eslint --fix && pnpm run lint:md-fix && pnpm run lint:packages-fix", @@ -78,7 +75,7 @@ "test": "pnpm run test:js-run && pnpm run test:types", "test:js": "vitest --coverage", "test:js-run": "vitest run --coverage", - "test:types": "pnpm run build:node && tsd -f 'tests/**/*.test-d.ts' -t 'dist/node/index.d.mts'", + "test:types": "pnpm run build && tsd -f 'tests/**/*.test-d.ts' -t 'dist/index.d.mts'", "typecheck": "tsc -p tsconfig.build.json --noEmit" }, "devDependencies": { @@ -88,6 +85,7 @@ "@eslint/compat": "1.1.1", "@rebeccastevens/eslint-config": "3.2.2", "@rollup/plugin-replace": "6.0.1", + "@sebbo2002/semantic-release-jsr": "2.0.0", "@semantic-release/changelog": "6.0.3", "@semantic-release/commit-analyzer": "13.0.0", "@semantic-release/git": "10.0.1", @@ -104,7 +102,6 @@ "commitizen": "4.3.1", "cspell": "8.14.4", "cz-conventional-changelog": "3.3.0", - "denoify": "1.6.16", "eslint": "9.11.1", "eslint-config-prettier": "9.1.0", "eslint-flat-config-utils": "0.4.0", @@ -127,7 +124,6 @@ "eslint-plugin-unicorn": "56.0.0", "eslint-plugin-yml": "1.14.0", "husky": "9.1.6", - "if-env-defined": "1.0.0", "jsonc-eslint-parser": "2.4.0", "knip": "5.31.0", "lint-staged": "15.2.10", @@ -150,9 +146,5 @@ "packageManager": "pnpm@9.12.0", "engines": { "node": ">=16.0.0" - }, - "denoify": { - "out": "dist/deno", - "index": "src/index.ts" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 62481838..182331b2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -26,6 +26,9 @@ importers: '@rollup/plugin-replace': specifier: 6.0.1 version: 6.0.1(rollup@4.24.0) + '@sebbo2002/semantic-release-jsr': + specifier: 2.0.0 + version: 2.0.0 '@semantic-release/changelog': specifier: 6.0.3 version: 6.0.3(semantic-release@24.1.2(typescript@5.6.2)) @@ -74,9 +77,6 @@ importers: cz-conventional-changelog: specifier: 3.3.0 version: 3.3.0(@types/node@20.16.10)(typescript@5.6.2) - denoify: - specifier: 1.6.16 - version: 1.6.16 eslint: specifier: 9.11.1 version: 9.11.1(jiti@2.1.2) @@ -143,9 +143,6 @@ importers: husky: specifier: 9.1.6 version: 9.1.6 - if-env-defined: - specifier: 1.0.0 - version: 1.0.0 jsonc-eslint-parser: specifier: 2.4.0 version: 2.4.0 @@ -1689,6 +1686,10 @@ packages: '@rtsao/scc@1.1.0': resolution: {integrity: sha512-zt6OdqaDoOnJ1ZYsCYGt9YmWzDXl4vQdKTyJev62gFhRGKdx7mcT54V9KIjg+d2wi9EXsPvAPKe7i7WjfVWB8g==} + '@sebbo2002/semantic-release-jsr@2.0.0': + resolution: {integrity: sha512-v8hvjvYKgiMx6DY3cVc+BhpFzTmqDok5y81u0YfwbqMP7wP+zsqQJZDYau5QjFFpt7byyXorR2kv+L3TmpH6Sg==} + engines: {node: 18 || 20 || >=22.0.0} + '@sec-ant/readable-stream@0.4.1': resolution: {integrity: sha512-831qok9r2t8AlxLko40y2ebgSDhenenCatLVeW/uBtnHPyhHOvG0C7TvfgecV+wHzIm5KUICgzmVpWS+IMEAeg==} @@ -2180,12 +2181,6 @@ packages: peerDependencies: '@babel/core': ^7.4.0 || ^8.0.0-0 <8.0.0 - babel-polyfill@6.26.0: - resolution: {integrity: sha512-F2rZGQnAdaHWQ8YAoeRbukc7HS9QgdgeyJ0rQDd485v9opwuPvjpPFcOOT/WmkKTdgy9ESgSPXDcTNpzrGr6iQ==} - - babel-runtime@6.26.0: - resolution: {integrity: sha512-ITKNuq2wKlW1fJg9sSW52eepoYgZBggvOAHC0u/CYu/qxQ9EVzThCgR69BnSXLHjy2f7SY5zaQ4yt7H9ZVxY2g==} - balanced-match@1.0.2: resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==} @@ -2460,10 +2455,6 @@ packages: core-js-compat@3.38.1: resolution: {integrity: sha512-JRH6gfXxGmrzF3tZ57lFx97YARxCXPaMzPo6jELZhv88pBH5VXpQ+y0znKGlFnzuaihqhLbefxSJxWJMPtfDzw==} - core-js@2.6.12: - resolution: {integrity: sha512-Kb2wC0fvsWfQrgk8HU5lW6U/Lcs8+9aaYcy4ZFc6DDlo4nZ7n70dEgE5rtR0oG6ufKDUnrwfWL1mXR5ljDatrQ==} - deprecated: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js. - core-util-is@1.0.3: resolution: {integrity: sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==} @@ -2619,10 +2610,6 @@ packages: resolution: {integrity: sha512-8QmQKqEASLd5nx0U1B1okLElbUuuttJ/AnYmRXbbbGDWh6uS208EjD4Xqq/I9wK7u0v6O08XhTWnt5XtEbR6Dg==} engines: {node: '>= 0.4'} - denoify@1.6.16: - resolution: {integrity: sha512-lWtvtn6a4VsN9m8xoHP+mUx5OCXydKdEEIqV7CycVRXcrd6acDvwhS+VHGuXbU1gX9oX8Sw6QqDIEtYriocE7g==} - hasBin: true - detect-file@1.0.0: resolution: {integrity: sha512-DtCOLG98P007x7wiiOmfI0fi3eIKyWiLTGJ2MDnVi/E04lWGbf+JzrRHMm0rgIIZJGtHpKpbVgLWHrv8xXpc3Q==} engines: {node: '>=0.10.0'} @@ -2662,9 +2649,6 @@ packages: duplexer2@0.1.4: resolution: {integrity: sha512-asLFVfWWtJ90ZyOUHMqk7/S2w2guQKxUI2itj3d92ADHhxUSbCMGi1f1cBcJ7xM1To+pE/Khbwo1yuNbMEPKeA==} - duplexer@0.1.2: - resolution: {integrity: sha512-jtD6YG370ZCIi/9GTaJKQxWTZD045+4R4hTk/x1UyoqadyJ9x9CgSi1RlVDQF8U2sxLLSnFkCaMihqljHIWgMg==} - eastasianwidth@0.2.0: resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==} @@ -3065,9 +3049,6 @@ packages: resolution: {integrity: sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==} engines: {node: '>=0.10.0'} - event-stream@3.3.4: - resolution: {integrity: sha512-QHpkERcGsR0T7Qm3HNJSyXKEEj8AHNxkY3PK8TS2KJvQ7NiSHe3DDpwVKKtoYprL/AreyzFBeIkBIWChAqn60g==} - eventemitter3@5.0.1: resolution: {integrity: sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA==} @@ -3193,9 +3174,6 @@ packages: from2@2.3.0: resolution: {integrity: sha512-OMcX/4IC/uqEPVgGeyfN22LJk6AZrMkRZHxcHBMBvHScDGgwTm2GT2Wkgtocyd3JfZffjj2kYUDXXII0Fk9W0g==} - from@0.1.7: - resolution: {integrity: sha512-twe20eF1OxVxp/ML/kq2p1uc6KvFK/+vs8WjEbeKmV2He22MKm7YF2ANIt+EOqhJ5L3K/SuuPhk0hWQDjOM23g==} - fs-extra@11.1.0: resolution: {integrity: sha512-0rcTq621PD5jM/e0a3EJoGC/1TC5ZBCERW82LQuwfGnCa1V8w7dpYH1yNu+SLb6E5dkeCBzKEyLGlFrnr+dUyw==} engines: {node: '>=14.14'} @@ -3471,10 +3449,6 @@ packages: ieee754@1.2.1: resolution: {integrity: sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==} - if-env-defined@1.0.0: - resolution: {integrity: sha512-Ne+YUro4Ri4OvBeehzC4noFOFEWGEtxf65whcIybnUSszx4AOaEIfiZsJ27U1eqH3tgAnz2ZFuxGeplk7Lf/dA==} - hasBin: true - ignore@5.3.1: resolution: {integrity: sha512-5Fytz/IraMjqpwfd34ke28PTVMjZjJG2MPn5t7OE4eUCUNf8BAa7b5WUS9/Qvr6mwOQS7Mk6vdsMno5he+T8Xw==} engines: {node: '>= 4'} @@ -3852,6 +3826,10 @@ packages: resolution: {integrity: sha512-POQXvpdL69+CluYsillJ7SUhKvytYjW9vG/GKpnf+xP8UWgYEM/RaMzHHofbALDiKbbP1W8UEYmgGl39WkPZsg==} engines: {'0': node >= 0.2.0} + jsr@0.13.2: + resolution: {integrity: sha512-c4ir0ql2Xgpg9mSOSPKBANS9oTvlV8fSzpesCsHP04VAOJ3pBm7YygY2LVkHC0jz9G36JBGh1oiEZTWO4UyctA==} + hasBin: true + jsx-ast-utils@3.3.5: resolution: {integrity: sha512-ZZow9HBI5O6EPgSJLUb8n2NKgmVWTwCvHGwFuJlMjvLFqlGG6pjirPhtdsseaLZjSibD8eegzmYpUZwoIlj2cQ==} engines: {node: '>=4.0'} @@ -3871,6 +3849,9 @@ packages: '@types/node': '>=18' typescript: '>=5.0.4' + kolorist@1.8.0: + resolution: {integrity: sha512-Y+60/zizpJ3HRH8DCss+q95yr6145JXZo46OTpFvDZWLfRCE4qChOyk1b26nMaNpfHHgxagk9dXT5OP0Tfe+dQ==} + language-subtag-registry@0.3.23: resolution: {integrity: sha512-0K65Lea881pHotoGEa5gDlMxt3pctLi2RplBb7Ezh4rRdLEOtgi7n4EwK9lamnUCkKBqaeKRVebTq6BAxSkpXQ==} @@ -4028,9 +4009,6 @@ packages: resolution: {integrity: sha512-hdN1wVrZbb29eBGiGjJbeP8JbKjq1urkHJ/LIP/NY48MZ1QVXUsQBV1G1zvYFHn1XE06cwjBsOI2K3Ulnj1YXQ==} engines: {node: '>=8'} - map-stream@0.1.0: - resolution: {integrity: sha512-CkYQrPYZfWnu/DAmVCpTSX/xHpKZ80eKh2lAkyA6AJTef6bW+6JpbQZN5rofum7da+SyN1bi5ctTm+lTfcCW3g==} - markdown-it@14.1.0: resolution: {integrity: sha512-a54IwgWPaeBCAAsv13YgmALOF1elABB08FxO9i+r4VFk5Vl4pKokRPeX8u5TCgSsPi6ec1otfLjdOpVcgbpshg==} hasBin: true @@ -4184,6 +4162,10 @@ packages: node-releases@2.0.18: resolution: {integrity: sha512-d9VeXT4SJ7ZeOqGX6R5EM022wpL+eWPooLI+5UpWn2jCT1aosUQEhQP214x33Wkwx3JQMvIm+tIoVOdodFS40g==} + node-stream-zip@1.15.0: + resolution: {integrity: sha512-LN4fydt9TqhZhThkZIVQnF9cwjU3qmUH9h78Mx/K7d3VvfRqqwthLwJEUOEL0QPZ0XQmNN7be5Ggit5+4dq3Bw==} + engines: {node: '>=0.12.0'} + normalize-package-data@2.5.0: resolution: {integrity: sha512-/5CMN3T0R4XTj4DcGaexo+roZSdSFW/0AOOTROrjxzCG1wrWXEsGbRKevjlIL+ZDE4sZlJr5ED4YW0yqmkK+eA==} @@ -4199,10 +4181,6 @@ packages: resolution: {integrity: sha512-IO9QvjUMWxPQQhs60oOu10CRkWCiZzSUkzbXGGV9pviYl1fXYcvkzQ5jV9z8Y6un8ARoVRl4EtC6v6jNqbaJ/w==} engines: {node: '>=14.16'} - npm-run-all@1.4.0: - resolution: {integrity: sha512-Le4iFE4VsbjPG4IMtuMN7gHu3UXIVnywPqBS2s3vHQe0JMGewfyWE8WYyqM509PjUybi4wbSqgW69mr3XGFr0w==} - hasBin: true - npm-run-path@4.0.1: resolution: {integrity: sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==} engines: {node: '>=8'} @@ -4517,9 +4495,6 @@ packages: resolution: {integrity: sha512-vE7JKRyES09KiunauX7nd2Q9/L7lhok4smP9RZTDeD4MVs72Dp2qNFVz39Nz5a0FVEW0BJR6C0DYrq6unoziZA==} engines: {node: '>= 14.16'} - pause-stream@0.0.11: - resolution: {integrity: sha512-e3FBlXLmN/D1S+zHzanP4E/4Z60oFAa3O051qt1pxa7DEJWKAyil6upYVXCWadEnuoqa4Pkc9oUx9zsxYeRv8A==} - picocolors@1.1.0: resolution: {integrity: sha512-TQ92mBOW0l3LeMeyLV6mzy/kWr8lkd/hp3mTg7wYK7zJhuBStmGMBG0BdeDZS/dZx1IukaX6Bk11zcln25o1Aw==} @@ -4601,11 +4576,6 @@ packages: proto-list@1.2.4: resolution: {integrity: sha512-vtK/94akxsTMhe0/cbfpR+syPuszcuwhqVjJq26CuNDgFGj682oRBXOP5MJpv2r7JtE8MsiepGIqvvOTBwn2vA==} - ps-tree@1.2.0: - resolution: {integrity: sha512-0VnamPPYHl4uaU/nSFeZZpR21QAWRz+sRv4iW9+v/GS/J5U5iZB5BNN6J0RMoOvdx2gWM2+ZFMIm58q24e4UYA==} - engines: {node: '>= 0.10'} - hasBin: true - punycode.js@2.3.1: resolution: {integrity: sha512-uxFIHU0YlHYhDQtV4R9J6a52SLx28BCjT+4ieh7IGbgwVJWO+km431c4yRlREUAsAmt/uMjQUyQHNEPf0M39CA==} engines: {node: '>=6'} @@ -4673,12 +4643,6 @@ packages: regenerate@1.4.2: resolution: {integrity: sha512-zrceR/XhGYU/d/opr2EKO7aRHUeiBI8qjtfHqADTwZd6Szfy16la6kqD0MIUs5z5hx6AaKa+PixpPrR289+I0A==} - regenerator-runtime@0.10.5: - resolution: {integrity: sha512-02YopEIhAgiBHWeoTiA8aitHDt8z6w+rQqNuIftlM+ZtvSl/brTouaU7DW6GO/cHtvxJvS4Hwv2ibKdxIRi24w==} - - regenerator-runtime@0.11.1: - resolution: {integrity: sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg==} - regenerator-runtime@0.14.1: resolution: {integrity: sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==} @@ -4848,6 +4812,10 @@ packages: engines: {node: '>=20.8.1'} hasBin: true + semiver@1.1.0: + resolution: {integrity: sha512-QNI2ChmuioGC1/xjyYwyZYADILWyW6AmS1UH6gDj/SFUUUS4MBAWs/7mxnkRPc/F4iHezDP+O8t0dO8WHiEOdg==} + engines: {node: '>=6'} + semver-diff@4.0.0: resolution: {integrity: sha512-0Ju4+6A8iOnpL/Thra7dZsSlOHYAHIeMxfhWQRI1/VLcT3WDBZKKtQt/QkBOsiIN9ZpuvHE6cGZ0x4glCMmfiA==} engines: {node: '>=12'} @@ -4885,9 +4853,6 @@ packages: resolution: {integrity: sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==} engines: {node: '>=8'} - shell-quote@1.8.0: - resolution: {integrity: sha512-QHsz8GgQIGKlRi24yFc6a6lN69Idnx634w49ay6+jA5yFh7a1UY+4Rp6HPx/L/1zcEDPEij8cIsiqR6bQsE5VQ==} - side-channel@1.0.6: resolution: {integrity: sha512-fDW/EZ6Q9RiO8eFG8Hj+7u/oW+XrPTIChwCOM2+th2A6OblDtYYIpve9m+KvI9Z4C9qSEXlaGR6bTEYHReuglA==} engines: {node: '>= 0.4'} @@ -4980,9 +4945,6 @@ packages: resolution: {integrity: sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==} engines: {node: '>= 10.x'} - split@0.3.3: - resolution: {integrity: sha512-wD2AeVmxXRBoX44wAycgjVpMhvbwdI2aZjCkvfNcH1YqHQvJVa1duWc73OyVGJUc05fhFaTZeQ/PYsrmyH0JVA==} - stable-hash@0.0.4: resolution: {integrity: sha512-LjdcbuBeLcdETCrPn9i8AYAZ1eCtu4ECAWtP7UleOiZ9LzVxRzzUZEoZ8zB24nhkQnDWyET0I+3sWokSDS3E7g==} @@ -4999,9 +4961,6 @@ packages: stream-combiner2@1.1.1: resolution: {integrity: sha512-3PnJbYgS56AeWgtKF5jtJRT6uFJe56Z0Hc5Ngg/6sI6rIt8iiMBTa9cvdyFfpMQjaVHr8dusbNeFGIIonxOvKw==} - stream-combiner@0.0.4: - resolution: {integrity: sha512-rT00SPnTVyRsaSz5zgSPma/aHSOic5U1prhYdRy5HS2kTZviFpmDgzilbtsJsxiroqACmayynDN/9VzIbX5DOw==} - string-argv@0.3.2: resolution: {integrity: sha512-aqD2Q0144Z+/RqG52NeHEkZauTAUWJO8c6yTftGJKO3Tja5tUgIfmIl6kExvhtxSDP7fXB6DvzkfMpCd/F3G+Q==} engines: {node: '>=0.6.19'} @@ -7109,6 +7068,10 @@ snapshots: '@rtsao/scc@1.1.0': {} + '@sebbo2002/semantic-release-jsr@2.0.0': + dependencies: + jsr: 0.13.2 + '@sec-ant/readable-stream@0.4.1': {} '@semantic-release/changelog@6.0.3(semantic-release@24.1.2(typescript@5.6.2))': @@ -7730,17 +7693,6 @@ snapshots: transitivePeerDependencies: - supports-color - babel-polyfill@6.26.0: - dependencies: - babel-runtime: 6.26.0 - core-js: 2.6.12 - regenerator-runtime: 0.10.5 - - babel-runtime@6.26.0: - dependencies: - core-js: 2.6.12 - regenerator-runtime: 0.11.1 - balanced-match@1.0.2: {} base64-js@1.5.1: {} @@ -8033,8 +7985,6 @@ snapshots: dependencies: browserslist: 4.24.0 - core-js@2.6.12: {} - core-util-is@1.0.3: {} cosmiconfig-typescript-loader@5.0.0(@types/node@20.16.10)(cosmiconfig@9.0.0(typescript@5.6.2))(typescript@5.6.2): @@ -8261,8 +8211,6 @@ snapshots: has-property-descriptors: 1.0.2 object-keys: 1.1.1 - denoify@1.6.16: {} - detect-file@1.0.0: {} detect-indent@6.1.0: {} @@ -8293,8 +8241,6 @@ snapshots: dependencies: readable-stream: 2.3.7 - duplexer@0.1.2: {} - eastasianwidth@0.2.0: {} easy-table@1.2.0: @@ -8933,16 +8879,6 @@ snapshots: esutils@2.0.3: {} - event-stream@3.3.4: - dependencies: - duplexer: 0.1.2 - from: 0.1.7 - map-stream: 0.1.0 - pause-stream: 0.0.11 - split: 0.3.3 - stream-combiner: 0.0.4 - through: 2.3.8 - eventemitter3@5.0.1: {} execa@5.1.1: @@ -9107,8 +9043,6 @@ snapshots: inherits: 2.0.4 readable-stream: 2.3.7 - from@0.1.7: {} - fs-extra@11.1.0: dependencies: graceful-fs: 4.2.10 @@ -9388,10 +9322,6 @@ snapshots: ieee754@1.2.1: {} - if-env-defined@1.0.0: - dependencies: - npm-run-all: 1.4.0 - ignore@5.3.1: {} import-fresh@3.3.0: @@ -9739,6 +9669,12 @@ snapshots: jsonparse@1.3.1: {} + jsr@0.13.2: + dependencies: + kolorist: 1.8.0 + node-stream-zip: 1.15.0 + semiver: 1.1.0 + jsx-ast-utils@3.3.5: dependencies: array-includes: 3.1.8 @@ -9773,6 +9709,8 @@ snapshots: zod: 3.23.8 zod-validation-error: 3.2.0(zod@3.23.8) + kolorist@1.8.0: {} + language-subtag-registry@0.3.23: {} language-tags@1.0.9: @@ -9932,8 +9870,6 @@ snapshots: map-obj@4.3.0: {} - map-stream@0.1.0: {} - markdown-it@14.1.0: dependencies: argparse: 2.0.1 @@ -10096,6 +10032,8 @@ snapshots: node-releases@2.0.18: {} + node-stream-zip@1.15.0: {} + normalize-package-data@2.5.0: dependencies: hosted-git-info: 2.8.9 @@ -10119,14 +10057,6 @@ snapshots: normalize-url@8.0.1: {} - npm-run-all@1.4.0: - dependencies: - babel-polyfill: 6.26.0 - minimatch: 3.1.2 - ps-tree: 1.2.0 - shell-quote: 1.8.0 - which: 1.3.1 - npm-run-path@4.0.1: dependencies: path-key: 3.1.1 @@ -10361,10 +10291,6 @@ snapshots: pathval@2.0.0: {} - pause-stream@0.0.11: - dependencies: - through: 2.3.8 - picocolors@1.1.0: {} picomatch@2.3.1: {} @@ -10435,10 +10361,6 @@ snapshots: proto-list@1.2.4: {} - ps-tree@1.2.0: - dependencies: - event-stream: 3.3.4 - punycode.js@2.3.1: {} punycode@2.3.0: {} @@ -10526,10 +10448,6 @@ snapshots: regenerate@1.4.2: {} - regenerator-runtime@0.10.5: {} - - regenerator-runtime@0.11.1: {} - regenerator-runtime@0.14.1: {} regenerator-transform@0.15.2: @@ -10739,6 +10657,8 @@ snapshots: - supports-color - typescript + semiver@1.1.0: {} + semver-diff@4.0.0: dependencies: semver: 7.6.3 @@ -10773,8 +10693,6 @@ snapshots: shebang-regex@3.0.0: {} - shell-quote@1.8.0: {} - side-channel@1.0.6: dependencies: call-bind: 1.0.7 @@ -10864,10 +10782,6 @@ snapshots: split2@4.2.0: {} - split@0.3.3: - dependencies: - through: 2.3.8 - stable-hash@0.0.4: {} stackback@0.0.2: {} @@ -10883,10 +10797,6 @@ snapshots: duplexer2: 0.1.4 readable-stream: 2.3.7 - stream-combiner@0.0.4: - dependencies: - duplexer: 0.1.2 - string-argv@0.3.2: {} string-width@4.2.3: diff --git a/project-dictionary.txt b/project-dictionary.txt index ae965a26..19f478a0 100644 --- a/project-dictionary.txt +++ b/project-dictionary.txt @@ -9,7 +9,6 @@ deepmerge deepmergecustomoptions deepmergets defu -denoify foo fred garply diff --git a/tsconfig.build.deno.json b/tsconfig.build.deno.json deleted file mode 100644 index 23d36430..00000000 --- a/tsconfig.build.deno.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "./tsconfig.build.json", - "compilerOptions": { - "outDir": "build/deno/" - }, - "exclude": ["node_modules", "build/deno/", "dist/", "src/**/*.deno.ts", "src/**/*.deno.tsx"] -} From ae350c0f695a1a9dc8e9689f103b4f9e642b9e57 Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Sat, 5 Oct 2024 01:36:03 +1300 Subject: [PATCH 2/2] build: swap out rollup-plugin-ts --- package.json | 8 +- pnpm-lock.yaml | 204 ++++++++++++-------------------------------- rollup.config.ts | 26 +++++- tsconfig.build.json | 4 +- 4 files changed, 86 insertions(+), 156 deletions(-) diff --git a/package.json b/package.json index eed24cc7..dbbf2da6 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ ], "scripts": { "benchmark": "pnpm run build && cd benchmark && pnpm run benchmark; cd ..", - "build": "rimraf dist && rollup -c rollup.config.ts --configPlugin rollup-plugin-ts", + "build": "rimraf dist && rollup -c rollup.config.ts --configPlugin @rollup/plugin-typescript", "cz": "git-cz", "lint": "eslint && pnpm run lint:md && pnpm run lint:spelling && pnpm run lint:knip && pnpm run lint:packages", "lint-fix": "eslint --fix && pnpm run lint:md-fix && pnpm run lint:packages-fix", @@ -78,6 +78,9 @@ "test:types": "pnpm run build && tsd -f 'tests/**/*.test-d.ts' -t 'dist/index.d.mts'", "typecheck": "tsc -p tsconfig.build.json --noEmit" }, + "resolutions": { + "dts-bundle-generator": "9.2.1" + }, "devDependencies": { "@commitlint/cli": "19.5.0", "@commitlint/config-conventional": "19.5.0", @@ -85,6 +88,7 @@ "@eslint/compat": "1.1.1", "@rebeccastevens/eslint-config": "3.2.2", "@rollup/plugin-replace": "6.0.1", + "@rollup/plugin-typescript": "12.1.0", "@sebbo2002/semantic-release-jsr": "2.0.0", "@semantic-release/changelog": "6.0.3", "@semantic-release/commit-analyzer": "13.0.0", @@ -134,7 +138,7 @@ "rimraf": "6.0.1", "rollup": "4.24.0", "rollup-plugin-deassert": "1.3.0", - "rollup-plugin-ts": "3.4.5", + "rollup-plugin-dts-bundle-generator": "1.4.0", "semantic-release": "24.1.2", "tsc-files": "1.1.4", "tsd": "0.31.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 182331b2..325df32b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4,6 +4,9 @@ settings: autoInstallPeers: true excludeLinksFromLockfile: false +overrides: + dts-bundle-generator: 9.2.1 + importers: .: @@ -26,6 +29,9 @@ importers: '@rollup/plugin-replace': specifier: 6.0.1 version: 6.0.1(rollup@4.24.0) + '@rollup/plugin-typescript': + specifier: 12.1.0 + version: 12.1.0(rollup@4.24.0)(tslib@2.6.3)(typescript@5.6.2) '@sebbo2002/semantic-release-jsr': specifier: 2.0.0 version: 2.0.0 @@ -173,9 +179,9 @@ importers: rollup-plugin-deassert: specifier: 1.3.0 version: 1.3.0(acorn@8.12.1)(rollup@4.24.0) - rollup-plugin-ts: - specifier: 3.4.5 - version: 3.4.5(@babel/core@7.25.2)(@babel/preset-env@7.25.4(@babel/core@7.25.2))(@babel/runtime@7.25.7)(rollup@4.24.0)(typescript@5.6.2) + rollup-plugin-dts-bundle-generator: + specifier: 1.4.0 + version: 1.4.0 semantic-release: specifier: 24.1.2 version: 24.1.2(typescript@5.6.2) @@ -1366,9 +1372,6 @@ packages: resolution: {integrity: sha512-f5DRIOZf7wxogefH03RjMPMdBF7ADTWUMoOs9kaJo06EfwF+aFhMZMDZxHg/Xe12hptN9xoZjGso2fdjapBRIA==} engines: {node: '>=10'} - '@mdn/browser-compat-data@5.5.26': - resolution: {integrity: sha512-S2tqS5ElUyKhTNKIutzWkBDriFbyFJ+MQJfGA4l5UPMP6PgTBQxCkgGeh0Rb+nKbrzhxaXyBh2Zatjn9k2JKlQ==} - '@nicolo-ribaudo/eslint-scope-5-internals@5.1.1-v1': resolution: {integrity: sha512-54/JRvkLIzzDWshCWfuhadfrfZVPiElY8Fcgmg1HroEly/EDSszzhBAsarCux+D/kOslTRquNzuyGSmUSTTHGg==} @@ -1594,6 +1597,19 @@ packages: rollup: optional: true + '@rollup/plugin-typescript@12.1.0': + resolution: {integrity: sha512-Kzs8KGJofe7cfTRODsnG1jNGxSvU8gVoNNd7Z/QaY25AYwe2LSSUpx/kPxqF38NYkpR8de3m51r9uwJpDlz6dg==} + engines: {node: '>=14.0.0'} + peerDependencies: + rollup: ^2.14.0||^3.0.0||^4.0.0 + tslib: '*' + typescript: '>=3.7.0' + peerDependenciesMeta: + rollup: + optional: true + tslib: + optional: true + '@rollup/pluginutils@5.1.0': resolution: {integrity: sha512-XTIWOPPcpvyKI6L1NHo0lFlCyznUEyPmPY1mc3KpPVDYulHSTvyeLNVW00QTLIAFNhR3kYnJTQHeGqU4M3n09g==} engines: {node: '>=14.0.0'} @@ -1794,24 +1810,15 @@ packages: '@types/minimist@1.2.2': resolution: {integrity: sha512-jhuKLIRrhvCPLqwPcx6INqmKeiA5EWrsCOPhrlFSrbrmU4ZMPjj5Ul/oLCMDO98XRUIwVm78xICz4EPCektzeQ==} - '@types/node@17.0.45': - resolution: {integrity: sha512-w+tIMs3rq2afQdsPJlODhoUEKzFP1ayaoyl1CcnwtIlsVe7K7bA1NGm4s3PraqTLlXnbIN84zuBlxBWo1u9BLw==} - '@types/node@20.16.10': resolution: {integrity: sha512-vQUKgWTjEIRFCvK6CyriPH3MZYiYlNy0fKiEYHWbcoWLEgs4opurGGKlebrTLqdSMIbXImH6XExNiIyNUv3WpA==} '@types/normalize-package-data@2.4.4': resolution: {integrity: sha512-37i+OaWTh9qeK4LSHPsyRC7NahnGotNuZvjLSgcPzblpHB3rrCJxAOgI5gCdKm7coonsaX1Of0ILiTcnZjbfxA==} - '@types/object-path@0.11.4': - resolution: {integrity: sha512-4tgJ1Z3elF/tOMpA8JLVuR9spt9Ynsf7+JjqsQ2IqtiPJtcLoHoXcT6qU4E10cPFqyXX5HDm9QwIzZhBSkLxsw==} - '@types/semver@7.5.8': resolution: {integrity: sha512-I8EUhyrgfLrcTkzV3TSsGyl1tSuPrEDzr0yd5m90UgNxQkyDXULk3b6MlQqTCpZpNtWe1K0hzclnZkTcLBe2UQ==} - '@types/ua-parser-js@0.7.39': - resolution: {integrity: sha512-P/oDfpofrdtF5xw433SPALpdSchtJmY7nsJItf8h3KXqOslkbySh8zq4dSWXH2oTjRvJ5PczVEoCZPow6GicLg==} - '@types/unist@2.0.6': resolution: {integrity: sha512-PBjIUxZHOuj0R15/xuwJYjFi+KZdNFrehocChv4g5hu6aFroHue8m0lBP0POdK2nKzbw0cgV1mws8+V/JAcEkQ==} @@ -2001,10 +2008,6 @@ packages: '@vitest/utils@2.1.2': resolution: {integrity: sha512-zMO2KdYy6mx56btx9JvAqAZ6EyS3g49krMPPrgOp1yxGZiA93HumGk+bZ5jIZtOg5/VBYl5eBmGRQHqq4FG6uQ==} - '@wessberg/stringutil@1.0.19': - resolution: {integrity: sha512-9AZHVXWlpN8Cn9k5BC/O0Dzb9E9xfEMXzYrNunwvkUTvuK7xgQPVRZpLo+jWCOZ5r8oBa8NIrHuPEu1hzbb6bg==} - engines: {node: '>=8.0.0'} - JSONStream@1.3.5: resolution: {integrity: sha512-E+iruNOY8VV9s4JEbe1aNEm6MiszPRr/UfcHMz0TQh1BXSxHK+ASV1R6W4HpjBhSeS+54PIsAMCBmwD06LLsqQ==} hasBin: true @@ -2041,10 +2044,6 @@ packages: ajv@8.12.0: resolution: {integrity: sha512-sRu1kpcO9yLtYxBKvqfTeh9KzZEwO3STyX1HT+4CaDzC6HpTGYhIhPIzj9XuKU7KYDwnaeh5hcOwjy1QuJzBPA==} - ansi-colors@4.1.3: - resolution: {integrity: sha512-/6w/C21Pm1A7aZitlI5Ni/2J6FFQN8i1Cvz3kHABAAbw93v/NlvKdVOqz7CCWz/3iv/JplRSEEZ83XION15ovw==} - engines: {node: '>=6'} - ansi-escapes@4.3.2: resolution: {integrity: sha512-gKXj5ALrKWQLsYG9jlTRmR/xKluxHV+Z9QEwNIgCfM1/uwPMCuzVVnh5mwTd+OuBZcwSIMbqssNWRm1lE51QaQ==} engines: {node: '>=8'} @@ -2206,10 +2205,6 @@ packages: resolution: {integrity: sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==} engines: {node: '>=8'} - browserslist-generator@2.1.0: - resolution: {integrity: sha512-ZFz4mAOgqm0cbwKaZsfJbYDbTXGoPANlte7qRsRJOfjB9KmmISQrXJxAVrnXG8C8v/QHNzXyeJt0Cfcks6zZvQ==} - engines: {node: '>=16.15.1', npm: '>=7.0.0', pnpm: '>=3.2.0', yarn: '>=1.13'} - browserslist@4.24.0: resolution: {integrity: sha512-Rmb62sR1Zpjql25eSanFGEhAxcFwfA1K0GuQcLoaJBAcENegrQut3hYdhXFF1obQfiDyqIW/cLM5HSJ/9k884A==} engines: {node: ^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7} @@ -2396,12 +2391,6 @@ packages: compare-func@2.0.0: resolution: {integrity: sha512-zHig5N+tPWARooBnb0Zx1MFcdfpyJrfTJ3Y5L+IFvUm8rM74hHz66z0gw0x4tijh5CorKkKUCnW82R2vmpeCRA==} - compatfactory@3.0.0: - resolution: {integrity: sha512-WD5kF7koPwVoyKL8p0LlrmIZtilrD46sQStyzzxzTFinMKN2Dxk1hN+sddLSQU1mGIZvQfU8c+ONSghvvM40jg==} - engines: {node: '>=14.9.0'} - peerDependencies: - typescript: '>=3.x || >= 4.x || >= 5.x' - concat-map@0.0.1: resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==} @@ -2479,10 +2468,6 @@ packages: resolution: {integrity: sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==} engines: {node: '>= 8'} - crosspath@2.0.0: - resolution: {integrity: sha512-ju88BYCQ2uvjO2bR+SsgLSTwTSctU+6Vp2ePbKPgSCZyy4MWZxYsT738DlKVRE5utUjobjPRm1MkTYKJxCmpTA==} - engines: {node: '>=14.9.0'} - crypto-random-string@4.0.0: resolution: {integrity: sha512-x8dy3RnvYdlUcPOjkEHqozhiwzKNSq7GcPuXFbnyMOCHxX8V3OgIg/pYuabl2sbUPfIJaeAQB7PMOK8DFIdoRA==} engines: {node: '>=12'} @@ -2646,6 +2631,11 @@ packages: resolution: {integrity: sha512-QM8q3zDe58hqUqjraQOmzZ1LIH9SWQJTlEKCH4kJ2oQvLZk7RbQXvtDM2XEq3fwkV9CCvvH4LA0AV+ogFsBM2Q==} engines: {node: '>=8'} + dts-bundle-generator@9.2.1: + resolution: {integrity: sha512-sMyIGJcn+FSc4f4VzRgX4muZS2uG91c/DjC++HkpZJyudGedSpGNR5bY9HEkSyyYFay0ERzjoDM7uKgUycaRvw==} + engines: {node: '>=14.0.0'} + hasBin: true + duplexer2@0.1.4: resolution: {integrity: sha512-asLFVfWWtJ90ZyOUHMqk7/S2w2guQKxUI2itj3d92ADHhxUSbCMGi1f1cBcJ7xM1To+pE/Khbwo1yuNbMEPKeA==} @@ -3384,10 +3374,6 @@ packages: resolution: {integrity: sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==} engines: {node: '>= 0.4'} - helpertypes@0.0.19: - resolution: {integrity: sha512-J00e55zffgi3yVnUp0UdbMztNkr2PnizEkOe9URNohnrNhW5X0QpegkuLpOmFQInpi93Nb8MCjQRHAiCDF42NQ==} - engines: {node: '>=10.0.0'} - highlight.js@10.7.3: resolution: {integrity: sha512-tzcUFauisWKNHaRkN4Wjl/ZA07gENAjFl3J/c480dprkGTg5EQstgaNFqBfUqCq54kZRIEcreTsAgF/m2quD7A==} @@ -3708,10 +3694,6 @@ packages: isarray@2.0.5: resolution: {integrity: sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw==} - isbot@3.8.0: - resolution: {integrity: sha512-vne1mzQUTR+qsMLeCBL9+/tgnDXRyc2pygLGl/WsgA+EZKIiB5Ehu0CiVTHIIk30zhJ24uGz4M5Ppse37aR0Hg==} - engines: {node: '>=12'} - isexe@2.0.0: resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==} @@ -4279,10 +4261,6 @@ packages: resolution: {integrity: sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==} engines: {node: '>= 0.4'} - object-path@0.11.8: - resolution: {integrity: sha512-YJjNZrlXJFM42wTBn6zgOJVar9KFJvzx6sTWDte8sWZF//cnjl0BxHNpfZx+ZffXX63A9q0b1zsFiBX4g4X5KA==} - engines: {node: '>= 10.12.0'} - object.assign@4.1.5: resolution: {integrity: sha512-byy+U7gp+FVwmyzKPYhW2h5l3crpmGsxl7X2s8y43IgxvG4g3QZ6CffDtsNQy1WsmZpQbO+ybo0AlW7TY6DcBQ==} engines: {node: '>= 0.4'} @@ -4741,35 +4719,13 @@ packages: acorn: ^8.12.1 rollup: ^4.20.0 - rollup-plugin-ts@3.4.5: - resolution: {integrity: sha512-9iCstRJpEZXSRQuXitlSZAzcGlrqTbJg1pE4CMbEi6xYldxVncdPyzA2I+j6vnh73wBymZckerS+Q/iEE/M3Ow==} - engines: {node: '>=16.15.1', npm: '>=7.0.0', pnpm: '>=3.2.0', yarn: '>=1.13'} - deprecated: please use @rollup/plugin-typescript and rollup-plugin-dts instead - peerDependencies: - '@babel/core': '>=7.x' - '@babel/plugin-transform-runtime': '>=7.x' - '@babel/preset-env': '>=7.x' - '@babel/preset-typescript': '>=7.x' - '@babel/runtime': '>=7.x' - '@swc/core': '>=1.x' - '@swc/helpers': '>=0.2' - rollup: '>=1.x || >=2.x || >=3.x' - typescript: '>=3.2.x || >= 4.x || >= 5.x' - peerDependenciesMeta: - '@babel/core': - optional: true - '@babel/plugin-transform-runtime': - optional: true - '@babel/preset-env': - optional: true - '@babel/preset-typescript': - optional: true - '@babel/runtime': - optional: true - '@swc/core': - optional: true - '@swc/helpers': - optional: true + rollup-plugin-dts-bundle-generator@1.4.0: + resolution: {integrity: sha512-++Vax6N0iFiH6/hqbKvdnVvyz48grMqAos6TqW4wajQE0AgDzbQK0hbsyDgKTTQoz1BjanC0omOJc/RnQoYajQ==} + + rollup@2.79.2: + resolution: {integrity: sha512-fS6iqSPZDs3dr/y7Od6y5nha8dW1YnbgtsyotCVvoFGKbERG++CVRFv1meyGDE1SNItQA8BrnCw7ScdAhRJ3XQ==} + engines: {node: '>=10.0.0'} + hasBin: true rollup@4.24.0: resolution: {integrity: sha512-DOmrlGSXNk1DM0ljiQA+i+o0rSLhtii1je5wgk60j49d1jHT5YYttBv1iWOnYSTG+fZZESUOSNiAl89SIet+Cg==} @@ -5166,12 +5122,6 @@ packages: peerDependencies: typescript: '>=4.2.0' - ts-clone-node@3.0.0: - resolution: {integrity: sha512-egavvyHbIoelkgh1IC2agNB1uMNjB8VJgh0g/cn0bg2XXTcrtjrGMzEk4OD3Fi2hocICjP3vMa56nkzIzq0FRg==} - engines: {node: '>=14.9.0'} - peerDependencies: - typescript: ^3.x || ^4.x || ^5.x - ts-declaration-location@1.0.4: resolution: {integrity: sha512-r4JoxYhKULbZuH81Pjrp9OEG5St7XWk7zXwGkLKhmVcjiBVHTJXV5wK6dEa9JKW5QGSTW6b1lOjxAKp8R1SQhg==} peerDependencies: @@ -5261,9 +5211,6 @@ packages: engines: {node: '>=14.17'} hasBin: true - ua-parser-js@1.0.37: - resolution: {integrity: sha512-bhTyI94tZofjo+Dn8SN6Zv8nBDvyXTymAdM3LDI/0IboIUwTu1rEhW7v2TfiVsoYWgkQ4kOVqnI8APUFbIQIFQ==} - uc.micro@2.1.0: resolution: {integrity: sha512-ARDJmphmdvUk6Glw7y9DQ2bFkKBHwQHLi2lsaH6PPmz/Ka9sFOBsBluozhDltWmnv9u/cF6Rt87znRTPV+yp/A==} @@ -6871,8 +6818,6 @@ snapshots: string-argv: 0.3.2 type-detect: 4.0.8 - '@mdn/browser-compat-data@5.5.26': {} - '@nicolo-ribaudo/eslint-scope-5-internals@5.1.1-v1': dependencies: eslint-scope: 5.1.1 @@ -7010,6 +6955,15 @@ snapshots: optionalDependencies: rollup: 4.24.0 + '@rollup/plugin-typescript@12.1.0(rollup@4.24.0)(tslib@2.6.3)(typescript@5.6.2)': + dependencies: + '@rollup/pluginutils': 5.1.0(rollup@4.24.0) + resolve: 1.22.8 + typescript: 5.6.2 + optionalDependencies: + rollup: 4.24.0 + tslib: 2.6.3 + '@rollup/pluginutils@5.1.0(rollup@4.24.0)': dependencies: '@types/estree': 1.0.6 @@ -7226,20 +7180,14 @@ snapshots: '@types/minimist@1.2.2': {} - '@types/node@17.0.45': {} - '@types/node@20.16.10': dependencies: undici-types: 6.19.8 '@types/normalize-package-data@2.4.4': {} - '@types/object-path@0.11.4': {} - '@types/semver@7.5.8': {} - '@types/ua-parser-js@0.7.39': {} - '@types/unist@2.0.6': {} '@typescript-eslint/eslint-plugin@7.16.1(@typescript-eslint/parser@8.8.0(eslint@9.11.1(jiti@2.1.2))(typescript@5.6.2))(eslint@9.11.1(jiti@2.1.2))(typescript@5.6.2)': @@ -7495,8 +7443,6 @@ snapshots: loupe: 3.1.1 tinyrainbow: 1.2.0 - '@wessberg/stringutil@1.0.19': {} - JSONStream@1.3.5: dependencies: jsonparse: 1.3.1 @@ -7542,8 +7488,6 @@ snapshots: require-from-string: 2.0.2 uri-js: 4.4.1 - ansi-colors@4.1.3: {} - ansi-escapes@4.3.2: dependencies: type-fest: 0.21.3 @@ -7720,19 +7664,6 @@ snapshots: dependencies: fill-range: 7.1.1 - browserslist-generator@2.1.0: - dependencies: - '@mdn/browser-compat-data': 5.5.26 - '@types/object-path': 0.11.4 - '@types/semver': 7.5.8 - '@types/ua-parser-js': 0.7.39 - browserslist: 4.24.0 - caniuse-lite: 1.0.30001667 - isbot: 3.8.0 - object-path: 0.11.8 - semver: 7.6.3 - ua-parser-js: 1.0.37 - browserslist@4.24.0: dependencies: caniuse-lite: 1.0.30001667 @@ -7928,11 +7859,6 @@ snapshots: array-ify: 1.0.0 dot-prop: 5.3.0 - compatfactory@3.0.0(typescript@5.6.2): - dependencies: - helpertypes: 0.0.19 - typescript: 5.6.2 - concat-map@0.0.1: {} confbox@0.1.7: {} @@ -8009,10 +7935,6 @@ snapshots: shebang-command: 2.0.0 which: 2.0.2 - crosspath@2.0.0: - dependencies: - '@types/node': 17.0.45 - crypto-random-string@4.0.0: dependencies: type-fest: 1.4.0 @@ -8237,6 +8159,11 @@ snapshots: dependencies: is-obj: 2.0.0 + dts-bundle-generator@9.2.1: + dependencies: + typescript: 5.6.2 + yargs: 17.6.2 + duplexer2@0.1.4: dependencies: readable-stream: 2.3.7 @@ -9268,8 +9195,6 @@ snapshots: dependencies: function-bind: 1.1.2 - helpertypes@0.0.19: {} - highlight.js@10.7.3: {} homedir-polyfill@1.0.3: @@ -9554,8 +9479,6 @@ snapshots: isarray@2.0.5: {} - isbot@3.8.0: {} - isexe@2.0.0: {} issue-parser@7.0.0: @@ -10078,8 +10001,6 @@ snapshots: object-keys@1.1.1: {} - object-path@0.11.8: {} - object.assign@4.1.5: dependencies: call-bind: 1.0.7 @@ -10546,24 +10467,14 @@ snapshots: deassert: 1.3.2 rollup: 4.24.0 - rollup-plugin-ts@3.4.5(@babel/core@7.25.2)(@babel/preset-env@7.25.4(@babel/core@7.25.2))(@babel/runtime@7.25.7)(rollup@4.24.0)(typescript@5.6.2): + rollup-plugin-dts-bundle-generator@1.4.0: dependencies: - '@rollup/pluginutils': 5.1.0(rollup@4.24.0) - '@wessberg/stringutil': 1.0.19 - ansi-colors: 4.1.3 - browserslist: 4.24.0 - browserslist-generator: 2.1.0 - compatfactory: 3.0.0(typescript@5.6.2) - crosspath: 2.0.0 - magic-string: 0.30.11 - rollup: 4.24.0 - ts-clone-node: 3.0.0(typescript@5.6.2) - tslib: 2.6.3 - typescript: 5.6.2 + dts-bundle-generator: 9.2.1 + rollup: 2.79.2 + + rollup@2.79.2: optionalDependencies: - '@babel/core': 7.25.2 - '@babel/preset-env': 7.25.4(@babel/core@7.25.2) - '@babel/runtime': 7.25.7 + fsevents: 2.3.3 rollup@4.24.0: dependencies: @@ -11001,11 +10912,6 @@ snapshots: dependencies: typescript: 5.6.2 - ts-clone-node@3.0.0(typescript@5.6.2): - dependencies: - compatfactory: 3.0.0(typescript@5.6.2) - typescript: 5.6.2 - ts-declaration-location@1.0.4(typescript@5.6.2): dependencies: minimatch: 10.0.1 @@ -11092,8 +10998,6 @@ snapshots: typescript@5.6.2: {} - ua-parser-js@1.0.37: {} - uc.micro@2.1.0: {} ufo@1.5.3: {} diff --git a/rollup.config.ts b/rollup.config.ts index 0c14d6b1..80d2b579 100644 --- a/rollup.config.ts +++ b/rollup.config.ts @@ -1,7 +1,8 @@ import rollupPluginReplace from "@rollup/plugin-replace"; +import rollupPluginTypescript from "@rollup/plugin-typescript"; import type { RollupOptions } from "rollup"; import rollupPluginDeassert from "rollup-plugin-deassert"; -import rollupPluginTs from "rollup-plugin-ts"; +import { generateDtsBundle } from "rollup-plugin-dts-bundle-generator"; import pkg from "./package.json" with { type: "json" }; @@ -18,11 +19,27 @@ const library = { file: pkg.exports.import, format: "esm", sourcemap: false, + plugins: [ + generateDtsBundle({ + compilation: { + preferredConfigPath: "tsconfig.build.json", + }, + outFile: pkg.exports.types.import, + }) as any, + ], }, { file: pkg.exports.require, format: "cjs", sourcemap: false, + plugins: [ + generateDtsBundle({ + compilation: { + preferredConfigPath: "tsconfig.build.json", + }, + outFile: pkg.exports.types.require, + }) as any, + ], }, ], @@ -34,8 +51,11 @@ const library = { }, plugins: [ - rollupPluginTs({ - transpileOnly: true, + rollupPluginTypescript({ + compilerOptions: { + noCheck: true, + declaration: false, + }, tsconfig: "tsconfig.build.json", }), rollupPluginReplace({ diff --git a/tsconfig.build.json b/tsconfig.build.json index 5b367589..7c082afa 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -2,7 +2,9 @@ "extends": "./tsconfig.base.json", "compilerOptions": { "rootDir": "src", - "declaration": true + "declaration": true, + "outDir": "dist", + "types": [] }, "include": ["src"] }