@strapi/utils 4.1.2 → 4.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -19,6 +19,8 @@ const {
19
19
  stringEquals,
20
20
  isKebabCase,
21
21
  isCamelCase,
22
+ toRegressedEnumValue,
23
+ startsWithANumber,
22
24
  } = require('./string-formatting');
23
25
  const { removeUndefined } = require('./object-formatting');
24
26
  const { getConfigUrls, getAbsoluteAdminUrl, getAbsoluteServerUrl } = require('./config');
@@ -47,6 +49,8 @@ module.exports = {
47
49
  traverseEntity,
48
50
  parseType,
49
51
  nameToSlug,
52
+ toRegressedEnumValue,
53
+ startsWithANumber,
50
54
  nameToCollectionName,
51
55
  getCommonBeginning,
52
56
  getConfigUrls,
@@ -2,6 +2,7 @@
2
2
 
3
3
  const ACTIONS_TO_VERIFY = ['find'];
4
4
 
5
+ // FIXME: Support populating creator fields
5
6
  module.exports = auth => async ({ data, key, attribute }, { remove, set }) => {
6
7
  const isRelation = attribute.type === 'relation';
7
8
 
@@ -6,6 +6,13 @@ const nameToSlug = (name, options = { separator: '-' }) => slugify(name, options
6
6
 
7
7
  const nameToCollectionName = name => slugify(name, { separator: '_' });
8
8
 
9
+ const toRegressedEnumValue = value =>
10
+ slugify(value, {
11
+ decamelize: false,
12
+ lowercase: false,
13
+ separator: '_',
14
+ });
15
+
9
16
  const getCommonBeginning = (...strings) =>
10
17
  _.takeWhile(strings[0], (char, index) => strings.every(string => string[index] === char)).join(
11
18
  ''
@@ -35,6 +42,7 @@ const stringIncludes = (arr, val) => arr.map(String).includes(String(val));
35
42
  const stringEquals = (a, b) => String(a) === String(b);
36
43
  const isCamelCase = value => /^[a-z][a-zA-Z0-9]+$/.test(value);
37
44
  const isKebabCase = value => /^([a-z][a-z0-9]*)(-[a-z0-9]+)*$/.test(value);
45
+ const startsWithANumber = value => /^[0-9]/.test(value);
38
46
 
39
47
  module.exports = {
40
48
  nameToSlug,
@@ -46,4 +54,6 @@ module.exports = {
46
54
  stringEquals,
47
55
  isCamelCase,
48
56
  isKebabCase,
57
+ toRegressedEnumValue,
58
+ startsWithANumber,
49
59
  };
@@ -41,6 +41,7 @@ const traverseEntity = async (visitor, options, entity) => {
41
41
  const isRelation = attribute.type === 'relation';
42
42
  const isComponent = attribute.type === 'component';
43
43
  const isDynamicZone = attribute.type === 'dynamiczone';
44
+ const isMedia = attribute.type === 'media';
44
45
 
45
46
  if (isRelation) {
46
47
  const isMorphRelation = attribute.relation.toLowerCase().startsWith('morph');
@@ -61,6 +62,22 @@ const traverseEntity = async (visitor, options, entity) => {
61
62
  : await traverseTarget(value);
62
63
  }
63
64
 
65
+ if (isMedia) {
66
+ const traverseTarget = entry => {
67
+ const targetSchemaUID = 'plugin::upload.file';
68
+ const targetSchema = strapi.getModel(targetSchemaUID);
69
+
70
+ const traverseOptions = { schema: targetSchema, path: newPath };
71
+
72
+ return traverseEntity(visitor, traverseOptions, entry);
73
+ };
74
+
75
+ // need to update copy
76
+ copy[key] = isArray(value)
77
+ ? await Promise.all(value.map(traverseTarget))
78
+ : await traverseTarget(value);
79
+ }
80
+
64
81
  if (isComponent) {
65
82
  const targetSchema = strapi.getModel(attribute.component);
66
83
  const traverseOptions = { schema: targetSchema, path: newPath };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/utils",
3
- "version": "4.1.2",
3
+ "version": "4.1.3",
4
4
  "description": "Shared utilities for the Strapi packages",
5
5
  "keywords": [
6
6
  "strapi",
@@ -45,5 +45,5 @@
45
45
  "node": ">=12.22.0 <=16.x.x",
46
46
  "npm": ">=6.0.0"
47
47
  },
48
- "gitHead": "6f72c3805232bc6c4b229aecfb19909b9f68d98d"
48
+ "gitHead": "8549f5aca34f2a72bb477a1b305260f39f271f4e"
49
49
  }