@strapi/core 5.45.1 → 5.46.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/core-api/routes/validation/attributes.d.ts +4 -4
- package/dist/core-api/routes/validation/attributes.d.ts.map +1 -1
- package/dist/core-api/routes/validation/attributes.js +6 -6
- package/dist/core-api/routes/validation/attributes.js.map +1 -1
- package/dist/core-api/routes/validation/attributes.mjs +6 -6
- package/dist/core-api/routes/validation/attributes.mjs.map +1 -1
- package/dist/core-api/routes/validation/component.js +1 -1
- package/dist/core-api/routes/validation/component.js.map +1 -1
- package/dist/core-api/routes/validation/component.mjs +1 -1
- package/dist/core-api/routes/validation/component.mjs.map +1 -1
- package/dist/core-api/routes/validation/content-type.js +2 -2
- package/dist/core-api/routes/validation/content-type.js.map +1 -1
- package/dist/core-api/routes/validation/content-type.mjs +2 -2
- package/dist/core-api/routes/validation/content-type.mjs.map +1 -1
- package/dist/core-api/routes/validation/mappers.d.ts +5 -5
- package/dist/core-api/routes/validation/mappers.d.ts.map +1 -1
- package/dist/core-api/routes/validation/mappers.js +13 -21
- package/dist/core-api/routes/validation/mappers.js.map +1 -1
- package/dist/core-api/routes/validation/mappers.mjs +13 -21
- package/dist/core-api/routes/validation/mappers.mjs.map +1 -1
- package/dist/core-api/routes/validation/utils.d.ts +3 -3
- package/dist/core-api/routes/validation/utils.d.ts.map +1 -1
- package/dist/core-api/routes/validation/utils.js +4 -7
- package/dist/core-api/routes/validation/utils.js.map +1 -1
- package/dist/core-api/routes/validation/utils.mjs +4 -7
- package/dist/core-api/routes/validation/utils.mjs.map +1 -1
- package/dist/package.json.js +12 -12
- package/dist/package.json.mjs +12 -12
- package/dist/services/content-source-maps.d.ts.map +1 -1
- package/dist/services/content-source-maps.js +12 -4
- package/dist/services/content-source-maps.js.map +1 -1
- package/dist/services/content-source-maps.mjs +12 -4
- package/dist/services/content-source-maps.mjs.map +1 -1
- package/dist/services/document-service/transform/relations/extract/data-ids.d.ts.map +1 -1
- package/dist/services/document-service/transform/relations/extract/data-ids.js +4 -1
- package/dist/services/document-service/transform/relations/extract/data-ids.js.map +1 -1
- package/dist/services/document-service/transform/relations/extract/data-ids.mjs +4 -1
- package/dist/services/document-service/transform/relations/extract/data-ids.mjs.map +1 -1
- package/dist/services/document-service/transform/relations/transform/data-ids.d.ts.map +1 -1
- package/dist/services/document-service/transform/relations/transform/data-ids.js +4 -1
- package/dist/services/document-service/transform/relations/transform/data-ids.js.map +1 -1
- package/dist/services/document-service/transform/relations/transform/data-ids.mjs +4 -1
- package/dist/services/document-service/transform/relations/transform/data-ids.mjs.map +1 -1
- package/dist/services/document-service/transform/relations/utils/xto-one.d.ts +8 -0
- package/dist/services/document-service/transform/relations/utils/xto-one.d.ts.map +1 -0
- package/dist/services/document-service/transform/relations/utils/xto-one.js +41 -0
- package/dist/services/document-service/transform/relations/utils/xto-one.js.map +1 -0
- package/dist/services/document-service/transform/relations/utils/xto-one.mjs +39 -0
- package/dist/services/document-service/transform/relations/utils/xto-one.mjs.map +1 -0
- package/package.json +12 -12
|
@@ -78,7 +78,7 @@ var z__namespace = /*#__PURE__*/_interopNamespaceDefault(z);
|
|
|
78
78
|
'password'
|
|
79
79
|
].includes(attribute.type));
|
|
80
80
|
// Merge all attributes into a single schema
|
|
81
|
-
const attributesSchema = mappers.createAttributesSchema(sanitizedAttributes);
|
|
81
|
+
const attributesSchema = mappers.createAttributesSchema(this._strapi, sanitizedAttributes);
|
|
82
82
|
return z__namespace.object({
|
|
83
83
|
documentId: this.documentID,
|
|
84
84
|
id: z__namespace.union([
|
|
@@ -165,7 +165,7 @@ var z__namespace = /*#__PURE__*/_interopNamespaceDefault(z);
|
|
|
165
165
|
});
|
|
166
166
|
const sanitizedAttributes = entries// Remove non-writable attributes
|
|
167
167
|
.filter(isWritableAttribute);
|
|
168
|
-
return mappers.createAttributesInputSchema(sanitizedAttributes);
|
|
168
|
+
return mappers.createAttributesInputSchema(this._strapi, sanitizedAttributes);
|
|
169
169
|
}
|
|
170
170
|
get query() {
|
|
171
171
|
return z__namespace.string();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-type.js","sources":["../../../../src/core-api/routes/validation/content-type.ts"],"sourcesContent":["import type { Schema, UID } from '@strapi/types';\n\nimport { contentTypes } from '@strapi/utils';\nimport * as z from 'zod/v4';\n\n// eslint-disable-next-line import/no-cycle\nimport { createAttributesInputSchema, createAttributesSchema } from './mappers';\nimport { AbstractCoreRouteValidator } from './common';\n\nexport type QueryParam =\n | 'fields'\n | 'populate'\n | 'sort'\n | 'status'\n | 'hasPublishedVersion'\n | 'locale'\n | 'pagination'\n | 'filters'\n | '_q';\n\n/**\n * A validator for core content-type routes.\n *\n * Provides validation schemas and utilities for handling content-type-specific route validation.\n * Extends the base AbstractRouteValidator with schema-aware validation for Strapi content types.\n *\n * @example\n * ```ts\n * const strapi = // ... strapi instance\n * const uid = 'api::article.article'\n * const validator = new CoreContentTypeRouteValidator(strapi, uid);\n *\n * // Get validation schema for document\n * const documentSchema = validator.document;\n *\n * // Validate query parameters with schema awareness\n * const querySchema = validator.queryParams(['fields', 'populate', 'sort']);\n * ```\n */\nexport class CoreContentTypeRouteValidator extends AbstractCoreRouteValidator<UID.ContentType> {\n /**\n * Generates a validation schema for document IDs\n *\n * @returns A schema that validates UUIDs\n *\n * @example\n * ```ts\n * const validator = new CoreContentTypeRouteValidator(strapi, uid);\n * const idSchema = validator.documentID;\n * ```\n */\n get documentID() {\n return z.uuid().describe('The document ID, represented by a UUID');\n }\n\n /**\n * Generates a comprehensive validation schema for a single document.\n *\n * Combines scalar fields and populatable fields into a single schema.\n *\n * @returns A schema for validating complete documents\n *\n * @example\n * ```ts\n * const validator = new CoreContentTypeRouteValidator(strapi, uid);\n * const docSchema = validator.document;\n * ```\n */\n get document() {\n const entries = Object.entries({ ...this._scalarFields, ...this._populatableFields });\n\n const sanitizedAttributes = entries\n // Remove passwords from the attribute list\n .filter(([, attribute]) => !['password'].includes(attribute.type));\n\n // Merge all attributes into a single schema\n const attributesSchema = createAttributesSchema(sanitizedAttributes);\n\n return z\n .object({\n documentId: this.documentID,\n id: z.union([z.string(), z.number()]),\n })\n .extend(attributesSchema.shape);\n }\n\n /**\n * Generates a validation schema for an array of documents\n *\n * @returns A schema for validating arrays of documents\n *\n * @example\n * ```ts\n * const validator = new CoreContentTypeRouteValidator(strapi, uid);\n * const docsSchema = validator.documents;\n * ```\n */\n get documents() {\n return z.array(this.document);\n }\n\n /**\n * Schema-aware fields validation that restricts to actual model fields\n */\n protected get schemaAwareQueryFields() {\n return this.scalarFieldsArray\n .readonly()\n .describe(\n `The fields to return, this doesn't include populatable fields like relations, components, files, or dynamic zones`\n );\n }\n\n /**\n * Schema-aware populate validation that restricts to actual populatable fields\n */\n protected get schemaAwareQueryPopulate() {\n const wildcardPopulate = z\n .literal('*')\n .readonly()\n .describe(\n 'Populate all the first level relations, components, files, and dynamic zones for the entry'\n );\n\n const singleFieldPopulate = this.populatableFieldsEnum\n .readonly()\n .describe('Populate a single relation, component, file, or dynamic zone');\n\n const multiPopulate = this.populatableFieldsArray.describe(\n 'Populate a selection of multiple relations, components, files, or dynamic zones'\n );\n\n return z.union([wildcardPopulate, singleFieldPopulate, multiPopulate]);\n }\n\n /**\n * Schema-aware sort validation that restricts to actual model fields\n */\n protected get schemaAwareQuerySort() {\n const orderDirection = z.enum(['asc', 'desc']);\n\n // TODO: Handle nested sorts but very low priority, very little usage\n return z\n .union([\n this.scalarFieldsEnum, // 'name' | 'title'\n this.scalarFieldsArray, // ['name', 'title']\n this.fieldRecord(orderDirection), // { name: 'desc' } | { title: 'asc' }\n z.array(this.fieldRecord(orderDirection)), // [{ name: 'desc'}, { title: 'asc' }]\n ])\n .describe('Sort the result');\n }\n\n /**\n * Schema-aware filters validation that restricts to actual model fields\n */\n protected get schemaAwareFilters() {\n return z.record(this.scalarFieldsEnum, z.any()).describe('Filters to apply to the query');\n }\n\n get locale() {\n return z.string().describe('Select a locale');\n }\n\n get status() {\n return z\n .enum(['draft', 'published'])\n .describe('Fetch documents based on their status. Default to \"published\" if not specified.');\n }\n\n get hasPublishedVersion() {\n return z\n .union([z.boolean(), z.enum(['true', 'false'])])\n .describe(\n 'Filter documents by whether they have a published version. Use with status=draft to find documents that have never been published'\n );\n }\n\n get data() {\n const isWritableAttribute = ([attributeName]: [string, Schema.Attribute.AnyAttribute]) => {\n return contentTypes.isWritableAttribute(this._schema, attributeName);\n };\n\n const entries = Object.entries({ ...this._scalarFields, ...this._populatableFields });\n\n const sanitizedAttributes = entries\n // Remove non-writable attributes\n .filter(isWritableAttribute);\n\n return createAttributesInputSchema(sanitizedAttributes);\n }\n\n get query() {\n return z.string();\n }\n\n get body() {\n return z.object({ data: this.data });\n }\n\n get partialBody() {\n return z.object({ data: this.data.partial() });\n }\n\n /**\n * Creates validation schemas for query parameters\n *\n * @param params - Array of query parameters to validate ('fields', 'populate', 'sort', ...)\n * @returns Object containing validation schemas for requested parameters\n *\n * @example\n * ```ts\n * const validator = new CoreContentTypeRouteValidator(strapi, uid);\n * const querySchemas = validator.queryParams(['fields', 'populate']);\n * ```\n */\n queryParams(params: QueryParam[]): Partial<Record<QueryParam, z.Schema>> {\n const map: Record<QueryParam, () => z.Schema> = {\n fields: () => this.schemaAwareQueryFields.optional(),\n populate: () => this.schemaAwareQueryPopulate.optional(),\n sort: () => this.schemaAwareQuerySort.optional(),\n filters: () => this.schemaAwareFilters.optional(),\n locale: () => this.locale.optional(),\n pagination: () => this.pagination.optional(),\n status: () => this.status.optional(),\n hasPublishedVersion: () => this.hasPublishedVersion.optional(),\n _q: () => this.query.optional(),\n } as const;\n\n return params.reduce(\n (acc, param) => ({ ...acc, [param]: map[param]() }),\n {} as Partial<Record<QueryParam, z.Schema>>\n );\n }\n}\n"],"names":["CoreContentTypeRouteValidator","AbstractCoreRouteValidator","documentID","z","uuid","describe","document","entries","Object","_scalarFields","_populatableFields","sanitizedAttributes","filter","attribute","includes","type","attributesSchema","createAttributesSchema","object","documentId","id","union","string","number","extend","shape","documents","array","schemaAwareQueryFields","scalarFieldsArray","readonly","schemaAwareQueryPopulate","wildcardPopulate","literal","singleFieldPopulate","populatableFieldsEnum","multiPopulate","populatableFieldsArray","schemaAwareQuerySort","orderDirection","enum","scalarFieldsEnum","fieldRecord","schemaAwareFilters","record","any","locale","status","hasPublishedVersion","boolean","data","isWritableAttribute","attributeName","contentTypes","_schema","createAttributesInputSchema","query","body","partialBody","partial","queryParams","params","map","fields","optional","populate","sort","filters","pagination","_q","reduce","acc","param"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAoBA;;;;;;;;;;;;;;;;;;IAmBO,MAAMA,6BAAAA,SAAsCC,iCAAAA,CAAAA;AACjD;;;;;;;;;;AAUC,MACD,IAAIC,UAAAA,GAAa;AACf,QAAA,OAAOC,YAAAA,CAAEC,IAAI,EAAA,CAAGC,QAAQ,CAAC,wCAAA,CAAA;AAC3B,IAAA;AAEA;;;;;;;;;;;;AAYC,MACD,IAAIC,QAAAA,GAAW;QACb,MAAMC,OAAAA,GAAUC,MAAAA,CAAOD,OAAO,CAAC;YAAE,GAAG,IAAI,CAACE,aAAa;YAAE,GAAG,IAAI,CAACC;AAAmB,SAAA,CAAA;QAEnF,MAAMC,mBAAAA,GAAsBJ,OAC1B;AACCK,SAAAA,MAAM,CAAC,CAAC,GAAGC,SAAAA,CAAU,GAAK,CAAC;AAAC,gBAAA;aAAW,CAACC,QAAQ,CAACD,SAAAA,CAAUE,IAAI,CAAA,CAAA;;AAGlE,QAAA,MAAMC,mBAAmBC,8BAAAA,CAAuBN,mBAAAA,CAAAA;QAEhD,OAAOR,YAAAA,CACJe,MAAM,CAAC;YACNC,UAAAA,EAAY,IAAI,CAACjB,UAAU;YAC3BkB,EAAAA,EAAIjB,YAAAA,CAAEkB,KAAK,CAAC;AAAClB,gBAAAA,YAAAA,CAAEmB,MAAM,EAAA;AAAInB,gBAAAA,YAAAA,CAAEoB,MAAM;AAAG,aAAA;S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MAAM,CAClB,CAACC,GAAAA,EAAKC,SAAW;AAAE,gBAAA,GAAGD,GAAG;AAAE,gBAAA,CAACC,KAAAA,GAAQV,GAAG,CAACU,KAAAA,CAAM;AAAG,aAAA,GACjD,EAAC,CAAA;AAEL,IAAA;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"content-type.js","sources":["../../../../src/core-api/routes/validation/content-type.ts"],"sourcesContent":["import type { Schema, UID } from '@strapi/types';\n\nimport { contentTypes } from '@strapi/utils';\nimport * as z from 'zod/v4';\n\n// eslint-disable-next-line import/no-cycle\nimport { createAttributesInputSchema, createAttributesSchema } from './mappers';\nimport { AbstractCoreRouteValidator } from './common';\n\nexport type QueryParam =\n | 'fields'\n | 'populate'\n | 'sort'\n | 'status'\n | 'hasPublishedVersion'\n | 'locale'\n | 'pagination'\n | 'filters'\n | '_q';\n\n/**\n * A validator for core content-type routes.\n *\n * Provides validation schemas and utilities for handling content-type-specific route validation.\n * Extends the base AbstractRouteValidator with schema-aware validation for Strapi content types.\n *\n * @example\n * ```ts\n * const strapi = // ... strapi instance\n * const uid = 'api::article.article'\n * const validator = new CoreContentTypeRouteValidator(strapi, uid);\n *\n * // Get validation schema for document\n * const documentSchema = validator.document;\n *\n * // Validate query parameters with schema awareness\n * const querySchema = validator.queryParams(['fields', 'populate', 'sort']);\n * ```\n */\nexport class CoreContentTypeRouteValidator extends AbstractCoreRouteValidator<UID.ContentType> {\n /**\n * Generates a validation schema for document IDs\n *\n * @returns A schema that validates UUIDs\n *\n * @example\n * ```ts\n * const validator = new CoreContentTypeRouteValidator(strapi, uid);\n * const idSchema = validator.documentID;\n * ```\n */\n get documentID() {\n return z.uuid().describe('The document ID, represented by a UUID');\n }\n\n /**\n * Generates a comprehensive validation schema for a single document.\n *\n * Combines scalar fields and populatable fields into a single schema.\n *\n * @returns A schema for validating complete documents\n *\n * @example\n * ```ts\n * const validator = new CoreContentTypeRouteValidator(strapi, uid);\n * const docSchema = validator.document;\n * ```\n */\n get document() {\n const entries = Object.entries({ ...this._scalarFields, ...this._populatableFields });\n\n const sanitizedAttributes = entries\n // Remove passwords from the attribute list\n .filter(([, attribute]) => !['password'].includes(attribute.type));\n\n // Merge all attributes into a single schema\n const attributesSchema = createAttributesSchema(this._strapi, sanitizedAttributes);\n\n return z\n .object({\n documentId: this.documentID,\n id: z.union([z.string(), z.number()]),\n })\n .extend(attributesSchema.shape);\n }\n\n /**\n * Generates a validation schema for an array of documents\n *\n * @returns A schema for validating arrays of documents\n *\n * @example\n * ```ts\n * const validator = new CoreContentTypeRouteValidator(strapi, uid);\n * const docsSchema = validator.documents;\n * ```\n */\n get documents() {\n return z.array(this.document);\n }\n\n /**\n * Schema-aware fields validation that restricts to actual model fields\n */\n protected get schemaAwareQueryFields() {\n return this.scalarFieldsArray\n .readonly()\n .describe(\n `The fields to return, this doesn't include populatable fields like relations, components, files, or dynamic zones`\n );\n }\n\n /**\n * Schema-aware populate validation that restricts to actual populatable fields\n */\n protected get schemaAwareQueryPopulate() {\n const wildcardPopulate = z\n .literal('*')\n .readonly()\n .describe(\n 'Populate all the first level relations, components, files, and dynamic zones for the entry'\n );\n\n const singleFieldPopulate = this.populatableFieldsEnum\n .readonly()\n .describe('Populate a single relation, component, file, or dynamic zone');\n\n const multiPopulate = this.populatableFieldsArray.describe(\n 'Populate a selection of multiple relations, components, files, or dynamic zones'\n );\n\n return z.union([wildcardPopulate, singleFieldPopulate, multiPopulate]);\n }\n\n /**\n * Schema-aware sort validation that restricts to actual model fields\n */\n protected get schemaAwareQuerySort() {\n const orderDirection = z.enum(['asc', 'desc']);\n\n // TODO: Handle nested sorts but very low priority, very little usage\n return z\n .union([\n this.scalarFieldsEnum, // 'name' | 'title'\n this.scalarFieldsArray, // ['name', 'title']\n this.fieldRecord(orderDirection), // { name: 'desc' } | { title: 'asc' }\n z.array(this.fieldRecord(orderDirection)), // [{ name: 'desc'}, { title: 'asc' }]\n ])\n .describe('Sort the result');\n }\n\n /**\n * Schema-aware filters validation that restricts to actual model fields\n */\n protected get schemaAwareFilters() {\n return z.record(this.scalarFieldsEnum, z.any()).describe('Filters to apply to the query');\n }\n\n get locale() {\n return z.string().describe('Select a locale');\n }\n\n get status() {\n return z\n .enum(['draft', 'published'])\n .describe('Fetch documents based on their status. Default to \"published\" if not specified.');\n }\n\n get hasPublishedVersion() {\n return z\n .union([z.boolean(), z.enum(['true', 'false'])])\n .describe(\n 'Filter documents by whether they have a published version. Use with status=draft to find documents that have never been published'\n );\n }\n\n get data() {\n const isWritableAttribute = ([attributeName]: [string, Schema.Attribute.AnyAttribute]) => {\n return contentTypes.isWritableAttribute(this._schema, attributeName);\n };\n\n const entries = Object.entries({ ...this._scalarFields, ...this._populatableFields });\n\n const sanitizedAttributes = entries\n // Remove non-writable attributes\n .filter(isWritableAttribute);\n\n return createAttributesInputSchema(this._strapi, sanitizedAttributes);\n }\n\n get query() {\n return z.string();\n }\n\n get body() {\n return z.object({ data: this.data });\n }\n\n get partialBody() {\n return z.object({ data: this.data.partial() });\n }\n\n /**\n * Creates validation schemas for query parameters\n *\n * @param params - Array of query parameters to validate ('fields', 'populate', 'sort', ...)\n * @returns Object containing validation schemas for requested parameters\n *\n * @example\n * ```ts\n * const validator = new CoreContentTypeRouteValidator(strapi, uid);\n * const querySchemas = validator.queryParams(['fields', 'populate']);\n * ```\n */\n queryParams(params: QueryParam[]): Partial<Record<QueryParam, z.Schema>> {\n const map: Record<QueryParam, () => z.Schema> = {\n fields: () => this.schemaAwareQueryFields.optional(),\n populate: () => this.schemaAwareQueryPopulate.optional(),\n sort: () => this.schemaAwareQuerySort.optional(),\n filters: () => this.schemaAwareFilters.optional(),\n locale: () => this.locale.optional(),\n pagination: () => this.pagination.optional(),\n status: () => this.status.optional(),\n hasPublishedVersion: () => this.hasPublishedVersion.optional(),\n _q: () => this.query.optional(),\n } as const;\n\n return params.reduce(\n (acc, param) => ({ ...acc, [param]: map[param]() }),\n {} as Partial<Record<QueryParam, z.Schema>>\n );\n }\n}\n"],"names":["CoreContentTypeRouteValidator","AbstractCoreRouteValidator","documentID","z","uuid","describe","document","entries","Object","_scalarFields","_populatableFields","sanitizedAttributes","filter","attribute","includes","type","attributesSchema","createAttributesSchema","_strapi","object","documentId","id","union","string","number","extend","shape","documents","array","schemaAwareQueryFields","scalarFieldsArray","readonly","schemaAwareQueryPopulate","wildcardPopulate","literal","singleFieldPopulate","populatableFieldsEnum","multiPopulate","populatableFieldsArray","schemaAwareQuerySort","orderDirection","enum","scalarFieldsEnum","fieldRecord","schemaAwareFilters","record","any","locale","status","hasPublishedVersion","boolean","data","isWritableAttribute","attributeName","contentTypes","_schema","createAttributesInputSchema","query","body","partialBody","partial","queryParams","params","map","fields","optional","populate","sort","filters","pagination","_q","reduce","acc","param"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAoBA;;;;;;;;;;;;;;;;;;IAmBO,MAAMA,6BAAAA,SAAsCC,iCAAAA,CAAAA;AACjD;;;;;;;;;;AAUC,MACD,IAAIC,UAAAA,GAAa;AACf,QAAA,OAAOC,YAAAA,CAAEC,IAAI,EAAA,CAAGC,QAAQ,CAAC,wCAAA,CAAA;AAC3B,IAAA;AAEA;;;;;;;;;;;;AAYC,MACD,IAAIC,QAAAA,GAAW;QACb,MAAMC,OAAAA,GAAUC,MAAAA,CAAOD,OAAO,CAAC;YAAE,GAAG,IAAI,CAACE,aAAa;YAAE,GAAG,IAAI,CAACC;AAAmB,SAAA,CAAA;QAEnF,MAAMC,mBAAAA,GAAsBJ,OAC1B;AACCK,SAAAA,MAAM,CAAC,CAAC,GAAGC,SAAAA,CAAU,GAAK,CAAC;AAAC,gBAAA;aAAW,CAACC,QAAQ,CAACD,SAAAA,CAAUE,IAAI,CAAA,CAAA;;AAGlE,QAAA,MAAMC,gBAAAA,GAAmBC,8BAAAA,CAAuB,IAAI,CAACC,OAAO,EAAEP,mBAAAA,CAAAA;QAE9D,OAAOR,YAAAA,CACJgB,MAAM,CAAC;YACNC,UAAAA,EAAY,IAAI,CAAClB,UAA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YAAAA,mBAAAA,EAAqB,IAAM,IAAI,CAACA,mBAAmB,CAACgB,QAAQ,EAAA;AAC5DK,YAAAA,EAAAA,EAAI,IAAM,IAAI,CAACb,KAAK,CAACQ,QAAQ;AAC/B,SAAA;AAEA,QAAA,OAAOH,OAAOS,MAAM,CAClB,CAACC,GAAAA,EAAKC,SAAW;AAAE,gBAAA,GAAGD,GAAG;AAAE,gBAAA,CAACC,KAAAA,GAAQV,GAAG,CAACU,KAAAA,CAAM;AAAG,aAAA,GACjD,EAAC,CAAA;AAEL,IAAA;AACF;;;;"}
|
|
@@ -57,7 +57,7 @@ import { AbstractCoreRouteValidator } from './common.mjs';
|
|
|
57
57
|
'password'
|
|
58
58
|
].includes(attribute.type));
|
|
59
59
|
// Merge all attributes into a single schema
|
|
60
|
-
const attributesSchema = createAttributesSchema(sanitizedAttributes);
|
|
60
|
+
const attributesSchema = createAttributesSchema(this._strapi, sanitizedAttributes);
|
|
61
61
|
return z.object({
|
|
62
62
|
documentId: this.documentID,
|
|
63
63
|
id: z.union([
|
|
@@ -144,7 +144,7 @@ import { AbstractCoreRouteValidator } from './common.mjs';
|
|
|
144
144
|
});
|
|
145
145
|
const sanitizedAttributes = entries// Remove non-writable attributes
|
|
146
146
|
.filter(isWritableAttribute);
|
|
147
|
-
return createAttributesInputSchema(sanitizedAttributes);
|
|
147
|
+
return createAttributesInputSchema(this._strapi, sanitizedAttributes);
|
|
148
148
|
}
|
|
149
149
|
get query() {
|
|
150
150
|
return z.string();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-type.mjs","sources":["../../../../src/core-api/routes/validation/content-type.ts"],"sourcesContent":["import type { Schema, UID } from '@strapi/types';\n\nimport { contentTypes } from '@strapi/utils';\nimport * as z from 'zod/v4';\n\n// eslint-disable-next-line import/no-cycle\nimport { createAttributesInputSchema, createAttributesSchema } from './mappers';\nimport { AbstractCoreRouteValidator } from './common';\n\nexport type QueryParam =\n | 'fields'\n | 'populate'\n | 'sort'\n | 'status'\n | 'hasPublishedVersion'\n | 'locale'\n | 'pagination'\n | 'filters'\n | '_q';\n\n/**\n * A validator for core content-type routes.\n *\n * Provides validation schemas and utilities for handling content-type-specific route validation.\n * Extends the base AbstractRouteValidator with schema-aware validation for Strapi content types.\n *\n * @example\n * ```ts\n * const strapi = // ... strapi instance\n * const uid = 'api::article.article'\n * const validator = new CoreContentTypeRouteValidator(strapi, uid);\n *\n * // Get validation schema for document\n * const documentSchema = validator.document;\n *\n * // Validate query parameters with schema awareness\n * const querySchema = validator.queryParams(['fields', 'populate', 'sort']);\n * ```\n */\nexport class CoreContentTypeRouteValidator extends AbstractCoreRouteValidator<UID.ContentType> {\n /**\n * Generates a validation schema for document IDs\n *\n * @returns A schema that validates UUIDs\n *\n * @example\n * ```ts\n * const validator = new CoreContentTypeRouteValidator(strapi, uid);\n * const idSchema = validator.documentID;\n * ```\n */\n get documentID() {\n return z.uuid().describe('The document ID, represented by a UUID');\n }\n\n /**\n * Generates a comprehensive validation schema for a single document.\n *\n * Combines scalar fields and populatable fields into a single schema.\n *\n * @returns A schema for validating complete documents\n *\n * @example\n * ```ts\n * const validator = new CoreContentTypeRouteValidator(strapi, uid);\n * const docSchema = validator.document;\n * ```\n */\n get document() {\n const entries = Object.entries({ ...this._scalarFields, ...this._populatableFields });\n\n const sanitizedAttributes = entries\n // Remove passwords from the attribute list\n .filter(([, attribute]) => !['password'].includes(attribute.type));\n\n // Merge all attributes into a single schema\n const attributesSchema = createAttributesSchema(sanitizedAttributes);\n\n return z\n .object({\n documentId: this.documentID,\n id: z.union([z.string(), z.number()]),\n })\n .extend(attributesSchema.shape);\n }\n\n /**\n * Generates a validation schema for an array of documents\n *\n * @returns A schema for validating arrays of documents\n *\n * @example\n * ```ts\n * const validator = new CoreContentTypeRouteValidator(strapi, uid);\n * const docsSchema = validator.documents;\n * ```\n */\n get documents() {\n return z.array(this.document);\n }\n\n /**\n * Schema-aware fields validation that restricts to actual model fields\n */\n protected get schemaAwareQueryFields() {\n return this.scalarFieldsArray\n .readonly()\n .describe(\n `The fields to return, this doesn't include populatable fields like relations, components, files, or dynamic zones`\n );\n }\n\n /**\n * Schema-aware populate validation that restricts to actual populatable fields\n */\n protected get schemaAwareQueryPopulate() {\n const wildcardPopulate = z\n .literal('*')\n .readonly()\n .describe(\n 'Populate all the first level relations, components, files, and dynamic zones for the entry'\n );\n\n const singleFieldPopulate = this.populatableFieldsEnum\n .readonly()\n .describe('Populate a single relation, component, file, or dynamic zone');\n\n const multiPopulate = this.populatableFieldsArray.describe(\n 'Populate a selection of multiple relations, components, files, or dynamic zones'\n );\n\n return z.union([wildcardPopulate, singleFieldPopulate, multiPopulate]);\n }\n\n /**\n * Schema-aware sort validation that restricts to actual model fields\n */\n protected get schemaAwareQuerySort() {\n const orderDirection = z.enum(['asc', 'desc']);\n\n // TODO: Handle nested sorts but very low priority, very little usage\n return z\n .union([\n this.scalarFieldsEnum, // 'name' | 'title'\n this.scalarFieldsArray, // ['name', 'title']\n this.fieldRecord(orderDirection), // { name: 'desc' } | { title: 'asc' }\n z.array(this.fieldRecord(orderDirection)), // [{ name: 'desc'}, { title: 'asc' }]\n ])\n .describe('Sort the result');\n }\n\n /**\n * Schema-aware filters validation that restricts to actual model fields\n */\n protected get schemaAwareFilters() {\n return z.record(this.scalarFieldsEnum, z.any()).describe('Filters to apply to the query');\n }\n\n get locale() {\n return z.string().describe('Select a locale');\n }\n\n get status() {\n return z\n .enum(['draft', 'published'])\n .describe('Fetch documents based on their status. Default to \"published\" if not specified.');\n }\n\n get hasPublishedVersion() {\n return z\n .union([z.boolean(), z.enum(['true', 'false'])])\n .describe(\n 'Filter documents by whether they have a published version. Use with status=draft to find documents that have never been published'\n );\n }\n\n get data() {\n const isWritableAttribute = ([attributeName]: [string, Schema.Attribute.AnyAttribute]) => {\n return contentTypes.isWritableAttribute(this._schema, attributeName);\n };\n\n const entries = Object.entries({ ...this._scalarFields, ...this._populatableFields });\n\n const sanitizedAttributes = entries\n // Remove non-writable attributes\n .filter(isWritableAttribute);\n\n return createAttributesInputSchema(sanitizedAttributes);\n }\n\n get query() {\n return z.string();\n }\n\n get body() {\n return z.object({ data: this.data });\n }\n\n get partialBody() {\n return z.object({ data: this.data.partial() });\n }\n\n /**\n * Creates validation schemas for query parameters\n *\n * @param params - Array of query parameters to validate ('fields', 'populate', 'sort', ...)\n * @returns Object containing validation schemas for requested parameters\n *\n * @example\n * ```ts\n * const validator = new CoreContentTypeRouteValidator(strapi, uid);\n * const querySchemas = validator.queryParams(['fields', 'populate']);\n * ```\n */\n queryParams(params: QueryParam[]): Partial<Record<QueryParam, z.Schema>> {\n const map: Record<QueryParam, () => z.Schema> = {\n fields: () => this.schemaAwareQueryFields.optional(),\n populate: () => this.schemaAwareQueryPopulate.optional(),\n sort: () => this.schemaAwareQuerySort.optional(),\n filters: () => this.schemaAwareFilters.optional(),\n locale: () => this.locale.optional(),\n pagination: () => this.pagination.optional(),\n status: () => this.status.optional(),\n hasPublishedVersion: () => this.hasPublishedVersion.optional(),\n _q: () => this.query.optional(),\n } as const;\n\n return params.reduce(\n (acc, param) => ({ ...acc, [param]: map[param]() }),\n {} as Partial<Record<QueryParam, z.Schema>>\n );\n }\n}\n"],"names":["CoreContentTypeRouteValidator","AbstractCoreRouteValidator","documentID","z","uuid","describe","document","entries","Object","_scalarFields","_populatableFields","sanitizedAttributes","filter","attribute","includes","type","attributesSchema","createAttributesSchema","object","documentId","id","union","string","number","extend","shape","documents","array","schemaAwareQueryFields","scalarFieldsArray","readonly","schemaAwareQueryPopulate","wildcardPopulate","literal","singleFieldPopulate","populatableFieldsEnum","multiPopulate","populatableFieldsArray","schemaAwareQuerySort","orderDirection","enum","scalarFieldsEnum","fieldRecord","schemaAwareFilters","record","any","locale","status","hasPublishedVersion","boolean","data","isWritableAttribute","attributeName","contentTypes","_schema","createAttributesInputSchema","query","body","partialBody","partial","queryParams","params","map","fields","optional","populate","sort","filters","pagination","_q","reduce","acc","param"],"mappings":";;;;;AAoBA;;;;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OAAO;AAAG,SAAA,CAAA;AAC9C,IAAA;AAEA;;;;;;;;;;;MAYAC,WAAAA,CAAYC,MAAoB,EAAyC;AACvE,QAAA,MAAMC,GAAAA,GAA0C;AAC9CC,YAAAA,MAAAA,EAAQ,IAAM,IAAI,CAACnC,sBAAsB,CAACoC,QAAQ,EAAA;AAClDC,YAAAA,QAAAA,EAAU,IAAM,IAAI,CAAClC,wBAAwB,CAACiC,QAAQ,EAAA;AACtDE,YAAAA,IAAAA,EAAM,IAAM,IAAI,CAAC5B,oBAAoB,CAAC0B,QAAQ,EAAA;AAC9CG,YAAAA,OAAAA,EAAS,IAAM,IAAI,CAACxB,kBAAkB,CAACqB,QAAQ,EAAA;AAC/ClB,YAAAA,MAAAA,EAAQ,IAAM,IAAI,CAACA,MAAM,CAACkB,QAAQ,EAAA;AAClCI,YAAAA,UAAAA,EAAY,IAAM,IAAI,CAACA,UAAU,CAACJ,QAAQ,EAAA;AAC1CjB,YAAAA,MAAAA,EAAQ,IAAM,IAAI,CAACA,MAAM,CAACiB,QAAQ,EAAA;AAClChB,YAAAA,mBAAAA,EAAqB,IAAM,IAAI,CAACA,mBAAmB,CAACgB,QAAQ,EAAA;AAC5DK,YAAAA,EAAAA,EAAI,IAAM,IAAI,CAACb,KAAK,CAACQ,QAAQ;AAC/B,SAAA;AAEA,QAAA,OAAOH,OAAOS,MAAM,CAClB,CAACC,GAAAA,EAAKC,SAAW;AAAE,gBAAA,GAAGD,GAAG;AAAE,gBAAA,CAACC,KAAAA,GAAQV,GAAG,CAACU,KAAAA,CAAM;AAAG,aAAA,GACjD,EAAC,CAAA;AAEL,IAAA;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"content-type.mjs","sources":["../../../../src/core-api/routes/validation/content-type.ts"],"sourcesContent":["import type { Schema, UID } from '@strapi/types';\n\nimport { contentTypes } from '@strapi/utils';\nimport * as z from 'zod/v4';\n\n// eslint-disable-next-line import/no-cycle\nimport { createAttributesInputSchema, createAttributesSchema } from './mappers';\nimport { AbstractCoreRouteValidator } from './common';\n\nexport type QueryParam =\n | 'fields'\n | 'populate'\n | 'sort'\n | 'status'\n | 'hasPublishedVersion'\n | 'locale'\n | 'pagination'\n | 'filters'\n | '_q';\n\n/**\n * A validator for core content-type routes.\n *\n * Provides validation schemas and utilities for handling content-type-specific route validation.\n * Extends the base AbstractRouteValidator with schema-aware validation for Strapi content types.\n *\n * @example\n * ```ts\n * const strapi = // ... strapi instance\n * const uid = 'api::article.article'\n * const validator = new CoreContentTypeRouteValidator(strapi, uid);\n *\n * // Get validation schema for document\n * const documentSchema = validator.document;\n *\n * // Validate query parameters with schema awareness\n * const querySchema = validator.queryParams(['fields', 'populate', 'sort']);\n * ```\n */\nexport class CoreContentTypeRouteValidator extends AbstractCoreRouteValidator<UID.ContentType> {\n /**\n * Generates a validation schema for document IDs\n *\n * @returns A schema that validates UUIDs\n *\n * @example\n * ```ts\n * const validator = new CoreContentTypeRouteValidator(strapi, uid);\n * const idSchema = validator.documentID;\n * ```\n */\n get documentID() {\n return z.uuid().describe('The document ID, represented by a UUID');\n }\n\n /**\n * Generates a comprehensive validation schema for a single document.\n *\n * Combines scalar fields and populatable fields into a single schema.\n *\n * @returns A schema for validating complete documents\n *\n * @example\n * ```ts\n * const validator = new CoreContentTypeRouteValidator(strapi, uid);\n * const docSchema = validator.document;\n * ```\n */\n get document() {\n const entries = Object.entries({ ...this._scalarFields, ...this._populatableFields });\n\n const sanitizedAttributes = entries\n // Remove passwords from the attribute list\n .filter(([, attribute]) => !['password'].includes(attribute.type));\n\n // Merge all attributes into a single schema\n const attributesSchema = createAttributesSchema(this._strapi, sanitizedAttributes);\n\n return z\n .object({\n documentId: this.documentID,\n id: z.union([z.string(), z.number()]),\n })\n .extend(attributesSchema.shape);\n }\n\n /**\n * Generates a validation schema for an array of documents\n *\n * @returns A schema for validating arrays of documents\n *\n * @example\n * ```ts\n * const validator = new CoreContentTypeRouteValidator(strapi, uid);\n * const docsSchema = validator.documents;\n * ```\n */\n get documents() {\n return z.array(this.document);\n }\n\n /**\n * Schema-aware fields validation that restricts to actual model fields\n */\n protected get schemaAwareQueryFields() {\n return this.scalarFieldsArray\n .readonly()\n .describe(\n `The fields to return, this doesn't include populatable fields like relations, components, files, or dynamic zones`\n );\n }\n\n /**\n * Schema-aware populate validation that restricts to actual populatable fields\n */\n protected get schemaAwareQueryPopulate() {\n const wildcardPopulate = z\n .literal('*')\n .readonly()\n .describe(\n 'Populate all the first level relations, components, files, and dynamic zones for the entry'\n );\n\n const singleFieldPopulate = this.populatableFieldsEnum\n .readonly()\n .describe('Populate a single relation, component, file, or dynamic zone');\n\n const multiPopulate = this.populatableFieldsArray.describe(\n 'Populate a selection of multiple relations, components, files, or dynamic zones'\n );\n\n return z.union([wildcardPopulate, singleFieldPopulate, multiPopulate]);\n }\n\n /**\n * Schema-aware sort validation that restricts to actual model fields\n */\n protected get schemaAwareQuerySort() {\n const orderDirection = z.enum(['asc', 'desc']);\n\n // TODO: Handle nested sorts but very low priority, very little usage\n return z\n .union([\n this.scalarFieldsEnum, // 'name' | 'title'\n this.scalarFieldsArray, // ['name', 'title']\n this.fieldRecord(orderDirection), // { name: 'desc' } | { title: 'asc' }\n z.array(this.fieldRecord(orderDirection)), // [{ name: 'desc'}, { title: 'asc' }]\n ])\n .describe('Sort the result');\n }\n\n /**\n * Schema-aware filters validation that restricts to actual model fields\n */\n protected get schemaAwareFilters() {\n return z.record(this.scalarFieldsEnum, z.any()).describe('Filters to apply to the query');\n }\n\n get locale() {\n return z.string().describe('Select a locale');\n }\n\n get status() {\n return z\n .enum(['draft', 'published'])\n .describe('Fetch documents based on their status. Default to \"published\" if not specified.');\n }\n\n get hasPublishedVersion() {\n return z\n .union([z.boolean(), z.enum(['true', 'false'])])\n .describe(\n 'Filter documents by whether they have a published version. Use with status=draft to find documents that have never been published'\n );\n }\n\n get data() {\n const isWritableAttribute = ([attributeName]: [string, Schema.Attribute.AnyAttribute]) => {\n return contentTypes.isWritableAttribute(this._schema, attributeName);\n };\n\n const entries = Object.entries({ ...this._scalarFields, ...this._populatableFields });\n\n const sanitizedAttributes = entries\n // Remove non-writable attributes\n .filter(isWritableAttribute);\n\n return createAttributesInputSchema(this._strapi, sanitizedAttributes);\n }\n\n get query() {\n return z.string();\n }\n\n get body() {\n return z.object({ data: this.data });\n }\n\n get partialBody() {\n return z.object({ data: this.data.partial() });\n }\n\n /**\n * Creates validation schemas for query parameters\n *\n * @param params - Array of query parameters to validate ('fields', 'populate', 'sort', ...)\n * @returns Object containing validation schemas for requested parameters\n *\n * @example\n * ```ts\n * const validator = new CoreContentTypeRouteValidator(strapi, uid);\n * const querySchemas = validator.queryParams(['fields', 'populate']);\n * ```\n */\n queryParams(params: QueryParam[]): Partial<Record<QueryParam, z.Schema>> {\n const map: Record<QueryParam, () => z.Schema> = {\n fields: () => this.schemaAwareQueryFields.optional(),\n populate: () => this.schemaAwareQueryPopulate.optional(),\n sort: () => this.schemaAwareQuerySort.optional(),\n filters: () => this.schemaAwareFilters.optional(),\n locale: () => this.locale.optional(),\n pagination: () => this.pagination.optional(),\n status: () => this.status.optional(),\n hasPublishedVersion: () => this.hasPublishedVersion.optional(),\n _q: () => this.query.optional(),\n } as const;\n\n return params.reduce(\n (acc, param) => ({ ...acc, [param]: map[param]() }),\n {} as Partial<Record<QueryParam, z.Schema>>\n );\n }\n}\n"],"names":["CoreContentTypeRouteValidator","AbstractCoreRouteValidator","documentID","z","uuid","describe","document","entries","Object","_scalarFields","_populatableFields","sanitizedAttributes","filter","attribute","includes","type","attributesSchema","createAttributesSchema","_strapi","object","documentId","id","union","string","number","extend","shape","documents","array","schemaAwareQueryFields","scalarFieldsArray","readonly","schemaAwareQueryPopulate","wildcardPopulate","literal","singleFieldPopulate","populatableFieldsEnum","multiPopulate","populatableFieldsArray","schemaAwareQuerySort","orderDirection","enum","scalarFieldsEnum","fieldRecord","schemaAwareFilters","record","any","locale","status","hasPublishedVersion","boolean","data","isWritableAttribute","attributeName","contentTypes","_schema","createAttributesInputSchema","query","body","partialBody","partial","queryParams","params","map","fields","optional","populate","sort","filters","pagination","_q","reduce","acc","param"],"mappings":";;;;;AAoBA;;;;;;;;;;;;;;;;;;IAmBO,MAAMA,6BAAAA,SAAsCC,0BAAAA,CAAAA;AACjD;;;;;;;;;;AAUC,MACD,IAAIC,UAAAA,GAAa;AACf,QAAA,OAAOC,CAAAA,CAAEC,IAAI,EAAA,CAAGC,QAAQ,CAAC,wCAAA,CAAA;AAC3B,IAAA;AAEA;;;;;;;;;;;;AAYC,MACD,IAAIC,QAAAA,GAAW;QACb,MAAMC,OAAAA,GAAUC,MAAAA,CAAOD,OAAO,CAAC;YAAE,GAAG,IAAI,CAACE,aAAa;YAAE,GAAG,IAAI,CAACC;AAAmB,SAAA,CAAA;QAEnF,MAAMC,mBAAAA,GAAsBJ,OAC1B;AACCK,SAAAA,MAAM,CAAC,CAAC,GAAGC,SAAAA,CAAU,GAAK,CAAC;AAAC,gBAAA;aAAW,CAACC,QAAQ,CAACD,SAAAA,CAAUE,IAAI,CAAA,CAAA;;AAGlE,QAAA,MAAMC,gBAAAA,GAAmBC,sBAAAA,CAAuB,IAAI,CAACC,OAAO,EAAEP,mBAAAA,CAAAA;QAE9D,OAAOR,CAAAA,CACJgB,MAAM,CAAC;YACNC,UAAAA,EAAY,IAAI,CAAClB,UAAU;YAC3BmB,EAAAA,EAAIlB,CAAAA,CAAEmB,KAAK,CAAC;AAACnB,gBAAAA,CAAAA,CAAEoB,MAAM,EAAA;AAAIpB,gBAAAA,CAAAA,CAAEqB,MAAM;AAAG,aAAA;SACtC,CAAA,CACCC,MAAM,CAACT,gBAAAA,CAAiBU,KAAK,CAAA;AAClC,IAAA;AAEA;;;;;;;;;;AAUC,MACD,IAAIC,SAAAA,GAAY;AACd,QAAA,OAAOxB,CAAAA,CAAEyB,KAAK,CAAC,IAAI,CAACtB,QAAQ,CAAA;AAC9B,IAAA;AAEA;;AAEC,MACD,IAAcuB,sBAAAA,GAAyB;QACrC,OAAO,IAA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
* This file contains functions responsible for mapping Strapi attribute definitions to Zod schemas.
|
|
4
4
|
*/
|
|
5
|
-
import type { Schema } from '@strapi/types';
|
|
5
|
+
import type { Core, Schema } from '@strapi/types';
|
|
6
6
|
import * as z from 'zod/v4';
|
|
7
7
|
/**
|
|
8
8
|
* Creates a Zod schema for a collection of Strapi attributes.
|
|
@@ -21,7 +21,7 @@ import * as z from 'zod/v4';
|
|
|
21
21
|
* // each mapped to their respective Zod schemas based on their Strapi attribute types.
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
|
-
export declare const createAttributesSchema: (attributes: [name: string, attribute: Schema.Attribute.AnyAttribute][]) => z.ZodObject<{}, z.core.$strip>;
|
|
24
|
+
export declare const createAttributesSchema: (strapi: Core.Strapi, attributes: [name: string, attribute: Schema.Attribute.AnyAttribute][]) => z.ZodObject<{}, z.core.$strip>;
|
|
25
25
|
/**
|
|
26
26
|
* Creates a Zod input schema for a collection of Strapi attributes.
|
|
27
27
|
* This is typically used for validating incoming data (e.g., from API requests).
|
|
@@ -40,7 +40,7 @@ export declare const createAttributesSchema: (attributes: [name: string, attribu
|
|
|
40
40
|
* // mapped to Zod schemas suitable for input validation.
|
|
41
41
|
* ```
|
|
42
42
|
*/
|
|
43
|
-
export declare const createAttributesInputSchema: (attributes: [name: string, attribute: Schema.Attribute.AnyAttribute][]) => z.ZodObject<{}, z.core.$strip>;
|
|
43
|
+
export declare const createAttributesInputSchema: (strapi: Core.Strapi, attributes: [name: string, attribute: Schema.Attribute.AnyAttribute][]) => z.ZodObject<{}, z.core.$strip>;
|
|
44
44
|
/**
|
|
45
45
|
* Maps a Strapi attribute definition to a corresponding Zod validation schema.
|
|
46
46
|
*
|
|
@@ -60,7 +60,7 @@ export declare const createAttributesInputSchema: (attributes: [name: string, at
|
|
|
60
60
|
* const booleanSchema = mapAttributeToSchema(booleanAttribute); // Returns a Zod boolean schema with a default.
|
|
61
61
|
* ```
|
|
62
62
|
*/
|
|
63
|
-
export declare const mapAttributeToSchema: (attribute: Schema.Attribute.AnyAttribute) => z.ZodTypeAny;
|
|
63
|
+
export declare const mapAttributeToSchema: (strapi: Core.Strapi, attribute: Schema.Attribute.AnyAttribute) => z.ZodTypeAny;
|
|
64
64
|
/**
|
|
65
65
|
* Maps a Strapi attribute definition to a corresponding Zod input validation schema.
|
|
66
66
|
*
|
|
@@ -101,5 +101,5 @@ export declare const mapAttributeToSchema: (attribute: Schema.Attribute.AnyAttri
|
|
|
101
101
|
* @throws {Error} Throws an error if an unsupported attribute type is provided
|
|
102
102
|
*
|
|
103
103
|
*/
|
|
104
|
-
export declare const mapAttributeToInputSchema: (attribute: Schema.Attribute.AnyAttribute) => z.ZodTypeAny;
|
|
104
|
+
export declare const mapAttributeToInputSchema: (strapi: Core.Strapi, attribute: Schema.Attribute.AnyAttribute) => z.ZodTypeAny;
|
|
105
105
|
//# sourceMappingURL=mappers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mappers.d.ts","sourceRoot":"","sources":["../../../../src/core-api/routes/validation/mappers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"mappers.d.ts","sourceRoot":"","sources":["../../../../src/core-api/routes/validation/mappers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAgB5B;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,sBAAsB,WACzB,KAAK,MAAM,cACP,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,SAAS,CAAC,YAAY,CAAC,EAAE,mCASvE,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,2BAA2B,WAC9B,KAAK,MAAM,cACP,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,SAAS,CAAC,YAAY,CAAC,EAAE,mCASvE,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,oBAAoB,WACvB,KAAK,MAAM,aACR,OAAO,SAAS,CAAC,YAAY,KACvC,EAAE,UA4DJ,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,eAAO,MAAM,yBAAyB,WAC5B,KAAK,MAAM,aACR,OAAO,SAAS,CAAC,YAAY,KACvC,EAAE,UA4DJ,CAAC"}
|
|
@@ -41,11 +41,11 @@ const isCustomFieldAttribute = (attribute)=>{
|
|
|
41
41
|
* // schema will be a Zod object with 'title' and 'description' fields,
|
|
42
42
|
* // each mapped to their respective Zod schemas based on their Strapi attribute types.
|
|
43
43
|
* ```
|
|
44
|
-
*/ const createAttributesSchema = (attributes)=>{
|
|
44
|
+
*/ const createAttributesSchema = (strapi, attributes)=>{
|
|
45
45
|
return attributes.reduce((acc, [name, attribute])=>{
|
|
46
46
|
return acc.extend({
|
|
47
47
|
get [name] () {
|
|
48
|
-
return mapAttributeToSchema(attribute);
|
|
48
|
+
return mapAttributeToSchema(strapi, attribute);
|
|
49
49
|
}
|
|
50
50
|
});
|
|
51
51
|
}, z__namespace.object({}));
|
|
@@ -67,11 +67,11 @@ const isCustomFieldAttribute = (attribute)=>{
|
|
|
67
67
|
* // inputSchema will be a Zod object with 'email' and 'description' fields,
|
|
68
68
|
* // mapped to Zod schemas suitable for input validation.
|
|
69
69
|
* ```
|
|
70
|
-
*/ const createAttributesInputSchema = (attributes)=>{
|
|
70
|
+
*/ const createAttributesInputSchema = (strapi, attributes)=>{
|
|
71
71
|
return attributes.reduce((acc, [name, attribute])=>{
|
|
72
72
|
return acc.extend({
|
|
73
73
|
get [name] () {
|
|
74
|
-
return mapAttributeToInputSchema(attribute);
|
|
74
|
+
return mapAttributeToInputSchema(strapi, attribute);
|
|
75
75
|
}
|
|
76
76
|
});
|
|
77
77
|
}, z__namespace.object({}));
|
|
@@ -94,7 +94,7 @@ const isCustomFieldAttribute = (attribute)=>{
|
|
|
94
94
|
* const booleanAttribute = { type: 'boolean', default: false };
|
|
95
95
|
* const booleanSchema = mapAttributeToSchema(booleanAttribute); // Returns a Zod boolean schema with a default.
|
|
96
96
|
* ```
|
|
97
|
-
*/ const mapAttributeToSchema = (attribute)=>{
|
|
97
|
+
*/ const mapAttributeToSchema = (strapi, attribute)=>{
|
|
98
98
|
switch(attribute.type){
|
|
99
99
|
case 'biginteger':
|
|
100
100
|
return attributes.bigIntegerToSchema(attribute);
|
|
@@ -103,7 +103,7 @@ const isCustomFieldAttribute = (attribute)=>{
|
|
|
103
103
|
case 'boolean':
|
|
104
104
|
return attributes.booleanToSchema(attribute);
|
|
105
105
|
case 'component':
|
|
106
|
-
return attributes.componentToSchema(attribute);
|
|
106
|
+
return attributes.componentToSchema(strapi, attribute);
|
|
107
107
|
case 'date':
|
|
108
108
|
return attributes.dateToSchema(attribute);
|
|
109
109
|
case 'datetime':
|
|
@@ -123,9 +123,9 @@ const isCustomFieldAttribute = (attribute)=>{
|
|
|
123
123
|
case 'json':
|
|
124
124
|
return attributes.jsonToSchema(attribute);
|
|
125
125
|
case 'media':
|
|
126
|
-
return attributes.mediaToSchema(attribute);
|
|
126
|
+
return attributes.mediaToSchema(strapi, attribute);
|
|
127
127
|
case 'relation':
|
|
128
|
-
return attributes.relationToSchema(attribute);
|
|
128
|
+
return attributes.relationToSchema(strapi, attribute);
|
|
129
129
|
case 'password':
|
|
130
130
|
case 'text':
|
|
131
131
|
case 'richtext':
|
|
@@ -141,16 +141,12 @@ const isCustomFieldAttribute = (attribute)=>{
|
|
|
141
141
|
{
|
|
142
142
|
if (isCustomFieldAttribute(attribute)) {
|
|
143
143
|
const attrCF = attribute;
|
|
144
|
-
const
|
|
145
|
-
if (!strapiInstance) {
|
|
146
|
-
throw new Error('Strapi instance not available for custom field conversion');
|
|
147
|
-
}
|
|
148
|
-
const customField = strapiInstance.get('custom-fields').get(attrCF.customField);
|
|
144
|
+
const customField = strapi.get('custom-fields').get(attrCF.customField);
|
|
149
145
|
if (!customField) {
|
|
150
146
|
throw new Error(`Custom field '${attrCF.customField}' not found`);
|
|
151
147
|
}
|
|
152
148
|
// Re-dispatch with the resolved underlying Strapi kind
|
|
153
|
-
return mapAttributeToSchema({
|
|
149
|
+
return mapAttributeToSchema(strapi, {
|
|
154
150
|
...attrCF,
|
|
155
151
|
type: customField.type
|
|
156
152
|
});
|
|
@@ -199,7 +195,7 @@ const isCustomFieldAttribute = (attribute)=>{
|
|
|
199
195
|
*
|
|
200
196
|
* @throws {Error} Throws an error if an unsupported attribute type is provided
|
|
201
197
|
*
|
|
202
|
-
*/ const mapAttributeToInputSchema = (attribute)=>{
|
|
198
|
+
*/ const mapAttributeToInputSchema = (strapi, attribute)=>{
|
|
203
199
|
switch(attribute.type){
|
|
204
200
|
case 'biginteger':
|
|
205
201
|
return attributes.bigIntegerToInputSchema(attribute);
|
|
@@ -246,16 +242,12 @@ const isCustomFieldAttribute = (attribute)=>{
|
|
|
246
242
|
{
|
|
247
243
|
if (isCustomFieldAttribute(attribute)) {
|
|
248
244
|
const attrCF = attribute;
|
|
249
|
-
const
|
|
250
|
-
if (!strapiInstance) {
|
|
251
|
-
throw new Error('Strapi instance not available for custom field conversion');
|
|
252
|
-
}
|
|
253
|
-
const customField = strapiInstance.get('custom-fields').get(attrCF.customField);
|
|
245
|
+
const customField = strapi.get('custom-fields').get(attrCF.customField);
|
|
254
246
|
if (!customField) {
|
|
255
247
|
throw new Error(`Custom field '${attrCF.customField}' not found`);
|
|
256
248
|
}
|
|
257
249
|
// Re-dispatch with the resolved underlying Strapi kind
|
|
258
|
-
return mapAttributeToInputSchema({
|
|
250
|
+
return mapAttributeToInputSchema(strapi, {
|
|
259
251
|
...attrCF,
|
|
260
252
|
type: customField.type
|
|
261
253
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mappers.js","sources":["../../../../src/core-api/routes/validation/mappers.ts"],"sourcesContent":["/**\n * @fileoverview\n * This file contains functions responsible for mapping Strapi attribute definitions to Zod schemas.\n */\n\nimport type { Schema } from '@strapi/types';\nimport * as z from 'zod/v4';\n\n// eslint-disable-next-line import/no-cycle\nimport * as attributes from './attributes';\n\nconst isCustomFieldAttribute = (\n attribute: unknown\n): attribute is { type: 'customField'; customField: string } => {\n return (\n !!attribute &&\n typeof attribute === 'object' &&\n (attribute as any).type === 'customField' &&\n typeof (attribute as any).customField === 'string'\n );\n};\n\n/**\n * Creates a Zod schema for a collection of Strapi attributes.\n *\n * @param attributes - An array of tuples, where each tuple contains the attribute name and its schema definition.\n * @returns A Zod object schema representing the combined attributes.\n *\n * @example\n * ```typescript\n * const myAttributes = [\n * ['title', { type: 'string', required: true }],\n * ['description', { type: 'text' }],\n * ];\n * const schema = createAttributesSchema(myAttributes);\n * // schema will be a Zod object with 'title' and 'description' fields,\n * // each mapped to their respective Zod schemas based on their Strapi attribute types.\n * ```\n */\nexport const createAttributesSchema = (\n attributes: [name: string, attribute: Schema.Attribute.AnyAttribute][]\n) => {\n return attributes.reduce((acc, [name, attribute]) => {\n return acc.extend({\n get [name]() {\n return mapAttributeToSchema(attribute);\n },\n });\n }, z.object({}));\n};\n\n/**\n * Creates a Zod input schema for a collection of Strapi attributes.\n * This is typically used for validating incoming data (e.g., from API requests).\n *\n * @param attributes - An array of tuples, where each tuple contains the attribute name and its schema definition.\n * @returns A Zod object schema representing the combined input attributes.\n *\n * @example\n * ```typescript\n * const myInputAttributes = [\n * ['email', { type: 'email', required: true }],\n * ['description', { type: 'text', minLength: 8 }],\n * ];\n * const inputSchema = createAttributesInputSchema(myInputAttributes);\n * // inputSchema will be a Zod object with 'email' and 'description' fields,\n * // mapped to Zod schemas suitable for input validation.\n * ```\n */\nexport const createAttributesInputSchema = (\n attributes: [name: string, attribute: Schema.Attribute.AnyAttribute][]\n) => {\n return attributes.reduce((acc, [name, attribute]) => {\n return acc.extend({\n get [name]() {\n return mapAttributeToInputSchema(attribute);\n },\n });\n }, z.object({}));\n};\n\n/**\n * Maps a Strapi attribute definition to a corresponding Zod validation schema.\n *\n * This function handles every Strapi attribute types and converts them into\n * appropriate Zod validation schemas.\n *\n * @param attribute - The Strapi attribute configuration object.\n * @returns A Zod schema that corresponds to the input attribute's type.\n * @throws {Error} Throws an error if an unsupported attribute type is provided.\n *\n * @example\n * ```typescript\n * const stringAttribute = { type: 'string', minLength: 3 };\n * const stringSchema = mapAttributeToSchema(stringAttribute); // Returns a Zod string schema with minLength.\n *\n * const booleanAttribute = { type: 'boolean', default: false };\n * const booleanSchema = mapAttributeToSchema(booleanAttribute); // Returns a Zod boolean schema with a default.\n * ```\n */\nexport const mapAttributeToSchema = (attribute: Schema.Attribute.AnyAttribute): z.ZodTypeAny => {\n switch (attribute.type) {\n case 'biginteger':\n return attributes.bigIntegerToSchema(attribute);\n case 'blocks':\n return attributes.blocksToSchema();\n case 'boolean':\n return attributes.booleanToSchema(attribute);\n case 'component':\n return attributes.componentToSchema(attribute);\n case 'date':\n return attributes.dateToSchema(attribute);\n case 'datetime':\n return attributes.datetimeToSchema(attribute);\n case 'decimal':\n return attributes.decimalToSchema(attribute);\n case 'dynamiczone':\n return attributes.dynamicZoneToSchema(attribute);\n case 'email':\n return attributes.emailToSchema(attribute);\n case 'enumeration':\n return attributes.enumToSchema(attribute);\n case 'float':\n return attributes.floatToSchema(attribute);\n case 'integer':\n return attributes.integerToSchema(attribute);\n case 'json':\n return attributes.jsonToSchema(attribute);\n case 'media':\n return attributes.mediaToSchema(attribute);\n case 'relation':\n return attributes.relationToSchema(attribute);\n case 'password':\n case 'text':\n case 'richtext':\n case 'string':\n return attributes.stringToSchema(attribute);\n case 'time':\n return attributes.timeToSchema(attribute);\n case 'timestamp':\n return attributes.timestampToSchema(attribute);\n case 'uid':\n return attributes.uidToSchema(attribute);\n default: {\n if (isCustomFieldAttribute(attribute)) {\n const attrCF = attribute as { type: 'customField'; customField: string };\n const strapiInstance = global.strapi;\n if (!strapiInstance) {\n throw new Error('Strapi instance not available for custom field conversion');\n }\n\n const customField = strapiInstance.get('custom-fields').get(attrCF.customField);\n if (!customField) {\n throw new Error(`Custom field '${attrCF.customField}' not found`);\n }\n\n // Re-dispatch with the resolved underlying Strapi kind\n return mapAttributeToSchema({ ...attrCF, type: customField.type });\n }\n\n const { type } = attribute as Schema.Attribute.AnyAttribute;\n\n throw new Error(`Unsupported attribute type: ${type}`);\n }\n }\n};\n\n/**\n * Maps a Strapi attribute definition to a corresponding Zod input validation schema.\n *\n * This function handles every Strapi attribute types and converts them into\n * appropriate Zod validation schemas with their respective constraints.\n *\n * @param attribute - The Strapi attribute configuration object. Contains type information\n * and validation rules for the attribute.\n *\n * @returns A Zod schema that corresponds to the input attribute's type and validation rules\n *\n * @example\n * ```typescript\n * // String attribute with constraints\n * const stringAttribute = {\n * type: 'string',\n * minLength: 3,\n * maxLength: 50,\n * required: true\n * };\n * const stringSchema = mapAttributeToInputSchema(stringAttribute);\n *\n * // Enumeration attribute\n * const enumAttribute = {\n * type: 'enumeration',\n * enum: ['draft', 'published', 'archived']\n * };\n * const enumSchema = mapAttributeToInputSchema(enumAttribute);\n *\n * // Media attribute with multiple files\n * const mediaAttribute = {\n * type: 'media',\n * multiple: true\n * };\n * const mediaSchema = mapAttributeToInputSchema(mediaAttribute);\n * ```\n *\n * @throws {Error} Throws an error if an unsupported attribute type is provided\n *\n */\nexport const mapAttributeToInputSchema = (\n attribute: Schema.Attribute.AnyAttribute\n): z.ZodTypeAny => {\n switch (attribute.type) {\n case 'biginteger':\n return attributes.bigIntegerToInputSchema(attribute);\n case 'blocks':\n return attributes.blocksToInputSchema();\n case 'boolean':\n return attributes.booleanToInputSchema(attribute);\n case 'component':\n return attributes.componentToInputSchema(attribute);\n case 'date':\n return attributes.dateToInputSchema(attribute);\n case 'datetime':\n return attributes.datetimeToInputSchema(attribute);\n case 'decimal':\n return attributes.decimalToInputSchema(attribute);\n case 'dynamiczone':\n return attributes.dynamicZoneToInputSchema(attribute);\n case 'email':\n return attributes.emailToInputSchema(attribute);\n case 'enumeration':\n return attributes.enumerationToInputSchema(attribute);\n case 'float':\n return attributes.floatToInputSchema(attribute);\n case 'integer':\n return attributes.integerToInputSchema(attribute);\n case 'json':\n return attributes.jsonToInputSchema(attribute);\n case 'media':\n return attributes.mediaToInputSchema(attribute);\n case 'relation':\n return attributes.relationToInputSchema(attribute);\n case 'password':\n case 'text':\n case 'richtext':\n case 'string':\n return attributes.textToInputSchema(attribute);\n case 'time':\n return attributes.timeToInputSchema(attribute);\n case 'timestamp':\n return attributes.timestampToInputSchema(attribute);\n case 'uid':\n return attributes.uidToInputSchema(attribute);\n default: {\n if (isCustomFieldAttribute(attribute)) {\n const attrCF = attribute as { type: 'customField'; customField: string };\n const strapiInstance = global.strapi;\n if (!strapiInstance) {\n throw new Error('Strapi instance not available for custom field conversion');\n }\n\n const customField = strapiInstance.get('custom-fields').get(attrCF.customField);\n if (!customField) {\n throw new Error(`Custom field '${attrCF.customField}' not found`);\n }\n\n // Re-dispatch with the resolved underlying Strapi kind\n return mapAttributeToInputSchema({ ...attrCF, type: customField.type });\n }\n\n const { type } = attribute as Schema.Attribute.AnyAttribute;\n\n throw new Error(`Unsupported attribute type: ${type}`);\n }\n }\n};\n"],"names":["isCustomFieldAttribute","attribute","type","customField","createAttributesSchema","attributes","reduce","acc","name","extend","mapAttributeToSchema","z","object","createAttributesInputSchema","mapAttributeToInputSchema","attrCF","strapiInstance","global","strapi","Error","get"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAWA,MAAMA,yBAAyB,CAC7BC,SAAAA,GAAAA;AAEA,IAAA,OACE,CAAC,CAACA,SAAAA,IACF,OAAOA,cAAc,QAAA,IACpBA,SAAAA,CAAkBC,IAAI,KAAK,aAAA,IAC5B,OAAO,SAACD,CAAkBE,WAAW,KAAK,QAAA;AAE9C,CAAA;AAEA;;;;;;;;;;;;;;;;IAiBO,MAAM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F;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"mappers.js","sources":["../../../../src/core-api/routes/validation/mappers.ts"],"sourcesContent":["/**\n * @fileoverview\n * This file contains functions responsible for mapping Strapi attribute definitions to Zod schemas.\n */\n\nimport type { Core, Schema } from '@strapi/types';\nimport * as z from 'zod/v4';\n\n// eslint-disable-next-line import/no-cycle\nimport * as attributes from './attributes';\n\nconst isCustomFieldAttribute = (\n attribute: unknown\n): attribute is { type: 'customField'; customField: string } => {\n return (\n !!attribute &&\n typeof attribute === 'object' &&\n (attribute as any).type === 'customField' &&\n typeof (attribute as any).customField === 'string'\n );\n};\n\n/**\n * Creates a Zod schema for a collection of Strapi attributes.\n *\n * @param attributes - An array of tuples, where each tuple contains the attribute name and its schema definition.\n * @returns A Zod object schema representing the combined attributes.\n *\n * @example\n * ```typescript\n * const myAttributes = [\n * ['title', { type: 'string', required: true }],\n * ['description', { type: 'text' }],\n * ];\n * const schema = createAttributesSchema(myAttributes);\n * // schema will be a Zod object with 'title' and 'description' fields,\n * // each mapped to their respective Zod schemas based on their Strapi attribute types.\n * ```\n */\nexport const createAttributesSchema = (\n strapi: Core.Strapi,\n attributes: [name: string, attribute: Schema.Attribute.AnyAttribute][]\n) => {\n return attributes.reduce((acc, [name, attribute]) => {\n return acc.extend({\n get [name]() {\n return mapAttributeToSchema(strapi, attribute);\n },\n });\n }, z.object({}));\n};\n\n/**\n * Creates a Zod input schema for a collection of Strapi attributes.\n * This is typically used for validating incoming data (e.g., from API requests).\n *\n * @param attributes - An array of tuples, where each tuple contains the attribute name and its schema definition.\n * @returns A Zod object schema representing the combined input attributes.\n *\n * @example\n * ```typescript\n * const myInputAttributes = [\n * ['email', { type: 'email', required: true }],\n * ['description', { type: 'text', minLength: 8 }],\n * ];\n * const inputSchema = createAttributesInputSchema(myInputAttributes);\n * // inputSchema will be a Zod object with 'email' and 'description' fields,\n * // mapped to Zod schemas suitable for input validation.\n * ```\n */\nexport const createAttributesInputSchema = (\n strapi: Core.Strapi,\n attributes: [name: string, attribute: Schema.Attribute.AnyAttribute][]\n) => {\n return attributes.reduce((acc, [name, attribute]) => {\n return acc.extend({\n get [name]() {\n return mapAttributeToInputSchema(strapi, attribute);\n },\n });\n }, z.object({}));\n};\n\n/**\n * Maps a Strapi attribute definition to a corresponding Zod validation schema.\n *\n * This function handles every Strapi attribute types and converts them into\n * appropriate Zod validation schemas.\n *\n * @param attribute - The Strapi attribute configuration object.\n * @returns A Zod schema that corresponds to the input attribute's type.\n * @throws {Error} Throws an error if an unsupported attribute type is provided.\n *\n * @example\n * ```typescript\n * const stringAttribute = { type: 'string', minLength: 3 };\n * const stringSchema = mapAttributeToSchema(stringAttribute); // Returns a Zod string schema with minLength.\n *\n * const booleanAttribute = { type: 'boolean', default: false };\n * const booleanSchema = mapAttributeToSchema(booleanAttribute); // Returns a Zod boolean schema with a default.\n * ```\n */\nexport const mapAttributeToSchema = (\n strapi: Core.Strapi,\n attribute: Schema.Attribute.AnyAttribute\n): z.ZodTypeAny => {\n switch (attribute.type) {\n case 'biginteger':\n return attributes.bigIntegerToSchema(attribute);\n case 'blocks':\n return attributes.blocksToSchema();\n case 'boolean':\n return attributes.booleanToSchema(attribute);\n case 'component':\n return attributes.componentToSchema(strapi, attribute);\n case 'date':\n return attributes.dateToSchema(attribute);\n case 'datetime':\n return attributes.datetimeToSchema(attribute);\n case 'decimal':\n return attributes.decimalToSchema(attribute);\n case 'dynamiczone':\n return attributes.dynamicZoneToSchema(attribute);\n case 'email':\n return attributes.emailToSchema(attribute);\n case 'enumeration':\n return attributes.enumToSchema(attribute);\n case 'float':\n return attributes.floatToSchema(attribute);\n case 'integer':\n return attributes.integerToSchema(attribute);\n case 'json':\n return attributes.jsonToSchema(attribute);\n case 'media':\n return attributes.mediaToSchema(strapi, attribute);\n case 'relation':\n return attributes.relationToSchema(strapi, attribute);\n case 'password':\n case 'text':\n case 'richtext':\n case 'string':\n return attributes.stringToSchema(attribute);\n case 'time':\n return attributes.timeToSchema(attribute);\n case 'timestamp':\n return attributes.timestampToSchema(attribute);\n case 'uid':\n return attributes.uidToSchema(attribute);\n default: {\n if (isCustomFieldAttribute(attribute)) {\n const attrCF = attribute as { type: 'customField'; customField: string };\n const customField = strapi.get('custom-fields').get(attrCF.customField);\n if (!customField) {\n throw new Error(`Custom field '${attrCF.customField}' not found`);\n }\n\n // Re-dispatch with the resolved underlying Strapi kind\n return mapAttributeToSchema(strapi, { ...attrCF, type: customField.type });\n }\n\n const { type } = attribute as Schema.Attribute.AnyAttribute;\n\n throw new Error(`Unsupported attribute type: ${type}`);\n }\n }\n};\n\n/**\n * Maps a Strapi attribute definition to a corresponding Zod input validation schema.\n *\n * This function handles every Strapi attribute types and converts them into\n * appropriate Zod validation schemas with their respective constraints.\n *\n * @param attribute - The Strapi attribute configuration object. Contains type information\n * and validation rules for the attribute.\n *\n * @returns A Zod schema that corresponds to the input attribute's type and validation rules\n *\n * @example\n * ```typescript\n * // String attribute with constraints\n * const stringAttribute = {\n * type: 'string',\n * minLength: 3,\n * maxLength: 50,\n * required: true\n * };\n * const stringSchema = mapAttributeToInputSchema(stringAttribute);\n *\n * // Enumeration attribute\n * const enumAttribute = {\n * type: 'enumeration',\n * enum: ['draft', 'published', 'archived']\n * };\n * const enumSchema = mapAttributeToInputSchema(enumAttribute);\n *\n * // Media attribute with multiple files\n * const mediaAttribute = {\n * type: 'media',\n * multiple: true\n * };\n * const mediaSchema = mapAttributeToInputSchema(mediaAttribute);\n * ```\n *\n * @throws {Error} Throws an error if an unsupported attribute type is provided\n *\n */\nexport const mapAttributeToInputSchema = (\n strapi: Core.Strapi,\n attribute: Schema.Attribute.AnyAttribute\n): z.ZodTypeAny => {\n switch (attribute.type) {\n case 'biginteger':\n return attributes.bigIntegerToInputSchema(attribute);\n case 'blocks':\n return attributes.blocksToInputSchema();\n case 'boolean':\n return attributes.booleanToInputSchema(attribute);\n case 'component':\n return attributes.componentToInputSchema(attribute);\n case 'date':\n return attributes.dateToInputSchema(attribute);\n case 'datetime':\n return attributes.datetimeToInputSchema(attribute);\n case 'decimal':\n return attributes.decimalToInputSchema(attribute);\n case 'dynamiczone':\n return attributes.dynamicZoneToInputSchema(attribute);\n case 'email':\n return attributes.emailToInputSchema(attribute);\n case 'enumeration':\n return attributes.enumerationToInputSchema(attribute);\n case 'float':\n return attributes.floatToInputSchema(attribute);\n case 'integer':\n return attributes.integerToInputSchema(attribute);\n case 'json':\n return attributes.jsonToInputSchema(attribute);\n case 'media':\n return attributes.mediaToInputSchema(attribute);\n case 'relation':\n return attributes.relationToInputSchema(attribute);\n case 'password':\n case 'text':\n case 'richtext':\n case 'string':\n return attributes.textToInputSchema(attribute);\n case 'time':\n return attributes.timeToInputSchema(attribute);\n case 'timestamp':\n return attributes.timestampToInputSchema(attribute);\n case 'uid':\n return attributes.uidToInputSchema(attribute);\n default: {\n if (isCustomFieldAttribute(attribute)) {\n const attrCF = attribute as { type: 'customField'; customField: string };\n const customField = strapi.get('custom-fields').get(attrCF.customField);\n if (!customField) {\n throw new Error(`Custom field '${attrCF.customField}' not found`);\n }\n\n // Re-dispatch with the resolved underlying Strapi kind\n return mapAttributeToInputSchema(strapi, { ...attrCF, type: customField.type });\n }\n\n const { type } = attribute as Schema.Attribute.AnyAttribute;\n\n throw new Error(`Unsupported attribute type: ${type}`);\n }\n }\n};\n"],"names":["isCustomFieldAttribute","attribute","type","customField","createAttributesSchema","strapi","attributes","reduce","acc","name","extend","mapAttributeToSchema","z","object","createAttributesInputSchema","mapAttributeToInputSchema","attrCF","get","Error"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAWA,MAAMA,yBAAyB,CAC7BC,SAAAA,GAAAA;AAEA,IAAA,OACE,CAAC,CAACA,SAAAA,IACF,OAAOA,cAAc,QAAA,IACpBA,SAAAA,CAAkBC,IAAI,KAAK,aAAA,IAC5B,OAAO,SAACD,CAAkBE,WAAW,KAAK,QAAA;AAE9C,CAAA;AAEA;;;;;;;;;;;;;;;;AAgBC,IACM,MAAMC,sBAAA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AAOK,6BAA6B,CAACL,SAAAA,CAAAA;QACvC,KAAK,UAAA;YACH,OAAOK,gCAAgC,CAACL,SAAAA,CAAAA;QAC1C,KAAK,UAAA;QACL,KAAK,MAAA;QACL,KAAK,UAAA;QACL,KAAK,QAAA;YACH,OAAOK,4BAA4B,CAACL,SAAAA,CAAAA;QACtC,KAAK,MAAA;YACH,OAAOK,4BAA4B,CAACL,SAAAA,CAAAA;QACtC,KAAK,WAAA;YACH,OAAOK,iCAAiC,CAACL,SAAAA,CAAAA;QAC3C,KAAK,KAAA;YACH,OAAOK,2BAA2B,CAACL,SAAAA,CAAAA;AACrC,QAAA;AAAS,YAAA;AACP,gBAAA,IAAID,uBAAuBC,SAAAA,CAAAA,EAAY;AACrC,oBAAA,MAAMe,MAAAA,GAASf,SAAAA;oBACf,MAAME,WAAAA,GAAcE,OAAOY,GAAG,CAAC,iBAAiBA,GAAG,CAACD,OAAOb,WAAW,CAAA;AACtE,oBAAA,IAAI,CAACA,WAAAA,EAAa;wBAChB,MAAM,IAAIe,MAAM,CAAC,cAAc,EAAEF,MAAAA,CAAOb,WAAW,CAAC,WAAW,CAAC,CAAA;AAClE,oBAAA;;AAGA,oBAAA,OAAOY,0BAA0BV,MAAAA,EAAQ;AAAE,wBAAA,GAAGW,MAAM;AAAEd,wBAAAA,IAAAA,EAAMC,YAAYD;AAAK,qBAAA,CAAA;AAC/E,gBAAA;gBAEA,MAAM,EAAEA,IAAI,EAAE,GAAGD,SAAAA;AAEjB,gBAAA,MAAM,IAAIiB,KAAAA,CAAM,CAAC,4BAA4B,EAAEhB,IAAAA,CAAAA,CAAM,CAAA;AACvD,YAAA;AACF;AACF;;;;;;;"}
|
|
@@ -20,11 +20,11 @@ const isCustomFieldAttribute = (attribute)=>{
|
|
|
20
20
|
* // schema will be a Zod object with 'title' and 'description' fields,
|
|
21
21
|
* // each mapped to their respective Zod schemas based on their Strapi attribute types.
|
|
22
22
|
* ```
|
|
23
|
-
*/ const createAttributesSchema = (attributes)=>{
|
|
23
|
+
*/ const createAttributesSchema = (strapi, attributes)=>{
|
|
24
24
|
return attributes.reduce((acc, [name, attribute])=>{
|
|
25
25
|
return acc.extend({
|
|
26
26
|
get [name] () {
|
|
27
|
-
return mapAttributeToSchema(attribute);
|
|
27
|
+
return mapAttributeToSchema(strapi, attribute);
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
30
|
}, z.object({}));
|
|
@@ -46,11 +46,11 @@ const isCustomFieldAttribute = (attribute)=>{
|
|
|
46
46
|
* // inputSchema will be a Zod object with 'email' and 'description' fields,
|
|
47
47
|
* // mapped to Zod schemas suitable for input validation.
|
|
48
48
|
* ```
|
|
49
|
-
*/ const createAttributesInputSchema = (attributes)=>{
|
|
49
|
+
*/ const createAttributesInputSchema = (strapi, attributes)=>{
|
|
50
50
|
return attributes.reduce((acc, [name, attribute])=>{
|
|
51
51
|
return acc.extend({
|
|
52
52
|
get [name] () {
|
|
53
|
-
return mapAttributeToInputSchema(attribute);
|
|
53
|
+
return mapAttributeToInputSchema(strapi, attribute);
|
|
54
54
|
}
|
|
55
55
|
});
|
|
56
56
|
}, z.object({}));
|
|
@@ -73,7 +73,7 @@ const isCustomFieldAttribute = (attribute)=>{
|
|
|
73
73
|
* const booleanAttribute = { type: 'boolean', default: false };
|
|
74
74
|
* const booleanSchema = mapAttributeToSchema(booleanAttribute); // Returns a Zod boolean schema with a default.
|
|
75
75
|
* ```
|
|
76
|
-
*/ const mapAttributeToSchema = (attribute)=>{
|
|
76
|
+
*/ const mapAttributeToSchema = (strapi, attribute)=>{
|
|
77
77
|
switch(attribute.type){
|
|
78
78
|
case 'biginteger':
|
|
79
79
|
return bigIntegerToSchema(attribute);
|
|
@@ -82,7 +82,7 @@ const isCustomFieldAttribute = (attribute)=>{
|
|
|
82
82
|
case 'boolean':
|
|
83
83
|
return booleanToSchema(attribute);
|
|
84
84
|
case 'component':
|
|
85
|
-
return componentToSchema(attribute);
|
|
85
|
+
return componentToSchema(strapi, attribute);
|
|
86
86
|
case 'date':
|
|
87
87
|
return dateToSchema(attribute);
|
|
88
88
|
case 'datetime':
|
|
@@ -102,9 +102,9 @@ const isCustomFieldAttribute = (attribute)=>{
|
|
|
102
102
|
case 'json':
|
|
103
103
|
return jsonToSchema(attribute);
|
|
104
104
|
case 'media':
|
|
105
|
-
return mediaToSchema(attribute);
|
|
105
|
+
return mediaToSchema(strapi, attribute);
|
|
106
106
|
case 'relation':
|
|
107
|
-
return relationToSchema(attribute);
|
|
107
|
+
return relationToSchema(strapi, attribute);
|
|
108
108
|
case 'password':
|
|
109
109
|
case 'text':
|
|
110
110
|
case 'richtext':
|
|
@@ -120,16 +120,12 @@ const isCustomFieldAttribute = (attribute)=>{
|
|
|
120
120
|
{
|
|
121
121
|
if (isCustomFieldAttribute(attribute)) {
|
|
122
122
|
const attrCF = attribute;
|
|
123
|
-
const
|
|
124
|
-
if (!strapiInstance) {
|
|
125
|
-
throw new Error('Strapi instance not available for custom field conversion');
|
|
126
|
-
}
|
|
127
|
-
const customField = strapiInstance.get('custom-fields').get(attrCF.customField);
|
|
123
|
+
const customField = strapi.get('custom-fields').get(attrCF.customField);
|
|
128
124
|
if (!customField) {
|
|
129
125
|
throw new Error(`Custom field '${attrCF.customField}' not found`);
|
|
130
126
|
}
|
|
131
127
|
// Re-dispatch with the resolved underlying Strapi kind
|
|
132
|
-
return mapAttributeToSchema({
|
|
128
|
+
return mapAttributeToSchema(strapi, {
|
|
133
129
|
...attrCF,
|
|
134
130
|
type: customField.type
|
|
135
131
|
});
|
|
@@ -178,7 +174,7 @@ const isCustomFieldAttribute = (attribute)=>{
|
|
|
178
174
|
*
|
|
179
175
|
* @throws {Error} Throws an error if an unsupported attribute type is provided
|
|
180
176
|
*
|
|
181
|
-
*/ const mapAttributeToInputSchema = (attribute)=>{
|
|
177
|
+
*/ const mapAttributeToInputSchema = (strapi, attribute)=>{
|
|
182
178
|
switch(attribute.type){
|
|
183
179
|
case 'biginteger':
|
|
184
180
|
return bigIntegerToInputSchema(attribute);
|
|
@@ -225,16 +221,12 @@ const isCustomFieldAttribute = (attribute)=>{
|
|
|
225
221
|
{
|
|
226
222
|
if (isCustomFieldAttribute(attribute)) {
|
|
227
223
|
const attrCF = attribute;
|
|
228
|
-
const
|
|
229
|
-
if (!strapiInstance) {
|
|
230
|
-
throw new Error('Strapi instance not available for custom field conversion');
|
|
231
|
-
}
|
|
232
|
-
const customField = strapiInstance.get('custom-fields').get(attrCF.customField);
|
|
224
|
+
const customField = strapi.get('custom-fields').get(attrCF.customField);
|
|
233
225
|
if (!customField) {
|
|
234
226
|
throw new Error(`Custom field '${attrCF.customField}' not found`);
|
|
235
227
|
}
|
|
236
228
|
// Re-dispatch with the resolved underlying Strapi kind
|
|
237
|
-
return mapAttributeToInputSchema({
|
|
229
|
+
return mapAttributeToInputSchema(strapi, {
|
|
238
230
|
...attrCF,
|
|
239
231
|
type: customField.type
|
|
240
232
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mappers.mjs","sources":["../../../../src/core-api/routes/validation/mappers.ts"],"sourcesContent":["/**\n * @fileoverview\n * This file contains functions responsible for mapping Strapi attribute definitions to Zod schemas.\n */\n\nimport type { Schema } from '@strapi/types';\nimport * as z from 'zod/v4';\n\n// eslint-disable-next-line import/no-cycle\nimport * as attributes from './attributes';\n\nconst isCustomFieldAttribute = (\n attribute: unknown\n): attribute is { type: 'customField'; customField: string } => {\n return (\n !!attribute &&\n typeof attribute === 'object' &&\n (attribute as any).type === 'customField' &&\n typeof (attribute as any).customField === 'string'\n );\n};\n\n/**\n * Creates a Zod schema for a collection of Strapi attributes.\n *\n * @param attributes - An array of tuples, where each tuple contains the attribute name and its schema definition.\n * @returns A Zod object schema representing the combined attributes.\n *\n * @example\n * ```typescript\n * const myAttributes = [\n * ['title', { type: 'string', required: true }],\n * ['description', { type: 'text' }],\n * ];\n * const schema = createAttributesSchema(myAttributes);\n * // schema will be a Zod object with 'title' and 'description' fields,\n * // each mapped to their respective Zod schemas based on their Strapi attribute types.\n * ```\n */\nexport const createAttributesSchema = (\n attributes: [name: string, attribute: Schema.Attribute.AnyAttribute][]\n) => {\n return attributes.reduce((acc, [name, attribute]) => {\n return acc.extend({\n get [name]() {\n return mapAttributeToSchema(attribute);\n },\n });\n }, z.object({}));\n};\n\n/**\n * Creates a Zod input schema for a collection of Strapi attributes.\n * This is typically used for validating incoming data (e.g., from API requests).\n *\n * @param attributes - An array of tuples, where each tuple contains the attribute name and its schema definition.\n * @returns A Zod object schema representing the combined input attributes.\n *\n * @example\n * ```typescript\n * const myInputAttributes = [\n * ['email', { type: 'email', required: true }],\n * ['description', { type: 'text', minLength: 8 }],\n * ];\n * const inputSchema = createAttributesInputSchema(myInputAttributes);\n * // inputSchema will be a Zod object with 'email' and 'description' fields,\n * // mapped to Zod schemas suitable for input validation.\n * ```\n */\nexport const createAttributesInputSchema = (\n attributes: [name: string, attribute: Schema.Attribute.AnyAttribute][]\n) => {\n return attributes.reduce((acc, [name, attribute]) => {\n return acc.extend({\n get [name]() {\n return mapAttributeToInputSchema(attribute);\n },\n });\n }, z.object({}));\n};\n\n/**\n * Maps a Strapi attribute definition to a corresponding Zod validation schema.\n *\n * This function handles every Strapi attribute types and converts them into\n * appropriate Zod validation schemas.\n *\n * @param attribute - The Strapi attribute configuration object.\n * @returns A Zod schema that corresponds to the input attribute's type.\n * @throws {Error} Throws an error if an unsupported attribute type is provided.\n *\n * @example\n * ```typescript\n * const stringAttribute = { type: 'string', minLength: 3 };\n * const stringSchema = mapAttributeToSchema(stringAttribute); // Returns a Zod string schema with minLength.\n *\n * const booleanAttribute = { type: 'boolean', default: false };\n * const booleanSchema = mapAttributeToSchema(booleanAttribute); // Returns a Zod boolean schema with a default.\n * ```\n */\nexport const mapAttributeToSchema = (attribute: Schema.Attribute.AnyAttribute): z.ZodTypeAny => {\n switch (attribute.type) {\n case 'biginteger':\n return attributes.bigIntegerToSchema(attribute);\n case 'blocks':\n return attributes.blocksToSchema();\n case 'boolean':\n return attributes.booleanToSchema(attribute);\n case 'component':\n return attributes.componentToSchema(attribute);\n case 'date':\n return attributes.dateToSchema(attribute);\n case 'datetime':\n return attributes.datetimeToSchema(attribute);\n case 'decimal':\n return attributes.decimalToSchema(attribute);\n case 'dynamiczone':\n return attributes.dynamicZoneToSchema(attribute);\n case 'email':\n return attributes.emailToSchema(attribute);\n case 'enumeration':\n return attributes.enumToSchema(attribute);\n case 'float':\n return attributes.floatToSchema(attribute);\n case 'integer':\n return attributes.integerToSchema(attribute);\n case 'json':\n return attributes.jsonToSchema(attribute);\n case 'media':\n return attributes.mediaToSchema(attribute);\n case 'relation':\n return attributes.relationToSchema(attribute);\n case 'password':\n case 'text':\n case 'richtext':\n case 'string':\n return attributes.stringToSchema(attribute);\n case 'time':\n return attributes.timeToSchema(attribute);\n case 'timestamp':\n return attributes.timestampToSchema(attribute);\n case 'uid':\n return attributes.uidToSchema(attribute);\n default: {\n if (isCustomFieldAttribute(attribute)) {\n const attrCF = attribute as { type: 'customField'; customField: string };\n const strapiInstance = global.strapi;\n if (!strapiInstance) {\n throw new Error('Strapi instance not available for custom field conversion');\n }\n\n const customField = strapiInstance.get('custom-fields').get(attrCF.customField);\n if (!customField) {\n throw new Error(`Custom field '${attrCF.customField}' not found`);\n }\n\n // Re-dispatch with the resolved underlying Strapi kind\n return mapAttributeToSchema({ ...attrCF, type: customField.type });\n }\n\n const { type } = attribute as Schema.Attribute.AnyAttribute;\n\n throw new Error(`Unsupported attribute type: ${type}`);\n }\n }\n};\n\n/**\n * Maps a Strapi attribute definition to a corresponding Zod input validation schema.\n *\n * This function handles every Strapi attribute types and converts them into\n * appropriate Zod validation schemas with their respective constraints.\n *\n * @param attribute - The Strapi attribute configuration object. Contains type information\n * and validation rules for the attribute.\n *\n * @returns A Zod schema that corresponds to the input attribute's type and validation rules\n *\n * @example\n * ```typescript\n * // String attribute with constraints\n * const stringAttribute = {\n * type: 'string',\n * minLength: 3,\n * maxLength: 50,\n * required: true\n * };\n * const stringSchema = mapAttributeToInputSchema(stringAttribute);\n *\n * // Enumeration attribute\n * const enumAttribute = {\n * type: 'enumeration',\n * enum: ['draft', 'published', 'archived']\n * };\n * const enumSchema = mapAttributeToInputSchema(enumAttribute);\n *\n * // Media attribute with multiple files\n * const mediaAttribute = {\n * type: 'media',\n * multiple: true\n * };\n * const mediaSchema = mapAttributeToInputSchema(mediaAttribute);\n * ```\n *\n * @throws {Error} Throws an error if an unsupported attribute type is provided\n *\n */\nexport const mapAttributeToInputSchema = (\n attribute: Schema.Attribute.AnyAttribute\n): z.ZodTypeAny => {\n switch (attribute.type) {\n case 'biginteger':\n return attributes.bigIntegerToInputSchema(attribute);\n case 'blocks':\n return attributes.blocksToInputSchema();\n case 'boolean':\n return attributes.booleanToInputSchema(attribute);\n case 'component':\n return attributes.componentToInputSchema(attribute);\n case 'date':\n return attributes.dateToInputSchema(attribute);\n case 'datetime':\n return attributes.datetimeToInputSchema(attribute);\n case 'decimal':\n return attributes.decimalToInputSchema(attribute);\n case 'dynamiczone':\n return attributes.dynamicZoneToInputSchema(attribute);\n case 'email':\n return attributes.emailToInputSchema(attribute);\n case 'enumeration':\n return attributes.enumerationToInputSchema(attribute);\n case 'float':\n return attributes.floatToInputSchema(attribute);\n case 'integer':\n return attributes.integerToInputSchema(attribute);\n case 'json':\n return attributes.jsonToInputSchema(attribute);\n case 'media':\n return attributes.mediaToInputSchema(attribute);\n case 'relation':\n return attributes.relationToInputSchema(attribute);\n case 'password':\n case 'text':\n case 'richtext':\n case 'string':\n return attributes.textToInputSchema(attribute);\n case 'time':\n return attributes.timeToInputSchema(attribute);\n case 'timestamp':\n return attributes.timestampToInputSchema(attribute);\n case 'uid':\n return attributes.uidToInputSchema(attribute);\n default: {\n if (isCustomFieldAttribute(attribute)) {\n const attrCF = attribute as { type: 'customField'; customField: string };\n const strapiInstance = global.strapi;\n if (!strapiInstance) {\n throw new Error('Strapi instance not available for custom field conversion');\n }\n\n const customField = strapiInstance.get('custom-fields').get(attrCF.customField);\n if (!customField) {\n throw new Error(`Custom field '${attrCF.customField}' not found`);\n }\n\n // Re-dispatch with the resolved underlying Strapi kind\n return mapAttributeToInputSchema({ ...attrCF, type: customField.type });\n }\n\n const { type } = attribute as Schema.Attribute.AnyAttribute;\n\n throw new Error(`Unsupported attribute type: ${type}`);\n }\n }\n};\n"],"names":["isCustomFieldAttribute","attribute","type","customField","createAttributesSchema","attributes","reduce","acc","name","extend","mapAttributeToSchema","z","object","createAttributesInputSchema","mapAttributeToInputSchema","attrCF","strapiInstance","global","strapi","Error","get"],"mappings":";;;AAWA,MAAMA,yBAAyB,CAC7BC,SAAAA,GAAAA;AAEA,IAAA,OACE,CAAC,CAACA,SAAAA,IACF,OAAOA,cAAc,QAAA,IACpBA,SAAAA,CAAkBC,IAAI,KAAK,aAAA,IAC5B,OAAO,SAACD,CAAkBE,WAAW,KAAK,QAAA;AAE9C,CAAA;AAEA;;;;;;;;;;;;;;;;IAiBO,MAAMC,sBAAAA,GAAyB,CACpCC,UAAAA,GAAAA;AAEA,IAAA,OAAOA,WAAWC,MAAM,CAAC,CAACC,GAAAA,EAAK,CAACC,MAAMP,SAAAA,CAAU,GAAA;QAC9C,OAAOM,GAAAA,CAAIE,MAAM,CAAC;YAChB,KAAKD,MAAK,GAAG;AACX,gBAAA,OAAOE,oBAAAA,CAAqBT,SAAAA,CAAAA;AAC9B,YAAA;AACF,SAAA,CAAA;IACF,CAAA,EAAGU,CAAAA,CAAEC,MAAM,CAAC,EAAC,CAAA,CAAA;AACf;AAEA;;;;;;;;;;;;;;;;;IAkBO,MAAMC,2BAAAA,GAA8B,CACzCR,UAAAA,GAAAA;AAEA,IAAA,OAAOA,WAAWC,MAAM,CAAC,CAACC,GAAAA,EAAK,CAACC,MAAMP,SAAAA,CAAU,GAAA;QAC9C,OAAOM,GAAAA,CAAIE,MAAM,CAAC;YAChB,KAAKD,MAAK,GAAG;AACX,gBAAA,OAAOM,yBAAAA,CAA0Bb,SAAAA,CAAAA;AACnC,YAAA;AACF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IG,KAAAA,CAAM,2DAAA,CAAA;AAClB,oBAAA;oBAEA,MAAMhB,WAAAA,GAAca,eAAeI,GAAG,CAAC,iBAAiBA,GAAG,CAACL,OAAOZ,WAAW,CAAA;AAC9E,oBAAA,IAAI,CAACA,WAAAA,EAAa;wBAChB,MAAM,IAAIgB,MAAM,CAAC,cAAc,EAAEJ,MAAAA,CAAOZ,WAAW,CAAC,WAAW,CAAC,CAAA;AAClE,oBAAA;;AAGA,oBAAA,OAAOW,yBAAAA,CAA0B;AAAE,wBAAA,GAAGC,MAAM;AAAEb,wBAAAA,IAAAA,EAAMC,YAAYD;AAAK,qBAAA,CAAA;AACvE,gBAAA;gBAEA,MAAM,EAAEA,IAAI,EAAE,GAAGD,SAAAA;AAEjB,gBAAA,MAAM,IAAIkB,KAAAA,CAAM,CAAC,4BAA4B,EAAEjB,IAAAA,CAAAA,CAAM,CAAA;AACvD,YAAA;AACF;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"mappers.mjs","sources":["../../../../src/core-api/routes/validation/mappers.ts"],"sourcesContent":["/**\n * @fileoverview\n * This file contains functions responsible for mapping Strapi attribute definitions to Zod schemas.\n */\n\nimport type { Core, Schema } from '@strapi/types';\nimport * as z from 'zod/v4';\n\n// eslint-disable-next-line import/no-cycle\nimport * as attributes from './attributes';\n\nconst isCustomFieldAttribute = (\n attribute: unknown\n): attribute is { type: 'customField'; customField: string } => {\n return (\n !!attribute &&\n typeof attribute === 'object' &&\n (attribute as any).type === 'customField' &&\n typeof (attribute as any).customField === 'string'\n );\n};\n\n/**\n * Creates a Zod schema for a collection of Strapi attributes.\n *\n * @param attributes - An array of tuples, where each tuple contains the attribute name and its schema definition.\n * @returns A Zod object schema representing the combined attributes.\n *\n * @example\n * ```typescript\n * const myAttributes = [\n * ['title', { type: 'string', required: true }],\n * ['description', { type: 'text' }],\n * ];\n * const schema = createAttributesSchema(myAttributes);\n * // schema will be a Zod object with 'title' and 'description' fields,\n * // each mapped to their respective Zod schemas based on their Strapi attribute types.\n * ```\n */\nexport const createAttributesSchema = (\n strapi: Core.Strapi,\n attributes: [name: string, attribute: Schema.Attribute.AnyAttribute][]\n) => {\n return attributes.reduce((acc, [name, attribute]) => {\n return acc.extend({\n get [name]() {\n return mapAttributeToSchema(strapi, attribute);\n },\n });\n }, z.object({}));\n};\n\n/**\n * Creates a Zod input schema for a collection of Strapi attributes.\n * This is typically used for validating incoming data (e.g., from API requests).\n *\n * @param attributes - An array of tuples, where each tuple contains the attribute name and its schema definition.\n * @returns A Zod object schema representing the combined input attributes.\n *\n * @example\n * ```typescript\n * const myInputAttributes = [\n * ['email', { type: 'email', required: true }],\n * ['description', { type: 'text', minLength: 8 }],\n * ];\n * const inputSchema = createAttributesInputSchema(myInputAttributes);\n * // inputSchema will be a Zod object with 'email' and 'description' fields,\n * // mapped to Zod schemas suitable for input validation.\n * ```\n */\nexport const createAttributesInputSchema = (\n strapi: Core.Strapi,\n attributes: [name: string, attribute: Schema.Attribute.AnyAttribute][]\n) => {\n return attributes.reduce((acc, [name, attribute]) => {\n return acc.extend({\n get [name]() {\n return mapAttributeToInputSchema(strapi, attribute);\n },\n });\n }, z.object({}));\n};\n\n/**\n * Maps a Strapi attribute definition to a corresponding Zod validation schema.\n *\n * This function handles every Strapi attribute types and converts them into\n * appropriate Zod validation schemas.\n *\n * @param attribute - The Strapi attribute configuration object.\n * @returns A Zod schema that corresponds to the input attribute's type.\n * @throws {Error} Throws an error if an unsupported attribute type is provided.\n *\n * @example\n * ```typescript\n * const stringAttribute = { type: 'string', minLength: 3 };\n * const stringSchema = mapAttributeToSchema(stringAttribute); // Returns a Zod string schema with minLength.\n *\n * const booleanAttribute = { type: 'boolean', default: false };\n * const booleanSchema = mapAttributeToSchema(booleanAttribute); // Returns a Zod boolean schema with a default.\n * ```\n */\nexport const mapAttributeToSchema = (\n strapi: Core.Strapi,\n attribute: Schema.Attribute.AnyAttribute\n): z.ZodTypeAny => {\n switch (attribute.type) {\n case 'biginteger':\n return attributes.bigIntegerToSchema(attribute);\n case 'blocks':\n return attributes.blocksToSchema();\n case 'boolean':\n return attributes.booleanToSchema(attribute);\n case 'component':\n return attributes.componentToSchema(strapi, attribute);\n case 'date':\n return attributes.dateToSchema(attribute);\n case 'datetime':\n return attributes.datetimeToSchema(attribute);\n case 'decimal':\n return attributes.decimalToSchema(attribute);\n case 'dynamiczone':\n return attributes.dynamicZoneToSchema(attribute);\n case 'email':\n return attributes.emailToSchema(attribute);\n case 'enumeration':\n return attributes.enumToSchema(attribute);\n case 'float':\n return attributes.floatToSchema(attribute);\n case 'integer':\n return attributes.integerToSchema(attribute);\n case 'json':\n return attributes.jsonToSchema(attribute);\n case 'media':\n return attributes.mediaToSchema(strapi, attribute);\n case 'relation':\n return attributes.relationToSchema(strapi, attribute);\n case 'password':\n case 'text':\n case 'richtext':\n case 'string':\n return attributes.stringToSchema(attribute);\n case 'time':\n return attributes.timeToSchema(attribute);\n case 'timestamp':\n return attributes.timestampToSchema(attribute);\n case 'uid':\n return attributes.uidToSchema(attribute);\n default: {\n if (isCustomFieldAttribute(attribute)) {\n const attrCF = attribute as { type: 'customField'; customField: string };\n const customField = strapi.get('custom-fields').get(attrCF.customField);\n if (!customField) {\n throw new Error(`Custom field '${attrCF.customField}' not found`);\n }\n\n // Re-dispatch with the resolved underlying Strapi kind\n return mapAttributeToSchema(strapi, { ...attrCF, type: customField.type });\n }\n\n const { type } = attribute as Schema.Attribute.AnyAttribute;\n\n throw new Error(`Unsupported attribute type: ${type}`);\n }\n }\n};\n\n/**\n * Maps a Strapi attribute definition to a corresponding Zod input validation schema.\n *\n * This function handles every Strapi attribute types and converts them into\n * appropriate Zod validation schemas with their respective constraints.\n *\n * @param attribute - The Strapi attribute configuration object. Contains type information\n * and validation rules for the attribute.\n *\n * @returns A Zod schema that corresponds to the input attribute's type and validation rules\n *\n * @example\n * ```typescript\n * // String attribute with constraints\n * const stringAttribute = {\n * type: 'string',\n * minLength: 3,\n * maxLength: 50,\n * required: true\n * };\n * const stringSchema = mapAttributeToInputSchema(stringAttribute);\n *\n * // Enumeration attribute\n * const enumAttribute = {\n * type: 'enumeration',\n * enum: ['draft', 'published', 'archived']\n * };\n * const enumSchema = mapAttributeToInputSchema(enumAttribute);\n *\n * // Media attribute with multiple files\n * const mediaAttribute = {\n * type: 'media',\n * multiple: true\n * };\n * const mediaSchema = mapAttributeToInputSchema(mediaAttribute);\n * ```\n *\n * @throws {Error} Throws an error if an unsupported attribute type is provided\n *\n */\nexport const mapAttributeToInputSchema = (\n strapi: Core.Strapi,\n attribute: Schema.Attribute.AnyAttribute\n): z.ZodTypeAny => {\n switch (attribute.type) {\n case 'biginteger':\n return attributes.bigIntegerToInputSchema(attribute);\n case 'blocks':\n return attributes.blocksToInputSchema();\n case 'boolean':\n return attributes.booleanToInputSchema(attribute);\n case 'component':\n return attributes.componentToInputSchema(attribute);\n case 'date':\n return attributes.dateToInputSchema(attribute);\n case 'datetime':\n return attributes.datetimeToInputSchema(attribute);\n case 'decimal':\n return attributes.decimalToInputSchema(attribute);\n case 'dynamiczone':\n return attributes.dynamicZoneToInputSchema(attribute);\n case 'email':\n return attributes.emailToInputSchema(attribute);\n case 'enumeration':\n return attributes.enumerationToInputSchema(attribute);\n case 'float':\n return attributes.floatToInputSchema(attribute);\n case 'integer':\n return attributes.integerToInputSchema(attribute);\n case 'json':\n return attributes.jsonToInputSchema(attribute);\n case 'media':\n return attributes.mediaToInputSchema(attribute);\n case 'relation':\n return attributes.relationToInputSchema(attribute);\n case 'password':\n case 'text':\n case 'richtext':\n case 'string':\n return attributes.textToInputSchema(attribute);\n case 'time':\n return attributes.timeToInputSchema(attribute);\n case 'timestamp':\n return attributes.timestampToInputSchema(attribute);\n case 'uid':\n return attributes.uidToInputSchema(attribute);\n default: {\n if (isCustomFieldAttribute(attribute)) {\n const attrCF = attribute as { type: 'customField'; customField: string };\n const customField = strapi.get('custom-fields').get(attrCF.customField);\n if (!customField) {\n throw new Error(`Custom field '${attrCF.customField}' not found`);\n }\n\n // Re-dispatch with the resolved underlying Strapi kind\n return mapAttributeToInputSchema(strapi, { ...attrCF, type: customField.type });\n }\n\n const { type } = attribute as Schema.Attribute.AnyAttribute;\n\n throw new Error(`Unsupported attribute type: ${type}`);\n }\n }\n};\n"],"names":["isCustomFieldAttribute","attribute","type","customField","createAttributesSchema","strapi","attributes","reduce","acc","name","extend","mapAttributeToSchema","z","object","createAttributesInputSchema","mapAttributeToInputSchema","attrCF","get","Error"],"mappings":";;;AAWA,MAAMA,yBAAyB,CAC7BC,SAAAA,GAAAA;AAEA,IAAA,OACE,CAAC,CAACA,SAAAA,IACF,OAAOA,cAAc,QAAA,IACpBA,SAAAA,CAAkBC,IAAI,KAAK,aAAA,IAC5B,OAAO,SAACD,CAAkBE,WAAW,KAAK,QAAA;AAE9C,CAAA;AAEA;;;;;;;;;;;;;;;;AAgBC,IACM,MAAMC,sBAAAA,GAAyB,CACpCC,MAAAA,EACAC,UAAAA,GAAAA;AAEA,IAAA,OAAOA,WAAWC,MAAM,CAAC,CAACC,GAAAA,EAAK,CAACC,MAAMR,SAAAA,CAAU,GAAA;QAC9C,OAAOO,GAAAA,CAAIE,MAAM,CAAC;YAChB,KAAKD,MAAK,GAAG;AACX,gBAAA,OAAOE,qBAAqBN,MAAAA,EAAQJ,SAAAA,CAAAA;AACtC,YAAA;AACF,SAAA,CAAA;IACF,CAAA,EAAGW,CAAAA,CAAEC,MAAM,CAAC,EAAC,CAAA,CAAA;AACf;AAEA;;;;;;;;;;;;;;;;;AAiBC,IACM,MAAMC,2BAAAA,GAA8B,CACzCT,MAAAA,EACAC,UAAAA,GAAAA;AAEA,IAAA,OAAOA,WAAWC,MAAM,CAAC,CAACC,GAAAA,EAAK,CAACC,MAAMR,SAAAA,CAAU,GAAA;QAC9C,OAAOO,GAAAA,CAAIE,MAAM,CAAC;YAChB,KAAKD,MAAK,GAAG;AACX,gBAAA,OAAOM,0BAA0BV,MAAAA,EAAQJ,SAAAA,CAAAA;AAC3C,YAAA;AACF,SA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C,CAAA;AAClE,oBAAA;;AAGA,oBAAA,OAAOY,0BAA0BV,MAAAA,EAAQ;AAAE,wBAAA,GAAGW,MAAM;AAAEd,wBAAAA,IAAAA,EAAMC,YAAYD;AAAK,qBAAA,CAAA;AAC/E,gBAAA;gBAEA,MAAM,EAAEA,IAAI,EAAE,GAAGD,SAAAA;AAEjB,gBAAA,MAAM,IAAIiB,KAAAA,CAAM,CAAC,4BAA4B,EAAEhB,IAAAA,CAAAA,CAAM,CAAA;AACvD,YAAA;AACF;AACF;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Internal } from '@strapi/types';
|
|
1
|
+
import type { Core, Internal } from '@strapi/types';
|
|
2
2
|
import * as z from 'zod/v4';
|
|
3
3
|
/**
|
|
4
4
|
* Safely adds or updates a schema in Zod's global registry.
|
|
@@ -14,7 +14,7 @@ import * as z from 'zod/v4';
|
|
|
14
14
|
* safeGlobalRegistrySet("mySchema", z.object({ name: z.string() }));
|
|
15
15
|
* ```
|
|
16
16
|
*/
|
|
17
|
-
export declare const safeGlobalRegistrySet: (id: Internal.UID.Schema, schema: z.ZodType) => void;
|
|
17
|
+
export declare const safeGlobalRegistrySet: (strapi: Core.Strapi, id: Internal.UID.Schema, schema: z.ZodType) => void;
|
|
18
18
|
/**
|
|
19
19
|
* Safely creates and registers a Zod schema in the global registry, particularly useful for handling cyclical data structures.
|
|
20
20
|
*
|
|
@@ -43,5 +43,5 @@ export declare const safeGlobalRegistrySet: (id: Internal.UID.Schema, schema: z.
|
|
|
43
43
|
* );
|
|
44
44
|
* ```
|
|
45
45
|
*/
|
|
46
|
-
export declare const safeSchemaCreation: (id: Internal.UID.Schema, callback: () => z.ZodType) => z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
|
|
46
|
+
export declare const safeSchemaCreation: (strapi: Core.Strapi, id: Internal.UID.Schema, callback: () => z.ZodType) => z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
|
|
47
47
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/core-api/routes/validation/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/core-api/routes/validation/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAI5B;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,qBAAqB,WACxB,KAAK,MAAM,MACf,SAAS,GAAG,CAAC,MAAM,UACf,EAAE,OAAO,SAyBlB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,kBAAkB,WACrB,KAAK,MAAM,MACf,SAAS,GAAG,CAAC,MAAM,YACb,MAAM,EAAE,OAAO,kFAyD1B,CAAC"}
|