@fourlights/strapi-plugin-deep-populate 1.5.0 → 1.6.0

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.
@@ -21,6 +21,7 @@ const require$$2$1 = require("util");
21
21
  const require$$0$8 = require("constants");
22
22
  require("node:stream");
23
23
  const cloneDeep = require("lodash/cloneDeep");
24
+ const unset = require("lodash/unset");
24
25
  const get = require("lodash/get");
25
26
  const mergeWith = require("lodash/mergeWith");
26
27
  const set$2 = require("lodash/set");
@@ -45,6 +46,7 @@ const require$$0__default$5 = /* @__PURE__ */ _interopDefault(require$$0$6);
45
46
  const require$$2__default$1 = /* @__PURE__ */ _interopDefault(require$$2$1);
46
47
  const require$$0__default$7 = /* @__PURE__ */ _interopDefault(require$$0$8);
47
48
  const cloneDeep__default = /* @__PURE__ */ _interopDefault(cloneDeep);
49
+ const unset__default = /* @__PURE__ */ _interopDefault(unset);
48
50
  const get__default = /* @__PURE__ */ _interopDefault(get);
49
51
  const mergeWith__default = /* @__PURE__ */ _interopDefault(mergeWith);
50
52
  const set__default = /* @__PURE__ */ _interopDefault(set$2);
@@ -12941,12 +12943,12 @@ const utils = {
12941
12943
  return new Date(getKey(key));
12942
12944
  },
