@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":"Result.cjs","sources":["../../../../../packages/engine-content-api/src/mapper/Result.ts"],"sourcesContent":["import { Input, Model, Value } from '@contember/schema'\nimport { MapperInput } from './types.js'\n\nexport enum MutationResultType {\n\tok = 'ok',\n\tnothingToDo = 'nothingToDo',\n\tnotFoundError = 'notFoundError',\n\tconstraintViolationError = 'constraintViolationError',\n\tnoResultError = 'noResultError',\n\tvalidationError = 'validationError',\n\tinputError = 'inputError',\n\tsqlError = 'sqlError',\n}\n\nexport enum MutationResultHint {\n\tsqlError = 'sqlError',\n\tsubSequentSqlError = 'subsequentSqlError',\n}\n\nexport enum ModificationType {\n\tcreate = 'create',\n\tupdate = 'update',\n\tdelete = 'delete',\n\tjunctionUpdate = 'junctionUpdate',\n}\n\nexport type MutationResult =\n\t| MutationUpdateOk\n\t| MutationCreateOk\n\t| MutationDeleteOk\n\t| MutationJunctionUpdateOk\n\t| MutationEntryNotFoundError\n\t| MutationNothingToDo\n\t| MutationConstraintViolationError\n\t| MutationNoResultError\n\t| MutationInputError\n\t| MutationSqlError\n\nexport type MutationResultList = MutationResult[]\n\ntype Path = ({ field: string } | { index: number; alias?: string })[]\n\ninterface MutationResultInterface {\n\terror: boolean\n\tresult: MutationResultType\n\tpaths: Path[]\n\tmessage?: string\n\thints: MutationResultHint[]\n}\n\nexport type RowValues = { [fieldName: string]: Value.FieldValue }\n\nexport class MutationUpdateOk implements MutationResultInterface {\n\terror = false\n\tresult = MutationResultType.ok as const\n\ttype = ModificationType.update as const\n\thints: MutationResultHint[] = []\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly entity: Model.Entity,\n\t\tpublic readonly primary: Value.PrimaryValue,\n\t\tpublic readonly input: MapperInput.UpdateDataInput,\n\t\tpublic readonly values: RowValues,\n\t\tpublic readonly oldValues?: RowValues,\n\t) {}\n}\n\nexport class MutationCreateOk implements MutationResultInterface {\n\terror = false\n\tresult = MutationResultType.ok as const\n\ttype = ModificationType.create as const\n\thints: MutationResultHint[] = []\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly entity: Model.Entity,\n\t\tpublic readonly primary: Value.PrimaryValue,\n\t\tpublic readonly input: MapperInput.CreateDataInput,\n\t\tpublic readonly values: RowValues,\n\t) {}\n}\n\nexport class MutationDeleteOk implements MutationResultInterface {\n\terror = false\n\tresult = MutationResultType.ok as const\n\ttype = ModificationType.delete as const\n\thints: MutationResultHint[] = []\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly entity: Model.Entity,\n\t\tpublic readonly primary: Value.PrimaryValue,\n\t) {}\n}\n\nexport class MutationJunctionUpdateOk implements MutationResultInterface {\n\terror = false\n\tresult = MutationResultType.ok as const\n\ttype = ModificationType.junctionUpdate as const\n\thints: MutationResultHint[] = []\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly entity: Model.Entity,\n\t\tpublic readonly relation: Model.ManyHasManyOwningRelation,\n\t\tpublic readonly owningUnique: Input.PrimaryValue,\n\t\tpublic readonly inverseUnique: Input.PrimaryValue,\n\t) {}\n}\n\nexport enum NothingToDoReason {\n\tnoData = 'noData',\n\temptyRelation = 'emptyRelation',\n\talreadyExists = 'alreadyExists',\n\taborted = 'aborted',\n\talreadyDeleted = 'alreadyDeleted',\n}\n\nexport class MutationNothingToDo implements MutationResultInterface {\n\terror = false\n\tresult = MutationResultType.nothingToDo as const\n\thints: MutationResultHint[] = []\n\n\tconstructor(public readonly paths: Path[], public readonly reason: NothingToDoReason) {}\n}\n\nexport enum InputErrorKind {\n\tnonUniqueWhere = 'nonUniqueWhere',\n\tinvalidData = 'invalidData',\n}\n\nexport class MutationInputError implements MutationResultInterface {\n\terror = true\n\tresult = MutationResultType.inputError as const\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly kind: InputErrorKind,\n\t\tpublic readonly message?: string,\n\t\tpublic readonly hints: MutationResultHint[] = [],\n\t) {}\n}\n\nexport class MutationSqlError implements MutationResultInterface {\n\terror = true\n\tresult = MutationResultType.sqlError as const\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly message?: string,\n\t\tpublic readonly hints: MutationResultHint[] = [],\n\t) {}\n}\n\nexport enum ConstraintType {\n\tnotNull = 'notNull',\n\tuniqueKey = 'uniqueKey',\n\tforeignKey = 'foreignKey',\n}\n\nexport class MutationConstraintViolationError implements MutationResultInterface {\n\terror = true\n\tresult = MutationResultType.constraintViolationError as const\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly constraint: ConstraintType,\n\t\tpublic readonly message?: string,\n\t\tpublic readonly hints: MutationResultHint[] = [],\n\t) {}\n}\n\n// maybe denied by acl\nexport class MutationEntryNotFoundError implements MutationResultInterface {\n\terror = true\n\tresult = MutationResultType.notFoundError as const\n\thints: MutationResultHint[] = []\n\tmessage: string\n\n\tconstructor(public readonly paths: Path[], public readonly where: Input.UniqueWhere | Input.OptionalWhere) {\n\t\tthis.message = 'for input ' + JSON.stringify(where)\n\t}\n}\n\n// possibly denied by acl\nexport class MutationNoResultError implements MutationResultInterface {\n\terror = true\n\tresult = MutationResultType.noResultError as const\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly message?: string,\n\t\tpublic readonly hints: MutationResultHint[] = [],\n\t) {}\n}\n\nexport const prependPath = (path: Path, results: MutationResultList): MutationResultList =>\n\tresults.map(it => ({\n\t\t...it,\n\t\tpaths: (it.paths.length === 0 ? [[]] : it.paths).map(it => [...path, ...it]),\n\t}))\n\nexport const getInsertPrimary = (result: MutationResultList) =>\n\t!result.some(it => it.error) && result[0] && result[0].result === MutationResultType.ok && result[0].type === ModificationType.create\n\t\t? result[0].primary\n\t\t: undefined\n"],"names":["MutationResultType","MutationResultHint","NothingToDoReason","InputErrorKind","ConstraintType","it"],"mappings":";;;;;AAGO,IAAK,uCAAAA,wBAAL;AACNA,sBAAA,IAAA,IAAK;AACLA,sBAAA,aAAA,IAAc;AACdA,sBAAA,eAAA,IAAgB;AAChBA,sBAAA,0BAAA,IAA2B;AAC3BA,sBAAA,eAAA,IAAgB;AAChBA,sBAAA,iBAAA,IAAkB;AAClBA,sBAAA,YAAA,IAAa;AACbA,sBAAA,UAAA,IAAW;AARA,SAAAA;AAAA,GAAA,sBAAA,CAAA,CAAA;AAWL,IAAK,uCAAAC,wBAAL;AACNA,sBAAA,UAAA,IAAW;AACXA,sBAAA,oBAAA,IAAqB;AAFV,SAAAA;AAAA,GAAA,sBAAA,CAAA,CAAA;AAsCL,MAAM,iBAAoD;AAAA,EAMhE,YACiB,OACA,QACA,SACA,OACA,QACA,WACf;AANe,SAAA,QAAA;AACA,SAAA,SAAA;AACA,SAAA,UAAA;AACA,SAAA,QAAA;AACA,SAAA,SAAA;AACA,SAAA,YAAA;AAXjB,kBAAA,MAAA,SAAQ,KAAA;AACR;AAAA,MAAA;AAAA,MAAA;AAAA,MAAS;AAAA;AAAA,IAAA;AACT;AAAA,MAAA;AAAA,MAAA;AAAA,MAAO;AAAA;AAAA,IAAA;AACP,kBAAA,MAAA,SAA8B,EAAC;AAAA,EAS5B;AACJ;AAEO,MAAM,iBAAoD;AAAA,EAMhE,YACiB,OACA,QACA,SACA,OACA,QACf;AALe,SAAA,QAAA;AACA,SAAA,SAAA;AACA,SAAA,UAAA;AACA,SAAA,QAAA;AACA,SAAA,SAAA;AAVjB,kBAAA,MAAA,SAAQ,KAAA;AACR;AAAA,MAAA;AAAA,MAAA;AAAA,MAAS;AAAA;AAAA,IAAA;AACT;AAAA,MAAA;AAAA,MAAA;AAAA,MAAO;AAAA;AAAA,IAAA;AACP,kBAAA,MAAA,SAA8B,EAAC;AAAA,EAQ5B;AACJ;AAEO,MAAM,iBAAoD;AAAA,EAMhE,Y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AA;AACA,SAAA,UAAA;AACA,SAAA,QAAA;AANjB,kBAAA,MAAA,SAAQ,IAAA;AACR;AAAA,MAAA;AAAA,MAAA;AAAA,MAAS;AAAA;AAAA,IAAA;AAAA,EAMN;AACJ;AAEO,MAAM,cAAc,CAAC,MAAY,YACvC,QAAQ,IAAI,CAAA,QAAO;AAAA,EAClB,GAAG;AAAA,EACH,QAAQ,GAAG,MAAM,WAAW,IAAI,CAAC,EAAE,IAAI,GAAG,OAAO,IAAI,CAAAC,QAAM,CAAC,GAAG,MAAM,GAAGA,GAAE,CAAC;AAC5E,EAAE;AAEI,MAAM,mBAAmB,CAAC,WAChC,CAAC,OAAO,KAAK,CAAA,OAAM,GAAG,KAAK,KAAK,OAAO,CAAC,KAAK,OAAO,CAAC,EAAE,WAAW,QAAyB,OAAO,CAAC,EAAE,SAAS,WAC3G,OAAO,CAAC,EAAE,UACV;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"Result.cjs","sources":["../../../../../packages/engine-content-api/src/mapper/Result.ts"],"sourcesContent":["import { Input, Model, Value } from '@contember/schema'\nimport { MapperInput } from './types.js'\n\nexport enum MutationResultType {\n\tok = 'ok',\n\tnothingToDo = 'nothingToDo',\n\tnotFoundError = 'notFoundError',\n\tconstraintViolationError = 'constraintViolationError',\n\tnoResultError = 'noResultError',\n\tvalidationError = 'validationError',\n\tinputError = 'inputError',\n\tsqlError = 'sqlError',\n}\n\nexport enum MutationResultHint {\n\tsqlError = 'sqlError',\n\tsubSequentSqlError = 'subsequentSqlError',\n}\n\nexport enum ModificationType {\n\tcreate = 'create',\n\tupdate = 'update',\n\tdelete = 'delete',\n\tjunctionUpdate = 'junctionUpdate',\n}\n\nexport type MutationResult =\n\t| MutationUpdateOk\n\t| MutationCreateOk\n\t| MutationDeleteOk\n\t| MutationJunctionUpdateOk\n\t| MutationEntryNotFoundError\n\t| MutationNothingToDo\n\t| MutationConstraintViolationError\n\t| MutationNoResultError\n\t| MutationInputError\n\t| MutationSqlError\n\nexport type MutationResultList = MutationResult[]\n\ntype Path = ({ field: string } | { index: number; alias?: string })[]\n\ninterface MutationResultInterface {\n\terror: boolean\n\tresult: MutationResultType\n\tpaths: Path[]\n\tmessage?: string\n\thints: MutationResultHint[]\n}\n\nexport type RowValues = { [fieldName: string]: Value.FieldValue }\n\nexport class MutationUpdateOk implements MutationResultInterface {\n\terror = false\n\tresult = MutationResultType.ok as const\n\ttype = ModificationType.update as const\n\thints: MutationResultHint[] = []\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly entity: Model.Entity,\n\t\tpublic readonly primary: Value.PrimaryValue,\n\t\tpublic readonly input: MapperInput.UpdateDataInput,\n\t\tpublic readonly values: RowValues,\n\t\tpublic readonly oldValues?: RowValues,\n\t) {}\n}\n\nexport class MutationCreateOk implements MutationResultInterface {\n\terror = false\n\tresult = MutationResultType.ok as const\n\ttype = ModificationType.create as const\n\thints: MutationResultHint[] = []\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly entity: Model.Entity,\n\t\tpublic readonly primary: Value.PrimaryValue,\n\t\tpublic readonly input: MapperInput.CreateDataInput,\n\t\tpublic readonly values: RowValues,\n\t) {}\n}\n\nexport class MutationDeleteOk implements MutationResultInterface {\n\terror = false\n\tresult = MutationResultType.ok as const\n\ttype = ModificationType.delete as const\n\thints: MutationResultHint[] = []\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly entity: Model.Entity,\n\t\tpublic readonly primary: Value.PrimaryValue,\n\t) {}\n}\n\nexport class MutationJunctionUpdateOk implements MutationResultInterface {\n\terror = false\n\tresult = MutationResultType.ok as const\n\ttype = ModificationType.junctionUpdate as const\n\thints: MutationResultHint[] = []\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly entity: Model.Entity,\n\t\tpublic readonly relation: Model.ManyHasManyOwningRelation,\n\t\tpublic readonly owningUnique: Input.PrimaryValue,\n\t\tpublic readonly inverseUnique: Input.PrimaryValue,\n\t) {}\n}\n\nexport enum NothingToDoReason {\n\tnoData = 'noData',\n\temptyRelation = 'emptyRelation',\n\talreadyExists = 'alreadyExists',\n\taborted = 'aborted',\n\talreadyDeleted = 'alreadyDeleted',\n}\n\nexport class MutationNothingToDo implements MutationResultInterface {\n\terror = false\n\tresult = MutationResultType.nothingToDo as const\n\thints: MutationResultHint[] = []\n\n\tconstructor(public readonly paths: Path[], public readonly reason: NothingToDoReason) {}\n}\n\nexport enum InputErrorKind {\n\tnonUniqueWhere = 'nonUniqueWhere',\n\tinvalidData = 'invalidData',\n}\n\nexport class MutationInputError implements MutationResultInterface {\n\terror = true\n\tresult = MutationResultType.inputError as const\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly kind: InputErrorKind,\n\t\tpublic readonly message?: string,\n\t\tpublic readonly hints: MutationResultHint[] = [],\n\t) {}\n}\n\nexport class MutationSqlError implements MutationResultInterface {\n\terror = true\n\tresult = MutationResultType.sqlError as const\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly message?: string,\n\t\tpublic readonly hints: MutationResultHint[] = [],\n\t) {}\n}\n\nexport enum ConstraintType {\n\tnotNull = 'notNull',\n\tuniqueKey = 'uniqueKey',\n\tforeignKey = 'foreignKey',\n\tcheck = 'check',\n}\n\nexport class MutationConstraintViolationError implements MutationResultInterface {\n\terror = true\n\tresult = MutationResultType.constraintViolationError as const\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly constraint: ConstraintType,\n\t\tpublic readonly message?: string,\n\t\tpublic readonly hints: MutationResultHint[] = [],\n\t) {}\n}\n\n// maybe denied by acl\nexport class MutationEntryNotFoundError implements MutationResultInterface {\n\terror = true\n\tresult = MutationResultType.notFoundError as const\n\thints: MutationResultHint[] = []\n\tmessage: string\n\n\tconstructor(public readonly paths: Path[], public readonly where: Input.UniqueWhere | Input.OptionalWhere) {\n\t\tthis.message = 'for input ' + JSON.stringify(where)\n\t}\n}\n\n// possibly denied by acl\nexport class MutationNoResultError implements MutationResultInterface {\n\terror = true\n\tresult = MutationResultType.noResultError as const\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly message?: string,\n\t\tpublic readonly hints: MutationResultHint[] = [],\n\t) {}\n}\n\nexport const prependPath = (path: Path, results: MutationResultList): MutationResultList =>\n\tresults.map(it => ({\n\t\t...it,\n\t\tpaths: (it.paths.length === 0 ? [[]] : it.paths).map(it => [...path, ...it]),\n\t}))\n\nexport const getInsertPrimary = (result: MutationResultList) =>\n\t!result.some(it => it.error) && result[0] && result[0].result === MutationResultType.ok && result[0].type === ModificationType.create\n\t\t? result[0].primary\n\t\t: undefined\n"],"names":["MutationResultType","MutationResultHint","NothingToDoReason","InputErrorKind","ConstraintType","it"],"mappings":";;;;;AAGO,IAAK,uCAAAA,wBAAL;AACNA,sBAAA,IAAA,IAAK;AACLA,sBAAA,aAAA,IAAc;AACdA,sBAAA,eAAA,IAAgB;AAChBA,sBAAA,0BAAA,IAA2B;AAC3BA,sBAAA,eAAA,IAAgB;AAChBA,sBAAA,iBAAA,IAAkB;AAClBA,sBAAA,YAAA,IAAa;AACbA,sBAAA,UAAA,IAAW;AARA,SAAAA;AAAA,GAAA,sBAAA,CAAA,CAAA;AAWL,IAAK,uCAAAC,wBAAL;AACNA,sBAAA,UAAA,IAAW;AACXA,sBAAA,oBAAA,IAAqB;AAFV,SAAAA;AAAA,GAAA,sBAAA,CAAA,CAAA;AAsCL,MAAM,iBAAoD;AAAA,EAMhE,YACiB,OACA,QACA,SACA,OACA,QACA,WACf;AANe,SAAA,QAAA;AACA,SAAA,SAAA;AACA,SAAA,UAAA;AACA,SAAA,QAAA;AACA,SAAA,SAAA;AACA,SAAA,YAAA;AAXjB,kBAAA,MAAA,SAAQ,KAAA;AACR;AAAA,MAAA;AAAA,MAAA;AAAA,MAAS;AAAA;AAAA,IAAA;AACT;AAAA,MAAA;AAAA,MAAA;AAAA,MAAO;AAAA;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SAAQ,IAAA;AACR;AAAA,MAAA;AAAA,MAAA;AAAA,MAAS;AAAA;AAAA,IAAA;AAAA,EAON;AACJ;AAGO,MAAM,2BAA8D;AAAA,EAM1E,YAA4B,OAA+B,OAAgD;AAA/E,SAAA,QAAA;AAA+B,SAAA,QAAA;AAL3D,kBAAA,MAAA,SAAQ,IAAA;AACR;AAAA,MAAA;AAAA,MAAA;AAAA,MAAS;AAAA;AAAA,IAAA;AACT,kBAAA,MAAA,SAA8B,EAAC;AAC/B,kBAAA,MAAA,SAAA;AAGC,SAAK,UAAU,eAAe,KAAK,UAAU,KAAK;AAAA,EACnD;AACD;AAGO,MAAM,sBAAyD;AAAA,EAIrE,YACiB,OACA,SACA,QAA8B,CAAA,GAC7C;AAHe,SAAA,QAAA;AACA,SAAA,UAAA;AACA,SAAA,QAAA;AANjB,kBAAA,MAAA,SAAQ,IAAA;AACR;AAAA,MAAA;AAAA,MAAA;AAAA,MAAS;AAAA;AAAA,IAAA;AAAA,EAMN;AACJ;AAEO,MAAM,cAAc,CAAC,MAAY,YACvC,QAAQ,IAAI,CAAA,QAAO;AAAA,EAClB,GAAG;AAAA,EACH,QAAQ,GAAG,MAAM,WAAW,IAAI,CAAC,EAAE,IAAI,GAAG,OAAO,IAAI,CAAAC,QAAM,CAAC,GAAG,MAAM,GAAGA,GAAE,CAAC;AAC5E,EAAE;AAEI,MAAM,mBAAmB,CAAC,WAChC,CAAC,OAAO,KAAK,CAAA,OAAM,GAAG,KAAK,KAAK,OAAO,CAAC,KAAK,OAAO,CAAC,EAAE,WAAW,QAAyB,OAAO,CAAC,EAAE,SAAS,WAC3G,OAAO,CAAC,EAAE,UACV;;;;;;;;;;;;;;;;;;"}
@@ -168,6 +168,7 @@ var ConstraintType = /* @__PURE__ */ ((ConstraintType2) => {
168
168
  ConstraintType2["notNull"] = "notNull";
169
169
  ConstraintType2["uniqueKey"] = "uniqueKey";
170
170
  ConstraintType2["foreignKey"] = "foreignKey";
171
+ ConstraintType2["check"] = "check";
171
172
  return ConstraintType2;
172
173
  })(ConstraintType || {});
