@contember/engine-content-api 2.2.0-alpha.18 → 2.2.0-alpha.19
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/dist/development/index.cjs +3 -0
- package/dist/development/index.cjs.map +1 -1
- package/dist/development/index.js +4 -1
- package/dist/development/index.js.map +1 -1
- package/dist/development/src/ExecutionContainer.cjs +1 -0
- package/dist/development/src/ExecutionContainer.cjs.map +1 -1
- package/dist/development/src/ExecutionContainer.js +1 -0
- package/dist/development/src/ExecutionContainer.js.map +1 -1
- package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.cjs +2 -1
- package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.cjs.map +1 -1
- package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.js +2 -1
- package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.js.map +1 -1
- package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.cjs +5 -1
- package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.cjs.map +1 -1
- package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.js +5 -1
- package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.js.map +1 -1
- package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.cjs +2 -1
- package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.cjs.map +1 -1
- package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.js +2 -1
- package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.js.map +1 -1
- package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.cjs +4 -1
- package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.cjs.map +1 -1
- package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.js +4 -1
- package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.js.map +1 -1
- package/dist/development/src/input-validation/preValidation/UpdateInputPreValidationProcessor.cjs +24 -3
- package/dist/development/src/input-validation/preValidation/UpdateInputPreValidationProcessor.cjs.map +1 -1
- package/dist/development/src/input-validation/preValidation/UpdateInputPreValidationProcessor.js +24 -3
- package/dist/development/src/input-validation/preValidation/UpdateInputPreValidationProcessor.js.map +1 -1
- package/dist/development/src/inputProcessing/UpdateInputVisitor.cjs +52 -2
- package/dist/development/src/inputProcessing/UpdateInputVisitor.cjs.map +1 -1
- package/dist/development/src/inputProcessing/UpdateInputVisitor.js +52 -2
- package/dist/development/src/inputProcessing/UpdateInputVisitor.js.map +1 -1
- package/dist/development/src/mapper/ErrorUtils.cjs +10 -0
- package/dist/development/src/mapper/ErrorUtils.cjs.map +1 -1
- package/dist/development/src/mapper/ErrorUtils.js +10 -0
- package/dist/development/src/mapper/ErrorUtils.js.map +1 -1
- package/dist/development/src/mapper/Mapper.cjs +37 -1
- package/dist/development/src/mapper/Mapper.cjs.map +1 -1
- package/dist/development/src/mapper/Mapper.js +38 -2
- package/dist/development/src/mapper/Mapper.js.map +1 -1
- package/dist/development/src/mapper/MutationProcessorHelper.cjs +12 -0
- package/dist/development/src/mapper/MutationProcessorHelper.cjs.map +1 -1
- package/dist/development/src/mapper/MutationProcessorHelper.js +13 -1
- package/dist/development/src/mapper/MutationProcessorHelper.js.map +1 -1
- package/dist/development/src/mapper/Result.cjs +1 -0
- package/dist/development/src/mapper/Result.cjs.map +1 -1
- package/dist/development/src/mapper/Result.js +1 -0
- package/dist/development/src/mapper/Result.js.map +1 -1
- package/dist/development/src/mapper/delete/DeleteExecutor.cjs +1 -1
- package/dist/development/src/mapper/delete/DeleteExecutor.js +1 -1
- package/dist/development/src/mapper/select/handlers/MetaHandler.cjs +1 -1
- package/dist/development/src/mapper/select/handlers/MetaHandler.js +1 -1
- package/dist/development/src/mapper/select/optimizer/WhereOptimizer.cjs +2 -2
- package/dist/development/src/mapper/select/optimizer/WhereOptimizer.cjs.map +1 -1
- package/dist/development/src/mapper/select/optimizer/WhereOptimizer.js +1 -1
- package/dist/development/src/mapper/select/optimizer/WhereOptimizer.js.map +1 -1
- package/dist/development/src/mapper/select/optimizer/WhereReplacer.cjs +3 -3
- package/dist/development/src/mapper/select/optimizer/WhereReplacer.cjs.map +1 -1
- package/dist/development/src/mapper/select/optimizer/WhereReplacer.js +1 -1
- package/dist/development/src/mapper/select/optimizer/WhereReplacer.js.map +1 -1
- package/dist/development/src/mapper/update/SqlUpdateInputProcessor.cjs +6 -3
- package/dist/development/src/mapper/update/SqlUpdateInputProcessor.cjs.map +1 -1
- package/dist/development/src/mapper/update/SqlUpdateInputProcessor.js +7 -4
- package/dist/development/src/mapper/update/SqlUpdateInputProcessor.js.map +1 -1
- package/dist/development/src/mapper/update/Updater.cjs +1 -1
- package/dist/development/src/mapper/update/Updater.js +1 -1
- package/dist/development/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.cjs +6 -0
- package/dist/development/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.cjs.map +1 -1
- package/dist/development/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.js +6 -0
- package/dist/development/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.js.map +1 -1
- package/dist/development/src/mapper/update/relations/OneHasManyUpdateInputProcessor.cjs +6 -0
- package/dist/development/src/mapper/update/relations/OneHasManyUpdateInputProcessor.cjs.map +1 -1
- package/dist/development/src/mapper/update/relations/OneHasManyUpdateInputProcessor.js +6 -0
- package/dist/development/src/mapper/update/relations/OneHasManyUpdateInputProcessor.js.map +1 -1
- package/dist/development/src/mapper/update/relations/SetManyRelationHelper.cjs +123 -0
- package/dist/development/src/mapper/update/relations/SetManyRelationHelper.cjs.map +1 -0
- package/dist/development/src/mapper/update/relations/SetManyRelationHelper.js +123 -0
- package/dist/development/src/mapper/update/relations/SetManyRelationHelper.js.map +1 -0
- package/dist/development/src/resolvers/MutationResolver.cjs +4 -1
- package/dist/development/src/resolvers/MutationResolver.cjs.map +1 -1
- package/dist/development/src/resolvers/MutationResolver.js +4 -1
- package/dist/development/src/resolvers/MutationResolver.js.map +1 -1
- package/dist/development/src/resolvers/ReadHelpers.cjs +2 -1
- package/dist/development/src/resolvers/ReadHelpers.cjs.map +1 -1
- package/dist/development/src/resolvers/ReadHelpers.js +2 -1
- package/dist/development/src/resolvers/ReadHelpers.js.map +1 -1
- package/dist/development/src/schema/CustomTypesProvider.cjs +35 -14
- package/dist/development/src/schema/CustomTypesProvider.cjs.map +1 -1
- package/dist/development/src/schema/CustomTypesProvider.js +36 -15
- package/dist/development/src/schema/CustomTypesProvider.js.map +1 -1
- package/dist/development/src/schema/EntityTypeProvider.cjs +8 -5
- package/dist/development/src/schema/EntityTypeProvider.cjs.map +1 -1
- package/dist/development/src/schema/EntityTypeProvider.js +8 -5
- package/dist/development/src/schema/EntityTypeProvider.js.map +1 -1
- package/dist/development/src/schema/GraphQlSchemaBuilderFactory.cjs +1 -1
- package/dist/development/src/schema/GraphQlSchemaBuilderFactory.js +1 -1
- package/dist/development/src/schema/MutationProvider.cjs +4 -0
- package/dist/development/src/schema/MutationProvider.cjs.map +1 -1
- package/dist/development/src/schema/MutationProvider.js +4 -0
- package/dist/development/src/schema/MutationProvider.js.map +1 -1
- package/dist/development/src/schema/OrderByTypeProvider.cjs +8 -2
- package/dist/development/src/schema/OrderByTypeProvider.cjs.map +1 -1
- package/dist/development/src/schema/OrderByTypeProvider.js +9 -3
- package/dist/development/src/schema/OrderByTypeProvider.js.map +1 -1
- package/dist/development/src/schema/QueryProvider.cjs +3 -0
- package/dist/development/src/schema/QueryProvider.cjs.map +1 -1
- package/dist/development/src/schema/QueryProvider.js +3 -0
- package/dist/development/src/schema/QueryProvider.js.map +1 -1
- package/dist/development/src/schema/ValidationQueriesProvider.cjs +2 -0
- package/dist/development/src/schema/ValidationQueriesProvider.cjs.map +1 -1
- package/dist/development/src/schema/ValidationQueriesProvider.js +2 -0
- package/dist/development/src/schema/ValidationQueriesProvider.js.map +1 -1
- package/dist/development/src/schema/WhereTypeProvider.cjs +17 -5
- package/dist/development/src/schema/WhereTypeProvider.cjs.map +1 -1
- package/dist/development/src/schema/WhereTypeProvider.js +18 -6
- package/dist/development/src/schema/WhereTypeProvider.js.map +1 -1
- package/dist/development/src/schema/calendarDate.cjs +21 -0
- package/dist/development/src/schema/calendarDate.cjs.map +1 -0
- package/dist/development/src/schema/calendarDate.js +21 -0
- package/dist/development/src/schema/calendarDate.js.map +1 -0
- package/dist/development/src/schema/mutations/CreateEntityInputFieldVisitor.cjs +11 -3
- package/dist/development/src/schema/mutations/CreateEntityInputFieldVisitor.cjs.map +1 -1
- package/dist/development/src/schema/mutations/CreateEntityInputFieldVisitor.js +11 -3
- package/dist/development/src/schema/mutations/CreateEntityInputFieldVisitor.js.map +1 -1
- package/dist/development/src/schema/mutations/UpdateEntityInputFieldVisitor.cjs +11 -3
- package/dist/development/src/schema/mutations/UpdateEntityInputFieldVisitor.cjs.map +1 -1
- package/dist/development/src/schema/mutations/UpdateEntityInputFieldVisitor.js +11 -3
- package/dist/development/src/schema/mutations/UpdateEntityInputFieldVisitor.js.map +1 -1
- package/dist/development/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.cjs +39 -2
- package/dist/development/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.cjs.map +1 -1
- package/dist/development/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.js +40 -3
- package/dist/development/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.js.map +1 -1
- package/dist/development/src/schema/utils.cjs +10 -0
- package/dist/development/src/schema/utils.cjs.map +1 -1
- package/dist/development/src/schema/utils.js +11 -1
- package/dist/development/src/schema/utils.js.map +1 -1
- package/dist/production/index.cjs +3 -0
- package/dist/production/index.cjs.map +1 -1
- package/dist/production/index.js +4 -1
- package/dist/production/index.js.map +1 -1
- package/dist/production/src/ExecutionContainer.cjs +1 -0
- package/dist/production/src/ExecutionContainer.cjs.map +1 -1
- package/dist/production/src/ExecutionContainer.js +1 -0
- package/dist/production/src/ExecutionContainer.js.map +1 -1
- package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.cjs +2 -1
- package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.cjs.map +1 -1
- package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.js +2 -1
- package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.js.map +1 -1
- package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.cjs +5 -1
- package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.cjs.map +1 -1
- package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.js +5 -1
- package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.js.map +1 -1
- package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.cjs +2 -1
- package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.cjs.map +1 -1
- package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.js +2 -1
- package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.js.map +1 -1
- package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.cjs +4 -1
- package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.cjs.map +1 -1
- package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.js +4 -1
- package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.js.map +1 -1
- package/dist/production/src/input-validation/preValidation/UpdateInputPreValidationProcessor.cjs +24 -3
- package/dist/production/src/input-validation/preValidation/UpdateInputPreValidationProcessor.cjs.map +1 -1
- package/dist/production/src/input-validation/preValidation/UpdateInputPreValidationProcessor.js +24 -3
- package/dist/production/src/input-validation/preValidation/UpdateInputPreValidationProcessor.js.map +1 -1
- package/dist/production/src/inputProcessing/UpdateInputVisitor.cjs +52 -2
- package/dist/production/src/inputProcessing/UpdateInputVisitor.cjs.map +1 -1
- package/dist/production/src/inputProcessing/UpdateInputVisitor.js +52 -2
- package/dist/production/src/inputProcessing/UpdateInputVisitor.js.map +1 -1
- package/dist/production/src/mapper/ErrorUtils.cjs +10 -0
- package/dist/production/src/mapper/ErrorUtils.cjs.map +1 -1
- package/dist/production/src/mapper/ErrorUtils.js +10 -0
- package/dist/production/src/mapper/ErrorUtils.js.map +1 -1
- package/dist/production/src/mapper/Mapper.cjs +37 -1
- package/dist/production/src/mapper/Mapper.cjs.map +1 -1
- package/dist/production/src/mapper/Mapper.js +38 -2
- package/dist/production/src/mapper/Mapper.js.map +1 -1
- package/dist/production/src/mapper/MutationProcessorHelper.cjs +12 -0
- package/dist/production/src/mapper/MutationProcessorHelper.cjs.map +1 -1
- package/dist/production/src/mapper/MutationProcessorHelper.js +13 -1
- package/dist/production/src/mapper/MutationProcessorHelper.js.map +1 -1
- package/dist/production/src/mapper/Result.cjs +1 -0
- package/dist/production/src/mapper/Result.cjs.map +1 -1
- package/dist/production/src/mapper/Result.js +1 -0
- package/dist/production/src/mapper/Result.js.map +1 -1
- package/dist/production/src/mapper/delete/DeleteExecutor.cjs +1 -1
- package/dist/production/src/mapper/delete/DeleteExecutor.js +1 -1
- package/dist/production/src/mapper/select/handlers/MetaHandler.cjs +1 -1
- package/dist/production/src/mapper/select/handlers/MetaHandler.js +1 -1
- package/dist/production/src/mapper/select/optimizer/WhereOptimizer.cjs +2 -2
- package/dist/production/src/mapper/select/optimizer/WhereOptimizer.cjs.map +1 -1
- package/dist/production/src/mapper/select/optimizer/WhereOptimizer.js +1 -1
- package/dist/production/src/mapper/select/optimizer/WhereOptimizer.js.map +1 -1
- package/dist/production/src/mapper/select/optimizer/WhereReplacer.cjs +3 -3
- package/dist/production/src/mapper/select/optimizer/WhereReplacer.cjs.map +1 -1
- package/dist/production/src/mapper/select/optimizer/WhereReplacer.js +1 -1
- package/dist/production/src/mapper/select/optimizer/WhereReplacer.js.map +1 -1
- package/dist/production/src/mapper/update/SqlUpdateInputProcessor.cjs +6 -3
- package/dist/production/src/mapper/update/SqlUpdateInputProcessor.cjs.map +1 -1
- package/dist/production/src/mapper/update/SqlUpdateInputProcessor.js +7 -4
- package/dist/production/src/mapper/update/SqlUpdateInputProcessor.js.map +1 -1
- package/dist/production/src/mapper/update/Updater.cjs +1 -1
- package/dist/production/src/mapper/update/Updater.js +1 -1
- package/dist/production/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.cjs +6 -0
- package/dist/production/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.cjs.map +1 -1
- package/dist/production/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.js +6 -0
- package/dist/production/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.js.map +1 -1
- package/dist/production/src/mapper/update/relations/OneHasManyUpdateInputProcessor.cjs +6 -0
- package/dist/production/src/mapper/update/relations/OneHasManyUpdateInputProcessor.cjs.map +1 -1
- package/dist/production/src/mapper/update/relations/OneHasManyUpdateInputProcessor.js +6 -0
- package/dist/production/src/mapper/update/relations/OneHasManyUpdateInputProcessor.js.map +1 -1
- package/dist/production/src/mapper/update/relations/SetManyRelationHelper.cjs +123 -0
- package/dist/production/src/mapper/update/relations/SetManyRelationHelper.cjs.map +1 -0
- package/dist/production/src/mapper/update/relations/SetManyRelationHelper.js +123 -0
- package/dist/production/src/mapper/update/relations/SetManyRelationHelper.js.map +1 -0
- package/dist/production/src/resolvers/MutationResolver.cjs +4 -1
- package/dist/production/src/resolvers/MutationResolver.cjs.map +1 -1
- package/dist/production/src/resolvers/MutationResolver.js +4 -1
- package/dist/production/src/resolvers/MutationResolver.js.map +1 -1
- package/dist/production/src/resolvers/ReadHelpers.cjs +2 -1
- package/dist/production/src/resolvers/ReadHelpers.cjs.map +1 -1
- package/dist/production/src/resolvers/ReadHelpers.js +2 -1
- package/dist/production/src/resolvers/ReadHelpers.js.map +1 -1
- package/dist/production/src/schema/CustomTypesProvider.cjs +35 -14
- package/dist/production/src/schema/CustomTypesProvider.cjs.map +1 -1
- package/dist/production/src/schema/CustomTypesProvider.js +36 -15
- package/dist/production/src/schema/CustomTypesProvider.js.map +1 -1
- package/dist/production/src/schema/EntityTypeProvider.cjs +8 -5
- package/dist/production/src/schema/EntityTypeProvider.cjs.map +1 -1
- package/dist/production/src/schema/EntityTypeProvider.js +8 -5
- package/dist/production/src/schema/EntityTypeProvider.js.map +1 -1
- package/dist/production/src/schema/GraphQlSchemaBuilderFactory.cjs +1 -1
- package/dist/production/src/schema/GraphQlSchemaBuilderFactory.js +1 -1
- package/dist/production/src/schema/MutationProvider.cjs +4 -0
- package/dist/production/src/schema/MutationProvider.cjs.map +1 -1
- package/dist/production/src/schema/MutationProvider.js +4 -0
- package/dist/production/src/schema/MutationProvider.js.map +1 -1
- package/dist/production/src/schema/OrderByTypeProvider.cjs +8 -2
- package/dist/production/src/schema/OrderByTypeProvider.cjs.map +1 -1
- package/dist/production/src/schema/OrderByTypeProvider.js +9 -3
- package/dist/production/src/schema/OrderByTypeProvider.js.map +1 -1
- package/dist/production/src/schema/QueryProvider.cjs +3 -0
- package/dist/production/src/schema/QueryProvider.cjs.map +1 -1
- package/dist/production/src/schema/QueryProvider.js +3 -0
- package/dist/production/src/schema/QueryProvider.js.map +1 -1
- package/dist/production/src/schema/ValidationQueriesProvider.cjs +2 -0
- package/dist/production/src/schema/ValidationQueriesProvider.cjs.map +1 -1
- package/dist/production/src/schema/ValidationQueriesProvider.js +2 -0
- package/dist/production/src/schema/ValidationQueriesProvider.js.map +1 -1
- package/dist/production/src/schema/WhereTypeProvider.cjs +17 -5
- package/dist/production/src/schema/WhereTypeProvider.cjs.map +1 -1
- package/dist/production/src/schema/WhereTypeProvider.js +18 -6
- package/dist/production/src/schema/WhereTypeProvider.js.map +1 -1
- package/dist/production/src/schema/calendarDate.cjs +21 -0
- package/dist/production/src/schema/calendarDate.cjs.map +1 -0
- package/dist/production/src/schema/calendarDate.js +21 -0
- package/dist/production/src/schema/calendarDate.js.map +1 -0
- package/dist/production/src/schema/mutations/CreateEntityInputFieldVisitor.cjs +11 -3
- package/dist/production/src/schema/mutations/CreateEntityInputFieldVisitor.cjs.map +1 -1
- package/dist/production/src/schema/mutations/CreateEntityInputFieldVisitor.js +11 -3
- package/dist/production/src/schema/mutations/CreateEntityInputFieldVisitor.js.map +1 -1
- package/dist/production/src/schema/mutations/UpdateEntityInputFieldVisitor.cjs +11 -3
- package/dist/production/src/schema/mutations/UpdateEntityInputFieldVisitor.cjs.map +1 -1
- package/dist/production/src/schema/mutations/UpdateEntityInputFieldVisitor.js +11 -3
- package/dist/production/src/schema/mutations/UpdateEntityInputFieldVisitor.js.map +1 -1
- package/dist/production/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.cjs +39 -2
- package/dist/production/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.cjs.map +1 -1
- package/dist/production/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.js +40 -3
- package/dist/production/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.js.map +1 -1
- package/dist/production/src/schema/utils.cjs +10 -0
- package/dist/production/src/schema/utils.cjs.map +1 -1
- package/dist/production/src/schema/utils.js +11 -1
- package/dist/production/src/schema/utils.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/update/manyHasManyInverse/set.test.d.ts +2 -0
- package/dist/tests/cases/integration/graphQlRequests/update/manyHasManyInverse/set.test.d.ts.map +1 -0
- package/dist/tests/cases/integration/graphQlRequests/update/manyHasManyOwning/set.test.d.ts +2 -0
- package/dist/tests/cases/integration/graphQlRequests/update/manyHasManyOwning/set.test.d.ts.map +1 -0
- package/dist/tests/cases/integration/graphQlRequests/update/oneHasMany/set.test.d.ts +2 -0
- package/dist/tests/cases/integration/graphQlRequests/update/oneHasMany/set.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/checkViolationError.test.d.ts +2 -0
- package/dist/tests/cases/unit/checkViolationError.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/dateType.test.d.ts +2 -0
- package/dist/tests/cases/unit/dateType.test.d.ts.map +1 -0
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/dist/types/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.d.ts.map +1 -1
- package/dist/types/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.d.ts.map +1 -1
- package/dist/types/input-validation/preValidation/UpdateInputPreValidationProcessor.d.ts +6 -0
- package/dist/types/input-validation/preValidation/UpdateInputPreValidationProcessor.d.ts.map +1 -1
- package/dist/types/inputProcessing/UpdateInputProcessor.d.ts +7 -0
- package/dist/types/inputProcessing/UpdateInputProcessor.d.ts.map +1 -1
- package/dist/types/inputProcessing/UpdateInputVisitor.d.ts +2 -0
- package/dist/types/inputProcessing/UpdateInputVisitor.d.ts.map +1 -1
- package/dist/types/mapper/ErrorUtils.d.ts.map +1 -1
- package/dist/types/mapper/Mapper.d.ts +5 -0
- package/dist/types/mapper/Mapper.d.ts.map +1 -1
- package/dist/types/mapper/MutationProcessorHelper.d.ts +3 -0
- package/dist/types/mapper/MutationProcessorHelper.d.ts.map +1 -1
- package/dist/types/mapper/Result.d.ts +2 -1
- package/dist/types/mapper/Result.d.ts.map +1 -1
- package/dist/types/mapper/types.d.ts +8 -1
- package/dist/types/mapper/types.d.ts.map +1 -1
- package/dist/types/mapper/update/SqlUpdateInputProcessor.d.ts.map +1 -1
- package/dist/types/mapper/update/relations/ManyHasManyUpdateInputProcessor.d.ts +5 -0
- package/dist/types/mapper/update/relations/ManyHasManyUpdateInputProcessor.d.ts.map +1 -1
- package/dist/types/mapper/update/relations/OneHasManyUpdateInputProcessor.d.ts +5 -0
- package/dist/types/mapper/update/relations/OneHasManyUpdateInputProcessor.d.ts.map +1 -1
- package/dist/types/mapper/update/relations/SetManyRelationHelper.d.ts +67 -0
- package/dist/types/mapper/update/relations/SetManyRelationHelper.d.ts.map +1 -0
- package/dist/types/resolvers/MutationResolver.d.ts.map +1 -1
- package/dist/types/schema/CustomTypesProvider.d.ts.map +1 -1
- package/dist/types/schema/EntityTypeProvider.d.ts.map +1 -1
- package/dist/types/schema/MutationProvider.d.ts.map +1 -1
- package/dist/types/schema/OrderByTypeProvider.d.ts.map +1 -1
- package/dist/types/schema/QueryProvider.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/calendarDate.d.ts +6 -0
- package/dist/types/schema/calendarDate.d.ts.map +1 -0
- package/dist/types/schema/index.d.ts +1 -0
- package/dist/types/schema/index.d.ts.map +1 -1
- package/dist/types/schema/mutations/CreateEntityInputFieldVisitor.d.ts.map +1 -1
- package/dist/types/schema/mutations/UpdateEntityInputFieldVisitor.d.ts +3 -0
- package/dist/types/schema/mutations/UpdateEntityInputFieldVisitor.d.ts.map +1 -1
- package/dist/types/schema/mutations/UpdateEntityRelationInputFieldVisitor.d.ts +1 -0
- package/dist/types/schema/mutations/UpdateEntityRelationInputFieldVisitor.d.ts.map +1 -1
- package/dist/types/schema/utils.d.ts +7 -0
- package/dist/types/schema/utils.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -10
- package/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.ts +3 -0
- package/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.ts +9 -7
- package/src/input-validation/preValidation/UpdateInputPreValidationProcessor.ts +29 -0
- package/src/inputProcessing/UpdateInputProcessor.ts +6 -0
- package/src/inputProcessing/UpdateInputVisitor.ts +64 -2
- package/src/mapper/ErrorUtils.ts +11 -0
- package/src/mapper/Mapper.ts +61 -1
- package/src/mapper/MutationProcessorHelper.ts +14 -0
- package/src/mapper/Result.ts +1 -0
- package/src/mapper/select/optimizer/WhereOptimizer.ts +1 -1
- package/src/mapper/select/optimizer/WhereReplacer.ts +1 -1
- package/src/mapper/types.ts +16 -1
- package/src/mapper/update/SqlUpdateInputProcessor.ts +4 -1
- package/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.ts +9 -0
- package/src/mapper/update/relations/OneHasManyUpdateInputProcessor.ts +9 -0
- package/src/mapper/update/relations/SetManyRelationHelper.ts +199 -0
- package/src/resolvers/MutationResolver.ts +2 -0
- package/src/schema/CustomTypesProvider.ts +40 -15
- package/src/schema/EntityTypeProvider.ts +8 -4
- package/src/schema/MutationProvider.ts +4 -0
- package/src/schema/OrderByTypeProvider.ts +9 -3
- package/src/schema/QueryProvider.ts +3 -0
- package/src/schema/ValidationQueriesProvider.ts +2 -0
- package/src/schema/WhereTypeProvider.ts +18 -6
- package/src/schema/calendarDate.ts +26 -0
- package/src/schema/index.ts +1 -0
- package/src/schema/mutations/CreateEntityInputFieldVisitor.ts +10 -2
- package/src/schema/mutations/UpdateEntityInputFieldVisitor.ts +10 -2
- package/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.ts +66 -7
- package/src/schema/utils.ts +14 -0
- package/src/tsconfig.json +2 -1
- package/tests/cases/integration/graphQlRequests/update/manyHasManyInverse/set.test.ts +219 -0
- package/tests/cases/integration/graphQlRequests/update/manyHasManyOwning/set.test.ts +479 -0
- package/tests/cases/integration/graphQlRequests/update/oneHasMany/set.test.ts +948 -0
- package/tests/cases/integration/graphQlSchema/graphQlSchemaBuilder.test.ts +102 -1
- package/tests/cases/integration/graphQlSchema/schema-acl-allowed.gql +17 -0
- package/tests/cases/integration/graphQlSchema/schema-acl-create-only.gql +1 -0
- package/tests/cases/integration/graphQlSchema/schema-acl-restricted-create.gql +14 -0
- package/tests/cases/integration/graphQlSchema/schema-acl-restricted-delete.gql +11 -0
- package/tests/cases/integration/graphQlSchema/schema-acl-restricted-read.gql +254 -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 +50 -0
- package/tests/cases/integration/graphQlSchema/schema-bug-66.gql +17 -0
- package/tests/cases/integration/graphQlSchema/schema-column-types.gql +1 -0
- package/tests/cases/integration/graphQlSchema/schema-custom-primary.gql +50 -0
- package/tests/cases/integration/graphQlSchema/schema-deprecation.gql +962 -0
- package/tests/cases/integration/graphQlSchema/schema-description.gql +992 -0
- package/tests/cases/integration/graphQlSchema/schema-has-many-reduction.gql +17 -0
- package/tests/cases/integration/graphQlSchema/schema-mixed-root-through.gql +1 -0
- package/tests/cases/integration/graphQlSchema/schema-new-builder.gql +50 -0
- package/tests/cases/integration/graphQlSchema/schema-no-root-ops.gql +1 -0
- package/tests/cases/unit/checkViolationError.test.ts +49 -0
- package/tests/cases/unit/dateType.test.ts +46 -0
- package/tests/cases/unit/decimalType.test.ts +2 -2
package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.cjs
CHANGED
|
@@ -6,10 +6,11 @@ require("@contember/schema-utils");
|
|
|
6
6
|
require("graphql");
|
|
7
7
|
require("@contember/schema");
|
|
8
8
|
const utils = require("../../schema/utils.cjs");
|
|
9
|
+
require("../../schema/mutations/UpdateEntityRelationInputFieldVisitor.cjs");
|
|
9
10
|
require("@contember/graphql-utils");
|
|
10
11
|
require("../hasManyToHasOneReducer/HasManyToHasOneReducer.cjs");
|
|
11
12
|
require("@contember/database");
|
|
12
|
-
require("
|
|
13
|
+
require("@contember/utilities");
|
|
13
14
|
require("../../acl/PredicatesInjector.cjs");
|
|
14
15
|
require("node:crypto");
|
|
15
16
|
require("../../mapper/select/Path.cjs");
|
|
@@ -39,6 +40,8 @@ class PaginatedHasManyFieldProviderVisitor {
|
|
|
39
40
|
`paginate${strings.capitalizeFirstLetter(relation.name)}`,
|
|
40
41
|
{
|
|
41
42
|
...this.paginatedFieldFactory.createFieldConfig(entity),
|
|
43
|
+
deprecationReason: relation.deprecationReason,
|
|
44
|
+
description: relation.description,
|
|
42
45
|
extensions: {
|
|
43
46
|
relationName: relation.name,
|
|
44
47
|
extensionKey: PaginatedHasManyFieldProvider.PaginatedHasManyFieldProvider.extensionName
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PaginatedHasManyFieldProviderVisitor.cjs","sources":["../../../../../../packages/engine-content-api/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.ts"],"sourcesContent":["import { Model } from '@contember/schema'\nimport { PaginatedHasManyFieldProvider, PaginatedHasManyFieldProviderExtension } from './PaginatedHasManyFieldProvider.js'\nimport { capitalizeFirstLetter } from '../../utils/index.js'\nimport { PaginatedFieldConfigFactory } from '../../schema/PaginatedFieldConfigFactory.js'\nimport { aliasAwareResolver } from '../../schema/index.js'\nimport { GraphQLFieldConfig } from 'graphql'\n\ntype Result = [\n\tstring,\n\tGraphQLFieldConfig<any, any> & {\n\t\textensions: PaginatedHasManyFieldProviderExtension\n\t},\n]\n\nexport class PaginatedHasManyFieldProviderVisitor implements Model.ColumnVisitor<Result[]>, Model.RelationByTypeVisitor<Result[]> {\n\tconstructor(private readonly paginatedFieldFactory: PaginatedFieldConfigFactory) {}\n\n\
|
|
1
|
+
{"version":3,"file":"PaginatedHasManyFieldProviderVisitor.cjs","sources":["../../../../../../packages/engine-content-api/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.ts"],"sourcesContent":["import { Model } from '@contember/schema'\nimport { PaginatedHasManyFieldProvider, PaginatedHasManyFieldProviderExtension } from './PaginatedHasManyFieldProvider.js'\nimport { capitalizeFirstLetter } from '../../utils/index.js'\nimport { PaginatedFieldConfigFactory } from '../../schema/PaginatedFieldConfigFactory.js'\nimport { aliasAwareResolver } from '../../schema/index.js'\nimport { GraphQLFieldConfig } from 'graphql'\n\ntype Result = [\n\tstring,\n\tGraphQLFieldConfig<any, any> & {\n\t\textensions: PaginatedHasManyFieldProviderExtension\n\t},\n]\n\nexport class PaginatedHasManyFieldProviderVisitor implements Model.ColumnVisitor<Result[]>, Model.RelationByTypeVisitor<Result[]> {\n\tconstructor(private readonly paginatedFieldFactory: PaginatedFieldConfigFactory) {}\n\n\tpublic visitOneHasMany({ targetEntity, relation }: Model.OneHasManyContext) {\n\t\treturn this.createField(targetEntity, relation)\n\t}\n\n\tpublic visitManyHasManyOwning({ targetEntity, relation }: Model.ManyHasManyOwningContext) {\n\t\treturn this.createField(targetEntity, relation)\n\t}\n\n\tpublic visitManyHasManyInverse({ targetEntity, relation }: Model.ManyHasManyInverseContext) {\n\t\treturn this.createField(targetEntity, relation)\n\t}\n\n\tprivate createField(entity: Model.Entity, relation: Model.Relation): Result[] {\n\t\treturn [\n\t\t\t[\n\t\t\t\t`paginate${capitalizeFirstLetter(relation.name)}`,\n\t\t\t\t{\n\t\t\t\t\t...this.paginatedFieldFactory.createFieldConfig(entity),\n\t\t\t\t\tdeprecationReason: relation.deprecationReason,\n\t\t\t\t\tdescription: relation.description,\n\t\t\t\t\textensions: {\n\t\t\t\t\t\trelationName: relation.name,\n\t\t\t\t\t\textensionKey: PaginatedHasManyFieldProvider.extensionName,\n\t\t\t\t\t},\n\t\t\t\t\tresolve: aliasAwareResolver,\n\t\t\t\t},\n\t\t\t],\n\t\t]\n\t}\n\n\tpublic visitColumn() {\n\t\treturn []\n\t}\n\n\tpublic visitManyHasOne() {\n\t\treturn []\n\t}\n\n\tpublic visitOneHasOneInverse() {\n\t\treturn []\n\t}\n\n\tpublic visitOneHasOneOwning() {\n\t\treturn []\n\t}\n}\n"],"names":["capitalizeFirstLetter","PaginatedHasManyFieldProvider","aliasAwareResolver"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAcO,MAAM,qCAAqH;AAAA,EACjI,YAA6B,uBAAoD;AAApD,SAAA,wBAAA;AAAA,EAAqD;AAAA,EAE3E,gBAAgB,EAAE,cAAc,YAAqC;AAC3E,WAAO,KAAK,YAAY,cAAc,QAAQ;AAAA,EAC/C;AAAA,EAEO,uBAAuB,EAAE,cAAc,YAA4C;AACzF,WAAO,KAAK,YAAY,cAAc,QAAQ;AAAA,EAC/C;AAAA,EAEO,wBAAwB,EAAE,cAAc,YAA6C;AAC3F,WAAO,KAAK,YAAY,cAAc,QAAQ;AAAA,EAC/C;AAAA,EAEQ,YAAY,QAAsB,UAAoC;AAC7E,WAAO;AAAA,MACN;AAAA,QACC,WAAWA,QAAAA,sBAAsB,SAAS,IAAI,CAAC;AAAA,QAC/C;AAAA,UACC,GAAG,KAAK,sBAAsB,kBAAkB,MAAM;AAAA,UACtD,mBAAmB,SAAS;AAAA,UAC5B,aAAa,SAAS;AAAA,UACtB,YAAY;AAAA,YACX,cAAc,SAAS;AAAA,YACvB,cAAcC,8BAAAA,8BAA8B;AAAA,UAAA;AAAA,UAE7C,SAASC,MAAAA;AAAAA,QAAA;AAAA,MACV;AAAA,IACD;AAAA,EAEF;AAAA,EAEO,cAAc;AACpB,WAAO,CAAA;AAAA,EACR;AAAA,EAEO,kBAAkB;AACxB,WAAO,CAAA;AAAA,EACR;AAAA,EAEO,wBAAwB;AAC9B,WAAO,CAAA;AAAA,EACR;AAAA,EAEO,uBAAuB;AAC7B,WAAO,CAAA;AAAA,EACR;AACD;;"}
|
package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.js
CHANGED
|
@@ -4,10 +4,11 @@ import "@contember/schema-utils";
|
|
|
4
4
|
import "graphql";
|
|
5
5
|
import "@contember/schema";
|
|
6
6
|
import { aliasAwareResolver } from "../../schema/utils.js";
|
|
7
|
+
import "../../schema/mutations/UpdateEntityRelationInputFieldVisitor.js";
|
|
7
8
|
import "@contember/graphql-utils";
|
|
8
9
|
import "../hasManyToHasOneReducer/HasManyToHasOneReducer.js";
|
|
9
10
|
import "@contember/database";
|
|
10
|
-
import "
|
|
11
|
+
import "@contember/utilities";
|
|
11
12
|
import "../../acl/PredicatesInjector.js";
|
|
12
13
|
import "node:crypto";
|
|
13
14
|
import "../../mapper/select/Path.js";
|
|
@@ -37,6 +38,8 @@ class PaginatedHasManyFieldProviderVisitor {
|
|
|
37
38
|
`paginate${capitalizeFirstLetter(relation.name)}`,
|
|
38
39
|
{
|
|
39
40
|
...this.paginatedFieldFactory.createFieldConfig(entity),
|
|
41
|
+
deprecationReason: relation.deprecationReason,
|
|
42
|
+
description: relation.description,
|
|
40
43
|
extensions: {
|
|
41
44
|
relationName: relation.name,
|
|
42
45
|
extensionKey: PaginatedHasManyFieldProvider.extensionName
|
package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PaginatedHasManyFieldProviderVisitor.js","sources":["../../../../../../packages/engine-content-api/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.ts"],"sourcesContent":["import { Model } from '@contember/schema'\nimport { PaginatedHasManyFieldProvider, PaginatedHasManyFieldProviderExtension } from './PaginatedHasManyFieldProvider.js'\nimport { capitalizeFirstLetter } from '../../utils/index.js'\nimport { PaginatedFieldConfigFactory } from '../../schema/PaginatedFieldConfigFactory.js'\nimport { aliasAwareResolver } from '../../schema/index.js'\nimport { GraphQLFieldConfig } from 'graphql'\n\ntype Result = [\n\tstring,\n\tGraphQLFieldConfig<any, any> & {\n\t\textensions: PaginatedHasManyFieldProviderExtension\n\t},\n]\n\nexport class PaginatedHasManyFieldProviderVisitor implements Model.ColumnVisitor<Result[]>, Model.RelationByTypeVisitor<Result[]> {\n\tconstructor(private readonly paginatedFieldFactory: PaginatedFieldConfigFactory) {}\n\n\
|
|
1
|
+
{"version":3,"file":"PaginatedHasManyFieldProviderVisitor.js","sources":["../../../../../../packages/engine-content-api/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.ts"],"sourcesContent":["import { Model } from '@contember/schema'\nimport { PaginatedHasManyFieldProvider, PaginatedHasManyFieldProviderExtension } from './PaginatedHasManyFieldProvider.js'\nimport { capitalizeFirstLetter } from '../../utils/index.js'\nimport { PaginatedFieldConfigFactory } from '../../schema/PaginatedFieldConfigFactory.js'\nimport { aliasAwareResolver } from '../../schema/index.js'\nimport { GraphQLFieldConfig } from 'graphql'\n\ntype Result = [\n\tstring,\n\tGraphQLFieldConfig<any, any> & {\n\t\textensions: PaginatedHasManyFieldProviderExtension\n\t},\n]\n\nexport class PaginatedHasManyFieldProviderVisitor implements Model.ColumnVisitor<Result[]>, Model.RelationByTypeVisitor<Result[]> {\n\tconstructor(private readonly paginatedFieldFactory: PaginatedFieldConfigFactory) {}\n\n\tpublic visitOneHasMany({ targetEntity, relation }: Model.OneHasManyContext) {\n\t\treturn this.createField(targetEntity, relation)\n\t}\n\n\tpublic visitManyHasManyOwning({ targetEntity, relation }: Model.ManyHasManyOwningContext) {\n\t\treturn this.createField(targetEntity, relation)\n\t}\n\n\tpublic visitManyHasManyInverse({ targetEntity, relation }: Model.ManyHasManyInverseContext) {\n\t\treturn this.createField(targetEntity, relation)\n\t}\n\n\tprivate createField(entity: Model.Entity, relation: Model.Relation): Result[] {\n\t\treturn [\n\t\t\t[\n\t\t\t\t`paginate${capitalizeFirstLetter(relation.name)}`,\n\t\t\t\t{\n\t\t\t\t\t...this.paginatedFieldFactory.createFieldConfig(entity),\n\t\t\t\t\tdeprecationReason: relation.deprecationReason,\n\t\t\t\t\tdescription: relation.description,\n\t\t\t\t\textensions: {\n\t\t\t\t\t\trelationName: relation.name,\n\t\t\t\t\t\textensionKey: PaginatedHasManyFieldProvider.extensionName,\n\t\t\t\t\t},\n\t\t\t\t\tresolve: aliasAwareResolver,\n\t\t\t\t},\n\t\t\t],\n\t\t]\n\t}\n\n\tpublic visitColumn() {\n\t\treturn []\n\t}\n\n\tpublic visitManyHasOne() {\n\t\treturn []\n\t}\n\n\tpublic visitOneHasOneInverse() {\n\t\treturn []\n\t}\n\n\tpublic visitOneHasOneOwning() {\n\t\treturn []\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAcO,MAAM,qCAAqH;AAAA,EACjI,YAA6B,uBAAoD;AAApD,SAAA,wBAAA;AAAA,EAAqD;AAAA,EAE3E,gBAAgB,EAAE,cAAc,YAAqC;AAC3E,WAAO,KAAK,YAAY,cAAc,QAAQ;AAAA,EAC/C;AAAA,EAEO,uBAAuB,EAAE,cAAc,YAA4C;AACzF,WAAO,KAAK,YAAY,cAAc,QAAQ;AAAA,EAC/C;AAAA,EAEO,wBAAwB,EAAE,cAAc,YAA6C;AAC3F,WAAO,KAAK,YAAY,cAAc,QAAQ;AAAA,EAC/C;AAAA,EAEQ,YAAY,QAAsB,UAAoC;AAC7E,WAAO;AAAA,MACN;AAAA,QACC,WAAW,sBAAsB,SAAS,IAAI,CAAC;AAAA,QAC/C;AAAA,UACC,GAAG,KAAK,sBAAsB,kBAAkB,MAAM;AAAA,UACtD,mBAAmB,SAAS;AAAA,UAC5B,aAAa,SAAS;AAAA,UACtB,YAAY;AAAA,YACX,cAAc,SAAS;AAAA,YACvB,cAAc,8BAA8B;AAAA,UAAA;AAAA,UAE7C,SAAS;AAAA,QAAA;AAAA,MACV;AAAA,IACD;AAAA,EAEF;AAAA,EAEO,cAAc;AACpB,WAAO,CAAA;AAAA,EACR;AAAA,EAEO,kBAAkB;AACxB,WAAO,CAAA;AAAA,EACR;AAAA,EAEO,wBAAwB;AAC9B,WAAO,CAAA;AAAA,EACR;AAAA,EAEO,uBAAuB;AAC7B,WAAO,CAAA;AAAA,EACR;AACD;"}
|
package/dist/development/src/input-validation/preValidation/UpdateInputPreValidationProcessor.cjs
CHANGED
|
@@ -17,7 +17,8 @@ class UpdateInputPreValidationProcessor {
|
|
|
17
17
|
connectOrCreate: (ctx) => this.processCreate({ ...ctx, input: ctx.input.create }),
|
|
18
18
|
connect: NoResult,
|
|
19
19
|
disconnect: NoResult,
|
|
20
|
-
["delete"]: NoResult
|
|
20
|
+
["delete"]: NoResult,
|
|
21
|
+
set: (ctx) => this.processSet(ctx)
|
|
21
22
|
});
|
|
22
23
|
__publicField(this, "manyHasManyOwning", {
|
|
23
24
|
create: (ctx) => this.processCreate(ctx),
|
|
@@ -26,7 +27,8 @@ class UpdateInputPreValidationProcessor {
|
|
|
26
27
|
connectOrCreate: (ctx) => this.processCreate({ ...ctx, input: ctx.input.create }),
|
|
27
28
|
connect: NoResult,
|
|
28
29
|
disconnect: NoResult,
|
|
29
|
-
["delete"]: NoResult
|
|
30
|
+
["delete"]: NoResult,
|
|
31
|
+
set: (ctx) => this.processSet(ctx)
|
|
30
32
|
});
|
|
31
33
|
__publicField(this, "manyHasOne", {
|
|
32
34
|
create: (ctx) => this.processCreate(ctx),
|
|
@@ -44,7 +46,8 @@ class UpdateInputPreValidationProcessor {
|
|
|
44
46
|
connectOrCreate: (ctx) => this.processCreate({ ...ctx, input: ctx.input.create }),
|
|
45
47
|
connect: NoResult,
|
|
46
48
|
disconnect: NoResult,
|
|
47
|
-
["delete"]: NoResult
|
|
49
|
+
["delete"]: NoResult,
|
|
50
|
+
set: (ctx) => this.processSet(ctx)
|
|
48
51
|
});
|
|
49
52
|
__publicField(this, "oneHasOneInverse", {
|
|
50
53
|
create: (ctx) => this.processCreate(ctx),
|
|
@@ -98,6 +101,24 @@ class UpdateInputPreValidationProcessor {
|
|
|
98
101
|
})
|
|
99
102
|
];
|
|
100
103
|
}
|
|
104
|
+
async processSet(context) {
|
|
105
|
+
const results = [];
|
|
106
|
+
for (const [index, item] of context.input.items.entries()) {
|
|
107
|
+
const position = { index, alias: item.alias };
|
|
108
|
+
if ("create" in item) {
|
|
109
|
+
results.push(...await this.processCreate({ ...context, ...position, input: item.create }));
|
|
110
|
+
} else if ("connectOrCreate" in item) {
|
|
111
|
+
results.push(...await this.processCreate({ ...context, ...position, input: item.connectOrCreate.create }));
|
|
112
|
+
} else if ("update" in item) {
|
|
113
|
+
results.push(...await this.processUpdate({ ...context, ...position, input: item.update.data }));
|
|
114
|
+
} else if ("upsert" in item) {
|
|
115
|
+
results.push(
|
|
116
|
+
...await this.processUpsert({ ...context, ...position, input: { update: item.upsert.update, create: item.upsert.create } })
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return results;
|
|
121
|
+
}
|
|
101
122
|
async processUpdate(context) {
|
|
102
123
|
const newPath = ValidationPath.appendRelationToPath(this.path, context.relation.name, context);
|
|
103
124
|
return this.inputValidator.validateUpdate({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UpdateInputPreValidationProcessor.cjs","sources":["../../../../../../packages/engine-content-api/src/input-validation/preValidation/UpdateInputPreValidationProcessor.ts"],"sourcesContent":["import { UpdateInputProcessor } from '../../inputProcessing/index.js'\nimport { Input, Model } from '@contember/schema'\nimport { appendRelationToPath, ValidationPath } from '../ValidationPath.js'\nimport { Mapper, MapperInput } from '../../mapper/index.js'\nimport { InputPreValidator } from './InputPreValidator.js'\n\ntype Result = any\n\nconst NoResult = () => Promise.resolve([])\n\nexport class UpdateInputPreValidationProcessor implements UpdateInputProcessor<Result> {\n\tconstructor(\n\t\tprivate readonly inputValidator: InputPreValidator,\n\t\tprivate readonly path: ValidationPath,\n\t\tprivate readonly mapper: Mapper,\n\t) {}\n\n\tasync column(context: Model.ColumnContext): Promise<Result> {\n\t\treturn []\n\t}\n\n\tmanyHasManyInverse: UpdateInputProcessor.HasManyRelationInputProcessor<Model.ManyHasManyInverseContext, Result> = {\n\t\tcreate: ctx => this.processCreate(ctx),\n\t\tupdate: ctx => this.processUpdate({ ...ctx, input: ctx.input.data }),\n\t\tupsert: ctx => this.processUpsert(ctx),\n\t\tconnectOrCreate: ctx => this.processCreate({ ...ctx, input: ctx.input.create }),\n\t\tconnect: NoResult,\n\t\tdisconnect: NoResult,\n\t\t['delete']: NoResult,\n\t}\n\tmanyHasManyOwning: UpdateInputProcessor.HasManyRelationInputProcessor<Model.ManyHasManyOwningContext, Result> = {\n\t\tcreate: ctx => this.processCreate(ctx),\n\t\tupdate: ctx => this.processUpdate({ ...ctx, input: ctx.input.data }),\n\t\tupsert: ctx => this.processUpsert(ctx),\n\t\tconnectOrCreate: ctx => this.processCreate({ ...ctx, input: ctx.input.create }),\n\t\tconnect: NoResult,\n\t\tdisconnect: NoResult,\n\t\t['delete']: NoResult,\n\t}\n\tmanyHasOne: UpdateInputProcessor.HasOneRelationInputProcessor<Model.ManyHasOneContext, Result> = {\n\t\tcreate: ctx => this.processCreate(ctx),\n\t\tupdate: ctx => this.processUpdate(ctx),\n\t\tupsert: ctx => this.processUpsert(ctx),\n\t\tconnectOrCreate: ctx => this.processCreate({ ...ctx, input: ctx.input.create }),\n\t\tconnect: NoResult,\n\t\tdisconnect: NoResult,\n\t\t['delete']: NoResult,\n\t}\n\toneHasMany: UpdateInputProcessor.HasManyRelationInputProcessor<Model.OneHasManyContext, Result> = {\n\t\tcreate: ctx => this.processCreate(ctx),\n\t\tupdate: ctx => this.processUpdate({ ...ctx, input: ctx.input.data }),\n\t\tupsert: ctx => this.processUpsert(ctx),\n\t\tconnectOrCreate: ctx => this.processCreate({ ...ctx, input: ctx.input.create }),\n\t\tconnect: NoResult,\n\t\tdisconnect: NoResult,\n\t\t['delete']: NoResult,\n\t}\n\toneHasOneInverse: UpdateInputProcessor.HasOneRelationInputProcessor<Model.OneHasOneInverseContext, Result> = {\n\t\tcreate: ctx => this.processCreate(ctx),\n\t\tupdate: ctx => this.processUpdate(ctx),\n\t\tupsert: ctx => this.processUpsert(ctx),\n\t\tconnectOrCreate: ctx => this.processCreate({ ...ctx, input: ctx.input.create }),\n\t\tconnect: NoResult,\n\t\tdisconnect: NoResult,\n\t\t['delete']: NoResult,\n\t}\n\n\toneHasOneOwning: UpdateInputProcessor.HasOneRelationInputProcessor<Model.OneHasOneOwningContext, Result> = {\n\t\tcreate: ctx => this.processCreate(ctx),\n\t\tupdate: ctx => this.processUpdate(ctx),\n\t\tupsert: ctx => this.processUpsert(ctx),\n\t\tconnectOrCreate: ctx => this.processCreate({ ...ctx, input: ctx.input.create }),\n\t\tconnect: NoResult,\n\t\tdisconnect: NoResult,\n\t\t['delete']: NoResult,\n\t}\n\n\tasync processCreate(context: {\n\t\ttargetEntity: Model.Entity\n\t\trelation: Model.AnyRelation\n\t\ttargetRelation: Model.AnyRelation | null\n\t\tinput: MapperInput.CreateDataInput\n\t\tindex?: number\n\t\talias?: string\n\t}) {\n\t\tconst newPath = appendRelationToPath(this.path, context.relation.name, context)\n\n\t\treturn this.inputValidator.validateCreate({\n\t\t\tentity: context.targetEntity,\n\t\t\tmapper: this.mapper,\n\t\t\tdata: context.input,\n\t\t\tpath: newPath,\n\t\t\toverRelation: context.targetRelation,\n\t\t})\n\t}\n\n\tasync processUpsert(context: {\n\t\ttargetEntity: Model.Entity\n\t\ttargetRelation: Model.AnyRelation | null\n\t\trelation: Model.AnyRelation\n\t\tinput: UpdateInputProcessor.UpsertInput\n\t\tindex?: number\n\t\talias?: string\n\t}) {\n\t\tconst newPath = appendRelationToPath(this.path, context.relation.name, context)\n\t\treturn [\n\t\t\t...(await this.inputValidator.validateUpdate({\n\t\t\t\tentity: context.targetEntity,\n\t\t\t\tmapper: this.mapper,\n\t\t\t\tdata: context.input.update,\n\t\t\t\tpath: newPath,\n\t\t\t\twhere: {}, // todo\n\t\t\t})),\n\t\t\t...(await this.inputValidator.validateCreate({\n\t\t\t\tentity: context.targetEntity,\n\t\t\t\tmapper: this.mapper,\n\t\t\t\tdata: context.input.create,\n\t\t\t\tpath: newPath,\n\t\t\t\toverRelation: context.targetRelation,\n\t\t\t})),\n\t\t]\n\t}\n\n\tasync processUpdate(context: {\n\t\ttargetEntity: Model.Entity\n\t\trelation: Model.AnyRelation\n\t\tinput: MapperInput.UpdateDataInput\n\t\ttargetRelation: Model.AnyRelation | null\n\t\tindex?: number\n\t\talias?: string\n\t}) {\n\t\tconst newPath = appendRelationToPath(this.path, context.relation.name, context)\n\t\treturn this.inputValidator.validateUpdate({\n\t\t\tentity: context.targetEntity,\n\t\t\tmapper: this.mapper,\n\t\t\tdata: context.input,\n\t\t\tpath: newPath,\n\t\t\twhere: {}, // todo,\n\t\t})\n\t}\n}\n"],"names":["appendRelationToPath"],"mappings":";;;;;;AAQA,MAAM,WAAW,MAAM,QAAQ,QAAQ,EAAE;AAElC,MAAM,kCAA0E;AAAA,EACtF,YACkB,gBACA,MACA,QAChB;AAHgB,SAAA,iBAAA;AACA,SAAA,OAAA;AACA,SAAA,SAAA;AAOlB,kBAAA,MAAA,sBAAkH;AAAA,MACjH,QAAQ,CAAA,QAAO,KAAK,cAAc,GAAG;AAAA,MACrC,QAAQ,CAAA,QAAO,KAAK,cAAc,EAAE,GAAG,KAAK,OAAO,IAAI,MAAM,KAAA,CAAM;AAAA,MACnE,QAAQ,CAAA,QAAO,KAAK,cAAc,GAAG;AAAA,MACrC,iBAAiB,CAAA,QAAO,KAAK,cAAc,EAAE,GAAG,KAAK,OAAO,IAAI,MAAM,OAAA,CAAQ;AAAA,MAC9E,SAAS;AAAA,MACT,YAAY;AAAA,MACZ,CAAC,QAAQ,GAAG;AAAA,IAAA,CACb;AACA,kBAAA,MAAA,qBAAgH;AAAA,MAC/G,QAAQ,CAAA,QAAO,KAAK,cAAc,GAAG;AAAA,MACrC,QAAQ,CAAA,QAAO,KAAK,cAAc,EAAE,GAAG,KAAK,OAAO,IAAI,MAAM,KAAA,CAAM;AAAA,MACnE,QAAQ,CAAA,QAAO,KAAK,cAAc,GAAG;AAAA,MACrC,iBAAiB,CAAA,QAAO,KAAK,cAAc,EAAE,GAAG,KAAK,OAAO,IAAI,MAAM,OAAA,CAAQ;AAAA,MAC9E,SAAS;AAAA,MACT,YAAY;AAAA,MACZ,CAAC,QAAQ,GAAG;AAAA,IAAA,CACb;AACA,kBAAA,MAAA,cAAiG;AA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QAAQ,KAAK;AAAA,MACb,MAAM,QAAQ;AAAA,MACd,MAAM;AAAA,MACN,OAAO,CAAA;AAAA;AAAA,IAAC,CACR;AAAA,EACF;AACD;;"}
|
|
1
|
+
{"version":3,"file":"UpdateInputPreValidationProcessor.cjs","sources":["../../../../../../packages/engine-content-api/src/input-validation/preValidation/UpdateInputPreValidationProcessor.ts"],"sourcesContent":["import { UpdateInputProcessor } from '../../inputProcessing/index.js'\nimport { Input, Model } from '@contember/schema'\nimport { appendRelationToPath, ValidationPath } from '../ValidationPath.js'\nimport { Mapper, MapperInput } from '../../mapper/index.js'\nimport { InputPreValidator } from './InputPreValidator.js'\n\ntype Result = any\n\nconst NoResult = () => Promise.resolve([])\n\nexport class UpdateInputPreValidationProcessor implements UpdateInputProcessor<Result> {\n\tconstructor(\n\t\tprivate readonly inputValidator: InputPreValidator,\n\t\tprivate readonly path: ValidationPath,\n\t\tprivate readonly mapper: Mapper,\n\t) {}\n\n\tasync column(context: Model.ColumnContext): Promise<Result> {\n\t\treturn []\n\t}\n\n\tmanyHasManyInverse: UpdateInputProcessor.HasManyRelationInputProcessor<Model.ManyHasManyInverseContext, Result> = {\n\t\tcreate: ctx => this.processCreate(ctx),\n\t\tupdate: ctx => this.processUpdate({ ...ctx, input: ctx.input.data }),\n\t\tupsert: ctx => this.processUpsert(ctx),\n\t\tconnectOrCreate: ctx => this.processCreate({ ...ctx, input: ctx.input.create }),\n\t\tconnect: NoResult,\n\t\tdisconnect: NoResult,\n\t\t['delete']: NoResult,\n\t\tset: ctx => this.processSet(ctx),\n\t}\n\tmanyHasManyOwning: UpdateInputProcessor.HasManyRelationInputProcessor<Model.ManyHasManyOwningContext, Result> = {\n\t\tcreate: ctx => this.processCreate(ctx),\n\t\tupdate: ctx => this.processUpdate({ ...ctx, input: ctx.input.data }),\n\t\tupsert: ctx => this.processUpsert(ctx),\n\t\tconnectOrCreate: ctx => this.processCreate({ ...ctx, input: ctx.input.create }),\n\t\tconnect: NoResult,\n\t\tdisconnect: NoResult,\n\t\t['delete']: NoResult,\n\t\tset: ctx => this.processSet(ctx),\n\t}\n\tmanyHasOne: UpdateInputProcessor.HasOneRelationInputProcessor<Model.ManyHasOneContext, Result> = {\n\t\tcreate: ctx => this.processCreate(ctx),\n\t\tupdate: ctx => this.processUpdate(ctx),\n\t\tupsert: ctx => this.processUpsert(ctx),\n\t\tconnectOrCreate: ctx => this.processCreate({ ...ctx, input: ctx.input.create }),\n\t\tconnect: NoResult,\n\t\tdisconnect: NoResult,\n\t\t['delete']: NoResult,\n\t}\n\toneHasMany: UpdateInputProcessor.HasManyRelationInputProcessor<Model.OneHasManyContext, Result> = {\n\t\tcreate: ctx => this.processCreate(ctx),\n\t\tupdate: ctx => this.processUpdate({ ...ctx, input: ctx.input.data }),\n\t\tupsert: ctx => this.processUpsert(ctx),\n\t\tconnectOrCreate: ctx => this.processCreate({ ...ctx, input: ctx.input.create }),\n\t\tconnect: NoResult,\n\t\tdisconnect: NoResult,\n\t\t['delete']: NoResult,\n\t\tset: ctx => this.processSet(ctx),\n\t}\n\toneHasOneInverse: UpdateInputProcessor.HasOneRelationInputProcessor<Model.OneHasOneInverseContext, Result> = {\n\t\tcreate: ctx => this.processCreate(ctx),\n\t\tupdate: ctx => this.processUpdate(ctx),\n\t\tupsert: ctx => this.processUpsert(ctx),\n\t\tconnectOrCreate: ctx => this.processCreate({ ...ctx, input: ctx.input.create }),\n\t\tconnect: NoResult,\n\t\tdisconnect: NoResult,\n\t\t['delete']: NoResult,\n\t}\n\n\toneHasOneOwning: UpdateInputProcessor.HasOneRelationInputProcessor<Model.OneHasOneOwningContext, Result> = {\n\t\tcreate: ctx => this.processCreate(ctx),\n\t\tupdate: ctx => this.processUpdate(ctx),\n\t\tupsert: ctx => this.processUpsert(ctx),\n\t\tconnectOrCreate: ctx => this.processCreate({ ...ctx, input: ctx.input.create }),\n\t\tconnect: NoResult,\n\t\tdisconnect: NoResult,\n\t\t['delete']: NoResult,\n\t}\n\n\tasync processCreate(context: {\n\t\ttargetEntity: Model.Entity\n\t\trelation: Model.AnyRelation\n\t\ttargetRelation: Model.AnyRelation | null\n\t\tinput: MapperInput.CreateDataInput\n\t\tindex?: number\n\t\talias?: string\n\t}) {\n\t\tconst newPath = appendRelationToPath(this.path, context.relation.name, context)\n\n\t\treturn this.inputValidator.validateCreate({\n\t\t\tentity: context.targetEntity,\n\t\t\tmapper: this.mapper,\n\t\t\tdata: context.input,\n\t\t\tpath: newPath,\n\t\t\toverRelation: context.targetRelation,\n\t\t})\n\t}\n\n\tasync processUpsert(context: {\n\t\ttargetEntity: Model.Entity\n\t\ttargetRelation: Model.AnyRelation | null\n\t\trelation: Model.AnyRelation\n\t\tinput: UpdateInputProcessor.UpsertInput\n\t\tindex?: number\n\t\talias?: string\n\t}) {\n\t\tconst newPath = appendRelationToPath(this.path, context.relation.name, context)\n\t\treturn [\n\t\t\t...(await this.inputValidator.validateUpdate({\n\t\t\t\tentity: context.targetEntity,\n\t\t\t\tmapper: this.mapper,\n\t\t\t\tdata: context.input.update,\n\t\t\t\tpath: newPath,\n\t\t\t\twhere: {}, // todo\n\t\t\t})),\n\t\t\t...(await this.inputValidator.validateCreate({\n\t\t\t\tentity: context.targetEntity,\n\t\t\t\tmapper: this.mapper,\n\t\t\t\tdata: context.input.create,\n\t\t\t\tpath: newPath,\n\t\t\t\toverRelation: context.targetRelation,\n\t\t\t})),\n\t\t]\n\t}\n\n\tasync processSet(context: {\n\t\ttargetEntity: Model.Entity\n\t\trelation: Model.AnyRelation\n\t\ttargetRelation: Model.AnyRelation | null\n\t\tinput: UpdateInputProcessor.SetManyInput\n\t}) {\n\t\tconst results: Result[] = []\n\t\t// index/alias have to travel with each item, otherwise every item's validation errors\n\t\t// collapse onto the same path and a client cannot tell which one failed.\n\t\tfor (const [index, item] of context.input.items.entries()) {\n\t\t\tconst position = { index, alias: item.alias }\n\t\t\tif ('create' in item) {\n\t\t\t\tresults.push(...(await this.processCreate({ ...context, ...position, input: item.create })))\n\t\t\t} else if ('connectOrCreate' in item) {\n\t\t\t\tresults.push(...(await this.processCreate({ ...context, ...position, input: item.connectOrCreate.create })))\n\t\t\t} else if ('update' in item) {\n\t\t\t\tresults.push(...(await this.processUpdate({ ...context, ...position, input: item.update.data })))\n\t\t\t} else if ('upsert' in item) {\n\t\t\t\tresults.push(\n\t\t\t\t\t...(await this.processUpsert({ ...context, ...position, input: { update: item.upsert.update, create: item.upsert.create } })),\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t\treturn results\n\t}\n\n\tasync processUpdate(context: {\n\t\ttargetEntity: Model.Entity\n\t\trelation: Model.AnyRelation\n\t\tinput: MapperInput.UpdateDataInput\n\t\ttargetRelation: Model.AnyRelation | null\n\t\tindex?: number\n\t\talias?: string\n\t}) {\n\t\tconst newPath = appendRelationToPath(this.path, context.relation.name, context)\n\t\treturn this.inputValidator.validateUpdate({\n\t\t\tentity: context.targetEntity,\n\t\t\tmapper: this.mapper,\n\t\t\tdata: context.input,\n\t\t\tpath: newPath,\n\t\t\twhere: {}, // todo,\n\t\t})\n\t}\n}\n"],"names":["appendRelationToPath"],"mappings":";;;;;;AAQA,MAAM,WAAW,MAAM,QAAQ,QAAQ,EAAE;AAElC,MAAM,kCAA0E;AAAA,EACtF,YACkB,gBACA,MACA,QAChB;AAHgB,SAAA,iBAAA;AACA,SAAA,OAAA;AACA,SAAA,SAAA;AAOlB,kBAAA,MAAA,sBAAkH;AAAA,MACjH,QAAQ,CAAA,QAAO,KAAK,cAAc,GAAG;AAAA,MACrC,QAAQ,CAAA,QAAO,KAAK,cAAc,EAAE,GAAG,KAAK,OAAO,IAAI,MAAM,KAAA,CAAM;AAAA,MACnE,QAAQ,CAAA,QAAO,KAAK,cAAc,GAAG;AAAA,MACrC,iBAAiB,CAAA,QAAO,KAAK,cAAc,EAAE,GAAG,KAAK,OAAO,IAAI,MAAM,OAAA,CAAQ;AAAA,MAC9E,SAAS;AAAA,MACT,YAAY;AAAA,MACZ,CAAC,QAAQ,GAAG;A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R;AAAA,EAEA,MAAM,cAAc,SAOjB;AACF,UAAM,UAAUA,eAAAA,qBAAqB,KAAK,MAAM,QAAQ,SAAS,MAAM,OAAO;AAC9E,WAAO,KAAK,eAAe,eAAe;AAAA,MACzC,QAAQ,QAAQ;AAAA,MAChB,QAAQ,KAAK;AAAA,MACb,MAAM,QAAQ;AAAA,MACd,MAAM;AAAA,MACN,OAAO,CAAA;AAAA;AAAA,IAAC,CACR;AAAA,EACF;AACD;;"}
|
package/dist/development/src/input-validation/preValidation/UpdateInputPreValidationProcessor.js
CHANGED
|
@@ -15,7 +15,8 @@ class UpdateInputPreValidationProcessor {
|
|
|
15
15
|
connectOrCreate: (ctx) => this.processCreate({ ...ctx, input: ctx.input.create }),
|
|
16
16
|
connect: NoResult,
|
|
17
17
|
disconnect: NoResult,
|
|
18
|
-
["delete"]: NoResult
|
|
18
|
+
["delete"]: NoResult,
|
|
19
|
+
set: (ctx) => this.processSet(ctx)
|
|
19
20
|
});
|
|
20
21
|
__publicField(this, "manyHasManyOwning", {
|
|
21
22
|
create: (ctx) => this.processCreate(ctx),
|
|
@@ -24,7 +25,8 @@ class UpdateInputPreValidationProcessor {
|
|
|
24
25
|
connectOrCreate: (ctx) => this.processCreate({ ...ctx, input: ctx.input.create }),
|
|
25
26
|
connect: NoResult,
|
|
26
27
|
disconnect: NoResult,
|
|
27
|
-
["delete"]: NoResult
|
|
28
|
+
["delete"]: NoResult,
|
|
29
|
+
set: (ctx) => this.processSet(ctx)
|
|
28
30
|
});
|
|
29
31
|
__publicField(this, "manyHasOne", {
|
|
30
32
|
create: (ctx) => this.processCreate(ctx),
|
|
@@ -42,7 +44,8 @@ class UpdateInputPreValidationProcessor {
|
|
|
42
44
|
connectOrCreate: (ctx) => this.processCreate({ ...ctx, input: ctx.input.create }),
|
|
43
45
|
connect: NoResult,
|
|
44
46
|
disconnect: NoResult,
|
|
45
|
-
["delete"]: NoResult
|
|
47
|
+
["delete"]: NoResult,
|
|
48
|
+
set: (ctx) => this.processSet(ctx)
|
|
46
49
|
});
|
|
47
50
|
__publicField(this, "oneHasOneInverse", {
|
|
48
51
|
create: (ctx) => this.processCreate(ctx),
|
|
@@ -96,6 +99,24 @@ class UpdateInputPreValidationProcessor {
|
|
|
96
99
|
})
|
|
97
100
|
];
|
|
98
101
|
}
|
|
102
|
+
async processSet(context) {
|
|
103
|
+
const results = [];
|
|
104
|
+
for (const [index, item] of context.input.items.entries()) {
|
|
105
|
+
const position = { index, alias: item.alias };
|
|
106
|
+
if ("create" in item) {
|
|
107
|
+
results.push(...await this.processCreate({ ...context, ...position, input: item.create }));
|
|
108
|
+
} else if ("connectOrCreate" in item) {
|
|
109
|
+
results.push(...await this.processCreate({ ...context, ...position, input: item.connectOrCreate.create }));
|
|
110
|
+
} else if ("update" in item) {
|
|
111
|
+
results.push(...await this.processUpdate({ ...context, ...position, input: item.update.data }));
|
|
112
|
+
} else if ("upsert" in item) {
|
|
113
|
+
results.push(
|
|
114
|
+
...await this.processUpsert({ ...context, ...position, input: { update: item.upsert.update, create: item.upsert.create } })
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return results;
|
|
119
|
+
}
|
|
99
120
|
async processUpdate(context) {
|
|
100
121
|
const newPath = appendRelationToPath(this.path, context.relation.name, context);
|
|
101
122
|
return this.inputValidator.validateUpdate({
|
package/dist/development/src/input-validation/preValidation/UpdateInputPreValidationProcessor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UpdateInputPreValidationProcessor.js","sources":["../../../../../../packages/engine-content-api/src/input-validation/preValidation/UpdateInputPreValidationProcessor.ts"],"sourcesContent":["import { UpdateInputProcessor } from '../../inputProcessing/index.js'\nimport { Input, Model } from '@contember/schema'\nimport { appendRelationToPath, ValidationPath } from '../ValidationPath.js'\nimport { Mapper, MapperInput } from '../../mapper/index.js'\nimport { InputPreValidator } from './InputPreValidator.js'\n\ntype Result = any\n\nconst NoResult = () => Promise.resolve([])\n\nexport class UpdateInputPreValidationProcessor implements UpdateInputProcessor<Result> {\n\tconstructor(\n\t\tprivate readonly inputValidator: InputPreValidator,\n\t\tprivate readonly path: ValidationPath,\n\t\tprivate readonly mapper: Mapper,\n\t) {}\n\n\tasync column(context: Model.ColumnContext): Promise<Result> {\n\t\treturn []\n\t}\n\n\tmanyHasManyInverse: UpdateInputProcessor.HasManyRelationInputProcessor<Model.ManyHasManyInverseContext, Result> = {\n\t\tcreate: ctx => this.processCreate(ctx),\n\t\tupdate: ctx => this.processUpdate({ ...ctx, input: ctx.input.data }),\n\t\tupsert: ctx => this.processUpsert(ctx),\n\t\tconnectOrCreate: ctx => this.processCreate({ ...ctx, input: ctx.input.create }),\n\t\tconnect: NoResult,\n\t\tdisconnect: NoResult,\n\t\t['delete']: NoResult,\n\t}\n\tmanyHasManyOwning: UpdateInputProcessor.HasManyRelationInputProcessor<Model.ManyHasManyOwningContext, Result> = {\n\t\tcreate: ctx => this.processCreate(ctx),\n\t\tupdate: ctx => this.processUpdate({ ...ctx, input: ctx.input.data }),\n\t\tupsert: ctx => this.processUpsert(ctx),\n\t\tconnectOrCreate: ctx => this.processCreate({ ...ctx, input: ctx.input.create }),\n\t\tconnect: NoResult,\n\t\tdisconnect: NoResult,\n\t\t['delete']: NoResult,\n\t}\n\tmanyHasOne: UpdateInputProcessor.HasOneRelationInputProcessor<Model.ManyHasOneContext, Result> = {\n\t\tcreate: ctx => this.processCreate(ctx),\n\t\tupdate: ctx => this.processUpdate(ctx),\n\t\tupsert: ctx => this.processUpsert(ctx),\n\t\tconnectOrCreate: ctx => this.processCreate({ ...ctx, input: ctx.input.create }),\n\t\tconnect: NoResult,\n\t\tdisconnect: NoResult,\n\t\t['delete']: NoResult,\n\t}\n\toneHasMany: UpdateInputProcessor.HasManyRelationInputProcessor<Model.OneHasManyContext, Result> = {\n\t\tcreate: ctx => this.processCreate(ctx),\n\t\tupdate: ctx => this.processUpdate({ ...ctx, input: ctx.input.data }),\n\t\tupsert: ctx => this.processUpsert(ctx),\n\t\tconnectOrCreate: ctx => this.processCreate({ ...ctx, input: ctx.input.create }),\n\t\tconnect: NoResult,\n\t\tdisconnect: NoResult,\n\t\t['delete']: NoResult,\n\t}\n\toneHasOneInverse: UpdateInputProcessor.HasOneRelationInputProcessor<Model.OneHasOneInverseContext, Result> = {\n\t\tcreate: ctx => this.processCreate(ctx),\n\t\tupdate: ctx => this.processUpdate(ctx),\n\t\tupsert: ctx => this.processUpsert(ctx),\n\t\tconnectOrCreate: ctx => this.processCreate({ ...ctx, input: ctx.input.create }),\n\t\tconnect: NoResult,\n\t\tdisconnect: NoResult,\n\t\t['delete']: NoResult,\n\t}\n\n\toneHasOneOwning: UpdateInputProcessor.HasOneRelationInputProcessor<Model.OneHasOneOwningContext, Result> = {\n\t\tcreate: ctx => this.processCreate(ctx),\n\t\tupdate: ctx => this.processUpdate(ctx),\n\t\tupsert: ctx => this.processUpsert(ctx),\n\t\tconnectOrCreate: ctx => this.processCreate({ ...ctx, input: ctx.input.create }),\n\t\tconnect: NoResult,\n\t\tdisconnect: NoResult,\n\t\t['delete']: NoResult,\n\t}\n\n\tasync processCreate(context: {\n\t\ttargetEntity: Model.Entity\n\t\trelation: Model.AnyRelation\n\t\ttargetRelation: Model.AnyRelation | null\n\t\tinput: MapperInput.CreateDataInput\n\t\tindex?: number\n\t\talias?: string\n\t}) {\n\t\tconst newPath = appendRelationToPath(this.path, context.relation.name, context)\n\n\t\treturn this.inputValidator.validateCreate({\n\t\t\tentity: context.targetEntity,\n\t\t\tmapper: this.mapper,\n\t\t\tdata: context.input,\n\t\t\tpath: newPath,\n\t\t\toverRelation: context.targetRelation,\n\t\t})\n\t}\n\n\tasync processUpsert(context: {\n\t\ttargetEntity: Model.Entity\n\t\ttargetRelation: Model.AnyRelation | null\n\t\trelation: Model.AnyRelation\n\t\tinput: UpdateInputProcessor.UpsertInput\n\t\tindex?: number\n\t\talias?: string\n\t}) {\n\t\tconst newPath = appendRelationToPath(this.path, context.relation.name, context)\n\t\treturn [\n\t\t\t...(await this.inputValidator.validateUpdate({\n\t\t\t\tentity: context.targetEntity,\n\t\t\t\tmapper: this.mapper,\n\t\t\t\tdata: context.input.update,\n\t\t\t\tpath: newPath,\n\t\t\t\twhere: {}, // todo\n\t\t\t})),\n\t\t\t...(await this.inputValidator.validateCreate({\n\t\t\t\tentity: context.targetEntity,\n\t\t\t\tmapper: this.mapper,\n\t\t\t\tdata: context.input.create,\n\t\t\t\tpath: newPath,\n\t\t\t\toverRelation: context.targetRelation,\n\t\t\t})),\n\t\t]\n\t}\n\n\tasync processUpdate(context: {\n\t\ttargetEntity: Model.Entity\n\t\trelation: Model.AnyRelation\n\t\tinput: MapperInput.UpdateDataInput\n\t\ttargetRelation: Model.AnyRelation | null\n\t\tindex?: number\n\t\talias?: string\n\t}) {\n\t\tconst newPath = appendRelationToPath(this.path, context.relation.name, context)\n\t\treturn this.inputValidator.validateUpdate({\n\t\t\tentity: context.targetEntity,\n\t\t\tmapper: this.mapper,\n\t\t\tdata: context.input,\n\t\t\tpath: newPath,\n\t\t\twhere: {}, // todo,\n\t\t})\n\t}\n}\n"],"names":[],"mappings":";;;;AAQA,MAAM,WAAW,MAAM,QAAQ,QAAQ,EAAE;AAElC,MAAM,kCAA0E;AAAA,EACtF,YACkB,gBACA,MACA,QAChB;AAHgB,SAAA,iBAAA;AACA,SAAA,OAAA;AACA,SAAA,SAAA;AAOlB,kBAAA,MAAA,sBAAkH;AAAA,MACjH,QAAQ,CAAA,QAAO,KAAK,cAAc,GAAG;AAAA,MACrC,QAAQ,CAAA,QAAO,KAAK,cAAc,EAAE,GAAG,KAAK,OAAO,IAAI,MAAM,KAAA,CAAM;AAAA,MACnE,QAAQ,CAAA,QAAO,KAAK,cAAc,GAAG;AAAA,MACrC,iBAAiB,CAAA,QAAO,KAAK,cAAc,EAAE,GAAG,KAAK,OAAO,IAAI,MAAM,OAAA,CAAQ;AAAA,MAC9E,SAAS;AAAA,MACT,YAAY;AAAA,MACZ,CAA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,QACpB,MAAM;AAAA,QACN,OAAO,CAAA;AAAA;AAAA,MAAC,CACR;AAAA,MACD,GAAI,MAAM,KAAK,eAAe,eAAe;AAAA,QAC5C,QAAQ,QAAQ;AAAA,QAChB,QAAQ,KAAK;AAAA,QACb,MAAM,QAAQ,MAAM;AAAA,QACpB,MAAM;AAAA,QACN,cAAc,QAAQ;AAAA,MAAA,CACtB;AAAA,IAAA;AAAA,EAEH;AAAA,EAEA,MAAM,cAAc,SAOjB;AACF,UAAM,UAAU,qBAAqB,KAAK,MAAM,QAAQ,SAAS,MAAM,OAAO;AAC9E,WAAO,KAAK,eAAe,eAAe;AAAA,MACzC,QAAQ,QAAQ;AAAA,MAChB,QAAQ,KAAK;AAAA,MACb,MAAM,QAAQ;AAAA,MACd,MAAM;AAAA,MACN,OAAO,CAAA;AAAA;AAAA,IAAC,CACR;AAAA,EACF;AACD;"}
|
|
1
|
+
{"version":3,"file":"UpdateInputPreValidationProcessor.js","sources":["../../../../../../packages/engine-content-api/src/input-validation/preValidation/UpdateInputPreValidationProcessor.ts"],"sourcesContent":["import { UpdateInputProcessor } from '../../inputProcessing/index.js'\nimport { Input, Model } from '@contember/schema'\nimport { appendRelationToPath, ValidationPath } from '../ValidationPath.js'\nimport { Mapper, MapperInput } from '../../mapper/index.js'\nimport { InputPreValidator } from './InputPreValidator.js'\n\ntype Result = any\n\nconst NoResult = () => Promise.resolve([])\n\nexport class UpdateInputPreValidationProcessor implements UpdateInputProcessor<Result> {\n\tconstructor(\n\t\tprivate readonly inputValidator: InputPreValidator,\n\t\tprivate readonly path: ValidationPath,\n\t\tprivate readonly mapper: Mapper,\n\t) {}\n\n\tasync column(context: Model.ColumnContext): Promise<Result> {\n\t\treturn []\n\t}\n\n\tmanyHasManyInverse: UpdateInputProcessor.HasManyRelationInputProcessor<Model.ManyHasManyInverseContext, Result> = {\n\t\tcreate: ctx => this.processCreate(ctx),\n\t\tupdate: ctx => this.processUpdate({ ...ctx, input: ctx.input.data }),\n\t\tupsert: ctx => this.processUpsert(ctx),\n\t\tconnectOrCreate: ctx => this.processCreate({ ...ctx, input: ctx.input.create }),\n\t\tconnect: NoResult,\n\t\tdisconnect: NoResult,\n\t\t['delete']: NoResult,\n\t\tset: ctx => this.processSet(ctx),\n\t}\n\tmanyHasManyOwning: UpdateInputProcessor.HasManyRelationInputProcessor<Model.ManyHasManyOwningContext, Result> = {\n\t\tcreate: ctx => this.processCreate(ctx),\n\t\tupdate: ctx => this.processUpdate({ ...ctx, input: ctx.input.data }),\n\t\tupsert: ctx => this.processUpsert(ctx),\n\t\tconnectOrCreate: ctx => this.processCreate({ ...ctx, input: ctx.input.create }),\n\t\tconnect: NoResult,\n\t\tdisconnect: NoResult,\n\t\t['delete']: NoResult,\n\t\tset: ctx => this.processSet(ctx),\n\t}\n\tmanyHasOne: UpdateInputProcessor.HasOneRelationInputProcessor<Model.ManyHasOneContext, Result> = {\n\t\tcreate: ctx => this.processCreate(ctx),\n\t\tupdate: ctx => this.processUpdate(ctx),\n\t\tupsert: ctx => this.processUpsert(ctx),\n\t\tconnectOrCreate: ctx => this.processCreate({ ...ctx, input: ctx.input.create }),\n\t\tconnect: NoResult,\n\t\tdisconnect: NoResult,\n\t\t['delete']: NoResult,\n\t}\n\toneHasMany: UpdateInputProcessor.HasManyRelationInputProcessor<Model.OneHasManyContext, Result> = {\n\t\tcreate: ctx => this.processCreate(ctx),\n\t\tupdate: ctx => this.processUpdate({ ...ctx, input: ctx.input.data }),\n\t\tupsert: ctx => this.processUpsert(ctx),\n\t\tconnectOrCreate: ctx => this.processCreate({ ...ctx, input: ctx.input.create }),\n\t\tconnect: NoResult,\n\t\tdisconnect: NoResult,\n\t\t['delete']: NoResult,\n\t\tset: ctx => this.processSet(ctx),\n\t}\n\toneHasOneInverse: UpdateInputProcessor.HasOneRelationInputProcessor<Model.OneHasOneInverseContext, Result> = {\n\t\tcreate: ctx => this.processCreate(ctx),\n\t\tupdate: ctx => this.processUpdate(ctx),\n\t\tupsert: ctx => this.processUpsert(ctx),\n\t\tconnectOrCreate: ctx => this.processCreate({ ...ctx, input: ctx.input.create }),\n\t\tconnect: NoResult,\n\t\tdisconnect: NoResult,\n\t\t['delete']: NoResult,\n\t}\n\n\toneHasOneOwning: UpdateInputProcessor.HasOneRelationInputProcessor<Model.OneHasOneOwningContext, Result> = {\n\t\tcreate: ctx => this.processCreate(ctx),\n\t\tupdate: ctx => this.processUpdate(ctx),\n\t\tupsert: ctx => this.processUpsert(ctx),\n\t\tconnectOrCreate: ctx => this.processCreate({ ...ctx, input: ctx.input.create }),\n\t\tconnect: NoResult,\n\t\tdisconnect: NoResult,\n\t\t['delete']: NoResult,\n\t}\n\n\tasync processCreate(context: {\n\t\ttargetEntity: Model.Entity\n\t\trelation: Model.AnyRelation\n\t\ttargetRelation: Model.AnyRelation | null\n\t\tinput: MapperInput.CreateDataInput\n\t\tindex?: number\n\t\talias?: string\n\t}) {\n\t\tconst newPath = appendRelationToPath(this.path, context.relation.name, context)\n\n\t\treturn this.inputValidator.validateCreate({\n\t\t\tentity: context.targetEntity,\n\t\t\tmapper: this.mapper,\n\t\t\tdata: context.input,\n\t\t\tpath: newPath,\n\t\t\toverRelation: context.targetRelation,\n\t\t})\n\t}\n\n\tasync processUpsert(context: {\n\t\ttargetEntity: Model.Entity\n\t\ttargetRelation: Model.AnyRelation | null\n\t\trelation: Model.AnyRelation\n\t\tinput: UpdateInputProcessor.UpsertInput\n\t\tindex?: number\n\t\talias?: string\n\t}) {\n\t\tconst newPath = appendRelationToPath(this.path, context.relation.name, context)\n\t\treturn [\n\t\t\t...(await this.inputValidator.validateUpdate({\n\t\t\t\tentity: context.targetEntity,\n\t\t\t\tmapper: this.mapper,\n\t\t\t\tdata: context.input.update,\n\t\t\t\tpath: newPath,\n\t\t\t\twhere: {}, // todo\n\t\t\t})),\n\t\t\t...(await this.inputValidator.validateCreate({\n\t\t\t\tentity: context.targetEntity,\n\t\t\t\tmapper: this.mapper,\n\t\t\t\tdata: context.input.create,\n\t\t\t\tpath: newPath,\n\t\t\t\toverRelation: context.targetRelation,\n\t\t\t})),\n\t\t]\n\t}\n\n\tasync processSet(context: {\n\t\ttargetEntity: Model.Entity\n\t\trelation: Model.AnyRelation\n\t\ttargetRelation: Model.AnyRelation | null\n\t\tinput: UpdateInputProcessor.SetManyInput\n\t}) {\n\t\tconst results: Result[] = []\n\t\t// index/alias have to travel with each item, otherwise every item's validation errors\n\t\t// collapse onto the same path and a client cannot tell which one failed.\n\t\tfor (const [index, item] of context.input.items.entries()) {\n\t\t\tconst position = { index, alias: item.alias }\n\t\t\tif ('create' in item) {\n\t\t\t\tresults.push(...(await this.processCreate({ ...context, ...position, input: item.create })))\n\t\t\t} else if ('connectOrCreate' in item) {\n\t\t\t\tresults.push(...(await this.processCreate({ ...context, ...position, input: item.connectOrCreate.create })))\n\t\t\t} else if ('update' in item) {\n\t\t\t\tresults.push(...(await this.processUpdate({ ...context, ...position, input: item.update.data })))\n\t\t\t} else if ('upsert' in item) {\n\t\t\t\tresults.push(\n\t\t\t\t\t...(await this.processUpsert({ ...context, ...position, input: { update: item.upsert.update, create: item.upsert.create } })),\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t\treturn results\n\t}\n\n\tasync processUpdate(context: {\n\t\ttargetEntity: Model.Entity\n\t\trelation: Model.AnyRelation\n\t\tinput: MapperInput.UpdateDataInput\n\t\ttargetRelation: Model.AnyRelation | null\n\t\tindex?: number\n\t\talias?: string\n\t}) {\n\t\tconst newPath = appendRelationToPath(this.path, context.relation.name, context)\n\t\treturn this.inputValidator.validateUpdate({\n\t\t\tentity: context.targetEntity,\n\t\t\tmapper: this.mapper,\n\t\t\tdata: context.input,\n\t\t\tpath: newPath,\n\t\t\twhere: {}, // todo,\n\t\t})\n\t}\n}\n"],"names":[],"mappings":";;;;AAQA,MAAM,WAAW,MAAM,QAAQ,QAAQ,EAAE;AAElC,MAAM,kCAA0E;AAAA,EACtF,YACkB,gBACA,MACA,QAChB;AAHgB,SAAA,iBAAA;A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AgB,OAAA,CAAQ,CAAE;AAAA,MAC5G,WAAW,YAAY,MAAM;AAC5B,gBAAQ,KAAK,GAAI,MAAM,KAAK,cAAc,EAAE,GAAG,SAAS,GAAG,UAAU,OAAO,KAAK,OAAO,KAAA,CAAM,CAAE;AAAA,MACjG,WAAW,YAAY,MAAM;AAC5B,gBAAQ;AAAA,UACP,GAAI,MAAM,KAAK,cAAc,EAAE,GAAG,SAAS,GAAG,UAAU,OAAO,EAAE,QAAQ,KAAK,OAAO,QAAQ,QAAQ,KAAK,OAAO,UAAU;AAAA,QAAA;AAAA,MAE7H;AAAA,IACD;AACA,WAAO;AAAA,EACR;AAAA,EAEA,MAAM,cAAc,SAOjB;AACF,UAAM,UAAU,qBAAqB,KAAK,MAAM,QAAQ,SAAS,MAAM,OAAO;AAC9E,WAAO,KAAK,eAAe,eAAe;AAAA,MACzC,QAAQ,QAAQ;AAAA,MAChB,QAAQ,KAAK;AAAA,MACb,MAAM,QAAQ;AAAA,MACd,MAAM;AAAA,MACN,OAAO,CAAA;AAAA;AAAA,IAAC,CACR;AAAA,EACF;AACD;"}
|
|
@@ -94,9 +94,17 @@ class UpdateInputVisitor {
|
|
|
94
94
|
if (input === void 0 || input === null) {
|
|
95
95
|
return Promise.resolve([]);
|
|
96
96
|
}
|
|
97
|
+
const elements = Array.isArray(input) ? input : [input];
|
|
98
|
+
const hasSet = elements.some((it) => it && it.set != null);
|
|
99
|
+
if (hasSet) {
|
|
100
|
+
if (elements.length !== 1) {
|
|
101
|
+
throw new exception.UserError('A "set" operation must be the only item of a has-many relation input.');
|
|
102
|
+
}
|
|
103
|
+
return this.processSetRelationInput(processor, context, elements[0]);
|
|
104
|
+
}
|
|
97
105
|
const results = [];
|
|
98
106
|
let i = 0;
|
|
99
|
-
for (let element of
|
|
107
|
+
for (let element of elements) {
|
|
100
108
|
const alias = element.alias;
|
|
101
109
|
element = object.filterObject(element, (k, v) => v !== null && v !== void 0);
|
|
102
110
|
this.verifyOperations(element);
|
|
@@ -138,9 +146,35 @@ class UpdateInputVisitor {
|
|
|
138
146
|
}
|
|
139
147
|
return results;
|
|
140
148
|
}
|
|
149
|
+
async processSetRelationInput(processor, context, input) {
|
|
150
|
+
const keys = Object.keys(object.filterObject(input, (k, v) => v !== null && v !== void 0));
|
|
151
|
+
const allowedKeys = ["set", "orphanStrategy", "alias"];
|
|
152
|
+
const unexpected = keys.filter((it) => !allowedKeys.includes(it));
|
|
153
|
+
if (unexpected.length > 0) {
|
|
154
|
+
throw new exception.UserError(
|
|
155
|
+
`Unexpected key(s) ${unexpected.join(", ")} alongside "set". Only "orphanStrategy" and "alias" are allowed.`
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
const orphanStrategy = input.orphanStrategy ?? schema.Input.OrphanRemovalStrategy.disconnect;
|
|
159
|
+
if (!Object.values(schema.Input.OrphanRemovalStrategy).includes(orphanStrategy)) {
|
|
160
|
+
throw new exception.UserError(
|
|
161
|
+
`Invalid orphanStrategy "${orphanStrategy}". Expected one of: ${Object.values(schema.Input.OrphanRemovalStrategy).join(", ")}.`
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
const items = input.set.map((it) => object.filterObject(it, (k, v) => v !== null && v !== void 0));
|
|
165
|
+
for (const item of items) {
|
|
166
|
+
this.verifySetItemOperations(item);
|
|
167
|
+
}
|
|
168
|
+
return [
|
|
169
|
+
await processor.set({
|
|
170
|
+
...context,
|
|
171
|
+
input: { items, orphanStrategy }
|
|
172
|
+
})
|
|
173
|
+
];
|
|
174
|
+
}
|
|
141
175
|
verifyOperations(input) {
|
|
142
176
|
const keys = Object.keys(input).filter((it) => it !== "alias");
|
|
143
|
-
const ops = Object.values(schema.Input.UpdateRelationOperation);
|
|
177
|
+
const ops = Object.values(schema.Input.UpdateRelationOperation).filter((it) => it !== schema.Input.UpdateRelationOperation.set);
|
|
144
178
|
if (keys.length !== 1 || !ops.includes(keys[0])) {
|
|
145
179
|
const found = keys.length === 0 ? "none" : keys.join(", ");
|
|
146
180
|
throw new exception.UserError(
|
|
@@ -148,6 +182,22 @@ class UpdateInputVisitor {
|
|
|
148
182
|
);
|
|
149
183
|
}
|
|
150
184
|
}
|
|
185
|
+
verifySetItemOperations(input) {
|
|
186
|
+
const keys = Object.keys(object.filterObject(input, (k, v) => v !== null && v !== void 0)).filter((it) => it !== "alias");
|
|
187
|
+
const ops = [
|
|
188
|
+
schema.Input.UpdateRelationOperation.create,
|
|
189
|
+
schema.Input.UpdateRelationOperation.connect,
|
|
190
|
+
schema.Input.UpdateRelationOperation.connectOrCreate,
|
|
191
|
+
schema.Input.UpdateRelationOperation.update,
|
|
192
|
+
schema.Input.UpdateRelationOperation.upsert
|
|
193
|
+
];
|
|
194
|
+
if (keys.length !== 1 || !ops.includes(keys[0])) {
|
|
195
|
+
const found = keys.length === 0 ? "none" : keys.join(", ");
|
|
196
|
+
throw new exception.UserError(
|
|
197
|
+
`Expected exactly one of: ${ops.join(", ")} in a "set" item. ${found} found.`
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
151
201
|
}
|
|
152
202
|
exports.UpdateInputVisitor = UpdateInputVisitor;
|
|
153
203
|
//# sourceMappingURL=UpdateInputVisitor.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UpdateInputVisitor.cjs","sources":["../../../../../packages/engine-content-api/src/inputProcessing/UpdateInputVisitor.ts"],"sourcesContent":["import { Input, Model } from '@contember/schema'\nimport { filterObject } from '../utils/index.js'\nimport { UpdateInputProcessor } from './UpdateInputProcessor.js'\nimport { ImplementationException, UserError } from '../exception.js'\nimport { MapperInput } from '../mapper/index.js'\n\nexport class UpdateInputVisitor<Result> implements Model.ColumnVisitor<Promise<Result[]>>, Model.RelationByTypeVisitor<Promise<Result[]>> {\n\tconstructor(\n\t\tprivate readonly updateInputProcessor: UpdateInputProcessor<Result>,\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly data: MapperInput.UpdateDataInput,\n\t) {}\n\n\tpublic async visitColumn({ entity, column }: Model.ColumnContext): Promise<Result[]> {\n\t\treturn [\n\t\t\tawait this.updateInputProcessor.column({\n\t\t\t\tentity,\n\t\t\t\tcolumn,\n\t\t\t\tinput: this.data[column.name] as Input.ColumnValue,\n\t\t\t}),\n\t\t]\n\t}\n\n\tpublic visitManyHasManyInverse(context: Model.ManyHasManyInverseContext) {\n\t\treturn this.processManyRelationInput(\n\t\t\tthis.updateInputProcessor.manyHasManyInverse,\n\t\t\tcontext,\n\t\t\tthis.data[context.relation.name] as MapperInput.CreateManyRelationInput,\n\t\t)\n\t}\n\n\tpublic visitManyHasManyOwning(context: Model.ManyHasManyOwningContext) {\n\t\treturn this.processManyRelationInput(\n\t\t\tthis.updateInputProcessor.manyHasManyOwning,\n\t\t\tcontext,\n\t\t\tthis.data[context.relation.name] as MapperInput.CreateManyRelationInput,\n\t\t)\n\t}\n\n\tpublic visitManyHasOne(context: Model.ManyHasOneContext) {\n\t\treturn this.processRelationInput(\n\t\t\tthis.updateInputProcessor.manyHasOne,\n\t\t\tcontext,\n\t\t\tthis.data[context.relation.name] as MapperInput.CreateOneRelationInput,\n\t\t)\n\t}\n\n\tpublic visitOneHasMany(context: Model.OneHasManyContext) {\n\t\treturn this.processManyRelationInput(\n\t\t\tthis.updateInputProcessor.oneHasMany,\n\t\t\tcontext,\n\t\t\tthis.data[context.relation.name] as MapperInput.CreateManyRelationInput,\n\t\t)\n\t}\n\n\tpublic visitOneHasOneInverse(context: Model.OneHasOneInverseContext) {\n\t\treturn this.processRelationInput(\n\t\t\tthis.updateInputProcessor.oneHasOneInverse,\n\t\t\tcontext,\n\t\t\tthis.data[context.relation.name] as MapperInput.CreateOneRelationInput,\n\t\t)\n\t}\n\n\tpublic visitOneHasOneOwning(context: Model.OneHasOneOwningContext) {\n\t\treturn this.processRelationInput(\n\t\t\tthis.updateInputProcessor.oneHasOneOwning,\n\t\t\tcontext,\n\t\t\tthis.data[context.relation.name] as MapperInput.CreateOneRelationInput,\n\t\t)\n\t}\n\n\tprivate async processRelationInput<Context>(\n\t\tprocessor: UpdateInputProcessor.HasOneRelationInputProcessor<Context, Result>,\n\t\tcontext: Context,\n\t\tinput: MapperInput.UpdateOneRelationInput | undefined,\n\t): Promise<Result[]> {\n\t\tif (input === undefined || input === null) {\n\t\t\treturn Promise.resolve([])\n\t\t}\n\t\tinput = filterObject(input, (k, v) => v !== null && v !== undefined)\n\t\tthis.verifyOperations(input)\n\t\tif ('connect' in input) {\n\t\t\treturn [await processor.connect({ ...context, input: input.connect })]\n\t\t}\n\t\tif ('create' in input) {\n\t\t\treturn [await processor.create({ ...context, input: input.create })]\n\t\t}\n\t\tif ('connectOrCreate' in input) {\n\t\t\treturn [await processor.connectOrCreate({ ...context, input: input.connectOrCreate })]\n\t\t}\n\t\tif ('delete' in input) {\n\t\t\treturn [await processor.delete({ ...context, input: undefined })]\n\t\t}\n\t\tif ('disconnect' in input) {\n\t\t\treturn [await processor.disconnect({ ...context, input: undefined })]\n\t\t}\n\t\tif ('update' in input) {\n\t\t\treturn [await processor.update({ ...context, input: input.update })]\n\t\t}\n\t\tif ('upsert' in input) {\n\t\t\treturn [await processor.upsert({ ...context, input: input.upsert })]\n\t\t}\n\t\tthrow new ImplementationException()\n\t}\n\n\tprivate async processManyRelationInput<Context>(\n\t\tprocessor: UpdateInputProcessor.HasManyRelationInputProcessor<Context, Result>,\n\t\tcontext: Context,\n\t\tinput: MapperInput.UpdateManyRelationInput | undefined,\n\t): Promise<Result[]> {\n\t\tif (input === undefined || input === null) {\n\t\t\treturn Promise.resolve([])\n\t\t}\n\t\tconst results: Array<Result> = []\n\t\tlet i = 0\n\t\tfor (let element of input) {\n\t\t\tconst alias = element.alias\n\t\t\telement = filterObject(element, (k, v) => v !== null && v !== undefined)\n\t\t\tthis.verifyOperations(element)\n\t\t\tlet result\n\t\t\tif ('connect' in element) {\n\t\t\t\tresult = processor.connect({ ...context, input: element.connect, index: i, alias })\n\t\t\t}\n\t\t\tif ('create' in element) {\n\t\t\t\tresult = processor.create({ ...context, input: element.create, index: i, alias })\n\t\t\t}\n\t\t\tif ('connectOrCreate' in element) {\n\t\t\t\tresult = processor.connectOrCreate({ ...context, input: element.connectOrCreate, index: i, alias })\n\t\t\t}\n\t\t\tif ('delete' in element) {\n\t\t\t\tresult = processor.delete({ ...context, input: element.delete, index: i, alias })\n\t\t\t}\n\t\t\tif ('disconnect' in element) {\n\t\t\t\tresult = processor.disconnect({ ...context, input: element.disconnect, index: i, alias })\n\t\t\t}\n\t\t\tif ('update' in element) {\n\t\t\t\tresult = processor.update({\n\t\t\t\t\t...context,\n\t\t\t\t\tinput: { where: element.update.by, data: element.update.data },\n\t\t\t\t\tindex: i,\n\t\t\t\t\talias,\n\t\t\t\t})\n\t\t\t}\n\t\t\tif ('upsert' in element) {\n\t\t\t\tresult = processor.upsert({\n\t\t\t\t\t...context,\n\t\t\t\t\tinput: { where: element.upsert.by, update: element.upsert.update, create: element.upsert.create },\n\t\t\t\t\tindex: i,\n\t\t\t\t\talias,\n\t\t\t\t})\n\t\t\t}\n\n\t\t\tif (result !== undefined) {\n\t\t\t\tresults.push(await result)\n\t\t\t}\n\t\t}\n\t\treturn results\n\t}\n\n\tprivate verifyOperations(input: object) {\n\t\tconst keys = Object.keys(input).filter(it => it !== 'alias')\n\t\tconst ops = Object.values(Input.UpdateRelationOperation) as string[]\n\t\tif (keys.length !== 1 || !ops.includes(keys[0])) {\n\t\t\tconst found = keys.length === 0 ? 'none' : keys.join(', ')\n\t\t\tthrow new UserError(\n\t\t\t\t`Expected exactly one of: ${ops.join(', ')}. ${found} found.`,\n\t\t\t)\n\t\t}\n\t}\n}\n"],"names":["schema","filterObject","ImplementationException","Input","UserError"],"mappings":";;;;;;AAMO,MAAM,mBAA6H;AAAA,EACzI,YACkB,sBACAA,SACA,MAChB;AAHgB,SAAA,uBAAA;AACA,SAAA,SAAAA;AACA,SAAA,OAAA;AAAA,EACf;AAAA,EAEH,MAAa,YAAY,EAAE,QAAQ,UAAkD;AACp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OAAO,KAAK,KAAK,EAAE,OAAO,CAAA,OAAM,OAAO,OAAO;AAC3D,UAAM,MAAM,OAAO,OAAOE,OAAAA,MAAM,uBAAuB;AACvD,QAAI,KAAK,WAAW,KAAK,CAAC,IAAI,SAAS,KAAK,CAAC,CAAC,GAAG;AAChD,YAAM,QAAQ,KAAK,WAAW,IAAI,SAAS,KAAK,KAAK,IAAI;AACzD,YAAM,IAAIC,UAAAA;AAAAA,QACT,4BAA4B,IAAI,KAAK,IAAI,CAAC,KAAK,KAAK;AAAA,MAAA;AAAA,IAEtD;AAAA,EACD;AACD;;"}
|
|
1
|
+
{"version":3,"file":"UpdateInputVisitor.cjs","sources":["../../../../../packages/engine-content-api/src/inputProcessing/UpdateInputVisitor.ts"],"sourcesContent":["import { Input, Model } from '@contember/schema'\nimport { filterObject } from '../utils/index.js'\nimport { UpdateInputProcessor } from './UpdateInputProcessor.js'\nimport { ImplementationException, UserError } from '../exception.js'\nimport { MapperInput } from '../mapper/index.js'\n\nexport class UpdateInputVisitor<Result> implements Model.ColumnVisitor<Promise<Result[]>>, Model.RelationByTypeVisitor<Promise<Result[]>> {\n\tconstructor(\n\t\tprivate readonly updateInputProcessor: UpdateInputProcessor<Result>,\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly data: MapperInput.UpdateDataInput,\n\t) {}\n\n\tpublic async visitColumn({ entity, column }: Model.ColumnContext): Promise<Result[]> {\n\t\treturn [\n\t\t\tawait this.updateInputProcessor.column({\n\t\t\t\tentity,\n\t\t\t\tcolumn,\n\t\t\t\tinput: this.data[column.name] as Input.ColumnValue,\n\t\t\t}),\n\t\t]\n\t}\n\n\tpublic visitManyHasManyInverse(context: Model.ManyHasManyInverseContext) {\n\t\treturn this.processManyRelationInput(\n\t\t\tthis.updateInputProcessor.manyHasManyInverse,\n\t\t\tcontext,\n\t\t\tthis.data[context.relation.name] as MapperInput.CreateManyRelationInput,\n\t\t)\n\t}\n\n\tpublic visitManyHasManyOwning(context: Model.ManyHasManyOwningContext) {\n\t\treturn this.processManyRelationInput(\n\t\t\tthis.updateInputProcessor.manyHasManyOwning,\n\t\t\tcontext,\n\t\t\tthis.data[context.relation.name] as MapperInput.CreateManyRelationInput,\n\t\t)\n\t}\n\n\tpublic visitManyHasOne(context: Model.ManyHasOneContext) {\n\t\treturn this.processRelationInput(\n\t\t\tthis.updateInputProcessor.manyHasOne,\n\t\t\tcontext,\n\t\t\tthis.data[context.relation.name] as MapperInput.CreateOneRelationInput,\n\t\t)\n\t}\n\n\tpublic visitOneHasMany(context: Model.OneHasManyContext) {\n\t\treturn this.processManyRelationInput(\n\t\t\tthis.updateInputProcessor.oneHasMany,\n\t\t\tcontext,\n\t\t\tthis.data[context.relation.name] as MapperInput.CreateManyRelationInput,\n\t\t)\n\t}\n\n\tpublic visitOneHasOneInverse(context: Model.OneHasOneInverseContext) {\n\t\treturn this.processRelationInput(\n\t\t\tthis.updateInputProcessor.oneHasOneInverse,\n\t\t\tcontext,\n\t\t\tthis.data[context.relation.name] as MapperInput.CreateOneRelationInput,\n\t\t)\n\t}\n\n\tpublic visitOneHasOneOwning(context: Model.OneHasOneOwningContext) {\n\t\treturn this.processRelationInput(\n\t\t\tthis.updateInputProcessor.oneHasOneOwning,\n\t\t\tcontext,\n\t\t\tthis.data[context.relation.name] as MapperInput.CreateOneRelationInput,\n\t\t)\n\t}\n\n\tprivate async processRelationInput<Context>(\n\t\tprocessor: UpdateInputProcessor.HasOneRelationInputProcessor<Context, Result>,\n\t\tcontext: Context,\n\t\tinput: MapperInput.UpdateOneRelationInput | undefined,\n\t): Promise<Result[]> {\n\t\tif (input === undefined || input === null) {\n\t\t\treturn Promise.resolve([])\n\t\t}\n\t\tinput = filterObject(input, (k, v) => v !== null && v !== undefined)\n\t\tthis.verifyOperations(input)\n\t\tif ('connect' in input) {\n\t\t\treturn [await processor.connect({ ...context, input: input.connect })]\n\t\t}\n\t\tif ('create' in input) {\n\t\t\treturn [await processor.create({ ...context, input: input.create })]\n\t\t}\n\t\tif ('connectOrCreate' in input) {\n\t\t\treturn [await processor.connectOrCreate({ ...context, input: input.connectOrCreate })]\n\t\t}\n\t\tif ('delete' in input) {\n\t\t\treturn [await processor.delete({ ...context, input: undefined })]\n\t\t}\n\t\tif ('disconnect' in input) {\n\t\t\treturn [await processor.disconnect({ ...context, input: undefined })]\n\t\t}\n\t\tif ('update' in input) {\n\t\t\treturn [await processor.update({ ...context, input: input.update })]\n\t\t}\n\t\tif ('upsert' in input) {\n\t\t\treturn [await processor.upsert({ ...context, input: input.upsert })]\n\t\t}\n\t\tthrow new ImplementationException()\n\t}\n\n\tprivate async processManyRelationInput<Context>(\n\t\tprocessor: UpdateInputProcessor.HasManyRelationInputProcessor<Context, Result>,\n\t\tcontext: Context,\n\t\tinput: MapperInput.UpdateManyRelationInput | undefined,\n\t): Promise<Result[]> {\n\t\tif (input === undefined || input === null) {\n\t\t\treturn Promise.resolve([])\n\t\t}\n\t\t// GraphQL coerces a single object into a single-element list, so a bare `{ set: ... }` arrives here as `[{ set: ... }]`.\n\t\tconst elements = Array.isArray(input) ? input : [input]\n\t\tconst hasSet = elements.some(it => it && (it as MapperInput.SetManyRelationInput).set != null)\n\t\tif (hasSet) {\n\t\t\tif (elements.length !== 1) {\n\t\t\t\tthrow new UserError('A \"set\" operation must be the only item of a has-many relation input.')\n\t\t\t}\n\t\t\treturn this.processSetRelationInput(processor, context, elements[0] as MapperInput.SetManyRelationInput)\n\t\t}\n\t\tconst results: Array<Result> = []\n\t\tlet i = 0\n\t\tfor (let element of elements as MapperInput.UpdateManyRelationInputItem[]) {\n\t\t\tconst alias = element.alias\n\t\t\telement = filterObject(element, (k, v) => v !== null && v !== undefined)\n\t\t\tthis.verifyOperations(element)\n\t\t\tlet result\n\t\t\tif ('connect' in element) {\n\t\t\t\tresult = processor.connect({ ...context, input: element.connect, index: i, alias })\n\t\t\t}\n\t\t\tif ('create' in element) {\n\t\t\t\tresult = processor.create({ ...context, input: element.create, index: i, alias })\n\t\t\t}\n\t\t\tif ('connectOrCreate' in element) {\n\t\t\t\tresult = processor.connectOrCreate({ ...context, input: element.connectOrCreate, index: i, alias })\n\t\t\t}\n\t\t\tif ('delete' in element) {\n\t\t\t\tresult = processor.delete({ ...context, input: element.delete, index: i, alias })\n\t\t\t}\n\t\t\tif ('disconnect' in element) {\n\t\t\t\tresult = processor.disconnect({ ...context, input: element.disconnect, index: i, alias })\n\t\t\t}\n\t\t\tif ('update' in element) {\n\t\t\t\tresult = processor.update({\n\t\t\t\t\t...context,\n\t\t\t\t\tinput: { where: element.update.by, data: element.update.data },\n\t\t\t\t\tindex: i,\n\t\t\t\t\talias,\n\t\t\t\t})\n\t\t\t}\n\t\t\tif ('upsert' in element) {\n\t\t\t\tresult = processor.upsert({\n\t\t\t\t\t...context,\n\t\t\t\t\tinput: { where: element.upsert.by, update: element.upsert.update, create: element.upsert.create },\n\t\t\t\t\tindex: i,\n\t\t\t\t\talias,\n\t\t\t\t})\n\t\t\t}\n\n\t\t\tif (result !== undefined) {\n\t\t\t\tresults.push(await result)\n\t\t\t}\n\t\t}\n\t\treturn results\n\t}\n\n\tprivate async processSetRelationInput<Context>(\n\t\tprocessor: UpdateInputProcessor.HasManyRelationInputProcessor<Context, Result>,\n\t\tcontext: Context,\n\t\tinput: MapperInput.SetManyRelationInput,\n\t): Promise<Result[]> {\n\t\tconst keys = Object.keys(filterObject(input, (k, v) => v !== null && v !== undefined))\n\t\tconst allowedKeys = ['set', 'orphanStrategy', 'alias']\n\t\tconst unexpected = keys.filter(it => !allowedKeys.includes(it))\n\t\tif (unexpected.length > 0) {\n\t\t\tthrow new UserError(\n\t\t\t\t`Unexpected key(s) ${unexpected.join(', ')} alongside \"set\". Only \"orphanStrategy\" and \"alias\" are allowed.`,\n\t\t\t)\n\t\t}\n\t\tconst orphanStrategy = input.orphanStrategy ?? Input.OrphanRemovalStrategy.disconnect\n\t\tif (!Object.values(Input.OrphanRemovalStrategy).includes(orphanStrategy)) {\n\t\t\tthrow new UserError(\n\t\t\t\t`Invalid orphanStrategy \"${orphanStrategy}\". Expected one of: ${Object.values(Input.OrphanRemovalStrategy).join(', ')}.`,\n\t\t\t)\n\t\t}\n\t\t// Strip null-valued keys before dispatching, exactly as the per-item path does: nullable\n\t\t// GraphQL variables are the reason `filterObject` exists, and both the pre-validator and\n\t\t// the mapper dispatch on key presence, so a `null` operation key would pick its branch.\n\t\tconst items = input.set.map(it => filterObject(it, (k, v) => v !== null && v !== undefined))\n\t\tfor (const item of items) {\n\t\t\tthis.verifySetItemOperations(item)\n\t\t}\n\t\treturn [\n\t\t\tawait processor.set({\n\t\t\t\t...context,\n\t\t\t\tinput: { items, orphanStrategy },\n\t\t\t}),\n\t\t]\n\t}\n\n\tprivate verifyOperations(input: object) {\n\t\tconst keys = Object.keys(input).filter(it => it !== 'alias')\n\t\t// `set` lives in the same enum but is not a per-item operation - accepting it here would\n\t\t// fall through to an ImplementationException (a 500) instead of a UserError.\n\t\tconst ops = (Object.values(Input.UpdateRelationOperation) as string[]).filter(it => it !== Input.UpdateRelationOperation.set)\n\t\tif (keys.length !== 1 || !ops.includes(keys[0])) {\n\t\t\tconst found = keys.length === 0 ? 'none' : keys.join(', ')\n\t\t\tthrow new UserError(\n\t\t\t\t`Expected exactly one of: ${ops.join(', ')}. ${found} found.`,\n\t\t\t)\n\t\t}\n\t}\n\n\tprivate verifySetItemOperations(input: object) {\n\t\tconst keys = Object.keys(filterObject(input, (k, v) => v !== null && v !== undefined)).filter(it => it !== 'alias')\n\t\tconst ops: string[] = [\n\t\t\tInput.UpdateRelationOperation.create,\n\t\t\tInput.UpdateRelationOperation.connect,\n\t\t\tInput.UpdateRelationOperation.connectOrCreate,\n\t\t\tInput.UpdateRelationOperation.update,\n\t\t\tInput.UpdateRelationOperation.upsert,\n\t\t]\n\t\tif (keys.length !== 1 || !ops.includes(keys[0])) {\n\t\t\tconst found = keys.length === 0 ? 'none' : keys.join(', ')\n\t\t\tthrow new UserError(\n\t\t\t\t`Expected exactly one of: ${ops.join(', ')} in a \"set\" item. ${found} found.`,\n\t\t\t)\n\t\t}\n\t}\n}\n"],"names":["schema","filterObject","ImplementationException","UserError","Input"],"mappings":";;;;;;AAMO,MAAM,mBAA6H;AAAA,EACzI,YACkB,sBACAA,SACA,MAChB;AAHgB,SAAA,uBAAA;AACA,SAAA,SAAAA;AACA,SAAA,OAAA;AAAA,EACf;AAAA,EAEH,MAAa,YAAY,EAAE,QAAQ,UAAkD;AACpF,WAAO;AAAA,MACN,MAAM,KAAK,qBAAqB,OAAO;AAAA,QACtC;AAAA,QACA;AAAA,QACA,OAAO,KAAK,KAAK,OAAO,IAAI;AAAA,MAAA,CAC5B;AAAA,IAAA;AAAA,EAEH;AAAA,EAEO,wBAAwB,SAA0C;AACxE,WAAO,KAAK;AAAA,MACX,KAAK,qBAAqB;AAAA,MAC1B;AAAA,MACA,KAAK,KAAK,QAAQ,SAAS,IAAI;AAAA,IAAA;AAAA,EAEjC;AAAA,EAEO,uBAAuB,SAAyC;AACtE,WAAO,KAAK;AAAA,MACX,KAAK,qBAAqB;AAAA,MAC1B;AAAA,MACA,KAAK,KAAK,QAAQ,SAAS,IAAI;AAAA,IAAA;AAAA,EAEjC;AAAA,EAEO,gBAAgB,SAAkC;AACxD,WAAO,KAAK;AAAA,MACX,KAAK,qBAAqB;AAAA,MAC1B;AAAA,MACA,KAAK,KAAK,QAAQ,SAAS,IAAI;AAAA,IAAA;AAAA,EAEjC;AAAA,EAEO,gBAAgB,SAAkC;AACxD,WAAO,KAAK;AAAA,MACX,KAAK,qBAAqB;AAAA,MAC1B;AAAA,MACA,KAAK,KAAK,QAAQ,SAAS,IAAI;AAAA,IAAA;AAAA,EAEjC;AAAA,EAEO,sBAAsB,SAAwC;AACpE,WAAO,KAAK;AAAA,MACX,KAAK,qBAAqB;AAAA,MAC1B;AAAA,MACA,KAAK,KAAK,QAAQ,SAAS,IAAI;AAAA,IAAA;AAAA,EAEjC;AAAA,EAEO,qBAAqB,SAAuC;AAClE,WAAO,KAAK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KAAK,IAAI;AACzD,YAAM,IAAID,UAAAA;AAAAA,QACT,4BAA4B,IAAI,KAAK,IAAI,CAAC,qBAAqB,KAAK;AAAA,MAAA;AAAA,IAEtE;AAAA,EACD;AACD;;"}
|
|
@@ -92,9 +92,17 @@ class UpdateInputVisitor {
|
|
|
92
92
|
if (input === void 0 || input === null) {
|
|
93
93
|
return Promise.resolve([]);
|
|
94
94
|
}
|
|
95
|
+
const elements = Array.isArray(input) ? input : [input];
|
|
96
|
+
const hasSet = elements.some((it) => it && it.set != null);
|
|
97
|
+
if (hasSet) {
|
|
98
|
+
if (elements.length !== 1) {
|
|
99
|
+
throw new UserError('A "set" operation must be the only item of a has-many relation input.');
|
|
100
|
+
}
|
|
101
|
+
return this.processSetRelationInput(processor, context, elements[0]);
|
|
102
|
+
}
|
|
95
103
|
const results = [];
|
|
96
104
|
let i = 0;
|
|
97
|
-
for (let element of
|
|
105
|
+
for (let element of elements) {
|
|
98
106
|
const alias = element.alias;
|
|
99
107
|
element = filterObject(element, (k, v) => v !== null && v !== void 0);
|
|
100
108
|
this.verifyOperations(element);
|
|
@@ -136,9 +144,35 @@ class UpdateInputVisitor {
|
|
|
136
144
|
}
|
|
137
145
|
return results;
|
|
138
146
|
}
|
|
147
|
+
async processSetRelationInput(processor, context, input) {
|
|
148
|
+
const keys = Object.keys(filterObject(input, (k, v) => v !== null && v !== void 0));
|
|
149
|
+
const allowedKeys = ["set", "orphanStrategy", "alias"];
|
|
150
|
+
const unexpected = keys.filter((it) => !allowedKeys.includes(it));
|
|
151
|
+
if (unexpected.length > 0) {
|
|
152
|
+
throw new UserError(
|
|
153
|
+
`Unexpected key(s) ${unexpected.join(", ")} alongside "set". Only "orphanStrategy" and "alias" are allowed.`
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
const orphanStrategy = input.orphanStrategy ?? Input.OrphanRemovalStrategy.disconnect;
|
|
157
|
+
if (!Object.values(Input.OrphanRemovalStrategy).includes(orphanStrategy)) {
|
|
158
|
+
throw new UserError(
|
|
159
|
+
`Invalid orphanStrategy "${orphanStrategy}". Expected one of: ${Object.values(Input.OrphanRemovalStrategy).join(", ")}.`
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
const items = input.set.map((it) => filterObject(it, (k, v) => v !== null && v !== void 0));
|
|
163
|
+
for (const item of items) {
|
|
164
|
+
this.verifySetItemOperations(item);
|
|
165
|
+
}
|
|
166
|
+
return [
|
|
167
|
+
await processor.set({
|
|
168
|
+
...context,
|
|
169
|
+
input: { items, orphanStrategy }
|
|
170
|
+
})
|
|
171
|
+
];
|
|
172
|
+
}
|
|
139
173
|
verifyOperations(input) {
|
|
140
174
|
const keys = Object.keys(input).filter((it) => it !== "alias");
|
|
141
|
-
const ops = Object.values(Input.UpdateRelationOperation);
|
|
175
|
+
const ops = Object.values(Input.UpdateRelationOperation).filter((it) => it !== Input.UpdateRelationOperation.set);
|
|
142
176
|
if (keys.length !== 1 || !ops.includes(keys[0])) {
|
|
143
177
|
const found = keys.length === 0 ? "none" : keys.join(", ");
|
|
144
178
|
throw new UserError(
|
|
@@ -146,6 +180,22 @@ class UpdateInputVisitor {
|
|
|
146
180
|
);
|
|
147
181
|
}
|
|
148
182
|
}
|
|
183
|
+
verifySetItemOperations(input) {
|
|
184
|
+
const keys = Object.keys(filterObject(input, (k, v) => v !== null && v !== void 0)).filter((it) => it !== "alias");
|
|
185
|
+
const ops = [
|
|
186
|
+
Input.UpdateRelationOperation.create,
|
|
187
|
+
Input.UpdateRelationOperation.connect,
|
|
188
|
+
Input.UpdateRelationOperation.connectOrCreate,
|
|
189
|
+
Input.UpdateRelationOperation.update,
|
|
190
|
+
Input.UpdateRelationOperation.upsert
|
|
191
|
+
];
|
|
192
|
+
if (keys.length !== 1 || !ops.includes(keys[0])) {
|
|
193
|
+
const found = keys.length === 0 ? "none" : keys.join(", ");
|
|
194
|
+
throw new UserError(
|
|
195
|
+
`Expected exactly one of: ${ops.join(", ")} in a "set" item. ${found} found.`
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
149
199
|
}
|
|
150
200
|
export {
|
|
151
201
|
UpdateInputVisitor
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UpdateInputVisitor.js","sources":["../../../../../packages/engine-content-api/src/inputProcessing/UpdateInputVisitor.ts"],"sourcesContent":["import { Input, Model } from '@contember/schema'\nimport { filterObject } from '../utils/index.js'\nimport { UpdateInputProcessor } from './UpdateInputProcessor.js'\nimport { ImplementationException, UserError } from '../exception.js'\nimport { MapperInput } from '../mapper/index.js'\n\nexport class UpdateInputVisitor<Result> implements Model.ColumnVisitor<Promise<Result[]>>, Model.RelationByTypeVisitor<Promise<Result[]>> {\n\tconstructor(\n\t\tprivate readonly updateInputProcessor: UpdateInputProcessor<Result>,\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly data: MapperInput.UpdateDataInput,\n\t) {}\n\n\tpublic async visitColumn({ entity, column }: Model.ColumnContext): Promise<Result[]> {\n\t\treturn [\n\t\t\tawait this.updateInputProcessor.column({\n\t\t\t\tentity,\n\t\t\t\tcolumn,\n\t\t\t\tinput: this.data[column.name] as Input.ColumnValue,\n\t\t\t}),\n\t\t]\n\t}\n\n\tpublic visitManyHasManyInverse(context: Model.ManyHasManyInverseContext) {\n\t\treturn this.processManyRelationInput(\n\t\t\tthis.updateInputProcessor.manyHasManyInverse,\n\t\t\tcontext,\n\t\t\tthis.data[context.relation.name] as MapperInput.CreateManyRelationInput,\n\t\t)\n\t}\n\n\tpublic visitManyHasManyOwning(context: Model.ManyHasManyOwningContext) {\n\t\treturn this.processManyRelationInput(\n\t\t\tthis.updateInputProcessor.manyHasManyOwning,\n\t\t\tcontext,\n\t\t\tthis.data[context.relation.name] as MapperInput.CreateManyRelationInput,\n\t\t)\n\t}\n\n\tpublic visitManyHasOne(context: Model.ManyHasOneContext) {\n\t\treturn this.processRelationInput(\n\t\t\tthis.updateInputProcessor.manyHasOne,\n\t\t\tcontext,\n\t\t\tthis.data[context.relation.name] as MapperInput.CreateOneRelationInput,\n\t\t)\n\t}\n\n\tpublic visitOneHasMany(context: Model.OneHasManyContext) {\n\t\treturn this.processManyRelationInput(\n\t\t\tthis.updateInputProcessor.oneHasMany,\n\t\t\tcontext,\n\t\t\tthis.data[context.relation.name] as MapperInput.CreateManyRelationInput,\n\t\t)\n\t}\n\n\tpublic visitOneHasOneInverse(context: Model.OneHasOneInverseContext) {\n\t\treturn this.processRelationInput(\n\t\t\tthis.updateInputProcessor.oneHasOneInverse,\n\t\t\tcontext,\n\t\t\tthis.data[context.relation.name] as MapperInput.CreateOneRelationInput,\n\t\t)\n\t}\n\n\tpublic visitOneHasOneOwning(context: Model.OneHasOneOwningContext) {\n\t\treturn this.processRelationInput(\n\t\t\tthis.updateInputProcessor.oneHasOneOwning,\n\t\t\tcontext,\n\t\t\tthis.data[context.relation.name] as MapperInput.CreateOneRelationInput,\n\t\t)\n\t}\n\n\tprivate async processRelationInput<Context>(\n\t\tprocessor: UpdateInputProcessor.HasOneRelationInputProcessor<Context, Result>,\n\t\tcontext: Context,\n\t\tinput: MapperInput.UpdateOneRelationInput | undefined,\n\t): Promise<Result[]> {\n\t\tif (input === undefined || input === null) {\n\t\t\treturn Promise.resolve([])\n\t\t}\n\t\tinput = filterObject(input, (k, v) => v !== null && v !== undefined)\n\t\tthis.verifyOperations(input)\n\t\tif ('connect' in input) {\n\t\t\treturn [await processor.connect({ ...context, input: input.connect })]\n\t\t}\n\t\tif ('create' in input) {\n\t\t\treturn [await processor.create({ ...context, input: input.create })]\n\t\t}\n\t\tif ('connectOrCreate' in input) {\n\t\t\treturn [await processor.connectOrCreate({ ...context, input: input.connectOrCreate })]\n\t\t}\n\t\tif ('delete' in input) {\n\t\t\treturn [await processor.delete({ ...context, input: undefined })]\n\t\t}\n\t\tif ('disconnect' in input) {\n\t\t\treturn [await processor.disconnect({ ...context, input: undefined })]\n\t\t}\n\t\tif ('update' in input) {\n\t\t\treturn [await processor.update({ ...context, input: input.update })]\n\t\t}\n\t\tif ('upsert' in input) {\n\t\t\treturn [await processor.upsert({ ...context, input: input.upsert })]\n\t\t}\n\t\tthrow new ImplementationException()\n\t}\n\n\tprivate async processManyRelationInput<Context>(\n\t\tprocessor: UpdateInputProcessor.HasManyRelationInputProcessor<Context, Result>,\n\t\tcontext: Context,\n\t\tinput: MapperInput.UpdateManyRelationInput | undefined,\n\t): Promise<Result[]> {\n\t\tif (input === undefined || input === null) {\n\t\t\treturn Promise.resolve([])\n\t\t}\n\t\tconst results: Array<Result> = []\n\t\tlet i = 0\n\t\tfor (let element of input) {\n\t\t\tconst alias = element.alias\n\t\t\telement = filterObject(element, (k, v) => v !== null && v !== undefined)\n\t\t\tthis.verifyOperations(element)\n\t\t\tlet result\n\t\t\tif ('connect' in element) {\n\t\t\t\tresult = processor.connect({ ...context, input: element.connect, index: i, alias })\n\t\t\t}\n\t\t\tif ('create' in element) {\n\t\t\t\tresult = processor.create({ ...context, input: element.create, index: i, alias })\n\t\t\t}\n\t\t\tif ('connectOrCreate' in element) {\n\t\t\t\tresult = processor.connectOrCreate({ ...context, input: element.connectOrCreate, index: i, alias })\n\t\t\t}\n\t\t\tif ('delete' in element) {\n\t\t\t\tresult = processor.delete({ ...context, input: element.delete, index: i, alias })\n\t\t\t}\n\t\t\tif ('disconnect' in element) {\n\t\t\t\tresult = processor.disconnect({ ...context, input: element.disconnect, index: i, alias })\n\t\t\t}\n\t\t\tif ('update' in element) {\n\t\t\t\tresult = processor.update({\n\t\t\t\t\t...context,\n\t\t\t\t\tinput: { where: element.update.by, data: element.update.data },\n\t\t\t\t\tindex: i,\n\t\t\t\t\talias,\n\t\t\t\t})\n\t\t\t}\n\t\t\tif ('upsert' in element) {\n\t\t\t\tresult = processor.upsert({\n\t\t\t\t\t...context,\n\t\t\t\t\tinput: { where: element.upsert.by, update: element.upsert.update, create: element.upsert.create },\n\t\t\t\t\tindex: i,\n\t\t\t\t\talias,\n\t\t\t\t})\n\t\t\t}\n\n\t\t\tif (result !== undefined) {\n\t\t\t\tresults.push(await result)\n\t\t\t}\n\t\t}\n\t\treturn results\n\t}\n\n\tprivate verifyOperations(input: object) {\n\t\tconst keys = Object.keys(input).filter(it => it !== 'alias')\n\t\tconst ops = Object.values(Input.UpdateRelationOperation) as string[]\n\t\tif (keys.length !== 1 || !ops.includes(keys[0])) {\n\t\t\tconst found = keys.length === 0 ? 'none' : keys.join(', ')\n\t\t\tthrow new UserError(\n\t\t\t\t`Expected exactly one of: ${ops.join(', ')}. ${found} found.`,\n\t\t\t)\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;;;AAMO,MAAM,mBAA6H;AAAA,EACzI,YACkB,sBACA,QACA,MAChB;AAHgB,SAAA,uBAAA;AACA,SAAA,SAAA;AACA,SAAA,OAAA;AAAA,EACf;AAAA,EAEH,MAAa,YAAY,EAAE,QAAQ,UAAkD;AACpF,WAAO;AAAA,MACN,MAAM,KAAK,qBAAqB,OAAO;AAAA,QACtC;AAAA,QACA;AAAA,QACA,OAAO,KAAK,KAAK,OAAO,IAAI;AAAA,MAAA,CAC5B;AAAA,IAAA;AAAA,EAEH;AAAA,EAEO,wBAAwB,SAA0C;AACxE,WAAO,KAAK;AAAA,MACX,KAAK,qBAAqB;AAAA,MAC1B;AAAA,MACA,KAAK,KAAK,QAAQ,SAAS,IAAI;AAAA,IAAA;AAAA,EAEjC;AAAA,EAEO,uBAAuB,SAAyC;AACtE,WAAO,KAAK;AAAA,MACX,KAAK,qBAAqB;AAAA,MAC1B;AAAA,MACA,KAAK,KAAK,QAAQ,SAAS,IAAI;AAAA,IAAA;AAAA,EAEjC;AAAA,EAEO,gBAAgB,SAAkC;AACxD,WAAO,KAAK;AAAA,MACX,KAAK,qBAAqB;AAAA,MAC1B;AAAA,MACA,KAAK,KAAK,QAAQ,SAAS,IAAI;AAAA,IAAA;AAAA,EAEjC;AAAA,EAEO,gBAAgB,SAAkC;AACxD,WAAO,KAAK;AAAA,MACX,KAAK,qBAAqB;AAAA,MAC1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AA,UACzB,GAAG;AAAA,UACH,OAAO,EAAE,OAAO,QAAQ,OAAO,IAAI,MAAM,QAAQ,OAAO,KAAA;AAAA,UACxD,OAAO;AAAA,UACP;AAAA,QAAA,CACA;AAAA,MACF;AACA,UAAI,YAAY,SAAS;AACxB,iBAAS,UAAU,OAAO;AAAA,UACzB,GAAG;AAAA,UACH,OAAO,EAAE,OAAO,QAAQ,OAAO,IAAI,QAAQ,QAAQ,OAAO,QAAQ,QAAQ,QAAQ,OAAO,OAAA;AAAA,UACzF,OAAO;AAAA,UACP;AAAA,QAAA,CACA;AAAA,MACF;AAEA,UAAI,WAAW,QAAW;AACzB,gBAAQ,KAAK,MAAM,MAAM;AAAA,MAC1B;AAAA,IACD;AACA,WAAO;AAAA,EACR;AAAA,EAEQ,iBAAiB,OAAe;AACvC,UAAM,OAAO,OAAO,KAAK,KAAK,EAAE,OAAO,CAAA,OAAM,OAAO,OAAO;AAC3D,UAAM,MAAM,OAAO,OAAO,MAAM,uBAAuB;AACvD,QAAI,KAAK,WAAW,KAAK,CAAC,IAAI,SAAS,KAAK,CAAC,CAAC,GAAG;AAChD,YAAM,QAAQ,KAAK,WAAW,IAAI,SAAS,KAAK,KAAK,IAAI;AACzD,YAAM,IAAI;AAAA,QACT,4BAA4B,IAAI,KAAK,IAAI,CAAC,KAAK,KAAK;AAAA,MAAA;AAAA,IAEtD;AAAA,EACD;AACD;"}
|
|
1
|
+
{"version":3,"file":"UpdateInputVisitor.js","sources":["../../../../../packages/engine-content-api/src/inputProcessing/UpdateInputVisitor.ts"],"sourcesContent":["import { Input, Model } from '@contember/schema'\nimport { filterObject } from '../utils/index.js'\nimport { UpdateInputProcessor } from './UpdateInputProcessor.js'\nimport { ImplementationException, UserError } from '../exception.js'\nimport { MapperInput } from '../mapper/index.js'\n\nexport class UpdateInputVisitor<Result> implements Model.ColumnVisitor<Promise<Result[]>>, Model.RelationByTypeVisitor<Promise<Result[]>> {\n\tconstructor(\n\t\tprivate readonly updateInputProcessor: UpdateInputProcessor<Result>,\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly data: MapperInput.UpdateDataInput,\n\t) {}\n\n\tpublic async visitColumn({ entity, column }: Model.ColumnContext): Promise<Result[]> {\n\t\treturn [\n\t\t\tawait this.updateInputProcessor.column({\n\t\t\t\tentity,\n\t\t\t\tcolumn,\n\t\t\t\tinput: this.data[column.name] as Input.ColumnValue,\n\t\t\t}),\n\t\t]\n\t}\n\n\tpublic visitManyHasManyInverse(context: Model.ManyHasManyInverseContext) {\n\t\treturn this.processManyRelationInput(\n\t\t\tthis.updateInputProcessor.manyHasManyInverse,\n\t\t\tcontext,\n\t\t\tthis.data[context.relation.name] as MapperInput.CreateManyRelationInput,\n\t\t)\n\t}\n\n\tpublic visitManyHasManyOwning(context: Model.ManyHasManyOwningContext) {\n\t\treturn this.processManyRelationInput(\n\t\t\tthis.updateInputProcessor.manyHasManyOwning,\n\t\t\tcontext,\n\t\t\tthis.data[context.relation.name] as MapperInput.CreateManyRelationInput,\n\t\t)\n\t}\n\n\tpublic visitManyHasOne(context: Model.ManyHasOneContext) {\n\t\treturn this.processRelationInput(\n\t\t\tthis.updateInputProcessor.manyHasOne,\n\t\t\tcontext,\n\t\t\tthis.data[context.relation.name] as MapperInput.CreateOneRelationInput,\n\t\t)\n\t}\n\n\tpublic visitOneHasMany(context: Model.OneHasManyContext) {\n\t\treturn this.processManyRelationInput(\n\t\t\tthis.updateInputProcessor.oneHasMany,\n\t\t\tcontext,\n\t\t\tthis.data[context.relation.name] as MapperInput.CreateManyRelationInput,\n\t\t)\n\t}\n\n\tpublic visitOneHasOneInverse(context: Model.OneHasOneInverseContext) {\n\t\treturn this.processRelationInput(\n\t\t\tthis.updateInputProcessor.oneHasOneInverse,\n\t\t\tcontext,\n\t\t\tthis.data[context.relation.name] as MapperInput.CreateOneRelationInput,\n\t\t)\n\t}\n\n\tpublic visitOneHasOneOwning(context: Model.OneHasOneOwningContext) {\n\t\treturn this.processRelationInput(\n\t\t\tthis.updateInputProcessor.oneHasOneOwning,\n\t\t\tcontext,\n\t\t\tthis.data[context.relation.name] as MapperInput.CreateOneRelationInput,\n\t\t)\n\t}\n\n\tprivate async processRelationInput<Context>(\n\t\tprocessor: UpdateInputProcessor.HasOneRelationInputProcessor<Context, Result>,\n\t\tcontext: Context,\n\t\tinput: MapperInput.UpdateOneRelationInput | undefined,\n\t): Promise<Result[]> {\n\t\tif (input === undefined || input === null) {\n\t\t\treturn Promise.resolve([])\n\t\t}\n\t\tinput = filterObject(input, (k, v) => v !== null && v !== undefined)\n\t\tthis.verifyOperations(input)\n\t\tif ('connect' in input) {\n\t\t\treturn [await processor.connect({ ...context, input: input.connect })]\n\t\t}\n\t\tif ('create' in input) {\n\t\t\treturn [await processor.create({ ...context, input: input.create })]\n\t\t}\n\t\tif ('connectOrCreate' in input) {\n\t\t\treturn [await processor.connectOrCreate({ ...context, input: input.connectOrCreate })]\n\t\t}\n\t\tif ('delete' in input) {\n\t\t\treturn [await processor.delete({ ...context, input: undefined })]\n\t\t}\n\t\tif ('disconnect' in input) {\n\t\t\treturn [await processor.disconnect({ ...context, input: undefined })]\n\t\t}\n\t\tif ('update' in input) {\n\t\t\treturn [await processor.update({ ...context, input: input.update })]\n\t\t}\n\t\tif ('upsert' in input) {\n\t\t\treturn [await processor.upsert({ ...context, input: input.upsert })]\n\t\t}\n\t\tthrow new ImplementationException()\n\t}\n\n\tprivate async processManyRelationInput<Context>(\n\t\tprocessor: UpdateInputProcessor.HasManyRelationInputProcessor<Context, Result>,\n\t\tcontext: Context,\n\t\tinput: MapperInput.UpdateManyRelationInput | undefined,\n\t): Promise<Result[]> {\n\t\tif (input === undefined || input === null) {\n\t\t\treturn Promise.resolve([])\n\t\t}\n\t\t// GraphQL coerces a single object into a single-element list, so a bare `{ set: ... }` arrives here as `[{ set: ... }]`.\n\t\tconst elements = Array.isArray(input) ? input : [input]\n\t\tconst hasSet = elements.some(it => it && (it as MapperInput.SetManyRelationInput).set != null)\n\t\tif (hasSet) {\n\t\t\tif (elements.length !== 1) {\n\t\t\t\tthrow new UserError('A \"set\" operation must be the only item of a has-many relation input.')\n\t\t\t}\n\t\t\treturn this.processSetRelationInput(processor, context, elements[0] as MapperInput.SetManyRelationInput)\n\t\t}\n\t\tconst results: Array<Result> = []\n\t\tlet i = 0\n\t\tfor (let element of elements as MapperInput.UpdateManyRelationInputItem[]) {\n\t\t\tconst alias = element.alias\n\t\t\telement = filterObject(element, (k, v) => v !== null && v !== undefined)\n\t\t\tthis.verifyOperations(element)\n\t\t\tlet result\n\t\t\tif ('connect' in element) {\n\t\t\t\tresult = processor.connect({ ...context, input: element.connect, index: i, alias })\n\t\t\t}\n\t\t\tif ('create' in element) {\n\t\t\t\tresult = processor.create({ ...context, input: element.create, index: i, alias })\n\t\t\t}\n\t\t\tif ('connectOrCreate' in element) {\n\t\t\t\tresult = processor.connectOrCreate({ ...context, input: element.connectOrCreate, index: i, alias })\n\t\t\t}\n\t\t\tif ('delete' in element) {\n\t\t\t\tresult = processor.delete({ ...context, input: element.delete, index: i, alias })\n\t\t\t}\n\t\t\tif ('disconnect' in element) {\n\t\t\t\tresult = processor.disconnect({ ...context, input: element.disconnect, index: i, alias })\n\t\t\t}\n\t\t\tif ('update' in element) {\n\t\t\t\tresult = processor.update({\n\t\t\t\t\t...context,\n\t\t\t\t\tinput: { where: element.update.by, data: element.update.data },\n\t\t\t\t\tindex: i,\n\t\t\t\t\talias,\n\t\t\t\t})\n\t\t\t}\n\t\t\tif ('upsert' in element) {\n\t\t\t\tresult = processor.upsert({\n\t\t\t\t\t...context,\n\t\t\t\t\tinput: { where: element.upsert.by, update: element.upsert.update, create: element.upsert.create },\n\t\t\t\t\tindex: i,\n\t\t\t\t\talias,\n\t\t\t\t})\n\t\t\t}\n\n\t\t\tif (result !== undefined) {\n\t\t\t\tresults.push(await result)\n\t\t\t}\n\t\t}\n\t\treturn results\n\t}\n\n\tprivate async processSetRelationInput<Context>(\n\t\tprocessor: UpdateInputProcessor.HasManyRelationInputProcessor<Context, Result>,\n\t\tcontext: Context,\n\t\tinput: MapperInput.SetManyRelationInput,\n\t): Promise<Result[]> {\n\t\tconst keys = Object.keys(filterObject(input, (k, v) => v !== null && v !== undefined))\n\t\tconst allowedKeys = ['set', 'orphanStrategy', 'alias']\n\t\tconst unexpected = keys.filter(it => !allowedKeys.includes(it))\n\t\tif (unexpected.length > 0) {\n\t\t\tthrow new UserError(\n\t\t\t\t`Unexpected key(s) ${unexpected.join(', ')} alongside \"set\". Only \"orphanStrategy\" and \"alias\" are allowed.`,\n\t\t\t)\n\t\t}\n\t\tconst orphanStrategy = input.orphanStrategy ?? Input.OrphanRemovalStrategy.disconnect\n\t\tif (!Object.values(Input.OrphanRemovalStrategy).includes(orphanStrategy)) {\n\t\t\tthrow new UserError(\n\t\t\t\t`Invalid orphanStrategy \"${orphanStrategy}\". Expected one of: ${Object.values(Input.OrphanRemovalStrategy).join(', ')}.`,\n\t\t\t)\n\t\t}\n\t\t// Strip null-valued keys before dispatching, exactly as the per-item path does: nullable\n\t\t// GraphQL variables are the reason `filterObject` exists, and both the pre-validator and\n\t\t// the mapper dispatch on key presence, so a `null` operation key would pick its branch.\n\t\tconst items = input.set.map(it => filterObject(it, (k, v) => v !== null && v !== undefined))\n\t\tfor (const item of items) {\n\t\t\tthis.verifySetItemOperations(item)\n\t\t}\n\t\treturn [\n\t\t\tawait processor.set({\n\t\t\t\t...context,\n\t\t\t\tinput: { items, orphanStrategy },\n\t\t\t}),\n\t\t]\n\t}\n\n\tprivate verifyOperations(input: object) {\n\t\tconst keys = Object.keys(input).filter(it => it !== 'alias')\n\t\t// `set` lives in the same enum but is not a per-item operation - accepting it here would\n\t\t// fall through to an ImplementationException (a 500) instead of a UserError.\n\t\tconst ops = (Object.values(Input.UpdateRelationOperation) as string[]).filter(it => it !== Input.UpdateRelationOperation.set)\n\t\tif (keys.length !== 1 || !ops.includes(keys[0])) {\n\t\t\tconst found = keys.length === 0 ? 'none' : keys.join(', ')\n\t\t\tthrow new UserError(\n\t\t\t\t`Expected exactly one of: ${ops.join(', ')}. ${found} found.`,\n\t\t\t)\n\t\t}\n\t}\n\n\tprivate verifySetItemOperations(input: object) {\n\t\tconst keys = Object.keys(filterObject(input, (k, v) => v !== null && v !== undefined)).filter(it => it !== 'alias')\n\t\tconst ops: string[] = [\n\t\t\tInput.UpdateRelationOperation.create,\n\t\t\tInput.UpdateRelationOperation.connect,\n\t\t\tInput.UpdateRelationOperation.connectOrCreate,\n\t\t\tInput.UpdateRelationOperation.update,\n\t\t\tInput.UpdateRelationOperation.upsert,\n\t\t]\n\t\tif (keys.length !== 1 || !ops.includes(keys[0])) {\n\t\t\tconst found = keys.length === 0 ? 'none' : keys.join(', ')\n\t\t\tthrow new UserError(\n\t\t\t\t`Expected exactly one of: ${ops.join(', ')} in a \"set\" item. ${found} found.`,\n\t\t\t)\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;;;AAMO,MAAM,mBAA6H;AAAA,EACzI,YACkB,sBACA,QACA,MAChB;AAHgB,SAAA,uBAAA;AACA,SAAA,SAAA;AACA,SAAA,OAAA;AAAA,EACf;AAAA,EAEH,MAAa,YAAY,EAAE,QAAQ,UAAkD;AACpF,WAAO;AAAA,MACN,MAAM,KAAK,qBAAqB,OAAO;AAAA,QACtC;AAAA,QACA;AAAA,QACA,OAAO,KAAK,KAAK,OAAO,IAAI;AAAA,MAAA,CAC5B;AAAA,IAAA;AAAA,EAEH;AAAA,EAEO,wBAAwB,SAA0C;AACxE,WAAO,KAAK;AAAA,MACX,KAAK,qBAAqB;AAAA,MAC1B;AAAA,MACA,KAAK,KAAK,QAAQ,SAAS,IAAI;AAAA,IAAA;AAAA,EAEjC;AAAA,EAEO,uBAAuB,SAAyC;AACtE,WAAO,KAAK;AAAA,MACX,KAAK,qBAAqB;AAAA,MAC1B;AAAA,MACA,KAAK,KAAK,QAAQ,SAAS,IAAI;AAAA,IAAA;AAAA,EAEjC;AAAA,EAEO,gBAAgB,SAAkC;AACxD,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,OAAO,OAAO;AAClH,UAAM,MAAgB;AAAA,MACrB,MAAM,wBAAwB;AAAA,MAC9B,MAAM,wBAAwB;AAAA,MAC9B,MAAM,wBAAwB;AAAA,MAC9B,MAAM,wBAAwB;AAAA,MAC9B,MAAM,wBAAwB;AAAA,IAAA;AAE/B,QAAI,KAAK,WAAW,KAAK,CAAC,IAAI,SAAS,KAAK,CAAC,CAAC,GAAG;AAChD,YAAM,QAAQ,KAAK,WAAW,IAAI,SAAS,KAAK,KAAK,IAAI;AACzD,YAAM,IAAI;AAAA,QACT,4BAA4B,IAAI,KAAK,IAAI,CAAC,qBAAqB,KAAK;AAAA,MAAA;AAAA,IAEtE;AAAA,EACD;AACD;"}
|
|
@@ -100,6 +100,16 @@ const convertError = (schema, databaseMetadata, e) => {
|
|
|
100
100
|
const paths = constraint ? constraint.fields.map((it) => [{ field: it }]) : [];
|
|
101
101
|
return new Result.MutationConstraintViolationError(paths, Result.ConstraintType.uniqueKey, message, [Result.MutationResultHint.sqlError]);
|
|
102
102
|
}
|
|
103
|
+
if (e instanceof Database__namespace.CheckViolationError) {
|
|
104
|
+
const entity = e.table ? getEntityByTableName(schema, e.table) : void 0;
|
|
105
|
+
const check = entity && e.constraint ? entity.checks?.find((it) => it.name === e.constraint) : void 0;
|
|
106
|
+
if (entity && check) {
|
|
107
|
+
const message = `Check constraint "${check.name}" on entity ${entity.name} violated`;
|
|
108
|
+
return new Result.MutationConstraintViolationError([], Result.ConstraintType.check, message, [Result.MutationResultHint.sqlError]);
|
|
109
|
+
}
|
|
110
|
+
logger.logger.warn(e, { loc: "convertError" });
|
|
111
|
+
return new Result.MutationConstraintViolationError([], Result.ConstraintType.check, e.originalMessage, [Result.MutationResultHint.sqlError]);
|
|
112
|
+
}
|
|
103
113
|
if (e instanceof UniqueWhereExpander.UniqueWhereError) {
|
|
104
114
|
return new Result.MutationInputError([], Result.InputErrorKind.nonUniqueWhere, e.message);
|
|
105
115
|
}
|