feat!: 700% faster deepCopyObject, refactor deep merging and deep copying, type improvements (#7272)

**BREAKING:**
- The `deepMerge` exported from payload now handles more complex data and
is slower. The old, simple deepMerge is now exported as `deepMergeSimple`
- `combineMerge` is no longer exported. You can use
`deepMergeWithCombinedArrays` instead
- The behavior of the exported `deepCopyObject` and `isPlainObject` may
be different and more reliable, as the underlying algorithm has changed
This commit is contained in:
Alessio Gravili
2024-07-22 13:01:52 -04:00
committed by GitHub
parent 2c16c608ba
commit c45fbb9149
82 changed files with 592 additions and 537 deletions

View File

@@ -1,16 +1,16 @@
import type { SanitizedCollectionConfig } from '../../../collections/config/types.js'
import type { SanitizedGlobalConfig } from '../../../globals/config/types.js'
import type { PayloadRequest, RequestContext } from '../../../types/index.js'
import type { JsonObject, PayloadRequest, RequestContext } from '../../../types/index.js'
import { deepCopyObject } from '../../../utilities/deepCopyObject.js'
import { deepCopyObjectSimple } from '../../../utilities/deepCopyObject.js'
import { traverseFields } from './traverseFields.js'
type Args = {
type Args<T extends JsonObject> = {
collection: SanitizedCollectionConfig | null
context: RequestContext
currentDepth?: number
depth: number
doc: Record<string, unknown>
doc: T
draft: boolean
fallbackLocale: null | string
findMany?: boolean
@@ -32,7 +32,7 @@ type Args = {
* - Populate relationships
*/
export async function afterRead<T = any>(args: Args): Promise<T> {
export async function afterRead<T extends JsonObject>(args: Args<T>): Promise<T> {
const {
collection,
context,
@@ -50,7 +50,7 @@ export async function afterRead<T = any>(args: Args): Promise<T> {
showHiddenFields,
} = args
const doc = deepCopyObject(incomingDoc)
const doc = deepCopyObjectSimple(incomingDoc)
const fieldPromises = []
const populationPromises = []