strapi-plugin-bulk-updater 1.3.0 → 1.3.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/dist/server/index.js +73 -43
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +73 -43
- package/dist/server/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/server/index.mjs
CHANGED
|
@@ -681,15 +681,20 @@ const MAX_QUERY_CACHE_SIZE = 500;
|
|
|
681
681
|
const CACHE_TTL_MS = 60 * 1e3;
|
|
682
682
|
let staticSchemaCache = null;
|
|
683
683
|
function buildDeepPopulate$1(attributes, allComponents, depth2 = 0) {
|
|
684
|
-
if (depth2 > 5) return
|
|
684
|
+
if (depth2 > 5) return void 0;
|
|
685
685
|
const populate2 = {};
|
|
686
686
|
for (const [key, def] of Object.entries(attributes || {})) {
|
|
687
687
|
if (def.type === "component" && def.component) {
|
|
688
688
|
const comp = allComponents[def.component];
|
|
689
689
|
if (comp?.attributes) {
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
690
|
+
const subPopulate = buildDeepPopulate$1(comp.attributes, allComponents, depth2 + 1);
|
|
691
|
+
if (subPopulate && Object.keys(subPopulate).length > 0) {
|
|
692
|
+
populate2[key] = {
|
|
693
|
+
populate: subPopulate
|
|
694
|
+
};
|
|
695
|
+
} else {
|
|
696
|
+
populate2[key] = true;
|
|
697
|
+
}
|
|
693
698
|
} else {
|
|
694
699
|
populate2[key] = true;
|
|
695
700
|
}
|
|
@@ -699,7 +704,7 @@ function buildDeepPopulate$1(attributes, allComponents, depth2 = 0) {
|
|
|
699
704
|
populate2[key] = true;
|
|
700
705
|
}
|
|
701
706
|
}
|
|
702
|
-
return Object.keys(populate2).length > 0 ? populate2 :
|
|
707
|
+
return Object.keys(populate2).length > 0 ? populate2 : void 0;
|
|
703
708
|
}
|
|
704
709
|
function discoverComponentAttributes(strapi2, compUid, prefix, currentDepth, maxDepth, systemFields, allContentTypes, relationsByAttr, allRelationsMeta, attributesMeta) {
|
|
705
710
|
if (currentDepth > maxDepth || !compUid) return [];
|
|
@@ -1016,10 +1021,12 @@ async function executeBatchInternal(strapi2, {
|
|
|
1016
1021
|
const hasAttribute = Boolean(attrDef) || isComponentNested;
|
|
1017
1022
|
if (hasAttribute) {
|
|
1018
1023
|
if (isComponentNested) {
|
|
1019
|
-
const
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1024
|
+
const populateOption = buildDeepPopulate$1(contentType.attributes, strapi2.components);
|
|
1025
|
+
const findOneArgs = { documentId: target.documentId };
|
|
1026
|
+
if (populateOption) {
|
|
1027
|
+
findOneArgs.populate = populateOption;
|
|
1028
|
+
}
|
|
1029
|
+
const currentEntryWithPopulate = await strapi2.documents(target.uid).findOne(findOneArgs);
|
|
1023
1030
|
const existingRoot = currentEntryWithPopulate?.[rootKey] || {};
|
|
1024
1031
|
const currentVal2 = getDeepProperty(existingRoot, parts.slice(1).join("."));
|
|
1025
1032
|
let newValue2 = value;
|
|
@@ -1572,20 +1579,25 @@ const bulkUpdaterService = ({ strapi: strapi2 }) => {
|
|
|
1572
1579
|
try {
|
|
1573
1580
|
const populateOption = buildDeepPopulate$1(allContentTypes[uid]?.attributes || {}, strapi2.components);
|
|
1574
1581
|
if (meta.isSingleType) {
|
|
1575
|
-
const
|
|
1576
|
-
|
|
1577
|
-
|
|
1582
|
+
const singleArgs = {};
|
|
1583
|
+
if (populateOption) {
|
|
1584
|
+
singleArgs.populate = populateOption;
|
|
1585
|
+
}
|
|
1586
|
+
const singleDoc = await strapi2.documents(uid).findFirst(singleArgs);
|
|
1578
1587
|
if (singleDoc) {
|
|
1579
1588
|
entries = [singleDoc];
|
|
1580
1589
|
totalCount = 1;
|
|
1581
1590
|
}
|
|
1582
1591
|
} else {
|
|
1583
1592
|
totalCount = await strapi2.documents(uid).count();
|
|
1584
|
-
|
|
1593
|
+
const findArgs = {
|
|
1585
1594
|
limit: 10,
|
|
1586
|
-
sort: { createdAt: "desc" }
|
|
1587
|
-
|
|
1588
|
-
|
|
1595
|
+
sort: { createdAt: "desc" }
|
|
1596
|
+
};
|
|
1597
|
+
if (populateOption) {
|
|
1598
|
+
findArgs.populate = populateOption;
|
|
1599
|
+
}
|
|
1600
|
+
entries = await strapi2.documents(uid).findMany(findArgs);
|
|
1589
1601
|
}
|
|
1590
1602
|
} catch (err) {
|
|
1591
1603
|
strapi2.log.error(`[bulk-updater] Failed to fetch entries for ${uid}:`, err);
|
|
@@ -1784,10 +1796,13 @@ const bulkUpdaterService = ({ strapi: strapi2 }) => {
|
|
|
1784
1796
|
if (isSingleType) {
|
|
1785
1797
|
let singleDoc = null;
|
|
1786
1798
|
try {
|
|
1787
|
-
|
|
1788
|
-
filters: Object.keys(filters2).length > 0 ? filters2 : void 0
|
|
1789
|
-
|
|
1790
|
-
|
|
1799
|
+
const singleArgs = {
|
|
1800
|
+
filters: Object.keys(filters2).length > 0 ? filters2 : void 0
|
|
1801
|
+
};
|
|
1802
|
+
if (populateOption) {
|
|
1803
|
+
singleArgs.populate = populateOption;
|
|
1804
|
+
}
|
|
1805
|
+
singleDoc = await strapi2.documents(uid).findFirst(singleArgs);
|
|
1791
1806
|
} catch {
|
|
1792
1807
|
singleDoc = null;
|
|
1793
1808
|
}
|
|
@@ -1818,14 +1833,17 @@ const bulkUpdaterService = ({ strapi: strapi2 }) => {
|
|
|
1818
1833
|
} else {
|
|
1819
1834
|
sortClause["createdAt"] = "desc";
|
|
1820
1835
|
}
|
|
1836
|
+
const findManyArgs = {
|
|
1837
|
+
start,
|
|
1838
|
+
limit,
|
|
1839
|
+
filters: Object.keys(filters2).length > 0 ? filters2 : void 0,
|
|
1840
|
+
sort: sortClause
|
|
1841
|
+
};
|
|
1842
|
+
if (populateOption) {
|
|
1843
|
+
findManyArgs.populate = populateOption;
|
|
1844
|
+
}
|
|
1821
1845
|
const [entries, totalEntries] = await Promise.all([
|
|
1822
|
-
strapi2.documents(uid).findMany(
|
|
1823
|
-
start,
|
|
1824
|
-
limit,
|
|
1825
|
-
filters: Object.keys(filters2).length > 0 ? filters2 : void 0,
|
|
1826
|
-
sort: sortClause,
|
|
1827
|
-
populate: populateOption
|
|
1828
|
-
}),
|
|
1846
|
+
strapi2.documents(uid).findMany(findManyArgs),
|
|
1829
1847
|
strapi2.documents(uid).count({
|
|
1830
1848
|
filters: Object.keys(filters2).length > 0 ? filters2 : void 0
|
|
1831
1849
|
})
|
|
@@ -1962,10 +1980,12 @@ const bulkUpdaterService = ({ strapi: strapi2 }) => {
|
|
|
1962
1980
|
}
|
|
1963
1981
|
let currentEntry;
|
|
1964
1982
|
if (isComponentNested) {
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1983
|
+
const findOneArgs = { documentId: target.documentId };
|
|
1984
|
+
const populateOption = buildDeepPopulate$1(contentType.attributes, strapi2.components);
|
|
1985
|
+
if (populateOption) {
|
|
1986
|
+
findOneArgs.populate = populateOption;
|
|
1987
|
+
}
|
|
1988
|
+
currentEntry = await strapi2.documents(target.uid).findOne(findOneArgs);
|
|
1969
1989
|
} else if (attrDef?.type === "relation") {
|
|
1970
1990
|
currentEntry = await strapi2.documents(target.uid).findOne({
|
|
1971
1991
|
documentId: target.documentId,
|
|
@@ -3714,15 +3734,20 @@ function discoverExportFields(ct, allComponents, maxDepth = 4) {
|
|
|
3714
3734
|
return fields2;
|
|
3715
3735
|
}
|
|
3716
3736
|
function buildDeepPopulate(attributes, allComponents, depth2 = 0) {
|
|
3717
|
-
if (depth2 >
|
|
3737
|
+
if (depth2 > 5) return void 0;
|
|
3718
3738
|
const populate2 = {};
|
|
3719
3739
|
for (const [key, def] of Object.entries(attributes || {})) {
|
|
3720
3740
|
if (def.type === "component" && def.component) {
|
|
3721
3741
|
const comp = allComponents[def.component];
|
|
3722
3742
|
if (comp?.attributes) {
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
|
|
3743
|
+
const subPopulate = buildDeepPopulate(comp.attributes, allComponents, depth2 + 1);
|
|
3744
|
+
if (subPopulate && Object.keys(subPopulate).length > 0) {
|
|
3745
|
+
populate2[key] = {
|
|
3746
|
+
populate: subPopulate
|
|
3747
|
+
};
|
|
3748
|
+
} else {
|
|
3749
|
+
populate2[key] = true;
|
|
3750
|
+
}
|
|
3726
3751
|
} else {
|
|
3727
3752
|
populate2[key] = true;
|
|
3728
3753
|
}
|
|
@@ -3732,7 +3757,7 @@ function buildDeepPopulate(attributes, allComponents, depth2 = 0) {
|
|
|
3732
3757
|
populate2[key] = true;
|
|
3733
3758
|
}
|
|
3734
3759
|
}
|
|
3735
|
-
return Object.keys(populate2).length > 0 ? populate2 :
|
|
3760
|
+
return Object.keys(populate2).length > 0 ? populate2 : void 0;
|
|
3736
3761
|
}
|
|
3737
3762
|
function getNestedExportValue(entry, path2) {
|
|
3738
3763
|
if (!entry || !path2) return "";
|
|
@@ -3899,17 +3924,22 @@ const csvService = ({ strapi: strapi2 }) => ({
|
|
|
3899
3924
|
const deepPopulate = buildDeepPopulate(ct.attributes || {}, allComponents);
|
|
3900
3925
|
let entries = [];
|
|
3901
3926
|
if (ct.kind === "singleType") {
|
|
3902
|
-
const
|
|
3903
|
-
|
|
3904
|
-
|
|
3927
|
+
const findFirstArgs = {};
|
|
3928
|
+
if (deepPopulate) {
|
|
3929
|
+
findFirstArgs.populate = deepPopulate;
|
|
3930
|
+
}
|
|
3931
|
+
const doc = await strapi2.documents(uid).findFirst(findFirstArgs);
|
|
3905
3932
|
entries = doc ? [doc] : [];
|
|
3906
3933
|
} else {
|
|
3907
|
-
|
|
3934
|
+
const findManyArgs = {
|
|
3908
3935
|
filters: Object.keys(filters2).length > 0 ? filters2 : void 0,
|
|
3909
3936
|
limit: options.limit || 5e3,
|
|
3910
|
-
sort: { createdAt: "desc" }
|
|
3911
|
-
|
|
3912
|
-
|
|
3937
|
+
sort: { createdAt: "desc" }
|
|
3938
|
+
};
|
|
3939
|
+
if (deepPopulate) {
|
|
3940
|
+
findManyArgs.populate = deepPopulate;
|
|
3941
|
+
}
|
|
3942
|
+
entries = await strapi2.documents(uid).findMany(findManyArgs);
|
|
3913
3943
|
}
|
|
3914
3944
|
const lines = [];
|
|
3915
3945
|
lines.push(fields2.map((f) => escapeCsvValue(f.key)).join(","));
|