@strapi/core 0.0.0-experimental.74c69aeafc770d59d5b3d5d37cd249934ef395ba → 0.0.0-experimental.76999222c105ee5da1bc2540e3b5e5f57747300c

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

Potentially problematic release.


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

Files changed (358) hide show
  1. package/LICENSE +18 -3
  2. package/dist/Strapi.d.ts +3 -1
  3. package/dist/Strapi.d.ts.map +1 -1
  4. package/dist/Strapi.js +59 -15
  5. package/dist/Strapi.js.map +1 -1
  6. package/dist/Strapi.mjs +38 -13
  7. package/dist/Strapi.mjs.map +1 -1
  8. package/dist/configuration/get-dirs.js +2 -2
  9. package/dist/configuration/get-dirs.js.map +1 -1
  10. package/dist/configuration/index.js +2 -2
  11. package/dist/configuration/index.js.map +1 -1
  12. package/dist/core-api/controller/collection-type.d.ts.map +1 -1
  13. package/dist/core-api/controller/collection-type.js +6 -3
  14. package/dist/core-api/controller/collection-type.js.map +1 -1
  15. package/dist/core-api/controller/collection-type.mjs +3 -0
  16. package/dist/core-api/controller/collection-type.mjs.map +1 -1
  17. package/dist/core-api/controller/index.js +2 -2
  18. package/dist/core-api/controller/index.js.map +1 -1
  19. package/dist/core-api/controller/single-type.d.ts.map +1 -1
  20. package/dist/core-api/controller/single-type.js +3 -2
  21. package/dist/core-api/controller/single-type.js.map +1 -1
  22. package/dist/core-api/controller/single-type.mjs +1 -0
  23. package/dist/core-api/controller/single-type.mjs.map +1 -1
  24. package/dist/core-api/controller/transform.js +8 -8
  25. package/dist/core-api/controller/transform.js.map +1 -1
  26. package/dist/core-api/routes/index.d.ts.map +1 -1
  27. package/dist/core-api/service/collection-type.d.ts +3 -9
  28. package/dist/core-api/service/collection-type.d.ts.map +1 -1
  29. package/dist/core-api/service/collection-type.js +5 -3
  30. package/dist/core-api/service/collection-type.js.map +1 -1
  31. package/dist/core-api/service/collection-type.mjs +6 -4
  32. package/dist/core-api/service/collection-type.mjs.map +1 -1
  33. package/dist/core-api/service/pagination.d.ts +4 -11
  34. package/dist/core-api/service/pagination.d.ts.map +1 -1
  35. package/dist/core-api/service/pagination.js +18 -44
  36. package/dist/core-api/service/pagination.js.map +1 -1
  37. package/dist/core-api/service/pagination.mjs +16 -42
  38. package/dist/core-api/service/pagination.mjs.map +1 -1
  39. package/dist/core-api/service/single-type.d.ts.map +1 -1
  40. package/dist/core-api/service/single-type.js +2 -1
  41. package/dist/core-api/service/single-type.js.map +1 -1
  42. package/dist/core-api/service/single-type.mjs +2 -1
  43. package/dist/core-api/service/single-type.mjs.map +1 -1
  44. package/dist/domain/content-type/index.js +4 -4
  45. package/dist/domain/content-type/index.js.map +1 -1
  46. package/dist/ee/index.d.ts.map +1 -1
  47. package/dist/ee/index.js +9 -4
  48. package/dist/ee/index.js.map +1 -1
  49. package/dist/ee/index.mjs +6 -1
  50. package/dist/ee/index.mjs.map +1 -1
  51. package/dist/ee/license.d.ts.map +1 -1
  52. package/dist/ee/license.js +2 -1
  53. package/dist/ee/license.js.map +1 -1
  54. package/dist/ee/license.mjs +2 -1
  55. package/dist/ee/license.mjs.map +1 -1
  56. package/dist/factories.d.ts +2 -2
  57. package/dist/factories.d.ts.map +1 -1
  58. package/dist/factories.js +4 -4
  59. package/dist/factories.js.map +1 -1
  60. package/dist/factories.mjs.map +1 -1
  61. package/dist/index.d.ts +14 -0
  62. package/dist/index.d.ts.map +1 -1
  63. package/dist/index.js.map +1 -1
  64. package/dist/index.mjs.map +1 -1
  65. package/dist/loaders/apis.d.ts.map +1 -1
  66. package/dist/loaders/apis.js +12 -12
  67. package/dist/loaders/apis.js.map +1 -1
  68. package/dist/loaders/apis.mjs +10 -10
  69. package/dist/loaders/apis.mjs.map +1 -1
  70. package/dist/loaders/plugins/get-enabled-plugins.d.ts.map +1 -1
  71. package/dist/loaders/plugins/get-enabled-plugins.js +45 -17
  72. package/dist/loaders/plugins/get-enabled-plugins.js.map +1 -1
  73. package/dist/loaders/plugins/get-enabled-plugins.mjs +15 -9
  74. package/dist/loaders/plugins/get-enabled-plugins.mjs.map +1 -1
  75. package/dist/loaders/plugins/get-user-plugins-config.js +2 -2
  76. package/dist/loaders/plugins/get-user-plugins-config.js.map +1 -1
  77. package/dist/loaders/plugins/index.d.ts.map +1 -1
  78. package/dist/loaders/plugins/index.js +34 -7
  79. package/dist/loaders/plugins/index.js.map +1 -1
  80. package/dist/loaders/plugins/index.mjs +9 -1
  81. package/dist/loaders/plugins/index.mjs.map +1 -1
  82. package/dist/middlewares/body.js +2 -2
  83. package/dist/middlewares/body.js.map +1 -1
  84. package/dist/middlewares/cors.d.ts.map +1 -1
  85. package/dist/middlewares/cors.js +9 -7
  86. package/dist/middlewares/cors.js.map +1 -1
  87. package/dist/middlewares/cors.mjs +9 -7
  88. package/dist/middlewares/cors.mjs.map +1 -1
  89. package/dist/middlewares/public.js +2 -2
  90. package/dist/middlewares/public.js.map +1 -1
  91. package/dist/middlewares/query.d.ts.map +1 -1
  92. package/dist/middlewares/query.js.map +1 -1
  93. package/dist/middlewares/query.mjs.map +1 -1
  94. package/dist/middlewares/responses.js +2 -2
  95. package/dist/middlewares/responses.js.map +1 -1
  96. package/dist/middlewares/security.d.ts.map +1 -1
  97. package/dist/middlewares/security.js +12 -5
  98. package/dist/middlewares/security.js.map +1 -1
  99. package/dist/middlewares/security.mjs +11 -4
  100. package/dist/middlewares/security.mjs.map +1 -1
  101. package/dist/middlewares/session.js +2 -2
  102. package/dist/middlewares/session.js.map +1 -1
  103. package/dist/migrations/database/5.0.0-discard-drafts.d.ts +33 -0
  104. package/dist/migrations/database/5.0.0-discard-drafts.d.ts.map +1 -0
  105. package/dist/migrations/database/5.0.0-discard-drafts.js +106 -0
  106. package/dist/migrations/database/5.0.0-discard-drafts.js.map +1 -0
  107. package/dist/migrations/database/5.0.0-discard-drafts.mjs +106 -0
  108. package/dist/migrations/database/5.0.0-discard-drafts.mjs.map +1 -0
  109. package/dist/migrations/draft-publish.d.ts +1 -1
  110. package/dist/migrations/draft-publish.d.ts.map +1 -1
  111. package/dist/migrations/draft-publish.js +14 -31
  112. package/dist/migrations/draft-publish.js.map +1 -1
  113. package/dist/migrations/draft-publish.mjs +15 -32
  114. package/dist/migrations/draft-publish.mjs.map +1 -1
  115. package/dist/migrations/i18n.d.ts +5 -0
  116. package/dist/migrations/i18n.d.ts.map +1 -0
  117. package/dist/migrations/i18n.js +54 -0
  118. package/dist/migrations/i18n.js.map +1 -0
  119. package/dist/migrations/i18n.mjs +54 -0
  120. package/dist/migrations/i18n.mjs.map +1 -0
  121. package/dist/migrations/index.d.ts +5 -0
  122. package/dist/migrations/index.d.ts.map +1 -0
  123. package/dist/migrations/index.js +15 -0
  124. package/dist/migrations/index.js.map +1 -0
  125. package/dist/migrations/index.mjs +15 -0
  126. package/dist/migrations/index.mjs.map +1 -0
  127. package/dist/providers/admin.d.ts.map +1 -1
  128. package/dist/providers/admin.js.map +1 -1
  129. package/dist/providers/admin.mjs.map +1 -1
  130. package/dist/providers/registries.d.ts.map +1 -1
  131. package/dist/providers/registries.js +5 -3
  132. package/dist/providers/registries.js.map +1 -1
  133. package/dist/providers/registries.mjs +5 -3
  134. package/dist/providers/registries.mjs.map +1 -1
  135. package/dist/registries/apis.js +2 -2
  136. package/dist/registries/apis.js.map +1 -1
  137. package/dist/registries/components.js +2 -2
  138. package/dist/registries/components.js.map +1 -1
  139. package/dist/registries/content-types.js +3 -3
  140. package/dist/registries/content-types.js.map +1 -1
  141. package/dist/registries/controllers.js +3 -3
  142. package/dist/registries/controllers.js.map +1 -1
  143. package/dist/registries/custom-fields.js +4 -4
  144. package/dist/registries/custom-fields.js.map +1 -1
  145. package/dist/registries/hooks.js +2 -2
  146. package/dist/registries/hooks.js.map +1 -1
  147. package/dist/registries/middlewares.js +3 -3
  148. package/dist/registries/middlewares.js.map +1 -1
  149. package/dist/registries/modules.js +3 -3
  150. package/dist/registries/modules.js.map +1 -1
  151. package/dist/registries/plugins.js +2 -2
  152. package/dist/registries/plugins.js.map +1 -1
  153. package/dist/registries/policies.d.ts +1 -1
  154. package/dist/registries/policies.d.ts.map +1 -1
  155. package/dist/registries/policies.js +5 -5
  156. package/dist/registries/policies.js.map +1 -1
  157. package/dist/registries/policies.mjs +1 -1
  158. package/dist/registries/policies.mjs.map +1 -1
  159. package/dist/registries/services.js +3 -3
  160. package/dist/registries/services.js.map +1 -1
  161. package/dist/services/auth/index.js +3 -3
  162. package/dist/services/auth/index.js.map +1 -1
  163. package/dist/services/content-api/index.d.ts +10 -12
  164. package/dist/services/content-api/index.d.ts.map +1 -1
  165. package/dist/services/content-api/permissions/index.d.ts +10 -12
  166. package/dist/services/content-api/permissions/index.d.ts.map +1 -1
  167. package/dist/services/content-api/permissions/providers/action.d.ts +5 -6
  168. package/dist/services/content-api/permissions/providers/action.d.ts.map +1 -1
  169. package/dist/services/content-api/permissions/providers/condition.d.ts +5 -6
  170. package/dist/services/content-api/permissions/providers/condition.d.ts.map +1 -1
  171. package/dist/services/core-store.d.ts.map +1 -1
  172. package/dist/services/core-store.js +3 -3
  173. package/dist/services/core-store.js.map +1 -1
  174. package/dist/services/cron.d.ts +3 -3
  175. package/dist/services/cron.d.ts.map +1 -1
  176. package/dist/services/cron.js +12 -7
  177. package/dist/services/cron.js.map +1 -1
  178. package/dist/services/cron.mjs +9 -4
  179. package/dist/services/cron.mjs.map +1 -1
  180. package/dist/services/document-service/attributes/index.d.ts +4 -4
  181. package/dist/services/document-service/attributes/index.d.ts.map +1 -1
  182. package/dist/services/document-service/attributes/index.js +5 -5
  183. package/dist/services/document-service/attributes/index.js.map +1 -1
  184. package/dist/services/document-service/attributes/index.mjs +5 -5
  185. package/dist/services/document-service/attributes/index.mjs.map +1 -1
  186. package/dist/services/document-service/attributes/transforms.js +3 -3
  187. package/dist/services/document-service/attributes/transforms.js.map +1 -1
  188. package/dist/services/document-service/common.d.ts +1 -1
  189. package/dist/services/document-service/common.d.ts.map +1 -1
  190. package/dist/services/document-service/common.js.map +1 -1
  191. package/dist/services/document-service/common.mjs.map +1 -1
  192. package/dist/services/document-service/components.d.ts +8 -80
  193. package/dist/services/document-service/components.d.ts.map +1 -1
  194. package/dist/services/document-service/components.js +29 -30
  195. package/dist/services/document-service/components.js.map +1 -1
  196. package/dist/services/document-service/components.mjs +19 -20
  197. package/dist/services/document-service/components.mjs.map +1 -1
  198. package/dist/services/document-service/draft-and-publish.js +16 -16
  199. package/dist/services/document-service/draft-and-publish.js.map +1 -1
  200. package/dist/services/document-service/entries.d.ts +5 -3
  201. package/dist/services/document-service/entries.d.ts.map +1 -1
  202. package/dist/services/document-service/entries.js +52 -19
  203. package/dist/services/document-service/entries.js.map +1 -1
  204. package/dist/services/document-service/entries.mjs +45 -12
  205. package/dist/services/document-service/entries.mjs.map +1 -1
  206. package/dist/services/document-service/events.d.ts +25 -0
  207. package/dist/services/document-service/events.d.ts.map +1 -0
  208. package/dist/services/document-service/events.js +47 -0
  209. package/dist/services/document-service/events.js.map +1 -0
  210. package/dist/services/document-service/events.mjs +47 -0
  211. package/dist/services/document-service/events.mjs.map +1 -0
  212. package/dist/services/document-service/index.d.ts +2 -1
  213. package/dist/services/document-service/index.d.ts.map +1 -1
  214. package/dist/services/document-service/index.js +12 -4
  215. package/dist/services/document-service/index.js.map +1 -1
  216. package/dist/services/document-service/index.mjs +12 -4
  217. package/dist/services/document-service/index.mjs.map +1 -1
  218. package/dist/services/document-service/internationalization.d.ts.map +1 -1
  219. package/dist/services/document-service/internationalization.js +21 -12
  220. package/dist/services/document-service/internationalization.js.map +1 -1
  221. package/dist/services/document-service/internationalization.mjs +14 -5
  222. package/dist/services/document-service/internationalization.mjs.map +1 -1
  223. package/dist/services/document-service/middlewares/middleware-manager.d.ts +5 -2
  224. package/dist/services/document-service/middlewares/middleware-manager.d.ts.map +1 -1
  225. package/dist/services/document-service/middlewares/middleware-manager.js +6 -3
  226. package/dist/services/document-service/middlewares/middleware-manager.js.map +1 -1
  227. package/dist/services/document-service/middlewares/middleware-manager.mjs +6 -3
  228. package/dist/services/document-service/middlewares/middleware-manager.mjs.map +1 -1
  229. package/dist/services/document-service/params.d.ts +1 -5
  230. package/dist/services/document-service/params.d.ts.map +1 -1
  231. package/dist/services/document-service/params.js +2 -2
  232. package/dist/services/document-service/params.js.map +1 -1
  233. package/dist/services/document-service/repository.d.ts.map +1 -1
  234. package/dist/services/document-service/repository.js +139 -86
  235. package/dist/services/document-service/repository.js.map +1 -1
  236. package/dist/services/document-service/repository.mjs +129 -76
  237. package/dist/services/document-service/repository.mjs.map +1 -1
  238. package/dist/services/document-service/transform/id-map.d.ts.map +1 -1
  239. package/dist/services/document-service/transform/id-map.js +13 -4
  240. package/dist/services/document-service/transform/id-map.js.map +1 -1
  241. package/dist/services/document-service/transform/id-map.mjs +14 -5
  242. package/dist/services/document-service/transform/id-map.mjs.map +1 -1
  243. package/dist/services/document-service/transform/id-transform.js +2 -2
  244. package/dist/services/document-service/transform/id-transform.js.map +1 -1
  245. package/dist/services/document-service/transform/query.js +3 -3
  246. package/dist/services/document-service/transform/query.js.map +1 -1
  247. package/dist/services/document-service/transform/relations/extract/data-ids.d.ts.map +1 -1
  248. package/dist/services/document-service/transform/relations/extract/data-ids.js +5 -2
  249. package/dist/services/document-service/transform/relations/extract/data-ids.js.map +1 -1
  250. package/dist/services/document-service/transform/relations/extract/data-ids.mjs +3 -0
  251. package/dist/services/document-service/transform/relations/extract/data-ids.mjs.map +1 -1
  252. package/dist/services/document-service/transform/relations/transform/data-ids.d.ts.map +1 -1
  253. package/dist/services/document-service/transform/relations/transform/data-ids.js +5 -2
  254. package/dist/services/document-service/transform/relations/transform/data-ids.js.map +1 -1
  255. package/dist/services/document-service/transform/relations/transform/data-ids.mjs +3 -0
  256. package/dist/services/document-service/transform/relations/transform/data-ids.mjs.map +1 -1
  257. package/dist/services/document-service/transform/relations/utils/dp.js +2 -2
  258. package/dist/services/document-service/transform/relations/utils/dp.js.map +1 -1
  259. package/dist/services/document-service/transform/relations/utils/map-relation.d.ts.map +1 -1
  260. package/dist/services/document-service/transform/relations/utils/map-relation.js +13 -9
  261. package/dist/services/document-service/transform/relations/utils/map-relation.js.map +1 -1
  262. package/dist/services/document-service/transform/relations/utils/map-relation.mjs +7 -3
  263. package/dist/services/document-service/transform/relations/utils/map-relation.mjs.map +1 -1
  264. package/dist/services/document-service/utils/populate.d.ts.map +1 -1
  265. package/dist/services/document-service/utils/populate.js +7 -1
  266. package/dist/services/document-service/utils/populate.js.map +1 -1
  267. package/dist/services/document-service/utils/populate.mjs +7 -1
  268. package/dist/services/document-service/utils/populate.mjs.map +1 -1
  269. package/dist/services/document-service/utils/unidirectional-relations.d.ts +36 -0
  270. package/dist/services/document-service/utils/unidirectional-relations.d.ts.map +1 -0
  271. package/dist/services/document-service/utils/unidirectional-relations.js +69 -0
  272. package/dist/services/document-service/utils/unidirectional-relations.js.map +1 -0
  273. package/dist/services/document-service/utils/unidirectional-relations.mjs +69 -0
  274. package/dist/services/document-service/utils/unidirectional-relations.mjs.map +1 -0
  275. package/dist/services/entity-service/index.d.ts.map +1 -1
  276. package/dist/services/entity-validator/blocks-validator.d.ts +1 -2
  277. package/dist/services/entity-validator/blocks-validator.d.ts.map +1 -1
  278. package/dist/services/entity-validator/blocks-validator.js +4 -3
  279. package/dist/services/entity-validator/blocks-validator.js.map +1 -1
  280. package/dist/services/entity-validator/blocks-validator.mjs +3 -3
  281. package/dist/services/entity-validator/blocks-validator.mjs.map +1 -1
  282. package/dist/services/entity-validator/index.d.ts +15 -1
  283. package/dist/services/entity-validator/index.d.ts.map +1 -1
  284. package/dist/services/entity-validator/index.js +109 -53
  285. package/dist/services/entity-validator/index.js.map +1 -1
  286. package/dist/services/entity-validator/index.mjs +95 -39
  287. package/dist/services/entity-validator/index.mjs.map +1 -1
  288. package/dist/services/entity-validator/validators.d.ts +36 -25
  289. package/dist/services/entity-validator/validators.d.ts.map +1 -1
  290. package/dist/services/entity-validator/validators.js +148 -33
  291. package/dist/services/entity-validator/validators.js.map +1 -1
  292. package/dist/services/entity-validator/validators.mjs +140 -25
  293. package/dist/services/entity-validator/validators.mjs.map +1 -1
  294. package/dist/services/event-hub.d.ts +1 -0
  295. package/dist/services/event-hub.d.ts.map +1 -1
  296. package/dist/services/event-hub.js +9 -4
  297. package/dist/services/event-hub.js.map +1 -1
  298. package/dist/services/event-hub.mjs +9 -4
  299. package/dist/services/event-hub.mjs.map +1 -1
  300. package/dist/services/metrics/middleware.d.ts.map +1 -1
  301. package/dist/services/server/compose-endpoint.d.ts.map +1 -1
  302. package/dist/services/server/compose-endpoint.js +7 -7
  303. package/dist/services/server/compose-endpoint.js.map +1 -1
  304. package/dist/services/server/index.js +1 -1
  305. package/dist/services/server/index.js.map +1 -1
  306. package/dist/services/server/index.mjs +1 -1
  307. package/dist/services/server/index.mjs.map +1 -1
  308. package/dist/services/server/koa.d.ts.map +1 -1
  309. package/dist/services/server/koa.js +4 -4
  310. package/dist/services/server/koa.js.map +1 -1
  311. package/dist/services/server/koa.mjs +1 -1
  312. package/dist/services/server/koa.mjs.map +1 -1
  313. package/dist/services/server/middleware.js +3 -3
  314. package/dist/services/server/middleware.js.map +1 -1
  315. package/dist/services/server/routing.js +2 -2
  316. package/dist/services/server/routing.js.map +1 -1
  317. package/dist/services/utils/dynamic-zones.js +5 -5
  318. package/dist/services/utils/dynamic-zones.js.map +1 -1
  319. package/dist/services/webhook-runner.d.ts +2 -1
  320. package/dist/services/webhook-runner.d.ts.map +1 -1
  321. package/dist/services/webhook-runner.js.map +1 -1
  322. package/dist/services/webhook-runner.mjs.map +1 -1
  323. package/dist/services/webhook-store.d.ts +2 -8
  324. package/dist/services/webhook-store.d.ts.map +1 -1
  325. package/dist/services/webhook-store.js +9 -2
  326. package/dist/services/webhook-store.js.map +1 -1
  327. package/dist/services/webhook-store.mjs +9 -2
  328. package/dist/services/webhook-store.mjs.map +1 -1
  329. package/dist/utils/cron.js +3 -3
  330. package/dist/utils/cron.js.map +1 -1
  331. package/dist/utils/fetch.d.ts.map +1 -1
  332. package/dist/utils/fetch.js +4 -3
  333. package/dist/utils/fetch.js.map +1 -1
  334. package/dist/utils/fetch.mjs +4 -3
  335. package/dist/utils/fetch.mjs.map +1 -1
  336. package/dist/utils/filepath-to-prop-path.d.ts +1 -1
  337. package/dist/utils/filepath-to-prop-path.d.ts.map +1 -1
  338. package/dist/utils/filepath-to-prop-path.js +27 -6
  339. package/dist/utils/filepath-to-prop-path.js.map +1 -1
  340. package/dist/utils/filepath-to-prop-path.mjs +25 -5
  341. package/dist/utils/filepath-to-prop-path.mjs.map +1 -1
  342. package/dist/utils/is-initialized.js +3 -3
  343. package/dist/utils/is-initialized.js.map +1 -1
  344. package/dist/utils/load-files.d.ts.map +1 -1
  345. package/dist/utils/startup-logger.d.ts.map +1 -1
  346. package/dist/utils/startup-logger.js +4 -4
  347. package/dist/utils/startup-logger.js.map +1 -1
  348. package/dist/utils/startup-logger.mjs +3 -3
  349. package/dist/utils/startup-logger.mjs.map +1 -1
  350. package/dist/utils/transform-content-types-to-models.d.ts +327 -23
  351. package/dist/utils/transform-content-types-to-models.d.ts.map +1 -1
  352. package/dist/utils/transform-content-types-to-models.js +17 -4
  353. package/dist/utils/transform-content-types-to-models.js.map +1 -1
  354. package/dist/utils/transform-content-types-to-models.mjs +16 -3
  355. package/dist/utils/transform-content-types-to-models.mjs.map +1 -1
  356. package/package.json +28 -24
  357. package/dist/services/document-service/document-engine.d.ts +0 -2
  358. package/dist/services/document-service/document-engine.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"cron.mjs","sources":["../../src/services/cron.ts"],"sourcesContent":["import { Job } from 'node-schedule';\nimport { isFunction } from 'lodash/fp';\nimport type { Core } from '@strapi/types';\n\ninterface JobSpec {\n job: Job;\n options: string | number | Date;\n name: string | null;\n}\n\ntype TaskFn = ({ strapi }: { strapi: Core.Strapi }, ...args: unknown[]) => Promise<unknown>;\n\ntype Task =\n | TaskFn\n | {\n task: TaskFn;\n options: string;\n };\n\ninterface Tasks {\n [key: string]: Task;\n}\n\nconst createCronService = () => {\n let jobsSpecs: JobSpec[] = [];\n let running = false;\n\n return {\n add(tasks: Tasks = {}) {\n for (const taskExpression of Object.keys(tasks)) {\n const taskValue = tasks[taskExpression];\n\n let fn: TaskFn;\n let options: string | number | Date;\n let taskName: string | null;\n if (isFunction(taskValue)) {\n // don't use task name if key is the rule\n taskName = null;\n fn = taskValue.bind(tasks);\n options = taskExpression;\n } else if (isFunction(taskValue.task)) {\n // set task name if key is not the rule\n taskName = taskExpression;\n fn = taskValue.task.bind(taskValue);\n options = taskValue.options;\n } else {\n throw new Error(\n `Could not schedule a cron job for \"${taskExpression}\": no function found.`\n );\n }\n\n const fnWithStrapi = (...args: unknown[]) => fn({ strapi }, ...args);\n\n // const job = new Job(null, fnWithStrapi);\n const job = new Job(fnWithStrapi);\n jobsSpecs.push({ job, options, name: taskName });\n\n if (running) {\n job.schedule(options);\n }\n }\n return this;\n },\n\n remove(name: string) {\n if (!name) {\n throw new Error('You must provide a name to remove a cron job.');\n }\n\n jobsSpecs\n .filter(({ name: jobSpecName }) => jobSpecName === name)\n .forEach(({ job }) => job.cancel());\n\n jobsSpecs = jobsSpecs.filter(({ name: jobSpecName }) => jobSpecName !== name);\n return this;\n },\n\n start() {\n jobsSpecs.forEach(({ job, options }) => job.schedule(options));\n running = true;\n return this;\n },\n\n stop() {\n jobsSpecs.forEach(({ job }) => job.cancel());\n running = false;\n return this;\n },\n\n destroy() {\n this.stop();\n jobsSpecs = [];\n return this;\n },\n jobs: jobsSpecs,\n };\n};\n\nexport default createCronService;\n"],"names":[],"mappings":";;AAuBA,MAAM,oBAAoB,MAAM;AAC9B,MAAI,YAAuB,CAAA;AAC3B,MAAI,UAAU;AAEP,SAAA;AAAA,IACL,IAAI,QAAe,IAAI;AACrB,iBAAW,kBAAkB,OAAO,KAAK,KAAK,GAAG;AACzC,cAAA,YAAY,MAAM,cAAc;AAElC,YAAA;AACA,YAAA;AACA,YAAA;AACA,YAAA,WAAW,SAAS,GAAG;AAEd,qBAAA;AACN,eAAA,UAAU,KAAK,KAAK;AACf,oBAAA;AAAA,QACD,WAAA,WAAW,UAAU,IAAI,GAAG;AAE1B,qBAAA;AACN,eAAA,UAAU,KAAK,KAAK,SAAS;AAClC,oBAAU,UAAU;AAAA,QAAA,OACf;AACL,gBAAM,IAAI;AAAA,YACR,sCAAsC,cAAc;AAAA,UAAA;AAAA,QAExD;AAEM,cAAA,eAAe,IAAI,SAAoB,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI;AAG7D,cAAA,MAAM,IAAI,IAAI,YAAY;AAChC,kBAAU,KAAK,EAAE,KAAK,SAAS,MAAM,UAAU;AAE/C,YAAI,SAAS;AACX,cAAI,SAAS,OAAO;AAAA,QACtB;AAAA,MACF;AACO,aAAA;AAAA,IACT;AAAA,IAEA,OAAO,MAAc;AACnB,UAAI,CAAC,MAAM;AACH,cAAA,IAAI,MAAM,+CAA+C;AAAA,MACjE;AAEA,gBACG,OAAO,CAAC,EAAE,MAAM,YAAA,MAAkB,gBAAgB,IAAI,EACtD,QAAQ,CAAC,EAAE,IAAA,MAAU,IAAI,OAAQ,CAAA;AAExB,kBAAA,UAAU,OAAO,CAAC,EAAE,MAAM,YAAY,MAAM,gBAAgB,IAAI;AACrE,aAAA;AAAA,IACT;AAAA,IAEA,QAAQ;AACI,gBAAA,QAAQ,CAAC,EAAE,KAAK,QAAc,MAAA,IAAI,SAAS,OAAO,CAAC;AACnD,gBAAA;AACH,aAAA;AAAA,IACT;AAAA,IAEA,OAAO;AACL,gBAAU,QAAQ,CAAC,EAAE,IAAU,MAAA,IAAI,QAAQ;AACjC,gBAAA;AACH,aAAA;AAAA,IACT;AAAA,IAEA,UAAU;AACR,WAAK,KAAK;AACV,kBAAY,CAAA;AACL,aAAA;AAAA,IACT;AAAA,IACA,MAAM;AAAA,EAAA;AAEV;"}
