@fourlights/strapi-plugin-deep-populate 1.5.1 → 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.
@@ -20,6 +20,7 @@ import require$$2$1 from "util";
20
20
  import require$$0$8 from "constants";
21
21
  import "node:stream";
22
22
  import cloneDeep$1 from "lodash/cloneDeep";
23
+ import unset from "lodash/unset";
23
24
  import get$1 from "lodash/get";
24
25
  import mergeWith from "lodash/mergeWith";
25
26
  import set$2 from "lodash/set";
@@ -12916,12 +12917,12 @@ const utils = {
12916
12917
  return new Date(getKey(key));
12917
12918
  },
12918
12919
  /**
12919
- * Gets a value from env that matches oneOf provided values
12920
- * @param {string} key
12921
- * @param {string[]} expectedValues
12922
- * @param {string|undefined} defaultValue
12923
- * @returns {string|undefined}
12924
- */
12920
+ * Gets a value from env that matches oneOf provided values
12921
+ * @param {string} key
12922
+ * @param {string[]} expectedValues
12923
+ * @param {string|undefined} defaultValue
12924
+ * @returns {string|undefined}
12925
+ */
12925
12926
  oneOf(key, expectedValues, defaultValue) {
12926
12927
  if (!expectedValues) {
12927
12928
  throw new Error(`env.oneOf requires expectedValues`);
@@ -12976,11 +12977,7 @@ const getCreatorFields = (model) => {
12976
12977
  };
12977
12978
  const getNonWritableAttributes = (model) => {
12978
12979
  if (!model) return [];
12979
- const nonWritableAttributes = ___default.reduce(
12980
- model.attributes,
12981
- (acc, attr, attrName) => attr.writable === false ? acc.concat(attrName) : acc,
12982
- []
12983
- );
12980
+ const nonWritableAttributes = ___default.reduce(model.attributes, (acc, attr, attrName) => attr.writable === false ? acc.concat(attrName) : acc, []);
12984
12981
  return ___default.uniq([
12985
12982
  ID_ATTRIBUTE$4,
12986
12983
  DOC_ID_ATTRIBUTE$4,
@@ -12996,12 +12993,13 @@ const isWritableAttribute = (model, attributeName) => {
12996
12993
  return getWritableAttributes(model).includes(attributeName);
12997
12994
  };
12998
12995
  const getNonVisibleAttributes = (model) => {
12999
- const nonVisibleAttributes = ___default.reduce(
13000
- model.attributes,
13001
- (acc, attr, attrName) => attr.visible === false ? acc.concat(attrName) : acc,
13002
- []
13003
- );
13004
- return ___default.uniq([ID_ATTRIBUTE$4, DOC_ID_ATTRIBUTE$4, ...getTimestamps(model), ...nonVisibleAttributes]);
12996
+ const nonVisibleAttributes = ___default.reduce(model.attributes, (acc, attr, attrName) => attr.visible === false ? acc.concat(attrName) : acc, []);
12997
+ return ___default.uniq([
12998
+ ID_ATTRIBUTE$4,
12999
+ DOC_ID_ATTRIBUTE$4,
13000
+ ...getTimestamps(model),
13001
+ ...nonVisibleAttributes
13002
+ ]);
13005
13003
  };
13006
13004
  const getVisibleAttributes = (model) => {
13007
13005
  return ___default.difference(___default.keys(model.attributes), getNonVisibleAttributes(model));
@@ -13009,11 +13007,16 @@ const getVisibleAttributes = (model) => {
13009
13007
  const isVisibleAttribute = (model, attributeName) => {
13010
13008
  return getVisibleAttributes(model).includes(attributeName);
13011
13009
  };
13012
- const getOptions = (model) => ___default.assign({ draftAndPublish: false }, ___default.get(model, "options", {}));
13010
+ const getOptions = (model) => ___default.assign({
13011
+ draftAndPublish: false
13012
+ }, ___default.get(model, "options", {}));
13013
13013
  const hasDraftAndPublish = (model) => ___default.get(model, "options.draftAndPublish", false) === true;
13014
13014
  const isDraft = (data, model) => hasDraftAndPublish(model) && ___default.get(data, PUBLISHED_AT_ATTRIBUTE$1) === null;
13015
13015
  const isSchema = (data) => {
13016
- return typeof data === "object" && data !== null && "modelType" in data && typeof data.modelType === "string" && ["component", "contentType"].includes(data.modelType);
13016
+ return typeof data === "object" && data !== null && "modelType" in data && typeof data.modelType === "string" && [
13017
+ "component",
13018
+ "contentType"
13019
+ ].includes(data.modelType);
13017
13020
  };
13018
13021
  const isComponentSchema = (data) => {
13019
13022
  return isSchema(data) && data.modelType === "component";
@@ -13024,15 +13027,9 @@ const isContentTypeSchema = (data) => {
13024
13027
  const isSingleType = ({ kind = COLLECTION_TYPE }) => kind === SINGLE_TYPE;
13025
13028
  const isCollectionType = ({ kind = COLLECTION_TYPE }) => kind === COLLECTION_TYPE;
13026
13029
  const isKind = (kind) => (model) => model.kind === kind;
13027
- const getStoredPrivateAttributes = (model) => union(
13028
- strapi?.config?.get("api.responses.privateAttributes", []) ?? [],
13029
- getOr([], "options.privateAttributes", model)
13030
- );
13030
+ const getStoredPrivateAttributes = (model) => union(strapi?.config?.get("api.responses.privateAttributes", []) ?? [], getOr([], "options.privateAttributes", model));
13031
13031
  const getPrivateAttributes = (model) => {
13032
- return ___default.union(
13033
- getStoredPrivateAttributes(model),
13034
- ___default.keys(___default.pickBy(model.attributes, (attr) => !!attr.private))
13035
- );
13032
+ return ___default.union(getStoredPrivateAttributes(model), ___default.keys(___default.pickBy(model.attributes, (attr) => !!attr.private)));
13036
13033
  };
13037
13034
  const isPrivateAttribute = (model, attributeName) => {
13038
13035
  if (model?.attributes?.[attributeName]?.private === true) {
@@ -13041,49 +13038,49 @@ const isPrivateAttribute = (model, attributeName) => {
13041
13038
  return getStoredPrivateAttributes(model).includes(attributeName);
13042
13039
  };
13043
13040
  const isScalarAttribute = (attribute) => {
13044
- return attribute && !["media", "component", "relation", "dynamiczone"].includes(attribute.type);
13041
+ return attribute && ![
13042
+ "media",
13043
+ "component",
13044
+ "relation",
13045
+ "dynamiczone"
13046
+ ].includes(attribute.type);
13045
13047
  };
13046
13048
  const getDoesAttributeRequireValidation = (attribute) => {
13047
13049
  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");
13048
13050
  };
13049
13051
  const isMediaAttribute = (attribute) => attribute?.type === "media";
13050
13052
  const isRelationalAttribute = (attribute) => attribute?.type === "relation";
13051
- const HAS_RELATION_REORDERING = ["manyToMany", "manyToOne", "oneToMany"];
13053
+ const HAS_RELATION_REORDERING = [
13054
+ "manyToMany",
13055
+ "manyToOne",
13056
+ "oneToMany"
13057
+ ];
13052
13058
  const hasRelationReordering = (attribute) => isRelationalAttribute(attribute) && HAS_RELATION_REORDERING.includes(attribute.relation);
13053
- const isComponentAttribute = (attribute) => ["component", "dynamiczone"].includes(attribute?.type);
13059
+ const isComponentAttribute = (attribute) => [
13060
+ "component",
13061
+ "dynamiczone"
13062
+ ].includes(attribute?.type);
13054
13063
  const isDynamicZoneAttribute = (attribute) => !!attribute && attribute.type === "dynamiczone";
13055
13064
  const isMorphToRelationalAttribute = (attribute) => {
13056
13065
  return !!attribute && isRelationalAttribute(attribute) && attribute.relation?.startsWith?.("morphTo");
13057
13066
  };
13058
13067
  const getComponentAttributes = (schema2) => {
13059
- return ___default.reduce(
13060
- schema2.attributes,
13061
- (acc, attr, attrName) => {
13062
- if (isComponentAttribute(attr)) acc.push(attrName);
13063
- return acc;
13064
- },
13065
- []
13066
- );
13068
+ return ___default.reduce(schema2.attributes, (acc, attr, attrName) => {
13069
+ if (isComponentAttribute(attr)) acc.push(attrName);
13070
+ return acc;
13071
+ }, []);
13067
13072
  };
13068
13073
  const getScalarAttributes = (schema2) => {
13069
- return ___default.reduce(
13070
- schema2.attributes,
13071
- (acc, attr, attrName) => {
13072
- if (isScalarAttribute(attr)) acc.push(attrName);
13073
- return acc;
13074
- },
13075
- []
13076
- );
13074
+ return ___default.reduce(schema2.attributes, (acc, attr, attrName) => {
13075
+ if (isScalarAttribute(attr)) acc.push(attrName);
13076
+ return acc;
13077
+ }, []);
13077
13078
  };
13078
13079
  const getRelationalAttributes = (schema2) => {
13079
- return ___default.reduce(
13080
- schema2.attributes,
13081
- (acc, attr, attrName) => {
13082
- if (isRelationalAttribute(attr)) acc.push(attrName);
13083
- return acc;
13084
- },
13085
- []
13086
- );
13080
+ return ___default.reduce(schema2.attributes, (acc, attr, attrName) => {
13081
+ if (isRelationalAttribute(attr)) acc.push(attrName);
13082
+ return acc;
13083
+ }, []);
13087
13084
  };
13088
13085
  const isTypedAttribute = (attribute, type2) => {
13089
13086
  return ___default.has(attribute, "type") && attribute.type === type2;
@@ -13091,7 +13088,7 @@ const isTypedAttribute = (attribute, type2) => {
13091
13088
  const getContentTypeRoutePrefix = (contentType) => {
13092
13089
  return isSingleType(contentType) ? ___default.kebabCase(contentType.info.singularName) : ___default.kebabCase(contentType.info.pluralName);
13093
13090
  };
13094
- const contentTypes = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
13091
+ var contentTypes = /* @__PURE__ */ Object.freeze({
13095
13092
  __proto__: null,
13096
13093
  constants: constants$1,
13097
13094
  getComponentAttributes,
@@ -13126,44 +13123,76 @@ const contentTypes = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.define
13126
13123
  isTypedAttribute,
13127
13124
  isVisibleAttribute,
13128
13125
  isWritableAttribute
13129
- }, Symbol.toStringTag, { value: "Module" }));
13130
- const traverseEntity = async (visitor2, options, entity) => {
13131
- const { path: path2 = { raw: null, attribute: null }, schema: schema2, getModel } = options;
13126
+ });
13127
+ const traverseEntity = async (visitor, options, entity) => {
13128
+ const { path: path2 = {
13129
+ raw: null,
13130
+ attribute: null
13131
+ }, schema: schema2, getModel } = options;
13132
13132
  let parent = options.parent;
13133
- const traverseMorphRelationTarget = async (visitor22, path22, entry) => {
13133
+ const traverseMorphRelationTarget = async (visitor2, path3, entry) => {
13134
13134
  const targetSchema = getModel(entry.__type);
13135
- const traverseOptions = { schema: targetSchema, path: path22, getModel, parent };
13136
- return traverseEntity(visitor22, traverseOptions, entry);
13135
+ const traverseOptions = {
13136
+ schema: targetSchema,
13137
+ path: path3,
13138
+ getModel,
13139
+ parent
13140
+ };
13141
+ return traverseEntity(visitor2, traverseOptions, entry);
13137
13142
  };
13138
- const traverseRelationTarget = (schema22) => async (visitor22, path22, entry) => {
13139
- const traverseOptions = { schema: schema22, path: path22, getModel, parent };
13140
- return traverseEntity(visitor22, traverseOptions, entry);
13143
+ const traverseRelationTarget = (schema3) => async (visitor2, path3, entry) => {
13144
+ const traverseOptions = {
13145
+ schema: schema3,
13146
+ path: path3,
13147
+ getModel,
13148
+ parent
13149
+ };
13150
+ return traverseEntity(visitor2, traverseOptions, entry);
13141
13151
  };
13142
- const traverseMediaTarget = async (visitor22, path22, entry) => {
13152
+ const traverseMediaTarget = async (visitor2, path3, entry) => {
13143
13153
  const targetSchemaUID = "plugin::upload.file";
13144
13154
  const targetSchema = getModel(targetSchemaUID);
13145
- const traverseOptions = { schema: targetSchema, path: path22, getModel, parent };
13146
- return traverseEntity(visitor22, traverseOptions, entry);
13155
+ const traverseOptions = {
13156
+ schema: targetSchema,
13157
+ path: path3,
13158
+ getModel,
13159
+ parent
13160
+ };
13161
+ return traverseEntity(visitor2, traverseOptions, entry);
13147
13162
  };
13148
- const traverseComponent = async (visitor22, path22, schema22, entry) => {
13149
- const traverseOptions = { schema: schema22, path: path22, getModel, parent };
13150
- return traverseEntity(visitor22, traverseOptions, entry);
13163
+ const traverseComponent = async (visitor2, path3, schema3, entry) => {
13164
+ const traverseOptions = {
13165
+ schema: schema3,
13166
+ path: path3,
13167
+ getModel,
13168
+ parent
13169
+ };
13170
+ return traverseEntity(visitor2, traverseOptions, entry);
13151
13171
  };
13152
- const visitDynamicZoneEntry = async (visitor22, path22, entry) => {
13172
+ const visitDynamicZoneEntry = async (visitor2, path3, entry) => {
13153
13173
  const targetSchema = getModel(entry.__component);
13154
- const traverseOptions = { schema: targetSchema, path: path22, getModel, parent };
13155
- return traverseEntity(visitor22, traverseOptions, entry);
13174
+ const traverseOptions = {
13175
+ schema: targetSchema,
13176
+ path: path3,
13177
+ getModel,
13178
+ parent
13179
+ };
13180
+ return traverseEntity(visitor2, traverseOptions, entry);
13156
13181
  };
13157
13182
  if (!isObject$5(entity) || isNil(schema2)) {
13158
13183
  return entity;
13159
13184
  }
13160
13185
  const copy = clone$3(entity);
13161
- const visitorUtils = createVisitorUtils({ data: copy });
13186
+ const visitorUtils = createVisitorUtils({
13187
+ data: copy
13188
+ });
13162
13189
  const keys = Object.keys(copy);
13163
13190
  for (let i = 0; i < keys.length; i += 1) {
13164
13191
  const key = keys[i];
13165
13192
  const attribute = schema2.attributes[key];
13166
- const newPath = { ...path2 };
13193
+ const newPath = {
13194
+ ...path2
13195
+ };
13167
13196
  newPath.raw = isNil(path2.raw) ? key : `${path2.raw}.${key}`;
13168
13197
  if (!isNil(attribute)) {
13169
13198
  newPath.attribute = isNil(path2.attribute) ? key : `${path2.attribute}.${key}`;
@@ -13178,23 +13207,28 @@ const traverseEntity = async (visitor2, options, entity) => {
13178
13207
  getModel,
13179
13208
  parent
13180
13209
  };
13181
- await visitor2(visitorOptions, visitorUtils);
13210
+ await visitor(visitorOptions, visitorUtils);
13182
13211
  const value = copy[key];
13183
13212
  if (isNil(value) || isNil(attribute)) {
13184
13213
  continue;
13185
13214
  }
13186
- parent = { schema: schema2, key, attribute, path: newPath };
13215
+ parent = {
13216
+ schema: schema2,
13217
+ key,
13218
+ attribute,
13219
+ path: newPath
13220
+ };
13187
13221
  if (isRelationalAttribute(attribute)) {
13188
13222
  const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
13189
13223
  const method = isMorphRelation ? traverseMorphRelationTarget : traverseRelationTarget(getModel(attribute.target));
13190
13224
  if (isArray(value)) {
13191
13225
  const res = new Array(value.length);
13192
13226
  for (let i2 = 0; i2 < value.length; i2 += 1) {
13193
- res[i2] = await method(visitor2, newPath, value[i2]);
13227
+ res[i2] = await method(visitor, newPath, value[i2]);
13194
13228
  }
13195
13229
  copy[key] = res;
13196
13230
  } else {
13197
- copy[key] = await method(visitor2, newPath, value);
13231
+ copy[key] = await method(visitor, newPath, value);
13198
13232
  }
13199
13233
  continue;
13200
13234
  }
@@ -13202,11 +13236,11 @@ const traverseEntity = async (visitor2, options, entity) => {
13202
13236
  if (isArray(value)) {
13203
13237
  const res = new Array(value.length);
13204
13238
  for (let i2 = 0; i2 < value.length; i2 += 1) {
13205
- res[i2] = await traverseMediaTarget(visitor2, newPath, value[i2]);
13239
+ res[i2] = await traverseMediaTarget(visitor, newPath, value[i2]);
13206
13240
  }
13207
13241
  copy[key] = res;
13208
13242
  } else {
13209
- copy[key] = await traverseMediaTarget(visitor2, newPath, value);
13243
+ copy[key] = await traverseMediaTarget(visitor, newPath, value);
13210
13244
  }
13211
13245
  continue;
13212
13246
  }
@@ -13215,18 +13249,18 @@ const traverseEntity = async (visitor2, options, entity) => {
13215
13249
  if (isArray(value)) {
13216
13250
  const res = new Array(value.length);
13217
13251
  for (let i2 = 0; i2 < value.length; i2 += 1) {
13218
- res[i2] = await traverseComponent(visitor2, newPath, targetSchema, value[i2]);
13252
+ res[i2] = await traverseComponent(visitor, newPath, targetSchema, value[i2]);
13219
13253
  }
13220
13254
  copy[key] = res;
13221
13255
  } else {
13222
- copy[key] = await traverseComponent(visitor2, newPath, targetSchema, value);
13256
+ copy[key] = await traverseComponent(visitor, newPath, targetSchema, value);
13223
13257
  }
13224
13258
  continue;
13225
13259
  }
13226
13260
  if (attribute.type === "dynamiczone" && isArray(value)) {
13227
13261
  const res = new Array(value.length);
13228
13262
  for (let i2 = 0; i2 < value.length; i2 += 1) {
13229
- res[i2] = await visitDynamicZoneEntry(visitor2, newPath, value[i2]);
13263
+ res[i2] = await visitDynamicZoneEntry(visitor, newPath, value[i2]);
13230
13264
  }
13231
13265
  copy[key] = res;
13232
13266
  continue;
@@ -13242,8 +13276,11 @@ const createVisitorUtils = ({ data }) => ({
13242
13276
  data[key] = value;
13243
13277
  }
13244
13278
  });
13245
- const traverseEntity$1 = curry(traverseEntity);
13246
- const GROUP_OPERATORS = ["$and", "$or"];
13279
+ var traverseEntity$1 = curry(traverseEntity);
13280
+ const GROUP_OPERATORS = [
13281
+ "$and",
13282
+ "$or"
13283
+ ];
13247
13284
  const WHERE_OPERATORS = [
13248
13285
  "$not",
13249
13286
  "$in",
@@ -13282,19 +13319,21 @@ const CAST_OPERATORS = [
13282
13319
  "$lte",
13283
13320
  "$between"
13284
13321
  ];
13285
- const ARRAY_OPERATORS = ["$in", "$notIn", "$between"];
13322
+ const ARRAY_OPERATORS = [
13323
+ "$in",
13324
+ "$notIn",
13325
+ "$between"
13326
+ ];
13286
13327
  const OPERATORS = {
13287
13328
  where: WHERE_OPERATORS,
13288
13329
  cast: CAST_OPERATORS,
13289
13330
  group: GROUP_OPERATORS,
13290
13331
  array: ARRAY_OPERATORS
13291
13332
  };
13292
- const OPERATORS_LOWERCASE = Object.fromEntries(
13293
- Object.entries(OPERATORS).map(([key, values]) => [
13294
- key,
13295
- values.map((value) => value.toLowerCase())
13296
- ])
13297
- );
13333
+ const OPERATORS_LOWERCASE = Object.fromEntries(Object.entries(OPERATORS).map(([key, values]) => [
13334
+ key,
13335
+ values.map((value) => value.toLowerCase())
13336
+ ]));
13298
13337
  const isObjKey = (key, obj) => {
13299
13338
  return key in obj;
13300
13339
  };
@@ -13321,26 +13360,28 @@ function pipe(...fns) {
13321
13360
  };
13322
13361
  }
13323
13362
  curry(pMap$1);
13324
- const visitor$8 = ({ key, attribute }, { remove: remove2 }) => {
13363
+ const visitor$8 = ({ key, attribute }, { remove }) => {
13325
13364
  if (attribute?.type === "password") {
13326
- remove2(key);
13365
+ remove(key);
13327
13366
  }
13328
13367
  };
13329
- const visitor$7 = ({ schema: schema2, key, attribute }, { remove: remove2 }) => {
13368
+ const visitor$7 = ({ schema: schema2, key, attribute }, { remove }) => {
13330
13369
  if (!attribute) {
13331
13370
  return;
13332
13371
  }
13333
13372
  const isPrivate = attribute.private === true || isPrivateAttribute(schema2, key);
13334
13373
  if (isPrivate) {
13335
- remove2(key);
13374
+ remove(key);
13336
13375
  }
13337
13376
  };
13338
13377
  const VALID_RELATION_ORDERING_KEYS = {
13339
13378
  strict: isBoolean$1
13340
13379
  };
13341
- const ACTIONS_TO_VERIFY$1 = ["find"];
13380
+ const ACTIONS_TO_VERIFY$1 = [
13381
+ "find"
13382
+ ];
13342
13383
  const { CREATED_BY_ATTRIBUTE: CREATED_BY_ATTRIBUTE$1, UPDATED_BY_ATTRIBUTE: UPDATED_BY_ATTRIBUTE$1 } = constants$1;
13343
- const removeRestrictedRelations = (auth) => async ({ data, key, attribute, schema: schema2 }, { remove: remove2, set: set2 }) => {
13384
+ var removeRestrictedRelations = (auth) => async ({ data, key, attribute, schema: schema2 }, { remove, set: set2 }) => {
13344
13385
  if (!attribute) {
13345
13386
  return;
13346
13387
  }
@@ -13405,10 +13446,13 @@ const removeRestrictedRelations = (auth) => async ({ data, key, attribute, schem
13405
13446
  const scopes = ACTIONS_TO_VERIFY$1.map((action) => `${attribute.target}.${action}`);
13406
13447
  const isAllowed = await hasAccessToSomeScopes$1(scopes, auth);
13407
13448
  if (!isAllowed) {
13408
- remove2(key);
13449
+ remove(key);
13409
13450
  }
13410
13451
  };
13411
- const isCreatorRelation = [CREATED_BY_ATTRIBUTE$1, UPDATED_BY_ATTRIBUTE$1].includes(key);
13452
+ const isCreatorRelation = [
13453
+ CREATED_BY_ATTRIBUTE$1,
13454
+ UPDATED_BY_ATTRIBUTE$1
13455
+ ].includes(key);
13412
13456
  if (isMorphToRelationalAttribute(attribute)) {
13413
13457
  await handleMorphRelation();
13414
13458
  return;
@@ -13421,7 +13465,9 @@ const removeRestrictedRelations = (auth) => async ({ data, key, attribute, schem
13421
13465
  const hasAccessToSomeScopes$1 = async (scopes, auth) => {
13422
13466
  for (const scope of scopes) {
13423
13467
  try {
13424
- await strapi.auth.verify(auth, { scope });
13468
+ await strapi.auth.verify(auth, {
13469
+ scope
13470
+ });
13425
13471
  return true;
13426
13472
  } catch {
13427
13473
  continue;
@@ -13429,74 +13475,75 @@ const hasAccessToSomeScopes$1 = async (scopes, auth) => {
13429
13475
  }
13430
13476
  return false;
13431
13477
  };
13432
- const visitor$6 = ({ key, attribute }, { remove: remove2 }) => {
13478
+ const visitor$6 = ({ key, attribute }, { remove }) => {
13433
13479
  if (isMorphToRelationalAttribute(attribute)) {
13434
- remove2(key);
13480
+ remove(key);
13435
13481
  }
13436
13482
  };
13437
- const visitor$5 = ({ key, attribute }, { remove: remove2 }) => {
13483
+ const visitor$5 = ({ key, attribute }, { remove }) => {
13438
13484
  if (isDynamicZoneAttribute(attribute)) {
13439
- remove2(key);
13485
+ remove(key);
13440
13486
  }
13441
13487
  };
13442
- const removeDisallowedFields = (allowedFields = null) => ({ key, path: { attribute: path2 } }, { remove: remove2 }) => {
13488
+ var removeDisallowedFields = (allowedFields = null) => ({ key, path: { attribute: path2 } }, { remove }) => {
13443
13489
  if (allowedFields === null) {
13444
13490
  return;
13445
13491
  }
13446
13492
  if (!(isArray(allowedFields) && allowedFields.every(isString))) {
13447
- throw new TypeError(
13448
- `Expected array of strings for allowedFields but got "${typeof allowedFields}"`
13449
- );
13493
+ throw new TypeError(`Expected array of strings for allowedFields but got "${typeof allowedFields}"`);
13450
13494
  }
13451
13495
  if (isNil(path2)) {
13452
13496
  return;
13453
13497
  }
13454
13498
  const containedPaths = getContainedPaths$1(path2);
13455
- const isPathAllowed = allowedFields.some(
13456
- (p) => containedPaths.includes(p) || p.startsWith(`${path2}.`)
13457
- );
13499
+ const isPathAllowed = allowedFields.some((p) => containedPaths.includes(p) || p.startsWith(`${path2}.`));
13458
13500
  if (isPathAllowed) {
13459
13501
  return;
13460
13502
  }
13461
- remove2(key);
13503
+ remove(key);
13462
13504
  };
13463
13505
  const getContainedPaths$1 = (path2) => {
13464
13506
  const parts = toPath(path2);
13465
13507
  return parts.reduce((acc, value, index2, list) => {
13466
- return [...acc, list.slice(0, index2 + 1).join(".")];
13508
+ return [
13509
+ ...acc,
13510
+ list.slice(0, index2 + 1).join(".")
13511
+ ];
13467
13512
  }, []);
13468
13513
  };
13469
- const removeRestrictedFields = (restrictedFields = null) => ({ key, path: { attribute: path2 } }, { remove: remove2 }) => {
13514
+ var removeRestrictedFields = (restrictedFields = null) => ({ key, path: { attribute: path2 } }, { remove }) => {
13470
13515
  if (restrictedFields === null) {
13471
- remove2(key);
13516
+ remove(key);
13472
13517
  return;
13473
13518
  }
13474
13519
  if (!(isArray(restrictedFields) && restrictedFields.every(isString))) {
13475
- throw new TypeError(
13476
- `Expected array of strings for restrictedFields but got "${typeof restrictedFields}"`
13477
- );
13520
+ throw new TypeError(`Expected array of strings for restrictedFields but got "${typeof restrictedFields}"`);
13478
13521
  }
13479
13522
  if (restrictedFields.includes(path2)) {
13480
- remove2(key);
13523
+ remove(key);
13481
13524
  return;
13482
13525
  }
13483
- const isRestrictedNested = restrictedFields.some(
13484
- (allowedPath) => path2?.toString().startsWith(`${allowedPath}.`)
13485
- );
13526
+ const isRestrictedNested = restrictedFields.some((allowedPath) => path2?.toString().startsWith(`${allowedPath}.`));
13486
13527
  if (isRestrictedNested) {
13487
- remove2(key);
13528
+ remove(key);
13488
13529
  }
13489
13530
  };
13490
13531
  const visitor$4 = ({ schema: schema2, key, value }, { set: set2 }) => {
13491
13532
  if (key === "" && value === "*") {
13492
13533
  const { attributes } = schema2;
13493
- const newPopulateQuery = Object.entries(attributes).filter(
13494
- ([, attribute]) => ["relation", "component", "media", "dynamiczone"].includes(attribute.type)
13495
- ).reduce((acc, [key2]) => ({ ...acc, [key2]: true }), {});
13534
+ const newPopulateQuery = Object.entries(attributes).filter(([, attribute]) => [
13535
+ "relation",
13536
+ "component",
13537
+ "media",
13538
+ "dynamiczone"
13539
+ ].includes(attribute.type)).reduce((acc, [key2]) => ({
13540
+ ...acc,
13541
+ [key2]: true
13542
+ }), {});
13496
13543
  set2("", newPopulateQuery);
13497
13544
  }
13498
13545
  };
13499
- const index$4 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
13546
+ var index$4 = /* @__PURE__ */ Object.freeze({
13500
13547
  __proto__: null,
13501
13548
  expandWildcardPopulate: visitor$4,
13502
13549
  removeDisallowedFields,
@@ -13506,9 +13553,12 @@ const index$4 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePrope
13506
13553
  removePrivate: visitor$7,
13507
13554
  removeRestrictedFields,
13508
13555
  removeRestrictedRelations
13509
- }, Symbol.toStringTag, { value: "Module" }));
13510
- const DEFAULT_PATH = { raw: null, attribute: null };
13511
- const traverseFactory = () => {
13556
+ });
13557
+ const DEFAULT_PATH = {
13558
+ raw: null,
13559
+ attribute: null
13560
+ };
13561
+ var traverseFactory = () => {
13512
13562
  const state = {
13513
13563
  parsers: [],
13514
13564
  interceptors: [],
@@ -13518,11 +13568,13 @@ const traverseFactory = () => {
13518
13568
  common: []
13519
13569
  }
13520
13570
  };
13521
- const traverse = async (visitor2, options, data) => {
13571
+ const traverse = async (visitor, options, data) => {
13522
13572
  const { path: path2 = DEFAULT_PATH, parent, schema: schema2, getModel } = options ?? {};
13523
13573
  for (const { predicate, handler } of state.interceptors) {
13524
13574
  if (predicate(data)) {
13525
- return handler(visitor2, options, data, { recurse: traverse });
13575
+ return handler(visitor, options, data, {
13576
+ recurse: traverse
13577
+ });
13526
13578
  }
13527
13579
  }
13528
13580
  const parser = state.parsers.find((parser2) => parser2.predicate(data))?.parser;
@@ -13534,7 +13586,9 @@ const traverseFactory = () => {
13534
13586
  const keys = utils2.keys(out);
13535
13587
  for (const key of keys) {
13536
13588
  const attribute = schema2?.attributes?.[key];
13537
- const newPath = { ...path2 };
13589
+ const newPath = {
13590
+ ...path2
13591
+ };
13538
13592
  newPath.raw = isNil(path2.raw) ? key : `${path2.raw}.${key}`;
13539
13593
  if (!isNil(attribute)) {
13540
13594
  newPath.attribute = isNil(path2.attribute) ? key : `${path2.attribute}.${key}`;
@@ -13558,7 +13612,10 @@ const traverseFactory = () => {
13558
13612
  },
13559
13613
  recurse: traverse
13560
13614
  };
13561
- await visitor2(visitorOptions, pick(["remove", "set"], transformUtils));
13615
+ await visitor(visitorOptions, pick([
13616
+ "remove",
13617
+ "set"
13618
+ ], transformUtils));
13562
13619
  const value = utils2.get(key, out);
13563
13620
  const createContext = () => ({
13564
13621
  key,
@@ -13567,7 +13624,7 @@ const traverseFactory = () => {
13567
13624
  schema: schema2,
13568
13625
  path: newPath,
13569
13626
  data: out,
13570
- visitor: visitor2,
13627
+ visitor,
13571
13628
  getModel,
13572
13629
  parent
13573
13630
  });
@@ -13576,12 +13633,18 @@ const traverseFactory = () => {
13576
13633
  if (shouldIgnore) {
13577
13634
  continue;
13578
13635
  }
13579
- const handlers = [...state.handlers.common, ...state.handlers.attributes];
13636
+ const handlers = [
13637
+ ...state.handlers.common,
13638
+ ...state.handlers.attributes
13639
+ ];
13580
13640
  for await (const handler of handlers) {
13581
13641
  const ctx = createContext();
13582
13642
  const pass = await handler.predicate(ctx);
13583
13643
  if (pass) {
13584
- await handler.handler(ctx, pick(["recurse", "set"], transformUtils));
13644
+ await handler.handler(ctx, pick([
13645
+ "recurse",
13646
+ "set"
13647
+ ], transformUtils));
13585
13648
  }
13586
13649
  }
13587
13650
  }
@@ -13590,11 +13653,17 @@ const traverseFactory = () => {
13590
13653
  return {
13591
13654
  traverse,
13592
13655
  intercept(predicate, handler) {
13593
- state.interceptors.push({ predicate, handler });
13656
+ state.interceptors.push({
13657
+ predicate,
13658
+ handler
13659
+ });
13594
13660
  return this;
13595
13661
  },
13596
13662
  parse(predicate, parser) {
13597
- state.parsers.push({ predicate, parser });
13663
+ state.parsers.push({
13664
+ predicate,
13665
+ parser
13666
+ });
13598
13667
  return this;
13599
13668
  },
13600
13669
  ignore(predicate) {
@@ -13602,11 +13671,17 @@ const traverseFactory = () => {
13602
13671
  return this;
13603
13672
  },
13604
13673
  on(predicate, handler) {
13605
- state.handlers.common.push({ predicate, handler });
13674
+ state.handlers.common.push({
13675
+ predicate,
13676
+ handler
13677
+ });
13606
13678
  return this;
13607
13679
  },
13608
13680
  onAttribute(predicate, handler) {
13609
- state.handlers.attributes.push({ predicate, handler });
13681
+ state.handlers.attributes.push({
13682
+ predicate,
13683
+ handler
13684
+ });
13610
13685
  return this;
13611
13686
  },
13612
13687
  onRelation(handler) {
@@ -13627,19 +13702,22 @@ const isObj$2 = (value) => isObject$5(value);
13627
13702
  const filters = traverseFactory().intercept(
13628
13703
  // Intercept filters arrays and apply the traversal to each one individually
13629
13704
  isArray,
13630
- async (visitor2, options, filters2, { recurse }) => {
13631
- return Promise.all(
13632
- filters2.map((filter, i) => {
13633
- const newPath = options.path ? { ...options.path, raw: `${options.path.raw}[${i}]` } : options.path;
13634
- return recurse(visitor2, { ...options, path: newPath }, filter);
13635
- })
13636
- // todo: move that to the visitors
13637
- ).then((res) => res.filter((val) => !(isObject$5(val) && isEmpty$2(val))));
13705
+ async (visitor, options, filters2, { recurse }) => {
13706
+ return Promise.all(filters2.map((filter, i) => {
13707
+ const newPath = options.path ? {
13708
+ ...options.path,
13709
+ raw: `${options.path.raw}[${i}]`
13710
+ } : options.path;
13711
+ return recurse(visitor, {
13712
+ ...options,
13713
+ path: newPath
13714
+ }, filter);
13715
+ })).then((res) => res.filter((val) => !(isObject$5(val) && isEmpty$2(val))));
13638
13716
  }
13639
13717
  ).intercept(
13640
13718
  // Ignore non object filters and return the value as-is
13641
13719
  (filters2) => !isObject$5(filters2),
13642
- (_2, __, filters2) => {
13720
+ (_, __, filters2) => {
13643
13721
  return filters2;
13644
13722
  }
13645
13723
  ).parse(isObj$2, () => ({
@@ -13648,7 +13726,10 @@ const filters = traverseFactory().intercept(
13648
13726
  return omit(key, data);
13649
13727
  },
13650
13728
  set(key, value, data) {
13651
- return { ...data, [key]: value };
13729
+ return {
13730
+ ...data,
13731
+ [key]: value
13732
+ };
13652
13733
  },
13653
13734
  keys(data) {
13654
13735
  return Object.keys(data);
@@ -13656,52 +13737,76 @@ const filters = traverseFactory().intercept(
13656
13737
  get(key, data) {
13657
13738
  return data[key];
13658
13739
  }
13659
- })).ignore(({ value }) => isNil(value)).on(
13660
- ({ attribute }) => isNil(attribute),
13661
- async ({ key, visitor: visitor2, path: path2, value, schema: schema2, getModel, attribute }, { set: set2, recurse }) => {
13662
- const parent = { key, path: path2, schema: schema2, attribute };
13663
- set2(key, await recurse(visitor2, { schema: schema2, path: path2, getModel, parent }, value));
13664
- }
13665
- ).onRelation(
13666
- async ({ key, attribute, visitor: visitor2, path: path2, value, schema: schema2, getModel }, { set: set2, recurse }) => {
13667
- const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
13668
- if (isMorphRelation) {
13669
- return;
13670
- }
13671
- const parent = { key, path: path2, schema: schema2, attribute };
13672
- const targetSchemaUID = attribute.target;
13673
- const targetSchema = getModel(targetSchemaUID);
13674
- const newValue = await recurse(
13675
- visitor2,
13676
- { schema: targetSchema, path: path2, getModel, parent },
13677
- value
13678
- );
13679
- set2(key, newValue);
13680
- }
13681
- ).onComponent(
13682
- async ({ key, attribute, visitor: visitor2, path: path2, schema: schema2, value, getModel }, { set: set2, recurse }) => {
13683
- const parent = { key, path: path2, schema: schema2, attribute };
13684
- const targetSchema = getModel(attribute.component);
13685
- const newValue = await recurse(
13686
- visitor2,
13687
- { schema: targetSchema, path: path2, getModel, parent },
13688
- value
13689
- );
13690
- set2(key, newValue);
13740
+ })).ignore(({ value }) => isNil(value)).on(({ attribute }) => isNil(attribute), async ({ key, visitor, path: path2, value, schema: schema2, getModel, attribute }, { set: set2, recurse }) => {
13741
+ const parent = {
13742
+ key,
13743
+ path: path2,
13744
+ schema: schema2,
13745
+ attribute
13746
+ };
13747
+ set2(key, await recurse(visitor, {
13748
+ schema: schema2,
13749
+ path: path2,
13750
+ getModel,
13751
+ parent
13752
+ }, value));
13753
+ }).onRelation(async ({ key, attribute, visitor, path: path2, value, schema: schema2, getModel }, { set: set2, recurse }) => {
13754
+ const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
13755
+ if (isMorphRelation) {
13756
+ return;
13691
13757
  }
13692
- ).onMedia(async ({ key, visitor: visitor2, path: path2, schema: schema2, attribute, value, getModel }, { set: set2, recurse }) => {
13693
- const parent = { key, path: path2, schema: schema2, attribute };
13758
+ const parent = {
13759
+ key,
13760
+ path: path2,
13761
+ schema: schema2,
13762
+ attribute
13763
+ };
13764
+ const targetSchemaUID = attribute.target;
13765
+ const targetSchema = getModel(targetSchemaUID);
13766
+ const newValue = await recurse(visitor, {
13767
+ schema: targetSchema,
13768
+ path: path2,
13769
+ getModel,
13770
+ parent
13771
+ }, value);
13772
+ set2(key, newValue);
13773
+ }).onComponent(async ({ key, attribute, visitor, path: path2, schema: schema2, value, getModel }, { set: set2, recurse }) => {
13774
+ const parent = {
13775
+ key,
13776
+ path: path2,
13777
+ schema: schema2,
13778
+ attribute
13779
+ };
13780
+ const targetSchema = getModel(attribute.component);
13781
+ const newValue = await recurse(visitor, {
13782
+ schema: targetSchema,
13783
+ path: path2,
13784
+ getModel,
13785
+ parent
13786
+ }, value);
13787
+ set2(key, newValue);
13788
+ }).onMedia(async ({ key, visitor, path: path2, schema: schema2, attribute, value, getModel }, { set: set2, recurse }) => {
13789
+ const parent = {
13790
+ key,
13791
+ path: path2,
13792
+ schema: schema2,
13793
+ attribute
13794
+ };
13694
13795
  const targetSchemaUID = "plugin::upload.file";
13695
13796
  const targetSchema = getModel(targetSchemaUID);
13696
- const newValue = await recurse(
13697
- visitor2,
13698
- { schema: targetSchema, path: path2, getModel, parent },
13699
- value
13700
- );
13797
+ const newValue = await recurse(visitor, {
13798
+ schema: targetSchema,
13799
+ path: path2,
13800
+ getModel,
13801
+ parent
13802
+ }, value);
13701
13803
  set2(key, newValue);
13702
13804
  });
13703
- const traverseQueryFilters = curry(filters.traverse);
13704
- const ORDERS = { asc: "asc", desc: "desc" };
13805
+ var traverseQueryFilters = curry(filters.traverse);
13806
+ const ORDERS = {
13807
+ asc: "asc",
13808
+ desc: "desc"
13809
+ };
13705
13810
  const ORDER_VALUES = Object.values(ORDERS);
13706
13811
  const isSortOrder = (value) => ORDER_VALUES.includes(value.toLowerCase());
13707
13812
  const isStringArray$2 = (value) => Array.isArray(value) && value.every(isString);
@@ -13711,26 +13816,20 @@ const isObj$1 = (value) => isObject$5(value);
13711
13816
  const sort = traverseFactory().intercept(
13712
13817
  // String with chained sorts (foo,bar,foobar) => split, map(recurse), then recompose
13713
13818
  isNestedSorts,
13714
- async (visitor2, options, sort2, { recurse }) => {
13715
- return Promise.all(
13716
- sort2.split(",").map(trim$1).map((nestedSort) => recurse(visitor2, options, nestedSort))
13717
- ).then((res) => res.filter((part) => !isEmpty$2(part)).join(","));
13819
+ async (visitor, options, sort2, { recurse }) => {
13820
+ return Promise.all(sort2.split(",").map(trim$1).map((nestedSort) => recurse(visitor, options, nestedSort))).then((res) => res.filter((part) => !isEmpty$2(part)).join(","));
13718
13821
  }
13719
13822
  ).intercept(
13720
13823
  // Array of strings ['foo', 'foo,bar'] => map(recurse), then filter out empty items
13721
13824
  isStringArray$2,
13722
- async (visitor2, options, sort2, { recurse }) => {
13723
- return Promise.all(sort2.map((nestedSort) => recurse(visitor2, options, nestedSort))).then(
13724
- (res) => res.filter((nestedSort) => !isEmpty$2(nestedSort))
13725
- );
13825
+ async (visitor, options, sort2, { recurse }) => {
13826
+ return Promise.all(sort2.map((nestedSort) => recurse(visitor, options, nestedSort))).then((res) => res.filter((nestedSort) => !isEmpty$2(nestedSort)));
13726
13827
  }
13727
13828
  ).intercept(
13728
13829
  // Array of objects [{ foo: 'asc' }, { bar: 'desc', baz: 'asc' }] => map(recurse), then filter out empty items
13729
13830
  isObjectArray,
13730
- async (visitor2, options, sort2, { recurse }) => {
13731
- return Promise.all(sort2.map((nestedSort) => recurse(visitor2, options, nestedSort))).then(
13732
- (res) => res.filter((nestedSort) => !isEmpty$2(nestedSort))
13733
- );
13831
+ async (visitor, options, sort2, { recurse }) => {
13832
+ return Promise.all(sort2.map((nestedSort) => recurse(visitor, options, nestedSort))).then((res) => res.filter((nestedSort) => !isEmpty$2(nestedSort)));
13734
13833
  }
13735
13834
  ).parse(isString, () => {
13736
13835
  const tokenize = pipe$1(split$1("."), map$2(split$1(":")), flatten);
@@ -13763,7 +13862,9 @@ const sort = traverseFactory().intercept(
13763
13862
  },
13764
13863
  keys(data) {
13765
13864
  const v = first(tokenize(data));
13766
- return v ? [v] : [];
13865
+ return v ? [
13866
+ v
13867
+ ] : [];
13767
13868
  },
13768
13869
  get(key, data) {
13769
13870
  const [root2, ...rest] = tokenize(data);
@@ -13777,7 +13878,10 @@ const sort = traverseFactory().intercept(
13777
13878
  return rest;
13778
13879
  },
13779
13880
  set(key, value, data) {
13780
- return { ...data, [key]: value };
13881
+ return {
13882
+ ...data,
13883
+ [key]: value
13884
+ };
13781
13885
  },
13782
13886
  keys(data) {
13783
13887
  return Object.keys(data);
@@ -13785,45 +13889,59 @@ const sort = traverseFactory().intercept(
13785
13889
  get(key, data) {
13786
13890
  return data[key];
13787
13891
  }
13788
- })).onRelation(
13789
- async ({ key, value, attribute, visitor: visitor2, path: path2, getModel, schema: schema2 }, { set: set2, recurse }) => {
13790
- const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
13791
- if (isMorphRelation) {
13792
- return;
13793
- }
13794
- const parent = { key, path: path2, schema: schema2, attribute };
13795
- const targetSchemaUID = attribute.target;
13796
- const targetSchema = getModel(targetSchemaUID);
13797
- const newValue = await recurse(
13798
- visitor2,
13799
- { schema: targetSchema, path: path2, getModel, parent },
13800
- value
13801
- );
13802
- set2(key, newValue);
13892
+ })).onRelation(async ({ key, value, attribute, visitor, path: path2, getModel, schema: schema2 }, { set: set2, recurse }) => {
13893
+ const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
13894
+ if (isMorphRelation) {
13895
+ return;
13803
13896
  }
13804
- ).onMedia(async ({ key, path: path2, schema: schema2, attribute, visitor: visitor2, value, getModel }, { recurse, set: set2 }) => {
13805
- const parent = { key, path: path2, schema: schema2, attribute };
13897
+ const parent = {
13898
+ key,
13899
+ path: path2,
13900
+ schema: schema2,
13901
+ attribute
13902
+ };
13903
+ const targetSchemaUID = attribute.target;
13904
+ const targetSchema = getModel(targetSchemaUID);
13905
+ const newValue = await recurse(visitor, {
13906
+ schema: targetSchema,
13907
+ path: path2,
13908
+ getModel,
13909
+ parent
13910
+ }, value);
13911
+ set2(key, newValue);
13912
+ }).onMedia(async ({ key, path: path2, schema: schema2, attribute, visitor, value, getModel }, { recurse, set: set2 }) => {
13913
+ const parent = {
13914
+ key,
13915
+ path: path2,
13916
+ schema: schema2,
13917
+ attribute
13918
+ };
13806
13919
  const targetSchemaUID = "plugin::upload.file";
13807
13920
  const targetSchema = getModel(targetSchemaUID);
13808
- const newValue = await recurse(
13809
- visitor2,
13810
- { schema: targetSchema, path: path2, getModel, parent },
13811
- value
13812
- );
13921
+ const newValue = await recurse(visitor, {
13922
+ schema: targetSchema,
13923
+ path: path2,
13924
+ getModel,
13925
+ parent
13926
+ }, value);
13813
13927
  set2(key, newValue);
13814
- }).onComponent(
13815
- async ({ key, value, visitor: visitor2, path: path2, schema: schema2, attribute, getModel }, { recurse, set: set2 }) => {
13816
- const parent = { key, path: path2, schema: schema2, attribute };
13817
- const targetSchema = getModel(attribute.component);
13818
- const newValue = await recurse(
13819
- visitor2,
13820
- { schema: targetSchema, path: path2, getModel, parent },
13821
- value
13822
- );
13823
- set2(key, newValue);
13824
- }
13825
- );
13826
- const traverseQuerySort = curry(sort.traverse);
13928
+ }).onComponent(async ({ key, value, visitor, path: path2, schema: schema2, attribute, getModel }, { recurse, set: set2 }) => {
13929
+ const parent = {
13930
+ key,
13931
+ path: path2,
13932
+ schema: schema2,
13933
+ attribute
13934
+ };
13935
+ const targetSchema = getModel(attribute.component);
13936
+ const newValue = await recurse(visitor, {
13937
+ schema: targetSchema,
13938
+ path: path2,
13939
+ getModel,
13940
+ parent
13941
+ }, value);
13942
+ set2(key, newValue);
13943
+ });
13944
+ var traverseQuerySort = curry(sort.traverse);
13827
13945
  const isKeyword = (keyword) => {
13828
13946
  return ({ key, attribute }) => {
13829
13947
  return !attribute && keyword === key;
@@ -13835,39 +13953,41 @@ const isPopulateString = (value) => {
13835
13953
  };
13836
13954
  const isStringArray$1 = (value) => isArray(value) && value.every(isString);
13837
13955
  const isObj = (value) => isObject$5(value);
13838
- const populate$2 = traverseFactory().intercept(isPopulateString, async (visitor2, options, populate2, { recurse }) => {
13839
- const populateObject = pathsToObjectPopulate([populate2]);
13840
- const traversedPopulate = await recurse(visitor2, options, populateObject);
13956
+ const populate$2 = traverseFactory().intercept(isPopulateString, async (visitor, options, populate2, { recurse }) => {
13957
+ const populateObject = pathsToObjectPopulate([
13958
+ populate2
13959
+ ]);
13960
+ const traversedPopulate = await recurse(visitor, options, populateObject);
13841
13961
  const [result] = objectPopulateToPaths(traversedPopulate);
13842
13962
  return result;
13843
- }).intercept(isStringArray$1, async (visitor2, options, populate2, { recurse }) => {
13844
- const paths = await Promise.all(
13845
- populate2.map((subClause) => recurse(visitor2, options, subClause))
13846
- );
13963
+ }).intercept(isStringArray$1, async (visitor, options, populate2, { recurse }) => {
13964
+ const paths = await Promise.all(populate2.map((subClause) => recurse(visitor, options, subClause)));
13847
13965
  return paths.filter((item) => !isNil(item));
13848
13966
  }).parse(isWildcard, () => ({
13849
13967
  /**
13850
- * Since value is '*', we don't need to transform it
13851
- */
13968
+ * Since value is '*', we don't need to transform it
13969
+ */
13852
13970
  transform: identity,
13853
13971
  /**
13854
- * '*' isn't a key/value structure, so regardless
13855
- * of the given key, it returns the data ('*')
13856
- */
13972
+ * '*' isn't a key/value structure, so regardless
13973
+ * of the given key, it returns the data ('*')
13974
+ */
13857
13975
  get: (_key, data) => data,
13858
13976
  /**
13859
- * '*' isn't a key/value structure, so regardless
13860
- * of the given `key`, use `value` as the new `data`
13861
- */
13977
+ * '*' isn't a key/value structure, so regardless
13978
+ * of the given `key`, use `value` as the new `data`
13979
+ */
13862
13980
  set: (_key, value) => value,
13863
13981
  /**
13864
- * '*' isn't a key/value structure, but we need to simulate at least one to enable
13865
- * the data traversal. We're using '' since it represents a falsy string value
13866
- */
13867
- keys: constant([""]),
13982
+ * '*' isn't a key/value structure, but we need to simulate at least one to enable
13983
+ * the data traversal. We're using '' since it represents a falsy string value
13984
+ */
13985
+ keys: constant([
13986
+ ""
13987
+ ]),
13868
13988
  /**
13869
- * Removing '*' means setting it to undefined, regardless of the given key
13870
- */
13989
+ * Removing '*' means setting it to undefined, regardless of the given key
13990
+ */
13871
13991
  remove: constant(void 0)
13872
13992
  })).parse(isString, () => {
13873
13993
  const tokenize = split$1(".");
@@ -13887,7 +14007,9 @@ const populate$2 = traverseFactory().intercept(isPopulateString, async (visitor2
13887
14007
  },
13888
14008
  keys(data) {
13889
14009
  const v = first(tokenize(data));
13890
- return v ? [v] : [];
14010
+ return v ? [
14011
+ v
14012
+ ] : [];
13891
14013
  },
13892
14014
  get(key, data) {
13893
14015
  const [root2, ...rest] = tokenize(data);
@@ -13901,7 +14023,10 @@ const populate$2 = traverseFactory().intercept(isPopulateString, async (visitor2
13901
14023
  return rest;
13902
14024
  },
13903
14025
  set(key, value, data) {
13904
- return { ...data, [key]: value };
14026
+ return {
14027
+ ...data,
14028
+ [key]: value
14029
+ };
13905
14030
  },
13906
14031
  keys(data) {
13907
14032
  return Object.keys(data);
@@ -13910,100 +14035,142 @@ const populate$2 = traverseFactory().intercept(isPopulateString, async (visitor2
13910
14035
  return data[key];
13911
14036
  }
13912
14037
  })).ignore(({ key, attribute }) => {
13913
- return ["sort", "filters", "fields"].includes(key) && !attribute;
14038
+ return [
14039
+ "sort",
14040
+ "filters",
14041
+ "fields"
14042
+ ].includes(key) && !attribute;
13914
14043
  }).on(
13915
14044
  // Handle recursion on populate."populate"
13916
14045
  isKeyword("populate"),
13917
- async ({ key, visitor: visitor2, path: path2, value, schema: schema2, getModel, attribute }, { set: set2, recurse }) => {
13918
- const parent = { key, path: path2, schema: schema2, attribute };
13919
- const newValue = await recurse(visitor2, { schema: schema2, path: path2, getModel, parent }, value);
14046
+ async ({ key, visitor, path: path2, value, schema: schema2, getModel, attribute }, { set: set2, recurse }) => {
14047
+ const parent = {
14048
+ key,
14049
+ path: path2,
14050
+ schema: schema2,
14051
+ attribute
14052
+ };
14053
+ const newValue = await recurse(visitor, {
14054
+ schema: schema2,
14055
+ path: path2,
14056
+ getModel,
14057
+ parent
14058
+ }, value);
13920
14059
  set2(key, newValue);
13921
14060
  }
13922
- ).on(
13923
- isKeyword("on"),
13924
- async ({ key, visitor: visitor2, path: path2, value, getModel, parent }, { set: set2, recurse }) => {
13925
- const newOn = {};
13926
- if (!isObj(value)) {
13927
- return;
13928
- }
13929
- for (const [uid, subPopulate] of Object.entries(value)) {
13930
- const model = getModel(uid);
13931
- const newPath = { ...path2, raw: `${path2.raw}[${uid}]` };
13932
- newOn[uid] = await recurse(
13933
- visitor2,
13934
- { schema: model, path: newPath, getModel, parent },
13935
- subPopulate
13936
- );
13937
- }
13938
- set2(key, newOn);
14061
+ ).on(isKeyword("on"), async ({ key, visitor, path: path2, value, getModel, parent }, { set: set2, recurse }) => {
14062
+ const newOn = {};
14063
+ if (!isObj(value)) {
14064
+ return;
13939
14065
  }
13940
- ).onRelation(
13941
- async ({ key, value, attribute, visitor: visitor2, path: path2, schema: schema2, getModel }, { set: set2, recurse }) => {
13942
- if (isNil(value)) {
13943
- return;
13944
- }
13945
- const parent = { key, path: path2, schema: schema2, attribute };
13946
- if (isMorphToRelationalAttribute(attribute)) {
13947
- if (!isObject$5(value) || !("on" in value && isObject$5(value?.on))) {
13948
- return;
13949
- }
13950
- const newValue2 = await recurse(
13951
- visitor2,
13952
- { schema: schema2, path: path2, getModel, parent },
13953
- { on: value?.on }
13954
- );
13955
- set2(key, newValue2);
14066
+ for (const [uid, subPopulate] of Object.entries(value)) {
14067
+ const model = getModel(uid);
14068
+ const newPath = {
14069
+ ...path2,
14070
+ raw: `${path2.raw}[${uid}]`
14071
+ };
14072
+ newOn[uid] = await recurse(visitor, {
14073
+ schema: model,
14074
+ path: newPath,
14075
+ getModel,
14076
+ parent
14077
+ }, subPopulate);
14078
+ }
14079
+ set2(key, newOn);
14080
+ }).onRelation(async ({ key, value, attribute, visitor, path: path2, schema: schema2, getModel }, { set: set2, recurse }) => {
14081
+ if (isNil(value)) {
14082
+ return;
14083
+ }
14084
+ const parent = {
14085
+ key,
14086
+ path: path2,
14087
+ schema: schema2,
14088
+ attribute
14089
+ };
14090
+ if (isMorphToRelationalAttribute(attribute)) {
14091
+ if (!isObject$5(value) || !("on" in value && isObject$5(value?.on))) {
13956
14092
  return;
13957
14093
  }
13958
- const targetSchemaUID = attribute.target;
13959
- const targetSchema = getModel(targetSchemaUID);
13960
- const newValue = await recurse(
13961
- visitor2,
13962
- { schema: targetSchema, path: path2, getModel, parent },
13963
- value
13964
- );
13965
- set2(key, newValue);
14094
+ const newValue2 = await recurse(visitor, {
14095
+ schema: schema2,
14096
+ path: path2,
14097
+ getModel,
14098
+ parent
14099
+ }, {
14100
+ on: value?.on
14101
+ });
14102
+ set2(key, newValue2);
14103
+ return;
13966
14104
  }
13967
- ).onMedia(async ({ key, path: path2, schema: schema2, attribute, visitor: visitor2, value, getModel }, { recurse, set: set2 }) => {
14105
+ const targetSchemaUID = attribute.target;
14106
+ const targetSchema = getModel(targetSchemaUID);
14107
+ const newValue = await recurse(visitor, {
14108
+ schema: targetSchema,
14109
+ path: path2,
14110
+ getModel,
14111
+ parent
14112
+ }, value);
14113
+ set2(key, newValue);
14114
+ }).onMedia(async ({ key, path: path2, schema: schema2, attribute, visitor, value, getModel }, { recurse, set: set2 }) => {
13968
14115
  if (isNil(value)) {
13969
14116
  return;
13970
14117
  }
13971
- const parent = { key, path: path2, schema: schema2, attribute };
14118
+ const parent = {
14119
+ key,
14120
+ path: path2,
14121
+ schema: schema2,
14122
+ attribute
14123
+ };
13972
14124
  const targetSchemaUID = "plugin::upload.file";
13973
14125
  const targetSchema = getModel(targetSchemaUID);
13974
- const newValue = await recurse(
13975
- visitor2,
13976
- { schema: targetSchema, path: path2, getModel, parent },
13977
- value
13978
- );
14126
+ const newValue = await recurse(visitor, {
14127
+ schema: targetSchema,
14128
+ path: path2,
14129
+ getModel,
14130
+ parent
14131
+ }, value);
13979
14132
  set2(key, newValue);
13980
- }).onComponent(
13981
- async ({ key, value, schema: schema2, visitor: visitor2, path: path2, attribute, getModel }, { recurse, set: set2 }) => {
13982
- if (isNil(value)) {
13983
- return;
13984
- }
13985
- const parent = { key, path: path2, schema: schema2, attribute };
13986
- const targetSchema = getModel(attribute.component);
13987
- const newValue = await recurse(
13988
- visitor2,
13989
- { schema: targetSchema, path: path2, getModel, parent },
13990
- value
13991
- );
13992
- set2(key, newValue);
14133
+ }).onComponent(async ({ key, value, schema: schema2, visitor, path: path2, attribute, getModel }, { recurse, set: set2 }) => {
14134
+ if (isNil(value)) {
14135
+ return;
13993
14136
  }
13994
- ).onDynamicZone(
13995
- async ({ key, value, schema: schema2, visitor: visitor2, path: path2, attribute, getModel }, { set: set2, recurse }) => {
13996
- if (isNil(value) || !isObject$5(value)) {
13997
- return;
13998
- }
13999
- const parent = { key, path: path2, schema: schema2, attribute };
14000
- if ("on" in value && value.on) {
14001
- const newOn = await recurse(visitor2, { schema: schema2, path: path2, getModel, parent }, { on: value.on });
14002
- set2(key, newOn);
14003
- }
14137
+ const parent = {
14138
+ key,
14139
+ path: path2,
14140
+ schema: schema2,
14141
+ attribute
14142
+ };
14143
+ const targetSchema = getModel(attribute.component);
14144
+ const newValue = await recurse(visitor, {
14145
+ schema: targetSchema,
14146
+ path: path2,
14147
+ getModel,
14148
+ parent
14149
+ }, value);
14150
+ set2(key, newValue);
14151
+ }).onDynamicZone(async ({ key, value, schema: schema2, visitor, path: path2, attribute, getModel }, { set: set2, recurse }) => {
14152
+ if (isNil(value) || !isObject$5(value)) {
14153
+ return;
14004
14154
  }
14005
- );
14006
- const traverseQueryPopulate = curry(populate$2.traverse);
14155
+ const parent = {
14156
+ key,
14157
+ path: path2,
14158
+ schema: schema2,
14159
+ attribute
14160
+ };
14161
+ if ("on" in value && value.on) {
14162
+ const newOn = await recurse(visitor, {
14163
+ schema: schema2,
14164
+ path: path2,
14165
+ getModel,
14166
+ parent
14167
+ }, {
14168
+ on: value.on
14169
+ });
14170
+ set2(key, newOn);
14171
+ }
14172
+ });
14173
+ var traverseQueryPopulate = curry(populate$2.traverse);
14007
14174
  const objectPopulateToPaths = (input) => {
14008
14175
  const paths = [];
14009
14176
  function traverse(currentObj, parentPath) {
@@ -14027,7 +14194,9 @@ const pathsToObjectPopulate = (input) => {
14027
14194
  object2[first2] = true;
14028
14195
  } else {
14029
14196
  if (!object2[first2] || typeof object2[first2] === "boolean") {
14030
- object2[first2] = { populate: {} };
14197
+ object2[first2] = {
14198
+ populate: {}
14199
+ };
14031
14200
  }
14032
14201
  traverse(object2[first2].populate, rest);
14033
14202
  }
@@ -14038,14 +14207,11 @@ const pathsToObjectPopulate = (input) => {
14038
14207
  const isStringArray = (value) => {
14039
14208
  return isArray(value) && value.every(isString);
14040
14209
  };
14041
- const fields = traverseFactory().intercept(isStringArray, async (visitor2, options, fields2, { recurse }) => {
14042
- return Promise.all(fields2.map((field) => recurse(visitor2, options, field)));
14043
- }).intercept(
14044
- (value) => isString(value) && value.includes(","),
14045
- (visitor2, options, fields2, { recurse }) => {
14046
- return Promise.all(fields2.split(",").map((field) => recurse(visitor2, options, field)));
14047
- }
14048
- ).intercept((value) => eq("*", value), constant("*")).parse(isString, () => ({
14210
+ const fields = traverseFactory().intercept(isStringArray, async (visitor, options, fields2, { recurse }) => {
14211
+ return Promise.all(fields2.map((field) => recurse(visitor, options, field)));
14212
+ }).intercept((value) => isString(value) && value.includes(","), (visitor, options, fields2, { recurse }) => {
14213
+ return Promise.all(fields2.split(",").map((field) => recurse(visitor, options, field)));
14214
+ }).intercept((value) => eq("*", value), constant("*")).parse(isString, () => ({
14049
14215
  transform: trim$1,
14050
14216
  remove(key, data) {
14051
14217
  return data === key ? void 0 : data;
@@ -14054,13 +14220,15 @@ const fields = traverseFactory().intercept(isStringArray, async (visitor2, optio
14054
14220
  return data;
14055
14221
  },
14056
14222
  keys(data) {
14057
- return [data];
14223
+ return [
14224
+ data
14225
+ ];
14058
14226
  },
14059
14227
  get(key, data) {
14060
14228
  return key === data ? data : void 0;
14061
14229
  }
14062
14230
  }));
14063
- const traverseQueryFields = curry(fields.traverse);
14231
+ var traverseQueryFields = curry(fields.traverse);
14064
14232
  const { ID_ATTRIBUTE: ID_ATTRIBUTE$2, DOC_ID_ATTRIBUTE: DOC_ID_ATTRIBUTE$2 } = constants$1;
14065
14233
  const sanitizePasswords = (ctx) => async (entity) => {
14066
14234
  if (!ctx.schema) {
@@ -14072,14 +14240,10 @@ const defaultSanitizeOutput = async (ctx, entity) => {
14072
14240
  if (!ctx.schema) {
14073
14241
  throw new Error("Missing schema in defaultSanitizeOutput");
14074
14242
  }
14075
- return traverseEntity$1(
14076
- (...args) => {
14077
- visitor$8(...args);
14078
- visitor$7(...args);
14079
- },
14080
- ctx,
14081
- entity
14082
- );
14243
+ return traverseEntity$1((...args) => {
14244
+ visitor$8(...args);
14245
+ visitor$7(...args);
14246
+ }, ctx, entity);
14083
14247
  };
14084
14248
  const defaultSanitizeFilters = curry((ctx, filters2) => {
14085
14249
  if (!ctx.schema) {
@@ -14087,13 +14251,16 @@ const defaultSanitizeFilters = curry((ctx, filters2) => {
14087
14251
  }
14088
14252
  return pipe(
14089
14253
  // Remove keys that are not attributes or valid operators
14090
- traverseQueryFilters(({ key, attribute }, { remove: remove2 }) => {
14254
+ traverseQueryFilters(({ key, attribute }, { remove }) => {
14091
14255
  const isAttribute = !!attribute;
14092
- if ([ID_ATTRIBUTE$2, DOC_ID_ATTRIBUTE$2].includes(key)) {
14256
+ if ([
14257
+ ID_ATTRIBUTE$2,
14258
+ DOC_ID_ATTRIBUTE$2
14259
+ ].includes(key)) {
14093
14260
  return;
14094
14261
  }
14095
14262
  if (!isAttribute && !isOperator(key)) {
14096
- remove2(key);
14263
+ remove(key);
14097
14264
  }
14098
14265
  }, ctx),
14099
14266
  // Remove dynamic zones from filters
@@ -14105,9 +14272,9 @@ const defaultSanitizeFilters = curry((ctx, filters2) => {
14105
14272
  // Remove private from filters
14106
14273
  traverseQueryFilters(visitor$7, ctx),
14107
14274
  // Remove empty objects
14108
- traverseQueryFilters(({ key, value }, { remove: remove2 }) => {
14275
+ traverseQueryFilters(({ key, value }, { remove }) => {
14109
14276
  if (isObject$5(value) && isEmpty$2(value)) {
14110
- remove2(key);
14277
+ remove(key);
14111
14278
  }
14112
14279
  }, ctx)
14113
14280
  )(filters2);
@@ -14118,12 +14285,15 @@ const defaultSanitizeSort = curry((ctx, sort2) => {
14118
14285
  }
14119
14286
  return pipe(
14120
14287
  // Remove non attribute keys
14121
- traverseQuerySort(({ key, attribute }, { remove: remove2 }) => {
14122
- if ([ID_ATTRIBUTE$2, DOC_ID_ATTRIBUTE$2].includes(key)) {
14288
+ traverseQuerySort(({ key, attribute }, { remove }) => {
14289
+ if ([
14290
+ ID_ATTRIBUTE$2,
14291
+ DOC_ID_ATTRIBUTE$2
14292
+ ].includes(key)) {
14123
14293
  return;
14124
14294
  }
14125
14295
  if (!attribute) {
14126
- remove2(key);
14296
+ remove(key);
14127
14297
  }
14128
14298
  }, ctx),
14129
14299
  // Remove dynamic zones from sort
@@ -14135,12 +14305,15 @@ const defaultSanitizeSort = curry((ctx, sort2) => {
14135
14305
  // Remove passwords from filters
14136
14306
  traverseQuerySort(visitor$8, ctx),
14137
14307
  // Remove keys for empty non-scalar values
14138
- traverseQuerySort(({ key, attribute, value }, { remove: remove2 }) => {
14139
- if ([ID_ATTRIBUTE$2, DOC_ID_ATTRIBUTE$2].includes(key)) {
14308
+ traverseQuerySort(({ key, attribute, value }, { remove }) => {
14309
+ if ([
14310
+ ID_ATTRIBUTE$2,
14311
+ DOC_ID_ATTRIBUTE$2
14312
+ ].includes(key)) {
14140
14313
  return;
14141
14314
  }
14142
14315
  if (!isScalarAttribute(attribute) && isEmpty$2(value)) {
14143
- remove2(key);
14316
+ remove(key);
14144
14317
  }
14145
14318
  }, ctx)
14146
14319
  )(sort2);
@@ -14151,12 +14324,15 @@ const defaultSanitizeFields = curry((ctx, fields2) => {
14151
14324
  }
14152
14325
  return pipe(
14153
14326
  // Only keep scalar attributes
14154
- traverseQueryFields(({ key, attribute }, { remove: remove2 }) => {
14155
- if ([ID_ATTRIBUTE$2, DOC_ID_ATTRIBUTE$2].includes(key)) {
14327
+ traverseQueryFields(({ key, attribute }, { remove }) => {
14328
+ if ([
14329
+ ID_ATTRIBUTE$2,
14330
+ DOC_ID_ATTRIBUTE$2
14331
+ ].includes(key)) {
14156
14332
  return;
14157
14333
  }
14158
14334
  if (isNil(attribute) || !isScalarAttribute(attribute)) {
14159
- remove2(key);
14335
+ remove(key);
14160
14336
  }
14161
14337
  }, ctx),
14162
14338
  // Remove private fields
@@ -14177,25 +14353,46 @@ const defaultSanitizePopulate = curry((ctx, populate2) => {
14177
14353
  if (attribute) {
14178
14354
  return;
14179
14355
  }
14180
- const parent = { key, path: path2, schema: schema2, attribute };
14356
+ const parent = {
14357
+ key,
14358
+ path: path2,
14359
+ schema: schema2,
14360
+ attribute
14361
+ };
14181
14362
  if (key === "sort") {
14182
- set2(key, await defaultSanitizeSort({ schema: schema2, getModel, parent }, value));
14363
+ set2(key, await defaultSanitizeSort({
14364
+ schema: schema2,
14365
+ getModel,
14366
+ parent
14367
+ }, value));
14183
14368
  }
14184
14369
  if (key === "filters") {
14185
- set2(key, await defaultSanitizeFilters({ schema: schema2, getModel, parent }, value));
14370
+ set2(key, await defaultSanitizeFilters({
14371
+ schema: schema2,
14372
+ getModel,
14373
+ parent
14374
+ }, value));
14186
14375
  }
14187
14376
  if (key === "fields") {
14188
- set2(key, await defaultSanitizeFields({ schema: schema2, getModel, parent }, value));
14377
+ set2(key, await defaultSanitizeFields({
14378
+ schema: schema2,
14379
+ getModel,
14380
+ parent
14381
+ }, value));
14189
14382
  }
14190
14383
  if (key === "populate") {
14191
- set2(key, await defaultSanitizePopulate({ schema: schema2, getModel, parent }, value));
14384
+ set2(key, await defaultSanitizePopulate({
14385
+ schema: schema2,
14386
+ getModel,
14387
+ parent
14388
+ }, value));
14192
14389
  }
14193
14390
  }, ctx),
14194
14391
  // Remove private fields
14195
14392
  traverseQueryPopulate(visitor$7, ctx)
14196
14393
  )(populate2);
14197
14394
  });
14198
- const sanitizers = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
14395
+ var sanitizers = /* @__PURE__ */ Object.freeze({
14199
14396
  __proto__: null,
14200
14397
  defaultSanitizeFields,
14201
14398
  defaultSanitizeFilters,
@@ -14203,7 +14400,7 @@ const sanitizers = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePr
14203
14400
  defaultSanitizePopulate,
14204
14401
  defaultSanitizeSort,
14205
14402
  sanitizePasswords
14206
- }, Symbol.toStringTag, { value: "Module" }));
14403
+ });
14207
14404
  const createAPISanitizers = (opts) => {
14208
14405
  const { getModel } = opts;
14209
14406
  const sanitizeInput = (data, schema2, { auth } = {}) => {
@@ -14211,7 +14408,9 @@ const createAPISanitizers = (opts) => {
14211
14408
  throw new Error("Missing schema in sanitizeInput");
14212
14409
  }
14213
14410
  if (isArray(data)) {
14214
- return Promise.all(data.map((entry) => sanitizeInput(entry, schema2, { auth })));
14411
+ return Promise.all(data.map((entry) => sanitizeInput(entry, schema2, {
14412
+ auth
14413
+ })));
14215
14414
  }
14216
14415
  const nonWritableAttributes = getNonWritableAttributes(schema2);
14217
14416
  const transforms = [
@@ -14219,12 +14418,16 @@ const createAPISanitizers = (opts) => {
14219
14418
  omit(constants$1.ID_ATTRIBUTE),
14220
14419
  omit(constants$1.DOC_ID_ATTRIBUTE),
14221
14420
  // Remove non-writable attributes
14222
- traverseEntity$1(removeRestrictedFields(nonWritableAttributes), { schema: schema2, getModel })
14421
+ traverseEntity$1(removeRestrictedFields(nonWritableAttributes), {
14422
+ schema: schema2,
14423
+ getModel
14424
+ })
14223
14425
  ];
14224
14426
  if (auth) {
14225
- transforms.push(
14226
- traverseEntity$1(removeRestrictedRelations(auth), { schema: schema2, getModel })
14227
- );
14427
+ transforms.push(traverseEntity$1(removeRestrictedRelations(auth), {
14428
+ schema: schema2,
14429
+ getModel
14430
+ }));
14228
14431
  }
14229
14432
  opts?.sanitizers?.input?.forEach((sanitizer) => transforms.push(sanitizer(schema2)));
14230
14433
  return pipe(...transforms)(data);
@@ -14236,17 +14439,23 @@ const createAPISanitizers = (opts) => {
14236
14439
  if (isArray(data)) {
14237
14440
  const res = new Array(data.length);
14238
14441
  for (let i = 0; i < data.length; i += 1) {
14239
- res[i] = await sanitizeOutput(data[i], schema2, { auth });
14442
+ res[i] = await sanitizeOutput(data[i], schema2, {
14443
+ auth
14444
+ });
14240
14445
  }
14241
14446
  return res;
14242
14447
  }
14243
14448
  const transforms = [
14244
- (data2) => defaultSanitizeOutput({ schema: schema2, getModel }, data2)
14449
+ (data2) => defaultSanitizeOutput({
14450
+ schema: schema2,
14451
+ getModel
14452
+ }, data2)
14245
14453
  ];
14246
14454
  if (auth) {
14247
- transforms.push(
14248
- traverseEntity$1(removeRestrictedRelations(auth), { schema: schema2, getModel })
14249
- );
14455
+ transforms.push(traverseEntity$1(removeRestrictedRelations(auth), {
14456
+ schema: schema2,
14457
+ getModel
14458
+ }));
14250
14459
  }
14251
14460
  opts?.sanitizers?.output?.forEach((sanitizer) => transforms.push(sanitizer(schema2)));
14252
14461
  return pipe(...transforms)(data);
@@ -14258,16 +14467,28 @@ const createAPISanitizers = (opts) => {
14258
14467
  const { filters: filters2, sort: sort2, fields: fields2, populate: populate2 } = query;
14259
14468
  const sanitizedQuery = cloneDeep(query);
14260
14469
  if (filters2) {
14261
- Object.assign(sanitizedQuery, { filters: await sanitizeFilters(filters2, schema2, { auth }) });
14470
+ Object.assign(sanitizedQuery, {
14471
+ filters: await sanitizeFilters(filters2, schema2, {
14472
+ auth
14473
+ })
14474
+ });
14262
14475
  }
14263
14476
  if (sort2) {
14264
- Object.assign(sanitizedQuery, { sort: await sanitizeSort(sort2, schema2, { auth }) });
14477
+ Object.assign(sanitizedQuery, {
14478
+ sort: await sanitizeSort(sort2, schema2, {
14479
+ auth
14480
+ })
14481
+ });
14265
14482
  }
14266
14483
  if (fields2) {
14267
- Object.assign(sanitizedQuery, { fields: await sanitizeFields(fields2, schema2) });
14484
+ Object.assign(sanitizedQuery, {
14485
+ fields: await sanitizeFields(fields2, schema2)
14486
+ });
14268
14487
  }
14269
14488
  if (populate2) {
14270
- Object.assign(sanitizedQuery, { populate: await sanitizePopulate(populate2, schema2) });
14489
+ Object.assign(sanitizedQuery, {
14490
+ populate: await sanitizePopulate(populate2, schema2)
14491
+ });
14271
14492
  }
14272
14493
  return sanitizedQuery;
14273
14494
  };
@@ -14276,13 +14497,21 @@ const createAPISanitizers = (opts) => {
14276
14497
  throw new Error("Missing schema in sanitizeFilters");
14277
14498
  }
14278
14499
  if (isArray(filters2)) {
14279
- return Promise.all(filters2.map((filter) => sanitizeFilters(filter, schema2, { auth })));
14500
+ return Promise.all(filters2.map((filter) => sanitizeFilters(filter, schema2, {
14501
+ auth
14502
+ })));
14280
14503
  }
14281
- const transforms = [defaultSanitizeFilters({ schema: schema2, getModel })];
14504
+ const transforms = [
14505
+ defaultSanitizeFilters({
14506
+ schema: schema2,
14507
+ getModel
14508
+ })
14509
+ ];
14282
14510
  if (auth) {
14283
- transforms.push(
14284
- traverseQueryFilters(removeRestrictedRelations(auth), { schema: schema2, getModel })
14285
- );
14511
+ transforms.push(traverseQueryFilters(removeRestrictedRelations(auth), {
14512
+ schema: schema2,
14513
+ getModel
14514
+ }));
14286
14515
  }
14287
14516
  return pipe(...transforms)(filters2);
14288
14517
  };
@@ -14290,11 +14519,17 @@ const createAPISanitizers = (opts) => {
14290
14519
  if (!schema2) {
14291
14520
  throw new Error("Missing schema in sanitizeSort");
14292
14521
  }
14293
- const transforms = [defaultSanitizeSort({ schema: schema2, getModel })];
14522
+ const transforms = [
14523
+ defaultSanitizeSort({
14524
+ schema: schema2,
14525
+ getModel
14526
+ })
14527
+ ];
14294
14528
  if (auth) {
14295
- transforms.push(
14296
- traverseQuerySort(removeRestrictedRelations(auth), { schema: schema2, getModel })
14297
- );
14529
+ transforms.push(traverseQuerySort(removeRestrictedRelations(auth), {
14530
+ schema: schema2,
14531
+ getModel
14532
+ }));
14298
14533
  }
14299
14534
  return pipe(...transforms)(sort2);
14300
14535
  };
@@ -14302,18 +14537,29 @@ const createAPISanitizers = (opts) => {
14302
14537
  if (!schema2) {
14303
14538
  throw new Error("Missing schema in sanitizeFields");
14304
14539
  }
14305
- const transforms = [defaultSanitizeFields({ schema: schema2, getModel })];
14540
+ const transforms = [
14541
+ defaultSanitizeFields({
14542
+ schema: schema2,
14543
+ getModel
14544
+ })
14545
+ ];
14306
14546
  return pipe(...transforms)(fields2);
14307
14547
  };
14308
14548
  const sanitizePopulate = (populate2, schema2, { auth } = {}) => {
14309
14549
  if (!schema2) {
14310
14550
  throw new Error("Missing schema in sanitizePopulate");
14311
14551
  }
14312
- const transforms = [defaultSanitizePopulate({ schema: schema2, getModel })];
14552
+ const transforms = [
14553
+ defaultSanitizePopulate({
14554
+ schema: schema2,
14555
+ getModel
14556
+ })
14557
+ ];
14313
14558
  if (auth) {
14314
- transforms.push(
14315
- traverseQueryPopulate(removeRestrictedRelations(auth), { schema: schema2, getModel })
14316
- );
14559
+ transforms.push(traverseQueryPopulate(removeRestrictedRelations(auth), {
14560
+ schema: schema2,
14561
+ getModel
14562
+ }));
14317
14563
  }
14318
14564
  return pipe(...transforms)(populate2);
14319
14565
  };
@@ -14327,13 +14573,16 @@ const createAPISanitizers = (opts) => {
14327
14573
  populate: sanitizePopulate
14328
14574
  };
14329
14575
  };
14330
- const index$2 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
14576
+ var index$2 = /* @__PURE__ */ Object.freeze({
14331
14577
  __proto__: null,
14332
14578
  createAPISanitizers,
14333
14579
  sanitizers,
14334
14580
  visitors: index$4
14335
- }, Symbol.toStringTag, { value: "Module" }));
14336
- [constants$1.DOC_ID_ATTRIBUTE, constants$1.DOC_ID_ATTRIBUTE];
14581
+ });
14582
+ [
14583
+ constants$1.DOC_ID_ATTRIBUTE,
14584
+ constants$1.DOC_ID_ATTRIBUTE
14585
+ ];
14337
14586
  const isCamelCase = (value) => /^[a-z][a-zA-Z0-9]+$/.test(value);
14338
14587
  const isKebabCase = (value) => /^([a-z][a-z0-9]*)(-[a-z0-9]+)*$/.test(value);
14339
14588
  const { toString: toString3 } = Object.prototype;
@@ -14364,15 +14613,11 @@ function printSimpleValue(val, quoteStrings = false) {
14364
14613
  function printValue(value, quoteStrings) {
14365
14614
  const result = printSimpleValue(value, quoteStrings);
14366
14615
  if (result !== null) return result;
14367
- return JSON.stringify(
14368
- value,
14369
- function replacer(key, value2) {
14370
- const result2 = printSimpleValue(this[key], quoteStrings);
14371
- if (result2 !== null) return result2;
14372
- return value2;
14373
- },
14374
- 2
14375
- );
14616
+ return JSON.stringify(value, function replacer(key, value2) {
14617
+ const result2 = printSimpleValue(this[key], quoteStrings);
14618
+ if (result2 !== null) return result2;
14619
+ return value2;
14620
+ }, 2);
14376
14621
  }
14377
14622
  const isNotNilTest = (value) => !___default.isNil(value);
14378
14623
  const isNotNullTest = (value) => !___default.isNull(value);
@@ -14383,71 +14628,35 @@ addMethod(create$3, "notNull", function isNotNull(msg = "${path} cannot be null.
14383
14628
  return this.test("defined", msg, isNotNullTest);
14384
14629
  });
14385
14630
  addMethod(create$3, "isFunction", function isFunction2(message = "${path} is not a function") {
14386
- return this.test(
14387
- "is a function",
14388
- message,
14389
- (value) => ___default.isUndefined(value) || ___default.isFunction(value)
14390
- );
14631
+ return this.test("is a function", message, (value) => ___default.isUndefined(value) || ___default.isFunction(value));
14391
14632
  });
14392
- addMethod(
14393
- create$2,
14394
- "isCamelCase",
14395
- function isCamelCase$1(message = "${path} is not in camel case (anExampleOfCamelCase)") {
14396
- return this.test(
14397
- "is in camelCase",
14398
- message,
14399
- (value) => value ? isCamelCase(value) : true
14400
- );
14401
- }
14402
- );
14403
- addMethod(
14404
- create$2,
14405
- "isKebabCase",
14406
- function isKebabCase$1(message = "${path} is not in kebab case (an-example-of-kebab-case)") {
14407
- return this.test(
14408
- "is in kebab-case",
14409
- message,
14410
- (value) => value ? isKebabCase(value) : true
14411
- );
14412
- }
14413
- );
14414
- addMethod(
14415
- create$1,
14416
- "onlyContainsFunctions",
14417
- function onlyContainsFunctions(message = "${path} contains values that are not functions") {
14418
- return this.test(
14419
- "only contains functions",
14420
- message,
14421
- (value) => ___default.isUndefined(value) || value && Object.values(value).every(___default.isFunction)
14422
- );
14423
- }
14424
- );
14425
- addMethod(
14426
- create,
14427
- "uniqueProperty",
14428
- function uniqueProperty(propertyName, message) {
14429
- return this.test("unique", message, function unique(list) {
14430
- const errors2 = [];
14431
- list?.forEach((element, index2) => {
14432
- const sameElements = list.filter(
14433
- (e) => get(propertyName, e) === get(propertyName, element)
14434
- );
14435
- if (sameElements.length > 1) {
14436
- errors2.push(
14437
- this.createError({
14438
- path: `${this.path}[${index2}].${propertyName}`,
14439
- message
14440
- })
14441
- );
14442
- }
14443
- });
14444
- if (errors2.length) {
14445
- throw new ValidationError(errors2);
14633
+ addMethod(create$2, "isCamelCase", function isCamelCase$1(message = "${path} is not in camel case (anExampleOfCamelCase)") {
14634
+ return this.test("is in camelCase", message, (value) => value ? isCamelCase(value) : true);
14635
+ });
14636
+ addMethod(create$2, "isKebabCase", function isKebabCase$1(message = "${path} is not in kebab case (an-example-of-kebab-case)") {
14637
+ return this.test("is in kebab-case", message, (value) => value ? isKebabCase(value) : true);
14638
+ });
14639
+ addMethod(create$1, "onlyContainsFunctions", function onlyContainsFunctions(message = "${path} contains values that are not functions") {
14640
+ return this.test("only contains functions", message, (value) => ___default.isUndefined(value) || value && Object.values(value).every(___default.isFunction));
14641
+ });
14642
+ addMethod(create, "uniqueProperty", function uniqueProperty(propertyName, message) {
14643
+ return this.test("unique", message, function unique(list) {
14644
+ const errors = [];
14645
+ list?.forEach((element, index2) => {
14646
+ const sameElements = list.filter((e) => get(propertyName, e) === get(propertyName, element));
14647
+ if (sameElements.length > 1) {
14648
+ errors.push(this.createError({
14649
+ path: `${this.path}[${index2}].${propertyName}`,
14650
+ message
14651
+ }));
14446
14652
  }
14447
- return true;
14448
14653
  });
14449
- }
14450
- );
14654
+ if (errors.length) {
14655
+ throw new ValidationError(errors);
14656
+ }
14657
+ return true;
14658
+ });
14659
+ });
14451
14660
  setLocale({
14452
14661
  mixed: {
14453
14662
  notType(options) {
@@ -14520,6 +14729,7 @@ const populateIsWildcardEquivalent = async ({
14520
14729
  schema: schema2,
14521
14730
  populate: populate2
14522
14731
  }) => {
14732
+ if (isEmpty$1(populate2)) return false;
14523
14733
  const expandedWildcardQuery = await index$2.sanitizers.defaultSanitizePopulate(
14524
14734
  {
14525
14735
  schema: schema2,
@@ -14553,6 +14763,7 @@ const register = async ({ strapi: strapi2 }) => {
14553
14763
  const cacheService = strapi2.plugin("deep-populate").service("cache");
14554
14764
  const { populate: populate2 } = context.params;
14555
14765
  const returnDeeplyPopulated = replaceWildcard && await populateIsWildcardEquivalent({ strapi: strapi2, schema: context.contentType, populate: populate2 });
14766
+ if (has(populate2, "__deepPopulated")) unset(populate2, "__deepPopulated");
14556
14767
  if (useCache && context.action === "delete")
14557
14768
  await cacheService.clear({ ...context.params, contentType: context.uid });
14558
14769
  const originalFields = cloneDeep$1(context.fields);
@@ -14561,7 +14772,8 @@ const register = async ({ strapi: strapi2 }) => {
14561
14772
  const result = await next();
14562
14773
  if (!result) return result;
14563
14774
  if (["create", "update"].includes(context.action)) {
14564
- const { documentId, status: status2, locale: locale2 } = result;
14775
+ const { documentId, publishedAt, locale: locale2 } = result;
14776
+ const status2 = publishedAt !== null ? "published" : "draft";
14565
14777
  if (useCache && context.action === "update")
14566
14778
  await cacheService.clear({ ...context.params, contentType: context.uid });
14567
14779
  if (useCache || returnDeeplyPopulated) {
@@ -14571,13 +14783,15 @@ const register = async ({ strapi: strapi2 }) => {
14571
14783
  }
14572
14784
  }
14573
14785
  if (returnDeeplyPopulated && ["findOne", "findFirst"].includes(context.action)) {
14574
- const { documentId, status: status2, locale: locale2 } = result;
14786
+ const { documentId, publishedAt, locale: locale2 } = result;
14787
+ const status2 = publishedAt !== null ? "published" : "draft";
14575
14788
  const deepPopulate = await populateService.get({ contentType: context.uid, documentId, status: status2, locale: locale2 });
14576
14789
  return await strapi2.documents(context.uid).findOne({ documentId, status: status2, locale: locale2, fields: originalFields, populate: deepPopulate });
14577
14790
  }
14578
14791
  if (returnDeeplyPopulated && context.action === "findMany") {
14579
14792
  return await Promise.all(
14580
- result.map(async ({ documentId, status: status2, locale: locale2 }) => {
14793
+ result.map(async ({ documentId, publishedAt, locale: locale2 }) => {
14794
+ const status2 = publishedAt !== null ? "published" : "draft";
14581
14795
  const deepPopulate = await populateService.get({ contentType: context.uid, documentId, status: status2, locale: locale2 });
14582
14796
  return await strapi2.documents(context.uid).findOne({ documentId, status: status2, locale: locale2, fields: originalFields, populate: deepPopulate });
14583
14797
  })
@@ -14589,10 +14803,13 @@ const register = async ({ strapi: strapi2 }) => {
14589
14803
  const getHash = (params) => {
14590
14804
  return `${params.contentType}-${params.documentId}-${params.locale}-${params.status}-${params.omitEmpty ? "sparse" : "full"}-${params.localizations ? "all" : "single"}`;
14591
14805
  };
14806
+ const isValid = (entry) => {
14807
+ return entry && !isEmpty$1(entry.populate) && has(entry.populate, "__deepPopulated");
14808
+ };
14592
14809
  const cache = ({ strapi: strapi2 }) => ({
14593
14810
  async get(params) {
14594
14811
  const entry = await strapi2.documents("plugin::deep-populate.cache").findFirst({ filters: { hash: { $eq: getHash(params) } } });
14595
- return entry && !isEmpty$1(entry.populate) ? entry.populate : null;
14812
+ return isValid(entry) ? entry.populate : null;
14596
14813
  },
14597
14814
  async set({ populate: populate2, dependencies, ...params }) {
14598
14815
  const documentService = strapi2.documents("plugin::deep-populate.cache");
@@ -14631,6 +14848,11 @@ const cache = ({ strapi: strapi2 }) => ({
14631
14848
  const getRelations = (model) => {
14632
14849
  const filteredAttributes = /* @__PURE__ */ new Set();
14633
14850
  const { populateCreatorFields } = contentTypes.getOptions(model);
14851
+ const { pluginOptions } = model;
14852
+ if (pluginOptions?.i18n?.localized !== true) {
14853
+ filteredAttributes.add("locale");
14854
+ filteredAttributes.add("localizations");
14855
+ }
14634
14856
  if (!populateCreatorFields) {
14635
14857
  filteredAttributes.add(contentTypes.constants.CREATED_BY_ATTRIBUTE);
14636
14858
  filteredAttributes.add(contentTypes.constants.UPDATED_BY_ATTRIBUTE);
@@ -14886,6 +15108,7 @@ async function populate$1(params) {
14886
15108
  __deny: deny,
14887
15109
  __allow: allow
14888
15110
  });
15111
+ populated.__deepPopulated = true;
14889
15112
  return { populate: populated, dependencies: [...resolvedRelations.keys()] };
14890
15113
  }
14891
15114
  const populate = ({ strapi: strapi2 }) => ({