payload 3.94.0 → 3.94.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth/defaultAccess.d.ts +4 -0
- package/dist/auth/defaultAccess.d.ts.map +1 -1
- package/dist/auth/defaultAccess.js +4 -1
- package/dist/auth/defaultAccess.js.map +1 -1
- package/dist/auth/defaultAdminPanelUserAccess.consumers.spec.js +47 -0
- package/dist/auth/defaultAdminPanelUserAccess.consumers.spec.js.map +1 -0
- package/dist/collections/operations/count.d.ts.map +1 -1
- package/dist/collections/operations/count.js +3 -1
- package/dist/collections/operations/count.js.map +1 -1
- package/dist/collections/operations/countVersions.d.ts.map +1 -1
- package/dist/collections/operations/countVersions.js +3 -1
- package/dist/collections/operations/countVersions.js.map +1 -1
- package/dist/collections/operations/delete.d.ts.map +1 -1
- package/dist/collections/operations/delete.js +9 -7
- package/dist/collections/operations/delete.js.map +1 -1
- package/dist/collections/operations/find.d.ts.map +1 -1
- package/dist/collections/operations/find.js +9 -15
- package/dist/collections/operations/find.js.map +1 -1
- package/dist/collections/operations/findDistinct.d.ts.map +1 -1
- package/dist/collections/operations/findDistinct.js +3 -1
- package/dist/collections/operations/findDistinct.js.map +1 -1
- package/dist/collections/operations/findVersions.d.ts.map +1 -1
- package/dist/collections/operations/findVersions.js +10 -8
- package/dist/collections/operations/findVersions.js.map +1 -1
- package/dist/collections/operations/update.d.ts.map +1 -1
- package/dist/collections/operations/update.js +9 -15
- package/dist/collections/operations/update.js.map +1 -1
- package/dist/config/defaults.js +7 -7
- package/dist/config/defaults.js.map +1 -1
- package/dist/database/cloneWhere.d.ts +10 -0
- package/dist/database/cloneWhere.d.ts.map +1 -0
- package/dist/database/cloneWhere.js +31 -0
- package/dist/database/cloneWhere.js.map +1 -0
- package/dist/database/queryValidation/validateSearchParams.d.ts.map +1 -1
- package/dist/database/queryValidation/validateSearchParams.js +37 -1
- package/dist/database/queryValidation/validateSearchParams.js.map +1 -1
- package/dist/database/queryValidation/validateSortQuery.d.ts.map +1 -1
- package/dist/database/queryValidation/validateSortQuery.js +4 -2
- package/dist/database/queryValidation/validateSortQuery.js.map +1 -1
- package/dist/fields/hooks/beforeChange/index.d.ts.map +1 -1
- package/dist/fields/hooks/beforeChange/index.js +6 -0
- package/dist/fields/hooks/beforeChange/index.js.map +1 -1
- package/dist/folders/createFolderCollection.js +6 -6
- package/dist/folders/createFolderCollection.js.map +1 -1
- package/dist/globals/operations/countGlobalVersions.d.ts.map +1 -1
- package/dist/globals/operations/countGlobalVersions.js +3 -1
- package/dist/globals/operations/countGlobalVersions.js.map +1 -1
- package/dist/globals/operations/findVersions.d.ts.map +1 -1
- package/dist/globals/operations/findVersions.js +3 -1
- package/dist/globals/operations/findVersions.js.map +1 -1
- package/dist/index.bundled.d.ts +58 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/locked-documents/config.js +5 -5
- package/dist/locked-documents/config.js.map +1 -1
- package/dist/query-presets/access.js +5 -5
- package/dist/query-presets/access.js.map +1 -1
- package/dist/queues/config/global.d.ts.map +1 -1
- package/dist/queues/config/global.js +5 -0
- package/dist/queues/config/global.js.map +1 -1
- package/dist/queues/config/types/index.d.ts +3 -3
- package/dist/queues/config/types/index.js.map +1 -1
- package/dist/queues/localAPI.d.ts +6 -12
- package/dist/queues/localAPI.d.ts.map +1 -1
- package/dist/queues/localAPI.js +3 -3
- package/dist/queues/localAPI.js.map +1 -1
- package/dist/queues/operations/runJobs/index.js +1 -1
- package/dist/queues/operations/runJobs/index.js.map +1 -1
- package/dist/utilities/configToJSONSchema.d.ts.map +1 -1
- package/dist/utilities/configToJSONSchema.js +6 -0
- package/dist/utilities/configToJSONSchema.js.map +1 -1
- package/dist/utilities/configToJSONSchema.spec.js +17 -0
- package/dist/utilities/configToJSONSchema.spec.js.map +1 -1
- package/dist/utilities/deepMerge.d.ts +55 -3
- package/dist/utilities/deepMerge.d.ts.map +1 -1
- package/dist/utilities/deepMerge.js +97 -2
- package/dist/utilities/deepMerge.js.map +1 -1
- package/dist/utilities/deepMerge.spec.js +332 -0
- package/dist/utilities/deepMerge.spec.js.map +1 -0
- package/dist/utilities/sanitizeUpdateData.d.ts +5 -0
- package/dist/utilities/sanitizeUpdateData.d.ts.map +1 -0
- package/dist/utilities/sanitizeUpdateData.js +10 -0
- package/dist/utilities/sanitizeUpdateData.js.map +1 -0
- package/package.json +2 -3
|
@@ -1,6 +1,34 @@
|
|
|
1
|
-
import deepMerge from 'deepmerge';
|
|
2
1
|
import { isPlainObject } from './isPlainObject.js';
|
|
3
|
-
|
|
2
|
+
const REACT_ELEMENT_TYPES = new Set([
|
|
3
|
+
Symbol.for('react.element'),
|
|
4
|
+
Symbol.for('react.transitional.element')
|
|
5
|
+
]);
|
|
6
|
+
export function deepMerge(target, source, options) {
|
|
7
|
+
// Copied rather than mutated, so that a reused options object is left untouched.
|
|
8
|
+
const resolvedOptions = {
|
|
9
|
+
...options,
|
|
10
|
+
arrayMerge: options?.arrayMerge || defaultArrayMerge,
|
|
11
|
+
// Exposed on `options` so that custom `arrayMerge` implementations can use it.
|
|
12
|
+
cloneUnlessOtherwiseSpecified: cloneUnlessOtherwiseSpecified,
|
|
13
|
+
isMergeableObject: options?.isMergeableObject || isMergeableObject
|
|
14
|
+
};
|
|
15
|
+
const isSourceArray = Array.isArray(source);
|
|
16
|
+
const isTargetArray = Array.isArray(target);
|
|
17
|
+
if (isSourceArray !== isTargetArray) {
|
|
18
|
+
return cloneUnlessOtherwiseSpecified(source, resolvedOptions);
|
|
19
|
+
}
|
|
20
|
+
if (isSourceArray) {
|
|
21
|
+
return resolvedOptions.arrayMerge(target, source, resolvedOptions);
|
|
22
|
+
}
|
|
23
|
+
return mergeObject(target, source, resolvedOptions);
|
|
24
|
+
}
|
|
25
|
+
function deepMergeAll(objects, options) {
|
|
26
|
+
if (!Array.isArray(objects)) {
|
|
27
|
+
throw new Error('first argument should be an array');
|
|
28
|
+
}
|
|
29
|
+
return objects.reduce((previous, next)=>deepMerge(previous, next, options), {});
|
|
30
|
+
}
|
|
31
|
+
deepMerge.all = deepMergeAll;
|
|
4
32
|
/**
|
|
5
33
|
* Fully-featured deepMerge.
|
|
6
34
|
*
|
|
@@ -39,5 +67,72 @@ export { deepMerge };
|
|
|
39
67
|
isMergeableObject: isPlainObject
|
|
40
68
|
});
|
|
41
69
|
}
|
|
70
|
+
function isMergeableObject(value) {
|
|
71
|
+
if (!value || typeof value !== 'object') {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
const stringTag = Object.prototype.toString.call(value);
|
|
75
|
+
if (stringTag === '[object RegExp]' || stringTag === '[object Date]') {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
return !REACT_ELEMENT_TYPES.has(value.$$typeof);
|
|
79
|
+
}
|
|
80
|
+
function cloneUnlessOtherwiseSpecified(value, options) {
|
|
81
|
+
return options.clone !== false && options.isMergeableObject(value) ? deepMerge(Array.isArray(value) ? [] : {}, value, options) : value;
|
|
82
|
+
}
|
|
83
|
+
function defaultArrayMerge(target, source, options) {
|
|
84
|
+
return target.concat(source).map((element)=>cloneUnlessOtherwiseSpecified(element, options));
|
|
85
|
+
}
|
|
86
|
+
function getMergeFunction(key, options) {
|
|
87
|
+
if (!options.customMerge) {
|
|
88
|
+
return deepMerge;
|
|
89
|
+
}
|
|
90
|
+
const customMerge = options.customMerge(key, options);
|
|
91
|
+
return typeof customMerge === 'function' ? customMerge : deepMerge;
|
|
92
|
+
}
|
|
93
|
+
function getEnumerableOwnKeys(value) {
|
|
94
|
+
return [
|
|
95
|
+
...Object.keys(value),
|
|
96
|
+
...Object.getOwnPropertySymbols(value).filter((symbol)=>Object.prototype.propertyIsEnumerable.call(value, symbol))
|
|
97
|
+
];
|
|
98
|
+
}
|
|
99
|
+
function isPropertyOnObject(object, property) {
|
|
100
|
+
try {
|
|
101
|
+
return property in object;
|
|
102
|
+
} catch {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* A key is unsafe to merge when it exists on the target but is inherited or non-enumerable, or when
|
|
108
|
+
* it is `__proto__`, which would replace the prototype of the returned object on assignment.
|
|
109
|
+
*/ function isUnsafeKey(target, key) {
|
|
110
|
+
if (key === '__proto__') {
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
return isPropertyOnObject(target, key) && !(Object.prototype.hasOwnProperty.call(target, key) && Object.prototype.propertyIsEnumerable.call(target, key));
|
|
114
|
+
}
|
|
115
|
+
function mergeObject(target, source, options) {
|
|
116
|
+
const destination = {};
|
|
117
|
+
if (options.isMergeableObject(target)) {
|
|
118
|
+
for (const key of getEnumerableOwnKeys(target)){
|
|
119
|
+
if (key === '__proto__') {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
destination[key] = cloneUnlessOtherwiseSpecified(target[key], options);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
for (const key of getEnumerableOwnKeys(source)){
|
|
126
|
+
if (isUnsafeKey(target, key)) {
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
if (isPropertyOnObject(target, key) && options.isMergeableObject(source[key])) {
|
|
130
|
+
destination[key] = getMergeFunction(key, options)(target[key], source[key], options);
|
|
131
|
+
} else {
|
|
132
|
+
destination[key] = cloneUnlessOtherwiseSpecified(source[key], options);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return destination;
|
|
136
|
+
}
|
|
42
137
|
|
|
43
138
|
//# sourceMappingURL=deepMerge.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/deepMerge.ts"],"sourcesContent":["import deepMerge from 'deepmerge'\n\nimport { isPlainObject } from './isPlainObject.js'\n\nexport { deepMerge }\n/**\n * Fully-featured deepMerge.\n *\n * Array handling: Arrays in the target object are combined with the source object's arrays.\n */\nexport function deepMergeWithCombinedArrays<T extends object>(\n obj1: object,\n obj2: object,\n options: deepMerge.Options = {},\n): T {\n return deepMerge<T>(obj1, obj2, {\n arrayMerge: (target, source, options) => {\n const destination = target.slice()\n\n source.forEach((item, index) => {\n if (typeof destination[index] === 'undefined') {\n destination[index] = options?.cloneUnlessOtherwiseSpecified(item, options)\n } else if (options?.isMergeableObject(item)) {\n destination[index] = deepMerge(target[index], item, options)\n } else if (target.indexOf(item) === -1) {\n destination.push(item)\n }\n })\n return destination\n },\n ...options,\n })\n}\n\n/**\n * Fully-featured deepMerge.\n *\n * Array handling: Arrays in the target object are replaced by the source object's arrays.\n */\nexport function deepMergeWithSourceArrays<T extends object>(obj1: object, obj2: object): T {\n return deepMerge<T>(obj1, obj2, { arrayMerge: (_, source) => source })\n}\n\n/**\n * Fully-featured deepMerge. Does not clone React components by default.\n */\nexport function deepMergeWithReactComponents<T extends object>(obj1: object, obj2: object): T {\n return deepMerge<T>(obj1, obj2, {\n isMergeableObject: isPlainObject,\n })\n}\n"],"names":["deepMerge","isPlainObject","deepMergeWithCombinedArrays","obj1","obj2","options","arrayMerge","target","source","destination","slice","forEach","item","index","cloneUnlessOtherwiseSpecified","isMergeableObject","indexOf","push","deepMergeWithSourceArrays","_","deepMergeWithReactComponents"],"mappings":"AAAA,OAAOA,eAAe,YAAW;AAEjC,SAASC,aAAa,QAAQ,qBAAoB;AAElD,SAASD,SAAS,GAAE;AACpB;;;;CAIC,GACD,OAAO,SAASE,4BACdC,IAAY,EACZC,IAAY,EACZC,UAA6B,CAAC,CAAC;IAE/B,OAAOL,UAAaG,MAAMC,MAAM;QAC9BE,YAAY,CAACC,QAAQC,QAAQH;YAC3B,MAAMI,cAAcF,OAAOG,KAAK;YAEhCF,OAAOG,OAAO,CAAC,CAACC,MAAMC;gBACpB,IAAI,OAAOJ,WAAW,CAACI,MAAM,KAAK,aAAa;oBAC7CJ,WAAW,CAACI,MAAM,GAAGR,SAASS,8BAA8BF,MAAMP;gBACpE,OAAO,IAAIA,SAASU,kBAAkBH,OAAO;oBAC3CH,WAAW,CAACI,MAAM,GAAGb,UAAUO,MAAM,CAACM,MAAM,EAAED,MAAMP;gBACtD,OAAO,IAAIE,OAAOS,OAAO,CAACJ,UAAU,CAAC,GAAG;oBACtCH,YAAYQ,IAAI,CAACL;gBACnB;YACF;YACA,OAAOH;QACT;QACA,GAAGJ,OAAO;IACZ;AACF;AAEA;;;;CAIC,GACD,OAAO,SAASa,0BAA4Cf,IAAY,EAAEC,IAAY;IACpF,OAAOJ,UAAaG,MAAMC,MAAM;QAAEE,YAAY,CAACa,GAAGX,SAAWA;IAAO;AACtE;AAEA;;CAEC,GACD,OAAO,SAASY,6BAA+CjB,IAAY,EAAEC,IAAY;IACvF,OAAOJ,UAAaG,MAAMC,MAAM;QAC9BW,mBAAmBd;IACrB;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/deepMerge.ts"],"sourcesContent":["import { isPlainObject } from './isPlainObject.js'\n\nexport type DeepMergeArrayMergeOptions = {\n cloneUnlessOtherwiseSpecified(value: object, options?: DeepMergeOptions): any\n isMergeableObject(value: object): boolean\n}\n\nexport type DeepMergeOptions = {\n /**\n * Merges two arrays. Defaults to concatenating `target` and `source`.\n */\n arrayMerge?: (target: any[], source: any[], options: ResolvedDeepMergeOptions) => any[]\n /**\n * When `false`, mergeable values are copied by reference instead of being deeply cloned.\n * @default true\n */\n clone?: boolean\n /**\n * Returns a custom merge function for a given key, or `undefined` to use the default merge.\n */\n customMerge?: (key: string, options?: DeepMergeOptions) => ((x: any, y: any) => any) | undefined\n /**\n * Determines whether a value should be merged recursively or copied as-is.\n */\n isMergeableObject?(value: object): boolean\n}\n\ntype ResolvedDeepMergeOptions = {\n arrayMerge: NonNullable<DeepMergeOptions['arrayMerge']>\n isMergeableObject: (value: unknown) => boolean\n} & DeepMergeArrayMergeOptions &\n DeepMergeOptions\n\nconst REACT_ELEMENT_TYPES = new Set<unknown>([\n Symbol.for('react.element'),\n Symbol.for('react.transitional.element'),\n])\n\n/**\n * Fully-featured deepMerge. Returns a new object and does not mutate its arguments.\n *\n * Array handling: arrays are concatenated unless `arrayMerge` is provided.\n *\n * `__proto__` keys are never copied to the result, preventing prototype poisoning of the returned\n * object when merging untrusted input (e.g. parsed JSON).\n */\nexport function deepMerge<T>(x: Partial<T>, y: Partial<T>, options?: DeepMergeOptions): T\nexport function deepMerge<T1, T2>(\n x: Partial<T1>,\n y: Partial<T2>,\n options?: DeepMergeOptions,\n): T1 & T2\nexport function deepMerge(target: any, source: any, options?: DeepMergeOptions): any {\n // Copied rather than mutated, so that a reused options object is left untouched.\n const resolvedOptions = {\n ...options,\n arrayMerge: options?.arrayMerge || defaultArrayMerge,\n // Exposed on `options` so that custom `arrayMerge` implementations can use it.\n cloneUnlessOtherwiseSpecified: cloneUnlessOtherwiseSpecified as any,\n isMergeableObject: options?.isMergeableObject || isMergeableObject,\n } as ResolvedDeepMergeOptions\n\n const isSourceArray = Array.isArray(source)\n const isTargetArray = Array.isArray(target)\n\n if (isSourceArray !== isTargetArray) {\n return cloneUnlessOtherwiseSpecified(source, resolvedOptions)\n }\n\n if (isSourceArray) {\n return resolvedOptions.arrayMerge(target, source, resolvedOptions)\n }\n\n return mergeObject(target, source, resolvedOptions)\n}\n\n/**\n * Keeps the `deepMerge.Options` / `deepMerge.ArrayMergeOptions` type references from the former\n * `deepmerge` dependency working.\n */\n// eslint-disable-next-line @typescript-eslint/no-namespace\nexport declare namespace deepMerge {\n type ArrayMergeOptions = DeepMergeArrayMergeOptions\n type Options = DeepMergeOptions\n}\n\n/**\n * Deep-merges all objects in the array, from left to right.\n */\nfunction deepMergeAll<T = object>(objects: Partial<T>[], options?: DeepMergeOptions): T\nfunction deepMergeAll(objects: object[], options?: DeepMergeOptions): object\nfunction deepMergeAll(objects: object[], options?: DeepMergeOptions): object {\n if (!Array.isArray(objects)) {\n throw new Error('first argument should be an array')\n }\n\n return objects.reduce<object>((previous, next) => deepMerge(previous, next, options), {})\n}\n\ndeepMerge.all = deepMergeAll\n\n/**\n * Fully-featured deepMerge.\n *\n * Array handling: Arrays in the target object are combined with the source object's arrays.\n */\nexport function deepMergeWithCombinedArrays<T extends object>(\n obj1: object,\n obj2: object,\n options: DeepMergeOptions = {},\n): T {\n return deepMerge<T>(obj1, obj2, {\n arrayMerge: (target, source, options) => {\n const destination = target.slice()\n\n source.forEach((item, index) => {\n if (typeof destination[index] === 'undefined') {\n destination[index] = options?.cloneUnlessOtherwiseSpecified(item, options)\n } else if (options?.isMergeableObject(item)) {\n destination[index] = deepMerge(target[index], item, options)\n } else if (target.indexOf(item) === -1) {\n destination.push(item)\n }\n })\n return destination\n },\n ...options,\n })\n}\n\n/**\n * Fully-featured deepMerge.\n *\n * Array handling: Arrays in the target object are replaced by the source object's arrays.\n */\nexport function deepMergeWithSourceArrays<T extends object>(obj1: object, obj2: object): T {\n return deepMerge<T>(obj1, obj2, { arrayMerge: (_, source) => source })\n}\n\n/**\n * Fully-featured deepMerge. Does not clone React components by default.\n */\nexport function deepMergeWithReactComponents<T extends object>(obj1: object, obj2: object): T {\n return deepMerge<T>(obj1, obj2, {\n isMergeableObject: isPlainObject,\n })\n}\n\nfunction isMergeableObject(value: unknown): boolean {\n if (!value || typeof value !== 'object') {\n return false\n }\n\n const stringTag = Object.prototype.toString.call(value)\n\n if (stringTag === '[object RegExp]' || stringTag === '[object Date]') {\n return false\n }\n\n return !REACT_ELEMENT_TYPES.has((value as { $$typeof?: unknown }).$$typeof)\n}\n\nfunction cloneUnlessOtherwiseSpecified(value: unknown, options: ResolvedDeepMergeOptions): any {\n return options.clone !== false && options.isMergeableObject(value)\n ? deepMerge<object>(Array.isArray(value) ? [] : {}, value as object, options)\n : value\n}\n\nfunction defaultArrayMerge(target: any[], source: any[], options: ResolvedDeepMergeOptions) {\n return target.concat(source).map((element) => cloneUnlessOtherwiseSpecified(element, options))\n}\n\nfunction getMergeFunction(key: PropertyKey, options: ResolvedDeepMergeOptions) {\n if (!options.customMerge) {\n return deepMerge\n }\n\n const customMerge = options.customMerge(key as string, options)\n\n return typeof customMerge === 'function' ? customMerge : deepMerge\n}\n\nfunction getEnumerableOwnKeys(value: object): PropertyKey[] {\n return [\n ...Object.keys(value),\n ...Object.getOwnPropertySymbols(value).filter((symbol) =>\n Object.prototype.propertyIsEnumerable.call(value, symbol),\n ),\n ]\n}\n\nfunction isPropertyOnObject(object: object, property: PropertyKey): boolean {\n try {\n return property in object\n } catch {\n return false\n }\n}\n\n/**\n * A key is unsafe to merge when it exists on the target but is inherited or non-enumerable, or when\n * it is `__proto__`, which would replace the prototype of the returned object on assignment.\n */\nfunction isUnsafeKey(target: object, key: PropertyKey): boolean {\n if (key === '__proto__') {\n return true\n }\n\n return (\n isPropertyOnObject(target, key) &&\n !(\n Object.prototype.hasOwnProperty.call(target, key) &&\n Object.prototype.propertyIsEnumerable.call(target, key)\n )\n )\n}\n\nfunction mergeObject(target: any, source: any, options: ResolvedDeepMergeOptions) {\n const destination: Record<PropertyKey, unknown> = {}\n\n if (options.isMergeableObject(target)) {\n for (const key of getEnumerableOwnKeys(target)) {\n if (key === '__proto__') {\n continue\n }\n\n destination[key] = cloneUnlessOtherwiseSpecified(target[key], options)\n }\n }\n\n for (const key of getEnumerableOwnKeys(source)) {\n if (isUnsafeKey(target, key)) {\n continue\n }\n\n if (isPropertyOnObject(target, key) && options.isMergeableObject(source[key])) {\n destination[key] = getMergeFunction(key, options)(target[key], source[key], options)\n } else {\n destination[key] = cloneUnlessOtherwiseSpecified(source[key], options)\n }\n }\n\n return destination\n}\n"],"names":["isPlainObject","REACT_ELEMENT_TYPES","Set","Symbol","for","deepMerge","target","source","options","resolvedOptions","arrayMerge","defaultArrayMerge","cloneUnlessOtherwiseSpecified","isMergeableObject","isSourceArray","Array","isArray","isTargetArray","mergeObject","deepMergeAll","objects","Error","reduce","previous","next","all","deepMergeWithCombinedArrays","obj1","obj2","destination","slice","forEach","item","index","indexOf","push","deepMergeWithSourceArrays","_","deepMergeWithReactComponents","value","stringTag","Object","prototype","toString","call","has","$$typeof","clone","concat","map","element","getMergeFunction","key","customMerge","getEnumerableOwnKeys","keys","getOwnPropertySymbols","filter","symbol","propertyIsEnumerable","isPropertyOnObject","object","property","isUnsafeKey","hasOwnProperty"],"mappings":"AAAA,SAASA,aAAa,QAAQ,qBAAoB;AAiClD,MAAMC,sBAAsB,IAAIC,IAAa;IAC3CC,OAAOC,GAAG,CAAC;IACXD,OAAOC,GAAG,CAAC;CACZ;AAgBD,OAAO,SAASC,UAAUC,MAAW,EAAEC,MAAW,EAAEC,OAA0B;IAC5E,iFAAiF;IACjF,MAAMC,kBAAkB;QACtB,GAAGD,OAAO;QACVE,YAAYF,SAASE,cAAcC;QACnC,+EAA+E;QAC/EC,+BAA+BA;QAC/BC,mBAAmBL,SAASK,qBAAqBA;IACnD;IAEA,MAAMC,gBAAgBC,MAAMC,OAAO,CAACT;IACpC,MAAMU,gBAAgBF,MAAMC,OAAO,CAACV;IAEpC,IAAIQ,kBAAkBG,eAAe;QACnC,OAAOL,8BAA8BL,QAAQE;IAC/C;IAEA,IAAIK,eAAe;QACjB,OAAOL,gBAAgBC,UAAU,CAACJ,QAAQC,QAAQE;IACpD;IAEA,OAAOS,YAAYZ,QAAQC,QAAQE;AACrC;AAiBA,SAASU,aAAaC,OAAiB,EAAEZ,OAA0B;IACjE,IAAI,CAACO,MAAMC,OAAO,CAACI,UAAU;QAC3B,MAAM,IAAIC,MAAM;IAClB;IAEA,OAAOD,QAAQE,MAAM,CAAS,CAACC,UAAUC,OAASnB,UAAUkB,UAAUC,MAAMhB,UAAU,CAAC;AACzF;AAEAH,UAAUoB,GAAG,GAAGN;AAEhB;;;;CAIC,GACD,OAAO,SAASO,4BACdC,IAAY,EACZC,IAAY,EACZpB,UAA4B,CAAC,CAAC;IAE9B,OAAOH,UAAasB,MAAMC,MAAM;QAC9BlB,YAAY,CAACJ,QAAQC,QAAQC;YAC3B,MAAMqB,cAAcvB,OAAOwB,KAAK;YAEhCvB,OAAOwB,OAAO,CAAC,CAACC,MAAMC;gBACpB,IAAI,OAAOJ,WAAW,CAACI,MAAM,KAAK,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,IAAIQ,mBAAmBtD,QAAQ8C,QAAQ5C,QAAQK,iBAAiB,CAACN,MAAM,CAAC6C,IAAI,GAAG;YAC7EvB,WAAW,CAACuB,IAAI,GAAGD,iBAAiBC,KAAK5C,SAASF,MAAM,CAAC8C,IAAI,EAAE7C,MAAM,CAAC6C,IAAI,EAAE5C;QAC9E,OAAO;YACLqB,WAAW,CAACuB,IAAI,GAAGxC,8BAA8BL,MAAM,CAAC6C,IAAI,EAAE5C;QAChE;IACF;IAEA,OAAOqB;AACT"}
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { deepMerge, deepMergeWithCombinedArrays, deepMergeWithReactComponents, deepMergeWithSourceArrays } from './deepMerge.js';
|
|
3
|
+
describe('deepMerge', ()=>{
|
|
4
|
+
it('should deeply merge nested objects with source taking precedence', ()=>{
|
|
5
|
+
const result = deepMerge({
|
|
6
|
+
a: {
|
|
7
|
+
b: 1,
|
|
8
|
+
c: 2
|
|
9
|
+
},
|
|
10
|
+
d: 1
|
|
11
|
+
}, {
|
|
12
|
+
a: {
|
|
13
|
+
c: 3,
|
|
14
|
+
e: 4
|
|
15
|
+
},
|
|
16
|
+
f: 5
|
|
17
|
+
});
|
|
18
|
+
expect(result).toStrictEqual({
|
|
19
|
+
a: {
|
|
20
|
+
b: 1,
|
|
21
|
+
c: 3,
|
|
22
|
+
e: 4
|
|
23
|
+
},
|
|
24
|
+
d: 1,
|
|
25
|
+
f: 5
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
it('should not mutate its arguments and should clone nested values', ()=>{
|
|
29
|
+
const target = {
|
|
30
|
+
nested: {
|
|
31
|
+
value: 1
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const source = {
|
|
35
|
+
other: {
|
|
36
|
+
value: 2
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const result = deepMerge(target, source);
|
|
40
|
+
expect(target).toStrictEqual({
|
|
41
|
+
nested: {
|
|
42
|
+
value: 1
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
expect(source).toStrictEqual({
|
|
46
|
+
other: {
|
|
47
|
+
value: 2
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
expect(result.nested).not.toBe(target.nested);
|
|
51
|
+
expect(result.other).not.toBe(source.other);
|
|
52
|
+
});
|
|
53
|
+
it('should keep references when clone is false', ()=>{
|
|
54
|
+
const nested = {
|
|
55
|
+
value: 1
|
|
56
|
+
};
|
|
57
|
+
const result = deepMerge({}, {
|
|
58
|
+
nested
|
|
59
|
+
}, {
|
|
60
|
+
clone: false
|
|
61
|
+
});
|
|
62
|
+
expect(result.nested).toBe(nested);
|
|
63
|
+
});
|
|
64
|
+
it('should concatenate arrays by default', ()=>{
|
|
65
|
+
const result = deepMerge({
|
|
66
|
+
list: [
|
|
67
|
+
1,
|
|
68
|
+
2
|
|
69
|
+
]
|
|
70
|
+
}, {
|
|
71
|
+
list: [
|
|
72
|
+
3
|
|
73
|
+
]
|
|
74
|
+
});
|
|
75
|
+
expect(result).toStrictEqual({
|
|
76
|
+
list: [
|
|
77
|
+
1,
|
|
78
|
+
2,
|
|
79
|
+
3
|
|
80
|
+
]
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
it('should not deeply merge dates and regular expressions', ()=>{
|
|
84
|
+
const date = new Date();
|
|
85
|
+
const regex = /test/;
|
|
86
|
+
const result = deepMerge({
|
|
87
|
+
date: {},
|
|
88
|
+
regex: {}
|
|
89
|
+
}, {
|
|
90
|
+
date,
|
|
91
|
+
regex
|
|
92
|
+
});
|
|
93
|
+
expect(result.date).toBe(date);
|
|
94
|
+
expect(result.regex).toBe(regex);
|
|
95
|
+
});
|
|
96
|
+
it('should merge enumerable symbol keys', ()=>{
|
|
97
|
+
const symbol = Symbol('key');
|
|
98
|
+
const result = deepMerge({
|
|
99
|
+
[symbol]: {
|
|
100
|
+
a: 1
|
|
101
|
+
}
|
|
102
|
+
}, {
|
|
103
|
+
[symbol]: {
|
|
104
|
+
b: 2
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
expect(result[symbol]).toStrictEqual({
|
|
108
|
+
a: 1,
|
|
109
|
+
b: 2
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
it('should use customMerge for matching keys', ()=>{
|
|
113
|
+
const result = deepMerge({
|
|
114
|
+
a: {
|
|
115
|
+
x: 1
|
|
116
|
+
},
|
|
117
|
+
b: {
|
|
118
|
+
x: 1
|
|
119
|
+
}
|
|
120
|
+
}, {
|
|
121
|
+
a: {
|
|
122
|
+
y: 2
|
|
123
|
+
},
|
|
124
|
+
b: {
|
|
125
|
+
y: 2
|
|
126
|
+
}
|
|
127
|
+
}, {
|
|
128
|
+
customMerge: (key)=>key === 'a' ? (_x, y)=>y : undefined
|
|
129
|
+
});
|
|
130
|
+
expect(result).toStrictEqual({
|
|
131
|
+
a: {
|
|
132
|
+
y: 2
|
|
133
|
+
},
|
|
134
|
+
b: {
|
|
135
|
+
x: 1,
|
|
136
|
+
y: 2
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
it('should merge all objects with deepMerge.all', ()=>{
|
|
141
|
+
const result = deepMerge.all([
|
|
142
|
+
{
|
|
143
|
+
a: {
|
|
144
|
+
x: 1
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
a: {
|
|
149
|
+
y: 2
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
b: 3
|
|
154
|
+
}
|
|
155
|
+
]);
|
|
156
|
+
expect(result).toStrictEqual({
|
|
157
|
+
a: {
|
|
158
|
+
x: 1,
|
|
159
|
+
y: 2
|
|
160
|
+
},
|
|
161
|
+
b: 3
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
it('should not poison the prototype of the result via a __proto__ key in the source', ()=>{
|
|
165
|
+
const target = JSON.parse('{"__proto__": {}}');
|
|
166
|
+
const source = JSON.parse('{"__proto__": {"isAdmin": true}}');
|
|
167
|
+
const result = deepMerge(target, source);
|
|
168
|
+
expect(Object.getPrototypeOf(result)).toBe(Object.prototype);
|
|
169
|
+
expect(result.isAdmin).toBeUndefined();
|
|
170
|
+
});
|
|
171
|
+
it('should not poison the prototype of the result via a __proto__ key in the target', ()=>{
|
|
172
|
+
const target = JSON.parse('{"__proto__": {"isAdmin": true}}');
|
|
173
|
+
const result = deepMerge(target, {});
|
|
174
|
+
expect(Object.getPrototypeOf(result)).toBe(Object.prototype);
|
|
175
|
+
expect(result.isAdmin).toBeUndefined();
|
|
176
|
+
});
|
|
177
|
+
it('should not pollute Object.prototype via constructor.prototype', ()=>{
|
|
178
|
+
const source = JSON.parse('{"constructor": {"prototype": {"polluted": true}}}');
|
|
179
|
+
deepMerge({}, source);
|
|
180
|
+
expect({}.polluted).toBeUndefined();
|
|
181
|
+
});
|
|
182
|
+
it('should not poison the prototype via a nested __proto__ key that only exists in the source', ()=>{
|
|
183
|
+
const source = JSON.parse('{"a": {"__proto__": {"isAdmin": true}}}');
|
|
184
|
+
const result = deepMerge({}, source);
|
|
185
|
+
expect(Object.getPrototypeOf(result.a)).toBe(Object.prototype);
|
|
186
|
+
expect(result.a.isAdmin).toBeUndefined();
|
|
187
|
+
});
|
|
188
|
+
it('should not poison the prototype via a __proto__ key inside array items', ()=>{
|
|
189
|
+
const source = JSON.parse('{"list": [{"__proto__": {"isAdmin": true}}]}');
|
|
190
|
+
const result = deepMerge({
|
|
191
|
+
list: []
|
|
192
|
+
}, source);
|
|
193
|
+
expect(Object.getPrototypeOf(result.list[0])).toBe(Object.prototype);
|
|
194
|
+
expect(result.list[0].isAdmin).toBeUndefined();
|
|
195
|
+
});
|
|
196
|
+
it('should not mutate the passed options object', ()=>{
|
|
197
|
+
const options = {
|
|
198
|
+
clone: true
|
|
199
|
+
};
|
|
200
|
+
deepMerge({
|
|
201
|
+
a: [
|
|
202
|
+
1
|
|
203
|
+
]
|
|
204
|
+
}, {
|
|
205
|
+
a: [
|
|
206
|
+
2
|
|
207
|
+
]
|
|
208
|
+
}, options);
|
|
209
|
+
expect(options).toStrictEqual({
|
|
210
|
+
clone: true
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
it('should not clone React 18 or React 19 elements', ()=>{
|
|
214
|
+
const react18Element = {
|
|
215
|
+
$$typeof: Symbol.for('react.element'),
|
|
216
|
+
props: {}
|
|
217
|
+
};
|
|
218
|
+
const react19Element = {
|
|
219
|
+
$$typeof: Symbol.for('react.transitional.element'),
|
|
220
|
+
props: {}
|
|
221
|
+
};
|
|
222
|
+
const result = deepMerge({}, {
|
|
223
|
+
react18: react18Element,
|
|
224
|
+
react19: react19Element
|
|
225
|
+
});
|
|
226
|
+
expect(result.react18).toBe(react18Element);
|
|
227
|
+
expect(result.react19).toBe(react19Element);
|
|
228
|
+
});
|
|
229
|
+
it('should accept the signatures of the former deepmerge dependency', ()=>{
|
|
230
|
+
const isMergeableObject = (value)=>Object.prototype.toString.call(value) === '[object Object]';
|
|
231
|
+
const options = {
|
|
232
|
+
isMergeableObject
|
|
233
|
+
};
|
|
234
|
+
const arrayMergeOptions = {
|
|
235
|
+
cloneUnlessOtherwiseSpecified: (value)=>value,
|
|
236
|
+
isMergeableObject
|
|
237
|
+
};
|
|
238
|
+
const merged = deepMerge.all([
|
|
239
|
+
{
|
|
240
|
+
a: 1
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
b: 'b'
|
|
244
|
+
}
|
|
245
|
+
], options);
|
|
246
|
+
const typed = deepMerge.all([
|
|
247
|
+
{
|
|
248
|
+
a: 1
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
b: 'b'
|
|
252
|
+
}
|
|
253
|
+
]);
|
|
254
|
+
expect(merged).toStrictEqual({
|
|
255
|
+
a: 1,
|
|
256
|
+
b: 'b'
|
|
257
|
+
});
|
|
258
|
+
expect(typed.b).toBe('b');
|
|
259
|
+
expect(arrayMergeOptions.cloneUnlessOtherwiseSpecified(merged)).toBe(merged);
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
describe('deepMergeWithSourceArrays', ()=>{
|
|
263
|
+
it('should replace target arrays with source arrays', ()=>{
|
|
264
|
+
const result = deepMergeWithSourceArrays({
|
|
265
|
+
list: [
|
|
266
|
+
1,
|
|
267
|
+
2
|
|
268
|
+
],
|
|
269
|
+
keep: true
|
|
270
|
+
}, {
|
|
271
|
+
list: [
|
|
272
|
+
3
|
|
273
|
+
]
|
|
274
|
+
});
|
|
275
|
+
expect(result).toStrictEqual({
|
|
276
|
+
keep: true,
|
|
277
|
+
list: [
|
|
278
|
+
3
|
|
279
|
+
]
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
describe('deepMergeWithCombinedArrays', ()=>{
|
|
284
|
+
it('should merge array items by index and append new primitives', ()=>{
|
|
285
|
+
const result = deepMergeWithCombinedArrays({
|
|
286
|
+
list: [
|
|
287
|
+
{
|
|
288
|
+
a: 1
|
|
289
|
+
},
|
|
290
|
+
'x'
|
|
291
|
+
]
|
|
292
|
+
}, {
|
|
293
|
+
list: [
|
|
294
|
+
{
|
|
295
|
+
b: 2
|
|
296
|
+
},
|
|
297
|
+
'y',
|
|
298
|
+
'z'
|
|
299
|
+
]
|
|
300
|
+
});
|
|
301
|
+
expect(result).toStrictEqual({
|
|
302
|
+
list: [
|
|
303
|
+
{
|
|
304
|
+
a: 1,
|
|
305
|
+
b: 2
|
|
306
|
+
},
|
|
307
|
+
'x',
|
|
308
|
+
'y',
|
|
309
|
+
'z'
|
|
310
|
+
]
|
|
311
|
+
});
|
|
312
|
+
});
|
|
313
|
+
});
|
|
314
|
+
describe('deepMergeWithReactComponents', ()=>{
|
|
315
|
+
it('should not clone functions', ()=>{
|
|
316
|
+
const Component = ()=>null;
|
|
317
|
+
const result = deepMergeWithReactComponents({
|
|
318
|
+
admin: {
|
|
319
|
+
components: {}
|
|
320
|
+
}
|
|
321
|
+
}, {
|
|
322
|
+
admin: {
|
|
323
|
+
components: {
|
|
324
|
+
Field: Component
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
expect(result.admin.components.Field).toBe(Component);
|
|
329
|
+
});
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
//# sourceMappingURL=deepMerge.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/deepMerge.spec.ts"],"sourcesContent":["import { describe, expect, it } from 'vitest'\n\nimport {\n deepMerge,\n deepMergeWithCombinedArrays,\n deepMergeWithReactComponents,\n deepMergeWithSourceArrays,\n} from './deepMerge.js'\n\ndescribe('deepMerge', () => {\n it('should deeply merge nested objects with source taking precedence', () => {\n const result = deepMerge<Record<string, unknown>>(\n { a: { b: 1, c: 2 }, d: 1 },\n { a: { c: 3, e: 4 }, f: 5 },\n )\n\n expect(result).toStrictEqual({ a: { b: 1, c: 3, e: 4 }, d: 1, f: 5 })\n })\n\n it('should not mutate its arguments and should clone nested values', () => {\n const target = { nested: { value: 1 } }\n const source = { other: { value: 2 } }\n\n const result = deepMerge<Record<string, any>>(target, source)\n\n expect(target).toStrictEqual({ nested: { value: 1 } })\n expect(source).toStrictEqual({ other: { value: 2 } })\n expect(result.nested).not.toBe(target.nested)\n expect(result.other).not.toBe(source.other)\n })\n\n it('should keep references when clone is false', () => {\n const nested = { value: 1 }\n\n const result = deepMerge<Record<string, any>>({}, { nested }, { clone: false })\n\n expect(result.nested).toBe(nested)\n })\n\n it('should concatenate arrays by default', () => {\n const result = deepMerge<Record<string, unknown>>({ list: [1, 2] }, { list: [3] })\n\n expect(result).toStrictEqual({ list: [1, 2, 3] })\n })\n\n it('should not deeply merge dates and regular expressions', () => {\n const date = new Date()\n const regex = /test/\n\n const result = deepMerge<Record<string, unknown>>({ date: {}, regex: {} }, { date, regex })\n\n expect(result.date).toBe(date)\n expect(result.regex).toBe(regex)\n })\n\n it('should merge enumerable symbol keys', () => {\n const symbol = Symbol('key')\n\n const result = deepMerge<Record<symbol, unknown>>(\n { [symbol]: { a: 1 } },\n { [symbol]: { b: 2 } },\n )\n\n expect(result[symbol]).toStrictEqual({ a: 1, b: 2 })\n })\n\n it('should use customMerge for matching keys', () => {\n const result = deepMerge<Record<string, unknown>>(\n { a: { x: 1 }, b: { x: 1 } },\n { a: { y: 2 }, b: { y: 2 } },\n { customMerge: (key) => (key === 'a' ? (_x, y) => y : undefined) },\n )\n\n expect(result).toStrictEqual({ a: { y: 2 }, b: { x: 1, y: 2 } })\n })\n\n it('should merge all objects with deepMerge.all', () => {\n const result = deepMerge.all<Record<string, unknown>>([\n { a: { x: 1 } },\n { a: { y: 2 } },\n { b: 3 },\n ])\n\n expect(result).toStrictEqual({ a: { x: 1, y: 2 }, b: 3 })\n })\n\n it('should not poison the prototype of the result via a __proto__ key in the source', () => {\n const target = JSON.parse('{\"__proto__\": {}}')\n const source = JSON.parse('{\"__proto__\": {\"isAdmin\": true}}')\n\n const result = deepMerge<Record<string, unknown>>(target, source)\n\n expect(Object.getPrototypeOf(result)).toBe(Object.prototype)\n expect(result.isAdmin).toBeUndefined()\n })\n\n it('should not poison the prototype of the result via a __proto__ key in the target', () => {\n const target = JSON.parse('{\"__proto__\": {\"isAdmin\": true}}')\n\n const result = deepMerge<Record<string, unknown>>(target, {})\n\n expect(Object.getPrototypeOf(result)).toBe(Object.prototype)\n expect(result.isAdmin).toBeUndefined()\n })\n\n it('should not pollute Object.prototype via constructor.prototype', () => {\n const source = JSON.parse('{\"constructor\": {\"prototype\": {\"polluted\": true}}}')\n\n deepMerge({}, source)\n\n expect(({} as Record<string, unknown>).polluted).toBeUndefined()\n })\n\n it('should not poison the prototype via a nested __proto__ key that only exists in the source', () => {\n const source = JSON.parse('{\"a\": {\"__proto__\": {\"isAdmin\": true}}}')\n\n const result = deepMerge<Record<string, any>>({}, source)\n\n expect(Object.getPrototypeOf(result.a)).toBe(Object.prototype)\n expect(result.a.isAdmin).toBeUndefined()\n })\n\n it('should not poison the prototype via a __proto__ key inside array items', () => {\n const source = JSON.parse('{\"list\": [{\"__proto__\": {\"isAdmin\": true}}]}')\n\n const result = deepMerge<Record<string, any>>({ list: [] }, source)\n\n expect(Object.getPrototypeOf(result.list[0])).toBe(Object.prototype)\n expect(result.list[0].isAdmin).toBeUndefined()\n })\n\n it('should not mutate the passed options object', () => {\n const options: deepMerge.Options = { clone: true }\n\n deepMerge({ a: [1] }, { a: [2] }, options)\n\n expect(options).toStrictEqual({ clone: true })\n })\n\n it('should not clone React 18 or React 19 elements', () => {\n const react18Element = { $$typeof: Symbol.for('react.element'), props: {} }\n const react19Element = { $$typeof: Symbol.for('react.transitional.element'), props: {} }\n\n const result = deepMerge<Record<string, unknown>>(\n {},\n { react18: react18Element, react19: react19Element },\n )\n\n expect(result.react18).toBe(react18Element)\n expect(result.react19).toBe(react19Element)\n })\n\n it('should accept the signatures of the former deepmerge dependency', () => {\n const isMergeableObject = (value: object) =>\n Object.prototype.toString.call(value) === '[object Object]'\n const options: deepMerge.Options = { isMergeableObject }\n const arrayMergeOptions: deepMerge.ArrayMergeOptions = {\n cloneUnlessOtherwiseSpecified: (value: object): object => value,\n isMergeableObject,\n }\n\n const merged: object = deepMerge.all([{ a: 1 }, { b: 'b' }], options)\n const typed = deepMerge.all<{ a: number; b: string }>([{ a: 1 }, { b: 'b' }])\n\n expect(merged).toStrictEqual({ a: 1, b: 'b' })\n expect(typed.b).toBe('b')\n expect(arrayMergeOptions.cloneUnlessOtherwiseSpecified(merged)).toBe(merged)\n })\n})\n\ndescribe('deepMergeWithSourceArrays', () => {\n it('should replace target arrays with source arrays', () => {\n const result = deepMergeWithSourceArrays<Record<string, unknown>>(\n { list: [1, 2], keep: true },\n { list: [3] },\n )\n\n expect(result).toStrictEqual({ keep: true, list: [3] })\n })\n})\n\ndescribe('deepMergeWithCombinedArrays', () => {\n it('should merge array items by index and append new primitives', () => {\n const result = deepMergeWithCombinedArrays<Record<string, unknown>>(\n { list: [{ a: 1 }, 'x'] },\n { list: [{ b: 2 }, 'y', 'z'] },\n )\n\n expect(result).toStrictEqual({ list: [{ a: 1, b: 2 }, 'x', 'y', 'z'] })\n })\n})\n\ndescribe('deepMergeWithReactComponents', () => {\n it('should not clone functions', () => {\n const Component = () => null\n\n const result = deepMergeWithReactComponents<Record<string, unknown>>(\n { admin: { components: {} } },\n { admin: { components: { Field: Component } } },\n )\n\n expect((result.admin as any).components.Field).toBe(Component)\n })\n})\n"],"names":["describe","expect","it","deepMerge","deepMergeWithCombinedArrays","deepMergeWithReactComponents","deepMergeWithSourceArrays","result","a","b","c","d","e","f","toStrictEqual","target","nested","value","source","other","not","toBe","clone","list","date","Date","regex","symbol","Symbol","x","y","customMerge","key","_x","undefined","all","JSON","parse","Object","getPrototypeOf","prototype","isAdmin","toBeUndefined","polluted","options","react18Element","$$typeof","for","props","react19Element","react18","react19","isMergeableObject","toString","call","arrayMergeOptions","cloneUnlessOtherwiseSpecified","merged","typed","keep","Component","admin","components","Field"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAQ;AAE7C,SACEC,SAAS,EACTC,2BAA2B,EAC3BC,4BAA4B,EAC5BC,yBAAyB,QACpB,iBAAgB;AAEvBN,SAAS,aAAa;IACpBE,GAAG,oEAAoE;QACrE,MAAMK,SAASJ,UACb;YAAEK,GAAG;gBAAEC,GAAG;gBAAGC,GAAG;YAAE;YAAGC,GAAG;QAAE,GAC1B;YAAEH,GAAG;gBAAEE,GAAG;gBAAGE,GAAG;YAAE;YAAGC,GAAG;QAAE;QAG5BZ,OAAOM,QAAQO,aAAa,CAAC;YAAEN,GAAG;gBAAEC,GAAG;gBAAGC,GAAG;gBAAGE,GAAG;YAAE;YAAGD,GAAG;YAAGE,GAAG;QAAE;IACrE;IAEAX,GAAG,kEAAkE;QACnE,MAAMa,SAAS;YAAEC,QAAQ;gBAAEC,OAAO;YAAE;QAAE;QACtC,MAAMC,SAAS;YAAEC,OAAO;gBAAEF,O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AG;gBAAE;gBAAG;gBAAK;aAAI;QAAC;QAG/BR,OAAOM,QAAQO,aAAa,CAAC;YAAES,MAAM;gBAAC;oBAAEf,GAAG;oBAAGC,GAAG;gBAAE;gBAAG;gBAAK;gBAAK;aAAI;QAAC;IACvE;AACF;AAEAT,SAAS,gCAAgC;IACvCE,GAAG,8BAA8B;QAC/B,MAAM0D,YAAY,IAAM;QAExB,MAAMrD,SAASF,6BACb;YAAEwD,OAAO;gBAAEC,YAAY,CAAC;YAAE;QAAE,GAC5B;YAAED,OAAO;gBAAEC,YAAY;oBAAEC,OAAOH;gBAAU;YAAE;QAAE;QAGhD3D,OAAO,AAACM,OAAOsD,KAAK,CAASC,UAAU,CAACC,KAAK,EAAE1C,IAAI,CAACuC;IACtD;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitizeUpdateData.d.ts","sourceRoot":"","sources":["../../src/utilities/sanitizeUpdateData.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,eAAO,MAAM,kBAAkB,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,YAAY;IAAE,IAAI,EAAE,CAAC,CAAA;CAAE,KAAG,CAQ7F,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Remove submitted top-level operators without traversing nested field values. */ export const sanitizeUpdateData = ({ data })=>{
|
|
2
|
+
for (const key of Object.keys(data)){
|
|
3
|
+
if (key.startsWith('$')) {
|
|
4
|
+
delete data[key];
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
return data;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=sanitizeUpdateData.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/sanitizeUpdateData.ts"],"sourcesContent":["/** Remove submitted top-level operators without traversing nested field values. */\nexport const sanitizeUpdateData = <T extends Record<string, unknown>>({ data }: { data: T }): T => {\n for (const key of Object.keys(data)) {\n if (key.startsWith('$')) {\n delete data[key]\n }\n }\n\n return data\n}\n"],"names":["sanitizeUpdateData","data","key","Object","keys","startsWith"],"mappings":"AAAA,iFAAiF,GACjF,OAAO,MAAMA,qBAAqB,CAAoC,EAAEC,IAAI,EAAe;IACzF,KAAK,MAAMC,OAAOC,OAAOC,IAAI,CAACH,MAAO;QACnC,IAAIC,IAAIG,UAAU,CAAC,MAAM;YACvB,OAAOJ,IAAI,CAACC,IAAI;QAClB;IACF;IAEA,OAAOD;AACT,EAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "payload",
|
|
3
|
-
"version": "3.94.
|
|
3
|
+
"version": "3.94.2",
|
|
4
4
|
"description": "Node, React, Headless CMS and Application Framework built on Next.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"admin panel",
|
|
@@ -87,7 +87,7 @@
|
|
|
87
87
|
],
|
|
88
88
|
"dependencies": {
|
|
89
89
|
"@next/env": "^15.1.5",
|
|
90
|
-
"@payloadcms/translations": "3.94.
|
|
90
|
+
"@payloadcms/translations": "3.94.2",
|
|
91
91
|
"@types/busboy": "1.5.4",
|
|
92
92
|
"ajv": "8.18.0",
|
|
93
93
|
"bson-objectid": "2.0.4",
|
|
@@ -96,7 +96,6 @@
|
|
|
96
96
|
"console-table-printer": "2.12.1",
|
|
97
97
|
"croner": "10.0.1",
|
|
98
98
|
"dataloader": "2.2.3",
|
|
99
|
-
"deepmerge": "4.3.1",
|
|
100
99
|
"file-type": "21.3.4",
|
|
101
100
|
"get-tsconfig": "4.8.1",
|
|
102
101
|
"http-status": "2.1.0",
|