@strapi/utils 4.14.3 → 4.14.5

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 (231) hide show
  1. package/dist/async.d.ts +1 -0
  2. package/dist/async.d.ts.map +1 -0
  3. package/dist/code-generator.d.ts +1 -0
  4. package/dist/code-generator.d.ts.map +1 -0
  5. package/dist/config.d.ts +1 -0
  6. package/dist/config.d.ts.map +1 -0
  7. package/dist/content-types.d.ts +1 -0
  8. package/dist/content-types.d.ts.map +1 -0
  9. package/dist/convert-query-params.d.ts +1 -0
  10. package/dist/convert-query-params.d.ts.map +1 -0
  11. package/dist/env-helper.d.ts +1 -0
  12. package/dist/env-helper.d.ts.map +1 -0
  13. package/dist/errors.d.ts +1 -0
  14. package/dist/errors.d.ts.map +1 -0
  15. package/dist/file.d.ts +1 -0
  16. package/dist/file.d.ts.map +1 -0
  17. package/dist/format-yup-error.d.ts +1 -0
  18. package/dist/format-yup-error.d.ts.map +1 -0
  19. package/dist/hooks.d.ts +1 -0
  20. package/dist/hooks.d.ts.map +1 -0
  21. package/dist/import-default.d.ts +1 -0
  22. package/dist/import-default.d.ts.map +1 -0
  23. package/dist/index.d.ts +20 -143
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +3046 -104
  26. package/dist/index.js.map +1 -1
  27. package/dist/index.mjs +3029 -0
  28. package/dist/index.mjs.map +1 -0
  29. package/dist/object-formatting.d.ts +1 -0
  30. package/dist/object-formatting.d.ts.map +1 -0
  31. package/dist/operators.d.ts +1 -0
  32. package/dist/operators.d.ts.map +1 -0
  33. package/dist/pagination.d.ts +1 -0
  34. package/dist/pagination.d.ts.map +1 -0
  35. package/dist/parse-multipart.d.ts +2 -2
  36. package/dist/parse-multipart.d.ts.map +1 -0
  37. package/dist/parse-type.d.ts +1 -0
  38. package/dist/parse-type.d.ts.map +1 -0
  39. package/dist/policy.d.ts +1 -0
  40. package/dist/policy.d.ts.map +1 -0
  41. package/dist/print-value.d.ts +2 -1
  42. package/dist/print-value.d.ts.map +1 -0
  43. package/dist/provider-factory.d.ts +1 -0
  44. package/dist/provider-factory.d.ts.map +1 -0
  45. package/dist/relations.d.ts +1 -0
  46. package/dist/relations.d.ts.map +1 -0
  47. package/dist/sanitize/index.d.ts +1 -0
  48. package/dist/sanitize/index.d.ts.map +1 -0
  49. package/dist/sanitize/sanitizers.d.ts +1 -0
  50. package/dist/sanitize/sanitizers.d.ts.map +1 -0
  51. package/dist/sanitize/visitors/index.d.ts +1 -0
  52. package/dist/sanitize/visitors/index.d.ts.map +1 -0
  53. package/dist/sanitize/visitors/remove-disallowed-fields.d.ts +1 -0
  54. package/dist/sanitize/visitors/remove-disallowed-fields.d.ts.map +1 -0
  55. package/dist/sanitize/visitors/remove-dynamic-zones.d.ts +1 -0
  56. package/dist/sanitize/visitors/remove-dynamic-zones.d.ts.map +1 -0
  57. package/dist/sanitize/visitors/remove-morph-to-relations.d.ts +1 -0
  58. package/dist/sanitize/visitors/remove-morph-to-relations.d.ts.map +1 -0
  59. package/dist/sanitize/visitors/remove-password.d.ts +1 -0
  60. package/dist/sanitize/visitors/remove-password.d.ts.map +1 -0
  61. package/dist/sanitize/visitors/remove-private.d.ts +1 -0
  62. package/dist/sanitize/visitors/remove-private.d.ts.map +1 -0
  63. package/dist/sanitize/visitors/remove-restricted-fields.d.ts +1 -0
  64. package/dist/sanitize/visitors/remove-restricted-fields.d.ts.map +1 -0
  65. package/dist/sanitize/visitors/remove-restricted-relations.d.ts +1 -0
  66. package/dist/sanitize/visitors/remove-restricted-relations.d.ts.map +1 -0
  67. package/dist/set-creator-fields.d.ts +1 -0
  68. package/dist/set-creator-fields.d.ts.map +1 -0
  69. package/dist/string-formatting.d.ts +1 -0
  70. package/dist/string-formatting.d.ts.map +1 -0
  71. package/dist/template-configuration.d.ts +2 -1
  72. package/dist/template-configuration.d.ts.map +1 -0
  73. package/dist/template.d.ts +1 -0
  74. package/dist/template.d.ts.map +1 -0
  75. package/dist/traverse/factory.d.ts +1 -0
  76. package/dist/traverse/factory.d.ts.map +1 -0
  77. package/dist/traverse/index.d.ts +1 -0
  78. package/dist/traverse/index.d.ts.map +1 -0
  79. package/dist/traverse/query-fields.d.ts +1 -0
  80. package/dist/traverse/query-fields.d.ts.map +1 -0
  81. package/dist/traverse/query-filters.d.ts +1 -0
  82. package/dist/traverse/query-filters.d.ts.map +1 -0
  83. package/dist/traverse/query-populate.d.ts +1 -0
  84. package/dist/traverse/query-populate.d.ts.map +1 -0
  85. package/dist/traverse/query-sort.d.ts +1 -0
  86. package/dist/traverse/query-sort.d.ts.map +1 -0
  87. package/dist/traverse-entity.d.ts +1 -0
  88. package/dist/traverse-entity.d.ts.map +1 -0
  89. package/dist/types.d.ts +2 -1
  90. package/dist/types.d.ts.map +1 -0
  91. package/dist/validate/index.d.ts +1 -0
  92. package/dist/validate/index.d.ts.map +1 -0
  93. package/dist/validate/utils.d.ts +1 -0
  94. package/dist/validate/utils.d.ts.map +1 -0
  95. package/dist/validate/validators.d.ts +1 -0
  96. package/dist/validate/validators.d.ts.map +1 -0
  97. package/dist/validate/visitors/index.d.ts +1 -0
  98. package/dist/validate/visitors/index.d.ts.map +1 -0
  99. package/dist/validate/visitors/throw-disallowed-fields.d.ts +1 -0
  100. package/dist/validate/visitors/throw-disallowed-fields.d.ts.map +1 -0
  101. package/dist/validate/visitors/throw-dynamic-zones.d.ts +1 -0
  102. package/dist/validate/visitors/throw-dynamic-zones.d.ts.map +1 -0
  103. package/dist/validate/visitors/throw-morph-to-relations.d.ts +1 -0
  104. package/dist/validate/visitors/throw-morph-to-relations.d.ts.map +1 -0
  105. package/dist/validate/visitors/throw-password.d.ts +1 -0
  106. package/dist/validate/visitors/throw-password.d.ts.map +1 -0
  107. package/dist/validate/visitors/throw-private.d.ts +1 -0
  108. package/dist/validate/visitors/throw-private.d.ts.map +1 -0
  109. package/dist/validate/visitors/throw-restricted-fields.d.ts +1 -0
  110. package/dist/validate/visitors/throw-restricted-fields.d.ts.map +1 -0
  111. package/dist/validate/visitors/throw-restricted-relations.d.ts +1 -0
  112. package/dist/validate/visitors/throw-restricted-relations.d.ts.map +1 -0
  113. package/dist/validators.d.ts +1 -0
  114. package/dist/validators.d.ts.map +1 -0
  115. package/dist/webhook.d.ts +1 -0
  116. package/dist/webhook.d.ts.map +1 -0
  117. package/dist/yup.d.ts +1 -0
  118. package/dist/yup.d.ts.map +1 -0
  119. package/package.json +12 -12
  120. package/dist/async.js +0 -33
  121. package/dist/async.js.map +0 -1
  122. package/dist/code-generator.js +0 -11
  123. package/dist/code-generator.js.map +0 -1
  124. package/dist/config.js +0 -79
  125. package/dist/config.js.map +0 -1
  126. package/dist/content-types.js +0 -162
  127. package/dist/content-types.js.map +0 -1
  128. package/dist/convert-query-params.js +0 -477
  129. package/dist/convert-query-params.js.map +0 -1
  130. package/dist/env-helper.js +0 -84
  131. package/dist/env-helper.js.map +0 -1
  132. package/dist/errors.js +0 -101
  133. package/dist/errors.js.map +0 -1
  134. package/dist/file.js +0 -54
  135. package/dist/file.js.map +0 -1
  136. package/dist/format-yup-error.js +0 -17
  137. package/dist/format-yup-error.js.map +0 -1
  138. package/dist/hooks.js +0 -89
  139. package/dist/hooks.js.map +0 -1
  140. package/dist/import-default.js +0 -9
  141. package/dist/import-default.js.map +0 -1
  142. package/dist/object-formatting.js +0 -14
  143. package/dist/object-formatting.js.map +0 -1
  144. package/dist/operators.js +0 -72
  145. package/dist/operators.js.map +0 -1
  146. package/dist/pagination.js +0 -80
  147. package/dist/pagination.js.map +0 -1
  148. package/dist/parse-multipart.js +0 -36
  149. package/dist/parse-multipart.js.map +0 -1
  150. package/dist/parse-type.js +0 -108
  151. package/dist/parse-type.js.map +0 -1
  152. package/dist/policy.js +0 -109
  153. package/dist/policy.js.map +0 -1
  154. package/dist/print-value.js +0 -50
  155. package/dist/print-value.js.map +0 -1
  156. package/dist/provider-factory.js +0 -80
  157. package/dist/provider-factory.js.map +0 -1
  158. package/dist/relations.js +0 -23
  159. package/dist/relations.js.map +0 -1
  160. package/dist/sanitize/index.js +0 -156
  161. package/dist/sanitize/index.js.map +0 -1
  162. package/dist/sanitize/sanitizers.js +0 -147
  163. package/dist/sanitize/sanitizers.js.map +0 -1
  164. package/dist/sanitize/visitors/index.js +0 -21
  165. package/dist/sanitize/visitors/index.js.map +0 -1
  166. package/dist/sanitize/visitors/remove-disallowed-fields.js +0 -83
  167. package/dist/sanitize/visitors/remove-disallowed-fields.js.map +0 -1
  168. package/dist/sanitize/visitors/remove-dynamic-zones.js +0 -10
  169. package/dist/sanitize/visitors/remove-dynamic-zones.js.map +0 -1
  170. package/dist/sanitize/visitors/remove-morph-to-relations.js +0 -10
  171. package/dist/sanitize/visitors/remove-morph-to-relations.js.map +0 -1
  172. package/dist/sanitize/visitors/remove-password.js +0 -9
  173. package/dist/sanitize/visitors/remove-password.js.map +0 -1
  174. package/dist/sanitize/visitors/remove-private.js +0 -14
  175. package/dist/sanitize/visitors/remove-private.js.map +0 -1
  176. package/dist/sanitize/visitors/remove-restricted-fields.js +0 -25
  177. package/dist/sanitize/visitors/remove-restricted-fields.js.map +0 -1
  178. package/dist/sanitize/visitors/remove-restricted-relations.js +0 -88
  179. package/dist/sanitize/visitors/remove-restricted-relations.js.map +0 -1
  180. package/dist/set-creator-fields.js +0 -39
  181. package/dist/set-creator-fields.js.map +0 -1
  182. package/dist/string-formatting.js +0 -85
  183. package/dist/string-formatting.js.map +0 -1
  184. package/dist/template-configuration.js +0 -30
  185. package/dist/template-configuration.js.map +0 -1
  186. package/dist/template.js +0 -20
  187. package/dist/template.js.map +0 -1
  188. package/dist/traverse/factory.js +0 -127
  189. package/dist/traverse/factory.js.map +0 -1
  190. package/dist/traverse/index.js +0 -17
  191. package/dist/traverse/index.js.map +0 -1
  192. package/dist/traverse/query-fields.js +0 -35
  193. package/dist/traverse/query-fields.js.map +0 -1
  194. package/dist/traverse/query-filters.js +0 -75
  195. package/dist/traverse/query-filters.js.map +0 -1
  196. package/dist/traverse/query-populate.js +0 -171
  197. package/dist/traverse/query-populate.js.map +0 -1
  198. package/dist/traverse/query-sort.js +0 -117
  199. package/dist/traverse/query-sort.js.map +0 -1
  200. package/dist/traverse-entity.js +0 -134
  201. package/dist/traverse-entity.js.map +0 -1
  202. package/dist/types.js +0 -3
  203. package/dist/types.js.map +0 -1
  204. package/dist/validate/index.js +0 -121
  205. package/dist/validate/index.js.map +0 -1
  206. package/dist/validate/utils.js +0 -9
  207. package/dist/validate/utils.js.map +0 -1
  208. package/dist/validate/validators.js +0 -111
  209. package/dist/validate/validators.js.map +0 -1
  210. package/dist/validate/visitors/index.js +0 -21
  211. package/dist/validate/visitors/index.js.map +0 -1
  212. package/dist/validate/visitors/throw-disallowed-fields.js +0 -84
  213. package/dist/validate/visitors/throw-disallowed-fields.js.map +0 -1
  214. package/dist/validate/visitors/throw-dynamic-zones.js +0 -11
  215. package/dist/validate/visitors/throw-dynamic-zones.js.map +0 -1
  216. package/dist/validate/visitors/throw-morph-to-relations.js +0 -11
  217. package/dist/validate/visitors/throw-morph-to-relations.js.map +0 -1
  218. package/dist/validate/visitors/throw-password.js +0 -10
  219. package/dist/validate/visitors/throw-password.js.map +0 -1
  220. package/dist/validate/visitors/throw-private.js +0 -15
  221. package/dist/validate/visitors/throw-private.js.map +0 -1
  222. package/dist/validate/visitors/throw-restricted-fields.js +0 -24
  223. package/dist/validate/visitors/throw-restricted-fields.js.map +0 -1
  224. package/dist/validate/visitors/throw-restricted-relations.js +0 -81
  225. package/dist/validate/visitors/throw-restricted-relations.js.map +0 -1
  226. package/dist/validators.js +0 -64
  227. package/dist/validators.js.map +0 -1
  228. package/dist/webhook.js +0 -27
  229. package/dist/webhook.js.map +0 -1
  230. package/dist/yup.js +0 -108
  231. package/dist/yup.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;;;;AAAA,oDAAuB;AACvB,2DAAoD;AAO7C,MAAM,aAAa,GAA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;IAE9D,IAAI,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE;QAC1B,OAAO,GAAG,CAAC;KACZ;IAED,MAAM,QAAQ,GACZ,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC,KAAK,aAAa;QAC3C,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;QAC1D,CAAC,CAAC,WAAW;QACb,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IAEhC,OAAO,UAAU,QAAQ,IAAI,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC,GAAG,GAAG,EAAE,CAAC;AACjE,CAAC,CAAC;AAES,QAAA,mBAAmB,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;AAC9C,QAAA,oBAAoB,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC"}
