@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
@@ -2,36 +2,72 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const schema = require("@contember/schema");
4
4
  const schemaUtils = require("@contember/schema-utils");
5
- class PredicatesInjector {
5
+ var __defProp = Object.defineProperty;
6
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
+ var __publicField = (obj, key, value) => __defNormalProp(obj, key + "", value);
8
+ const READ_GUARD_KEY = "$readGuard";
9
+ const FIELD_GUARD_KEY = "$fieldGuard";
10
+ const MASKED_CELL_KEY = "$maskedCell";
11
+ const isWhere = (value) => value !== null && value !== void 0 && typeof value === "object" && !Array.isArray(value);
12
+ const parseMaskedCells = (value) => {
13
+ if (!Array.isArray(value)) {
14
+ throw new Error(`${MASKED_CELL_KEY} expects a list of masked cells`);
15
+ }
16
+ return value.map((cell) => {
17
+ if (!isWhere(cell) || !isWhere(cell.guard) || !isWhere(cell.where)) {
18
+ throw new Error(`${MASKED_CELL_KEY} expects a guard and a where`);
19
+ }
20
+ return { guard: cell.guard, where: cell.where };
21
+ });
22
+ };
23
+ const splitFieldGuard = (where) => {
24
+ const { [FIELD_GUARD_KEY]: fieldGuard, ...rest } = where;
25
+ return { fieldGuard: isWhere(fieldGuard) ? fieldGuard : void 0, where: rest };
26
+ };
27
+ const splitReadGuard = (where) => {
28
+ const { [READ_GUARD_KEY]: guard, [FIELD_GUARD_KEY]: fieldGuard, ...rest } = where;
29
+ return { guard: isWhere(guard) ? guard : {}, fieldGuard: isWhere(fieldGuard) ? fieldGuard : {}, where: rest };
30
+ };
31
+ const _PredicatesInjector = class _PredicatesInjector2 {
6
32
  constructor(schema2, predicateFactory) {
7
33
  this.schema = schema2;
8
34
  this.predicateFactory = predicateFactory;
9
35
  }
10
- inject(entity, where, relationContext, ancestorPath) {
11
- const isQueryRoot = !relationContext && (!ancestorPath || ancestorPath.length === 0);
12
- const restrictedWhere = this.injectToWhere(where, entity, true, relationContext, false, ancestorPath ?? [], isQueryRoot);
13
- return this.createWhere(entity, void 0, restrictedWhere, relationContext, false, ancestorPath ?? [], isQueryRoot);
14
- }
15
36
  /**
16
- * Finds an ancestor in the path that matches the given relation as a back-reference.
17
- * A match occurs when:
18
- * 1. The relation we're traversing has the same name as the inverse (targetRelation) of a relation in the ancestor path
19
- * 2. AND the entity where our relation is defined matches the targetEntity in the path
20
- * (to prevent false positives when different entities have relations with the same name)
37
+ * `scope` is the scope of the entry entity. Relations traversed by `where` are always nested. A lookup
38
+ * without a relation context (a by-unique lookup of a mutation) states the scope of the row it looks for.
21
39
  */
22
- findBackReferencedAncestor(ancestorPath, relationName, relationSourceEntityName) {
23
- return ancestorPath.find(
24
- (ctx) => ctx.targetRelation?.name === relationName && ctx.targetEntity.name === relationSourceEntityName
25
- );
40
+ inject(entity, where, scope, relationContext, ancestorPath) {
41
+ const restrictedWhere = this.injectToWhere(where, entity, true, relationContext, ancestorPath ?? [], scope);
42
+ return this.createWhere(entity, restrictedWhere, relationContext, scope);
26
43
  }
27
- createWhere(entity, fieldNames, where, relationContext, isBackReferenceContext, ancestorPath, isQueryRoot) {
28
- const shouldSimplify = isBackReferenceContext === true && ancestorPath !== void 0 && relationContext !== void 0 && this.findBackReferencedAncestor(ancestorPath, relationContext.relation.name, relationContext.entity.name) !== void 0;
29
- let predicatesWhere;
30
- if (shouldSimplify) {
31
- predicatesWhere = { [entity.primary]: { always: true } };
32
- } else {
33
- predicatesWhere = this.predicateFactory.create(entity, schema.Acl.Operation.read, fieldNames, relationContext, isQueryRoot);
44
+ /**
45
+ * Row-level read predicate guarding a relation hop's target (the nested scope, since the target
46
+ * is reached through a relation). Empty when the target is freely readable, or when the hop is a to-one
47
+ * back-reference to an ancestor row that is already verified readable. Shared by the filter injection
48
+ * and the order-by join so both guard the same hop identically (they share the join alias).
49
+ */
50
+ createReadGuard(relationContext, ancestorPath) {
51
+ if (this.canSimplifyBackReference(ancestorPath, relationContext)) {
52
+ return {};
34
53
  }
54
+ return this.predicateFactory.create(relationContext.targetEntity, schema.Acl.Operation.read, "nested", void 0, relationContext);
55
+ }
56
+ /**
57
+ * A hop is a back-reference when it is the inverse of the hop that reached its source entity. Only the
58
+ * immediate parent counts: an earlier ancestor of the same entity is generally a different row.
59
+ */
60
+ canSimplifyBackReference(ancestorPath, relationContext) {
61
+ const parent = ancestorPath[ancestorPath.length - 1];
62
+ const isBackReference = parent !== void 0 && parent.targetRelation?.name === relationContext.relation.name && parent.targetEntity.name === relationContext.entity.name;
63
+ return isBackReference && _PredicatesInjector2.toOneBackReferenceTypes.has(relationContext.type);
64
+ }
65
+ /**
66
+ * ANDs the row-level read predicate of the injection root onto `where` — the only place the row predicate
67
+ * lands in the WHERE; relation targets carry theirs in `READ_GUARD_KEY` instead.
68
+ */
69
+ createWhere(entity, where, relationContext, scope) {
70
+ const predicatesWhere = this.predicateFactory.create(entity, schema.Acl.Operation.read, scope, void 0, relationContext);
35
71
  const and = [where, predicatesWhere].filter((it) => Object.keys(it).length > 0);
36
72
  if (and.length === 0) {
37
73
  return {};
@@ -41,25 +77,27 @@ class PredicatesInjector {
41
77
  }
42
78
  return { and };
43
79
  }
44
- injectToWhere(where, entity, isRoot, relationContext, isBackReferenceContext, ancestorPath, isQueryRoot) {
80
+ injectToWhere(where, entity, isRoot, relationContext, ancestorPath, scope) {
45
81
  const resultWhere = {};
46
82
  if (where.and) {
47
83
  resultWhere.and = where.and.filter((it) => !!it).map(
48
- (it) => this.injectToWhere(it, entity, isRoot, relationContext, isBackReferenceContext, ancestorPath, isQueryRoot)
84
+ (it) => this.injectToWhere(it, entity, isRoot, relationContext, ancestorPath, scope)
49
85
  );
50
86
  }
51
87
  if (where.or) {
52
88
  resultWhere.or = where.or.filter((it) => !!it).map(
53
- (it) => this.injectToWhere(it, entity, isRoot, relationContext, isBackReferenceContext, ancestorPath, isQueryRoot)
89
+ (it) => this.injectToWhere(it, entity, isRoot, relationContext, ancestorPath, scope)
54
90
  );
55
91
  }
56
92
  if (where.not) {
57
- resultWhere.not = this.injectToWhere(where.not, entity, isRoot, relationContext, isBackReferenceContext, ancestorPath, isQueryRoot);
93
+ resultWhere.not = this.injectToWhere(where.not, entity, isRoot, relationContext, ancestorPath, scope);
58
94
  }
59
95
  const fields = Object.keys(where).filter((it) => !["and", "or", "not"].includes(it));
60
96
  if (fields.length === 0) {
61
97
  return resultWhere;
62
98
  }
99
+ const isCellLevel = (field) => this.predicateFactory.shouldApplyCellLevelPredicate(entity, schema.Acl.Operation.read, field, scope);
100
+ const fieldGuard = (field) => this.predicateFactory.create(entity, schema.Acl.Operation.read, scope, [field], relationContext);
63
101
  for (let field of fields) {
64
102
  resultWhere[field] = schemaUtils.acceptFieldVisitor(this.schema, entity, field, {
65
103
  visitColumn: () => where[field],
@@ -68,16 +106,43 @@ class PredicatesInjector {
68
106
  if (relationWhere === null) {
69
107
  return null;
70
108
  }
71
- const isBackReference = this.findBackReferencedAncestor(ancestorPath, context.relation.name, context.entity.name) !== void 0;
72
- const nestedIsBackReferenceContext = isBackReference || isBackReferenceContext;
73
109
  const nestedAncestorPath = [...ancestorPath, context];
74
- return this.injectToWhere(relationWhere, context.targetEntity, false, context, nestedIsBackReferenceContext, nestedAncestorPath, isQueryRoot);
110
+ const nestedWhere = this.injectToWhere(relationWhere, context.targetEntity, false, context, nestedAncestorPath, "nested");
111
+ const guard = this.createReadGuard(context, ancestorPath);
112
+ return {
113
+ ...nestedWhere,
114
+ ...Object.keys(guard).length > 0 ? { [READ_GUARD_KEY]: guard } : {},
115
+ ...isCellLevel(field) ? { [FIELD_GUARD_KEY]: fieldGuard(field) } : {}
116
+ };
75
117
  }
76
118
  });
77
119
  }
78
- const fieldsForPredicate = !isRoot ? fields : fields.filter((it) => this.predicateFactory.shouldApplyCellLevelPredicate(entity, schema.Acl.Operation.read, it, isQueryRoot));
79
- return this.createWhere(entity, fieldsForPredicate, resultWhere, relationContext, isBackReferenceContext, ancestorPath, isQueryRoot);
120
+ const maskedColumns = fields.filter((it) => schemaUtils.isColumn(entity.fields[it]) && !this.isEmptyCondition(where[it]) && isCellLevel(it));
121
+ if (maskedColumns.length === 0) {
122
+ return resultWhere;
123
+ }
124
+ resultWhere[MASKED_CELL_KEY] = maskedColumns.map((field) => ({ guard: fieldGuard(field), where: { [field]: resultWhere[field] } }));
125
+ for (const field of maskedColumns) {
126
+ delete resultWhere[field];
127
+ }
128
+ return resultWhere;
129
+ }
130
+ isEmptyCondition(value) {
131
+ return isWhere(value) && Object.keys(value).length === 0;
80
132
  }
81
- }
133
+ };
134
+ __publicField(_PredicatesInjector, "toOneBackReferenceTypes", /* @__PURE__ */ new Set([
135
+ "manyHasOne",
136
+ "oneHasOneOwning",
137
+ "oneHasOneInverse"
138
+ ]));
139
+ let PredicatesInjector = _PredicatesInjector;
140
+ exports.FIELD_GUARD_KEY = FIELD_GUARD_KEY;
141
+ exports.MASKED_CELL_KEY = MASKED_CELL_KEY;
82
142
  exports.PredicatesInjector = PredicatesInjector;
143
+ exports.READ_GUARD_KEY = READ_GUARD_KEY;
144
+ exports.isWhere = isWhere;
145
+ exports.parseMaskedCells = parseMaskedCells;
146
+ exports.splitFieldGuard = splitFieldGuard;
147
+ exports.splitReadGuard = splitReadGuard;
83
148
  //# sourceMappingURL=PredicatesInjector.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"PredicatesInjector.cjs","sources":["../../../../../packages/engine-content-api/src/acl/PredicatesInjector.ts"],"sourcesContent":["import { Acl, Input, Model, Writable } from '@contember/schema'\nimport { acceptFieldVisitor } from '@contember/schema-utils'\nimport { PredicateFactory } from './PredicateFactory.js'\n\nexport class PredicatesInjector {\n\tconstructor(private readonly schema: Model.Schema, private readonly predicateFactory: PredicateFactory) {}\n\n\tpublic inject(\n\t\tentity: Model.Entity,\n\t\twhere: Input.OptionalWhere,\n\t\trelationContext?: Model.AnyRelationContext,\n\t\tancestorPath?: readonly Model.AnyRelationContext[],\n\t): Input.OptionalWhere {\n\t\tconst isQueryRoot = !relationContext && (!ancestorPath || ancestorPath.length === 0)\n\t\tconst restrictedWhere = this.injectToWhere(where, entity, true, relationContext, false, ancestorPath ?? [], isQueryRoot)\n\t\treturn this.createWhere(entity, undefined, restrictedWhere, relationContext, false, ancestorPath ?? [], isQueryRoot)\n\t}\n\n\t/**\n\t * Finds an ancestor in the path that matches the given relation as a back-reference.\n\t * A match occurs when:\n\t * 1. The relation we're traversing has the same name as the inverse (targetRelation) of a relation in the ancestor path\n\t * 2. AND the entity where our relation is defined matches the targetEntity in the path\n\t * (to prevent false positives when different entities have relations with the same name)\n\t */\n\tprivate findBackReferencedAncestor(\n\t\tancestorPath: readonly Model.AnyRelationContext[],\n\t\trelationName: string,\n\t\trelationSourceEntityName: string,\n\t): Model.AnyRelationContext | undefined {\n\t\treturn ancestorPath.find(ctx =>\n\t\t\tctx.targetRelation?.name === relationName\n\t\t\t&& ctx.targetEntity.name === relationSourceEntityName\n\t\t)\n\t}\n\n\tprivate createWhere(\n\t\tentity: Model.Entity,\n\t\tfieldNames: string[] | undefined,\n\t\twhere: Input.OptionalWhere,\n\t\trelationContext?: Model.AnyRelationContext,\n\t\tisBackReferenceContext?: boolean,\n\t\tancestorPath?: readonly Model.AnyRelationContext[],\n\t\tisQueryRoot?: boolean,\n\t): Input.OptionalWhere {\n\t\t// Simplify predicates when:\n\t\t// 1. We're in a back-reference context (inside a filter that traverses back)\n\t\t// 2. AND the relation we traversed to get here corresponds to a relation in our query path\n\t\t// This ensures we only simplify when the traversed relation actually corresponds\n\t\t// to a relation in our query path (not just any relation to the same entity type)\n\t\tconst shouldSimplify = isBackReferenceContext === true\n\t\t\t&& ancestorPath !== undefined\n\t\t\t&& relationContext !== undefined\n\t\t\t&& this.findBackReferencedAncestor(ancestorPath, relationContext.relation.name, relationContext.entity.name) !== undefined\n\n\t\tlet predicatesWhere: Input.OptionalWhere\n\t\tif (shouldSimplify) {\n\t\t\tpredicatesWhere = { [entity.primary]: { always: true } }\n\t\t} else {\n\t\t\tpredicatesWhere = this.predicateFactory.create(entity, Acl.Operation.read, fieldNames, relationContext, isQueryRoot)\n\t\t}\n\n\t\tconst and = [where, predicatesWhere].filter(it => Object.keys(it).length > 0)\n\t\tif (and.length === 0) {\n\t\t\treturn {}\n\t\t}\n\t\tif (and.length === 1) {\n\t\t\treturn and[0]\n\t\t}\n\t\treturn { and: and }\n\t}\n\n\tprivate injectToWhere(\n\t\twhere: Input.OptionalWhere,\n\t\tentity: Model.Entity,\n\t\tisRoot: boolean,\n\t\trelationContext: Model.AnyRelationContext | undefined,\n\t\tisBackReferenceContext: boolean,\n\t\tancestorPath: readonly Model.AnyRelationContext[],\n\t\tisQueryRoot?: boolean,\n\t): Input.OptionalWhere {\n\t\tconst resultWhere: Writable<Input.OptionalWhere> = {}\n\t\tif (where.and) {\n\t\t\tresultWhere.and = where.and.filter((it): it is Input.Where => !!it).map(it =>\n\t\t\t\tthis.injectToWhere(it, entity, isRoot, relationContext, isBackReferenceContext, ancestorPath, isQueryRoot)\n\t\t\t)\n\t\t}\n\t\tif (where.or) {\n\t\t\tresultWhere.or = where.or.filter((it): it is Input.Where => !!it).map(it =>\n\t\t\t\tthis.injectToWhere(it, entity, isRoot, relationContext, isBackReferenceContext, ancestorPath, isQueryRoot)\n\t\t\t)\n\t\t}\n\t\tif (where.not) {\n\t\t\tresultWhere.not = this.injectToWhere(where.not, entity, isRoot, relationContext, isBackReferenceContext, ancestorPath, isQueryRoot)\n\t\t}\n\n\t\tconst fields = Object.keys(where).filter(it => !['and', 'or', 'not'].includes(it))\n\n\t\tif (fields.length === 0) {\n\t\t\treturn resultWhere\n\t\t}\n\t\tfor (let field of fields) {\n\t\t\tresultWhere[field] = acceptFieldVisitor(this.schema, entity, field, {\n\t\t\t\tvisitColumn: () => where[field],\n\t\t\t\tvisitRelation: context => {\n\t\t\t\t\tconst relationWhere = where[field] as Input.OptionalWhere | null\n\t\t\t\t\tif (relationWhere === null) {\n\t\t\t\t\t\treturn null\n\t\t\t\t\t}\n\t\t\t\t\t// Check if this relation is a back-reference to somewhere in our ancestor path\n\t\t\t\t\tconst isBackReference = this.findBackReferencedAncestor(ancestorPath, context.relation.name, context.entity.name) !== undefined\n\t\t\t\t\t// Once we enter a back-reference context, stay in it for nested relations\n\t\t\t\t\tconst nestedIsBackReferenceContext = isBackReference || isBackReferenceContext\n\t\t\t\t\t// Build extended ancestor path for nested traversal\n\t\t\t\t\tconst nestedAncestorPath: Model.AnyRelationContext[] = [...ancestorPath, context]\n\t\t\t\t\treturn this.injectToWhere(relationWhere, context.targetEntity, false, context, nestedIsBackReferenceContext, nestedAncestorPath, isQueryRoot)\n\t\t\t\t},\n\t\t\t})\n\t\t}\n\t\tconst fieldsForPredicate = !isRoot\n\t\t\t? fields\n\t\t\t: fields.filter(it => this.predicateFactory.shouldApplyCellLevelPredicate(entity, Acl.Operation.read, it, isQueryRoot))\n\n\t\treturn this.createWhere(entity, fieldsForPredicate, resultWhere, relationContext, isBackReferenceContext, ancestorPath, isQueryRoot)\n\t}\n}\n"],"names":["schema","Acl","acceptFieldVisitor"],"mappings":";;;;AAIO,MAAM,mBAAmB;AAAA,EAC/B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AoB,WAAW;AAAA,QAC7I;AAAA,MAAA,CACA;AAAA,IACF;AACA,UAAM,qBAAqB,CAAC,SACzB,SACA,OAAO,OAAO,CAAA,OAAM,KAAK,iBAAiB,8BAA8B,QAAQD,OAAAA,IAAI,UAAU,MAAM,IAAI,WAAW,CAAC;AAEvH,WAAO,KAAK,YAAY,QAAQ,oBAAoB,aAAa,iBAAiB,wBAAwB,cAAc,WAAW;AAAA,EACpI;AACD;;"}
1
+ {"version":3,"file":"PredicatesInjector.cjs","sources":["../../../../../packages/engine-content-api/src/acl/PredicatesInjector.ts"],"sourcesContent":["import { Acl, Input, Model, Writable } from '@contember/schema'\nimport { acceptFieldVisitor, isColumn } from '@contember/schema-utils'\nimport { PredicateFactory } from './PredicateFactory.js'\nimport { AclScope } from './AclScope.js'\n\n/**\n * Internal where key carrying the row-level read predicate of a relation target. The injector attaches it\n * to every user-authored relation hop; the WhereBuilder compiles it into the hop's table source (a guarded\n * join / subquery), so an unreadable related row null-extends exactly like an absent one under any boolean\n * shape. `$` cannot appear in a GraphQL name, so the key can never arrive from user input.\n */\nexport const READ_GUARD_KEY = '$readGuard'\n\n/**\n * Internal where key on a relation hop carrying the read predicate of the relation FIELD when it is stricter than\n * the source row's (a cell-level relation). It is a where over the SOURCE entity. The WhereBuilder makes the hop\n * read empty where the predicate does not hold, so a masked relation behaves exactly like an empty one.\n */\nexport const FIELD_GUARD_KEY = '$fieldGuard'\n\n/**\n * Internal where key carrying, for each cell-level column of a where level, its condition (`where`, a single-field\n * where) together with the column's read predicate (`guard`). The WhereBuilder compiles each so that a masked cell\n * behaves exactly like a NULL value: the condition holds on a masked cell iff it holds on NULL. The cells sit next\n * to the other keys of the level, so the level keeps the shape the user wrote.\n */\nexport const MASKED_CELL_KEY = '$maskedCell'\n\nexport const isWhere = (value: Input.OptionalWhere[string]): value is Input.OptionalWhere =>\n\tvalue !== null && value !== undefined && typeof value === 'object' && !Array.isArray(value)\n\nexport type MaskedCell = { guard: Input.OptionalWhere; where: Input.OptionalWhere }\n\nexport const parseMaskedCells = (value: Input.OptionalWhere[string]): MaskedCell[] => {\n\tif (!Array.isArray(value)) {\n\t\tthrow new Error(`${MASKED_CELL_KEY} expects a list of masked cells`)\n\t}\n\treturn value.map(cell => {\n\t\tif (!isWhere(cell) || !isWhere(cell.guard) || !isWhere(cell.where)) {\n\t\t\tthrow new Error(`${MASKED_CELL_KEY} expects a guard and a where`)\n\t\t}\n\t\treturn { guard: cell.guard, where: cell.where }\n\t})\n}\n\n/** Separates the field guard of a relation hop; undefined when the relation field is not cell-level. */\nexport const splitFieldGuard = (where: Input.OptionalWhere): { fieldGuard: Input.OptionalWhere | undefined; where: Input.OptionalWhere } => {\n\tconst { [FIELD_GUARD_KEY]: fieldGuard, ...rest } = where\n\treturn { fieldGuard: isWhere(fieldGuard) ? fieldGuard : undefined, where: rest }\n}\n\nexport type HopGuards = { guard: Input.OptionalWhere; fieldGuard: Input.OptionalWhere; where: Input.OptionalWhere }\n\n/** Separates the hop's read guards from the user-authored remainder; a guard is empty when absent. */\nexport const splitReadGuard = (where: Input.OptionalWhere): HopGuards => {\n\tconst { [READ_GUARD_KEY]: guard, [FIELD_GUARD_KEY]: fieldGuard, ...rest } = where\n\treturn { guard: isWhere(guard) ? guard : {}, fieldGuard: isWhere(fieldGuard) ? fieldGuard : {}, where: rest }\n}\n\nexport class PredicatesInjector {\n\t/**\n\t * Back-reference simplification is only sound for to-one back-hops. A to-one round-trip\n\t * re-reaches the exact ancestor row (already verified readable), so its predicate can be dropped.\n\t * A to-many back-hop reaches the ancestor's SIBLINGS, which are NOT guaranteed readable — dropping\n\t * their row predicate would leak a value/presence oracle over unreadable rows. Fail-closed: only the\n\t * types listed here simplify; anything else keeps the full predicate.\n\t */\n\tprivate static readonly toOneBackReferenceTypes = new Set<Model.AnyRelationContext['type']>([\n\t\t'manyHasOne',\n\t\t'oneHasOneOwning',\n\t\t'oneHasOneInverse',\n\t])\n\n\tconstructor(private readonly schema: Model.Schema, private readonly predicateFactory: PredicateFactory) {}\n\n\t/**\n\t * `scope` is the scope of the entry entity. Relations traversed by `where` are always nested. A lookup\n\t * without a relation context (a by-unique lookup of a mutation) states the scope of the row it looks for.\n\t */\n\tpublic inject(\n\t\tentity: Model.Entity,\n\t\twhere: Input.OptionalWhere,\n\t\tscope: AclScope,\n\t\trelationContext?: Model.AnyRelationContext,\n\t\tancestorPath?: readonly Model.AnyRelationContext[],\n\t): Input.OptionalWhere {\n\t\tconst restrictedWhere = this.injectToWhere(where, entity, true, relationContext, ancestorPath ?? [], scope)\n\t\treturn this.createWhere(entity, restrictedWhere, relationContext, scope)\n\t}\n\n\t/**\n\t * Row-level read predicate guarding a relation hop's target (the nested scope, since the target\n\t * is reached through a relation). Empty when the target is freely readable, or when the hop is a to-one\n\t * back-reference to an ancestor row that is already verified readable. Shared by the filter injection\n\t * and the order-by join so both guard the same hop identically (they share the join alias).\n\t */\n\tpublic createReadGuard(relationContext: Model.AnyRelationContext, ancestorPath: readonly Model.AnyRelationContext[]): Input.OptionalWhere {\n\t\tif (this.canSimplifyBackReference(ancestorPath, relationContext)) {\n\t\t\treturn {}\n\t\t}\n\t\treturn this.predicateFactory.create(relationContext.targetEntity, Acl.Operation.read, 'nested', undefined, relationContext)\n\t}\n\n\t/**\n\t * A hop is a back-reference when it is the inverse of the hop that reached its source entity. Only the\n\t * immediate parent counts: an earlier ancestor of the same entity is generally a different row.\n\t */\n\tprivate canSimplifyBackReference(\n\t\tancestorPath: readonly Model.AnyRelationContext[],\n\t\trelationContext: Model.AnyRelationContext,\n\t): boolean {\n\t\tconst parent = ancestorPath[ancestorPath.length - 1]\n\t\tconst isBackReference = parent !== undefined\n\t\t\t&& parent.targetRelation?.name === relationContext.relation.name\n\t\t\t&& parent.targetEntity.name === relationContext.entity.name\n\t\treturn isBackReference && PredicatesInjector.toOneBackReferenceTypes.has(relationContext.type)\n\t}\n\n\t/**\n\t * ANDs the row-level read predicate of the injection root onto `where` — the only place the row predicate\n\t * lands in the WHERE; relation targets carry theirs in `READ_GUARD_KEY` instead.\n\t */\n\tprivate createWhere(\n\t\tentity: Model.Entity,\n\t\twhere: Input.OptionalWhere,\n\t\trelationContext: Model.AnyRelationContext | undefined,\n\t\tscope: AclScope,\n\t): Input.OptionalWhere {\n\t\tconst predicatesWhere = this.predicateFactory.create(entity, Acl.Operation.read, scope, undefined, relationContext)\n\n\t\tconst and = [where, predicatesWhere].filter(it => Object.keys(it).length > 0)\n\t\tif (and.length === 0) {\n\t\t\treturn {}\n\t\t}\n\t\tif (and.length === 1) {\n\t\t\treturn and[0]\n\t\t}\n\t\treturn { and: and }\n\t}\n\n\tprivate injectToWhere(\n\t\twhere: Input.OptionalWhere,\n\t\tentity: Model.Entity,\n\t\tisRoot: boolean,\n\t\trelationContext: Model.AnyRelationContext | undefined,\n\t\tancestorPath: readonly Model.AnyRelationContext[],\n\t\tscope: AclScope,\n\t): Input.OptionalWhere {\n\t\tconst resultWhere: Writable<Input.OptionalWhere> = {}\n\t\tif (where.and) {\n\t\t\tresultWhere.and = where.and.filter((it): it is Input.Where => !!it).map(it =>\n\t\t\t\tthis.injectToWhere(it, entity, isRoot, relationContext, ancestorPath, scope)\n\t\t\t)\n\t\t}\n\t\tif (where.or) {\n\t\t\tresultWhere.or = where.or.filter((it): it is Input.Where => !!it).map(it =>\n\t\t\t\tthis.injectToWhere(it, entity, isRoot, relationContext, ancestorPath, scope)\n\t\t\t)\n\t\t}\n\t\tif (where.not) {\n\t\t\tresultWhere.not = this.injectToWhere(where.not, entity, isRoot, relationContext, ancestorPath, scope)\n\t\t}\n\n\t\tconst fields = Object.keys(where).filter(it => !['and', 'or', 'not'].includes(it))\n\n\t\tif (fields.length === 0) {\n\t\t\treturn resultWhere\n\t\t}\n\t\t// Only cell-level fields (a read predicate stricter than the row-level one) need a guard of their own; the\n\t\t// row-level predicate is enforced once — in the WHERE of the injection root, or in the guarded source of a\n\t\t// relation hop. An empty column condition reads nothing, so a guard there would only filter by readability;\n\t\t// an empty relation condition can still test presence (`EXISTS`), so a relation keeps its guard.\n\t\tconst isCellLevel = (field: string) => this.predicateFactory.shouldApplyCellLevelPredicate(entity, Acl.Operation.read, field, scope)\n\t\tconst fieldGuard = (field: string) => this.predicateFactory.create(entity, Acl.Operation.read, scope, [field], relationContext)\n\t\tfor (let field of fields) {\n\t\t\tresultWhere[field] = acceptFieldVisitor(this.schema, entity, field, {\n\t\t\t\tvisitColumn: () => where[field],\n\t\t\t\tvisitRelation: context => {\n\t\t\t\t\tconst relationWhere = where[field] as Input.OptionalWhere | null\n\t\t\t\t\tif (relationWhere === null) {\n\t\t\t\t\t\treturn null\n\t\t\t\t\t}\n\t\t\t\t\tconst nestedAncestorPath: Model.AnyRelationContext[] = [...ancestorPath, context]\n\t\t\t\t\tconst nestedWhere = this.injectToWhere(relationWhere, context.targetEntity, false, context, nestedAncestorPath, 'nested')\n\t\t\t\t\tconst guard = this.createReadGuard(context, ancestorPath)\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...nestedWhere,\n\t\t\t\t\t\t...(Object.keys(guard).length > 0 ? { [READ_GUARD_KEY]: guard } : {}),\n\t\t\t\t\t\t...(isCellLevel(field) ? { [FIELD_GUARD_KEY]: fieldGuard(field) } : {}),\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t})\n\t\t}\n\t\tconst maskedColumns = fields.filter(it => isColumn(entity.fields[it]) && !this.isEmptyCondition(where[it]) && isCellLevel(it))\n\t\tif (maskedColumns.length === 0) {\n\t\t\treturn resultWhere\n\t\t}\n\t\tresultWhere[MASKED_CELL_KEY] = maskedColumns.map(field => ({ guard: fieldGuard(field), where: { [field]: resultWhere[field] } }))\n\t\tfor (const field of maskedColumns) {\n\t\t\tdelete resultWhere[field]\n\t\t}\n\t\treturn resultWhere\n\t}\n\n\tprivate isEmptyCondition(value: Input.OptionalWhere[string]): boolean {\n\t\treturn isWhere(value) && Object.keys(value).length === 0\n\t}\n}\n"],"names":["_PredicatesInjector","schema","Acl","acceptFieldVisitor","isColum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AAK,KAAK,EAAE,SAAS,IAAI,EAAE,CAAC,cAAc,GAAG,MAAA,IAAU,CAAA;AAAA,YAClE,GAAI,YAAY,KAAK,IAAI,EAAE,CAAC,eAAe,GAAG,WAAW,KAAK,MAAM,CAAA;AAAA,UAAC;AAAA,QAEvE;AAAA,MAAA,CACA;AAAA,IACF;AACA,UAAM,gBAAgB,OAAO,OAAO,QAAMC,YAAAA,SAAS,OAAO,OAAO,EAAE,CAAC,KAAK,CAAC,KAAK,iBAAiB,MAAM,EAAE,CAAC,KAAK,YAAY,EAAE,CAAC;AAC7H,QAAI,cAAc,WAAW,GAAG;AAC/B,aAAO;AAAA,IACR;AACA,gBAAY,eAAe,IAAI,cAAc,IAAI,CAAA,WAAU,EAAE,OAAO,WAAW,KAAK,GAAG,OAAO,EAAE,CAAC,KAAK,GAAG,YAAY,KAAK,EAAA,IAAM;AAChI,eAAW,SAAS,eAAe;AAClC,aAAO,YAAY,KAAK;AAAA,IACzB;AACA,WAAO;AAAA,EACR;AAAA,EAEQ,iBAAiB,OAA6C;AACrE,WAAO,QAAQ,KAAK,KAAK,OAAO,KAAK,KAAK,EAAE,WAAW;AAAA,EACxD;AACD;AA5IC,cARY,qBAQY,2BAA0B,oBAAI,IAAsC;AAAA,EAC3F;AAAA,EACA;AAAA,EACA;AACD,CAAC,CAAA;AAZK,IAAM,qBAAN;;;;;;;;;"}
@@ -1,35 +1,71 @@
1
1
  import { Acl } from "@contember/schema";
2
- import { acceptFieldVisitor } from "@contember/schema-utils";
3
- class PredicatesInjector {
2
+ import { acceptFieldVisitor, isColumn } from "@contember/schema-utils";
3
+ var __defProp = Object.defineProperty;
4
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
5
+ var __publicField = (obj, key, value) => __defNormalProp(obj, key + "", value);
6
+ const READ_GUARD_KEY = "$readGuard";
7
+ const FIELD_GUARD_KEY = "$fieldGuard";
8
+ const MASKED_CELL_KEY = "$maskedCell";
9
+ const isWhere = (value) => value !== null && value !== void 0 && typeof value === "object" && !Array.isArray(value);
10
+ const parseMaskedCells = (value) => {
11
+ if (!Array.isArray(value)) {
12
+ throw new Error(`${MASKED_CELL_KEY} expects a list of masked cells`);
13
+ }
14
+ return value.map((cell) => {
15
+ if (!isWhere(cell) || !isWhere(cell.guard) || !isWhere(cell.where)) {
16
+ throw new Error(`${MASKED_CELL_KEY} expects a guard and a where`);
17
+ }
18
+ return { guard: cell.guard, where: cell.where };
19
+ });
20
+ };
21
+ const splitFieldGuard = (where) => {
22
+ const { [FIELD_GUARD_KEY]: fieldGuard, ...rest } = where;
23
+ return { fieldGuard: isWhere(fieldGuard) ? fieldGuard : void 0, where: rest };
24
+ };
25
+ const splitReadGuard = (where) => {
26
+ const { [READ_GUARD_KEY]: guard, [FIELD_GUARD_KEY]: fieldGuard, ...rest } = where;
27
+ return { guard: isWhere(guard) ? guard : {}, fieldGuard: isWhere(fieldGuard) ? fieldGuard : {}, where: rest };
28
+ };
29
+ const _PredicatesInjector = class _PredicatesInjector2 {
4
30
  constructor(schema, predicateFactory) {
5
31
  this.schema = schema;
6
32
  this.predicateFactory = predicateFactory;
7
33
  }
8
- inject(entity, where, relationContext, ancestorPath) {
9
- const isQueryRoot = !relationContext && (!ancestorPath || ancestorPath.length === 0);
10
- const restrictedWhere = this.injectToWhere(where, entity, true, relationContext, false, ancestorPath ?? [], isQueryRoot);
11
- return this.createWhere(entity, void 0, restrictedWhere, relationContext, false, ancestorPath ?? [], isQueryRoot);
12
- }
13
34
  /**
14
- * Finds an ancestor in the path that matches the given relation as a back-reference.
15
- * A match occurs when:
16
- * 1. The relation we're traversing has the same name as the inverse (targetRelation) of a relation in the ancestor path
17
- * 2. AND the entity where our relation is defined matches the targetEntity in the path
18
- * (to prevent false positives when different entities have relations with the same name)
35
+ * `scope` is the scope of the entry entity. Relations traversed by `where` are always nested. A lookup
36
+ * without a relation context (a by-unique lookup of a mutation) states the scope of the row it looks for.
19
37
  */
20
- findBackReferencedAncestor(ancestorPath, relationName, relationSourceEntityName) {
21
- return ancestorPath.find(
22
- (ctx) => ctx.targetRelation?.name === relationName && ctx.targetEntity.name === relationSourceEntityName
23
- );
38
+ inject(entity, where, scope, relationContext, ancestorPath) {
39
+ const restrictedWhere = this.injectToWhere(where, entity, true, relationContext, ancestorPath ?? [], scope);
40
+ return this.createWhere(entity, restrictedWhere, relationContext, scope);
24
41
  }
25
- createWhere(entity, fieldNames, where, relationContext, isBackReferenceContext, ancestorPath, isQueryRoot) {
26
- const shouldSimplify = isBackReferenceContext === true && ancestorPath !== void 0 && relationContext !== void 0 && this.findBackReferencedAncestor(ancestorPath, relationContext.relation.name, relationContext.entity.name) !== void 0;
27
- let predicatesWhere;
28
- if (shouldSimplify) {
29
- predicatesWhere = { [entity.primary]: { always: true } };
30
- } else {
31
- predicatesWhere = this.predicateFactory.create(entity, Acl.Operation.read, fieldNames, relationContext, isQueryRoot);
42
+ /**
43
+ * Row-level read predicate guarding a relation hop's target (the nested scope, since the target
44
+ * is reached through a relation). Empty when the target is freely readable, or when the hop is a to-one
45
+ * back-reference to an ancestor row that is already verified readable. Shared by the filter injection
46
+ * and the order-by join so both guard the same hop identically (they share the join alias).
47
+ */
48
+ createReadGuard(relationContext, ancestorPath) {
49
+ if (this.canSimplifyBackReference(ancestorPath, relationContext)) {
50
+ return {};
32
51
  }
52
+ return this.predicateFactory.create(relationContext.targetEntity, Acl.Operation.read, "nested", void 0, relationContext);
53
+ }
54
+ /**
55
+ * A hop is a back-reference when it is the inverse of the hop that reached its source entity. Only the
56
+ * immediate parent counts: an earlier ancestor of the same entity is generally a different row.
57
+ */
58
+ canSimplifyBackReference(ancestorPath, relationContext) {
59
+ const parent = ancestorPath[ancestorPath.length - 1];
60
+ const isBackReference = parent !== void 0 && parent.targetRelation?.name === relationContext.relation.name && parent.targetEntity.name === relationContext.entity.name;
61
+ return isBackReference && _PredicatesInjector2.toOneBackReferenceTypes.has(relationContext.type);
62
+ }
63
+ /**
64
+ * ANDs the row-level read predicate of the injection root onto `where` — the only place the row predicate
65
+ * lands in the WHERE; relation targets carry theirs in `READ_GUARD_KEY` instead.
66
+ */
67
+ createWhere(entity, where, relationContext, scope) {
68
+ const predicatesWhere = this.predicateFactory.create(entity, Acl.Operation.read, scope, void 0, relationContext);
33
69
  const and = [where, predicatesWhere].filter((it) => Object.keys(it).length > 0);
34
70
  if (and.length === 0) {
35
71
  return {};
@@ -39,25 +75,27 @@ class PredicatesInjector {
39
75
  }
40
76
  return { and };
41
77
  }
42
- injectToWhere(where, entity, isRoot, relationContext, isBackReferenceContext, ancestorPath, isQueryRoot) {
78
+ injectToWhere(where, entity, isRoot, relationContext, ancestorPath, scope) {
43
79
  const resultWhere = {};
44
80
  if (where.and) {
45
81
  resultWhere.and = where.and.filter((it) => !!it).map(
46
- (it) => this.injectToWhere(it, entity, isRoot, relationContext, isBackReferenceContext, ancestorPath, isQueryRoot)
82
+ (it) => this.injectToWhere(it, entity, isRoot, relationContext, ancestorPath, scope)
47
83
  );
48
84
  }
49
85
  if (where.or) {
50
86
  resultWhere.or = where.or.filter((it) => !!it).map(
51
- (it) => this.injectToWhere(it, entity, isRoot, relationContext, isBackReferenceContext, ancestorPath, isQueryRoot)
87
+ (it) => this.injectToWhere(it, entity, isRoot, relationContext, ancestorPath, scope)
52
88
  );
53
89
  }
54
90
  if (where.not) {
55
- resultWhere.not = this.injectToWhere(where.not, entity, isRoot, relationContext, isBackReferenceContext, ancestorPath, isQueryRoot);
91
+ resultWhere.not = this.injectToWhere(where.not, entity, isRoot, relationContext, ancestorPath, scope);
56
92
  }
57
93
  const fields = Object.keys(where).filter((it) => !["and", "or", "not"].includes(it));
58
94
  if (fields.length === 0) {
59
95
  return resultWhere;
60
96
  }
97
+ const isCellLevel = (field) => this.predicateFactory.shouldApplyCellLevelPredicate(entity, Acl.Operation.read, field, scope);
98
+ const fieldGuard = (field) => this.predicateFactory.create(entity, Acl.Operation.read, scope, [field], relationContext);
61
99
  for (let field of fields) {
62
100
  resultWhere[field] = acceptFieldVisitor(this.schema, entity, field, {
63
101
  visitColumn: () => where[field],
@@ -66,18 +104,45 @@ class PredicatesInjector {
66
104
  if (relationWhere === null) {
67
105
  return null;
68
106
  }
69
- const isBackReference = this.findBackReferencedAncestor(ancestorPath, context.relation.name, context.entity.name) !== void 0;
70
- const nestedIsBackReferenceContext = isBackReference || isBackReferenceContext;
71
107
  const nestedAncestorPath = [...ancestorPath, context];
72
- return this.injectToWhere(relationWhere, context.targetEntity, false, context, nestedIsBackReferenceContext, nestedAncestorPath, isQueryRoot);
108
+ const nestedWhere = this.injectToWhere(relationWhere, context.targetEntity, false, context, nestedAncestorPath, "nested");
109
+ const guard = this.createReadGuard(context, ancestorPath);
110
+ return {
111
+ ...nestedWhere,
112
+ ...Object.keys(guard).length > 0 ? { [READ_GUARD_KEY]: guard } : {},
113
+ ...isCellLevel(field) ? { [FIELD_GUARD_KEY]: fieldGuard(field) } : {}
114
+ };
73
115
  }
74
116
  });
75
117
  }
76
- const fieldsForPredicate = !isRoot ? fields : fields.filter((it) => this.predicateFactory.shouldApplyCellLevelPredicate(entity, Acl.Operation.read, it, isQueryRoot));
77
- return this.createWhere(entity, fieldsForPredicate, resultWhere, relationContext, isBackReferenceContext, ancestorPath, isQueryRoot);
118
+ const maskedColumns = fields.filter((it) => isColumn(entity.fields[it]) && !this.isEmptyCondition(where[it]) && isCellLevel(it));
119
+ if (maskedColumns.length === 0) {
120
+ return resultWhere;
121
+ }
122
+ resultWhere[MASKED_CELL_KEY] = maskedColumns.map((field) => ({ guard: fieldGuard(field), where: { [field]: resultWhere[field] } }));
123
+ for (const field of maskedColumns) {
124
+ delete resultWhere[field];
125
+ }
126
+ return resultWhere;
78
127
  }
79
- }
128
+ isEmptyCondition(value) {
129
+ return isWhere(value) && Object.keys(value).length === 0;
130
+ }
131
+ };
132
+ __publicField(_PredicatesInjector, "toOneBackReferenceTypes", /* @__PURE__ */ new Set([
133
+ "manyHasOne",
134
+ "oneHasOneOwning",
135
+ "oneHasOneInverse"
136
+ ]));
137
+ let PredicatesInjector = _PredicatesInjector;
80
138
  export {
81
- PredicatesInjector
139
+ FIELD_GUARD_KEY,
140
+ MASKED_CELL_KEY,
141
+ PredicatesInjector,
142
+ READ_GUARD_KEY,
143
+ isWhere,
144
+ parseMaskedCells,
145
+ splitFieldGuard,
146
+ splitReadGuard
82
147
  };
83
148
  //# sourceMappingURL=PredicatesInjector.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PredicatesInjector.js","sources":["../../../../../packages/engine-content-api/src/acl/PredicatesInjector.ts"],"sourcesContent":["import { Acl, Input, Model, Writable } from '@contember/schema'\nimport { acceptFieldVisitor } from '@contember/schema-utils'\nimport { PredicateFactory } from './PredicateFactory.js'\n\nexport class PredicatesInjector {\n\tconstructor(private readonly schema: Model.Schema, private readonly predicateFactory: PredicateFactory) {}\n\n\tpublic inject(\n\t\tentity: Model.Entity,\n\t\twhere: Input.OptionalWhere,\n\t\trelationContext?: Model.AnyRelationContext,\n\t\tancestorPath?: readonly Model.AnyRelationContext[],\n\t): Input.OptionalWhere {\n\t\tconst isQueryRoot = !relationContext && (!ancestorPath || ancestorPath.length === 0)\n\t\tconst restrictedWhere = this.injectToWhere(where, entity, true, relationContext, false, ancestorPath ?? [], isQueryRoot)\n\t\treturn this.createWhere(entity, undefined, restrictedWhere, relationContext, false, ancestorPath ?? [], isQueryRoot)\n\t}\n\n\t/**\n\t * Finds an ancestor in the path that matches the given relation as a back-reference.\n\t * A match occurs when:\n\t * 1. The relation we're traversing has the same name as the inverse (targetRelation) of a relation in the ancestor path\n\t * 2. AND the entity where our relation is defined matches the targetEntity in the path\n\t * (to prevent false positives when different entities have relations with the same name)\n\t */\n\tprivate findBackReferencedAncestor(\n\t\tancestorPath: readonly Model.AnyRelationContext[],\n\t\trelationName: string,\n\t\trelationSourceEntityName: string,\n\t): Model.AnyRelationContext | undefined {\n\t\treturn ancestorPath.find(ctx =>\n\t\t\tctx.targetRelation?.name === relationName\n\t\t\t&& ctx.targetEntity.name === relationSourceEntityName\n\t\t)\n\t}\n\n\tprivate createWhere(\n\t\tentity: Model.Entity,\n\t\tfieldNames: string[] | undefined,\n\t\twhere: Input.OptionalWhere,\n\t\trelationContext?: Model.AnyRelationContext,\n\t\tisBackReferenceContext?: boolean,\n\t\tancestorPath?: readonly Model.AnyRelationContext[],\n\t\tisQueryRoot?: boolean,\n\t): Input.OptionalWhere {\n\t\t// Simplify predicates when:\n\t\t// 1. We're in a back-reference context (inside a filter that traverses back)\n\t\t// 2. AND the relation we traversed to get here corresponds to a relation in our query path\n\t\t// This ensures we only simplify when the traversed relation actually corresponds\n\t\t// to a relation in our query path (not just any relation to the same entity type)\n\t\tconst shouldSimplify = isBackReferenceContext === true\n\t\t\t&& ancestorPath !== undefined\n\t\t\t&& relationContext !== undefined\n\t\t\t&& this.findBackReferencedAncestor(ancestorPath, relationContext.relation.name, relationContext.entity.name) !== undefined\n\n\t\tlet predicatesWhere: Input.OptionalWhere\n\t\tif (shouldSimplify) {\n\t\t\tpredicatesWhere = { [entity.primary]: { always: true } }\n\t\t} else {\n\t\t\tpredicatesWhere = this.predicateFactory.create(entity, Acl.Operation.read, fieldNames, relationContext, isQueryRoot)\n\t\t}\n\n\t\tconst and = [where, predicatesWhere].filter(it => Object.keys(it).length > 0)\n\t\tif (and.length === 0) {\n\t\t\treturn {}\n\t\t}\n\t\tif (and.length === 1) {\n\t\t\treturn and[0]\n\t\t}\n\t\treturn { and: and }\n\t}\n\n\tprivate injectToWhere(\n\t\twhere: Input.OptionalWhere,\n\t\tentity: Model.Entity,\n\t\tisRoot: boolean,\n\t\trelationContext: Model.AnyRelationContext | undefined,\n\t\tisBackReferenceContext: boolean,\n\t\tancestorPath: readonly Model.AnyRelationContext[],\n\t\tisQueryRoot?: boolean,\n\t): Input.OptionalWhere {\n\t\tconst resultWhere: Writable<Input.OptionalWhere> = {}\n\t\tif (where.and) {\n\t\t\tresultWhere.and = where.and.filter((it): it is Input.Where => !!it).map(it =>\n\t\t\t\tthis.injectToWhere(it, entity, isRoot, relationContext, isBackReferenceContext, ancestorPath, isQueryRoot)\n\t\t\t)\n\t\t}\n\t\tif (where.or) {\n\t\t\tresultWhere.or = where.or.filter((it): it is Input.Where => !!it).map(it =>\n\t\t\t\tthis.injectToWhere(it, entity, isRoot, relationContext, isBackReferenceContext, ancestorPath, isQueryRoot)\n\t\t\t)\n\t\t}\n\t\tif (where.not) {\n\t\t\tresultWhere.not = this.injectToWhere(where.not, entity, isRoot, relationContext, isBackReferenceContext, ancestorPath, isQueryRoot)\n\t\t}\n\n\t\tconst fields = Object.keys(where).filter(it => !['and', 'or', 'not'].includes(it))\n\n\t\tif (fields.length === 0) {\n\t\t\treturn resultWhere\n\t\t}\n\t\tfor (let field of fields) {\n\t\t\tresultWhere[field] = acceptFieldVisitor(this.schema, entity, field, {\n\t\t\t\tvisitColumn: () => where[field],\n\t\t\t\tvisitRelation: context => {\n\t\t\t\t\tconst relationWhere = where[field] as Input.OptionalWhere | null\n\t\t\t\t\tif (relationWhere === null) {\n\t\t\t\t\t\treturn null\n\t\t\t\t\t}\n\t\t\t\t\t// Check if this relation is a back-reference to somewhere in our ancestor path\n\t\t\t\t\tconst isBackReference = this.findBackReferencedAncestor(ancestorPath, context.relation.name, context.entity.name) !== undefined\n\t\t\t\t\t// Once we enter a back-reference context, stay in it for nested relations\n\t\t\t\t\tconst nestedIsBackReferenceContext = isBackReference || isBackReferenceContext\n\t\t\t\t\t// Build extended ancestor path for nested traversal\n\t\t\t\t\tconst nestedAncestorPath: Model.AnyRelationContext[] = [...ancestorPath, context]\n\t\t\t\t\treturn this.injectToWhere(relationWhere, context.targetEntity, false, context, nestedIsBackReferenceContext, nestedAncestorPath, isQueryRoot)\n\t\t\t\t},\n\t\t\t})\n\t\t}\n\t\tconst fieldsForPredicate = !isRoot\n\t\t\t? fields\n\t\t\t: fields.filter(it => this.predicateFactory.shouldApplyCellLevelPredicate(entity, Acl.Operation.read, it, isQueryRoot))\n\n\t\treturn this.createWhere(entity, fieldsForPredicate, resultWhere, relationContext, isBackReferenceContext, ancestorPath, isQueryRoot)\n\t}\n}\n"],"names":[],"mappings":";;AAIO,MAAM,mBAAmB;AAAA,EAC/B,YAA6B,QAAuC,kBAAoC;AAA3E,SAAA,SAAA;AAAuC,SAAA,mBAAA;AAAA,EAAqC;AAAA,EAElG,OACN,QACA,OACA,iBACA,cACsB;AACtB,UAAM,cAAc,CAAC,oBAAoB,CAAC,gBAAgB,aAAa,WAAW;AAClF,UAAM,kBAAkB,KAAK,cAAc,OAAO,QAAQ,MAAM,iBAAiB,OAAO,gBAAgB,CAAA,GAAI,WAAW;AACvH,WAAO,KAAK,YAAY,QAAQ,QAAW,iBAAiB,iBAAiB,OAAO,gBAAgB,CAAA,GAAI,WAAW;AAAA,EACpH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASQ,2BACP,cACA,cACA,0BACuC;AACvC,WAAO,aAAa;AAAA,MAAK,SACxB,IAAI,gBAAgB,SAAS,gBAC1B,IAAI,aAAa,SAAS;AAAA,IAAA;AAAA,EAE/B;AAAA,EAEQ,YACP,QACA,YACA,OACA,iBACA,wBACA,cACA,aACsB;AAMtB,UAAM,iBAAiB,2BAA2B,QAC9C,iBAAiB,UACjB,oBAAoB,UACpB,KAAK,2BAA2B,cAAc,gBAAgB,SAAS,MAAM,gBAAgB,OAAO,IAAI,MAAM;AAElH,QAAI;AACJ,QAAI,gBAAgB;AACnB,wBAAkB,EAAE,CAAC,OAAO,OAAO,GAAG,EAAE,QAAQ,OAAK;AAAA,IACtD,OAAO;AACN,wBAAkB,KAAK,iBAAiB,OAAO,QAAQ,IAAI,UAAU,MAAM,YAAY,iBAAiB,WAAW;AAAA,IACpH;AAEA,UAAM,MAAM,CAAC,OAAO,eAAe,EAAE,OAAO,CAAA,OAAM,OAAO,KAAK,EAAE,EAAE,SAAS,CAAC;AAC5E,QAAI,IAAI,WAAW,GAAG;AACrB,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tH,gBAAM,+BAA+B,mBAAmB;AAExD,gBAAM,qBAAiD,CAAC,GAAG,cAAc,OAAO;AAChF,iBAAO,KAAK,cAAc,eAAe,QAAQ,cAAc,OAAO,SAAS,8BAA8B,oBAAoB,WAAW;AAAA,QAC7I;AAAA,MAAA,CACA;AAAA,IACF;AACA,UAAM,qBAAqB,CAAC,SACzB,SACA,OAAO,OAAO,CAAA,OAAM,KAAK,iBAAiB,8BAA8B,QAAQ,IAAI,UAAU,MAAM,IAAI,WAAW,CAAC;AAEvH,WAAO,KAAK,YAAY,QAAQ,oBAAoB,aAAa,iBAAiB,wBAAwB,cAAc,WAAW;AAAA,EACpI;AACD;"}
1
+ {"version":3,"file":"PredicatesInjector.js","sources":["../../../../../packages/engine-content-api/src/acl/PredicatesInjector.ts"],"sourcesContent":["import { Acl, Input, Model, Writable } from '@contember/schema'\nimport { acceptFieldVisitor, isColumn } from '@contember/schema-utils'\nimport { PredicateFactory } from './PredicateFactory.js'\nimport { AclScope } from './AclScope.js'\n\n/**\n * Internal where key carrying the row-level read predicate of a relation target. The injector attaches it\n * to every user-authored relation hop; the WhereBuilder compiles it into the hop's table source (a guarded\n * join / subquery), so an unreadable related row null-extends exactly like an absent one under any boolean\n * shape. `$` cannot appear in a GraphQL name, so the key can never arrive from user input.\n */\nexport const READ_GUARD_KEY = '$readGuard'\n\n/**\n * Internal where key on a relation hop carrying the read predicate of the relation FIELD when it is stricter than\n * the source row's (a cell-level relation). It is a where over the SOURCE entity. The WhereBuilder makes the hop\n * read empty where the predicate does not hold, so a masked relation behaves exactly like an empty one.\n */\nexport const FIELD_GUARD_KEY = '$fieldGuard'\n\n/**\n * Internal where key carrying, for each cell-level column of a where level, its condition (`where`, a single-field\n * where) together with the column's read predicate (`guard`). The WhereBuilder compiles each so that a masked cell\n * behaves exactly like a NULL value: the condition holds on a masked cell iff it holds on NULL. The cells sit next\n * to the other keys of the level, so the level keeps the shape the user wrote.\n */\nexport const MASKED_CELL_KEY = '$maskedCell'\n\nexport const isWhere = (value: Input.OptionalWhere[string]): value is Input.OptionalWhere =>\n\tvalue !== null && value !== undefined && typeof value === 'object' && !Array.isArray(value)\n\nexport type MaskedCell = { guard: Input.OptionalWhere; where: Input.OptionalWhere }\n\nexport const parseMaskedCells = (value: Input.OptionalWhere[string]): MaskedCell[] => {\n\tif (!Array.isArray(value)) {\n\t\tthrow new Error(`${MASKED_CELL_KEY} expects a list of masked cells`)\n\t}\n\treturn value.map(cell => {\n\t\tif (!isWhere(cell) || !isWhere(cell.guard) || !isWhere(cell.where)) {\n\t\t\tthrow new Error(`${MASKED_CELL_KEY} expects a guard and a where`)\n\t\t}\n\t\treturn { guard: cell.guard, where: cell.where }\n\t})\n}\n\n/** Separates the field guard of a relation hop; undefined when the relation field is not cell-level. */\nexport const splitFieldGuard = (where: Input.OptionalWhere): { fieldGuard: Input.OptionalWhere | undefined; where: Input.OptionalWhere } => {\n\tconst { [FIELD_GUARD_KEY]: fieldGuard, ...rest } = where\n\treturn { fieldGuard: isWhere(fieldGuard) ? fieldGuard : undefined, where: rest }\n}\n\nexport type HopGuards = { guard: Input.OptionalWhere; fieldGuard: Input.OptionalWhere; where: Input.OptionalWhere }\n\n/** Separates the hop's read guards from the user-authored remainder; a guard is empty when absent. */\nexport const splitReadGuard = (where: Input.OptionalWhere): HopGuards => {\n\tconst { [READ_GUARD_KEY]: guard, [FIELD_GUARD_KEY]: fieldGuard, ...rest } = where\n\treturn { guard: isWhere(guard) ? guard : {}, fieldGuard: isWhere(fieldGuard) ? fieldGuard : {}, where: rest }\n}\n\nexport class PredicatesInjector {\n\t/**\n\t * Back-reference simplification is only sound for to-one back-hops. A to-one round-trip\n\t * re-reaches the exact ancestor row (already verified readable), so its predicate can be dropped.\n\t * A to-many back-hop reaches the ancestor's SIBLINGS, which are NOT guaranteed readable — dropping\n\t * their row predicate would leak a value/presence oracle over unreadable rows. Fail-closed: only the\n\t * types listed here simplify; anything else keeps the full predicate.\n\t */\n\tprivate static readonly toOneBackReferenceTypes = new Set<Model.AnyRelationContext['type']>([\n\t\t'manyHasOne',\n\t\t'oneHasOneOwning',\n\t\t'oneHasOneInverse',\n\t])\n\n\tconstructor(private readonly schema: Model.Schema, private readonly predicateFactory: PredicateFactory) {}\n\n\t/**\n\t * `scope` is the scope of the entry entity. Relations traversed by `where` are always nested. A lookup\n\t * without a relation context (a by-unique lookup of a mutation) states the scope of the row it looks for.\n\t */\n\tpublic inject(\n\t\tentity: Model.Entity,\n\t\twhere: Input.OptionalWhere,\n\t\tscope: AclScope,\n\t\trelationContext?: Model.AnyRelationContext,\n\t\tancestorPath?: readonly Model.AnyRelationContext[],\n\t): Input.OptionalWhere {\n\t\tconst restrictedWhere = this.injectToWhere(where, entity, true, relationContext, ancestorPath ?? [], scope)\n\t\treturn this.createWhere(entity, restrictedWhere, relationContext, scope)\n\t}\n\n\t/**\n\t * Row-level read predicate guarding a relation hop's target (the nested scope, since the target\n\t * is reached through a relation). Empty when the target is freely readable, or when the hop is a to-one\n\t * back-reference to an ancestor row that is already verified readable. Shared by the filter injection\n\t * and the order-by join so both guard the same hop identically (they share the join alias).\n\t */\n\tpublic createReadGuard(relationContext: Model.AnyRelationContext, ancestorPath: readonly Model.AnyRelationContext[]): Input.OptionalWhere {\n\t\tif (this.canSimplifyBackReference(ancestorPath, relationContext)) {\n\t\t\treturn {}\n\t\t}\n\t\treturn this.predicateFactory.create(relationContext.targetEntity, Acl.Operation.read, 'nested', undefined, relationContext)\n\t}\n\n\t/**\n\t * A hop is a back-reference when it is the inverse of the hop that reached its source entity. Only the\n\t * immediate parent counts: an earlier ancestor of the same entity is generally a different row.\n\t */\n\tprivate canSimplifyBackReference(\n\t\tancestorPath: readonly Model.AnyRelationContext[],\n\t\trelationContext: Model.AnyRelationContext,\n\t): boolean {\n\t\tconst parent = ancestorPath[ancestorPath.length - 1]\n\t\tconst isBackReference = parent !== undefined\n\t\t\t&& parent.targetRelation?.name === relationContext.relation.name\n\t\t\t&& parent.targetEntity.name === relationContext.entity.name\n\t\treturn isBackReference && PredicatesInjector.toOneBackReferenceTypes.has(relationContext.type)\n\t}\n\n\t/**\n\t * ANDs the row-level read predicate of the injection root onto `where` — the only place the row predicate\n\t * lands in the WHERE; relation targets carry theirs in `READ_GUARD_KEY` instead.\n\t */\n\tprivate createWhere(\n\t\tentity: Model.Entity,\n\t\twhere: Input.OptionalWhere,\n\t\trelationContext: Model.AnyRelationContext | undefined,\n\t\tscope: AclScope,\n\t): Input.OptionalWhere {\n\t\tconst predicatesWhere = this.predicateFactory.create(entity, Acl.Operation.read, scope, undefined, relationContext)\n\n\t\tconst and = [where, predicatesWhere].filter(it => Object.keys(it).length > 0)\n\t\tif (and.length === 0) {\n\t\t\treturn {}\n\t\t}\n\t\tif (and.length === 1) {\n\t\t\treturn and[0]\n\t\t}\n\t\treturn { and: and }\n\t}\n\n\tprivate injectToWhere(\n\t\twhere: Input.OptionalWhere,\n\t\tentity: Model.Entity,\n\t\tisRoot: boolean,\n\t\trelationContext: Model.AnyRelationContext | undefined,\n\t\tancestorPath: readonly Model.AnyRelationContext[],\n\t\tscope: AclScope,\n\t): Input.OptionalWhere {\n\t\tconst resultWhere: Writable<Input.OptionalWhere> = {}\n\t\tif (where.and) {\n\t\t\tresultWhere.and = where.and.filter((it): it is Input.Where => !!it).map(it =>\n\t\t\t\tthis.injectToWhere(it, entity, isRoot, relationContext, ancestorPath, scope)\n\t\t\t)\n\t\t}\n\t\tif (where.or) {\n\t\t\tresultWhere.or = where.or.filter((it): it is Input.Where => !!it).map(it =>\n\t\t\t\tthis.injectToWhere(it, entity, isRoot, relationContext, ancestorPath, scope)\n\t\t\t)\n\t\t}\n\t\tif (where.not) {\n\t\t\tresultWhere.not = this.injectToWhere(where.not, entity, isRoot, relationContext, ancestorPath, scope)\n\t\t}\n\n\t\tconst fields = Object.keys(where).filter(it => !['and', 'or', 'not'].includes(it))\n\n\t\tif (fields.length === 0) {\n\t\t\treturn resultWhere\n\t\t}\n\t\t// Only cell-level fields (a read predicate stricter than the row-level one) need a guard of their own; the\n\t\t// row-level predicate is enforced once — in the WHERE of the injection root, or in the guarded source of a\n\t\t// relation hop. An empty column condition reads nothing, so a guard there would only filter by readability;\n\t\t// an empty relation condition can still test presence (`EXISTS`), so a relation keeps its guard.\n\t\tconst isCellLevel = (field: string) => this.predicateFactory.shouldApplyCellLevelPredicate(entity, Acl.Operation.read, field, scope)\n\t\tconst fieldGuard = (field: string) => this.predicateFactory.create(entity, Acl.Operation.read, scope, [field], relationContext)\n\t\tfor (let field of fields) {\n\t\t\tresultWhere[field] = acceptFieldVisitor(this.schema, entity, field, {\n\t\t\t\tvisitColumn: () => where[field],\n\t\t\t\tvisitRelation: context => {\n\t\t\t\t\tconst relationWhere = where[field] as Input.OptionalWhere | null\n\t\t\t\t\tif (relationWhere === null) {\n\t\t\t\t\t\treturn null\n\t\t\t\t\t}\n\t\t\t\t\tconst nestedAncestorPath: Model.AnyRelationContext[] = [...ancestorPath, context]\n\t\t\t\t\tconst nestedWhere = this.injectToWhere(relationWhere, context.targetEntity, false, context, nestedAncestorPath, 'nested')\n\t\t\t\t\tconst guard = this.createReadGuard(context, ancestorPath)\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...nestedWhere,\n\t\t\t\t\t\t...(Object.keys(guard).length > 0 ? { [READ_GUARD_KEY]: guard } : {}),\n\t\t\t\t\t\t...(isCellLevel(field) ? { [FIELD_GUARD_KEY]: fieldGuard(field) } : {}),\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t})\n\t\t}\n\t\tconst maskedColumns = fields.filter(it => isColumn(entity.fields[it]) && !this.isEmptyCondition(where[it]) && isCellLevel(it))\n\t\tif (maskedColumns.length === 0) {\n\t\t\treturn resultWhere\n\t\t}\n\t\tresultWhere[MASKED_CELL_KEY] = maskedColumns.map(field => ({ guard: fieldGuard(field), where: { [field]: resultWhere[field] } }))\n\t\tfor (const field of maskedColumns) {\n\t\t\tdelete resultWhere[field]\n\t\t}\n\t\treturn resultWhere\n\t}\n\n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gBAAgB,SAAS,YAAY;AACxD,iBAAO;AAAA,YACN,GAAG;AAAA,YACH,GAAI,OAAO,KAAK,KAAK,EAAE,SAAS,IAAI,EAAE,CAAC,cAAc,GAAG,MAAA,IAAU,CAAA;AAAA,YAClE,GAAI,YAAY,KAAK,IAAI,EAAE,CAAC,eAAe,GAAG,WAAW,KAAK,MAAM,CAAA;AAAA,UAAC;AAAA,QAEvE;AAAA,MAAA,CACA;AAAA,IACF;AACA,UAAM,gBAAgB,OAAO,OAAO,QAAM,SAAS,OAAO,OAAO,EAAE,CAAC,KAAK,CAAC,KAAK,iBAAiB,MAAM,EAAE,CAAC,KAAK,YAAY,EAAE,CAAC;AAC7H,QAAI,cAAc,WAAW,GAAG;AAC/B,aAAO;AAAA,IACR;AACA,gBAAY,eAAe,IAAI,cAAc,IAAI,CAAA,WAAU,EAAE,OAAO,WAAW,KAAK,GAAG,OAAO,EAAE,CAAC,KAAK,GAAG,YAAY,KAAK,EAAA,IAAM;AAChI,eAAW,SAAS,eAAe;AAClC,aAAO,YAAY,KAAK;AAAA,IACzB;AACA,WAAO;AAAA,EACR;AAAA,EAEQ,iBAAiB,OAA6C;AACrE,WAAO,QAAQ,KAAK,KAAK,OAAO,KAAK,KAAK,EAAE,WAAW;AAAA,EACxD;AACD;AA5IC,cARY,qBAQY,2BAA0B,oBAAI,IAAsC;AAAA,EAC3F;AAAA,EACA;AAAA,EACA;AACD,CAAC,CAAA;AAZK,IAAM,qBAAN;"}
@@ -11,7 +11,8 @@ class VariableInjector {
11
11
  __publicField(this, "injectorCache", /* @__PURE__ */ new WeakMap());
12
12
  }
13
13
  inject(entity, where) {
14
- const cacheEntry = this.injectorCache.get(where);
14
+ const entityCache = this.injectorCache.get(where);
15
+ const cacheEntry = entityCache?.get(entity.name);
15
16
  if (cacheEntry !== void 0) {
16
17
  return cacheEntry;
17
18
  }
@@ -30,7 +31,11 @@ class VariableInjector {
30
31
  return value;
31
32
  }
32
33
  });
33
- this.injectorCache.set(where, resultWhere);
34
+ if (entityCache) {
35
+ entityCache.set(entity.name, resultWhere);
36
+ } else {
37
+ this.injectorCache.set(where, /* @__PURE__ */ new Map([[entity.name, resultWhere]]));
38
+ }
34
39
  return resultWhere;
35
40
  }
36
41
  }
@@ -1 +1 @@
1
- {"version":3,"file":"VariableInjector.cjs","sources":["../../../../../packages/engine-content-api/src/acl/VariableInjector.ts"],"sourcesContent":["import { Acl, Input, Model } from '@contember/schema'\nimport { PredicateDefinitionProcessor } from '@contember/schema-utils'\n\nexport class VariableInjector {\n\tprivate injectorCache = new WeakMap<Acl.PredicateDefinition, Input.Where>()\n\n\tconstructor(private readonly schema: Model.Schema, private readonly variables: Acl.VariablesMap) {}\n\n\tpublic inject(entity: Model.Entity, where: Acl.PredicateDefinition): Input.Where {\n\t\tconst cacheEntry = this.injectorCache.get(where)\n\t\tif (cacheEntry !== undefined) {\n\t\t\treturn cacheEntry\n\t\t}\n\t\tconst predicateDefinitionProcessor = new PredicateDefinitionProcessor(this.schema)\n\n\t\tconst resultWhere = predicateDefinitionProcessor.process(entity, where, {\n\t\t\thandleColumn: ({ value }) => {\n\t\t\t\tif (typeof value === 'string') {\n\t\t\t\t\treturn this.variables[value] ?? { never: true }\n\t\t\t\t}\n\t\t\t\treturn value as Input.Condition\n\t\t\t},\n\t\t\thandleRelation: ({ value, targetEntity }) => {\n\t\t\t\tif (typeof value === 'string') {\n\t\t\t\t\treturn { [targetEntity.primary]: this.variables[value] ?? { never: true } }\n\t\t\t\t}\n\t\t\t\treturn value\n\t\t\t},\n\t\t})\n\t\tthis.injectorCache.set(where, resultWhere)\n\t\treturn resultWhere\n\t}\n}\n"],"names":["PredicateDefinitionProcessor"],"mappings":";;;;;;AAGO,MAAM,iBAAiB;AAAA,EAG7B,YAA6B,QAAuC,WAA6B;AAApE,SAAA,SAAA;AAAuC,SAAA,YAAA;AAFpE,kBAAA,MAAQ,qCAAoB,QAAA,CAA8C;AAAA,EAEwB;AAAA,EAE3F,OAAO,QAAsB,OAA6C;AAChF,UAAM,aAAa,KAAK,cAAc,IAAI,KAAK;AAC/C,QAAI,eAAe,QAAW;AAC7B,aAAO;AAAA,IACR;AACA,UAAM,+BAA+B,IAAIA,yCAA6B,KAAK,MAAM;AAEjF,UAAM,cAAc,6BAA6B,QAAQ,QAAQ,OAAO;AAAA,MACvE,cAAc,CAAC,EAAE,YAAY;AAC5B,YAAI,OAAO,UAAU,UAAU;AAC9B,iBAAO,KAAK,UAAU,KAAK,KAAK,EAAE,OAAO,KAAA;AAAA,QAC1C;AACA,eAAO;AAAA,MACR;AAAA,MACA,gBAAgB,CAAC,EAAE,OAAO,mBAAmB;AAC5C,YAAI,OAAO,UAAU,UAAU;AAC9B,iBAAO,EAAE,CAAC,aAAa,OAAO,GAAG,KAAK,UAAU,KAAK,KAAK,EAAE,OAAO,OAAK;AAAA,QACzE;AACA,eAAO;AAAA,MACR;AAAA,IAAA,CACA;AACD,SAAK,cAAc,IAAI,OAAO,WAAW;AACzC,WAAO;AAAA,EACR;AACD;;"}
1
+ {"version":3,"file":"VariableInjector.cjs","sources":["../../../../../packages/engine-content-api/src/acl/VariableInjector.ts"],"sourcesContent":["import { Acl, Input, Model } from '@contember/schema'\nimport { PredicateDefinitionProcessor } from '@contember/schema-utils'\n\nexport class VariableInjector {\n\tprivate injectorCache = new WeakMap<Acl.PredicateDefinition, Map<string, Input.Where>>()\n\n\tconstructor(private readonly schema: Model.Schema, private readonly variables: Acl.VariablesMap) {}\n\n\tpublic inject(entity: Model.Entity, where: Acl.PredicateDefinition): Input.Where {\n\t\tconst entityCache = this.injectorCache.get(where)\n\t\tconst cacheEntry = entityCache?.get(entity.name)\n\t\tif (cacheEntry !== undefined) {\n\t\t\treturn cacheEntry\n\t\t}\n\t\tconst predicateDefinitionProcessor = new PredicateDefinitionProcessor(this.schema)\n\n\t\tconst resultWhere = predicateDefinitionProcessor.process(entity, where, {\n\t\t\thandleColumn: ({ value }) => {\n\t\t\t\tif (typeof value === 'string') {\n\t\t\t\t\treturn this.variables[value] ?? { never: true }\n\t\t\t\t}\n\t\t\t\treturn value as Input.Condition\n\t\t\t},\n\t\t\thandleRelation: ({ value, targetEntity }) => {\n\t\t\t\tif (typeof value === 'string') {\n\t\t\t\t\treturn { [targetEntity.primary]: this.variables[value] ?? { never: true } }\n\t\t\t\t}\n\t\t\t\treturn value\n\t\t\t},\n\t\t})\n\t\tif (entityCache) {\n\t\t\tentityCache.set(entity.name, resultWhere)\n\t\t} else {\n\t\t\tthis.injectorCache.set(where, new Map([[entity.name, resultWhere]]))\n\t\t}\n\t\treturn resultWhere\n\t}\n}\n"],"names":["PredicateDefinitionProcessor"],"mappings":";;;;;;AAGO,MAAM,iBAAiB;AAAA,EAG7B,YAA6B,QAAuC,WAA6B;AAApE,SAAA,SAAA;AAAuC,SAAA,YAAA;AAFpE,kBAAA,MAAQ,qCAAoB,QAAA,CAA2D;AAAA,EAEW;AAAA,EAE3F,OAAO,QAAsB,OAA6C;AAChF,UAAM,cAAc,KAAK,cAAc,IAAI,KAAK;AAChD,UAAM,aAAa,aAAa,IAAI,OAAO,IAAI;AAC/C,QAAI,eAAe,QAAW;AAC7B,aAAO;AAAA,IACR;AACA,UAAM,+BAA+B,IAAIA,yCAA6B,KAAK,MAAM;AAEjF,UAAM,cAAc,6BAA6B,QAAQ,QAAQ,OAAO;AAAA,MACvE,cAAc,CAAC,EAAE,YAAY;AAC5B,YAAI,OAAO,UAAU,UAAU;AAC9B,iBAAO,KAAK,UAAU,KAAK,KAAK,EAAE,OAAO,KAAA;AAAA,QAC1C;AACA,eAAO;AAAA,MACR;AAAA,MACA,gBAAgB,CAAC,EAAE,OAAO,mBAAmB;AAC5C,YAAI,OAAO,UAAU,UAAU;AAC9B,iBAAO,EAAE,CAAC,aAAa,OAAO,GAAG,KAAK,UAAU,KAAK,KAAK,EAAE,OAAO,OAAK;AAAA,QACzE;AACA,eAAO;AAAA,MACR;AAAA,IAAA,CACA;AACD,QAAI,aAAa;AAChB,kBAAY,IAAI,OAAO,MAAM,WAAW;AAAA,IACzC,OAAO;AACN,WAAK,cAAc,IAAI,OAAO,oBAAI,IAAI,CAAC,CAAC,OAAO,MAAM,WAAW,CAAC,CAAC,CAAC;AAAA,IACpE;AACA,WAAO;AAAA,EACR;AACD;;"}
@@ -9,7 +9,8 @@ class VariableInjector {
9
9
  __publicField(this, "injectorCache", /* @__PURE__ */ new WeakMap());
10
10
  }
11
11
  inject(entity, where) {
12
- const cacheEntry = this.injectorCache.get(where);
12
+ const entityCache = this.injectorCache.get(where);
13
+ const cacheEntry = entityCache?.get(entity.name);
13
14
  if (cacheEntry !== void 0) {
14
15
  return cacheEntry;
15
16
  }
@@ -28,7 +29,11 @@ class VariableInjector {
28
29
  return value;
29
30
  }
30
31
  });
31
- this.injectorCache.set(where, resultWhere);
32
+ if (entityCache) {
33
+ entityCache.set(entity.name, resultWhere);
34
+ } else {
35
+ this.injectorCache.set(where, /* @__PURE__ */ new Map([[entity.name, resultWhere]]));
36
+ }
32
37
  return resultWhere;
33
38
  }
34
39
  }
@@ -1 +1 @@
1
- {"version":3,"file":"VariableInjector.js","sources":["../../../../../packages/engine-content-api/src/acl/VariableInjector.ts"],"sourcesContent":["import { Acl, Input, Model } from '@contember/schema'\nimport { PredicateDefinitionProcessor } from '@contember/schema-utils'\n\nexport class VariableInjector {\n\tprivate injectorCache = new WeakMap<Acl.PredicateDefinition, Input.Where>()\n\n\tconstructor(private readonly schema: Model.Schema, private readonly variables: Acl.VariablesMap) {}\n\n\tpublic inject(entity: Model.Entity, where: Acl.PredicateDefinition): Input.Where {\n\t\tconst cacheEntry = this.injectorCache.get(where)\n\t\tif (cacheEntry !== undefined) {\n\t\t\treturn cacheEntry\n\t\t}\n\t\tconst predicateDefinitionProcessor = new PredicateDefinitionProcessor(this.schema)\n\n\t\tconst resultWhere = predicateDefinitionProcessor.process(entity, where, {\n\t\t\thandleColumn: ({ value }) => {\n\t\t\t\tif (typeof value === 'string') {\n\t\t\t\t\treturn this.variables[value] ?? { never: true }\n\t\t\t\t}\n\t\t\t\treturn value as Input.Condition\n\t\t\t},\n\t\t\thandleRelation: ({ value, targetEntity }) => {\n\t\t\t\tif (typeof value === 'string') {\n\t\t\t\t\treturn { [targetEntity.primary]: this.variables[value] ?? { never: true } }\n\t\t\t\t}\n\t\t\t\treturn value\n\t\t\t},\n\t\t})\n\t\tthis.injectorCache.set(where, resultWhere)\n\t\treturn resultWhere\n\t}\n}\n"],"names":[],"mappings":";;;;AAGO,MAAM,iBAAiB;AAAA,EAG7B,YAA6B,QAAuC,WAA6B;AAApE,SAAA,SAAA;AAAuC,SAAA,YAAA;AAFpE,kBAAA,MAAQ,qCAAoB,QAAA,CAA8C;AAAA,EAEwB;AAAA,EAE3F,OAAO,QAAsB,OAA6C;AAChF,UAAM,aAAa,KAAK,cAAc,IAAI,KAAK;AAC/C,QAAI,eAAe,QAAW;AAC7B,aAAO;AAAA,IACR;AACA,UAAM,+BAA+B,IAAI,6BAA6B,KAAK,MAAM;AAEjF,UAAM,cAAc,6BAA6B,QAAQ,QAAQ,OAAO;AAAA,MACvE,cAAc,CAAC,EAAE,YAAY;AAC5B,YAAI,OAAO,UAAU,UAAU;AAC9B,iBAAO,KAAK,UAAU,KAAK,KAAK,EAAE,OAAO,KAAA;AAAA,QAC1C;AACA,eAAO;AAAA,MACR;AAAA,MACA,gBAAgB,CAAC,EAAE,OAAO,mBAAmB;AAC5C,YAAI,OAAO,UAAU,UAAU;AAC9B,iBAAO,EAAE,CAAC,aAAa,OAAO,GAAG,KAAK,UAAU,KAAK,KAAK,EAAE,OAAO,OAAK;AAAA,QACzE;AACA,eAAO;AAAA,MACR;AAAA,IAAA,CACA;AACD,SAAK,cAAc,IAAI,OAAO,WAAW;AACzC,WAAO;AAAA,EACR;AACD;"}
1
+ {"version":3,"file":"VariableInjector.js","sources":["../../../../../packages/engine-content-api/src/acl/VariableInjector.ts"],"sourcesContent":["import { Acl, Input, Model } from '@contember/schema'\nimport { PredicateDefinitionProcessor } from '@contember/schema-utils'\n\nexport class VariableInjector {\n\tprivate injectorCache = new WeakMap<Acl.PredicateDefinition, Map<string, Input.Where>>()\n\n\tconstructor(private readonly schema: Model.Schema, private readonly variables: Acl.VariablesMap) {}\n\n\tpublic inject(entity: Model.Entity, where: Acl.PredicateDefinition): Input.Where {\n\t\tconst entityCache = this.injectorCache.get(where)\n\t\tconst cacheEntry = entityCache?.get(entity.name)\n\t\tif (cacheEntry !== undefined) {\n\t\t\treturn cacheEntry\n\t\t}\n\t\tconst predicateDefinitionProcessor = new PredicateDefinitionProcessor(this.schema)\n\n\t\tconst resultWhere = predicateDefinitionProcessor.process(entity, where, {\n\t\t\thandleColumn: ({ value }) => {\n\t\t\t\tif (typeof value === 'string') {\n\t\t\t\t\treturn this.variables[value] ?? { never: true }\n\t\t\t\t}\n\t\t\t\treturn value as Input.Condition\n\t\t\t},\n\t\t\thandleRelation: ({ value, targetEntity }) => {\n\t\t\t\tif (typeof value === 'string') {\n\t\t\t\t\treturn { [targetEntity.primary]: this.variables[value] ?? { never: true } }\n\t\t\t\t}\n\t\t\t\treturn value\n\t\t\t},\n\t\t})\n\t\tif (entityCache) {\n\t\t\tentityCache.set(entity.name, resultWhere)\n\t\t} else {\n\t\t\tthis.injectorCache.set(where, new Map([[entity.name, resultWhere]]))\n\t\t}\n\t\treturn resultWhere\n\t}\n}\n"],"names":[],"mappings":";;;;AAGO,MAAM,iBAAiB;AAAA,EAG7B,YAA6B,QAAuC,WAA6B;AAApE,SAAA,SAAA;AAAuC,SAAA,YAAA;AAFpE,kBAAA,MAAQ,qCAAoB,QAAA,CAA2D;AAAA,EAEW;AAAA,EAE3F,OAAO,QAAsB,OAA6C;AAChF,UAAM,cAAc,KAAK,cAAc,IAAI,KAAK;AAChD,UAAM,aAAa,aAAa,IAAI,OAAO,IAAI;AAC/C,QAAI,eAAe,QAAW;AAC7B,aAAO;AAAA,IACR;AACA,UAAM,+BAA+B,IAAI,6BAA6B,KAAK,MAAM;AAEjF,UAAM,cAAc,6BAA6B,QAAQ,QAAQ,OAAO;AAAA,MACvE,cAAc,CAAC,EAAE,YAAY;AAC5B,YAAI,OAAO,UAAU,UAAU;AAC9B,iBAAO,KAAK,UAAU,KAAK,KAAK,EAAE,OAAO,KAAA;AAAA,QAC1C;AACA,eAAO;AAAA,MACR;AAAA,MACA,gBAAgB,CAAC,EAAE,OAAO,mBAAmB;AAC5C,YAAI,OAAO,UAAU,UAAU;AAC9B,iBAAO,EAAE,CAAC,aAAa,OAAO,GAAG,KAAK,UAAU,KAAK,KAAK,EAAE,OAAO,OAAK;AAAA,QACzE;AACA,eAAO;AAAA,MACR;AAAA,IAAA,CACA;AACD,QAAI,aAAa;AAChB,kBAAY,IAAI,OAAO,MAAM,WAAW;AAAA,IACzC,OAAO;AACN,WAAK,cAAc,IAAI,OAAO,oBAAI,IAAI,CAAC,CAAC,OAAO,MAAM,WAAW,CAAC,CAAC,CAAC;AAAA,IACpE;AACA,WAAO;AAAA,EACR;AACD;"}
@@ -3,10 +3,28 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const exception = require("../../exception.cjs");
4
4
  const isIt = require("../../utils/isIt.cjs");
5
5
  const schemaUtils = require("@contember/schema-utils");
6
+ require("@contember/schema");
7
+ require("@contember/database");
8
+ require("fast-deep-equal");
9
+ require("../../acl/PredicatesInjector.cjs");
10
+ require("node:crypto");
11
+ const getFieldReadPredicate = require("../../mapper/select/getFieldReadPredicate.cjs");
12
+ require("@contember/logger");
13
+ require("./HasManyToHasOneReducer.cjs");
14
+ require("graphql");
15
+ require("@contember/graphql-utils");
16
+ require("../paginatedHasMany/PaginatedHasManyFieldProvider.cjs");
17
+ require("@contember/dic");
18
+ require("../../mapper/select/optimizer/WhereOptimizer.cjs");
19
+ require("node:util");
20
+ require("@contember/schema-definition");
21
+ require("../../input-validation/ValidationContext.cjs");
22
+ require("../../input-validation/ValidationEvaluation.cjs");
6
23
  class HasManyToHasOneReducerExecutionHandler {
7
- constructor(schema, uniqueWhereExpander) {
24
+ constructor(schema, uniqueWhereExpander, predicateFactory) {
8
25
  this.schema = schema;
9
26
  this.uniqueWhereExpander = uniqueWhereExpander;
27
+ this.predicateFactory = predicateFactory;
10
28
  }
11
29
  process(context) {
12
30
  const { addData, entity, objectNode } = context;
@@ -42,7 +60,13 @@ class HasManyToHasOneReducerExecutionHandler {
42
60
  relationContext
43
61
  ], targetRelation.name);
44
62
  },
45
- defaultValue: null
63
+ defaultValue: null,
64
+ predicate: getFieldReadPredicate.getFieldReadPredicate(
65
+ this.predicateFactory,
66
+ entity,
67
+ schemaUtils.getField(entity, objectNode.extensions.relationName),
68
+ context.relationPath
69
+ )
46
70
  });
47
71
  }
48
72
  }
@@ -1 +1 @@
1
- {"version":3,"file":"HasManyToHasOneReducerExecutionHandler.cjs","sources":["../../../../../../packages/engine-content-api/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.ts"],"sourcesContent":["import { Input, Model } from '@contember/schema'\nimport { isIt } from '../../utils/index.js'\nimport { acceptFieldVisitor } from '@contember/schema-utils'\nimport { SelectExecutionHandler, SelectExecutionHandlerContext } from '../../mapper/index.js'\nimport { ImplementationException } from '../../exception.js'\nimport { UniqueWhereExpander } from '../../inputProcessing/index.js'\nimport { HasManyToHasOneReducerExtension } from './HasManyToHasOneReducer.js'\n\nexport class HasManyToHasOneReducerExecutionHandler implements SelectExecutionHandler<Input.UniqueQueryInput, HasManyToHasOneReducerExtension> {\n\tconstructor(private readonly schema: Model.Schema, private readonly uniqueWhereExpander: UniqueWhereExpander) {}\n\n\tprocess(context: SelectExecutionHandlerContext<Input.UniqueQueryInput, HasManyToHasOneReducerExtension>): void {\n\t\tconst { addData, entity, objectNode } = context\n\t\tif (!objectNode) {\n\t\t\tthrow new Error()\n\t\t}\n\t\taddData({\n\t\t\tfield: entity.primary,\n\t\t\tdataProvider: async (ids: Input.PrimaryValue[]) => {\n\t\t\t\tconst relationContext = acceptFieldVisitor(this.schema, entity, objectNode.extensions.relationName, {\n\t\t\t\t\tvisitRelation: context => context,\n\t\t\t\t\tvisitColumn: (): never => {\n\t\t\t\t\t\tthrow new ImplementationException('HasManyToHasOneReducerExecutionHandler: Not applicable for a column')\n\t\t\t\t\t},\n\t\t\t\t})\n\n\t\t\t\tconst { targetEntity, targetRelation } = relationContext\n\t\t\t\tif (!targetRelation || !isIt<Model.JoiningColumnRelation>(targetRelation, 'joiningColumn')) {\n\t\t\t\t\tthrow new Error('HasManyToHasOneReducerExecutionHandler: only applicable for relations with joiningColumn')\n\t\t\t\t}\n\n\t\t\t\tconst uniqueWhere = this.uniqueWhereExpander.expand(targetEntity, {\n\t\t\t\t\t...objectNode.args.by,\n\t\t\t\t\t[targetRelation.name]: { [entity.primary]: ids },\n\t\t\t\t})\n\t\t\t\tif (Object.keys(uniqueWhere).length !== 2) {\n\t\t\t\t\tthrow new Error('HasManyToHasOneReducerExecutionHandler: only tuple unique keys are allowed')\n\t\t\t\t}\n\t\t\t\tconst whereWithParentId = {\n\t\t\t\t\tand: [objectNode.args.filter || {}, uniqueWhere],\n\t\t\t\t}\n\t\t\t\tconst newObjectNode = objectNode.withArgs<Input.ListQueryInput>({ filter: whereWithParentId })\n\n\t\t\t\treturn context.mapper.selectAssoc(targetEntity, newObjectNode, [\n\t\t\t\t\t...context.relationPath,\n\t\t\t\t\trelationContext,\n\t\t\t\t], targetRelation.name)\n\t\t\t},\n\t\t\tdefaultValue: null,\n\t\t})\n\t}\n}\n"],"names":["acceptFieldVisitor","context","ImplementationException","isIt"],"mappings":";;;;;AAQO,MAAM,uCAAkI;AAAA,EAC9I,YAA6B,QAAuC,qBAA0C;AAAjF,SAAA,SAAA;AAAuC,SAAA,sBAAA;AAAA,EAA2C;AAAA,EAE/G,QAAQ,SAAuG;AAC9G,UAAM,EAAE,SAAS,QAAQ,WAAA,IAAe;AACxC,QAAI,CAAC,YAAY;AAChB,YAAM,IAAI,MAAA;AAAA,IACX;AACA,YAAQ;AAAA,MACP,OAAO,OAAO;AAAA,MACd,cAAc,OAAO,QAA8B;AAClD,cAAM,kBAAkBA,YAAAA,mBAAmB,KAAK,QAAQ,QAAQ,WAAW,WAAW,cAAc;AAAA,UACnG,eAAe,CAAAC,aAAWA;AAAAA,UAC1B,aAAa,MAAa;AACzB,kBAAM,IAAIC,UAAAA,wBAAwB,qEAAqE;AAAA,UACxG;AAAA,QAAA,CACA;AAED,cAAM,EAAE,cAAc,eAAA,IAAmB;AACzC,YAAI,CAAC,kBAAkB,CAACC,KAAAA,KAAkC,gBAAgB,eAAe,GAAG;AAC3F,gBAAM,IAAI,MAAM,0FAA0F;AAAA,QAC3G;AAEA,cAAM,cAAc,KAAK,oBAAoB,OAAO,cAAc;AAAA,UACjE,GAAG,WAAW,KAAK;AAAA,UACnB,CAAC,eAAe,IAAI,GAAG,EAAE,CAAC,OAAO,OAAO,GAAG,IAAA;AAAA,QAAI,CAC/C;AACD,YAAI,OAAO,KAAK,WAAW,EAAE,WAAW,GAAG;AAC1C,gBAAM,IAAI,MAAM,4EAA4E;AAAA,QAC7F;AACA,cAAM,oBAAoB;AAAA,UACzB,KAAK,CAAC,WAAW,KAAK,UAAU,CAAA,GAAI,WAAW;AAAA,QAAA;AAEhD,cAAM,gBAAgB,WAAW,SAA+B,EAAE,QAAQ,mBAAmB;AAE7F,eAAO,QAAQ,OAAO,YAAY,cAAc,eAAe;AAAA,UAC9D,GAAG,QAAQ;AAAA,UACX;AAAA,QAAA,GACE,eAAe,IAAI;AAAA,MACvB;AAAA,MACA,cAAc;AAAA,IAAA,CACd;AAAA,EACF;AACD;;"}
1
+ {"version":3,"file":"HasManyToHasOneReducerExecutionHandler.cjs","sources":["../../../../../../packages/engine-content-api/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.ts"],"sourcesContent":["import { Input, Model } from '@contember/schema'\nimport { isIt } from '../../utils/index.js'\nimport { acceptFieldVisitor, getField } from '@contember/schema-utils'\nimport { getFieldReadPredicate, SelectExecutionHandler, SelectExecutionHandlerContext } from '../../mapper/index.js'\nimport { ImplementationException } from '../../exception.js'\nimport { UniqueWhereExpander } from '../../inputProcessing/index.js'\nimport { HasManyToHasOneReducerExtension } from './HasManyToHasOneReducer.js'\nimport { PredicateFactory } from '../../acl/index.js'\n\nexport class HasManyToHasOneReducerExecutionHandler implements SelectExecutionHandler<Input.UniqueQueryInput, HasManyToHasOneReducerExtension> {\n\tconstructor(\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly uniqueWhereExpander: UniqueWhereExpander,\n\t\tprivate readonly predicateFactory: PredicateFactory,\n\t) {}\n\n\tprocess(context: SelectExecutionHandlerContext<Input.UniqueQueryInput, HasManyToHasOneReducerExtension>): void {\n\t\tconst { addData, entity, objectNode } = context\n\t\tif (!objectNode) {\n\t\t\tthrow new Error()\n\t\t}\n\t\taddData({\n\t\t\tfield: entity.primary,\n\t\t\tdataProvider: async (ids: Input.PrimaryValue[]) => {\n\t\t\t\tconst relationContext = acceptFieldVisitor(this.schema, entity, objectNode.extensions.relationName, {\n\t\t\t\t\tvisitRelation: context => context,\n\t\t\t\t\tvisitColumn: (): never => {\n\t\t\t\t\t\tthrow new ImplementationException('HasManyToHasOneReducerExecutionHandler: Not applicable for a column')\n\t\t\t\t\t},\n\t\t\t\t})\n\n\t\t\t\tconst { targetEntity, targetRelation } = relationContext\n\t\t\t\tif (!targetRelation || !isIt<Model.JoiningColumnRelation>(targetRelation, 'joiningColumn')) {\n\t\t\t\t\tthrow new Error('HasManyToHasOneReducerExecutionHandler: only applicable for relations with joiningColumn')\n\t\t\t\t}\n\n\t\t\t\tconst uniqueWhere = this.uniqueWhereExpander.expand(targetEntity, {\n\t\t\t\t\t...objectNode.args.by,\n\t\t\t\t\t[targetRelation.name]: { [entity.primary]: ids },\n\t\t\t\t})\n\t\t\t\tif (Object.keys(uniqueWhere).length !== 2) {\n\t\t\t\t\tthrow new Error('HasManyToHasOneReducerExecutionHandler: only tuple unique keys are allowed')\n\t\t\t\t}\n\t\t\t\tconst whereWithParentId = {\n\t\t\t\t\tand: [objectNode.args.filter || {}, uniqueWhere],\n\t\t\t\t}\n\t\t\t\tconst newObjectNode = objectNode.withArgs<Input.ListQueryInput>({ filter: whereWithParentId })\n\n\t\t\t\treturn context.mapper.selectAssoc(targetEntity, newObjectNode, [\n\t\t\t\t\t...context.relationPath,\n\t\t\t\t\trelationContext,\n\t\t\t\t], targetRelation.name)\n\t\t\t},\n\t\t\tdefaultValue: null,\n\t\t\tpredicate: getFieldReadPredicate(\n\t\t\t\tthis.predicateFactory,\n\t\t\t\tentity,\n\t\t\t\tgetField(entity, objectNode.extensions.relationName),\n\t\t\t\tcontext.relationPath,\n\t\t\t),\n\t\t})\n\t}\n}\n"],"names":["acceptFieldVisitor","context","ImplementationException","isIt","getFieldReadPredicate","getField"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AASO,MAAM,uCAAkI;AAAA,EAC9I,YACkB,QACA,qBACA,kBAChB;AAHgB,SAAA,SAAA;AACA,SAAA,sBAAA;AACA,SAAA,mBAAA;AAAA,EACf;AAAA,EAEH,QAAQ,SAAuG;AAC9G,UAAM,EAAE,SAAS,QAAQ,WAAA,IAAe;AACxC,QAAI,CAAC,YAAY;AAChB,YAAM,IAAI,MAAA;AAAA,IACX;AACA,YAAQ;AAAA,MACP,OAAO,OAAO;AAAA,MACd,cAAc,OAAO,QAA8B;AAClD,cAAM,kBAAkBA,YAAAA,mBAAmB,KAAK,QAAQ,QAAQ,WAAW,WAAW,cAAc;AAAA,UACnG,eAAe,CAAAC,aAAWA;AAAAA,UAC1B,aAAa,MAAa;AACzB,kBAAM,IAAIC,UAAAA,wBAAwB,qEAAqE;AAAA,UACxG;AAAA,QAAA,CACA;AAED,cAAM,EAAE,cAAc,eAAA,IAAmB;AACzC,YAAI,CAAC,kBAAkB,CAACC,KAAAA,KAAkC,gBAAgB,eAAe,GAAG;AAC3F,gBAAM,IAAI,MAAM,0FAA0F;AAAA,QAC3G;AAEA,cAAM,cAAc,KAAK,oBAAoB,OAAO,cA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