@strapi/utils 5.52.0 → 5.52.2
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/zod.d.ts +5 -5
- package/dist/zod.js.map +1 -1
- package/dist/zod.mjs.map +1 -1
- package/package.json +5 -5
package/dist/zod.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import * as z from 'zod/v4';
|
|
2
2
|
/**
|
|
3
3
|
* Re-export of the Zod v4 schema builder from the same version Strapi uses
|
|
4
|
-
* internally.
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* internally. Intended for packages that already depend on `@strapi/utils`.
|
|
5
|
+
*
|
|
6
|
+
* For `contentAPI.addQueryParams` / `addInputParams`, pass a factory instead
|
|
7
|
+
* of importing this `z` (or `zod` / `zod/v4`). Strapi supplies its own Zod:
|
|
7
8
|
*
|
|
8
9
|
* @example
|
|
9
|
-
* import { z } from '@strapi/utils';
|
|
10
10
|
* strapi.contentAPI.addQueryParams({
|
|
11
11
|
* search: {
|
|
12
|
-
* schema: z.string().max(200).optional(),
|
|
12
|
+
* schema: (z) => z.string().max(200).optional(),
|
|
13
13
|
* matchRoute: (route) => route.path.includes('articles'),
|
|
14
14
|
* },
|
|
15
15
|
* });
|
package/dist/zod.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zod.js","sources":["../src/zod.ts"],"sourcesContent":["import * as z from 'zod/v4';\n\nimport { ValidationError } from './errors';\n\n/**\n * Re-export of the Zod v4 schema builder from the same version Strapi uses\n * internally.
|
|
1
|
+
{"version":3,"file":"zod.js","sources":["../src/zod.ts"],"sourcesContent":["import * as z from 'zod/v4';\n\nimport { ValidationError } from './errors';\n\n/**\n * Re-export of the Zod v4 schema builder from the same version Strapi uses\n * internally. Intended for packages that already depend on `@strapi/utils`.\n *\n * For `contentAPI.addQueryParams` / `addInputParams`, pass a factory instead\n * of importing this `z` (or `zod` / `zod/v4`). Strapi supplies its own Zod:\n *\n * @example\n * strapi.contentAPI.addQueryParams({\n * search: {\n * schema: (z) => z.string().max(200).optional(),\n * matchRoute: (route) => route.path.includes('articles'),\n * },\n * });\n */\nexport { z };\n\nexport const validateZodSchema =\n <T extends z.Schema>(schema: T) =>\n (data: unknown, errorMessage?: string): z.infer<T> => {\n try {\n return schema.parse(data);\n } catch (error) {\n if (error instanceof z.ZodError) {\n const { message, errors } = formatZodErrors(error);\n throw new ValidationError(errorMessage || message, { errors });\n }\n\n throw error;\n }\n };\n\nconst formatZodErrors = (zodError: z.ZodError) => ({\n errors: zodError.issues.map((issue) => {\n return {\n path: issue.path.map(String),\n message: issue.message,\n name: 'ValidationError',\n value: undefined,\n };\n }),\n message: zodError.issues[0]?.message ?? 'Validation error',\n});\n\ntype FormErrors = Record<string, string>;\n\n/**\n * Converts a ZodError into form-compatible errors matching\n * getYupValidationErrors from @strapi/admin Form component.\n *\n * Returns a flat object with dot-path keys and string error messages.\n * Only the first error per path is kept (matches Yup behavior).\n * Root-level errors (path = []) are stored under the empty string key ''.\n */\nexport const getZodValidationErrors = (error: z.ZodError): FormErrors => {\n const errors: FormErrors = {};\n\n for (const issue of error.issues) {\n const path = issue.path.join('.');\n if (!(path in errors)) {\n errors[path] = issue.message;\n }\n }\n\n return errors;\n};\n"],"names":["validateZodSchema","schema","data","errorMessage","parse","error","z","ZodError","message","errors","formatZodErrors","ValidationError","zodError","issues","map","issue","path","String","name","value","undefined","getZodValidationErrors","join"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAqBO,MAAMA,iBAAAA,GACX,CAAqBC,MAAAA,GACrB,CAACC,IAAAA,EAAeC,YAAAA,GAAAA;QACd,IAAI;YACF,OAAOF,MAAAA,CAAOG,KAAK,CAACF,IAAAA,CAAAA;AACtB,QAAA,CAAA,CAAE,OAAOG,KAAAA,EAAO;YACd,IAAIA,KAAAA,YAAiBC,YAAAA,CAAEC,QAAQ,EAAE;AAC/B,gBAAA,MAAM,EAAE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import { ValidationError } from './errors';\n\n/**\n * Re-export of the Zod v4 schema builder from the same version Strapi uses\n * internally.
|
|
1
|
+
{"version":3,"file":"zod.mjs","sources":["../src/zod.ts"],"sourcesContent":["import * as z from 'zod/v4';\n\nimport { ValidationError } from './errors';\n\n/**\n * Re-export of the Zod v4 schema builder from the same version Strapi uses\n * internally. Intended for packages that already depend on `@strapi/utils`.\n *\n * For `contentAPI.addQueryParams` / `addInputParams`, pass a factory instead\n * of importing this `z` (or `zod` / `zod/v4`). Strapi supplies its own Zod:\n *\n * @example\n * strapi.contentAPI.addQueryParams({\n * search: {\n * schema: (z) => z.string().max(200).optional(),\n * matchRoute: (route) => route.path.includes('articles'),\n * },\n * });\n */\nexport { z };\n\nexport const validateZodSchema =\n <T extends z.Schema>(schema: T) =>\n (data: unknown, errorMessage?: string): z.infer<T> => {\n try {\n return schema.parse(data);\n } catch (error) {\n if (error instanceof z.ZodError) {\n const { message, errors } = formatZodErrors(error);\n throw new ValidationError(errorMessage || message, { errors });\n }\n\n throw error;\n }\n };\n\nconst formatZodErrors = (zodError: z.ZodError) => ({\n errors: zodError.issues.map((issue) => {\n return {\n path: issue.path.map(String),\n message: issue.message,\n name: 'ValidationError',\n value: undefined,\n };\n }),\n message: zodError.issues[0]?.message ?? 'Validation error',\n});\n\ntype FormErrors = Record<string, string>;\n\n/**\n * Converts a ZodError into form-compatible errors matching\n * getYupValidationErrors from @strapi/admin Form component.\n *\n * Returns a flat object with dot-path keys and string error messages.\n * Only the first error per path is kept (matches Yup behavior).\n * Root-level errors (path = []) are stored under the empty string key ''.\n */\nexport const getZodValidationErrors = (error: z.ZodError): FormErrors => {\n const errors: FormErrors = {};\n\n for (const issue of error.issues) {\n const path = issue.path.join('.');\n if (!(path in errors)) {\n errors[path] = issue.message;\n }\n }\n\n return errors;\n};\n"],"names":["validateZodSchema","schema","data","errorMessage","parse","error","z","ZodError","message","errors","formatZodErrors","ValidationError","zodError","issues","map","issue","path","String","name","value","undefined","getZodValidationErrors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N,IAAAA,IAAQP,MAAK,CAAA,EAAI;AACrBA,YAAAA,MAAM,CAACO,IAAAA,CAAK,GAAGD,KAAAA,CAAMP,OAAO;AAC9B,QAAA;AACF,IAAA;IAEA,OAAOC,MAAAA;AACT;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/utils",
|
|
3
|
-
"version": "5.52.
|
|
3
|
+
"version": "5.52.2",
|
|
4
4
|
"description": "Shared utilities for the Strapi packages",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"strapi",
|
|
@@ -58,20 +58,20 @@
|
|
|
58
58
|
"p-map": "4.0.0",
|
|
59
59
|
"preferred-pm": "5.0.0",
|
|
60
60
|
"yup": "0.32.9",
|
|
61
|
-
"zod": "
|
|
61
|
+
"zod": "4.4.3"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"@types/http-errors": "2.0.4",
|
|
65
65
|
"@types/jest": "29.5.2",
|
|
66
66
|
"@types/koa": "2.15.2",
|
|
67
67
|
"@types/node": "20.19.41",
|
|
68
|
-
"eslint-config-custom": "5.52.
|
|
68
|
+
"eslint-config-custom": "5.52.2",
|
|
69
69
|
"jest": "29.6.0",
|
|
70
70
|
"koa": "2.16.4",
|
|
71
71
|
"koa-body": "6.0.1",
|
|
72
|
-
"tsconfig": "5.52.
|
|
72
|
+
"tsconfig": "5.52.2",
|
|
73
73
|
"vitest": "catalog:",
|
|
74
|
-
"vitest-config": "5.52.
|
|
74
|
+
"vitest-config": "5.52.2"
|
|
75
75
|
},
|
|
76
76
|
"engines": {
|
|
77
77
|
"node": ">=20.0.0 <=26.x.x",
|