@fourlights/strapi-plugin-deep-populate 1.8.0 → 1.9.1-rc.0
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/server/index.js
CHANGED
|
@@ -23,6 +23,7 @@ require("node:stream");
|
|
|
23
23
|
const cloneDeep = require("lodash/cloneDeep");
|
|
24
24
|
const unset = require("lodash/unset");
|
|
25
25
|
const get = require("lodash/get");
|
|
26
|
+
const merge$2 = require("lodash/merge");
|
|
26
27
|
const mergeWith = require("lodash/mergeWith");
|
|
27
28
|
const set$2 = require("lodash/set");
|
|
28
29
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
@@ -48,6 +49,7 @@ const require$$0__default$7 = /* @__PURE__ */ _interopDefault(require$$0$8);
|
|
|
48
49
|
const cloneDeep__default = /* @__PURE__ */ _interopDefault(cloneDeep);
|
|
49
50
|
const unset__default = /* @__PURE__ */ _interopDefault(unset);
|
|
50
51
|
const get__default = /* @__PURE__ */ _interopDefault(get);
|
|
52
|
+
const merge__default = /* @__PURE__ */ _interopDefault(merge$2);
|
|
51
53
|
const mergeWith__default = /* @__PURE__ */ _interopDefault(mergeWith);
|
|
52
54
|
const set__default = /* @__PURE__ */ _interopDefault(set$2);
|
|
53
55
|
const config$1 = {
|
|
@@ -18549,6 +18551,20 @@ const cache = ({ strapi: strapi2 }) => ({
|
|
|
18549
18551
|
}
|
|
18550
18552
|
}
|
|
18551
18553
|
});
|
|
18554
|
+
const sanitizeObject = (obj) => {
|
|
18555
|
+
if (obj === null || typeof obj !== "object") return obj;
|
|
18556
|
+
const dangerousProps = ["__proto__", "constructor", "prototype"];
|
|
18557
|
+
const sanitized = {};
|
|
18558
|
+
for (const key in obj) {
|
|
18559
|
+
if (dangerousProps.includes(key)) continue;
|
|
18560
|
+
if (typeof obj[key] === "object" && ___default.isNil(obj[key])) {
|
|
18561
|
+
sanitized[key] = sanitizeObject(obj[key]);
|
|
18562
|
+
} else {
|
|
18563
|
+
sanitized[key] = obj[key];
|
|
18564
|
+
}
|
|
18565
|
+
}
|
|
18566
|
+
return sanitized;
|
|
18567
|
+
};
|
|
18552
18568
|
const getRelations = (model) => {
|
|
18553
18569
|
const filteredAttributes = /* @__PURE__ */ new Set();
|
|
18554
18570
|
const { populateCreatorFields } = getOptions(model);
|
|
@@ -18616,7 +18632,9 @@ async function _populateDynamicZone({
|
|
|
18616
18632
|
inDynamicZone: true,
|
|
18617
18633
|
...params
|
|
18618
18634
|
});
|
|
18619
|
-
|
|
18635
|
+
const currentPopulate = get__default.default(resolvedPopulate, [component]);
|
|
18636
|
+
const mergedComponentPopulate = !currentPopulate && componentPopulate === true ? componentPopulate : merge__default.default({}, currentPopulate, sanitizeObject(componentPopulate));
|
|
18637
|
+
set__default.default(resolvedPopulate, [component], mergedComponentPopulate);
|
|
18620
18638
|
}
|
|
18621
18639
|
if (isEmpty(resolvedPopulate)) return void 0;
|
|
18622
18640
|
return { on: resolvedPopulate };
|
|
@@ -18648,7 +18666,7 @@ async function _populateRelation({
|
|
|
18648
18666
|
}
|
|
18649
18667
|
const newPopulate = {};
|
|
18650
18668
|
for (const { documentId } of relations) {
|
|
18651
|
-
const relationPopulate = resolvedRelations.get(documentId);
|
|
18669
|
+
const relationPopulate = sanitizeObject(resolvedRelations.get(documentId));
|
|
18652
18670
|
mergeWith__default.default(newPopulate, relationPopulate, (existing, proposed) => {
|
|
18653
18671
|
if (proposed === true && existing) return existing;
|
|
18654
18672
|
return void 0;
|
|
@@ -18667,17 +18685,17 @@ const _resolveValue = ({ document: document2, lookup, attrName }) => {
|
|
|
18667
18685
|
throw Error("Nested dynamic zones are not supported");
|
|
18668
18686
|
}
|
|
18669
18687
|
const dynamicZoneValue = dynamicZoneLookup.length === 0 ? document2 : get__default.default(document2, dynamicZoneLookup, []);
|
|
18670
|
-
const componentValue = dynamicZoneValue.filter((b) => b.__component === dynamicZoneComponent).
|
|
18671
|
-
return (Array.isArray(componentValue) ? componentValue : [componentValue]).
|
|
18688
|
+
const componentValue = dynamicZoneValue.filter((b) => b.__component === dynamicZoneComponent).flatMap((c) => _resolveValue({ document: c, lookup: componentLookup, attrName }));
|
|
18689
|
+
return (Array.isArray(componentValue) ? componentValue : [componentValue]).filter((v) => hasValue(v));
|
|
18672
18690
|
}
|
|
18673
18691
|
if (populateIdx !== -1) {
|
|
18674
18692
|
const parentLookup = lookup.slice(0, populateIdx);
|
|
18675
18693
|
const childLookup = lookup.slice(populateIdx + 1, lookup.length);
|
|
18676
18694
|
const parentValue2 = parentLookup.length === 0 ? document2 : get__default.default(document2, parentLookup);
|
|
18677
|
-
const childValue = (Array.isArray(parentValue2) ? parentValue2 : [parentValue2]).
|
|
18695
|
+
const childValue = (Array.isArray(parentValue2) ? parentValue2 : [parentValue2]).flatMap(
|
|
18678
18696
|
(v) => _resolveValue({ document: v, lookup: childLookup, attrName })
|
|
18679
18697
|
);
|
|
18680
|
-
return childValue.
|
|
18698
|
+
return childValue.filter((v) => hasValue(v));
|
|
18681
18699
|
}
|
|
18682
18700
|
const parentValue = lookup.length === 0 ? document2 : get__default.default(document2, lookup);
|
|
18683
18701
|
if (Array.isArray(parentValue)) {
|
|
@@ -18819,7 +18837,7 @@ async function populate$1(params) {
|
|
|
18819
18837
|
const { omitEmpty, localizations, contentTypes: contentTypes2 } = strapi.config.get("plugin::deep-populate");
|
|
18820
18838
|
const contentTypeConfig = has__default.default(contentTypes2, "*") ? get__default.default(contentTypes2, "*") : {};
|
|
18821
18839
|
if (has__default.default(contentTypes2, params.contentType)) {
|
|
18822
|
-
mergeWith__default.default(contentTypeConfig, get__default.default(contentTypes2, params.contentType));
|
|
18840
|
+
mergeWith__default.default(contentTypeConfig, sanitizeObject(get__default.default(contentTypes2, params.contentType)));
|
|
18823
18841
|
}
|
|
18824
18842
|
const { allow, deny } = contentTypeConfig;
|
|
18825
18843
|
const resolvedRelations = /* @__PURE__ */ new Map();
|
package/dist/server/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import isEmpty$1 from "lodash/isEmpty";
|
|
2
2
|
import isObject$2 from "lodash/isObject";
|
|
3
|
-
import ___default from "lodash";
|
|
3
|
+
import ___default, { isNil as isNil$1 } from "lodash";
|
|
4
4
|
import { union as union$1, getOr, curry, isObject as isObject$3, isNil, clone as clone$2, isArray, pick as pick$1, isEmpty as isEmpty$2, cloneDeep, omit as omit$1, isString, trim as trim$1, pipe as pipe$2, split, map as map$2, flatten, first, constant, identity, join, eq, get } from "lodash/fp";
|
|
5
5
|
import require$$1 from "crypto";
|
|
6
6
|
import require$$0$1 from "child_process";
|
|
@@ -22,6 +22,7 @@ import "node:stream";
|
|
|
22
22
|
import cloneDeep$1 from "lodash/cloneDeep";
|
|
23
23
|
import unset from "lodash/unset";
|
|
24
24
|
import get$1 from "lodash/get";
|
|
25
|
+
import merge$2 from "lodash/merge";
|
|
25
26
|
import mergeWith from "lodash/mergeWith";
|
|
26
27
|
import set$2 from "lodash/set";
|
|
27
28
|
const config$1 = {
|
|
@@ -18523,6 +18524,20 @@ const cache = ({ strapi: strapi2 }) => ({
|
|
|
18523
18524
|
}
|
|
18524
18525
|
}
|
|
18525
18526
|
});
|
|
18527
|
+
const sanitizeObject = (obj) => {
|
|
18528
|
+
if (obj === null || typeof obj !== "object") return obj;
|
|
18529
|
+
const dangerousProps = ["__proto__", "constructor", "prototype"];
|
|
18530
|
+
const sanitized = {};
|
|
18531
|
+
for (const key in obj) {
|
|
18532
|
+
if (dangerousProps.includes(key)) continue;
|
|
18533
|
+
if (typeof obj[key] === "object" && isNil$1(obj[key])) {
|
|
18534
|
+
sanitized[key] = sanitizeObject(obj[key]);
|
|
18535
|
+
} else {
|
|
18536
|
+
sanitized[key] = obj[key];
|
|
18537
|
+
}
|
|
18538
|
+
}
|
|
18539
|
+
return sanitized;
|
|
18540
|
+
};
|
|
18526
18541
|
const getRelations = (model) => {
|
|
18527
18542
|
const filteredAttributes = /* @__PURE__ */ new Set();
|
|
18528
18543
|
const { populateCreatorFields } = getOptions(model);
|
|
@@ -18590,7 +18605,9 @@ async function _populateDynamicZone({
|
|
|
18590
18605
|
inDynamicZone: true,
|
|
18591
18606
|
...params
|
|
18592
18607
|
});
|
|
18593
|
-
|
|
18608
|
+
const currentPopulate = get$1(resolvedPopulate, [component]);
|
|
18609
|
+
const mergedComponentPopulate = !currentPopulate && componentPopulate === true ? componentPopulate : merge$2({}, currentPopulate, sanitizeObject(componentPopulate));
|
|
18610
|
+
set$2(resolvedPopulate, [component], mergedComponentPopulate);
|
|
18594
18611
|
}
|
|
18595
18612
|
if (isEmpty(resolvedPopulate)) return void 0;
|
|
18596
18613
|
return { on: resolvedPopulate };
|
|
@@ -18622,7 +18639,7 @@ async function _populateRelation({
|
|
|
18622
18639
|
}
|
|
18623
18640
|
const newPopulate = {};
|
|
18624
18641
|
for (const { documentId } of relations) {
|
|
18625
|
-
const relationPopulate = resolvedRelations.get(documentId);
|
|
18642
|
+
const relationPopulate = sanitizeObject(resolvedRelations.get(documentId));
|
|
18626
18643
|
mergeWith(newPopulate, relationPopulate, (existing, proposed) => {
|
|
18627
18644
|
if (proposed === true && existing) return existing;
|
|
18628
18645
|
return void 0;
|
|
@@ -18641,17 +18658,17 @@ const _resolveValue = ({ document: document2, lookup, attrName }) => {
|
|
|
18641
18658
|
throw Error("Nested dynamic zones are not supported");
|
|
18642
18659
|
}
|
|
18643
18660
|
const dynamicZoneValue = dynamicZoneLookup.length === 0 ? document2 : get$1(document2, dynamicZoneLookup, []);
|
|
18644
|
-
const componentValue = dynamicZoneValue.filter((b) => b.__component === dynamicZoneComponent).
|
|
18645
|
-
return (Array.isArray(componentValue) ? componentValue : [componentValue]).
|
|
18661
|
+
const componentValue = dynamicZoneValue.filter((b) => b.__component === dynamicZoneComponent).flatMap((c) => _resolveValue({ document: c, lookup: componentLookup, attrName }));
|
|
18662
|
+
return (Array.isArray(componentValue) ? componentValue : [componentValue]).filter((v) => hasValue(v));
|
|
18646
18663
|
}
|
|
18647
18664
|
if (populateIdx !== -1) {
|
|
18648
18665
|
const parentLookup = lookup.slice(0, populateIdx);
|
|
18649
18666
|
const childLookup = lookup.slice(populateIdx + 1, lookup.length);
|
|
18650
18667
|
const parentValue2 = parentLookup.length === 0 ? document2 : get$1(document2, parentLookup);
|
|
18651
|
-
const childValue = (Array.isArray(parentValue2) ? parentValue2 : [parentValue2]).
|
|
18668
|
+
const childValue = (Array.isArray(parentValue2) ? parentValue2 : [parentValue2]).flatMap(
|
|
18652
18669
|
(v) => _resolveValue({ document: v, lookup: childLookup, attrName })
|
|
18653
18670
|
);
|
|
18654
|
-
return childValue.
|
|
18671
|
+
return childValue.filter((v) => hasValue(v));
|
|
18655
18672
|
}
|
|
18656
18673
|
const parentValue = lookup.length === 0 ? document2 : get$1(document2, lookup);
|
|
18657
18674
|
if (Array.isArray(parentValue)) {
|
|
@@ -18793,7 +18810,7 @@ async function populate$1(params) {
|
|
|
18793
18810
|
const { omitEmpty, localizations, contentTypes: contentTypes2 } = strapi.config.get("plugin::deep-populate");
|
|
18794
18811
|
const contentTypeConfig = has(contentTypes2, "*") ? get$1(contentTypes2, "*") : {};
|
|
18795
18812
|
if (has(contentTypes2, params.contentType)) {
|
|
18796
|
-
mergeWith(contentTypeConfig, get$1(contentTypes2, params.contentType));
|
|
18813
|
+
mergeWith(contentTypeConfig, sanitizeObject(get$1(contentTypes2, params.contentType)));
|
|
18797
18814
|
}
|
|
18798
18815
|
const { allow, deny } = contentTypeConfig;
|
|
18799
18816
|
const resolvedRelations = /* @__PURE__ */ new Map();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const sanitizeObject: (obj: unknown) => unknown;
|
package/package.json
CHANGED