@contember/engine-content-api 2.0.0-alpha.19 → 2.0.0-alpha.21

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 (330) hide show
  1. package/dist/development/index.cjs +1 -1
  2. package/dist/development/index.js +1 -1
  3. package/dist/development/src/input-validation/preValidation/InputPreValidator.cjs +1 -1
  4. package/dist/development/src/input-validation/preValidation/InputPreValidator.cjs.map +1 -1
  5. package/dist/development/src/input-validation/preValidation/InputPreValidator.js +1 -1
  6. package/dist/development/src/input-validation/preValidation/InputPreValidator.js.map +1 -1
  7. package/dist/development/src/inputProcessing/CreateInputVisitor.cjs +10 -10
  8. package/dist/development/src/inputProcessing/CreateInputVisitor.cjs.map +1 -1
  9. package/dist/development/src/inputProcessing/CreateInputVisitor.js +10 -10
  10. package/dist/development/src/inputProcessing/CreateInputVisitor.js.map +1 -1
  11. package/dist/development/src/inputProcessing/UpdateInputVisitor.cjs +13 -13
  12. package/dist/development/src/inputProcessing/UpdateInputVisitor.cjs.map +1 -1
  13. package/dist/development/src/inputProcessing/UpdateInputVisitor.js +13 -13
  14. package/dist/development/src/inputProcessing/UpdateInputVisitor.js.map +1 -1
  15. package/dist/development/src/mapper/MutationProcessorHelper.cjs +10 -2
  16. package/dist/development/src/mapper/MutationProcessorHelper.cjs.map +1 -1
  17. package/dist/development/src/mapper/MutationProcessorHelper.js +10 -2
  18. package/dist/development/src/mapper/MutationProcessorHelper.js.map +1 -1
  19. package/dist/development/src/mapper/Result.cjs +10 -27
  20. package/dist/development/src/mapper/Result.cjs.map +1 -1
  21. package/dist/development/src/mapper/Result.js +10 -27
  22. package/dist/development/src/mapper/Result.js.map +1 -1
  23. package/dist/development/src/mapper/insert/InsertBuilder.cjs +1 -13
  24. package/dist/development/src/mapper/insert/InsertBuilder.cjs.map +1 -1
  25. package/dist/development/src/mapper/insert/InsertBuilder.js +1 -13
  26. package/dist/development/src/mapper/insert/InsertBuilder.js.map +1 -1
  27. package/dist/development/src/mapper/insert/Inserter.cjs +43 -21
  28. package/dist/development/src/mapper/insert/Inserter.cjs.map +1 -1
  29. package/dist/development/src/mapper/insert/Inserter.js +45 -23
  30. package/dist/development/src/mapper/insert/Inserter.js.map +1 -1
  31. package/dist/development/src/mapper/insert/SqlCreateInputProcessor.cjs +22 -76
  32. package/dist/development/src/mapper/insert/SqlCreateInputProcessor.cjs.map +1 -1
  33. package/dist/development/src/mapper/insert/SqlCreateInputProcessor.js +22 -76
  34. package/dist/development/src/mapper/insert/SqlCreateInputProcessor.js.map +1 -1
  35. package/dist/development/src/mapper/insert/relations/ManyHasManyCreateInputProcessor.cjs +45 -0
  36. package/dist/development/src/mapper/insert/relations/ManyHasManyCreateInputProcessor.cjs.map +1 -0
  37. package/dist/development/src/mapper/insert/relations/ManyHasManyCreateInputProcessor.js +45 -0
  38. package/dist/development/src/mapper/insert/relations/ManyHasManyCreateInputProcessor.js.map +1 -0
  39. package/dist/development/src/mapper/insert/relations/ManyHasOneCreateInputProcessor.cjs +42 -0
  40. package/dist/development/src/mapper/insert/relations/ManyHasOneCreateInputProcessor.cjs.map +1 -0
  41. package/dist/development/src/mapper/insert/relations/ManyHasOneCreateInputProcessor.js +42 -0
  42. package/dist/development/src/mapper/insert/relations/ManyHasOneCreateInputProcessor.js.map +1 -0
  43. package/dist/development/src/mapper/insert/relations/OneHasManyCreateInputProcessor.cjs +37 -0
  44. package/dist/development/src/mapper/insert/relations/OneHasManyCreateInputProcessor.cjs.map +1 -0
  45. package/dist/development/src/mapper/insert/relations/OneHasManyCreateInputProcessor.js +37 -0
  46. package/dist/development/src/mapper/insert/relations/OneHasManyCreateInputProcessor.js.map +1 -0
  47. package/dist/development/src/mapper/{relations → insert/relations}/OneHasOneInverseCreateInputProcessor.cjs +25 -32
  48. package/dist/development/src/mapper/insert/relations/OneHasOneInverseCreateInputProcessor.cjs.map +1 -0
  49. package/dist/development/src/mapper/{relations → insert/relations}/OneHasOneInverseCreateInputProcessor.js +25 -32
  50. package/dist/development/src/mapper/insert/relations/OneHasOneInverseCreateInputProcessor.js.map +1 -0
  51. package/dist/development/src/mapper/insert/relations/OneHasOneOwningCreateInputProcessor.cjs +67 -0
  52. package/dist/development/src/mapper/insert/relations/OneHasOneOwningCreateInputProcessor.cjs.map +1 -0
  53. package/dist/development/src/mapper/insert/relations/OneHasOneOwningCreateInputProcessor.js +67 -0
  54. package/dist/development/src/mapper/insert/relations/OneHasOneOwningCreateInputProcessor.js.map +1 -0
  55. package/dist/development/src/mapper/select/handlers/FieldsVisitor.cjs +3 -0
  56. package/dist/development/src/mapper/select/handlers/FieldsVisitor.cjs.map +1 -1
  57. package/dist/development/src/mapper/select/handlers/FieldsVisitor.js +3 -0
  58. package/dist/development/src/mapper/select/handlers/FieldsVisitor.js.map +1 -1
  59. package/dist/development/src/mapper/update/SqlUpdateInputProcessor.cjs +36 -36
  60. package/dist/development/src/mapper/update/SqlUpdateInputProcessor.cjs.map +1 -1
  61. package/dist/development/src/mapper/update/SqlUpdateInputProcessor.js +36 -36
  62. package/dist/development/src/mapper/update/SqlUpdateInputProcessor.js.map +1 -1
  63. package/dist/development/src/mapper/update/UpdateBuilder.cjs +2 -14
  64. package/dist/development/src/mapper/update/UpdateBuilder.cjs.map +1 -1
  65. package/dist/development/src/mapper/update/UpdateBuilder.js +2 -14
  66. package/dist/development/src/mapper/update/UpdateBuilder.js.map +1 -1
  67. package/dist/development/src/mapper/update/Updater.cjs +45 -17
  68. package/dist/development/src/mapper/update/Updater.cjs.map +1 -1
  69. package/dist/development/src/mapper/update/Updater.js +47 -19
  70. package/dist/development/src/mapper/update/Updater.js.map +1 -1
  71. package/dist/development/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.cjs +89 -0
  72. package/dist/development/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.cjs.map +1 -0
  73. package/dist/development/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.js +89 -0
  74. package/dist/development/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.js.map +1 -0
  75. package/dist/development/src/mapper/update/relations/ManyHasOneUpdateInputProcessor.cjs +89 -0
  76. package/dist/development/src/mapper/update/relations/ManyHasOneUpdateInputProcessor.cjs.map +1 -0
  77. package/dist/development/src/mapper/update/relations/ManyHasOneUpdateInputProcessor.js +89 -0
  78. package/dist/development/src/mapper/update/relations/ManyHasOneUpdateInputProcessor.js.map +1 -0
  79. package/dist/development/src/mapper/update/relations/OneHasManyUpdateInputProcessor.cjs +86 -0
  80. package/dist/development/src/mapper/update/relations/OneHasManyUpdateInputProcessor.cjs.map +1 -0
  81. package/dist/development/src/mapper/update/relations/OneHasManyUpdateInputProcessor.js +86 -0
  82. package/dist/development/src/mapper/update/relations/OneHasManyUpdateInputProcessor.js.map +1 -0
  83. package/dist/development/src/mapper/{relations → update/relations}/OneHasOneInverseUpdateInputProcessor.cjs +83 -66
  84. package/dist/development/src/mapper/update/relations/OneHasOneInverseUpdateInputProcessor.cjs.map +1 -0
  85. package/dist/development/src/mapper/{relations → update/relations}/OneHasOneInverseUpdateInputProcessor.js +83 -66
  86. package/dist/development/src/mapper/update/relations/OneHasOneInverseUpdateInputProcessor.js.map +1 -0
  87. package/dist/development/src/mapper/update/relations/OneHasOneOwningUpdateInputProcessor.cjs +187 -0
  88. package/dist/development/src/mapper/update/relations/OneHasOneOwningUpdateInputProcessor.cjs.map +1 -0
  89. package/dist/development/src/mapper/update/relations/OneHasOneOwningUpdateInputProcessor.js +187 -0
  90. package/dist/development/src/mapper/update/relations/OneHasOneOwningUpdateInputProcessor.js.map +1 -0
  91. package/dist/development/src/resolvers/MutationResolver.cjs +1 -1
  92. package/dist/development/src/resolvers/MutationResolver.js +1 -1
  93. package/dist/production/index.cjs +1 -1
  94. package/dist/production/index.js +1 -1
  95. package/dist/production/src/input-validation/preValidation/InputPreValidator.cjs +1 -1
  96. package/dist/production/src/input-validation/preValidation/InputPreValidator.cjs.map +1 -1
  97. package/dist/production/src/input-validation/preValidation/InputPreValidator.js +1 -1
  98. package/dist/production/src/input-validation/preValidation/InputPreValidator.js.map +1 -1
  99. package/dist/production/src/inputProcessing/CreateInputVisitor.cjs +10 -10
  100. package/dist/production/src/inputProcessing/CreateInputVisitor.cjs.map +1 -1
  101. package/dist/production/src/inputProcessing/CreateInputVisitor.js +10 -10
  102. package/dist/production/src/inputProcessing/CreateInputVisitor.js.map +1 -1
  103. package/dist/production/src/inputProcessing/UpdateInputVisitor.cjs +13 -13
  104. package/dist/production/src/inputProcessing/UpdateInputVisitor.cjs.map +1 -1
  105. package/dist/production/src/inputProcessing/UpdateInputVisitor.js +13 -13
  106. package/dist/production/src/inputProcessing/UpdateInputVisitor.js.map +1 -1
  107. package/dist/production/src/mapper/MutationProcessorHelper.cjs +10 -2
  108. package/dist/production/src/mapper/MutationProcessorHelper.cjs.map +1 -1
  109. package/dist/production/src/mapper/MutationProcessorHelper.js +10 -2
  110. package/dist/production/src/mapper/MutationProcessorHelper.js.map +1 -1
  111. package/dist/production/src/mapper/Result.cjs +10 -27
  112. package/dist/production/src/mapper/Result.cjs.map +1 -1
  113. package/dist/production/src/mapper/Result.js +10 -27
  114. package/dist/production/src/mapper/Result.js.map +1 -1
  115. package/dist/production/src/mapper/insert/InsertBuilder.cjs +1 -13
  116. package/dist/production/src/mapper/insert/InsertBuilder.cjs.map +1 -1
  117. package/dist/production/src/mapper/insert/InsertBuilder.js +1 -13
  118. package/dist/production/src/mapper/insert/InsertBuilder.js.map +1 -1
  119. package/dist/production/src/mapper/insert/Inserter.cjs +43 -21
  120. package/dist/production/src/mapper/insert/Inserter.cjs.map +1 -1
  121. package/dist/production/src/mapper/insert/Inserter.js +45 -23
  122. package/dist/production/src/mapper/insert/Inserter.js.map +1 -1
  123. package/dist/production/src/mapper/insert/SqlCreateInputProcessor.cjs +22 -76
  124. package/dist/production/src/mapper/insert/SqlCreateInputProcessor.cjs.map +1 -1
  125. package/dist/production/src/mapper/insert/SqlCreateInputProcessor.js +22 -76
  126. package/dist/production/src/mapper/insert/SqlCreateInputProcessor.js.map +1 -1
  127. package/dist/production/src/mapper/insert/relations/ManyHasManyCreateInputProcessor.cjs +45 -0
  128. package/dist/production/src/mapper/insert/relations/ManyHasManyCreateInputProcessor.cjs.map +1 -0
  129. package/dist/production/src/mapper/insert/relations/ManyHasManyCreateInputProcessor.js +45 -0
  130. package/dist/production/src/mapper/insert/relations/ManyHasManyCreateInputProcessor.js.map +1 -0
  131. package/dist/production/src/mapper/insert/relations/ManyHasOneCreateInputProcessor.cjs +42 -0
  132. package/dist/production/src/mapper/insert/relations/ManyHasOneCreateInputProcessor.cjs.map +1 -0
  133. package/dist/production/src/mapper/insert/relations/ManyHasOneCreateInputProcessor.js +42 -0
  134. package/dist/production/src/mapper/insert/relations/ManyHasOneCreateInputProcessor.js.map +1 -0
  135. package/dist/production/src/mapper/insert/relations/OneHasManyCreateInputProcessor.cjs +37 -0
  136. package/dist/production/src/mapper/insert/relations/OneHasManyCreateInputProcessor.cjs.map +1 -0
  137. package/dist/production/src/mapper/insert/relations/OneHasManyCreateInputProcessor.js +37 -0
  138. package/dist/production/src/mapper/insert/relations/OneHasManyCreateInputProcessor.js.map +1 -0
  139. package/dist/production/src/mapper/{relations → insert/relations}/OneHasOneInverseCreateInputProcessor.cjs +25 -32
  140. package/dist/production/src/mapper/insert/relations/OneHasOneInverseCreateInputProcessor.cjs.map +1 -0
  141. package/dist/production/src/mapper/{relations → insert/relations}/OneHasOneInverseCreateInputProcessor.js +25 -32
  142. package/dist/production/src/mapper/insert/relations/OneHasOneInverseCreateInputProcessor.js.map +1 -0
  143. package/dist/production/src/mapper/insert/relations/OneHasOneOwningCreateInputProcessor.cjs +67 -0
  144. package/dist/production/src/mapper/insert/relations/OneHasOneOwningCreateInputProcessor.cjs.map +1 -0
  145. package/dist/production/src/mapper/insert/relations/OneHasOneOwningCreateInputProcessor.js +67 -0
  146. package/dist/production/src/mapper/insert/relations/OneHasOneOwningCreateInputProcessor.js.map +1 -0
  147. package/dist/production/src/mapper/select/handlers/FieldsVisitor.cjs +3 -0
  148. package/dist/production/src/mapper/select/handlers/FieldsVisitor.cjs.map +1 -1
  149. package/dist/production/src/mapper/select/handlers/FieldsVisitor.js +3 -0
  150. package/dist/production/src/mapper/select/handlers/FieldsVisitor.js.map +1 -1
  151. package/dist/production/src/mapper/update/SqlUpdateInputProcessor.cjs +36 -36
  152. package/dist/production/src/mapper/update/SqlUpdateInputProcessor.cjs.map +1 -1
  153. package/dist/production/src/mapper/update/SqlUpdateInputProcessor.js +36 -36
  154. package/dist/production/src/mapper/update/SqlUpdateInputProcessor.js.map +1 -1
  155. package/dist/production/src/mapper/update/UpdateBuilder.cjs +2 -14
  156. package/dist/production/src/mapper/update/UpdateBuilder.cjs.map +1 -1
  157. package/dist/production/src/mapper/update/UpdateBuilder.js +2 -14
  158. package/dist/production/src/mapper/update/UpdateBuilder.js.map +1 -1
  159. package/dist/production/src/mapper/update/Updater.cjs +45 -17
  160. package/dist/production/src/mapper/update/Updater.cjs.map +1 -1
  161. package/dist/production/src/mapper/update/Updater.js +47 -19
  162. package/dist/production/src/mapper/update/Updater.js.map +1 -1
  163. package/dist/production/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.cjs +89 -0
  164. package/dist/production/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.cjs.map +1 -0
  165. package/dist/production/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.js +89 -0
  166. package/dist/production/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.js.map +1 -0
  167. package/dist/production/src/mapper/update/relations/ManyHasOneUpdateInputProcessor.cjs +89 -0
  168. package/dist/production/src/mapper/update/relations/ManyHasOneUpdateInputProcessor.cjs.map +1 -0
  169. package/dist/production/src/mapper/update/relations/ManyHasOneUpdateInputProcessor.js +89 -0
  170. package/dist/production/src/mapper/update/relations/ManyHasOneUpdateInputProcessor.js.map +1 -0
  171. package/dist/production/src/mapper/update/relations/OneHasManyUpdateInputProcessor.cjs +86 -0
  172. package/dist/production/src/mapper/update/relations/OneHasManyUpdateInputProcessor.cjs.map +1 -0
  173. package/dist/production/src/mapper/update/relations/OneHasManyUpdateInputProcessor.js +86 -0
  174. package/dist/production/src/mapper/update/relations/OneHasManyUpdateInputProcessor.js.map +1 -0
  175. package/dist/production/src/mapper/{relations → update/relations}/OneHasOneInverseUpdateInputProcessor.cjs +83 -66
  176. package/dist/production/src/mapper/update/relations/OneHasOneInverseUpdateInputProcessor.cjs.map +1 -0
  177. package/dist/production/src/mapper/{relations → update/relations}/OneHasOneInverseUpdateInputProcessor.js +83 -66
  178. package/dist/production/src/mapper/update/relations/OneHasOneInverseUpdateInputProcessor.js.map +1 -0
  179. package/dist/production/src/mapper/update/relations/OneHasOneOwningUpdateInputProcessor.cjs +187 -0
  180. package/dist/production/src/mapper/update/relations/OneHasOneOwningUpdateInputProcessor.cjs.map +1 -0
  181. package/dist/production/src/mapper/update/relations/OneHasOneOwningUpdateInputProcessor.js +187 -0
  182. package/dist/production/src/mapper/update/relations/OneHasOneOwningUpdateInputProcessor.js.map +1 -0
  183. package/dist/production/src/resolvers/MutationResolver.cjs +1 -1
  184. package/dist/production/src/resolvers/MutationResolver.js +1 -1
  185. package/dist/tests/tsconfig.tsbuildinfo +1 -1
  186. package/dist/types/input-validation/preValidation/InputPreValidator.d.ts.map +1 -1
  187. package/dist/types/inputProcessing/CreateInputVisitor.d.ts +8 -8
  188. package/dist/types/inputProcessing/CreateInputVisitor.d.ts.map +1 -1
  189. package/dist/types/inputProcessing/UpdateInputVisitor.d.ts +8 -8
  190. package/dist/types/inputProcessing/UpdateInputVisitor.d.ts.map +1 -1
  191. package/dist/types/mapper/MutationProcessorHelper.d.ts +2 -2
  192. package/dist/types/mapper/MutationProcessorHelper.d.ts.map +1 -1
  193. package/dist/types/mapper/Result.d.ts +11 -5
  194. package/dist/types/mapper/Result.d.ts.map +1 -1
  195. package/dist/types/mapper/insert/InsertBuilder.d.ts +3 -7
  196. package/dist/types/mapper/insert/InsertBuilder.d.ts.map +1 -1
  197. package/dist/types/mapper/insert/Inserter.d.ts +0 -1
  198. package/dist/types/mapper/insert/Inserter.d.ts.map +1 -1
  199. package/dist/types/mapper/insert/SqlCreateInputProcessor.d.ts +11 -8
  200. package/dist/types/mapper/insert/SqlCreateInputProcessor.d.ts.map +1 -1
  201. package/dist/types/mapper/insert/relations/ManyHasManyCreateInputProcessor.d.ts +24 -0
  202. package/dist/types/mapper/insert/relations/ManyHasManyCreateInputProcessor.d.ts.map +1 -0
  203. package/dist/types/mapper/insert/relations/ManyHasOneCreateInputProcessor.d.ts +23 -0
  204. package/dist/types/mapper/insert/relations/ManyHasOneCreateInputProcessor.d.ts.map +1 -0
  205. package/dist/types/mapper/insert/relations/OneHasManyCreateInputProcessor.d.ts +26 -0
  206. package/dist/types/mapper/insert/relations/OneHasManyCreateInputProcessor.d.ts.map +1 -0
  207. package/dist/types/mapper/insert/relations/OneHasOneInverseCreateInputProcessor.d.ts +29 -0
  208. package/dist/types/mapper/insert/relations/OneHasOneInverseCreateInputProcessor.d.ts.map +1 -0
  209. package/dist/types/mapper/insert/relations/OneHasOneOwningCreateInputProcessor.d.ts +24 -0
  210. package/dist/types/mapper/insert/relations/OneHasOneOwningCreateInputProcessor.d.ts.map +1 -0
  211. package/dist/types/mapper/select/handlers/FieldsVisitor.d.ts.map +1 -1
  212. package/dist/types/mapper/update/SqlUpdateInputProcessor.d.ts +10 -7
  213. package/dist/types/mapper/update/SqlUpdateInputProcessor.d.ts.map +1 -1
  214. package/dist/types/mapper/update/UpdateBuilder.d.ts +2 -6
  215. package/dist/types/mapper/update/UpdateBuilder.d.ts.map +1 -1
  216. package/dist/types/mapper/update/Updater.d.ts +0 -1
  217. package/dist/types/mapper/update/Updater.d.ts.map +1 -1
  218. package/dist/types/mapper/update/relations/ManyHasManyUpdateInputProcessor.d.ts +46 -0
  219. package/dist/types/mapper/update/relations/ManyHasManyUpdateInputProcessor.d.ts.map +1 -0
  220. package/dist/types/mapper/update/relations/ManyHasOneUpdateInputProcessor.d.ts +40 -0
  221. package/dist/types/mapper/update/relations/ManyHasOneUpdateInputProcessor.d.ts.map +1 -0
  222. package/dist/types/mapper/update/relations/OneHasManyUpdateInputProcessor.d.ts +46 -0
  223. package/dist/types/mapper/update/relations/OneHasManyUpdateInputProcessor.d.ts.map +1 -0
  224. package/dist/types/mapper/{relations → update/relations}/OneHasOneInverseUpdateInputProcessor.d.ts +17 -13
  225. package/dist/types/mapper/update/relations/OneHasOneInverseUpdateInputProcessor.d.ts.map +1 -0
  226. package/dist/types/mapper/{relations → update/relations}/OneHasOneOwningUpdateInputProcessor.d.ts +19 -16
  227. package/dist/types/mapper/update/relations/OneHasOneOwningUpdateInputProcessor.d.ts.map +1 -0
  228. package/dist/types/tsconfig.tsbuildinfo +1 -1
  229. package/package.json +11 -11
  230. package/src/input-validation/preValidation/InputPreValidator.ts +3 -5
  231. package/src/inputProcessing/CreateInputVisitor.ts +14 -14
  232. package/src/inputProcessing/UpdateInputVisitor.ts +17 -17
  233. package/src/mapper/MutationProcessorHelper.ts +16 -8
  234. package/src/mapper/Result.ts +11 -47
  235. package/src/mapper/insert/InsertBuilder.ts +8 -22
  236. package/src/mapper/insert/Inserter.ts +53 -40
  237. package/src/mapper/insert/SqlCreateInputProcessor.ts +35 -88
  238. package/src/mapper/insert/relations/ManyHasManyCreateInputProcessor.ts +59 -0
  239. package/src/mapper/insert/relations/ManyHasOneCreateInputProcessor.ts +57 -0
  240. package/src/mapper/insert/relations/OneHasManyCreateInputProcessor.ts +50 -0
  241. package/src/mapper/insert/relations/OneHasOneInverseCreateInputProcessor.ts +91 -0
  242. package/src/mapper/insert/relations/OneHasOneOwningCreateInputProcessor.ts +87 -0
  243. package/src/mapper/select/handlers/FieldsVisitor.ts +3 -0
  244. package/src/mapper/update/SqlUpdateInputProcessor.ts +48 -46
  245. package/src/mapper/update/UpdateBuilder.ts +9 -23
  246. package/src/mapper/update/Updater.ts +53 -34
  247. package/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.ts +116 -0
  248. package/src/mapper/update/relations/ManyHasOneUpdateInputProcessor.ts +125 -0
  249. package/src/mapper/update/relations/OneHasManyUpdateInputProcessor.ts +111 -0
  250. package/src/mapper/{relations → update/relations}/OneHasOneInverseUpdateInputProcessor.ts +93 -73
  251. package/src/mapper/update/relations/OneHasOneOwningUpdateInputProcessor.ts +243 -0
  252. package/tests/cases/integration/graphQlRequests/insert/oneHasMany/create.test.ts +8 -8
  253. package/tests/cases/integration/graphQlRequests/update/oneHasMany/connectOrCreate.test.ts +4 -4
  254. package/dist/development/src/mapper/DataManipulationBuilder.cjs +0 -5
  255. package/dist/development/src/mapper/DataManipulationBuilder.cjs.map +0 -1
  256. package/dist/development/src/mapper/DataManipulationBuilder.js +0 -5
  257. package/dist/development/src/mapper/DataManipulationBuilder.js.map +0 -1
  258. package/dist/development/src/mapper/relations/ManyHasManyInputProcessor.cjs +0 -75
  259. package/dist/development/src/mapper/relations/ManyHasManyInputProcessor.cjs.map +0 -1
  260. package/dist/development/src/mapper/relations/ManyHasManyInputProcessor.js +0 -75
  261. package/dist/development/src/mapper/relations/ManyHasManyInputProcessor.js.map +0 -1
  262. package/dist/development/src/mapper/relations/ManyHasOneInputProcessor.cjs +0 -114
  263. package/dist/development/src/mapper/relations/ManyHasOneInputProcessor.cjs.map +0 -1
  264. package/dist/development/src/mapper/relations/ManyHasOneInputProcessor.js +0 -114
  265. package/dist/development/src/mapper/relations/ManyHasOneInputProcessor.js.map +0 -1
  266. package/dist/development/src/mapper/relations/OneHasManyInputProcessor.cjs +0 -72
  267. package/dist/development/src/mapper/relations/OneHasManyInputProcessor.cjs.map +0 -1
  268. package/dist/development/src/mapper/relations/OneHasManyInputProcessor.js +0 -72
  269. package/dist/development/src/mapper/relations/OneHasManyInputProcessor.js.map +0 -1
  270. package/dist/development/src/mapper/relations/OneHasOneInverseCreateInputProcessor.cjs.map +0 -1
  271. package/dist/development/src/mapper/relations/OneHasOneInverseCreateInputProcessor.js.map +0 -1
  272. package/dist/development/src/mapper/relations/OneHasOneInverseUpdateInputProcessor.cjs.map +0 -1
  273. package/dist/development/src/mapper/relations/OneHasOneInverseUpdateInputProcessor.js.map +0 -1
  274. package/dist/development/src/mapper/relations/OneHasOneOwningCreateInputProcessor.cjs +0 -71
  275. package/dist/development/src/mapper/relations/OneHasOneOwningCreateInputProcessor.cjs.map +0 -1
  276. package/dist/development/src/mapper/relations/OneHasOneOwningCreateInputProcessor.js +0 -71
  277. package/dist/development/src/mapper/relations/OneHasOneOwningCreateInputProcessor.js.map +0 -1
  278. package/dist/development/src/mapper/relations/OneHasOneOwningUpdateInputProcessor.cjs +0 -200
  279. package/dist/development/src/mapper/relations/OneHasOneOwningUpdateInputProcessor.cjs.map +0 -1
  280. package/dist/development/src/mapper/relations/OneHasOneOwningUpdateInputProcessor.js +0 -200
  281. package/dist/development/src/mapper/relations/OneHasOneOwningUpdateInputProcessor.js.map +0 -1
  282. package/dist/production/src/mapper/DataManipulationBuilder.cjs +0 -5
  283. package/dist/production/src/mapper/DataManipulationBuilder.cjs.map +0 -1
  284. package/dist/production/src/mapper/DataManipulationBuilder.js +0 -5
  285. package/dist/production/src/mapper/DataManipulationBuilder.js.map +0 -1
  286. package/dist/production/src/mapper/relations/ManyHasManyInputProcessor.cjs +0 -75
  287. package/dist/production/src/mapper/relations/ManyHasManyInputProcessor.cjs.map +0 -1
  288. package/dist/production/src/mapper/relations/ManyHasManyInputProcessor.js +0 -75
  289. package/dist/production/src/mapper/relations/ManyHasManyInputProcessor.js.map +0 -1
  290. package/dist/production/src/mapper/relations/ManyHasOneInputProcessor.cjs +0 -114
  291. package/dist/production/src/mapper/relations/ManyHasOneInputProcessor.cjs.map +0 -1
  292. package/dist/production/src/mapper/relations/ManyHasOneInputProcessor.js +0 -114
  293. package/dist/production/src/mapper/relations/ManyHasOneInputProcessor.js.map +0 -1
  294. package/dist/production/src/mapper/relations/OneHasManyInputProcessor.cjs +0 -72
  295. package/dist/production/src/mapper/relations/OneHasManyInputProcessor.cjs.map +0 -1
  296. package/dist/production/src/mapper/relations/OneHasManyInputProcessor.js +0 -72
  297. package/dist/production/src/mapper/relations/OneHasManyInputProcessor.js.map +0 -1
  298. package/dist/production/src/mapper/relations/OneHasOneInverseCreateInputProcessor.cjs.map +0 -1
  299. package/dist/production/src/mapper/relations/OneHasOneInverseCreateInputProcessor.js.map +0 -1
  300. package/dist/production/src/mapper/relations/OneHasOneInverseUpdateInputProcessor.cjs.map +0 -1
  301. package/dist/production/src/mapper/relations/OneHasOneInverseUpdateInputProcessor.js.map +0 -1
  302. package/dist/production/src/mapper/relations/OneHasOneOwningCreateInputProcessor.cjs +0 -71
  303. package/dist/production/src/mapper/relations/OneHasOneOwningCreateInputProcessor.cjs.map +0 -1
  304. package/dist/production/src/mapper/relations/OneHasOneOwningCreateInputProcessor.js +0 -71
  305. package/dist/production/src/mapper/relations/OneHasOneOwningCreateInputProcessor.js.map +0 -1
  306. package/dist/production/src/mapper/relations/OneHasOneOwningUpdateInputProcessor.cjs +0 -200
  307. package/dist/production/src/mapper/relations/OneHasOneOwningUpdateInputProcessor.cjs.map +0 -1
  308. package/dist/production/src/mapper/relations/OneHasOneOwningUpdateInputProcessor.js +0 -200
  309. package/dist/production/src/mapper/relations/OneHasOneOwningUpdateInputProcessor.js.map +0 -1
  310. package/dist/types/mapper/DataManipulationBuilder.d.ts +0 -7
  311. package/dist/types/mapper/DataManipulationBuilder.d.ts.map +0 -1
  312. package/dist/types/mapper/relations/ManyHasManyInputProcessor.d.ts +0 -32
  313. package/dist/types/mapper/relations/ManyHasManyInputProcessor.d.ts.map +0 -1
  314. package/dist/types/mapper/relations/ManyHasOneInputProcessor.d.ts +0 -32
  315. package/dist/types/mapper/relations/ManyHasOneInputProcessor.d.ts.map +0 -1
  316. package/dist/types/mapper/relations/OneHasManyInputProcessor.d.ts +0 -29
  317. package/dist/types/mapper/relations/OneHasManyInputProcessor.d.ts.map +0 -1
  318. package/dist/types/mapper/relations/OneHasOneInverseCreateInputProcessor.d.ts +0 -21
  319. package/dist/types/mapper/relations/OneHasOneInverseCreateInputProcessor.d.ts.map +0 -1
  320. package/dist/types/mapper/relations/OneHasOneInverseUpdateInputProcessor.d.ts.map +0 -1
  321. package/dist/types/mapper/relations/OneHasOneOwningCreateInputProcessor.d.ts +0 -21
  322. package/dist/types/mapper/relations/OneHasOneOwningCreateInputProcessor.d.ts.map +0 -1
  323. package/dist/types/mapper/relations/OneHasOneOwningUpdateInputProcessor.d.ts.map +0 -1
  324. package/src/mapper/DataManipulationBuilder.ts +0 -12
  325. package/src/mapper/relations/ManyHasManyInputProcessor.ts +0 -108
  326. package/src/mapper/relations/ManyHasOneInputProcessor.ts +0 -158
  327. package/src/mapper/relations/OneHasManyInputProcessor.ts +0 -101
  328. package/src/mapper/relations/OneHasOneInverseCreateInputProcessor.ts +0 -99
  329. package/src/mapper/relations/OneHasOneOwningCreateInputProcessor.ts +0 -92
  330. package/src/mapper/relations/OneHasOneOwningUpdateInputProcessor.ts +0 -253