173
174
  class MutationConstraintViolationError {
@@ -1 +1 @@
1
- {"version":3,"file":"Result.js","sources":["../../../../../packages/engine-content-api/src/mapper/Result.ts"],"sourcesContent":["import { Input, Model, Value } from '@contember/schema'\nimport { MapperInput } from './types.js'\n\nexport enum MutationResultType {\n\tok = 'ok',\n\tnothingToDo = 'nothingToDo',\n\tnotFoundError = 'notFoundError',\n\tconstraintViolationError = 'constraintViolationError',\n\tnoResultError = 'noResultError',\n\tvalidationError = 'validationError',\n\tinputError = 'inputError',\n\tsqlError = 'sqlError',\n}\n\nexport enum MutationResultHint {\n\tsqlError = 'sqlError',\n\tsubSequentSqlError = 'subsequentSqlError',\n}\n\nexport enum ModificationType {\n\tcreate = 'create',\n\tupdate = 'update',\n\tdelete = 'delete',\n\tjunctionUpdate = 'junctionUpdate',\n}\n\nexport type MutationResult =\n\t| MutationUpdateOk\n\t| MutationCreateOk\n\t| MutationDeleteOk\n\t| MutationJunctionUpdateOk\n\t| MutationEntryNotFoundError\n\t| MutationNothingToDo\n\t| MutationConstraintViolationError\n\t| MutationNoResultError\n\t| MutationInputError\n\t| MutationSqlError\n\nexport type MutationResultList = MutationResult[]\n\ntype Path = ({ field: string } | { index: number; alias?: string })[]\n\ninterface MutationResultInterface {\n\terror: boolean\n\tresult: MutationResultType\n\tpaths: Path[]\n\tmessage?: string\n\thints: MutationResultHint[]\n}\n\nexport type RowValues = { [fieldName: string]: Value.FieldValue }\n\nexport class MutationUpdateOk implements MutationResultInterface {\n\terror = false\n\tresult = MutationResultType.ok as const\n\ttype = ModificationType.update as const\n\thints: MutationResultHint[] = []\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly entity: Model.Entity,\n\t\tpublic readonly primary: Value.PrimaryValue,\n\t\tpublic readonly input: MapperInput.UpdateDataInput,\n\t\tpublic readonly values: RowValues,\n\t\tpublic readonly oldValues?: RowValues,\n\t) {}\n}\n\nexport class MutationCreateOk implements MutationResultInterface {\n\terror = false\n\tresult = MutationResultType.ok as const\n\ttype = ModificationType.create as const\n\thints: MutationResultHint[] = []\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly entity: Model.Entity,\n\t\tpublic readonly primary: Value.PrimaryValue,\n\t\tpublic readonly input: MapperInput.CreateDataInput,\n\t\tpublic readonly values: RowValues,\n\t) {}\n}\n\nexport class MutationDeleteOk implements MutationResultInterface {\n\terror = false\n\tresult = MutationResultType.ok as const\n\ttype = ModificationType.delete as const\n\thints: MutationResultHint[] = []\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly entity: Model.Entity,\n\t\tpublic readonly primary: Value.PrimaryValue,\n\t) {}\n}\n\nexport class MutationJunctionUpdateOk implements MutationResultInterface {\n\terror = false\n\tresult = MutationResultType.ok as const\n\ttype = ModificationType.junctionUpdate as const\n\thints: MutationResultHint[] = []\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly entity: Model.Entity,\n\t\tpublic readonly relation: Model.ManyHasManyOwningRelation,\n\t\tpublic readonly owningUnique: Input.PrimaryValue,\n\t\tpublic readonly inverseUnique: Input.PrimaryValue,\n\t) {}\n}\n\nexport enum NothingToDoReason {\n\tnoData = 'noData',\n\temptyRelation = 'emptyRelation',\n\talreadyExists = 'alreadyExists',\n\taborted = 'aborted',\n\talreadyDeleted = 'alreadyDeleted',\n}\n\nexport class MutationNothingToDo implements MutationResultInterface {\n\terror = false\n\tresult = MutationResultType.nothingToDo as const\n\thints: MutationResultHint[] = []\n\n\tconstructor(public readonly paths: Path[], public readonly reason: NothingToDoReason) {}\n}\n\nexport enum InputErrorKind {\n\tnonUniqueWhere = 'nonUniqueWhere',\n\tinvalidData = 'invalidData',\n}\n\nexport class MutationInputError implements MutationResultInterface {\n\terror = true\n\tresult = MutationResultType.inputError as const\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly kind: InputErrorKind,\n\t\tpublic readonly message?: string,\n\t\tpublic readonly hints: MutationResultHint[] = [],\n\t) {}\n}\n\nexport class MutationSqlError implements MutationResultInterface {\n\terror = true\n\tresult = MutationResultType.sqlError as const\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly message?: string,\n\t\tpublic readonly hints: MutationResultHint[] = [],\n\t) {}\n}\n\nexport enum ConstraintType {\n\tnotNull = 'notNull',\n\tuniqueKey = 'uniqueKey',\n\tforeignKey = 'foreignKey',\n}\n\nexport class MutationConstraintViolationError implements MutationResultInterface {\n\terror = true\n\tresult = MutationResultType.constraintViolationError as const\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly constraint: ConstraintType,\n\t\tpublic readonly message?: string,\n\t\tpublic readonly hints: MutationResultHint[] = [],\n\t) {}\n}\n\n// maybe denied by acl\nexport class MutationEntryNotFoundError implements MutationResultInterface {\n\terror = true\n\tresult = MutationResultType.notFoundError as const\n\thints: MutationResultHint[] = []\n\tmessage: string\n\n\tconstructor(public readonly paths: Path[], public readonly where: Input.UniqueWhere | Input.OptionalWhere) {\n\t\tthis.message = 'for input ' + JSON.stringify(where)\n\t}\n}\n\n// possibly denied by acl\nexport class MutationNoResultError implements MutationResultInterface {\n\terror = true\n\tresult = MutationResultType.noResultError as const\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly message?: string,\n\t\tpublic readonly hints: MutationResultHint[] = [],\n\t) {}\n}\n\nexport const prependPath = (path: Path, results: MutationResultList): MutationResultList =>\n\tresults.map(it => ({\n\t\t...it,\n\t\tpaths: (it.paths.length === 0 ? [[]] : it.paths).map(it => [...path, ...it]),\n\t}))\n\nexport const getInsertPrimary = (result: MutationResultList) =>\n\t!result.some(it => it.error) && result[0] && result[0].result === MutationResultType.ok && result[0].type === ModificationType.create\n\t\t? result[0].primary\n\t\t: undefined\n"],"names":["MutationResultType","MutationResultHint","NothingToDoReason","InputErrorKind","ConstraintType","it"],"mappings":";;;AAGO,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A;AACR;AAAA,MAAA;AAAA,MAAA;AAAA,MAAS;AAAA;AAAA,IAAA;AAAA,EAMN;AACJ;AAEO,MAAM,cAAc,CAAC,MAAY,YACvC,QAAQ,IAAI,CAAA,QAAO;AAAA,EAClB,GAAG;AAAA,EACH,QAAQ,GAAG,MAAM,WAAW,IAAI,CAAC,EAAE,IAAI,GAAG,OAAO,IAAI,CAAAC,QAAM,CAAC,GAAG,MAAM,GAAGA,GAAE,CAAC;AAC5E,EAAE;AAEI,MAAM,mBAAmB,CAAC,WAChC,CAAC,OAAO,KAAK,CAAA,OAAM,GAAG,KAAK,KAAK,OAAO,CAAC,KAAK,OAAO,CAAC,EAAE,WAAW,QAAyB,OAAO,CAAC,EAAE,SAAS,WAC3G,OAAO,CAAC,EAAE,UACV;"}
1
+ {"version":3,"file":"Result.js","sources":["../../../../../packages/engine-content-api/src/mapper/Result.ts"],"sourcesContent":["import { Input, Model, Value } from '@contember/schema'\nimport { MapperInput } from './types.js'\n\nexport enum MutationResultType {\n\tok = 'ok',\n\tnothingToDo = 'nothingToDo',\n\tnotFoundError = 'notFoundError',\n\tconstraintViolationError = 'constraintViolationError',\n\tnoResultError = 'noResultError',\n\tvalidationError = 'validationError',\n\tinputError = 'inputError',\n\tsqlError = 'sqlError',\n}\n\nexport enum MutationResultHint {\n\tsqlError = 'sqlError',\n\tsubSequentSqlError = 'subsequentSqlError',\n}\n\nexport enum ModificationType {\n\tcreate = 'create',\n\tupdate = 'update',\n\tdelete = 'delete',\n\tjunctionUpdate = 'junctionUpdate',\n}\n\nexport type MutationResult =\n\t| MutationUpdateOk\n\t| MutationCreateOk\n\t| MutationDeleteOk\n\t| MutationJunctionUpdateOk\n\t| MutationEntryNotFoundError\n\t| MutationNothingToDo\n\t| MutationConstraintViolationError\n\t| MutationNoResultError\n\t| MutationInputError\n\t| MutationSqlError\n\nexport type MutationResultList = MutationResult[]\n\ntype Path = ({ field: string } | { index: number; alias?: string })[]\n\ninterface MutationResultInterface {\n\terror: boolean\n\tresult: MutationResultType\n\tpaths: Path[]\n\tmessage?: string\n\thints: MutationResultHint[]\n}\n\nexport type RowValues = { [fieldName: string]: Value.FieldValue }\n\nexport class MutationUpdateOk implements MutationResultInterface {\n\terror = false\n\tresult = MutationResultType.ok as const\n\ttype = ModificationType.update as const\n\thints: MutationResultHint[] = []\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly entity: Model.Entity,\n\t\tpublic readonly primary: Value.PrimaryValue,\n\t\tpublic readonly input: MapperInput.UpdateDataInput,\n\t\tpublic readonly values: RowValues,\n\t\tpublic readonly oldValues?: RowValues,\n\t) {}\n}\n\nexport class MutationCreateOk implements MutationResultInterface {\n\terror = false\n\tresult = MutationResultType.ok as const\n\ttype = ModificationType.create as const\n\thints: MutationResultHint[] = []\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly entity: Model.Entity,\n\t\tpublic readonly primary: Value.PrimaryValue,\n\t\tpublic readonly input: MapperInput.CreateDataInput,\n\t\tpublic readonly values: RowValues,\n\t) {}\n}\n\nexport class MutationDeleteOk implements MutationResultInterface {\n\terror = false\n\tresult = MutationResultType.ok as const\n\ttype = ModificationType.delete as const\n\thints: MutationResultHint[] = []\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly entity: Model.Entity,\n\t\tpublic readonly primary: Value.PrimaryValue,\n\t) {}\n}\n\nexport class MutationJunctionUpdateOk implements MutationResultInterface {\n\terror = false\n\tresult = MutationResultType.ok as const\n\ttype = ModificationType.junctionUpdate as const\n\thints: MutationResultHint[] = []\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly entity: Model.Entity,\n\t\tpublic readonly relation: Model.ManyHasManyOwningRelation,\n\t\tpublic readonly owningUnique: Input.PrimaryValue,\n\t\tpublic readonly inverseUnique: Input.PrimaryValue,\n\t) {}\n}\n\nexport enum NothingToDoReason {\n\tnoData = 'noData',\n\temptyRelation = 'emptyRelation',\n\talreadyExists = 'alreadyExists',\n\taborted = 'aborted',\n\talreadyDeleted = 'alreadyDeleted',\n}\n\nexport class MutationNothingToDo implements MutationResultInterface {\n\terror = false\n\tresult = MutationResultType.nothingToDo as const\n\thints: MutationResultHint[] = []\n\n\tconstructor(public readonly paths: Path[], public readonly reason: NothingToDoReason) {}\n}\n\nexport enum InputErrorKind {\n\tnonUniqueWhere = 'nonUniqueWhere',\n\tinvalidData = 'invalidData',\n}\n\nexport class MutationInputError implements MutationResultInterface {\n\terror = true\n\tresult = MutationResultType.inputError as const\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly kind: InputErrorKind,\n\t\tpublic readonly message?: string,\n\t\tpublic readonly hints: MutationResultHint[] = [],\n\t) {}\n}\n\nexport class MutationSqlError implements MutationResultInterface {\n\terror = true\n\tresult = MutationResultType.sqlError as const\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly message?: string,\n\t\tpublic readonly hints: MutationResultHint[] = [],\n\t) {}\n}\n\nexport enum ConstraintType {\n\tnotNull = 'notNull',\n\tuniqueKey = 'uniqueKey',\n\tforeignKey = 'foreignKey',\n\tcheck = 'check',\n}\n\nexport class MutationConstraintViolationError implements MutationResultInterface {\n\terror = true\n\tresult = MutationResultType.constraintViolationError as const\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly constraint: ConstraintType,\n\t\tpublic readonly message?: string,\n\t\tpublic readonly hints: MutationResultHint[] = [],\n\t) {}\n}\n\n// maybe denied by acl\nexport class MutationEntryNotFoundError implements MutationResultInterface {\n\terror = true\n\tresult = MutationResultType.notFoundError as const\n\thints: MutationResultHint[] = []\n\tmessage: string\n\n\tconstructor(public readonly paths: Path[], public readonly where: Input.UniqueWhere | Input.OptionalWhere) {\n\t\tthis.message = 'for input ' + JSON.stringify(where)\n\t}\n}\n\n// possibly denied by acl\nexport class MutationNoResultError implements MutationResultInterface {\n\terror = true\n\tresult = MutationResultType.noResultError as const\n\n\tconstructor(\n\t\tpublic readonly paths: Path[],\n\t\tpublic readonly message?: string,\n\t\tpublic readonly hints: MutationResultHint[] = [],\n\t) {}\n}\n\nexport const prependPath = (path: Path, results: MutationResultList): MutationResultList =>\n\tresults.map(it => ({\n\t\t...it,\n\t\tpaths: (it.paths.length === 0 ? [[]] : it.paths).map(it => [...path, ...it]),\n\t}))\n\nexport const getInsertPrimary = (result: MutationResultList) =>\n\t!result.some(it => it.error) && result[0] && result[0].result === MutationResultType.ok && result[0].type === ModificationType.create\n\t\t? result[0].primary\n\t\t: undefined\n"],"names":["MutationResultType","MutationResultHint","NothingToDoReason","InputErrorKind","ConstraintType","it"],"mappings":";;;AAGO,IAAK,uCAAAA,wBAAL;AACNA,sBAAA,IAAA,IAAK;AACLA,sBAAA,aAAA,IAAc;AACdA,sBAAA,eAAA,IAAgB;AAChBA,sBAAA,0BAAA,IAA2B;AAC3BA,sBAAA,eAAA,IAAgB;AAChBA,sBAAA,iBAAA,IAAkB;AAClBA,sBAAA,YAAA,IAAa;AACbA,sBAAA,UAAA,IAAW;AARA,SAAAA;AAAA,GAAA,sBAAA,CAAA,CAAA;AAWL,IAAK,uCAAAC,wBAAL;AACNA,sBAAA,UAAA,IAAW;AACXA,sBAAA,oBAAA,IAAqB;AAFV,SAAAA;AAAA,GAAA,sBAAA,CAAA,CAAA;AAsCL,MAAM,iBAAoD;AAAA,EAMhE,YACiB,OACA,QACA,SACA,OACA,QACA,WACf;AANe,SAAA,QAAA;AACA,SAAA,SAAA;AACA,SAAA,UAAA;AACA,SAAA,QAAA;AACA,SAAA,SAAA;AACA,SAAA,YAAA;AAXjB,kBAAA,MAAA,SAAQ,KAAA;AACR;AAAA,MAAA;AAAA,MAAA;AAAA,MAAS;AAAA;AAAA,IAAA;AACT;AAAA,MAAA;AAAA,MAAA;AAAA,MAAO;AAAA;AAAA,IAAA;AACP,kBAAA,MAAA,SAA8B,EAAC;AAAA,EAS5B;AACJ;AAEO,MAAM,iBAAoD;AAAA,EAM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O,MAAM,2BAA8D;AAAA,EAM1E,YAA4B,OAA+B,OAAgD;AAA/E,SAAA,QAAA;AAA+B,SAAA,QAAA;AAL3D,kBAAA,MAAA,SAAQ,IAAA;AACR;AAAA,MAAA;AAAA,MAAA;AAAA,MAAS;AAAA;AAAA,IAAA;AACT,kBAAA,MAAA,SAA8B,EAAC;AAC/B,kBAAA,MAAA,SAAA;AAGC,SAAK,UAAU,eAAe,KAAK,UAAU,KAAK;AAAA,EACnD;AACD;AAGO,MAAM,sBAAyD;AAAA,EAIrE,YACiB,OACA,SACA,QAA8B,CAAA,GAC7C;AAHe,SAAA,QAAA;AACA,SAAA,UAAA;AACA,SAAA,QAAA;AANjB,kBAAA,MAAA,SAAQ,IAAA;AACR;AAAA,MAAA;AAAA,MAAA;AAAA,MAAS;AAAA;AAAA,IAAA;AAAA,EAMN;AACJ;AAEO,MAAM,cAAc,CAAC,MAAY,YACvC,QAAQ,IAAI,CAAA,QAAO;AAAA,EAClB,GAAG;AAAA,EACH,QAAQ,GAAG,MAAM,WAAW,IAAI,CAAC,EAAE,IAAI,GAAG,OAAO,IAAI,CAAAC,QAAM,CAAC,GAAG,MAAM,GAAGA,GAAE,CAAC;AAC5E,EAAE;AAEI,MAAM,mBAAmB,CAAC,WAChC,CAAC,OAAO,KAAK,CAAA,OAAM,GAAG,KAAK,KAAK,OAAO,CAAC,KAAK,OAAO,CAAC,EAAE,WAAW,QAAyB,OAAO,CAAC,EAAE,SAAS,WAC3G,OAAO,CAAC,EAAE,UACV;"}
@@ -6,7 +6,7 @@ const assertNever = require("../../utils/assertNever.cjs");
6
6
  const schemaUtils = require("@contember/schema-utils");
7
7
  const Database = require("@contember/database");
8
8
  const AclScope = require("../../acl/AclScope.cjs");
9
- require("fast-deep-equal");
9
+ require("@contember/utilities");
10
10
  require("../../acl/PredicatesInjector.cjs");
11
11
  const Result = require("../Result.cjs");
12
12
  const DeleteState = require("./DeleteState.cjs");
@@ -4,7 +4,7 @@ import { assertNever } from "../../utils/assertNever.js";
4
4
  import { getEntity } from "@contember/schema-utils";
5
5
  import { DeleteBuilder, SelectBuilder, Literal } from "@contember/database";
6
6
  import { ROW_LOOKUP_SCOPE } from "../../acl/AclScope.js";
7
- import "fast-deep-equal";
7
+ import "@contember/utilities";
8
8
  import "../../acl/PredicatesInjector.js";
9
9
  import { MutationNothingToDo, NothingToDoReason, MutationDeleteOk, MutationUpdateOk, MutationNoResultError, MutationEntryNotFoundError, MutationConstraintViolationError, ConstraintType } from "../Result.js";
10
10
  import { DeleteState } from "./DeleteState.js";
@@ -48,8 +48,8 @@ class Path {
48
48
  for(path) {
49
49
  return new Path([...this.path, path], this.aliasContext, this.rootAlias);
50
50
  }
51
- // Segment for a column the engine selects for itself. `$` cannot occur in a GraphQL alias, so these aliases stay
52
- // distinct from those of selected fields; `kind` must not contain `_`.
51
+ // Engine-owned columns share the alias namespace with client GraphQL aliases. `$` is outside the GraphQL Name
52
+ // grammar, so no client alias (nor `_`-joined aliases) can produce the segment; `kind` must not contain `_`.
53
53
  forInternal(kind) {
54
54
  return this.for("$" + kind);
55
55
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Path.cjs","sources":["../../../../../../packages/engine-content-api/src/mapper/select/Path.ts"],"sourcesContent":["const MAX_IDENTIFIER_LENGTH = 63\n\nconst utf8Encoder = new TextEncoder()\nconst byteLength = (value: string): number => utf8Encoder.encode(value).length\n\nexport type HopGuards = { readonly row: boolean; readonly field: boolean }\n\n/**\n * Path segment of a relation hop. JoinBuilder reuses a join by alias, so hops whose joins differ must differ in\n * alias: a read-guarded target source must not be shared with the same relation traversed unguarded (as-definer)\n * by an ACL predicate, and a join restricted by the relation field's guard must not be shared with an order-by\n * hop, which masks that field with CASE instead. `$` cannot occur in a field name, so no alias collides with a field.\n */\nexport const hopPathSegment = (fieldName: string, guards: HopGuards): string =>\n\tguards.field ? `${fieldName}$$` : guards.row ? `${fieldName}$` : fieldName\n\nexport class AliasContext {\n\tprivate aliasIndex = new Map<string, number>()\n\n\tpublic getAliasIndex(alias: string): number {\n\t\tconst index = this.aliasIndex.get(alias)\n\t\tif (index !== undefined) {\n\t\t\treturn index\n\t\t}\n\t\tconst newIndex = this.aliasIndex.size + 1\n\t\tthis.aliasIndex.set(alias, newIndex)\n\t\treturn newIndex\n\t}\n}\n\nexport class PathFactory {\n\tprivate aliasContext = new AliasContext()\n\n\tpublic create(path: string[], rootAlias = 'root_') {\n\t\treturn new Path(path, this.aliasContext, rootAlias)\n\t}\n}\n\nexport class Path {\n\tpublic readonly alias: string\n\n\tconstructor(\n\t\tpublic readonly path: string[],\n\t\tprivate readonly aliasContext: AliasContext,\n\t\tpublic readonly rootAlias = 'root_',\n\t) {\n\t\tthis.alias = this.createAlias()\n\t}\n\n\tpublic get fullAlias() {\n\t\treturn this.rootAlias + this.path.join('_')\n\t}\n\n\tpublic back() {\n\t\tconst newPath = [...this.path]\n\t\tnewPath.pop()\n\t\treturn new Path(newPath, this.aliasContext, this.rootAlias)\n\t}\n\n\tpublic for(path: string) {\n\t\treturn new Path([...this.path, path], this.aliasContext, this.rootAlias)\n\t}\n\n\t// Segment for a column the engine selects for itself. `$` cannot occur in a GraphQL alias, so these aliases stay\n\t// distinct from those of selected fields; `kind` must not contain `_`.\n\tpublic forInternal(kind: string) {\n\t\treturn this.for('$' + kind)\n\t}\n\n\t// PostgreSQL limits identifiers in bytes. Untruncated aliases stay below the limit and truncated ones fill it\n\t// exactly (padded when a multi-byte character does not fit), so the two can never coincide.\n\tprivate createAlias(): string {\n\t\tconst alias = this.fullAlias\n\t\tif (byteLength(alias) < MAX_IDENTIFIER_LENGTH) {\n\t\t\treturn alias\n\t\t}\n\t\tconst suffix = '_' + this.aliasContext.getAliasIndex(alias).toString()\n\t\tconst prefixBytes = MAX_IDENTIFIER_LENGTH - suffix.length\n\t\tlet prefix = ''\n\t\tlet usedBytes = 0\n\t\tfor (const char of alias) {\n\t\t\tconst charBytes = byteLength(char)\n\t\t\tif (usedBytes + charBytes > prefixBytes) {\n\t\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S,KAAK,cAAc,KAAK,SAAS;AAAA,EAC3D;AAAA,EAEO,IAAI,MAAc;AACxB,WAAO,IAAI,KAAK,CAAC,GAAG,KAAK,MAAM,IAAI,GAAG,KAAK,cAAc,KAAK,SAAS;AAAA,EACxE;AAAA;AAAA;AAAA,EAIO,YAAY,MAAc;AAChC,WAAO,KAAK,IAAI,MAAM,IAAI;AAAA,EAC3B;AAAA;AAAA;AAAA,EAIQ,cAAsB;AAC7B,UAAM,QAAQ,KAAK;AACnB,QAAI,WAAW,KAAK,IAAI,uBAAuB;AAC9C,aAAO;AAAA,IACR;AACA,UAAM,SAAS,MAAM,KAAK,aAAa,cAAc,KAAK,EAAE,SAAA;AAC5D,UAAM,cAAc,wBAAwB,OAAO;AACnD,QAAI,SAAS;AACb,QAAI,YAAY;AAChB,eAAW,QAAQ,OAAO;AACzB,YAAM,YAAY,WAAW,IAAI;AACjC,UAAI,YAAY,YAAY,aAAa;AACxC;AAAA,MACD;AACA,gBAAU;AACV,mBAAa;AAAA,IACd;AACA,WAAO,SAAS,IAAI,OAAO,cAAc,SAAS,IAAI;AAAA,EACvD;AACD;;;;;"}
1
+ {"version":3,"file":"Path.cjs","sources":["../../../../../../packages/engine-content-api/src/mapper/select/Path.ts"],"sourcesContent":["const MAX_IDENTIFIER_LENGTH = 63\n\nconst utf8Encoder = new TextEncoder()\nconst byteLength = (value: string): number => utf8Encoder.encode(value).length\n\nexport type HopGuards = { readonly row: boolean; readonly field: boolean }\n\n/**\n * Path segment of a relation hop. JoinBuilder reuses a join by alias, so hops whose joins differ must differ in\n * alias: a read-guarded target source must not be shared with the same relation traversed unguarded (as-definer)\n * by an ACL predicate, and a join restricted by the relation field's guard must not be shared with an order-by\n * hop, which masks that field with CASE instead. `$` cannot occur in a field name, so no alias collides with a field.\n */\nexport const hopPathSegment = (fieldName: string, guards: HopGuards): string =>\n\tguards.field ? `${fieldName}$$` : guards.row ? `${fieldName}$` : fieldName\n\nexport class AliasContext {\n\tprivate aliasIndex = new Map<string, number>()\n\n\tpublic getAliasIndex(alias: string): number {\n\t\tconst index = this.aliasIndex.get(alias)\n\t\tif (index !== undefined) {\n\t\t\treturn index\n\t\t}\n\t\tconst newIndex = this.aliasIndex.size + 1\n\t\tthis.aliasIndex.set(alias, newIndex)\n\t\treturn newIndex\n\t}\n}\n\nexport class PathFactory {\n\tprivate aliasContext = new AliasContext()\n\n\tpublic create(path: string[], rootAlias = 'root_') {\n\t\treturn new Path(path, this.aliasContext, rootAlias)\n\t}\n}\n\nexport class Path {\n\tpublic readonly alias: string\n\n\tconstructor(\n\t\tpublic readonly path: string[],\n\t\tprivate readonly aliasContext: AliasContext,\n\t\tpublic readonly rootAlias = 'root_',\n\t) {\n\t\tthis.alias = this.createAlias()\n\t}\n\n\tpublic get fullAlias() {\n\t\treturn this.rootAlias + this.path.join('_')\n\t}\n\n\tpublic back() {\n\t\tconst newPath = [...this.path]\n\t\tnewPath.pop()\n\t\treturn new Path(newPath, this.aliasContext, this.rootAlias)\n\t}\n\n\tpublic for(path: string) {\n\t\treturn new Path([...this.path, path], this.aliasContext, this.rootAlias)\n\t}\n\n\t// Engine-owned columns share the alias namespace with client GraphQL aliases. `$` is outside the GraphQL Name\n\t// grammar, so no client alias (nor `_`-joined aliases) can produce the segment; `kind` must not contain `_`.\n\tpublic forInternal(kind: string) {\n\t\treturn this.for('$' + kind)\n\t}\n\n\t// PostgreSQL limits identifiers in bytes. Untruncated aliases stay below the limit and truncated ones fill it\n\t// exactly (padded when a multi-byte character does not fit), so the two can never coincide.\n\tprivate createAlias(): string {\n\t\tconst alias = this.fullAlias\n\t\tif (byteLength(alias) < MAX_IDENTIFIER_LENGTH) {\n\t\t\treturn alias\n\t\t}\n\t\tconst suffix = '_' + this.aliasContext.getAliasIndex(alias).toString()\n\t\tconst prefixBytes = MAX_IDENTIFIER_LENGTH - suffix.length\n\t\tlet prefix = ''\n\t\tlet usedBytes = 0\n\t\tfor (const char of alias) {\n\t\t\tconst charBytes = byteLength(char)\n\t\t\tif (usedBytes + charBytes > prefixBytes) {\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tprefix += char\n\t\t\tusedBytes += charBytes\n\t\t}\n\t\treturn prefix + '_'.repeat(prefixBytes - usedBytes) + suffix\n\t}\n}\n"],"names":[],"mappings":";;;;;AAAA,MAAM,wBAAwB;AAE9B,MAAM,cAAc,IAAI,YAAA;AACxB,MAAM,aAAa,CAAC,UAA0B,YAAY,OAAO,KAAK,EAAE;AAUjE,MAAM,iBAAiB,CAAC,WAAmB,WACjD,OAAO,QAAQ,GAAG,SAAS,OAAO,OAAO,MAAM,GAAG,SAAS,MAAM;AAE3D,MAAM,aAAa;AAAA,EAAnB,cAAA;AACN,kBAAA,MAAQ,kCAAiB,IAAA,CAAoB;AAAA,EAAA;AAAA,EAEtC,cAAc,OAAuB;AAC3C,UAAM,QAAQ,KAAK,WAAW,IAAI,KAAK;AACvC,QAAI,UAAU,QAAW;AACxB,aAAO;AAAA,IACR;AACA,UAAM,WAAW,KAAK,WAAW,OAAO;AACxC,SAAK,WAAW,IAAI,OAAO,QAAQ;AACnC,WAAO;AAAA,EACR;AACD;AAEO,MAAM,YAAY;AAAA,EAAlB,cAAA;AACN,kBAAA,MAAQ,gBAAe,IAAI,aAAA,CAAa;AAAA,EAAA;AAAA,EAEjC,OAAO,MAAgB,YAAY,SAAS;AAClD,WAAO,IAAI,KAAK,MAAM,KAAK,cAAc,SAAS;AAAA,EACnD;AACD;AAEO,MAAM,KAAK;AAAA,EAGjB,YACiB,MACC,cACD,YAAY,SAC3B;AAHe,SAAA,OAAA;AACC,SAAA,eAAA;AACD,SAAA,YAAA;AALjB,kBAAA,MAAgB,OAAA;AAOf,SAAK,QAAQ,KAAK,YAAA;AAAA,EACnB;AAAA,EAEA,IAAW,YAAY;AACtB,WAAO,KAAK,YAAY,KAAK,KAAK,KAAK,GAAG;AAAA,EAC3C;AAAA,EAEO,OAAO;AACb,UAAM,UAAU,CAAC,GAAG,KAAK,IAAI;AAC7B,YAAQ,IAAA;AACR,WAAO,IAAI,KAAK,SAAS,KAAK,cAAc,KAAK,SAAS;AAAA,EAC3D;AAAA,EAEO,IAAI,MAAc;AACxB,WAAO,IAAI,KAAK,CAAC,GAAG,KAAK,MAAM,IAAI,GAAG,KAAK,cAAc,KAAK,SAAS;AAAA,EACxE;AAAA;AAAA;AAAA,EAIO,YAAY,MAAc;AAChC,WAAO,KAAK,IAAI,MAAM,IAAI;AAAA,EAC3B;AAAA;AAAA;AAAA,EAIQ,cAAsB;AAC7B,UAAM,QAAQ,KAAK;AACnB,QAAI,WAAW,KAAK,IAAI,uBAAuB;AAC9C,aAAO;AAAA,IACR;AACA,UAAM,SAAS,MAAM,KAAK,aAAa,cAAc,KAAK,EAAE,SAAA;AAC5D,UAAM,cAAc,wBAAwB,OAAO;AACnD,QAAI,SAAS;AACb,QAAI,YAAY;AAChB,eAAW,QAAQ,OAAO;AACzB,YAAM,YAAY,WAAW,IAAI;AACjC,UAAI,YAAY,YAAY,aAAa;AACxC;AAAA,MACD;AACA,gBAAU;AACV,mBAAa;AAAA,IACd;AACA,WAAO,SAAS,IAAI,OAAO,cAAc,SAAS,IAAI;AAAA,EACvD;AACD;;;;;"}
@@ -46,8 +46,8 @@ class Path {
46
46
  for(path) {
47
47
  return new Path([...this.path, path], this.aliasContext, this.rootAlias);
48
48
  }
49
- // Segment for a column the engine selects for itself. `$` cannot occur in a GraphQL alias, so these aliases stay
50
- // distinct from those of selected fields; `kind` must not contain `_`.
49
+ // Engine-owned columns share the alias namespace with client GraphQL aliases. `$` is outside the GraphQL Name
50
+ // grammar, so no client alias (nor `_`-joined aliases) can produce the segment; `kind` must not contain `_`.
51
51
  forInternal(kind) {
52
52
  return this.for("$" + kind);
53
53
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Path.js","sources":["../../../../../../packages/engine-content-api/src/mapper/select/Path.ts"],"sourcesContent":["const MAX_IDENTIFIER_LENGTH = 63\n\nconst utf8Encoder = new TextEncoder()\nconst byteLength = (value: string): number => utf8Encoder.encode(value).length\n\nexport type HopGuards = { readonly row: boolean; readonly field: boolean }\n\n/**\n * Path segment of a relation hop. JoinBuilder reuses a join by alias, so hops whose joins differ must differ in\n * alias: a read-guarded target source must not be shared with the same relation traversed unguarded (as-definer)\n * by an ACL predicate, and a join restricted by the relation field's guard must not be shared with an order-by\n * hop, which masks that field with CASE instead. `$` cannot occur in a field name, so no alias collides with a field.\n */\nexport const hopPathSegment = (fieldName: string, guards: HopGuards): string =>\n\tguards.field ? `${fieldName}$$` : guards.row ? `${fieldName}$` : fieldName\n\nexport class AliasContext {\n\tprivate aliasIndex = new Map<string, number>()\n\n\tpublic getAliasIndex(alias: string): number {\n\t\tconst index = this.aliasIndex.get(alias)\n\t\tif (index !== undefined) {\n\t\t\treturn index\n\t\t}\n\t\tconst newIndex = this.aliasIndex.size + 1\n\t\tthis.aliasIndex.set(alias, newIndex)\n\t\treturn newIndex\n\t}\n}\n\nexport class PathFactory {\n\tprivate aliasContext = new AliasContext()\n\n\tpublic create(path: string[], rootAlias = 'root_') {\n\t\treturn new Path(path, this.aliasContext, rootAlias)\n\t}\n}\n\nexport class Path {\n\tpublic readonly alias: string\n\n\tconstructor(\n\t\tpublic readonly path: string[],\n\t\tprivate readonly aliasContext: AliasContext,\n\t\tpublic readonly rootAlias = 'root_',\n\t) {\n\t\tthis.alias = this.createAlias()\n\t}\n\n\tpublic get fullAlias() {\n\t\treturn this.rootAlias + this.path.join('_')\n\t}\n\n\tpublic back() {\n\t\tconst newPath = [...this.path]\n\t\tnewPath.pop()\n\t\treturn new Path(newPath, this.aliasContext, this.rootAlias)\n\t}\n\n\tpublic for(path: string) {\n\t\treturn new Path([...this.path, path], this.aliasContext, this.rootAlias)\n\t}\n\n\t// Segment for a column the engine selects for itself. `$` cannot occur in a GraphQL alias, so these aliases stay\n\t// distinct from those of selected fields; `kind` must not contain `_`.\n\tpublic forInternal(kind: string) {\n\t\treturn this.for('$' + kind)\n\t}\n\n\t// PostgreSQL limits identifiers in bytes. Untruncated aliases stay below the limit and truncated ones fill it\n\t// exactly (padded when a multi-byte character does not fit), so the two can never coincide.\n\tprivate createAlias(): string {\n\t\tconst alias = this.fullAlias\n\t\tif (byteLength(alias) < MAX_IDENTIFIER_LENGTH) {\n\t\t\treturn alias\n\t\t}\n\t\tconst suffix = '_' + this.aliasContext.getAliasIndex(alias).toString()\n\t\tconst prefixBytes = MAX_IDENTIFIER_LENGTH - suffix.length\n\t\tlet prefix = ''\n\t\tlet usedBytes = 0\n\t\tfor (const char of alias) {\n\t\t\tconst charBytes = byteLength(char)\n\t\t\tif (usedBytes + charBytes > prefixBytes) {\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tprefix += char\n\t\t\tusedBytes += charBytes\n\t\t}\n\t\treturn prefix + '_'.repeat(prefixBytes - usedBytes) + suffix\n\t}\n}\n"],"names":[],"mappings":";;;AAAA,MAAM,wBAAwB;AAE9B,MAAM,cAAc,IAAI,YAAA;AACxB,MAAM,aAAa,CAAC,UAA0B,YAAY,OAAO,KAAK,EAAE;AAUjE,MAAM,iBAAiB,CAAC,WAAmB,WACjD,OAAO,QAAQ,GAAG,SAAS,OAAO,OAAO,MAAM,GAAG,SAAS,MAAM;AAE3D,MAAM,aAAa;AAAA,EAAnB,cAAA;AACN,kBAAA,MAAQ,kCAAiB,IAAA,CAAoB;AAAA,EAAA;AAAA,EAEtC,cAAc,OAAuB;AAC3C,UAAM,QAAQ,KAAK,WAAW,IAAI,KAAK;AACvC,QAAI,UAAU,QAAW;AACxB,aAAO;AAAA,IACR;AACA,UAAM,WAAW,KAAK,WAAW,OAAO;AACxC,SAAK,WAAW,IAAI,OAAO,QAAQ;AACnC,WAAO;AAAA,EACR;AACD;AAEO,MAAM,YAAY;AAAA,EAAlB,cAAA;AACN,kBAAA,MAAQ,gBAAe,IAAI,aAAA,CAAa;AAAA,EAAA;AAAA,EAEjC,OAAO,MAAgB,YAAY,SAAS;AAClD,WAAO,IAAI,KAAK,MAAM,KAAK,cAAc,SAAS;AAAA,EACnD;AACD;AAEO,MAAM,KAAK;AAAA,EAGjB,YACiB,MACC,cACD,YAAY,SAC3B;AAHe,SAAA,OAAA;AACC,SAAA,eAAA;AACD,SAAA,YAAA;AALjB,kBAAA,MAAgB,OAAA;AAOf,SAAK,QAAQ,KAAK,YAAA;AAAA,EACnB;AAAA,EAEA,IAAW,YAAY;AACtB,WAAO,KAAK,YAAY,KAAK,KAAK,KAAK,GAAG;AAAA,EAC3C;AAAA,EAEO,OAAO;AACb,UAAM,UAAU,CAAC,GAAG,KAAK,IAAI;AAC7B,YAAQ,IAAA;AACR,WAAO,IAAI,KAAK,SAAS,KAAK,cAAc,KAAK,SAAS;AAAA,EAC3D;AAAA,EAEO,IAAI,MAAc;AACxB,WAAO,IAAI,KAAK,CAAC,GAAG,KAAK,MAAM,IAAI,GAAG,KAAK,cAAc,KAAK,SAAS;AAAA,EACxE;AAAA;AAAA;AAAA,EAIO,YAAY,MAAc;AAChC,WAAO,KAAK,IAAI,MAAM,IAAI;AAAA,EAC3B;AAAA;AAAA;AAAA,EAIQ,cAAsB;AAC7B,UAAM,QAAQ,KAAK;AACnB,QAAI,WAAW,KAAK,IAAI,uBAAuB;AAC9C,aAAO;AAAA,IACR;AACA,UAAM,SAAS,MAAM,KAAK,aAAa,cAAc,KAAK,EAAE,SAAA;AAC5D,UAAM,cAAc,wBAAwB,OAAO;AACnD,QAAI,SAAS;AACb,QAAI,YAAY;AAChB,eAAW,QAAQ,OAAO;AACzB,YAAM,YAAY,WAAW,IAAI;AACjC,UAAI,YAAY,YAAY,aAAa;AACxC;AAAA,MACD;AACA,gBAAU;AACV,mBAAa;AAAA,IACd;AACA,WAAO,SAAS,IAAI,OAAO,cAAc,SAAS,IAAI;AAAA,EACvD;AACD;"}
1
+ {"version":3,"file":"Path.js","sources":["../../../../../../packages/engine-content-api/src/mapper/select/Path.ts"],"sourcesContent":["const MAX_IDENTIFIER_LENGTH = 63\n\nconst utf8Encoder = new TextEncoder()\nconst byteLength = (value: string): number => utf8Encoder.encode(value).length\n\nexport type HopGuards = { readonly row: boolean; readonly field: boolean }\n\n/**\n * Path segment of a relation hop. JoinBuilder reuses a join by alias, so hops whose joins differ must differ in\n * alias: a read-guarded target source must not be shared with the same relation traversed unguarded (as-definer)\n * by an ACL predicate, and a join restricted by the relation field's guard must not be shared with an order-by\n * hop, which masks that field with CASE instead. `$` cannot occur in a field name, so no alias collides with a field.\n */\nexport const hopPathSegment = (fieldName: string, guards: HopGuards): string =>\n\tguards.field ? `${fieldName}$$` : guards.row ? `${fieldName}$` : fieldName\n\nexport class AliasContext {\n\tprivate aliasIndex = new Map<string, number>()\n\n\tpublic getAliasIndex(alias: string): number {\n\t\tconst index = this.aliasIndex.get(alias)\n\t\tif (index !== undefined) {\n\t\t\treturn index\n\t\t}\n\t\tconst newIndex = this.aliasIndex.size + 1\n\t\tthis.aliasIndex.set(alias, newIndex)\n\t\treturn newIndex\n\t}\n}\n\nexport class PathFactory {\n\tprivate aliasContext = new AliasContext()\n\n\tpublic create(path: string[], rootAlias = 'root_') {\n\t\treturn new Path(path, this.aliasContext, rootAlias)\n\t}\n}\n\nexport class Path {\n\tpublic readonly alias: string\n\n\tconstructor(\n\t\tpublic readonly path: string[],\n\t\tprivate readonly aliasContext: AliasContext,\n\t\tpublic readonly rootAlias = 'root_',\n\t) {\n\t\tthis.alias = this.createAlias()\n\t}\n\n\tpublic get fullAlias() {\n\t\treturn this.rootAlias + this.path.join('_')\n\t}\n\n\tpublic back() {\n\t\tconst newPath = [...this.path]\n\t\tnewPath.pop()\n\t\treturn new Path(newPath, this.aliasContext, this.rootAlias)\n\t}\n\n\tpublic for(path: string) {\n\t\treturn new Path([...this.path, path], this.aliasContext, this.rootAlias)\n\t}\n\n\t// Engine-owned columns share the alias namespace with client GraphQL aliases. `$` is outside the GraphQL Name\n\t// grammar, so no client alias (nor `_`-joined aliases) can produce the segment; `kind` must not contain `_`.\n\tpublic forInternal(kind: string) {\n\t\treturn this.for('$' + kind)\n\t}\n\n\t// PostgreSQL limits identifiers in bytes. Untruncated aliases stay below the limit and truncated ones fill it\n\t// exactly (padded when a multi-byte character does not fit), so the two can never coincide.\n\tprivate createAlias(): string {\n\t\tconst alias = this.fullAlias\n\t\tif (byteLength(alias) < MAX_IDENTIFIER_LENGTH) {\n\t\t\treturn alias\n\t\t}\n\t\tconst suffix = '_' + this.aliasContext.getAliasIndex(alias).toString()\n\t\tconst prefixBytes = MAX_IDENTIFIER_LENGTH - suffix.length\n\t\tlet prefix = ''\n\t\tlet usedBytes = 0\n\t\tfor (const char of alias) {\n\t\t\tconst charBytes = byteLength(char)\n\t\t\tif (usedBytes + charBytes > prefixBytes) {\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tprefix += char\n\t\t\tusedBytes += charBytes\n\t\t}\n\t\treturn prefix + '_'.repeat(prefixBytes - usedBytes) + suffix\n\t}\n}\n"],"names":[],"mappings":";;;AAAA,MAAM,wBAAwB;AAE9B,MAAM,cAAc,IAAI,YAAA;AACxB,MAAM,aAAa,CAAC,UAA0B,YAAY,OAAO,KAAK,EAAE;AAUjE,MAAM,iBAAiB,CAAC,WAAmB,WACjD,OAAO,QAAQ,GAAG,SAAS,OAAO,OAAO,MAAM,GAAG,SAAS,MAAM;AAE3D,MAAM,aAAa;AAAA,EAAnB,cAAA;AACN,kBAAA,MAAQ,kCAAiB,IAAA,CAAoB;AAAA,EAAA;AAAA,EAEtC,cAAc,OAAuB;AAC3C,UAAM,QAAQ,KAAK,WAAW,IAAI,KAAK;AACvC,QAAI,UAAU,QAAW;AACxB,aAAO;AAAA,IACR;AACA,UAAM,WAAW,KAAK,WAAW,OAAO;AACxC,SAAK,WAAW,IAAI,OAAO,QAAQ;AACnC,WAAO;AAAA,EACR;AACD;AAEO,MAAM,YAAY;AAAA,EAAlB,cAAA;AACN,kBAAA,MAAQ,gBAAe,IAAI,aAAA,CAAa;AAAA,EAAA;AAAA,EAEjC,OAAO,MAAgB,YAAY,SAAS;AAClD,WAAO,IAAI,KAAK,MAAM,KAAK,cAAc,SAAS;AAAA,EACnD;AACD;AAEO,MAAM,KAAK;AAAA,EAGjB,YACiB,MACC,cACD,YAAY,SAC3B;AAHe,SAAA,OAAA;AACC,SAAA,eAAA;AACD,SAAA,YAAA;AALjB,kBAAA,MAAgB,OAAA;AAOf,SAAK,QAAQ,KAAK,YAAA;AAAA,EACnB;AAAA,EAEA,IAAW,YAAY;AACtB,WAAO,KAAK,YAAY,KAAK,KAAK,KAAK,GAAG;AAAA,EAC3C;AAAA,EAEO,OAAO;AACb,UAAM,UAAU,CAAC,GAAG,KAAK,IAAI;AAC7B,YAAQ,IAAA;AACR,WAAO,IAAI,KAAK,SAAS,KAAK,cAAc,KAAK,SAAS;AAAA,EAC3D;AAAA,EAEO,IAAI,MAAc;AACxB,WAAO,IAAI,KAAK,CAAC,GAAG,KAAK,MAAM,IAAI,GAAG,KAAK,cAAc,KAAK,SAAS;AAAA,EACxE;AAAA;AAAA;AAAA,EAIO,YAAY,MAAc;AAChC,WAAO,KAAK,IAAI,MAAM,IAAI;AAAA,EAC3B;AAAA;AAAA;AAAA,EAIQ,cAAsB;AAC7B,UAAM,QAAQ,KAAK;AACnB,QAAI,WAAW,KAAK,IAAI,uBAAuB;AAC9C,aAAO;AAAA,IACR;AACA,UAAM,SAAS,MAAM,KAAK,aAAa,cAAc,KAAK,EAAE,SAAA;AAC5D,UAAM,cAAc,wBAAwB,OAAO;AACnD,QAAI,SAAS;AACb,QAAI,YAAY;AAChB,eAAW,QAAQ,OAAO;AACzB,YAAM,YAAY,WAAW,IAAI;AACjC,UAAI,YAAY,YAAY,aAAa;AACxC;AAAA,MACD;AACA,gBAAU;AACV,mBAAa;AAAA,IACd;AACA,WAAO,SAAS,IAAI,OAAO,cAAc,SAAS,IAAI;AAAA,EACvD;AACD;"}
@@ -3,7 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const schema = require("@contember/schema");
4
4
  const AclScope = require("../../../acl/AclScope.cjs");
5
5
  require("@contember/schema-utils");
6
- require("fast-deep-equal");
6
+ require("@contember/utilities");
7
7
  require("../../../acl/PredicatesInjector.cjs");
8
8
  class MetaHandler {
9
9
  constructor(whereBuilder, predicateFactory) {
@@ -1,7 +1,7 @@
1
1
  import { Input, Acl } from "@contember/schema";
2
2
  import { aclScopeFromPath } from "../../../acl/AclScope.js";
3
3
  import "@contember/schema-utils";
4
- import "fast-deep-equal";
4
+ import "@contember/utilities";
5
5
  import "../../../acl/PredicatesInjector.js";
6
6
  class MetaHandler {
7
7
  constructor(whereBuilder, predicateFactory) {
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const schema = require("@contember/schema");
4
4
  const schemaUtils = require("@contember/schema-utils");
5
- const deepEqual = require("fast-deep-equal");
5
+ const utilities = require("@contember/utilities");
6
6
  const helpers = require("./helpers.cjs");
7
7
  const WhereReplacer = require("./WhereReplacer.cjs");
8
8
  const PredicatesInjector = require("../../../acl/PredicatesInjector.cjs");
@@ -110,7 +110,7 @@ const _WhereOptimizer = class _WhereOptimizer2 {
110
110
  }
111
111
  /** Replaces every part of `where` equal to a fact with TRUE, following the facts into to-one relations. */
112
112
  replaceFacts(where, facts, entity) {
113
- if (facts.some((fact) => deepEqual(where, fact))) {
113
+ if (facts.some((fact) => utilities.deepEqual(where, fact))) {
114
114
  return { [entity.primary]: { always: true } };
115
115
  }
116
116
  let result = where;
@@ -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":";;;;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per/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,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,UAAU;AACd,UAAM,QAA+B,CAAA;AACrC,eAAW,aAAa,qBAAqB;AAC5C,YAAM,qBAAqB,KAAK,SAAS,WAAW,MAAM;AAC1D,YAAM,KAAK,kBAAkB;AAC7B,YAAM,YAAYC,cAAAA,aAAa,QAAQ,oBAAoB,EAAE,CAAC,OAAO,OAA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AA,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,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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e,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,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,aA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