Compare commits

...

14 Commits
v1.1.0 ... main

Author SHA1 Message Date
Christofer Jungberg
7847cfcb1e set version 2023-11-05 21:38:08 +01:00
Christofer Jungberg
1175a82011
Merge pull request #40 from chohner/patch-2 2023-10-10 11:20:53 +02:00
chris
3634208405
Support Node v20 2023-08-27 14:44:52 +02:00
Christofer Jungberg
85a9a7ad61
Merge pull request #36 from ChrisKru97/main
fix: self-recursion
2023-07-25 18:56:19 +02:00
chk97
94e7c70660 fix: self-recursion 2023-06-05 13:30:55 +00:00
Christofer Jungberg
b1809e0e1c 2.0.0 2023-01-17 12:58:57 +01:00
Christofer Jungberg
403a510e0e
Merge pull request #27 from chohner/patch-1
Add node v18 support
2023-01-17 12:57:00 +01:00
chris
25ff082461
Add node v18 support
Node 18 is supported in strapi since https://github.com/strapi/strapi/pull/14350
This updates the corresponding node engine to supported the same range
2023-01-02 15:48:40 +01:00
Christofer Jungberg
5bb823f3e5 1.1.2 2022-10-25 23:10:50 +02:00
Christofer Jungberg
b560e3a15d fixed creator field config 2022-10-25 23:10:36 +02:00
Christofer Jungberg
83ee0a4187 1.1.1 2022-10-25 23:01:58 +02:00
Christofer Jungberg
bcc4c4ebbf Merge branch 'feature/plugin-config' into main 2022-10-25 23:00:50 +02:00
Christofer Jungberg
a111f49032 fixed plugin name 2022-10-25 22:56:01 +02:00
Christofer Jungberg
560b68fd57
Merge pull request #21 from Barelydead/feature/plugin-config
configure depth and creator fields
2022-10-25 22:03:42 +02:00
5 changed files with 17 additions and 16 deletions

View File

@ -32,7 +32,7 @@ The populate deep option is available for all collections and single types using
# Configuration # Configuration
The default depth and behaviour for populating creator fields can be customized via the plugin config. To do so create or edit you plugins.js file. The default depth can be customized via the plugin config. To do so create or edit you plugins.js file.
## Example configuration ## Example configuration
@ -40,11 +40,9 @@ The default depth and behaviour for populating creator fields can be customized
``` ```
module.exports = ({ env }) => ({ module.exports = ({ env }) => ({
'populate-deep': { 'strapi-plugin-populate-deep': {
enabled: true,
config: { config: {
defaultDepth: 3, // Default is 5 defaultDepth: 3, // Default is 5
skipCreatorFields: false, // Default is true
} }
}, },
}); });

4
package-lock.json generated
View File

@ -1,5 +1,5 @@
{ {
"name": "strapi-plugin-populate-deep", "name": "strapi-plugin-populate-deep",
"version": "1.1.0", "version": "3.0.1",
"lockfileVersion": 1 "lockfileVersion": 1
} }

View File

@ -1,7 +1,7 @@
{ {
"name": "strapi-plugin-populate-deep", "name": "strapi-plugin-populate-deep",
"version": "1.1.0", "version": "3.0.1",
"description": "This is the description of the plugin.", "description": "Strapi plugin that populates nested content.",
"strapi": { "strapi": {
"name": "strapi-plugin-populate-deep", "name": "strapi-plugin-populate-deep",
"description": "Api helper to populate deep content structures.", "description": "Api helper to populate deep content structures.",
@ -21,8 +21,8 @@
"url": "https://github.com/Barelydead/strapi-plugin-deep-populate" "url": "https://github.com/Barelydead/strapi-plugin-deep-populate"
}, },
"engines": { "engines": {
"node": ">=12.x.x <=16.x.x", "node": ">=14.19.1 <=20.x.x",
"npm": ">=6.0.0" "npm": ">=6.0.0"
}, },
"license": "MIT" "license": "MIT"
} }

4
server/bootstrap.js vendored
View File

@ -6,11 +6,11 @@ module.exports = ({ strapi }) => {
strapi.db.lifecycles.subscribe((event) => { strapi.db.lifecycles.subscribe((event) => {
if (event.action === 'beforeFindMany' || event.action === 'beforeFindOne') { if (event.action === 'beforeFindMany' || event.action === 'beforeFindOne') {
const populate = event.params?.populate; const populate = event.params?.populate;
const defaultDepth = strapi.plugin('populate-deep')?.config('defaultDepth') || 5 const defaultDepth = strapi.plugin('strapi-plugin-populate-deep')?.config('defaultDepth') || 5
if (populate && populate[0] === 'deep') { if (populate && populate[0] === 'deep') {
const depth = populate[1] ?? defaultDepth const depth = populate[1] ?? defaultDepth
const modelObject = getFullPopulateObject(event.model.uid, depth); const modelObject = getFullPopulateObject(event.model.uid, depth, []);
event.params.populate = modelObject.populate event.params.populate = modelObject.populate
} }
} }

View File

@ -1,7 +1,5 @@
const { isEmpty, merge } = require("lodash/fp"); const { isEmpty, merge } = require("lodash/fp");
const skipCreatorFields = strapi.plugin('populate-deep')?.config('skipCreatorFields') || true;
const getModelPopulationAttributes = (model) => { const getModelPopulationAttributes = (model) => {
if (model.uid === "plugin::upload.file") { if (model.uid === "plugin::upload.file") {
const { related, ...attributes } = model.attributes; const { related, ...attributes } = model.attributes;
@ -11,7 +9,9 @@ const getModelPopulationAttributes = (model) => {
return model.attributes; return model.attributes;
}; };
const getFullPopulateObject = (modelUid, maxDepth = 20) => { const getFullPopulateObject = (modelUid, maxDepth = 20, ignore) => {
const skipCreatorFields = strapi.plugin('strapi-plugin-populate-deep')?.config('skipCreatorFields');
if (maxDepth <= 1) { if (maxDepth <= 1) {
return true; return true;
} }
@ -21,9 +21,11 @@ const getFullPopulateObject = (modelUid, maxDepth = 20) => {
const populate = {}; const populate = {};
const model = strapi.getModel(modelUid); const model = strapi.getModel(modelUid);
if (ignore && !ignore.includes(model.collectionName)) ignore.push(model.collectionName)
for (const [key, value] of Object.entries( for (const [key, value] of Object.entries(
getModelPopulationAttributes(model) getModelPopulationAttributes(model)
)) { )) {
if (ignore?.includes(key)) continue
if (value) { if (value) {
if (value.type === "component") { if (value.type === "component") {
populate[key] = getFullPopulateObject(value.component, maxDepth - 1); populate[key] = getFullPopulateObject(value.component, maxDepth - 1);
@ -36,7 +38,8 @@ const getFullPopulateObject = (modelUid, maxDepth = 20) => {
} else if (value.type === "relation") { } else if (value.type === "relation") {
const relationPopulate = getFullPopulateObject( const relationPopulate = getFullPopulateObject(
value.target, value.target,
(key === 'localizations') && maxDepth > 2 ? 1 : maxDepth - 1 (key === 'localizations') && maxDepth > 2 ? 1 : maxDepth - 1,
ignore
); );
if (relationPopulate) { if (relationPopulate) {
populate[key] = relationPopulate; populate[key] = relationPopulate;