@strapi/core 0.0.0-experimental.04d28a073af6fa6a173e2212fa8593a4df25efbf → 0.0.0-experimental.16eaafeff6bd4cd49d56f3c31d002cad71a1134a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of @strapi/core might be problematic. Click here for more details.

Files changed (152) hide show
  1. package/dist/Strapi.d.ts +3 -1
  2. package/dist/Strapi.d.ts.map +1 -1
  3. package/dist/Strapi.js +57 -13
  4. package/dist/Strapi.js.map +1 -1
  5. package/dist/Strapi.mjs +38 -13
  6. package/dist/Strapi.mjs.map +1 -1
  7. package/dist/core-api/controller/collection-type.d.ts.map +1 -1
  8. package/dist/core-api/controller/collection-type.js +2 -0
  9. package/dist/core-api/controller/collection-type.js.map +1 -1
  10. package/dist/core-api/controller/collection-type.mjs +2 -0
  11. package/dist/core-api/controller/collection-type.mjs.map +1 -1
  12. package/dist/core-api/controller/single-type.d.ts.map +1 -1
  13. package/dist/core-api/controller/single-type.js +1 -0
  14. package/dist/core-api/controller/single-type.js.map +1 -1
  15. package/dist/core-api/controller/single-type.mjs +1 -0
  16. package/dist/core-api/controller/single-type.mjs.map +1 -1
  17. package/dist/core-api/service/collection-type.d.ts +1 -7
  18. package/dist/core-api/service/collection-type.d.ts.map +1 -1
  19. package/dist/core-api/service/collection-type.js +5 -3
  20. package/dist/core-api/service/collection-type.js.map +1 -1
  21. package/dist/core-api/service/collection-type.mjs +6 -4
  22. package/dist/core-api/service/collection-type.mjs.map +1 -1
  23. package/dist/core-api/service/pagination.d.ts +4 -11
  24. package/dist/core-api/service/pagination.d.ts.map +1 -1
  25. package/dist/core-api/service/pagination.js +14 -40
  26. package/dist/core-api/service/pagination.js.map +1 -1
  27. package/dist/core-api/service/pagination.mjs +16 -42
  28. package/dist/core-api/service/pagination.mjs.map +1 -1
  29. package/dist/core-api/service/single-type.d.ts.map +1 -1
  30. package/dist/core-api/service/single-type.js +2 -1
  31. package/dist/core-api/service/single-type.js.map +1 -1
  32. package/dist/core-api/service/single-type.mjs +2 -1
  33. package/dist/core-api/service/single-type.mjs.map +1 -1
  34. package/dist/loaders/apis.d.ts.map +1 -1
  35. package/dist/loaders/apis.js +10 -10
  36. package/dist/loaders/apis.js.map +1 -1
  37. package/dist/loaders/apis.mjs +10 -10
  38. package/dist/loaders/apis.mjs.map +1 -1
  39. package/dist/loaders/plugins/get-enabled-plugins.d.ts.map +1 -1
  40. package/dist/loaders/plugins/get-enabled-plugins.js +5 -5
  41. package/dist/loaders/plugins/get-enabled-plugins.js.map +1 -1
  42. package/dist/loaders/plugins/get-enabled-plugins.mjs +5 -5
  43. package/dist/loaders/plugins/get-enabled-plugins.mjs.map +1 -1
  44. package/dist/middlewares/cors.d.ts.map +1 -1
  45. package/dist/middlewares/cors.js +6 -8
  46. package/dist/middlewares/cors.js.map +1 -1
  47. package/dist/middlewares/cors.mjs +6 -8
  48. package/dist/middlewares/cors.mjs.map +1 -1
  49. package/dist/middlewares/security.d.ts.map +1 -1
  50. package/dist/middlewares/security.js +10 -3
  51. package/dist/middlewares/security.js.map +1 -1
  52. package/dist/middlewares/security.mjs +11 -4
  53. package/dist/middlewares/security.mjs.map +1 -1
  54. package/dist/migrations/database/5.0.0-discard-drafts.d.ts +19 -1
  55. package/dist/migrations/database/5.0.0-discard-drafts.d.ts.map +1 -1
  56. package/dist/migrations/database/5.0.0-discard-drafts.js +1 -0
  57. package/dist/migrations/database/5.0.0-discard-drafts.js.map +1 -1
  58. package/dist/migrations/database/5.0.0-discard-drafts.mjs +2 -1
  59. package/dist/migrations/database/5.0.0-discard-drafts.mjs.map +1 -1
  60. package/dist/migrations/draft-publish.d.ts.map +1 -1
  61. package/dist/migrations/draft-publish.js +14 -31
  62. package/dist/migrations/draft-publish.js.map +1 -1
  63. package/dist/migrations/draft-publish.mjs +15 -32
  64. package/dist/migrations/draft-publish.mjs.map +1 -1
  65. package/dist/services/document-service/entries.d.ts +1 -1
  66. package/dist/services/document-service/entries.d.ts.map +1 -1
  67. package/dist/services/document-service/entries.js +2 -1
  68. package/dist/services/document-service/entries.js.map +1 -1
  69. package/dist/services/document-service/entries.mjs +2 -1
  70. package/dist/services/document-service/entries.mjs.map +1 -1
  71. package/dist/services/document-service/events.d.ts +25 -0
  72. package/dist/services/document-service/events.d.ts.map +1 -0
  73. package/dist/services/document-service/events.js +47 -0
  74. package/dist/services/document-service/events.js.map +1 -0
  75. package/dist/services/document-service/events.mjs +47 -0
  76. package/dist/services/document-service/events.mjs.map +1 -0
  77. package/dist/services/document-service/index.d.ts.map +1 -1
  78. package/dist/services/document-service/index.js.map +1 -1
  79. package/dist/services/document-service/index.mjs.map +1 -1
  80. package/dist/services/document-service/internationalization.d.ts.map +1 -1
  81. package/dist/services/document-service/internationalization.js +14 -5
  82. package/dist/services/document-service/internationalization.js.map +1 -1
  83. package/dist/services/document-service/internationalization.mjs +14 -5
  84. package/dist/services/document-service/internationalization.mjs.map +1 -1
  85. package/dist/services/document-service/repository.d.ts.map +1 -1
  86. package/dist/services/document-service/repository.js +73 -45
  87. package/dist/services/document-service/repository.js.map +1 -1
  88. package/dist/services/document-service/repository.mjs +75 -47
  89. package/dist/services/document-service/repository.mjs.map +1 -1
  90. package/dist/services/document-service/transform/relations/extract/data-ids.d.ts.map +1 -1
  91. package/dist/services/document-service/transform/relations/extract/data-ids.js +3 -0
  92. package/dist/services/document-service/transform/relations/extract/data-ids.js.map +1 -1
  93. package/dist/services/document-service/transform/relations/extract/data-ids.mjs +3 -0
  94. package/dist/services/document-service/transform/relations/extract/data-ids.mjs.map +1 -1
  95. package/dist/services/document-service/transform/relations/transform/data-ids.d.ts.map +1 -1
  96. package/dist/services/document-service/transform/relations/transform/data-ids.js +3 -0
  97. package/dist/services/document-service/transform/relations/transform/data-ids.js.map +1 -1
  98. package/dist/services/document-service/transform/relations/transform/data-ids.mjs +3 -0
  99. package/dist/services/document-service/transform/relations/transform/data-ids.mjs.map +1 -1
  100. package/dist/services/document-service/transform/relations/utils/map-relation.d.ts.map +1 -1
  101. package/dist/services/document-service/transform/relations/utils/map-relation.js +7 -3
  102. package/dist/services/document-service/transform/relations/utils/map-relation.js.map +1 -1
  103. package/dist/services/document-service/transform/relations/utils/map-relation.mjs +7 -3
  104. package/dist/services/document-service/transform/relations/utils/map-relation.mjs.map +1 -1
  105. package/dist/services/entity-validator/index.d.ts +14 -1
  106. package/dist/services/entity-validator/index.d.ts.map +1 -1
  107. package/dist/services/entity-validator/index.js +82 -20
  108. package/dist/services/entity-validator/index.js.map +1 -1
  109. package/dist/services/entity-validator/index.mjs +82 -20
  110. package/dist/services/entity-validator/index.mjs.map +1 -1
  111. package/dist/services/entity-validator/validators.d.ts +10 -8
  112. package/dist/services/entity-validator/validators.d.ts.map +1 -1
  113. package/dist/services/entity-validator/validators.js +60 -19
  114. package/dist/services/entity-validator/validators.js.map +1 -1
  115. package/dist/services/entity-validator/validators.mjs +53 -11
  116. package/dist/services/entity-validator/validators.mjs.map +1 -1
  117. package/dist/services/event-hub.d.ts +1 -0
  118. package/dist/services/event-hub.d.ts.map +1 -1
  119. package/dist/services/event-hub.js +9 -4
  120. package/dist/services/event-hub.js.map +1 -1
  121. package/dist/services/event-hub.mjs +9 -4
  122. package/dist/services/event-hub.mjs.map +1 -1
  123. package/dist/services/server/index.js +1 -1
  124. package/dist/services/server/index.js.map +1 -1
  125. package/dist/services/server/index.mjs +1 -1
  126. package/dist/services/server/index.mjs.map +1 -1
  127. package/dist/services/server/koa.d.ts.map +1 -1
  128. package/dist/services/server/koa.js +1 -1
  129. package/dist/services/server/koa.js.map +1 -1
  130. package/dist/services/server/koa.mjs +1 -1
  131. package/dist/services/server/koa.mjs.map +1 -1
  132. package/dist/services/webhook-runner.d.ts +2 -1
  133. package/dist/services/webhook-runner.d.ts.map +1 -1
  134. package/dist/services/webhook-runner.js.map +1 -1
  135. package/dist/services/webhook-runner.mjs.map +1 -1
  136. package/dist/services/webhook-store.d.ts +2 -8
  137. package/dist/services/webhook-store.d.ts.map +1 -1
  138. package/dist/services/webhook-store.js +9 -2
  139. package/dist/services/webhook-store.js.map +1 -1
  140. package/dist/services/webhook-store.mjs +9 -2
  141. package/dist/services/webhook-store.mjs.map +1 -1
  142. package/dist/utils/fetch.d.ts.map +1 -1
  143. package/dist/utils/fetch.js +4 -3
  144. package/dist/utils/fetch.js.map +1 -1
  145. package/dist/utils/fetch.mjs +4 -3
  146. package/dist/utils/fetch.mjs.map +1 -1
  147. package/dist/utils/transform-content-types-to-models.d.ts.map +1 -1
  148. package/dist/utils/transform-content-types-to-models.js +10 -0
  149. package/dist/utils/transform-content-types-to-models.js.map +1 -1
  150. package/dist/utils/transform-content-types-to-models.mjs +10 -0
  151. package/dist/utils/transform-content-types-to-models.mjs.map +1 -1
  152. package/package.json +22 -18
