@strapi/utils 5.19.0 → 5.21.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.
Files changed (39) hide show
  1. package/dist/content-types.d.ts +3 -1
  2. package/dist/content-types.d.ts.map +1 -1
  3. package/dist/content-types.js +4 -0
  4. package/dist/content-types.js.map +1 -1
  5. package/dist/content-types.mjs +4 -1
  6. package/dist/content-types.mjs.map +1 -1
  7. package/dist/index.d.ts +1 -0
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +19 -0
  10. package/dist/index.js.map +1 -1
  11. package/dist/index.mjs +3 -0
  12. package/dist/index.mjs.map +1 -1
  13. package/dist/validation/index.d.ts +3 -0
  14. package/dist/validation/index.d.ts.map +1 -0
  15. package/dist/validation/route-validators/base.d.ts +107 -0
  16. package/dist/validation/route-validators/base.d.ts.map +1 -0
  17. package/dist/validation/route-validators/base.js +92 -0
  18. package/dist/validation/route-validators/base.js.map +1 -0
  19. package/dist/validation/route-validators/base.mjs +90 -0
  20. package/dist/validation/route-validators/base.mjs.map +1 -0
  21. package/dist/validation/route-validators/index.d.ts +39 -0
  22. package/dist/validation/route-validators/index.d.ts.map +1 -0
  23. package/dist/validation/route-validators/query-params.d.ts +100 -0
  24. package/dist/validation/route-validators/query-params.d.ts.map +1 -0
  25. package/dist/validation/route-validators/query-params.js +117 -0
  26. package/dist/validation/route-validators/query-params.js.map +1 -0
  27. package/dist/validation/route-validators/query-params.mjs +88 -0
  28. package/dist/validation/route-validators/query-params.mjs.map +1 -0
  29. package/dist/validation/utilities.d.ts +81 -0
  30. package/dist/validation/utilities.d.ts.map +1 -0
  31. package/dist/validation/utilities.js +123 -0
  32. package/dist/validation/utilities.js.map +1 -0
  33. package/dist/validation/utilities.mjs +116 -0
  34. package/dist/validation/utilities.mjs.map +1 -0
  35. package/dist/zod.js +2 -2
  36. package/dist/zod.js.map +1 -1
  37. package/dist/zod.mjs +2 -2
  38. package/dist/zod.mjs.map +1 -1
  39. package/package.json +4 -4