1
+ {"version":3,"file":"cron.mjs","sources":["../../src/services/cron.ts"],"sourcesContent":["import { Job, Spec } from 'node-schedule';\nimport { isFunction } from 'lodash/fp';\nimport type { Core } from '@strapi/types';\n\ninterface JobSpec {\n job: Job;\n options: Spec;\n name: string | null;\n}\n\ntype TaskFn = ({ strapi }: { strapi: Core.Strapi }, ...args: unknown[]) => Promise<unknown>;\n\ntype Task =\n | TaskFn\n | {\n task: TaskFn;\n options: Spec;\n };\n\ninterface Tasks {\n [key: string]: Task;\n}\n\nconst createCronService = () => {\n let jobsSpecs: JobSpec[] = [];\n let running = false;\n\n return {\n add(tasks: Tasks = {}) {\n for (const taskExpression of Object.keys(tasks)) {\n const taskValue = tasks[taskExpression];\n\n let fn: TaskFn;\n let options: Spec;\n let taskName: string | null;\n if (isFunction(taskValue)) {\n // don't use task name if key is the rule\n taskName = null;\n fn = taskValue.bind(tasks);\n options = taskExpression;\n } else if (isFunction(taskValue.task)) {\n // set task name if key is not the rule\n taskName = taskExpression;\n fn = taskValue.task.bind(taskValue);\n options = taskValue.options;\n } else {\n throw new Error(\n `Could not schedule a cron job for \"${taskExpression}\": no function found.`\n );\n }\n\n const fnWithStrapi = (...args: unknown[]) => fn({ strapi }, ...args);\n\n // const job = new Job(null, fnWithStrapi);\n const job = new Job(fnWithStrapi);\n jobsSpecs.push({ job, options, name: taskName });\n\n if (running) {\n job.schedule(options);\n }\n }\n return this;\n },\n\n remove(name: string) {\n if (!name) throw new Error('You must provide a name to remove a cron job.');\n const matchingJobsSpecs = jobsSpecs.filter(({ name: jobSpecName }, index) => {\n if (jobSpecName === name) {\n jobsSpecs.splice(index, 1);\n return true;\n }\n return false;\n });\n matchingJobsSpecs.forEach(({ job }) => job.cancel());\n return this;\n },\n\n start() {\n jobsSpecs.forEach(({ job, options }) => job.schedule(options));\n running = true;\n return this;\n },\n\n stop() {\n jobsSpecs.forEach(({ job }) => job.cancel());\n running = false;\n return this;\n },\n\n destroy() {\n this.stop();\n jobsSpecs = [];\n return this;\n },\n jobs: jobsSpecs,\n };\n};\n\nexport default createCronService;\n"],"names":[],"mappings":";;AAuBA,MAAM,oBAAoB,MAAM;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AAI,QAAQ;AACjC,gBAAA;AACH,aAAA;AAAA,IACT;AAAA,IAEA,UAAU;AACR,WAAK,KAAK;AACV,kBAAY,CAAA;AACL,aAAA;AAAA,IACT;AAAA,IACA,MAAM;AAAA,EAAA;AAEV;"}
@@ -1,6 +1,6 @@
1
- import type { UID, Modules, Schema } from '@strapi/types';
2
- declare const applyTransforms: <TUID extends UID.ContentType>(data: Modules.EntityService.Params.Data.Input<TUID>, context: {
3
- contentType: Schema.ContentType<TUID>;
4
- }) => Modules.EntityService.Params.Data.Input<TUID>;
1
+ /// <reference types="lodash" />
2
+ import type { UID, Modules } from '@strapi/types';
3
+ type Data = Modules.Documents.Params.Data.Input<UID.Schema>;
4
+ declare const applyTransforms: import("lodash").CurriedFunction2<import("@strapi/types/dist/struct").ComponentSchema | import("@strapi/types/dist/struct").ContentTypeSchema, Data, Data>;
5
5
  export { applyTransforms };
