@strapi/utils 5.19.0 → 5.20.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/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3 -0
- package/dist/index.mjs.map +1 -1
- package/dist/validation/index.d.ts +3 -0
- package/dist/validation/index.d.ts.map +1 -0
- package/dist/validation/route-validators/base.d.ts +107 -0
- package/dist/validation/route-validators/base.d.ts.map +1 -0
- package/dist/validation/route-validators/base.js +92 -0
- package/dist/validation/route-validators/base.js.map +1 -0
- package/dist/validation/route-validators/base.mjs +90 -0
- package/dist/validation/route-validators/base.mjs.map +1 -0
- package/dist/validation/route-validators/index.d.ts +39 -0
- package/dist/validation/route-validators/index.d.ts.map +1 -0
- package/dist/validation/route-validators/query-params.d.ts +100 -0
- package/dist/validation/route-validators/query-params.d.ts.map +1 -0
- package/dist/validation/route-validators/query-params.js +117 -0
- package/dist/validation/route-validators/query-params.js.map +1 -0
- package/dist/validation/route-validators/query-params.mjs +88 -0
- package/dist/validation/route-validators/query-params.mjs.map +1 -0
- package/dist/validation/utilities.d.ts +81 -0
- package/dist/validation/utilities.d.ts.map +1 -0
- package/dist/validation/utilities.js +123 -0
- package/dist/validation/utilities.js.map +1 -0
- package/dist/validation/utilities.mjs +116 -0
- package/dist/validation/utilities.mjs.map +1 -0
- package/dist/zod.js +2 -2
- package/dist/zod.js.map +1 -1
- package/dist/zod.mjs +2 -2
- package/dist/zod.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,OAAO,IAAI,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C;AAE7B,cAAc,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -25,6 +25,9 @@ var contentTypes = require('./content-types.js');
|
|
|
25
25
|
var relations = require('./relations.js');
|
|
26
26
|
var hooks = require('./hooks.js');
|
|
27
27
|
var zod = require('./zod.js');
|
|
28
|
+
var base = require('./validation/route-validators/base.js');
|
|
29
|
+
var queryParams = require('./validation/route-validators/query-params.js');
|
|
30
|
+
var utilities = require('./validation/utilities.js');
|
|
28
31
|
var strings = require('./primitives/strings.js');
|
|
29
32
|
var arrays = require('./primitives/arrays.js');
|
|
30
33
|
var objects = require('./primitives/objects.js');
|
|
@@ -59,6 +62,22 @@ exports.contentTypes = contentTypes;
|
|
|
59
62
|
exports.relations = relations;
|
|
60
63
|
exports.hooks = hooks;
|
|
61
64
|
exports.validateZod = zod.validateZod;
|
|
65
|
+
exports.AbstractRouteValidator = base.AbstractRouteValidator;
|
|
66
|
+
exports.filtersSchema = queryParams.filtersSchema;
|
|
67
|
+
exports.localeSchema = queryParams.localeSchema;
|
|
68
|
+
exports.paginationSchema = queryParams.paginationSchema;
|
|
69
|
+
exports.queryFieldsSchema = queryParams.queryFieldsSchema;
|
|
70
|
+
exports.queryParameterSchemas = queryParams.queryParameterSchemas;
|
|
71
|
+
exports.queryPopulateSchema = queryParams.queryPopulateSchema;
|
|
72
|
+
exports.querySortSchema = queryParams.querySortSchema;
|
|
73
|
+
exports.searchQuerySchema = queryParams.searchQuerySchema;
|
|
74
|
+
exports.statusSchema = queryParams.statusSchema;
|
|
75
|
+
exports.augmentSchema = utilities.augmentSchema;
|
|
76
|
+
exports.maybeReadonly = utilities.maybeReadonly;
|
|
77
|
+
exports.maybeRequired = utilities.maybeRequired;
|
|
78
|
+
exports.maybeWithDefault = utilities.maybeWithDefault;
|
|
79
|
+
exports.maybeWithMinMax = utilities.maybeWithMinMax;
|
|
80
|
+
exports.transformUidToValidOpenApiName = utilities.transformUidToValidOpenApiName;
|
|
62
81
|
exports.strings = strings;
|
|
63
82
|
exports.arrays = arrays;
|
|
64
83
|
exports.objects = objects;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/index.mjs
CHANGED
|
@@ -38,6 +38,9 @@ export { relations };
|
|
|
38
38
|
import * as hooks from './hooks.mjs';
|
|
39
39
|
export { hooks };
|
|
40
40
|
export { validateZod } from './zod.mjs';
|
|
41
|
+
export { AbstractRouteValidator } from './validation/route-validators/base.mjs';
|
|
42
|
+
export { filtersSchema, localeSchema, paginationSchema, queryFieldsSchema, queryParameterSchemas, queryPopulateSchema, querySortSchema, searchQuerySchema, statusSchema } from './validation/route-validators/query-params.mjs';
|
|
43
|
+
export { augmentSchema, maybeReadonly, maybeRequired, maybeWithDefault, maybeWithMinMax, transformUidToValidOpenApiName } from './validation/utilities.mjs';
|
|
41
44
|
import * as strings from './primitives/strings.mjs';
|
|
42
45
|
export { strings };
|
|
43
46
|
import * as arrays from './primitives/arrays.mjs';
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validation/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import * as z from 'zod/v4';
|
|
2
|
+
import { type QueryParam } from './query-params';
|
|
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
|
+
*/
|
|
11
|
+
export declare abstract class AbstractRouteValidator {
|
|
12
|
+
/**
|
|
13
|
+
* Creates a fields query parameter validator
|
|
14
|
+
* Validates field selection for API responses
|
|
15
|
+
*/
|
|
16
|
+
get queryFields(): z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>;
|
|
17
|
+
/**
|
|
18
|
+
* Creates a populate query parameter validator
|
|
19
|
+
* Validates which relations to populate in the response
|
|
20
|
+
*/
|
|
21
|
+
get queryPopulate(): z.ZodUnion<readonly [z.ZodLiteral<"*">, z.ZodString, z.ZodArray<z.ZodString>, z.ZodRecord<z.ZodString, z.ZodAny>]>;
|
|
22
|
+
/**
|
|
23
|
+
* Creates a sort query parameter validator
|
|
24
|
+
* Validates sorting options for list endpoints
|
|
25
|
+
*/
|
|
26
|
+
get querySort(): z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>, z.ZodRecord<z.ZodString, z.ZodEnum<{
|
|
27
|
+
asc: "asc";
|
|
28
|
+
desc: "desc";
|
|
29
|
+
}>>, z.ZodArray<z.ZodRecord<z.ZodString, z.ZodEnum<{
|
|
30
|
+
asc: "asc";
|
|
31
|
+
desc: "desc";
|
|
32
|
+
}>>>]>;
|
|
33
|
+
/**
|
|
34
|
+
* Creates a pagination query parameter validator
|
|
35
|
+
* Supports both page-based and offset-based pagination
|
|
36
|
+
*/
|
|
37
|
+
get pagination(): z.ZodIntersection<z.ZodObject<{
|
|
38
|
+
withCount: z.ZodOptional<z.ZodBoolean>;
|
|
39
|
+
}, z.core.$strip>, z.ZodUnion<readonly [z.ZodObject<{
|
|
40
|
+
page: z.ZodNumber;
|
|
41
|
+
pageSize: z.ZodNumber;
|
|
42
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
43
|
+
start: z.ZodNumber;
|
|
44
|
+
limit: z.ZodNumber;
|
|
45
|
+
}, z.core.$strip>]>>;
|
|
46
|
+
/**
|
|
47
|
+
* Creates a filters query parameter validator
|
|
48
|
+
* Validates filtering options for list endpoints
|
|
49
|
+
*/
|
|
50
|
+
get filters(): z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
51
|
+
/**
|
|
52
|
+
* Creates a locale query parameter validator
|
|
53
|
+
* Used for internationalization
|
|
54
|
+
*/
|
|
55
|
+
get locale(): z.ZodString;
|
|
56
|
+
/**
|
|
57
|
+
* Creates a status query parameter validator
|
|
58
|
+
* Used for draft & publish functionality
|
|
59
|
+
*/
|
|
60
|
+
get status(): z.ZodEnum<{
|
|
61
|
+
draft: "draft";
|
|
62
|
+
published: "published";
|
|
63
|
+
}>;
|
|
64
|
+
/**
|
|
65
|
+
* Creates a search query parameter validator
|
|
66
|
+
* Used for text search functionality
|
|
67
|
+
*/
|
|
68
|
+
get query(): z.ZodString;
|
|
69
|
+
/**
|
|
70
|
+
* Provides access to all base query parameter validators
|
|
71
|
+
*/
|
|
72
|
+
protected get baseQueryValidators(): {
|
|
73
|
+
fields: () => z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
|
|
74
|
+
populate: () => z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"*">, z.ZodString, z.ZodArray<z.ZodString>, z.ZodRecord<z.ZodString, z.ZodAny>]>>;
|
|
75
|
+
sort: () => z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>, z.ZodRecord<z.ZodString, z.ZodEnum<{
|
|
76
|
+
asc: "asc";
|
|
77
|
+
desc: "desc";
|
|
78
|
+
}>>, z.ZodArray<z.ZodRecord<z.ZodString, z.ZodEnum<{
|
|
79
|
+
asc: "asc";
|
|
80
|
+
desc: "desc";
|
|
81
|
+
}>>>]>>;
|
|
82
|
+
filters: () => z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
83
|
+
pagination: () => z.ZodOptional<z.ZodIntersection<z.ZodObject<{
|
|
84
|
+
withCount: z.ZodOptional<z.ZodBoolean>;
|
|
85
|
+
}, z.core.$strip>, z.ZodUnion<readonly [z.ZodObject<{
|
|
86
|
+
page: z.ZodNumber;
|
|
87
|
+
pageSize: z.ZodNumber;
|
|
88
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
89
|
+
start: z.ZodNumber;
|
|
90
|
+
limit: z.ZodNumber;
|
|
91
|
+
}, z.core.$strip>]>>>;
|
|
92
|
+
locale: () => z.ZodOptional<z.ZodString>;
|
|
93
|
+
status: () => z.ZodOptional<z.ZodEnum<{
|
|
94
|
+
draft: "draft";
|
|
95
|
+
published: "published";
|
|
96
|
+
}>>;
|
|
97
|
+
_q: () => z.ZodOptional<z.ZodString>;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Helper method to create a query parameters object with specified validators
|
|
101
|
+
*
|
|
102
|
+
* @param params - Array of query parameter names to include
|
|
103
|
+
* @returns Object containing Zod schemas for the requested query parameters
|
|
104
|
+
*/
|
|
105
|
+
queryParams(params: QueryParam[]): Record<string, z.ZodSchema>;
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/validation/route-validators/base.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAyB,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAExE;;;;;;;GAOG;AACH,8BAAsB,sBAAsB;IAC1C;;;OAGG;IACH,IAAI,WAAW,gEAEd;IAED;;;OAGG;IACH,IAAI,aAAa,uHAEhB;IAED;;;OAGG;IACH,IAAI,SAAS;;;;;;WAEZ;IAED;;;OAGG;IACH,IAAI,UAAU;;;;;;;;yBAEb;IAED;;;OAGG;IACH,IAAI,OAAO,uCAEV;IAED;;;OAGG;IACH,IAAI,MAAM,gBAET;IAED;;;OAGG;IACH,IAAI,MAAM;;;OAET;IAED;;;OAGG;IACH,IAAI,KAAK,gBAER;IAED;;OAEG;IACH,SAAS,KAAK,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;MAWhC;IAED;;;;;OAKG;IACH,WAAW,CAAC,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC;CAa/D"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var queryParams = require('./query-params.js');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* AbstractRouteValidator provides the foundation for validating routes.
|
|
7
|
+
*
|
|
8
|
+
* This abstract class provides common query parameter validators that can be reused
|
|
9
|
+
* across different route validators in Strapi. It serves as a building block for
|
|
10
|
+
* both generic validation (plugins, external packages) and schema-aware validation
|
|
11
|
+
* (core content types).
|
|
12
|
+
*/ class AbstractRouteValidator {
|
|
13
|
+
/**
|
|
14
|
+
* Creates a fields query parameter validator
|
|
15
|
+
* Validates field selection for API responses
|
|
16
|
+
*/ get queryFields() {
|
|
17
|
+
return queryParams.queryParameterSchemas.fields;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Creates a populate query parameter validator
|
|
21
|
+
* Validates which relations to populate in the response
|
|
22
|
+
*/ get queryPopulate() {
|
|
23
|
+
return queryParams.queryParameterSchemas.populate;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Creates a sort query parameter validator
|
|
27
|
+
* Validates sorting options for list endpoints
|
|
28
|
+
*/ get querySort() {
|
|
29
|
+
return queryParams.queryParameterSchemas.sort;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Creates a pagination query parameter validator
|
|
33
|
+
* Supports both page-based and offset-based pagination
|
|
34
|
+
*/ get pagination() {
|
|
35
|
+
return queryParams.queryParameterSchemas.pagination;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Creates a filters query parameter validator
|
|
39
|
+
* Validates filtering options for list endpoints
|
|
40
|
+
*/ get filters() {
|
|
41
|
+
return queryParams.queryParameterSchemas.filters;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Creates a locale query parameter validator
|
|
45
|
+
* Used for internationalization
|
|
46
|
+
*/ get locale() {
|
|
47
|
+
return queryParams.queryParameterSchemas.locale;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Creates a status query parameter validator
|
|
51
|
+
* Used for draft & publish functionality
|
|
52
|
+
*/ get status() {
|
|
53
|
+
return queryParams.queryParameterSchemas.status;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Creates a search query parameter validator
|
|
57
|
+
* Used for text search functionality
|
|
58
|
+
*/ get query() {
|
|
59
|
+
return queryParams.queryParameterSchemas._q;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Provides access to all base query parameter validators
|
|
63
|
+
*/ get baseQueryValidators() {
|
|
64
|
+
return {
|
|
65
|
+
fields: ()=>this.queryFields.optional(),
|
|
66
|
+
populate: ()=>this.queryPopulate.optional(),
|
|
67
|
+
sort: ()=>this.querySort.optional(),
|
|
68
|
+
filters: ()=>this.filters.optional(),
|
|
69
|
+
pagination: ()=>this.pagination.optional(),
|
|
70
|
+
locale: ()=>this.locale.optional(),
|
|
71
|
+
status: ()=>this.status.optional(),
|
|
72
|
+
_q: ()=>this.query.optional()
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Helper method to create a query parameters object with specified validators
|
|
77
|
+
*
|
|
78
|
+
* @param params - Array of query parameter names to include
|
|
79
|
+
* @returns Object containing Zod schemas for the requested query parameters
|
|
80
|
+
*/ queryParams(params) {
|
|
81
|
+
const validators = this.baseQueryValidators;
|
|
82
|
+
return params.reduce((acc, param)=>{
|
|
83
|
+
if (param in validators) {
|
|
84
|
+
acc[param] = validators[param]();
|
|
85
|
+
}
|
|
86
|
+
return acc;
|
|
87
|
+
}, {});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
exports.AbstractRouteValidator = AbstractRouteValidator;
|
|
92
|
+
//# sourceMappingURL=base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.js","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,kCAAsBC,MAAM;AACrC;AAEA;;;AAGC,MACD,IAAIC,aAAgB,GAAA;AAClB,QAAA,OAAOF,kCAAsBG,QAAQ;AACvC;AAEA;;;AAGC,MACD,IAAIC,SAAY,GAAA;AACd,QAAA,OAAOJ,kCAAsBK,IAAI;AACnC;AAEA;;;AAGC,MACD,IAAIC,UAAa,GAAA;AACf,QAAA,OAAON,kCAAsBM,UAAU;AACzC;AAEA;;;AAGC,MACD,IAAIC,OAAU,GAAA;AACZ,QAAA,OAAOP,kCAAsBO,OAAO;AACtC;AAEA;;;AAGC,MACD,IAAIC,MAAS,GAAA;AACX,QAAA,OAAOR,kCAAsBQ,MAAM;AACrC;AAEA;;;AAGC,MACD,IAAIC,MAAS,GAAA;AACX,QAAA,OAAOT,kCAAsBS,MAAM;AACrC;AAEA;;;AAGC,MACD,IAAIC,KAAQ,GAAA;AACV,QAAA,OAAOV,kCAAsBW,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,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,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;;;;;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,QAAQ,CAAC,kDAAoD;AAEhE;;;AAGC,IACM,MAAMC,mBAAsBL,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AA;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;AA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emas.
|
|
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"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file This file contains utility functions for working with Zod schemas.
|
|
5
|
+
* It provides functions to modify schemas (e.g., make them optional, readonly, or add default values),
|
|
6
|
+
* and to safely register and create schemas within Zod's global registry.
|
|
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
|
+
*/ const transformUidToValidOpenApiName = (uid)=>{
|
|
13
|
+
const capitalize = (str)=>{
|
|
14
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
15
|
+
};
|
|
16
|
+
const toPascalCase = (str)=>{
|
|
17
|
+
return str.split(/[-_]/).map(capitalize).join('');
|
|
18
|
+
};
|
|
19
|
+
// Check if it contains double colons (other namespaced UIDs)
|
|
20
|
+
if (uid.includes('::')) {
|
|
21
|
+
const [namespace, ...rest] = uid.split('::');
|
|
22
|
+
const namespacePart = toPascalCase(namespace);
|
|
23
|
+
const restParts = rest.join('.').split('.').map(toPascalCase).map(capitalize);
|
|
24
|
+
return `${capitalize(namespacePart)}${restParts.join('')}Document`;
|
|
25
|
+
}
|
|
26
|
+
if (uid.includes('.')) {
|
|
27
|
+
// basic.seo -> BasicSeoEntry
|
|
28
|
+
const parts = uid.split('.');
|
|
29
|
+
const transformedParts = parts.map(toPascalCase).map(capitalize);
|
|
30
|
+
return `${transformedParts.join('')}Entry`;
|
|
31
|
+
}
|
|
32
|
+
return `${toPascalCase(capitalize(uid))}Schema`;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Conditionally makes a Zod schema optional based on the `required` parameter.
|
|
36
|
+
*
|
|
37
|
+
* @param required - If `false` or `undefined`, the schema will be made optional. If `true`, the schema becomes non-optional.
|
|
38
|
+
* @returns A function that takes a Zod schema and returns a modified schema (optional or required).
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* const optionalString = maybeRequired(false)(z.string()); // z.ZodOptional<z.ZodString>
|
|
42
|
+
*
|
|
43
|
+
* const requiredString = maybeRequired(true)(z.string()); // z.ZodString
|
|
44
|
+
* ```
|
|
45
|
+
*/ const maybeRequired = (required)=>{
|
|
46
|
+
return (schema)=>{
|
|
47
|
+
return required !== true ? schema.optional() : schema.nonoptional();
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Conditionally makes a Zod schema readonly based on the `writable` parameter.
|
|
52
|
+
*
|
|
53
|
+
* @param writable - If `false`, the schema will be made readonly. If `true` or `undefined`, the schema remains unchanged.
|
|
54
|
+
* @returns A function that takes a Zod schema and returns a modified schema (readonly or original).
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* const readonlyNumber = maybeReadonly(false)(z.number()); // z.ZodReadonly<z.ZodNumber>
|
|
58
|
+
* const writableNumber = maybeReadonly(true)(z.number()); // z.ZodNumber
|
|
59
|
+
* ```
|
|
60
|
+
*/ const maybeReadonly = (writable)=>{
|
|
61
|
+
return (schema)=>writable !== false ? schema : schema.readonly();
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Conditionally adds a default value to a Zod schema based on the `defaultValue` parameter.
|
|
65
|
+
*
|
|
66
|
+
* @param defaultValue - The default value to apply to the schema. If `undefined`, no default value is added.
|
|
67
|
+
* If `defaultValue` is a function, its return value will be used as the default.
|
|
68
|
+
* @returns A function that takes a Zod schema and returns a modified schema (with default or original).
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* const stringWithDefault = maybeWithDefault("default")(z.string()); // z.ZodDefault<z.ZodString>
|
|
72
|
+
* const numberWithFunctionDefault = maybeWithDefault(() => Math.random())(z.number());
|
|
73
|
+
* ```
|
|
74
|
+
*/ const maybeWithDefault = (defaultValue)=>{
|
|
75
|
+
return (schema)=>{
|
|
76
|
+
if (defaultValue === undefined) {
|
|
77
|
+
return schema;
|
|
78
|
+
}
|
|
79
|
+
const value = typeof defaultValue === 'function' ? defaultValue() : defaultValue;
|
|
80
|
+
return schema.default(value);
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Conditionally applies `min` and `max` constraints to a Zod string, number, or array schema.
|
|
85
|
+
*
|
|
86
|
+
* @param min - The minimum value/length. If `undefined`, no minimum constraint is applied.
|
|
87
|
+
* @param max - The maximum value/length. If `undefined`, no maximum constraint is applied.
|
|
88
|
+
* @returns A function that takes a Zod string, number, or array schema and returns a modified schema (with min/max constraints or original).
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* const stringWithMinMax = maybeWithMinMax(5, 10)(z.string()); // z.ZodString with min(5) and max(10)
|
|
92
|
+
* const numberWithMinMax = maybeWithMinMax(0, 100)(z.number()); // z.ZodNumber with min(0) and max(100)
|
|
93
|
+
* ```
|
|
94
|
+
*/ const maybeWithMinMax = (min, max)=>{
|
|
95
|
+
return (schema)=>{
|
|
96
|
+
return min !== undefined && max !== undefined ? schema.min(min).max(max) : schema;
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Applies a series of modifier functions to a Zod schema sequentially.
|
|
101
|
+
*
|
|
102
|
+
* @template T - The type of the Zod schema.
|
|
103
|
+
* @param schema - The initial Zod schema to which modifiers will be applied.
|
|
104
|
+
* @param modifiers - An array of functions, each taking a Zod schema and returning a modified schema.
|
|
105
|
+
* @returns The final Zod schema after all modifiers have been applied.
|
|
106
|
+
* @example
|
|
107
|
+
* ```typescript
|
|
108
|
+
* const modifiedSchema = augmentSchema(z.string(), [
|
|
109
|
+
* maybeRequired(false),
|
|
110
|
+
* maybeWithDefault("test")
|
|
111
|
+
* ]);
|
|
112
|
+
* ```
|
|
113
|
+
*/ const augmentSchema = (schema, modifiers)=>{
|
|
114
|
+
return modifiers.reduce((acc, modifier)=>modifier(acc), schema);
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
exports.augmentSchema = augmentSchema;
|
|
118
|
+
exports.maybeReadonly = maybeReadonly;
|
|
119
|
+
exports.maybeRequired = maybeRequired;
|
|
120
|
+
exports.maybeWithDefault = maybeWithDefault;
|
|
121
|
+
exports.maybeWithMinMax = maybeWithMinMax;
|
|
122
|
+
exports.transformUidToValidOpenApiName = transformUidToValidOpenApiName;
|
|
123
|
+
//# sourceMappingURL=utilities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utilities.js","sources":["../../src/validation/utilities.ts"],"sourcesContent":["/**\n * @file This file contains utility functions for working with Zod schemas.\n * It provides functions to modify schemas (e.g., make them optional, readonly, or add default values),\n * and to safely register and create schemas within Zod's global registry.\n */\n\nimport * as z from 'zod/v4';\n\n/**\n * Transforms a Strapi UID into an OpenAPI-compliant component name.\n *\n * @param uid - The Strapi UID to transform (e.g., \"basic.seo\", \"api::category.category\", \"plugin::upload.file\")\n * @returns The OpenAPI-compliant component name (e.g., \"BasicSeoEntry\", \"ApiCategoryCategoryDocument\", \"PluginUploadFileDocument\")\n */\nexport const transformUidToValidOpenApiName = (uid: string): string => {\n const capitalize = (str: string): string => {\n return str.charAt(0).toUpperCase() + str.slice(1);\n };\n\n const toPascalCase = (str: string): string => {\n return str.split(/[-_]/).map(capitalize).join('');\n };\n\n // Check if it contains double colons (other namespaced UIDs)\n if (uid.includes('::')) {\n const [namespace, ...rest] = uid.split('::');\n const namespacePart = toPascalCase(namespace);\n const restParts = rest.join('.').split('.').map(toPascalCase).map(capitalize);\n return `${capitalize(namespacePart)}${restParts.join('')}Document`;\n }\n\n if (uid.includes('.')) {\n // basic.seo -> BasicSeoEntry\n const parts = uid.split('.');\n const transformedParts = parts.map(toPascalCase).map(capitalize);\n return `${transformedParts.join('')}Entry`;\n }\n\n return `${toPascalCase(capitalize(uid))}Schema`;\n};\n\n/**\n * Conditionally makes a Zod schema optional based on the `required` parameter.\n *\n * @param required - If `false` or `undefined`, the schema will be made optional. If `true`, the schema becomes non-optional.\n * @returns A function that takes a Zod schema and returns a modified schema (optional or required).\n * @example\n * ```typescript\n * const optionalString = maybeRequired(false)(z.string()); // z.ZodOptional<z.ZodString>\n *\n * const requiredString = maybeRequired(true)(z.string()); // z.ZodString\n * ```\n */\nexport const maybeRequired = (required?: boolean) => {\n return <T extends z.Schema>(schema: T) => {\n return required !== true ? schema.optional() : schema.nonoptional();\n };\n};\n\n/**\n * Conditionally makes a Zod schema readonly based on the `writable` parameter.\n *\n * @param writable - If `false`, the schema will be made readonly. If `true` or `undefined`, the schema remains unchanged.\n * @returns A function that takes a Zod schema and returns a modified schema (readonly or original).\n * @example\n * ```typescript\n * const readonlyNumber = maybeReadonly(false)(z.number()); // z.ZodReadonly<z.ZodNumber>\n * const writableNumber = maybeReadonly(true)(z.number()); // z.ZodNumber\n * ```\n */\nexport const maybeReadonly = (writable?: boolean) => {\n return <T extends z.Schema>(schema: T) => (writable !== false ? schema : schema.readonly());\n};\n\n/**\n * Conditionally adds a default value to a Zod schema based on the `defaultValue` parameter.\n *\n * @param defaultValue - The default value to apply to the schema. If `undefined`, no default value is added.\n * If `defaultValue` is a function, its return value will be used as the default.\n * @returns A function that takes a Zod schema and returns a modified schema (with default or original).\n * @example\n * ```typescript\n * const stringWithDefault = maybeWithDefault(\"default\")(z.string()); // z.ZodDefault<z.ZodString>\n * const numberWithFunctionDefault = maybeWithDefault(() => Math.random())(z.number());\n * ```\n */\nexport const maybeWithDefault = (defaultValue?: unknown) => {\n return <T extends z.Schema>(schema: T) => {\n if (defaultValue === undefined) {\n return schema;\n }\n\n const value = typeof defaultValue === 'function' ? defaultValue() : defaultValue;\n return schema.default(value);\n };\n};\n\n/**\n * Conditionally applies `min` and `max` constraints to a Zod string, number, or array schema.\n *\n * @param min - The minimum value/length. If `undefined`, no minimum constraint is applied.\n * @param max - The maximum value/length. If `undefined`, no maximum constraint is applied.\n * @returns A function that takes a Zod string, number, or array schema and returns a modified schema (with min/max constraints or original).\n * @example\n * ```typescript\n * const stringWithMinMax = maybeWithMinMax(5, 10)(z.string()); // z.ZodString with min(5) and max(10)\n * const numberWithMinMax = maybeWithMinMax(0, 100)(z.number()); // z.ZodNumber with min(0) and max(100)\n * ```\n */\nexport const maybeWithMinMax = (min?: number, max?: number) => {\n return <R extends z.ZodString | z.ZodEmail | z.ZodNumber | z.ZodArray<z.ZodAny>>(schema: R) => {\n return min !== undefined && max !== undefined ? schema.min(min).max(max) : schema;\n };\n};\n\n/**\n * Applies a series of modifier functions to a Zod schema sequentially.\n *\n * @template T - The type of the Zod schema.\n * @param schema - The initial Zod schema to which modifiers will be applied.\n * @param modifiers - An array of functions, each taking a Zod schema and returning a modified schema.\n * @returns The final Zod schema after all modifiers have been applied.\n * @example\n * ```typescript\n * const modifiedSchema = augmentSchema(z.string(), [\n * maybeRequired(false),\n * maybeWithDefault(\"test\")\n * ]);\n * ```\n */\nexport const augmentSchema = <T extends z.Schema>(\n schema: T,\n modifiers: ((schema: T) => z.Schema)[]\n) => {\n return modifiers.reduce((acc, modifier) => modifier(acc) as T, schema);\n};\n"],"names":["transformUidToValidOpenApiName","uid","capitalize","str","charAt","toUpperCase","slice","toPascalCase","split","map","join","includes","namespace","rest","namespacePart","restParts","parts","transformedParts","maybeRequired","required","schema","optional","nonoptional","maybeReadonly","writable","readonly","maybeWithDefault","defaultValue","undefined","value","default","maybeWithMinMax","min","max","augmentSchema","modifiers","reduce","acc","modifier"],"mappings":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B,GAAA,CAC3Bd,MACAe,EAAAA,SAAAA,GAAAA;AAEA,IAAA,OAAOA,UAAUC,MAAM,CAAC,CAACC,GAAKC,EAAAA,QAAAA,GAAaA,SAASD,GAAWjB,CAAAA,EAAAA,MAAAA,CAAAA;AACjE;;;;;;;;;"}
|
|
@@ -0,0 +1,116 @@
|
|
|
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
|
+
* Transforms a Strapi UID into an OpenAPI-compliant component name.
|
|
7
|
+
*
|
|
8
|
+
* @param uid - The Strapi UID to transform (e.g., "basic.seo", "api::category.category", "plugin::upload.file")
|
|
9
|
+
* @returns The OpenAPI-compliant component name (e.g., "BasicSeoEntry", "ApiCategoryCategoryDocument", "PluginUploadFileDocument")
|
|
10
|
+
*/ const transformUidToValidOpenApiName = (uid)=>{
|
|
11
|
+
const capitalize = (str)=>{
|
|
12
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
13
|
+
};
|
|
14
|
+
const toPascalCase = (str)=>{
|
|
15
|
+
return str.split(/[-_]/).map(capitalize).join('');
|
|
16
|
+
};
|
|
17
|
+
// Check if it contains double colons (other namespaced UIDs)
|
|
18
|
+
if (uid.includes('::')) {
|
|
19
|
+
const [namespace, ...rest] = uid.split('::');
|
|
20
|
+
const namespacePart = toPascalCase(namespace);
|
|
21
|
+
const restParts = rest.join('.').split('.').map(toPascalCase).map(capitalize);
|
|
22
|
+
return `${capitalize(namespacePart)}${restParts.join('')}Document`;
|
|
23
|
+
}
|
|
24
|
+
if (uid.includes('.')) {
|
|
25
|
+
// basic.seo -> BasicSeoEntry
|
|
26
|
+
const parts = uid.split('.');
|
|
27
|
+
const transformedParts = parts.map(toPascalCase).map(capitalize);
|
|
28
|
+
return `${transformedParts.join('')}Entry`;
|
|
29
|
+
}
|
|
30
|
+
return `${toPascalCase(capitalize(uid))}Schema`;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Conditionally makes a Zod schema optional based on the `required` parameter.
|
|
34
|
+
*
|
|
35
|
+
* @param required - If `false` or `undefined`, the schema will be made optional. If `true`, the schema becomes non-optional.
|
|
36
|
+
* @returns A function that takes a Zod schema and returns a modified schema (optional or required).
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* const optionalString = maybeRequired(false)(z.string()); // z.ZodOptional<z.ZodString>
|
|
40
|
+
*
|
|
41
|
+
* const requiredString = maybeRequired(true)(z.string()); // z.ZodString
|
|
42
|
+
* ```
|
|
43
|
+
*/ const maybeRequired = (required)=>{
|
|
44
|
+
return (schema)=>{
|
|
45
|
+
return required !== true ? schema.optional() : schema.nonoptional();
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Conditionally makes a Zod schema readonly based on the `writable` parameter.
|
|
50
|
+
*
|
|
51
|
+
* @param writable - If `false`, the schema will be made readonly. If `true` or `undefined`, the schema remains unchanged.
|
|
52
|
+
* @returns A function that takes a Zod schema and returns a modified schema (readonly or original).
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* const readonlyNumber = maybeReadonly(false)(z.number()); // z.ZodReadonly<z.ZodNumber>
|
|
56
|
+
* const writableNumber = maybeReadonly(true)(z.number()); // z.ZodNumber
|
|
57
|
+
* ```
|
|
58
|
+
*/ const maybeReadonly = (writable)=>{
|
|
59
|
+
return (schema)=>writable !== false ? schema : schema.readonly();
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Conditionally adds a default value to a Zod schema based on the `defaultValue` parameter.
|
|
63
|
+
*
|
|
64
|
+
* @param defaultValue - The default value to apply to the schema. If `undefined`, no default value is added.
|
|
65
|
+
* If `defaultValue` is a function, its return value will be used as the default.
|
|
66
|
+
* @returns A function that takes a Zod schema and returns a modified schema (with default or original).
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* const stringWithDefault = maybeWithDefault("default")(z.string()); // z.ZodDefault<z.ZodString>
|
|
70
|
+
* const numberWithFunctionDefault = maybeWithDefault(() => Math.random())(z.number());
|
|
71
|
+
* ```
|
|
72
|
+
*/ const maybeWithDefault = (defaultValue)=>{
|
|
73
|
+
return (schema)=>{
|
|
74
|
+
if (defaultValue === undefined) {
|
|
75
|
+
return schema;
|
|
76
|
+
}
|
|
77
|
+
const value = typeof defaultValue === 'function' ? defaultValue() : defaultValue;
|
|
78
|
+
return schema.default(value);
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Conditionally applies `min` and `max` constraints to a Zod string, number, or array schema.
|
|
83
|
+
*
|
|
84
|
+
* @param min - The minimum value/length. If `undefined`, no minimum constraint is applied.
|
|
85
|
+
* @param max - The maximum value/length. If `undefined`, no maximum constraint is applied.
|
|
86
|
+
* @returns A function that takes a Zod string, number, or array schema and returns a modified schema (with min/max constraints or original).
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* const stringWithMinMax = maybeWithMinMax(5, 10)(z.string()); // z.ZodString with min(5) and max(10)
|
|
90
|
+
* const numberWithMinMax = maybeWithMinMax(0, 100)(z.number()); // z.ZodNumber with min(0) and max(100)
|
|
91
|
+
* ```
|
|
92
|
+
*/ const maybeWithMinMax = (min, max)=>{
|
|
93
|
+
return (schema)=>{
|
|
94
|
+
return min !== undefined && max !== undefined ? schema.min(min).max(max) : schema;
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Applies a series of modifier functions to a Zod schema sequentially.
|
|
99
|
+
*
|
|
100
|
+
* @template T - The type of the Zod schema.
|
|
101
|
+
* @param schema - The initial Zod schema to which modifiers will be applied.
|
|
102
|
+
* @param modifiers - An array of functions, each taking a Zod schema and returning a modified schema.
|
|
103
|
+
* @returns The final Zod schema after all modifiers have been applied.
|
|
104
|
+
* @example
|
|
105
|
+
* ```typescript
|
|
106
|
+
* const modifiedSchema = augmentSchema(z.string(), [
|
|
107
|
+
* maybeRequired(false),
|
|
108
|
+
* maybeWithDefault("test")
|
|
109
|
+
* ]);
|
|
110
|
+
* ```
|
|
111
|
+
*/ const augmentSchema = (schema, modifiers)=>{
|
|
112
|
+
return modifiers.reduce((acc, modifier)=>modifier(acc), schema);
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
export { augmentSchema, maybeReadonly, maybeRequired, maybeWithDefault, maybeWithMinMax, transformUidToValidOpenApiName };
|
|
116
|
+
//# sourceMappingURL=utilities.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utilities.mjs","sources":["../../src/validation/utilities.ts"],"sourcesContent":["/**\n * @file This file contains utility functions for working with Zod schemas.\n * It provides functions to modify schemas (e.g., make them optional, readonly, or add default values),\n * and to safely register and create schemas within Zod's global registry.\n */\n\nimport * as z from 'zod/v4';\n\n/**\n * Transforms a Strapi UID into an OpenAPI-compliant component name.\n *\n * @param uid - The Strapi UID to transform (e.g., \"basic.seo\", \"api::category.category\", \"plugin::upload.file\")\n * @returns The OpenAPI-compliant component name (e.g., \"BasicSeoEntry\", \"ApiCategoryCategoryDocument\", \"PluginUploadFileDocument\")\n */\nexport const transformUidToValidOpenApiName = (uid: string): string => {\n const capitalize = (str: string): string => {\n return str.charAt(0).toUpperCase() + str.slice(1);\n };\n\n const toPascalCase = (str: string): string => {\n return str.split(/[-_]/).map(capitalize).join('');\n };\n\n // Check if it contains double colons (other namespaced UIDs)\n if (uid.includes('::')) {\n const [namespace, ...rest] = uid.split('::');\n const namespacePart = toPascalCase(namespace);\n const restParts = rest.join('.').split('.').map(toPascalCase).map(capitalize);\n return `${capitalize(namespacePart)}${restParts.join('')}Document`;\n }\n\n if (uid.includes('.')) {\n // basic.seo -> BasicSeoEntry\n const parts = uid.split('.');\n const transformedParts = parts.map(toPascalCase).map(capitalize);\n return `${transformedParts.join('')}Entry`;\n }\n\n return `${toPascalCase(capitalize(uid))}Schema`;\n};\n\n/**\n * Conditionally makes a Zod schema optional based on the `required` parameter.\n *\n * @param required - If `false` or `undefined`, the schema will be made optional. If `true`, the schema becomes non-optional.\n * @returns A function that takes a Zod schema and returns a modified schema (optional or required).\n * @example\n * ```typescript\n * const optionalString = maybeRequired(false)(z.string()); // z.ZodOptional<z.ZodString>\n *\n * const requiredString = maybeRequired(true)(z.string()); // z.ZodString\n * ```\n */\nexport const maybeRequired = (required?: boolean) => {\n return <T extends z.Schema>(schema: T) => {\n return required !== true ? schema.optional() : schema.nonoptional();\n };\n};\n\n/**\n * Conditionally makes a Zod schema readonly based on the `writable` parameter.\n *\n * @param writable - If `false`, the schema will be made readonly. If `true` or `undefined`, the schema remains unchanged.\n * @returns A function that takes a Zod schema and returns a modified schema (readonly or original).\n * @example\n * ```typescript\n * const readonlyNumber = maybeReadonly(false)(z.number()); // z.ZodReadonly<z.ZodNumber>\n * const writableNumber = maybeReadonly(true)(z.number()); // z.ZodNumber\n * ```\n */\nexport const maybeReadonly = (writable?: boolean) => {\n return <T extends z.Schema>(schema: T) => (writable !== false ? schema : schema.readonly());\n};\n\n/**\n * Conditionally adds a default value to a Zod schema based on the `defaultValue` parameter.\n *\n * @param defaultValue - The default value to apply to the schema. If `undefined`, no default value is added.\n * If `defaultValue` is a function, its return value will be used as the default.\n * @returns A function that takes a Zod schema and returns a modified schema (with default or original).\n * @example\n * ```typescript\n * const stringWithDefault = maybeWithDefault(\"default\")(z.string()); // z.ZodDefault<z.ZodString>\n * const numberWithFunctionDefault = maybeWithDefault(() => Math.random())(z.number());\n * ```\n */\nexport const maybeWithDefault = (defaultValue?: unknown) => {\n return <T extends z.Schema>(schema: T) => {\n if (defaultValue === undefined) {\n return schema;\n }\n\n const value = typeof defaultValue === 'function' ? defaultValue() : defaultValue;\n return schema.default(value);\n };\n};\n\n/**\n * Conditionally applies `min` and `max` constraints to a Zod string, number, or array schema.\n *\n * @param min - The minimum value/length. If `undefined`, no minimum constraint is applied.\n * @param max - The maximum value/length. If `undefined`, no maximum constraint is applied.\n * @returns A function that takes a Zod string, number, or array schema and returns a modified schema (with min/max constraints or original).\n * @example\n * ```typescript\n * const stringWithMinMax = maybeWithMinMax(5, 10)(z.string()); // z.ZodString with min(5) and max(10)\n * const numberWithMinMax = maybeWithMinMax(0, 100)(z.number()); // z.ZodNumber with min(0) and max(100)\n * ```\n */\nexport const maybeWithMinMax = (min?: number, max?: number) => {\n return <R extends z.ZodString | z.ZodEmail | z.ZodNumber | z.ZodArray<z.ZodAny>>(schema: R) => {\n return min !== undefined && max !== undefined ? schema.min(min).max(max) : schema;\n };\n};\n\n/**\n * Applies a series of modifier functions to a Zod schema sequentially.\n *\n * @template T - The type of the Zod schema.\n * @param schema - The initial Zod schema to which modifiers will be applied.\n * @param modifiers - An array of functions, each taking a Zod schema and returning a modified schema.\n * @returns The final Zod schema after all modifiers have been applied.\n * @example\n * ```typescript\n * const modifiedSchema = augmentSchema(z.string(), [\n * maybeRequired(false),\n * maybeWithDefault(\"test\")\n * ]);\n * ```\n */\nexport const augmentSchema = <T extends z.Schema>(\n schema: T,\n modifiers: ((schema: T) => z.Schema)[]\n) => {\n return modifiers.reduce((acc, modifier) => modifier(acc) as T, schema);\n};\n"],"names":["transformUidToValidOpenApiName","uid","capitalize","str","charAt","toUpperCase","slice","toPascalCase","split","map","join","includes","namespace","rest","namespacePart","restParts","parts","transformedParts","maybeRequired","required","schema","optional","nonoptional","maybeReadonly","writable","readonly","maybeWithDefault","defaultValue","undefined","value","default","maybeWithMinMax","min","max","augmentSchema","modifiers","reduce","acc","modifier"],"mappings":"AAAA;;;;;;;;;IAcaA,MAAAA,8BAAAA,GAAiC,CAACC,GAAAA,GAAAA;AAC7C,IAAA,MAAMC,aAAa,CAACC,GAAAA,GAAAA;QAClB,OAAOA,GAAAA,CAAIC,MAAM,CAAC,CAAA,CAAA,CAAGC,WAAW,EAAKF,GAAAA,GAAAA,CAAIG,KAAK,C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@ const validateZod = (schema)=>(data)=>{
|
|
|
17
17
|
}
|
|
18
18
|
};
|
|
19
19
|
const formatZodErrors = (zodError)=>({
|
|
20
|
-
errors: zodError.
|
|
20
|
+
errors: zodError.issues.map((issue)=>{
|
|
21
21
|
return {
|
|
22
22
|
path: issue.path,
|
|
23
23
|
message: issue.message,
|
|
24
|
-
name:
|
|
24
|
+
name: 'ValidationError'
|
|
25
25
|
};
|
|
26
26
|
}),
|
|
27
27
|
message: 'Validation error'
|
package/dist/zod.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zod.js","sources":["../src/zod.ts"],"sourcesContent":["import { z } from 'zod';\n\nimport { ValidationError } from './errors';\n\nexport const validateZod =\n <T extends z.ZodTypeAny>(schema: T) =>\n (data: unknown): z.TypeOf<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(message, { errors });\n }\n\n throw error;\n }\n };\n\nconst formatZodErrors = (zodError: z.ZodError) => ({\n errors: zodError.
|
|
1
|
+
{"version":3,"file":"zod.js","sources":["../src/zod.ts"],"sourcesContent":["import { z } from 'zod';\n\nimport { ValidationError } from './errors';\n\nexport const validateZod =\n <T extends z.ZodTypeAny>(schema: T) =>\n (data: unknown): z.TypeOf<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(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,\n message: issue.message,\n name: 'ValidationError',\n };\n }),\n message: 'Validation error',\n});\n"],"names":["validateZod","schema","data","parse","error","z","ZodError","message","errors","formatZodErrors","ValidationError","zodError","issues","map","issue","path","name"],"mappings":";;;;;AAIaA,MAAAA,WAAAA,GACX,CAAyBC,MAAAA,GACzB,CAACC,IAAAA,GAAAA;QACC,IAAI;YACF,OAAOD,MAAAA,CAAOE,KAAK,CAACD,IAAAA,CAAAA;AACtB,SAAA,CAAE,OAAOE,KAAO,EAAA;YACd,IAAIA,KAAAA,YAAiBC,KAAEC,CAAAA,QAAQ,EAAE;AAC/B,gBAAA,MAAM,EAAEC,OAAO,UAAEC,QAAM,EAAE,GAAGC,eAAgBL,CAAAA,KAAAA,CAAAA;gBAC5C,MAAM,IAAIM,uBAAgBH,OAAS,EAAA;AAAEC,4BAAAA;AAAO,iBAAA,CAAA;AAC9C;YAEA,MAAMJ,KAAAA;AACR;;AAGJ,MAAMK,eAAAA,GAAkB,CAACE,QAAAA,IAA0B;AACjDH,QAAAA,MAAAA,EAAQG,QAASC,CAAAA,MAAM,CAACC,GAAG,CAAC,CAACC,KAAAA,GAAAA;YAC3B,OAAO;AACLC,gBAAAA,IAAAA,EAAMD,MAAMC,IAAI;AAChBR,gBAAAA,OAAAA,EAASO,MAAMP,OAAO;gBACtBS,IAAM,EAAA;AACR,aAAA;AACF,SAAA,CAAA;QACAT,OAAS,EAAA;KACX,CAAA;;;;"}
|
package/dist/zod.mjs
CHANGED
|
@@ -15,11 +15,11 @@ const validateZod = (schema)=>(data)=>{
|
|
|
15
15
|
}
|
|
16
16
|
};
|
|
17
17
|
const formatZodErrors = (zodError)=>({
|
|
18
|
-
errors: zodError.
|
|
18
|
+
errors: zodError.issues.map((issue)=>{
|
|
19
19
|
return {
|
|
20
20
|
path: issue.path,
|
|
21
21
|
message: issue.message,
|
|
22
|
-
name:
|
|
22
|
+
name: 'ValidationError'
|
|
23
23
|
};
|
|
24
24
|
}),
|
|
25
25
|
message: 'Validation error'
|
package/dist/zod.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zod.mjs","sources":["../src/zod.ts"],"sourcesContent":["import { z } from 'zod';\n\nimport { ValidationError } from './errors';\n\nexport const validateZod =\n <T extends z.ZodTypeAny>(schema: T) =>\n (data: unknown): z.TypeOf<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(message, { errors });\n }\n\n throw error;\n }\n };\n\nconst formatZodErrors = (zodError: z.ZodError) => ({\n errors: zodError.
|
|
1
|
+
{"version":3,"file":"zod.mjs","sources":["../src/zod.ts"],"sourcesContent":["import { z } from 'zod';\n\nimport { ValidationError } from './errors';\n\nexport const validateZod =\n <T extends z.ZodTypeAny>(schema: T) =>\n (data: unknown): z.TypeOf<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(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,\n message: issue.message,\n name: 'ValidationError',\n };\n }),\n message: 'Validation error',\n});\n"],"names":["validateZod","schema","data","parse","error","z","ZodError","message","errors","formatZodErrors","ValidationError","zodError","issues","map","issue","path","name"],"mappings":";;;AAIaA,MAAAA,WAAAA,GACX,CAAyBC,MAAAA,GACzB,CAACC,IAAAA,GAAAA;QACC,IAAI;YACF,OAAOD,MAAAA,CAAOE,KAAK,CAACD,IAAAA,CAAAA;AACtB,SAAA,CAAE,OAAOE,KAAO,EAAA;YACd,IAAIA,KAAAA,YAAiBC,CAAEC,CAAAA,QAAQ,EAAE;AAC/B,gBAAA,MAAM,EAAEC,OAAO,EAAEC,MAAM,EAAE,GAAGC,eAAgBL,CAAAA,KAAAA,CAAAA;gBAC5C,MAAM,IAAIM,gBAAgBH,OAAS,EAAA;AAAEC,oBAAAA;AAAO,iBAAA,CAAA;AAC9C;YAEA,MAAMJ,KAAAA;AACR;;AAGJ,MAAMK,eAAAA,GAAkB,CAACE,QAAAA,IAA0B;AACjDH,QAAAA,MAAAA,EAAQG,QAASC,CAAAA,MAAM,CAACC,GAAG,CAAC,CAACC,KAAAA,GAAAA;YAC3B,OAAO;AACLC,gBAAAA,IAAAA,EAAMD,MAAMC,IAAI;AAChBR,gBAAAA,OAAAA,EAASO,MAAMP,OAAO;gBACtBS,IAAM,EAAA;AACR,aAAA;AACF,SAAA,CAAA;QACAT,OAAS,EAAA;KACX,CAAA;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/utils",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.20.0",
|
|
4
4
|
"description": "Shared utilities for the Strapi packages",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"strapi",
|
|
@@ -55,16 +55,16 @@
|
|
|
55
55
|
"p-map": "4.0.0",
|
|
56
56
|
"preferred-pm": "3.1.2",
|
|
57
57
|
"yup": "0.32.9",
|
|
58
|
-
"zod": "3.
|
|
58
|
+
"zod": "3.25.67"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@types/http-errors": "2.0.4",
|
|
62
62
|
"@types/koa": "2.13.4",
|
|
63
63
|
"@types/node": "18.19.24",
|
|
64
|
-
"eslint-config-custom": "5.
|
|
64
|
+
"eslint-config-custom": "5.20.0",
|
|
65
65
|
"koa": "2.16.1",
|
|
66
66
|
"koa-body": "6.0.1",
|
|
67
|
-
"tsconfig": "5.
|
|
67
|
+
"tsconfig": "5.20.0"
|
|
68
68
|
},
|
|
69
69
|
"engines": {
|
|
70
70
|
"node": ">=18.0.0 <=22.x.x",
|