@fourlights/strapi-plugin-deep-populate 1.1.2 → 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 +243 -124
- package/dist/server/index.mjs +242 -123
- 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/dist/server/index.mjs
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { dset } from "dset/merge";
|
|
2
|
-
import delve from "dlv";
|
|
3
1
|
import { klona } from "klona/json";
|
|
4
2
|
import require$$1 from "crypto";
|
|
5
3
|
import require$$0$1 from "child_process";
|
|
@@ -13,6 +11,139 @@ import require$$0$6 from "stream";
|
|
|
13
11
|
import require$$2$1 from "util";
|
|
14
12
|
import require$$0$8 from "constants";
|
|
15
13
|
import "node:stream";
|
|
14
|
+
import delve from "dlv";
|
|
15
|
+
import { dset } from "dset/merge";
|
|
16
|
+
const config = {
|
|
17
|
+
default: ({ env: env2 }) => ({ cachePopulate: true, augmentPopulateStar: true }),
|
|
18
|
+
validator: (config2) => {
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const schema$1 = {
|
|
22
|
+
kind: "collectionType",
|
|
23
|
+
collectionName: "caches",
|
|
24
|
+
info: {
|
|
25
|
+
singularName: "cache",
|
|
26
|
+
pluralName: "caches",
|
|
27
|
+
displayName: "Cache",
|
|
28
|
+
description: "Holds cached deep populate object"
|
|
29
|
+
},
|
|
30
|
+
options: {},
|
|
31
|
+
pluginOptions: {
|
|
32
|
+
"content-manager": {
|
|
33
|
+
visible: false
|
|
34
|
+
},
|
|
35
|
+
"content-type-builder": {
|
|
36
|
+
visible: false
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
attributes: {
|
|
40
|
+
hash: {
|
|
41
|
+
type: "string",
|
|
42
|
+
configurable: false,
|
|
43
|
+
required: true
|
|
44
|
+
},
|
|
45
|
+
params: {
|
|
46
|
+
type: "json",
|
|
47
|
+
configurable: false,
|
|
48
|
+
required: true
|
|
49
|
+
},
|
|
50
|
+
populate: {
|
|
51
|
+
type: "json",
|
|
52
|
+
configurable: false
|
|
53
|
+
},
|
|
54
|
+
dependencies: { type: "string", configurable: false }
|
|
55
|
+
},
|
|
56
|
+
// experimental feature:
|
|
57
|
+
indexes: [
|
|
58
|
+
{
|
|
59
|
+
name: "deep-populate_cache_hash_index",
|
|
60
|
+
columns: ["hash"],
|
|
61
|
+
type: "unique"
|
|
62
|
+
}
|
|
63
|
+
]
|
|
64
|
+
};
|
|
65
|
+
const cache$1 = { schema: schema$1 };
|
|
66
|
+
const contentTypes$1 = { cache: cache$1 };
|
|
67
|
+
const register = async ({ strapi: strapi2 }) => {
|
|
68
|
+
strapi2.documents.use(async (context, next) => {
|
|
69
|
+
const { cachePopulate, augmentPopulateStar } = strapi2.config.get("plugin::deep-populate");
|
|
70
|
+
if (
|
|
71
|
+
// do nothing if not configured
|
|
72
|
+
!cachePopulate && !augmentPopulateStar || context.uid === "plugin::deep-populate.cache"
|
|
73
|
+
)
|
|
74
|
+
return await next();
|
|
75
|
+
const populateService = strapi2.plugin("deep-populate").service("populate");
|
|
76
|
+
const cacheService = strapi2.plugin("deep-populate").service("cache");
|
|
77
|
+
const { populate: populate2 } = context.params;
|
|
78
|
+
const returnDeeplyPopulated = augmentPopulateStar && populate2 === "*";
|
|
79
|
+
if (cachePopulate && context.action === "delete")
|
|
80
|
+
await cacheService.clear({ ...context.params, contentType: context.uid });
|
|
81
|
+
const originalFields = klona(context.fields);
|
|
82
|
+
if (returnDeeplyPopulated && ["findOne", "findFirst", "findMany"].includes(context.action))
|
|
83
|
+
context.fields = ["documentId", "status", "locale"];
|
|
84
|
+
const result = await next();
|
|
85
|
+
if (["create", "update"].includes(context.action)) {
|
|
86
|
+
const { documentId, status: status2, locale: locale2 } = result;
|
|
87
|
+
if (cachePopulate && context.action === "update")
|
|
88
|
+
await cacheService.clear({ ...context.params, contentType: context.uid });
|
|
89
|
+
if (cachePopulate || returnDeeplyPopulated) {
|
|
90
|
+
const deepPopulate = await populateService.get({ contentType: context.uid, documentId, status: status2, locale: locale2 });
|
|
91
|
+
if (returnDeeplyPopulated)
|
|
92
|
+
return await strapi2.documents(context.uid).findOne({ documentId, status: status2, locale: locale2, fields: originalFields, populate: deepPopulate });
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (returnDeeplyPopulated && ["findOne", "findFirst"].includes(context.action)) {
|
|
96
|
+
const { documentId, status: status2, locale: locale2 } = result;
|
|
97
|
+
const deepPopulate = await populateService.get({ contentType: context.uid, documentId, status: status2, locale: locale2 });
|
|
98
|
+
return await strapi2.documents(context.uid).findOne({ documentId, status: status2, locale: locale2, fields: originalFields, populate: deepPopulate });
|
|
99
|
+
}
|
|
100
|
+
if (returnDeeplyPopulated && context.action === "findMany") {
|
|
101
|
+
return await Promise.all(
|
|
102
|
+
result.map(async ({ documentId, status: status2, locale: locale2 }) => {
|
|
103
|
+
const deepPopulate = await populateService.get({ contentType: context.uid, documentId, status: status2, locale: locale2 });
|
|
104
|
+
return await strapi2.documents(context.uid).findOne({ documentId, status: status2, locale: locale2, fields: originalFields, populate: deepPopulate });
|
|
105
|
+
})
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
return result;
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
const getHash = (params) => {
|
|
112
|
+
return `${params.contentType}-${params.documentId}-${params.locale}-${params.status}-${params.omitEmpty ? "sparse" : "full"}`;
|
|
113
|
+
};
|
|
114
|
+
const cache = ({ strapi: strapi2 }) => ({
|
|
115
|
+
async get(params) {
|
|
116
|
+
const entry = await strapi2.documents("plugin::deep-populate.cache").findFirst({ filters: { hash: { $eq: getHash(params) } } });
|
|
117
|
+
return entry ? entry.populate : null;
|
|
118
|
+
},
|
|
119
|
+
async set({ populate: populate2, dependencies, ...params }) {
|
|
120
|
+
return await strapi2.documents("plugin::deep-populate.cache").create({ data: { hash: getHash(params), params, populate: populate2, dependencies: dependencies.join(",") } });
|
|
121
|
+
},
|
|
122
|
+
async clear(params) {
|
|
123
|
+
const entry = await strapi2.documents("plugin::deep-populate.cache").findFirst({ filters: { hash: { $eq: getHash(params) } } });
|
|
124
|
+
let retval = null;
|
|
125
|
+
if (entry) {
|
|
126
|
+
retval = await strapi2.documents("plugin::deep-populate.cache").delete({ documentId: entry.documentId });
|
|
127
|
+
}
|
|
128
|
+
await this.refreshDependents(params.documentId);
|
|
129
|
+
return retval;
|
|
130
|
+
},
|
|
131
|
+
async refreshDependents(documentId) {
|
|
132
|
+
const entries = await strapi2.documents("plugin::deep-populate.cache").findMany({ filters: { dependencies: { $contains: documentId } }, fields: ["documentId", "params"] });
|
|
133
|
+
const deleted = await strapi2.db.query("plugin::deep-populate.cache").deleteMany({
|
|
134
|
+
where: {
|
|
135
|
+
documentId: { $in: entries.map((x) => x.documentId) }
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
if (deleted.count !== entries.length)
|
|
139
|
+
console.error(`Deleted count ${deleted.count} does not match entries count ${entries.length}`);
|
|
140
|
+
const batchSize = 5;
|
|
141
|
+
for (let i = 0; i < entries.length; i += batchSize) {
|
|
142
|
+
const batch = entries.slice(i, i + batchSize);
|
|
143
|
+
await Promise.all(batch.map((entry) => strapi2.service("plugin::deep-populate.populate").get(entry.params)));
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
});
|
|
16
147
|
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
|
17
148
|
function getDefaultExportFromCjs(x) {
|
|
18
149
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
@@ -588,8 +719,8 @@ lodash.exports;
|
|
|
588
719
|
return object2[key];
|
|
589
720
|
});
|
|
590
721
|
}
|
|
591
|
-
function cacheHas2(
|
|
592
|
-
return
|
|
722
|
+
function cacheHas2(cache2, key) {
|
|
723
|
+
return cache2.has(key);
|
|
593
724
|
}
|
|
594
725
|
function charsStartIndex(strSymbols, chrSymbols) {
|
|
595
726
|
var index2 = -1, length = strSymbols.length;
|
|
@@ -1404,8 +1535,8 @@ lodash.exports;
|
|
|
1404
1535
|
if (!(seen ? cacheHas2(seen, computed) : includes2(result2, computed, comparator))) {
|
|
1405
1536
|
othIndex = othLength;
|
|
1406
1537
|
while (--othIndex) {
|
|
1407
|
-
var
|
|
1408
|
-
if (!(
|
|
1538
|
+
var cache2 = caches[othIndex];
|
|
1539
|
+
if (!(cache2 ? cacheHas2(cache2, computed) : includes2(arrays[othIndex], computed, comparator))) {
|
|
1409
1540
|
continue outer;
|
|
1410
1541
|
}
|
|
1411
1542
|
}
|
|
@@ -2979,12 +3110,12 @@ lodash.exports;
|
|
|
2979
3110
|
}
|
|
2980
3111
|
function memoizeCapped2(func) {
|
|
2981
3112
|
var result2 = memoize2(func, function(key) {
|
|
2982
|
-
if (
|
|
2983
|
-
|
|
3113
|
+
if (cache2.size === MAX_MEMOIZE_SIZE2) {
|
|
3114
|
+
cache2.clear();
|
|
2984
3115
|
}
|
|
2985
3116
|
return key;
|
|
2986
3117
|
});
|
|
2987
|
-
var
|
|
3118
|
+
var cache2 = result2.cache;
|
|
2988
3119
|
return result2;
|
|
2989
3120
|
}
|
|
2990
3121
|
function mergeData(data, source) {
|
|
@@ -3938,12 +4069,12 @@ lodash.exports;
|
|
|
3938
4069
|
throw new TypeError2(FUNC_ERROR_TEXT2);
|
|
3939
4070
|
}
|
|
3940
4071
|
var memoized = function() {
|
|
3941
|
-
var args = arguments, key = resolver ? resolver.apply(this, args) : args[0],
|
|
3942
|
-
if (
|
|
3943
|
-
return
|
|
4072
|
+
var args = arguments, key = resolver ? resolver.apply(this, args) : args[0], cache2 = memoized.cache;
|
|
4073
|
+
if (cache2.has(key)) {
|
|
4074
|
+
return cache2.get(key);
|
|
3944
4075
|
}
|
|
3945
4076
|
var result2 = func.apply(this, args);
|
|
3946
|
-
memoized.cache =
|
|
4077
|
+
memoized.cache = cache2.set(key, result2) || cache2;
|
|
3947
4078
|
return result2;
|
|
3948
4079
|
};
|
|
3949
4080
|
memoized.cache = new (memoize2.Cache || MapCache2)();
|
|
@@ -9205,7 +9336,7 @@ function baseConvert(util2, name, func, options) {
|
|
|
9205
9336
|
throw new TypeError();
|
|
9206
9337
|
}
|
|
9207
9338
|
options || (options = {});
|
|
9208
|
-
var
|
|
9339
|
+
var config2 = {
|
|
9209
9340
|
"cap": "cap" in options ? options.cap : true,
|
|
9210
9341
|
"curry": "curry" in options ? options.curry : true,
|
|
9211
9342
|
"fixed": "fixed" in options ? options.fixed : true,
|
|
@@ -9241,7 +9372,7 @@ function baseConvert(util2, name, func, options) {
|
|
|
9241
9372
|
"iteratee": function(iteratee) {
|
|
9242
9373
|
return function() {
|
|
9243
9374
|
var func2 = arguments[0], arity = arguments[1], result = iteratee(func2, arity), length = result.length;
|
|
9244
|
-
if (
|
|
9375
|
+
if (config2.cap && typeof arity == "number") {
|
|
9245
9376
|
arity = arity > 2 ? arity - 2 : 1;
|
|
9246
9377
|
return length && length <= arity ? result : baseAry(result, arity);
|
|
9247
9378
|
}
|
|
@@ -9291,7 +9422,7 @@ function baseConvert(util2, name, func, options) {
|
|
|
9291
9422
|
}
|
|
9292
9423
|
};
|
|
9293
9424
|
function castCap(name2, func2) {
|
|
9294
|
-
if (
|
|
9425
|
+
if (config2.cap) {
|
|
9295
9426
|
var indexes = mapping.iterateeRearg[name2];
|
|
9296
9427
|
if (indexes) {
|
|
9297
9428
|
return iterateeRearg(func2, indexes);
|
|
@@ -9304,17 +9435,17 @@ function baseConvert(util2, name, func, options) {
|
|
|
9304
9435
|
return func2;
|
|
9305
9436
|
}
|
|
9306
9437
|
function castCurry(name2, func2, n) {
|
|
9307
|
-
return forceCurry ||
|
|
9438
|
+
return forceCurry || config2.curry && n > 1 ? curry(func2, n) : func2;
|
|
9308
9439
|
}
|
|
9309
9440
|
function castFixed(name2, func2, n) {
|
|
9310
|
-
if (
|
|
9441
|
+
if (config2.fixed && (forceFixed || !mapping.skipFixed[name2])) {
|
|
9311
9442
|
var data = mapping.methodSpread[name2], start = data && data.start;
|
|
9312
9443
|
return start === void 0 ? ary(func2, n) : flatSpread(func2, start);
|
|
9313
9444
|
}
|
|
9314
9445
|
return func2;
|
|
9315
9446
|
}
|
|
9316
9447
|
function castRearg(name2, func2, n) {
|
|
9317
|
-
return
|
|
9448
|
+
return config2.rearg && n > 1 && (forceRearg || !mapping.skipRearg[name2]) ? rearg(func2, mapping.methodRearg[name2] || mapping.aryRearg[n]) : func2;
|
|
9318
9449
|
}
|
|
9319
9450
|
function cloneByPath(object2, path2) {
|
|
9320
9451
|
path2 = toPath(path2);
|
|
@@ -9359,7 +9490,7 @@ function baseConvert(util2, name, func, options) {
|
|
|
9359
9490
|
while (length--) {
|
|
9360
9491
|
args[length] = arguments[length];
|
|
9361
9492
|
}
|
|
9362
|
-
var index2 =
|
|
9493
|
+
var index2 = config2.rearg ? 0 : length - 1;
|
|
9363
9494
|
args[index2] = transform2(args[index2]);
|
|
9364
9495
|
return func2.apply(void 0, args);
|
|
9365
9496
|
};
|
|
@@ -9368,7 +9499,7 @@ function baseConvert(util2, name, func, options) {
|
|
|
9368
9499
|
var result, realName = mapping.aliasToReal[name2] || name2, wrapped = func2, wrapper = wrappers[realName];
|
|
9369
9500
|
if (wrapper) {
|
|
9370
9501
|
wrapped = wrapper(func2);
|
|
9371
|
-
} else if (
|
|
9502
|
+
} else if (config2.immutable) {
|
|
9372
9503
|
if (mapping.mutate.array[realName]) {
|
|
9373
9504
|
wrapped = wrapImmutable(func2, cloneArray);
|
|
9374
9505
|
} else if (mapping.mutate.object[realName]) {
|
|
@@ -10660,12 +10791,12 @@ function memoize$1(func, resolver) {
|
|
|
10660
10791
|
throw new TypeError(FUNC_ERROR_TEXT);
|
|
10661
10792
|
}
|
|
10662
10793
|
var memoized = function() {
|
|
10663
|
-
var args = arguments, key = resolver ? resolver.apply(this, args) : args[0],
|
|
10664
|
-
if (
|
|
10665
|
-
return
|
|
10794
|
+
var args = arguments, key = resolver ? resolver.apply(this, args) : args[0], cache2 = memoized.cache;
|
|
10795
|
+
if (cache2.has(key)) {
|
|
10796
|
+
return cache2.get(key);
|
|
10666
10797
|
}
|
|
10667
10798
|
var result = func.apply(this, args);
|
|
10668
|
-
memoized.cache =
|
|
10799
|
+
memoized.cache = cache2.set(key, result) || cache2;
|
|
10669
10800
|
return result;
|
|
10670
10801
|
};
|
|
10671
10802
|
memoized.cache = new (memoize$1.Cache || MapCache$2)();
|
|
@@ -10677,12 +10808,12 @@ var memoize = memoize_1;
|
|
|
10677
10808
|
var MAX_MEMOIZE_SIZE = 500;
|
|
10678
10809
|
function memoizeCapped$1(func) {
|
|
10679
10810
|
var result = memoize(func, function(key) {
|
|
10680
|
-
if (
|
|
10681
|
-
|
|
10811
|
+
if (cache2.size === MAX_MEMOIZE_SIZE) {
|
|
10812
|
+
cache2.clear();
|
|
10682
10813
|
}
|
|
10683
10814
|
return key;
|
|
10684
10815
|
});
|
|
10685
|
-
var
|
|
10816
|
+
var cache2 = result.cache;
|
|
10686
10817
|
return result;
|
|
10687
10818
|
}
|
|
10688
10819
|
var _memoizeCapped = memoizeCapped$1;
|
|
@@ -11184,8 +11315,8 @@ function arraySome$1(array2, predicate) {
|
|
|
11184
11315
|
return false;
|
|
11185
11316
|
}
|
|
11186
11317
|
var _arraySome = arraySome$1;
|
|
11187
|
-
function cacheHas$1(
|
|
11188
|
-
return
|
|
11318
|
+
function cacheHas$1(cache2, key) {
|
|
11319
|
+
return cache2.has(key);
|
|
11189
11320
|
}
|
|
11190
11321
|
var _cacheHas = cacheHas$1;
|
|
11191
11322
|
var SetCache = _SetCache, arraySome = _arraySome, cacheHas = _cacheHas;
|
|
@@ -11810,7 +11941,7 @@ function _objectWithoutPropertiesLoose(source, excluded) {
|
|
|
11810
11941
|
}
|
|
11811
11942
|
return target;
|
|
11812
11943
|
}
|
|
11813
|
-
function createValidation(
|
|
11944
|
+
function createValidation(config2) {
|
|
11814
11945
|
function validate(_ref, cb) {
|
|
11815
11946
|
let {
|
|
11816
11947
|
value,
|
|
@@ -11825,7 +11956,7 @@ function createValidation(config) {
|
|
|
11825
11956
|
test,
|
|
11826
11957
|
params,
|
|
11827
11958
|
message
|
|
11828
|
-
} =
|
|
11959
|
+
} = config2;
|
|
11829
11960
|
let {
|
|
11830
11961
|
parent,
|
|
11831
11962
|
context
|
|
@@ -11880,7 +12011,7 @@ function createValidation(config) {
|
|
|
11880
12011
|
else if (!result) cb(createError());
|
|
11881
12012
|
else cb(null, result);
|
|
11882
12013
|
}
|
|
11883
|
-
validate.OPTIONS =
|
|
12014
|
+
validate.OPTIONS = config2;
|
|
11884
12015
|
return validate;
|
|
11885
12016
|
}
|
|
11886
12017
|
let trim = (part) => part.substr(0, part.length - 1).substr(1);
|
|
@@ -24570,7 +24701,7 @@ const isPopulateString = (value) => {
|
|
|
24570
24701
|
};
|
|
24571
24702
|
const isStringArray$1 = (value) => fp.isArray(value) && value.every(fp.isString);
|
|
24572
24703
|
const isObj = (value) => fp.isObject(value);
|
|
24573
|
-
const populate$
|
|
24704
|
+
const populate$2 = traverseFactory().intercept(isPopulateString, async (visitor2, options, populate2, { recurse }) => {
|
|
24574
24705
|
const populateObject = pathsToObjectPopulate([populate2]);
|
|
24575
24706
|
const traversedPopulate = await recurse(visitor2, options, populateObject);
|
|
24576
24707
|
const [result] = objectPopulateToPaths(traversedPopulate);
|
|
@@ -24738,7 +24869,7 @@ const populate$1 = traverseFactory().intercept(isPopulateString, async (visitor2
|
|
|
24738
24869
|
}
|
|
24739
24870
|
}
|
|
24740
24871
|
);
|
|
24741
|
-
const traverseQueryPopulate = fp.curry(populate$
|
|
24872
|
+
const traverseQueryPopulate = fp.curry(populate$2.traverse);
|
|
24742
24873
|
const objectPopulateToPaths = (input) => {
|
|
24743
24874
|
const paths = [];
|
|
24744
24875
|
function traverse(currentObj, parentPath) {
|
|
@@ -25058,54 +25189,40 @@ const hasValue = (value) => {
|
|
|
25058
25189
|
return !(value === null || value === void 0 || Array.isArray(value) && value.length === 0 || typeof value === "object" && isEmpty(value));
|
|
25059
25190
|
};
|
|
25060
25191
|
async function _populateComponent({
|
|
25061
|
-
mainUid,
|
|
25062
|
-
mainDocumentId,
|
|
25063
|
-
schema: schema2,
|
|
25064
25192
|
populate: populate2 = {},
|
|
25065
25193
|
lookup,
|
|
25194
|
+
attrName,
|
|
25066
25195
|
inDynamicZone = false,
|
|
25067
|
-
|
|
25068
|
-
omitEmpty
|
|
25196
|
+
...params
|
|
25069
25197
|
}) {
|
|
25070
|
-
const attrName = lookup.pop();
|
|
25071
25198
|
const componentLookup = lookup.length === 0 ? [attrName] : [...lookup, inDynamicZone ? "on" : "populate", attrName];
|
|
25072
|
-
const componentPopulate =
|
|
25199
|
+
const componentPopulate = populate2;
|
|
25073
25200
|
dset(componentPopulate, componentLookup, { populate: "*" });
|
|
25074
25201
|
const nestedPopulate = await _populate({
|
|
25075
|
-
mainUid,
|
|
25076
|
-
mainDocumentId,
|
|
25077
|
-
schema: schema2,
|
|
25078
25202
|
populate: componentPopulate,
|
|
25079
25203
|
lookup: componentLookup,
|
|
25080
|
-
|
|
25081
|
-
omitEmpty
|
|
25204
|
+
...params
|
|
25082
25205
|
});
|
|
25083
25206
|
return isEmpty(nestedPopulate) ? true : { populate: nestedPopulate };
|
|
25084
25207
|
}
|
|
25085
25208
|
async function _populateDynamicZone({
|
|
25086
|
-
mainUid,
|
|
25087
|
-
mainDocumentId,
|
|
25088
25209
|
components,
|
|
25089
|
-
populate: populate2,
|
|
25090
25210
|
lookup,
|
|
25091
|
-
|
|
25092
|
-
|
|
25211
|
+
attrName,
|
|
25212
|
+
...params
|
|
25093
25213
|
}) {
|
|
25094
|
-
const
|
|
25095
|
-
|
|
25096
|
-
|
|
25097
|
-
|
|
25098
|
-
schema:
|
|
25099
|
-
|
|
25100
|
-
|
|
25214
|
+
const dynamicZoneLookup = [...lookup, attrName];
|
|
25215
|
+
const resolvedPopulate = {};
|
|
25216
|
+
for (const component of components) {
|
|
25217
|
+
const componentPopulate = await _populateComponent({
|
|
25218
|
+
schema: component,
|
|
25219
|
+
lookup: dynamicZoneLookup,
|
|
25220
|
+
attrName: component,
|
|
25101
25221
|
inDynamicZone: true,
|
|
25102
|
-
|
|
25103
|
-
omitEmpty
|
|
25222
|
+
...params
|
|
25104
25223
|
});
|
|
25105
|
-
|
|
25106
|
-
|
|
25107
|
-
return newPop;
|
|
25108
|
-
}, Promise.resolve({}));
|
|
25224
|
+
dset(resolvedPopulate, [component], componentPopulate);
|
|
25225
|
+
}
|
|
25109
25226
|
if (isEmpty(resolvedPopulate)) return void 0;
|
|
25110
25227
|
return { on: resolvedPopulate };
|
|
25111
25228
|
}
|
|
@@ -25116,18 +25233,23 @@ async function _populateRelation({
|
|
|
25116
25233
|
contentType,
|
|
25117
25234
|
relation,
|
|
25118
25235
|
resolvedRelations,
|
|
25119
|
-
omitEmpty
|
|
25236
|
+
omitEmpty,
|
|
25237
|
+
locale: locale2,
|
|
25238
|
+
status: status2
|
|
25120
25239
|
}) {
|
|
25121
25240
|
const isSingleRelation = !Array.isArray(relation);
|
|
25122
25241
|
const relations = isSingleRelation ? [relation] : relation;
|
|
25123
|
-
|
|
25242
|
+
const nonResolvedRelations = relations.filter(({ documentId }) => !resolvedRelations.has(documentId));
|
|
25243
|
+
for (const relation2 of nonResolvedRelations) {
|
|
25124
25244
|
resolvedRelations.set(relation2.documentId, {});
|
|
25125
25245
|
const relationPopulate = await _populate({
|
|
25126
|
-
|
|
25127
|
-
|
|
25246
|
+
contentType,
|
|
25247
|
+
documentId: relation2.documentId,
|
|
25128
25248
|
schema: contentType,
|
|
25129
25249
|
resolvedRelations,
|
|
25130
|
-
omitEmpty
|
|
25250
|
+
omitEmpty,
|
|
25251
|
+
locale: locale2,
|
|
25252
|
+
status: status2
|
|
25131
25253
|
});
|
|
25132
25254
|
resolvedRelations.set(relation2.documentId, relationPopulate);
|
|
25133
25255
|
}
|
|
@@ -25157,7 +25279,7 @@ const _resolveValue = ({ document: document2, lookup, attrName }) => {
|
|
|
25157
25279
|
const childLookup = lookup[populateIdx + 1];
|
|
25158
25280
|
const parentValue2 = delve(document2, parentLookup);
|
|
25159
25281
|
const childValue = (Array.isArray(parentValue2) ? parentValue2 : [parentValue2]).map(
|
|
25160
|
-
(v) => _resolveValue({ document:
|
|
25282
|
+
(v) => _resolveValue({ document: v, lookup: childLookup, attrName })
|
|
25161
25283
|
);
|
|
25162
25284
|
return childValue.find((v) => hasValue(v));
|
|
25163
25285
|
}
|
|
@@ -25168,18 +25290,18 @@ const _resolveValue = ({ document: document2, lookup, attrName }) => {
|
|
|
25168
25290
|
return parentValue?.[attrName];
|
|
25169
25291
|
};
|
|
25170
25292
|
async function _populate({
|
|
25171
|
-
|
|
25172
|
-
mainDocumentId,
|
|
25293
|
+
contentType,
|
|
25173
25294
|
schema: schema2,
|
|
25174
25295
|
populate: populate2 = {},
|
|
25175
25296
|
lookup = [],
|
|
25176
|
-
resolvedRelations
|
|
25177
|
-
omitEmpty
|
|
25297
|
+
resolvedRelations,
|
|
25298
|
+
omitEmpty,
|
|
25299
|
+
...params
|
|
25178
25300
|
}) {
|
|
25179
25301
|
const newPopulate = {};
|
|
25180
|
-
|
|
25181
|
-
|
|
25182
|
-
|
|
25302
|
+
let relations = getRelations(strapi.getModel(schema2));
|
|
25303
|
+
let currentPopulate = klona(populate2);
|
|
25304
|
+
resolvedRelations.set(params.documentId, true);
|
|
25183
25305
|
for (const [attrName] of relations) {
|
|
25184
25306
|
if (lookup.length > 0) {
|
|
25185
25307
|
const parent = delve(currentPopulate, lookup);
|
|
@@ -25190,47 +25312,56 @@ async function _populate({
|
|
|
25190
25312
|
dset(currentPopulate, attrName, { populate: "*" });
|
|
25191
25313
|
}
|
|
25192
25314
|
}
|
|
25193
|
-
|
|
25194
|
-
|
|
25315
|
+
let document2 = await strapi.documents(contentType).findOne({
|
|
25316
|
+
...params,
|
|
25195
25317
|
populate: currentPopulate ? currentPopulate : "*"
|
|
25196
25318
|
});
|
|
25319
|
+
currentPopulate = null;
|
|
25320
|
+
const resolveRelations = [];
|
|
25197
25321
|
for (const [attrName, attr] of relations) {
|
|
25198
25322
|
const value = _resolveValue({ document: document2, attrName, lookup });
|
|
25199
25323
|
if (!hasValue(value)) {
|
|
25200
25324
|
if (!omitEmpty) newPopulate[attrName] = true;
|
|
25201
25325
|
continue;
|
|
25202
25326
|
}
|
|
25327
|
+
resolveRelations.push([attrName, attr, value]);
|
|
25328
|
+
}
|
|
25329
|
+
relations = null;
|
|
25330
|
+
document2 = null;
|
|
25331
|
+
for (const [attrName, attr, value] of resolveRelations) {
|
|
25203
25332
|
if (contentTypes.isDynamicZoneAttribute(attr)) {
|
|
25204
25333
|
const relComponents = value.map(
|
|
25205
25334
|
(dataComponent) => attr.components.find((schemaComponent) => schemaComponent === dataComponent.__component)
|
|
25206
25335
|
);
|
|
25207
25336
|
newPopulate[attrName] = await _populateDynamicZone({
|
|
25208
|
-
|
|
25209
|
-
mainDocumentId,
|
|
25337
|
+
contentType,
|
|
25210
25338
|
components: relComponents,
|
|
25211
|
-
lookup
|
|
25339
|
+
lookup,
|
|
25340
|
+
attrName,
|
|
25212
25341
|
resolvedRelations,
|
|
25213
|
-
omitEmpty
|
|
25342
|
+
omitEmpty,
|
|
25343
|
+
...params
|
|
25214
25344
|
});
|
|
25215
25345
|
}
|
|
25216
25346
|
if (contentTypes.isRelationalAttribute(attr)) {
|
|
25217
|
-
const { target: relContentType } = attr;
|
|
25218
|
-
resolvedRelations.set(mainDocumentId, true);
|
|
25219
25347
|
newPopulate[attrName] = await _populateRelation({
|
|
25220
|
-
contentType:
|
|
25348
|
+
contentType: attr.target,
|
|
25221
25349
|
relation: value,
|
|
25222
25350
|
resolvedRelations,
|
|
25223
|
-
omitEmpty
|
|
25351
|
+
omitEmpty,
|
|
25352
|
+
locale: params.locale,
|
|
25353
|
+
status: params.status
|
|
25224
25354
|
});
|
|
25225
25355
|
}
|
|
25226
25356
|
if (contentTypes.isComponentAttribute(attr) && !contentTypes.isDynamicZoneAttribute(attr)) {
|
|
25227
25357
|
newPopulate[attrName] = await _populateComponent({
|
|
25228
|
-
|
|
25229
|
-
mainDocumentId,
|
|
25358
|
+
contentType,
|
|
25230
25359
|
schema: attr.component,
|
|
25231
|
-
lookup
|
|
25360
|
+
lookup,
|
|
25361
|
+
attrName,
|
|
25232
25362
|
resolvedRelations,
|
|
25233
|
-
omitEmpty
|
|
25363
|
+
omitEmpty,
|
|
25364
|
+
...params
|
|
25234
25365
|
});
|
|
25235
25366
|
}
|
|
25236
25367
|
if (contentTypes.isMediaAttribute(attr)) {
|
|
@@ -25239,43 +25370,31 @@ async function _populate({
|
|
|
25239
25370
|
}
|
|
25240
25371
|
return newPopulate;
|
|
25241
25372
|
}
|
|
25373
|
+
async function populate$1(params) {
|
|
25374
|
+
const resolvedRelations = /* @__PURE__ */ new Map();
|
|
25375
|
+
const populated = await _populate({ ...params, schema: params.contentType, resolvedRelations });
|
|
25376
|
+
return { populate: populated, dependencies: [...resolvedRelations.keys()] };
|
|
25377
|
+
}
|
|
25242
25378
|
const populate = ({ strapi: strapi2 }) => ({
|
|
25243
|
-
async get({
|
|
25244
|
-
|
|
25245
|
-
|
|
25246
|
-
|
|
25247
|
-
|
|
25248
|
-
|
|
25249
|
-
|
|
25250
|
-
|
|
25251
|
-
strapi2.documents(contentType);
|
|
25252
|
-
const { findOne, ...wrapped } = strapi2.documents(contentType);
|
|
25253
|
-
const wrappedFindOne = async (params) => {
|
|
25254
|
-
const { documentId, populate: originalPopulate } = params;
|
|
25255
|
-
const deepPopulate = await _populate({
|
|
25256
|
-
mainUid: contentType,
|
|
25257
|
-
mainDocumentId: documentId,
|
|
25258
|
-
schema: contentType,
|
|
25259
|
-
omitEmpty: originalPopulate !== "*"
|
|
25260
|
-
});
|
|
25261
|
-
if (originalPopulate && originalPopulate !== "*") {
|
|
25262
|
-
strapi2.log.warn(
|
|
25263
|
-
`passed "populate" will be merged with deepPopulate, which could result in unexpected behavior.`
|
|
25264
|
-
);
|
|
25265
|
-
if (typeof originalPopulate === "object")
|
|
25266
|
-
Object.keys(originalPopulate).map((k) => dset(deepPopulate, k, originalPopulate[k]));
|
|
25267
|
-
if (Array.isArray(originalPopulate)) originalPopulate.map((k) => dset(deepPopulate, k, true));
|
|
25268
|
-
}
|
|
25269
|
-
return await findOne({ ...params, populate: deepPopulate });
|
|
25270
|
-
};
|
|
25271
|
-
return { ...wrapped, findOne: wrappedFindOne };
|
|
25379
|
+
async get(params) {
|
|
25380
|
+
const { cachePopulate } = strapi2.config.get("plugin::deep-populate");
|
|
25381
|
+
if (!cachePopulate) return (await populate$1(params)).populate;
|
|
25382
|
+
const cachedEntry = await strapi2.service("plugin::deep-populate.cache").get(params);
|
|
25383
|
+
if (cachedEntry) return cachedEntry;
|
|
25384
|
+
const resolved = await populate$1(params);
|
|
25385
|
+
await strapi2.service("plugin::deep-populate.cache").set({ ...params, ...resolved });
|
|
25386
|
+
return resolved;
|
|
25272
25387
|
}
|
|
25273
25388
|
});
|
|
25274
25389
|
const services = {
|
|
25275
|
-
populate
|
|
25390
|
+
populate,
|
|
25391
|
+
cache
|
|
25276
25392
|
};
|
|
25277
25393
|
const index = {
|
|
25278
|
-
|
|
25394
|
+
config,
|
|
25395
|
+
contentTypes: contentTypes$1,
|
|
25396
|
+
services,
|
|
25397
|
+
register
|
|
25279
25398
|
};
|
|
25280
25399
|
export {
|
|
25281
25400
|
index as default
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
schema: {
|
|
3
|
+
kind: string;
|
|
4
|
+
collectionName: string;
|
|
5
|
+
info: {
|
|
6
|
+
singularName: string;
|
|
7
|
+
pluralName: string;
|
|
8
|
+
displayName: string;
|
|
9
|
+
description: string;
|
|
10
|
+
};
|
|
11
|
+
options: {};
|
|
12
|
+
pluginOptions: {
|
|
13
|
+
"content-manager": {
|
|
14
|
+
visible: boolean;
|
|
15
|
+
};
|
|
16
|
+
"content-type-builder": {
|
|
17
|
+
visible: boolean;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
attributes: {
|
|
21
|
+
hash: {
|
|
22
|
+
type: string;
|
|
23
|
+
configurable: boolean;
|
|
24
|
+
required: boolean;
|
|
25
|
+
};
|
|
26
|
+
params: {
|
|
27
|
+
type: string;
|
|
28
|
+
configurable: boolean;
|
|
29
|
+
required: boolean;
|
|
30
|
+
};
|
|
31
|
+
populate: {
|
|
32
|
+
type: string;
|
|
33
|
+
configurable: boolean;
|
|
34
|
+
};
|
|
35
|
+
dependencies: {
|
|
36
|
+
type: string;
|
|
37
|
+
configurable: boolean;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
indexes: {
|
|
41
|
+
name: string;
|
|
42
|
+
columns: string[];
|
|
43
|
+
type: string;
|
|
44
|
+
}[];
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
export default _default;
|