@contember/engine-content-api 2.2.0-alpha.1 → 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 (251) 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/PredicatesInjector.cjs +1 -68
  7. package/dist/development/src/acl/PredicatesInjector.cjs.map +1 -1
  8. package/dist/development/src/acl/PredicatesInjector.js +1 -68
  9. package/dist/development/src/acl/PredicatesInjector.js.map +1 -1
  10. package/dist/development/src/mapper/Mapper.cjs +8 -5
  11. package/dist/development/src/mapper/Mapper.cjs.map +1 -1
  12. package/dist/development/src/mapper/Mapper.js +8 -5
  13. package/dist/development/src/mapper/Mapper.js.map +1 -1
  14. package/dist/development/src/mapper/MapperFactory.cjs +7 -4
  15. package/dist/development/src/mapper/MapperFactory.cjs.map +1 -1
  16. package/dist/development/src/mapper/MapperFactory.js +7 -4
  17. package/dist/development/src/mapper/MapperFactory.js.map +1 -1
  18. package/dist/development/src/mapper/select/ConditionBuilder.cjs +8 -1
  19. package/dist/development/src/mapper/select/ConditionBuilder.cjs.map +1 -1
  20. package/dist/development/src/mapper/select/ConditionBuilder.js +8 -1
  21. package/dist/development/src/mapper/select/ConditionBuilder.js.map +1 -1
  22. package/dist/development/src/mapper/select/RelationFetcher.cjs +2 -2
  23. package/dist/development/src/mapper/select/RelationFetcher.cjs.map +1 -1
  24. package/dist/development/src/mapper/select/RelationFetcher.js +2 -2
  25. package/dist/development/src/mapper/select/RelationFetcher.js.map +1 -1
  26. package/dist/development/src/mapper/select/SelectHydrator.cjs +39 -19
  27. package/dist/development/src/mapper/select/SelectHydrator.cjs.map +1 -1
  28. package/dist/development/src/mapper/select/SelectHydrator.js +39 -19
  29. package/dist/development/src/mapper/select/SelectHydrator.js.map +1 -1
  30. package/dist/development/src/resolvers/MutationResolver.cjs +49 -35
  31. package/dist/development/src/resolvers/MutationResolver.cjs.map +1 -1
  32. package/dist/development/src/resolvers/MutationResolver.js +50 -36
  33. package/dist/development/src/resolvers/MutationResolver.js.map +1 -1
  34. package/dist/production/src/ExecutionContainer.cjs +7 -4
  35. package/dist/production/src/ExecutionContainer.cjs.map +1 -1
  36. package/dist/production/src/ExecutionContainer.js +7 -4
  37. package/dist/production/src/ExecutionContainer.js.map +1 -1
  38. package/dist/production/src/acl/PredicatesInjector.cjs +1 -68
  39. package/dist/production/src/acl/PredicatesInjector.cjs.map +1 -1
  40. package/dist/production/src/acl/PredicatesInjector.js +1 -68
  41. package/dist/production/src/acl/PredicatesInjector.js.map +1 -1
  42. package/dist/production/src/mapper/Mapper.cjs +8 -5
  43. package/dist/production/src/mapper/Mapper.cjs.map +1 -1
  44. package/dist/production/src/mapper/Mapper.js +8 -5
  45. package/dist/production/src/mapper/Mapper.js.map +1 -1
  46. package/dist/production/src/mapper/MapperFactory.cjs +7 -4
  47. package/dist/production/src/mapper/MapperFactory.cjs.map +1 -1
  48. package/dist/production/src/mapper/MapperFactory.js +7 -4
  49. package/dist/production/src/mapper/MapperFactory.js.map +1 -1
  50. package/dist/production/src/mapper/select/ConditionBuilder.cjs +8 -1
  51. package/dist/production/src/mapper/select/ConditionBuilder.cjs.map +1 -1
  52. package/dist/production/src/mapper/select/ConditionBuilder.js +8 -1
  53. package/dist/production/src/mapper/select/ConditionBuilder.js.map +1 -1
  54. package/dist/production/src/mapper/select/RelationFetcher.cjs +2 -2
  55. package/dist/production/src/mapper/select/RelationFetcher.cjs.map +1 -1
  56. package/dist/production/src/mapper/select/RelationFetcher.js +2 -2
  57. package/dist/production/src/mapper/select/RelationFetcher.js.map +1 -1
  58. package/dist/production/src/mapper/select/SelectHydrator.cjs +39 -19
  59. package/dist/production/src/mapper/select/SelectHydrator.cjs.map +1 -1
  60. package/dist/production/src/mapper/select/SelectHydrator.js +39 -19
  61. package/dist/production/src/mapper/select/SelectHydrator.js.map +1 -1
  62. package/dist/production/src/resolvers/MutationResolver.cjs +49 -35
  63. package/dist/production/src/resolvers/MutationResolver.cjs.map +1 -1
  64. package/dist/production/src/resolvers/MutationResolver.js +50 -36
  65. package/dist/production/src/resolvers/MutationResolver.js.map +1 -1
  66. package/dist/tests/cases/integration/graphQlRequests/insert/memoryBudget.test.d.ts +2 -0
  67. package/dist/tests/cases/integration/graphQlRequests/insert/memoryBudget.test.d.ts.map +1 -0
  68. package/dist/tests/cases/integration/graphQlRequests/validation/utils.d.ts.map +1 -1
  69. package/dist/tests/cases/integration/graphQlSchema/model.d.ts +1 -1
  70. package/dist/tests/src/assert.d.ts.map +1 -1
  71. package/dist/tests/src/tags.d.ts.map +1 -1
  72. package/dist/tests/src/test.d.ts +2 -0
  73. package/dist/tests/src/test.d.ts.map +1 -1
  74. package/dist/tests/src/testGraphql.d.ts.map +1 -1
  75. package/dist/tests/src/testUuid.d.ts.map +1 -1
  76. package/dist/tests/tsconfig.tsbuildinfo +1 -1
  77. package/dist/types/ExecutionContainer.d.ts +3 -2
  78. package/dist/types/ExecutionContainer.d.ts.map +1 -1
  79. package/dist/types/acl/Authorizator.d.ts.map +1 -1
  80. package/dist/types/acl/EvaluatedPredicateReplacer.d.ts.map +1 -1
  81. package/dist/types/acl/PermissionFactory.d.ts.map +1 -1
  82. package/dist/types/acl/PredicateFactory.d.ts.map +1 -1
  83. package/dist/types/acl/PredicatesInjector.d.ts +0 -6
  84. package/dist/types/acl/PredicatesInjector.d.ts.map +1 -1
  85. package/dist/types/acl/VariableInjector.d.ts.map +1 -1
  86. package/dist/types/acl/VariableUtils.d.ts.map +1 -1
  87. package/dist/types/exception.d.ts.map +1 -1
  88. package/dist/types/extensions/hasManyToHasOneReducer/HasManyToHasOneReducer.d.ts.map +1 -1
  89. package/dist/types/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.d.ts.map +1 -1
  90. package/dist/types/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.d.ts.map +1 -1
  91. package/dist/types/extensions/paginatedHasMany/PaginatedHasManyCountVisitor.d.ts.map +1 -1
  92. package/dist/types/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.d.ts.map +1 -1
  93. package/dist/types/extensions/paginatedHasMany/PaginatedHasManyFieldProvider.d.ts.map +1 -1
  94. package/dist/types/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.d.ts.map +1 -1
  95. package/dist/types/extensions/paginatedHasMany/PaginatedHasManyNodesVisitor.d.ts.map +1 -1
  96. package/dist/types/input-validation/ColumnValueResolver.d.ts.map +1 -1
  97. package/dist/types/input-validation/EntityRulesResolver.d.ts.map +1 -1
  98. package/dist/types/input-validation/JsonSchemaValidator.d.ts.map +1 -1
  99. package/dist/types/input-validation/QueryAstFactory.d.ts.map +1 -1
  100. package/dist/types/input-validation/ValidationContext.d.ts.map +1 -1
  101. package/dist/types/input-validation/ValidationDataSelector.d.ts +1 -1
  102. package/dist/types/input-validation/ValidationDataSelector.d.ts.map +1 -1
  103. package/dist/types/input-validation/ValidationEvaluation.d.ts.map +1 -1
  104. package/dist/types/input-validation/ValidationPath.d.ts.map +1 -1
  105. package/dist/types/input-validation/dependencies/DependencyCollector.d.ts.map +1 -1
  106. package/dist/types/input-validation/dependencies/DependencyMerger.d.ts.map +1 -1
  107. package/dist/types/input-validation/preValidation/CreateInputPreValidationProcessor.d.ts.map +1 -1
  108. package/dist/types/input-validation/preValidation/InputPreValidator.d.ts.map +1 -1
  109. package/dist/types/input-validation/preValidation/UpdateInputPreValidationProcessor.d.ts.map +1 -1
  110. package/dist/types/inputProcessing/CreateInputVisitor.d.ts.map +1 -1
  111. package/dist/types/inputProcessing/FieldNode.d.ts.map +1 -1
  112. package/dist/types/inputProcessing/ObjectNode.d.ts.map +1 -1
  113. package/dist/types/inputProcessing/UniqueWhereExpander.d.ts.map +1 -1
  114. package/dist/types/inputProcessing/UpdateInputVisitor.d.ts.map +1 -1
  115. package/dist/types/introspection/IntrospectionSchemaDefinitionFactory.d.ts.map +1 -1
  116. package/dist/types/introspection/IntrospectionSchemaFactory.d.ts.map +1 -1
  117. package/dist/types/introspection/introspection.schema.d.ts.map +1 -1
  118. package/dist/types/mapper/CheckedPrimary.d.ts.map +1 -1
  119. package/dist/types/mapper/ColumnValue.d.ts.map +1 -1
  120. package/dist/types/mapper/Constraints.d.ts.map +1 -1
  121. package/dist/types/mapper/ErrorUtils.d.ts.map +1 -1
  122. package/dist/types/mapper/EventManager.d.ts +9 -9
  123. package/dist/types/mapper/EventManager.d.ts.map +1 -1
  124. package/dist/types/mapper/JunctionTableManager.d.ts.map +1 -1
  125. package/dist/types/mapper/Mapper.d.ts +5 -2
  126. package/dist/types/mapper/Mapper.d.ts.map +1 -1
  127. package/dist/types/mapper/MapperFactory.d.ts +3 -2
  128. package/dist/types/mapper/MapperFactory.d.ts.map +1 -1
  129. package/dist/types/mapper/MutationProcessorHelper.d.ts.map +1 -1
  130. package/dist/types/mapper/Result.d.ts.map +1 -1
  131. package/dist/types/mapper/delete/DeleteExecutor.d.ts.map +1 -1
  132. package/dist/types/mapper/delete/DeleteState.d.ts.map +1 -1
  133. package/dist/types/mapper/delete/DeletedEntitiesStorage.d.ts.map +1 -1
  134. package/dist/types/mapper/delete/helpers.d.ts +1 -1
  135. package/dist/types/mapper/delete/helpers.d.ts.map +1 -1
  136. package/dist/types/mapper/insert/InsertBuilder.d.ts.map +1 -1
  137. package/dist/types/mapper/insert/InsertBuilderFactory.d.ts.map +1 -1
  138. package/dist/types/mapper/insert/Inserter.d.ts.map +1 -1
  139. package/dist/types/mapper/insert/SqlCreateInputProcessor.d.ts.map +1 -1
  140. package/dist/types/mapper/insert/relations/ManyHasManyCreateInputProcessor.d.ts +1 -1
  141. package/dist/types/mapper/insert/relations/ManyHasManyCreateInputProcessor.d.ts.map +1 -1
  142. package/dist/types/mapper/insert/relations/ManyHasOneCreateInputProcessor.d.ts.map +1 -1
  143. package/dist/types/mapper/insert/relations/OneHasManyCreateInputProcessor.d.ts.map +1 -1
  144. package/dist/types/mapper/insert/relations/OneHasOneInverseCreateInputProcessor.d.ts +1 -1
  145. package/dist/types/mapper/insert/relations/OneHasOneInverseCreateInputProcessor.d.ts.map +1 -1
  146. package/dist/types/mapper/insert/relations/OneHasOneOwningCreateInputProcessor.d.ts.map +1 -1
  147. package/dist/types/mapper/select/ConditionBuilder.d.ts.map +1 -1
  148. package/dist/types/mapper/select/JoinBuilder.d.ts.map +1 -1
  149. package/dist/types/mapper/select/JoinVisitor.d.ts.map +1 -1
  150. package/dist/types/mapper/select/OrderByBuilder.d.ts.map +1 -1
  151. package/dist/types/mapper/select/OrderByHelper.d.ts.map +1 -1
  152. package/dist/types/mapper/select/Path.d.ts.map +1 -1
  153. package/dist/types/mapper/select/RelationFetcher.d.ts.map +1 -1
  154. package/dist/types/mapper/select/SelectBuilder.d.ts.map +1 -1
  155. package/dist/types/mapper/select/SelectHydrator.d.ts +6 -0
  156. package/dist/types/mapper/select/SelectHydrator.d.ts.map +1 -1
  157. package/dist/types/mapper/select/WhereBuilder.d.ts.map +1 -1
  158. package/dist/types/mapper/select/handlers/FieldsVisitor.d.ts.map +1 -1
  159. package/dist/types/mapper/select/handlers/FieldsVisitorFactory.d.ts.map +1 -1
  160. package/dist/types/mapper/select/handlers/MetaHandler.d.ts.map +1 -1
  161. package/dist/types/mapper/select/optimizer/ConditionOptimizer.d.ts.map +1 -1
  162. package/dist/types/mapper/select/optimizer/WhereOptimizer.d.ts.map +1 -1
  163. package/dist/types/mapper/select/optimizer/WhereReplacer.d.ts.map +1 -1
  164. package/dist/types/mapper/select/optimizer/helpers.d.ts +1 -1
  165. package/dist/types/mapper/select/optimizer/helpers.d.ts.map +1 -1
  166. package/dist/types/mapper/update/SqlUpdateInputProcessor.d.ts.map +1 -1
  167. package/dist/types/mapper/update/UpdateBuilder.d.ts.map +1 -1
  168. package/dist/types/mapper/update/UpdateBuilderFactory.d.ts.map +1 -1
  169. package/dist/types/mapper/update/Updater.d.ts.map +1 -1
  170. package/dist/types/mapper/update/relations/ManyHasManyUpdateInputProcessor.d.ts +2 -2
  171. package/dist/types/mapper/update/relations/ManyHasManyUpdateInputProcessor.d.ts.map +1 -1
  172. package/dist/types/mapper/update/relations/ManyHasOneUpdateInputProcessor.d.ts.map +1 -1
  173. package/dist/types/mapper/update/relations/OneHasManyUpdateInputProcessor.d.ts.map +1 -1
  174. package/dist/types/mapper/update/relations/OneHasOneInverseUpdateInputProcessor.d.ts.map +1 -1
  175. package/dist/types/mapper/update/relations/OneHasOneOwningUpdateInputProcessor.d.ts.map +1 -1
  176. package/dist/types/resolvers/GraphQlQueryAstFactory.d.ts.map +1 -1
  177. package/dist/types/resolvers/MutationResolver.d.ts.map +1 -1
  178. package/dist/types/resolvers/ReadHelpers.d.ts.map +1 -1
  179. package/dist/types/resolvers/ReadResolver.d.ts.map +1 -1
  180. package/dist/types/resolvers/RefreshViewResolver.d.ts.map +1 -1
  181. package/dist/types/resolvers/ValidationResolver.d.ts.map +1 -1
  182. package/dist/types/schema/ColumnTypeResolver.d.ts.map +1 -1
  183. package/dist/types/schema/ConditionTypeProvider.d.ts.map +1 -1
  184. package/dist/types/schema/EntityTypeProvider.d.ts.map +1 -1
  185. package/dist/types/schema/EnumsProvider.d.ts.map +1 -1
  186. package/dist/types/schema/FieldAccessVisitor.d.ts.map +1 -1
  187. package/dist/types/schema/GraphQlSchemaBuilder.d.ts.map +1 -1
  188. package/dist/types/schema/GraphQlSchemaBuilderFactory.d.ts.map +1 -1
  189. package/dist/types/schema/MutationProvider.d.ts.map +1 -1
  190. package/dist/types/schema/OperationExtension.d.ts.map +1 -1
  191. package/dist/types/schema/OrderByTypeProvider.d.ts.map +1 -1
  192. package/dist/types/schema/PaginatedFieldConfigFactory.d.ts.map +1 -1
  193. package/dist/types/schema/QueryProvider.d.ts.map +1 -1
  194. package/dist/types/schema/RefreshViewMutationProvider.d.ts.map +1 -1
  195. package/dist/types/schema/ValidationQueriesProvider.d.ts.map +1 -1
  196. package/dist/types/schema/WhereTypeProvider.d.ts.map +1 -1
  197. package/dist/types/schema/entities/FieldArgsVisitor.d.ts.map +1 -1
  198. package/dist/types/schema/entities/FieldTypeVisitor.d.ts.map +1 -1
  199. package/dist/types/schema/mutations/ConnectOrCreateRelationInputProvider.d.ts.map +1 -1
  200. package/dist/types/schema/mutations/CreateEntityInputFieldVisitor.d.ts.map +1 -1
  201. package/dist/types/schema/mutations/CreateEntityRelationAllowedOperationsVisitor.d.ts.map +1 -1
  202. package/dist/types/schema/mutations/CreateEntityRelationInputFieldVisitor.d.ts.map +1 -1
  203. package/dist/types/schema/mutations/CreateEntityRelationInputProvider.d.ts.map +1 -1
  204. package/dist/types/schema/mutations/EntityInputProvider.d.ts.map +1 -1
  205. package/dist/types/schema/mutations/UpdateEntityInputFieldVisitor.d.ts.map +1 -1
  206. package/dist/types/schema/mutations/UpdateEntityRelationAllowedOperationsVisitor.d.ts.map +1 -1
  207. package/dist/types/schema/mutations/UpdateEntityRelationInputFieldVisitor.d.ts.map +1 -1
  208. package/dist/types/schema/mutations/UpdateEntityRelationInputProvider.d.ts.map +1 -1
  209. package/dist/types/schema/utils.d.ts.map +1 -1
  210. package/dist/types/tsconfig.tsbuildinfo +1 -1
  211. package/dist/types/utils/Mutex.d.ts.map +1 -1
  212. package/dist/types/utils/ResolveInfoUtils.d.ts.map +1 -1
  213. package/dist/types/utils/accessor.d.ts.map +1 -1
  214. package/dist/types/utils/isIt.d.ts.map +1 -1
  215. package/dist/types/utils/paginationUtils.d.ts.map +1 -1
  216. package/dist/types/utils/promises.d.ts.map +1 -1
  217. package/dist/types/utils/singletonFactory.d.ts.map +1 -1
  218. package/dist/types/utils/strings.d.ts.map +1 -1
  219. package/dist/types/utils/tuple.d.ts.map +1 -1
  220. package/dist/types/utils/uniqueWhereFields.d.ts.map +1 -1
  221. package/dist/types/utils/viewComputedId.d.ts.map +1 -1
  222. package/package.json +9 -9
  223. package/src/ExecutionContainer.ts +7 -2
  224. package/src/acl/PredicatesInjector.ts +1 -104
  225. package/src/mapper/Mapper.ts +9 -5
  226. package/src/mapper/MapperFactory.ts +7 -3
  227. package/src/mapper/select/ConditionBuilder.ts +12 -1
  228. package/src/mapper/select/RelationFetcher.ts +2 -4
  229. package/src/mapper/select/SelectHydrator.ts +43 -16
  230. package/src/resolvers/MutationResolver.ts +59 -36
  231. package/tests/cases/integration/graphQlRequests/insert/memoryBudget.test.ts +97 -0
  232. package/tests/cases/integration/graphQlRequests/query/pagination/hasManyLimit.test.ts +48 -2
  233. package/tests/cases/integration/graphQlRequests/query/relations/oneHasMany.test.ts +3 -3
  234. package/tests/cases/integration/graphQlRequests/query/sorting/randomSort.test.ts +1 -1
  235. package/tests/cases/integration/graphQlSchema/schema-acl-allowed.gql +1 -0
  236. package/tests/cases/integration/graphQlSchema/schema-acl-create-only.gql +1 -0
  237. package/tests/cases/integration/graphQlSchema/schema-acl-restricted-create.gql +1 -0
  238. package/tests/cases/integration/graphQlSchema/schema-acl-restricted-delete.gql +1 -0
  239. package/tests/cases/integration/graphQlSchema/schema-acl-restricted-update.gql +1 -0
  240. package/tests/cases/integration/graphQlSchema/schema-acl.gql +1 -0
  241. package/tests/cases/integration/graphQlSchema/schema-aliased-type.gql +1 -0
  242. package/tests/cases/integration/graphQlSchema/schema-array.gql +1 -0
  243. package/tests/cases/integration/graphQlSchema/schema-basic.gql +1 -0
  244. package/tests/cases/integration/graphQlSchema/schema-bug-66.gql +1 -0
  245. package/tests/cases/integration/graphQlSchema/schema-column-types.gql +1 -0
  246. package/tests/cases/integration/graphQlSchema/schema-custom-primary.gql +1 -0
  247. package/tests/cases/integration/graphQlSchema/schema-has-many-reduction.gql +1 -0
  248. package/tests/cases/integration/graphQlSchema/schema-new-builder.gql +1 -0
  249. package/tests/cases/integration/graphQlSchema/schema-no-root-ops.gql +1 -0
  250. package/tests/cases/unit/predicatesInjector.test.ts +15 -67
  251. package/tests/src/test.ts +3 -1