@@ -0,0 +1,90 @@
1
+ import { queryParameterSchemas } from './query-params.mjs';
2
+
3
+ /**
4
+ * AbstractRouteValidator provides the foundation for validating routes.
5
+ *
6
+ * This abstract class provides common query parameter validators that can be reused
7
+ * across different route validators in Strapi. It serves as a building block for
8
+ * both generic validation (plugins, external packages) and schema-aware validation
9
+ * (core content types).
10
+ */ class AbstractRouteValidator {
11
+ /**
12
+ * Creates a fields query parameter validator
13
+ * Validates field selection for API responses
14
+ */ get queryFields() {
15
+ return queryParameterSchemas.fields;
16
+ }
17
+ /**
18
+ * Creates a populate query parameter validator
19
+ * Validates which relations to populate in the response
20
+ */ get queryPopulate() {
21
+ return queryParameterSchemas.populate;
22
+ }
23
+ /**
24
+ * Creates a sort query parameter validator
25
+ * Validates sorting options for list endpoints
26
+ */ get querySort() {
27
+ return queryParameterSchemas.sort;
28
+ }
29
+ /**
30
+ * Creates a pagination query parameter validator
31
+ * Supports both page-based and offset-based pagination
32
+ */ get pagination() {
33
+ return queryParameterSchemas.pagination;
34
+ }
35
+ /**
36
+ * Creates a filters query parameter validator
37
+ * Validates filtering options for list endpoints
38
+ */ get filters() {
39
+ return queryParameterSchemas.filters;
40
+ }
41
+ /**
42
+ * Creates a locale query parameter validator
43
+ * Used for internationalization
44
+ */ get locale() {
45
+ return queryParameterSchemas.locale;
46
+ }
47
+ /**
48
+ * Creates a status query parameter validator
49
+ * Used for draft & publish functionality
50
+ */ get status() {
51
+ return queryParameterSchemas.status;
52
+ }
53
+ /**
54
+ * Creates a search query parameter validator
55
+ * Used for text search functionality
56
+ */ get query() {
57
+ return queryParameterSchemas._q;
58
+ }
59
+ /**
60
+ * Provides access to all base query parameter validators
61
+ */ get baseQueryValidators() {
62
+ return {
63
+ fields: ()=>this.queryFields.optional(),
64
+ populate: ()=>this.queryPopulate.optional(),
65
+ sort: ()=>this.querySort.optional(),
66
+ filters: ()=>this.filters.optional(),
67
+ pagination: ()=>this.pagination.optional(),
68
+ locale: ()=>this.locale.optional(),
69
+ status: ()=>this.status.optional(),
70
+ _q: ()=>this.query.optional()
71
+ };
72
+ }
73
+ /**
74
+ * Helper method to create a query parameters object with specified validators
75
+ *
76
+ * @param params - Array of query parameter names to include
77
+ * @returns Object containing Zod schemas for the requested query parameters
78
+ */ queryParams(params) {
79
+ const validators = this.baseQueryValidators;
80
+ return params.reduce((acc, param)=>{
81
+ if (param in validators) {
82
+ acc[param] = validators[param]();
83
+ }
84
+ return acc;
85
+ }, {});
86
+ }
87
+ }
88
+
89
+ export { AbstractRouteValidator };
90
+ //# sourceMappingURL=base.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.mjs","sources":["../../../src/validation/route-validators/base.ts"],"sourcesContent":["import * as z from 'zod/v4';\nimport { queryParameterSchemas, type QueryParam } from './query-params';\n\n/**\n * AbstractRouteValidator provides the foundation for validating routes.\n *\n * This abstract class provides common query parameter validators that can be reused\n * across different route validators in Strapi. It serves as a building block for\n * both generic validation (plugins, external packages) and schema-aware validation\n * (core content types).\n */\nexport abstract class AbstractRouteValidator {\n /**\n * Creates a fields query parameter validator\n * Validates field selection for API responses\n */\n get queryFields() {\n return queryParameterSchemas.fields;\n }\n\n /**\n * Creates a populate query parameter validator\n * Validates which relations to populate in the response\n */\n get queryPopulate() {\n return queryParameterSchemas.populate;\n }\n\n /**\n * Creates a sort query parameter validator\n * Validates sorting options for list endpoints\n */\n get querySort() {\n return queryParameterSchemas.sort;\n }\n\n /**\n * Creates a pagination query parameter validator\n * Supports both page-based and offset-based pagination\n */\n get pagination() {\n return queryParameterSchemas.pagination;\n }\n\n /**\n * Creates a filters query parameter validator\n * Validates filtering options for list endpoints\n */\n get filters() {\n return queryParameterSchemas.filters;\n }\n\n /**\n * Creates a locale query parameter validator\n * Used for internationalization\n */\n get locale() {\n return queryParameterSchemas.locale;\n }\n\n /**\n * Creates a status query parameter validator\n * Used for draft & publish functionality\n */\n get status() {\n return queryParameterSchemas.status;\n }\n\n /**\n * Creates a search query parameter validator\n * Used for text search functionality\n */\n get query() {\n return queryParameterSchemas._q;\n }\n\n /**\n * Provides access to all base query parameter validators\n */\n protected get baseQueryValidators() {\n return {\n fields: () => this.queryFields.optional(),\n populate: () => this.queryPopulate.optional(),\n sort: () => this.querySort.optional(),\n filters: () => this.filters.optional(),\n pagination: () => this.pagination.optional(),\n locale: () => this.locale.optional(),\n status: () => this.status.optional(),\n _q: () => this.query.optional(),\n };\n }\n\n /**\n * Helper method to create a query parameters object with specified validators\n *\n * @param params - Array of query parameter names to include\n * @returns Object containing Zod schemas for the requested query parameters\n */\n queryParams(params: QueryParam[]): Record<string, z.ZodSchema> {\n const validators = this.baseQueryValidators;\n\n return params.reduce(\n (acc, param) => {\n if (param in validators) {\n acc[param] = validators[param]();\n }\n return acc;\n },\n {} as Record<string, z.ZodSchema>\n );\n }\n}\n"],"names":["AbstractRouteValidator","queryFields","queryParameterSchemas","fields","queryPopulate","populate","querySort","sort","pagination","filters","locale","status","query","_q","baseQueryValidators","optional","queryParams","params","validators","reduce","acc","param"],"mappings":";;AAGA;;;;;;;AAOC,IACM,MAAeA,sBAAAA,CAAAA;AACpB;;;AAGC,MACD,IAAIC,WAAc,GAAA;AAChB,QAAA,OAAOC,sBAAsBC,MAAM;AACrC;AAEA;;;AAGC,MACD,IAAIC,aAAgB,GAAA;AAClB,QAAA,OAAOF,sBAAsBG,QAAQ;AACvC;AAEA;;;AAGC,MACD,IAAIC,SAAY,GAAA;AACd,QAAA,OAAOJ,sBAAsBK,IAAI;AACnC;AAEA;;;AAGC,MACD,IAAIC,UAAa,GAAA;AACf,QAAA,OAAON,sBAAsBM,UAAU;AACzC;AAEA;;;AAGC,MACD,IAAIC,OAAU,GAAA;AACZ,QAAA,OAAOP,sBAAsBO,OAAO;AACtC;AAEA;;;AAGC,MACD,IAAIC,MAAS,GAAA;AACX,QAAA,OAAOR,sBAAsBQ,MAAM;AACrC;AAEA;;;AAGC,MACD,IAAIC,MAAS,GAAA;AACX,QAAA,OAAOT,sBAAsBS,MAAM;AACrC;AAEA;;;AAGC,MACD,IAAIC,KAAQ,GAAA;AACV,QAAA,OAAOV,sBAAsBW,EAAE;AACjC;AAEA;;AAEC,MACD,IAAcC,mBAAsB,GAAA;QAClC,OAAO;AACLX,YAAAA,MAAAA,EAAQ,IAAM,IAAI,CAACF,WAAW,CAACc,QAAQ,EAAA;AACvCV,YAAAA,QAAAA,EAAU,IAAM,IAAI,CAACD,aAAa,CAACW,QAAQ,EAAA;AAC3CR,YAAAA,IAAAA,EAAM,IAAM,IAAI,CAACD,SAAS,CAACS,QAAQ,EAAA;AACnCN,YAAAA,OAAAA,EAAS,IAAM,IAAI,CAACA,OAAO,CAACM,QAAQ,EAAA;AACpCP,YAAAA,UAAAA,EAAY,IAAM,IAAI,CAACA,UAAU,CAACO,QAAQ,EAAA;AAC1CL,YAAAA,MAAAA,EAAQ,IAAM,IAAI,CAACA,MAAM,CAACK,QAAQ,EAAA;AAClCJ,YAAAA,MAAAA,EAAQ,IAAM,IAAI,CAACA,MAAM,CAACI,QAAQ,EAAA;AAClCF,YAAAA,EAAAA,EAAI,IAAM,IAAI,CAACD,KAAK,CAACG,QAAQ;AAC/B,SAAA;AACF;AAEA;;;;;MAMAC,WAAAA,CAAYC,MAAoB,EAA+B;QAC7D,MAAMC,UAAAA,GAAa,IAAI,CAACJ,mBAAmB;AAE3C,QAAA,OAAOG,MAAOE,CAAAA,MAAM,CAClB,CAACC,GAAKC,EAAAA,KAAAA,GAAAA;AACJ,YAAA,IAAIA,SAASH,UAAY,EAAA;AACvBE,gBAAAA,GAAG,CAACC,KAAAA,CAAM,GAAGH,UAAU,CAACG,KAAM,CAAA,EAAA;AAChC;YACA,OAAOD,GAAAA;AACT,SAAA,EACA,EAAC,CAAA;AAEL;AACF;;;;"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Route validation utilities for Strapi
3
+ *
4
+ * This module provides route validation that can be used across different
5
+ * packages & plugins.
6
+ *
7
+ * The utilities are designed to work both standalone (for generic validation) and
8
+ * as building blocks for more sophisticated schema-aware validation via @strapi/core.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * import { AbstractRouteValidator, type QueryParam } from '@strapi/utils';
13
+ * import * as z from 'zod/v4';
14
+ *
15
+ * export class MyPluginRouteValidator extends AbstractRouteValidator {
16
+ * constructor(strapi: Core.Strapi) {
17
+ * super();
18
+ * }
19
+ *
20
+ * // Add custom validators for your plugin
21
+ * get myEntity() {
22
+ * return z.object({
23
+ * id: z.number(),
24
+ * name: z.string(),
25
+ * // ... other fields
26
+ * });
27
+ * }
28
+ *
29
+ * // Use inherited query parameter validators
30
+ * // In your routes:
31
+ * // request: {
32
+ * // query: validator.queryParams(['fields', 'populate', 'sort', 'pagination'])
33
+ * // }
34
+ * }
35
+ * ```
36
+ */
37
+ export { AbstractRouteValidator } from './base';
38
+ export * from './query-params';
39
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/validation/route-validators/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,OAAO,EAAE,sBAAsB,EAAE,MAAM,QAAQ,CAAC;AAChD,cAAc,gBAAgB,CAAC"}
@@ -0,0 +1,100 @@
1
+ import * as z from 'zod/v4';
2
+ /**
3
+ * Standard query parameter validators that can be reused across different route validators
4
+ *
5
+ * These schemas provide the basic structure validation for common Strapi API query parameters.
6
+ * They can be used as building blocks for both generic validation and schema-aware validation.
7
+ */
8
+ /**
9
+ * Fields parameter validation
10
+ * Supports: 'title', ['title', 'name'], or '*'
11
+ */
12
+ export declare const queryFieldsSchema: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>;
13
+ /**
14
+ * Populate parameter validation
15
+ * Supports: '*', 'relation', ['relation1', 'relation2'], or complex objects
16
+ */
17
+ export declare const queryPopulateSchema: z.ZodUnion<readonly [z.ZodLiteral<"*">, z.ZodString, z.ZodArray<z.ZodString>, z.ZodRecord<z.ZodString, z.ZodAny>]>;
18
+ /**
19
+ * Sort parameter validation
20
+ * Supports: 'name', ['name', 'title'], { name: 'asc' }, or [{ name: 'desc' }]
21
+ */
22
+ export declare const querySortSchema: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>, z.ZodRecord<z.ZodString, z.ZodEnum<{
23
+ asc: "asc";
24
+ desc: "desc";
25
+ }>>, z.ZodArray<z.ZodRecord<z.ZodString, z.ZodEnum<{
26
+ asc: "asc";
27
+ desc: "desc";
28
+ }>>>]>;
29
+ /**
30
+ * Pagination parameter validation
31
+ * Supports both page-based and offset-based pagination
32
+ */
33
+ export declare const paginationSchema: z.ZodIntersection<z.ZodObject<{
34
+ withCount: z.ZodOptional<z.ZodBoolean>;
35
+ }, z.core.$strip>, z.ZodUnion<readonly [z.ZodObject<{
36
+ page: z.ZodNumber;
37
+ pageSize: z.ZodNumber;
38
+ }, z.core.$strip>, z.ZodObject<{
39
+ start: z.ZodNumber;
40
+ limit: z.ZodNumber;
41
+ }, z.core.$strip>]>>;
42
+ /**
43
+ * Filters parameter validation
44
+ * Supports any object structure for filtering
45
+ */
46
+ export declare const filtersSchema: z.ZodRecord<z.ZodString, z.ZodAny>;
47
+ /**
48
+ * Locale parameter validation
49
+ * Used for internationalization
50
+ */
51
+ export declare const localeSchema: z.ZodString;
52
+ /**
53
+ * Status parameter validation
54
+ * Used for draft & publish functionality
55
+ */
56
+ export declare const statusSchema: z.ZodEnum<{
57
+ draft: "draft";
58
+ published: "published";
59
+ }>;
60
+ /**
61
+ * Search query parameter validation
62
+ * Used for text search functionality
63
+ */
64
+ export declare const searchQuerySchema: z.ZodString;
65
+ /**
66
+ * Complete collection of all standard query parameter schemas
67
+ * This object provides easy access to all available query parameter validators
68
+ */
69
+ export declare const queryParameterSchemas: {
70
+ readonly fields: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>;
71
+ readonly populate: z.ZodUnion<readonly [z.ZodLiteral<"*">, z.ZodString, z.ZodArray<z.ZodString>, z.ZodRecord<z.ZodString, z.ZodAny>]>;
72
+ readonly sort: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>, z.ZodRecord<z.ZodString, z.ZodEnum<{
73
+ asc: "asc";
74
+ desc: "desc";
75
+ }>>, z.ZodArray<z.ZodRecord<z.ZodString, z.ZodEnum<{
76
+ asc: "asc";
77
+ desc: "desc";
78
+ }>>>]>;
79
+ readonly pagination: z.ZodIntersection<z.ZodObject<{
80
+ withCount: z.ZodOptional<z.ZodBoolean>;
81
+ }, z.core.$strip>, z.ZodUnion<readonly [z.ZodObject<{
82
+ page: z.ZodNumber;
83
+ pageSize: z.ZodNumber;
84
+ }, z.core.$strip>, z.ZodObject<{
85
+ start: z.ZodNumber;
86
+ limit: z.ZodNumber;
87
+ }, z.core.$strip>]>>;
88
+ readonly filters: z.ZodRecord<z.ZodString, z.ZodAny>;
89
+ readonly locale: z.ZodString;
90
+ readonly status: z.ZodEnum<{
91
+ draft: "draft";
92
+ published: "published";
93
+ }>;
94
+ readonly _q: z.ZodString;
95
+ };
96
+ /**
97
+ * Query parameter names supported by Strapi's API
98
+ */
99
+ export type QueryParam = keyof typeof queryParameterSchemas;
100
+ //# sourceMappingURL=query-params.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query-params.d.ts","sourceRoot":"","sources":["../../../src/validation/route-validators/query-params.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAE5B;;;;;GAKG;AAEH;;;GAGG;AACH,eAAO,MAAM,iBAAiB,6DAEiC,CAAC;AAEhE;;;GAGG;AACH,eAAO,MAAM,mBAAmB,oHAEkC,CAAC;AAEnE;;;GAGG;AACH,eAAO,MAAM,eAAe;;;;;;MAOuB,CAAC;AAEpD;;;GAGG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;oBAoBO,CAAC;AAErC;;;GAGG;AACH,eAAO,MAAM,aAAa,oCAAuE,CAAC;AAElG;;;GAGG;AACH,eAAO,MAAM,YAAY,aAAkE,CAAC;AAE5F;;;GAGG;AACH,eAAO,MAAM,YAAY;;;EAA0E,CAAC;AAEpG;;;GAGG;AACH,eAAO,MAAM,iBAAiB,aAA6C,CAAC;AAE5E;;;GAGG;AACH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;CASxB,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,OAAO,qBAAqB,CAAC"}
@@ -0,0 +1,117 @@
1
+ 'use strict';
2
+
3
+ var z = require('zod/v4');
4
+
5
+ function _interopNamespaceDefault(e) {
6
+ var n = Object.create(null);
7
+ if (e) {
8
+ Object.keys(e).forEach(function (k) {
9
+ if (k !== 'default') {
10
+ var d = Object.getOwnPropertyDescriptor(e, k);
11
+ Object.defineProperty(n, k, d.get ? d : {
12
+ enumerable: true,
13
+ get: function () { return e[k]; }
14
+ });
15
+ }
16
+ });
17
+ }
18
+ n.default = e;
19
+ return Object.freeze(n);
20
+ }
21
+
22
+ var z__namespace = /*#__PURE__*/_interopNamespaceDefault(z);
23
+
24
+ /**
25
+ * Standard query parameter validators that can be reused across different route validators
26
+ *
27
+ * These schemas provide the basic structure validation for common Strapi API query parameters.
28
+ * They can be used as building blocks for both generic validation and schema-aware validation.
29
+ */ /**
30
+ * Fields parameter validation
31
+ * Supports: 'title', ['title', 'name'], or '*'
32
+ */ const queryFieldsSchema = z__namespace.union([
33
+ z__namespace.string(),
34
+ z__namespace.array(z__namespace.string())
35
+ ]).describe('Select specific fields to return in the response');
36
+ /**
37
+ * Populate parameter validation
38
+ * Supports: '*', 'relation', ['relation1', 'relation2'], or complex objects
39
+ */ const queryPopulateSchema = z__namespace.union([
40
+ z__namespace.literal('*'),
41
+ z__namespace.string(),
42
+ z__namespace.array(z__namespace.string()),
43
+ z__namespace.record(z__namespace.string(), z__namespace.any())
44
+ ]).describe('Specify which relations to populate in the response');
45
+ /**
46
+ * Sort parameter validation
47
+ * Supports: 'name', ['name', 'title'], { name: 'asc' }, or [{ name: 'desc' }]
48
+ */ const querySortSchema = z__namespace.union([
49
+ z__namespace.string(),
50
+ z__namespace.array(z__namespace.string()),
51
+ z__namespace.record(z__namespace.string(), z__namespace.enum([
52
+ 'asc',
53
+ 'desc'
54
+ ])),
55
+ z__namespace.array(z__namespace.record(z__namespace.string(), z__namespace.enum([
56
+ 'asc',
57
+ 'desc'
58
+ ])))
59
+ ]).describe('Sort the results by specified fields');
60
+ /**
61
+ * Pagination parameter validation
62
+ * Supports both page-based and offset-based pagination
63
+ */ const paginationSchema = z__namespace.intersection(z__namespace.object({
64
+ withCount: z__namespace.boolean().optional().describe('Include total count in response')
65
+ }), z__namespace.union([
66
+ z__namespace.object({
67
+ page: z__namespace.number().int().positive().describe('Page number (1-based)'),
68
+ pageSize: z__namespace.number().int().positive().describe('Number of entries per page')
69
+ }).describe('Page-based pagination'),
70
+ z__namespace.object({
71
+ start: z__namespace.number().int().min(0).describe('Number of entries to skip'),
72
+ limit: z__namespace.number().int().positive().describe('Maximum number of entries to return')
73
+ }).describe('Offset-based pagination')
74
+ ])).describe('Pagination parameters');
75
+ /**
76
+ * Filters parameter validation
77
+ * Supports any object structure for filtering
78
+ */ const filtersSchema = z__namespace.record(z__namespace.string(), z__namespace.any()).describe('Apply filters to the query');
79
+ /**
80
+ * Locale parameter validation
81
+ * Used for internationalization
82
+ */ const localeSchema = z__namespace.string().describe('Specify the locale for localized content');
83
+ /**
84
+ * Status parameter validation
85
+ * Used for draft & publish functionality
86
+ */ const statusSchema = z__namespace.enum([
87
+ 'draft',
88
+ 'published'
89
+ ]).describe('Filter by publication status');
90
+ /**
91
+ * Search query parameter validation
92
+ * Used for text search functionality
93
+ */ const searchQuerySchema = z__namespace.string().describe('Search query string');
94
+ /**
95
+ * Complete collection of all standard query parameter schemas
96
+ * This object provides easy access to all available query parameter validators
97
+ */ const queryParameterSchemas = {
98
+ fields: queryFieldsSchema,
99
+ populate: queryPopulateSchema,
100
+ sort: querySortSchema,
101
+ pagination: paginationSchema,
102
+ filters: filtersSchema,
103
+ locale: localeSchema,
104
+ status: statusSchema,
105
+ _q: searchQuerySchema
106
+ };
107
+
108
+ exports.filtersSchema = filtersSchema;
109
+ exports.localeSchema = localeSchema;
110
+ exports.paginationSchema = paginationSchema;
111
+ exports.queryFieldsSchema = queryFieldsSchema;
112
+ exports.queryParameterSchemas = queryParameterSchemas;
113
+ exports.queryPopulateSchema = queryPopulateSchema;
114
+ exports.querySortSchema = querySortSchema;
115
+ exports.searchQuerySchema = searchQuerySchema;
116
+ exports.statusSchema = statusSchema;
117
+ //# sourceMappingURL=query-params.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query-params.js","sources":["../../../src/validation/route-validators/query-params.ts"],"sourcesContent":["import * as z from 'zod/v4';\n\n/**\n * Standard query parameter validators that can be reused across different route validators\n *\n * These schemas provide the basic structure validation for common Strapi API query parameters.\n * They can be used as building blocks for both generic validation and schema-aware validation.\n */\n\n/**\n * Fields parameter validation\n * Supports: 'title', ['title', 'name'], or '*'\n */\nexport const queryFieldsSchema = z\n .union([z.string(), z.array(z.string())])\n .describe('Select specific fields to return in the response');\n\n/**\n * Populate parameter validation\n * Supports: '*', 'relation', ['relation1', 'relation2'], or complex objects\n */\nexport const queryPopulateSchema = z\n .union([z.literal('*'), z.string(), z.array(z.string()), z.record(z.string(), z.any())])\n .describe('Specify which relations to populate in the response');\n\n/**\n * Sort parameter validation\n * Supports: 'name', ['name', 'title'], { name: 'asc' }, or [{ name: 'desc' }]\n */\nexport const querySortSchema = z\n .union([\n z.string(),\n z.array(z.string()),\n z.record(z.string(), z.enum(['asc', 'desc'])),\n z.array(z.record(z.string(), z.enum(['asc', 'desc']))),\n ])\n .describe('Sort the results by specified fields');\n\n/**\n * Pagination parameter validation\n * Supports both page-based and offset-based pagination\n */\nexport const paginationSchema = z\n .intersection(\n z.object({\n withCount: z.boolean().optional().describe('Include total count in response'),\n }),\n z.union([\n z\n .object({\n page: z.number().int().positive().describe('Page number (1-based)'),\n pageSize: z.number().int().positive().describe('Number of entries per page'),\n })\n .describe('Page-based pagination'),\n z\n .object({\n start: z.number().int().min(0).describe('Number of entries to skip'),\n limit: z.number().int().positive().describe('Maximum number of entries to return'),\n })\n .describe('Offset-based pagination'),\n ])\n )\n .describe('Pagination parameters');\n\n/**\n * Filters parameter validation\n * Supports any object structure for filtering\n */\nexport const filtersSchema = z.record(z.string(), z.any()).describe('Apply filters to the query');\n\n/**\n * Locale parameter validation\n * Used for internationalization\n */\nexport const localeSchema = z.string().describe('Specify the locale for localized content');\n\n/**\n * Status parameter validation\n * Used for draft & publish functionality\n */\nexport const statusSchema = z.enum(['draft', 'published']).describe('Filter by publication status');\n\n/**\n * Search query parameter validation\n * Used for text search functionality\n */\nexport const searchQuerySchema = z.string().describe('Search query string');\n\n/**\n * Complete collection of all standard query parameter schemas\n * This object provides easy access to all available query parameter validators\n */\nexport const queryParameterSchemas = {\n fields: queryFieldsSchema,\n populate: queryPopulateSchema,\n sort: querySortSchema,\n pagination: paginationSchema,\n filters: filtersSchema,\n locale: localeSchema,\n status: statusSchema,\n _q: searchQuerySchema,\n} as const;\n\n/**\n * Query parameter names supported by Strapi's API\n */\nexport type QueryParam = keyof typeof queryParameterSchemas;\n"],"names":["queryFieldsSchema","z","union","string","array","describe","queryPopulateSchema","literal","record","any","querySortSchema","enum","paginationSchema","intersection","object","withCount","boolean","optional","page","number","int","positive","pageSize","start","min","limit","filtersSchema","localeSchema","statusSchema","searchQuerySchema","queryParameterSchemas","fields","populate","sort","pagination","filters","locale","status","_q"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAEA;;;;;;;;AAUC,IACM,MAAMA,iBAAoBC,GAAAA,YAAAA,CAC9BC,KAAK,CAAC;AAACD,IAAAA,YAAAA,CAAEE,MAAM,EAAA;IAAIF,YAAEG,CAAAA,KAAK,CAACH,YAAAA,CAAEE,MAAM,EAAA;CAAI,CACvCE,CAAAA,QAA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V2B,IAAMvB,EAAAA,eAAAA;IACNwB,UAAYtB,EAAAA,gBAAAA;IACZuB,OAAST,EAAAA,aAAAA;IACTU,MAAQT,EAAAA,YAAAA;IACRU,MAAQT,EAAAA,YAAAA;IACRU,EAAIT,EAAAA;AACN;;;;;;;;;;;;"}
@@ -0,0 +1,88 @@
1
+ import * as z from 'zod/v4';
2
+
3
+ /**
4
+ * Standard query parameter validators that can be reused across different route validators
5
+ *
6
+ * These schemas provide the basic structure validation for common Strapi API query parameters.
7
+ * They can be used as building blocks for both generic validation and schema-aware validation.
8
+ */ /**
9
+ * Fields parameter validation
10
+ * Supports: 'title', ['title', 'name'], or '*'
11
+ */ const queryFieldsSchema = z.union([
12
+ z.string(),
13
+ z.array(z.string())
14
+ ]).describe('Select specific fields to return in the response');
15
+ /**
16
+ * Populate parameter validation
17
+ * Supports: '*', 'relation', ['relation1', 'relation2'], or complex objects
18
+ */ const queryPopulateSchema = z.union([
19
+ z.literal('*'),
20
+ z.string(),
21
+ z.array(z.string()),
22
+ z.record(z.string(), z.any())
23
+ ]).describe('Specify which relations to populate in the response');
24
+ /**
25
+ * Sort parameter validation
26
+ * Supports: 'name', ['name', 'title'], { name: 'asc' }, or [{ name: 'desc' }]
27
+ */ const querySortSchema = z.union([
28
+ z.string(),
29
+ z.array(z.string()),
30
+ z.record(z.string(), z.enum([
31
+ 'asc',
32
+ 'desc'
33
+ ])),
34
+ z.array(z.record(z.string(), z.enum([
35
+ 'asc',
36
+ 'desc'
37
+ ])))
38
+ ]).describe('Sort the results by specified fields');
39
+ /**
40
+ * Pagination parameter validation
41
+ * Supports both page-based and offset-based pagination
42
+ */ const paginationSchema = z.intersection(z.object({
43
+ withCount: z.boolean().optional().describe('Include total count in response')
44
+ }), z.union([
45
+ z.object({
46
+ page: z.number().int().positive().describe('Page number (1-based)'),
47
+ pageSize: z.number().int().positive().describe('Number of entries per page')
48
+ }).describe('Page-based pagination'),
49
+ z.object({
50
+ start: z.number().int().min(0).describe('Number of entries to skip'),
51
+ limit: z.number().int().positive().describe('Maximum number of entries to return')
52
+ }).describe('Offset-based pagination')
53
+ ])).describe('Pagination parameters');
54
+ /**
55
+ * Filters parameter validation
56
+ * Supports any object structure for filtering
57
+ */ const filtersSchema = z.record(z.string(), z.any()).describe('Apply filters to the query');
58
+ /**
59
+ * Locale parameter validation
60
+ * Used for internationalization
61
+ */ const localeSchema = z.string().describe('Specify the locale for localized content');
62
+ /**
63
+ * Status parameter validation
64
+ * Used for draft & publish functionality
65
+ */ const statusSchema = z.enum([
66
+ 'draft',
67
+ 'published'
68
+ ]).describe('Filter by publication status');
69
+ /**
70
+ * Search query parameter validation
71
+ * Used for text search functionality
72
+ */ const searchQuerySchema = z.string().describe('Search query string');
73
+ /**
74
+ * Complete collection of all standard query parameter schemas
75
+ * This object provides easy access to all available query parameter validators
76
+ */ const queryParameterSchemas = {
77
+ fields: queryFieldsSchema,
78
+ populate: queryPopulateSchema,
79
+ sort: querySortSchema,
80
+ pagination: paginationSchema,
81
+ filters: filtersSchema,
82
+ locale: localeSchema,
83
+ status: statusSchema,
84
+ _q: searchQuerySchema
85
+ };
86
+
87
+ export { filtersSchema, localeSchema, paginationSchema, queryFieldsSchema, queryParameterSchemas, queryPopulateSchema, querySortSchema, searchQuerySchema, statusSchema };
88
+ //# sourceMappingURL=query-params.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query-params.mjs","sources":["../../../src/validation/route-validators/query-params.ts"],"sourcesContent":["import * as z from 'zod/v4';\n\n/**\n * Standard query parameter validators that can be reused across different route validators\n *\n * These schemas provide the basic structure validation for common Strapi API query parameters.\n * They can be used as building blocks for both generic validation and schema-aware validation.\n */\n\n/**\n * Fields parameter validation\n * Supports: 'title', ['title', 'name'], or '*'\n */\nexport const queryFieldsSchema = z\n .union([z.string(), z.array(z.string())])\n .describe('Select specific fields to return in the response');\n\n/**\n * Populate parameter validation\n * Supports: '*', 'relation', ['relation1', 'relation2'], or complex objects\n */\nexport const queryPopulateSchema = z\n .union([z.literal('*'), z.string(), z.array(z.string()), z.record(z.string(), z.any())])\n .describe('Specify which relations to populate in the response');\n\n/**\n * Sort parameter validation\n * Supports: 'name', ['name', 'title'], { name: 'asc' }, or [{ name: 'desc' }]\n */\nexport const querySortSchema = z\n .union([\n z.string(),\n z.array(z.string()),\n z.record(z.string(), z.enum(['asc', 'desc'])),\n z.array(z.record(z.string(), z.enum(['asc', 'desc']))),\n ])\n .describe('Sort the results by specified fields');\n\n/**\n * Pagination parameter validation\n * Supports both page-based and offset-based pagination\n */\nexport const paginationSchema = z\n .intersection(\n z.object({\n withCount: z.boolean().optional().describe('Include total count in response'),\n }),\n z.union([\n z\n .object({\n page: z.number().int().positive().describe('Page number (1-based)'),\n pageSize: z.number().int().positive().describe('Number of entries per page'),\n })\n .describe('Page-based pagination'),\n z\n .object({\n start: z.number().int().min(0).describe('Number of entries to skip'),\n limit: z.number().int().positive().describe('Maximum number of entries to return'),\n })\n .describe('Offset-based pagination'),\n ])\n )\n .describe('Pagination parameters');\n\n/**\n * Filters parameter validation\n * Supports any object structure for filtering\n */\nexport const filtersSchema = z.record(z.string(), z.any()).describe('Apply filters to the query');\n\n/**\n * Locale parameter validation\n * Used for internationalization\n */\nexport const localeSchema = z.string().describe('Specify the locale for localized content');\n\n/**\n * Status parameter validation\n * Used for draft & publish functionality\n */\nexport const statusSchema = z.enum(['draft', 'published']).describe('Filter by publication status');\n\n/**\n * Search query parameter validation\n * Used for text search functionality\n */\nexport const searchQuerySchema = z.string().describe('Search query string');\n\n/**\n * Complete collection of all standard query parameter schemas\n * This object provides easy access to all available query parameter validators\n */\nexport const queryParameterSchemas = {\n fields: queryFieldsSchema,\n populate: queryPopulateSchema,\n sort: querySortSchema,\n pagination: paginationSchema,\n filters: filtersSchema,\n locale: localeSchema,\n status: statusSchema,\n _q: searchQuerySchema,\n} as const;\n\n/**\n * Query parameter names supported by Strapi's API\n */\nexport type QueryParam = keyof typeof queryParameterSchemas;\n"],"names":["queryFieldsSchema","z","union","string","array","describe","queryPopulateSchema","literal","record","any","querySortSchema","enum","paginationSchema","intersection","object","withCount","boolean","optional","page","number","int","positive","pageSize","start","min","limit","filtersSchema","localeSchema","statusSchema","searchQuerySchema","queryParameterSchemas","fields","populate","sort","pagination","filters","locale","status","_q"],"mappings":";;AAEA;;;;;;;;AAUC,IACM,MAAMA,iBAAoBC,GAAAA,CAAAA,CAC9BC,KAAK,CAAC;AAACD,IAAAA,CAAAA,CAAEE,MAAM,EAAA;IAAIF,CAAEG,CAAAA,KAAK,CAACH,CAAAA,CAAEE,MAAM,EAAA;CAAI,CACvCE,CAAAA,QAAQ,CAAC,kDAAoD;AAEhE;;;AAGC,IACM,MAAMC,mBAAsBL,GAAAA,CAAAA,CAChCC,KAAK,CAAC;AAACD,IAAAA,CAAAA,CAAEM,OAAO,CAAC,GAAA,CAAA;AAAMN,IAAAA,CAAAA,CAAEE,MAAM,EAAA;IAAIF,CAAEG,CAAAA,KAAK,CAACH,CAAAA,CAAEE,MAAM,EAAA,CAAA;AAAKF,IAAAA,CAAAA,CAAEO,MAAM,CAACP,CAAAA,CAAEE,MAAM,EAAA,EAAIF,EAAEQ,GAAG,EAAA;CAAI,CACtFJ,CAAAA,QAAQ,CAAC,qDAAuD;AAEnE;;;AAGC,IACM,MAAMK,eAAkBT,GAAAA,CAAAA,CAC5BC,KAAK,CAAC;AACLD,IAAAA,CAAAA,CAAEE,MAAM,EAAA;IACRF,CAAEG,CAAAA,KAAK,CAACH,CAAAA,CAAEE,MAAM,EAAA,CAAA;AAChBF,IAAAA,CAAAA,CAAEO,MAAM,CAACP,CAAAA,CAAEE,MAAM,EAAIF,EAAAA,CAAAA,CAAEU,IAAI,CAAC;AAAC,QAAA,KAAA;AAAO,QAAA;AAAO,KAAA,CAAA,CAAA;IAC3CV,CAAEG,CAAAA,KAAK,CAACH,CAAAA,CAAEO,MAAM,CAACP,EAAEE,MAAM,EAAA,EAAIF,CAAEU,CAAAA,IAAI,CAAC;AAAC,QAAA,KAA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A,CAAEE,MAAM,EAAGE,CAAAA,QAAQ,CAAC,0CAA4C;AAE5F;;;AAGC,IACM,MAAMuB,YAAe3B,GAAAA,CAAAA,CAAEU,IAAI,CAAC;AAAC,IAAA,OAAA;AAAS,IAAA;CAAY,CAAEN,CAAAA,QAAQ,CAAC,8BAAgC;AAEpG;;;UAIawB,iBAAoB5B,GAAAA,CAAAA,CAAEE,MAAM,EAAGE,CAAAA,QAAQ,CAAC,qBAAuB;AAE5E;;;UAIayB,qBAAwB,GAAA;IACnCC,MAAQ/B,EAAAA,iBAAAA;IACRgC,QAAU1B,EAAAA,mBAAAA;IACV2B,IAAMvB,EAAAA,eAAAA;IACNwB,UAAYtB,EAAAA,gBAAAA;IACZuB,OAAST,EAAAA,aAAAA;IACTU,MAAQT,EAAAA,YAAAA;IACRU,MAAQT,EAAAA,YAAAA;IACRU,EAAIT,EAAAA;AACN;;;;"}
@@ -0,0 +1,81 @@
1
+ /**
2
+ * @file This file contains utility functions for working with Zod schemas.
3
+ * It provides functions to modify schemas (e.g., make them optional, readonly, or add default values),
4
+ * and to safely register and create schemas within Zod's global registry.
5
+ */
6
+ import * as z from 'zod/v4';
7
+ /**
8
+ * Transforms a Strapi UID into an OpenAPI-compliant component name.
9
+ *
10
+ * @param uid - The Strapi UID to transform (e.g., "basic.seo", "api::category.category", "plugin::upload.file")
11
+ * @returns The OpenAPI-compliant component name (e.g., "BasicSeoEntry", "ApiCategoryCategoryDocument", "PluginUploadFileDocument")
12
+ */
13
+ export declare const transformUidToValidOpenApiName: (uid: string) => string;
14
+ /**
15
+ * Conditionally makes a Zod schema optional based on the `required` parameter.
16
+ *
17
+ * @param required - If `false` or `undefined`, the schema will be made optional. If `true`, the schema becomes non-optional.
18
+ * @returns A function that takes a Zod schema and returns a modified schema (optional or required).
19
+ * @example
20
+ * ```typescript
21
+ * const optionalString = maybeRequired(false)(z.string()); // z.ZodOptional<z.ZodString>
22
+ *
23
+ * const requiredString = maybeRequired(true)(z.string()); // z.ZodString
24
+ * ```
25
+ */
26
+ export declare const maybeRequired: (required?: boolean) => <T extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>(schema: T) => z.ZodOptional<T> | z.ZodNonOptional<T>;
27
+ /**
28
+ * Conditionally makes a Zod schema readonly based on the `writable` parameter.
29
+ *
30
+ * @param writable - If `false`, the schema will be made readonly. If `true` or `undefined`, the schema remains unchanged.
31
+ * @returns A function that takes a Zod schema and returns a modified schema (readonly or original).
32
+ * @example
33
+ * ```typescript
34
+ * const readonlyNumber = maybeReadonly(false)(z.number()); // z.ZodReadonly<z.ZodNumber>
35
+ * const writableNumber = maybeReadonly(true)(z.number()); // z.ZodNumber
36
+ * ```
37
+ */
38
+ export declare const maybeReadonly: (writable?: boolean) => <T extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>(schema: T) => T | z.ZodReadonly<T>;
39
+ /**
40
+ * Conditionally adds a default value to a Zod schema based on the `defaultValue` parameter.
41
+ *
42
+ * @param defaultValue - The default value to apply to the schema. If `undefined`, no default value is added.
43
+ * If `defaultValue` is a function, its return value will be used as the default.
44
+ * @returns A function that takes a Zod schema and returns a modified schema (with default or original).
45
+ * @example
46
+ * ```typescript
47
+ * const stringWithDefault = maybeWithDefault("default")(z.string()); // z.ZodDefault<z.ZodString>
48
+ * const numberWithFunctionDefault = maybeWithDefault(() => Math.random())(z.number());
49
+ * ```
50
+ */
51
+ export declare const maybeWithDefault: (defaultValue?: unknown) => <T extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>(schema: T) => T | z.ZodDefault<T>;
52
+ /**
53
+ * Conditionally applies `min` and `max` constraints to a Zod string, number, or array schema.
54
+ *
55
+ * @param min - The minimum value/length. If `undefined`, no minimum constraint is applied.
56
+ * @param max - The maximum value/length. If `undefined`, no maximum constraint is applied.
57
+ * @returns A function that takes a Zod string, number, or array schema and returns a modified schema (with min/max constraints or original).
58
+ * @example
59
+ * ```typescript
60
+ * const stringWithMinMax = maybeWithMinMax(5, 10)(z.string()); // z.ZodString with min(5) and max(10)
61
+ * const numberWithMinMax = maybeWithMinMax(0, 100)(z.number()); // z.ZodNumber with min(0) and max(100)
62
+ * ```
63
+ */
64
+ export declare const maybeWithMinMax: (min?: number, max?: number) => <R extends z.ZodString | z.ZodNumber | z.ZodEmail | z.ZodArray<z.ZodAny>>(schema: R) => z.ZodString | z.ZodNumber | z.ZodEmail | z.ZodArray<z.ZodAny>;
65
+ /**
66
+ * Applies a series of modifier functions to a Zod schema sequentially.
67
+ *
68
+ * @template T - The type of the Zod schema.
69
+ * @param schema - The initial Zod schema to which modifiers will be applied.
70
+ * @param modifiers - An array of functions, each taking a Zod schema and returning a modified schema.
71
+ * @returns The final Zod schema after all modifiers have been applied.
72
+ * @example
73
+ * ```typescript
74
+ * const modifiedSchema = augmentSchema(z.string(), [
75
+ * maybeRequired(false),
76
+ * maybeWithDefault("test")
77
+ * ]);
78
+ * ```
79
+ */
80
+ export declare const augmentSchema: <T extends z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>(schema: T, modifiers: ((schema: T) => z.Schema)[]) => T;
81
+ //# sourceMappingURL=utilities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../../src/validation/utilities.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAE5B;;;;;GAKG;AACH,eAAO,MAAM,8BAA8B,QAAS,MAAM,KAAG,MAyB5D,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,aAAa,cAAe,OAAO,iGACV,CAAC,2CAGtC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,aAAa,cAAe,OAAO,iGACV,CAAC,yBACtC,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,gBAAgB,kBAAmB,OAAO,iGACjB,CAAC,wBAQtC,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,eAAe,SAAU,MAAM,QAAQ,MAAM,uFACiC,CAAC,kEAG3F,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,aAAa,8FAChB,CAAC,aACE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,MAGvC,CAAC"}