@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.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const merge$1 = require("dset/merge");
|
|
3
|
-
const delve = require("dlv");
|
|
4
2
|
const json$1 = require("klona/json");
|
|
5
3
|
const require$$1 = require("crypto");
|
|
6
4
|
const require$$0$1 = require("child_process");
|
|
@@ -14,8 +12,9 @@ const require$$0$6 = require("stream");
|
|
|
14
12
|
const require$$2$1 = require("util");
|
|
15
13
|
const require$$0$8 = require("constants");
|
|
16
14
|
require("node:stream");
|
|
15
|
+
const delve = require("dlv");
|
|
16
|
+
const merge$1 = require("dset/merge");
|
|
17
17
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
18
|
-
const delve__default = /* @__PURE__ */ _interopDefault(delve);
|
|
19
18
|
const require$$1__default = /* @__PURE__ */ _interopDefault(require$$1);
|
|
20
19
|
const require$$0__default = /* @__PURE__ */ _interopDefault(require$$0$1);
|
|
21
20
|
const require$$0__default$1 = /* @__PURE__ */ _interopDefault(require$$0$2);
|
|
@@ -27,6 +26,138 @@ const require$$0__default$6 = /* @__PURE__ */ _interopDefault(require$$0$7);
|
|
|
27
26
|
const require$$0__default$5 = /* @__PURE__ */ _interopDefault(require$$0$6);
|
|
28
27
|
const require$$2__default$1 = /* @__PURE__ */ _interopDefault(require$$2$1);
|
|
29
28
|
const require$$0__default$7 = /* @__PURE__ */ _interopDefault(require$$0$8);
|
|
29
|
+
const delve__default = /* @__PURE__ */ _interopDefault(delve);
|
|
30
|
+
const config = {
|
|
31
|
+
default: ({ env: env2 }) => ({ cachePopulate: true, augmentPopulateStar: true }),
|
|
32
|
+
validator: (config2) => {
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const schema$1 = {
|
|
36
|
+
kind: "collectionType",
|
|
37
|
+
collectionName: "caches",
|
|
38
|
+
info: {
|
|
39
|
+
singularName: "cache",
|
|
40
|
+
pluralName: "caches",
|
|
41
|
+
displayName: "Cache",
|
|
42
|
+
description: "Holds cached deep populate object"
|
|
43
|
+
},
|
|
44
|
+
options: {},
|
|
45
|
+
pluginOptions: {
|
|
46
|
+
"content-manager": {
|
|
47
|
+
visible: false
|
|
48
|
+
},
|
|
49
|
+
"content-type-builder": {
|
|
50
|
+
visible: false
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
attributes: {
|
|
54
|
+
hash: {
|
|
55
|
+
type: "string",
|
|
56
|
+
configurable: false,
|
|
57
|
+
required: true
|
|
58
|
+
},
|
|
59
|
+
params: {
|
|
60
|
+
type: "json",
|
|
61
|
+
configurable: false,
|
|
62
|
+
required: true
|
|
63
|
+
},
|
|
64
|
+
populate: {
|
|
65
|
+
type: "json",
|
|
66
|
+
configurable: false
|
|
67
|
+
},
|
|
68
|
+
dependencies: { type: "string", configurable: false }
|
|
69
|
+
},
|
|
70
|
+
// experimental feature:
|
|
71
|
+
indexes: [
|
|
72
|
+
{
|
|
73
|
+
name: "deep-populate_cache_hash_index",
|
|
74
|
+
columns: ["hash"],
|
|
75
|
+
type: "unique"
|
|
76
|
+
}
|
|
77
|
+
]
|
|
78
|
+
};
|
|
79
|
+
const cache$1 = { schema: schema$1 };
|
|
80
|
+
const contentTypes$1 = { cache: cache$1 };
|
|
81
|
+
const register = async ({ strapi: strapi2 }) => {
|
|
82
|
+
strapi2.documents.use(async (context, next) => {
|
|
83
|
+
const { cachePopulate, augmentPopulateStar } = strapi2.config.get("plugin::deep-populate");
|
|
84
|
+
if (
|
|
85
|
+
// do nothing if not configured
|
|
86
|
+
!cachePopulate && !augmentPopulateStar || context.uid === "plugin::deep-populate.cache"
|
|
87
|
+
)
|
|
88
|
+
return await next();
|
|
89
|
+
const populateService = strapi2.plugin("deep-populate").service("populate");
|
|
90
|
+
const cacheService = strapi2.plugin("deep-populate").service("cache");
|
|
91
|
+
const { populate: populate2 } = context.params;
|
|
92
|
+
const returnDeeplyPopulated = augmentPopulateStar && populate2 === "*";
|
|
93
|
+
if (cachePopulate && context.action === "delete")
|
|
94
|
+
await cacheService.clear({ ...context.params, contentType: context.uid });
|
|
95
|
+
const originalFields = json$1.klona(context.fields);
|
|
96
|
+
if (returnDeeplyPopulated && ["findOne", "findFirst", "findMany"].includes(context.action))
|
|
97
|
+
context.fields = ["documentId", "status", "locale"];
|
|
98
|
+
const result = await next();
|
|
99
|
+
if (["create", "update"].includes(context.action)) {
|
|
100
|
+
const { documentId, status: status2, locale: locale2 } = result;
|
|
101
|
+
if (cachePopulate && context.action === "update")
|
|
102
|
+
await cacheService.clear({ ...context.params, contentType: context.uid });
|
|
103
|
+
if (cachePopulate || returnDeeplyPopulated) {
|
|
104
|
+
const deepPopulate = await populateService.get({ contentType: context.uid, documentId, status: status2, locale: locale2 });
|
|
105
|
+
if (returnDeeplyPopulated)
|
|
106
|
+
return await strapi2.documents(context.uid).findOne({ documentId, status: status2, locale: locale2, fields: originalFields, populate: deepPopulate });
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (returnDeeplyPopulated && ["findOne", "findFirst"].includes(context.action)) {
|
|
110
|
+
const { documentId, status: status2, locale: locale2 } = result;
|
|
111
|
+
const deepPopulate = await populateService.get({ contentType: context.uid, documentId, status: status2, locale: locale2 });
|
|
112
|
+
return await strapi2.documents(context.uid).findOne({ documentId, status: status2, locale: locale2, fields: originalFields, populate: deepPopulate });
|
|
113
|
+
}
|
|
114
|
+
if (returnDeeplyPopulated && context.action === "findMany") {
|
|
115
|
+
return await Promise.all(
|
|
116
|
+
result.map(async ({ documentId, status: status2, locale: locale2 }) => {
|
|
117
|
+
const deepPopulate = await populateService.get({ contentType: context.uid, documentId, status: status2, locale: locale2 });
|
|
118
|
+
return await strapi2.documents(context.uid).findOne({ documentId, status: status2, locale: locale2, fields: originalFields, populate: deepPopulate });
|
|
119
|
+
})
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
return result;
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
const getHash = (params) => {
|
|
126
|
+
return `${params.contentType}-${params.documentId}-${params.locale}-${params.status}-${params.omitEmpty ? "sparse" : "full"}`;
|
|
127
|
+
};
|
|
128
|
+
const cache = ({ strapi: strapi2 }) => ({
|
|
129
|
+
async get(params) {
|
|
130
|
+
const entry = await strapi2.documents("plugin::deep-populate.cache").findFirst({ filters: { hash: { $eq: getHash(params) } } });
|
|
131
|
+
return entry ? entry.populate : null;
|
|
132
|
+
},
|
|
133
|
+
async set({ populate: populate2, dependencies, ...params }) {
|
|
134
|
+
return await strapi2.documents("plugin::deep-populate.cache").create({ data: { hash: getHash(params), params, populate: populate2, dependencies: dependencies.join(",") } });
|
|
135
|
+
},
|
|
136
|
+
async clear(params) {
|
|
137
|
+
const entry = await strapi2.documents("plugin::deep-populate.cache").findFirst({ filters: { hash: { $eq: getHash(params) } } });
|
|
138
|
+
let retval = null;
|
|
139
|
+
if (entry) {
|
|
140
|
+
retval = await strapi2.documents("plugin::deep-populate.cache").delete({ documentId: entry.documentId });
|
|
141
|
+
}
|
|
142
|
+
await this.refreshDependents(params.documentId);
|
|
143
|
+
return retval;
|
|
144
|
+
},
|
|
145
|
+
async refreshDependents(documentId) {
|
|
146
|
+
const entries = await strapi2.documents("plugin::deep-populate.cache").findMany({ filters: { dependencies: { $contains: documentId } }, fields: ["documentId", "params"] });
|
|
147
|
+
const deleted = await strapi2.db.query("plugin::deep-populate.cache").deleteMany({
|
|
148
|
+
where: {
|
|
149
|
+
documentId: { $in: entries.map((x) => x.documentId) }
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
if (deleted.count !== entries.length)
|
|
153
|
+
console.error(`Deleted count ${deleted.count} does not match entries count ${entries.length}`);
|
|
154
|
+
const batchSize = 5;
|
|
155
|
+
for (let i = 0; i < entries.length; i += batchSize) {
|
|
156
|
+
const batch = entries.slice(i, i + batchSize);
|
|
157
|
+
await Promise.all(batch.map((entry) => strapi2.service("plugin::deep-populate.populate").get(entry.params)));
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
});
|
|
30
161
|
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
|
31
162
|
function getDefaultExportFromCjs(x) {
|
|
32
163
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
@@ -602,8 +733,8 @@ lodash.exports;
|
|
|
602
733
|
return object2[key];
|
|
603
734
|
});
|
|
604
735
|
}
|
|
605
|
-
function cacheHas2(
|
|
606
|
-
return
|
|
736
|
+
function cacheHas2(cache2, key) {
|
|
737
|
+
return cache2.has(key);
|
|
607
738
|
}
|
|
608
739
|
function charsStartIndex(strSymbols, chrSymbols) {
|
|
609
740
|
var index2 = -1, length = strSymbols.length;
|
|
@@ -1418,8 +1549,8 @@ lodash.exports;
|
|
|
1418
1549
|
if (!(seen ? cacheHas2(seen, computed) : includes2(result2, computed, comparator))) {
|
|
1419
1550
|
othIndex = othLength;
|
|
1420
1551
|
while (--othIndex) {
|
|
1421
|
-
var
|
|
1422
|
-
if (!(
|
|
1552
|
+
var cache2 = caches[othIndex];
|
|
1553
|
+
if (!(cache2 ? cacheHas2(cache2, computed) : includes2(arrays[othIndex], computed, comparator))) {
|
|
1423
1554
|
continue outer;
|
|
1424
1555
|
}
|
|
1425
1556
|
}
|
|
@@ -2993,12 +3124,12 @@ lodash.exports;
|
|
|
2993
3124
|
}
|
|
2994
3125
|
function memoizeCapped2(func) {
|
|
2995
3126
|
var result2 = memoize2(func, function(key) {
|
|
2996
|
-
if (
|
|
2997
|
-
|
|
3127
|
+
if (cache2.size === MAX_MEMOIZE_SIZE2) {
|
|
3128
|
+
cache2.clear();
|
|
2998
3129
|
}
|
|
2999
3130
|
return key;
|
|
3000
3131
|
});
|
|
3001
|
-
var
|
|
3132
|
+
var cache2 = result2.cache;
|
|
3002
3133
|
return result2;
|
|
3003
3134
|
}
|
|
3004
3135
|
function mergeData(data, source) {
|
|
@@ -3952,12 +4083,12 @@ lodash.exports;
|
|
|
3952
4083
|
throw new TypeError2(FUNC_ERROR_TEXT2);
|
|
3953
4084
|
}
|
|
3954
4085
|
var memoized = function() {
|
|
3955
|
-
var args = arguments, key = resolver ? resolver.apply(this, args) : args[0],
|
|
3956
|
-
if (
|
|
3957
|
-
return
|
|
4086
|
+
var args = arguments, key = resolver ? resolver.apply(this, args) : args[0], cache2 = memoized.cache;
|
|
4087
|
+
if (cache2.has(key)) {
|
|
4088
|
+
return cache2.get(key);
|
|
3958
4089
|
}
|
|
3959
4090
|
var result2 = func.apply(this, args);
|
|
3960
|
-
memoized.cache =
|
|
4091
|
+
memoized.cache = cache2.set(key, result2) || cache2;
|
|
3961
4092
|
return result2;
|
|
3962
4093
|
};
|
|
3963
4094
|
memoized.cache = new (memoize2.Cache || MapCache2)();
|
|
@@ -9219,7 +9350,7 @@ function baseConvert(util2, name, func, options) {
|
|
|
9219
9350
|
throw new TypeError();
|
|
9220
9351
|
}
|
|
9221
9352
|
options || (options = {});
|
|
9222
|
-
var
|
|
9353
|
+
var config2 = {
|
|
9223
9354
|
"cap": "cap" in options ? options.cap : true,
|
|
9224
9355
|
"curry": "curry" in options ? options.curry : true,
|
|
9225
9356
|
"fixed": "fixed" in options ? options.fixed : true,
|
|
@@ -9255,7 +9386,7 @@ function baseConvert(util2, name, func, options) {
|
|
|
9255
9386
|
"iteratee": function(iteratee) {
|
|
9256
9387
|
return function() {
|
|
9257
9388
|
var func2 = arguments[0], arity = arguments[1], result = iteratee(func2, arity), length = result.length;
|
|
9258
|
-
if (
|
|
9389
|
+
if (config2.cap && typeof arity == "number") {
|
|
9259
9390
|
arity = arity > 2 ? arity - 2 : 1;
|
|
9260
9391
|
return length && length <= arity ? result : baseAry(result, arity);
|
|
9261
9392
|
}
|
|
@@ -9305,7 +9436,7 @@ function baseConvert(util2, name, func, options) {
|
|
|
9305
9436
|
}
|
|
9306
9437
|
};
|
|
9307
9438
|
function castCap(name2, func2) {
|
|
9308
|
-
if (
|
|
9439
|
+
if (config2.cap) {
|
|
9309
9440
|
var indexes = mapping.iterateeRearg[name2];
|
|
9310
9441
|
if (indexes) {
|
|
9311
9442
|
return iterateeRearg(func2, indexes);
|
|
@@ -9318,17 +9449,17 @@ function baseConvert(util2, name, func, options) {
|
|
|
9318
9449
|
return func2;
|
|
9319
9450
|
}
|
|
9320
9451
|
function castCurry(name2, func2, n) {
|
|
9321
|
-
return forceCurry ||
|
|
9452
|
+
return forceCurry || config2.curry && n > 1 ? curry(func2, n) : func2;
|
|
9322
9453
|
}
|
|
9323
9454
|
function castFixed(name2, func2, n) {
|
|
9324
|
-
if (
|
|
9455
|
+
if (config2.fixed && (forceFixed || !mapping.skipFixed[name2])) {
|
|
9325
9456
|
var data = mapping.methodSpread[name2], start = data && data.start;
|
|
9326
9457
|
return start === void 0 ? ary(func2, n) : flatSpread(func2, start);
|
|
9327
9458
|
}
|
|
9328
9459
|
return func2;
|
|
9329
9460
|
}
|
|
9330
9461
|
function castRearg(name2, func2, n) {
|
|
9331
|
-
return
|
|
9462
|
+
return config2.rearg && n > 1 && (forceRearg || !mapping.skipRearg[name2]) ? rearg(func2, mapping.methodRearg[name2] || mapping.aryRearg[n]) : func2;
|
|
9332
9463
|
}
|
|
9333
9464
|
function cloneByPath(object2, path2) {
|
|
9334
9465
|
path2 = toPath(path2);
|
|
@@ -9373,7 +9504,7 @@ function baseConvert(util2, name, func, options) {
|
|
|
9373
9504
|
while (length--) {
|
|
9374
9505
|
args[length] = arguments[length];
|
|
9375
9506
|
}
|
|
9376
|
-
var index2 =
|
|
9507
|
+
var index2 = config2.rearg ? 0 : length - 1;
|
|
9377
9508
|
args[index2] = transform2(args[index2]);
|
|
9378
9509
|
return func2.apply(void 0, args);
|
|
9379
9510
|
};
|
|
@@ -9382,7 +9513,7 @@ function baseConvert(util2, name, func, options) {
|
|
|
9382
9513
|
var result, realName = mapping.aliasToReal[name2] || name2, wrapped = func2, wrapper = wrappers[realName];
|
|
9383
9514
|
if (wrapper) {
|
|
9384
9515
|
wrapped = wrapper(func2);
|
|
9385
|
-
} else if (
|
|
9516
|
+
} else if (config2.immutable) {
|
|
9386
9517
|
if (mapping.mutate.array[realName]) {
|
|
9387
9518
|
wrapped = wrapImmutable(func2, cloneArray);
|
|
9388
9519
|
} else if (mapping.mutate.object[realName]) {
|
|
@@ -10674,12 +10805,12 @@ function memoize$1(func, resolver) {
|
|
|
10674
10805
|
throw new TypeError(FUNC_ERROR_TEXT);
|
|
10675
10806
|
}
|
|
10676
10807
|
var memoized = function() {
|
|
10677
|
-
var args = arguments, key = resolver ? resolver.apply(this, args) : args[0],
|
|
10678
|
-
if (
|
|
10679
|
-
return
|
|
10808
|
+
var args = arguments, key = resolver ? resolver.apply(this, args) : args[0], cache2 = memoized.cache;
|
|
10809
|
+
if (cache2.has(key)) {
|
|
10810
|
+
return cache2.get(key);
|
|
10680
10811
|
}
|
|
10681
10812
|
var result = func.apply(this, args);
|
|
10682
|
-
memoized.cache =
|
|
10813
|
+
memoized.cache = cache2.set(key, result) || cache2;
|
|
10683
10814
|
return result;
|
|
10684
10815
|
};
|
|
10685
10816
|
memoized.cache = new (memoize$1.Cache || MapCache$2)();
|
|
@@ -10691,12 +10822,12 @@ var memoize = memoize_1;
|
|
|
10691
10822
|
var MAX_MEMOIZE_SIZE = 500;
|
|
10692
10823
|
function memoizeCapped$1(func) {
|
|
10693
10824
|
var result = memoize(func, function(key) {
|
|
10694
|
-
if (
|
|
10695
|
-
|
|
10825
|
+
if (cache2.size === MAX_MEMOIZE_SIZE) {
|
|
10826
|
+
cache2.clear();
|
|
10696
10827
|
}
|
|
10697
10828
|
return key;
|
|
10698
10829
|
});
|
|
10699
|
-
var
|
|
10830
|
+
var cache2 = result.cache;
|
|
10700
10831
|
return result;
|
|
10701
10832
|
}
|
|
10702
10833
|
var _memoizeCapped = memoizeCapped$1;
|
|
@@ -11198,8 +11329,8 @@ function arraySome$1(array2, predicate) {
|
|
|
11198
11329
|
return false;
|
|
11199
11330
|
}
|
|
11200
11331
|
var _arraySome = arraySome$1;
|
|
11201
|
-
function cacheHas$1(
|
|
11202
|
-
return
|
|
11332
|
+
function cacheHas$1(cache2, key) {
|
|
11333
|
+
return cache2.has(key);
|
|
11203
11334
|
}
|
|
11204
11335
|
var _cacheHas = cacheHas$1;
|
|
11205
11336
|
var SetCache = _SetCache, arraySome = _arraySome, cacheHas = _cacheHas;
|
|
@@ -11824,7 +11955,7 @@ function _objectWithoutPropertiesLoose(source, excluded) {
|
|
|
11824
11955
|
}
|
|
11825
11956
|
return target;
|
|
11826
11957
|
}
|
|
11827
|
-
function createValidation(
|
|
11958
|
+
function createValidation(config2) {
|
|
11828
11959
|
function validate(_ref, cb) {
|
|
11829
11960
|
let {
|
|
11830
11961
|
value,
|
|
@@ -11839,7 +11970,7 @@ function createValidation(config) {
|
|
|
11839
11970
|
test,
|
|
11840
11971
|
params,
|
|
11841
11972
|
message
|
|
11842
|
-
} =
|
|
11973
|
+
} = config2;
|
|
11843
11974
|
let {
|
|
11844
11975
|
parent,
|
|
11845
11976
|
context
|
|
@@ -11894,7 +12025,7 @@ function createValidation(config) {
|
|
|
11894
12025
|
else if (!result) cb(createError());
|
|
11895
12026
|
else cb(null, result);
|
|
11896
12027
|
}
|
|
11897
|
-
validate.OPTIONS =
|
|
12028
|
+
validate.OPTIONS = config2;
|
|
11898
12029
|
return validate;
|
|
11899
12030
|
}
|
|
11900
12031
|
let trim = (part) => part.substr(0, part.length - 1).substr(1);
|
|
@@ -24584,7 +24715,7 @@ const isPopulateString = (value) => {
|
|
|
24584
24715
|
};
|
|
24585
24716
|
const isStringArray$1 = (value) => fp.isArray(value) && value.every(fp.isString);
|
|
24586
24717
|
const isObj = (value) => fp.isObject(value);
|
|
24587
|
-
const populate$
|
|
24718
|
+
const populate$2 = traverseFactory().intercept(isPopulateString, async (visitor2, options, populate2, { recurse }) => {
|
|
24588
24719
|
const populateObject = pathsToObjectPopulate([populate2]);
|
|
24589
24720
|
const traversedPopulate = await recurse(visitor2, options, populateObject);
|
|
24590
24721
|
const [result] = objectPopulateToPaths(traversedPopulate);
|
|
@@ -24752,7 +24883,7 @@ const populate$1 = traverseFactory().intercept(isPopulateString, async (visitor2
|
|
|
24752
24883
|
}
|
|
24753
24884
|
}
|
|
24754
24885
|
);
|
|
24755
|
-
const traverseQueryPopulate = fp.curry(populate$
|
|
24886
|
+
const traverseQueryPopulate = fp.curry(populate$2.traverse);
|
|
24756
24887
|
const objectPopulateToPaths = (input) => {
|
|
24757
24888
|
const paths = [];
|
|
24758
24889
|
function traverse(currentObj, parentPath) {
|
|
@@ -25072,54 +25203,40 @@ const hasValue = (value) => {
|
|
|
25072
25203
|
return !(value === null || value === void 0 || Array.isArray(value) && value.length === 0 || typeof value === "object" && isEmpty(value));
|
|
25073
25204
|
};
|
|
25074
25205
|
async function _populateComponent({
|
|
25075
|
-
mainUid,
|
|
25076
|
-
mainDocumentId,
|
|
25077
|
-
schema: schema2,
|
|
25078
25206
|
populate: populate2 = {},
|
|
25079
25207
|
lookup,
|
|
25208
|
+
attrName,
|
|
25080
25209
|
inDynamicZone = false,
|
|
25081
|
-
|
|
25082
|
-
omitEmpty
|
|
25210
|
+
...params
|
|
25083
25211
|
}) {
|
|
25084
|
-
const attrName = lookup.pop();
|
|
25085
25212
|
const componentLookup = lookup.length === 0 ? [attrName] : [...lookup, inDynamicZone ? "on" : "populate", attrName];
|
|
25086
|
-
const componentPopulate =
|
|
25213
|
+
const componentPopulate = populate2;
|
|
25087
25214
|
merge$1.dset(componentPopulate, componentLookup, { populate: "*" });
|
|
25088
25215
|
const nestedPopulate = await _populate({
|
|
25089
|
-
mainUid,
|
|
25090
|
-
mainDocumentId,
|
|
25091
|
-
schema: schema2,
|
|
25092
25216
|
populate: componentPopulate,
|
|
25093
25217
|
lookup: componentLookup,
|
|
25094
|
-
|
|
25095
|
-
omitEmpty
|
|
25218
|
+
...params
|
|
25096
25219
|
});
|
|
25097
25220
|
return isEmpty(nestedPopulate) ? true : { populate: nestedPopulate };
|
|
25098
25221
|
}
|
|
25099
25222
|
async function _populateDynamicZone({
|
|
25100
|
-
mainUid,
|
|
25101
|
-
mainDocumentId,
|
|
25102
25223
|
components,
|
|
25103
|
-
populate: populate2,
|
|
25104
25224
|
lookup,
|
|
25105
|
-
|
|
25106
|
-
|
|
25225
|
+
attrName,
|
|
25226
|
+
...params
|
|
25107
25227
|
}) {
|
|
25108
|
-
const
|
|
25109
|
-
|
|
25110
|
-
|
|
25111
|
-
|
|
25112
|
-
schema:
|
|
25113
|
-
|
|
25114
|
-
|
|
25228
|
+
const dynamicZoneLookup = [...lookup, attrName];
|
|
25229
|
+
const resolvedPopulate = {};
|
|
25230
|
+
for (const component of components) {
|
|
25231
|
+
const componentPopulate = await _populateComponent({
|
|
25232
|
+
schema: component,
|
|
25233
|
+
lookup: dynamicZoneLookup,
|
|
25234
|
+
attrName: component,
|
|
25115
25235
|
inDynamicZone: true,
|
|
25116
|
-
|
|
25117
|
-
omitEmpty
|
|
25236
|
+
...params
|
|
25118
25237
|
});
|
|
25119
|
-
|
|
25120
|
-
|
|
25121
|
-
return newPop;
|
|
25122
|
-
}, Promise.resolve({}));
|
|
25238
|
+
merge$1.dset(resolvedPopulate, [component], componentPopulate);
|
|
25239
|
+
}
|
|
25123
25240
|
if (isEmpty(resolvedPopulate)) return void 0;
|
|
25124
25241
|
return { on: resolvedPopulate };
|
|
25125
25242
|
}
|
|
@@ -25130,18 +25247,23 @@ async function _populateRelation({
|
|
|
25130
25247
|
contentType,
|
|
25131
25248
|
relation,
|
|
25132
25249
|
resolvedRelations,
|
|
25133
|
-
omitEmpty
|
|
25250
|
+
omitEmpty,
|
|
25251
|
+
locale: locale2,
|
|
25252
|
+
status: status2
|
|
25134
25253
|
}) {
|
|
25135
25254
|
const isSingleRelation = !Array.isArray(relation);
|
|
25136
25255
|
const relations = isSingleRelation ? [relation] : relation;
|
|
25137
|
-
|
|
25256
|
+
const nonResolvedRelations = relations.filter(({ documentId }) => !resolvedRelations.has(documentId));
|
|
25257
|
+
for (const relation2 of nonResolvedRelations) {
|
|
25138
25258
|
resolvedRelations.set(relation2.documentId, {});
|
|
25139
25259
|
const relationPopulate = await _populate({
|
|
25140
|
-
|
|
25141
|
-
|
|
25260
|
+
contentType,
|
|
25261
|
+
documentId: relation2.documentId,
|
|
25142
25262
|
schema: contentType,
|
|
25143
25263
|
resolvedRelations,
|
|
25144
|
-
omitEmpty
|
|
25264
|
+
omitEmpty,
|
|
25265
|
+
locale: locale2,
|
|
25266
|
+
status: status2
|
|
25145
25267
|
});
|
|
25146
25268
|
resolvedRelations.set(relation2.documentId, relationPopulate);
|
|
25147
25269
|
}
|
|
@@ -25171,7 +25293,7 @@ const _resolveValue = ({ document: document2, lookup, attrName }) => {
|
|
|
25171
25293
|
const childLookup = lookup[populateIdx + 1];
|
|
25172
25294
|
const parentValue2 = delve__default.default(document2, parentLookup);
|
|
25173
25295
|
const childValue = (Array.isArray(parentValue2) ? parentValue2 : [parentValue2]).map(
|
|
25174
|
-
(v) => _resolveValue({ document:
|
|
25296
|
+
(v) => _resolveValue({ document: v, lookup: childLookup, attrName })
|
|
25175
25297
|
);
|
|
25176
25298
|
return childValue.find((v) => hasValue(v));
|
|
25177
25299
|
}
|
|
@@ -25182,18 +25304,18 @@ const _resolveValue = ({ document: document2, lookup, attrName }) => {
|
|
|
25182
25304
|
return parentValue?.[attrName];
|
|
25183
25305
|
};
|
|
25184
25306
|
async function _populate({
|
|
25185
|
-
|
|
25186
|
-
mainDocumentId,
|
|
25307
|
+
contentType,
|
|
25187
25308
|
schema: schema2,
|
|
25188
25309
|
populate: populate2 = {},
|
|
25189
25310
|
lookup = [],
|
|
25190
|
-
resolvedRelations
|
|
25191
|
-
omitEmpty
|
|
25311
|
+
resolvedRelations,
|
|
25312
|
+
omitEmpty,
|
|
25313
|
+
...params
|
|
25192
25314
|
}) {
|
|
25193
25315
|
const newPopulate = {};
|
|
25194
|
-
|
|
25195
|
-
|
|
25196
|
-
|
|
25316
|
+
let relations = getRelations(strapi.getModel(schema2));
|
|
25317
|
+
let currentPopulate = json$1.klona(populate2);
|
|
25318
|
+
resolvedRelations.set(params.documentId, true);
|
|
25197
25319
|
for (const [attrName] of relations) {
|
|
25198
25320
|
if (lookup.length > 0) {
|
|
25199
25321
|
const parent = delve__default.default(currentPopulate, lookup);
|
|
@@ -25204,47 +25326,56 @@ async function _populate({
|
|
|
25204
25326
|
merge$1.dset(currentPopulate, attrName, { populate: "*" });
|
|
25205
25327
|
}
|
|
25206
25328
|
}
|
|
25207
|
-
|
|
25208
|
-
|
|
25329
|
+
let document2 = await strapi.documents(contentType).findOne({
|
|
25330
|
+
...params,
|
|
25209
25331
|
populate: currentPopulate ? currentPopulate : "*"
|
|
25210
25332
|
});
|
|
25333
|
+
currentPopulate = null;
|
|
25334
|
+
const resolveRelations = [];
|
|
25211
25335
|
for (const [attrName, attr] of relations) {
|
|
25212
25336
|
const value = _resolveValue({ document: document2, attrName, lookup });
|
|
25213
25337
|
if (!hasValue(value)) {
|
|
25214
25338
|
if (!omitEmpty) newPopulate[attrName] = true;
|
|
25215
25339
|
continue;
|
|
25216
25340
|
}
|
|
25341
|
+
resolveRelations.push([attrName, attr, value]);
|
|
25342
|
+
}
|
|
25343
|
+
relations = null;
|
|
25344
|
+
document2 = null;
|
|
25345
|
+
for (const [attrName, attr, value] of resolveRelations) {
|
|
25217
25346
|
if (contentTypes.isDynamicZoneAttribute(attr)) {
|
|
25218
25347
|
const relComponents = value.map(
|
|
25219
25348
|
(dataComponent) => attr.components.find((schemaComponent) => schemaComponent === dataComponent.__component)
|
|
25220
25349
|
);
|
|
25221
25350
|
newPopulate[attrName] = await _populateDynamicZone({
|
|
25222
|
-
|
|
25223
|
-
mainDocumentId,
|
|
25351
|
+
contentType,
|
|
25224
25352
|
components: relComponents,
|
|
25225
|
-
lookup
|
|
25353
|
+
lookup,
|
|
25354
|
+
attrName,
|
|
25226
25355
|
resolvedRelations,
|
|
25227
|
-
omitEmpty
|
|
25356
|
+
omitEmpty,
|
|
25357
|
+
...params
|
|
25228
25358
|
});
|
|
25229
25359
|
}
|
|
25230
25360
|
if (contentTypes.isRelationalAttribute(attr)) {
|
|
25231
|
-
const { target: relContentType } = attr;
|
|
25232
|
-
resolvedRelations.set(mainDocumentId, true);
|
|
25233
25361
|
newPopulate[attrName] = await _populateRelation({
|
|
25234
|
-
contentType:
|
|
25362
|
+
contentType: attr.target,
|
|
25235
25363
|
relation: value,
|
|
25236
25364
|
resolvedRelations,
|
|
25237
|
-
omitEmpty
|
|
25365
|
+
omitEmpty,
|
|
25366
|
+
locale: params.locale,
|
|
25367
|
+
status: params.status
|
|
25238
25368
|
});
|
|
25239
25369
|
}
|
|
25240
25370
|
if (contentTypes.isComponentAttribute(attr) && !contentTypes.isDynamicZoneAttribute(attr)) {
|
|
25241
25371
|
newPopulate[attrName] = await _populateComponent({
|
|
25242
|
-
|
|
25243
|
-
mainDocumentId,
|
|
25372
|
+
contentType,
|
|
25244
25373
|
schema: attr.component,
|
|
25245
|
-
lookup
|
|
25374
|
+
lookup,
|
|
25375
|
+
attrName,
|
|
25246
25376
|
resolvedRelations,
|
|
25247
|
-
omitEmpty
|
|
25377
|
+
omitEmpty,
|
|
25378
|
+
...params
|
|
25248
25379
|
});
|
|
25249
25380
|
}
|
|
25250
25381
|
if (contentTypes.isMediaAttribute(attr)) {
|
|
@@ -25253,42 +25384,30 @@ async function _populate({
|
|
|
25253
25384
|
}
|
|
25254
25385
|
return newPopulate;
|
|
25255
25386
|
}
|
|
25387
|
+
async function populate$1(params) {
|
|
25388
|
+
const resolvedRelations = /* @__PURE__ */ new Map();
|
|
25389
|
+
const populated = await _populate({ ...params, schema: params.contentType, resolvedRelations });
|
|
25390
|
+
return { populate: populated, dependencies: [...resolvedRelations.keys()] };
|
|
25391
|
+
}
|
|
25256
25392
|
const populate = ({ strapi: strapi2 }) => ({
|
|
25257
|
-
async get({
|
|
25258
|
-
|
|
25259
|
-
|
|
25260
|
-
|
|
25261
|
-
|
|
25262
|
-
|
|
25263
|
-
|
|
25264
|
-
|
|
25265
|
-
strapi2.documents(contentType);
|
|
25266
|
-
const { findOne, ...wrapped } = strapi2.documents(contentType);
|
|
25267
|
-
const wrappedFindOne = async (params) => {
|
|
25268
|
-
const { documentId, populate: originalPopulate } = params;
|
|
25269
|
-
const deepPopulate = await _populate({
|
|
25270
|
-
mainUid: contentType,
|
|
25271
|
-
mainDocumentId: documentId,
|
|
25272
|
-
schema: contentType,
|
|
25273
|
-
omitEmpty: originalPopulate !== "*"
|
|
25274
|
-
});
|
|
25275
|
-
if (originalPopulate && originalPopulate !== "*") {
|
|
25276
|
-
strapi2.log.warn(
|
|
25277
|
-
`passed "populate" will be merged with deepPopulate, which could result in unexpected behavior.`
|
|
25278
|
-
);
|
|
25279
|
-
if (typeof originalPopulate === "object")
|
|
25280
|
-
Object.keys(originalPopulate).map((k) => merge$1.dset(deepPopulate, k, originalPopulate[k]));
|
|
25281
|
-
if (Array.isArray(originalPopulate)) originalPopulate.map((k) => merge$1.dset(deepPopulate, k, true));
|
|
25282
|
-
}
|
|
25283
|
-
return await findOne({ ...params, populate: deepPopulate });
|
|
25284
|
-
};
|
|
25285
|
-
return { ...wrapped, findOne: wrappedFindOne };
|
|
25393
|
+
async get(params) {
|
|
25394
|
+
const { cachePopulate } = strapi2.config.get("plugin::deep-populate");
|
|
25395
|
+
if (!cachePopulate) return (await populate$1(params)).populate;
|
|
25396
|
+
const cachedEntry = await strapi2.service("plugin::deep-populate.cache").get(params);
|
|
25397
|
+
if (cachedEntry) return cachedEntry;
|
|
25398
|
+
const resolved = await populate$1(params);
|
|
25399
|
+
await strapi2.service("plugin::deep-populate.cache").set({ ...params, ...resolved });
|
|
25400
|
+
return resolved;
|
|
25286
25401
|
}
|
|
25287
25402
|
});
|
|
25288
25403
|
const services = {
|
|
25289
|
-
populate
|
|
25404
|
+
populate,
|
|
25405
|
+
cache
|
|
25290
25406
|
};
|
|
25291
25407
|
const index = {
|
|
25292
|
-
|
|
25408
|
+
config,
|
|
25409
|
+
contentTypes: contentTypes$1,
|
|
25410
|
+
services,
|
|
25411
|
+
register
|
|
25293
25412
|
};
|
|
25294
25413
|
module.exports = index;
|