@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
package/CLAUDE.md CHANGED
@@ -28,6 +28,12 @@ GraphQL mutation → MutationResolver.resolveTransaction
28
28
  → REPEATABLE_READ transaction with deadlock retry (up to 15 attempts)
29
29
  ```
30
30
 
31
+ ## Request Memory Budget
32
+
33
+ - The `db` service of the execution container is the request client **bound** to the `RequestMemoryBudget` without charging (`withMemoryBudget(budget, { chargeRows: false })`): every query of the request is refused once the budget is exhausted, none of them accounts rows. `Mapper.selectionDb` is the same client **charged** — route a query through it only when its rows end up in the response (`selectRows`, the many-has-many junction fetch). `SelectHydrator` charges the hydrated objects once per result.
34
+ - The budget is sticky: once exceeded, every further query throws `RequestMemoryBudgetExceededError` — a `totalCount` or unique lookup queued behind the selection that exhausted it fails with the same error, never with a connection error. `MapperFactory.transaction` also checks before it queues for a pool connection.
35
+ - `MutationResolver.transaction` turns that error into `ok: false` with `ExecutionErrorType.ResourceExhausted`, after the rollback. For `mutation { transaction { … } }` every mutation field of the transaction gets that result too, because those fields are non-null. A query is instead rejected as a whole by `engine-http` (`graphql/execution.ts`), because partial data of a read is worthless.
36
+
31
37
  ## ACL Enforcement
32
38
 
33
39
  Row-level and field-level security via predicate injection into every SQL operation:
@@ -36,6 +42,12 @@ Row-level and field-level security via predicate injection into every SQL operat
36
42
  - `PredicatesInjector` — ANDs user predicates with ACL predicates on every query
37
43
  - `VariableInjector` — replaces variable references with identity-specific values
38
44
 
45
+ ### Read-path guarding
46
+
47
+ - `PredicateFactory.getFieldPredicate(...)` resolves a field's ACL predicate; `getPermissionsForContext(isRoot)` picks the permission set — root-only unless the caller passes `isRoot === false` (nested/relation context), which adds `through: true` permissions (`allPermissions`). An unknown context falls back to the narrower root set, so the two sets can **over-restrict, never leak**.
48
+ - Projection cell-masking happens during JS hydration (`SelectBuilder` maps `row => predicateGetter(row) ? row[alias] : null`), not in SQL. The predicate boolean column is also consumed by relation fetching (`getColumnValues`) and by the hydrator, so moving the mask into the SQL expression is not a local change.
49
+ - **`WhereOptimizer`'s `isLast` handling is deliberately conservative.** The obvious one-line "fix" (`Number(i) === relationPath.length` → `- 1`) drops the has-many `EXISTS` requirement, collapsing `{ articles: { author: { id: { isNull: false } } } }` to `{ id: { always: true } }` — an over-match. Verified empirically; it needs a real optimizer change, not a tweak.
50
+
39
51
  ## GraphQL Schema Building
40
52
 
41
53
  `GraphQlSchemaBuilderFactory` → `GraphQlSchemaBuilder`:
@@ -79,6 +79,7 @@ class ExecutionContainerFactory {
79
79
  identityVariables,
80
80
  identityId,
81
81
  db,
82
+ memoryBudget,
82
83
  schema,
83
84
  schemaMeta,
84
85
  systemSchema,
@@ -87,7 +88,7 @@ class ExecutionContainerFactory {
87
88
  schemaDatabaseMetadata,
88
89
  userInfo
89
90
  }) {
90
- return new dic.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.VariableInjector(schema2.model, identityVariables)).addService(
91
+ return new dic.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.VariableInjector(schema2.model, identityVariables)).addService(
91
92
  "predicateFactory",
92
93
  ({ variableInjector, schema: schema2 }) => new PredicateFactory.PredicateFactory(permissions, schema2.model, variableInjector, allPermissions)
93
94
  ).addService("predicatesInjector", ({ predicateFactory, schema: schema2 }) => new PredicatesInjector.PredicatesInjector(schema2.model, predicateFactory)).addService("joinBuilder", ({ schema: schema2 }) => new JoinBuilder.JoinBuilder(schema2.model)).addService("conditionBuilder", () => new ConditionBuilder.ConditionBuilder()).addService("pathFactory", () => new Path.PathFactory()).addService("whereOptimized", ({ schema: schema2 }) => new WhereOptimizer.WhereOptimizer(schema2.model, new ConditionOptimizer.ConditionOptimizer(), this.whereOptimizerOptions)).addService("whereBuilder", ({ joinBuilder, conditionBuilder, pathFactory, whereOptimized, schema: schema2 }) => new WhereBuilder.WhereBuilder(
@@ -160,10 +161,11 @@ class ExecutionContainerFactory {
160
161
  pathFactory,
161
162
  providers,
162
163
  schema: schema2,
163
- schemaDatabaseMetadata: schemaDatabaseMetadata2
164
+ schemaDatabaseMetadata: schemaDatabaseMetadata2,
165
+ db: db2
164
166
  }) => {
165
167
  return new MapperFactory.MapperFactory(
166
- db,
168
+ db2,
167
169
  identityId,
168
170
  schema2.model,
169
171
  schemaDatabaseMetadata2,
@@ -176,7 +178,8 @@ class ExecutionContainerFactory {
176
178
  updater,
177
179
  inserter,
178
180
  pathFactory,
179
- providers
181
+ providers,
182
+ memoryBudget
180
183
  );
181
184
  }
182
185
  ).addService("queryAstFactory", () => new GraphQlQueryAstFactory.GraphQlQueryAstFactory()).addService("readResolver", ({ mapperFactory, queryAstFactory }) => new ReadResolver.ReadResolver(mapperFactory, queryAstFactory)).addService("validationDependencyCollector", () => new DependencyCollector.DependencyCollector()).addService("validationQueryAstFactory", ({ schema: schema2 }) => new QueryAstFactory.QueryAstFactory(schema2.model)).addService("dataSelector", ({ validationQueryAstFactory, schema: schema2 }) => new ValidationDataSelector.ValidationDataSelector(schema2.model, validationQueryAstFactory)).addService("columnValueResolver", ({ providers }) => new ColumnValueResolver.ColumnValueResolver(providers)).addService("entityRulesResolver", ({ schema: schema2 }) => new EntityRulesResolver.EntityRulesResolver(schema2.validation, schema2.model)).addService(
@@ -1 +1 @@
1
- {"version":3,"file":"ExecutionContainer.cjs","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":["Builder","schema","VariableInjector","PredicateFactory","PredicatesInjector","JoinBuilder","ConditionBuilder","PathFactory","WhereOptimizer","ConditionOptimizer","WhereBuilder","OrderByBuilder","RelationFetcher","FieldsVisitorFactory","MetaHandler","UniqueWhereExpander","HasManyToHasOneReducerExecutionHandler","PaginatedHasManyExecutionHandler","HasManyToHasOneReducer","PaginatedHasManyFieldProvider","SelectBuilder","InsertBuilderFactory","UpdateBuilderFactory","JunctionConnectHandler","JunctionDisconnectHandler","JunctionTableManager","DeleteExecutor","Updater","schemaDatabaseMetadata","Inserter","MapperFactory","GraphQlQueryAstFactory","ReadResolver","DependencyCollector","QueryAstFactory","ValidationDataSelector","ColumnValueResolver","EntityRulesResolver","InputPreValidator","MutationResolver","ValidationResolver","RefreshViewResolver"],"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,IACA;AAAA,IACA;AAAA,EAAA,GAEA;AACD,WAAO,IAAIA,IAAAA,QAAQ,CAAA,CAAE,EACnB,WAAW,gBAAgB,MAAM,YAAY,EAC7C,WAAW,MAAM,MAAM,EAAE,EACzB,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,UAAU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AiB,CAAC,EACnI,WAAW,uBAAuB,CAAC,EAAE,QAAAvC,SAAQ,cAAA,MAAoB,IAAIwC,oBAAAA,oBAAoBxC,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.cjs","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":["Builder","schema","VariableInjector","PredicateFactory","PredicatesInjector","JoinBuilder","ConditionBuilder","PathFactory","WhereOptimizer","ConditionOptimizer","WhereBuilder","OrderByBuilder","RelationFetcher","FieldsVisitorFactory","MetaHandler","UniqueWhereExpander","HasManyToHasOneReducerExecutionHandler","PaginatedHasManyExecutionHandler","HasManyToHasOneReducer","PaginatedHasManyFieldProvider","SelectBuilder","InsertBuilderFactory","UpdateBuilderFactory","JunctionConnectHandler","JunctionDisconnectHandler","JunctionTableManager","DeleteExecutor","Updater","schemaDatabaseMetadata","Inserter","db","MapperFactory","GraphQlQueryAstFactory","ReadResolver","DependencyCollector","QueryAstFactory","ValidationDataSelector","ColumnValueResolver","EntityRulesResolver","InputPreValidator","MutationResolver","ValidationResolver","RefreshViewResolver"],"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;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,WAAW,uBAAuB,CAAC,EAAE,QAAApC,QAAAA,MAAa,IAAIqC,oBAAAA,oBAAoBrC,QAAO,YAAYA,QAAO,KAAK,CAAC,EAC1G;AAAA,MACA;AAAA,MACA,CAAC,EAAE,qBAAqB,qBAAqB,cAAc,QAAAA,QAAAA,MAC1D,IAAIsC,kBAAAA,kBAAkBtC,QAAO,OAAO,qBAAqB,qBAAqB,YAAY;AAAA,IAAA,EAE3F;AAAA,MACA;AAAA,MACA,CAAC,EAAE,eAAe,mBAAmB,iBAAiB,QAAAA,SAAQ,wBAAA2B,wBAAAA,MAC7D,IAAIY,iBAAAA,iBAAiBvC,QAAO,OAAO,eAAe,mBAAmB,iBAAiB2B,uBAAsB;AAAA,IAAA,EAE7G,WAAW,sBAAsB,CAAC,EAAE,mBAAmB,cAAA,MAAoB,IAAIa,mBAAAA,mBAAmB,eAAe,iBAAiB,CAAC,EACnI,WAAW,uBAAuB,CAAC,EAAE,QAAAxC,SAAQ,cAAA,MAAoB,IAAIyC,oBAAAA,oBAAoBzC,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;;;"}
@@ -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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,CAAqB,EAC3E,WAAW,6BAA6B,CAAC,EAAE,QAAAD,QAAAA,MAAa,IAAI,gBAAgBA,QAAO,KAAK,CAAC,EACzF,WAAW,gBAAgB,CAAC,EAAE,2BAA2B,QAAAA,cAAa,IAAI,uBAAuBA,QAAO,OAAO,yBAAyB,CAAC,EACzI,WAAW,uBAAuB,CAAC,EAAE,UAAA,MAAgB,IAAI,oBAAoB,SAAS,CAAC,EACvF,WAAW,uBAAuB,CAAC,EAAE,QAAAA,QAAAA,MAAa,IAAI,oBAAoBA,QAAO,YAAYA,QAAO,KAAK,CAAC,EAC1G;AAAA,MACA;AAAA,MACA,CAAC,EAAE,qBAAqB,qBAAqB,cAAc,QAAAA,QAAAA,MAC1D,IAAI,kBAAkBA,QAAO,OAAO,qBAAqB,qBAAqB,YAAY;AAAA,IAAA,EAE3F;AAAA,MACA;AAAA,MACA,CAAC,EAAE,eAAe,mBAAmB,iBAAiB,QAAAA,SAAQ,wBAAAC,wBAAAA,MAC7D,IAAI,iBAAiBD,QAAO,OAAO,eAAe,mBAAmB,iBAAiBC,uBAAsB;AAAA,IAAA,EAE7G,WAAW,sBAAsB,CAAC,EAAE,mBAAmB,cAAA,MAAoB,IAAI,mBAAmB,eAAe,iBAAiB,CAAC,EACnI,WAAW,uBAAuB,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,0BAA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AA,QAAAA,MAAa,IAAI,oBAAoBA,QAAO,YAAYA,QAAO,KAAK,CAAC,EAC1G;AAAA,MACA;AAAA,MACA,CAAC,EAAE,qBAAqB,qBAAqB,cAAc,QAAAA,QAAAA,MAC1D,IAAI,kBAAkBA,QAAO,OAAO,qBAAqB,qBAAqB,YAAY;AAAA,IAAA,EAE3F;AAAA,MACA;AAAA,MACA,CAAC,EAAE,eAAe,mBAAmB,iBAAiB,QAAAA,SAAQ,wBAAAC,wBAAAA,MAC7D,IAAI,iBAAiBD,QAAO,OAAO,eAAe,mBAAmB,iBAAiBC,uBAAsB;AAAA,IAAA,EAE7G,WAAW,sBAAsB,CAAC,EAAE,mBAAmB,cAAA,MAAoB,IAAI,mBAAmB,eAAe,iBAAiB,CAAC,EACnI,WAAW,uBAAuB,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;"}
@@ -30,14 +30,7 @@ class PredicatesInjector {
30
30
  if (shouldSimplify) {
31
31
  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"],"names":["schema","Acl","acceptFieldVisitor"],"mappings":";;;;AAIO,MAAM,mBAAmB;AAAA,EAC/B,YAA6BA,SAAuC,kBAAoC;AAA3E,SAAA,SAAAA;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,E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A,UAAM,SAAS,OAAO,KAAK,KAAK,EAAE,OAAO,CAAA,OAAM,CAAC,CAAC,OAAO,MAAM,KAAK,EAAE,SAAS,EAAE,CAAC;AAEjF,QAAI,OAAO,WAAW,GAAG;AACxB,aAAO;AAAA,IACR;AACA,aAAS,SAAS,QAAQ;AACzB,kBAAY,KAAK,IAAIC,YAAAA,mBAAmB,KAAK,QAAQ,QAAQ,OAAO;AAAA,QACnE,aAAa,MAAM,MAAM,KAAK;AAAA,QAC9B,eAAe,CAAA,YAAW;AACzB,gBAAM,gBAAgB,MAAM,KAAK;AACjC,cAAI,kBAAkB,MAAM;AAC3B,mBAAO;AAAA,UACR;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,QAAQD,OAAAA,IAAI,UAAU,MAAM,IAAI,WAAW,CAAC;AAEvH,WAAO,KAAK,YAAY,QAAQ,oBAAoB,aAAa,iBAAiB,wBAAwB,cAAc,WAAW;AAAA,EACpI;AACD;;"}
1
+ {"version":3,"file":"PredicatesInjector.cjs","sources":["../../../../../packages/engine-content-api/src/acl/PredicatesInjector.ts"],"sourcesContent":["import { Acl, Input, Model, Writable } from '@contember/schema'\nimport { acceptFieldVisitor } from '@contember/schema-utils'\nimport { PredicateFactory } from './PredicateFactory.js'\n\nexport class PredicatesInjector {\n\tconstructor(private readonly schema: Model.Schema, private readonly predicateFactory: PredicateFactory) {}\n\n\tpublic inject(\n\t\tentity: Model.Entity,\n\t\twhere: Input.OptionalWhere,\n\t\trelationContext?: Model.AnyRelationContext,\n\t\tancestorPath?: readonly Model.AnyRelationContext[],\n\t): Input.OptionalWhere {\n\t\tconst isQueryRoot = !relationContext && (!ancestorPath || ancestorPath.length === 0)\n\t\tconst restrictedWhere = this.injectToWhere(where, entity, true, relationContext, false, ancestorPath ?? [], isQueryRoot)\n\t\treturn this.createWhere(entity, undefined, restrictedWhere, relationContext, false, ancestorPath ?? [], isQueryRoot)\n\t}\n\n\t/**\n\t * Finds an ancestor in the path that matches the given relation as a back-reference.\n\t * A match occurs when:\n\t * 1. The relation we're traversing has the same name as the inverse (targetRelation) of a relation in the ancestor path\n\t * 2. AND the entity where our relation is defined matches the targetEntity in the path\n\t * (to prevent false positives when different entities have relations with the same name)\n\t */\n\tprivate findBackReferencedAncestor(\n\t\tancestorPath: readonly Model.AnyRelationContext[],\n\t\trelationName: string,\n\t\trelationSourceEntityName: string,\n\t): Model.AnyRelationContext | undefined {\n\t\treturn ancestorPath.find(ctx =>\n\t\t\tctx.targetRelation?.name === relationName\n\t\t\t&& ctx.targetEntity.name === relationSourceEntityName\n\t\t)\n\t}\n\n\tprivate createWhere(\n\t\tentity: Model.Entity,\n\t\tfieldNames: string[] | undefined,\n\t\twhere: Input.OptionalWhere,\n\t\trelationContext?: Model.AnyRelationContext,\n\t\tisBackReferenceContext?: boolean,\n\t\tancestorPath?: readonly Model.AnyRelationContext[],\n\t\tisQueryRoot?: boolean,\n\t): Input.OptionalWhere {\n\t\t// Simplify predicates when:\n\t\t// 1. We're in a back-reference context (inside a filter that traverses back)\n\t\t// 2. AND the relation we traversed to get here corresponds to a relation in our query path\n\t\t// This ensures we only simplify when the traversed relation actually corresponds\n\t\t// to a relation in our query path (not just any relation to the same entity type)\n\t\tconst shouldSimplify = isBackReferenceContext === true\n\t\t\t&& ancestorPath !== undefined\n\t\t\t&& relationContext !== undefined\n\t\t\t&& this.findBackReferencedAncestor(ancestorPath, relationContext.relation.name, relationContext.entity.name) !== undefined\n\n\t\tlet predicatesWhere: Input.OptionalWhere\n\t\tif (shouldSimplify) {\n\t\t\tpredicatesWhere = { [entity.primary]: { always: true } }\n\t\t} else {\n\t\t\tpredicatesWhere = this.predicateFactory.create(entity, Acl.Operation.read, fieldNames, relationContext, isQueryRoot)\n\t\t}\n\n\t\tconst and = [where, predicatesWhere].filter(it => Object.keys(it).length > 0)\n\t\tif (and.length === 0) {\n\t\t\treturn {}\n\t\t}\n\t\tif (and.length === 1) {\n\t\t\treturn and[0]\n\t\t}\n\t\treturn { and: and }\n\t}\n\n\tprivate injectToWhere(\n\t\twhere: Input.OptionalWhere,\n\t\tentity: Model.Entity,\n\t\tisRoot: boolean,\n\t\trelationContext: Model.AnyRelationContext | undefined,\n\t\tisBackReferenceContext: boolean,\n\t\tancestorPath: readonly Model.AnyRelationContext[],\n\t\tisQueryRoot?: boolean,\n\t): Input.OptionalWhere {\n\t\tconst resultWhere: Writable<Input.OptionalWhere> = {}\n\t\tif (where.and) {\n\t\t\tresultWhere.and = where.and.filter((it): it is Input.Where => !!it).map(it =>\n\t\t\t\tthis.injectToWhere(it, entity, isRoot, relationContext, isBackReferenceContext, ancestorPath, isQueryRoot)\n\t\t\t)\n\t\t}\n\t\tif (where.or) {\n\t\t\tresultWhere.or = where.or.filter((it): it is Input.Where => !!it).map(it =>\n\t\t\t\tthis.injectToWhere(it, entity, isRoot, relationContext, isBackReferenceContext, ancestorPath, isQueryRoot)\n\t\t\t)\n\t\t}\n\t\tif (where.not) {\n\t\t\tresultWhere.not = this.injectToWhere(where.not, entity, isRoot, relationContext, isBackReferenceContext, ancestorPath, isQueryRoot)\n\t\t}\n\n\t\tconst fields = Object.keys(where).filter(it => !['and', 'or', 'not'].includes(it))\n\n\t\tif (fields.length === 0) {\n\t\t\treturn resultWhere\n\t\t}\n\t\tfor (let field of fields) {\n\t\t\tresultWhere[field] = acceptFieldVisitor(this.schema, entity, field, {\n\t\t\t\tvisitColumn: () => where[field],\n\t\t\t\tvisitRelation: context => {\n\t\t\t\t\tconst relationWhere = where[field] as Input.OptionalWhere | null\n\t\t\t\t\tif (relationWhere === null) {\n\t\t\t\t\t\treturn null\n\t\t\t\t\t}\n\t\t\t\t\t// Check if this relation is a back-reference to somewhere in our ancestor path\n\t\t\t\t\tconst isBackReference = this.findBackReferencedAncestor(ancestorPath, context.relation.name, context.entity.name) !== undefined\n\t\t\t\t\t// Once we enter a back-reference context, stay in it for nested relations\n\t\t\t\t\tconst nestedIsBackReferenceContext = isBackReference || isBackReferenceContext\n\t\t\t\t\t// Build extended ancestor path for nested traversal\n\t\t\t\t\tconst nestedAncestorPath: Model.AnyRelationContext[] = [...ancestorPath, context]\n\t\t\t\t\treturn this.injectToWhere(relationWhere, context.targetEntity, false, context, nestedIsBackReferenceContext, nestedAncestorPath, isQueryRoot)\n\t\t\t\t},\n\t\t\t})\n\t\t}\n\t\tconst fieldsForPredicate = !isRoot\n\t\t\t? fields\n\t\t\t: fields.filter(it => this.predicateFactory.shouldApplyCellLevelPredicate(entity, Acl.Operation.read, it, isQueryRoot))\n\n\t\treturn this.createWhere(entity, fieldsForPredicate, resultWhere, relationContext, isBackReferenceContext, ancestorPath, isQueryRoot)\n\t}\n}\n"],"names":["schema","Acl","acceptFieldVisitor"],"mappings":";;;;AAIO,MAAM,mBAAmB;AAAA,EAC/B,YAA6BA,SAAuC,kBAAoC;AAA3E,SAAA,SAAAA;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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,cAAc,WAAW;AAAA,MAAA;AAAA,IAE3G;AACA,QAAI,MAAM,KAAK;AACd,kBAAY,MAAM,KAAK,cAAc,MAAM,KAAK,QAAQ,QAAQ,iBAAiB,wBAAwB,cAAc,WAAW;AAAA,IACnI;AAEA,UAAM,SAAS,OAAO,KAAK,KAAK,EAAE,OAAO,CAAA,OAAM,CAAC,CAAC,OAAO,MAAM,KAAK,EAAE,SAAS,EAAE,CAAC;AAEjF,QAAI,OAAO,WAAW,GAAG;AACxB,aAAO;AAAA,IACR;AACA,aAAS,SAAS,QAAQ;AACzB,kBAAY,KAAK,IAAIC,YAAAA,mBAAmB,KAAK,QAAQ,QAAQ,OAAO;AAAA,QACnE,aAAa,MAAM,MAAM,KAAK;AAAA,QAC9B,eAAe,CAAA,YAAW;AACzB,gBAAM,gBAAgB,MAAM,KAAK;AACjC,cAAI,kBAAkB,MAAM;AAC3B,mBAAO;AAAA,UACR;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,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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ages/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,kB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