@@ -77,6 +77,7 @@ class ExecutionContainerFactory {
77
77
  identityVariables,
78
78
  identityId,
79
79
  db,
80
+ memoryBudget,
80
81
  schema,
81
82
  schemaMeta,
82
83
  systemSchema,
@@ -85,7 +86,7 @@ class ExecutionContainerFactory {
85
86
  schemaDatabaseMetadata,
86
87
  userInfo
87
88
  }) {
88
- return new Builder({}).addService("systemSchema", () => systemSchema).addService("db", () => db).addService("project", () => project).addService("stage", () => stage).addService("triggeredActionsCollector", () => schema.settings.actions?.returnTriggeredActions === true ? new InMemoryTriggeredActionsCollector() : void 0).addService("schema", () => schema).addService("schemaMeta", () => schemaMeta).addService("schemaDatabaseMetadata", () => schemaDatabaseMetadata).addService("userInfo", () => userInfo).addService("providers", () => this.providers).addService("variableInjector", ({ schema: schema2 }) => new VariableInjector(schema2.model, identityVariables)).addService(
89
+ return new Builder({}).addService("systemSchema", () => systemSchema).addService("db", () => memoryBudget ? db.withMemoryBudget(memoryBudget, { chargeRows: false }) : db).addService("project", () => project).addService("stage", () => stage).addService("triggeredActionsCollector", () => schema.settings.actions?.returnTriggeredActions === true ? new InMemoryTriggeredActionsCollector() : void 0).addService("schema", () => schema).addService("schemaMeta", () => schemaMeta).addService("schemaDatabaseMetadata", () => schemaDatabaseMetadata).addService("userInfo", () => userInfo).addService("providers", () => this.providers).addService("variableInjector", ({ schema: schema2 }) => new VariableInjector(schema2.model, identityVariables)).addService(
89
90
  "predicateFactory",
90
91
  ({ variableInjector, schema: schema2 }) => new PredicateFactory(permissions, schema2.model, variableInjector, allPermissions)
91
92
  ).addService("predicatesInjector", ({ predicateFactory, schema: schema2 }) => new PredicatesInjector(schema2.model, predicateFactory)).addService("joinBuilder", ({ schema: schema2 }) => new JoinBuilder(schema2.model)).addService("conditionBuilder", () => new ConditionBuilder()).addService("pathFactory", () => new PathFactory()).addService("whereOptimized", ({ schema: schema2 }) => new WhereOptimizer(schema2.model, new ConditionOptimizer(), this.whereOptimizerOptions)).addService("whereBuilder", ({ joinBuilder, conditionBuilder, pathFactory, whereOptimized, schema: schema2 }) => new WhereBuilder(
@@ -158,10 +159,11 @@ class ExecutionContainerFactory {
158
159
  pathFactory,
159
160
  providers,
160
161
  schema: schema2,
161
- schemaDatabaseMetadata: schemaDatabaseMetadata2
162
+ schemaDatabaseMetadata: schemaDatabaseMetadata2,
163
+ db: db2
162
164
  }) => {
163
165
  return new MapperFactory(
164
- db,
166
+ db2,
165
167
  identityId,
166
168
  schema2.model,
167
169
  schemaDatabaseMetadata2,
@@ -174,7 +176,8 @@ class ExecutionContainerFactory {
174
176
  updater,
175
177
  inserter,
176
178
  pathFactory,
177
- providers
179
+ providers,
180
+ memoryBudget
178
181
  );
179
182
  }
180
183
  ).addService("queryAstFactory", () => new GraphQlQueryAstFactory()).addService("readResolver", ({ mapperFactory, queryAstFactory }) => new ReadResolver(mapperFactory, queryAstFactory)).addService("validationDependencyCollector", () => new DependencyCollector()).addService("validationQueryAstFactory", ({ schema: schema2 }) => new QueryAstFactory(schema2.model)).addService("dataSelector", ({ validationQueryAstFactory, schema: schema2 }) => new ValidationDataSelector(schema2.model, validationQueryAstFactory)).addService("columnValueResolver", ({ providers }) => new ColumnValueResolver(providers)).addService("entityRulesResolver", ({ schema: schema2 }) => new EntityRulesResolver(schema2.validation, schema2.model)).addService(
@@ -1 +1 @@
1
- {"version":3,"file":"ExecutionContainer.js","sources":["../../../../packages/engine-content-api/src/ExecutionContainer.ts"],"sourcesContent":["import { PredicateFactory, PredicatesInjector, VariableInjector } from './acl/index.js'\nimport {\n\tConditionBuilder,\n\tFieldsVisitorFactory,\n\tJoinBuilder,\n\tMetaHandler,\n\tOrderByBuilder,\n\tRelationFetcher,\n\tWhereBuilder,\n} from './mapper/select/index.js'\nimport { UniqueWhereExpander } from './inputProcessing/index.js'\nimport { HasManyToHasOneReducer, HasManyToHasOneReducerExecutionHandler } from './extensions/index.js'\nimport {\n\tDeleteExecutor,\n\tInsertBuilderFactory,\n\tInserter,\n\tJunctionConnectHandler,\n\tJunctionDisconnectHandler,\n\tJunctionTableManager,\n\tMapperFactory,\n\tPathFactory,\n\tSelectBuilder,\n\tSelectBuilderFactory,\n\tSelectHydrator,\n\tUpdateBuilderFactory,\n\tUpdater,\n} from './mapper/index.js'\nimport { Builder } from '@contember/dic'\nimport { Acl, Model, Schema } from '@contember/schema'\nimport { Client, DatabaseMetadata, SelectBuilder as DbSelectBuilder } from '@contember/database'\nimport { ParsedMembership, Providers } from '@contember/schema-utils'\nimport { PaginatedHasManyExecutionHandler } from './extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.js'\nimport { PaginatedHasManyFieldProvider } from './extensions/paginatedHasMany/PaginatedHasManyFieldProvider.js'\nimport { WhereOptimizer, WhereOptimizerOptions } from './mapper/select/optimizer/WhereOptimizer.js'\nimport { ConditionOptimizer } from './mapper/select/optimizer/ConditionOptimizer.js'\nimport { GraphQlQueryAstFactory, MutationResolver, ReadResolver, ValidationResolver } from './resolvers/index.js'\nimport {\n\tColumnValueResolver,\n\tDependencyCollector,\n\tEntityRulesResolver,\n\tInputPreValidator,\n\tQueryAstFactory,\n\tValidationDataSelector,\n} from './input-validation/index.js'\nimport { RefreshViewResolver } from './resolvers/RefreshViewResolver.js'\n\nexport interface TriggeredActionEvent {\n\tid: string\n\ttrigger: string\n\ttarget: string\n\ttransactionId: string\n}\n\nexport interface TriggeredActionsCollector {\n\tadd(events: readonly TriggeredActionEvent[]): void\n\tgetEvents(): readonly TriggeredActionEvent[]\n}\n\nexport class InMemoryTriggeredActionsCollector implements TriggeredActionsCollector {\n\tprivate events: TriggeredActionEvent[] = []\n\n\tadd(events: readonly TriggeredActionEvent[]): void {\n\t\tfor (const event of events) {\n\t\t\tthis.events.push(event)\n\t\t}\n\t}\n\n\tgetEvents(): readonly TriggeredActionEvent[] {\n\t\treturn this.events\n\t}\n}\n\nexport type ExecutionContainerArgs = {\n\tschema: Schema\n\tschemaMeta: { id?: number }\n\tschemaDatabaseMetadata: DatabaseMetadata\n\tdb: Client\n\tidentityId: string\n\tidentityVariables: Acl.VariablesMap\n\tpermissions: Acl.Permissions\n\tallPermissions?: Acl.Permissions\n\tsystemSchema: string\n\tproject: { slug: string }\n\tstage: { id: string; slug: string }\n\tuserInfo: { ipAddress: string | null; userAgent: string | null }\n}\n\nexport interface ExecutionContainer {\n\treadResolver: ReadResolver\n\tmutationResolver: MutationResolver\n\tvalidationResolver: ValidationResolver\n\trefreshViewResolver: RefreshViewResolver\n\ttriggeredActionsCollector: TriggeredActionsCollector | undefined\n}\n\nexport type ExecutionContainerBuilder = ReturnType<ExecutionContainerFactory['createBuilderInternal']>\nexport type ExecutionContainerHook = (builder: ExecutionContainerBuilder) => ExecutionContainerBuilder\n\nexport class ExecutionContainerFactory {\n\tpublic readonly hooks: ExecutionContainerHook[] = []\n\n\tconstructor(\n\t\tprivate readonly providers: Providers,\n\t\tprivate readonly whereOptimizerOptions?: WhereOptimizerOptions,\n\t) {\n\t}\n\n\tcreateBuilder(args: ExecutionContainerArgs): ExecutionContainerBuilder {\n\t\tconst builder = this.createBuilderInternal(args)\n\t\treturn this.hooks.reduce((acc, cb) => cb(acc), builder)\n\t}\n\n\tcreateBuilderInternal(\n\t\t{\n\t\t\tpermissions,\n\t\t\tallPermissions,\n\t\t\tidentityVariables,\n\t\t\tidentityId,\n\t\t\tdb,\n\t\t\tschema,\n\t\t\tschemaMeta,\n\t\t\tsystemSchema,\n\t\t\tstage,\n\t\t\tproject,\n\t\t\tschemaDatabaseMetadata,\n\t\t\tuserInfo,\n\t\t}: ExecutionContainerArgs,\n\t) {\n\t\treturn new Builder({})\n\t\t\t.addService('systemSchema', () => systemSchema)\n\t\t\t.addService('db', () => db)\n\t\t\t.addService('project', () => project)\n\t\t\t.addService('stage', () => stage)\n\t\t\t.addService('triggeredActionsCollector', (): TriggeredActionsCollector | undefined =>\n\t\t\t\tschema.settings.actions?.returnTriggeredActions === true\n\t\t\t\t\t? new InMemoryTriggeredActionsCollector()\n\t\t\t\t\t: undefined)\n\t\t\t.addService('schema', () => schema)\n\t\t\t.addService('schemaMeta', () => schemaMeta)\n\t\t\t.addService('schemaDatabaseMetadata', () => schemaDatabaseMetadata)\n\t\t\t.addService('userInfo', () => userInfo)\n\t\t\t.addService('providers', () => this.providers)\n\t\t\t.addService('variableInjector', ({ schema }) => new VariableInjector(schema.model, identityVariables))\n\t\t\t.addService(\n\t\t\t\t'predicateFactory',\n\t\t\t\t({ variableInjector, schema }) => new PredicateFactory(permissions, schema.model, variableInjector, allPermissions),\n\t\t\t)\n\t\t\t.addService('predicatesInjector', ({ predicateFactory, schema }) => new PredicatesInjector(schema.model, predicateFactory))\n\t\t\t.addService('joinBuilder', ({ schema }) => new JoinBuilder(schema.model))\n\t\t\t.addService('conditionBuilder', () => new ConditionBuilder())\n\t\t\t.addService('pathFactory', () => new PathFactory())\n\t\t\t.addService('whereOptimized', ({ schema }) => new WhereOptimizer(schema.model, new ConditionOptimizer(), this.whereOptimizerOptions))\n\t\t\t.addService('whereBuilder', ({ joinBuilder, conditionBuilder, pathFactory, whereOptimized, schema }) =>\n\t\t\t\tnew WhereBuilder(\n\t\t\t\t\tschema.model,\n\t\t\t\t\tjoinBuilder,\n\t\t\t\t\tconditionBuilder,\n\t\t\t\t\tpathFactory,\n\t\t\t\t\twhereOptimized,\n\t\t\t\t\t(schema.settings.content?.useExistsInHasManyFilter ?? schema.settings.useExistsInHasManyFilter) === true,\n\t\t\t\t))\n\t\t\t.addService('orderByBuilder', ({ joinBuilder, schema }) => new OrderByBuilder(schema.model, joinBuilder))\n\t\t\t.addService(\n\t\t\t\t'relationFetcher',\n\t\t\t\t({ whereBuilder, orderByBuilder, predicatesInjector, pathFactory }) =>\n\t\t\t\t\tnew RelationFetcher(whereBuilder, orderByBuilder, predicatesInjector, pathFactory),\n\t\t\t)\n\t\t\t.addService(\n\t\t\t\t'fieldsVisitorFactory',\n\t\t\t\t({ relationFetcher, predicateFactory, schema, providers }) =>\n\t\t\t\t\tnew FieldsVisitorFactory(schema.model, relationFetcher, predicateFactory, schema.settings.content ?? {}, providers),\n\t\t\t)\n\t\t\t.addService('metaHandler', ({ whereBuilder, predicateFactory }) => new MetaHandler(whereBuilder, predicateFactory))\n\t\t\t.addService('uniqueWhereExpander', ({ schema }) => new UniqueWhereExpander(schema.model))\n\t\t\t.addService(\n\t\t\t\t'hasManyToHasOneReducer',\n\t\t\t\t({ uniqueWhereExpander, schema }) => new HasManyToHasOneReducerExecutionHandler(schema.model, uniqueWhereExpander),\n\t\t\t)\n\t\t\t.addService(\n\t\t\t\t'paginatedHasManyExecutionHandler',\n\t\t\t\t({ relationFetcher, schema }) => new PaginatedHasManyExecutionHandler(schema.model, relationFetcher),\n\t\t\t)\n\t\t\t.addService('selectHandlers', ({ hasManyToHasOneReducer, paginatedHasManyExecutionHandler }) => ({\n\t\t\t\t[HasManyToHasOneReducer.extensionName]: hasManyToHasOneReducer,\n\t\t\t\t[PaginatedHasManyFieldProvider.extensionName]: paginatedHasManyExecutionHandler,\n\t\t\t}))\n\t\t\t.addService(\n\t\t\t\t'selectBuilderFactory',\n\t\t\t\t({ whereBuilder, orderByBuilder, fieldsVisitorFactory, metaHandler, selectHandlers, pathFactory, predicateFactory, schema }) =>\n\t\t\t\t\tnew (class implements SelectBuilderFactory {\n\t\t\t\t\t\tcreate(qb: DbSelectBuilder, hydrator: SelectHydrator, relationPath: Model.AnyRelationContext[]): SelectBuilder {\n\t\t\t\t\t\t\treturn new SelectBuilder(\n\t\t\t\t\t\t\t\tschema.model,\n\t\t\t\t\t\t\t\twhereBuilder,\n\t\t\t\t\t\t\t\torderByBuilder,\n\t\t\t\t\t\t\t\tmetaHandler,\n\t\t\t\t\t\t\t\tqb,\n\t\t\t\t\t\t\t\thydrator,\n\t\t\t\t\t\t\t\tfieldsVisitorFactory,\n\t\t\t\t\t\t\t\tselectHandlers,\n\t\t\t\t\t\t\t\tpathFactory,\n\t\t\t\t\t\t\t\trelationPath,\n\t\t\t\t\t\t\t\tpredicateFactory,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t})(),\n\t\t\t)\n\t\t\t.addService(\n\t\t\t\t'insertBuilderFactory',\n\t\t\t\t({ whereBuilder, pathFactory, schema, predicateFactory }) => new InsertBuilderFactory(schema.model, whereBuilder, pathFactory, predicateFactory),\n\t\t\t)\n\t\t\t.addService(\n\t\t\t\t'updateBuilderFactory',\n\t\t\t\t({ whereBuilder, pathFactory, schema, predicateFactory }) => new UpdateBuilderFactory(schema.model, whereBuilder, pathFactory, predicateFactory),\n\t\t\t)\n\t\t\t.addService('connectJunctionHandler', () => new JunctionConnectHandler())\n\t\t\t.addService('disconnectJunctionHandler', ({}) => new JunctionDisconnectHandler())\n\t\t\t.addService(\n\t\t\t\t'junctionTableManager',\n\t\t\t\t({ predicateFactory, whereBuilder, connectJunctionHandler, disconnectJunctionHandler, pathFactory, schema }) =>\n\t\t\t\t\tnew JunctionTableManager(schema.model, predicateFactory, whereBuilder, connectJunctionHandler, disconnectJunctionHandler, pathFactory),\n\t\t\t)\n\t\t\t.addService(\n\t\t\t\t'deleteExecutor',\n\t\t\t\t({ predicateFactory, updateBuilderFactory, whereBuilder, pathFactory, schema }) =>\n\t\t\t\t\tnew DeleteExecutor(schema.model, predicateFactory, whereBuilder, updateBuilderFactory, pathFactory),\n\t\t\t)\n\t\t\t.addService('updater', ({ updateBuilderFactory, schema }) => new Updater(schema.model, updateBuilderFactory))\n\t\t\t.addService(\n\t\t\t\t'inserter',\n\t\t\t\t({ insertBuilderFactory, providers, schema, schemaDatabaseMetadata }) =>\n\t\t\t\t\tnew Inserter(schema.model, schemaDatabaseMetadata, insertBuilderFactory, providers, { uuidVersion: schema.settings.content?.uuidVersion }),\n\t\t\t)\n\t\t\t.addService(\n\t\t\t\t'mapperFactory',\n\t\t\t\t({\n\t\t\t\t\tpredicatesInjector,\n\t\t\t\t\tselectBuilderFactory,\n\t\t\t\t\tuniqueWhereExpander,\n\t\t\t\t\twhereBuilder,\n\t\t\t\t\tjunctionTableManager,\n\t\t\t\t\tdeleteExecutor,\n\t\t\t\t\tupdater,\n\t\t\t\t\tinserter,\n\t\t\t\t\tpathFactory,\n\t\t\t\t\tproviders,\n\t\t\t\t\tschema,\n\t\t\t\t\tschemaDatabaseMetadata,\n\t\t\t\t}) => {\n\t\t\t\t\treturn new MapperFactory(\n\t\t\t\t\t\tdb,\n\t\t\t\t\t\tidentityId,\n\t\t\t\t\t\tschema.model,\n\t\t\t\t\t\tschemaDatabaseMetadata,\n\t\t\t\t\t\tpredicatesInjector,\n\t\t\t\t\t\tselectBuilderFactory,\n\t\t\t\t\t\tuniqueWhereExpander,\n\t\t\t\t\t\twhereBuilder,\n\t\t\t\t\t\tjunctionTableManager,\n\t\t\t\t\t\tdeleteExecutor,\n\t\t\t\t\t\tupdater,\n\t\t\t\t\t\tinserter,\n\t\t\t\t\t\tpathFactory,\n\t\t\t\t\t\tproviders,\n\t\t\t\t\t)\n\t\t\t\t},\n\t\t\t)\n\t\t\t.addService('queryAstFactory', () => new GraphQlQueryAstFactory())\n\t\t\t.addService('readResolver', ({ mapperFactory, queryAstFactory }) => new ReadResolver(mapperFactory, queryAstFactory))\n\t\t\t.addService('validationDependencyCollector', () => new DependencyCollector())\n\t\t\t.addService('validationQueryAstFactory', ({ schema }) => new QueryAstFactory(schema.model))\n\t\t\t.addService('dataSelector', ({ validationQueryAstFactory, schema }) => new ValidationDataSelector(schema.model, validationQueryAstFactory))\n\t\t\t.addService('columnValueResolver', ({ providers }) => new ColumnValueResolver(providers))\n\t\t\t.addService('entityRulesResolver', ({ schema }) => new EntityRulesResolver(schema.validation, schema.model))\n\t\t\t.addService(\n\t\t\t\t'inputPreValidator',\n\t\t\t\t({ entityRulesResolver, columnValueResolver, dataSelector, schema }) =>\n\t\t\t\t\tnew InputPreValidator(schema.model, entityRulesResolver, columnValueResolver, dataSelector),\n\t\t\t)\n\t\t\t.addService(\n\t\t\t\t'mutationResolver',\n\t\t\t\t({ mapperFactory, inputPreValidator, queryAstFactory, schema, schemaDatabaseMetadata }) =>\n\t\t\t\t\tnew MutationResolver(schema.model, mapperFactory, inputPreValidator, queryAstFactory, schemaDatabaseMetadata),\n\t\t\t)\n\t\t\t.addService('validationResolver', ({ inputPreValidator, mapperFactory }) => new ValidationResolver(mapperFactory, inputPreValidator))\n\t\t\t.addService('refreshViewResolver', ({ schema, mapperFactory }) => new RefreshViewResolver(schema, mapperFactory))\n\t}\n\n\tpublic create(args: ExecutionContainerArgs): ExecutionContainer {\n\t\treturn this.createBuilder(args).build().pick(\n\t\t\t'validationResolver',\n\t\t\t'readResolver',\n\t\t\t'mutationResolver',\n\t\t\t'refreshViewResolver',\n\t\t\t'triggeredActionsCollector',\n\t\t)\n\t}\n}\n"],"names":["schema","schemaDatabaseMetadata"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0DO,MAAM,kCAAuE;AAAA,EAA7E,cAAA;AACN,kBAAA,MAAQ,UAAiC,EAAC;AAAA,EAAA;AAAA,EAE1C,IAAI,QAA+C;AAClD,eAAW,SAAS,QAAQ;AAC3B,WAAK,OAAO,KAAK,KAAK;AAAA,IACvB;AAAA,EACD;AAAA,EAEA,YAA6C;AAC5C,WAAO,KAAK;AAAA,EACb;AACD;AA4BO,MAAM,0BAA0B;AAAA,EAGtC,YACkB,WACA,uBAChB;AAFgB,SAAA,YAAA;AACA,SAAA,wBAAA;AAJlB,kBAAA,MAAgB,SAAkC,EAAC;AAAA,EAMnD;AAAA,EAEA,cAAc,MAAyD;AACtE,UAAM,UAAU,KAAK,sBAAsB,IAAI;AAC/C,WAAO,KAAK,MAAM,OAAO,CAAC,KAAK,OAAO,GAAG,GAAG,GAAG,OAAO;AAAA,EACvD;AAAA,EAEA,sBACC;AAAA,IACC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,I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CAAC,EAAE,QAAAD,SAAQ,cAAA,MAAoB,IAAI,oBAAoBA,SAAQ,aAAa,CAAC;AAAA,EAClH;AAAA,EAEO,OAAO,MAAkD;AAC/D,WAAO,KAAK,cAAc,IAAI,EAAE,QAAQ;AAAA,MACvC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA;AAAA,EAEF;AACD;"}
1
+ {"version":3,"file":"ExecutionContainer.js","sources":["../../../../packages/engine-content-api/src/ExecutionContainer.ts"],"sourcesContent":["import { PredicateFactory, PredicatesInjector, VariableInjector } from './acl/index.js'\nimport {\n\tConditionBuilder,\n\tFieldsVisitorFactory,\n\tJoinBuilder,\n\tMetaHandler,\n\tOrderByBuilder,\n\tRelationFetcher,\n\tWhereBuilder,\n} from './mapper/select/index.js'\nimport { UniqueWhereExpander } from './inputProcessing/index.js'\nimport { HasManyToHasOneReducer, HasManyToHasOneReducerExecutionHandler } from './extensions/index.js'\nimport {\n\tDeleteExecutor,\n\tInsertBuilderFactory,\n\tInserter,\n\tJunctionConnectHandler,\n\tJunctionDisconnectHandler,\n\tJunctionTableManager,\n\tMapperFactory,\n\tPathFactory,\n\tSelectBuilder,\n\tSelectBuilderFactory,\n\tSelectHydrator,\n\tUpdateBuilderFactory,\n\tUpdater,\n} from './mapper/index.js'\nimport { Builder } from '@contember/dic'\nimport { Acl, Model, Schema } from '@contember/schema'\nimport { Client, DatabaseMetadata, RequestMemoryBudget, SelectBuilder as DbSelectBuilder } from '@contember/database'\nimport { ParsedMembership, Providers } from '@contember/schema-utils'\nimport { PaginatedHasManyExecutionHandler } from './extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.js'\nimport { PaginatedHasManyFieldProvider } from './extensions/paginatedHasMany/PaginatedHasManyFieldProvider.js'\nimport { WhereOptimizer, WhereOptimizerOptions } from './mapper/select/optimizer/WhereOptimizer.js'\nimport { ConditionOptimizer } from './mapper/select/optimizer/ConditionOptimizer.js'\nimport { GraphQlQueryAstFactory, MutationResolver, ReadResolver, ValidationResolver } from './resolvers/index.js'\nimport {\n\tColumnValueResolver,\n\tDependencyCollector,\n\tEntityRulesResolver,\n\tInputPreValidator,\n\tQueryAstFactory,\n\tValidationDataSelector,\n} from './input-validation/index.js'\nimport { RefreshViewResolver } from './resolvers/RefreshViewResolver.js'\n\nexport interface TriggeredActionEvent {\n\tid: string\n\ttrigger: string\n\ttarget: string\n\ttransactionId: string\n}\n\nexport interface TriggeredActionsCollector {\n\tadd(events: readonly TriggeredActionEvent[]): void\n\tgetEvents(): readonly TriggeredActionEvent[]\n}\n\nexport class InMemoryTriggeredActionsCollector implements TriggeredActionsCollector {\n\tprivate events: TriggeredActionEvent[] = []\n\n\tadd(events: readonly TriggeredActionEvent[]): void {\n\t\tfor (const event of events) {\n\t\t\tthis.events.push(event)\n\t\t}\n\t}\n\n\tgetEvents(): readonly TriggeredActionEvent[] {\n\t\treturn this.events\n\t}\n}\n\nexport type ExecutionContainerArgs = {\n\tschema: Schema\n\tschemaMeta: { id?: number }\n\tschemaDatabaseMetadata: DatabaseMetadata\n\tdb: Client\n\tmemoryBudget?: RequestMemoryBudget\n\tidentityId: string\n\tidentityVariables: Acl.VariablesMap\n\tpermissions: Acl.Permissions\n\tallPermissions?: Acl.Permissions\n\tsystemSchema: string\n\tproject: { slug: string }\n\tstage: { id: string; slug: string }\n\tuserInfo: { ipAddress: string | null; userAgent: string | null }\n}\n\nexport interface ExecutionContainer {\n\treadResolver: ReadResolver\n\tmutationResolver: MutationResolver\n\tvalidationResolver: ValidationResolver\n\trefreshViewResolver: RefreshViewResolver\n\ttriggeredActionsCollector: TriggeredActionsCollector | undefined\n}\n\nexport type ExecutionContainerBuilder = ReturnType<ExecutionContainerFactory['createBuilderInternal']>\nexport type ExecutionContainerHook = (builder: ExecutionContainerBuilder) => ExecutionContainerBuilder\n\nexport class ExecutionContainerFactory {\n\tpublic readonly hooks: ExecutionContainerHook[] = []\n\n\tconstructor(\n\t\tprivate readonly providers: Providers,\n\t\tprivate readonly whereOptimizerOptions?: WhereOptimizerOptions,\n\t) {\n\t}\n\n\tcreateBuilder(args: ExecutionContainerArgs): ExecutionContainerBuilder {\n\t\tconst builder = this.createBuilderInternal(args)\n\t\treturn this.hooks.reduce((acc, cb) => cb(acc), builder)\n\t}\n\n\tcreateBuilderInternal(\n\t\t{\n\t\t\tpermissions,\n\t\t\tallPermissions,\n\t\t\tidentityVariables,\n\t\t\tidentityId,\n\t\t\tdb,\n\t\t\tmemoryBudget,\n\t\t\tschema,\n\t\t\tschemaMeta,\n\t\t\tsystemSchema,\n\t\t\tstage,\n\t\t\tproject,\n\t\t\tschemaDatabaseMetadata,\n\t\t\tuserInfo,\n\t\t}: ExecutionContainerArgs,\n\t) {\n\t\treturn new Builder({})\n\t\t\t.addService('systemSchema', () => systemSchema)\n\t\t\t// Every query of the request is refused once the budget is exhausted; only selections charge it (Mapper.selectionDb).\n\t\t\t.addService('db', () => memoryBudget ? db.withMemoryBudget(memoryBudget, { chargeRows: false }) : db)\n\t\t\t.addService('project', () => project)\n\t\t\t.addService('stage', () => stage)\n\t\t\t.addService('triggeredActionsCollector', (): TriggeredActionsCollector | undefined =>\n\t\t\t\tschema.settings.actions?.returnTriggeredActions === true\n\t\t\t\t\t? new InMemoryTriggeredActionsCollector()\n\t\t\t\t\t: undefined)\n\t\t\t.addService('schema', () => schema)\n\t\t\t.addService('schemaMeta', () => schemaMeta)\n\t\t\t.addService('schemaDatabaseMetadata', () => schemaDatabaseMetadata)\n\t\t\t.addService('userInfo', () => userInfo)\n\t\t\t.addService('providers', () => this.providers)\n\t\t\t.addService('variableInjector', ({ schema }) => new VariableInjector(schema.model, identityVariables))\n\t\t\t.addService(\n\t\t\t\t'predicateFactory',\n\t\t\t\t({ variableInjector, schema }) => new PredicateFactory(permissions, schema.model, variableInjector, allPermissions),\n\t\t\t)\n\t\t\t.addService('predicatesInjector', ({ predicateFactory, schema }) => new PredicatesInjector(schema.model, predicateFactory))\n\t\t\t.addService('joinBuilder', ({ schema }) => new JoinBuilder(schema.model))\n\t\t\t.addService('conditionBuilder', () => new ConditionBuilder())\n\t\t\t.addService('pathFactory', () => new PathFactory())\n\t\t\t.addService('whereOptimized', ({ schema }) => new WhereOptimizer(schema.model, new ConditionOptimizer(), this.whereOptimizerOptions))\n\t\t\t.addService('whereBuilder', ({ joinBuilder, conditionBuilder, pathFactory, whereOptimized, schema }) =>\n\t\t\t\tnew WhereBuilder(\n\t\t\t\t\tschema.model,\n\t\t\t\t\tjoinBuilder,\n\t\t\t\t\tconditionBuilder,\n\t\t\t\t\tpathFactory,\n\t\t\t\t\twhereOptimized,\n\t\t\t\t\t(schema.settings.content?.useExistsInHasManyFilter ?? schema.settings.useExistsInHasManyFilter) === true,\n\t\t\t\t))\n\t\t\t.addService('orderByBuilder', ({ joinBuilder, schema }) => new OrderByBuilder(schema.model, joinBuilder))\n\t\t\t.addService(\n\t\t\t\t'relationFetcher',\n\t\t\t\t({ whereBuilder, orderByBuilder, predicatesInjector, pathFactory }) =>\n\t\t\t\t\tnew RelationFetcher(whereBuilder, orderByBuilder, predicatesInjector, pathFactory),\n\t\t\t)\n\t\t\t.addService(\n\t\t\t\t'fieldsVisitorFactory',\n\t\t\t\t({ relationFetcher, predicateFactory, schema, providers }) =>\n\t\t\t\t\tnew FieldsVisitorFactory(schema.model, relationFetcher, predicateFactory, schema.settings.content ?? {}, providers),\n\t\t\t)\n\t\t\t.addService('metaHandler', ({ whereBuilder, predicateFactory }) => new MetaHandler(whereBuilder, predicateFactory))\n\t\t\t.addService('uniqueWhereExpander', ({ schema }) => new UniqueWhereExpander(schema.model))\n\t\t\t.addService(\n\t\t\t\t'hasManyToHasOneReducer',\n\t\t\t\t({ uniqueWhereExpander, schema }) => new HasManyToHasOneReducerExecutionHandler(schema.model, uniqueWhereExpander),\n\t\t\t)\n\t\t\t.addService(\n\t\t\t\t'paginatedHasManyExecutionHandler',\n\t\t\t\t({ relationFetcher, schema }) => new PaginatedHasManyExecutionHandler(schema.model, relationFetcher),\n\t\t\t)\n\t\t\t.addService('selectHandlers', ({ hasManyToHasOneReducer, paginatedHasManyExecutionHandler }) => ({\n\t\t\t\t[HasManyToHasOneReducer.extensionName]: hasManyToHasOneReducer,\n\t\t\t\t[PaginatedHasManyFieldProvider.extensionName]: paginatedHasManyExecutionHandler,\n\t\t\t}))\n\t\t\t.addService(\n\t\t\t\t'selectBuilderFactory',\n\t\t\t\t({ whereBuilder, orderByBuilder, fieldsVisitorFactory, metaHandler, selectHandlers, pathFactory, predicateFactory, schema }) =>\n\t\t\t\t\tnew (class implements SelectBuilderFactory {\n\t\t\t\t\t\tcreate(qb: DbSelectBuilder, hydrator: SelectHydrator, relationPath: Model.AnyRelationContext[]): SelectBuilder {\n\t\t\t\t\t\t\treturn new SelectBuilder(\n\t\t\t\t\t\t\t\tschema.model,\n\t\t\t\t\t\t\t\twhereBuilder,\n\t\t\t\t\t\t\t\torderByBuilder,\n\t\t\t\t\t\t\t\tmetaHandler,\n\t\t\t\t\t\t\t\tqb,\n\t\t\t\t\t\t\t\thydrator,\n\t\t\t\t\t\t\t\tfieldsVisitorFactory,\n\t\t\t\t\t\t\t\tselectHandlers,\n\t\t\t\t\t\t\t\tpathFactory,\n\t\t\t\t\t\t\t\trelationPath,\n\t\t\t\t\t\t\t\tpredicateFactory,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t})(),\n\t\t\t)\n\t\t\t.addService(\n\t\t\t\t'insertBuilderFactory',\n\t\t\t\t({ whereBuilder, pathFactory, schema, predicateFactory }) => new InsertBuilderFactory(schema.model, whereBuilder, pathFactory, predicateFactory),\n\t\t\t)\n\t\t\t.addService(\n\t\t\t\t'updateBuilderFactory',\n\t\t\t\t({ whereBuilder, pathFactory, schema, predicateFactory }) => new UpdateBuilderFactory(schema.model, whereBuilder, pathFactory, predicateFactory),\n\t\t\t)\n\t\t\t.addService('connectJunctionHandler', () => new JunctionConnectHandler())\n\t\t\t.addService('disconnectJunctionHandler', ({}) => new JunctionDisconnectHandler())\n\t\t\t.addService(\n\t\t\t\t'junctionTableManager',\n\t\t\t\t({ predicateFactory, whereBuilder, connectJunctionHandler, disconnectJunctionHandler, pathFactory, schema }) =>\n\t\t\t\t\tnew JunctionTableManager(schema.model, predicateFactory, whereBuilder, connectJunctionHandler, disconnectJunctionHandler, pathFactory),\n\t\t\t)\n\t\t\t.addService(\n\t\t\t\t'deleteExecutor',\n\t\t\t\t({ predicateFactory, updateBuilderFactory, whereBuilder, pathFactory, schema }) =>\n\t\t\t\t\tnew DeleteExecutor(schema.model, predicateFactory, whereBuilder, updateBuilderFactory, pathFactory),\n\t\t\t)\n\t\t\t.addService('updater', ({ updateBuilderFactory, schema }) => new Updater(schema.model, updateBuilderFactory))\n\t\t\t.addService(\n\t\t\t\t'inserter',\n\t\t\t\t({ insertBuilderFactory, providers, schema, schemaDatabaseMetadata }) =>\n\t\t\t\t\tnew Inserter(schema.model, schemaDatabaseMetadata, insertBuilderFactory, providers, { uuidVersion: schema.settings.content?.uuidVersion }),\n\t\t\t)\n\t\t\t.addService(\n\t\t\t\t'mapperFactory',\n\t\t\t\t({\n\t\t\t\t\tpredicatesInjector,\n\t\t\t\t\tselectBuilderFactory,\n\t\t\t\t\tuniqueWhereExpander,\n\t\t\t\t\twhereBuilder,\n\t\t\t\t\tjunctionTableManager,\n\t\t\t\t\tdeleteExecutor,\n\t\t\t\t\tupdater,\n\t\t\t\t\tinserter,\n\t\t\t\t\tpathFactory,\n\t\t\t\t\tproviders,\n\t\t\t\t\tschema,\n\t\t\t\t\tschemaDatabaseMetadata,\n\t\t\t\t\tdb,\n\t\t\t\t}) => {\n\t\t\t\t\treturn new MapperFactory(\n\t\t\t\t\t\tdb,\n\t\t\t\t\t\tidentityId,\n\t\t\t\t\t\tschema.model,\n\t\t\t\t\t\tschemaDatabaseMetadata,\n\t\t\t\t\t\tpredicatesInjector,\n\t\t\t\t\t\tselectBuilderFactory,\n\t\t\t\t\t\tuniqueWhereExpander,\n\t\t\t\t\t\twhereBuilder,\n\t\t\t\t\t\tjunctionTableManager,\n\t\t\t\t\t\tdeleteExecutor,\n\t\t\t\t\t\tupdater,\n\t\t\t\t\t\tinserter,\n\t\t\t\t\t\tpathFactory,\n\t\t\t\t\t\tproviders,\n\t\t\t\t\t\tmemoryBudget,\n\t\t\t\t\t)\n\t\t\t\t},\n\t\t\t)\n\t\t\t.addService('queryAstFactory', () => new GraphQlQueryAstFactory())\n\t\t\t.addService('readResolver', ({ mapperFactory, queryAstFactory }) => new ReadResolver(mapperFactory, queryAstFactory))\n\t\t\t.addService('validationDependencyCollector', () => new DependencyCollector())\n\t\t\t.addService('validationQueryAstFactory', ({ schema }) => new QueryAstFactory(schema.model))\n\t\t\t.addService('dataSelector', ({ validationQueryAstFactory, schema }) => new ValidationDataSelector(schema.model, validationQueryAstFactory))\n\t\t\t.addService('columnValueResolver', ({ providers }) => new ColumnValueResolver(providers))\n\t\t\t.addService('entityRulesResolver', ({ schema }) => new EntityRulesResolver(schema.validation, schema.model))\n\t\t\t.addService(\n\t\t\t\t'inputPreValidator',\n\t\t\t\t({ entityRulesResolver, columnValueResolver, dataSelector, schema }) =>\n\t\t\t\t\tnew InputPreValidator(schema.model, entityRulesResolver, columnValueResolver, dataSelector),\n\t\t\t)\n\t\t\t.addService(\n\t\t\t\t'mutationResolver',\n\t\t\t\t({ mapperFactory, inputPreValidator, queryAstFactory, schema, schemaDatabaseMetadata }) =>\n\t\t\t\t\tnew MutationResolver(schema.model, mapperFactory, inputPreValidator, queryAstFactory, schemaDatabaseMetadata),\n\t\t\t)\n\t\t\t.addService('validationResolver', ({ inputPreValidator, mapperFactory }) => new ValidationResolver(mapperFactory, inputPreValidator))\n\t\t\t.addService('refreshViewResolver', ({ schema, mapperFactory }) => new RefreshViewResolver(schema, mapperFactory))\n\t}\n\n\tpublic create(args: ExecutionContainerArgs): ExecutionContainer {\n\t\treturn this.createBuilder(args).build().pick(\n\t\t\t'validationResolver',\n\t\t\t'readResolver',\n\t\t\t'mutationResolver',\n\t\t\t'refreshViewResolver',\n\t\t\t'triggeredActionsCollector',\n\t\t)\n\t}\n}\n"],"names":["schema","schemaDatabaseMetadata","db"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0DO,MAAM,kCAAuE;AAAA,EAA7E,cAAA;AACN,kBAAA,MAAQ,UAAiC,EAAC;AAAA,EAAA;AAAA,EAE1C,IAAI,QAA+C;AAClD,eAAW,SAAS,QAAQ;AAC3B,WAAK,OAAO,KAAK,KAAK;AAAA,IACvB;AAAA,EACD;AAAA,EAEA,YAA6C;AAC5C,WAAO,KAAK;AAAA,EACb;AACD;AA6BO,MAAM,0BAA0B;AAAA,EAGtC,YACkB,WACA,uBAChB;AAFgB,SAAA,YAAA;AACA,SAAA,wBAAA;AAJlB,kBAAA,MAAgB,SAAkC,EAAC;AAAA,EAMnD;AAAA,EAEA,cAAc,MAAyD;AACtE,UAAM,UAAU,KAAK,sBAAsB,IAAI;AAC/C,WAAO,KAAK,MAAM,OAAO,CAAC,KAAK,OAAO,GAAG,GAAG,GAAG,OAAO;AAAA,EACvD;AAAA,EAEA,sBACC;AAAA,IACC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,GAEA;AACD,WAAO,IAAI,QAAQ,EAAE,EACnB,WAAW,gBAAgB,MAAM,YAAY,EAE7C,WAAW,MAAM,MAAM,eAAe,GAAG,iBAAiB,cAAc,EAAE,YAAY,MAAA,CAAO,IAAI,EAAE,EACnG,WAAW,WAAW,MAAM,OAAO,EACnC,WAAW,SAAS,MAAM,KAAK,EAC/B,WAAW,6BAA6B,MACxC,OAAO,SAAS,SAAS,2BAA2B,OACjD,IAAI,kCAAA,IACJ,MAAS,EACZ,WAAW,UAAU,MAAM,MAAM,EACjC,WAAW,cAAc,MAAM,U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
  predicatesWhere = { [entity.primary]: { always: true } };
32
32
  } else {
33
- const rawPredicate = this.predicateFactory.create(entity, schema.Acl.Operation.read, fieldNames, relationContext, isQueryRoot);
34
- predicatesWhere = this.injectPredicatesToPredicate(
35
- rawPredicate,
36
- entity,
37
- isBackReferenceContext ?? false,
38
- ancestorPath ?? [],
39
- isQueryRoot
40
- );
33
+ predicatesWhere = this.predicateFactory.create(entity, schema.Acl.Operation.read, fieldNames, relationContext, isQueryRoot);
41
34
  }
42
35
  const and = [where, predicatesWhere].filter((it) => Object.keys(it).length > 0);
43
36
  if (and.length === 0) {
@@ -48,66 +41,6 @@ class PredicatesInjector {
48
41
  }
49
42
  return { and };
50
43
  }
51
- /**
52
- * Processes a predicate and injects nested entity predicates for any relation traversals.
53
- * This ensures that when a predicate like { department: { company: { name: 'Acme' } } }
54
- * is used, the predicates of Department and Company are also applied.
55
- */
56
- injectPredicatesToPredicate(where, entity, isBackReferenceContext, ancestorPath, isQueryRoot) {
57
- const resultWhere = {};
58
- if (where.and) {
59
- resultWhere.and = where.and.filter((it) => !!it).map((it) => this.injectPredicatesToPredicate(it, entity, isBackReferenceContext, ancestorPath, isQueryRoot));
60
- }
61
- if (where.or) {
62
- resultWhere.or = where.or.filter((it) => !!it).map((it) => this.injectPredicatesToPredicate(it, entity, isBackReferenceContext, ancestorPath, isQueryRoot));
63
- }
64
- if (where.not) {
65
- resultWhere.not = this.injectPredicatesToPredicate(where.not, entity, isBackReferenceContext, ancestorPath, isQueryRoot);
66
- }
67
- const fields = Object.keys(where).filter((it) => !["and", "or", "not"].includes(it));
68
- for (const field of fields) {
69
- resultWhere[field] = schemaUtils.acceptFieldVisitor(this.schema, entity, field, {
70
- visitColumn: () => where[field],
71
- visitRelation: (context) => {
72
- const relationWhere = where[field];
73
- if (relationWhere === null) {
74
- return null;
75
- }
76
- const isBackReference = this.findBackReferencedAncestor(
77
- ancestorPath,
78
- context.relation.name,
79
- context.entity.name
80
- ) !== void 0;
81
- const nestedIsBackReferenceContext = isBackReference || isBackReferenceContext;
82
- const nestedAncestorPath = [...ancestorPath, context];
83
- const processedNestedWhere = this.injectPredicatesToPredicate(
84
- relationWhere,
85
- context.targetEntity,
86
- nestedIsBackReferenceContext,
87
- nestedAncestorPath,
88
- isQueryRoot
89
- );
90
- const shouldSimplifyNested = nestedIsBackReferenceContext && this.findBackReferencedAncestor(nestedAncestorPath, context.relation.name, context.entity.name) !== void 0;
91
- const targetPredicate = shouldSimplifyNested ? { [context.targetEntity.primary]: { always: true } } : this.predicateFactory.create(context.targetEntity, schema.Acl.Operation.read, void 0, context, isQueryRoot);
92
- const primaryKey = context.targetEntity.primary;
93
- const nestedIsAlwaysTrue = Object.keys(processedNestedWhere).length === 1 && processedNestedWhere[primaryKey] !== void 0 && processedNestedWhere[primaryKey]?.always === true;
94
- const targetIsAlwaysTrue = Object.keys(targetPredicate).length === 1 && targetPredicate[primaryKey] !== void 0 && targetPredicate[primaryKey]?.always === true;
95
- if (nestedIsAlwaysTrue && targetIsAlwaysTrue) {
96
- return processedNestedWhere;
97
- }
98
- const parts = [processedNestedWhere, targetPredicate].filter((it) => Object.keys(it).length > 0);
99
- if (parts.length === 0) {
100
- return {};
101
- }
102
- if (parts.length === 1) {
103
- return parts[0];
104
- }
105
- return { and: parts };
106
- }
107
- });
108
- }
109
- return resultWhere;
110
- }
111
44
  injectToWhere(where, entity, isRoot, relationContext, isBackReferenceContext, ancestorPath, isQueryRoot) {
112
45
  const resultWhere = {};
113
46
  if (where.and) {
@@ -1 +1 @@
1
- {"version":3,"file":"PredicatesInjector.cjs","sources":["../../../../../packages/engine-content-api/src/acl/PredicatesInjector.ts"],"sourcesContent":["import { Acl, Input, Model, Writable } from '@contember/schema'\nimport { acceptFieldVisitor } from '@contember/schema-utils'\nimport { PredicateFactory } from './PredicateFactory.js'\n\nexport class PredicatesInjector {\n\tconstructor(private readonly schema: Model.Schema, private readonly predicateFactory: PredicateFactory) {}\n\n\tpublic inject(\n\t\tentity: Model.Entity,\n\t\twhere: Input.OptionalWhere,\n\t\trelationContext?: Model.AnyRelationContext,\n\t\tancestorPath?: readonly Model.AnyRelationContext[],\n\t): Input.OptionalWhere {\n\t\tconst isQueryRoot = !relationContext && (!ancestorPath || ancestorPath.length === 0)\n\t\tconst restrictedWhere = this.injectToWhere(where, entity, true, relationContext, false, ancestorPath ?? [], isQueryRoot)\n\t\treturn this.createWhere(entity, undefined, restrictedWhere, relationContext, false, ancestorPath ?? [], isQueryRoot)\n\t}\n\n\t/**\n\t * Finds an ancestor in the path that matches the given relation as a back-reference.\n\t * A match occurs when:\n\t * 1. The relation we're traversing has the same name as the inverse (targetRelation) of a relation in the ancestor path\n\t * 2. AND the entity where our relation is defined matches the targetEntity in the path\n\t * (to prevent false positives when different entities have relations with the same name)\n\t */\n\tprivate findBackReferencedAncestor(\n\t\tancestorPath: readonly Model.AnyRelationContext[],\n\t\trelationName: string,\n\t\trelationSourceEntityName: string,\n\t): Model.AnyRelationContext | undefined {\n\t\treturn ancestorPath.find(ctx =>\n\t\t\tctx.targetRelation?.name === relationName\n\t\t\t&& ctx.targetEntity.name === relationSourceEntityName\n\t\t)\n\t}\n\n\tprivate createWhere(\n\t\tentity: Model.Entity,\n\t\tfieldNames: string[] | undefined,\n\t\twhere: Input.OptionalWhere,\n\t\trelationContext?: Model.AnyRelationContext,\n\t\tisBackReferenceContext?: boolean,\n\t\tancestorPath?: readonly Model.AnyRelationContext[],\n\t\tisQueryRoot?: boolean,\n\t): Input.OptionalWhere {\n\t\t// Simplify predicates when:\n\t\t// 1. We're in a back-reference context (inside a filter that traverses back)\n\t\t// 2. AND the relation we traversed to get here corresponds to a relation in our query path\n\t\t// This ensures we only simplify when the traversed relation actually corresponds\n\t\t// to a relation in our query path (not just any relation to the same entity type)\n\t\tconst shouldSimplify = isBackReferenceContext === true\n\t\t\t&& ancestorPath !== undefined\n\t\t\t&& relationContext !== undefined\n\t\t\t&& this.findBackReferencedAncestor(ancestorPath, relationContext.relation.name, relationContext.entity.name) !== undefined\n\n\t\tlet predicatesWhere: Input.OptionalWhere\n\t\tif (shouldSimplify) {\n\t\t\tpredicatesWhere = { [entity.primary]: { always: true } }\n\t\t} else {\n\t\t\tconst rawPredicate = this.predicateFactory.create(entity, Acl.Operation.read, fieldNames, relationContext, isQueryRoot)\n\t\t\t// Process the predicate to inject nested entity predicates\n\t\t\tpredicatesWhere = this.injectPredicatesToPredicate(\n\t\t\t\trawPredicate,\n\t\t\t\tentity,\n\t\t\t\tisBackReferenceContext ?? false,\n\t\t\t\tancestorPath ?? [],\n\t\t\t\tisQueryRoot,\n\t\t\t)\n\t\t}\n\n\t\tconst and = [where, predicatesWhere].filter(it => Object.keys(it).length > 0)\n\t\tif (and.length === 0) {\n\t\t\treturn {}\n\t\t}\n\t\tif (and.length === 1) {\n\t\t\treturn and[0]\n\t\t}\n\t\treturn { and: and }\n\t}\n\n\t/**\n\t * Processes a predicate and injects nested entity predicates for any relation traversals.\n\t * This ensures that when a predicate like { department: { company: { name: 'Acme' } } }\n\t * is used, the predicates of Department and Company are also applied.\n\t */\n\tprivate injectPredicatesToPredicate(\n\t\twhere: Input.OptionalWhere,\n\t\tentity: Model.Entity,\n\t\tisBackReferenceContext: boolean,\n\t\tancestorPath: readonly Model.AnyRelationContext[],\n\t\tisQueryRoot?: boolean,\n\t): Input.OptionalWhere {\n\t\tconst resultWhere: Writable<Input.OptionalWhere> = {}\n\n\t\tif (where.and) {\n\t\t\tresultWhere.and = where.and\n\t\t\t\t.filter((it): it is Input.Where => !!it)\n\t\t\t\t.map(it => this.injectPredicatesToPredicate(it, entity, isBackReferenceContext, ancestorPath, isQueryRoot))\n\t\t}\n\t\tif (where.or) {\n\t\t\tresultWhere.or = where.or\n\t\t\t\t.filter((it): it is Input.Where => !!it)\n\t\t\t\t.map(it => this.injectPredicatesToPredicate(it, entity, isBackReferenceContext, ancestorPath, isQueryRoot))\n\t\t}\n\t\tif (where.not) {\n\t\t\tresultWhere.not = this.injectPredicatesToPredicate(where.not, entity, isBackReferenceContext, ancestorPath, isQueryRoot)\n\t\t}\n\n\t\tconst fields = Object.keys(where).filter(it => !['and', 'or', 'not'].includes(it))\n\n\t\tfor (const field of fields) {\n\t\t\tresultWhere[field] = acceptFieldVisitor(this.schema, entity, field, {\n\t\t\t\tvisitColumn: () => where[field],\n\t\t\t\tvisitRelation: context => {\n\t\t\t\t\tconst relationWhere = where[field] as Input.OptionalWhere | null\n\t\t\t\t\tif (relationWhere === null) {\n\t\t\t\t\t\treturn null\n\t\t\t\t\t}\n\n\t\t\t\t\t// Check if this relation is a back-reference to somewhere in our ancestor path\n\t\t\t\t\tconst isBackReference = this.findBackReferencedAncestor(\n\t\t\t\t\t\tancestorPath,\n\t\t\t\t\t\tcontext.relation.name,\n\t\t\t\t\t\tcontext.entity.name,\n\t\t\t\t\t) !== undefined\n\t\t\t\t\tconst nestedIsBackReferenceContext = isBackReference || isBackReferenceContext\n\t\t\t\t\tconst nestedAncestorPath: readonly Model.AnyRelationContext[] = [...ancestorPath, context]\n\n\t\t\t\t\t// Recursively process the nested where (always do this to handle deeper nesting)\n\t\t\t\t\tconst processedNestedWhere = this.injectPredicatesToPredicate(\n\t\t\t\t\t\trelationWhere,\n\t\t\t\t\t\tcontext.targetEntity,\n\t\t\t\t\t\tnestedIsBackReferenceContext,\n\t\t\t\t\t\tnestedAncestorPath,\n\t\t\t\t\t\tisQueryRoot,\n\t\t\t\t\t)\n\n\t\t\t\t\t// Check if we should simplify the target entity's predicate\n\t\t\t\t\tconst shouldSimplifyNested = nestedIsBackReferenceContext\n\t\t\t\t\t\t&& this.findBackReferencedAncestor(nestedAncestorPath, context.relation.name, context.entity.name) !== undefined\n\n\t\t\t\t\t// Get target entity's predicate (simplified if back-reference)\n\t\t\t\t\tconst targetPredicate = shouldSimplifyNested\n\t\t\t\t\t\t? { [context.targetEntity.primary]: { always: true } }\n\t\t\t\t\t\t: this.predicateFactory.create(context.targetEntity, Acl.Operation.read, undefined, context, isQueryRoot)\n\n\t\t\t\t\t// Optimization: avoid duplicate { id: always } when both are simplified\n\t\t\t\t\tconst primaryKey = context.targetEntity.primary\n\t\t\t\t\tconst nestedIsAlwaysTrue = Object.keys(processedNestedWhere).length === 1\n\t\t\t\t\t\t&& (processedNestedWhere as Record<string, unknown>)[primaryKey] !== undefined\n\t\t\t\t\t\t&& (processedNestedWhere as Record<string, Record<string, unknown>>)[primaryKey]?.always === true\n\t\t\t\t\tconst targetIsAlwaysTrue = Object.keys(targetPredicate).length === 1\n\t\t\t\t\t\t&& (targetPredicate as Record<string, unknown>)[primaryKey] !== undefined\n\t\t\t\t\t\t&& (targetPredicate as Record<string, Record<string, unknown>>)[primaryKey]?.always === true\n\n\t\t\t\t\tif (nestedIsAlwaysTrue && targetIsAlwaysTrue) {\n\t\t\t\t\t\treturn processedNestedWhere\n\t\t\t\t\t}\n\n\t\t\t\t\t// Combine the processed nested where with target entity's predicate\n\t\t\t\t\tconst parts = [processedNestedWhere, targetPredicate].filter(it => Object.keys(it).length > 0)\n\t\t\t\t\tif (parts.length === 0) {\n\t\t\t\t\t\treturn {}\n\t\t\t\t\t}\n\t\t\t\t\tif (parts.length === 1) {\n\t\t\t\t\t\treturn parts[0]\n\t\t\t\t\t}\n\t\t\t\t\treturn { and: parts }\n\t\t\t\t},\n\t\t\t})\n\t\t}\n\n\t\treturn resultWhere\n\t}\n\n\tprivate injectToWhere(\n\t\twhere: Input.OptionalWhere,\n\t\tentity: Model.Entity,\n\t\tisRoot: boolean,\n\t\trelationContext: Model.AnyRelationContext | undefined,\n\t\tisBackReferenceContext: boolean,\n\t\tancestorPath: readonly Model.AnyRelationContext[],\n\t\tisQueryRoot?: boolean,\n\t): Input.OptionalWhere {\n\t\tconst resultWhere: Writable<Input.OptionalWhere> = {}\n\t\tif (where.and) {\n\t\t\tresultWhere.and = where.and.filter((it): it is Input.Where => !!it).map(it =>\n\t\t\t\tthis.injectToWhere(it, entity, isRoot, relationContext, isBackReferenceContext, ancestorPath, isQueryRoot)\n\t\t\t)\n\t\t}\n\t\tif (where.or) {\n\t\t\tresultWhere.or = where.or.filter((it): it is Input.Where => !!it).map(it =>\n\t\t\t\tthis.injectToWhere(it, entity, isRoot, relationContext, isBackReferenceContext, ancestorPath, isQueryRoot)\n\t\t\t)\n\t\t}\n\t\tif (where.not) {\n\t\t\tresultWhere.not = this.injectToWhere(where.not, entity, isRoot, relationContext, isBackReferenceContext, ancestorPath, isQueryRoot)\n\t\t}\n\n\t\tconst fields = Object.keys(where).filter(it => !['and', 'or', 'not'].includes(it))\n\n\t\tif (fields.length === 0) {\n\t\t\treturn resultWhere\n\t\t}\n\t\tfor (let field of fields) {\n\t\t\tresultWhere[field] = acceptFieldVisitor(this.schema, entity, field, {\n\t\t\t\tvisitColumn: () => where[field],\n\t\t\t\tvisitRelation: context => {\n\t\t\t\t\tconst relationWhere = where[field] as Input.OptionalWhere | null\n\t\t\t\t\tif (relationWhere === null) {\n\t\t\t\t\t\treturn null\n\t\t\t\t\t}\n\t\t\t\t\t// Check if this relation is a back-reference to somewhere in our ancestor path\n\t\t\t\t\tconst isBackReference = this.findBackReferencedAncestor(ancestorPath, context.relation.name, context.entity.name) !== undefined\n\t\t\t\t\t// Once we enter a back-reference context, stay in it for nested relations\n\t\t\t\t\tconst nestedIsBackReferenceContext = isBackReference || isBackReferenceContext\n\t\t\t\t\t// Build extended ancestor path for nested traversal\n\t\t\t\t\tconst nestedAncestorPath: Model.AnyRelationContext[] = [...ancestorPath, context]\n\t\t\t\t\treturn this.injectToWhere(relationWhere, context.targetEntity, false, context, nestedIsBackReferenceContext, nestedAncestorPath, isQueryRoot)\n\t\t\t\t},\n\t\t\t})\n\t\t}\n\t\tconst fieldsForPredicate = !isRoot\n\t\t\t? fields\n\t\t\t: fields.filter(it => this.predicateFactory.shouldApplyCellLevelPredicate(entity, Acl.Operation.read, it, isQueryRoot))\n\n\t\treturn this.createWhere(entity, fieldsForPredicate, resultWhere, relationContext, isBackReferenceContext, ancestorPath, isQueryRoot)\n\t}\n}\n"],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UAAU,MAAM,IAAI,WAAW,CAAC;AAEvH,WAAO,KAAK,YAAY,QAAQ,oBAAoB,aAAa,iBAAiB,wBAAwB,cAAc,WAAW;AAAA,EACpI;AACD;;"}
1
+ {"version":3,"file":"PredicatesInjector.cjs","sources":["../../../../../packages/engine-content-api/src/acl/PredicatesInjector.ts"],"sourcesContent":["import { Acl, Input, Model, Writable } from '@contember/schema'\nimport { acceptFieldVisitor } from '@contember/schema-utils'\nimport { PredicateFactory } from './PredicateFactory.js'\n\nexport class PredicatesInjector {\n\tconstructor(private readonly schema: Model.Schema, private readonly predicateFactory: PredicateFactory) {}\n\n\tpublic inject(\n\t\tentity: Model.Entity,\n\t\twhere: Input.OptionalWhere,\n\t\trelationContext?: Model.AnyRelationContext,\n\t\tancestorPath?: readonly Model.AnyRelationContext[],\n\t): Input.OptionalWhere {\n\t\tconst isQueryRoot = !relationContext && (!ancestorPath || ancestorPath.length === 0)\n\t\tconst restrictedWhere = this.injectToWhere(where, entity, true, relationContext, false, ancestorPath ?? [], isQueryRoot)\n\t\treturn this.createWhere(entity, undefined, restrictedWhere, relationContext, false, ancestorPath ?? [], isQueryRoot)\n\t}\n\n\t/**\n\t * Finds an ancestor in the path that matches the given relation as a back-reference.\n\t * A match occurs when:\n\t * 1. The relation we're traversing has the same name as the inverse (targetRelation) of a relation in the ancestor path\n\t * 2. AND the entity where our relation is defined matches the targetEntity in the path\n\t * (to prevent false positives when different entities have relations with the same name)\n\t */\n\tprivate findBackReferencedAncestor(\n\t\tancestorPath: readonly Model.AnyRelationContext[],\n\t\trelationName: string,\n\t\trelationSourceEntityName: string,\n\t): Model.AnyRelationContext | undefined {\n\t\treturn ancestorPath.find(ctx =>\n\t\t\tctx.targetRelation?.name === relationName\n\t\t\t&& ctx.targetEntity.name === relationSourceEntityName\n\t\t)\n\t}\n\n\tprivate createWhere(\n\t\tentity: Model.Entity,\n\t\tfieldNames: string[] | undefined,\n\t\twhere: Input.OptionalWhere,\n\t\trelationContext?: Model.AnyRelationContext,\n\t\tisBackReferenceContext?: boolean,\n\t\tancestorPath?: readonly Model.AnyRelationContext[],\n\t\tisQueryRoot?: boolean,\n\t): Input.OptionalWhere {\n\t\t// Simplify predicates when:\n\t\t// 1. We're in a back-reference context (inside a filter that traverses back)\n\t\t// 2. AND the relation we traversed to get here corresponds to a relation in our query path\n\t\t// This ensures we only simplify when the traversed relation actually corresponds\n\t\t// to a relation in our query path (not just any relation to the same entity type)\n\t\tconst shouldSimplify = isBackReferenceContext === true\n\t\t\t&& ancestorPath !== undefined\n\t\t\t&& relationContext !== undefined\n\t\t\t&& this.findBackReferencedAncestor(ancestorPath, relationContext.relation.name, relationContext.entity.name) !== undefined\n\n\t\tlet predicatesWhere: Input.OptionalWhere\n\t\tif (shouldSimplify) {\n\t\t\tpredicatesWhere = { [entity.primary]: { always: true } }\n\t\t} else {\n\t\t\tpredicatesWhere = this.predicateFactory.create(entity, Acl.Operation.read, fieldNames, relationContext, isQueryRoot)\n\t\t}\n\n\t\tconst and = [where, predicatesWhere].filter(it => Object.keys(it).length > 0)\n\t\tif (and.length === 0) {\n\t\t\treturn {}\n\t\t}\n\t\tif (and.length === 1) {\n\t\t\treturn and[0]\n\t\t}\n\t\treturn { and: and }\n\t}\n\n\tprivate injectToWhere(\n\t\twhere: Input.OptionalWhere,\n\t\tentity: Model.Entity,\n\t\tisRoot: boolean,\n\t\trelationContext: Model.AnyRelationContext | undefined,\n\t\tisBackReferenceContext: boolean,\n\t\tancestorPath: readonly Model.AnyRelationContext[],\n\t\tisQueryRoot?: boolean,\n\t): Input.OptionalWhere {\n\t\tconst resultWhere: Writable<Input.OptionalWhere> = {}\n\t\tif (where.and) {\n\t\t\tresultWhere.and = where.and.filter((it): it is Input.Where => !!it).map(it =>\n\t\t\t\tthis.injectToWhere(it, entity, isRoot, relationContext, isBackReferenceContext, ancestorPath, isQueryRoot)\n\t\t\t)\n\t\t}\n\t\tif (where.or) {\n\t\t\tresultWhere.or = where.or.filter((it): it is Input.Where => !!it).map(it =>\n\t\t\t\tthis.injectToWhere(it, entity, isRoot, relationContext, isBackReferenceContext, ancestorPath, isQueryRoot)\n\t\t\t)\n\t\t}\n\t\tif (where.not) {\n\t\t\tresultWhere.not = this.injectToWhere(where.not, entity, isRoot, relationContext, isBackReferenceContext, ancestorPath, isQueryRoot)\n\t\t}\n\n\t\tconst fields = Object.keys(where).filter(it => !['and', 'or', 'not'].includes(it))\n\n\t\tif (fields.length === 0) {\n\t\t\treturn resultWhere\n\t\t}\n\t\tfor (let field of fields) {\n\t\t\tresultWhere[field] = acceptFieldVisitor(this.schema, entity, field, {\n\t\t\t\tvisitColumn: () => where[field],\n\t\t\t\tvisitRelation: context => {\n\t\t\t\t\tconst relationWhere = where[field] as Input.OptionalWhere | null\n\t\t\t\t\tif (relationWhere === null) {\n\t\t\t\t\t\treturn null\n\t\t\t\t\t}\n\t\t\t\t\t// Check if this relation is a back-reference to somewhere in our ancestor path\n\t\t\t\t\tconst isBackReference = this.findBackReferencedAncestor(ancestorPath, context.relation.name, context.entity.name) !== undefined\n\t\t\t\t\t// Once we enter a back-reference context, stay in it for nested relations\n\t\t\t\t\tconst nestedIsBackReferenceContext = isBackReference || isBackReferenceContext\n\t\t\t\t\t// Build extended ancestor path for nested traversal\n\t\t\t\t\tconst nestedAncestorPath: Model.AnyRelationContext[] = [...ancestorPath, context]\n\t\t\t\t\treturn this.injectToWhere(relationWhere, context.targetEntity, false, context, nestedIsBackReferenceContext, nestedAncestorPath, isQueryRoot)\n\t\t\t\t},\n\t\t\t})\n\t\t}\n\t\tconst fieldsForPredicate = !isRoot\n\t\t\t? fields\n\t\t\t: fields.filter(it => this.predicateFactory.shouldApplyCellLevelPredicate(entity, Acl.Operation.read, it, isQueryRoot))\n\n\t\treturn this.createWhere(entity, fieldsForPredicate, resultWhere, relationContext, isBackReferenceContext, ancestorPath, isQueryRoot)\n\t}\n}\n"],"names":["schema","Acl","acceptFieldVisitor"],"mappings":";;;;AAIO,MAAM,mBAAmB;AAAA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8B,oBAAoB,WAAW;AAAA,QAC7I;AAAA,MAAA,CACA;AAAA,IACF;AACA,UAAM,qBAAqB,CAAC,SACzB,SACA,OAAO,OAAO,CAAA,OAAM,KAAK,iBAAiB,8BAA8B,QAAQD,OAAAA,IAAI,UAAU,MAAM,IAAI,WAAW,CAAC;AAEvH,WAAO,KAAK,YAAY,QAAQ,oBAAoB,aAAa,iBAAiB,wBAAwB,cAAc,WAAW;AAAA,EACpI;AACD;;"}
@@ -28,14 +28,7 @@ class PredicatesInjector {
28
28
  if (shouldSimplify) {
29
29
  predicatesWhere = { [entity.primary]: { always: true } };
30
30
  } else {
31
- const rawPredicate = this.predicateFactory.create(entity, Acl.Operation.read, fieldNames, relationContext, isQueryRoot);
32
- predicatesWhere = this.injectPredicatesToPredicate(
33
- rawPredicate,
34
- entity,
35
- isBackReferenceContext ?? false,
36
- ancestorPath ?? [],
37
- isQueryRoot
38
- );
31
+ predicatesWhere = this.predicateFactory.create(entity, Acl.Operation.read, fieldNames, relationContext, isQueryRoot);
39
32
  }
40
33
  const and = [where, predicatesWhere].filter((it) => Object.keys(it).length > 0);
41
34
  if (and.length === 0) {
@@ -46,66 +39,6 @@ class PredicatesInjector {
46
39
  }
47
40
  return { and };
48
41
  }
49
- /**
50
- * Processes a predicate and injects nested entity predicates for any relation traversals.
51
- * This ensures that when a predicate like { department: { company: { name: 'Acme' } } }
52
- * is used, the predicates of Department and Company are also applied.
53
- */
54
- injectPredicatesToPredicate(where, entity, isBackReferenceContext, ancestorPath, isQueryRoot) {
55
- const resultWhere = {};
56
- if (where.and) {
57
- resultWhere.and = where.and.filter((it) => !!it).map((it) => this.injectPredicatesToPredicate(it, entity, isBackReferenceContext, ancestorPath, isQueryRoot));
58
- }
59
- if (where.or) {
60
- resultWhere.or = where.or.filter((it) => !!it).map((it) => this.injectPredicatesToPredicate(it, entity, isBackReferenceContext, ancestorPath, isQueryRoot));
61
- }
62
- if (where.not) {
63
- resultWhere.not = this.injectPredicatesToPredicate(where.not, entity, isBackReferenceContext, ancestorPath, isQueryRoot);
64
- }
65
- const fields = Object.keys(where).filter((it) => !["and", "or", "not"].includes(it));
66
- for (const field of fields) {
67
- resultWhere[field] = acceptFieldVisitor(this.schema, entity, field, {
68
- visitColumn: () => where[field],
69
- visitRelation: (context) => {
70
- const relationWhere = where[field];
71
- if (relationWhere === null) {
72
- return null;
73
- }
74
- const isBackReference = this.findBackReferencedAncestor(
75
- ancestorPath,
76
- context.relation.name,
77
- context.entity.name
78
- ) !== void 0;
79
- const nestedIsBackReferenceContext = isBackReference || isBackReferenceContext;
80
- const nestedAncestorPath = [...ancestorPath, context];
81
- const processedNestedWhere = this.injectPredicatesToPredicate(
82
- relationWhere,
83
- context.targetEntity,
84
- nestedIsBackReferenceContext,
85
- nestedAncestorPath,
86
- isQueryRoot
87
- );
88
- const shouldSimplifyNested = nestedIsBackReferenceContext && this.findBackReferencedAncestor(nestedAncestorPath, context.relation.name, context.entity.name) !== void 0;
89
- const targetPredicate = shouldSimplifyNested ? { [context.targetEntity.primary]: { always: true } } : this.predicateFactory.create(context.targetEntity, Acl.Operation.read, void 0, context, isQueryRoot);
90
- const primaryKey = context.targetEntity.primary;
91
- const nestedIsAlwaysTrue = Object.keys(processedNestedWhere).length === 1 && processedNestedWhere[primaryKey] !== void 0 && processedNestedWhere[primaryKey]?.always === true;
92
- const targetIsAlwaysTrue = Object.keys(targetPredicate).length === 1 && targetPredicate[primaryKey] !== void 0 && targetPredicate[primaryKey]?.always === true;
93
- if (nestedIsAlwaysTrue && targetIsAlwaysTrue) {
94
- return processedNestedWhere;
95
- }
96
- const parts = [processedNestedWhere, targetPredicate].filter((it) => Object.keys(it).length > 0);
97
- if (parts.length === 0) {
98
- return {};
99
- }
100
- if (parts.length === 1) {
101
- return parts[0];
102
- }
103
- return { and: parts };
104
- }
105
- });
106
- }
107
- return resultWhere;
108
- }
109
42
  injectToWhere(where, entity, isRoot, relationContext, isBackReferenceContext, ancestorPath, isQueryRoot) {
110
43
  const resultWhere = {};
111
44
  if (where.and) {
@@ -1 +1 @@
1
- {"version":3,"file":"PredicatesInjector.js","sources":["../../../../../packages/engine-content-api/src/acl/PredicatesInjector.ts"],"sourcesContent":["import { Acl, Input, Model, Writable } from '@contember/schema'\nimport { acceptFieldVisitor } from '@contember/schema-utils'\nimport { PredicateFactory } from './PredicateFactory.js'\n\nexport class PredicatesInjector {\n\tconstructor(private readonly schema: Model.Schema, private readonly predicateFactory: PredicateFactory) {}\n\n\tpublic inject(\n\t\tentity: Model.Entity,\n\t\twhere: Input.OptionalWhere,\n\t\trelationContext?: Model.AnyRelationContext,\n\t\tancestorPath?: readonly Model.AnyRelationContext[],\n\t): Input.OptionalWhere {\n\t\tconst isQueryRoot = !relationContext && (!ancestorPath || ancestorPath.length === 0)\n\t\tconst restrictedWhere = this.injectToWhere(where, entity, true, relationContext, false, ancestorPath ?? [], isQueryRoot)\n\t\treturn this.createWhere(entity, undefined, restrictedWhere, relationContext, false, ancestorPath ?? [], isQueryRoot)\n\t}\n\n\t/**\n\t * Finds an ancestor in the path that matches the given relation as a back-reference.\n\t * A match occurs when:\n\t * 1. The relation we're traversing has the same name as the inverse (targetRelation) of a relation in the ancestor path\n\t * 2. AND the entity where our relation is defined matches the targetEntity in the path\n\t * (to prevent false positives when different entities have relations with the same name)\n\t */\n\tprivate findBackReferencedAncestor(\n\t\tancestorPath: readonly Model.AnyRelationContext[],\n\t\trelationName: string,\n\t\trelationSourceEntityName: string,\n\t): Model.AnyRelationContext | undefined {\n\t\treturn ancestorPath.find(ctx =>\n\t\t\tctx.targetRelation?.name === relationName\n\t\t\t&& ctx.targetEntity.name === relationSourceEntityName\n\t\t)\n\t}\n\n\tprivate createWhere(\n\t\tentity: Model.Entity,\n\t\tfieldNames: string[] | undefined,\n\t\twhere: Input.OptionalWhere,\n\t\trelationContext?: Model.AnyRelationContext,\n\t\tisBackReferenceContext?: boolean,\n\t\tancestorPath?: readonly Model.AnyRelationContext[],\n\t\tisQueryRoot?: boolean,\n\t): Input.OptionalWhere {\n\t\t// Simplify predicates when:\n\t\t// 1. We're in a back-reference context (inside a filter that traverses back)\n\t\t// 2. AND the relation we traversed to get here corresponds to a relation in our query path\n\t\t// This ensures we only simplify when the traversed relation actually corresponds\n\t\t// to a relation in our query path (not just any relation to the same entity type)\n\t\tconst shouldSimplify = isBackReferenceContext === true\n\t\t\t&& ancestorPath !== undefined\n\t\t\t&& relationContext !== undefined\n\t\t\t&& this.findBackReferencedAncestor(ancestorPath, relationContext.relation.name, relationContext.entity.name) !== undefined\n\n\t\tlet predicatesWhere: Input.OptionalWhere\n\t\tif (shouldSimplify) {\n\t\t\tpredicatesWhere = { [entity.primary]: { always: true } }\n\t\t} else {\n\t\t\tconst rawPredicate = this.predicateFactory.create(entity, Acl.Operation.read, fieldNames, relationContext, isQueryRoot)\n\t\t\t// Process the predicate to inject nested entity predicates\n\t\t\tpredicatesWhere = this.injectPredicatesToPredicate(\n\t\t\t\trawPredicate,\n\t\t\t\tentity,\n\t\t\t\tisBackReferenceContext ?? false,\n\t\t\t\tancestorPath ?? [],\n\t\t\t\tisQueryRoot,\n\t\t\t)\n\t\t}\n\n\t\tconst and = [where, predicatesWhere].filter(it => Object.keys(it).length > 0)\n\t\tif (and.length === 0) {\n\t\t\treturn {}\n\t\t}\n\t\tif (and.length === 1) {\n\t\t\treturn and[0]\n\t\t}\n\t\treturn { and: and }\n\t}\n\n\t/**\n\t * Processes a predicate and injects nested entity predicates for any relation traversals.\n\t * This ensures that when a predicate like { department: { company: { name: 'Acme' } } }\n\t * is used, the predicates of Department and Company are also applied.\n\t */\n\tprivate injectPredicatesToPredicate(\n\t\twhere: Input.OptionalWhere,\n\t\tentity: Model.Entity,\n\t\tisBackReferenceContext: boolean,\n\t\tancestorPath: readonly Model.AnyRelationContext[],\n\t\tisQueryRoot?: boolean,\n\t): Input.OptionalWhere {\n\t\tconst resultWhere: Writable<Input.OptionalWhere> = {}\n\n\t\tif (where.and) {\n\t\t\tresultWhere.and = where.and\n\t\t\t\t.filter((it): it is Input.Where => !!it)\n\t\t\t\t.map(it => this.injectPredicatesToPredicate(it, entity, isBackReferenceContext, ancestorPath, isQueryRoot))\n\t\t}\n\t\tif (where.or) {\n\t\t\tresultWhere.or = where.or\n\t\t\t\t.filter((it): it is Input.Where => !!it)\n\t\t\t\t.map(it => this.injectPredicatesToPredicate(it, entity, isBackReferenceContext, ancestorPath, isQueryRoot))\n\t\t}\n\t\tif (where.not) {\n\t\t\tresultWhere.not = this.injectPredicatesToPredicate(where.not, entity, isBackReferenceContext, ancestorPath, isQueryRoot)\n\t\t}\n\n\t\tconst fields = Object.keys(where).filter(it => !['and', 'or', 'not'].includes(it))\n\n\t\tfor (const field of fields) {\n\t\t\tresultWhere[field] = acceptFieldVisitor(this.schema, entity, field, {\n\t\t\t\tvisitColumn: () => where[field],\n\t\t\t\tvisitRelation: context => {\n\t\t\t\t\tconst relationWhere = where[field] as Input.OptionalWhere | null\n\t\t\t\t\tif (relationWhere === null) {\n\t\t\t\t\t\treturn null\n\t\t\t\t\t}\n\n\t\t\t\t\t// Check if this relation is a back-reference to somewhere in our ancestor path\n\t\t\t\t\tconst isBackReference = this.findBackReferencedAncestor(\n\t\t\t\t\t\tancestorPath,\n\t\t\t\t\t\tcontext.relation.name,\n\t\t\t\t\t\tcontext.entity.name,\n\t\t\t\t\t) !== undefined\n\t\t\t\t\tconst nestedIsBackReferenceContext = isBackReference || isBackReferenceContext\n\t\t\t\t\tconst nestedAncestorPath: readonly Model.AnyRelationContext[] = [...ancestorPath, context]\n\n\t\t\t\t\t// Recursively process the nested where (always do this to handle deeper nesting)\n\t\t\t\t\tconst processedNestedWhere = this.injectPredicatesToPredicate(\n\t\t\t\t\t\trelationWhere,\n\t\t\t\t\t\tcontext.targetEntity,\n\t\t\t\t\t\tnestedIsBackReferenceContext,\n\t\t\t\t\t\tnestedAncestorPath,\n\t\t\t\t\t\tisQueryRoot,\n\t\t\t\t\t)\n\n\t\t\t\t\t// Check if we should simplify the target entity's predicate\n\t\t\t\t\tconst shouldSimplifyNested = nestedIsBackReferenceContext\n\t\t\t\t\t\t&& this.findBackReferencedAncestor(nestedAncestorPath, context.relation.name, context.entity.name) !== undefined\n\n\t\t\t\t\t// Get target entity's predicate (simplified if back-reference)\n\t\t\t\t\tconst targetPredicate = shouldSimplifyNested\n\t\t\t\t\t\t? { [context.targetEntity.primary]: { always: true } }\n\t\t\t\t\t\t: this.predicateFactory.create(context.targetEntity, Acl.Operation.read, undefined, context, isQueryRoot)\n\n\t\t\t\t\t// Optimization: avoid duplicate { id: always } when both are simplified\n\t\t\t\t\tconst primaryKey = context.targetEntity.primary\n\t\t\t\t\tconst nestedIsAlwaysTrue = Object.keys(processedNestedWhere).length === 1\n\t\t\t\t\t\t&& (processedNestedWhere as Record<string, unknown>)[primaryKey] !== undefined\n\t\t\t\t\t\t&& (processedNestedWhere as Record<string, Record<string, unknown>>)[primaryKey]?.always === true\n\t\t\t\t\tconst targetIsAlwaysTrue = Object.keys(targetPredicate).length === 1\n\t\t\t\t\t\t&& (targetPredicate as Record<string, unknown>)[primaryKey] !== undefined\n\t\t\t\t\t\t&& (targetPredicate as Record<string, Record<string, unknown>>)[primaryKey]?.always === true\n\n\t\t\t\t\tif (nestedIsAlwaysTrue && targetIsAlwaysTrue) {\n\t\t\t\t\t\treturn processedNestedWhere\n\t\t\t\t\t}\n\n\t\t\t\t\t// Combine the processed nested where with target entity's predicate\n\t\t\t\t\tconst parts = [processedNestedWhere, targetPredicate].filter(it => Object.keys(it).length > 0)\n\t\t\t\t\tif (parts.length === 0) {\n\t\t\t\t\t\treturn {}\n\t\t\t\t\t}\n\t\t\t\t\tif (parts.length === 1) {\n\t\t\t\t\t\treturn parts[0]\n\t\t\t\t\t}\n\t\t\t\t\treturn { and: parts }\n\t\t\t\t},\n\t\t\t})\n\t\t}\n\n\t\treturn resultWhere\n\t}\n\n\tprivate injectToWhere(\n\t\twhere: Input.OptionalWhere,\n\t\tentity: Model.Entity,\n\t\tisRoot: boolean,\n\t\trelationContext: Model.AnyRelationContext | undefined,\n\t\tisBackReferenceContext: boolean,\n\t\tancestorPath: readonly Model.AnyRelationContext[],\n\t\tisQueryRoot?: boolean,\n\t): Input.OptionalWhere {\n\t\tconst resultWhere: Writable<Input.OptionalWhere> = {}\n\t\tif (where.and) {\n\t\t\tresultWhere.and = where.and.filter((it): it is Input.Where => !!it).map(it =>\n\t\t\t\tthis.injectToWhere(it, entity, isRoot, relationContext, isBackReferenceContext, ancestorPath, isQueryRoot)\n\t\t\t)\n\t\t}\n\t\tif (where.or) {\n\t\t\tresultWhere.or = where.or.filter((it): it is Input.Where => !!it).map(it =>\n\t\t\t\tthis.injectToWhere(it, entity, isRoot, relationContext, isBackReferenceContext, ancestorPath, isQueryRoot)\n\t\t\t)\n\t\t}\n\t\tif (where.not) {\n\t\t\tresultWhere.not = this.injectToWhere(where.not, entity, isRoot, relationContext, isBackReferenceContext, ancestorPath, isQueryRoot)\n\t\t}\n\n\t\tconst fields = Object.keys(where).filter(it => !['and', 'or', 'not'].includes(it))\n\n\t\tif (fields.length === 0) {\n\t\t\treturn resultWhere\n\t\t}\n\t\tfor (let field of fields) {\n\t\t\tresultWhere[field] = acceptFieldVisitor(this.schema, entity, field, {\n\t\t\t\tvisitColumn: () => where[field],\n\t\t\t\tvisitRelation: context => {\n\t\t\t\t\tconst relationWhere = where[field] as Input.OptionalWhere | null\n\t\t\t\t\tif (relationWhere === null) {\n\t\t\t\t\t\treturn null\n\t\t\t\t\t}\n\t\t\t\t\t// Check if this relation is a back-reference to somewhere in our ancestor path\n\t\t\t\t\tconst isBackReference = this.findBackReferencedAncestor(ancestorPath, context.relation.name, context.entity.name) !== undefined\n\t\t\t\t\t// Once we enter a back-reference context, stay in it for nested relations\n\t\t\t\t\tconst nestedIsBackReferenceContext = isBackReference || isBackReferenceContext\n\t\t\t\t\t// Build extended ancestor path for nested traversal\n\t\t\t\t\tconst nestedAncestorPath: Model.AnyRelationContext[] = [...ancestorPath, context]\n\t\t\t\t\treturn this.injectToWhere(relationWhere, context.targetEntity, false, context, nestedIsBackReferenceContext, nestedAncestorPath, isQueryRoot)\n\t\t\t\t},\n\t\t\t})\n\t\t}\n\t\tconst fieldsForPredicate = !isRoot\n\t\t\t? fields\n\t\t\t: fields.filter(it => this.predicateFactory.shouldApplyCellLevelPredicate(entity, Acl.Operation.read, it, isQueryRoot))\n\n\t\treturn this.createWhere(entity, fieldsForPredicate, resultWhere, relationContext, isBackReferenceContext, ancestorPath, isQueryRoot)\n\t}\n}\n"],"names":[],"mappings":";;AAIO,MAAM,mBAAmB;AAAA,EAC/B,YAA6B,QAAuC,kBAAoC;AAA3E,SAAA,SAAA;AAAuC,SAAA,mBAAA;AAAA,EAAqC;AAAA,EAElG,OACN,QACA,OACA,iBACA,cACsB;AACtB,UAAM,cAAc,CAAC,oBAAoB,CAAC,gBAAgB,aAAa,WAAW;AAClF,UAAM,kBAAkB,KAAK,cAAc,OAAO,QAAQ,MAAM,iBAAiB,OAAO,gBAAgB,CAAA,GAAI,WAAW;AACvH,WAAO,KAAK,YAAY,QAAQ,QAAW,iBAAiB,iBAAiB,OAAO,gBAAgB,CAAA,GAAI,WAAW;AAAA,EACpH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASQ,2BACP,cACA,cACA,0BACuC;AACvC,WAAO,aAAa;AAAA,MAAK,SACxB,IAAI,gBAAgB,SAAS,gBAC1B,IAAI,aAAa,SAAS;AAAA,IAAA;AAAA,EAE/B;AAAA,EAEQ,YACP,QACA,YACA,OACA,iBACA,wBACA,cACA,aACsB;AAMtB,UAAM,iBAAiB,2BAA2B,QAC9C,iBAAiB,UACjB,oBAAoB,UACpB,KAAK,2BAA2B,cAAc,gBAAgB,SAAS,MAAM,gBAAgB,OAAO,IAAI,MAAM;AAElH,QAAI;AACJ,QAAI,gBAAgB;AACnB,wBAAkB,EAAE,CAAC,OAAO,OAAO,GAAG,EAAE,QAAQ,OAAK;AAAA,IACtD,OAAO;AACN,Y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mB;AAExD,gBAAM,qBAAiD,CAAC,GAAG,cAAc,OAAO;AAChF,iBAAO,KAAK,cAAc,eAAe,QAAQ,cAAc,OAAO,SAAS,8BAA8B,oBAAoB,WAAW;AAAA,QAC7I;AAAA,MAAA,CACA;AAAA,IACF;AACA,UAAM,qBAAqB,CAAC,SACzB,SACA,OAAO,OAAO,CAAA,OAAM,KAAK,iBAAiB,8BAA8B,QAAQ,IAAI,UAAU,MAAM,IAAI,WAAW,CAAC;AAEvH,WAAO,KAAK,YAAY,QAAQ,oBAAoB,aAAa,iBAAiB,wBAAwB,cAAc,WAAW;AAAA,EACpI;AACD;"}
1
+ {"version":3,"file":"PredicatesInjector.js","sources":["../../../../../packages/engine-content-api/src/acl/PredicatesInjector.ts"],"sourcesContent":["import { Acl, Input, Model, Writable } from '@contember/schema'\nimport { acceptFieldVisitor } from '@contember/schema-utils'\nimport { PredicateFactory } from './PredicateFactory.js'\n\nexport class PredicatesInjector {\n\tconstructor(private readonly schema: Model.Schema, private readonly predicateFactory: PredicateFactory) {}\n\n\tpublic inject(\n\t\tentity: Model.Entity,\n\t\twhere: Input.OptionalWhere,\n\t\trelationContext?: Model.AnyRelationContext,\n\t\tancestorPath?: readonly Model.AnyRelationContext[],\n\t): Input.OptionalWhere {\n\t\tconst isQueryRoot = !relationContext && (!ancestorPath || ancestorPath.length === 0)\n\t\tconst restrictedWhere = this.injectToWhere(where, entity, true, relationContext, false, ancestorPath ?? [], isQueryRoot)\n\t\treturn this.createWhere(entity, undefined, restrictedWhere, relationContext, false, ancestorPath ?? [], isQueryRoot)\n\t}\n\n\t/**\n\t * Finds an ancestor in the path that matches the given relation as a back-reference.\n\t * A match occurs when:\n\t * 1. The relation we're traversing has the same name as the inverse (targetRelation) of a relation in the ancestor path\n\t * 2. AND the entity where our relation is defined matches the targetEntity in the path\n\t * (to prevent false positives when different entities have relations with the same name)\n\t */\n\tprivate findBackReferencedAncestor(\n\t\tancestorPath: readonly Model.AnyRelationContext[],\n\t\trelationName: string,\n\t\trelationSourceEntityName: string,\n\t): Model.AnyRelationContext | undefined {\n\t\treturn ancestorPath.find(ctx =>\n\t\t\tctx.targetRelation?.name === relationName\n\t\t\t&& ctx.targetEntity.name === relationSourceEntityName\n\t\t)\n\t}\n\n\tprivate createWhere(\n\t\tentity: Model.Entity,\n\t\tfieldNames: string[] | undefined,\n\t\twhere: Input.OptionalWhere,\n\t\trelationContext?: Model.AnyRelationContext,\n\t\tisBackReferenceContext?: boolean,\n\t\tancestorPath?: readonly Model.AnyRelationContext[],\n\t\tisQueryRoot?: boolean,\n\t): Input.OptionalWhere {\n\t\t// Simplify predicates when:\n\t\t// 1. We're in a back-reference context (inside a filter that traverses back)\n\t\t// 2. AND the relation we traversed to get here corresponds to a relation in our query path\n\t\t// This ensures we only simplify when the traversed relation actually corresponds\n\t\t// to a relation in our query path (not just any relation to the same entity type)\n\t\tconst shouldSimplify = isBackReferenceContext === true\n\t\t\t&& ancestorPath !== undefined\n\t\t\t&& relationContext !== undefined\n\t\t\t&& this.findBackReferencedAncestor(ancestorPath, relationContext.relation.name, relationContext.entity.name) !== undefined\n\n\t\tlet predicatesWhere: Input.OptionalWhere\n\t\tif (shouldSimplify) {\n\t\t\tpredicatesWhere = { [entity.primary]: { always: true } }\n\t\t} else {\n\t\t\tpredicatesWhere = this.predicateFactory.create(entity, Acl.Operation.read, fieldNames, relationContext, isQueryRoot)\n\t\t}\n\n\t\tconst and = [where, predicatesWhere].filter(it => Object.keys(it).length > 0)\n\t\tif (and.length === 0) {\n\t\t\treturn {}\n\t\t}\n\t\tif (and.length === 1) {\n\t\t\treturn and[0]\n\t\t}\n\t\treturn { and: and }\n\t}\n\n\tprivate injectToWhere(\n\t\twhere: Input.OptionalWhere,\n\t\tentity: Model.Entity,\n\t\tisRoot: boolean,\n\t\trelationContext: Model.AnyRelationContext | undefined,\n\t\tisBackReferenceContext: boolean,\n\t\tancestorPath: readonly Model.AnyRelationContext[],\n\t\tisQueryRoot?: boolean,\n\t): Input.OptionalWhere {\n\t\tconst resultWhere: Writable<Input.OptionalWhere> = {}\n\t\tif (where.and) {\n\t\t\tresultWhere.and = where.and.filter((it): it is Input.Where => !!it).map(it =>\n\t\t\t\tthis.injectToWhere(it, entity, isRoot, relationContext, isBackReferenceContext, ancestorPath, isQueryRoot)\n\t\t\t)\n\t\t}\n\t\tif (where.or) {\n\t\t\tresultWhere.or = where.or.filter((it): it is Input.Where => !!it).map(it =>\n\t\t\t\tthis.injectToWhere(it, entity, isRoot, relationContext, isBackReferenceContext, ancestorPath, isQueryRoot)\n\t\t\t)\n\t\t}\n\t\tif (where.not) {\n\t\t\tresultWhere.not = this.injectToWhere(where.not, entity, isRoot, relationContext, isBackReferenceContext, ancestorPath, isQueryRoot)\n\t\t}\n\n\t\tconst fields = Object.keys(where).filter(it => !['and', 'or', 'not'].includes(it))\n\n\t\tif (fields.length === 0) {\n\t\t\treturn resultWhere\n\t\t}\n\t\tfor (let field of fields) {\n\t\t\tresultWhere[field] = acceptFieldVisitor(this.schema, entity, field, {\n\t\t\t\tvisitColumn: () => where[field],\n\t\t\t\tvisitRelation: context => {\n\t\t\t\t\tconst relationWhere = where[field] as Input.OptionalWhere | null\n\t\t\t\t\tif (relationWhere === null) {\n\t\t\t\t\t\treturn null\n\t\t\t\t\t}\n\t\t\t\t\t// Check if this relation is a back-reference to somewhere in our ancestor path\n\t\t\t\t\tconst isBackReference = this.findBackReferencedAncestor(ancestorPath, context.relation.name, context.entity.name) !== undefined\n\t\t\t\t\t// Once we enter a back-reference context, stay in it for nested relations\n\t\t\t\t\tconst nestedIsBackReferenceContext = isBackReference || isBackReferenceContext\n\t\t\t\t\t// Build extended ancestor path for nested traversal\n\t\t\t\t\tconst nestedAncestorPath: Model.AnyRelationContext[] = [...ancestorPath, context]\n\t\t\t\t\treturn this.injectToWhere(relationWhere, context.targetEntity, false, context, nestedIsBackReferenceContext, nestedAncestorPath, isQueryRoot)\n\t\t\t\t},\n\t\t\t})\n\t\t}\n\t\tconst fieldsForPredicate = !isRoot\n\t\t\t? fields\n\t\t\t: fields.filter(it => this.predicateFactory.shouldApplyCellLevelPredicate(entity, Acl.Operation.read, it, isQueryRoot))\n\n\t\treturn this.createWhere(entity, fieldsForPredicate, resultWhere, relationContext, isBackReferenceContext, ancestorPath, isQueryRoot)\n\t}\n}\n"],"names":[],"mappings":";;AAIO,MAAM,mBAAmB;AAAA,EAC/B,YAA6B,QAAuC,kBAAoC;AAA3E,SAAA,SAAA;AAAuC,SAAA,mBAAA;AAAA,EAAqC;AAAA,EAElG,OACN,QACA,OACA,iBACA,cACsB;AACtB,UAAM,cAAc,CAAC,oBAAoB,CAAC,gBAAgB,aAAa,WAAW;AAClF,UAAM,kBAAkB,KAAK,cAAc,OAAO,QAAQ,MAAM,iBAAiB,OAAO,gBAAgB,CAAA,GAAI,WAAW;AACvH,WAAO,KAAK,YAAY,QAAQ,QAAW,iBAAiB,iBAAiB,OAAO,gBAAgB,CAAA,GAAI,WAAW;AAAA,EACpH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASQ,2BACP,cACA,cACA,0BACuC;AACvC,WAAO,aAAa;AAAA,MAAK,SACxB,IAAI,gBAAgB,SAAS,gBAC1B,IAAI,aAAa,SAAS;AAAA,IAAA;AAAA,EAE/B;AAAA,EAEQ,YACP,QACA,YACA,OACA,iBACA,wBACA,cACA,aACsB;AAMtB,UAAM,iBAAiB,2BAA2B,QAC9C,iBAAiB,UACjB,oBAAoB,UACpB,KAAK,2BAA2B,cAAc,gBAAgB,SAAS,MAAM,gBAAgB,OAAO,IAAI,MAAM;AAElH,QAAI;AACJ,QAAI,gBAAgB;AACnB,wBAAkB,EAAE,CAAC,OAAO,OAAO,GAAG,EAAE,QAAQ,OAAK;AAAA,IACtD,OAAO;AACN,wBAAkB,KAAK,iBAAiB,OAAO,QAAQ,IAAI,UAAU,MAAM,YAAY,iBAAiB,WAAW;AAAA,IACpH;AAEA,UAAM,MAAM,CAAC,OAAO,eAAe,EAAE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R;AAEA,gBAAM,kBAAkB,KAAK,2BAA2B,cAAc,QAAQ,SAAS,MAAM,QAAQ,OAAO,IAAI,MAAM;AAEtH,gBAAM,+BAA+B,mBAAmB;AAExD,gBAAM,qBAAiD,CAAC,GAAG,cAAc,OAAO;AAChF,iBAAO,KAAK,cAAc,eAAe,QAAQ,cAAc,OAAO,SAAS,8BAA8B,oBAAoB,WAAW;AAAA,QAC7I;AAAA,MAAA,CACA;AAAA,IACF;AACA,UAAM,qBAAqB,CAAC,SACzB,SACA,OAAO,OAAO,CAAA,OAAM,KAAK,iBAAiB,8BAA8B,QAAQ,IAAI,UAAU,MAAM,IAAI,WAAW,CAAC;AAEvH,WAAO,KAAK,YAAY,QAAQ,oBAAoB,aAAa,iBAAiB,wBAAwB,cAAc,WAAW;AAAA,EACpI;AACD;"}
@@ -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/index.js'\nimport { Client, Connection, ConstraintHelper, DatabaseMetadata, 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\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":";;;;;;;;;;;;;;;;;;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,IAAIA,uBAAAA,uBAAA,CAAuB;AAC7D,kBAAA,MAAgB,SAAQ,IAAIC,MAAAA,MAAA,CAAM;AAClC,kBAAA,MAAgB,kBAAA;AAEhB,kBAAA,MAAgB,cAAA;AAkBf,SAAK,mBAAmB,IAAIC,SAAAA,iBAAiB,IAAI,KAAK,sBAAsB;AAC5E,SAAK,eAAe,IAAIC,aAAAA,aAAa,IAAI;AAAA,EAC1C;AAAA,EAEA,MAAa,YAAY,QAAsB,OAA2C,WAAmB;AAC5G,UAAM,aAAaC,YAAAA,cAAc,KAAK,QAAQ,QAAQ,SAAS;AAE/D,UAAM,KAAKC,SAAAA,cAAc,OAAA,EACvB,KAAK,OAAO,WAAW,OAAO,EAC9B,OAAO,CAAC,SAAS,UAAU,CAAC;AAC9B,UAAM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IACX;AACA,WAAO,MAAME,YAAAA,mBAAmB,KAAK,QAAQ,QAAQ,UAAU;AAAA,MAC9D,wBAAwB,CAAC,EAAE,QAAAC,SAAQ,UAAAC,gBAAe;AACjD,eAAO,KAAK,qBAAqB,mBAAmB,MAAMD,SAAQC,WAAU,aAAa,YAAY;AAAA,MACtG;AAAA,MACA,yBAAyB,CAAC,EAAE,cAAc,qBAAqB;AAC9D,eAAO,KAAK,qBAAqB,mBAAmB,MAAM,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;;"}
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,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;AACA,SAAA,eAAA;AAxBlB,kBAAA,MAAQ,0BAAA;AACR,kBAAA,MAAgB,mBAAkB,IAAIA,uBAAAA,uBAAA,CAAuB;AAC7D,kBAAA,MAAgB,SAAQ,IAAIC,MAAAA,MAAA,CAAM;AAClC,kBAAA,MAAgB,kBAAA;AAEhB,kBAAA,MAAgB,aAAA;AAEhB,kBAAA,MAAgB,cAAA;AAmBf,SAAK,mBAAmB,IAAIC,SAAAA,iBAAiB,IAAI,KAAK,sBAAsB;AAC5E,SAAK,cAAc,eAAe,GAAG,iBAAiB,cAAc,EAAE,YAAY,KAAA,CAAM,IAAI;AAC5F,SAAK,eAAe,IAAIC,aAAAA,aAAa,IAAI;AAAA,EAC1C;AAAA,EAEA,MAAa,YAAY,QAAsB,OAA2C,WAAmB;AAC5G,UAAM,aAAaC,YAAAA,cAAc,KAAK,QAAQ,QAAQ,SAAS;AAE/D,UAAM,KAAKC,SAAAA,cAAc,OAAA,EACvB,KAAK,OAAO,WAAW,OAAO,EAC9B,OAAO,CAAC,SAAS,UAAU,CAAC;AAC9B,UAAM,gBAAgB,KAAK,o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