@strapi/utils 4.11.3 → 4.12.0-beta.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.
Files changed (184) hide show
  1. package/dist/async.d.ts +10 -0
  2. package/dist/async.js +33 -0
  3. package/dist/async.js.map +1 -0
  4. package/dist/code-generator.d.ts +2 -0
  5. package/dist/code-generator.js +11 -0
  6. package/dist/code-generator.js.map +1 -0
  7. package/dist/config.d.ts +8 -0
  8. package/dist/config.js +79 -0
  9. package/dist/config.js.map +1 -0
  10. package/dist/content-types.d.ts +60 -0
  11. package/dist/content-types.js +151 -0
  12. package/dist/content-types.js.map +1 -0
  13. package/dist/convert-query-params.d.ts +75 -0
  14. package/dist/convert-query-params.js +476 -0
  15. package/dist/convert-query-params.js.map +1 -0
  16. package/dist/env-helper.d.ts +18 -0
  17. package/dist/env-helper.js +84 -0
  18. package/dist/env-helper.js.map +1 -0
  19. package/dist/errors.d.ts +37 -0
  20. package/dist/errors.js +100 -0
  21. package/dist/errors.js.map +1 -0
  22. package/dist/file.d.ts +16 -0
  23. package/dist/file.js +54 -0
  24. package/dist/file.js.map +1 -0
  25. package/dist/format-yup-error.d.ts +10 -0
  26. package/dist/format-yup-error.js +17 -0
  27. package/dist/format-yup-error.js.map +1 -0
  28. package/dist/hooks.d.ts +63 -0
  29. package/dist/hooks.js +89 -0
  30. package/dist/hooks.js.map +1 -0
  31. package/dist/import-default.d.ts +1 -0
  32. package/dist/import-default.js +9 -0
  33. package/dist/import-default.js.map +1 -0
  34. package/dist/index.d.ts +30 -0
  35. package/dist/index.js +99 -0
  36. package/dist/index.js.map +1 -0
  37. package/dist/object-formatting.d.ts +3 -0
  38. package/dist/object-formatting.js +14 -0
  39. package/dist/object-formatting.js.map +1 -0
  40. package/dist/operators.d.ts +2 -0
  41. package/dist/operators.js +70 -0
  42. package/dist/operators.js.map +1 -0
  43. package/dist/pagination.d.ts +14 -0
  44. package/dist/pagination.js +80 -0
  45. package/dist/pagination.js.map +1 -0
  46. package/dist/parse-multipart.d.ts +8 -0
  47. package/dist/parse-multipart.js +36 -0
  48. package/dist/parse-multipart.js.map +1 -0
  49. package/dist/parse-type.d.ts +21 -0
  50. package/dist/parse-type.js +108 -0
  51. package/dist/parse-type.js.map +1 -0
  52. package/dist/policy.d.ts +41 -0
  53. package/dist/policy.js +109 -0
  54. package/dist/policy.js.map +1 -0
  55. package/dist/print-value.d.ts +2 -0
  56. package/dist/print-value.js +50 -0
  57. package/dist/print-value.js.map +1 -0
  58. package/dist/provider-factory.d.ts +29 -0
  59. package/dist/provider-factory.js +80 -0
  60. package/dist/provider-factory.js.map +1 -0
  61. package/dist/relations.d.ts +10 -0
  62. package/dist/relations.js +23 -0
  63. package/dist/relations.js.map +1 -0
  64. package/dist/sanitize/index.d.ts +23 -0
  65. package/dist/sanitize/index.js +135 -0
  66. package/dist/sanitize/index.js.map +1 -0
  67. package/dist/sanitize/sanitizers.d.ts +10 -0
  68. package/dist/sanitize/sanitizers.js +114 -0
  69. package/dist/sanitize/sanitizers.js.map +1 -0
  70. package/dist/sanitize/visitors/allowed-fields.d.ts +3 -0
  71. package/{lib → dist}/sanitize/visitors/allowed-fields.js +17 -32
  72. package/dist/sanitize/visitors/allowed-fields.js.map +1 -0
  73. package/dist/sanitize/visitors/index.d.ts +7 -0
  74. package/dist/sanitize/visitors/index.js +21 -0
  75. package/dist/sanitize/visitors/index.js.map +1 -0
  76. package/dist/sanitize/visitors/remove-dynamic-zones.d.ts +3 -0
  77. package/dist/sanitize/visitors/remove-dynamic-zones.js +10 -0
  78. package/dist/sanitize/visitors/remove-dynamic-zones.js.map +1 -0
  79. package/dist/sanitize/visitors/remove-morph-to-relations.d.ts +3 -0
  80. package/dist/sanitize/visitors/remove-morph-to-relations.js +10 -0
  81. package/dist/sanitize/visitors/remove-morph-to-relations.js.map +1 -0
  82. package/dist/sanitize/visitors/remove-password.d.ts +3 -0
  83. package/dist/sanitize/visitors/remove-password.js +9 -0
  84. package/dist/sanitize/visitors/remove-password.js.map +1 -0
  85. package/dist/sanitize/visitors/remove-private.d.ts +3 -0
  86. package/dist/sanitize/visitors/remove-private.js +14 -0
  87. package/dist/sanitize/visitors/remove-private.js.map +1 -0
  88. package/dist/sanitize/visitors/remove-restricted-relations.d.ts +3 -0
  89. package/dist/sanitize/visitors/remove-restricted-relations.js +88 -0
  90. package/dist/sanitize/visitors/remove-restricted-relations.js.map +1 -0
  91. package/dist/sanitize/visitors/restricted-fields.d.ts +3 -0
  92. package/dist/sanitize/visitors/restricted-fields.js +25 -0
  93. package/dist/sanitize/visitors/restricted-fields.js.map +1 -0
  94. package/dist/set-creator-fields.d.ts +9 -0
  95. package/dist/set-creator-fields.js +39 -0
  96. package/dist/set-creator-fields.js.map +1 -0
  97. package/dist/string-formatting.d.ts +15 -0
  98. package/dist/string-formatting.js +85 -0
  99. package/dist/string-formatting.js.map +1 -0
  100. package/dist/template-configuration.d.ts +5 -0
  101. package/dist/template-configuration.js +30 -0
  102. package/dist/template-configuration.js.map +1 -0
  103. package/dist/template.d.ts +9 -0
  104. package/dist/template.js +20 -0
  105. package/dist/template.js.map +1 -0
  106. package/dist/traverse/factory.d.ts +78 -0
  107. package/dist/traverse/factory.js +127 -0
  108. package/dist/traverse/factory.js.map +1 -0
  109. package/dist/traverse/index.d.ts +5 -0
  110. package/dist/traverse/index.js +17 -0
  111. package/dist/traverse/index.js.map +1 -0
  112. package/dist/traverse/query-fields.d.ts +3 -0
  113. package/dist/traverse/query-fields.js +35 -0
  114. package/dist/traverse/query-fields.js.map +1 -0
  115. package/dist/traverse/query-filters.d.ts +3 -0
  116. package/dist/traverse/query-filters.js +75 -0
  117. package/dist/traverse/query-filters.js.map +1 -0
  118. package/dist/traverse/query-populate.d.ts +3 -0
  119. package/dist/traverse/query-populate.js +144 -0
  120. package/dist/traverse/query-populate.js.map +1 -0
  121. package/dist/traverse/query-sort.d.ts +3 -0
  122. package/dist/traverse/query-sort.js +116 -0
  123. package/dist/traverse/query-sort.js.map +1 -0
  124. package/dist/traverse-entity.d.ts +31 -0
  125. package/dist/traverse-entity.js +134 -0
  126. package/dist/traverse-entity.js.map +1 -0
  127. package/dist/types.d.ts +65 -0
  128. package/dist/types.js +3 -0
  129. package/dist/types.js.map +1 -0
  130. package/dist/validators.d.ts +13 -0
  131. package/dist/validators.js +120 -0
  132. package/dist/validators.js.map +1 -0
  133. package/dist/webhook.d.ts +5 -0
  134. package/dist/webhook.js +27 -0
  135. package/dist/webhook.js.map +1 -0
  136. package/package.json +19 -4
  137. package/.eslintignore +0 -3
  138. package/.eslintrc.js +0 -4
  139. package/index.d.ts +0 -5
  140. package/lib/async.d.ts +0 -21
  141. package/lib/async.js +0 -45
  142. package/lib/build-query.js +0 -208
  143. package/lib/code-generator.js +0 -13
  144. package/lib/config.js +0 -88
  145. package/lib/content-types.js +0 -196
  146. package/lib/convert-query-params.js +0 -586
  147. package/lib/env-helper.js +0 -98
  148. package/lib/errors.js +0 -113
  149. package/lib/file.js +0 -60
  150. package/lib/format-yup-error.js +0 -20
  151. package/lib/hooks.js +0 -110
  152. package/lib/import-default.js +0 -10
  153. package/lib/index.js +0 -99
  154. package/lib/object-formatting.js +0 -15
  155. package/lib/operators.js +0 -74
  156. package/lib/pagination.js +0 -99
  157. package/lib/parse-multipart.js +0 -44
  158. package/lib/parse-type.js +0 -100
  159. package/lib/policy.js +0 -129
  160. package/lib/print-value.js +0 -52
  161. package/lib/provider-factory.js +0 -116
  162. package/lib/relations.js +0 -31
  163. package/lib/sanitize/index.js +0 -143
  164. package/lib/sanitize/sanitizers.js +0 -163
  165. package/lib/sanitize/visitors/index.js +0 -11
  166. package/lib/sanitize/visitors/remove-dynamic-zones.js +0 -9
  167. package/lib/sanitize/visitors/remove-morph-to-relations.js +0 -9
  168. package/lib/sanitize/visitors/remove-password.js +0 -7
  169. package/lib/sanitize/visitors/remove-private.js +0 -15
  170. package/lib/sanitize/visitors/remove-restricted-relations.js +0 -81
  171. package/lib/sanitize/visitors/restricted-fields.js +0 -32
  172. package/lib/set-creator-fields.js +0 -17
  173. package/lib/string-formatting.js +0 -79
  174. package/lib/template-configuration.js +0 -32
  175. package/lib/template.js +0 -28
  176. package/lib/traverse/factory.js +0 -157
  177. package/lib/traverse/index.js +0 -16
  178. package/lib/traverse/query-fields.js +0 -39
  179. package/lib/traverse/query-filters.js +0 -97
  180. package/lib/traverse/query-populate.js +0 -191
  181. package/lib/traverse/query-sort.js +0 -171
  182. package/lib/traverse-entity.js +0 -166
  183. package/lib/validators.js +0 -120
  184. package/lib/webhook.js +0 -30