@@ -5,14 +5,22 @@ const hasManyProcessor = (innerProcessor) => {
5
5
  return async (context) => {
6
6
  const { relation, index, alias } = context;
7
7
  const path = [{ field: relation.name }, { index, alias }];
8
- return Result.prependPath(path, await innerProcessor(context));
8
+ const innerResult = await innerProcessor(context);
9
+ if (typeof innerResult === "function") {
10
+ return async (it) => Result.prependPath(path, await innerResult(it));
11
+ }
12
+ return Result.prependPath(path, innerResult);
9
13
  };
10
14
  };
11
15
  const hasOneProcessor = (innerProcessor) => {
12
16
  return async (context) => {
13
17
  const { relation } = context;
14
18
  const path = [{ field: relation.name }];
15
- return Result.prependPath(path, await innerProcessor(context));
19
+ const innerResult = await innerProcessor(context);
20
+ if (typeof innerResult === "function") {
21
+ return async (it) => Result.prependPath(path, await innerResult(it));
22
+ }
23
+ return Result.prependPath(path, innerResult);
16
24
  };
17
25
  };
18
26
  exports.hasManyProcessor = hasManyProcessor;
@@ -1 +1 @@
1
- {"version":3,"file":"MutationProcessorHelper.cjs","sources":["../../../../../packages/engine-content-api/src/mapper/MutationProcessorHelper.ts"],"sourcesContent":["import { MutationResultList, prependPath } from './Result'\nimport { Model } from '@contember/schema'\n\nexport const hasManyProcessor = <Context extends { relation: Model.AnyRelation; index: number; alias?: string }>(\n\tinnerProcessor: (context: Context) => Promise<MutationResultList>,\n) => {\n\treturn async (context: Context): Promise<MutationResultList> => {\n\t\tconst { relation, index, alias } = context\n\t\tconst path = [{ field: relation.name }, { index, alias }]\n\t\treturn prependPath(path, await innerProcessor(context))\n\t}\n}\n\nexport const hasOneProcessor = <Context extends { relation: Model.AnyRelation }>(\n\tinnerProcessor: (context: Context) => Promise<MutationResultList>,\n) => {\n\treturn async (context: Context): Promise<MutationResultList> => {\n\t\tconst { relation } = context\n\t\tconst path = [{ field: relation.name }]\n\t\treturn prependPath(path, await innerProcessor(context))\n\t}\n}\n"],"names":["prependPath"],"mappings":";;;AAGa,MAAA,mBAAmB,CAC/B,mBACI;AACJ,SAAO,OAAO,YAAkD;AAC/D,UAAM,EAAE,UAAU,OAAO,MAAA,IAAU;AAC7B,UAAA,OAAO,CAAC,EAAE,OAAO,SAAS,QAAQ,EAAE,OAAO,MAAA,CAAO;AACxD,WAAOA,OAAY,YAAA,MAAM,MAAM,eAAe,OAAO,CAAC;AAAA,EAAA;AAExD;AAEa,MAAA,kBAAkB,CAC9B,mBACI;AACJ,SAAO,OAAO,YAAkD;AACzD,UAAA,EAAE,SAAa,IAAA;AACrB,UAAM,OAAO,CAAC,EAAE,OAAO,SAAS,KAAM,CAAA;AACtC,WAAOA,OAAY,YAAA,MAAM,MAAM,eAAe,OAAO,CAAC;AAAA,EAAA;AAExD;;;"}
1
+ {"version":3,"file":"MutationProcessorHelper.cjs","sources":["../../../../../packages/engine-content-api/src/mapper/MutationProcessorHelper.ts"],"sourcesContent":["import { MutationResultList, prependPath } from './Result'\nimport { Model } from '@contember/schema'\n\nexport const hasManyProcessor = <Context extends { relation: Model.AnyRelation; index: number; alias?: string }, Args>(\n\tinnerProcessor: (context: Context) => Promise<MutationResultList | ((args: Args) => Promise<MutationResultList>)>,\n) => {\n\treturn async (context: Context): Promise<MutationResultList | ((args: Args) => Promise<MutationResultList>)> => {\n\t\tconst { relation, index, alias } = context\n\t\tconst path = [{ field: relation.name }, { index, alias }]\n\t\tconst innerResult = await innerProcessor(context)\n\t\tif (typeof innerResult === 'function') {\n\t\t\treturn async (it: Args) => prependPath(path, await innerResult(it))\n\t\t}\n\t\treturn prependPath(path, innerResult)\n\t}\n}\n\nexport const hasOneProcessor = <Context extends { relation: Model.AnyRelation }, Args>(\n\tinnerProcessor: (context: Context) => Promise<MutationResultList | ((args: Args) => Promise<MutationResultList>)>,\n) => {\n\treturn async (context: Context): Promise<MutationResultList | ((args: Args) => Promise<MutationResultList>)> => {\n\t\tconst { relation } = context\n\t\tconst path = [{ field: relation.name }]\n\t\tconst innerResult = await innerProcessor(context)\n\t\tif (typeof innerResult === 'function') {\n\t\t\treturn async (it: Args) => prependPath(path, await innerResult(it))\n\t\t}\n\t\treturn prependPath(path, innerResult)\n\t}\n}\n"],"names":["prependPath"],"mappings":";;;AAGa,MAAA,mBAAmB,CAC/B,mBACI;AACJ,SAAO,OAAO,YAAkG;AAC/G,UAAM,EAAE,UAAU,OAAO,MAAA,IAAU;AAC7B,UAAA,OAAO,CAAC,EAAE,OAAO,SAAS,QAAQ,EAAE,OAAO,MAAA,CAAO;AAClD,UAAA,cAAc,MAAM,eAAe,OAAO;AAC5C,QAAA,OAAO,gBAAgB,YAAY;AACtC,aAAO,OAAO,OAAaA,mBAAY,MAAM,MAAM,YAAY,EAAE,CAAC;AAAA,IACnE;AACO,WAAAA,OAAA,YAAY,MAAM,WAAW;AAAA,EAAA;AAEtC;AAEa,MAAA,kBAAkB,CAC9B,mBACI;AACJ,SAAO,OAAO,YAAkG;AACzG,UAAA,EAAE,SAAa,IAAA;AACrB,UAAM,OAAO,CAAC,EAAE,OAAO,SAAS,KAAM,CAAA;AAChC,UAAA,cAAc,MAAM,eAAe,OAAO;AAC5C,QAAA,OAAO,gBAAgB,YAAY;AACtC,aAAO,OAAO,OAAaA,mBAAY,MAAM,MAAM,YAAY,EAAE,CAAC;AAAA,IACnE;AACO,WAAAA,OAAA,YAAY,MAAM,WAAW;AAAA,EAAA;AAEtC;;;"}
@@ -3,14 +3,22 @@ const hasManyProcessor = (innerProcessor) => {
3
3
  return async (context) => {
4
4
  const { relation, index, alias } = context;
5
5
  const path = [{ field: relation.name }, { index, alias }];
6
- return prependPath(path, await innerProcessor(context));
6
+ const innerResult = await innerProcessor(context);
7
+ if (typeof innerResult === "function") {
8
+ return async (it) => prependPath(path, await innerResult(it));
9
+ }
10
+ return prependPath(path, innerResult);
7
11
  };
8
12
  };
