@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
@@ -1,196 +0,0 @@
1
- 'use strict';
2
-
3
- const _ = require('lodash');
4
- const { getOr, has, union } = require('lodash/fp');
5
-
6
- const SINGLE_TYPE = 'singleType';
7
- const COLLECTION_TYPE = 'collectionType';
8
-
9
- const ID_ATTRIBUTE = 'id';
10
- const PUBLISHED_AT_ATTRIBUTE = 'publishedAt';
11
- const CREATED_BY_ATTRIBUTE = 'createdBy';
12
- const UPDATED_BY_ATTRIBUTE = 'updatedBy';
13
-
14
- const CREATED_AT_ATTRIBUTE = 'createdAt';
15
- const UPDATED_AT_ATTRIBUTE = 'updatedAt';
16
-
17
- const DP_PUB_STATE_LIVE = 'live';
18
- const DP_PUB_STATE_PREVIEW = 'preview';
19
- const DP_PUB_STATES = [DP_PUB_STATE_LIVE, DP_PUB_STATE_PREVIEW];
20
-
21
- const constants = {
22
- ID_ATTRIBUTE,
23
- PUBLISHED_AT_ATTRIBUTE,
24
- CREATED_BY_ATTRIBUTE,
25
- UPDATED_BY_ATTRIBUTE,
26
- CREATED_AT_ATTRIBUTE,
27
- UPDATED_AT_ATTRIBUTE,
28
- DP_PUB_STATES,
29
- DP_PUB_STATE_LIVE,
30
- DP_PUB_STATE_PREVIEW,
31
- SINGLE_TYPE,
32
- COLLECTION_TYPE,
33
- };
34
-
35
- const getTimestamps = (model) => {
36
- const attributes = [];
37
-
38
- if (has(CREATED_AT_ATTRIBUTE, model.attributes)) {
39
- attributes.push(CREATED_AT_ATTRIBUTE);
40
- }
41
-
42
- if (has(UPDATED_AT_ATTRIBUTE, model.attributes)) {
43
- attributes.push(UPDATED_AT_ATTRIBUTE);
44
- }
45
-
46
- return attributes;
47
- };
48
-
49
- const getNonWritableAttributes = (model = {}) => {
50
- const nonWritableAttributes = _.reduce(
51
- model.attributes,
52
- (acc, attr, attrName) => (attr.writable === false ? acc.concat(attrName) : acc),
53
- []
54
- );
55
-
56
- return _.uniq([ID_ATTRIBUTE, ...getTimestamps(model), ...nonWritableAttributes]);
57
- };
58
-
59
- const getWritableAttributes = (model = {}) => {
60
- return _.difference(Object.keys(model.attributes), getNonWritableAttributes(model));
61
- };
62
-
63
- const isWritableAttribute = (model, attributeName) => {
64
- return getWritableAttributes(model).includes(attributeName);
65
- };
66
-
67
- const getNonVisibleAttributes = (model) => {
68
- const nonVisibleAttributes = _.reduce(
69
- model.attributes,
70
- (acc, attr, attrName) => (attr.visible === false ? acc.concat(attrName) : acc),
71
- []
72
- );
73
-
74
- return _.uniq([ID_ATTRIBUTE, ...getTimestamps(model), ...nonVisibleAttributes]);
75
- };
76
-
77
- const getVisibleAttributes = (model) => {
78
- return _.difference(_.keys(model.attributes), getNonVisibleAttributes(model));
79
- };
80
-
81
- const isVisibleAttribute = (model, attributeName) => {
82
- return getVisibleAttributes(model).includes(attributeName);
83
- };
84
-
85
- const getOptions = (model) => _.assign({ draftAndPublish: false }, _.get(model, 'options', {}));
86
- const hasDraftAndPublish = (model) => _.get(model, 'options.draftAndPublish', false) === true;
87
-
88
- const isDraft = (data, model) =>
89
- hasDraftAndPublish(model) && _.get(data, PUBLISHED_AT_ATTRIBUTE) === null;
90
-
91
- const isSingleType = ({ kind = COLLECTION_TYPE }) => kind === SINGLE_TYPE;
92
- const isCollectionType = ({ kind = COLLECTION_TYPE }) => kind === COLLECTION_TYPE;
93
- const isKind = (kind) => (model) => model.kind === kind;
94
-
95
- const getStoredPrivateAttributes = (model) =>
96
- union(
97
- strapi?.config?.get('api.responses.privateAttributes', []) ?? [],
98
- getOr([], 'options.privateAttributes', model)
99
- );
100
-
101
- const getPrivateAttributes = (model = {}) => {
102
- return _.union(
103
- getStoredPrivateAttributes(model),
104
- _.keys(_.pickBy(model.attributes, (attr) => !!attr.private))
105
- );
106
- };
107
-
108
- const isPrivateAttribute = (model, attributeName) => {
109
- if (model?.attributes?.[attributeName]?.private === true) {
110
- return true;
111
- }
112
- return getStoredPrivateAttributes(model).includes(attributeName);
113
- };
114
-
115
- const isScalarAttribute = (attribute) => {
116
- return !['media', 'component', 'relation', 'dynamiczone'].includes(attribute?.type);
117
- };
118
- const isMediaAttribute = (attribute) => attribute?.type === 'media';
119
- const isRelationalAttribute = (attribute) => attribute?.type === 'relation';
120
- const isComponentAttribute = (attribute) => ['component', 'dynamiczone'].includes(attribute?.type);
121
-
122
- const isDynamicZoneAttribute = (attribute) => attribute?.type === 'dynamiczone';
123
- const isMorphToRelationalAttribute = (attribute) => {
124
- return isRelationalAttribute(attribute) && attribute?.relation?.startsWith?.('morphTo');
125
- };
126
-
127
- const getComponentAttributes = (schema) => {
128
- return _.reduce(
129
- schema.attributes,
130
- (acc, attr, attrName) => {
131
- if (isComponentAttribute(attr)) acc.push(attrName);
132
- return acc;
133
- },
134
- []
135
- );
136
- };
137
-
138
- const getScalarAttributes = (schema) => {
139
- return _.reduce(
140
- schema.attributes,
141
- (acc, attr, attrName) => {
142
- if (isScalarAttribute(attr)) acc.push(attrName);
143
- return acc;
144
- },
145
- []
146
- );
147
- };
148
-
149
- /**
150
- * Checks if an attribute is of type `type`
151
- * @param {object} attribute
152
- * @param {string} type
153
- */
154
- const isTypedAttribute = (attribute, type) => {
155
- return _.has(attribute, 'type') && attribute.type === type;
156
- };
157
-
158
- /**
159
- * Returns a route prefix for a contentType
160
- * @param {object} contentType
161
- * @returns {string}
162
- */
163
- const getContentTypeRoutePrefix = (contentType) => {
164
- return isSingleType(contentType)
165
- ? _.kebabCase(contentType.info.singularName)
166
- : _.kebabCase(contentType.info.pluralName);
167
- };
168
-
169
- module.exports = {
170
- isScalarAttribute,
171
- isMediaAttribute,
172
- isRelationalAttribute,
173
- isComponentAttribute,
174
- isDynamicZoneAttribute,
175
- isMorphToRelationalAttribute,
176
- isTypedAttribute,
177
- getPrivateAttributes,
178
- isPrivateAttribute,
179
- constants,
180
- getNonWritableAttributes,
181
- getComponentAttributes,
182
- getScalarAttributes,
183
- getWritableAttributes,
184
- isWritableAttribute,
185
- getNonVisibleAttributes,
186
- getVisibleAttributes,
187
- getTimestamps,
188
- isVisibleAttribute,
189
- hasDraftAndPublish,
190
- getOptions,
191
- isDraft,
192
- isSingleType,
193
- isCollectionType,
194
- isKind,
195
- getContentTypeRoutePrefix,
196
- };