@strapi/utils 4.2.0-beta.0 → 4.2.0-beta.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/hooks.js CHANGED
@@ -20,17 +20,19 @@ const createHook = () => {
20
20
  };
21
21
 
22
22
  return {
23
- get handlers() {
23
+ getHandlers() {
24
24
  return state.handlers;
25
25
  },
26
26
 
27
27
  register(handler) {
28
28
  state.handlers.push(handler);
29
+
29
30
  return this;
30
31
  },
31
32
 
32
33
  delete(handler) {
33
34
  state.handlers = remove(eq(handler), state.handlers);
35
+
34
36
  return this;
35
37
  },
36
38
 
@@ -49,7 +51,7 @@ const createAsyncSeriesHook = () => ({
49
51
  ...createHook(),
50
52
 
51
53
  async call(context) {
52
- for (const handler of this.handlers) {
54
+ for (const handler of this.getHandlers()) {
53
55
  await handler(context);
54
56
  }
55
57
  },
@@ -66,7 +68,7 @@ const createAsyncSeriesWaterfallHook = () => ({
66
68
  async call(param) {
67
69
  let res = param;
68
70
 
69
- for (const handler of this.handlers) {
71
+ for (const handler of this.getHandlers()) {
70
72
  res = await handler(res);
71
73
  }
72
74
 
@@ -83,7 +85,7 @@ const createAsyncParallelHook = () => ({
83
85
  ...createHook(),
84
86
 
85
87
  async call(context) {
86
- const promises = this.handlers.map(handler => handler(cloneDeep(context)));
88
+ const promises = this.getHandlers().map(handler => handler(cloneDeep(context)));
87
89
 
88
90
  return Promise.all(promises);
89
91
  },
package/lib/index.js CHANGED
@@ -21,6 +21,8 @@ const {
21
21
  isCamelCase,
22
22
  toRegressedEnumValue,
23
23
  startsWithANumber,
24
+ joinBy,
25
+ toKebabCase,
24
26
  } = require('./string-formatting');
25
27
  const { removeUndefined } = require('./object-formatting');
26
28
  const { getConfigUrls, getAbsoluteAdminUrl, getAbsoluteServerUrl } = require('./config');
@@ -51,6 +53,7 @@ module.exports = {
51
53
  nameToSlug,
52
54
  toRegressedEnumValue,
53
55
  startsWithANumber,
56
+ joinBy,
54
57
  nameToCollectionName,
55
58
  getCommonBeginning,
56
59
  getConfigUrls,
@@ -63,6 +66,7 @@ module.exports = {
63
66
  stringEquals,
64
67
  isKebabCase,
65
68
  isCamelCase,
69
+ toKebabCase,
66
70
  contentTypes,
67
71
  webhook,
68
72
  env,
package/lib/pagination.js CHANGED
@@ -47,10 +47,7 @@ const withDefaultPagination = (args, { defaults = {}, maxLimit = -1 } = {}) => {
47
47
  const usePagePagination = !isNil(args.page) || !isNil(args.pageSize);
48
48
  const useOffsetPagination = !isNil(args.start) || !isNil(args.limit);
49
49
 
50
- const ensureValidValues = pipe(
51
- ensureMinValues,
52
- ensureMaxValues(maxLimit)
53
- );
50
+ const ensureValidValues = pipe(ensureMinValues, ensureMaxValues(maxLimit));
54
51
 
55
52
  // If there is no pagination attribute, don't modify the payload
56
53
  if (!usePagePagination && !useOffsetPagination) {
@@ -28,6 +28,11 @@ module.exports = {
28
28
  transforms.push(traverseEntity(visitors.removeRestrictedRelations(auth), { schema }));
29
29
  }
30
30
 
31
+ // Apply sanitizers from registry if exists
32
+ strapi.sanitizers
33
+ .get('content-api.input')
34
+ .forEach(sanitizer => transforms.push(sanitizer(schema)));
35
+
31
36
  return pipeAsync(...transforms)(data);
32
37
  },
33
38
 
@@ -42,6 +47,11 @@ module.exports = {
42
47
  transforms.push(traverseEntity(visitors.removeRestrictedRelations(auth), { schema }));
43
48
  }
44
49
 
50
+ // Apply sanitizers from registry if exists
51
+ strapi.sanitizers
52
+ .get('content-api.output')
53
+ .forEach(sanitizer => transforms.push(sanitizer(schema)));
54
+
45
55
  return pipeAsync(...transforms)(data);
46
56
  },
47
57
  },
@@ -1,6 +1,8 @@
1
1
  'use strict';
2
2
  const _ = require('lodash');
3
+ const { trimChars, trimCharsEnd, trimCharsStart } = require('lodash/fp');
3
4
  const slugify = require('@sindresorhus/slugify');
5
+ const { kebabCase } = require('lodash');
4
6
 
5
7
  const nameToSlug = (name, options = { separator: '-' }) => slugify(name, options);
6
8
 
@@ -44,6 +46,21 @@ const isCamelCase = value => /^[a-z][a-zA-Z0-9]+$/.test(value);
44
46
  const isKebabCase = value => /^([a-z][a-z0-9]*)(-[a-z0-9]+)*$/.test(value);
45
47
  const startsWithANumber = value => /^[0-9]/.test(value);
46
48
 
49
+ const joinBy = (joint, ...args) => {
50
+ const trim = trimChars(joint);
51
+ const trimEnd = trimCharsEnd(joint);
52
+ const trimStart = trimCharsStart(joint);
53
+
54
+ return args.reduce((url, path, index) => {
55
+ if (args.length === 1) return path;
56
+ if (index === 0) return trimEnd(path);
57
+ if (index === args.length - 1) return url + joint + trimStart(path);
58
+ return url + joint + trim(path);
59
+ }, '');
60
+ };
61
+
62
+ const toKebabCase = value => kebabCase(value);
63
+
47
64
  module.exports = {
48
65
  nameToSlug,
49
66
  nameToCollectionName,
@@ -54,6 +71,8 @@ module.exports = {
54
71
  stringEquals,
55
72
  isCamelCase,
56
73
  isKebabCase,
74
+ toKebabCase,
57
75
  toRegressedEnumValue,
58
76
  startsWithANumber,
77
+ joinBy,
59
78
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/utils",
3
- "version": "4.2.0-beta.0",
3
+ "version": "4.2.0-beta.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": "db70f0de7cc73fb469c8a076b89530729cf14142"
48
+ "gitHead": "c4addbad6ecbc8ef7633bbba3806f3b0a2ae5f49"
49
49
  }