9
13
  const hasOneProcessor = (innerProcessor) => {
10
14
  return async (context) => {
11
15
  const { relation } = context;
12
16
  const path = [{ field: relation.name }];
13
- return prependPath(path, await innerProcessor(context));
17
+ const innerResult = await innerProcessor(context);
18
+ if (typeof innerResult === "function") {
19
+ return async (it) => prependPath(path, await innerResult(it));
20
+ }
21
+ return prependPath(path, innerResult);
14
22
  };
15
23
  };
16
24
  export {
@@ -1 +1 @@
1
- {"version":3,"file":"MutationProcessorHelper.js","sources":["../../../../../packages/engine-content-api/src/mapper/MutationProcessorHelper.ts"],"sourcesContent":["import { MutationResultList, prependPath } from './Result'\nimport { Model } from '@contember/schema'\n\nexport const hasManyProcessor = <Context extends { relation: Model.AnyRelation; index: number; alias?: string }>(\n\tinnerProcessor: (context: Context) => Promise<MutationResultList>,\n) => {\n\treturn async (context: Context): Promise<MutationResultList> => {\n\t\tconst { relation, index, alias } = context\n\t\tconst path = [{ field: relation.name }, { index, alias }]\n\t\treturn prependPath(path, await innerProcessor(context))\n\t}\n}\n\nexport const hasOneProcessor = <Context extends { relation: Model.AnyRelation }>(\n\tinnerProcessor: (context: Context) => Promise<MutationResultList>,\n) => {\n\treturn async (context: Context): Promise<MutationResultList> => {\n\t\tconst { relation } = context\n\t\tconst path = [{ field: relation.name }]\n\t\treturn prependPath(path, await innerProcessor(context))\n\t}\n}\n"],"names":[],"mappings":";AAGa,MAAA,mBAAmB,CAC/B,mBACI;AACJ,SAAO,OAAO,YAAkD;AAC/D,UAAM,EAAE,UAAU,OAAO,MAAA,IAAU;AAC7B,UAAA,OAAO,CAAC,EAAE,OAAO,SAAS,QAAQ,EAAE,OAAO,MAAA,CAAO;AACxD,WAAO,YAAY,MAAM,MAAM,eAAe,OAAO,CAAC;AAAA,EAAA;AAExD;AAEa,MAAA,kBAAkB,CAC9B,mBACI;AACJ,SAAO,OAAO,YAAkD;AACzD,UAAA,EAAE,SAAa,IAAA;AACrB,UAAM,OAAO,CAAC,EAAE,OAAO,SAAS,KAAM,CAAA;AACtC,WAAO,YAAY,MAAM,MAAM,eAAe,OAAO,CAAC;AAAA,EAAA;AAExD;"}
1
+ {"version":3,"file":"MutationProcessorHelper.js","sources":["../../../../../packages/engine-content-api/src/mapper/MutationProcessorHelper.ts"],"sourcesContent":["import { MutationResultList, prependPath } from './Result'\nimport { Model } from '@contember/schema'\n\nexport const hasManyProcessor = <Context extends { relation: Model.AnyRelation; index: number; alias?: string }, Args>(\n\tinnerProcessor: (context: Context) => Promise<MutationResultList | ((args: Args) => Promise<MutationResultList>)>,\n) => {\n\treturn async (context: Context): Promise<MutationResultList | ((args: Args) => Promise<MutationResultList>)> => {\n\t\tconst { relation, index, alias } = context\n\t\tconst path = [{ field: relation.name }, { index, alias }]\n\t\tconst innerResult = await innerProcessor(context)\n\t\tif (typeof innerResult === 'function') {\n\t\t\treturn async (it: Args) => prependPath(path, await innerResult(it))\n\t\t}\n\t\treturn prependPath(path, innerResult)\n\t}\n}\n\nexport const hasOneProcessor = <Context extends { relation: Model.AnyRelation }, Args>(\n\tinnerProcessor: (context: Context) => Promise<MutationResultList | ((args: Args) => Promise<MutationResultList>)>,\n) => {\n\treturn async (context: Context): Promise<MutationResultList | ((args: Args) => Promise<MutationResultList>)> => {\n\t\tconst { relation } = context\n\t\tconst path = [{ field: relation.name }]\n\t\tconst innerResult = await innerProcessor(context)\n\t\tif (typeof innerResult === 'function') {\n\t\t\treturn async (it: Args) => prependPath(path, await innerResult(it))\n\t\t}\n\t\treturn prependPath(path, innerResult)\n\t}\n}\n"],"names":[],"mappings":";AAGa,MAAA,mBAAmB,CAC/B,mBACI;AACJ,SAAO,OAAO,YAAkG;AAC/G,UAAM,EAAE,UAAU,OAAO,MAAA,IAAU;AAC7B,UAAA,OAAO,CAAC,EAAE,OAAO,SAAS,QAAQ,EAAE,OAAO,MAAA,CAAO;AAClD,UAAA,cAAc,MAAM,eAAe,OAAO;AAC5C,QAAA,OAAO,gBAAgB,YAAY;AACtC,aAAO,OAAO,OAAa,YAAY,MAAM,MAAM,YAAY,EAAE,CAAC;AAAA,IACnE;AACO,WAAA,YAAY,MAAM,WAAW;AAAA,EAAA;AAEtC;AAEa,MAAA,kBAAkB,CAC9B,mBACI;AACJ,SAAO,OAAO,YAAkG;AACzG,UAAA,EAAE,SAAa,IAAA;AACrB,UAAM,OAAO,CAAC,EAAE,OAAO,SAAS,KAAM,CAAA;AAChC,UAAA,cAAc,MAAM,eAAe,OAAO;AAC5C,QAAA,OAAO,gBAAgB,YAAY;AACtC,aAAO,OAAO,OAAa,YAAY,MAAM,MAAM,YAAY,EAAE,CAAC;AAAA,IACnE;AACO,WAAA,YAAY,MAAM,WAAW;AAAA,EAAA;AAEtC;"}
@@ -1,10 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const ErrorUtils = require("./ErrorUtils.cjs");
4
- const promises = require("../utils/promises.cjs");
5
- require("@contember/schema-utils");
6
- const Database = require("@contember/database");
7
- const logger = require("@contember/logger");
8
3
  var __defProp = Object.defineProperty;
9
4
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
5
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
@@ -32,6 +27,7 @@ class MutationUpdateOk {
32
27
  this.input = input;
33
28
  this.values = values;
34
29
  this.oldValues = oldValues;
30
+ __publicField(this, "error", false);
35
31
  __publicField(
36
32
  this,
37
33
  "result",
@@ -54,6 +50,7 @@ class MutationCreateOk {
54
50
  this.primary = primary;
55
51
  this.input = input;
56
52
  this.values = values;
53
+ __publicField(this, "error", false);
57
54
  __publicField(
58
55
  this,
59
56
  "result",
@@ -74,6 +71,7 @@ class MutationDeleteOk {
74
71
  this.paths = paths;
75
72
  this.entity = entity;
76
73
  this.primary = primary;
74
+ __publicField(this, "error", false);
77
75
  __publicField(
78
76
  this,
79
77
  "result",
@@ -96,6 +94,7 @@ class MutationJunctionUpdateOk {
96
94
  this.relation = relation;
97
95
  this.owningUnique = owningUnique;
98
96
  this.inverseUnique = inverseUnique;
97
+ __publicField(this, "error", false);
99
98
  __publicField(
100
99
  this,
101
100
  "result",
@@ -123,6 +122,7 @@ class MutationNothingToDo {
123
122
  constructor(paths, reason) {
124
123
  this.paths = paths;
125
124
  this.reason = reason;
125
+ __publicField(this, "error", false);
126
126
  __publicField(
127
127
  this,
128
128
  "result",
@@ -143,6 +143,7 @@ class MutationInputError {
143
143
  this.kind = kind;
144
144
  this.message = message;
145
145
  this.hints = hints;
146
+ __publicField(this, "error", true);
146
147
  __publicField(
147
148
  this,
148
149
  "result",
@@ -156,6 +157,7 @@ class MutationSqlError {
156
157
  this.paths = paths;
157
158
  this.message = message;
158
159
  this.hints = hints;
160
+ __publicField(this, "error", true);
159
161
  __publicField(
160
162
  this,
161
163
  "result",
@@ -176,6 +178,7 @@ class MutationConstraintViolationError {
176
178
  this.constraint = constraint;
177
179
  this.message = message;
178
180
  this.hints = hints;
181
+ __publicField(this, "error", true);
179
182
  __publicField(
180
183
  this,
181
184
  "result",
@@ -188,6 +191,7 @@ class MutationEntryNotFoundError {
188
191
  constructor(paths, where) {
189
192
  this.paths = paths;
190
193
  this.where = where;
194
+ __publicField(this, "error", true);
191
195
  __publicField(
192
196
  this,
193
197
  "result",
@@ -204,6 +208,7 @@ class MutationNoResultError {
204
208
  this.paths = paths;
205
209
  this.message = message;
206
210
  this.hints = hints;
211
+ __publicField(this, "error", true);
207
212
  __publicField(
208
213
  this,
209
214
  "result",
@@ -217,26 +222,6 @@ const prependPath = (path, results) => results.map((it) => ({
217
222
  paths: (it.paths.length === 0 ? [[]] : it.paths).map((it2) => [...path, ...it2])
218
223
  }));
219
224
  const getInsertPrimary = (result) => result[0] && result[0].result === "ok" && result[0].type === "create" ? result[0].primary : void 0;
220
- const flattenResult = (result) => result.reduce((acc, it) => [...acc, ...it], []).reduce((acc, it) => Array.isArray(it) ? [...acc, ...it] : [...acc, it], []);
221
- const collectResults = async (schema, schemaDatabaseMetadata, mainPromise, otherPromises) => {
222
- let index = 0;
223
- const allPromises = [mainPromise, ...otherPromises].filter((it) => !!it).map(
224
- (it) => it.catch((e) => [ErrorUtils.convertError(schema, schemaDatabaseMetadata, e)]).then((value) => ({ value, index: index++ }))
225
- );
226
- const results = await Promise.allSettled(allPromises);
227
- const failures = promises.getRejections(results);
228
- if (failures.length > 0) {
229
- if (failures.length > 1 && !failures.every((it) => it instanceof Database.SerializationFailureError)) {
230
- failures.slice(1).map((e) => logger.logger.error(e));
231
- }
232
- throw failures[0];
233
- }
234
- const values = promises.getFulfilledValues(results);
235
- const sortedValues = [values[0], ...values.slice(1).sort((a, b) => a.index - b.index)];
236
- return flattenResult(
237
- sortedValues.map((it) => it.value).filter((it) => !!it)
238
- );
239
- };
240
225
  exports.ConstraintType = ConstraintType;
241
226
  exports.InputErrorKind = InputErrorKind;
242
227
  exports.MutationConstraintViolationError = MutationConstraintViolationError;
@@ -252,8 +237,6 @@ exports.MutationResultType = MutationResultType;
252
237
  exports.MutationSqlError = MutationSqlError;
253
238
  exports.MutationUpdateOk = MutationUpdateOk;
254
239
  exports.NothingToDoReason = NothingToDoReason;
255
- exports.collectResults = collectResults;
256
- exports.flattenResult = flattenResult;
257
240
  exports.getInsertPrimary = getInsertPrimary;
258
241
  exports.prependPath = prependPath;
259
242
  //# sourceMappingURL=Result.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"Result.cjs","sources":["../../../../../packages/engine-content-api/src/mapper/Result.ts"],"sourcesContent":["import { Input, Model, Value } from '@contember/schema'\nimport { convertError } from './ErrorUtils'\nimport { getFulfilledValues, getRejections } from '../utils'\nimport { DatabaseMetadata, SerializationFailureError } from '@contember/database'\nimport { logger } from '@contember/logger'\n\nexport enum MutationResultType {\n\tok = 'ok',\n\tnothingToDo = 'nothingToDo',\n\tnotFoundError = 'notFoundError',\n\tconstraintViolationError = 'constraintViolationError',\n\tnoResultError = 'noResultError',\n\tvalidationError = 'validationError',\n\tinputError = 'inputError',\n\tsqlError = 'sqlError',\n}\n\nexport enum MutationResultHint {\n\tsqlError = 'sqlError',\n\tsubSequentSqlError = 'subsequentSqlError',\n}\n\nexport enum ModificationType {\n\tcreate = 'create',\n\tupdate = 'update',\n\tdelete = 'delete',\n\tjunctionUpdate = 'junctionUpdate',\n}\n\nexport type MutationResult =\n\t| MutationUpdateOk\n\t| MutationCreateOk\n\t| MutationDeleteOk\n\t| MutationJunctionUpdateOk\n\t| MutationEntryNotFoundError\n\t| MutationNothingToDo\n\t| MutationConstraintViolationError\n\t| MutationNoResultError\n\t| MutationInputError\n\t| MutationSqlError\n\nexport type MutationResultList = MutationResult[]\n\ntype Path = ({ field: string } | { index: number; alias?: string })[]\n\ninterface MutationResultInterface {\n\tresult: MutationResultType\n\tpaths: Path[]\n\tmessage?: string\n\thints: MutationResultHint[]\n}\n\nexport type RowValues = { [fieldName: string]: Value.FieldValue }\n\nexport class MutationUpdateOk implements MutationResultInterface {\n\tresult = MutationResultType.ok as const\n\ttype = ModificationType.update as const\n\thints: MutationResultHint[] = []\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly entity: Model.Entity,\n\t\tpublic readonly primary: Value.PrimaryValue,\n\t\tpublic readonly input: Input.UpdateDataInput,\n\t\tpublic readonly values: RowValues,\n\t\tpublic readonly oldValues?: RowValues,\n\t) {}\n}\n\nexport class MutationCreateOk implements MutationResultInterface {\n\tresult = MutationResultType.ok as const\n\ttype = ModificationType.create as const\n\thints: MutationResultHint[] = []\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly entity: Model.Entity,\n\t\tpublic readonly primary: Value.PrimaryValue,\n\t\tpublic readonly input: Input.CreateDataInput,\n\t\tpublic readonly values: RowValues,\n\t) {}\n}\n\nexport class MutationDeleteOk implements MutationResultInterface {\n\tresult = MutationResultType.ok as const\n\ttype = ModificationType.delete as const\n\thints: MutationResultHint[] = []\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly entity: Model.Entity,\n\t\tpublic readonly primary: Value.PrimaryValue,\n\t) {}\n}\n\nexport class MutationJunctionUpdateOk implements MutationResultInterface {\n\tresult = MutationResultType.ok as const\n\ttype = ModificationType.junctionUpdate as const\n\thints: MutationResultHint[] = []\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly entity: Model.Entity,\n\t\tpublic readonly relation: Model.ManyHasManyOwningRelation,\n\t\tpublic readonly owningUnique: Input.PrimaryValue,\n\t\tpublic readonly inverseUnique: Input.PrimaryValue,\n\t) {}\n}\n\nexport enum NothingToDoReason {\n\tnoData = 'noData',\n\temptyRelation = 'emptyRelation',\n\talreadyExists = 'alreadyExists',\n\taborted = 'aborted',\n\talreadyDeleted = 'alreadyDeleted',\n}\n\nexport class MutationNothingToDo implements MutationResultInterface {\n\tresult = MutationResultType.nothingToDo as const\n\thints: MutationResultHint[] = []\n\n\tconstructor(public readonly paths: Path[], public readonly reason: NothingToDoReason) {}\n}\n\nexport enum InputErrorKind {\n\tnonUniqueWhere = 'nonUniqueWhere',\n\tinvalidData = 'invalidData',\n}\n\nexport class MutationInputError implements MutationResultInterface {\n\tresult = MutationResultType.inputError as const\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly kind: InputErrorKind,\n\t\tpublic readonly message?: string,\n\t\tpublic readonly hints: MutationResultHint[] = [],\n\t) {}\n}\n\nexport class MutationSqlError implements MutationResultInterface {\n\tresult = MutationResultType.sqlError as const\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly message?: string,\n\t\tpublic readonly hints: MutationResultHint[] = [],\n\t) {}\n}\n\nexport enum ConstraintType {\n\tnotNull = 'notNull',\n\tuniqueKey = 'uniqueKey',\n\tforeignKey = 'foreignKey',\n}\n\nexport class MutationConstraintViolationError implements MutationResultInterface {\n\tresult = MutationResultType.constraintViolationError as const\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly constraint: ConstraintType,\n\t\tpublic readonly message?: string,\n\t\tpublic readonly hints: MutationResultHint[] = [],\n\t) {}\n}\n\n// maybe denied by acl\nexport class MutationEntryNotFoundError implements MutationResultInterface {\n\tresult = MutationResultType.notFoundError as const\n\thints: MutationResultHint[] = []\n\tmessage: string\n\n\tconstructor(public readonly paths: Path[], public readonly where: Input.UniqueWhere | Input.Where) {\n\t\tthis.message = 'for input ' + JSON.stringify(where)\n\t}\n}\n\n// possibly denied by acl\nexport class MutationNoResultError implements MutationResultInterface {\n\tresult = MutationResultType.noResultError as const\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly message?: string,\n\t\tpublic readonly hints: MutationResultHint[] = [],\n\t) {}\n}\n\nexport const prependPath = (path: Path, results: MutationResultList): MutationResultList =>\n\tresults.map(it => ({\n\t\t...it,\n\t\tpaths: (it.paths.length === 0 ? [[]] : it.paths).map(it => [...path, ...it]),\n\t}))\n\nexport const getInsertPrimary = (result: MutationResultList) =>\n\tresult[0] && result[0].result === MutationResultType.ok && result[0].type === ModificationType.create\n\t\t? result[0].primary\n\t\t: undefined\n\nexport const getUpdatePrimary = (result: MutationResultList) =>\n\tresult[0] && result[0].result === MutationResultType.ok && result[0].type === ModificationType.update\n\t\t? result[0].primary\n\t\t: undefined\n\nexport const flattenResult = (result: (MutationResultList | MutationResultList[])[]): MutationResultList =>\n\tresult\n\t\t.reduce<(MutationResult | MutationResult[])[]>((acc, it) => [...acc, ...it], [])\n\t\t.reduce<MutationResultList>((acc, it) => (Array.isArray(it) ? [...acc, ...it] : [...acc, it]), [])\n\nexport type ResultListNotFlatten = MutationResultList | MutationResultList[]\n\nexport const collectResults = async (\n\tschema: Model.Schema,\n\tschemaDatabaseMetadata: DatabaseMetadata,\n\tmainPromise: Promise<ResultListNotFlatten | undefined> | undefined,\n\totherPromises: (Promise<ResultListNotFlatten | undefined> | undefined)[],\n): Promise<MutationResultList> => {\n\tlet index = 0\n\tconst allPromises: Promise<{ index: number; value: ResultListNotFlatten }>[] = [mainPromise, ...otherPromises]\n\t\t.filter((it): it is Promise<ResultListNotFlatten> => !!it)\n\t\t.map(it =>\n\t\t\tit //\n\t\t\t\t.catch(e => [convertError(schema, schemaDatabaseMetadata, e)])\n\t\t\t\t.then(value => ({ value, index: index++ })),\n\t\t)\n\tconst results = await Promise.allSettled(allPromises)\n\tconst failures = getRejections(results)\n\tif (failures.length > 0) {\n\t\tif (failures.length > 1 && !failures.every(it => it instanceof SerializationFailureError)) {\n\t\t\tfailures.slice(1).map(e => logger.error(e))\n\t\t}\n\t\tthrow failures[0]\n\t}\n\n\tconst values = getFulfilledValues(results)\n\tconst sortedValues = [values[0], ...values.slice(1).sort((a, b) => a.index - b.index)]\n\n\treturn flattenResult(\n\t\tsortedValues.map(it => it.value).filter((it): it is MutationResultList | MutationResultList[] => !!it),\n\t)\n}\n"],"names":["MutationResultType","MutationResultHint","NothingToDoReason","InputErrorKind","ConstraintType","it","convertError","getRejections","SerializationFailureError","logger","getFulfilledValues"],"mappings":";;;;;;;;;;AAMY,IAAA,uCAAAA,wBAAL;AACNA,sBAAA,IAAK,IAAA;AACLA,sBAAA,aAAc,IAAA;AACdA,sBAAA,eAAgB,IAAA;AAChBA,sBAAA,0BAA2B,IAAA;AAC3BA,sBAAA,eAAgB,IAA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EAC9E,OAA2B,CAAC,KAAK,OAAQ,MAAM,QAAQ,EAAE,IAAI,CAAC,GAAG,KAAK,GAAG,EAAE,IAAI,CAAC,GAAG,KAAK,EAAE,GAAI,CAAA,CAAE;AAI5F,MAAM,iBAAiB,OAC7B,QACA,wBACA,aACA,kBACiC;AACjC,MAAI,QAAQ;AACZ,QAAM,cAAyE,CAAC,aAAa,GAAG,aAAa,EAC3G,OAAO,CAAC,OAA4C,CAAC,CAAC,EAAE,EACxD;AAAA,IAAI,QACJ,GACE,MAAM,OAAK,CAACC,WAAA,aAAa,QAAQ,wBAAwB,CAAC,CAAC,CAAC,EAC5D,KAAK,CAAA,WAAU,EAAE,OAAO,OAAO,UAAU;AAAA,EAAA;AAE7C,QAAM,UAAU,MAAM,QAAQ,WAAW,WAAW;AAC9C,QAAA,WAAWC,uBAAc,OAAO;AAClC,MAAA,SAAS,SAAS,GAAG;AACpB,QAAA,SAAS,SAAS,KAAK,CAAC,SAAS,MAAM,CAAA,OAAM,cAAcC,SAAAA,yBAAyB,GAAG;AACjF,eAAA,MAAM,CAAC,EAAE,IAAI,OAAKC,cAAO,MAAM,CAAC,CAAC;AAAA,IAC3C;AACA,UAAM,SAAS,CAAC;AAAA,EACjB;AAEM,QAAA,SAASC,4BAAmB,OAAO;AACzC,QAAM,eAAe,CAAC,OAAO,CAAC,GAAG,GAAG,OAAO,MAAM,CAAC,EAAE,KAAK,CAAC,GAAG,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAC;AAE9E,SAAA;AAAA,IACN,aAAa,IAAI,CAAA,OAAM,GAAG,KAAK,EAAE,OAAO,CAAC,OAAwD,CAAC,CAAC,EAAE;AAAA,EAAA;AAEvG;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"Result.cjs","sources":["../../../../../packages/engine-content-api/src/mapper/Result.ts"],"sourcesContent":["import { Input, Model, Value } from '@contember/schema'\n\nexport enum MutationResultType {\n\tok = 'ok',\n\tnothingToDo = 'nothingToDo',\n\tnotFoundError = 'notFoundError',\n\tconstraintViolationError = 'constraintViolationError',\n\tnoResultError = 'noResultError',\n\tvalidationError = 'validationError',\n\tinputError = 'inputError',\n\tsqlError = 'sqlError',\n}\n\nexport enum MutationResultHint {\n\tsqlError = 'sqlError',\n\tsubSequentSqlError = 'subsequentSqlError',\n}\n\nexport enum ModificationType {\n\tcreate = 'create',\n\tupdate = 'update',\n\tdelete = 'delete',\n\tjunctionUpdate = 'junctionUpdate',\n}\n\nexport type MutationResult =\n\t| MutationUpdateOk\n\t| MutationCreateOk\n\t| MutationDeleteOk\n\t| MutationJunctionUpdateOk\n\t| MutationEntryNotFoundError\n\t| MutationNothingToDo\n\t| MutationConstraintViolationError\n\t| MutationNoResultError\n\t| MutationInputError\n\t| MutationSqlError\n\nexport type MutationResultList = MutationResult[]\n\ntype Path = ({ field: string } | { index: number; alias?: string })[]\n\ninterface MutationResultInterface {\n\terror: boolean\n\tresult: MutationResultType\n\tpaths: Path[]\n\tmessage?: string\n\thints: MutationResultHint[]\n}\n\nexport type RowValues = { [fieldName: string]: Value.FieldValue }\n\nexport class MutationUpdateOk implements MutationResultInterface {\n\terror = false\n\tresult = MutationResultType.ok as const\n\ttype = ModificationType.update as const\n\thints: MutationResultHint[] = []\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly entity: Model.Entity,\n\t\tpublic readonly primary: Value.PrimaryValue,\n\t\tpublic readonly input: Input.UpdateDataInput,\n\t\tpublic readonly values: RowValues,\n\t\tpublic readonly oldValues?: RowValues,\n\t) {}\n}\n\nexport class MutationCreateOk implements MutationResultInterface {\n\terror = false\n\tresult = MutationResultType.ok as const\n\ttype = ModificationType.create as const\n\thints: MutationResultHint[] = []\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly entity: Model.Entity,\n\t\tpublic readonly primary: Value.PrimaryValue,\n\t\tpublic readonly input: Input.CreateDataInput,\n\t\tpublic readonly values: RowValues,\n\t) {}\n}\n\nexport class MutationDeleteOk implements MutationResultInterface {\n\terror = false\n\tresult = MutationResultType.ok as const\n\ttype = ModificationType.delete as const\n\thints: MutationResultHint[] = []\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly entity: Model.Entity,\n\t\tpublic readonly primary: Value.PrimaryValue,\n\t) {}\n}\n\nexport class MutationJunctionUpdateOk implements MutationResultInterface {\n\terror = false\n\tresult = MutationResultType.ok as const\n\ttype = ModificationType.junctionUpdate as const\n\thints: MutationResultHint[] = []\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly entity: Model.Entity,\n\t\tpublic readonly relation: Model.ManyHasManyOwningRelation,\n\t\tpublic readonly owningUnique: Input.PrimaryValue,\n\t\tpublic readonly inverseUnique: Input.PrimaryValue,\n\t) {}\n}\n\nexport enum NothingToDoReason {\n\tnoData = 'noData',\n\temptyRelation = 'emptyRelation',\n\talreadyExists = 'alreadyExists',\n\taborted = 'aborted',\n\talreadyDeleted = 'alreadyDeleted',\n}\n\nexport class MutationNothingToDo implements MutationResultInterface {\n\terror = false\n\tresult = MutationResultType.nothingToDo as const\n\thints: MutationResultHint[] = []\n\n\tconstructor(public readonly paths: Path[], public readonly reason: NothingToDoReason) {}\n}\n\nexport enum InputErrorKind {\n\tnonUniqueWhere = 'nonUniqueWhere',\n\tinvalidData = 'invalidData',\n}\n\nexport class MutationInputError implements MutationResultInterface {\n\terror = true\n\tresult = MutationResultType.inputError as const\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly kind: InputErrorKind,\n\t\tpublic readonly message?: string,\n\t\tpublic readonly hints: MutationResultHint[] = [],\n\t) {}\n}\n\nexport class MutationSqlError implements MutationResultInterface {\n\terror = true\n\tresult = MutationResultType.sqlError as const\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly message?: string,\n\t\tpublic readonly hints: MutationResultHint[] = [],\n\t) {}\n}\n\nexport enum ConstraintType {\n\tnotNull = 'notNull',\n\tuniqueKey = 'uniqueKey',\n\tforeignKey = 'foreignKey',\n}\n\nexport class MutationConstraintViolationError implements MutationResultInterface {\n\terror = true\n\tresult = MutationResultType.constraintViolationError as const\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly constraint: ConstraintType,\n\t\tpublic readonly message?: string,\n\t\tpublic readonly hints: MutationResultHint[] = [],\n\t) {}\n}\n\n// maybe denied by acl\nexport class MutationEntryNotFoundError implements MutationResultInterface {\n\terror = true\n\tresult = MutationResultType.notFoundError as const\n\thints: MutationResultHint[] = []\n\tmessage: string\n\n\tconstructor(public readonly paths: Path[], public readonly where: Input.UniqueWhere | Input.Where) {\n\t\tthis.message = 'for input ' + JSON.stringify(where)\n\t}\n}\n\n// possibly denied by acl\nexport class MutationNoResultError implements MutationResultInterface {\n\terror = true\n\tresult = MutationResultType.noResultError as const\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly message?: string,\n\t\tpublic readonly hints: MutationResultHint[] = [],\n\t) {}\n}\n\nexport const prependPath = (path: Path, results: MutationResultList): MutationResultList =>\n\tresults.map(it => ({\n\t\t...it,\n\t\tpaths: (it.paths.length === 0 ? [[]] : it.paths).map(it => [...path, ...it]),\n\t}))\n\nexport const getInsertPrimary = (result: MutationResultList) =>\n\tresult[0] && result[0].result === MutationResultType.ok && result[0].type === ModificationType.create\n\t\t? result[0].primary\n\t\t: undefined\n"],"names":["MutationResultType","MutationResultHint","NothingToDoReason","InputErrorKind","ConstraintType","it"],"mappings":";;;;;AAEY,IAAA,uCAAAA,wBAAL;AACNA,sBAAA,IAAK,IAAA;AACLA,sBAAA,aAAc,IAAA;AACdA,sBAAA,eAAgB,IAAA;AAChBA,sBAAA,0BAA2B,IAAA;AAC3BA,sBAAA,eAAgB,IAAA;AAChBA,sBAAA,iBAAkB,IAAA;AAClBA,sBAAA,YAAa,IAAA;AACbA,sBAAA,UAAW,IAAA;AARAA,SAAAA;AAAA,GAAA,sBAAA,CAAA,CAAA;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W,QAAyB,OAAO,CAAC,EAAE,SAAS,WAC3E,OAAO,CAAC,EAAE,UACV;;;;;;;;;;;;;;;;;;"}
@@ -1,8 +1,3 @@
1
- import { convertError } from "./ErrorUtils.js";
2
- import { getRejections, getFulfilledValues } from "../utils/promises.js";
3
- import "@contember/schema-utils";
4
- import { SerializationFailureError } from "@contember/database";
5
- import { logger } from "@contember/logger";
6
1
  var __defProp = Object.defineProperty;
7
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
3
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
@@ -30,6 +25,7 @@ class MutationUpdateOk {
30
25
  this.input = input;
31
26
  this.values = values;
32
27
  this.oldValues = oldValues;
28
+ __publicField(this, "error", false);
33
29
  __publicField(
34
30
  this,
35
31
  "result",
@@ -52,6 +48,7 @@ class MutationCreateOk {
52
48
  this.primary = primary;
53
49
  this.input = input;
54
50
  this.values = values;
51
+ __publicField(this, "error", false);
55
52
  __publicField(
56
53
  this,
57
54
  "result",
@@ -72,6 +69,7 @@ class MutationDeleteOk {
72
69
  this.paths = paths;
73
70
  this.entity = entity;
74
71
  this.primary = primary;
72
+ __publicField(this, "error", false);
75
73
  __publicField(
76
74
  this,
77
75
  "result",
@@ -94,6 +92,7 @@ class MutationJunctionUpdateOk {
94
92
  this.relation = relation;
95
93
  this.owningUnique = owningUnique;
96
94
  this.inverseUnique = inverseUnique;
95
+ __publicField(this, "error", false);
97
96
  __publicField(
98
97
  this,
99
98
  "result",
@@ -121,6 +120,7 @@ class MutationNothingToDo {
121
120
  constructor(paths, reason) {
122
121
  this.paths = paths;
123
122
  this.reason = reason;
123
+ __publicField(this, "error", false);
124
124
  __publicField(
125
125
  this,
126
126
  "result",
@@ -141,6 +141,7 @@ class MutationInputError {
141
141
  this.kind = kind;
142
142
  this.message = message;
143
143
  this.hints = hints;
144
+ __publicField(this, "error", true);
144
145
  __publicField(
145
146
  this,
146
147
  "result",
@@ -154,6 +155,7 @@ class MutationSqlError {
154
155
  this.paths = paths;
155
156
  this.message = message;
156
157
  this.hints = hints;
158
+ __publicField(this, "error", true);
157
159
  __publicField(
158
160
  this,
159
161
  "result",
@@ -174,6 +176,7 @@ class MutationConstraintViolationError {
174
176
  this.constraint = constraint;
175
177
  this.message = message;
176
178
  this.hints = hints;
179
+ __publicField(this, "error", true);
177
180
  __publicField(
178
181
  this,
179
182
  "result",
@@ -186,6 +189,7 @@ class MutationEntryNotFoundError {
186
189
  constructor(paths, where) {
187
190
  this.paths = paths;
188
191
  this.where = where;
192
+ __publicField(this, "error", true);
189
193
  __publicField(
190
194
  this,
191
195
  "result",
@@ -202,6 +206,7 @@ class MutationNoResultError {
202
206
  this.paths = paths;
203
207
  this.message = message;
204
208
  this.hints = hints;
209
+ __publicField(this, "error", true);
205
210
  __publicField(
206
211
  this,
207
212
  "result",
@@ -215,26 +220,6 @@ const prependPath = (path, results) => results.map((it) => ({
215
220
  paths: (it.paths.length === 0 ? [[]] : it.paths).map((it2) => [...path, ...it2])
216
221
  }));
217
222
  const getInsertPrimary = (result) => result[0] && result[0].result === "ok" && result[0].type === "create" ? result[0].primary : void 0;
218
- const flattenResult = (result) => result.reduce((acc, it) => [...acc, ...it], []).reduce((acc, it) => Array.isArray(it) ? [...acc, ...it] : [...acc, it], []);
219
- const collectResults = async (schema, schemaDatabaseMetadata, mainPromise, otherPromises) => {
220
- let index = 0;
221
- const allPromises = [mainPromise, ...otherPromises].filter((it) => !!it).map(
222
- (it) => it.catch((e) => [convertError(schema, schemaDatabaseMetadata, e)]).then((value) => ({ value, index: index++ }))
223
- );
224
- const results = await Promise.allSettled(allPromises);
225
- const failures = getRejections(results);
226
- if (failures.length > 0) {
227
- if (failures.length > 1 && !failures.every((it) => it instanceof SerializationFailureError)) {
228
- failures.slice(1).map((e) => logger.error(e));
229
- }
230
- throw failures[0];
231
- }
232
- const values = getFulfilledValues(results);
233
- const sortedValues = [values[0], ...values.slice(1).sort((a, b) => a.index - b.index)];
234
- return flattenResult(
235
- sortedValues.map((it) => it.value).filter((it) => !!it)
236
- );
237
- };
238
223
  export {
239
224
  ConstraintType,
240
225
  InputErrorKind,
@@ -251,8 +236,6 @@ export {
251
236
  MutationSqlError,
252
237
  MutationUpdateOk,
253
238
  NothingToDoReason,
254
- collectResults,
255
- flattenResult,
256
239
  getInsertPrimary,
257
240
  prependPath
258
241
  };
@@ -1 +1 @@
1
- {"version":3,"file":"Result.js","sources":["../../../../../packages/engine-content-api/src/mapper/Result.ts"],"sourcesContent":["import { Input, Model, Value } from '@contember/schema'\nimport { convertError } from './ErrorUtils'\nimport { getFulfilledValues, getRejections } from '../utils'\nimport { DatabaseMetadata, SerializationFailureError } from '@contember/database'\nimport { logger } from '@contember/logger'\n\nexport enum MutationResultType {\n\tok = 'ok',\n\tnothingToDo = 'nothingToDo',\n\tnotFoundError = 'notFoundError',\n\tconstraintViolationError = 'constraintViolationError',\n\tnoResultError = 'noResultError',\n\tvalidationError = 'validationError',\n\tinputError = 'inputError',\n\tsqlError = 'sqlError',\n}\n\nexport enum MutationResultHint {\n\tsqlError = 'sqlError',\n\tsubSequentSqlError = 'subsequentSqlError',\n}\n\nexport enum ModificationType {\n\tcreate = 'create',\n\tupdate = 'update',\n\tdelete = 'delete',\n\tjunctionUpdate = 'junctionUpdate',\n}\n\nexport type MutationResult =\n\t| MutationUpdateOk\n\t| MutationCreateOk\n\t| MutationDeleteOk\n\t| MutationJunctionUpdateOk\n\t| MutationEntryNotFoundError\n\t| MutationNothingToDo\n\t| MutationConstraintViolationError\n\t| MutationNoResultError\n\t| MutationInputError\n\t| MutationSqlError\n\nexport type MutationResultList = MutationResult[]\n\ntype Path = ({ field: string } | { index: number; alias?: string })[]\n\ninterface MutationResultInterface {\n\tresult: MutationResultType\n\tpaths: Path[]\n\tmessage?: string\n\thints: MutationResultHint[]\n}\n\nexport type RowValues = { [fieldName: string]: Value.FieldValue }\n\nexport class MutationUpdateOk implements MutationResultInterface {\n\tresult = MutationResultType.ok as const\n\ttype = ModificationType.update as const\n\thints: MutationResultHint[] = []\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly entity: Model.Entity,\n\t\tpublic readonly primary: Value.PrimaryValue,\n\t\tpublic readonly input: Input.UpdateDataInput,\n\t\tpublic readonly values: RowValues,\n\t\tpublic readonly oldValues?: RowValues,\n\t) {}\n}\n\nexport class MutationCreateOk implements MutationResultInterface {\n\tresult = MutationResultType.ok as const\n\ttype = ModificationType.create as const\n\thints: MutationResultHint[] = []\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly entity: Model.Entity,\n\t\tpublic readonly primary: Value.PrimaryValue,\n\t\tpublic readonly input: Input.CreateDataInput,\n\t\tpublic readonly values: RowValues,\n\t) {}\n}\n\nexport class MutationDeleteOk implements MutationResultInterface {\n\tresult = MutationResultType.ok as const\n\ttype = ModificationType.delete as const\n\thints: MutationResultHint[] = []\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly entity: Model.Entity,\n\t\tpublic readonly primary: Value.PrimaryValue,\n\t) {}\n}\n\nexport class MutationJunctionUpdateOk implements MutationResultInterface {\n\tresult = MutationResultType.ok as const\n\ttype = ModificationType.junctionUpdate as const\n\thints: MutationResultHint[] = []\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly entity: Model.Entity,\n\t\tpublic readonly relation: Model.ManyHasManyOwningRelation,\n\t\tpublic readonly owningUnique: Input.PrimaryValue,\n\t\tpublic readonly inverseUnique: Input.PrimaryValue,\n\t) {}\n}\n\nexport enum NothingToDoReason {\n\tnoData = 'noData',\n\temptyRelation = 'emptyRelation',\n\talreadyExists = 'alreadyExists',\n\taborted = 'aborted',\n\talreadyDeleted = 'alreadyDeleted',\n}\n\nexport class MutationNothingToDo implements MutationResultInterface {\n\tresult = MutationResultType.nothingToDo as const\n\thints: MutationResultHint[] = []\n\n\tconstructor(public readonly paths: Path[], public readonly reason: NothingToDoReason) {}\n}\n\nexport enum InputErrorKind {\n\tnonUniqueWhere = 'nonUniqueWhere',\n\tinvalidData = 'invalidData',\n}\n\nexport class MutationInputError implements MutationResultInterface {\n\tresult = MutationResultType.inputError as const\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly kind: InputErrorKind,\n\t\tpublic readonly message?: string,\n\t\tpublic readonly hints: MutationResultHint[] = [],\n\t) {}\n}\n\nexport class MutationSqlError implements MutationResultInterface {\n\tresult = MutationResultType.sqlError as const\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly message?: string,\n\t\tpublic readonly hints: MutationResultHint[] = [],\n\t) {}\n}\n\nexport enum ConstraintType {\n\tnotNull = 'notNull',\n\tuniqueKey = 'uniqueKey',\n\tforeignKey = 'foreignKey',\n}\n\nexport class MutationConstraintViolationError implements MutationResultInterface {\n\tresult = MutationResultType.constraintViolationError as const\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly constraint: ConstraintType,\n\t\tpublic readonly message?: string,\n\t\tpublic readonly hints: MutationResultHint[] = [],\n\t) {}\n}\n\n// maybe denied by acl\nexport class MutationEntryNotFoundError implements MutationResultInterface {\n\tresult = MutationResultType.notFoundError as const\n\thints: MutationResultHint[] = []\n\tmessage: string\n\n\tconstructor(public readonly paths: Path[], public readonly where: Input.UniqueWhere | Input.Where) {\n\t\tthis.message = 'for input ' + JSON.stringify(where)\n\t}\n}\n\n// possibly denied by acl\nexport class MutationNoResultError implements MutationResultInterface {\n\tresult = MutationResultType.noResultError as const\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly message?: string,\n\t\tpublic readonly hints: MutationResultHint[] = [],\n\t) {}\n}\n\nexport const prependPath = (path: Path, results: MutationResultList): MutationResultList =>\n\tresults.map(it => ({\n\t\t...it,\n\t\tpaths: (it.paths.length === 0 ? [[]] : it.paths).map(it => [...path, ...it]),\n\t}))\n\nexport const getInsertPrimary = (result: MutationResultList) =>\n\tresult[0] && result[0].result === MutationResultType.ok && result[0].type === ModificationType.create\n\t\t? result[0].primary\n\t\t: undefined\n\nexport const getUpdatePrimary = (result: MutationResultList) =>\n\tresult[0] && result[0].result === MutationResultType.ok && result[0].type === ModificationType.update\n\t\t? result[0].primary\n\t\t: undefined\n\nexport const flattenResult = (result: (MutationResultList | MutationResultList[])[]): MutationResultList =>\n\tresult\n\t\t.reduce<(MutationResult | MutationResult[])[]>((acc, it) => [...acc, ...it], [])\n\t\t.reduce<MutationResultList>((acc, it) => (Array.isArray(it) ? [...acc, ...it] : [...acc, it]), [])\n\nexport type ResultListNotFlatten = MutationResultList | MutationResultList[]\n\nexport const collectResults = async (\n\tschema: Model.Schema,\n\tschemaDatabaseMetadata: DatabaseMetadata,\n\tmainPromise: Promise<ResultListNotFlatten | undefined> | undefined,\n\totherPromises: (Promise<ResultListNotFlatten | undefined> | undefined)[],\n): Promise<MutationResultList> => {\n\tlet index = 0\n\tconst allPromises: Promise<{ index: number; value: ResultListNotFlatten }>[] = [mainPromise, ...otherPromises]\n\t\t.filter((it): it is Promise<ResultListNotFlatten> => !!it)\n\t\t.map(it =>\n\t\t\tit //\n\t\t\t\t.catch(e => [convertError(schema, schemaDatabaseMetadata, e)])\n\t\t\t\t.then(value => ({ value, index: index++ })),\n\t\t)\n\tconst results = await Promise.allSettled(allPromises)\n\tconst failures = getRejections(results)\n\tif (failures.length > 0) {\n\t\tif (failures.length > 1 && !failures.every(it => it instanceof SerializationFailureError)) {\n\t\t\tfailures.slice(1).map(e => logger.error(e))\n\t\t}\n\t\tthrow failures[0]\n\t}\n\n\tconst values = getFulfilledValues(results)\n\tconst sortedValues = [values[0], ...values.slice(1).sort((a, b) => a.index - b.index)]\n\n\treturn flattenResult(\n\t\tsortedValues.map(it => it.value).filter((it): it is MutationResultList | MutationResultList[] => !!it),\n\t)\n}\n"],"names":["MutationResultType","MutationResultHint","NothingToDoReason","InputErrorKind","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file":"Result.js","sources":["../../../../../packages/engine-content-api/src/mapper/Result.ts"],"sourcesContent":["import { Input, Model, Value } from '@contember/schema'\n\nexport enum MutationResultType {\n\tok = 'ok',\n\tnothingToDo = 'nothingToDo',\n\tnotFoundError = 'notFoundError',\n\tconstraintViolationError = 'constraintViolationError',\n\tnoResultError = 'noResultError',\n\tvalidationError = 'validationError',\n\tinputError = 'inputError',\n\tsqlError = 'sqlError',\n}\n\nexport enum MutationResultHint {\n\tsqlError = 'sqlError',\n\tsubSequentSqlError = 'subsequentSqlError',\n}\n\nexport enum ModificationType {\n\tcreate = 'create',\n\tupdate = 'update',\n\tdelete = 'delete',\n\tjunctionUpdate = 'junctionUpdate',\n}\n\nexport type MutationResult =\n\t| MutationUpdateOk\n\t| MutationCreateOk\n\t| MutationDeleteOk\n\t| MutationJunctionUpdateOk\n\t| MutationEntryNotFoundError\n\t| MutationNothingToDo\n\t| MutationConstraintViolationError\n\t| MutationNoResultError\n\t| MutationInputError\n\t| MutationSqlError\n\nexport type MutationResultList = MutationResult[]\n\ntype Path = ({ field: string } | { index: number; alias?: string })[]\n\ninterface MutationResultInterface {\n\terror: boolean\n\tresult: MutationResultType\n\tpaths: Path[]\n\tmessage?: string\n\thints: MutationResultHint[]\n}\n\nexport type RowValues = { [fieldName: string]: Value.FieldValue }\n\nexport class MutationUpdateOk implements MutationResultInterface {\n\terror = false\n\tresult = MutationResultType.ok as const\n\ttype = ModificationType.update as const\n\thints: MutationResultHint[] = []\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly entity: Model.Entity,\n\t\tpublic readonly primary: Value.PrimaryValue,\n\t\tpublic readonly input: Input.UpdateDataInput,\n\t\tpublic readonly values: RowValues,\n\t\tpublic readonly oldValues?: RowValues,\n\t) {}\n}\n\nexport class MutationCreateOk implements MutationResultInterface {\n\terror = false\n\tresult = MutationResultType.ok as const\n\ttype = ModificationType.create as const\n\thints: MutationResultHint[] = []\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly entity: Model.Entity,\n\t\tpublic readonly primary: Value.PrimaryValue,\n\t\tpublic readonly input: Input.CreateDataInput,\n\t\tpublic readonly values: RowValues,\n\t) {}\n}\n\nexport class MutationDeleteOk implements MutationResultInterface {\n\terror = false\n\tresult = MutationResultType.ok as const\n\ttype = ModificationType.delete as const\n\thints: MutationResultHint[] = []\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly entity: Model.Entity,\n\t\tpublic readonly primary: Value.PrimaryValue,\n\t) {}\n}\n\nexport class MutationJunctionUpdateOk implements MutationResultInterface {\n\terror = false\n\tresult = MutationResultType.ok as const\n\ttype = ModificationType.junctionUpdate as const\n\thints: MutationResultHint[] = []\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly entity: Model.Entity,\n\t\tpublic readonly relation: Model.ManyHasManyOwningRelation,\n\t\tpublic readonly owningUnique: Input.PrimaryValue,\n\t\tpublic readonly inverseUnique: Input.PrimaryValue,\n\t) {}\n}\n\nexport enum NothingToDoReason {\n\tnoData = 'noData',\n\temptyRelation = 'emptyRelation',\n\talreadyExists = 'alreadyExists',\n\taborted = 'aborted',\n\talreadyDeleted = 'alreadyDeleted',\n}\n\nexport class MutationNothingToDo implements MutationResultInterface {\n\terror = false\n\tresult = MutationResultType.nothingToDo as const\n\thints: MutationResultHint[] = []\n\n\tconstructor(public readonly paths: Path[], public readonly reason: NothingToDoReason) {}\n}\n\nexport enum InputErrorKind {\n\tnonUniqueWhere = 'nonUniqueWhere',\n\tinvalidData = 'invalidData',\n}\n\nexport class MutationInputError implements MutationResultInterface {\n\terror = true\n\tresult = MutationResultType.inputError as const\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly kind: InputErrorKind,\n\t\tpublic readonly message?: string,\n\t\tpublic readonly hints: MutationResultHint[] = [],\n\t) {}\n}\n\nexport class MutationSqlError implements MutationResultInterface {\n\terror = true\n\tresult = MutationResultType.sqlError as const\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly message?: string,\n\t\tpublic readonly hints: MutationResultHint[] = [],\n\t) {}\n}\n\nexport enum ConstraintType {\n\tnotNull = 'notNull',\n\tuniqueKey = 'uniqueKey',\n\tforeignKey = 'foreignKey',\n}\n\nexport class MutationConstraintViolationError implements MutationResultInterface {\n\terror = true\n\tresult = MutationResultType.constraintViolationError as const\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly constraint: ConstraintType,\n\t\tpublic readonly message?: string,\n\t\tpublic readonly hints: MutationResultHint[] = [],\n\t) {}\n}\n\n// maybe denied by acl\nexport class MutationEntryNotFoundError implements MutationResultInterface {\n\terror = true\n\tresult = MutationResultType.notFoundError as const\n\thints: MutationResultHint[] = []\n\tmessage: string\n\n\tconstructor(public readonly paths: Path[], public readonly where: Input.UniqueWhere | Input.Where) {\n\t\tthis.message = 'for input ' + JSON.stringify(where)\n\t}\n}\n\n// possibly denied by acl\nexport class MutationNoResultError implements MutationResultInterface {\n\terror = true\n\tresult = MutationResultType.noResultError as const\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly message?: string,\n\t\tpublic readonly hints: MutationResultHint[] = [],\n\t) {}\n}\n\nexport const prependPath = (path: Path, results: MutationResultList): MutationResultList =>\n\tresults.map(it => ({\n\t\t...it,\n\t\tpaths: (it.paths.length === 0 ? [[]] : it.paths).map(it => [...path, ...it]),\n\t}))\n\nexport const getInsertPrimary = (result: MutationResultList) =>\n\tresult[0] && result[0].result === MutationResultType.ok && result[0].type === ModificationType.create\n\t\t? result[0].primary\n\t\t: undefined\n"],"names":["MutationResultType","MutationResultHint","NothingToDoReason","InputErrorKind","ConstraintType","it"],"mappings":";;;AAEY,IAAA,uCAAAA,wBAAL;AACNA,sBAAA,IAAK,IAAA;AACLA,sBAAA,aAAc,IAAA;AACdA,sBAAA,eAAgB,IAAA;AAChBA,sBAAA,0BAA2B,IAAA;AAC3BA,sBA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IAAI,CAAAC,QAAM,CAAC,GAAG,MAAM,GAAGA,GAAE,CAAC;AAC5E,EAAE;AAEI,MAAM,mBAAmB,CAAC,WAChC,OAAO,CAAC,KAAK,OAAO,CAAC,EAAE,WAAW,QAAyB,OAAO,CAAC,EAAE,SAAS,WAC3E,OAAO,CAAC,EAAE,UACV;"}
@@ -4,8 +4,6 @@ const schema = require("@contember/schema");
4
4
  const Database = require("@contember/database");
5
5
  const schemaUtils = require("@contember/schema-utils");
6
6
  const ColumnValue = require("../ColumnValue.cjs");
7
- const exception = require("../../exception.cjs");
8
- const DataManipulationBuilder = require("../DataManipulationBuilder.cjs");
9
7
  const EventManager = require("../EventManager.cjs");
10
8
  var __defProp = Object.defineProperty;
11
9
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
@@ -17,10 +15,6 @@ class InsertBuilder {
17
15
  this.whereBuilder = whereBuilder;
18
16
  this.pathFactory = pathFactory;
19
17
  this.predicateFactory = predicateFactory;
20
- __publicField(this, "resolver", () => {
21
- throw new exception.ImplementationException("InsertBuilder: Resolver called too soon");
22
- });
23
- __publicField(this, "insert", new Promise((resolve) => this.resolver = resolve));
24
18
  __publicField(this, "rowData", /* @__PURE__ */ new Map());
25
19
  __publicField(this, "where", { and: [] });
26
20
  }
@@ -44,10 +38,6 @@ class InsertBuilder {
44
38
  async execute(mapper) {
45
39
  try {
46
40
  const resolvedData = await this.getResolvedData();
47
- if (resolvedData.find((it) => it.resolvedValue === DataManipulationBuilder.AbortDataManipulation)) {
48
- this.resolver(null);
49
- return { aborted: true, executed: false, primaryValue: null, values: [] };
50
- }
51
41
  const insertData = resolvedData.reduce(
52
42
  (result2, item) => ({ ...result2, [item.columnName]: (expr) => expr.select(["root_", item.columnName]) }),
53
43
  {}
@@ -68,10 +58,8 @@ class InsertBuilder {
68
58
  const afterInsertEvent = new EventManager.AfterInsertEvent(this.entity, resolvedData, result);
69
59
  beforeInsertEvent.afterEvent = afterInsertEvent;
70
60
  await mapper.eventManager.fire(afterInsertEvent);
71
- this.resolver(result);
72
- return { values: resolvedData, executed: true, primaryValue: result, aborted: false };
61
+ return { values: resolvedData, executed: true, primaryValue: result };
73
62
  } catch (e) {
74
- this.resolver(null);
75
63
  throw e;
76
64
  }
77
65
  }
@@ -1 +1 @@
1
- {"version":3,"file":"InsertBuilder.cjs","sources":["../../../../../../packages/engine-content-api/src/mapper/insert/InsertBuilder.ts"],"sourcesContent":["import { Acl, Input, Model, Value } from '@contember/schema'\nimport { Client, InsertBuilder as DbInsertBuilder, QueryBuilder, Value as DbValue } from '@contember/database'\nimport { PathFactory, WhereBuilder } from '../select'\nimport { getColumnName, getColumnType } from '@contember/schema-utils'\nimport { ColumnValue, ResolvedColumnValue, resolveGenericValue, resolveRowData } from '../ColumnValue'\nimport { ImplementationException } from '../../exception'\nimport { PredicateFactory } from '../../acl'\nimport { AbortDataManipulation, DataManipulationBuilder } from '../DataManipulationBuilder'\nimport { AfterInsertEvent, BeforeInsertEvent, EventManager } from '../EventManager'\nimport { Mapper } from '../Mapper'\n\nexport interface InsertResult {\n\tvalues: ResolvedColumnValue[]\n\texecuted: boolean\n\taborted: boolean\n\tprimaryValue: Value.PrimaryValue | null\n}\n\nexport class InsertBuilder implements DataManipulationBuilder {\n\tprivate resolver: (value: Value.PrimaryValue | null) => void = () => {\n\t\tthrow new ImplementationException('InsertBuilder: Resolver called too soon')\n\t}\n\tpublic readonly insert: Promise<Value.PrimaryValue | null> = new Promise(resolve => (this.resolver = resolve))\n\n\tprivate rowData: Map<string, ColumnValue<AbortDataManipulation | undefined>> = new Map()\n\tprivate where: { and: Input.OptionalWhere[] } = { and: [] }\n\n\tconstructor(\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly entity: Model.Entity,\n\t\tprivate readonly whereBuilder: WhereBuilder,\n\t\tprivate readonly pathFactory: PathFactory,\n\t\tprivate readonly predicateFactory: PredicateFactory,\n\t) {}\n\n\tpublic addFieldValue(\n\t\tfieldName: string,\n\t\tvalue: Value.GenericValueLike<Value.AtomicValue<AbortDataManipulation | undefined>>,\n\t): Promise<Value.AtomicValue<AbortDataManipulation | undefined>> {\n\t\tconst columnName = getColumnName(this.schema, this.entity, fieldName)\n\t\tconst columnType = getColumnType(this.schema, this.entity, fieldName)\n\t\tconst resolvedValue = resolveGenericValue(value)\n\t\tthis.rowData.set(columnName, { columnName, value: resolvedValue, columnType, fieldName })\n\t\treturn resolvedValue\n\t}\n\n\tpublic addPredicates(fields: string[]): void {\n\t\tconst where = this.predicateFactory.create(this.entity, Acl.Operation.create, fields)\n\t\tthis.addWhere(where)\n\t}\n\n\tpublic addWhere(where: Input.OptionalWhere): void {\n\t\tthis.where.and.push(where)\n\t}\n\n\tpublic async getResolvedData(): Promise<ResolvedColumnValue<AbortDataManipulation>[]> {\n\t\treturn resolveRowData([...this.rowData.values()])\n\t}\n\n\tpublic async execute(mapper: Mapper): Promise<InsertResult> {\n\t\ttry {\n\t\t\tconst resolvedData = await this.getResolvedData()\n\t\t\tif (resolvedData.find(it => it.resolvedValue === AbortDataManipulation)) {\n\t\t\t\tthis.resolver(null)\n\t\t\t\treturn { aborted: true, executed: false, primaryValue: null, values: [] }\n\t\t\t}\n\n\t\t\tconst insertData = resolvedData.reduce<QueryBuilder.ColumnExpressionMap>(\n\t\t\t\t(result, item) => ({ ...result, [item.columnName]: expr => expr.select(['root_', item.columnName]) }),\n\t\t\t\t{},\n\t\t\t)\n\t\t\tconst qb = DbInsertBuilder.create()\n\t\t\t\t.with('root_', qb => {\n\t\t\t\t\treturn resolvedData.reduce(\n\t\t\t\t\t\t(qb, value) =>\n\t\t\t\t\t\t\tqb.select(expr => expr.selectValue(value.resolvedValue as DbValue, value.columnType), value.columnName),\n\t\t\t\t\t\tqb,\n\t\t\t\t\t)\n\t\t\t\t})\n\t\t\t\t.into(this.entity.tableName)\n\t\t\t\t.values(insertData)\n\t\t\t\t.from(qb => {\n\t\t\t\t\tqb = qb.from('root_')\n\t\t\t\t\treturn this.whereBuilder.build(qb, this.entity, this.pathFactory.create([]), this.where)\n\t\t\t\t})\n\t\t\t\t.returning(this.entity.primaryColumn)\n\n\t\t\tconst beforeInsertEvent = new BeforeInsertEvent(this.entity, resolvedData as ResolvedColumnValue[])\n\t\t\tawait mapper.eventManager.fire(beforeInsertEvent)\n\n\t\t\tconst returning = (await qb.execute(mapper.db)).map(it => it[this.entity.primaryColumn])\n\t\t\tconst result = returning.length === 1 ? returning[0] : null\n\n\t\t\tconst afterInsertEvent = new AfterInsertEvent(this.entity, resolvedData as ResolvedColumnValue[], result)\n\t\t\tbeforeInsertEvent.afterEvent = afterInsertEvent\n\t\t\tawait mapper.eventManager.fire(afterInsertEvent)\n\n\t\t\tthis.resolver(result)\n\t\t\treturn { values: resolvedData as ResolvedColumnValue[], executed: true, primaryValue: result, aborted: false }\n\t\t} catch (e) {\n\t\t\tthis.resolver(null)\n\t\t\tthrow e\n\t\t}\n\t}\n}\n"],"names":["schema","ImplementationException","getColumnName","getColumnType","resolveGenericValue","Acl","resolveRowData","AbortDataManipulation","result","DbInsertBuilder","qb","BeforeInsertEvent","AfterInsertEvent"],"mappings":";;;;;;;;;;;;AAkBO,MAAM,cAAiD;AAAA,EAS7D,YACkBA,SACA,QACA,cACA,aACA,kBAChB;AALgB,SAAA,SAAAA;AACA,SAAA,SAAA;AACA,SAAA,eAAA;AACA,SAAA,cAAA;AACA,SAAA,mBAAA;AAblB,kBAAA,MAAQ,YAAuD,MAAM;AAC9D,YAAA,IAAIC,UAAAA,wBAAwB,yCAAyC;AAAA,IAAA,CAC5E;AACA,kBAAA,MAAgB,UAA6C,IAAI,QAAQ,CAAY,YAAA,KAAK,WAAW,OAAQ,CAAA;AAErG,kBAAA,MAAA,+BAA2E,IAAI,CAAA;AACvF,kBAAA,MAAQ,SAAwC,EAAE,KAAK,CAAA,EAAG,CAAA;AAAA,EAQvD;AAAA,EAEI,cACN,WACA,OACgE;AAChE,UAAM,aAAaC,YA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AA,EACA,KAAK,KAAK,OAAO,SAAS,EAC1B,OAAO,UAAU,EACjB,KAAK,CAAAA,QAAM;AACXA,cAAKA,IAAG,KAAK,OAAO;AACpB,eAAO,KAAK,aAAa,MAAMA,KAAI,KAAK,QAAQ,KAAK,YAAY,OAAO,CAAA,CAAE,GAAG,KAAK,KAAK;AAAA,MACvF,CAAA,EACA,UAAU,KAAK,OAAO,aAAa;AAErC,YAAM,oBAAoB,IAAIC,aAAkB,kBAAA,KAAK,QAAQ,YAAqC;AAC5F,YAAA,OAAO,aAAa,KAAK,iBAAiB;AAEhD,YAAM,aAAa,MAAM,GAAG,QAAQ,OAAO,EAAE,GAAG,IAAI,CAAM,OAAA,GAAG,KAAK,OAAO,aAAa,CAAC;AACvF,YAAM,SAAS,UAAU,WAAW,IAAI,UAAU,CAAC,IAAI;AAEvD,YAAM,mBAAmB,IAAIC,8BAAiB,KAAK,QAAQ,cAAuC,MAAM;AACxG,wBAAkB,aAAa;AACzB,YAAA,OAAO,aAAa,KAAK,gBAAgB;AAE/C,WAAK,SAAS,MAAM;AACb,aAAA,EAAE,QAAQ,cAAuC,UAAU,MAAM,cAAc,QAAQ,SAAS;aAC/F,GAAG;AACX,WAAK,SAAS,IAAI;AACZ,YAAA;AAAA,IACP;AAAA,EACD;AACD;;"}
1
+ {"version":3,"file":"InsertBuilder.cjs","sources":["../../../../../../packages/engine-content-api/src/mapper/insert/InsertBuilder.ts"],"sourcesContent":["import { Acl, Input, Model, Value } from '@contember/schema'\nimport { InsertBuilder as DbInsertBuilder, QueryBuilder, Value as DbValue } from '@contember/database'\nimport { PathFactory, WhereBuilder } from '../select'\nimport { getColumnName, getColumnType } from '@contember/schema-utils'\nimport { ColumnValue, ResolvedColumnValue, resolveGenericValue, resolveRowData } from '../ColumnValue'\nimport { PredicateFactory } from '../../acl'\nimport { AfterInsertEvent, BeforeInsertEvent } from '../EventManager'\nimport { Mapper } from '../Mapper'\n\nexport interface InsertResult {\n\tvalues: ResolvedColumnValue[]\n\texecuted: boolean\n\tprimaryValue: Value.PrimaryValue | null\n}\n\nexport class InsertBuilder {\n\tprivate rowData: Map<string, ColumnValue<undefined>> = new Map()\n\tprivate where: { and: Input.OptionalWhere[] } = { and: [] }\n\n\tconstructor(\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly entity: Model.Entity,\n\t\tprivate readonly whereBuilder: WhereBuilder,\n\t\tprivate readonly pathFactory: PathFactory,\n\t\tprivate readonly predicateFactory: PredicateFactory,\n\t) {}\n\n\tpublic addFieldValue(\n\t\tfieldName: string,\n\t\tvalue: Value.GenericValueLike<Value.AtomicValue<undefined>>,\n\t): Promise<Value.AtomicValue<undefined>> {\n\t\tconst columnName = getColumnName(this.schema, this.entity, fieldName)\n\t\tconst columnType = getColumnType(this.schema, this.entity, fieldName)\n\t\tconst resolvedValue = resolveGenericValue(value)\n\t\tthis.rowData.set(columnName, { columnName, value: resolvedValue, columnType, fieldName })\n\t\treturn resolvedValue\n\t}\n\n\tpublic addPredicates(fields: string[]): void {\n\t\tconst where = this.predicateFactory.create(this.entity, Acl.Operation.create, fields)\n\t\tthis.addWhere(where)\n\t}\n\n\tpublic addWhere(where: Input.OptionalWhere): void {\n\t\tthis.where.and.push(where)\n\t}\n\n\tpublic async getResolvedData(): Promise<ResolvedColumnValue[]> {\n\t\treturn resolveRowData([...this.rowData.values()])\n\t}\n\n\tpublic async execute(mapper: Mapper): Promise<InsertResult> {\n\t\ttry {\n\t\t\tconst resolvedData = await this.getResolvedData()\n\n\t\t\tconst insertData = resolvedData.reduce<QueryBuilder.ColumnExpressionMap>(\n\t\t\t\t(result, item) => ({ ...result, [item.columnName]: expr => expr.select(['root_', item.columnName]) }),\n\t\t\t\t{},\n\t\t\t)\n\t\t\tconst qb = DbInsertBuilder.create()\n\t\t\t\t.with('root_', qb => {\n\t\t\t\t\treturn resolvedData.reduce(\n\t\t\t\t\t\t(qb, value) =>\n\t\t\t\t\t\t\tqb.select(expr => expr.selectValue(value.resolvedValue as DbValue, value.columnType), value.columnName),\n\t\t\t\t\t\tqb,\n\t\t\t\t\t)\n\t\t\t\t})\n\t\t\t\t.into(this.entity.tableName)\n\t\t\t\t.values(insertData)\n\t\t\t\t.from(qb => {\n\t\t\t\t\tqb = qb.from('root_')\n\t\t\t\t\treturn this.whereBuilder.build(qb, this.entity, this.pathFactory.create([]), this.where)\n\t\t\t\t})\n\t\t\t\t.returning(this.entity.primaryColumn)\n\n\t\t\tconst beforeInsertEvent = new BeforeInsertEvent(this.entity, resolvedData as ResolvedColumnValue[])\n\t\t\tawait mapper.eventManager.fire(beforeInsertEvent)\n\n\t\t\tconst returning = (await qb.execute(mapper.db)).map(it => it[this.entity.primaryColumn])\n\t\t\tconst result = returning.length === 1 ? returning[0] : null\n\n\t\t\tconst afterInsertEvent = new AfterInsertEvent(this.entity, resolvedData as ResolvedColumnValue[], result)\n\t\t\tbeforeInsertEvent.afterEvent = afterInsertEvent\n\t\t\tawait mapper.eventManager.fire(afterInsertEvent)\n\n\t\t\treturn { values: resolvedData as ResolvedColumnValue[], executed: true, primaryValue: result }\n\t\t} catch (e) {\n\t\t\tthrow e\n\t\t}\n\t}\n}\n"],"names":["schema","getColumnName","getColumnType","resolveGenericValue","Acl","resolveRowData","result","DbInsertBuilder","qb","BeforeInsertEvent","AfterInsertEvent"],"mappings":";;;;;;;;;;AAeO,MAAM,cAAc;AAAA,EAI1B,YACkBA,SACA,QACA,cACA,aACA,kBAChB;AALgB,SAAA,SAAAA;AACA,SAAA,SAAA;AACA,SAAA,eAAA;AACA,SAAA,cAAA;AACA,SAAA,mBAAA;AARV,kBAAA,MAAA,+BAAmD,IAAI,CAAA;AAC/D,kBAAA,MAAQ,SAAwC,EAAE,KAAK,CAAA,EAAG,CAAA;AAAA,EAQvD;AAAA,EAEI,cACN,WACA,OACwC;AACxC,UAAM,aAAaC,YAAAA,cAAc,KAAK,QAAQ,KAAK,QAAQ,SAAS;AACpE,UAAM,aAAaC,YAAAA,cAAc,KAAK,QAAQ,KA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YAAM,oBAAoB,IAAIC,aAAkB,kBAAA,KAAK,QAAQ,YAAqC;AAC5F,YAAA,OAAO,aAAa,KAAK,iBAAiB;AAEhD,YAAM,aAAa,MAAM,GAAG,QAAQ,OAAO,EAAE,GAAG,IAAI,CAAM,OAAA,GAAG,KAAK,OAAO,aAAa,CAAC;AACvF,YAAM,SAAS,UAAU,WAAW,IAAI,UAAU,CAAC,IAAI;AAEvD,YAAM,mBAAmB,IAAIC,8BAAiB,KAAK,QAAQ,cAAuC,MAAM;AACxG,wBAAkB,aAAa;AACzB,YAAA,OAAO,aAAa,KAAK,gBAAgB;AAE/C,aAAO,EAAE,QAAQ,cAAuC,UAAU,MAAM,cAAc;aAC9E,GAAG;AACL,YAAA;AAAA,IACP;AAAA,EACD;AACD;;"}
@@ -2,8 +2,6 @@ import { Acl } from "@contember/schema";
2
2
  import { InsertBuilder as InsertBuilder$1 } from "@contember/database";
3
3
  import { getColumnName, getColumnType } from "@contember/schema-utils";
4
4
  import { resolveGenericValue, resolveRowData } from "../ColumnValue.js";
5
- import { ImplementationException } from "../../exception.js";
6
- import { AbortDataManipulation } from "../DataManipulationBuilder.js";
7
5
  import { BeforeInsertEvent, AfterInsertEvent } from "../EventManager.js";
8
6
  var __defProp = Object.defineProperty;
9
7
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
@@ -15,10 +13,6 @@ class InsertBuilder {
15
13
  this.whereBuilder = whereBuilder;
16
14
  this.pathFactory = pathFactory;
17
15
  this.predicateFactory = predicateFactory;
18
- __publicField(this, "resolver", () => {
19
- throw new ImplementationException("InsertBuilder: Resolver called too soon");
20
- });
21
- __publicField(this, "insert", new Promise((resolve) => this.resolver = resolve));
22
16
  __publicField(this, "rowData", /* @__PURE__ */ new Map());
23
17
  __publicField(this, "where", { and: [] });
24
18
  }
@@ -42,10 +36,6 @@ class InsertBuilder {
42
36
  async execute(mapper) {
43
37
  try {
44
38
  const resolvedData = await this.getResolvedData();
45
- if (resolvedData.find((it) => it.resolvedValue === AbortDataManipulation)) {
46
- this.resolver(null);
47
- return { aborted: true, executed: false, primaryValue: null, values: [] };
48
- }
49
39
  const insertData = resolvedData.reduce(
50
40
  (result2, item) => ({ ...result2, [item.columnName]: (expr) => expr.select(["root_", item.columnName]) }),
51
41
  {}
@@ -66,10 +56,8 @@ class InsertBuilder {
66
56
  const afterInsertEvent = new AfterInsertEvent(this.entity, resolvedData, result);
67
57
  beforeInsertEvent.afterEvent = afterInsertEvent;
68
58
  await mapper.eventManager.fire(afterInsertEvent);
69
- this.resolver(result);
70
- return { values: resolvedData, executed: true, primaryValue: result, aborted: false };
59
+ return { values: resolvedData, executed: true, primaryValue: result };
71
60
  } catch (e) {
72
- this.resolver(null);
73
61
  throw e;
74
62
  }
75
63
  }
@@ -1 +1 @@
1
- {"version":3,"file":"InsertBuilder.js","sources":["../../../../../../packages/engine-content-api/src/mapper/insert/InsertBuilder.ts"],"sourcesContent":["import { Acl, Input, Model, Value } from '@contember/schema'\nimport { Client, InsertBuilder as DbInsertBuilder, QueryBuilder, Value as DbValue } from '@contember/database'\nimport { PathFactory, WhereBuilder } from '../select'\nimport { getColumnName, getColumnType } from '@contember/schema-utils'\nimport { ColumnValue, ResolvedColumnValue, resolveGenericValue, resolveRowData } from '../ColumnValue'\nimport { ImplementationException } from '../../exception'\nimport { PredicateFactory } from '../../acl'\nimport { AbortDataManipulation, DataManipulationBuilder } from '../DataManipulationBuilder'\nimport { AfterInsertEvent, BeforeInsertEvent, EventManager } from '../EventManager'\nimport { Mapper } from '../Mapper'\n\nexport interface InsertResult {\n\tvalues: ResolvedColumnValue[]\n\texecuted: boolean\n\taborted: boolean\n\tprimaryValue: Value.PrimaryValue | null\n}\n\nexport class InsertBuilder implements DataManipulationBuilder {\n\tprivate resolver: (value: Value.PrimaryValue | null) => void = () => {\n\t\tthrow new ImplementationException('InsertBuilder: Resolver called too soon')\n\t}\n\tpublic readonly insert: Promise<Value.PrimaryValue | null> = new Promise(resolve => (this.resolver = resolve))\n\n\tprivate rowData: Map<string, ColumnValue<AbortDataManipulation | undefined>> = new Map()\n\tprivate where: { and: Input.OptionalWhere[] } = { and: [] }\n\n\tconstructor(\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly entity: Model.Entity,\n\t\tprivate readonly whereBuilder: WhereBuilder,\n\t\tprivate readonly pathFactory: PathFactory,\n\t\tprivate readonly predicateFactory: PredicateFactory,\n\t) {}\n\n\tpublic addFieldValue(\n\t\tfieldName: string,\n\t\tvalue: Value.GenericValueLike<Value.AtomicValue<AbortDataManipulation | undefined>>,\n\t): Promise<Value.AtomicValue<AbortDataManipulation | undefined>> {\n\t\tconst columnName = getColumnName(this.schema, this.entity, fieldName)\n\t\tconst columnType = getColumnType(this.schema, this.entity, fieldName)\n\t\tconst resolvedValue = resolveGenericValue(value)\n\t\tthis.rowData.set(columnName, { columnName, value: resolvedValue, columnType, fieldName })\n\t\treturn resolvedValue\n\t}\n\n\tpublic addPredicates(fields: string[]): void {\n\t\tconst where = this.predicateFactory.create(this.entity, Acl.Operation.create, fields)\n\t\tthis.addWhere(where)\n\t}\n\n\tpublic addWhere(where: Input.OptionalWhere): void {\n\t\tthis.where.and.push(where)\n\t}\n\n\tpublic async getResolvedData(): Promise<ResolvedColumnValue<AbortDataManipulation>[]> {\n\t\treturn resolveRowData([...this.rowData.values()])\n\t}\n\n\tpublic async execute(mapper: Mapper): Promise<InsertResult> {\n\t\ttry {\n\t\t\tconst resolvedData = await this.getResolvedData()\n\t\t\tif (resolvedData.find(it => it.resolvedValue === AbortDataManipulation)) {\n\t\t\t\tthis.resolver(null)\n\t\t\t\treturn { aborted: true, executed: false, primaryValue: null, values: [] }\n\t\t\t}\n\n\t\t\tconst insertData = resolvedData.reduce<QueryBuilder.ColumnExpressionMap>(\n\t\t\t\t(result, item) => ({ ...result, [item.columnName]: expr => expr.select(['root_', item.columnName]) }),\n\t\t\t\t{},\n\t\t\t)\n\t\t\tconst qb = DbInsertBuilder.create()\n\t\t\t\t.with('root_', qb => {\n\t\t\t\t\treturn resolvedData.reduce(\n\t\t\t\t\t\t(qb, value) =>\n\t\t\t\t\t\t\tqb.select(expr => expr.selectValue(value.resolvedValue as DbValue, value.columnType), value.columnName),\n\t\t\t\t\t\tqb,\n\t\t\t\t\t)\n\t\t\t\t})\n\t\t\t\t.into(this.entity.tableName)\n\t\t\t\t.values(insertData)\n\t\t\t\t.from(qb => {\n\t\t\t\t\tqb = qb.from('root_')\n\t\t\t\t\treturn this.whereBuilder.build(qb, this.entity, this.pathFactory.create([]), this.where)\n\t\t\t\t})\n\t\t\t\t.returning(this.entity.primaryColumn)\n\n\t\t\tconst beforeInsertEvent = new BeforeInsertEvent(this.entity, resolvedData as ResolvedColumnValue[])\n\t\t\tawait mapper.eventManager.fire(beforeInsertEvent)\n\n\t\t\tconst returning = (await qb.execute(mapper.db)).map(it => it[this.entity.primaryColumn])\n\t\t\tconst result = returning.length === 1 ? returning[0] : null\n\n\t\t\tconst afterInsertEvent = new AfterInsertEvent(this.entity, resolvedData as ResolvedColumnValue[], result)\n\t\t\tbeforeInsertEvent.afterEvent = afterInsertEvent\n\t\t\tawait mapper.eventManager.fire(afterInsertEvent)\n\n\t\t\tthis.resolver(result)\n\t\t\treturn { values: resolvedData as ResolvedColumnValue[], executed: true, primaryValue: result, aborted: false }\n\t\t} catch (e) {\n\t\t\tthis.resolver(null)\n\t\t\tthrow e\n\t\t}\n\t}\n}\n"],"names":["result","DbInsertBuilder","qb"],"mappings":";;;;;;;;;;AAkBO,MAAM,cAAiD;AAAA,EAS7D,YACkB,QACA,QACA,cACA,aACA,kBAChB;AALgB,SAAA,SAAA;AACA,SAAA,SAAA;AACA,SAAA,eAAA;AACA,SAAA,cAAA;AACA,SAAA,mBAAA;AAblB,kBAAA,MAAQ,YAAuD,MAAM;AAC9D,YAAA,IAAI,wBAAwB,yCAAyC;AAAA,IAAA,CAC5E;AACA,kBAAA,MAAgB,UAA6C,IA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pB,eAAO,aAAa;AAAA,UACnB,CAACA,KAAI,UACJA,IAAG,OAAO,CAAQ,SAAA,KAAK,YAAY,MAAM,eAA0B,MAAM,UAAU,GAAG,MAAM,UAAU;AAAA,UACvGA;AAAAA,QAAA;AAAA,MAED,CAAA,EACA,KAAK,KAAK,OAAO,SAAS,EAC1B,OAAO,UAAU,EACjB,KAAK,CAAAA,QAAM;AACXA,cAAKA,IAAG,KAAK,OAAO;AACpB,eAAO,KAAK,aAAa,MAAMA,KAAI,KAAK,QAAQ,KAAK,YAAY,OAAO,CAAA,CAAE,GAAG,KAAK,KAAK;AAAA,MACvF,CAAA,EACA,UAAU,KAAK,OAAO,aAAa;AAErC,YAAM,oBAAoB,IAAI,kBAAkB,KAAK,QAAQ,YAAqC;AAC5F,YAAA,OAAO,aAAa,KAAK,iBAAiB;AAEhD,YAAM,aAAa,MAAM,GAAG,QAAQ,OAAO,EAAE,GAAG,IAAI,CAAM,OAAA,GAAG,KAAK,OAAO,aAAa,CAAC;AACvF,YAAM,SAAS,UAAU,WAAW,IAAI,UAAU,CAAC,IAAI;AAEvD,YAAM,mBAAmB,IAAI,iBAAiB,KAAK,QAAQ,cAAuC,MAAM;AACxG,wBAAkB,aAAa;AACzB,YAAA,OAAO,aAAa,KAAK,gBAAgB;AAE/C,WAAK,SAAS,MAAM;AACb,aAAA,EAAE,QAAQ,cAAuC,UAAU,MAAM,cAAc,QAAQ,SAAS;aAC/F,GAAG;AACX,WAAK,SAAS,IAAI;AACZ,YAAA;AAAA,IACP;AAAA,EACD;AACD;"}
1
+ {"version":3,"file":"InsertBuilder.js","sources":["../../../../../../packages/engine-content-api/src/mapper/insert/InsertBuilder.ts"],"sourcesContent":["import { Acl, Input, Model, Value } from '@contember/schema'\nimport { InsertBuilder as DbInsertBuilder, QueryBuilder, Value as DbValue } from '@contember/database'\nimport { PathFactory, WhereBuilder } from '../select'\nimport { getColumnName, getColumnType } from '@contember/schema-utils'\nimport { ColumnValue, ResolvedColumnValue, resolveGenericValue, resolveRowData } from '../ColumnValue'\nimport { PredicateFactory } from '../../acl'\nimport { AfterInsertEvent, BeforeInsertEvent } from '../EventManager'\nimport { Mapper } from '../Mapper'\n\nexport interface InsertResult {\n\tvalues: ResolvedColumnValue[]\n\texecuted: boolean\n\tprimaryValue: Value.PrimaryValue | null\n}\n\nexport class InsertBuilder {\n\tprivate rowData: Map<string, ColumnValue<undefined>> = new Map()\n\tprivate where: { and: Input.OptionalWhere[] } = { and: [] }\n\n\tconstructor(\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly entity: Model.Entity,\n\t\tprivate readonly whereBuilder: WhereBuilder,\n\t\tprivate readonly pathFactory: PathFactory,\n\t\tprivate readonly predicateFactory: PredicateFactory,\n\t) {}\n\n\tpublic addFieldValue(\n\t\tfieldName: string,\n\t\tvalue: Value.GenericValueLike<Value.AtomicValue<undefined>>,\n\t): Promise<Value.AtomicValue<undefined>> {\n\t\tconst columnName = getColumnName(this.schema, this.entity, fieldName)\n\t\tconst columnType = getColumnType(this.schema, this.entity, fieldName)\n\t\tconst resolvedValue = resolveGenericValue(value)\n\t\tthis.rowData.set(columnName, { columnName, value: resolvedValue, columnType, fieldName })\n\t\treturn resolvedValue\n\t}\n\n\tpublic addPredicates(fields: string[]): void {\n\t\tconst where = this.predicateFactory.create(this.entity, Acl.Operation.create, fields)\n\t\tthis.addWhere(where)\n\t}\n\n\tpublic addWhere(where: Input.OptionalWhere): void {\n\t\tthis.where.and.push(where)\n\t}\n\n\tpublic async getResolvedData(): Promise<ResolvedColumnValue[]> {\n\t\treturn resolveRowData([...this.rowData.values()])\n\t}\n\n\tpublic async execute(mapper: Mapper): Promise<InsertResult> {\n\t\ttry {\n\t\t\tconst resolvedData = await this.getResolvedData()\n\n\t\t\tconst insertData = resolvedData.reduce<QueryBuilder.ColumnExpressionMap>(\n\t\t\t\t(result, item) => ({ ...result, [item.columnName]: expr => expr.select(['root_', item.columnName]) }),\n\t\t\t\t{},\n\t\t\t)\n\t\t\tconst qb = DbInsertBuilder.create()\n\t\t\t\t.with('root_', qb => {\n\t\t\t\t\treturn resolvedData.reduce(\n\t\t\t\t\t\t(qb, value) =>\n\t\t\t\t\t\t\tqb.select(expr => expr.selectValue(value.resolvedValue as DbValue, value.columnType), value.columnName),\n\t\t\t\t\t\tqb,\n\t\t\t\t\t)\n\t\t\t\t})\n\t\t\t\t.into(this.entity.tableName)\n\t\t\t\t.values(insertData)\n\t\t\t\t.from(qb => {\n\t\t\t\t\tqb = qb.from('root_')\n\t\t\t\t\treturn this.whereBuilder.build(qb, this.entity, this.pathFactory.create([]), this.where)\n\t\t\t\t})\n\t\t\t\t.returning(this.entity.primaryColumn)\n\n\t\t\tconst beforeInsertEvent = new BeforeInsertEvent(this.entity, resolvedData as ResolvedColumnValue[])\n\t\t\tawait mapper.eventManager.fire(beforeInsertEvent)\n\n\t\t\tconst returning = (await qb.execute(mapper.db)).map(it => it[this.entity.primaryColumn])\n\t\t\tconst result = returning.length === 1 ? returning[0] : null\n\n\t\t\tconst afterInsertEvent = new AfterInsertEvent(this.entity, resolvedData as ResolvedColumnValue[], result)\n\t\t\tbeforeInsertEvent.afterEvent = afterInsertEvent\n\t\t\tawait mapper.eventManager.fire(afterInsertEvent)\n\n\t\t\treturn { values: resolvedData as ResolvedColumnValue[], executed: true, primaryValue: result }\n\t\t} catch (e) {\n\t\t\tthrow e\n\t\t}\n\t}\n}\n"],"names":["result","DbInsertBuilder","qb"],"mappings":";;;;;;;;AAeO,MAAM,cAAc;AAAA,EAI1B,YACkB,QACA,QACA,cACA,aACA,kBAChB;AALgB,SAAA,SAAA;AACA,SAAA,SAAA;AACA,SAAA,eAAA;AACA,SAAA,cAAA;AACA,SAAA,mBAAA;AARV,kBAAA,MAAA,+BAAmD,IAAI,CAAA;AAC/D,kBAAA,MAAQ,SAAwC,EAAE,KAAK,CAAA,EAAG,CAAA;AAAA,EAQvD;AAAA,EAEI,cACN,WACA,OACwC;AACxC,UAAM,aAAa,cAAc,KAAK,Q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