@fourlights/strapi-plugin-deep-populate 1.1.0 → 1.1.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/server/index.js +29 -11
- package/dist/server/index.mjs +29 -11
- package/package.json +1 -1
package/dist/server/index.js
CHANGED
|
@@ -25078,6 +25078,7 @@ async function _populateComponent({
|
|
|
25078
25078
|
populate: populate2 = {},
|
|
25079
25079
|
lookup,
|
|
25080
25080
|
inDynamicZone = false,
|
|
25081
|
+
resolvedRelations,
|
|
25081
25082
|
omitEmpty
|
|
25082
25083
|
}) {
|
|
25083
25084
|
const attrName = lookup.pop();
|
|
@@ -25090,6 +25091,7 @@ async function _populateComponent({
|
|
|
25090
25091
|
schema: schema2,
|
|
25091
25092
|
populate: componentPopulate,
|
|
25092
25093
|
lookup: componentLookup,
|
|
25094
|
+
resolvedRelations,
|
|
25093
25095
|
omitEmpty
|
|
25094
25096
|
});
|
|
25095
25097
|
return isEmpty(nestedPopulate) ? true : { populate: nestedPopulate };
|
|
@@ -25100,6 +25102,7 @@ async function _populateDynamicZone({
|
|
|
25100
25102
|
components,
|
|
25101
25103
|
populate: populate2,
|
|
25102
25104
|
lookup,
|
|
25105
|
+
resolvedRelations,
|
|
25103
25106
|
omitEmpty
|
|
25104
25107
|
}) {
|
|
25105
25108
|
const resolvedPopulate = await components.reduce(async (prev, cur) => {
|
|
@@ -25110,6 +25113,7 @@ async function _populateDynamicZone({
|
|
|
25110
25113
|
populate: populate2,
|
|
25111
25114
|
lookup: [...lookup, cur],
|
|
25112
25115
|
inDynamicZone: true,
|
|
25116
|
+
resolvedRelations,
|
|
25113
25117
|
omitEmpty
|
|
25114
25118
|
});
|
|
25115
25119
|
const newPop = await prev;
|
|
@@ -25149,20 +25153,31 @@ async function _populateRelation({
|
|
|
25149
25153
|
return isEmpty(newPopulate) ? true : { populate: newPopulate };
|
|
25150
25154
|
}
|
|
25151
25155
|
const _resolveValue = ({ document: document2, lookup, attrName }) => {
|
|
25152
|
-
|
|
25153
|
-
|
|
25154
|
-
|
|
25155
|
-
const
|
|
25156
|
-
|
|
25157
|
-
|
|
25158
|
-
|
|
25159
|
-
|
|
25160
|
-
|
|
25161
|
-
|
|
25156
|
+
const dynamicZoneIdx = Array.isArray(lookup) ? lookup.findIndex((l) => l === "on") : -1;
|
|
25157
|
+
const populateIdx = Array.isArray(lookup) ? lookup.findIndex((l) => l === "populate") : -1;
|
|
25158
|
+
if (dynamicZoneIdx !== -1) {
|
|
25159
|
+
const dynamicZoneLookup = lookup.slice(0, dynamicZoneIdx);
|
|
25160
|
+
const dynamicZoneComponent = lookup[dynamicZoneIdx + 1];
|
|
25161
|
+
const componentLookup = lookup.slice(dynamicZoneIdx + 2);
|
|
25162
|
+
if (componentLookup.find((l) => l === "on")) {
|
|
25163
|
+
throw Error("Nested dynamic zones are not supported");
|
|
25164
|
+
}
|
|
25165
|
+
const dynamicZoneValue = delve__default.default(document2, dynamicZoneLookup) ?? [];
|
|
25166
|
+
const componentValue = dynamicZoneValue.filter((b) => b.__component === dynamicZoneComponent).map((c) => _resolveValue({ document: c, lookup: componentLookup, attrName }));
|
|
25167
|
+
return (Array.isArray(componentValue) ? componentValue : [componentValue]).find((v) => hasValue(v));
|
|
25168
|
+
}
|
|
25169
|
+
if (populateIdx !== -1) {
|
|
25170
|
+
const parentLookup = lookup.slice(0, populateIdx);
|
|
25171
|
+
const childLookup = lookup[populateIdx + 1];
|
|
25172
|
+
const parentValue2 = delve__default.default(document2, parentLookup);
|
|
25173
|
+
const childValue = (Array.isArray(parentValue2) ? parentValue2 : [parentValue2]).map(
|
|
25174
|
+
(v) => _resolveValue({ document: parentValue2, lookup: childLookup, attrName })
|
|
25175
|
+
);
|
|
25176
|
+
return childValue.find((v) => hasValue(v));
|
|
25162
25177
|
}
|
|
25163
25178
|
const parentValue = delve__default.default(document2, lookup);
|
|
25164
25179
|
if (Array.isArray(parentValue)) {
|
|
25165
|
-
return parentValue.map((v) => v[attrName]);
|
|
25180
|
+
return parentValue.map((v) => v[attrName]).filter((v) => hasValue(v));
|
|
25166
25181
|
}
|
|
25167
25182
|
return parentValue?.[attrName];
|
|
25168
25183
|
};
|
|
@@ -25208,11 +25223,13 @@ async function _populate({
|
|
|
25208
25223
|
mainDocumentId,
|
|
25209
25224
|
components: relComponents,
|
|
25210
25225
|
lookup: [...lookup, attrName],
|
|
25226
|
+
resolvedRelations,
|
|
25211
25227
|
omitEmpty
|
|
25212
25228
|
});
|
|
25213
25229
|
}
|
|
25214
25230
|
if (contentTypes.isRelationalAttribute(attr)) {
|
|
25215
25231
|
const { target: relContentType } = attr;
|
|
25232
|
+
resolvedRelations.set(mainDocumentId, true);
|
|
25216
25233
|
newPopulate[attrName] = await _populateRelation({
|
|
25217
25234
|
contentType: relContentType,
|
|
25218
25235
|
relation: value,
|
|
@@ -25226,6 +25243,7 @@ async function _populate({
|
|
|
25226
25243
|
mainDocumentId,
|
|
25227
25244
|
schema: attr.component,
|
|
25228
25245
|
lookup: [...lookup, attrName],
|
|
25246
|
+
resolvedRelations,
|
|
25229
25247
|
omitEmpty
|
|
25230
25248
|
});
|
|
25231
25249
|
}
|
package/dist/server/index.mjs
CHANGED
|
@@ -25064,6 +25064,7 @@ async function _populateComponent({
|
|
|
25064
25064
|
populate: populate2 = {},
|
|
25065
25065
|
lookup,
|
|
25066
25066
|
inDynamicZone = false,
|
|
25067
|
+
resolvedRelations,
|
|
25067
25068
|
omitEmpty
|
|
25068
25069
|
}) {
|
|
25069
25070
|
const attrName = lookup.pop();
|
|
@@ -25076,6 +25077,7 @@ async function _populateComponent({
|
|
|
25076
25077
|
schema: schema2,
|
|
25077
25078
|
populate: componentPopulate,
|
|
25078
25079
|
lookup: componentLookup,
|
|
25080
|
+
resolvedRelations,
|
|
25079
25081
|
omitEmpty
|
|
25080
25082
|
});
|
|
25081
25083
|
return isEmpty(nestedPopulate) ? true : { populate: nestedPopulate };
|
|
@@ -25086,6 +25088,7 @@ async function _populateDynamicZone({
|
|
|
25086
25088
|
components,
|
|
25087
25089
|
populate: populate2,
|
|
25088
25090
|
lookup,
|
|
25091
|
+
resolvedRelations,
|
|
25089
25092
|
omitEmpty
|
|
25090
25093
|
}) {
|
|
25091
25094
|
const resolvedPopulate = await components.reduce(async (prev, cur) => {
|
|
@@ -25096,6 +25099,7 @@ async function _populateDynamicZone({
|
|
|
25096
25099
|
populate: populate2,
|
|
25097
25100
|
lookup: [...lookup, cur],
|
|
25098
25101
|
inDynamicZone: true,
|
|
25102
|
+
resolvedRelations,
|
|
25099
25103
|
omitEmpty
|
|
25100
25104
|
});
|
|
25101
25105
|
const newPop = await prev;
|
|
@@ -25135,20 +25139,31 @@ async function _populateRelation({
|
|
|
25135
25139
|
return isEmpty(newPopulate) ? true : { populate: newPopulate };
|
|
25136
25140
|
}
|
|
25137
25141
|
const _resolveValue = ({ document: document2, lookup, attrName }) => {
|
|
25138
|
-
|
|
25139
|
-
|
|
25140
|
-
|
|
25141
|
-
const
|
|
25142
|
-
|
|
25143
|
-
|
|
25144
|
-
|
|
25145
|
-
|
|
25146
|
-
|
|
25147
|
-
|
|
25142
|
+
const dynamicZoneIdx = Array.isArray(lookup) ? lookup.findIndex((l) => l === "on") : -1;
|
|
25143
|
+
const populateIdx = Array.isArray(lookup) ? lookup.findIndex((l) => l === "populate") : -1;
|
|
25144
|
+
if (dynamicZoneIdx !== -1) {
|
|
25145
|
+
const dynamicZoneLookup = lookup.slice(0, dynamicZoneIdx);
|
|
25146
|
+
const dynamicZoneComponent = lookup[dynamicZoneIdx + 1];
|
|
25147
|
+
const componentLookup = lookup.slice(dynamicZoneIdx + 2);
|
|
25148
|
+
if (componentLookup.find((l) => l === "on")) {
|
|
25149
|
+
throw Error("Nested dynamic zones are not supported");
|
|
25150
|
+
}
|
|
25151
|
+
const dynamicZoneValue = delve(document2, dynamicZoneLookup) ?? [];
|
|
25152
|
+
const componentValue = dynamicZoneValue.filter((b) => b.__component === dynamicZoneComponent).map((c) => _resolveValue({ document: c, lookup: componentLookup, attrName }));
|
|
25153
|
+
return (Array.isArray(componentValue) ? componentValue : [componentValue]).find((v) => hasValue(v));
|
|
25154
|
+
}
|
|
25155
|
+
if (populateIdx !== -1) {
|
|
25156
|
+
const parentLookup = lookup.slice(0, populateIdx);
|
|
25157
|
+
const childLookup = lookup[populateIdx + 1];
|
|
25158
|
+
const parentValue2 = delve(document2, parentLookup);
|
|
25159
|
+
const childValue = (Array.isArray(parentValue2) ? parentValue2 : [parentValue2]).map(
|
|
25160
|
+
(v) => _resolveValue({ document: parentValue2, lookup: childLookup, attrName })
|
|
25161
|
+
);
|
|
25162
|
+
return childValue.find((v) => hasValue(v));
|
|
25148
25163
|
}
|
|
25149
25164
|
const parentValue = delve(document2, lookup);
|
|
25150
25165
|
if (Array.isArray(parentValue)) {
|
|
25151
|
-
return parentValue.map((v) => v[attrName]);
|
|
25166
|
+
return parentValue.map((v) => v[attrName]).filter((v) => hasValue(v));
|
|
25152
25167
|
}
|
|
25153
25168
|
return parentValue?.[attrName];
|
|
25154
25169
|
};
|
|
@@ -25194,11 +25209,13 @@ async function _populate({
|
|
|
25194
25209
|
mainDocumentId,
|
|
25195
25210
|
components: relComponents,
|
|
25196
25211
|
lookup: [...lookup, attrName],
|
|
25212
|
+
resolvedRelations,
|
|
25197
25213
|
omitEmpty
|
|
25198
25214
|
});
|
|
25199
25215
|
}
|
|
25200
25216
|
if (contentTypes.isRelationalAttribute(attr)) {
|
|
25201
25217
|
const { target: relContentType } = attr;
|
|
25218
|
+
resolvedRelations.set(mainDocumentId, true);
|
|
25202
25219
|
newPopulate[attrName] = await _populateRelation({
|
|
25203
25220
|
contentType: relContentType,
|
|
25204
25221
|
relation: value,
|
|
@@ -25212,6 +25229,7 @@ async function _populate({
|
|
|
25212
25229
|
mainDocumentId,
|
|
25213
25230
|
schema: attr.component,
|
|
25214
25231
|
lookup: [...lookup, attrName],
|
|
25232
|
+
resolvedRelations,
|
|
25215
25233
|
omitEmpty
|
|
25216
25234
|
});
|
|
25217
25235
|
}
|
package/package.json
CHANGED