@contember/engine-content-api 2.2.0-alpha.17 → 2.2.0-alpha.19

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 (405) hide show
  1. package/CLAUDE.md +1 -1
  2. package/dist/development/index.cjs +3 -0
  3. package/dist/development/index.cjs.map +1 -1
  4. package/dist/development/index.js +4 -1
  5. package/dist/development/index.js.map +1 -1
  6. package/dist/development/src/ExecutionContainer.cjs +1 -0
  7. package/dist/development/src/ExecutionContainer.cjs.map +1 -1
  8. package/dist/development/src/ExecutionContainer.js +1 -0
  9. package/dist/development/src/ExecutionContainer.js.map +1 -1
  10. package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.cjs +2 -1
  11. package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.cjs.map +1 -1
  12. package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.js +2 -1
  13. package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.js.map +1 -1
  14. package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.cjs +5 -1
  15. package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.cjs.map +1 -1
  16. package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.js +5 -1
  17. package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.js.map +1 -1
  18. package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.cjs +2 -1
  19. package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.cjs.map +1 -1
  20. package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.js +2 -1
  21. package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.js.map +1 -1
  22. package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.cjs +4 -1
  23. package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.cjs.map +1 -1
  24. package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.js +4 -1
  25. package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.js.map +1 -1
  26. package/dist/development/src/input-validation/preValidation/UpdateInputPreValidationProcessor.cjs +24 -3
  27. package/dist/development/src/input-validation/preValidation/UpdateInputPreValidationProcessor.cjs.map +1 -1
  28. package/dist/development/src/input-validation/preValidation/UpdateInputPreValidationProcessor.js +24 -3
  29. package/dist/development/src/input-validation/preValidation/UpdateInputPreValidationProcessor.js.map +1 -1
  30. package/dist/development/src/inputProcessing/UpdateInputVisitor.cjs +52 -2
  31. package/dist/development/src/inputProcessing/UpdateInputVisitor.cjs.map +1 -1
  32. package/dist/development/src/inputProcessing/UpdateInputVisitor.js +52 -2
  33. package/dist/development/src/inputProcessing/UpdateInputVisitor.js.map +1 -1
  34. package/dist/development/src/mapper/ErrorUtils.cjs +10 -0
  35. package/dist/development/src/mapper/ErrorUtils.cjs.map +1 -1
  36. package/dist/development/src/mapper/ErrorUtils.js +10 -0
  37. package/dist/development/src/mapper/ErrorUtils.js.map +1 -1
  38. package/dist/development/src/mapper/Mapper.cjs +37 -1
  39. package/dist/development/src/mapper/Mapper.cjs.map +1 -1
  40. package/dist/development/src/mapper/Mapper.js +38 -2
  41. package/dist/development/src/mapper/Mapper.js.map +1 -1
  42. package/dist/development/src/mapper/MutationProcessorHelper.cjs +12 -0
  43. package/dist/development/src/mapper/MutationProcessorHelper.cjs.map +1 -1
  44. package/dist/development/src/mapper/MutationProcessorHelper.js +13 -1
  45. package/dist/development/src/mapper/MutationProcessorHelper.js.map +1 -1
  46. package/dist/development/src/mapper/Result.cjs +1 -0
  47. package/dist/development/src/mapper/Result.cjs.map +1 -1
  48. package/dist/development/src/mapper/Result.js +1 -0
  49. package/dist/development/src/mapper/Result.js.map +1 -1
  50. package/dist/development/src/mapper/delete/DeleteExecutor.cjs +1 -1
  51. package/dist/development/src/mapper/delete/DeleteExecutor.js +1 -1
  52. package/dist/development/src/mapper/select/Path.cjs +2 -2
  53. package/dist/development/src/mapper/select/Path.cjs.map +1 -1
  54. package/dist/development/src/mapper/select/Path.js +2 -2
  55. package/dist/development/src/mapper/select/Path.js.map +1 -1
  56. package/dist/development/src/mapper/select/handlers/MetaHandler.cjs +1 -1
  57. package/dist/development/src/mapper/select/handlers/MetaHandler.js +1 -1
  58. package/dist/development/src/mapper/select/optimizer/WhereOptimizer.cjs +2 -2
  59. package/dist/development/src/mapper/select/optimizer/WhereOptimizer.cjs.map +1 -1
  60. package/dist/development/src/mapper/select/optimizer/WhereOptimizer.js +1 -1
  61. package/dist/development/src/mapper/select/optimizer/WhereOptimizer.js.map +1 -1
  62. package/dist/development/src/mapper/select/optimizer/WhereReplacer.cjs +3 -3
  63. package/dist/development/src/mapper/select/optimizer/WhereReplacer.cjs.map +1 -1
  64. package/dist/development/src/mapper/select/optimizer/WhereReplacer.js +1 -1
  65. package/dist/development/src/mapper/select/optimizer/WhereReplacer.js.map +1 -1
  66. package/dist/development/src/mapper/update/SqlUpdateInputProcessor.cjs +6 -3
  67. package/dist/development/src/mapper/update/SqlUpdateInputProcessor.cjs.map +1 -1
  68. package/dist/development/src/mapper/update/SqlUpdateInputProcessor.js +7 -4
  69. package/dist/development/src/mapper/update/SqlUpdateInputProcessor.js.map +1 -1
  70. package/dist/development/src/mapper/update/Updater.cjs +1 -1
  71. package/dist/development/src/mapper/update/Updater.js +1 -1
  72. package/dist/development/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.cjs +6 -0
  73. package/dist/development/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.cjs.map +1 -1
  74. package/dist/development/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.js +6 -0
  75. package/dist/development/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.js.map +1 -1
  76. package/dist/development/src/mapper/update/relations/OneHasManyUpdateInputProcessor.cjs +6 -0
  77. package/dist/development/src/mapper/update/relations/OneHasManyUpdateInputProcessor.cjs.map +1 -1
  78. package/dist/development/src/mapper/update/relations/OneHasManyUpdateInputProcessor.js +6 -0
  79. package/dist/development/src/mapper/update/relations/OneHasManyUpdateInputProcessor.js.map +1 -1
  80. package/dist/development/src/mapper/update/relations/SetManyRelationHelper.cjs +123 -0
  81. package/dist/development/src/mapper/update/relations/SetManyRelationHelper.cjs.map +1 -0
  82. package/dist/development/src/mapper/update/relations/SetManyRelationHelper.js +123 -0
  83. package/dist/development/src/mapper/update/relations/SetManyRelationHelper.js.map +1 -0
  84. package/dist/development/src/resolvers/MutationResolver.cjs +4 -1
  85. package/dist/development/src/resolvers/MutationResolver.cjs.map +1 -1
  86. package/dist/development/src/resolvers/MutationResolver.js +4 -1
  87. package/dist/development/src/resolvers/MutationResolver.js.map +1 -1
  88. package/dist/development/src/resolvers/ReadHelpers.cjs +2 -1
  89. package/dist/development/src/resolvers/ReadHelpers.cjs.map +1 -1
  90. package/dist/development/src/resolvers/ReadHelpers.js +2 -1
  91. package/dist/development/src/resolvers/ReadHelpers.js.map +1 -1
  92. package/dist/development/src/schema/CustomTypesProvider.cjs +35 -14
  93. package/dist/development/src/schema/CustomTypesProvider.cjs.map +1 -1
  94. package/dist/development/src/schema/CustomTypesProvider.js +36 -15
  95. package/dist/development/src/schema/CustomTypesProvider.js.map +1 -1
  96. package/dist/development/src/schema/EntityTypeProvider.cjs +8 -5
  97. package/dist/development/src/schema/EntityTypeProvider.cjs.map +1 -1
  98. package/dist/development/src/schema/EntityTypeProvider.js +8 -5
  99. package/dist/development/src/schema/EntityTypeProvider.js.map +1 -1
  100. package/dist/development/src/schema/GraphQlSchemaBuilderFactory.cjs +1 -1
  101. package/dist/development/src/schema/GraphQlSchemaBuilderFactory.js +1 -1
  102. package/dist/development/src/schema/MutationProvider.cjs +4 -0
  103. package/dist/development/src/schema/MutationProvider.cjs.map +1 -1
  104. package/dist/development/src/schema/MutationProvider.js +4 -0
  105. package/dist/development/src/schema/MutationProvider.js.map +1 -1
  106. package/dist/development/src/schema/OrderByTypeProvider.cjs +8 -2
  107. package/dist/development/src/schema/OrderByTypeProvider.cjs.map +1 -1
  108. package/dist/development/src/schema/OrderByTypeProvider.js +9 -3
  109. package/dist/development/src/schema/OrderByTypeProvider.js.map +1 -1
  110. package/dist/development/src/schema/QueryProvider.cjs +3 -0
  111. package/dist/development/src/schema/QueryProvider.cjs.map +1 -1
  112. package/dist/development/src/schema/QueryProvider.js +3 -0
  113. package/dist/development/src/schema/QueryProvider.js.map +1 -1
  114. package/dist/development/src/schema/ValidationQueriesProvider.cjs +2 -0
  115. package/dist/development/src/schema/ValidationQueriesProvider.cjs.map +1 -1
  116. package/dist/development/src/schema/ValidationQueriesProvider.js +2 -0
  117. package/dist/development/src/schema/ValidationQueriesProvider.js.map +1 -1
  118. package/dist/development/src/schema/WhereTypeProvider.cjs +17 -5
  119. package/dist/development/src/schema/WhereTypeProvider.cjs.map +1 -1
  120. package/dist/development/src/schema/WhereTypeProvider.js +18 -6
  121. package/dist/development/src/schema/WhereTypeProvider.js.map +1 -1
  122. package/dist/development/src/schema/calendarDate.cjs +21 -0
  123. package/dist/development/src/schema/calendarDate.cjs.map +1 -0
  124. package/dist/development/src/schema/calendarDate.js +21 -0
  125. package/dist/development/src/schema/calendarDate.js.map +1 -0
  126. package/dist/development/src/schema/mutations/CreateEntityInputFieldVisitor.cjs +11 -3
  127. package/dist/development/src/schema/mutations/CreateEntityInputFieldVisitor.cjs.map +1 -1
  128. package/dist/development/src/schema/mutations/CreateEntityInputFieldVisitor.js +11 -3
  129. package/dist/development/src/schema/mutations/CreateEntityInputFieldVisitor.js.map +1 -1
  130. package/dist/development/src/schema/mutations/UpdateEntityInputFieldVisitor.cjs +11 -3
  131. package/dist/development/src/schema/mutations/UpdateEntityInputFieldVisitor.cjs.map +1 -1
  132. package/dist/development/src/schema/mutations/UpdateEntityInputFieldVisitor.js +11 -3
  133. package/dist/development/src/schema/mutations/UpdateEntityInputFieldVisitor.js.map +1 -1
  134. package/dist/development/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.cjs +39 -2
  135. package/dist/development/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.cjs.map +1 -1
  136. package/dist/development/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.js +40 -3
  137. package/dist/development/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.js.map +1 -1
  138. package/dist/development/src/schema/utils.cjs +10 -0
  139. package/dist/development/src/schema/utils.cjs.map +1 -1
  140. package/dist/development/src/schema/utils.js +11 -1
  141. package/dist/development/src/schema/utils.js.map +1 -1
  142. package/dist/production/index.cjs +3 -0
  143. package/dist/production/index.cjs.map +1 -1
  144. package/dist/production/index.js +4 -1
  145. package/dist/production/index.js.map +1 -1
  146. package/dist/production/src/ExecutionContainer.cjs +1 -0
  147. package/dist/production/src/ExecutionContainer.cjs.map +1 -1
  148. package/dist/production/src/ExecutionContainer.js +1 -0
  149. package/dist/production/src/ExecutionContainer.js.map +1 -1
  150. package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.cjs +2 -1
  151. package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.cjs.map +1 -1
  152. package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.js +2 -1
  153. package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.js.map +1 -1
  154. package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.cjs +5 -1
  155. package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.cjs.map +1 -1
  156. package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.js +5 -1
  157. package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.js.map +1 -1
  158. package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.cjs +2 -1
  159. package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.cjs.map +1 -1
  160. package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.js +2 -1
  161. package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.js.map +1 -1
  162. package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.cjs +4 -1
  163. package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.cjs.map +1 -1
  164. package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.js +4 -1
  165. package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.js.map +1 -1
  166. package/dist/production/src/input-validation/preValidation/UpdateInputPreValidationProcessor.cjs +24 -3
  167. package/dist/production/src/input-validation/preValidation/UpdateInputPreValidationProcessor.cjs.map +1 -1
  168. package/dist/production/src/input-validation/preValidation/UpdateInputPreValidationProcessor.js +24 -3
  169. package/dist/production/src/input-validation/preValidation/UpdateInputPreValidationProcessor.js.map +1 -1
  170. package/dist/production/src/inputProcessing/UpdateInputVisitor.cjs +52 -2
  171. package/dist/production/src/inputProcessing/UpdateInputVisitor.cjs.map +1 -1
  172. package/dist/production/src/inputProcessing/UpdateInputVisitor.js +52 -2
  173. package/dist/production/src/inputProcessing/UpdateInputVisitor.js.map +1 -1
  174. package/dist/production/src/mapper/ErrorUtils.cjs +10 -0
  175. package/dist/production/src/mapper/ErrorUtils.cjs.map +1 -1
  176. package/dist/production/src/mapper/ErrorUtils.js +10 -0
  177. package/dist/production/src/mapper/ErrorUtils.js.map +1 -1
  178. package/dist/production/src/mapper/Mapper.cjs +37 -1
  179. package/dist/production/src/mapper/Mapper.cjs.map +1 -1
  180. package/dist/production/src/mapper/Mapper.js +38 -2
  181. package/dist/production/src/mapper/Mapper.js.map +1 -1
  182. package/dist/production/src/mapper/MutationProcessorHelper.cjs +12 -0
  183. package/dist/production/src/mapper/MutationProcessorHelper.cjs.map +1 -1
  184. package/dist/production/src/mapper/MutationProcessorHelper.js +13 -1
  185. package/dist/production/src/mapper/MutationProcessorHelper.js.map +1 -1
  186. package/dist/production/src/mapper/Result.cjs +1 -0
  187. package/dist/production/src/mapper/Result.cjs.map +1 -1
  188. package/dist/production/src/mapper/Result.js +1 -0
  189. package/dist/production/src/mapper/Result.js.map +1 -1
  190. package/dist/production/src/mapper/delete/DeleteExecutor.cjs +1 -1
  191. package/dist/production/src/mapper/delete/DeleteExecutor.js +1 -1
  192. package/dist/production/src/mapper/select/Path.cjs +2 -2
  193. package/dist/production/src/mapper/select/Path.cjs.map +1 -1
  194. package/dist/production/src/mapper/select/Path.js +2 -2
  195. package/dist/production/src/mapper/select/Path.js.map +1 -1
  196. package/dist/production/src/mapper/select/handlers/MetaHandler.cjs +1 -1
  197. package/dist/production/src/mapper/select/handlers/MetaHandler.js +1 -1
  198. package/dist/production/src/mapper/select/optimizer/WhereOptimizer.cjs +2 -2
  199. package/dist/production/src/mapper/select/optimizer/WhereOptimizer.cjs.map +1 -1
  200. package/dist/production/src/mapper/select/optimizer/WhereOptimizer.js +1 -1
  201. package/dist/production/src/mapper/select/optimizer/WhereOptimizer.js.map +1 -1
  202. package/dist/production/src/mapper/select/optimizer/WhereReplacer.cjs +3 -3
  203. package/dist/production/src/mapper/select/optimizer/WhereReplacer.cjs.map +1 -1
  204. package/dist/production/src/mapper/select/optimizer/WhereReplacer.js +1 -1
  205. package/dist/production/src/mapper/select/optimizer/WhereReplacer.js.map +1 -1
  206. package/dist/production/src/mapper/update/SqlUpdateInputProcessor.cjs +6 -3
  207. package/dist/production/src/mapper/update/SqlUpdateInputProcessor.cjs.map +1 -1
  208. package/dist/production/src/mapper/update/SqlUpdateInputProcessor.js +7 -4
  209. package/dist/production/src/mapper/update/SqlUpdateInputProcessor.js.map +1 -1
  210. package/dist/production/src/mapper/update/Updater.cjs +1 -1
  211. package/dist/production/src/mapper/update/Updater.js +1 -1
  212. package/dist/production/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.cjs +6 -0
  213. package/dist/production/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.cjs.map +1 -1
  214. package/dist/production/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.js +6 -0
  215. package/dist/production/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.js.map +1 -1
  216. package/dist/production/src/mapper/update/relations/OneHasManyUpdateInputProcessor.cjs +6 -0
  217. package/dist/production/src/mapper/update/relations/OneHasManyUpdateInputProcessor.cjs.map +1 -1
  218. package/dist/production/src/mapper/update/relations/OneHasManyUpdateInputProcessor.js +6 -0
  219. package/dist/production/src/mapper/update/relations/OneHasManyUpdateInputProcessor.js.map +1 -1
  220. package/dist/production/src/mapper/update/relations/SetManyRelationHelper.cjs +123 -0
  221. package/dist/production/src/mapper/update/relations/SetManyRelationHelper.cjs.map +1 -0
  222. package/dist/production/src/mapper/update/relations/SetManyRelationHelper.js +123 -0
  223. package/dist/production/src/mapper/update/relations/SetManyRelationHelper.js.map +1 -0
  224. package/dist/production/src/resolvers/MutationResolver.cjs +4 -1
  225. package/dist/production/src/resolvers/MutationResolver.cjs.map +1 -1
  226. package/dist/production/src/resolvers/MutationResolver.js +4 -1
  227. package/dist/production/src/resolvers/MutationResolver.js.map +1 -1
  228. package/dist/production/src/resolvers/ReadHelpers.cjs +2 -1
  229. package/dist/production/src/resolvers/ReadHelpers.cjs.map +1 -1
  230. package/dist/production/src/resolvers/ReadHelpers.js +2 -1
  231. package/dist/production/src/resolvers/ReadHelpers.js.map +1 -1
  232. package/dist/production/src/schema/CustomTypesProvider.cjs +35 -14
  233. package/dist/production/src/schema/CustomTypesProvider.cjs.map +1 -1
  234. package/dist/production/src/schema/CustomTypesProvider.js +36 -15
  235. package/dist/production/src/schema/CustomTypesProvider.js.map +1 -1
  236. package/dist/production/src/schema/EntityTypeProvider.cjs +8 -5
  237. package/dist/production/src/schema/EntityTypeProvider.cjs.map +1 -1
  238. package/dist/production/src/schema/EntityTypeProvider.js +8 -5
  239. package/dist/production/src/schema/EntityTypeProvider.js.map +1 -1
  240. package/dist/production/src/schema/GraphQlSchemaBuilderFactory.cjs +1 -1
  241. package/dist/production/src/schema/GraphQlSchemaBuilderFactory.js +1 -1
  242. package/dist/production/src/schema/MutationProvider.cjs +4 -0
  243. package/dist/production/src/schema/MutationProvider.cjs.map +1 -1
  244. package/dist/production/src/schema/MutationProvider.js +4 -0
  245. package/dist/production/src/schema/MutationProvider.js.map +1 -1
  246. package/dist/production/src/schema/OrderByTypeProvider.cjs +8 -2
  247. package/dist/production/src/schema/OrderByTypeProvider.cjs.map +1 -1
  248. package/dist/production/src/schema/OrderByTypeProvider.js +9 -3
  249. package/dist/production/src/schema/OrderByTypeProvider.js.map +1 -1
  250. package/dist/production/src/schema/QueryProvider.cjs +3 -0
  251. package/dist/production/src/schema/QueryProvider.cjs.map +1 -1
  252. package/dist/production/src/schema/QueryProvider.js +3 -0
  253. package/dist/production/src/schema/QueryProvider.js.map +1 -1
  254. package/dist/production/src/schema/ValidationQueriesProvider.cjs +2 -0
  255. package/dist/production/src/schema/ValidationQueriesProvider.cjs.map +1 -1
  256. package/dist/production/src/schema/ValidationQueriesProvider.js +2 -0
  257. package/dist/production/src/schema/ValidationQueriesProvider.js.map +1 -1
  258. package/dist/production/src/schema/WhereTypeProvider.cjs +17 -5
  259. package/dist/production/src/schema/WhereTypeProvider.cjs.map +1 -1
  260. package/dist/production/src/schema/WhereTypeProvider.js +18 -6
  261. package/dist/production/src/schema/WhereTypeProvider.js.map +1 -1
  262. package/dist/production/src/schema/calendarDate.cjs +21 -0
  263. package/dist/production/src/schema/calendarDate.cjs.map +1 -0
  264. package/dist/production/src/schema/calendarDate.js +21 -0
  265. package/dist/production/src/schema/calendarDate.js.map +1 -0
  266. package/dist/production/src/schema/mutations/CreateEntityInputFieldVisitor.cjs +11 -3
  267. package/dist/production/src/schema/mutations/CreateEntityInputFieldVisitor.cjs.map +1 -1
  268. package/dist/production/src/schema/mutations/CreateEntityInputFieldVisitor.js +11 -3
  269. package/dist/production/src/schema/mutations/CreateEntityInputFieldVisitor.js.map +1 -1
  270. package/dist/production/src/schema/mutations/UpdateEntityInputFieldVisitor.cjs +11 -3
  271. package/dist/production/src/schema/mutations/UpdateEntityInputFieldVisitor.cjs.map +1 -1
  272. package/dist/production/src/schema/mutations/UpdateEntityInputFieldVisitor.js +11 -3
  273. package/dist/production/src/schema/mutations/UpdateEntityInputFieldVisitor.js.map +1 -1
  274. package/dist/production/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.cjs +39 -2
  275. package/dist/production/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.cjs.map +1 -1
  276. package/dist/production/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.js +40 -3
  277. package/dist/production/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.js.map +1 -1
  278. package/dist/production/src/schema/utils.cjs +10 -0
  279. package/dist/production/src/schema/utils.cjs.map +1 -1
  280. package/dist/production/src/schema/utils.js +11 -1
  281. package/dist/production/src/schema/utils.js.map +1 -1
  282. package/dist/tests/cases/integration/graphQlRequests/query/acl/internalColumnAliases.test.d.ts +2 -0
  283. package/dist/tests/cases/integration/graphQlRequests/query/acl/internalColumnAliases.test.d.ts.map +1 -0
  284. package/dist/tests/cases/integration/graphQlRequests/query/acl/mergedRolePredicate.test.d.ts +2 -0
  285. package/dist/tests/cases/integration/graphQlRequests/query/acl/mergedRolePredicate.test.d.ts.map +1 -0
  286. package/dist/tests/cases/integration/graphQlRequests/update/manyHasManyInverse/set.test.d.ts +2 -0
  287. package/dist/tests/cases/integration/graphQlRequests/update/manyHasManyInverse/set.test.d.ts.map +1 -0
  288. package/dist/tests/cases/integration/graphQlRequests/update/manyHasManyOwning/set.test.d.ts +2 -0
  289. package/dist/tests/cases/integration/graphQlRequests/update/manyHasManyOwning/set.test.d.ts.map +1 -0
  290. package/dist/tests/cases/integration/graphQlRequests/update/oneHasMany/set.test.d.ts +2 -0
  291. package/dist/tests/cases/integration/graphQlRequests/update/oneHasMany/set.test.d.ts.map +1 -0
  292. package/dist/tests/cases/unit/checkViolationError.test.d.ts +2 -0
  293. package/dist/tests/cases/unit/checkViolationError.test.d.ts.map +1 -0
  294. package/dist/tests/cases/unit/dateType.test.d.ts +2 -0
  295. package/dist/tests/cases/unit/dateType.test.d.ts.map +1 -0
  296. package/dist/tests/cases/unit/internalColumnAliases.test.d.ts +2 -0
  297. package/dist/tests/cases/unit/internalColumnAliases.test.d.ts.map +1 -0
  298. package/dist/tests/tsconfig.tsbuildinfo +1 -1
  299. package/dist/types/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.d.ts.map +1 -1
  300. package/dist/types/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.d.ts.map +1 -1
  301. package/dist/types/input-validation/preValidation/UpdateInputPreValidationProcessor.d.ts +6 -0
  302. package/dist/types/input-validation/preValidation/UpdateInputPreValidationProcessor.d.ts.map +1 -1
  303. package/dist/types/inputProcessing/UpdateInputProcessor.d.ts +7 -0
  304. package/dist/types/inputProcessing/UpdateInputProcessor.d.ts.map +1 -1
  305. package/dist/types/inputProcessing/UpdateInputVisitor.d.ts +2 -0
  306. package/dist/types/inputProcessing/UpdateInputVisitor.d.ts.map +1 -1
  307. package/dist/types/mapper/ErrorUtils.d.ts.map +1 -1
  308. package/dist/types/mapper/Mapper.d.ts +5 -0
  309. package/dist/types/mapper/Mapper.d.ts.map +1 -1
  310. package/dist/types/mapper/MutationProcessorHelper.d.ts +3 -0
  311. package/dist/types/mapper/MutationProcessorHelper.d.ts.map +1 -1
  312. package/dist/types/mapper/Result.d.ts +2 -1
  313. package/dist/types/mapper/Result.d.ts.map +1 -1
  314. package/dist/types/mapper/types.d.ts +8 -1
  315. package/dist/types/mapper/types.d.ts.map +1 -1
  316. package/dist/types/mapper/update/SqlUpdateInputProcessor.d.ts.map +1 -1
  317. package/dist/types/mapper/update/relations/ManyHasManyUpdateInputProcessor.d.ts +5 -0
  318. package/dist/types/mapper/update/relations/ManyHasManyUpdateInputProcessor.d.ts.map +1 -1
  319. package/dist/types/mapper/update/relations/OneHasManyUpdateInputProcessor.d.ts +5 -0
  320. package/dist/types/mapper/update/relations/OneHasManyUpdateInputProcessor.d.ts.map +1 -1
  321. package/dist/types/mapper/update/relations/SetManyRelationHelper.d.ts +67 -0
  322. package/dist/types/mapper/update/relations/SetManyRelationHelper.d.ts.map +1 -0
  323. package/dist/types/resolvers/MutationResolver.d.ts.map +1 -1
  324. package/dist/types/schema/CustomTypesProvider.d.ts.map +1 -1
  325. package/dist/types/schema/EntityTypeProvider.d.ts.map +1 -1
  326. package/dist/types/schema/MutationProvider.d.ts.map +1 -1
  327. package/dist/types/schema/OrderByTypeProvider.d.ts.map +1 -1
  328. package/dist/types/schema/QueryProvider.d.ts.map +1 -1
  329. package/dist/types/schema/ValidationQueriesProvider.d.ts.map +1 -1
  330. package/dist/types/schema/WhereTypeProvider.d.ts.map +1 -1
  331. package/dist/types/schema/calendarDate.d.ts +6 -0
  332. package/dist/types/schema/calendarDate.d.ts.map +1 -0
  333. package/dist/types/schema/index.d.ts +1 -0
  334. package/dist/types/schema/index.d.ts.map +1 -1
  335. package/dist/types/schema/mutations/CreateEntityInputFieldVisitor.d.ts.map +1 -1
  336. package/dist/types/schema/mutations/UpdateEntityInputFieldVisitor.d.ts +3 -0
  337. package/dist/types/schema/mutations/UpdateEntityInputFieldVisitor.d.ts.map +1 -1
  338. package/dist/types/schema/mutations/UpdateEntityRelationInputFieldVisitor.d.ts +1 -0
  339. package/dist/types/schema/mutations/UpdateEntityRelationInputFieldVisitor.d.ts.map +1 -1
  340. package/dist/types/schema/utils.d.ts +7 -0
  341. package/dist/types/schema/utils.d.ts.map +1 -1
  342. package/dist/types/tsconfig.tsbuildinfo +1 -1
  343. package/package.json +10 -10
  344. package/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.ts +3 -0
  345. package/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.ts +9 -7
  346. package/src/input-validation/preValidation/UpdateInputPreValidationProcessor.ts +29 -0
  347. package/src/inputProcessing/UpdateInputProcessor.ts +6 -0
  348. package/src/inputProcessing/UpdateInputVisitor.ts +64 -2
  349. package/src/mapper/ErrorUtils.ts +12 -1
  350. package/src/mapper/Mapper.ts +61 -1
  351. package/src/mapper/MutationProcessorHelper.ts +14 -0
  352. package/src/mapper/Result.ts +1 -0
  353. package/src/mapper/select/Path.ts +2 -2
  354. package/src/mapper/select/optimizer/WhereOptimizer.ts +1 -1
  355. package/src/mapper/select/optimizer/WhereReplacer.ts +1 -1
  356. package/src/mapper/types.ts +16 -1
  357. package/src/mapper/update/SqlUpdateInputProcessor.ts +4 -1
  358. package/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.ts +9 -0
  359. package/src/mapper/update/relations/OneHasManyUpdateInputProcessor.ts +9 -0
  360. package/src/mapper/update/relations/SetManyRelationHelper.ts +199 -0
  361. package/src/resolvers/MutationResolver.ts +2 -0
  362. package/src/schema/CustomTypesProvider.ts +40 -15
  363. package/src/schema/EntityTypeProvider.ts +8 -4
  364. package/src/schema/MutationProvider.ts +4 -0
  365. package/src/schema/OrderByTypeProvider.ts +9 -3
  366. package/src/schema/QueryProvider.ts +3 -0
  367. package/src/schema/ValidationQueriesProvider.ts +2 -0
  368. package/src/schema/WhereTypeProvider.ts +18 -6
  369. package/src/schema/calendarDate.ts +26 -0
  370. package/src/schema/index.ts +1 -0
  371. package/src/schema/mutations/CreateEntityInputFieldVisitor.ts +10 -2
  372. package/src/schema/mutations/UpdateEntityInputFieldVisitor.ts +10 -2
  373. package/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.ts +66 -7
  374. package/src/schema/utils.ts +14 -0
  375. package/src/tsconfig.json +2 -1
  376. package/tests/cases/integration/graphQlRequests/query/acl/internalColumnAliases.test.ts +326 -0
  377. package/tests/cases/integration/graphQlRequests/query/acl/mergedRolePredicate.test.ts +124 -0
  378. package/tests/cases/integration/graphQlRequests/update/manyHasManyInverse/set.test.ts +219 -0
  379. package/tests/cases/integration/graphQlRequests/update/manyHasManyOwning/set.test.ts +479 -0
  380. package/tests/cases/integration/graphQlRequests/update/oneHasMany/set.test.ts +948 -0
  381. package/tests/cases/integration/graphQlSchema/graphQlSchemaBuilder.test.ts +102 -1
  382. package/tests/cases/integration/graphQlSchema/schema-acl-allowed.gql +17 -0
  383. package/tests/cases/integration/graphQlSchema/schema-acl-create-only.gql +1 -0
  384. package/tests/cases/integration/graphQlSchema/schema-acl-restricted-create.gql +14 -0
  385. package/tests/cases/integration/graphQlSchema/schema-acl-restricted-delete.gql +11 -0
  386. package/tests/cases/integration/graphQlSchema/schema-acl-restricted-read.gql +254 -0
  387. package/tests/cases/integration/graphQlSchema/schema-acl-restricted-update.gql +1 -0
  388. package/tests/cases/integration/graphQlSchema/schema-acl.gql +1 -0
  389. package/tests/cases/integration/graphQlSchema/schema-aliased-type.gql +1 -0
  390. package/tests/cases/integration/graphQlSchema/schema-array.gql +1 -0
  391. package/tests/cases/integration/graphQlSchema/schema-basic.gql +50 -0
  392. package/tests/cases/integration/graphQlSchema/schema-bug-66.gql +17 -0
  393. package/tests/cases/integration/graphQlSchema/schema-column-types.gql +1 -0
  394. package/tests/cases/integration/graphQlSchema/schema-custom-primary.gql +50 -0
  395. package/tests/cases/integration/graphQlSchema/schema-deprecation.gql +962 -0
  396. package/tests/cases/integration/graphQlSchema/schema-description.gql +992 -0
  397. package/tests/cases/integration/graphQlSchema/schema-has-many-reduction.gql +17 -0
  398. package/tests/cases/integration/graphQlSchema/schema-mixed-root-through.gql +1 -0
  399. package/tests/cases/integration/graphQlSchema/schema-new-builder.gql +50 -0
  400. package/tests/cases/integration/graphQlSchema/schema-no-root-ops.gql +1 -0
  401. package/tests/cases/unit/checkViolationError.test.ts +49 -0
  402. package/tests/cases/unit/dateType.test.ts +46 -0
  403. package/tests/cases/unit/decimalType.test.ts +2 -2
  404. package/tests/cases/unit/internalColumnAliases.test.ts +41 -0
  405. package/tests/cases/unit/mutationSqlError.test.ts +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"WhereOptimizer.cjs","sources":["../../../../../../../packages/engine-content-api/src/mapper/select/optimizer/WhereOptimizer.ts"],"sourcesContent":["import { Input, Model, Writable } from '@contember/schema'\nimport { ConditionOptimizer } from './ConditionOptimizer.js'\nimport { acceptFieldVisitor, getEntity, isRelation } from '@contember/schema-utils'\nimport deepEqual from 'fast-deep-equal'\nimport { optimizeAnd, optimizeNot, optimizeOr } from './helpers.js'\nimport { replaceWhere } from './WhereReplacer.js'\nimport {\n\tFIELD_GUARD_KEY,\n\tisWhere,\n\tMASKED_CELL_KEY,\n\tMaskedCell,\n\tparseMaskedCells,\n\tREAD_GUARD_KEY,\n\tsplitFieldGuard,\n\tsplitReadGuard,\n} from '../../../acl/PredicatesInjector.js'\n\ntype ExtendedRelationContext = {\n\tcontext: Model.AnyRelationContext\n\tcanEliminate: boolean\n\tisLast: boolean\n}\n\nexport interface WhereOptimizationHints {\n\trelationPath?: Model.AnyRelationContext[]\n\tevaluatedPredicates?: Input.OptionalWhere[]\n}\n\ntype OptimizedOperand = Input.OptionalWhere | undefined | boolean\n\nexport type WhereOptimizerOptions = {\n\tdisable?: boolean\n\tmaxCrossOptimizationInput?: number\n}\n\nexport class WhereOptimizer {\n\tprivate static eliminableRelations = new Set<Model.AnyRelationContext['type']>(['oneHasMany', 'oneHasOneInverse', 'oneHasOneOwning'])\n\n\tconstructor(\n\t\tprivate readonly model: Model.Schema,\n\t\tprivate readonly conditionOptimizer: ConditionOptimizer,\n\t\tprivate readonly options?: WhereOptimizerOptions,\n\t) {\n\t}\n\n\tpublic optimize(\n\t\twhere: Input.OptionalWhere,\n\t\tentity: Model.Entity,\n\t\t{ relationPath = [], evaluatedPredicates = [] }: WhereOptimizationHints = {},\n\t): Input.OptionalWhere {\n\t\tif (this.options?.disable) {\n\t\t\treturn where\n\t\t}\n\t\tlet processedRelationPath: ExtendedRelationContext[] = []\n\t\tfor (const i in relationPath) {\n\t\t\tconst el = relationPath[i]\n\t\t\tif (!WhereOptimizer.eliminableRelations.has(el.type)) {\n\t\t\t\tprocessedRelationPath = []\n\t\t\t} else {\n\t\t\t\tprocessedRelationPath.push({ context: el, canEliminate: true, isLast: Number(i) === relationPath.length })\n\t\t\t}\n\t\t}\n\t\tlet result = this.optimizeWhere(where, entity, processedRelationPath)\n\n\t\tif (typeof result === 'boolean') {\n\t\t\treturn { [entity.primary]: { [result ? 'always' : 'never']: true } }\n\t\t}\n\t\tlet changed = false\n\t\tconst facts: Input.OptionalWhere[] = []\n\t\tfor (const evaluated of evaluatedPredicates) {\n\t\t\tconst evaluatedPredicate = this.optimize(evaluated, entity)\n\t\t\tfacts.push(evaluatedPredicate)\n\t\t\tconst newResult = replaceWhere(result, evaluatedPredicate, { [entity.primary]: { always: true } })\n\t\t\tif (newResult !== result) {\n\t\t\t\tresult = newResult\n\t\t\t\tchanged = true\n\t\t\t}\n\t\t}\n\t\tif (changed) {\n\t\t\tresult = this.optimize(result, entity)\n\t\t}\n\t\treturn this.simplifyGuardsWithFacts(result, facts, entity, processedRelationPath)\n\t}\n\n\t/**\n\t * Guards may only be simplified with facts that hold on every row the query can select: the evaluated\n\t * predicates and the guard-free operands of the top-level AND. Deeper, a sibling can be NULL under a `not`, and\n\t * assuming it TRUE inside a guard would unmask a cell. A guarded operand can never equal a part of a guard, so\n\t * only guard-free operands serve as facts, capped like the cross optimization so that a long AND stays linear.\n\t */\n\tprivate simplifyGuardsWithFacts(\n\t\twhere: Input.OptionalWhere,\n\t\tevaluatedFacts: readonly Input.OptionalWhere[],\n\t\tentity: Model.Entity,\n\t\trelationPath: ExtendedRelationContext[],\n\t): Input.OptionalWhere {\n\t\tconst facts = evaluatedFacts.filter(isUsableFact)\n\t\tconst simplified = facts.length > 0 ? this.simplifyGuards(where, facts, entity, relationPath) : where\n\t\tconst operands = simplified.and\n\t\tif (!Array.isArray(operands)) {\n\t\t\treturn simplified\n\t\t}\n\t\tconst topLevel: readonly Input.OptionalWhere[] = operands\n\t\tconst operandFacts = topLevel.filter(isUsableFact).slice(0, this.options?.maxCrossOptimizationInput ?? 50)\n\t\tif (operandFacts.length === 0) {\n\t\t\treturn simplified\n\t\t}\n\t\tconst simplifiedOperands = topLevel.map(operand => hasGuards(operand) ? this.simplifyGuards(operand, operandFacts, entity, relationPath) : operand)\n\t\treturn simplifiedOperands.some((it, index) => it !== topLevel[index]) ? { ...simplified, and: simplifiedOperands } : simplified\n\t}\n\n\t/**\n\t * Whether `facts`, wheres TRUE on the row, imply `guard`. A guard they imply holds on every row the query\n\t * can select, so the hop it protects may join the plain table instead of a guarded source.\n\t */\n\tpublic isImpliedByFacts(guard: Input.OptionalWhere, entity: Model.Entity, facts: readonly Input.OptionalWhere[]): boolean {\n\t\tconst usableFacts = facts.filter(isUsableFact).map(it => this.optimize(it, entity))\n\t\treturn usableFacts.length > 0 && this.isImpliedByOptimizedFacts(guard, entity, usableFacts)\n\t}\n\n\tprivate isImpliedByOptimizedFacts(guard: Input.OptionalWhere, entity: Model.Entity, facts: readonly Input.OptionalWhere[]): boolean {\n\t\tconst optimizedGuard = this.optimizeWhere(guard, entity, [])\n\t\tif (typeof optimizedGuard === 'boolean') {\n\t\t\treturn optimizedGuard\n\t\t}\n\t\treturn this.optimizeWhere(this.replaceFacts(optimizedGuard, facts, entity), entity, []) === true\n\t}\n\n\t/**\n\t * Facts about the row a to-one relation joins. A fact TRUE on a row holds on the (possibly null-extended) row its\n\t * to-one relation joins, so each operand of its top-level AND over that relation is a fact there. A to-many\n\t * relation joins many rows, which share no fact.\n\t */\n\tpublic factsThroughRelation(facts: readonly Input.OptionalWhere[], entity: Model.Entity, relationName: string): Input.OptionalWhere[] {\n\t\tif (this.getToOneTarget(entity, relationName) === undefined) {\n\t\t\treturn []\n\t\t}\n\t\tconst relationOperands = (fact: Input.OptionalWhere): Input.OptionalWhere[] => {\n\t\t\tconst value = fact[relationName]\n\t\t\tconst operands = Array.isArray(fact.and) ? fact.and.filter(isWhere).flatMap(relationOperands) : []\n\t\t\treturn isWhere(value) ? [value, ...operands] : operands\n\t\t}\n\t\treturn facts.flatMap(relationOperands)\n\t}\n\n\tprivate getToOneTarget(entity: Model.Entity, fieldName: string): Model.Entity | undefined {\n\t\tconst field = entity.fields[fieldName]\n\t\tif (field === undefined || !isRelation(field)) {\n\t\t\treturn undefined\n\t\t}\n\t\tconst isToOne = field.type === Model.RelationType.ManyHasOne || field.type === Model.RelationType.OneHasOne\n\t\treturn isToOne ? getEntity(this.model, field.target) : undefined\n\t}\n\n\t/** Replaces every part of `where` equal to a fact with TRUE, following the facts into to-one relations. */\n\tprivate replaceFacts(where: Input.OptionalWhere, facts: readonly Input.OptionalWhere[], entity: Model.Entity): Input.OptionalWhere {\n\t\tif (facts.some(fact => deepEqual(where, fact))) {\n\t\t\treturn { [entity.primary]: { always: true } }\n\t\t}\n\t\tlet result: Writable<Input.OptionalWhere> = where\n\t\tconst write = (key: string, value: Input.OptionalWhere[string]) => {\n\t\t\tif (result === where) {\n\t\t\t\tresult = { ...where }\n\t\t\t}\n\t\t\tresult[key] = value\n\t\t}\n\t\tfor (const key in where) {\n\t\t\tconst value = where[key]\n\t\t\tif ((key === 'and' || key === 'or') && Array.isArray(value)) {\n\t\t\t\tconst operands: readonly Input.OptionalWhere[] = value\n\t\t\t\tconst replaced = operands.map(it => this.replaceFacts(it, facts, entity))\n\t\t\t\tif (replaced.some((it, index) => it !== operands[index])) {\n\t\t\t\t\twrite(key, replaced)\n\t\t\t\t}\n\t\t\t} else if (key === 'not' && isWhere(value)) {\n\t\t\t\tconst replaced = this.replaceFacts(value, facts, entity)\n\t\t\t\tif (replaced !== value) {\n\t\t\t\t\twrite(key, replaced)\n\t\t\t\t}\n\t\t\t} else if (isWhere(value)) {\n\t\t\t\tconst target = this.getToOneTarget(entity, key)\n\t\t\t\tconst targetFacts = target === undefined ? [] : this.factsThroughRelation(facts, entity, key)\n\t\t\t\tconst replaced = target === undefined || targetFacts.length === 0 ? value : this.replaceFacts(value, targetFacts, target)\n\t\t\t\tif (replaced !== value) {\n\t\t\t\t\twrite(key, replaced)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn result\n\t}\n\n\tprivate optimizeWhere(where: Input.OptionalWhere, entity: Model.Entity, relationPath: ExtendedRelationContext[]): Input.OptionalWhere | boolean {\n\t\tconst { guard, where: rest } = splitReadGuard(where ?? {})\n\t\tconst optimizedRest = this.optimizeWhereOperands(rest, entity, relationPath)\n\t\tif (Object.keys(guard).length === 0 || typeof optimizedRest === 'boolean') {\n\t\t\t// A hop without any remaining condition is a no-op whatever its guard (an empty relation filter).\n\t\t\treturn optimizedRest\n\t\t}\n\t\t// The guard is a where over the same target rows, but it is compiled into the hop's table source\n\t\t// rather than its condition, so it is optimized on its own and kept out of the AND above.\n\t\tconst optimizedGuard = this.optimizeWhereOperands(guard, entity, relationPath)\n\t\tif (optimizedGuard === true) {\n\t\t\treturn optimizedRest\n\t\t}\n\t\tconst guardWhere = optimizedGuard === false ? { [entity.primary]: { never: true } } : optimizedGuard\n\t\treturn { ...optimizedRest, [READ_GUARD_KEY]: guardWhere }\n\t}\n\n\tprivate optimizeWhereOperands(\n\t\twhere: Input.OptionalWhere,\n\t\tentity: Model.Entity,\n\t\trelationPath: ExtendedRelationContext[],\n\t): Input.OptionalWhere | boolean {\n\t\tconst operands: OptimizedOperand[] = []\n\n\t\tfor (const key in where) {\n\t\t\tconst value = where[key]\n\t\t\tlet operand: OptimizedOperand\n\t\t\tif (value === undefined || value === null) {\n\t\t\t\tcontinue\n\t\t\t} else if (key === 'and') {\n\t\t\t\tconst innerOperands: (Input.OptionalWhere | boolean)[] = []\n\t\t\t\tfor (const innerValue of value as readonly Input.OptionalWhere[]) {\n\t\t\t\t\tconst innerOperand = this.optimizeWhere(innerValue, entity, relationPath)\n\t\t\t\t\tif (innerOperand === false) {\n\t\t\t\t\t\treturn false\n\t\t\t\t\t}\n\t\t\t\t\tinnerOperands.push(innerOperand)\n\t\t\t\t}\n\t\t\t\toperand = this.optimizeAnd(innerOperands, entity, relationPath)\n\t\t\t} else if (key === 'or') {\n\t\t\t\tconst innerOperands: (Input.OptionalWhere | boolean)[] = []\n\t\t\t\tfor (const innerValue of value as readonly Input.OptionalWhere[]) {\n\t\t\t\t\tconst innerOperand = this.optimizeWhere(innerValue, entity, relationPath)\n\t\t\t\t\tif (innerOperand === true) {\n\t\t\t\t\t\toperand = true\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tinnerOperands.push(innerOperand)\n\t\t\t\t}\n\t\t\t\tif (operand !== true) {\n\t\t\t\t\toperand = this.optimizeOr(innerOperands, entity, relationPath)\n\t\t\t\t}\n\t\t\t} else if (key === 'not') {\n\t\t\t\toperand = optimizeNot(this.optimizeWhere(value as Input.OptionalWhere, entity, relationPath))\n\t\t\t} else if (key === MASKED_CELL_KEY) {\n\t\t\t\toperand = this.optimizeAnd(parseMaskedCells(value).map(cell => this.optimizeMaskedCell(cell, entity, relationPath)), entity, relationPath)\n\t\t\t} else {\n\t\t\t\toperand = this.resolveFieldValue(entity, key, value, relationPath)\n\t\t\t}\n\n\t\t\tif (operand === false) {\n\t\t\t\treturn false\n\t\t\t} else if (operand !== undefined) {\n\t\t\t\toperands.push(operand)\n\t\t\t}\n\t\t}\n\t\treturn this.optimizeAnd(operands, entity, relationPath)\n\t}\n\n\t/**\n\t * Replaces `facts`, known to hold on the row, inside the read guards of `where` (field guards of its relations\n\t * and masked-cell guards; a guard reads the same row), and follows them into its to-one relation hops. Only the\n\t * guards are re-optimized, so the user's condition keeps the shape it was optimized into.\n\t */\n\tprivate simplifyGuards(\n\t\twhere: Input.OptionalWhere,\n\t\tfacts: readonly Input.OptionalWhere[],\n\t\tentity: Model.Entity,\n\t\trelationPath: ExtendedRelationContext[],\n\t): Input.OptionalWhere {\n\t\tconst simplifyGuard = (guard: Input.OptionalWhere): Input.OptionalWhere | boolean | undefined => {\n\t\t\tconst replaced = this.replaceFacts(guard, facts, entity)\n\t\t\treturn replaced === guard ? undefined : this.optimizeWhere(replaced, entity, relationPath)\n\t\t}\n\t\tconst asWhere = (guard: Input.OptionalWhere | boolean): Input.OptionalWhere =>\n\t\t\ttypeof guard === 'boolean' ? { [entity.primary]: { [guard ? 'always' : 'never']: true } } : guard\n\t\tlet result: Writable<Input.OptionalWhere> = where\n\t\tconst write = (key: string, value: Input.OptionalWhere[string]) => {\n\t\t\tif (result === where) {\n\t\t\t\tresult = { ...where }\n\t\t\t}\n\t\t\tresult[key] = value\n\t\t}\n\t\tconst readableCells: Input.OptionalWhere[] = []\n\t\tfor (const key in where) {\n\t\t\tconst value = where[key]\n\t\t\tif ((key === 'and' || key === 'or') && Array.isArray(value)) {\n\t\t\t\tconst operands: readonly Input.OptionalWhere[] = value\n\t\t\t\tconst simplified = operands.map(it => this.simplifyGuards(it, facts, entity, relationPath))\n\t\t\t\tif (simplified.some((it, index) => it !== operands[index])) {\n\t\t\t\t\twrite(key, simplified)\n\t\t\t\t}\n\t\t\t} else if (key === 'not' && isWhere(value)) {\n\t\t\t\tconst simplified = this.simplifyGuards(value, facts, entity, relationPath)\n\t\t\t\tif (simplified !== value) {\n\t\t\t\t\twrite(key, simplified)\n\t\t\t\t}\n\t\t\t} else if (key === MASKED_CELL_KEY) {\n\t\t\t\tconst cells = parseMaskedCells(value).map(cell => ({ cell, guard: simplifyGuard(cell.guard) }))\n\t\t\t\tif (cells.every(it => it.guard === undefined)) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\t// A cell whose guard always holds reads its plain value.\n\t\t\t\treadableCells.push(...cells.filter(it => it.guard === true).map(it => it.cell.where))\n\t\t\t\twrite(\n\t\t\t\t\tkey,\n\t\t\t\t\tcells\n\t\t\t\t\t\t.filter(it => it.guard !== true)\n\t\t\t\t\t\t.map(({ cell, guard }) => guard === undefined ? cell : { guard: asWhere(guard), where: cell.where }),\n\t\t\t\t)\n\t\t\t} else if (isWhere(value)) {\n\t\t\t\tconst { fieldGuard, where: relationWhere } = splitFieldGuard(value)\n\t\t\t\tconst guard = fieldGuard === undefined ? undefined : simplifyGuard(fieldGuard)\n\t\t\t\tconst hopWhere = this.simplifyHopGuards(relationWhere, facts, entity, key)\n\t\t\t\tif (guard === true) {\n\t\t\t\t\twrite(key, hopWhere)\n\t\t\t\t} else if (guard !== undefined) {\n\t\t\t\t\twrite(key, { ...hopWhere, [FIELD_GUARD_KEY]: asWhere(guard) })\n\t\t\t\t} else if (hopWhere !== relationWhere) {\n\t\t\t\t\twrite(key, fieldGuard === undefined ? hopWhere : { ...hopWhere, [FIELD_GUARD_KEY]: fieldGuard })\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (readableCells.length === 0) {\n\t\t\treturn result\n\t\t}\n\t\tconst { [MASKED_CELL_KEY]: maskedCells, and, ...rest } = result\n\t\tconst operands = [...(Array.isArray(and) ? and : []), ...readableCells]\n\t\tconst masked = Array.isArray(maskedCells) && maskedCells.length > 0 ? { [MASKED_CELL_KEY]: maskedCells } : {}\n\t\tif (operands.length === 1 && Object.keys(rest).length === 0 && Object.keys(masked).length === 0) {\n\t\t\treturn operands[0]\n\t\t}\n\t\treturn { ...rest, and: operands, ...masked }\n\t}\n\n\t/**\n\t * Follows the facts into a to-one relation hop. Its read guard is dropped when the facts imply it, so the hop\n\t * shares the plain join of an ACL predicate through the same relation instead of joining a guarded source.\n\t */\n\tprivate simplifyHopGuards(\n\t\twhere: Input.OptionalWhere,\n\t\tfacts: readonly Input.OptionalWhere[],\n\t\tentity: Model.Entity,\n\t\trelationName: string,\n\t): Input.OptionalWhere {\n\t\tconst target = this.getToOneTarget(entity, relationName)\n\t\tconst targetFacts = target === undefined ? [] : this.factsThroughRelation(facts, entity, relationName)\n\t\tif (target === undefined || targetFacts.length === 0) {\n\t\t\treturn where\n\t\t}\n\t\tconst { [READ_GUARD_KEY]: readGuard, ...rest } = where\n\t\tconst simplified = this.simplifyGuards(rest, targetFacts, target, [])\n\t\tconst keepsGuard = isWhere(readGuard) && !this.isImpliedByOptimizedFacts(readGuard, target, targetFacts)\n\t\tif (keepsGuard) {\n\t\t\treturn simplified === rest ? where : { ...simplified, [READ_GUARD_KEY]: readGuard }\n\t\t}\n\t\treturn readGuard === undefined && simplified === rest ? where : simplified\n\t}\n\n\t/** Guard and condition are optimized apart: the masked form depends on the condition alone. */\n\tprivate optimizeMaskedCell(masked: MaskedCell, entity: Model.Entity, relationPath: ExtendedRelationContext[]): Input.OptionalWhere | boolean {\n\t\tconst where = this.optimizeWhere(masked.where, entity, relationPath)\n\t\tconst guard = this.optimizeWhere(masked.guard, entity, relationPath)\n\t\tif (typeof where === 'boolean' || guard === true || (typeof guard !== 'boolean' && Object.keys(guard).length === 0)) {\n\t\t\treturn where\n\t\t}\n\t\treturn { [MASKED_CELL_KEY]: [{ guard: guard === false ? { [entity.primary]: { never: true } } : guard, where }] }\n\t}\n\n\tprivate optimizeOr(\n\t\toperands: readonly OptimizedOperand[],\n\t\tentity: Model.Entity,\n\t\trelationPath: ExtendedRelationContext[],\n\t): Input.OptionalWhere | boolean {\n\t\tconst optimized = optimizeOr(operands)\n\t\tif (typeof optimized === 'boolean' || !Array.isArray(optimized.or)) {\n\t\t\treturn optimized\n\t\t}\n\t\tconst result = this.crossOptimize(optimized.or, entity, { never: true }, relationPath)\n\t\tif (result === optimized.or) {\n\t\t\treturn optimized\n\t\t}\n\t\treturn optimizeOr(result)\n\t}\n\n\tprivate optimizeAnd(\n\t\toperands: readonly OptimizedOperand[],\n\t\tentity: Model.Entity,\n\t\trelationPath: ExtendedRelationContext[],\n\t): Input.OptionalWhere | boolean {\n\t\tconst optimized = optimizeAnd(operands)\n\t\tif (typeof optimized === 'boolean' || !Array.isArray(optimized.and)) {\n\t\t\treturn optimized\n\t\t}\n\t\tconst result = this.crossOptimize(optimized.and, entity, { always: true }, relationPath)\n\t\tif (result === optimized.and) {\n\t\t\treturn optimized\n\t\t}\n\t\treturn optimizeAnd(result)\n\t}\n\n\tprivate crossOptimize(\n\t\toperands: Input.OptionalWhere[],\n\t\tentity: Model.Entity,\n\t\treplacement: Input.Condition,\n\t\trelationPath: ExtendedRelationContext[],\n\t): (Input.OptionalWhere | boolean)[] {\n\t\tlet result: (Input.OptionalWhere | boolean)[] = operands\n\t\tlet copied = false\n\t\tconst count = Math.min(result.length, this.options?.maxCrossOptimizationInput ?? 50)\n\t\tfor (let i = 0; i < count; i++) {\n\t\t\tfor (let j = 0; j < count; j++) {\n\t\t\t\tconst a = result[j]\n\t\t\t\tconst b = result[i]\n\t\t\t\tif (i !== j && typeof a !== 'boolean' && typeof b !== 'boolean') {\n\t\t\t\t\tconst elResult = replaceWhere(a, b, { [entity.primary]: replacement }, {\n\t\t\t\t\t\treplaceSubOperands: true,\n\t\t\t\t\t})\n\t\t\t\t\tif (elResult !== a) {\n\t\t\t\t\t\tif (!copied) {\n\t\t\t\t\t\t\tresult = [...result]\n\t\t\t\t\t\t\tcopied = true\n\t\t\t\t\t\t}\n\t\t\t\t\t\tresult[j] = this.optimizeWhere(elResult, entity, relationPath)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn result\n\t}\n\n\tprivate resolveFieldValue(entity: Model.Entity, key: string, value: Input.OptionalWhere[string], relationPath: ExtendedRelationContext[]) {\n\t\treturn acceptFieldVisitor<Input.OptionalWhere | boolean>(this.model, entity, key, {\n\t\t\tvisitColumn: () => {\n\t\t\t\tconst optimizedCondition = this.conditionOptimizer.optimize(value as Input.Condition)\n\n\t\t\t\tif (typeof optimizedCondition === 'boolean') {\n\t\t\t\t\treturn optimizedCondition\n\t\t\t\t}\n\n\t\t\t\treturn { [key]: optimizedCondition }\n\t\t\t},\n\t\t\tvisitRelation: context => {\n\t\t\t\t// The field guard is a where over this (source) entity, so it is optimized here, not with the target.\n\t\t\t\tconst { fieldGuard: rawFieldGuard, where: relationWhere } = splitFieldGuard(value as Input.OptionalWhere)\n\t\t\t\tconst fieldGuard = rawFieldGuard === undefined ? true : this.optimizeWhere(rawFieldGuard, entity, relationPath)\n\t\t\t\tlet where: Input.OptionalWhere = relationWhere\n\t\t\t\tconst newRelationPath: ExtendedRelationContext[] = [...relationPath]\n\t\t\t\tconst length = relationPath.length\n\t\t\t\tif (length > 0 && relationPath[length - 1].context.targetRelation?.name === context.relation.name) {\n\t\t\t\t\tconst item = newRelationPath.pop()\n\t\t\t\t\tconst type = item!.context.type\n\t\t\t\t\tif (item?.canEliminate && (type === 'oneHasMany' || type === 'oneHasOneOwning' || type === 'oneHasOneInverse')) {\n\t\t\t\t\t\twhere = replaceWhere(where, { [context.targetEntity.primary]: { isNull: true } }, { [context.targetEntity.primary]: { never: true } })\n\t\t\t\t\t\twhere = replaceWhere(where, { [context.targetEntity.primary]: { isNull: false } }, { [context.targetEntity.primary]: { always: true } })\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// first level relation - we are sure root exists\n\t\t\t\t\tconst canEliminate = length === 0 || relationPath[length - 1].isLast\n\t\t\t\t\tnewRelationPath.push({ context, isLast: false, canEliminate })\n\t\t\t\t}\n\t\t\t\tconst optimizedWhere = this.optimizeWhere(where, context.targetEntity, newRelationPath)\n\n\t\t\t\tif (typeof optimizedWhere === 'boolean') {\n\t\t\t\t\treturn optimizedWhere\n\t\t\t\t}\n\t\t\t\tif (fieldGuard === true || (fieldGuard !== false && Object.keys(fieldGuard).length === 0)) {\n\t\t\t\t\treturn { [key]: optimizedWhere }\n\t\t\t\t}\n\t\t\t\tconst fieldGuardWhere = fieldGuard === false ? { [entity.primary]: { never: true } } : fieldGuard\n\t\t\t\treturn { [key]: { ...optimizedWhere, [FIELD_GUARD_KEY]: fieldGuardWhere } }\n\t\t\t},\n\t\t})\n\t}\n}\n\nconst guardKeys = new Set<string>([READ_GUARD_KEY, FIELD_GUARD_KEY, MASKED_CELL_KEY])\n\nconst hasGuards = (value: unknown): boolean => {\n\tif (Array.isArray(value)) {\n\t\treturn value.some(hasGuards)\n\t}\n\tif (value === null || typeof value !== 'object') {\n\t\treturn false\n\t}\n\treturn Object.entries(value).some(([key, item]) => guardKeys.has(key) || hasGuards(item))\n}\n\n/** A guarded where tells nothing about the plain rows a guard reads (an unreadable row reads as absent there). */\nconst isUsableFact = (fact: Input.OptionalWhere): boolean => Object.keys(fact).length > 0 && !hasGuards(fact)\n"],"names":["_WhereOptimizer","replaceWhere","isWhere","isRelation","Model","getEntity","splitReadGuard","READ_GUARD_KEY","optimizeNot","MASKED_CELL_KEY","parseMaskedCells","operands","splitFieldGuard","FIELD_GUARD_KEY","optimizeOr","optimizeAnd","acceptFieldVisitor"],"mappings":";;;;;;;;;;;AAmCO,MAAM,kBAAN,MAAMA,iBAAe;AAAA,EAG3B,YACkB,OACA,oBACA,SAChB;AAHgB,SAAA,QAAA;AACA,SAAA,qBAAA;AACA,SAAA,UAAA;AAAA,EAElB;AAAA,EAEO,SACN,OACA,QACA,EAAE,eAAe,CAAA,GAAI,sBAAsB,GAAC,IAA8B,IACpD;AACtB,QAAI,KAAK,SAAS,SAAS;AAC1B,aAAO;AAAA,IACR;AACA,QAAI,wBAAmD,CAAA;AACvD,eAAW,KAAK,cAAc;AAC7B,YAAM,KAAK,aAAa,CAAC;AACzB,UAAI,CAACA,iBAAe,oBAAoB,IAAI,GAAG,IAAI,GAAG;AACrD,gCAAwB,CAAA;AAAA,MACzB,OAAO;AACN,8BAAsB,KAAK,EAAE,SAAS,IAAI,cAAc,MAAM,QAAQ,OAAO,CAAC,MAAM,aAAa,OAAA,CAAQ;AAAA,MAC1G;AAAA,IACD;AACA,QAAI,SAAS,KAAK,cAAc,OAAO,QAAQ,qBAAqB;AAEpE,QAAI,OAAO,WAAW,WAAW;AAChC,aAAO,EAAE,CAAC,OAAO,OAAO,GAAG,EAAE,CAAC,SAAS,WAAW,OAAO,GAAG,OAAK;AAAA,IAClE;AACA,QAAI,UAA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A,eAAe,CAAC;AAEpF,MAAM,YAAY,CAAC,UAA4B;AAC9C,MAAI,MAAM,QAAQ,KAAK,GAAG;AACzB,WAAO,MAAM,KAAK,SAAS;AAAA,EAC5B;AACA,MAAI,UAAU,QAAQ,OAAO,UAAU,UAAU;AAChD,WAAO;AAAA,EACR;AACA,SAAO,OAAO,QAAQ,KAAK,EAAE,KAAK,CAAC,CAAC,KAAK,IAAI,MAAM,UAAU,IAAI,GAAG,KAAK,UAAU,IAAI,CAAC;AACzF;AAGA,MAAM,eAAe,CAAC,SAAuC,OAAO,KAAK,IAAI,EAAE,SAAS,KAAK,CAAC,UAAU,IAAI;;"}
