@contember/engine-content-api 2.1.0-rc.3 → 2.2.0-alpha.10

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 (1114) hide show
  1. package/CLAUDE.md +12 -0
  2. package/dist/development/src/ExecutionContainer.cjs +7 -4
  3. package/dist/development/src/ExecutionContainer.cjs.map +1 -1
  4. package/dist/development/src/ExecutionContainer.js +7 -4
  5. package/dist/development/src/ExecutionContainer.js.map +1 -1
  6. package/dist/development/src/acl/EvaluatedPredicateReplacer.cjs.map +1 -1
  7. package/dist/development/src/acl/EvaluatedPredicateReplacer.js.map +1 -1
  8. package/dist/development/src/acl/PermissionFactory.cjs.map +1 -1
  9. package/dist/development/src/acl/PermissionFactory.js.map +1 -1
  10. package/dist/development/src/acl/PredicateFactory.cjs.map +1 -1
  11. package/dist/development/src/acl/PredicateFactory.js.map +1 -1
  12. package/dist/development/src/acl/PredicatesInjector.cjs.map +1 -1
  13. package/dist/development/src/acl/PredicatesInjector.js.map +1 -1
  14. package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducer.cjs.map +1 -1
  15. package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducer.js.map +1 -1
  16. package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.cjs.map +1 -1
  17. package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.js.map +1 -1
  18. package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.cjs.map +1 -1
  19. package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.js.map +1 -1
  20. package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyCountVisitor.cjs.map +1 -1
  21. package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyCountVisitor.js.map +1 -1
  22. package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.cjs.map +1 -1
  23. package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.js.map +1 -1
  24. package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyFieldProvider.cjs.map +1 -1
  25. package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyFieldProvider.js.map +1 -1
  26. package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.cjs.map +1 -1
  27. package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.js.map +1 -1
  28. package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyNodesVisitor.cjs.map +1 -1
  29. package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyNodesVisitor.js.map +1 -1
  30. package/dist/development/src/input-validation/EntityRulesResolver.cjs.map +1 -1
  31. package/dist/development/src/input-validation/EntityRulesResolver.js.map +1 -1
  32. package/dist/development/src/input-validation/JsonSchemaValidator.cjs +208 -0
  33. package/dist/development/src/input-validation/JsonSchemaValidator.cjs.map +1 -0
  34. package/dist/development/src/input-validation/JsonSchemaValidator.js +208 -0
  35. package/dist/development/src/input-validation/JsonSchemaValidator.js.map +1 -0
  36. package/dist/development/src/input-validation/QueryAstFactory.cjs.map +1 -1
  37. package/dist/development/src/input-validation/QueryAstFactory.js.map +1 -1
  38. package/dist/development/src/input-validation/ValidationContext.cjs.map +1 -1
  39. package/dist/development/src/input-validation/ValidationContext.js.map +1 -1
  40. package/dist/development/src/input-validation/ValidationDataSelector.cjs.map +1 -1
  41. package/dist/development/src/input-validation/ValidationDataSelector.js.map +1 -1
  42. package/dist/development/src/input-validation/ValidationEvaluation.cjs.map +1 -1
  43. package/dist/development/src/input-validation/ValidationEvaluation.js.map +1 -1
  44. package/dist/development/src/input-validation/dependencies/DependencyCollector.cjs.map +1 -1
  45. package/dist/development/src/input-validation/dependencies/DependencyCollector.js.map +1 -1
  46. package/dist/development/src/input-validation/dependencies/DependencyMerger.cjs.map +1 -1
  47. package/dist/development/src/input-validation/dependencies/DependencyMerger.js.map +1 -1
  48. package/dist/development/src/input-validation/preValidation/CreateInputPreValidationProcessor.cjs.map +1 -1
  49. package/dist/development/src/input-validation/preValidation/CreateInputPreValidationProcessor.js.map +1 -1
  50. package/dist/development/src/input-validation/preValidation/InputPreValidator.cjs +38 -2
  51. package/dist/development/src/input-validation/preValidation/InputPreValidator.cjs.map +1 -1
  52. package/dist/development/src/input-validation/preValidation/InputPreValidator.js +38 -2
  53. package/dist/development/src/input-validation/preValidation/InputPreValidator.js.map +1 -1
  54. package/dist/development/src/input-validation/preValidation/UpdateInputPreValidationProcessor.cjs.map +1 -1
  55. package/dist/development/src/input-validation/preValidation/UpdateInputPreValidationProcessor.js.map +1 -1
  56. package/dist/development/src/inputProcessing/CreateInputVisitor.cjs.map +1 -1
  57. package/dist/development/src/inputProcessing/CreateInputVisitor.js.map +1 -1
  58. package/dist/development/src/inputProcessing/ObjectNode.cjs.map +1 -1
  59. package/dist/development/src/inputProcessing/ObjectNode.js.map +1 -1
  60. package/dist/development/src/inputProcessing/UniqueWhereExpander.cjs.map +1 -1
  61. package/dist/development/src/inputProcessing/UniqueWhereExpander.js.map +1 -1
  62. package/dist/development/src/inputProcessing/UpdateInputVisitor.cjs.map +1 -1
  63. package/dist/development/src/inputProcessing/UpdateInputVisitor.js.map +1 -1
  64. package/dist/development/src/introspection/IntrospectionSchemaDefinitionFactory.cjs.map +1 -1
  65. package/dist/development/src/introspection/IntrospectionSchemaDefinitionFactory.js.map +1 -1
  66. package/dist/development/src/introspection/IntrospectionSchemaFactory.cjs.map +1 -1
  67. package/dist/development/src/introspection/IntrospectionSchemaFactory.js.map +1 -1
  68. package/dist/development/src/mapper/ErrorUtils.cjs.map +1 -1
  69. package/dist/development/src/mapper/ErrorUtils.js.map +1 -1
  70. package/dist/development/src/mapper/EventManager.cjs.map +1 -1
  71. package/dist/development/src/mapper/EventManager.js.map +1 -1
  72. package/dist/development/src/mapper/JunctionTableManager.cjs.map +1 -1
  73. package/dist/development/src/mapper/JunctionTableManager.js.map +1 -1
  74. package/dist/development/src/mapper/Mapper.cjs +8 -5
  75. package/dist/development/src/mapper/Mapper.cjs.map +1 -1
  76. package/dist/development/src/mapper/Mapper.js +8 -5
  77. package/dist/development/src/mapper/Mapper.js.map +1 -1
  78. package/dist/development/src/mapper/MapperFactory.cjs +7 -4
  79. package/dist/development/src/mapper/MapperFactory.cjs.map +1 -1
  80. package/dist/development/src/mapper/MapperFactory.js +7 -4
  81. package/dist/development/src/mapper/MapperFactory.js.map +1 -1
  82. package/dist/development/src/mapper/MutationProcessorHelper.cjs.map +1 -1
  83. package/dist/development/src/mapper/MutationProcessorHelper.js.map +1 -1
  84. package/dist/development/src/mapper/Result.cjs.map +1 -1
  85. package/dist/development/src/mapper/Result.js.map +1 -1
  86. package/dist/development/src/mapper/delete/DeleteExecutor.cjs.map +1 -1
  87. package/dist/development/src/mapper/delete/DeleteExecutor.js.map +1 -1
  88. package/dist/development/src/mapper/delete/DeleteState.cjs.map +1 -1
  89. package/dist/development/src/mapper/delete/DeleteState.js.map +1 -1
  90. package/dist/development/src/mapper/insert/InsertBuilder.cjs.map +1 -1
  91. package/dist/development/src/mapper/insert/InsertBuilder.js.map +1 -1
  92. package/dist/development/src/mapper/insert/InsertBuilderFactory.cjs.map +1 -1
  93. package/dist/development/src/mapper/insert/InsertBuilderFactory.js.map +1 -1
  94. package/dist/development/src/mapper/insert/Inserter.cjs.map +1 -1
  95. package/dist/development/src/mapper/insert/Inserter.js.map +1 -1
  96. package/dist/development/src/mapper/insert/SqlCreateInputProcessor.cjs.map +1 -1
  97. package/dist/development/src/mapper/insert/SqlCreateInputProcessor.js.map +1 -1
  98. package/dist/development/src/mapper/insert/relations/ManyHasManyCreateInputProcessor.cjs.map +1 -1
  99. package/dist/development/src/mapper/insert/relations/ManyHasManyCreateInputProcessor.js.map +1 -1
  100. package/dist/development/src/mapper/insert/relations/ManyHasOneCreateInputProcessor.cjs.map +1 -1
  101. package/dist/development/src/mapper/insert/relations/ManyHasOneCreateInputProcessor.js.map +1 -1
  102. package/dist/development/src/mapper/insert/relations/OneHasManyCreateInputProcessor.cjs.map +1 -1
  103. package/dist/development/src/mapper/insert/relations/OneHasManyCreateInputProcessor.js.map +1 -1
  104. package/dist/development/src/mapper/insert/relations/OneHasOneInverseCreateInputProcessor.cjs.map +1 -1
  105. package/dist/development/src/mapper/insert/relations/OneHasOneInverseCreateInputProcessor.js.map +1 -1
  106. package/dist/development/src/mapper/insert/relations/OneHasOneOwningCreateInputProcessor.cjs.map +1 -1
  107. package/dist/development/src/mapper/insert/relations/OneHasOneOwningCreateInputProcessor.js.map +1 -1
  108. package/dist/development/src/mapper/select/ConditionBuilder.cjs +10 -1
  109. package/dist/development/src/mapper/select/ConditionBuilder.cjs.map +1 -1
  110. package/dist/development/src/mapper/select/ConditionBuilder.js +10 -1
  111. package/dist/development/src/mapper/select/ConditionBuilder.js.map +1 -1
  112. package/dist/development/src/mapper/select/JoinBuilder.cjs.map +1 -1
  113. package/dist/development/src/mapper/select/JoinBuilder.js.map +1 -1
  114. package/dist/development/src/mapper/select/JoinVisitor.cjs.map +1 -1
  115. package/dist/development/src/mapper/select/JoinVisitor.js.map +1 -1
  116. package/dist/development/src/mapper/select/OrderByBuilder.cjs.map +1 -1
  117. package/dist/development/src/mapper/select/OrderByBuilder.js.map +1 -1
  118. package/dist/development/src/mapper/select/OrderByHelper.cjs.map +1 -1
  119. package/dist/development/src/mapper/select/OrderByHelper.js.map +1 -1
  120. package/dist/development/src/mapper/select/RelationFetcher.cjs +2 -2
  121. package/dist/development/src/mapper/select/RelationFetcher.cjs.map +1 -1
  122. package/dist/development/src/mapper/select/RelationFetcher.js +2 -2
  123. package/dist/development/src/mapper/select/RelationFetcher.js.map +1 -1
  124. package/dist/development/src/mapper/select/SelectBuilder.cjs.map +1 -1
  125. package/dist/development/src/mapper/select/SelectBuilder.js.map +1 -1
  126. package/dist/development/src/mapper/select/SelectHydrator.cjs +39 -19
  127. package/dist/development/src/mapper/select/SelectHydrator.cjs.map +1 -1
  128. package/dist/development/src/mapper/select/SelectHydrator.js +39 -19
  129. package/dist/development/src/mapper/select/SelectHydrator.js.map +1 -1
  130. package/dist/development/src/mapper/select/WhereBuilder.cjs.map +1 -1
  131. package/dist/development/src/mapper/select/WhereBuilder.js.map +1 -1
  132. package/dist/development/src/mapper/select/handlers/FieldsVisitor.cjs +9 -1
  133. package/dist/development/src/mapper/select/handlers/FieldsVisitor.cjs.map +1 -1
  134. package/dist/development/src/mapper/select/handlers/FieldsVisitor.js +9 -1
  135. package/dist/development/src/mapper/select/handlers/FieldsVisitor.js.map +1 -1
  136. package/dist/development/src/mapper/select/handlers/FieldsVisitorFactory.cjs.map +1 -1
  137. package/dist/development/src/mapper/select/handlers/FieldsVisitorFactory.js.map +1 -1
  138. package/dist/development/src/mapper/select/handlers/MetaHandler.cjs.map +1 -1
  139. package/dist/development/src/mapper/select/handlers/MetaHandler.js.map +1 -1
  140. package/dist/development/src/mapper/select/optimizer/ConditionOptimizer.cjs.map +1 -1
  141. package/dist/development/src/mapper/select/optimizer/ConditionOptimizer.js.map +1 -1
  142. package/dist/development/src/mapper/select/optimizer/WhereOptimizer.cjs.map +1 -1
  143. package/dist/development/src/mapper/select/optimizer/WhereOptimizer.js.map +1 -1
  144. package/dist/development/src/mapper/update/SqlUpdateInputProcessor.cjs.map +1 -1
  145. package/dist/development/src/mapper/update/SqlUpdateInputProcessor.js.map +1 -1
  146. package/dist/development/src/mapper/update/UpdateBuilder.cjs.map +1 -1
  147. package/dist/development/src/mapper/update/UpdateBuilder.js.map +1 -1
  148. package/dist/development/src/mapper/update/UpdateBuilderFactory.cjs.map +1 -1
  149. package/dist/development/src/mapper/update/UpdateBuilderFactory.js.map +1 -1
  150. package/dist/development/src/mapper/update/Updater.cjs.map +1 -1
  151. package/dist/development/src/mapper/update/Updater.js.map +1 -1
  152. package/dist/development/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.cjs.map +1 -1
  153. package/dist/development/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.js.map +1 -1
  154. package/dist/development/src/mapper/update/relations/ManyHasOneUpdateInputProcessor.cjs.map +1 -1
  155. package/dist/development/src/mapper/update/relations/ManyHasOneUpdateInputProcessor.js.map +1 -1
  156. package/dist/development/src/mapper/update/relations/OneHasManyUpdateInputProcessor.cjs.map +1 -1
  157. package/dist/development/src/mapper/update/relations/OneHasManyUpdateInputProcessor.js.map +1 -1
  158. package/dist/development/src/mapper/update/relations/OneHasOneInverseUpdateInputProcessor.cjs.map +1 -1
  159. package/dist/development/src/mapper/update/relations/OneHasOneInverseUpdateInputProcessor.js.map +1 -1
  160. package/dist/development/src/mapper/update/relations/OneHasOneOwningUpdateInputProcessor.cjs.map +1 -1
  161. package/dist/development/src/mapper/update/relations/OneHasOneOwningUpdateInputProcessor.js.map +1 -1
  162. package/dist/development/src/resolvers/GraphQlQueryAstFactory.cjs.map +1 -1
  163. package/dist/development/src/resolvers/GraphQlQueryAstFactory.js.map +1 -1
  164. package/dist/development/src/resolvers/MutationResolver.cjs +49 -35
  165. package/dist/development/src/resolvers/MutationResolver.cjs.map +1 -1
  166. package/dist/development/src/resolvers/MutationResolver.js +50 -36
  167. package/dist/development/src/resolvers/MutationResolver.js.map +1 -1
  168. package/dist/development/src/resolvers/ReadHelpers.cjs.map +1 -1
  169. package/dist/development/src/resolvers/ReadHelpers.js.map +1 -1
  170. package/dist/development/src/resolvers/ReadResolver.cjs.map +1 -1
  171. package/dist/development/src/resolvers/ReadResolver.js.map +1 -1
  172. package/dist/development/src/resolvers/RefreshViewResolver.cjs.map +1 -1
  173. package/dist/development/src/resolvers/RefreshViewResolver.js.map +1 -1
  174. package/dist/development/src/resolvers/ValidationResolver.cjs.map +1 -1
  175. package/dist/development/src/resolvers/ValidationResolver.js.map +1 -1
  176. package/dist/development/src/schema/ColumnTypeResolver.cjs +2 -0
  177. package/dist/development/src/schema/ColumnTypeResolver.cjs.map +1 -1
  178. package/dist/development/src/schema/ColumnTypeResolver.js +2 -0
  179. package/dist/development/src/schema/ColumnTypeResolver.js.map +1 -1
  180. package/dist/development/src/schema/ConditionTypeProvider.cjs +2 -0
  181. package/dist/development/src/schema/ConditionTypeProvider.cjs.map +1 -1
  182. package/dist/development/src/schema/ConditionTypeProvider.js +2 -0
  183. package/dist/development/src/schema/ConditionTypeProvider.js.map +1 -1
  184. package/dist/development/src/schema/CustomTypesProvider.cjs +32 -0
  185. package/dist/development/src/schema/CustomTypesProvider.cjs.map +1 -1
  186. package/dist/development/src/schema/CustomTypesProvider.js +32 -0
  187. package/dist/development/src/schema/CustomTypesProvider.js.map +1 -1
  188. package/dist/development/src/schema/EntityTypeProvider.cjs.map +1 -1
  189. package/dist/development/src/schema/EntityTypeProvider.js.map +1 -1
  190. package/dist/development/src/schema/EnumsProvider.cjs.map +1 -1
  191. package/dist/development/src/schema/EnumsProvider.js.map +1 -1
  192. package/dist/development/src/schema/FieldAccessVisitor.cjs.map +1 -1
  193. package/dist/development/src/schema/FieldAccessVisitor.js.map +1 -1
  194. package/dist/development/src/schema/GraphQlSchemaBuilder.cjs.map +1 -1
  195. package/dist/development/src/schema/GraphQlSchemaBuilder.js.map +1 -1
  196. package/dist/development/src/schema/GraphQlSchemaBuilderFactory.cjs.map +1 -1
  197. package/dist/development/src/schema/GraphQlSchemaBuilderFactory.js.map +1 -1
  198. package/dist/development/src/schema/MutationProvider.cjs.map +1 -1
  199. package/dist/development/src/schema/MutationProvider.js.map +1 -1
  200. package/dist/development/src/schema/OperationExtension.cjs.map +1 -1
  201. package/dist/development/src/schema/OperationExtension.js.map +1 -1
  202. package/dist/development/src/schema/OrderByTypeProvider.cjs.map +1 -1
  203. package/dist/development/src/schema/OrderByTypeProvider.js.map +1 -1
  204. package/dist/development/src/schema/PaginatedFieldConfigFactory.cjs.map +1 -1
  205. package/dist/development/src/schema/PaginatedFieldConfigFactory.js.map +1 -1
  206. package/dist/development/src/schema/QueryProvider.cjs.map +1 -1
  207. package/dist/development/src/schema/QueryProvider.js.map +1 -1
  208. package/dist/development/src/schema/RefreshViewMutationProvider.cjs.map +1 -1
  209. package/dist/development/src/schema/RefreshViewMutationProvider.js.map +1 -1
  210. package/dist/development/src/schema/ValidationQueriesProvider.cjs.map +1 -1
  211. package/dist/development/src/schema/ValidationQueriesProvider.js.map +1 -1
  212. package/dist/development/src/schema/WhereTypeProvider.cjs.map +1 -1
  213. package/dist/development/src/schema/WhereTypeProvider.js.map +1 -1
  214. package/dist/development/src/schema/entities/FieldArgsVisitor.cjs.map +1 -1
  215. package/dist/development/src/schema/entities/FieldArgsVisitor.js.map +1 -1
  216. package/dist/development/src/schema/entities/FieldTypeVisitor.cjs.map +1 -1
  217. package/dist/development/src/schema/entities/FieldTypeVisitor.js.map +1 -1
  218. package/dist/development/src/schema/mutations/ConnectOrCreateRelationInputProvider.cjs.map +1 -1
  219. package/dist/development/src/schema/mutations/ConnectOrCreateRelationInputProvider.js.map +1 -1
  220. package/dist/development/src/schema/mutations/CreateEntityInputFieldVisitor.cjs.map +1 -1
  221. package/dist/development/src/schema/mutations/CreateEntityInputFieldVisitor.js.map +1 -1
  222. package/dist/development/src/schema/mutations/CreateEntityRelationAllowedOperationsVisitor.cjs.map +1 -1
  223. package/dist/development/src/schema/mutations/CreateEntityRelationAllowedOperationsVisitor.js.map +1 -1
  224. package/dist/development/src/schema/mutations/CreateEntityRelationInputFieldVisitor.cjs.map +1 -1
  225. package/dist/development/src/schema/mutations/CreateEntityRelationInputFieldVisitor.js.map +1 -1
  226. package/dist/development/src/schema/mutations/CreateEntityRelationInputProvider.cjs.map +1 -1
  227. package/dist/development/src/schema/mutations/CreateEntityRelationInputProvider.js.map +1 -1
  228. package/dist/development/src/schema/mutations/EntityInputProvider.cjs.map +1 -1
  229. package/dist/development/src/schema/mutations/EntityInputProvider.js.map +1 -1
  230. package/dist/development/src/schema/mutations/UpdateEntityInputFieldVisitor.cjs.map +1 -1
  231. package/dist/development/src/schema/mutations/UpdateEntityInputFieldVisitor.js.map +1 -1
  232. package/dist/development/src/schema/mutations/UpdateEntityRelationAllowedOperationsVisitor.cjs.map +1 -1
  233. package/dist/development/src/schema/mutations/UpdateEntityRelationAllowedOperationsVisitor.js.map +1 -1
  234. package/dist/development/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.cjs.map +1 -1
  235. package/dist/development/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.js.map +1 -1
  236. package/dist/development/src/schema/mutations/UpdateEntityRelationInputProvider.cjs.map +1 -1
  237. package/dist/development/src/schema/mutations/UpdateEntityRelationInputProvider.js.map +1 -1
  238. package/dist/development/src/schema/utils.cjs.map +1 -1
  239. package/dist/development/src/schema/utils.js.map +1 -1
  240. package/dist/development/src/utils/accessor.cjs.map +1 -1
  241. package/dist/development/src/utils/accessor.js.map +1 -1
  242. package/dist/development/src/utils/paginationUtils.cjs.map +1 -1
  243. package/dist/development/src/utils/paginationUtils.js.map +1 -1
  244. package/dist/development/src/utils/singletonFactory.cjs.map +1 -1
  245. package/dist/development/src/utils/singletonFactory.js.map +1 -1
  246. package/dist/production/src/ExecutionContainer.cjs +7 -4
  247. package/dist/production/src/ExecutionContainer.cjs.map +1 -1
  248. package/dist/production/src/ExecutionContainer.js +7 -4
  249. package/dist/production/src/ExecutionContainer.js.map +1 -1
  250. package/dist/production/src/acl/EvaluatedPredicateReplacer.cjs.map +1 -1
  251. package/dist/production/src/acl/EvaluatedPredicateReplacer.js.map +1 -1
  252. package/dist/production/src/acl/PermissionFactory.cjs.map +1 -1
  253. package/dist/production/src/acl/PermissionFactory.js.map +1 -1
  254. package/dist/production/src/acl/PredicateFactory.cjs.map +1 -1
  255. package/dist/production/src/acl/PredicateFactory.js.map +1 -1
  256. package/dist/production/src/acl/PredicatesInjector.cjs.map +1 -1
  257. package/dist/production/src/acl/PredicatesInjector.js.map +1 -1
  258. package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducer.cjs.map +1 -1
  259. package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducer.js.map +1 -1
  260. package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.cjs.map +1 -1
  261. package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.js.map +1 -1
  262. package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.cjs.map +1 -1
  263. package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.js.map +1 -1
  264. package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyCountVisitor.cjs.map +1 -1
  265. package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyCountVisitor.js.map +1 -1
  266. package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.cjs.map +1 -1
  267. package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.js.map +1 -1
  268. package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyFieldProvider.cjs.map +1 -1
  269. package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyFieldProvider.js.map +1 -1
  270. package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.cjs.map +1 -1
  271. package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.js.map +1 -1
  272. package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyNodesVisitor.cjs.map +1 -1
  273. package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyNodesVisitor.js.map +1 -1
  274. package/dist/production/src/input-validation/EntityRulesResolver.cjs.map +1 -1
  275. package/dist/production/src/input-validation/EntityRulesResolver.js.map +1 -1
  276. package/dist/production/src/input-validation/JsonSchemaValidator.cjs +208 -0
  277. package/dist/production/src/input-validation/JsonSchemaValidator.cjs.map +1 -0
  278. package/dist/production/src/input-validation/JsonSchemaValidator.js +208 -0
  279. package/dist/production/src/input-validation/JsonSchemaValidator.js.map +1 -0
  280. package/dist/production/src/input-validation/QueryAstFactory.cjs.map +1 -1
  281. package/dist/production/src/input-validation/QueryAstFactory.js.map +1 -1
  282. package/dist/production/src/input-validation/ValidationContext.cjs.map +1 -1
  283. package/dist/production/src/input-validation/ValidationContext.js.map +1 -1
  284. package/dist/production/src/input-validation/ValidationDataSelector.cjs.map +1 -1
  285. package/dist/production/src/input-validation/ValidationDataSelector.js.map +1 -1
  286. package/dist/production/src/input-validation/ValidationEvaluation.cjs.map +1 -1
  287. package/dist/production/src/input-validation/ValidationEvaluation.js.map +1 -1
  288. package/dist/production/src/input-validation/dependencies/DependencyCollector.cjs.map +1 -1
  289. package/dist/production/src/input-validation/dependencies/DependencyCollector.js.map +1 -1
  290. package/dist/production/src/input-validation/dependencies/DependencyMerger.cjs.map +1 -1
  291. package/dist/production/src/input-validation/dependencies/DependencyMerger.js.map +1 -1
  292. package/dist/production/src/input-validation/preValidation/CreateInputPreValidationProcessor.cjs.map +1 -1
  293. package/dist/production/src/input-validation/preValidation/CreateInputPreValidationProcessor.js.map +1 -1
  294. package/dist/production/src/input-validation/preValidation/InputPreValidator.cjs +38 -2
  295. package/dist/production/src/input-validation/preValidation/InputPreValidator.cjs.map +1 -1
  296. package/dist/production/src/input-validation/preValidation/InputPreValidator.js +38 -2
  297. package/dist/production/src/input-validation/preValidation/InputPreValidator.js.map +1 -1
  298. package/dist/production/src/input-validation/preValidation/UpdateInputPreValidationProcessor.cjs.map +1 -1
  299. package/dist/production/src/input-validation/preValidation/UpdateInputPreValidationProcessor.js.map +1 -1
  300. package/dist/production/src/inputProcessing/CreateInputVisitor.cjs.map +1 -1
  301. package/dist/production/src/inputProcessing/CreateInputVisitor.js.map +1 -1
  302. package/dist/production/src/inputProcessing/ObjectNode.cjs.map +1 -1
  303. package/dist/production/src/inputProcessing/ObjectNode.js.map +1 -1
  304. package/dist/production/src/inputProcessing/UniqueWhereExpander.cjs.map +1 -1
  305. package/dist/production/src/inputProcessing/UniqueWhereExpander.js.map +1 -1
  306. package/dist/production/src/inputProcessing/UpdateInputVisitor.cjs.map +1 -1
  307. package/dist/production/src/inputProcessing/UpdateInputVisitor.js.map +1 -1
  308. package/dist/production/src/introspection/IntrospectionSchemaDefinitionFactory.cjs.map +1 -1
  309. package/dist/production/src/introspection/IntrospectionSchemaDefinitionFactory.js.map +1 -1
  310. package/dist/production/src/introspection/IntrospectionSchemaFactory.cjs.map +1 -1
  311. package/dist/production/src/introspection/IntrospectionSchemaFactory.js.map +1 -1
  312. package/dist/production/src/mapper/ErrorUtils.cjs.map +1 -1
  313. package/dist/production/src/mapper/ErrorUtils.js.map +1 -1
  314. package/dist/production/src/mapper/EventManager.cjs.map +1 -1
  315. package/dist/production/src/mapper/EventManager.js.map +1 -1
  316. package/dist/production/src/mapper/JunctionTableManager.cjs.map +1 -1
  317. package/dist/production/src/mapper/JunctionTableManager.js.map +1 -1
  318. package/dist/production/src/mapper/Mapper.cjs +8 -5
  319. package/dist/production/src/mapper/Mapper.cjs.map +1 -1
  320. package/dist/production/src/mapper/Mapper.js +8 -5
  321. package/dist/production/src/mapper/Mapper.js.map +1 -1
  322. package/dist/production/src/mapper/MapperFactory.cjs +7 -4
  323. package/dist/production/src/mapper/MapperFactory.cjs.map +1 -1
  324. package/dist/production/src/mapper/MapperFactory.js +7 -4
  325. package/dist/production/src/mapper/MapperFactory.js.map +1 -1
  326. package/dist/production/src/mapper/MutationProcessorHelper.cjs.map +1 -1
  327. package/dist/production/src/mapper/MutationProcessorHelper.js.map +1 -1
  328. package/dist/production/src/mapper/Result.cjs.map +1 -1
  329. package/dist/production/src/mapper/Result.js.map +1 -1
  330. package/dist/production/src/mapper/delete/DeleteExecutor.cjs.map +1 -1
  331. package/dist/production/src/mapper/delete/DeleteExecutor.js.map +1 -1
  332. package/dist/production/src/mapper/delete/DeleteState.cjs.map +1 -1
  333. package/dist/production/src/mapper/delete/DeleteState.js.map +1 -1
  334. package/dist/production/src/mapper/insert/InsertBuilder.cjs.map +1 -1
  335. package/dist/production/src/mapper/insert/InsertBuilder.js.map +1 -1
  336. package/dist/production/src/mapper/insert/InsertBuilderFactory.cjs.map +1 -1
  337. package/dist/production/src/mapper/insert/InsertBuilderFactory.js.map +1 -1
  338. package/dist/production/src/mapper/insert/Inserter.cjs.map +1 -1
  339. package/dist/production/src/mapper/insert/Inserter.js.map +1 -1
  340. package/dist/production/src/mapper/insert/SqlCreateInputProcessor.cjs.map +1 -1
  341. package/dist/production/src/mapper/insert/SqlCreateInputProcessor.js.map +1 -1
  342. package/dist/production/src/mapper/insert/relations/ManyHasManyCreateInputProcessor.cjs.map +1 -1
  343. package/dist/production/src/mapper/insert/relations/ManyHasManyCreateInputProcessor.js.map +1 -1
  344. package/dist/production/src/mapper/insert/relations/ManyHasOneCreateInputProcessor.cjs.map +1 -1
  345. package/dist/production/src/mapper/insert/relations/ManyHasOneCreateInputProcessor.js.map +1 -1
  346. package/dist/production/src/mapper/insert/relations/OneHasManyCreateInputProcessor.cjs.map +1 -1
  347. package/dist/production/src/mapper/insert/relations/OneHasManyCreateInputProcessor.js.map +1 -1
  348. package/dist/production/src/mapper/insert/relations/OneHasOneInverseCreateInputProcessor.cjs.map +1 -1
  349. package/dist/production/src/mapper/insert/relations/OneHasOneInverseCreateInputProcessor.js.map +1 -1
  350. package/dist/production/src/mapper/insert/relations/OneHasOneOwningCreateInputProcessor.cjs.map +1 -1
  351. package/dist/production/src/mapper/insert/relations/OneHasOneOwningCreateInputProcessor.js.map +1 -1
  352. package/dist/production/src/mapper/select/ConditionBuilder.cjs +10 -1
  353. package/dist/production/src/mapper/select/ConditionBuilder.cjs.map +1 -1
  354. package/dist/production/src/mapper/select/ConditionBuilder.js +10 -1
  355. package/dist/production/src/mapper/select/ConditionBuilder.js.map +1 -1
  356. package/dist/production/src/mapper/select/JoinBuilder.cjs.map +1 -1
  357. package/dist/production/src/mapper/select/JoinBuilder.js.map +1 -1
  358. package/dist/production/src/mapper/select/JoinVisitor.cjs.map +1 -1
  359. package/dist/production/src/mapper/select/JoinVisitor.js.map +1 -1
  360. package/dist/production/src/mapper/select/OrderByBuilder.cjs.map +1 -1
  361. package/dist/production/src/mapper/select/OrderByBuilder.js.map +1 -1
  362. package/dist/production/src/mapper/select/OrderByHelper.cjs.map +1 -1
  363. package/dist/production/src/mapper/select/OrderByHelper.js.map +1 -1
  364. package/dist/production/src/mapper/select/RelationFetcher.cjs +2 -2
  365. package/dist/production/src/mapper/select/RelationFetcher.cjs.map +1 -1
  366. package/dist/production/src/mapper/select/RelationFetcher.js +2 -2
  367. package/dist/production/src/mapper/select/RelationFetcher.js.map +1 -1
  368. package/dist/production/src/mapper/select/SelectBuilder.cjs.map +1 -1
  369. package/dist/production/src/mapper/select/SelectBuilder.js.map +1 -1
  370. package/dist/production/src/mapper/select/SelectHydrator.cjs +39 -19
  371. package/dist/production/src/mapper/select/SelectHydrator.cjs.map +1 -1
  372. package/dist/production/src/mapper/select/SelectHydrator.js +39 -19
  373. package/dist/production/src/mapper/select/SelectHydrator.js.map +1 -1
  374. package/dist/production/src/mapper/select/WhereBuilder.cjs.map +1 -1
  375. package/dist/production/src/mapper/select/WhereBuilder.js.map +1 -1
  376. package/dist/production/src/mapper/select/handlers/FieldsVisitor.cjs +9 -1
  377. package/dist/production/src/mapper/select/handlers/FieldsVisitor.cjs.map +1 -1
  378. package/dist/production/src/mapper/select/handlers/FieldsVisitor.js +9 -1
  379. package/dist/production/src/mapper/select/handlers/FieldsVisitor.js.map +1 -1
  380. package/dist/production/src/mapper/select/handlers/FieldsVisitorFactory.cjs.map +1 -1
  381. package/dist/production/src/mapper/select/handlers/FieldsVisitorFactory.js.map +1 -1
  382. package/dist/production/src/mapper/select/handlers/MetaHandler.cjs.map +1 -1
  383. package/dist/production/src/mapper/select/handlers/MetaHandler.js.map +1 -1
  384. package/dist/production/src/mapper/select/optimizer/ConditionOptimizer.cjs.map +1 -1
  385. package/dist/production/src/mapper/select/optimizer/ConditionOptimizer.js.map +1 -1
  386. package/dist/production/src/mapper/select/optimizer/WhereOptimizer.cjs.map +1 -1
  387. package/dist/production/src/mapper/select/optimizer/WhereOptimizer.js.map +1 -1
  388. package/dist/production/src/mapper/update/SqlUpdateInputProcessor.cjs.map +1 -1
  389. package/dist/production/src/mapper/update/SqlUpdateInputProcessor.js.map +1 -1
  390. package/dist/production/src/mapper/update/UpdateBuilder.cjs.map +1 -1
  391. package/dist/production/src/mapper/update/UpdateBuilder.js.map +1 -1
  392. package/dist/production/src/mapper/update/UpdateBuilderFactory.cjs.map +1 -1
  393. package/dist/production/src/mapper/update/UpdateBuilderFactory.js.map +1 -1
  394. package/dist/production/src/mapper/update/Updater.cjs.map +1 -1
  395. package/dist/production/src/mapper/update/Updater.js.map +1 -1
  396. package/dist/production/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.cjs.map +1 -1
  397. package/dist/production/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.js.map +1 -1
  398. package/dist/production/src/mapper/update/relations/ManyHasOneUpdateInputProcessor.cjs.map +1 -1
  399. package/dist/production/src/mapper/update/relations/ManyHasOneUpdateInputProcessor.js.map +1 -1
  400. package/dist/production/src/mapper/update/relations/OneHasManyUpdateInputProcessor.cjs.map +1 -1
  401. package/dist/production/src/mapper/update/relations/OneHasManyUpdateInputProcessor.js.map +1 -1
  402. package/dist/production/src/mapper/update/relations/OneHasOneInverseUpdateInputProcessor.cjs.map +1 -1
  403. package/dist/production/src/mapper/update/relations/OneHasOneInverseUpdateInputProcessor.js.map +1 -1
  404. package/dist/production/src/mapper/update/relations/OneHasOneOwningUpdateInputProcessor.cjs.map +1 -1
  405. package/dist/production/src/mapper/update/relations/OneHasOneOwningUpdateInputProcessor.js.map +1 -1
  406. package/dist/production/src/resolvers/GraphQlQueryAstFactory.cjs.map +1 -1
  407. package/dist/production/src/resolvers/GraphQlQueryAstFactory.js.map +1 -1
  408. package/dist/production/src/resolvers/MutationResolver.cjs +49 -35
  409. package/dist/production/src/resolvers/MutationResolver.cjs.map +1 -1
  410. package/dist/production/src/resolvers/MutationResolver.js +50 -36
  411. package/dist/production/src/resolvers/MutationResolver.js.map +1 -1
  412. package/dist/production/src/resolvers/ReadHelpers.cjs.map +1 -1
  413. package/dist/production/src/resolvers/ReadHelpers.js.map +1 -1
  414. package/dist/production/src/resolvers/ReadResolver.cjs.map +1 -1
  415. package/dist/production/src/resolvers/ReadResolver.js.map +1 -1
  416. package/dist/production/src/resolvers/RefreshViewResolver.cjs.map +1 -1
  417. package/dist/production/src/resolvers/RefreshViewResolver.js.map +1 -1
  418. package/dist/production/src/resolvers/ValidationResolver.cjs.map +1 -1
  419. package/dist/production/src/resolvers/ValidationResolver.js.map +1 -1
  420. package/dist/production/src/schema/ColumnTypeResolver.cjs +2 -0
  421. package/dist/production/src/schema/ColumnTypeResolver.cjs.map +1 -1
  422. package/dist/production/src/schema/ColumnTypeResolver.js +2 -0
  423. package/dist/production/src/schema/ColumnTypeResolver.js.map +1 -1
  424. package/dist/production/src/schema/ConditionTypeProvider.cjs +2 -0
  425. package/dist/production/src/schema/ConditionTypeProvider.cjs.map +1 -1
  426. package/dist/production/src/schema/ConditionTypeProvider.js +2 -0
  427. package/dist/production/src/schema/ConditionTypeProvider.js.map +1 -1
  428. package/dist/production/src/schema/CustomTypesProvider.cjs +32 -0
  429. package/dist/production/src/schema/CustomTypesProvider.cjs.map +1 -1
  430. package/dist/production/src/schema/CustomTypesProvider.js +32 -0
  431. package/dist/production/src/schema/CustomTypesProvider.js.map +1 -1
  432. package/dist/production/src/schema/EntityTypeProvider.cjs.map +1 -1
  433. package/dist/production/src/schema/EntityTypeProvider.js.map +1 -1
  434. package/dist/production/src/schema/EnumsProvider.cjs.map +1 -1
  435. package/dist/production/src/schema/EnumsProvider.js.map +1 -1
  436. package/dist/production/src/schema/FieldAccessVisitor.cjs.map +1 -1
  437. package/dist/production/src/schema/FieldAccessVisitor.js.map +1 -1
  438. package/dist/production/src/schema/GraphQlSchemaBuilder.cjs.map +1 -1
  439. package/dist/production/src/schema/GraphQlSchemaBuilder.js.map +1 -1
  440. package/dist/production/src/schema/GraphQlSchemaBuilderFactory.cjs.map +1 -1
  441. package/dist/production/src/schema/GraphQlSchemaBuilderFactory.js.map +1 -1
  442. package/dist/production/src/schema/MutationProvider.cjs.map +1 -1
  443. package/dist/production/src/schema/MutationProvider.js.map +1 -1
  444. package/dist/production/src/schema/OperationExtension.cjs.map +1 -1
  445. package/dist/production/src/schema/OperationExtension.js.map +1 -1
  446. package/dist/production/src/schema/OrderByTypeProvider.cjs.map +1 -1
  447. package/dist/production/src/schema/OrderByTypeProvider.js.map +1 -1
  448. package/dist/production/src/schema/PaginatedFieldConfigFactory.cjs.map +1 -1
  449. package/dist/production/src/schema/PaginatedFieldConfigFactory.js.map +1 -1
  450. package/dist/production/src/schema/QueryProvider.cjs.map +1 -1
  451. package/dist/production/src/schema/QueryProvider.js.map +1 -1
  452. package/dist/production/src/schema/RefreshViewMutationProvider.cjs.map +1 -1
  453. package/dist/production/src/schema/RefreshViewMutationProvider.js.map +1 -1
  454. package/dist/production/src/schema/ValidationQueriesProvider.cjs.map +1 -1
  455. package/dist/production/src/schema/ValidationQueriesProvider.js.map +1 -1
  456. package/dist/production/src/schema/WhereTypeProvider.cjs.map +1 -1
  457. package/dist/production/src/schema/WhereTypeProvider.js.map +1 -1
  458. package/dist/production/src/schema/entities/FieldArgsVisitor.cjs.map +1 -1
  459. package/dist/production/src/schema/entities/FieldArgsVisitor.js.map +1 -1
  460. package/dist/production/src/schema/entities/FieldTypeVisitor.cjs.map +1 -1
  461. package/dist/production/src/schema/entities/FieldTypeVisitor.js.map +1 -1
  462. package/dist/production/src/schema/mutations/ConnectOrCreateRelationInputProvider.cjs.map +1 -1
  463. package/dist/production/src/schema/mutations/ConnectOrCreateRelationInputProvider.js.map +1 -1
  464. package/dist/production/src/schema/mutations/CreateEntityInputFieldVisitor.cjs.map +1 -1
  465. package/dist/production/src/schema/mutations/CreateEntityInputFieldVisitor.js.map +1 -1
  466. package/dist/production/src/schema/mutations/CreateEntityRelationAllowedOperationsVisitor.cjs.map +1 -1
  467. package/dist/production/src/schema/mutations/CreateEntityRelationAllowedOperationsVisitor.js.map +1 -1
  468. package/dist/production/src/schema/mutations/CreateEntityRelationInputFieldVisitor.cjs.map +1 -1
  469. package/dist/production/src/schema/mutations/CreateEntityRelationInputFieldVisitor.js.map +1 -1
  470. package/dist/production/src/schema/mutations/CreateEntityRelationInputProvider.cjs.map +1 -1
  471. package/dist/production/src/schema/mutations/CreateEntityRelationInputProvider.js.map +1 -1
  472. package/dist/production/src/schema/mutations/EntityInputProvider.cjs.map +1 -1
  473. package/dist/production/src/schema/mutations/EntityInputProvider.js.map +1 -1
  474. package/dist/production/src/schema/mutations/UpdateEntityInputFieldVisitor.cjs.map +1 -1
  475. package/dist/production/src/schema/mutations/UpdateEntityInputFieldVisitor.js.map +1 -1
  476. package/dist/production/src/schema/mutations/UpdateEntityRelationAllowedOperationsVisitor.cjs.map +1 -1
  477. package/dist/production/src/schema/mutations/UpdateEntityRelationAllowedOperationsVisitor.js.map +1 -1
  478. package/dist/production/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.cjs.map +1 -1
  479. package/dist/production/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.js.map +1 -1
  480. package/dist/production/src/schema/mutations/UpdateEntityRelationInputProvider.cjs.map +1 -1
  481. package/dist/production/src/schema/mutations/UpdateEntityRelationInputProvider.js.map +1 -1
  482. package/dist/production/src/schema/utils.cjs.map +1 -1
  483. package/dist/production/src/schema/utils.js.map +1 -1
  484. package/dist/production/src/utils/accessor.cjs.map +1 -1
  485. package/dist/production/src/utils/accessor.js.map +1 -1
  486. package/dist/production/src/utils/paginationUtils.cjs.map +1 -1
  487. package/dist/production/src/utils/paginationUtils.js.map +1 -1
  488. package/dist/production/src/utils/singletonFactory.cjs.map +1 -1
  489. package/dist/production/src/utils/singletonFactory.js.map +1 -1
  490. package/dist/tests/cases/integration/graphQlRequests/insert/memoryBudget.test.d.ts +2 -0
  491. package/dist/tests/cases/integration/graphQlRequests/insert/memoryBudget.test.d.ts.map +1 -0
  492. package/dist/tests/cases/integration/graphQlRequests/insert/numericColumn.test.d.ts +2 -0
  493. package/dist/tests/cases/integration/graphQlRequests/insert/numericColumn.test.d.ts.map +1 -0
  494. package/dist/tests/cases/integration/graphQlRequests/query/filter/numericFilter.test.d.ts +2 -0
  495. package/dist/tests/cases/integration/graphQlRequests/query/filter/numericFilter.test.d.ts.map +1 -0
  496. package/dist/tests/cases/integration/graphQlRequests/query/filter/similarQuery.test.d.ts +2 -0
  497. package/dist/tests/cases/integration/graphQlRequests/query/filter/similarQuery.test.d.ts.map +1 -0
  498. package/dist/tests/cases/integration/graphQlRequests/query/formatting/numericFormat.test.d.ts +2 -0
  499. package/dist/tests/cases/integration/graphQlRequests/query/formatting/numericFormat.test.d.ts.map +1 -0
  500. package/dist/tests/cases/integration/graphQlRequests/query/formatting/numericList.test.d.ts +2 -0
  501. package/dist/tests/cases/integration/graphQlRequests/query/formatting/numericList.test.d.ts.map +1 -0
  502. package/dist/tests/cases/integration/graphQlRequests/validation/utils.d.ts +1 -1
  503. package/dist/tests/cases/integration/graphQlRequests/validation/utils.d.ts.map +1 -1
  504. package/dist/tests/cases/integration/graphQlSchema/model.d.ts +1 -1
  505. package/dist/tests/cases/unit/decimalType.test.d.ts +2 -0
  506. package/dist/tests/cases/unit/decimalType.test.d.ts.map +1 -0
  507. package/dist/tests/cases/unit/jsonSchemaValidator.test.d.ts +2 -0
  508. package/dist/tests/cases/unit/jsonSchemaValidator.test.d.ts.map +1 -0
  509. package/dist/tests/src/assert.d.ts.map +1 -1
  510. package/dist/tests/src/tags.d.ts.map +1 -1
  511. package/dist/tests/src/test.d.ts +4 -1
  512. package/dist/tests/src/test.d.ts.map +1 -1
  513. package/dist/tests/src/testGraphql.d.ts.map +1 -1
  514. package/dist/tests/src/testUuid.d.ts.map +1 -1
  515. package/dist/tests/tsconfig.tsbuildinfo +1 -1
  516. package/dist/types/ExecutionContainer.d.ts +14 -13
  517. package/dist/types/ExecutionContainer.d.ts.map +1 -1
  518. package/dist/types/acl/Authorizator.d.ts.map +1 -1
  519. package/dist/types/acl/EvaluatedPredicateReplacer.d.ts.map +1 -1
  520. package/dist/types/acl/PermissionFactory.d.ts.map +1 -1
  521. package/dist/types/acl/PredicateFactory.d.ts +1 -1
  522. package/dist/types/acl/PredicateFactory.d.ts.map +1 -1
  523. package/dist/types/acl/PredicatesInjector.d.ts +1 -1
  524. package/dist/types/acl/PredicatesInjector.d.ts.map +1 -1
  525. package/dist/types/acl/VariableInjector.d.ts.map +1 -1
  526. package/dist/types/acl/VariableUtils.d.ts.map +1 -1
  527. package/dist/types/acl/index.d.ts +6 -6
  528. package/dist/types/acl/index.d.ts.map +1 -1
  529. package/dist/types/exception.d.ts.map +1 -1
  530. package/dist/types/extensions/hasManyToHasOneReducer/HasManyToHasOneReducer.d.ts +2 -2
  531. package/dist/types/extensions/hasManyToHasOneReducer/HasManyToHasOneReducer.d.ts.map +1 -1
  532. package/dist/types/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.d.ts +3 -3
  533. package/dist/types/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.d.ts.map +1 -1
  534. package/dist/types/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.d.ts +3 -3
  535. package/dist/types/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.d.ts.map +1 -1
  536. package/dist/types/extensions/hasManyToHasOneReducer/index.d.ts +3 -3
  537. package/dist/types/extensions/hasManyToHasOneReducer/index.d.ts.map +1 -1
  538. package/dist/types/extensions/index.d.ts +2 -2
  539. package/dist/types/extensions/index.d.ts.map +1 -1
  540. package/dist/types/extensions/paginatedHasMany/PaginatedHasManyCountVisitor.d.ts +2 -2
  541. package/dist/types/extensions/paginatedHasMany/PaginatedHasManyCountVisitor.d.ts.map +1 -1
  542. package/dist/types/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.d.ts +2 -2
  543. package/dist/types/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.d.ts.map +1 -1
  544. package/dist/types/extensions/paginatedHasMany/PaginatedHasManyFieldProvider.d.ts +2 -2
  545. package/dist/types/extensions/paginatedHasMany/PaginatedHasManyFieldProvider.d.ts.map +1 -1
  546. package/dist/types/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.d.ts +2 -2
  547. package/dist/types/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.d.ts.map +1 -1
  548. package/dist/types/extensions/paginatedHasMany/PaginatedHasManyNodesVisitor.d.ts +2 -2
  549. package/dist/types/extensions/paginatedHasMany/PaginatedHasManyNodesVisitor.d.ts.map +1 -1
  550. package/dist/types/index.d.ts +11 -11
  551. package/dist/types/index.d.ts.map +1 -1
  552. package/dist/types/input-validation/ColumnValueResolver.d.ts.map +1 -1
  553. package/dist/types/input-validation/EntityRulesResolver.d.ts.map +1 -1
  554. package/dist/types/input-validation/InputValidator.d.ts +1 -1
  555. package/dist/types/input-validation/InputValidator.d.ts.map +1 -1
  556. package/dist/types/input-validation/JsonSchemaValidator.d.ts +25 -0
  557. package/dist/types/input-validation/JsonSchemaValidator.d.ts.map +1 -0
  558. package/dist/types/input-validation/QueryAstFactory.d.ts +2 -2
  559. package/dist/types/input-validation/QueryAstFactory.d.ts.map +1 -1
  560. package/dist/types/input-validation/ValidationContext.d.ts.map +1 -1
  561. package/dist/types/input-validation/ValidationDataSelector.d.ts +4 -4
  562. package/dist/types/input-validation/ValidationDataSelector.d.ts.map +1 -1
  563. package/dist/types/input-validation/ValidationEvaluation.d.ts +1 -1
  564. package/dist/types/input-validation/ValidationEvaluation.d.ts.map +1 -1
  565. package/dist/types/input-validation/ValidationPath.d.ts.map +1 -1
  566. package/dist/types/input-validation/dependencies/DependencyCollector.d.ts.map +1 -1
  567. package/dist/types/input-validation/dependencies/DependencyMerger.d.ts +1 -1
  568. package/dist/types/input-validation/dependencies/DependencyMerger.d.ts.map +1 -1
  569. package/dist/types/input-validation/dependencies/index.d.ts +2 -2
  570. package/dist/types/input-validation/dependencies/index.d.ts.map +1 -1
  571. package/dist/types/input-validation/index.d.ts +12 -11
  572. package/dist/types/input-validation/index.d.ts.map +1 -1
  573. package/dist/types/input-validation/preValidation/CreateInputPreValidationProcessor.d.ts +5 -5
  574. package/dist/types/input-validation/preValidation/CreateInputPreValidationProcessor.d.ts.map +1 -1
  575. package/dist/types/input-validation/preValidation/InputPreValidator.d.ts +11 -6
  576. package/dist/types/input-validation/preValidation/InputPreValidator.d.ts.map +1 -1
  577. package/dist/types/input-validation/preValidation/UpdateInputPreValidationProcessor.d.ts +7 -7
  578. package/dist/types/input-validation/preValidation/UpdateInputPreValidationProcessor.d.ts.map +1 -1
  579. package/dist/types/input-validation/preValidation/index.d.ts +3 -3
  580. package/dist/types/input-validation/preValidation/index.d.ts.map +1 -1
  581. package/dist/types/inputProcessing/CreateInputProcessor.d.ts +2 -2
  582. package/dist/types/inputProcessing/CreateInputProcessor.d.ts.map +1 -1
  583. package/dist/types/inputProcessing/CreateInputVisitor.d.ts +2 -2
  584. package/dist/types/inputProcessing/CreateInputVisitor.d.ts.map +1 -1
  585. package/dist/types/inputProcessing/FieldNode.d.ts.map +1 -1
  586. package/dist/types/inputProcessing/ObjectNode.d.ts +1 -1
  587. package/dist/types/inputProcessing/ObjectNode.d.ts.map +1 -1
  588. package/dist/types/inputProcessing/UniqueWhereExpander.d.ts +2 -2
  589. package/dist/types/inputProcessing/UniqueWhereExpander.d.ts.map +1 -1
  590. package/dist/types/inputProcessing/UpdateInputProcessor.d.ts +2 -2
  591. package/dist/types/inputProcessing/UpdateInputProcessor.d.ts.map +1 -1
  592. package/dist/types/inputProcessing/UpdateInputVisitor.d.ts +2 -2
  593. package/dist/types/inputProcessing/UpdateInputVisitor.d.ts.map +1 -1
  594. package/dist/types/inputProcessing/index.d.ts +7 -7
  595. package/dist/types/inputProcessing/index.d.ts.map +1 -1
  596. package/dist/types/introspection/IntrospectionSchemaDefinitionFactory.d.ts +1 -1
  597. package/dist/types/introspection/IntrospectionSchemaDefinitionFactory.d.ts.map +1 -1
  598. package/dist/types/introspection/IntrospectionSchemaFactory.d.ts +3 -3
  599. package/dist/types/introspection/IntrospectionSchemaFactory.d.ts.map +1 -1
  600. package/dist/types/introspection/index.d.ts +4 -4
  601. package/dist/types/introspection/index.d.ts.map +1 -1
  602. package/dist/types/introspection/introspection.schema.d.ts.map +1 -1
  603. package/dist/types/mapper/CheckedPrimary.d.ts.map +1 -1
  604. package/dist/types/mapper/ColumnValue.d.ts.map +1 -1
  605. package/dist/types/mapper/Constraints.d.ts.map +1 -1
  606. package/dist/types/mapper/ErrorUtils.d.ts +1 -1
  607. package/dist/types/mapper/ErrorUtils.d.ts.map +1 -1
  608. package/dist/types/mapper/EventManager.d.ts +11 -11
  609. package/dist/types/mapper/EventManager.d.ts.map +1 -1
  610. package/dist/types/mapper/JunctionTableManager.d.ts +4 -4
  611. package/dist/types/mapper/JunctionTableManager.d.ts.map +1 -1
  612. package/dist/types/mapper/Mapper.d.ts +17 -14
  613. package/dist/types/mapper/Mapper.d.ts.map +1 -1
  614. package/dist/types/mapper/MapperFactory.d.ts +11 -10
  615. package/dist/types/mapper/MapperFactory.d.ts.map +1 -1
  616. package/dist/types/mapper/MutationProcessorHelper.d.ts +1 -1
  617. package/dist/types/mapper/MutationProcessorHelper.d.ts.map +1 -1
  618. package/dist/types/mapper/Result.d.ts +1 -1
  619. package/dist/types/mapper/Result.d.ts.map +1 -1
  620. package/dist/types/mapper/delete/DeleteExecutor.d.ts +6 -6
  621. package/dist/types/mapper/delete/DeleteExecutor.d.ts.map +1 -1
  622. package/dist/types/mapper/delete/DeleteState.d.ts +2 -2
  623. package/dist/types/mapper/delete/DeleteState.d.ts.map +1 -1
  624. package/dist/types/mapper/delete/DeletedEntitiesStorage.d.ts.map +1 -1
  625. package/dist/types/mapper/delete/helpers.d.ts +1 -1
  626. package/dist/types/mapper/delete/helpers.d.ts.map +1 -1
  627. package/dist/types/mapper/delete/index.d.ts +2 -2
  628. package/dist/types/mapper/delete/index.d.ts.map +1 -1
  629. package/dist/types/mapper/index.d.ts +15 -15
  630. package/dist/types/mapper/index.d.ts.map +1 -1
  631. package/dist/types/mapper/insert/InsertBuilder.d.ts +4 -4
  632. package/dist/types/mapper/insert/InsertBuilder.d.ts.map +1 -1
  633. package/dist/types/mapper/insert/InsertBuilderFactory.d.ts +3 -3
  634. package/dist/types/mapper/insert/InsertBuilderFactory.d.ts.map +1 -1
  635. package/dist/types/mapper/insert/Inserter.d.ts +5 -5
  636. package/dist/types/mapper/insert/Inserter.d.ts.map +1 -1
  637. package/dist/types/mapper/insert/SqlCreateInputProcessor.d.ts +4 -4
  638. package/dist/types/mapper/insert/SqlCreateInputProcessor.d.ts.map +1 -1
  639. package/dist/types/mapper/insert/index.d.ts +4 -4
  640. package/dist/types/mapper/insert/index.d.ts.map +1 -1
  641. package/dist/types/mapper/insert/relations/ManyHasManyCreateInputProcessor.d.ts +7 -7
  642. package/dist/types/mapper/insert/relations/ManyHasManyCreateInputProcessor.d.ts.map +1 -1
  643. package/dist/types/mapper/insert/relations/ManyHasOneCreateInputProcessor.d.ts +9 -9
  644. package/dist/types/mapper/insert/relations/ManyHasOneCreateInputProcessor.d.ts.map +1 -1
  645. package/dist/types/mapper/insert/relations/OneHasManyCreateInputProcessor.d.ts +8 -8
  646. package/dist/types/mapper/insert/relations/OneHasManyCreateInputProcessor.d.ts.map +1 -1
  647. package/dist/types/mapper/insert/relations/OneHasOneInverseCreateInputProcessor.d.ts +8 -8
  648. package/dist/types/mapper/insert/relations/OneHasOneInverseCreateInputProcessor.d.ts.map +1 -1
  649. package/dist/types/mapper/insert/relations/OneHasOneOwningCreateInputProcessor.d.ts +7 -7
  650. package/dist/types/mapper/insert/relations/OneHasOneOwningCreateInputProcessor.d.ts.map +1 -1
  651. package/dist/types/mapper/select/ConditionBuilder.d.ts.map +1 -1
  652. package/dist/types/mapper/select/JoinBuilder.d.ts +1 -1
  653. package/dist/types/mapper/select/JoinBuilder.d.ts.map +1 -1
  654. package/dist/types/mapper/select/JoinVisitor.d.ts +1 -1
  655. package/dist/types/mapper/select/JoinVisitor.d.ts.map +1 -1
  656. package/dist/types/mapper/select/OrderByBuilder.d.ts +2 -2
  657. package/dist/types/mapper/select/OrderByBuilder.d.ts.map +1 -1
  658. package/dist/types/mapper/select/OrderByHelper.d.ts +1 -1
  659. package/dist/types/mapper/select/OrderByHelper.d.ts.map +1 -1
  660. package/dist/types/mapper/select/Path.d.ts.map +1 -1
  661. package/dist/types/mapper/select/RelationFetcher.d.ts +7 -7
  662. package/dist/types/mapper/select/RelationFetcher.d.ts.map +1 -1
  663. package/dist/types/mapper/select/SelectBuilder.d.ts +10 -10
  664. package/dist/types/mapper/select/SelectBuilder.d.ts.map +1 -1
  665. package/dist/types/mapper/select/SelectBuilderFactory.d.ts +2 -2
  666. package/dist/types/mapper/select/SelectBuilderFactory.d.ts.map +1 -1
  667. package/dist/types/mapper/select/SelectExecutionHandler.d.ts +4 -4
  668. package/dist/types/mapper/select/SelectExecutionHandler.d.ts.map +1 -1
  669. package/dist/types/mapper/select/SelectHydrator.d.ts +7 -1
  670. package/dist/types/mapper/select/SelectHydrator.d.ts.map +1 -1
  671. package/dist/types/mapper/select/WhereBuilder.d.ts +4 -4
  672. package/dist/types/mapper/select/WhereBuilder.d.ts.map +1 -1
  673. package/dist/types/mapper/select/handlers/FieldsVisitor.d.ts +4 -4
  674. package/dist/types/mapper/select/handlers/FieldsVisitor.d.ts.map +1 -1
  675. package/dist/types/mapper/select/handlers/FieldsVisitorFactory.d.ts +5 -5
  676. package/dist/types/mapper/select/handlers/FieldsVisitorFactory.d.ts.map +1 -1
  677. package/dist/types/mapper/select/handlers/MetaHandler.d.ts +3 -3
  678. package/dist/types/mapper/select/handlers/MetaHandler.d.ts.map +1 -1
  679. package/dist/types/mapper/select/handlers/index.d.ts +3 -3
  680. package/dist/types/mapper/select/handlers/index.d.ts.map +1 -1
  681. package/dist/types/mapper/select/index.d.ts +13 -13
  682. package/dist/types/mapper/select/index.d.ts.map +1 -1
  683. package/dist/types/mapper/select/optimizer/ConditionOptimizer.d.ts.map +1 -1
  684. package/dist/types/mapper/select/optimizer/WhereOptimizer.d.ts +1 -1
  685. package/dist/types/mapper/select/optimizer/WhereOptimizer.d.ts.map +1 -1
  686. package/dist/types/mapper/select/optimizer/WhereReplacer.d.ts.map +1 -1
  687. package/dist/types/mapper/select/optimizer/helpers.d.ts +1 -1
  688. package/dist/types/mapper/select/optimizer/helpers.d.ts.map +1 -1
  689. package/dist/types/mapper/types.d.ts +1 -1
  690. package/dist/types/mapper/types.d.ts.map +1 -1
  691. package/dist/types/mapper/update/SqlUpdateInputProcessor.d.ts +5 -5
  692. package/dist/types/mapper/update/SqlUpdateInputProcessor.d.ts.map +1 -1
  693. package/dist/types/mapper/update/UpdateBuilder.d.ts +4 -4
  694. package/dist/types/mapper/update/UpdateBuilder.d.ts.map +1 -1
  695. package/dist/types/mapper/update/UpdateBuilderFactory.d.ts +3 -3
  696. package/dist/types/mapper/update/UpdateBuilderFactory.d.ts.map +1 -1
  697. package/dist/types/mapper/update/Updater.d.ts +5 -5
  698. package/dist/types/mapper/update/Updater.d.ts.map +1 -1
  699. package/dist/types/mapper/update/index.d.ts +4 -4
  700. package/dist/types/mapper/update/index.d.ts.map +1 -1
  701. package/dist/types/mapper/update/relations/ManyHasManyUpdateInputProcessor.d.ts +12 -12
  702. package/dist/types/mapper/update/relations/ManyHasManyUpdateInputProcessor.d.ts.map +1 -1
  703. package/dist/types/mapper/update/relations/ManyHasOneUpdateInputProcessor.d.ts +12 -12
  704. package/dist/types/mapper/update/relations/ManyHasOneUpdateInputProcessor.d.ts.map +1 -1
  705. package/dist/types/mapper/update/relations/OneHasManyUpdateInputProcessor.d.ts +12 -12
  706. package/dist/types/mapper/update/relations/OneHasManyUpdateInputProcessor.d.ts.map +1 -1
  707. package/dist/types/mapper/update/relations/OneHasOneInverseUpdateInputProcessor.d.ts +6 -6
  708. package/dist/types/mapper/update/relations/OneHasOneInverseUpdateInputProcessor.d.ts.map +1 -1
  709. package/dist/types/mapper/update/relations/OneHasOneOwningUpdateInputProcessor.d.ts +10 -10
  710. package/dist/types/mapper/update/relations/OneHasOneOwningUpdateInputProcessor.d.ts.map +1 -1
  711. package/dist/types/resolvers/GraphQlQueryAstFactory.d.ts +1 -1
  712. package/dist/types/resolvers/GraphQlQueryAstFactory.d.ts.map +1 -1
  713. package/dist/types/resolvers/MutationResolver.d.ts +3 -3
  714. package/dist/types/resolvers/MutationResolver.d.ts.map +1 -1
  715. package/dist/types/resolvers/ReadHelpers.d.ts +2 -2
  716. package/dist/types/resolvers/ReadHelpers.d.ts.map +1 -1
  717. package/dist/types/resolvers/ReadResolver.d.ts +4 -4
  718. package/dist/types/resolvers/ReadResolver.d.ts.map +1 -1
  719. package/dist/types/resolvers/RefreshViewResolver.d.ts +1 -1
  720. package/dist/types/resolvers/RefreshViewResolver.d.ts.map +1 -1
  721. package/dist/types/resolvers/ValidationResolver.d.ts +2 -2
  722. package/dist/types/resolvers/ValidationResolver.d.ts.map +1 -1
  723. package/dist/types/resolvers/index.d.ts +4 -4
  724. package/dist/types/resolvers/index.d.ts.map +1 -1
  725. package/dist/types/schema/ColumnTypeResolver.d.ts +2 -2
  726. package/dist/types/schema/ColumnTypeResolver.d.ts.map +1 -1
  727. package/dist/types/schema/ConditionTypeProvider.d.ts +1 -1
  728. package/dist/types/schema/ConditionTypeProvider.d.ts.map +1 -1
  729. package/dist/types/schema/CustomTypesProvider.d.ts +1 -0
  730. package/dist/types/schema/CustomTypesProvider.d.ts.map +1 -1
  731. package/dist/types/schema/EntityTypeProvider.d.ts +5 -5
  732. package/dist/types/schema/EntityTypeProvider.d.ts.map +1 -1
  733. package/dist/types/schema/EnumsProvider.d.ts.map +1 -1
  734. package/dist/types/schema/FieldAccessVisitor.d.ts +1 -1
  735. package/dist/types/schema/FieldAccessVisitor.d.ts.map +1 -1
  736. package/dist/types/schema/GraphQlSchemaBuilder.d.ts +6 -6
  737. package/dist/types/schema/GraphQlSchemaBuilder.d.ts.map +1 -1
  738. package/dist/types/schema/GraphQlSchemaBuilderFactory.d.ts +30 -30
  739. package/dist/types/schema/GraphQlSchemaBuilderFactory.d.ts.map +1 -1
  740. package/dist/types/schema/MutationProvider.d.ts +6 -6
  741. package/dist/types/schema/MutationProvider.d.ts.map +1 -1
  742. package/dist/types/schema/OperationExtension.d.ts.map +1 -1
  743. package/dist/types/schema/OrderByTypeProvider.d.ts +1 -1
  744. package/dist/types/schema/OrderByTypeProvider.d.ts.map +1 -1
  745. package/dist/types/schema/PaginatedFieldConfigFactory.d.ts +3 -3
  746. package/dist/types/schema/PaginatedFieldConfigFactory.d.ts.map +1 -1
  747. package/dist/types/schema/QueryProvider.d.ts +6 -6
  748. package/dist/types/schema/QueryProvider.d.ts.map +1 -1
  749. package/dist/types/schema/RefreshViewMutationProvider.d.ts +2 -2
  750. package/dist/types/schema/RefreshViewMutationProvider.d.ts.map +1 -1
  751. package/dist/types/schema/ValidationQueriesProvider.d.ts +4 -4
  752. package/dist/types/schema/ValidationQueriesProvider.d.ts.map +1 -1
  753. package/dist/types/schema/WhereTypeProvider.d.ts +3 -3
  754. package/dist/types/schema/WhereTypeProvider.d.ts.map +1 -1
  755. package/dist/types/schema/entities/FieldArgsVisitor.d.ts +2 -2
  756. package/dist/types/schema/entities/FieldArgsVisitor.d.ts.map +1 -1
  757. package/dist/types/schema/entities/FieldTypeVisitor.d.ts +3 -3
  758. package/dist/types/schema/entities/FieldTypeVisitor.d.ts.map +1 -1
  759. package/dist/types/schema/entities/index.d.ts +2 -2
  760. package/dist/types/schema/entities/index.d.ts.map +1 -1
  761. package/dist/types/schema/index.d.ts +18 -18
  762. package/dist/types/schema/index.d.ts.map +1 -1
  763. package/dist/types/schema/mutations/ConnectOrCreateRelationInputProvider.d.ts +3 -3
  764. package/dist/types/schema/mutations/ConnectOrCreateRelationInputProvider.d.ts.map +1 -1
  765. package/dist/types/schema/mutations/CreateEntityInputFieldVisitor.d.ts +3 -3
  766. package/dist/types/schema/mutations/CreateEntityInputFieldVisitor.d.ts.map +1 -1
  767. package/dist/types/schema/mutations/CreateEntityRelationAllowedOperationsVisitor.d.ts +1 -1
  768. package/dist/types/schema/mutations/CreateEntityRelationAllowedOperationsVisitor.d.ts.map +1 -1
  769. package/dist/types/schema/mutations/CreateEntityRelationInputFieldVisitor.d.ts +5 -5
  770. package/dist/types/schema/mutations/CreateEntityRelationInputFieldVisitor.d.ts.map +1 -1
  771. package/dist/types/schema/mutations/CreateEntityRelationInputProvider.d.ts +1 -1
  772. package/dist/types/schema/mutations/CreateEntityRelationInputProvider.d.ts.map +1 -1
  773. package/dist/types/schema/mutations/EntityInputProvider.d.ts +1 -1
  774. package/dist/types/schema/mutations/EntityInputProvider.d.ts.map +1 -1
  775. package/dist/types/schema/mutations/UpdateEntityInputFieldVisitor.d.ts +4 -4
  776. package/dist/types/schema/mutations/UpdateEntityInputFieldVisitor.d.ts.map +1 -1
  777. package/dist/types/schema/mutations/UpdateEntityRelationAllowedOperationsVisitor.d.ts +1 -1
  778. package/dist/types/schema/mutations/UpdateEntityRelationAllowedOperationsVisitor.d.ts.map +1 -1
  779. package/dist/types/schema/mutations/UpdateEntityRelationInputFieldVisitor.d.ts +6 -6
  780. package/dist/types/schema/mutations/UpdateEntityRelationInputFieldVisitor.d.ts.map +1 -1
  781. package/dist/types/schema/mutations/UpdateEntityRelationInputProvider.d.ts +1 -1
  782. package/dist/types/schema/mutations/UpdateEntityRelationInputProvider.d.ts.map +1 -1
  783. package/dist/types/schema/mutations/index.d.ts +9 -9
  784. package/dist/types/schema/mutations/index.d.ts.map +1 -1
  785. package/dist/types/schema/utils.d.ts.map +1 -1
  786. package/dist/types/tsconfig.tsbuildinfo +1 -1
  787. package/dist/types/types.d.ts +1 -1
  788. package/dist/types/types.d.ts.map +1 -1
  789. package/dist/types/utils/Mutex.d.ts.map +1 -1
  790. package/dist/types/utils/ResolveInfoUtils.d.ts.map +1 -1
  791. package/dist/types/utils/accessor.d.ts +1 -1
  792. package/dist/types/utils/accessor.d.ts.map +1 -1
  793. package/dist/types/utils/index.d.ts +13 -13
  794. package/dist/types/utils/index.d.ts.map +1 -1
  795. package/dist/types/utils/isIt.d.ts.map +1 -1
  796. package/dist/types/utils/paginationUtils.d.ts +1 -1
  797. package/dist/types/utils/paginationUtils.d.ts.map +1 -1
  798. package/dist/types/utils/promises.d.ts.map +1 -1
  799. package/dist/types/utils/singletonFactory.d.ts.map +1 -1
  800. package/dist/types/utils/strings.d.ts.map +1 -1
  801. package/dist/types/utils/tuple.d.ts.map +1 -1
  802. package/dist/types/utils/uniqueWhereFields.d.ts.map +1 -1
  803. package/dist/types/utils/viewComputedId.d.ts.map +1 -1
  804. package/package.json +9 -9
  805. package/src/ExecutionContainer.ts +27 -14
  806. package/src/acl/EvaluatedPredicateReplacer.ts +1 -1
  807. package/src/acl/PermissionFactory.ts +2 -2
  808. package/src/acl/PredicateFactory.ts +2 -2
  809. package/src/acl/PredicatesInjector.ts +1 -1
  810. package/src/acl/index.ts +6 -6
  811. package/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducer.ts +2 -2
  812. package/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.ts +5 -5
  813. package/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.ts +4 -4
  814. package/src/extensions/hasManyToHasOneReducer/index.ts +3 -3
  815. package/src/extensions/index.ts +2 -2
  816. package/src/extensions/paginatedHasMany/PaginatedHasManyCountVisitor.ts +2 -2
  817. package/src/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.ts +5 -5
  818. package/src/extensions/paginatedHasMany/PaginatedHasManyFieldProvider.ts +2 -2
  819. package/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.ts +4 -4
  820. package/src/extensions/paginatedHasMany/PaginatedHasManyNodesVisitor.ts +2 -2
  821. package/src/index.ts +11 -11
  822. package/src/input-validation/EntityRulesResolver.ts +3 -3
  823. package/src/input-validation/InputValidator.ts +1 -1
  824. package/src/input-validation/JsonSchemaValidator.ts +257 -0
  825. package/src/input-validation/QueryAstFactory.ts +2 -2
  826. package/src/input-validation/ValidationContext.ts +1 -1
  827. package/src/input-validation/ValidationDataSelector.ts +3 -3
  828. package/src/input-validation/ValidationEvaluation.ts +1 -1
  829. package/src/input-validation/dependencies/DependencyCollector.ts +1 -1
  830. package/src/input-validation/dependencies/DependencyMerger.ts +2 -2
  831. package/src/input-validation/dependencies/index.ts +2 -2
  832. package/src/input-validation/index.ts +12 -11
  833. package/src/input-validation/preValidation/CreateInputPreValidationProcessor.ts +4 -4
  834. package/src/input-validation/preValidation/InputPreValidator.ts +60 -17
  835. package/src/input-validation/preValidation/UpdateInputPreValidationProcessor.ts +4 -4
  836. package/src/input-validation/preValidation/index.ts +3 -3
  837. package/src/inputProcessing/CreateInputProcessor.ts +2 -2
  838. package/src/inputProcessing/CreateInputVisitor.ts +4 -4
  839. package/src/inputProcessing/ObjectNode.ts +1 -1
  840. package/src/inputProcessing/UniqueWhereExpander.ts +3 -3
  841. package/src/inputProcessing/UpdateInputProcessor.ts +2 -2
  842. package/src/inputProcessing/UpdateInputVisitor.ts +4 -4
  843. package/src/inputProcessing/index.ts +7 -7
  844. package/src/introspection/IntrospectionSchemaDefinitionFactory.ts +3 -3
  845. package/src/introspection/IntrospectionSchemaFactory.ts +4 -4
  846. package/src/introspection/index.ts +4 -4
  847. package/src/mapper/ErrorUtils.ts +2 -2
  848. package/src/mapper/EventManager.ts +2 -2
  849. package/src/mapper/JunctionTableManager.ts +6 -6
  850. package/src/mapper/Mapper.ts +23 -19
  851. package/src/mapper/MapperFactory.ts +15 -11
  852. package/src/mapper/MutationProcessorHelper.ts +1 -1
  853. package/src/mapper/Result.ts +1 -1
  854. package/src/mapper/delete/DeleteExecutor.ts +11 -11
  855. package/src/mapper/delete/DeleteState.ts +3 -3
  856. package/src/mapper/delete/index.ts +2 -2
  857. package/src/mapper/index.ts +15 -15
  858. package/src/mapper/insert/InsertBuilder.ts +5 -5
  859. package/src/mapper/insert/InsertBuilderFactory.ts +3 -3
  860. package/src/mapper/insert/Inserter.ts +8 -8
  861. package/src/mapper/insert/SqlCreateInputProcessor.ts +10 -10
  862. package/src/mapper/insert/index.ts +4 -4
  863. package/src/mapper/insert/relations/ManyHasManyCreateInputProcessor.ts +6 -6
  864. package/src/mapper/insert/relations/ManyHasOneCreateInputProcessor.ts +7 -7
  865. package/src/mapper/insert/relations/OneHasManyCreateInputProcessor.ts +5 -5
  866. package/src/mapper/insert/relations/OneHasOneInverseCreateInputProcessor.ts +6 -6
  867. package/src/mapper/insert/relations/OneHasOneOwningCreateInputProcessor.ts +7 -7
  868. package/src/mapper/select/ConditionBuilder.ts +15 -2
  869. package/src/mapper/select/JoinBuilder.ts +2 -2
  870. package/src/mapper/select/JoinVisitor.ts +1 -1
  871. package/src/mapper/select/OrderByBuilder.ts +3 -3
  872. package/src/mapper/select/OrderByHelper.ts +1 -1
  873. package/src/mapper/select/RelationFetcher.ts +11 -13
  874. package/src/mapper/select/SelectBuilder.ts +11 -11
  875. package/src/mapper/select/SelectBuilderFactory.ts +2 -2
  876. package/src/mapper/select/SelectExecutionHandler.ts +4 -4
  877. package/src/mapper/select/SelectHydrator.ts +45 -18
  878. package/src/mapper/select/WhereBuilder.ts +5 -5
  879. package/src/mapper/select/handlers/FieldsVisitor.ts +22 -7
  880. package/src/mapper/select/handlers/FieldsVisitorFactory.ts +5 -5
  881. package/src/mapper/select/handlers/MetaHandler.ts +5 -5
  882. package/src/mapper/select/handlers/index.ts +3 -3
  883. package/src/mapper/select/index.ts +13 -13
  884. package/src/mapper/select/optimizer/ConditionOptimizer.ts +1 -1
  885. package/src/mapper/select/optimizer/WhereOptimizer.ts +3 -3
  886. package/src/mapper/types.ts +1 -1
  887. package/src/mapper/update/SqlUpdateInputProcessor.ts +11 -11
  888. package/src/mapper/update/UpdateBuilder.ts +6 -6
  889. package/src/mapper/update/UpdateBuilderFactory.ts +3 -3
  890. package/src/mapper/update/Updater.ts +8 -8
  891. package/src/mapper/update/index.ts +4 -4
  892. package/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.ts +6 -6
  893. package/src/mapper/update/relations/ManyHasOneUpdateInputProcessor.ts +7 -7
  894. package/src/mapper/update/relations/OneHasManyUpdateInputProcessor.ts +6 -6
  895. package/src/mapper/update/relations/OneHasOneInverseUpdateInputProcessor.ts +6 -6
  896. package/src/mapper/update/relations/OneHasOneOwningUpdateInputProcessor.ts +7 -7
  897. package/src/resolvers/GraphQlQueryAstFactory.ts +2 -2
  898. package/src/resolvers/MutationResolver.ts +68 -45
  899. package/src/resolvers/ReadHelpers.ts +5 -5
  900. package/src/resolvers/ReadResolver.ts +4 -4
  901. package/src/resolvers/RefreshViewResolver.ts +1 -1
  902. package/src/resolvers/ValidationResolver.ts +3 -3
  903. package/src/resolvers/index.ts +4 -4
  904. package/src/schema/ColumnTypeResolver.ts +6 -4
  905. package/src/schema/ConditionTypeProvider.ts +7 -4
  906. package/src/schema/CustomTypesProvider.ts +37 -0
  907. package/src/schema/EntityTypeProvider.ts +10 -10
  908. package/src/schema/EnumsProvider.ts +1 -1
  909. package/src/schema/FieldAccessVisitor.ts +1 -1
  910. package/src/schema/GraphQlSchemaBuilder.ts +6 -6
  911. package/src/schema/GraphQlSchemaBuilderFactory.ts +30 -30
  912. package/src/schema/MutationProvider.ts +9 -9
  913. package/src/schema/OperationExtension.ts +1 -1
  914. package/src/schema/OrderByTypeProvider.ts +4 -4
  915. package/src/schema/PaginatedFieldConfigFactory.ts +3 -3
  916. package/src/schema/QueryProvider.ts +8 -8
  917. package/src/schema/RefreshViewMutationProvider.ts +2 -2
  918. package/src/schema/ValidationQueriesProvider.ts +5 -5
  919. package/src/schema/WhereTypeProvider.ts +7 -7
  920. package/src/schema/entities/FieldArgsVisitor.ts +2 -2
  921. package/src/schema/entities/FieldTypeVisitor.ts +4 -4
  922. package/src/schema/entities/index.ts +2 -2
  923. package/src/schema/index.ts +18 -18
  924. package/src/schema/mutations/ConnectOrCreateRelationInputProvider.ts +5 -5
  925. package/src/schema/mutations/CreateEntityInputFieldVisitor.ts +3 -3
  926. package/src/schema/mutations/CreateEntityRelationAllowedOperationsVisitor.ts +2 -2
  927. package/src/schema/mutations/CreateEntityRelationInputFieldVisitor.ts +7 -7
  928. package/src/schema/mutations/CreateEntityRelationInputProvider.ts +2 -2
  929. package/src/schema/mutations/EntityInputProvider.ts +4 -4
  930. package/src/schema/mutations/UpdateEntityInputFieldVisitor.ts +3 -3
  931. package/src/schema/mutations/UpdateEntityRelationAllowedOperationsVisitor.ts +1 -1
  932. package/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.ts +8 -8
  933. package/src/schema/mutations/UpdateEntityRelationInputProvider.ts +2 -2
  934. package/src/schema/mutations/index.ts +9 -9
  935. package/src/schema/utils.ts +1 -1
  936. package/src/types.ts +1 -1
  937. package/src/utils/accessor.ts +2 -2
  938. package/src/utils/index.ts +13 -13
  939. package/src/utils/paginationUtils.ts +1 -1
  940. package/src/utils/singletonFactory.ts +1 -1
  941. package/tests/cases/bugs/bug-filter-or.test.ts +3 -3
  942. package/tests/cases/bugs/bug-update-by-nested-unique.test.ts +3 -3
  943. package/tests/cases/bugs/bug102.test.ts +3 -3
  944. package/tests/cases/integration/graphQlRequests/delete/aclDelete.test.ts +3 -3
  945. package/tests/cases/integration/graphQlRequests/delete/additionalDeleteFilter.test.ts +3 -3
  946. package/tests/cases/integration/graphQlRequests/delete/cascadeDelete.test.ts +3 -3
  947. package/tests/cases/integration/graphQlRequests/delete/deleteById.test.ts +3 -3
  948. package/tests/cases/integration/graphQlRequests/delete/orphanRemoval.test.ts +3 -3
  949. package/tests/cases/integration/graphQlRequests/delete/restrictOnDelete.test.ts +3 -3
  950. package/tests/cases/integration/graphQlRequests/delete/setNullOnDelete.test.ts +3 -3
  951. package/tests/cases/integration/graphQlRequests/insert/acl/setField.test.ts +3 -3
  952. package/tests/cases/integration/graphQlRequests/insert/aclInsert.test.ts +3 -3
  953. package/tests/cases/integration/graphQlRequests/insert/basicInsert.test.ts +3 -3
  954. package/tests/cases/integration/graphQlRequests/insert/insertCustomId.test.ts +3 -3
  955. package/tests/cases/integration/graphQlRequests/insert/jsonInsert.test.ts +3 -3
  956. package/tests/cases/integration/graphQlRequests/insert/manyHasManyInverse/create.test.ts +3 -3
  957. package/tests/cases/integration/graphQlRequests/insert/manyHasManyOwning/create.test.ts +3 -3
  958. package/tests/cases/integration/graphQlRequests/insert/manyHasOne/connectOrCreate.test.ts +3 -3
  959. package/tests/cases/integration/graphQlRequests/insert/manyHasOne/create.test.ts +3 -3
  960. package/tests/cases/integration/graphQlRequests/insert/memoryBudget.test.ts +97 -0
  961. package/tests/cases/integration/graphQlRequests/insert/numericColumn.test.ts +110 -0
  962. package/tests/cases/integration/graphQlRequests/insert/oneHasMany/connect.test.ts +3 -3
  963. package/tests/cases/integration/graphQlRequests/insert/oneHasMany/create.test.ts +3 -3
  964. package/tests/cases/integration/graphQlRequests/insert/oneHasOneInverse/create.test.ts +3 -3
  965. package/tests/cases/integration/graphQlRequests/insert/oneHasOneOwning/create.test.ts +3 -3
  966. package/tests/cases/integration/graphQlRequests/insert/oneHasOneOwning/empty.test.ts +3 -3
  967. package/tests/cases/integration/graphQlRequests/insert/subOperationFail.test.ts +3 -3
  968. package/tests/cases/integration/graphQlRequests/insert/validation/toBeFixed.test.ts +3 -3
  969. package/tests/cases/integration/graphQlRequests/query/acl/differentRowAndFieldPredicate.test.ts +3 -3
  970. package/tests/cases/integration/graphQlRequests/query/acl/fieldRestrictedByLocale.test.ts +3 -3
  971. package/tests/cases/integration/graphQlRequests/query/acl/isNullAcl.test.ts +4 -4
  972. package/tests/cases/integration/graphQlRequests/query/acl/nestedPredicate.test.ts +3 -3
  973. package/tests/cases/integration/graphQlRequests/query/acl/orPredicate.test.ts +3 -3
  974. package/tests/cases/integration/graphQlRequests/query/acl/predicateElimination.test.ts +4 -4
  975. package/tests/cases/integration/graphQlRequests/query/acl/relationAcl.test.ts +4 -4
  976. package/tests/cases/integration/graphQlRequests/query/acl/rowPredicateSubset.test.ts +4 -4
  977. package/tests/cases/integration/graphQlRequests/query/acl/sameRowAndFieldPredicate.test.ts +3 -3
  978. package/tests/cases/integration/graphQlRequests/query/filter/backReferencedFilter.test.ts +3 -3
  979. package/tests/cases/integration/graphQlRequests/query/filter/complexCondition.test.ts +3 -3
  980. package/tests/cases/integration/graphQlRequests/query/filter/composedFilter.test.ts +3 -3
  981. package/tests/cases/integration/graphQlRequests/query/filter/containsQuery.test.ts +3 -3
  982. package/tests/cases/integration/graphQlRequests/query/filter/manyHasManyOwnerRelation.test.ts +3 -3
  983. package/tests/cases/integration/graphQlRequests/query/filter/manyHasOneRelation.test.ts +3 -3
  984. package/tests/cases/integration/graphQlRequests/query/filter/numericFilter.test.ts +92 -0
  985. package/tests/cases/integration/graphQlRequests/query/filter/oneHasManyRelation.test.ts +3 -3
  986. package/tests/cases/integration/graphQlRequests/query/filter/similarQuery.test.ts +72 -0
  987. package/tests/cases/integration/graphQlRequests/query/formatting/dateFormat.test.ts +135 -4
  988. package/tests/cases/integration/graphQlRequests/query/formatting/numericFormat.test.ts +68 -0
  989. package/tests/cases/integration/graphQlRequests/query/formatting/numericList.test.ts +41 -0
  990. package/tests/cases/integration/graphQlRequests/query/graphqlFeatures/alias.test.ts +3 -3
  991. package/tests/cases/integration/graphQlRequests/query/graphqlFeatures/fragments.test.ts +3 -3
  992. package/tests/cases/integration/graphQlRequests/query/misc/aliasedType.test.ts +3 -3
  993. package/tests/cases/integration/graphQlRequests/query/misc/longAliasHash.test.ts +3 -3
  994. package/tests/cases/integration/graphQlRequests/query/misc/reducedHasMany.test.ts +3 -3
  995. package/tests/cases/integration/graphQlRequests/query/misc/transaction.test.ts +3 -3
  996. package/tests/cases/integration/graphQlRequests/query/pagination/hasManyLimit.test.ts +51 -5
  997. package/tests/cases/integration/graphQlRequests/query/pagination/paginate.test.ts +3 -3
  998. package/tests/cases/integration/graphQlRequests/query/pagination/paginateAliased.test.ts +3 -3
  999. package/tests/cases/integration/graphQlRequests/query/pagination/simpleLimit.test.ts +3 -3
  1000. package/tests/cases/integration/graphQlRequests/query/relations/advanced.test.ts +3 -3
  1001. package/tests/cases/integration/graphQlRequests/query/relations/manyHasManyInverse.test.ts +3 -3
  1002. package/tests/cases/integration/graphQlRequests/query/relations/manyHasManyOwning.test.ts +3 -3
  1003. package/tests/cases/integration/graphQlRequests/query/relations/manyHasOne.test.ts +3 -3
  1004. package/tests/cases/integration/graphQlRequests/query/relations/oneHasMany.test.ts +6 -6
  1005. package/tests/cases/integration/graphQlRequests/query/relations/oneHasOneInverse.test.ts +3 -3
  1006. package/tests/cases/integration/graphQlRequests/query/relations/oneHasOneOwner.test.ts +3 -3
  1007. package/tests/cases/integration/graphQlRequests/query/sorting/byRelations.test.ts +3 -3
  1008. package/tests/cases/integration/graphQlRequests/query/sorting/defaultOrdering.test.ts +3 -3
  1009. package/tests/cases/integration/graphQlRequests/query/sorting/orderBy.test.ts +3 -3
  1010. package/tests/cases/integration/graphQlRequests/query/sorting/randomSort.test.ts +4 -4
  1011. package/tests/cases/integration/graphQlRequests/query/sorting/sortNulls.test.ts +2 -2
  1012. package/tests/cases/integration/graphQlRequests/query/sorting/sortedHasMany.test.ts +3 -3
  1013. package/tests/cases/integration/graphQlRequests/query/unique/basicQueryById.test.ts +3 -3
  1014. package/tests/cases/integration/graphQlRequests/query/unique/composedUnique.test.ts +3 -3
  1015. package/tests/cases/integration/graphQlRequests/query/unique/oneHasManyUnique.test.ts +3 -3
  1016. package/tests/cases/integration/graphQlRequests/query/unique/uniqueWithFilter.test.ts +3 -3
  1017. package/tests/cases/integration/graphQlRequests/query/view/view.test.ts +3 -3
  1018. package/tests/cases/integration/graphQlRequests/update/acl/aclUpdate.test.ts +3 -3
  1019. package/tests/cases/integration/graphQlRequests/update/additionalFilter.test.ts +3 -3
  1020. package/tests/cases/integration/graphQlRequests/update/basic/columnUpdate.test.ts +3 -3
  1021. package/tests/cases/integration/graphQlRequests/update/manyHasManyInverse/connect.test.ts +4 -4
  1022. package/tests/cases/integration/graphQlRequests/update/manyHasManyInverse/create.test.ts +4 -4
  1023. package/tests/cases/integration/graphQlRequests/update/manyHasManyInverse/delete.test.ts +4 -4
  1024. package/tests/cases/integration/graphQlRequests/update/manyHasManyInverse/disconnect.test.ts +4 -4
  1025. package/tests/cases/integration/graphQlRequests/update/manyHasManyInverse/update.test.ts +4 -4
  1026. package/tests/cases/integration/graphQlRequests/update/manyHasManyInverse/upsert.test.ts +4 -4
  1027. package/tests/cases/integration/graphQlRequests/update/manyHasManyOwning/connect.test.ts +4 -4
  1028. package/tests/cases/integration/graphQlRequests/update/manyHasManyOwning/connectOrCreate.test.ts +4 -4
  1029. package/tests/cases/integration/graphQlRequests/update/manyHasManyOwning/create.test.ts +4 -4
  1030. package/tests/cases/integration/graphQlRequests/update/manyHasManyOwning/delete.test.ts +4 -4
  1031. package/tests/cases/integration/graphQlRequests/update/manyHasManyOwning/disconnect.test.ts +4 -4
  1032. package/tests/cases/integration/graphQlRequests/update/manyHasManyOwning/update.test.ts +4 -4
  1033. package/tests/cases/integration/graphQlRequests/update/manyHasManyOwning/upsert.test.ts +4 -4
  1034. package/tests/cases/integration/graphQlRequests/update/manyHasOne/connect.test.ts +4 -4
  1035. package/tests/cases/integration/graphQlRequests/update/manyHasOne/create.test.ts +4 -4
  1036. package/tests/cases/integration/graphQlRequests/update/manyHasOne/delete.test.ts +4 -4
  1037. package/tests/cases/integration/graphQlRequests/update/manyHasOne/disconnect.test.ts +4 -4
  1038. package/tests/cases/integration/graphQlRequests/update/manyHasOne/update.test.ts +4 -4
  1039. package/tests/cases/integration/graphQlRequests/update/manyHasOne/upsert.test.ts +4 -4
  1040. package/tests/cases/integration/graphQlRequests/update/oneHasMany/combination.test.ts +4 -4
  1041. package/tests/cases/integration/graphQlRequests/update/oneHasMany/connect.test.ts +4 -4
  1042. package/tests/cases/integration/graphQlRequests/update/oneHasMany/connectOrCreate.test.ts +4 -4
  1043. package/tests/cases/integration/graphQlRequests/update/oneHasMany/create.test.ts +4 -4
  1044. package/tests/cases/integration/graphQlRequests/update/oneHasMany/delete.test.ts +4 -4
  1045. package/tests/cases/integration/graphQlRequests/update/oneHasMany/disconnect.test.ts +4 -4
  1046. package/tests/cases/integration/graphQlRequests/update/oneHasMany/update.test.ts +4 -4
  1047. package/tests/cases/integration/graphQlRequests/update/oneHasMany/upsert.test.ts +4 -4
  1048. package/tests/cases/integration/graphQlRequests/update/oneHasOneInverse/connect.test.ts +4 -4
  1049. package/tests/cases/integration/graphQlRequests/update/oneHasOneInverse/create.test.ts +4 -4
  1050. package/tests/cases/integration/graphQlRequests/update/oneHasOneInverse/delete.test.ts +4 -4
  1051. package/tests/cases/integration/graphQlRequests/update/oneHasOneInverse/disconnect.test.ts +4 -4
  1052. package/tests/cases/integration/graphQlRequests/update/oneHasOneInverse/update.test.ts +4 -4
  1053. package/tests/cases/integration/graphQlRequests/update/oneHasOneInverse/upsert.test.ts +4 -4
  1054. package/tests/cases/integration/graphQlRequests/update/oneHasOneOwning/connect.test.ts +4 -4
  1055. package/tests/cases/integration/graphQlRequests/update/oneHasOneOwning/connectOrCreate.test.ts +4 -4
  1056. package/tests/cases/integration/graphQlRequests/update/oneHasOneOwning/create.test.ts +4 -4
  1057. package/tests/cases/integration/graphQlRequests/update/oneHasOneOwning/delete.test.ts +4 -4
  1058. package/tests/cases/integration/graphQlRequests/update/oneHasOneOwning/disconnect.test.ts +4 -4
  1059. package/tests/cases/integration/graphQlRequests/update/oneHasOneOwning/update.test.ts +4 -4
  1060. package/tests/cases/integration/graphQlRequests/update/oneHasOneOwning/upsert.test.ts +4 -4
  1061. package/tests/cases/integration/graphQlRequests/update/queryPortal.test.ts +3 -3
  1062. package/tests/cases/integration/graphQlRequests/update/transaction.test.ts +3 -3
  1063. package/tests/cases/integration/graphQlRequests/update/validation/toBeFixed.test.ts +3 -3
  1064. package/tests/cases/integration/graphQlRequests/upsert/basicUpsert.test.ts +3 -3
  1065. package/tests/cases/integration/graphQlRequests/validation/conditions.test.ts +1 -1
  1066. package/tests/cases/integration/graphQlRequests/validation/nestedValidation.test.ts +2 -2
  1067. package/tests/cases/integration/graphQlRequests/validation/optionalAssert.test.ts +2 -2
  1068. package/tests/cases/integration/graphQlRequests/validation/required.test.ts +2 -2
  1069. package/tests/cases/integration/graphQlRequests/validation/requiredWhen.test.ts +2 -2
  1070. package/tests/cases/integration/graphQlRequests/validation/rules/andRule.test.ts +1 -1
  1071. package/tests/cases/integration/graphQlRequests/validation/rules/lengthRangeRule.test.ts +1 -1
  1072. package/tests/cases/integration/graphQlRequests/validation/rules/maxLengthRule.test.ts +1 -1
  1073. package/tests/cases/integration/graphQlRequests/validation/rules/minLength.test.ts +1 -1
  1074. package/tests/cases/integration/graphQlRequests/validation/rules/notEmptyRule.test.ts +1 -1
  1075. package/tests/cases/integration/graphQlRequests/validation/rules/notRule.test.ts +1 -1
  1076. package/tests/cases/integration/graphQlRequests/validation/rules/orRule.test.ts +1 -1
  1077. package/tests/cases/integration/graphQlRequests/validation/rules/patternRule.test.ts +1 -1
  1078. package/tests/cases/integration/graphQlRequests/validation/rules/rangeRule.test.ts +1 -1
  1079. package/tests/cases/integration/graphQlRequests/validation/utils.ts +2 -2
  1080. package/tests/cases/integration/graphQlSchema/graphQlSchemaBuilder.test.ts +2 -2
  1081. package/tests/cases/integration/graphQlSchema/schema-acl-allowed.gql +3 -0
  1082. package/tests/cases/integration/graphQlSchema/schema-acl-create-only.gql +1 -0
  1083. package/tests/cases/integration/graphQlSchema/schema-acl-predicate.gql +2 -0
  1084. package/tests/cases/integration/graphQlSchema/schema-acl-predicate2.gql +2 -0
  1085. package/tests/cases/integration/graphQlSchema/schema-acl-restricted-create.gql +3 -0
  1086. package/tests/cases/integration/graphQlSchema/schema-acl-restricted-delete.gql +3 -0
  1087. package/tests/cases/integration/graphQlSchema/schema-acl-restricted-update.gql +3 -0
  1088. package/tests/cases/integration/graphQlSchema/schema-acl.gql +3 -0
  1089. package/tests/cases/integration/graphQlSchema/schema-aliased-type.gql +3 -0
  1090. package/tests/cases/integration/graphQlSchema/schema-array.gql +1 -0
  1091. package/tests/cases/integration/graphQlSchema/schema-basic.gql +3 -0
  1092. package/tests/cases/integration/graphQlSchema/schema-bug-66.gql +3 -0
  1093. package/tests/cases/integration/graphQlSchema/schema-column-types.gql +3 -0
  1094. package/tests/cases/integration/graphQlSchema/schema-custom-primary.gql +3 -0
  1095. package/tests/cases/integration/graphQlSchema/schema-has-many-reduction.gql +3 -0
  1096. package/tests/cases/integration/graphQlSchema/schema-new-builder.gql +3 -0
  1097. package/tests/cases/integration/graphQlSchema/schema-no-root-ops.gql +3 -0
  1098. package/tests/cases/integration/graphQlSchema/schema-read-only.gql +2 -0
  1099. package/tests/cases/integration/graphQlSchema/schema-view-entity.gql +2 -0
  1100. package/tests/cases/unit/aclVariablesFactory.test.ts +2 -2
  1101. package/tests/cases/unit/conditionOptimizer.test.ts +1 -1
  1102. package/tests/cases/unit/decimalType.test.ts +65 -0
  1103. package/tests/cases/unit/inputPreValidator.test.ts +101 -6
  1104. package/tests/cases/unit/inputValidation.test.ts +3 -3
  1105. package/tests/cases/unit/jsonSchemaValidator.test.ts +115 -0
  1106. package/tests/cases/unit/orderbyHelper.test.ts +3 -3
  1107. package/tests/cases/unit/permissionMerger.test.ts +2 -2
  1108. package/tests/cases/unit/predicatesFactory.test.ts +2 -2
  1109. package/tests/cases/unit/predicatesInjector.test.ts +5 -5
  1110. package/tests/cases/unit/uuidType.test.ts +1 -1
  1111. package/tests/cases/unit/variableInjector.test.ts +2 -2
  1112. package/tests/cases/unit/whereBuilder.test.ts +4 -4
  1113. package/tests/cases/unit/whereOptimizer.test.ts +3 -3
  1114. package/tests/src/test.ts +9 -6
