@fourlights/strapi-plugin-deep-populate 1.14.0 → 1.15.0-rc.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.
@@ -632,9 +632,9 @@ function requireDist() {
632
632
  t2.exports = "constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf".split(",");
633
633
  }, function(t2, n2, r) {
634
634
  var e = r(2), o = r(6), i = r(7), c = r(5), u = "prototype", s = function(t3, n3, r2) {
635
- var f, a, p, l = t3 & s.F, v = t3 & s.G, h = t3 & s.S, d = t3 & s.P, y = t3 & s.B, _ = t3 & s.W, x = v ? o : o[n3] || (o[n3] = {}), m = x[u], w = v ? e : h ? e[n3] : (e[n3] || {})[u];
635
+ var f2, a, p, l = t3 & s.F, v = t3 & s.G, h = t3 & s.S, d = t3 & s.P, y = t3 & s.B, _ = t3 & s.W, x = v ? o : o[n3] || (o[n3] = {}), m = x[u], w = v ? e : h ? e[n3] : (e[n3] || {})[u];
636
636
  v && (r2 = n3);
637
- for (f in r2) a = !l && w && void 0 !== w[f], a && f in x || (p = a ? w[f] : r2[f], x[f] = v && "function" != typeof w[f] ? r2[f] : y && a ? i(p, e) : _ && w[f] == p ? (function(t4) {
637
+ for (f2 in r2) a = !l && w && void 0 !== w[f2], a && f2 in x || (p = a ? w[f2] : r2[f2], x[f2] = v && "function" != typeof w[f2] ? r2[f2] : y && a ? i(p, e) : _ && w[f2] == p ? (function(t4) {
638
638
  var n4 = function(n5, r3, e2) {
639
639
  if (this instanceof t4) {
640
640
  switch (arguments.length) {
@@ -650,7 +650,7 @@ function requireDist() {
650
650
  return t4.apply(this, arguments);
651
651
  };
652
652
  return n4[u] = t4[u], n4;
653
- })(p) : d && "function" == typeof p ? i(Function.call, p) : p, d && ((x.virtual || (x.virtual = {}))[f] = p, t3 & s.R && m && !m[f] && c(m, f, p)));
653
+ })(p) : d && "function" == typeof p ? i(Function.call, p) : p, d && ((x.virtual || (x.virtual = {}))[f2] = p, t3 & s.R && m && !m[f2] && c(m, f2, p)));
654
654
  };
655
655
  s.F = 1, s.G = 2, s.S = 4, s.P = 8, s.B = 16, s.W = 32, s.U = 64, s.R = 128, t2.exports = s;
656
656
  }, function(t2, n2) {
@@ -670,11 +670,11 @@ function requireDist() {
670
670
  } }).a;
671
671
  });