1
+ {"version":3,"file":"WhereOptimizer.cjs","sources":["../../../../../../../packages/engine-content-api/src/mapper/select/optimizer/WhereOptimizer.ts"],"sourcesContent":["import { Input, Model, Writable } from '@contember/schema'\nimport { ConditionOptimizer } from './ConditionOptimizer.js'\nimport { acceptFieldVisitor, getEntity, isRelation } from '@contember/schema-utils'\nimport { deepEqual } from '@contember/utilities'\nimport { optimizeAnd, optimizeNot, optimizeOr } from './helpers.js'\nimport { replaceWhere } from './WhereReplacer.js'\nimport {\n\tFIELD_GUARD_KEY,\n\tisWhere,\n\tMASKED_CELL_KEY,\n\tMaskedCell,\n\tparseMaskedCells,\n\tREAD_GUARD_KEY,\n\tsplitFieldGuard,\n\tsplitReadGuard,\n} from '../../../acl/PredicatesInjector.js'\n\ntype ExtendedRelationContext = {\n\tcontext: Model.AnyRelationContext\n\tcanEliminate: boolean\n\tisLast: boolean\n}\n\nexport interface WhereOptimizationHints {\n\trelationPath?: Model.AnyRelationContext[]\n\tevaluatedPredicates?: Input.OptionalWhere[]\n}\n\ntype OptimizedOperand = Input.OptionalWhere | undefined | boolean\n\nexport type WhereOptimizerOptions = {\n\tdisable?: boolean\n\tmaxCrossOptimizationInput?: number\n}\n\nexport class WhereOptimizer {\n\tprivate static eliminableRelations = new Set<Model.AnyRelationContext['type']>(['oneHasMany', 'oneHasOneInverse', 'oneHasOneOwning'])\n\n\tconstructor(\n\t\tprivate readonly model: Model.Schema,\n\t\tprivate readonly conditionOptimizer: ConditionOptimizer,\n\t\tprivate readonly options?: WhereOptimizerOptions,\n\t) {\n\t}\n\n\tpublic optimize(\n\t\twhere: Input.OptionalWhere,\n\t\tentity: Model.Entity,\n\t\t{ relationPath = [], evaluatedPredicates = [] }: WhereOptimizationHints = {},\n\t): Input.OptionalWhere {\n\t\tif (this.options?.disable) {\n\t\t\treturn where\n\t\t}\n\t\tlet processedRelationPath: ExtendedRelationContext[] = []\n\t\tfor (const i in relationPath) {\n\t\t\tconst el = relationPath[i]\n\t\t\tif (!WhereOptimizer.eliminableRelations.has(el.type)) {\n\t\t\t\tprocessedRelationPath = []\n\t\t\t} else {\n\t\t\t\tprocessedRelationPath.push({ context: el, canEliminate: true, isLast: Number(i) === relationPath.length })\n\t\t\t}\n\t\t}\n\t\tlet result = this.optimizeWhere(where, entity, processedRelationPath)\n\n\t\tif (typeof result === 'boolean') {\n\t\t\treturn { [entity.primary]: { [result ? 'always' : 'never']: true } }\n\t\t}\n\t\tlet changed = false\n\t\tconst facts: Input.OptionalWhere[] = []\n\t\tfor (const evaluated of evaluatedPredicates) {\n\t\t\tconst evaluatedPredicate = this.optimize(evaluated, entity)\n\t\t\tfacts.push(evaluatedPredicate)\n\t\t\tconst newResult = replaceWhere(result, evaluatedPredicate, { [entity.primary]: { always: true } })\n\t\t\tif (newResult !== result) {\n\t\t\t\tresult = newResult\n\t\t\t\tchanged = true\n\t\t\t}\n\t\t}\n\t\tif (changed) {\n\t\t\tresult = this.optimize(result, entity)\n\t\t}\n\t\treturn this.simplifyGuardsWithFacts(result, facts, entity, processedRelationPath)\n\t}\n\n\t/**\n\t * Guards may only be simplified with facts that hold on every row the query can select: the evaluated\n\t * predicates and the guard-free operands of the top-level AND. Deeper, a sibling can be NULL under a `not`, and\n\t * assuming it TRUE inside a guard would unmask a cell. A guarded operand can never equal a part of a guard, so\n\t * only guard-free operands serve as facts, capped like the cross optimization so that a long AND stays linear.\n\t */\n\tprivate simplifyGuardsWithFacts(\n\t\twhere: Input.OptionalWhere,\n\t\tevaluatedFacts: readonly Input.OptionalWhere[],\n\t\tentity: Model.Entity,\n\t\trelationPath: ExtendedRelationContext[],\n\t): Input.OptionalWhere {\n\t\tconst facts = evaluatedFacts.filter(isUsableFact)\n\t\tconst simplified = facts.length > 0 ? this.simplifyGuards(where, facts, entity, relationPath) : where\n\t\tconst operands = simplified.and\n\t\tif (!Array.isArray(operands)) {\n\t\t\treturn simplified\n\t\t}\n\t\tconst topLevel: readonly Input.OptionalWhere[] = operands\n\t\tconst operandFacts = topLevel.filter(isUsableFact).slice(0, this.options?.maxCrossOptimizationInput ?? 50)\n\t\tif (operandFacts.length === 0) {\n\t\t\treturn simplified\n\t\t}\n\t\tconst simplifiedOperands = topLevel.map(operand => hasGuards(operand) ? this.simplifyGuards(operand, operandFacts, entity, relationPath) : operand)\n\t\treturn simplifiedOperands.some((it, index) => it !== topLevel[index]) ? { ...simplified, and: simplifiedOperands } : simplified\n\t}\n\n\t/**\n\t * Whether `facts`, wheres TRUE on the row, imply `guard`. A guard they imply holds on every row the query\n\t * can select, so the hop it protects may join the plain table instead of a guarded source.\n\t */\n\tpublic isImpliedByFacts(guard: Input.OptionalWhere, entity: Model.Entity, facts: readonly Input.OptionalWhere[]): boolean {\n\t\tconst usableFacts = facts.filter(isUsableFact).map(it => this.optimize(it, entity))\n\t\treturn usableFacts.length > 0 && this.isImpliedByOptimizedFacts(guard, entity, usableFacts)\n\t}\n\n\tprivate isImpliedByOptimizedFacts(guard: Input.OptionalWhere, entity: Model.Entity, facts: readonly Input.OptionalWhere[]): boolean {\n\t\tconst optimizedGuard = this.optimizeWhere(guard, entity, [])\n\t\tif (typeof optimizedGuard === 'boolean') {\n\t\t\treturn optimizedGuard\n\t\t}\n\t\treturn this.optimizeWhere(this.replaceFacts(optimizedGuard, facts, entity), entity, []) === true\n\t}\n\n\t/**\n\t * Facts about the row a to-one relation joins. A fact TRUE on a row holds on the (possibly null-extended) row its\n\t * to-one relation joins, so each operand of its top-level AND over that relation is a fact there. A to-many\n\t * relation joins many rows, which share no fact.\n\t */\n\tpublic factsThroughRelation(facts: readonly Input.OptionalWhere[], entity: Model.Entity, relationName: string): Input.OptionalWhere[] {\n\t\tif (this.getToOneTarget(entity, relationName) === undefined) {\n\t\t\treturn []\n\t\t}\n\t\tconst relationOperands = (fact: Input.OptionalWhere): Input.OptionalWhere[] => {\n\t\t\tconst value = fact[relationName]\n\t\t\tconst operands = Array.isArray(fact.and) ? fact.and.filter(isWhere).flatMap(relationOperands) : []\n\t\t\treturn isWhere(value) ? [value, ...operands] : operands\n\t\t}\n\t\treturn facts.flatMap(relationOperands)\n\t}\n\n\tprivate getToOneTarget(entity: Model.Entity, fieldName: string): Model.Entity | undefined {\n\t\tconst field = entity.fields[fieldName]\n\t\tif (field === undefined || !isRelation(field)) {\n\t\t\treturn undefined\n\t\t}\n\t\tconst isToOne = field.type === Model.RelationType.ManyHasOne || field.type === Model.RelationType.OneHasOne\n\t\treturn isToOne ? getEntity(this.model, field.target) : undefined\n\t}\n\n\t/** Replaces every part of `where` equal to a fact with TRUE, following the facts into to-one relations. */\n\tprivate replaceFacts(where: Input.OptionalWhere, facts: readonly Input.OptionalWhere[], entity: Model.Entity): Input.OptionalWhere {\n\t\tif (facts.some(fact => deepEqual(where, fact))) {\n\t\t\treturn { [entity.primary]: { always: true } }\n\t\t}\n\t\tlet result: Writable<Input.OptionalWhere> = where\n\t\tconst write = (key: string, value: Input.OptionalWhere[string]) => {\n\t\t\tif (result === where) {\n\t\t\t\tresult = { ...where }\n\t\t\t}\n\t\t\tresult[key] = value\n\t\t}\n\t\tfor (const key in where) {\n\t\t\tconst value = where[key]\n\t\t\tif ((key === 'and' || key === 'or') && Array.isArray(value)) {\n\t\t\t\tconst operands: readonly Input.OptionalWhere[] = value\n\t\t\t\tconst replaced = operands.map(it => this.replaceFacts(it, facts, entity))\n\t\t\t\tif (replaced.some((it, index) => it !== operands[index])) {\n\t\t\t\t\twrite(key, replaced)\n\t\t\t\t}\n\t\t\t} else if (key === 'not' && isWhere(value)) {\n\t\t\t\tconst replaced = this.replaceFacts(value, facts, entity)\n\t\t\t\tif (replaced !== value) {\n\t\t\t\t\twrite(key, replaced)\n\t\t\t\t}\n\t\t\t} else if (isWhere(value)) {\n\t\t\t\tconst target = this.getToOneTarget(entity, key)\n\t\t\t\tconst targetFacts = target === undefined ? [] : this.factsThroughRelation(facts, entity, key)\n\t\t\t\tconst replaced = target === undefined || targetFacts.length === 0 ? value : this.replaceFacts(value, targetFacts, target)\n\t\t\t\tif (replaced !== value) {\n\t\t\t\t\twrite(key, replaced)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn result\n\t}\n\n\tprivate optimizeWhere(where: Input.OptionalWhere, entity: Model.Entity, relationPath: ExtendedRelationContext[]): Input.OptionalWhere | boolean {\n\t\tconst { guard, where: rest } = splitReadGuard(where ?? {})\n\t\tconst optimizedRest = this.optimizeWhereOperands(rest, entity, relationPath)\n\t\tif (Object.keys(guard).length === 0 || typeof optimizedRest === 'boolean') {\n\t\t\t// A hop without any remaining condition is a no-op whatever its guard (an empty relation filter).\n\t\t\treturn optimizedRest\n\t\t}\n\t\t// The guard is a where over the same target rows, but it is compiled into the hop's table source\n\t\t// rather than its condition, so it is optimized on its own and kept out of the AND above.\n\t\tconst optimizedGuard = this.optimizeWhereOperands(guard, entity, relationPath)\n\t\tif (optimizedGuard === true) {\n\t\t\treturn optimizedRest\n\t\t}\n\t\tconst guardWhere = optimizedGuard === false ? { [entity.primary]: { never: true } } : optimizedGuard\n\t\treturn { ...optimizedRest, [READ_GUARD_KEY]: guardWhere }\n\t}\n\n\tprivate optimizeWhereOperands(\n\t\twhere: Input.OptionalWhere,\n\t\tentity: Model.Entity,\n\t\trelationPath: ExtendedRelationContext[],\n\t): Input.OptionalWhere | boolean {\n\t\tconst operands: OptimizedOperand[] = []\n\n\t\tfor (const key in where) {\n\t\t\tconst value = where[key]\n\t\t\tlet operand: OptimizedOperand\n\t\t\tif (value === undefined || value === null) {\n\t\t\t\tcontinue\n\t\t\t} else if (key === 'and') {\n\t\t\t\tconst innerOperands: (Input.OptionalWhere | boolean)[] = []\n\t\t\t\tfor (const innerValue of value as readonly Input.OptionalWhere[]) {\n\t\t\t\t\tconst innerOperand = this.optimizeWhere(innerValue, entity, relationPath)\n\t\t\t\t\tif (innerOperand === false) {\n\t\t\t\t\t\treturn false\n\t\t\t\t\t}\n\t\t\t\t\tinnerOperands.push(innerOperand)\n\t\t\t\t}\n\t\t\t\toperand = this.optimizeAnd(innerOperands, entity, relationPath)\n\t\t\t} else if (key === 'or') {\n\t\t\t\tconst innerOperands: (Input.OptionalWhere | boolean)[] = []\n\t\t\t\tfor (const innerValue of value as readonly Input.OptionalWhere[]) {\n\t\t\t\t\tconst innerOperand = this.optimizeWhere(innerValue, entity, relationPath)\n\t\t\t\t\tif (innerOperand === true) {\n\t\t\t\t\t\toperand = true\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tinnerOperands.push(innerOperand)\n\t\t\t\t}\n\t\t\t\tif (operand !== true) {\n\t\t\t\t\toperand = this.optimizeOr(innerOperands, entity, relationPath)\n\t\t\t\t}\n\t\t\t} else if (key === 'not') {\n\t\t\t\toperand = optimizeNot(this.optimizeWhere(value as Input.OptionalWhere, entity, relationPath))\n\t\t\t} else if (key === MASKED_CELL_KEY) {\n\t\t\t\toperand = this.optimizeAnd(parseMaskedCells(value).map(cell => this.optimizeMaskedCell(cell, entity, relationPath)), entity, relationPath)\n\t\t\t} else {\n\t\t\t\toperand = this.resolveFieldValue(entity, key, value, relationPath)\n\t\t\t}\n\n\t\t\tif (operand === false) {\n\t\t\t\treturn false\n\t\t\t} else if (operand !== undefined) {\n\t\t\t\toperands.push(operand)\n\t\t\t}\n\t\t}\n\t\treturn this.optimizeAnd(operands, entity, relationPath)\n\t}\n\n\t/**\n\t * Replaces `facts`, known to hold on the row, inside the read guards of `where` (field guards of its relations\n\t * and masked-cell guards; a guard reads the same row), and follows them into its to-one relation hops. Only the\n\t * guards are re-optimized, so the user's condition keeps the shape it was optimized into.\n\t */\n\tprivate simplifyGuards(\n\t\twhere: Input.OptionalWhere,\n\t\tfacts: readonly Input.OptionalWhere[],\n\t\tentity: Model.Entity,\n\t\trelationPath: ExtendedRelationContext[],\n\t): Input.OptionalWhere {\n\t\tconst simplifyGuard = (guard: Input.OptionalWhere): Input.OptionalWhere | boolean | undefined => {\n\t\t\tconst replaced = this.replaceFacts(guard, facts, entity)\n\t\t\treturn replaced === guard ? undefined : this.optimizeWhere(replaced, entity, relationPath)\n\t\t}\n\t\tconst asWhere = (guard: Input.OptionalWhere | boolean): Input.OptionalWhere =>\n\t\t\ttypeof guard === 'boolean' ? { [entity.primary]: { [guard ? 'always' : 'never']: true } } : guard\n\t\tlet result: Writable<Input.OptionalWhere> = where\n\t\tconst write = (key: string, value: Input.OptionalWhere[string]) => {\n\t\t\tif (result === where) {\n\t\t\t\tresult = { ...where }\n\t\t\t}\n\t\t\tresult[key] = value\n\t\t}\n\t\tconst readableCells: Input.OptionalWhere[] = []\n\t\tfor (const key in where) {\n\t\t\tconst value = where[key]\n\t\t\tif ((key === 'and' || key === 'or') && Array.isArray(value)) {\n\t\t\t\tconst operands: readonly Input.OptionalWhere[] = value\n\t\t\t\tconst simplified = operands.map(it => this.simplifyGuards(it, facts, entity, relationPath))\n\t\t\t\tif (simplified.some((it, index) => it !== operands[index])) {\n\t\t\t\t\twrite(key, simplified)\n\t\t\t\t}\n\t\t\t} else if (key === 'not' && isWhere(value)) {\n\t\t\t\tconst simplified = this.simplifyGuards(value, facts, entity, relationPath)\n\t\t\t\tif (simplified !== value) {\n\t\t\t\t\twrite(key, simplified)\n\t\t\t\t}\n\t\t\t} else if (key === MASKED_CELL_KEY) {\n\t\t\t\tconst cells = parseMaskedCells(value).map(cell => ({ cell, guard: simplifyGuard(cell.guard) }))\n\t\t\t\tif (cells.every(it => it.guard === undefined)) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\t// A cell whose guard always holds reads its plain value.\n\t\t\t\treadableCells.push(...cells.filter(it => it.guard === true).map(it => it.cell.where))\n\t\t\t\twrite(\n\t\t\t\t\tkey,\n\t\t\t\t\tcells\n\t\t\t\t\t\t.filter(it => it.guard !== true)\n\t\t\t\t\t\t.map(({ cell, guard }) => guard === undefined ? cell : { guard: asWhere(guard), where: cell.where }),\n\t\t\t\t)\n\t\t\t} else if (isWhere(value)) {\n\t\t\t\tconst { fieldGuard, where: relationWhere } = splitFieldGuard(value)\n\t\t\t\tconst guard = fieldGuard === undefined ? undefined : simplifyGuard(fieldGuard)\n\t\t\t\tconst hopWhere = this.simplifyHopGuards(relationWhere, facts, entity, key)\n\t\t\t\tif (guard === true) {\n\t\t\t\t\twrite(key, hopWhere)\n\t\t\t\t} else if (guard !== undefined) {\n\t\t\t\t\twrite(key, { ...hopWhere, [FIELD_GUARD_KEY]: asWhere(guard) })\n\t\t\t\t} else if (hopWhere !== relationWhere) {\n\t\t\t\t\twrite(key, fieldGuard === undefined ? hopWhere : { ...hopWhere, [FIELD_GUARD_KEY]: fieldGuard })\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (readableCells.length === 0) {\n\t\t\treturn result\n\t\t}\n\t\tconst { [MASKED_CELL_KEY]: maskedCells, and, ...rest } = result\n\t\tconst operands = [...(Array.isArray(and) ? and : []), ...readableCells]\n\t\tconst masked = Array.isArray(maskedCells) && maskedCells.length > 0 ? { [MASKED_CELL_KEY]: maskedCells } : {}\n\t\tif (operands.length === 1 && Object.keys(rest).length === 0 && Object.keys(masked).length === 0) {\n\t\t\treturn operands[0]\n\t\t}\n\t\treturn { ...rest, and: operands, ...masked }\n\t}\n\n\t/**\n\t * Follows the facts into a to-one relation hop. Its read guard is dropped when the facts imply it, so the hop\n\t * shares the plain join of an ACL predicate through the same relation instead of joining a guarded source.\n\t */\n\tprivate simplifyHopGuards(\n\t\twhere: Input.OptionalWhere,\n\t\tfacts: readonly Input.OptionalWhere[],\n\t\tentity: Model.Entity,\n\t\trelationName: string,\n\t): Input.OptionalWhere {\n\t\tconst target = this.getToOneTarget(entity, relationName)\n\t\tconst targetFacts = target === undefined ? [] : this.factsThroughRelation(facts, entity, relationName)\n\t\tif (target === undefined || targetFacts.length === 0) {\n\t\t\treturn where\n\t\t}\n\t\tconst { [READ_GUARD_KEY]: readGuard, ...rest } = where\n\t\tconst simplified = this.simplifyGuards(rest, targetFacts, target, [])\n\t\tconst keepsGuard = isWhere(readGuard) && !this.isImpliedByOptimizedFacts(readGuard, target, targetFacts)\n\t\tif (keepsGuard) {\n\t\t\treturn simplified === rest ? where : { ...simplified, [READ_GUARD_KEY]: readGuard }\n\t\t}\n\t\treturn readGuard === undefined && simplified === rest ? where : simplified\n\t}\n\n\t/** Guard and condition are optimized apart: the masked form depends on the condition alone. */\n\tprivate optimizeMaskedCell(masked: MaskedCell, entity: Model.Entity, relationPath: ExtendedRelationContext[]): Input.OptionalWhere | boolean {\n\t\tconst where = this.optimizeWhere(masked.where, entity, relationPath)\n\t\tconst guard = this.optimizeWhere(masked.guard, entity, relationPath)\n\t\tif (typeof where === 'boolean' || guard === true || (typeof guard !== 'boolean' && Object.keys(guard).length === 0)) {\n\t\t\treturn where\n\t\t}\n\t\treturn { [MASKED_CELL_KEY]: [{ guard: guard === false ? { [entity.primary]: { never: true } } : guard, where }] }\n\t}\n\n\tprivate optimizeOr(\n\t\toperands: readonly OptimizedOperand[],\n\t\tentity: Model.Entity,\n\t\trelationPath: ExtendedRelationContext[],\n\t): Input.OptionalWhere | boolean {\n\t\tconst optimized = optimizeOr(operands)\n\t\tif (typeof optimized === 'boolean' || !Array.isArray(optimized.or)) {\n\t\t\treturn optimized\n\t\t}\n\t\tconst result = this.crossOptimize(optimized.or, entity, { never: true }, relationPath)\n\t\tif (result === optimized.or) {\n\t\t\treturn optimized\n\t\t}\n\t\treturn optimizeOr(result)\n\t}\n\n\tprivate optimizeAnd(\n\t\toperands: readonly OptimizedOperand[],\n\t\tentity: Model.Entity,\n\t\trelationPath: ExtendedRelationContext[],\n\t): Input.OptionalWhere | boolean {\n\t\tconst optimized = optimizeAnd(operands)\n\t\tif (typeof optimized === 'boolean' || !Array.isArray(optimized.and)) {\n\t\t\treturn optimized\n\t\t}\n\t\tconst result = this.crossOptimize(optimized.and, entity, { always: true }, relationPath)\n\t\tif (result === optimized.and) {\n\t\t\treturn optimized\n\t\t}\n\t\treturn optimizeAnd(result)\n\t}\n\n\tprivate crossOptimize(\n\t\toperands: Input.OptionalWhere[],\n\t\tentity: Model.Entity,\n\t\treplacement: Input.Condition,\n\t\trelationPath: ExtendedRelationContext[],\n\t): (Input.OptionalWhere | boolean)[] {\n\t\tlet result: (Input.OptionalWhere | boolean)[] = operands\n\t\tlet copied = false\n\t\tconst count = Math.min(result.length, this.options?.maxCrossOptimizationInput ?? 50)\n\t\tfor (let i = 0; i < count; i++) {\n\t\t\tfor (let j = 0; j < count; j++) {\n\t\t\t\tconst a = result[j]\n\t\t\t\tconst b = result[i]\n\t\t\t\tif (i !== j && typeof a !== 'boolean' && typeof b !== 'boolean') {\n\t\t\t\t\tconst elResult = replaceWhere(a, b, { [entity.primary]: replacement }, {\n\t\t\t\t\t\treplaceSubOperands: true,\n\t\t\t\t\t})\n\t\t\t\t\tif (elResult !== a) {\n\t\t\t\t\t\tif (!copied) {\n\t\t\t\t\t\t\tresult = [...result]\n\t\t\t\t\t\t\tcopied = true\n\t\t\t\t\t\t}\n\t\t\t\t\t\tresult[j] = this.optimizeWhere(elResult, entity, relationPath)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn result\n\t}\n\n\tprivate resolveFieldValue(entity: Model.Entity, key: string, value: Input.OptionalWhere[string], relationPath: ExtendedRelationContext[]) {\n\t\treturn acceptFieldVisitor<Input.OptionalWhere | boolean>(this.model, entity, key, {\n\t\t\tvisitColumn: () => {\n\t\t\t\tconst optimizedCondition = this.conditionOptimizer.optimize(value as Input.Condition)\n\n\t\t\t\tif (typeof optimizedCondition === 'boolean') {\n\t\t\t\t\treturn optimizedCondition\n\t\t\t\t}\n\n\t\t\t\treturn { [key]: optimizedCondition }\n\t\t\t},\n\t\t\tvisitRelation: context => {\n\t\t\t\t// The field guard is a where over this (source) entity, so it is optimized here, not with the target.\n\t\t\t\tconst { fieldGuard: rawFieldGuard, where: relationWhere } = splitFieldGuard(value as Input.OptionalWhere)\n\t\t\t\tconst fieldGuard = rawFieldGuard === undefined ? true : this.optimizeWhere(rawFieldGuard, entity, relationPath)\n\t\t\t\tlet where: Input.OptionalWhere = relationWhere\n\t\t\t\tconst newRelationPath: ExtendedRelationContext[] = [...relationPath]\n\t\t\t\tconst length = relationPath.length\n\t\t\t\tif (length > 0 && relationPath[length - 1].context.targetRelation?.name === context.relation.name) {\n\t\t\t\t\tconst item = newRelationPath.pop()\n\t\t\t\t\tconst type = item!.context.type\n\t\t\t\t\tif (item?.canEliminate && (type === 'oneHasMany' || type === 'oneHasOneOwning' || type === 'oneHasOneInverse')) {\n\t\t\t\t\t\twhere = replaceWhere(where, { [context.targetEntity.primary]: { isNull: true } }, { [context.targetEntity.primary]: { never: true } })\n\t\t\t\t\t\twhere = replaceWhere(where, { [context.targetEntity.primary]: { isNull: false } }, { [context.targetEntity.primary]: { always: true } })\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// first level relation - we are sure root exists\n\t\t\t\t\tconst canEliminate = length === 0 || relationPath[length - 1].isLast\n\t\t\t\t\tnewRelationPath.push({ context, isLast: false, canEliminate })\n\t\t\t\t}\n\t\t\t\tconst optimizedWhere = this.optimizeWhere(where, context.targetEntity, newRelationPath)\n\n\t\t\t\tif (typeof optimizedWhere === 'boolean') {\n\t\t\t\t\treturn optimizedWhere\n\t\t\t\t}\n\t\t\t\tif (fieldGuard === true || (fieldGuard !== false && Object.keys(fieldGuard).length === 0)) {\n\t\t\t\t\treturn { [key]: optimizedWhere }\n\t\t\t\t}\n\t\t\t\tconst fieldGuardWhere = fieldGuard === false ? { [entity.primary]: { never: true } } : fieldGuard\n\t\t\t\treturn { [key]: { ...optimizedWhere, [FIELD_GUARD_KEY]: fieldGuardWhere } }\n\t\t\t},\n\t\t})\n\t}\n}\n\nconst guardKeys = new Set<string>([READ_GUARD_KEY, FIELD_GUARD_KEY, MASKED_CELL_KEY])\n\nconst hasGuards = (value: unknown): boolean => {\n\tif (Array.isArray(value)) {\n\t\treturn value.some(hasGuards)\n\t}\n\tif (value === null || typeof value !== 'object') {\n\t\treturn false\n\t}\n\treturn Object.entries(value).some(([key, item]) => guardKeys.has(key) || hasGuards(item))\n}\n\n/** A guarded where tells nothing about the plain rows a guard reads (an unreadable row reads as absent there). */\nconst isUsableFact = (fact: Input.OptionalWhere): boolean => Object.keys(fact).length > 0 && !hasGuards(fact)\n"],"names":["_WhereOptimizer","replaceWhere","isWhere","isRelation","Model","getEntity","deepEqual","splitReadGuard","READ_GUARD_KEY","optimizeNot","MASKED_CELL_KEY","parseMaskedCells","operands","splitFieldGuard","FIELD_GUARD_KEY","optimizeOr","optimizeAnd","acceptFieldVisitor"],"mappings":";;;;;;;;;;;AAmCO,MAAM,kBAAN,MAAMA,iBAAe;AAAA,EAG3B,YACkB,OACA,oBACA,SAChB;AAHgB,SAAA,QAAA;AACA,SAAA,qBAAA;AACA,SAAA,UAAA;AAAA,EAElB;AAAA,EAEO,SACN,OACA,QACA,EAAE,eAAe,CAAA,GAAI,sBAAsB,GAAC,IAA8B,IACpD;AACtB,QAAI,KAAK,SAAS,SAAS;AAC1B,aAAO;AAAA,IACR;AACA,QAAI,wBAAmD,CAAA;AACvD,eAAW,KAAK,cAAc;AAC7B,YAAM,KAAK,aAAa,CAAC;AACzB,UAAI,CAACA,iBAAe,oBAAoB,IAAI,GAAG,IAAI,GAAG;AACrD,gCAAwB,CAAA;AAAA,MACzB,OAAO;AACN,8BAAsB,KAAK,EAAE,SAAS,IAAI,cAA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AE,GAAG,gBAAgB,CAACa,mBAAAA,eAAe,GAAG,kBAAgB;AAAA,MACzE;AAAA,IAAA,CACA;AAAA,EACF;AACD;AAvbC,cADY,iBACG,uBAAsB,oBAAI,IAAsC,CAAC,cAAc,oBAAoB,iBAAiB,CAAC,CAAA;AAD9H,IAAM,iBAAN;AA0bP,MAAM,YAAY,oBAAI,IAAY,CAACN,mBAAAA,gBAAgBM,mBAAAA,iBAAiBJ,mBAAAA,eAAe,CAAC;AAEpF,MAAM,YAAY,CAAC,UAA4B;AAC9C,MAAI,MAAM,QAAQ,KAAK,GAAG;AACzB,WAAO,MAAM,KAAK,SAAS;AAAA,EAC5B;AACA,MAAI,UAAU,QAAQ,OAAO,UAAU,UAAU;AAChD,WAAO;AAAA,EACR;AACA,SAAO,OAAO,QAAQ,KAAK,EAAE,KAAK,CAAC,CAAC,KAAK,IAAI,MAAM,UAAU,IAAI,GAAG,KAAK,UAAU,IAAI,CAAC;AACzF;AAGA,MAAM,eAAe,CAAC,SAAuC,OAAO,KAAK,IAAI,EAAE,SAAS,KAAK,CAAC,UAAU,IAAI;;"}
@@ -1,6 +1,6 @@
1
1
  import { Model } from "@contember/schema";
