@strapi/core 0.0.0-experimental.f31889311d753b5f7d95198ae84d8fce1d156cd6 → 0.0.0-experimental.f49f46a1c17445a39e8af3f63124bcccf73842e6

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.
Files changed (156) hide show
  1. package/dist/Strapi.d.ts.map +1 -1
  2. package/dist/Strapi.js +10 -6
  3. package/dist/Strapi.js.map +1 -1
  4. package/dist/Strapi.mjs +9 -6
  5. package/dist/Strapi.mjs.map +1 -1
  6. package/dist/core-api/service/collection-type.d.ts +2 -2
  7. package/dist/ee/index.d.ts.map +1 -1
  8. package/dist/ee/index.js +6 -1
  9. package/dist/ee/index.js.map +1 -1
  10. package/dist/ee/index.mjs +6 -1
  11. package/dist/ee/index.mjs.map +1 -1
  12. package/dist/factories.js.map +1 -1
  13. package/dist/factories.mjs.map +1 -1
  14. package/dist/loaders/plugins/get-enabled-plugins.d.ts.map +1 -1
  15. package/dist/loaders/plugins/get-enabled-plugins.js +6 -3
  16. package/dist/loaders/plugins/get-enabled-plugins.js.map +1 -1
  17. package/dist/loaders/plugins/get-enabled-plugins.mjs +6 -3
  18. package/dist/loaders/plugins/get-enabled-plugins.mjs.map +1 -1
  19. package/dist/loaders/plugins/index.d.ts.map +1 -1
  20. package/dist/loaders/plugins/index.js +28 -1
  21. package/dist/loaders/plugins/index.js.map +1 -1
  22. package/dist/loaders/plugins/index.mjs +9 -1
  23. package/dist/loaders/plugins/index.mjs.map +1 -1
  24. package/dist/middlewares/query.js.map +1 -1
  25. package/dist/middlewares/query.mjs.map +1 -1
  26. package/dist/middlewares/security.d.ts.map +1 -1
  27. package/dist/middlewares/security.js +1 -1
  28. package/dist/middlewares/security.js.map +1 -1
  29. package/dist/middlewares/security.mjs +1 -1
  30. package/dist/middlewares/security.mjs.map +1 -1
  31. package/dist/migrations/database/5.0.0-discard-drafts.d.ts +12 -9
  32. package/dist/migrations/database/5.0.0-discard-drafts.d.ts.map +1 -1
  33. package/dist/migrations/database/5.0.0-discard-drafts.js +67 -11
  34. package/dist/migrations/database/5.0.0-discard-drafts.js.map +1 -1
  35. package/dist/migrations/database/5.0.0-discard-drafts.mjs +68 -12
  36. package/dist/migrations/database/5.0.0-discard-drafts.mjs.map +1 -1
  37. package/dist/migrations/draft-publish.d.ts +1 -1
  38. package/dist/migrations/draft-publish.d.ts.map +1 -1
  39. package/dist/migrations/draft-publish.js.map +1 -1
  40. package/dist/migrations/draft-publish.mjs.map +1 -1
  41. package/dist/migrations/i18n.d.ts +5 -0
  42. package/dist/migrations/i18n.d.ts.map +1 -0
  43. package/dist/migrations/i18n.js +54 -0
  44. package/dist/migrations/i18n.js.map +1 -0
  45. package/dist/migrations/i18n.mjs +54 -0
  46. package/dist/migrations/i18n.mjs.map +1 -0
  47. package/dist/migrations/index.d.ts +5 -0
  48. package/dist/migrations/index.d.ts.map +1 -0
  49. package/dist/migrations/index.js +15 -0
  50. package/dist/migrations/index.js.map +1 -0
  51. package/dist/migrations/index.mjs +15 -0
  52. package/dist/migrations/index.mjs.map +1 -0
  53. package/dist/providers/admin.d.ts.map +1 -1
  54. package/dist/providers/admin.js.map +1 -1
  55. package/dist/providers/admin.mjs.map +1 -1
  56. package/dist/providers/registries.js +3 -3
  57. package/dist/providers/registries.js.map +1 -1
  58. package/dist/providers/registries.mjs +3 -3
  59. package/dist/providers/registries.mjs.map +1 -1
  60. package/dist/registries/policies.d.ts +1 -1
  61. package/dist/registries/policies.d.ts.map +1 -1
  62. package/dist/registries/policies.js +1 -1
  63. package/dist/registries/policies.js.map +1 -1
  64. package/dist/registries/policies.mjs +1 -1
  65. package/dist/registries/policies.mjs.map +1 -1
  66. package/dist/services/content-api/index.d.ts +10 -12
  67. package/dist/services/content-api/index.d.ts.map +1 -1
  68. package/dist/services/content-api/permissions/index.d.ts +10 -12
  69. package/dist/services/content-api/permissions/index.d.ts.map +1 -1
  70. package/dist/services/content-api/permissions/providers/action.d.ts +5 -6
  71. package/dist/services/content-api/permissions/providers/action.d.ts.map +1 -1
  72. package/dist/services/content-api/permissions/providers/condition.d.ts +5 -6
  73. package/dist/services/content-api/permissions/providers/condition.d.ts.map +1 -1
  74. package/dist/services/cron.d.ts +3 -3
  75. package/dist/services/cron.d.ts.map +1 -1
  76. package/dist/services/cron.js +9 -4
  77. package/dist/services/cron.js.map +1 -1
  78. package/dist/services/cron.mjs +9 -4
  79. package/dist/services/cron.mjs.map +1 -1
  80. package/dist/services/document-service/common.d.ts +1 -1
  81. package/dist/services/document-service/common.d.ts.map +1 -1
  82. package/dist/services/document-service/common.js.map +1 -1
  83. package/dist/services/document-service/common.mjs.map +1 -1
  84. package/dist/services/document-service/entries.d.ts +2 -2
  85. package/dist/services/document-service/entries.d.ts.map +1 -1
  86. package/dist/services/document-service/entries.js +6 -7
  87. package/dist/services/document-service/entries.js.map +1 -1
  88. package/dist/services/document-service/entries.mjs +1 -2
  89. package/dist/services/document-service/entries.mjs.map +1 -1
  90. package/dist/services/document-service/index.d.ts +2 -1
  91. package/dist/services/document-service/index.d.ts.map +1 -1
  92. package/dist/services/document-service/index.js +3 -2
  93. package/dist/services/document-service/index.js.map +1 -1
  94. package/dist/services/document-service/index.mjs +3 -2
  95. package/dist/services/document-service/index.mjs.map +1 -1
  96. package/dist/services/document-service/repository.d.ts.map +1 -1
  97. package/dist/services/document-service/repository.js +60 -9
  98. package/dist/services/document-service/repository.js.map +1 -1
  99. package/dist/services/document-service/repository.mjs +61 -10
  100. package/dist/services/document-service/repository.mjs.map +1 -1
  101. package/dist/services/document-service/transform/id-map.d.ts.map +1 -1
  102. package/dist/services/document-service/transform/id-map.js +13 -4
  103. package/dist/services/document-service/transform/id-map.js.map +1 -1
  104. package/dist/services/document-service/transform/id-map.mjs +14 -5
  105. package/dist/services/document-service/transform/id-map.mjs.map +1 -1
  106. package/dist/services/document-service/transform/relations/extract/data-ids.d.ts.map +1 -1
  107. package/dist/services/document-service/transform/relations/extract/data-ids.js +13 -6
  108. package/dist/services/document-service/transform/relations/extract/data-ids.js.map +1 -1
  109. package/dist/services/document-service/transform/relations/extract/data-ids.mjs +13 -6
  110. package/dist/services/document-service/transform/relations/extract/data-ids.mjs.map +1 -1
  111. package/dist/services/document-service/transform/relations/transform/data-ids.d.ts.map +1 -1
  112. package/dist/services/document-service/transform/relations/transform/data-ids.js +16 -6
  113. package/dist/services/document-service/transform/relations/transform/data-ids.js.map +1 -1
  114. package/dist/services/document-service/transform/relations/transform/data-ids.mjs +17 -7
  115. package/dist/services/document-service/transform/relations/transform/data-ids.mjs.map +1 -1
  116. package/dist/services/document-service/transform/relations/utils/map-relation.d.ts.map +1 -1
  117. package/dist/services/document-service/transform/relations/utils/map-relation.js +0 -4
  118. package/dist/services/document-service/transform/relations/utils/map-relation.js.map +1 -1
  119. package/dist/services/document-service/transform/relations/utils/map-relation.mjs +0 -4
  120. package/dist/services/document-service/transform/relations/utils/map-relation.mjs.map +1 -1
  121. package/dist/services/document-service/utils/populate.d.ts.map +1 -1
  122. package/dist/services/document-service/utils/populate.js +4 -2
  123. package/dist/services/document-service/utils/populate.js.map +1 -1
  124. package/dist/services/document-service/utils/populate.mjs +4 -2
  125. package/dist/services/document-service/utils/populate.mjs.map +1 -1
  126. package/dist/services/document-service/utils/unidirectional-relations.d.ts +36 -0
  127. package/dist/services/document-service/utils/unidirectional-relations.d.ts.map +1 -0
  128. package/dist/services/document-service/utils/unidirectional-relations.js +69 -0
  129. package/dist/services/document-service/utils/unidirectional-relations.js.map +1 -0
  130. package/dist/services/document-service/utils/unidirectional-relations.mjs +69 -0
  131. package/dist/services/document-service/utils/unidirectional-relations.mjs.map +1 -0
  132. package/dist/services/entity-validator/blocks-validator.d.ts +1 -2
  133. package/dist/services/entity-validator/blocks-validator.d.ts.map +1 -1
  134. package/dist/services/entity-validator/blocks-validator.js +4 -3
  135. package/dist/services/entity-validator/blocks-validator.js.map +1 -1
  136. package/dist/services/entity-validator/blocks-validator.mjs +3 -3
  137. package/dist/services/entity-validator/blocks-validator.mjs.map +1 -1
  138. package/dist/services/entity-validator/index.d.ts +2 -1
  139. package/dist/services/entity-validator/index.d.ts.map +1 -1
  140. package/dist/services/entity-validator/index.js +16 -17
  141. package/dist/services/entity-validator/index.js.map +1 -1
  142. package/dist/services/entity-validator/index.mjs +20 -21
  143. package/dist/services/entity-validator/index.mjs.map +1 -1
  144. package/dist/services/entity-validator/validators.d.ts +32 -23
  145. package/dist/services/entity-validator/validators.d.ts.map +1 -1
  146. package/dist/services/entity-validator/validators.js +136 -63
  147. package/dist/services/entity-validator/validators.js.map +1 -1
  148. package/dist/services/entity-validator/validators.mjs +135 -63
  149. package/dist/services/entity-validator/validators.mjs.map +1 -1
  150. package/dist/utils/transform-content-types-to-models.d.ts +355 -23
  151. package/dist/utils/transform-content-types-to-models.d.ts.map +1 -1
  152. package/dist/utils/transform-content-types-to-models.js +2 -1
  153. package/dist/utils/transform-content-types-to-models.js.map +1 -1
  154. package/dist/utils/transform-content-types-to-models.mjs +2 -1
  155. package/dist/utils/transform-content-types-to-models.mjs.map +1 -1
  156. package/package.json +19 -19
