@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.
- package/dist/async.d.ts +10 -0
- package/dist/async.js +33 -0
- package/dist/async.js.map +1 -0
- package/dist/code-generator.d.ts +2 -0
- package/dist/code-generator.js +11 -0
- package/dist/code-generator.js.map +1 -0
- package/dist/config.d.ts +8 -0
- package/dist/config.js +79 -0
- package/dist/config.js.map +1 -0
- package/dist/content-types.d.ts +60 -0
- package/dist/content-types.js +151 -0
- package/dist/content-types.js.map +1 -0
- package/dist/convert-query-params.d.ts +75 -0
- package/dist/convert-query-params.js +476 -0
- package/dist/convert-query-params.js.map +1 -0
- package/dist/env-helper.d.ts +18 -0
- package/dist/env-helper.js +84 -0
- package/dist/env-helper.js.map +1 -0
- package/dist/errors.d.ts +37 -0
- package/dist/errors.js +100 -0
- package/dist/errors.js.map +1 -0
- package/dist/file.d.ts +16 -0
- package/dist/file.js +54 -0
- package/dist/file.js.map +1 -0
- package/dist/format-yup-error.d.ts +10 -0
- package/dist/format-yup-error.js +17 -0
- package/dist/format-yup-error.js.map +1 -0
- package/dist/hooks.d.ts +63 -0
- package/dist/hooks.js +89 -0
- package/dist/hooks.js.map +1 -0
- package/dist/import-default.d.ts +1 -0
- package/dist/import-default.js +9 -0
- package/dist/import-default.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +99 -0
- package/dist/index.js.map +1 -0
- package/dist/object-formatting.d.ts +3 -0
- package/dist/object-formatting.js +14 -0
- package/dist/object-formatting.js.map +1 -0
- package/dist/operators.d.ts +2 -0
- package/dist/operators.js +70 -0
- package/dist/operators.js.map +1 -0
- package/dist/pagination.d.ts +14 -0
- package/dist/pagination.js +80 -0
- package/dist/pagination.js.map +1 -0
- package/dist/parse-multipart.d.ts +8 -0
- package/dist/parse-multipart.js +36 -0
- package/dist/parse-multipart.js.map +1 -0
- package/dist/parse-type.d.ts +21 -0
- package/dist/parse-type.js +108 -0
- package/dist/parse-type.js.map +1 -0
- package/dist/policy.d.ts +41 -0
- package/dist/policy.js +109 -0
- package/dist/policy.js.map +1 -0
- package/dist/print-value.d.ts +2 -0
- package/dist/print-value.js +50 -0
- package/dist/print-value.js.map +1 -0
- package/dist/provider-factory.d.ts +29 -0
- package/dist/provider-factory.js +80 -0
- package/dist/provider-factory.js.map +1 -0
- package/dist/relations.d.ts +10 -0
- package/dist/relations.js +23 -0
- package/dist/relations.js.map +1 -0
- package/dist/sanitize/index.d.ts +23 -0
- package/dist/sanitize/index.js +135 -0
- package/dist/sanitize/index.js.map +1 -0
- package/dist/sanitize/sanitizers.d.ts +10 -0
- package/dist/sanitize/sanitizers.js +114 -0
- package/dist/sanitize/sanitizers.js.map +1 -0
- package/dist/sanitize/visitors/allowed-fields.d.ts +3 -0
- package/{lib → dist}/sanitize/visitors/allowed-fields.js +17 -32
- package/dist/sanitize/visitors/allowed-fields.js.map +1 -0
- package/dist/sanitize/visitors/index.d.ts +7 -0
- package/dist/sanitize/visitors/index.js +21 -0
- package/dist/sanitize/visitors/index.js.map +1 -0
- package/dist/sanitize/visitors/remove-dynamic-zones.d.ts +3 -0
- package/dist/sanitize/visitors/remove-dynamic-zones.js +10 -0
- package/dist/sanitize/visitors/remove-dynamic-zones.js.map +1 -0
- package/dist/sanitize/visitors/remove-morph-to-relations.d.ts +3 -0
- package/dist/sanitize/visitors/remove-morph-to-relations.js +10 -0
- package/dist/sanitize/visitors/remove-morph-to-relations.js.map +1 -0
- package/dist/sanitize/visitors/remove-password.d.ts +3 -0
- package/dist/sanitize/visitors/remove-password.js +9 -0
- package/dist/sanitize/visitors/remove-password.js.map +1 -0
- package/dist/sanitize/visitors/remove-private.d.ts +3 -0
- package/dist/sanitize/visitors/remove-private.js +14 -0
- package/dist/sanitize/visitors/remove-private.js.map +1 -0
- package/dist/sanitize/visitors/remove-restricted-relations.d.ts +3 -0
- package/dist/sanitize/visitors/remove-restricted-relations.js +88 -0
- package/dist/sanitize/visitors/remove-restricted-relations.js.map +1 -0
- package/dist/sanitize/visitors/restricted-fields.d.ts +3 -0
- package/dist/sanitize/visitors/restricted-fields.js +25 -0
- package/dist/sanitize/visitors/restricted-fields.js.map +1 -0
- package/dist/set-creator-fields.d.ts +9 -0
- package/dist/set-creator-fields.js +39 -0
- package/dist/set-creator-fields.js.map +1 -0
- package/dist/string-formatting.d.ts +15 -0
- package/dist/string-formatting.js +85 -0
- package/dist/string-formatting.js.map +1 -0
- package/dist/template-configuration.d.ts +5 -0
- package/dist/template-configuration.js +30 -0
- package/dist/template-configuration.js.map +1 -0
- package/dist/template.d.ts +9 -0
- package/dist/template.js +20 -0
- package/dist/template.js.map +1 -0
- package/dist/traverse/factory.d.ts +78 -0
- package/dist/traverse/factory.js +127 -0
- package/dist/traverse/factory.js.map +1 -0
- package/dist/traverse/index.d.ts +5 -0
- package/dist/traverse/index.js +17 -0
- package/dist/traverse/index.js.map +1 -0
- package/dist/traverse/query-fields.d.ts +3 -0
- package/dist/traverse/query-fields.js +35 -0
- package/dist/traverse/query-fields.js.map +1 -0
- package/dist/traverse/query-filters.d.ts +3 -0
- package/dist/traverse/query-filters.js +75 -0
- package/dist/traverse/query-filters.js.map +1 -0
- package/dist/traverse/query-populate.d.ts +3 -0
- package/dist/traverse/query-populate.js +144 -0
- package/dist/traverse/query-populate.js.map +1 -0
- package/dist/traverse/query-sort.d.ts +3 -0
- package/dist/traverse/query-sort.js +116 -0
- package/dist/traverse/query-sort.js.map +1 -0
- package/dist/traverse-entity.d.ts +31 -0
- package/dist/traverse-entity.js +134 -0
- package/dist/traverse-entity.js.map +1 -0
- package/dist/types.d.ts +65 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/validators.d.ts +13 -0
- package/dist/validators.js +120 -0
- package/dist/validators.js.map +1 -0
- package/dist/webhook.d.ts +5 -0
- package/dist/webhook.js +27 -0
- package/dist/webhook.js.map +1 -0
- package/package.json +19 -4
- package/.eslintignore +0 -3
- package/.eslintrc.js +0 -4
- package/index.d.ts +0 -5
- package/lib/async.d.ts +0 -21
- package/lib/async.js +0 -45
- package/lib/build-query.js +0 -208
- package/lib/code-generator.js +0 -13
- package/lib/config.js +0 -88
- package/lib/content-types.js +0 -196
- package/lib/convert-query-params.js +0 -586
- package/lib/env-helper.js +0 -98
- package/lib/errors.js +0 -113
- package/lib/file.js +0 -60
- package/lib/format-yup-error.js +0 -20
- package/lib/hooks.js +0 -110
- package/lib/import-default.js +0 -10
- package/lib/index.js +0 -99
- package/lib/object-formatting.js +0 -15
- package/lib/operators.js +0 -74
- package/lib/pagination.js +0 -99
- package/lib/parse-multipart.js +0 -44
- package/lib/parse-type.js +0 -100
- package/lib/policy.js +0 -129
- package/lib/print-value.js +0 -52
- package/lib/provider-factory.js +0 -116
- package/lib/relations.js +0 -31
- package/lib/sanitize/index.js +0 -143
- package/lib/sanitize/sanitizers.js +0 -163
- package/lib/sanitize/visitors/index.js +0 -11
- package/lib/sanitize/visitors/remove-dynamic-zones.js +0 -9
- package/lib/sanitize/visitors/remove-morph-to-relations.js +0 -9
- package/lib/sanitize/visitors/remove-password.js +0 -7
- package/lib/sanitize/visitors/remove-private.js +0 -15
- package/lib/sanitize/visitors/remove-restricted-relations.js +0 -81
- package/lib/sanitize/visitors/restricted-fields.js +0 -32
- package/lib/set-creator-fields.js +0 -17
- package/lib/string-formatting.js +0 -79
- package/lib/template-configuration.js +0 -32
- package/lib/template.js +0 -28
- package/lib/traverse/factory.js +0 -157
- package/lib/traverse/index.js +0 -16
- package/lib/traverse/query-fields.js +0 -39
- package/lib/traverse/query-filters.js +0 -97
- package/lib/traverse/query-populate.js +0 -191
- package/lib/traverse/query-sort.js +0 -171
- package/lib/traverse-entity.js +0 -166
- package/lib/validators.js +0 -120
- package/lib/webhook.js +0 -30
package/lib/content-types.js
DELETED
|
@@ -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
|
-
};
|