@contember/engine-content-api 2.2.0-alpha.11 → 2.2.0-alpha.12

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 (636) hide show
  1. package/CLAUDE.md +1 -1
  2. package/dist/development/index.cjs +10 -0
  3. package/dist/development/index.cjs.map +1 -1
  4. package/dist/development/index.js +12 -2
  5. package/dist/development/index.js.map +1 -1
  6. package/dist/development/src/ExecutionContainer.cjs +6 -3
  7. package/dist/development/src/ExecutionContainer.cjs.map +1 -1
  8. package/dist/development/src/ExecutionContainer.js +6 -3
  9. package/dist/development/src/ExecutionContainer.js.map +1 -1
  10. package/dist/development/src/acl/AclScope.cjs +7 -0
  11. package/dist/development/src/acl/AclScope.cjs.map +1 -0
  12. package/dist/development/src/acl/AclScope.js +7 -0
  13. package/dist/development/src/acl/AclScope.js.map +1 -0
  14. package/dist/development/src/acl/Authorizator.cjs +0 -3
  15. package/dist/development/src/acl/Authorizator.cjs.map +1 -1
  16. package/dist/development/src/acl/Authorizator.js +0 -3
  17. package/dist/development/src/acl/Authorizator.js.map +1 -1
  18. package/dist/development/src/acl/EvaluatedPredicateReplacer.cjs +4 -1
  19. package/dist/development/src/acl/EvaluatedPredicateReplacer.cjs.map +1 -1
  20. package/dist/development/src/acl/EvaluatedPredicateReplacer.js +4 -1
  21. package/dist/development/src/acl/EvaluatedPredicateReplacer.js.map +1 -1
  22. package/dist/development/src/acl/PermissionFactory.cjs +50 -68
  23. package/dist/development/src/acl/PermissionFactory.cjs.map +1 -1
  24. package/dist/development/src/acl/PermissionFactory.js +51 -69
  25. package/dist/development/src/acl/PermissionFactory.js.map +1 -1
  26. package/dist/development/src/acl/PredicateFactory.cjs +95 -26
  27. package/dist/development/src/acl/PredicateFactory.cjs.map +1 -1
  28. package/dist/development/src/acl/PredicateFactory.js +95 -26
  29. package/dist/development/src/acl/PredicateFactory.js.map +1 -1
  30. package/dist/development/src/acl/PredicatesInjector.cjs +97 -32
  31. package/dist/development/src/acl/PredicatesInjector.cjs.map +1 -1
  32. package/dist/development/src/acl/PredicatesInjector.js +99 -34
  33. package/dist/development/src/acl/PredicatesInjector.js.map +1 -1
  34. package/dist/development/src/acl/VariableInjector.cjs +7 -2
  35. package/dist/development/src/acl/VariableInjector.cjs.map +1 -1
  36. package/dist/development/src/acl/VariableInjector.js +7 -2
  37. package/dist/development/src/acl/VariableInjector.js.map +1 -1
  38. package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.cjs +26 -2
  39. package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.cjs.map +1 -1
  40. package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.js +27 -3
  41. package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.js.map +1 -1
  42. package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.cjs +11 -1
  43. package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.cjs.map +1 -1
  44. package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.js +11 -1
  45. package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.js.map +1 -1
  46. package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.cjs +27 -3
  47. package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.cjs.map +1 -1
  48. package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.js +27 -3
  49. package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.js.map +1 -1
  50. package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.cjs +10 -0
  51. package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.cjs.map +1 -1
  52. package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.js +10 -0
  53. package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.js.map +1 -1
  54. package/dist/development/src/input-validation/ValidationDataSelector.cjs +2 -2
  55. package/dist/development/src/input-validation/ValidationDataSelector.cjs.map +1 -1
  56. package/dist/development/src/input-validation/ValidationDataSelector.js +2 -2
  57. package/dist/development/src/input-validation/ValidationDataSelector.js.map +1 -1
  58. package/dist/development/src/mapper/JunctionTableManager.cjs +18 -12
  59. package/dist/development/src/mapper/JunctionTableManager.cjs.map +1 -1
  60. package/dist/development/src/mapper/JunctionTableManager.js +19 -13
  61. package/dist/development/src/mapper/JunctionTableManager.js.map +1 -1
  62. package/dist/development/src/mapper/Mapper.cjs +65 -31
  63. package/dist/development/src/mapper/Mapper.cjs.map +1 -1
  64. package/dist/development/src/mapper/Mapper.js +65 -31
  65. package/dist/development/src/mapper/Mapper.js.map +1 -1
  66. package/dist/development/src/mapper/delete/DeleteExecutor.cjs +15 -8
  67. package/dist/development/src/mapper/delete/DeleteExecutor.cjs.map +1 -1
  68. package/dist/development/src/mapper/delete/DeleteExecutor.js +15 -8
  69. package/dist/development/src/mapper/delete/DeleteExecutor.js.map +1 -1
  70. package/dist/development/src/mapper/insert/InsertBuilder.cjs +3 -2
  71. package/dist/development/src/mapper/insert/InsertBuilder.cjs.map +1 -1
  72. package/dist/development/src/mapper/insert/InsertBuilder.js +3 -2
  73. package/dist/development/src/mapper/insert/InsertBuilder.js.map +1 -1
  74. package/dist/development/src/mapper/insert/InsertBuilderFactory.cjs +2 -2
  75. package/dist/development/src/mapper/insert/InsertBuilderFactory.cjs.map +1 -1
  76. package/dist/development/src/mapper/insert/InsertBuilderFactory.js +2 -2
  77. package/dist/development/src/mapper/insert/InsertBuilderFactory.js.map +1 -1
  78. package/dist/development/src/mapper/insert/Inserter.cjs +3 -3
  79. package/dist/development/src/mapper/insert/Inserter.cjs.map +1 -1
  80. package/dist/development/src/mapper/insert/Inserter.js +3 -3
  81. package/dist/development/src/mapper/insert/Inserter.js.map +1 -1
  82. package/dist/development/src/mapper/insert/SqlCreateInputProcessor.cjs +3 -2
  83. package/dist/development/src/mapper/insert/SqlCreateInputProcessor.cjs.map +1 -1
  84. package/dist/development/src/mapper/insert/SqlCreateInputProcessor.js +3 -2
  85. package/dist/development/src/mapper/insert/SqlCreateInputProcessor.js.map +1 -1
  86. package/dist/development/src/mapper/insert/relations/ManyHasManyCreateInputProcessor.cjs +9 -8
  87. package/dist/development/src/mapper/insert/relations/ManyHasManyCreateInputProcessor.cjs.map +1 -1
  88. package/dist/development/src/mapper/insert/relations/ManyHasManyCreateInputProcessor.js +9 -8
  89. package/dist/development/src/mapper/insert/relations/ManyHasManyCreateInputProcessor.js.map +1 -1
  90. package/dist/development/src/mapper/insert/relations/ManyHasOneCreateInputProcessor.cjs +4 -4
  91. package/dist/development/src/mapper/insert/relations/ManyHasOneCreateInputProcessor.cjs.map +1 -1
  92. package/dist/development/src/mapper/insert/relations/ManyHasOneCreateInputProcessor.js +4 -4
  93. package/dist/development/src/mapper/insert/relations/ManyHasOneCreateInputProcessor.js.map +1 -1
  94. package/dist/development/src/mapper/insert/relations/OneHasManyCreateInputProcessor.cjs +3 -3
  95. package/dist/development/src/mapper/insert/relations/OneHasManyCreateInputProcessor.cjs.map +1 -1
  96. package/dist/development/src/mapper/insert/relations/OneHasManyCreateInputProcessor.js +3 -3
  97. package/dist/development/src/mapper/insert/relations/OneHasManyCreateInputProcessor.js.map +1 -1
  98. package/dist/development/src/mapper/insert/relations/OneHasOneInverseCreateInputProcessor.cjs +7 -7
  99. package/dist/development/src/mapper/insert/relations/OneHasOneInverseCreateInputProcessor.cjs.map +1 -1
  100. package/dist/development/src/mapper/insert/relations/OneHasOneInverseCreateInputProcessor.js +7 -7
  101. package/dist/development/src/mapper/insert/relations/OneHasOneInverseCreateInputProcessor.js.map +1 -1
  102. package/dist/development/src/mapper/insert/relations/OneHasOneOwningCreateInputProcessor.cjs +6 -6
  103. package/dist/development/src/mapper/insert/relations/OneHasOneOwningCreateInputProcessor.cjs.map +1 -1
  104. package/dist/development/src/mapper/insert/relations/OneHasOneOwningCreateInputProcessor.js +6 -6
  105. package/dist/development/src/mapper/insert/relations/OneHasOneOwningCreateInputProcessor.js.map +1 -1
  106. package/dist/development/src/mapper/select/JoinBuilder.cjs +26 -4
  107. package/dist/development/src/mapper/select/JoinBuilder.cjs.map +1 -1
  108. package/dist/development/src/mapper/select/JoinBuilder.js +27 -5
  109. package/dist/development/src/mapper/select/JoinBuilder.js.map +1 -1
  110. package/dist/development/src/mapper/select/OrderByBuilder.cjs +81 -13
  111. package/dist/development/src/mapper/select/OrderByBuilder.cjs.map +1 -1
  112. package/dist/development/src/mapper/select/OrderByBuilder.js +83 -15
  113. package/dist/development/src/mapper/select/OrderByBuilder.js.map +1 -1
  114. package/dist/development/src/mapper/select/Path.cjs +2 -0
  115. package/dist/development/src/mapper/select/Path.cjs.map +1 -1
  116. package/dist/development/src/mapper/select/Path.js +3 -1
  117. package/dist/development/src/mapper/select/Path.js.map +1 -1
  118. package/dist/development/src/mapper/select/RelationFetcher.cjs +3 -2
  119. package/dist/development/src/mapper/select/RelationFetcher.cjs.map +1 -1
  120. package/dist/development/src/mapper/select/RelationFetcher.js +3 -2
  121. package/dist/development/src/mapper/select/RelationFetcher.js.map +1 -1
  122. package/dist/development/src/mapper/select/SelectBuilder.cjs +10 -16
  123. package/dist/development/src/mapper/select/SelectBuilder.cjs.map +1 -1
  124. package/dist/development/src/mapper/select/SelectBuilder.js +8 -14
  125. package/dist/development/src/mapper/select/SelectBuilder.js.map +1 -1
  126. package/dist/development/src/mapper/select/WhereBuilder.cjs +261 -47
  127. package/dist/development/src/mapper/select/WhereBuilder.cjs.map +1 -1
  128. package/dist/development/src/mapper/select/WhereBuilder.js +262 -48
  129. package/dist/development/src/mapper/select/WhereBuilder.js.map +1 -1
  130. package/dist/development/src/mapper/select/getFieldReadPredicate.cjs +8 -0
  131. package/dist/development/src/mapper/select/getFieldReadPredicate.cjs.map +1 -0
  132. package/dist/development/src/mapper/select/getFieldReadPredicate.js +8 -0
  133. package/dist/development/src/mapper/select/getFieldReadPredicate.js.map +1 -0
  134. package/dist/development/src/mapper/select/handlers/FieldsVisitor.cjs +8 -12
  135. package/dist/development/src/mapper/select/handlers/FieldsVisitor.cjs.map +1 -1
  136. package/dist/development/src/mapper/select/handlers/FieldsVisitor.js +9 -13
  137. package/dist/development/src/mapper/select/handlers/FieldsVisitor.js.map +1 -1
  138. package/dist/development/src/mapper/select/handlers/MetaHandler.cjs +6 -2
  139. package/dist/development/src/mapper/select/handlers/MetaHandler.cjs.map +1 -1
  140. package/dist/development/src/mapper/select/handlers/MetaHandler.js +6 -2
  141. package/dist/development/src/mapper/select/handlers/MetaHandler.js.map +1 -1
  142. package/dist/development/src/mapper/select/optimizer/WhereOptimizer.cjs +229 -3
  143. package/dist/development/src/mapper/select/optimizer/WhereOptimizer.cjs.map +1 -1
  144. package/dist/development/src/mapper/select/optimizer/WhereOptimizer.js +230 -4
  145. package/dist/development/src/mapper/select/optimizer/WhereOptimizer.js.map +1 -1
  146. package/dist/development/src/mapper/update/SqlUpdateInputProcessor.cjs +3 -2
  147. package/dist/development/src/mapper/update/SqlUpdateInputProcessor.cjs.map +1 -1
  148. package/dist/development/src/mapper/update/SqlUpdateInputProcessor.js +3 -2
  149. package/dist/development/src/mapper/update/SqlUpdateInputProcessor.js.map +1 -1
  150. package/dist/development/src/mapper/update/UpdateBuilder.cjs +35 -2
  151. package/dist/development/src/mapper/update/UpdateBuilder.cjs.map +1 -1
  152. package/dist/development/src/mapper/update/UpdateBuilder.js +36 -3
  153. package/dist/development/src/mapper/update/UpdateBuilder.js.map +1 -1
  154. package/dist/development/src/mapper/update/UpdateBuilderFactory.cjs +3 -2
  155. package/dist/development/src/mapper/update/UpdateBuilderFactory.cjs.map +1 -1
  156. package/dist/development/src/mapper/update/UpdateBuilderFactory.js +3 -2
  157. package/dist/development/src/mapper/update/UpdateBuilderFactory.js.map +1 -1
  158. package/dist/development/src/mapper/update/Updater.cjs +12 -6
  159. package/dist/development/src/mapper/update/Updater.cjs.map +1 -1
  160. package/dist/development/src/mapper/update/Updater.js +13 -7
  161. package/dist/development/src/mapper/update/Updater.js.map +1 -1
  162. package/dist/development/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.cjs +27 -19
  163. package/dist/development/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.cjs.map +1 -1
  164. package/dist/development/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.js +27 -19
  165. package/dist/development/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.js.map +1 -1
  166. package/dist/development/src/mapper/update/relations/ManyHasOneUpdateInputProcessor.cjs +13 -11
  167. package/dist/development/src/mapper/update/relations/ManyHasOneUpdateInputProcessor.cjs.map +1 -1
  168. package/dist/development/src/mapper/update/relations/ManyHasOneUpdateInputProcessor.js +13 -11
  169. package/dist/development/src/mapper/update/relations/ManyHasOneUpdateInputProcessor.js.map +1 -1
  170. package/dist/development/src/mapper/update/relations/OneHasManyUpdateInputProcessor.cjs +11 -8
  171. package/dist/development/src/mapper/update/relations/OneHasManyUpdateInputProcessor.cjs.map +1 -1
  172. package/dist/development/src/mapper/update/relations/OneHasManyUpdateInputProcessor.js +11 -8
  173. package/dist/development/src/mapper/update/relations/OneHasManyUpdateInputProcessor.js.map +1 -1
  174. package/dist/development/src/mapper/update/relations/OneHasOneInverseUpdateInputProcessor.cjs +19 -16
  175. package/dist/development/src/mapper/update/relations/OneHasOneInverseUpdateInputProcessor.cjs.map +1 -1
  176. package/dist/development/src/mapper/update/relations/OneHasOneInverseUpdateInputProcessor.js +19 -16
  177. package/dist/development/src/mapper/update/relations/OneHasOneInverseUpdateInputProcessor.js.map +1 -1
  178. package/dist/development/src/mapper/update/relations/OneHasOneOwningUpdateInputProcessor.cjs +19 -16
  179. package/dist/development/src/mapper/update/relations/OneHasOneOwningUpdateInputProcessor.cjs.map +1 -1
  180. package/dist/development/src/mapper/update/relations/OneHasOneOwningUpdateInputProcessor.js +19 -16
  181. package/dist/development/src/mapper/update/relations/OneHasOneOwningUpdateInputProcessor.js.map +1 -1
  182. package/dist/development/src/resolvers/MutationResolver.cjs +6 -5
  183. package/dist/development/src/resolvers/MutationResolver.cjs.map +1 -1
  184. package/dist/development/src/resolvers/MutationResolver.js +6 -5
  185. package/dist/development/src/resolvers/MutationResolver.js.map +1 -1
  186. package/dist/development/src/resolvers/ReadHelpers.cjs +12 -2
  187. package/dist/development/src/resolvers/ReadHelpers.cjs.map +1 -1
  188. package/dist/development/src/resolvers/ReadHelpers.js +12 -2
  189. package/dist/development/src/resolvers/ReadHelpers.js.map +1 -1
  190. package/dist/development/src/schema/EntityTypeProvider.cjs +3 -2
  191. package/dist/development/src/schema/EntityTypeProvider.cjs.map +1 -1
  192. package/dist/development/src/schema/EntityTypeProvider.js +3 -2
  193. package/dist/development/src/schema/EntityTypeProvider.js.map +1 -1
  194. package/dist/development/src/schema/GraphQlSchemaBuilderFactory.cjs +38 -11
  195. package/dist/development/src/schema/GraphQlSchemaBuilderFactory.cjs.map +1 -1
  196. package/dist/development/src/schema/GraphQlSchemaBuilderFactory.js +38 -11
  197. package/dist/development/src/schema/GraphQlSchemaBuilderFactory.js.map +1 -1
  198. package/dist/development/src/schema/MutationProvider.cjs +13 -8
  199. package/dist/development/src/schema/MutationProvider.cjs.map +1 -1
  200. package/dist/development/src/schema/MutationProvider.js +13 -8
  201. package/dist/development/src/schema/MutationProvider.js.map +1 -1
  202. package/dist/development/src/schema/QueryProvider.cjs +3 -5
  203. package/dist/development/src/schema/QueryProvider.cjs.map +1 -1
  204. package/dist/development/src/schema/QueryProvider.js +3 -5
  205. package/dist/development/src/schema/QueryProvider.js.map +1 -1
  206. package/dist/development/src/schema/entities/FieldTypeVisitor.cjs +15 -2
  207. package/dist/development/src/schema/entities/FieldTypeVisitor.cjs.map +1 -1
  208. package/dist/development/src/schema/entities/FieldTypeVisitor.js +15 -2
  209. package/dist/development/src/schema/entities/FieldTypeVisitor.js.map +1 -1
  210. package/dist/production/index.cjs +10 -0
  211. package/dist/production/index.cjs.map +1 -1
  212. package/dist/production/index.js +12 -2
  213. package/dist/production/index.js.map +1 -1
  214. package/dist/production/src/ExecutionContainer.cjs +6 -3
  215. package/dist/production/src/ExecutionContainer.cjs.map +1 -1
  216. package/dist/production/src/ExecutionContainer.js +6 -3
  217. package/dist/production/src/ExecutionContainer.js.map +1 -1
  218. package/dist/production/src/acl/AclScope.cjs +7 -0
  219. package/dist/production/src/acl/AclScope.cjs.map +1 -0
  220. package/dist/production/src/acl/AclScope.js +7 -0
  221. package/dist/production/src/acl/AclScope.js.map +1 -0
  222. package/dist/production/src/acl/Authorizator.cjs +0 -3
  223. package/dist/production/src/acl/Authorizator.cjs.map +1 -1
  224. package/dist/production/src/acl/Authorizator.js +0 -3
  225. package/dist/production/src/acl/Authorizator.js.map +1 -1
  226. package/dist/production/src/acl/EvaluatedPredicateReplacer.cjs +4 -1
  227. package/dist/production/src/acl/EvaluatedPredicateReplacer.cjs.map +1 -1
  228. package/dist/production/src/acl/EvaluatedPredicateReplacer.js +4 -1
  229. package/dist/production/src/acl/EvaluatedPredicateReplacer.js.map +1 -1
  230. package/dist/production/src/acl/PermissionFactory.cjs +50 -68
  231. package/dist/production/src/acl/PermissionFactory.cjs.map +1 -1
  232. package/dist/production/src/acl/PermissionFactory.js +51 -69
  233. package/dist/production/src/acl/PermissionFactory.js.map +1 -1
  234. package/dist/production/src/acl/PredicateFactory.cjs +95 -26
  235. package/dist/production/src/acl/PredicateFactory.cjs.map +1 -1
  236. package/dist/production/src/acl/PredicateFactory.js +95 -26
  237. package/dist/production/src/acl/PredicateFactory.js.map +1 -1
  238. package/dist/production/src/acl/PredicatesInjector.cjs +97 -32
  239. package/dist/production/src/acl/PredicatesInjector.cjs.map +1 -1
  240. package/dist/production/src/acl/PredicatesInjector.js +99 -34
  241. package/dist/production/src/acl/PredicatesInjector.js.map +1 -1
  242. package/dist/production/src/acl/VariableInjector.cjs +7 -2
  243. package/dist/production/src/acl/VariableInjector.cjs.map +1 -1
  244. package/dist/production/src/acl/VariableInjector.js +7 -2
  245. package/dist/production/src/acl/VariableInjector.js.map +1 -1
  246. package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.cjs +26 -2
  247. package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.cjs.map +1 -1
  248. package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.js +27 -3
  249. package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.js.map +1 -1
  250. package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.cjs +11 -1
  251. package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.cjs.map +1 -1
  252. package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.js +11 -1
  253. package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.js.map +1 -1
  254. package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.cjs +27 -3
  255. package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.cjs.map +1 -1
  256. package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.js +27 -3
  257. package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.js.map +1 -1
  258. package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.cjs +10 -0
  259. package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.cjs.map +1 -1
  260. package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.js +10 -0
  261. package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.js.map +1 -1
  262. package/dist/production/src/input-validation/ValidationDataSelector.cjs +2 -2
  263. package/dist/production/src/input-validation/ValidationDataSelector.cjs.map +1 -1
  264. package/dist/production/src/input-validation/ValidationDataSelector.js +2 -2
  265. package/dist/production/src/input-validation/ValidationDataSelector.js.map +1 -1
  266. package/dist/production/src/mapper/JunctionTableManager.cjs +18 -12
  267. package/dist/production/src/mapper/JunctionTableManager.cjs.map +1 -1
  268. package/dist/production/src/mapper/JunctionTableManager.js +19 -13
  269. package/dist/production/src/mapper/JunctionTableManager.js.map +1 -1
  270. package/dist/production/src/mapper/Mapper.cjs +65 -31
  271. package/dist/production/src/mapper/Mapper.cjs.map +1 -1
  272. package/dist/production/src/mapper/Mapper.js +65 -31
  273. package/dist/production/src/mapper/Mapper.js.map +1 -1
  274. package/dist/production/src/mapper/delete/DeleteExecutor.cjs +15 -8
  275. package/dist/production/src/mapper/delete/DeleteExecutor.cjs.map +1 -1
  276. package/dist/production/src/mapper/delete/DeleteExecutor.js +15 -8
  277. package/dist/production/src/mapper/delete/DeleteExecutor.js.map +1 -1
  278. package/dist/production/src/mapper/insert/InsertBuilder.cjs +3 -2
  279. package/dist/production/src/mapper/insert/InsertBuilder.cjs.map +1 -1
  280. package/dist/production/src/mapper/insert/InsertBuilder.js +3 -2
  281. package/dist/production/src/mapper/insert/InsertBuilder.js.map +1 -1
  282. package/dist/production/src/mapper/insert/InsertBuilderFactory.cjs +2 -2
  283. package/dist/production/src/mapper/insert/InsertBuilderFactory.cjs.map +1 -1
  284. package/dist/production/src/mapper/insert/InsertBuilderFactory.js +2 -2
  285. package/dist/production/src/mapper/insert/InsertBuilderFactory.js.map +1 -1
  286. package/dist/production/src/mapper/insert/Inserter.cjs +3 -3
  287. package/dist/production/src/mapper/insert/Inserter.cjs.map +1 -1
  288. package/dist/production/src/mapper/insert/Inserter.js +3 -3
  289. package/dist/production/src/mapper/insert/Inserter.js.map +1 -1
  290. package/dist/production/src/mapper/insert/SqlCreateInputProcessor.cjs +3 -2
  291. package/dist/production/src/mapper/insert/SqlCreateInputProcessor.cjs.map +1 -1
  292. package/dist/production/src/mapper/insert/SqlCreateInputProcessor.js +3 -2
  293. package/dist/production/src/mapper/insert/SqlCreateInputProcessor.js.map +1 -1
  294. package/dist/production/src/mapper/insert/relations/ManyHasManyCreateInputProcessor.cjs +9 -8
  295. package/dist/production/src/mapper/insert/relations/ManyHasManyCreateInputProcessor.cjs.map +1 -1
  296. package/dist/production/src/mapper/insert/relations/ManyHasManyCreateInputProcessor.js +9 -8
  297. package/dist/production/src/mapper/insert/relations/ManyHasManyCreateInputProcessor.js.map +1 -1
  298. package/dist/production/src/mapper/insert/relations/ManyHasOneCreateInputProcessor.cjs +4 -4
  299. package/dist/production/src/mapper/insert/relations/ManyHasOneCreateInputProcessor.cjs.map +1 -1
  300. package/dist/production/src/mapper/insert/relations/ManyHasOneCreateInputProcessor.js +4 -4
  301. package/dist/production/src/mapper/insert/relations/ManyHasOneCreateInputProcessor.js.map +1 -1
  302. package/dist/production/src/mapper/insert/relations/OneHasManyCreateInputProcessor.cjs +3 -3
  303. package/dist/production/src/mapper/insert/relations/OneHasManyCreateInputProcessor.cjs.map +1 -1
  304. package/dist/production/src/mapper/insert/relations/OneHasManyCreateInputProcessor.js +3 -3
  305. package/dist/production/src/mapper/insert/relations/OneHasManyCreateInputProcessor.js.map +1 -1
  306. package/dist/production/src/mapper/insert/relations/OneHasOneInverseCreateInputProcessor.cjs +7 -7
  307. package/dist/production/src/mapper/insert/relations/OneHasOneInverseCreateInputProcessor.cjs.map +1 -1
  308. package/dist/production/src/mapper/insert/relations/OneHasOneInverseCreateInputProcessor.js +7 -7
  309. package/dist/production/src/mapper/insert/relations/OneHasOneInverseCreateInputProcessor.js.map +1 -1
  310. package/dist/production/src/mapper/insert/relations/OneHasOneOwningCreateInputProcessor.cjs +6 -6
  311. package/dist/production/src/mapper/insert/relations/OneHasOneOwningCreateInputProcessor.cjs.map +1 -1
  312. package/dist/production/src/mapper/insert/relations/OneHasOneOwningCreateInputProcessor.js +6 -6
  313. package/dist/production/src/mapper/insert/relations/OneHasOneOwningCreateInputProcessor.js.map +1 -1
  314. package/dist/production/src/mapper/select/JoinBuilder.cjs +26 -4
  315. package/dist/production/src/mapper/select/JoinBuilder.cjs.map +1 -1
  316. package/dist/production/src/mapper/select/JoinBuilder.js +27 -5
  317. package/dist/production/src/mapper/select/JoinBuilder.js.map +1 -1
  318. package/dist/production/src/mapper/select/OrderByBuilder.cjs +81 -13
  319. package/dist/production/src/mapper/select/OrderByBuilder.cjs.map +1 -1
  320. package/dist/production/src/mapper/select/OrderByBuilder.js +83 -15
  321. package/dist/production/src/mapper/select/OrderByBuilder.js.map +1 -1
  322. package/dist/production/src/mapper/select/Path.cjs +2 -0
  323. package/dist/production/src/mapper/select/Path.cjs.map +1 -1
  324. package/dist/production/src/mapper/select/Path.js +3 -1
  325. package/dist/production/src/mapper/select/Path.js.map +1 -1
  326. package/dist/production/src/mapper/select/RelationFetcher.cjs +3 -2
  327. package/dist/production/src/mapper/select/RelationFetcher.cjs.map +1 -1
  328. package/dist/production/src/mapper/select/RelationFetcher.js +3 -2
  329. package/dist/production/src/mapper/select/RelationFetcher.js.map +1 -1
  330. package/dist/production/src/mapper/select/SelectBuilder.cjs +10 -16
  331. package/dist/production/src/mapper/select/SelectBuilder.cjs.map +1 -1
  332. package/dist/production/src/mapper/select/SelectBuilder.js +8 -14
  333. package/dist/production/src/mapper/select/SelectBuilder.js.map +1 -1
  334. package/dist/production/src/mapper/select/WhereBuilder.cjs +261 -47
  335. package/dist/production/src/mapper/select/WhereBuilder.cjs.map +1 -1
  336. package/dist/production/src/mapper/select/WhereBuilder.js +262 -48
  337. package/dist/production/src/mapper/select/WhereBuilder.js.map +1 -1
  338. package/dist/production/src/mapper/select/getFieldReadPredicate.cjs +8 -0
  339. package/dist/production/src/mapper/select/getFieldReadPredicate.cjs.map +1 -0
  340. package/dist/production/src/mapper/select/getFieldReadPredicate.js +8 -0
  341. package/dist/production/src/mapper/select/getFieldReadPredicate.js.map +1 -0
  342. package/dist/production/src/mapper/select/handlers/FieldsVisitor.cjs +8 -12
  343. package/dist/production/src/mapper/select/handlers/FieldsVisitor.cjs.map +1 -1
  344. package/dist/production/src/mapper/select/handlers/FieldsVisitor.js +9 -13
  345. package/dist/production/src/mapper/select/handlers/FieldsVisitor.js.map +1 -1
  346. package/dist/production/src/mapper/select/handlers/MetaHandler.cjs +6 -2
  347. package/dist/production/src/mapper/select/handlers/MetaHandler.cjs.map +1 -1
  348. package/dist/production/src/mapper/select/handlers/MetaHandler.js +6 -2
  349. package/dist/production/src/mapper/select/handlers/MetaHandler.js.map +1 -1
  350. package/dist/production/src/mapper/select/optimizer/WhereOptimizer.cjs +229 -3
  351. package/dist/production/src/mapper/select/optimizer/WhereOptimizer.cjs.map +1 -1
  352. package/dist/production/src/mapper/select/optimizer/WhereOptimizer.js +230 -4
  353. package/dist/production/src/mapper/select/optimizer/WhereOptimizer.js.map +1 -1
  354. package/dist/production/src/mapper/update/SqlUpdateInputProcessor.cjs +3 -2
  355. package/dist/production/src/mapper/update/SqlUpdateInputProcessor.cjs.map +1 -1
  356. package/dist/production/src/mapper/update/SqlUpdateInputProcessor.js +3 -2
  357. package/dist/production/src/mapper/update/SqlUpdateInputProcessor.js.map +1 -1
  358. package/dist/production/src/mapper/update/UpdateBuilder.cjs +35 -2
  359. package/dist/production/src/mapper/update/UpdateBuilder.cjs.map +1 -1
  360. package/dist/production/src/mapper/update/UpdateBuilder.js +36 -3
  361. package/dist/production/src/mapper/update/UpdateBuilder.js.map +1 -1
  362. package/dist/production/src/mapper/update/UpdateBuilderFactory.cjs +3 -2
  363. package/dist/production/src/mapper/update/UpdateBuilderFactory.cjs.map +1 -1
  364. package/dist/production/src/mapper/update/UpdateBuilderFactory.js +3 -2
  365. package/dist/production/src/mapper/update/UpdateBuilderFactory.js.map +1 -1
  366. package/dist/production/src/mapper/update/Updater.cjs +12 -6
  367. package/dist/production/src/mapper/update/Updater.cjs.map +1 -1
  368. package/dist/production/src/mapper/update/Updater.js +13 -7
  369. package/dist/production/src/mapper/update/Updater.js.map +1 -1
  370. package/dist/production/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.cjs +27 -19
  371. package/dist/production/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.cjs.map +1 -1
  372. package/dist/production/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.js +27 -19
  373. package/dist/production/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.js.map +1 -1
  374. package/dist/production/src/mapper/update/relations/ManyHasOneUpdateInputProcessor.cjs +13 -11
  375. package/dist/production/src/mapper/update/relations/ManyHasOneUpdateInputProcessor.cjs.map +1 -1
  376. package/dist/production/src/mapper/update/relations/ManyHasOneUpdateInputProcessor.js +13 -11
  377. package/dist/production/src/mapper/update/relations/ManyHasOneUpdateInputProcessor.js.map +1 -1
  378. package/dist/production/src/mapper/update/relations/OneHasManyUpdateInputProcessor.cjs +11 -8
  379. package/dist/production/src/mapper/update/relations/OneHasManyUpdateInputProcessor.cjs.map +1 -1
  380. package/dist/production/src/mapper/update/relations/OneHasManyUpdateInputProcessor.js +11 -8
  381. package/dist/production/src/mapper/update/relations/OneHasManyUpdateInputProcessor.js.map +1 -1
  382. package/dist/production/src/mapper/update/relations/OneHasOneInverseUpdateInputProcessor.cjs +19 -16
  383. package/dist/production/src/mapper/update/relations/OneHasOneInverseUpdateInputProcessor.cjs.map +1 -1
  384. package/dist/production/src/mapper/update/relations/OneHasOneInverseUpdateInputProcessor.js +19 -16
  385. package/dist/production/src/mapper/update/relations/OneHasOneInverseUpdateInputProcessor.js.map +1 -1
  386. package/dist/production/src/mapper/update/relations/OneHasOneOwningUpdateInputProcessor.cjs +19 -16
  387. package/dist/production/src/mapper/update/relations/OneHasOneOwningUpdateInputProcessor.cjs.map +1 -1
  388. package/dist/production/src/mapper/update/relations/OneHasOneOwningUpdateInputProcessor.js +19 -16
  389. package/dist/production/src/mapper/update/relations/OneHasOneOwningUpdateInputProcessor.js.map +1 -1
  390. package/dist/production/src/resolvers/MutationResolver.cjs +6 -5
  391. package/dist/production/src/resolvers/MutationResolver.cjs.map +1 -1
  392. package/dist/production/src/resolvers/MutationResolver.js +6 -5
  393. package/dist/production/src/resolvers/MutationResolver.js.map +1 -1
  394. package/dist/production/src/resolvers/ReadHelpers.cjs +12 -2
  395. package/dist/production/src/resolvers/ReadHelpers.cjs.map +1 -1
  396. package/dist/production/src/resolvers/ReadHelpers.js +12 -2
  397. package/dist/production/src/resolvers/ReadHelpers.js.map +1 -1
  398. package/dist/production/src/schema/EntityTypeProvider.cjs +3 -2
  399. package/dist/production/src/schema/EntityTypeProvider.cjs.map +1 -1
  400. package/dist/production/src/schema/EntityTypeProvider.js +3 -2
  401. package/dist/production/src/schema/EntityTypeProvider.js.map +1 -1
  402. package/dist/production/src/schema/GraphQlSchemaBuilderFactory.cjs +38 -11
  403. package/dist/production/src/schema/GraphQlSchemaBuilderFactory.cjs.map +1 -1
  404. package/dist/production/src/schema/GraphQlSchemaBuilderFactory.js +38 -11
  405. package/dist/production/src/schema/GraphQlSchemaBuilderFactory.js.map +1 -1
  406. package/dist/production/src/schema/MutationProvider.cjs +13 -8
  407. package/dist/production/src/schema/MutationProvider.cjs.map +1 -1
  408. package/dist/production/src/schema/MutationProvider.js +13 -8
  409. package/dist/production/src/schema/MutationProvider.js.map +1 -1
  410. package/dist/production/src/schema/QueryProvider.cjs +3 -5
  411. package/dist/production/src/schema/QueryProvider.cjs.map +1 -1
  412. package/dist/production/src/schema/QueryProvider.js +3 -5
  413. package/dist/production/src/schema/QueryProvider.js.map +1 -1
  414. package/dist/production/src/schema/entities/FieldTypeVisitor.cjs +15 -2
  415. package/dist/production/src/schema/entities/FieldTypeVisitor.cjs.map +1 -1
  416. package/dist/production/src/schema/entities/FieldTypeVisitor.js +15 -2
  417. package/dist/production/src/schema/entities/FieldTypeVisitor.js.map +1 -1
  418. package/dist/tests/cases/integration/graphQlRequests/delete/acl/throughScope.test.d.ts +2 -0
  419. package/dist/tests/cases/integration/graphQlRequests/delete/acl/throughScope.test.d.ts.map +1 -0
  420. package/dist/tests/cases/integration/graphQlRequests/insert/acl/throughScope.test.d.ts +2 -0
  421. package/dist/tests/cases/integration/graphQlRequests/insert/acl/throughScope.test.d.ts.map +1 -0
  422. package/dist/tests/cases/integration/graphQlRequests/query/acl/hasManyCellPredicate.test.d.ts +2 -0
  423. package/dist/tests/cases/integration/graphQlRequests/query/acl/hasManyCellPredicate.test.d.ts.map +1 -0
  424. package/dist/tests/cases/integration/graphQlRequests/query/acl/impliedReadGuard.test.d.ts +2 -0
  425. package/dist/tests/cases/integration/graphQlRequests/query/acl/impliedReadGuard.test.d.ts.map +1 -0
  426. package/dist/tests/cases/integration/graphQlRequests/query/acl/manyHasManyGuardedJoin.test.d.ts +2 -0
  427. package/dist/tests/cases/integration/graphQlRequests/query/acl/manyHasManyGuardedJoin.test.d.ts.map +1 -0
  428. package/dist/tests/cases/integration/graphQlRequests/query/acl/maskedRelationField.test.d.ts +2 -0
  429. package/dist/tests/cases/integration/graphQlRequests/query/acl/maskedRelationField.test.d.ts.map +1 -0
  430. package/dist/tests/cases/integration/graphQlRequests/query/acl/metaReadableThroughContext.test.d.ts +2 -0
  431. package/dist/tests/cases/integration/graphQlRequests/query/acl/metaReadableThroughContext.test.d.ts.map +1 -0
  432. package/dist/tests/cases/integration/graphQlRequests/query/acl/negationAcrossSubquery.test.d.ts +2 -0
  433. package/dist/tests/cases/integration/graphQlRequests/query/acl/negationAcrossSubquery.test.d.ts.map +1 -0
  434. package/dist/tests/cases/integration/graphQlRequests/query/acl/nonAdjacentBackReference.test.d.ts +2 -0
  435. package/dist/tests/cases/integration/graphQlRequests/query/acl/nonAdjacentBackReference.test.d.ts.map +1 -0
  436. package/dist/tests/cases/integration/graphQlRequests/query/acl/notOverGuardedHop.test.d.ts +2 -0
  437. package/dist/tests/cases/integration/graphQlRequests/query/acl/notOverGuardedHop.test.d.ts.map +1 -0
  438. package/dist/tests/cases/integration/graphQlRequests/query/acl/notOverOrCellPredicate.test.d.ts +2 -0
  439. package/dist/tests/cases/integration/graphQlRequests/query/acl/notOverOrCellPredicate.test.d.ts.map +1 -0
  440. package/dist/tests/cases/integration/graphQlRequests/query/acl/orderByCellPredicate.test.d.ts +2 -0
  441. package/dist/tests/cases/integration/graphQlRequests/query/acl/orderByCellPredicate.test.d.ts.map +1 -0
  442. package/dist/tests/cases/integration/graphQlRequests/query/acl/throughScope.test.d.ts +2 -0
  443. package/dist/tests/cases/integration/graphQlRequests/query/acl/throughScope.test.d.ts.map +1 -0
  444. package/dist/tests/cases/integration/graphQlRequests/query/acl/throughScopeFilter.test.d.ts +2 -0
  445. package/dist/tests/cases/integration/graphQlRequests/query/acl/throughScopeFilter.test.d.ts.map +1 -0
  446. package/dist/tests/cases/integration/graphQlRequests/query/acl/throughScopeNullability.test.d.ts +2 -0
  447. package/dist/tests/cases/integration/graphQlRequests/query/acl/throughScopeNullability.test.d.ts.map +1 -0
  448. package/dist/tests/cases/integration/graphQlRequests/query/filter/hasOneDataViewFilter.test.d.ts +2 -0
  449. package/dist/tests/cases/integration/graphQlRequests/query/filter/hasOneDataViewFilter.test.d.ts.map +1 -0
  450. package/dist/tests/cases/integration/graphQlRequests/update/acl/legacyNoRootRootWrites.test.d.ts +2 -0
  451. package/dist/tests/cases/integration/graphQlRequests/update/acl/legacyNoRootRootWrites.test.d.ts.map +1 -0
  452. package/dist/tests/cases/integration/graphQlRequests/update/acl/throughScope.test.d.ts +2 -0
  453. package/dist/tests/cases/integration/graphQlRequests/update/acl/throughScope.test.d.ts.map +1 -0
  454. package/dist/tests/cases/integration/graphQlRequests/update/acl/throughScopeJunction.test.d.ts +2 -0
  455. package/dist/tests/cases/integration/graphQlRequests/update/acl/throughScopeJunction.test.d.ts.map +1 -0
  456. package/dist/tests/cases/integration/graphQlRequests/update/acl/throughScopeLookup.test.d.ts +2 -0
  457. package/dist/tests/cases/integration/graphQlRequests/update/acl/throughScopeLookup.test.d.ts.map +1 -0
  458. package/dist/tests/cases/integration/graphQlRequests/update/acl/throughScopeRootWrites.test.d.ts +2 -0
  459. package/dist/tests/cases/integration/graphQlRequests/update/acl/throughScopeRootWrites.test.d.ts.map +1 -0
  460. package/dist/tests/cases/integration/graphQlRequests/update/acl/throughScopeUpdate.test.d.ts +2 -0
  461. package/dist/tests/cases/integration/graphQlRequests/update/acl/throughScopeUpdate.test.d.ts.map +1 -0
  462. package/dist/tests/cases/integration/graphQlRequests/upsert/acl/throughScope.test.d.ts +2 -0
  463. package/dist/tests/cases/integration/graphQlRequests/upsert/acl/throughScope.test.d.ts.map +1 -0
  464. package/dist/tests/src/test.d.ts +2 -0
  465. package/dist/tests/src/test.d.ts.map +1 -1
  466. package/dist/tests/tsconfig.tsbuildinfo +1 -1
  467. package/dist/types/ExecutionContainer.d.ts.map +1 -1
  468. package/dist/types/acl/AclScope.d.ts +26 -0
  469. package/dist/types/acl/AclScope.d.ts.map +1 -0
  470. package/dist/types/acl/Authorizator.d.ts +0 -1
  471. package/dist/types/acl/Authorizator.d.ts.map +1 -1
  472. package/dist/types/acl/EvaluatedPredicateReplacer.d.ts +1 -0
  473. package/dist/types/acl/EvaluatedPredicateReplacer.d.ts.map +1 -1
  474. package/dist/types/acl/PermissionFactory.d.ts +17 -4
  475. package/dist/types/acl/PermissionFactory.d.ts.map +1 -1
  476. package/dist/types/acl/PredicateFactory.d.ts +31 -15
  477. package/dist/types/acl/PredicateFactory.d.ts.map +1 -1
  478. package/dist/types/acl/PredicatesInjector.d.ts +67 -7
  479. package/dist/types/acl/PredicatesInjector.d.ts.map +1 -1
  480. package/dist/types/acl/VariableInjector.d.ts.map +1 -1
  481. package/dist/types/acl/index.d.ts +1 -0
  482. package/dist/types/acl/index.d.ts.map +1 -1
  483. package/dist/types/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.d.ts +3 -1
  484. package/dist/types/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.d.ts.map +1 -1
  485. package/dist/types/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.d.ts +3 -1
  486. package/dist/types/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.d.ts.map +1 -1
  487. package/dist/types/input-validation/ValidationDataSelector.d.ts +2 -1
  488. package/dist/types/input-validation/ValidationDataSelector.d.ts.map +1 -1
  489. package/dist/types/mapper/JunctionTableManager.d.ts +17 -5
  490. package/dist/types/mapper/JunctionTableManager.d.ts.map +1 -1
  491. package/dist/types/mapper/Mapper.d.ts +16 -11
  492. package/dist/types/mapper/Mapper.d.ts.map +1 -1
  493. package/dist/types/mapper/delete/DeleteExecutor.d.ts +6 -2
  494. package/dist/types/mapper/delete/DeleteExecutor.d.ts.map +1 -1
  495. package/dist/types/mapper/insert/InsertBuilder.d.ts +3 -2
  496. package/dist/types/mapper/insert/InsertBuilder.d.ts.map +1 -1
  497. package/dist/types/mapper/insert/InsertBuilderFactory.d.ts +2 -2
  498. package/dist/types/mapper/insert/InsertBuilderFactory.d.ts.map +1 -1
  499. package/dist/types/mapper/insert/Inserter.d.ts +2 -1
  500. package/dist/types/mapper/insert/Inserter.d.ts.map +1 -1
  501. package/dist/types/mapper/insert/SqlCreateInputProcessor.d.ts +6 -1
  502. package/dist/types/mapper/insert/SqlCreateInputProcessor.d.ts.map +1 -1
  503. package/dist/types/mapper/insert/relations/ManyHasManyCreateInputProcessor.d.ts +6 -1
  504. package/dist/types/mapper/insert/relations/ManyHasManyCreateInputProcessor.d.ts.map +1 -1
  505. package/dist/types/mapper/select/JoinBuilder.d.ts +8 -2
  506. package/dist/types/mapper/select/JoinBuilder.d.ts.map +1 -1
  507. package/dist/types/mapper/select/OrderByBuilder.d.ts +18 -2
  508. package/dist/types/mapper/select/OrderByBuilder.d.ts.map +1 -1
  509. package/dist/types/mapper/select/Path.d.ts +11 -0
  510. package/dist/types/mapper/select/Path.d.ts.map +1 -1
  511. package/dist/types/mapper/select/RelationFetcher.d.ts.map +1 -1
  512. package/dist/types/mapper/select/SelectBuilder.d.ts.map +1 -1
  513. package/dist/types/mapper/select/SelectExecutionHandler.d.ts +5 -0
  514. package/dist/types/mapper/select/SelectExecutionHandler.d.ts.map +1 -1
  515. package/dist/types/mapper/select/WhereBuilder.d.ts +33 -1
  516. package/dist/types/mapper/select/WhereBuilder.d.ts.map +1 -1
  517. package/dist/types/mapper/select/getFieldReadPredicate.d.ts +4 -0
  518. package/dist/types/mapper/select/getFieldReadPredicate.d.ts.map +1 -0
  519. package/dist/types/mapper/select/handlers/FieldsVisitor.d.ts +0 -1
  520. package/dist/types/mapper/select/handlers/FieldsVisitor.d.ts.map +1 -1
  521. package/dist/types/mapper/select/handlers/MetaHandler.d.ts.map +1 -1
  522. package/dist/types/mapper/select/index.d.ts +1 -0
  523. package/dist/types/mapper/select/index.d.ts.map +1 -1
  524. package/dist/types/mapper/select/optimizer/WhereOptimizer.d.ts +36 -0
  525. package/dist/types/mapper/select/optimizer/WhereOptimizer.d.ts.map +1 -1
  526. package/dist/types/mapper/update/SqlUpdateInputProcessor.d.ts +6 -1
  527. package/dist/types/mapper/update/SqlUpdateInputProcessor.d.ts.map +1 -1
  528. package/dist/types/mapper/update/UpdateBuilder.d.ts +18 -2
  529. package/dist/types/mapper/update/UpdateBuilder.d.ts.map +1 -1
  530. package/dist/types/mapper/update/UpdateBuilderFactory.d.ts +2 -2
  531. package/dist/types/mapper/update/UpdateBuilderFactory.d.ts.map +1 -1
  532. package/dist/types/mapper/update/Updater.d.ts +3 -2
  533. package/dist/types/mapper/update/Updater.d.ts.map +1 -1
  534. package/dist/types/mapper/update/relations/ManyHasManyUpdateInputProcessor.d.ts +8 -1
  535. package/dist/types/mapper/update/relations/ManyHasManyUpdateInputProcessor.d.ts.map +1 -1
  536. package/dist/types/mapper/update/relations/ManyHasOneUpdateInputProcessor.d.ts.map +1 -1
  537. package/dist/types/mapper/update/relations/OneHasManyUpdateInputProcessor.d.ts.map +1 -1
  538. package/dist/types/mapper/update/relations/OneHasOneInverseUpdateInputProcessor.d.ts.map +1 -1
  539. package/dist/types/mapper/update/relations/OneHasOneOwningUpdateInputProcessor.d.ts.map +1 -1
  540. package/dist/types/schema/EntityTypeProvider.d.ts +2 -1
  541. package/dist/types/schema/EntityTypeProvider.d.ts.map +1 -1
  542. package/dist/types/schema/GraphQlSchemaBuilderFactory.d.ts +10 -2
  543. package/dist/types/schema/GraphQlSchemaBuilderFactory.d.ts.map +1 -1
  544. package/dist/types/schema/MutationProvider.d.ts +7 -1
  545. package/dist/types/schema/MutationProvider.d.ts.map +1 -1
  546. package/dist/types/schema/QueryProvider.d.ts +2 -1
  547. package/dist/types/schema/QueryProvider.d.ts.map +1 -1
  548. package/dist/types/schema/entities/FieldTypeVisitor.d.ts +4 -1
  549. package/dist/types/schema/entities/FieldTypeVisitor.d.ts.map +1 -1
  550. package/dist/types/tsconfig.tsbuildinfo +1 -1
  551. package/package.json +9 -9
  552. package/src/ExecutionContainer.ts +8 -3
  553. package/src/acl/AclScope.ts +29 -0
  554. package/src/acl/Authorizator.ts +0 -4
  555. package/src/acl/EvaluatedPredicateReplacer.ts +6 -2
  556. package/src/acl/PermissionFactory.ts +59 -104
  557. package/src/acl/PredicateFactory.ts +131 -28
  558. package/src/acl/PredicatesInjector.ts +135 -53
  559. package/src/acl/VariableInjector.ts +8 -3
  560. package/src/acl/index.ts +1 -0
  561. package/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.ts +14 -3
  562. package/src/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.ts +10 -2
  563. package/src/input-validation/ValidationDataSelector.ts +3 -2
  564. package/src/mapper/JunctionTableManager.ts +28 -6
  565. package/src/mapper/Mapper.ts +67 -23
  566. package/src/mapper/delete/DeleteExecutor.ts +13 -7
  567. package/src/mapper/insert/InsertBuilder.ts +3 -2
  568. package/src/mapper/insert/InsertBuilderFactory.ts +3 -3
  569. package/src/mapper/insert/Inserter.ts +4 -2
  570. package/src/mapper/insert/SqlCreateInputProcessor.ts +4 -1
  571. package/src/mapper/insert/relations/ManyHasManyCreateInputProcessor.ts +10 -7
  572. package/src/mapper/insert/relations/ManyHasOneCreateInputProcessor.ts +4 -4
  573. package/src/mapper/insert/relations/OneHasManyCreateInputProcessor.ts +3 -3
  574. package/src/mapper/insert/relations/OneHasOneInverseCreateInputProcessor.ts +7 -7
  575. package/src/mapper/insert/relations/OneHasOneOwningCreateInputProcessor.ts +6 -6
  576. package/src/mapper/select/JoinBuilder.ts +39 -6
  577. package/src/mapper/select/OrderByBuilder.ts +137 -17
  578. package/src/mapper/select/Path.ts +11 -0
  579. package/src/mapper/select/RelationFetcher.ts +4 -1
  580. package/src/mapper/select/SelectBuilder.ts +7 -16
  581. package/src/mapper/select/SelectExecutionHandler.ts +5 -0
  582. package/src/mapper/select/WhereBuilder.ts +322 -50
  583. package/src/mapper/select/getFieldReadPredicate.ts +12 -0
  584. package/src/mapper/select/handlers/FieldsVisitor.ts +9 -14
  585. package/src/mapper/select/handlers/MetaHandler.ts +5 -3
  586. package/src/mapper/select/index.ts +1 -0
  587. package/src/mapper/select/optimizer/WhereOptimizer.ts +279 -6
  588. package/src/mapper/update/SqlUpdateInputProcessor.ts +4 -1
  589. package/src/mapper/update/UpdateBuilder.ts +41 -3
  590. package/src/mapper/update/UpdateBuilderFactory.ts +3 -2
  591. package/src/mapper/update/Updater.ts +11 -4
  592. package/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.ts +29 -18
  593. package/src/mapper/update/relations/ManyHasOneUpdateInputProcessor.ts +11 -9
  594. package/src/mapper/update/relations/OneHasManyUpdateInputProcessor.ts +8 -5
  595. package/src/mapper/update/relations/OneHasOneInverseUpdateInputProcessor.ts +16 -13
  596. package/src/mapper/update/relations/OneHasOneOwningUpdateInputProcessor.ts +16 -13
  597. package/src/resolvers/MutationResolver.ts +4 -4
  598. package/src/resolvers/ReadHelpers.ts +1 -1
  599. package/src/schema/EntityTypeProvider.ts +2 -1
  600. package/src/schema/GraphQlSchemaBuilderFactory.ts +24 -8
  601. package/src/schema/MutationProvider.ts +16 -8
  602. package/src/schema/QueryProvider.ts +4 -4
  603. package/src/schema/entities/FieldTypeVisitor.ts +17 -1
  604. package/tests/cases/integration/graphQlRequests/delete/acl/throughScope.test.ts +320 -0
  605. package/tests/cases/integration/graphQlRequests/insert/acl/throughScope.test.ts +502 -0
  606. package/tests/cases/integration/graphQlRequests/query/acl/hasManyCellPredicate.test.ts +54 -0
  607. package/tests/cases/integration/graphQlRequests/query/acl/impliedReadGuard.test.ts +142 -0
  608. package/tests/cases/integration/graphQlRequests/query/acl/isNullAcl.test.ts +7 -4
  609. package/tests/cases/integration/graphQlRequests/query/acl/manyHasManyGuardedJoin.test.ts +64 -0
  610. package/tests/cases/integration/graphQlRequests/query/acl/maskedRelationField.test.ts +124 -0
  611. package/tests/cases/integration/graphQlRequests/query/acl/metaReadableThroughContext.test.ts +315 -0
  612. package/tests/cases/integration/graphQlRequests/query/acl/negationAcrossSubquery.test.ts +55 -0
  613. package/tests/cases/integration/graphQlRequests/query/acl/nonAdjacentBackReference.test.ts +141 -0
  614. package/tests/cases/integration/graphQlRequests/query/acl/notOverGuardedHop.test.ts +320 -0
  615. package/tests/cases/integration/graphQlRequests/query/acl/notOverOrCellPredicate.test.ts +156 -0
  616. package/tests/cases/integration/graphQlRequests/query/acl/orderByCellPredicate.test.ts +513 -0
  617. package/tests/cases/integration/graphQlRequests/query/acl/throughScope.test.ts +348 -0
  618. package/tests/cases/integration/graphQlRequests/query/acl/throughScopeFilter.test.ts +203 -0
  619. package/tests/cases/integration/graphQlRequests/query/acl/throughScopeNullability.test.ts +127 -0
  620. package/tests/cases/integration/graphQlRequests/query/filter/hasOneDataViewFilter.test.ts +79 -0
  621. package/tests/cases/integration/graphQlRequests/update/acl/legacyNoRootRootWrites.test.ts +127 -0
  622. package/tests/cases/integration/graphQlRequests/update/acl/throughScope.test.ts +89 -0
  623. package/tests/cases/integration/graphQlRequests/update/acl/throughScopeJunction.test.ts +296 -0
  624. package/tests/cases/integration/graphQlRequests/update/acl/throughScopeLookup.test.ts +265 -0
  625. package/tests/cases/integration/graphQlRequests/update/acl/throughScopeRootWrites.test.ts +441 -0
  626. package/tests/cases/integration/graphQlRequests/update/acl/throughScopeUpdate.test.ts +415 -0
  627. package/tests/cases/integration/graphQlRequests/upsert/acl/throughScope.test.ts +134 -0
  628. package/tests/cases/integration/graphQlSchema/graphQlSchemaBuilder.test.ts +129 -5
  629. package/tests/cases/integration/graphQlSchema/schema-mixed-root-through.gql +265 -0
  630. package/tests/cases/integration/graphQlSchema/schema-not-null-through.gql +201 -0
  631. package/tests/cases/unit/permissionMerger.test.ts +947 -13
  632. package/tests/cases/unit/predicatesFactory.test.ts +7 -16
  633. package/tests/cases/unit/predicatesInjector.test.ts +1031 -116
  634. package/tests/cases/unit/variableInjector.test.ts +12 -0
  635. package/tests/cases/unit/whereOptimizer.test.ts +62 -0
  636. package/tests/src/test.ts +8 -2