2
2
  import { isRelation, getEntity, acceptFieldVisitor } from "@contember/schema-utils";
3
- import deepEqual from "fast-deep-equal";
3
+ import { deepEqual } from "@contember/utilities";
4
4
  import { optimizeNot, optimizeOr, optimizeAnd } from "./helpers.js";
5
5
  import { replaceWhere } from "./WhereReplacer.js";
6
6
  import { isWhere, splitReadGuard, READ_GUARD_KEY, MASKED_CELL_KEY, parseMaskedCells, splitFieldGuard, FIELD_GUARD_KEY } from "../../../acl/PredicatesInjector.js";
@@ -1 +1 @@
1
- {"version":3,"file":"WhereOptimizer.js","sources":["../../../../../../../packages/engine-content-api/src/mapper/select/optimizer/WhereOptimizer.ts"],"sourcesContent":["import { Input, Model, Writable } from '@contember/schema'\nimport { ConditionOptimizer } from './ConditionOptimizer.js'\nimport { acceptFieldVisitor, getEntity, isRelation } from '@contember/schema-utils'\nimport deepEqual from 'fast-deep-equal'\nimport { optimizeAnd, optimizeNot, optimizeOr } from './helpers.js'\nimport { replaceWhere } from './WhereReplacer.js'\nimport {\n\tFIELD_GUARD_KEY,\n\tisWhere,\n\tMASKED_CELL_KEY,\n\tMaskedCell,\n\tparseMaskedCells,\n\tREAD_GUARD_KEY,\n\tsplitFieldGuard,\n\tsplitReadGuard,\n} from '../../../acl/PredicatesInjector.js'\n\ntype ExtendedRelationContext = {\n\tcontext: Model.AnyRelationContext\n\tcanEliminate: boolean\n\tisLast: boolean\n}\n\nexport interface WhereOptimizationHints {\n\trelationPath?: Model.AnyRelationContext[]\n\tevaluatedPredicates?: Input.OptionalWhere[]\n}\n\ntype OptimizedOperand = Input.OptionalWhere | undefined | boolean\n\nexport type WhereOptimizerOptions = {\n\tdisable?: boolean\n\tmaxCrossOptimizationInput?: number\n}\n\nexport class WhereOptimizer {\n\tprivate static eliminableRelations = new Set<Model.AnyRelationContext['type']>(['oneHasMany', 'oneHasOneInverse', 'oneHasOneOwning'])\n\n\tconstructor(\n\t\tprivate readonly model: Model.Schema,\n\t\tprivate readonly conditionOptimizer: ConditionOptimizer,\n\t\tprivate readonly options?: WhereOptimizerOptions,\n\t) {\n\t}\n\n\tpublic optimize(\n\t\twhere: Input.OptionalWhere,\n\t\tentity: Model.Entity,\n\t\t{ relationPath = [], evaluatedPredicates = [] }: WhereOptimizationHints = {},\n\t): Input.OptionalWhere {\n\t\tif (this.options?.disable) {\n\t\t\treturn where\n\t\t}\n\t\tlet processedRelationPath: ExtendedRelationContext[] = []\n\t\tfor (const i in relationPath) {\n\t\t\tconst el = relationPath[i]\n\t\t\tif (!WhereOptimizer.eliminableRelations.has(el.type)) {\n\t\t\t\tprocessedRelationPath = []\n\t\t\t} else {\n\t\t\t\tprocessedRelationPath.push({ context: el, canEliminate: true, isLast: Number(i) === relationPath.length })\n\t\t\t}\n\t\t}\n\t\tlet result = this.optimizeWhere(where, entity, processedRelationPath)\n\n\t\tif (typeof result === 'boolean') {\n\t\t\treturn { [entity.primary]: { [result ? 'always' : 'never']: true } }\n\t\t}\n\t\tlet changed = false\n\t\tconst facts: Input.OptionalWhere[] = []\n\t\tfor (const evaluated of evaluatedPredicates) {\n\t\t\tconst evaluatedPredicate = this.optimize(evaluated, entity)\n\t\t\tfacts.push(evaluatedPredicate)\n\t\t\tconst newResult = replaceWhere(result, evaluatedPredicate, { [entity.primary]: { always: true } })\n\t\t\tif (newResult !== result) {\n\t\t\t\tresult = newResult\n\t\t\t\tchanged = true\n\t\t\t}\n\t\t}\n\t\tif (changed) {\n\t\t\tresult = this.optimize(result, entity)\n\t\t}\n\t\treturn this.simplifyGuardsWithFacts(result, facts, entity, processedRelationPath)\n\t}\n\n\t/**\n\t * Guards may only be simplified with facts that hold on every row the query can select: the evaluated\n\t * predicates and the guard-free operands of the top-level AND. Deeper, a sibling can be NULL under a `not`, and\n\t * assuming it TRUE inside a guard would unmask a cell. A guarded operand can never equal a part of a guard, so\n\t * only guard-free operands serve as facts, capped like the cross optimization so that a long AND stays linear.\n\t */\n\tprivate simplifyGuardsWithFacts(\n\t\twhere: Input.OptionalWhere,\n\t\tevaluatedFacts: readonly Input.OptionalWhere[],\n\t\tentity: Model.Entity,\n\t\trelationPath: ExtendedRelationContext[],\n\t): Input.OptionalWhere {\n\t\tconst facts = evaluatedFacts.filter(isUsableFact)\n\t\tconst simplified = facts.length > 0 ? this.simplifyGuards(where, facts, entity, relationPath) : where\n\t\tconst operands = simplified.and\n\t\tif (!Array.isArray(operands)) {\n\t\t\treturn simplified\n\t\t}\n\t\tconst topLevel: readonly Input.OptionalWhere[] = operands\n\t\tconst operandFacts = topLevel.filter(isUsableFact).slice(0, this.options?.maxCrossOptimizationInput ?? 50)\n\t\tif (operandFacts.length === 0) {\n\t\t\treturn simplified\n\t\t}\n\t\tconst simplifiedOperands = topLevel.map(operand => hasGuards(operand) ? this.simplifyGuards(operand, operandFacts, entity, relationPath) : operand)\n\t\treturn simplifiedOperands.some((it, index) => it !== topLevel[index]) ? { ...simplified, and: simplifiedOperands } : simplified\n\t}\n\n\t/**\n\t * Whether `facts`, wheres TRUE on the row, imply `guard`. A guard they imply holds on every row the query\n\t * can select, so the hop it protects may join the plain table instead of a guarded source.\n\t */\n\tpublic isImpliedByFacts(guard: Input.OptionalWhere, entity: Model.Entity, facts: readonly Input.OptionalWhere[]): boolean {\n\t\tconst usableFacts = facts.filter(isUsableFact).map(it => this.optimize(it, entity))\n\t\treturn usableFacts.length > 0 && this.isImpliedByOptimizedFacts(guard, entity, usableFacts)\n\t}\n\n\tprivate isImpliedByOptimizedFacts(guard: Input.OptionalWhere, entity: Model.Entity, facts: readonly Input.OptionalWhere[]): boolean {\n\t\tconst optimizedGuard = this.optimizeWhere(guard, entity, [])\n\t\tif (typeof optimizedGuard === 'boolean') {\n\t\t\treturn optimizedGuard\n\t\t}\n\t\treturn this.optimizeWhere(this.replaceFacts(optimizedGuard, facts, entity), entity, []) === true\n\t}\n\n\t/**\n\t * Facts about the row a to-one relation joins. A fact TRUE on a row holds on the (possibly null-extended) row its\n\t * to-one relation joins, so each operand of its top-level AND over that relation is a fact there. A to-many\n\t * relation joins many rows, which share no fact.\n\t */\n\tpublic factsThroughRelation(facts: readonly Input.OptionalWhere[], entity: Model.Entity, relationName: string): Input.OptionalWhere[] {\n\t\tif (this.getToOneTarget(entity, relationName) === undefined) {\n\t\t\treturn []\n\t\t}\n\t\tconst relationOperands = (fact: Input.OptionalWhere): Input.OptionalWhere[] => {\n\t\t\tconst value = fact[relationName]\n\t\t\tconst operands = Array.isArray(fact.and) ? fact.and.filter(isWhere).flatMap(relationOperands) : []\n\t\t\treturn isWhere(value) ? [value, ...operands] : operands\n\t\t}\n\t\treturn facts.flatMap(relationOperands)\n\t}\n\n\tprivate getToOneTarget(entity: Model.Entity, fieldName: string): Model.Entity | undefined {\n\t\tconst field = entity.fields[fieldName]\n\t\tif (field === undefined || !isRelation(field)) {\n\t\t\treturn undefined\n\t\t}\n\t\tconst isToOne = field.type === Model.RelationType.ManyHasOne || field.type === Model.RelationType.OneHasOne\n\t\treturn isToOne ? getEntity(this.model, field.target) : undefined\n\t}\n\n\t/** Replaces every part of `where` equal to a fact with TRUE, following the facts into to-one relations. */\n\tprivate replaceFacts(where: Input.OptionalWhere, facts: readonly Input.OptionalWhere[], entity: Model.Entity): Input.OptionalWhere {\n\t\tif (facts.some(fact => deepEqual(where, fact))) {\n\t\t\treturn { [entity.primary]: { always: true } }\n\t\t}\n\t\tlet result: Writable<Input.OptionalWhere> = where\n\t\tconst write = (key: string, value: Input.OptionalWhere[string]) => {\n\t\t\tif (result === where) {\n\t\t\t\tresult = { ...where }\n\t\t\t}\n\t\t\tresult[key] = value\n\t\t}\n\t\tfor (const key in where) {\n\t\t\tconst value = where[key]\n\t\t\tif ((key === 'and' || key === 'or') && Array.isArray(value)) {\n\t\t\t\tconst operands: readonly Input.OptionalWhere[] = value\n\t\t\t\tconst replaced = operands.map(it => this.replaceFacts(it, facts, entity))\n\t\t\t\tif (replaced.some((it, index) => it !== operands[index])) {\n\t\t\t\t\twrite(key, replaced)\n\t\t\t\t}\n\t\t\t} else if (key === 'not' && isWhere(value)) {\n\t\t\t\tconst replaced = this.replaceFacts(value, facts, entity)\n\t\t\t\tif (replaced !== value) {\n\t\t\t\t\twrite(key, replaced)\n\t\t\t\t}\n\t\t\t} else if (isWhere(value)) {\n\t\t\t\tconst target = this.getToOneTarget(entity, key)\n\t\t\t\tconst targetFacts = target === undefined ? [] : this.factsThroughRelation(facts, entity, key)\n\t\t\t\tconst replaced = target === undefined || targetFacts.length === 0 ? value : this.replaceFacts(value, targetFacts, target)\n\t\t\t\tif (replaced !== value) {\n\t\t\t\t\twrite(key, replaced)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn result\n\t}\n\n\tprivate optimizeWhere(where: Input.OptionalWhere, entity: Model.Entity, relationPath: ExtendedRelationContext[]): Input.OptionalWhere | boolean {\n\t\tconst { guard, where: rest } = splitReadGuard(where ?? {})\n\t\tconst optimizedRest = this.optimizeWhereOperands(rest, entity, relationPath)\n\t\tif (Object.keys(guard).length === 0 || typeof optimizedRest === 'boolean') {\n\t\t\t// A hop without any remaining condition is a no-op whatever its guard (an empty relation filter).\n\t\t\treturn optimizedRest\n\t\t}\n\t\t// The guard is a where over the same target rows, but it is compiled into the hop's table source\n\t\t// rather than its condition, so it is optimized on its own and kept out of the AND above.\n\t\tconst optimizedGuard = this.optimizeWhereOperands(guard, entity, relationPath)\n\t\tif (optimizedGuard === true) {\n\t\t\treturn optimizedRest\n\t\t}\n\t\tconst guardWhere = optimizedGuard === false ? { [entity.primary]: { never: true } } : optimizedGuard\n\t\treturn { ...optimizedRest, [READ_GUARD_KEY]: guardWhere }\n\t}\n\n\tprivate optimizeWhereOperands(\n\t\twhere: Input.OptionalWhere,\n\t\tentity: Model.Entity,\n\t\trelationPath: ExtendedRelationContext[],\n\t): Input.OptionalWhere | boolean {\n\t\tconst operands: OptimizedOperand[] = []\n\n\t\tfor (const key in where) {\n\t\t\tconst value = where[key]\n\t\t\tlet operand: OptimizedOperand\n\t\t\tif (value === undefined || value === null) {\n\t\t\t\tcontinue\n\t\t\t} else if (key === 'and') {\n\t\t\t\tconst innerOperands: (Input.OptionalWhere | boolean)[] = []\n\t\t\t\tfor (const innerValue of value as readonly Input.OptionalWhere[]) {\n\t\t\t\t\tconst innerOperand = this.optimizeWhere(innerValue, entity, relationPath)\n\t\t\t\t\tif (innerOperand === false) {\n\t\t\t\t\t\treturn false\n\t\t\t\t\t}\n\t\t\t\t\tinnerOperands.push(innerOperand)\n\t\t\t\t}\n\t\t\t\toperand = this.optimizeAnd(innerOperands, entity, relationPath)\n\t\t\t} else if (key === 'or') {\n\t\t\t\tconst innerOperands: (Input.OptionalWhere | boolean)[] = []\n\t\t\t\tfor (const innerValue of value as readonly Input.OptionalWhere[]) {\n\t\t\t\t\tconst innerOperand = this.optimizeWhere(innerValue, entity, relationPath)\n\t\t\t\t\tif (innerOperand === true) {\n\t\t\t\t\t\toperand = true\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tinnerOperands.push(innerOperand)\n\t\t\t\t}\n\t\t\t\tif (operand !== true) {\n\t\t\t\t\toperand = this.optimizeOr(innerOperands, entity, relationPath)\n\t\t\t\t}\n\t\t\t} else if (key === 'not') {\n\t\t\t\toperand = optimizeNot(this.optimizeWhere(value as Input.OptionalWhere, entity, relationPath))\n\t\t\t} else if (key === MASKED_CELL_KEY) {\n\t\t\t\toperand = this.optimizeAnd(parseMaskedCells(value).map(cell => this.optimizeMaskedCell(cell, entity, relationPath)), entity, relationPath)\n\t\t\t} else {\n\t\t\t\toperand = this.resolveFieldValue(entity, key, value, relationPath)\n\t\t\t}\n\n\t\t\tif (operand === false) {\n\t\t\t\treturn false\n\t\t\t} else if (operand !== undefined) {\n\t\t\t\toperands.push(operand)\n\t\t\t}\n\t\t}\n\t\treturn this.optimizeAnd(operands, entity, relationPath)\n\t}\n\n\t/**\n\t * Replaces `facts`, known to hold on the row, inside the read guards of `where` (field guards of its relations\n\t * and masked-cell guards; a guard reads the same row), and follows them into its to-one relation hops. Only the\n\t * guards are re-optimized, so the user's condition keeps the shape it was optimized into.\n\t */\n\tprivate simplifyGuards(\n\t\twhere: Input.OptionalWhere,\n\t\tfacts: readonly Input.OptionalWhere[],\n\t\tentity: Model.Entity,\n\t\trelationPath: ExtendedRelationContext[],\n\t): Input.OptionalWhere {\n\t\tconst simplifyGuard = (guard: Input.OptionalWhere): Input.OptionalWhere | boolean | undefined => {\n\t\t\tconst replaced = this.replaceFacts(guard, facts, entity)\n\t\t\treturn replaced === guard ? undefined : this.optimizeWhere(replaced, entity, relationPath)\n\t\t}\n\t\tconst asWhere = (guard: Input.OptionalWhere | boolean): Input.OptionalWhere =>\n\t\t\ttypeof guard === 'boolean' ? { [entity.primary]: { [guard ? 'always' : 'never']: true } } : guard\n\t\tlet result: Writable<Input.OptionalWhere> = where\n\t\tconst write = (key: string, value: Input.OptionalWhere[string]) => {\n\t\t\tif (result === where) {\n\t\t\t\tresult = { ...where }\n\t\t\t}\n\t\t\tresult[key] = value\n\t\t}\n\t\tconst readableCells: Input.OptionalWhere[] = []\n\t\tfor (const key in where) {\n\t\t\tconst value = where[key]\n\t\t\tif ((key === 'and' || key === 'or') && Array.isArray(value)) {\n\t\t\t\tconst operands: readonly Input.OptionalWhere[] = value\n\t\t\t\tconst simplified = operands.map(it => this.simplifyGuards(it, facts, entity, relationPath))\n\t\t\t\tif (simplified.some((it, index) => it !== operands[index])) {\n\t\t\t\t\twrite(key, simplified)\n\t\t\t\t}\n\t\t\t} else if (key === 'not' && isWhere(value)) {\n\t\t\t\tconst simplified = this.simplifyGuards(value, facts, entity, relationPath)\n\t\t\t\tif (simplified !== value) {\n\t\t\t\t\twrite(key, simplified)\n\t\t\t\t}\n\t\t\t} else if (key === MASKED_CELL_KEY) {\n\t\t\t\tconst cells = parseMaskedCells(value).map(cell => ({ cell, guard: simplifyGuard(cell.guard) }))\n\t\t\t\tif (cells.every(it => it.guard === undefined)) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\t// A cell whose guard always holds reads its plain value.\n\t\t\t\treadableCells.push(...cells.filter(it => it.guard === true).map(it => it.cell.where))\n\t\t\t\twrite(\n\t\t\t\t\tkey,\n\t\t\t\t\tcells\n\t\t\t\t\t\t.filter(it => it.guard !== true)\n\t\t\t\t\t\t.map(({ cell, guard }) => guard === undefined ? cell : { guard: asWhere(guard), where: cell.where }),\n\t\t\t\t)\n\t\t\t} else if (isWhere(value)) {\n\t\t\t\tconst { fieldGuard, where: relationWhere } = splitFieldGuard(value)\n\t\t\t\tconst guard = fieldGuard === undefined ? undefined : simplifyGuard(fieldGuard)\n\t\t\t\tconst hopWhere = this.simplifyHopGuards(relationWhere, facts, entity, key)\n\t\t\t\tif (guard === true) {\n\t\t\t\t\twrite(key, hopWhere)\n\t\t\t\t} else if (guard !== undefined) {\n\t\t\t\t\twrite(key, { ...hopWhere, [FIELD_GUARD_KEY]: asWhere(guard) })\n\t\t\t\t} else if (hopWhere !== relationWhere) {\n\t\t\t\t\twrite(key, fieldGuard === undefined ? hopWhere : { ...hopWhere, [FIELD_GUARD_KEY]: fieldGuard })\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (readableCells.length === 0) {\n\t\t\treturn result\n\t\t}\n\t\tconst { [MASKED_CELL_KEY]: maskedCells, and, ...rest } = result\n\t\tconst operands = [...(Array.isArray(and) ? and : []), ...readableCells]\n\t\tconst masked = Array.isArray(maskedCells) && maskedCells.length > 0 ? { [MASKED_CELL_KEY]: maskedCells } : {}\n\t\tif (operands.length === 1 && Object.keys(rest).length === 0 && Object.keys(masked).length === 0) {\n\t\t\treturn operands[0]\n\t\t}\n\t\treturn { ...rest, and: operands, ...masked }\n\t}\n\n\t/**\n\t * Follows the facts into a to-one relation hop. Its read guard is dropped when the facts imply it, so the hop\n\t * shares the plain join of an ACL predicate through the same relation instead of joining a guarded source.\n\t */\n\tprivate simplifyHopGuards(\n\t\twhere: Input.OptionalWhere,\n\t\tfacts: readonly Input.OptionalWhere[],\n\t\tentity: Model.Entity,\n\t\trelationName: string,\n\t): Input.OptionalWhere {\n\t\tconst target = this.getToOneTarget(entity, relationName)\n\t\tconst targetFacts = target === undefined ? [] : this.factsThroughRelation(facts, entity, relationName)\n\t\tif (target === undefined || targetFacts.length === 0) {\n\t\t\treturn where\n\t\t}\n\t\tconst { [READ_GUARD_KEY]: readGuard, ...rest } = where\n\t\tconst simplified = this.simplifyGuards(rest, targetFacts, target, [])\n\t\tconst keepsGuard = isWhere(readGuard) && !this.isImpliedByOptimizedFacts(readGuard, target, targetFacts)\n\t\tif (keepsGuard) {\n\t\t\treturn simplified === rest ? where : { ...simplified, [READ_GUARD_KEY]: readGuard }\n\t\t}\n\t\treturn readGuard === undefined && simplified === rest ? where : simplified\n\t}\n\n\t/** Guard and condition are optimized apart: the masked form depends on the condition alone. */\n\tprivate optimizeMaskedCell(masked: MaskedCell, entity: Model.Entity, relationPath: ExtendedRelationContext[]): Input.OptionalWhere | boolean {\n\t\tconst where = this.optimizeWhere(masked.where, entity, relationPath)\n\t\tconst guard = this.optimizeWhere(masked.guard, entity, relationPath)\n\t\tif (typeof where === 'boolean' || guard === true || (typeof guard !== 'boolean' && Object.keys(guard).length === 0)) {\n\t\t\treturn where\n\t\t}\n\t\treturn { [MASKED_CELL_KEY]: [{ guard: guard === false ? { [entity.primary]: { never: true } } : guard, where }] }\n\t}\n\n\tprivate optimizeOr(\n\t\toperands: readonly OptimizedOperand[],\n\t\tentity: Model.Entity,\n\t\trelationPath: ExtendedRelationContext[],\n\t): Input.OptionalWhere | boolean {\n\t\tconst optimized = optimizeOr(operands)\n\t\tif (typeof optimized === 'boolean' || !Array.isArray(optimized.or)) {\n\t\t\treturn optimized\n\t\t}\n\t\tconst result = this.crossOptimize(optimized.or, entity, { never: true }, relationPath)\n\t\tif (result === optimized.or) {\n\t\t\treturn optimized\n\t\t}\n\t\treturn optimizeOr(result)\n\t}\n\n\tprivate optimizeAnd(\n\t\toperands: readonly OptimizedOperand[],\n\t\tentity: Model.Entity,\n\t\trelationPath: ExtendedRelationContext[],\n\t): Input.OptionalWhere | boolean {\n\t\tconst optimized = optimizeAnd(operands)\n\t\tif (typeof optimized === 'boolean' || !Array.isArray(optimized.and)) {\n\t\t\treturn optimized\n\t\t}\n\t\tconst result = this.crossOptimize(optimized.and, entity, { always: true }, relationPath)\n\t\tif (result === optimized.and) {\n\t\t\treturn optimized\n\t\t}\n\t\treturn optimizeAnd(result)\n\t}\n\n\tprivate crossOptimize(\n\t\toperands: Input.OptionalWhere[],\n\t\tentity: Model.Entity,\n\t\treplacement: Input.Condition,\n\t\trelationPath: ExtendedRelationContext[],\n\t): (Input.OptionalWhere | boolean)[] {\n\t\tlet result: (Input.OptionalWhere | boolean)[] = operands\n\t\tlet copied = false\n\t\tconst count = Math.min(result.length, this.options?.maxCrossOptimizationInput ?? 50)\n\t\tfor (let i = 0; i < count; i++) {\n\t\t\tfor (let j = 0; j < count; j++) {\n\t\t\t\tconst a = result[j]\n\t\t\t\tconst b = result[i]\n\t\t\t\tif (i !== j && typeof a !== 'boolean' && typeof b !== 'boolean') {\n\t\t\t\t\tconst elResult = replaceWhere(a, b, { [entity.primary]: replacement }, {\n\t\t\t\t\t\treplaceSubOperands: true,\n\t\t\t\t\t})\n\t\t\t\t\tif (elResult !== a) {\n\t\t\t\t\t\tif (!copied) {\n\t\t\t\t\t\t\tresult = [...result]\n\t\t\t\t\t\t\tcopied = true\n\t\t\t\t\t\t}\n\t\t\t\t\t\tresult[j] = this.optimizeWhere(elResult, entity, relationPath)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn result\n\t}\n\n\tprivate resolveFieldValue(entity: Model.Entity, key: string, value: Input.OptionalWhere[string], relationPath: ExtendedRelationContext[]) {\n\t\treturn acceptFieldVisitor<Input.OptionalWhere | boolean>(this.model, entity, key, {\n\t\t\tvisitColumn: () => {\n\t\t\t\tconst optimizedCondition = this.conditionOptimizer.optimize(value as Input.Condition)\n\n\t\t\t\tif (typeof optimizedCondition === 'boolean') {\n\t\t\t\t\treturn optimizedCondition\n\t\t\t\t}\n\n\t\t\t\treturn { [key]: optimizedCondition }\n\t\t\t},\n\t\t\tvisitRelation: context => {\n\t\t\t\t// The field guard is a where over this (source) entity, so it is optimized here, not with the target.\n\t\t\t\tconst { fieldGuard: rawFieldGuard, where: relationWhere } = splitFieldGuard(value as Input.OptionalWhere)\n\t\t\t\tconst fieldGuard = rawFieldGuard === undefined ? true : this.optimizeWhere(rawFieldGuard, entity, relationPath)\n\t\t\t\tlet where: Input.OptionalWhere = relationWhere\n\t\t\t\tconst newRelationPath: ExtendedRelationContext[] = [...relationPath]\n\t\t\t\tconst length = relationPath.length\n\t\t\t\tif (length > 0 && relationPath[length - 1].context.targetRelation?.name === context.relation.name) {\n\t\t\t\t\tconst item = newRelationPath.pop()\n\t\t\t\t\tconst type = item!.context.type\n\t\t\t\t\tif (item?.canEliminate && (type === 'oneHasMany' || type === 'oneHasOneOwning' || type === 'oneHasOneInverse')) {\n\t\t\t\t\t\twhere = replaceWhere(where, { [context.targetEntity.primary]: { isNull: true } }, { [context.targetEntity.primary]: { never: true } })\n\t\t\t\t\t\twhere = replaceWhere(where, { [context.targetEntity.primary]: { isNull: false } }, { [context.targetEntity.primary]: { always: true } })\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// first level relation - we are sure root exists\n\t\t\t\t\tconst canEliminate = length === 0 || relationPath[length - 1].isLast\n\t\t\t\t\tnewRelationPath.push({ context, isLast: false, canEliminate })\n\t\t\t\t}\n\t\t\t\tconst optimizedWhere = this.optimizeWhere(where, context.targetEntity, newRelationPath)\n\n\t\t\t\tif (typeof optimizedWhere === 'boolean') {\n\t\t\t\t\treturn optimizedWhere\n\t\t\t\t}\n\t\t\t\tif (fieldGuard === true || (fieldGuard !== false && Object.keys(fieldGuard).length === 0)) {\n\t\t\t\t\treturn { [key]: optimizedWhere }\n\t\t\t\t}\n\t\t\t\tconst fieldGuardWhere = fieldGuard === false ? { [entity.primary]: { never: true } } : fieldGuard\n\t\t\t\treturn { [key]: { ...optimizedWhere, [FIELD_GUARD_KEY]: fieldGuardWhere } }\n\t\t\t},\n\t\t})\n\t}\n}\n\nconst guardKeys = new Set<string>([READ_GUARD_KEY, FIELD_GUARD_KEY, MASKED_CELL_KEY])\n\nconst hasGuards = (value: unknown): boolean => {\n\tif (Array.isArray(value)) {\n\t\treturn value.some(hasGuards)\n\t}\n\tif (value === null || typeof value !== 'object') {\n\t\treturn false\n\t}\n\treturn Object.entries(value).some(([key, item]) => guardKeys.has(key) || hasGuards(item))\n}\n\n/** A guarded where tells nothing about the plain rows a guard reads (an unreadable row reads as absent there). */\nconst isUsableFact = (fact: Input.OptionalWhere): boolean => Object.keys(fact).length > 0 && !hasGuards(fact)\n"],"names":["_WhereOptimizer","operands"],"mappings":";;;;;;;;;AAmCO,MA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AAK,UAAU,EAAE,WAAW,GAAI;AAC1F,iBAAO,EAAE,CAAC,GAAG,GAAG,eAAA;AAAA,QACjB;AACA,cAAM,kBAAkB,eAAe,QAAQ,EAAE,CAAC,OAAO,OAAO,GAAG,EAAE,OAAO,KAAA,EAAK,IAAM;AACvF,eAAO,EAAE,CAAC,GAAG,GAAG,EAAE,GAAG,gBAAgB,CAAC,eAAe,GAAG,kBAAgB;AAAA,MACzE;AAAA,IAAA,CACA;AAAA,EACF;AACD;AAvbC,cADY,iBACG,uBAAsB,oBAAI,IAAsC,CAAC,cAAc,oBAAoB,iBAAiB,CAAC,CAAA;AAD9H,IAAM,iBAAN;AA0bP,MAAM,YAAY,oBAAI,IAAY,CAAC,gBAAgB,iBAAiB,eAAe,CAAC;AAEpF,MAAM,YAAY,CAAC,UAA4B;AAC9C,MAAI,MAAM,QAAQ,KAAK,GAAG;AACzB,WAAO,MAAM,KAAK,SAAS;AAAA,EAC5B;AACA,MAAI,UAAU,QAAQ,OAAO,UAAU,UAAU;AAChD,WAAO;AAAA,EACR;AACA,SAAO,OAAO,QAAQ,KAAK,EAAE,KAAK,CAAC,CAAC,KAAK,IAAI,MAAM,UAAU,IAAI,GAAG,KAAK,UAAU,IAAI,CAAC;AACzF;AAGA,MAAM,eAAe,CAAC,SAAuC,OAAO,KAAK,IAAI,EAAE,SAAS,KAAK,CAAC,UAAU,IAAI;"}
1
+ {"version":3,"file":"WhereOptimizer.js","sources":["../../../../../../../packages/engine-content-api/src/mapper/select/optimizer/WhereOptimizer.ts"],"sourcesContent":["import { Input, Model, Writable } from '@contember/schema'\nimport { ConditionOptimizer } from './ConditionOptimizer.js'\nimport { acceptFieldVisitor, getEntity, isRelation } from '@contember/schema-utils'\nimport { deepEqual } from '@contember/utilities'\nimport { optimizeAnd, optimizeNot, optimizeOr } from './helpers.js'\nimport { replaceWhere } from './WhereReplacer.js'\nimport {\n\tFIELD_GUARD_KEY,\n\tisWhere,\n\tMASKED_CELL_KEY,\n\tMaskedCell,\n\tparseMaskedCells,\n\tREAD_GUARD_KEY,\n\tsplitFieldGuard,\n\tsplitReadGuard,\n} from '../../../acl/PredicatesInjector.js'\n\ntype ExtendedRelationContext = {\n\tcontext: Model.AnyRelationContext\n\tcanEliminate: boolean\n\tisLast: boolean\n}\n\nexport interface WhereOptimizationHints {\n\trelationPath?: Model.AnyRelationContext[]\n\tevaluatedPredicates?: Input.OptionalWhere[]\n}\n\ntype OptimizedOperand = Input.OptionalWhere | undefined | boolean\n\nexport type WhereOptimizerOptions = {\n\tdisable?: boolean\n\tmaxCrossOptimizationInput?: number\n}\n\nexport class WhereOptimizer {\n\tprivate static eliminableRelations = new Set<Model.AnyRelationContext['type']>(['oneHasMany', 'oneHasOneInverse', 'oneHasOneOwning'])\n\n\tconstructor(\n\t\tprivate readonly model: Model.Schema,\n\t\tprivate readonly conditionOptimizer: ConditionOptimizer,\n\t\tprivate readonly options?: WhereOptimizerOptions,\n\t) {\n\t}\n\n\tpublic optimize(\n\t\twhere: Input.OptionalWhere,\n\t\tentity: Model.Entity,\n\t\t{ relationPath = [], evaluatedPredicates = [] }: WhereOptimizationHints = {},\n\t): Input.OptionalWhere {\n\t\tif (this.options?.disable) {\n\t\t\treturn where\n\t\t}\n\t\tlet processedRelationPath: ExtendedRelationContext[] = []\n\t\tfor (const i in relationPath) {\n\t\t\tconst el = relationPath[i]\n\t\t\tif (!WhereOptimizer.eliminableRelations.has(el.type)) {\n\t\t\t\tprocessedRelationPath = []\n\t\t\t} else {\n\t\t\t\tprocessedRelationPath.push({ context: el, canEliminate: true, isLast: Number(i) === relationPath.length })\n\t\t\t}\n\t\t}\n\t\tlet result = this.optimizeWhere(where, entity, processedRelationPath)\n\n\t\tif (typeof result === 'boolean') {\n\t\t\treturn { [entity.primary]: { [result ? 'always' : 'never']: true } }\n\t\t}\n\t\tlet changed = false\n\t\tconst facts: Input.OptionalWhere[] = []\n\t\tfor (const evaluated of evaluatedPredicates) {\n\t\t\tconst evaluatedPredicate = this.optimize(evaluated, entity)\n\t\t\tfacts.push(evaluatedPredicate)\n\t\t\tconst newResult = replaceWhere(result, evaluatedPredicate, { [entity.primary]: { always: true } })\n\t\t\tif (newResult !== result) {\n\t\t\t\tresult = newResult\n\t\t\t\tchanged = true\n\t\t\t}\n\t\t}\n\t\tif (changed) {\n\t\t\tresult = this.optimize(result, entity)\n\t\t}\n\t\treturn this.simplifyGuardsWithFacts(result, facts, entity, processedRelationPath)\n\t}\n\n\t/**\n\t * Guards may only be simplified with facts that hold on every row the query can select: the evaluated\n\t * predicates and the guard-free operands of the top-level AND. Deeper, a sibling can be NULL under a `not`, and\n\t * assuming it TRUE inside a guard would unmask a cell. A guarded operand can never equal a part of a guard, so\n\t * only guard-free operands serve as facts, capped like the cross optimization so that a long AND stays linear.\n\t */\n\tprivate simplifyGuardsWithFacts(\n\t\twhere: Input.OptionalWhere,\n\t\tevaluatedFacts: readonly Input.OptionalWhere[],\n\t\tentity: Model.Entity,\n\t\trelationPath: ExtendedRelationContext[],\n\t): Input.OptionalWhere {\n\t\tconst facts = evaluatedFacts.filter(isUsableFact)\n\t\tconst simplified = facts.length > 0 ? this.simplifyGuards(where, facts, entity, relationPath) : where\n\t\tconst operands = simplified.and\n\t\tif (!Array.isArray(operands)) {\n\t\t\treturn simplified\n\t\t}\n\t\tconst topLevel: readonly Input.OptionalWhere[] = operands\n\t\tconst operandFacts = topLevel.filter(isUsableFact).slice(0, this.options?.maxCrossOptimizationInput ?? 50)\n\t\tif (operandFacts.length === 0) {\n\t\t\treturn simplified\n\t\t}\n\t\tconst simplifiedOperands = topLevel.map(operand => hasGuards(operand) ? this.simplifyGuards(operand, operandFacts, entity, relationPath) : operand)\n\t\treturn simplifiedOperands.some((it, index) => it !== topLevel[index]) ? { ...simplified, and: simplifiedOperands } : simplified\n\t}\n\n\t/**\n\t * Whether `facts`, wheres TRUE on the row, imply `guard`. A guard they imply holds on every row the query\n\t * can select, so the hop it protects may join the plain table instead of a guarded source.\n\t */\n\tpublic isImpliedByFacts(guard: Input.OptionalWhere, entity: Model.Entity, facts: readonly Input.OptionalWhere[]): boolean {\n\t\tconst usableFacts = facts.filter(isUsableFact).map(it => this.optimize(it, entity))\n\t\treturn usableFacts.length > 0 && this.isImpliedByOptimizedFacts(guard, entity, usableFacts)\n\t}\n\n\tprivate isImpliedByOptimizedFacts(guard: Input.OptionalWhere, entity: Model.Entity, facts: readonly Input.OptionalWhere[]): boolean {\n\t\tconst optimizedGuard = this.optimizeWhere(guard, entity, [])\n\t\tif (typeof optimizedGuard === 'boolean') {\n\t\t\treturn optimizedGuard\n\t\t}\n\t\treturn this.optimizeWhere(this.replaceFacts(optimizedGuard, facts, entity), entity, []) === true\n\t}\n\n\t/**\n\t * Facts about the row a to-one relation joins. A fact TRUE on a row holds on the (possibly null-extended) row its\n\t * to-one relation joins, so each operand of its top-level AND over that relation is a fact there. A to-many\n\t * relation joins many rows, which share no fact.\n\t */\n\tpublic factsThroughRelation(facts: readonly Input.OptionalWhere[], entity: Model.Entity, relationName: string): Input.OptionalWhere[] {\n\t\tif (this.getToOneTarget(entity, relationName) === undefined) {\n\t\t\treturn []\n\t\t}\n\t\tconst relationOperands = (fact: Input.OptionalWhere): Input.OptionalWhere[] => {\n\t\t\tconst value = fact[relationName]\n\t\t\tconst operands = Array.isArray(fact.and) ? fact.and.filter(isWhere).flatMap(relationOperands) : []\n\t\t\treturn isWhere(value) ? [value, ...operands] : operands\n\t\t}\n\t\treturn facts.flatMap(relationOperands)\n\t}\n\n\tprivate getToOneTarget(entity: Model.Entity, fieldName: string): Model.Entity | undefined {\n\t\tconst field = entity.fields[fieldName]\n\t\tif (field === undefined || !isRelation(field)) {\n\t\t\treturn undefined\n\t\t}\n\t\tconst isToOne = field.type === Model.RelationType.ManyHasOne || field.type === Model.RelationType.OneHasOne\n\t\treturn isToOne ? getEntity(this.model, field.target) : undefined\n\t}\n\n\t/** Replaces every part of `where` equal to a fact with TRUE, following the facts into to-one relations. */\n\tprivate replaceFacts(where: Input.OptionalWhere, facts: readonly Input.OptionalWhere[], entity: Model.Entity): Input.OptionalWhere {\n\t\tif (facts.some(fact => deepEqual(where, fact))) {\n\t\t\treturn { [entity.primary]: { always: true } }\n\t\t}\n\t\tlet result: Writable<Input.OptionalWhere> = where\n\t\tconst write = (key: string, value: Input.OptionalWhere[string]) => {\n\t\t\tif (result === where) {\n\t\t\t\tresult = { ...where }\n\t\t\t}\n\t\t\tresult[key] = value\n\t\t}\n\t\tfor (const key in where) {\n\t\t\tconst value = where[key]\n\t\t\tif ((key === 'and' || key === 'or') && Array.isArray(value)) {\n\t\t\t\tconst operands: readonly Input.OptionalWhere[] = value\n\t\t\t\tconst replaced = operands.map(it => this.replaceFacts(it, facts, entity))\n\t\t\t\tif (replaced.some((it, index) => it !== operands[index])) {\n\t\t\t\t\twrite(key, replaced)\n\t\t\t\t}\n\t\t\t} else if (key === 'not' && isWhere(value)) {\n\t\t\t\tconst replaced = this.replaceFacts(value, facts, entity)\n\t\t\t\tif (replaced !== value) {\n\t\t\t\t\twrite(key, replaced)\n\t\t\t\t}\n\t\t\t} else if (isWhere(value)) {\n\t\t\t\tconst target = this.getToOneTarget(entity, key)\n\t\t\t\tconst targetFacts = target === undefined ? [] : this.factsThroughRelation(facts, entity, key)\n\t\t\t\tconst replaced = target === undefined || targetFacts.length === 0 ? value : this.replaceFacts(value, targetFacts, target)\n\t\t\t\tif (replaced !== value) {\n\t\t\t\t\twrite(key, replaced)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn result\n\t}\n\n\tprivate optimizeWhere(where: Input.OptionalWhere, entity: Model.Entity, relationPath: ExtendedRelationContext[]): Input.OptionalWhere | boolean {\n\t\tconst { guard, where: rest } = splitReadGuard(where ?? {})\n\t\tconst optimizedRest = this.optimizeWhereOperands(rest, entity, relationPath)\n\t\tif (Object.keys(guard).length === 0 || typeof optimizedRest === 'boolean') {\n\t\t\t// A hop without any remaining condition is a no-op whatever its guard (an empty relation filter).\n\t\t\treturn optimizedRest\n\t\t}\n\t\t// The guard is a where over the same target rows, but it is compiled into the hop's table source\n\t\t// rather than its condition, so it is optimized on its own and kept out of the AND above.\n\t\tconst optimizedGuard = this.optimizeWhereOperands(guard, entity, relationPath)\n\t\tif (optimizedGuard === true) {\n\t\t\treturn optimizedRest\n\t\t}\n\t\tconst guardWhere = optimizedGuard === false ? { [entity.primary]: { never: true } } : optimizedGuard\n\t\treturn { ...optimizedRest, [READ_GUARD_KEY]: guardWhere }\n\t}\n\n\tprivate optimizeWhereOperands(\n\t\twhere: Input.OptionalWhere,\n\t\tentity: Model.Entity,\n\t\trelationPath: ExtendedRelationContext[],\n\t): Input.OptionalWhere | boolean {\n\t\tconst operands: OptimizedOperand[] = []\n\n\t\tfor (const key in where) {\n\t\t\tconst value = where[key]\n\t\t\tlet operand: OptimizedOperand\n\t\t\tif (value === undefined || value === null) {\n\t\t\t\tcontinue\n\t\t\t} else if (key === 'and') {\n\t\t\t\tconst innerOperands: (Input.OptionalWhere | boolean)[] = []\n\t\t\t\tfor (const innerValue of value as readonly Input.OptionalWhere[]) {\n\t\t\t\t\tconst innerOperand = this.optimizeWhere(innerValue, entity, relationPath)\n\t\t\t\t\tif (innerOperand === false) {\n\t\t\t\t\t\treturn false\n\t\t\t\t\t}\n\t\t\t\t\tinnerOperands.push(innerOperand)\n\t\t\t\t}\n\t\t\t\toperand = this.optimizeAnd(innerOperands, entity, relationPath)\n\t\t\t} else if (key === 'or') {\n\t\t\t\tconst innerOperands: (Input.OptionalWhere | boolean)[] = []\n\t\t\t\tfor (const innerValue of value as readonly Input.OptionalWhere[]) {\n\t\t\t\t\tconst innerOperand = this.optimizeWhere(innerValue, entity, relationPath)\n\t\t\t\t\tif (innerOperand === true) {\n\t\t\t\t\t\toperand = true\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tinnerOperands.push(innerOperand)\n\t\t\t\t}\n\t\t\t\tif (operand !== true) {\n\t\t\t\t\toperand = this.optimizeOr(innerOperands, entity, relationPath)\n\t\t\t\t}\n\t\t\t} else if (key === 'not') {\n\t\t\t\toperand = optimizeNot(this.optimizeWhere(value as Input.OptionalWhere, entity, relationPath))\n\t\t\t} else if (key === MASKED_CELL_KEY) {\n\t\t\t\toperand = this.optimizeAnd(parseMaskedCells(value).map(cell => this.optimizeMaskedCell(cell, entity, relationPath)), entity, relationPath)\n\t\t\t} else {\n\t\t\t\toperand = this.resolveFieldValue(entity, key, value, relationPath)\n\t\t\t}\n\n\t\t\tif (operand === false) {\n\t\t\t\treturn false\n\t\t\t} else if (operand !== undefined) {\n\t\t\t\toperands.push(operand)\n\t\t\t}\n\t\t}\n\t\treturn this.optimizeAnd(operands, entity, relationPath)\n\t}\n\n\t/**\n\t * Replaces `facts`, known to hold on the row, inside the read guards of `where` (field guards of its relations\n\t * and masked-cell guards; a guard reads the same row), and follows them into its to-one relation hops. Only the\n\t * guards are re-optimized, so the user's condition keeps the shape it was optimized into.\n\t */\n\tprivate simplifyGuards(\n\t\twhere: Input.OptionalWhere,\n\t\tfacts: readonly Input.OptionalWhere[],\n\t\tentity: Model.Entity,\n\t\trelationPath: ExtendedRelationContext[],\n\t): Input.OptionalWhere {\n\t\tconst simplifyGuard = (guard: Input.OptionalWhere): Input.OptionalWhere | boolean | undefined => {\n\t\t\tconst replaced = this.replaceFacts(guard, facts, entity)\n\t\t\treturn replaced === guard ? undefined : this.optimizeWhere(replaced, entity, relationPath)\n\t\t}\n\t\tconst asWhere = (guard: Input.OptionalWhere | boolean): Input.OptionalWhere =>\n\t\t\ttypeof guard === 'boolean' ? { [entity.primary]: { [guard ? 'always' : 'never']: true } } : guard\n\t\tlet result: Writable<Input.OptionalWhere> = where\n\t\tconst write = (key: string, value: Input.OptionalWhere[string]) => {\n\t\t\tif (result === where) {\n\t\t\t\tresult = { ...where }\n\t\t\t}\n\t\t\tresult[key] = value\n\t\t}\n\t\tconst readableCells: Input.OptionalWhere[] = []\n\t\tfor (const key in where) {\n\t\t\tconst value = where[key]\n\t\t\tif ((key === 'and' || key === 'or') && Array.isArray(value)) {\n\t\t\t\tconst operands: readonly Input.OptionalWhere[] = value\n\t\t\t\tconst simplified = operands.map(it => this.simplifyGuards(it, facts, entity, relationPath))\n\t\t\t\tif (simplified.some((it, index) => it !== operands[index])) {\n\t\t\t\t\twrite(key, simplified)\n\t\t\t\t}\n\t\t\t} else if (key === 'not' && isWhere(value)) {\n\t\t\t\tconst simplified = this.simplifyGuards(value, facts, entity, relationPath)\n\t\t\t\tif (simplified !== value) {\n\t\t\t\t\twrite(key, simplified)\n\t\t\t\t}\n\t\t\t} else if (key === MASKED_CELL_KEY) {\n\t\t\t\tconst cells = parseMaskedCells(value).map(cell => ({ cell, guard: simplifyGuard(cell.guard) }))\n\t\t\t\tif (cells.every(it => it.guard === undefined)) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\t// A cell whose guard always holds reads its plain value.\n\t\t\t\treadableCells.push(...cells.filter(it => it.guard === true).map(it => it.cell.where))\n\t\t\t\twrite(\n\t\t\t\t\tkey,\n\t\t\t\t\tcells\n\t\t\t\t\t\t.filter(it => it.guard !== true)\n\t\t\t\t\t\t.map(({ cell, guard }) => guard === undefined ? cell : { guard: asWhere(guard), where: cell.where }),\n\t\t\t\t)\n\t\t\t} else if (isWhere(value)) {\n\t\t\t\tconst { fieldGuard, where: relationWhere } = splitFieldGuard(value)\n\t\t\t\tconst guard = fieldGuard === undefined ? undefined : simplifyGuard(fieldGuard)\n\t\t\t\tconst hopWhere = this.simplifyHopGuards(relationWhere, facts, entity, key)\n\t\t\t\tif (guard === true) {\n\t\t\t\t\twrite(key, hopWhere)\n\t\t\t\t} else if (guard !== undefined) {\n\t\t\t\t\twrite(key, { ...hopWhere, [FIELD_GUARD_KEY]: asWhere(guard) })\n\t\t\t\t} else if (hopWhere !== relationWhere) {\n\t\t\t\t\twrite(key, fieldGuard === undefined ? hopWhere : { ...hopWhere, [FIELD_GUARD_KEY]: fieldGuard })\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (readableCells.length === 0) {\n\t\t\treturn result\n\t\t}\n\t\tconst { [MASKED_CELL_KEY]: maskedCells, and, ...rest } = result\n\t\tconst operands = [...(Array.isArray(and) ? and : []), ...readableCells]\n\t\tconst masked = Array.isArray(maskedCells) && maskedCells.length > 0 ? { [MASKED_CELL_KEY]: maskedCells } : {}\n\t\tif (operands.length === 1 && Object.keys(rest).length === 0 && Object.keys(masked).length === 0) {\n\t\t\treturn operands[0]\n\t\t}\n\t\treturn { ...rest, and: operands, ...masked }\n\t}\n\n\t/**\n\t * Follows the facts into a to-one relation hop. Its read guard is dropped when the facts imply it, so the hop\n\t * shares the plain join of an ACL predicate through the same relation instead of joining a guarded source.\n\t */\n\tprivate simplifyHopGuards(\n\t\twhere: Input.OptionalWhere,\n\t\tfacts: readonly Input.OptionalWhere[],\n\t\tentity: Model.Entity,\n\t\trelationName: string,\n\t): Input.OptionalWhere {\n\t\tconst target = this.getToOneTarget(entity, relationName)\n\t\tconst targetFacts = target === undefined ? [] : this.factsThroughRelation(facts, entity, relationName)\n\t\tif (target === undefined || targetFacts.length === 0) {\n\t\t\treturn where\n\t\t}\n\t\tconst { [READ_GUARD_KEY]: readGuard, ...rest } = where\n\t\tconst simplified = this.simplifyGuards(rest, targetFacts, target, [])\n\t\tconst keepsGuard = isWhere(readGuard) && !this.isImpliedByOptimizedFacts(readGuard, target, targetFacts)\n\t\tif (keepsGuard) {\n\t\t\treturn simplified === rest ? where : { ...simplified, [READ_GUARD_KEY]: readGuard }\n\t\t}\n\t\treturn readGuard === undefined && simplified === rest ? where : simplified\n\t}\n\n\t/** Guard and condition are optimized apart: the masked form depends on the condition alone. */\n\tprivate optimizeMaskedCell(masked: MaskedCell, entity: Model.Entity, relationPath: ExtendedRelationContext[]): Input.OptionalWhere | boolean {\n\t\tconst where = this.optimizeWhere(masked.where, entity, relationPath)\n\t\tconst guard = this.optimizeWhere(masked.guard, entity, relationPath)\n\t\tif (typeof where === 'boolean' || guard === true || (typeof guard !== 'boolean' && Object.keys(guard).length === 0)) {\n\t\t\treturn where\n\t\t}\n\t\treturn { [MASKED_CELL_KEY]: [{ guard: guard === false ? { [entity.primary]: { never: true } } : guard, where }] }\n\t}\n\n\tprivate optimizeOr(\n\t\toperands: readonly OptimizedOperand[],\n\t\tentity: Model.Entity,\n\t\trelationPath: ExtendedRelationContext[],\n\t): Input.OptionalWhere | boolean {\n\t\tconst optimized = optimizeOr(operands)\n\t\tif (typeof optimized === 'boolean' || !Array.isArray(optimized.or)) {\n\t\t\treturn optimized\n\t\t}\n\t\tconst result = this.crossOptimize(optimized.or, entity, { never: true }, relationPath)\n\t\tif (result === optimized.or) {\n\t\t\treturn optimized\n\t\t}\n\t\treturn optimizeOr(result)\n\t}\n\n\tprivate optimizeAnd(\n\t\toperands: readonly OptimizedOperand[],\n\t\tentity: Model.Entity,\n\t\trelationPath: ExtendedRelationContext[],\n\t): Input.OptionalWhere | boolean {\n\t\tconst optimized = optimizeAnd(operands)\n\t\tif (typeof optimized === 'boolean' || !Array.isArray(optimized.and)) {\n\t\t\treturn optimized\n\t\t}\n\t\tconst result = this.crossOptimize(optimized.and, entity, { always: true }, relationPath)\n\t\tif (result === optimized.and) {\n\t\t\treturn optimized\n\t\t}\n\t\treturn optimizeAnd(result)\n\t}\n\n\tprivate crossOptimize(\n\t\toperands: Input.OptionalWhere[],\n\t\tentity: Model.Entity,\n\t\treplacement: Input.Condition,\n\t\trelationPath: ExtendedRelationContext[],\n\t): (Input.OptionalWhere | boolean)[] {\n\t\tlet result: (Input.OptionalWhere | boolean)[] = operands\n\t\tlet copied = false\n\t\tconst count = Math.min(result.length, this.options?.maxCrossOptimizationInput ?? 50)\n\t\tfor (let i = 0; i < count; i++) {\n\t\t\tfor (let j = 0; j < count; j++) {\n\t\t\t\tconst a = result[j]\n\t\t\t\tconst b = result[i]\n\t\t\t\tif (i !== j && typeof a !== 'boolean' && typeof b !== 'boolean') {\n\t\t\t\t\tconst elResult = replaceWhere(a, b, { [entity.primary]: replacement }, {\n\t\t\t\t\t\treplaceSubOperands: true,\n\t\t\t\t\t})\n\t\t\t\t\tif (elResult !== a) {\n\t\t\t\t\t\tif (!copied) {\n\t\t\t\t\t\t\tresult = [...result]\n\t\t\t\t\t\t\tcopied = true\n\t\t\t\t\t\t}\n\t\t\t\t\t\tresult[j] = this.optimizeWhere(elResult, entity, relationPath)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn result\n\t}\n\n\tprivate resolveFieldValue(entity: Model.Entity, key: string, value: Input.OptionalWhere[string], relationPath: ExtendedRelationContext[]) {\n\t\treturn acceptFieldVisitor<Input.OptionalWhere | boolean>(this.model, entity, key, {\n\t\t\tvisitColumn: () => {\n\t\t\t\tconst optimizedCondition = this.conditionOptimizer.optimize(value as Input.Condition)\n\n\t\t\t\tif (typeof optimizedCondition === 'boolean') {\n\t\t\t\t\treturn optimizedCondition\n\t\t\t\t}\n\n\t\t\t\treturn { [key]: optimizedCondition }\n\t\t\t},\n\t\t\tvisitRelation: context => {\n\t\t\t\t// The field guard is a where over this (source) entity, so it is optimized here, not with the target.\n\t\t\t\tconst { fieldGuard: rawFieldGuard, where: relationWhere } = splitFieldGuard(value as Input.OptionalWhere)\n\t\t\t\tconst fieldGuard = rawFieldGuard === undefined ? true : this.optimizeWhere(rawFieldGuard, entity, relationPath)\n\t\t\t\tlet where: Input.OptionalWhere = relationWhere\n\t\t\t\tconst newRelationPath: ExtendedRelationContext[] = [...relationPath]\n\t\t\t\tconst length = relationPath.length\n\t\t\t\tif (length > 0 && relationPath[length - 1].context.targetRelation?.name === context.relation.name) {\n\t\t\t\t\tconst item = newRelationPath.pop()\n\t\t\t\t\tconst type = item!.context.type\n\t\t\t\t\tif (item?.canEliminate && (type === 'oneHasMany' || type === 'oneHasOneOwning' || type === 'oneHasOneInverse')) {\n\t\t\t\t\t\twhere = replaceWhere(where, { [context.targetEntity.primary]: { isNull: true } }, { [context.targetEntity.primary]: { never: true } })\n\t\t\t\t\t\twhere = replaceWhere(where, { [context.targetEntity.primary]: { isNull: false } }, { [context.targetEntity.primary]: { always: true } })\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// first level relation - we are sure root exists\n\t\t\t\t\tconst canEliminate = length === 0 || relationPath[length - 1].isLast\n\t\t\t\t\tnewRelationPath.push({ context, isLast: false, canEliminate })\n\t\t\t\t}\n\t\t\t\tconst optimizedWhere = this.optimizeWhere(where, context.targetEntity, newRelationPath)\n\n\t\t\t\tif (typeof optimizedWhere === 'boolean') {\n\t\t\t\t\treturn optimizedWhere\n\t\t\t\t}\n\t\t\t\tif (fieldGuard === true || (fieldGuard !== false && Object.keys(fieldGuard).length === 0)) {\n\t\t\t\t\treturn { [key]: optimizedWhere }\n\t\t\t\t}\n\t\t\t\tconst fieldGuardWhere = fieldGuard === false ? { [entity.primary]: { never: true } } : fieldGuard\n\t\t\t\treturn { [key]: { ...optimizedWhere, [FIELD_GUARD_KEY]: fieldGuardWhere } }\n\t\t\t},\n\t\t})\n\t}\n}\n\nconst guardKeys = new Set<string>([READ_GUARD_KEY, FIELD_GUARD_KEY, MASKED_CELL_KEY])\n\nconst hasGuards = (value: unknown): boolean => {\n\tif (Array.isArray(value)) {\n\t\treturn value.some(hasGuards)\n\t}\n\tif (value === null || typeof value !== 'object') {\n\t\treturn false\n\t}\n\treturn Object.entries(value).some(([key, item]) => guardKeys.has(key) || hasGuards(item))\n}\n\n/** A guarded where tells nothing about the plain rows a guard reads (an unreadable row reads as absent there). */\nconst isUsableFact = (fact: Input.OptionalWhere): boolean => Object.keys(fact).length > 0 && !hasGuards(fact)\n"],"names":["_WhereOptimizer","operands"],"mappings":";;;;;;;;;AAmCO,MAAM,kBAAN,MAAMA,iBAAe;AAAA,EAG3B,YACkB,OACA,oBACA,SAChB;AAHgB,SAAA,QAAA;AACA,SAAA,qBAAA;AACA,SAAA,UAAA;AAAA,EAElB;AAAA,EAEO,SACN,OACA,QACA,EAAE,eAAe,CAAA,GAAI,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AACvF,eAAO,EAAE,CAAC,GAAG,GAAG,EAAE,GAAG,gBAAgB,CAAC,eAAe,GAAG,kBAAgB;AAAA,MACzE;AAAA,IAAA,CACA;AAAA,EACF;AACD;AAvbC,cADY,iBACG,uBAAsB,oBAAI,IAAsC,CAAC,cAAc,oBAAoB,iBAAiB,CAAC,CAAA;AAD9H,IAAM,iBAAN;AA0bP,MAAM,YAAY,oBAAI,IAAY,CAAC,gBAAgB,iBAAiB,eAAe,CAAC;AAEpF,MAAM,YAAY,CAAC,UAA4B;AAC9C,MAAI,MAAM,QAAQ,KAAK,GAAG;AACzB,WAAO,MAAM,KAAK,SAAS;AAAA,EAC5B;AACA,MAAI,UAAU,QAAQ,OAAO,UAAU,UAAU;AAChD,WAAO;AAAA,EACR;AACA,SAAO,OAAO,QAAQ,KAAK,EAAE,KAAK,CAAC,CAAC,KAAK,IAAI,MAAM,UAAU,IAAI,GAAG,KAAK,UAAU,IAAI,CAAC;AACzF;AAGA,MAAM,eAAe,CAAC,SAAuC,OAAO,KAAK,IAAI,EAAE,SAAS,KAAK,CAAC,UAAU,IAAI;"}
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const deepEqual = require("fast-deep-equal");
3
+ const utilities = require("@contember/utilities");
4
4
  const replaceWhere = (subject, find, replace, opts = {}) => {
5
- if (deepEqual(subject, find)) {
5
+ if (utilities.deepEqual(subject, find)) {
6
6
  return replace;
7
7
  }
8
8
  let result = subject;
@@ -48,7 +48,7 @@ const containsAllOperands = (subjectOperands, findOperands) => {
48
48
  for (const op1 of findOperands) {
49
49
  let found = false;
50
50
  for (const op2 of subjectOperands) {
51
- if (deepEqual(op1, op2)) {
51
+ if (utilities.deepEqual(op1, op2)) {
52
52
  found = true;
53
53
  break;
54
54
  }
@@ -1 +1 @@
1
- {"version":3,"file":"WhereReplacer.cjs","sources":["../../../../../../../packages/engine-content-api/src/mapper/select/optimizer/WhereReplacer.ts"],"sourcesContent":["import { Input, Writable } from '@contember/schema'\nimport deepEqual from 'fast-deep-equal'\n\nexport const replaceWhere = (\n\tsubject: Input.OptionalWhere,\n\tfind: Input.OptionalWhere,\n\treplace: Input.OptionalWhere,\n\topts: { replaceSubOperands?: boolean } = {},\n): Input.OptionalWhere => {\n\tif (deepEqual(subject, find)) {\n\t\treturn replace\n\t}\n\tlet result: Writable<Input.OptionalWhere> = subject\n\tlet copied = false\n\t// copy on write to preserve referential integrity, when nothing has changed\n\tconst write = <T extends string>(key: T, value: Input.OptionalWhere[T]) => {\n\t\tif (!copied) {\n\t\t\tresult = { ...result }\n\t\t\tcopied = true\n\t\t}\n\t\tresult[key] = value\n\t}\n\n\tfor (const key in subject) {\n\t\tconst value = subject[key]\n\t\tif (key === 'not') {\n\t\t\tconst newNot = replaceWhere(value as Input.OptionalWhere, find, replace, opts)\n\t\t\tif (newNot !== value) {\n\t\t\t\twrite('not', newNot)\n\t\t\t}\n\t\t} else if (key === 'and' || key === 'or') {\n\t\t\tconst operands = value as Input.OptionalWhere[]\n\t\t\tconst subOperandsToFind = opts.replaceSubOperands && Object.keys(find).length === 1 && find[key] ? (find[key] as Input.OptionalWhere[]) : null\n\t\t\tif (subOperandsToFind !== null && containsAllOperands(operands, subOperandsToFind)) {\n\t\t\t\twrite(key, [replace])\n\t\t\t} else {\n\t\t\t\tconst items: Input.OptionalWhere[] = []\n\t\t\t\tlet itemChanged = false\n\t\t\t\tfor (const el of operands) {\n\t\t\t\t\tconst newEl = replaceWhere(el, find, replace, opts)\n\t\t\t\t\tif (newEl !== el) {\n\t\t\t\t\t\titemChanged = true\n\t\t\t\t\t}\n\t\t\t\t\titems.push(newEl)\n\t\t\t\t}\n\t\t\t\tif (itemChanged) {\n\t\t\t\t\twrite(key, items)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn result\n}\n\nconst containsAllOperands = (subjectOperands: Input.OptionalWhere[], findOperands: Input.OptionalWhere[]): boolean => {\n\tfor (const op1 of findOperands) {\n\t\tlet found = false\n\t\tfor (const op2 of subjectOperands) {\n\t\t\tif (deepEqual(op1, op2)) {\n\t\t\t\tfound = true\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tif (!found) {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}\n"],"names":[],"mappings":";;;AAGO,MAAM,eAAe,CAC3B,SACA,MACA,SACA,OAAyC,CAAA,MAChB;AACzB,MAAI,UAAU,SAAS,IAAI,GAAG;AAC7B,WAAO;AAAA,EACR;AACA,MAAI,SAAwC;AAC5C,MAAI,SAAS;AAEb,QAAM,QAAQ,CAAmB,KAAQ,UAAkC;AAC1E,QAAI,CAAC,QAAQ;AACZ,eAAS,EAAE,GAAG,OAAA;AACd,eAAS;AAAA,IACV;AACA,WAAO,GAAG,IAAI;AAAA,EACf;AAEA,aAAW,OAAO,SAAS;AAC1B,UAAM,QAAQ,QAAQ,GAAG;AACzB,QAAI,QAAQ,OAAO;AAClB,YAAM,SAAS,aAAa,OAA8B,MAAM,SAAS,IAAI;AAC7E,UAAI,WAAW,OAAO;AACrB,cAAM,OAAO,MAAM;AAAA,MACpB;AAAA,IACD,WAAW,QAAQ,SAAS,QAAQ,MAAM;AACzC,YAAM,WAAW;AACjB,YAAM,oBAAoB,KAAK,sBAAsB,OAAO,KAAK,IAAI,EAAE,WAAW,KAAK,KAAK,GAAG,IAAK,KAAK,GAAG,IAA8B;AAC1I,UAAI,sBAAsB,QAAQ,oBAAoB,UAAU,iBAAiB,GAAG;AACnF,cAAM,KAAK,CAAC,OAAO,CAAC;AAAA,MACrB,OAAO;AACN,cAAM,QAA+B,CAAA;AACrC,YAAI,cAAc;AAClB,mBAAW,MAAM,UAAU;AAC1B,gBAAM,QAAQ,aAAa,IAAI,MAAM,SAAS,IAAI;AAClD,cAAI,UAAU,IAAI;AACjB,0BAAc;AAAA,UACf;AACA,gBAAM,KAAK,KAAK;AAAA,QACjB;AACA,YAAI,aAAa;AAChB,gBAAM,KAAK,KAAK;AAAA,QACjB;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACA,SAAO;AACR;AAEA,MAAM,sBAAsB,CAAC,iBAAwC,iBAAiD;AACrH,aAAW,OAAO,cAAc;AAC/B,QAAI,QAAQ;AACZ,eAAW,OAAO,iBAAiB;AAClC,UAAI,UAAU,KAAK,GAAG,GAAG;AACxB,gBAAQ;AACR;AAAA,MACD;AAAA,IACD;AACA,QAAI,CAAC,OAAO;AACX,aAAO;AAAA,IACR;AAAA,EACD;AACA,SAAO;AACR;;"}
1
+ {"version":3,"file":"WhereReplacer.cjs","sources":["../../../../../../../packages/engine-content-api/src/mapper/select/optimizer/WhereReplacer.ts"],"sourcesContent":["import { Input, Writable } from '@contember/schema'\nimport { deepEqual } from '@contember/utilities'\n\nexport const replaceWhere = (\n\tsubject: Input.OptionalWhere,\n\tfind: Input.OptionalWhere,\n\treplace: Input.OptionalWhere,\n\topts: { replaceSubOperands?: boolean } = {},\n): Input.OptionalWhere => {\n\tif (deepEqual(subject, find)) {\n\t\treturn replace\n\t}\n\tlet result: Writable<Input.OptionalWhere> = subject\n\tlet copied = false\n\t// copy on write to preserve referential integrity, when nothing has changed\n\tconst write = <T extends string>(key: T, value: Input.OptionalWhere[T]) => {\n\t\tif (!copied) {\n\t\t\tresult = { ...result }\n\t\t\tcopied = true\n\t\t}\n\t\tresult[key] = value\n\t}\n\n\tfor (const key in subject) {\n\t\tconst value = subject[key]\n\t\tif (key === 'not') {\n\t\t\tconst newNot = replaceWhere(value as Input.OptionalWhere, find, replace, opts)\n\t\t\tif (newNot !== value) {\n\t\t\t\twrite('not', newNot)\n\t\t\t}\n\t\t} else if (key === 'and' || key === 'or') {\n\t\t\tconst operands = value as Input.OptionalWhere[]\n\t\t\tconst subOperandsToFind = opts.replaceSubOperands && Object.keys(find).length === 1 && find[key] ? (find[key] as Input.OptionalWhere[]) : null\n\t\t\tif (subOperandsToFind !== null && containsAllOperands(operands, subOperandsToFind)) {\n\t\t\t\twrite(key, [replace])\n\t\t\t} else {\n\t\t\t\tconst items: Input.OptionalWhere[] = []\n\t\t\t\tlet itemChanged = false\n\t\t\t\tfor (const el of operands) {\n\t\t\t\t\tconst newEl = replaceWhere(el, find, replace, opts)\n\t\t\t\t\tif (newEl !== el) {\n\t\t\t\t\t\titemChanged = true\n\t\t\t\t\t}\n\t\t\t\t\titems.push(newEl)\n\t\t\t\t}\n\t\t\t\tif (itemChanged) {\n\t\t\t\t\twrite(key, items)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn result\n}\n\nconst containsAllOperands = (subjectOperands: Input.OptionalWhere[], findOperands: Input.OptionalWhere[]): boolean => {\n\tfor (const op1 of findOperands) {\n\t\tlet found = false\n\t\tfor (const op2 of subjectOperands) {\n\t\t\tif (deepEqual(op1, op2)) {\n\t\t\t\tfound = true\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tif (!found) {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}\n"],"names":["deepEqual"],"mappings":";;;AAGO,MAAM,eAAe,CAC3B,SACA,MACA,SACA,OAAyC,CAAA,MAChB;AACzB,MAAIA,UAAAA,UAAU,SAAS,IAAI,GAAG;AAC7B,WAAO;AAAA,EACR;AACA,MAAI,SAAwC;AAC5C,MAAI,SAAS;AAEb,QAAM,QAAQ,CAAmB,KAAQ,UAAkC;AAC1E,QAAI,CAAC,QAAQ;AACZ,eAAS,EAAE,GAAG,OAAA;AACd,eAAS;AAAA,IACV;AACA,WAAO,GAAG,IAAI;AAAA,EACf;AAEA,aAAW,OAAO,SAAS;AAC1B,UAAM,QAAQ,QAAQ,GAAG;AACzB,QAAI,QAAQ,OAAO;AAClB,YAAM,SAAS,aAAa,OAA8B,MAAM,SAAS,IAAI;AAC7E,UAAI,WAAW,OAAO;AACrB,cAAM,OAAO,MAAM;AAAA,MACpB;AAAA,IACD,WAAW,QAAQ,SAAS,QAAQ,MAAM;AACzC,YAAM,WAAW;AACjB,YAAM,oBAAoB,KAAK,sBAAsB,OAAO,KAAK,IAAI,EAAE,WAAW,KAAK,KAAK,GAAG,IAAK,KAAK,GAAG,IAA8B;AAC1I,UAAI,sBAAsB,QAAQ,oBAAoB,UAAU,iBAAiB,GAAG;AACnF,cAAM,KAAK,CAAC,OAAO,CAAC;AAAA,MACrB,OAAO;AACN,cAAM,QAA+B,CAAA;AACrC,YAAI,cAAc;AAClB,mBAAW,MAAM,UAAU;AAC1B,gBAAM,QAAQ,aAAa,IAAI,MAAM,SAAS,IAAI;AAClD,cAAI,UAAU,IAAI;AACjB,0BAAc;AAAA,UACf;AACA,gBAAM,KAAK,KAAK;AAAA,QACjB;AACA,YAAI,aAAa;AAChB,gBAAM,KAAK,KAAK;AAAA,QACjB;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACA,SAAO;AACR;AAEA,MAAM,sBAAsB,CAAC,iBAAwC,iBAAiD;AACrH,aAAW,OAAO,cAAc;AAC/B,QAAI,QAAQ;AACZ,eAAW,OAAO,iBAAiB;AAClC,UAAIA,UAAAA,UAAU,KAAK,GAAG,GAAG;AACxB,gBAAQ;AACR;AAAA,MACD;AAAA,IACD;AACA,QAAI,CAAC,OAAO;AACX,aAAO;AAAA,IACR;AAAA,EACD;AACA,SAAO;AACR;;"}
@@ -1,4 +1,4 @@
1
- import deepEqual from "fast-deep-equal";
1
+ import { deepEqual } from "@contember/utilities";
2
2
  const replaceWhere = (subject, find, replace, opts = {}) => {
3
3
  if (deepEqual(subject, find)) {
4
4
  return replace;
@@ -1 +1 @@
1
- {"version":3,"file":"WhereReplacer.js","sources":["../../../../../../../packages/engine-content-api/src/mapper/select/optimizer/WhereReplacer.ts"],"sourcesContent":["import { Input, Writable } from '@contember/schema'\nimport deepEqual from 'fast-deep-equal'\n\nexport const replaceWhere = (\n\tsubject: Input.OptionalWhere,\n\tfind: Input.OptionalWhere,\n\treplace: Input.OptionalWhere,\n\topts: { replaceSubOperands?: boolean } = {},\n): Input.OptionalWhere => {\n\tif (deepEqual(subject, find)) {\n\t\treturn replace\n\t}\n\tlet result: Writable<Input.OptionalWhere> = subject\n\tlet copied = false\n\t// copy on write to preserve referential integrity, when nothing has changed\n\tconst write = <T extends string>(key: T, value: Input.OptionalWhere[T]) => {\n\t\tif (!copied) {\n\t\t\tresult = { ...result }\n\t\t\tcopied = true\n\t\t}\n\t\tresult[key] = value\n\t}\n\n\tfor (const key in subject) {\n\t\tconst value = subject[key]\n\t\tif (key === 'not') {\n\t\t\tconst newNot = replaceWhere(value as Input.OptionalWhere, find, replace, opts)\n\t\t\tif (newNot !== value) {\n\t\t\t\twrite('not', newNot)\n\t\t\t}\n\t\t} else if (key === 'and' || key === 'or') {\n\t\t\tconst operands = value as Input.OptionalWhere[]\n\t\t\tconst subOperandsToFind = opts.replaceSubOperands && Object.keys(find).length === 1 && find[key] ? (find[key] as Input.OptionalWhere[]) : null\n\t\t\tif (subOperandsToFind !== null && containsAllOperands(operands, subOperandsToFind)) {\n\t\t\t\twrite(key, [replace])\n\t\t\t} else {\n\t\t\t\tconst items: Input.OptionalWhere[] = []\n\t\t\t\tlet itemChanged = false\n\t\t\t\tfor (const el of operands) {\n\t\t\t\t\tconst newEl = replaceWhere(el, find, replace, opts)\n\t\t\t\t\tif (newEl !== el) {\n\t\t\t\t\t\titemChanged = true\n\t\t\t\t\t}\n\t\t\t\t\titems.push(newEl)\n\t\t\t\t}\n\t\t\t\tif (itemChanged) {\n\t\t\t\t\twrite(key, items)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn result\n}\n\nconst containsAllOperands = (subjectOperands: Input.OptionalWhere[], findOperands: Input.OptionalWhere[]): boolean => {\n\tfor (const op1 of findOperands) {\n\t\tlet found = false\n\t\tfor (const op2 of subjectOperands) {\n\t\t\tif (deepEqual(op1, op2)) {\n\t\t\t\tfound = true\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tif (!found) {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}\n"],"names":[],"mappings":";AAGO,MAAM,eAAe,C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Q;AACR;AAAA,MACD;AAAA,IACD;AACA,QAAI,CAAC,OAAO;AACX,aAAO;AAAA,IACR;AAAA,EACD;AACA,SAAO;AACR;"}
1
+ {"version":3,"file":"WhereReplacer.js","sources":["../../../../../../../packages/engine-content-api/src/mapper/select/optimizer/WhereReplacer.ts"],"sourcesContent":["import { Input, Writable } from '@contember/schema'\nimport { deepEqual } from '@contember/utilities'\n\nexport const replaceWhere = (\n\tsubject: Input.OptionalWhere,\n\tfind: Input.OptionalWhere,\n\treplace: Input.OptionalWhere,\n\topts: { replaceSubOperands?: boolean } = {},\n): Input.OptionalWhere => {\n\tif (deepEqual(subject, find)) {\n\t\treturn replace\n\t}\n\tlet result: Writable<Input.OptionalWhere> = subject\n\tlet copied = false\n\t// copy on write to preserve referential integrity, when nothing has changed\n\tconst write = <T extends string>(key: T, value: Input.OptionalWhere[T]) => {\n\t\tif (!copied) {\n\t\t\tresult = { ...result }\n\t\t\tcopied = true\n\t\t}\n\t\tresult[key] = value\n\t}\n\n\tfor (const key in subject) {\n\t\tconst value = subject[key]\n\t\tif (key === 'not') {\n\t\t\tconst newNot = replaceWhere(value as Input.OptionalWhere, find, replace, opts)\n\t\t\tif (newNot !== value) {\n\t\t\t\twrite('not', newNot)\n\t\t\t}\n\t\t} else if (key === 'and' || key === 'or') {\n\t\t\tconst operands = value as Input.OptionalWhere[]\n\t\t\tconst subOperandsToFind = opts.replaceSubOperands && Object.keys(find).length === 1 && find[key] ? (find[key] as Input.OptionalWhere[]) : null\n\t\t\tif (subOperandsToFind !== null && containsAllOperands(operands, subOperandsToFind)) {\n\t\t\t\twrite(key, [replace])\n\t\t\t} else {\n\t\t\t\tconst items: Input.OptionalWhere[] = []\n\t\t\t\tlet itemChanged = false\n\t\t\t\tfor (const el of operands) {\n\t\t\t\t\tconst newEl = replaceWhere(el, find, replace, opts)\n\t\t\t\t\tif (newEl !== el) {\n\t\t\t\t\t\titemChanged = true\n\t\t\t\t\t}\n\t\t\t\t\titems.push(newEl)\n\t\t\t\t}\n\t\t\t\tif (itemChanged) {\n\t\t\t\t\twrite(key, items)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn result\n}\n\nconst containsAllOperands = (subjectOperands: Input.OptionalWhere[], findOperands: Input.OptionalWhere[]): boolean => {\n\tfor (const op1 of findOperands) {\n\t\tlet found = false\n\t\tfor (const op2 of subjectOperands) {\n\t\t\tif (deepEqual(op1, op2)) {\n\t\t\t\tfound = true\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tif (!found) {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}\n"],"names":[],"mappings":";AAGO,MAAM,eAAe,CAC3B,SACA,MACA,SACA,OAAyC,CAAA,MAChB;AACzB,MAAI,UAAU,SAAS,IAAI,GAAG;AAC7B,WAAO;AAAA,EACR;AACA,MAAI,SAAwC;AAC5C,MAAI,SAAS;AAEb,QAAM,QAAQ,CAAmB,KAAQ,UAAkC;AAC1E,QAAI,CAAC,QAAQ;AACZ,eAAS,EAAE,GAAG,OAAA;AACd,eAAS;AAAA,IACV;AACA,WAAO,GAAG,IAAI;AAAA,EACf;AAEA,aAAW,OAAO,SAAS;AAC1B,UAAM,QAAQ,QAAQ,GAAG;AACzB,QAAI,QAAQ,OAAO;AAClB,YAAM,SAAS,aAAa,OAA8B,MAAM,SAAS,IAAI;AAC7E,UAAI,WAAW,OAAO;AACrB,cAAM,OAAO,MAAM;AAAA,MACpB;AAAA,IACD,WAAW,QAAQ,SAAS,QAAQ,MAAM;AACzC,YAAM,WAAW;AACjB,YAAM,oBAAoB,KAAK,sBAAsB,OAAO,KAAK,IAAI,EAAE,WAAW,KAAK,KAAK,GAAG,IAAK,KAAK,GAAG,IAA8B;AAC1I,UAAI,sBAAsB,QAAQ,oBAAoB,UAAU,iBAAiB,GAAG;AACnF,cAAM,KAAK,CAAC,OAAO,CAAC;AAAA,MACrB,OAAO;AACN,cAAM,QAA+B,CAAA;AACrC,YAAI,cAAc;AAClB,mBAAW,MAAM,UAAU;AAC1B,gBAAM,QAAQ,aAAa,IAAI,MAAM,SAAS,IAAI;AAClD,cAAI,UAAU,IAAI;AACjB,0BAAc;AAAA,UACf;AACA,gBAAM,KAAK,KAAK;AAAA,QACjB;AACA,YAAI,aAAa;AAChB,gBAAM,KAAK,KAAK;AAAA,QACjB;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACA,SAAO;AACR;AAEA,MAAM,sBAAsB,CAAC,iBAAwC,iBAAiD;AACrH,aAAW,OAAO,cAAc;AAC/B,QAAI,QAAQ;AACZ,eAAW,OAAO,iBAAiB;AAClC,UAAI,UAAU,KAAK,GAAG,GAAG;AACxB,gBAAQ;AACR;AAAA,MACD;AAAA,IACD;AACA,QAAI,CAAC,OAAO;AACX,aAAO;AAAA,IACR;AAAA,EACD;AACA,SAAO;AACR;"}
@@ -28,7 +28,8 @@ class SqlUpdateInputProcessor {
28
28
  update: MutationProcessorHelper.hasManyProcessor((ctx) => this.manyHasManyUpdateInputProcessor.update(ctx)),
29
29
  upsert: MutationProcessorHelper.hasManyProcessor((ctx) => this.manyHasManyUpdateInputProcessor.upsert(ctx)),
30
30
  delete: MutationProcessorHelper.hasManyProcessor((ctx) => this.manyHasManyUpdateInputProcessor.delete(ctx)),
31
- disconnect: MutationProcessorHelper.hasManyProcessor((ctx) => this.manyHasManyUpdateInputProcessor.disconnect(ctx))
31
+ disconnect: MutationProcessorHelper.hasManyProcessor((ctx) => this.manyHasManyUpdateInputProcessor.disconnect(ctx)),
32
+ set: MutationProcessorHelper.relationFieldProcessor((ctx) => this.manyHasManyUpdateInputProcessor.set(ctx))
32
33
  });
33
34
  __publicField(this, "manyHasManyOwning", {
34
35
  connect: MutationProcessorHelper.hasManyProcessor((ctx) => this.manyHasManyUpdateInputProcessor.connect(ctx)),
@@ -37,7 +38,8 @@ class SqlUpdateInputProcessor {
37
38
  update: MutationProcessorHelper.hasManyProcessor((ctx) => this.manyHasManyUpdateInputProcessor.update(ctx)),
38
39
  upsert: MutationProcessorHelper.hasManyProcessor((ctx) => this.manyHasManyUpdateInputProcessor.upsert(ctx)),
39
40
  delete: MutationProcessorHelper.hasManyProcessor((ctx) => this.manyHasManyUpdateInputProcessor.delete(ctx)),
40
- disconnect: MutationProcessorHelper.hasManyProcessor((ctx) => this.manyHasManyUpdateInputProcessor.disconnect(ctx))
41
+ disconnect: MutationProcessorHelper.hasManyProcessor((ctx) => this.manyHasManyUpdateInputProcessor.disconnect(ctx)),
42
+ set: MutationProcessorHelper.relationFieldProcessor((ctx) => this.manyHasManyUpdateInputProcessor.set(ctx))
41
43
  });
42
44
  __publicField(this, "manyHasOne", {
43
45
  connect: MutationProcessorHelper.hasOneProcessor((ctx) => this.manyHasOneUpdateInputProcessor.connect(ctx)),
@@ -55,7 +57,8 @@ class SqlUpdateInputProcessor {
55
57
  update: MutationProcessorHelper.hasManyProcessor((ctx) => this.oneHasManyUpdateInputProcessor.update(ctx)),
56
58
  upsert: MutationProcessorHelper.hasManyProcessor((ctx) => this.oneHasManyUpdateInputProcessor.upsert(ctx)),
57
59
  delete: MutationProcessorHelper.hasManyProcessor((ctx) => this.oneHasManyUpdateInputProcessor.delete(ctx)),
58
- disconnect: MutationProcessorHelper.hasManyProcessor((ctx) => this.oneHasManyUpdateInputProcessor.disconnect(ctx))
60
+ disconnect: MutationProcessorHelper.hasManyProcessor((ctx) => this.oneHasManyUpdateInputProcessor.disconnect(ctx)),
61
+ set: MutationProcessorHelper.relationFieldProcessor((ctx) => this.oneHasManyUpdateInputProcessor.set(ctx))
59
62
  });
60
63
  __publicField(this, "oneHasOneInverse", {
61
64
  connect: MutationProcessorHelper.hasOneProcessor((ctx) => this.oneHasOneInverseUpdateInputProcessor.connect(ctx)),
@@ -1 +1 @@
1
- {"version":3,"file":"SqlUpdateInputProcessor.cjs","sources":["../../../../../../packages/engine-content-api/src/mapper/update/SqlUpdateInputProcessor.ts"],"sourcesContent":["import { Input, Model, Value } from '@contember/schema'\nimport { Mapper } from '../Mapper.js'\nimport { UpdateBuilder } from './UpdateBuilder.js'\nimport { hasManyProcessor, hasOneProcessor } from '../MutationProcessorHelper.js'\nimport { OneHasOneInverseUpdateInputProcessor } from './relations/OneHasOneInverseUpdateInputProcessor.js'\nimport { OneHasOneOwningUpdateInputProcessor } from './relations/OneHasOneOwningUpdateInputProcessor.js'\nimport { OneHasManyUpdateInputProcessor } from './relations/OneHasManyUpdateInputProcessor.js'\nimport { ManyHasManyUpdateInputProcessor } from './relations/ManyHasManyUpdateInputProcessor.js'\nimport { UpdateInputProcessor } from '../../inputProcessing/index.js'\nimport { MutationResultList } from '../Result.js'\nimport { ManyHasOneUpdateInputProcessor } from './relations/ManyHasOneUpdateInputProcessor.js'\nimport { MapperInput } from '../types.js'\nimport { AclScope } from '../../acl/index.js'\n\nexport type SqlUpdateInputProcessorResult = MutationResultList | ((ctx: { primary: Input.PrimaryValue }) => Promise<MutationResultList>)\n\nexport class SqlUpdateInputProcessor implements UpdateInputProcessor<SqlUpdateInputProcessorResult> {\n\tprivate oneHasOneInverseUpdateInputProcessor: OneHasOneInverseUpdateInputProcessor\n\tprivate oneHasOneOwningUpdateInputProcessor: OneHasOneOwningUpdateInputProcessor\n\tprivate oneHasManyUpdateInputProcessor: OneHasManyUpdateInputProcessor\n\tprivate manyHasOneUpdateInputProcessor: ManyHasOneUpdateInputProcessor\n\tprivate manyHasManyUpdateInputProcessor: ManyHasManyUpdateInputProcessor\n\n\tconstructor(\n\t\tprivate readonly primaryValue: Input.PrimaryValue,\n\t\tprivate readonly data: MapperInput.UpdateDataInput,\n\t\tprivate readonly updateBuilder: UpdateBuilder,\n\t\tprivate readonly mapper: Mapper,\n\t\t/** Scope of the entity being updated; relation targets are always reached over a relation and stay nested. */\n\t\tprivate readonly scope: AclScope,\n\t) {\n\t\tthis.oneHasOneInverseUpdateInputProcessor = new OneHasOneInverseUpdateInputProcessor(this.primaryValue, this.mapper)\n\t\tthis.oneHasOneOwningUpdateInputProcessor = new OneHasOneOwningUpdateInputProcessor(this.primaryValue, this.mapper, this.updateBuilder)\n\t\tthis.oneHasManyUpdateInputProcessor = new OneHasManyUpdateInputProcessor(this.mapper)\n\t\tthis.manyHasOneUpdateInputProcessor = new ManyHasOneUpdateInputProcessor(this.mapper, this.updateBuilder, this.primaryValue)\n\t\tthis.manyHasManyUpdateInputProcessor = new ManyHasManyUpdateInputProcessor(this.mapper, this.scope, this.updateBuilder)\n\t}\n\n\tpublic column({ entity, column }: Model.ColumnContext) {\n\t\tif (this.data[column.name] !== undefined) {\n\t\t\tthis.updateBuilder.addFieldValue(column.name, this.data[column.name] as Value.AtomicValue)\n\t\t}\n\t\treturn Promise.resolve([])\n\t}\n\n\tmanyHasManyInverse: UpdateInputProcessor<SqlUpdateInputProcessorResult>['manyHasManyInverse'] = {\n\t\tconnect: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.connect(ctx)),\n\t\tcreate: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.connectOrCreate(ctx)),\n\t\tupdate: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.update(ctx)),\n\t\tupsert: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.upsert(ctx)),\n\t\tdelete: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.delete(ctx)),\n\t\tdisconnect: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.disconnect(ctx)),\n\t}\n\n\tmanyHasManyOwning: UpdateInputProcessor<SqlUpdateInputProcessorResult>['manyHasManyOwning'] = {\n\t\tconnect: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.connect(ctx)),\n\t\tcreate: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.connectOrCreate(ctx)),\n\t\tupdate: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.update(ctx)),\n\t\tupsert: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.upsert(ctx)),\n\t\tdelete: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.delete(ctx)),\n\t\tdisconnect: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.disconnect(ctx)),\n\t}\n\n\tmanyHasOne: UpdateInputProcessor<SqlUpdateInputProcessorResult>['manyHasOne'] = {\n\t\tconnect: hasOneProcessor(ctx => this.manyHasOneUpdateInputProcessor.connect(ctx)),\n\t\tcreate: hasOneProcessor(ctx => this.manyHasOneUpdateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasOneProcessor(ctx => this.manyHasOneUpdateInputProcessor.connectOrCreate(ctx)),\n\t\tupdate: hasOneProcessor(ctx => this.manyHasOneUpdateInputProcessor.update(ctx)),\n\t\tupsert: hasOneProcessor(ctx => this.manyHasOneUpdateInputProcessor.upsert(ctx)),\n\t\tdelete: hasOneProcessor(ctx => this.manyHasOneUpdateInputProcessor.delete(ctx)),\n\t\tdisconnect: hasOneProcessor(ctx => this.manyHasOneUpdateInputProcessor.disconnect(ctx)),\n\t}\n\n\toneHasMany: UpdateInputProcessor<SqlUpdateInputProcessorResult>['oneHasMany'] = {\n\t\tconnect: hasManyProcessor(ctx => this.oneHasManyUpdateInputProcessor.connect(ctx)),\n\t\tcreate: hasManyProcessor(ctx => this.oneHasManyUpdateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasManyProcessor(ctx => this.oneHasManyUpdateInputProcessor.connectOrCreate(ctx)),\n\t\tupdate: hasManyProcessor(ctx => this.oneHasManyUpdateInputProcessor.update(ctx)),\n\t\tupsert: hasManyProcessor(ctx => this.oneHasManyUpdateInputProcessor.upsert(ctx)),\n\t\tdelete: hasManyProcessor(ctx => this.oneHasManyUpdateInputProcessor.delete(ctx)),\n\t\tdisconnect: hasManyProcessor(ctx => this.oneHasManyUpdateInputProcessor.disconnect(ctx)),\n\t}\n\n\toneHasOneInverse: UpdateInputProcessor<SqlUpdateInputProcessorResult>['oneHasOneInverse'] = {\n\t\tconnect: hasOneProcessor(ctx => this.oneHasOneInverseUpdateInputProcessor.connect(ctx)),\n\t\tcreate: hasOneProcessor(ctx => this.oneHasOneInverseUpdateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasOneProcessor(ctx => this.oneHasOneInverseUpdateInputProcessor.connectOrCreate(ctx)),\n\t\tupdate: hasOneProcessor(ctx => this.oneHasOneInverseUpdateInputProcessor.update(ctx)),\n\t\tupsert: hasOneProcessor(ctx => this.oneHasOneInverseUpdateInputProcessor.upsert(ctx)),\n\t\tdelete: hasOneProcessor(ctx => this.oneHasOneInverseUpdateInputProcessor.delete(ctx)),\n\t\tdisconnect: hasOneProcessor(ctx => this.oneHasOneInverseUpdateInputProcessor.disconnect(ctx)),\n\t}\n\n\toneHasOneOwning: UpdateInputProcessor<SqlUpdateInputProcessorResult>['oneHasOneOwning'] = {\n\t\tconnect: hasOneProcessor(ctx => this.oneHasOneOwningUpdateInputProcessor.connect(ctx)),\n\t\tcreate: hasOneProcessor(ctx => this.oneHasOneOwningUpdateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasOneProcessor(ctx => this.oneHasOneOwningUpdateInputProcessor.connectOrCreate(ctx)),\n\t\tupdate: hasOneProcessor(ctx => this.oneHasOneOwningUpdateInputProcessor.update(ctx)),\n\t\tupsert: hasOneProcessor(ctx => this.oneHasOneOwningUpdateInputProcessor.upsert(ctx)),\n\t\tdelete: hasOneProcessor(ctx => this.oneHasOneOwningUpdateInputProcessor.delete(ctx)),\n\t\tdisconnect: hasOneProcessor(ctx => this.oneHasOneOwningUpdateInputProcessor.disconnect(ctx)),\n\t}\n}\n"],"names":["hasManyProcessor","hasOneProcessor","OneHasOneInverseUpdateInputProcessor","OneHasOneOwningUpdateInputProcessor","OneHasManyUpdateInputProcessor","ManyHasOneUpdateInputProcessor","ManyHasManyUpdateInputProcessor"],"mappings":";;;;;;;;;;;AAgBO,MAAM,wBAAuF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OAAO,GAAG,CAAC;AAAA,MACnF,QAAQA,wBAAAA,gBAAgB,CAAA,QAAO,KAAK,oCAAoC,OAAO,GAAG,CAAC;AAAA,MACnF,QAAQA,wBAAAA,gBAAgB,CAAA,QAAO,KAAK,oCAAoC,OAAO,GAAG,CAAC;AAAA,MACnF,YAAYA,wBAAAA,gBAAgB,CAAA,QAAO,KAAK,oCAAoC,WAAW,GAAG,CAAC;AAAA,IAAA,CAC5F;AAxEC,SAAK,uCAAuC,IAAIC,qCAAAA,qCAAqC,KAAK,cAAc,KAAK,MAAM;AACnH,SAAK,sCAAsC,IAAIC,oCAAAA,oCAAoC,KAAK,cAAc,KAAK,QAAQ,KAAK,aAAa;AACrI,SAAK,iCAAiC,IAAIC,8DAA+B,KAAK,MAAM;AACpF,SAAK,iCAAiC,IAAIC,+BAAAA,+BAA+B,KAAK,QAAQ,KAAK,eAAe,KAAK,YAAY;AAC3H,SAAK,kCAAkC,IAAIC,gCAAAA,gCAAgC,KAAK,QAAQ,KAAK,OAAO,KAAK,aAAa;AAAA,EACvH;AAAA,EAEO,OAAO,EAAE,QAAQ,UAA+B;AACtD,QAAI,KAAK,KAAK,OAAO,IAAI,MAAM,QAAW;AACzC,WAAK,cAAc,cAAc,OAAO,MAAM,KAAK,KAAK,OAAO,IAAI,CAAsB;AAAA,IAC1F;AACA,WAAO,QAAQ,QAAQ,EAAE;AAAA,EAC1B;AA6DD;;"}
1
+ {"version":3,"file":"SqlUpdateInputProcessor.cjs","sources":["../../../../../../packages/engine-content-api/src/mapper/update/SqlUpdateInputProcessor.ts"],"sourcesContent":["import { Input, Model, Value } from '@contember/schema'\nimport { Mapper } from '../Mapper.js'\nimport { UpdateBuilder } from './UpdateBuilder.js'\nimport { hasManyProcessor, hasOneProcessor, relationFieldProcessor } from '../MutationProcessorHelper.js'\nimport { OneHasOneInverseUpdateInputProcessor } from './relations/OneHasOneInverseUpdateInputProcessor.js'\nimport { OneHasOneOwningUpdateInputProcessor } from './relations/OneHasOneOwningUpdateInputProcessor.js'\nimport { OneHasManyUpdateInputProcessor } from './relations/OneHasManyUpdateInputProcessor.js'\nimport { ManyHasManyUpdateInputProcessor } from './relations/ManyHasManyUpdateInputProcessor.js'\nimport { UpdateInputProcessor } from '../../inputProcessing/index.js'\nimport { MutationResultList } from '../Result.js'\nimport { ManyHasOneUpdateInputProcessor } from './relations/ManyHasOneUpdateInputProcessor.js'\nimport { MapperInput } from '../types.js'\nimport { AclScope } from '../../acl/index.js'\n\nexport type SqlUpdateInputProcessorResult = MutationResultList | ((ctx: { primary: Input.PrimaryValue }) => Promise<MutationResultList>)\n\nexport class SqlUpdateInputProcessor implements UpdateInputProcessor<SqlUpdateInputProcessorResult> {\n\tprivate oneHasOneInverseUpdateInputProcessor: OneHasOneInverseUpdateInputProcessor\n\tprivate oneHasOneOwningUpdateInputProcessor: OneHasOneOwningUpdateInputProcessor\n\tprivate oneHasManyUpdateInputProcessor: OneHasManyUpdateInputProcessor\n\tprivate manyHasOneUpdateInputProcessor: ManyHasOneUpdateInputProcessor\n\tprivate manyHasManyUpdateInputProcessor: ManyHasManyUpdateInputProcessor\n\n\tconstructor(\n\t\tprivate readonly primaryValue: Input.PrimaryValue,\n\t\tprivate readonly data: MapperInput.UpdateDataInput,\n\t\tprivate readonly updateBuilder: UpdateBuilder,\n\t\tprivate readonly mapper: Mapper,\n\t\t/** Scope of the entity being updated; relation targets are always reached over a relation and stay nested. */\n\t\tprivate readonly scope: AclScope,\n\t) {\n\t\tthis.oneHasOneInverseUpdateInputProcessor = new OneHasOneInverseUpdateInputProcessor(this.primaryValue, this.mapper)\n\t\tthis.oneHasOneOwningUpdateInputProcessor = new OneHasOneOwningUpdateInputProcessor(this.primaryValue, this.mapper, this.updateBuilder)\n\t\tthis.oneHasManyUpdateInputProcessor = new OneHasManyUpdateInputProcessor(this.mapper)\n\t\tthis.manyHasOneUpdateInputProcessor = new ManyHasOneUpdateInputProcessor(this.mapper, this.updateBuilder, this.primaryValue)\n\t\tthis.manyHasManyUpdateInputProcessor = new ManyHasManyUpdateInputProcessor(this.mapper, this.scope, this.updateBuilder)\n\t}\n\n\tpublic column({ entity, column }: Model.ColumnContext) {\n\t\tif (this.data[column.name] !== undefined) {\n\t\t\tthis.updateBuilder.addFieldValue(column.name, this.data[column.name] as Value.AtomicValue)\n\t\t}\n\t\treturn Promise.resolve([])\n\t}\n\n\tmanyHasManyInverse: UpdateInputProcessor<SqlUpdateInputProcessorResult>['manyHasManyInverse'] = {\n\t\tconnect: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.connect(ctx)),\n\t\tcreate: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.connectOrCreate(ctx)),\n\t\tupdate: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.update(ctx)),\n\t\tupsert: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.upsert(ctx)),\n\t\tdelete: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.delete(ctx)),\n\t\tdisconnect: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.disconnect(ctx)),\n\t\tset: relationFieldProcessor(ctx => this.manyHasManyUpdateInputProcessor.set(ctx)),\n\t}\n\n\tmanyHasManyOwning: UpdateInputProcessor<SqlUpdateInputProcessorResult>['manyHasManyOwning'] = {\n\t\tconnect: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.connect(ctx)),\n\t\tcreate: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.connectOrCreate(ctx)),\n\t\tupdate: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.update(ctx)),\n\t\tupsert: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.upsert(ctx)),\n\t\tdelete: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.delete(ctx)),\n\t\tdisconnect: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.disconnect(ctx)),\n\t\tset: relationFieldProcessor(ctx => this.manyHasManyUpdateInputProcessor.set(ctx)),\n\t}\n\n\tmanyHasOne: UpdateInputProcessor<SqlUpdateInputProcessorResult>['manyHasOne'] = {\n\t\tconnect: hasOneProcessor(ctx => this.manyHasOneUpdateInputProcessor.connect(ctx)),\n\t\tcreate: hasOneProcessor(ctx => this.manyHasOneUpdateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasOneProcessor(ctx => this.manyHasOneUpdateInputProcessor.connectOrCreate(ctx)),\n\t\tupdate: hasOneProcessor(ctx => this.manyHasOneUpdateInputProcessor.update(ctx)),\n\t\tupsert: hasOneProcessor(ctx => this.manyHasOneUpdateInputProcessor.upsert(ctx)),\n\t\tdelete: hasOneProcessor(ctx => this.manyHasOneUpdateInputProcessor.delete(ctx)),\n\t\tdisconnect: hasOneProcessor(ctx => this.manyHasOneUpdateInputProcessor.disconnect(ctx)),\n\t}\n\n\toneHasMany: UpdateInputProcessor<SqlUpdateInputProcessorResult>['oneHasMany'] = {\n\t\tconnect: hasManyProcessor(ctx => this.oneHasManyUpdateInputProcessor.connect(ctx)),\n\t\tcreate: hasManyProcessor(ctx => this.oneHasManyUpdateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasManyProcessor(ctx => this.oneHasManyUpdateInputProcessor.connectOrCreate(ctx)),\n\t\tupdate: hasManyProcessor(ctx => this.oneHasManyUpdateInputProcessor.update(ctx)),\n\t\tupsert: hasManyProcessor(ctx => this.oneHasManyUpdateInputProcessor.upsert(ctx)),\n\t\tdelete: hasManyProcessor(ctx => this.oneHasManyUpdateInputProcessor.delete(ctx)),\n\t\tdisconnect: hasManyProcessor(ctx => this.oneHasManyUpdateInputProcessor.disconnect(ctx)),\n\t\tset: relationFieldProcessor(ctx => this.oneHasManyUpdateInputProcessor.set(ctx)),\n\t}\n\n\toneHasOneInverse: UpdateInputProcessor<SqlUpdateInputProcessorResult>['oneHasOneInverse'] = {\n\t\tconnect: hasOneProcessor(ctx => this.oneHasOneInverseUpdateInputProcessor.connect(ctx)),\n\t\tcreate: hasOneProcessor(ctx => this.oneHasOneInverseUpdateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasOneProcessor(ctx => this.oneHasOneInverseUpdateInputProcessor.connectOrCreate(ctx)),\n\t\tupdate: hasOneProcessor(ctx => this.oneHasOneInverseUpdateInputProcessor.update(ctx)),\n\t\tupsert: hasOneProcessor(ctx => this.oneHasOneInverseUpdateInputProcessor.upsert(ctx)),\n\t\tdelete: hasOneProcessor(ctx => this.oneHasOneInverseUpdateInputProcessor.delete(ctx)),\n\t\tdisconnect: hasOneProcessor(ctx => this.oneHasOneInverseUpdateInputProcessor.disconnect(ctx)),\n\t}\n\n\toneHasOneOwning: UpdateInputProcessor<SqlUpdateInputProcessorResult>['oneHasOneOwning'] = {\n\t\tconnect: hasOneProcessor(ctx => this.oneHasOneOwningUpdateInputProcessor.connect(ctx)),\n\t\tcreate: hasOneProcessor(ctx => this.oneHasOneOwningUpdateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasOneProcessor(ctx => this.oneHasOneOwningUpdateInputProcessor.connectOrCreate(ctx)),\n\t\tupdate: hasOneProcessor(ctx => this.oneHasOneOwningUpdateInputProcessor.update(ctx)),\n\t\tupsert: hasOneProcessor(ctx => this.oneHasOneOwningUpdateInputProcessor.upsert(ctx)),\n\t\tdelete: hasOneProcessor(ctx => this.oneHasOneOwningUpdateInputProcessor.delete(ctx)),\n\t\tdisconnect: hasOneProcessor(ctx => this.oneHasOneOwningUpdateInputProcessor.disconnect(ctx)),\n\t}\n}\n"],"names":["hasManyProcessor","relationFieldProcessor","hasOneProcessor","OneHasOneInverseUpdateInputProcessor","OneHasOneOwningUpdateInputProcessor","OneHasManyUpdateInputProcessor","ManyHasOneUpdateInputProcessor","ManyHasManyUpdateInputProcessor"],"mappings":";;;;;;;;;;;AAgBO,MAAM,w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or } from "../MutationProcessorHelper.js";
2
2
  import { OneHasOneInverseUpdateInputProcessor } from "./relations/OneHasOneInverseUpdateInputProcessor.js";
3
3
  import { OneHasOneOwningUpdateInputProcessor } from "./relations/OneHasOneOwningUpdateInputProcessor.js";
4
4
  import { OneHasManyUpdateInputProcessor } from "./relations/OneHasManyUpdateInputProcessor.js";
@@ -26,7 +26,8 @@ class SqlUpdateInputProcessor {
26
26
  update: hasManyProcessor((ctx) => this.manyHasManyUpdateInputProcessor.update(ctx)),
27
27
  upsert: hasManyProcessor((ctx) => this.manyHasManyUpdateInputProcessor.upsert(ctx)),
28
28
  delete: hasManyProcessor((ctx) => this.manyHasManyUpdateInputProcessor.delete(ctx)),
29
- disconnect: hasManyProcessor((ctx) => this.manyHasManyUpdateInputProcessor.disconnect(ctx))
29
+ disconnect: hasManyProcessor((ctx) => this.manyHasManyUpdateInputProcessor.disconnect(ctx)),
30
+ set: relationFieldProcessor((ctx) => this.manyHasManyUpdateInputProcessor.set(ctx))
30
31
  });
31
32
  __publicField(this, "manyHasManyOwning", {
32
33
  connect: hasManyProcessor((ctx) => this.manyHasManyUpdateInputProcessor.connect(ctx)),
@@ -35,7 +36,8 @@ class SqlUpdateInputProcessor {
35
36
  update: hasManyProcessor((ctx) => this.manyHasManyUpdateInputProcessor.update(ctx)),
36
37
  upsert: hasManyProcessor((ctx) => this.manyHasManyUpdateInputProcessor.upsert(ctx)),
37
38
  delete: hasManyProcessor((ctx) => this.manyHasManyUpdateInputProcessor.delete(ctx)),
38
- disconnect: hasManyProcessor((ctx) => this.manyHasManyUpdateInputProcessor.disconnect(ctx))
39
+ disconnect: hasManyProcessor((ctx) => this.manyHasManyUpdateInputProcessor.disconnect(ctx)),
40
+ set: relationFieldProcessor((ctx) => this.manyHasManyUpdateInputProcessor.set(ctx))
39
41
  });
40
42
  __publicField(this, "manyHasOne", {
41
43
  connect: hasOneProcessor((ctx) => this.manyHasOneUpdateInputProcessor.connect(ctx)),
@@ -53,7 +55,8 @@ class SqlUpdateInputProcessor {
53
55
  update: hasManyProcessor((ctx) => this.oneHasManyUpdateInputProcessor.update(ctx)),
54
56
  upsert: hasManyProcessor((ctx) => this.oneHasManyUpdateInputProcessor.upsert(ctx)),
55
57
  delete: hasManyProcessor((ctx) => this.oneHasManyUpdateInputProcessor.delete(ctx)),
56
- disconnect: hasManyProcessor((ctx) => this.oneHasManyUpdateInputProcessor.disconnect(ctx))
58
+ disconnect: hasManyProcessor((ctx) => this.oneHasManyUpdateInputProcessor.disconnect(ctx)),
59
+ set: relationFieldProcessor((ctx) => this.oneHasManyUpdateInputProcessor.set(ctx))
57
60
  });
58
61
  __publicField(this, "oneHasOneInverse", {
59
62
  connect: hasOneProcessor((ctx) => this.oneHasOneInverseUpdateInputProcessor.connect(ctx)),
@@ -1 +1 @@
1
- {"version":3,"file":"SqlUpdateInputProcessor.js","sources":["../../../../../../packages/engine-content-api/src/mapper/update/SqlUpdateInputProcessor.ts"],"sourcesContent":["import { Input, Model, Value } from '@contember/schema'\nimport { Mapper } from '../Mapper.js'\nimport { UpdateBuilder } from './UpdateBuilder.js'\nimport { hasManyProcessor, hasOneProcessor } from '../MutationProcessorHelper.js'\nimport { OneHasOneInverseUpdateInputProcessor } from './relations/OneHasOneInverseUpdateInputProcessor.js'\nimport { OneHasOneOwningUpdateInputProcessor } from './relations/OneHasOneOwningUpdateInputProcessor.js'\nimport { OneHasManyUpdateInputProcessor } from './relations/OneHasManyUpdateInputProcessor.js'\nimport { ManyHasManyUpdateInputProcessor } from './relations/ManyHasManyUpdateInputProcessor.js'\nimport { UpdateInputProcessor } from '../../inputProcessing/index.js'\nimport { MutationResultList } from '../Result.js'\nimport { ManyHasOneUpdateInputProcessor } from './relations/ManyHasOneUpdateInputProcessor.js'\nimport { MapperInput } from '../types.js'\nimport { AclScope } from '../../acl/index.js'\n\nexport type SqlUpdateInputProcessorResult = MutationResultList | ((ctx: { primary: Input.PrimaryValue }) => Promise<MutationResultList>)\n\nexport class SqlUpdateInputProcessor implements UpdateInputProcessor<SqlUpdateInputProcessorResult> {\n\tprivate oneHasOneInverseUpdateInputProcessor: OneHasOneInverseUpdateInputProcessor\n\tprivate oneHasOneOwningUpdateInputProcessor: OneHasOneOwningUpdateInputProcessor\n\tprivate oneHasManyUpdateInputProcessor: OneHasManyUpdateInputProcessor\n\tprivate manyHasOneUpdateInputProcessor: ManyHasOneUpdateInputProcessor\n\tprivate manyHasManyUpdateInputProcessor: ManyHasManyUpdateInputProcessor\n\n\tconstructor(\n\t\tprivate readonly primaryValue: Input.PrimaryValue,\n\t\tprivate readonly data: MapperInput.UpdateDataInput,\n\t\tprivate readonly updateBuilder: UpdateBuilder,\n\t\tprivate readonly mapper: Mapper,\n\t\t/** Scope of the entity being updated; relation targets are always reached over a relation and stay nested. */\n\t\tprivate readonly scope: AclScope,\n\t) {\n\t\tthis.oneHasOneInverseUpdateInputProcessor = new OneHasOneInverseUpdateInputProcessor(this.primaryValue, this.mapper)\n\t\tthis.oneHasOneOwningUpdateInputProcessor = new OneHasOneOwningUpdateInputProcessor(this.primaryValue, this.mapper, this.updateBuilder)\n\t\tthis.oneHasManyUpdateInputProcessor = new OneHasManyUpdateInputProcessor(this.mapper)\n\t\tthis.manyHasOneUpdateInputProcessor = new ManyHasOneUpdateInputProcessor(this.mapper, this.updateBuilder, this.primaryValue)\n\t\tthis.manyHasManyUpdateInputProcessor = new ManyHasManyUpdateInputProcessor(this.mapper, this.scope, this.updateBuilder)\n\t}\n\n\tpublic column({ entity, column }: Model.ColumnContext) {\n\t\tif (this.data[column.name] !== undefined) {\n\t\t\tthis.updateBuilder.addFieldValue(column.name, this.data[column.name] as Value.AtomicValue)\n\t\t}\n\t\treturn Promise.resolve([])\n\t}\n\n\tmanyHasManyInverse: UpdateInputProcessor<SqlUpdateInputProcessorResult>['manyHasManyInverse'] = {\n\t\tconnect: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.connect(ctx)),\n\t\tcreate: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.connectOrCreate(ctx)),\n\t\tupdate: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.update(ctx)),\n\t\tupsert: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.upsert(ctx)),\n\t\tdelete: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.delete(ctx)),\n\t\tdisconnect: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.disconnect(ctx)),\n\t}\n\n\tmanyHasManyOwning: UpdateInputProcessor<SqlUpdateInputProcessorResult>['manyHasManyOwning'] = {\n\t\tconnect: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.connect(ctx)),\n\t\tcreate: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.connectOrCreate(ctx)),\n\t\tupdate: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.update(ctx)),\n\t\tupsert: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.upsert(ctx)),\n\t\tdelete: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.delete(ctx)),\n\t\tdisconnect: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.disconnect(ctx)),\n\t}\n\n\tmanyHasOne: UpdateInputProcessor<SqlUpdateInputProcessorResult>['manyHasOne'] = {\n\t\tconnect: hasOneProcessor(ctx => this.manyHasOneUpdateInputProcessor.connect(ctx)),\n\t\tcreate: hasOneProcessor(ctx => this.manyHasOneUpdateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasOneProcessor(ctx => this.manyHasOneUpdateInputProcessor.connectOrCreate(ctx)),\n\t\tupdate: hasOneProcessor(ctx => this.manyHasOneUpdateInputProcessor.update(ctx)),\n\t\tupsert: hasOneProcessor(ctx => this.manyHasOneUpdateInputProcessor.upsert(ctx)),\n\t\tdelete: hasOneProcessor(ctx => this.manyHasOneUpdateInputProcessor.delete(ctx)),\n\t\tdisconnect: hasOneProcessor(ctx => this.manyHasOneUpdateInputProcessor.disconnect(ctx)),\n\t}\n\n\toneHasMany: UpdateInputProcessor<SqlUpdateInputProcessorResult>['oneHasMany'] = {\n\t\tconnect: hasManyProcessor(ctx => this.oneHasManyUpdateInputProcessor.connect(ctx)),\n\t\tcreate: hasManyProcessor(ctx => this.oneHasManyUpdateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasManyProcessor(ctx => this.oneHasManyUpdateInputProcessor.connectOrCreate(ctx)),\n\t\tupdate: hasManyProcessor(ctx => this.oneHasManyUpdateInputProcessor.update(ctx)),\n\t\tupsert: hasManyProcessor(ctx => this.oneHasManyUpdateInputProcessor.upsert(ctx)),\n\t\tdelete: hasManyProcessor(ctx => this.oneHasManyUpdateInputProcessor.delete(ctx)),\n\t\tdisconnect: hasManyProcessor(ctx => this.oneHasManyUpdateInputProcessor.disconnect(ctx)),\n\t}\n\n\toneHasOneInverse: UpdateInputProcessor<SqlUpdateInputProcessorResult>['oneHasOneInverse'] = {\n\t\tconnect: hasOneProcessor(ctx => this.oneHasOneInverseUpdateInputProcessor.connect(ctx)),\n\t\tcreate: hasOneProcessor(ctx => this.oneHasOneInverseUpdateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasOneProcessor(ctx => this.oneHasOneInverseUpdateInputProcessor.connectOrCreate(ctx)),\n\t\tupdate: hasOneProcessor(ctx => this.oneHasOneInverseUpdateInputProcessor.update(ctx)),\n\t\tupsert: hasOneProcessor(ctx => this.oneHasOneInverseUpdateInputProcessor.upsert(ctx)),\n\t\tdelete: hasOneProcessor(ctx => this.oneHasOneInverseUpdateInputProcessor.delete(ctx)),\n\t\tdisconnect: hasOneProcessor(ctx => this.oneHasOneInverseUpdateInputProcessor.disconnect(ctx)),\n\t}\n\n\toneHasOneOwning: UpdateInputProcessor<SqlUpdateInputProcessorResult>['oneHasOneOwning'] = {\n\t\tconnect: hasOneProcessor(ctx => this.oneHasOneOwningUpdateInputProcessor.connect(ctx)),\n\t\tcreate: hasOneProcessor(ctx => this.oneHasOneOwningUpdateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasOneProcessor(ctx => this.oneHasOneOwningUpdateInputProcessor.connectOrCreate(ctx)),\n\t\tupdate: hasOneProcessor(ctx => this.oneHasOneOwningUpdateInputProcessor.update(ctx)),\n\t\tupsert: hasOneProcessor(ctx => this.oneHasOneOwningUpdateInputProcessor.upsert(ctx)),\n\t\tdelete: hasOneProcessor(ctx => this.oneHasOneOwningUpdateInputProcessor.delete(ctx)),\n\t\tdisconnect: hasOneProcessor(ctx => this.oneHasOneOwningUpdateInputProcessor.disconnect(ctx)),\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;AAgBO,MAAM,wBAAuF;AAAA,EAOnG,YACkB,cACA,MACA,eACA,QAEA,OAChB;AANgB,SAAA,eAAA;AACA,SAAA,OAAA;AACA,SAAA,gBAAA;AACA,SAAA,SAAA;AAEA,SAAA,QAAA;AAZlB,kBAAA,MAAQ,sCAAA;AACR,kBAAA,MAAQ,qCAAA;AACR,kBAAA,MAAQ,gCAAA;AACR,kBAAA,MAAQ,gCAAA;AACR,kBAAA,MAAQ,iCAAA;AAwBR,kBAAA,MAAA,sBAAgG;AAAA,MAC/F,SAAS,iBAAiB,CAAA,QAAO,KAAK,gCAAgC,QAAQ,GAAG,CAAC;AAAA,MAClF,QAAQ,iBAAiB,CAAA,QAAO,KAAK,gCAAgC,OAAO,GAAG,CAAC;AAAA,MAChF,iBAAiB,iBAAiB,CAAA,QAAO,KAAK,gCAAgC,gBAAgB,GAAG,CAAC;AAAA,MAClG,QAAQ,iBAAiB,CAAA,QAAO,KAAK,gCAAgC,OAAO,GAAG,CAAC;AAAA,MAChF,QAAQ,iBAAiB,CAAA,QAAO,KAAK,gCAAgC,OAAO,GAAG,CAAC;AAAA,MAChF,QAAQ,iBAAiB,CAAA,QAAO,KAAK,gC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gB,CAAA,QAAO,KAAK,oCAAoC,OAAO,GAAG,CAAC;AAAA,MACnF,iBAAiB,gBAAgB,CAAA,QAAO,KAAK,oCAAoC,gBAAgB,GAAG,CAAC;AAAA,MACrG,QAAQ,gBAAgB,CAAA,QAAO,KAAK,oCAAoC,OAAO,GAAG,CAAC;AAAA,MACnF,QAAQ,gBAAgB,CAAA,QAAO,KAAK,oCAAoC,OAAO,GAAG,CAAC;AAAA,MACnF,QAAQ,gBAAgB,CAAA,QAAO,KAAK,oCAAoC,OAAO,GAAG,CAAC;AAAA,MACnF,YAAY,gBAAgB,CAAA,QAAO,KAAK,oCAAoC,WAAW,GAAG,CAAC;AAAA,IAAA,CAC5F;AAxEC,SAAK,uCAAuC,IAAI,qCAAqC,KAAK,cAAc,KAAK,MAAM;AACnH,SAAK,sCAAsC,IAAI,oCAAoC,KAAK,cAAc,KAAK,QAAQ,KAAK,aAAa;AACrI,SAAK,iCAAiC,IAAI,+BAA+B,KAAK,MAAM;AACpF,SAAK,iCAAiC,IAAI,+BAA+B,KAAK,QAAQ,KAAK,eAAe,KAAK,YAAY;AAC3H,SAAK,kCAAkC,IAAI,gCAAgC,KAAK,QAAQ,KAAK,OAAO,KAAK,aAAa;AAAA,EACvH;AAAA,EAEO,OAAO,EAAE,QAAQ,UAA+B;AACtD,QAAI,KAAK,KAAK,OAAO,IAAI,MAAM,QAAW;AACzC,WAAK,cAAc,cAAc,OAAO,MAAM,KAAK,KAAK,OAAO,IAAI,CAAsB;AAAA,IAC1F;AACA,WAAO,QAAQ,QAAQ,EAAE;AAAA,EAC1B;AA6DD;"}
1
+ {"version":3,"file":"SqlUpdateInputProcessor.js","sources":["../../../../../../packages/engine-content-api/src/mapper/update/SqlUpdateInputProcessor.ts"],"sourcesContent":["import { Input, Model, Value } from '@contember/schema'\nimport { Mapper } from '../Mapper.js'\nimport { UpdateBuilder } from './UpdateBuilder.js'\nimport { hasManyProcessor, hasOneProcessor, relationFieldProcessor } from '../MutationProcessorHelper.js'\nimport { OneHasOneInverseUpdateInputProcessor } from './relations/OneHasOneInverseUpdateInputProcessor.js'\nimport { OneHasOneOwningUpdateInputProcessor } from './relations/OneHasOneOwningUpdateInputProcessor.js'\nimport { OneHasManyUpdateInputProcessor } from './relations/OneHasManyUpdateInputProcessor.js'\nimport { ManyHasManyUpdateInputProcessor } from './relations/ManyHasManyUpdateInputProcessor.js'\nimport { UpdateInputProcessor } from '../../inputProcessing/index.js'\nimport { MutationResultList } from '../Result.js'\nimport { ManyHasOneUpdateInputProcessor } from './relations/ManyHasOneUpdateInputProcessor.js'\nimport { MapperInput } from '../types.js'\nimport { AclScope } from '../../acl/index.js'\n\nexport type SqlUpdateInputProcessorResult = MutationResultList | ((ctx: { primary: Input.PrimaryValue }) => Promise<MutationResultList>)\n\nexport class SqlUpdateInputProcessor implements UpdateInputProcessor<SqlUpdateInputProcessorResult> {\n\tprivate oneHasOneInverseUpdateInputProcessor: OneHasOneInverseUpdateInputProcessor\n\tprivate oneHasOneOwningUpdateInputProcessor: OneHasOneOwningUpdateInputProcessor\n\tprivate oneHasManyUpdateInputProcessor: OneHasManyUpdateInputProcessor\n\tprivate manyHasOneUpdateInputProcessor: ManyHasOneUpdateInputProcessor\n\tprivate manyHasManyUpdateInputProcessor: ManyHasManyUpdateInputProcessor\n\n\tconstructor(\n\t\tprivate readonly primaryValue: Input.PrimaryValue,\n\t\tprivate readonly data: MapperInput.UpdateDataInput,\n\t\tprivate readonly updateBuilder: UpdateBuilder,\n\t\tprivate readonly mapper: Mapper,\n\t\t/** Scope of the entity being updated; relation targets are always reached over a relation and stay nested. */\n\t\tprivate readonly scope: AclScope,\n\t) {\n\t\tthis.oneHasOneInverseUpdateInputProcessor = new OneHasOneInverseUpdateInputProcessor(this.primaryValue, this.mapper)\n\t\tthis.oneHasOneOwningUpdateInputProcessor = new OneHasOneOwningUpdateInputProcessor(this.primaryValue, this.mapper, this.updateBuilder)\n\t\tthis.oneHasManyUpdateInputProcessor = new OneHasManyUpdateInputProcessor(this.mapper)\n\t\tthis.manyHasOneUpdateInputProcessor = new ManyHasOneUpdateInputProcessor(this.mapper, this.updateBuilder, this.primaryValue)\n\t\tthis.manyHasManyUpdateInputProcessor = new ManyHasManyUpdateInputProcessor(this.mapper, this.scope, this.updateBuilder)\n\t}\n\n\tpublic column({ entity, column }: Model.ColumnContext) {\n\t\tif (this.data[column.name] !== undefined) {\n\t\t\tthis.updateBuilder.addFieldValue(column.name, this.data[column.name] as Value.AtomicValue)\n\t\t}\n\t\treturn Promise.resolve([])\n\t}\n\n\tmanyHasManyInverse: UpdateInputProcessor<SqlUpdateInputProcessorResult>['manyHasManyInverse'] = {\n\t\tconnect: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.connect(ctx)),\n\t\tcreate: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.connectOrCreate(ctx)),\n\t\tupdate: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.update(ctx)),\n\t\tupsert: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.upsert(ctx)),\n\t\tdelete: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.delete(ctx)),\n\t\tdisconnect: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.disconnect(ctx)),\n\t\tset: relationFieldProcessor(ctx => this.manyHasManyUpdateInputProcessor.set(ctx)),\n\t}\n\n\tmanyHasManyOwning: UpdateInputProcessor<SqlUpdateInputProcessorResult>['manyHasManyOwning'] = {\n\t\tconnect: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.connect(ctx)),\n\t\tcreate: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.connectOrCreate(ctx)),\n\t\tupdate: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.update(ctx)),\n\t\tupsert: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.upsert(ctx)),\n\t\tdelete: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.delete(ctx)),\n\t\tdisconnect: hasManyProcessor(ctx => this.manyHasManyUpdateInputProcessor.disconnect(ctx)),\n\t\tset: relationFieldProcessor(ctx => this.manyHasManyUpdateInputProcessor.set(ctx)),\n\t}\n\n\tmanyHasOne: UpdateInputProcessor<SqlUpdateInputProcessorResult>['manyHasOne'] = {\n\t\tconnect: hasOneProcessor(ctx => this.manyHasOneUpdateInputProcessor.connect(ctx)),\n\t\tcreate: hasOneProcessor(ctx => this.manyHasOneUpdateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasOneProcessor(ctx => this.manyHasOneUpdateInputProcessor.connectOrCreate(ctx)),\n\t\tupdate: hasOneProcessor(ctx => this.manyHasOneUpdateInputProcessor.update(ctx)),\n\t\tupsert: hasOneProcessor(ctx => this.manyHasOneUpdateInputProcessor.upsert(ctx)),\n\t\tdelete: hasOneProcessor(ctx => this.manyHasOneUpdateInputProcessor.delete(ctx)),\n\t\tdisconnect: hasOneProcessor(ctx => this.manyHasOneUpdateInputProcessor.disconnect(ctx)),\n\t}\n\n\toneHasMany: UpdateInputProcessor<SqlUpdateInputProcessorResult>['oneHasMany'] = {\n\t\tconnect: hasManyProcessor(ctx => this.oneHasManyUpdateInputProcessor.connect(ctx)),\n\t\tcreate: hasManyProcessor(ctx => this.oneHasManyUpdateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasManyProcessor(ctx => this.oneHasManyUpdateInputProcessor.connectOrCreate(ctx)),\n\t\tupdate: hasManyProcessor(ctx => this.oneHasManyUpdateInputProcessor.update(ctx)),\n\t\tupsert: hasManyProcessor(ctx => this.oneHasManyUpdateInputProcessor.upsert(ctx)),\n\t\tdelete: hasManyProcessor(ctx => this.oneHasManyUpdateInputProcessor.delete(ctx)),\n\t\tdisconnect: hasManyProcessor(ctx => this.oneHasManyUpdateInputProcessor.disconnect(ctx)),\n\t\tset: relationFieldProcessor(ctx => this.oneHasManyUpdateInputProcessor.set(ctx)),\n\t}\n\n\toneHasOneInverse: UpdateInputProcessor<SqlUpdateInputProcessorResult>['oneHasOneInverse'] = {\n\t\tconnect: hasOneProcessor(ctx => this.oneHasOneInverseUpdateInputProcessor.connect(ctx)),\n\t\tcreate: hasOneProcessor(ctx => this.oneHasOneInverseUpdateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasOneProcessor(ctx => this.oneHasOneInverseUpdateInputProcessor.connectOrCreate(ctx)),\n\t\tupdate: hasOneProcessor(ctx => this.oneHasOneInverseUpdateInputProcessor.update(ctx)),\n\t\tupsert: hasOneProcessor(ctx => this.oneHasOneInverseUpdateInputProcessor.upsert(ctx)),\n\t\tdelete: hasOneProcessor(ctx => this.oneHasOneInverseUpdateInputProcessor.delete(ctx)),\n\t\tdisconnect: hasOneProcessor(ctx => this.oneHasOneInverseUpdateInputProcessor.disconnect(ctx)),\n\t}\n\n\toneHasOneOwning: UpdateInputProcessor<SqlUpdateInputProcessorResult>['oneHasOneOwning'] = {\n\t\tconnect: hasOneProcessor(ctx => this.oneHasOneOwningUpdateInputProcessor.connect(ctx)),\n\t\tcreate: hasOneProcessor(ctx => this.oneHasOneOwningUpdateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasOneProcessor(ctx => this.oneHasOneOwningUpdateInputProcessor.connectOrCreate(ctx)),\n\t\tupdate: hasOneProcessor(ctx => this.oneHasOneOwningUpdateInputProcessor.update(ctx)),\n\t\tupsert: hasOneProcessor(ctx => this.oneHasOneOwningUpdateInputProcessor.upsert(ctx)),\n\t\tdelete: hasOneProcessor(ctx => this.oneHasOneOwningUpdateInputProcessor.delete(ctx)),\n\t\tdisconnect: hasOneProcessor(ctx => this.oneHasOneOwningUpdateInputProcessor.disconnect(ctx)),\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;AAgBO,MAAM,wBAAuF;AAAA,EAOnG,YACkB,cACA,MACA,eACA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