@fourlights/strapi-plugin-deep-populate 1.1.1 → 1.2.1
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 +58 -43
- package/dist/server/index.js +245 -119
- package/dist/server/index.mjs +244 -118
- package/dist/server/src/config/index.d.ts +10 -0
- package/dist/server/src/content-types/cache/index.d.ts +47 -0
- package/dist/server/src/content-types/cache/schema.d.ts +45 -0
- package/dist/server/src/content-types/index.d.ts +49 -0
- package/dist/server/src/index.d.ts +76 -12
- package/dist/server/src/register.d.ts +4 -0
- package/dist/server/src/services/cache.d.ts +14 -0
- package/dist/server/src/services/deep-populate/index.d.ts +5 -3
- package/dist/server/src/services/index.d.ts +16 -12
- package/dist/server/src/services/populate.d.ts +7 -16
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,65 +1,80 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Strapi v5 Deep Populate Plugin
|
|
2
2
|
|
|
3
3
|
[](https://badge.fury.io/js/@fourlights%2Fstrapi-plugin-deep-populate)
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
It does
|
|
7
|
-
Only relations that are actually set will be populated.
|
|
5
|
+
A Strapi v5 plugin that automatically populates all nested relations in a single request using `populate: '*'`.
|
|
6
|
+
It does not impose a limit on the level of nesting and can cache the populate object for improved performance.
|
|
8
7
|
|
|
9
|
-
##
|
|
8
|
+
## Features
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
```ts
|
|
17
|
-
// Option 2: use the `findOne` method that wraps around documentService.findOne
|
|
18
|
-
const { findOne } = strapi.plugin("deep-populate").service("populate").documents("api::page.page")
|
|
19
|
-
const document = await findOne({ documentId: 'xyz' })
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
```ts
|
|
23
|
-
// Using the wrapped FindOne provides some handy features:
|
|
10
|
+
- Automatically resolves and populates all nested relations
|
|
11
|
+
- Supports all relation types including dynamic zones
|
|
12
|
+
- Handles circular references and edge cases
|
|
13
|
+
- Includes caching for improved performance
|
|
14
|
+
- Honors `populateCreatorFields` setting
|
|
24
15
|
|
|
25
|
-
|
|
26
|
-
const documentWithCreatedBy = findOne({ documentId: 'xyz', populate: ['createdBy']})
|
|
27
|
-
const documentWithoutSection = findOne({ documentId: 'xyz', populate: { section: false }})
|
|
16
|
+
## Installation
|
|
28
17
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const fullDocument = findOne({ documentId: 'xyz', populate: '*' }) // fully populated, so all attributes are returned
|
|
18
|
+
```bash
|
|
19
|
+
npm install @fourlights/strapi-plugin-deep-populate
|
|
32
20
|
```
|
|
33
21
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
The plugin honors the `populateCreatorFields`<a href="#fn1"><sup>[1]</sup></a> parameter at the content-type level. When set to true, the `createdBy` and `updatedBy` fields will be populated automatically.
|
|
22
|
+
## Usage
|
|
37
23
|
|
|
38
|
-
|
|
24
|
+
Enable deep population in your Strapi config:
|
|
39
25
|
|
|
26
|
+
```js
|
|
27
|
+
// config/plugins.js
|
|
28
|
+
module.exports = ({ env }) => ({
|
|
29
|
+
'deep-populate': {
|
|
30
|
+
augmentPopulateStar: true, // default
|
|
31
|
+
cachePopulate: true // default
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
```
|
|
40
35
|
|
|
41
|
-
|
|
36
|
+
### Basic Usage
|
|
42
37
|
|
|
43
|
-
|
|
38
|
+
```ts
|
|
39
|
+
// Get fully populated document
|
|
40
|
+
const document = await strapi.documents("api.page.page").findOne({
|
|
41
|
+
documentId: 'xyz',
|
|
42
|
+
populate: '*'
|
|
43
|
+
});
|
|
44
|
+
```
|
|
44
45
|
|
|
45
|
-
|
|
46
|
+
### Advanced Usage
|
|
46
47
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
```ts
|
|
49
|
+
// Get populate object for custom usage
|
|
50
|
+
const { populate } = await strapi.plugin("deep-populate")
|
|
51
|
+
.service("populate")
|
|
52
|
+
.get({
|
|
53
|
+
documentId: 'xyz',
|
|
54
|
+
contentType: 'api::page.page',
|
|
55
|
+
omitEmpty: true // optional
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const document = await strapi.documents('api::page.page').findOne({
|
|
59
|
+
documentId: 'xyz',
|
|
60
|
+
populate
|
|
61
|
+
});
|
|
62
|
+
```
|
|
50
63
|
|
|
51
|
-
|
|
64
|
+
### Caching
|
|
52
65
|
|
|
53
|
-
|
|
66
|
+
The plugin caches populate objects to improve performance. Cache can be disabled via the `cachePopulate` setting.
|
|
54
67
|
|
|
55
|
-
|
|
68
|
+
### Creator Fields
|
|
56
69
|
|
|
57
|
-
|
|
58
|
-
It takes care of some edge cases (e.g. circular relations) and works for all types of relations, most notably the dynamic zone (which has a different format to populate in Strapi).
|
|
70
|
+
The plugin automatically populates `createdBy` and `updatedBy` fields when `populateCreatorFields` is enabled in the content-type configuration.
|
|
59
71
|
|
|
60
|
-
##
|
|
72
|
+
## How It Works
|
|
61
73
|
|
|
62
|
-
The
|
|
74
|
+
The plugin recursively:
|
|
75
|
+
1. Traverses the content-type schema
|
|
76
|
+
2. Retrieves documents with one-level deep populate
|
|
77
|
+
3. Resolves all nested relations
|
|
78
|
+
4. Returns a complete populate object
|
|
63
79
|
|
|
64
|
-
|
|
65
|
-
- Invalidate said cache using db lifecycle hooks
|
|
80
|
+
This process handles all relation types including dynamic zones and circular references.
|