@@ -1,6 +1,8 @@
1
1
  import { isIt } from "../../utils/isIt.js";
2
2
  import { acceptFieldVisitor, isColumn } from "@contember/schema-utils";
3
- import { SelectBuilder, Literal, wrapIdentifier, Operator } from "@contember/database";
3
+ import { hopPathSegment } from "./Path.js";
4
+ import { Literal, ConditionBuilder, SelectBuilder, wrapIdentifier, Compiler, Operator } from "@contember/database";
5
+ import { MASKED_CELL_KEY, parseMaskedCells, splitReadGuard } from "../../acl/PredicatesInjector.js";
4
6
  class WhereBuilder {
5
7
  constructor(schema, joinBuilder, conditionBuilder, pathFactory, whereOptimizer, useExistsInHasManyFilter) {
6
8
  this.schema = schema;
@@ -30,6 +32,47 @@ class WhereBuilder {
30
32
  allowManyJoin: false
31
33
  });
32
34
  }
35
+ /**
36
+ * Compiles a where into a single boolean SQL condition (a `Literal`), applying any relation joins it needs
37
+ * to `qb`. Shared by the read-predicate consumers that need the condition as an expression rather than a
38
+ * WHERE clause: the projection predicate column (selected as a boolean) and the order-by guard (wrapped in
39
+ * `CASE WHEN <condition> THEN <column> END`). An empty/trivially-true predicate compiles to `true`.
40
+ */
41
+ buildConditionLiteral(qb, entity, path, where, optimizationHints = {}) {
42
+ let condition = new Literal("true");
43
+ const resultQb = this.buildAdvanced(
44
+ entity,
45
+ path,
46
+ where,
47
+ (applyCondition) => {
48
+ condition = ConditionBuilder.process((clause) => {
49
+ const applied = applyCondition(clause);
50
+ return applied.isEmpty() ? applied.raw("true") : applied;
51
+ }).getSql() ?? new Literal("true");
52
+ return qb;
53
+ },
54
+ optimizationHints
55
+ );
56
+ return { qb: resultQb, condition };
57
+ }
58
+ /**
59
+ * The table source of a relation hop restricted to rows satisfying `guard` (the target's row-level read
60
+ * predicate): `(select <alias>.* from <table> as <alias> where <guard>)`. LEFT JOINing this source
61
+ * null-extends an unreadable row exactly like an absent one. The guard is compiled as-definer — its own
62
+ * relation hops are plain joins — and Postgres pulls the subquery up into the outer join tree.
63
+ */
64
+ buildGuardedSource(entity, path, guard) {
65
+ const qb = SelectBuilder.create().select((expr) => expr.raw(`${wrapIdentifier(path.alias)}.*`)).from(entity.tableName, path.alias);
66
+ const guarded = this.buildInternal({
67
+ entity,
68
+ path,
69
+ where: this.whereOptimizer.optimize(guard, entity),
70
+ callback: (cb) => qb.where((clause) => cb(clause)),
71
+ allowManyJoin: false
72
+ });
73
+ const query = guarded.createQuery(new Compiler.Context(Compiler.SCHEMA_PLACEHOLDER, /* @__PURE__ */ new Set()));
74
+ return new Literal(`(${query.sql})`, query.parameters);
75
+ }
33
76
  buildInternal({
34
77
  callback,
35
78
  ...args
@@ -39,11 +82,12 @@ class WhereBuilder {
39
82
  (clause) => this.buildRecursive({
40
83
  conditionBuilder: clause,
41
84
  joinList,
42
- ...args
85
+ ...args,
86
+ negated: false
43
87
  })
44
88
  );
45
89
  return joinList.reduce(
46
- (qb, { path, entity, relationName }) => this.joinBuilder.join(qb, path, entity, relationName),
90
+ (qb, { path, entity, relationName, targetSource, joinCondition }) => this.joinBuilder.join(qb, path, entity, relationName, targetSource, joinCondition),
47
91
  qbWithWhere
48
92
  );
49
93
  }
@@ -53,7 +97,8 @@ class WhereBuilder {
53
97
  path,
54
98
  where,
55
99
  joinList,
56
- allowManyJoin
100
+ allowManyJoin,
101
+ negated
57
102
  }) {
58
103
  const tableName = path.alias;
59
104
  if (where.and !== void 0 && where.and !== null && where.and.length > 0) {
@@ -66,7 +111,8 @@ class WhereBuilder {
66
111
  path,
67
112
  where: where2,
68
113
  joinList,
69
- allowManyJoin
114
+ allowManyJoin,
115
+ negated
70
116
  }),
71
117
  clause
72
118
  )
