@strapi/core 0.0.0-experimental.94632b9dc1ff6c9600db6db51cd6dd2d693f5204 → 0.0.0-experimental.9612538209f3c68285c5dea8fe26f96e7e470afd
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 +49 -58
- package/dist/Strapi.d.ts.map +1 -1
- package/dist/Strapi.js +190 -218
- package/dist/Strapi.js.map +1 -1
- package/dist/Strapi.mjs +161 -209
- package/dist/Strapi.mjs.map +1 -1
- package/dist/configuration/config-loader.d.ts.map +1 -1
- package/dist/configuration/config-loader.js +9 -5
- package/dist/configuration/config-loader.js.map +1 -1
- package/dist/configuration/config-loader.mjs +9 -5
- package/dist/configuration/config-loader.mjs.map +1 -1
- package/dist/configuration/get-dirs.d.ts +10 -0
- package/dist/configuration/get-dirs.d.ts.map +1 -0
- package/dist/{utils → configuration}/get-dirs.js +3 -2
- package/dist/configuration/get-dirs.js.map +1 -0
- package/dist/{utils → configuration}/get-dirs.mjs +3 -2
- package/dist/configuration/get-dirs.mjs.map +1 -0
- package/dist/configuration/index.d.ts +4 -7
- package/dist/configuration/index.d.ts.map +1 -1
- package/dist/configuration/index.js +6 -4
- package/dist/configuration/index.js.map +1 -1
- package/dist/configuration/index.mjs +5 -4
- package/dist/configuration/index.mjs.map +1 -1
- package/dist/container.d.ts +2 -2
- package/dist/container.d.ts.map +1 -1
- package/dist/container.js.map +1 -1
- package/dist/container.mjs.map +1 -1
- package/dist/core-api/controller/collection-type.d.ts +3 -3
- package/dist/core-api/controller/collection-type.d.ts.map +1 -1
- package/dist/core-api/controller/collection-type.js +3 -0
- package/dist/core-api/controller/collection-type.js.map +1 -1
- package/dist/core-api/controller/collection-type.mjs +3 -0
- package/dist/core-api/controller/collection-type.mjs.map +1 -1
- package/dist/core-api/controller/index.d.ts +3 -3
- package/dist/core-api/controller/index.d.ts.map +1 -1
- package/dist/core-api/controller/index.js +5 -5
- package/dist/core-api/controller/index.js.map +1 -1
- package/dist/core-api/controller/index.mjs +6 -6
- package/dist/core-api/controller/index.mjs.map +1 -1
- package/dist/core-api/controller/single-type.d.ts +3 -3
- package/dist/core-api/controller/single-type.d.ts.map +1 -1
- package/dist/core-api/controller/single-type.js +1 -0
- package/dist/core-api/controller/single-type.js.map +1 -1
- package/dist/core-api/controller/single-type.mjs +1 -0
- package/dist/core-api/controller/single-type.mjs.map +1 -1
- package/dist/core-api/controller/transform.d.ts +2 -2
- package/dist/core-api/controller/transform.d.ts.map +1 -1
- package/dist/core-api/controller/transform.js +2 -5
- package/dist/core-api/controller/transform.js.map +1 -1
- package/dist/core-api/controller/transform.mjs +2 -5
- package/dist/core-api/controller/transform.mjs.map +1 -1
- package/dist/core-api/routes/index.d.ts.map +1 -1
- package/dist/core-api/service/collection-type.d.ts +11 -17
- package/dist/core-api/service/collection-type.d.ts.map +1 -1
- package/dist/core-api/service/collection-type.js +18 -7
- package/dist/core-api/service/collection-type.js.map +1 -1
- package/dist/core-api/service/collection-type.mjs +19 -8
- package/dist/core-api/service/collection-type.mjs.map +1 -1
- package/dist/core-api/service/index.d.ts +3 -3
- package/dist/core-api/service/index.d.ts.map +1 -1
- package/dist/core-api/service/index.js.map +1 -1
- package/dist/core-api/service/index.mjs.map +1 -1
- package/dist/core-api/service/pagination.d.ts +4 -11
- package/dist/core-api/service/pagination.d.ts.map +1 -1
- package/dist/core-api/service/pagination.js +14 -40
- package/dist/core-api/service/pagination.js.map +1 -1
- package/dist/core-api/service/pagination.mjs +16 -42
- package/dist/core-api/service/pagination.mjs.map +1 -1
- package/dist/core-api/service/single-type.d.ts +4 -4
- package/dist/core-api/service/single-type.d.ts.map +1 -1
- package/dist/core-api/service/single-type.js +9 -2
- package/dist/core-api/service/single-type.js.map +1 -1
- package/dist/core-api/service/single-type.mjs +9 -2
- package/dist/core-api/service/single-type.mjs.map +1 -1
- package/dist/domain/content-type/index.d.ts +1 -1
- package/dist/domain/content-type/index.d.ts.map +1 -1
- package/dist/domain/module/index.d.ts +24 -23
- package/dist/domain/module/index.d.ts.map +1 -1
- package/dist/domain/module/index.js +2 -1
- package/dist/domain/module/index.js.map +1 -1
- package/dist/domain/module/index.mjs +3 -2
- package/dist/domain/module/index.mjs.map +1 -1
- package/dist/ee/index.d.ts +4 -2
- package/dist/ee/index.d.ts.map +1 -1
- package/dist/ee/index.js.map +1 -1
- package/dist/ee/index.mjs.map +1 -1
- package/dist/ee/license.d.ts +2 -2
- package/dist/ee/license.d.ts.map +1 -1
- package/dist/ee/license.js +2 -1
- package/dist/ee/license.js.map +1 -1
- package/dist/ee/license.mjs +2 -1
- package/dist/ee/license.mjs.map +1 -1
- package/dist/factories.d.ts +10 -10
- package/dist/factories.d.ts.map +1 -1
- package/dist/factories.js +6 -2
- package/dist/factories.js.map +1 -1
- package/dist/factories.mjs +6 -2
- package/dist/factories.mjs.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +27 -3
- package/dist/index.mjs.map +1 -1
- package/dist/loaders/admin.d.ts +2 -2
- package/dist/loaders/admin.d.ts.map +1 -1
- package/dist/loaders/admin.js +0 -1
- package/dist/loaders/admin.js.map +1 -1
- package/dist/loaders/admin.mjs +0 -1
- package/dist/loaders/admin.mjs.map +1 -1
- package/dist/loaders/apis.d.ts +2 -2
- package/dist/loaders/apis.d.ts.map +1 -1
- package/dist/loaders/apis.js +10 -10
- package/dist/loaders/apis.js.map +1 -1
- package/dist/loaders/apis.mjs +10 -10
- package/dist/loaders/apis.mjs.map +1 -1
- package/dist/loaders/components.d.ts +2 -2
- package/dist/loaders/components.d.ts.map +1 -1
- package/dist/loaders/components.js.map +1 -1
- package/dist/loaders/components.mjs.map +1 -1
- package/dist/loaders/index.d.ts +2 -2
- package/dist/loaders/index.d.ts.map +1 -1
- package/dist/loaders/index.js +0 -2
- package/dist/loaders/index.js.map +1 -1
- package/dist/loaders/index.mjs +0 -2
- package/dist/loaders/index.mjs.map +1 -1
- package/dist/loaders/middlewares.d.ts +2 -2
- package/dist/loaders/middlewares.d.ts.map +1 -1
- package/dist/loaders/middlewares.js.map +1 -1
- package/dist/loaders/middlewares.mjs.map +1 -1
- package/dist/loaders/plugins/get-enabled-plugins.d.ts +2 -2
- package/dist/loaders/plugins/get-enabled-plugins.d.ts.map +1 -1
- package/dist/loaders/plugins/get-enabled-plugins.js +7 -5
- package/dist/loaders/plugins/get-enabled-plugins.js.map +1 -1
- package/dist/loaders/plugins/get-enabled-plugins.mjs +7 -5
- package/dist/loaders/plugins/get-enabled-plugins.mjs.map +1 -1
- package/dist/loaders/plugins/index.d.ts +2 -2
- package/dist/loaders/plugins/index.d.ts.map +1 -1
- package/dist/loaders/plugins/index.js.map +1 -1
- package/dist/loaders/plugins/index.mjs.map +1 -1
- package/dist/loaders/policies.d.ts +2 -2
- package/dist/loaders/policies.d.ts.map +1 -1
- package/dist/loaders/policies.js.map +1 -1
- package/dist/loaders/policies.mjs.map +1 -1
- package/dist/loaders/sanitizers.d.ts +2 -2
- package/dist/loaders/sanitizers.d.ts.map +1 -1
- package/dist/loaders/sanitizers.js.map +1 -1
- package/dist/loaders/sanitizers.mjs.map +1 -1
- package/dist/loaders/src-index.d.ts +2 -2
- package/dist/loaders/src-index.d.ts.map +1 -1
- package/dist/loaders/src-index.js.map +1 -1
- package/dist/loaders/src-index.mjs.map +1 -1
- package/dist/loaders/validators.d.ts +2 -2
- package/dist/loaders/validators.d.ts.map +1 -1
- package/dist/loaders/validators.js.map +1 -1
- package/dist/loaders/validators.mjs.map +1 -1
- package/dist/middlewares/body.d.ts +4 -4
- package/dist/middlewares/body.d.ts.map +1 -1
- package/dist/middlewares/body.js +4 -4
- package/dist/middlewares/body.js.map +1 -1
- package/dist/middlewares/body.mjs +4 -4
- package/dist/middlewares/body.mjs.map +1 -1
- package/dist/middlewares/compression.d.ts +2 -2
- package/dist/middlewares/compression.d.ts.map +1 -1
- package/dist/middlewares/compression.js.map +1 -1
- package/dist/middlewares/compression.mjs.map +1 -1
- package/dist/middlewares/cors.d.ts +2 -2
- package/dist/middlewares/cors.d.ts.map +1 -1
- package/dist/middlewares/cors.js +6 -8
- package/dist/middlewares/cors.js.map +1 -1
- package/dist/middlewares/cors.mjs +6 -8
- package/dist/middlewares/cors.mjs.map +1 -1
- package/dist/middlewares/errors.d.ts +2 -2
- package/dist/middlewares/errors.d.ts.map +1 -1
- package/dist/middlewares/errors.js.map +1 -1
- package/dist/middlewares/errors.mjs.map +1 -1
- package/dist/middlewares/favicon.d.ts +2 -2
- package/dist/middlewares/favicon.d.ts.map +1 -1
- package/dist/middlewares/favicon.js.map +1 -1
- package/dist/middlewares/favicon.mjs.map +1 -1
- package/dist/middlewares/index.d.ts +2 -2
- package/dist/middlewares/index.d.ts.map +1 -1
- package/dist/middlewares/index.js.map +1 -1
- package/dist/middlewares/index.mjs.map +1 -1
- package/dist/middlewares/ip.d.ts +2 -2
- package/dist/middlewares/ip.d.ts.map +1 -1
- package/dist/middlewares/ip.js.map +1 -1
- package/dist/middlewares/ip.mjs.map +1 -1
- package/dist/middlewares/logger.d.ts +2 -2
- package/dist/middlewares/logger.d.ts.map +1 -1
- package/dist/middlewares/logger.js.map +1 -1
- package/dist/middlewares/logger.mjs.map +1 -1
- package/dist/middlewares/powered-by.d.ts +2 -2
- package/dist/middlewares/powered-by.d.ts.map +1 -1
- package/dist/middlewares/powered-by.js.map +1 -1
- package/dist/middlewares/powered-by.mjs.map +1 -1
- package/dist/middlewares/public.d.ts +2 -2
- package/dist/middlewares/public.d.ts.map +1 -1
- package/dist/middlewares/public.js +1 -1
- package/dist/middlewares/public.js.map +1 -1
- package/dist/middlewares/public.mjs +1 -1
- package/dist/middlewares/public.mjs.map +1 -1
- package/dist/middlewares/query.d.ts +2 -2
- package/dist/middlewares/query.d.ts.map +1 -1
- package/dist/middlewares/query.js.map +1 -1
- package/dist/middlewares/query.mjs.map +1 -1
- package/dist/middlewares/response-time.d.ts +2 -2
- package/dist/middlewares/response-time.d.ts.map +1 -1
- package/dist/middlewares/response-time.js.map +1 -1
- package/dist/middlewares/response-time.mjs.map +1 -1
- package/dist/middlewares/responses.d.ts +3 -3
- package/dist/middlewares/responses.d.ts.map +1 -1
- package/dist/middlewares/responses.js.map +1 -1
- package/dist/middlewares/responses.mjs.map +1 -1
- package/dist/middlewares/security.d.ts +2 -2
- package/dist/middlewares/security.d.ts.map +1 -1
- package/dist/middlewares/security.js +10 -3
- package/dist/middlewares/security.js.map +1 -1
- package/dist/middlewares/security.mjs +11 -4
- package/dist/middlewares/security.mjs.map +1 -1
- package/dist/middlewares/session.d.ts +2 -2
- package/dist/middlewares/session.d.ts.map +1 -1
- package/dist/middlewares/session.js.map +1 -1
- package/dist/middlewares/session.mjs.map +1 -1
- package/dist/migrations/database/5.0.0-discard-drafts.d.ts +30 -0
- package/dist/migrations/database/5.0.0-discard-drafts.d.ts.map +1 -0
- package/dist/migrations/database/5.0.0-discard-drafts.js +50 -0
- package/dist/migrations/database/5.0.0-discard-drafts.js.map +1 -0
- package/dist/migrations/database/5.0.0-discard-drafts.mjs +50 -0
- package/dist/migrations/database/5.0.0-discard-drafts.mjs.map +1 -0
- package/dist/migrations/draft-publish.d.ts.map +1 -1
- package/dist/migrations/draft-publish.js +14 -31
- package/dist/migrations/draft-publish.js.map +1 -1
- package/dist/migrations/draft-publish.mjs +15 -32
- package/dist/migrations/draft-publish.mjs.map +1 -1
- package/dist/providers/admin.d.ts +3 -0
- package/dist/providers/admin.d.ts.map +1 -0
- package/dist/providers/admin.js +20 -0
- package/dist/providers/admin.js.map +1 -0
- package/dist/providers/admin.mjs +21 -0
- package/dist/providers/admin.mjs.map +1 -0
- package/dist/providers/coreStore.d.ts +3 -0
- package/dist/providers/coreStore.d.ts.map +1 -0
- package/dist/providers/coreStore.js +11 -0
- package/dist/providers/coreStore.js.map +1 -0
- package/dist/providers/coreStore.mjs +12 -0
- package/dist/providers/coreStore.mjs.map +1 -0
- package/dist/providers/cron.d.ts +3 -0
- package/dist/providers/cron.d.ts.map +1 -0
- package/dist/providers/cron.js +20 -0
- package/dist/providers/cron.js.map +1 -0
- package/dist/providers/cron.mjs +21 -0
- package/dist/providers/cron.mjs.map +1 -0
- package/dist/providers/index.d.ts +3 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +11 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/index.mjs +11 -0
- package/dist/providers/index.mjs.map +1 -0
- package/dist/providers/provider.d.ts +9 -0
- package/dist/providers/provider.d.ts.map +1 -0
- package/dist/providers/provider.js +5 -0
- package/dist/providers/provider.js.map +1 -0
- package/dist/providers/provider.mjs +5 -0
- package/dist/providers/provider.mjs.map +1 -0
- package/dist/providers/registries.d.ts +3 -0
- package/dist/providers/registries.d.ts.map +1 -0
- package/dist/providers/registries.js +35 -0
- package/dist/providers/registries.js.map +1 -0
- package/dist/providers/registries.mjs +36 -0
- package/dist/providers/registries.mjs.map +1 -0
- package/dist/providers/telemetry.d.ts +3 -0
- package/dist/providers/telemetry.d.ts.map +1 -0
- package/dist/providers/telemetry.js +19 -0
- package/dist/providers/telemetry.js.map +1 -0
- package/dist/providers/telemetry.mjs +20 -0
- package/dist/providers/telemetry.mjs.map +1 -0
- package/dist/providers/webhooks.d.ts +3 -0
- package/dist/providers/webhooks.d.ts.map +1 -0
- package/dist/providers/webhooks.js +30 -0
- package/dist/providers/webhooks.js.map +1 -0
- package/dist/providers/webhooks.mjs +31 -0
- package/dist/providers/webhooks.mjs.map +1 -0
- package/dist/registries/apis.d.ts +2 -2
- package/dist/registries/apis.d.ts.map +1 -1
- package/dist/registries/apis.js.map +1 -1
- package/dist/registries/apis.mjs.map +1 -1
- package/dist/registries/components.d.ts +6 -6
- package/dist/registries/components.d.ts.map +1 -1
- package/dist/registries/components.js.map +1 -1
- package/dist/registries/components.mjs.map +1 -1
- package/dist/registries/content-types.d.ts +5 -5
- package/dist/registries/content-types.d.ts.map +1 -1
- package/dist/registries/content-types.js.map +1 -1
- package/dist/registries/content-types.mjs.map +1 -1
- package/dist/registries/controllers.d.ts +10 -10
- package/dist/registries/controllers.d.ts.map +1 -1
- package/dist/registries/controllers.js.map +1 -1
- package/dist/registries/controllers.mjs.map +1 -1
- package/dist/registries/custom-fields.d.ts +3 -3
- package/dist/registries/custom-fields.d.ts.map +1 -1
- package/dist/registries/custom-fields.js.map +1 -1
- package/dist/registries/custom-fields.mjs.map +1 -1
- package/dist/registries/index.d.ts +0 -1
- package/dist/registries/index.d.ts.map +1 -1
- package/dist/registries/middlewares.d.ts +6 -6
- package/dist/registries/middlewares.d.ts.map +1 -1
- package/dist/registries/middlewares.js.map +1 -1
- package/dist/registries/middlewares.mjs.map +1 -1
- package/dist/registries/modules.d.ts +2 -2
- package/dist/registries/modules.d.ts.map +1 -1
- package/dist/registries/modules.js.map +1 -1
- package/dist/registries/modules.mjs.map +1 -1
- package/dist/registries/plugins.d.ts +5 -5
- package/dist/registries/plugins.d.ts.map +1 -1
- package/dist/registries/plugins.js.map +1 -1
- package/dist/registries/plugins.mjs.map +1 -1
- package/dist/registries/policies.d.ts +23 -11
- package/dist/registries/policies.d.ts.map +1 -1
- package/dist/registries/policies.js +64 -18
- package/dist/registries/policies.js.map +1 -1
- package/dist/registries/policies.mjs +65 -19
- package/dist/registries/policies.mjs.map +1 -1
- package/dist/registries/services.d.ts +8 -8
- package/dist/registries/services.d.ts.map +1 -1
- package/dist/registries/services.js.map +1 -1
- package/dist/registries/services.mjs.map +1 -1
- package/dist/services/auth/index.d.ts +4 -4
- package/dist/services/auth/index.d.ts.map +1 -1
- package/dist/services/auth/index.js.map +1 -1
- package/dist/services/auth/index.mjs.map +1 -1
- package/dist/services/config.d.ts +3 -0
- package/dist/services/config.d.ts.map +1 -0
- package/dist/services/config.js +47 -0
- package/dist/services/config.js.map +1 -0
- package/dist/services/config.mjs +47 -0
- package/dist/services/config.mjs.map +1 -0
- package/dist/services/content-api/index.d.ts +21 -3
- package/dist/services/content-api/index.d.ts.map +1 -1
- package/dist/services/content-api/index.js +28 -2
- package/dist/services/content-api/index.js.map +1 -1
- package/dist/services/content-api/index.mjs +28 -2
- package/dist/services/content-api/index.mjs.map +1 -1
- package/dist/services/content-api/permissions/index.d.ts +3 -3
- package/dist/services/content-api/permissions/index.d.ts.map +1 -1
- package/dist/services/content-api/permissions/index.js +1 -1
- package/dist/services/content-api/permissions/index.js.map +1 -1
- package/dist/services/content-api/permissions/index.mjs +1 -1
- package/dist/services/content-api/permissions/index.mjs.map +1 -1
- package/dist/services/core-store.d.ts.map +1 -1
- package/dist/services/cron.d.ts +2 -2
- package/dist/services/cron.d.ts.map +1 -1
- package/dist/services/cron.js.map +1 -1
- package/dist/services/cron.mjs.map +1 -1
- package/dist/services/custom-fields.d.ts +2 -2
- package/dist/services/custom-fields.d.ts.map +1 -1
- package/dist/services/custom-fields.js.map +1 -1
- package/dist/services/custom-fields.mjs.map +1 -1
- package/dist/services/document-service/attributes/index.d.ts +6 -0
- package/dist/services/document-service/attributes/index.d.ts.map +1 -0
- package/dist/services/{entity-service → document-service}/attributes/index.js +5 -5
- package/dist/services/document-service/attributes/index.js.map +1 -0
- package/dist/services/{entity-service → document-service}/attributes/index.mjs +5 -5
- package/dist/services/document-service/attributes/index.mjs.map +1 -0
- package/dist/services/document-service/attributes/transforms.d.ts +10 -0
- package/dist/services/document-service/attributes/transforms.d.ts.map +1 -0
- package/dist/services/document-service/attributes/transforms.js.map +1 -0
- package/dist/services/document-service/attributes/transforms.mjs.map +1 -0
- package/dist/services/document-service/common.d.ts +2 -2
- package/dist/services/document-service/common.d.ts.map +1 -1
- package/dist/services/document-service/common.js.map +1 -1
- package/dist/services/document-service/common.mjs.map +1 -1
- package/dist/services/document-service/components.d.ts +25 -1
- package/dist/services/document-service/components.d.ts.map +1 -1
- package/dist/services/{entity-service → document-service}/components.js +35 -45
- package/dist/services/document-service/components.js.map +1 -0
- package/dist/services/{entity-service → document-service}/components.mjs +36 -46
- package/dist/services/document-service/components.mjs.map +1 -0
- package/dist/services/document-service/draft-and-publish.d.ts +7 -7
- package/dist/services/document-service/draft-and-publish.d.ts.map +1 -1
- package/dist/services/document-service/draft-and-publish.js.map +1 -1
- package/dist/services/document-service/draft-and-publish.mjs.map +1 -1
- package/dist/services/document-service/entries.d.ts +10 -0
- package/dist/services/document-service/entries.d.ts.map +1 -0
- package/dist/services/document-service/entries.js +96 -0
- package/dist/services/document-service/entries.js.map +1 -0
- package/dist/services/document-service/entries.mjs +96 -0
- package/dist/services/document-service/entries.mjs.map +1 -0
- package/dist/services/document-service/events.d.ts +25 -0
- package/dist/services/document-service/events.d.ts.map +1 -0
- package/dist/services/document-service/events.js +47 -0
- package/dist/services/document-service/events.js.map +1 -0
- package/dist/services/document-service/events.mjs +47 -0
- package/dist/services/document-service/events.mjs.map +1 -0
- package/dist/services/document-service/index.d.ts +2 -4
- package/dist/services/document-service/index.d.ts.map +1 -1
- package/dist/services/document-service/index.js +13 -2
- package/dist/services/document-service/index.js.map +1 -1
- package/dist/services/document-service/index.mjs +13 -2
- package/dist/services/document-service/index.mjs.map +1 -1
- package/dist/services/document-service/internationalization.d.ts +5 -5
- package/dist/services/document-service/internationalization.d.ts.map +1 -1
- package/dist/services/document-service/internationalization.js +14 -5
- package/dist/services/document-service/internationalization.js.map +1 -1
- package/dist/services/document-service/internationalization.mjs +14 -5
- package/dist/services/document-service/internationalization.mjs.map +1 -1
- package/dist/services/document-service/middlewares/middleware-manager.d.ts +5 -2
- package/dist/services/document-service/middlewares/middleware-manager.d.ts.map +1 -1
- package/dist/services/document-service/middlewares/middleware-manager.js +8 -5
- package/dist/services/document-service/middlewares/middleware-manager.js.map +1 -1
- package/dist/services/document-service/middlewares/middleware-manager.mjs +8 -5
- package/dist/services/document-service/middlewares/middleware-manager.mjs.map +1 -1
- package/dist/services/document-service/params.d.ts +3 -1
- package/dist/services/document-service/params.d.ts.map +1 -1
- package/dist/services/document-service/params.js.map +1 -0
- package/dist/services/document-service/params.mjs.map +1 -0
- package/dist/services/document-service/repository.d.ts.map +1 -1
- package/dist/services/document-service/repository.js +135 -152
- package/dist/services/document-service/repository.js.map +1 -1
- package/dist/services/document-service/repository.mjs +118 -135
- package/dist/services/document-service/repository.mjs.map +1 -1
- package/dist/services/document-service/transform/data.d.ts.map +1 -1
- package/dist/services/document-service/transform/data.js +4 -2
- package/dist/services/document-service/transform/data.js.map +1 -1
- package/dist/services/document-service/transform/data.mjs +4 -2
- package/dist/services/document-service/transform/data.mjs.map +1 -1
- package/dist/services/document-service/transform/fields.d.ts +2 -2
- package/dist/services/document-service/transform/fields.d.ts.map +1 -1
- package/dist/services/document-service/transform/fields.js.map +1 -1
- package/dist/services/document-service/transform/fields.mjs.map +1 -1
- package/dist/services/document-service/transform/id-map.d.ts +3 -3
- package/dist/services/document-service/transform/id-map.d.ts.map +1 -1
- package/dist/services/document-service/transform/id-map.js.map +1 -1
- package/dist/services/document-service/transform/id-map.mjs.map +1 -1
- package/dist/services/document-service/transform/id-transform.d.ts +2 -2
- package/dist/services/document-service/transform/id-transform.d.ts.map +1 -1
- package/dist/services/document-service/transform/id-transform.js.map +1 -1
- package/dist/services/document-service/transform/id-transform.mjs.map +1 -1
- package/dist/services/document-service/transform/populate.d.ts +2 -2
- package/dist/services/document-service/transform/populate.d.ts.map +1 -1
- package/dist/services/document-service/transform/populate.js +1 -1
- package/dist/services/document-service/transform/populate.js.map +1 -1
- package/dist/services/document-service/transform/populate.mjs +1 -1
- package/dist/services/document-service/transform/populate.mjs.map +1 -1
- package/dist/services/document-service/transform/query.d.ts +5 -0
- package/dist/services/document-service/transform/query.d.ts.map +1 -0
- package/dist/services/document-service/transform/query.js +9 -0
- package/dist/services/document-service/transform/query.js.map +1 -0
- package/dist/services/document-service/transform/query.mjs +9 -0
- package/dist/services/document-service/transform/query.mjs.map +1 -0
- package/dist/services/document-service/transform/relations/extract/data-ids.d.ts +8 -7
- 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 +44 -77
- 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 +44 -77
- 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 +8 -4
- 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 +60 -125
- 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 +61 -126
- package/dist/services/document-service/transform/relations/transform/data-ids.mjs.map +1 -1
- package/dist/services/document-service/transform/relations/transform/default-locale.d.ts +9 -0
- package/dist/services/document-service/transform/relations/transform/default-locale.d.ts.map +1 -0
- package/dist/services/document-service/transform/relations/transform/default-locale.js +32 -0
- package/dist/services/document-service/transform/relations/transform/default-locale.js.map +1 -0
- package/dist/services/document-service/transform/relations/transform/default-locale.mjs +32 -0
- package/dist/services/document-service/transform/relations/transform/default-locale.mjs.map +1 -0
- package/dist/services/document-service/transform/relations/utils/dp.d.ts +3 -3
- package/dist/services/document-service/transform/relations/utils/dp.d.ts.map +1 -1
- package/dist/services/document-service/transform/relations/utils/dp.js +9 -4
- package/dist/services/document-service/transform/relations/utils/dp.js.map +1 -1
- package/dist/services/document-service/transform/relations/utils/dp.mjs +9 -4
- package/dist/services/document-service/transform/relations/utils/dp.mjs.map +1 -1
- package/dist/services/document-service/transform/relations/utils/i18n.d.ts +5 -5
- package/dist/services/document-service/transform/relations/utils/i18n.d.ts.map +1 -1
- package/dist/services/document-service/transform/relations/utils/i18n.js +2 -8
- package/dist/services/document-service/transform/relations/utils/i18n.js.map +1 -1
- package/dist/services/document-service/transform/relations/utils/i18n.mjs +2 -8
- package/dist/services/document-service/transform/relations/utils/i18n.mjs.map +1 -1
- package/dist/services/document-service/transform/relations/utils/map-relation.d.ts +6 -0
- package/dist/services/document-service/transform/relations/utils/map-relation.d.ts.map +1 -0
- package/dist/services/document-service/transform/relations/utils/map-relation.js +91 -0
- package/dist/services/document-service/transform/relations/utils/map-relation.js.map +1 -0
- package/dist/services/document-service/transform/relations/utils/map-relation.mjs +91 -0
- package/dist/services/document-service/transform/relations/utils/map-relation.mjs.map +1 -0
- package/dist/services/document-service/transform/relations/utils/types.d.ts +6 -0
- package/dist/services/document-service/transform/relations/utils/types.d.ts.map +1 -1
- package/dist/services/document-service/transform/types.d.ts +3 -3
- package/dist/services/document-service/transform/types.d.ts.map +1 -1
- package/dist/services/document-service/utils/populate.d.ts +2 -2
- package/dist/services/document-service/utils/populate.d.ts.map +1 -1
- package/dist/services/document-service/utils/populate.js +4 -0
- package/dist/services/document-service/utils/populate.js.map +1 -1
- package/dist/services/document-service/utils/populate.mjs +4 -0
- package/dist/services/document-service/utils/populate.mjs.map +1 -1
- package/dist/services/entity-service/index.d.ts +4 -4
- package/dist/services/entity-service/index.d.ts.map +1 -1
- package/dist/services/entity-service/index.js +22 -16
- package/dist/services/entity-service/index.js.map +1 -1
- package/dist/services/entity-service/index.mjs +23 -17
- package/dist/services/entity-service/index.mjs.map +1 -1
- package/dist/services/entity-validator/index.d.ts +15 -2
- package/dist/services/entity-validator/index.d.ts.map +1 -1
- package/dist/services/entity-validator/index.js +186 -118
- package/dist/services/entity-validator/index.js.map +1 -1
- package/dist/services/entity-validator/index.mjs +186 -118
- package/dist/services/entity-validator/index.mjs.map +1 -1
- package/dist/services/entity-validator/validators.d.ts +24 -22
- package/dist/services/entity-validator/validators.d.ts.map +1 -1
- package/dist/services/entity-validator/validators.js +65 -19
- package/dist/services/entity-validator/validators.js.map +1 -1
- package/dist/services/entity-validator/validators.mjs +58 -11
- package/dist/services/entity-validator/validators.mjs.map +1 -1
- package/dist/services/event-hub.d.ts +1 -0
- package/dist/services/event-hub.d.ts.map +1 -1
- package/dist/services/event-hub.js +9 -4
- package/dist/services/event-hub.js.map +1 -1
- package/dist/services/event-hub.mjs +9 -4
- package/dist/services/event-hub.mjs.map +1 -1
- package/dist/services/features.d.ts +3 -3
- package/dist/services/features.d.ts.map +1 -1
- package/dist/services/features.js.map +1 -1
- package/dist/services/features.mjs.map +1 -1
- package/dist/services/fs.d.ts +2 -2
- package/dist/services/fs.d.ts.map +1 -1
- package/dist/services/fs.js.map +1 -1
- package/dist/services/fs.mjs.map +1 -1
- package/dist/services/metrics/admin-user-hash.d.ts +2 -2
- 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 +2 -2
- package/dist/services/metrics/index.d.ts.map +1 -1
- package/dist/services/metrics/index.js.map +1 -1
- package/dist/services/metrics/index.mjs.map +1 -1
- package/dist/services/metrics/middleware.d.ts +2 -2
- package/dist/services/metrics/middleware.d.ts.map +1 -1
- package/dist/services/metrics/middleware.js.map +1 -1
- package/dist/services/metrics/middleware.mjs.map +1 -1
- package/dist/services/metrics/rate-limiter.d.ts.map +1 -1
- package/dist/services/metrics/rate-limiter.js.map +1 -1
- package/dist/services/metrics/rate-limiter.mjs.map +1 -1
- package/dist/services/metrics/sender.d.ts +3 -3
- package/dist/services/metrics/sender.d.ts.map +1 -1
- package/dist/services/metrics/sender.js.map +1 -1
- package/dist/services/metrics/sender.mjs.map +1 -1
- package/dist/services/query-params.d.ts +7 -0
- package/dist/services/query-params.d.ts.map +1 -0
- package/dist/services/query-params.js +12 -0
- package/dist/services/query-params.js.map +1 -0
- package/dist/services/query-params.mjs +13 -0
- package/dist/services/query-params.mjs.map +1 -0
- package/dist/services/reloader.d.ts +7 -0
- package/dist/services/reloader.d.ts.map +1 -0
- package/dist/services/reloader.js +36 -0
- package/dist/services/reloader.js.map +1 -0
- package/dist/services/reloader.mjs +36 -0
- package/dist/services/reloader.mjs.map +1 -0
- package/dist/services/server/admin-api.d.ts +3 -3
- package/dist/services/server/admin-api.d.ts.map +1 -1
- package/dist/services/server/admin-api.js.map +1 -1
- package/dist/services/server/admin-api.mjs.map +1 -1
- package/dist/services/server/api.d.ts +3 -3
- package/dist/services/server/api.d.ts.map +1 -1
- package/dist/services/server/api.js.map +1 -1
- package/dist/services/server/api.mjs.map +1 -1
- package/dist/services/server/compose-endpoint.d.ts +2 -2
- package/dist/services/server/compose-endpoint.d.ts.map +1 -1
- package/dist/services/server/compose-endpoint.js +1 -2
- package/dist/services/server/compose-endpoint.js.map +1 -1
- package/dist/services/server/compose-endpoint.mjs +2 -3
- package/dist/services/server/compose-endpoint.mjs.map +1 -1
- package/dist/services/server/content-api.d.ts +3 -3
- package/dist/services/server/content-api.d.ts.map +1 -1
- package/dist/services/server/content-api.js.map +1 -1
- package/dist/services/server/content-api.mjs.map +1 -1
- package/dist/services/server/http-server.d.ts +2 -2
- package/dist/services/server/http-server.d.ts.map +1 -1
- package/dist/services/server/http-server.js.map +1 -1
- package/dist/services/server/http-server.mjs.map +1 -1
- package/dist/services/server/index.d.ts +2 -2
- package/dist/services/server/index.d.ts.map +1 -1
- package/dist/services/server/index.js +2 -3
- package/dist/services/server/index.js.map +1 -1
- package/dist/services/server/index.mjs +2 -3
- package/dist/services/server/index.mjs.map +1 -1
- package/dist/services/server/koa.d.ts.map +1 -1
- package/dist/services/server/koa.js +1 -1
- package/dist/services/server/koa.js.map +1 -1
- package/dist/services/server/koa.mjs +1 -1
- package/dist/services/server/koa.mjs.map +1 -1
- package/dist/services/server/middleware.d.ts +4 -4
- package/dist/services/server/middleware.d.ts.map +1 -1
- package/dist/services/server/middleware.js.map +1 -1
- package/dist/services/server/middleware.mjs.map +1 -1
- package/dist/services/server/policy.d.ts +3 -3
- package/dist/services/server/policy.d.ts.map +1 -1
- package/dist/services/server/policy.js +4 -4
- package/dist/services/server/policy.js.map +1 -1
- package/dist/services/server/policy.mjs +4 -4
- package/dist/services/server/policy.mjs.map +1 -1
- package/dist/services/server/register-middlewares.d.ts +2 -2
- package/dist/services/server/register-middlewares.d.ts.map +1 -1
- package/dist/services/server/register-middlewares.js.map +1 -1
- package/dist/services/server/register-middlewares.mjs.map +1 -1
- package/dist/services/server/register-routes.d.ts +2 -2
- package/dist/services/server/register-routes.d.ts.map +1 -1
- package/dist/services/server/register-routes.js +3 -3
- package/dist/services/server/register-routes.js.map +1 -1
- package/dist/services/server/register-routes.mjs +3 -3
- package/dist/services/server/register-routes.mjs.map +1 -1
- package/dist/services/server/routing.d.ts +5 -5
- package/dist/services/server/routing.d.ts.map +1 -1
- package/dist/services/server/routing.js.map +1 -1
- package/dist/services/server/routing.mjs.map +1 -1
- package/dist/services/utils/dynamic-zones.d.ts.map +1 -1
- package/dist/services/utils/dynamic-zones.js +2 -1
- package/dist/services/utils/dynamic-zones.js.map +1 -1
- package/dist/services/utils/dynamic-zones.mjs +2 -1
- package/dist/services/utils/dynamic-zones.mjs.map +1 -1
- package/dist/services/webhook-runner.d.ts +2 -1
- package/dist/services/webhook-runner.d.ts.map +1 -1
- package/dist/services/webhook-runner.js.map +1 -1
- package/dist/services/webhook-runner.mjs.map +1 -1
- package/dist/services/webhook-store.d.ts +2 -8
- package/dist/services/webhook-store.d.ts.map +1 -1
- package/dist/services/webhook-store.js +14 -8
- package/dist/services/webhook-store.js.map +1 -1
- package/dist/services/webhook-store.mjs +14 -8
- package/dist/services/webhook-store.mjs.map +1 -1
- package/dist/utils/convert-custom-field-type.d.ts +2 -2
- package/dist/utils/convert-custom-field-type.d.ts.map +1 -1
- package/dist/utils/convert-custom-field-type.js.map +1 -1
- package/dist/utils/convert-custom-field-type.mjs.map +1 -1
- package/dist/utils/fetch.d.ts +3 -3
- package/dist/utils/fetch.d.ts.map +1 -1
- package/dist/utils/fetch.js +4 -3
- package/dist/utils/fetch.js.map +1 -1
- package/dist/utils/fetch.mjs +4 -3
- package/dist/utils/fetch.mjs.map +1 -1
- package/dist/utils/index.d.ts +2 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/is-initialized.d.ts +2 -2
- package/dist/utils/is-initialized.d.ts.map +1 -1
- package/dist/utils/is-initialized.js.map +1 -1
- package/dist/utils/is-initialized.mjs.map +1 -1
- package/dist/utils/load-files.d.ts.map +1 -1
- package/dist/utils/open-browser.d.ts +2 -2
- package/dist/utils/open-browser.d.ts.map +1 -1
- package/dist/utils/open-browser.js.map +1 -1
- package/dist/utils/open-browser.mjs.map +1 -1
- package/dist/utils/resolve-working-dirs.d.ts +19 -0
- package/dist/utils/resolve-working-dirs.d.ts.map +1 -0
- package/dist/utils/resolve-working-dirs.js +13 -0
- package/dist/utils/resolve-working-dirs.js.map +1 -0
- package/dist/utils/resolve-working-dirs.mjs +11 -0
- package/dist/utils/resolve-working-dirs.mjs.map +1 -0
- package/dist/utils/signals.d.ts +2 -2
- package/dist/utils/signals.d.ts.map +1 -1
- package/dist/utils/signals.js.map +1 -1
- package/dist/utils/signals.mjs.map +1 -1
- package/dist/utils/startup-logger.d.ts +2 -2
- package/dist/utils/startup-logger.d.ts.map +1 -1
- package/dist/utils/startup-logger.js.map +1 -1
- package/dist/utils/startup-logger.mjs.map +1 -1
- package/dist/utils/transform-content-types-to-models.d.ts +54 -99
- package/dist/utils/transform-content-types-to-models.d.ts.map +1 -1
- package/dist/utils/transform-content-types-to-models.js +105 -57
- package/dist/utils/transform-content-types-to-models.js.map +1 -1
- package/dist/utils/transform-content-types-to-models.mjs +105 -57
- package/dist/utils/transform-content-types-to-models.mjs.map +1 -1
- package/dist/utils/update-notifier/index.d.ts +2 -7
- package/dist/utils/update-notifier/index.d.ts.map +1 -1
- package/dist/utils/update-notifier/index.js +11 -14
- package/dist/utils/update-notifier/index.js.map +1 -1
- package/dist/utils/update-notifier/index.mjs +11 -14
- package/dist/utils/update-notifier/index.mjs.map +1 -1
- package/package.json +32 -28
- package/dist/registries/config.d.ts +0 -4
- package/dist/registries/config.d.ts.map +0 -1
- package/dist/registries/config.js +0 -31
- package/dist/registries/config.js.map +0 -1
- package/dist/registries/config.mjs +0 -32
- package/dist/registries/config.mjs.map +0 -1
- package/dist/services/document-service/transform/relations/utils/data.js +0 -12
- package/dist/services/document-service/transform/relations/utils/data.js.map +0 -1
- package/dist/services/document-service/transform/relations/utils/data.mjs +0 -12
- package/dist/services/document-service/transform/relations/utils/data.mjs.map +0 -1
- package/dist/services/entity-service/attributes/index.d.ts +0 -6
- package/dist/services/entity-service/attributes/index.d.ts.map +0 -1
- package/dist/services/entity-service/attributes/index.js.map +0 -1
- package/dist/services/entity-service/attributes/index.mjs.map +0 -1
- package/dist/services/entity-service/attributes/transforms.d.ts +0 -10
- package/dist/services/entity-service/attributes/transforms.d.ts.map +0 -1
- package/dist/services/entity-service/attributes/transforms.js.map +0 -1
- package/dist/services/entity-service/attributes/transforms.mjs.map +0 -1
- package/dist/services/entity-service/components.d.ts +0 -20
- package/dist/services/entity-service/components.d.ts.map +0 -1
- package/dist/services/entity-service/components.js.map +0 -1
- package/dist/services/entity-service/components.mjs.map +0 -1
- package/dist/services/entity-service/params.d.ts +0 -8
- package/dist/services/entity-service/params.d.ts.map +0 -1
- package/dist/services/entity-service/params.js.map +0 -1
- package/dist/services/entity-service/params.mjs.map +0 -1
- package/dist/utils/get-dirs.d.ts +0 -9
- package/dist/utils/get-dirs.d.ts.map +0 -1
- package/dist/utils/get-dirs.js.map +0 -1
- package/dist/utils/get-dirs.mjs.map +0 -1
- /package/dist/services/{entity-service → document-service}/attributes/transforms.js +0 -0
- /package/dist/services/{entity-service → document-service}/attributes/transforms.mjs +0 -0
- /package/dist/services/{entity-service → document-service}/params.js +0 -0
- /package/dist/services/{entity-service → document-service}/params.mjs +0 -0
|
@@ -1,39 +1,41 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type {
|
|
3
|
-
|
|
1
|
+
import { yup } from '@strapi/utils';
|
|
2
|
+
import type { Schema, Struct, Modules } from '@strapi/types';
|
|
3
|
+
import type { ComponentContext } from '.';
|
|
4
|
+
interface ValidatorMetas<TAttribute extends Schema.Attribute.AnyAttribute> {
|
|
4
5
|
attr: TAttribute;
|
|
5
|
-
model:
|
|
6
|
+
model: Struct.ContentTypeSchema;
|
|
6
7
|
updatedAttribute: {
|
|
7
8
|
name: string;
|
|
8
9
|
value: unknown;
|
|
9
10
|
};
|
|
10
|
-
entity:
|
|
11
|
+
entity: Modules.EntityValidator.Entity;
|
|
12
|
+
componentContext: ComponentContext;
|
|
11
13
|
}
|
|
12
14
|
interface ValidatorOptions {
|
|
13
15
|
isDraft: boolean;
|
|
14
16
|
locale?: string;
|
|
15
17
|
}
|
|
16
18
|
declare const _default: {
|
|
17
|
-
string: (metas: ValidatorMetas<Attribute.
|
|
18
|
-
text: (metas: ValidatorMetas<Attribute.
|
|
19
|
-
richtext: (metas: ValidatorMetas<Attribute.
|
|
20
|
-
password: (metas: ValidatorMetas<Attribute.
|
|
21
|
-
email: (metas: ValidatorMetas<Attribute.
|
|
19
|
+
string: (metas: ValidatorMetas<(Schema.Attribute.OfType<"email"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<string> & Schema.Attribute.MinMaxLengthOption & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.UniqueOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"password"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<string> & Schema.Attribute.MinMaxLengthOption & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"richtext"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<string> & Schema.Attribute.MinMaxLengthOption & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"string"> & Schema.Attribute.StringProperties & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<string> & Schema.Attribute.MinMaxLengthOption & Schema.Attribute.PrivateOption & Schema.Attribute.UniqueOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"text"> & Schema.Attribute.TextProperties & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<string> & Schema.Attribute.MinMaxLengthOption & Schema.Attribute.PrivateOption & Schema.Attribute.UniqueOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"uid"> & Schema.Attribute.UIDProperties<string, Schema.Attribute.UIDOptions> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<string> & Schema.Attribute.MinMaxLengthOption & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption)>, options: ValidatorOptions) => import("yup").StringSchema<string | undefined, Record<string, any>, string | undefined>;
|
|
20
|
+
text: (metas: ValidatorMetas<(Schema.Attribute.OfType<"email"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<string> & Schema.Attribute.MinMaxLengthOption & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.UniqueOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"password"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<string> & Schema.Attribute.MinMaxLengthOption & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"richtext"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<string> & Schema.Attribute.MinMaxLengthOption & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"string"> & Schema.Attribute.StringProperties & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<string> & Schema.Attribute.MinMaxLengthOption & Schema.Attribute.PrivateOption & Schema.Attribute.UniqueOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"text"> & Schema.Attribute.TextProperties & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<string> & Schema.Attribute.MinMaxLengthOption & Schema.Attribute.PrivateOption & Schema.Attribute.UniqueOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"uid"> & Schema.Attribute.UIDProperties<string, Schema.Attribute.UIDOptions> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<string> & Schema.Attribute.MinMaxLengthOption & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption)>, options: ValidatorOptions) => import("yup").StringSchema<string | undefined, Record<string, any>, string | undefined>;
|
|
21
|
+
richtext: (metas: ValidatorMetas<(Schema.Attribute.OfType<"email"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<string> & Schema.Attribute.MinMaxLengthOption & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.UniqueOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"password"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<string> & Schema.Attribute.MinMaxLengthOption & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"richtext"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<string> & Schema.Attribute.MinMaxLengthOption & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"string"> & Schema.Attribute.StringProperties & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<string> & Schema.Attribute.MinMaxLengthOption & Schema.Attribute.PrivateOption & Schema.Attribute.UniqueOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"text"> & Schema.Attribute.TextProperties & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<string> & Schema.Attribute.MinMaxLengthOption & Schema.Attribute.PrivateOption & Schema.Attribute.UniqueOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"uid"> & Schema.Attribute.UIDProperties<string, Schema.Attribute.UIDOptions> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<string> & Schema.Attribute.MinMaxLengthOption & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption)>, options: ValidatorOptions) => import("yup").StringSchema<string | undefined, Record<string, any>, string | undefined>;
|
|
22
|
+
password: (metas: ValidatorMetas<(Schema.Attribute.OfType<"email"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<string> & Schema.Attribute.MinMaxLengthOption & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.UniqueOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"password"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<string> & Schema.Attribute.MinMaxLengthOption & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"richtext"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<string> & Schema.Attribute.MinMaxLengthOption & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"string"> & Schema.Attribute.StringProperties & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<string> & Schema.Attribute.MinMaxLengthOption & Schema.Attribute.PrivateOption & Schema.Attribute.UniqueOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"text"> & Schema.Attribute.TextProperties & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<string> & Schema.Attribute.MinMaxLengthOption & Schema.Attribute.PrivateOption & Schema.Attribute.UniqueOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"uid"> & Schema.Attribute.UIDProperties<string, Schema.Attribute.UIDOptions> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<string> & Schema.Attribute.MinMaxLengthOption & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption)>, options: ValidatorOptions) => import("yup").StringSchema<string | undefined, Record<string, any>, string | undefined>;
|
|
23
|
+
email: (metas: ValidatorMetas<Schema.Attribute.OfType<"email"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<string> & Schema.Attribute.MinMaxLengthOption & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.UniqueOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption>, options: ValidatorOptions) => import("yup").StringSchema<string | undefined, Record<string, any>, string | undefined>;
|
|
22
24
|
enumeration: ({ attr }: {
|
|
23
|
-
attr: Attribute.
|
|
25
|
+
attr: Schema.Attribute.OfType<"enumeration"> & Schema.Attribute.EnumerationProperties<[]> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<never> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption;
|
|
24
26
|
}) => import("yup").StringSchema<string | undefined, Record<string, any>, string | undefined>;
|
|
25
|
-
boolean: () =>
|
|
26
|
-
uid: (metas: ValidatorMetas<Attribute.
|
|
27
|
+
boolean: () => yup.BooleanSchema<boolean | undefined, Record<string, any>, boolean | undefined>;
|
|
28
|
+
uid: (metas: ValidatorMetas<Schema.Attribute.OfType<"uid"> & Schema.Attribute.UIDProperties<string, Schema.Attribute.UIDOptions> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<string> & Schema.Attribute.MinMaxLengthOption & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption>, options: ValidatorOptions) => import("yup").StringSchema<string | undefined, Record<string, any>, string | undefined>;
|
|
27
29
|
json: () => import("yup/lib/mixed").MixedSchema<any, Record<string, any>, any>;
|
|
28
|
-
integer: (metas: ValidatorMetas<Attribute.
|
|
29
|
-
biginteger: (metas: ValidatorMetas<Attribute.
|
|
30
|
-
float: (metas: ValidatorMetas<Attribute.
|
|
31
|
-
decimal: (metas: ValidatorMetas<Attribute.
|
|
32
|
-
date: (metas: ValidatorMetas<Attribute.
|
|
33
|
-
time: (metas: ValidatorMetas<Attribute.
|
|
34
|
-
datetime: (metas: ValidatorMetas<Attribute.
|
|
35
|
-
timestamp: (metas: ValidatorMetas<Attribute.
|
|
36
|
-
blocks: (metas: any, options: any) =>
|
|
30
|
+
integer: (metas: ValidatorMetas<(Schema.Attribute.OfType<"biginteger"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<string> & Schema.Attribute.MinMaxOption<string> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption & Schema.Attribute.UniqueOption) | (Schema.Attribute.OfType<"integer"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<number> & Schema.Attribute.MinMaxOption<number> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption & Schema.Attribute.UniqueOption)>, options: ValidatorOptions) => yup.NumberSchema<number | undefined, Record<string, any>, number | undefined>;
|
|
31
|
+
biginteger: (metas: ValidatorMetas<Schema.Attribute.OfType<"biginteger"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<string> & Schema.Attribute.MinMaxOption<string> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption & Schema.Attribute.UniqueOption>, options: ValidatorOptions) => import("yup/lib/mixed").MixedSchema<any, Record<string, any>, any>;
|
|
32
|
+
float: (metas: ValidatorMetas<(Schema.Attribute.OfType<"decimal"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<number> & Schema.Attribute.MinMaxOption<number> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption & Schema.Attribute.UniqueOption) | (Schema.Attribute.OfType<"float"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<number> & Schema.Attribute.MinMaxOption<number> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption & Schema.Attribute.UniqueOption)>, options: ValidatorOptions) => yup.NumberSchema<number | undefined, Record<string, any>, number | undefined>;
|
|
33
|
+
decimal: (metas: ValidatorMetas<(Schema.Attribute.OfType<"decimal"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<number> & Schema.Attribute.MinMaxOption<number> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption & Schema.Attribute.UniqueOption) | (Schema.Attribute.OfType<"float"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<number> & Schema.Attribute.MinMaxOption<number> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption & Schema.Attribute.UniqueOption)>, options: ValidatorOptions) => yup.NumberSchema<number | undefined, Record<string, any>, number | undefined>;
|
|
34
|
+
date: (metas: ValidatorMetas<(Schema.Attribute.OfType<"datetime"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<Schema.Attribute.DateTimeValue> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.UniqueOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"date"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<Schema.Attribute.DateValue> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.UniqueOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"time"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<Schema.Attribute.TimeValue> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.UniqueOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"timestamp"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<Schema.Attribute.TimestampValue> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.UniqueOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption)>, options: ValidatorOptions) => import("yup/lib/mixed").MixedSchema<any, Record<string, any>, any>;
|
|
35
|
+
time: (metas: ValidatorMetas<(Schema.Attribute.OfType<"datetime"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<Schema.Attribute.DateTimeValue> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.UniqueOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"date"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<Schema.Attribute.DateValue> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.UniqueOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"time"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<Schema.Attribute.TimeValue> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.UniqueOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"timestamp"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<Schema.Attribute.TimestampValue> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.UniqueOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption)>, options: ValidatorOptions) => import("yup/lib/mixed").MixedSchema<any, Record<string, any>, any>;
|
|
36
|
+
datetime: (metas: ValidatorMetas<(Schema.Attribute.OfType<"datetime"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<Schema.Attribute.DateTimeValue> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.UniqueOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"date"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<Schema.Attribute.DateValue> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.UniqueOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"time"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<Schema.Attribute.TimeValue> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.UniqueOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"timestamp"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<Schema.Attribute.TimestampValue> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.UniqueOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption)>, options: ValidatorOptions) => import("yup/lib/mixed").MixedSchema<any, Record<string, any>, any>;
|
|
37
|
+
timestamp: (metas: ValidatorMetas<(Schema.Attribute.OfType<"datetime"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<Schema.Attribute.DateTimeValue> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.UniqueOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"date"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<Schema.Attribute.DateValue> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.UniqueOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"time"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<Schema.Attribute.TimeValue> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.UniqueOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"timestamp"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<Schema.Attribute.TimestampValue> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.UniqueOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption)>, options: ValidatorOptions) => import("yup/lib/mixed").MixedSchema<any, Record<string, any>, any>;
|
|
38
|
+
blocks: (metas: any, options: any) => yup.ArraySchema<any, import("yup/lib/types").AnyObject, any[] | undefined, any[] | undefined>;
|
|
37
39
|
};
|
|
38
40
|
export default _default;
|
|
39
41
|
//# sourceMappingURL=validators.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../../src/services/entity-validator/validators.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../../src/services/entity-validator/validators.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAG7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,GAAG,CAAC;AAE1C,UAAU,cAAc,CAAC,UAAU,SAAS,MAAM,CAAC,SAAS,CAAC,YAAY;IACvE,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC,iBAAiB,CAAC;IAChC,gBAAgB,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,CAAC;IACnD,MAAM,EAAE,OAAO,CAAC,eAAe,CAAC,MAAM,CAAC;IACvC,gBAAgB,EAAE,gBAAgB,CAAC;CACpC;AAED,UAAU,gBAAgB;IACxB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;;;;;;;;;;;;;;;;;;;;;;;AAwVD,wBAmBE"}
|
|
@@ -4,8 +4,6 @@ const strapiUtils = require("@strapi/utils");
|
|
|
4
4
|
const blocksValidator = require("./blocks-validator.js");
|
|
5
5
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
6
6
|
const ___default = /* @__PURE__ */ _interopDefault(_);
|
|
7
|
-
const strapiUtils__default = /* @__PURE__ */ _interopDefault(strapiUtils);
|
|
8
|
-
const { yup } = strapiUtils__default.default;
|
|
9
7
|
const addMinLengthValidator = (validator, {
|
|
10
8
|
attr
|
|
11
9
|
}, { isDraft }) => {
|
|
@@ -33,7 +31,13 @@ const addStringRegexValidator = (validator, {
|
|
|
33
31
|
}) => {
|
|
34
32
|
return "regex" in attr && !___default.default.isUndefined(attr.regex) ? validator.matches(new RegExp(attr.regex), { excludeEmptyString: !attr.required }) : validator;
|
|
35
33
|
};
|
|
36
|
-
const addUniqueValidator = (validator, {
|
|
34
|
+
const addUniqueValidator = (validator, {
|
|
35
|
+
attr,
|
|
36
|
+
model,
|
|
37
|
+
updatedAttribute,
|
|
38
|
+
entity,
|
|
39
|
+
componentContext
|
|
40
|
+
}, options) => {
|
|
37
41
|
if (attr.type !== "uid" && !attr.unique) {
|
|
38
42
|
return validator;
|
|
39
43
|
}
|
|
@@ -45,19 +49,61 @@ const addUniqueValidator = (validator, { attr, model, updatedAttribute, entity }
|
|
|
45
49
|
if (!isPublish && value === entity?.[updatedAttribute.name]) {
|
|
46
50
|
return true;
|
|
47
51
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
let queryUid;
|
|
53
|
+
let queryWhere = {};
|
|
54
|
+
if (componentContext) {
|
|
55
|
+
const hasRepeatableData = componentContext.repeatableData.length > 0;
|
|
56
|
+
if (hasRepeatableData) {
|
|
57
|
+
const { name: updatedName, value: updatedValue } = updatedAttribute;
|
|
58
|
+
const pathToCheck = [...componentContext.pathToComponent.slice(1), updatedName].join(".");
|
|
59
|
+
const values = componentContext.repeatableData.map((item) => {
|
|
60
|
+
return pathToCheck.split(".").reduce((acc, key) => acc[key], item);
|
|
61
|
+
});
|
|
62
|
+
const isUpdatedAttributeRepeatedInThisEntity = values.filter((value2) => value2 === updatedValue).length > 1;
|
|
63
|
+
if (isUpdatedAttributeRepeatedInThisEntity) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
54
66
|
}
|
|
55
|
-
|
|
56
|
-
|
|
67
|
+
const {
|
|
68
|
+
model: parentModel,
|
|
69
|
+
options: parentOptions,
|
|
70
|
+
id: excludeId
|
|
71
|
+
} = componentContext.parentContent;
|
|
72
|
+
queryUid = parentModel.uid;
|
|
73
|
+
const whereConditions = {};
|
|
74
|
+
const isParentDraft = parentOptions && parentOptions.isDraft;
|
|
75
|
+
whereConditions.publishedAt = isParentDraft ? null : { $notNull: true };
|
|
76
|
+
if (parentOptions?.locale) {
|
|
77
|
+
whereConditions.locale = parentOptions.locale;
|
|
78
|
+
}
|
|
79
|
+
if (excludeId && !Number.isNaN(excludeId)) {
|
|
80
|
+
whereConditions.id = { $ne: excludeId };
|
|
81
|
+
}
|
|
82
|
+
queryWhere = {
|
|
83
|
+
...componentContext.pathToComponent.reduceRight((acc, key) => ({ [key]: acc }), {
|
|
84
|
+
[updatedAttribute.name]: value
|
|
85
|
+
}),
|
|
86
|
+
...whereConditions
|
|
87
|
+
};
|
|
88
|
+
} else {
|
|
89
|
+
queryUid = model.uid;
|
|
90
|
+
const scalarAttributeWhere = {
|
|
91
|
+
[updatedAttribute.name]: value
|
|
92
|
+
};
|
|
93
|
+
scalarAttributeWhere.publishedAt = options.isDraft ? null : { $notNull: true };
|
|
94
|
+
if (options?.locale) {
|
|
95
|
+
scalarAttributeWhere.locale = options.locale;
|
|
96
|
+
}
|
|
97
|
+
if (entity?.id) {
|
|
98
|
+
scalarAttributeWhere.id = { $ne: entity.id };
|
|
99
|
+
}
|
|
100
|
+
queryWhere = scalarAttributeWhere;
|
|
101
|
+
}
|
|
102
|
+
return !await strapi.db.query(queryUid).findOne({ where: queryWhere });
|
|
57
103
|
});
|
|
58
104
|
};
|
|
59
105
|
const stringValidator = (metas, options) => {
|
|
60
|
-
let schema = yup.string().transform((val, originalVal) => originalVal);
|
|
106
|
+
let schema = strapiUtils.yup.string().transform((val, originalVal) => originalVal);
|
|
61
107
|
schema = addMinLengthValidator(schema, metas, options);
|
|
62
108
|
schema = addMaxLengthValidator(schema, metas);
|
|
63
109
|
schema = addStringRegexValidator(schema, metas);
|
|
@@ -73,28 +119,28 @@ const uidValidator = (metas, options) => {
|
|
|
73
119
|
return schema.matches(/^[A-Za-z0-9-_.~]*$/);
|
|
74
120
|
};
|
|
75
121
|
const enumerationValidator = ({ attr }) => {
|
|
76
|
-
return yup.string().oneOf((Array.isArray(attr.enum) ? attr.enum : [attr.enum]).concat(null));
|
|
122
|
+
return strapiUtils.yup.string().oneOf((Array.isArray(attr.enum) ? attr.enum : [attr.enum]).concat(null));
|
|
77
123
|
};
|
|
78
124
|
const integerValidator = (metas, options) => {
|
|
79
|
-
let schema = yup.number().integer();
|
|
125
|
+
let schema = strapiUtils.yup.number().integer();
|
|
80
126
|
schema = addMinIntegerValidator(schema, metas);
|
|
81
127
|
schema = addMaxIntegerValidator(schema, metas);
|
|
82
128
|
schema = addUniqueValidator(schema, metas, options);
|
|
83
129
|
return schema;
|
|
84
130
|
};
|
|
85
131
|
const floatValidator = (metas, options) => {
|
|
86
|
-
let schema = yup.number();
|
|
132
|
+
let schema = strapiUtils.yup.number();
|
|
87
133
|
schema = addMinFloatValidator(schema, metas);
|
|
88
134
|
schema = addMaxFloatValidator(schema, metas);
|
|
89
135
|
schema = addUniqueValidator(schema, metas, options);
|
|
90
136
|
return schema;
|
|
91
137
|
};
|
|
92
138
|
const bigintegerValidator = (metas, options) => {
|
|
93
|
-
const schema = yup.mixed();
|
|
139
|
+
const schema = strapiUtils.yup.mixed();
|
|
94
140
|
return addUniqueValidator(schema, metas, options);
|
|
95
141
|
};
|
|
96
142
|
const datesValidator = (metas, options) => {
|
|
97
|
-
const schema = yup.mixed();
|
|
143
|
+
const schema = strapiUtils.yup.mixed();
|
|
98
144
|
return addUniqueValidator(schema, metas, options);
|
|
99
145
|
};
|
|
100
146
|
const validators = {
|
|
@@ -104,9 +150,9 @@ const validators = {
|
|
|
104
150
|
password: stringValidator,
|
|
105
151
|
email: emailValidator,
|
|
106
152
|
enumeration: enumerationValidator,
|
|
107
|
-
boolean: () => yup.boolean(),
|
|
153
|
+
boolean: () => strapiUtils.yup.boolean(),
|
|
108
154
|
uid: uidValidator,
|
|
109
|
-
json: () => yup.mixed(),
|
|
155
|
+
json: () => strapiUtils.yup.mixed(),
|
|
110
156
|
integer: integerValidator,
|
|
111
157
|
biginteger: bigintegerValidator,
|
|
112
158
|
float: floatValidator,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.js","sources":["../../../src/services/entity-validator/validators.ts"],"sourcesContent":["import _ from 'lodash';\nimport strapiUtils from '@strapi/utils';\nimport type { Attribute, Schema } from '@strapi/types';\nimport blocksValidator from './blocks-validator';\n\nconst { yup } = strapiUtils;\n\ninterface ValidatorMetas<TAttribute extends Attribute.Any> {\n attr: TAttribute;\n model: Schema.ContentType;\n updatedAttribute: { name: string; value: unknown };\n entity: Record<string, unknown> | null;\n}\n\ninterface ValidatorOptions {\n isDraft: boolean;\n locale?: string;\n}\n\n/* Validator utils */\n\n/**\n * Adds minLength validator\n */\nconst addMinLengthValidator = (\n validator: strapiUtils.yup.StringSchema,\n {\n attr,\n }: {\n attr:\n | Attribute.String\n | Attribute.Text\n | Attribute.RichText\n | Attribute.Password\n | Attribute.Email\n | Attribute.UID;\n },\n { isDraft }: ValidatorOptions\n) => {\n return attr.minLength && _.isInteger(attr.minLength) && !isDraft\n ? validator.min(attr.minLength)\n : validator;\n};\n\n/**\n * Adds maxLength validator\n * @returns {StringSchema}\n */\nconst addMaxLengthValidator = (\n validator: strapiUtils.yup.StringSchema,\n {\n attr,\n }: {\n attr:\n | Attribute.String\n | Attribute.Text\n | Attribute.RichText\n | Attribute.Password\n | Attribute.Email\n | Attribute.UID;\n }\n) => {\n return attr.maxLength && _.isInteger(attr.maxLength) ? validator.max(attr.maxLength) : validator;\n};\n\n/**\n * Adds min integer validator\n * @returns {NumberSchema}\n */\nconst addMinIntegerValidator = (\n validator: strapiUtils.yup.NumberSchema,\n {\n attr,\n }: {\n attr: Attribute.Integer | Attribute.BigInteger;\n }\n) => (_.isNumber(attr.min) ? validator.min(_.toInteger(attr.min)) : validator);\n\n/**\n * Adds max integer validator\n */\nconst addMaxIntegerValidator = (\n validator: strapiUtils.yup.NumberSchema,\n {\n attr,\n }: {\n attr: Attribute.Integer | Attribute.BigInteger;\n }\n) => (_.isNumber(attr.max) ? validator.max(_.toInteger(attr.max)) : validator);\n\n/**\n * Adds min float/decimal validator\n */\nconst addMinFloatValidator = (\n validator: strapiUtils.yup.NumberSchema,\n {\n attr,\n }: {\n attr: Attribute.Decimal | Attribute.Float;\n }\n) => (_.isNumber(attr.min) ? validator.min(attr.min) : validator);\n\n/**\n * Adds max float/decimal validator\n */\nconst addMaxFloatValidator = (\n validator: strapiUtils.yup.NumberSchema,\n {\n attr,\n }: {\n attr: Attribute.Decimal | Attribute.Float;\n }\n) => (_.isNumber(attr.max) ? validator.max(attr.max) : validator);\n\n/**\n * Adds regex validator\n */\nconst addStringRegexValidator = (\n validator: strapiUtils.yup.StringSchema,\n {\n attr,\n }: {\n attr:\n | Attribute.String\n | Attribute.Text\n | Attribute.RichText\n | Attribute.Password\n | Attribute.Email\n | Attribute.UID;\n }\n) => {\n return 'regex' in attr && !_.isUndefined(attr.regex)\n ? validator.matches(new RegExp(attr.regex), { excludeEmptyString: !attr.required })\n : validator;\n};\n\n/**\n * Adds unique validator\n */\nconst addUniqueValidator = <T extends strapiUtils.yup.AnySchema>(\n validator: T,\n { attr, model, updatedAttribute, entity }: ValidatorMetas<Attribute.Any & Attribute.UniqueOption>,\n options: ValidatorOptions\n): T => {\n if (attr.type !== 'uid' && !attr.unique) {\n return validator;\n }\n\n return validator.test('unique', 'This attribute must be unique', async (value) => {\n const isPublish = options.isDraft === false;\n\n /**\n * If the attribute value is `null` we want to skip the unique validation.\n * Otherwise it'll only accept a single `null` entry in the database.\n */\n if (_.isNil(value)) {\n return true;\n }\n\n /**\n * If we are updating a draft and the value is unchanged we skip the unique verification. This will\n * prevent the validator to be triggered in case the user activated the\n * unique constraint after already creating multiple entries with\n * the same attribute value for that field.\n */\n if (!isPublish && value === entity?.[updatedAttribute.name]) {\n return true;\n }\n\n /**\n * At this point we know that we are creating a new entry, publishing an entry or that the unique field value has changed\n * We check if there is an entry of this content type in the same locale, publication state and with the same unique field value\n */\n const record = await strapi.db.query(model.uid).findOne({\n where: {\n locale: options.locale,\n publishedAt: options.isDraft ? null : { $notNull: true },\n [updatedAttribute.name]: value,\n ...(entity?.id ? { id: { $ne: entity.id } } : {}),\n },\n });\n\n return !record;\n });\n};\n\n/* Type validators */\n\nconst stringValidator = (\n metas: ValidatorMetas<\n | Attribute.String\n | Attribute.Text\n | Attribute.RichText\n | Attribute.Password\n | Attribute.Email\n | Attribute.UID\n >,\n options: ValidatorOptions\n) => {\n let schema = yup.string().transform((val, originalVal) => originalVal);\n\n schema = addMinLengthValidator(schema, metas, options);\n schema = addMaxLengthValidator(schema, metas);\n schema = addStringRegexValidator(schema, metas);\n schema = addUniqueValidator(schema, metas, options);\n\n return schema;\n};\n\nconst emailValidator = (metas: ValidatorMetas<Attribute.Email>, options: ValidatorOptions) => {\n const schema = stringValidator(metas, options);\n return schema.email().min(1, '${path} cannot be empty');\n};\n\nconst uidValidator = (metas: ValidatorMetas<Attribute.UID>, options: ValidatorOptions) => {\n const schema = stringValidator(metas, options);\n\n return schema.matches(/^[A-Za-z0-9-_.~]*$/);\n};\n\nconst enumerationValidator = ({ attr }: { attr: Attribute.Enumeration }) => {\n return yup\n .string()\n .oneOf((Array.isArray(attr.enum) ? attr.enum : [attr.enum]).concat(null as any));\n};\n\nconst integerValidator = (\n metas: ValidatorMetas<Attribute.Integer | Attribute.BigInteger>,\n options: ValidatorOptions\n) => {\n let schema = yup.number().integer();\n\n schema = addMinIntegerValidator(schema, metas);\n schema = addMaxIntegerValidator(schema, metas);\n schema = addUniqueValidator(schema, metas, options);\n\n return schema;\n};\n\nconst floatValidator = (\n metas: ValidatorMetas<Attribute.Decimal | Attribute.Float>,\n options: ValidatorOptions\n) => {\n let schema = yup.number();\n schema = addMinFloatValidator(schema, metas);\n schema = addMaxFloatValidator(schema, metas);\n schema = addUniqueValidator(schema, metas, options);\n\n return schema;\n};\n\nconst bigintegerValidator = (\n metas: ValidatorMetas<Attribute.BigInteger>,\n options: ValidatorOptions\n) => {\n const schema = yup.mixed();\n return addUniqueValidator(schema, metas, options);\n};\n\nconst datesValidator = (\n metas: ValidatorMetas<Attribute.Date | Attribute.DateTime | Attribute.Time | Attribute.Timestamp>,\n options: ValidatorOptions\n) => {\n const schema = yup.mixed();\n return addUniqueValidator(schema, metas, options);\n};\n\nexport default {\n string: stringValidator,\n text: stringValidator,\n richtext: stringValidator,\n password: stringValidator,\n email: emailValidator,\n enumeration: enumerationValidator,\n boolean: () => yup.boolean(),\n uid: uidValidator,\n json: () => yup.mixed(),\n integer: integerValidator,\n biginteger: bigintegerValidator,\n float: floatValidator,\n decimal: floatValidator,\n date: datesValidator,\n time: datesValidator,\n datetime: datesValidator,\n timestamp: datesValidator,\n blocks: blocksValidator,\n};\n"],"names":["strapiUtils","_"],"mappings":";;;;;;;AAKA,MAAM,EAAE,IAAQ,IAAAA;AAmBhB,MAAM,wBAAwB,CAC5B,WACA;AAAA,EACE;AACF,GASA,EAAE,cACC;AACH,SAAO,KAAK,aAAaC,WAAE,QAAA,UAAU,KAAK,SAAS,KAAK,CAAC,UACrD,UAAU,IAAI,KAAK,SAAS,IAC5B;AACN;AAMA,MAAM,wBAAwB,CAC5B,WACA;AAAA,EACE;AACF,MASG;AACI,SAAA,KAAK,aAAaA,mBAAE,UAAU,KAAK,SAAS,IAAI,UAAU,IAAI,KAAK,SAAS,IAAI;AACzF;AAMA,MAAM,yBAAyB,CAC7B,WACA;AAAA,EACE;AACF,MAGIA,WAAE,QAAA,SAAS,KAAK,GAAG,IAAI,UAAU,IAAIA,WAAAA,QAAE,UAAU,KAAK,GAAG,CAAC,IAAI;AAKpE,MAAM,yBAAyB,CAC7B,WACA;AAAA,EACE;AACF,MAGIA,WAAE,QAAA,SAAS,KAAK,GAAG,IAAI,UAAU,IAAIA,WAAAA,QAAE,UAAU,KAAK,GAAG,CAAC,IAAI;AAKpE,MAAM,uBAAuB,CAC3B,WACA;AAAA,EACE;AACF,MAGIA,mBAAE,SAAS,KAAK,GAAG,IAAI,UAAU,IAAI,KAAK,GAAG,IAAI;AAKvD,MAAM,uBAAuB,CAC3B,WACA;AAAA,EACE;AACF,MAGIA,mBAAE,SAAS,KAAK,GAAG,IAAI,UAAU,IAAI,KAAK,GAAG,IAAI;AAKvD,MAAM,0BAA0B,CAC9B,WACA;AAAA,EACE;AACF,MASG;AACI,SAAA,WAAW,QAAQ,CAACA,WAAA,QAAE,YAAY,KAAK,KAAK,IAC/C,UAAU,QAAQ,IAAI,OAAO,KAAK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{"version":3,"file":"validators.js","sources":["../../../src/services/entity-validator/validators.ts"],"sourcesContent":["import _ from 'lodash';\nimport { yup } from '@strapi/utils';\nimport type { Schema, Struct, Modules } from '@strapi/types';\nimport blocksValidator from './blocks-validator';\n\nimport type { ComponentContext } from '.';\n\ninterface ValidatorMetas<TAttribute extends Schema.Attribute.AnyAttribute> {\n attr: TAttribute;\n model: Struct.ContentTypeSchema;\n updatedAttribute: { name: string; value: unknown };\n entity: Modules.EntityValidator.Entity;\n componentContext: ComponentContext;\n}\n\ninterface ValidatorOptions {\n isDraft: boolean;\n locale?: string;\n}\n\n/* Validator utils */\n\n/**\n * Adds minLength validator\n */\nconst addMinLengthValidator = (\n validator: yup.StringSchema,\n {\n attr,\n }: {\n attr:\n | Schema.Attribute.String\n | Schema.Attribute.Text\n | Schema.Attribute.RichText\n | Schema.Attribute.Password\n | Schema.Attribute.Email\n | Schema.Attribute.UID;\n },\n { isDraft }: ValidatorOptions\n) => {\n return attr.minLength && _.isInteger(attr.minLength) && !isDraft\n ? validator.min(attr.minLength)\n : validator;\n};\n\n/**\n * Adds maxLength validator\n * @returns {StringSchema}\n */\nconst addMaxLengthValidator = (\n validator: yup.StringSchema,\n {\n attr,\n }: {\n attr:\n | Schema.Attribute.String\n | Schema.Attribute.Text\n | Schema.Attribute.RichText\n | Schema.Attribute.Password\n | Schema.Attribute.Email\n | Schema.Attribute.UID;\n }\n) => {\n return attr.maxLength && _.isInteger(attr.maxLength) ? validator.max(attr.maxLength) : validator;\n};\n\n/**\n * Adds min integer validator\n * @returns {NumberSchema}\n */\nconst addMinIntegerValidator = (\n validator: yup.NumberSchema,\n {\n attr,\n }: {\n attr: Schema.Attribute.Integer | Schema.Attribute.BigInteger;\n }\n) => (_.isNumber(attr.min) ? validator.min(_.toInteger(attr.min)) : validator);\n\n/**\n * Adds max integer validator\n */\nconst addMaxIntegerValidator = (\n validator: yup.NumberSchema,\n {\n attr,\n }: {\n attr: Schema.Attribute.Integer | Schema.Attribute.BigInteger;\n }\n) => (_.isNumber(attr.max) ? validator.max(_.toInteger(attr.max)) : validator);\n\n/**\n * Adds min float/decimal validator\n */\nconst addMinFloatValidator = (\n validator: yup.NumberSchema,\n {\n attr,\n }: {\n attr: Schema.Attribute.Decimal | Schema.Attribute.Float;\n }\n) => (_.isNumber(attr.min) ? validator.min(attr.min) : validator);\n\n/**\n * Adds max float/decimal validator\n */\nconst addMaxFloatValidator = (\n validator: yup.NumberSchema,\n {\n attr,\n }: {\n attr: Schema.Attribute.Decimal | Schema.Attribute.Float;\n }\n) => (_.isNumber(attr.max) ? validator.max(attr.max) : validator);\n\n/**\n * Adds regex validator\n */\nconst addStringRegexValidator = (\n validator: yup.StringSchema,\n {\n attr,\n }: {\n attr:\n | Schema.Attribute.String\n | Schema.Attribute.Text\n | Schema.Attribute.RichText\n | Schema.Attribute.Password\n | Schema.Attribute.Email\n | Schema.Attribute.UID;\n }\n) => {\n return 'regex' in attr && !_.isUndefined(attr.regex)\n ? validator.matches(new RegExp(attr.regex), { excludeEmptyString: !attr.required })\n : validator;\n};\n\n/**\n * Adds unique validator\n */\nconst addUniqueValidator = <T extends yup.AnySchema>(\n validator: T,\n {\n attr,\n model,\n updatedAttribute,\n entity,\n componentContext,\n }: ValidatorMetas<Schema.Attribute.AnyAttribute & Schema.Attribute.UniqueOption>,\n options: ValidatorOptions\n): T => {\n if (attr.type !== 'uid' && !attr.unique) {\n return validator;\n }\n\n return validator.test('unique', 'This attribute must be unique', async (value) => {\n const isPublish = options.isDraft === false;\n\n /**\n * If the attribute value is `null` we want to skip the unique validation.\n * Otherwise it'll only accept a single `null` entry in the database.\n */\n if (_.isNil(value)) {\n return true;\n }\n\n /**\n * If we are updating a draft and the value is unchanged we skip the unique verification. This will\n * prevent the validator to be triggered in case the user activated the\n * unique constraint after already creating multiple entries with\n * the same attribute value for that field.\n */\n if (!isPublish && value === entity?.[updatedAttribute.name]) {\n return true;\n }\n\n let queryUid: string;\n let queryWhere: Record<string, any> = {};\n\n if (componentContext) {\n const hasRepeatableData = componentContext.repeatableData.length > 0;\n if (hasRepeatableData) {\n // If we are validating a unique field within a repeatable component,\n // we first need to ensure that the repeatable in the current entity is\n // valid against itself.\n\n const { name: updatedName, value: updatedValue } = updatedAttribute;\n // Construct the full path to the unique field within the component.\n const pathToCheck = [...componentContext.pathToComponent.slice(1), updatedName].join('.');\n\n // Extract the values from the repeatable data using the constructed path\n const values = componentContext.repeatableData.map((item) => {\n return pathToCheck.split('.').reduce((acc, key) => acc[key], item as any);\n });\n\n // Check if the value is repeated in the current entity\n const isUpdatedAttributeRepeatedInThisEntity =\n values.filter((value) => value === updatedValue).length > 1;\n\n if (isUpdatedAttributeRepeatedInThisEntity) {\n return false;\n }\n }\n\n /**\n * When `componentContext` is present it means we are dealing with a unique\n * field within a component.\n *\n * The unique validation must consider the specific context of the\n * component, which will always be contained within a parent content type\n * and may also be nested within another component.\n *\n * We construct a query that takes into account the parent's model UID,\n * dimensions (such as draft and publish state/locale) and excludes the current\n * content type entity by its ID if provided.\n */\n const {\n model: parentModel,\n options: parentOptions,\n id: excludeId,\n } = componentContext.parentContent;\n queryUid = parentModel.uid;\n\n const whereConditions: Record<string, any> = {};\n const isParentDraft = parentOptions && parentOptions.isDraft;\n\n whereConditions.publishedAt = isParentDraft ? null : { $notNull: true };\n\n if (parentOptions?.locale) {\n whereConditions.locale = parentOptions.locale;\n }\n\n if (excludeId && !Number.isNaN(excludeId)) {\n whereConditions.id = { $ne: excludeId };\n }\n\n queryWhere = {\n ...componentContext.pathToComponent.reduceRight((acc, key) => ({ [key]: acc }), {\n [updatedAttribute.name]: value,\n }),\n\n ...whereConditions,\n };\n } else {\n /**\n * Here we are validating a scalar unique field from the content type's schema.\n * We construct a query to check if the value is unique\n * considering dimensions (e.g. locale, publication state) and excluding the current entity by its ID if available.\n */\n queryUid = model.uid;\n const scalarAttributeWhere: Record<string, any> = {\n [updatedAttribute.name]: value,\n };\n\n scalarAttributeWhere.publishedAt = options.isDraft ? null : { $notNull: true };\n\n if (options?.locale) {\n scalarAttributeWhere.locale = options.locale;\n }\n\n if (entity?.id) {\n scalarAttributeWhere.id = { $ne: entity.id };\n }\n\n queryWhere = scalarAttributeWhere;\n }\n\n // The validation should pass if there is no other record found from the query\n // TODO query not working for dynamic zones (type === relation)\n return !(await strapi.db.query(queryUid).findOne({ where: queryWhere }));\n });\n};\n\n/* Type validators */\n\nconst stringValidator = (\n metas: ValidatorMetas<\n | Schema.Attribute.String\n | Schema.Attribute.Text\n | Schema.Attribute.RichText\n | Schema.Attribute.Password\n | Schema.Attribute.Email\n | Schema.Attribute.UID\n >,\n options: ValidatorOptions\n) => {\n let schema = yup.string().transform((val, originalVal) => originalVal);\n\n schema = addMinLengthValidator(schema, metas, options);\n schema = addMaxLengthValidator(schema, metas);\n schema = addStringRegexValidator(schema, metas);\n schema = addUniqueValidator(schema, metas, options);\n\n return schema;\n};\n\nconst emailValidator = (\n metas: ValidatorMetas<Schema.Attribute.Email>,\n options: ValidatorOptions\n) => {\n const schema = stringValidator(metas, options);\n return schema.email().min(1, '${path} cannot be empty');\n};\n\nconst uidValidator = (metas: ValidatorMetas<Schema.Attribute.UID>, options: ValidatorOptions) => {\n const schema = stringValidator(metas, options);\n\n return schema.matches(/^[A-Za-z0-9-_.~]*$/);\n};\n\nconst enumerationValidator = ({ attr }: { attr: Schema.Attribute.Enumeration }) => {\n return yup\n .string()\n .oneOf((Array.isArray(attr.enum) ? attr.enum : [attr.enum]).concat(null as any));\n};\n\nconst integerValidator = (\n metas: ValidatorMetas<Schema.Attribute.Integer | Schema.Attribute.BigInteger>,\n options: ValidatorOptions\n) => {\n let schema = yup.number().integer();\n\n schema = addMinIntegerValidator(schema, metas);\n schema = addMaxIntegerValidator(schema, metas);\n schema = addUniqueValidator(schema, metas, options);\n\n return schema;\n};\n\nconst floatValidator = (\n metas: ValidatorMetas<Schema.Attribute.Decimal | Schema.Attribute.Float>,\n options: ValidatorOptions\n) => {\n let schema = yup.number();\n schema = addMinFloatValidator(schema, metas);\n schema = addMaxFloatValidator(schema, metas);\n schema = addUniqueValidator(schema, metas, options);\n\n return schema;\n};\n\nconst bigintegerValidator = (\n metas: ValidatorMetas<Schema.Attribute.BigInteger>,\n options: ValidatorOptions\n) => {\n const schema = yup.mixed();\n return addUniqueValidator(schema, metas, options);\n};\n\nconst datesValidator = (\n metas: ValidatorMetas<\n | Schema.Attribute.Date\n | Schema.Attribute.DateTime\n | Schema.Attribute.Time\n | Schema.Attribute.Timestamp\n >,\n options: ValidatorOptions\n) => {\n const schema = yup.mixed();\n return addUniqueValidator(schema, metas, options);\n};\n\nexport default {\n string: stringValidator,\n text: stringValidator,\n richtext: stringValidator,\n password: stringValidator,\n email: emailValidator,\n enumeration: enumerationValidator,\n boolean: () => yup.boolean(),\n uid: uidValidator,\n json: () => yup.mixed(),\n integer: integerValidator,\n biginteger: bigintegerValidator,\n float: floatValidator,\n decimal: floatValidator,\n date: datesValidator,\n time: datesValidator,\n datetime: datesValidator,\n timestamp: datesValidator,\n blocks: blocksValidator,\n};\n"],"names":["_","value","yup"],"mappings":";;;;;;AAyBA,MAAM,wBAAwB,CAC5B,WACA;AAAA,EACE;AACF,GASA,EAAE,cACC;AACH,SAAO,KAAK,aAAaA,WAAE,QAAA,UAAU,KAAK,SAAS,KAAK,CAAC,UACrD,UAAU,IAAI,KAAK,SAAS,IAC5B;AACN;AAMA,MAAM,wBAAwB,CAC5B,WACA;AAAA,EACE;AACF,MASG;AACI,SAAA,KAAK,aAAaA,mBAAE,UAAU,KAAK,SAAS,IAAI,UAAU,IAAI,KAAK,SAAS,IAAI;AACzF;AAMA,MAAM,yBAAyB,CAC7B,WACA;AAAA,EACE;AACF,MAGIA,WAAE,QAAA,SAAS,KAAK,GAAG,IAAI,UAAU,IAAIA,WAAAA,QAAE,UAAU,KAAK,GAAG,CAAC,IAAI;AAKpE,MAAM,yBAAyB,CAC7B,WACA;AAAA,EACE;AACF,MAGIA,WAAE,QAAA,SAAS,KAAK,GAAG,IAAI,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ASA,gBAAI;AACZ,SAAA,mBAAmB,QAAQ,OAAO,OAAO;AAClD;AAEA,MAAe,aAAA;AAAA,EACb,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,UAAU;AAAA,EACV,UAAU;AAAA,EACV,OAAO;AAAA,EACP,aAAa;AAAA,EACb,SAAS,MAAMA,YAAA,IAAI,QAAQ;AAAA,EAC3B,KAAK;AAAA,EACL,MAAM,MAAMA,YAAA,IAAI,MAAM;AAAA,EACtB,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,OAAO;AAAA,EACP,SAAS;AAAA,EACT,MAAM;AAAA,EACN,MAAM;AAAA,EACN,UAAU;AAAA,EACV,WAAW;AAAA,EACX,QAAQ;AACV;;"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import _ from "lodash";
|
|
2
|
-
import
|
|
2
|
+
import { yup } from "@strapi/utils";
|
|
3
3
|
import blocksValidator from "./blocks-validator.mjs";
|
|
4
|
-
const { yup } = strapiUtils;
|
|
5
4
|
const addMinLengthValidator = (validator, {
|
|
6
5
|
attr
|
|
7
6
|
}, { isDraft }) => {
|
|
@@ -29,7 +28,13 @@ const addStringRegexValidator = (validator, {
|
|
|
29
28
|
}) => {
|
|
30
29
|
return "regex" in attr && !_.isUndefined(attr.regex) ? validator.matches(new RegExp(attr.regex), { excludeEmptyString: !attr.required }) : validator;
|
|
31
30
|
};
|
|
32
|
-
const addUniqueValidator = (validator, {
|
|
31
|
+
const addUniqueValidator = (validator, {
|
|
32
|
+
attr,
|
|
33
|
+
model,
|
|
34
|
+
updatedAttribute,
|
|
35
|
+
entity,
|
|
36
|
+
componentContext
|
|
37
|
+
}, options) => {
|
|
33
38
|
if (attr.type !== "uid" && !attr.unique) {
|
|
34
39
|
return validator;
|
|
35
40
|
}
|
|
@@ -41,15 +46,57 @@ const addUniqueValidator = (validator, { attr, model, updatedAttribute, entity }
|
|
|
41
46
|
if (!isPublish && value === entity?.[updatedAttribute.name]) {
|
|
42
47
|
return true;
|
|
43
48
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
let queryUid;
|
|
50
|
+
let queryWhere = {};
|
|
51
|
+
if (componentContext) {
|
|
52
|
+
const hasRepeatableData = componentContext.repeatableData.length > 0;
|
|
53
|
+
if (hasRepeatableData) {
|
|
54
|
+
const { name: updatedName, value: updatedValue } = updatedAttribute;
|
|
55
|
+
const pathToCheck = [...componentContext.pathToComponent.slice(1), updatedName].join(".");
|
|
56
|
+
const values = componentContext.repeatableData.map((item) => {
|
|
57
|
+
return pathToCheck.split(".").reduce((acc, key) => acc[key], item);
|
|
58
|
+
});
|
|
59
|
+
const isUpdatedAttributeRepeatedInThisEntity = values.filter((value2) => value2 === updatedValue).length > 1;
|
|
60
|
+
if (isUpdatedAttributeRepeatedInThisEntity) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
50
63
|
}
|
|
51
|
-
|
|
52
|
-
|
|
64
|
+
const {
|
|
65
|
+
model: parentModel,
|
|
66
|
+
options: parentOptions,
|
|
67
|
+
id: excludeId
|
|
68
|
+
} = componentContext.parentContent;
|
|
69
|
+
queryUid = parentModel.uid;
|
|
70
|
+
const whereConditions = {};
|
|
71
|
+
const isParentDraft = parentOptions && parentOptions.isDraft;
|
|
72
|
+
whereConditions.publishedAt = isParentDraft ? null : { $notNull: true };
|
|
73
|
+
if (parentOptions?.locale) {
|
|
74
|
+
whereConditions.locale = parentOptions.locale;
|
|
75
|
+
}
|
|
76
|
+
if (excludeId && !Number.isNaN(excludeId)) {
|
|
77
|
+
whereConditions.id = { $ne: excludeId };
|
|
78
|
+
}
|
|
79
|
+
queryWhere = {
|
|
80
|
+
...componentContext.pathToComponent.reduceRight((acc, key) => ({ [key]: acc }), {
|
|
81
|
+
[updatedAttribute.name]: value
|
|
82
|
+
}),
|
|
83
|
+
...whereConditions
|
|
84
|
+
};
|
|
85
|
+
} else {
|
|
86
|
+
queryUid = model.uid;
|
|
87
|
+
const scalarAttributeWhere = {
|
|
88
|
+
[updatedAttribute.name]: value
|
|
89
|
+
};
|
|
90
|
+
scalarAttributeWhere.publishedAt = options.isDraft ? null : { $notNull: true };
|
|
91
|
+
if (options?.locale) {
|
|
92
|
+
scalarAttributeWhere.locale = options.locale;
|
|
93
|
+
}
|
|
94
|
+
if (entity?.id) {
|
|
95
|
+
scalarAttributeWhere.id = { $ne: entity.id };
|
|
96
|
+
}
|
|
97
|
+
queryWhere = scalarAttributeWhere;
|
|
98
|
+
}
|
|
99
|
+
return !await strapi.db.query(queryUid).findOne({ where: queryWhere });
|
|
53
100
|
});
|
|
54
101
|
};
|
|
55
102
|
const stringValidator = (metas, options) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.mjs","sources":["../../../src/services/entity-validator/validators.ts"],"sourcesContent":["import _ from 'lodash';\nimport strapiUtils from '@strapi/utils';\nimport type { Attribute, Schema } from '@strapi/types';\nimport blocksValidator from './blocks-validator';\n\nconst { yup } = strapiUtils;\n\ninterface ValidatorMetas<TAttribute extends Attribute.Any> {\n attr: TAttribute;\n model: Schema.ContentType;\n updatedAttribute: { name: string; value: unknown };\n entity: Record<string, unknown> | null;\n}\n\ninterface ValidatorOptions {\n isDraft: boolean;\n locale?: string;\n}\n\n/* Validator utils */\n\n/**\n * Adds minLength validator\n */\nconst addMinLengthValidator = (\n validator: strapiUtils.yup.StringSchema,\n {\n attr,\n }: {\n attr:\n | Attribute.String\n | Attribute.Text\n | Attribute.RichText\n | Attribute.Password\n | Attribute.Email\n | Attribute.UID;\n },\n { isDraft }: ValidatorOptions\n) => {\n return attr.minLength && _.isInteger(attr.minLength) && !isDraft\n ? validator.min(attr.minLength)\n : validator;\n};\n\n/**\n * Adds maxLength validator\n * @returns {StringSchema}\n */\nconst addMaxLengthValidator = (\n validator: strapiUtils.yup.StringSchema,\n {\n attr,\n }: {\n attr:\n | Attribute.String\n | Attribute.Text\n | Attribute.RichText\n | Attribute.Password\n | Attribute.Email\n | Attribute.UID;\n }\n) => {\n return attr.maxLength && _.isInteger(attr.maxLength) ? validator.max(attr.maxLength) : validator;\n};\n\n/**\n * Adds min integer validator\n * @returns {NumberSchema}\n */\nconst addMinIntegerValidator = (\n validator: strapiUtils.yup.NumberSchema,\n {\n attr,\n }: {\n attr: Attribute.Integer | Attribute.BigInteger;\n }\n) => (_.isNumber(attr.min) ? validator.min(_.toInteger(attr.min)) : validator);\n\n/**\n * Adds max integer validator\n */\nconst addMaxIntegerValidator = (\n validator: strapiUtils.yup.NumberSchema,\n {\n attr,\n }: {\n attr: Attribute.Integer | Attribute.BigInteger;\n }\n) => (_.isNumber(attr.max) ? validator.max(_.toInteger(attr.max)) : validator);\n\n/**\n * Adds min float/decimal validator\n */\nconst addMinFloatValidator = (\n validator: strapiUtils.yup.NumberSchema,\n {\n attr,\n }: {\n attr: Attribute.Decimal | Attribute.Float;\n }\n) => (_.isNumber(attr.min) ? validator.min(attr.min) : validator);\n\n/**\n * Adds max float/decimal validator\n */\nconst addMaxFloatValidator = (\n validator: strapiUtils.yup.NumberSchema,\n {\n attr,\n }: {\n attr: Attribute.Decimal | Attribute.Float;\n }\n) => (_.isNumber(attr.max) ? validator.max(attr.max) : validator);\n\n/**\n * Adds regex validator\n */\nconst addStringRegexValidator = (\n validator: strapiUtils.yup.StringSchema,\n {\n attr,\n }: {\n attr:\n | Attribute.String\n | Attribute.Text\n | Attribute.RichText\n | Attribute.Password\n | Attribute.Email\n | Attribute.UID;\n }\n) => {\n return 'regex' in attr && !_.isUndefined(attr.regex)\n ? validator.matches(new RegExp(attr.regex), { excludeEmptyString: !attr.required })\n : validator;\n};\n\n/**\n * Adds unique validator\n */\nconst addUniqueValidator = <T extends strapiUtils.yup.AnySchema>(\n validator: T,\n { attr, model, updatedAttribute, entity }: ValidatorMetas<Attribute.Any & Attribute.UniqueOption>,\n options: ValidatorOptions\n): T => {\n if (attr.type !== 'uid' && !attr.unique) {\n return validator;\n }\n\n return validator.test('unique', 'This attribute must be unique', async (value) => {\n const isPublish = options.isDraft === false;\n\n /**\n * If the attribute value is `null` we want to skip the unique validation.\n * Otherwise it'll only accept a single `null` entry in the database.\n */\n if (_.isNil(value)) {\n return true;\n }\n\n /**\n * If we are updating a draft and the value is unchanged we skip the unique verification. This will\n * prevent the validator to be triggered in case the user activated the\n * unique constraint after already creating multiple entries with\n * the same attribute value for that field.\n */\n if (!isPublish && value === entity?.[updatedAttribute.name]) {\n return true;\n }\n\n /**\n * At this point we know that we are creating a new entry, publishing an entry or that the unique field value has changed\n * We check if there is an entry of this content type in the same locale, publication state and with the same unique field value\n */\n const record = await strapi.db.query(model.uid).findOne({\n where: {\n locale: options.locale,\n publishedAt: options.isDraft ? null : { $notNull: true },\n [updatedAttribute.name]: value,\n ...(entity?.id ? { id: { $ne: entity.id } } : {}),\n },\n });\n\n return !record;\n });\n};\n\n/* Type validators */\n\nconst stringValidator = (\n metas: ValidatorMetas<\n | Attribute.String\n | Attribute.Text\n | Attribute.RichText\n | Attribute.Password\n | Attribute.Email\n | Attribute.UID\n >,\n options: ValidatorOptions\n) => {\n let schema = yup.string().transform((val, originalVal) => originalVal);\n\n schema = addMinLengthValidator(schema, metas, options);\n schema = addMaxLengthValidator(schema, metas);\n schema = addStringRegexValidator(schema, metas);\n schema = addUniqueValidator(schema, metas, options);\n\n return schema;\n};\n\nconst emailValidator = (metas: ValidatorMetas<Attribute.Email>, options: ValidatorOptions) => {\n const schema = stringValidator(metas, options);\n return schema.email().min(1, '${path} cannot be empty');\n};\n\nconst uidValidator = (metas: ValidatorMetas<Attribute.UID>, options: ValidatorOptions) => {\n const schema = stringValidator(metas, options);\n\n return schema.matches(/^[A-Za-z0-9-_.~]*$/);\n};\n\nconst enumerationValidator = ({ attr }: { attr: Attribute.Enumeration }) => {\n return yup\n .string()\n .oneOf((Array.isArray(attr.enum) ? attr.enum : [attr.enum]).concat(null as any));\n};\n\nconst integerValidator = (\n metas: ValidatorMetas<Attribute.Integer | Attribute.BigInteger>,\n options: ValidatorOptions\n) => {\n let schema = yup.number().integer();\n\n schema = addMinIntegerValidator(schema, metas);\n schema = addMaxIntegerValidator(schema, metas);\n schema = addUniqueValidator(schema, metas, options);\n\n return schema;\n};\n\nconst floatValidator = (\n metas: ValidatorMetas<Attribute.Decimal | Attribute.Float>,\n options: ValidatorOptions\n) => {\n let schema = yup.number();\n schema = addMinFloatValidator(schema, metas);\n schema = addMaxFloatValidator(schema, metas);\n schema = addUniqueValidator(schema, metas, options);\n\n return schema;\n};\n\nconst bigintegerValidator = (\n metas: ValidatorMetas<Attribute.BigInteger>,\n options: ValidatorOptions\n) => {\n const schema = yup.mixed();\n return addUniqueValidator(schema, metas, options);\n};\n\nconst datesValidator = (\n metas: ValidatorMetas<Attribute.Date | Attribute.DateTime | Attribute.Time | Attribute.Timestamp>,\n options: ValidatorOptions\n) => {\n const schema = yup.mixed();\n return addUniqueValidator(schema, metas, options);\n};\n\nexport default {\n string: stringValidator,\n text: stringValidator,\n richtext: stringValidator,\n password: stringValidator,\n email: emailValidator,\n enumeration: enumerationValidator,\n boolean: () => yup.boolean(),\n uid: uidValidator,\n json: () => yup.mixed(),\n integer: integerValidator,\n biginteger: bigintegerValidator,\n float: floatValidator,\n decimal: floatValidator,\n date: datesValidator,\n time: datesValidator,\n datetime: datesValidator,\n timestamp: datesValidator,\n blocks: blocksValidator,\n};\n"],"names":[],"mappings":";;;AAKA,MAAM,EAAE,IAAQ,IAAA;AAmBhB,MAAM,wBAAwB,CAC5B,WACA;AAAA,EACE;AACF,GASA,EAAE,cACC;AACH,SAAO,KAAK,aAAa,EAAE,UAAU,KAAK,SAAS,KAAK,CAAC,UACrD,UAAU,IAAI,KAAK,SAAS,IAC5B;AACN;AAMA,MAAM,wBAAwB,CAC5B,WACA;AAAA,EACE;AACF,MASG;AACI,SAAA,KAAK,aAAa,EAAE,UAAU,KAAK,SAAS,IAAI,UAAU,IAAI,KAAK,SAAS,IAAI;AACzF;AAMA,MAAM,yBAAyB,CAC7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,SAAA;AACT;AAEA,MAAM,sBAAsB,CAC1B,OACA,YACG;AACG,QAAA,SAAS,IAAI;AACZ,SAAA,mBAAmB,QAAQ,OAAO,OAAO;AAClD;AAEA,MAAM,iBAAiB,CACrB,OACA,YACG;AACG,QAAA,SAAS,IAAI;AACZ,SAAA,mBAAmB,QAAQ,OAAO,OAAO;AAClD;AAEA,MAAe,aAAA;AAAA,EACb,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,UAAU;AAAA,EACV,UAAU;AAAA,EACV,OAAO;AAAA,EACP,aAAa;AAAA,EACb,SAAS,MAAM,IAAI,QAAQ;AAAA,EAC3B,KAAK;AAAA,EACL,MAAM,MAAM,IAAI,MAAM;AAAA,EACtB,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,OAAO;AAAA,EACP,SAAS;AAAA,EACT,MAAM;AAAA,EACN,MAAM;AAAA,EACN,UAAU;AAAA,EACV,WAAW;AAAA,EACX,QAAQ;AACV;"}
|
|
1
|
+
{"version":3,"file":"validators.mjs","sources":["../../../src/services/entity-validator/validators.ts"],"sourcesContent":["import _ from 'lodash';\nimport { yup } from '@strapi/utils';\nimport type { Schema, Struct, Modules } from '@strapi/types';\nimport blocksValidator from './blocks-validator';\n\nimport type { ComponentContext } from '.';\n\ninterface ValidatorMetas<TAttribute extends Schema.Attribute.AnyAttribute> {\n attr: TAttribute;\n model: Struct.ContentTypeSchema;\n updatedAttribute: { name: string; value: unknown };\n entity: Modules.EntityValidator.Entity;\n componentContext: ComponentContext;\n}\n\ninterface ValidatorOptions {\n isDraft: boolean;\n locale?: string;\n}\n\n/* Validator utils */\n\n/**\n * Adds minLength validator\n */\nconst addMinLengthValidator = (\n validator: yup.StringSchema,\n {\n attr,\n }: {\n attr:\n | Schema.Attribute.String\n | Schema.Attribute.Text\n | Schema.Attribute.RichText\n | Schema.Attribute.Password\n | Schema.Attribute.Email\n | Schema.Attribute.UID;\n },\n { isDraft }: ValidatorOptions\n) => {\n return attr.minLength && _.isInteger(attr.minLength) && !isDraft\n ? validator.min(attr.minLength)\n : validator;\n};\n\n/**\n * Adds maxLength validator\n * @returns {StringSchema}\n */\nconst addMaxLengthValidator = (\n validator: yup.StringSchema,\n {\n attr,\n }: {\n attr:\n | Schema.Attribute.String\n | Schema.Attribute.Text\n | Schema.Attribute.RichText\n | Schema.Attribute.Password\n | Schema.Attribute.Email\n | Schema.Attribute.UID;\n }\n) => {\n return attr.maxLength && _.isInteger(attr.maxLength) ? validator.max(attr.maxLength) : validator;\n};\n\n/**\n * Adds min integer validator\n * @returns {NumberSchema}\n */\nconst addMinIntegerValidator = (\n validator: yup.NumberSchema,\n {\n attr,\n }: {\n attr: Schema.Attribute.Integer | Schema.Attribute.BigInteger;\n }\n) => (_.isNumber(attr.min) ? validator.min(_.toInteger(attr.min)) : validator);\n\n/**\n * Adds max integer validator\n */\nconst addMaxIntegerValidator = (\n validator: yup.NumberSchema,\n {\n attr,\n }: {\n attr: Schema.Attribute.Integer | Schema.Attribute.BigInteger;\n }\n) => (_.isNumber(attr.max) ? validator.max(_.toInteger(attr.max)) : validator);\n\n/**\n * Adds min float/decimal validator\n */\nconst addMinFloatValidator = (\n validator: yup.NumberSchema,\n {\n attr,\n }: {\n attr: Schema.Attribute.Decimal | Schema.Attribute.Float;\n }\n) => (_.isNumber(attr.min) ? validator.min(attr.min) : validator);\n\n/**\n * Adds max float/decimal validator\n */\nconst addMaxFloatValidator = (\n validator: yup.NumberSchema,\n {\n attr,\n }: {\n attr: Schema.Attribute.Decimal | Schema.Attribute.Float;\n }\n) => (_.isNumber(attr.max) ? validator.max(attr.max) : validator);\n\n/**\n * Adds regex validator\n */\nconst addStringRegexValidator = (\n validator: yup.StringSchema,\n {\n attr,\n }: {\n attr:\n | Schema.Attribute.String\n | Schema.Attribute.Text\n | Schema.Attribute.RichText\n | Schema.Attribute.Password\n | Schema.Attribute.Email\n | Schema.Attribute.UID;\n }\n) => {\n return 'regex' in attr && !_.isUndefined(attr.regex)\n ? validator.matches(new RegExp(attr.regex), { excludeEmptyString: !attr.required })\n : validator;\n};\n\n/**\n * Adds unique validator\n */\nconst addUniqueValidator = <T extends yup.AnySchema>(\n validator: T,\n {\n attr,\n model,\n updatedAttribute,\n entity,\n componentContext,\n }: ValidatorMetas<Schema.Attribute.AnyAttribute & Schema.Attribute.UniqueOption>,\n options: ValidatorOptions\n): T => {\n if (attr.type !== 'uid' && !attr.unique) {\n return validator;\n }\n\n return validator.test('unique', 'This attribute must be unique', async (value) => {\n const isPublish = options.isDraft === false;\n\n /**\n * If the attribute value is `null` we want to skip the unique validation.\n * Otherwise it'll only accept a single `null` entry in the database.\n */\n if (_.isNil(value)) {\n return true;\n }\n\n /**\n * If we are updating a draft and the value is unchanged we skip the unique verification. This will\n * prevent the validator to be triggered in case the user activated the\n * unique constraint after already creating multiple entries with\n * the same attribute value for that field.\n */\n if (!isPublish && value === entity?.[updatedAttribute.name]) {\n return true;\n }\n\n let queryUid: string;\n let queryWhere: Record<string, any> = {};\n\n if (componentContext) {\n const hasRepeatableData = componentContext.repeatableData.length > 0;\n if (hasRepeatableData) {\n // If we are validating a unique field within a repeatable component,\n // we first need to ensure that the repeatable in the current entity is\n // valid against itself.\n\n const { name: updatedName, value: updatedValue } = updatedAttribute;\n // Construct the full path to the unique field within the component.\n const pathToCheck = [...componentContext.pathToComponent.slice(1), updatedName].join('.');\n\n // Extract the values from the repeatable data using the constructed path\n const values = componentContext.repeatableData.map((item) => {\n return pathToCheck.split('.').reduce((acc, key) => acc[key], item as any);\n });\n\n // Check if the value is repeated in the current entity\n const isUpdatedAttributeRepeatedInThisEntity =\n values.filter((value) => value === updatedValue).length > 1;\n\n if (isUpdatedAttributeRepeatedInThisEntity) {\n return false;\n }\n }\n\n /**\n * When `componentContext` is present it means we are dealing with a unique\n * field within a component.\n *\n * The unique validation must consider the specific context of the\n * component, which will always be contained within a parent content type\n * and may also be nested within another component.\n *\n * We construct a query that takes into account the parent's model UID,\n * dimensions (such as draft and publish state/locale) and excludes the current\n * content type entity by its ID if provided.\n */\n const {\n model: parentModel,\n options: parentOptions,\n id: excludeId,\n } = componentContext.parentContent;\n queryUid = parentModel.uid;\n\n const whereConditions: Record<string, any> = {};\n const isParentDraft = parentOptions && parentOptions.isDraft;\n\n whereConditions.publishedAt = isParentDraft ? null : { $notNull: true };\n\n if (parentOptions?.locale) {\n whereConditions.locale = parentOptions.locale;\n }\n\n if (excludeId && !Number.isNaN(excludeId)) {\n whereConditions.id = { $ne: excludeId };\n }\n\n queryWhere = {\n ...componentContext.pathToComponent.reduceRight((acc, key) => ({ [key]: acc }), {\n [updatedAttribute.name]: value,\n }),\n\n ...whereConditions,\n };\n } else {\n /**\n * Here we are validating a scalar unique field from the content type's schema.\n * We construct a query to check if the value is unique\n * considering dimensions (e.g. locale, publication state) and excluding the current entity by its ID if available.\n */\n queryUid = model.uid;\n const scalarAttributeWhere: Record<string, any> = {\n [updatedAttribute.name]: value,\n };\n\n scalarAttributeWhere.publishedAt = options.isDraft ? null : { $notNull: true };\n\n if (options?.locale) {\n scalarAttributeWhere.locale = options.locale;\n }\n\n if (entity?.id) {\n scalarAttributeWhere.id = { $ne: entity.id };\n }\n\n queryWhere = scalarAttributeWhere;\n }\n\n // The validation should pass if there is no other record found from the query\n // TODO query not working for dynamic zones (type === relation)\n return !(await strapi.db.query(queryUid).findOne({ where: queryWhere }));\n });\n};\n\n/* Type validators */\n\nconst stringValidator = (\n metas: ValidatorMetas<\n | Schema.Attribute.String\n | Schema.Attribute.Text\n | Schema.Attribute.RichText\n | Schema.Attribute.Password\n | Schema.Attribute.Email\n | Schema.Attribute.UID\n >,\n options: ValidatorOptions\n) => {\n let schema = yup.string().transform((val, originalVal) => originalVal);\n\n schema = addMinLengthValidator(schema, metas, options);\n schema = addMaxLengthValidator(schema, metas);\n schema = addStringRegexValidator(schema, metas);\n schema = addUniqueValidator(schema, metas, options);\n\n return schema;\n};\n\nconst emailValidator = (\n metas: ValidatorMetas<Schema.Attribute.Email>,\n options: ValidatorOptions\n) => {\n const schema = stringValidator(metas, options);\n return schema.email().min(1, '${path} cannot be empty');\n};\n\nconst uidValidator = (metas: ValidatorMetas<Schema.Attribute.UID>, options: ValidatorOptions) => {\n const schema = stringValidator(metas, options);\n\n return schema.matches(/^[A-Za-z0-9-_.~]*$/);\n};\n\nconst enumerationValidator = ({ attr }: { attr: Schema.Attribute.Enumeration }) => {\n return yup\n .string()\n .oneOf((Array.isArray(attr.enum) ? attr.enum : [attr.enum]).concat(null as any));\n};\n\nconst integerValidator = (\n metas: ValidatorMetas<Schema.Attribute.Integer | Schema.Attribute.BigInteger>,\n options: ValidatorOptions\n) => {\n let schema = yup.number().integer();\n\n schema = addMinIntegerValidator(schema, metas);\n schema = addMaxIntegerValidator(schema, metas);\n schema = addUniqueValidator(schema, metas, options);\n\n return schema;\n};\n\nconst floatValidator = (\n metas: ValidatorMetas<Schema.Attribute.Decimal | Schema.Attribute.Float>,\n options: ValidatorOptions\n) => {\n let schema = yup.number();\n schema = addMinFloatValidator(schema, metas);\n schema = addMaxFloatValidator(schema, metas);\n schema = addUniqueValidator(schema, metas, options);\n\n return schema;\n};\n\nconst bigintegerValidator = (\n metas: ValidatorMetas<Schema.Attribute.BigInteger>,\n options: ValidatorOptions\n) => {\n const schema = yup.mixed();\n return addUniqueValidator(schema, metas, options);\n};\n\nconst datesValidator = (\n metas: ValidatorMetas<\n | Schema.Attribute.Date\n | Schema.Attribute.DateTime\n | Schema.Attribute.Time\n | Schema.Attribute.Timestamp\n >,\n options: ValidatorOptions\n) => {\n const schema = yup.mixed();\n return addUniqueValidator(schema, metas, options);\n};\n\nexport default {\n string: stringValidator,\n text: stringValidator,\n richtext: stringValidator,\n password: stringValidator,\n email: emailValidator,\n enumeration: enumerationValidator,\n boolean: () => yup.boolean(),\n uid: uidValidator,\n json: () => yup.mixed(),\n integer: integerValidator,\n biginteger: bigintegerValidator,\n float: floatValidator,\n decimal: floatValidator,\n date: datesValidator,\n time: datesValidator,\n datetime: datesValidator,\n timestamp: datesValidator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,CACvB,OACA,YACG;AACH,MAAI,SAAS,IAAI,OAAO,EAAE,QAAQ;AAEzB,WAAA,uBAAuB,QAAQ,KAAK;AACpC,WAAA,uBAAuB,QAAQ,KAAK;AACpC,WAAA,mBAAmB,QAAQ,OAAO,OAAO;AAE3C,SAAA;AACT;AAEA,MAAM,iBAAiB,CACrB,OACA,YACG;AACC,MAAA,SAAS,IAAI;AACR,WAAA,qBAAqB,QAAQ,KAAK;AAClC,WAAA,qBAAqB,QAAQ,KAAK;AAClC,WAAA,mBAAmB,QAAQ,OAAO,OAAO;AAE3C,SAAA;AACT;AAEA,MAAM,sBAAsB,CAC1B,OACA,YACG;AACG,QAAA,SAAS,IAAI;AACZ,SAAA,mBAAmB,QAAQ,OAAO,OAAO;AAClD;AAEA,MAAM,iBAAiB,CACrB,OAMA,YACG;AACG,QAAA,SAAS,IAAI;AACZ,SAAA,mBAAmB,QAAQ,OAAO,OAAO;AAClD;AAEA,MAAe,aAAA;AAAA,EACb,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,UAAU;AAAA,EACV,UAAU;AAAA,EACV,OAAO;AAAA,EACP,aAAa;AAAA,EACb,SAAS,MAAM,IAAI,QAAQ;AAAA,EAC3B,KAAK;AAAA,EACL,MAAM,MAAM,IAAI,MAAM;AAAA,EACtB,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,OAAO;AAAA,EACP,SAAS;AAAA,EACT,MAAM;AAAA,EACN,MAAM;AAAA,EACN,UAAU;AAAA,EACV,WAAW;AAAA,EACX,QAAQ;AACV;"}
|
|
@@ -10,6 +10,7 @@ export interface EventHub {
|
|
|
10
10
|
destroy(): EventHub;
|
|
11
11
|
removeListener(eventName: string, listener: Listener): void;
|
|
12
12
|
removeAllListeners(): EventHub;
|
|
13
|
+
removeAllSubscribers(): EventHub;
|
|
13
14
|
addListener(eventName: string, listener: Listener): () => void;
|
|
14
15
|
}
|
|
15
16
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-hub.d.ts","sourceRoot":"","sources":["../../src/services/event-hub.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAC9E,MAAM,MAAM,QAAQ,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAEzD,MAAM,WAAW,QAAQ;IACvB,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3D,SAAS,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,IAAI,CAAC;IAC9C,WAAW,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI,CAAC;IAC1C,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,MAAM,IAAI,CAAC;IACtD,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;IACjD,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,MAAM,IAAI,CAAC;IACxD,OAAO,IAAI,QAAQ,CAAC;IACpB,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC5D,kBAAkB,IAAI,QAAQ,CAAC;IAC/B,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,MAAM,IAAI,CAAC;CAChE;AAED;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,cAAc,IAAI,QAAQ,
|
|
1
|
+
{"version":3,"file":"event-hub.d.ts","sourceRoot":"","sources":["../../src/services/event-hub.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAC9E,MAAM,MAAM,QAAQ,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAEzD,MAAM,WAAW,QAAQ;IACvB,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3D,SAAS,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,IAAI,CAAC;IAC9C,WAAW,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI,CAAC;IAC1C,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,MAAM,IAAI,CAAC;IACtD,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;IACjD,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,MAAM,IAAI,CAAC;IACxD,OAAO,IAAI,QAAQ,CAAC;IACpB,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC5D,kBAAkB,IAAI,QAAQ,CAAC;IAC/B,oBAAoB,IAAI,QAAQ,CAAC;IACjC,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,MAAM,IAAI,CAAC;CAChE;AAED;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,cAAc,IAAI,QAAQ,CA0FjD"}
|
|
@@ -38,7 +38,7 @@ function createEventHub() {
|
|
|
38
38
|
};
|
|
39
39
|
},
|
|
40
40
|
off(eventName, listener) {
|
|
41
|
-
listeners.get(eventName)
|
|
41
|
+
listeners.get(eventName)?.splice(listeners.get(eventName).indexOf(listener), 1);
|
|
42
42
|
},
|
|
43
43
|
once(eventName, listener) {
|
|
44
44
|
return eventHub.on(eventName, async (...args) => {
|
|
@@ -47,15 +47,20 @@ function createEventHub() {
|
|
|
47
47
|
});
|
|
48
48
|
},
|
|
49
49
|
destroy() {
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
this.removeAllListeners();
|
|
51
|
+
this.removeAllSubscribers();
|
|
52
52
|
return this;
|
|
53
53
|
},
|
|
54
54
|
removeListener(eventName, listener) {
|
|
55
55
|
return eventHub.off(eventName, listener);
|
|
56
56
|
},
|
|
57
57
|
removeAllListeners() {
|
|
58
|
-
|
|
58
|
+
listeners.clear();
|
|
59
|
+
return this;
|
|
60
|
+
},
|
|
61
|
+
removeAllSubscribers() {
|
|
62
|
+
subscribers.length = 0;
|
|
63
|
+
return this;
|
|
59
64
|
},
|
|
60
65
|
addListener(eventName, listener) {
|
|
61
66
|
return eventHub.on(eventName, listener);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-hub.js","sources":["../../src/services/event-hub.ts"],"sourcesContent":["export type Subscriber = (eventName: string, ...args: any[]) => Promise<void>;\nexport type Listener = (...args: any[]) => Promise<void>;\n\nexport interface EventHub {\n emit(eventName: string, ...args: unknown[]): Promise<void>;\n subscribe(subscriber: Subscriber): () => void;\n unsubscribe(subscriber: Subscriber): void;\n on(eventName: string, listener: Listener): () => void;\n off(eventName: string, listener: Listener): void;\n once(eventName: string, listener: Listener): () => void;\n destroy(): EventHub;\n removeListener(eventName: string, listener: Listener): void;\n removeAllListeners(): EventHub;\n addListener(eventName: string, listener: Listener): () => void;\n}\n\n/**\n * The event hub is Strapi's event control center.\n */\nexport default function createEventHub(): EventHub {\n const listeners = new Map();\n\n // Default subscriber to easily add listeners with the on() method\n const defaultSubscriber = async (eventName: string, ...args: unknown[]) => {\n if (listeners.has(eventName)) {\n for (const listener of listeners.get(eventName)) {\n await listener(...args);\n }\n }\n };\n\n // Store of subscribers that will be called when an event is emitted\n const subscribers = [defaultSubscriber];\n\n const eventHub: EventHub = {\n async emit(eventName, ...args) {\n for (const subscriber of subscribers) {\n await subscriber(eventName, ...args);\n }\n },\n\n subscribe(subscriber) {\n subscribers.push(subscriber);\n\n // Return a function to remove the subscriber\n return () => {\n eventHub.unsubscribe(subscriber);\n };\n },\n\n unsubscribe(subscriber) {\n const subscriberIndex = subscribers.indexOf(subscriber);\n\n // Only remove the subscriber if it exists\n if (subscriberIndex >= 0) {\n subscribers.splice(subscriberIndex, 1);\n }\n },\n\n on(eventName, listener) {\n if (!listeners.has(eventName)) {\n listeners.set(eventName, [listener]);\n } else {\n listeners.get(eventName).push(listener);\n }\n\n // Return a function to remove the listener\n return () => {\n eventHub.off(eventName, listener);\n };\n },\n\n off(eventName, listener) {\n listeners.get(eventName)
|
|
1
|
+
{"version":3,"file":"event-hub.js","sources":["../../src/services/event-hub.ts"],"sourcesContent":["export type Subscriber = (eventName: string, ...args: any[]) => Promise<void>;\nexport type Listener = (...args: any[]) => Promise<void>;\n\nexport interface EventHub {\n emit(eventName: string, ...args: unknown[]): Promise<void>;\n subscribe(subscriber: Subscriber): () => void;\n unsubscribe(subscriber: Subscriber): void;\n on(eventName: string, listener: Listener): () => void;\n off(eventName: string, listener: Listener): void;\n once(eventName: string, listener: Listener): () => void;\n destroy(): EventHub;\n removeListener(eventName: string, listener: Listener): void;\n removeAllListeners(): EventHub;\n removeAllSubscribers(): EventHub;\n addListener(eventName: string, listener: Listener): () => void;\n}\n\n/**\n * The event hub is Strapi's event control center.\n */\nexport default function createEventHub(): EventHub {\n const listeners = new Map();\n\n // Default subscriber to easily add listeners with the on() method\n const defaultSubscriber = async (eventName: string, ...args: unknown[]) => {\n if (listeners.has(eventName)) {\n for (const listener of listeners.get(eventName)) {\n await listener(...args);\n }\n }\n };\n\n // Store of subscribers that will be called when an event is emitted\n const subscribers = [defaultSubscriber];\n\n const eventHub: EventHub = {\n async emit(eventName, ...args) {\n for (const subscriber of subscribers) {\n await subscriber(eventName, ...args);\n }\n },\n\n subscribe(subscriber) {\n subscribers.push(subscriber);\n\n // Return a function to remove the subscriber\n return () => {\n eventHub.unsubscribe(subscriber);\n };\n },\n\n unsubscribe(subscriber) {\n const subscriberIndex = subscribers.indexOf(subscriber);\n\n // Only remove the subscriber if it exists\n if (subscriberIndex >= 0) {\n subscribers.splice(subscriberIndex, 1);\n }\n },\n\n on(eventName, listener) {\n if (!listeners.has(eventName)) {\n listeners.set(eventName, [listener]);\n } else {\n listeners.get(eventName).push(listener);\n }\n\n // Return a function to remove the listener\n return () => {\n eventHub.off(eventName, listener);\n };\n },\n\n off(eventName, listener) {\n listeners.get(eventName)?.splice(listeners.get(eventName).indexOf(listener), 1);\n },\n\n once(eventName, listener) {\n return eventHub.on(eventName, async (...args) => {\n eventHub.off(eventName, listener);\n return listener(...args);\n });\n },\n\n destroy() {\n this.removeAllListeners();\n this.removeAllSubscribers();\n return this;\n },\n\n removeListener(eventName, listener) {\n return eventHub.off(eventName, listener);\n },\n\n removeAllListeners() {\n listeners.clear();\n return this;\n },\n\n removeAllSubscribers() {\n subscribers.length = 0;\n return this;\n },\n\n addListener(eventName, listener) {\n return eventHub.on(eventName, listener);\n },\n };\n\n return eventHub;\n}\n"],"names":[],"mappings":";AAoBA,SAAwB,iBAA2B;AAC3C,QAAA,gCAAgB;AAGhB,QAAA,oBAAoB,OAAO,cAAsB,SAAoB;AACrE,QAAA,UAAU,IAAI,SAAS,GAAG;AAC5B,iBAAW,YAAY,UAAU,IAAI,SAAS,GAAG;AACzC,cAAA,SAAS,GAAG,IAAI;AAAA,MACxB;AAAA,IACF;AAAA,EAAA;AAII,QAAA,cAAc,CAAC,iBAAiB;AAEtC,QAAM,WAAqB;AAAA,IACzB,MAAM,KAAK,cAAc,MAAM;AAC7B,iBAAW,cAAc,aAAa;AAC9B,cAAA,WAAW,WAAW,GAAG,IAAI;AAAA,MACrC;AAAA,IACF;AAAA,IAEA,UAAU,YAAY;AACpB,kBAAY,KAAK,UAAU;AAG3B,aAAO,MAAM;AACX,iBAAS,YAAY,U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
|
-
listeners.get(eventName)
|
|
40
|
+
listeners.get(eventName)?.splice(listeners.get(eventName).indexOf(listener), 1);
|
|
41
41
|
},
|
|
42
42
|
once(eventName, listener) {
|
|
43
43
|
return eventHub.on(eventName, async (...args) => {
|
|
@@ -46,15 +46,20 @@ function createEventHub() {
|
|
|
46
46
|
});
|
|
47
47
|
},
|
|
48
48
|
destroy() {
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
this.removeAllListeners();
|
|
50
|
+
this.removeAllSubscribers();
|
|
51
51
|
return this;
|
|
52
52
|
},
|
|
53
53
|
removeListener(eventName, listener) {
|
|
54
54
|
return eventHub.off(eventName, listener);
|
|
55
55
|
},
|
|
56
56
|
removeAllListeners() {
|
|
57
|
-
|
|
57
|
+
listeners.clear();
|
|
58
|
+
return this;
|
|
59
|
+
},
|
|
60
|
+
removeAllSubscribers() {
|
|
61
|
+
subscribers.length = 0;
|
|
62
|
+
return this;
|
|
58
63
|
},
|
|
59
64
|
addListener(eventName, listener) {
|
|
60
65
|
return eventHub.on(eventName, listener);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-hub.mjs","sources":["../../src/services/event-hub.ts"],"sourcesContent":["export type Subscriber = (eventName: string, ...args: any[]) => Promise<void>;\nexport type Listener = (...args: any[]) => Promise<void>;\n\nexport interface EventHub {\n emit(eventName: string, ...args: unknown[]): Promise<void>;\n subscribe(subscriber: Subscriber): () => void;\n unsubscribe(subscriber: Subscriber): void;\n on(eventName: string, listener: Listener): () => void;\n off(eventName: string, listener: Listener): void;\n once(eventName: string, listener: Listener): () => void;\n destroy(): EventHub;\n removeListener(eventName: string, listener: Listener): void;\n removeAllListeners(): EventHub;\n addListener(eventName: string, listener: Listener): () => void;\n}\n\n/**\n * The event hub is Strapi's event control center.\n */\nexport default function createEventHub(): EventHub {\n const listeners = new Map();\n\n // Default subscriber to easily add listeners with the on() method\n const defaultSubscriber = async (eventName: string, ...args: unknown[]) => {\n if (listeners.has(eventName)) {\n for (const listener of listeners.get(eventName)) {\n await listener(...args);\n }\n }\n };\n\n // Store of subscribers that will be called when an event is emitted\n const subscribers = [defaultSubscriber];\n\n const eventHub: EventHub = {\n async emit(eventName, ...args) {\n for (const subscriber of subscribers) {\n await subscriber(eventName, ...args);\n }\n },\n\n subscribe(subscriber) {\n subscribers.push(subscriber);\n\n // Return a function to remove the subscriber\n return () => {\n eventHub.unsubscribe(subscriber);\n };\n },\n\n unsubscribe(subscriber) {\n const subscriberIndex = subscribers.indexOf(subscriber);\n\n // Only remove the subscriber if it exists\n if (subscriberIndex >= 0) {\n subscribers.splice(subscriberIndex, 1);\n }\n },\n\n on(eventName, listener) {\n if (!listeners.has(eventName)) {\n listeners.set(eventName, [listener]);\n } else {\n listeners.get(eventName).push(listener);\n }\n\n // Return a function to remove the listener\n return () => {\n eventHub.off(eventName, listener);\n };\n },\n\n off(eventName, listener) {\n listeners.get(eventName)
|
|
1
|
+
{"version":3,"file":"event-hub.mjs","sources":["../../src/services/event-hub.ts"],"sourcesContent":["export type Subscriber = (eventName: string, ...args: any[]) => Promise<void>;\nexport type Listener = (...args: any[]) => Promise<void>;\n\nexport interface EventHub {\n emit(eventName: string, ...args: unknown[]): Promise<void>;\n subscribe(subscriber: Subscriber): () => void;\n unsubscribe(subscriber: Subscriber): void;\n on(eventName: string, listener: Listener): () => void;\n off(eventName: string, listener: Listener): void;\n once(eventName: string, listener: Listener): () => void;\n destroy(): EventHub;\n removeListener(eventName: string, listener: Listener): void;\n removeAllListeners(): EventHub;\n removeAllSubscribers(): EventHub;\n addListener(eventName: string, listener: Listener): () => void;\n}\n\n/**\n * The event hub is Strapi's event control center.\n */\nexport default function createEventHub(): EventHub {\n const listeners = new Map();\n\n // Default subscriber to easily add listeners with the on() method\n const defaultSubscriber = async (eventName: string, ...args: unknown[]) => {\n if (listeners.has(eventName)) {\n for (const listener of listeners.get(eventName)) {\n await listener(...args);\n }\n }\n };\n\n // Store of subscribers that will be called when an event is emitted\n const subscribers = [defaultSubscriber];\n\n const eventHub: EventHub = {\n async emit(eventName, ...args) {\n for (const subscriber of subscribers) {\n await subscriber(eventName, ...args);\n }\n },\n\n subscribe(subscriber) {\n subscribers.push(subscriber);\n\n // Return a function to remove the subscriber\n return () => {\n eventHub.unsubscribe(subscriber);\n };\n },\n\n unsubscribe(subscriber) {\n const subscriberIndex = subscribers.indexOf(subscriber);\n\n // Only remove the subscriber if it exists\n if (subscriberIndex >= 0) {\n subscribers.splice(subscriberIndex, 1);\n }\n },\n\n on(eventName, listener) {\n if (!listeners.has(eventName)) {\n listeners.set(eventName, [listener]);\n } else {\n listeners.get(eventName).push(listener);\n }\n\n // Return a function to remove the listener\n return () => {\n eventHub.off(eventName, listener);\n };\n },\n\n off(eventName, listener) {\n listeners.get(eventName)?.splice(listeners.get(eventName).indexOf(listener), 1);\n },\n\n once(eventName, listener) {\n return eventHub.on(eventName, async (...args) => {\n eventHub.off(eventName, listener);\n return listener(...args);\n });\n },\n\n destroy() {\n this.removeAllListeners();\n this.removeAllSubscribers();\n return this;\n },\n\n removeListener(eventName, listener) {\n return eventHub.off(eventName, listener);\n },\n\n removeAllListeners() {\n listeners.clear();\n return this;\n },\n\n removeAllSubscribers() {\n subscribers.length = 0;\n return this;\n },\n\n addListener(eventName, listener) {\n return eventHub.on(eventName, listener);\n },\n };\n\n return eventHub;\n}\n"],"names":[],"mappings":"AAoBA,SAAwB,iBAA2B;AAC3C,QAAA,gCAAgB;AAGhB,QAAA,oBAAoB,OAAO,cAAsB,SAAoB;AACrE,QAAA,UAAU,IAAI,SAAS,GAAG;AAC5B,iBAAW,YAAY,UAAU,IAAI,SAAS,GAAG;AACzC,cAAA,SAAS,GAAG,IAAI;AAAA,MACxB;AAAA,IACF;AAAA,EAAA;AAII,QAAA,cAAc,CAAC,iBAAiB;AAEtC,QAAM,WAAqB;AAAA,IACzB,MAAM,KAAK,cAAc,MAAM;AAC7B,iBAAW,cAAc,aAAa;AAC9B,cAAA,WAAW,WAAW,GAAG,IAAI;AA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