@@ -1 +1 @@
1
- {"version":3,"file":"EventManager.js","sources":["../../../../../packages/engine-content-api/src/mapper/EventManager.ts"],"sourcesContent":["import { Input, Model, Value } from '@contember/schema'\nimport { Mapper } from './Mapper'\nimport { ColumnValue } from './ColumnValue'\n\nexport class BeforeInsertEvent {\n\tpublic type = 'BeforeInsertEvent' as const\n\n\tpublic afterEvent: AfterInsertEvent | undefined = undefined\n\n\tconstructor(\n\t\tpublic readonly entity: Model.Entity,\n\t\tpublic readonly data: ColumnValue[],\n\t) {\n\t}\n}\n\nexport class AfterInsertEvent {\n\tpublic type = 'AfterInsertEvent' as const\n\n\tconstructor(\n\t\tpublic readonly entity: Model.Entity,\n\t\tpublic readonly data: ColumnValue[],\n\t\tpublic readonly id: Input.PrimaryValue,\n\t) {\n\t}\n}\n\nexport class BeforeUpdateEvent {\n\tpublic type = 'BeforeUpdateEvent' as const\n\n\tpublic afterEvent: AfterUpdateEvent | undefined = undefined\n\n\tconstructor(\n\t\tpublic readonly entity: Model.Entity,\n\t\tpublic readonly data: ColumnValue[],\n\t\tpublic readonly id: Input.PrimaryValue,\n\t) {\n\t}\n}\n\nexport class AfterUpdateEvent {\n\tpublic type = 'AfterUpdateEvent' as const\n\n\tprivate _hasChanges: boolean | undefined\n\n\tconstructor(\n\t\tpublic readonly entity: Model.Entity,\n\t\tpublic readonly data: (ColumnValue & { old: Value.FieldValue })[],\n\t\tpublic readonly id: Input.PrimaryValue,\n\t) {\n\t}\n\tget hasChanges() {\n\t\t// todo: deep equals\n\t\treturn this._hasChanges = this.data.some(it => it.value !== it.old)\n\t}\n}\n\nexport class BeforeDeleteEvent {\n\tpublic type = 'BeforeDeleteEvent' as const\n\n\tconstructor(\n\t\tpublic readonly entity: Model.Entity,\n\t\tpublic readonly id: Input.PrimaryValue,\n\t) {\n\t}\n}\n\nexport class BeforeJunctionUpdateEvent {\n\tpublic type = 'BeforeJunctionUpdateEvent' as const\n\n\tpublic afterEvent: AfterJunctionUpdateEvent | undefined = undefined\n\n\tconstructor(\n\t\tpublic readonly owningEntity: Model.Entity,\n\t\tpublic readonly owningRelation: Model.ManyHasManyOwningRelation,\n\t\tpublic readonly owningId: Input.PrimaryValue,\n\t\tpublic readonly inverseId: Input.PrimaryValue,\n\t\tpublic readonly operation: 'connect' | 'disconnect',\n\t) {\n\t}\n}\n\nexport class AfterJunctionUpdateEvent {\n\tpublic type = 'AfterJunctionUpdateEvent' as const\n\n\tconstructor(\n\t\tpublic readonly owningEntity: Model.Entity,\n\t\tpublic readonly owningRelation: Model.ManyHasManyOwningRelation,\n\t\tpublic readonly owningId: Input.PrimaryValue,\n\t\tpublic readonly inverseId: Input.PrimaryValue,\n\t\tpublic readonly operation: 'connect' | 'disconnect',\n\t\tpublic readonly hasChanges: boolean,\n\t) {\n\t}\n}\n\nexport class BeforeCommitEvent {\n\tpublic type = 'BeforeCommitEvent' as const\n}\n\nexport class AfterCommitEvent {\n\tpublic type = 'AfterCommitEvent' as const\n}\n\nexport type DataModificationEvent =\n\t| BeforeInsertEvent\n\t| AfterInsertEvent\n\t| BeforeUpdateEvent\n\t| AfterUpdateEvent\n\t| BeforeJunctionUpdateEvent\n\t| AfterJunctionUpdateEvent\n\t| BeforeDeleteEvent\n\nexport type AnyEvent =\n\t| DataModificationEvent\n\t| BeforeCommitEvent\n\t| AfterCommitEvent\n\nexport type EventMap<E extends AnyEvent = AnyEvent> = {\n\t[K in E['type']]: E extends { type: K } ? E : never\n}\n\nexport type EventListener<K extends keyof EventMap> = (event: EventMap[K], mapper: Mapper) => Promise<void>\n\nexport class EventManager {\n\tprivate listeners: { [K in keyof EventMap]: EventListener<K>[] } = {\n\t\tBeforeInsertEvent: [],\n\t\tAfterInsertEvent: [],\n\t\tBeforeUpdateEvent: [],\n\t\tAfterUpdateEvent: [],\n\t\tBeforeDeleteEvent: [],\n\t\tBeforeCommitEvent: [],\n\t\tAfterCommitEvent: [],\n\t\tBeforeJunctionUpdateEvent: [],\n\t\tAfterJunctionUpdateEvent: [],\n\t}\n\n\tconstructor(\n\t\tprivate readonly mapper: Mapper,\n\t) {\n\t}\n\n\tpublic listen<K extends keyof EventMap>(type: K, cb: EventListener<K>) {\n\t\tthis.listeners[type].push(cb)\n\t}\n\n\tpublic async fire<K extends keyof EventMap>(event: EventMap[K]) {\n\t\tfor (const listener of this.listeners[event.type]) {\n\t\t\tawait listener(event, this.mapper)\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;;AAIO,MAAM,kBAAkB;AAAA,EAK9B,YACiB,QACA,MACf;AAFe,SAAA,SAAA;AACA,SAAA,OAAA;AANjB,kBAAA,MAAO,QAAO,mBAAA;AAEd,kBAAA,MAAO,YAAA;AAAA,EAMP;AACD;AAEO,MAAM,iBAAiB;AAAA,EAG7B,YACiB,QACA,MACA,IACf;AAHe,SAAA,SAAA;AACA,SAAA,OAAA;AACA,SAAA,KAAA;AALjB,kBAAA,MAAO,QAAO,kBAAA;AAAA,EAOd;AACD;AAEO,MAAM,kBAAkB;AAAA,EAK9B,YACiB,QACA,MACA,IACf;AAHe,SAAA,SAAA;AACA,SAAA,OAAA;AACA,SAAA,KAAA;AAPjB,kBAAA,MAAO,QAAO,mBAAA;AAEd,kBAAA,MAAO,YAAA;AAAA,EAOP;AACD;AAEO,MAAM,iBAAiB;AAAA,EAK7B,YACiB,QACA,MACA,IACf;AAHe,SAAA,SAAA;AACA,SAAA,OAAA;AACA,SAAA,KAAA;AAPjB,kBAAA,MAAO,QAAO,kBAAA;AAEd,kBAAA,MAAQ,aAAA;AAAA,EAOR;AAAA,EACA,IAAI,aAAa;AAEhB,WAAO,KAAK,cAAc,KAAK,KAAK,KAAK,CAAA,OAAM,GAAG,UAAU,GAAG,GAAG;AAAA,EACnE;AACD;AAEO,MAAM,kBAAkB;AAAA,EAG9B,YACiB,QACA,IACf;AAFe,SAAA,SAAA;AACA,SAAA,KAAA;AAJjB,kBAAA,MAAO,QAAO,mBAAA;AAAA,EAMd;AACD;AAEO,MAAM,0BAA0B;AAAA,EAKtC,YACiB,cACA,gBACA,UACA,WACA,WACf;AALe,SAAA,eAAA;AACA,SAAA,iBAAA;AACA,SAAA,WAAA;AACA,SAAA,YAAA;AACA,SAAA,YAAA;AATjB,kBAAA,MAAO,QAAO,2BAAA;AAEd,kBAAA,MAAO,YAAA;AAAA,EASP;AACD;AAEO,MAAM,yBAAyB;AAAA,EAGrC,YACiB,cACA,gBACA,UACA,WACA,WACA,YACf;AANe,SAAA,eAAA;AACA,SAAA,iBAAA;AACA,SAAA,WAAA;AACA,SAAA,YAAA;AACA,SAAA,YAAA;AACA,SAAA,aAAA;AARjB,kBAAA,MAAO,QAAO,0BAAA;AAAA,EAUd;AACD;AAEO,MAAM,kBAAkB;AAAA,EAAxB,cAAA;AACN,kBAAA,MAAO,QAAO,mBAAA;AAAA,EAAA;AACf;AAEO,MAAM,iBAAiB;AAAA,EAAvB,cAAA;AACN,kBAAA,MAAO,QAAO,kBAAA;AAAA,EAAA;AACf;AAsBO,MAAM,aAAa;AAAA,EAazB,YACkB,QAChB;AADgB,SAAA,SAAA;AAblB,kBAAA,MAAQ,aAA2D;AAAA,MAClE,mBAAmB,CAAA;AAAA,MACnB,kBAAkB,CAAA;AAAA,MAClB,mBAAmB,CAAA;AAAA,MACnB,kBAAkB,CAAA;AAAA,MAClB,mBAAmB,CAAA;AAAA,MACnB,mBAAmB,CAAA;AAAA,MACnB,kBAAkB,CAAA;AAAA,MAClB,2BAA2B,CAAA;AAAA,MAC3B,0BAA0B,CAAA;AAAA,IAAC,CAC5B;AAAA,EAKA;AAAA,EAEO,OAAiC,MAAS,IAAsB;AACtE,SAAK,UAAU,IAAI,EAAE,KAAK,EAAE;AAAA,EAC7B;AAAA,EAEA,MAAa,KAA+B,OAAoB;AAC/D,eAAW,YAAY,KAAK,UAAU,MAAM,IAAI,GAAG;AAClD,YAAM,SAAS,OAAO,KAAK,MAAM;AAAA,IAClC;AAAA,EACD;AACD;"}
1
+ {"version":3,"file":"EventManager.js","sources":["../../../../../packages/engine-content-api/src/mapper/EventManager.ts"],"sourcesContent":["import { Input, Model, Value } from '@contember/schema'\nimport { Mapper } from './Mapper.js'\nimport { ColumnValue } from './ColumnValue.js'\n\nexport class BeforeInsertEvent {\n\tpublic type = 'BeforeInsertEvent' as const\n\n\tpublic afterEvent: AfterInsertEvent | undefined = undefined\n\n\tconstructor(\n\t\tpublic readonly entity: Model.Entity,\n\t\tpublic readonly data: ColumnValue[],\n\t) {\n\t}\n}\n\nexport class AfterInsertEvent {\n\tpublic type = 'AfterInsertEvent' as const\n\n\tconstructor(\n\t\tpublic readonly entity: Model.Entity,\n\t\tpublic readonly data: ColumnValue[],\n\t\tpublic readonly id: Input.PrimaryValue,\n\t) {\n\t}\n}\n\nexport class BeforeUpdateEvent {\n\tpublic type = 'BeforeUpdateEvent' as const\n\n\tpublic afterEvent: AfterUpdateEvent | undefined = undefined\n\n\tconstructor(\n\t\tpublic readonly entity: Model.Entity,\n\t\tpublic readonly data: ColumnValue[],\n\t\tpublic readonly id: Input.PrimaryValue,\n\t) {\n\t}\n}\n\nexport class AfterUpdateEvent {\n\tpublic type = 'AfterUpdateEvent' as const\n\n\tprivate _hasChanges: boolean | undefined\n\n\tconstructor(\n\t\tpublic readonly entity: Model.Entity,\n\t\tpublic readonly data: (ColumnValue & { old: Value.FieldValue })[],\n\t\tpublic readonly id: Input.PrimaryValue,\n\t) {\n\t}\n\tget hasChanges() {\n\t\t// todo: deep equals\n\t\treturn this._hasChanges = this.data.some(it => it.value !== it.old)\n\t}\n}\n\nexport class BeforeDeleteEvent {\n\tpublic type = 'BeforeDeleteEvent' as const\n\n\tconstructor(\n\t\tpublic readonly entity: Model.Entity,\n\t\tpublic readonly id: Input.PrimaryValue,\n\t) {\n\t}\n}\n\nexport class BeforeJunctionUpdateEvent {\n\tpublic type = 'BeforeJunctionUpdateEvent' as const\n\n\tpublic afterEvent: AfterJunctionUpdateEvent | undefined = undefined\n\n\tconstructor(\n\t\tpublic readonly owningEntity: Model.Entity,\n\t\tpublic readonly owningRelation: Model.ManyHasManyOwningRelation,\n\t\tpublic readonly owningId: Input.PrimaryValue,\n\t\tpublic readonly inverseId: Input.PrimaryValue,\n\t\tpublic readonly operation: 'connect' | 'disconnect',\n\t) {\n\t}\n}\n\nexport class AfterJunctionUpdateEvent {\n\tpublic type = 'AfterJunctionUpdateEvent' as const\n\n\tconstructor(\n\t\tpublic readonly owningEntity: Model.Entity,\n\t\tpublic readonly owningRelation: Model.ManyHasManyOwningRelation,\n\t\tpublic readonly owningId: Input.PrimaryValue,\n\t\tpublic readonly inverseId: Input.PrimaryValue,\n\t\tpublic readonly operation: 'connect' | 'disconnect',\n\t\tpublic readonly hasChanges: boolean,\n\t) {\n\t}\n}\n\nexport class BeforeCommitEvent {\n\tpublic type = 'BeforeCommitEvent' as const\n}\n\nexport class AfterCommitEvent {\n\tpublic type = 'AfterCommitEvent' as const\n}\n\nexport type DataModificationEvent =\n\t| BeforeInsertEvent\n\t| AfterInsertEvent\n\t| BeforeUpdateEvent\n\t| AfterUpdateEvent\n\t| BeforeJunctionUpdateEvent\n\t| AfterJunctionUpdateEvent\n\t| BeforeDeleteEvent\n\nexport type AnyEvent =\n\t| DataModificationEvent\n\t| BeforeCommitEvent\n\t| AfterCommitEvent\n\nexport type EventMap<E extends AnyEvent = AnyEvent> = {\n\t[K in E['type']]: E extends { type: K } ? E : never\n}\n\nexport type EventListener<K extends keyof EventMap> = (event: EventMap[K], mapper: Mapper) => Promise<void>\n\nexport class EventManager {\n\tprivate listeners: { [K in keyof EventMap]: EventListener<K>[] } = {\n\t\tBeforeInsertEvent: [],\n\t\tAfterInsertEvent: [],\n\t\tBeforeUpdateEvent: [],\n\t\tAfterUpdateEvent: [],\n\t\tBeforeDeleteEvent: [],\n\t\tBeforeCommitEvent: [],\n\t\tAfterCommitEvent: [],\n\t\tBeforeJunctionUpdateEvent: [],\n\t\tAfterJunctionUpdateEvent: [],\n\t}\n\n\tconstructor(\n\t\tprivate readonly mapper: Mapper,\n\t) {\n\t}\n\n\tpublic listen<K extends keyof EventMap>(type: K, cb: EventListener<K>) {\n\t\tthis.listeners[type].push(cb)\n\t}\n\n\tpublic async fire<K extends keyof EventMap>(event: EventMap[K]) {\n\t\tfor (const listener of this.listeners[event.type]) {\n\t\t\tawait listener(event, this.mapper)\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;;AAIO,MAAM,kBAAkB;AAAA,EAK9B,YACiB,QACA,MACf;AAFe,SAAA,SAAA;AACA,SAAA,OAAA;AANjB,kBAAA,MAAO,QAAO,mBAAA;AAEd,kBAAA,MAAO,YAAA;AAAA,EAMP;AACD;AAEO,MAAM,iBAAiB;AAAA,EAG7B,YACiB,QACA,MACA,IACf;AAHe,SAAA,SAAA;AACA,SAAA,OAAA;AACA,SAAA,KAAA;AALjB,kBAAA,MAAO,QAAO,kBAAA;AAAA,EAOd;AACD;AAEO,MAAM,kBAAkB;AAAA,EAK9B,YACiB,QACA,MACA,IACf;AAHe,SAAA,SAAA;AACA,SAAA,OAAA;AACA,SAAA,KAAA;AAPjB,kBAAA,MAAO,QAAO,mBAAA;AAEd,kBAAA,MAAO,YAAA;AAAA,EAOP;AACD;AAEO,MAAM,iBAAiB;AAAA,EAK7B,YACiB,QACA,MACA,IACf;AAHe,SAAA,SAAA;AACA,SAAA,OAAA;AACA,SAAA,KAAA;AAPjB,kBAAA,MAAO,QAAO,kBAAA;AAEd,kBAAA,MAAQ,aAAA;AAAA,EAOR;AAAA,EACA,IAAI,aAAa;AAEhB,WAAO,KAAK,cAAc,KAAK,KAAK,KAAK,CAAA,OAAM,GAAG,UAAU,GAAG,GAAG;AAAA,EACnE;AACD;AAEO,MAAM,kBAAkB;AAAA,EAG9B,YACiB,QACA,IACf;AAFe,SAAA,SAAA;AACA,SAAA,KAAA;AAJjB,kBAAA,MAAO,QAAO,mBAAA;AAAA,EAMd;AACD;AAEO,MAAM,0BAA0B;AAAA,EAKtC,YACiB,cACA,gBACA,UACA,WACA,WACf;AALe,SAAA,eAAA;AACA,SAAA,iBAAA;AACA,SAAA,WAAA;AACA,SAAA,YAAA;AACA,SAAA,YAAA;AATjB,kBAAA,MAAO,QAAO,2BAAA;AAEd,kBAAA,MAAO,YAAA;AAAA,EASP;AACD;AAEO,MAAM,yBAAyB;AAAA,EAGrC,YACiB,cACA,gBACA,UACA,WACA,WACA,YACf;AANe,SAAA,eAAA;AACA,SAAA,iBAAA;AACA,SAAA,WAAA;AACA,SAAA,YAAA;AACA,SAAA,YAAA;AACA,SAAA,aAAA;AARjB,kBAAA,MAAO,QAAO,0BAAA;AAAA,EAUd;AACD;AAEO,MAAM,kBAAkB;AAAA,EAAxB,cAAA;AACN,kBAAA,MAAO,QAAO,mBAAA;AAAA,EAAA;AACf;AAEO,MAAM,iBAAiB;AAAA,EAAvB,cAAA;AACN,kBAAA,MAAO,QAAO,kBAAA;AAAA,EAAA;AACf;AAsBO,MAAM,aAAa;AAAA,EAazB,YACkB,QAChB;AADgB,SAAA,SAAA;AAblB,kBAAA,MAAQ,aAA2D;AAAA,MAClE,mBAAmB,CAAA;AAAA,MACnB,kBAAkB,CAAA;AAAA,MAClB,mBAAmB,CAAA;AAAA,MACnB,kBAAkB,CAAA;AAAA,MAClB,mBAAmB,CAAA;AAAA,MACnB,mBAAmB,CAAA;AAAA,MACnB,kBAAkB,CAAA;AAAA,MAClB,2BAA2B,CAAA;AAAA,MAC3B,0BAA0B,CAAA;AAAA,IAAC,CAC5B;AAAA,EAKA;AAAA,EAEO,OAAiC,MAAS,IAAsB;AACtE,SAAK,UAAU,IAAI,EAAE,KAAK,EAAE;AAAA,EAC7B;AAAA,EAEA,MAAa,KAA+B,OAAoB;AAC/D,eAAW,YAAY,KAAK,UAAU,MAAM,IAAI,GAAG;AAClD,YAAM,SAAS,OAAO,KAAK,MAAM;AAAA,IAClC;AAAA,EACD;AACD;"}
@@ -1 +1 @@
1
- {"version":3,"file":"JunctionTableManager.cjs","sources":["../../../../../packages/engine-content-api/src/mapper/JunctionTableManager.ts"],"sourcesContent":["import { getEntity } from '@contember/schema-utils'\nimport { PathFactory, WhereBuilder } from './select'\nimport { PredicateFactory } from '../acl'\nimport { Client, ConflictActionType, DeleteBuilder, InsertBuilder, Literal, Operator, SelectBuilder } from '@contember/database'\nimport { Acl, Input, Model } from '@contember/schema'\nimport {\n\tMutationJunctionUpdateOk,\n\tMutationNoResultError,\n\tMutationNothingToDo,\n\tMutationResultList,\n\tMutationResultType,\n\tNothingToDoReason,\n} from './Result'\nimport { ImplementationException } from '../exception'\nimport { AfterJunctionUpdateEvent, BeforeJunctionUpdateEvent } from './EventManager'\nimport { Mapper } from './Mapper'\n\ntype OkResultFactory = () => MutationJunctionUpdateOk\n\ntype JunctionMutationResult =\n\t| MutationJunctionUpdateOk\n\t| MutationNothingToDo\n\t| MutationNoResultError\n\nexport class JunctionTableManager {\n\tconstructor(\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly predicateFactory: PredicateFactory,\n\t\tprivate readonly whereBuilder: WhereBuilder,\n\t\tprivate readonly connectJunctionHandler: JunctionConnectHandler,\n\t\tprivate readonly disconnectJunctionHandler: JunctionDisconnectHandler,\n\t\tprivate readonly pathFactory: PathFactory,\n\t) {}\n\n\tpublic async connectJunction(\n\t\tmapper: Mapper,\n\t\towningEntity: Model.Entity,\n\t\trelation: Model.ManyHasManyOwningRelation,\n\t\towningUnique: Input.PrimaryValue,\n\t\tinverseUnique: Input.PrimaryValue,\n\t): Promise<MutationResultList> {\n\t\tconst beforeEvent = new BeforeJunctionUpdateEvent(owningEntity, relation, owningUnique, inverseUnique, 'connect')\n\t\tawait mapper.eventManager.fire(beforeEvent)\n\t\tconst result = await this.executeJunctionModification(\n\t\t\tmapper.db,\n\t\t\towningEntity,\n\t\t\trelation,\n\t\t\towningUnique,\n\t\t\tinverseUnique,\n\t\t\tthis.connectJunctionHandler,\n\t\t)\n\t\tif (result.result !== MutationResultType.noResultError) {\n\t\t\tconst afterEvent = new AfterJunctionUpdateEvent(\n\t\t\t\towningEntity,\n\t\t\t\trelation,\n\t\t\t\towningUnique,\n\t\t\t\tinverseUnique,\n\t\t\t\t'connect',\n\t\t\t\tresult.result === MutationResultType.ok,\n\t\t\t)\n\t\t\tawait mapper.eventManager.fire(afterEvent)\n\t\t}\n\t\treturn [result]\n\t}\n\n\tpublic async disconnectJunction(\n\t\tmapper: Mapper,\n\t\towningEntity: Model.Entity,\n\t\trelation: Model.ManyHasManyOwningRelation,\n\t\towningUnique: Input.PrimaryValue,\n\t\tinverseUnique: Input.PrimaryValue,\n\t): Promise<MutationResultList> {\n\t\tconst beforeEvent = new BeforeJunctionUpdateEvent(owningEntity, relation, owningUnique, inverseUnique, 'connect')\n\t\tawait mapper.eventManager.fire(beforeEvent)\n\t\tconst result = await this.executeJunctionModification(\n\t\t\tmapper.db,\n\t\t\towningEntity,\n\t\t\trelation,\n\t\t\towningUnique,\n\t\t\tinverseUnique,\n\t\t\tthis.disconnectJunctionHandler,\n\t\t)\n\t\tif (result.result !== MutationResultType.noResultError) {\n\t\t\tconst afterEvent = new AfterJunctionUpdateEvent(\n\t\t\t\towningEntity,\n\t\t\t\trelation,\n\t\t\t\towningUnique,\n\t\t\t\tinverseUnique,\n\t\t\t\t'disconnect',\n\t\t\t\tresult.result === MutationResultType.ok,\n\t\t\t)\n\t\t\tbeforeEvent.afterEvent = afterEvent\n\t\t\tawait mapper.eventManager.fire(afterEvent)\n\t\t}\n\t\treturn [result]\n\t}\n\n\tprivate async executeJunctionModification(\n\t\tdb: Client,\n\t\towningEntity: Model.Entity,\n\t\trelation: Model.ManyHasManyOwningRelation,\n\t\towningPrimary: Input.PrimaryValue,\n\t\tinversePrimary: Input.PrimaryValue,\n\t\thandler: JunctionHandler,\n\t): Promise<JunctionMutationResult> {\n\t\tconst joiningTable = relation.joiningTable\n\t\tconst inverseEntity = getEntity(this.schema, relation.target)\n\t\tif (inverseEntity.view || owningEntity.view) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\n\t\tconst owningPredicate = this.predicateFactory.create(owningEntity, Acl.Operation.update, [relation.name])\n\t\tlet inversePredicate: Input.OptionalWhere = {}\n\t\tif (relation.inversedBy) {\n\t\t\tinversePredicate = this.predicateFactory.create(inverseEntity, Acl.Operation.update, [relation.inversedBy])\n\t\t}\n\n\t\tconst hasNoPredicates = Object.keys(owningPredicate).length === 0 && Object.keys(inversePredicate).length === 0\n\n\t\tconst okResultFactory = () => new MutationJunctionUpdateOk([], owningEntity, relation, owningPrimary, inversePrimary)\n\t\tif (hasNoPredicates) {\n\t\t\treturn await handler.executeSimple({ db, joiningTable, owningPrimary, inversePrimary, okResultFactory })\n\t\t} else {\n\t\t\tconst owningWhere: Input.OptionalWhere = {\n\t\t\t\tand: [owningPredicate, { [owningEntity.primary]: { eq: owningPrimary } }],\n\t\t\t}\n\n\t\t\tconst inverseWhere: Input.OptionalWhere = {\n\t\t\t\tand: [inversePredicate, { [inverseEntity.primary]: { eq: inversePrimary } }],\n\t\t\t}\n\n\t\t\tconst dataCallback: SelectBuilder.Callback = qb => {\n\t\t\t\tqb = qb\n\t\t\t\t\t.select(expr => expr.select(['owning', owningEntity.primaryColumn]), joiningTable.joiningColumn.columnName)\n\t\t\t\t\t.select(\n\t\t\t\t\t\texpr => expr.select(['inverse', inverseEntity.primaryColumn]),\n\t\t\t\t\t\tjoiningTable.inverseJoiningColumn.columnName,\n\t\t\t\t\t)\n\t\t\t\t\t.select(expr => expr.raw('true'), 'selected')\n\t\t\t\t\t.from(new Literal('(values (null))'), 't')\n\t\t\t\t\t.join(owningEntity.tableName, 'owning', condition => condition.raw('true'))\n\t\t\t\t\t.join(inverseEntity.tableName, 'inverse', condition => condition.raw('true'))\n\t\t\t\tqb = this.whereBuilder.build(qb, owningEntity, this.pathFactory.create([], 'owning'), owningWhere)\n\t\t\t\tqb = this.whereBuilder.build(qb, inverseEntity, this.pathFactory.create([], 'inverse'), inverseWhere)\n\t\t\t\treturn qb\n\t\t\t}\n\n\t\t\treturn await handler.executeComplex({ db, joiningTable, dataCallback, okResultFactory })\n\t\t}\n\t}\n}\n\ninterface JunctionSimpleExecutionArgs {\n\tdb: Client\n\tjoiningTable: Model.JoiningTable\n\towningPrimary: Input.PrimaryValue\n\tinversePrimary: Input.PrimaryValue\n\tokResultFactory: OkResultFactory\n}\n\ninterface JunctionComplexExecutionArgs {\n\tdb: Client\n\tjoiningTable: Model.JoiningTable\n\tdataCallback: SelectBuilder.Callback\n\tokResultFactory: OkResultFactory\n}\n\ninterface JunctionHandler {\n\texecuteSimple(args: JunctionSimpleExecutionArgs): Promise<JunctionMutationResult>\n\n\texecuteComplex(args: JunctionComplexExecutionArgs): Promise<JunctionMutationResult>\n}\n\nexport class JunctionConnectHandler implements JunctionHandler {\n\tasync executeSimple({\n\t\tdb,\n\t\tjoiningTable,\n\t\towningPrimary,\n\t\tinversePrimary,\n\t\tokResultFactory,\n\t}: JunctionSimpleExecutionArgs): Promise<JunctionMutationResult> {\n\t\tconst result = await InsertBuilder.create()\n\t\t\t.into(joiningTable.tableName)\n\t\t\t.values({\n\t\t\t\t[joiningTable.joiningColumn.columnName]: expr => expr.selectValue(owningPrimary),\n\t\t\t\t[joiningTable.inverseJoiningColumn.columnName]: expr => expr.selectValue(inversePrimary),\n\t\t\t})\n\t\t\t.onConflict(ConflictActionType.doNothing)\n\t\t\t.execute(db)\n\t\tif (result === 0) {\n\t\t\treturn new MutationNothingToDo([], NothingToDoReason.alreadyExists)\n\t\t}\n\t\treturn okResultFactory()\n\t}\n\n\tasync executeComplex({\n\t\tdb,\n\t\tjoiningTable,\n\t\tdataCallback,\n\t\tokResultFactory,\n\t}: JunctionComplexExecutionArgs): Promise<JunctionMutationResult> {\n\t\tconst insert = InsertBuilder.create()\n\t\t\t.into(joiningTable.tableName)\n\t\t\t.values({\n\t\t\t\t[joiningTable.joiningColumn.columnName]: expr => expr.select(['data', joiningTable.joiningColumn.columnName]),\n\t\t\t\t[joiningTable.inverseJoiningColumn.columnName]: expr => expr.select(['data', joiningTable.inverseJoiningColumn.columnName]),\n\t\t\t})\n\t\t\t.returning(new Literal('true as inserted'))\n\t\t\t.from(qb => qb.from('data'))\n\t\t\t.onConflict(ConflictActionType.doNothing)\n\n\t\tconst qb = SelectBuilder.create()\n\t\t\t.with('data', dataCallback)\n\t\t\t.with('insert', insert)\n\t\t\t.from(new Literal('(values (null))'), 't')\n\t\t\t.leftJoin('data', 'data', condition => condition.raw('true'))\n\t\t\t.leftJoin('insert', 'insert', condition => condition.raw('true'))\n\t\t\t.select(expr => expr.raw('coalesce(data.selected, false)'), 'selected')\n\t\t\t.select(expr => expr.raw('coalesce(insert.inserted, false)'), 'inserted')\n\n\t\tconst result = await qb.getResult(db)\n\t\tif (result[0]['selected'] === false) {\n\t\t\treturn new MutationNoResultError([])\n\t\t}\n\t\tif (result[0]['inserted'] === false) {\n\t\t\treturn new MutationNothingToDo([], NothingToDoReason.alreadyExists)\n\t\t}\n\t\treturn okResultFactory()\n\t}\n}\n\nexport class JunctionDisconnectHandler implements JunctionHandler {\n\tpublic async executeSimple({\n\t\tdb,\n\t\tjoiningTable,\n\t\towningPrimary,\n\t\tinversePrimary,\n\t\tokResultFactory,\n\t}: JunctionSimpleExecutionArgs): Promise<JunctionMutationResult> {\n\t\tconst qb = DeleteBuilder.create()\n\t\t\t.from(joiningTable.tableName)\n\t\t\t.where(cond => cond.compare(joiningTable.joiningColumn.columnName, Operator.eq, owningPrimary))\n\t\t\t.where(cond => cond.compare(joiningTable.inverseJoiningColumn.columnName, Operator.eq, inversePrimary))\n\n\t\tconst result = await qb.execute(db)\n\t\tif (result === 0) {\n\t\t\treturn new MutationNothingToDo([], NothingToDoReason.alreadyExists)\n\t\t}\n\t\treturn okResultFactory()\n\t}\n\n\tpublic async executeComplex({\n\t\tdb,\n\t\tjoiningTable,\n\t\tdataCallback,\n\t\tokResultFactory,\n\t}: JunctionComplexExecutionArgs): Promise<JunctionMutationResult> {\n\t\tconst deleteQb = DeleteBuilder.create()\n\t\t\t.from(joiningTable.tableName)\n\t\t\t.using('data')\n\t\t\t.where(cond => {\n\t\t\t\tcond = cond.compareColumns([joiningTable.tableName, joiningTable.joiningColumn.columnName], Operator.eq, [\n\t\t\t\t\t'data',\n\t\t\t\t\tjoiningTable.joiningColumn.columnName,\n\t\t\t\t])\n\t\t\t\tcond = cond.compareColumns(\n\t\t\t\t\t[joiningTable.tableName, joiningTable.inverseJoiningColumn.columnName],\n\t\t\t\t\tOperator.eq,\n\t\t\t\t\t['data', joiningTable.inverseJoiningColumn.columnName],\n\t\t\t\t)\n\t\t\t\treturn cond\n\t\t\t})\n\t\t\t.returning(new Literal('true as deleted'))\n\n\t\tconst qb = SelectBuilder.create()\n\t\t\t.with('data', dataCallback)\n\t\t\t.with('delete', deleteQb)\n\t\t\t.from(new Literal('(values (null))'), 't')\n\t\t\t.leftJoin('data', 'data', condition => condition.raw('true'))\n\t\t\t.leftJoin('delete', 'delete', condition => condition.raw('true'))\n\t\t\t.select(expr => expr.raw('coalesce(data.selected, false)'), 'selected')\n\t\t\t.select(expr => expr.raw('coalesce(delete.deleted, false)'), 'deleted')\n\n\t\tconst result = await qb.getResult(db)\n\t\tif (result[0]['selected'] === false) {\n\t\t\treturn new MutationNoResultError([])\n\t\t}\n\t\tif (result[0]['inserted'] === false) {\n\t\t\treturn new MutationNothingToDo([], NothingToDoReason.alreadyExists)\n\t\t}\n\t\treturn okResultFactory()\n\t}\n}\n"],"names":["schema","BeforeJunctionUpdateEvent","MutationResultType","AfterJunctionUpdateEvent","getEntity","ImplementationException","Acl","MutationJunctionUpdateOk","Literal","InsertBuilder","ConflictActionType","MutationNothingToDo","NothingToDoReason","qb","SelectBuilder","MutationNoResultError","DeleteBuilder","Operator"],"mappings":";;;;;;;;AAwBO,MAAM,qBAAqB;AAAA,EACjC,YACkBA,SACA,kBACA,cACA,wBACA,2BACA,aAChB;AANgB,SAAA,SAAAA;AACA,SAAA,mBAAA;AACA,SAAA,eAAA;AACA,SAAA,yBAAA;AACA,SAAA,4BAAA;AACA,SAAA,cAAA;AAAA,EACf;AAAA,EAEH,MAAa,gBACZ,QACA,cACA,UACA,cACA,eAC8B;AAC9B,UAAM,cAAc,IAAIC,uCAA0B,cAAc,UAAU,cAAc,eAAe,SAAS;AAChH,UAA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AO,IAAIJ,OAAAA,oBAAoB,IAAIC,OAAAA,kBAAkB,aAAa;AAAA,IACnE;AACA,WAAO,gBAAA;AAAA,EACR;AACD;;;;"}
1
+ {"version":3,"file":"JunctionTableManager.cjs","sources":["../../../../../packages/engine-content-api/src/mapper/JunctionTableManager.ts"],"sourcesContent":["import { getEntity } from '@contember/schema-utils'\nimport { PathFactory, WhereBuilder } from './select/index.js'\nimport { PredicateFactory } from '../acl/index.js'\nimport { Client, ConflictActionType, DeleteBuilder, InsertBuilder, Literal, Operator, SelectBuilder } from '@contember/database'\nimport { Acl, Input, Model } from '@contember/schema'\nimport {\n\tMutationJunctionUpdateOk,\n\tMutationNoResultError,\n\tMutationNothingToDo,\n\tMutationResultList,\n\tMutationResultType,\n\tNothingToDoReason,\n} from './Result.js'\nimport { ImplementationException } from '../exception.js'\nimport { AfterJunctionUpdateEvent, BeforeJunctionUpdateEvent } from './EventManager.js'\nimport { Mapper } from './Mapper.js'\n\ntype OkResultFactory = () => MutationJunctionUpdateOk\n\ntype JunctionMutationResult =\n\t| MutationJunctionUpdateOk\n\t| MutationNothingToDo\n\t| MutationNoResultError\n\nexport class JunctionTableManager {\n\tconstructor(\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly predicateFactory: PredicateFactory,\n\t\tprivate readonly whereBuilder: WhereBuilder,\n\t\tprivate readonly connectJunctionHandler: JunctionConnectHandler,\n\t\tprivate readonly disconnectJunctionHandler: JunctionDisconnectHandler,\n\t\tprivate readonly pathFactory: PathFactory,\n\t) {}\n\n\tpublic async connectJunction(\n\t\tmapper: Mapper,\n\t\towningEntity: Model.Entity,\n\t\trelation: Model.ManyHasManyOwningRelation,\n\t\towningUnique: Input.PrimaryValue,\n\t\tinverseUnique: Input.PrimaryValue,\n\t): Promise<MutationResultList> {\n\t\tconst beforeEvent = new BeforeJunctionUpdateEvent(owningEntity, relation, owningUnique, inverseUnique, 'connect')\n\t\tawait mapper.eventManager.fire(beforeEvent)\n\t\tconst result = await this.executeJunctionModification(\n\t\t\tmapper.db,\n\t\t\towningEntity,\n\t\t\trelation,\n\t\t\towningUnique,\n\t\t\tinverseUnique,\n\t\t\tthis.connectJunctionHandler,\n\t\t)\n\t\tif (result.result !== MutationResultType.noResultError) {\n\t\t\tconst afterEvent = new AfterJunctionUpdateEvent(\n\t\t\t\towningEntity,\n\t\t\t\trelation,\n\t\t\t\towningUnique,\n\t\t\t\tinverseUnique,\n\t\t\t\t'connect',\n\t\t\t\tresult.result === MutationResultType.ok,\n\t\t\t)\n\t\t\tawait mapper.eventManager.fire(afterEvent)\n\t\t}\n\t\treturn [result]\n\t}\n\n\tpublic async disconnectJunction(\n\t\tmapper: Mapper,\n\t\towningEntity: Model.Entity,\n\t\trelation: Model.ManyHasManyOwningRelation,\n\t\towningUnique: Input.PrimaryValue,\n\t\tinverseUnique: Input.PrimaryValue,\n\t): Promise<MutationResultList> {\n\t\tconst beforeEvent = new BeforeJunctionUpdateEvent(owningEntity, relation, owningUnique, inverseUnique, 'connect')\n\t\tawait mapper.eventManager.fire(beforeEvent)\n\t\tconst result = await this.executeJunctionModification(\n\t\t\tmapper.db,\n\t\t\towningEntity,\n\t\t\trelation,\n\t\t\towningUnique,\n\t\t\tinverseUnique,\n\t\t\tthis.disconnectJunctionHandler,\n\t\t)\n\t\tif (result.result !== MutationResultType.noResultError) {\n\t\t\tconst afterEvent = new AfterJunctionUpdateEvent(\n\t\t\t\towningEntity,\n\t\t\t\trelation,\n\t\t\t\towningUnique,\n\t\t\t\tinverseUnique,\n\t\t\t\t'disconnect',\n\t\t\t\tresult.result === MutationResultType.ok,\n\t\t\t)\n\t\t\tbeforeEvent.afterEvent = afterEvent\n\t\t\tawait mapper.eventManager.fire(afterEvent)\n\t\t}\n\t\treturn [result]\n\t}\n\n\tprivate async executeJunctionModification(\n\t\tdb: Client,\n\t\towningEntity: Model.Entity,\n\t\trelation: Model.ManyHasManyOwningRelation,\n\t\towningPrimary: Input.PrimaryValue,\n\t\tinversePrimary: Input.PrimaryValue,\n\t\thandler: JunctionHandler,\n\t): Promise<JunctionMutationResult> {\n\t\tconst joiningTable = relation.joiningTable\n\t\tconst inverseEntity = getEntity(this.schema, relation.target)\n\t\tif (inverseEntity.view || owningEntity.view) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\n\t\tconst owningPredicate = this.predicateFactory.create(owningEntity, Acl.Operation.update, [relation.name])\n\t\tlet inversePredicate: Input.OptionalWhere = {}\n\t\tif (relation.inversedBy) {\n\t\t\tinversePredicate = this.predicateFactory.create(inverseEntity, Acl.Operation.update, [relation.inversedBy])\n\t\t}\n\n\t\tconst hasNoPredicates = Object.keys(owningPredicate).length === 0 && Object.keys(inversePredicate).length === 0\n\n\t\tconst okResultFactory = () => new MutationJunctionUpdateOk([], owningEntity, relation, owningPrimary, inversePrimary)\n\t\tif (hasNoPredicates) {\n\t\t\treturn await handler.executeSimple({ db, joiningTable, owningPrimary, inversePrimary, okResultFactory })\n\t\t} else {\n\t\t\tconst owningWhere: Input.OptionalWhere = {\n\t\t\t\tand: [owningPredicate, { [owningEntity.primary]: { eq: owningPrimary } }],\n\t\t\t}\n\n\t\t\tconst inverseWhere: Input.OptionalWhere = {\n\t\t\t\tand: [inversePredicate, { [inverseEntity.primary]: { eq: inversePrimary } }],\n\t\t\t}\n\n\t\t\tconst dataCallback: SelectBuilder.Callback = qb => {\n\t\t\t\tqb = qb\n\t\t\t\t\t.select(expr => expr.select(['owning', owningEntity.primaryColumn]), joiningTable.joiningColumn.columnName)\n\t\t\t\t\t.select(\n\t\t\t\t\t\texpr => expr.select(['inverse', inverseEntity.primaryColumn]),\n\t\t\t\t\t\tjoiningTable.inverseJoiningColumn.columnName,\n\t\t\t\t\t)\n\t\t\t\t\t.select(expr => expr.raw('true'), 'selected')\n\t\t\t\t\t.from(new Literal('(values (null))'), 't')\n\t\t\t\t\t.join(owningEntity.tableName, 'owning', condition => condition.raw('true'))\n\t\t\t\t\t.join(inverseEntity.tableName, 'inverse', condition => condition.raw('true'))\n\t\t\t\tqb = this.whereBuilder.build(qb, owningEntity, this.pathFactory.create([], 'owning'), owningWhere)\n\t\t\t\tqb = this.whereBuilder.build(qb, inverseEntity, this.pathFactory.create([], 'inverse'), inverseWhere)\n\t\t\t\treturn qb\n\t\t\t}\n\n\t\t\treturn await handler.executeComplex({ db, joiningTable, dataCallback, okResultFactory })\n\t\t}\n\t}\n}\n\ninterface JunctionSimpleExecutionArgs {\n\tdb: Client\n\tjoiningTable: Model.JoiningTable\n\towningPrimary: Input.PrimaryValue\n\tinversePrimary: Input.PrimaryValue\n\tokResultFactory: OkResultFactory\n}\n\ninterface JunctionComplexExecutionArgs {\n\tdb: Client\n\tjoiningTable: Model.JoiningTable\n\tdataCallback: SelectBuilder.Callback\n\tokResultFactory: OkResultFactory\n}\n\ninterface JunctionHandler {\n\texecuteSimple(args: JunctionSimpleExecutionArgs): Promise<JunctionMutationResult>\n\n\texecuteComplex(args: JunctionComplexExecutionArgs): Promise<JunctionMutationResult>\n}\n\nexport class JunctionConnectHandler implements JunctionHandler {\n\tasync executeSimple({\n\t\tdb,\n\t\tjoiningTable,\n\t\towningPrimary,\n\t\tinversePrimary,\n\t\tokResultFactory,\n\t}: JunctionSimpleExecutionArgs): Promise<JunctionMutationResult> {\n\t\tconst result = await InsertBuilder.create()\n\t\t\t.into(joiningTable.tableName)\n\t\t\t.values({\n\t\t\t\t[joiningTable.joiningColumn.columnName]: expr => expr.selectValue(owningPrimary),\n\t\t\t\t[joiningTable.inverseJoiningColumn.columnName]: expr => expr.selectValue(inversePrimary),\n\t\t\t})\n\t\t\t.onConflict(ConflictActionType.doNothing)\n\t\t\t.execute(db)\n\t\tif (result === 0) {\n\t\t\treturn new MutationNothingToDo([], NothingToDoReason.alreadyExists)\n\t\t}\n\t\treturn okResultFactory()\n\t}\n\n\tasync executeComplex({\n\t\tdb,\n\t\tjoiningTable,\n\t\tdataCallback,\n\t\tokResultFactory,\n\t}: JunctionComplexExecutionArgs): Promise<JunctionMutationResult> {\n\t\tconst insert = InsertBuilder.create()\n\t\t\t.into(joiningTable.tableName)\n\t\t\t.values({\n\t\t\t\t[joiningTable.joiningColumn.columnName]: expr => expr.select(['data', joiningTable.joiningColumn.columnName]),\n\t\t\t\t[joiningTable.inverseJoiningColumn.columnName]: expr => expr.select(['data', joiningTable.inverseJoiningColumn.columnName]),\n\t\t\t})\n\t\t\t.returning(new Literal('true as inserted'))\n\t\t\t.from(qb => qb.from('data'))\n\t\t\t.onConflict(ConflictActionType.doNothing)\n\n\t\tconst qb = SelectBuilder.create()\n\t\t\t.with('data', dataCallback)\n\t\t\t.with('insert', insert)\n\t\t\t.from(new Literal('(values (null))'), 't')\n\t\t\t.leftJoin('data', 'data', condition => condition.raw('true'))\n\t\t\t.leftJoin('insert', 'insert', condition => condition.raw('true'))\n\t\t\t.select(expr => expr.raw('coalesce(data.selected, false)'), 'selected')\n\t\t\t.select(expr => expr.raw('coalesce(insert.inserted, false)'), 'inserted')\n\n\t\tconst result = await qb.getResult(db)\n\t\tif (result[0]['selected'] === false) {\n\t\t\treturn new MutationNoResultError([])\n\t\t}\n\t\tif (result[0]['inserted'] === false) {\n\t\t\treturn new MutationNothingToDo([], NothingToDoReason.alreadyExists)\n\t\t}\n\t\treturn okResultFactory()\n\t}\n}\n\nexport class JunctionDisconnectHandler implements JunctionHandler {\n\tpublic async executeSimple({\n\t\tdb,\n\t\tjoiningTable,\n\t\towningPrimary,\n\t\tinversePrimary,\n\t\tokResultFactory,\n\t}: JunctionSimpleExecutionArgs): Promise<JunctionMutationResult> {\n\t\tconst qb = DeleteBuilder.create()\n\t\t\t.from(joiningTable.tableName)\n\t\t\t.where(cond => cond.compare(joiningTable.joiningColumn.columnName, Operator.eq, owningPrimary))\n\t\t\t.where(cond => cond.compare(joiningTable.inverseJoiningColumn.columnName, Operator.eq, inversePrimary))\n\n\t\tconst result = await qb.execute(db)\n\t\tif (result === 0) {\n\t\t\treturn new MutationNothingToDo([], NothingToDoReason.alreadyExists)\n\t\t}\n\t\treturn okResultFactory()\n\t}\n\n\tpublic async executeComplex({\n\t\tdb,\n\t\tjoiningTable,\n\t\tdataCallback,\n\t\tokResultFactory,\n\t}: JunctionComplexExecutionArgs): Promise<JunctionMutationResult> {\n\t\tconst deleteQb = DeleteBuilder.create()\n\t\t\t.from(joiningTable.tableName)\n\t\t\t.using('data')\n\t\t\t.where(cond => {\n\t\t\t\tcond = cond.compareColumns([joiningTable.tableName, joiningTable.joiningColumn.columnName], Operator.eq, [\n\t\t\t\t\t'data',\n\t\t\t\t\tjoiningTable.joiningColumn.columnName,\n\t\t\t\t])\n\t\t\t\tcond = cond.compareColumns(\n\t\t\t\t\t[joiningTable.tableName, joiningTable.inverseJoiningColumn.columnName],\n\t\t\t\t\tOperator.eq,\n\t\t\t\t\t['data', joiningTable.inverseJoiningColumn.columnName],\n\t\t\t\t)\n\t\t\t\treturn cond\n\t\t\t})\n\t\t\t.returning(new Literal('true as deleted'))\n\n\t\tconst qb = SelectBuilder.create()\n\t\t\t.with('data', dataCallback)\n\t\t\t.with('delete', deleteQb)\n\t\t\t.from(new Literal('(values (null))'), 't')\n\t\t\t.leftJoin('data', 'data', condition => condition.raw('true'))\n\t\t\t.leftJoin('delete', 'delete', condition => condition.raw('true'))\n\t\t\t.select(expr => expr.raw('coalesce(data.selected, false)'), 'selected')\n\t\t\t.select(expr => expr.raw('coalesce(delete.deleted, false)'), 'deleted')\n\n\t\tconst result = await qb.getResult(db)\n\t\tif (result[0]['selected'] === false) {\n\t\t\treturn new MutationNoResultError([])\n\t\t}\n\t\tif (result[0]['inserted'] === false) {\n\t\t\treturn new MutationNothingToDo([], NothingToDoReason.alreadyExists)\n\t\t}\n\t\treturn okResultFactory()\n\t}\n}\n"],"names":["schema","BeforeJunctionUpdateEvent","MutationResultType","AfterJunctionUpdateEvent","getEntity","ImplementationException","Acl","MutationJunctionUpdateOk","Literal","InsertBuilder","ConflictActionType","MutationNothingToDo","NothingToDoReason","qb","SelectBuilder","MutationNoResultError","DeleteBuil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A,cAAa,UAAU,IAAI,MAAM,CAAC,EAC/D,OAAO,CAAA,SAAQ,KAAK,IAAI,gCAAgC,GAAG,UAAU,EACrE,OAAO,UAAQ,KAAK,IAAI,iCAAiC,GAAG,SAAS;AAEvE,UAAM,SAAS,MAAM,GAAG,UAAU,EAAE;AACpC,QAAI,OAAO,CAAC,EAAE,UAAU,MAAM,OAAO;AACpC,aAAO,IAAIO,OAAAA,sBAAsB,EAAE;AAAA,IACpC;AACA,QAAI,OAAO,CAAC,EAAE,UAAU,MAAM,OAAO;AACpC,aAAO,IAAIJ,OAAAA,oBAAoB,IAAIC,OAAAA,kBAAkB,aAAa;AAAA,IACnE;AACA,WAAO,gBAAA;AAAA,EACR;AACD;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"JunctionTableManager.js","sources":["../../../../../packages/engine-content-api/src/mapper/JunctionTableManager.ts"],"sourcesContent":["import { getEntity } from '@contember/schema-utils'\nimport { PathFactory, WhereBuilder } from './select'\nimport { PredicateFactory } from '../acl'\nimport { Client, ConflictActionType, DeleteBuilder, InsertBuilder, Literal, Operator, SelectBuilder } from '@contember/database'\nimport { Acl, Input, Model } from '@contember/schema'\nimport {\n\tMutationJunctionUpdateOk,\n\tMutationNoResultError,\n\tMutationNothingToDo,\n\tMutationResultList,\n\tMutationResultType,\n\tNothingToDoReason,\n} from './Result'\nimport { ImplementationException } from '../exception'\nimport { AfterJunctionUpdateEvent, BeforeJunctionUpdateEvent } from './EventManager'\nimport { Mapper } from './Mapper'\n\ntype OkResultFactory = () => MutationJunctionUpdateOk\n\ntype JunctionMutationResult =\n\t| MutationJunctionUpdateOk\n\t| MutationNothingToDo\n\t| MutationNoResultError\n\nexport class JunctionTableManager {\n\tconstructor(\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly predicateFactory: PredicateFactory,\n\t\tprivate readonly whereBuilder: WhereBuilder,\n\t\tprivate readonly connectJunctionHandler: JunctionConnectHandler,\n\t\tprivate readonly disconnectJunctionHandler: JunctionDisconnectHandler,\n\t\tprivate readonly pathFactory: PathFactory,\n\t) {}\n\n\tpublic async connectJunction(\n\t\tmapper: Mapper,\n\t\towningEntity: Model.Entity,\n\t\trelation: Model.ManyHasManyOwningRelation,\n\t\towningUnique: Input.PrimaryValue,\n\t\tinverseUnique: Input.PrimaryValue,\n\t): Promise<MutationResultList> {\n\t\tconst beforeEvent = new BeforeJunctionUpdateEvent(owningEntity, relation, owningUnique, inverseUnique, 'connect')\n\t\tawait mapper.eventManager.fire(beforeEvent)\n\t\tconst result = await this.executeJunctionModification(\n\t\t\tmapper.db,\n\t\t\towningEntity,\n\t\t\trelation,\n\t\t\towningUnique,\n\t\t\tinverseUnique,\n\t\t\tthis.connectJunctionHandler,\n\t\t)\n\t\tif (result.result !== MutationResultType.noResultError) {\n\t\t\tconst afterEvent = new AfterJunctionUpdateEvent(\n\t\t\t\towningEntity,\n\t\t\t\trelation,\n\t\t\t\towningUnique,\n\t\t\t\tinverseUnique,\n\t\t\t\t'connect',\n\t\t\t\tresult.result === MutationResultType.ok,\n\t\t\t)\n\t\t\tawait mapper.eventManager.fire(afterEvent)\n\t\t}\n\t\treturn [result]\n\t}\n\n\tpublic async disconnectJunction(\n\t\tmapper: Mapper,\n\t\towningEntity: Model.Entity,\n\t\trelation: Model.ManyHasManyOwningRelation,\n\t\towningUnique: Input.PrimaryValue,\n\t\tinverseUnique: Input.PrimaryValue,\n\t): Promise<MutationResultList> {\n\t\tconst beforeEvent = new BeforeJunctionUpdateEvent(owningEntity, relation, owningUnique, inverseUnique, 'connect')\n\t\tawait mapper.eventManager.fire(beforeEvent)\n\t\tconst result = await this.executeJunctionModification(\n\t\t\tmapper.db,\n\t\t\towningEntity,\n\t\t\trelation,\n\t\t\towningUnique,\n\t\t\tinverseUnique,\n\t\t\tthis.disconnectJunctionHandler,\n\t\t)\n\t\tif (result.result !== MutationResultType.noResultError) {\n\t\t\tconst afterEvent = new AfterJunctionUpdateEvent(\n\t\t\t\towningEntity,\n\t\t\t\trelation,\n\t\t\t\towningUnique,\n\t\t\t\tinverseUnique,\n\t\t\t\t'disconnect',\n\t\t\t\tresult.result === MutationResultType.ok,\n\t\t\t)\n\t\t\tbeforeEvent.afterEvent = afterEvent\n\t\t\tawait mapper.eventManager.fire(afterEvent)\n\t\t}\n\t\treturn [result]\n\t}\n\n\tprivate async executeJunctionModification(\n\t\tdb: Client,\n\t\towningEntity: Model.Entity,\n\t\trelation: Model.ManyHasManyOwningRelation,\n\t\towningPrimary: Input.PrimaryValue,\n\t\tinversePrimary: Input.PrimaryValue,\n\t\thandler: JunctionHandler,\n\t): Promise<JunctionMutationResult> {\n\t\tconst joiningTable = relation.joiningTable\n\t\tconst inverseEntity = getEntity(this.schema, relation.target)\n\t\tif (inverseEntity.view || owningEntity.view) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\n\t\tconst owningPredicate = this.predicateFactory.create(owningEntity, Acl.Operation.update, [relation.name])\n\t\tlet inversePredicate: Input.OptionalWhere = {}\n\t\tif (relation.inversedBy) {\n\t\t\tinversePredicate = this.predicateFactory.create(inverseEntity, Acl.Operation.update, [relation.inversedBy])\n\t\t}\n\n\t\tconst hasNoPredicates = Object.keys(owningPredicate).length === 0 && Object.keys(inversePredicate).length === 0\n\n\t\tconst okResultFactory = () => new MutationJunctionUpdateOk([], owningEntity, relation, owningPrimary, inversePrimary)\n\t\tif (hasNoPredicates) {\n\t\t\treturn await handler.executeSimple({ db, joiningTable, owningPrimary, inversePrimary, okResultFactory })\n\t\t} else {\n\t\t\tconst owningWhere: Input.OptionalWhere = {\n\t\t\t\tand: [owningPredicate, { [owningEntity.primary]: { eq: owningPrimary } }],\n\t\t\t}\n\n\t\t\tconst inverseWhere: Input.OptionalWhere = {\n\t\t\t\tand: [inversePredicate, { [inverseEntity.primary]: { eq: inversePrimary } }],\n\t\t\t}\n\n\t\t\tconst dataCallback: SelectBuilder.Callback = qb => {\n\t\t\t\tqb = qb\n\t\t\t\t\t.select(expr => expr.select(['owning', owningEntity.primaryColumn]), joiningTable.joiningColumn.columnName)\n\t\t\t\t\t.select(\n\t\t\t\t\t\texpr => expr.select(['inverse', inverseEntity.primaryColumn]),\n\t\t\t\t\t\tjoiningTable.inverseJoiningColumn.columnName,\n\t\t\t\t\t)\n\t\t\t\t\t.select(expr => expr.raw('true'), 'selected')\n\t\t\t\t\t.from(new Literal('(values (null))'), 't')\n\t\t\t\t\t.join(owningEntity.tableName, 'owning', condition => condition.raw('true'))\n\t\t\t\t\t.join(inverseEntity.tableName, 'inverse', condition => condition.raw('true'))\n\t\t\t\tqb = this.whereBuilder.build(qb, owningEntity, this.pathFactory.create([], 'owning'), owningWhere)\n\t\t\t\tqb = this.whereBuilder.build(qb, inverseEntity, this.pathFactory.create([], 'inverse'), inverseWhere)\n\t\t\t\treturn qb\n\t\t\t}\n\n\t\t\treturn await handler.executeComplex({ db, joiningTable, dataCallback, okResultFactory })\n\t\t}\n\t}\n}\n\ninterface JunctionSimpleExecutionArgs {\n\tdb: Client\n\tjoiningTable: Model.JoiningTable\n\towningPrimary: Input.PrimaryValue\n\tinversePrimary: Input.PrimaryValue\n\tokResultFactory: OkResultFactory\n}\n\ninterface JunctionComplexExecutionArgs {\n\tdb: Client\n\tjoiningTable: Model.JoiningTable\n\tdataCallback: SelectBuilder.Callback\n\tokResultFactory: OkResultFactory\n}\n\ninterface JunctionHandler {\n\texecuteSimple(args: JunctionSimpleExecutionArgs): Promise<JunctionMutationResult>\n\n\texecuteComplex(args: JunctionComplexExecutionArgs): Promise<JunctionMutationResult>\n}\n\nexport class JunctionConnectHandler implements JunctionHandler {\n\tasync executeSimple({\n\t\tdb,\n\t\tjoiningTable,\n\t\towningPrimary,\n\t\tinversePrimary,\n\t\tokResultFactory,\n\t}: JunctionSimpleExecutionArgs): Promise<JunctionMutationResult> {\n\t\tconst result = await InsertBuilder.create()\n\t\t\t.into(joiningTable.tableName)\n\t\t\t.values({\n\t\t\t\t[joiningTable.joiningColumn.columnName]: expr => expr.selectValue(owningPrimary),\n\t\t\t\t[joiningTable.inverseJoiningColumn.columnName]: expr => expr.selectValue(inversePrimary),\n\t\t\t})\n\t\t\t.onConflict(ConflictActionType.doNothing)\n\t\t\t.execute(db)\n\t\tif (result === 0) {\n\t\t\treturn new MutationNothingToDo([], NothingToDoReason.alreadyExists)\n\t\t}\n\t\treturn okResultFactory()\n\t}\n\n\tasync executeComplex({\n\t\tdb,\n\t\tjoiningTable,\n\t\tdataCallback,\n\t\tokResultFactory,\n\t}: JunctionComplexExecutionArgs): Promise<JunctionMutationResult> {\n\t\tconst insert = InsertBuilder.create()\n\t\t\t.into(joiningTable.tableName)\n\t\t\t.values({\n\t\t\t\t[joiningTable.joiningColumn.columnName]: expr => expr.select(['data', joiningTable.joiningColumn.columnName]),\n\t\t\t\t[joiningTable.inverseJoiningColumn.columnName]: expr => expr.select(['data', joiningTable.inverseJoiningColumn.columnName]),\n\t\t\t})\n\t\t\t.returning(new Literal('true as inserted'))\n\t\t\t.from(qb => qb.from('data'))\n\t\t\t.onConflict(ConflictActionType.doNothing)\n\n\t\tconst qb = SelectBuilder.create()\n\t\t\t.with('data', dataCallback)\n\t\t\t.with('insert', insert)\n\t\t\t.from(new Literal('(values (null))'), 't')\n\t\t\t.leftJoin('data', 'data', condition => condition.raw('true'))\n\t\t\t.leftJoin('insert', 'insert', condition => condition.raw('true'))\n\t\t\t.select(expr => expr.raw('coalesce(data.selected, false)'), 'selected')\n\t\t\t.select(expr => expr.raw('coalesce(insert.inserted, false)'), 'inserted')\n\n\t\tconst result = await qb.getResult(db)\n\t\tif (result[0]['selected'] === false) {\n\t\t\treturn new MutationNoResultError([])\n\t\t}\n\t\tif (result[0]['inserted'] === false) {\n\t\t\treturn new MutationNothingToDo([], NothingToDoReason.alreadyExists)\n\t\t}\n\t\treturn okResultFactory()\n\t}\n}\n\nexport class JunctionDisconnectHandler implements JunctionHandler {\n\tpublic async executeSimple({\n\t\tdb,\n\t\tjoiningTable,\n\t\towningPrimary,\n\t\tinversePrimary,\n\t\tokResultFactory,\n\t}: JunctionSimpleExecutionArgs): Promise<JunctionMutationResult> {\n\t\tconst qb = DeleteBuilder.create()\n\t\t\t.from(joiningTable.tableName)\n\t\t\t.where(cond => cond.compare(joiningTable.joiningColumn.columnName, Operator.eq, owningPrimary))\n\t\t\t.where(cond => cond.compare(joiningTable.inverseJoiningColumn.columnName, Operator.eq, inversePrimary))\n\n\t\tconst result = await qb.execute(db)\n\t\tif (result === 0) {\n\t\t\treturn new MutationNothingToDo([], NothingToDoReason.alreadyExists)\n\t\t}\n\t\treturn okResultFactory()\n\t}\n\n\tpublic async executeComplex({\n\t\tdb,\n\t\tjoiningTable,\n\t\tdataCallback,\n\t\tokResultFactory,\n\t}: JunctionComplexExecutionArgs): Promise<JunctionMutationResult> {\n\t\tconst deleteQb = DeleteBuilder.create()\n\t\t\t.from(joiningTable.tableName)\n\t\t\t.using('data')\n\t\t\t.where(cond => {\n\t\t\t\tcond = cond.compareColumns([joiningTable.tableName, joiningTable.joiningColumn.columnName], Operator.eq, [\n\t\t\t\t\t'data',\n\t\t\t\t\tjoiningTable.joiningColumn.columnName,\n\t\t\t\t])\n\t\t\t\tcond = cond.compareColumns(\n\t\t\t\t\t[joiningTable.tableName, joiningTable.inverseJoiningColumn.columnName],\n\t\t\t\t\tOperator.eq,\n\t\t\t\t\t['data', joiningTable.inverseJoiningColumn.columnName],\n\t\t\t\t)\n\t\t\t\treturn cond\n\t\t\t})\n\t\t\t.returning(new Literal('true as deleted'))\n\n\t\tconst qb = SelectBuilder.create()\n\t\t\t.with('data', dataCallback)\n\t\t\t.with('delete', deleteQb)\n\t\t\t.from(new Literal('(values (null))'), 't')\n\t\t\t.leftJoin('data', 'data', condition => condition.raw('true'))\n\t\t\t.leftJoin('delete', 'delete', condition => condition.raw('true'))\n\t\t\t.select(expr => expr.raw('coalesce(data.selected, false)'), 'selected')\n\t\t\t.select(expr => expr.raw('coalesce(delete.deleted, false)'), 'deleted')\n\n\t\tconst result = await qb.getResult(db)\n\t\tif (result[0]['selected'] === false) {\n\t\t\treturn new MutationNoResultError([])\n\t\t}\n\t\tif (result[0]['inserted'] === false) {\n\t\t\treturn new MutationNothingToDo([], NothingToDoReason.alreadyExists)\n\t\t}\n\t\treturn okResultFactory()\n\t}\n}\n"],"names":["InsertBuilder","qb"],"mappings":";;;;;;AAwBO,MAAM,qBAAqB;AAAA,EACjC,YACkB,QACA,kBACA,cACA,wBACA,2BACA,aAChB;AANgB,SAAA,SAAA;AACA,SAAA,mBAAA;AACA,SAAA,eAAA;AACA,SAAA,yBAAA;AACA,SAAA,4BAAA;AACA,SAAA,cAAA;AAAA,EACf;AAAA,EAEH,MAAa,gBACZ,QACA,cACA,UACA,cACA,eAC8B;AAC9B,UAAM,cAAc,IAAI,0BAA0B,cAAc,UAAU,cAAc,eAAe,SAAS;AAChH,UAAM,OAAO,aAAa,KAAK,WAAW;AAC1C,UAAM,SAAS,MAAM,KAAK;AAAA,MACzB,OAAO;AAAA,MACP;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,KAAK;AAAA,IAAA;AAEN,QAAI,OAAO,WAAW,mBAAmB,eAAe;AACvD,YAAM,aAAa,IAAI;AAAA,QACtB;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,OAAO,WAAW,mBAAmB;AAAA,MAAA;AAEtC,YAAM,OAAO,aAAa,KAAK,UAAU;AAAA,IAC1C;AACA,WAAO,CAAC,MAAM;AAAA,EACf;AAAA,EAEA,MAAa,mBACZ,QACA,cACA,UACA,cACA,eAC8B;AAC9B,UAAM,cAAc,IAAI,0BAA0B,cAAc,UAAU,cAAc,eAAe,SAAS;AAChH,UAAM,OAAO,aAAa,KAAK,WAAW;AAC1C,UAAM,SAAS,MAAM,KAAK;AAAA,MACzB,OAAO;AAAA,MACP;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,KAAK;AAAA,IAAA;AAEN,QAAI,OAAO,WAAW,mBAAmB,eAAe;AACvD,YAAM,aA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AgC,GAAG,UAAU,EACrE,OAAO,UAAQ,KAAK,IAAI,iCAAiC,GAAG,SAAS;AAEvE,UAAM,SAAS,MAAM,GAAG,UAAU,EAAE;AACpC,QAAI,OAAO,CAAC,EAAE,UAAU,MAAM,OAAO;AACpC,aAAO,IAAI,sBAAsB,EAAE;AAAA,IACpC;AACA,QAAI,OAAO,CAAC,EAAE,UAAU,MAAM,OAAO;AACpC,aAAO,IAAI,oBAAoB,IAAI,kBAAkB,aAAa;AAAA,IACnE;AACA,WAAO,gBAAA;AAAA,EACR;AACD;"}
1
+ {"version":3,"file":"JunctionTableManager.js","sources":["../../../../../packages/engine-content-api/src/mapper/JunctionTableManager.ts"],"sourcesContent":["import { getEntity } from '@contember/schema-utils'\nimport { PathFactory, WhereBuilder } from './select/index.js'\nimport { PredicateFactory } from '../acl/index.js'\nimport { Client, ConflictActionType, DeleteBuilder, InsertBuilder, Literal, Operator, SelectBuilder } from '@contember/database'\nimport { Acl, Input, Model } from '@contember/schema'\nimport {\n\tMutationJunctionUpdateOk,\n\tMutationNoResultError,\n\tMutationNothingToDo,\n\tMutationResultList,\n\tMutationResultType,\n\tNothingToDoReason,\n} from './Result.js'\nimport { ImplementationException } from '../exception.js'\nimport { AfterJunctionUpdateEvent, BeforeJunctionUpdateEvent } from './EventManager.js'\nimport { Mapper } from './Mapper.js'\n\ntype OkResultFactory = () => MutationJunctionUpdateOk\n\ntype JunctionMutationResult =\n\t| MutationJunctionUpdateOk\n\t| MutationNothingToDo\n\t| MutationNoResultError\n\nexport class JunctionTableManager {\n\tconstructor(\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly predicateFactory: PredicateFactory,\n\t\tprivate readonly whereBuilder: WhereBuilder,\n\t\tprivate readonly connectJunctionHandler: JunctionConnectHandler,\n\t\tprivate readonly disconnectJunctionHandler: JunctionDisconnectHandler,\n\t\tprivate readonly pathFactory: PathFactory,\n\t) {}\n\n\tpublic async connectJunction(\n\t\tmapper: Mapper,\n\t\towningEntity: Model.Entity,\n\t\trelation: Model.ManyHasManyOwningRelation,\n\t\towningUnique: Input.PrimaryValue,\n\t\tinverseUnique: Input.PrimaryValue,\n\t): Promise<MutationResultList> {\n\t\tconst beforeEvent = new BeforeJunctionUpdateEvent(owningEntity, relation, owningUnique, inverseUnique, 'connect')\n\t\tawait mapper.eventManager.fire(beforeEvent)\n\t\tconst result = await this.executeJunctionModification(\n\t\t\tmapper.db,\n\t\t\towningEntity,\n\t\t\trelation,\n\t\t\towningUnique,\n\t\t\tinverseUnique,\n\t\t\tthis.connectJunctionHandler,\n\t\t)\n\t\tif (result.result !== MutationResultType.noResultError) {\n\t\t\tconst afterEvent = new AfterJunctionUpdateEvent(\n\t\t\t\towningEntity,\n\t\t\t\trelation,\n\t\t\t\towningUnique,\n\t\t\t\tinverseUnique,\n\t\t\t\t'connect',\n\t\t\t\tresult.result === MutationResultType.ok,\n\t\t\t)\n\t\t\tawait mapper.eventManager.fire(afterEvent)\n\t\t}\n\t\treturn [result]\n\t}\n\n\tpublic async disconnectJunction(\n\t\tmapper: Mapper,\n\t\towningEntity: Model.Entity,\n\t\trelation: Model.ManyHasManyOwningRelation,\n\t\towningUnique: Input.PrimaryValue,\n\t\tinverseUnique: Input.PrimaryValue,\n\t): Promise<MutationResultList> {\n\t\tconst beforeEvent = new BeforeJunctionUpdateEvent(owningEntity, relation, owningUnique, inverseUnique, 'connect')\n\t\tawait mapper.eventManager.fire(beforeEvent)\n\t\tconst result = await this.executeJunctionModification(\n\t\t\tmapper.db,\n\t\t\towningEntity,\n\t\t\trelation,\n\t\t\towningUnique,\n\t\t\tinverseUnique,\n\t\t\tthis.disconnectJunctionHandler,\n\t\t)\n\t\tif (result.result !== MutationResultType.noResultError) {\n\t\t\tconst afterEvent = new AfterJunctionUpdateEvent(\n\t\t\t\towningEntity,\n\t\t\t\trelation,\n\t\t\t\towningUnique,\n\t\t\t\tinverseUnique,\n\t\t\t\t'disconnect',\n\t\t\t\tresult.result === MutationResultType.ok,\n\t\t\t)\n\t\t\tbeforeEvent.afterEvent = afterEvent\n\t\t\tawait mapper.eventManager.fire(afterEvent)\n\t\t}\n\t\treturn [result]\n\t}\n\n\tprivate async executeJunctionModification(\n\t\tdb: Client,\n\t\towningEntity: Model.Entity,\n\t\trelation: Model.ManyHasManyOwningRelation,\n\t\towningPrimary: Input.PrimaryValue,\n\t\tinversePrimary: Input.PrimaryValue,\n\t\thandler: JunctionHandler,\n\t): Promise<JunctionMutationResult> {\n\t\tconst joiningTable = relation.joiningTable\n\t\tconst inverseEntity = getEntity(this.schema, relation.target)\n\t\tif (inverseEntity.view || owningEntity.view) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\n\t\tconst owningPredicate = this.predicateFactory.create(owningEntity, Acl.Operation.update, [relation.name])\n\t\tlet inversePredicate: Input.OptionalWhere = {}\n\t\tif (relation.inversedBy) {\n\t\t\tinversePredicate = this.predicateFactory.create(inverseEntity, Acl.Operation.update, [relation.inversedBy])\n\t\t}\n\n\t\tconst hasNoPredicates = Object.keys(owningPredicate).length === 0 && Object.keys(inversePredicate).length === 0\n\n\t\tconst okResultFactory = () => new MutationJunctionUpdateOk([], owningEntity, relation, owningPrimary, inversePrimary)\n\t\tif (hasNoPredicates) {\n\t\t\treturn await handler.executeSimple({ db, joiningTable, owningPrimary, inversePrimary, okResultFactory })\n\t\t} else {\n\t\t\tconst owningWhere: Input.OptionalWhere = {\n\t\t\t\tand: [owningPredicate, { [owningEntity.primary]: { eq: owningPrimary } }],\n\t\t\t}\n\n\t\t\tconst inverseWhere: Input.OptionalWhere = {\n\t\t\t\tand: [inversePredicate, { [inverseEntity.primary]: { eq: inversePrimary } }],\n\t\t\t}\n\n\t\t\tconst dataCallback: SelectBuilder.Callback = qb => {\n\t\t\t\tqb = qb\n\t\t\t\t\t.select(expr => expr.select(['owning', owningEntity.primaryColumn]), joiningTable.joiningColumn.columnName)\n\t\t\t\t\t.select(\n\t\t\t\t\t\texpr => expr.select(['inverse', inverseEntity.primaryColumn]),\n\t\t\t\t\t\tjoiningTable.inverseJoiningColumn.columnName,\n\t\t\t\t\t)\n\t\t\t\t\t.select(expr => expr.raw('true'), 'selected')\n\t\t\t\t\t.from(new Literal('(values (null))'), 't')\n\t\t\t\t\t.join(owningEntity.tableName, 'owning', condition => condition.raw('true'))\n\t\t\t\t\t.join(inverseEntity.tableName, 'inverse', condition => condition.raw('true'))\n\t\t\t\tqb = this.whereBuilder.build(qb, owningEntity, this.pathFactory.create([], 'owning'), owningWhere)\n\t\t\t\tqb = this.whereBuilder.build(qb, inverseEntity, this.pathFactory.create([], 'inverse'), inverseWhere)\n\t\t\t\treturn qb\n\t\t\t}\n\n\t\t\treturn await handler.executeComplex({ db, joiningTable, dataCallback, okResultFactory })\n\t\t}\n\t}\n}\n\ninterface JunctionSimpleExecutionArgs {\n\tdb: Client\n\tjoiningTable: Model.JoiningTable\n\towningPrimary: Input.PrimaryValue\n\tinversePrimary: Input.PrimaryValue\n\tokResultFactory: OkResultFactory\n}\n\ninterface JunctionComplexExecutionArgs {\n\tdb: Client\n\tjoiningTable: Model.JoiningTable\n\tdataCallback: SelectBuilder.Callback\n\tokResultFactory: OkResultFactory\n}\n\ninterface JunctionHandler {\n\texecuteSimple(args: JunctionSimpleExecutionArgs): Promise<JunctionMutationResult>\n\n\texecuteComplex(args: JunctionComplexExecutionArgs): Promise<JunctionMutationResult>\n}\n\nexport class JunctionConnectHandler implements JunctionHandler {\n\tasync executeSimple({\n\t\tdb,\n\t\tjoiningTable,\n\t\towningPrimary,\n\t\tinversePrimary,\n\t\tokResultFactory,\n\t}: JunctionSimpleExecutionArgs): Promise<JunctionMutationResult> {\n\t\tconst result = await InsertBuilder.create()\n\t\t\t.into(joiningTable.tableName)\n\t\t\t.values({\n\t\t\t\t[joiningTable.joiningColumn.columnName]: expr => expr.selectValue(owningPrimary),\n\t\t\t\t[joiningTable.inverseJoiningColumn.columnName]: expr => expr.selectValue(inversePrimary),\n\t\t\t})\n\t\t\t.onConflict(ConflictActionType.doNothing)\n\t\t\t.execute(db)\n\t\tif (result === 0) {\n\t\t\treturn new MutationNothingToDo([], NothingToDoReason.alreadyExists)\n\t\t}\n\t\treturn okResultFactory()\n\t}\n\n\tasync executeComplex({\n\t\tdb,\n\t\tjoiningTable,\n\t\tdataCallback,\n\t\tokResultFactory,\n\t}: JunctionComplexExecutionArgs): Promise<JunctionMutationResult> {\n\t\tconst insert = InsertBuilder.create()\n\t\t\t.into(joiningTable.tableName)\n\t\t\t.values({\n\t\t\t\t[joiningTable.joiningColumn.columnName]: expr => expr.select(['data', joiningTable.joiningColumn.columnName]),\n\t\t\t\t[joiningTable.inverseJoiningColumn.columnName]: expr => expr.select(['data', joiningTable.inverseJoiningColumn.columnName]),\n\t\t\t})\n\t\t\t.returning(new Literal('true as inserted'))\n\t\t\t.from(qb => qb.from('data'))\n\t\t\t.onConflict(ConflictActionType.doNothing)\n\n\t\tconst qb = SelectBuilder.create()\n\t\t\t.with('data', dataCallback)\n\t\t\t.with('insert', insert)\n\t\t\t.from(new Literal('(values (null))'), 't')\n\t\t\t.leftJoin('data', 'data', condition => condition.raw('true'))\n\t\t\t.leftJoin('insert', 'insert', condition => condition.raw('true'))\n\t\t\t.select(expr => expr.raw('coalesce(data.selected, false)'), 'selected')\n\t\t\t.select(expr => expr.raw('coalesce(insert.inserted, false)'), 'inserted')\n\n\t\tconst result = await qb.getResult(db)\n\t\tif (result[0]['selected'] === false) {\n\t\t\treturn new MutationNoResultError([])\n\t\t}\n\t\tif (result[0]['inserted'] === false) {\n\t\t\treturn new MutationNothingToDo([], NothingToDoReason.alreadyExists)\n\t\t}\n\t\treturn okResultFactory()\n\t}\n}\n\nexport class JunctionDisconnectHandler implements JunctionHandler {\n\tpublic async executeSimple({\n\t\tdb,\n\t\tjoiningTable,\n\t\towningPrimary,\n\t\tinversePrimary,\n\t\tokResultFactory,\n\t}: JunctionSimpleExecutionArgs): Promise<JunctionMutationResult> {\n\t\tconst qb = DeleteBuilder.create()\n\t\t\t.from(joiningTable.tableName)\n\t\t\t.where(cond => cond.compare(joiningTable.joiningColumn.columnName, Operator.eq, owningPrimary))\n\t\t\t.where(cond => cond.compare(joiningTable.inverseJoiningColumn.columnName, Operator.eq, inversePrimary))\n\n\t\tconst result = await qb.execute(db)\n\t\tif (result === 0) {\n\t\t\treturn new MutationNothingToDo([], NothingToDoReason.alreadyExists)\n\t\t}\n\t\treturn okResultFactory()\n\t}\n\n\tpublic async executeComplex({\n\t\tdb,\n\t\tjoiningTable,\n\t\tdataCallback,\n\t\tokResultFactory,\n\t}: JunctionComplexExecutionArgs): Promise<JunctionMutationResult> {\n\t\tconst deleteQb = DeleteBuilder.create()\n\t\t\t.from(joiningTable.tableName)\n\t\t\t.using('data')\n\t\t\t.where(cond => {\n\t\t\t\tcond = cond.compareColumns([joiningTable.tableName, joiningTable.joiningColumn.columnName], Operator.eq, [\n\t\t\t\t\t'data',\n\t\t\t\t\tjoiningTable.joiningColumn.columnName,\n\t\t\t\t])\n\t\t\t\tcond = cond.compareColumns(\n\t\t\t\t\t[joiningTable.tableName, joiningTable.inverseJoiningColumn.columnName],\n\t\t\t\t\tOperator.eq,\n\t\t\t\t\t['data', joiningTable.inverseJoiningColumn.columnName],\n\t\t\t\t)\n\t\t\t\treturn cond\n\t\t\t})\n\t\t\t.returning(new Literal('true as deleted'))\n\n\t\tconst qb = SelectBuilder.create()\n\t\t\t.with('data', dataCallback)\n\t\t\t.with('delete', deleteQb)\n\t\t\t.from(new Literal('(values (null))'), 't')\n\t\t\t.leftJoin('data', 'data', condition => condition.raw('true'))\n\t\t\t.leftJoin('delete', 'delete', condition => condition.raw('true'))\n\t\t\t.select(expr => expr.raw('coalesce(data.selected, false)'), 'selected')\n\t\t\t.select(expr => expr.raw('coalesce(delete.deleted, false)'), 'deleted')\n\n\t\tconst result = await qb.getResult(db)\n\t\tif (result[0]['selected'] === false) {\n\t\t\treturn new MutationNoResultError([])\n\t\t}\n\t\tif (result[0]['inserted'] === false) {\n\t\t\treturn new MutationNothingToDo([], NothingToDoReason.alreadyExists)\n\t\t}\n\t\treturn okResultFactory()\n\t}\n}\n"],"names":["InsertBuilder","qb"],"mappings":";;;;;;AAwBO,MAAM,qBAAqB;AAAA,EACjC,YACkB,QACA,kBACA,cACA,wBACA,2BACA,aAChB;AANgB,SAAA,SAAA;AACA,SAAA,mBAAA;AACA,SAAA,eAAA;AACA,SAAA,yBAAA;AACA,SAAA,4BAAA;AACA,SAAA,cAAA;AAAA,EACf;AAAA,EAEH,MAAa,gBACZ,QACA,cACA,UACA,cACA,eAC8B;AAC9B,UAAM,cAAc,IAAI,0BAA0B,cAAc,UAAU,cAAc,eAAe,SAAS;AAChH,UAAM,OAAO,aAAa,KAAK,WAAW;AAC1C,UAAM,SAAS,MAAM,KAAK;AAAA,MACzB,OAAO;AAAA,MACP;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,KAAK;AAAA,IAAA;AAEN,QAAI,OAAO,WAAW,mBAAmB,eAAe;AACvD,YAAM,aAAa,IAAI;AAAA,QACtB;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,OAAO,WAAW,mBAAmB;AAAA,MAAA;AAEtC,YAAM,OAAO,aAAa,KAAK,UAAU;AAAA,IAC1C;AACA,WAAO,CAAC,MAAM;AAAA,EACf;AAAA,EAEA,MAAa,mBACZ,QACA,cACA,UACA,cACA,eAC8B;AAC9B,UAAM,cAAc,IAAI,0BAA0B,cAAc,UAAU,cAAc,eAAe,SAAS;AAChH,UAAM,OAAO,aAAa,KAAK,WAAW;AAC1C,UAAM,SAAS,MAAM,KAAK;AAAA,MACzB,OAAO;AAAA,MACP;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,KAAK;AAAA,IAAA;AAEN,QAAI,OAAO,WAAW,mBAAmB,eAAe;AACvD,YAAM,aAAa,IAAI;AAAA,QACtB;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,OAAO,WAAW,mBAAmB;AA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,UAAU,EAAE;AACpC,QAAI,OAAO,CAAC,EAAE,UAAU,MAAM,OAAO;AACpC,aAAO,IAAI,sBAAsB,EAAE;AAAA,IACpC;AACA,QAAI,OAAO,CAAC,EAAE,UAAU,MAAM,OAAO;AACpC,aAAO,IAAI,oBAAoB,IAAI,kBAAkB,aAAa;AAAA,IACnE;AACA,WAAO,gBAAA;AAAA,EACR;AACD;"}
@@ -17,7 +17,7 @@ var __defProp = Object.defineProperty;
17
17
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
18
18
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
19
19
  class Mapper {
20
- constructor(db, identityId, transactionId, schema, schemaDatabaseMetadata, predicatesInjector, selectBuilderFactory, uniqueWhereExpander, whereBuilder, junctionTableManager, deleteExecutor, updater, inserter, pathFactory) {
20
+ constructor(db, identityId, transactionId, schema, schemaDatabaseMetadata, predicatesInjector, selectBuilderFactory, uniqueWhereExpander, whereBuilder, junctionTableManager, deleteExecutor, updater, inserter, pathFactory, memoryBudget) {
21
21
  this.db = db;
22
22
  this.identityId = identityId;
23
23
  this.transactionId = transactionId;
@@ -32,12 +32,15 @@ class Mapper {
32
32
  this.updater = updater;
33
33
  this.inserter = inserter;
34
34
  this.pathFactory = pathFactory;
35
+ this.memoryBudget = memoryBudget;
35
36
  __publicField(this, "systemVariablesSetupDone");
36
37
  __publicField(this, "deletedEntities", new DeletedEntitiesStorage.DeletedEntitiesStorage());
37
38
  __publicField(this, "mutex", new Mutex.Mutex());
38
39
  __publicField(this, "constraintHelper");
40
+ __publicField(this, "selectionDb");
39
41
  __publicField(this, "eventManager");
40
42
  this.constraintHelper = new Database.ConstraintHelper(db, this.schemaDatabaseMetadata);
43
+ this.selectionDb = memoryBudget ? db.withMemoryBudget(memoryBudget, { chargeRows: true }) : db;
41
44
  this.eventManager = new EventManager.EventManager(this);
42
45
  }
43
46
  async selectField(entity, where, fieldName) {
@@ -50,7 +53,7 @@ class Mapper {
50
53
  return result[0] !== void 0 ? result[0][columnName] : void 0;
51
54
  }
52
55
  async selectAssoc(entity, input, relationPath, indexBy) {
53
- const hydrator = new SelectHydrator.SelectHydrator();
56
+ const hydrator = new SelectHydrator.SelectHydrator(this.memoryBudget);
54
57
  const path = this.pathFactory.create([]);
55
58
  const indexByAlias = path.for(indexBy).alias;
56
59
  const qb = Database.SelectBuilder.create().select([path.alias, schemaUtils.getColumnName(this.schema, entity, indexBy)], indexByAlias);
@@ -58,7 +61,7 @@ class Mapper {
58
61
  return await hydrator.hydrateAll(rows, indexByAlias);
59
62
  }
60
63
  async select(entity, input, relationPath) {
61
- const hydrator = new SelectHydrator.SelectHydrator();
64
+ const hydrator = new SelectHydrator.SelectHydrator(this.memoryBudget);
62
65
  const qb = Database.SelectBuilder.create();
63
66
  const rows = await this.selectRows(hydrator, qb, entity, input, relationPath);
64
67
  return await hydrator.hydrateAll(rows);
@@ -71,7 +74,7 @@ class Mapper {
71
74
  return rows[0] ?? null;
72
75
  }
73
76
  async selectGrouped(entity, input, relation, relationPath) {
74
- const hydrator = new SelectHydrator.SelectHydrator();
77
+ const hydrator = new SelectHydrator.SelectHydrator(this.memoryBudget);
75
78
  const path = this.pathFactory.create([]);
76
79
  const groupingKey = "__grouping_key";
77
80
  const qb = Database.SelectBuilder.create().select([path.alias, relation.joiningColumn.columnName], groupingKey);
@@ -91,7 +94,7 @@ class Mapper {
91
94
  );
92
95
  const inputWithPredicates = inputWithOrder.withArg("filter", filterWithPredicates);
93
96
  selector.select(this, entity, inputWithPredicates, path, groupBy);
94
- return await selector.execute(this.db);
97
+ return await selector.execute(this.selectionDb);
95
98
  }
96
99
  async count(entity, filter) {
97
100
  const path = this.pathFactory.create([]);
@@ -1 +1 @@
1
- {"version":3,"file":"Mapper.cjs","sources":["../../../../../packages/engine-content-api/src/mapper/Mapper.ts"],"sourcesContent":["import { Input, Model } from '@contember/schema'\nimport { acceptFieldVisitor, getColumnName } from '@contember/schema-utils'\nimport {\n\tOrderByHelper,\n\tPathFactory,\n\tSelectBuilderFactory,\n\tSelectGroupedObjects,\n\tSelectHydrator,\n\tSelectIndexedResultObjects,\n\tSelectResultObject,\n\tWhereBuilder,\n} from './select'\nimport { Client, Connection, ConstraintHelper, DatabaseMetadata, SelectBuilder } from '@contember/database'\nimport { PredicatesInjector } from '../acl'\nimport { JunctionTableManager } from './JunctionTableManager'\nimport { DeletedEntitiesStorage, DeleteExecutor } from './delete'\nimport { MutationEntryNotFoundError, MutationResultList } from './Result'\nimport { UpdateBuilder, Updater } from './update'\nimport { InsertBuilder, Inserter } from './insert'\nimport { tryMutation } from './ErrorUtils'\nimport { ObjectNode, UniqueWhereExpander } from '../inputProcessing'\nimport { Mutex } from '../utils'\nimport { CheckedPrimary } from './CheckedPrimary'\nimport { ImplementationException } from '../exception'\nimport { EventManager } from './EventManager'\nimport { MapperInput } from './types'\n\nexport class Mapper<ConnectionType extends Connection.ConnectionLike = Connection.ConnectionLike> {\n\tprivate systemVariablesSetupDone: Promise<void> | undefined\n\tpublic readonly deletedEntities = new DeletedEntitiesStorage()\n\tpublic readonly mutex = new Mutex()\n\tpublic readonly constraintHelper: ConstraintHelper\n\n\tpublic readonly eventManager: EventManager\n\n\tconstructor(\n\t\tpublic readonly db: Client<ConnectionType>,\n\t\tpublic readonly identityId: string,\n\t\tpublic readonly transactionId: string,\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly schemaDatabaseMetadata: DatabaseMetadata,\n\t\tprivate readonly predicatesInjector: PredicatesInjector,\n\t\tprivate readonly selectBuilderFactory: SelectBuilderFactory,\n\t\tprivate readonly uniqueWhereExpander: UniqueWhereExpander,\n\t\tprivate readonly whereBuilder: WhereBuilder,\n\t\tprivate readonly junctionTableManager: JunctionTableManager,\n\t\tprivate readonly deleteExecutor: DeleteExecutor,\n\t\tprivate readonly updater: Updater,\n\t\tprivate readonly inserter: Inserter,\n\t\tprivate readonly pathFactory: PathFactory,\n\t) {\n\t\tthis.constraintHelper = new ConstraintHelper(db, this.schemaDatabaseMetadata)\n\t\tthis.eventManager = new EventManager(this)\n\t}\n\n\tpublic async selectField(entity: Model.Entity, where: Input.UniqueWhere | CheckedPrimary, fieldName: string) {\n\t\tconst columnName = getColumnName(this.schema, entity, fieldName)\n\n\t\tconst qb = SelectBuilder.create() //\n\t\t\t.from(entity.tableName, 'root_')\n\t\t\t.select(['root_', columnName])\n\t\tconst expandedWhere = this.uniqueWhereExpander.expand(entity, where)\n\t\tconst withPredicates = this.predicatesInjector.inject(entity, expandedWhere)\n\t\tconst builtQb = this.whereBuilder.build(qb, entity, this.pathFactory.create([]), withPredicates)\n\t\tconst result = await builtQb.getResult(this.db)\n\n\t\treturn result[0] !== undefined ? result[0][columnName] : undefined\n\t}\n\n\tpublic async selectAssoc(\n\t\tentity: Model.Entity,\n\t\tinput: ObjectNode<Input.ListQueryInput>,\n\t\trelationPath: Model.AnyRelationContext[],\n\t\tindexBy: string,\n\t): Promise<SelectIndexedResultObjects> {\n\t\tconst hydrator = new SelectHydrator()\n\t\tconst path = this.pathFactory.create([])\n\t\tconst indexByAlias: string = path.for(indexBy).alias\n\t\tconst qb: SelectBuilder = SelectBuilder.create()\n\t\t\t.select([path.alias, getColumnName(this.schema, entity, indexBy)], indexByAlias)\n\t\tconst rows = await this.selectRows(hydrator, qb, entity, input, relationPath)\n\t\treturn await hydrator.hydrateAll(rows, indexByAlias)\n\t}\n\n\tpublic async select(\n\t\tentity: Model.Entity,\n\t\tinput: ObjectNode<Input.ListQueryInput>,\n\t\trelationPath: Model.AnyRelationContext[],\n\t): Promise<SelectResultObject[]> {\n\t\tconst hydrator = new SelectHydrator()\n\t\tconst qb: SelectBuilder<SelectBuilder.Result> = SelectBuilder.create()\n\n\t\tconst rows = await this.selectRows(hydrator, qb, entity, input, relationPath)\n\n\t\treturn await hydrator.hydrateAll(rows)\n\t}\n\n\tpublic async selectUnique(\n\t\tentity: Model.Entity,\n\t\tquery: ObjectNode<Input.UniqueQueryInput>,\n\t\trelationPath: Model.AnyRelationContext[],\n\t): Promise<SelectResultObject | null> {\n\t\tconst uniqueWhere = this.uniqueWhereExpander.expand(entity, query.args.by)\n\t\tconst where = query.args.filter ? { and: [uniqueWhere, query.args.filter] } : uniqueWhere\n\t\tconst queryExpanded = query.withArg<Input.ListQueryInput>('filter', where)\n\n\t\tconst rows = await this.select(entity, queryExpanded, relationPath)\n\n\t\treturn rows[0] ?? null\n\t}\n\n\tpublic async selectGrouped(\n\t\tentity: Model.Entity,\n\t\tinput: ObjectNode<Input.ListQueryInput>,\n\t\trelation: Model.JoiningColumnRelation & Model.AnyRelation,\n\t\trelationPath: Model.AnyRelationContext[],\n\t): Promise<SelectGroupedObjects> {\n\t\tconst hydrator = new SelectHydrator()\n\t\tconst path = this.pathFactory.create([])\n\t\tconst groupingKey = '__grouping_key'\n\t\tconst qb: SelectBuilder = SelectBuilder.create()\n\t\t\t.select([path.alias, relation.joiningColumn.columnName], groupingKey)\n\n\t\tconst rows = await this.selectRows(hydrator, qb, entity, input, relationPath, relation.name)\n\n\t\treturn await hydrator.hydrateGroups(rows, groupingKey)\n\t}\n\n\tprivate async selectRows(\n\t\thydrator: SelectHydrator,\n\t\tqb: SelectBuilder<SelectBuilder.Result>,\n\t\tentity: Model.Entity,\n\t\tinput: ObjectNode<Input.ListQueryInput>,\n\t\trelationPath: Model.AnyRelationContext[],\n\t\tgroupBy?: string,\n\t) {\n\t\tconst inputWithOrder = OrderByHelper.appendDefaultOrderBy(entity, input, undefined)\n\t\tconst path = this.pathFactory.create([])\n\t\tconst augmentedBuilder = qb.from(entity.tableName, path.alias).meta('path', [...input.path, input.alias])\n\n\t\tconst selector = this.selectBuilderFactory.create(augmentedBuilder, hydrator, relationPath)\n\t\tconst filterWithPredicates = this.predicatesInjector.inject(\n\t\t\tentity,\n\t\t\tinputWithOrder.args.filter || {},\n\t\t\trelationPath[relationPath.length - 1],\n\t\t\trelationPath,\n\t\t)\n\t\tconst inputWithPredicates = inputWithOrder.withArg('filter', filterWithPredicates)\n\t\tselector.select(this, entity, inputWithPredicates, path, groupBy)\n\t\treturn await selector.execute(this.db)\n\t}\n\n\tpublic async count(entity: Model.Entity, filter: Input.OptionalWhere) {\n\t\tconst path = this.pathFactory.create([])\n\t\tconst qb = SelectBuilder.create()\n\t\t\t.from(entity.tableName, path.alias)\n\t\t\t.select(expr => expr.raw('count(*)'), 'row_count')\n\t\tconst withPredicates = this.predicatesInjector.inject(entity, filter)\n\t\tconst qbWithWhere = this.whereBuilder.build(qb, entity, path, withPredicates)\n\t\tconst result = await qbWithWhere.getResult(this.db)\n\t\treturn result[0].row_count\n\t}\n\n\tpublic async countGrouped(\n\t\tentity: Model.Entity,\n\t\tfilter: Input.OptionalWhere,\n\t\trelation: Model.JoiningColumnRelation & Model.Relation,\n\t\trelationPath: Model.AnyRelationContext[],\n\t): Promise<Record<string, number>> {\n\t\tconst path = this.pathFactory.create([])\n\t\tconst qb = SelectBuilder.create()\n\t\t\t.from(entity.tableName, path.alias)\n\t\t\t.select(expr => expr.raw('count(*)'), 'row_count')\n\t\t\t.select([path.alias, relation.joiningColumn.columnName])\n\t\t\t.groupBy([path.alias, relation.joiningColumn.columnName])\n\t\tconst withPredicates = this.predicatesInjector.inject(entity, filter, relationPath[relationPath.length - 1], relationPath)\n\t\tconst qbWithWhere = this.whereBuilder.build(qb, entity, path, withPredicates, { relationPath })\n\t\tconst rows = await qbWithWhere.getResult(this.db)\n\t\tconst result = new Map<string, number>()\n\t\tfor (const row of rows) {\n\t\t\tresult.set(String(row[relation.joiningColumn.columnName]), Number(row.row_count))\n\t\t}\n\t\treturn Object.fromEntries(result)\n\t}\n\n\tpublic async insert(\n\t\tentity: Model.Entity,\n\t\tdata: MapperInput.CreateDataInput,\n\t\tbuilderCb: (builder: InsertBuilder) => void = () => {},\n\t): Promise<MutationResultList> {\n\t\tif (entity.view) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\tawait this.setupSystemVariables()\n\t\treturn tryMutation(this.schema, this.schemaDatabaseMetadata, () => this.insertInternal(entity, data, builderCb))\n\t}\n\n\tpublic async update(\n\t\tentity: Model.Entity,\n\t\tby: Input.UniqueWhere | CheckedPrimary,\n\t\tdata: MapperInput.UpdateDataInput,\n\t\tfilter?: Input.OptionalWhere,\n\t): Promise<MutationResultList> {\n\t\tif (entity.view) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\tawait this.setupSystemVariables()\n\t\treturn tryMutation(this.schema, this.schemaDatabaseMetadata, async () => {\n\t\t\tconst [primaryValue, err] = await this.getPrimaryValue(entity, by)\n\t\t\tif (err) return [err]\n\n\t\t\treturn await this.updater.update(this, entity, primaryValue, data, filter)\n\t\t})\n\t}\n\n\tpublic async updateInternal(\n\t\tentity: Model.Entity,\n\t\tby: Input.UniqueWhere | CheckedPrimary,\n\t\tbuilderCb: (builder: UpdateBuilder) => void,\n\t): Promise<MutationResultList> {\n\t\tif (entity.view) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\tawait this.setupSystemVariables()\n\t\treturn tryMutation(this.schema, this.schemaDatabaseMetadata, async () => {\n\t\t\tconst [primaryValue, err] = await this.getPrimaryValue(entity, by)\n\t\t\tif (err) return [err]\n\n\t\t\treturn await this.updater.updateCb(this, entity, primaryValue, builderCb)\n\t\t})\n\t}\n\tpublic async upsert(\n\t\tentity: Model.Entity,\n\t\tby: Input.UniqueWhere | CheckedPrimary,\n\t\tupdate: MapperInput.UpdateDataInput,\n\t\tcreate: MapperInput.CreateDataInput,\n\t\tfilter?: Input.OptionalWhere,\n\t): Promise<MutationResultList> {\n\t\tif (entity.view) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\tawait this.setupSystemVariables()\n\t\treturn tryMutation(this.schema, this.schemaDatabaseMetadata, async () => {\n\t\t\tconst [primaryValue] = await this.getPrimaryValue(entity, by)\n\t\t\tif (primaryValue === undefined) {\n\t\t\t\treturn await this.insertInternal(entity, create)\n\t\t\t}\n\t\t\treturn await this.updater.update(this, entity, primaryValue, update, filter)\n\t\t})\n\t}\n\n\tprivate insertInternal(entity: Model.Entity, data: MapperInput.CreateDataInput, builderCb: (builder: InsertBuilder) => void = () => {}) {\n\t\treturn this.inserter.insert(this, entity, data, id => {\n\t\t}, builderCb)\n\t}\n\n\tpublic async delete(\n\t\tentity: Model.Entity,\n\t\tby: Input.UniqueWhere | CheckedPrimary,\n\t\tfilter?: Input.OptionalWhere,\n\t): Promise<MutationResultList> {\n\t\tif (entity.view) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\tawait this.setupSystemVariables()\n\t\treturn tryMutation(this.schema, this.schemaDatabaseMetadata, () => {\n\t\t\treturn this.deleteExecutor.execute(this, entity, by, filter)\n\t\t})\n\t}\n\n\tpublic async connectJunction(\n\t\tentity: Model.Entity,\n\t\trelation: Model.ManyHasManyOwningRelation | Model.ManyHasManyInverseRelation,\n\t\tthisPrimary: Input.PrimaryValue,\n\t\totherPrimary: Input.PrimaryValue,\n\t): Promise<MutationResultList> {\n\t\tawait this.setupSystemVariables()\n\t\tconst err = () => {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\treturn await acceptFieldVisitor(this.schema, entity, relation, {\n\t\t\tvisitManyHasManyOwning: ({ entity, relation }) => {\n\t\t\t\treturn this.junctionTableManager.connectJunction(this, entity, relation, thisPrimary, otherPrimary)\n\t\t\t},\n\t\t\tvisitManyHasManyInverse: ({ targetEntity, targetRelation }) => {\n\t\t\t\treturn this.junctionTableManager.connectJunction(this, targetEntity, targetRelation, otherPrimary, thisPrimary)\n\t\t\t},\n\t\t\tvisitColumn: err,\n\t\t\tvisitOneHasMany: err,\n\t\t\tvisitOneHasOneInverse: err,\n\t\t\tvisitOneHasOneOwning: err,\n\t\t\tvisitManyHasOne: err,\n\t\t})\n\t}\n\n\tpublic async disconnectJunction(\n\t\tentity: Model.Entity,\n\t\trelation: Model.ManyHasManyOwningRelation | Model.ManyHasManyInverseRelation,\n\t\tthisPrimary: Input.PrimaryValue,\n\t\totherPrimary: Input.PrimaryValue,\n\t): Promise<MutationResultList> {\n\t\tawait this.setupSystemVariables()\n\t\tconst err = () => {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\treturn await acceptFieldVisitor(this.schema, entity, relation, {\n\t\t\tvisitManyHasManyOwning: ({ entity, relation }) => {\n\t\t\t\treturn this.junctionTableManager.disconnectJunction(this, entity, relation, thisPrimary, otherPrimary)\n\t\t\t},\n\t\t\tvisitManyHasManyInverse: ({ targetEntity, targetRelation }) => {\n\t\t\t\treturn this.junctionTableManager.disconnectJunction(this, targetEntity, targetRelation, otherPrimary, thisPrimary)\n\t\t\t},\n\t\t\tvisitColumn: err,\n\t\t\tvisitOneHasMany: err,\n\t\t\tvisitOneHasOneInverse: err,\n\t\t\tvisitOneHasOneOwning: err,\n\t\t\tvisitManyHasOne: err,\n\t\t})\n\t}\n\n\tpublic async getPrimaryValue(\n\t\tentity: Model.Entity,\n\t\twhere: Input.UniqueWhere | CheckedPrimary,\n\t): Promise<[Input.PrimaryValue, undefined] | [undefined, MutationEntryNotFoundError]> {\n\t\tif (where instanceof CheckedPrimary) {\n\t\t\treturn [where.primaryValue, undefined]\n\t\t}\n\t\tconst result = await this.selectField(entity, where, entity.primary)\n\t\treturn result ? [result, undefined] : [undefined, new MutationEntryNotFoundError([], where)]\n\t}\n\n\tprivate async setupSystemVariables() {\n\t\tthis.systemVariablesSetupDone ??= (async () => {\n\t\t\tawait this.db.query('SELECT set_config(?, ?, false)', ['tenant.identity_id', this.identityId]) // todo rename to system.identity_id\n\t\t\tawait this.db.query('SELECT set_config(?, ?, false)', ['system.transaction_id', this.transactionId])\n\t\t})()\n\t\tawait this.systemVariablesSetupDone\n\t}\n}\n"],"names":["DeletedEntitiesStorage","Mutex","ConstraintHelper","EventManager","getColumnName","SelectBuilder","SelectHydrator","OrderByHelper","ImplementationException","tryMutation","acceptFieldVisitor","entity","relation","CheckedPrimary","MutationEntryNotFoundError"],"mappings":";;;;;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Ac,WAAW;AAAA,MAClH;AAAA,MACA,aAAa;AAAA,MACb,iBAAiB;AAAA,MACjB,uBAAuB;AAAA,MACvB,sBAAsB;AAAA,MACtB,iBAAiB;AAAA,IAAA,CACjB;AAAA,EACF;AAAA,EAEA,MAAa,gBACZ,QACA,OACqF;AACrF,QAAI,iBAAiBC,eAAAA,gBAAgB;AACpC,aAAO,CAAC,MAAM,cAAc,MAAS;AAAA,IACtC;AACA,UAAM,SAAS,MAAM,KAAK,YAAY,QAAQ,OAAO,OAAO,OAAO;AACnE,WAAO,SAAS,CAAC,QAAQ,MAAS,IAAI,CAAC,QAAW,IAAIC,OAAAA,2BAA2B,IAAI,KAAK,CAAC;AAAA,EAC5F;AAAA,EAEA,MAAc,uBAAuB;AACpC,SAAK,6BAAL,KAAK,4BAA8B,YAAY;AAC9C,YAAM,KAAK,GAAG,MAAM,kCAAkC,CAAC,sBAAsB,KAAK,UAAU,CAAC;AAC7F,YAAM,KAAK,GAAG,MAAM,kCAAkC,CAAC,yBAAyB,KAAK,aAAa,CAAC;AAAA,IACpG;AACA,UAAM,KAAK;AAAA,EACZ;AACD;;"}
1
+ {"version":3,"file":"Mapper.cjs","sources":["../../../../../packages/engine-content-api/src/mapper/Mapper.ts"],"sourcesContent":["import { Input, Model } from '@contember/schema'\nimport { acceptFieldVisitor, getColumnName } from '@contember/schema-utils'\nimport {\n\tOrderByHelper,\n\tPathFactory,\n\tSelectBuilderFactory,\n\tSelectGroupedObjects,\n\tSelectHydrator,\n\tSelectIndexedResultObjects,\n\tSelectResultObject,\n\tWhereBuilder,\n} from './select/index.js'\nimport { Client, Connection, ConstraintHelper, DatabaseMetadata, RequestMemoryBudget, SelectBuilder } from '@contember/database'\nimport { PredicatesInjector } from '../acl/index.js'\nimport { JunctionTableManager } from './JunctionTableManager.js'\nimport { DeletedEntitiesStorage, DeleteExecutor } from './delete/index.js'\nimport { MutationEntryNotFoundError, MutationResultList } from './Result.js'\nimport { UpdateBuilder, Updater } from './update/index.js'\nimport { InsertBuilder, Inserter } from './insert/index.js'\nimport { tryMutation } from './ErrorUtils.js'\nimport { ObjectNode, UniqueWhereExpander } from '../inputProcessing/index.js'\nimport { Mutex } from '../utils/index.js'\nimport { CheckedPrimary } from './CheckedPrimary.js'\nimport { ImplementationException } from '../exception.js'\nimport { EventManager } from './EventManager.js'\nimport { MapperInput } from './types.js'\n\nexport class Mapper<ConnectionType extends Connection.ConnectionLike = Connection.ConnectionLike> {\n\tprivate systemVariablesSetupDone: Promise<void> | undefined\n\tpublic readonly deletedEntities = new DeletedEntitiesStorage()\n\tpublic readonly mutex = new Mutex()\n\tpublic readonly constraintHelper: ConstraintHelper\n\t/** Charges the request memory budget; only selection results use it, internal mutation queries stay on `db`. */\n\tpublic readonly selectionDb: Client<ConnectionType>\n\n\tpublic readonly eventManager: EventManager\n\n\tconstructor(\n\t\tpublic readonly db: Client<ConnectionType>,\n\t\tpublic readonly identityId: string,\n\t\tpublic readonly transactionId: string,\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly schemaDatabaseMetadata: DatabaseMetadata,\n\t\tprivate readonly predicatesInjector: PredicatesInjector,\n\t\tprivate readonly selectBuilderFactory: SelectBuilderFactory,\n\t\tprivate readonly uniqueWhereExpander: UniqueWhereExpander,\n\t\tprivate readonly whereBuilder: WhereBuilder,\n\t\tprivate readonly junctionTableManager: JunctionTableManager,\n\t\tprivate readonly deleteExecutor: DeleteExecutor,\n\t\tprivate readonly updater: Updater,\n\t\tprivate readonly inserter: Inserter,\n\t\tprivate readonly pathFactory: PathFactory,\n\t\tprivate readonly memoryBudget?: RequestMemoryBudget,\n\t) {\n\t\tthis.constraintHelper = new ConstraintHelper(db, this.schemaDatabaseMetadata)\n\t\tthis.selectionDb = memoryBudget ? db.withMemoryBudget(memoryBudget, { chargeRows: true }) : db\n\t\tthis.eventManager = new EventManager(this)\n\t}\n\n\tpublic async selectField(entity: Model.Entity, where: Input.UniqueWhere | CheckedPrimary, fieldName: string) {\n\t\tconst columnName = getColumnName(this.schema, entity, fieldName)\n\n\t\tconst qb = SelectBuilder.create() //\n\t\t\t.from(entity.tableName, 'root_')\n\t\t\t.select(['root_', columnName])\n\t\tconst expandedWhere = this.uniqueWhereExpander.expand(entity, where)\n\t\tconst withPredicates = this.predicatesInjector.inject(entity, expandedWhere)\n\t\tconst builtQb = this.whereBuilder.build(qb, entity, this.pathFactory.create([]), withPredicates)\n\t\tconst result = await builtQb.getResult(this.db)\n\n\t\treturn result[0] !== undefined ? result[0][columnName] : undefined\n\t}\n\n\tpublic async selectAssoc(\n\t\tentity: Model.Entity,\n\t\tinput: ObjectNode<Input.ListQueryInput>,\n\t\trelationPath: Model.AnyRelationContext[],\n\t\tindexBy: string,\n\t): Promise<SelectIndexedResultObjects> {\n\t\tconst hydrator = new SelectHydrator(this.memoryBudget)\n\t\tconst path = this.pathFactory.create([])\n\t\tconst indexByAlias: string = path.for(indexBy).alias\n\t\tconst qb: SelectBuilder = SelectBuilder.create()\n\t\t\t.select([path.alias, getColumnName(this.schema, entity, indexBy)], indexByAlias)\n\t\tconst rows = await this.selectRows(hydrator, qb, entity, input, relationPath)\n\t\treturn await hydrator.hydrateAll(rows, indexByAlias)\n\t}\n\n\tpublic async select(\n\t\tentity: Model.Entity,\n\t\tinput: ObjectNode<Input.ListQueryInput>,\n\t\trelationPath: Model.AnyRelationContext[],\n\t): Promise<SelectResultObject[]> {\n\t\tconst hydrator = new SelectHydrator(this.memoryBudget)\n\t\tconst qb: SelectBuilder<SelectBuilder.Result> = SelectBuilder.create()\n\n\t\tconst rows = await this.selectRows(hydrator, qb, entity, input, relationPath)\n\n\t\treturn await hydrator.hydrateAll(rows)\n\t}\n\n\tpublic async selectUnique(\n\t\tentity: Model.Entity,\n\t\tquery: ObjectNode<Input.UniqueQueryInput>,\n\t\trelationPath: Model.AnyRelationContext[],\n\t): Promise<SelectResultObject | null> {\n\t\tconst uniqueWhere = this.uniqueWhereExpander.expand(entity, query.args.by)\n\t\tconst where = query.args.filter ? { and: [uniqueWhere, query.args.filter] } : uniqueWhere\n\t\tconst queryExpanded = query.withArg<Input.ListQueryInput>('filter', where)\n\n\t\tconst rows = await this.select(entity, queryExpanded, relationPath)\n\n\t\treturn rows[0] ?? null\n\t}\n\n\tpublic async selectGrouped(\n\t\tentity: Model.Entity,\n\t\tinput: ObjectNode<Input.ListQueryInput>,\n\t\trelation: Model.JoiningColumnRelation & Model.AnyRelation,\n\t\trelationPath: Model.AnyRelationContext[],\n\t): Promise<SelectGroupedObjects> {\n\t\tconst hydrator = new SelectHydrator(this.memoryBudget)\n\t\tconst path = this.pathFactory.create([])\n\t\tconst groupingKey = '__grouping_key'\n\t\tconst qb: SelectBuilder = SelectBuilder.create()\n\t\t\t.select([path.alias, relation.joiningColumn.columnName], groupingKey)\n\n\t\tconst rows = await this.selectRows(hydrator, qb, entity, input, relationPath, relation.name)\n\n\t\treturn await hydrator.hydrateGroups(rows, groupingKey)\n\t}\n\n\tprivate async selectRows(\n\t\thydrator: SelectHydrator,\n\t\tqb: SelectBuilder<SelectBuilder.Result>,\n\t\tentity: Model.Entity,\n\t\tinput: ObjectNode<Input.ListQueryInput>,\n\t\trelationPath: Model.AnyRelationContext[],\n\t\tgroupBy?: string,\n\t) {\n\t\tconst inputWithOrder = OrderByHelper.appendDefaultOrderBy(entity, input, undefined)\n\t\tconst path = this.pathFactory.create([])\n\t\tconst augmentedBuilder = qb.from(entity.tableName, path.alias).meta('path', [...input.path, input.alias])\n\n\t\tconst selector = this.selectBuilderFactory.create(augmentedBuilder, hydrator, relationPath)\n\t\tconst filterWithPredicates = this.predicatesInjector.inject(\n\t\t\tentity,\n\t\t\tinputWithOrder.args.filter || {},\n\t\t\trelationPath[relationPath.length - 1],\n\t\t\trelationPath,\n\t\t)\n\t\tconst inputWithPredicates = inputWithOrder.withArg('filter', filterWithPredicates)\n\t\tselector.select(this, entity, inputWithPredicates, path, groupBy)\n\t\treturn await selector.execute(this.selectionDb)\n\t}\n\n\tpublic async count(entity: Model.Entity, filter: Input.OptionalWhere) {\n\t\tconst path = this.pathFactory.create([])\n\t\tconst qb = SelectBuilder.create()\n\t\t\t.from(entity.tableName, path.alias)\n\t\t\t.select(expr => expr.raw('count(*)'), 'row_count')\n\t\tconst withPredicates = this.predicatesInjector.inject(entity, filter)\n\t\tconst qbWithWhere = this.whereBuilder.build(qb, entity, path, withPredicates)\n\t\tconst result = await qbWithWhere.getResult(this.db)\n\t\treturn result[0].row_count\n\t}\n\n\tpublic async countGrouped(\n\t\tentity: Model.Entity,\n\t\tfilter: Input.OptionalWhere,\n\t\trelation: Model.JoiningColumnRelation & Model.Relation,\n\t\trelationPath: Model.AnyRelationContext[],\n\t): Promise<Record<string, number>> {\n\t\tconst path = this.pathFactory.create([])\n\t\tconst qb = SelectBuilder.create()\n\t\t\t.from(entity.tableName, path.alias)\n\t\t\t.select(expr => expr.raw('count(*)'), 'row_count')\n\t\t\t.select([path.alias, relation.joiningColumn.columnName])\n\t\t\t.groupBy([path.alias, relation.joiningColumn.columnName])\n\t\tconst withPredicates = this.predicatesInjector.inject(entity, filter, relationPath[relationPath.length - 1], relationPath)\n\t\tconst qbWithWhere = this.whereBuilder.build(qb, entity, path, withPredicates, { relationPath })\n\t\tconst rows = await qbWithWhere.getResult(this.db)\n\t\tconst result = new Map<string, number>()\n\t\tfor (const row of rows) {\n\t\t\tresult.set(String(row[relation.joiningColumn.columnName]), Number(row.row_count))\n\t\t}\n\t\treturn Object.fromEntries(result)\n\t}\n\n\tpublic async insert(\n\t\tentity: Model.Entity,\n\t\tdata: MapperInput.CreateDataInput,\n\t\tbuilderCb: (builder: InsertBuilder) => void = () => {},\n\t): Promise<MutationResultList> {\n\t\tif (entity.view) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\tawait this.setupSystemVariables()\n\t\treturn tryMutation(this.schema, this.schemaDatabaseMetadata, () => this.insertInternal(entity, data, builderCb))\n\t}\n\n\tpublic async update(\n\t\tentity: Model.Entity,\n\t\tby: Input.UniqueWhere | CheckedPrimary,\n\t\tdata: MapperInput.UpdateDataInput,\n\t\tfilter?: Input.OptionalWhere,\n\t): Promise<MutationResultList> {\n\t\tif (entity.view) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\tawait this.setupSystemVariables()\n\t\treturn tryMutation(this.schema, this.schemaDatabaseMetadata, async () => {\n\t\t\tconst [primaryValue, err] = await this.getPrimaryValue(entity, by)\n\t\t\tif (err) return [err]\n\n\t\t\treturn await this.updater.update(this, entity, primaryValue, data, filter)\n\t\t})\n\t}\n\n\tpublic async updateInternal(\n\t\tentity: Model.Entity,\n\t\tby: Input.UniqueWhere | CheckedPrimary,\n\t\tbuilderCb: (builder: UpdateBuilder) => void,\n\t): Promise<MutationResultList> {\n\t\tif (entity.view) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\tawait this.setupSystemVariables()\n\t\treturn tryMutation(this.schema, this.schemaDatabaseMetadata, async () => {\n\t\t\tconst [primaryValue, err] = await this.getPrimaryValue(entity, by)\n\t\t\tif (err) return [err]\n\n\t\t\treturn await this.updater.updateCb(this, entity, primaryValue, builderCb)\n\t\t})\n\t}\n\tpublic async upsert(\n\t\tentity: Model.Entity,\n\t\tby: Input.UniqueWhere | CheckedPrimary,\n\t\tupdate: MapperInput.UpdateDataInput,\n\t\tcreate: MapperInput.CreateDataInput,\n\t\tfilter?: Input.OptionalWhere,\n\t): Promise<MutationResultList> {\n\t\tif (entity.view) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\tawait this.setupSystemVariables()\n\t\treturn tryMutation(this.schema, this.schemaDatabaseMetadata, async () => {\n\t\t\tconst [primaryValue] = await this.getPrimaryValue(entity, by)\n\t\t\tif (primaryValue === undefined) {\n\t\t\t\treturn await this.insertInternal(entity, create)\n\t\t\t}\n\t\t\treturn await this.updater.update(this, entity, primaryValue, update, filter)\n\t\t})\n\t}\n\n\tprivate insertInternal(entity: Model.Entity, data: MapperInput.CreateDataInput, builderCb: (builder: InsertBuilder) => void = () => {}) {\n\t\treturn this.inserter.insert(this, entity, data, id => {\n\t\t}, builderCb)\n\t}\n\n\tpublic async delete(\n\t\tentity: Model.Entity,\n\t\tby: Input.UniqueWhere | CheckedPrimary,\n\t\tfilter?: Input.OptionalWhere,\n\t): Promise<MutationResultList> {\n\t\tif (entity.view) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\tawait this.setupSystemVariables()\n\t\treturn tryMutation(this.schema, this.schemaDatabaseMetadata, () => {\n\t\t\treturn this.deleteExecutor.execute(this, entity, by, filter)\n\t\t})\n\t}\n\n\tpublic async connectJunction(\n\t\tentity: Model.Entity,\n\t\trelation: Model.ManyHasManyOwningRelation | Model.ManyHasManyInverseRelation,\n\t\tthisPrimary: Input.PrimaryValue,\n\t\totherPrimary: Input.PrimaryValue,\n\t): Promise<MutationResultList> {\n\t\tawait this.setupSystemVariables()\n\t\tconst err = () => {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\treturn await acceptFieldVisitor(this.schema, entity, relation, {\n\t\t\tvisitManyHasManyOwning: ({ entity, relation }) => {\n\t\t\t\treturn this.junctionTableManager.connectJunction(this, entity, relation, thisPrimary, otherPrimary)\n\t\t\t},\n\t\t\tvisitManyHasManyInverse: ({ targetEntity, targetRelation }) => {\n\t\t\t\treturn this.junctionTableManager.connectJunction(this, targetEntity, targetRelation, otherPrimary, thisPrimary)\n\t\t\t},\n\t\t\tvisitColumn: err,\n\t\t\tvisitOneHasMany: err,\n\t\t\tvisitOneHasOneInverse: err,\n\t\t\tvisitOneHasOneOwning: err,\n\t\t\tvisitManyHasOne: err,\n\t\t})\n\t}\n\n\tpublic async disconnectJunction(\n\t\tentity: Model.Entity,\n\t\trelation: Model.ManyHasManyOwningRelation | Model.ManyHasManyInverseRelation,\n\t\tthisPrimary: Input.PrimaryValue,\n\t\totherPrimary: Input.PrimaryValue,\n\t): Promise<MutationResultList> {\n\t\tawait this.setupSystemVariables()\n\t\tconst err = () => {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\treturn await acceptFieldVisitor(this.schema, entity, relation, {\n\t\t\tvisitManyHasManyOwning: ({ entity, relation }) => {\n\t\t\t\treturn this.junctionTableManager.disconnectJunction(this, entity, relation, thisPrimary, otherPrimary)\n\t\t\t},\n\t\t\tvisitManyHasManyInverse: ({ targetEntity, targetRelation }) => {\n\t\t\t\treturn this.junctionTableManager.disconnectJunction(this, targetEntity, targetRelation, otherPrimary, thisPrimary)\n\t\t\t},\n\t\t\tvisitColumn: err,\n\t\t\tvisitOneHasMany: err,\n\t\t\tvisitOneHasOneInverse: err,\n\t\t\tvisitOneHasOneOwning: err,\n\t\t\tvisitManyHasOne: err,\n\t\t})\n\t}\n\n\tpublic async getPrimaryValue(\n\t\tentity: Model.Entity,\n\t\twhere: Input.UniqueWhere | CheckedPrimary,\n\t): Promise<[Input.PrimaryValue, undefined] | [undefined, MutationEntryNotFoundError]> {\n\t\tif (where instanceof CheckedPrimary) {\n\t\t\treturn [where.primaryValue, undefined]\n\t\t}\n\t\tconst result = await this.selectField(entity, where, entity.primary)\n\t\treturn result ? [result, undefined] : [undefined, new MutationEntryNotFoundError([], where)]\n\t}\n\n\tprivate async setupSystemVariables() {\n\t\tthis.systemVariablesSetupDone ??= (async () => {\n\t\t\tawait this.db.query('SELECT set_config(?, ?, false)', ['tenant.identity_id', this.identityId]) // todo rename to system.identity_id\n\t\t\tawait this.db.query('SELECT set_config(?, ?, false)', ['system.transaction_id', this.transactionId])\n\t\t})()\n\t\tawait this.systemVariablesSetupDone\n\t}\n}\n"],"names":["DeletedEntitiesStorage","Mutex","ConstraintHelper","EventManager","getColumnName","SelectBuilder","SelectHydrator","OrderByHelper","ImplementationException","tryMutation","acceptFieldVisitor","entity","relation","CheckedPrimary","MutationEntryNotFoundError"],"mappings":";;;;;;;;;;;;;;;;;;AA2BO,MAAM,OAAqF;AAAA,EAUjG,YACiB,IACA,YACA,eACC,QACA,wBACA,oBACA,sBACA,qBACA,cACA,sBACA,gBACA,SACA,UACA,aACA,cAChB;AAfe,SA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AM,cAAc,gBAAgB,cAAc,WAAW;AAAA,MAClH;AAAA,MACA,aAAa;AAAA,MACb,iBAAiB;AAAA,MACjB,uBAAuB;AAAA,MACvB,sBAAsB;AAAA,MACtB,iBAAiB;AAAA,IAAA,CACjB;AAAA,EACF;AAAA,EAEA,MAAa,gBACZ,QACA,OACqF;AACrF,QAAI,iBAAiBC,eAAAA,gBAAgB;AACpC,aAAO,CAAC,MAAM,cAAc,MAAS;AAAA,IACtC;AACA,UAAM,SAAS,MAAM,KAAK,YAAY,QAAQ,OAAO,OAAO,OAAO;AACnE,WAAO,SAAS,CAAC,QAAQ,MAAS,IAAI,CAAC,QAAW,IAAIC,OAAAA,2BAA2B,IAAI,KAAK,CAAC;AAAA,EAC5F;AAAA,EAEA,MAAc,uBAAuB;AACpC,SAAK,6BAAL,KAAK,4BAA8B,YAAY;AAC9C,YAAM,KAAK,GAAG,MAAM,kCAAkC,CAAC,sBAAsB,KAAK,UAAU,CAAC;AAC7F,YAAM,KAAK,GAAG,MAAM,kCAAkC,CAAC,yBAAyB,KAAK,aAAa,CAAC;AAAA,IACpG;AACA,UAAM,KAAK;AAAA,EACZ;AACD;;"}
@@ -15,7 +15,7 @@ var __defProp = Object.defineProperty;
15
15
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
16
16
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
17
17
  class Mapper {
18
- constructor(db, identityId, transactionId, schema, schemaDatabaseMetadata, predicatesInjector, selectBuilderFactory, uniqueWhereExpander, whereBuilder, junctionTableManager, deleteExecutor, updater, inserter, pathFactory) {
18
+ constructor(db, identityId, transactionId, schema, schemaDatabaseMetadata, predicatesInjector, selectBuilderFactory, uniqueWhereExpander, whereBuilder, junctionTableManager, deleteExecutor, updater, inserter, pathFactory, memoryBudget) {
19
19
  this.db = db;
20
20
  this.identityId = identityId;
21
21
  this.transactionId = transactionId;
@@ -30,12 +30,15 @@ class Mapper {
30
30
  this.updater = updater;
31
31
  this.inserter = inserter;
32
32
  this.pathFactory = pathFactory;
33
+ this.memoryBudget = memoryBudget;
33
34
  __publicField(this, "systemVariablesSetupDone");
34
35
  __publicField(this, "deletedEntities", new DeletedEntitiesStorage());
35
36
  __publicField(this, "mutex", new Mutex());
36
37
  __publicField(this, "constraintHelper");
38
+ __publicField(this, "selectionDb");
37
39
  __publicField(this, "eventManager");
38
40
  this.constraintHelper = new ConstraintHelper(db, this.schemaDatabaseMetadata);
41
+ this.selectionDb = memoryBudget ? db.withMemoryBudget(memoryBudget, { chargeRows: true }) : db;
39
42
  this.eventManager = new EventManager(this);
40
43
  }
41
44
  async selectField(entity, where, fieldName) {
@@ -48,7 +51,7 @@ class Mapper {
48
51
  return result[0] !== void 0 ? result[0][columnName] : void 0;
49
52
  }
50
53
  async selectAssoc(entity, input, relationPath, indexBy) {
51
- const hydrator = new SelectHydrator();
54
+ const hydrator = new SelectHydrator(this.memoryBudget);
52
55
  const path = this.pathFactory.create([]);
53
56
  const indexByAlias = path.for(indexBy).alias;
54
57
  const qb = SelectBuilder.create().select([path.alias, getColumnName(this.schema, entity, indexBy)], indexByAlias);
@@ -56,7 +59,7 @@ class Mapper {
56
59
  return await hydrator.hydrateAll(rows, indexByAlias);
57
60
  }
58
61
  async select(entity, input, relationPath) {
59
- const hydrator = new SelectHydrator();
62
+ const hydrator = new SelectHydrator(this.memoryBudget);
60
63
  const qb = SelectBuilder.create();
61
64
  const rows = await this.selectRows(hydrator, qb, entity, input, relationPath);
62
65
  return await hydrator.hydrateAll(rows);
@@ -69,7 +72,7 @@ class Mapper {
69
72
  return rows[0] ?? null;
70
73
  }
71
74
  async selectGrouped(entity, input, relation, relationPath) {
72
- const hydrator = new SelectHydrator();
75
+ const hydrator = new SelectHydrator(this.memoryBudget);
73
76
  const path = this.pathFactory.create([]);
74
77
  const groupingKey = "__grouping_key";
75
78
  const qb = SelectBuilder.create().select([path.alias, relation.joiningColumn.columnName], groupingKey);
@@ -89,7 +92,7 @@ class Mapper {
89
92
  );
90
93
  const inputWithPredicates = inputWithOrder.withArg("filter", filterWithPredicates);
91
94
  selector.select(this, entity, inputWithPredicates, path, groupBy);
92
- return await selector.execute(this.db);
95
+ return await selector.execute(this.selectionDb);
93
96
  }
94
97
  async count(entity, filter) {
95
98
  const path = this.pathFactory.create([]);
@@ -1 +1 @@
1
- {"version":3,"file":"Mapper.js","sources":["../../../../../packages/engine-content-api/src/mapper/Mapper.ts"],"sourcesContent":["import { Input, Model } from '@contember/schema'\nimport { acceptFieldVisitor, getColumnName } from '@contember/schema-utils'\nimport {\n\tOrderByHelper,\n\tPathFactory,\n\tSelectBuilderFactory,\n\tSelectGroupedObjects,\n\tSelectHydrator,\n\tSelectIndexedResultObjects,\n\tSelectResultObject,\n\tWhereBuilder,\n} from './select'\nimport { Client, Connection, ConstraintHelper, DatabaseMetadata, SelectBuilder } from '@contember/database'\nimport { PredicatesInjector } from '../acl'\nimport { JunctionTableManager } from './JunctionTableManager'\nimport { DeletedEntitiesStorage, DeleteExecutor } from './delete'\nimport { MutationEntryNotFoundError, MutationResultList } from './Result'\nimport { UpdateBuilder, Updater } from './update'\nimport { InsertBuilder, Inserter } from './insert'\nimport { tryMutation } from './ErrorUtils'\nimport { ObjectNode, UniqueWhereExpander } from '../inputProcessing'\nimport { Mutex } from '../utils'\nimport { CheckedPrimary } from './CheckedPrimary'\nimport { ImplementationException } from '../exception'\nimport { EventManager } from './EventManager'\nimport { MapperInput } from './types'\n\nexport class Mapper<ConnectionType extends Connection.ConnectionLike = Connection.ConnectionLike> {\n\tprivate systemVariablesSetupDone: Promise<void> | undefined\n\tpublic readonly deletedEntities = new DeletedEntitiesStorage()\n\tpublic readonly mutex = new Mutex()\n\tpublic readonly constraintHelper: ConstraintHelper\n\n\tpublic readonly eventManager: EventManager\n\n\tconstructor(\n\t\tpublic readonly db: Client<ConnectionType>,\n\t\tpublic readonly identityId: string,\n\t\tpublic readonly transactionId: string,\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly schemaDatabaseMetadata: DatabaseMetadata,\n\t\tprivate readonly predicatesInjector: PredicatesInjector,\n\t\tprivate readonly selectBuilderFactory: SelectBuilderFactory,\n\t\tprivate readonly uniqueWhereExpander: UniqueWhereExpander,\n\t\tprivate readonly whereBuilder: WhereBuilder,\n\t\tprivate readonly junctionTableManager: JunctionTableManager,\n\t\tprivate readonly deleteExecutor: DeleteExecutor,\n\t\tprivate readonly updater: Updater,\n\t\tprivate readonly inserter: Inserter,\n\t\tprivate readonly pathFactory: PathFactory,\n\t) {\n\t\tthis.constraintHelper = new ConstraintHelper(db, this.schemaDatabaseMetadata)\n\t\tthis.eventManager = new EventManager(this)\n\t}\n\n\tpublic async selectField(entity: Model.Entity, where: Input.UniqueWhere | CheckedPrimary, fieldName: string) {\n\t\tconst columnName = getColumnName(this.schema, entity, fieldName)\n\n\t\tconst qb = SelectBuilder.create() //\n\t\t\t.from(entity.tableName, 'root_')\n\t\t\t.select(['root_', columnName])\n\t\tconst expandedWhere = this.uniqueWhereExpander.expand(entity, where)\n\t\tconst withPredicates = this.predicatesInjector.inject(entity, expandedWhere)\n\t\tconst builtQb = this.whereBuilder.build(qb, entity, this.pathFactory.create([]), withPredicates)\n\t\tconst result = await builtQb.getResult(this.db)\n\n\t\treturn result[0] !== undefined ? result[0][columnName] : undefined\n\t}\n\n\tpublic async selectAssoc(\n\t\tentity: Model.Entity,\n\t\tinput: ObjectNode<Input.ListQueryInput>,\n\t\trelationPath: Model.AnyRelationContext[],\n\t\tindexBy: string,\n\t): Promise<SelectIndexedResultObjects> {\n\t\tconst hydrator = new SelectHydrator()\n\t\tconst path = this.pathFactory.create([])\n\t\tconst indexByAlias: string = path.for(indexBy).alias\n\t\tconst qb: SelectBuilder = SelectBuilder.create()\n\t\t\t.select([path.alias, getColumnName(this.schema, entity, indexBy)], indexByAlias)\n\t\tconst rows = await this.selectRows(hydrator, qb, entity, input, relationPath)\n\t\treturn await hydrator.hydrateAll(rows, indexByAlias)\n\t}\n\n\tpublic async select(\n\t\tentity: Model.Entity,\n\t\tinput: ObjectNode<Input.ListQueryInput>,\n\t\trelationPath: Model.AnyRelationContext[],\n\t): Promise<SelectResultObject[]> {\n\t\tconst hydrator = new SelectHydrator()\n\t\tconst qb: SelectBuilder<SelectBuilder.Result> = SelectBuilder.create()\n\n\t\tconst rows = await this.selectRows(hydrator, qb, entity, input, relationPath)\n\n\t\treturn await hydrator.hydrateAll(rows)\n\t}\n\n\tpublic async selectUnique(\n\t\tentity: Model.Entity,\n\t\tquery: ObjectNode<Input.UniqueQueryInput>,\n\t\trelationPath: Model.AnyRelationContext[],\n\t): Promise<SelectResultObject | null> {\n\t\tconst uniqueWhere = this.uniqueWhereExpander.expand(entity, query.args.by)\n\t\tconst where = query.args.filter ? { and: [uniqueWhere, query.args.filter] } : uniqueWhere\n\t\tconst queryExpanded = query.withArg<Input.ListQueryInput>('filter', where)\n\n\t\tconst rows = await this.select(entity, queryExpanded, relationPath)\n\n\t\treturn rows[0] ?? null\n\t}\n\n\tpublic async selectGrouped(\n\t\tentity: Model.Entity,\n\t\tinput: ObjectNode<Input.ListQueryInput>,\n\t\trelation: Model.JoiningColumnRelation & Model.AnyRelation,\n\t\trelationPath: Model.AnyRelationContext[],\n\t): Promise<SelectGroupedObjects> {\n\t\tconst hydrator = new SelectHydrator()\n\t\tconst path = this.pathFactory.create([])\n\t\tconst groupingKey = '__grouping_key'\n\t\tconst qb: SelectBuilder = SelectBuilder.create()\n\t\t\t.select([path.alias, relation.joiningColumn.columnName], groupingKey)\n\n\t\tconst rows = await this.selectRows(hydrator, qb, entity, input, relationPath, relation.name)\n\n\t\treturn await hydrator.hydrateGroups(rows, groupingKey)\n\t}\n\n\tprivate async selectRows(\n\t\thydrator: SelectHydrator,\n\t\tqb: SelectBuilder<SelectBuilder.Result>,\n\t\tentity: Model.Entity,\n\t\tinput: ObjectNode<Input.ListQueryInput>,\n\t\trelationPath: Model.AnyRelationContext[],\n\t\tgroupBy?: string,\n\t) {\n\t\tconst inputWithOrder = OrderByHelper.appendDefaultOrderBy(entity, input, undefined)\n\t\tconst path = this.pathFactory.create([])\n\t\tconst augmentedBuilder = qb.from(entity.tableName, path.alias).meta('path', [...input.path, input.alias])\n\n\t\tconst selector = this.selectBuilderFactory.create(augmentedBuilder, hydrator, relationPath)\n\t\tconst filterWithPredicates = this.predicatesInjector.inject(\n\t\t\tentity,\n\t\t\tinputWithOrder.args.filter || {},\n\t\t\trelationPath[relationPath.length - 1],\n\t\t\trelationPath,\n\t\t)\n\t\tconst inputWithPredicates = inputWithOrder.withArg('filter', filterWithPredicates)\n\t\tselector.select(this, entity, inputWithPredicates, path, groupBy)\n\t\treturn await selector.execute(this.db)\n\t}\n\n\tpublic async count(entity: Model.Entity, filter: Input.OptionalWhere) {\n\t\tconst path = this.pathFactory.create([])\n\t\tconst qb = SelectBuilder.create()\n\t\t\t.from(entity.tableName, path.alias)\n\t\t\t.select(expr => expr.raw('count(*)'), 'row_count')\n\t\tconst withPredicates = this.predicatesInjector.inject(entity, filter)\n\t\tconst qbWithWhere = this.whereBuilder.build(qb, entity, path, withPredicates)\n\t\tconst result = await qbWithWhere.getResult(this.db)\n\t\treturn result[0].row_count\n\t}\n\n\tpublic async countGrouped(\n\t\tentity: Model.Entity,\n\t\tfilter: Input.OptionalWhere,\n\t\trelation: Model.JoiningColumnRelation & Model.Relation,\n\t\trelationPath: Model.AnyRelationContext[],\n\t): Promise<Record<string, number>> {\n\t\tconst path = this.pathFactory.create([])\n\t\tconst qb = SelectBuilder.create()\n\t\t\t.from(entity.tableName, path.alias)\n\t\t\t.select(expr => expr.raw('count(*)'), 'row_count')\n\t\t\t.select([path.alias, relation.joiningColumn.columnName])\n\t\t\t.groupBy([path.alias, relation.joiningColumn.columnName])\n\t\tconst withPredicates = this.predicatesInjector.inject(entity, filter, relationPath[relationPath.length - 1], relationPath)\n\t\tconst qbWithWhere = this.whereBuilder.build(qb, entity, path, withPredicates, { relationPath })\n\t\tconst rows = await qbWithWhere.getResult(this.db)\n\t\tconst result = new Map<string, number>()\n\t\tfor (const row of rows) {\n\t\t\tresult.set(String(row[relation.joiningColumn.columnName]), Number(row.row_count))\n\t\t}\n\t\treturn Object.fromEntries(result)\n\t}\n\n\tpublic async insert(\n\t\tentity: Model.Entity,\n\t\tdata: MapperInput.CreateDataInput,\n\t\tbuilderCb: (builder: InsertBuilder) => void = () => {},\n\t): Promise<MutationResultList> {\n\t\tif (entity.view) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\tawait this.setupSystemVariables()\n\t\treturn tryMutation(this.schema, this.schemaDatabaseMetadata, () => this.insertInternal(entity, data, builderCb))\n\t}\n\n\tpublic async update(\n\t\tentity: Model.Entity,\n\t\tby: Input.UniqueWhere | CheckedPrimary,\n\t\tdata: MapperInput.UpdateDataInput,\n\t\tfilter?: Input.OptionalWhere,\n\t): Promise<MutationResultList> {\n\t\tif (entity.view) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\tawait this.setupSystemVariables()\n\t\treturn tryMutation(this.schema, this.schemaDatabaseMetadata, async () => {\n\t\t\tconst [primaryValue, err] = await this.getPrimaryValue(entity, by)\n\t\t\tif (err) return [err]\n\n\t\t\treturn await this.updater.update(this, entity, primaryValue, data, filter)\n\t\t})\n\t}\n\n\tpublic async updateInternal(\n\t\tentity: Model.Entity,\n\t\tby: Input.UniqueWhere | CheckedPrimary,\n\t\tbuilderCb: (builder: UpdateBuilder) => void,\n\t): Promise<MutationResultList> {\n\t\tif (entity.view) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\tawait this.setupSystemVariables()\n\t\treturn tryMutation(this.schema, this.schemaDatabaseMetadata, async () => {\n\t\t\tconst [primaryValue, err] = await this.getPrimaryValue(entity, by)\n\t\t\tif (err) return [err]\n\n\t\t\treturn await this.updater.updateCb(this, entity, primaryValue, builderCb)\n\t\t})\n\t}\n\tpublic async upsert(\n\t\tentity: Model.Entity,\n\t\tby: Input.UniqueWhere | CheckedPrimary,\n\t\tupdate: MapperInput.UpdateDataInput,\n\t\tcreate: MapperInput.CreateDataInput,\n\t\tfilter?: Input.OptionalWhere,\n\t): Promise<MutationResultList> {\n\t\tif (entity.view) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\tawait this.setupSystemVariables()\n\t\treturn tryMutation(this.schema, this.schemaDatabaseMetadata, async () => {\n\t\t\tconst [primaryValue] = await this.getPrimaryValue(entity, by)\n\t\t\tif (primaryValue === undefined) {\n\t\t\t\treturn await this.insertInternal(entity, create)\n\t\t\t}\n\t\t\treturn await this.updater.update(this, entity, primaryValue, update, filter)\n\t\t})\n\t}\n\n\tprivate insertInternal(entity: Model.Entity, data: MapperInput.CreateDataInput, builderCb: (builder: InsertBuilder) => void = () => {}) {\n\t\treturn this.inserter.insert(this, entity, data, id => {\n\t\t}, builderCb)\n\t}\n\n\tpublic async delete(\n\t\tentity: Model.Entity,\n\t\tby: Input.UniqueWhere | CheckedPrimary,\n\t\tfilter?: Input.OptionalWhere,\n\t): Promise<MutationResultList> {\n\t\tif (entity.view) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\tawait this.setupSystemVariables()\n\t\treturn tryMutation(this.schema, this.schemaDatabaseMetadata, () => {\n\t\t\treturn this.deleteExecutor.execute(this, entity, by, filter)\n\t\t})\n\t}\n\n\tpublic async connectJunction(\n\t\tentity: Model.Entity,\n\t\trelation: Model.ManyHasManyOwningRelation | Model.ManyHasManyInverseRelation,\n\t\tthisPrimary: Input.PrimaryValue,\n\t\totherPrimary: Input.PrimaryValue,\n\t): Promise<MutationResultList> {\n\t\tawait this.setupSystemVariables()\n\t\tconst err = () => {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\treturn await acceptFieldVisitor(this.schema, entity, relation, {\n\t\t\tvisitManyHasManyOwning: ({ entity, relation }) => {\n\t\t\t\treturn this.junctionTableManager.connectJunction(this, entity, relation, thisPrimary, otherPrimary)\n\t\t\t},\n\t\t\tvisitManyHasManyInverse: ({ targetEntity, targetRelation }) => {\n\t\t\t\treturn this.junctionTableManager.connectJunction(this, targetEntity, targetRelation, otherPrimary, thisPrimary)\n\t\t\t},\n\t\t\tvisitColumn: err,\n\t\t\tvisitOneHasMany: err,\n\t\t\tvisitOneHasOneInverse: err,\n\t\t\tvisitOneHasOneOwning: err,\n\t\t\tvisitManyHasOne: err,\n\t\t})\n\t}\n\n\tpublic async disconnectJunction(\n\t\tentity: Model.Entity,\n\t\trelation: Model.ManyHasManyOwningRelation | Model.ManyHasManyInverseRelation,\n\t\tthisPrimary: Input.PrimaryValue,\n\t\totherPrimary: Input.PrimaryValue,\n\t): Promise<MutationResultList> {\n\t\tawait this.setupSystemVariables()\n\t\tconst err = () => {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\treturn await acceptFieldVisitor(this.schema, entity, relation, {\n\t\t\tvisitManyHasManyOwning: ({ entity, relation }) => {\n\t\t\t\treturn this.junctionTableManager.disconnectJunction(this, entity, relation, thisPrimary, otherPrimary)\n\t\t\t},\n\t\t\tvisitManyHasManyInverse: ({ targetEntity, targetRelation }) => {\n\t\t\t\treturn this.junctionTableManager.disconnectJunction(this, targetEntity, targetRelation, otherPrimary, thisPrimary)\n\t\t\t},\n\t\t\tvisitColumn: err,\n\t\t\tvisitOneHasMany: err,\n\t\t\tvisitOneHasOneInverse: err,\n\t\t\tvisitOneHasOneOwning: err,\n\t\t\tvisitManyHasOne: err,\n\t\t})\n\t}\n\n\tpublic async getPrimaryValue(\n\t\tentity: Model.Entity,\n\t\twhere: Input.UniqueWhere | CheckedPrimary,\n\t): Promise<[Input.PrimaryValue, undefined] | [undefined, MutationEntryNotFoundError]> {\n\t\tif (where instanceof CheckedPrimary) {\n\t\t\treturn [where.primaryValue, undefined]\n\t\t}\n\t\tconst result = await this.selectField(entity, where, entity.primary)\n\t\treturn result ? [result, undefined] : [undefined, new MutationEntryNotFoundError([], where)]\n\t}\n\n\tprivate async setupSystemVariables() {\n\t\tthis.systemVariablesSetupDone ??= (async () => {\n\t\t\tawait this.db.query('SELECT set_config(?, ?, false)', ['tenant.identity_id', this.identityId]) // todo rename to system.identity_id\n\t\t\tawait this.db.query('SELECT set_config(?, ?, false)', ['system.transaction_id', this.transactionId])\n\t\t})()\n\t\tawait this.systemVariablesSetupDone\n\t}\n}\n"],"names":["entity","relation"],"mappings":";;;;;;;;;;;;;;;;AA2BO,MAAM,OAAqF;AAAA,EAQjG,YACiB,IACA,YACA,eACC,QACA,wBACA,oBACA,sBACA,qBACA,cACA,sBACA,gBACA,SACA,UACA,aAChB;AAde,SAAA,KAAA;AACA,SAAA,aAAA;AACA,SAAA,gBAAA;AACC,SAAA,SAAA;AACA,SAAA,yBAAA;AACA,SAAA,qBAAA;AACA,SAAA,uBAAA;AACA,SAAA,sBAAA;AACA,SAAA,eAAA;AACA,SAAA,uBAAA;AACA,SAAA,iBAAA;AACA,SAAA,UAAA;AACA,SAAA,WAAA;AACA,SAAA,cAAA;AArBlB,kBAAA,MAAQ,0BAAA;AACR,kBAAA,MAAgB,mBAAkB,IAAI,uBAAA,CAAuB;AAC7D,kBAAA,MAAgB,SAAQ,IAAI,MAAA,CAAM;AAClC,kBAAA,MAAgB,kBAAA;AAEhB,kBAAA,MAAgB,cAAA;AAkBf,SAAK,mBAAmB,IAAI,iBAAiB,IAAI,KAAK,sBAAsB;AAC5E,SAAK,eAAe,IAAI,aAAa,IAAI;AAAA,EAC1C;AAAA,EAEA,MAAa,YAAY,QAAsB,OAA2C,WAAmB;AAC5G,UAAM,aAAa,cAAc,KAAK,QAAQ,QAAQ,SAAS;AAE/D,UAAM,KAAK,cAAc,OAAA,EACvB,KAAK,OAAO,WAAW,OAAO,EAC9B,OAAO,CAAC,SAAS,UAAU,CAAC;AAC9B,UAAM,gBAAgB,KAAK,oBAAoB,OAAO,QAAQ,KAAK;AACnE,UAAM,iBAAiB,KAAK,mBAAmB,OAAO,QAAQ,aAAa;AAC3E,UAAM,UAAU,KAAK,aAAa,MAAM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gB,cAAc,WAAW;AAAA,MAClH;AAAA,MACA,aAAa;AAAA,MACb,iBAAiB;AAAA,MACjB,uBAAuB;AAAA,MACvB,sBAAsB;AAAA,MACtB,iBAAiB;AAAA,IAAA,CACjB;AAAA,EACF;AAAA,EAEA,MAAa,gBACZ,QACA,OACqF;AACrF,QAAI,iBAAiB,gBAAgB;AACpC,aAAO,CAAC,MAAM,cAAc,MAAS;AAAA,IACtC;AACA,UAAM,SAAS,MAAM,KAAK,YAAY,QAAQ,OAAO,OAAO,OAAO;AACnE,WAAO,SAAS,CAAC,QAAQ,MAAS,IAAI,CAAC,QAAW,IAAI,2BAA2B,IAAI,KAAK,CAAC;AAAA,EAC5F;AAAA,EAEA,MAAc,uBAAuB;AACpC,SAAK,6BAAL,KAAK,4BAA8B,YAAY;AAC9C,YAAM,KAAK,GAAG,MAAM,kCAAkC,CAAC,sBAAsB,KAAK,UAAU,CAAC;AAC7F,YAAM,KAAK,GAAG,MAAM,kCAAkC,CAAC,yBAAyB,KAAK,aAAa,CAAC;AAAA,IACpG;AACA,UAAM,KAAK;AAAA,EACZ;AACD;"}
1
+ {"version":3,"file":"Mapper.js","sources":["../../../../../packages/engine-content-api/src/mapper/Mapper.ts"],"sourcesContent":["import { Input, Model } from '@contember/schema'\nimport { acceptFieldVisitor, getColumnName } from '@contember/schema-utils'\nimport {\n\tOrderByHelper,\n\tPathFactory,\n\tSelectBuilderFactory,\n\tSelectGroupedObjects,\n\tSelectHydrator,\n\tSelectIndexedResultObjects,\n\tSelectResultObject,\n\tWhereBuilder,\n} from './select/index.js'\nimport { Client, Connection, ConstraintHelper, DatabaseMetadata, RequestMemoryBudget, SelectBuilder } from '@contember/database'\nimport { PredicatesInjector } from '../acl/index.js'\nimport { JunctionTableManager } from './JunctionTableManager.js'\nimport { DeletedEntitiesStorage, DeleteExecutor } from './delete/index.js'\nimport { MutationEntryNotFoundError, MutationResultList } from './Result.js'\nimport { UpdateBuilder, Updater } from './update/index.js'\nimport { InsertBuilder, Inserter } from './insert/index.js'\nimport { tryMutation } from './ErrorUtils.js'\nimport { ObjectNode, UniqueWhereExpander } from '../inputProcessing/index.js'\nimport { Mutex } from '../utils/index.js'\nimport { CheckedPrimary } from './CheckedPrimary.js'\nimport { ImplementationException } from '../exception.js'\nimport { EventManager } from './EventManager.js'\nimport { MapperInput } from './types.js'\n\nexport class Mapper<ConnectionType extends Connection.ConnectionLike = Connection.ConnectionLike> {\n\tprivate systemVariablesSetupDone: Promise<void> | undefined\n\tpublic readonly deletedEntities = new DeletedEntitiesStorage()\n\tpublic readonly mutex = new Mutex()\n\tpublic readonly constraintHelper: ConstraintHelper\n\t/** Charges the request memory budget; only selection results use it, internal mutation queries stay on `db`. */\n\tpublic readonly selectionDb: Client<ConnectionType>\n\n\tpublic readonly eventManager: EventManager\n\n\tconstructor(\n\t\tpublic readonly db: Client<ConnectionType>,\n\t\tpublic readonly identityId: string,\n\t\tpublic readonly transactionId: string,\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly schemaDatabaseMetadata: DatabaseMetadata,\n\t\tprivate readonly predicatesInjector: PredicatesInjector,\n\t\tprivate readonly selectBuilderFactory: SelectBuilderFactory,\n\t\tprivate readonly uniqueWhereExpander: UniqueWhereExpander,\n\t\tprivate readonly whereBuilder: WhereBuilder,\n\t\tprivate readonly junctionTableManager: JunctionTableManager,\n\t\tprivate readonly deleteExecutor: DeleteExecutor,\n\t\tprivate readonly updater: Updater,\n\t\tprivate readonly inserter: Inserter,\n\t\tprivate readonly pathFactory: PathFactory,\n\t\tprivate readonly memoryBudget?: RequestMemoryBudget,\n\t) {\n\t\tthis.constraintHelper = new ConstraintHelper(db, this.schemaDatabaseMetadata)\n\t\tthis.selectionDb = memoryBudget ? db.withMemoryBudget(memoryBudget, { chargeRows: true }) : db\n\t\tthis.eventManager = new EventManager(this)\n\t}\n\n\tpublic async selectField(entity: Model.Entity, where: Input.UniqueWhere | CheckedPrimary, fieldName: string) {\n\t\tconst columnName = getColumnName(this.schema, entity, fieldName)\n\n\t\tconst qb = SelectBuilder.create() //\n\t\t\t.from(entity.tableName, 'root_')\n\t\t\t.select(['root_', columnName])\n\t\tconst expandedWhere = this.uniqueWhereExpander.expand(entity, where)\n\t\tconst withPredicates = this.predicatesInjector.inject(entity, expandedWhere)\n\t\tconst builtQb = this.whereBuilder.build(qb, entity, this.pathFactory.create([]), withPredicates)\n\t\tconst result = await builtQb.getResult(this.db)\n\n\t\treturn result[0] !== undefined ? result[0][columnName] : undefined\n\t}\n\n\tpublic async selectAssoc(\n\t\tentity: Model.Entity,\n\t\tinput: ObjectNode<Input.ListQueryInput>,\n\t\trelationPath: Model.AnyRelationContext[],\n\t\tindexBy: string,\n\t): Promise<SelectIndexedResultObjects> {\n\t\tconst hydrator = new SelectHydrator(this.memoryBudget)\n\t\tconst path = this.pathFactory.create([])\n\t\tconst indexByAlias: string = path.for(indexBy).alias\n\t\tconst qb: SelectBuilder = SelectBuilder.create()\n\t\t\t.select([path.alias, getColumnName(this.schema, entity, indexBy)], indexByAlias)\n\t\tconst rows = await this.selectRows(hydrator, qb, entity, input, relationPath)\n\t\treturn await hydrator.hydrateAll(rows, indexByAlias)\n\t}\n\n\tpublic async select(\n\t\tentity: Model.Entity,\n\t\tinput: ObjectNode<Input.ListQueryInput>,\n\t\trelationPath: Model.AnyRelationContext[],\n\t): Promise<SelectResultObject[]> {\n\t\tconst hydrator = new SelectHydrator(this.memoryBudget)\n\t\tconst qb: SelectBuilder<SelectBuilder.Result> = SelectBuilder.create()\n\n\t\tconst rows = await this.selectRows(hydrator, qb, entity, input, relationPath)\n\n\t\treturn await hydrator.hydrateAll(rows)\n\t}\n\n\tpublic async selectUnique(\n\t\tentity: Model.Entity,\n\t\tquery: ObjectNode<Input.UniqueQueryInput>,\n\t\trelationPath: Model.AnyRelationContext[],\n\t): Promise<SelectResultObject | null> {\n\t\tconst uniqueWhere = this.uniqueWhereExpander.expand(entity, query.args.by)\n\t\tconst where = query.args.filter ? { and: [uniqueWhere, query.args.filter] } : uniqueWhere\n\t\tconst queryExpanded = query.withArg<Input.ListQueryInput>('filter', where)\n\n\t\tconst rows = await this.select(entity, queryExpanded, relationPath)\n\n\t\treturn rows[0] ?? null\n\t}\n\n\tpublic async selectGrouped(\n\t\tentity: Model.Entity,\n\t\tinput: ObjectNode<Input.ListQueryInput>,\n\t\trelation: Model.JoiningColumnRelation & Model.AnyRelation,\n\t\trelationPath: Model.AnyRelationContext[],\n\t): Promise<SelectGroupedObjects> {\n\t\tconst hydrator = new SelectHydrator(this.memoryBudget)\n\t\tconst path = this.pathFactory.create([])\n\t\tconst groupingKey = '__grouping_key'\n\t\tconst qb: SelectBuilder = SelectBuilder.create()\n\t\t\t.select([path.alias, relation.joiningColumn.columnName], groupingKey)\n\n\t\tconst rows = await this.selectRows(hydrator, qb, entity, input, relationPath, relation.name)\n\n\t\treturn await hydrator.hydrateGroups(rows, groupingKey)\n\t}\n\n\tprivate async selectRows(\n\t\thydrator: SelectHydrator,\n\t\tqb: SelectBuilder<SelectBuilder.Result>,\n\t\tentity: Model.Entity,\n\t\tinput: ObjectNode<Input.ListQueryInput>,\n\t\trelationPath: Model.AnyRelationContext[],\n\t\tgroupBy?: string,\n\t) {\n\t\tconst inputWithOrder = OrderByHelper.appendDefaultOrderBy(entity, input, undefined)\n\t\tconst path = this.pathFactory.create([])\n\t\tconst augmentedBuilder = qb.from(entity.tableName, path.alias).meta('path', [...input.path, input.alias])\n\n\t\tconst selector = this.selectBuilderFactory.create(augmentedBuilder, hydrator, relationPath)\n\t\tconst filterWithPredicates = this.predicatesInjector.inject(\n\t\t\tentity,\n\t\t\tinputWithOrder.args.filter || {},\n\t\t\trelationPath[relationPath.length - 1],\n\t\t\trelationPath,\n\t\t)\n\t\tconst inputWithPredicates = inputWithOrder.withArg('filter', filterWithPredicates)\n\t\tselector.select(this, entity, inputWithPredicates, path, groupBy)\n\t\treturn await selector.execute(this.selectionDb)\n\t}\n\n\tpublic async count(entity: Model.Entity, filter: Input.OptionalWhere) {\n\t\tconst path = this.pathFactory.create([])\n\t\tconst qb = SelectBuilder.create()\n\t\t\t.from(entity.tableName, path.alias)\n\t\t\t.select(expr => expr.raw('count(*)'), 'row_count')\n\t\tconst withPredicates = this.predicatesInjector.inject(entity, filter)\n\t\tconst qbWithWhere = this.whereBuilder.build(qb, entity, path, withPredicates)\n\t\tconst result = await qbWithWhere.getResult(this.db)\n\t\treturn result[0].row_count\n\t}\n\n\tpublic async countGrouped(\n\t\tentity: Model.Entity,\n\t\tfilter: Input.OptionalWhere,\n\t\trelation: Model.JoiningColumnRelation & Model.Relation,\n\t\trelationPath: Model.AnyRelationContext[],\n\t): Promise<Record<string, number>> {\n\t\tconst path = this.pathFactory.create([])\n\t\tconst qb = SelectBuilder.create()\n\t\t\t.from(entity.tableName, path.alias)\n\t\t\t.select(expr => expr.raw('count(*)'), 'row_count')\n\t\t\t.select([path.alias, relation.joiningColumn.columnName])\n\t\t\t.groupBy([path.alias, relation.joiningColumn.columnName])\n\t\tconst withPredicates = this.predicatesInjector.inject(entity, filter, relationPath[relationPath.length - 1], relationPath)\n\t\tconst qbWithWhere = this.whereBuilder.build(qb, entity, path, withPredicates, { relationPath })\n\t\tconst rows = await qbWithWhere.getResult(this.db)\n\t\tconst result = new Map<string, number>()\n\t\tfor (const row of rows) {\n\t\t\tresult.set(String(row[relation.joiningColumn.columnName]), Number(row.row_count))\n\t\t}\n\t\treturn Object.fromEntries(result)\n\t}\n\n\tpublic async insert(\n\t\tentity: Model.Entity,\n\t\tdata: MapperInput.CreateDataInput,\n\t\tbuilderCb: (builder: InsertBuilder) => void = () => {},\n\t): Promise<MutationResultList> {\n\t\tif (entity.view) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\tawait this.setupSystemVariables()\n\t\treturn tryMutation(this.schema, this.schemaDatabaseMetadata, () => this.insertInternal(entity, data, builderCb))\n\t}\n\n\tpublic async update(\n\t\tentity: Model.Entity,\n\t\tby: Input.UniqueWhere | CheckedPrimary,\n\t\tdata: MapperInput.UpdateDataInput,\n\t\tfilter?: Input.OptionalWhere,\n\t): Promise<MutationResultList> {\n\t\tif (entity.view) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\tawait this.setupSystemVariables()\n\t\treturn tryMutation(this.schema, this.schemaDatabaseMetadata, async () => {\n\t\t\tconst [primaryValue, err] = await this.getPrimaryValue(entity, by)\n\t\t\tif (err) return [err]\n\n\t\t\treturn await this.updater.update(this, entity, primaryValue, data, filter)\n\t\t})\n\t}\n\n\tpublic async updateInternal(\n\t\tentity: Model.Entity,\n\t\tby: Input.UniqueWhere | CheckedPrimary,\n\t\tbuilderCb: (builder: UpdateBuilder) => void,\n\t): Promise<MutationResultList> {\n\t\tif (entity.view) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\tawait this.setupSystemVariables()\n\t\treturn tryMutation(this.schema, this.schemaDatabaseMetadata, async () => {\n\t\t\tconst [primaryValue, err] = await this.getPrimaryValue(entity, by)\n\t\t\tif (err) return [err]\n\n\t\t\treturn await this.updater.updateCb(this, entity, primaryValue, builderCb)\n\t\t})\n\t}\n\tpublic async upsert(\n\t\tentity: Model.Entity,\n\t\tby: Input.UniqueWhere | CheckedPrimary,\n\t\tupdate: MapperInput.UpdateDataInput,\n\t\tcreate: MapperInput.CreateDataInput,\n\t\tfilter?: Input.OptionalWhere,\n\t): Promise<MutationResultList> {\n\t\tif (entity.view) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\tawait this.setupSystemVariables()\n\t\treturn tryMutation(this.schema, this.schemaDatabaseMetadata, async () => {\n\t\t\tconst [primaryValue] = await this.getPrimaryValue(entity, by)\n\t\t\tif (primaryValue === undefined) {\n\t\t\t\treturn await this.insertInternal(entity, create)\n\t\t\t}\n\t\t\treturn await this.updater.update(this, entity, primaryValue, update, filter)\n\t\t})\n\t}\n\n\tprivate insertInternal(entity: Model.Entity, data: MapperInput.CreateDataInput, builderCb: (builder: InsertBuilder) => void = () => {}) {\n\t\treturn this.inserter.insert(this, entity, data, id => {\n\t\t}, builderCb)\n\t}\n\n\tpublic async delete(\n\t\tentity: Model.Entity,\n\t\tby: Input.UniqueWhere | CheckedPrimary,\n\t\tfilter?: Input.OptionalWhere,\n\t): Promise<MutationResultList> {\n\t\tif (entity.view) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\tawait this.setupSystemVariables()\n\t\treturn tryMutation(this.schema, this.schemaDatabaseMetadata, () => {\n\t\t\treturn this.deleteExecutor.execute(this, entity, by, filter)\n\t\t})\n\t}\n\n\tpublic async connectJunction(\n\t\tentity: Model.Entity,\n\t\trelation: Model.ManyHasManyOwningRelation | Model.ManyHasManyInverseRelation,\n\t\tthisPrimary: Input.PrimaryValue,\n\t\totherPrimary: Input.PrimaryValue,\n\t): Promise<MutationResultList> {\n\t\tawait this.setupSystemVariables()\n\t\tconst err = () => {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\treturn await acceptFieldVisitor(this.schema, entity, relation, {\n\t\t\tvisitManyHasManyOwning: ({ entity, relation }) => {\n\t\t\t\treturn this.junctionTableManager.connectJunction(this, entity, relation, thisPrimary, otherPrimary)\n\t\t\t},\n\t\t\tvisitManyHasManyInverse: ({ targetEntity, targetRelation }) => {\n\t\t\t\treturn this.junctionTableManager.connectJunction(this, targetEntity, targetRelation, otherPrimary, thisPrimary)\n\t\t\t},\n\t\t\tvisitColumn: err,\n\t\t\tvisitOneHasMany: err,\n\t\t\tvisitOneHasOneInverse: err,\n\t\t\tvisitOneHasOneOwning: err,\n\t\t\tvisitManyHasOne: err,\n\t\t})\n\t}\n\n\tpublic async disconnectJunction(\n\t\tentity: Model.Entity,\n\t\trelation: Model.ManyHasManyOwningRelation | Model.ManyHasManyInverseRelation,\n\t\tthisPrimary: Input.PrimaryValue,\n\t\totherPrimary: Input.PrimaryValue,\n\t): Promise<MutationResultList> {\n\t\tawait this.setupSystemVariables()\n\t\tconst err = () => {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\treturn await acceptFieldVisitor(this.schema, entity, relation, {\n\t\t\tvisitManyHasManyOwning: ({ entity, relation }) => {\n\t\t\t\treturn this.junctionTableManager.disconnectJunction(this, entity, relation, thisPrimary, otherPrimary)\n\t\t\t},\n\t\t\tvisitManyHasManyInverse: ({ targetEntity, targetRelation }) => {\n\t\t\t\treturn this.junctionTableManager.disconnectJunction(this, targetEntity, targetRelation, otherPrimary, thisPrimary)\n\t\t\t},\n\t\t\tvisitColumn: err,\n\t\t\tvisitOneHasMany: err,\n\t\t\tvisitOneHasOneInverse: err,\n\t\t\tvisitOneHasOneOwning: err,\n\t\t\tvisitManyHasOne: err,\n\t\t})\n\t}\n\n\tpublic async getPrimaryValue(\n\t\tentity: Model.Entity,\n\t\twhere: Input.UniqueWhere | CheckedPrimary,\n\t): Promise<[Input.PrimaryValue, undefined] | [undefined, MutationEntryNotFoundError]> {\n\t\tif (where instanceof CheckedPrimary) {\n\t\t\treturn [where.primaryValue, undefined]\n\t\t}\n\t\tconst result = await this.selectField(entity, where, entity.primary)\n\t\treturn result ? [result, undefined] : [undefined, new MutationEntryNotFoundError([], where)]\n\t}\n\n\tprivate async setupSystemVariables() {\n\t\tthis.systemVariablesSetupDone ??= (async () => {\n\t\t\tawait this.db.query('SELECT set_config(?, ?, false)', ['tenant.identity_id', this.identityId]) // todo rename to system.identity_id\n\t\t\tawait this.db.query('SELECT set_config(?, ?, false)', ['system.transaction_id', this.transactionId])\n\t\t})()\n\t\tawait this.systemVariablesSetupDone\n\t}\n}\n"],"names":["entity","relation"],"mappings":";;;;;;;;;;;;;;;;AA2BO,MAAM,OAAqF;AAAA,EAUjG,YACiB,IACA,YACA,eACC,QACA,wBACA,oBACA,sBACA,qBACA,cACA,sBACA,gBACA,SACA,UACA,aACA,cAChB;AAfe,SAAA,KAAA;AACA,SAAA,aAAA;AACA,SAAA,gBAAA;AACC,SAAA,SAAA;AACA,SAAA,yBAAA;AACA,SAAA,qBAAA;AACA,SAAA,uBAAA;AACA,SAAA,sBAAA;AACA,SAAA,eA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Q,MAAS,IAAI,CAAC,QAAW,IAAI,2BAA2B,IAAI,KAAK,CAAC;AAAA,EAC5F;AAAA,EAEA,MAAc,uBAAuB;AACpC,SAAK,6BAAL,KAAK,4BAA8B,YAAY;AAC9C,YAAM,KAAK,GAAG,MAAM,kCAAkC,CAAC,sBAAsB,KAAK,UAAU,CAAC;AAC7F,YAAM,KAAK,GAAG,MAAM,kCAAkC,CAAC,yBAAyB,KAAK,aAAa,CAAC;AAAA,IACpG;AACA,UAAM,KAAK;AAAA,EACZ;AACD;"}
@@ -6,7 +6,7 @@ var __defProp = Object.defineProperty;
6
6
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
7
  var __publicField = (obj, key, value) => __defNormalProp(obj, key + "", value);
8
8
  class MapperFactory {
9
- constructor(db, identityId, schema, schemaDatabaseMetadata, predicatesInjector, selectBuilderFactory, uniqueWhereExpander, whereBuilder, junctionTableManager, deleteExecutor, updater, inserter, pathFactory, providers) {
9
+ constructor(db, identityId, schema, schemaDatabaseMetadata, predicatesInjector, selectBuilderFactory, uniqueWhereExpander, whereBuilder, junctionTableManager, deleteExecutor, updater, inserter, pathFactory, providers, memoryBudget) {
10
10
  this.db = db;
11
11
  this.identityId = identityId;
12
12
  this.schema = schema;
@@ -21,13 +21,15 @@ class MapperFactory {
21
21
  this.inserter = inserter;
22
22
  this.pathFactory = pathFactory;
23
23
  this.providers = providers;
24
+ this.memoryBudget = memoryBudget;
24
25
  __publicField(this, "hooks", []);
25
26
  }
26
27
  create() {
27
28
  return this.createInternal(this.db);
28
29
  }
29
- transaction(cb) {
30
- return this.db.transaction(async (trx) => {
30
+ async transaction(cb) {
31
+ this.memoryBudget?.check();
32
+ return await this.db.transaction(async (trx) => {
31
33
  await trx.connection.query(Database.Connection.REPEATABLE_READ);
32
34
  const mapper = this.createInternal(trx);
33
35
  return await cb(mapper);
@@ -48,7 +50,8 @@ class MapperFactory {
48
50
  this.deleteExecutor,
49
51
  this.updater,
50
52
  this.inserter,
51
- this.pathFactory
53
+ this.pathFactory,
54
+ this.memoryBudget
52
55
  );
53
56
  this.hooks.forEach((it) => it(mapper));
54
57
  return mapper;
@@ -1 +1 @@
1
- {"version":3,"file":"MapperFactory.cjs","sources":["../../../../../packages/engine-content-api/src/mapper/MapperFactory.ts"],"sourcesContent":["import { PredicatesInjector } from '../acl'\nimport { PathFactory, SelectBuilderFactory, WhereBuilder } from './select'\nimport { UniqueWhereExpander } from '../inputProcessing'\nimport { JunctionTableManager } from './JunctionTableManager'\nimport { DeleteExecutor } from './delete'\nimport { Updater } from './update'\nimport { Inserter } from './insert'\nimport { Model } from '@contember/schema'\nimport { Client, Connection, DatabaseMetadata } from '@contember/database'\nimport { Mapper } from './Mapper'\nimport { Providers } from '@contember/schema-utils'\n\nexport type MapperFactoryHook = (mapper: Mapper) => void\n\nexport class MapperFactory {\n\tpublic readonly hooks: MapperFactoryHook[] = []\n\n\tconstructor(\n\t\tprivate readonly db: Client,\n\t\tprivate readonly identityId: string,\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly schemaDatabaseMetadata: DatabaseMetadata,\n\t\tprivate readonly predicatesInjector: PredicatesInjector,\n\t\tprivate readonly selectBuilderFactory: SelectBuilderFactory,\n\t\tprivate readonly uniqueWhereExpander: UniqueWhereExpander,\n\t\tprivate readonly whereBuilder: WhereBuilder,\n\t\tprivate readonly junctionTableManager: JunctionTableManager,\n\t\tprivate readonly deleteExecutor: DeleteExecutor,\n\t\tprivate readonly updater: Updater,\n\t\tprivate readonly inserter: Inserter,\n\t\tprivate readonly pathFactory: PathFactory,\n\t\tprivate readonly providers: Providers,\n\t) {\n\t}\n\n\tpublic create() {\n\t\treturn this.createInternal(this.db)\n\t}\n\n\tpublic transaction<T>(cb: (mapper: Mapper<Connection.TransactionLike>) => Promise<T>): Promise<T> {\n\t\treturn this.db.transaction(async trx => {\n\t\t\tawait trx.connection.query(Connection.REPEATABLE_READ)\n\t\t\tconst mapper = this.createInternal(trx)\n\t\t\treturn await cb(mapper)\n\t\t})\n\t}\n\n\tprivate createInternal<T extends Connection.ConnectionLike>(db: Client<T>) {\n\t\tconst mapper = new Mapper<T>(\n\t\t\tdb,\n\t\t\tthis.identityId,\n\t\t\tthis.providers.uuid(),\n\t\t\tthis.schema,\n\t\t\tthis.schemaDatabaseMetadata,\n\t\t\tthis.predicatesInjector,\n\t\t\tthis.selectBuilderFactory,\n\t\t\tthis.uniqueWhereExpander,\n\t\t\tthis.whereBuilder,\n\t\t\tthis.junctionTableManager,\n\t\t\tthis.deleteExecutor,\n\t\t\tthis.updater,\n\t\t\tthis.inserter,\n\t\t\tthis.pathFactory,\n\t\t)\n\t\tthis.hooks.forEach(it => it(mapper))\n\t\treturn mapper\n\t}\n}\n"],"names":["Connection","Mapper"],"mappings":";;;;;;;AAcO,MAAM,cAAc;AAAA,EAG1B,YACkB,IACA,YACA,QACA,wBACA,oBACA,sBACA,qBACA,cACA,sBACA,gBACA,SACA,UACA,aACA,WAChB;AAdgB,SAAA,KAAA;AACA,SAAA,aAAA;AACA,SAAA,SAAA;AACA,SAAA,yBAAA;AACA,SAAA,qBAAA;AACA,SAAA,uBAAA;AACA,SAAA,sBAAA;AACA,SAAA,eAAA;AACA,SAAA,uBAAA;AACA,SAAA,iBAAA;AACA,SAAA,UAAA;AACA,SAAA,WAAA;AACA,SAAA,cAAA;AACA,SAAA,YAAA;AAhBlB,kBAAA,MAAgB,SAA6B,EAAC;AAAA,EAkB9C;AAAA,EAEO,SAAS;AACf,WAAO,KAAK,eAAe,KAAK,EAAE;AAAA,EACnC;AAAA,EAEO,YAAe,IAA4E;AACjG,WAAO,KAAK,GAAG,YAAY,OAAM,QAAO;AACvC,YAAM,IAAI,WAAW,MAAMA,SAAAA,WAAW,eAAe;AACrD,YAAM,SAAS,KAAK,eAAe,GAAG;AACtC,aAAO,MAAM,GAAG,MAAM;AAAA,IACvB,CAAC;AAAA,EACF;AAAA,EAEQ,eAAoD,IAAe;AAC1E,UAAM,SAAS,IAAIC,OAAAA;AAAAA,MAClB;AAAA,MACA,KAAK;AAAA,MACL,KAAK,UAAU,KAAA;AAAA,MACf,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,IAAA;AAEN,SAAK,MAAM,QAAQ,CAAA,OAAM,GAAG,MAAM,CAAC;AACnC,WAAO;AAAA,EACR;AACD;;"}
1
+ {"version":3,"file":"MapperFactory.cjs","sources":["../../../../../packages/engine-content-api/src/mapper/MapperFactory.ts"],"sourcesContent":["import { PredicatesInjector } from '../acl/index.js'\nimport { PathFactory, SelectBuilderFactory, WhereBuilder } from './select/index.js'\nimport { UniqueWhereExpander } from '../inputProcessing/index.js'\nimport { JunctionTableManager } from './JunctionTableManager.js'\nimport { DeleteExecutor } from './delete/index.js'\nimport { Updater } from './update/index.js'\nimport { Inserter } from './insert/index.js'\nimport { Model } from '@contember/schema'\nimport { Client, Connection, DatabaseMetadata, RequestMemoryBudget } from '@contember/database'\nimport { Mapper } from './Mapper.js'\nimport { Providers } from '@contember/schema-utils'\n\nexport type MapperFactoryHook = (mapper: Mapper) => void\n\nexport class MapperFactory {\n\tpublic readonly hooks: MapperFactoryHook[] = []\n\n\tconstructor(\n\t\tprivate readonly db: Client,\n\t\tprivate readonly identityId: string,\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly schemaDatabaseMetadata: DatabaseMetadata,\n\t\tprivate readonly predicatesInjector: PredicatesInjector,\n\t\tprivate readonly selectBuilderFactory: SelectBuilderFactory,\n\t\tprivate readonly uniqueWhereExpander: UniqueWhereExpander,\n\t\tprivate readonly whereBuilder: WhereBuilder,\n\t\tprivate readonly junctionTableManager: JunctionTableManager,\n\t\tprivate readonly deleteExecutor: DeleteExecutor,\n\t\tprivate readonly updater: Updater,\n\t\tprivate readonly inserter: Inserter,\n\t\tprivate readonly pathFactory: PathFactory,\n\t\tprivate readonly providers: Providers,\n\t\tprivate readonly memoryBudget?: RequestMemoryBudget,\n\t) {\n\t}\n\n\tpublic create() {\n\t\treturn this.createInternal(this.db)\n\t}\n\n\tpublic async transaction<T>(cb: (mapper: Mapper<Connection.TransactionLike>) => Promise<T>): Promise<T> {\n\t\t// Refused here as well as by the bound `db`, so an exhausted request stops before it queues for a pool connection.\n\t\tthis.memoryBudget?.check()\n\t\treturn await this.db.transaction(async trx => {\n\t\t\tawait trx.connection.query(Connection.REPEATABLE_READ)\n\t\t\tconst mapper = this.createInternal(trx)\n\t\t\treturn await cb(mapper)\n\t\t})\n\t}\n\n\tprivate createInternal<T extends Connection.ConnectionLike>(db: Client<T>) {\n\t\tconst mapper = new Mapper<T>(\n\t\t\tdb,\n\t\t\tthis.identityId,\n\t\t\tthis.providers.uuid(),\n\t\t\tthis.schema,\n\t\t\tthis.schemaDatabaseMetadata,\n\t\t\tthis.predicatesInjector,\n\t\t\tthis.selectBuilderFactory,\n\t\t\tthis.uniqueWhereExpander,\n\t\t\tthis.whereBuilder,\n\t\t\tthis.junctionTableManager,\n\t\t\tthis.deleteExecutor,\n\t\t\tthis.updater,\n\t\t\tthis.inserter,\n\t\t\tthis.pathFactory,\n\t\t\tthis.memoryBudget,\n\t\t)\n\t\tthis.hooks.forEach(it => it(mapper))\n\t\treturn mapper\n\t}\n}\n"],"names":["Connection","Mapper"],"mappings":";;;;;;;AAcO,MAAM,cAAc;AAAA,EAG1B,YACkB,IACA,YACA,QACA,wBACA,oBACA,sBACA,qBACA,cACA,sBACA,gBACA,SACA,UACA,aACA,WACA,cAChB;AAfgB,SAAA,KAAA;AACA,SAAA,aAAA;AACA,SAAA,SAAA;AACA,SAAA,yBAAA;AACA,SAAA,qBAAA;AACA,SAAA,uBAAA;AACA,SAAA,sBAAA;AACA,SAAA,eAAA;AACA,SAAA,uBAAA;AACA,S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