@webiny/api-headless-cms 5.34.8 → 5.35.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (374) hide show
  1. package/context.js +47 -68
  2. package/context.js.map +1 -1
  3. package/crud/contentEntry/afterDelete.js +0 -5
  4. package/crud/contentEntry/afterDelete.js.map +1 -1
  5. package/crud/contentEntry/beforeCreate.js +0 -3
  6. package/crud/contentEntry/beforeCreate.js.map +1 -1
  7. package/crud/contentEntry/beforeUpdate.js +0 -3
  8. package/crud/contentEntry/beforeUpdate.js.map +1 -1
  9. package/crud/contentEntry/entryDataValidation.js +1 -40
  10. package/crud/contentEntry/entryDataValidation.js.map +1 -1
  11. package/crud/contentEntry/markLockedFields.d.ts +1 -1
  12. package/crud/contentEntry/markLockedFields.js +5 -26
  13. package/crud/contentEntry/markLockedFields.js.map +1 -1
  14. package/crud/contentEntry/referenceFieldsMapping.js +39 -66
  15. package/crud/contentEntry/referenceFieldsMapping.js.map +1 -1
  16. package/crud/contentEntry/searchableFields.js +1 -12
  17. package/crud/contentEntry/searchableFields.js.map +1 -1
  18. package/crud/contentEntry.crud.d.ts +5 -2
  19. package/crud/contentEntry.crud.js +859 -941
  20. package/crud/contentEntry.crud.js.map +1 -1
  21. package/crud/contentModel/afterCreate.js +0 -2
  22. package/crud/contentModel/afterCreate.js.map +1 -1
  23. package/crud/contentModel/afterCreateFrom.js +0 -2
  24. package/crud/contentModel/afterCreateFrom.js.map +1 -1
  25. package/crud/contentModel/afterDelete.js +0 -2
  26. package/crud/contentModel/afterDelete.js.map +1 -1
  27. package/crud/contentModel/afterUpdate.js +0 -2
  28. package/crud/contentModel/afterUpdate.js.map +1 -1
  29. package/crud/contentModel/beforeCreate.js +39 -105
  30. package/crud/contentModel/beforeCreate.js.map +1 -1
  31. package/crud/contentModel/beforeDelete.d.ts +1 -1
  32. package/crud/contentModel/beforeDelete.js +1 -15
  33. package/crud/contentModel/beforeDelete.js.map +1 -1
  34. package/crud/contentModel/beforeUpdate.js +31 -8
  35. package/crud/contentModel/beforeUpdate.js.map +1 -1
  36. package/crud/contentModel/compatibility/modelApiName.d.ts +3 -0
  37. package/crud/contentModel/compatibility/modelApiName.js +24 -0
  38. package/crud/contentModel/compatibility/modelApiName.js.map +1 -0
  39. package/crud/contentModel/contentModelManagerFactory.js +0 -7
  40. package/crud/contentModel/contentModelManagerFactory.js.map +1 -1
  41. package/crud/contentModel/createFieldStorageId.js +0 -3
  42. package/crud/contentModel/createFieldStorageId.js.map +1 -1
  43. package/crud/contentModel/defaultFields.d.ts +5 -0
  44. package/crud/contentModel/defaultFields.js +58 -0
  45. package/crud/contentModel/defaultFields.js.map +1 -0
  46. package/crud/contentModel/fields/descriptionField.d.ts +2 -0
  47. package/crud/contentModel/fields/descriptionField.js +42 -0
  48. package/crud/contentModel/fields/descriptionField.js.map +1 -0
  49. package/crud/contentModel/fields/imageField.d.ts +2 -0
  50. package/crud/contentModel/fields/imageField.js +46 -0
  51. package/crud/contentModel/fields/imageField.js.map +1 -0
  52. package/crud/contentModel/fields/titleField.d.ts +2 -0
  53. package/crud/contentModel/fields/titleField.js +58 -0
  54. package/crud/contentModel/fields/titleField.js.map +1 -0
  55. package/crud/contentModel/validate/endingAllowed.d.ts +6 -0
  56. package/crud/contentModel/validate/endingAllowed.js +26 -0
  57. package/crud/contentModel/validate/endingAllowed.js.map +1 -0
  58. package/crud/contentModel/validate/isModelEndingAllowed.d.ts +6 -0
  59. package/crud/contentModel/validate/isModelEndingAllowed.js +24 -0
  60. package/crud/contentModel/validate/isModelEndingAllowed.js.map +1 -0
  61. package/crud/contentModel/validate/modelId.d.ts +11 -0
  62. package/crud/contentModel/validate/modelId.js +36 -0
  63. package/crud/contentModel/validate/modelId.js.map +1 -0
  64. package/crud/contentModel/validate/pluralApiName.d.ts +7 -0
  65. package/crud/contentModel/validate/pluralApiName.js +24 -0
  66. package/crud/contentModel/validate/pluralApiName.js.map +1 -0
  67. package/crud/contentModel/validate/singularApiName.d.ts +7 -0
  68. package/crud/contentModel/validate/singularApiName.js +24 -0
  69. package/crud/contentModel/validate/singularApiName.js.map +1 -0
  70. package/crud/contentModel/validateLayout.js +0 -8
  71. package/crud/contentModel/validateLayout.js.map +1 -1
  72. package/crud/contentModel/validateModel.d.ts +1 -0
  73. package/crud/contentModel/validateModel.js +0 -8
  74. package/crud/contentModel/validateModel.js.map +1 -1
  75. package/crud/contentModel/validateModelFields.d.ts +2 -1
  76. package/crud/contentModel/validateModelFields.js +25 -133
  77. package/crud/contentModel/validateModelFields.js.map +1 -1
  78. package/crud/contentModel/validation.d.ts +551 -0
  79. package/crud/contentModel/validation.js +145 -0
  80. package/crud/contentModel/validation.js.map +1 -0
  81. package/crud/contentModel.crud.js +354 -373
  82. package/crud/contentModel.crud.js.map +1 -1
  83. package/crud/contentModelGroup/beforeCreate.js +0 -12
  84. package/crud/contentModelGroup/beforeCreate.js.map +1 -1
  85. package/crud/contentModelGroup/beforeDelete.js +0 -8
  86. package/crud/contentModelGroup/beforeDelete.js.map +1 -1
  87. package/crud/contentModelGroup/beforeUpdate.js +0 -5
  88. package/crud/contentModelGroup/beforeUpdate.js.map +1 -1
  89. package/crud/contentModelGroup/validation.d.ts +30 -0
  90. package/crud/contentModelGroup/validation.js +34 -0
  91. package/crud/contentModelGroup/validation.js.map +1 -0
  92. package/crud/contentModelGroup.crud.js +177 -221
  93. package/crud/contentModelGroup.crud.js.map +1 -1
  94. package/crud/settings.crud.d.ts +1 -1
  95. package/crud/settings.crud.js +5 -22
  96. package/crud/settings.crud.js.map +1 -1
  97. package/crud/system.crud.js +1 -96
  98. package/crud/system.crud.js.map +1 -1
  99. package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js +0 -13
  100. package/fieldConverters/CmsModelDefaultFieldConverterPlugin.js.map +1 -1
  101. package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js +0 -36
  102. package/fieldConverters/CmsModelDynamicZoneFieldConverterPlugin.js.map +1 -1
  103. package/fieldConverters/CmsModelObjectFieldConverterPlugin.js +0 -53
  104. package/fieldConverters/CmsModelObjectFieldConverterPlugin.js.map +1 -1
  105. package/fieldConverters/index.js +0 -5
  106. package/fieldConverters/index.js.map +1 -1
  107. package/graphql/buildSchemaPlugins.d.ts +2 -2
  108. package/graphql/buildSchemaPlugins.js +4 -9
  109. package/graphql/buildSchemaPlugins.js.map +1 -1
  110. package/graphql/checkEndpointAccess.d.ts +2 -0
  111. package/graphql/checkEndpointAccess.js +18 -0
  112. package/graphql/checkEndpointAccess.js.map +1 -0
  113. package/graphql/createExecutableSchema.d.ts +2 -3
  114. package/graphql/createExecutableSchema.js +2 -6
  115. package/graphql/createExecutableSchema.js.map +1 -1
  116. package/graphql/createRequestBody.d.ts +2 -0
  117. package/graphql/createRequestBody.js +14 -0
  118. package/graphql/createRequestBody.js.map +1 -0
  119. package/graphql/formatErrorPayload.d.ts +1 -0
  120. package/graphql/formatErrorPayload.js +25 -0
  121. package/graphql/formatErrorPayload.js.map +1 -0
  122. package/graphql/generateSchema.js +2 -9
  123. package/graphql/generateSchema.js.map +1 -1
  124. package/graphql/getSchema.d.ts +17 -0
  125. package/graphql/getSchema.js +102 -0
  126. package/graphql/getSchema.js.map +1 -0
  127. package/graphql/graphQLHandlerFactory.js +6 -173
  128. package/graphql/graphQLHandlerFactory.js.map +1 -1
  129. package/graphql/handleRequest.d.ts +11 -0
  130. package/graphql/handleRequest.js +81 -0
  131. package/graphql/handleRequest.js.map +1 -0
  132. package/graphql/index.d.ts +1 -1
  133. package/graphql/index.js +0 -5
  134. package/graphql/index.js.map +1 -1
  135. package/graphql/schema/baseContentSchema.d.ts +2 -2
  136. package/graphql/schema/baseContentSchema.js +5 -19
  137. package/graphql/schema/baseContentSchema.js.map +1 -1
  138. package/graphql/schema/baseSchema.d.ts +1 -1
  139. package/graphql/schema/baseSchema.js +5 -10
  140. package/graphql/schema/baseSchema.js.map +1 -1
  141. package/graphql/schema/contentEntries.d.ts +2 -2
  142. package/graphql/schema/contentEntries.js +98 -100
  143. package/graphql/schema/contentEntries.js.map +1 -1
  144. package/graphql/schema/contentModelGroups.d.ts +2 -2
  145. package/graphql/schema/contentModelGroups.js +12 -29
  146. package/graphql/schema/contentModelGroups.js.map +1 -1
  147. package/graphql/schema/contentModels.d.ts +2 -2
  148. package/graphql/schema/contentModels.js +28 -31
  149. package/graphql/schema/contentModels.js.map +1 -1
  150. package/graphql/schema/createFieldResolvers.js +7 -29
  151. package/graphql/schema/createFieldResolvers.js.map +1 -1
  152. package/graphql/schema/createManageResolvers.d.ts +1 -1
  153. package/graphql/schema/createManageResolvers.js +33 -43
  154. package/graphql/schema/createManageResolvers.js.map +1 -1
  155. package/graphql/schema/createManageSDL.d.ts +1 -0
  156. package/graphql/schema/createManageSDL.js +56 -63
  157. package/graphql/schema/createManageSDL.js.map +1 -1
  158. package/graphql/schema/createPreviewResolvers.js +3 -17
  159. package/graphql/schema/createPreviewResolvers.js.map +1 -1
  160. package/graphql/schema/createReadResolvers.js +4 -18
  161. package/graphql/schema/createReadResolvers.js.map +1 -1
  162. package/graphql/schema/createReadSDL.d.ts +1 -0
  163. package/graphql/schema/createReadSDL.js +24 -32
  164. package/graphql/schema/createReadSDL.js.map +1 -1
  165. package/graphql/schema/resolvers/commonFieldResolvers.d.ts +3 -2
  166. package/graphql/schema/resolvers/commonFieldResolvers.js +2 -3
  167. package/graphql/schema/resolvers/commonFieldResolvers.js.map +1 -1
  168. package/graphql/schema/resolvers/manage/resolveCreate.js +0 -3
  169. package/graphql/schema/resolvers/manage/resolveCreate.js.map +1 -1
  170. package/graphql/schema/resolvers/manage/resolveCreateFrom.js +0 -3
  171. package/graphql/schema/resolvers/manage/resolveCreateFrom.js.map +1 -1
  172. package/graphql/schema/resolvers/manage/resolveDelete.js +0 -6
  173. package/graphql/schema/resolvers/manage/resolveDelete.js.map +1 -1
  174. package/graphql/schema/resolvers/manage/resolveGet.js +0 -16
  175. package/graphql/schema/resolvers/manage/resolveGet.js.map +1 -1
  176. package/graphql/schema/resolvers/manage/resolveGetByIds.js +0 -3
  177. package/graphql/schema/resolvers/manage/resolveGetByIds.js.map +1 -1
  178. package/graphql/schema/resolvers/manage/resolveGetRevisions.js +0 -3
  179. package/graphql/schema/resolvers/manage/resolveGetRevisions.js.map +1 -1
  180. package/graphql/schema/resolvers/manage/resolveList.js +0 -3
  181. package/graphql/schema/resolvers/manage/resolveList.js.map +1 -1
  182. package/graphql/schema/resolvers/manage/resolvePublish.js +0 -3
  183. package/graphql/schema/resolvers/manage/resolvePublish.js.map +1 -1
  184. package/graphql/schema/resolvers/manage/resolveRepublish.js +0 -3
  185. package/graphql/schema/resolvers/manage/resolveRepublish.js.map +1 -1
  186. package/graphql/schema/resolvers/manage/resolveUnpublish.js +0 -3
  187. package/graphql/schema/resolvers/manage/resolveUnpublish.js.map +1 -1
  188. package/graphql/schema/resolvers/manage/resolveUpdate.js +0 -3
  189. package/graphql/schema/resolvers/manage/resolveUpdate.js.map +1 -1
  190. package/graphql/schema/resolvers/preview/resolveGet.js +0 -8
  191. package/graphql/schema/resolvers/preview/resolveGet.js.map +1 -1
  192. package/graphql/schema/resolvers/preview/resolveList.js +0 -3
  193. package/graphql/schema/resolvers/preview/resolveList.js.map +1 -1
  194. package/graphql/schema/resolvers/read/resolveGet.js +0 -8
  195. package/graphql/schema/resolvers/read/resolveGet.js.map +1 -1
  196. package/graphql/schema/resolvers/read/resolveList.js +0 -3
  197. package/graphql/schema/resolvers/read/resolveList.js.map +1 -1
  198. package/graphql/schema/schemaPlugins.d.ts +2 -2
  199. package/graphql/schema/schemaPlugins.js +21 -30
  200. package/graphql/schema/schemaPlugins.js.map +1 -1
  201. package/graphql/system.js +55 -87
  202. package/graphql/system.js.map +1 -1
  203. package/graphqlFields/boolean.js +0 -12
  204. package/graphqlFields/boolean.js.map +1 -1
  205. package/graphqlFields/datetime.js +0 -17
  206. package/graphqlFields/datetime.js.map +1 -1
  207. package/graphqlFields/dynamicZone/dynamicZoneField.d.ts +1 -1
  208. package/graphqlFields/dynamicZone/dynamicZoneField.js +57 -48
  209. package/graphqlFields/dynamicZone/dynamicZoneField.js.map +1 -1
  210. package/graphqlFields/dynamicZone/dynamicZoneStorage.js +2 -18
  211. package/graphqlFields/dynamicZone/dynamicZoneStorage.js.map +1 -1
  212. package/graphqlFields/dynamicZone/index.js +0 -2
  213. package/graphqlFields/dynamicZone/index.js.map +1 -1
  214. package/graphqlFields/file.js +0 -8
  215. package/graphqlFields/file.js.map +1 -1
  216. package/graphqlFields/helpers.js +0 -10
  217. package/graphqlFields/helpers.js.map +1 -1
  218. package/graphqlFields/index.js +0 -12
  219. package/graphqlFields/index.js.map +1 -1
  220. package/graphqlFields/longText.js +0 -10
  221. package/graphqlFields/longText.js.map +1 -1
  222. package/graphqlFields/number.js +0 -12
  223. package/graphqlFields/number.js.map +1 -1
  224. package/graphqlFields/object.js +21 -38
  225. package/graphqlFields/object.js.map +1 -1
  226. package/graphqlFields/ref.js +59 -65
  227. package/graphqlFields/ref.js.map +1 -1
  228. package/graphqlFields/richText.js +0 -9
  229. package/graphqlFields/richText.js.map +1 -1
  230. package/graphqlFields/text.js +0 -11
  231. package/graphqlFields/text.js.map +1 -1
  232. package/index.d.ts +4 -2
  233. package/index.js +26 -22
  234. package/index.js.map +1 -1
  235. package/modelManager/DefaultCmsModelManager.js +0 -16
  236. package/modelManager/DefaultCmsModelManager.js.map +1 -1
  237. package/modelManager/index.js +0 -4
  238. package/modelManager/index.js.map +1 -1
  239. package/package.json +26 -28
  240. package/parameters/context.js +0 -4
  241. package/parameters/context.js.map +1 -1
  242. package/parameters/header.js +0 -11
  243. package/parameters/header.js.map +1 -1
  244. package/parameters/index.js +0 -8
  245. package/parameters/index.js.map +1 -1
  246. package/parameters/manual.js +1 -8
  247. package/parameters/manual.js.map +1 -1
  248. package/parameters/path.js +0 -11
  249. package/parameters/path.js.map +1 -1
  250. package/plugins/CmsGraphQLSchemaPlugin.d.ts +5 -0
  251. package/plugins/CmsGraphQLSchemaPlugin.js +12 -0
  252. package/plugins/CmsGraphQLSchemaPlugin.js.map +1 -0
  253. package/plugins/CmsGraphQLSchemaSorterPlugin.js +0 -10
  254. package/plugins/CmsGraphQLSchemaSorterPlugin.js.map +1 -1
  255. package/plugins/CmsGroupPlugin.js +0 -8
  256. package/plugins/CmsGroupPlugin.js.map +1 -1
  257. package/plugins/CmsModelFieldConverterPlugin.js +0 -5
  258. package/plugins/CmsModelFieldConverterPlugin.js.map +1 -1
  259. package/plugins/CmsModelPlugin.d.ts +21 -3
  260. package/plugins/CmsModelPlugin.js +30 -40
  261. package/plugins/CmsModelPlugin.js.map +1 -1
  262. package/plugins/CmsParametersPlugin.js +0 -7
  263. package/plugins/CmsParametersPlugin.js.map +1 -1
  264. package/plugins/StorageOperationsCmsModelPlugin.d.ts +23 -0
  265. package/plugins/StorageOperationsCmsModelPlugin.js +42 -0
  266. package/plugins/StorageOperationsCmsModelPlugin.js.map +1 -0
  267. package/plugins/StorageTransformPlugin.js +0 -9
  268. package/plugins/StorageTransformPlugin.js.map +1 -1
  269. package/plugins/index.d.ts +2 -0
  270. package/plugins/index.js +22 -12
  271. package/plugins/index.js.map +1 -1
  272. package/storage/default.js +0 -3
  273. package/storage/default.js.map +1 -1
  274. package/storage/object.js +0 -19
  275. package/storage/object.js.map +1 -1
  276. package/types.d.ts +173 -79
  277. package/types.js +23 -73
  278. package/types.js.map +1 -1
  279. package/utils/access.js +11 -25
  280. package/utils/access.js.map +1 -1
  281. package/utils/converters/Converter.js +0 -13
  282. package/utils/converters/Converter.js.map +1 -1
  283. package/utils/converters/ConverterCollection.js +9 -33
  284. package/utils/converters/ConverterCollection.js.map +1 -1
  285. package/utils/converters/valueKeyStorageConverter.d.ts +1 -5
  286. package/utils/converters/valueKeyStorageConverter.js +21 -44
  287. package/utils/converters/valueKeyStorageConverter.js.map +1 -1
  288. package/utils/createTypeFromFields.d.ts +1 -0
  289. package/utils/createTypeFromFields.js +11 -20
  290. package/utils/createTypeFromFields.js.map +1 -1
  291. package/utils/createTypeName.d.ts +0 -2
  292. package/utils/createTypeName.js +2 -19
  293. package/utils/createTypeName.js.map +1 -1
  294. package/utils/entryStorage.js +10 -26
  295. package/utils/entryStorage.js.map +1 -1
  296. package/utils/filterAsync.js +0 -5
  297. package/utils/filterAsync.js.map +1 -1
  298. package/utils/getBaseFieldType.js +0 -2
  299. package/utils/getBaseFieldType.js.map +1 -1
  300. package/utils/getEntryDescription.d.ts +2 -0
  301. package/utils/getEntryDescription.js +17 -0
  302. package/utils/getEntryDescription.js.map +1 -0
  303. package/utils/getEntryImage.d.ts +2 -0
  304. package/utils/getEntryImage.js +17 -0
  305. package/utils/getEntryImage.js.map +1 -0
  306. package/utils/getEntryTitle.js +0 -9
  307. package/utils/getEntryTitle.js.map +1 -1
  308. package/utils/getSchemaFromFieldPlugins.d.ts +4 -7
  309. package/utils/getSchemaFromFieldPlugins.js +23 -19
  310. package/utils/getSchemaFromFieldPlugins.js.map +1 -1
  311. package/utils/incrementEntryIdVersion.d.ts +5 -0
  312. package/utils/incrementEntryIdVersion.js +29 -0
  313. package/utils/incrementEntryIdVersion.js.map +1 -0
  314. package/utils/ownership.d.ts +3 -3
  315. package/utils/ownership.js +0 -8
  316. package/utils/ownership.js.map +1 -1
  317. package/utils/permissions.js +8 -23
  318. package/utils/permissions.js.map +1 -1
  319. package/utils/renderFields.d.ts +2 -1
  320. package/utils/renderFields.js +8 -10
  321. package/utils/renderFields.js.map +1 -1
  322. package/utils/renderGetFilterFields.js +0 -13
  323. package/utils/renderGetFilterFields.js.map +1 -1
  324. package/utils/renderInputFields.d.ts +2 -1
  325. package/utils/renderInputFields.js +4 -9
  326. package/utils/renderInputFields.js.map +1 -1
  327. package/utils/renderListFilterFields.js +1 -10
  328. package/utils/renderListFilterFields.js.map +1 -1
  329. package/utils/renderSortEnum.js +0 -9
  330. package/utils/renderSortEnum.js.map +1 -1
  331. package/utils/toSlug.js +0 -4
  332. package/utils/toSlug.js.map +1 -1
  333. package/validators/dateGte.js +0 -7
  334. package/validators/dateGte.js.map +1 -1
  335. package/validators/dateLte.js +0 -7
  336. package/validators/dateLte.js.map +1 -1
  337. package/validators/dynamicZone.js +0 -4
  338. package/validators/dynamicZone.js.map +1 -1
  339. package/validators/gte.js +0 -8
  340. package/validators/gte.js.map +1 -1
  341. package/validators/in.js +0 -8
  342. package/validators/in.js.map +1 -1
  343. package/validators/index.js +0 -16
  344. package/validators/index.js.map +1 -1
  345. package/validators/lte.js +0 -8
  346. package/validators/lte.js.map +1 -1
  347. package/validators/maxLength.js +0 -8
  348. package/validators/maxLength.js.map +1 -1
  349. package/validators/minLength.js +0 -8
  350. package/validators/minLength.js.map +1 -1
  351. package/validators/pattern.js +0 -9
  352. package/validators/pattern.js.map +1 -1
  353. package/validators/patternPlugins/email.js +0 -2
  354. package/validators/patternPlugins/email.js.map +1 -1
  355. package/validators/patternPlugins/index.js +0 -8
  356. package/validators/patternPlugins/index.js.map +1 -1
  357. package/validators/patternPlugins/lowerCase.js +0 -2
  358. package/validators/patternPlugins/lowerCase.js.map +1 -1
  359. package/validators/patternPlugins/lowerCaseSpace.js +0 -2
  360. package/validators/patternPlugins/lowerCaseSpace.js.map +1 -1
  361. package/validators/patternPlugins/upperCase.js +0 -2
  362. package/validators/patternPlugins/upperCase.js.map +1 -1
  363. package/validators/patternPlugins/upperCaseSpace.js +0 -2
  364. package/validators/patternPlugins/upperCaseSpace.js.map +1 -1
  365. package/validators/patternPlugins/url.js +0 -2
  366. package/validators/patternPlugins/url.js.map +1 -1
  367. package/validators/required.js +0 -5
  368. package/validators/required.js.map +1 -1
  369. package/validators/timeGte.js +0 -8
  370. package/validators/timeGte.js.map +1 -1
  371. package/validators/timeLte.js +0 -8
  372. package/validators/timeLte.js.map +1 -1
  373. package/validators/unique.js +0 -7
  374. package/validators/unique.js.map +1 -1