@@ -1 +1 @@
1
- {"version":3,"file":"id-map.js","sources":["../../../../src/services/document-service/transform/id-map.ts"],"sourcesContent":["import { Core, Data } from '@strapi/types';\nimport { async } from '@strapi/utils';\n\n/**\n * TODO: Find a better way to encode keys than this\n * This converts an object into a string by joining its keys and values,\n * so it can be used as a key in a Map.\n *\n * @example\n * const obj = { a: 1, b: 2 };\n * const key = encodeKey(obj);\n * ^ \"a:::1&&b:::2\"\n */\nconst encodeKey = (obj: any) => {\n // Sort keys to always keep the same order when encoding\n const keys = Object.keys(obj).sort();\n return keys.map((key) => `${key}:::${obj[key]}`).join('&&');\n};\n\ninterface KeyFields {\n uid: string;\n documentId: Data.ID;\n locale?: string | null;\n status?: 'draft' | 'published';\n}\n\nexport interface IdMap {\n loadedIds: Map<string, string>;\n toLoadIds: Map<string, KeyFields>;\n // Make the Keys type to be the params of add\n add(keys: KeyFields): void;\n load(): Promise<void>;\n get(keys: KeyFields): string | undefined;\n clear(): void;\n}\n\n/**\n * Holds a registry of document ids and their corresponding entity ids.\n */\nconst createIdMap = ({ strapi }: { strapi: Core.Strapi }): IdMap => {\n const loadedIds = new Map();\n const toLoadIds = new Map();\n\n return {\n loadedIds,\n toLoadIds,\n /**\n * Register a new document id and its corresponding entity id.\n */\n add(keyFields: KeyFields) {\n const key = encodeKey({ status: 'published', locale: null, ...keyFields });\n\n // If the id is already loaded, do nothing\n if (loadedIds.has(key)) return;\n // If the id is already in the toLoadIds, do nothing\n if (toLoadIds.has(key)) return;\n\n // Add the id to the toLoadIds\n toLoadIds.set(key, keyFields);\n },\n\n /**\n * Load all ids from the registry.\n */\n async load() {\n // Document Id to Entry Id queries are batched by its uid and locale\n // TODO: Add publication state too\n const loadIdValues = Array.from(toLoadIds.values());\n\n // 1. Group ids to query together\n const idsByUidAndLocale = loadIdValues.reduce((acc, { documentId, ...rest }) => {\n const key = encodeKey(rest);\n const ids = acc[key] || { ...rest, documentIds: [] };\n ids.documentIds.push(documentId);\n return { ...acc, [key]: ids };\n }, {});\n\n // 2. Query ids\n await async.map(\n Object.values(idsByUidAndLocale),\n async ({ uid, locale, documentIds, status }: any) => {\n const findParams = {\n select: ['id', 'documentId', 'locale', 'publishedAt'],\n where: {\n documentId: { $in: documentIds },\n locale: locale || null,\n publishedAt: status === 'draft' ? null : { $ne: null },\n },\n } as any;\n\n const result = await strapi?.db?.query(uid).findMany(findParams);\n\n // 3. Store result in loadedIds\n result?.forEach(({ documentId, id, locale, publishedAt }: any) => {\n const key = encodeKey({\n documentId,\n uid,\n locale,\n status: publishedAt ? 'published' : 'draft',\n });\n loadedIds.set(key, id);\n });\n }\n );\n\n // 4. Clear toLoadIds\n toLoadIds.clear();\n },\n\n /**\n * Get the entity id for a given document id.\n */\n get(keys: KeyFields) {\n const key = encodeKey({ status: 'published', locale: null, ...keys });\n return loadedIds.get(key);\n },\n\n /**\n * Clear the registry.\n */\n clear() {\n loadedIds.clear();\n toLoad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,cAClB,aAAa,WAAW,UAAU,OAAO,EAAE,KAAK,KAAK;AAAA,YACvD;AAAA,UAAA;AAGI,gBAAA,SAAS,MAAM,QAAQ,IAAI,MAAM,GAAG,EAAE,SAAS,UAAU;AAGvD,kBAAA,QAAQ,CAAC,EAAE,YAAY,IAAI,QAAAC,SAAQ,kBAAuB;AAChE,kBAAM,MAAM,UAAU;AAAA,cACpB;AAAA,cACA;AAAA,cACA,QAAAA;AAAAA,cACA,QAAQ,cAAc,cAAc;AAAA,YAAA,CACrC;AACS,sBAAA,IAAI,KAAK,EAAE;AAAA,UAAA,CACtB;AAAA,QACH;AAAA,MAAA;AAIF,gBAAU,MAAM;AAAA,IAClB;AAAA;AAAA;AAAA;AAAA,IAKA,IAAI,MAAiB;AACb,YAAA,MAAM,UAAU,EAAE,QAAQ,aAAa,QAAQ,MAAM,GAAG,KAAA,CAAM;AAC7D,aAAA,UAAU,IAAI,GAAG;AAAA,IAC1B;AAAA;AAAA;AAAA;AAAA,IAKA,QAAQ;AACN,gBAAU,MAAM;AAChB,gBAAU,MAAM;AAAA,IAClB;AAAA,EAAA;AAEJ;;"}
1
+ {"version":3,"file":"id-map.js","sources":["../../../../src/services/document-service/transform/id-map.ts"],"sourcesContent":["import { Core, Data, UID } from '@strapi/types';\nimport { async, contentTypes } from '@strapi/utils';\n\nconst hasDraftAndPublish = (uid: UID.CollectionType) => {\n const model = strapi.getModel(uid);\n return contentTypes.hasDraftAndPublish(model);\n};\n\n/**\n * TODO: Find a better way to encode keys than this\n * This converts an object into a string by joining its keys and values,\n * so it can be used as a key in a Map.\n *\n * @example\n * const obj = { a: 1, b: 2 };\n * const key = encodeKey(obj);\n * ^ \"a:::1&&b:::2\"\n */\nconst encodeKey = (obj: any) => {\n // Ignore status field for models without draft and publish\n if (!hasDraftAndPublish(obj.uid)) {\n delete obj.status;\n }\n\n // Sort keys to always keep the same order when encoding\n const keys = Object.keys(obj).sort();\n return keys.map((key) => `${key}:::${obj[key]}`).join('&&');\n};\n\ninterface KeyFields {\n uid: string;\n documentId: Data.ID;\n locale?: string | null;\n status?: 'draft' | 'published';\n}\n\nexport interface IdMap {\n loadedIds: Map<string, string>;\n toLoadIds: Map<string, KeyFields>;\n // Make the Keys type to be the params of add\n add(keys: KeyFields): void;\n load(): Promise<void>;\n get(keys: KeyFields): string | undefined;\n clear(): void;\n}\n\n/**\n * Holds a registry of document ids and their corresponding entity ids.\n */\nconst createIdMap = ({ strapi }: { strapi: Core.Strapi }): IdMap => {\n const loadedIds = new Map();\n const toLoadIds = new Map();\n\n return {\n loadedIds,\n toLoadIds,\n /**\n * Register a new document id and its corresponding entity id.\n */\n add(keyFields: KeyFields) {\n const key = encodeKey({ status: 'published', locale: null, ...keyFields });\n\n // If the id is already loaded, do nothing\n if (loadedIds.has(key)) return;\n // If the id is already in the toLoadIds, do nothing\n if (toLoadIds.has(key)) return;\n\n // Add the id to the toLoadIds\n toLoadIds.set(key, keyFields);\n },\n\n /**\n * Load all ids from the registry.\n */\n async load() {\n // Document Id to Entry Id queries are batched by its uid and locale\n // TODO: Add publication state too\n const loadIdValues = Array.from(toLoadIds.values());\n\n // 1. Group ids to query together\n const idsByUidAndLocale = loadIdValues.reduce((acc, { documentId, ...rest }) => {\n const key = encodeKey(rest);\n const ids = acc[key] || { ...rest, documentIds: [] };\n ids.documentIds.push(documentId);\n return { ...acc, [key]: ids };\n }, {});\n\n // 2. Query ids\n await async.map(\n Object.values(idsByUidAndLocale),\n async ({ uid, locale, documentIds, status }: any) => {\n const findParams = {\n select: ['id', 'documentId', 'locale', 'publishedAt'],\n where: {\n documentId: { $in: documentIds },\n locale: locale || null,\n },\n } as any;\n\n if (hasDraftAndPublish(uid)) {\n findParams.where.publishedAt = status === 'draft' ? null : { $ne: null };\n }\n\n const result = await strapi?.db?.query(uid).findMany(findParams);\n\n // 3. Store result in loadedIds\n result?.forEach(({ documentId, id, locale, publishedAt }: any) => {\n const key = encodeKey({\n documentId,\n uid,\n locale,\n status: publishedAt ? 'published' : 'draft',\n });\n loadedIds.set(key, id);\n });\n }\n );\n\n // 4. Clear toLoadIds\n toLoadIds.clear();\n },\n\n /**\n * Get the entity id for a given document id.\n */\n get(keys: KeyFields) {\n const key = encodeKey({ status: 'published', locale: null, ...keys });\n return loadedIds.get(key);\n },\n\n /**\n * Clear the registry.\n */\n clear() {\n loadedIds.clear();\n toLoadIds.clear();\n },\n };\n};\n\nexport { createIdMap };\n"],"names":["contentTypes","strapi","async","locale"],"mappings":";;;AAGA,MAAM,qBAAqB,CAAC,QAA4B;AAChD,QAAA,QAAQ,OAAO,SAAS,GAAG;AAC1B,SAAAA,YAAA,aAAa,mBAAmB,KAAK;AAC9C;AAYA,MAAM,YAAY,CAAC,QAAa;AAE9B,MAAI,CAAC,mBAAmB,IAAI,GAAG,GAAG;AAChC,WAAO,IAAI;AAAA,EACb;AAGA,QAAM,OAAO,OAAO,KAAK,GAAG,EAAE,KAAK;AACnC,SAAO,KAAK,IAAI,CAAC,QAAQ,GAAG,GAAG,MAAM,IAAI,GAAG,CAAC,EAAE,EAAE,KAAK,IAAI;AAC5D;AAsBA,MAAM,cAAc,CAAC,EAAE,QAAAC,cAA6C;AAC5D,QAAA,gCAAgB;AAChB,QAAA,gCAAgB;AAEf,SAAA;AAAA,IACL;AAAA,IACA;AAAA;AAAA;AAAA;AAAA,IAIA,IAAI,WAAsB;AAClB,YAAA,MAAM,UAAU,EAAE,QAAQ,aAAa,QAAQ,MAAM,GAAG,UAAA,CAAW;AAGrE,UAAA,UAAU,IAAI,GAAG;AAAG;AAEpB,UAAA,UAAU,IAAI,GAAG;AAAG;AAGd,gBAAA,IAAI,KAAK,SAAS;AAAA,IAC9B;AAAA;AAAA;AAAA;AAAA,IAKA,MAAM,OAAO;AAGX,YAAM,eAAe,MAAM,KAAK,UAAU,OAAQ,CAAA;AAG5C,YAAA,oBAAoB,aAAa,OAAO,CAAC,KAAK,EAAE,YAAY,GAAG,WAAW;AACxE,cAAA,MAAM,UAAU,IAAI;AACpB,c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entTypes } from "@strapi/utils";
2
+ const hasDraftAndPublish = (uid) => {
3
+ const model = strapi.getModel(uid);
4
+ return contentTypes.hasDraftAndPublish(model);
5
+ };
2
6
  const encodeKey = (obj) => {
7
+ if (!hasDraftAndPublish(obj.uid)) {
8
+ delete obj.status;
9
+ }
3
10
  const keys = Object.keys(obj).sort();
4
11
  return keys.map((key) => `${key}:::${obj[key]}`).join("&&");
5
12
  };
6
- const createIdMap = ({ strapi }) => {
13
+ const createIdMap = ({ strapi: strapi2 }) => {
7
14
  const loadedIds = /* @__PURE__ */ new Map();
8
15
  const toLoadIds = /* @__PURE__ */ new Map();
9
16
  return {
@@ -38,11 +45,13 @@ const createIdMap = ({ strapi }) => {
38
45
  select: ["id", "documentId", "locale", "publishedAt"],
39
46
  where: {
40
47
  documentId: { $in: documentIds },
41
- locale: locale || null,
42
- publishedAt: status === "draft" ? null : { $ne: null }
48
+ locale: locale || null
43
49
  }
44
50
  };
45
- const result = await strapi?.db?.query(uid).findMany(findParams);
51
+ if (hasDraftAndPublish(uid)) {
52
+ findParams.where.publishedAt = status === "draft" ? null : { $ne: null };
53
+ }
54
+ const result = await strapi2?.db?.query(uid).findMany(findParams);
46
55
  result?.forEach(({ documentId, id, locale: locale2, publishedAt }) => {
47
56
  const key = encodeKey({
48
57
  documentId,
@@ -1 +1 @@
1
- {"version":3,"file":"id-map.mjs","sources":["../../../../src/services/document-service/transform/id-map.ts"],"sourcesContent":["import { Core, Data } from '@strapi/types';\nimport { async } from '@strapi/utils';\n\n/**\n * TODO: Find a better way to encode keys than this\n * This converts an object into a string by joining its keys and values,\n * so it can be used as a key in a Map.\n *\n * @example\n * const obj = { a: 1, b: 2 };\n * const key = encodeKey(obj);\n * ^ \"a:::1&&b:::2\"\n */\nconst encodeKey = (obj: any) => {\n // Sort keys to always keep the same order when encoding\n const keys = Object.keys(obj).sort();\n return keys.map((key) => `${key}:::${obj[key]}`).join('&&');\n};\n\ninterface KeyFields {\n uid: string;\n documentId: Data.ID;\n locale?: string | null;\n status?: 'draft' | 'published';\n}\n\nexport interface IdMap {\n loadedIds: Map<string, string>;\n toLoadIds: Map<string, KeyFields>;\n // Make the Keys type to be the params of add\n add(keys: KeyFields): void;\n load(): Promise<void>;\n get(keys: KeyFields): string | undefined;\n clear(): void;\n}\n\n/**\n * Holds a registry of document ids and their corresponding entity ids.\n */\nconst createIdMap = ({ strapi }: { strapi: Core.Strapi }): IdMap => {\n const loadedIds = new Map();\n const toLoadIds = new Map();\n\n return {\n loadedIds,\n toLoadIds,\n /**\n * Register a new document id and its corresponding entity id.\n */\n add(keyFields: KeyFields) {\n const key = encodeKey({ status: 'published', locale: null, ...keyFields });\n\n // If the id is already loaded, do nothing\n if (loadedIds.has(key)) return;\n // If the id is already in the toLoadIds, do nothing\n if (toLoadIds.has(key)) return;\n\n // Add the id to the toLoadIds\n toLoadIds.set(key, keyFields);\n },\n\n /**\n * Load all ids from the registry.\n */\n async load() {\n // Document Id to Entry Id queries are batched by its uid and locale\n // TODO: Add publication state too\n const loadIdValues = Array.from(toLoadIds.values());\n\n // 1. Group ids to query together\n const idsByUidAndLocale = loadIdValues.reduce((acc, { documentId, ...rest }) => {\n const key = encodeKey(rest);\n const ids = acc[key] || { ...rest, documentIds: [] };\n ids.documentIds.push(documentId);\n return { ...acc, [key]: ids };\n }, {});\n\n // 2. Query ids\n await async.map(\n Object.values(idsByUidAndLocale),\n async ({ uid, locale, documentIds, status }: any) => {\n const findParams = {\n select: ['id', 'documentId', 'locale', 'publishedAt'],\n where: {\n documentId: { $in: documentIds },\n locale: locale || null,\n publishedAt: status === 'draft' ? null : { $ne: null },\n },\n } as any;\n\n const result = await strapi?.db?.query(uid).findMany(findParams);\n\n // 3. Store result in loadedIds\n result?.forEach(({ documentId, id, locale, publishedAt }: any) => {\n const key = encodeKey({\n documentId,\n uid,\n locale,\n status: publishedAt ? 'published' : 'draft',\n });\n loadedIds.set(key, id);\n });\n }\n );\n\n // 4. Clear toLoadIds\n toLoadIds.clear();\n },\n\n /**\n * Get the entity id for a given document id.\n */\n get(keys: KeyFields) {\n const key = encodeKey({ status: 'published', locale: null, ...keys });\n return loadedIds.get(key);\n },\n\n /**\n * Clear the registry.\n */\n clear() {\n loadedIds.clear();\n toLoadIds.clear();\n },\n };\n};\n\nexport { createIdMap };\n"],"names":["locale"],"mappings":";AAaA,MAAM,YAAY,CAAC,QAAa;AAE9B,QAAM,OAAO,OAAO,KAAK,GAAG,EAAE,KAAK;AACnC,SAAO,KAAK,IAAI,CAAC,QAAQ,GAAG,GAAG,MAAM,IAAI,GAAG,CAAC,EAAE,EAAE,KAAK,IAAI;AAC5D;AAsBA,MAAM,cAAc,CAAC,EAAE,aAA6C;AAC5D,QAAA,gCAAgB;AAChB,QAAA,gCAAgB;AAEf,SAAA;AAAA,IACL;AAAA,IACA;AAAA;AAAA;AAAA;AAAA,IAIA,IAAI,WAAsB;AAClB,YAAA,MAAM,UAAU,EAAE,QAAQ,aAAa,QAAQ,MAAM,GAAG,UAAA,CAAW;AAGrE,UAAA,UAAU,IAAI,GAAG;AAAG;AAEpB,UAAA,UAAU,IAAI,GAAG;AAAG;AAGd,gBAAA,IAAI,KAAK,SAAS;AAAA,IAC9B;AAAA;AAAA;AAAA;AAAA,IAKA,MAAM,OAAO;AAGX,YAAM,eAAe,MAAM,KAAK,UAAU,OAAQ,CAAA;AAG5C,YAAA,oBAAoB,aAAa,OAAO,CAAC,KAAK,EAAE,YAAY,GAAG,WAAW;AACxE,cAAA,MAAM,UAAU,IAAI;AACpB,cAAA,MAAM,IAAI,GAAG,KAAK,EAAE,GAAG,MAAM,aAAa,CAAA;AAC5C,YAAA,YAAY,KAAK,UAAU;AAC/B,eAAO,EAAE,GAAG,KAAK,CAAC,GAAG,GAAG,IAAI;AAAA,MAC9B,GAAG,CAAE,CAAA;AAGL,YAAM,MAAM;AAAA,QACV,OAAO,OAAO,iBAAiB;AAAA,QAC/B,OAAO,EAAE,KAAK,QAAQ,aAAa,aAAkB;AACnD,gBAAM,aAAa;AAAA,YACjB,QAAQ,CAAC,MAAM,cAAc,UAAU,aAAa;AAAA,YACpD,OAAO;AAAA,cACL,YAAY,EAAE,KAAK,YAAY;AAAA,cAC/B,QAAQ,UAAU;AAAA,cAClB,aAAa,WAAW,UAAU,OAAO,EAAE,KAAK,KAAK;AAAA,YACvD;AAAA,UAAA;AAGI,gBAAA,SAAS,MAAM,QAAQ,IAAI,MAAM,GAAG,EAAE,SAAS,UAAU;AAGvD,kBAAA,QAAQ,CAAC,EAAE,YAAY,IAAI,QAAAA,SAAQ,kBAAuB;AAChE,kBAAM,MAAM,UAAU;AAAA,cACpB;AAAA,cACA;AAAA,cACA,QAAAA;AAAAA,cACA,QAAQ,cAAc,cAAc;AAAA,YAAA,CACrC;AACS,sBAAA,IAAI,KAAK,EAAE;AAAA,UAAA,CACtB;AAAA,QACH;AAAA,MAAA;AAIF,gBAAU,MAAM;AAAA,IAClB;AAAA;AAAA;AAAA;AAAA,IAKA,IAAI,MAAiB;AACb,YAAA,MAAM,UAAU,EAAE,QAAQ,aAAa,QAAQ,MAAM,GAAG,KAAA,CAAM;AAC7D,aAAA,UAAU,IAAI,GAAG;AAAA,IAC1B;AAAA;AAAA;AAAA;AAAA,IAKA,QAAQ;AACN,gBAAU,MAAM;AAChB,gBAAU,MAAM;AAAA,IAClB;AAAA,EAAA;AAEJ;"}
1
+ {"version":3,"file":"id-map.mjs","sources":["../../../../src/services/document-service/transform/id-map.ts"],"sourcesContent":["import { Core, Data, UID } from '@strapi/types';\nimport { async, contentTypes } from '@strapi/utils';\n\nconst hasDraftAndPublish = (uid: UID.CollectionType) => {\n const model = strapi.getModel(uid);\n return contentTypes.hasDraftAndPublish(model);\n};\n\n/**\n * TODO: Find a better way to encode keys than this\n * This converts an object into a string by joining its keys and values,\n * so it can be used as a key in a Map.\n *\n * @example\n * const obj = { a: 1, b: 2 };\n * const key = encodeKey(obj);\n * ^ \"a:::1&&b:::2\"\n */\nconst encodeKey = (obj: any) => {\n // Ignore status field for models without draft and publish\n if (!hasDraftAndPublish(obj.uid)) {\n delete obj.status;\n }\n\n // Sort keys to always keep the same order when encoding\n const keys = Object.keys(obj).sort();\n return keys.map((key) => `${key}:::${obj[key]}`).join('&&');\n};\n\ninterface KeyFields {\n uid: string;\n documentId: Data.ID;\n locale?: string | null;\n status?: 'draft' | 'published';\n}\n\nexport interface IdMap {\n loadedIds: Map<string, string>;\n toLoadIds: Map<string, KeyFields>;\n // Make the Keys type to be the params of add\n add(keys: KeyFields): void;\n load(): Promise<void>;\n get(keys: KeyFields): string | undefined;\n clear(): void;\n}\n\n/**\n * Holds a registry of document ids and their corresponding entity ids.\n */\nconst createIdMap = ({ strapi }: { strapi: Core.Strapi }): IdMap => {\n const loadedIds = new Map();\n const toLoadIds = new Map();\n\n return {\n loadedIds,\n toLoadIds,\n /**\n * Register a new document id and its corresponding entity id.\n */\n add(keyFields: KeyFields) {\n const key = encodeKey({ status: 'published', locale: null, ...keyFields });\n\n // If the id is already loaded, do nothing\n if (loadedIds.has(key)) return;\n // If the id is already in the toLoadIds, do nothing\n if (toLoadIds.has(key)) return;\n\n // Add the id to the toLoadIds\n toLoadIds.set(key, keyFields);\n },\n\n /**\n * Load all ids from the registry.\n */\n async load() {\n // Document Id to Entry Id queries are batched by its uid and locale\n // TODO: Add publication state too\n const loadIdValues = Array.from(toLoadIds.values());\n\n // 1. Group ids to query together\n const idsByUidAndLocale = loadIdValues.reduce((acc, { documentId, ...rest }) => {\n const key = encodeKey(rest);\n const ids = acc[key] || { ...rest, documentIds: [] };\n ids.documentIds.push(documentId);\n return { ...acc, [key]: ids };\n }, {});\n\n // 2. Query ids\n await async.map(\n Object.values(idsByUidAndLocale),\n async ({ uid, locale, documentIds, status }: any) => {\n const findParams = {\n select: ['id', 'documentId', 'locale', 'publishedAt'],\n where: {\n documentId: { $in: documentIds },\n locale: locale || null,\n },\n } as any;\n\n if (hasDraftAndPublish(uid)) {\n findParams.where.publishedAt = status === 'draft' ? null : { $ne: null };\n }\n\n const result = await strapi?.db?.query(uid).findMany(findParams);\n\n // 3. Store result in loadedIds\n result?.forEach(({ documentId, id, locale, publishedAt }: any) => {\n const key = encodeKey({\n documentId,\n uid,\n locale,\n status: publishedAt ? 'published' : 'draft',\n });\n loadedIds.set(key, id);\n });\n }\n );\n\n // 4. Clear toLoadIds\n toLoadIds.clear();\n },\n\n /**\n * Get the entity id for a given document id.\n */\n get(keys: KeyFields) {\n const key = encodeKey({ status: 'published', locale: null, ...keys });\n return loadedIds.get(key);\n },\n\n /**\n * Clear the registry.\n */\n clear() {\n loadedIds.clear();\n toLoadIds.clear();\n },\n };\n};\n\nexport { createIdMap };\n"],"names":["strapi","locale"],"mappings":";AAGA,MAAM,qBAAqB,CAAC,QAA4B;AAChD,QAAA,QAAQ,OAAO,SAAS,GAAG;AAC1B,SAAA,aAAa,mBAAmB,KAAK;AAC9C;AAYA,MAAM,YAAY,CAAC,QAAa;AAE9B,MAAI,CAAC,mBAAmB,IAAI,GAAG,GAAG;AAChC,WAAO,IAAI;AAAA,EACb;AAGA,QAAM,OAAO,OAAO,KAAK,GAAG,EAAE,KAAK;AACnC,SAAO,KAAK,IAAI,CAAC,QAAQ,GAAG,GAAG,MAAM,IAAI,GAAG,CAAC,EAAE,EAAE,KAAK,IAAI;AAC5D;AAsBA,MAAM,cAAc,CAAC,EAAE,QAAAA,cAA6C;AAC5D,QAAA,gCAAgB;AAChB,QAAA,gCAAgB;AAEf,SAAA;AAAA,IACL;AAAA,IACA;AAAA;AAAA;AAAA;AAAA,IAIA,IAAI,WAAsB;AAClB,YAAA,MAAM,UAAU,EAAE,QAAQ,aAAa,QAAQ,MAAM,GAAG,UAAA,CAAW;AAGrE,UAAA,UAAU,IAAI,GAAG;AAAG;AAEpB,UAAA,UAAU,IAAI,GAAG;AAAG;AAGd,gBAAA,IAAI,KAAK,SAAS;AAAA,IAC9B;AAAA;AAAA;AAAA;AAAA,IAKA,MAAM,OAAO;AAGX,YAAM,eAAe,MAAM,KAAK,UAAU,OA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AM;AAChB,gBAAU,MAAM;AAAA,IAClB;AAAA,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,qDAkC/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;AAQrC,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,qDA2C/E,CAAC;AAEF,OAAO,EAAE,cAAc,EAAE,CAAC"}
@@ -1,11 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const fp = require("lodash/fp");
4
+ const strapiUtils = require("@strapi/utils");
4
5
  const i18n = require("../utils/i18n.js");
5
6
  const dp = require("../utils/dp.js");
6
7
  const mapRelation = require("../utils/map-relation.js");
8
+ const { isPolymorphic } = strapiUtils.relations;
7
9
  const addRelationDocId = fp.curry(
8
- (idMap, targetUid, source, relation) => {
10
+ (idMap, source, targetUid, relation) => {
9
11
  const targetLocale = i18n.getRelationTargetLocale(relation, {
10
12
  targetUid,
11
13
  sourceUid: source.uid,
@@ -32,19 +34,24 @@ const extractDataIds = (idMap, data, source) => {
32
34
  if (!attribute) {
33
35
  return;
34
36
  }
35
- const targetUid = attribute.target;
36
- const addDocId = addRelationDocId(idMap, targetUid, source);
37
+ const isPolymorphicRelation = isPolymorphic(attribute);
38
+ const addDocId = addRelationDocId(idMap, source);
37
39
  return mapRelation.mapRelation((relation) => {
38
40
  if (!relation || !relation.documentId) {
39
41
  return relation;
40
42
  }
41
- addDocId(relation);
43
+ const targetUid = isPolymorphicRelation ? relation.__type : attribute.target;
44
+ addDocId(targetUid, relation);
42
45
  const position = relation.position;
46
+ let positionTargetUid = targetUid;
47
+ if (isPolymorphicRelation && position?.__type) {
48
+ positionTargetUid = position.__type;
49
+ }
43
50
  if (position?.before) {
44
- addDocId({ ...relation, ...position, documentId: position.before });
51
+ addDocId(positionTargetUid, { ...relation, ...position, documentId: position.before });
45
52
  }
46
53
  if (position?.after) {
47
- addDocId({ ...relation, ...position, documentId: position.after });
54
+ addDocId(positionTargetUid, { ...relation, ...position, documentId: position.after });
48
55
  }
49
56
  return relation;
50
57
  }, value);
@@ -1 +1 @@
1
- {"version":3,"file":"data-ids.js","sources":["../../../../../../src/services/document-service/transform/relations/extract/data-ids.ts"],"sourcesContent":["import { curry } from 'lodash/fp';\n\nimport { UID } from '@strapi/types';\n\nimport { IdMap } from '../../id-map';\nimport { getRelationTargetLocale } from '../utils/i18n';\nimport { getRelationTargetStatus } from '../utils/dp';\nimport { mapRelation, traverseEntityRelations } from '../utils/map-relation';\nimport { LongHandDocument } from '../utils/types';\n\ninterface Options {\n uid: UID.Schema;\n locale?: string | null;\n status?: 'draft' | 'published';\n}\n\n/**\n * Load a relation documentId into the idMap.\n */\nconst addRelationDocId = curry(\n (idMap: IdMap, targetUid: UID.Schema, source: Options, relation: LongHandDocument) => {\n const targetLocale = getRelationTargetLocale(relation, {\n targetUid,\n sourceUid: source.uid,\n sourceLocale: source.locale,\n });\n\n const targetStatus = getRelationTargetStatus(relation, {\n targetUid,\n sourceUid: source.uid,\n sourceStatus: source.status,\n });\n\n targetStatus.forEach((status) => {\n idMap.add({\n uid: targetUid,\n documentId: relation.documentId,\n locale: targetLocale,\n status,\n });\n });\n }\n);\n\n/**\n * Iterate over all relations of a data object and extract all relational document ids.\n * Those will later be transformed to entity ids.\n */\nconst extractDataIds = (idMap: IdMap, data: Record<string, any>, source: Options) => {\n return traverseEntityRelations(\n async ({ attribute, value }) => {\n if (!attribute) {\n return;\n }\n\n const targetUid = attribute.target!;\n const addDocId = addRelationDocId(idMap, targetUid, source);\n\n return mapRelation((relation) => {\n if (!relation || !relation.documentId) {\n return relation;\n }\n\n addDocId(relation);\n\n // Handle positional arguments\n const position = relation.position;\n\n if (position?.before) {\n addDocId({ ...relation, ...position, documentId: position.before });\n }\n\n if (position?.after) {\n addDocId({ ...relation, ...position, documentId: position.after });\n }\n\n return relation;\n }, value as any);\n },\n { schema: strapi.getModel(source.uid), getModel: strapi.getModel.bind(strapi) },\n data\n );\n};\n\nexport { extractDataIds };\n"],"names":["curry","getRelationTargetLocale","getRelationTargetStatus","traverseEntityRelations","mapRelation"],"mappings":";;;;;;AAmBA,MAAM,mBAAmBA,GAAA;AAAA,EACvB,CAAC,OAAc,WAAuB,QAAiB,aAA+B;AAC9E,UAAA,eAAeC,6BAAwB,UAAU;AAAA,MACrD;AAAA,MACA,WAAW,OAAO;AAAA,MAClB,cAAc,OAAO;AAAA,IAAA,CACtB;AAEK,UAAA,eAAeC,2BAAwB,UAAU;AAAA,MACrD;AAAA,MACA,WAAW,OAAO;AAAA,MAClB,cAAc,OAAO;AAAA,IAAA,CACtB;AAEY,iBAAA,QAAQ,CAAC,WAAW;AAC/B,YAAM,IAAI;AAAA,QACR,KAAK;AAAA,QACL,YAAY,SAAS;AAAA,QACrB,QAAQ;AAAA,QACR;AAAA,MAAA,CACD;AAAA,IAAA,CACF;AAAA,EACH;AACF;AAMA,MAAM,iBAAiB,CAAC,OAAc,MAA2B,WAAoB;AAC5E,SAAAC,YAAA;AAAA,IACL,OAAO,EAAE,WAAW,YAAY;AAC9B,UAAI,CAAC,WAAW;AACd;AAAA,MACF;AAEA,YAAM,YAAY,UAAU;AAC5B,YAAM,WAAW,iBAAiB,OAAO,WAAW,MAAM;AAEnD,aAAAC,YAAAA,YAAY,CAAC,aAAa;AAC/B,YAAI,CAAC,YAAY,CAAC,SAAS,YAAY;AAC9B,iBAAA;AAAA,QACT;AAEA,iBAAS,QAAQ;AAGjB,cAAM,WAAW,SAAS;AAE1B,YAAI,UAAU,QAAQ;AACX,mBAAA,EAAE,GAAG,UAAU,GAAG,UAAU,YAAY,SAAS,QAAQ;AAAA,QACpE;AAEA,YAAI,UAAU,OAAO;AACV,mBAAA,EAAE,GAAG,UAAU,GAAG,UAAU,YAAY,SAAS,OAAO;AAAA,QACnE;AAEO,eAAA;AAAA,SACN,KAAY;AAAA,IACjB;AAAA,IACA,EAAE,QAAQ,OAAO,SAAS,OAAO,GAAG,GAAG,UAAU,OAAO,SAAS,KAAK,MAAM,EAAE;AAAA,IAC9E;AAAA,EAAA;AAEJ;;"}
1
+ {"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';\nimport { relations } from '@strapi/utils';\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\nconst { isPolymorphic } = relations;\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, source: Options, targetUid: UID.Schema, 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 const isPolymorphicRelation = isPolymorphic(attribute);\n const addDocId = addRelationDocId(idMap, source);\n\n return mapRelation((relation) => {\n if (!relation || !relation.documentId) {\n return relation;\n }\n\n // Regular relations will always target the same target\n // if its a polymorphic relation we need to get it from the data itself\n const targetUid = isPolymorphicRelation ? relation.__type : attribute.target;\n\n addDocId(targetUid, relation);\n\n // Handle positional arguments\n const position = relation.position;\n\n // The positional relation target uid can be different for polymorphic relations\n let positionTargetUid = targetUid;\n if (isPolymorphicRelation && position?.__type) {\n positionTargetUid = position.__type;\n }\n\n if (position?.before) {\n addDocId(positionTargetUid, { ...relation, ...position, documentId: position.before });\n }\n\n if (position?.after) {\n addDocId(positionTargetUid, { ...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":["relations","curry","getRelationTargetLocale","getRelationTargetStatus","traverseEntityRelations","mapRelation"],"mappings":";;;;;;;AAUA,MAAM,EAAE,cAAkB,IAAAA;AAW1B,MAAM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AA,IACA,EAAE,QAAQ,OAAO,SAAS,OAAO,GAAG,GAAG,UAAU,OAAO,SAAS,KAAK,MAAM,EAAE;AAAA,IAC9E;AAAA,EAAA;AAEJ;;"}
@@ -1,9 +1,11 @@
1
1
  import { curry } from "lodash/fp";
2
+ import { relations } from "@strapi/utils";
2
3
  import { getRelationTargetLocale } from "../utils/i18n.mjs";
3
4
  import { getRelationTargetStatus } from "../utils/dp.mjs";
4
5
  import { traverseEntityRelations as traverseEntityRelationsCurried, mapRelation as mapRelationCurried } from "../utils/map-relation.mjs";
6
+ const { isPolymorphic } = relations;
5
7
  const addRelationDocId = curry(
6
- (idMap, targetUid, source, relation) => {
8
+ (idMap, source, targetUid, relation) => {
7
9
  const targetLocale = getRelationTargetLocale(relation, {
8
10
  targetUid,
9
11
  sourceUid: source.uid,
@@ -30,19 +32,24 @@ const extractDataIds = (idMap, data, source) => {
30
32
  if (!attribute) {
31
33
  return;
32
34
  }
33
- const targetUid = attribute.target;
34
- const addDocId = addRelationDocId(idMap, targetUid, source);
35
+ const isPolymorphicRelation = isPolymorphic(attribute);
36
+ const addDocId = addRelationDocId(idMap, source);
35
37
  return mapRelationCurried((relation) => {
36
38
  if (!relation || !relation.documentId) {
37
39
  return relation;
38
40
  }
39
- addDocId(relation);
41
+ const targetUid = isPolymorphicRelation ? relation.__type : attribute.target;
42
+ addDocId(targetUid, relation);
40
43
  const position = relation.position;
44
+ let positionTargetUid = targetUid;
45
+ if (isPolymorphicRelation && position?.__type) {
46
+ positionTargetUid = position.__type;
47
+ }
41
48
  if (position?.before) {
42
- addDocId({ ...relation, ...position, documentId: position.before });
49
+ addDocId(positionTargetUid, { ...relation, ...position, documentId: position.before });
43
50
  }
44
51
  if (position?.after) {
45
- addDocId({ ...relation, ...position, documentId: position.after });
52
+ addDocId(positionTargetUid, { ...relation, ...position, documentId: position.after });
46
53
  }
47
54
  return relation;
48
55
  }, value);
@@ -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 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
+ {"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';\nimport { relations } from '@strapi/utils';\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\nconst { isPolymorphic } = relations;\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, source: Options, targetUid: UID.Schema, 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 const isPolymorphicRelation = isPolymorphic(attribute);\n const addDocId = addRelationDocId(idMap, source);\n\n return mapRelation((relation) => {\n if (!relation || !relation.documentId) {\n return relation;\n }\n\n // Regular relations will always target the same target\n // if its a polymorphic relation we need to get it from the data itself\n const targetUid = isPolymorphicRelation ? relation.__type : attribute.target;\n\n addDocId(targetUid, relation);\n\n // Handle positional arguments\n const position = relation.position;\n\n // The positional relation target uid can be different for polymorphic relations\n let positionTargetUid = targetUid;\n if (isPolymorphicRelation && position?.__type) {\n positionTargetUid = position.__type;\n }\n\n if (position?.before) {\n addDocId(positionTargetUid, { ...relation, ...position, documentId: position.before });\n }\n\n if (position?.after) {\n addDocId(positionTargetUid, { ...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":";;;;;AAUA,MAAM,EAAE,cAAkB,IAAA;AAW1B,MAAM,mBAAmB;AAAA,EACvB,CAAC,OAAc,QAAiB,WAAuB,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;AACM,YAAA,wBAAwB,cAAc,SAAS;AAC/C,YAAA,WAAW,iBAAiB,OAAO,MAAM;AAExC,aAAAC,mBAAY,CAAC,aAAa;AAC/B,YAAI,CAAC,YAAY,CAAC,SAAS,YAAY;AAC9B,iBAAA;AAAA,QACT;AAIA,cAAM,YAAY,wBAAwB,SAAS,SAAS,UAAU;AAEtE,iBAAS,WAAW,QAAQ;AAG5B,cAAM,WAAW,SAAS;AAG1B,YAAI,oBAAoB;AACpB,YAAA,yBAAyB,UAAU,QAAQ;AAC7C,8BAAoB,SAAS;AAAA,QAC/B;AAEA,YAAI,UAAU,QAAQ;AACX,mBAAA,mBAAmB,EAAE,GAAG,UAAU,GAAG,UAAU,YAAY,SAAS,OAAA,CAAQ;AAAA,QACvF;AAEA,YAAI,UAAU,OAAO;AACV,mBAAA,mBAAmB,EAAE,GAAG,UAAU,GAAG,UAAU,YAAY,SAAS,MAAA,CAAO;AAAA,QACtF;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,qDAgDxF,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;AAOrC,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,qDA8DxF,CAAC;AAEF,OAAO,EAAE,uBAAuB,EAAE,CAAC"}
@@ -5,8 +5,9 @@ const strapiUtils = require("@strapi/utils");
5
5
  const i18n = require("../utils/i18n.js");
6
6
  const dp = require("../utils/dp.js");
7
7
  const mapRelation = require("../utils/map-relation.js");
8
+ const { isPolymorphic } = strapiUtils.relations;
8
9
  const getRelationIds = fp.curry(
9
- (idMap, targetUid, source, relation) => {
10
+ (idMap, source, targetUid, relation) => {
10
11
  const targetLocale = i18n.getRelationTargetLocale(relation, {
11
12
  targetUid,
12
13
  sourceUid: source.uid,
@@ -42,27 +43,36 @@ const transformDataIdsVisitor = (idMap, data, source) => {
42
43
  if (!attribute) {
43
44
  return;
44
45
  }
45
- const targetUid = attribute.target;
46
- const getIds = getRelationIds(idMap, targetUid, source);
46
+ const isPolymorphicRelation = isPolymorphic(attribute);
47
+ const getIds = getRelationIds(idMap, source);
47
48
  const newRelation = await mapRelation.mapRelation((relation) => {
48
49
  if (!relation || !relation.documentId) {
49
50
  return relation;
50
51
  }
51
- const ids = getIds(relation);
52
+ const targetUid = isPolymorphicRelation ? relation.__type : attribute.target;
53
+ const ids = getIds(targetUid, relation);
52
54
  const position = { ...relation.position };
55
+ let positionTargetUid = targetUid;
56
+ if (isPolymorphicRelation && position?.__type) {
57
+ positionTargetUid = position.__type;
58
+ }
53
59
  if (position.before) {
54
60
  const beforeRelation = { ...relation, ...position, documentId: position.before };
55
- position.before = getIds(beforeRelation).at(0);
61
+ const beforeIds = getIds(positionTargetUid, beforeRelation);
62
+ position.before = beforeIds.at(0);
56
63
  }
57
64
  if (position.after) {
58
65
  const afterRelation = { ...relation, ...position, documentId: position.after };
59
- position.after = getIds(afterRelation).at(0);
66
+ position.after = getIds(positionTargetUid, afterRelation).at(0);
60
67
  }
61
68
  return ids?.map((id) => {
62
69
  const newRelation2 = { id };
63
70
  if (relation.position) {
64
71
  newRelation2.position = position;
65
72
  }
73
+ if (isPolymorphicRelation) {
74
+ newRelation2.__type = targetUid;
75
+ }
66
76
  return newRelation2;
67
77
  });
68
78
  }, value);
@@ -1 +1 @@
1
- {"version":3,"file":"data-ids.js","sources":["../../../../../../src/services/document-service/transform/relations/transform/data-ids.ts"],"sourcesContent":["import { curry } from 'lodash/fp';\n\nimport type { UID } from '@strapi/types';\nimport { errors } from '@strapi/utils';\n\nimport { ID, LongHandDocument } from '../utils/types';\nimport { IdMap } from '../../id-map';\nimport { getRelationTargetLocale } from '../utils/i18n';\nimport { getRelationTargetStatus } from '../utils/dp';\nimport { mapRelation, traverseEntityRelations } from '../utils/map-relation';\n\ninterface Options {\n uid: UID.Schema;\n locale?: string | null;\n status?: 'draft' | 'published';\n allowMissingId?: boolean; // Whether to ignore missing ids and not throw any error\n}\n\n/**\n * Get the entry ids for a given documentId.\n */\nconst getRelationIds = curry(\n (idMap: IdMap, targetUid: UID.Schema, source: Options, relation: LongHandDocument) => {\n // locale to connect to\n const targetLocale = getRelationTargetLocale(relation, {\n targetUid,\n sourceUid: source.uid,\n sourceLocale: source.locale,\n });\n\n // status(es) to connect to\n const targetStatus = getRelationTargetStatus(relation, {\n targetUid,\n sourceUid: source.uid,\n sourceStatus: source.status,\n });\n\n const ids: ID[] = [];\n\n // Find mapping between documentID -> id(s).\n // There are scenarios where a single documentID can map to multiple ids.\n // e.g when connecting Non DP -> DP and connecting to both the draft and publish version at the same time\n for (const tStatus of targetStatus) {\n const entryId = idMap.get({\n uid: targetUid,\n documentId: relation.documentId,\n locale: targetLocale,\n status: tStatus,\n });\n\n if (entryId) ids.push(entryId);\n }\n\n if (!ids.length && !source.allowMissingId) {\n throw new errors.ValidationError(\n `Document with id \"${relation.documentId}\", locale \"${targetLocale}\" not found`\n );\n }\n\n return ids;\n }\n);\n\n/**\n * Iterate over all relations of a data object and transform all relational document ids to entity ids.\n */\nconst transformDataIdsVisitor = (idMap: IdMap, data: Record<string, any>, source: Options) => {\n return traverseEntityRelations(\n async ({ key, value, attribute }, { set }) => {\n if (!attribute) {\n return;\n }\n\n // Find relational attributes, and return the document ids\n const targetUid = attribute.target!;\n const getIds = getRelationIds(idMap, targetUid, source);\n\n // Transform the relation documentId to entity id\n const newRelation = await mapRelation((relation) => {\n if (!relation || !relation.documentId) {\n return relation;\n }\n\n const ids = getIds(relation);\n\n // Handle positional arguments\n const position = { ...relation.position };\n\n if (position.before) {\n const beforeRelation = { ...relation, ...position, documentId: position.before };\n position.before = getIds(beforeRelation).at(0);\n }\n\n if (position.after) {\n const afterRelation = { ...relation, ...position, documentId: position.after };\n position.after = getIds(afterRelation).at(0);\n }\n\n // Transform all ids to new relations\n return ids?.map((id) => {\n const newRelation = { id } as typeof relation;\n if (relation.position) {\n newRelation.position = position;\n }\n\n return newRelation;\n });\n }, value as any);\n\n set(key, newRelation as any);\n },\n { schema: strapi.getModel(source.uid), getModel: strapi.getModel.bind(strapi) },\n data\n );\n};\n\nexport { transformDataIdsVisitor };\n"],"names":["curry","getRelationTargetLocale","getRelationTargetStatus","errors","traverseEntityRelations","mapRelation","newRelation"],"mappings":";;;;;;;AAqBA,MAAM,iBAAiBA,GAAA;AAAA,EACrB,CAAC,OAAc,WAAuB,QAAiB,aAA+B;AAE9E,UAAA,eAAeC,6BAAwB,UAAU;AAAA,MACrD;AAAA,MACA,WAAW,OAAO;AAAA,MAClB,cAAc,OAAO;AAAA,IAAA,CACtB;AAGK,UAAA,eAAeC,2BAAwB,UAAU;AAAA,MACrD;AAAA,MACA,WAAW,OAAO;AAAA,MAClB,cAAc,OAAO;AAAA,IAAA,CACtB;AAED,UAAM,MAAY,CAAA;AAKlB,eAAW,WAAW,cAAc;AAC5B,YAAA,UAAU,MAAM,IAAI;AAAA,QACxB,KAAK;AAAA,QACL,YAAY,SAAS;AAAA,QACrB,QAAQ;AAAA,QACR,QAAQ;AAAA,MAAA,CACT;AAEG,UAA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E;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, relations } 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\nconst { isPolymorphic } = relations;\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, source: Options, targetUid: UID.Schema, 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 const isPolymorphicRelation = isPolymorphic(attribute);\n const getIds = getRelationIds(idMap, 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 // Find relational attributes, and return the document ids\n // if its a polymorphic relation we need to get it from the data itself\n const targetUid: UID.Schema = isPolymorphicRelation ? relation.__type : attribute.target;\n const ids: ID[] = getIds(targetUid, relation);\n\n // Handle positional arguments\n const position = { ...relation.position };\n\n // The positional relation target uid can be different for polymorphic relations\n let positionTargetUid: UID.Schema = targetUid;\n if (isPolymorphicRelation && position?.__type) {\n positionTargetUid = position.__type;\n }\n\n if (position.before) {\n const beforeRelation = { ...relation, ...position, documentId: position.before };\n const beforeIds: ID[] = getIds(positionTargetUid, beforeRelation);\n position.before = beforeIds.at(0);\n }\n\n if (position.after) {\n const afterRelation = { ...relation, ...position, documentId: position.after };\n position.after = getIds(positionTargetUid, 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\n if (relation.position) {\n newRelation.position = position;\n }\n\n // Insert type if its a polymorphic relation\n if (isPolymorphicRelation) {\n newRelation.__type = targetUid;\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":["relations","curry","getRelationTargetLocale","getRelationTargetStatus","errors","traverseEntityRelations","mapRelation","newRelation"],"mappings":";;;;;;;AAWA,MAAM,EAAE,cAAkB,IAAAA;AAY1B,MAAM,iBAAiBC,GAAA;AAAA,EACrB,CAAC,OAAc,QAAiB,WAAuB,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,WAA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gB,EAAE,GAAG,UAAU,GAAG,UAAU,YAAY,SAAS;AACvE,mBAAS,QAAQ,OAAO,mBAAmB,aAAa,EAAE,GAAG,CAAC;AAAA,QAChE;AAGO,eAAA,KAAK,IAAI,CAAC,OAAO;AAChBC,gBAAAA,eAAc,EAAE;AAEtB,cAAI,SAAS,UAAU;AACrBA,yBAAY,WAAW;AAAA,UACzB;AAGA,cAAI,uBAAuB;AACzBA,yBAAY,SAAS;AAAA,UACvB;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,10 +1,11 @@
1
1
  import { curry } from "lodash/fp";
2
- import { errors } from "@strapi/utils";
2
+ import { errors, relations } from "@strapi/utils";
3
3
  import { getRelationTargetLocale } from "../utils/i18n.mjs";
4
4
  import { getRelationTargetStatus } from "../utils/dp.mjs";
5
5
  import { traverseEntityRelations as traverseEntityRelationsCurried, mapRelation as mapRelationCurried } from "../utils/map-relation.mjs";
6
+ const { isPolymorphic } = relations;
6
7
  const getRelationIds = curry(
7
- (idMap, targetUid, source, relation) => {
8
+ (idMap, source, targetUid, relation) => {
8
9
  const targetLocale = getRelationTargetLocale(relation, {
9
10
  targetUid,
10
11
  sourceUid: source.uid,
@@ -40,27 +41,36 @@ const transformDataIdsVisitor = (idMap, data, source) => {
40
41
  if (!attribute) {
41
42
  return;
42
43
  }
43
- const targetUid = attribute.target;
44
- const getIds = getRelationIds(idMap, targetUid, source);
44
+ const isPolymorphicRelation = isPolymorphic(attribute);
45
+ const getIds = getRelationIds(idMap, source);
45
46
  const newRelation = await mapRelationCurried((relation) => {
46
47
  if (!relation || !relation.documentId) {
47
48
  return relation;
48
49
  }
49
- const ids = getIds(relation);
50
+ const targetUid = isPolymorphicRelation ? relation.__type : attribute.target;
51
+ const ids = getIds(targetUid, relation);
50
52
  const position = { ...relation.position };
53
+ let positionTargetUid = targetUid;
54
+ if (isPolymorphicRelation && position?.__type) {
55
+ positionTargetUid = position.__type;
56
+ }
51
57
  if (position.before) {
52
58
  const beforeRelation = { ...relation, ...position, documentId: position.before };
53
- position.before = getIds(beforeRelation).at(0);
59
+ const beforeIds = getIds(positionTargetUid, beforeRelation);
60
+ position.before = beforeIds.at(0);
54
61
  }
55
62
  if (position.after) {
56
63
  const afterRelation = { ...relation, ...position, documentId: position.after };
57
- position.after = getIds(afterRelation).at(0);
64
+ position.after = getIds(positionTargetUid, afterRelation).at(0);
58
65
  }
59
66
  return ids?.map((id) => {
60
67
  const newRelation2 = { id };
61
68
  if (relation.position) {
62
69
  newRelation2.position = position;
63
70
  }
71
+ if (isPolymorphicRelation) {
72
+ newRelation2.__type = targetUid;
73
+ }
64
74
  return newRelation2;
65
75
  });
66
76
  }, value);
@@ -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 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,U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AAG,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
+ {"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, relations } 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\nconst { isPolymorphic } = relations;\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, source: Options, targetUid: UID.Schema, 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 const isPolymorphicRelation = isPolymorphic(attribute);\n const getIds = getRelationIds(idMap, 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 // Find relational attributes, and return the document ids\n // if its a polymorphic relation we need to get it from the data itself\n const targetUid: UID.Schema = isPolymorphicRelation ? relation.__type : attribute.target;\n const ids: ID[] = getIds(targetUid, relation);\n\n // Handle positional arguments\n const position = { ...relation.position };\n\n // The positional relation target uid can be different for polymorphic relations\n let positionTargetUid: UID.Schema = targetUid;\n if (isPolymorphicRelation && position?.__type) {\n positionTargetUid = position.__type;\n }\n\n if (position.before) {\n const beforeRelation = { ...relation, ...position, documentId: position.before };\n const beforeIds: ID[] = getIds(positionTargetUid, beforeRelation);\n position.before = beforeIds.at(0);\n }\n\n if (position.after) {\n const afterRelation = { ...relation, ...position, documentId: position.after };\n position.after = getIds(positionTargetUid, 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\n if (relation.position) {\n newRelation.position = position;\n }\n\n // Insert type if its a polymorphic relation\n if (isPolymorphicRelation) {\n newRelation.__type = targetUid;\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\n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SAAS,SAAS;AAGxC,YAAI,oBAAgC;AAChC,YAAA,yBAAyB,UAAU,QAAQ;AAC7C,8BAAoB,SAAS;AAAA,QAC/B;AAEA,YAAI,SAAS,QAAQ;AACb,gBAAA,iBAAiB,EAAE,GAAG,UAAU,GAAG,UAAU,YAAY,SAAS;AAClE,gBAAA,YAAkB,OAAO,mBAAmB,cAAc;AACvD,mBAAA,SAAS,UAAU,GAAG,CAAC;AAAA,QAClC;AAEA,YAAI,SAAS,OAAO;AACZ,gBAAA,gBAAgB,EAAE,GAAG,UAAU,GAAG,UAAU,YAAY,SAAS;AACvE,mBAAS,QAAQ,OAAO,mBAAmB,aAAa,EAAE,GAAG,CAAC;AAAA,QAChE;AAGO,eAAA,KAAK,IAAI,CAAC,OAAO;AAChBC,gBAAAA,eAAc,EAAE;AAEtB,cAAI,SAAS,UAAU;AACrBA,yBAAY,WAAW;AAAA,UACzB;AAGA,cAAI,uBAAuB;AACzBA,yBAAY,SAAS;AAAA,UACvB;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;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"}
1
+ {"version":3,"file":"map-relation.d.ts","sourceRoot":"","sources":["../../../../../../src/services/document-service/transform/relations/utils/map-relation.ts"],"names":[],"mappings":";AAKA,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"}
@@ -74,10 +74,6 @@ const traverseEntityRelations = async (visitor, options, data) => {
74
74
  if (attribute.useJoinTable === false) {
75
75
  return;
76
76
  }
77
- const target = attribute.target;
78
- if (!target) {
79
- return;
80
- }
81
77
  return visitor(options2, utils);
82
78
  },
83
79
  options,
@@ -1 +1 @@
1
- {"version":3,"file":"map-relation.js","sources":["../../../../../../src/services/document-service/transform/relations/utils/map-relation.ts"],"sourcesContent":["/* eslint-disable node/no-callback-literal */\nimport { isObject, curry, isNil } from 'lodash/fp';\n\nimport type { UID } from '@strapi/types';\nimport { traverseEntity, async } from '@strapi/utils';\n\nimport { Relation } from './types';\n\nconst isNumeric = (value: any): value is number => {\n if (Array.isArray(value)) return false; // Handle [1, 'docId'] case\n const parsed = parseInt(value, 10);\n return !Number.isNaN(parsed);\n};\n\nconst toArray = (value: any) => {\n // Keep value as it is if it's a nullish value\n if (isNil(value)) return value;\n if (Array.isArray(value)) return value;\n\n return [value];\n};\n\n/**\n * There are multiple ways to create Strapi relations.\n * This is a utility to traverse and transform relation data\n *\n *\n * For consistency and ease of use, the response will always be an object with the following shape:\n * { set: [{...}], connect: [{...}], disconnect: [{...}] }\n *\n * @example\n * transformRelationData({\n * onLongHand: (relation) => {\n * // Change the id of the relation\n * return { id: 'other' };\n * },\n * }, relation)\n */\nconst mapRelation = async (\n callback: (relation: any) => any,\n rel: Relation,\n isRecursive = false\n): Promise<Relation> => {\n let relation: Relation = rel;\n\n const wrapInSet = (value: any) => {\n // Ignore wrapping if it's a recursive call\n if (isRecursive) {\n return value;\n }\n return { set: toArray(value) };\n };\n\n // undefined | null\n if (isNil(relation)) {\n return callback(relation);\n }\n\n // LongHand[] | ShortHand[]\n if (Array.isArray(relation)) {\n return async\n .map(relation, (r: Relation) => mapRelation(callback, r, true))\n .then((result: any) => result.flat().filter(Boolean))\n .then(wrapInSet);\n }\n\n // LongHand\n if (isObject(relation)) {\n // { id: 1 } || { documentId: 1 }\n if ('id' in relation || 'documentId' in relation) {\n const result = await callback(relation);\n return wrapInSet(result);\n }\n\n // If not connecting anything, return default visitor\n if (!relation.set && !relation.disconnect && !relation.connect) {\n return callback(relation);\n }\n\n // { set }\n if (relation.set) {\n const set: any = await mapRelation(callback, relation.set, true);\n relation = { ...relation, set: toArray(set) };\n }\n\n // { disconnect}\n if (relation.disconnect) {\n const disconnect: any = await mapRelation(callback, relation.disconnect, true);\n relation = { ...relation, disconnect: toArray(disconnect) };\n }\n\n // { connect }\n if (relation.connect) {\n // Transform the relation to connect\n const connect: any = await mapRelation(callback, relation.connect, true);\n relation = { ...relation, connect: toArray(connect) };\n }\n\n return relation;\n }\n\n // ShortHand\n if (isNumeric(relation)) {\n const result = await callback({ id: relation });\n return wrapInSet(result);\n }\n\n if (typeof relation === 'string') {\n const result = await callback({ documentId: relation });\n return wrapInSet(result);\n }\n\n // Anything else\n return callback(relation);\n};\n\ntype TraverseEntity = Parameters<typeof traverseEntity>;\n\n/**\n * Utility function, same as `traverseEntity` but only for relations.\n */\nconst traverseEntityRelations = async (\n visitor: TraverseEntity[0],\n options: TraverseEntity[1],\n data: TraverseEntity[2]\n) => {\n return traverseEntity(\n async (options, utils) => {\n const { attribute } = options;\n\n if (!attribute) {\n return;\n }\n\n if (attribute.type !== 'relation') {\n return;\n }\n\n // TODO: Handle join columns\n if (attribute.useJoinTable === false) {\n return;\n }\n\n // TODO: Handle morph relations (they have multiple targets)\n const target = attribute.target as UID.Schema | undefined;\n if (!target) {\n return;\n }\n\n return visitor(options, utils);\n },\n options,\n data\n );\n};\n\nconst mapRelationCurried = curry(mapRelation);\nconst traverseEntityRelationsCurried = curry(traverseEntityRelations);\n\nexport {\n mapRelationCurried as mapRelation,\n traverseEntityRelationsCurried as traverseEntityRelations,\n};\n"],"names":["isNil","async","isObject","traverseEntity","options","curry"],"mappings":";;;;AAQA,MAAM,YAAY,CAAC,UAAgC;AAC7C,MAAA,MAAM,QAAQ,KAAK;AAAU,WAAA;AAC3B,QAAA,SAAS,SAAS,OAAO,EAAE;AAC1B,SAAA,CAAC,OAAO,MAAM,MAAM;AAC7B;AAEA,MAAM,UAAU,CAAC,UAAe;AAE9B,MAAIA,GAAAA,MAAM,KAAK;AAAU,WAAA;AACrB,MAAA,MAAM,QAAQ,KAAK;AAAU,WAAA;AAEjC,SAAO,CAAC,KAAK;AACf;AAkBA,MAAM,cAAc,OAClB,UACA,KACA,cAAc,UACQ;AACtB,MAAI,WAAqB;AAEnB,QAAA,YAAY,CAAC,UAAe;AAEhC,QAAI,aAAa;AACR,aAAA;AAAA,IACT;AACA,WAAO,EAAE,KAAK,QAAQ,KAAK,EAAE;AAAA,EAAA;AAI3B,MAAAA,GAAAA,MAAM,QAAQ,GAAG;AACnB,WAAO,SAAS,QAAQ;AAAA,EAC1B;AAGI,MAAA,MAAM,QAAQ,QAAQ,GAAG;AACpB,WAAAC,YAAA,MACJ,IAAI,UAAU,CAAC,MAAgB,YAAY,UAAU,GAAG,IAAI,CAAC,EAC7D,KAAK,CAAC,WAAgB,OAAO,OAAO,OAAO,OAAO,CAAC,EACnD,KAAK,SAAS;AAAA,EACnB;AAGI,MAAAC,GAAAA,SAAS,QAAQ,GAAG;AAElB,QAAA,QAAQ,YAAY,gBAAgB,UAAU;AAC1C,YAAA,SAAS,MAAM,SAAS,QAAQ;AACtC,aAAO,UAAU,MAAM;AAAA,IACzB;AAGI,QAAA,CAAC,SAAS,OAAO,CAAC,SAAS,cAAc,CAAC,SAAS,SAAS;AAC9D,aAAO,SAAS,QAAQ;AAAA,IAC1B;AAGA,QAAI,SAA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ations/utils/map-relation.ts"],"sourcesContent":["/* eslint-disable node/no-callback-literal */\nimport { isObject, curry, isNil } from 'lodash/fp';\n\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 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":";;;;AAOA,MAAM,YAAY,CAAC,UAAgC;AAC7C,MAAA,MAAM,QAAQ,KAAK;AAAU,WAAA;AAC3B,QAAA,SAAS,SAAS,OAAO,EAAE;AAC1B,SAAA,CAAC,OAAO,MAAM,MAAM;AAC7B;AAEA,MAAM,UAAU,CAAC,UAAe;AAE9B,MAAIA,GAAAA,MAAM,KAAK;AAAU,WAAA;AACrB,MAAA,MAAM,QAAQ,KAAK;AAAU,WAAA;AAEjC,SAAO,CAAC,KAAK;AACf;AAkBA,MAAM,cAAc,OAClB,UACA,KACA,cAAc,UACQ;AACtB,MAAI,WAAqB;AAEnB,QAAA,YAAY,CAAC,UAAe;AAEhC,QAAI,aAAa;AACR,aAAA;AAAA,IACT;AACA,W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A;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;AAEO,aAAA,QAAQA,UAAS,KAAK;AAAA,IAC/B;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEJ;AAEM,MAAA,qBAAqBC,SAAM,WAAW;AACtC,MAAA,iCAAiCA,SAAM,uBAAuB;;;"}
@@ -72,10 +72,6 @@ const traverseEntityRelations = async (visitor, options, data) => {
72
72
  if (attribute.useJoinTable === false) {
73
73
  return;
74
74
  }
75
- const target = attribute.target;
76
- if (!target) {
77
- return;
78
- }
79
75
  return visitor(options2, utils);
80
76
  },
81
77
  options,
@@ -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 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,YAAY,gBAAgB,UAAU;AAC1C,YAAA,SAAS,MAAM,SAAS,QAAQ;AACtC,aAAO,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AA;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 { 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 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":";;AAOA,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,UAC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,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;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;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 +1 @@
1
- {"version":3,"file":"populate.d.ts","sourceRoot":"","sources":["../../../../src/services/document-service/utils/populate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAGpC,UAAU,OAAO;IACf;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC7B;AAGD,eAAO,MAAM,eAAe,QAAS,IAAI,MAAM,SAAQ,OAAO,QAoD7D,CAAC"}
1
+ {"version":3,"file":"populate.d.ts","sourceRoot":"","sources":["../../../../src/services/document-service/utils/populate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAGpC,UAAU,OAAO;IACf;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC7B;AAKD,eAAO,MAAM,eAAe,QAAS,IAAI,MAAM,SAAQ,OAAO,QAwD7D,CAAC"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const strapiUtils = require("@strapi/utils");
4
+ const { CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE } = strapiUtils.contentTypes.constants;
4
5
  const getDeepPopulate = (uid, opts = {}) => {
5
6
  const model = strapi.getModel(uid);
6
7
  const attributes = Object.entries(model.attributes);
@@ -12,13 +13,14 @@ const getDeepPopulate = (uid, opts = {}) => {
12
13
  break;
13
14
  }
14
15
  const isVisible = strapiUtils.contentTypes.isVisibleAttribute(model, attributeName);
15
- if (isVisible) {
16
+ const isCreatorField = [CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE].includes(attributeName);
17
+ if (isVisible || isCreatorField) {
16
18
  acc[attributeName] = { select: opts.relationalFields };
17
19
  }
18
20
  break;
19
21
  }
20
22
  case "media": {
21
- acc[attributeName] = { select: ["id"] };
23
+ acc[attributeName] = { select: ["*"] };
22
24
  break;
23
25
  }
24
26
  case "component": {
@@ -1 +1 @@
1
- {"version":3,"file":"populate.js","sources":["../../../../src/services/document-service/utils/populate.ts"],"sourcesContent":["import { UID } from '@strapi/types';\nimport { contentTypes } from '@strapi/utils';\n\ninterface Options {\n /**\n * Fields to select when populating relations\n */\n relationalFields?: string[];\n}\n\n// We want to build a populate object based on the schema\nexport const getDeepPopulate = (uid: UID.Schema, opts: Options = {}) => {\n const model = strapi.getModel(uid);\n const attributes = Object.entries(model.attributes);\n\n return attributes.reduce((acc: any, [attributeName, attribute]) => {\n switch (attribute.type) {\n case 'relation': {\n // TODO: Support polymorphic relations\n const isMorphRelation = attribute.relation.toLowerCase().startsWith('morph');\n if (isMorphRelation) {\n break;\n }\n\n // TODO: Should this just be a plain list?\n // Ignore createdBy, updatedBy, ...\n const isVisible = contentTypes.isVisibleAttribute(model, attributeName);\n if (isVisible) {\n acc[attributeName] = { select: opts.relationalFields };\n }\n break;\n }\n\n case 'media': {\n acc[attributeName] = { select: ['id'] };\n break;\n }\n\n case 'component': {\n const populate = getDeepPopulate(attribute.component, opts);\n acc[attributeName] = { populate };\n break;\n }\n\n case 'dynamiczone': {\n // Use fragments to populate the dynamic zone components\n const populatedComponents = (attribute.components || []).reduce(\n (acc: any, componentUID: UID.Component) => {\n acc[componentUID] = { populate: getDeepPopulate(componentUID, opts) };\n return acc;\n },\n {}\n );\n\n acc[attributeName] = { on: populatedComponents };\n break;\n }\n default:\n break;\n }\n\n return acc;\n }, {});\n};\n"],"names":["contentTypes","acc"],"mappings":";;;AAWO,MAAM,kBAAkB,CAAC,KAAiB,OAAgB,OAAO;AAChE,QAAA,QAAQ,OAAO,SAAS,GAAG;AACjC,QAAM,aAAa,OAAO,QAAQ,MAAM,UAAU;AAElD,SAAO,WAAW,OAAO,CAAC,KAAU,CAAC,eAAe,SAAS,MAAM;AACjE,YAAQ,UAAU,MAAM;AAAA,MACtB,KAAK,YAAY;AAEf,cAAM,kBAAkB,UAAU,SAAS,YAAY,EAAE,WAAW,OAAO;AAC3E,YAAI,iBAAiB;AACnB;AAAA,QACF;AAIA,cAAM,YAAYA,YAAA,aAAa,mBAAmB,OAAO,aAAa;AACtE,YAAI,WAAW;AACb,cAAI,aAAa,IAAI,EAAE,QAAQ,KAAK,iBAAiB;AAAA,QACvD;AACA;AAAA,MACF;AAAA,MAEA,KAAK,SAAS;AACZ,YAAI,aAAa,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE;AACtC;AAAA,MACF;AAAA,MAEA,KAAK,aAAa;AAChB,cAAM,WAAW,gBAAgB,UAAU,WAAW,IAAI;AACtD,YAAA,aAAa,IAAI,EAAE;AACvB;AAAA,MACF;AAAA,MAEA,KAAK,eAAe;AAElB,cAAM,uBAAuB,UAAU,cAAc,CAAI,GAAA;AAAA,UACvD,CAACC,MAAU,iBAAgC;AACzCA,iBAAI,YAAY,IAAI,EAAE,UAAU,gBAAgB,cAAc,IAAI;AAC3DA,mBAAAA;AAAAA,UACT;AAAA,UACA,CAAC;AAAA,QAAA;AAGH,YAAI,aAAa,IAAI,EAAE,IAAI,oBAAoB;AAC/C;AAAA,MACF;AAAA,IAGF;AAEO,WAAA;AAAA,EACT,GAAG,CAAE,CAAA;AACP;;"}
1
+ {"version":3,"file":"populate.js","sources":["../../../../src/services/document-service/utils/populate.ts"],"sourcesContent":["import { UID } from '@strapi/types';\nimport { contentTypes } from '@strapi/utils';\n\ninterface Options {\n /**\n * Fields to select when populating relations\n */\n relationalFields?: string[];\n}\n\nconst { CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE } = contentTypes.constants;\n\n// We want to build a populate object based on the schema\nexport const getDeepPopulate = (uid: UID.Schema, opts: Options = {}) => {\n const model = strapi.getModel(uid);\n const attributes = Object.entries(model.attributes);\n\n return attributes.reduce((acc: any, [attributeName, attribute]) => {\n switch (attribute.type) {\n case 'relation': {\n // TODO: Support polymorphic relations\n const isMorphRelation = attribute.relation.toLowerCase().startsWith('morph');\n if (isMorphRelation) {\n break;\n }\n\n // Ignore not visible fields other than createdBy and updatedBy\n const isVisible = contentTypes.isVisibleAttribute(model, attributeName);\n const isCreatorField = [CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE].includes(attributeName);\n\n if (isVisible || isCreatorField) {\n acc[attributeName] = { select: opts.relationalFields };\n }\n\n break;\n }\n\n case 'media': {\n // We populate all media fields for completeness of webhook responses\n // see https://github.com/strapi/strapi/issues/21546\n acc[attributeName] = { select: ['*'] };\n break;\n }\n\n case 'component': {\n const populate = getDeepPopulate(attribute.component, opts);\n acc[attributeName] = { populate };\n break;\n }\n\n case 'dynamiczone': {\n // Use fragments to populate the dynamic zone components\n const populatedComponents = (attribute.components || []).reduce(\n (acc: any, componentUID: UID.Component) => {\n acc[componentUID] = { populate: getDeepPopulate(componentUID, opts) };\n return acc;\n },\n {}\n );\n\n acc[attributeName] = { on: populatedComponents };\n break;\n }\n default:\n break;\n }\n\n return acc;\n }, {});\n};\n"],"names":["contentTypes","acc"],"mappings":";;;AAUA,MAAM,EAAE,sBAAsB,yBAAyBA,YAAAA,aAAa;AAG7D,MAAM,kBAAkB,CAAC,KAAi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const model = strapi.getModel(uid);
4
5
  const attributes = Object.entries(model.attributes);
@@ -10,13 +11,14 @@ const getDeepPopulate = (uid, opts = {}) => {
10
11
  break;
11
12
  }
12
13
  const isVisible = contentTypes.isVisibleAttribute(model, attributeName);
13
- if (isVisible) {
14
+ const isCreatorField = [CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE].includes(attributeName);
15
+ if (isVisible || isCreatorField) {
14
16
  acc[attributeName] = { select: opts.relationalFields };
15
17
  }
16
18
  break;
17
19
  }
18
20
  case "media": {
19
- acc[attributeName] = { select: ["id"] };
21
+ acc[attributeName] = { select: ["*"] };
20
22
  break;
21
23
  }
22
24
  case "component": {