12943
12945
  /**
12944
- * Gets a value from env that matches oneOf provided values
12945
- * @param {string} key
12946
- * @param {string[]} expectedValues
12947
- * @param {string|undefined} defaultValue
12948
- * @returns {string|undefined}
12949
- */
12946
+ * Gets a value from env that matches oneOf provided values
12947
+ * @param {string} key
12948
+ * @param {string[]} expectedValues
12949
+ * @param {string|undefined} defaultValue
12950
+ * @returns {string|undefined}
12951
+ */
12950
12952
  oneOf(key, expectedValues, defaultValue) {
12951
12953
  if (!expectedValues) {
12952
12954
  throw new Error(`env.oneOf requires expectedValues`);
@@ -13001,11 +13003,7 @@ const getCreatorFields = (model) => {
13001
13003
  };
13002
13004
  const getNonWritableAttributes = (model) => {
13003
13005
  if (!model) return [];
13004
- const nonWritableAttributes = ___default__default.default.reduce(
13005
- model.attributes,
13006
- (acc, attr, attrName) => attr.writable === false ? acc.concat(attrName) : acc,
13007
- []
13008
- );
13006
+ const nonWritableAttributes = ___default__default.default.reduce(model.attributes, (acc, attr, attrName) => attr.writable === false ? acc.concat(attrName) : acc, []);
13009
13007
  return ___default__default.default.uniq([
13010
13008
  ID_ATTRIBUTE$4,
13011
13009
  DOC_ID_ATTRIBUTE$4,
@@ -13021,12 +13019,13 @@ const isWritableAttribute = (model, attributeName) => {
13021
13019
  return getWritableAttributes(model).includes(attributeName);
13022
13020
  };
13023
13021
  const getNonVisibleAttributes = (model) => {
13024
- const nonVisibleAttributes = ___default__default.default.reduce(
13025
- model.attributes,
13026
- (acc, attr, attrName) => attr.visible === false ? acc.concat(attrName) : acc,
13027
- []
13028
- );
13029
- return ___default__default.default.uniq([ID_ATTRIBUTE$4, DOC_ID_ATTRIBUTE$4, ...getTimestamps(model), ...nonVisibleAttributes]);
13022
+ const nonVisibleAttributes = ___default__default.default.reduce(model.attributes, (acc, attr, attrName) => attr.visible === false ? acc.concat(attrName) : acc, []);
13023
+ return ___default__default.default.uniq([
13024
+ ID_ATTRIBUTE$4,
13025
+ DOC_ID_ATTRIBUTE$4,
13026
+ ...getTimestamps(model),
13027
+ ...nonVisibleAttributes
13028
+ ]);
13030
13029
  };
13031
13030
  const getVisibleAttributes = (model) => {
13032
13031
  return ___default__default.default.difference(___default__default.default.keys(model.attributes), getNonVisibleAttributes(model));
@@ -13034,11 +13033,16 @@ const getVisibleAttributes = (model) => {
13034
13033
  const isVisibleAttribute = (model, attributeName) => {
13035
13034
  return getVisibleAttributes(model).includes(attributeName);
13036
13035
  };
13037
- const getOptions = (model) => ___default__default.default.assign({ draftAndPublish: false }, ___default__default.default.get(model, "options", {}));
13036
+ const getOptions = (model) => ___default__default.default.assign({
13037
+ draftAndPublish: false
13038
+ }, ___default__default.default.get(model, "options", {}));
13038
13039
  const hasDraftAndPublish = (model) => ___default__default.default.get(model, "options.draftAndPublish", false) === true;
13039
13040
  const isDraft = (data, model) => hasDraftAndPublish(model) && ___default__default.default.get(data, PUBLISHED_AT_ATTRIBUTE$1) === null;
13040
13041
  const isSchema = (data) => {
13041
- return typeof data === "object" && data !== null && "modelType" in data && typeof data.modelType === "string" && ["component", "contentType"].includes(data.modelType);
13042
+ return typeof data === "object" && data !== null && "modelType" in data && typeof data.modelType === "string" && [
13043
+ "component",
13044
+ "contentType"
13045
+ ].includes(data.modelType);
13042
13046
  };
13043
13047
  const isComponentSchema = (data) => {
13044
13048
  return isSchema(data) && data.modelType === "component";
@@ -13049,15 +13053,9 @@ const isContentTypeSchema = (data) => {
13049
13053
  const isSingleType = ({ kind = COLLECTION_TYPE }) => kind === SINGLE_TYPE;
13050
13054
  const isCollectionType = ({ kind = COLLECTION_TYPE }) => kind === COLLECTION_TYPE;
13051
13055
  const isKind = (kind) => (model) => model.kind === kind;
13052
- const getStoredPrivateAttributes = (model) => fp.union(
13053
- strapi?.config?.get("api.responses.privateAttributes", []) ?? [],
13054
- fp.getOr([], "options.privateAttributes", model)
13055
- );
13056
+ const getStoredPrivateAttributes = (model) => fp.union(strapi?.config?.get("api.responses.privateAttributes", []) ?? [], fp.getOr([], "options.privateAttributes", model));
13056
13057
  const getPrivateAttributes = (model) => {
13057
- return ___default__default.default.union(
13058
- getStoredPrivateAttributes(model),
13059
- ___default__default.default.keys(___default__default.default.pickBy(model.attributes, (attr) => !!attr.private))
13060
- );
13058
+ return ___default__default.default.union(getStoredPrivateAttributes(model), ___default__default.default.keys(___default__default.default.pickBy(model.attributes, (attr) => !!attr.private)));
13061
13059
  };
13062
13060
  const isPrivateAttribute = (model, attributeName) => {
13063
13061
  if (model?.attributes?.[attributeName]?.private === true) {
@@ -13066,49 +13064,49 @@ const isPrivateAttribute = (model, attributeName) => {
13066
13064
  return getStoredPrivateAttributes(model).includes(attributeName);
13067
13065
  };
13068
13066
  const isScalarAttribute = (attribute) => {
13069
- return attribute && !["media", "component", "relation", "dynamiczone"].includes(attribute.type);
13067
+ return attribute && ![
13068
+ "media",
13069
+ "component",
13070
+ "relation",
13071
+ "dynamiczone"
13072
+ ].includes(attribute.type);
13070
13073
  };
13071
13074
  const getDoesAttributeRequireValidation = (attribute) => {
13072
13075
  return attribute.required || attribute.unique || Object.prototype.hasOwnProperty.call(attribute, "max") || Object.prototype.hasOwnProperty.call(attribute, "min") || Object.prototype.hasOwnProperty.call(attribute, "maxLength") || Object.prototype.hasOwnProperty.call(attribute, "minLength");
13073
13076
  };
13074
13077
  const isMediaAttribute = (attribute) => attribute?.type === "media";
13075
13078
  const isRelationalAttribute = (attribute) => attribute?.type === "relation";
13076
- const HAS_RELATION_REORDERING = ["manyToMany", "manyToOne", "oneToMany"];
13079
+ const HAS_RELATION_REORDERING = [
13080
+ "manyToMany",
13081
+ "manyToOne",
13082
+ "oneToMany"
13083
+ ];
13077
13084
  const hasRelationReordering = (attribute) => isRelationalAttribute(attribute) && HAS_RELATION_REORDERING.includes(attribute.relation);
13078
- const isComponentAttribute = (attribute) => ["component", "dynamiczone"].includes(attribute?.type);
13085
+ const isComponentAttribute = (attribute) => [
13086
+ "component",
13087
+ "dynamiczone"
13088
+ ].includes(attribute?.type);
13079
13089
  const isDynamicZoneAttribute = (attribute) => !!attribute && attribute.type === "dynamiczone";
13080
13090
  const isMorphToRelationalAttribute = (attribute) => {
13081
13091
  return !!attribute && isRelationalAttribute(attribute) && attribute.relation?.startsWith?.("morphTo");
13082
13092
  };
13083
13093
  const getComponentAttributes = (schema2) => {
13084
- return ___default__default.default.reduce(
13085
- schema2.attributes,
13086
- (acc, attr, attrName) => {
13087
- if (isComponentAttribute(attr)) acc.push(attrName);
13088
- return acc;
13089
- },
13090
- []
13091
- );
13094
+ return ___default__default.default.reduce(schema2.attributes, (acc, attr, attrName) => {
13095
+ if (isComponentAttribute(attr)) acc.push(attrName);
13096
+ return acc;
13097
+ }, []);
13092
13098
  };
13093
13099
  const getScalarAttributes = (schema2) => {
13094
- return ___default__default.default.reduce(
13095
- schema2.attributes,
13096
- (acc, attr, attrName) => {
13097
- if (isScalarAttribute(attr)) acc.push(attrName);
13098
- return acc;
13099
- },
13100
- []
13101
- );
13100
+ return ___default__default.default.reduce(schema2.attributes, (acc, attr, attrName) => {
13101
+ if (isScalarAttribute(attr)) acc.push(attrName);
13102
+ return acc;
13103
+ }, []);
13102
13104
  };
13103
13105
  const getRelationalAttributes = (schema2) => {
13104
- return ___default__default.default.reduce(
13105
- schema2.attributes,
13106
- (acc, attr, attrName) => {
13107
- if (isRelationalAttribute(attr)) acc.push(attrName);
13108
- return acc;
13109
- },
13110
- []
13111
- );
13106
+ return ___default__default.default.reduce(schema2.attributes, (acc, attr, attrName) => {
13107
+ if (isRelationalAttribute(attr)) acc.push(attrName);
13108
+ return acc;
13109
+ }, []);
13112
13110
  };
13113
13111
  const isTypedAttribute = (attribute, type2) => {
13114
13112
  return ___default__default.default.has(attribute, "type") && attribute.type === type2;
@@ -13116,7 +13114,7 @@ const isTypedAttribute = (attribute, type2) => {
13116
13114
  const getContentTypeRoutePrefix = (contentType) => {
13117
13115
  return isSingleType(contentType) ? ___default__default.default.kebabCase(contentType.info.singularName) : ___default__default.default.kebabCase(contentType.info.pluralName);
13118
13116
  };
13119
- const contentTypes = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
13117
+ var contentTypes = /* @__PURE__ */ Object.freeze({
13120
13118
  __proto__: null,
13121
13119
  constants: constants$1,
13122
13120
  getComponentAttributes,
@@ -13151,44 +13149,76 @@ const contentTypes = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.define
13151
13149
  isTypedAttribute,
13152
13150
  isVisibleAttribute,
13153
13151
  isWritableAttribute
13154
- }, Symbol.toStringTag, { value: "Module" }));
13155
- const traverseEntity = async (visitor2, options, entity) => {
13156
- const { path: path2 = { raw: null, attribute: null }, schema: schema2, getModel } = options;
13152
+ });
13153
+ const traverseEntity = async (visitor, options, entity) => {
13154
+ const { path: path2 = {
13155
+ raw: null,
13156
+ attribute: null
13157
+ }, schema: schema2, getModel } = options;
13157
13158
  let parent = options.parent;
13158
- const traverseMorphRelationTarget = async (visitor22, path22, entry) => {
13159
+ const traverseMorphRelationTarget = async (visitor2, path3, entry) => {
13159
13160
  const targetSchema = getModel(entry.__type);
13160
- const traverseOptions = { schema: targetSchema, path: path22, getModel, parent };
13161
- return traverseEntity(visitor22, traverseOptions, entry);
13161
+ const traverseOptions = {
13162
+ schema: targetSchema,
13163
+ path: path3,
13164
+ getModel,
13165
+ parent
13166
+ };
13167
+ return traverseEntity(visitor2, traverseOptions, entry);
13162
13168
  };
13163
- const traverseRelationTarget = (schema22) => async (visitor22, path22, entry) => {
13164
- const traverseOptions = { schema: schema22, path: path22, getModel, parent };
13165
- return traverseEntity(visitor22, traverseOptions, entry);
13169
+ const traverseRelationTarget = (schema3) => async (visitor2, path3, entry) => {
13170
+ const traverseOptions = {
13171
+ schema: schema3,
13172
+ path: path3,
13173
+ getModel,
13174
+ parent
13175
+ };
13176
+ return traverseEntity(visitor2, traverseOptions, entry);
13166
13177
  };
13167
- const traverseMediaTarget = async (visitor22, path22, entry) => {
13178
+ const traverseMediaTarget = async (visitor2, path3, entry) => {
13168
13179
  const targetSchemaUID = "plugin::upload.file";
13169
13180
  const targetSchema = getModel(targetSchemaUID);
13170
- const traverseOptions = { schema: targetSchema, path: path22, getModel, parent };
13171
- return traverseEntity(visitor22, traverseOptions, entry);
13181
+ const traverseOptions = {
13182
+ schema: targetSchema,
13183
+ path: path3,
13184
+ getModel,
13185
+ parent
13186
+ };
13187
+ return traverseEntity(visitor2, traverseOptions, entry);
13172
13188
  };
13173
- const traverseComponent = async (visitor22, path22, schema22, entry) => {
13174
- const traverseOptions = { schema: schema22, path: path22, getModel, parent };
13175
- return traverseEntity(visitor22, traverseOptions, entry);
13189
+ const traverseComponent = async (visitor2, path3, schema3, entry) => {
13190
+ const traverseOptions = {
13191
+ schema: schema3,
13192
+ path: path3,
13193
+ getModel,
13194
+ parent
13195
+ };
13196
+ return traverseEntity(visitor2, traverseOptions, entry);
13176
13197
  };
13177
- const visitDynamicZoneEntry = async (visitor22, path22, entry) => {
13198
+ const visitDynamicZoneEntry = async (visitor2, path3, entry) => {
13178
13199
  const targetSchema = getModel(entry.__component);
13179
- const traverseOptions = { schema: targetSchema, path: path22, getModel, parent };
13180
- return traverseEntity(visitor22, traverseOptions, entry);
13200
+ const traverseOptions = {
13201
+ schema: targetSchema,
13202
+ path: path3,
13203
+ getModel,
13204
+ parent
13205
+ };
13206
+ return traverseEntity(visitor2, traverseOptions, entry);
13181
13207
  };
13182
13208
  if (!fp.isObject(entity) || fp.isNil(schema2)) {
13183
13209
  return entity;
13184
13210
  }
13185
13211
  const copy = fp.clone(entity);
13186
- const visitorUtils = createVisitorUtils({ data: copy });
13212
+ const visitorUtils = createVisitorUtils({
13213
+ data: copy
13214
+ });
13187
13215
  const keys = Object.keys(copy);
13188
13216
  for (let i = 0; i < keys.length; i += 1) {
13189
13217
  const key = keys[i];
13190
13218
  const attribute = schema2.attributes[key];
13191
- const newPath = { ...path2 };
13219
+ const newPath = {
13220
+ ...path2
13221
+ };
13192
13222
  newPath.raw = fp.isNil(path2.raw) ? key : `${path2.raw}.${key}`;
13193
13223
  if (!fp.isNil(attribute)) {
13194
13224
  newPath.attribute = fp.isNil(path2.attribute) ? key : `${path2.attribute}.${key}`;
@@ -13203,23 +13233,28 @@ const traverseEntity = async (visitor2, options, entity) => {
13203
13233
  getModel,
13204
13234
  parent
13205
13235
  };
13206
- await visitor2(visitorOptions, visitorUtils);
13236
+ await visitor(visitorOptions, visitorUtils);
13207
13237
  const value = copy[key];
13208
13238
  if (fp.isNil(value) || fp.isNil(attribute)) {
13209
13239
  continue;
13210
13240
  }
13211
- parent = { schema: schema2, key, attribute, path: newPath };
13241
+ parent = {
13242
+ schema: schema2,
13243
+ key,
13244
+ attribute,
13245
+ path: newPath
13246
+ };
13212
13247
  if (isRelationalAttribute(attribute)) {
13213
13248
  const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
13214
13249
  const method = isMorphRelation ? traverseMorphRelationTarget : traverseRelationTarget(getModel(attribute.target));
13215
13250
  if (fp.isArray(value)) {
13216
13251
  const res = new Array(value.length);
13217
13252
  for (let i2 = 0; i2 < value.length; i2 += 1) {
13218
- res[i2] = await method(visitor2, newPath, value[i2]);
13253
+ res[i2] = await method(visitor, newPath, value[i2]);
13219
13254
  }
13220
13255
  copy[key] = res;
13221
13256
  } else {
13222
- copy[key] = await method(visitor2, newPath, value);
13257
+ copy[key] = await method(visitor, newPath, value);
13223
13258
  }
13224
13259
  continue;
13225
13260
  }
@@ -13227,11 +13262,11 @@ const traverseEntity = async (visitor2, options, entity) => {
13227
13262
  if (fp.isArray(value)) {
13228
13263
  const res = new Array(value.length);
13229
13264
  for (let i2 = 0; i2 < value.length; i2 += 1) {
13230
- res[i2] = await traverseMediaTarget(visitor2, newPath, value[i2]);
13265
+ res[i2] = await traverseMediaTarget(visitor, newPath, value[i2]);
13231
13266
  }
13232
13267
  copy[key] = res;
13233
13268
  } else {
13234
- copy[key] = await traverseMediaTarget(visitor2, newPath, value);
13269
+ copy[key] = await traverseMediaTarget(visitor, newPath, value);
13235
13270
  }
13236
13271
  continue;
13237
13272
  }
@@ -13240,18 +13275,18 @@ const traverseEntity = async (visitor2, options, entity) => {
13240
13275
  if (fp.isArray(value)) {
13241
13276
  const res = new Array(value.length);
13242
13277
  for (let i2 = 0; i2 < value.length; i2 += 1) {
13243
- res[i2] = await traverseComponent(visitor2, newPath, targetSchema, value[i2]);
13278
+ res[i2] = await traverseComponent(visitor, newPath, targetSchema, value[i2]);
13244
13279
  }
13245
13280
  copy[key] = res;
13246
13281
  } else {
13247
- copy[key] = await traverseComponent(visitor2, newPath, targetSchema, value);
13282
+ copy[key] = await traverseComponent(visitor, newPath, targetSchema, value);
13248
13283
  }
13249
13284
  continue;
13250
13285
  }
13251
13286
  if (attribute.type === "dynamiczone" && fp.isArray(value)) {
13252
13287
  const res = new Array(value.length);
13253
13288
  for (let i2 = 0; i2 < value.length; i2 += 1) {
13254
- res[i2] = await visitDynamicZoneEntry(visitor2, newPath, value[i2]);
13289
+ res[i2] = await visitDynamicZoneEntry(visitor, newPath, value[i2]);
13255
13290
  }
13256
13291
  copy[key] = res;
13257
13292
  continue;
@@ -13267,8 +13302,11 @@ const createVisitorUtils = ({ data }) => ({
13267
13302
  data[key] = value;
13268
13303
  }
13269
13304
  });
13270
- const traverseEntity$1 = fp.curry(traverseEntity);
13271
- const GROUP_OPERATORS = ["$and", "$or"];
13305
+ var traverseEntity$1 = fp.curry(traverseEntity);
13306
+ const GROUP_OPERATORS = [
13307
+ "$and",
13308
+ "$or"
13309
+ ];
13272
13310
  const WHERE_OPERATORS = [
13273
13311
  "$not",
13274
13312
  "$in",
@@ -13307,19 +13345,21 @@ const CAST_OPERATORS = [
13307
13345
  "$lte",
13308
13346
  "$between"
13309
13347
  ];
13310
- const ARRAY_OPERATORS = ["$in", "$notIn", "$between"];
13348
+ const ARRAY_OPERATORS = [
13349
+ "$in",
13350
+ "$notIn",
13351
+ "$between"
13352
+ ];
13311
13353
  const OPERATORS = {
13312
13354
  where: WHERE_OPERATORS,
13313
13355
  cast: CAST_OPERATORS,
13314
13356
  group: GROUP_OPERATORS,
13315
13357
  array: ARRAY_OPERATORS
13316
13358
  };
13317
- const OPERATORS_LOWERCASE = Object.fromEntries(
13318
- Object.entries(OPERATORS).map(([key, values]) => [
13319
- key,
13320
- values.map((value) => value.toLowerCase())
13321
- ])
13322
- );
13359
+ const OPERATORS_LOWERCASE = Object.fromEntries(Object.entries(OPERATORS).map(([key, values]) => [
13360
+ key,
13361
+ values.map((value) => value.toLowerCase())
13362
+ ]));
13323
13363
  const isObjKey = (key, obj) => {
13324
13364
  return key in obj;
13325
13365
  };
@@ -13346,26 +13386,28 @@ function pipe(...fns) {
13346
13386
  };
13347
13387
  }
13348
13388
  fp.curry(pMap$1);
13349
- const visitor$8 = ({ key, attribute }, { remove: remove2 }) => {
13389
+ const visitor$8 = ({ key, attribute }, { remove }) => {
13350
13390
  if (attribute?.type === "password") {
13351
- remove2(key);
13391
+ remove(key);
13352
13392
  }
13353
13393
  };
13354
- const visitor$7 = ({ schema: schema2, key, attribute }, { remove: remove2 }) => {
13394
+ const visitor$7 = ({ schema: schema2, key, attribute }, { remove }) => {
13355
13395
  if (!attribute) {
13356
13396
  return;
13357
13397
  }
13358
13398
  const isPrivate = attribute.private === true || isPrivateAttribute(schema2, key);
13359
13399
  if (isPrivate) {
13360
- remove2(key);
13400
+ remove(key);
13361
13401
  }
13362
13402
  };
13363
13403
  const VALID_RELATION_ORDERING_KEYS = {
13364
13404
  strict: fp.isBoolean
13365
13405
  };
13366
- const ACTIONS_TO_VERIFY$1 = ["find"];
13406
+ const ACTIONS_TO_VERIFY$1 = [
13407
+ "find"
13408
+ ];
13367
13409
  const { CREATED_BY_ATTRIBUTE: CREATED_BY_ATTRIBUTE$1, UPDATED_BY_ATTRIBUTE: UPDATED_BY_ATTRIBUTE$1 } = constants$1;
13368
- const removeRestrictedRelations = (auth) => async ({ data, key, attribute, schema: schema2 }, { remove: remove2, set: set2 }) => {
13410
+ var removeRestrictedRelations = (auth) => async ({ data, key, attribute, schema: schema2 }, { remove, set: set2 }) => {
13369
13411
  if (!attribute) {
13370
13412
  return;
13371
13413
  }
@@ -13430,10 +13472,13 @@ const removeRestrictedRelations = (auth) => async ({ data, key, attribute, schem
13430
13472
  const scopes = ACTIONS_TO_VERIFY$1.map((action) => `${attribute.target}.${action}`);
13431
13473
  const isAllowed = await hasAccessToSomeScopes$1(scopes, auth);
13432
13474
  if (!isAllowed) {
13433
- remove2(key);
13475
+ remove(key);
13434
13476
  }
13435
13477
  };
13436
- const isCreatorRelation = [CREATED_BY_ATTRIBUTE$1, UPDATED_BY_ATTRIBUTE$1].includes(key);
13478
+ const isCreatorRelation = [
13479
+ CREATED_BY_ATTRIBUTE$1,
13480
+ UPDATED_BY_ATTRIBUTE$1
13481
+ ].includes(key);
13437
13482
  if (isMorphToRelationalAttribute(attribute)) {
13438
13483
  await handleMorphRelation();
13439
13484
  return;
@@ -13446,7 +13491,9 @@ const removeRestrictedRelations = (auth) => async ({ data, key, attribute, schem
13446
13491
  const hasAccessToSomeScopes$1 = async (scopes, auth) => {
13447
13492
  for (const scope of scopes) {
13448
13493
  try {
13449
- await strapi.auth.verify(auth, { scope });
13494
+ await strapi.auth.verify(auth, {
13495
+ scope
13496
+ });
13450
13497
  return true;
13451
13498
  } catch {
13452
13499
  continue;
@@ -13454,74 +13501,75 @@ const hasAccessToSomeScopes$1 = async (scopes, auth) => {
13454
13501
  }
13455
13502
  return false;
13456
13503
  };
13457
- const visitor$6 = ({ key, attribute }, { remove: remove2 }) => {
13504
+ const visitor$6 = ({ key, attribute }, { remove }) => {
13458
13505
  if (isMorphToRelationalAttribute(attribute)) {
13459
- remove2(key);
13506
+ remove(key);
13460
13507
  }
13461
13508
  };
13462
- const visitor$5 = ({ key, attribute }, { remove: remove2 }) => {
13509
+ const visitor$5 = ({ key, attribute }, { remove }) => {
13463
13510
  if (isDynamicZoneAttribute(attribute)) {
13464
- remove2(key);
13511
+ remove(key);
13465
13512
  }
13466
13513
  };
13467
- const removeDisallowedFields = (allowedFields = null) => ({ key, path: { attribute: path2 } }, { remove: remove2 }) => {
13514
+ var removeDisallowedFields = (allowedFields = null) => ({ key, path: { attribute: path2 } }, { remove }) => {
13468
13515
  if (allowedFields === null) {
13469
13516
  return;
13470
13517
  }
13471
13518
  if (!(fp.isArray(allowedFields) && allowedFields.every(fp.isString))) {
13472
- throw new TypeError(
13473
- `Expected array of strings for allowedFields but got "${typeof allowedFields}"`
13474
- );
13519
+ throw new TypeError(`Expected array of strings for allowedFields but got "${typeof allowedFields}"`);
13475
13520
  }
13476
13521
  if (fp.isNil(path2)) {
13477
13522
  return;
13478
13523
  }
13479
13524
  const containedPaths = getContainedPaths$1(path2);
13480
- const isPathAllowed = allowedFields.some(
13481
- (p) => containedPaths.includes(p) || p.startsWith(`${path2}.`)
13482
- );
13525
+ const isPathAllowed = allowedFields.some((p) => containedPaths.includes(p) || p.startsWith(`${path2}.`));
13483
13526
  if (isPathAllowed) {
13484
13527
  return;
13485
13528
  }
13486
- remove2(key);
13529
+ remove(key);
13487
13530
  };
13488
13531
  const getContainedPaths$1 = (path2) => {
13489
13532
  const parts = fp.toPath(path2);
13490
13533
  return parts.reduce((acc, value, index2, list) => {
13491
- return [...acc, list.slice(0, index2 + 1).join(".")];
13534
+ return [
13535
+ ...acc,
13536
+ list.slice(0, index2 + 1).join(".")
13537
+ ];
13492
13538
  }, []);
13493
13539
  };
13494
- const removeRestrictedFields = (restrictedFields = null) => ({ key, path: { attribute: path2 } }, { remove: remove2 }) => {
13540
+ var removeRestrictedFields = (restrictedFields = null) => ({ key, path: { attribute: path2 } }, { remove }) => {
13495
13541
  if (restrictedFields === null) {
13496
- remove2(key);
13542
+ remove(key);
13497
13543
  return;
13498
13544
  }
13499
13545
  if (!(fp.isArray(restrictedFields) && restrictedFields.every(fp.isString))) {
13500
- throw new TypeError(
13501
- `Expected array of strings for restrictedFields but got "${typeof restrictedFields}"`
13502
- );
13546
+ throw new TypeError(`Expected array of strings for restrictedFields but got "${typeof restrictedFields}"`);
13503
13547
  }
13504
13548
  if (restrictedFields.includes(path2)) {
13505
- remove2(key);
13549
+ remove(key);
13506
13550
  return;
13507
13551
  }
13508
- const isRestrictedNested = restrictedFields.some(
13509
- (allowedPath) => path2?.toString().startsWith(`${allowedPath}.`)
13510
- );
13552
+ const isRestrictedNested = restrictedFields.some((allowedPath) => path2?.toString().startsWith(`${allowedPath}.`));
13511
13553
  if (isRestrictedNested) {
13512
- remove2(key);
13554
+ remove(key);
13513
13555
  }
13514
13556
  };
13515
13557
  const visitor$4 = ({ schema: schema2, key, value }, { set: set2 }) => {
13516
13558
  if (key === "" && value === "*") {
13517
13559
  const { attributes } = schema2;
13518
- const newPopulateQuery = Object.entries(attributes).filter(
13519
- ([, attribute]) => ["relation", "component", "media", "dynamiczone"].includes(attribute.type)
13520
- ).reduce((acc, [key2]) => ({ ...acc, [key2]: true }), {});
13560
+ const newPopulateQuery = Object.entries(attributes).filter(([, attribute]) => [
13561
+ "relation",
13562
+ "component",
13563
+ "media",
13564
+ "dynamiczone"
13565
+ ].includes(attribute.type)).reduce((acc, [key2]) => ({
13566
+ ...acc,
13567
+ [key2]: true
13568
+ }), {});
13521
13569
  set2("", newPopulateQuery);
13522
13570
  }
13523
13571
  };
13524
- const index$4 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
13572
+ var index$4 = /* @__PURE__ */ Object.freeze({
13525
13573
  __proto__: null,
13526
13574
  expandWildcardPopulate: visitor$4,
13527
13575
  removeDisallowedFields,
@@ -13531,9 +13579,12 @@ const index$4 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePrope
13531
13579
  removePrivate: visitor$7,
13532
13580
  removeRestrictedFields,
13533
13581
  removeRestrictedRelations
13534
- }, Symbol.toStringTag, { value: "Module" }));
13535
- const DEFAULT_PATH = { raw: null, attribute: null };
13536
- const traverseFactory = () => {
13582
+ });
13583
+ const DEFAULT_PATH = {
13584
+ raw: null,
13585
+ attribute: null
13586
+ };
13587
+ var traverseFactory = () => {
13537
13588
  const state = {
13538
13589
  parsers: [],
13539
13590
  interceptors: [],
@@ -13543,11 +13594,13 @@ const traverseFactory = () => {
13543
13594
  common: []
13544
13595
  }
13545
13596
  };
13546
- const traverse = async (visitor2, options, data) => {
13597
+ const traverse = async (visitor, options, data) => {
13547
13598
  const { path: path2 = DEFAULT_PATH, parent, schema: schema2, getModel } = options ?? {};
13548
13599
  for (const { predicate, handler } of state.interceptors) {
13549
13600
  if (predicate(data)) {
13550
- return handler(visitor2, options, data, { recurse: traverse });
13601
+ return handler(visitor, options, data, {
13602
+ recurse: traverse
13603
+ });
13551
13604
  }
13552
13605
  }
13553
13606
  const parser = state.parsers.find((parser2) => parser2.predicate(data))?.parser;
@@ -13559,7 +13612,9 @@ const traverseFactory = () => {
13559
13612
  const keys = utils2.keys(out);
13560
13613
  for (const key of keys) {
13561
13614
  const attribute = schema2?.attributes?.[key];
13562
- const newPath = { ...path2 };
13615
+ const newPath = {
13616
+ ...path2
13617
+ };
13563
13618
  newPath.raw = fp.isNil(path2.raw) ? key : `${path2.raw}.${key}`;
13564
13619
  if (!fp.isNil(attribute)) {
13565
13620
  newPath.attribute = fp.isNil(path2.attribute) ? key : `${path2.attribute}.${key}`;
@@ -13583,7 +13638,10 @@ const traverseFactory = () => {
13583
13638
  },
13584
13639
  recurse: traverse
13585
13640
  };
13586
- await visitor2(visitorOptions, fp.pick(["remove", "set"], transformUtils));
13641
+ await visitor(visitorOptions, fp.pick([
13642
+ "remove",
13643
+ "set"
13644
+ ], transformUtils));
13587
13645
  const value = utils2.get(key, out);
13588
13646
  const createContext = () => ({
13589
13647
  key,
@@ -13592,7 +13650,7 @@ const traverseFactory = () => {
13592
13650
  schema: schema2,
13593
13651
  path: newPath,
13594
13652
  data: out,
13595
- visitor: visitor2,
13653
+ visitor,
13596
13654
  getModel,
13597
13655
  parent
13598
13656
  });
@@ -13601,12 +13659,18 @@ const traverseFactory = () => {
13601
13659
  if (shouldIgnore) {
13602
13660
  continue;
13603
13661
  }
13604
- const handlers = [...state.handlers.common, ...state.handlers.attributes];
13662
+ const handlers = [
13663
+ ...state.handlers.common,
13664
+ ...state.handlers.attributes
13665
+ ];
13605
13666
  for await (const handler of handlers) {
13606
13667
  const ctx = createContext();
13607
13668
  const pass = await handler.predicate(ctx);
13608
13669
  if (pass) {
13609
- await handler.handler(ctx, fp.pick(["recurse", "set"], transformUtils));
13670
+ await handler.handler(ctx, fp.pick([
13671
+ "recurse",
13672
+ "set"
13673
+ ], transformUtils));
13610
13674
  }
13611
13675
  }
13612
13676
  }
@@ -13615,11 +13679,17 @@ const traverseFactory = () => {
13615
13679
  return {
13616
13680
  traverse,
13617
13681
  intercept(predicate, handler) {
13618
- state.interceptors.push({ predicate, handler });
13682
+ state.interceptors.push({
13683
+ predicate,
13684
+ handler
13685
+ });
13619
13686
  return this;
13620
13687
  },
13621
13688
  parse(predicate, parser) {
13622
- state.parsers.push({ predicate, parser });
13689
+ state.parsers.push({
13690
+ predicate,
13691
+ parser
13692
+ });
13623
13693
  return this;
13624
13694
  },
13625
13695
  ignore(predicate) {
@@ -13627,11 +13697,17 @@ const traverseFactory = () => {
13627
13697
  return this;
13628
13698
  },
13629
13699
  on(predicate, handler) {
13630
- state.handlers.common.push({ predicate, handler });
13700
+ state.handlers.common.push({
13701
+ predicate,
13702
+ handler
13703
+ });
13631
13704
  return this;
13632
13705
  },
13633
13706
  onAttribute(predicate, handler) {
13634
- state.handlers.attributes.push({ predicate, handler });
13707
+ state.handlers.attributes.push({
13708
+ predicate,
13709
+ handler
13710
+ });
13635
13711
  return this;
13636
13712
  },
13637
13713
  onRelation(handler) {
@@ -13652,19 +13728,22 @@ const isObj$2 = (value) => fp.isObject(value);
13652
13728
  const filters = traverseFactory().intercept(
13653
13729
  // Intercept filters arrays and apply the traversal to each one individually
13654
13730
  fp.isArray,
13655
- async (visitor2, options, filters2, { recurse }) => {
13656
- return Promise.all(
13657
- filters2.map((filter, i) => {
13658
- const newPath = options.path ? { ...options.path, raw: `${options.path.raw}[${i}]` } : options.path;
13659
- return recurse(visitor2, { ...options, path: newPath }, filter);
13660
- })
13661
- // todo: move that to the visitors
13662
- ).then((res) => res.filter((val) => !(fp.isObject(val) && fp.isEmpty(val))));
13731
+ async (visitor, options, filters2, { recurse }) => {
13732
+ return Promise.all(filters2.map((filter, i) => {
13733
+ const newPath = options.path ? {
13734
+ ...options.path,
13735
+ raw: `${options.path.raw}[${i}]`
13736
+ } : options.path;
13737
+ return recurse(visitor, {
13738
+ ...options,
13739
+ path: newPath
13740
+ }, filter);
13741
+ })).then((res) => res.filter((val) => !(fp.isObject(val) && fp.isEmpty(val))));
13663
13742
  }
13664
13743
  ).intercept(
13665
13744
  // Ignore non object filters and return the value as-is
13666
13745
  (filters2) => !fp.isObject(filters2),
13667
- (_2, __, filters2) => {
13746
+ (_, __, filters2) => {
13668
13747
  return filters2;
13669
13748
  }
13670
13749
  ).parse(isObj$2, () => ({
@@ -13673,7 +13752,10 @@ const filters = traverseFactory().intercept(
13673
13752
  return fp.omit(key, data);
13674
13753
  },
13675
13754
  set(key, value, data) {
13676
- return { ...data, [key]: value };
13755
+ return {
13756
+ ...data,
13757
+ [key]: value
13758
+ };
13677
13759
  },
13678
13760
  keys(data) {
13679
13761
  return Object.keys(data);
@@ -13681,52 +13763,76 @@ const filters = traverseFactory().intercept(
13681
13763
  get(key, data) {
13682
13764
  return data[key];
13683
13765
  }
13684
- })).ignore(({ value }) => fp.isNil(value)).on(
13685
- ({ attribute }) => fp.isNil(attribute),
13686
- async ({ key, visitor: visitor2, path: path2, value, schema: schema2, getModel, attribute }, { set: set2, recurse }) => {
13687
- const parent = { key, path: path2, schema: schema2, attribute };
13688
- set2(key, await recurse(visitor2, { schema: schema2, path: path2, getModel, parent }, value));
13689
- }
13690
- ).onRelation(
13691
- async ({ key, attribute, visitor: visitor2, path: path2, value, schema: schema2, getModel }, { set: set2, recurse }) => {
13692
- const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
13693
- if (isMorphRelation) {
13694
- return;
13695
- }
13696
- const parent = { key, path: path2, schema: schema2, attribute };
13697
- const targetSchemaUID = attribute.target;
13698
- const targetSchema = getModel(targetSchemaUID);
13699
- const newValue = await recurse(
13700
- visitor2,
13701
- { schema: targetSchema, path: path2, getModel, parent },
13702
- value
13703
- );
13704
- set2(key, newValue);
13705
- }
13706
- ).onComponent(
13707
- async ({ key, attribute, visitor: visitor2, path: path2, schema: schema2, value, getModel }, { set: set2, recurse }) => {
13708
- const parent = { key, path: path2, schema: schema2, attribute };
13709
- const targetSchema = getModel(attribute.component);
13710
- const newValue = await recurse(
13711
- visitor2,
13712
- { schema: targetSchema, path: path2, getModel, parent },
13713
- value
13714
- );
13715
- set2(key, newValue);
13766
+ })).ignore(({ value }) => fp.isNil(value)).on(({ attribute }) => fp.isNil(attribute), async ({ key, visitor, path: path2, value, schema: schema2, getModel, attribute }, { set: set2, recurse }) => {
13767
+ const parent = {
13768
+ key,
13769
+ path: path2,
13770
+ schema: schema2,
13771
+ attribute
13772
+ };
13773
+ set2(key, await recurse(visitor, {
13774
+ schema: schema2,
13775
+ path: path2,
13776
+ getModel,
13777
+ parent
13778
+ }, value));
13779
+ }).onRelation(async ({ key, attribute, visitor, path: path2, value, schema: schema2, getModel }, { set: set2, recurse }) => {
13780
+ const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
13781
+ if (isMorphRelation) {
13782
+ return;
13716
13783
  }
13717
- ).onMedia(async ({ key, visitor: visitor2, path: path2, schema: schema2, attribute, value, getModel }, { set: set2, recurse }) => {
13718
- const parent = { key, path: path2, schema: schema2, attribute };
13784
+ const parent = {
13785
+ key,
13786
+ path: path2,
13787
+ schema: schema2,
13788
+ attribute
13789
+ };
13790
+ const targetSchemaUID = attribute.target;
13791
+ const targetSchema = getModel(targetSchemaUID);
13792
+ const newValue = await recurse(visitor, {
13793
+ schema: targetSchema,
13794
+ path: path2,
13795
+ getModel,
13796
+ parent
13797
+ }, value);
13798
+ set2(key, newValue);
13799
+ }).onComponent(async ({ key, attribute, visitor, path: path2, schema: schema2, value, getModel }, { set: set2, recurse }) => {
13800
+ const parent = {
13801
+ key,
13802
+ path: path2,
13803
+ schema: schema2,
13804
+ attribute
13805
+ };
13806
+ const targetSchema = getModel(attribute.component);
13807
+ const newValue = await recurse(visitor, {
13808
+ schema: targetSchema,
13809
+ path: path2,
13810
+ getModel,
13811
+ parent
13812
+ }, value);
13813
+ set2(key, newValue);
13814
+ }).onMedia(async ({ key, visitor, path: path2, schema: schema2, attribute, value, getModel }, { set: set2, recurse }) => {
13815
+ const parent = {
13816
+ key,
13817
+ path: path2,
13818
+ schema: schema2,
13819
+ attribute
13820
+ };
13719
13821
  const targetSchemaUID = "plugin::upload.file";
13720
13822
  const targetSchema = getModel(targetSchemaUID);
13721
- const newValue = await recurse(
13722
- visitor2,
13723
- { schema: targetSchema, path: path2, getModel, parent },
13724
- value
13725
- );
13823
+ const newValue = await recurse(visitor, {
13824
+ schema: targetSchema,
13825
+ path: path2,
13826
+ getModel,
13827
+ parent
13828
+ }, value);
13726
13829
  set2(key, newValue);
13727
13830
  });
13728
- const traverseQueryFilters = fp.curry(filters.traverse);
13729
- const ORDERS = { asc: "asc", desc: "desc" };
13831
+ var traverseQueryFilters = fp.curry(filters.traverse);
13832
+ const ORDERS = {
13833
+ asc: "asc",
13834
+ desc: "desc"
13835
+ };
13730
13836
  const ORDER_VALUES = Object.values(ORDERS);
13731
13837
  const isSortOrder = (value) => ORDER_VALUES.includes(value.toLowerCase());
13732
13838
  const isStringArray$2 = (value) => Array.isArray(value) && value.every(fp.isString);
@@ -13736,26 +13842,20 @@ const isObj$1 = (value) => fp.isObject(value);
13736
13842
  const sort = traverseFactory().intercept(
13737
13843
  // String with chained sorts (foo,bar,foobar) => split, map(recurse), then recompose
13738
13844
  isNestedSorts,
13739
- async (visitor2, options, sort2, { recurse }) => {
13740
- return Promise.all(
13741
- sort2.split(",").map(fp.trim).map((nestedSort) => recurse(visitor2, options, nestedSort))
13742
- ).then((res) => res.filter((part) => !fp.isEmpty(part)).join(","));
13845
+ async (visitor, options, sort2, { recurse }) => {
13846
+ return Promise.all(sort2.split(",").map(fp.trim).map((nestedSort) => recurse(visitor, options, nestedSort))).then((res) => res.filter((part) => !fp.isEmpty(part)).join(","));
13743
13847
  }
13744
13848
  ).intercept(
13745
13849
  // Array of strings ['foo', 'foo,bar'] => map(recurse), then filter out empty items
13746
13850
  isStringArray$2,
13747
- async (visitor2, options, sort2, { recurse }) => {
13748
- return Promise.all(sort2.map((nestedSort) => recurse(visitor2, options, nestedSort))).then(
13749
- (res) => res.filter((nestedSort) => !fp.isEmpty(nestedSort))
13750
- );
13851
+ async (visitor, options, sort2, { recurse }) => {
13852
+ return Promise.all(sort2.map((nestedSort) => recurse(visitor, options, nestedSort))).then((res) => res.filter((nestedSort) => !fp.isEmpty(nestedSort)));
13751
13853
  }
13752
13854
  ).intercept(
13753
13855
  // Array of objects [{ foo: 'asc' }, { bar: 'desc', baz: 'asc' }] => map(recurse), then filter out empty items
13754
13856
  isObjectArray,
13755
- async (visitor2, options, sort2, { recurse }) => {
13756
- return Promise.all(sort2.map((nestedSort) => recurse(visitor2, options, nestedSort))).then(
13757
- (res) => res.filter((nestedSort) => !fp.isEmpty(nestedSort))
13758
- );
13857
+ async (visitor, options, sort2, { recurse }) => {
13858
+ return Promise.all(sort2.map((nestedSort) => recurse(visitor, options, nestedSort))).then((res) => res.filter((nestedSort) => !fp.isEmpty(nestedSort)));
13759
13859
  }
13760
13860
  ).parse(fp.isString, () => {
13761
13861
  const tokenize = fp.pipe(fp.split("."), fp.map(fp.split(":")), fp.flatten);
@@ -13788,7 +13888,9 @@ const sort = traverseFactory().intercept(
13788
13888
  },
13789
13889
  keys(data) {
13790
13890
  const v = fp.first(tokenize(data));
13791
- return v ? [v] : [];
13891
+ return v ? [
13892
+ v
13893
+ ] : [];
13792
13894
  },
13793
13895
  get(key, data) {
13794
13896
  const [root2, ...rest] = tokenize(data);
@@ -13802,7 +13904,10 @@ const sort = traverseFactory().intercept(
13802
13904
  return rest;
13803
13905
  },
13804
13906
  set(key, value, data) {
13805
- return { ...data, [key]: value };
13907
+ return {
13908
+ ...data,
13909
+ [key]: value
13910
+ };
13806
13911
  },
13807
13912
  keys(data) {
13808
13913
  return Object.keys(data);
@@ -13810,45 +13915,59 @@ const sort = traverseFactory().intercept(
13810
13915
  get(key, data) {
13811
13916
  return data[key];
13812
13917
  }
13813
- })).onRelation(
13814
- async ({ key, value, attribute, visitor: visitor2, path: path2, getModel, schema: schema2 }, { set: set2, recurse }) => {
13815
- const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
13816
- if (isMorphRelation) {
13817
- return;
13818
- }
13819
- const parent = { key, path: path2, schema: schema2, attribute };
13820
- const targetSchemaUID = attribute.target;
13821
- const targetSchema = getModel(targetSchemaUID);
13822
- const newValue = await recurse(
13823
- visitor2,
13824
- { schema: targetSchema, path: path2, getModel, parent },
13825
- value
13826
- );
13827
- set2(key, newValue);
13918
+ })).onRelation(async ({ key, value, attribute, visitor, path: path2, getModel, schema: schema2 }, { set: set2, recurse }) => {
13919
+ const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
13920
+ if (isMorphRelation) {
13921
+ return;
13828
13922
  }
13829
- ).onMedia(async ({ key, path: path2, schema: schema2, attribute, visitor: visitor2, value, getModel }, { recurse, set: set2 }) => {
13830
- const parent = { key, path: path2, schema: schema2, attribute };
13923
+ const parent = {
13924
+ key,
13925
+ path: path2,
13926
+ schema: schema2,
13927
+ attribute
13928
+ };
13929
+ const targetSchemaUID = attribute.target;
13930
+ const targetSchema = getModel(targetSchemaUID);
13931
+ const newValue = await recurse(visitor, {
13932
+ schema: targetSchema,
13933
+ path: path2,
13934
+ getModel,
13935
+ parent
13936
+ }, value);
13937
+ set2(key, newValue);
13938
+ }).onMedia(async ({ key, path: path2, schema: schema2, attribute, visitor, value, getModel }, { recurse, set: set2 }) => {
13939
+ const parent = {
13940
+ key,
13941
+ path: path2,
13942
+ schema: schema2,
13943
+ attribute
13944
+ };
13831
13945
  const targetSchemaUID = "plugin::upload.file";
13832
13946
  const targetSchema = getModel(targetSchemaUID);
13833
- const newValue = await recurse(
13834
- visitor2,
13835
- { schema: targetSchema, path: path2, getModel, parent },
13836
- value
13837
- );
13947
+ const newValue = await recurse(visitor, {
13948
+ schema: targetSchema,
13949
+ path: path2,
13950
+ getModel,
13951
+ parent
13952
+ }, value);
13838
13953
  set2(key, newValue);
13839
- }).onComponent(
13840
- async ({ key, value, visitor: visitor2, path: path2, schema: schema2, attribute, getModel }, { recurse, set: set2 }) => {
13841
- const parent = { key, path: path2, schema: schema2, attribute };
13842
- const targetSchema = getModel(attribute.component);
13843
- const newValue = await recurse(
13844
- visitor2,
13845
- { schema: targetSchema, path: path2, getModel, parent },
13846
- value
13847
- );
13848
- set2(key, newValue);
13849
- }
13850
- );
13851
- const traverseQuerySort = fp.curry(sort.traverse);
13954
+ }).onComponent(async ({ key, value, visitor, path: path2, schema: schema2, attribute, getModel }, { recurse, set: set2 }) => {
13955
+ const parent = {
13956
+ key,
13957
+ path: path2,
13958
+ schema: schema2,
13959
+ attribute
13960
+ };
13961
+ const targetSchema = getModel(attribute.component);
13962
+ const newValue = await recurse(visitor, {
13963
+ schema: targetSchema,
13964
+ path: path2,
13965
+ getModel,
13966
+ parent
13967
+ }, value);
13968
+ set2(key, newValue);
13969
+ });
13970
+ var traverseQuerySort = fp.curry(sort.traverse);
13852
13971
  const isKeyword = (keyword) => {
13853
13972
  return ({ key, attribute }) => {
13854
13973
  return !attribute && keyword === key;
@@ -13860,39 +13979,41 @@ const isPopulateString = (value) => {
13860
13979
  };
13861
13980
  const isStringArray$1 = (value) => fp.isArray(value) && value.every(fp.isString);
13862
13981
  const isObj = (value) => fp.isObject(value);
13863
- const populate$2 = traverseFactory().intercept(isPopulateString, async (visitor2, options, populate2, { recurse }) => {
13864
- const populateObject = pathsToObjectPopulate([populate2]);
13865
- const traversedPopulate = await recurse(visitor2, options, populateObject);
13982
+ const populate$2 = traverseFactory().intercept(isPopulateString, async (visitor, options, populate2, { recurse }) => {
13983
+ const populateObject = pathsToObjectPopulate([
13984
+ populate2
13985
+ ]);
13986
+ const traversedPopulate = await recurse(visitor, options, populateObject);
13866
13987
  const [result] = objectPopulateToPaths(traversedPopulate);
13867
13988
  return result;
13868
- }).intercept(isStringArray$1, async (visitor2, options, populate2, { recurse }) => {
13869
- const paths = await Promise.all(
13870
- populate2.map((subClause) => recurse(visitor2, options, subClause))
13871
- );
13989
+ }).intercept(isStringArray$1, async (visitor, options, populate2, { recurse }) => {
13990
+ const paths = await Promise.all(populate2.map((subClause) => recurse(visitor, options, subClause)));
13872
13991
  return paths.filter((item) => !fp.isNil(item));
13873
13992
  }).parse(isWildcard, () => ({
13874
13993
  /**
13875
- * Since value is '*', we don't need to transform it
13876
- */
13994
+ * Since value is '*', we don't need to transform it
13995
+ */
13877
13996
  transform: fp.identity,
13878
13997
  /**
13879
- * '*' isn't a key/value structure, so regardless
13880
- * of the given key, it returns the data ('*')
13881
- */
13998
+ * '*' isn't a key/value structure, so regardless
13999
+ * of the given key, it returns the data ('*')
14000
+ */
13882
14001
  get: (_key, data) => data,
13883
14002
  /**
13884
- * '*' isn't a key/value structure, so regardless
13885
- * of the given `key`, use `value` as the new `data`
13886
- */
14003
+ * '*' isn't a key/value structure, so regardless
14004
+ * of the given `key`, use `value` as the new `data`
14005
+ */
13887
14006
  set: (_key, value) => value,
13888
14007
  /**
13889
- * '*' isn't a key/value structure, but we need to simulate at least one to enable
13890
- * the data traversal. We're using '' since it represents a falsy string value
13891
- */
13892
- keys: fp.constant([""]),
14008
+ * '*' isn't a key/value structure, but we need to simulate at least one to enable
14009
+ * the data traversal. We're using '' since it represents a falsy string value
14010
+ */
14011
+ keys: fp.constant([
14012
+ ""
14013
+ ]),
13893
14014
  /**
13894
- * Removing '*' means setting it to undefined, regardless of the given key
13895
- */
14015
+ * Removing '*' means setting it to undefined, regardless of the given key
14016
+ */
13896
14017
  remove: fp.constant(void 0)
13897
14018
  })).parse(fp.isString, () => {
13898
14019
  const tokenize = fp.split(".");
@@ -13912,7 +14033,9 @@ const populate$2 = traverseFactory().intercept(isPopulateString, async (visitor2
13912
14033
  },
13913
14034
  keys(data) {
13914
14035
  const v = fp.first(tokenize(data));
13915
- return v ? [v] : [];
14036
+ return v ? [
14037
+ v
14038
+ ] : [];
13916
14039
  },
13917
14040
  get(key, data) {
13918
14041
  const [root2, ...rest] = tokenize(data);
@@ -13926,7 +14049,10 @@ const populate$2 = traverseFactory().intercept(isPopulateString, async (visitor2
13926
14049
  return rest;
13927
14050
  },
13928
14051
  set(key, value, data) {
13929
- return { ...data, [key]: value };
14052
+ return {
14053
+ ...data,
14054
+ [key]: value
14055
+ };
13930
14056
  },
13931
14057
  keys(data) {
13932
14058
  return Object.keys(data);
@@ -13935,100 +14061,142 @@ const populate$2 = traverseFactory().intercept(isPopulateString, async (visitor2
13935
14061
  return data[key];
13936
14062
  }
13937
14063
  })).ignore(({ key, attribute }) => {
13938
- return ["sort", "filters", "fields"].includes(key) && !attribute;
14064
+ return [
14065
+ "sort",
14066
+ "filters",
14067
+ "fields"
14068
+ ].includes(key) && !attribute;
13939
14069
  }).on(
13940
14070
  // Handle recursion on populate."populate"
13941
14071
  isKeyword("populate"),
13942
- async ({ key, visitor: visitor2, path: path2, value, schema: schema2, getModel, attribute }, { set: set2, recurse }) => {
13943
- const parent = { key, path: path2, schema: schema2, attribute };
13944
- const newValue = await recurse(visitor2, { schema: schema2, path: path2, getModel, parent }, value);
14072
+ async ({ key, visitor, path: path2, value, schema: schema2, getModel, attribute }, { set: set2, recurse }) => {
14073
+ const parent = {
14074
+ key,
14075
+ path: path2,
14076
+ schema: schema2,
14077
+ attribute
14078
+ };
14079
+ const newValue = await recurse(visitor, {
14080
+ schema: schema2,
14081
+ path: path2,
14082
+ getModel,
14083
+ parent
14084
+ }, value);
13945
14085
  set2(key, newValue);
13946
14086
  }
13947
- ).on(
13948
- isKeyword("on"),
13949
- async ({ key, visitor: visitor2, path: path2, value, getModel, parent }, { set: set2, recurse }) => {
13950
- const newOn = {};
13951
- if (!isObj(value)) {
13952
- return;
13953
- }
13954
- for (const [uid, subPopulate] of Object.entries(value)) {
13955
- const model = getModel(uid);
13956
- const newPath = { ...path2, raw: `${path2.raw}[${uid}]` };
13957
- newOn[uid] = await recurse(
13958
- visitor2,
13959
- { schema: model, path: newPath, getModel, parent },
13960
- subPopulate
13961
- );
13962
- }
13963
- set2(key, newOn);
14087
+ ).on(isKeyword("on"), async ({ key, visitor, path: path2, value, getModel, parent }, { set: set2, recurse }) => {
14088
+ const newOn = {};
14089
+ if (!isObj(value)) {
14090
+ return;
13964
14091
  }
13965
- ).onRelation(
13966
- async ({ key, value, attribute, visitor: visitor2, path: path2, schema: schema2, getModel }, { set: set2, recurse }) => {
13967
- if (fp.isNil(value)) {
13968
- return;
13969
- }
13970
- const parent = { key, path: path2, schema: schema2, attribute };
13971
- if (isMorphToRelationalAttribute(attribute)) {
13972
- if (!fp.isObject(value) || !("on" in value && fp.isObject(value?.on))) {
13973
- return;
13974
- }
13975
- const newValue2 = await recurse(
13976
- visitor2,
13977
- { schema: schema2, path: path2, getModel, parent },
13978
- { on: value?.on }
13979
- );
13980
- set2(key, newValue2);
14092
+ for (const [uid, subPopulate] of Object.entries(value)) {
14093
+ const model = getModel(uid);
14094
+ const newPath = {
14095
+ ...path2,
14096
+ raw: `${path2.raw}[${uid}]`
14097
+ };
14098
+ newOn[uid] = await recurse(visitor, {
14099
+ schema: model,
14100
+ path: newPath,
14101
+ getModel,
14102
+ parent
14103
+ }, subPopulate);
14104
+ }
14105
+ set2(key, newOn);
14106
+ }).onRelation(async ({ key, value, attribute, visitor, path: path2, schema: schema2, getModel }, { set: set2, recurse }) => {
14107
+ if (fp.isNil(value)) {
14108
+ return;
14109
+ }
14110
+ const parent = {
14111
+ key,
14112
+ path: path2,
14113
+ schema: schema2,
14114
+ attribute
14115
+ };
14116
+ if (isMorphToRelationalAttribute(attribute)) {
14117
+ if (!fp.isObject(value) || !("on" in value && fp.isObject(value?.on))) {
13981
14118
  return;
13982
14119
  }
13983
- const targetSchemaUID = attribute.target;
13984
- const targetSchema = getModel(targetSchemaUID);
13985
- const newValue = await recurse(
13986
- visitor2,
13987
- { schema: targetSchema, path: path2, getModel, parent },
13988
- value
13989
- );
13990
- set2(key, newValue);
14120
+ const newValue2 = await recurse(visitor, {
14121
+ schema: schema2,
14122
+ path: path2,
14123
+ getModel,
14124
+ parent
14125
+ }, {
14126
+ on: value?.on
14127
+ });
14128
+ set2(key, newValue2);
14129
+ return;
13991
14130
  }
13992
- ).onMedia(async ({ key, path: path2, schema: schema2, attribute, visitor: visitor2, value, getModel }, { recurse, set: set2 }) => {
14131
+ const targetSchemaUID = attribute.target;
14132
+ const targetSchema = getModel(targetSchemaUID);
14133
+ const newValue = await recurse(visitor, {
14134
+ schema: targetSchema,
14135
+ path: path2,
14136
+ getModel,
14137
+ parent
14138
+ }, value);
14139
+ set2(key, newValue);
14140
+ }).onMedia(async ({ key, path: path2, schema: schema2, attribute, visitor, value, getModel }, { recurse, set: set2 }) => {
13993
14141
  if (fp.isNil(value)) {
13994
14142
  return;
13995
14143
  }
13996
- const parent = { key, path: path2, schema: schema2, attribute };
14144
+ const parent = {
14145
+ key,
14146
+ path: path2,
14147
+ schema: schema2,
14148
+ attribute
14149
+ };
13997
14150
  const targetSchemaUID = "plugin::upload.file";
13998
14151
  const targetSchema = getModel(targetSchemaUID);
13999
- const newValue = await recurse(
14000
- visitor2,
14001
- { schema: targetSchema, path: path2, getModel, parent },
14002
- value
14003
- );
14152
+ const newValue = await recurse(visitor, {
14153
+ schema: targetSchema,
14154
+ path: path2,
14155
+ getModel,
14156
+ parent
14157
+ }, value);
14004
14158
  set2(key, newValue);
14005
- }).onComponent(
14006
- async ({ key, value, schema: schema2, visitor: visitor2, path: path2, attribute, getModel }, { recurse, set: set2 }) => {
14007
- if (fp.isNil(value)) {
14008
- return;
14009
- }
14010
- const parent = { key, path: path2, schema: schema2, attribute };
14011
- const targetSchema = getModel(attribute.component);
14012
- const newValue = await recurse(
14013
- visitor2,
14014
- { schema: targetSchema, path: path2, getModel, parent },
14015
- value
14016
- );
14017
- set2(key, newValue);
14159
+ }).onComponent(async ({ key, value, schema: schema2, visitor, path: path2, attribute, getModel }, { recurse, set: set2 }) => {
14160
+ if (fp.isNil(value)) {
14161
+ return;
14018
14162
  }
14019
- ).onDynamicZone(
14020
- async ({ key, value, schema: schema2, visitor: visitor2, path: path2, attribute, getModel }, { set: set2, recurse }) => {
14021
- if (fp.isNil(value) || !fp.isObject(value)) {
14022
- return;
14023
- }
14024
- const parent = { key, path: path2, schema: schema2, attribute };
14025
- if ("on" in value && value.on) {
14026
- const newOn = await recurse(visitor2, { schema: schema2, path: path2, getModel, parent }, { on: value.on });
14027
- set2(key, newOn);
14028
- }
14163
+ const parent = {
14164
+ key,
14165
+ path: path2,
14166
+ schema: schema2,
14167
+ attribute
14168
+ };
14169
+ const targetSchema = getModel(attribute.component);
14170
+ const newValue = await recurse(visitor, {
14171
+ schema: targetSchema,
14172
+ path: path2,
14173
+ getModel,
14174
+ parent
14175
+ }, value);
14176
+ set2(key, newValue);
14177
+ }).onDynamicZone(async ({ key, value, schema: schema2, visitor, path: path2, attribute, getModel }, { set: set2, recurse }) => {
14178
+ if (fp.isNil(value) || !fp.isObject(value)) {
14179
+ return;
14029
14180
  }
14030
- );
14031
- const traverseQueryPopulate = fp.curry(populate$2.traverse);
14181
+ const parent = {
14182
+ key,
14183
+ path: path2,
14184
+ schema: schema2,
14185
+ attribute
14186
+ };
14187
+ if ("on" in value && value.on) {
14188
+ const newOn = await recurse(visitor, {
14189
+ schema: schema2,
14190
+ path: path2,
14191
+ getModel,
14192
+ parent
14193
+ }, {
14194
+ on: value.on
14195
+ });
14196
+ set2(key, newOn);
14197
+ }
14198
+ });
14199
+ var traverseQueryPopulate = fp.curry(populate$2.traverse);
14032
14200
  const objectPopulateToPaths = (input) => {
14033
14201
  const paths = [];
14034
14202
  function traverse(currentObj, parentPath) {
@@ -14047,14 +14215,16 @@ const objectPopulateToPaths = (input) => {
14047
14215
  const pathsToObjectPopulate = (input) => {
14048
14216
  const result = {};
14049
14217
  function traverse(object2, keys) {
14050
- const [first2, ...rest] = keys;
14218
+ const [first, ...rest] = keys;
14051
14219
  if (rest.length === 0) {
14052
- object2[first2] = true;
14220
+ object2[first] = true;
14053
14221
  } else {
14054
- if (!object2[first2] || typeof object2[first2] === "boolean") {
14055
- object2[first2] = { populate: {} };
14222
+ if (!object2[first] || typeof object2[first] === "boolean") {
14223
+ object2[first] = {
14224
+ populate: {}
14225
+ };
14056
14226
  }
14057
- traverse(object2[first2].populate, rest);
14227
+ traverse(object2[first].populate, rest);
14058
14228
  }
14059
14229
  }
14060
14230
  input.forEach((clause) => traverse(result, clause.split(".")));
@@ -14063,14 +14233,11 @@ const pathsToObjectPopulate = (input) => {
14063
14233
  const isStringArray = (value) => {
14064
14234
  return fp.isArray(value) && value.every(fp.isString);
14065
14235
  };
14066
- const fields = traverseFactory().intercept(isStringArray, async (visitor2, options, fields2, { recurse }) => {
14067
- return Promise.all(fields2.map((field) => recurse(visitor2, options, field)));
14068
- }).intercept(
14069
- (value) => fp.isString(value) && value.includes(","),
14070
- (visitor2, options, fields2, { recurse }) => {
14071
- return Promise.all(fields2.split(",").map((field) => recurse(visitor2, options, field)));
14072
- }
14073
- ).intercept((value) => fp.eq("*", value), fp.constant("*")).parse(fp.isString, () => ({
14236
+ const fields = traverseFactory().intercept(isStringArray, async (visitor, options, fields2, { recurse }) => {
14237
+ return Promise.all(fields2.map((field) => recurse(visitor, options, field)));
14238
+ }).intercept((value) => fp.isString(value) && value.includes(","), (visitor, options, fields2, { recurse }) => {
14239
+ return Promise.all(fields2.split(",").map((field) => recurse(visitor, options, field)));
14240
+ }).intercept((value) => fp.eq("*", value), fp.constant("*")).parse(fp.isString, () => ({
14074
14241
  transform: fp.trim,
14075
14242
  remove(key, data) {
14076
14243
  return data === key ? void 0 : data;
@@ -14079,13 +14246,15 @@ const fields = traverseFactory().intercept(isStringArray, async (visitor2, optio
14079
14246
  return data;
14080
14247
  },
14081
14248
  keys(data) {
14082
- return [data];
14249
+ return [
14250
+ data
14251
+ ];
14083
14252
  },
14084
14253
  get(key, data) {
14085
14254
  return key === data ? data : void 0;
14086
14255
  }
14087
14256
  }));
14088
- const traverseQueryFields = fp.curry(fields.traverse);
14257
+ var traverseQueryFields = fp.curry(fields.traverse);
14089
14258
  const { ID_ATTRIBUTE: ID_ATTRIBUTE$2, DOC_ID_ATTRIBUTE: DOC_ID_ATTRIBUTE$2 } = constants$1;
14090
14259
  const sanitizePasswords = (ctx) => async (entity) => {
14091
14260
  if (!ctx.schema) {
@@ -14097,14 +14266,10 @@ const defaultSanitizeOutput = async (ctx, entity) => {
14097
14266
  if (!ctx.schema) {
14098
14267
  throw new Error("Missing schema in defaultSanitizeOutput");
14099
14268
  }
14100
- return traverseEntity$1(
14101
- (...args) => {
14102
- visitor$8(...args);
14103
- visitor$7(...args);
14104
- },
14105
- ctx,
14106
- entity
14107
- );
14269
+ return traverseEntity$1((...args) => {
14270
+ visitor$8(...args);
14271
+ visitor$7(...args);
14272
+ }, ctx, entity);
14108
14273
  };
14109
14274
  const defaultSanitizeFilters = fp.curry((ctx, filters2) => {
14110
14275
  if (!ctx.schema) {
@@ -14112,13 +14277,16 @@ const defaultSanitizeFilters = fp.curry((ctx, filters2) => {
14112
14277
  }
14113
14278
  return pipe(
14114
14279
  // Remove keys that are not attributes or valid operators
14115
- traverseQueryFilters(({ key, attribute }, { remove: remove2 }) => {
14280
+ traverseQueryFilters(({ key, attribute }, { remove }) => {
14116
14281
  const isAttribute = !!attribute;
14117
- if ([ID_ATTRIBUTE$2, DOC_ID_ATTRIBUTE$2].includes(key)) {
14282
+ if ([
14283
+ ID_ATTRIBUTE$2,
14284
+ DOC_ID_ATTRIBUTE$2
14285
+ ].includes(key)) {
14118
14286
  return;
14119
14287
  }
14120
14288
  if (!isAttribute && !isOperator(key)) {
14121
- remove2(key);
14289
+ remove(key);
14122
14290
  }
14123
14291
  }, ctx),
14124
14292
  // Remove dynamic zones from filters
@@ -14130,9 +14298,9 @@ const defaultSanitizeFilters = fp.curry((ctx, filters2) => {
14130
14298
  // Remove private from filters
14131
14299
  traverseQueryFilters(visitor$7, ctx),
14132
14300
  // Remove empty objects
14133
- traverseQueryFilters(({ key, value }, { remove: remove2 }) => {
14301
+ traverseQueryFilters(({ key, value }, { remove }) => {
14134
14302
  if (fp.isObject(value) && fp.isEmpty(value)) {
14135
- remove2(key);
14303
+ remove(key);
14136
14304
  }
14137
14305
  }, ctx)
14138
14306
  )(filters2);
@@ -14143,12 +14311,15 @@ const defaultSanitizeSort = fp.curry((ctx, sort2) => {
14143
14311
  }
14144
14312
  return pipe(
14145
14313
  // Remove non attribute keys
14146
- traverseQuerySort(({ key, attribute }, { remove: remove2 }) => {
14147
- if ([ID_ATTRIBUTE$2, DOC_ID_ATTRIBUTE$2].includes(key)) {
14314
+ traverseQuerySort(({ key, attribute }, { remove }) => {
14315
+ if ([
14316
+ ID_ATTRIBUTE$2,
14317
+ DOC_ID_ATTRIBUTE$2
14318
+ ].includes(key)) {
14148
14319
  return;
14149
14320
  }
14150
14321
  if (!attribute) {
14151
- remove2(key);
14322
+ remove(key);
14152
14323
  }
14153
14324
  }, ctx),
14154
14325
  // Remove dynamic zones from sort
@@ -14160,12 +14331,15 @@ const defaultSanitizeSort = fp.curry((ctx, sort2) => {
14160
14331
  // Remove passwords from filters
14161
14332
  traverseQuerySort(visitor$8, ctx),
14162
14333
  // Remove keys for empty non-scalar values
14163
- traverseQuerySort(({ key, attribute, value }, { remove: remove2 }) => {
14164
- if ([ID_ATTRIBUTE$2, DOC_ID_ATTRIBUTE$2].includes(key)) {
14334
+ traverseQuerySort(({ key, attribute, value }, { remove }) => {
14335
+ if ([
14336
+ ID_ATTRIBUTE$2,
14337
+ DOC_ID_ATTRIBUTE$2
14338
+ ].includes(key)) {
14165
14339
  return;
14166
14340
  }
14167
14341
  if (!isScalarAttribute(attribute) && fp.isEmpty(value)) {
14168
- remove2(key);
14342
+ remove(key);
14169
14343
  }
14170
14344
  }, ctx)
14171
14345
  )(sort2);
@@ -14176,12 +14350,15 @@ const defaultSanitizeFields = fp.curry((ctx, fields2) => {
14176
14350
  }
14177
14351
  return pipe(
14178
14352
  // Only keep scalar attributes
14179
- traverseQueryFields(({ key, attribute }, { remove: remove2 }) => {
14180
- if ([ID_ATTRIBUTE$2, DOC_ID_ATTRIBUTE$2].includes(key)) {
14353
+ traverseQueryFields(({ key, attribute }, { remove }) => {
14354
+ if ([
14355
+ ID_ATTRIBUTE$2,
14356
+ DOC_ID_ATTRIBUTE$2
14357
+ ].includes(key)) {
14181
14358
  return;
14182
14359
  }
14183
14360
  if (fp.isNil(attribute) || !isScalarAttribute(attribute)) {
14184
- remove2(key);
14361
+ remove(key);
14185
14362
  }
14186
14363
  }, ctx),
14187
14364
  // Remove private fields
@@ -14202,25 +14379,46 @@ const defaultSanitizePopulate = fp.curry((ctx, populate2) => {
14202
14379
  if (attribute) {
14203
14380
  return;
14204
14381
  }
14205
- const parent = { key, path: path2, schema: schema2, attribute };
14382
+ const parent = {
14383
+ key,
14384
+ path: path2,
14385
+ schema: schema2,
14386
+ attribute
14387
+ };
14206
14388
  if (key === "sort") {
14207
- set2(key, await defaultSanitizeSort({ schema: schema2, getModel, parent }, value));
14389
+ set2(key, await defaultSanitizeSort({
14390
+ schema: schema2,
14391
+ getModel,
14392
+ parent
14393
+ }, value));
14208
14394
  }
14209
14395
  if (key === "filters") {
14210
- set2(key, await defaultSanitizeFilters({ schema: schema2, getModel, parent }, value));
14396
+ set2(key, await defaultSanitizeFilters({
14397
+ schema: schema2,
14398
+ getModel,
14399
+ parent
14400
+ }, value));
14211
14401
  }
14212
14402
  if (key === "fields") {
14213
- set2(key, await defaultSanitizeFields({ schema: schema2, getModel, parent }, value));
14403
+ set2(key, await defaultSanitizeFields({
14404
+ schema: schema2,
14405
+ getModel,
14406
+ parent
14407
+ }, value));
14214
14408
  }
14215
14409
  if (key === "populate") {
14216
- set2(key, await defaultSanitizePopulate({ schema: schema2, getModel, parent }, value));
14410
+ set2(key, await defaultSanitizePopulate({
14411
+ schema: schema2,
14412
+ getModel,
14413
+ parent
14414
+ }, value));
14217
14415
  }
14218
14416
  }, ctx),
14219
14417
  // Remove private fields
14220
14418
  traverseQueryPopulate(visitor$7, ctx)
14221
14419
  )(populate2);
14222
14420
  });
14223
- const sanitizers = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
14421
+ var sanitizers = /* @__PURE__ */ Object.freeze({
14224
14422
  __proto__: null,
14225
14423
  defaultSanitizeFields,
14226
14424
  defaultSanitizeFilters,
@@ -14228,7 +14426,7 @@ const sanitizers = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePr
14228
14426
  defaultSanitizePopulate,
14229
14427
  defaultSanitizeSort,
14230
14428
  sanitizePasswords
14231
- }, Symbol.toStringTag, { value: "Module" }));
14429
+ });
14232
14430
  const createAPISanitizers = (opts) => {
14233
14431
  const { getModel } = opts;
14234
14432
  const sanitizeInput = (data, schema2, { auth } = {}) => {
@@ -14236,7 +14434,9 @@ const createAPISanitizers = (opts) => {
14236
14434
  throw new Error("Missing schema in sanitizeInput");
14237
14435
  }
14238
14436
  if (fp.isArray(data)) {
14239
- return Promise.all(data.map((entry) => sanitizeInput(entry, schema2, { auth })));
14437
+ return Promise.all(data.map((entry) => sanitizeInput(entry, schema2, {
14438
+ auth
14439
+ })));
14240
14440
  }
14241
14441
  const nonWritableAttributes = getNonWritableAttributes(schema2);
14242
14442
  const transforms = [
@@ -14244,12 +14444,16 @@ const createAPISanitizers = (opts) => {
14244
14444
  fp.omit(constants$1.ID_ATTRIBUTE),
14245
14445
  fp.omit(constants$1.DOC_ID_ATTRIBUTE),
14246
14446
  // Remove non-writable attributes
14247
- traverseEntity$1(removeRestrictedFields(nonWritableAttributes), { schema: schema2, getModel })
14447
+ traverseEntity$1(removeRestrictedFields(nonWritableAttributes), {
14448
+ schema: schema2,
14449
+ getModel
14450
+ })
14248
14451
  ];
14249
14452
  if (auth) {
14250
- transforms.push(
14251
- traverseEntity$1(removeRestrictedRelations(auth), { schema: schema2, getModel })
14252
- );
14453
+ transforms.push(traverseEntity$1(removeRestrictedRelations(auth), {
14454
+ schema: schema2,
14455
+ getModel
14456
+ }));
14253
14457
  }
14254
14458
  opts?.sanitizers?.input?.forEach((sanitizer) => transforms.push(sanitizer(schema2)));
14255
14459
  return pipe(...transforms)(data);
@@ -14261,17 +14465,23 @@ const createAPISanitizers = (opts) => {
14261
14465
  if (fp.isArray(data)) {
14262
14466
  const res = new Array(data.length);
14263
14467
  for (let i = 0; i < data.length; i += 1) {
14264
- res[i] = await sanitizeOutput(data[i], schema2, { auth });
14468
+ res[i] = await sanitizeOutput(data[i], schema2, {
14469
+ auth
14470
+ });
14265
14471
  }
14266
14472
  return res;
14267
14473
  }
14268
14474
  const transforms = [
14269
- (data2) => defaultSanitizeOutput({ schema: schema2, getModel }, data2)
14475
+ (data2) => defaultSanitizeOutput({
14476
+ schema: schema2,
14477
+ getModel
14478
+ }, data2)
14270
14479
  ];
14271
14480
  if (auth) {
14272
- transforms.push(
14273
- traverseEntity$1(removeRestrictedRelations(auth), { schema: schema2, getModel })
14274
- );
14481
+ transforms.push(traverseEntity$1(removeRestrictedRelations(auth), {
14482
+ schema: schema2,
14483
+ getModel
14484
+ }));
14275
14485
  }
14276
14486
  opts?.sanitizers?.output?.forEach((sanitizer) => transforms.push(sanitizer(schema2)));
14277
14487
  return pipe(...transforms)(data);
@@ -14283,16 +14493,28 @@ const createAPISanitizers = (opts) => {
14283
14493
  const { filters: filters2, sort: sort2, fields: fields2, populate: populate2 } = query;
14284
14494
  const sanitizedQuery = fp.cloneDeep(query);
14285
14495
  if (filters2) {
14286
- Object.assign(sanitizedQuery, { filters: await sanitizeFilters(filters2, schema2, { auth }) });
14496
+ Object.assign(sanitizedQuery, {
14497
+ filters: await sanitizeFilters(filters2, schema2, {
14498
+ auth
14499
+ })
14500
+ });
14287
14501
  }
14288
14502
  if (sort2) {
14289
- Object.assign(sanitizedQuery, { sort: await sanitizeSort(sort2, schema2, { auth }) });
14503
+ Object.assign(sanitizedQuery, {
14504
+ sort: await sanitizeSort(sort2, schema2, {
14505
+ auth
14506
+ })
14507
+ });
14290
14508
  }
14291
14509
  if (fields2) {
14292
- Object.assign(sanitizedQuery, { fields: await sanitizeFields(fields2, schema2) });
14510
+ Object.assign(sanitizedQuery, {
14511
+ fields: await sanitizeFields(fields2, schema2)
14512
+ });
14293
14513
  }
14294
14514
  if (populate2) {
14295
- Object.assign(sanitizedQuery, { populate: await sanitizePopulate(populate2, schema2) });
14515
+ Object.assign(sanitizedQuery, {
14516
+ populate: await sanitizePopulate(populate2, schema2)
14517
+ });
14296
14518
  }
14297
14519
  return sanitizedQuery;
14298
14520
  };
@@ -14301,13 +14523,21 @@ const createAPISanitizers = (opts) => {
14301
14523
  throw new Error("Missing schema in sanitizeFilters");
14302
14524
  }
14303
14525
  if (fp.isArray(filters2)) {
14304
- return Promise.all(filters2.map((filter) => sanitizeFilters(filter, schema2, { auth })));
14526
+ return Promise.all(filters2.map((filter) => sanitizeFilters(filter, schema2, {
14527
+ auth
14528
+ })));
14305
14529
  }
14306
- const transforms = [defaultSanitizeFilters({ schema: schema2, getModel })];
14530
+ const transforms = [
14531
+ defaultSanitizeFilters({
14532
+ schema: schema2,
14533
+ getModel
14534
+ })
14535
+ ];
14307
14536
  if (auth) {
14308
- transforms.push(
14309
- traverseQueryFilters(removeRestrictedRelations(auth), { schema: schema2, getModel })
14310
- );
14537
+ transforms.push(traverseQueryFilters(removeRestrictedRelations(auth), {
14538
+ schema: schema2,
14539
+ getModel
14540
+ }));
14311
14541
  }
14312
14542
  return pipe(...transforms)(filters2);
14313
14543
  };
@@ -14315,11 +14545,17 @@ const createAPISanitizers = (opts) => {
14315
14545
  if (!schema2) {
14316
14546
  throw new Error("Missing schema in sanitizeSort");
14317
14547
  }
14318
- const transforms = [defaultSanitizeSort({ schema: schema2, getModel })];
14548
+ const transforms = [
14549
+ defaultSanitizeSort({
14550
+ schema: schema2,
14551
+ getModel
14552
+ })
14553
+ ];
14319
14554
  if (auth) {
14320
- transforms.push(
14321
- traverseQuerySort(removeRestrictedRelations(auth), { schema: schema2, getModel })
14322
- );
14555
+ transforms.push(traverseQuerySort(removeRestrictedRelations(auth), {
14556
+ schema: schema2,
14557
+ getModel
14558
+ }));
14323
14559
  }
14324
14560
  return pipe(...transforms)(sort2);
14325
14561
  };
@@ -14327,18 +14563,29 @@ const createAPISanitizers = (opts) => {
14327
14563
  if (!schema2) {
14328
14564
  throw new Error("Missing schema in sanitizeFields");
14329
14565
  }
14330
- const transforms = [defaultSanitizeFields({ schema: schema2, getModel })];
14566
+ const transforms = [
14567
+ defaultSanitizeFields({
14568
+ schema: schema2,
14569
+ getModel
14570
+ })
14571
+ ];
14331
14572
  return pipe(...transforms)(fields2);
14332
14573
  };
14333
14574
  const sanitizePopulate = (populate2, schema2, { auth } = {}) => {
14334
14575
  if (!schema2) {
14335
14576
  throw new Error("Missing schema in sanitizePopulate");
14336
14577
  }
14337
- const transforms = [defaultSanitizePopulate({ schema: schema2, getModel })];
14578
+ const transforms = [
14579
+ defaultSanitizePopulate({
14580
+ schema: schema2,
14581
+ getModel
14582
+ })
14583
+ ];
14338
14584
  if (auth) {
14339
- transforms.push(
14340
- traverseQueryPopulate(removeRestrictedRelations(auth), { schema: schema2, getModel })
14341
- );
14585
+ transforms.push(traverseQueryPopulate(removeRestrictedRelations(auth), {
14586
+ schema: schema2,
14587
+ getModel
14588
+ }));
14342
14589
  }
14343
14590
  return pipe(...transforms)(populate2);
14344
14591
  };
@@ -14352,13 +14599,16 @@ const createAPISanitizers = (opts) => {
14352
14599
  populate: sanitizePopulate
14353
14600
  };
14354
14601
  };
14355
- const index$2 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
14602
+ var index$2 = /* @__PURE__ */ Object.freeze({
14356
14603
  __proto__: null,
14357
14604
  createAPISanitizers,
14358
14605
  sanitizers,
14359
14606
  visitors: index$4
14360
- }, Symbol.toStringTag, { value: "Module" }));
14361
- [constants$1.DOC_ID_ATTRIBUTE, constants$1.DOC_ID_ATTRIBUTE];
14607
+ });
14608
+ [
14609
+ constants$1.DOC_ID_ATTRIBUTE,
14610
+ constants$1.DOC_ID_ATTRIBUTE
14611
+ ];
14362
14612
  const isCamelCase = (value) => /^[a-z][a-zA-Z0-9]+$/.test(value);
14363
14613
  const isKebabCase = (value) => /^([a-z][a-z0-9]*)(-[a-z0-9]+)*$/.test(value);
14364
14614
  const { toString: toString3 } = Object.prototype;
@@ -14389,15 +14639,11 @@ function printSimpleValue(val, quoteStrings = false) {
14389
14639
  function printValue(value, quoteStrings) {
14390
14640
  const result = printSimpleValue(value, quoteStrings);
14391
14641
  if (result !== null) return result;
14392
- return JSON.stringify(
14393
- value,
14394
- function replacer(key, value2) {
14395
- const result2 = printSimpleValue(this[key], quoteStrings);
14396
- if (result2 !== null) return result2;
14397
- return value2;
14398
- },
14399
- 2
14400
- );
14642
+ return JSON.stringify(value, function replacer(key, value2) {
14643
+ const result2 = printSimpleValue(this[key], quoteStrings);
14644
+ if (result2 !== null) return result2;
14645
+ return value2;
14646
+ }, 2);
14401
14647
  }
14402
14648
  const isNotNilTest = (value) => !___default__default.default.isNil(value);
14403
14649
  const isNotNullTest = (value) => !___default__default.default.isNull(value);
@@ -14408,71 +14654,35 @@ addMethod(create$3, "notNull", function isNotNull(msg = "${path} cannot be null.
14408
14654
  return this.test("defined", msg, isNotNullTest);
14409
14655
  });
14410
14656
  addMethod(create$3, "isFunction", function isFunction2(message = "${path} is not a function") {
14411
- return this.test(
14412
- "is a function",
14413
- message,
14414
- (value) => ___default__default.default.isUndefined(value) || ___default__default.default.isFunction(value)
14415
- );
14657
+ return this.test("is a function", message, (value) => ___default__default.default.isUndefined(value) || ___default__default.default.isFunction(value));
14416
14658
  });
14417
- addMethod(
14418
- create$2,
14419
- "isCamelCase",
14420
- function isCamelCase$1(message = "${path} is not in camel case (anExampleOfCamelCase)") {
14421
- return this.test(
14422
- "is in camelCase",
14423
- message,
14424
- (value) => value ? isCamelCase(value) : true
14425
- );
14426
- }
14427
- );
14428
- addMethod(
14429
- create$2,
14430
- "isKebabCase",
14431
- function isKebabCase$1(message = "${path} is not in kebab case (an-example-of-kebab-case)") {
14432
- return this.test(
14433
- "is in kebab-case",
14434
- message,
14435
- (value) => value ? isKebabCase(value) : true
14436
- );
14437
- }
14438
- );
14439
- addMethod(
14440
- create$1,
14441
- "onlyContainsFunctions",
14442
- function onlyContainsFunctions(message = "${path} contains values that are not functions") {
14443
- return this.test(
14444
- "only contains functions",
14445
- message,
14446
- (value) => ___default__default.default.isUndefined(value) || value && Object.values(value).every(___default__default.default.isFunction)
14447
- );
14448
- }
14449
- );
14450
- addMethod(
14451
- create,
14452
- "uniqueProperty",
14453
- function uniqueProperty(propertyName, message) {
14454
- return this.test("unique", message, function unique(list) {
14455
- const errors2 = [];
14456
- list?.forEach((element, index2) => {
14457
- const sameElements = list.filter(
14458
- (e) => fp.get(propertyName, e) === fp.get(propertyName, element)
14459
- );
14460
- if (sameElements.length > 1) {
14461
- errors2.push(
14462
- this.createError({
14463
- path: `${this.path}[${index2}].${propertyName}`,
14464
- message
14465
- })
14466
- );
14467
- }
14468
- });
14469
- if (errors2.length) {
14470
- throw new ValidationError(errors2);
14659
+ addMethod(create$2, "isCamelCase", function isCamelCase$1(message = "${path} is not in camel case (anExampleOfCamelCase)") {
14660
+ return this.test("is in camelCase", message, (value) => value ? isCamelCase(value) : true);
14661
+ });
14662
+ addMethod(create$2, "isKebabCase", function isKebabCase$1(message = "${path} is not in kebab case (an-example-of-kebab-case)") {
14663
+ return this.test("is in kebab-case", message, (value) => value ? isKebabCase(value) : true);
14664
+ });
14665
+ addMethod(create$1, "onlyContainsFunctions", function onlyContainsFunctions(message = "${path} contains values that are not functions") {
14666
+ return this.test("only contains functions", message, (value) => ___default__default.default.isUndefined(value) || value && Object.values(value).every(___default__default.default.isFunction));
14667
+ });
14668
+ addMethod(create, "uniqueProperty", function uniqueProperty(propertyName, message) {
14669
+ return this.test("unique", message, function unique(list) {
14670
+ const errors = [];
14671
+ list?.forEach((element, index2) => {
14672
+ const sameElements = list.filter((e) => fp.get(propertyName, e) === fp.get(propertyName, element));
14673
+ if (sameElements.length > 1) {
14674
+ errors.push(this.createError({
14675
+ path: `${this.path}[${index2}].${propertyName}`,
14676
+ message
14677
+ }));
14471
14678
  }
14472
- return true;
14473
14679
  });
14474
- }
14475
- );
14680
+ if (errors.length) {
14681
+ throw new ValidationError(errors);
14682
+ }
14683
+ return true;
14684
+ });
14685
+ });
14476
14686
  setLocale({
14477
14687
  mixed: {
14478
14688
  notType(options) {
@@ -14545,6 +14755,7 @@ const populateIsWildcardEquivalent = async ({
14545
14755
  schema: schema2,
14546
14756
  populate: populate2
14547
14757
  }) => {
14758
+ if (isEmpty__default.default(populate2)) return false;
14548
14759
  const expandedWildcardQuery = await index$2.sanitizers.defaultSanitizePopulate(
14549
14760
  {
14550
14761
  schema: schema2,
@@ -14578,6 +14789,7 @@ const register = async ({ strapi: strapi2 }) => {
14578
14789
  const cacheService = strapi2.plugin("deep-populate").service("cache");
14579
14790
  const { populate: populate2 } = context.params;
14580
14791
  const returnDeeplyPopulated = replaceWildcard && await populateIsWildcardEquivalent({ strapi: strapi2, schema: context.contentType, populate: populate2 });
14792
+ if (has__default.default(populate2, "__deepPopulated")) unset__default.default(populate2, "__deepPopulated");
14581
14793
  if (useCache && context.action === "delete")
14582
14794
  await cacheService.clear({ ...context.params, contentType: context.uid });
14583
14795
  const originalFields = cloneDeep__default.default(context.fields);
@@ -14586,7 +14798,8 @@ const register = async ({ strapi: strapi2 }) => {
14586
14798
  const result = await next();
14587
14799
  if (!result) return result;
14588
14800
  if (["create", "update"].includes(context.action)) {
14589
- const { documentId, status: status2, locale: locale2 } = result;
14801
+ const { documentId, publishedAt, locale: locale2 } = result;
14802
+ const status2 = publishedAt !== null ? "published" : "draft";
14590
14803
  if (useCache && context.action === "update")
14591
14804
  await cacheService.clear({ ...context.params, contentType: context.uid });
14592
14805
  if (useCache || returnDeeplyPopulated) {
@@ -14596,13 +14809,15 @@ const register = async ({ strapi: strapi2 }) => {
14596
14809
  }
14597
14810
  }
14598
14811
  if (returnDeeplyPopulated && ["findOne", "findFirst"].includes(context.action)) {
14599
- const { documentId, status: status2, locale: locale2 } = result;
14812
+ const { documentId, publishedAt, locale: locale2 } = result;
14813
+ const status2 = publishedAt !== null ? "published" : "draft";
14600
14814
  const deepPopulate = await populateService.get({ contentType: context.uid, documentId, status: status2, locale: locale2 });
14601
14815
  return await strapi2.documents(context.uid).findOne({ documentId, status: status2, locale: locale2, fields: originalFields, populate: deepPopulate });
14602
14816
  }
14603
14817
  if (returnDeeplyPopulated && context.action === "findMany") {
14604
14818
  return await Promise.all(
14605
- result.map(async ({ documentId, status: status2, locale: locale2 }) => {
14819
+ result.map(async ({ documentId, publishedAt, locale: locale2 }) => {
14820
+ const status2 = publishedAt !== null ? "published" : "draft";
14606
14821
  const deepPopulate = await populateService.get({ contentType: context.uid, documentId, status: status2, locale: locale2 });
14607
14822
  return await strapi2.documents(context.uid).findOne({ documentId, status: status2, locale: locale2, fields: originalFields, populate: deepPopulate });
14608
14823
  })
@@ -14614,10 +14829,13 @@ const register = async ({ strapi: strapi2 }) => {
14614
14829
  const getHash = (params) => {
14615
14830
  return `${params.contentType}-${params.documentId}-${params.locale}-${params.status}-${params.omitEmpty ? "sparse" : "full"}-${params.localizations ? "all" : "single"}`;
14616
14831
  };
14832
+ const isValid = (entry) => {
14833
+ return entry && !isEmpty__default.default(entry.populate) && has__default.default(entry.populate, "__deepPopulated");
14834
+ };
14617
14835
  const cache = ({ strapi: strapi2 }) => ({
14618
14836
  async get(params) {
14619
14837
  const entry = await strapi2.documents("plugin::deep-populate.cache").findFirst({ filters: { hash: { $eq: getHash(params) } } });
14620
- return entry ? entry.populate : null;
14838
+ return isValid(entry) ? entry.populate : null;
14621
14839
  },
14622
14840
  async set({ populate: populate2, dependencies, ...params }) {
14623
14841
  const documentService = strapi2.documents("plugin::deep-populate.cache");
@@ -14656,6 +14874,11 @@ const cache = ({ strapi: strapi2 }) => ({
14656
14874
  const getRelations = (model) => {
14657
14875
  const filteredAttributes = /* @__PURE__ */ new Set();
14658
14876
  const { populateCreatorFields } = contentTypes.getOptions(model);
14877
+ const { pluginOptions } = model;
14878
+ if (pluginOptions?.i18n?.localized !== true) {
14879
+ filteredAttributes.add("locale");
14880
+ filteredAttributes.add("localizations");
14881
+ }
14659
14882
  if (!populateCreatorFields) {
14660
14883
  filteredAttributes.add(contentTypes.constants.CREATED_BY_ATTRIBUTE);
14661
14884
  filteredAttributes.add(contentTypes.constants.UPDATED_BY_ATTRIBUTE);
@@ -14911,6 +15134,7 @@ async function populate$1(params) {
14911
15134
  __deny: deny,
14912
15135
  __allow: allow
14913
15136
  });
15137
+ populated.__deepPopulated = true;
14914
15138
  return { populate: populated, dependencies: [...resolvedRelations.keys()] };
14915
15139
  }
14916
15140
  const populate = ({ strapi: strapi2 }) => ({