@strapi/core 5.0.0-rc.0 → 5.0.0-rc.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +18 -3
- package/dist/Strapi.js +2 -2
- package/dist/Strapi.js.map +1 -1
- package/dist/configuration/get-dirs.js +2 -2
- package/dist/configuration/get-dirs.js.map +1 -1
- package/dist/configuration/index.js +2 -2
- package/dist/configuration/index.js.map +1 -1
- package/dist/core-api/controller/collection-type.js +3 -3
- package/dist/core-api/controller/collection-type.js.map +1 -1
- package/dist/core-api/controller/index.js +2 -2
- package/dist/core-api/controller/index.js.map +1 -1
- package/dist/core-api/controller/single-type.js +2 -2
- package/dist/core-api/controller/single-type.js.map +1 -1
- package/dist/core-api/controller/transform.js +8 -8
- package/dist/core-api/controller/transform.js.map +1 -1
- package/dist/core-api/service/pagination.js +8 -8
- package/dist/core-api/service/pagination.js.map +1 -1
- package/dist/domain/content-type/index.js +4 -4
- package/dist/domain/content-type/index.js.map +1 -1
- package/dist/ee/index.js +3 -3
- package/dist/ee/index.js.map +1 -1
- package/dist/factories.js +4 -4
- package/dist/factories.js.map +1 -1
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/loaders/apis.js +2 -2
- package/dist/loaders/apis.js.map +1 -1
- package/dist/loaders/plugins/get-enabled-plugins.d.ts.map +1 -1
- package/dist/loaders/plugins/get-enabled-plugins.js +34 -9
- package/dist/loaders/plugins/get-enabled-plugins.js.map +1 -1
- package/dist/loaders/plugins/get-enabled-plugins.mjs +4 -1
- package/dist/loaders/plugins/get-enabled-plugins.mjs.map +1 -1
- package/dist/loaders/plugins/get-user-plugins-config.js +2 -2
- package/dist/loaders/plugins/get-user-plugins-config.js.map +1 -1
- package/dist/loaders/plugins/index.js +6 -6
- package/dist/loaders/plugins/index.js.map +1 -1
- package/dist/middlewares/body.js +2 -2
- package/dist/middlewares/body.js.map +1 -1
- package/dist/middlewares/cors.d.ts.map +1 -1
- package/dist/middlewares/cors.js +4 -0
- package/dist/middlewares/cors.js.map +1 -1
- package/dist/middlewares/cors.mjs +4 -0
- package/dist/middlewares/cors.mjs.map +1 -1
- package/dist/middlewares/public.js +2 -2
- package/dist/middlewares/public.js.map +1 -1
- 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/responses.js +2 -2
- package/dist/middlewares/responses.js.map +1 -1
- package/dist/middlewares/security.js +3 -3
- package/dist/middlewares/security.js.map +1 -1
- package/dist/middlewares/session.js +2 -2
- package/dist/middlewares/session.js.map +1 -1
- package/dist/registries/apis.js +2 -2
- package/dist/registries/apis.js.map +1 -1
- package/dist/registries/components.js +2 -2
- package/dist/registries/components.js.map +1 -1
- package/dist/registries/content-types.js +3 -3
- package/dist/registries/content-types.js.map +1 -1
- package/dist/registries/controllers.js +3 -3
- package/dist/registries/controllers.js.map +1 -1
- package/dist/registries/custom-fields.js +4 -4
- package/dist/registries/custom-fields.js.map +1 -1
- package/dist/registries/hooks.js +2 -2
- package/dist/registries/hooks.js.map +1 -1
- package/dist/registries/middlewares.js +3 -3
- package/dist/registries/middlewares.js.map +1 -1
- package/dist/registries/modules.js +3 -3
- package/dist/registries/modules.js.map +1 -1
- package/dist/registries/plugins.js +2 -2
- package/dist/registries/plugins.js.map +1 -1
- package/dist/registries/policies.d.ts +1 -1
- package/dist/registries/policies.d.ts.map +1 -1
- package/dist/registries/policies.js +5 -5
- package/dist/registries/policies.js.map +1 -1
- package/dist/registries/policies.mjs +1 -1
- package/dist/registries/policies.mjs.map +1 -1
- package/dist/registries/services.js +3 -3
- package/dist/registries/services.js.map +1 -1
- package/dist/services/auth/index.js +3 -3
- package/dist/services/auth/index.js.map +1 -1
- package/dist/services/content-api/index.d.ts +6 -12
- package/dist/services/content-api/index.d.ts.map +1 -1
- package/dist/services/content-api/permissions/index.d.ts +6 -12
- package/dist/services/content-api/permissions/index.d.ts.map +1 -1
- package/dist/services/content-api/permissions/providers/action.d.ts +3 -6
- package/dist/services/content-api/permissions/providers/action.d.ts.map +1 -1
- package/dist/services/content-api/permissions/providers/condition.d.ts +3 -6
- package/dist/services/content-api/permissions/providers/condition.d.ts.map +1 -1
- package/dist/services/core-store.js +3 -3
- package/dist/services/core-store.js.map +1 -1
- package/dist/services/cron.js +3 -3
- package/dist/services/cron.js.map +1 -1
- package/dist/services/document-service/attributes/index.js +2 -2
- package/dist/services/document-service/attributes/index.js.map +1 -1
- package/dist/services/document-service/attributes/transforms.js +3 -3
- package/dist/services/document-service/attributes/transforms.js.map +1 -1
- package/dist/services/document-service/components.js +15 -15
- package/dist/services/document-service/components.js.map +1 -1
- package/dist/services/document-service/draft-and-publish.js +16 -16
- package/dist/services/document-service/draft-and-publish.js.map +1 -1
- package/dist/services/document-service/entries.js +5 -5
- package/dist/services/document-service/entries.js.map +1 -1
- package/dist/services/document-service/internationalization.js +9 -9
- package/dist/services/document-service/internationalization.js.map +1 -1
- package/dist/services/document-service/params.js +2 -2
- package/dist/services/document-service/params.js.map +1 -1
- package/dist/services/document-service/repository.js +9 -9
- package/dist/services/document-service/repository.js.map +1 -1
- package/dist/services/document-service/transform/id-transform.js +2 -2
- package/dist/services/document-service/transform/id-transform.js.map +1 -1
- package/dist/services/document-service/transform/query.js +3 -3
- package/dist/services/document-service/transform/query.js.map +1 -1
- package/dist/services/document-service/transform/relations/extract/data-ids.js +2 -2
- package/dist/services/document-service/transform/relations/extract/data-ids.js.map +1 -1
- package/dist/services/document-service/transform/relations/transform/data-ids.js +2 -2
- package/dist/services/document-service/transform/relations/transform/data-ids.js.map +1 -1
- package/dist/services/document-service/transform/relations/utils/dp.js +2 -2
- package/dist/services/document-service/transform/relations/utils/dp.js.map +1 -1
- package/dist/services/document-service/transform/relations/utils/map-relation.js +6 -6
- package/dist/services/document-service/transform/relations/utils/map-relation.js.map +1 -1
- package/dist/services/entity-validator/blocks-validator.d.ts +1 -2
- package/dist/services/entity-validator/blocks-validator.d.ts.map +1 -1
- package/dist/services/entity-validator/blocks-validator.js +4 -3
- package/dist/services/entity-validator/blocks-validator.js.map +1 -1
- package/dist/services/entity-validator/blocks-validator.mjs +3 -3
- package/dist/services/entity-validator/blocks-validator.mjs.map +1 -1
- package/dist/services/entity-validator/index.d.ts +2 -1
- package/dist/services/entity-validator/index.d.ts.map +1 -1
- package/dist/services/entity-validator/index.js +28 -33
- package/dist/services/entity-validator/index.js.map +1 -1
- package/dist/services/entity-validator/index.mjs +14 -19
- package/dist/services/entity-validator/index.mjs.map +1 -1
- package/dist/services/entity-validator/validators.d.ts +32 -23
- package/dist/services/entity-validator/validators.d.ts.map +1 -1
- package/dist/services/entity-validator/validators.js +137 -63
- package/dist/services/entity-validator/validators.js.map +1 -1
- package/dist/services/entity-validator/validators.mjs +136 -63
- package/dist/services/entity-validator/validators.mjs.map +1 -1
- package/dist/services/server/compose-endpoint.js +7 -7
- package/dist/services/server/compose-endpoint.js.map +1 -1
- package/dist/services/server/koa.js +3 -3
- package/dist/services/server/koa.js.map +1 -1
- package/dist/services/server/middleware.js +3 -3
- package/dist/services/server/middleware.js.map +1 -1
- package/dist/services/server/routing.js +2 -2
- package/dist/services/server/routing.js.map +1 -1
- package/dist/services/utils/dynamic-zones.js +5 -5
- package/dist/services/utils/dynamic-zones.js.map +1 -1
- package/dist/utils/cron.js +3 -3
- package/dist/utils/cron.js.map +1 -1
- package/dist/utils/filepath-to-prop-path.d.ts +1 -1
- package/dist/utils/filepath-to-prop-path.d.ts.map +1 -1
- package/dist/utils/filepath-to-prop-path.js +27 -6
- package/dist/utils/filepath-to-prop-path.js.map +1 -1
- package/dist/utils/filepath-to-prop-path.mjs +25 -5
- package/dist/utils/filepath-to-prop-path.mjs.map +1 -1
- package/dist/utils/is-initialized.js +3 -3
- package/dist/utils/is-initialized.js.map +1 -1
- package/dist/utils/startup-logger.js +4 -4
- package/dist/utils/startup-logger.js.map +1 -1
- package/dist/utils/startup-logger.mjs +3 -3
- package/dist/utils/startup-logger.mjs.map +1 -1
- package/dist/utils/transform-content-types-to-models.d.ts +2 -2
- package/dist/utils/transform-content-types-to-models.d.ts.map +1 -1
- package/dist/utils/transform-content-types-to-models.js +8 -5
- package/dist/utils/transform-content-types-to-models.js.map +1 -1
- package/dist/utils/transform-content-types-to-models.mjs +7 -4
- package/dist/utils/transform-content-types-to-models.mjs.map +1 -1
- package/package.json +13 -13
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"repository.js","sources":["../../../src/services/document-service/repository.ts"],"sourcesContent":["import { omit, assoc, merge, curry } from 'lodash/fp';\n\nimport { async, contentTypes as contentTypesUtils } from '@strapi/utils';\n\nimport { wrapInTransaction, type RepositoryFactoryMethod } from './common';\nimport * as DP from './draft-and-publish';\nimport * as i18n from './internationalization';\nimport * as components from './components';\n\nimport { createEntriesService } from './entries';\nimport { pickSelectionParams } from './params';\nimport { createDocumentId } from '../../utils/transform-content-types-to-models';\nimport { getDeepPopulate } from './utils/populate';\nimport { transformParamsToQuery } from './transform/query';\nimport { transformParamsDocumentId } from './transform/id-transform';\nimport { createEventManager } from './events';\n\nexport const createContentTypeRepository: RepositoryFactoryMethod = (uid) => {\n const contentType = strapi.contentType(uid);\n const hasDraftAndPublish = contentTypesUtils.hasDraftAndPublish(contentType);\n\n const entries = createEntriesService(uid);\n\n const eventManager = createEventManager(strapi, uid);\n const emitEvent = curry(eventManager.emitEvent);\n\n async function findMany(params = {} as any) {\n const query = await async.pipe(\n DP.defaultToDraft,\n DP.statusToLookup(contentType),\n i18n.defaultLocale(contentType),\n i18n.multiLocaleToLookup(contentType),\n transformParamsDocumentId(uid),\n transformParamsToQuery(uid)\n )(params || {});\n\n return strapi.db.query(uid).findMany(query);\n }\n\n async function findFirst(params = {} as any) {\n const query = await async.pipe(\n DP.defaultToDraft,\n DP.statusToLookup(contentType),\n i18n.defaultLocale(contentType),\n i18n.localeToLookup(contentType),\n transformParamsDocumentId(uid),\n transformParamsToQuery(uid)\n )(params);\n\n return strapi.db.query(uid).findOne(query);\n }\n\n // TODO: do we really want to add filters on the findOne now that we have findFirst ?\n async function findOne(opts = {} as any) {\n const { documentId, ...params } = opts;\n\n const query = await async.pipe(\n DP.defaultToDraft,\n DP.statusToLookup(contentType),\n i18n.defaultLocale(contentType),\n i18n.localeToLookup(contentType),\n transformParamsDocumentId(uid),\n transformParamsToQuery(uid),\n (query) => assoc('where', { ...query.where, documentId }, query)\n )(params);\n\n return strapi.db.query(uid).findOne(query);\n }\n\n async function deleteDocument(opts = {} as any) {\n const { documentId, ...params } = opts;\n\n const query = await async.pipe(\n omit('status'),\n i18n.defaultLocale(contentType),\n i18n.multiLocaleToLookup(contentType),\n transformParamsToQuery(uid),\n (query) => assoc('where', { ...query.where, documentId }, query)\n )(params);\n\n if (params.status === 'draft') {\n throw new Error('Cannot delete a draft document');\n }\n\n const entriesToDelete = await strapi.db.query(uid).findMany(query);\n\n // Delete all matched entries and its components\n const deletedEntries = await async.map(entriesToDelete, (entryToDelete: any) =>\n entries.delete(entryToDelete.id)\n );\n\n entriesToDelete.forEach(emitEvent('entry.delete'));\n\n return { documentId, entries: deletedEntries };\n }\n\n async function create(opts = {} as any) {\n const { documentId, ...params } = opts;\n\n const queryParams = await async.pipe(\n DP.filterDataPublishedAt,\n DP.setStatusToDraft(contentType),\n DP.statusToData(contentType),\n i18n.defaultLocale(contentType),\n i18n.localeToData(contentType)\n )(params);\n\n const doc = await entries.create(queryParams);\n\n emitEvent('entry.create', doc);\n\n if (hasDraftAndPublish && params.status === 'published') {\n return publish({\n ...params,\n documentId: doc.documentId,\n }).then((doc) => doc.entries[0]);\n }\n\n return doc;\n }\n\n async function clone(opts = {} as any) {\n const { documentId, ...params } = opts;\n\n const queryParams = await async.pipe(\n DP.filterDataPublishedAt,\n i18n.defaultLocale(contentType),\n i18n.multiLocaleToLookup(contentType)\n )(params);\n\n // Get deep populate\n const entriesToClone = await strapi.db.query(uid).findMany({\n where: {\n ...queryParams?.lookup,\n documentId,\n // DP Enabled: Clone drafts\n // DP Disabled: Clone only the existing version (published)\n publishedAt: { $null: hasDraftAndPublish },\n },\n populate: getDeepPopulate(uid, { relationalFields: ['id'] }),\n });\n\n const clonedEntries = await async.map(\n entriesToClone,\n async.pipe(\n omit('id'),\n // assign new documentId\n assoc('documentId', createDocumentId()),\n // Merge new data into it\n (data) => merge(data, queryParams.data),\n (data) => entries.create({ ...queryParams, data, status: 'draft' })\n )\n );\n\n clonedEntries.forEach(emitEvent('entry.create'));\n\n return { documentId: clonedEntries.at(0)?.documentId, entries: clonedEntries };\n }\n\n async function update(opts = {} as any) {\n const { documentId, ...params } = opts;\n\n const queryParams = await async.pipe(\n DP.filterDataPublishedAt,\n DP.setStatusToDraft(contentType),\n DP.statusToLookup(contentType),\n DP.statusToData(contentType),\n // Default locale will be set if not provided\n i18n.defaultLocale(contentType),\n i18n.localeToLookup(contentType),\n i18n.localeToData(contentType)\n )(params);\n\n const { data, ...restParams } = await transformParamsDocumentId(uid, queryParams || {});\n const query = transformParamsToQuery(uid, pickSelectionParams(restParams || {}) as any);\n\n // Validation\n // Find if document exists\n const entryToUpdate = await strapi.db\n .query(uid)\n .findOne({ ...query, where: { ...queryParams?.lookup, ...query?.where, documentId } });\n\n let updatedDraft = null;\n if (entryToUpdate) {\n updatedDraft = await entries.update(entryToUpdate, queryParams);\n emitEvent('entry.update', updatedDraft);\n }\n\n if (!updatedDraft) {\n const documentExists = await strapi.db\n .query(contentType.uid)\n .findOne({ where: { documentId } });\n\n if (documentExists) {\n updatedDraft = await entries.create({\n ...queryParams,\n data: { ...queryParams.data, documentId },\n });\n emitEvent('entry.create', updatedDraft);\n }\n }\n\n if (hasDraftAndPublish && updatedDraft && params.status === 'published') {\n return publish({\n ...params,\n documentId,\n }).then((doc) => doc.entries[0]);\n }\n\n return updatedDraft;\n }\n\n async function count(params = {} as any) {\n const query = await async.pipe(\n DP.defaultStatus(contentType),\n DP.statusToLookup(contentType),\n i18n.defaultLocale(contentType),\n i18n.localeToLookup(contentType),\n transformParamsToQuery(uid)\n )(params);\n\n return strapi.db.query(uid).count(query);\n }\n\n async function publish(opts = {} as any) {\n const { documentId, ...params } = opts;\n\n const queryParams = await async.pipe(\n i18n.defaultLocale(contentType),\n i18n.multiLocaleToLookup(contentType)\n )(params);\n\n const [draftsToPublish, publishedToDelete] = await Promise.all([\n strapi.db.query(uid).findMany({\n where: {\n ...queryParams?.lookup,\n documentId,\n publishedAt: null, // Ignore lookup\n },\n // Populate relations, media, compos and dz\n populate: getDeepPopulate(uid, { relationalFields: ['documentId', 'locale'] }),\n }),\n strapi.db.query(uid).findMany({\n where: {\n ...queryParams?.lookup,\n documentId,\n publishedAt: { $ne: null },\n },\n select: ['id'],\n }),\n ]);\n\n // Delete all published versions\n await async.map(publishedToDelete, (entry: any) => entries.delete(entry.id));\n\n // Transform draft entry data and create published versions\n const publishedEntries = await async.map(draftsToPublish, (draft: unknown) =>\n entries.publish(draft, queryParams)\n );\n\n publishedEntries.forEach(emitEvent('entry.publish'));\n return { documentId, entries: publishedEntries };\n }\n\n async function unpublish(opts = {} as any) {\n const { documentId, ...params } = opts;\n\n const query = await async.pipe(\n i18n.defaultLocale(contentType),\n i18n.multiLocaleToLookup(contentType),\n transformParamsToQuery(uid),\n (query) => assoc('where', { ...query.where, documentId, publishedAt: { $ne: null } }, query)\n )(params);\n\n // Delete all published versions\n const versionsToDelete = await strapi.db.query(uid).findMany(query);\n await async.map(versionsToDelete, (entry: any) => entries.delete(entry.id));\n\n versionsToDelete.forEach(emitEvent('entry.unpublish'));\n return { documentId, entries: versionsToDelete };\n }\n\n async function discardDraft(opts = {} as any) {\n const { documentId, ...params } = opts;\n\n const queryParams = await async.pipe(\n i18n.defaultLocale(contentType),\n i18n.multiLocaleToLookup(contentType)\n )(params);\n\n const [versionsToDraft, versionsToDelete] = await Promise.all([\n strapi.db.query(uid).findMany({\n where: {\n ...queryParams?.lookup,\n documentId,\n publishedAt: { $ne: null },\n },\n // Populate relations, media, compos and dz\n populate: getDeepPopulate(uid, { relationalFields: ['documentId', 'locale'] }),\n }),\n strapi.db.query(uid).findMany({\n where: {\n ...queryParams?.lookup,\n documentId,\n publishedAt: null,\n },\n select: ['id'],\n }),\n ]);\n\n // Delete all drafts\n await async.map(versionsToDelete, (entry: any) => entries.delete(entry.id));\n\n // Transform published entry data and create draft versions\n const draftEntries = await async.map(versionsToDraft, (entry: any) =>\n entries.discardDraft(entry, queryParams)\n );\n\n draftEntries.forEach(emitEvent('entry.draft-discard'));\n return { documentId, entries: draftEntries };\n }\n\n async function updateComponents(entry: any, data: any) {\n return components.updateComponents(uid, entry, data);\n }\n\n function omitComponentData(data: any) {\n return components.omitComponentData(contentType, data);\n }\n\n return {\n findMany: wrapInTransaction(findMany),\n findFirst: wrapInTransaction(findFirst),\n findOne: wrapInTransaction(findOne),\n delete: wrapInTransaction(deleteDocument),\n create: wrapInTransaction(create),\n clone: wrapInTransaction(clone),\n update: wrapInTransaction(update),\n count: wrapInTransaction(count),\n publish: hasDraftAndPublish ? wrapInTransaction(publish) : (undefined as any),\n unpublish: hasDraftAndPublish ? wrapInTransaction(unpublish) : (undefined as any),\n discardDraft: hasDraftAndPublish ? wrapInTransaction(discardDraft) : (undefined as any),\n\n updateComponents,\n omitComponentData,\n };\n};\n"],"names":["contentTypesUtils","entries","createEntriesService","createEventManager","curry","params","query","async","DP.defaultToDraft","DP.statusToLookup","i18n.defaultLocale","i18n.multiLocaleToLookup","transformParamsDocumentId","transformParamsToQuery","i18n.localeToLookup","assoc","omit","DP.filterDataPublishedAt","DP.setStatusToDraft","DP.statusToData","i18n.localeToData","doc","getDeepPopulate","createDocumentId","merge","pickSelectionParams","DP.defaultStatus","components.updateComponents","components.omitComponentData","wrapInTransaction"],"mappings":";;;;;;;;;;;;;;;AAiBa,MAAA,8BAAuD,CAAC,QAAQ;AACrE,QAAA,cAAc,OAAO,YAAY,GAAG;AACpC,QAAA,qBAAqBA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AO,GAAG,MAAM,GAAG,EAAE,SAAS;AAAA,QAC5B,OAAO;AAAA,UACL,GAAG,aAAa;AAAA,UAChB;AAAA,UACA,aAAa;AAAA,QACf;AAAA,QACA,QAAQ,CAAC,IAAI;AAAA,MAAA,CACd;AAAA,IAAA,CACF;AAGK,UAAAf,YAAA,MAAM,IAAI,kBAAkB,CAAC,UAAeN,UAAQ,OAAO,MAAM,EAAE,CAAC;AAGpE,UAAA,eAAe,MAAMM,YAAAA,MAAM;AAAA,MAAI;AAAA,MAAiB,CAAC,UACrDN,UAAQ,aAAa,OAAO,WAAW;AAAA,IAAA;AAG5B,iBAAA,QAAQ,UAAU,qBAAqB,CAAC;AAC9C,WAAA,EAAE,YAAY,SAAS;EAChC;AAEe,iBAAA,iBAAiB,OAAY,MAAW;AACrD,WAAO0B,4BAA4B,KAAK,OAAO,IAAI;AAAA,EACrD;AAEA,WAAS,kBAAkB,MAAW;AAC7B,WAAAC,WAA6B,kBAAA,aAAa,IAAI;AAAA,EACvD;AAEO,SAAA;AAAA,IACL,UAAUC,yBAAkB,QAAQ;AAAA,IACpC,WAAWA,yBAAkB,SAAS;AAAA,IACtC,SAASA,yBAAkB,OAAO;AAAA,IAClC,QAAQA,yBAAkB,cAAc;AAAA,IACxC,QAAQA,yBAAkB,MAAM;AAAA,IAChC,OAAOA,yBAAkB,KAAK;AAAA,IAC9B,QAAQA,yBAAkB,MAAM;AAAA,IAChC,OAAOA,yBAAkB,KAAK;AAAA,IAC9B,SAAS,qBAAqBA,OAAAA,kBAAkB,OAAO,IAAK;AAAA,IAC5D,WAAW,qBAAqBA,OAAAA,kBAAkB,SAAS,IAAK;AAAA,IAChE,cAAc,qBAAqBA,OAAAA,kBAAkB,YAAY,IAAK;AAAA,IAEtE;AAAA,IACA;AAAA,EAAA;AAEJ;;"}
|
1
|
+
{"version":3,"file":"repository.js","sources":["../../../src/services/document-service/repository.ts"],"sourcesContent":["import { omit, assoc, merge, curry } from 'lodash/fp';\n\nimport { async, contentTypes as contentTypesUtils } from '@strapi/utils';\n\nimport { wrapInTransaction, type RepositoryFactoryMethod } from './common';\nimport * as DP from './draft-and-publish';\nimport * as i18n from './internationalization';\nimport * as components from './components';\n\nimport { createEntriesService } from './entries';\nimport { pickSelectionParams } from './params';\nimport { createDocumentId } from '../../utils/transform-content-types-to-models';\nimport { getDeepPopulate } from './utils/populate';\nimport { transformParamsToQuery } from './transform/query';\nimport { transformParamsDocumentId } from './transform/id-transform';\nimport { createEventManager } from './events';\n\nexport const createContentTypeRepository: RepositoryFactoryMethod = (uid) => {\n const contentType = strapi.contentType(uid);\n const hasDraftAndPublish = contentTypesUtils.hasDraftAndPublish(contentType);\n\n const entries = createEntriesService(uid);\n\n const eventManager = createEventManager(strapi, uid);\n const emitEvent = curry(eventManager.emitEvent);\n\n async function findMany(params = {} as any) {\n const query = await async.pipe(\n DP.defaultToDraft,\n DP.statusToLookup(contentType),\n i18n.defaultLocale(contentType),\n i18n.multiLocaleToLookup(contentType),\n transformParamsDocumentId(uid),\n transformParamsToQuery(uid)\n )(params || {});\n\n return strapi.db.query(uid).findMany(query);\n }\n\n async function findFirst(params = {} as any) {\n const query = await async.pipe(\n DP.defaultToDraft,\n DP.statusToLookup(contentType),\n i18n.defaultLocale(contentType),\n i18n.localeToLookup(contentType),\n transformParamsDocumentId(uid),\n transformParamsToQuery(uid)\n )(params);\n\n return strapi.db.query(uid).findOne(query);\n }\n\n // TODO: do we really want to add filters on the findOne now that we have findFirst ?\n async function findOne(opts = {} as any) {\n const { documentId, ...params } = opts;\n\n const query = await async.pipe(\n DP.defaultToDraft,\n DP.statusToLookup(contentType),\n i18n.defaultLocale(contentType),\n i18n.localeToLookup(contentType),\n transformParamsDocumentId(uid),\n transformParamsToQuery(uid),\n (query) => assoc('where', { ...query.where, documentId }, query)\n )(params);\n\n return strapi.db.query(uid).findOne(query);\n }\n\n async function deleteDocument(opts = {} as any) {\n const { documentId, ...params } = opts;\n\n const query = await async.pipe(\n omit('status'),\n i18n.defaultLocale(contentType),\n i18n.multiLocaleToLookup(contentType),\n transformParamsToQuery(uid),\n (query) => assoc('where', { ...query.where, documentId }, query)\n )(params);\n\n if (params.status === 'draft') {\n throw new Error('Cannot delete a draft document');\n }\n\n const entriesToDelete = await strapi.db.query(uid).findMany(query);\n\n // Delete all matched entries and its components\n const deletedEntries = await async.map(entriesToDelete, (entryToDelete: any) =>\n entries.delete(entryToDelete.id)\n );\n\n entriesToDelete.forEach(emitEvent('entry.delete'));\n\n return { documentId, entries: deletedEntries };\n }\n\n async function create(opts = {} as any) {\n const { documentId, ...params } = opts;\n\n const queryParams = await async.pipe(\n DP.filterDataPublishedAt,\n DP.setStatusToDraft(contentType),\n DP.statusToData(contentType),\n i18n.defaultLocale(contentType),\n i18n.localeToData(contentType)\n )(params);\n\n const doc = await entries.create(queryParams);\n\n emitEvent('entry.create', doc);\n\n if (hasDraftAndPublish && params.status === 'published') {\n return publish({\n ...params,\n documentId: doc.documentId,\n }).then((doc) => doc.entries[0]);\n }\n\n return doc;\n }\n\n async function clone(opts = {} as any) {\n const { documentId, ...params } = opts;\n\n const queryParams = await async.pipe(\n DP.filterDataPublishedAt,\n i18n.defaultLocale(contentType),\n i18n.multiLocaleToLookup(contentType)\n )(params);\n\n // Get deep populate\n const entriesToClone = await strapi.db.query(uid).findMany({\n where: {\n ...queryParams?.lookup,\n documentId,\n // DP Enabled: Clone drafts\n // DP Disabled: Clone only the existing version (published)\n publishedAt: { $null: hasDraftAndPublish },\n },\n populate: getDeepPopulate(uid, { relationalFields: ['id'] }),\n });\n\n const clonedEntries = await async.map(\n entriesToClone,\n async.pipe(\n omit('id'),\n // assign new documentId\n assoc('documentId', createDocumentId()),\n // Merge new data into it\n (data) => merge(data, queryParams.data),\n (data) => entries.create({ ...queryParams, data, status: 'draft' })\n )\n );\n\n clonedEntries.forEach(emitEvent('entry.create'));\n\n return { documentId: clonedEntries.at(0)?.documentId, entries: clonedEntries };\n }\n\n async function update(opts = {} as any) {\n const { documentId, ...params } = opts;\n\n const queryParams = await async.pipe(\n DP.filterDataPublishedAt,\n DP.setStatusToDraft(contentType),\n DP.statusToLookup(contentType),\n DP.statusToData(contentType),\n // Default locale will be set if not provided\n i18n.defaultLocale(contentType),\n i18n.localeToLookup(contentType),\n i18n.localeToData(contentType)\n )(params);\n\n const { data, ...restParams } = await transformParamsDocumentId(uid, queryParams || {});\n const query = transformParamsToQuery(uid, pickSelectionParams(restParams || {}) as any);\n\n // Validation\n // Find if document exists\n const entryToUpdate = await strapi.db\n .query(uid)\n .findOne({ ...query, where: { ...queryParams?.lookup, ...query?.where, documentId } });\n\n let updatedDraft = null;\n if (entryToUpdate) {\n updatedDraft = await entries.update(entryToUpdate, queryParams);\n emitEvent('entry.update', updatedDraft);\n }\n\n if (!updatedDraft) {\n const documentExists = await strapi.db\n .query(contentType.uid)\n .findOne({ where: { documentId } });\n\n if (documentExists) {\n updatedDraft = await entries.create({\n ...queryParams,\n data: { ...queryParams.data, documentId },\n });\n emitEvent('entry.create', updatedDraft);\n }\n }\n\n if (hasDraftAndPublish && updatedDraft && params.status === 'published') {\n return publish({\n ...params,\n documentId,\n }).then((doc) => doc.entries[0]);\n }\n\n return updatedDraft;\n }\n\n async function count(params = {} as any) {\n const query = await async.pipe(\n DP.defaultStatus(contentType),\n DP.statusToLookup(contentType),\n i18n.defaultLocale(contentType),\n i18n.localeToLookup(contentType),\n transformParamsToQuery(uid)\n )(params);\n\n return strapi.db.query(uid).count(query);\n }\n\n async function publish(opts = {} as any) {\n const { documentId, ...params } = opts;\n\n const queryParams = await async.pipe(\n i18n.defaultLocale(contentType),\n i18n.multiLocaleToLookup(contentType)\n )(params);\n\n const [draftsToPublish, publishedToDelete] = await Promise.all([\n strapi.db.query(uid).findMany({\n where: {\n ...queryParams?.lookup,\n documentId,\n publishedAt: null, // Ignore lookup\n },\n // Populate relations, media, compos and dz\n populate: getDeepPopulate(uid, { relationalFields: ['documentId', 'locale'] }),\n }),\n strapi.db.query(uid).findMany({\n where: {\n ...queryParams?.lookup,\n documentId,\n publishedAt: { $ne: null },\n },\n select: ['id'],\n }),\n ]);\n\n // Delete all published versions\n await async.map(publishedToDelete, (entry: any) => entries.delete(entry.id));\n\n // Transform draft entry data and create published versions\n const publishedEntries = await async.map(draftsToPublish, (draft: unknown) =>\n entries.publish(draft, queryParams)\n );\n\n publishedEntries.forEach(emitEvent('entry.publish'));\n return { documentId, entries: publishedEntries };\n }\n\n async function unpublish(opts = {} as any) {\n const { documentId, ...params } = opts;\n\n const query = await async.pipe(\n i18n.defaultLocale(contentType),\n i18n.multiLocaleToLookup(contentType),\n transformParamsToQuery(uid),\n (query) => assoc('where', { ...query.where, documentId, publishedAt: { $ne: null } }, query)\n )(params);\n\n // Delete all published versions\n const versionsToDelete = await strapi.db.query(uid).findMany(query);\n await async.map(versionsToDelete, (entry: any) => entries.delete(entry.id));\n\n versionsToDelete.forEach(emitEvent('entry.unpublish'));\n return { documentId, entries: versionsToDelete };\n }\n\n async function discardDraft(opts = {} as any) {\n const { documentId, ...params } = opts;\n\n const queryParams = await async.pipe(\n i18n.defaultLocale(contentType),\n i18n.multiLocaleToLookup(contentType)\n )(params);\n\n const [versionsToDraft, versionsToDelete] = await Promise.all([\n strapi.db.query(uid).findMany({\n where: {\n ...queryParams?.lookup,\n documentId,\n publishedAt: { $ne: null },\n },\n // Populate relations, media, compos and dz\n populate: getDeepPopulate(uid, { relationalFields: ['documentId', 'locale'] }),\n }),\n strapi.db.query(uid).findMany({\n where: {\n ...queryParams?.lookup,\n documentId,\n publishedAt: null,\n },\n select: ['id'],\n }),\n ]);\n\n // Delete all drafts\n await async.map(versionsToDelete, (entry: any) => entries.delete(entry.id));\n\n // Transform published entry data and create draft versions\n const draftEntries = await async.map(versionsToDraft, (entry: any) =>\n entries.discardDraft(entry, queryParams)\n );\n\n draftEntries.forEach(emitEvent('entry.draft-discard'));\n return { documentId, entries: draftEntries };\n }\n\n async function updateComponents(entry: any, data: any) {\n return components.updateComponents(uid, entry, data);\n }\n\n function omitComponentData(data: any) {\n return components.omitComponentData(contentType, data);\n }\n\n return {\n findMany: wrapInTransaction(findMany),\n findFirst: wrapInTransaction(findFirst),\n findOne: wrapInTransaction(findOne),\n delete: wrapInTransaction(deleteDocument),\n create: wrapInTransaction(create),\n clone: wrapInTransaction(clone),\n update: wrapInTransaction(update),\n count: wrapInTransaction(count),\n publish: hasDraftAndPublish ? wrapInTransaction(publish) : (undefined as any),\n unpublish: hasDraftAndPublish ? wrapInTransaction(unpublish) : (undefined as any),\n discardDraft: hasDraftAndPublish ? wrapInTransaction(discardDraft) : (undefined as any),\n\n updateComponents,\n omitComponentData,\n };\n};\n"],"names":["contentTypesUtils","entries","createEntriesService","createEventManager","curry","params","query","async","DP.defaultToDraft","DP.statusToLookup","i18n.defaultLocale","i18n.multiLocaleToLookup","transformParamsDocumentId","transformParamsToQuery","i18n.localeToLookup","assoc","omit","DP.filterDataPublishedAt","DP.setStatusToDraft","DP.statusToData","i18n.localeToData","doc","getDeepPopulate","createDocumentId","merge","pickSelectionParams","DP.defaultStatus","components.updateComponents","components.omitComponentData","wrapInTransaction"],"mappings":";;;;;;;;;;;;;;;AAiBa,MAAA,8BAAuD,CAAC,QAAQ;AACrE,QAAA,cAAc,OAAO,YAAY,GAAG;AACpC,QAAA,qBAAqBA,YAAAA,aAAkB,mBAAmB,WAAW;AAErE,QAAAC,YAAUC,6BAAqB,GAAG;AAElC,QAAA,eAAeC,OAAAA,mBAAmB,QAAQ,GAAG;AAC7C,QAAA,YAAYC,GAAAA,MAAM,aAAa,SAAS;AAE/B,iBAAA,SAASC,UAAS,IAAW;AACpC,UAAAC,UAAQ,MAAMC,YAAAA,MAAM;AAAA,MACxBC,gBAAG;AAAA,MACHC,gBAAAA,eAAkB,WAAW;AAAA,MAC7BC,qBAAAA,cAAmB,WAAW;AAAA,MAC9BC,qBAAAA,oBAAyB,WAAW;AAAA,MACpCC,YAAAA,0BAA0B,GAAG;AAAA,MAC7BC,MAAAA,uBAAuB,GAAG;AA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,EAAE,YAAY,SAAS;EAChC;AAEe,iBAAA,iBAAiB,OAAY,MAAW;AACrD,WAAO0B,4BAA4B,KAAK,OAAO,IAAI;AAAA,EACrD;AAEA,WAAS,kBAAkB,MAAW;AAC7B,WAAAC,WAA6B,kBAAA,aAAa,IAAI;AAAA,EACvD;AAEO,SAAA;AAAA,IACL,UAAUC,yBAAkB,QAAQ;AAAA,IACpC,WAAWA,yBAAkB,SAAS;AAAA,IACtC,SAASA,yBAAkB,OAAO;AAAA,IAClC,QAAQA,yBAAkB,cAAc;AAAA,IACxC,QAAQA,yBAAkB,MAAM;AAAA,IAChC,OAAOA,yBAAkB,KAAK;AAAA,IAC9B,QAAQA,yBAAkB,MAAM;AAAA,IAChC,OAAOA,yBAAkB,KAAK;AAAA,IAC9B,SAAS,qBAAqBA,OAAAA,kBAAkB,OAAO,IAAK;AAAA,IAC5D,WAAW,qBAAqBA,OAAAA,kBAAkB,SAAS,IAAK;AAAA,IAChE,cAAc,qBAAqBA,OAAAA,kBAAkB,YAAY,IAAK;AAAA,IAEtE;AAAA,IACA;AAAA,EAAA;AAEJ;;"}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
3
|
-
const
|
3
|
+
const fp = require("lodash/fp");
|
4
4
|
const data = require("./data.js");
|
5
5
|
const fields = require("./fields.js");
|
6
6
|
const populate = require("./populate.js");
|
@@ -28,6 +28,6 @@ async function transformParamsDocumentId(uid, query) {
|
|
28
28
|
populate: populate$1
|
29
29
|
};
|
30
30
|
}
|
31
|
-
const curriedTransformParamsDocumentId =
|
31
|
+
const curriedTransformParamsDocumentId = fp.curry(transformParamsDocumentId);
|
32
32
|
exports.transformParamsDocumentId = curriedTransformParamsDocumentId;
|
33
33
|
//# sourceMappingURL=id-transform.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"id-transform.js","sources":["../../../../src/services/document-service/transform/id-transform.ts"],"sourcesContent":["import { curry } from 'lodash/fp';\n\nimport { UID, Modules } from '@strapi/types';\n\nimport { transformData } from './data';\nimport { transformFields } from './fields';\nimport { transformPopulate } from './populate';\n\n/**\n * Transform input of a query to map document ids to entity ids.\n */\nasync function transformParamsDocumentId(\n uid: UID.Schema,\n query: Modules.Documents.Params.All\n): Promise<Modules.Documents.Params.All> {\n // Transform relational documentIds to entity ids\n let data = query.data;\n if (query.data) {\n data = await transformData(query.data, {\n locale: query.locale,\n status: query.status,\n uid,\n });\n }\n\n // Make sure documentId is always present in the response\n let fields = query.fields;\n if (query.fields) {\n fields = transformFields(query.fields) as typeof query.fields;\n }\n\n let populate = query.populate;\n if (query.populate) {\n populate = (await transformPopulate(query.populate, { uid })) as typeof query.populate;\n }\n\n return {\n ...query,\n data,\n fields,\n populate,\n };\n}\n\nconst curriedTransformParamsDocumentId = curry(transformParamsDocumentId);\n\nexport { curriedTransformParamsDocumentId as transformParamsDocumentId };\n"],"names":["data","transformData","fields","transformFields","populate","transformPopulate","curry"],"mappings":";;;;;;AAWA,eAAe,0BACb,KACA,OACuC;AAEvC,MAAIA,SAAO,MAAM;AACjB,MAAI,MAAM,MAAM;AACPA,aAAA,MAAMC,KAAAA,cAAc,MAAM,MAAM;AAAA,MACrC,QAAQ,MAAM;AAAA,MACd,QAAQ,MAAM;AAAA,MACd;AAAA,IAAA,CACD;AAAA,EACH;AAGA,MAAIC,WAAS,MAAM;AACnB,MAAI,MAAM,QAAQ;AACPA,eAAAC,OAAA,gBAAgB,MAAM,MAAM;AAAA,EACvC;AAEA,MAAIC,aAAW,MAAM;AACrB,MAAI,MAAM,UAAU;AAClBA,iBAAY,MAAMC,SAAAA,kBAAkB,MAAM,UAAU,EAAE,KAAK;AAAA,EAC7D;AAEO,SAAA;AAAA,IACL,GAAG;AAAA,IAAA,MACHL;AAAAA,IAAA,QACAE;AAAAA,IAAA,UACAE;AAAAA,EAAA;AAEJ;AAEM,MAAA,mCAAmCE,
|
1
|
+
{"version":3,"file":"id-transform.js","sources":["../../../../src/services/document-service/transform/id-transform.ts"],"sourcesContent":["import { curry } from 'lodash/fp';\n\nimport { UID, Modules } from '@strapi/types';\n\nimport { transformData } from './data';\nimport { transformFields } from './fields';\nimport { transformPopulate } from './populate';\n\n/**\n * Transform input of a query to map document ids to entity ids.\n */\nasync function transformParamsDocumentId(\n uid: UID.Schema,\n query: Modules.Documents.Params.All\n): Promise<Modules.Documents.Params.All> {\n // Transform relational documentIds to entity ids\n let data = query.data;\n if (query.data) {\n data = await transformData(query.data, {\n locale: query.locale,\n status: query.status,\n uid,\n });\n }\n\n // Make sure documentId is always present in the response\n let fields = query.fields;\n if (query.fields) {\n fields = transformFields(query.fields) as typeof query.fields;\n }\n\n let populate = query.populate;\n if (query.populate) {\n populate = (await transformPopulate(query.populate, { uid })) as typeof query.populate;\n }\n\n return {\n ...query,\n data,\n fields,\n populate,\n };\n}\n\nconst curriedTransformParamsDocumentId = curry(transformParamsDocumentId);\n\nexport { curriedTransformParamsDocumentId as transformParamsDocumentId };\n"],"names":["data","transformData","fields","transformFields","populate","transformPopulate","curry"],"mappings":";;;;;;AAWA,eAAe,0BACb,KACA,OACuC;AAEvC,MAAIA,SAAO,MAAM;AACjB,MAAI,MAAM,MAAM;AACPA,aAAA,MAAMC,KAAAA,cAAc,MAAM,MAAM;AAAA,MACrC,QAAQ,MAAM;AAAA,MACd,QAAQ,MAAM;AAAA,MACd;AAAA,IAAA,CACD;AAAA,EACH;AAGA,MAAIC,WAAS,MAAM;AACnB,MAAI,MAAM,QAAQ;AACPA,eAAAC,OAAA,gBAAgB,MAAM,MAAM;AAAA,EACvC;AAEA,MAAIC,aAAW,MAAM;AACrB,MAAI,MAAM,UAAU;AAClBA,iBAAY,MAAMC,SAAAA,kBAAkB,MAAM,UAAU,EAAE,KAAK;AAAA,EAC7D;AAEO,SAAA;AAAA,IACL,GAAG;AAAA,IAAA,MACHL;AAAAA,IAAA,QACAE;AAAAA,IAAA,UACAE;AAAAA,EAAA;AAEJ;AAEM,MAAA,mCAAmCE,SAAM,yBAAyB;;"}
|
@@ -1,9 +1,9 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
3
|
-
const
|
4
|
-
const transformParamsToQuery =
|
3
|
+
const fp = require("lodash/fp");
|
4
|
+
const transformParamsToQuery = fp.curry((uid, params) => {
|
5
5
|
const query = strapi.get("query-params").transform(uid, params);
|
6
|
-
return
|
6
|
+
return fp.assoc("where", { ...params?.lookup, ...query.where }, query);
|
7
7
|
});
|
8
8
|
exports.transformParamsToQuery = transformParamsToQuery;
|
9
9
|
//# sourceMappingURL=query.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"query.js","sources":["../../../../src/services/document-service/transform/query.ts"],"sourcesContent":["import type { UID } from '@strapi/types';\n\nimport { curry, assoc } from 'lodash/fp';\n\nconst transformParamsToQuery = curry((uid: UID.Schema, params: any) => {\n const query = strapi.get('query-params').transform(uid, params);\n\n return assoc('where', { ...params?.lookup, ...query.where }, query);\n});\n\nexport { transformParamsToQuery };\n"],"names":["curry","assoc"],"mappings":";;;AAIA,MAAM,yBAAyBA,
|
1
|
+
{"version":3,"file":"query.js","sources":["../../../../src/services/document-service/transform/query.ts"],"sourcesContent":["import type { UID } from '@strapi/types';\n\nimport { curry, assoc } from 'lodash/fp';\n\nconst transformParamsToQuery = curry((uid: UID.Schema, params: any) => {\n const query = strapi.get('query-params').transform(uid, params);\n\n return assoc('where', { ...params?.lookup, ...query.where }, query);\n});\n\nexport { transformParamsToQuery };\n"],"names":["curry","assoc"],"mappings":";;;AAIA,MAAM,yBAAyBA,GAAA,MAAM,CAAC,KAAiB,WAAgB;AACrE,QAAM,QAAQ,OAAO,IAAI,cAAc,EAAE,UAAU,KAAK,MAAM;AAEvD,SAAAC,GAAA,MAAM,SAAS,EAAE,GAAG,QAAQ,QAAQ,GAAG,MAAM,SAAS,KAAK;AACpE,CAAC;;"}
|
@@ -1,10 +1,10 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
3
|
-
const
|
3
|
+
const fp = require("lodash/fp");
|
4
4
|
const i18n = require("../utils/i18n.js");
|
5
5
|
const dp = require("../utils/dp.js");
|
6
6
|
const mapRelation = require("../utils/map-relation.js");
|
7
|
-
const addRelationDocId =
|
7
|
+
const addRelationDocId = fp.curry(
|
8
8
|
(idMap, targetUid, source, relation) => {
|
9
9
|
const targetLocale = i18n.getRelationTargetLocale(relation, {
|
10
10
|
targetUid,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"data-ids.js","sources":["../../../../../../src/services/document-service/transform/relations/extract/data-ids.ts"],"sourcesContent":["import { curry } from 'lodash/fp';\n\nimport { UID } from '@strapi/types';\n\nimport { IdMap } from '../../id-map';\nimport { getRelationTargetLocale } from '../utils/i18n';\nimport { getRelationTargetStatus } from '../utils/dp';\nimport { mapRelation, traverseEntityRelations } from '../utils/map-relation';\nimport { LongHandDocument } from '../utils/types';\n\ninterface Options {\n uid: UID.Schema;\n locale?: string | null;\n status?: 'draft' | 'published';\n}\n\n/**\n * Load a relation documentId into the idMap.\n */\nconst addRelationDocId = curry(\n (idMap: IdMap, targetUid: UID.Schema, source: Options, relation: LongHandDocument) => {\n const targetLocale = getRelationTargetLocale(relation, {\n targetUid,\n sourceUid: source.uid,\n sourceLocale: source.locale,\n });\n\n const targetStatus = getRelationTargetStatus(relation, {\n targetUid,\n sourceUid: source.uid,\n sourceStatus: source.status,\n });\n\n targetStatus.forEach((status) => {\n idMap.add({\n uid: targetUid,\n documentId: relation.documentId,\n locale: targetLocale,\n status,\n });\n });\n }\n);\n\n/**\n * Iterate over all relations of a data object and extract all relational document ids.\n * Those will later be transformed to entity ids.\n */\nconst extractDataIds = (idMap: IdMap, data: Record<string, any>, source: Options) => {\n return traverseEntityRelations(\n async ({ attribute, value }) => {\n if (!attribute) {\n return;\n }\n\n const targetUid = attribute.target!;\n const addDocId = addRelationDocId(idMap, targetUid, source);\n\n return mapRelation((relation) => {\n if (!relation || !relation.documentId) {\n return relation;\n }\n\n addDocId(relation);\n\n // Handle positional arguments\n const position = relation.position;\n\n if (position?.before) {\n addDocId({ ...relation, ...position, documentId: position.before });\n }\n\n if (position?.after) {\n addDocId({ ...relation, ...position, documentId: position.after });\n }\n\n return relation;\n }, value as any);\n },\n { schema: strapi.getModel(source.uid), getModel: strapi.getModel.bind(strapi) },\n data\n );\n};\n\nexport { extractDataIds };\n"],"names":["curry","getRelationTargetLocale","getRelationTargetStatus","traverseEntityRelations","mapRelation"],"mappings":";;;;;;AAmBA,MAAM,mBAAmBA,
|
1
|
+
{"version":3,"file":"data-ids.js","sources":["../../../../../../src/services/document-service/transform/relations/extract/data-ids.ts"],"sourcesContent":["import { curry } from 'lodash/fp';\n\nimport { UID } from '@strapi/types';\n\nimport { IdMap } from '../../id-map';\nimport { getRelationTargetLocale } from '../utils/i18n';\nimport { getRelationTargetStatus } from '../utils/dp';\nimport { mapRelation, traverseEntityRelations } from '../utils/map-relation';\nimport { LongHandDocument } from '../utils/types';\n\ninterface Options {\n uid: UID.Schema;\n locale?: string | null;\n status?: 'draft' | 'published';\n}\n\n/**\n * Load a relation documentId into the idMap.\n */\nconst addRelationDocId = curry(\n (idMap: IdMap, targetUid: UID.Schema, source: Options, relation: LongHandDocument) => {\n const targetLocale = getRelationTargetLocale(relation, {\n targetUid,\n sourceUid: source.uid,\n sourceLocale: source.locale,\n });\n\n const targetStatus = getRelationTargetStatus(relation, {\n targetUid,\n sourceUid: source.uid,\n sourceStatus: source.status,\n });\n\n targetStatus.forEach((status) => {\n idMap.add({\n uid: targetUid,\n documentId: relation.documentId,\n locale: targetLocale,\n status,\n });\n });\n }\n);\n\n/**\n * Iterate over all relations of a data object and extract all relational document ids.\n * Those will later be transformed to entity ids.\n */\nconst extractDataIds = (idMap: IdMap, data: Record<string, any>, source: Options) => {\n return traverseEntityRelations(\n async ({ attribute, value }) => {\n if (!attribute) {\n return;\n }\n\n const targetUid = attribute.target!;\n const addDocId = addRelationDocId(idMap, targetUid, source);\n\n return mapRelation((relation) => {\n if (!relation || !relation.documentId) {\n return relation;\n }\n\n addDocId(relation);\n\n // Handle positional arguments\n const position = relation.position;\n\n if (position?.before) {\n addDocId({ ...relation, ...position, documentId: position.before });\n }\n\n if (position?.after) {\n addDocId({ ...relation, ...position, documentId: position.after });\n }\n\n return relation;\n }, value as any);\n },\n { schema: strapi.getModel(source.uid), getModel: strapi.getModel.bind(strapi) },\n data\n );\n};\n\nexport { extractDataIds };\n"],"names":["curry","getRelationTargetLocale","getRelationTargetStatus","traverseEntityRelations","mapRelation"],"mappings":";;;;;;AAmBA,MAAM,mBAAmBA,GAAA;AAAA,EACvB,CAAC,OAAc,WAAuB,QAAiB,aAA+B;AAC9E,UAAA,eAAeC,6BAAwB,UAAU;AAAA,MACrD;AAAA,MACA,WAAW,OAAO;AAAA,MAClB,cAAc,OAAO;AAAA,IAAA,CACtB;AAEK,UAAA,eAAeC,2BAAwB,UAAU;AAAA,MACrD;AAAA,MACA,WAAW,OAAO;AAAA,MAClB,cAAc,OAAO;AAAA,IAAA,CACtB;AAEY,iBAAA,QAAQ,CAAC,WAAW;AAC/B,YAAM,IAAI;AAAA,QACR,KAAK;AAAA,QACL,YAAY,SAAS;AAAA,QACrB,QAAQ;AAAA,QACR;AAAA,MAAA,CACD;AAAA,IAAA,CACF;AAAA,EACH;AACF;AAMA,MAAM,iBAAiB,CAAC,OAAc,MAA2B,WAAoB;AAC5E,SAAAC,YAAA;AAAA,IACL,OAAO,EAAE,WAAW,YAAY;AAC9B,UAAI,CAAC,WAAW;AACd;AAAA,MACF;AAEA,YAAM,YAAY,UAAU;AAC5B,YAAM,WAAW,iBAAiB,OAAO,WAAW,MAAM;AAEnD,aAAAC,YAAAA,YAAY,CAAC,aAAa;AAC/B,YAAI,CAAC,YAAY,CAAC,SAAS,YAAY;AAC9B,iBAAA;AAAA,QACT;AAEA,iBAAS,QAAQ;AAGjB,cAAM,WAAW,SAAS;AAE1B,YAAI,UAAU,QAAQ;AACX,mBAAA,EAAE,GAAG,UAAU,GAAG,UAAU,YAAY,SAAS,QAAQ;AAAA,QACpE;AAEA,YAAI,UAAU,OAAO;AACV,mBAAA,EAAE,GAAG,UAAU,GAAG,UAAU,YAAY,SAAS,OAAO;AAAA,QACnE;AAEO,eAAA;AAAA,SACN,KAAY;AAAA,IACjB;AAAA,IACA,EAAE,QAAQ,OAAO,SAAS,OAAO,GAAG,GAAG,UAAU,OAAO,SAAS,KAAK,MAAM,EAAE;AAAA,IAC9E;AAAA,EAAA;AAEJ;;"}
|
@@ -1,11 +1,11 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
3
|
-
const
|
3
|
+
const fp = require("lodash/fp");
|
4
4
|
const strapiUtils = require("@strapi/utils");
|
5
5
|
const i18n = require("../utils/i18n.js");
|
6
6
|
const dp = require("../utils/dp.js");
|
7
7
|
const mapRelation = require("../utils/map-relation.js");
|
8
|
-
const getRelationIds =
|
8
|
+
const getRelationIds = fp.curry(
|
9
9
|
(idMap, targetUid, source, relation) => {
|
10
10
|
const targetLocale = i18n.getRelationTargetLocale(relation, {
|
11
11
|
targetUid,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"data-ids.js","sources":["../../../../../../src/services/document-service/transform/relations/transform/data-ids.ts"],"sourcesContent":["import { curry } from 'lodash/fp';\n\nimport type { UID } from '@strapi/types';\nimport { errors } from '@strapi/utils';\n\nimport { ID, LongHandDocument } from '../utils/types';\nimport { IdMap } from '../../id-map';\nimport { getRelationTargetLocale } from '../utils/i18n';\nimport { getRelationTargetStatus } from '../utils/dp';\nimport { mapRelation, traverseEntityRelations } from '../utils/map-relation';\n\ninterface Options {\n uid: UID.Schema;\n locale?: string | null;\n status?: 'draft' | 'published';\n allowMissingId?: boolean; // Whether to ignore missing ids and not throw any error\n}\n\n/**\n * Get the entry ids for a given documentId.\n */\nconst getRelationIds = curry(\n (idMap: IdMap, targetUid: UID.Schema, source: Options, relation: LongHandDocument) => {\n // locale to connect to\n const targetLocale = getRelationTargetLocale(relation, {\n targetUid,\n sourceUid: source.uid,\n sourceLocale: source.locale,\n });\n\n // status(es) to connect to\n const targetStatus = getRelationTargetStatus(relation, {\n targetUid,\n sourceUid: source.uid,\n sourceStatus: source.status,\n });\n\n const ids: ID[] = [];\n\n // Find mapping between documentID -> id(s).\n // There are scenarios where a single documentID can map to multiple ids.\n // e.g when connecting Non DP -> DP and connecting to both the draft and publish version at the same time\n for (const tStatus of targetStatus) {\n const entryId = idMap.get({\n uid: targetUid,\n documentId: relation.documentId,\n locale: targetLocale,\n status: tStatus,\n });\n\n if (entryId) ids.push(entryId);\n }\n\n if (!ids.length && !source.allowMissingId) {\n throw new errors.ValidationError(\n `Document with id \"${relation.documentId}\", locale \"${targetLocale}\" not found`\n );\n }\n\n return ids;\n }\n);\n\n/**\n * Iterate over all relations of a data object and transform all relational document ids to entity ids.\n */\nconst transformDataIdsVisitor = (idMap: IdMap, data: Record<string, any>, source: Options) => {\n return traverseEntityRelations(\n async ({ key, value, attribute }, { set }) => {\n if (!attribute) {\n return;\n }\n\n // Find relational attributes, and return the document ids\n const targetUid = attribute.target!;\n const getIds = getRelationIds(idMap, targetUid, source);\n\n // Transform the relation documentId to entity id\n const newRelation = await mapRelation((relation) => {\n if (!relation || !relation.documentId) {\n return relation;\n }\n\n const ids = getIds(relation);\n\n // Handle positional arguments\n const position = { ...relation.position };\n\n if (position.before) {\n const beforeRelation = { ...relation, ...position, documentId: position.before };\n position.before = getIds(beforeRelation).at(0);\n }\n\n if (position.after) {\n const afterRelation = { ...relation, ...position, documentId: position.after };\n position.after = getIds(afterRelation).at(0);\n }\n\n // Transform all ids to new relations\n return ids?.map((id) => {\n const newRelation = { id } as typeof relation;\n if (relation.position) {\n newRelation.position = position;\n }\n\n return newRelation;\n });\n }, value as any);\n\n set(key, newRelation as any);\n },\n { schema: strapi.getModel(source.uid), getModel: strapi.getModel.bind(strapi) },\n data\n );\n};\n\nexport { transformDataIdsVisitor };\n"],"names":["curry","getRelationTargetLocale","getRelationTargetStatus","errors","traverseEntityRelations","mapRelation","newRelation"],"mappings":";;;;;;;AAqBA,MAAM,iBAAiBA,
|
1
|
+
{"version":3,"file":"data-ids.js","sources":["../../../../../../src/services/document-service/transform/relations/transform/data-ids.ts"],"sourcesContent":["import { curry } from 'lodash/fp';\n\nimport type { UID } from '@strapi/types';\nimport { errors } from '@strapi/utils';\n\nimport { ID, LongHandDocument } from '../utils/types';\nimport { IdMap } from '../../id-map';\nimport { getRelationTargetLocale } from '../utils/i18n';\nimport { getRelationTargetStatus } from '../utils/dp';\nimport { mapRelation, traverseEntityRelations } from '../utils/map-relation';\n\ninterface Options {\n uid: UID.Schema;\n locale?: string | null;\n status?: 'draft' | 'published';\n allowMissingId?: boolean; // Whether to ignore missing ids and not throw any error\n}\n\n/**\n * Get the entry ids for a given documentId.\n */\nconst getRelationIds = curry(\n (idMap: IdMap, targetUid: UID.Schema, source: Options, relation: LongHandDocument) => {\n // locale to connect to\n const targetLocale = getRelationTargetLocale(relation, {\n targetUid,\n sourceUid: source.uid,\n sourceLocale: source.locale,\n });\n\n // status(es) to connect to\n const targetStatus = getRelationTargetStatus(relation, {\n targetUid,\n sourceUid: source.uid,\n sourceStatus: source.status,\n });\n\n const ids: ID[] = [];\n\n // Find mapping between documentID -> id(s).\n // There are scenarios where a single documentID can map to multiple ids.\n // e.g when connecting Non DP -> DP and connecting to both the draft and publish version at the same time\n for (const tStatus of targetStatus) {\n const entryId = idMap.get({\n uid: targetUid,\n documentId: relation.documentId,\n locale: targetLocale,\n status: tStatus,\n });\n\n if (entryId) ids.push(entryId);\n }\n\n if (!ids.length && !source.allowMissingId) {\n throw new errors.ValidationError(\n `Document with id \"${relation.documentId}\", locale \"${targetLocale}\" not found`\n );\n }\n\n return ids;\n }\n);\n\n/**\n * Iterate over all relations of a data object and transform all relational document ids to entity ids.\n */\nconst transformDataIdsVisitor = (idMap: IdMap, data: Record<string, any>, source: Options) => {\n return traverseEntityRelations(\n async ({ key, value, attribute }, { set }) => {\n if (!attribute) {\n return;\n }\n\n // Find relational attributes, and return the document ids\n const targetUid = attribute.target!;\n const getIds = getRelationIds(idMap, targetUid, source);\n\n // Transform the relation documentId to entity id\n const newRelation = await mapRelation((relation) => {\n if (!relation || !relation.documentId) {\n return relation;\n }\n\n const ids = getIds(relation);\n\n // Handle positional arguments\n const position = { ...relation.position };\n\n if (position.before) {\n const beforeRelation = { ...relation, ...position, documentId: position.before };\n position.before = getIds(beforeRelation).at(0);\n }\n\n if (position.after) {\n const afterRelation = { ...relation, ...position, documentId: position.after };\n position.after = getIds(afterRelation).at(0);\n }\n\n // Transform all ids to new relations\n return ids?.map((id) => {\n const newRelation = { id } as typeof relation;\n if (relation.position) {\n newRelation.position = position;\n }\n\n return newRelation;\n });\n }, value as any);\n\n set(key, newRelation as any);\n },\n { schema: strapi.getModel(source.uid), getModel: strapi.getModel.bind(strapi) },\n data\n );\n};\n\nexport { transformDataIdsVisitor };\n"],"names":["curry","getRelationTargetLocale","getRelationTargetStatus","errors","traverseEntityRelations","mapRelation","newRelation"],"mappings":";;;;;;;AAqBA,MAAM,iBAAiBA,GAAA;AAAA,EACrB,CAAC,OAAc,WAAuB,QAAiB,aAA+B;AAE9E,UAAA,eAAeC,6BAAwB,UAAU;AAAA,MACrD;AAAA,MACA,WAAW,OAAO;AAAA,MAClB,cAAc,OAAO;AAAA,IAAA,CACtB;AAGK,UAAA,eAAeC,2BAAwB,UAAU;AAAA,MACrD;AAAA,MACA,WAAW,OAAO;AAAA,MAClB,cAAc,OAAO;AAAA,IAAA,CACtB;AAED,UAAM,MAAY,CAAA;AAKlB,eAAW,WAAW,cAAc;AAC5B,YAAA,UAAU,MAAM,IAAI;AAAA,QACxB,KAAK;AAAA,QACL,YAAY,SAAS;AAAA,QACrB,QAAQ;AAAA,QACR,QAAQ;AAAA,MAAA,CACT;AAEG,U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AAE;AAAA,IAC9E;AAAA,EAAA;AAEJ;;"}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
3
|
-
const
|
3
|
+
const fp = require("lodash/fp");
|
4
4
|
const strapiUtils = require("@strapi/utils");
|
5
5
|
const getRelationTargetStatus = (relation, opts) => {
|
6
6
|
const targetContentType = strapi.getModel(opts.targetUid);
|
@@ -10,7 +10,7 @@ const getRelationTargetStatus = (relation, opts) => {
|
|
10
10
|
if (!targetHasDP) {
|
11
11
|
return ["published"];
|
12
12
|
}
|
13
|
-
if (sourceHasDP && !
|
13
|
+
if (sourceHasDP && !fp.isNil(opts.sourceStatus)) {
|
14
14
|
return [opts.sourceStatus];
|
15
15
|
}
|
16
16
|
if (relation.status) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"dp.js","sources":["../../../../../../src/services/document-service/transform/relations/utils/dp.ts"],"sourcesContent":["import { isNil } from 'lodash/fp';\n\nimport { contentTypes } from '@strapi/utils';\nimport { UID } from '@strapi/types';\n\nimport { LongHandDocument } from './types';\n\ntype Status = 'draft' | 'published';\n\nexport const getRelationTargetStatus = (\n relation: Pick<LongHandDocument, 'documentId' | 'status'>,\n opts: {\n targetUid: UID.Schema;\n sourceUid: UID.Schema;\n sourceStatus?: Status;\n }\n): Status[] => {\n // Ignore if the target content type does not have draft and publish enabled\n const targetContentType = strapi.getModel(opts.targetUid);\n const sourceContentType = strapi.getModel(opts.sourceUid);\n\n const targetHasDP = contentTypes.hasDraftAndPublish(targetContentType);\n const sourceHasDP = contentTypes.hasDraftAndPublish(sourceContentType);\n\n if (!targetHasDP) {\n return ['published'];\n }\n\n /**\n * If both source and target have DP enabled,\n * connect it to the same status as the source status\n */\n if (sourceHasDP && !isNil(opts.sourceStatus)) {\n return [opts.sourceStatus];\n }\n\n /**\n * Use the status from the relation if it's set\n */\n if (relation.status) {\n switch (relation.status) {\n case 'published':\n return ['published'];\n default:\n // Default to draft if it's an invalid status (e.g. modified)\n return ['draft'];\n }\n }\n\n /**\n * If DP is disabled and relation does not specify any status\n * Connect to both draft and published versions\n */\n if (!sourceHasDP) {\n return ['draft', 'published'];\n }\n\n // Default to draft as a fallback\n return ['draft'];\n};\n"],"names":["contentTypes","isNil"],"mappings":";;;;AASa,MAAA,0BAA0B,CACrC,UACA,SAKa;AAEb,QAAM,oBAAoB,OAAO,SAAS,KAAK,SAAS;AACxD,QAAM,oBAAoB,OAAO,SAAS,KAAK,SAAS;AAElD,QAAA,cAAcA,YAAAA,aAAa,mBAAmB,iBAAiB;AAC/D,QAAA,cAAcA,YAAAA,aAAa,mBAAmB,iBAAiB;AAErE,MAAI,CAAC,aAAa;AAChB,WAAO,CAAC,WAAW;AAAA,EACrB;AAMA,MAAI,eAAe,CAACC,
|
1
|
+
{"version":3,"file":"dp.js","sources":["../../../../../../src/services/document-service/transform/relations/utils/dp.ts"],"sourcesContent":["import { isNil } from 'lodash/fp';\n\nimport { contentTypes } from '@strapi/utils';\nimport { UID } from '@strapi/types';\n\nimport { LongHandDocument } from './types';\n\ntype Status = 'draft' | 'published';\n\nexport const getRelationTargetStatus = (\n relation: Pick<LongHandDocument, 'documentId' | 'status'>,\n opts: {\n targetUid: UID.Schema;\n sourceUid: UID.Schema;\n sourceStatus?: Status;\n }\n): Status[] => {\n // Ignore if the target content type does not have draft and publish enabled\n const targetContentType = strapi.getModel(opts.targetUid);\n const sourceContentType = strapi.getModel(opts.sourceUid);\n\n const targetHasDP = contentTypes.hasDraftAndPublish(targetContentType);\n const sourceHasDP = contentTypes.hasDraftAndPublish(sourceContentType);\n\n if (!targetHasDP) {\n return ['published'];\n }\n\n /**\n * If both source and target have DP enabled,\n * connect it to the same status as the source status\n */\n if (sourceHasDP && !isNil(opts.sourceStatus)) {\n return [opts.sourceStatus];\n }\n\n /**\n * Use the status from the relation if it's set\n */\n if (relation.status) {\n switch (relation.status) {\n case 'published':\n return ['published'];\n default:\n // Default to draft if it's an invalid status (e.g. modified)\n return ['draft'];\n }\n }\n\n /**\n * If DP is disabled and relation does not specify any status\n * Connect to both draft and published versions\n */\n if (!sourceHasDP) {\n return ['draft', 'published'];\n }\n\n // Default to draft as a fallback\n return ['draft'];\n};\n"],"names":["contentTypes","isNil"],"mappings":";;;;AASa,MAAA,0BAA0B,CACrC,UACA,SAKa;AAEb,QAAM,oBAAoB,OAAO,SAAS,KAAK,SAAS;AACxD,QAAM,oBAAoB,OAAO,SAAS,KAAK,SAAS;AAElD,QAAA,cAAcA,YAAAA,aAAa,mBAAmB,iBAAiB;AAC/D,QAAA,cAAcA,YAAAA,aAAa,mBAAmB,iBAAiB;AAErE,MAAI,CAAC,aAAa;AAChB,WAAO,CAAC,WAAW;AAAA,EACrB;AAMA,MAAI,eAAe,CAACC,GAAAA,MAAM,KAAK,YAAY,GAAG;AACrC,WAAA,CAAC,KAAK,YAAY;AAAA,EAC3B;AAKA,MAAI,SAAS,QAAQ;AACnB,YAAQ,SAAS,QAAQ;AAAA,MACvB,KAAK;AACH,eAAO,CAAC,WAAW;AAAA,MACrB;AAEE,eAAO,CAAC,OAAO;AAAA,IACnB;AAAA,EACF;AAMA,MAAI,CAAC,aAAa;AACT,WAAA,CAAC,SAAS,WAAW;AAAA,EAC9B;AAGA,SAAO,CAAC,OAAO;AACjB;;"}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
3
|
-
const
|
3
|
+
const fp = require("lodash/fp");
|
4
4
|
const strapiUtils = require("@strapi/utils");
|
5
5
|
const isNumeric = (value) => {
|
6
6
|
if (Array.isArray(value))
|
@@ -9,7 +9,7 @@ const isNumeric = (value) => {
|
|
9
9
|
return !Number.isNaN(parsed);
|
10
10
|
};
|
11
11
|
const toArray = (value) => {
|
12
|
-
if (
|
12
|
+
if (fp.isNil(value))
|
13
13
|
return value;
|
14
14
|
if (Array.isArray(value))
|
15
15
|
return value;
|
@@ -23,13 +23,13 @@ const mapRelation = async (callback, rel, isRecursive = false) => {
|
|
23
23
|
}
|
24
24
|
return { set: toArray(value) };
|
25
25
|
};
|
26
|
-
if (
|
26
|
+
if (fp.isNil(relation)) {
|
27
27
|
return callback(relation);
|
28
28
|
}
|
29
29
|
if (Array.isArray(relation)) {
|
30
30
|
return strapiUtils.async.map(relation, (r) => mapRelation(callback, r, true)).then((result) => result.flat().filter(Boolean)).then(wrapInSet);
|
31
31
|
}
|
32
|
-
if (
|
32
|
+
if (fp.isObject(relation)) {
|
33
33
|
if ("id" in relation || "documentId" in relation) {
|
34
34
|
const result = await callback(relation);
|
35
35
|
return wrapInSet(result);
|
@@ -84,8 +84,8 @@ const traverseEntityRelations = async (visitor, options, data) => {
|
|
84
84
|
data
|
85
85
|
);
|
86
86
|
};
|
87
|
-
const mapRelationCurried =
|
88
|
-
const traverseEntityRelationsCurried =
|
87
|
+
const mapRelationCurried = fp.curry(mapRelation);
|
88
|
+
const traverseEntityRelationsCurried = fp.curry(traverseEntityRelations);
|
89
89
|
exports.mapRelation = mapRelationCurried;
|
90
90
|
exports.traverseEntityRelations = traverseEntityRelationsCurried;
|
91
91
|
//# sourceMappingURL=map-relation.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"map-relation.js","sources":["../../../../../../src/services/document-service/transform/relations/utils/map-relation.ts"],"sourcesContent":["/* eslint-disable node/no-callback-literal */\nimport { isObject, curry, isNil } from 'lodash/fp';\n\nimport type { UID } from '@strapi/types';\nimport { traverseEntity, async } from '@strapi/utils';\n\nimport { Relation } from './types';\n\nconst isNumeric = (value: any): value is number => {\n if (Array.isArray(value)) return false; // Handle [1, 'docId'] case\n const parsed = parseInt(value, 10);\n return !Number.isNaN(parsed);\n};\n\nconst toArray = (value: any) => {\n // Keep value as it is if it's a nullish value\n if (isNil(value)) return value;\n if (Array.isArray(value)) return value;\n\n return [value];\n};\n\n/**\n * There are multiple ways to create Strapi relations.\n * This is a utility to traverse and transform relation data\n *\n *\n * For consistency and ease of use, the response will always be an object with the following shape:\n * { set: [{...}], connect: [{...}], disconnect: [{...}] }\n *\n * @example\n * transformRelationData({\n * onLongHand: (relation) => {\n * // Change the id of the relation\n * return { id: 'other' };\n * },\n * }, relation)\n */\nconst mapRelation = async (\n callback: (relation: any) => any,\n rel: Relation,\n isRecursive = false\n): Promise<Relation> => {\n let relation: Relation = rel;\n\n const wrapInSet = (value: any) => {\n // Ignore wrapping if it's a recursive call\n if (isRecursive) {\n return value;\n }\n return { set: toArray(value) };\n };\n\n // undefined | null\n if (isNil(relation)) {\n return callback(relation);\n }\n\n // LongHand[] | ShortHand[]\n if (Array.isArray(relation)) {\n return async\n .map(relation, (r: Relation) => mapRelation(callback, r, true))\n .then((result: any) => result.flat().filter(Boolean))\n .then(wrapInSet);\n }\n\n // LongHand\n if (isObject(relation)) {\n // { id: 1 } || { documentId: 1 }\n if ('id' in relation || 'documentId' in relation) {\n const result = await callback(relation);\n return wrapInSet(result);\n }\n\n // If not connecting anything, return default visitor\n if (!relation.set && !relation.disconnect && !relation.connect) {\n return callback(relation);\n }\n\n // { set }\n if (relation.set) {\n const set: any = await mapRelation(callback, relation.set, true);\n relation = { ...relation, set: toArray(set) };\n }\n\n // { disconnect}\n if (relation.disconnect) {\n const disconnect: any = await mapRelation(callback, relation.disconnect, true);\n relation = { ...relation, disconnect: toArray(disconnect) };\n }\n\n // { connect }\n if (relation.connect) {\n // Transform the relation to connect\n const connect: any = await mapRelation(callback, relation.connect, true);\n relation = { ...relation, connect: toArray(connect) };\n }\n\n return relation;\n }\n\n // ShortHand\n if (isNumeric(relation)) {\n const result = await callback({ id: relation });\n return wrapInSet(result);\n }\n\n if (typeof relation === 'string') {\n const result = await callback({ documentId: relation });\n return wrapInSet(result);\n }\n\n // Anything else\n return callback(relation);\n};\n\ntype TraverseEntity = Parameters<typeof traverseEntity>;\n\n/**\n * Utility function, same as `traverseEntity` but only for relations.\n */\nconst traverseEntityRelations = async (\n visitor: TraverseEntity[0],\n options: TraverseEntity[1],\n data: TraverseEntity[2]\n) => {\n return traverseEntity(\n async (options, utils) => {\n const { attribute } = options;\n\n if (!attribute) {\n return;\n }\n\n if (attribute.type !== 'relation') {\n return;\n }\n\n // TODO: Handle join columns\n if (attribute.useJoinTable === false) {\n return;\n }\n\n // TODO: Handle morph relations (they have multiple targets)\n const target = attribute.target as UID.Schema | undefined;\n if (!target) {\n return;\n }\n\n return visitor(options, utils);\n },\n options,\n data\n );\n};\n\nconst mapRelationCurried = curry(mapRelation);\nconst traverseEntityRelationsCurried = curry(traverseEntityRelations);\n\nexport {\n mapRelationCurried as mapRelation,\n traverseEntityRelationsCurried as traverseEntityRelations,\n};\n"],"names":["isNil","async","isObject","traverseEntity","options","curry"],"mappings":";;;;AAQA,MAAM,YAAY,CAAC,UAAgC;AAC7C,MAAA,MAAM,QAAQ,KAAK;AAAU,WAAA;AAC3B,QAAA,SAAS,SAAS,OAAO,EAAE;AAC1B,SAAA,CAAC,OAAO,MAAM,MAAM;AAC7B;AAEA,MAAM,UAAU,CAAC,UAAe;AAE9B,MAAIA,
|
1
|
+
{"version":3,"file":"map-relation.js","sources":["../../../../../../src/services/document-service/transform/relations/utils/map-relation.ts"],"sourcesContent":["/* eslint-disable node/no-callback-literal */\nimport { isObject, curry, isNil } from 'lodash/fp';\n\nimport type { UID } from '@strapi/types';\nimport { traverseEntity, async } from '@strapi/utils';\n\nimport { Relation } from './types';\n\nconst isNumeric = (value: any): value is number => {\n if (Array.isArray(value)) return false; // Handle [1, 'docId'] case\n const parsed = parseInt(value, 10);\n return !Number.isNaN(parsed);\n};\n\nconst toArray = (value: any) => {\n // Keep value as it is if it's a nullish value\n if (isNil(value)) return value;\n if (Array.isArray(value)) return value;\n\n return [value];\n};\n\n/**\n * There are multiple ways to create Strapi relations.\n * This is a utility to traverse and transform relation data\n *\n *\n * For consistency and ease of use, the response will always be an object with the following shape:\n * { set: [{...}], connect: [{...}], disconnect: [{...}] }\n *\n * @example\n * transformRelationData({\n * onLongHand: (relation) => {\n * // Change the id of the relation\n * return { id: 'other' };\n * },\n * }, relation)\n */\nconst mapRelation = async (\n callback: (relation: any) => any,\n rel: Relation,\n isRecursive = false\n): Promise<Relation> => {\n let relation: Relation = rel;\n\n const wrapInSet = (value: any) => {\n // Ignore wrapping if it's a recursive call\n if (isRecursive) {\n return value;\n }\n return { set: toArray(value) };\n };\n\n // undefined | null\n if (isNil(relation)) {\n return callback(relation);\n }\n\n // LongHand[] | ShortHand[]\n if (Array.isArray(relation)) {\n return async\n .map(relation, (r: Relation) => mapRelation(callback, r, true))\n .then((result: any) => result.flat().filter(Boolean))\n .then(wrapInSet);\n }\n\n // LongHand\n if (isObject(relation)) {\n // { id: 1 } || { documentId: 1 }\n if ('id' in relation || 'documentId' in relation) {\n const result = await callback(relation);\n return wrapInSet(result);\n }\n\n // If not connecting anything, return default visitor\n if (!relation.set && !relation.disconnect && !relation.connect) {\n return callback(relation);\n }\n\n // { set }\n if (relation.set) {\n const set: any = await mapRelation(callback, relation.set, true);\n relation = { ...relation, set: toArray(set) };\n }\n\n // { disconnect}\n if (relation.disconnect) {\n const disconnect: any = await mapRelation(callback, relation.disconnect, true);\n relation = { ...relation, disconnect: toArray(disconnect) };\n }\n\n // { connect }\n if (relation.connect) {\n // Transform the relation to connect\n const connect: any = await mapRelation(callback, relation.connect, true);\n relation = { ...relation, connect: toArray(connect) };\n }\n\n return relation;\n }\n\n // ShortHand\n if (isNumeric(relation)) {\n const result = await callback({ id: relation });\n return wrapInSet(result);\n }\n\n if (typeof relation === 'string') {\n const result = await callback({ documentId: relation });\n return wrapInSet(result);\n }\n\n // Anything else\n return callback(relation);\n};\n\ntype TraverseEntity = Parameters<typeof traverseEntity>;\n\n/**\n * Utility function, same as `traverseEntity` but only for relations.\n */\nconst traverseEntityRelations = async (\n visitor: TraverseEntity[0],\n options: TraverseEntity[1],\n data: TraverseEntity[2]\n) => {\n return traverseEntity(\n async (options, utils) => {\n const { attribute } = options;\n\n if (!attribute) {\n return;\n }\n\n if (attribute.type !== 'relation') {\n return;\n }\n\n // TODO: Handle join columns\n if (attribute.useJoinTable === false) {\n return;\n }\n\n // TODO: Handle morph relations (they have multiple targets)\n const target = attribute.target as UID.Schema | undefined;\n if (!target) {\n return;\n }\n\n return visitor(options, utils);\n },\n options,\n data\n );\n};\n\nconst mapRelationCurried = curry(mapRelation);\nconst traverseEntityRelationsCurried = curry(traverseEntityRelations);\n\nexport {\n mapRelationCurried as mapRelation,\n traverseEntityRelationsCurried as traverseEntityRelations,\n};\n"],"names":["isNil","async","isObject","traverseEntity","options","curry"],"mappings":";;;;AAQA,MAAM,YAAY,CAAC,UAAgC;AAC7C,MAAA,MAAM,QAAQ,KAAK;AAAU,WAAA;AAC3B,QAAA,SAAS,SAAS,OAAO,EAAE;AAC1B,SAAA,CAAC,OAAO,MAAM,MAAM;AAC7B;AAEA,MAAM,UAAU,CAAC,UAAe;AAE9B,MAAIA,GAAAA,MAAM,KAAK;AAAU,WAAA;AACrB,MAAA,MAAM,QAAQ,KAAK;AAAU,WAAA;AAEjC,SAAO,CAAC,KAAK;AACf;AAkBA,MAAM,cAAc,OAClB,UACA,KACA,cAAc,UACQ;AACtB,MAAI,WAAqB;AAEnB,QAAA,YAAY,CAAC,UAAe;AAEhC,QAAI,aAAa;AACR,aAAA;AAAA,IACT;AACA,WAAO,EAAE,KAAK,QAAQ,KAAK,EAAE;AAAA,EAAA;AAI3B,MAAAA,GAAAA,MAAM,QAAQ,GAAG;AACnB,WAAO,SAAS,QAAQ;AAAA,EAC1B;AAGI,MAAA,MAAM,QAAQ,QAAQ,GAAG;AACpB,WAAAC,YAAA,MACJ,IAAI,UAAU,CAAC,MAAgB,YAAY,UAAU,GAAG,IAAI,CAAC,EAC7D,KAAK,CAAC,WAAgB,OAAO,OAAO,OAAO,OAAO,CAAC,EACnD,KAAK,SAAS;AAAA,EACnB;AAGI,MAAAC,GAAAA,SAAS,QAAQ,GAAG;AAElB,QAAA,QAAQ,YAAY,gBAA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AAA,QAAQA,UAAS,KAAK;AAAA,IAC/B;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEJ;AAEM,MAAA,qBAAqBC,SAAM,WAAW;AACtC,MAAA,iCAAiCA,SAAM,uBAAuB;;;"}
|
@@ -1,4 +1,3 @@
|
|
1
1
|
import { yup } from '@strapi/utils';
|
2
|
-
declare const
|
3
|
-
export default _default;
|
2
|
+
export declare const blocksValidator: () => yup.ArraySchema<any, import("yup/lib/types").AnyObject, any[] | undefined, any[] | undefined>;
|
4
3
|
//# sourceMappingURL=blocks-validator.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"blocks-validator.d.ts","sourceRoot":"","sources":["../../../src/services/entity-validator/blocks-validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;
|
1
|
+
{"version":3,"file":"blocks-validator.d.ts","sourceRoot":"","sources":["../../../src/services/entity-validator/blocks-validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAwKpC,eAAO,MAAM,eAAe,qGAA8B,CAAC"}
|
@@ -1,4 +1,5 @@
|
|
1
1
|
"use strict";
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
2
3
|
const strapiUtils = require("@strapi/utils");
|
3
4
|
const textNodeValidator = strapiUtils.yup.object().shape({
|
4
5
|
type: strapiUtils.yup.string().equals(["text"]).required(),
|
@@ -121,7 +122,7 @@ const blockNodeValidator = strapiUtils.yup.lazy((value) => {
|
|
121
122
|
});
|
122
123
|
}
|
123
124
|
});
|
124
|
-
const
|
125
|
-
const blocksValidator
|
126
|
-
|
125
|
+
const blocksValidatorSchema = strapiUtils.yup.array().of(blockNodeValidator);
|
126
|
+
const blocksValidator = () => blocksValidatorSchema;
|
127
|
+
exports.blocksValidator = blocksValidator;
|
127
128
|
//# sourceMappingURL=blocks-validator.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"blocks-validator.js","sources":["../../../src/services/entity-validator/blocks-validator.ts"],"sourcesContent":["import { yup } from '@strapi/utils';\n\nconst textNodeValidator = yup.object().shape({\n type: yup.string().equals(['text']).required(),\n text: yup\n .string()\n .test(\n 'is-valid-text',\n 'Text must be defined with at least an empty string',\n (text: unknown) => {\n return typeof text === 'string' || text === '';\n }\n ),\n bold: yup.boolean(),\n italic: yup.boolean(),\n underline: yup.boolean(),\n strikethrough: yup.boolean(),\n code: yup.boolean(),\n});\n\nconst checkValidLink = (link: string) => {\n try {\n // eslint-disable-next-line no-new\n new URL(link.startsWith('/') ? `https://strapi.io${link}` : link);\n } catch (error) {\n return false;\n }\n return true;\n};\n\nconst linkNodeValidator = yup.object().shape({\n type: yup.string().equals(['link']).required(),\n url: yup\n .string()\n .test('invalid-url', 'Please specify a valid link.', (value) => checkValidLink(value ?? '')),\n children: yup.array().of(textNodeValidator).required(),\n});\n\n// TODO: remove any with a correct Type\nconst inlineNodeValidator: any = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'text':\n return textNodeValidator;\n case 'link':\n return linkNodeValidator;\n default:\n return yup.mixed().test('invalid-type', 'Inline node must be Text or Link', () => {\n return false;\n });\n }\n});\n\nconst paragraphNodeValidator = yup.object().shape({\n type: yup.string().equals(['paragraph']).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Paragraph node children must have at least one Text or Link node')\n .required(),\n});\n\nconst headingNodeValidator = yup.object().shape({\n type: yup.string().equals(['heading']).required(),\n level: yup.number().oneOf([1, 2, 3, 4, 5, 6]).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Heading node children must have at least one Text or Link node')\n .required(),\n});\n\nconst quoteNodeValidator = yup.object().shape({\n type: yup.string().equals(['quote']).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Quote node children must have at least one Text or Link node')\n .required(),\n});\n\nconst codeBlockValidator = yup.object().shape({\n type: yup.string().equals(['code']).required(),\n syntax: yup.string().nullable(),\n children: yup\n .array()\n .of(textNodeValidator)\n .min(1, 'Quote node children must have at least one Text or Link node')\n .required(),\n});\n\nconst listItemNode = yup.object().shape({\n type: yup.string().equals(['list-item']).required(),\n children: yup.array().of(inlineNodeValidator).required(),\n});\n\n// Allow children to be either a listItemNode or a listNode itself\n// @ts-expect-error - listChildrenValidator needs a type\nconst listChildrenValidator = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'list':\n return listNodeValidator;\n case 'list-item':\n return listItemNode;\n default:\n return yup.mixed().test('invalid-type', 'Inline node must be list-item or list', () => {\n return false;\n });\n }\n});\n\n// @ts-expect-error - listNodeValidator needs a type\nconst listNodeValidator = yup.object().shape({\n type: yup.string().equals(['list']).required(),\n format: yup.string().equals(['ordered', 'unordered']).required(),\n children: yup\n .array()\n .of(listChildrenValidator)\n .min(1, 'List node children must have at least one ListItem or ListNode')\n .required(),\n});\n\nconst imageNodeValidator = yup.object().shape({\n type: yup.string().equals(['image']).required(),\n image: yup.object().shape({\n name: yup.string().required(),\n alternativeText: yup.string().nullable(),\n url: yup.string().required(),\n caption: yup.string().nullable(),\n width: yup.number().required(),\n height: yup.number().required(),\n formats: yup.object().required(),\n hash: yup.string().required(),\n ext: yup.string().required(),\n mime: yup.string().required(),\n size: yup.number().required(),\n previewUrl: yup.string().nullable(),\n provider: yup.string().required(),\n provider_metadata: yup.mixed().nullable(),\n createdAt: yup.string().required(),\n updatedAt: yup.string().required(),\n }),\n children: yup.array().of(inlineNodeValidator).required(),\n});\n\n// TODO: remove the any and replace with a correct Type\nconst blockNodeValidator: any = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'paragraph':\n return paragraphNodeValidator;\n case 'heading':\n return headingNodeValidator;\n case 'quote':\n return quoteNodeValidator;\n case 'list':\n return listNodeValidator;\n case 'image':\n return imageNodeValidator;\n case 'code':\n return codeBlockValidator;\n default:\n return yup.mixed().test('invalid-type', 'Block node is of invalid type', () => {\n return false;\n });\n }\n});\n\nconst
|
1
|
+
{"version":3,"file":"blocks-validator.js","sources":["../../../src/services/entity-validator/blocks-validator.ts"],"sourcesContent":["import { yup } from '@strapi/utils';\n\nconst textNodeValidator = yup.object().shape({\n type: yup.string().equals(['text']).required(),\n text: yup\n .string()\n .test(\n 'is-valid-text',\n 'Text must be defined with at least an empty string',\n (text: unknown) => {\n return typeof text === 'string' || text === '';\n }\n ),\n bold: yup.boolean(),\n italic: yup.boolean(),\n underline: yup.boolean(),\n strikethrough: yup.boolean(),\n code: yup.boolean(),\n});\n\nconst checkValidLink = (link: string) => {\n try {\n // eslint-disable-next-line no-new\n new URL(link.startsWith('/') ? `https://strapi.io${link}` : link);\n } catch (error) {\n return false;\n }\n return true;\n};\n\nconst linkNodeValidator = yup.object().shape({\n type: yup.string().equals(['link']).required(),\n url: yup\n .string()\n .test('invalid-url', 'Please specify a valid link.', (value) => checkValidLink(value ?? '')),\n children: yup.array().of(textNodeValidator).required(),\n});\n\n// TODO: remove any with a correct Type\nconst inlineNodeValidator: any = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'text':\n return textNodeValidator;\n case 'link':\n return linkNodeValidator;\n default:\n return yup.mixed().test('invalid-type', 'Inline node must be Text or Link', () => {\n return false;\n });\n }\n});\n\nconst paragraphNodeValidator = yup.object().shape({\n type: yup.string().equals(['paragraph']).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Paragraph node children must have at least one Text or Link node')\n .required(),\n});\n\nconst headingNodeValidator = yup.object().shape({\n type: yup.string().equals(['heading']).required(),\n level: yup.number().oneOf([1, 2, 3, 4, 5, 6]).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Heading node children must have at least one Text or Link node')\n .required(),\n});\n\nconst quoteNodeValidator = yup.object().shape({\n type: yup.string().equals(['quote']).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Quote node children must have at least one Text or Link node')\n .required(),\n});\n\nconst codeBlockValidator = yup.object().shape({\n type: yup.string().equals(['code']).required(),\n syntax: yup.string().nullable(),\n children: yup\n .array()\n .of(textNodeValidator)\n .min(1, 'Quote node children must have at least one Text or Link node')\n .required(),\n});\n\nconst listItemNode = yup.object().shape({\n type: yup.string().equals(['list-item']).required(),\n children: yup.array().of(inlineNodeValidator).required(),\n});\n\n// Allow children to be either a listItemNode or a listNode itself\n// @ts-expect-error - listChildrenValidator needs a type\nconst listChildrenValidator = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'list':\n return listNodeValidator;\n case 'list-item':\n return listItemNode;\n default:\n return yup.mixed().test('invalid-type', 'Inline node must be list-item or list', () => {\n return false;\n });\n }\n});\n\n// @ts-expect-error - listNodeValidator needs a type\nconst listNodeValidator = yup.object().shape({\n type: yup.string().equals(['list']).required(),\n format: yup.string().equals(['ordered', 'unordered']).required(),\n children: yup\n .array()\n .of(listChildrenValidator)\n .min(1, 'List node children must have at least one ListItem or ListNode')\n .required(),\n});\n\nconst imageNodeValidator = yup.object().shape({\n type: yup.string().equals(['image']).required(),\n image: yup.object().shape({\n name: yup.string().required(),\n alternativeText: yup.string().nullable(),\n url: yup.string().required(),\n caption: yup.string().nullable(),\n width: yup.number().required(),\n height: yup.number().required(),\n formats: yup.object().required(),\n hash: yup.string().required(),\n ext: yup.string().required(),\n mime: yup.string().required(),\n size: yup.number().required(),\n previewUrl: yup.string().nullable(),\n provider: yup.string().required(),\n provider_metadata: yup.mixed().nullable(),\n createdAt: yup.string().required(),\n updatedAt: yup.string().required(),\n }),\n children: yup.array().of(inlineNodeValidator).required(),\n});\n\n// TODO: remove the any and replace with a correct Type\nconst blockNodeValidator: any = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'paragraph':\n return paragraphNodeValidator;\n case 'heading':\n return headingNodeValidator;\n case 'quote':\n return quoteNodeValidator;\n case 'list':\n return listNodeValidator;\n case 'image':\n return imageNodeValidator;\n case 'code':\n return codeBlockValidator;\n default:\n return yup.mixed().test('invalid-type', 'Block node is of invalid type', () => {\n return false;\n });\n }\n});\n\nconst blocksValidatorSchema = yup.array().of(blockNodeValidator);\n\nexport const blocksValidator = () => blocksValidatorSchema;\n"],"names":["yup"],"mappings":";;;AAEA,MAAM,oBAAoBA,YAAA,IAAI,OAAO,EAAE,MAAM;AAAA,EAC3C,MAAMA,gBAAI,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,SAAS;AAAA,EAC7C,MAAMA,YAAAA,IACH,OAAA,EACA;AAAA,IACC;AAAA,IACA;AAAA,IACA,CAAC,SAAkB;AACV,aAAA,OAAO,SAAS,YAAY,SAAS;AAAA,IAC9C;AAAA,EACF;AAAA,EACF,MAAMA,gBAAI,QAAQ;AAAA,EAClB,QAAQA,gBAAI,QAAQ;AAAA,EACpB,WAAWA,gBAAI,QAAQ;AAAA,EACvB,eAAeA,gBAAI,QAAQ;AAAA,EAC3B,MAAMA,gBAAI,QAAQ;AACpB,CAAC;AAED,MAAM,iBAAiB,CAAC,SAAiB;AACnC,MAAA;AAEE,QAAA,IAAI,KAAK,WAAW,GAAG,IAAI,oBAAoB,IAAI,KAAK,IAAI;AAAA,WACzD,OAAO;AACP,WAAA;AAAA,EACT;AACO,SAAA;AACT;AAEA,MAAM,oBAAoBA,YAAA,IAAI,OAAO,EAAE,MAAM;AAAA,EAC3C,MAAMA,gBAAI,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,SAAS;AAAA,EAC7C,KAAKA,YAAA,IACF,OAAO,EACP,KAAK,eAAe,gCAAgC,CAAC,UAAU,eAAe,SAAS,EAAE,CAAC;AAAA,EAC7F,UAAUA,YAAI,IAAA,MAAA,EAAQ,GAAG,iBAAiB,EAAE,SAAS;AACvD,CAAC;AAGD,MAAM,sBAA2BA,YAAA,IAAI,KAAK,CAAC,UAA4B;AACrE,UAAQ,MAAM,MAAM;AAAA,IAClB,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT;AACE,aAAOA,YAAAA,IAAI,MAAM,EAAE,KAAK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S;AAAA,IAC/B,MAAMA,YAAA,IAAI,OAAO,EAAE,SAAS;AAAA,IAC5B,KAAKA,YAAA,IAAI,OAAO,EAAE,SAAS;AAAA,IAC3B,MAAMA,YAAA,IAAI,OAAO,EAAE,SAAS;AAAA,IAC5B,MAAMA,YAAA,IAAI,OAAO,EAAE,SAAS;AAAA,IAC5B,YAAYA,YAAA,IAAI,OAAO,EAAE,SAAS;AAAA,IAClC,UAAUA,YAAA,IAAI,OAAO,EAAE,SAAS;AAAA,IAChC,mBAAmBA,YAAA,IAAI,MAAM,EAAE,SAAS;AAAA,IACxC,WAAWA,YAAA,IAAI,OAAO,EAAE,SAAS;AAAA,IACjC,WAAWA,YAAA,IAAI,OAAO,EAAE,SAAS;AAAA,EAAA,CAClC;AAAA,EACD,UAAUA,YAAI,IAAA,MAAA,EAAQ,GAAG,mBAAmB,EAAE,SAAS;AACzD,CAAC;AAGD,MAAM,qBAA0BA,YAAA,IAAI,KAAK,CAAC,UAA4B;AACpE,UAAQ,MAAM,MAAM;AAAA,IAClB,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT;AACE,aAAOA,YAAAA,IAAI,MAAM,EAAE,KAAK,gBAAgB,iCAAiC,MAAM;AACtE,eAAA;AAAA,MAAA,CACR;AAAA,EACL;AACF,CAAC;AAED,MAAM,wBAAwBA,YAAAA,IAAI,MAAM,EAAE,GAAG,kBAAkB;AAExD,MAAM,kBAAkB,MAAM;;"}
|
@@ -120,9 +120,9 @@ const blockNodeValidator = yup.lazy((value) => {
|
|
120
120
|
});
|
121
121
|
}
|
122
122
|
});
|
123
|
-
const
|
124
|
-
const blocksValidator
|
123
|
+
const blocksValidatorSchema = yup.array().of(blockNodeValidator);
|
124
|
+
const blocksValidator = () => blocksValidatorSchema;
|
125
125
|
export {
|
126
|
-
blocksValidator
|
126
|
+
blocksValidator
|
127
127
|
};
|
128
128
|
//# sourceMappingURL=blocks-validator.mjs.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"blocks-validator.mjs","sources":["../../../src/services/entity-validator/blocks-validator.ts"],"sourcesContent":["import { yup } from '@strapi/utils';\n\nconst textNodeValidator = yup.object().shape({\n type: yup.string().equals(['text']).required(),\n text: yup\n .string()\n .test(\n 'is-valid-text',\n 'Text must be defined with at least an empty string',\n (text: unknown) => {\n return typeof text === 'string' || text === '';\n }\n ),\n bold: yup.boolean(),\n italic: yup.boolean(),\n underline: yup.boolean(),\n strikethrough: yup.boolean(),\n code: yup.boolean(),\n});\n\nconst checkValidLink = (link: string) => {\n try {\n // eslint-disable-next-line no-new\n new URL(link.startsWith('/') ? `https://strapi.io${link}` : link);\n } catch (error) {\n return false;\n }\n return true;\n};\n\nconst linkNodeValidator = yup.object().shape({\n type: yup.string().equals(['link']).required(),\n url: yup\n .string()\n .test('invalid-url', 'Please specify a valid link.', (value) => checkValidLink(value ?? '')),\n children: yup.array().of(textNodeValidator).required(),\n});\n\n// TODO: remove any with a correct Type\nconst inlineNodeValidator: any = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'text':\n return textNodeValidator;\n case 'link':\n return linkNodeValidator;\n default:\n return yup.mixed().test('invalid-type', 'Inline node must be Text or Link', () => {\n return false;\n });\n }\n});\n\nconst paragraphNodeValidator = yup.object().shape({\n type: yup.string().equals(['paragraph']).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Paragraph node children must have at least one Text or Link node')\n .required(),\n});\n\nconst headingNodeValidator = yup.object().shape({\n type: yup.string().equals(['heading']).required(),\n level: yup.number().oneOf([1, 2, 3, 4, 5, 6]).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Heading node children must have at least one Text or Link node')\n .required(),\n});\n\nconst quoteNodeValidator = yup.object().shape({\n type: yup.string().equals(['quote']).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Quote node children must have at least one Text or Link node')\n .required(),\n});\n\nconst codeBlockValidator = yup.object().shape({\n type: yup.string().equals(['code']).required(),\n syntax: yup.string().nullable(),\n children: yup\n .array()\n .of(textNodeValidator)\n .min(1, 'Quote node children must have at least one Text or Link node')\n .required(),\n});\n\nconst listItemNode = yup.object().shape({\n type: yup.string().equals(['list-item']).required(),\n children: yup.array().of(inlineNodeValidator).required(),\n});\n\n// Allow children to be either a listItemNode or a listNode itself\n// @ts-expect-error - listChildrenValidator needs a type\nconst listChildrenValidator = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'list':\n return listNodeValidator;\n case 'list-item':\n return listItemNode;\n default:\n return yup.mixed().test('invalid-type', 'Inline node must be list-item or list', () => {\n return false;\n });\n }\n});\n\n// @ts-expect-error - listNodeValidator needs a type\nconst listNodeValidator = yup.object().shape({\n type: yup.string().equals(['list']).required(),\n format: yup.string().equals(['ordered', 'unordered']).required(),\n children: yup\n .array()\n .of(listChildrenValidator)\n .min(1, 'List node children must have at least one ListItem or ListNode')\n .required(),\n});\n\nconst imageNodeValidator = yup.object().shape({\n type: yup.string().equals(['image']).required(),\n image: yup.object().shape({\n name: yup.string().required(),\n alternativeText: yup.string().nullable(),\n url: yup.string().required(),\n caption: yup.string().nullable(),\n width: yup.number().required(),\n height: yup.number().required(),\n formats: yup.object().required(),\n hash: yup.string().required(),\n ext: yup.string().required(),\n mime: yup.string().required(),\n size: yup.number().required(),\n previewUrl: yup.string().nullable(),\n provider: yup.string().required(),\n provider_metadata: yup.mixed().nullable(),\n createdAt: yup.string().required(),\n updatedAt: yup.string().required(),\n }),\n children: yup.array().of(inlineNodeValidator).required(),\n});\n\n// TODO: remove the any and replace with a correct Type\nconst blockNodeValidator: any = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'paragraph':\n return paragraphNodeValidator;\n case 'heading':\n return headingNodeValidator;\n case 'quote':\n return quoteNodeValidator;\n case 'list':\n return listNodeValidator;\n case 'image':\n return imageNodeValidator;\n case 'code':\n return codeBlockValidator;\n default:\n return yup.mixed().test('invalid-type', 'Block node is of invalid type', () => {\n return false;\n });\n }\n});\n\nconst
|
1
|
+
{"version":3,"file":"blocks-validator.mjs","sources":["../../../src/services/entity-validator/blocks-validator.ts"],"sourcesContent":["import { yup } from '@strapi/utils';\n\nconst textNodeValidator = yup.object().shape({\n type: yup.string().equals(['text']).required(),\n text: yup\n .string()\n .test(\n 'is-valid-text',\n 'Text must be defined with at least an empty string',\n (text: unknown) => {\n return typeof text === 'string' || text === '';\n }\n ),\n bold: yup.boolean(),\n italic: yup.boolean(),\n underline: yup.boolean(),\n strikethrough: yup.boolean(),\n code: yup.boolean(),\n});\n\nconst checkValidLink = (link: string) => {\n try {\n // eslint-disable-next-line no-new\n new URL(link.startsWith('/') ? `https://strapi.io${link}` : link);\n } catch (error) {\n return false;\n }\n return true;\n};\n\nconst linkNodeValidator = yup.object().shape({\n type: yup.string().equals(['link']).required(),\n url: yup\n .string()\n .test('invalid-url', 'Please specify a valid link.', (value) => checkValidLink(value ?? '')),\n children: yup.array().of(textNodeValidator).required(),\n});\n\n// TODO: remove any with a correct Type\nconst inlineNodeValidator: any = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'text':\n return textNodeValidator;\n case 'link':\n return linkNodeValidator;\n default:\n return yup.mixed().test('invalid-type', 'Inline node must be Text or Link', () => {\n return false;\n });\n }\n});\n\nconst paragraphNodeValidator = yup.object().shape({\n type: yup.string().equals(['paragraph']).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Paragraph node children must have at least one Text or Link node')\n .required(),\n});\n\nconst headingNodeValidator = yup.object().shape({\n type: yup.string().equals(['heading']).required(),\n level: yup.number().oneOf([1, 2, 3, 4, 5, 6]).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Heading node children must have at least one Text or Link node')\n .required(),\n});\n\nconst quoteNodeValidator = yup.object().shape({\n type: yup.string().equals(['quote']).required(),\n children: yup\n .array()\n .of(inlineNodeValidator)\n .min(1, 'Quote node children must have at least one Text or Link node')\n .required(),\n});\n\nconst codeBlockValidator = yup.object().shape({\n type: yup.string().equals(['code']).required(),\n syntax: yup.string().nullable(),\n children: yup\n .array()\n .of(textNodeValidator)\n .min(1, 'Quote node children must have at least one Text or Link node')\n .required(),\n});\n\nconst listItemNode = yup.object().shape({\n type: yup.string().equals(['list-item']).required(),\n children: yup.array().of(inlineNodeValidator).required(),\n});\n\n// Allow children to be either a listItemNode or a listNode itself\n// @ts-expect-error - listChildrenValidator needs a type\nconst listChildrenValidator = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'list':\n return listNodeValidator;\n case 'list-item':\n return listItemNode;\n default:\n return yup.mixed().test('invalid-type', 'Inline node must be list-item or list', () => {\n return false;\n });\n }\n});\n\n// @ts-expect-error - listNodeValidator needs a type\nconst listNodeValidator = yup.object().shape({\n type: yup.string().equals(['list']).required(),\n format: yup.string().equals(['ordered', 'unordered']).required(),\n children: yup\n .array()\n .of(listChildrenValidator)\n .min(1, 'List node children must have at least one ListItem or ListNode')\n .required(),\n});\n\nconst imageNodeValidator = yup.object().shape({\n type: yup.string().equals(['image']).required(),\n image: yup.object().shape({\n name: yup.string().required(),\n alternativeText: yup.string().nullable(),\n url: yup.string().required(),\n caption: yup.string().nullable(),\n width: yup.number().required(),\n height: yup.number().required(),\n formats: yup.object().required(),\n hash: yup.string().required(),\n ext: yup.string().required(),\n mime: yup.string().required(),\n size: yup.number().required(),\n previewUrl: yup.string().nullable(),\n provider: yup.string().required(),\n provider_metadata: yup.mixed().nullable(),\n createdAt: yup.string().required(),\n updatedAt: yup.string().required(),\n }),\n children: yup.array().of(inlineNodeValidator).required(),\n});\n\n// TODO: remove the any and replace with a correct Type\nconst blockNodeValidator: any = yup.lazy((value: { type: string }) => {\n switch (value.type) {\n case 'paragraph':\n return paragraphNodeValidator;\n case 'heading':\n return headingNodeValidator;\n case 'quote':\n return quoteNodeValidator;\n case 'list':\n return listNodeValidator;\n case 'image':\n return imageNodeValidator;\n case 'code':\n return codeBlockValidator;\n default:\n return yup.mixed().test('invalid-type', 'Block node is of invalid type', () => {\n return false;\n });\n }\n});\n\nconst blocksValidatorSchema = yup.array().of(blockNodeValidator);\n\nexport const blocksValidator = () => blocksValidatorSchema;\n"],"names":[],"mappings":";AAEA,MAAM,oBAAoB,IAAI,OAAO,EAAE,MAAM;AAAA,EAC3C,MAAM,IAAI,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,SAAS;AAAA,EAC7C,MAAM,IACH,OAAA,EACA;AAAA,IACC;AAAA,IACA;AAAA,IACA,CAAC,SAAkB;AACV,aAAA,OAAO,SAAS,YAAY,SAAS;AAAA,IAC9C;AAAA,EACF;AAAA,EACF,MAAM,IAAI,QAAQ;AAAA,EAClB,QAAQ,IAAI,QAAQ;AAAA,EACpB,WAAW,IAAI,QAAQ;AAAA,EACvB,eAAe,IAAI,QAAQ;AAAA,EAC3B,MAAM,IAAI,QAAQ;AACpB,CAAC;AAED,MAAM,iBAAiB,CAAC,SAAiB;AACnC,MAAA;AAEE,QAAA,IAAI,KAAK,WAAW,GAAG,IAAI,oBAAoB,IAAI,KAAK,IAAI;AAAA,WACzD,OAAO;AACP,WAAA;AAAA,EACT;AACO,SAAA;AACT;AAEA,MAAM,oBAAoB,IAAI,OAAO,EAAE,MAAM;AAAA,EAC3C,MAAM,IAAI,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,SAAS;AAAA,EAC7C,KAAK,IACF,OAAO,EACP,KAAK,eAAe,gCAAgC,CAAC,UAAU,eAAe,SAAS,EAAE,CAAC;AAAA,EAC7F,UAAU,IAAI,MAAA,EAAQ,GAAG,iBAAiB,EAAE,SAAS;AACvD,CAAC;AAGD,MAAM,sBAA2B,IAAI,KAAK,CAAC,UAA4B;AACrE,UAAQ,MAAM,MAAM;AAAA,IAClB,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAA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I,OAAO,EAAE,SAAS;AAAA,IAC5B,YAAY,IAAI,OAAO,EAAE,SAAS;AAAA,IAClC,UAAU,IAAI,OAAO,EAAE,SAAS;AAAA,IAChC,mBAAmB,IAAI,MAAM,EAAE,SAAS;AAAA,IACxC,WAAW,IAAI,OAAO,EAAE,SAAS;AAAA,IACjC,WAAW,IAAI,OAAO,EAAE,SAAS;AAAA,EAAA,CAClC;AAAA,EACD,UAAU,IAAI,MAAA,EAAQ,GAAG,mBAAmB,EAAE,SAAS;AACzD,CAAC;AAGD,MAAM,qBAA0B,IAAI,KAAK,CAAC,UAA4B;AACpE,UAAQ,MAAM,MAAM;AAAA,IAClB,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT;AACE,aAAO,IAAI,MAAM,EAAE,KAAK,gBAAgB,iCAAiC,MAAM;AACtE,eAAA;AAAA,MAAA,CACR;AAAA,EACL;AACF,CAAC;AAED,MAAM,wBAAwB,IAAI,MAAM,EAAE,GAAG,kBAAkB;AAExD,MAAM,kBAAkB,MAAM;"}
|
@@ -2,7 +2,7 @@
|
|
2
2
|
* Entity validator
|
3
3
|
* Module that will validate input data for entity creation or edition
|
4
4
|
*/
|
5
|
-
import { Modules, Struct } from '@strapi/types';
|
5
|
+
import { Modules, Struct, Schema } from '@strapi/types';
|
6
6
|
export type ComponentContext = {
|
7
7
|
parentContent: {
|
8
8
|
model: Struct.Schema;
|
@@ -11,6 +11,7 @@ export type ComponentContext = {
|
|
11
11
|
};
|
12
12
|
pathToComponent: string[];
|
13
13
|
repeatableData: Modules.EntityValidator.Entity[];
|
14
|
+
fullDynamicZoneContent?: Schema.Attribute.Value<Schema.Attribute.DynamicZone>;
|
14
15
|
};
|
15
16
|
interface ValidatorContext {
|
16
17
|
isDraft?: boolean;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/entity-validator/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,OAAO,EAAO,MAAM,
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/entity-validator/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,OAAO,EAAO,MAAM,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAa7D,MAAM,MAAM,gBAAgB,GAAG;IAC7B,aAAa,EAAE;QAEb,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC;QAErB,EAAE,CAAC,EAAE,MAAM,CAAC;QAGZ,OAAO,CAAC,EAAE,gBAAgB,CAAC;KAC5B,CAAC;IAEF,eAAe,EAAE,MAAM,EAAE,CAAC;IAG1B,cAAc,EAAE,OAAO,CAAC,eAAe,CAAC,MAAM,EAAE,CAAC;IACjD,sBAAsB,CAAC,EAAE,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;CAC/E,CAAC;AAWF,UAAU,gBAAgB;IACxB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB;AA+gBD,QAAA,MAAM,eAAe,EAAE,OAAO,CAAC,eAAe,CAAC,eAG9C,CAAC;AAEF,eAAe,eAAe,CAAC"}
|