@@ -1 +1 @@
1
- {"version":3,"file":"repository.mjs","sources":["../../../src/services/document-service/repository.ts"],"sourcesContent":["import { omit, assoc, merge } 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';\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 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.localeToLookup(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 await async.map(entriesToDelete, (entryToDelete: any) => entries.delete(entryToDelete.id));\n\n return { deletedEntries: entriesToDelete };\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 if (hasDraftAndPublish && params.status === 'published') {\n return publish({\n ...params,\n documentId: doc.documentId,\n }).then((doc) => doc.versions[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 return { documentId: clonedEntries.at(0)?.documentId, versions: 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 }\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 }\n }\n\n if (hasDraftAndPublish && updatedDraft && params.status === 'published') {\n return publish({\n ...params,\n documentId,\n }).then((doc) => doc.versions[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 await deleteDocument({\n ...queryParams,\n documentId,\n lookup: { ...queryParams?.lookup, publishedAt: { $ne: null } },\n });\n\n // Get deep populate\n const draftsToPublish = await strapi.db?.query(uid).findMany({\n where: {\n ...queryParams?.lookup,\n documentId,\n publishedAt: null,\n },\n populate: getDeepPopulate(uid, { relationalFields: ['documentId', 'locale'] }),\n });\n\n // Transform draft entry data and create published versions\n const versions = await async.map(draftsToPublish, (draft: unknown) =>\n entries.publish(draft, queryParams)\n );\n\n return { versions };\n }\n\n async function unpublish(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 { deletedEntries } = await deleteDocument({\n ...params,\n documentId,\n lookup: { ...queryParams?.lookup, publishedAt: { $ne: null } },\n });\n\n return { versions: deletedEntries };\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 // Delete all drafts that match query\n await deleteDocument({\n ...queryParams,\n documentId,\n lookup: { ...queryParams?.lookup, publishedAt: null },\n });\n\n // Get deep populate of published versions\n const entriesToDraft = await strapi.db?.query(uid).findMany({\n where: {\n ...queryParams?.lookup,\n documentId,\n publishedAt: { $ne: null },\n },\n populate: getDeepPopulate(uid, { relationalFields: ['documentId', 'locale'] }),\n });\n\n // Transform published entry data and create draft versions\n const draftEntries = await async.map(entriesToDraft, (entry: any) =>\n entries.discardDraft(entry, queryParams)\n );\n\n return { versions: 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","DP.defaultToDraft","DP.statusToLookup","i18n.defaultLocale","i18n.localeToLookup","transformParamsDocumentId","query","i18n.multiLocaleToLookup","DP.filterDataPublishedAt","DP.setStatusToDraft","DP.statusToData","i18n.localeToData","doc","DP.defaultStatus","updateComponents","components.updateComponents","omitComponentData","components.omitComponentData"],"mappings":";;;;;;;;;;;;AAgBa,MAAA,8BAAuD,CAAC,QAAQ;AACrE,QAAA,cAAc,OAAO,YAAY,GAAG;AACpC,QAAA,qBAAqBA,aAAkB,mBAAmB,WAAW;AAErE,QAAA,UAAU,qBAAqB,GAAG;AAEzB,iBAAA,SAAS,SAAS,IAAW;AACpC,UAAA,QAAQ,MAAM,MAAM;AAAA,MACxBC;AAAAA,MACAC,oBAAkB,WAAW;AAAA,MAC7BC,mBAAmB,WAAW;AAAA,MAC9BC,oBAAoB,WAAW;AAAA,MAC/BC,iCAA0B,GAAG;AAAA,MAC7B,uBAAuB,GAAG;AAAA,IAAA,EAC1B,UAAU,CAAA,CAAE;AAEd,WAAO,OAAO,GAAG,MAAM,GAAG,EAAE,SAAS,KAAK;AAAA,EAC5C;AAEe,iBAAA,UAAU,SAAS,IAAW;AACrC,UAAA,QAAQ,MAAM,MAAM;AAAA,MACxBJ;AAAAA,MACAC,oBAAkB,WAAW;AAAA,MAC7BC,mBAAmB,WAAW;AAAA,MAC9BC,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AAkB,OAAO,IAAK;AAAA,IAC5D,WAAW,qBAAqB,kBAAkB,SAAS,IAAK;AAAA,IAChE,cAAc,qBAAqB,kBAAkB,YAAY,IAAK;AAAA,IAAA,kBAEtEH;AAAAA,IAAA,mBACAE;AAAAA,EAAA;AAEJ;"}
1
+ {"version":3,"file":"repository.mjs","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","DP.defaultToDraft","DP.statusToLookup","i18n.defaultLocale","i18n.multiLocaleToLookup","transformParamsDocumentId","i18n.localeToLookup","query","DP.filterDataPublishedAt","DP.setStatusToDraft","DP.statusToData","i18n.localeToData","doc","DP.defaultStatus","updateComponents","components.updateComponents","omitComponentData","components.omitComponentData"],"mappings":";;;;;;;;;;;;;AAiBa,MAAA,8BAAuD,CAAC,QAAQ;AACrE,QAAA,cAAc,OAAO,YAAY,GAAG;AACpC,QAAA,qBAAqBA,aAAkB,mBAAmB,WAAW;AAErE,QAAA,UAAU,qBAAqB,GAAG;AAElC,QAAA,eAAe,mBAAmB,QAAQ,GAAG;AAC7C,QAAA,YAAY,MAAM,aAAa,SAAS;AAE/B,iBAAA,SAAS,SAAS,IAAW;AACpC,UAAA,QAAQ,MAAM,MAAM;AAAA,MACxBC;AAAAA,MACAC,oBA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K;AAAA,IAC9B,SAAS,qBAAqB,kBAAkB,OAAO,IAAK;AAAA,IAC5D,WAAW,qBAAqB,kBAAkB,SAAS,IAAK;AAAA,IAChE,cAAc,qBAAqB,kBAAkB,YAAY,IAAK;AAAA,IAAA,kBAEtEH;AAAAA,IAAA,mBACAE;AAAAA,EAAA;AAEJ;"}
@@ -1 +1 @@
1
- {"version":3,"file":"data-ids.d.ts","sourceRoot":"","sources":["../../../../../../src/services/document-service/transform/relations/extract/data-ids.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAMrC,UAAU,OAAO;IACf,GAAG,EAAE,GAAG,CAAC,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,MAAM,CAAC,EAAE,OAAO,GAAG,WAAW,CAAC;CAChC;AA8BD;;;GAGG;AACH,QAAA,MAAM,cAAc,UAAW,KAAK,QAAQ,OAAO,MAAM,EAAE,GAAG,CAAC,UAAU,OAAO,qDA8B/E,CAAC;AAEF,OAAO,EAAE,cAAc,EAAE,CAAC"}
1
+ {"version":3,"file":"data-ids.d.ts","sourceRoot":"","sources":["../../../../../../src/services/document-service/transform/relations/extract/data-ids.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAEpC,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAMrC,UAAU,OAAO;IACf,GAAG,EAAE,GAAG,CAAC,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,MAAM,CAAC,EAAE,OAAO,GAAG,WAAW,CAAC;CAChC;AA8BD;;;GAGG;AACH,QAAA,MAAM,cAAc,UAAW,KAAK,QAAQ,OAAO,MAAM,EAAE,GAAG,CAAC,UAAU,OAAO,qDAkC/E,CAAC;AAEF,OAAO,EAAE,cAAc,EAAE,CAAC"}
@@ -29,6 +29,9 @@ const addRelationDocId = _.curry(
29
29
  const extractDataIds = (idMap, data, source) => {
30
30
  return mapRelation.traverseEntityRelations(
31
31
  async ({ attribute, value }) => {
32
+ if (!attribute) {
33
+ return;
34
+ }
32
35
  const targetUid = attribute.target;
33
36
  const addDocId = addRelationDocId(idMap, targetUid, source);
34
37
  return mapRelation.mapRelation((relation) => {
@@ -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 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,EAAA;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,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
+ {"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,EAAA;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;;"}
@@ -27,6 +27,9 @@ const addRelationDocId = curry(
27
27
  const extractDataIds = (idMap, data, source) => {
28
28
  return traverseEntityRelationsCurried(
29
29
  async ({ attribute, value }) => {
30
+ if (!attribute) {
31
+ return;
32
+ }
30
33
  const targetUid = attribute.target;
31
34
  const addDocId = addRelationDocId(idMap, targetUid, source);
32
35
  return mapRelationCurried((relation) => {
@@ -1 +1 @@
1
- {"version":3,"file":"data-ids.mjs","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 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":["traverseEntityRelations","mapRelation"],"mappings":";;;;AAmBA,MAAM,mBAAmB;AAAA,EACvB,CAAC,OAAc,WAAuB,QAAiB,aAA+B;AAC9E,UAAA,eAAe,wBAAwB,UAAU;AAAA,MACrD;AAAA,MACA,WAAW,OAAO;AAAA,MAClB,cAAc,OAAO;AAAA,IAAA,CACtB;AAEK,UAAA,eAAe,wBAAwB,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,SAAAA;AAAAA,IACL,OAAO,EAAE,WAAW,YAAY;AAC9B,YAAM,YAAY,UAAU;AAC5B,YAAM,WAAW,iBAAiB,OAAO,WAAW,MAAM;AAEnD,aAAAC,mBAAY,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
+ {"version":3,"file":"data-ids.mjs","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":["traverseEntityRelations","mapRelation"],"mappings":";;;;AAmBA,MAAM,mBAAmB;AAAA,EACvB,CAAC,OAAc,WAAuB,QAAiB,aAA+B;AAC9E,UAAA,eAAe,wBAAwB,UAAU;AAAA,MACrD;AAAA,MACA,WAAW,OAAO;AAAA,MAClB,cAAc,OAAO;AAAA,IAAA,CACtB;AAEK,UAAA,eAAe,wBAAwB,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,SAAAA;AAAAA,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,mBAAY,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 +1 @@
1
- {"version":3,"file":"data-ids.d.ts","sourceRoot":"","sources":["../../../../../../src/services/document-service/transform/relations/transform/data-ids.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAIzC,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAKrC,UAAU,OAAO;IACf,GAAG,EAAE,GAAG,CAAC,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,MAAM,CAAC,EAAE,OAAO,GAAG,WAAW,CAAC;IAC/B,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AA+CD;;GAEG;AACH,QAAA,MAAM,uBAAuB,UAAW,KAAK,QAAQ,OAAO,MAAM,EAAE,GAAG,CAAC,UAAU,OAAO,qDA4CxF,CAAC;AAEF,OAAO,EAAE,uBAAuB,EAAE,CAAC"}
1
+ {"version":3,"file":"data-ids.d.ts","sourceRoot":"","sources":["../../../../../../src/services/document-service/transform/relations/transform/data-ids.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAIzC,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAKrC,UAAU,OAAO;IACf,GAAG,EAAE,GAAG,CAAC,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,MAAM,CAAC,EAAE,OAAO,GAAG,WAAW,CAAC;IAC/B,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AA+CD;;GAEG;AACH,QAAA,MAAM,uBAAuB,UAAW,KAAK,QAAQ,OAAO,MAAM,EAAE,GAAG,CAAC,UAAU,OAAO,qDAgDxF,CAAC;AAEF,OAAO,EAAE,uBAAuB,EAAE,CAAC"}
@@ -39,6 +39,9 @@ const getRelationIds = _.curry(
39
39
  const transformDataIdsVisitor = (idMap, data, source) => {
40
40
  return mapRelation.traverseEntityRelations(
41
41
  async ({ key, value, attribute }, { set }) => {
42
+ if (!attribute) {
43
+ return;
44
+ }
42
45
  const targetUid = attribute.target;
43
46
  const getIds = getRelationIds(idMap, targetUid, source);
44
47
  const newRelation = await mapRelation.mapRelation((relation) => {
@@ -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 // 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,EAAA;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;AA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AAI,KAAK,WAAkB;AAAA,IAC7B;AAAA,IACA,EAAE,QAAQ,OAAO,SAAS,OAAO,GAAG,GAAG,UAAU,OAAO,SAAS,KAAK,MAAM,EAAE;AAAA,IAC9E;AAAA,EAAA;AAEJ;;"}
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,EAAA;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,UAAA;AAAS,YAAI,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;AAAA,EAAA;AAEJ;;"}
@@ -37,6 +37,9 @@ const getRelationIds = curry(
37
37
  const transformDataIdsVisitor = (idMap, data, source) => {
38
38
  return traverseEntityRelationsCurried(
39
39
  async ({ key, value, attribute }, { set }) => {
40
+ if (!attribute) {
41
+ return;
42
+ }
40
43
  const targetUid = attribute.target;
41
44
  const getIds = getRelationIds(idMap, targetUid, source);
42
45
  const newRelation = await mapRelationCurried((relation) => {
@@ -1 +1 @@
1
- {"version":3,"file":"data-ids.mjs","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 // 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":["traverseEntityRelations","mapRelation","newRelation"],"mappings":";;;;;AAqBA,MAAM,iBAAiB;AAAA,EACrB,CAAC,OAAc,WAAuB,QAAiB,aAA+B;AAE9E,UAAA,eAAe,wBAAwB,UAAU;AAAA,MACrD;AAAA,MACA,WAAW,OAAO;AAAA,MAClB,cAAc,OAAO;AAAA,IAAA,CACtB;AAGK,UAAA,eAAe,wBAAwB,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;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,IAC9E;AAAA,EAAA;AAEJ;"}
1
+ {"version":3,"file":"data-ids.mjs","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":["traverseEntityRelations","mapRelation","newRelation"],"mappings":";;;;;AAqBA,MAAM,iBAAiB;AAAA,EACrB,CAAC,OAAc,WAAuB,QAAiB,aAA+B;AAE9E,UAAA,eAAe,wBAAwB,UAAU;AAAA,MACrD;AAAA,MACA,WAAW,OAAO;AAAA,MAClB,cAAc,OAAO;AAAA,IAAA,CACtB;AAGK,UAAA,eAAe,wBAAwB,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,UAAA;AAAS,YAAI,KAAK,OAAO;AAAA,IAC/B;AAEA,QAAI,CAAC,IAAI,UAAU,CAAC,OAAO,gBAAgB;AACzC,YAAM,IAAI,OAAO;AAAA,QACf,qBAAqB,SAAS,UAAU,cAAc,YAAY;AAAA,MAAA;AAAA,IAEtE;AAEO,WAAA;AAAA,EACT;AACF;AAKA,MAAM,0BAA0B,CAAC,OAAc,MAA2B,WAAoB;AACrF,SAAAA;AAAAA,IACL,OAAO,EAAE,KAAK,OAAO,aAAa,EAAE,UAAU;AAC5C,UAAI,CAAC,WAAW;AACd;AAAA,MACF;AAGA,YAAM,YAAY,UAAU;AAC5B,YAAM,SAAS,eAAe,OAAO,WAAW,MAAM;AAGtD,YAAM,cAAc,MAAMC,mBAAY,CAAC,aAAa;AAClD,YAAI,CAAC,YAAY,CAAC,SAAS,YAAY;AAC9B,iBAAA;AAAA,QACT;AAEM,cAAA,MAAM,OAAO,QAAQ;AAG3B,cAAM,WAAW,EAAE,GAAG,SAAS,SAAS;AAExC,YAAI,SAAS,QAAQ;AACb,gBAAA,iBAAiB,EAAE,GAAG,UAAU,GAAG,UAAU,YAAY,SAAS;AACxE,mBAAS,SAAS,OAAO,cAAc,EAAE,GAAG,CAAC;AAAA,QAC/C;AAEA,YAAI,SAAS,OAAO;AACZ,gBAAA,gBAAgB,EAAE,GAAG,UAAU,GAAG,UAAU,YAAY,SAAS;AACvE,mBAAS,QAAQ,OAAO,aAAa,EAAE,GAAG,CAAC;AAAA,QAC7C;AAGO,eAAA,KAAK,IAAI,CAAC,OAAO;AAChBC,gBAAAA,eAAc,EAAE;AACtB,cAAI,SAAS,UAAU;AACrBA,yBAAY,WAAW;AAAA,UACzB;AAEOA,iBAAAA;AAAAA,QAAA,CACR;AAAA,SACA,KAAY;AAEf,UAAI,KAAK,WAAkB;AAAA,IAC7B;AAAA,IACA,EAAE,QAAQ,OAAO,SAAS,OAAO,GAAG,GAAG,UAAU,OAAO,SAAS,KAAK,MAAM,EAAE;AAAA,IAC9E;AAAA,EAAA;AAEJ;"}
@@ -1 +1 @@
1
- {"version":3,"file":"map-relation.d.ts","sourceRoot":"","sources":["../../../../../../src/services/document-service/transform/relations/utils/map-relation.ts"],"names":[],"mappings":";AAMA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAgJnC,QAAA,MAAM,kBAAkB,+CA/GD,GAAG,KAAK,GAAG,8BA+GW,CAAC;AAC9C,QAAA,MAAM,8BAA8B,kPAAiC,CAAC;AAEtE,OAAO,EACL,kBAAkB,IAAI,WAAW,EACjC,8BAA8B,IAAI,uBAAuB,GAC1D,CAAC"}
1
+ {"version":3,"file":"map-relation.d.ts","sourceRoot":"","sources":["../../../../../../src/services/document-service/transform/relations/utils/map-relation.ts"],"names":[],"mappings":";AAMA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAsJnC,QAAA,MAAM,kBAAkB,+CArHD,GAAG,KAAK,GAAG,8BAqHW,CAAC;AAC9C,QAAA,MAAM,8BAA8B,kPAAiC,CAAC;AAEtE,OAAO,EACL,kBAAkB,IAAI,WAAW,EACjC,8BAA8B,IAAI,uBAAuB,GAC1D,CAAC"}
@@ -64,13 +64,17 @@ const mapRelation = async (callback, rel, isRecursive = false) => {
64
64
  const traverseEntityRelations = async (visitor, options, data) => {
65
65
  return strapiUtils.traverseEntity(
66
66
  async (options2, utils) => {
67
- if (options2.attribute.type !== "relation") {
67
+ const { attribute } = options2;
68
+ if (!attribute) {
68
69
  return;
69
70
  }
70
- if (options2.attribute.useJoinTable === false) {
71
+ if (attribute.type !== "relation") {
71
72
  return;
72
73
  }
73
- const target = options2.attribute.target;
74
+ if (attribute.useJoinTable === false) {
75
+ return;
76
+ }
77
+ const target = attribute.target;
74
78
  if (!target) {
75
79
  return;
76
80
  }
@@ -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 if (options.attribute.type !== 'relation') {\n return;\n }\n\n // TODO: Handle join columns\n if (options.attribute.useJoinTable === false) {\n return;\n }\n\n // TODO: Handle morph relations (they have multiple targets)\n const target = options.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,EAAAA,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,EAAAA,MAAM,QAAQ,GAAG;AACnB,WAAO,SAAS,QAAQ;AAAA,EAC1B;AAGI,MAAA,MAAM,QAAQ,QAAQ,GAAG;AACpB,WAAAC,YAA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UAAU,SAAS,YAAY;AACzC;AAAA,MACF;AAGIA,UAAAA,SAAQ,UAAU,iBAAiB,OAAO;AAC5C;AAAA,MACF;AAGM,YAAA,SAASA,SAAQ,UAAU;AACjC,UAAI,CAAC,QAAQ;AACX;AAAA,MACF;AAEO,aAAA,QAAQA,UAAS,KAAK;AAAA,IAC/B;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEJ;AAEM,MAAA,qBAAqBC,QAAM,WAAW;AACtC,MAAA,iCAAiCA,QAAM,uBAAuB;;;"}
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","tra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ACvB,YAAM,aAAkB,MAAM,YAAY,UAAU,SAAS,YAAY,IAAI;AAC7E,iBAAW,EAAE,GAAG,UAAU,YAAY,QAAQ,UAAU;IAC1D;AAGA,QAAI,SAAS,SAAS;AAEpB,YAAM,UAAe,MAAM,YAAY,UAAU,SAAS,SAAS,IAAI;AACvE,iBAAW,EAAE,GAAG,UAAU,SAAS,QAAQ,OAAO;IACpD;AAEO,WAAA;AAAA,EACT;AAGI,MAAA,UAAU,QAAQ,GAAG;AACvB,UAAM,SAAS,MAAM,SAAS,EAAE,IAAI,SAAU,CAAA;AAC9C,WAAO,UAAU,MAAM;AAAA,EACzB;AAEI,MAAA,OAAO,aAAa,UAAU;AAChC,UAAM,SAAS,MAAM,SAAS,EAAE,YAAY,SAAU,CAAA;AACtD,WAAO,UAAU,MAAM;AAAA,EACzB;AAGA,SAAO,SAAS,QAAQ;AAC1B;AAOA,MAAM,0BAA0B,OAC9B,SACA,SACA,SACG;AACI,SAAAC,YAAA;AAAA,IACL,OAAOC,UAAS,UAAU;AAClB,YAAA,EAAE,UAAcA,IAAAA;AAEtB,UAAI,CAAC,WAAW;AACd;AAAA,MACF;AAEI,UAAA,UAAU,SAAS,YAAY;AACjC;AAAA,MACF;AAGI,UAAA,UAAU,iBAAiB,OAAO;AACpC;AAAA,MACF;AAGA,YAAM,SAAS,UAAU;AACzB,UAAI,CAAC,QAAQ;AACX;AAAA,MACF;AAEO,aAAA,QAAQA,UAAS,KAAK;AAAA,IAC/B;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEJ;AAEM,MAAA,qBAAqBC,QAAM,WAAW;AACtC,MAAA,iCAAiCA,QAAM,uBAAuB;;;"}
@@ -62,13 +62,17 @@ const mapRelation = async (callback, rel, isRecursive = false) => {
62
62
  const traverseEntityRelations = async (visitor, options, data) => {
63
63
  return traverseEntity(
64
64
  async (options2, utils) => {
65
- if (options2.attribute.type !== "relation") {
65
+ const { attribute } = options2;
66
+ if (!attribute) {
66
67
  return;
67
68
  }
68
- if (options2.attribute.useJoinTable === false) {
69
+ if (attribute.type !== "relation") {
69
70
  return;
70
71
  }
71
- const target = options2.attribute.target;
72
+ if (attribute.useJoinTable === false) {
73
+ return;
74
+ }
75
+ const target = attribute.target;
72
76
  if (!target) {
73
77
  return;
74
78
  }
@@ -1 +1 @@
1
- {"version":3,"file":"map-relation.mjs","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 if (options.attribute.type !== 'relation') {\n return;\n }\n\n // TODO: Handle join columns\n if (options.attribute.useJoinTable === false) {\n return;\n }\n\n // TODO: Handle morph relations (they have multiple targets)\n const target = options.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":["options"],"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,MAA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AAS,QAAQ,OAAO;IACpD;AAEO,WAAA;AAAA,EACT;AAGI,MAAA,UAAU,QAAQ,GAAG;AACvB,UAAM,SAAS,MAAM,SAAS,EAAE,IAAI,SAAU,CAAA;AAC9C,WAAO,UAAU,MAAM;AAAA,EACzB;AAEI,MAAA,OAAO,aAAa,UAAU;AAChC,UAAM,SAAS,MAAM,SAAS,EAAE,YAAY,SAAU,CAAA;AACtD,WAAO,UAAU,MAAM;AAAA,EACzB;AAGA,SAAO,SAAS,QAAQ;AAC1B;AAOA,MAAM,0BAA0B,OAC9B,SACA,SACA,SACG;AACI,SAAA;AAAA,IACL,OAAOA,UAAS,UAAU;AACpBA,UAAAA,SAAQ,UAAU,SAAS,YAAY;AACzC;AAAA,MACF;AAGIA,UAAAA,SAAQ,UAAU,iBAAiB,OAAO;AAC5C;AAAA,MACF;AAGM,YAAA,SAASA,SAAQ,UAAU;AACjC,UAAI,CAAC,QAAQ;AACX;AAAA,MACF;AAEO,aAAA,QAAQA,UAAS,KAAK;AAAA,IAC/B;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEJ;AAEM,MAAA,qBAAqB,MAAM,WAAW;AACtC,MAAA,iCAAiC,MAAM,uBAAuB;"}
1
+ {"version":3,"file":"map-relation.mjs","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":["options"],"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,MAAI,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,MAAA,MAAM,QAAQ,GAAG;AACnB,WAAO,SAAS,QAAQ;AAAA,EAC1B;AAGI,MAAA,MAAM,QAAQ,QAAQ,GAAG;AACpB,WAAA,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,MAAA,SAAS,QAAQ,GAAG;AAElB,QAAA,QAAQ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AEO,aAAA,QAAQA,UAAS,KAAK;AAAA,IAC/B;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEJ;AAEM,MAAA,qBAAqB,MAAM,WAAW;AACtC,MAAA,iCAAiC,MAAM,uBAAuB;"}
@@ -2,7 +2,20 @@
2
2
  * Entity validator
3
3
  * Module that will validate input data for entity creation or edition
4
4
  */
5
- import { Modules } from '@strapi/types';
5
+ import { Modules, Struct } from '@strapi/types';
6
+ export type ComponentContext = {
7
+ parentContent: {
8
+ model: Struct.Schema;
9
+ id?: number;
10
+ options?: ValidatorContext;
11
+ };
12
+ pathToComponent: string[];
13
+ repeatableData: Modules.EntityValidator.Entity[];
14
+ };
15
+ interface ValidatorContext {
16
+ isDraft?: boolean;
17
+ locale?: string | null;
18
+ }
6
19
  declare const entityValidator: Modules.EntityValidator.EntityValidator;
7
20
  export default entityValidator;
8
21
  //# sourceMappingURL=index.d.ts.map
@@ -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,EAAuB,MAAM,eAAe,CAAC;AAmf7D,QAAA,MAAM,eAAe,EAAE,OAAO,CAAC,eAAe,CAAC,eAG9C,CAAC;AAEF,eAAe,eAAe,CAAC"}
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,EAAU,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;CAClD,CAAC;AAWF,UAAU,gBAAgB;IACxB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB;AAyiBD,QAAA,MAAM,eAAe,EAAE,OAAO,CAAC,eAAe,CAAC,eAG9C,CAAC;AAEF,eAAe,eAAe,CAAC"}
@@ -55,7 +55,11 @@ const addDefault = (createOrUpdate) => {
55
55
  };
56
56
  };
57
57
  const preventCast = (validator) => validator.transform((val, originalVal) => originalVal);
58
- const createComponentValidator = (createOrUpdate) => ({ attr, updatedAttribute }, { isDraft }) => {
58
+ const createComponentValidator = (createOrUpdate) => ({
59
+ attr,
60
+ updatedAttribute,
61
+ componentContext
62
+ }, { isDraft }) => {
59
63
  const model = strapi.getModel(attr.component);
60
64
  if (!model) {
61
65
  throw new Error("Validation failed: Model not found");
@@ -63,7 +67,10 @@ const createComponentValidator = (createOrUpdate) => ({ attr, updatedAttribute }
63
67
  if (attr?.repeatable) {
64
68
  let validator2 = yup.array().of(
65
69
  yup.lazy(
66
- (item) => createModelValidator(createOrUpdate)({ model, data: item }, { isDraft }).notNull()
70
+ (item) => createModelValidator(createOrUpdate)(
71
+ { componentContext, model, data: item },
72
+ { isDraft }
73
+ ).notNull()
67
74
  )
68
75
  );
69
76
  validator2 = addRequiredValidation(createOrUpdate)(validator2, {
@@ -74,7 +81,11 @@ const createComponentValidator = (createOrUpdate) => ({ attr, updatedAttribute }
74
81
  return validator2;
75
82
  }
76
83
  let validator = createModelValidator(createOrUpdate)(
77
- { model, data: updatedAttribute.value },
84
+ {
85
+ model,
86
+ data: updatedAttribute.value,
87
+ componentContext
88
+ },
78
89
  { isDraft }
79
90
  );
80
91
  validator = addRequiredValidation(createOrUpdate)(validator, {
@@ -83,7 +94,7 @@ const createComponentValidator = (createOrUpdate) => ({ attr, updatedAttribute }
83
94
  });
84
95
  return validator;
85
96
  };
86
- const createDzValidator = (createOrUpdate) => ({ attr, updatedAttribute }, { isDraft }) => {
97
+ const createDzValidator = (createOrUpdate) => ({ attr, updatedAttribute, componentContext }, { isDraft }) => {
87
98
  let validator;
88
99
  validator = yup.array().of(
89
100
  yup.lazy((item) => {
@@ -91,7 +102,12 @@ const createDzValidator = (createOrUpdate) => ({ attr, updatedAttribute }, { isD
91
102
  const schema = yup.object().shape({
92
103
  __component: yup.string().required().oneOf(Object.keys(strapi.components))
93
104
  }).notNull();
94
- return model ? schema.concat(createModelValidator(createOrUpdate)({ model, data: item }, { isDraft })) : schema;
105
+ return model ? schema.concat(
106
+ createModelValidator(createOrUpdate)(
107
+ { model, data: item, componentContext },
108
+ { isDraft }
109
+ )
110
+ ) : schema;
95
111
  })
96
112
  // FIXME: yup v1
97
113
  );
@@ -136,12 +152,37 @@ const createAttributeValidator = (createOrUpdate) => (metas, options) => {
136
152
  validator = createScalarAttributeValidator(createOrUpdate)(metas, options);
137
153
  } else {
138
154
  if (metas.attr.type === "component") {
155
+ const pathToComponent = [
156
+ ...metas?.componentContext?.pathToComponent ?? [],
157
+ metas.updatedAttribute.name
158
+ ];
159
+ const repeatableData = metas.attr.repeatable && pathToComponent.length === 1 ? metas.updatedAttribute.value : metas.componentContext?.repeatableData;
160
+ const newComponentContext = {
161
+ ...metas?.componentContext ?? {},
162
+ pathToComponent,
163
+ repeatableData
164
+ };
139
165
  validator = createComponentValidator(createOrUpdate)(
140
- { attr: metas.attr, updatedAttribute: metas.updatedAttribute },
166
+ {
167
+ componentContext: newComponentContext,
168
+ attr: metas.attr,
169
+ updatedAttribute: metas.updatedAttribute
170
+ },
141
171
  options
142
172
  );
143
173
  } else if (metas.attr.type === "dynamiczone") {
144
- validator = createDzValidator(createOrUpdate)(metas, options);
174
+ const pathToComponent = [
175
+ ...metas?.componentContext?.pathToComponent ?? [],
176
+ metas.updatedAttribute.name
177
+ ];
178
+ const newComponentContext = {
179
+ ...metas?.componentContext ?? {},
180
+ pathToComponent
181
+ };
182
+ validator = createDzValidator(createOrUpdate)(
183
+ { ...metas, componentContext: newComponentContext },
184
+ options
185
+ );
145
186
  } else if (metas.attr.type === "relation") {
146
187
  validator = createRelationValidator(createOrUpdate)(
147
188
  {
@@ -156,7 +197,7 @@ const createAttributeValidator = (createOrUpdate) => (metas, options) => {
156
197
  validator = addDefault(createOrUpdate)(validator, metas);
157
198
  return validator;
158
199
  };
159
- const createModelValidator = (createOrUpdate) => ({ model, data, entity }, options) => {
200
+ const createModelValidator = (createOrUpdate) => ({ componentContext, model, data, entity }, options) => {
160
201
  const writableAttributes = model ? getWritableAttributes(model) : [];
161
202
  const schema = writableAttributes.reduce(
162
203
  (validators2, attributeName) => {
@@ -164,7 +205,8 @@ const createModelValidator = (createOrUpdate) => ({ model, data, entity }, optio
164
205
  attr: model.attributes[attributeName],
165
206
  updatedAttribute: { name: attributeName, value: _.prop(attributeName, data) },
166
207
  model,
167
- entity
208
+ entity,
209
+ componentContext
168
210
  };
169
211
  const validator = createAttributeValidator(createOrUpdate)(metas, options);
170
212
  validators2[attributeName] = validator;
@@ -183,22 +225,42 @@ const createValidateEntity = (createOrUpdate) => {
183
225
  );
184
226
  }
185
227
  const validator = createModelValidator(createOrUpdate)(
186
- { model, data, entity },
228
+ {
229
+ model,
230
+ data,
231
+ entity,
232
+ componentContext: {
233
+ // Set up the initial component context.
234
+ // Keeping track of parent content type context in which a component will be used.
235
+ // This is necessary to validate component field constraints such as uniqueness.
236
+ parentContent: {
237
+ id: entity?.id,
238
+ model,
239
+ options
240
+ },
241
+ pathToComponent: [],
242
+ repeatableData: []
243
+ }
244
+ },
187
245
  {
188
246
  isDraft: options?.isDraft ?? false,
189
247
  locale: options?.locale ?? null
190
248
  }
191
- ).test("relations-test", "check that all relations exist", async function(data2) {
192
- try {
193
- await checkRelationsExist(buildRelationsStore({ uid: model.uid, data: data2 }));
194
- } catch (e) {
195
- return this.createError({
196
- path: this.path,
197
- message: e instanceof ValidationError && e.message || "Invalid relations"
198
- });
249
+ ).test(
250
+ "relations-test",
251
+ "check that all relations exist",
252
+ async function relationsValidation(data2) {
253
+ try {
254
+ await checkRelationsExist(buildRelationsStore({ uid: model.uid, data: data2 }));
255
+ } catch (e) {
256
+ return this.createError({
257
+ path: this.path,
258
+ message: e instanceof ValidationError && e.message || "Invalid relations"
259
+ });
260
+ }
261
+ return true;
199
262
  }
200
- return true;
201
- }).required();
263
+ ).required();
202
264
  return validateYupSchema(validator, {
203
265
  strict: false,
204
266
  abortEarly: false