@strapi/utils 5.0.0-beta.2 → 5.0.0-beta.4
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 +5 -11
- package/dist/async.d.ts.map +1 -1
- package/dist/content-types.d.ts.map +1 -1
- package/dist/hooks.d.ts.map +1 -1
- package/dist/index.js +66 -66
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +52 -52
- package/dist/index.mjs.map +1 -1
- package/dist/parse-type.d.ts.map +1 -1
- package/dist/sanitize/sanitizers.d.ts +1 -1
- package/dist/sanitize/sanitizers.d.ts.map +1 -1
- package/dist/set-creator-fields.d.ts.map +1 -1
- package/dist/traverse/factory.d.ts +1 -3
- package/dist/traverse/factory.d.ts.map +1 -1
- package/dist/traverse-entity.d.ts.map +1 -1
- package/dist/validate/utils.d.ts +1 -1
- package/dist/validate/utils.d.ts.map +1 -1
- package/dist/validators.d.ts +2 -2
- package/dist/validators.d.ts.map +1 -1
- package/dist/zod.d.ts.map +1 -1
- package/package.json +7 -7
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as _ from "lodash";
|
|
2
|
+
import ___default, { kebabCase } from "lodash";
|
|
3
|
+
import * as dates$1 from "date-fns";
|
|
2
4
|
import { has, union, getOr, assoc, assign, cloneDeep, remove, eq, curry, isObject, isNil, clone, isArray, isEmpty, toPath, defaults, isString, mergeAll, get, toNumber, isInteger, pick, omit, trim, pipe as pipe$1, split, map as map$1, flatten, first, identity, constant, join, merge, trimChars, trimCharsEnd, trimCharsStart, isNumber } from "lodash/fp";
|
|
3
5
|
import { randomUUID } from "crypto";
|
|
4
6
|
import { machineIdSync } from "node-machine-id";
|
|
@@ -29,8 +31,6 @@ function _mergeNamespaces(n, m) {
|
|
|
29
31
|
}
|
|
30
32
|
return Object.freeze(Object.defineProperty(n, Symbol.toStringTag, { value: "Module" }));
|
|
31
33
|
}
|
|
32
|
-
const _ = require("lodash");
|
|
33
|
-
const dates$1 = require("date-fns");
|
|
34
34
|
const timeRegex = /^(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(.[0-9]{1,3})?$/;
|
|
35
35
|
const isDate = (v) => {
|
|
36
36
|
return dates$1.isDate(v);
|
|
@@ -129,32 +129,32 @@ const parseType = (options) => {
|
|
|
129
129
|
}
|
|
130
130
|
};
|
|
131
131
|
function envFn(key, defaultValue) {
|
|
132
|
-
return
|
|
132
|
+
return ___default.has(process.env, key) ? process.env[key] : defaultValue;
|
|
133
133
|
}
|
|
134
134
|
function getKey(key) {
|
|
135
135
|
return process.env[key] ?? "";
|
|
136
136
|
}
|
|
137
137
|
const utils = {
|
|
138
138
|
int(key, defaultValue) {
|
|
139
|
-
if (!
|
|
139
|
+
if (!___default.has(process.env, key)) {
|
|
140
140
|
return defaultValue;
|
|
141
141
|
}
|
|
142
142
|
return parseInt(getKey(key), 10);
|
|
143
143
|
},
|
|
144
144
|
float(key, defaultValue) {
|
|
145
|
-
if (!
|
|
145
|
+
if (!___default.has(process.env, key)) {
|
|
146
146
|
return defaultValue;
|
|
147
147
|
}
|
|
148
148
|
return parseFloat(getKey(key));
|
|
149
149
|
},
|
|
150
150
|
bool(key, defaultValue) {
|
|
151
|
-
if (!
|
|
151
|
+
if (!___default.has(process.env, key)) {
|
|
152
152
|
return defaultValue;
|
|
153
153
|
}
|
|
154
154
|
return getKey(key) === "true";
|
|
155
155
|
},
|
|
156
156
|
json(key, defaultValue) {
|
|
157
|
-
if (!
|
|
157
|
+
if (!___default.has(process.env, key)) {
|
|
158
158
|
return defaultValue;
|
|
159
159
|
}
|
|
160
160
|
try {
|
|
@@ -167,7 +167,7 @@ const utils = {
|
|
|
167
167
|
}
|
|
168
168
|
},
|
|
169
169
|
array(key, defaultValue) {
|
|
170
|
-
if (!
|
|
170
|
+
if (!___default.has(process.env, key)) {
|
|
171
171
|
return defaultValue;
|
|
172
172
|
}
|
|
173
173
|
let value = getKey(key);
|
|
@@ -175,11 +175,11 @@ const utils = {
|
|
|
175
175
|
value = value.substring(1, value.length - 1);
|
|
176
176
|
}
|
|
177
177
|
return value.split(",").map((v) => {
|
|
178
|
-
return
|
|
178
|
+
return ___default.trim(___default.trim(v, " "), '"');
|
|
179
179
|
});
|
|
180
180
|
},
|
|
181
181
|
date(key, defaultValue) {
|
|
182
|
-
if (!
|
|
182
|
+
if (!___default.has(process.env, key)) {
|
|
183
183
|
return defaultValue;
|
|
184
184
|
}
|
|
185
185
|
return new Date(getKey(key));
|
|
@@ -246,12 +246,12 @@ const getCreatorFields = (model) => {
|
|
|
246
246
|
const getNonWritableAttributes = (model) => {
|
|
247
247
|
if (!model)
|
|
248
248
|
return [];
|
|
249
|
-
const nonWritableAttributes =
|
|
249
|
+
const nonWritableAttributes = ___default.reduce(
|
|
250
250
|
model.attributes,
|
|
251
251
|
(acc, attr, attrName) => attr.writable === false ? acc.concat(attrName) : acc,
|
|
252
252
|
[]
|
|
253
253
|
);
|
|
254
|
-
return
|
|
254
|
+
return ___default.uniq([
|
|
255
255
|
ID_ATTRIBUTE$4,
|
|
256
256
|
DOC_ID_ATTRIBUTE$4,
|
|
257
257
|
...getTimestamps(model),
|
|
@@ -261,28 +261,28 @@ const getNonWritableAttributes = (model) => {
|
|
|
261
261
|
const getWritableAttributes = (model) => {
|
|
262
262
|
if (!model)
|
|
263
263
|
return [];
|
|
264
|
-
return
|
|
264
|
+
return ___default.difference(Object.keys(model.attributes), getNonWritableAttributes(model));
|
|
265
265
|
};
|
|
266
266
|
const isWritableAttribute = (model, attributeName) => {
|
|
267
267
|
return getWritableAttributes(model).includes(attributeName);
|
|
268
268
|
};
|
|
269
269
|
const getNonVisibleAttributes = (model) => {
|
|
270
|
-
const nonVisibleAttributes =
|
|
270
|
+
const nonVisibleAttributes = ___default.reduce(
|
|
271
271
|
model.attributes,
|
|
272
272
|
(acc, attr, attrName) => attr.visible === false ? acc.concat(attrName) : acc,
|
|
273
273
|
[]
|
|
274
274
|
);
|
|
275
|
-
return
|
|
275
|
+
return ___default.uniq([ID_ATTRIBUTE$4, DOC_ID_ATTRIBUTE$4, ...getTimestamps(model), ...nonVisibleAttributes]);
|
|
276
276
|
};
|
|
277
277
|
const getVisibleAttributes = (model) => {
|
|
278
|
-
return
|
|
278
|
+
return ___default.difference(___default.keys(model.attributes), getNonVisibleAttributes(model));
|
|
279
279
|
};
|
|
280
280
|
const isVisibleAttribute = (model, attributeName) => {
|
|
281
281
|
return getVisibleAttributes(model).includes(attributeName);
|
|
282
282
|
};
|
|
283
|
-
const getOptions = (model) =>
|
|
284
|
-
const hasDraftAndPublish = (model) =>
|
|
285
|
-
const isDraft = (data, model) => hasDraftAndPublish(model) &&
|
|
283
|
+
const getOptions = (model) => ___default.assign({ draftAndPublish: false }, ___default.get(model, "options", {}));
|
|
284
|
+
const hasDraftAndPublish = (model) => ___default.get(model, "options.draftAndPublish", false) === true;
|
|
285
|
+
const isDraft = (data, model) => hasDraftAndPublish(model) && ___default.get(data, PUBLISHED_AT_ATTRIBUTE$1) === null;
|
|
286
286
|
const isSingleType = ({ kind = COLLECTION_TYPE }) => kind === SINGLE_TYPE;
|
|
287
287
|
const isCollectionType = ({ kind = COLLECTION_TYPE }) => kind === COLLECTION_TYPE;
|
|
288
288
|
const isKind = (kind) => (model) => model.kind === kind;
|
|
@@ -291,9 +291,9 @@ const getStoredPrivateAttributes = (model) => union(
|
|
|
291
291
|
getOr([], "options.privateAttributes", model)
|
|
292
292
|
);
|
|
293
293
|
const getPrivateAttributes = (model) => {
|
|
294
|
-
return
|
|
294
|
+
return ___default.union(
|
|
295
295
|
getStoredPrivateAttributes(model),
|
|
296
|
-
|
|
296
|
+
___default.keys(___default.pickBy(model.attributes, (attr) => !!attr.private))
|
|
297
297
|
);
|
|
298
298
|
};
|
|
299
299
|
const isPrivateAttribute = (model, attributeName) => {
|
|
@@ -313,7 +313,7 @@ const isMorphToRelationalAttribute = (attribute) => {
|
|
|
313
313
|
return isRelationalAttribute(attribute) && attribute?.relation?.startsWith?.("morphTo");
|
|
314
314
|
};
|
|
315
315
|
const getComponentAttributes = (schema) => {
|
|
316
|
-
return
|
|
316
|
+
return ___default.reduce(
|
|
317
317
|
schema.attributes,
|
|
318
318
|
(acc, attr, attrName) => {
|
|
319
319
|
if (isComponentAttribute(attr))
|
|
@@ -324,7 +324,7 @@ const getComponentAttributes = (schema) => {
|
|
|
324
324
|
);
|
|
325
325
|
};
|
|
326
326
|
const getScalarAttributes = (schema) => {
|
|
327
|
-
return
|
|
327
|
+
return ___default.reduce(
|
|
328
328
|
schema.attributes,
|
|
329
329
|
(acc, attr, attrName) => {
|
|
330
330
|
if (isScalarAttribute(attr))
|
|
@@ -335,7 +335,7 @@ const getScalarAttributes = (schema) => {
|
|
|
335
335
|
);
|
|
336
336
|
};
|
|
337
337
|
const getRelationalAttributes = (schema) => {
|
|
338
|
-
return
|
|
338
|
+
return ___default.reduce(
|
|
339
339
|
schema.attributes,
|
|
340
340
|
(acc, attr, attrName) => {
|
|
341
341
|
if (isRelationalAttribute(attr))
|
|
@@ -346,10 +346,10 @@ const getRelationalAttributes = (schema) => {
|
|
|
346
346
|
);
|
|
347
347
|
};
|
|
348
348
|
const isTypedAttribute = (attribute, type) => {
|
|
349
|
-
return
|
|
349
|
+
return ___default.has(attribute, "type") && attribute.type === type;
|
|
350
350
|
};
|
|
351
351
|
const getContentTypeRoutePrefix = (contentType) => {
|
|
352
|
-
return isSingleType(contentType) ?
|
|
352
|
+
return isSingleType(contentType) ? ___default.kebabCase(contentType.info.singularName) : ___default.kebabCase(contentType.info.pluralName);
|
|
353
353
|
};
|
|
354
354
|
const contentTypes = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
355
355
|
__proto__: null,
|
|
@@ -883,7 +883,7 @@ const convertCountQueryParams = (countQuery) => {
|
|
|
883
883
|
const convertOrderingQueryParams = (ordering) => {
|
|
884
884
|
return ordering;
|
|
885
885
|
};
|
|
886
|
-
const isPlainObject = (value) =>
|
|
886
|
+
const isPlainObject = (value) => ___default.isPlainObject(value);
|
|
887
887
|
const isStringArray$3 = (value) => isArray(value) && value.every(isString);
|
|
888
888
|
const createTransformer = ({ getModel }) => {
|
|
889
889
|
const convertSortQueryParams = (sortQuery) => {
|
|
@@ -916,7 +916,7 @@ const createTransformer = ({ getModel }) => {
|
|
|
916
916
|
throw new Error("Field cannot be empty");
|
|
917
917
|
}
|
|
918
918
|
validateOrder(order);
|
|
919
|
-
return
|
|
919
|
+
return ___default.set({}, field, order);
|
|
920
920
|
};
|
|
921
921
|
const convertNestedSortQueryParam = (sortQuery) => {
|
|
922
922
|
const transformedSort = {};
|
|
@@ -934,15 +934,15 @@ const createTransformer = ({ getModel }) => {
|
|
|
934
934
|
return transformedSort;
|
|
935
935
|
};
|
|
936
936
|
const convertStartQueryParams = (startQuery) => {
|
|
937
|
-
const startAsANumber =
|
|
938
|
-
if (!
|
|
937
|
+
const startAsANumber = ___default.toNumber(startQuery);
|
|
938
|
+
if (!___default.isInteger(startAsANumber) || startAsANumber < 0) {
|
|
939
939
|
throw new Error(`convertStartQueryParams expected a positive integer got ${startAsANumber}`);
|
|
940
940
|
}
|
|
941
941
|
return startAsANumber;
|
|
942
942
|
};
|
|
943
943
|
const convertLimitQueryParams = (limitQuery) => {
|
|
944
|
-
const limitAsANumber =
|
|
945
|
-
if (!
|
|
944
|
+
const limitAsANumber = ___default.toNumber(limitQuery);
|
|
945
|
+
if (!___default.isInteger(limitAsANumber) || limitAsANumber !== -1 && limitAsANumber < 0) {
|
|
946
946
|
throw new Error(`convertLimitQueryParams expected a positive integer got ${limitAsANumber}`);
|
|
947
947
|
}
|
|
948
948
|
if (limitAsANumber === -1) {
|
|
@@ -988,19 +988,19 @@ const createTransformer = ({ getModel }) => {
|
|
|
988
988
|
return true;
|
|
989
989
|
}
|
|
990
990
|
if (typeof populate2 === "string") {
|
|
991
|
-
return populate2.split(",").map((value) =>
|
|
991
|
+
return populate2.split(",").map((value) => ___default.trim(value));
|
|
992
992
|
}
|
|
993
993
|
if (Array.isArray(populate2)) {
|
|
994
|
-
return
|
|
994
|
+
return ___default.uniq(
|
|
995
995
|
populate2.flatMap((value) => {
|
|
996
996
|
if (typeof value !== "string") {
|
|
997
997
|
throw new InvalidPopulateError();
|
|
998
998
|
}
|
|
999
|
-
return value.split(",").map((value2) =>
|
|
999
|
+
return value.split(",").map((value2) => ___default.trim(value2));
|
|
1000
1000
|
})
|
|
1001
1001
|
);
|
|
1002
1002
|
}
|
|
1003
|
-
if (
|
|
1003
|
+
if (___default.isPlainObject(populate2)) {
|
|
1004
1004
|
return convertPopulateObject(populate2, schema);
|
|
1005
1005
|
}
|
|
1006
1006
|
throw new InvalidPopulateError();
|
|
@@ -1014,7 +1014,7 @@ const createTransformer = ({ getModel }) => {
|
|
|
1014
1014
|
}
|
|
1015
1015
|
const { attributes } = schema;
|
|
1016
1016
|
return Object.entries(populate2).reduce((acc, [key, subPopulate]) => {
|
|
1017
|
-
if (
|
|
1017
|
+
if (___default.isBoolean(subPopulate)) {
|
|
1018
1018
|
return { ...acc, [key]: subPopulate };
|
|
1019
1019
|
}
|
|
1020
1020
|
const attribute = attributes[key];
|
|
@@ -1074,10 +1074,10 @@ const createTransformer = ({ getModel }) => {
|
|
|
1074
1074
|
}, {});
|
|
1075
1075
|
};
|
|
1076
1076
|
const convertNestedPopulate = (subPopulate, schema) => {
|
|
1077
|
-
if (
|
|
1077
|
+
if (___default.isString(subPopulate)) {
|
|
1078
1078
|
return parseType({ type: "boolean", value: subPopulate, forceCast: true });
|
|
1079
1079
|
}
|
|
1080
|
-
if (
|
|
1080
|
+
if (___default.isBoolean(subPopulate)) {
|
|
1081
1081
|
return subPopulate;
|
|
1082
1082
|
}
|
|
1083
1083
|
if (!isPlainObject(subPopulate)) {
|
|
@@ -1123,12 +1123,12 @@ const createTransformer = ({ getModel }) => {
|
|
|
1123
1123
|
return void 0;
|
|
1124
1124
|
}
|
|
1125
1125
|
if (typeof fields2 === "string") {
|
|
1126
|
-
const fieldsValues = fields2.split(",").map((value) =>
|
|
1127
|
-
return
|
|
1126
|
+
const fieldsValues = fields2.split(",").map((value) => ___default.trim(value));
|
|
1127
|
+
return ___default.uniq([ID_ATTRIBUTE$3, DOC_ID_ATTRIBUTE$3, ...fieldsValues]);
|
|
1128
1128
|
}
|
|
1129
1129
|
if (isStringArray$3(fields2)) {
|
|
1130
1130
|
const fieldsValues = fields2.flatMap((value) => convertFieldsQueryParams(value, depth + 1)).filter((v) => !isNil(v));
|
|
1131
|
-
return
|
|
1131
|
+
return ___default.uniq([ID_ATTRIBUTE$3, DOC_ID_ATTRIBUTE$3, ...fieldsValues]);
|
|
1132
1132
|
}
|
|
1133
1133
|
throw new Error("Invalid fields parameter. Expected a string or an array of strings");
|
|
1134
1134
|
};
|
|
@@ -2758,9 +2758,9 @@ const toRegressedEnumValue = (value) => slugify(value, {
|
|
|
2758
2758
|
separator: "_"
|
|
2759
2759
|
});
|
|
2760
2760
|
const getCommonPath = (...paths) => {
|
|
2761
|
-
const [segments, ...otherSegments] = paths.map((it) =>
|
|
2762
|
-
return
|
|
2763
|
-
|
|
2761
|
+
const [segments, ...otherSegments] = paths.map((it) => ___default.split(it, "/"));
|
|
2762
|
+
return ___default.join(
|
|
2763
|
+
___default.takeWhile(segments, (str, index2) => otherSegments.every((it) => it[index2] === str)),
|
|
2764
2764
|
"/"
|
|
2765
2765
|
);
|
|
2766
2766
|
};
|
|
@@ -2802,9 +2802,9 @@ const arrays = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProper
|
|
|
2802
2802
|
__proto__: null,
|
|
2803
2803
|
includesString
|
|
2804
2804
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
2805
|
-
const keysDeep = (obj, path = []) => !
|
|
2805
|
+
const keysDeep = (obj, path = []) => !___default.isObject(obj) ? [path.join(".")] : ___default.reduce(
|
|
2806
2806
|
obj,
|
|
2807
|
-
(acc, next, key) =>
|
|
2807
|
+
(acc, next, key) => ___default.concat(acc, keysDeep(next, [...path, key])),
|
|
2808
2808
|
[]
|
|
2809
2809
|
);
|
|
2810
2810
|
const objects = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
@@ -2868,8 +2868,8 @@ function printValue(value, quoteStrings) {
|
|
|
2868
2868
|
);
|
|
2869
2869
|
}
|
|
2870
2870
|
const strapiID = () => new StrapiIDSchema();
|
|
2871
|
-
const isNotNilTest = (value) => !
|
|
2872
|
-
const isNotNullTest = (value) => !
|
|
2871
|
+
const isNotNilTest = (value) => !___default.isNil(value);
|
|
2872
|
+
const isNotNullTest = (value) => !___default.isNull(value);
|
|
2873
2873
|
yup$1.addMethod(yup$1.mixed, "notNil", function isNotNill(msg = "${path} must be defined.") {
|
|
2874
2874
|
return this.test("defined", msg, isNotNilTest);
|
|
2875
2875
|
});
|
|
@@ -2880,7 +2880,7 @@ yup$1.addMethod(yup$1.mixed, "isFunction", function isFunction(message = "${path
|
|
|
2880
2880
|
return this.test(
|
|
2881
2881
|
"is a function",
|
|
2882
2882
|
message,
|
|
2883
|
-
(value) =>
|
|
2883
|
+
(value) => ___default.isUndefined(value) || ___default.isFunction(value)
|
|
2884
2884
|
);
|
|
2885
2885
|
});
|
|
2886
2886
|
yup$1.addMethod(
|
|
@@ -2912,7 +2912,7 @@ yup$1.addMethod(
|
|
|
2912
2912
|
return this.test(
|
|
2913
2913
|
"only contains functions",
|
|
2914
2914
|
message,
|
|
2915
|
-
(value) =>
|
|
2915
|
+
(value) => ___default.isUndefined(value) || value && Object.values(value).every(___default.isFunction)
|
|
2916
2916
|
);
|
|
2917
2917
|
}
|
|
2918
2918
|
);
|