@@ -83,7 +129,8 @@ class WhereBuilder {
83
129
  path,
84
130
  where: where2,
85
131
  joinList,
86
- allowManyJoin
132
+ allowManyJoin,
133
+ negated
87
134
  })
88
135
  ),
89
136
  clause
@@ -99,7 +146,8 @@ class WhereBuilder {
99
146
  path,
100
147
  where: expr,
101
148
  joinList,
102
- allowManyJoin
149
+ allowManyJoin,
150
+ negated: !negated
103
151
  })
104
152
  );
105
153
  }
@@ -111,13 +159,42 @@ class WhereBuilder {
111
159
  if (!fieldWhere) {
112
160
  continue;
113
161
  }
162
+ if (fieldName === MASKED_CELL_KEY) {
163
+ conditionBuilder = parseMaskedCells(fieldWhere).reduce(
164
+ (builder, cell) => this.buildMaskedCell(builder, entity, path, cell, joinList, allowManyJoin, negated),
165
+ conditionBuilder
166
+ );
167
+ continue;
168
+ }
114
169
  const targetPath = path.for(fieldName);
115
- const joinedWhere = ({ targetEntity, relation, entity: entity2 }) => {
116
- const relationWhere = where[fieldName];
117
- if (!relationWhere || Object.keys(relationWhere).length === 0) {
170
+ const hop = () => {
171
+ if (!this.isOptionalWhere(fieldWhere)) {
172
+ throw new Error(`WhereBuilder: ${entity.name}::${fieldName} expects a relation where`);
173
+ }
174
+ const { guard, fieldGuard, where: relationWhere } = splitReadGuard(fieldWhere);
175
+ const guards = { row: Object.keys(guard).length > 0, field: Object.keys(fieldGuard).length > 0 };
176
+ return { guard, fieldGuard, where: relationWhere, path: guards.row || guards.field ? path.for(hopPathSegment(fieldName, guards)) : targetPath };
177
+ };
178
+ const fieldGuardCondition = (fieldGuard) => {
179
+ if (Object.keys(fieldGuard).length === 0) {
180
+ return void 0;
181
+ }
182
+ const condition = ConditionBuilder.process(
183
+ (clause) => this.buildRecursive({ conditionBuilder: clause, entity, path, where: fieldGuard, joinList, allowManyJoin, negated: false })
184
+ ).getSql();
185
+ return condition === null ? void 0 : new Literal(`coalesce(${condition.sql}, false)`, condition.parameters);
186
+ };
187
+ const existsIfReadable = (fieldGuard, subquery) => {
188
+ const readable = fieldGuardCondition(fieldGuard);
189
+ return readable === void 0 ? conditionBuilder.exists(subquery) : conditionBuilder.and((clause) => clause.with(readable).exists(subquery));
190
+ };
191
+ const joinedWhere = (context) => {
192
+ const { targetEntity, relation, entity: entity2 } = context;
193
+ const { guard, fieldGuard, where: relationWhere, path: targetPath2 } = hop();
194
+ if (Object.keys(relationWhere).length === 0) {
118
195
  return conditionBuilder;
119
196
  }
120
- if (isIt(relation, "joiningColumn")) {
197
+ if (isIt(relation, "joiningColumn") && Object.keys(guard).length === 0 && Object.keys(fieldGuard).length === 0) {
121
198
  const primaryCondition = this.transformWhereToPrimaryCondition(relationWhere, targetEntity.primary);
122
199
  if (primaryCondition !== null) {
123
200
  return this.conditionBuilder.build(
@@ -129,14 +206,21 @@ class WhereBuilder {
129
206
  );
130
207
  }
131
208
  }
132
- joinList.push({ path: targetPath, entity: entity2, relationName: relation.name });
209
+ joinList.push({
210
+ path: targetPath2,
211
+ entity: entity2,
212
+ relationName: relation.name,
213
+ targetSource: this.createGuardedSource(targetEntity, targetPath2, guard),
214
+ joinCondition: fieldGuardCondition(fieldGuard)
215
+ });
133
216
  return this.buildRecursive({
134
217
  conditionBuilder,
135
218
  entity: targetEntity,
136
- path: targetPath,
219
+ path: targetPath2,
137
220
  where: relationWhere,
138
221
  joinList,
139
- allowManyJoin
222
+ allowManyJoin,
223
+ negated
140
224
  });
141
225
  };
142
226
  conditionBuilder = acceptFieldVisitor(this.schema, entity, fieldName, {
@@ -150,14 +234,17 @@ class WhereBuilder {
150
234
  if (allowManyJoin && !this.useExistsInHasManyFilter) {
151
235
  return joinedWhere(context);
152
236
  }
153
- return conditionBuilder.exists(
237
+ const { guard, fieldGuard, where: relationWhere, path: targetPath2 } = hop();
238
+ return existsIfReadable(
239
+ fieldGuard,
154
240
  this.createManyHasManySubquery(
155
241
  [tableName, entity.primaryColumn],
156
- fieldWhere,
242
+ relationWhere,
243
+ guard,
157
244
  context.targetEntity,
158
245
  context.targetRelation.joiningTable,
159
246
  "inverse",
160
- targetPath
247
+ targetPath2
161
248
  )
162
249
  );
163
250
  },
@@ -165,15 +252,17 @@ class WhereBuilder {
165
252
  if (allowManyJoin && !this.useExistsInHasManyFilter) {
166
253
  return joinedWhere(context);
167
254
  }
168
- where[fieldName];
169
- return conditionBuilder.exists(
255
+ const { guard, fieldGuard, where: relationWhere, path: targetPath2 } = hop();
256
+ return existsIfReadable(
257
+ fieldGuard,
170
258
  this.createManyHasManySubquery(
171
259
  [tableName, entity.primaryColumn],
172
- fieldWhere,
260
+ relationWhere,
261
+ guard,
173
262
  context.targetEntity,
174
263
  context.relation.joiningTable,
175
264
  "owning",
176
- targetPath
265
+ targetPath2
177
266
  )
178
267
  );
179
268
  },
@@ -181,17 +270,43 @@ class WhereBuilder {
181
270
  if (allowManyJoin && !this.useExistsInHasManyFilter) {
182
271
  return joinedWhere(context);
183
272
  }
184
- const relationWhere = fieldWhere;
185
- const qb = this.hasRootIsNull(relationWhere, context.targetEntity) ? SelectBuilder.create().select((it) => it.raw("1")).from(new Literal(`(select ${wrapIdentifier(tableName)}.${wrapIdentifier(entity.primaryColumn)})`), targetPath.for("tmp_").alias).leftJoin(
186
- context.targetEntity.tableName,
187
- targetPath.alias,
188
- (it) => it.columnsEq([targetPath.for("tmp_").alias, entity.primaryColumn], [targetPath.alias, context.targetRelation.joiningColumn.columnName])
189
- ) : SelectBuilder.create().select((it) => it.raw("1")).from(context.targetEntity.tableName, targetPath.alias).where((it) => it.columnsEq([tableName, entity.primaryColumn], [targetPath.alias, context.targetRelation.joiningColumn.columnName]));
190
- return conditionBuilder.exists(
273
+ const { guard, fieldGuard, where: relationWhere, path: targetPath2 } = hop();
274
+ if (this.hasRootIsNull(relationWhere, context.targetEntity)) {
275
+ const subquery = (joinsChildren) => {
276
+ const qb2 = SelectBuilder.create().select((it) => it.raw("1")).from(new Literal(`(select ${wrapIdentifier(tableName)}.${wrapIdentifier(entity.primaryColumn)})`), targetPath2.for("tmp_").alias).leftJoin(
277
+ this.createGuardedSource(context.targetEntity, targetPath2, guard) ?? context.targetEntity.tableName,
278
+ targetPath2.alias,
279
+ (it) => joinsChildren ? it.columnsEq([targetPath2.for("tmp_").alias, entity.primaryColumn], [targetPath2.alias, context.targetRelation.joiningColumn.columnName]) : it.raw("false")
280
+ );
281
+ return this.buildInternal({
282
+ entity: context.targetEntity,
283
+ path: targetPath2,
284
+ where: relationWhere,
285
+ callback: (cb) => qb2.where((clause) => cb(clause)),
286
+ allowManyJoin: true
287
+ });
288
+ };
289
+ const readable = fieldGuardCondition(fieldGuard);
290
+ if (readable === void 0) {
291
+ return conditionBuilder.exists(subquery(true));
292
+ }
293
+ const withChildren = subquery(true).createQuery(new Compiler.Context(Compiler.SCHEMA_PLACEHOLDER, /* @__PURE__ */ new Set()));
294
+ const withoutChildren = subquery(false).createQuery(new Compiler.Context(Compiler.SCHEMA_PLACEHOLDER, /* @__PURE__ */ new Set()));
295
+ return conditionBuilder.with(
296
+ new Literal(`case when ${readable.sql} then exists (${withChildren.sql}) else exists (${withoutChildren.sql}) end`, [
297
+ ...readable.parameters,
298
+ ...withChildren.parameters,
299
+ ...withoutChildren.parameters
300
+ ])
301
+ );
302
+ }
303
+ const qb = SelectBuilder.create().select((it) => it.raw("1")).from(context.targetEntity.tableName, targetPath2.alias).where((it) => it.columnsEq([tableName, entity.primaryColumn], [targetPath2.alias, context.targetRelation.joiningColumn.columnName]));
304
+ return existsIfReadable(
305
+ fieldGuard,
191
306
  this.buildInternal({
192
307
  entity: context.targetEntity,
193
- path: targetPath,
194
- where: relationWhere,
308
+ path: targetPath2,
309
+ where: this.combineWhereAnd([relationWhere, guard]),
195
310
  callback: (cb) => qb.where((clause) => cb(clause)),
196
311
  allowManyJoin: true
197
312
  })
@@ -201,12 +316,92 @@ class WhereBuilder {
201
316
  }
202
317
  return conditionBuilder;
203
318
  }
204
- createManyHasManySubquery(outerColumn, relationWhere, targetEntity, joiningTable, fromSide, path) {
319
+ /**
320
+ * A condition over a cell-level column holds on a masked cell iff it holds on NULL. Outside a negation FALSE and
321
+ * NULL drop the row alike, so only a condition that is TRUE on NULL needs more than `cond AND guard`; under a
322
+ * negation the masked cell must also keep NULL as NULL.
323
+ */
324
+ buildMaskedCell(conditionBuilder, entity, path, { guard, where }, joinList, allowManyJoin, negated) {
325
+ const compile = (where2) => ConditionBuilder.process((clause) => this.buildRecursive({ conditionBuilder: clause, entity, path, where: where2, joinList, allowManyJoin, negated })).getSql();
326
+ const condition = compile(where);
327
+ if (condition === null) {
328
+ return conditionBuilder;
329
+ }
330
+ const guardCondition = compile(guard);
331
+ if (guardCondition === null) {
332
+ return conditionBuilder.with(condition);
333
+ }
334
+ const onNull = this.evaluateWhereOnNull(where, entity);
335
+ const crispGuard = `coalesce(${guardCondition.sql}, false)`;
336
+ if (onNull === "true") {
337
+ return conditionBuilder.with(new Literal(`(${condition.sql} or not ${crispGuard})`, [...condition.parameters, ...guardCondition.parameters]));
338
+ }
339
+ if (!negated) {
340
+ return conditionBuilder.with(condition).with(guardCondition);
341
+ }
342
+ if (onNull === "false") {
343
+ return conditionBuilder.with(new Literal(`${condition.sql} and ${crispGuard}`, [...condition.parameters, ...guardCondition.parameters]));
344
+ }
345
+ return conditionBuilder.with(
346
+ new Literal(`case when ${crispGuard} then ${condition.sql} end`, [...guardCondition.parameters, ...condition.parameters])
347
+ );
348
+ }
349
+ /** The three-valued result of a column where on a NULL cell, mirroring how `ConditionBuilder` compiles it. */
350
+ evaluateWhereOnNull(where, entity) {
351
+ const operands = [];
352
+ for (const [key, value] of Object.entries(where)) {
353
+ if (value === null || value === void 0) {
354
+ continue;
355
+ }
356
+ if (!isColumn(entity.fields[key]) || !this.isInputCondition(value)) {
357
+ throw new Error(`WhereBuilder: ${MASKED_CELL_KEY} expects a column condition, got ${entity.name}::${key}`);
358
+ }
359
+ operands.push(this.evaluateConditionOnNull(value));
360
+ }
361
+ return combineNullCellValues(operands, "and");
362
+ }
363
+ evaluateConditionOnNull(condition) {
364
+ const isSet = (value) => value !== null && value !== void 0;
365
+ if (!Object.values(condition).some(isSet)) {
366
+ return "empty";
367
+ }
368
+ if (isSet(condition.and)) {
369
+ return combineNullCellValues(condition.and.map((it) => this.evaluateConditionOnNull(it)), "and");
370
+ }
371
+ if (isSet(condition.or)) {
372
+ return combineNullCellValues(condition.or.map((it) => this.evaluateConditionOnNull(it)), "or");
373
+ }
374
+ if (isSet(condition.not)) {
375
+ const operand = this.evaluateConditionOnNull(condition.not);
376
+ return operand === "true" ? "false" : operand === "false" ? "true" : operand;
377
+ }
378
+ const isNull = condition.isNull ?? condition.null;
379
+ if (isSet(isNull)) {
380
+ return isNull ? "true" : "false";
381
+ }
382
+ if (isSet(condition.always)) {
383
+ return "true";
384
+ }
385
+ if (isSet(condition.never)) {
386
+ return "false";
387
+ }
388
+ if (isSet(condition.in)) {
389
+ return condition.in.some((it) => it !== void 0) ? "unknown" : "false";
390
+ }
391
+ if (isSet(condition.notIn)) {
392
+ return condition.notIn.some((it) => it !== void 0) ? "unknown" : "true";
393
+ }
394
+ return "unknown";
395
+ }
396
+ createGuardedSource(entity, path, guard) {
397
+ return Object.keys(guard).length === 0 ? void 0 : this.buildGuardedSource(entity, path, guard);
398
+ }
399
+ createManyHasManySubquery(outerColumn, relationWhere, guard, targetEntity, joiningTable, fromSide, path) {
205
400
  const fromColumn = fromSide === "owning" ? joiningTable.joiningColumn.columnName : joiningTable.inverseJoiningColumn.columnName;
206
401
  const toColumn = fromSide === "owning" ? joiningTable.inverseJoiningColumn.columnName : joiningTable.joiningColumn.columnName;
207
402
  const junctionPath = path.for("junction_");
208
403
  const qb = SelectBuilder.create().from(joiningTable.tableName, junctionPath.alias).select((it) => it.raw("1")).where((it) => it.columnsEq(outerColumn, [junctionPath.alias, fromColumn]));
209
- const primaryCondition = this.transformWhereToPrimaryCondition(relationWhere, targetEntity.primary);
404
+ const primaryCondition = Object.keys(guard).length === 0 ? this.transformWhereToPrimaryCondition(relationWhere, targetEntity.primary) : null;
210
405
  if (primaryCondition !== null) {
211
406
  const columnType = targetEntity.fields[targetEntity.primary];
212
407
  return qb.where((condition) => this.conditionBuilder.build(condition, junctionPath.alias, toColumn, columnType, primaryCondition));
@@ -219,11 +414,24 @@ class WhereBuilder {
219
414
  return this.buildInternal({
220
415
  entity: targetEntity,
221
416
  path: this.pathFactory.create([], path.fullAlias),
222
- where: relationWhere,
417
+ where: this.combineWhereAnd([relationWhere, guard]),
223
418
  callback: (cb) => qbJoined.where((clause) => cb(clause)),
224
419
  allowManyJoin: true
225
420
  });
226
421
  }
422
+ combineWhereAnd(wheres) {
423
+ const nonEmpty = wheres.filter((it) => Object.keys(it).length > 0);
424
+ if (nonEmpty.length === 0) {
425
+ return {};
426
+ }
427
+ return nonEmpty.length === 1 ? nonEmpty[0] : { and: nonEmpty };
428
+ }
429
+ isInputCondition(value) {
430
+ return value !== null && typeof value === "object" && !Array.isArray(value);
431
+ }
432
+ isOptionalWhere(value) {
433
+ return value !== null && value !== void 0 && typeof value === "object" && !Array.isArray(value);
434
+ }
227
435
  transformWhereToPrimaryCondition(where, primaryField) {
228
436
  const keys = Object.keys(where);
229
437
  if (keys.filter((it) => !["and", "or", "not", primaryField].includes(it)).length > 0) {
@@ -269,28 +477,34 @@ class WhereBuilder {
269
477
  if (where.not && this.hasRootIsNull(where.not, entity)) {
270
478
  return true;
271
479
  }
272
- } else if (isColumn(entity.fields[key]) && this.conditionHasIsNull(where[key])) {
273
- return true;
480
+ } else if (key === MASKED_CELL_KEY) {
481
+ if (parseMaskedCells(where[key]).some((cell) => this.hasRootIsNull(cell.where, entity) || this.hasRootIsNull(cell.guard, entity))) {
482
+ return true;
483
+ }
484
+ } else if (isColumn(entity.fields[key])) {
485
+ const condition = where[key];
486
+ if (this.isInputCondition(condition) && this.conditionHasIsNull(condition)) {
487
+ return true;
488
+ }
274
489
  }
275
490
  }
276
491
  return false;
277
492
  }
278
493
  conditionHasIsNull(cond) {
279
- if (cond.isNull !== void 0) {
280
- return true;
281
- }
282
- if (cond.and?.some((it) => this.conditionHasIsNull(it))) {
283
- return true;
284
- }
285
- if (cond.or?.some((it) => this.conditionHasIsNull(it))) {
286
- return true;
287
- }
288
- if (cond.not && this.conditionHasIsNull(cond.not)) {
289
- return true;
290
- }
291
- return false;
494
+ return cond.isNull !== void 0 || cond.and?.some((item) => this.conditionHasIsNull(item)) === true || cond.or?.some((item) => this.conditionHasIsNull(item)) === true || cond.not !== void 0 && this.conditionHasIsNull(cond.not);
292
495
  }
293
496
  }
497
+ const combineNullCellValues = (operands, operator) => {
498
+ const present = operands.filter((it) => it !== "empty");
499
+ if (present.length === 0) {
500
+ return "empty";
501
+ }
502
+ const dominant = operator === "and" ? "false" : "true";
503
+ if (present.includes(dominant)) {
504
+ return dominant;
505
+ }
506
+ return present.includes("unknown") ? "unknown" : operator === "and" ? "true" : "false";
507
+ };
294
508
  export {
295
509
  WhereBuilder
296
510
  };
@@ -1 +1 @@
1
- {"version":3,"file":"WhereBuilder.js","sources":["../../../../../../packages/engine-content-api/src/mapper/select/WhereBuilder.ts"],"sourcesContent":["import { isIt } from '../../utils/index.js'\nimport { acceptFieldVisitor, isColumn } from '@contember/schema-utils'\nimport { Input, Model } from '@contember/schema'\nimport { Path, PathFactory } from './Path.js'\nimport { JoinBuilder } from './JoinBuilder.js'\nimport { ConditionBuilder } from './ConditionBuilder.js'\nimport { ConditionBuilder as SqlConditionBuilder, Literal, Operator, QueryBuilder, SelectBuilder, wrapIdentifier } from '@contember/database'\nimport { WhereOptimizationHints, WhereOptimizer } from './optimizer/WhereOptimizer.js'\n\nexport class WhereBuilder {\n\tconstructor(\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly joinBuilder: JoinBuilder,\n\t\tprivate readonly conditionBuilder: ConditionBuilder,\n\t\tprivate readonly pathFactory: PathFactory,\n\t\tprivate readonly whereOptimizer: WhereOptimizer,\n\t\tprivate readonly useExistsInHasManyFilter: boolean,\n\t) {}\n\n\tpublic build<R extends SelectBuilder.Result>(\n\t\tqb: SelectBuilder<R>,\n\t\tentity: Model.Entity,\n\t\tpath: Path,\n\t\twhere: Input.OptionalWhere,\n\t\toptimizationHints: WhereOptimizationHints = {},\n\t): SelectBuilder<R> {\n\t\tconst optimizedWhere = this.whereOptimizer.optimize(where, entity, optimizationHints)\n\t\treturn this.buildInternal({\n\t\t\tentity,\n\t\t\tpath,\n\t\t\twhere: optimizedWhere,\n\t\t\tcallback: cb => qb.where(clause => cb(clause)),\n\t\t\tallowManyJoin: false,\n\t\t})\n\t}\n\n\tpublic buildAdvanced<R extends SelectBuilder.Result>(\n\t\tentity: Model.Entity,\n\t\tpath: Path,\n\t\twhere: Input.OptionalWhere,\n\t\tcallback: (clauseCb: (clause: SqlConditionBuilder) => SqlConditionBuilder) => SelectBuilder<R>,\n\t\toptimizationHints: WhereOptimizationHints = {},\n\t): SelectBuilder<R> {\n\t\tconst optimizedWhere = this.whereOptimizer.optimize(where, entity, optimizationHints)\n\t\treturn this.buildInternal({\n\t\t\tentity,\n\t\t\tpath,\n\t\t\twhere: optimizedWhere,\n\t\t\tcallback,\n\t\t\tallowManyJoin: false,\n\t\t})\n\t}\n\n\tprivate buildInternal<R extends SelectBuilder.Result>({\n\t\tcallback,\n\t\t...args\n\t}: {\n\t\tentity: Model.Entity\n\t\tpath: Path\n\t\twhere: Input.OptionalWhere\n\t\tcallback: (clauseCb: (clause: SqlConditionBuilder) => SqlConditionBuilder) => SelectBuilder<R>\n\t\tallowManyJoin: boolean\n\t}): SelectBuilder<R> {\n\t\tconst joinList: WhereJoinDefinition[] = []\n\n\t\tconst qbWithWhere = callback(clause =>\n\t\t\tthis.buildRecursive({\n\t\t\t\tconditionBuilder: clause,\n\t\t\t\tjoinList: joinList,\n\t\t\t\t...args,\n\t\t\t})\n\t\t)\n\t\treturn joinList.reduce<SelectBuilder<R>>(\n\t\t\t(qb, { path, entity, relationName }) => this.joinBuilder.join<R>(qb, path, entity, relationName),\n\t\t\tqbWithWhere,\n\t\t)\n\t}\n\n\tprivate buildRecursive({\n\t\tconditionBuilder,\n\t\tentity,\n\t\tpath,\n\t\twhere,\n\t\tjoinList,\n\t\tallowManyJoin,\n\t}: {\n\t\tconditionBuilder: SqlConditionBuilder\n\t\tentity: Model.Entity\n\t\tpath: Path\n\t\twhere: Input.OptionalWhere\n\t\tjoinList: WhereJoinDefinition[]\n\t\tallowManyJoin: boolean\n\t}): SqlConditionBuilder {\n\t\tconst tableName = path.alias\n\n\t\tif (where.and !== undefined && where.and !== null && where.and.length > 0) {\n\t\t\tconst expr = where.and\n\t\t\tconditionBuilder = conditionBuilder.and(clause =>\n\t\t\t\texpr.reduce(\n\t\t\t\t\t(clause2, where) =>\n\t\t\t\t\t\t!where ? clause2 : this.buildRecursive({\n\t\t\t\t\t\t\tconditionBuilder: clause2,\n\t\t\t\t\t\t\tentity,\n\t\t\t\t\t\t\tpath,\n\t\t\t\t\t\t\twhere,\n\t\t\t\t\t\t\tjoinList,\n\t\t\t\t\t\t\tallowManyJoin,\n\t\t\t\t\t\t}),\n\t\t\t\t\tclause,\n\t\t\t\t)\n\t\t\t)\n\t\t}\n\t\tif (where.or !== undefined && where.or !== null && where.or.length > 0) {\n\t\t\tconst expr = where.or\n\t\t\tconditionBuilder = conditionBuilder.or(clause =>\n\t\t\t\texpr.reduce(\n\t\t\t\t\t(clause2, where) =>\n\t\t\t\t\t\t!where\n\t\t\t\t\t\t\t? clause2\n\t\t\t\t\t\t\t: clause2.and(clause3 =>\n\t\t\t\t\t\t\t\tthis.buildRecursive({\n\t\t\t\t\t\t\t\t\tconditionBuilder: clause3,\n\t\t\t\t\t\t\t\t\tentity,\n\t\t\t\t\t\t\t\t\tpath,\n\t\t\t\t\t\t\t\t\twhere,\n\t\t\t\t\t\t\t\t\tjoinList,\n\t\t\t\t\t\t\t\t\tallowManyJoin,\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t),\n\t\t\t\t\tclause,\n\t\t\t\t)\n\t\t\t)\n\t\t}\n\t\tif (where.not !== undefined && where.not !== null) {\n\t\t\tconst expr = where.not\n\t\t\tconditionBuilder = conditionBuilder.not(clause =>\n\t\t\t\tthis.buildRecursive({\n\t\t\t\t\tconditionBuilder: clause,\n\t\t\t\t\tentity,\n\t\t\t\t\tpath,\n\t\t\t\t\twhere: expr,\n\t\t\t\t\tjoinList,\n\t\t\t\t\tallowManyJoin,\n\t\t\t\t})\n\t\t\t)\n\t\t}\n\n\t\tfor (const fieldName in where) {\n\t\t\tif (fieldName === 'and' || fieldName === 'or' || fieldName === 'not') {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst fieldWhere = where[fieldName]\n\t\t\tif (!fieldWhere) {\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tconst targetPath = path.for(fieldName)\n\n\t\t\tconst joinedWhere = ({ targetEntity, relation, entity }: Model.AnyRelationContext): SqlConditionBuilder => {\n\t\t\t\tconst relationWhere = where[fieldName] as Input.OptionalWhere | null\n\t\t\t\tif (!relationWhere || Object.keys(relationWhere).length === 0) {\n\t\t\t\t\treturn conditionBuilder\n\t\t\t\t}\n\t\t\t\tif (isIt<Model.JoiningColumnRelation>(relation, 'joiningColumn')) {\n\t\t\t\t\tconst primaryCondition = this.transformWhereToPrimaryCondition(relationWhere, targetEntity.primary)\n\t\t\t\t\tif (primaryCondition !== null) {\n\t\t\t\t\t\treturn this.conditionBuilder.build(\n\t\t\t\t\t\t\tconditionBuilder,\n\t\t\t\t\t\t\ttableName,\n\t\t\t\t\t\t\trelation.joiningColumn.columnName,\n\t\t\t\t\t\t\ttargetEntity.fields[targetEntity.primary] as Model.AnyColumn,\n\t\t\t\t\t\t\tprimaryCondition,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tjoinList.push({ path: targetPath, entity, relationName: relation.name })\n\n\t\t\t\treturn this.buildRecursive({\n\t\t\t\t\tconditionBuilder,\n\t\t\t\t\tentity: targetEntity,\n\t\t\t\t\tpath: targetPath,\n\t\t\t\t\twhere: relationWhere,\n\t\t\t\t\tjoinList,\n\t\t\t\t\tallowManyJoin,\n\t\t\t\t})\n\t\t\t}\n\n\t\t\tconditionBuilder = acceptFieldVisitor<SqlConditionBuilder>(this.schema, entity, fieldName, {\n\t\t\t\tvisitColumn: ({ entity, column }) => {\n\t\t\t\t\treturn this.conditionBuilder.build(conditionBuilder, tableName, column.columnName, column, fieldWhere as Input.Condition<Input.ColumnValue>)\n\t\t\t\t},\n\t\t\t\tvisitOneHasOneInverse: joinedWhere,\n\t\t\t\tvisitOneHasOneOwning: joinedWhere,\n\t\t\t\tvisitManyHasOne: joinedWhere,\n\t\t\t\tvisitManyHasManyInverse: context => {\n\t\t\t\t\tif (allowManyJoin && !this.useExistsInHasManyFilter) {\n\t\t\t\t\t\treturn joinedWhere(context)\n\t\t\t\t\t}\n\n\t\t\t\t\treturn conditionBuilder.exists(\n\t\t\t\t\t\tthis.createManyHasManySubquery(\n\t\t\t\t\t\t\t[tableName, entity.primaryColumn],\n\t\t\t\t\t\t\tfieldWhere as Input.OptionalWhere,\n\t\t\t\t\t\t\tcontext.targetEntity,\n\t\t\t\t\t\t\tcontext.targetRelation.joiningTable,\n\t\t\t\t\t\t\t'inverse',\n\t\t\t\t\t\t\ttargetPath,\n\t\t\t\t\t\t),\n\t\t\t\t\t)\n\t\t\t\t},\n\t\t\t\tvisitManyHasManyOwning: context => {\n\t\t\t\t\tif (allowManyJoin && !this.useExistsInHasManyFilter) {\n\t\t\t\t\t\treturn joinedWhere(context)\n\t\t\t\t\t}\n\n\t\t\t\t\tconst relationWhere = where[fieldName] as Input.Where | null\n\n\t\t\t\t\treturn conditionBuilder.exists(\n\t\t\t\t\t\tthis.createManyHasManySubquery(\n\t\t\t\t\t\t\t[tableName, entity.primaryColumn],\n\t\t\t\t\t\t\tfieldWhere as Input.OptionalWhere,\n\t\t\t\t\t\t\tcontext.targetEntity,\n\t\t\t\t\t\t\tcontext.relation.joiningTable,\n\t\t\t\t\t\t\t'owning',\n\t\t\t\t\t\t\ttargetPath,\n\t\t\t\t\t\t),\n\t\t\t\t\t)\n\t\t\t\t},\n\t\t\t\tvisitOneHasMany: context => {\n\t\t\t\t\tif (allowManyJoin && !this.useExistsInHasManyFilter) {\n\t\t\t\t\t\treturn joinedWhere(context)\n\t\t\t\t\t}\n\n\t\t\t\t\tconst relationWhere = fieldWhere as Input.OptionalWhere\n\n\t\t\t\t\tconst qb = this.hasRootIsNull(relationWhere, context.targetEntity)\n\t\t\t\t\t\t? SelectBuilder.create()\n\t\t\t\t\t\t\t.select(it => it.raw('1'))\n\t\t\t\t\t\t\t.from(new Literal(`(select ${wrapIdentifier(tableName)}.${wrapIdentifier(entity.primaryColumn)})`), targetPath.for('tmp_').alias)\n\t\t\t\t\t\t\t.leftJoin(\n\t\t\t\t\t\t\t\tcontext.targetEntity.tableName,\n\t\t\t\t\t\t\t\ttargetPath.alias,\n\t\t\t\t\t\t\t\tit => it.columnsEq([targetPath.for('tmp_').alias, entity.primaryColumn], [targetPath.alias, context.targetRelation.joiningColumn.columnName]),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t: SelectBuilder.create()\n\t\t\t\t\t\t\t.select(it => it.raw('1'))\n\t\t\t\t\t\t\t.from(context.targetEntity.tableName, targetPath.alias)\n\t\t\t\t\t\t\t.where(it => it.columnsEq([tableName, entity.primaryColumn], [targetPath.alias, context.targetRelation.joiningColumn.columnName]))\n\n\t\t\t\t\treturn conditionBuilder.exists(\n\t\t\t\t\t\tthis.buildInternal({\n\t\t\t\t\t\t\tentity: context.targetEntity,\n\t\t\t\t\t\t\tpath: targetPath,\n\t\t\t\t\t\t\twhere: relationWhere,\n\t\t\t\t\t\t\tcallback: cb => qb.where(clause => cb(clause)),\n\t\t\t\t\t\t\tallowManyJoin: true,\n\t\t\t\t\t\t}),\n\t\t\t\t\t)\n\t\t\t\t},\n\t\t\t})\n\t\t}\n\t\treturn conditionBuilder\n\t}\n\n\tprivate createManyHasManySubquery(\n\t\touterColumn: QueryBuilder.ColumnIdentifier,\n\t\trelationWhere: Input.OptionalWhere,\n\t\ttargetEntity: Model.Entity,\n\t\tjoiningTable: Model.JoiningTable,\n\t\tfromSide: 'owning' | 'inverse',\n\t\tpath: Path,\n\t) {\n\t\tconst fromColumn = fromSide === 'owning' ? joiningTable.joiningColumn.columnName : joiningTable.inverseJoiningColumn.columnName\n\t\tconst toColumn = fromSide === 'owning' ? joiningTable.inverseJoiningColumn.columnName : joiningTable.joiningColumn.columnName\n\t\tconst junctionPath = path.for('junction_')\n\t\tconst qb = SelectBuilder.create<SelectBuilder.Result>()\n\t\t\t.from(joiningTable.tableName, junctionPath.alias)\n\t\t\t.select(it => it.raw('1'))\n\t\t\t.where(it => it.columnsEq(outerColumn, [junctionPath.alias, fromColumn]))\n\n\t\tconst primaryCondition = this.transformWhereToPrimaryCondition(relationWhere, targetEntity.primary)\n\t\tif (primaryCondition !== null) {\n\t\t\tconst columnType = targetEntity.fields[targetEntity.primary] as Model.AnyColumn\n\n\t\t\treturn qb.where(condition => this.conditionBuilder.build(condition, junctionPath.alias, toColumn, columnType, primaryCondition))\n\t\t}\n\n\t\tconst qbJoined = qb.join(\n\t\t\ttargetEntity.tableName,\n\t\t\tpath.alias,\n\t\t\tclause => clause.compareColumns([junctionPath.alias, toColumn], Operator.eq, [path.alias, targetEntity.primary]),\n\t\t)\n\t\treturn this.buildInternal({\n\t\t\tentity: targetEntity,\n\t\t\tpath: this.pathFactory.create([], path.fullAlias),\n\t\t\twhere: relationWhere,\n\t\t\tcallback: cb => qbJoined.where(clause => cb(clause)),\n\t\t\tallowManyJoin: true,\n\t\t})\n\t}\n\n\tprivate transformWhereToPrimaryCondition(where: Input.OptionalWhere, primaryField: string): Input.Condition<never> | null {\n\t\tconst keys = Object.keys(where)\n\t\tif (keys.filter(it => !['and', 'or', 'not', primaryField].includes(it)).length > 0) {\n\t\t\treturn null\n\t\t}\n\t\tlet condition: {\n\t\t\tand?: Array<Input.Condition<never>>\n\t\t\tor?: Array<Input.Condition<never>>\n\t\t\tnot?: Input.Condition<never>\n\t\t} = {}\n\t\tif (where.and) {\n\t\t\tconst conditions = where.and\n\t\t\t\t.filter((it): it is Input.Where => !!it)\n\t\t\t\t.map(it => this.transformWhereToPrimaryCondition(it, primaryField))\n\t\t\tif (conditions.includes(null)) {\n\t\t\t\treturn null\n\t\t\t}\n\t\t\tcondition.and = conditions as Input.Condition<never>[]\n\t\t}\n\t\tif (where.or) {\n\t\t\tconst conditions = where.or\n\t\t\t\t.filter((it): it is Input.Where => !!it)\n\t\t\t\t.map(it => this.transformWhereToPrimaryCondition(it, primaryField))\n\t\t\tif (conditions.includes(null)) {\n\t\t\t\treturn null\n\t\t\t}\n\t\t\tcondition.or = conditions as Input.Condition<never>[]\n\t\t}\n\t\tif (where.not) {\n\t\t\tconst conditions = this.transformWhereToPrimaryCondition(where.not, primaryField)\n\t\t\tif (conditions === null) {\n\t\t\t\treturn null\n\t\t\t}\n\t\t\tcondition.not = conditions as Input.Condition<never>\n\t\t}\n\t\tif (where[primaryField]) {\n\t\t\tif (Object.keys(condition).length > 0) {\n\t\t\t\treturn { and: [condition, where[primaryField] as Input.Condition<never>] }\n\t\t\t}\n\t\t\treturn where[primaryField] as Input.Condition<never>\n\t\t}\n\t\treturn condition\n\t}\n\n\tprivate hasRootIsNull(where: Input.OptionalWhere, entity: Model.Entity): boolean {\n\t\tfor (const key in where) {\n\t\t\tif (key === 'and' || key === 'or') {\n\t\t\t\tif (where[key]?.some(it => it && this.hasRootIsNull(it, entity))) {\n\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t} else if (key === 'not') {\n\t\t\t\tif (where.not && this.hasRootIsNull(where.not, entity)) {\n\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t} else if (isColumn(entity.fields[key]) && this.conditionHasIsNull(where[key] as Input.Condition)) {\n\t\t\t\treturn true\n\t\t\t}\n\t\t}\n\t\treturn false\n\t}\n\n\tprivate conditionHasIsNull(cond: Input.Condition): boolean {\n\t\tif (cond.isNull !== undefined) {\n\t\t\treturn true\n\t\t}\n\t\tif (cond.and?.some(it => this.conditionHasIsNull(it))) {\n\t\t\treturn true\n\t\t}\n\t\tif (cond.or?.some(it => this.conditionHasIsNull(it))) {\n\t\t\treturn true\n\t\t}\n\t\tif (cond.not && this.conditionHasIsNull(cond.not)) {\n\t\t\treturn true\n\t\t}\n\t\treturn false\n\t}\n}\n\nexport type WhereJoinDefinition = { path: Path; entity: Model.Entity; relationName: string }\n"],"names":["where","entity"],"mappings":";;;AASO,MAAM,aAAa;AAAA,EACzB,YACkB,QACA,aACA,kBACA,aACA,gBACA,0BAChB;AANgB,SAAA,SAAA;AACA,SAAA,cAAA;AACA,SAAA,mBAAA;AACA,SAAA,cAAA;AACA,SAAA,iBAAA;AACA,SAAA,2BAAA;AAAA,EACf;AAAA,EAEI,MACN,IACA,QACA,MACA,OACA,oBAA4C,IACzB;AACnB,UAAM,iBAAiB,KAAK,eAAe,SAAS,OAAO,QAAQ,iBAAiB;AACpF,WAAO,KAAK,cAAc;AAAA,MACzB;AAAA,MACA;AAAA,MACA,OAAO;AAAA,MACP,UAAU,CAAA,OAAM,GAAG,MAAM,CAAA,WAAU,GAAG,MAAM,CAAC;AAAA,MAC7C,eAAe;AAAA,IAAA,CACf;AAAA,EACF;AAAA,EAEO,cACN,QACA,MACA,OACA,UACA,oBAA4C,IACzB;AACnB,UAAM,iBAAiB,KAAK,eAAe,SAAS,OAAO,QAAQ,iBAAiB;AACpF,WAAO,KAAK,cAAc;AAAA,MACzB;AAAA,MACA;AAAA,MACA,OAAO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sources":["../../../../../../packages/engine-content-api/src/mapper/select/WhereBuilder.ts"],"sourcesContent":["import { isIt } from '../../utils/index.js'\nimport { acceptFieldVisitor, isColumn } from '@contember/schema-utils'\nimport { Input, Model } from '@contember/schema'\nimport { hopPathSegment, Path, PathFactory } from './Path.js'\nimport { JoinBuilder } from './JoinBuilder.js'\nimport { ConditionBuilder } from './ConditionBuilder.js'\nimport {\n\tCompiler,\n\tConditionBuilder as SqlConditionBuilder,\n\tLiteral,\n\tOperator,\n\tQueryBuilder,\n\tSelectBuilder,\n\twrapIdentifier,\n} from '@contember/database'\nimport { WhereOptimizationHints, WhereOptimizer } from './optimizer/WhereOptimizer.js'\nimport { MASKED_CELL_KEY, MaskedCell, parseMaskedCells, splitReadGuard } from '../../acl/PredicatesInjector.js'\n\n/**\n * A user-authored relation hop: the remaining condition on the target rows and the target's row-level read\n * guard (see `READ_GUARD_KEY`). The guard is compiled into the hop's table source, never into its condition,\n * so an unreadable target row behaves exactly like an absent one under any boolean shape.\n */\ntype RelationHop = { where: Input.OptionalWhere; guard: Input.OptionalWhere; fieldGuard: Input.OptionalWhere; path: Path }\n\nexport class WhereBuilder {\n\tconstructor(\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly joinBuilder: JoinBuilder,\n\t\tprivate readonly conditionBuilder: ConditionBuilder,\n\t\tprivate readonly pathFactory: PathFactory,\n\t\tprivate readonly whereOptimizer: WhereOptimizer,\n\t\tprivate readonly useExistsInHasManyFilter: boolean,\n\t) {}\n\n\tpublic build<R extends SelectBuilder.Result>(\n\t\tqb: SelectBuilder<R>,\n\t\tentity: Model.Entity,\n\t\tpath: Path,\n\t\twhere: Input.OptionalWhere,\n\t\toptimizationHints: WhereOptimizationHints = {},\n\t): SelectBuilder<R> {\n\t\tconst optimizedWhere = this.whereOptimizer.optimize(where, entity, optimizationHints)\n\t\treturn this.buildInternal({\n\t\t\tentity,\n\t\t\tpath,\n\t\t\twhere: optimizedWhere,\n\t\t\tcallback: cb => qb.where(clause => cb(clause)),\n\t\t\tallowManyJoin: false,\n\t\t})\n\t}\n\n\tpublic buildAdvanced<R extends SelectBuilder.Result>(\n\t\tentity: Model.Entity,\n\t\tpath: Path,\n\t\twhere: Input.OptionalWhere,\n\t\tcallback: (clauseCb: (clause: SqlConditionBuilder) => SqlConditionBuilder) => SelectBuilder<R>,\n\t\toptimizationHints: WhereOptimizationHints = {},\n\t): SelectBuilder<R> {\n\t\tconst optimizedWhere = this.whereOptimizer.optimize(where, entity, optimizationHints)\n\t\treturn this.buildInternal({\n\t\t\tentity,\n\t\t\tpath,\n\t\t\twhere: optimizedWhere,\n\t\t\tcallback,\n\t\t\tallowManyJoin: false,\n\t\t})\n\t}\n\n\t/**\n\t * Compiles a where into a single boolean SQL condition (a `Literal`), applying any relation joins it needs\n\t * to `qb`. Shared by the read-predicate consumers that need the condition as an expression rather than a\n\t * WHERE clause: the projection predicate column (selected as a boolean) and the order-by guard (wrapped in\n\t * `CASE WHEN <condition> THEN <column> END`). An empty/trivially-true predicate compiles to `true`.\n\t */\n\tpublic buildConditionLiteral<R extends SelectBuilder.Result>(\n\t\tqb: SelectBuilder<R>,\n\t\tentity: Model.Entity,\n\t\tpath: Path,\n\t\twhere: Input.OptionalWhere,\n\t\toptimizationHints: WhereOptimizationHints = {},\n\t): { qb: SelectBuilder<R>; condition: Literal } {\n\t\tlet condition: Literal = new Literal('true')\n\t\tconst resultQb = this.buildAdvanced<R>(\n\t\t\tentity,\n\t\t\tpath,\n\t\t\twhere,\n\t\t\tapplyCondition => {\n\t\t\t\tcondition = SqlConditionBuilder.process(clause => {\n\t\t\t\t\tconst applied = applyCondition(clause)\n\t\t\t\t\treturn applied.isEmpty() ? applied.raw('true') : applied\n\t\t\t\t}).getSql() ?? new Literal('true')\n\t\t\t\treturn qb\n\t\t\t},\n\t\t\toptimizationHints,\n\t\t)\n\t\treturn { qb: resultQb, condition }\n\t}\n\n\t/**\n\t * The table source of a relation hop restricted to rows satisfying `guard` (the target's row-level read\n\t * predicate): `(select <alias>.* from <table> as <alias> where <guard>)`. LEFT JOINing this source\n\t * null-extends an unreadable row exactly like an absent one. The guard is compiled as-definer — its own\n\t * relation hops are plain joins — and Postgres pulls the subquery up into the outer join tree.\n\t */\n\tpublic buildGuardedSource(entity: Model.Entity, path: Path, guard: Input.OptionalWhere): Literal {\n\t\tconst qb = SelectBuilder.create()\n\t\t\t.select(expr => expr.raw(`${wrapIdentifier(path.alias)}.*`))\n\t\t\t.from(entity.tableName, path.alias)\n\t\tconst guarded = this.buildInternal({\n\t\t\tentity,\n\t\t\tpath,\n\t\t\twhere: this.whereOptimizer.optimize(guard, entity),\n\t\t\tcallback: cb => qb.where(clause => cb(clause)),\n\t\t\tallowManyJoin: false,\n\t\t})\n\t\tconst query = guarded.createQuery(new Compiler.Context(Compiler.SCHEMA_PLACEHOLDER, new Set()))\n\t\treturn new Literal(`(${query.sql})`, query.parameters)\n\t}\n\n\tprivate buildInternal<R extends SelectBuilder.Result>({\n\t\tcallback,\n\t\t...args\n\t}: {\n\t\tentity: Model.Entity\n\t\tpath: Path\n\t\twhere: Input.OptionalWhere\n\t\tcallback: (clauseCb: (clause: SqlConditionBuilder) => SqlConditionBuilder) => SelectBuilder<R>\n\t\tallowManyJoin: boolean\n\t}): SelectBuilder<R> {\n\t\tconst joinList: WhereJoinDefinition[] = []\n\n\t\t// Every (sub)query starts unnegated: an EXISTS yields TRUE or FALSE, so a `not` around it does not reach in.\n\t\tconst qbWithWhere = callback(clause =>\n\t\t\tthis.buildRecursive({\n\t\t\t\tconditionBuilder: clause,\n\t\t\t\tjoinList: joinList,\n\t\t\t\t...args,\n\t\t\t\tnegated: false,\n\t\t\t})\n\t\t)\n\t\treturn joinList.reduce<SelectBuilder<R>>(\n\t\t\t(qb, { path, entity, relationName, targetSource, joinCondition }) =>\n\t\t\t\tthis.joinBuilder.join<R>(qb, path, entity, relationName, targetSource, joinCondition),\n\t\t\tqbWithWhere,\n\t\t)\n\t}\n\n\tprivate buildRecursive({\n\t\tconditionBuilder,\n\t\tentity,\n\t\tpath,\n\t\twhere,\n\t\tjoinList,\n\t\tallowManyJoin,\n\t\tnegated,\n\t}: {\n\t\tconditionBuilder: SqlConditionBuilder\n\t\tentity: Model.Entity\n\t\tpath: Path\n\t\twhere: Input.OptionalWhere\n\t\tjoinList: WhereJoinDefinition[]\n\t\tallowManyJoin: boolean\n\t\t/** Odd number of enclosing `not`s within the current (sub)query. */\n\t\tnegated: boolean\n\t}): SqlConditionBuilder {\n\t\tconst tableName = path.alias\n\n\t\tif (where.and !== undefined && where.and !== null && where.and.length > 0) {\n\t\t\tconst expr = where.and\n\t\t\tconditionBuilder = conditionBuilder.and(clause =>\n\t\t\t\texpr.reduce(\n\t\t\t\t\t(clause2, where) =>\n\t\t\t\t\t\t!where ? clause2 : this.buildRecursive({\n\t\t\t\t\t\t\tconditionBuilder: clause2,\n\t\t\t\t\t\t\tentity,\n\t\t\t\t\t\t\tpath,\n\t\t\t\t\t\t\twhere,\n\t\t\t\t\t\t\tjoinList,\n\t\t\t\t\t\t\tallowManyJoin,\n\t\t\t\t\t\t\tnegated,\n\t\t\t\t\t\t}),\n\t\t\t\t\tclause,\n\t\t\t\t)\n\t\t\t)\n\t\t}\n\t\tif (where.or !== undefined && where.or !== null && where.or.length > 0) {\n\t\t\tconst expr = where.or\n\t\t\tconditionBuilder = conditionBuilder.or(clause =>\n\t\t\t\texpr.reduce(\n\t\t\t\t\t(clause2, where) =>\n\t\t\t\t\t\t!where\n\t\t\t\t\t\t\t? clause2\n\t\t\t\t\t\t\t: clause2.and(clause3 =>\n\t\t\t\t\t\t\t\tthis.buildRecursive({\n\t\t\t\t\t\t\t\t\tconditionBuilder: clause3,\n\t\t\t\t\t\t\t\t\tentity,\n\t\t\t\t\t\t\t\t\tpath,\n\t\t\t\t\t\t\t\t\twhere,\n\t\t\t\t\t\t\t\t\tjoinList,\n\t\t\t\t\t\t\t\t\tallowManyJoin,\n\t\t\t\t\t\t\t\t\tnegated,\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t),\n\t\t\t\t\tclause,\n\t\t\t\t)\n\t\t\t)\n\t\t}\n\t\tif (where.not !== undefined && where.not !== null) {\n\t\t\tconst expr = where.not\n\t\t\tconditionBuilder = conditionBuilder.not(clause =>\n\t\t\t\tthis.buildRecursive({\n\t\t\t\t\tconditionBuilder: clause,\n\t\t\t\t\tentity,\n\t\t\t\t\tpath,\n\t\t\t\t\twhere: expr,\n\t\t\t\t\tjoinList,\n\t\t\t\t\tallowManyJoin,\n\t\t\t\t\tnegated: !negated,\n\t\t\t\t})\n\t\t\t)\n\t\t}\n\n\t\tfor (const fieldName in where) {\n\t\t\tif (fieldName === 'and' || fieldName === 'or' || fieldName === 'not') {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst fieldWhere = where[fieldName]\n\t\t\tif (!fieldWhere) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (fieldName === MASKED_CELL_KEY) {\n\t\t\t\tconditionBuilder = parseMaskedCells(fieldWhere).reduce(\n\t\t\t\t\t(builder, cell) => this.buildMaskedCell(builder, entity, path, cell, joinList, allowManyJoin, negated),\n\t\t\t\t\tconditionBuilder,\n\t\t\t\t)\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tconst targetPath = path.for(fieldName)\n\t\t\tconst hop = (): RelationHop => {\n\t\t\t\tif (!this.isOptionalWhere(fieldWhere)) {\n\t\t\t\t\tthrow new Error(`WhereBuilder: ${entity.name}::${fieldName} expects a relation where`)\n\t\t\t\t}\n\t\t\t\tconst { guard, fieldGuard, where: relationWhere } = splitReadGuard(fieldWhere)\n\t\t\t\tconst guards = { row: Object.keys(guard).length > 0, field: Object.keys(fieldGuard).length > 0 }\n\t\t\t\treturn { guard, fieldGuard, where: relationWhere, path: guards.row || guards.field ? path.for(hopPathSegment(fieldName, guards)) : targetPath }\n\t\t\t}\n\t\t\t// A masked relation field reads empty: the hop sees no related row where its field guard does not hold.\n\t\t\tconst fieldGuardCondition = (fieldGuard: Input.OptionalWhere): Literal | undefined => {\n\t\t\t\tif (Object.keys(fieldGuard).length === 0) {\n\t\t\t\t\treturn undefined\n\t\t\t\t}\n\t\t\t\tconst condition = SqlConditionBuilder.process(clause =>\n\t\t\t\t\tthis.buildRecursive({ conditionBuilder: clause, entity, path, where: fieldGuard, joinList, allowManyJoin, negated: false })\n\t\t\t\t).getSql()\n\t\t\t\treturn condition === null ? undefined : new Literal(`coalesce(${condition.sql}, false)`, condition.parameters)\n\t\t\t}\n\t\t\tconst existsIfReadable = (fieldGuard: Input.OptionalWhere, subquery: SelectBuilder<SelectBuilder.Result>): SqlConditionBuilder => {\n\t\t\t\tconst readable = fieldGuardCondition(fieldGuard)\n\t\t\t\treturn readable === undefined ? conditionBuilder.exists(subquery) : conditionBuilder.and(clause => clause.with(readable).exists(subquery))\n\t\t\t}\n\n\t\t\tconst joinedWhere = (context: Model.AnyRelationContext): SqlConditionBuilder => {\n\t\t\t\tconst { targetEntity, relation, entity } = context\n\t\t\t\tconst { guard, fieldGuard, where: relationWhere, path: targetPath } = hop()\n\t\t\t\tif (Object.keys(relationWhere).length === 0) {\n\t\t\t\t\treturn conditionBuilder\n\t\t\t\t}\n\t\t\t\t// The FK shortcut skips the join, so it is only valid while every target row is readable.\n\t\t\t\tif (isIt<Model.JoiningColumnRelation>(relation, 'joiningColumn') && Object.keys(guard).length === 0 && Object.keys(fieldGuard).length === 0) {\n\t\t\t\t\tconst primaryCondition = this.transformWhereToPrimaryCondition(relationWhere, targetEntity.primary)\n\t\t\t\t\tif (primaryCondition !== null) {\n\t\t\t\t\t\treturn this.conditionBuilder.build(\n\t\t\t\t\t\t\tconditionBuilder,\n\t\t\t\t\t\t\ttableName,\n\t\t\t\t\t\t\trelation.joiningColumn.columnName,\n\t\t\t\t\t\t\ttargetEntity.fields[targetEntity.primary] as Model.AnyColumn,\n\t\t\t\t\t\t\tprimaryCondition,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tjoinList.push({\n\t\t\t\t\tpath: targetPath,\n\t\t\t\t\tentity,\n\t\t\t\t\trelationName: relation.name,\n\t\t\t\t\ttargetSource: this.createGuardedSource(targetEntity, targetPath, guard),\n\t\t\t\t\tjoinCondition: fieldGuardCondition(fieldGuard),\n\t\t\t\t})\n\n\t\t\t\treturn this.buildRecursive({\n\t\t\t\t\tconditionBuilder,\n\t\t\t\t\tentity: targetEntity,\n\t\t\t\t\tpath: targetPath,\n\t\t\t\t\twhere: relationWhere,\n\t\t\t\t\tjoinList,\n\t\t\t\t\tallowManyJoin,\n\t\t\t\t\tnegated,\n\t\t\t\t})\n\t\t\t}\n\n\t\t\tconditionBuilder = acceptFieldVisitor<SqlConditionBuilder>(this.schema, entity, fieldName, {\n\t\t\t\tvisitColumn: ({ entity, column }) => {\n\t\t\t\t\treturn this.conditionBuilder.build(conditionBuilder, tableName, column.columnName, column, fieldWhere as Input.Condition<Input.ColumnValue>)\n\t\t\t\t},\n\t\t\t\tvisitOneHasOneInverse: joinedWhere,\n\t\t\t\tvisitOneHasOneOwning: joinedWhere,\n\t\t\t\tvisitManyHasOne: joinedWhere,\n\t\t\t\tvisitManyHasManyInverse: context => {\n\t\t\t\t\tif (allowManyJoin && !this.useExistsInHasManyFilter) {\n\t\t\t\t\t\treturn joinedWhere(context)\n\t\t\t\t\t}\n\t\t\t\t\tconst { guard, fieldGuard, where: relationWhere, path: targetPath } = hop()\n\n\t\t\t\t\treturn existsIfReadable(\n\t\t\t\t\t\tfieldGuard,\n\t\t\t\t\t\tthis.createManyHasManySubquery(\n\t\t\t\t\t\t\t[tableName, entity.primaryColumn],\n\t\t\t\t\t\t\trelationWhere,\n\t\t\t\t\t\t\tguard,\n\t\t\t\t\t\t\tcontext.targetEntity,\n\t\t\t\t\t\t\tcontext.targetRelation.joiningTable,\n\t\t\t\t\t\t\t'inverse',\n\t\t\t\t\t\t\ttargetPath,\n\t\t\t\t\t\t),\n\t\t\t\t\t)\n\t\t\t\t},\n\t\t\t\tvisitManyHasManyOwning: context => {\n\t\t\t\t\tif (allowManyJoin && !this.useExistsInHasManyFilter) {\n\t\t\t\t\t\treturn joinedWhere(context)\n\t\t\t\t\t}\n\t\t\t\t\tconst { guard, fieldGuard, where: relationWhere, path: targetPath } = hop()\n\n\t\t\t\t\treturn existsIfReadable(\n\t\t\t\t\t\tfieldGuard,\n\t\t\t\t\t\tthis.createManyHasManySubquery(\n\t\t\t\t\t\t\t[tableName, entity.primaryColumn],\n\t\t\t\t\t\t\trelationWhere,\n\t\t\t\t\t\t\tguard,\n\t\t\t\t\t\t\tcontext.targetEntity,\n\t\t\t\t\t\t\tcontext.relation.joiningTable,\n\t\t\t\t\t\t\t'owning',\n\t\t\t\t\t\t\ttargetPath,\n\t\t\t\t\t\t),\n\t\t\t\t\t)\n\t\t\t\t},\n\t\t\t\tvisitOneHasMany: context => {\n\t\t\t\t\tif (allowManyJoin && !this.useExistsInHasManyFilter) {\n\t\t\t\t\t\treturn joinedWhere(context)\n\t\t\t\t\t}\n\t\t\t\t\tconst { guard, fieldGuard, where: relationWhere, path: targetPath } = hop()\n\n\t\t\t\t\tif (this.hasRootIsNull(relationWhere, context.targetEntity)) {\n\t\t\t\t\t\t// The null-extended row of the LEFT JOIN makes a parent without (readable) children match a\n\t\t\t\t\t\t// column `isNull`; the guarded source keeps unreadable children out of the join.\n\t\t\t\t\t\tconst subquery = (joinsChildren: boolean) => {\n\t\t\t\t\t\t\tconst qb = SelectBuilder.create()\n\t\t\t\t\t\t\t\t.select(it => it.raw('1'))\n\t\t\t\t\t\t\t\t.from(new Literal(`(select ${wrapIdentifier(tableName)}.${wrapIdentifier(entity.primaryColumn)})`), targetPath.for('tmp_').alias)\n\t\t\t\t\t\t\t\t.leftJoin(\n\t\t\t\t\t\t\t\t\tthis.createGuardedSource(context.targetEntity, targetPath, guard) ?? context.targetEntity.tableName,\n\t\t\t\t\t\t\t\t\ttargetPath.alias,\n\t\t\t\t\t\t\t\t\tit =>\n\t\t\t\t\t\t\t\t\t\tjoinsChildren\n\t\t\t\t\t\t\t\t\t\t\t? it.columnsEq([targetPath.for('tmp_').alias, entity.primaryColumn], [targetPath.alias, context.targetRelation.joiningColumn.columnName])\n\t\t\t\t\t\t\t\t\t\t\t: it.raw('false'),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\treturn this.buildInternal({\n\t\t\t\t\t\t\t\tentity: context.targetEntity,\n\t\t\t\t\t\t\t\tpath: targetPath,\n\t\t\t\t\t\t\t\twhere: relationWhere,\n\t\t\t\t\t\t\t\tcallback: cb => qb.where(clause => cb(clause)),\n\t\t\t\t\t\t\t\tallowManyJoin: true,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst readable = fieldGuardCondition(fieldGuard)\n\t\t\t\t\t\tif (readable === undefined) {\n\t\t\t\t\t\t\treturn conditionBuilder.exists(subquery(true))\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// A masked relation is evaluated on the null-extended row alone, like a parent without children.\n\t\t\t\t\t\tconst withChildren = subquery(true).createQuery(new Compiler.Context(Compiler.SCHEMA_PLACEHOLDER, new Set()))\n\t\t\t\t\t\tconst withoutChildren = subquery(false).createQuery(new Compiler.Context(Compiler.SCHEMA_PLACEHOLDER, new Set()))\n\t\t\t\t\t\treturn conditionBuilder.with(\n\t\t\t\t\t\t\tnew Literal(`case when ${readable.sql} then exists (${withChildren.sql}) else exists (${withoutChildren.sql}) end`, [\n\t\t\t\t\t\t\t\t...readable.parameters,\n\t\t\t\t\t\t\t\t...withChildren.parameters,\n\t\t\t\t\t\t\t\t...withoutChildren.parameters,\n\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t\tconst qb = SelectBuilder.create()\n\t\t\t\t\t\t.select(it => it.raw('1'))\n\t\t\t\t\t\t.from(context.targetEntity.tableName, targetPath.alias)\n\t\t\t\t\t\t.where(it => it.columnsEq([tableName, entity.primaryColumn], [targetPath.alias, context.targetRelation.joiningColumn.columnName]))\n\n\t\t\t\t\treturn existsIfReadable(\n\t\t\t\t\t\tfieldGuard,\n\t\t\t\t\t\tthis.buildInternal({\n\t\t\t\t\t\t\tentity: context.targetEntity,\n\t\t\t\t\t\t\tpath: targetPath,\n\t\t\t\t\t\t\twhere: this.combineWhereAnd([relationWhere, guard]),\n\t\t\t\t\t\t\tcallback: cb => qb.where(clause => cb(clause)),\n\t\t\t\t\t\t\tallowManyJoin: true,\n\t\t\t\t\t\t}),\n\t\t\t\t\t)\n\t\t\t\t},\n\t\t\t})\n\t\t}\n\t\treturn conditionBuilder\n\t}\n\n\t/**\n\t * A condition over a cell-level column holds on a masked cell iff it holds on NULL. Outside a negation FALSE and\n\t * NULL drop the row alike, so only a condition that is TRUE on NULL needs more than `cond AND guard`; under a\n\t * negation the masked cell must also keep NULL as NULL.\n\t */\n\tprivate buildMaskedCell(\n\t\tconditionBuilder: SqlConditionBuilder,\n\t\tentity: Model.Entity,\n\t\tpath: Path,\n\t\t{ guard, where }: MaskedCell,\n\t\tjoinList: WhereJoinDefinition[],\n\t\tallowManyJoin: boolean,\n\t\tnegated: boolean,\n\t): SqlConditionBuilder {\n\t\tconst compile = (where: Input.OptionalWhere) =>\n\t\t\tSqlConditionBuilder.process(clause => this.buildRecursive({ conditionBuilder: clause, entity, path, where, joinList, allowManyJoin, negated }))\n\t\t\t\t.getSql()\n\t\tconst condition = compile(where)\n\t\tif (condition === null) {\n\t\t\treturn conditionBuilder\n\t\t}\n\t\tconst guardCondition = compile(guard)\n\t\tif (guardCondition === null) {\n\t\t\treturn conditionBuilder.with(condition)\n\t\t}\n\t\tconst onNull = this.evaluateWhereOnNull(where, entity)\n\t\tconst crispGuard = `coalesce(${guardCondition.sql}, false)`\n\t\tif (onNull === 'true') {\n\t\t\treturn conditionBuilder.with(new Literal(`(${condition.sql} or not ${crispGuard})`, [...condition.parameters, ...guardCondition.parameters]))\n\t\t}\n\t\tif (!negated) {\n\t\t\treturn conditionBuilder.with(condition).with(guardCondition)\n\t\t}\n\t\tif (onNull === 'false') {\n\t\t\treturn conditionBuilder.with(new Literal(`${condition.sql} and ${crispGuard}`, [...condition.parameters, ...guardCondition.parameters]))\n\t\t}\n\t\treturn conditionBuilder.with(\n\t\t\tnew Literal(`case when ${crispGuard} then ${condition.sql} end`, [...guardCondition.parameters, ...condition.parameters]),\n\t\t)\n\t}\n\n\t/** The three-valued result of a column where on a NULL cell, mirroring how `ConditionBuilder` compiles it. */\n\tprivate evaluateWhereOnNull(where: Input.OptionalWhere, entity: Model.Entity): NullCellValue {\n\t\tconst operands: NullCellValue[] = []\n\t\tfor (const [key, value] of Object.entries(where)) {\n\t\t\tif (value === null || value === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (!isColumn(entity.fields[key]) || !this.isInputCondition(value)) {\n\t\t\t\tthrow new Error(`WhereBuilder: ${MASKED_CELL_KEY} expects a column condition, got ${entity.name}::${key}`)\n\t\t\t}\n\t\t\toperands.push(this.evaluateConditionOnNull(value))\n\t\t}\n\t\treturn combineNullCellValues(operands, 'and')\n\t}\n\n\tprivate evaluateConditionOnNull(condition: Input.Condition): NullCellValue {\n\t\tconst isSet = <T>(value: T | null | undefined): value is T => value !== null && value !== undefined\n\t\tif (!Object.values(condition).some(isSet)) {\n\t\t\treturn 'empty'\n\t\t}\n\t\tif (isSet(condition.and)) {\n\t\t\treturn combineNullCellValues(condition.and.map(it => this.evaluateConditionOnNull(it)), 'and')\n\t\t}\n\t\tif (isSet(condition.or)) {\n\t\t\treturn combineNullCellValues(condition.or.map(it => this.evaluateConditionOnNull(it)), 'or')\n\t\t}\n\t\tif (isSet(condition.not)) {\n\t\t\tconst operand = this.evaluateConditionOnNull(condition.not)\n\t\t\treturn operand === 'true' ? 'false' : operand === 'false' ? 'true' : operand\n\t\t}\n\t\tconst isNull = condition.isNull ?? condition.null\n\t\tif (isSet(isNull)) {\n\t\t\treturn isNull ? 'true' : 'false'\n\t\t}\n\t\tif (isSet(condition.always)) {\n\t\t\treturn 'true'\n\t\t}\n\t\tif (isSet(condition.never)) {\n\t\t\treturn 'false'\n\t\t}\n\t\tif (isSet(condition.in)) {\n\t\t\treturn condition.in.some(it => it !== undefined) ? 'unknown' : 'false'\n\t\t}\n\t\tif (isSet(condition.notIn)) {\n\t\t\treturn condition.notIn.some(it => it !== undefined) ? 'unknown' : 'true'\n\t\t}\n\t\treturn 'unknown'\n\t}\n\n\tprivate createGuardedSource(entity: Model.Entity, path: Path, guard: Input.OptionalWhere): Literal | undefined {\n\t\treturn Object.keys(guard).length === 0 ? undefined : this.buildGuardedSource(entity, path, guard)\n\t}\n\n\tprivate createManyHasManySubquery(\n\t\touterColumn: QueryBuilder.ColumnIdentifier,\n\t\trelationWhere: Input.OptionalWhere,\n\t\tguard: Input.OptionalWhere,\n\t\ttargetEntity: Model.Entity,\n\t\tjoiningTable: Model.JoiningTable,\n\t\tfromSide: 'owning' | 'inverse',\n\t\tpath: Path,\n\t) {\n\t\tconst fromColumn = fromSide === 'owning' ? joiningTable.joiningColumn.columnName : joiningTable.inverseJoiningColumn.columnName\n\t\tconst toColumn = fromSide === 'owning' ? joiningTable.inverseJoiningColumn.columnName : joiningTable.joiningColumn.columnName\n\t\tconst junctionPath = path.for('junction_')\n\t\tconst qb = SelectBuilder.create<SelectBuilder.Result>()\n\t\t\t.from(joiningTable.tableName, junctionPath.alias)\n\t\t\t.select(it => it.raw('1'))\n\t\t\t.where(it => it.columnsEq(outerColumn, [junctionPath.alias, fromColumn]))\n\n\t\t// The junction-only shortcut skips the target table, so it is only valid while every target row is readable.\n\t\tconst primaryCondition = Object.keys(guard).length === 0 ? this.transformWhereToPrimaryCondition(relationWhere, targetEntity.primary) : null\n\t\tif (primaryCondition !== null) {\n\t\t\tconst columnType = targetEntity.fields[targetEntity.primary] as Model.AnyColumn\n\n\t\t\treturn qb.where(condition => this.conditionBuilder.build(condition, junctionPath.alias, toColumn, columnType, primaryCondition))\n\t\t}\n\n\t\tconst qbJoined = qb.join(\n\t\t\ttargetEntity.tableName,\n\t\t\tpath.alias,\n\t\t\tclause => clause.compareColumns([junctionPath.alias, toColumn], Operator.eq, [path.alias, targetEntity.primary]),\n\t\t)\n\t\treturn this.buildInternal({\n\t\t\tentity: targetEntity,\n\t\t\tpath: this.pathFactory.create([], path.fullAlias),\n\t\t\twhere: this.combineWhereAnd([relationWhere, guard]),\n\t\t\tcallback: cb => qbJoined.where(clause => cb(clause)),\n\t\t\tallowManyJoin: true,\n\t\t})\n\t}\n\n\tprivate combineWhereAnd(wheres: readonly Input.OptionalWhere[]): Input.OptionalWhere {\n\t\tconst nonEmpty = wheres.filter(it => Object.keys(it).length > 0)\n\t\tif (nonEmpty.length === 0) {\n\t\t\treturn {}\n\t\t}\n\t\treturn nonEmpty.length === 1 ? nonEmpty[0] : { and: nonEmpty }\n\t}\n\n\tprivate isInputCondition(value: unknown): value is Input.Condition {\n\t\treturn value !== null && typeof value === 'object' && !Array.isArray(value)\n\t}\n\n\tprivate isOptionalWhere(value: unknown): value is Input.OptionalWhere {\n\t\treturn value !== null && value !== undefined && typeof value === 'object' && !Array.isArray(value)\n\t}\n\n\tprivate transformWhereToPrimaryCondition(where: Input.OptionalWhere, primaryField: string): Input.Condition<never> | null {\n\t\tconst keys = Object.keys(where)\n\t\tif (keys.filter(it => !['and', 'or', 'not', primaryField].includes(it)).length > 0) {\n\t\t\treturn null\n\t\t}\n\t\tlet condition: {\n\t\t\tand?: Array<Input.Condition<never>>\n\t\t\tor?: Array<Input.Condition<never>>\n\t\t\tnot?: Input.Condition<never>\n\t\t} = {}\n\t\tif (where.and) {\n\t\t\tconst conditions = where.and\n\t\t\t\t.filter((it): it is Input.Where => !!it)\n\t\t\t\t.map(it => this.transformWhereToPrimaryCondition(it, primaryField))\n\t\t\tif (conditions.includes(null)) {\n\t\t\t\treturn null\n\t\t\t}\n\t\t\tcondition.and = conditions as Input.Condition<never>[]\n\t\t}\n\t\tif (where.or) {\n\t\t\tconst conditions = where.or\n\t\t\t\t.filter((it): it is Input.Where => !!it)\n\t\t\t\t.map(it => this.transformWhereToPrimaryCondition(it, primaryField))\n\t\t\tif (conditions.includes(null)) {\n\t\t\t\treturn null\n\t\t\t}\n\t\t\tcondition.or = conditions as Input.Condition<never>[]\n\t\t}\n\t\tif (where.not) {\n\t\t\tconst conditions = this.transformWhereToPrimaryCondition(where.not, primaryField)\n\t\t\tif (conditions === null) {\n\t\t\t\treturn null\n\t\t\t}\n\t\t\tcondition.not = conditions as Input.Condition<never>\n\t\t}\n\t\tif (where[primaryField]) {\n\t\t\tif (Object.keys(condition).length > 0) {\n\t\t\t\treturn { and: [condition, where[primaryField] as Input.Condition<never>] }\n\t\t\t}\n\t\t\treturn where[primaryField] as Input.Condition<never>\n\t\t}\n\t\treturn condition\n\t}\n\n\tprivate hasRootIsNull(where: Input.OptionalWhere, entity: Model.Entity): boolean {\n\t\tfor (const key in where) {\n\t\t\tif (key === 'and' || key === 'or') {\n\t\t\t\tif (where[key]?.some(it => it && this.hasRootIsNull(it, entity))) {\n\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t} else if (key === 'not') {\n\t\t\t\tif (where.not && this.hasRootIsNull(where.not, entity)) {\n\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t} else if (key === MASKED_CELL_KEY) {\n\t\t\t\tif (parseMaskedCells(where[key]).some(cell => this.hasRootIsNull(cell.where, entity) || this.hasRootIsNull(cell.guard, entity))) {\n\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t} else if (isColumn(entity.fields[key])) {\n\t\t\t\tconst condition = where[key]\n\t\t\t\tif (this.isInputCondition(condition) && this.conditionHasIsNull(condition)) {\n\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn false\n\t}\n\n\tprivate conditionHasIsNull(cond: Input.Condition): boolean {\n\t\treturn cond.isNull !== undefined\n\t\t\t|| cond.and?.some(item => this.conditionHasIsNull(item)) === true\n\t\t\t|| cond.or?.some(item => this.conditionHasIsNull(item)) === true\n\t\t\t|| (cond.not !== undefined && this.conditionHasIsNull(cond.not))\n\t}\n}\n\n/** `empty` is a condition that compiles to nothing, so it neither holds nor fails. */\ntype NullCellValue = 'true' | 'false' | 'unknown' | 'empty'\n\nconst combineNullCellValues = (operands: readonly NullCellValue[], operator: 'and' | 'or'): NullCellValue => {\n\tconst present = operands.filter(it => it !== 'empty')\n\tif (present.length === 0) {\n\t\treturn 'empty'\n\t}\n\tconst dominant = operator === 'and' ? 'false' : 'true'\n\tif (present.includes(dominant)) {\n\t\treturn dominant\n\t}\n\treturn present.includes('unknown') ? 'unknown' : operator === 'and' ? 'true' : 'false'\n}\n\nexport type WhereJoinDefinition = { path: Path; entity: Model.Entity; relationName: string; targetSource?: Literal; joinCondition?: Literal }\n"],"names":["SqlConditionBuilder","where","entity","targetPath","qb"],"mappings":";;;;;AAyBO,MAAM,aAAa;AAAA,EACzB,YACkB,QACA,aACA,kBACA,aACA,gBACA,0BAChB;AANgB,SAAA,SAAA;AACA,SAAA,cAAA;AACA,SAAA,mBAAA;AACA,SAAA,cAAA;AACA,SAAA,iBAAA;AACA,SAAA,2BAAA;AAAA,EACf;AAAA,EAEI,MACN,IACA,QACA,MACA,OACA,oBAA4C,IACzB;AACnB,UAAM,iBAAiB,KAAK,eAAe,SAAS,OAAO,QAAQ,iBAAiB;AACpF,WAAO,KAAK,cAAc;AAAA,MACzB;AAAA,MACA;AAAA,MACA,OAAO;AAAA,MACP,UAAU,CAAA,OAAM,GAAG,MAAM,CAAA,WAAU,GAAG,MAAM,CAAC;AAAA,MAC7C,eAAe;AAAA,IAAA,CACf;AAAA,EACF;AAAA,EAEO,cACN,QACA,MACA,OACA,UACA,oBAA4C,IACzB;AACnB,UAAM,iBAAiB,KAAK,eAAe,SAAS,OAAO,QAAQ,iBAAiB;AACpF,WAAO,KAAK,cAAc;AAAA,MACzB;AAAA,MACA;AAAA,MACA,OAAO;AAAA,MACP;AAAA,MACA,eAAe;AAAA,IAAA,CACf;AAAA,E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AA,EACR;AACA,SAAO,QAAQ,SAAS,SAAS,IAAI,YAAY,aAAa,QAAQ,SAAS;AAChF;"}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const getFieldReadPredicate = (predicateFactory, entity, field, relationPath) => {
4
+ const fieldPredicate = predicateFactory.getFieldReadPredicate(entity, field.name, relationPath);
5
+ return fieldPredicate.isSameAsPrimary ? void 0 : fieldPredicate.predicate;
6
+ };
7
+ exports.getFieldReadPredicate = getFieldReadPredicate;
8
+ //# sourceMappingURL=getFieldReadPredicate.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getFieldReadPredicate.cjs","sources":["../../../../../../packages/engine-content-api/src/mapper/select/getFieldReadPredicate.ts"],"sourcesContent":["import { Acl, Model } from '@contember/schema'\nimport { PredicateFactory } from '../../acl/index.js'\n\nexport const getFieldReadPredicate = (\n\tpredicateFactory: PredicateFactory,\n\tentity: Model.Entity,\n\tfield: Model.AnyField,\n\trelationPath: readonly Model.AnyRelationContext[],\n): Acl.Predicate | undefined => {\n\tconst fieldPredicate = predicateFactory.getFieldReadPredicate(entity, field.name, relationPath)\n\treturn fieldPredicate.isSameAsPrimary ? undefined : fieldPredicate.predicate\n}\n"],"names":[],"mappings":";;AAGO,MAAM,wBAAwB,CACpC,kBACA,QACA,OACA,iBAC+B;AAC/B,QAAM,iBAAiB,iBAAiB,sBAAsB,QAAQ,MAAM,MAAM,YAAY;AAC9F,SAAO,eAAe,kBAAkB,SAAY,eAAe;AACpE;;"}
@@ -0,0 +1,8 @@
1
+ const getFieldReadPredicate = (predicateFactory, entity, field, relationPath) => {
2
+ const fieldPredicate = predicateFactory.getFieldReadPredicate(entity, field.name, relationPath);
3
+ return fieldPredicate.isSameAsPrimary ? void 0 : fieldPredicate.predicate;
4
+ };
5
+ export {
6
+ getFieldReadPredicate
7
+ };
8
+ //# sourceMappingURL=getFieldReadPredicate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getFieldReadPredicate.js","sources":["../../../../../../packages/engine-content-api/src/mapper/select/getFieldReadPredicate.ts"],"sourcesContent":["import { Acl, Model } from '@contember/schema'\nimport { PredicateFactory } from '../../acl/index.js'\n\nexport const getFieldReadPredicate = (\n\tpredicateFactory: PredicateFactory,\n\tentity: Model.Entity,\n\tfield: Model.AnyField,\n\trelationPath: readonly Model.AnyRelationContext[],\n): Acl.Predicate | undefined => {\n\tconst fieldPredicate = predicateFactory.getFieldReadPredicate(entity, field.name, relationPath)\n\treturn fieldPredicate.isSameAsPrimary ? undefined : fieldPredicate.predicate\n}\n"],"names":[],"mappings":"AAGO,MAAM,wBAAwB,CACpC,kBACA,QACA,OACA,iBAC+B;AAC/B,QAAM,iBAAiB,iBAAiB,sBAAsB,QAAQ,MAAM,MAAM,YAAY;AAC9F,SAAO,eAAe,kBAAkB,SAAY,eAAe;AACpE;"}