@strapi/core 0.0.0-next.266ff4f8317121b6b17eea7fbfe2461e6171e48a → 0.0.0-next.281b331dc777a6a76694c122f7d1d9bc8c783747
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.
Potentially problematic release.
This version of @strapi/core might be problematic. Click here for more details.
- package/dist/Strapi.d.ts +1 -0
- package/dist/Strapi.d.ts.map +1 -1
- package/dist/Strapi.js +20 -1
- package/dist/Strapi.js.map +1 -1
- package/dist/Strapi.mjs +20 -1
- package/dist/Strapi.mjs.map +1 -1
- package/dist/configuration/index.d.ts +1 -0
- package/dist/configuration/index.d.ts.map +1 -1
- package/dist/configuration/index.js +1 -0
- package/dist/configuration/index.js.map +1 -1
- package/dist/configuration/index.mjs +1 -0
- package/dist/configuration/index.mjs.map +1 -1
- package/dist/configuration/urls.d.ts.map +1 -1
- package/dist/configuration/urls.js +13 -4
- package/dist/configuration/urls.js.map +1 -1
- package/dist/configuration/urls.mjs +13 -4
- package/dist/configuration/urls.mjs.map +1 -1
- package/dist/constants.d.ts +3 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +6 -0
- package/dist/constants.js.map +1 -0
- package/dist/constants.mjs +4 -0
- package/dist/constants.mjs.map +1 -0
- package/dist/core-api/controller/index.d.ts.map +1 -1
- package/dist/core-api/controller/index.js +2 -1
- package/dist/core-api/controller/index.js.map +1 -1
- package/dist/core-api/controller/index.mjs +2 -1
- package/dist/core-api/controller/index.mjs.map +1 -1
- package/dist/core-api/controller/transform.d.ts +3 -2
- package/dist/core-api/controller/transform.d.ts.map +1 -1
- package/dist/core-api/controller/transform.js +13 -3
- package/dist/core-api/controller/transform.js.map +1 -1
- package/dist/core-api/controller/transform.mjs +13 -3
- package/dist/core-api/controller/transform.mjs.map +1 -1
- package/dist/core-api/routes/index.d.ts +4 -22
- package/dist/core-api/routes/index.d.ts.map +1 -1
- package/dist/core-api/routes/index.js +150 -8
- package/dist/core-api/routes/index.js.map +1 -1
- package/dist/core-api/routes/index.mjs +131 -8
- package/dist/core-api/routes/index.mjs.map +1 -1
- package/dist/core-api/routes/validation/attributes.d.ts +244 -0
- package/dist/core-api/routes/validation/attributes.d.ts.map +1 -0
- package/dist/core-api/routes/validation/attributes.js +560 -0
- package/dist/core-api/routes/validation/attributes.js.map +1 -0
- package/dist/core-api/routes/validation/attributes.mjs +521 -0
- package/dist/core-api/routes/validation/attributes.mjs.map +1 -0
- package/dist/core-api/routes/validation/common.d.ts +105 -0
- package/dist/core-api/routes/validation/common.d.ts.map +1 -0
- package/dist/core-api/routes/validation/common.js +116 -0
- package/dist/core-api/routes/validation/common.js.map +1 -0
- package/dist/core-api/routes/validation/common.mjs +95 -0
- package/dist/core-api/routes/validation/common.mjs.map +1 -0
- package/dist/core-api/routes/validation/component.d.ts +34 -0
- package/dist/core-api/routes/validation/component.d.ts.map +1 -0
- package/dist/core-api/routes/validation/component.js +45 -0
- package/dist/core-api/routes/validation/component.js.map +1 -0
- package/dist/core-api/routes/validation/component.mjs +43 -0
- package/dist/core-api/routes/validation/component.mjs.map +1 -0
- package/dist/core-api/routes/validation/constants.d.ts +8 -0
- package/dist/core-api/routes/validation/constants.d.ts.map +1 -0
- package/dist/core-api/routes/validation/constants.js +18 -0
- package/dist/core-api/routes/validation/constants.js.map +1 -0
- package/dist/core-api/routes/validation/constants.mjs +16 -0
- package/dist/core-api/routes/validation/constants.mjs.map +1 -0
- package/dist/core-api/routes/validation/content-type.d.ts +128 -0
- package/dist/core-api/routes/validation/content-type.d.ts.map +1 -0
- package/dist/core-api/routes/validation/content-type.js +201 -0
- package/dist/core-api/routes/validation/content-type.js.map +1 -0
- package/dist/core-api/routes/validation/content-type.mjs +180 -0
- package/dist/core-api/routes/validation/content-type.mjs.map +1 -0
- package/dist/core-api/routes/validation/index.d.ts +5 -0
- package/dist/core-api/routes/validation/index.d.ts.map +1 -0
- package/dist/core-api/routes/validation/mappers.d.ts +105 -0
- package/dist/core-api/routes/validation/mappers.d.ts.map +1 -0
- package/dist/core-api/routes/validation/mappers.js +273 -0
- package/dist/core-api/routes/validation/mappers.js.map +1 -0
- package/dist/core-api/routes/validation/mappers.mjs +249 -0
- package/dist/core-api/routes/validation/mappers.mjs.map +1 -0
- package/dist/core-api/routes/validation/utils.d.ts +47 -0
- package/dist/core-api/routes/validation/utils.d.ts.map +1 -0
- package/dist/core-api/routes/validation/utils.js +128 -0
- package/dist/core-api/routes/validation/utils.js.map +1 -0
- package/dist/core-api/routes/validation/utils.mjs +106 -0
- package/dist/core-api/routes/validation/utils.mjs.map +1 -0
- package/dist/domain/content-type/index.d.ts.map +1 -1
- package/dist/domain/content-type/index.js +17 -1
- package/dist/domain/content-type/index.js.map +1 -1
- package/dist/domain/content-type/index.mjs +17 -1
- package/dist/domain/content-type/index.mjs.map +1 -1
- package/dist/domain/module/index.d.ts.map +1 -1
- package/dist/domain/module/index.js +3 -0
- package/dist/domain/module/index.js.map +1 -1
- package/dist/domain/module/index.mjs +3 -0
- package/dist/domain/module/index.mjs.map +1 -1
- package/dist/ee/index.d.ts +6 -0
- package/dist/ee/index.d.ts.map +1 -1
- package/dist/ee/index.js +29 -3
- package/dist/ee/index.js.map +1 -1
- package/dist/ee/index.mjs +30 -4
- package/dist/ee/index.mjs.map +1 -1
- package/dist/ee/license.d.ts +3 -1
- package/dist/ee/license.d.ts.map +1 -1
- package/dist/ee/license.js +8 -2
- package/dist/ee/license.js.map +1 -1
- package/dist/ee/license.mjs +9 -4
- package/dist/ee/license.mjs.map +1 -1
- package/dist/factories.d.ts +3 -1
- package/dist/factories.d.ts.map +1 -1
- package/dist/factories.js +10 -2
- package/dist/factories.js.map +1 -1
- package/dist/factories.mjs +10 -3
- package/dist/factories.mjs.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/loaders/plugins/index.js +1 -1
- package/dist/loaders/plugins/index.js.map +1 -1
- package/dist/loaders/plugins/index.mjs +1 -1
- package/dist/loaders/plugins/index.mjs.map +1 -1
- package/dist/middlewares/cors.d.ts +9 -1
- package/dist/middlewares/cors.d.ts.map +1 -1
- package/dist/middlewares/cors.js +39 -17
- package/dist/middlewares/cors.js.map +1 -1
- package/dist/middlewares/cors.mjs +39 -18
- package/dist/middlewares/cors.mjs.map +1 -1
- package/dist/migrations/first-published-at.d.ts +4 -0
- package/dist/migrations/first-published-at.d.ts.map +1 -0
- package/dist/migrations/first-published-at.js +51 -0
- package/dist/migrations/first-published-at.js.map +1 -0
- package/dist/migrations/first-published-at.mjs +49 -0
- package/dist/migrations/first-published-at.mjs.map +1 -0
- package/dist/migrations/index.d.ts.map +1 -1
- package/dist/migrations/index.js +5 -0
- package/dist/migrations/index.js.map +1 -1
- package/dist/migrations/index.mjs +5 -0
- package/dist/migrations/index.mjs.map +1 -1
- package/dist/package.json.js +19 -14
- package/dist/package.json.js.map +1 -1
- package/dist/package.json.mjs +19 -14
- package/dist/package.json.mjs.map +1 -1
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +2 -0
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/index.mjs +2 -0
- package/dist/providers/index.mjs.map +1 -1
- package/dist/providers/sessionManager.d.ts +3 -0
- package/dist/providers/sessionManager.d.ts.map +1 -0
- package/dist/providers/sessionManager.js +21 -0
- package/dist/providers/sessionManager.js.map +1 -0
- package/dist/providers/sessionManager.mjs +19 -0
- package/dist/providers/sessionManager.mjs.map +1 -0
- package/dist/services/content-api/index.d.ts +1 -1
- package/dist/services/content-api/index.d.ts.map +1 -1
- package/dist/services/content-api/index.js +1 -1
- package/dist/services/content-api/index.js.map +1 -1
- package/dist/services/content-api/index.mjs +2 -2
- package/dist/services/content-api/index.mjs.map +1 -1
- package/dist/services/content-source-maps.d.ts +13 -0
- package/dist/services/content-source-maps.d.ts.map +1 -0
- package/dist/services/content-source-maps.js +108 -0
- package/dist/services/content-source-maps.js.map +1 -0
- package/dist/services/content-source-maps.mjs +106 -0
- package/dist/services/content-source-maps.mjs.map +1 -0
- package/dist/services/core-store.d.ts +2 -2
- package/dist/services/core-store.d.ts.map +1 -1
- package/dist/services/core-store.js.map +1 -1
- package/dist/services/core-store.mjs.map +1 -1
- package/dist/services/document-service/components.d.ts +31 -1
- package/dist/services/document-service/components.d.ts.map +1 -1
- package/dist/services/document-service/components.js +109 -0
- package/dist/services/document-service/components.js.map +1 -1
- package/dist/services/document-service/components.mjs +107 -1
- package/dist/services/document-service/components.mjs.map +1 -1
- package/dist/services/document-service/entries.d.ts.map +1 -1
- package/dist/services/document-service/entries.js +42 -0
- package/dist/services/document-service/entries.js.map +1 -1
- package/dist/services/document-service/entries.mjs +43 -1
- package/dist/services/document-service/entries.mjs.map +1 -1
- package/dist/services/document-service/first-published-at.d.ts +7 -0
- package/dist/services/document-service/first-published-at.d.ts.map +1 -0
- package/dist/services/document-service/first-published-at.js +31 -0
- package/dist/services/document-service/first-published-at.js.map +1 -0
- package/dist/services/document-service/first-published-at.mjs +28 -0
- package/dist/services/document-service/first-published-at.mjs.map +1 -0
- package/dist/services/document-service/internationalization.d.ts +6 -1
- package/dist/services/document-service/internationalization.d.ts.map +1 -1
- package/dist/services/document-service/internationalization.js +32 -0
- package/dist/services/document-service/internationalization.js.map +1 -1
- package/dist/services/document-service/internationalization.mjs +32 -1
- package/dist/services/document-service/internationalization.mjs.map +1 -1
- package/dist/services/document-service/repository.d.ts.map +1 -1
- package/dist/services/document-service/repository.js +16 -8
- package/dist/services/document-service/repository.js.map +1 -1
- package/dist/services/document-service/repository.mjs +18 -10
- package/dist/services/document-service/repository.mjs.map +1 -1
- package/dist/services/document-service/utils/clean-component-join-table.d.ts +7 -0
- package/dist/services/document-service/utils/clean-component-join-table.d.ts.map +1 -0
- package/dist/services/document-service/utils/clean-component-join-table.js +138 -0
- package/dist/services/document-service/utils/clean-component-join-table.js.map +1 -0
- package/dist/services/document-service/utils/clean-component-join-table.mjs +136 -0
- package/dist/services/document-service/utils/clean-component-join-table.mjs.map +1 -0
- package/dist/services/document-service/utils/unidirectional-relations.d.ts +19 -2
- package/dist/services/document-service/utils/unidirectional-relations.d.ts.map +1 -1
- package/dist/services/document-service/utils/unidirectional-relations.js +21 -6
- package/dist/services/document-service/utils/unidirectional-relations.js.map +1 -1
- package/dist/services/document-service/utils/unidirectional-relations.mjs +21 -6
- package/dist/services/document-service/utils/unidirectional-relations.mjs.map +1 -1
- package/dist/services/entity-validator/index.d.ts.map +1 -1
- package/dist/services/entity-validator/index.js +9 -0
- package/dist/services/entity-validator/index.js.map +1 -1
- package/dist/services/entity-validator/index.mjs +9 -0
- package/dist/services/entity-validator/index.mjs.map +1 -1
- package/dist/services/entity-validator/validators.d.ts +1 -0
- package/dist/services/entity-validator/validators.d.ts.map +1 -1
- package/dist/services/entity-validator/validators.js +3 -0
- package/dist/services/entity-validator/validators.js.map +1 -1
- package/dist/services/entity-validator/validators.mjs +3 -0
- package/dist/services/entity-validator/validators.mjs.map +1 -1
- package/dist/services/metrics/admin-user-hash.d.ts.map +1 -1
- package/dist/services/metrics/admin-user-hash.js.map +1 -1
- package/dist/services/metrics/admin-user-hash.mjs.map +1 -1
- package/dist/services/metrics/index.d.ts +1 -1
- package/dist/services/metrics/index.d.ts.map +1 -1
- package/dist/services/metrics/index.js +11 -9
- package/dist/services/metrics/index.js.map +1 -1
- package/dist/services/metrics/index.mjs +11 -9
- package/dist/services/metrics/index.mjs.map +1 -1
- package/dist/services/metrics/middleware.d.ts +2 -1
- package/dist/services/metrics/middleware.d.ts.map +1 -1
- package/dist/services/metrics/middleware.js +2 -2
- package/dist/services/metrics/middleware.js.map +1 -1
- package/dist/services/metrics/middleware.mjs +2 -2
- package/dist/services/metrics/middleware.mjs.map +1 -1
- package/dist/services/metrics/sender.d.ts.map +1 -1
- package/dist/services/metrics/sender.js +5 -5
- package/dist/services/metrics/sender.js.map +1 -1
- package/dist/services/metrics/sender.mjs +6 -6
- package/dist/services/metrics/sender.mjs.map +1 -1
- package/dist/services/server/register-routes.js +22 -2
- package/dist/services/server/register-routes.js.map +1 -1
- package/dist/services/server/register-routes.mjs +22 -2
- package/dist/services/server/register-routes.mjs.map +1 -1
- package/dist/services/server/routing.d.ts +10 -0
- package/dist/services/server/routing.d.ts.map +1 -1
- package/dist/services/server/routing.js +7 -1
- package/dist/services/server/routing.js.map +1 -1
- package/dist/services/server/routing.mjs +7 -1
- package/dist/services/server/routing.mjs.map +1 -1
- package/dist/services/session-manager.d.ts +160 -0
- package/dist/services/session-manager.d.ts.map +1 -0
- package/dist/services/session-manager.js +476 -0
- package/dist/services/session-manager.js.map +1 -0
- package/dist/services/session-manager.mjs +473 -0
- package/dist/services/session-manager.mjs.map +1 -0
- package/dist/services/utils/conditional-fields.d.ts +3 -0
- package/dist/services/utils/conditional-fields.d.ts.map +1 -0
- package/dist/services/utils/conditional-fields.js +22 -0
- package/dist/services/utils/conditional-fields.js.map +1 -0
- package/dist/services/utils/conditional-fields.mjs +20 -0
- package/dist/services/utils/conditional-fields.mjs.map +1 -0
- package/dist/utils/fetch.d.ts +5 -1
- package/dist/utils/fetch.d.ts.map +1 -1
- package/dist/utils/fetch.js +8 -4
- package/dist/utils/fetch.js.map +1 -1
- package/dist/utils/fetch.mjs +8 -4
- package/dist/utils/fetch.mjs.map +1 -1
- package/dist/utils/transform-content-types-to-models.d.ts +197 -0
- package/dist/utils/transform-content-types-to-models.d.ts.map +1 -1
- package/package.json +19 -14
|
@@ -0,0 +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,SACF,IAAA,OAAOA,cAAc,QACrB,IAACA,SAAkBC,CAAAA,IAAI,KAAK,aAC5B,IAAA,OAAO,SAACD,CAAkBE,WAAW,KAAK,QAAA;AAE9C,CAAA;AAEA;;;;;;;;;;;;;;;;IAiBaC,MAAAA,sBAAAA,GAAyB,CACpCC,UAAAA,GAAAA;AAEA,IAAA,OAAOA,WAAWC,MAAM,CAAC,CAACC,GAAK,EAAA,CAACC,MAAMP,SAAU,CAAA,GAAA;QAC9C,OAAOM,GAAAA,CAAIE,MAAM,CAAC;YAChB,KAAKD,MAAQ,GAAA;AACX,gBAAA,OAAOE,oBAAqBT,CAAAA,SAAAA,CAAAA;AAC9B;AACF,SAAA,CAAA;KACCU,EAAAA,CAAAA,CAAEC,MAAM,CAAC,EAAC,CAAA,CAAA;AACf;AAEA;;;;;;;;;;;;;;;;;IAk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;AACrC,QAAA;AAAS,YAAA;AACP,gBAAA,IAAID,uBAAuBC,SAAY,CAAA,EAAA;AACrC,oBAAA,MAAMc,MAASd,GAAAA,SAAAA;oBACf,MAAMe,cAAAA,GAAiBC,OAAOC,MAAM;AACpC,oBAAA,IAAI,CAACF,cAAgB,EAAA;AACnB,wBAAA,MAAM,IAAIG,KAAM,CAAA,2DAAA,CAAA;AAClB;oBAEA,MAAMhB,WAAAA,GAAca,eAAeI,GAAG,CAAC,iBAAiBA,GAAG,CAACL,OAAOZ,WAAW,CAAA;AAC9E,oBAAA,IAAI,CAACA,WAAa,EAAA;wBAChB,MAAM,IAAIgB,MAAM,CAAC,cAAc,EAAEJ,MAAOZ,CAAAA,WAAW,CAAC,WAAW,CAAC,CAAA;AAClE;;AAGA,oBAAA,OAAOW,yBAA0B,CAAA;AAAE,wBAAA,GAAGC,MAAM;AAAEb,wBAAAA,IAAAA,EAAMC,YAAYD;AAAK,qBAAA,CAAA;AACvE;gBAEA,MAAM,EAAEA,IAAI,EAAE,GAAGD,SAAAA;AAEjB,gBAAA,MAAM,IAAIkB,KAAM,CAAA,CAAC,4BAA4B,EAAEjB,KAAK,CAAC,CAAA;AACvD;AACF;AACF;;;;"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Internal } from '@strapi/types';
|
|
2
|
+
import * as z from 'zod/v4';
|
|
3
|
+
/**
|
|
4
|
+
* Safely adds or updates a schema in Zod's global registry.
|
|
5
|
+
*
|
|
6
|
+
* If a schema with the given `id` already exists, it will be removed before adding the new one.
|
|
7
|
+
*
|
|
8
|
+
* This is useful for hot-reloading or preventing issues with cyclical dependencies.
|
|
9
|
+
*
|
|
10
|
+
* @param id - The unique identifier for the schema in the global registry.
|
|
11
|
+
* @param schema - The Zod schema to register.
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* safeGlobalRegistrySet("mySchema", z.object({ name: z.string() }));
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare const safeGlobalRegistrySet: (id: Internal.UID.Schema, schema: z.ZodType) => void;
|
|
18
|
+
/**
|
|
19
|
+
* Safely creates and registers a Zod schema in the global registry, particularly useful for handling cyclical data structures.
|
|
20
|
+
*
|
|
21
|
+
* If a schema with the given `id` already exists in the global registry, it returns the existing schema.
|
|
22
|
+
*
|
|
23
|
+
* Otherwise, it registers a temporary `z.any()` schema, calls the provided `callback` to create the actual schema,
|
|
24
|
+
* and then replaces the temporary schema with the actual one in the registry.
|
|
25
|
+
*
|
|
26
|
+
* This prevents infinite loops in cases of cyclical dependencies.
|
|
27
|
+
*
|
|
28
|
+
* @param id - The unique identifier for the schema in the global registry.
|
|
29
|
+
* @param callback - A function that returns the Zod schema to be created and registered.
|
|
30
|
+
* @returns The created or retrieved Zod schema.
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* const CategorySchema = safeSchemaCreation("Category", () =>
|
|
34
|
+
* z.object({
|
|
35
|
+
* name: z.string(),
|
|
36
|
+
* products: z.array(safeSchemaCreation("Product", () =>
|
|
37
|
+
* z.object({
|
|
38
|
+
* name: z.string(),
|
|
39
|
+
* category: z.lazy(() => CategorySchema) // Cyclical reference
|
|
40
|
+
* })
|
|
41
|
+
* ))
|
|
42
|
+
* })
|
|
43
|
+
* );
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare const safeSchemaCreation: (id: Internal.UID.Schema, callback: () => z.ZodType) => z.core.$ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
|
|
47
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +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;AAC9C,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAI5B;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,qBAAqB,OAAQ,SAAS,GAAG,CAAC,MAAM,UAAU,EAAE,OAAO,SAyB/E,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,kBAAkB,OAAQ,SAAS,GAAG,CAAC,MAAM,YAAY,MAAM,EAAE,OAAO,kFA0DpF,CAAC"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var strapiUtils = require('@strapi/utils');
|
|
4
|
+
var z = require('zod/v4');
|
|
5
|
+
|
|
6
|
+
function _interopNamespaceDefault(e) {
|
|
7
|
+
var n = Object.create(null);
|
|
8
|
+
if (e) {
|
|
9
|
+
Object.keys(e).forEach(function (k) {
|
|
10
|
+
if (k !== 'default') {
|
|
11
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
12
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () { return e[k]; }
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
n.default = e;
|
|
20
|
+
return Object.freeze(n);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
var z__namespace = /*#__PURE__*/_interopNamespaceDefault(z);
|
|
24
|
+
|
|
25
|
+
// Schema generation happens on-demand when schemas don't exist in the registry
|
|
26
|
+
/**
|
|
27
|
+
* Safely adds or updates a schema in Zod's global registry.
|
|
28
|
+
*
|
|
29
|
+
* If a schema with the given `id` already exists, it will be removed before adding the new one.
|
|
30
|
+
*
|
|
31
|
+
* This is useful for hot-reloading or preventing issues with cyclical dependencies.
|
|
32
|
+
*
|
|
33
|
+
* @param id - The unique identifier for the schema in the global registry.
|
|
34
|
+
* @param schema - The Zod schema to register.
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* safeGlobalRegistrySet("mySchema", z.object({ name: z.string() }));
|
|
38
|
+
* ```
|
|
39
|
+
*/ const safeGlobalRegistrySet = (id, schema)=>{
|
|
40
|
+
try {
|
|
41
|
+
const { _idmap: idMap } = z__namespace.globalRegistry;
|
|
42
|
+
const transformedId = strapiUtils.transformUidToValidOpenApiName(id);
|
|
43
|
+
const isReplacing = idMap.has(transformedId);
|
|
44
|
+
if (isReplacing) {
|
|
45
|
+
// Remove existing schema to prevent conflicts
|
|
46
|
+
idMap.delete(transformedId);
|
|
47
|
+
}
|
|
48
|
+
// Register the new schema with the transformed ID
|
|
49
|
+
strapi.log.debug(`${isReplacing ? 'Replacing' : 'Registering'} schema ${transformedId} in global registry`);
|
|
50
|
+
z__namespace.globalRegistry.add(schema, {
|
|
51
|
+
id: transformedId
|
|
52
|
+
});
|
|
53
|
+
} catch (error) {
|
|
54
|
+
strapi.log.error(`Schema registration failed: Failed to register schema ${id} in global registry`);
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Safely creates and registers a Zod schema in the global registry, particularly useful for handling cyclical data structures.
|
|
60
|
+
*
|
|
61
|
+
* If a schema with the given `id` already exists in the global registry, it returns the existing schema.
|
|
62
|
+
*
|
|
63
|
+
* Otherwise, it registers a temporary `z.any()` schema, calls the provided `callback` to create the actual schema,
|
|
64
|
+
* and then replaces the temporary schema with the actual one in the registry.
|
|
65
|
+
*
|
|
66
|
+
* This prevents infinite loops in cases of cyclical dependencies.
|
|
67
|
+
*
|
|
68
|
+
* @param id - The unique identifier for the schema in the global registry.
|
|
69
|
+
* @param callback - A function that returns the Zod schema to be created and registered.
|
|
70
|
+
* @returns The created or retrieved Zod schema.
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* const CategorySchema = safeSchemaCreation("Category", () =>
|
|
74
|
+
* z.object({
|
|
75
|
+
* name: z.string(),
|
|
76
|
+
* products: z.array(safeSchemaCreation("Product", () =>
|
|
77
|
+
* z.object({
|
|
78
|
+
* name: z.string(),
|
|
79
|
+
* category: z.lazy(() => CategorySchema) // Cyclical reference
|
|
80
|
+
* })
|
|
81
|
+
* ))
|
|
82
|
+
* })
|
|
83
|
+
* );
|
|
84
|
+
* ```
|
|
85
|
+
*/ const safeSchemaCreation = (id, callback)=>{
|
|
86
|
+
try {
|
|
87
|
+
const { _idmap: idMap } = z__namespace.globalRegistry;
|
|
88
|
+
const transformedId = strapiUtils.transformUidToValidOpenApiName(id);
|
|
89
|
+
// Return existing schema if already registered
|
|
90
|
+
const mapItem = idMap.get(transformedId);
|
|
91
|
+
if (mapItem) {
|
|
92
|
+
// Schema already exists, return it silently
|
|
93
|
+
return mapItem;
|
|
94
|
+
}
|
|
95
|
+
strapi.log.debug(`Schema ${transformedId} not found in registry, generating new schema`);
|
|
96
|
+
// Determine if this is a built-in schema or user content
|
|
97
|
+
const isBuiltInSchema = id.startsWith('plugin::') || id.startsWith('admin');
|
|
98
|
+
if (isBuiltInSchema) {
|
|
99
|
+
// Built-in schemas keep at debug level to avoid clutter
|
|
100
|
+
strapi.log.debug(`Initializing validation schema for ${transformedId}`);
|
|
101
|
+
} else {
|
|
102
|
+
// User content
|
|
103
|
+
const schemaName = transformedId.replace('Document', '').replace('Entry', '').replace(/([A-Z])/g, ' $1').trim();
|
|
104
|
+
strapi.log.debug(`📝 Generating validation schema for "${schemaName}"`);
|
|
105
|
+
}
|
|
106
|
+
// Temporary any placeholder before replacing with the actual schema type
|
|
107
|
+
// Used to prevent infinite loops in cyclical data structures
|
|
108
|
+
safeGlobalRegistrySet(id, z__namespace.any());
|
|
109
|
+
// Generate the actual schema using the callback
|
|
110
|
+
const schema = callback();
|
|
111
|
+
// Replace the placeholder with the real schema
|
|
112
|
+
safeGlobalRegistrySet(id, schema);
|
|
113
|
+
// Show completion for user content only
|
|
114
|
+
if (!isBuiltInSchema) {
|
|
115
|
+
const fieldCount = Object.keys(schema?._def?.shape || {}).length || 0;
|
|
116
|
+
const schemaName = transformedId.replace('Document', '').replace('Entry', '').replace(/([A-Z])/g, ' $1').trim();
|
|
117
|
+
strapi.log.debug(` ✅ "${schemaName}" schema created with ${fieldCount} fields`);
|
|
118
|
+
}
|
|
119
|
+
return schema;
|
|
120
|
+
} catch (error) {
|
|
121
|
+
strapi.log.error(`Schema creation failed: Failed to create schema ${id}`);
|
|
122
|
+
throw error;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
exports.safeGlobalRegistrySet = safeGlobalRegistrySet;
|
|
127
|
+
exports.safeSchemaCreation = safeSchemaCreation;
|
|
128
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../../src/core-api/routes/validation/utils.ts"],"sourcesContent":["import { transformUidToValidOpenApiName } from '@strapi/utils';\nimport type { Internal } from '@strapi/types';\nimport * as z from 'zod/v4';\n\n// Schema generation happens on-demand when schemas don't exist in the registry\n\n/**\n * Safely adds or updates a schema in Zod's global registry.\n *\n * If a schema with the given `id` already exists, it will be removed before adding the new one.\n *\n * This is useful for hot-reloading or preventing issues with cyclical dependencies.\n *\n * @param id - The unique identifier for the schema in the global registry.\n * @param schema - The Zod schema to register.\n * @example\n * ```typescript\n * safeGlobalRegistrySet(\"mySchema\", z.object({ name: z.string() }));\n * ```\n */\nexport const safeGlobalRegistrySet = (id: Internal.UID.Schema, schema: z.ZodType) => {\n try {\n const { _idmap: idMap } = z.globalRegistry;\n\n const transformedId = transformUidToValidOpenApiName(id);\n\n const isReplacing = idMap.has(transformedId);\n\n if (isReplacing) {\n // Remove existing schema to prevent conflicts\n idMap.delete(transformedId);\n }\n\n // Register the new schema with the transformed ID\n strapi.log.debug(\n `${isReplacing ? 'Replacing' : 'Registering'} schema ${transformedId} in global registry`\n );\n z.globalRegistry.add(schema, { id: transformedId });\n } catch (error) {\n strapi.log.error(\n `Schema registration failed: Failed to register schema ${id} in global registry`\n );\n\n throw error;\n }\n};\n\n/**\n * Safely creates and registers a Zod schema in the global registry, particularly useful for handling cyclical data structures.\n *\n * If a schema with the given `id` already exists in the global registry, it returns the existing schema.\n *\n * Otherwise, it registers a temporary `z.any()` schema, calls the provided `callback` to create the actual schema,\n * and then replaces the temporary schema with the actual one in the registry.\n *\n * This prevents infinite loops in cases of cyclical dependencies.\n *\n * @param id - The unique identifier for the schema in the global registry.\n * @param callback - A function that returns the Zod schema to be created and registered.\n * @returns The created or retrieved Zod schema.\n * @example\n * ```typescript\n * const CategorySchema = safeSchemaCreation(\"Category\", () =>\n * z.object({\n * name: z.string(),\n * products: z.array(safeSchemaCreation(\"Product\", () =>\n * z.object({\n * name: z.string(),\n * category: z.lazy(() => CategorySchema) // Cyclical reference\n * })\n * ))\n * })\n * );\n * ```\n */\nexport const safeSchemaCreation = (id: Internal.UID.Schema, callback: () => z.ZodType) => {\n try {\n const { _idmap: idMap } = z.globalRegistry;\n\n const transformedId = transformUidToValidOpenApiName(id);\n\n // Return existing schema if already registered\n const mapItem = idMap.get(transformedId);\n if (mapItem) {\n // Schema already exists, return it silently\n return mapItem;\n }\n\n strapi.log.debug(`Schema ${transformedId} not found in registry, generating new schema`);\n\n // Determine if this is a built-in schema or user content\n const isBuiltInSchema = id.startsWith('plugin::') || id.startsWith('admin');\n\n if (isBuiltInSchema) {\n // Built-in schemas keep at debug level to avoid clutter\n strapi.log.debug(`Initializing validation schema for ${transformedId}`);\n } else {\n // User content\n const schemaName = transformedId\n .replace('Document', '')\n .replace('Entry', '')\n .replace(/([A-Z])/g, ' $1')\n .trim();\n strapi.log.debug(`📝 Generating validation schema for \"${schemaName}\"`);\n }\n\n // Temporary any placeholder before replacing with the actual schema type\n // Used to prevent infinite loops in cyclical data structures\n safeGlobalRegistrySet(id, z.any());\n\n // Generate the actual schema using the callback\n const schema = callback();\n\n // Replace the placeholder with the real schema\n safeGlobalRegistrySet(id, schema);\n\n // Show completion for user content only\n if (!isBuiltInSchema) {\n const fieldCount = Object.keys((schema as any)?._def?.shape || {}).length || 0;\n const schemaName = transformedId\n .replace('Document', '')\n .replace('Entry', '')\n .replace(/([A-Z])/g, ' $1')\n .trim();\n strapi.log.debug(` ✅ \"${schemaName}\" schema created with ${fieldCount} fields`);\n }\n\n return schema;\n } catch (error) {\n strapi.log.error(`Schema creation failed: Failed to create schema ${id}`);\n\n throw error;\n }\n};\n"],"names":["safeGlobalRegistrySet","id","schema","_idmap","idMap","z","globalRegistry","transformedId","transformUidToValidOpenApiName","isReplacing","has","delete","strapi","log","debug","add","error","safeSchemaCreation","callback","mapItem","get","isBuiltInSchema","startsWith","schemaName","replace","trim","any","fieldCount","Object","keys","_def","shape","length"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAIA;AAEA;;;;;;;;;;;;;AAaC,IACM,MAAMA,qBAAwB,GAAA,CAACC,EAAyBC,EAAAA,MAAAA,GAAAA;IAC7D,IAAI;AACF,QAAA,MAAM,EAAEC,MAAQC,EAAAA,KAAK,EAAE,GAAGC,aAAEC,cAAc;AAE1C,QAAA,MAAMC,gBAAgBC,0CAA+BP,CAAAA,EAAAA,CAAAA;QAErD,MAAMQ,WAAAA,GAAcL,KAAMM,CAAAA,GAAG,CAACH,aAAAA,CAAAA;AAE9B,QAAA,IAAIE,WAAa,EAAA;;AAEfL,YAAAA,KAAAA,CAAMO,MAAM,CAACJ,aAAAA,CAAAA;AACf;;AAGAK,QAAAA,MAAAA,CAAOC,GAAG,CAACC,KAAK,CACd,CAAC,EAAEL,WAAc,GAAA,WAAA,GAAc,aAAc,CAAA,QAAQ,EAAEF,aAAAA,CAAc,mBAAmB,CAAC,CAAA;AAE3FF,QAAAA,YAAAA,CAAEC,cAAc,CAACS,GAAG,CAACb,MAAQ,EAAA;YAAED,EAAIM,EAAAA;AAAc,SAAA,CAAA;AACnD,KAAA,CAAE,OAAOS,KAAO,EAAA;QACdJ,MAAOC,CAAAA,GAAG,CAACG,KAAK,CACd,CAAC,sDAAsD,EAAEf,EAAG,CAAA,mBAAmB,CAAC,CAAA;QAGlF,MAAMe,KAAAA;AACR;AACF;AAEA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AAA;YACpB,MAAMM,UAAAA,GAAaC,MAAOC,CAAAA,IAAI,CAAE3B,MAAgB4B,EAAAA,IAAAA,EAAMC,KAAS,IAAA,EAAIC,CAAAA,CAAAA,MAAM,IAAI,CAAA;AAC7E,YAAA,MAAMT,UAAahB,GAAAA,aAAAA,CAChBiB,OAAO,CAAC,YAAY,EACpBA,CAAAA,CAAAA,OAAO,CAAC,OAAA,EAAS,EACjBA,CAAAA,CAAAA,OAAO,CAAC,UAAA,EAAY,OACpBC,IAAI,EAAA;AACPb,YAAAA,MAAAA,CAAOC,GAAG,CAACC,KAAK,CAAC,CAAC,MAAM,EAAES,UAAAA,CAAW,sBAAsB,EAAEI,UAAW,CAAA,OAAO,CAAC,CAAA;AAClF;QAEA,OAAOzB,MAAAA;AACT,KAAA,CAAE,OAAOc,KAAO,EAAA;QACdJ,MAAOC,CAAAA,GAAG,CAACG,KAAK,CAAC,CAAC,gDAAgD,EAAEf,GAAG,CAAC,CAAA;QAExE,MAAMe,KAAAA;AACR;AACF;;;;;"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { transformUidToValidOpenApiName } from '@strapi/utils';
|
|
2
|
+
import * as z from 'zod/v4';
|
|
3
|
+
|
|
4
|
+
// Schema generation happens on-demand when schemas don't exist in the registry
|
|
5
|
+
/**
|
|
6
|
+
* Safely adds or updates a schema in Zod's global registry.
|
|
7
|
+
*
|
|
8
|
+
* If a schema with the given `id` already exists, it will be removed before adding the new one.
|
|
9
|
+
*
|
|
10
|
+
* This is useful for hot-reloading or preventing issues with cyclical dependencies.
|
|
11
|
+
*
|
|
12
|
+
* @param id - The unique identifier for the schema in the global registry.
|
|
13
|
+
* @param schema - The Zod schema to register.
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* safeGlobalRegistrySet("mySchema", z.object({ name: z.string() }));
|
|
17
|
+
* ```
|
|
18
|
+
*/ const safeGlobalRegistrySet = (id, schema)=>{
|
|
19
|
+
try {
|
|
20
|
+
const { _idmap: idMap } = z.globalRegistry;
|
|
21
|
+
const transformedId = transformUidToValidOpenApiName(id);
|
|
22
|
+
const isReplacing = idMap.has(transformedId);
|
|
23
|
+
if (isReplacing) {
|
|
24
|
+
// Remove existing schema to prevent conflicts
|
|
25
|
+
idMap.delete(transformedId);
|
|
26
|
+
}
|
|
27
|
+
// Register the new schema with the transformed ID
|
|
28
|
+
strapi.log.debug(`${isReplacing ? 'Replacing' : 'Registering'} schema ${transformedId} in global registry`);
|
|
29
|
+
z.globalRegistry.add(schema, {
|
|
30
|
+
id: transformedId
|
|
31
|
+
});
|
|
32
|
+
} catch (error) {
|
|
33
|
+
strapi.log.error(`Schema registration failed: Failed to register schema ${id} in global registry`);
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Safely creates and registers a Zod schema in the global registry, particularly useful for handling cyclical data structures.
|
|
39
|
+
*
|
|
40
|
+
* If a schema with the given `id` already exists in the global registry, it returns the existing schema.
|
|
41
|
+
*
|
|
42
|
+
* Otherwise, it registers a temporary `z.any()` schema, calls the provided `callback` to create the actual schema,
|
|
43
|
+
* and then replaces the temporary schema with the actual one in the registry.
|
|
44
|
+
*
|
|
45
|
+
* This prevents infinite loops in cases of cyclical dependencies.
|
|
46
|
+
*
|
|
47
|
+
* @param id - The unique identifier for the schema in the global registry.
|
|
48
|
+
* @param callback - A function that returns the Zod schema to be created and registered.
|
|
49
|
+
* @returns The created or retrieved Zod schema.
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* const CategorySchema = safeSchemaCreation("Category", () =>
|
|
53
|
+
* z.object({
|
|
54
|
+
* name: z.string(),
|
|
55
|
+
* products: z.array(safeSchemaCreation("Product", () =>
|
|
56
|
+
* z.object({
|
|
57
|
+
* name: z.string(),
|
|
58
|
+
* category: z.lazy(() => CategorySchema) // Cyclical reference
|
|
59
|
+
* })
|
|
60
|
+
* ))
|
|
61
|
+
* })
|
|
62
|
+
* );
|
|
63
|
+
* ```
|
|
64
|
+
*/ const safeSchemaCreation = (id, callback)=>{
|
|
65
|
+
try {
|
|
66
|
+
const { _idmap: idMap } = z.globalRegistry;
|
|
67
|
+
const transformedId = transformUidToValidOpenApiName(id);
|
|
68
|
+
// Return existing schema if already registered
|
|
69
|
+
const mapItem = idMap.get(transformedId);
|
|
70
|
+
if (mapItem) {
|
|
71
|
+
// Schema already exists, return it silently
|
|
72
|
+
return mapItem;
|
|
73
|
+
}
|
|
74
|
+
strapi.log.debug(`Schema ${transformedId} not found in registry, generating new schema`);
|
|
75
|
+
// Determine if this is a built-in schema or user content
|
|
76
|
+
const isBuiltInSchema = id.startsWith('plugin::') || id.startsWith('admin');
|
|
77
|
+
if (isBuiltInSchema) {
|
|
78
|
+
// Built-in schemas keep at debug level to avoid clutter
|
|
79
|
+
strapi.log.debug(`Initializing validation schema for ${transformedId}`);
|
|
80
|
+
} else {
|
|
81
|
+
// User content
|
|
82
|
+
const schemaName = transformedId.replace('Document', '').replace('Entry', '').replace(/([A-Z])/g, ' $1').trim();
|
|
83
|
+
strapi.log.debug(`📝 Generating validation schema for "${schemaName}"`);
|
|
84
|
+
}
|
|
85
|
+
// Temporary any placeholder before replacing with the actual schema type
|
|
86
|
+
// Used to prevent infinite loops in cyclical data structures
|
|
87
|
+
safeGlobalRegistrySet(id, z.any());
|
|
88
|
+
// Generate the actual schema using the callback
|
|
89
|
+
const schema = callback();
|
|
90
|
+
// Replace the placeholder with the real schema
|
|
91
|
+
safeGlobalRegistrySet(id, schema);
|
|
92
|
+
// Show completion for user content only
|
|
93
|
+
if (!isBuiltInSchema) {
|
|
94
|
+
const fieldCount = Object.keys(schema?._def?.shape || {}).length || 0;
|
|
95
|
+
const schemaName = transformedId.replace('Document', '').replace('Entry', '').replace(/([A-Z])/g, ' $1').trim();
|
|
96
|
+
strapi.log.debug(` ✅ "${schemaName}" schema created with ${fieldCount} fields`);
|
|
97
|
+
}
|
|
98
|
+
return schema;
|
|
99
|
+
} catch (error) {
|
|
100
|
+
strapi.log.error(`Schema creation failed: Failed to create schema ${id}`);
|
|
101
|
+
throw error;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export { safeGlobalRegistrySet, safeSchemaCreation };
|
|
106
|
+
//# sourceMappingURL=utils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.mjs","sources":["../../../../src/core-api/routes/validation/utils.ts"],"sourcesContent":["import { transformUidToValidOpenApiName } from '@strapi/utils';\nimport type { Internal } from '@strapi/types';\nimport * as z from 'zod/v4';\n\n// Schema generation happens on-demand when schemas don't exist in the registry\n\n/**\n * Safely adds or updates a schema in Zod's global registry.\n *\n * If a schema with the given `id` already exists, it will be removed before adding the new one.\n *\n * This is useful for hot-reloading or preventing issues with cyclical dependencies.\n *\n * @param id - The unique identifier for the schema in the global registry.\n * @param schema - The Zod schema to register.\n * @example\n * ```typescript\n * safeGlobalRegistrySet(\"mySchema\", z.object({ name: z.string() }));\n * ```\n */\nexport const safeGlobalRegistrySet = (id: Internal.UID.Schema, schema: z.ZodType) => {\n try {\n const { _idmap: idMap } = z.globalRegistry;\n\n const transformedId = transformUidToValidOpenApiName(id);\n\n const isReplacing = idMap.has(transformedId);\n\n if (isReplacing) {\n // Remove existing schema to prevent conflicts\n idMap.delete(transformedId);\n }\n\n // Register the new schema with the transformed ID\n strapi.log.debug(\n `${isReplacing ? 'Replacing' : 'Registering'} schema ${transformedId} in global registry`\n );\n z.globalRegistry.add(schema, { id: transformedId });\n } catch (error) {\n strapi.log.error(\n `Schema registration failed: Failed to register schema ${id} in global registry`\n );\n\n throw error;\n }\n};\n\n/**\n * Safely creates and registers a Zod schema in the global registry, particularly useful for handling cyclical data structures.\n *\n * If a schema with the given `id` already exists in the global registry, it returns the existing schema.\n *\n * Otherwise, it registers a temporary `z.any()` schema, calls the provided `callback` to create the actual schema,\n * and then replaces the temporary schema with the actual one in the registry.\n *\n * This prevents infinite loops in cases of cyclical dependencies.\n *\n * @param id - The unique identifier for the schema in the global registry.\n * @param callback - A function that returns the Zod schema to be created and registered.\n * @returns The created or retrieved Zod schema.\n * @example\n * ```typescript\n * const CategorySchema = safeSchemaCreation(\"Category\", () =>\n * z.object({\n * name: z.string(),\n * products: z.array(safeSchemaCreation(\"Product\", () =>\n * z.object({\n * name: z.string(),\n * category: z.lazy(() => CategorySchema) // Cyclical reference\n * })\n * ))\n * })\n * );\n * ```\n */\nexport const safeSchemaCreation = (id: Internal.UID.Schema, callback: () => z.ZodType) => {\n try {\n const { _idmap: idMap } = z.globalRegistry;\n\n const transformedId = transformUidToValidOpenApiName(id);\n\n // Return existing schema if already registered\n const mapItem = idMap.get(transformedId);\n if (mapItem) {\n // Schema already exists, return it silently\n return mapItem;\n }\n\n strapi.log.debug(`Schema ${transformedId} not found in registry, generating new schema`);\n\n // Determine if this is a built-in schema or user content\n const isBuiltInSchema = id.startsWith('plugin::') || id.startsWith('admin');\n\n if (isBuiltInSchema) {\n // Built-in schemas keep at debug level to avoid clutter\n strapi.log.debug(`Initializing validation schema for ${transformedId}`);\n } else {\n // User content\n const schemaName = transformedId\n .replace('Document', '')\n .replace('Entry', '')\n .replace(/([A-Z])/g, ' $1')\n .trim();\n strapi.log.debug(`📝 Generating validation schema for \"${schemaName}\"`);\n }\n\n // Temporary any placeholder before replacing with the actual schema type\n // Used to prevent infinite loops in cyclical data structures\n safeGlobalRegistrySet(id, z.any());\n\n // Generate the actual schema using the callback\n const schema = callback();\n\n // Replace the placeholder with the real schema\n safeGlobalRegistrySet(id, schema);\n\n // Show completion for user content only\n if (!isBuiltInSchema) {\n const fieldCount = Object.keys((schema as any)?._def?.shape || {}).length || 0;\n const schemaName = transformedId\n .replace('Document', '')\n .replace('Entry', '')\n .replace(/([A-Z])/g, ' $1')\n .trim();\n strapi.log.debug(` ✅ \"${schemaName}\" schema created with ${fieldCount} fields`);\n }\n\n return schema;\n } catch (error) {\n strapi.log.error(`Schema creation failed: Failed to create schema ${id}`);\n\n throw error;\n }\n};\n"],"names":["safeGlobalRegistrySet","id","schema","_idmap","idMap","z","globalRegistry","transformedId","transformUidToValidOpenApiName","isReplacing","has","delete","strapi","log","debug","add","error","safeSchemaCreation","callback","mapItem","get","isBuiltInSchema","startsWith","schemaName","replace","trim","any","fieldCount","Object","keys","_def","shape","length"],"mappings":";;;AAIA;AAEA;;;;;;;;;;;;;AAaC,IACM,MAAMA,qBAAwB,GAAA,CAACC,EAAyBC,EAAAA,MAAAA,GAAAA;IAC7D,IAAI;AACF,QAAA,MAAM,EAAEC,MAAQC,EAAAA,KAAK,EAAE,GAAGC,EAAEC,cAAc;AAE1C,QAAA,MAAMC,gBAAgBC,8BAA+BP,CAAAA,EAAAA,CAAAA;QAErD,MAAMQ,WAAAA,GAAcL,KAAMM,CAAAA,GAAG,CAACH,aAAAA,CAAAA;AAE9B,QAAA,IAAIE,WAAa,EAAA;;AAEfL,YAAAA,KAAAA,CAAMO,MAAM,CAACJ,aAAAA,CAAAA;AACf;;AAGAK,QAAAA,MAAAA,CAAOC,GAAG,CAACC,KAAK,CACd,CAAC,EAAEL,WAAc,GAAA,WAAA,GAAc,aAAc,CAAA,QAAQ,EAAEF,aAAAA,CAAc,mBAAmB,CAAC,CAAA;AAE3FF,QAAAA,CAAAA,CAAEC,cAAc,CAACS,GAAG,CAACb,MAAQ,EAAA;YAAED,EAAIM,EAAAA;AAAc,SAAA,CAAA;AACnD,KAAA,CAAE,OAAOS,KAAO,EAAA;QACdJ,MAAOC,CAAAA,GAAG,CAACG,KAAK,CACd,CAAC,sDAAsD,EAAEf,EAAG,CAAA,mBAAmB,CAAC,CAAA;QAGlF,MAAMe,KAAAA;AACR;AACF;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BC,IACM,MAAMC,kBAAqB,GAAA,CAAChB,EAAyBiB,EAAAA,QAAAA,GAAAA;IAC1D,IAAI;AACF,QAAA,MAAM,EAAEf,MAAQC,EAAAA,KAAK,EAAE,GAAG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AAAA,aAAAA,CAChBiB,OAAO,CAAC,YAAY,EACpBA,CAAAA,CAAAA,OAAO,CAAC,OAAA,EAAS,EACjBA,CAAAA,CAAAA,OAAO,CAAC,UAAA,EAAY,OACpBC,IAAI,EAAA;AACPb,YAAAA,MAAAA,CAAOC,GAAG,CAACC,KAAK,CAAC,CAAC,MAAM,EAAES,UAAAA,CAAW,sBAAsB,EAAEI,UAAW,CAAA,OAAO,CAAC,CAAA;AAClF;QAEA,OAAOzB,MAAAA;AACT,KAAA,CAAE,OAAOc,KAAO,EAAA;QACdJ,MAAOC,CAAAA,GAAG,CAACG,KAAK,CAAC,CAAC,gDAAgD,EAAEf,GAAG,CAAC,CAAA;QAExE,MAAMe,KAAAA;AACR;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/domain/content-type/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAG5C,MAAM,MAAM,qBAAqB,GAAG;IAClC,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACrC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/domain/content-type/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAG5C,MAAM,MAAM,qBAAqB,GAAG;IAClC,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACrC,CAAC;AAWF,QAAA,MAAM,iBAAiB,QAAS,MAAM,cAAc,qBAAqB,0DAmCxE,CAAC;AA0EF,QAAA,MAAM,WAAW,WAAY,OAAO,WAAW,WAAW,MAAM,WAK/D,CAAC;AAmBF,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -5,7 +5,7 @@ var _ = require('lodash');
|
|
|
5
5
|
var strapiUtils = require('@strapi/utils');
|
|
6
6
|
var validator = require('./validator.js');
|
|
7
7
|
|
|
8
|
-
const { CREATED_AT_ATTRIBUTE, UPDATED_AT_ATTRIBUTE, PUBLISHED_AT_ATTRIBUTE, CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE } = strapiUtils.contentTypes.constants;
|
|
8
|
+
const { CREATED_AT_ATTRIBUTE, UPDATED_AT_ATTRIBUTE, PUBLISHED_AT_ATTRIBUTE, FIRST_PUBLISHED_AT_ATTRIBUTE, CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE } = strapiUtils.contentTypes.constants;
|
|
9
9
|
const createContentType = (uid, definition)=>{
|
|
10
10
|
try {
|
|
11
11
|
validator.validateContentTypeDefinition(definition);
|
|
@@ -31,6 +31,7 @@ const createContentType = (uid, definition)=>{
|
|
|
31
31
|
// In case it is not enabled, value will be always published, and it will not contain a draft
|
|
32
32
|
addDraftAndPublish(schema);
|
|
33
33
|
addCreatorFields(schema);
|
|
34
|
+
addFirstPublishedAt(schema);
|
|
34
35
|
return schema;
|
|
35
36
|
};
|
|
36
37
|
const addTimestamps = (schema)=>{
|
|
@@ -59,6 +60,21 @@ const addDraftAndPublish = (schema)=>{
|
|
|
59
60
|
}
|
|
60
61
|
};
|
|
61
62
|
};
|
|
63
|
+
const addFirstPublishedAt = (schema)=>{
|
|
64
|
+
const isEnabled = strapiUtils.contentTypes.hasFirstPublishedAtField(schema);
|
|
65
|
+
// Note: As an expertimental feature, we are okay if this data is deleted if this feature is
|
|
66
|
+
// switched off. Once "preserve_attributes" come into play, this will be updated.
|
|
67
|
+
if (isEnabled) {
|
|
68
|
+
strapi.log.warn(`Experimental feature enabled: firstPublishedAt on ${schema.collectionName}`);
|
|
69
|
+
schema.attributes[FIRST_PUBLISHED_AT_ATTRIBUTE] = {
|
|
70
|
+
type: 'datetime',
|
|
71
|
+
configurable: false,
|
|
72
|
+
writable: true,
|
|
73
|
+
visible: false,
|
|
74
|
+
private: !isEnabled
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
};
|
|
62
78
|
const addCreatorFields = (schema)=>{
|
|
63
79
|
const isPrivate = !_.get(schema, 'options.populateCreatorFields', false);
|
|
64
80
|
schema.attributes[CREATED_BY_ATTRIBUTE] = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/domain/content-type/index.ts"],"sourcesContent":["import { cloneDeep } from 'lodash/fp';\nimport _ from 'lodash';\nimport { yup, contentTypes as contentTypesUtils } from '@strapi/utils';\nimport type { Schema } from '@strapi/types';\nimport { validateContentTypeDefinition } from './validator';\n\nexport type ContentTypeDefinition = {\n schema: Schema.ContentType;\n actions: Record<string, unknown>;\n lifecycles: Record<string, unknown>;\n};\n\nconst {\n CREATED_AT_ATTRIBUTE,\n UPDATED_AT_ATTRIBUTE,\n PUBLISHED_AT_ATTRIBUTE,\n CREATED_BY_ATTRIBUTE,\n UPDATED_BY_ATTRIBUTE,\n} = contentTypesUtils.constants;\n\nconst createContentType = (uid: string, definition: ContentTypeDefinition) => {\n try {\n validateContentTypeDefinition(definition);\n } catch (e) {\n if (e instanceof yup.ValidationError) {\n throw new Error(`Content Type Definition is invalid for ${uid}'.\\n${e.errors}`);\n }\n\n throw e;\n }\n\n const { schema, actions, lifecycles } = cloneDeep(definition);\n\n // general info\n Object.assign(schema, {\n uid,\n modelType: 'contentType',\n kind: schema.kind || 'collectionType',\n __schema__: pickSchema(definition.schema),\n modelName: definition.schema.info.singularName,\n actions,\n lifecycles,\n });\n\n addTimestamps(schema);\n\n // Published at is added regardless of draft and publish being enabled\n // In case it is not enabled, value will be always published, and it will not contain a draft\n addDraftAndPublish(schema);\n\n addCreatorFields(schema);\n\n return schema;\n};\n\nconst addTimestamps = (schema: Schema.ContentType) => {\n // attributes\n Object.assign(schema.attributes, {\n [CREATED_AT_ATTRIBUTE]: {\n type: 'datetime',\n },\n // TODO: handle on edit set to new date\n [UPDATED_AT_ATTRIBUTE]: {\n type: 'datetime',\n },\n });\n};\n\nconst addDraftAndPublish = (schema: Schema.ContentType) => {\n if (!_.has(schema, 'options.draftAndPublish')) {\n _.set(schema, 'options.draftAndPublish', false); // Disabled by default\n }\n\n schema.attributes[PUBLISHED_AT_ATTRIBUTE] = {\n type: 'datetime',\n configurable: false,\n writable: true,\n visible: false,\n default() {\n return new Date();\n },\n };\n};\n\nconst addCreatorFields = (schema: Schema.ContentType) => {\n const isPrivate = !_.get(schema, 'options.populateCreatorFields', false);\n\n schema.attributes[CREATED_BY_ATTRIBUTE] = {\n type: 'relation',\n relation: 'oneToOne',\n target: 'admin::user',\n configurable: false,\n writable: false,\n visible: false,\n useJoinTable: false,\n private: isPrivate,\n };\n\n schema.attributes[UPDATED_BY_ATTRIBUTE] = {\n type: 'relation',\n relation: 'oneToOne',\n target: 'admin::user',\n configurable: false,\n writable: false,\n visible: false,\n useJoinTable: false,\n private: isPrivate,\n };\n};\n\nconst getGlobalId = (schema: Schema.ContentType, prefix?: string) => {\n const modelName = schema.info.singularName;\n const globalId = prefix ? `${prefix}-${modelName}` : modelName;\n\n return schema.globalId || _.upperFirst(_.camelCase(globalId));\n};\n\nconst pickSchema = (model: Schema.ContentType) => {\n const schema = _.cloneDeep(\n _.pick(model, [\n 'connection',\n 'collectionName',\n 'info',\n 'options',\n 'pluginOptions',\n 'attributes',\n 'kind',\n ])\n );\n\n schema.kind = model.kind || 'collectionType';\n return schema;\n};\n\nexport { createContentType, getGlobalId };\n"],"names":["CREATED_AT_ATTRIBUTE","UPDATED_AT_ATTRIBUTE","PUBLISHED_AT_ATTRIBUTE","CREATED_BY_ATTRIBUTE","UPDATED_BY_ATTRIBUTE","contentTypesUtils","constants","createContentType","uid","definition","validateContentTypeDefinition","e","yup","ValidationError","Error","errors","schema","actions","lifecycles","cloneDeep","Object","assign","modelType","kind","__schema__","pickSchema","modelName","info","singularName","addTimestamps","addDraftAndPublish","addCreatorFields","attributes","type","_","has","set","configurable","writable","visible","default","Date","isPrivate","get","relation","target","useJoinTable","
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/domain/content-type/index.ts"],"sourcesContent":["import { cloneDeep } from 'lodash/fp';\nimport _ from 'lodash';\nimport { yup, contentTypes as contentTypesUtils } from '@strapi/utils';\nimport type { Schema } from '@strapi/types';\nimport { validateContentTypeDefinition } from './validator';\n\nexport type ContentTypeDefinition = {\n schema: Schema.ContentType;\n actions: Record<string, unknown>;\n lifecycles: Record<string, unknown>;\n};\n\nconst {\n CREATED_AT_ATTRIBUTE,\n UPDATED_AT_ATTRIBUTE,\n PUBLISHED_AT_ATTRIBUTE,\n FIRST_PUBLISHED_AT_ATTRIBUTE,\n CREATED_BY_ATTRIBUTE,\n UPDATED_BY_ATTRIBUTE,\n} = contentTypesUtils.constants;\n\nconst createContentType = (uid: string, definition: ContentTypeDefinition) => {\n try {\n validateContentTypeDefinition(definition);\n } catch (e) {\n if (e instanceof yup.ValidationError) {\n throw new Error(`Content Type Definition is invalid for ${uid}'.\\n${e.errors}`);\n }\n\n throw e;\n }\n\n const { schema, actions, lifecycles } = cloneDeep(definition);\n\n // general info\n Object.assign(schema, {\n uid,\n modelType: 'contentType',\n kind: schema.kind || 'collectionType',\n __schema__: pickSchema(definition.schema),\n modelName: definition.schema.info.singularName,\n actions,\n lifecycles,\n });\n\n addTimestamps(schema);\n\n // Published at is added regardless of draft and publish being enabled\n // In case it is not enabled, value will be always published, and it will not contain a draft\n addDraftAndPublish(schema);\n\n addCreatorFields(schema);\n\n addFirstPublishedAt(schema);\n\n return schema;\n};\n\nconst addTimestamps = (schema: Schema.ContentType) => {\n // attributes\n Object.assign(schema.attributes, {\n [CREATED_AT_ATTRIBUTE]: {\n type: 'datetime',\n },\n // TODO: handle on edit set to new date\n [UPDATED_AT_ATTRIBUTE]: {\n type: 'datetime',\n },\n });\n};\n\nconst addDraftAndPublish = (schema: Schema.ContentType) => {\n if (!_.has(schema, 'options.draftAndPublish')) {\n _.set(schema, 'options.draftAndPublish', false); // Disabled by default\n }\n\n schema.attributes[PUBLISHED_AT_ATTRIBUTE] = {\n type: 'datetime',\n configurable: false,\n writable: true,\n visible: false,\n default() {\n return new Date();\n },\n };\n};\n\nconst addFirstPublishedAt = (schema: Schema.ContentType) => {\n const isEnabled = contentTypesUtils.hasFirstPublishedAtField(schema);\n\n // Note: As an expertimental feature, we are okay if this data is deleted if this feature is\n // switched off. Once \"preserve_attributes\" come into play, this will be updated.\n if (isEnabled) {\n strapi.log.warn(`Experimental feature enabled: firstPublishedAt on ${schema.collectionName}`);\n schema.attributes[FIRST_PUBLISHED_AT_ATTRIBUTE] = {\n type: 'datetime',\n configurable: false,\n writable: true,\n visible: false,\n private: !isEnabled,\n };\n }\n};\n\nconst addCreatorFields = (schema: Schema.ContentType) => {\n const isPrivate = !_.get(schema, 'options.populateCreatorFields', false);\n\n schema.attributes[CREATED_BY_ATTRIBUTE] = {\n type: 'relation',\n relation: 'oneToOne',\n target: 'admin::user',\n configurable: false,\n writable: false,\n visible: false,\n useJoinTable: false,\n private: isPrivate,\n };\n\n schema.attributes[UPDATED_BY_ATTRIBUTE] = {\n type: 'relation',\n relation: 'oneToOne',\n target: 'admin::user',\n configurable: false,\n writable: false,\n visible: false,\n useJoinTable: false,\n private: isPrivate,\n };\n};\n\nconst getGlobalId = (schema: Schema.ContentType, prefix?: string) => {\n const modelName = schema.info.singularName;\n const globalId = prefix ? `${prefix}-${modelName}` : modelName;\n\n return schema.globalId || _.upperFirst(_.camelCase(globalId));\n};\n\nconst pickSchema = (model: Schema.ContentType) => {\n const schema = _.cloneDeep(\n _.pick(model, [\n 'connection',\n 'collectionName',\n 'info',\n 'options',\n 'pluginOptions',\n 'attributes',\n 'kind',\n ])\n );\n\n schema.kind = model.kind || 'collectionType';\n return schema;\n};\n\nexport { createContentType, getGlobalId };\n"],"names":["CREATED_AT_ATTRIBUTE","UPDATED_AT_ATTRIBUTE","PUBLISHED_AT_ATTRIBUTE","FIRST_PUBLISHED_AT_ATTRIBUTE","CREATED_BY_ATTRIBUTE","UPDATED_BY_ATTRIBUTE","contentTypesUtils","constants","createContentType","uid","definition","validateContentTypeDefinition","e","yup","ValidationError","Error","errors","schema","actions","lifecycles","cloneDeep","Object","assign","modelType","kind","__schema__","pickSchema","modelName","info","singularName","addTimestamps","addDraftAndPublish","addCreatorFields","addFirstPublishedAt","attributes","type","_","has","set","configurable","writable","visible","default","Date","isEnabled","hasFirstPublishedAtField","strapi","log","warn","collectionName","private","isPrivate","get","relation","target","useJoinTable","getGlobalId","prefix","globalId","upperFirst","camelCase","model","pick"],"mappings":";;;;;;;AAYA,MAAM,EACJA,oBAAoB,EACpBC,oBAAoB,EACpBC,sBAAsB,EACtBC,4BAA4B,EAC5BC,oBAAoB,EACpBC,oBAAoB,EACrB,GAAGC,yBAAkBC,SAAS;AAEzBC,MAAAA,iBAAAA,GAAoB,CAACC,GAAaC,EAAAA,UAAAA,GAAAA;IACtC,IAAI;QACFC,uCAA8BD,CAAAA,UAAAA,CAAAA;AAChC,KAAA,CAAE,OAAOE,CAAG,EAAA;QACV,IAAIA,CAAAA,YAAaC,eAAIC,CAAAA,eAAe,EAAE;YACpC,MAAM,IAAIC,KAAM,CAAA,CAAC,uCAAuC,EAAEN,GAAI,CAAA,IAAI,EAAEG,CAAAA,CAAEI,MAAM,CAAC,CAAC,CAAA;AAChF;QAEA,MAAMJ,CAAAA;AACR;IAEA,MAAM,EAAEK,MAAM,EAAEC,OAAO,EAAEC,UAAU,EAAE,GAAGC,YAAUV,CAAAA,UAAAA,CAAAA;;IAGlDW,MAAOC,CAAAA,MAAM,CAACL,MAAQ,EAAA;AACpBR,QAAAA,GAAAA;QACAc,SAAW,EAAA,aA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AAWD,SAAS,CAAC,EAAEA,OAAO,CAAC,EAAE9B,SAAU,CAAA,CAAC,GAAGA,SAAAA;IAErD,OAAOV,MAAAA,CAAOyC,QAAQ,IAAItB,CAAAA,CAAEuB,UAAU,CAACvB,CAAAA,CAAEwB,SAAS,CAACF,QAAAA,CAAAA,CAAAA;AACrD;AAEA,MAAMhC,aAAa,CAACmC,KAAAA,GAAAA;AAClB,IAAA,MAAM5C,SAASmB,CAAEhB,CAAAA,SAAS,CACxBgB,CAAE0B,CAAAA,IAAI,CAACD,KAAO,EAAA;AACZ,QAAA,YAAA;AACA,QAAA,gBAAA;AACA,QAAA,MAAA;AACA,QAAA,SAAA;AACA,QAAA,eAAA;AACA,QAAA,YAAA;AACA,QAAA;AACD,KAAA,CAAA,CAAA;AAGH5C,IAAAA,MAAAA,CAAOO,IAAI,GAAGqC,KAAMrC,CAAAA,IAAI,IAAI,gBAAA;IAC5B,OAAOP,MAAAA;AACT,CAAA;;;;;"}
|
|
@@ -3,7 +3,7 @@ import _ from 'lodash';
|
|
|
3
3
|
import { contentTypes, yup } from '@strapi/utils';
|
|
4
4
|
import { validateContentTypeDefinition } from './validator.mjs';
|
|
5
5
|
|
|
6
|
-
const { CREATED_AT_ATTRIBUTE, UPDATED_AT_ATTRIBUTE, PUBLISHED_AT_ATTRIBUTE, CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE } = contentTypes.constants;
|
|
6
|
+
const { CREATED_AT_ATTRIBUTE, UPDATED_AT_ATTRIBUTE, PUBLISHED_AT_ATTRIBUTE, FIRST_PUBLISHED_AT_ATTRIBUTE, CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE } = contentTypes.constants;
|
|
7
7
|
const createContentType = (uid, definition)=>{
|
|
8
8
|
try {
|
|
9
9
|
validateContentTypeDefinition(definition);
|
|
@@ -29,6 +29,7 @@ const createContentType = (uid, definition)=>{
|
|
|
29
29
|
// In case it is not enabled, value will be always published, and it will not contain a draft
|
|
30
30
|
addDraftAndPublish(schema);
|
|
31
31
|
addCreatorFields(schema);
|
|
32
|
+
addFirstPublishedAt(schema);
|
|
32
33
|
return schema;
|
|
33
34
|
};
|
|
34
35
|
const addTimestamps = (schema)=>{
|
|
@@ -57,6 +58,21 @@ const addDraftAndPublish = (schema)=>{
|
|
|
57
58
|
}
|
|
58
59
|
};
|
|
59
60
|
};
|
|
61
|
+
const addFirstPublishedAt = (schema)=>{
|
|
62
|
+
const isEnabled = contentTypes.hasFirstPublishedAtField(schema);
|
|
63
|
+
// Note: As an expertimental feature, we are okay if this data is deleted if this feature is
|
|
64
|
+
// switched off. Once "preserve_attributes" come into play, this will be updated.
|
|
65
|
+
if (isEnabled) {
|
|
66
|
+
strapi.log.warn(`Experimental feature enabled: firstPublishedAt on ${schema.collectionName}`);
|
|
67
|
+
schema.attributes[FIRST_PUBLISHED_AT_ATTRIBUTE] = {
|
|
68
|
+
type: 'datetime',
|
|
69
|
+
configurable: false,
|
|
70
|
+
writable: true,
|
|
71
|
+
visible: false,
|
|
72
|
+
private: !isEnabled
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
};
|
|
60
76
|
const addCreatorFields = (schema)=>{
|
|
61
77
|
const isPrivate = !_.get(schema, 'options.populateCreatorFields', false);
|
|
62
78
|
schema.attributes[CREATED_BY_ATTRIBUTE] = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../../src/domain/content-type/index.ts"],"sourcesContent":["import { cloneDeep } from 'lodash/fp';\nimport _ from 'lodash';\nimport { yup, contentTypes as contentTypesUtils } from '@strapi/utils';\nimport type { Schema } from '@strapi/types';\nimport { validateContentTypeDefinition } from './validator';\n\nexport type ContentTypeDefinition = {\n schema: Schema.ContentType;\n actions: Record<string, unknown>;\n lifecycles: Record<string, unknown>;\n};\n\nconst {\n CREATED_AT_ATTRIBUTE,\n UPDATED_AT_ATTRIBUTE,\n PUBLISHED_AT_ATTRIBUTE,\n CREATED_BY_ATTRIBUTE,\n UPDATED_BY_ATTRIBUTE,\n} = contentTypesUtils.constants;\n\nconst createContentType = (uid: string, definition: ContentTypeDefinition) => {\n try {\n validateContentTypeDefinition(definition);\n } catch (e) {\n if (e instanceof yup.ValidationError) {\n throw new Error(`Content Type Definition is invalid for ${uid}'.\\n${e.errors}`);\n }\n\n throw e;\n }\n\n const { schema, actions, lifecycles } = cloneDeep(definition);\n\n // general info\n Object.assign(schema, {\n uid,\n modelType: 'contentType',\n kind: schema.kind || 'collectionType',\n __schema__: pickSchema(definition.schema),\n modelName: definition.schema.info.singularName,\n actions,\n lifecycles,\n });\n\n addTimestamps(schema);\n\n // Published at is added regardless of draft and publish being enabled\n // In case it is not enabled, value will be always published, and it will not contain a draft\n addDraftAndPublish(schema);\n\n addCreatorFields(schema);\n\n return schema;\n};\n\nconst addTimestamps = (schema: Schema.ContentType) => {\n // attributes\n Object.assign(schema.attributes, {\n [CREATED_AT_ATTRIBUTE]: {\n type: 'datetime',\n },\n // TODO: handle on edit set to new date\n [UPDATED_AT_ATTRIBUTE]: {\n type: 'datetime',\n },\n });\n};\n\nconst addDraftAndPublish = (schema: Schema.ContentType) => {\n if (!_.has(schema, 'options.draftAndPublish')) {\n _.set(schema, 'options.draftAndPublish', false); // Disabled by default\n }\n\n schema.attributes[PUBLISHED_AT_ATTRIBUTE] = {\n type: 'datetime',\n configurable: false,\n writable: true,\n visible: false,\n default() {\n return new Date();\n },\n };\n};\n\nconst addCreatorFields = (schema: Schema.ContentType) => {\n const isPrivate = !_.get(schema, 'options.populateCreatorFields', false);\n\n schema.attributes[CREATED_BY_ATTRIBUTE] = {\n type: 'relation',\n relation: 'oneToOne',\n target: 'admin::user',\n configurable: false,\n writable: false,\n visible: false,\n useJoinTable: false,\n private: isPrivate,\n };\n\n schema.attributes[UPDATED_BY_ATTRIBUTE] = {\n type: 'relation',\n relation: 'oneToOne',\n target: 'admin::user',\n configurable: false,\n writable: false,\n visible: false,\n useJoinTable: false,\n private: isPrivate,\n };\n};\n\nconst getGlobalId = (schema: Schema.ContentType, prefix?: string) => {\n const modelName = schema.info.singularName;\n const globalId = prefix ? `${prefix}-${modelName}` : modelName;\n\n return schema.globalId || _.upperFirst(_.camelCase(globalId));\n};\n\nconst pickSchema = (model: Schema.ContentType) => {\n const schema = _.cloneDeep(\n _.pick(model, [\n 'connection',\n 'collectionName',\n 'info',\n 'options',\n 'pluginOptions',\n 'attributes',\n 'kind',\n ])\n );\n\n schema.kind = model.kind || 'collectionType';\n return schema;\n};\n\nexport { createContentType, getGlobalId };\n"],"names":["CREATED_AT_ATTRIBUTE","UPDATED_AT_ATTRIBUTE","PUBLISHED_AT_ATTRIBUTE","CREATED_BY_ATTRIBUTE","UPDATED_BY_ATTRIBUTE","contentTypesUtils","constants","createContentType","uid","definition","validateContentTypeDefinition","e","yup","ValidationError","Error","errors","schema","actions","lifecycles","cloneDeep","Object","assign","modelType","kind","__schema__","pickSchema","modelName","info","singularName","addTimestamps","addDraftAndPublish","addCreatorFields","attributes","type","_","has","set","configurable","writable","visible","default","Date","isPrivate","get","relation","target","useJoinTable","
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../src/domain/content-type/index.ts"],"sourcesContent":["import { cloneDeep } from 'lodash/fp';\nimport _ from 'lodash';\nimport { yup, contentTypes as contentTypesUtils } from '@strapi/utils';\nimport type { Schema } from '@strapi/types';\nimport { validateContentTypeDefinition } from './validator';\n\nexport type ContentTypeDefinition = {\n schema: Schema.ContentType;\n actions: Record<string, unknown>;\n lifecycles: Record<string, unknown>;\n};\n\nconst {\n CREATED_AT_ATTRIBUTE,\n UPDATED_AT_ATTRIBUTE,\n PUBLISHED_AT_ATTRIBUTE,\n FIRST_PUBLISHED_AT_ATTRIBUTE,\n CREATED_BY_ATTRIBUTE,\n UPDATED_BY_ATTRIBUTE,\n} = contentTypesUtils.constants;\n\nconst createContentType = (uid: string, definition: ContentTypeDefinition) => {\n try {\n validateContentTypeDefinition(definition);\n } catch (e) {\n if (e instanceof yup.ValidationError) {\n throw new Error(`Content Type Definition is invalid for ${uid}'.\\n${e.errors}`);\n }\n\n throw e;\n }\n\n const { schema, actions, lifecycles } = cloneDeep(definition);\n\n // general info\n Object.assign(schema, {\n uid,\n modelType: 'contentType',\n kind: schema.kind || 'collectionType',\n __schema__: pickSchema(definition.schema),\n modelName: definition.schema.info.singularName,\n actions,\n lifecycles,\n });\n\n addTimestamps(schema);\n\n // Published at is added regardless of draft and publish being enabled\n // In case it is not enabled, value will be always published, and it will not contain a draft\n addDraftAndPublish(schema);\n\n addCreatorFields(schema);\n\n addFirstPublishedAt(schema);\n\n return schema;\n};\n\nconst addTimestamps = (schema: Schema.ContentType) => {\n // attributes\n Object.assign(schema.attributes, {\n [CREATED_AT_ATTRIBUTE]: {\n type: 'datetime',\n },\n // TODO: handle on edit set to new date\n [UPDATED_AT_ATTRIBUTE]: {\n type: 'datetime',\n },\n });\n};\n\nconst addDraftAndPublish = (schema: Schema.ContentType) => {\n if (!_.has(schema, 'options.draftAndPublish')) {\n _.set(schema, 'options.draftAndPublish', false); // Disabled by default\n }\n\n schema.attributes[PUBLISHED_AT_ATTRIBUTE] = {\n type: 'datetime',\n configurable: false,\n writable: true,\n visible: false,\n default() {\n return new Date();\n },\n };\n};\n\nconst addFirstPublishedAt = (schema: Schema.ContentType) => {\n const isEnabled = contentTypesUtils.hasFirstPublishedAtField(schema);\n\n // Note: As an expertimental feature, we are okay if this data is deleted if this feature is\n // switched off. Once \"preserve_attributes\" come into play, this will be updated.\n if (isEnabled) {\n strapi.log.warn(`Experimental feature enabled: firstPublishedAt on ${schema.collectionName}`);\n schema.attributes[FIRST_PUBLISHED_AT_ATTRIBUTE] = {\n type: 'datetime',\n configurable: false,\n writable: true,\n visible: false,\n private: !isEnabled,\n };\n }\n};\n\nconst addCreatorFields = (schema: Schema.ContentType) => {\n const isPrivate = !_.get(schema, 'options.populateCreatorFields', false);\n\n schema.attributes[CREATED_BY_ATTRIBUTE] = {\n type: 'relation',\n relation: 'oneToOne',\n target: 'admin::user',\n configurable: false,\n writable: false,\n visible: false,\n useJoinTable: false,\n private: isPrivate,\n };\n\n schema.attributes[UPDATED_BY_ATTRIBUTE] = {\n type: 'relation',\n relation: 'oneToOne',\n target: 'admin::user',\n configurable: false,\n writable: false,\n visible: false,\n useJoinTable: false,\n private: isPrivate,\n };\n};\n\nconst getGlobalId = (schema: Schema.ContentType, prefix?: string) => {\n const modelName = schema.info.singularName;\n const globalId = prefix ? `${prefix}-${modelName}` : modelName;\n\n return schema.globalId || _.upperFirst(_.camelCase(globalId));\n};\n\nconst pickSchema = (model: Schema.ContentType) => {\n const schema = _.cloneDeep(\n _.pick(model, [\n 'connection',\n 'collectionName',\n 'info',\n 'options',\n 'pluginOptions',\n 'attributes',\n 'kind',\n ])\n );\n\n schema.kind = model.kind || 'collectionType';\n return schema;\n};\n\nexport { createContentType, getGlobalId };\n"],"names":["CREATED_AT_ATTRIBUTE","UPDATED_AT_ATTRIBUTE","PUBLISHED_AT_ATTRIBUTE","FIRST_PUBLISHED_AT_ATTRIBUTE","CREATED_BY_ATTRIBUTE","UPDATED_BY_ATTRIBUTE","contentTypesUtils","constants","createContentType","uid","definition","validateContentTypeDefinition","e","yup","ValidationError","Error","errors","schema","actions","lifecycles","cloneDeep","Object","assign","modelType","kind","__schema__","pickSchema","modelName","info","singularName","addTimestamps","addDraftAndPublish","addCreatorFields","addFirstPublishedAt","attributes","type","_","has","set","configurable","writable","visible","default","Date","isEnabled","hasFirstPublishedAtField","strapi","log","warn","collectionName","private","isPrivate","get","relation","target","useJoinTable","getGlobalId","prefix","globalId","upperFirst","camelCase","model","pick"],"mappings":";;;;;AAYA,MAAM,EACJA,oBAAoB,EACpBC,oBAAoB,EACpBC,sBAAsB,EACtBC,4BAA4B,EAC5BC,oBAAoB,EACpBC,oBAAoB,EACrB,GAAGC,aAAkBC,SAAS;AAEzBC,MAAAA,iBAAAA,GAAoB,CAACC,GAAaC,EAAAA,UAAAA,GAAAA;IACtC,IAAI;QACFC,6BAA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AAC,CAAC;IAC1D,WAAW,EAAE,CAAC,MAAM,EAAE,GAAG,CAAC,WAAW,KAAK,MAAM,CAAC,iBAAiB,CAAC;IACnE,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,iBAAiB,CAAC,CAAC;IACvD,OAAO,EAAE,CAAC,WAAW,EAAE,GAAG,CAAC,OAAO,KAAK,IAAI,CAAC,OAAO,CAAC;IACpD,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IACvC,MAAM,EAAE,CAAC,UAAU,EAAE,GAAG,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM,CAAC;IAChD,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IACtC,UAAU,EAAE,CAAC,cAAc,EAAE,GAAG,CAAC,UAAU,KAAK,IAAI,CAAC,UAAU,CAAC;IAChE,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IAC7C,UAAU,EAAE,CAAC,cAAc,EAAE,GAAG,CAAC,UAAU,KAAK,IAAI,CAAC,UAAU,CAAC;IAChE,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;CAC9C;AAiBD,eAAO,MAAM,YAAY,cACZ,MAAM,aACN,SAAS,UACZ,KAAK,MAAM,KAClB,MAwFF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/domain/module/index.ts"],"sourcesContent":["import _, { type PropertyPath, flatten } from 'lodash';\nimport { yup } from '@strapi/utils';\nimport type { Core, UID, Struct } from '@strapi/types';\n\nimport { removeNamespace } from '../../registries/namespace';\nimport { validateModule } from './validation';\n\ninterface LifecyclesState {\n bootstrap?: boolean;\n register?: boolean;\n destroy?: boolean;\n}\n\nexport interface RawModule {\n config?: Record<string, unknown>;\n routes?: Core.Module['routes'];\n controllers?: Core.Module['controllers'];\n services?: Core.Module['services'];\n contentTypes?: Core.Module['contentTypes'];\n policies?: Core.Module['policies'];\n middlewares?: Core.Module['middlewares'];\n bootstrap?: (params: { strapi: Core.Strapi }) => Promise<void>;\n register?: (params: { strapi: Core.Strapi }) => Promise<void>;\n destroy?: (params: { strapi: Core.Strapi }) => Promise<void>;\n}\n\nexport interface Module {\n bootstrap: () => Promise<void>;\n register: () => Promise<void>;\n destroy: () => Promise<void>;\n load: () => void;\n routes: Core.Module['routes'];\n config<T = unknown>(key: PropertyPath, defaultVal?: T): T; // TODO: this mirrors ConfigProvider.get, we should use it directly\n contentType: (ctName: UID.ContentType) => Struct.ContentTypeSchema;\n contentTypes: Record<string, Struct.ContentTypeSchema>;\n service: (serviceName: UID.Service) => Core.Service;\n services: Record<string, Core.Service>;\n policy: (policyName: UID.Policy) => Core.Policy;\n policies: Record<string, Core.Policy>;\n middleware: (middlewareName: UID.Middleware) => Core.Middleware;\n middlewares: Record<string, Core.Middleware>;\n controller: (controllerName: UID.Controller) => Core.Controller;\n controllers: Record<string, Core.Controller>;\n}\n\n// Removes the namespace from a map with keys prefixed with a namespace\nconst removeNamespacedKeys = <T extends Record<string, unknown>>(map: T, namespace: string) => {\n return _.mapKeys(map, (value, key) => removeNamespace(key, namespace));\n};\n\nconst defaultModule = {\n config: {},\n routes: [],\n controllers: {},\n services: {},\n contentTypes: {},\n policies: {},\n middlewares: {},\n};\n\nexport const createModule = (\n namespace: string,\n rawModule: RawModule,\n strapi: Core.Strapi\n): Module => {\n _.defaults(rawModule, defaultModule);\n\n try {\n validateModule(rawModule);\n } catch (e) {\n if (e instanceof yup.ValidationError) {\n throw new Error(`strapi-server.js is invalid for '${namespace}'.\\n${e.errors.join('\\n')}`);\n }\n }\n\n const called: LifecyclesState = {};\n return {\n async bootstrap() {\n if (called.bootstrap) {\n throw new Error(`Bootstrap for ${namespace} has already been called`);\n }\n called.bootstrap = true;\n await (rawModule.bootstrap && rawModule.bootstrap({ strapi }));\n },\n async register() {\n if (called.register) {\n throw new Error(`Register for ${namespace} has already been called`);\n }\n called.register = true;\n await (rawModule.register && rawModule.register({ strapi }));\n },\n async destroy() {\n if (called.destroy) {\n throw new Error(`Destroy for ${namespace} has already been called`);\n }\n called.destroy = true;\n await (rawModule.destroy && rawModule.destroy({ strapi }));\n },\n load() {\n strapi.get('content-types').add(namespace, rawModule.contentTypes);\n strapi.get('services').add(namespace, rawModule.services);\n strapi.get('policies').add(namespace, rawModule.policies);\n strapi.get('middlewares').add(namespace, rawModule.middlewares);\n strapi.get('controllers').add(namespace, rawModule.controllers);\n strapi.get('config').set(namespace, rawModule.config);\n },\n get routes() {\n return rawModule.routes ?? {};\n },\n config(path: PropertyPath, defaultValue: unknown) {\n const pathArray = flatten([namespace, path]);\n return strapi.get('config').get(pathArray, defaultValue);\n },\n contentType(ctName: UID.ContentType) {\n return strapi.get('content-types').get(`${namespace}.${ctName}`);\n },\n get contentTypes() {\n const contentTypes = strapi.get('content-types').getAll(namespace);\n return removeNamespacedKeys(contentTypes, namespace);\n },\n service(serviceName: UID.Service) {\n return strapi.get('services').get(`${namespace}.${serviceName}`);\n },\n get services() {\n const services = strapi.get('services').getAll(namespace);\n return removeNamespacedKeys(services, namespace);\n },\n policy(policyName: UID.Policy) {\n return strapi.get('policies').get(`${namespace}.${policyName}`);\n },\n get policies() {\n const policies = strapi.get('policies').getAll(namespace);\n return removeNamespacedKeys(policies, namespace);\n },\n middleware(middlewareName: UID.Middleware) {\n return strapi.get('middlewares').get(`${namespace}.${middlewareName}`);\n },\n get middlewares() {\n const middlewares = strapi.get('middlewares').getAll(namespace);\n return removeNamespacedKeys(middlewares, namespace);\n },\n controller(controllerName: UID.Controller) {\n return strapi.get('controllers').get(`${namespace}.${controllerName}`);\n },\n get controllers() {\n const controllers = strapi.get('controllers').getAll(namespace);\n return removeNamespacedKeys(controllers, namespace);\n },\n };\n};\n"],"names":["removeNamespacedKeys","map","namespace","_","mapKeys","value","key","removeNamespace","defaultModule","config","routes","controllers","services","contentTypes","policies","middlewares","createModule","rawModule","strapi","defaults","validateModule","e","yup","ValidationError","Error","errors","join","called","bootstrap","register","destroy","load","get","add","set","path","defaultValue","pathArray","flatten","contentType","ctName","getAll","service","serviceName","policy","policyName","middleware","middlewareName","controller","controllerName"],"mappings":";;;;;;;AA6CA;AACA,MAAMA,oBAAAA,GAAuB,CAAoCC,GAAQC,EAAAA,WAAAA,GAAAA;IACvE,OAAOC,CAAAA,CAAEC,OAAO,CAACH,GAAAA,EAAK,CAACI,KAAOC,EAAAA,GAAAA,GAAQC,0BAAgBD,GAAKJ,EAAAA,WAAAA,CAAAA,CAAAA;AAC7D,CAAA;AAEA,MAAMM,aAAgB,GAAA;AACpBC,IAAAA,MAAAA,EAAQ,EAAC;AACTC,IAAAA,MAAAA,EAAQ,EAAE;AACVC,IAAAA,WAAAA,EAAa,EAAC;AACdC,IAAAA,QAAAA,EAAU,EAAC;AACXC,IAAAA,YAAAA,EAAc,EAAC;AACfC,IAAAA,QAAAA,EAAU,EAAC;AACXC,IAAAA,WAAAA,EAAa;AACf,CAAA;AAEaC,MAAAA,YAAAA,GAAe,CAC1Bd,SAAAA,EACAe,SACAC,EAAAA,MAAAA,GAAAA;IAEAf,CAAEgB,CAAAA,QAAQ,CAACF,SAAWT,EAAAA,aAAAA,CAAAA;IAEtB,IAAI;QACFY,yBAAeH,CAAAA,SAAAA,CAAAA;AACjB,KAAA,CAAE,OAAOI,CAAG,EAAA;QACV,IAAIA,CAAAA,YAAaC,eAAIC,CAAAA,eAAe,EAAE;AACpC,YAAA,MAAM,IAAIC,KAAAA,CAAM,CAAC,iCAAiC,EAAEtB,SAAU,CAAA,IAAI,EAAEmB,CAAAA,CAAEI,MAAM,CAACC,IAAI,CAAC,MAAM,CAAC,CAAA;AAC3F;AACF;AAEA,IAAA,MAAMC,SAA0B,EAAC;IACjC,OAAO;QACL,MAAMC,SAAAA,CAAAA,GAAAA;YACJ,IAAID,MAAAA,CAAOC,SAAS,EAA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A,UAAAA,CAAAA,CAAWC,cAA8B,EAAA;AACvC,YAAA,OAAO/B,MAAOc,CAAAA,GAAG,CAAC,aAAA,CAAA,CAAeA,GAAG,CAAC,CAAC,EAAE9B,SAAU,CAAA,CAAC,EAAE+C,cAAAA,CAAe,CAAC,CAAA;AACvE,SAAA;AACA,QAAA,IAAItC,WAAc,CAAA,GAAA;AAChB,YAAA,MAAMA,cAAcO,MAAOc,CAAAA,GAAG,CAAC,aAAA,CAAA,CAAeS,MAAM,CAACvC,SAAAA,CAAAA;AACrD,YAAA,OAAOF,qBAAqBW,WAAaT,EAAAA,SAAAA,CAAAA;AAC3C;AACF,KAAA;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/domain/module/index.ts"],"sourcesContent":["import _, { type PropertyPath, flatten } from 'lodash';\nimport { yup } from '@strapi/utils';\nimport type { Core, UID, Struct } from '@strapi/types';\n\nimport { removeNamespace } from '../../registries/namespace';\nimport { validateModule } from './validation';\n\ninterface LifecyclesState {\n bootstrap?: boolean;\n register?: boolean;\n destroy?: boolean;\n}\n\nexport interface RawModule {\n config?: Record<string, unknown>;\n routes?: Core.Module['routes'];\n controllers?: Core.Module['controllers'];\n services?: Core.Module['services'];\n contentTypes?: Core.Module['contentTypes'];\n policies?: Core.Module['policies'];\n middlewares?: Core.Module['middlewares'];\n bootstrap?: (params: { strapi: Core.Strapi }) => Promise<void>;\n register?: (params: { strapi: Core.Strapi }) => Promise<void>;\n destroy?: (params: { strapi: Core.Strapi }) => Promise<void>;\n}\n\nexport interface Module {\n bootstrap: () => Promise<void>;\n register: () => Promise<void>;\n destroy: () => Promise<void>;\n load: () => void;\n routes: Core.Module['routes'];\n config<T = unknown>(key: PropertyPath, defaultVal?: T): T; // TODO: this mirrors ConfigProvider.get, we should use it directly\n contentType: (ctName: UID.ContentType) => Struct.ContentTypeSchema;\n contentTypes: Record<string, Struct.ContentTypeSchema>;\n service: (serviceName: UID.Service) => Core.Service;\n services: Record<string, Core.Service>;\n policy: (policyName: UID.Policy) => Core.Policy;\n policies: Record<string, Core.Policy>;\n middleware: (middlewareName: UID.Middleware) => Core.Middleware;\n middlewares: Record<string, Core.Middleware>;\n controller: (controllerName: UID.Controller) => Core.Controller;\n controllers: Record<string, Core.Controller>;\n}\n\n// Removes the namespace from a map with keys prefixed with a namespace\nconst removeNamespacedKeys = <T extends Record<string, unknown>>(map: T, namespace: string) => {\n return _.mapKeys(map, (value, key) => removeNamespace(key, namespace));\n};\n\nconst defaultModule = {\n config: {},\n routes: [],\n controllers: {},\n services: {},\n contentTypes: {},\n policies: {},\n middlewares: {},\n};\n\nexport const createModule = (\n namespace: string,\n rawModule: RawModule,\n strapi: Core.Strapi\n): Module => {\n _.defaults(rawModule, defaultModule);\n\n try {\n validateModule(rawModule);\n } catch (e) {\n if (e instanceof yup.ValidationError) {\n throw new Error(`strapi-server.js is invalid for '${namespace}'.\\n${e.errors.join('\\n')}`);\n }\n }\n\n const called: LifecyclesState = {};\n return {\n async bootstrap() {\n if (called.bootstrap) {\n throw new Error(`Bootstrap for ${namespace} has already been called`);\n }\n called.bootstrap = true;\n await (rawModule.bootstrap && rawModule.bootstrap({ strapi }));\n },\n async register() {\n if (called.register) {\n throw new Error(`Register for ${namespace} has already been called`);\n }\n called.register = true;\n await (rawModule.register && rawModule.register({ strapi }));\n },\n async destroy() {\n if (called.destroy) {\n throw new Error(`Destroy for ${namespace} has already been called`);\n }\n called.destroy = true;\n await (rawModule.destroy && rawModule.destroy({ strapi }));\n },\n load() {\n strapi.get('content-types').add(namespace, rawModule.contentTypes);\n strapi.get('services').add(namespace, rawModule.services);\n strapi.get('policies').add(namespace, rawModule.policies);\n strapi.get('middlewares').add(namespace, rawModule.middlewares);\n strapi.get('controllers').add(namespace, rawModule.controllers);\n strapi.get('config').set(namespace, rawModule.config);\n },\n get routes() {\n return rawModule.routes ?? {};\n },\n set routes(routes: Record<string, Core.Router>) {\n rawModule.routes = routes;\n },\n config(path: PropertyPath, defaultValue: unknown) {\n const pathArray = flatten([namespace, path]);\n return strapi.get('config').get(pathArray, defaultValue);\n },\n contentType(ctName: UID.ContentType) {\n return strapi.get('content-types').get(`${namespace}.${ctName}`);\n },\n get contentTypes() {\n const contentTypes = strapi.get('content-types').getAll(namespace);\n return removeNamespacedKeys(contentTypes, namespace);\n },\n service(serviceName: UID.Service) {\n return strapi.get('services').get(`${namespace}.${serviceName}`);\n },\n get services() {\n const services = strapi.get('services').getAll(namespace);\n return removeNamespacedKeys(services, namespace);\n },\n policy(policyName: UID.Policy) {\n return strapi.get('policies').get(`${namespace}.${policyName}`);\n },\n get policies() {\n const policies = strapi.get('policies').getAll(namespace);\n return removeNamespacedKeys(policies, namespace);\n },\n middleware(middlewareName: UID.Middleware) {\n return strapi.get('middlewares').get(`${namespace}.${middlewareName}`);\n },\n get middlewares() {\n const middlewares = strapi.get('middlewares').getAll(namespace);\n return removeNamespacedKeys(middlewares, namespace);\n },\n controller(controllerName: UID.Controller) {\n return strapi.get('controllers').get(`${namespace}.${controllerName}`);\n },\n get controllers() {\n const controllers = strapi.get('controllers').getAll(namespace);\n return removeNamespacedKeys(controllers, namespace);\n },\n };\n};\n"],"names":["removeNamespacedKeys","map","namespace","_","mapKeys","value","key","removeNamespace","defaultModule","config","routes","controllers","services","contentTypes","policies","middlewares","createModule","rawModule","strapi","defaults","validateModule","e","yup","ValidationError","Error","errors","join","called","bootstrap","register","destroy","load","get","add","set","path","defaultValue","pathArray","flatten","contentType","ctName","getAll","service","serviceName","policy","policyName","middleware","middlewareName","controller","controllerName"],"mappings":";;;;;;;AA6CA;AACA,MAAMA,oBAAAA,GAAuB,CAAoCC,GAAQC,EAAAA,WAAAA,GAAAA;IACvE,OAAOC,CAAAA,CAAEC,OAAO,CAACH,GAAAA,EAAK,CAACI,KAAOC,EAAAA,GAAAA,GAAQC,0BAAgBD,GAAKJ,EAAAA,WAAAA,CAAAA,CAAAA;AAC7D,CAAA;AAEA,MAAMM,aAAgB,GAAA;AACpBC,IAAAA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