@contember/engine-content-api 2.2.0-alpha.1 → 2.2.0-alpha.11
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.
- package/CLAUDE.md +12 -0
- package/dist/development/src/ExecutionContainer.cjs +7 -4
- package/dist/development/src/ExecutionContainer.cjs.map +1 -1
- package/dist/development/src/ExecutionContainer.js +7 -4
- package/dist/development/src/ExecutionContainer.js.map +1 -1
- package/dist/development/src/acl/PredicatesInjector.cjs +1 -68
- package/dist/development/src/acl/PredicatesInjector.cjs.map +1 -1
- package/dist/development/src/acl/PredicatesInjector.js +1 -68
- package/dist/development/src/acl/PredicatesInjector.js.map +1 -1
- package/dist/development/src/mapper/Mapper.cjs +8 -5
- package/dist/development/src/mapper/Mapper.cjs.map +1 -1
- package/dist/development/src/mapper/Mapper.js +8 -5
- package/dist/development/src/mapper/Mapper.js.map +1 -1
- package/dist/development/src/mapper/MapperFactory.cjs +7 -4
- package/dist/development/src/mapper/MapperFactory.cjs.map +1 -1
- package/dist/development/src/mapper/MapperFactory.js +7 -4
- package/dist/development/src/mapper/MapperFactory.js.map +1 -1
- package/dist/development/src/mapper/select/ConditionBuilder.cjs +8 -1
- package/dist/development/src/mapper/select/ConditionBuilder.cjs.map +1 -1
- package/dist/development/src/mapper/select/ConditionBuilder.js +8 -1
- package/dist/development/src/mapper/select/ConditionBuilder.js.map +1 -1
- package/dist/development/src/mapper/select/RelationFetcher.cjs +2 -2
- package/dist/development/src/mapper/select/RelationFetcher.cjs.map +1 -1
- package/dist/development/src/mapper/select/RelationFetcher.js +2 -2
- package/dist/development/src/mapper/select/RelationFetcher.js.map +1 -1
- package/dist/development/src/mapper/select/SelectHydrator.cjs +39 -19
- package/dist/development/src/mapper/select/SelectHydrator.cjs.map +1 -1
- package/dist/development/src/mapper/select/SelectHydrator.js +39 -19
- package/dist/development/src/mapper/select/SelectHydrator.js.map +1 -1
- package/dist/development/src/resolvers/MutationResolver.cjs +49 -35
- package/dist/development/src/resolvers/MutationResolver.cjs.map +1 -1
- package/dist/development/src/resolvers/MutationResolver.js +50 -36
- package/dist/development/src/resolvers/MutationResolver.js.map +1 -1
- package/dist/production/src/ExecutionContainer.cjs +7 -4
- package/dist/production/src/ExecutionContainer.cjs.map +1 -1
- package/dist/production/src/ExecutionContainer.js +7 -4
- package/dist/production/src/ExecutionContainer.js.map +1 -1
- package/dist/production/src/acl/PredicatesInjector.cjs +1 -68
- package/dist/production/src/acl/PredicatesInjector.cjs.map +1 -1
- package/dist/production/src/acl/PredicatesInjector.js +1 -68
- package/dist/production/src/acl/PredicatesInjector.js.map +1 -1
- package/dist/production/src/mapper/Mapper.cjs +8 -5
- package/dist/production/src/mapper/Mapper.cjs.map +1 -1
- package/dist/production/src/mapper/Mapper.js +8 -5
- package/dist/production/src/mapper/Mapper.js.map +1 -1
- package/dist/production/src/mapper/MapperFactory.cjs +7 -4
- package/dist/production/src/mapper/MapperFactory.cjs.map +1 -1
- package/dist/production/src/mapper/MapperFactory.js +7 -4
- package/dist/production/src/mapper/MapperFactory.js.map +1 -1
- package/dist/production/src/mapper/select/ConditionBuilder.cjs +8 -1
- package/dist/production/src/mapper/select/ConditionBuilder.cjs.map +1 -1
- package/dist/production/src/mapper/select/ConditionBuilder.js +8 -1
- package/dist/production/src/mapper/select/ConditionBuilder.js.map +1 -1
- package/dist/production/src/mapper/select/RelationFetcher.cjs +2 -2
- package/dist/production/src/mapper/select/RelationFetcher.cjs.map +1 -1
- package/dist/production/src/mapper/select/RelationFetcher.js +2 -2
- package/dist/production/src/mapper/select/RelationFetcher.js.map +1 -1
- package/dist/production/src/mapper/select/SelectHydrator.cjs +39 -19
- package/dist/production/src/mapper/select/SelectHydrator.cjs.map +1 -1
- package/dist/production/src/mapper/select/SelectHydrator.js +39 -19
- package/dist/production/src/mapper/select/SelectHydrator.js.map +1 -1
- package/dist/production/src/resolvers/MutationResolver.cjs +49 -35
- package/dist/production/src/resolvers/MutationResolver.cjs.map +1 -1
- package/dist/production/src/resolvers/MutationResolver.js +50 -36
- package/dist/production/src/resolvers/MutationResolver.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/insert/memoryBudget.test.d.ts +2 -0
- package/dist/tests/cases/integration/graphQlRequests/insert/memoryBudget.test.d.ts.map +1 -0
- package/dist/tests/cases/integration/graphQlRequests/validation/utils.d.ts.map +1 -1
- package/dist/tests/cases/integration/graphQlSchema/model.d.ts +1 -1
- package/dist/tests/src/assert.d.ts.map +1 -1
- package/dist/tests/src/tags.d.ts.map +1 -1
- package/dist/tests/src/test.d.ts +2 -0
- package/dist/tests/src/test.d.ts.map +1 -1
- package/dist/tests/src/testGraphql.d.ts.map +1 -1
- package/dist/tests/src/testUuid.d.ts.map +1 -1
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/dist/types/ExecutionContainer.d.ts +3 -2
- package/dist/types/ExecutionContainer.d.ts.map +1 -1
- package/dist/types/acl/Authorizator.d.ts.map +1 -1
- package/dist/types/acl/EvaluatedPredicateReplacer.d.ts.map +1 -1
- package/dist/types/acl/PermissionFactory.d.ts.map +1 -1
- package/dist/types/acl/PredicateFactory.d.ts.map +1 -1
- package/dist/types/acl/PredicatesInjector.d.ts +0 -6
- package/dist/types/acl/PredicatesInjector.d.ts.map +1 -1
- package/dist/types/acl/VariableInjector.d.ts.map +1 -1
- package/dist/types/acl/VariableUtils.d.ts.map +1 -1
- package/dist/types/exception.d.ts.map +1 -1
- package/dist/types/extensions/hasManyToHasOneReducer/HasManyToHasOneReducer.d.ts.map +1 -1
- package/dist/types/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.d.ts.map +1 -1
- package/dist/types/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.d.ts.map +1 -1
- package/dist/types/extensions/paginatedHasMany/PaginatedHasManyCountVisitor.d.ts.map +1 -1
- package/dist/types/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.d.ts.map +1 -1
- package/dist/types/extensions/paginatedHasMany/PaginatedHasManyFieldProvider.d.ts.map +1 -1
- package/dist/types/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.d.ts.map +1 -1
- package/dist/types/extensions/paginatedHasMany/PaginatedHasManyNodesVisitor.d.ts.map +1 -1
- package/dist/types/input-validation/ColumnValueResolver.d.ts.map +1 -1
- package/dist/types/input-validation/EntityRulesResolver.d.ts.map +1 -1
- package/dist/types/input-validation/JsonSchemaValidator.d.ts.map +1 -1
- package/dist/types/input-validation/QueryAstFactory.d.ts.map +1 -1
- package/dist/types/input-validation/ValidationContext.d.ts.map +1 -1
- package/dist/types/input-validation/ValidationDataSelector.d.ts +1 -1
- package/dist/types/input-validation/ValidationDataSelector.d.ts.map +1 -1
- package/dist/types/input-validation/ValidationEvaluation.d.ts.map +1 -1
- package/dist/types/input-validation/ValidationPath.d.ts.map +1 -1
- package/dist/types/input-validation/dependencies/DependencyCollector.d.ts.map +1 -1
- package/dist/types/input-validation/dependencies/DependencyMerger.d.ts.map +1 -1
- package/dist/types/input-validation/preValidation/CreateInputPreValidationProcessor.d.ts.map +1 -1
- package/dist/types/input-validation/preValidation/InputPreValidator.d.ts.map +1 -1
- package/dist/types/input-validation/preValidation/UpdateInputPreValidationProcessor.d.ts.map +1 -1
- package/dist/types/inputProcessing/CreateInputVisitor.d.ts.map +1 -1
- package/dist/types/inputProcessing/FieldNode.d.ts.map +1 -1
- package/dist/types/inputProcessing/ObjectNode.d.ts.map +1 -1
- package/dist/types/inputProcessing/UniqueWhereExpander.d.ts.map +1 -1
- package/dist/types/inputProcessing/UpdateInputVisitor.d.ts.map +1 -1
- package/dist/types/introspection/IntrospectionSchemaDefinitionFactory.d.ts.map +1 -1
- package/dist/types/introspection/IntrospectionSchemaFactory.d.ts.map +1 -1
- package/dist/types/introspection/introspection.schema.d.ts.map +1 -1
- package/dist/types/mapper/CheckedPrimary.d.ts.map +1 -1
- package/dist/types/mapper/ColumnValue.d.ts.map +1 -1
- package/dist/types/mapper/Constraints.d.ts.map +1 -1
- package/dist/types/mapper/ErrorUtils.d.ts.map +1 -1
- package/dist/types/mapper/EventManager.d.ts +9 -9
- package/dist/types/mapper/EventManager.d.ts.map +1 -1
- package/dist/types/mapper/JunctionTableManager.d.ts.map +1 -1
- package/dist/types/mapper/Mapper.d.ts +5 -2
- package/dist/types/mapper/Mapper.d.ts.map +1 -1
- package/dist/types/mapper/MapperFactory.d.ts +3 -2
- package/dist/types/mapper/MapperFactory.d.ts.map +1 -1
- package/dist/types/mapper/MutationProcessorHelper.d.ts.map +1 -1
- package/dist/types/mapper/Result.d.ts.map +1 -1
- package/dist/types/mapper/delete/DeleteExecutor.d.ts.map +1 -1
- package/dist/types/mapper/delete/DeleteState.d.ts.map +1 -1
- package/dist/types/mapper/delete/DeletedEntitiesStorage.d.ts.map +1 -1
- package/dist/types/mapper/delete/helpers.d.ts +1 -1
- package/dist/types/mapper/delete/helpers.d.ts.map +1 -1
- package/dist/types/mapper/insert/InsertBuilder.d.ts.map +1 -1
- package/dist/types/mapper/insert/InsertBuilderFactory.d.ts.map +1 -1
- package/dist/types/mapper/insert/Inserter.d.ts.map +1 -1
- package/dist/types/mapper/insert/SqlCreateInputProcessor.d.ts.map +1 -1
- package/dist/types/mapper/insert/relations/ManyHasManyCreateInputProcessor.d.ts +1 -1
- package/dist/types/mapper/insert/relations/ManyHasManyCreateInputProcessor.d.ts.map +1 -1
- package/dist/types/mapper/insert/relations/ManyHasOneCreateInputProcessor.d.ts.map +1 -1
- package/dist/types/mapper/insert/relations/OneHasManyCreateInputProcessor.d.ts.map +1 -1
- package/dist/types/mapper/insert/relations/OneHasOneInverseCreateInputProcessor.d.ts +1 -1
- package/dist/types/mapper/insert/relations/OneHasOneInverseCreateInputProcessor.d.ts.map +1 -1
- package/dist/types/mapper/insert/relations/OneHasOneOwningCreateInputProcessor.d.ts.map +1 -1
- package/dist/types/mapper/select/ConditionBuilder.d.ts.map +1 -1
- package/dist/types/mapper/select/JoinBuilder.d.ts.map +1 -1
- package/dist/types/mapper/select/JoinVisitor.d.ts.map +1 -1
- package/dist/types/mapper/select/OrderByBuilder.d.ts.map +1 -1
- package/dist/types/mapper/select/OrderByHelper.d.ts.map +1 -1
- package/dist/types/mapper/select/Path.d.ts.map +1 -1
- package/dist/types/mapper/select/RelationFetcher.d.ts.map +1 -1
- package/dist/types/mapper/select/SelectBuilder.d.ts.map +1 -1
- package/dist/types/mapper/select/SelectHydrator.d.ts +6 -0
- package/dist/types/mapper/select/SelectHydrator.d.ts.map +1 -1
- package/dist/types/mapper/select/WhereBuilder.d.ts.map +1 -1
- package/dist/types/mapper/select/handlers/FieldsVisitor.d.ts.map +1 -1
- package/dist/types/mapper/select/handlers/FieldsVisitorFactory.d.ts.map +1 -1
- package/dist/types/mapper/select/handlers/MetaHandler.d.ts.map +1 -1
- package/dist/types/mapper/select/optimizer/ConditionOptimizer.d.ts.map +1 -1
- package/dist/types/mapper/select/optimizer/WhereOptimizer.d.ts.map +1 -1
- package/dist/types/mapper/select/optimizer/WhereReplacer.d.ts.map +1 -1
- package/dist/types/mapper/select/optimizer/helpers.d.ts +1 -1
- package/dist/types/mapper/select/optimizer/helpers.d.ts.map +1 -1
- package/dist/types/mapper/update/SqlUpdateInputProcessor.d.ts.map +1 -1
- package/dist/types/mapper/update/UpdateBuilder.d.ts.map +1 -1
- package/dist/types/mapper/update/UpdateBuilderFactory.d.ts.map +1 -1
- package/dist/types/mapper/update/Updater.d.ts.map +1 -1
- package/dist/types/mapper/update/relations/ManyHasManyUpdateInputProcessor.d.ts +2 -2
- package/dist/types/mapper/update/relations/ManyHasManyUpdateInputProcessor.d.ts.map +1 -1
- package/dist/types/mapper/update/relations/ManyHasOneUpdateInputProcessor.d.ts.map +1 -1
- package/dist/types/mapper/update/relations/OneHasManyUpdateInputProcessor.d.ts.map +1 -1
- package/dist/types/mapper/update/relations/OneHasOneInverseUpdateInputProcessor.d.ts.map +1 -1
- package/dist/types/mapper/update/relations/OneHasOneOwningUpdateInputProcessor.d.ts.map +1 -1
- package/dist/types/resolvers/GraphQlQueryAstFactory.d.ts.map +1 -1
- package/dist/types/resolvers/MutationResolver.d.ts.map +1 -1
- package/dist/types/resolvers/ReadHelpers.d.ts.map +1 -1
- package/dist/types/resolvers/ReadResolver.d.ts.map +1 -1
- package/dist/types/resolvers/RefreshViewResolver.d.ts.map +1 -1
- package/dist/types/resolvers/ValidationResolver.d.ts.map +1 -1
- package/dist/types/schema/ColumnTypeResolver.d.ts.map +1 -1
- package/dist/types/schema/ConditionTypeProvider.d.ts.map +1 -1
- package/dist/types/schema/EntityTypeProvider.d.ts.map +1 -1
- package/dist/types/schema/EnumsProvider.d.ts.map +1 -1
- package/dist/types/schema/FieldAccessVisitor.d.ts.map +1 -1
- package/dist/types/schema/GraphQlSchemaBuilder.d.ts.map +1 -1
- package/dist/types/schema/GraphQlSchemaBuilderFactory.d.ts.map +1 -1
- package/dist/types/schema/MutationProvider.d.ts.map +1 -1
- package/dist/types/schema/OperationExtension.d.ts.map +1 -1
- package/dist/types/schema/OrderByTypeProvider.d.ts.map +1 -1
- package/dist/types/schema/PaginatedFieldConfigFactory.d.ts.map +1 -1
- package/dist/types/schema/QueryProvider.d.ts.map +1 -1
- package/dist/types/schema/RefreshViewMutationProvider.d.ts.map +1 -1
- package/dist/types/schema/ValidationQueriesProvider.d.ts.map +1 -1
- package/dist/types/schema/WhereTypeProvider.d.ts.map +1 -1
- package/dist/types/schema/entities/FieldArgsVisitor.d.ts.map +1 -1
- package/dist/types/schema/entities/FieldTypeVisitor.d.ts.map +1 -1
- package/dist/types/schema/mutations/ConnectOrCreateRelationInputProvider.d.ts.map +1 -1
- package/dist/types/schema/mutations/CreateEntityInputFieldVisitor.d.ts.map +1 -1
- package/dist/types/schema/mutations/CreateEntityRelationAllowedOperationsVisitor.d.ts.map +1 -1
- package/dist/types/schema/mutations/CreateEntityRelationInputFieldVisitor.d.ts.map +1 -1
- package/dist/types/schema/mutations/CreateEntityRelationInputProvider.d.ts.map +1 -1
- package/dist/types/schema/mutations/EntityInputProvider.d.ts.map +1 -1
- package/dist/types/schema/mutations/UpdateEntityInputFieldVisitor.d.ts.map +1 -1
- package/dist/types/schema/mutations/UpdateEntityRelationAllowedOperationsVisitor.d.ts.map +1 -1
- package/dist/types/schema/mutations/UpdateEntityRelationInputFieldVisitor.d.ts.map +1 -1
- package/dist/types/schema/mutations/UpdateEntityRelationInputProvider.d.ts.map +1 -1
- package/dist/types/schema/utils.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/dist/types/utils/Mutex.d.ts.map +1 -1
- package/dist/types/utils/ResolveInfoUtils.d.ts.map +1 -1
- package/dist/types/utils/accessor.d.ts.map +1 -1
- package/dist/types/utils/isIt.d.ts.map +1 -1
- package/dist/types/utils/paginationUtils.d.ts.map +1 -1
- package/dist/types/utils/promises.d.ts.map +1 -1
- package/dist/types/utils/singletonFactory.d.ts.map +1 -1
- package/dist/types/utils/strings.d.ts.map +1 -1
- package/dist/types/utils/tuple.d.ts.map +1 -1
- package/dist/types/utils/uniqueWhereFields.d.ts.map +1 -1
- package/dist/types/utils/viewComputedId.d.ts.map +1 -1
- package/package.json +9 -9
- package/src/ExecutionContainer.ts +7 -2
- package/src/acl/PredicatesInjector.ts +1 -104
- package/src/mapper/Mapper.ts +9 -5
- package/src/mapper/MapperFactory.ts +7 -3
- package/src/mapper/select/ConditionBuilder.ts +12 -1
- package/src/mapper/select/RelationFetcher.ts +2 -4
- package/src/mapper/select/SelectHydrator.ts +43 -16
- package/src/resolvers/MutationResolver.ts +59 -36
- package/tests/cases/integration/graphQlRequests/insert/memoryBudget.test.ts +97 -0
- package/tests/cases/integration/graphQlRequests/query/pagination/hasManyLimit.test.ts +48 -2
- package/tests/cases/integration/graphQlRequests/query/relations/oneHasMany.test.ts +3 -3
- package/tests/cases/integration/graphQlRequests/query/sorting/randomSort.test.ts +1 -1
- package/tests/cases/integration/graphQlSchema/schema-acl-allowed.gql +1 -0
- package/tests/cases/integration/graphQlSchema/schema-acl-create-only.gql +1 -0
- package/tests/cases/integration/graphQlSchema/schema-acl-restricted-create.gql +1 -0
- package/tests/cases/integration/graphQlSchema/schema-acl-restricted-delete.gql +1 -0
- package/tests/cases/integration/graphQlSchema/schema-acl-restricted-update.gql +1 -0
- package/tests/cases/integration/graphQlSchema/schema-acl.gql +1 -0
- package/tests/cases/integration/graphQlSchema/schema-aliased-type.gql +1 -0
- package/tests/cases/integration/graphQlSchema/schema-array.gql +1 -0
- package/tests/cases/integration/graphQlSchema/schema-basic.gql +1 -0
- package/tests/cases/integration/graphQlSchema/schema-bug-66.gql +1 -0
- package/tests/cases/integration/graphQlSchema/schema-column-types.gql +1 -0
- package/tests/cases/integration/graphQlSchema/schema-custom-primary.gql +1 -0
- package/tests/cases/integration/graphQlSchema/schema-has-many-reduction.gql +1 -0
- package/tests/cases/integration/graphQlSchema/schema-new-builder.gql +1 -0
- package/tests/cases/integration/graphQlSchema/schema-no-root-ops.gql +1 -0
- package/tests/cases/unit/predicatesInjector.test.ts +15 -67
- package/tests/src/test.ts +3 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Mutex.d.ts","sourceRoot":"","sources":["../../../src/utils/Mutex.ts"],"names":[],"mappings":"AAAA,qBAAa,KAAK;IACjB,OAAO,CAAC,SAAS,CAAqB;IAEtC,OAAO,CAAC,MAAM,CAAQ;IAET,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"Mutex.d.ts","sourceRoot":"","sources":["../../../src/utils/Mutex.ts"],"names":[],"mappings":"AAAA,qBAAa,KAAK;IACjB,OAAO,CAAC,SAAS,CAAqB;IAEtC,OAAO,CAAC,MAAM,CAAQ;IAET,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAO/C;IAED,OAAO,CAAC,IAAI;IAQZ,OAAO,CAAC,OAAO;CAQf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ResolveInfoUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/ResolveInfoUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,gBAAgB,EAAE,kBAAkB,EAAoB,MAAM,SAAS,CAAA;AAE7F,qBAAa,gBAAgB;
|
|
1
|
+
{"version":3,"file":"ResolveInfoUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/ResolveInfoUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,gBAAgB,EAAE,kBAAkB,EAAoB,MAAM,SAAS,CAAA;AAE7F,qBAAa,gBAAgB;IAC5B,OAAc,gBAAgB,CAAC,IAAI,EAAE,kBAAkB,GAAG,gBAAgB,CAWzE;IAED,OAAO,CAAC,MAAM,CAAC,eAAe;CAY9B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accessor.d.ts","sourceRoot":"","sources":["../../../src/utils/accessor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE1C,qBAAa,QAAQ,CAAC,CAAC;IACtB,OAAO,CAAC,GAAG,CAAe;IAE1B,GAAG,IAAI,SAAS,CAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"accessor.d.ts","sourceRoot":"","sources":["../../../src/utils/accessor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE1C,qBAAa,QAAQ,CAAC,CAAC;IACtB,OAAO,CAAC,GAAG,CAAe;IAE1B,GAAG,IAAI,SAAS,CAAC,CAAC,CAAC,CAMlB;IAED,GAAG,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAE3B;CACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isIt.d.ts","sourceRoot":"","sources":["../../../src/utils/isIt.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI,GAAI,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,CAAC,GAAG,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"isIt.d.ts","sourceRoot":"","sources":["../../../src/utils/isIt.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI,GAAI,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,CAAC,GAAG,MAAM,CAAC,OAAO,GAAG,YAAY,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,KAAG,GAAG,IAAI,CAKhH,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paginationUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/paginationUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;AACxD,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAEzC,qBAAa,gBAAgB;aAEX,aAAa,EAAE,UAAU,GAAG,SAAS;aACrC,SAAS,EAAE,UAAU,GAAG,SAAS;
|
|
1
|
+
{"version":3,"file":"paginationUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/paginationUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;AACxD,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAEzC,qBAAa,gBAAgB;aAEX,aAAa,EAAE,UAAU,GAAG,SAAS;aACrC,SAAS,EAAE,UAAU,GAAG,SAAS;IAFlD,YACiB,aAAa,EAAE,UAAU,GAAG,SAAS,EACrC,SAAS,EAAE,UAAU,GAAG,SAAS,EAC9C;IAEJ,IAAI,kBAAkB,YAErB;IAED,IAAI,aAAa,YAEhB;IAEM,cAAc,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,GAAG,CAa7E;CACD;AACD,eAAO,MAAM,sBAAsB,aAAc,UAAU,CAAC,KAAK,CAAC,oBAAoB,CAAC,qBAmBtF,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promises.d.ts","sourceRoot":"","sources":["../../../src/utils/promises.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,
|
|
1
|
+
{"version":3,"file":"promises.d.ts","sourceRoot":"","sources":["../../../src/utils/promises.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,YAAa,oBAAoB,CAAC,GAAG,CAAC,EAAE,KAAG,GAAG,EAEvE,CAAA;AAED,eAAO,MAAM,kBAAkB,GAAI,CAAC,WAAW,oBAAoB,CAAC,CAAC,CAAC,EAAE,KAAG,CAAC,EAE3E,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"singletonFactory.d.ts","sourceRoot":"","sources":["../../../src/utils/singletonFactory.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,gBAAgB,GAAI,CAAC,EAAE,EAAE,GAAG,MAAM,EAAE,IAAI,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"singletonFactory.d.ts","sourceRoot":"","sources":["../../../src/utils/singletonFactory.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,gBAAgB,GAAI,CAAC,EAAE,EAAE,GAAG,MAAM,EAAE,IAAI,GAAG,SAAS,MAAM,CAAC,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,KAAK,CAAC,YAGjF,EAAE,SAAS,IAAI,KAAG,CAkBhC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"strings.d.ts","sourceRoot":"","sources":["../../../src/utils/strings.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,qBAAqB,
|
|
1
|
+
{"version":3,"file":"strings.d.ts","sourceRoot":"","sources":["../../../src/utils/strings.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,qBAAqB,UAAW,MAAM,WAE3C,CAAA;AAED,OAAO,EAAE,qBAAqB,EAAE,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tuple.d.ts","sourceRoot":"","sources":["../../../src/utils/tuple.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,KAAK,GAAI,CAAC,SAAS,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"tuple.d.ts","sourceRoot":"","sources":["../../../src/utils/tuple.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,KAAK,GAAI,CAAC,SAAS,OAAO,EAAE,WAAW,CAAC,MAAS,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uniqueWhereFields.d.ts","sourceRoot":"","sources":["../../../src/utils/uniqueWhereFields.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAEzC,KAAK,YAAY,GAAG,SAAS,MAAM,EAAE,CAAA;AACrC,eAAO,MAAM,uBAAuB,
|
|
1
|
+
{"version":3,"file":"uniqueWhereFields.d.ts","sourceRoot":"","sources":["../../../src/utils/uniqueWhereFields.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAEzC,KAAK,YAAY,GAAG,SAAS,MAAM,EAAE,CAAA;AACrC,eAAO,MAAM,uBAAuB,WAAY,KAAK,CAAC,MAAM,UAAU,KAAK,CAAC,MAAM,KAAG,SAAS,CAAC,YAAY,CAAC,EAc3G,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"viewComputedId.d.ts","sourceRoot":"","sources":["../../../src/utils/viewComputedId.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,cAAc,
|
|
1
|
+
{"version":3,"file":"viewComputedId.d.ts","sourceRoot":"","sources":["../../../src/utils/viewComputedId.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,cAAc,WAAY,CAAC,MAAM,CAAC,EAAE,KAAG,MAWnD,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contember/engine-content-api",
|
|
3
|
-
"version": "2.2.0-alpha.
|
|
3
|
+
"version": "2.2.0-alpha.11",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "./dist/production/index.js",
|
|
6
6
|
"typings": "./dist/types/index.d.ts",
|
|
@@ -26,17 +26,17 @@
|
|
|
26
26
|
"generate": "gql-gen --config graphql.codegen.yml"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@contember/database": "2.
|
|
30
|
-
"@contember/dic": "2.
|
|
31
|
-
"@contember/graphql-utils": "2.
|
|
32
|
-
"@contember/logger": "2.
|
|
33
|
-
"@contember/schema": "2.
|
|
34
|
-
"@contember/schema-definition": "2.
|
|
35
|
-
"@contember/schema-utils": "2.
|
|
29
|
+
"@contember/database": "2.2.0-alpha.11",
|
|
30
|
+
"@contember/dic": "2.2.0-alpha.11",
|
|
31
|
+
"@contember/graphql-utils": "2.2.0-alpha.11",
|
|
32
|
+
"@contember/logger": "2.2.0-alpha.11",
|
|
33
|
+
"@contember/schema": "2.2.0-alpha.11",
|
|
34
|
+
"@contember/schema-definition": "2.2.0-alpha.11",
|
|
35
|
+
"@contember/schema-utils": "2.2.0-alpha.11",
|
|
36
36
|
"fast-deep-equal": "^3.1.3"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@contember/database-tester": "2.
|
|
39
|
+
"@contember/database-tester": "2.2.0-alpha.11",
|
|
40
40
|
"@types/node": "^24.12.0",
|
|
41
41
|
"graphql": "^16.13.1",
|
|
42
42
|
"pg": "^8.20.0"
|
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
} from './mapper/index.js'
|
|
28
28
|
import { Builder } from '@contember/dic'
|
|
29
29
|
import { Acl, Model, Schema } from '@contember/schema'
|
|
30
|
-
import { Client, DatabaseMetadata, SelectBuilder as DbSelectBuilder } from '@contember/database'
|
|
30
|
+
import { Client, DatabaseMetadata, RequestMemoryBudget, SelectBuilder as DbSelectBuilder } from '@contember/database'
|
|
31
31
|
import { ParsedMembership, Providers } from '@contember/schema-utils'
|
|
32
32
|
import { PaginatedHasManyExecutionHandler } from './extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.js'
|
|
33
33
|
import { PaginatedHasManyFieldProvider } from './extensions/paginatedHasMany/PaginatedHasManyFieldProvider.js'
|
|
@@ -75,6 +75,7 @@ export type ExecutionContainerArgs = {
|
|
|
75
75
|
schemaMeta: { id?: number }
|
|
76
76
|
schemaDatabaseMetadata: DatabaseMetadata
|
|
77
77
|
db: Client
|
|
78
|
+
memoryBudget?: RequestMemoryBudget
|
|
78
79
|
identityId: string
|
|
79
80
|
identityVariables: Acl.VariablesMap
|
|
80
81
|
permissions: Acl.Permissions
|
|
@@ -117,6 +118,7 @@ export class ExecutionContainerFactory {
|
|
|
117
118
|
identityVariables,
|
|
118
119
|
identityId,
|
|
119
120
|
db,
|
|
121
|
+
memoryBudget,
|
|
120
122
|
schema,
|
|
121
123
|
schemaMeta,
|
|
122
124
|
systemSchema,
|
|
@@ -128,7 +130,8 @@ export class ExecutionContainerFactory {
|
|
|
128
130
|
) {
|
|
129
131
|
return new Builder({})
|
|
130
132
|
.addService('systemSchema', () => systemSchema)
|
|
131
|
-
|
|
133
|
+
// Every query of the request is refused once the budget is exhausted; only selections charge it (Mapper.selectionDb).
|
|
134
|
+
.addService('db', () => memoryBudget ? db.withMemoryBudget(memoryBudget, { chargeRows: false }) : db)
|
|
132
135
|
.addService('project', () => project)
|
|
133
136
|
.addService('stage', () => stage)
|
|
134
137
|
.addService('triggeredActionsCollector', (): TriggeredActionsCollector | undefined =>
|
|
@@ -246,6 +249,7 @@ export class ExecutionContainerFactory {
|
|
|
246
249
|
providers,
|
|
247
250
|
schema,
|
|
248
251
|
schemaDatabaseMetadata,
|
|
252
|
+
db,
|
|
249
253
|
}) => {
|
|
250
254
|
return new MapperFactory(
|
|
251
255
|
db,
|
|
@@ -262,6 +266,7 @@ export class ExecutionContainerFactory {
|
|
|
262
266
|
inserter,
|
|
263
267
|
pathFactory,
|
|
264
268
|
providers,
|
|
269
|
+
memoryBudget,
|
|
265
270
|
)
|
|
266
271
|
},
|
|
267
272
|
)
|
|
@@ -57,15 +57,7 @@ export class PredicatesInjector {
|
|
|
57
57
|
if (shouldSimplify) {
|
|
58
58
|
predicatesWhere = { [entity.primary]: { always: true } }
|
|
59
59
|
} else {
|
|
60
|
-
|
|
61
|
-
// Process the predicate to inject nested entity predicates
|
|
62
|
-
predicatesWhere = this.injectPredicatesToPredicate(
|
|
63
|
-
rawPredicate,
|
|
64
|
-
entity,
|
|
65
|
-
isBackReferenceContext ?? false,
|
|
66
|
-
ancestorPath ?? [],
|
|
67
|
-
isQueryRoot,
|
|
68
|
-
)
|
|
60
|
+
predicatesWhere = this.predicateFactory.create(entity, Acl.Operation.read, fieldNames, relationContext, isQueryRoot)
|
|
69
61
|
}
|
|
70
62
|
|
|
71
63
|
const and = [where, predicatesWhere].filter(it => Object.keys(it).length > 0)
|
|
@@ -78,101 +70,6 @@ export class PredicatesInjector {
|
|
|
78
70
|
return { and: and }
|
|
79
71
|
}
|
|
80
72
|
|
|
81
|
-
/**
|
|
82
|
-
* Processes a predicate and injects nested entity predicates for any relation traversals.
|
|
83
|
-
* This ensures that when a predicate like { department: { company: { name: 'Acme' } } }
|
|
84
|
-
* is used, the predicates of Department and Company are also applied.
|
|
85
|
-
*/
|
|
86
|
-
private injectPredicatesToPredicate(
|
|
87
|
-
where: Input.OptionalWhere,
|
|
88
|
-
entity: Model.Entity,
|
|
89
|
-
isBackReferenceContext: boolean,
|
|
90
|
-
ancestorPath: readonly Model.AnyRelationContext[],
|
|
91
|
-
isQueryRoot?: boolean,
|
|
92
|
-
): Input.OptionalWhere {
|
|
93
|
-
const resultWhere: Writable<Input.OptionalWhere> = {}
|
|
94
|
-
|
|
95
|
-
if (where.and) {
|
|
96
|
-
resultWhere.and = where.and
|
|
97
|
-
.filter((it): it is Input.Where => !!it)
|
|
98
|
-
.map(it => this.injectPredicatesToPredicate(it, entity, isBackReferenceContext, ancestorPath, isQueryRoot))
|
|
99
|
-
}
|
|
100
|
-
if (where.or) {
|
|
101
|
-
resultWhere.or = where.or
|
|
102
|
-
.filter((it): it is Input.Where => !!it)
|
|
103
|
-
.map(it => this.injectPredicatesToPredicate(it, entity, isBackReferenceContext, ancestorPath, isQueryRoot))
|
|
104
|
-
}
|
|
105
|
-
if (where.not) {
|
|
106
|
-
resultWhere.not = this.injectPredicatesToPredicate(where.not, entity, isBackReferenceContext, ancestorPath, isQueryRoot)
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const fields = Object.keys(where).filter(it => !['and', 'or', 'not'].includes(it))
|
|
110
|
-
|
|
111
|
-
for (const field of fields) {
|
|
112
|
-
resultWhere[field] = acceptFieldVisitor(this.schema, entity, field, {
|
|
113
|
-
visitColumn: () => where[field],
|
|
114
|
-
visitRelation: context => {
|
|
115
|
-
const relationWhere = where[field] as Input.OptionalWhere | null
|
|
116
|
-
if (relationWhere === null) {
|
|
117
|
-
return null
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// Check if this relation is a back-reference to somewhere in our ancestor path
|
|
121
|
-
const isBackReference = this.findBackReferencedAncestor(
|
|
122
|
-
ancestorPath,
|
|
123
|
-
context.relation.name,
|
|
124
|
-
context.entity.name,
|
|
125
|
-
) !== undefined
|
|
126
|
-
const nestedIsBackReferenceContext = isBackReference || isBackReferenceContext
|
|
127
|
-
const nestedAncestorPath: readonly Model.AnyRelationContext[] = [...ancestorPath, context]
|
|
128
|
-
|
|
129
|
-
// Recursively process the nested where (always do this to handle deeper nesting)
|
|
130
|
-
const processedNestedWhere = this.injectPredicatesToPredicate(
|
|
131
|
-
relationWhere,
|
|
132
|
-
context.targetEntity,
|
|
133
|
-
nestedIsBackReferenceContext,
|
|
134
|
-
nestedAncestorPath,
|
|
135
|
-
isQueryRoot,
|
|
136
|
-
)
|
|
137
|
-
|
|
138
|
-
// Check if we should simplify the target entity's predicate
|
|
139
|
-
const shouldSimplifyNested = nestedIsBackReferenceContext
|
|
140
|
-
&& this.findBackReferencedAncestor(nestedAncestorPath, context.relation.name, context.entity.name) !== undefined
|
|
141
|
-
|
|
142
|
-
// Get target entity's predicate (simplified if back-reference)
|
|
143
|
-
const targetPredicate = shouldSimplifyNested
|
|
144
|
-
? { [context.targetEntity.primary]: { always: true } }
|
|
145
|
-
: this.predicateFactory.create(context.targetEntity, Acl.Operation.read, undefined, context, isQueryRoot)
|
|
146
|
-
|
|
147
|
-
// Optimization: avoid duplicate { id: always } when both are simplified
|
|
148
|
-
const primaryKey = context.targetEntity.primary
|
|
149
|
-
const nestedIsAlwaysTrue = Object.keys(processedNestedWhere).length === 1
|
|
150
|
-
&& (processedNestedWhere as Record<string, unknown>)[primaryKey] !== undefined
|
|
151
|
-
&& (processedNestedWhere as Record<string, Record<string, unknown>>)[primaryKey]?.always === true
|
|
152
|
-
const targetIsAlwaysTrue = Object.keys(targetPredicate).length === 1
|
|
153
|
-
&& (targetPredicate as Record<string, unknown>)[primaryKey] !== undefined
|
|
154
|
-
&& (targetPredicate as Record<string, Record<string, unknown>>)[primaryKey]?.always === true
|
|
155
|
-
|
|
156
|
-
if (nestedIsAlwaysTrue && targetIsAlwaysTrue) {
|
|
157
|
-
return processedNestedWhere
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// Combine the processed nested where with target entity's predicate
|
|
161
|
-
const parts = [processedNestedWhere, targetPredicate].filter(it => Object.keys(it).length > 0)
|
|
162
|
-
if (parts.length === 0) {
|
|
163
|
-
return {}
|
|
164
|
-
}
|
|
165
|
-
if (parts.length === 1) {
|
|
166
|
-
return parts[0]
|
|
167
|
-
}
|
|
168
|
-
return { and: parts }
|
|
169
|
-
},
|
|
170
|
-
})
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
return resultWhere
|
|
174
|
-
}
|
|
175
|
-
|
|
176
73
|
private injectToWhere(
|
|
177
74
|
where: Input.OptionalWhere,
|
|
178
75
|
entity: Model.Entity,
|
package/src/mapper/Mapper.ts
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
SelectResultObject,
|
|
11
11
|
WhereBuilder,
|
|
12
12
|
} from './select/index.js'
|
|
13
|
-
import { Client, Connection, ConstraintHelper, DatabaseMetadata, SelectBuilder } from '@contember/database'
|
|
13
|
+
import { Client, Connection, ConstraintHelper, DatabaseMetadata, RequestMemoryBudget, SelectBuilder } from '@contember/database'
|
|
14
14
|
import { PredicatesInjector } from '../acl/index.js'
|
|
15
15
|
import { JunctionTableManager } from './JunctionTableManager.js'
|
|
16
16
|
import { DeletedEntitiesStorage, DeleteExecutor } from './delete/index.js'
|
|
@@ -30,6 +30,8 @@ export class Mapper<ConnectionType extends Connection.ConnectionLike = Connectio
|
|
|
30
30
|
public readonly deletedEntities = new DeletedEntitiesStorage()
|
|
31
31
|
public readonly mutex = new Mutex()
|
|
32
32
|
public readonly constraintHelper: ConstraintHelper
|
|
33
|
+
/** Charges the request memory budget; only selection results use it, internal mutation queries stay on `db`. */
|
|
34
|
+
public readonly selectionDb: Client<ConnectionType>
|
|
33
35
|
|
|
34
36
|
public readonly eventManager: EventManager
|
|
35
37
|
|
|
@@ -48,8 +50,10 @@ export class Mapper<ConnectionType extends Connection.ConnectionLike = Connectio
|
|
|
48
50
|
private readonly updater: Updater,
|
|
49
51
|
private readonly inserter: Inserter,
|
|
50
52
|
private readonly pathFactory: PathFactory,
|
|
53
|
+
private readonly memoryBudget?: RequestMemoryBudget,
|
|
51
54
|
) {
|
|
52
55
|
this.constraintHelper = new ConstraintHelper(db, this.schemaDatabaseMetadata)
|
|
56
|
+
this.selectionDb = memoryBudget ? db.withMemoryBudget(memoryBudget, { chargeRows: true }) : db
|
|
53
57
|
this.eventManager = new EventManager(this)
|
|
54
58
|
}
|
|
55
59
|
|
|
@@ -73,7 +77,7 @@ export class Mapper<ConnectionType extends Connection.ConnectionLike = Connectio
|
|
|
73
77
|
relationPath: Model.AnyRelationContext[],
|
|
74
78
|
indexBy: string,
|
|
75
79
|
): Promise<SelectIndexedResultObjects> {
|
|
76
|
-
const hydrator = new SelectHydrator()
|
|
80
|
+
const hydrator = new SelectHydrator(this.memoryBudget)
|
|
77
81
|
const path = this.pathFactory.create([])
|
|
78
82
|
const indexByAlias: string = path.for(indexBy).alias
|
|
79
83
|
const qb: SelectBuilder = SelectBuilder.create()
|
|
@@ -87,7 +91,7 @@ export class Mapper<ConnectionType extends Connection.ConnectionLike = Connectio
|
|
|
87
91
|
input: ObjectNode<Input.ListQueryInput>,
|
|
88
92
|
relationPath: Model.AnyRelationContext[],
|
|
89
93
|
): Promise<SelectResultObject[]> {
|
|
90
|
-
const hydrator = new SelectHydrator()
|
|
94
|
+
const hydrator = new SelectHydrator(this.memoryBudget)
|
|
91
95
|
const qb: SelectBuilder<SelectBuilder.Result> = SelectBuilder.create()
|
|
92
96
|
|
|
93
97
|
const rows = await this.selectRows(hydrator, qb, entity, input, relationPath)
|
|
@@ -115,7 +119,7 @@ export class Mapper<ConnectionType extends Connection.ConnectionLike = Connectio
|
|
|
115
119
|
relation: Model.JoiningColumnRelation & Model.AnyRelation,
|
|
116
120
|
relationPath: Model.AnyRelationContext[],
|
|
117
121
|
): Promise<SelectGroupedObjects> {
|
|
118
|
-
const hydrator = new SelectHydrator()
|
|
122
|
+
const hydrator = new SelectHydrator(this.memoryBudget)
|
|
119
123
|
const path = this.pathFactory.create([])
|
|
120
124
|
const groupingKey = '__grouping_key'
|
|
121
125
|
const qb: SelectBuilder = SelectBuilder.create()
|
|
@@ -147,7 +151,7 @@ export class Mapper<ConnectionType extends Connection.ConnectionLike = Connectio
|
|
|
147
151
|
)
|
|
148
152
|
const inputWithPredicates = inputWithOrder.withArg('filter', filterWithPredicates)
|
|
149
153
|
selector.select(this, entity, inputWithPredicates, path, groupBy)
|
|
150
|
-
return await selector.execute(this.
|
|
154
|
+
return await selector.execute(this.selectionDb)
|
|
151
155
|
}
|
|
152
156
|
|
|
153
157
|
public async count(entity: Model.Entity, filter: Input.OptionalWhere) {
|
|
@@ -6,7 +6,7 @@ import { DeleteExecutor } from './delete/index.js'
|
|
|
6
6
|
import { Updater } from './update/index.js'
|
|
7
7
|
import { Inserter } from './insert/index.js'
|
|
8
8
|
import { Model } from '@contember/schema'
|
|
9
|
-
import { Client, Connection, DatabaseMetadata } from '@contember/database'
|
|
9
|
+
import { Client, Connection, DatabaseMetadata, RequestMemoryBudget } from '@contember/database'
|
|
10
10
|
import { Mapper } from './Mapper.js'
|
|
11
11
|
import { Providers } from '@contember/schema-utils'
|
|
12
12
|
|
|
@@ -30,6 +30,7 @@ export class MapperFactory {
|
|
|
30
30
|
private readonly inserter: Inserter,
|
|
31
31
|
private readonly pathFactory: PathFactory,
|
|
32
32
|
private readonly providers: Providers,
|
|
33
|
+
private readonly memoryBudget?: RequestMemoryBudget,
|
|
33
34
|
) {
|
|
34
35
|
}
|
|
35
36
|
|
|
@@ -37,8 +38,10 @@ export class MapperFactory {
|
|
|
37
38
|
return this.createInternal(this.db)
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
public transaction<T>(cb: (mapper: Mapper<Connection.TransactionLike>) => Promise<T>): Promise<T> {
|
|
41
|
-
|
|
41
|
+
public async transaction<T>(cb: (mapper: Mapper<Connection.TransactionLike>) => Promise<T>): Promise<T> {
|
|
42
|
+
// Refused here as well as by the bound `db`, so an exhausted request stops before it queues for a pool connection.
|
|
43
|
+
this.memoryBudget?.check()
|
|
44
|
+
return await this.db.transaction(async trx => {
|
|
42
45
|
await trx.connection.query(Connection.REPEATABLE_READ)
|
|
43
46
|
const mapper = this.createInternal(trx)
|
|
44
47
|
return await cb(mapper)
|
|
@@ -61,6 +64,7 @@ export class MapperFactory {
|
|
|
61
64
|
this.updater,
|
|
62
65
|
this.inserter,
|
|
63
66
|
this.pathFactory,
|
|
67
|
+
this.memoryBudget,
|
|
64
68
|
)
|
|
65
69
|
this.hooks.forEach(it => it(mapper))
|
|
66
70
|
return mapper
|
|
@@ -81,6 +81,17 @@ export class ConditionBuilder {
|
|
|
81
81
|
null: (builder, value) => value ? builder.isNull(columnIdentifier) : builder.not(clause => clause.isNull(columnIdentifier)),
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+
// Dispatch through a generic helper so the key and the value stay correlated through a single
|
|
85
|
+
// type parameter K. Indexing `handler` with a union key would otherwise collapse the parameter
|
|
86
|
+
// type to `never`.
|
|
87
|
+
const apply = <K extends keyof Input.Condition<any>>(key: K): SqlConditionBuilder => {
|
|
88
|
+
const value = condition[key]
|
|
89
|
+
if (value === undefined) {
|
|
90
|
+
return builder
|
|
91
|
+
}
|
|
92
|
+
return handler[key](builder, value)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return apply(entries[0][0])
|
|
85
96
|
}
|
|
86
97
|
}
|
|
@@ -147,7 +147,7 @@ export class RelationFetcher {
|
|
|
147
147
|
const objectNode = OrderByHelper.appendDefaultOrderBy(relationContext.targetEntity, field, defaultOrderBy)
|
|
148
148
|
const { targetEntity, entity } = relationContext
|
|
149
149
|
const junctionValues = await this.fetchJunction(
|
|
150
|
-
mapper.
|
|
150
|
+
mapper.selectionDb,
|
|
151
151
|
owningRelation,
|
|
152
152
|
ids,
|
|
153
153
|
joiningColumns,
|
|
@@ -162,9 +162,7 @@ export class RelationFetcher {
|
|
|
162
162
|
|
|
163
163
|
const primaryField = new FieldNode(targetEntity.primary, targetEntity.primary, {})
|
|
164
164
|
const inverseJoiningColumn = joiningColumns.targetColumn.columnName
|
|
165
|
-
const inverseIds = junctionValues
|
|
166
|
-
.map(it => it[inverseJoiningColumn])
|
|
167
|
-
.filter((it, index, arr) => arr.indexOf(it) === index)
|
|
165
|
+
const inverseIds = [...new Set(junctionValues.map(it => it[inverseJoiningColumn]))]
|
|
168
166
|
|
|
169
167
|
const queryWithWhere = objectNode
|
|
170
168
|
.withArgs({
|
|
@@ -2,6 +2,7 @@ import { Path } from './Path.js'
|
|
|
2
2
|
import { Value } from '@contember/schema'
|
|
3
3
|
import { getFulfilledValues, getRejections } from '../../utils/index.js'
|
|
4
4
|
import { logger } from '@contember/logger'
|
|
5
|
+
import { RequestMemoryBudget, RequestMemoryBudgetExceededError } from '@contember/database'
|
|
5
6
|
|
|
6
7
|
type DataPromises = {
|
|
7
8
|
path: Path
|
|
@@ -27,6 +28,9 @@ type Column = {
|
|
|
27
28
|
export class SelectHydrator {
|
|
28
29
|
private columns: Column[] = []
|
|
29
30
|
private promises: DataPromises[] = []
|
|
31
|
+
private formattedDates = 0
|
|
32
|
+
|
|
33
|
+
constructor(private readonly memoryBudget?: RequestMemoryBudget) {}
|
|
30
34
|
|
|
31
35
|
public addColumn(path: Path, getValue: ColumnValueGetter) {
|
|
32
36
|
this.columns.push({ path, getValue })
|
|
@@ -42,15 +46,15 @@ export class SelectHydrator {
|
|
|
42
46
|
}
|
|
43
47
|
|
|
44
48
|
public async hydrateGroups(rows: SelectRow[], groupBy: string): Promise<SelectGroupedObjects> {
|
|
45
|
-
const
|
|
49
|
+
const hydrated = await this.hydrateRows(rows)
|
|
46
50
|
const result: SelectGroupedObjects = {}
|
|
47
|
-
|
|
51
|
+
rows.forEach((row, index) => {
|
|
48
52
|
const key = row[groupBy] as Value.PrimaryValue
|
|
49
53
|
if (!result[key]) {
|
|
50
54
|
result[key] = []
|
|
51
55
|
}
|
|
52
|
-
result[key].push(
|
|
53
|
-
}
|
|
56
|
+
result[key].push(hydrated[index])
|
|
57
|
+
})
|
|
54
58
|
return result
|
|
55
59
|
}
|
|
56
60
|
|
|
@@ -61,19 +65,25 @@ export class SelectHydrator {
|
|
|
61
65
|
rows: SelectRow[],
|
|
62
66
|
indexBy?: string,
|
|
63
67
|
): Promise<SelectResultObject[] | SelectIndexedResultObjects> {
|
|
64
|
-
const
|
|
68
|
+
const hydrated = await this.hydrateRows(rows)
|
|
65
69
|
if (indexBy) {
|
|
66
70
|
const result: SelectIndexedResultObjects = {}
|
|
67
|
-
|
|
68
|
-
result[row[indexBy] as Value.PrimaryValue] =
|
|
69
|
-
}
|
|
71
|
+
rows.forEach((row, index) => {
|
|
72
|
+
result[row[indexBy] as Value.PrimaryValue] = hydrated[index]
|
|
73
|
+
})
|
|
70
74
|
return result
|
|
71
75
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
76
|
+
return hydrated
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
private async hydrateRows(rows: SelectRow[]): Promise<SelectResultObject[]> {
|
|
80
|
+
const resolved = await this.resolveDataPromises()
|
|
81
|
+
this.chargeRows(rows.length, resolved.length)
|
|
82
|
+
this.formattedDates = 0
|
|
83
|
+
const hydrated = rows.map(row => this.hydrateRow(row, resolved))
|
|
84
|
+
// A formatted Date is a new string; their count is known only after the rows are built.
|
|
85
|
+
this.memoryBudget?.addHydrationBytes(this.formattedDates * 72)
|
|
86
|
+
return hydrated
|
|
77
87
|
}
|
|
78
88
|
|
|
79
89
|
private hydrateRow(row: SelectRow, resolvedData: ResolvedData[]): SelectResultObject {
|
|
@@ -109,9 +119,10 @@ export class SelectHydrator {
|
|
|
109
119
|
})))
|
|
110
120
|
const failures = getRejections(results)
|
|
111
121
|
if (failures.length > 0) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
122
|
+
// Budget exhaustion aborts every in-flight sibling query; those rejections are expected.
|
|
123
|
+
failures.slice(1)
|
|
124
|
+
.filter(e => !(e instanceof RequestMemoryBudgetExceededError))
|
|
125
|
+
.forEach(e => logger.error(e, { loc: 'SelectHydrator' }))
|
|
115
126
|
throw failures[0]
|
|
116
127
|
}
|
|
117
128
|
|
|
@@ -120,10 +131,26 @@ export class SelectHydrator {
|
|
|
120
131
|
|
|
121
132
|
private formatValue(value: any) {
|
|
122
133
|
if (value instanceof Date) {
|
|
134
|
+
this.formattedDates++
|
|
123
135
|
return value.toISOString()
|
|
124
136
|
}
|
|
125
137
|
return value
|
|
126
138
|
}
|
|
139
|
+
|
|
140
|
+
// The row shape is fixed by the columns, so all rows are charged at once, before any of them is allocated.
|
|
141
|
+
private chargeRows(rowCount: number, relationCount: number): void {
|
|
142
|
+
if (!this.memoryBudget || rowCount === 0) {
|
|
143
|
+
return
|
|
144
|
+
}
|
|
145
|
+
const nestedObjects = new Set<string>()
|
|
146
|
+
for (const { path } of this.columns) {
|
|
147
|
+
for (let depth = 1; depth < path.path.length; depth++) {
|
|
148
|
+
nestedObjects.add(path.path.slice(0, depth).join('.'))
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
const rowBytes = 40 + this.columns.length * 16 + nestedObjects.size * 48 + relationCount * 16
|
|
152
|
+
this.memoryBudget.addHydrationBytes(rowCount * rowBytes)
|
|
153
|
+
}
|
|
127
154
|
}
|
|
128
155
|
|
|
129
156
|
export type SelectRow = { [key: string]: Value.FieldValue }
|
|
@@ -17,7 +17,7 @@ import { ValidationResolver } from './ValidationResolver.js'
|
|
|
17
17
|
import { GraphQLResolveInfo } from 'graphql'
|
|
18
18
|
import { GraphQlQueryAstFactory } from './GraphQlQueryAstFactory.js'
|
|
19
19
|
import { ImplementationException } from '../exception.js'
|
|
20
|
-
import { DatabaseMetadata, retryTransaction } from '@contember/database'
|
|
20
|
+
import { DatabaseMetadata, RequestMemoryBudgetExceededError, retryTransaction } from '@contember/database'
|
|
21
21
|
import { Operation, readOperationMeta } from '../schema/index.js'
|
|
22
22
|
import { assertNever } from '../utils/index.js'
|
|
23
23
|
import { InputPreValidator } from '../input-validation/index.js'
|
|
@@ -27,6 +27,13 @@ import { logger } from '@contember/logger'
|
|
|
27
27
|
|
|
28
28
|
type WithoutNode<T extends { node: any }> = Pick<T, Exclude<keyof T, 'node'>>
|
|
29
29
|
|
|
30
|
+
type MemoryBudgetFailure = {
|
|
31
|
+
ok: false
|
|
32
|
+
validation: Result.ValidationResult
|
|
33
|
+
errors: Result.ExecutionError[]
|
|
34
|
+
errorMessage: string
|
|
35
|
+
}
|
|
36
|
+
|
|
30
37
|
type TransactionOptions = {
|
|
31
38
|
deferForeignKeyConstraints?: boolean
|
|
32
39
|
deferUniqueConstraints?: boolean
|
|
@@ -52,6 +59,7 @@ export class MutationResolver {
|
|
|
52
59
|
)
|
|
53
60
|
})
|
|
54
61
|
const fields = GraphQlQueryAstFactory.resolveObjectType(info.returnType).getFields()
|
|
62
|
+
const mutationFields = queryAst.fields.filter(field => field.name !== 'query' && field.name !== '__typename')
|
|
55
63
|
|
|
56
64
|
const prefixErrors = <T extends { path: Result.PathFragment[]; paths?: Result.PathFragment[][] }>(
|
|
57
65
|
errors: T[],
|
|
@@ -211,7 +219,12 @@ export class MutationResolver {
|
|
|
211
219
|
validation: { valid: true, errors: [] },
|
|
212
220
|
...trxResult,
|
|
213
221
|
}
|
|
214
|
-
}
|
|
222
|
+
}, failure => ({
|
|
223
|
+
__typename: 'MutationTransaction',
|
|
224
|
+
...failure,
|
|
225
|
+
// Every mutation field of the transaction is non-null; each one reports the failure of the whole.
|
|
226
|
+
...Object.fromEntries(mutationFields.map(field => [field.alias, { ...failure, node: null }])),
|
|
227
|
+
}))
|
|
215
228
|
}
|
|
216
229
|
|
|
217
230
|
public async resolveUpdate(
|
|
@@ -466,43 +479,53 @@ export class MutationResolver {
|
|
|
466
479
|
|
|
467
480
|
private async transaction<R extends { ok: boolean }>(
|
|
468
481
|
cb: (mapper: Mapper) => Promise<R>,
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
logger.debug('MutationResolver: Transaction ok, committing')
|
|
482
|
-
await mapper.db.connection.commit()
|
|
483
|
-
await mapper.eventManager.fire(new AfterCommitEvent())
|
|
484
|
-
} catch (e) {
|
|
482
|
+
onMemoryBudgetExceeded: (failure: MemoryBudgetFailure) => R | MemoryBudgetFailure = failure => failure,
|
|
483
|
+
): Promise<R | MemoryBudgetFailure> {
|
|
484
|
+
try {
|
|
485
|
+
return await retryTransaction(
|
|
486
|
+
async () => {
|
|
487
|
+
return await this.mapperFactory.transaction(async mapper => {
|
|
488
|
+
logger.debug('MutationResolver: Starting mutation transaction')
|
|
489
|
+
const result = await cb(mapper)
|
|
490
|
+
if (!result.ok) {
|
|
491
|
+
logger.debug('MutationResolver: Transaction failed, rolling back', { result })
|
|
492
|
+
await mapper.db.connection.rollback()
|
|
493
|
+
} else {
|
|
485
494
|
try {
|
|
486
|
-
await mapper.
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
495
|
+
await mapper.eventManager.fire(new BeforeCommitEvent())
|
|
496
|
+
logger.debug('MutationResolver: Transaction ok, committing')
|
|
497
|
+
await mapper.db.connection.commit()
|
|
498
|
+
await mapper.eventManager.fire(new AfterCommitEvent())
|
|
499
|
+
} catch (e) {
|
|
500
|
+
try {
|
|
501
|
+
await mapper.db.connection.rollback()
|
|
502
|
+
} catch {}
|
|
503
|
+
const err = convertError(this.schema, this.schemaDatabaseMetadata, e)
|
|
504
|
+
const errorResponse = this.createErrorResponse([err])
|
|
505
|
+
if (!errorResponse) {
|
|
506
|
+
throw new ImplementationException()
|
|
507
|
+
}
|
|
508
|
+
return { ...result, ...errorResponse }
|
|
492
509
|
}
|
|
493
|
-
return { ...result, ...errorResponse }
|
|
494
510
|
}
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
)
|
|
511
|
+
return result
|
|
512
|
+
})
|
|
513
|
+
},
|
|
514
|
+
message => logger.warn(message),
|
|
515
|
+
{
|
|
516
|
+
maxAttempts: 15,
|
|
517
|
+
minTimeout: 10,
|
|
518
|
+
maxTimeout: 1000,
|
|
519
|
+
},
|
|
520
|
+
)
|
|
521
|
+
} catch (e) {
|
|
522
|
+
if (!(e instanceof RequestMemoryBudgetExceededError)) {
|
|
523
|
+
throw e
|
|
524
|
+
}
|
|
525
|
+
// Already rolled back. Reported in data like any failed mutation, so results of sibling mutations survive.
|
|
526
|
+
const errors = [{ path: [], paths: [], type: Result.ExecutionErrorType.ResourceExhausted, message: e.message }]
|
|
527
|
+
return onMemoryBudgetExceeded({ ok: false, validation: { valid: true, errors: [] }, errors, errorMessage: e.message })
|
|
528
|
+
}
|
|
506
529
|
}
|
|
507
530
|
|
|
508
531
|
private createErrorResponse(result: MutationResultList) {
|