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.
@@ -694,15 +694,20 @@ const MAX_QUERY_CACHE_SIZE = 500;
694
694
  const CACHE_TTL_MS = 60 * 1e3;
695
695
  let staticSchemaCache = null;
696
696
  function buildDeepPopulate$1(attributes, allComponents, depth2 = 0) {
697
- if (depth2 > 5) return true;
697
+ if (depth2 > 5) return void 0;
698
698
  const populate2 = {};
699
699
  for (const [key, def] of Object.entries(attributes || {})) {
700
700
  if (def.type === "component" && def.component) {
701
701
  const comp = allComponents[def.component];
702
702
  if (comp?.attributes) {
703
- populate2[key] = {
704
- populate: buildDeepPopulate$1(comp.attributes, allComponents, depth2 + 1)
705
- };
703
+ const subPopulate = buildDeepPopulate$1(comp.attributes, allComponents, depth2 + 1);
704
+ if (subPopulate && Object.keys(subPopulate).length > 0) {
705
+ populate2[key] = {
706
+ populate: subPopulate
707
+ };
708
+ } else {
709
+ populate2[key] = true;
710
+ }
706
711
  } else {
707
712
  populate2[key] = true;
708
713
  }
@@ -712,7 +717,7 @@ function buildDeepPopulate$1(attributes, allComponents, depth2 = 0) {
712
717
  populate2[key] = true;
713
718
  }
714
719
  }
715
- return Object.keys(populate2).length > 0 ? populate2 : true;
720
+ return Object.keys(populate2).length > 0 ? populate2 : void 0;
716
721
  }
717
722
  function discoverComponentAttributes(strapi2, compUid, prefix, currentDepth, maxDepth, systemFields, allContentTypes, relationsByAttr, allRelationsMeta, attributesMeta) {
718
723
  if (currentDepth > maxDepth || !compUid) return [];
@@ -1029,10 +1034,12 @@ async function executeBatchInternal(strapi2, {
1029
1034
  const hasAttribute = Boolean(attrDef) || isComponentNested;
1030
1035
  if (hasAttribute) {
1031
1036
  if (isComponentNested) {
1032
- const currentEntryWithPopulate = await strapi2.documents(target.uid).findOne({
1033
- documentId: target.documentId,
1034
- populate: buildDeepPopulate$1(contentType.attributes, strapi2.components)
1035
- });
1037
+ const populateOption = buildDeepPopulate$1(contentType.attributes, strapi2.components);
1038
+ const findOneArgs = { documentId: target.documentId };
1039
+ if (populateOption) {
1040
+ findOneArgs.populate = populateOption;
1041
+ }
1042
+ const currentEntryWithPopulate = await strapi2.documents(target.uid).findOne(findOneArgs);
1036
1043
  const existingRoot = currentEntryWithPopulate?.[rootKey] || {};
1037
1044
  const currentVal2 = getDeepProperty(existingRoot, parts.slice(1).join("."));
1038
1045
  let newValue2 = value;
@@ -1585,20 +1592,25 @@ const bulkUpdaterService = ({ strapi: strapi2 }) => {
1585
1592
  try {
1586
1593
  const populateOption = buildDeepPopulate$1(allContentTypes[uid]?.attributes || {}, strapi2.components);
1587
1594
  if (meta.isSingleType) {
1588
- const singleDoc = await strapi2.documents(uid).findFirst({
1589
- populate: populateOption
1590
- });
1595
+ const singleArgs = {};
1596
+ if (populateOption) {
1597
+ singleArgs.populate = populateOption;
1598
+ }
1599
+ const singleDoc = await strapi2.documents(uid).findFirst(singleArgs);
1591
1600
  if (singleDoc) {
1592
1601
  entries = [singleDoc];
1593
1602
  totalCount = 1;
1594
1603
  }
1595
1604
  } else {
1596
1605
  totalCount = await strapi2.documents(uid).count();
1597
- entries = await strapi2.documents(uid).findMany({
1606
+ const findArgs = {
1598
1607
  limit: 10,
1599
- sort: { createdAt: "desc" },
1600
- populate: populateOption
1601
- });
1608
+ sort: { createdAt: "desc" }
1609
+ };
1610
+ if (populateOption) {
1611
+ findArgs.populate = populateOption;
1612
+ }
1613
+ entries = await strapi2.documents(uid).findMany(findArgs);
1602
1614
  }
1603
1615
  } catch (err) {
1604
1616
  strapi2.log.error(`[bulk-updater] Failed to fetch entries for ${uid}:`, err);
@@ -1797,10 +1809,13 @@ const bulkUpdaterService = ({ strapi: strapi2 }) => {
1797
1809
  if (isSingleType) {
1798
1810
  let singleDoc = null;
1799
1811
  try {
1800
- singleDoc = await strapi2.documents(uid).findFirst({
1801
- filters: Object.keys(filters2).length > 0 ? filters2 : void 0,
1802
- populate: populateOption
1803
- });
1812
+ const singleArgs = {
1813
+ filters: Object.keys(filters2).length > 0 ? filters2 : void 0
1814
+ };
1815
+ if (populateOption) {
1816
+ singleArgs.populate = populateOption;
1817
+ }
1818
+ singleDoc = await strapi2.documents(uid).findFirst(singleArgs);
1804
1819
  } catch {
1805
1820
  singleDoc = null;
1806
1821
  }
@@ -1831,14 +1846,17 @@ const bulkUpdaterService = ({ strapi: strapi2 }) => {
1831
1846
  } else {
1832
1847
  sortClause["createdAt"] = "desc";
1833
1848
  }
1849
+ const findManyArgs = {
1850
+ start,
1851
+ limit,
1852
+ filters: Object.keys(filters2).length > 0 ? filters2 : void 0,
1853
+ sort: sortClause
1854
+ };
1855
+ if (populateOption) {
1856
+ findManyArgs.populate = populateOption;
1857
+ }
1834
1858
  const [entries, totalEntries] = await Promise.all([
1835
- strapi2.documents(uid).findMany({
1836
- start,
1837
- limit,
1838
- filters: Object.keys(filters2).length > 0 ? filters2 : void 0,
1839
- sort: sortClause,
1840
- populate: populateOption
1841
- }),
1859
+ strapi2.documents(uid).findMany(findManyArgs),
1842
1860
  strapi2.documents(uid).count({
1843
1861
  filters: Object.keys(filters2).length > 0 ? filters2 : void 0
1844
1862
  })
@@ -1975,10 +1993,12 @@ const bulkUpdaterService = ({ strapi: strapi2 }) => {
1975
1993
  }
1976
1994
  let currentEntry;
1977
1995
  if (isComponentNested) {
1978
- currentEntry = await strapi2.documents(target.uid).findOne({
1979
- documentId: target.documentId,
1980
- populate: buildDeepPopulate$1(contentType.attributes, strapi2.components)
1981
- });
1996
+ const findOneArgs = { documentId: target.documentId };
1997
+ const populateOption = buildDeepPopulate$1(contentType.attributes, strapi2.components);
1998
+ if (populateOption) {
1999
+ findOneArgs.populate = populateOption;
2000
+ }
2001
+ currentEntry = await strapi2.documents(target.uid).findOne(findOneArgs);
1982
2002
  } else if (attrDef?.type === "relation") {
1983
2003
  currentEntry = await strapi2.documents(target.uid).findOne({
1984
2004
  documentId: target.documentId,
@@ -3727,15 +3747,20 @@ function discoverExportFields(ct, allComponents, maxDepth = 4) {
3727
3747
  return fields2;
3728
3748
  }
3729
3749
  function buildDeepPopulate(attributes, allComponents, depth2 = 0) {
3730
- if (depth2 > 4) return true;
3750
+ if (depth2 > 5) return void 0;
3731
3751
  const populate2 = {};
3732
3752
  for (const [key, def] of Object.entries(attributes || {})) {
3733
3753
  if (def.type === "component" && def.component) {
3734
3754
  const comp = allComponents[def.component];
3735
3755
  if (comp?.attributes) {
3736
- populate2[key] = {
3737
- populate: buildDeepPopulate(comp.attributes, allComponents, depth2 + 1)
3738
- };
3756
+ const subPopulate = buildDeepPopulate(comp.attributes, allComponents, depth2 + 1);
3757
+ if (subPopulate && Object.keys(subPopulate).length > 0) {
3758
+ populate2[key] = {
3759
+ populate: subPopulate
3760
+ };
3761
+ } else {
3762
+ populate2[key] = true;
3763
+ }
3739
3764
  } else {
3740
3765
  populate2[key] = true;
3741
3766
  }
@@ -3745,7 +3770,7 @@ function buildDeepPopulate(attributes, allComponents, depth2 = 0) {
3745
3770
  populate2[key] = true;
3746
3771
  }
3747
3772
  }
3748
- return Object.keys(populate2).length > 0 ? populate2 : true;
3773
+ return Object.keys(populate2).length > 0 ? populate2 : void 0;
3749
3774
  }
3750
3775
  function getNestedExportValue(entry, path2) {
3751
3776
  if (!entry || !path2) return "";
@@ -3912,17 +3937,22 @@ const csvService = ({ strapi: strapi2 }) => ({
3912
3937
  const deepPopulate = buildDeepPopulate(ct.attributes || {}, allComponents);
3913
3938
  let entries = [];
3914
3939
  if (ct.kind === "singleType") {
3915
- const doc = await strapi2.documents(uid).findFirst({
3916
- populate: deepPopulate
3917
- });
3940
+ const findFirstArgs = {};
3941
+ if (deepPopulate) {
3942
+ findFirstArgs.populate = deepPopulate;
3943
+ }
3944
+ const doc = await strapi2.documents(uid).findFirst(findFirstArgs);
3918
3945
  entries = doc ? [doc] : [];
3919
3946
  } else {
3920
- entries = await strapi2.documents(uid).findMany({
3947
+ const findManyArgs = {
3921
3948
  filters: Object.keys(filters2).length > 0 ? filters2 : void 0,
3922
3949
  limit: options.limit || 5e3,
3923
- sort: { createdAt: "desc" },
3924
- populate: deepPopulate
3925
- });
3950
+ sort: { createdAt: "desc" }
3951
+ };
3952
+ if (deepPopulate) {
3953
+ findManyArgs.populate = deepPopulate;
3954
+ }
3955
+ entries = await strapi2.documents(uid).findMany(findManyArgs);
3926
3956
  }
3927
3957
  const lines = [];
3928
3958
  lines.push(fields2.map((f) => escapeCsvValue(f.key)).join(","));