672
672
  }, function(t2, n2, r) {
673
- var e = r(28), o = r(23), i = r(57), c = r(5), u = r(8), s = r(10), f = r(45), a = r(18), p = r(52), l = r(1)("iterator"), v = !([].keys && "next" in [].keys()), h = "@@iterator", d = "keys", y = "values", _ = function() {
673
+ var e = r(28), o = r(23), i = r(57), c = r(5), u = r(8), s = r(10), f2 = r(45), a = r(18), p = r(52), l = r(1)("iterator"), v = !([].keys && "next" in [].keys()), h = "@@iterator", d = "keys", y = "values", _ = function() {
674
674
  return this;
675
675
  };
676
676
  t2.exports = function(t3, n3, r2, x, m, w, g) {
677
- f(r2, n3, x);
677
+ f2(r2, n3, x);
678
678
  var b, O, j, S = function(t4) {
679
679
  if (!v && t4 in T) return T[t4];
680
680
  switch (t4) {
@@ -705,7 +705,7 @@ function requireDist() {
705
705
  return i[t3] || (i[t3] = {});
706
706
  };
707
707
  }, function(t2, n2, r) {
708
- var e, o, i, c = r(7), u = r(41), s = r(25), f = r(16), a = r(2), p = a.process, l = a.setImmediate, v = a.clearImmediate, h = a.MessageChannel, d = 0, y = {}, _ = "onreadystatechange", x = function() {
708
+ var e, o, i, c = r(7), u = r(41), s = r(25), f2 = r(16), a = r(2), p = a.process, l = a.setImmediate, v = a.clearImmediate, h = a.MessageChannel, d = 0, y = {}, _ = "onreadystatechange", x = function() {
709
709
  var t3 = +this;
710
710
  if (y.hasOwnProperty(t3)) {
711
711
  var n3 = y[t3];
@@ -725,8 +725,8 @@ function requireDist() {
725
725
  p.nextTick(c(x, t3, 1));
726
726
  } : h ? (o = new h(), i = o.port2, o.port1.onmessage = m, e = c(i.postMessage, i, 1)) : a.addEventListener && "function" == typeof postMessage && !a.importScripts ? (e = function(t3) {
727
727
  a.postMessage(t3 + "", "*");
728
- }, a.addEventListener("message", m, false)) : e = _ in f("script") ? function(t3) {
729
- s.appendChild(f("script"))[_] = function() {
728
+ }, a.addEventListener("message", m, false)) : e = _ in f2("script") ? function(t3) {
729
+ s.appendChild(f2("script"))[_] = function() {
730
730
  s.removeChild(this), x.call(t3);
731
731
  };
732
732
  } : function(t3) {
@@ -790,7 +790,7 @@ function requireDist() {
790
790
  });
791
791
  }
792
792
  Object.defineProperty(n2, "__esModule", { value: true });
793
- var f = r(35), a = e(f);
793
+ var f2 = r(35), a = e(f2);
794
794
  n2.machineIdSync = u, n2.machineId = s;
795
795
  var p = r(70), l = r(71), v = process, h = v.platform, d = { native: "%windir%\\System32", mixed: "%windir%\\sysnative\\cmd.exe /c %windir%\\System32" }, y = { darwin: "ioreg -rd1 -c IOPlatformExpertDevice", win32: d[o()] + "\\REG.exe QUERY HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography /v MachineGuid", linux: "( cat /var/lib/dbus/machine-id /etc/machine-id 2> /dev/null || hostname ) | head -n 1 || :", freebsd: "kenv -q smbios.system.uuid || sysctl -n kern.hostuuid" };
796
796
  }, function(t2, n2, r) {
@@ -809,24 +809,24 @@ function requireDist() {
809
809
  var e = r(13), o = r(31), i = r(62);
810
810
  t2.exports = function(t3) {
811
811
  return function(n3, r2, c) {
812
- var u, s = e(n3), f = o(s.length), a = i(c, f);
812
+ var u, s = e(n3), f2 = o(s.length), a = i(c, f2);
813
813
  if (t3 && r2 != r2) {
814
- for (; f > a; ) if (u = s[a++], u != u) return true;
815
- } else for (; f > a; a++) if ((t3 || a in s) && s[a] === r2) return t3 || a || 0;
814
+ for (; f2 > a; ) if (u = s[a++], u != u) return true;
815
+ } else for (; f2 > a; a++) if ((t3 || a in s) && s[a] === r2) return t3 || a || 0;
816
816
  return !t3 && -1;
817
817
  };
818
818
  };
819
819
  }, function(t2, n2, r) {
820
- var e = r(7), o = r(44), i = r(43), c = r(3), u = r(31), s = r(64), f = {}, a = {}, n2 = t2.exports = function(t3, n3, r2, p, l) {
820
+ var e = r(7), o = r(44), i = r(43), c = r(3), u = r(31), s = r(64), f2 = {}, a = {}, n2 = t2.exports = function(t3, n3, r2, p, l) {
821
821
  var v, h, d, y, _ = l ? function() {
822
822
  return t3;
823
823
  } : s(t3), x = e(r2, p, n3 ? 2 : 1), m = 0;
824
824
  if ("function" != typeof _) throw TypeError(t3 + " is not iterable!");
825
825
  if (i(_)) {
826
- for (v = u(t3.length); v > m; m++) if (y = n3 ? x(c(h = t3[m])[0], h[1]) : x(t3[m]), y === f || y === a) return y;
827
- } else for (d = _.call(t3); !(h = d.next()).done; ) if (y = o(d, x, h.value, n3), y === f || y === a) return y;
826
+ for (v = u(t3.length); v > m; m++) if (y = n3 ? x(c(h = t3[m])[0], h[1]) : x(t3[m]), y === f2 || y === a) return y;
827
+ } else for (d = _.call(t3); !(h = d.next()).done; ) if (y = o(d, x, h.value, n3), y === f2 || y === a) return y;
828
828
  };
829
- n2.BREAK = f, n2.RETURN = a;
829
+ n2.BREAK = f2, n2.RETURN = a;
830
830
  }, function(t2, n2) {
831
831
  t2.exports = function(t3, n3, r) {
832
832
  var e = void 0 === r;
@@ -903,7 +903,7 @@ function requireDist() {
903
903
  }, function(t2, n2, r) {
904
904
  var e = r(2), o = r(30).set, i = e.MutationObserver || e.WebKitMutationObserver, c = e.process, u = e.Promise, s = "process" == r(11)(c);
905
905
  t2.exports = function() {
906
- var t3, n3, r2, f = function() {
906
+ var t3, n3, r2, f2 = function() {
907
907
  var e2, o2;
908
908
  for (s && (e2 = c.domain) && e2.exit(); t3; ) {
909
909
  o2 = t3.fn, t3 = t3.next;
@@ -916,20 +916,20 @@ function requireDist() {
916
916
  n3 = void 0, e2 && e2.enter();
917
917
  };
918
918
  if (s) r2 = function() {
919
- c.nextTick(f);
919
+ c.nextTick(f2);
920
920
  };
921
921
  else if (i) {
922
922
  var a = true, p = document.createTextNode("");
923
- new i(f).observe(p, { characterData: true }), r2 = function() {
923
+ new i(f2).observe(p, { characterData: true }), r2 = function() {
924
924
  p.data = a = !a;
925
925
  };
926
926
  } else if (u && u.resolve) {
927
927
  var l = u.resolve();
928
928
  r2 = function() {
929
- l.then(f);
929
+ l.then(f2);
930
930
  };
931
931
  } else r2 = function() {
932
- o.call(e, f);
932
+ o.call(e, f2);
933
933
  };
934
934
  return function(e2) {
935
935
  var o2 = { fn: e2, next: void 0 };
@@ -938,14 +938,14 @@ function requireDist() {
938
938
  };
939
939
  }, function(t2, n2, r) {
940
940
  var e = r(3), o = r(50), i = r(22), c = r(19)("IE_PROTO"), u = function() {
941
- }, s = "prototype", f = function() {
941
+ }, s = "prototype", f2 = function() {
942
942
  var t3, n3 = r(16)("iframe"), e2 = i.length, o2 = ">";
943
- for (n3.style.display = "none", r(25).appendChild(n3), n3.src = "javascript:", t3 = n3.contentWindow.document, t3.open(), t3.write("<script>document.F=Object<\/script" + o2), t3.close(), f = t3.F; e2--; ) delete f[s][i[e2]];
944
- return f();
943
+ for (n3.style.display = "none", r(25).appendChild(n3), n3.src = "javascript:", t3 = n3.contentWindow.document, t3.open(), t3.write("<script>document.F=Object<\/script" + o2), t3.close(), f2 = t3.F; e2--; ) delete f2[s][i[e2]];
944
+ return f2();
945
945
  };
946
946
  t2.exports = Object.create || function(t3, n3) {
947
947
  var r2;
948
- return null !== t3 ? (u[s] = e(t3), r2 = new u(), u[s] = null, r2[c] = t3) : r2 = f(), void 0 === n3 ? r2 : o(r2, n3);
948
+ return null !== t3 ? (u[s] = e(t3), r2 = new u(), u[s] = null, r2[c] = t3) : r2 = f2(), void 0 === n3 ? r2 : o(r2, n3);
949
949
  };
950
950
  }, function(t2, n2, r) {
951
951
  var e = r(12), o = r(3), i = r(54);
@@ -955,10 +955,10 @@ function requireDist() {
955
955
  return t3;
956
956
  };
957
957
  }, function(t2, n2, r) {
958
- var e = r(55), o = r(17), i = r(13), c = r(32), u = r(8), s = r(26), f = Object.getOwnPropertyDescriptor;
959
- n2.f = r(4) ? f : function(t3, n3) {
958
+ var e = r(55), o = r(17), i = r(13), c = r(32), u = r(8), s = r(26), f2 = Object.getOwnPropertyDescriptor;
959
+ n2.f = r(4) ? f2 : function(t3, n3) {
960
960
  if (t3 = i(t3), n3 = c(n3, true), s) try {
961
- return f(t3, n3);
961
+ return f2(t3, n3);
962
962
  } catch (t4) {
963
963
  }
964
964
  if (u(t3, n3)) return o(!e.f.call(t3, n3), t3[n3]);
@@ -971,10 +971,10 @@ function requireDist() {
971
971
  }, function(t2, n2, r) {
972
972
  var e = r(8), o = r(13), i = r(39)(false), c = r(19)("IE_PROTO");
973
973
  t2.exports = function(t3, n3) {
974
- var r2, u = o(t3), s = 0, f = [];
975
- for (r2 in u) r2 != c && e(u, r2) && f.push(r2);
976
- for (; n3.length > s; ) e(u, r2 = n3[s++]) && (~i(f, r2) || f.push(r2));
977
- return f;
974
+ var r2, u = o(t3), s = 0, f2 = [];
975
+ for (r2 in u) r2 != c && e(u, r2) && f2.push(r2);
976
+ for (; n3.length > s; ) e(u, r2 = n3[s++]) && (~i(f2, r2) || f2.push(r2));
977
+ return f2;
978
978
  };
979
979
  }, function(t2, n2, r) {
980
980
  var e = r(53), o = r(22);
@@ -1023,8 +1023,8 @@ function requireDist() {
1023
1023
  var e = r(20), o = r(15);
1024
1024
  t2.exports = function(t3) {
1025
1025
  return function(n3, r2) {
1026
- var i, c, u = String(o(n3)), s = e(r2), f = u.length;
1027
- return s < 0 || s >= f ? t3 ? "" : void 0 : (i = u.charCodeAt(s), i < 55296 || i > 56319 || s + 1 === f || (c = u.charCodeAt(s + 1)) < 56320 || c > 57343 ? t3 ? u.charAt(s) : i : t3 ? u.slice(s, s + 2) : (i - 55296 << 10) + (c - 56320) + 65536);
1026
+ var i, c, u = String(o(n3)), s = e(r2), f2 = u.length;
1027
+ return s < 0 || s >= f2 ? t3 ? "" : void 0 : (i = u.charCodeAt(s), i < 55296 || i > 56319 || s + 1 === f2 || (c = u.charCodeAt(s + 1)) < 56320 || c > 57343 ? t3 ? u.charAt(s) : i : t3 ? u.slice(s, s + 2) : (i - 55296 << 10) + (c - 56320) + 65536);
1028
1028
  };
1029
1029
  };
1030
1030
  }, function(t2, n2, r) {
@@ -1052,7 +1052,7 @@ function requireDist() {
1052
1052
  }, "values"), i.Arguments = i.Array, e("keys"), e("values"), e("entries");
1053
1053
  }, function(t2, n2) {
1054
1054
  }, function(t2, n2, r) {
1055
- var e, o, i, c = r(28), u = r(2), s = r(7), f = r(21), a = r(23), p = r(9), l = (r(3), r(14)), v = r(38), h = r(40), d = (r(58).set, r(60)), y = r(30).set, _ = r(48)(), x = "Promise", m = u.TypeError, w = u.process, g = u[x], w = u.process, b = "process" == f(w), O = function() {
1055
+ var e, o, i, c = r(28), u = r(2), s = r(7), f2 = r(21), a = r(23), p = r(9), l = (r(3), r(14)), v = r(38), h = r(40), d = (r(58).set, r(60)), y = r(30).set, _ = r(48)(), x = "Promise", m = u.TypeError, w = u.process, g = u[x], w = u.process, b = "process" == f2(w), O = function() {
1056
1056
  }, j = !!(function() {
1057
1057
  try {
1058
1058
  var t3 = g.resolve(1), n3 = (t3.constructor = {})[r(1)("species")] = function(t4) {
@@ -1086,9 +1086,9 @@ function requireDist() {
1086
1086
  var r2 = t3._c;
1087
1087
  _(function() {
1088
1088
  for (var e2 = t3._v, o2 = 1 == t3._s, i2 = 0, c2 = function(n4) {
1089
- var r3, i3, c3 = o2 ? n4.ok : n4.fail, u2 = n4.resolve, s2 = n4.reject, f2 = n4.domain;
1089
+ var r3, i3, c3 = o2 ? n4.ok : n4.fail, u2 = n4.resolve, s2 = n4.reject, f3 = n4.domain;
1090
1090
  try {
1091
- c3 ? (o2 || (2 == t3._h && I(t3), t3._h = 1), c3 === true ? r3 = e2 : (f2 && f2.enter(), r3 = c3(e2), f2 && f2.exit()), r3 === n4.promise ? s2(m("Promise-chain cycle")) : (i3 = E(r3)) ? i3.call(r3, u2, s2) : u2(r3)) : s2(e2);
1091
+ c3 ? (o2 || (2 == t3._h && I(t3), t3._h = 1), c3 === true ? r3 = e2 : (f3 && f3.enter(), r3 = c3(e2), f3 && f3.exit()), r3 === n4.promise ? s2(m("Promise-chain cycle")) : (i3 = E(r3)) ? i3.call(r3, u2, s2) : u2(r3)) : s2(e2);
1092
1092
  } catch (t4) {
1093
1093
  s2(t4);
1094
1094
  }
@@ -1190,8 +1190,8 @@ function requireDist() {
1190
1190
  }, function(t2, n2, r) {
1191
1191
  r(65);
1192
1192
  for (var e = r(2), o = r(5), i = r(10), c = r(1)("toStringTag"), u = ["NodeList", "DOMTokenList", "MediaList", "StyleSheetList", "CSSRuleList"], s = 0; s < 5; s++) {
1193
- var f = u[s], a = e[f], p = a && a.prototype;
1194
- p && !p[c] && o(p, c, f), i[f] = i.Array;
1193
+ var f2 = u[s], a = e[f2], p = a && a.prototype;
1194
+ p && !p[c] && o(p, c, f2), i[f2] = i.Array;
1195
1195
  }
1196
1196
  }, function(t2, n2) {
1197
1197
  t2.exports = require$$0__default.default;
@@ -1203,9 +1203,9 @@ function requireDist() {
1203
1203
  return dist$1.exports;
1204
1204
  }
1205
1205
  requireDist();
1206
- var map$1;
1206
+ var map$2;
1207
1207
  try {
1208
- map$1 = Map;
1208
+ map$2 = Map;
1209
1209
  } catch (_) {
1210
1210
  }
1211
1211
  var set$1;
@@ -1229,7 +1229,7 @@ function baseClone(src, circulars, clones) {
1229
1229
  if (Array.isArray(src)) {
1230
1230
  return src.map(clone$1);
1231
1231
  }
1232
- if (map$1 && src instanceof map$1) {
1232
+ if (map$2 && src instanceof map$2) {
1233
1233
  return new Map(Array.from(src.entries()));
1234
1234
  }
1235
1235
  if (set$1 && src instanceof set$1) {
@@ -3779,7 +3779,7 @@ function pipe$1(...fns) {
3779
3779
  return res;
3780
3780
  };
3781
3781
  }
3782
- fp.curry(pMap);
3782
+ const map$1 = fp.curry(pMap);
3783
3783
  const visitor$4 = ({ key, attribute }, { remove }) => {
3784
3784
  if (attribute?.type === "password") {
3785
3785
  remove(key);
@@ -18430,6 +18430,19 @@ function asBoolean(value) {
18430
18430
  const normalized = value.toLowerCase().trim();
18431
18431
  return normalized !== "false" && normalized !== "0";
18432
18432
  }
18433
+ const version = "1.15.0-rc.1";
18434
+ const name = "@fourlights/strapi-plugin-deep-populate";
18435
+ const f = (msg, context = void 0) => {
18436
+ const prefix = `[${name}] `;
18437
+ const suffix = context !== void 0 ? `
18438
+ ${prefix}${context}` : "";
18439
+ return `${prefix}${msg}${suffix}`;
18440
+ };
18441
+ const error = (msg, context = void 0) => strapi.log.error(f(msg, context));
18442
+ const warn = (msg, context = void 0) => strapi.log.warn(f(msg, context));
18443
+ const info = (msg, context = void 0) => strapi.log.info(f(msg, context));
18444
+ const debug = (msg, context = void 0) => strapi.log.debug(f(msg, context));
18445
+ const log = { error, warn, info, debug };
18433
18446
  const populateIsWildcardEquivalent = async ({
18434
18447
  strapi: strapi2,
18435
18448
  schema: schema2,
@@ -18445,9 +18458,35 @@ const populateIsWildcardEquivalent = async ({
18445
18458
  );
18446
18459
  return populate2 === "*" || populate2 === true || JSON.stringify(expandedWildcardQuery) === JSON.stringify(populate2);
18447
18460
  };
18461
+ async function clearCacheForChangedSchemas(schemas) {
18462
+ await map$1(schemas, async (schema2) => {
18463
+ const deleted = await strapi.db.query("plugin::deep-populate.cache").deleteMany({
18464
+ where: {
18465
+ dependencies: { $contains: schema2 }
18466
+ }
18467
+ });
18468
+ log.debug(`Deleted ${deleted.count} cached entries due to out of date schema '${schema2}'`);
18469
+ });
18470
+ }
18448
18471
  const register = async ({ strapi: strapi2 }) => {
18472
+ strapi2.hook("strapi::content-types.beforeSync").register(async () => {
18473
+ const databaseSchema = await strapi2.db.dialect.schemaInspector.getSchema();
18474
+ const storedSchema = await strapi2.db.schema.schemaStorage.read();
18475
+ const { status, diff } = await strapi2.db.schema.schemaDiff.diff({
18476
+ previousSchema: storedSchema?.schema,
18477
+ databaseSchema,
18478
+ userSchema: strapi2.db.schema.schema
18479
+ });
18480
+ if (status === "CHANGED") {
18481
+ const updatedTables = (diff.tables.updated ?? []).map((t) => t.name);
18482
+ const updatedSchemas = [...strapi2.db.metadata.values()].filter((m) => updatedTables.includes(m.tableName)).map((m) => m.uid);
18483
+ const tableName = strapi2.db.metadata.get("plugin::deep-populate.cache").tableName;
18484
+ const hasTable = await strapi2.db.connection.schema.hasTable(tableName);
18485
+ if (hasTable) await clearCacheForChangedSchemas(updatedSchemas);
18486
+ }
18487
+ });
18449
18488
  strapi2.hook("strapi::content-types.afterSync").register(async () => {
18450
- const tableName = "populate_cache";
18489
+ const tableName = strapi2.db.metadata.get("plugin::deep-populate.cache").tableName;
18451
18490
  const columnName = "dependencies";
18452
18491
  const hasIndex = await hasDeepPopulateCacheFullTextIndex(strapi2.db, tableName, columnName);
18453
18492
  const hasTable = await strapi2.db.connection.schema.hasTable(tableName);
@@ -18522,13 +18561,23 @@ const register = async ({ strapi: strapi2 }) => {
18522
18561
  return result;
18523
18562
  });
18524
18563
  };
18525
- const version = "1.14.0";
18526
- const name = "@fourlights/strapi-plugin-deep-populate";
18527
- const error = (msg, context = void 0) => strapi.log.error(`[${name}] ${msg}`, context);
18528
- const warn = (msg, context = void 0) => strapi.log.warn(`[${name}] ${msg}`, context);
18529
- const info = (msg, context = void 0) => strapi.log.info(`[${name}] ${msg}`, context);
18530
- const debug = (msg, context = void 0) => strapi.log.debug(`[${name}] ${msg}`, context);
18531
- const log = { error, warn, info, debug };
18564
+ const UniqueConstraintErrorCodes = {
18565
+ // PostgreSQL
18566
+ POSTGRES_UNIQUE_VIOLATION: "23505",
18567
+ // MySQL
18568
+ MYSQL_DUPLICATE_ENTRY: 1062,
18569
+ // SQLite
18570
+ SQLITE_CONSTRAINT: 19,
18571
+ SQLITE_CONSTRAINT_UNIQUE: 2067,
18572
+ // SQL Server
18573
+ SQLSERVER_DUPLICATE_KEY: 2601,
18574
+ SQLSERVER_UNIQUE_KEY_VIOLATION: 2627
18575
+ };
18576
+ const isUniqueConstraintError = (error2) => {
18577
+ const err = error2;
18578
+ return Object.keys(UniqueConstraintErrorCodes).includes(err.code) || err.code === UniqueConstraintErrorCodes.POSTGRES_UNIQUE_VIOLATION || err.errno === UniqueConstraintErrorCodes.MYSQL_DUPLICATE_ENTRY || err.errno === UniqueConstraintErrorCodes.SQLITE_CONSTRAINT || err.errno === UniqueConstraintErrorCodes.SQLITE_CONSTRAINT_UNIQUE || err.number === UniqueConstraintErrorCodes.SQLSERVER_DUPLICATE_KEY || err.number === UniqueConstraintErrorCodes.SQLSERVER_UNIQUE_KEY_VIOLATION;
18579
+ };
18580
+ const majorMinorVersion = version.split(".").slice(0, -1).join(".");
18532
18581
  const sanitizeObject = (obj) => {
18533
18582
  if (obj === null || typeof obj !== "object") return obj;
18534
18583
  const dangerousProps = ["__proto__", "constructor", "prototype"];
@@ -18584,7 +18633,6 @@ const getConfig = (params) => {
18584
18633
  const localizations = params.localizations ?? contentTypeConfig.localizations ?? localizationsFallback;
18585
18634
  return { allow, deny, omitEmpty, localizations };
18586
18635
  };
18587
- const majorMinorVersion = version.split(".").slice(0, -1).join(".");
18588
18636
  const isEqualConfig = (lhs, rhs) => {
18589
18637
  const cleanedLhs = JSON.parse(JSON.stringify(lhs));
18590
18638
  const cleanedRhs = JSON.parse(JSON.stringify(rhs));
@@ -18609,15 +18657,19 @@ const cache = ({ strapi: strapi2 }) => ({
18609
18657
  async set({ populate: populate2, dependencies, ...params }) {
18610
18658
  const documentService = strapi2.documents("plugin::deep-populate.cache");
18611
18659
  const hash = getHash(params);
18612
- const entry = await documentService.findFirst({ filters: { hash: { $eq: hash } } });
18613
18660
  try {
18614
- return entry ? await documentService.update({
18615
- documentId: entry.documentId,
18616
- data: { populate: populate2, dependencies: dependencies.join(",") }
18617
- }) : await documentService.create({ data: { hash, params, populate: populate2, dependencies: dependencies.join(",") } });
18661
+ return await documentService.create({ data: { hash, params, populate: populate2, dependencies: dependencies.join(",") } });
18618
18662
  } catch (error2) {
18619
- log.error("[Plugin: Deep Populate] Failed to save cached entry", { error: error2 });
18620
- return;
18663
+ if (isUniqueConstraintError(error2)) {
18664
+ const entry = await documentService.findFirst({ filters: { hash: { $eq: hash } } });
18665
+ if (entry) {
18666
+ return await documentService.update({
18667
+ documentId: entry.documentId,
18668
+ data: { populate: populate2, dependencies: dependencies.join(",") }
18669
+ });
18670
+ }
18671
+ }
18672
+ log.error("Failed to save cached entry", error2);
18621
18673
  }
18622
18674
  },
18623
18675
  async clear(params) {
@@ -18784,6 +18836,7 @@ async function _populate({
18784
18836
  populate: populate2 = {},
18785
18837
  lookup = [],
18786
18838
  resolvedRelations,
18839
+ resolvedSchemas,
18787
18840
  omitEmpty,
18788
18841
  __deny,
18789
18842
  __allow,
@@ -18799,6 +18852,7 @@ async function _populate({
18799
18852
  let relations = getRelations(model);
18800
18853
  let currentPopulate = cloneDeep__default.default(populate2);
18801
18854
  resolvedRelations.set(params.documentId, true);
18855
+ resolvedSchemas.add(schema2);
18802
18856
  for (const [attrName, attr] of relations) {
18803
18857
  if (lookup.length > 0) {
18804
18858
  const parent = get__default.default(currentPopulate, lookup);
@@ -18870,6 +18924,7 @@ async function _populate({
18870
18924
  lookup,
18871
18925
  attrName,
18872
18926
  resolvedRelations,
18927
+ resolvedSchemas,
18873
18928
  omitEmpty,
18874
18929
  __deny,
18875
18930
  __allow,
@@ -18881,6 +18936,7 @@ async function _populate({
18881
18936
  contentType: attr.target,
18882
18937
  relation: value,
18883
18938
  resolvedRelations,
18939
+ resolvedSchemas,
18884
18940
  omitEmpty,
18885
18941
  locale: params.locale,
18886
18942
  status: params.status,
@@ -18896,6 +18952,7 @@ async function _populate({
18896
18952
  lookup,
18897
18953
  attrName,
18898
18954
  resolvedRelations,
18955
+ resolvedSchemas,
18899
18956
  omitEmpty,
18900
18957
  __deny,
18901
18958
  __allow,
@@ -18911,9 +18968,11 @@ async function _populate({
18911
18968
  async function populate$1(params) {
18912
18969
  const config2 = getConfig(params);
18913
18970
  const resolvedRelations = /* @__PURE__ */ new Map();
18971
+ const resolvedSchemas = /* @__PURE__ */ new Set();
18914
18972
  const populated = await _populate({
18915
18973
  schema: params.contentType,
18916
18974
  resolvedRelations,
18975
+ resolvedSchemas,
18917
18976
  omitEmpty: config2.omitEmpty,
18918
18977
  localizations: config2.localizations,
18919
18978
  __deny: config2.deny,
@@ -18922,7 +18981,11 @@ async function populate$1(params) {
18922
18981
  });
18923
18982
  populated.__deepPopulated = true;
18924
18983
  populated.__deepPopulateConfig = config2;
18925
- const dependencies = [...resolvedRelations.keys()].filter((r) => !r.startsWith("api::"));
18984
+ const dependencies = [
18985
+ ...[...resolvedRelations.keys()].filter((r) => !r.startsWith("api::")),
18986
+ // Remove content-types from resolved relations
18987
+ ...resolvedSchemas.values()
18988
+ ];
18926
18989
  return { populate: populated, dependencies };
18927
18990
  }
18928
18991
  const populate = ({ strapi: strapi2 }) => ({
@@ -1,7 +1,7 @@
1
1
  import isEmpty$1 from "lodash/isEmpty";
2
2
  import isObject$2 from "lodash/isObject";
3
3
  import ___default, { isNil as isNil$1, has as has$1, get as get$1, mergeWith } from "lodash";
4
- import { union as union$1, getOr, curry, isObject as isObject$3, isNil, clone as clone$2, isArray, pick as pick$1, isEmpty as isEmpty$2, cloneDeep, omit as omit$1, isString, trim as trim$1, pipe as pipe$2, split, map as map$2, flatten, first, constant, identity, join, eq, get } from "lodash/fp";
4
+ import { union as union$1, getOr, curry, isObject as isObject$3, isNil, clone as clone$2, isArray, pick as pick$1, isEmpty as isEmpty$2, cloneDeep, omit as omit$1, isString, trim as trim$1, pipe as pipe$2, split, map as map$3, flatten, first, constant, identity, join, eq, get } from "lodash/fp";
5
5
  import require$$1 from "crypto";
6
6
  import require$$0$1 from "child_process";
7
7
  import has from "lodash/has";
@@ -604,9 +604,9 @@ function requireDist() {
604
604
  t2.exports = "constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf".split(",");
605
605
  }, function(t2, n2, r) {
606
606
  var e = r(2), o = r(6), i = r(7), c = r(5), u = "prototype", s = function(t3, n3, r2) {
607
- var f, a, p, l = t3 & s.F, v = t3 & s.G, h = t3 & s.S, d = t3 & s.P, y = t3 & s.B, _ = t3 & s.W, x = v ? o : o[n3] || (o[n3] = {}), m = x[u], w = v ? e : h ? e[n3] : (e[n3] || {})[u];
607
+ var f2, a, p, l = t3 & s.F, v = t3 & s.G, h = t3 & s.S, d = t3 & s.P, y = t3 & s.B, _ = t3 & s.W, x = v ? o : o[n3] || (o[n3] = {}), m = x[u], w = v ? e : h ? e[n3] : (e[n3] || {})[u];
608
608
  v && (r2 = n3);
609
- for (f in r2) a = !l && w && void 0 !== w[f], a && f in x || (p = a ? w[f] : r2[f], x[f] = v && "function" != typeof w[f] ? r2[f] : y && a ? i(p, e) : _ && w[f] == p ? (function(t4) {
609
+ for (f2 in r2) a = !l && w && void 0 !== w[f2], a && f2 in x || (p = a ? w[f2] : r2[f2], x[f2] = v && "function" != typeof w[f2] ? r2[f2] : y && a ? i(p, e) : _ && w[f2] == p ? (function(t4) {
610
610
  var n4 = function(n5, r3, e2) {
611
611
  if (this instanceof t4) {
612
612
  switch (arguments.length) {
@@ -622,7 +622,7 @@ function requireDist() {
622
622
  return t4.apply(this, arguments);
623
623
  };
624
624
  return n4[u] = t4[u], n4;
625
- })(p) : d && "function" == typeof p ? i(Function.call, p) : p, d && ((x.virtual || (x.virtual = {}))[f] = p, t3 & s.R && m && !m[f] && c(m, f, p)));
625
+ })(p) : d && "function" == typeof p ? i(Function.call, p) : p, d && ((x.virtual || (x.virtual = {}))[f2] = p, t3 & s.R && m && !m[f2] && c(m, f2, p)));
626
626
  };
627
627
  s.F = 1, s.G = 2, s.S = 4, s.P = 8, s.B = 16, s.W = 32, s.U = 64, s.R = 128, t2.exports = s;
628
628
  }, function(t2, n2) {
@@ -642,11 +642,11 @@ function requireDist() {
642
642
  } }).a;
643
643
  });
644
644
  }, function(t2, n2, r) {
645
- var e = r(28), o = r(23), i = r(57), c = r(5), u = r(8), s = r(10), f = r(45), a = r(18), p = r(52), l = r(1)("iterator"), v = !([].keys && "next" in [].keys()), h = "@@iterator", d = "keys", y = "values", _ = function() {
645
+ var e = r(28), o = r(23), i = r(57), c = r(5), u = r(8), s = r(10), f2 = r(45), a = r(18), p = r(52), l = r(1)("iterator"), v = !([].keys && "next" in [].keys()), h = "@@iterator", d = "keys", y = "values", _ = function() {
646
646
  return this;
647
647
  };
648
648
  t2.exports = function(t3, n3, r2, x, m, w, g) {
649
- f(r2, n3, x);
649
+ f2(r2, n3, x);
650
650
  var b, O, j, S = function(t4) {
651
651
  if (!v && t4 in T) return T[t4];
652
652
  switch (t4) {
@@ -677,7 +677,7 @@ function requireDist() {
677
677
  return i[t3] || (i[t3] = {});
678
678
  };
679
679
  }, function(t2, n2, r) {
680
- var e, o, i, c = r(7), u = r(41), s = r(25), f = r(16), a = r(2), p = a.process, l = a.setImmediate, v = a.clearImmediate, h = a.MessageChannel, d = 0, y = {}, _ = "onreadystatechange", x = function() {
680
+ var e, o, i, c = r(7), u = r(41), s = r(25), f2 = r(16), a = r(2), p = a.process, l = a.setImmediate, v = a.clearImmediate, h = a.MessageChannel, d = 0, y = {}, _ = "onreadystatechange", x = function() {
681
681
  var t3 = +this;
682
682
  if (y.hasOwnProperty(t3)) {
683
683
  var n3 = y[t3];
@@ -697,8 +697,8 @@ function requireDist() {
697
697
  p.nextTick(c(x, t3, 1));
698
698
  } : h ? (o = new h(), i = o.port2, o.port1.onmessage = m, e = c(i.postMessage, i, 1)) : a.addEventListener && "function" == typeof postMessage && !a.importScripts ? (e = function(t3) {
699
699
  a.postMessage(t3 + "", "*");
700
- }, a.addEventListener("message", m, false)) : e = _ in f("script") ? function(t3) {
701
- s.appendChild(f("script"))[_] = function() {
700
+ }, a.addEventListener("message", m, false)) : e = _ in f2("script") ? function(t3) {
701
+ s.appendChild(f2("script"))[_] = function() {
702
702
  s.removeChild(this), x.call(t3);
703
703
  };
704
704
  } : function(t3) {
@@ -762,7 +762,7 @@ function requireDist() {
762
762
  });
763
763
  }
764
764
  Object.defineProperty(n2, "__esModule", { value: true });
765
- var f = r(35), a = e(f);
765
+ var f2 = r(35), a = e(f2);
766
766
  n2.machineIdSync = u, n2.machineId = s;
767
767
  var p = r(70), l = r(71), v = process, h = v.platform, d = { native: "%windir%\\System32", mixed: "%windir%\\sysnative\\cmd.exe /c %windir%\\System32" }, y = { darwin: "ioreg -rd1 -c IOPlatformExpertDevice", win32: d[o()] + "\\REG.exe QUERY HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography /v MachineGuid", linux: "( cat /var/lib/dbus/machine-id /etc/machine-id 2> /dev/null || hostname ) | head -n 1 || :", freebsd: "kenv -q smbios.system.uuid || sysctl -n kern.hostuuid" };
768
768
  }, function(t2, n2, r) {
@@ -781,24 +781,24 @@ function requireDist() {
781
781
  var e = r(13), o = r(31), i = r(62);
782
782
  t2.exports = function(t3) {
783
783
  return function(n3, r2, c) {
784
- var u, s = e(n3), f = o(s.length), a = i(c, f);
784
+ var u, s = e(n3), f2 = o(s.length), a = i(c, f2);
785
785
  if (t3 && r2 != r2) {
786
- for (; f > a; ) if (u = s[a++], u != u) return true;
787
- } else for (; f > a; a++) if ((t3 || a in s) && s[a] === r2) return t3 || a || 0;
786
+ for (; f2 > a; ) if (u = s[a++], u != u) return true;
787
+ } else for (; f2 > a; a++) if ((t3 || a in s) && s[a] === r2) return t3 || a || 0;
788
788
  return !t3 && -1;
789
789
  };
790
790
  };
791
791
  }, function(t2, n2, r) {
792
- var e = r(7), o = r(44), i = r(43), c = r(3), u = r(31), s = r(64), f = {}, a = {}, n2 = t2.exports = function(t3, n3, r2, p, l) {
792
+ var e = r(7), o = r(44), i = r(43), c = r(3), u = r(31), s = r(64), f2 = {}, a = {}, n2 = t2.exports = function(t3, n3, r2, p, l) {
793
793
  var v, h, d, y, _ = l ? function() {
794
794
  return t3;
795
795
  } : s(t3), x = e(r2, p, n3 ? 2 : 1), m = 0;
796
796
  if ("function" != typeof _) throw TypeError(t3 + " is not iterable!");
797
797
  if (i(_)) {
798
- for (v = u(t3.length); v > m; m++) if (y = n3 ? x(c(h = t3[m])[0], h[1]) : x(t3[m]), y === f || y === a) return y;
799
- } else for (d = _.call(t3); !(h = d.next()).done; ) if (y = o(d, x, h.value, n3), y === f || y === a) return y;
798
+ for (v = u(t3.length); v > m; m++) if (y = n3 ? x(c(h = t3[m])[0], h[1]) : x(t3[m]), y === f2 || y === a) return y;
799
+ } else for (d = _.call(t3); !(h = d.next()).done; ) if (y = o(d, x, h.value, n3), y === f2 || y === a) return y;
800
800
  };
801
- n2.BREAK = f, n2.RETURN = a;
801
+ n2.BREAK = f2, n2.RETURN = a;
802
802
  }, function(t2, n2) {
803
803
  t2.exports = function(t3, n3, r) {
804
804
  var e = void 0 === r;
@@ -875,7 +875,7 @@ function requireDist() {
875
875
  }, function(t2, n2, r) {
876
876
  var e = r(2), o = r(30).set, i = e.MutationObserver || e.WebKitMutationObserver, c = e.process, u = e.Promise, s = "process" == r(11)(c);
877
877
  t2.exports = function() {
878
- var t3, n3, r2, f = function() {
878
+ var t3, n3, r2, f2 = function() {
879
879
  var e2, o2;
880
880
  for (s && (e2 = c.domain) && e2.exit(); t3; ) {
881
881
  o2 = t3.fn, t3 = t3.next;
@@ -888,20 +888,20 @@ function requireDist() {
888
888
  n3 = void 0, e2 && e2.enter();
889
889
  };
890
890
  if (s) r2 = function() {
891
- c.nextTick(f);
891
+ c.nextTick(f2);
892
892
  };
893
893
  else if (i) {
894
894
  var a = true, p = document.createTextNode("");
895
- new i(f).observe(p, { characterData: true }), r2 = function() {
895
+ new i(f2).observe(p, { characterData: true }), r2 = function() {
896
896
  p.data = a = !a;
897
897
  };
898
898
  } else if (u && u.resolve) {
899
899
  var l = u.resolve();
900
900
  r2 = function() {
901
- l.then(f);
901
+ l.then(f2);
902
902
  };
903
903
  } else r2 = function() {
904
- o.call(e, f);
904
+ o.call(e, f2);
905
905
  };
906
906
  return function(e2) {
907
907
  var o2 = { fn: e2, next: void 0 };
@@ -910,14 +910,14 @@ function requireDist() {
910
910
  };
911
911
  }, function(t2, n2, r) {
912
912
  var e = r(3), o = r(50), i = r(22), c = r(19)("IE_PROTO"), u = function() {
913
- }, s = "prototype", f = function() {
913
+ }, s = "prototype", f2 = function() {
914
914
  var t3, n3 = r(16)("iframe"), e2 = i.length, o2 = ">";
915
- for (n3.style.display = "none", r(25).appendChild(n3), n3.src = "javascript:", t3 = n3.contentWindow.document, t3.open(), t3.write("<script>document.F=Object<\/script" + o2), t3.close(), f = t3.F; e2--; ) delete f[s][i[e2]];
916
- return f();
915
+ for (n3.style.display = "none", r(25).appendChild(n3), n3.src = "javascript:", t3 = n3.contentWindow.document, t3.open(), t3.write("<script>document.F=Object<\/script" + o2), t3.close(), f2 = t3.F; e2--; ) delete f2[s][i[e2]];
916
+ return f2();
917
917
  };
918
918
  t2.exports = Object.create || function(t3, n3) {
919
919
  var r2;
920
- return null !== t3 ? (u[s] = e(t3), r2 = new u(), u[s] = null, r2[c] = t3) : r2 = f(), void 0 === n3 ? r2 : o(r2, n3);
920
+ return null !== t3 ? (u[s] = e(t3), r2 = new u(), u[s] = null, r2[c] = t3) : r2 = f2(), void 0 === n3 ? r2 : o(r2, n3);
921
921
  };
922
922
  }, function(t2, n2, r) {
923
923
  var e = r(12), o = r(3), i = r(54);
@@ -927,10 +927,10 @@ function requireDist() {
927
927
  return t3;
928
928
  };
929
929
  }, function(t2, n2, r) {
930
- var e = r(55), o = r(17), i = r(13), c = r(32), u = r(8), s = r(26), f = Object.getOwnPropertyDescriptor;
931
- n2.f = r(4) ? f : function(t3, n3) {
930
+ var e = r(55), o = r(17), i = r(13), c = r(32), u = r(8), s = r(26), f2 = Object.getOwnPropertyDescriptor;
931
+ n2.f = r(4) ? f2 : function(t3, n3) {
932
932
  if (t3 = i(t3), n3 = c(n3, true), s) try {
933
- return f(t3, n3);
933
+ return f2(t3, n3);
934
934
  } catch (t4) {
935
935
  }
936
936
  if (u(t3, n3)) return o(!e.f.call(t3, n3), t3[n3]);
@@ -943,10 +943,10 @@ function requireDist() {
943
943
  }, function(t2, n2, r) {
944
944
  var e = r(8), o = r(13), i = r(39)(false), c = r(19)("IE_PROTO");
945
945
  t2.exports = function(t3, n3) {
946
- var r2, u = o(t3), s = 0, f = [];
947
- for (r2 in u) r2 != c && e(u, r2) && f.push(r2);
948
- for (; n3.length > s; ) e(u, r2 = n3[s++]) && (~i(f, r2) || f.push(r2));
949
- return f;
946
+ var r2, u = o(t3), s = 0, f2 = [];
947
+ for (r2 in u) r2 != c && e(u, r2) && f2.push(r2);
948
+ for (; n3.length > s; ) e(u, r2 = n3[s++]) && (~i(f2, r2) || f2.push(r2));
949
+ return f2;
950
950
  };
951
951
  }, function(t2, n2, r) {
952
952
  var e = r(53), o = r(22);
@@ -995,8 +995,8 @@ function requireDist() {
995
995
  var e = r(20), o = r(15);
996
996
  t2.exports = function(t3) {
997
997
  return function(n3, r2) {
998
- var i, c, u = String(o(n3)), s = e(r2), f = u.length;
999
- return s < 0 || s >= f ? t3 ? "" : void 0 : (i = u.charCodeAt(s), i < 55296 || i > 56319 || s + 1 === f || (c = u.charCodeAt(s + 1)) < 56320 || c > 57343 ? t3 ? u.charAt(s) : i : t3 ? u.slice(s, s + 2) : (i - 55296 << 10) + (c - 56320) + 65536);
998
+ var i, c, u = String(o(n3)), s = e(r2), f2 = u.length;
999
+ return s < 0 || s >= f2 ? t3 ? "" : void 0 : (i = u.charCodeAt(s), i < 55296 || i > 56319 || s + 1 === f2 || (c = u.charCodeAt(s + 1)) < 56320 || c > 57343 ? t3 ? u.charAt(s) : i : t3 ? u.slice(s, s + 2) : (i - 55296 << 10) + (c - 56320) + 65536);
1000
1000
  };
1001
1001
  };
1002
1002
  }, function(t2, n2, r) {
@@ -1024,7 +1024,7 @@ function requireDist() {
1024
1024
  }, "values"), i.Arguments = i.Array, e("keys"), e("values"), e("entries");
1025
1025
  }, function(t2, n2) {
1026
1026
  }, function(t2, n2, r) {
1027
- var e, o, i, c = r(28), u = r(2), s = r(7), f = r(21), a = r(23), p = r(9), l = (r(3), r(14)), v = r(38), h = r(40), d = (r(58).set, r(60)), y = r(30).set, _ = r(48)(), x = "Promise", m = u.TypeError, w = u.process, g = u[x], w = u.process, b = "process" == f(w), O = function() {
1027
+ var e, o, i, c = r(28), u = r(2), s = r(7), f2 = r(21), a = r(23), p = r(9), l = (r(3), r(14)), v = r(38), h = r(40), d = (r(58).set, r(60)), y = r(30).set, _ = r(48)(), x = "Promise", m = u.TypeError, w = u.process, g = u[x], w = u.process, b = "process" == f2(w), O = function() {
1028
1028
  }, j = !!(function() {
1029
1029
  try {
1030
1030
  var t3 = g.resolve(1), n3 = (t3.constructor = {})[r(1)("species")] = function(t4) {
@@ -1058,9 +1058,9 @@ function requireDist() {
1058
1058
  var r2 = t3._c;
1059
1059
  _(function() {
1060
1060
  for (var e2 = t3._v, o2 = 1 == t3._s, i2 = 0, c2 = function(n4) {
1061
- var r3, i3, c3 = o2 ? n4.ok : n4.fail, u2 = n4.resolve, s2 = n4.reject, f2 = n4.domain;
1061
+ var r3, i3, c3 = o2 ? n4.ok : n4.fail, u2 = n4.resolve, s2 = n4.reject, f3 = n4.domain;
1062
1062
  try {
1063
- c3 ? (o2 || (2 == t3._h && I(t3), t3._h = 1), c3 === true ? r3 = e2 : (f2 && f2.enter(), r3 = c3(e2), f2 && f2.exit()), r3 === n4.promise ? s2(m("Promise-chain cycle")) : (i3 = E(r3)) ? i3.call(r3, u2, s2) : u2(r3)) : s2(e2);
1063
+ c3 ? (o2 || (2 == t3._h && I(t3), t3._h = 1), c3 === true ? r3 = e2 : (f3 && f3.enter(), r3 = c3(e2), f3 && f3.exit()), r3 === n4.promise ? s2(m("Promise-chain cycle")) : (i3 = E(r3)) ? i3.call(r3, u2, s2) : u2(r3)) : s2(e2);
1064
1064
  } catch (t4) {
1065
1065
  s2(t4);
1066
1066
  }
@@ -1162,8 +1162,8 @@ function requireDist() {
1162
1162
  }, function(t2, n2, r) {
1163
1163
  r(65);
1164
1164
  for (var e = r(2), o = r(5), i = r(10), c = r(1)("toStringTag"), u = ["NodeList", "DOMTokenList", "MediaList", "StyleSheetList", "CSSRuleList"], s = 0; s < 5; s++) {
1165
- var f = u[s], a = e[f], p = a && a.prototype;
1166
- p && !p[c] && o(p, c, f), i[f] = i.Array;
1165
+ var f2 = u[s], a = e[f2], p = a && a.prototype;
1166
+ p && !p[c] && o(p, c, f2), i[f2] = i.Array;
1167
1167
  }
1168
1168
  }, function(t2, n2) {
1169
1169
  t2.exports = require$$0$1;
@@ -1175,9 +1175,9 @@ function requireDist() {
1175
1175
  return dist$1.exports;
1176
1176
  }
1177
1177
  requireDist();
1178
- var map$1;
1178
+ var map$2;
1179
1179
  try {
1180
- map$1 = Map;
1180
+ map$2 = Map;
1181
1181
  } catch (_) {
1182
1182
  }
1183
1183
  var set$1;
@@ -1201,7 +1201,7 @@ function baseClone(src, circulars, clones) {
1201
1201
  if (Array.isArray(src)) {
1202
1202
  return src.map(clone$1);
1203
1203
  }
1204
- if (map$1 && src instanceof map$1) {
1204
+ if (map$2 && src instanceof map$2) {
1205
1205
  return new Map(Array.from(src.entries()));
1206
1206
  }
1207
1207
  if (set$1 && src instanceof set$1) {
@@ -3751,7 +3751,7 @@ function pipe$1(...fns) {
3751
3751
  return res;
3752
3752
  };
3753
3753
  }
3754
- curry(pMap);
3754
+ const map$1 = curry(pMap);
3755
3755
  const visitor$4 = ({ key, attribute }, { remove }) => {
3756
3756
  if (attribute?.type === "password") {
3757
3757
  remove(key);
@@ -4069,7 +4069,7 @@ const sort = traverseFactory().intercept(
4069
4069
  return Promise.all(sort2.map((nestedSort) => recurse(visitor2, options, nestedSort))).then((res) => res.filter((nestedSort) => !isEmpty$2(nestedSort)));
4070
4070
  }
4071
4071
  ).parse(isString, () => {
4072
- const tokenize = pipe$2(split("."), map$2(split(":")), flatten);
4072
+ const tokenize = pipe$2(split("."), map$3(split(":")), flatten);
4073
4073
  const recompose = (parts) => {
4074
4074
  if (parts.length === 0) {
4075
4075
  return void 0;
@@ -18402,6 +18402,19 @@ function asBoolean(value) {
18402
18402
  const normalized = value.toLowerCase().trim();
18403
18403
  return normalized !== "false" && normalized !== "0";
18404
18404
  }
18405
+ const version = "1.15.0-rc.1";
18406
+ const name = "@fourlights/strapi-plugin-deep-populate";
18407
+ const f = (msg, context = void 0) => {
18408
+ const prefix = `[${name}] `;
18409
+ const suffix = context !== void 0 ? `
18410
+ ${prefix}${context}` : "";
18411
+ return `${prefix}${msg}${suffix}`;
18412
+ };
18413
+ const error = (msg, context = void 0) => strapi.log.error(f(msg, context));
18414
+ const warn = (msg, context = void 0) => strapi.log.warn(f(msg, context));
18415
+ const info = (msg, context = void 0) => strapi.log.info(f(msg, context));
18416
+ const debug = (msg, context = void 0) => strapi.log.debug(f(msg, context));
18417
+ const log = { error, warn, info, debug };
18405
18418
  const populateIsWildcardEquivalent = async ({
18406
18419
  strapi: strapi2,
18407
18420
  schema: schema2,
@@ -18417,9 +18430,35 @@ const populateIsWildcardEquivalent = async ({
18417
18430
  );
18418
18431
  return populate2 === "*" || populate2 === true || JSON.stringify(expandedWildcardQuery) === JSON.stringify(populate2);
18419
18432
  };
18433
+ async function clearCacheForChangedSchemas(schemas) {
18434
+ await map$1(schemas, async (schema2) => {
18435
+ const deleted = await strapi.db.query("plugin::deep-populate.cache").deleteMany({
18436
+ where: {
18437
+ dependencies: { $contains: schema2 }
18438
+ }
18439
+ });
18440
+ log.debug(`Deleted ${deleted.count} cached entries due to out of date schema '${schema2}'`);
18441
+ });
18442
+ }
18420
18443
  const register = async ({ strapi: strapi2 }) => {
18444
+ strapi2.hook("strapi::content-types.beforeSync").register(async () => {
18445
+ const databaseSchema = await strapi2.db.dialect.schemaInspector.getSchema();
18446
+ const storedSchema = await strapi2.db.schema.schemaStorage.read();
18447
+ const { status, diff } = await strapi2.db.schema.schemaDiff.diff({
18448
+ previousSchema: storedSchema?.schema,
18449
+ databaseSchema,
18450
+ userSchema: strapi2.db.schema.schema
18451
+ });
18452
+ if (status === "CHANGED") {
18453
+ const updatedTables = (diff.tables.updated ?? []).map((t) => t.name);
18454
+ const updatedSchemas = [...strapi2.db.metadata.values()].filter((m) => updatedTables.includes(m.tableName)).map((m) => m.uid);
18455
+ const tableName = strapi2.db.metadata.get("plugin::deep-populate.cache").tableName;
18456
+ const hasTable = await strapi2.db.connection.schema.hasTable(tableName);
18457
+ if (hasTable) await clearCacheForChangedSchemas(updatedSchemas);
18458
+ }
18459
+ });
18421
18460
  strapi2.hook("strapi::content-types.afterSync").register(async () => {
18422
- const tableName = "populate_cache";
18461
+ const tableName = strapi2.db.metadata.get("plugin::deep-populate.cache").tableName;
18423
18462
  const columnName = "dependencies";
18424
18463
  const hasIndex = await hasDeepPopulateCacheFullTextIndex(strapi2.db, tableName, columnName);
18425
18464
  const hasTable = await strapi2.db.connection.schema.hasTable(tableName);
@@ -18494,13 +18533,23 @@ const register = async ({ strapi: strapi2 }) => {
18494
18533
  return result;
18495
18534
  });
18496
18535
  };
18497
- const version = "1.14.0";
18498
- const name = "@fourlights/strapi-plugin-deep-populate";
18499
- const error = (msg, context = void 0) => strapi.log.error(`[${name}] ${msg}`, context);
18500
- const warn = (msg, context = void 0) => strapi.log.warn(`[${name}] ${msg}`, context);
18501
- const info = (msg, context = void 0) => strapi.log.info(`[${name}] ${msg}`, context);
18502
- const debug = (msg, context = void 0) => strapi.log.debug(`[${name}] ${msg}`, context);
18503
- const log = { error, warn, info, debug };
18536
+ const UniqueConstraintErrorCodes = {
18537
+ // PostgreSQL
18538
+ POSTGRES_UNIQUE_VIOLATION: "23505",
18539
+ // MySQL
18540
+ MYSQL_DUPLICATE_ENTRY: 1062,
18541
+ // SQLite
18542
+ SQLITE_CONSTRAINT: 19,
18543
+ SQLITE_CONSTRAINT_UNIQUE: 2067,
18544
+ // SQL Server
18545
+ SQLSERVER_DUPLICATE_KEY: 2601,
18546
+ SQLSERVER_UNIQUE_KEY_VIOLATION: 2627
18547
+ };
18548
+ const isUniqueConstraintError = (error2) => {
18549
+ const err = error2;
18550
+ return Object.keys(UniqueConstraintErrorCodes).includes(err.code) || err.code === UniqueConstraintErrorCodes.POSTGRES_UNIQUE_VIOLATION || err.errno === UniqueConstraintErrorCodes.MYSQL_DUPLICATE_ENTRY || err.errno === UniqueConstraintErrorCodes.SQLITE_CONSTRAINT || err.errno === UniqueConstraintErrorCodes.SQLITE_CONSTRAINT_UNIQUE || err.number === UniqueConstraintErrorCodes.SQLSERVER_DUPLICATE_KEY || err.number === UniqueConstraintErrorCodes.SQLSERVER_UNIQUE_KEY_VIOLATION;
18551
+ };
18552
+ const majorMinorVersion = version.split(".").slice(0, -1).join(".");
18504
18553
  const sanitizeObject = (obj) => {
18505
18554
  if (obj === null || typeof obj !== "object") return obj;
18506
18555
  const dangerousProps = ["__proto__", "constructor", "prototype"];
@@ -18556,7 +18605,6 @@ const getConfig = (params) => {
18556
18605
  const localizations = params.localizations ?? contentTypeConfig.localizations ?? localizationsFallback;
18557
18606
  return { allow, deny, omitEmpty, localizations };
18558
18607
  };
18559
- const majorMinorVersion = version.split(".").slice(0, -1).join(".");
18560
18608
  const isEqualConfig = (lhs, rhs) => {
18561
18609
  const cleanedLhs = JSON.parse(JSON.stringify(lhs));
18562
18610
  const cleanedRhs = JSON.parse(JSON.stringify(rhs));
@@ -18581,15 +18629,19 @@ const cache = ({ strapi: strapi2 }) => ({
18581
18629
  async set({ populate: populate2, dependencies, ...params }) {
18582
18630
  const documentService = strapi2.documents("plugin::deep-populate.cache");
18583
18631
  const hash = getHash(params);
18584
- const entry = await documentService.findFirst({ filters: { hash: { $eq: hash } } });
18585
18632
  try {
18586
- return entry ? await documentService.update({
18587
- documentId: entry.documentId,
18588
- data: { populate: populate2, dependencies: dependencies.join(",") }
18589
- }) : await documentService.create({ data: { hash, params, populate: populate2, dependencies: dependencies.join(",") } });
18633
+ return await documentService.create({ data: { hash, params, populate: populate2, dependencies: dependencies.join(",") } });
18590
18634
  } catch (error2) {
18591
- log.error("[Plugin: Deep Populate] Failed to save cached entry", { error: error2 });
18592
- return;
18635
+ if (isUniqueConstraintError(error2)) {
18636
+ const entry = await documentService.findFirst({ filters: { hash: { $eq: hash } } });
18637
+ if (entry) {
18638
+ return await documentService.update({
18639
+ documentId: entry.documentId,
18640
+ data: { populate: populate2, dependencies: dependencies.join(",") }
18641
+ });
18642
+ }
18643
+ }
18644
+ log.error("Failed to save cached entry", error2);
18593
18645
  }
18594
18646
  },
18595
18647
  async clear(params) {
@@ -18756,6 +18808,7 @@ async function _populate({
18756
18808
  populate: populate2 = {},
18757
18809
  lookup = [],
18758
18810
  resolvedRelations,
18811
+ resolvedSchemas,
18759
18812
  omitEmpty,
18760
18813
  __deny,
18761
18814
  __allow,
@@ -18771,6 +18824,7 @@ async function _populate({
18771
18824
  let relations = getRelations(model);
18772
18825
  let currentPopulate = cloneDeep$1(populate2);
18773
18826
  resolvedRelations.set(params.documentId, true);
18827
+ resolvedSchemas.add(schema2);
18774
18828
  for (const [attrName, attr] of relations) {
18775
18829
  if (lookup.length > 0) {
18776
18830
  const parent = get$2(currentPopulate, lookup);
@@ -18842,6 +18896,7 @@ async function _populate({
18842
18896
  lookup,
18843
18897
  attrName,
18844
18898
  resolvedRelations,
18899
+ resolvedSchemas,
18845
18900
  omitEmpty,
18846
18901
  __deny,
18847
18902
  __allow,
@@ -18853,6 +18908,7 @@ async function _populate({
18853
18908
  contentType: attr.target,
18854
18909
  relation: value,
18855
18910
  resolvedRelations,
18911
+ resolvedSchemas,
18856
18912
  omitEmpty,
18857
18913
  locale: params.locale,
18858
18914
  status: params.status,
@@ -18868,6 +18924,7 @@ async function _populate({
18868
18924
  lookup,
18869
18925
  attrName,
18870
18926
  resolvedRelations,
18927
+ resolvedSchemas,
18871
18928
  omitEmpty,
18872
18929
  __deny,
18873
18930
  __allow,
@@ -18883,9 +18940,11 @@ async function _populate({
18883
18940
  async function populate$1(params) {
18884
18941
  const config2 = getConfig(params);
18885
18942
  const resolvedRelations = /* @__PURE__ */ new Map();
18943
+ const resolvedSchemas = /* @__PURE__ */ new Set();
18886
18944
  const populated = await _populate({
18887
18945
  schema: params.contentType,
18888
18946
  resolvedRelations,
18947
+ resolvedSchemas,
18889
18948
  omitEmpty: config2.omitEmpty,
18890
18949
  localizations: config2.localizations,
18891
18950
  __deny: config2.deny,
@@ -18894,7 +18953,11 @@ async function populate$1(params) {
18894
18953
  });
18895
18954
  populated.__deepPopulated = true;
18896
18955
  populated.__deepPopulateConfig = config2;
18897
- const dependencies = [...resolvedRelations.keys()].filter((r) => !r.startsWith("api::"));
18956
+ const dependencies = [
18957
+ ...[...resolvedRelations.keys()].filter((r) => !r.startsWith("api::")),
18958
+ // Remove content-types from resolved relations
18959
+ ...resolvedSchemas.values()
18960
+ ];
18898
18961
  return { populate: populated, dependencies };
18899
18962
  }
18900
18963
  const populate = ({ strapi: strapi2 }) => ({
@@ -1,3 +1,5 @@
1
+ import type { UID } from "@strapi/strapi";
2
+ export declare function clearCacheForChangedSchemas(schemas: UID.Schema[]): Promise<void>;
1
3
  declare const _default: ({ strapi }: {
2
4
  strapi: any;
3
5
  }) => Promise<void>;
@@ -0,0 +1 @@
1
+ export declare const isUniqueConstraintError: (error: unknown) => boolean;
@@ -1,11 +1,11 @@
1
- export declare const error: (msg: any, context?: any) => import("winston").Logger;
2
- export declare const warn: (msg: any, context?: any) => import("winston").Logger;
3
- export declare const info: (msg: any, context?: any) => import("winston").Logger;
4
- export declare const debug: (msg: any, context?: any) => import("winston").Logger;
1
+ export declare const error: (msg: string, context?: any) => import("winston").Logger;
2
+ export declare const warn: (msg: string, context?: any) => import("winston").Logger;
3
+ export declare const info: (msg: string, context?: any) => import("winston").Logger;
4
+ export declare const debug: (msg: string, context?: any) => import("winston").Logger;
5
5
  declare const _default: {
6
- error: (msg: any, context?: any) => import("winston").Logger;
7
- warn: (msg: any, context?: any) => import("winston").Logger;
8
- info: (msg: any, context?: any) => import("winston").Logger;
9
- debug: (msg: any, context?: any) => import("winston").Logger;
6
+ error: (msg: string, context?: any) => import("winston").Logger;
7
+ warn: (msg: string, context?: any) => import("winston").Logger;
8
+ info: (msg: string, context?: any) => import("winston").Logger;
9
+ debug: (msg: string, context?: any) => import("winston").Logger;
10
10
  };
11
11
  export default _default;
@@ -0,0 +1 @@
1
+ export declare const majorMinorVersion: string;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.14.0",
2
+ "version": "1.15.0-rc.1",
3
3
  "keywords": [
4
4
  "strapi",
5
5
  "strapi-plugin",