6
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/services/document-service/attributes/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAG1D,QAAA,MAAM,eAAe;;mDA6BpB,CAAC;AAEF,OAAO,EAAE,eAAe,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/services/document-service/attributes/index.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,OAAO,EAAU,MAAM,eAAe,CAAC;AAK1D,KAAK,IAAI,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;AAE5D,QAAA,MAAM,eAAe,4JAsBnB,CAAC;AAEH,OAAO,EAAE,eAAe,EAAE,CAAC"}
@@ -1,22 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const fp = require("lodash/fp");
3
4
  const transforms = require("./transforms.js");
4
- const applyTransforms = (data, context) => {
5
- const { contentType } = context;
5
+ const applyTransforms = fp.curry((schema, data) => {
6
6
  const attributeNames = Object.keys(data);
7
7
  for (const attributeName of attributeNames) {
8
8
  const value = data[attributeName];
9
- const attribute = contentType.attributes[attributeName];
9
+ const attribute = schema.attributes[attributeName];
10
10
  if (!attribute) {
11
11
  continue;
12
12
  }
13
13
  const transform = transforms[attribute.type];
14
14
  if (transform) {
15
- const attributeContext = { ...context, attributeName, attribute };
15
+ const attributeContext = { attributeName, attribute };
16
16
  data[attributeName] = transform(value, attributeContext);
17
17
  }
18
18
  }
19
19
  return data;
20
- };
20
+ });
21
21
  exports.applyTransforms = applyTransforms;
22
22
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../../src/services/document-service/attributes/index.ts"],"sourcesContent":["import type { UID, Modules, Schema } from '@strapi/types';\nimport transforms from './transforms';\n\nconst applyTransforms = <TUID extends UID.ContentType>(\n data: Modules.EntityService.Params.Data.Input<TUID>,\n context: {\n contentType: Schema.ContentType<TUID>;\n }\n) => {\n const { contentType } = context;\n\n const attributeNames = Object.keys(data) as Array<keyof typeof data & string>;\n\n for (const attributeName of attributeNames) {\n const value = data[attributeName];\n\n const attribute = contentType.attributes[attributeName];\n\n if (!attribute) {\n continue;\n }\n\n const transform = transforms[attribute.type];\n\n if (transform) {\n const attributeContext = { ...context, attributeName, attribute };\n\n data[attributeName] = transform(value, attributeContext);\n }\n }\n\n return data;\n};\n\nexport { applyTransforms };\n"],"names":[],"mappings":";;;AAGM,MAAA,kBAAkB,CACtB,MACA,YAGG;AACG,QAAA,EAAE,YAAgB,IAAA;AAElB,QAAA,iBAAiB,OAAO,KAAK,IAAI;AAEvC,aAAW,iBAAiB,gBAAgB;AACpC,UAAA,QAAQ,KAAK,aAAa;AAE1B,UAAA,YAAY,YAAY,WAAW,aAAa;AAEtD,QAAI,CAAC,WAAW;AACd;AAAA,IACF;AAEM,UAAA,YAAY,WAAW,UAAU,IAAI;AAE3C,QAAI,WAAW;AACb,YAAM,mBAAmB,EAAE,GAAG,SAAS,eAAe,UAAU;AAEhE,WAAK,aAAa,IAAI,UAAU,OAAO,gBAAgB;AAAA,IACzD;AAAA,EACF;AAEO,SAAA;AACT;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../../src/services/document-service/attributes/index.ts"],"sourcesContent":["import { curry } from 'lodash/fp';\n\nimport type { UID, Modules, Schema } from '@strapi/types';\n\nimport transforms from './transforms';\n\n// aliasing the type to make it easier to read\ntype Data = Modules.Documents.Params.Data.Input<UID.Schema>;\n\nconst applyTransforms = curry((schema: Schema.Schema, data: Data) => {\n const attributeNames = Object.keys(data) as Array<keyof typeof data & string>;\n\n for (const attributeName of attributeNames) {\n const value = data[attributeName];\n\n const attribute = schema.attributes[attributeName];\n\n if (!attribute) {\n continue;\n }\n\n const transform = transforms[attribute.type];\n\n if (transform) {\n const attributeContext = { attributeName, attribute };\n\n data[attributeName] = transform(value, attributeContext);\n }\n }\n\n return data;\n});\n\nexport { applyTransforms };\n"],"names":["curry"],"mappings":";;;;AASA,MAAM,kBAAkBA,GAAA,MAAM,CAAC,QAAuB,SAAe;AAC7D,QAAA,iBAAiB,OAAO,KAAK,IAAI;AAEvC,aAAW,iBAAiB,gBAAgB;AACpC,UAAA,QAAQ,KAAK,aAAa;AAE1B,UAAA,YAAY,OAAO,WAAW,aAAa;AAEjD,QAAI,CAAC,WAAW;AACd;AAAA,IACF;AAEM,UAAA,YAAY,WAAW,UAAU,IAAI;AAE3C,QAAI,WAAW;AACP,YAAA,mBAAmB,EAAE,eAAe;AAE1C,WAAK,aAAa,IAAI,UAAU,OAAO,gBAAgB;AAAA,IACzD;AAAA,EACF;AAEO,SAAA;AACT,CAAC;;"}
@@ -1,21 +1,21 @@
1
+ import { curry } from "lodash/fp";
1
2
  import transforms from "./transforms.mjs";