@@ -1,24 +1,16 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.ConverterCollection = void 0;
9
-
10
8
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
-
12
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
-
14
10
  var _error = _interopRequireDefault(require("@webiny/error"));
15
-
16
11
  var _Converter = require("./Converter");
17
-
18
12
  var _plugins = require("../../plugins");
19
-
20
13
  var _getBaseFieldType = require("../getBaseFieldType");
21
-
22
14
  class ConverterCollection {
23
15
  constructor(params) {
24
16
  (0, _defineProperty2.default)(this, "converters", new Map());
@@ -28,11 +20,9 @@ class ConverterCollection {
28
20
  const fieldGraphQLPlugins = plugins.byType("cms-model-field-to-graphql");
29
21
  const fieldConverterPlugins = plugins.byType(_plugins.CmsModelFieldConverterPlugin.type);
30
22
  const defaultFieldConverterPlugin = fieldConverterPlugins.find(pl => pl.getFieldType() === "*");
31
-
32
23
  if (defaultFieldConverterPlugin === undefined) {
33
24
  throw new _error.default(`Missing default field converter plugin.`, "DEFAULT_FIELD_CONVERTER_ERROR");
34
25
  }
35
-
36
26
  for (const fieldGraphQLPlugin of fieldGraphQLPlugins) {
37
27
  const plugin = fieldConverterPlugins.find(pl => pl.getFieldType() === fieldGraphQLPlugin.fieldType);
38
28
  const converter = new _Converter.Converter({
@@ -42,43 +32,34 @@ class ConverterCollection {
42
32
  this.addConverter(converter);
43
33
  }
44
34
  }
45
-
46
35
  addConverter(converter) {
47
36
  converter.setConverterCollection(this);
48
37
  this.converters.set(converter.getType(), converter);
49
38
  }
50
-
51
39
  getConverter(type) {
52
40
  const converter = this.converters.get(type);
53
-
54
41
  if (converter === undefined) {
55
42
  throw new _error.default(`Missing converter for field type "${type}".`, "CONVERTER_ERROR", {
56
43
  type
57
44
  });
58
45
  }
59
-
60
46
  return converter;
61
47
  }
62
-
63
48
  convertToStorage(params) {
64
49
  const {
65
50
  fields,
66
51
  values: inputValues
67
52
  } = params;
68
-
69
53
  if (inputValues === undefined) {
70
54
  return undefined;
71
55
  }
72
-
73
56
  this.attachHasOwnProperty(inputValues);
74
57
  return fields.reduce((output, field) => {
75
58
  const baseType = (0, _getBaseFieldType.getBaseFieldType)(field);
76
59
  const converter = this.getConverter(baseType);
77
-
78
60
  if (inputValues === null || inputValues.hasOwnProperty(field.fieldId) === false) {
79
61
  return output;
80
62
  }
81
-
82
63
  const values = converter.convertToStorage({
83
64
  field,
84
65
  value: inputValues[field.fieldId]
@@ -86,25 +67,20 @@ class ConverterCollection {
86
67
  return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, output), values);
87
68
  }, {});
88
69
  }
89
-
90
70
  convertFromStorage(params) {
91
71
  const {
92
72
  fields,
93
73
  values: inputValues
94
74
  } = params;
95
-
96
75
  if (inputValues === undefined) {
97
76
  return undefined;
98
77
  }
99
-
100
78
  return fields.reduce((output, field) => {
101
79
  const baseType = (0, _getBaseFieldType.getBaseFieldType)(field);
102
80
  const converter = this.getConverter(baseType);
103
-
104
81
  if (inputValues === null || inputValues.hasOwnProperty(field.storageId) === false) {
105
82
  return output;
106
83
  }
107
-
108
84
  const values = converter.convertFromStorage({
109
85
  field,
110
86
  value: inputValues[field.storageId]
@@ -112,23 +88,25 @@ class ConverterCollection {
112
88
  return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, output), values);
113
89
  }, {});
114
90
  }
91
+
115
92
  /**
116
93
  * This method attaches hasOwnProperty when received object was created via Object.create(null) - no inheritance of Object.
117
94
  * At that point, hasOwnProperty does not exist, and we need to add it.
118
95
  *
119
96
  * TODO add more checks if required
120
97
  */
121
-
122
-
123
98
  attachHasOwnProperty(values) {
124
- if ( // null or undefined?
125
- values === null || values === undefined || // not an object?
126
- typeof values !== "object" || // maybe it's an array?
127
- Array.isArray(values) || // and in the end, check if hasOwnProperty is a function already
99
+ if (
100
+ // null or undefined?
101
+ values === null || values === undefined ||
102
+ // not an object?
103
+ typeof values !== "object" ||
104
+ // maybe it's an array?
105
+ Array.isArray(values) ||
106
+ // and in the end, check if hasOwnProperty is a function already
128
107
  typeof (values === null || values === void 0 ? void 0 : values.hasOwnProperty) === "function") {
129
108
  return;
130
109
  }
131
-
132
110
  Object.defineProperty(values, "hasOwnProperty", {
133
111
  enumerable: false,
134
112
  writable: false,
@@ -137,7 +115,5 @@ class ConverterCollection {
137
115
  }
138
116
  });
139
117
  }
140
-
141
118
  }
142
-
143
119
  exports.ConverterCollection = ConverterCollection;
@@ -1 +1 @@
1
- {"version":3,"names":["ConverterCollection","constructor","params","Map","plugins","fieldGraphQLPlugins","byType","fieldConverterPlugins","CmsModelFieldConverterPlugin","type","defaultFieldConverterPlugin","find","pl","getFieldType","undefined","WebinyError","fieldGraphQLPlugin","plugin","fieldType","converter","Converter","addConverter","setConverterCollection","converters","set","getType","getConverter","get","convertToStorage","fields","values","inputValues","attachHasOwnProperty","reduce","output","field","baseType","getBaseFieldType","hasOwnProperty","fieldId","value","convertFromStorage","storageId","Array","isArray","Object","defineProperty","enumerable","writable","property"],"sources":["ConverterCollection.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { Converter } from \"./Converter\";\nimport { CmsEntryValues, CmsModelField, CmsModelFieldToGraphQLPlugin } from \"~/types\";\nimport { CmsModelFieldConverterPlugin } from \"~/plugins\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { getBaseFieldType } from \"~/utils/getBaseFieldType\";\n\nexport interface CmsModelFieldsWithParent extends CmsModelField {\n parent?: CmsModelField | null;\n}\n\nexport interface CmsModelConverterCallable {\n (params: ConverterCollectionConvertParams): CmsEntryValues;\n}\n\nexport interface ConverterCollectionConvertParams {\n fields: CmsModelFieldsWithParent[];\n values?: CmsEntryValues;\n}\n\nexport interface ConverterCollectionParams {\n plugins: PluginsContainer;\n}\n\nexport class ConverterCollection {\n private readonly converters: Map<string, Converter> = new Map();\n\n public constructor(params: ConverterCollectionParams) {\n const { plugins } = params;\n const fieldGraphQLPlugins = plugins.byType<CmsModelFieldToGraphQLPlugin>(\n \"cms-model-field-to-graphql\"\n );\n const fieldConverterPlugins = plugins.byType<CmsModelFieldConverterPlugin>(\n CmsModelFieldConverterPlugin.type\n );\n const defaultFieldConverterPlugin = fieldConverterPlugins.find(\n pl => pl.getFieldType() === \"*\"\n );\n if (defaultFieldConverterPlugin === undefined) {\n throw new WebinyError(\n `Missing default field converter plugin.`,\n \"DEFAULT_FIELD_CONVERTER_ERROR\"\n );\n }\n for (const fieldGraphQLPlugin of fieldGraphQLPlugins) {\n const plugin = fieldConverterPlugins.find(\n pl => pl.getFieldType() === fieldGraphQLPlugin.fieldType\n );\n const converter = new Converter({\n type: fieldGraphQLPlugin.fieldType,\n plugin: plugin || defaultFieldConverterPlugin\n });\n\n this.addConverter(converter);\n }\n }\n\n public addConverter(converter: Converter): void {\n converter.setConverterCollection(this);\n this.converters.set(converter.getType(), converter);\n }\n\n public getConverter(type: string): Converter {\n const converter = this.converters.get(type);\n if (converter === undefined) {\n throw new WebinyError(\n `Missing converter for field type \"${type}\".`,\n \"CONVERTER_ERROR\",\n {\n type\n }\n );\n }\n return converter;\n }\n\n public convertToStorage(params: ConverterCollectionConvertParams): CmsEntryValues | undefined {\n const { fields, values: inputValues } = params;\n if (inputValues === undefined) {\n return undefined;\n }\n\n this.attachHasOwnProperty(inputValues);\n\n return fields.reduce<CmsEntryValues>((output, field) => {\n const baseType = getBaseFieldType(field);\n const converter = this.getConverter(baseType);\n if (inputValues === null || inputValues.hasOwnProperty(field.fieldId) === false) {\n return output;\n }\n const values = converter.convertToStorage({\n field,\n value: inputValues[field.fieldId]\n });\n\n return {\n ...output,\n ...values\n };\n }, {});\n }\n\n public convertFromStorage(\n params: ConverterCollectionConvertParams\n ): CmsEntryValues | undefined {\n const { fields, values: inputValues } = params;\n if (inputValues === undefined) {\n return undefined;\n }\n\n return fields.reduce((output, field) => {\n const baseType = getBaseFieldType(field);\n const converter = this.getConverter(baseType);\n if (inputValues === null || inputValues.hasOwnProperty(field.storageId) === false) {\n return output;\n }\n const values = converter.convertFromStorage({\n field,\n value: inputValues[field.storageId]\n });\n\n return {\n ...output,\n ...values\n };\n }, {});\n }\n\n /**\n * This method attaches hasOwnProperty when received object was created via Object.create(null) - no inheritance of Object.\n * At that point, hasOwnProperty does not exist, and we need to add it.\n *\n * TODO add more checks if required\n */\n private attachHasOwnProperty(values: CmsEntryValues) {\n if (\n // null or undefined?\n values === null ||\n values === undefined ||\n // not an object?\n typeof values !== \"object\" ||\n // maybe it's an array?\n Array.isArray(values) ||\n // and in the end, check if hasOwnProperty is a function already\n typeof values?.hasOwnProperty === \"function\"\n ) {\n return;\n }\n Object.defineProperty(values, \"hasOwnProperty\", {\n enumerable: false,\n writable: false,\n value: function (property: string) {\n return this[property] !== undefined;\n }\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAAA;;AACA;;AAEA;;AAEA;;AAmBO,MAAMA,mBAAN,CAA0B;EAGtBC,WAAW,CAACC,MAAD,EAAoC;IAAA,kDAFA,IAAIC,GAAJ,EAEA;IAClD,MAAM;MAAEC;IAAF,IAAcF,MAApB;IACA,MAAMG,mBAAmB,GAAGD,OAAO,CAACE,MAAR,CACxB,4BADwB,CAA5B;IAGA,MAAMC,qBAAqB,GAAGH,OAAO,CAACE,MAAR,CAC1BE,qCAAA,CAA6BC,IADH,CAA9B;IAGA,MAAMC,2BAA2B,GAAGH,qBAAqB,CAACI,IAAtB,CAChCC,EAAE,IAAIA,EAAE,CAACC,YAAH,OAAsB,GADI,CAApC;;IAGA,IAAIH,2BAA2B,KAAKI,SAApC,EAA+C;MAC3C,MAAM,IAAIC,cAAJ,CACD,yCADC,EAEF,+BAFE,CAAN;IAIH;;IACD,KAAK,MAAMC,kBAAX,IAAiCX,mBAAjC,EAAsD;MAClD,MAAMY,MAAM,GAAGV,qBAAqB,CAACI,IAAtB,CACXC,EAAE,IAAIA,EAAE,CAACC,YAAH,OAAsBG,kBAAkB,CAACE,SADpC,CAAf;MAGA,MA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AC5CiB,UAAU,EAAE,KADgC;MAE5CC,QAAQ,EAAE,KAFkC;MAG5CR,KAAK,EAAE,UAAUS,QAAV,EAA4B;QAC/B,OAAO,KAAKA,QAAL,MAAmBnC,SAA1B;MACH;IAL2C,CAAhD;EAOH;;AAnI4B"}
1
+ {"version":3,"names":["ConverterCollection","constructor","params","Map","plugins","fieldGraphQLPlugins","byType","fieldConverterPlugins","CmsModelFieldConverterPlugin","type","defaultFieldConverterPlugin","find","pl","getFieldType","undefined","WebinyError","fieldGraphQLPlugin","plugin","fieldType","converter","Converter","addConverter","setConverterCollection","converters","set","getType","getConverter","get","convertToStorage","fields","values","inputValues","attachHasOwnProperty","reduce","output","field","baseType","getBaseFieldType","hasOwnProperty","fieldId","value","convertFromStorage","storageId","Array","isArray","Object","defineProperty","enumerable","writable","property"],"sources":["ConverterCollection.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { Converter } from \"./Converter\";\nimport { CmsEntryValues, CmsModelField, CmsModelFieldToGraphQLPlugin } from \"~/types\";\nimport { CmsModelFieldConverterPlugin } from \"~/plugins\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { getBaseFieldType } from \"~/utils/getBaseFieldType\";\n\nexport interface CmsModelFieldsWithParent extends CmsModelField {\n parent?: CmsModelField | null;\n}\n\nexport interface CmsModelConverterCallable {\n (params: ConverterCollectionConvertParams): CmsEntryValues;\n}\n\nexport interface ConverterCollectionConvertParams {\n fields: CmsModelFieldsWithParent[];\n values?: CmsEntryValues;\n}\n\nexport interface ConverterCollectionParams {\n plugins: PluginsContainer;\n}\n\nexport class ConverterCollection {\n private readonly converters: Map<string, Converter> = new Map();\n\n public constructor(params: ConverterCollectionParams) {\n const { plugins } = params;\n const fieldGraphQLPlugins = plugins.byType<CmsModelFieldToGraphQLPlugin>(\n \"cms-model-field-to-graphql\"\n );\n const fieldConverterPlugins = plugins.byType<CmsModelFieldConverterPlugin>(\n CmsModelFieldConverterPlugin.type\n );\n const defaultFieldConverterPlugin = fieldConverterPlugins.find(\n pl => pl.getFieldType() === \"*\"\n );\n if (defaultFieldConverterPlugin === undefined) {\n throw new WebinyError(\n `Missing default field converter plugin.`,\n \"DEFAULT_FIELD_CONVERTER_ERROR\"\n );\n }\n for (const fieldGraphQLPlugin of fieldGraphQLPlugins) {\n const plugin = fieldConverterPlugins.find(\n pl => pl.getFieldType() === fieldGraphQLPlugin.fieldType\n );\n const converter = new Converter({\n type: fieldGraphQLPlugin.fieldType,\n plugin: plugin || defaultFieldConverterPlugin\n });\n\n this.addConverter(converter);\n }\n }\n\n public addConverter(converter: Converter): void {\n converter.setConverterCollection(this);\n this.converters.set(converter.getType(), converter);\n }\n\n public getConverter(type: string): Converter {\n const converter = this.converters.get(type);\n if (converter === undefined) {\n throw new WebinyError(\n `Missing converter for field type \"${type}\".`,\n \"CONVERTER_ERROR\",\n {\n type\n }\n );\n }\n return converter;\n }\n\n public convertToStorage(params: ConverterCollectionConvertParams): CmsEntryValues | undefined {\n const { fields, values: inputValues } = params;\n if (inputValues === undefined) {\n return undefined;\n }\n\n this.attachHasOwnProperty(inputValues);\n\n return fields.reduce<CmsEntryValues>((output, field) => {\n const baseType = getBaseFieldType(field);\n const converter = this.getConverter(baseType);\n if (inputValues === null || inputValues.hasOwnProperty(field.fieldId) === false) {\n return output;\n }\n const values = converter.convertToStorage({\n field,\n value: inputValues[field.fieldId]\n });\n\n return {\n ...output,\n ...values\n };\n }, {});\n }\n\n public convertFromStorage(\n params: ConverterCollectionConvertParams\n ): CmsEntryValues | undefined {\n const { fields, values: inputValues } = params;\n if (inputValues === undefined) {\n return undefined;\n }\n\n return fields.reduce((output, field) => {\n const baseType = getBaseFieldType(field);\n const converter = this.getConverter(baseType);\n if (inputValues === null || inputValues.hasOwnProperty(field.storageId) === false) {\n return output;\n }\n const values = converter.convertFromStorage({\n field,\n value: inputValues[field.storageId]\n });\n\n return {\n ...output,\n ...values\n };\n }, {});\n }\n\n /**\n * This method attaches hasOwnProperty when received object was created via Object.create(null) - no inheritance of Object.\n * At that point, hasOwnProperty does not exist, and we need to add it.\n *\n * TODO add more checks if required\n */\n private attachHasOwnProperty(values: CmsEntryValues) {\n if (\n // null or undefined?\n values === null ||\n values === undefined ||\n // not an object?\n typeof values !== \"object\" ||\n // maybe it's an array?\n Array.isArray(values) ||\n // and in the end, check if hasOwnProperty is a function already\n typeof values?.hasOwnProperty === \"function\"\n ) {\n return;\n }\n Object.defineProperty(values, \"hasOwnProperty\", {\n enumerable: false,\n writable: false,\n value: function (property: string) {\n return this[property] !== undefined;\n }\n });\n }\n}\n"],"mappings":";;;;;;;;;AAAA;AACA;AAEA;AAEA;AAmBO,MAAMA,mBAAmB,CAAC;EAGtBC,WAAW,CAACC,MAAiC,EAAE;IAAA,kDAFA,IAAIC,GAAG,EAAE;IAG3D,MAAM;MAAEC;IAAQ,CAAC,GAAGF,MAAM;IAC1B,MAAMG,mBAAmB,GAAGD,OAAO,CAACE,MAAM,CACtC,4BAA4B,CAC/B;IACD,MAAMC,qBAAqB,GAAGH,OAAO,CAACE,MAAM,CACxCE,qCAA4B,CAACC,IAAI,CACpC;IACD,MAAMC,2BAA2B,GAAGH,qBAAqB,CAACI,IAAI,CAC1DC,EAAE,IAAIA,EAAE,CAACC,YAAY,EAAE,KAAK,GAAG,CAClC;IACD,IAAIH,2BAA2B,KAAKI,SAAS,EAAE;MAC3C,MAAM,IAAIC,cAAW,CAChB,yCAAwC,EACzC,+BAA+B,CAClC;IACL;IACA,KAAK,MAAMC,kBAAkB,IAAIX,mBAAmB,EAAE;MAClD,MAAMY,MAAM,GAAGV,qBAAqB,CAACI,IAAI,CACrCC,EAAE,IAAIA,EAAE,CAACC,YAAY,EAAE,KAAKG,kBAAkB,CAACE,SAAS,CAC3D;MACD,MAAMC,SAAS,GAAG,IAAIC,oBAAS,CAAC;QAC5BX,IAAI,EAAEO,kBAAkB,CAACE,SAAS;QAClCD,MAAM,EAAEA,MAAM,IAAIP;MACtB,CAAC,CAAC;MAEF,IAAI,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KnC,SAAS;MACvC;IACJ,CAAC,CAAC;EACN;AACJ;AAAC"}
@@ -10,9 +10,5 @@ interface Params {
10
10
  }
11
11
  export declare const createValueKeyToStorageConverter: (params: Params) => CmsModelConverterCallable;
12
12
  export declare const createValueKeyFromStorageConverter: (params: Params) => CmsModelConverterCallable;
13
- interface AttachConvertersParams {
14
- plugins: PluginsContainer;
15
- model: CmsModel;
16
- }
17
- export declare const attachCmsModelFieldConverters: (params: AttachConvertersParams) => StorageOperationsCmsModel;
13
+ export declare const createCmsModelFieldConvertersAttachFactory: (plugins: PluginsContainer) => (model: StorageOperationsCmsModel | CmsModel) => StorageOperationsCmsModel;
18
14
  export {};
@@ -1,28 +1,20 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
- exports.createValueKeyToStorageConverter = exports.createValueKeyFromStorageConverter = exports.attachCmsModelFieldConverters = void 0;
9
-
7
+ exports.createValueKeyToStorageConverter = exports.createValueKeyFromStorageConverter = exports.createCmsModelFieldConvertersAttachFactory = void 0;
10
8
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
-
12
9
  var _ConverterCollection = require("./ConverterCollection");
13
-
14
10
  var _semver = _interopRequireDefault(require("semver"));
15
-
16
11
  const featureVersion = _semver.default.coerce("5.33.0");
17
-
18
12
  const isBetaOrNext = model => {
19
13
  if (!model.webinyVersion) {
20
14
  return false;
21
15
  }
22
-
23
16
  return model.webinyVersion.match(/next|beta/) !== null;
24
17
  };
25
-
26
18
  const isFeatureEnabled = model => {
27
19
  /**
28
20
  * In case of disabled webinyVersion value, we disable this feature.
@@ -34,16 +26,13 @@ const isFeatureEnabled = model => {
34
26
  /**
35
27
  * If is a test environment, always have this turned on.
36
28
  */
37
-
38
-
39
- if (process.env.NODE_ENV === "test" || isBetaOrNext(model) === true) {
29
+ const nodeEnv = process.env.NODE_ENV;
30
+ if (nodeEnv === "test" || nodeEnv === "disable" || isBetaOrNext(model)) {
40
31
  return true;
41
32
  }
42
33
  /**
43
34
  * Possibility that the version is not defined, this means it is a quite old system where models did not change.
44
35
  */
45
-
46
-
47
36
  if (!model.webinyVersion) {
48
37
  return false;
49
38
  }
@@ -52,26 +41,20 @@ const isFeatureEnabled = model => {
52
41
  *
53
42
  * TODO change if necessary after the update to the system
54
43
  */
55
-
56
-
57
44
  const modelVersion = _semver.default.coerce(model.webinyVersion);
58
-
59
45
  if (!modelVersion) {
60
46
  console.log(`Warning: Model "${model.modelId}" does not have valid Webiny version set.`);
61
47
  return true;
62
48
  } else if (_semver.default.compare(modelVersion, featureVersion) === -1) {
63
49
  return false;
64
50
  }
65
-
66
51
  return true;
67
52
  };
68
-
69
53
  const createValueKeyToStorageConverter = params => {
70
54
  const {
71
55
  plugins,
72
56
  model
73
57
  } = params;
74
-
75
58
  if (isFeatureEnabled(model) === false) {
76
59
  return ({
77
60
  values
@@ -79,7 +62,6 @@ const createValueKeyToStorageConverter = params => {
79
62
  return values || {};
80
63
  };
81
64
  }
82
-
83
65
  const converters = new _ConverterCollection.ConverterCollection({
84
66
  plugins
85
67
  });
@@ -94,15 +76,12 @@ const createValueKeyToStorageConverter = params => {
94
76
  return result || {};
95
77
  };
96
78
  };
97
-
98
79
  exports.createValueKeyToStorageConverter = createValueKeyToStorageConverter;
99
-
100
80
  const createValueKeyFromStorageConverter = params => {
101
81
  const {
102
82
  plugins,
103
83
  model
104
84
  } = params;
105
-
106
85
  if (isFeatureEnabled(model) === false) {
107
86
  return ({
108
87
  values
@@ -110,7 +89,6 @@ const createValueKeyFromStorageConverter = params => {
110
89
  return values || {};
111
90
  };
112
91
  }
113
-
114
92
  const converters = new _ConverterCollection.ConverterCollection({
115
93
  plugins
116
94
  });
@@ -125,24 +103,23 @@ const createValueKeyFromStorageConverter = params => {
125
103
  return result || {};
126
104
  };
127
105
  };
128
-
129
106
  exports.createValueKeyFromStorageConverter = createValueKeyFromStorageConverter;
130
-
131
- const attachCmsModelFieldConverters = params => {
132
- const {
133
- model,
134
- plugins
135
- } = params;
136
- return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, model), {}, {
137
- convertValueKeyToStorage: createValueKeyToStorageConverter({
138
- model,
139
- plugins
140
- }),
141
- convertValueKeyFromStorage: createValueKeyFromStorageConverter({
142
- model,
143
- plugins
144
- })
145
- });
107
+ const createCmsModelFieldConvertersAttachFactory = plugins => {
108
+ return model => {
109
+ const storageModel = model;
110
+ if (!!storageModel.convertValueKeyToStorage && !!storageModel.convertValueKeyFromStorage) {
111
+ return storageModel;
112
+ }
113
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, model), {}, {
114
+ convertValueKeyToStorage: createValueKeyToStorageConverter({
115
+ model,
116
+ plugins
117
+ }),
118
+ convertValueKeyFromStorage: createValueKeyFromStorageConverter({
119
+ model,
120
+ plugins
121
+ })
122
+ });
123
+ };
146
124
  };
147
-
148
- exports.attachCmsModelFieldConverters = attachCmsModelFieldConverters;
125
+ exports.createCmsModelFieldConvertersAttachFactory = createCmsModelFieldConvertersAttachFactory;
@@ -1 +1 @@
1
- {"version":3,"names":["featureVersion","semver","coerce","isBetaOrNext","model","webinyVersion","match","isFeatureEnabled","process","env","NODE_ENV","modelVersion","console","log","modelId","compare","createValueKeyToStorageConverter","params","plugins","values","converters","ConverterCollection","fields","result","convertToStorage","createValueKeyFromStorageConverter","convertFromStorage","attachCmsModelFieldConverters","convertValueKeyToStorage","convertValueKeyFromStorage"],"sources":["valueKeyStorageConverter.ts"],"sourcesContent":["import { PluginsContainer } from \"@webiny/plugins\";\nimport {\n CmsModelConverterCallable,\n ConverterCollection,\n ConverterCollectionConvertParams as BaseConverterCollectionConvertParams\n} from \"~/utils/converters/ConverterCollection\";\nimport { CmsModel, StorageOperationsCmsModel } from \"~/types\";\nimport semver, { SemVer } from \"semver\";\n\nconst featureVersion = semver.coerce(\"5.33.0\") as SemVer;\n\nconst isBetaOrNext = (model: CmsModel): boolean => {\n if (!model.webinyVersion) {\n return false;\n }\n return model.webinyVersion.match(/next|beta/) !== null;\n};\n\nconst isFeatureEnabled = (model: CmsModel): boolean => {\n /**\n * In case of disabled webinyVersion value, we disable this feature.\n * This is only for testing...\n */\n if (model.webinyVersion === \"disable\") {\n return false;\n }\n /**\n * If is a test environment, always have this turned on.\n */\n if (process.env.NODE_ENV === \"test\" || isBetaOrNext(model) === true) {\n return true;\n }\n /**\n * Possibility that the version is not defined, this means it is a quite old system where models did not change.\n */\n if (!model.webinyVersion) {\n return false;\n }\n /**\n * In case feature version value is greater than the model version, feature is not enabled as it is an older model with no storageId.\n *\n * TODO change if necessary after the update to the system\n */\n const modelVersion = semver.coerce(model.webinyVersion);\n if (!modelVersion) {\n console.log(`Warning: Model \"${model.modelId}\" does not have valid Webiny version set.`);\n return true;\n } else if (semver.compare(modelVersion, featureVersion) === -1) {\n return false;\n }\n return true;\n};\n\ninterface Params {\n /**\n * We need a model to determine if the conversion feature is enabled.\n */\n model: CmsModel;\n plugins: PluginsContainer;\n}\n\n/**\n * In the first call of the converter we do not need the fields property as it will be taken directly from the model.\n */\ninterface ConverterCollectionConvertParams\n extends Omit<BaseConverterCollectionConvertParams, \"fields\"> {\n fields?: BaseConverterCollectionConvertParams[\"fields\"];\n}\n\nexport const createValueKeyToStorageConverter = (params: Params): CmsModelConverterCallable => {\n const { plugins, model } = params;\n\n if (isFeatureEnabled(model) === false) {\n return ({ values }: ConverterCollectionConvertParams) => {\n return values || {};\n };\n }\n\n const converters = new ConverterCollection({\n plugins\n });\n\n return ({ fields, values }: ConverterCollectionConvertParams) => {\n const result = converters.convertToStorage({\n fields: fields || model.fields,\n values\n });\n return result || {};\n };\n};\n\nexport const createValueKeyFromStorageConverter = (params: Params): CmsModelConverterCallable => {\n const { plugins, model } = params;\n\n if (isFeatureEnabled(model) === false) {\n return ({ values }: ConverterCollectionConvertParams) => {\n return values || {};\n };\n }\n\n const converters = new ConverterCollection({\n plugins\n });\n\n return ({ fields, values }: ConverterCollectionConvertParams) => {\n const result = converters.convertFromStorage({\n fields: fields || model.fields,\n values\n });\n return result || {};\n };\n};\n\ninterface AttachConvertersParams {\n plugins: PluginsContainer;\n model: CmsModel;\n}\nexport const attachCmsModelFieldConverters = (\n params: AttachConvertersParams\n): StorageOperationsCmsModel => {\n const { model, plugins } = params;\n return {\n ...model,\n convertValueKeyToStorage: createValueKeyToStorageConverter({\n model,\n plugins\n }),\n convertValueKeyFromStorage: createValueKeyFromStorageConverter({\n model,\n plugins\n })\n };\n};\n"],"mappings":";;;;;;;;;;;AACA;;AAMA;;AAEA,MAAMA,cAAc,GAAGC,eAAA,CAAOC,MAAP,CAAc,QAAd,CAAvB;;AAEA,MAAMC,YAAY,GAAIC,KAAD,IAA8B;EAC/C,IAAI,CAACA,KAAK,CAACC,aAAX,EAA0B;IACtB,OAAO,KAAP;EACH;;EACD,OAAOD,KAAK,CAACC,aAAN,CAAoBC,KAApB,CAA0B,WAA1B,MAA2C,IAAlD;AACH,CALD;;AAOA,MAAMC,gBAAgB,GAAIH,KAAD,IAA8B;EACnD;AACJ;AACA;AACA;EACI,IAAIA,KAAK,CAACC,aAAN,KAAwB,SAA5B,EAAuC;IACnC,OAAO,KAAP;EACH;EACD;AACJ;AACA;;;EACI,IAAIG,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,MAAzB,IAAmCP,YAAY,CAACC,KAAD,CAAZ,KAAwB,IAA/D,EAAqE;IACjE,OAAO,IAAP;EACH;EACD;AACJ;AACA;;;EACI,IAAI,CAACA,KAAK,CAACC,aAAX,EAA0B;IACtB,OAAO,KAAP;EACH;EACD;AACJ;AACA;AACA;AACA;;;EACI,MAAMM,YAAY,GAAGV,eAAA,CAAOC,MAAP,CAAcE,KAAK,CAACC,aAApB,CAArB;;EACA,IAAI,CAACM,YAAL,EAAmB;IACfC,OAAO,CAACC,GAAR,CAAa,mBAAkBT,KAAK,CAACU,OAAQ,2CAA7C;IACA,O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AAK,CAACkB,MADiB;MAEzCH;IAFyC,CAA9B,CAAf;IAIA,OAAOI,MAAM,IAAI,EAAjB;EACH,CAND;AAOH,CApBM;;;;AA0BA,MAAMI,6BAA6B,GACtCV,MADyC,IAEb;EAC5B,MAAM;IAAEb,KAAF;IAASc;EAAT,IAAqBD,MAA3B;EACA,mEACOb,KADP;IAEIwB,wBAAwB,EAAEZ,gCAAgC,CAAC;MACvDZ,KADuD;MAEvDc;IAFuD,CAAD,CAF9D;IAMIW,0BAA0B,EAAEJ,kCAAkC,CAAC;MAC3DrB,KAD2D;MAE3Dc;IAF2D,CAAD;EANlE;AAWH,CAfM"}
1
+ {"version":3,"names":["featureVersion","semver","coerce","isBetaOrNext","model","webinyVersion","match","isFeatureEnabled","nodeEnv","process","env","NODE_ENV","modelVersion","console","log","modelId","compare","createValueKeyToStorageConverter","params","plugins","values","converters","ConverterCollection","fields","result","convertToStorage","createValueKeyFromStorageConverter","convertFromStorage","createCmsModelFieldConvertersAttachFactory","storageModel","convertValueKeyToStorage","convertValueKeyFromStorage"],"sources":["valueKeyStorageConverter.ts"],"sourcesContent":["import { PluginsContainer } from \"@webiny/plugins\";\nimport {\n CmsModelConverterCallable,\n ConverterCollection,\n ConverterCollectionConvertParams as BaseConverterCollectionConvertParams\n} from \"~/utils/converters/ConverterCollection\";\nimport { CmsModel, StorageOperationsCmsModel } from \"~/types\";\nimport semver, { SemVer } from \"semver\";\n\nconst featureVersion = semver.coerce(\"5.33.0\") as SemVer;\n\nconst isBetaOrNext = (model: CmsModel): boolean => {\n if (!model.webinyVersion) {\n return false;\n }\n return model.webinyVersion.match(/next|beta/) !== null;\n};\n\nconst isFeatureEnabled = (model: CmsModel): boolean => {\n /**\n * In case of disabled webinyVersion value, we disable this feature.\n * This is only for testing...\n */\n if (model.webinyVersion === \"disable\") {\n return false;\n }\n /**\n * If is a test environment, always have this turned on.\n */\n const nodeEnv = process.env.NODE_ENV as string;\n if (nodeEnv === \"test\" || nodeEnv === \"disable\" || isBetaOrNext(model)) {\n return true;\n }\n /**\n * Possibility that the version is not defined, this means it is a quite old system where models did not change.\n */\n if (!model.webinyVersion) {\n return false;\n }\n /**\n * In case feature version value is greater than the model version, feature is not enabled as it is an older model with no storageId.\n *\n * TODO change if necessary after the update to the system\n */\n const modelVersion = semver.coerce(model.webinyVersion);\n if (!modelVersion) {\n console.log(`Warning: Model \"${model.modelId}\" does not have valid Webiny version set.`);\n return true;\n } else if (semver.compare(modelVersion, featureVersion) === -1) {\n return false;\n }\n return true;\n};\n\ninterface Params {\n /**\n * We need a model to determine if the conversion feature is enabled.\n */\n model: CmsModel;\n plugins: PluginsContainer;\n}\n\n/**\n * In the first call of the converter we do not need the fields property as it will be taken directly from the model.\n */\ninterface ConverterCollectionConvertParams\n extends Omit<BaseConverterCollectionConvertParams, \"fields\"> {\n fields?: BaseConverterCollectionConvertParams[\"fields\"];\n}\n\nexport const createValueKeyToStorageConverter = (params: Params): CmsModelConverterCallable => {\n const { plugins, model } = params;\n\n if (isFeatureEnabled(model) === false) {\n return ({ values }: ConverterCollectionConvertParams) => {\n return values || {};\n };\n }\n\n const converters = new ConverterCollection({\n plugins\n });\n\n return ({ fields, values }: ConverterCollectionConvertParams) => {\n const result = converters.convertToStorage({\n fields: fields || model.fields,\n values\n });\n return result || {};\n };\n};\n\nexport const createValueKeyFromStorageConverter = (params: Params): CmsModelConverterCallable => {\n const { plugins, model } = params;\n\n if (isFeatureEnabled(model) === false) {\n return ({ values }: ConverterCollectionConvertParams) => {\n return values || {};\n };\n }\n\n const converters = new ConverterCollection({\n plugins\n });\n\n return ({ fields, values }: ConverterCollectionConvertParams) => {\n const result = converters.convertFromStorage({\n fields: fields || model.fields,\n values\n });\n return result || {};\n };\n};\n\nexport const createCmsModelFieldConvertersAttachFactory = (plugins: PluginsContainer) => {\n return (model: StorageOperationsCmsModel | CmsModel): StorageOperationsCmsModel => {\n const storageModel = model as Partial<StorageOperationsCmsModel>;\n if (!!storageModel.convertValueKeyToStorage && !!storageModel.convertValueKeyFromStorage) {\n return storageModel as StorageOperationsCmsModel;\n }\n return {\n ...model,\n convertValueKeyToStorage: createValueKeyToStorageConverter({\n model,\n plugins\n }),\n convertValueKeyFromStorage: createValueKeyFromStorageConverter({\n model,\n plugins\n })\n };\n };\n};\n"],"mappings":";;;;;;;;AACA;AAMA;AAEA,MAAMA,cAAc,GAAGC,eAAM,CAACC,MAAM,CAAC,QAAQ,CAAW;AAExD,MAAMC,YAAY,GAAIC,KAAe,IAAc;EAC/C,IAAI,CAACA,KAAK,CAACC,aAAa,EAAE;IACtB,OAAO,KAAK;EAChB;EACA,OAAOD,KAAK,CAACC,aAAa,CAACC,KAAK,CAAC,WAAW,CAAC,KAAK,IAAI;AAC1D,CAAC;AAED,MAAMC,gBAAgB,GAAIH,KAAe,IAAc;EACnD;AACJ;AACA;AACA;EACI,IAAIA,KAAK,CAACC,aAAa,KAAK,SAAS,EAAE;IACnC,OAAO,KAAK;EAChB;EACA;AACJ;AACA;EACI,MAAMG,OAAO,GAAGC,OAAO,CAACC,GAAG,CAACC,QAAkB;EAC9C,IAAIH,OAAO,KAAK,MAAM,IAAIA,OAAO,KAAK,SAAS,IAAIL,YAAY,CAACC,KAAK,CAAC,EAAE;IACpE,OAAO,IAAI;EACf;EACA;AACJ;AACA;EACI,IAAI,CAACA,KAAK,CAACC,aAAa,EAAE;IACtB,OAAO,KAAK;EAChB;EACA;AACJ;AACA;AACA;AACA;EACI,MAAMO,YAAY,GAAGX,eAAM,CAACC,MAAM,CAACE,KAAK,CAACC,aAAa,CAAC;EACvD,IAAI,CAACO,YAAY,EAAE;IACfC,OAAO,CAACC,GAAG,CAAE,mBAAkBV,KAAK,CAACW,OAAQ,2CAA0C,CAAC;IACxF,OAAO,IAAI;EACf,CAAC,MAAM,IAAId,eAAM,CAACe,OAAO,CAACJ,YAAY,EAAEZ,cAAc,CAAC,KAAK,CAAC,CAAC,EAAE;IAC5D,OAAO,KAAK;EAChB;EACA,OAAO,IAAI;AACf,CA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AAQf,KAA2C,IAAgC;IAC/E,MAAMyB,YAAY,GAAGzB,KAA2C;IAChE,IAAI,CAAC,CAACyB,YAAY,CAACC,wBAAwB,IAAI,CAAC,CAACD,YAAY,CAACE,0BAA0B,EAAE;MACtF,OAAOF,YAAY;IACvB;IACA,mEACOzB,KAAK;MACR0B,wBAAwB,EAAEb,gCAAgC,CAAC;QACvDb,KAAK;QACLe;MACJ,CAAC,CAAC;MACFY,0BAA0B,EAAEL,kCAAkC,CAAC;QAC3DtB,KAAK;QACLe;MACJ,CAAC;IAAC;EAEV,CAAC;AACL,CAAC;AAAC"}
@@ -1,6 +1,7 @@
1
1
  import { ApiEndpoint, CmsFieldTypePlugins, CmsModel, CmsModelField } from "../types";
2
2
  interface TypeFromFieldParams {
3
3
  typeOfType: "type" | "input";
4
+ models: CmsModel[];
4
5
  model: CmsModel;
5
6
  type: ApiEndpoint;
6
7
  typeNamePrefix: string;
@@ -4,65 +4,57 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.createTypeFromFields = void 0;
7
-
8
- var _createTypeName = require("./createTypeName");
9
-
10
7
  var _renderFields = require("./renderFields");
11
-
12
8
  var _renderInputFields = require("./renderInputFields");
13
-
14
9
  const createTypeFromFields = params => {
15
10
  const {
16
11
  typeOfType,
17
12
  model,
13
+ models,
18
14
  type,
19
15
  typeNamePrefix,
20
16
  fields,
21
17
  fieldTypePlugins
22
18
  } = params;
23
19
  const typeSuffix = typeOfType === "input" ? "Input" : "";
24
- const mTypeName = (0, _createTypeName.createTypeName)(model.modelId);
20
+ const mTypeName = model.singularApiName;
25
21
  const typeFields = [];
26
- const nestedTypes = []; // Once the loop below starts, we'll be executing a recursive "object" type generation.
22
+ const nestedTypes = [];
23
+
24
+ // Once the loop below starts, we'll be executing a recursive "object" type generation.
27
25
  // The main trick here is that nested objects don't know who the parent is, and will generate
28
26
  // type names using the "model", as if they're at the top level:
29
27
  // Every time the types are returned, we need to replace the model name in the generated type name
30
28
  // with the actual prefix which includes parent field name type.
31
-
32
29
  const replace = new RegExp(`${mTypeName}_`, "g");
33
-
34
- for (const f of fields) {
30
+ for (const field of fields) {
35
31
  const result = typeOfType === "type" ? (0, _renderFields.renderField)({
36
- field: f,
32
+ field,
37
33
  type,
34
+ models,
38
35
  model,
39
36
  fieldTypePlugins
40
37
  }) : (0, _renderInputFields.renderInputField)({
41
- field: f,
38
+ field,
39
+ models,
42
40
  model,
43
41
  fieldTypePlugins
44
42
  });
45
-
46
43
  if (!result) {
47
44
  continue;
48
45
  }
49
-
50
46
  const {
51
47
  fields,
52
48
  typeDefs
53
49
  } = result;
54
50
  typeFields.push(fields.replace(replace, `${typeNamePrefix}_`));
55
-
56
51
  if (typeDefs) {
57
52
  nestedTypes.push(typeDefs.replace(replace, `${typeNamePrefix}_`));
58
53
  }
59
54
  }
60
-
61
55
  return {
62
56
  fieldType: `${typeNamePrefix}${typeSuffix}`,
63
- typeDefs:
64
- /* GraphQL */
65
- `
57
+ typeDefs: /* GraphQL */`
66
58
  ${nestedTypes.join("\n")}
67
59
 
68
60
  ${typeOfType} ${typeNamePrefix}${typeSuffix} {
@@ -71,5 +63,4 @@ const createTypeFromFields = params => {
71
63
  `
72
64
  };
73
65
  };
74
-
75
66
  exports.createTypeFromFields = createTypeFromFields;
@@ -1 +1 @@
1
- {"version":3,"names":["createTypeFromFields","params","typeOfType","model","type","typeNamePrefix","fields","fieldTypePlugins","typeSuffix","mTypeName","createTypeName","modelId","typeFields","nestedTypes","replace","RegExp","f","result","renderField","field","renderInputField","typeDefs","push","fieldType","join"],"sources":["createTypeFromFields.ts"],"sourcesContent":["import { createTypeName } from \"~/utils/createTypeName\";\nimport { renderField } from \"~/utils/renderFields\";\nimport { renderInputField } from \"~/utils/renderInputFields\";\nimport { ApiEndpoint, CmsFieldTypePlugins, CmsModel, CmsModelField } from \"~/types\";\n\ninterface TypeFromFieldParams {\n typeOfType: \"type\" | \"input\";\n model: CmsModel;\n type: ApiEndpoint;\n typeNamePrefix: string;\n fields: CmsModelField[];\n fieldTypePlugins: CmsFieldTypePlugins;\n}\n\ninterface TypeFromFieldResponse {\n fieldType: string;\n typeDefs: string;\n}\n\nexport const createTypeFromFields = (params: TypeFromFieldParams): TypeFromFieldResponse | null => {\n const { typeOfType, model, type, typeNamePrefix, fields, fieldTypePlugins } = params;\n const typeSuffix = typeOfType === \"input\" ? \"Input\" : \"\";\n const mTypeName = createTypeName(model.modelId);\n\n const typeFields = [];\n const nestedTypes = [];\n\n // Once the loop below starts, we'll be executing a recursive \"object\" type generation.\n // The main trick here is that nested objects don't know who the parent is, and will generate\n // type names using the \"model\", as if they're at the top level:\n // Every time the types are returned, we need to replace the model name in the generated type name\n // with the actual prefix which includes parent field name type.\n const replace = new RegExp(`${mTypeName}_`, \"g\");\n\n for (const f of fields) {\n const result =\n typeOfType === \"type\"\n ? renderField({ field: f, type, model, fieldTypePlugins })\n : renderInputField({ field: f, model, fieldTypePlugins });\n\n if (!result) {\n continue;\n }\n\n const { fields, typeDefs } = result;\n\n typeFields.push(fields.replace(replace, `${typeNamePrefix}_`));\n if (typeDefs) {\n nestedTypes.push(typeDefs.replace(replace, `${typeNamePrefix}_`));\n }\n }\n\n return {\n fieldType: `${typeNamePrefix}${typeSuffix}`,\n typeDefs: /* GraphQL */ `\n ${nestedTypes.join(\"\\n\")}\n\n ${typeOfType} ${typeNamePrefix}${typeSuffix} {\n ${typeFields.join(\"\\n\")}\n }\n `\n };\n};\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAiBO,MAAMA,oBAAoB,GAAIC,MAAD,IAA+D;EAC/F,MAAM;IAAEC,UAAF;IAAcC,KAAd;IAAqBC,IAArB;IAA2BC,cAA3B;IAA2CC,MAA3C;IAAmDC;EAAnD,IAAwEN,MAA9E;EACA,MAAMO,UAAU,GAAGN,UAAU,KAAK,OAAf,GAAyB,OAAzB,GAAmC,EAAtD;EACA,MAAMO,SAAS,GAAG,IAAAC,8BAAA,EAAeP,KAAK,CAACQ,OAArB,CAAlB;EAEA,MAAMC,UAAU,GAAG,EAAnB;EACA,MAAMC,WAAW,GAAG,EAApB,CAN+F,CAQ/F;EACA;EACA;EACA;EACA;;EACA,MAAMC,OAAO,GAAG,IAAIC,MAAJ,CAAY,GAAEN,SAAU,GAAxB,EAA4B,GAA5B,CAAhB;;EAEA,KAAK,MAAMO,CAAX,IAAgBV,MAAhB,EAAwB;IACpB,MAAMW,MAAM,GACRf,UAAU,KAAK,MAAf,GACM,IAAAgB,yBAAA,EAAY;MAAEC,KAAK,EAAEH,CAAT;MAAYZ,IAAZ;MAAkBD,KAAlB;MAAyBI;IAAzB,CAAZ,CADN,GAEM,IAAAa,mCAAA,EAAiB;MAAED,KAAK,EAAEH,CAAT;MAAYb,KAAZ;MAAmBI;IAAnB,CAAjB,CAHV;;IAKA,IAAI,CAACU,MAAL,EAAa;MACT;IACH;;IAED,MAAM;MAAEX,MAAF;MAAUe;IAAV,IAAuBJ,MAA7B;IAEAL,UAAU,CAACU,IAAX,CAAgBhB,MAAM,CAACQ,OAAP,CAAeA,OAAf,EAAyB,GAAET,cAAe,GAA1C,CAAhB;;IACA,IAAIgB,QAAJ,EAAc;MACVR,WAAW,CAACS,IAAZ,CAAiBD,QAAQ,CAACP,OAAT,CAAiBA,OAAjB,EAA2B,GAAET,cAAe,GAA5C,CAAjB;IACH;EACJ;;EAED,OAAO;IACHkB,SAAS,EAAG,GAAElB,cAAe,GAAEG,UAAW,EADvC;IAEHa,QAAQ;IAAE;IAAe;AACjC,cAAcR,WAAW,CAACW,IAAZ,CAAiB,IAAjB,CAAuB;AACrC;AACA,cAActB,UAAW,IAAGG,cAAe,GAAEG,UAAW;AACxD,kBAAkBI,UAAU,CAACY,IAAX,CAAgB,IAAhB,CAAsB;AACxC;AACA;EARW,CAAP;AAUH,CA3CM"}
1
+ {"version":3,"names":["createTypeFromFields","params","typeOfType","model","models","type","typeNamePrefix","fields","fieldTypePlugins","typeSuffix","mTypeName","singularApiName","typeFields","nestedTypes","replace","RegExp","field","result","renderField","renderInputField","typeDefs","push","fieldType","join"],"sources":["createTypeFromFields.ts"],"sourcesContent":["import { renderField } from \"~/utils/renderFields\";\nimport { renderInputField } from \"~/utils/renderInputFields\";\nimport { ApiEndpoint, CmsFieldTypePlugins, CmsModel, CmsModelField } from \"~/types\";\n\ninterface TypeFromFieldParams {\n typeOfType: \"type\" | \"input\";\n models: CmsModel[];\n model: CmsModel;\n type: ApiEndpoint;\n typeNamePrefix: string;\n fields: CmsModelField[];\n fieldTypePlugins: CmsFieldTypePlugins;\n}\n\ninterface TypeFromFieldResponse {\n fieldType: string;\n typeDefs: string;\n}\n\nexport const createTypeFromFields = (params: TypeFromFieldParams): TypeFromFieldResponse | null => {\n const { typeOfType, model, models, type, typeNamePrefix, fields, fieldTypePlugins } = params;\n const typeSuffix = typeOfType === \"input\" ? \"Input\" : \"\";\n const mTypeName = model.singularApiName;\n\n const typeFields: string[] = [];\n const nestedTypes: string[] = [];\n\n // Once the loop below starts, we'll be executing a recursive \"object\" type generation.\n // The main trick here is that nested objects don't know who the parent is, and will generate\n // type names using the \"model\", as if they're at the top level:\n // Every time the types are returned, we need to replace the model name in the generated type name\n // with the actual prefix which includes parent field name type.\n const replace = new RegExp(`${mTypeName}_`, \"g\");\n\n for (const field of fields) {\n const result =\n typeOfType === \"type\"\n ? renderField({ field, type, models, model, fieldTypePlugins })\n : renderInputField({ field, models, model, fieldTypePlugins });\n\n if (!result) {\n continue;\n }\n\n const { fields, typeDefs } = result;\n\n typeFields.push(fields.replace(replace, `${typeNamePrefix}_`));\n if (typeDefs) {\n nestedTypes.push(typeDefs.replace(replace, `${typeNamePrefix}_`));\n }\n }\n\n return {\n fieldType: `${typeNamePrefix}${typeSuffix}`,\n typeDefs: /* GraphQL */ `\n ${nestedTypes.join(\"\\n\")}\n\n ${typeOfType} ${typeNamePrefix}${typeSuffix} {\n ${typeFields.join(\"\\n\")}\n }\n `\n };\n};\n"],"mappings":";;;;;;AAAA;AACA;AAkBO,M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,cAAcrB,UAAW,IAAGI,cAAe,GAAEG,UAAW;AACxD,kBAAkBG,UAAU,CAACW,IAAI,CAAC,IAAI,CAAE;AACxC;AACA;EACI,CAAC;AACL,CAAC;AAAC"}
@@ -1,3 +1 @@
1
1
  export declare const createTypeName: (modelId: string) => string;
2
- export declare const createReadTypeName: (baseTypeName: string) => string;
3
- export declare const createManageTypeName: (baseTypeName: string) => string;
@@ -1,30 +1,13 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
- exports.createTypeName = exports.createReadTypeName = exports.createManageTypeName = void 0;
9
-
7
+ exports.createTypeName = void 0;
10
8
  var _upperFirst = _interopRequireDefault(require("lodash/upperFirst"));
11
-
12
9
  var _camelCase = _interopRequireDefault(require("lodash/camelCase"));
13
-
14
10
  const createTypeName = modelId => {
15
11
  return (0, _upperFirst.default)((0, _camelCase.default)(modelId));
16
12
  };
17
-
18
- exports.createTypeName = createTypeName;
19
-
20
- const createReadTypeName = baseTypeName => {
21
- return createTypeName(baseTypeName);
22
- };
23
-
24
- exports.createReadTypeName = createReadTypeName;
25
-
26
- const createManageTypeName = baseTypeName => {
27
- return createTypeName(baseTypeName);
28
- };
29
-
30
- exports.createManageTypeName = createManageTypeName;
13
+ exports.createTypeName = createTypeName;
@@ -1 +1 @@
1
- {"version":3,"names":["createTypeName","modelId","upperFirst","camelCase","createReadTypeName","baseTypeName","createManageTypeName"],"sources":["createTypeName.ts"],"sourcesContent":["import upperFirst from \"lodash/upperFirst\";\nimport camelCase from \"lodash/camelCase\";\n\nexport const createTypeName = (modelId: string): string => {\n return upperFirst(camelCase(modelId));\n};\n\nexport const createReadTypeName = (baseTypeName: string): string => {\n return createTypeName(baseTypeName);\n};\n\nexport const createManageTypeName = (baseTypeName: string): string => {\n return createTypeName(baseTypeName);\n};\n"],"mappings":";;;;;;;;;AAAA;;AACA;;AAEO,MAAMA,cAAc,GAAIC,OAAD,IAA6B;EACvD,OAAO,IAAAC,mBAAA,EAAW,IAAAC,kBAAA,EAAUF,OAAV,CAAX,CAAP;AACH,CAFM;;;;AAIA,MAAMG,kBAAkB,GAAIC,YAAD,IAAkC;EAChE,OAAOL,cAAc,CAACK,YAAD,CAArB;AACH,CAFM;;;;AAIA,MAAMC,oBAAoB,GAAID,YAAD,IAAkC;EAClE,OAAOL,cAAc,CAACK,YAAD,CAArB;AACH,CAFM"}
1
+ {"version":3,"names":["createTypeName","modelId","upperFirst","camelCase"],"sources":["createTypeName.ts"],"sourcesContent":["import upperFirst from \"lodash/upperFirst\";\nimport camelCase from \"lodash/camelCase\";\n\nexport const createTypeName = (modelId: string): string => {\n return upperFirst(camelCase(modelId));\n};\n"],"mappings":";;;;;;;AAAA;AACA;AAEO,MAAMA,cAAc,GAAIC,OAAe,IAAa;EACvD,OAAO,IAAAC,mBAAU,EAAC,IAAAC,kBAAS,EAACF,OAAO,CAAC,CAAC;AACzC,CAAC;AAAC"}