@strapi/utils 5.0.0-beta.1 → 5.0.0-beta.3

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/index.mjs CHANGED
@@ -9,6 +9,7 @@ import execa from "execa";
9
9
  import preferredPM from "preferred-pm";
10
10
  import { Writable } from "node:stream";
11
11
  import slugify from "@sindresorhus/slugify";
12
+ import { z } from "zod";
12
13
  function _mergeNamespaces(n, m) {
13
14
  for (var i = 0; i < m.length; i++) {
14
15
  const e = m[i];
@@ -333,6 +334,17 @@ const getScalarAttributes = (schema) => {
333
334
  []
334
335
  );
335
336
  };
337
+ const getRelationalAttributes = (schema) => {
338
+ return _$1.reduce(
339
+ schema.attributes,
340
+ (acc, attr, attrName) => {
341
+ if (isRelationalAttribute(attr))
342
+ acc.push(attrName);
343
+ return acc;
344
+ },
345
+ []
346
+ );
347
+ };
336
348
  const isTypedAttribute = (attribute, type) => {
337
349
  return _$1.has(attribute, "type") && attribute.type === type;
338
350
  };
@@ -349,6 +361,7 @@ const contentTypes = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.define
349
361
  getNonWritableAttributes,
350
362
  getOptions,
351
363
  getPrivateAttributes,
364
+ getRelationalAttributes,
352
365
  getScalarAttributes,
353
366
  getTimestamps,
354
367
  getVisibleAttributes,
@@ -2974,6 +2987,27 @@ const relations = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePro
2974
2987
  isManyToAny,
2975
2988
  isOneToAny
2976
2989
  }, Symbol.toStringTag, { value: "Module" }));
2990
+ const validateZod = (schema) => (data) => {
2991
+ try {
2992
+ return schema.parse(data);
2993
+ } catch (error) {
2994
+ if (error instanceof z.ZodError) {
2995
+ const { message, errors: errors2 } = formatZodErrors(error);
2996
+ throw new ValidationError(message, { errors: errors2 });
2997
+ }
2998
+ throw error;
2999
+ }
3000
+ };
3001
+ const formatZodErrors = (zodError) => ({
3002
+ errors: zodError.errors.map((error) => {
3003
+ return {
3004
+ path: error.path,
3005
+ message: error.message,
3006
+ name: "ValidationError"
3007
+ };
3008
+ }),
3009
+ message: "Validation error"
3010
+ });
2977
3011
  export {
2978
3012
  arrays,
2979
3013
  async,
@@ -3004,6 +3038,7 @@ export {
3004
3038
  index as validate,
3005
3039
  validateYupSchema,
3006
3040
  validateYupSchemaSync,
3041
+ validateZod,
3007
3042
  yup
3008
3043
  };
3009
3044
  //# sourceMappingURL=index.mjs.map