2
- const applyTransforms = (data, context) => {
3
- const { contentType } = context;
3
+ const applyTransforms = curry((schema, data) => {
4
4
  const attributeNames = Object.keys(data);
5
5
  for (const attributeName of attributeNames) {
6
6
  const value = data[attributeName];
7
- const attribute = contentType.attributes[attributeName];
7
+ const attribute = schema.attributes[attributeName];
8
8
  if (!attribute) {
9
9
  continue;
10
10
  }
11
11
  const transform = transforms[attribute.type];
12
12
  if (transform) {
13
- const attributeContext = { ...context, attributeName, attribute };
13
+ const attributeContext = { attributeName, attribute };
14
14
  data[attributeName] = transform(value, attributeContext);
15
15
  }
16
16
  }
17
17
  return data;
18
- };
18
+ });
19
19
  export {
20
20
  applyTransforms
21
21
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../../../../src/services/document-service/attributes/index.ts"],"sourcesContent":["import type { UID, Modules, Schema } from '@strapi/types';\nimport transforms from './transforms';\n\nconst applyTransforms = <TUID extends UID.ContentType>(\n data: Modules.EntityService.Params.Data.Input<TUID>,\n context: {\n contentType: Schema.ContentType<TUID>;\n }\n) => {\n const { contentType } = context;\n\n const attributeNames = Object.keys(data) as Array<keyof typeof data & string>;\n\n for (const attributeName of attributeNames) {\n const value = data[attributeName];\n\n const attribute = contentType.attributes[attributeName];\n\n if (!attribute) {\n continue;\n }\n\n const transform = transforms[attribute.type];\n\n if (transform) {\n const attributeContext = { ...context, attributeName, attribute };\n\n data[attributeName] = transform(value, attributeContext);\n }\n }\n\n return data;\n};\n\nexport { applyTransforms };\n"],"names":[],"mappings":";AAGM,MAAA,kBAAkB,CACtB,MACA,YAGG;AACG,QAAA,EAAE,YAAgB,IAAA;AAElB,QAAA,iBAAiB,OAAO,KAAK,IAAI;AAEvC,aAAW,iBAAiB,gBAAgB;AACpC,UAAA,QAAQ,KAAK,aAAa;AAE1B,UAAA,YAAY,YAAY,WAAW,aAAa;AAEtD,QAAI,CAAC,WAAW;AACd;AAAA,IACF;AAEM,UAAA,YAAY,WAAW,UAAU,IAAI;AAE3C,QAAI,WAAW;AACb,YAAM,mBAAmB,EAAE,GAAG,SAAS,eAAe,UAAU;AAEhE,WAAK,aAAa,IAAI,UAAU,OAAO,gBAAgB;AAAA,IACzD;AAAA,EACF;AAEO,SAAA;AACT;"}
1
+ {"version":3,"file":"index.mjs","sources":["../../../../src/services/document-service/attributes/index.ts"],"sourcesContent":["import { curry } from 'lodash/fp';\n\nimport type { UID, Modules, Schema } from '@strapi/types';\n\nimport transforms from './transforms';\n\n// aliasing the type to make it easier to read\ntype Data = Modules.Documents.Params.Data.Input<UID.Schema>;\n\nconst applyTransforms = curry((schema: Schema.Schema, data: Data) => {\n const attributeNames = Object.keys(data) as Array<keyof typeof data & string>;\n\n for (const attributeName of attributeNames) {\n const value = data[attributeName];\n\n const attribute = schema.attributes[attributeName];\n\n if (!attribute) {\n continue;\n }\n\n const transform = transforms[attribute.type];\n\n if (transform) {\n const attributeContext = { attributeName, attribute };\n\n data[attributeName] = transform(value, attributeContext);\n }\n }\n\n return data;\n});\n\nexport { applyTransforms };\n"],"names":[],"mappings":";;AASA,MAAM,kBAAkB,MAAM,CAAC,QAAuB,SAAe;AAC7D,QAAA,iBAAiB,OAAO,KAAK,IAAI;AAEvC,aAAW,iBAAiB,gBAAgB;AACpC,UAAA,QAAQ,KAAK,aAAa;AAE1B,UAAA,YAAY,OAAO,WAAW,aAAa;AAEjD,QAAI,CAAC,WAAW;AACd;AAAA,IACF;AAEM,UAAA,YAAY,WAAW,UAAU,IAAI;AAE3C,QAAI,WAAW;AACP,YAAA,mBAAmB,EAAE,eAAe;AAE1C,WAAK,aAAa,IAAI,UAAU,OAAO,gBAAgB;AAAA,IACzD;AAAA,EACF;AAEO,SAAA;AACT,CAAC;"}
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- const _ = require("lodash/fp");
2
+ const fp = require("lodash/fp");
3
3
  const bcrypt = require("bcryptjs");
4
4
  const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
5
5
  const bcrypt__default = /* @__PURE__ */ _interopDefault(bcrypt);
@@ -9,10 +9,10 @@ const transforms = {
9
9
  if (attribute.type !== "password") {
10
10
  throw new Error("Invalid attribute type");
11
11
  }
12
- if (!_.isString(value) && !(value instanceof Buffer)) {
12
+ if (!fp.isString(value) && !(value instanceof Buffer)) {
13
13
  return value;
14
14
  }
15
- const rounds = _.toNumber(_.getOr(10, "encryption.rounds", attribute));
15
+ const rounds = fp.toNumber(fp.getOr(10, "encryption.rounds", attribute));
16
16
  return bcrypt__default.default.hashSync(value.toString(), rounds);
17
17
  }
18
18
  };
@@ -1 +1 @@
1
- {"version":3,"file":"transforms.js","sources":["../../../../src/services/document-service/attributes/transforms.ts"],"sourcesContent":["import { getOr, toNumber, isString } from 'lodash/fp';\nimport type { Schema } from '@strapi/types';\nimport bcrypt from 'bcryptjs';\n\ntype Transforms = {\n [TKind in Schema.Attribute.Kind]?: (\n value: unknown,\n context: {\n attribute: Schema.Attribute.AnyAttribute;\n attributeName: string;\n }\n ) => any;\n};\n\nconst transforms: Transforms = {\n password(value, context) {\n const { attribute } = context;\n\n if (attribute.type !== 'password') {\n throw new Error('Invalid attribute type');\n }\n\n if (!isString(value) && !(value instanceof Buffer)) {\n return value;\n }\n\n const rounds = toNumber(getOr(10, 'encryption.rounds', attribute));\n\n return bcrypt.hashSync(value.toString(), rounds);\n },\n};\n\nexport default transforms;\n"],"names":["isString","toNumber","getOr","bcrypt"],"mappings":";;;;;AAcA,MAAM,aAAyB;AAAA,EAC7B,SAAS,OAAO,SAAS;AACjB,UAAA,EAAE,UAAc,IAAA;AAElB,QAAA,UAAU,SAAS,YAAY;AAC3B,YAAA,IAAI,MAAM,wBAAwB;AAAA,IAC1C;AAEA,QAAI,CAACA,EAAS,SAAA,KAAK,KAAK,EAAE,iBAAiB,SAAS;AAC3C,aAAA;AAAA,IACT;AAEA,UAAM,SAASC,EAAAA,SAASC,EAAA,MAAM,IAAI,qBAAqB,SAAS,CAAC;AAEjE,WAAOC,gBAAAA,QAAO,SAAS,MAAM,YAAY,MAAM;AAAA,EACjD;AACF;;"}
1
+ {"version":3,"file":"transforms.js","sources":["../../../../src/services/document-service/attributes/transforms.ts"],"sourcesContent":["import { getOr, toNumber, isString } from 'lodash/fp';\nimport type { Schema } from '@strapi/types';\nimport bcrypt from 'bcryptjs';\n\ntype Transforms = {\n [TKind in Schema.Attribute.Kind]?: (\n value: unknown,\n context: {\n attribute: Schema.Attribute.AnyAttribute;\n attributeName: string;\n }\n ) => any;\n};\n\nconst transforms: Transforms = {\n password(value, context) {\n const { attribute } = context;\n\n if (attribute.type !== 'password') {\n throw new Error('Invalid attribute type');\n }\n\n if (!isString(value) && !(value instanceof Buffer)) {\n return value;\n }\n\n const rounds = toNumber(getOr(10, 'encryption.rounds', attribute));\n\n return bcrypt.hashSync(value.toString(), rounds);\n },\n};\n\nexport default transforms;\n"],"names":["isString","toNumber","getOr","bcrypt"],"mappings":";;;;;AAcA,MAAM,aAAyB;AAAA,EAC7B,SAAS,OAAO,SAAS;AACjB,UAAA,EAAE,UAAc,IAAA;AAElB,QAAA,UAAU,SAAS,YAAY;AAC3B,YAAA,IAAI,MAAM,wBAAwB;AAAA,IAC1C;AAEA,QAAI,CAACA,GAAS,SAAA,KAAK,KAAK,EAAE,iBAAiB,SAAS;AAC3C,aAAA;AAAA,IACT;AAEA,UAAM,SAASC,GAAAA,SAASC,GAAA,MAAM,IAAI,qBAAqB,SAAS,CAAC;AAEjE,WAAOC,gBAAAA,QAAO,SAAS,MAAM,YAAY,MAAM;AAAA,EACjD;AACF;;"}
@@ -1,4 +1,4 @@
1
1
  import type { UID, Modules } from '@strapi/types';
2
- export type RepositoryFactoryMethod = <TContentTypeUID extends UID.ContentType>(uid: TContentTypeUID) => Modules.Documents.ServiceInstance<TContentTypeUID>;
2
+ export type RepositoryFactoryMethod = <TContentTypeUID extends UID.ContentType>(uid: TContentTypeUID, entityValidator: Modules.EntityValidator.EntityValidator) => Modules.Documents.ServiceInstance<TContentTypeUID>;
3
3
  export declare const wrapInTransaction: (fn: (...args: any) => any) => (...args: any[]) => Promise<any>;
4
4
  //# sourceMappingURL=common.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/services/document-service/common.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAElD,MAAM,MAAM,uBAAuB,GAAG,CAAC,eAAe,SAAS,GAAG,CAAC,WAAW,EAC5E,GAAG,EAAE,eAAe,KACjB,OAAO,CAAC,SAAS,CAAC,eAAe,CAAC,eAAe,CAAC,CAAC;AAExD,eAAO,MAAM,iBAAiB,iBAAkB,GAAG,KAAK,GAAG,eACxC,GAAG,EAAE,iBACvB,CAAC"}
1
+ {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/services/document-service/common.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAElD,MAAM,MAAM,uBAAuB,GAAG,CAAC,eAAe,SAAS,GAAG,CAAC,WAAW,EAC5E,GAAG,EAAE,eAAe,EACpB,eAAe,EAAE,OAAO,CAAC,eAAe,CAAC,eAAe,KACrD,OAAO,CAAC,SAAS,CAAC,eAAe,CAAC,eAAe,CAAC,CAAC;AAExD,eAAO,MAAM,iBAAiB,OAAQ,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,GAAG,eACxC,GAAG,EAAE,iBACvB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"common.js","sources":["../../../src/services/document-service/common.ts"],"sourcesContent":["import type { UID, Modules } from '@strapi/types';\n\nexport type RepositoryFactoryMethod = <TContentTypeUID extends UID.ContentType>(\n uid: TContentTypeUID\n) => Modules.Documents.ServiceInstance<TContentTypeUID>;\n\nexport const wrapInTransaction = (fn: (...args: any) => any) => {\n return (...args: any[]) => strapi.db.transaction?.(() => fn(...args));\n};\n"],"names":[],"mappings":";;AAMa,MAAA,oBAAoB,CAAC,OAA8B;AACvD,SAAA,IAAI,SAAgB,OAAO,GAAG,cAAc,MAAM,GAAG,GAAG,IAAI,CAAC;AACtE;;"}
1
+ {"version":3,"file":"common.js","sources":["../../../src/services/document-service/common.ts"],"sourcesContent":["import type { UID, Modules } from '@strapi/types';\n\nexport type RepositoryFactoryMethod = <TContentTypeUID extends UID.ContentType>(\n uid: TContentTypeUID,\n entityValidator: Modules.EntityValidator.EntityValidator\n) => Modules.Documents.ServiceInstance<TContentTypeUID>;\n\nexport const wrapInTransaction = (fn: (...args: any) => any) => {\n return (...args: any[]) => strapi.db.transaction?.(() => fn(...args));\n};\n"],"names":[],"mappings":";;AAOa,MAAA,oBAAoB,CAAC,OAA8B;AACvD,SAAA,IAAI,SAAgB,OAAO,GAAG,cAAc,MAAM,GAAG,GAAG,IAAI,CAAC;AACtE;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"common.mjs","sources":["../../../src/services/document-service/common.ts"],"sourcesContent":["import type { UID, Modules } from '@strapi/types';\n\nexport type RepositoryFactoryMethod = <TContentTypeUID extends UID.ContentType>(\n uid: TContentTypeUID\n) => Modules.Documents.ServiceInstance<TContentTypeUID>;\n\nexport const wrapInTransaction = (fn: (...args: any) => any) => {\n return (...args: any[]) => strapi.db.transaction?.(() => fn(...args));\n};\n"],"names":[],"mappings":"AAMa,MAAA,oBAAoB,CAAC,OAA8B;AACvD,SAAA,IAAI,SAAgB,OAAO,GAAG,cAAc,MAAM,GAAG,GAAG,IAAI,CAAC;AACtE;"}
1
+ {"version":3,"file":"common.mjs","sources":["../../../src/services/document-service/common.ts"],"sourcesContent":["import type { UID, Modules } from '@strapi/types';\n\nexport type RepositoryFactoryMethod = <TContentTypeUID extends UID.ContentType>(\n uid: TContentTypeUID,\n entityValidator: Modules.EntityValidator.EntityValidator\n) => Modules.Documents.ServiceInstance<TContentTypeUID>;\n\nexport const wrapInTransaction = (fn: (...args: any) => any) => {\n return (...args: any[]) => strapi.db.transaction?.(() => fn(...args));\n};\n"],"names":[],"mappings":"AAOa,MAAA,oBAAoB,CAAC,OAA8B;AACvD,SAAA,IAAI,SAAgB,OAAO,GAAG,cAAc,MAAM,GAAG,GAAG,IAAI,CAAC;AACtE;"}
@@ -1,4 +1,6 @@
1
- import type { Struct, Utils, UID, Schema, Data, Modules } from '@strapi/types';
1
+ import _ from 'lodash';
2
+ import type { UID, Schema, Data, Modules } from '@strapi/types';
3
+ type Input<T extends UID.Schema> = Modules.Documents.Params.Data.Input<T>;
2
4
  type LoadedComponents<TUID extends UID.Schema> = Data.Entity<TUID, Schema.AttributeNamesByType<TUID, 'component' | 'dynamiczone'>>;
3
5
  type SingleComponentValue = Schema.Attribute.ComponentValue<UID.Component, false>;
4
6
  type RepeatableComponentValue = Schema.Attribute.ComponentValue<UID.Component, true>;
@@ -7,92 +9,18 @@ type DynamicZoneValue = Schema.Attribute.DynamicZoneValue<UID.Component[]>;
7
9
  type ComponentBody = {
8
10
  [key: string]: ComponentValue | DynamicZoneValue;
9
11
  };
10
- declare function omitComponentData(contentType: Struct.ContentTypeSchema, data: Modules.EntityService.Params.Data.Input<Struct.ContentTypeSchema['uid']>): Partial<Modules.EntityService.Params.Data.Input<Struct.ContentTypeSchema['uid']>>;
11
- declare function omitComponentData(contentType: Struct.ComponentSchema, data: Modules.EntityService.Params.Data.Input<Struct.ComponentSchema['uid']>): Partial<Modules.EntityService.Params.Data.Input<Struct.ComponentSchema['uid']>>;
12
- declare const createComponents: <TUID extends UID.Schema, TData extends Modules.EntityService.Params.Data.Input<TUID>>(uid: TUID, data: TData) => Promise<ComponentBody>;
12
+ declare const omitComponentData: _.CurriedFunction2<import("@strapi/types/dist/struct").ComponentSchema | import("@strapi/types/dist/struct").ContentTypeSchema, Input<UID.Schema>, Partial<Input<UID.Schema>>>;
13
+ declare const createComponents: <TUID extends UID.Schema, TData extends Input<TUID>>(uid: TUID, data: TData) => Promise<ComponentBody>;
13
14
  declare const getComponents: <TUID extends UID.Schema>(uid: TUID, entity: {
14
15
  id: Modules.EntityService.Params.Attribute.ID;
15
16
  }) => Promise<LoadedComponents<TUID>>;
16
- declare const updateComponents: <TUID extends UID.Schema, TData extends Partial<Modules.EntityService.Params.Data.Input<TUID>>>(uid: TUID, entityToUpdate: {
17
+ declare const updateComponents: <TUID extends UID.Schema, TData extends Partial<Input<TUID>>>(uid: TUID, entityToUpdate: {
17
18
  id: Modules.EntityService.Params.Attribute.ID;
18
19
  }, data: TData) => Promise<ComponentBody>;
19
20
  declare const deleteComponents: <TUID extends UID.Schema, TEntity extends Data.Entity<TUID, Extract<keyof Schema.Attributes<TUID>, string>>>(uid: TUID, entityToDelete: TEntity, { loadComponents }?: {
20
21
  loadComponents?: boolean | undefined;
21
22
  }) => Promise<void>;
22
- declare const deleteComponent: <TUID extends `${string}.${string}`>(uid: TUID, componentToDelete: {
23
- id: Data.ID;
24
- } & Pick<{ [TAttributeName in Extract<keyof Schema.Attributes<TUID>, string>]?: Utils.If<Utils.IsTrue<Utils.IsTrue<Utils.Extends<{
25
- biginteger: Schema.Attribute.GetBigIntegerValue<Schema.AttributeByName<TUID, TAttributeName>>;
26
- boolean: Schema.Attribute.GetBooleanValue<Schema.AttributeByName<TUID, TAttributeName>>;
27
- blocks: Schema.Attribute.GetBlocksValue<Schema.AttributeByName<TUID, TAttributeName>>;
28
- decimal: Schema.Attribute.GetDecimalValue<Schema.AttributeByName<TUID, TAttributeName>>;
29
- enumeration: Schema.Attribute.GetEnumerationValue<Schema.AttributeByName<TUID, TAttributeName>>;
30
- email: Schema.Attribute.GetEmailValue<Schema.AttributeByName<TUID, TAttributeName>>;
31
- float: Schema.Attribute.GetFloatValue<Schema.AttributeByName<TUID, TAttributeName>>;
32
- integer: Schema.Attribute.GetIntegerValue<Schema.AttributeByName<TUID, TAttributeName>>;
33
- json: Schema.Attribute.GetJsonValue<Schema.AttributeByName<TUID, TAttributeName>>;
34
- password: Schema.Attribute.GetPasswordValue<Schema.AttributeByName<TUID, TAttributeName>>;
35
- richtext: Schema.Attribute.GetRichTextValue<Schema.AttributeByName<TUID, TAttributeName>>;
36
- string: Schema.Attribute.GetStringValue<Schema.AttributeByName<TUID, TAttributeName>>;
37
- text: Schema.Attribute.GetTextValue<Schema.AttributeByName<TUID, TAttributeName>>;
38
- uid: Schema.Attribute.GetUIDValue<Schema.AttributeByName<TUID, TAttributeName>>;
39
- date: Schema.Attribute.GetDateValue<Schema.AttributeByName<TUID, TAttributeName>>;
40
- datetime: Schema.Attribute.GetDateTimeValue<Schema.AttributeByName<TUID, TAttributeName>>;
41
- time: Schema.Attribute.GetTimeValue<Schema.AttributeByName<TUID, TAttributeName>>;
42
- timestamp: Schema.Attribute.GetTimestampValue<Schema.AttributeByName<TUID, TAttributeName>>;
43
- component: Schema.Attribute.GetComponentValue<Schema.AttributeByName<TUID, TAttributeName>>;
44
- dynamiczone: Schema.Attribute.GetDynamicZoneValue<Schema.AttributeByName<TUID, TAttributeName>>;
45
- media: Schema.Attribute.GetMediaValue<Schema.AttributeByName<TUID, TAttributeName>>;
46
- relation: Schema.Attribute.GetRelationValue<Schema.AttributeByName<TUID, TAttributeName>>;
47
- }[Schema.Attribute.TypeOf<Schema.AttributeByName<TUID, TAttributeName>>], never>> | Utils.IsTrue<Utils.Extends<never, {
48
- biginteger: Schema.Attribute.GetBigIntegerValue<Schema.AttributeByName<TUID, TAttributeName>>;
49
- boolean: Schema.Attribute.GetBooleanValue<Schema.AttributeByName<TUID, TAttributeName>>;
50
- blocks: Schema.Attribute.GetBlocksValue<Schema.AttributeByName<TUID, TAttributeName>>;
51
- decimal: Schema.Attribute.GetDecimalValue<Schema.AttributeByName<TUID, TAttributeName>>;
52
- enumeration: Schema.Attribute.GetEnumerationValue<Schema.AttributeByName<TUID, TAttributeName>>;
53
- email: Schema.Attribute.GetEmailValue<Schema.AttributeByName<TUID, TAttributeName>>;
54
- float: Schema.Attribute.GetFloatValue<Schema.AttributeByName<TUID, TAttributeName>>;
55
- integer: Schema.Attribute.GetIntegerValue<Schema.AttributeByName<TUID, TAttributeName>>;
56
- json: Schema.Attribute.GetJsonValue<Schema.AttributeByName<TUID, TAttributeName>>;
57
- password: Schema.Attribute.GetPasswordValue<Schema.AttributeByName<TUID, TAttributeName>>;
58
- richtext: Schema.Attribute.GetRichTextValue<Schema.AttributeByName<TUID, TAttributeName>>;
59
- string: Schema.Attribute.GetStringValue<Schema.AttributeByName<TUID, TAttributeName>>;
60
- text: Schema.Attribute.GetTextValue<Schema.AttributeByName<TUID, TAttributeName>>;
61
- uid: Schema.Attribute.GetUIDValue<Schema.AttributeByName<TUID, TAttributeName>>;
62
- date: Schema.Attribute.GetDateValue<Schema.AttributeByName<TUID, TAttributeName>>;
63
- datetime: Schema.Attribute.GetDateTimeValue<Schema.AttributeByName<TUID, TAttributeName>>;
64
- time: Schema.Attribute.GetTimeValue<Schema.AttributeByName<TUID, TAttributeName>>;
65
- timestamp: Schema.Attribute.GetTimestampValue<Schema.AttributeByName<TUID, TAttributeName>>;
66
- component: Schema.Attribute.GetComponentValue<Schema.AttributeByName<TUID, TAttributeName>>;
67
- dynamiczone: Schema.Attribute.GetDynamicZoneValue<Schema.AttributeByName<TUID, TAttributeName>>;
68
- media: Schema.Attribute.GetMediaValue<Schema.AttributeByName<TUID, TAttributeName>>;
69
- relation: Schema.Attribute.GetRelationValue<Schema.AttributeByName<TUID, TAttributeName>>;
70
- }[Schema.Attribute.TypeOf<Schema.AttributeByName<TUID, TAttributeName>>]>>>, unknown, {
71
- biginteger: Schema.Attribute.GetBigIntegerValue<Schema.AttributeByName<TUID, TAttributeName>>;
72
- boolean: Schema.Attribute.GetBooleanValue<Schema.AttributeByName<TUID, TAttributeName>>;
73
- blocks: Schema.Attribute.GetBlocksValue<Schema.AttributeByName<TUID, TAttributeName>>;
74
- decimal: Schema.Attribute.GetDecimalValue<Schema.AttributeByName<TUID, TAttributeName>>;
75
- enumeration: Schema.Attribute.GetEnumerationValue<Schema.AttributeByName<TUID, TAttributeName>>;
76
- email: Schema.Attribute.GetEmailValue<Schema.AttributeByName<TUID, TAttributeName>>;
77
- float: Schema.Attribute.GetFloatValue<Schema.AttributeByName<TUID, TAttributeName>>;
78
- integer: Schema.Attribute.GetIntegerValue<Schema.AttributeByName<TUID, TAttributeName>>;
79
- json: Schema.Attribute.GetJsonValue<Schema.AttributeByName<TUID, TAttributeName>>;
80
- password: Schema.Attribute.GetPasswordValue<Schema.AttributeByName<TUID, TAttributeName>>;
81
- richtext: Schema.Attribute.GetRichTextValue<Schema.AttributeByName<TUID, TAttributeName>>;
82
- string: Schema.Attribute.GetStringValue<Schema.AttributeByName<TUID, TAttributeName>>;
83
- text: Schema.Attribute.GetTextValue<Schema.AttributeByName<TUID, TAttributeName>>;
84
- uid: Schema.Attribute.GetUIDValue<Schema.AttributeByName<TUID, TAttributeName>>;
85
- date: Schema.Attribute.GetDateValue<Schema.AttributeByName<TUID, TAttributeName>>;
86
- datetime: Schema.Attribute.GetDateTimeValue<Schema.AttributeByName<TUID, TAttributeName>>;
87
- time: Schema.Attribute.GetTimeValue<Schema.AttributeByName<TUID, TAttributeName>>;
88
- timestamp: Schema.Attribute.GetTimestampValue<Schema.AttributeByName<TUID, TAttributeName>>;
89
- component: Schema.Attribute.GetComponentValue<Schema.AttributeByName<TUID, TAttributeName>>;
90
- dynamiczone: Schema.Attribute.GetDynamicZoneValue<Schema.AttributeByName<TUID, TAttributeName>>;
91
- media: Schema.Attribute.GetMediaValue<Schema.AttributeByName<TUID, TAttributeName>>;
92
- relation: Schema.Attribute.GetRelationValue<Schema.AttributeByName<TUID, TAttributeName>>;
93
- }[Schema.Attribute.TypeOf<Schema.AttributeByName<TUID, TAttributeName>>]> | null | undefined; }, Extract<keyof Schema.Attributes<TUID>, string>>) => Promise<void>;
94
- declare const assignComponentData: <TUID extends UID.ContentType>(data: Modules.EntityService.Params.Data.Input<TUID>, componentData: ComponentBody, { contentType, }: {
95
- contentType: Schema.ContentType<TUID>;
96
- }) => Partial<Modules.EntityService.Params.Data.Input<UID.ContentType>> & ComponentBody;
23
+ declare const deleteComponent: <TUID extends `${string}.${string}`>(uid: TUID, componentToDelete: Data.Component<TUID>) => Promise<void>;
24
+ declare const assignComponentData: _.CurriedFunction3<import("@strapi/types/dist/struct").ComponentSchema | import("@strapi/types/dist/struct").ContentTypeSchema, ComponentBody, Input<UID.Schema>, ComponentBody & Partial<Input<UID.Schema>>>;
97
25
  export { omitComponentData, assignComponentData, getComponents, createComponents, updateComponents, deleteComponents, deleteComponent, };
98
26
  //# sourceMappingURL=components.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"components.d.ts","sourceRoot":"","sources":["../../../src/services/document-service/components.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAG/E,KAAK,gBAAgB,CAAC,IAAI,SAAS,GAAG,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CAC1D,IAAI,EACJ,MAAM,CAAC,oBAAoB,CAAC,IAAI,EAAE,WAAW,GAAG,aAAa,CAAC,CAC/D,CAAC;AAEF,KAAK,oBAAoB,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,GAAG,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;AAClF,KAAK,wBAAwB,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;AAErF,KAAK,cAAc,GAAG,oBAAoB,GAAG,wBAAwB,CAAC;AAEtE,KAAK,gBAAgB,GAAG,MAAM,CAAC,SAAS,CAAC,gBAAgB,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,CAAC;AAE3E,KAAK,aAAa,GAAG;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,GAAG,gBAAgB,CAAC;CAClD,CAAC;AAEF,iBAAS,iBAAiB,CACxB,WAAW,EAAE,MAAM,CAAC,iBAAiB,EACrC,IAAI,EAAE,OAAO,CAAC,a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,qEACf,IAAI,kBACO;IAAE,EAAE,EAAE,QAAQ,aAAa,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAA;CAAE,QAC3D,KAAK,2BA0EZ,CAAC;AAkGF,QAAA,MAAM,gBAAgB,oHACf,IAAI,kBACO,OAAO;;mBAqCxB,CAAC;AAyDF,QAAA,MAAM,eAAe,4CACd,IAAI,qBACU,KAAK,SAAS,CAAC,IAAI,CAAC,kBAIxC,CAAC;AAEF,QAAA,MAAM,mBAAmB,+MAIxB,CAAC;AAEF,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,GAChB,CAAC"}
@@ -1,24 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const _$1 = require("lodash");
4
- const _ = require("lodash/fp");
3
+ const _ = require("lodash");
4
+ const fp = require("lodash/fp");
5
5
  const strapiUtils = require("@strapi/utils");
6
6
  const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
7
- const ___default = /* @__PURE__ */ _interopDefault(_$1);
8
- function omitComponentData(contentType, data) {
9
- const { attributes } = contentType;
10
- const componentAttributes = Object.keys(attributes).filter(
11
- (attributeName) => strapiUtils.contentTypes.isComponentAttribute(attributes[attributeName])
12
- );
13
- return _.omit(componentAttributes, data);
14
- }
7
+ const ___default = /* @__PURE__ */ _interopDefault(_);
8
+ const omitComponentData = fp.curry(
9
+ (schema, data) => {
10
+ const { attributes } = schema;
11
+ const componentAttributes = Object.keys(attributes).filter(
12
+ (attributeName) => strapiUtils.contentTypes.isComponentAttribute(attributes[attributeName])
13
+ );
14
+ return fp.omit(componentAttributes, data);
15
+ }
16
+ );
15
17
  const createComponents = async (uid, data) => {
16
18
  const { attributes = {} } = strapi.getModel(uid);
17
19
  const componentBody = {};
18
20
  const attributeNames = Object.keys(attributes);
19
21
  for (const attributeName of attributeNames) {
20
22
  const attribute = attributes[attributeName];
21
- if (!_.has(attributeName, data) || !strapiUtils.contentTypes.isComponentAttribute(attribute)) {
23
+ if (!fp.has(attributeName, data) || !strapiUtils.contentTypes.isComponentAttribute(attribute)) {
22
24
  continue;
23
25
  }
24
26
  if (attribute.type === "component") {
@@ -95,7 +97,7 @@ const updateComponents = async (uid, entityToUpdate, data) => {
95
97
  const componentBody = {};
96
98
  for (const attributeName of Object.keys(attributes)) {
97
99
  const attribute = attributes[attributeName];
98
- if (!_.has(attributeName, data)) {
100
+ if (!fp.has(attributeName, data)) {
99
101
  continue;
100
102
  }
101
103
  if (attribute.type === "component") {
@@ -159,8 +161,8 @@ const pickStringifiedId = ({
159
161
  };
160
162
  const deleteOldComponents = async (uid, componentUID, entityToUpdate, attributeName, componentValue) => {
161
163
  const previousValue = await strapi.db.query(uid).load(entityToUpdate, attributeName);
162
- const idsToKeep = ___default.default.castArray(componentValue).filter(_.has("id")).map(pickStringifiedId);
163
- const allIds = ___default.default.castArray(previousValue).filter(_.has("id")).map(pickStringifiedId);
164
+ const idsToKeep = ___default.default.castArray(componentValue).filter(fp.has("id")).map(pickStringifiedId);
165
+ const allIds = ___default.default.castArray(previousValue).filter(fp.has("id")).map(pickStringifiedId);
164
166
  idsToKeep.forEach((id) => {
165
167
  if (!allIds.includes(id)) {
166
168
  throw new strapiUtils.errors.ApplicationError(
@@ -177,11 +179,11 @@ const deleteOldComponents = async (uid, componentUID, entityToUpdate, attributeN
177
179
  };
178
180
  const deleteOldDZComponents = async (uid, entityToUpdate, attributeName, dynamiczoneValues) => {
179
181
  const previousValue = await strapi.db.query(uid).load(entityToUpdate, attributeName);
180
- const idsToKeep = ___default.default.castArray(dynamiczoneValues).filter(_.has("id")).map((v) => ({
182
+ const idsToKeep = ___default.default.castArray(dynamiczoneValues).filter(fp.has("id")).map((v) => ({
181
183
  id: pickStringifiedId(v),
182
184
  __component: v.__component
183
185
  }));
184
- const allIds = ___default.default.castArray(previousValue).filter(_.has("id")).map((v) => ({
186
+ const allIds = ___default.default.castArray(previousValue).filter(fp.has("id")).map((v) => ({
185
187
  id: pickStringifiedId(v),
186
188
  __component: v.__component
187
189
  }));
@@ -239,26 +241,23 @@ const deleteComponents = async (uid, entityToDelete, { loadComponents = true } =
239
241
  }
240
242
  };
241
243
  const createComponent = async (uid, data) => {
242
- const model = strapi.getModel(uid);
244
+ const schema = strapi.getModel(uid);
243
245
  const componentData = await createComponents(uid, data);
244
- const transform = _.pipe(
246
+ const transform = fp.pipe(
245
247
  // Make sure we don't save the component with a pre-defined ID
246
- _.omit("id"),
247
- // Remove the component data from the original data object ...
248
- (payload) => omitComponentData(model, payload),
249
- // ... and assign the newly created component instead
250
- _.assign(componentData)
248
+ fp.omit("id"),
249
+ assignComponentData(schema, componentData)
251
250
  );
252
251
  return strapi.db.query(uid).create({ data: transform(data) });
253
252
  };
254
253
  const updateComponent = async (uid, componentToUpdate, data) => {
255
- const model = strapi.getModel(uid);
254
+ const schema = strapi.getModel(uid);
256
255
  const componentData = await updateComponents(uid, componentToUpdate, data);
257
256
  return strapi.db.query(uid).update({
258
257
  where: {
259
258
  id: componentToUpdate.id
260
259
  },
261
- data: Object.assign(omitComponentData(model, data), componentData)
260
+ data: assignComponentData(schema, componentData, data)
262
261
  });
263
262
  };
264
263
  const updateOrCreateComponent = (componentUID, value) => {
@@ -274,11 +273,11 @@ const deleteComponent = async (uid, componentToDelete) => {
274
273
  await deleteComponents(uid, componentToDelete);
275
274
  await strapi.db.query(uid).delete({ where: { id: componentToDelete.id } });
276
275
  };
277
- const assignComponentData = (data, componentData, {
278
- contentType
279
- }) => {
280
- return Object.assign(omitComponentData(contentType, data), componentData);
281
- };
276
+ const assignComponentData = fp.curry(
277
+ (schema, componentData, data) => {
278
+ return fp.pipe(omitComponentData(schema), fp.assign(componentData))(data);
279
+ }
280
+ );
282
281
  exports.assignComponentData = assignComponentData;
283
282
  exports.createComponents = createComponents;
284
283
  exports.deleteComponent = deleteComponent;
@@ -1 +1 @@
1
- {"version":3,"file":"components.js","sources":["../../../src/services/document-service/components.ts"],"sourcesContent":["import _ from 'lodash';\nimport { has, omit, pipe, assign } from 'lodash/fp';\nimport type { Struct, Utils, UID, Schema, Data, Modules } from '@strapi/types';\nimport { contentTypes as contentTypesUtils, async, errors } from '@strapi/utils';\n\ntype LoadedComponents<TUID extends UID.Schema> = Data.Entity<\n TUID,\n Schema.AttributeNamesByType<TUID, 'component' | 'dynamiczone'>\n>;\n\ntype SingleComponentValue = Schema.Attribute.ComponentValue<UID.Component, false>;\ntype RepeatableComponentValue = Schema.Attribute.ComponentValue<UID.Component, true>;\n\ntype ComponentValue = SingleComponentValue | RepeatableComponentValue;\n\ntype DynamicZoneValue = Schema.Attribute.DynamicZoneValue<UID.Component[]>;\n\ntype ComponentBody = {\n [key: string]: ComponentValue | DynamicZoneValue;\n};\n\nfunction omitComponentData(\n contentType: Struct.ContentTypeSchema,\n data: Modules.EntityService.Params.Data.Input<Struct.ContentTypeSchema['uid']>\n): Partial<Modules.EntityService.Params.Data.Input<Struct.ContentTypeSchema['uid']>>;\nfunction omitComponentData(\n contentType: Struct.ComponentSchema,\n data: Modules.EntityService.Params.Data.Input<Struct.ComponentSchema['uid']>\n): Partial<Modules.EntityService.Params.Data.Input<Struct.ComponentSchema['uid']>>;\nfunction omitComponentData(\n contentType: Struct.Schema,\n data: Modules.EntityService.Params.Data.Input<\n Struct.ContentTypeSchema['uid'] | Struct.ComponentSchema['uid']\n >\n): Partial<\n Modules.EntityService.Params.Data.Input<\n Struct.ContentTypeSchema['uid'] | Struct.ComponentSchema['uid']\n >\n> {\n const { attributes } = contentType;\n const componentAttributes = Object.keys(attributes).filter((attributeName) =>\n contentTypesUtils.isComponentAttribute(attributes[attributeName])\n );\n\n return omit(componentAttributes, data);\n}\n\n// NOTE: we could generalize the logic to allow CRUD of relation directly in the DB layer\nconst createComponents = async <\n TUID extends UID.Schema,\n TData extends Modules.EntityService.Params.Data.Input<TUID>,\n>(\n uid: TUID,\n data: TData\n) => {\n const { attributes = {} } = strapi.getModel(uid);\n\n const componentBody: ComponentBody = {};\n\n const attributeNames = Object.keys(attributes);\n\n for (const attributeName of attributeNames) {\n const attribute = attributes[attributeName];\n\n if (!has(attributeName, data) || !contentTypesUtils.isComponentAttribute(attribute)) {\n continue;\n }\n\n if (attribute.type === 'component') {\n const { component: componentUID, repeatable = false } = attribute;\n\n const componentValue = data[attributeName as keyof TData];\n\n if (componentValue === null) {\n continue;\n }\n\n if (repeatable === true) {\n if (!Array.isArray(componentValue)) {\n throw new Error('Expected an array to create repeatable component');\n }\n\n // MySQL/MariaDB can cause deadlocks here if concurrency higher than 1\n const components: RepeatableComponentValue = await async.map(componentValue, (value: any) =>\n createComponent(componentUID, value)\n );\n\n componentBody[attributeName] = components.map(({ id }) => {\n return {\n id,\n __pivot: {\n field: attributeName,\n component_type: componentUID,\n },\n };\n });\n } else {\n const component = await createComponent(\n componentUID,\n componentValue as Modules.EntityService.Params.Data.Input<UID.Component>\n );\n\n componentBody[attributeName] = {\n id: component.id,\n __pivot: {\n field: attributeName,\n component_type: componentUID,\n },\n };\n }\n\n continue;\n }\n\n if (attribute.type === 'dynamiczone') {\n const dynamiczoneValues = data[\n attributeName as keyof TData\n ] as Modules.EntityService.Params.Attribute.GetValue<Schema.Attribute.DynamicZone>;\n\n if (!Array.isArray(dynamiczoneValues)) {\n throw new Error('Expected an array to create repeatable component');\n }\n\n const createDynamicZoneComponents = async (\n value: Utils.Array.Values<typeof dynamiczoneValues>\n ) => {\n const { id } = await createComponent(value.__component, value);\n return {\n id,\n __component: value.__component,\n __pivot: {\n field: attributeName,\n },\n };\n };\n\n // MySQL/MariaDB can cause deadlocks here if concurrency higher than 1\n componentBody[attributeName] = await async.map(\n dynamiczoneValues,\n createDynamicZoneComponents\n );\n\n continue;\n }\n }\n\n return componentBody;\n};\n\nconst getComponents = async <TUID extends UID.Schema>(\n uid: TUID,\n entity: { id: Modules.EntityService.Params.Attribute.ID }\n): Promise<LoadedComponents<TUID>> => {\n const componentAttributes = contentTypesUtils.getComponentAttributes(strapi.getModel(uid));\n\n if (_.isEmpty(componentAttributes)) {\n return {} as LoadedComponents<TUID>;\n }\n\n return strapi.db.query(uid).load(entity, componentAttributes) as Promise<LoadedComponents<TUID>>;\n};\n\n/*\n delete old components\n create or update\n*/\nconst updateComponents = async <\n TUID extends UID.Schema,\n TData extends Partial<Modules.EntityService.Params.Data.Input<TUID>>,\n>(\n uid: TUID,\n entityToUpdate: { id: Modules.EntityService.Params.Attribute.ID },\n data: TData\n) => {\n const { attributes = {} } = strapi.getModel(uid);\n\n const componentBody: ComponentBody = {};\n\n for (const attributeName of Object.keys(attributes)) {\n const attribute = attributes[attributeName];\n\n if (!has(attributeName, data)) {\n continue;\n }\n\n if (attribute.type === 'component') {\n const { component: componentUID, repeatable = false } = attribute;\n\n const componentValue = data[attributeName as keyof TData] as ComponentValue;\n\n await deleteOldComponents(uid, componentUID, entityToUpdate, attributeName, componentValue);\n\n if (repeatable === true) {\n if (!Array.isArray(componentValue)) {\n throw new Error('Expected an array to create repeatable component');\n }\n\n // MySQL/MariaDB can cause deadlocks here if concurrency higher than 1\n const components: RepeatableComponentValue = await async.map(componentValue, (value: any) =>\n updateOrCreateComponent(componentUID, value)\n );\n\n componentBody[attributeName] = components.filter(_.negate(_.isNil)).map(({ id }) => {\n return {\n id,\n __pivot: {\n field: attributeName,\n component_type: componentUID,\n },\n };\n });\n } else {\n const component = await updateOrCreateComponent(componentUID, componentValue);\n componentBody[attributeName] = component && {\n id: component.id,\n __pivot: {\n field: attributeName,\n component_type: componentUID,\n },\n };\n }\n } else if (attribute.type === 'dynamiczone') {\n const dynamiczoneValues = data[attributeName as keyof TData] as DynamicZoneValue;\n\n await deleteOldDZComponents(uid, entityToUpdate, attributeName, dynamiczoneValues);\n\n if (!Array.isArray(dynamiczoneValues)) {\n throw new Error('Expected an array to create repeatable component');\n }\n\n // MySQL/MariaDB can cause deadlocks here if concurrency higher than 1\n componentBody[attributeName] = await async.map(dynamiczoneValues, async (value: any) => {\n const { id } = await updateOrCreateComponent(value.__component, value);\n\n return {\n id,\n __component: value.__component,\n __pivot: {\n field: attributeName,\n },\n };\n });\n }\n }\n\n return componentBody;\n};\n\nconst pickStringifiedId = ({\n id,\n}: {\n id: Modules.EntityService.Params.Attribute.ID;\n}): Modules.EntityService.Params.Attribute.ID & string => {\n if (typeof id === 'string') {\n return id;\n }\n\n return `${id}`;\n};\n\nconst deleteOldComponents = async <TUID extends UID.Schema>(\n uid: TUID,\n componentUID: UID.Component,\n entityToUpdate: { id: Modules.EntityService.Params.Attribute.ID },\n attributeName: string,\n componentValue: ComponentValue\n) => {\n const previousValue = (await strapi.db\n .query(uid)\n .load(entityToUpdate, attributeName)) as ComponentValue;\n\n const idsToKeep = _.castArray(componentValue).filter(has('id')).map(pickStringifiedId);\n const allIds = _.castArray(previousValue).filter(has('id')).map(pickStringifiedId);\n\n idsToKeep.forEach((id) => {\n if (!allIds.includes(id)) {\n throw new errors.ApplicationError(\n `Some of the provided components in ${attributeName} are not related to the entity`\n );\n }\n });\n\n const idsToDelete = _.difference(allIds, idsToKeep);\n\n if (idsToDelete.length > 0) {\n for (const idToDelete of idsToDelete) {\n await deleteComponent(componentUID, { id: idToDelete });\n }\n }\n};\n\nconst deleteOldDZComponents = async <TUID extends UID.Schema>(\n uid: TUID,\n entityToUpdate: { id: Modules.EntityService.Params.Attribute.ID },\n attributeName: string,\n dynamiczoneValues: DynamicZoneValue\n) => {\n const previousValue = (await strapi.db\n .query(uid)\n .load(entityToUpdate, attributeName)) as DynamicZoneValue;\n\n const idsToKeep = _.castArray(dynamiczoneValues)\n .filter(has('id'))\n .map((v) => ({\n id: pickStringifiedId(v),\n __component: v.__component,\n }));\n\n const allIds = _.castArray(previousValue)\n .filter(has('id'))\n .map((v) => ({\n id: pickStringifiedId(v),\n __component: v.__component,\n }));\n\n idsToKeep.forEach(({ id, __component }) => {\n if (!allIds.find((el) => el.id === id && el.__component === __component)) {\n const err = new Error(\n `Some of the provided components in ${attributeName} are not related to the entity`\n );\n\n Object.assign(err, { status: 400 });\n throw err;\n }\n });\n\n type IdsToDelete = DynamicZoneValue;\n\n const idsToDelete = allIds.reduce((acc, { id, __component }) => {\n if (!idsToKeep.find((el) => el.id === id && el.__component === __component)) {\n acc.push({ id, __component });\n }\n\n return acc;\n }, [] as IdsToDelete);\n\n if (idsToDelete.length > 0) {\n for (const idToDelete of idsToDelete) {\n const { id, __component } = idToDelete;\n await deleteComponent(__component, { id });\n }\n }\n};\n\nconst deleteComponents = async <TUID extends UID.Schema, TEntity extends Data.Entity<TUID>>(\n uid: TUID,\n entityToDelete: TEntity,\n { loadComponents = true } = {}\n) => {\n const { attributes = {} } = strapi.getModel(uid);\n\n const attributeNames = Object.keys(attributes);\n\n for (const attributeName of attributeNames) {\n const attribute = attributes[attributeName];\n\n if (attribute.type === 'component' || attribute.type === 'dynamiczone') {\n let value;\n if (loadComponents) {\n value = await strapi.db.query(uid).load(entityToDelete, attributeName);\n } else {\n value = entityToDelete[attributeName as keyof TEntity];\n }\n\n if (!value) {\n continue;\n }\n\n if (attribute.type === 'component') {\n const { component: componentUID } = attribute;\n // MySQL/MariaDB can cause deadlocks here if concurrency higher than 1\n await async.map(_.castArray(value), (subValue: any) =>\n deleteComponent(componentUID, subValue)\n );\n } else {\n // delete dynamic zone components\n // MySQL/MariaDB can cause deadlocks here if concurrency higher than 1\n await async.map(_.castArray(value), (subValue: any) =>\n deleteComponent(subValue.__component, subValue)\n );\n }\n\n continue;\n }\n }\n};\n\n/** *************************\n Component queries\n************************** */\n\n// components can have nested compos so this must be recursive\nconst createComponent = async <TUID extends UID.Component>(\n uid: TUID,\n data: Modules.EntityService.Params.Data.Input<TUID>\n) => {\n const model = strapi.getModel(uid);\n\n const componentData = await createComponents(uid, data);\n const transform = pipe(\n // Make sure we don't save the component with a pre-defined ID\n omit('id'),\n // Remove the component data from the original data object ...\n (payload) => omitComponentData(model, payload),\n // ... and assign the newly created component instead\n assign(componentData)\n );\n\n return strapi.db.query(uid).create({ data: transform(data) });\n};\n\n// components can have nested compos so this must be recursive\nconst updateComponent = async <TUID extends UID.Component>(\n uid: TUID,\n componentToUpdate: { id: Modules.EntityService.Params.Attribute.ID },\n data: Modules.EntityService.Params.Data.Input<TUID>\n) => {\n const model = strapi.getModel(uid);\n\n const componentData = await updateComponents(uid, componentToUpdate, data);\n\n return strapi.db.query(uid).update({\n where: {\n id: componentToUpdate.id,\n },\n data: Object.assign(omitComponentData(model, data), componentData),\n });\n};\n\nconst updateOrCreateComponent = <TUID extends UID.Component>(\n componentUID: TUID,\n value: Modules.EntityService.Params.Data.Input<TUID>\n) => {\n if (value === null) {\n return null;\n }\n\n // update\n if ('id' in value && typeof value.id !== 'undefined') {\n // TODO: verify the compo is associated with the entity\n return updateComponent(componentUID, { id: value.id }, value);\n }\n\n // create\n return createComponent(componentUID, value);\n};\n\nconst deleteComponent = async <TUID extends UID.Component>(\n uid: TUID,\n componentToDelete: Data.Component<TUID>\n) => {\n await deleteComponents(uid, componentToDelete);\n await strapi.db.query(uid).delete({ where: { id: componentToDelete.id } });\n};\n\nconst assignComponentData = <TUID extends UID.ContentType>(\n data: Modules.EntityService.Params.Data.Input<TUID>,\n componentData: ComponentBody,\n {\n contentType,\n }: {\n contentType: Schema.ContentType<TUID>;\n }\n) => {\n return Object.assign(omitComponentData(contentType, data), componentData);\n};\n\nexport {\n omitComponentData,\n assignComponentData,\n getComponents,\n createComponents,\n updateComponents,\n deleteComponents,\n deleteComponent,\n};\n"],"names":["contentTypesUtils","omit","has","async","_","errors","pipe","assign"],"mappings":";;;;;;;AA6BA,SAAS,kBACP,aACA,MAOA;AACM,QAAA,EAAE,WAAe,IAAA;AACvB,QAAM,sBAAsB,OAAO,KAAK,UAAU,EAAE;AAAA,IAAO,CAAC,kBAC1DA,YAAA,aAAkB,qBAAqB,WAAW,aAAa,CAAC;AAAA,EAAA;AAG3D,SAAAC,EAAA,KAAK,qBAAqB,IAAI;AACvC;AAGM,MAAA,mBAAmB,OA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CAC1B,MACA,eACA;AAAA,EACE;AACF,MAGG;AACH,SAAO,OAAO,OAAO,kBAAkB,aAAa,IAAI,GAAG,aAAa;AAC1E;;;;;;;;"}
1
+ {"version":3,"file":"components.js","sources":["../../../src/services/document-service/components.ts"],"sourcesContent":["import _ from 'lodash';\nimport { has, omit, pipe, assign, curry } from 'lodash/fp';\nimport type { Utils, UID, Schema, Data, Modules } from '@strapi/types';\nimport { contentTypes as contentTypesUtils, async, errors } from '@strapi/utils';\n\n// type aliases for readability\ntype Input<T extends UID.Schema> = Modules.Documents.Params.Data.Input<T>;\n\ntype LoadedComponents<TUID extends UID.Schema> = Data.Entity<\n TUID,\n Schema.AttributeNamesByType<TUID, 'component' | 'dynamiczone'>\n>;\n\ntype SingleComponentValue = Schema.Attribute.ComponentValue<UID.Component, false>;\ntype RepeatableComponentValue = Schema.Attribute.ComponentValue<UID.Component, true>;\n\ntype ComponentValue = SingleComponentValue | RepeatableComponentValue;\n\ntype DynamicZoneValue = Schema.Attribute.DynamicZoneValue<UID.Component[]>;\n\ntype ComponentBody = {\n [key: string]: ComponentValue | DynamicZoneValue;\n};\n\nconst omitComponentData = curry(\n (schema: Schema.Schema, data: Input<UID.Schema>): Partial<Input<UID.Schema>> => {\n const { attributes } = schema;\n const componentAttributes = Object.keys(attributes).filter((attributeName) =>\n contentTypesUtils.isComponentAttribute(attributes[attributeName])\n );\n\n return omit(componentAttributes, data);\n }\n);\n\n// NOTE: we could generalize the logic to allow CRUD of relation directly in the DB layer\nconst createComponents = async <TUID extends UID.Schema, TData extends Input<TUID>>(\n uid: TUID,\n data: TData\n) => {\n const { attributes = {} } = strapi.getModel(uid);\n\n const componentBody: ComponentBody = {};\n\n const attributeNames = Object.keys(attributes);\n\n for (const attributeName of attributeNames) {\n const attribute = attributes[attributeName];\n\n if (!has(attributeName, data) || !contentTypesUtils.isComponentAttribute(attribute)) {\n continue;\n }\n\n if (attribute.type === 'component') {\n const { component: componentUID, repeatable = false } = attribute;\n\n const componentValue = data[attributeName as keyof TData];\n\n if (componentValue === null) {\n continue;\n }\n\n if (repeatable === true) {\n if (!Array.isArray(componentValue)) {\n throw new Error('Expected an array to create repeatable component');\n }\n\n const components: RepeatableComponentValue = await async.map(componentValue, (value: any) =>\n createComponent(componentUID, value)\n );\n\n componentBody[attributeName] = components.map(({ id }) => {\n return {\n id,\n __pivot: {\n field: attributeName,\n component_type: componentUID,\n },\n };\n });\n } else {\n const component = await createComponent(\n componentUID,\n componentValue as Input<UID.Component>\n );\n\n componentBody[attributeName] = {\n id: component.id,\n __pivot: {\n field: attributeName,\n component_type: componentUID,\n },\n };\n }\n\n continue;\n }\n\n if (attribute.type === 'dynamiczone') {\n const dynamiczoneValues = data[\n attributeName as keyof TData\n ] as Modules.EntityService.Params.Attribute.GetValue<Schema.Attribute.DynamicZone>;\n\n if (!Array.isArray(dynamiczoneValues)) {\n throw new Error('Expected an array to create repeatable component');\n }\n\n const createDynamicZoneComponents = async (\n value: Utils.Array.Values<typeof dynamiczoneValues>\n ) => {\n const { id } = await createComponent(value.__component, value);\n return {\n id,\n __component: value.__component,\n __pivot: {\n field: attributeName,\n },\n };\n };\n\n // MySQL/MariaDB can cause deadlocks here if concurrency higher than 1\n componentBody[attributeName] = await async.map(\n dynamiczoneValues,\n createDynamicZoneComponents\n );\n\n continue;\n }\n }\n\n return componentBody;\n};\n\nconst getComponents = async <TUID extends UID.Schema>(\n uid: TUID,\n entity: { id: Modules.EntityService.Params.Attribute.ID }\n): Promise<LoadedComponents<TUID>> => {\n const componentAttributes = contentTypesUtils.getComponentAttributes(strapi.getModel(uid));\n\n if (_.isEmpty(componentAttributes)) {\n return {} as LoadedComponents<TUID>;\n }\n\n return strapi.db.query(uid).load(entity, componentAttributes) as Promise<LoadedComponents<TUID>>;\n};\n\n/*\n delete old components\n create or update\n*/\nconst updateComponents = async <TUID extends UID.Schema, TData extends Partial<Input<TUID>>>(\n uid: TUID,\n entityToUpdate: { id: Modules.EntityService.Params.Attribute.ID },\n data: TData\n) => {\n const { attributes = {} } = strapi.getModel(uid);\n\n const componentBody: ComponentBody = {};\n\n for (const attributeName of Object.keys(attributes)) {\n const attribute = attributes[attributeName];\n\n if (!has(attributeName, data)) {\n continue;\n }\n\n if (attribute.type === 'component') {\n const { component: componentUID, repeatable = false } = attribute;\n\n const componentValue = data[attributeName as keyof TData] as ComponentValue;\n\n await deleteOldComponents(uid, componentUID, entityToUpdate, attributeName, componentValue);\n\n if (repeatable === true) {\n if (!Array.isArray(componentValue)) {\n throw new Error('Expected an array to create repeatable component');\n }\n\n // MySQL/MariaDB can cause deadlocks here if concurrency higher than 1\n const components: RepeatableComponentValue = await async.map(componentValue, (value: any) =>\n updateOrCreateComponent(componentUID, value)\n );\n\n componentBody[attributeName] = components.filter(_.negate(_.isNil)).map(({ id }) => {\n return {\n id,\n __pivot: {\n field: attributeName,\n component_type: componentUID,\n },\n };\n });\n } else {\n const component = await updateOrCreateComponent(componentUID, componentValue);\n componentBody[attributeName] = component && {\n id: component.id,\n __pivot: {\n field: attributeName,\n component_type: componentUID,\n },\n };\n }\n } else if (attribute.type === 'dynamiczone') {\n const dynamiczoneValues = data[attributeName as keyof TData] as DynamicZoneValue;\n\n await deleteOldDZComponents(uid, entityToUpdate, attributeName, dynamiczoneValues);\n\n if (!Array.isArray(dynamiczoneValues)) {\n throw new Error('Expected an array to create repeatable component');\n }\n\n // MySQL/MariaDB can cause deadlocks here if concurrency higher than 1\n componentBody[attributeName] = await async.map(dynamiczoneValues, async (value: any) => {\n const { id } = await updateOrCreateComponent(value.__component, value);\n\n return {\n id,\n __component: value.__component,\n __pivot: {\n field: attributeName,\n },\n };\n });\n }\n }\n\n return componentBody;\n};\n\nconst pickStringifiedId = ({\n id,\n}: {\n id: Modules.EntityService.Params.Attribute.ID;\n}): Modules.EntityService.Params.Attribute.ID & string => {\n if (typeof id === 'string') {\n return id;\n }\n\n return `${id}`;\n};\n\nconst deleteOldComponents = async <TUID extends UID.Schema>(\n uid: TUID,\n componentUID: UID.Component,\n entityToUpdate: { id: Modules.EntityService.Params.Attribute.ID },\n attributeName: string,\n componentValue: ComponentValue\n) => {\n const previousValue = (await strapi.db\n .query(uid)\n .load(entityToUpdate, attributeName)) as ComponentValue;\n\n const idsToKeep = _.castArray(componentValue).filter(has('id')).map(pickStringifiedId);\n const allIds = _.castArray(previousValue).filter(has('id')).map(pickStringifiedId);\n\n idsToKeep.forEach((id) => {\n if (!allIds.includes(id)) {\n throw new errors.ApplicationError(\n `Some of the provided components in ${attributeName} are not related to the entity`\n );\n }\n });\n\n const idsToDelete = _.difference(allIds, idsToKeep);\n\n if (idsToDelete.length > 0) {\n for (const idToDelete of idsToDelete) {\n await deleteComponent(componentUID, { id: idToDelete });\n }\n }\n};\n\nconst deleteOldDZComponents = async <TUID extends UID.Schema>(\n uid: TUID,\n entityToUpdate: { id: Modules.EntityService.Params.Attribute.ID },\n attributeName: string,\n dynamiczoneValues: DynamicZoneValue\n) => {\n const previousValue = (await strapi.db\n .query(uid)\n .load(entityToUpdate, attributeName)) as DynamicZoneValue;\n\n const idsToKeep = _.castArray(dynamiczoneValues)\n .filter(has('id'))\n .map((v) => ({\n id: pickStringifiedId(v),\n __component: v.__component,\n }));\n\n const allIds = _.castArray(previousValue)\n .filter(has('id'))\n .map((v) => ({\n id: pickStringifiedId(v),\n __component: v.__component,\n }));\n\n idsToKeep.forEach(({ id, __component }) => {\n if (!allIds.find((el) => el.id === id && el.__component === __component)) {\n const err = new Error(\n `Some of the provided components in ${attributeName} are not related to the entity`\n );\n\n Object.assign(err, { status: 400 });\n throw err;\n }\n });\n\n type IdsToDelete = DynamicZoneValue;\n\n const idsToDelete = allIds.reduce((acc, { id, __component }) => {\n if (!idsToKeep.find((el) => el.id === id && el.__component === __component)) {\n acc.push({ id, __component });\n }\n\n return acc;\n }, [] as IdsToDelete);\n\n if (idsToDelete.length > 0) {\n for (const idToDelete of idsToDelete) {\n const { id, __component } = idToDelete;\n await deleteComponent(__component, { id });\n }\n }\n};\n\nconst deleteComponents = async <TUID extends UID.Schema, TEntity extends Data.Entity<TUID>>(\n uid: TUID,\n entityToDelete: TEntity,\n { loadComponents = true } = {}\n) => {\n const { attributes = {} } = strapi.getModel(uid);\n\n const attributeNames = Object.keys(attributes);\n\n for (const attributeName of attributeNames) {\n const attribute = attributes[attributeName];\n\n if (attribute.type === 'component' || attribute.type === 'dynamiczone') {\n let value;\n\n if (loadComponents) {\n value = await strapi.db.query(uid).load(entityToDelete, attributeName);\n } else {\n value = entityToDelete[attributeName as keyof TEntity];\n }\n\n if (!value) {\n continue;\n }\n\n if (attribute.type === 'component') {\n const { component: componentUID } = attribute;\n await async.map(_.castArray(value), (subValue: any) =>\n deleteComponent(componentUID, subValue)\n );\n } else {\n await async.map(_.castArray(value), (subValue: any) =>\n deleteComponent(subValue.__component, subValue)\n );\n }\n\n continue;\n }\n }\n};\n\n/** *************************\n Component queries\n************************** */\n\n// components can have nested compos so this must be recursive\nconst createComponent = async <TUID extends UID.Component>(uid: TUID, data: Input<TUID>) => {\n const schema = strapi.getModel(uid);\n\n const componentData = await createComponents(uid, data);\n\n const transform = pipe(\n // Make sure we don't save the component with a pre-defined ID\n omit('id'),\n assignComponentData(schema, componentData)\n );\n\n return strapi.db.query(uid).create({ data: transform(data) });\n};\n\n// components can have nested compos so this must be recursive\nconst updateComponent = async <TUID extends UID.Component>(\n uid: TUID,\n componentToUpdate: { id: Modules.EntityService.Params.Attribute.ID },\n data: Input<TUID>\n) => {\n const schema = strapi.getModel(uid);\n\n const componentData = await updateComponents(uid, componentToUpdate, data);\n\n return strapi.db.query(uid).update({\n where: {\n id: componentToUpdate.id,\n },\n data: assignComponentData(schema, componentData, data),\n });\n};\n\nconst updateOrCreateComponent = <TUID extends UID.Component>(\n componentUID: TUID,\n value: Input<TUID>\n) => {\n if (value === null) {\n return null;\n }\n\n // update\n if ('id' in value && typeof value.id !== 'undefined') {\n // TODO: verify the compo is associated with the entity\n return updateComponent(componentUID, { id: value.id }, value);\n }\n\n // create\n return createComponent(componentUID, value);\n};\n\nconst deleteComponent = async <TUID extends UID.Component>(\n uid: TUID,\n componentToDelete: Data.Component<TUID>\n) => {\n await deleteComponents(uid, componentToDelete);\n await strapi.db.query(uid).delete({ where: { id: componentToDelete.id } });\n};\n\nconst assignComponentData = curry(\n (schema: Schema.Schema, componentData: ComponentBody, data: Input<UID.Schema>) => {\n return pipe(omitComponentData(schema), assign(componentData))(data);\n }\n);\n\nexport {\n omitComponentData,\n assignComponentData,\n getComponents,\n createComponents,\n updateComponents,\n deleteComponents,\n deleteComponent,\n};\n"],"names":["curry","contentTypesUtils","omit","has","async","_","errors","pipe","assign"],"mappings":";;;;;;;AAwBA,MAAM,oBAAoBA,GAAA;AAAA,EACxB,CAAC,QAAuB,SAAwD;AACxE,UAAA,EAAE,WAAe,IAAA;AACvB,UAAM,sBAAsB,OAAO,KAAK,UAAU,EAAE;AAAA,MAAO,CAAC,kBAC1DC,YAAA,aAAkB,qBAAqB,WAAW,aAAa,CAAC;AAAA,IAAA;AAG3D,WAAAC,GAAA,KAAK,qBAAqB,IAAI;AAAA,EACvC;AACF;AAGM,MAAA,mBAAmB,OACvB,KACA,SACG;AACH,QAAM,EAAE,aAAa,OAAO,OAAO,SAAS,GAAG;AAE/C,QAAM,gBAA+B,CAAA;AAE/B,QAAA,iBAAiB,OAAO,KAAK,UAAU;AAE7C,aAAW,iBAAiB,gBAAgB;AACpC,UAAA,YAAY,WAAW,aAAa;AAEtC,QAAA,CAACC,GAAAA,IAAI,eAAe,IAAI,KAAK,CAACF,yBAAkB,qBAAqB,SAAS,GAAG;AACnF;AAAA,IACF;AAEI,QAAA,UAAU,SAAS,aAAa;AAClC,YAAM,EAAE,WAAW,cAAc,aAAa,UAAU;AAElD,YAAA,iBAAiB,KAAK,aAA4B;AAExD,UAAI,mBAAmB,MAAM;AAC3B;AAAA,MACF;AAEA,UAAI,eAAe,MAAM;AACvB,YAAI,CAAC,MAAM,QAAQ,cAAc,GAAG;AAC5B,gBAAA,IAAI,M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AmB,IAAI;AAEzE,SAAO,OAAO,GAAG,MAAM,GAAG,EAAE,OAAO;AAAA,IACjC,OAAO;AAAA,MACL,IAAI,kBAAkB;AAAA,IACxB;AAAA,IACA,MAAM,oBAAoB,QAAQ,eAAe,IAAI;AAAA,EAAA,CACtD;AACH;AAEA,MAAM,0BAA0B,CAC9B,cACA,UACG;AACH,MAAI,UAAU,MAAM;AACX,WAAA;AAAA,EACT;AAGA,MAAI,QAAQ,SAAS,OAAO,MAAM,OAAO,aAAa;AAEpD,WAAO,gBAAgB,cAAc,EAAE,IAAI,MAAM,GAAA,GAAM,KAAK;AAAA,EAC9D;AAGO,SAAA,gBAAgB,cAAc,KAAK;AAC5C;AAEM,MAAA,kBAAkB,OACtB,KACA,sBACG;AACG,QAAA,iBAAiB,KAAK,iBAAiB;AAC7C,QAAM,OAAO,GAAG,MAAM,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,kBAAkB,GAAA,EAAM,CAAA;AAC3E;AAEA,MAAM,sBAAsBF,GAAA;AAAA,EAC1B,CAAC,QAAuB,eAA8B,SAA4B;AACzE,WAAAO,GAAA,KAAK,kBAAkB,MAAM,GAAGC,UAAO,aAAa,CAAC,EAAE,IAAI;AAAA,EACpE;AACF;;;;;;;;"}
@@ -1,13 +1,15 @@
1
1
  import _ from "lodash";
2
- import { omit, has, pipe, assign } from "lodash/fp";
2
+ import { curry, omit, pipe, assign, has } from "lodash/fp";
3
3
  import { contentTypes, async, errors } from "@strapi/utils";
4
- function omitComponentData(contentType, data) {
5
- const { attributes } = contentType;
6
- const componentAttributes = Object.keys(attributes).filter(
7
- (attributeName) => contentTypes.isComponentAttribute(attributes[attributeName])
8
- );
9
- return omit(componentAttributes, data);
10
- }
4
+ const omitComponentData = curry(
5
+ (schema, data) => {
6
+ const { attributes } = schema;
7
+ const componentAttributes = Object.keys(attributes).filter(
8
+ (attributeName) => contentTypes.isComponentAttribute(attributes[attributeName])
9
+ );
10
+ return omit(componentAttributes, data);
11
+ }
12
+ );
11
13
  const createComponents = async (uid, data) => {
12
14
  const { attributes = {} } = strapi.getModel(uid);
13
15
  const componentBody = {};
@@ -235,26 +237,23 @@ const deleteComponents = async (uid, entityToDelete, { loadComponents = true } =
235
237
  }
236
238
  };
237
239
  const createComponent = async (uid, data) => {
238
- const model = strapi.getModel(uid);
240
+ const schema = strapi.getModel(uid);
239
241
  const componentData = await createComponents(uid, data);
240
242
  const transform = pipe(
241
243
  // Make sure we don't save the component with a pre-defined ID
242
244
  omit("id"),
243
- // Remove the component data from the original data object ...
244
- (payload) => omitComponentData(model, payload),
245
- // ... and assign the newly created component instead
246
- assign(componentData)
245
+ assignComponentData(schema, componentData)
247
246
  );
248
247
  return strapi.db.query(uid).create({ data: transform(data) });
249
248
  };
250
249
  const updateComponent = async (uid, componentToUpdate, data) => {
251
- const model = strapi.getModel(uid);
250
+ const schema = strapi.getModel(uid);
252
251
  const componentData = await updateComponents(uid, componentToUpdate, data);
253
252
  return strapi.db.query(uid).update({
254
253
  where: {
255
254
  id: componentToUpdate.id
256
255
  },
257
- data: Object.assign(omitComponentData(model, data), componentData)
256
+ data: assignComponentData(schema, componentData, data)
258
257
  });
259
258
  };
260
259
  const updateOrCreateComponent = (componentUID, value) => {
@@ -270,11 +269,11 @@ const deleteComponent = async (uid, componentToDelete) => {
270
269
  await deleteComponents(uid, componentToDelete);
271
270
  await strapi.db.query(uid).delete({ where: { id: componentToDelete.id } });
272
271
  };
273
- const assignComponentData = (data, componentData, {
274
- contentType
275
- }) => {
276
- return Object.assign(omitComponentData(contentType, data), componentData);
277
- };
272
+ const assignComponentData = curry(
273
+ (schema, componentData, data) => {
274
+ return pipe(omitComponentData(schema), assign(componentData))(data);
275
+ }
276
+ );
278
277
  export {
279
278
  assignComponentData,
280
279
  createComponents,