strapi-plugin-populate-all 1.2.2 → 1.2.5
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/README.md +5 -2
- package/dist/server/index.js +5 -5
- package/dist/server/index.mjs +5 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Strapi Plugin Populate All
|
|
2
2
|
|
|
3
|
+
[](https://market.strapi.io/plugins/strapi-plugin-populate-all) [](https://www.npmjs.com/package/strapi-plugin-populate-all) [](https://github.com/faessler/strapi-plugin-populate-all/actions/workflows/test.yml)
|
|
4
|
+
|
|
3
5
|
A lightweight Strapi plugin that enables you to **recursively populate** all nested components, dynamic zones and relations in your REST API responses using a simple query parameter: `?populate=all`.
|
|
4
6
|
|
|
5
7
|
## Features
|
|
@@ -28,7 +30,7 @@ Add the following to your Strapi project's `config/plugins.js` (or `config/plugi
|
|
|
28
30
|
|
|
29
31
|
```js
|
|
30
32
|
module.exports = {
|
|
31
|
-
|
|
33
|
+
"populate-all": {
|
|
32
34
|
enabled: true,
|
|
33
35
|
config: {
|
|
34
36
|
// Populate all relations recursively (default)
|
|
@@ -38,7 +40,7 @@ module.exports = {
|
|
|
38
40
|
relations: false,
|
|
39
41
|
|
|
40
42
|
// OR: Only populate specific collection types by UID
|
|
41
|
-
relations: [
|
|
43
|
+
relations: ["api::article.article", "api::category.category"],
|
|
42
44
|
},
|
|
43
45
|
},
|
|
44
46
|
};
|
|
@@ -49,3 +51,4 @@ module.exports = {
|
|
|
49
51
|
- The plugin provides a global middleware that intercepts requests with `?populate=all` and rewrites the query to trigger recursive population.
|
|
50
52
|
- In the background, it builds a standard Strapi populate query as described in the [Strapi documentation](https://docs.strapi.io/cms/api/rest/populate-select).
|
|
51
53
|
- You can control which relations are included using the relations config option.
|
|
54
|
+
- Inside the document API, you can set `populate: '*'` and `recursive: true` to make it work
|
package/dist/server/index.js
CHANGED
|
@@ -4,7 +4,7 @@ const getPopulateQuery = (modelUid, parentsModelUids = []) => {
|
|
|
4
4
|
try {
|
|
5
5
|
if (queryCache[modelUid]) {
|
|
6
6
|
strapi.log.debug(`[populate-all] query cache hit: ${modelUid}`);
|
|
7
|
-
return queryCache[modelUid];
|
|
7
|
+
return structuredClone(queryCache[modelUid]);
|
|
8
8
|
}
|
|
9
9
|
if (parentsModelUids.includes(modelUid)) {
|
|
10
10
|
strapi.log.debug(
|
|
@@ -71,7 +71,7 @@ const getPopulateQuery = (modelUid, parentsModelUids = []) => {
|
|
|
71
71
|
}
|
|
72
72
|
strapi.log.debug(`[populate-all] new query cached: ${modelUid}`);
|
|
73
73
|
queryCache[modelUid] = query;
|
|
74
|
-
return query;
|
|
74
|
+
return structuredClone(query);
|
|
75
75
|
} catch (error) {
|
|
76
76
|
console.error(
|
|
77
77
|
`[populate-all] getPopulateQuery(${modelUid}) failed: ${error}`
|
|
@@ -82,8 +82,8 @@ const getPopulateQuery = (modelUid, parentsModelUids = []) => {
|
|
|
82
82
|
const bootstrap = ({ strapi: strapi2 }) => {
|
|
83
83
|
strapi2.db.lifecycles.subscribe((event) => {
|
|
84
84
|
try {
|
|
85
|
-
if (event.
|
|
86
|
-
if (event.
|
|
85
|
+
if (event.action === "beforeFindMany" || event.action === "beforeFindOne") {
|
|
86
|
+
if (event.params?.populateAll) {
|
|
87
87
|
strapi2.log.debug(
|
|
88
88
|
`[populate-all] recursively populate ${event.model.uid}`
|
|
89
89
|
);
|
|
@@ -135,7 +135,7 @@ const middlewares = {
|
|
|
135
135
|
populateAll: async (ctx, next) => {
|
|
136
136
|
if (ctx.query.populate === "all") {
|
|
137
137
|
ctx.query.populate = void 0;
|
|
138
|
-
ctx.query.
|
|
138
|
+
ctx.query.populateAll = true;
|
|
139
139
|
}
|
|
140
140
|
await next();
|
|
141
141
|
}
|
package/dist/server/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@ const getPopulateQuery = (modelUid, parentsModelUids = []) => {
|
|
|
3
3
|
try {
|
|
4
4
|
if (queryCache[modelUid]) {
|
|
5
5
|
strapi.log.debug(`[populate-all] query cache hit: ${modelUid}`);
|
|
6
|
-
return queryCache[modelUid];
|
|
6
|
+
return structuredClone(queryCache[modelUid]);
|
|
7
7
|
}
|
|
8
8
|
if (parentsModelUids.includes(modelUid)) {
|
|
9
9
|
strapi.log.debug(
|
|
@@ -70,7 +70,7 @@ const getPopulateQuery = (modelUid, parentsModelUids = []) => {
|
|
|
70
70
|
}
|
|
71
71
|
strapi.log.debug(`[populate-all] new query cached: ${modelUid}`);
|
|
72
72
|
queryCache[modelUid] = query;
|
|
73
|
-
return query;
|
|
73
|
+
return structuredClone(query);
|
|
74
74
|
} catch (error) {
|
|
75
75
|
console.error(
|
|
76
76
|
`[populate-all] getPopulateQuery(${modelUid}) failed: ${error}`
|
|
@@ -81,8 +81,8 @@ const getPopulateQuery = (modelUid, parentsModelUids = []) => {
|
|
|
81
81
|
const bootstrap = ({ strapi: strapi2 }) => {
|
|
82
82
|
strapi2.db.lifecycles.subscribe((event) => {
|
|
83
83
|
try {
|
|
84
|
-
if (event.
|
|
85
|
-
if (event.
|
|
84
|
+
if (event.action === "beforeFindMany" || event.action === "beforeFindOne") {
|
|
85
|
+
if (event.params?.populateAll) {
|
|
86
86
|
strapi2.log.debug(
|
|
87
87
|
`[populate-all] recursively populate ${event.model.uid}`
|
|
88
88
|
);
|
|
@@ -134,7 +134,7 @@ const middlewares = {
|
|
|
134
134
|
populateAll: async (ctx, next) => {
|
|
135
135
|
if (ctx.query.populate === "all") {
|
|
136
136
|
ctx.query.populate = void 0;
|
|
137
|
-
ctx.query.
|
|
137
|
+
ctx.query.populateAll = true;
|
|
138
138
|
}
|
|
139
139
|
await next();
|
|
140
140
|
}
|
package/package.json
CHANGED