package/lib/validators.js DELETED
@@ -1,120 +0,0 @@
1
- 'use strict';
2
-
3
- const yup = require('yup');
4
- const _ = require('lodash');
5
- const { defaults } = require('lodash/fp');
6
- const utils = require('./string-formatting');
7
- const { YupValidationError } = require('./errors');
8
- const printValue = require('./print-value');
9
-
10
- const MixedSchemaType = yup.MixedSchema;
11
-
12
- const isNotNilTest = (value) => !_.isNil(value);
13
-
14
- function isNotNill(msg = '${path} must be defined.') {
15
- return this.test('defined', msg, isNotNilTest);
16
- }
17
-
18
- const isNotNullTest = (value) => !_.isNull(value);
19
- function isNotNull(msg = '${path} cannot be null.') {
20
- return this.test('defined', msg, isNotNullTest);
21
- }
22
-
23
- function isFunction(message = '${path} is not a function') {
24
- return this.test(
25
- 'is a function',
26
- message,
27
- (value) => _.isUndefined(value) || _.isFunction(value)
28
- );
29
- }
30
-
31
- function isCamelCase(message = '${path} is not in camel case (anExampleOfCamelCase)') {
32
- return this.test('is in camelCase', message, (value) => utils.isCamelCase(value));
33
- }
34
-
35
- function isKebabCase(message = '${path} is not in kebab case (an-example-of-kebab-case)') {
36
- return this.test('is in kebab-case', message, (value) => utils.isKebabCase(value));
37
- }
38
-
39
- function onlyContainsFunctions(message = '${path} contains values that are not functions') {
40
- return this.test(
41
- 'only contains functions',
42
- message,
43
- (value) => _.isUndefined(value) || (value && Object.values(value).every(_.isFunction))
44
- );
45
- }
46
-
47
- yup.addMethod(yup.mixed, 'notNil', isNotNill);
48
- yup.addMethod(yup.mixed, 'notNull', isNotNull);
49
- yup.addMethod(yup.mixed, 'isFunction', isFunction);
50
- yup.addMethod(yup.string, 'isCamelCase', isCamelCase);
51
- yup.addMethod(yup.string, 'isKebabCase', isKebabCase);
52
- yup.addMethod(yup.object, 'onlyContainsFunctions', onlyContainsFunctions);
53
-
54
- class StrapiIDSchema extends MixedSchemaType {
55
- constructor() {
56
- super({ type: 'strapiID' });
57
- }
58
-
59
- _typeCheck(value) {
60
- return typeof value === 'string' || (Number.isInteger(value) && value >= 0);
61
- }
62
- }
63
-
64
- yup.strapiID = () => new StrapiIDSchema();
65
-
66
- const handleYupError = (error, errorMessage) => {
67
- throw new YupValidationError(error, errorMessage);
68
- };
69
-
70
- const defaultValidationParam = { strict: true, abortEarly: false };
71
-
72
- const validateYupSchema =
73
- (schema, options = {}) =>
74
- async (body, errorMessage) => {
75
- try {
76
- const optionsWithDefaults = defaults(defaultValidationParam, options);
77
- return await schema.validate(body, optionsWithDefaults);
78
- } catch (e) {
79
- handleYupError(e, errorMessage);
80
- }
81
- };
82
-
83
- const validateYupSchemaSync =
84
- (schema, options = {}) =>
85
- (body, errorMessage) => {
86
- try {
87
- const optionsWithDefaults = defaults(defaultValidationParam, options);
88
- return schema.validateSync(body, optionsWithDefaults);
89
- } catch (e) {
90
- handleYupError(e, errorMessage);
91
- }
92
- };
93
-
94
- // Temporary fix of this issue : https://github.com/jquense/yup/issues/616
95
- yup.setLocale({
96
- mixed: {
97
- notType({ path, type, value, originalValue }) {
98
- const isCast = originalValue != null && originalValue !== value;
99
- const msg =
100
- `${path} must be a \`${type}\` type, ` +
101
- `but the final value was: \`${printValue(value, true)}\`${
102
- isCast ? ` (cast from the value \`${printValue(originalValue, true)}\`).` : '.'
103
- }`;
104
-
105
- /* Remove comment that is not supposed to be seen by the enduser
106
- if (value === null) {
107
- msg += `\n If "null" is intended as an empty value be sure to mark the schema as \`.nullable()\``;
108
- }
109
- */
110
- return msg;
111
- },
112
- },
113
- });
114
-
115
- module.exports = {
116
- yup,
117
- handleYupError,
118
- validateYupSchema,
119
- validateYupSchemaSync,
120
- };
package/lib/webhook.js DELETED
@@ -1,30 +0,0 @@
1
- 'use strict';
2
-
3
- const webhookEvents = {
4
- ENTRY_CREATE: 'entry.create',
5
- ENTRY_UPDATE: 'entry.update',
6
- ENTRY_DELETE: 'entry.delete',
7
- ENTRY_PUBLISH: 'entry.publish',
8
- ENTRY_UNPUBLISH: 'entry.unpublish',
9
- MEDIA_CREATE: 'media.create',
10
- MEDIA_UPDATE: 'media.update',
11
- MEDIA_DELETE: 'media.delete',
12
- };
13
-
14
- /**
15
- * TODO V5: remove this file
16
- * @deprecated
17
- */
18
- const deprecatedWebhookEvents = new Proxy(webhookEvents, {
19
- get(target, prop) {
20
- console.warn(
21
- '[deprecated] @strapi/utils/webhook will no longer exist in the next major release of Strapi. ' +
22
- 'Instead, the webhookEvents object can be retrieved from strapi.webhookStore.allowedEvents'
23
- );
24
- return target[prop];
25
- },
26
- });
27
-
28
- module.exports = {
29
- webhookEvents: deprecatedWebhookEvents,
30
- };