@@ -1,162 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getContentTypeRoutePrefix = exports.isKind = exports.isCollectionType = exports.isSingleType = exports.isDraft = exports.getOptions = exports.hasDraftAndPublish = exports.isVisibleAttribute = exports.getCreatorFields = exports.getTimestamps = exports.getVisibleAttributes = exports.getNonVisibleAttributes = exports.isWritableAttribute = exports.getWritableAttributes = exports.getScalarAttributes = exports.getComponentAttributes = exports.getNonWritableAttributes = exports.constants = exports.isPrivateAttribute = exports.getPrivateAttributes = exports.isTypedAttribute = exports.isMorphToRelationalAttribute = exports.isDynamicZoneAttribute = exports.isComponentAttribute = exports.isRelationalAttribute = exports.isMediaAttribute = exports.isScalarAttribute = void 0;
7
- const lodash_1 = __importDefault(require("lodash"));
8
- const fp_1 = require("lodash/fp");
9
- const SINGLE_TYPE = 'singleType';
10
- const COLLECTION_TYPE = 'collectionType';
11
- const ID_ATTRIBUTE = 'id';
12
- const PUBLISHED_AT_ATTRIBUTE = 'publishedAt';
13
- const CREATED_BY_ATTRIBUTE = 'createdBy';
14
- const UPDATED_BY_ATTRIBUTE = 'updatedBy';
15
- const CREATED_AT_ATTRIBUTE = 'createdAt';
16
- const UPDATED_AT_ATTRIBUTE = 'updatedAt';
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
- const constants = {
21
- ID_ATTRIBUTE,
22
- PUBLISHED_AT_ATTRIBUTE,
23
- CREATED_BY_ATTRIBUTE,
24
- UPDATED_BY_ATTRIBUTE,
25
- CREATED_AT_ATTRIBUTE,
26
- UPDATED_AT_ATTRIBUTE,
27
- DP_PUB_STATES,
28
- DP_PUB_STATE_LIVE,
29
- DP_PUB_STATE_PREVIEW,
30
- SINGLE_TYPE,
31
- COLLECTION_TYPE,
32
- };
33
- exports.constants = constants;
34
- const getTimestamps = (model) => {
35
- const attributes = [];
36
- if ((0, fp_1.has)(CREATED_AT_ATTRIBUTE, model.attributes)) {
37
- attributes.push(CREATED_AT_ATTRIBUTE);
38
- }
39
- if ((0, fp_1.has)(UPDATED_AT_ATTRIBUTE, model.attributes)) {
40
- attributes.push(UPDATED_AT_ATTRIBUTE);
41
- }
42
- return attributes;
43
- };
44
- exports.getTimestamps = getTimestamps;
45
- const getCreatorFields = (model) => {
46
- const attributes = [];
47
- if ((0, fp_1.has)(CREATED_BY_ATTRIBUTE, model.attributes)) {
48
- attributes.push(CREATED_BY_ATTRIBUTE);
49
- }
50
- if ((0, fp_1.has)(UPDATED_BY_ATTRIBUTE, model.attributes)) {
51
- attributes.push(UPDATED_BY_ATTRIBUTE);
52
- }
53
- return attributes;
54
- };
55
- exports.getCreatorFields = getCreatorFields;
56
- const getNonWritableAttributes = (model) => {
57
- if (!model)
58
- return [];
59
- const nonWritableAttributes = lodash_1.default.reduce(model.attributes, (acc, attr, attrName) => (attr.writable === false ? acc.concat(attrName) : acc), []);
60
- return lodash_1.default.uniq([ID_ATTRIBUTE, ...getTimestamps(model), ...nonWritableAttributes]);
61
- };
62
- exports.getNonWritableAttributes = getNonWritableAttributes;
63
- const getWritableAttributes = (model) => {
64
- if (!model)
65
- return [];
66
- return lodash_1.default.difference(Object.keys(model.attributes), getNonWritableAttributes(model));
67
- };
68
- exports.getWritableAttributes = getWritableAttributes;
69
- const isWritableAttribute = (model, attributeName) => {
70
- return getWritableAttributes(model).includes(attributeName);
71
- };
72
- exports.isWritableAttribute = isWritableAttribute;
73
- const getNonVisibleAttributes = (model) => {
74
- const nonVisibleAttributes = lodash_1.default.reduce(model.attributes, (acc, attr, attrName) => (attr.visible === false ? acc.concat(attrName) : acc), []);
75
- return lodash_1.default.uniq([ID_ATTRIBUTE, ...getTimestamps(model), ...nonVisibleAttributes]);
76
- };
77
- exports.getNonVisibleAttributes = getNonVisibleAttributes;
78
- const getVisibleAttributes = (model) => {
79
- return lodash_1.default.difference(lodash_1.default.keys(model.attributes), getNonVisibleAttributes(model));
80
- };
81
- exports.getVisibleAttributes = getVisibleAttributes;
82
- const isVisibleAttribute = (model, attributeName) => {
83
- return getVisibleAttributes(model).includes(attributeName);
84
- };
85
- exports.isVisibleAttribute = isVisibleAttribute;
86
- const getOptions = (model) => lodash_1.default.assign({ draftAndPublish: false }, lodash_1.default.get(model, 'options', {}));
87
- exports.getOptions = getOptions;
88
- const hasDraftAndPublish = (model) => lodash_1.default.get(model, 'options.draftAndPublish', false) === true;
89
- exports.hasDraftAndPublish = hasDraftAndPublish;
90
- const isDraft = (data, model) => hasDraftAndPublish(model) && lodash_1.default.get(data, PUBLISHED_AT_ATTRIBUTE) === null;
91
- exports.isDraft = isDraft;
92
- const isSingleType = ({ kind = COLLECTION_TYPE }) => kind === SINGLE_TYPE;
93
- exports.isSingleType = isSingleType;
94
- const isCollectionType = ({ kind = COLLECTION_TYPE }) => kind === COLLECTION_TYPE;
95
- exports.isCollectionType = isCollectionType;
96
- const isKind = (kind) => (model) => model.kind === kind;
97
- exports.isKind = isKind;
98
- const getStoredPrivateAttributes = (model) => (0, fp_1.union)((strapi?.config?.get('api.responses.privateAttributes', []) ?? []), (0, fp_1.getOr)([], 'options.privateAttributes', model));
99
- const getPrivateAttributes = (model) => {
100
- return lodash_1.default.union(getStoredPrivateAttributes(model), lodash_1.default.keys(lodash_1.default.pickBy(model.attributes, (attr) => !!attr.private)));
101
- };
102
- exports.getPrivateAttributes = getPrivateAttributes;
103
- const isPrivateAttribute = (model, attributeName) => {
104
- if (model?.attributes?.[attributeName]?.private === true) {
105
- return true;
106
- }
107
- return getStoredPrivateAttributes(model).includes(attributeName);
108
- };
109
- exports.isPrivateAttribute = isPrivateAttribute;
110
- const isScalarAttribute = (attribute) => {
111
- return !['media', 'component', 'relation', 'dynamiczone'].includes(attribute?.type);
112
- };
113
- exports.isScalarAttribute = isScalarAttribute;
114
- const isMediaAttribute = (attribute) => attribute?.type === 'media';
115
- exports.isMediaAttribute = isMediaAttribute;
116
- const isRelationalAttribute = (attribute) => attribute?.type === 'relation';
117
- exports.isRelationalAttribute = isRelationalAttribute;
118
- const isComponentAttribute = (attribute) => ['component', 'dynamiczone'].includes(attribute?.type);
119
- exports.isComponentAttribute = isComponentAttribute;
120
- const isDynamicZoneAttribute = (attribute) => attribute?.type === 'dynamiczone';
121
- exports.isDynamicZoneAttribute = isDynamicZoneAttribute;
122
- const isMorphToRelationalAttribute = (attribute) => {
123
- return isRelationalAttribute(attribute) && attribute?.relation?.startsWith?.('morphTo');
124
- };
125
- exports.isMorphToRelationalAttribute = isMorphToRelationalAttribute;
126
- const getComponentAttributes = (schema) => {
127
- return lodash_1.default.reduce(schema.attributes, (acc, attr, attrName) => {
128
- if (isComponentAttribute(attr))
129
- acc.push(attrName);
130
- return acc;
131
- }, []);
132
- };
133
- exports.getComponentAttributes = getComponentAttributes;
134
- const getScalarAttributes = (schema) => {
135
- return lodash_1.default.reduce(schema.attributes, (acc, attr, attrName) => {
136
- if (isScalarAttribute(attr))
137
- acc.push(attrName);
138
- return acc;
139
- }, []);
140
- };
141
- exports.getScalarAttributes = getScalarAttributes;
142
- /**
143
- * Checks if an attribute is of type `type`
144
- * @param {object} attribute
145
- * @param {string} type
146
- */
147
- const isTypedAttribute = (attribute, type) => {
148
- return lodash_1.default.has(attribute, 'type') && attribute.type === type;
149
- };
150
- exports.isTypedAttribute = isTypedAttribute;
151
- /**
152
- * Returns a route prefix for a contentType
153
- * @param {object} contentType
154
- * @returns {string}
155
- */
156
- const getContentTypeRoutePrefix = (contentType) => {
157
- return isSingleType(contentType)
158
- ? lodash_1.default.kebabCase(contentType.info.singularName)
159
- : lodash_1.default.kebabCase(contentType.info.pluralName);
160
- };
161
- exports.getContentTypeRoutePrefix = getContentTypeRoutePrefix;
162
- //# sourceMappingURL=content-types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"content-types.js","sourceRoot":"","sources":["../src/content-types.ts"],"names":[],"mappings":";;;;;;AAAA,oDAAuB;AACvB,kCAA8C;AAW9C,MAAM,WAAW,GAAG,YAAY,CAAC;AACjC,MAAM,eAAe,GAAG,gBAAgB,CAAC;AAEzC,MAAM,YAAY,GAAG,IAAI,CAAC;AAC1B,MAAM,sBAAsB,GAAG,aAAa,CAAC;AAC7C,MAAM,oBAAoB,GAAG,WAAW,CAAC;AACzC,MAAM,oBAAoB,GAAG,WAAW,CAAC;AAEzC,MAAM,oBAAoB,GAAG,WAAW,CAAC;AACzC,MAAM,oBAAoB,GAAG,WAAW,CAAC;AAEzC,MAAM,iBAAiB,GAAG,MAAM,CAAC;AACjC,MAAM,oBAAoB,GAAG,SAAS,CAAC;AACvC,MAAM,aAAa,GAAG,CAAC,iBAAiB,EAAE,oBAAoB,CAAC,CAAC;AAEhE,MAAM,SAAS,GAAG;IAChB,YAAY;IACZ,sBAAsB;IACtB,oBAAoB;IACpB,oBAAoB;IACpB,oBAAoB;IACpB,oBAAoB;IACpB,aAAa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AG,CAAC,SAAoB,EAAE,IAAY,EAAE,EAAE;IAC9D,OAAO,gBAAC,CAAC,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,IAAI,SAAS,CAAC,IAAI,KAAK,IAAI,CAAC;AAC7D,CAAC,CAAC;AAoBA,4CAAgB;AAlBlB;;;;GAIG;AACH,MAAM,yBAAyB,GAAG,CAAC,WAAwC,EAAE,EAAE;IAC7E,OAAO,YAAY,CAAC,WAAW,CAAC;QAC9B,CAAC,CAAC,gBAAC,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,YAAY,CAAC;QAC5C,CAAC,CAAC,gBAAC,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;AAC/C,CAAC,CAAC;AA6BA,8DAAyB"}
@@ -1,477 +0,0 @@
1
- "use strict";
2
- /* eslint-disable max-classes-per-file */
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k;
5
- var desc = Object.getOwnPropertyDescriptor(m, k);
6
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
- desc = { enumerable: true, get: function() { return m[k]; } };
8
- }
9
- Object.defineProperty(o, k2, desc);
10
- }) : (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k;
12
- o[k2] = m[k];
13
- }));
14
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
- Object.defineProperty(o, "default", { enumerable: true, value: v });
16
- }) : function(o, v) {
17
- o["default"] = v;
18
- });
19
- var __importStar = (this && this.__importStar) || function (mod) {
20
- if (mod && mod.__esModule) return mod;
21
- var result = {};
22
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
- __setModuleDefault(result, mod);
24
- return result;
25
- };
26
- var __importDefault = (this && this.__importDefault) || function (mod) {
27
- return (mod && mod.__esModule) ? mod : { "default": mod };
28
- };
29
- Object.defineProperty(exports, "__esModule", { value: true });
30
- /**
31
- * Converts the standard Strapi REST query params to a more usable format for querying
32
- * You can read more here: https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/rest-api.html#filters
33
- */
34
- const fp_1 = require("lodash/fp");
35
- const lodash_1 = __importDefault(require("lodash"));
36
- const parse_type_1 = __importDefault(require("./parse-type"));
37
- const contentTypesUtils = __importStar(require("./content-types"));
38
- const errors_1 = require("./errors");
39
- const content_types_1 = require("./content-types");
40
- const operators_1 = require("./operators");
41
- const { PUBLISHED_AT_ATTRIBUTE } = contentTypesUtils.constants;
42
- class InvalidOrderError extends Error {
43
- constructor() {
44
- super();
45
- this.message = 'Invalid order. order can only be one of asc|desc|ASC|DESC';
46
- }
47
- }
48
- class InvalidSortError extends Error {
49
- constructor() {
50
- super();
51
- this.message =
52
- 'Invalid sort parameter. Expected a string, an array of strings, a sort object or an array of sort objects';
53
- }
54
- }
55
- function validateOrder(order) {
56
- if (!(0, fp_1.isString)(order) || !['asc', 'desc'].includes(order.toLocaleLowerCase())) {
57
- throw new InvalidOrderError();
58
- }
59
- }
60
- const convertCountQueryParams = (countQuery) => {
61
- return (0, parse_type_1.default)({ type: 'boolean', value: countQuery });
62
- };
63
- const convertOrderingQueryParams = (ordering) => {
64
- return ordering;
65
- };
66
- const isPlainObject = (value) => lodash_1.default.isPlainObject(value);
67
- const isStringArray = (value) => (0, fp_1.isArray)(value) && value.every(fp_1.isString);
68
- /**
69
- * Sort query parser
70
- */
71
- const convertSortQueryParams = (sortQuery) => {
72
- if (typeof sortQuery === 'string') {
73
- return convertStringSortQueryParam(sortQuery);
74
- }
75
- if (isStringArray(sortQuery)) {
76
- return sortQuery.flatMap((sortValue) => convertStringSortQueryParam(sortValue));
77
- }
78
- if (Array.isArray(sortQuery)) {
79
- return sortQuery.map((sortValue) => convertNestedSortQueryParam(sortValue));
80
- }
81
- if (isPlainObject(sortQuery)) {
82
- return convertNestedSortQueryParam(sortQuery);
83
- }
84
- throw new InvalidSortError();
85
- };
86
- const convertStringSortQueryParam = (sortQuery) => {
87
- return sortQuery.split(',').map((value) => convertSingleSortQueryParam(value));
88
- };
89
- const convertSingleSortQueryParam = (sortQuery) => {
90
- if (!sortQuery) {
91
- return {};
92
- }
93
- if (!(0, fp_1.isString)(sortQuery)) {
94
- throw new Error('Invalid sort query');
95
- }
96
- // split field and order param with default order to ascending
97
- const [field, order = 'asc'] = sortQuery.split(':');
98
- if (field.length === 0) {
99
- throw new Error('Field cannot be empty');
100
- }
101
- validateOrder(order);
102
- // TODO: field should be a valid path on an object model
103
- return lodash_1.default.set({}, field, order);
104
- };
105
- const convertNestedSortQueryParam = (sortQuery) => {
106
- const transformedSort = {};
107
- for (const field of Object.keys(sortQuery)) {
108
- const order = sortQuery[field];
109
- // this is a deep sort
110
- if (isPlainObject(order)) {
111
- transformedSort[field] = convertNestedSortQueryParam(order);
112
- }
113
- else if (typeof order === 'string') {
114
- validateOrder(order);
115
- transformedSort[field] = order;
116
- }
117
- else {
118
- throw Error(`Invalid sort type expected object or string got ${typeof order}`);
119
- }
120
- }
121
- return transformedSort;
122
- };
123
- /**
124
- * Start query parser
125
- */
126
- const convertStartQueryParams = (startQuery) => {
127
- const startAsANumber = lodash_1.default.toNumber(startQuery);
128
- if (!lodash_1.default.isInteger(startAsANumber) || startAsANumber < 0) {
129
- throw new Error(`convertStartQueryParams expected a positive integer got ${startAsANumber}`);
130
- }
131
- return startAsANumber;
132
- };
133
- /**
134
- * Limit query parser
135
- */
136
- const convertLimitQueryParams = (limitQuery) => {
137
- const limitAsANumber = lodash_1.default.toNumber(limitQuery);
138
- if (!lodash_1.default.isInteger(limitAsANumber) || (limitAsANumber !== -1 && limitAsANumber < 0)) {
139
- throw new Error(`convertLimitQueryParams expected a positive integer got ${limitAsANumber}`);
140
- }
141
- if (limitAsANumber === -1) {
142
- return undefined;
143
- }
144
- return limitAsANumber;
145
- };
146
- const convertPageQueryParams = (page) => {
147
- const pageVal = (0, fp_1.toNumber)(page);
148
- if (!(0, fp_1.isInteger)(pageVal) || pageVal <= 0) {
149
- throw new errors_1.PaginationError(`Invalid 'page' parameter. Expected an integer > 0, received: ${page}`);
150
- }
151
- return pageVal;
152
- };
153
- const convertPageSizeQueryParams = (pageSize, page) => {
154
- const pageSizeVal = (0, fp_1.toNumber)(pageSize);
155
- if (!(0, fp_1.isInteger)(pageSizeVal) || pageSizeVal <= 0) {
156
- throw new errors_1.PaginationError(`Invalid 'pageSize' parameter. Expected an integer > 0, received: ${page}`);
157
- }
158
- return pageSizeVal;
159
- };
160
- const validatePaginationParams = (page, pageSize, start, limit) => {
161
- const isPagePagination = !(0, fp_1.isNil)(page) || !(0, fp_1.isNil)(pageSize);
162
- const isOffsetPagination = !(0, fp_1.isNil)(start) || !(0, fp_1.isNil)(limit);
163
- if (isPagePagination && isOffsetPagination) {
164
- throw new errors_1.PaginationError('Invalid pagination attributes. You cannot use page and offset pagination in the same query');
165
- }
166
- };
167
- class InvalidPopulateError extends Error {
168
- constructor() {
169
- super();
170
- this.message =
171
- 'Invalid populate parameter. Expected a string, an array of strings, a populate object';
172
- }
173
- }
174
- // NOTE: we could support foo.* or foo.bar.* etc later on
175
- const convertPopulateQueryParams = (populate, schema, depth = 0) => {
176
- if (depth === 0 && populate === '*') {
177
- return true;
178
- }
179
- if (typeof populate === 'string') {
180
- return populate.split(',').map((value) => lodash_1.default.trim(value));
181
- }
182
- if (Array.isArray(populate)) {
183
- // map convert
184
- return lodash_1.default.uniq(populate.flatMap((value) => {
185
- if (typeof value !== 'string') {
186
- throw new InvalidPopulateError();
187
- }
188
- return value.split(',').map((value) => lodash_1.default.trim(value));
189
- }));
190
- }
191
- if (lodash_1.default.isPlainObject(populate)) {
192
- return convertPopulateObject(populate, schema);
193
- }
194
- throw new InvalidPopulateError();
195
- };
196
- const convertPopulateObject = (populate, schema) => {
197
- if (!schema) {
198
- return {};
199
- }
200
- const { attributes } = schema;
201
- return Object.entries(populate).reduce((acc, [key, subPopulate]) => {
202
- const attribute = attributes[key];
203
- if (!attribute) {
204
- return acc;
205
- }
206
- // Allow adding an 'on' strategy to populate queries for morphTo relations and dynamic zones
207
- const isAllowedAttributeForFragmentPopulate = (0, content_types_1.isDynamicZoneAttribute)(attribute) || (0, content_types_1.isMorphToRelationalAttribute)(attribute);
208
- const hasFragmentPopulateDefined = typeof subPopulate === 'object' && 'on' in subPopulate && !(0, fp_1.isNil)(subPopulate.on);
209
- if (isAllowedAttributeForFragmentPopulate && hasFragmentPopulateDefined) {
210
- return {
211
- ...acc,
212
- [key]: {
213
- on: Object.entries(subPopulate.on).reduce((acc, [type, typeSubPopulate]) => ({
214
- ...acc,
215
- [type]: convertNestedPopulate(typeSubPopulate, strapi.getModel(type)),
216
- }), {}),
217
- },
218
- };
219
- }
220
- // TODO: This is a query's populate fallback for DynamicZone and is kept for legacy purpose.
221
- // Removing it could break existing user queries but it should be removed in V5.
222
- if ((0, content_types_1.isDynamicZoneAttribute)(attribute)) {
223
- const populates = attribute.components
224
- .map((uid) => strapi.getModel(uid))
225
- .map((schema) => convertNestedPopulate(subPopulate, schema))
226
- .map((populate) => (populate === true ? {} : populate)) // cast boolean to empty object to avoid merging issues
227
- .filter((populate) => populate !== false);
228
- if ((0, fp_1.isEmpty)(populates)) {
229
- return acc;
230
- }
231
- return {
232
- ...acc,
233
- [key]: (0, fp_1.mergeAll)(populates),
234
- };
235
- }
236
- if ((0, content_types_1.isMorphToRelationalAttribute)(attribute)) {
237
- return { ...acc, [key]: convertNestedPopulate(subPopulate, undefined) };
238
- }
239
- // NOTE: Retrieve the target schema UID.
240
- // Only handles basic relations, medias and component since it's not possible
241
- // to populate with options for a dynamic zone or a polymorphic relation
242
- let targetSchemaUID;
243
- if (attribute.type === 'relation') {
244
- targetSchemaUID = attribute.target;
245
- }
246
- else if (attribute.type === 'component') {
247
- targetSchemaUID = attribute.component;
248
- }
249
- else if (attribute.type === 'media') {
250
- targetSchemaUID = 'plugin::upload.file';
251
- }
252
- else {
253
- return acc;
254
- }
255
- const targetSchema = strapi.getModel(targetSchemaUID);
256
- // ignore the sub-populate for the current key if there is no schema associated
257
- if (!targetSchema) {
258
- return acc;
259
- }
260
- const populateObject = convertNestedPopulate(subPopulate, targetSchema);
261
- if (!populateObject) {
262
- return acc;
263
- }
264
- return {
265
- ...acc,
266
- [key]: populateObject,
267
- };
268
- }, {});
269
- };
270
- const convertNestedPopulate = (subPopulate, schema) => {
271
- if (lodash_1.default.isString(subPopulate)) {
272
- return (0, parse_type_1.default)({ type: 'boolean', value: subPopulate, forceCast: true });
273
- }
274
- if (lodash_1.default.isBoolean(subPopulate)) {
275
- return subPopulate;
276
- }
277
- if (!isPlainObject(subPopulate)) {
278
- throw new Error(`Invalid nested populate. Expected '*' or an object`);
279
- }
280
- const { sort, filters, fields, populate, count, ordering, page, pageSize, start, limit } = subPopulate;
281
- const query = {};
282
- if (sort) {
283
- query.orderBy = convertSortQueryParams(sort);
284
- }
285
- if (filters) {
286
- query.where = convertFiltersQueryParams(filters, schema);
287
- }
288
- if (fields) {
289
- query.select = convertFieldsQueryParams(fields);
290
- }
291
- if (populate) {
292
- query.populate = convertPopulateQueryParams(populate, schema);
293
- }
294
- if (count) {
295
- query.count = convertCountQueryParams(count);
296
- }
297
- if (ordering) {
298
- query.ordering = convertOrderingQueryParams(ordering);
299
- }
300
- validatePaginationParams(page, pageSize, start, limit);
301
- if (!(0, fp_1.isNil)(page)) {
302
- query.page = convertPageQueryParams(page);
303
- }
304
- if (!(0, fp_1.isNil)(pageSize)) {
305
- query.pageSize = convertPageSizeQueryParams(pageSize, page);
306
- }
307
- if (!(0, fp_1.isNil)(start)) {
308
- query.offset = convertStartQueryParams(start);
309
- }
310
- if (!(0, fp_1.isNil)(limit)) {
311
- query.limit = convertLimitQueryParams(limit);
312
- }
313
- convertPublicationStateParams(schema, subPopulate, query);
314
- return query;
315
- };
316
- // TODO: ensure field is valid in content types (will probably have to check strapi.contentTypes since it can be a string.path)
317
- const convertFieldsQueryParams = (fields, depth = 0) => {
318
- if (depth === 0 && fields === '*') {
319
- return undefined;
320
- }
321
- if (typeof fields === 'string') {
322
- const fieldsValues = fields.split(',').map((value) => lodash_1.default.trim(value));
323
- return lodash_1.default.uniq(['id', ...fieldsValues]);
324
- }
325
- if (isStringArray(fields)) {
326
- // map convert
327
- const fieldsValues = fields
328
- .flatMap((value) => convertFieldsQueryParams(value, depth + 1))
329
- .filter((v) => !(0, fp_1.isNil)(v));
330
- return lodash_1.default.uniq(['id', ...fieldsValues]);
331
- }
332
- throw new Error('Invalid fields parameter. Expected a string or an array of strings');
333
- };
334
- const isValidSchemaAttribute = (key, schema) => {
335
- if (key === 'id') {
336
- return true;
337
- }
338
- if (!schema) {
339
- return false;
340
- }
341
- return Object.keys(schema.attributes).includes(key);
342
- };
343
- const convertFiltersQueryParams = (filters, schema) => {
344
- // Filters need to be either an array or an object
345
- // Here we're only checking for 'object' type since typeof [] => object and typeof {} => object
346
- if (!(0, fp_1.isObject)(filters)) {
347
- throw new Error('The filters parameter must be an object or an array');
348
- }
349
- // Don't mutate the original object
350
- const filtersCopy = (0, fp_1.cloneDeep)(filters);
351
- return convertAndSanitizeFilters(filtersCopy, schema);
352
- };
353
- const convertAndSanitizeFilters = (filters, schema) => {
354
- if (Array.isArray(filters)) {
355
- return (filters
356
- // Sanitize each filter
357
- .map((filter) => convertAndSanitizeFilters(filter, schema))
358
- // Filter out empty filters
359
- .filter((filter) => !isPlainObject(filter) || !(0, fp_1.isEmpty)(filter)));
360
- }
361
- if (!isPlainObject(filters)) {
362
- return filters;
363
- }
364
- const removeOperator = (operator) => delete filters[operator];
365
- // Here, `key` can either be an operator or an attribute name
366
- for (const [key, value] of Object.entries(filters)) {
367
- const attribute = (0, fp_1.get)(key, schema?.attributes);
368
- const validKey = (0, operators_1.isOperator)(key) || isValidSchemaAttribute(key, schema);
369
- if (!validKey) {
370
- removeOperator(key);
371
- }
372
- // Handle attributes
373
- else if (attribute) {
374
- // Relations
375
- if (attribute.type === 'relation') {
376
- filters[key] = convertAndSanitizeFilters(value, strapi.getModel(attribute.target));
377
- }
378
- // Components
379
- else if (attribute.type === 'component') {
380
- filters[key] = convertAndSanitizeFilters(value, strapi.getModel(attribute.component));
381
- }
382
- // Media
383
- else if (attribute.type === 'media') {
384
- filters[key] = convertAndSanitizeFilters(value, strapi.getModel('plugin::upload.file'));
385
- }
386
- // Dynamic Zones
387
- else if (attribute.type === 'dynamiczone') {
388
- removeOperator(key);
389
- }
390
- // Password attributes
391
- else if (attribute.type === 'password') {
392
- // Always remove password attributes from filters object
393
- removeOperator(key);
394
- }
395
- // Scalar attributes
396
- else {
397
- filters[key] = convertAndSanitizeFilters(value, schema);
398
- }
399
- }
400
- // Handle operators
401
- else if (['$null', '$notNull'].includes(key)) {
402
- filters[key] = (0, parse_type_1.default)({ type: 'boolean', value: filters[key], forceCast: true });
403
- }
404
- else if ((0, fp_1.isObject)(value)) {
405
- filters[key] = convertAndSanitizeFilters(value, schema);
406
- }
407
- // Remove empty objects & arrays
408
- if (isPlainObject(filters[key]) && (0, fp_1.isEmpty)(filters[key])) {
409
- removeOperator(key);
410
- }
411
- }
412
- return filters;
413
- };
414
- const convertPublicationStateParams = (schema, params = {}, query = {}) => {
415
- if (!schema) {
416
- return;
417
- }
418
- const { publicationState } = params;
419
- if (!lodash_1.default.isNil(publicationState)) {
420
- if (!contentTypesUtils.constants.DP_PUB_STATES.includes(publicationState)) {
421
- throw new Error(`Invalid publicationState. Expected one of 'preview','live' received: ${publicationState}.`);
422
- }
423
- // NOTE: this is the query layer filters not the entity service filters
424
- query.filters = ({ meta }) => {
425
- if (publicationState === 'live' && (0, fp_1.has)(PUBLISHED_AT_ATTRIBUTE, meta.attributes)) {
426
- return { [PUBLISHED_AT_ATTRIBUTE]: { $notNull: true } };
427
- }
428
- };
429
- }
430
- };
431
- const transformParamsToQuery = (uid, params) => {
432
- // NOTE: can be a CT, a Compo or nothing in the case of polymorphism (DZ & morph relations)
433
- const schema = strapi.getModel(uid);
434
- const query = {};
435
- const { _q, sort, filters, fields, populate, page, pageSize, start, limit } = params;
436
- if (!(0, fp_1.isNil)(_q)) {
437
- query._q = _q;
438
- }
439
- if (!(0, fp_1.isNil)(sort)) {
440
- query.orderBy = convertSortQueryParams(sort);
441
- }
442
- if (!(0, fp_1.isNil)(filters)) {
443
- query.where = convertFiltersQueryParams(filters, schema);
444
- }
445
- if (!(0, fp_1.isNil)(fields)) {
446
- query.select = convertFieldsQueryParams(fields);
447
- }
448
- if (!(0, fp_1.isNil)(populate)) {
449
- query.populate = convertPopulateQueryParams(populate, schema);
450
- }
451
- validatePaginationParams(page, pageSize, start, limit);
452
- if (!(0, fp_1.isNil)(page)) {
453
- query.page = convertPageQueryParams(page);
454
- }
455
- if (!(0, fp_1.isNil)(pageSize)) {
456
- query.pageSize = convertPageSizeQueryParams(pageSize, page);
457
- }
458
- if (!(0, fp_1.isNil)(start)) {
459
- query.offset = convertStartQueryParams(start);
460
- }
461
- if (!(0, fp_1.isNil)(limit)) {
462
- query.limit = convertLimitQueryParams(limit);
463
- }
464
- convertPublicationStateParams(schema, params, query);
465
- return query;
466
- };
467
- exports.default = {
468
- convertSortQueryParams,
469
- convertStartQueryParams,
470
- convertLimitQueryParams,
471
- convertPopulateQueryParams,
472
- convertFiltersQueryParams,
473
- convertFieldsQueryParams,
474
- convertPublicationStateParams,
475
- transformParamsToQuery,
476
- };
477
- //# sourceMappingURL=convert-query-params.js.map