@contember/engine-content-api 2.0.0-alpha.20 → 2.0.0-alpha.21
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 +1 -1
- package/dist/development/index.js +1 -1
- package/dist/development/src/input-validation/preValidation/InputPreValidator.cjs +1 -1
- package/dist/development/src/input-validation/preValidation/InputPreValidator.cjs.map +1 -1
- package/dist/development/src/input-validation/preValidation/InputPreValidator.js +1 -1
- package/dist/development/src/input-validation/preValidation/InputPreValidator.js.map +1 -1
- package/dist/development/src/inputProcessing/CreateInputVisitor.cjs +10 -10
- package/dist/development/src/inputProcessing/CreateInputVisitor.cjs.map +1 -1
- package/dist/development/src/inputProcessing/CreateInputVisitor.js +10 -10
- package/dist/development/src/inputProcessing/CreateInputVisitor.js.map +1 -1
- package/dist/development/src/inputProcessing/UpdateInputVisitor.cjs +13 -13
- package/dist/development/src/inputProcessing/UpdateInputVisitor.cjs.map +1 -1
- package/dist/development/src/inputProcessing/UpdateInputVisitor.js +13 -13
- package/dist/development/src/inputProcessing/UpdateInputVisitor.js.map +1 -1
- package/dist/development/src/mapper/MutationProcessorHelper.cjs +10 -2
- package/dist/development/src/mapper/MutationProcessorHelper.cjs.map +1 -1
- package/dist/development/src/mapper/MutationProcessorHelper.js +10 -2
- package/dist/development/src/mapper/MutationProcessorHelper.js.map +1 -1
- package/dist/development/src/mapper/Result.cjs +10 -27
- package/dist/development/src/mapper/Result.cjs.map +1 -1
- package/dist/development/src/mapper/Result.js +10 -27
- package/dist/development/src/mapper/Result.js.map +1 -1
- package/dist/development/src/mapper/insert/InsertBuilder.cjs +1 -13
- package/dist/development/src/mapper/insert/InsertBuilder.cjs.map +1 -1
- package/dist/development/src/mapper/insert/InsertBuilder.js +1 -13
- package/dist/development/src/mapper/insert/InsertBuilder.js.map +1 -1
- package/dist/development/src/mapper/insert/Inserter.cjs +43 -21
- package/dist/development/src/mapper/insert/Inserter.cjs.map +1 -1
- package/dist/development/src/mapper/insert/Inserter.js +45 -23
- package/dist/development/src/mapper/insert/Inserter.js.map +1 -1
- package/dist/development/src/mapper/insert/SqlCreateInputProcessor.cjs +22 -76
- package/dist/development/src/mapper/insert/SqlCreateInputProcessor.cjs.map +1 -1
- package/dist/development/src/mapper/insert/SqlCreateInputProcessor.js +22 -76
- package/dist/development/src/mapper/insert/SqlCreateInputProcessor.js.map +1 -1
- package/dist/development/src/mapper/insert/relations/ManyHasManyCreateInputProcessor.cjs +45 -0
- package/dist/development/src/mapper/insert/relations/ManyHasManyCreateInputProcessor.cjs.map +1 -0
- package/dist/development/src/mapper/insert/relations/ManyHasManyCreateInputProcessor.js +45 -0
- package/dist/development/src/mapper/insert/relations/ManyHasManyCreateInputProcessor.js.map +1 -0
- package/dist/development/src/mapper/insert/relations/ManyHasOneCreateInputProcessor.cjs +42 -0
- package/dist/development/src/mapper/insert/relations/ManyHasOneCreateInputProcessor.cjs.map +1 -0
- package/dist/development/src/mapper/insert/relations/ManyHasOneCreateInputProcessor.js +42 -0
- package/dist/development/src/mapper/insert/relations/ManyHasOneCreateInputProcessor.js.map +1 -0
- package/dist/development/src/mapper/insert/relations/OneHasManyCreateInputProcessor.cjs +37 -0
- package/dist/development/src/mapper/insert/relations/OneHasManyCreateInputProcessor.cjs.map +1 -0
- package/dist/development/src/mapper/insert/relations/OneHasManyCreateInputProcessor.js +37 -0
- package/dist/development/src/mapper/insert/relations/OneHasManyCreateInputProcessor.js.map +1 -0
- package/dist/development/src/mapper/{relations → insert/relations}/OneHasOneInverseCreateInputProcessor.cjs +25 -32
- package/dist/development/src/mapper/insert/relations/OneHasOneInverseCreateInputProcessor.cjs.map +1 -0
- package/dist/development/src/mapper/{relations → insert/relations}/OneHasOneInverseCreateInputProcessor.js +25 -32
- package/dist/development/src/mapper/insert/relations/OneHasOneInverseCreateInputProcessor.js.map +1 -0
- package/dist/development/src/mapper/insert/relations/OneHasOneOwningCreateInputProcessor.cjs +67 -0
- package/dist/development/src/mapper/insert/relations/OneHasOneOwningCreateInputProcessor.cjs.map +1 -0
- package/dist/development/src/mapper/insert/relations/OneHasOneOwningCreateInputProcessor.js +67 -0
- package/dist/development/src/mapper/insert/relations/OneHasOneOwningCreateInputProcessor.js.map +1 -0
- package/dist/development/src/mapper/update/SqlUpdateInputProcessor.cjs +36 -36
- package/dist/development/src/mapper/update/SqlUpdateInputProcessor.cjs.map +1 -1
- package/dist/development/src/mapper/update/SqlUpdateInputProcessor.js +36 -36
- package/dist/development/src/mapper/update/SqlUpdateInputProcessor.js.map +1 -1
- package/dist/development/src/mapper/update/UpdateBuilder.cjs +2 -14
- package/dist/development/src/mapper/update/UpdateBuilder.cjs.map +1 -1
- package/dist/development/src/mapper/update/UpdateBuilder.js +2 -14
- package/dist/development/src/mapper/update/UpdateBuilder.js.map +1 -1
- package/dist/development/src/mapper/update/Updater.cjs +45 -17
- package/dist/development/src/mapper/update/Updater.cjs.map +1 -1
- package/dist/development/src/mapper/update/Updater.js +47 -19
- package/dist/development/src/mapper/update/Updater.js.map +1 -1
- package/dist/development/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.cjs +89 -0
- package/dist/development/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.cjs.map +1 -0
- package/dist/development/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.js +89 -0
- package/dist/development/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.js.map +1 -0
- package/dist/development/src/mapper/update/relations/ManyHasOneUpdateInputProcessor.cjs +89 -0
- package/dist/development/src/mapper/update/relations/ManyHasOneUpdateInputProcessor.cjs.map +1 -0
- package/dist/development/src/mapper/update/relations/ManyHasOneUpdateInputProcessor.js +89 -0
- package/dist/development/src/mapper/update/relations/ManyHasOneUpdateInputProcessor.js.map +1 -0
- package/dist/development/src/mapper/update/relations/OneHasManyUpdateInputProcessor.cjs +86 -0
- package/dist/development/src/mapper/update/relations/OneHasManyUpdateInputProcessor.cjs.map +1 -0
- package/dist/development/src/mapper/update/relations/OneHasManyUpdateInputProcessor.js +86 -0
- package/dist/development/src/mapper/update/relations/OneHasManyUpdateInputProcessor.js.map +1 -0
- package/dist/development/src/mapper/{relations → update/relations}/OneHasOneInverseUpdateInputProcessor.cjs +83 -66
- package/dist/development/src/mapper/update/relations/OneHasOneInverseUpdateInputProcessor.cjs.map +1 -0
- package/dist/development/src/mapper/{relations → update/relations}/OneHasOneInverseUpdateInputProcessor.js +83 -66
- package/dist/development/src/mapper/update/relations/OneHasOneInverseUpdateInputProcessor.js.map +1 -0
- package/dist/development/src/mapper/update/relations/OneHasOneOwningUpdateInputProcessor.cjs +187 -0
- package/dist/development/src/mapper/update/relations/OneHasOneOwningUpdateInputProcessor.cjs.map +1 -0
- package/dist/development/src/mapper/update/relations/OneHasOneOwningUpdateInputProcessor.js +187 -0
- package/dist/development/src/mapper/update/relations/OneHasOneOwningUpdateInputProcessor.js.map +1 -0
- package/dist/development/src/resolvers/MutationResolver.cjs +1 -1
- package/dist/development/src/resolvers/MutationResolver.js +1 -1
- package/dist/production/index.cjs +1 -1
- package/dist/production/index.js +1 -1
- package/dist/production/src/input-validation/preValidation/InputPreValidator.cjs +1 -1
- package/dist/production/src/input-validation/preValidation/InputPreValidator.cjs.map +1 -1
- package/dist/production/src/input-validation/preValidation/InputPreValidator.js +1 -1
- package/dist/production/src/input-validation/preValidation/InputPreValidator.js.map +1 -1
- package/dist/production/src/inputProcessing/CreateInputVisitor.cjs +10 -10
- package/dist/production/src/inputProcessing/CreateInputVisitor.cjs.map +1 -1
- package/dist/production/src/inputProcessing/CreateInputVisitor.js +10 -10
- package/dist/production/src/inputProcessing/CreateInputVisitor.js.map +1 -1
- package/dist/production/src/inputProcessing/UpdateInputVisitor.cjs +13 -13
- package/dist/production/src/inputProcessing/UpdateInputVisitor.cjs.map +1 -1
- package/dist/production/src/inputProcessing/UpdateInputVisitor.js +13 -13
- package/dist/production/src/inputProcessing/UpdateInputVisitor.js.map +1 -1
- package/dist/production/src/mapper/MutationProcessorHelper.cjs +10 -2
- package/dist/production/src/mapper/MutationProcessorHelper.cjs.map +1 -1
- package/dist/production/src/mapper/MutationProcessorHelper.js +10 -2
- package/dist/production/src/mapper/MutationProcessorHelper.js.map +1 -1
- package/dist/production/src/mapper/Result.cjs +10 -27
- package/dist/production/src/mapper/Result.cjs.map +1 -1
- package/dist/production/src/mapper/Result.js +10 -27
- package/dist/production/src/mapper/Result.js.map +1 -1
- package/dist/production/src/mapper/insert/InsertBuilder.cjs +1 -13
- package/dist/production/src/mapper/insert/InsertBuilder.cjs.map +1 -1
- package/dist/production/src/mapper/insert/InsertBuilder.js +1 -13
- package/dist/production/src/mapper/insert/InsertBuilder.js.map +1 -1
- package/dist/production/src/mapper/insert/Inserter.cjs +43 -21
- package/dist/production/src/mapper/insert/Inserter.cjs.map +1 -1
- package/dist/production/src/mapper/insert/Inserter.js +45 -23
- package/dist/production/src/mapper/insert/Inserter.js.map +1 -1
- package/dist/production/src/mapper/insert/SqlCreateInputProcessor.cjs +22 -76
- package/dist/production/src/mapper/insert/SqlCreateInputProcessor.cjs.map +1 -1
- package/dist/production/src/mapper/insert/SqlCreateInputProcessor.js +22 -76
- package/dist/production/src/mapper/insert/SqlCreateInputProcessor.js.map +1 -1
- package/dist/production/src/mapper/insert/relations/ManyHasManyCreateInputProcessor.cjs +45 -0
- package/dist/production/src/mapper/insert/relations/ManyHasManyCreateInputProcessor.cjs.map +1 -0
- package/dist/production/src/mapper/insert/relations/ManyHasManyCreateInputProcessor.js +45 -0
- package/dist/production/src/mapper/insert/relations/ManyHasManyCreateInputProcessor.js.map +1 -0
- package/dist/production/src/mapper/insert/relations/ManyHasOneCreateInputProcessor.cjs +42 -0
- package/dist/production/src/mapper/insert/relations/ManyHasOneCreateInputProcessor.cjs.map +1 -0
- package/dist/production/src/mapper/insert/relations/ManyHasOneCreateInputProcessor.js +42 -0
- package/dist/production/src/mapper/insert/relations/ManyHasOneCreateInputProcessor.js.map +1 -0
- package/dist/production/src/mapper/insert/relations/OneHasManyCreateInputProcessor.cjs +37 -0
- package/dist/production/src/mapper/insert/relations/OneHasManyCreateInputProcessor.cjs.map +1 -0
- package/dist/production/src/mapper/insert/relations/OneHasManyCreateInputProcessor.js +37 -0
- package/dist/production/src/mapper/insert/relations/OneHasManyCreateInputProcessor.js.map +1 -0
- package/dist/production/src/mapper/{relations → insert/relations}/OneHasOneInverseCreateInputProcessor.cjs +25 -32
- package/dist/production/src/mapper/insert/relations/OneHasOneInverseCreateInputProcessor.cjs.map +1 -0
- package/dist/production/src/mapper/{relations → insert/relations}/OneHasOneInverseCreateInputProcessor.js +25 -32
- package/dist/production/src/mapper/insert/relations/OneHasOneInverseCreateInputProcessor.js.map +1 -0
- package/dist/production/src/mapper/insert/relations/OneHasOneOwningCreateInputProcessor.cjs +67 -0
- package/dist/production/src/mapper/insert/relations/OneHasOneOwningCreateInputProcessor.cjs.map +1 -0
- package/dist/production/src/mapper/insert/relations/OneHasOneOwningCreateInputProcessor.js +67 -0
- package/dist/production/src/mapper/insert/relations/OneHasOneOwningCreateInputProcessor.js.map +1 -0
- package/dist/production/src/mapper/update/SqlUpdateInputProcessor.cjs +36 -36
- package/dist/production/src/mapper/update/SqlUpdateInputProcessor.cjs.map +1 -1
- package/dist/production/src/mapper/update/SqlUpdateInputProcessor.js +36 -36
- package/dist/production/src/mapper/update/SqlUpdateInputProcessor.js.map +1 -1
- package/dist/production/src/mapper/update/UpdateBuilder.cjs +2 -14
- package/dist/production/src/mapper/update/UpdateBuilder.cjs.map +1 -1
- package/dist/production/src/mapper/update/UpdateBuilder.js +2 -14
- package/dist/production/src/mapper/update/UpdateBuilder.js.map +1 -1
- package/dist/production/src/mapper/update/Updater.cjs +45 -17
- package/dist/production/src/mapper/update/Updater.cjs.map +1 -1
- package/dist/production/src/mapper/update/Updater.js +47 -19
- package/dist/production/src/mapper/update/Updater.js.map +1 -1
- package/dist/production/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.cjs +89 -0
- package/dist/production/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.cjs.map +1 -0
- package/dist/production/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.js +89 -0
- package/dist/production/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.js.map +1 -0
- package/dist/production/src/mapper/update/relations/ManyHasOneUpdateInputProcessor.cjs +89 -0
- package/dist/production/src/mapper/update/relations/ManyHasOneUpdateInputProcessor.cjs.map +1 -0
- package/dist/production/src/mapper/update/relations/ManyHasOneUpdateInputProcessor.js +89 -0
- package/dist/production/src/mapper/update/relations/ManyHasOneUpdateInputProcessor.js.map +1 -0
- package/dist/production/src/mapper/update/relations/OneHasManyUpdateInputProcessor.cjs +86 -0
- package/dist/production/src/mapper/update/relations/OneHasManyUpdateInputProcessor.cjs.map +1 -0
- package/dist/production/src/mapper/update/relations/OneHasManyUpdateInputProcessor.js +86 -0
- package/dist/production/src/mapper/update/relations/OneHasManyUpdateInputProcessor.js.map +1 -0
- package/dist/production/src/mapper/{relations → update/relations}/OneHasOneInverseUpdateInputProcessor.cjs +83 -66
- package/dist/production/src/mapper/update/relations/OneHasOneInverseUpdateInputProcessor.cjs.map +1 -0
- package/dist/production/src/mapper/{relations → update/relations}/OneHasOneInverseUpdateInputProcessor.js +83 -66
- package/dist/production/src/mapper/update/relations/OneHasOneInverseUpdateInputProcessor.js.map +1 -0
- package/dist/production/src/mapper/update/relations/OneHasOneOwningUpdateInputProcessor.cjs +187 -0
- package/dist/production/src/mapper/update/relations/OneHasOneOwningUpdateInputProcessor.cjs.map +1 -0
- package/dist/production/src/mapper/update/relations/OneHasOneOwningUpdateInputProcessor.js +187 -0
- package/dist/production/src/mapper/update/relations/OneHasOneOwningUpdateInputProcessor.js.map +1 -0
- package/dist/production/src/resolvers/MutationResolver.cjs +1 -1
- package/dist/production/src/resolvers/MutationResolver.js +1 -1
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/dist/types/input-validation/preValidation/InputPreValidator.d.ts.map +1 -1
- package/dist/types/inputProcessing/CreateInputVisitor.d.ts +8 -8
- package/dist/types/inputProcessing/CreateInputVisitor.d.ts.map +1 -1
- package/dist/types/inputProcessing/UpdateInputVisitor.d.ts +8 -8
- package/dist/types/inputProcessing/UpdateInputVisitor.d.ts.map +1 -1
- package/dist/types/mapper/MutationProcessorHelper.d.ts +2 -2
- package/dist/types/mapper/MutationProcessorHelper.d.ts.map +1 -1
- package/dist/types/mapper/Result.d.ts +11 -5
- package/dist/types/mapper/Result.d.ts.map +1 -1
- package/dist/types/mapper/insert/InsertBuilder.d.ts +3 -7
- package/dist/types/mapper/insert/InsertBuilder.d.ts.map +1 -1
- package/dist/types/mapper/insert/Inserter.d.ts +0 -1
- package/dist/types/mapper/insert/Inserter.d.ts.map +1 -1
- package/dist/types/mapper/insert/SqlCreateInputProcessor.d.ts +11 -8
- package/dist/types/mapper/insert/SqlCreateInputProcessor.d.ts.map +1 -1
- package/dist/types/mapper/insert/relations/ManyHasManyCreateInputProcessor.d.ts +24 -0
- package/dist/types/mapper/insert/relations/ManyHasManyCreateInputProcessor.d.ts.map +1 -0
- package/dist/types/mapper/insert/relations/ManyHasOneCreateInputProcessor.d.ts +23 -0
- package/dist/types/mapper/insert/relations/ManyHasOneCreateInputProcessor.d.ts.map +1 -0
- package/dist/types/mapper/insert/relations/OneHasManyCreateInputProcessor.d.ts +26 -0
- package/dist/types/mapper/insert/relations/OneHasManyCreateInputProcessor.d.ts.map +1 -0
- package/dist/types/mapper/insert/relations/OneHasOneInverseCreateInputProcessor.d.ts +29 -0
- package/dist/types/mapper/insert/relations/OneHasOneInverseCreateInputProcessor.d.ts.map +1 -0
- package/dist/types/mapper/insert/relations/OneHasOneOwningCreateInputProcessor.d.ts +24 -0
- package/dist/types/mapper/insert/relations/OneHasOneOwningCreateInputProcessor.d.ts.map +1 -0
- package/dist/types/mapper/update/SqlUpdateInputProcessor.d.ts +10 -7
- package/dist/types/mapper/update/SqlUpdateInputProcessor.d.ts.map +1 -1
- package/dist/types/mapper/update/UpdateBuilder.d.ts +2 -6
- package/dist/types/mapper/update/UpdateBuilder.d.ts.map +1 -1
- package/dist/types/mapper/update/Updater.d.ts +0 -1
- package/dist/types/mapper/update/Updater.d.ts.map +1 -1
- package/dist/types/mapper/update/relations/ManyHasManyUpdateInputProcessor.d.ts +46 -0
- package/dist/types/mapper/update/relations/ManyHasManyUpdateInputProcessor.d.ts.map +1 -0
- package/dist/types/mapper/update/relations/ManyHasOneUpdateInputProcessor.d.ts +40 -0
- package/dist/types/mapper/update/relations/ManyHasOneUpdateInputProcessor.d.ts.map +1 -0
- package/dist/types/mapper/update/relations/OneHasManyUpdateInputProcessor.d.ts +46 -0
- package/dist/types/mapper/update/relations/OneHasManyUpdateInputProcessor.d.ts.map +1 -0
- package/dist/types/mapper/{relations → update/relations}/OneHasOneInverseUpdateInputProcessor.d.ts +17 -13
- package/dist/types/mapper/update/relations/OneHasOneInverseUpdateInputProcessor.d.ts.map +1 -0
- package/dist/types/mapper/{relations → update/relations}/OneHasOneOwningUpdateInputProcessor.d.ts +19 -16
- package/dist/types/mapper/update/relations/OneHasOneOwningUpdateInputProcessor.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -10
- package/src/input-validation/preValidation/InputPreValidator.ts +3 -5
- package/src/inputProcessing/CreateInputVisitor.ts +14 -14
- package/src/inputProcessing/UpdateInputVisitor.ts +17 -17
- package/src/mapper/MutationProcessorHelper.ts +16 -8
- package/src/mapper/Result.ts +11 -47
- package/src/mapper/insert/InsertBuilder.ts +8 -22
- package/src/mapper/insert/Inserter.ts +53 -40
- package/src/mapper/insert/SqlCreateInputProcessor.ts +35 -88
- package/src/mapper/insert/relations/ManyHasManyCreateInputProcessor.ts +59 -0
- package/src/mapper/insert/relations/ManyHasOneCreateInputProcessor.ts +57 -0
- package/src/mapper/insert/relations/OneHasManyCreateInputProcessor.ts +50 -0
- package/src/mapper/insert/relations/OneHasOneInverseCreateInputProcessor.ts +91 -0
- package/src/mapper/insert/relations/OneHasOneOwningCreateInputProcessor.ts +87 -0
- package/src/mapper/update/SqlUpdateInputProcessor.ts +48 -46
- package/src/mapper/update/UpdateBuilder.ts +9 -23
- package/src/mapper/update/Updater.ts +53 -34
- package/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.ts +116 -0
- package/src/mapper/update/relations/ManyHasOneUpdateInputProcessor.ts +125 -0
- package/src/mapper/update/relations/OneHasManyUpdateInputProcessor.ts +111 -0
- package/src/mapper/{relations → update/relations}/OneHasOneInverseUpdateInputProcessor.ts +93 -73
- package/src/mapper/update/relations/OneHasOneOwningUpdateInputProcessor.ts +243 -0
- package/tests/cases/integration/graphQlRequests/insert/oneHasMany/create.test.ts +8 -8
- package/tests/cases/integration/graphQlRequests/update/oneHasMany/connectOrCreate.test.ts +4 -4
- package/dist/development/src/mapper/DataManipulationBuilder.cjs +0 -5
- package/dist/development/src/mapper/DataManipulationBuilder.cjs.map +0 -1
- package/dist/development/src/mapper/DataManipulationBuilder.js +0 -5
- package/dist/development/src/mapper/DataManipulationBuilder.js.map +0 -1
- package/dist/development/src/mapper/relations/ManyHasManyInputProcessor.cjs +0 -75
- package/dist/development/src/mapper/relations/ManyHasManyInputProcessor.cjs.map +0 -1
- package/dist/development/src/mapper/relations/ManyHasManyInputProcessor.js +0 -75
- package/dist/development/src/mapper/relations/ManyHasManyInputProcessor.js.map +0 -1
- package/dist/development/src/mapper/relations/ManyHasOneInputProcessor.cjs +0 -114
- package/dist/development/src/mapper/relations/ManyHasOneInputProcessor.cjs.map +0 -1
- package/dist/development/src/mapper/relations/ManyHasOneInputProcessor.js +0 -114
- package/dist/development/src/mapper/relations/ManyHasOneInputProcessor.js.map +0 -1
- package/dist/development/src/mapper/relations/OneHasManyInputProcessor.cjs +0 -72
- package/dist/development/src/mapper/relations/OneHasManyInputProcessor.cjs.map +0 -1
- package/dist/development/src/mapper/relations/OneHasManyInputProcessor.js +0 -72
- package/dist/development/src/mapper/relations/OneHasManyInputProcessor.js.map +0 -1
- package/dist/development/src/mapper/relations/OneHasOneInverseCreateInputProcessor.cjs.map +0 -1
- package/dist/development/src/mapper/relations/OneHasOneInverseCreateInputProcessor.js.map +0 -1
- package/dist/development/src/mapper/relations/OneHasOneInverseUpdateInputProcessor.cjs.map +0 -1
- package/dist/development/src/mapper/relations/OneHasOneInverseUpdateInputProcessor.js.map +0 -1
- package/dist/development/src/mapper/relations/OneHasOneOwningCreateInputProcessor.cjs +0 -71
- package/dist/development/src/mapper/relations/OneHasOneOwningCreateInputProcessor.cjs.map +0 -1
- package/dist/development/src/mapper/relations/OneHasOneOwningCreateInputProcessor.js +0 -71
- package/dist/development/src/mapper/relations/OneHasOneOwningCreateInputProcessor.js.map +0 -1
- package/dist/development/src/mapper/relations/OneHasOneOwningUpdateInputProcessor.cjs +0 -200
- package/dist/development/src/mapper/relations/OneHasOneOwningUpdateInputProcessor.cjs.map +0 -1
- package/dist/development/src/mapper/relations/OneHasOneOwningUpdateInputProcessor.js +0 -200
- package/dist/development/src/mapper/relations/OneHasOneOwningUpdateInputProcessor.js.map +0 -1
- package/dist/production/src/mapper/DataManipulationBuilder.cjs +0 -5
- package/dist/production/src/mapper/DataManipulationBuilder.cjs.map +0 -1
- package/dist/production/src/mapper/DataManipulationBuilder.js +0 -5
- package/dist/production/src/mapper/DataManipulationBuilder.js.map +0 -1
- package/dist/production/src/mapper/relations/ManyHasManyInputProcessor.cjs +0 -75
- package/dist/production/src/mapper/relations/ManyHasManyInputProcessor.cjs.map +0 -1
- package/dist/production/src/mapper/relations/ManyHasManyInputProcessor.js +0 -75
- package/dist/production/src/mapper/relations/ManyHasManyInputProcessor.js.map +0 -1
- package/dist/production/src/mapper/relations/ManyHasOneInputProcessor.cjs +0 -114
- package/dist/production/src/mapper/relations/ManyHasOneInputProcessor.cjs.map +0 -1
- package/dist/production/src/mapper/relations/ManyHasOneInputProcessor.js +0 -114
- package/dist/production/src/mapper/relations/ManyHasOneInputProcessor.js.map +0 -1
- package/dist/production/src/mapper/relations/OneHasManyInputProcessor.cjs +0 -72
- package/dist/production/src/mapper/relations/OneHasManyInputProcessor.cjs.map +0 -1
- package/dist/production/src/mapper/relations/OneHasManyInputProcessor.js +0 -72
- package/dist/production/src/mapper/relations/OneHasManyInputProcessor.js.map +0 -1
- package/dist/production/src/mapper/relations/OneHasOneInverseCreateInputProcessor.cjs.map +0 -1
- package/dist/production/src/mapper/relations/OneHasOneInverseCreateInputProcessor.js.map +0 -1
- package/dist/production/src/mapper/relations/OneHasOneInverseUpdateInputProcessor.cjs.map +0 -1
- package/dist/production/src/mapper/relations/OneHasOneInverseUpdateInputProcessor.js.map +0 -1
- package/dist/production/src/mapper/relations/OneHasOneOwningCreateInputProcessor.cjs +0 -71
- package/dist/production/src/mapper/relations/OneHasOneOwningCreateInputProcessor.cjs.map +0 -1
- package/dist/production/src/mapper/relations/OneHasOneOwningCreateInputProcessor.js +0 -71
- package/dist/production/src/mapper/relations/OneHasOneOwningCreateInputProcessor.js.map +0 -1
- package/dist/production/src/mapper/relations/OneHasOneOwningUpdateInputProcessor.cjs +0 -200
- package/dist/production/src/mapper/relations/OneHasOneOwningUpdateInputProcessor.cjs.map +0 -1
- package/dist/production/src/mapper/relations/OneHasOneOwningUpdateInputProcessor.js +0 -200
- package/dist/production/src/mapper/relations/OneHasOneOwningUpdateInputProcessor.js.map +0 -1
- package/dist/types/mapper/DataManipulationBuilder.d.ts +0 -7
- package/dist/types/mapper/DataManipulationBuilder.d.ts.map +0 -1
- package/dist/types/mapper/relations/ManyHasManyInputProcessor.d.ts +0 -32
- package/dist/types/mapper/relations/ManyHasManyInputProcessor.d.ts.map +0 -1
- package/dist/types/mapper/relations/ManyHasOneInputProcessor.d.ts +0 -32
- package/dist/types/mapper/relations/ManyHasOneInputProcessor.d.ts.map +0 -1
- package/dist/types/mapper/relations/OneHasManyInputProcessor.d.ts +0 -29
- package/dist/types/mapper/relations/OneHasManyInputProcessor.d.ts.map +0 -1
- package/dist/types/mapper/relations/OneHasOneInverseCreateInputProcessor.d.ts +0 -21
- package/dist/types/mapper/relations/OneHasOneInverseCreateInputProcessor.d.ts.map +0 -1
- package/dist/types/mapper/relations/OneHasOneInverseUpdateInputProcessor.d.ts.map +0 -1
- package/dist/types/mapper/relations/OneHasOneOwningCreateInputProcessor.d.ts +0 -21
- package/dist/types/mapper/relations/OneHasOneOwningCreateInputProcessor.d.ts.map +0 -1
- package/dist/types/mapper/relations/OneHasOneOwningUpdateInputProcessor.d.ts.map +0 -1
- package/src/mapper/DataManipulationBuilder.ts +0 -12
- package/src/mapper/relations/ManyHasManyInputProcessor.ts +0 -108
- package/src/mapper/relations/ManyHasOneInputProcessor.ts +0 -158
- package/src/mapper/relations/OneHasManyInputProcessor.ts +0 -101
- package/src/mapper/relations/OneHasOneInverseCreateInputProcessor.ts +0 -99
- package/src/mapper/relations/OneHasOneOwningCreateInputProcessor.ts +0 -92
- package/src/mapper/relations/OneHasOneOwningUpdateInputProcessor.ts +0 -253
|
@@ -57,9 +57,9 @@ const EntityRulesResolver = require("./src/input-validation/EntityRulesResolver.
|
|
|
57
57
|
const ExecutionContainer = require("./src/ExecutionContainer.cjs");
|
|
58
58
|
const graphql = require("graphql");
|
|
59
59
|
require("@contember/database");
|
|
60
|
-
require("@contember/logger");
|
|
61
60
|
const EventManager = require("./src/mapper/EventManager.cjs");
|
|
62
61
|
const Path = require("./src/mapper/select/Path.cjs");
|
|
62
|
+
require("@contember/logger");
|
|
63
63
|
const WhereBuilder = require("./src/mapper/select/WhereBuilder.cjs");
|
|
64
64
|
const Mapper = require("./src/mapper/Mapper.cjs");
|
|
65
65
|
const MapperFactory = require("./src/mapper/MapperFactory.cjs");
|
|
@@ -55,9 +55,9 @@ import { EntityRulesResolver } from "./src/input-validation/EntityRulesResolver.
|
|
|
55
55
|
import { ExecutionContainerFactory } from "./src/ExecutionContainer.js";
|
|
56
56
|
import { graphql } from "graphql";
|
|
57
57
|
import "@contember/database";
|
|
58
|
-
import "@contember/logger";
|
|
59
58
|
import { AfterCommitEvent, AfterInsertEvent, AfterJunctionUpdateEvent, AfterUpdateEvent, BeforeCommitEvent, BeforeDeleteEvent, BeforeInsertEvent, BeforeJunctionUpdateEvent, BeforeUpdateEvent, EventManager } from "./src/mapper/EventManager.js";
|
|
60
59
|
import { Path, PathFactory } from "./src/mapper/select/Path.js";
|
|
60
|
+
import "@contember/logger";
|
|
61
61
|
import { WhereBuilder } from "./src/mapper/select/WhereBuilder.js";
|
|
62
62
|
import { Mapper } from "./src/mapper/Mapper.js";
|
|
63
63
|
import { MapperFactory } from "./src/mapper/MapperFactory.js";
|
|
@@ -109,7 +109,7 @@ class InputPreValidator {
|
|
|
109
109
|
}
|
|
110
110
|
async validateRelations(entity, visitor) {
|
|
111
111
|
const validateRelationsResult = schemaUtils.acceptEveryFieldVisitor(this.model, entity, visitor);
|
|
112
|
-
return (await Promise.all(Object.values(validateRelationsResult))).
|
|
112
|
+
return (await Promise.all(Object.values(validateRelationsResult))).flatMap((it) => it.flat());
|
|
113
113
|
}
|
|
114
114
|
getApplicableRules(changedFields, entityRules) {
|
|
115
115
|
return Object.fromEntries(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InputPreValidator.cjs","sources":["../../../../../../packages/engine-content-api/src/input-validation/preValidation/InputPreValidator.ts"],"sourcesContent":["import { acceptEveryFieldVisitor } from '@contember/schema-utils'\nimport { isIt, tuple } from '../../utils'\nimport { Input, Model, Validation, Value } from '@contember/schema'\nimport { InputValidation } from '@contember/schema-definition'\nimport { CreateInputVisitor, UpdateInputVisitor } from '../../inputProcessing'\nimport { CreateInputPreValidationProcessor } from './CreateInputPreValidationProcessor'\nimport { ValidationContext } from '../ValidationContext'\nimport { evaluateValidation } from '../ValidationEvaluation'\nimport { ValidationPath } from '../ValidationPath'\nimport { EntityRulesResolver } from '../EntityRulesResolver'\nimport { FieldValidationResult, ValidationResult } from '../InputValidator'\nimport { UpdateInputPreValidationProcessor } from './UpdateInputPreValidationProcessor'\nimport { ColumnValueResolver } from '../ColumnValueResolver'\nimport { Mapper } from '../../mapper'\nimport { Dependencies, DependencyCollector } from '../dependencies'\nimport { DependencyMerger } from '../dependencies'\nimport { NotSupportedError } from '../exceptions'\nimport { ValidationDataSelector } from '../ValidationDataSelector'\n\nexport interface CreateValidationArgs {\n\tmapper: Mapper\n\tentity: Model.Entity\n\tdata: Input.CreateDataInput\n\tpath: ValidationPath\n\toverRelation: Model.AnyRelation | null\n}\n\nexport interface UpdateValidationArgs {\n\tmapper: Mapper\n\tentity: Model.Entity\n\twhere: Input.UniqueWhere\n\tdata: Input.UpdateDataInput\n\tpath: ValidationPath\n}\n\nexport class InputPreValidator {\n\tconstructor(\n\t\tprivate readonly model: Model.Schema,\n\t\tprivate readonly entityRulesResolver: EntityRulesResolver,\n\t\tprivate readonly columnValueResolver: ColumnValueResolver,\n\t\tprivate readonly dataSelector: ValidationDataSelector,\n\t) {}\n\n\tasync validateCreate({ entity, data, path, mapper, overRelation }: CreateValidationArgs): Promise<ValidationResult> {\n\t\tconst rules = this.entityRulesResolver.getSimpleRules(entity.name)\n\n\t\tconst dataWithRelation = overRelation\n\t\t\t? {\n\t\t\t\t...data,\n\t\t\t\t[overRelation.name]: { create: {} },\n\t\t\t }\n\t\t\t: data\n\t\tconst context = this.createContextForCreate(entity, dataWithRelation)\n\n\t\tconst fieldsResult = this.validateFields(rules, context, path)\n\n\t\tconst processor = new CreateInputPreValidationProcessor(this, path, mapper)\n\t\tconst visitor = new CreateInputVisitor(processor, this.model, data)\n\t\tconst relationResult = await this.validateRelations(entity, visitor)\n\n\t\treturn [...fieldsResult, ...relationResult]\n\t}\n\n\tasync validateUpdate({ entity, data, path, mapper, where }: UpdateValidationArgs): Promise<ValidationResult> {\n\t\tconst simpleRules = this.entityRulesResolver.getSimpleRules(entity.name)\n\t\tconst rules = this.getApplicableRules(Object.keys(data), simpleRules)\n\t\tconst dependencies = this.buildDependencies(rules)\n\n\t\tconst context = await this.createContextForUpdate(mapper, entity, where, data, dependencies)\n\t\tconst fieldsResult: ValidationResult = this.validateFields(rules, context, path)\n\n\t\tconst processor = new UpdateInputPreValidationProcessor(this, path, mapper)\n\t\tconst visitor = new UpdateInputVisitor(processor, this.model, data)\n\t\tconst relationResult = await this.validateRelations(entity, visitor)\n\n\t\treturn [...fieldsResult, ...relationResult]\n\t}\n\n\tprivate createContextForCreate(entity: Model.Entity, data: Input.CreateDataInput): ValidationContext.NodeContext {\n\t\tconst nodeData = acceptEveryFieldVisitor(this.model, entity, {\n\t\t\tvisitColumn: ({ entity, column }) => {\n\t\t\t\tconst value = data[column.name] as Input.ColumnValue | undefined\n\t\t\t\tconst validationValue = this.columnValueResolver.getDefaultValidationValue({ entity, column, input: value })\n\t\t\t\treturn validationValue === undefined ? null : validationValue\n\t\t\t},\n\t\t\tvisitHasOne: ({ relation }) => {\n\t\t\t\tconst value = data[relation.name] as Input.CreateOneRelationInput | undefined\n\t\t\t\treturn value ? true : null\n\t\t\t},\n\t\t\t// more complex validation on relations are not possible in pre-validation phase\n\t\t\tvisitHasMany: () => null,\n\t\t})\n\n\t\treturn ValidationContext.createRootContext(nodeData)\n\t}\n\tprivate async createContextForUpdate(\n\t\tmapper: Mapper,\n\t\tentity: Model.Entity,\n\t\twhere: Input.UniqueWhere,\n\t\tdata: Input.UpdateDataInput,\n\t\tdependencies: Dependencies,\n\t): Promise<ValidationContext.NodeContext> {\n\t\tconst inputNodeData = acceptEveryFieldVisitor(this.model, entity, {\n\t\t\tvisitColumn: ({ column }) => {\n\t\t\t\treturn data[column.name] as Input.ColumnValue | undefined\n\t\t\t},\n\t\t\tvisitHasOne: ({ relation }) => {\n\t\t\t\tconst value = data[relation.name] as Input.CreateOneRelationInput | Input.UpdateOneRelationInput | undefined | null\n\t\t\t\tif (value === undefined || value === null) {\n\t\t\t\t\treturn undefined\n\t\t\t\t}\n\t\t\t\tif ('disconnect' in value) {\n\t\t\t\t\treturn null\n\t\t\t\t}\n\t\t\t\tif ('delete' in value) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tisIt<Model.JoiningColumnRelation>(relation, 'joiningColumn') &&\n\t\t\t\t\t\trelation.joiningColumn.onDelete === Model.OnDelete.cascade\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn true\n\t\t\t\t\t}\n\t\t\t\t\treturn null\n\t\t\t\t}\n\t\t\t\treturn true\n\t\t\t},\n\t\t\t// more complex validation on relations are not possible in pre-validation phase\n\t\t\tvisitHasMany: () => null,\n\t\t})\n\n\t\tconst missingDependencies = Object.keys(dependencies).filter(it => inputNodeData[it] === undefined)\n\t\tmissingDependencies.forEach(it => {\n\t\t\tif (Object.keys(dependencies[it]).length !== 0) {\n\t\t\t\tthrow new NotSupportedError()\n\t\t\t}\n\t\t})\n\n\t\tconst dbData = await this.dataSelector.select(\n\t\t\tmapper,\n\t\t\tentity,\n\t\t\twhere,\n\t\t\tmissingDependencies.reduce((acc, field) => ({ ...acc, [field]: {} }), {}),\n\t\t)\n\n\t\treturn ValidationContext.createRootContext({ ...(inputNodeData as Value.Object), ...(dbData || {}) })\n\t}\n\n\tprivate validateFields(rules: Validation.EntityRules, context: ValidationContext.NodeContext, path: ValidationPath) {\n\t\treturn Object.entries(rules)\n\t\t\t.map(([field, fieldRules]) =>\n\t\t\t\ttuple(\n\t\t\t\t\tfield,\n\t\t\t\t\tfieldRules.find(it => evaluateValidation(context, InputValidation.rules.on(field, it.validator)) === false),\n\t\t\t\t),\n\t\t\t)\n\t\t\t.filter((arg): arg is [string, Validation.ValidationRule] => !!arg[1])\n\t\t\t.map(([field, { message }]) => ({ path: [...path, { field }], message }))\n\t}\n\n\tprivate async validateRelations(\n\t\tentity: Model.Entity,\n\t\tvisitor: Model.FieldVisitor<Promise<ValidationResult | ValidationResult[] | undefined>>,\n\t): Promise<FieldValidationResult[]> {\n\t\tconst validateRelationsResult = acceptEveryFieldVisitor(this.model, entity, visitor)\n\n\t\treturn (await Promise.all(Object.values(validateRelationsResult)))\n\t\t\t.filter((value): value is FieldValidationResult[] | FieldValidationResult[][] => value !== undefined)\n\t\t\t.reduce<(FieldValidationResult[] | FieldValidationResult)[]>((res, it) => [...res, ...it], [])\n\t\t\t.reduce<FieldValidationResult[]>((res, it) => [...res, ...(Array.isArray(it) ? it : [it])], [])\n\t}\n\n\tprivate getApplicableRules(changedFields: string[], entityRules: Validation.EntityRules): Validation.EntityRules {\n\t\treturn Object.fromEntries(\n\t\t\tObject.entries(entityRules)\n\t\t\t\t.map(([field, fieldRules]) => {\n\t\t\t\t\treturn tuple(\n\t\t\t\t\t\tfield,\n\t\t\t\t\t\tchangedFields.includes(field)\n\t\t\t\t\t\t\t? fieldRules\n\t\t\t\t\t\t\t: fieldRules.filter(rule =>\n\t\t\t\t\t\t\t\tObject.keys(DependencyCollector.collect(rule.validator)).find(it => changedFields.includes(it)),\n\t\t\t\t\t\t\t ),\n\t\t\t\t\t)\n\t\t\t\t})\n\t\t\t\t.filter(([, it]) => it.length > 0),\n\t\t)\n\t}\n\n\tprivate buildDependencies(rules: Validation.EntityRules): Dependencies {\n\t\tconst baseFieldsAsDeps = Object.keys(rules).reduce((acc, field) => ({ ...acc, [field]: {} }), {})\n\n\t\treturn Object.values(rules)\n\t\t\t.flatMap(it => it)\n\t\t\t.map(it => DependencyCollector.collect(it.validator))\n\t\t\t.concat(baseFieldsAsDeps)\n\t\t\t.reduce((acc, dependecy) => DependencyMerger.merge(acc, dependecy), {})\n\t}\n}\n"],"names":["CreateInputPreValidationProcessor","CreateInputVisitor","UpdateInputPreValidationProcessor","UpdateInputVisitor","acceptEveryFieldVisitor","entity","ValidationContext","isIt","Model","NotSupportedError","tuple","evaluateValidation","InputValidation","DependencyCollector","DependencyMerger"],"mappings":";;;;;;;;;;;;;;;;AAmCO,MAAM,kBAAkB;AAAA,EAC9B,YACkB,OACA,qBACA,qBACA,cAChB;AAJgB,SAAA,QAAA;AACA,SAAA,sBAAA;AACA,SAAA,sBAAA;AACA,SAAA,eAAA;AAAA,EACf;AAAA,EAEH,MAAM,eAAe,EAAE,QAAQ,MAAM,MAAM,QAAQ,gB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IAAI,CAAC,CAAC,OAAO,UAAU,MAAM;AACtB,eAAAM,MAAA;AAAA,UACN;AAAA,UACA,cAAc,SAAS,KAAK,IACzB,aACA,WAAW;AAAA,YAAO,CACnB,SAAA,OAAO,KAAKG,oBAAAA,oBAAoB,QAAQ,KAAK,SAAS,CAAC,EAAE,KAAK,CAAA,OAAM,cAAc,SAAS,EAAE,CAAC;AAAA,UAC7F;AAAA,QAAA;AAAA,MACJ,CACA,EACA,OAAO,CAAC,CAAG,EAAA,EAAE,MAAM,GAAG,SAAS,CAAC;AAAA,IAAA;AAAA,EAEpC;AAAA,EAEQ,kBAAkB,OAA6C;AACtE,UAAM,mBAAmB,OAAO,KAAK,KAAK,EAAE,OAAO,CAAC,KAAK,WAAW,EAAE,GAAG,KAAK,CAAC,KAAK,GAAG,CAAA,EAAG,IAAI,CAAA,CAAE;AAEhG,WAAO,OAAO,OAAO,KAAK,EACxB,QAAQ,CAAA,OAAM,EAAE,EAChB,IAAI,CAAA,OAAMA,oBAAoB,oBAAA,QAAQ,GAAG,SAAS,CAAC,EACnD,OAAO,gBAAgB,EACvB,OAAO,CAAC,KAAK,cAAcC,iBAAAA,iBAAiB,MAAM,KAAK,SAAS,GAAG,CAAE,CAAA;AAAA,EACxE;AACD;;"}
|
|
1
|
+
{"version":3,"file":"InputPreValidator.cjs","sources":["../../../../../../packages/engine-content-api/src/input-validation/preValidation/InputPreValidator.ts"],"sourcesContent":["import { acceptEveryFieldVisitor } from '@contember/schema-utils'\nimport { isIt, tuple } from '../../utils'\nimport { Input, Model, Validation, Value } from '@contember/schema'\nimport { InputValidation } from '@contember/schema-definition'\nimport { CreateInputVisitor, UpdateInputVisitor } from '../../inputProcessing'\nimport { CreateInputPreValidationProcessor } from './CreateInputPreValidationProcessor'\nimport { ValidationContext } from '../ValidationContext'\nimport { evaluateValidation } from '../ValidationEvaluation'\nimport { ValidationPath } from '../ValidationPath'\nimport { EntityRulesResolver } from '../EntityRulesResolver'\nimport { FieldValidationResult, ValidationResult } from '../InputValidator'\nimport { UpdateInputPreValidationProcessor } from './UpdateInputPreValidationProcessor'\nimport { ColumnValueResolver } from '../ColumnValueResolver'\nimport { Mapper } from '../../mapper'\nimport { Dependencies, DependencyCollector } from '../dependencies'\nimport { DependencyMerger } from '../dependencies'\nimport { NotSupportedError } from '../exceptions'\nimport { ValidationDataSelector } from '../ValidationDataSelector'\n\nexport interface CreateValidationArgs {\n\tmapper: Mapper\n\tentity: Model.Entity\n\tdata: Input.CreateDataInput\n\tpath: ValidationPath\n\toverRelation: Model.AnyRelation | null\n}\n\nexport interface UpdateValidationArgs {\n\tmapper: Mapper\n\tentity: Model.Entity\n\twhere: Input.UniqueWhere\n\tdata: Input.UpdateDataInput\n\tpath: ValidationPath\n}\n\nexport class InputPreValidator {\n\tconstructor(\n\t\tprivate readonly model: Model.Schema,\n\t\tprivate readonly entityRulesResolver: EntityRulesResolver,\n\t\tprivate readonly columnValueResolver: ColumnValueResolver,\n\t\tprivate readonly dataSelector: ValidationDataSelector,\n\t) {}\n\n\tasync validateCreate({ entity, data, path, mapper, overRelation }: CreateValidationArgs): Promise<ValidationResult> {\n\t\tconst rules = this.entityRulesResolver.getSimpleRules(entity.name)\n\n\t\tconst dataWithRelation = overRelation\n\t\t\t? {\n\t\t\t\t...data,\n\t\t\t\t[overRelation.name]: { create: {} },\n\t\t\t }\n\t\t\t: data\n\t\tconst context = this.createContextForCreate(entity, dataWithRelation)\n\n\t\tconst fieldsResult = this.validateFields(rules, context, path)\n\n\t\tconst processor = new CreateInputPreValidationProcessor(this, path, mapper)\n\t\tconst visitor = new CreateInputVisitor(processor, this.model, data)\n\t\tconst relationResult = await this.validateRelations(entity, visitor)\n\n\t\treturn [...fieldsResult, ...relationResult]\n\t}\n\n\tasync validateUpdate({ entity, data, path, mapper, where }: UpdateValidationArgs): Promise<ValidationResult> {\n\t\tconst simpleRules = this.entityRulesResolver.getSimpleRules(entity.name)\n\t\tconst rules = this.getApplicableRules(Object.keys(data), simpleRules)\n\t\tconst dependencies = this.buildDependencies(rules)\n\n\t\tconst context = await this.createContextForUpdate(mapper, entity, where, data, dependencies)\n\t\tconst fieldsResult: ValidationResult = this.validateFields(rules, context, path)\n\n\t\tconst processor = new UpdateInputPreValidationProcessor(this, path, mapper)\n\t\tconst visitor = new UpdateInputVisitor(processor, this.model, data)\n\t\tconst relationResult = await this.validateRelations(entity, visitor)\n\n\t\treturn [...fieldsResult, ...relationResult]\n\t}\n\n\tprivate createContextForCreate(entity: Model.Entity, data: Input.CreateDataInput): ValidationContext.NodeContext {\n\t\tconst nodeData = acceptEveryFieldVisitor(this.model, entity, {\n\t\t\tvisitColumn: ({ entity, column }) => {\n\t\t\t\tconst value = data[column.name] as Input.ColumnValue | undefined\n\t\t\t\tconst validationValue = this.columnValueResolver.getDefaultValidationValue({ entity, column, input: value })\n\t\t\t\treturn validationValue === undefined ? null : validationValue\n\t\t\t},\n\t\t\tvisitHasOne: ({ relation }) => {\n\t\t\t\tconst value = data[relation.name] as Input.CreateOneRelationInput | undefined\n\t\t\t\treturn value ? true : null\n\t\t\t},\n\t\t\t// more complex validation on relations are not possible in pre-validation phase\n\t\t\tvisitHasMany: () => null,\n\t\t})\n\n\t\treturn ValidationContext.createRootContext(nodeData)\n\t}\n\tprivate async createContextForUpdate(\n\t\tmapper: Mapper,\n\t\tentity: Model.Entity,\n\t\twhere: Input.UniqueWhere,\n\t\tdata: Input.UpdateDataInput,\n\t\tdependencies: Dependencies,\n\t): Promise<ValidationContext.NodeContext> {\n\t\tconst inputNodeData = acceptEveryFieldVisitor(this.model, entity, {\n\t\t\tvisitColumn: ({ column }) => {\n\t\t\t\treturn data[column.name] as Input.ColumnValue | undefined\n\t\t\t},\n\t\t\tvisitHasOne: ({ relation }) => {\n\t\t\t\tconst value = data[relation.name] as Input.CreateOneRelationInput | Input.UpdateOneRelationInput | undefined | null\n\t\t\t\tif (value === undefined || value === null) {\n\t\t\t\t\treturn undefined\n\t\t\t\t}\n\t\t\t\tif ('disconnect' in value) {\n\t\t\t\t\treturn null\n\t\t\t\t}\n\t\t\t\tif ('delete' in value) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tisIt<Model.JoiningColumnRelation>(relation, 'joiningColumn') &&\n\t\t\t\t\t\trelation.joiningColumn.onDelete === Model.OnDelete.cascade\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn true\n\t\t\t\t\t}\n\t\t\t\t\treturn null\n\t\t\t\t}\n\t\t\t\treturn true\n\t\t\t},\n\t\t\t// more complex validation on relations are not possible in pre-validation phase\n\t\t\tvisitHasMany: () => null,\n\t\t})\n\n\t\tconst missingDependencies = Object.keys(dependencies).filter(it => inputNodeData[it] === undefined)\n\t\tmissingDependencies.forEach(it => {\n\t\t\tif (Object.keys(dependencies[it]).length !== 0) {\n\t\t\t\tthrow new NotSupportedError()\n\t\t\t}\n\t\t})\n\n\t\tconst dbData = await this.dataSelector.select(\n\t\t\tmapper,\n\t\t\tentity,\n\t\t\twhere,\n\t\t\tmissingDependencies.reduce((acc, field) => ({ ...acc, [field]: {} }), {}),\n\t\t)\n\n\t\treturn ValidationContext.createRootContext({ ...(inputNodeData as Value.Object), ...(dbData || {}) })\n\t}\n\n\tprivate validateFields(rules: Validation.EntityRules, context: ValidationContext.NodeContext, path: ValidationPath) {\n\t\treturn Object.entries(rules)\n\t\t\t.map(([field, fieldRules]) =>\n\t\t\t\ttuple(\n\t\t\t\t\tfield,\n\t\t\t\t\tfieldRules.find(it => evaluateValidation(context, InputValidation.rules.on(field, it.validator)) === false),\n\t\t\t\t),\n\t\t\t)\n\t\t\t.filter((arg): arg is [string, Validation.ValidationRule] => !!arg[1])\n\t\t\t.map(([field, { message }]) => ({ path: [...path, { field }], message }))\n\t}\n\n\tprivate async validateRelations(\n\t\tentity: Model.Entity,\n\t\tvisitor: Model.FieldVisitor<Promise<ValidationResult[]>>,\n\t): Promise<ValidationResult> {\n\t\tconst validateRelationsResult = acceptEveryFieldVisitor(this.model, entity, visitor)\n\n\t\treturn (await Promise.all(Object.values(validateRelationsResult)))\n\t\t\t.flatMap(it => it.flat())\n\t}\n\n\tprivate getApplicableRules(changedFields: string[], entityRules: Validation.EntityRules): Validation.EntityRules {\n\t\treturn Object.fromEntries(\n\t\t\tObject.entries(entityRules)\n\t\t\t\t.map(([field, fieldRules]) => {\n\t\t\t\t\treturn tuple(\n\t\t\t\t\t\tfield,\n\t\t\t\t\t\tchangedFields.includes(field)\n\t\t\t\t\t\t\t? fieldRules\n\t\t\t\t\t\t\t: fieldRules.filter(rule =>\n\t\t\t\t\t\t\t\tObject.keys(DependencyCollector.collect(rule.validator)).find(it => changedFields.includes(it)),\n\t\t\t\t\t\t\t ),\n\t\t\t\t\t)\n\t\t\t\t})\n\t\t\t\t.filter(([, it]) => it.length > 0),\n\t\t)\n\t}\n\n\tprivate buildDependencies(rules: Validation.EntityRules): Dependencies {\n\t\tconst baseFieldsAsDeps = Object.keys(rules).reduce((acc, field) => ({ ...acc, [field]: {} }), {})\n\n\t\treturn Object.values(rules)\n\t\t\t.flatMap(it => it)\n\t\t\t.map(it => DependencyCollector.collect(it.validator))\n\t\t\t.concat(baseFieldsAsDeps)\n\t\t\t.reduce((acc, dependecy) => DependencyMerger.merge(acc, dependecy), {})\n\t}\n}\n"],"names":["CreateInputPreValidationProcessor","CreateInputVisitor","UpdateInputPreValidationProcessor","UpdateInputVisitor","acceptEveryFieldVisitor","entity","ValidationContext","isIt","Model","NotSupportedError","tuple","evaluateValidation","InputValidation","DependencyCollector","DependencyMerger"],"mappings":";;;;;;;;;;;;;;;;AAmCO,MAAM,kBAAkB;AAAA,EAC9B,YACkB,OACA,qBACA,qBACA,cAChB;AAJgB,SAAA,QAAA;AACA,SAAA,sBAAA;AACA,SAAA,sBAAA;AACA,SAAA,eAAA;AAAA,EACf;AAAA,EAEH,MAAM,eAAe,EAAE,QAAQ,MAAM,MAAM,QAAQ,gBAAiE;AACnH,UAAM,QAAQ,KAAK,oBAAoB,eAAe,OAAO,IAAI;AAEjE,UAAM,mBAA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A,MACJ,CACA,EACA,OAAO,CAAC,CAAG,EAAA,EAAE,MAAM,GAAG,SAAS,CAAC;AAAA,IAAA;AAAA,EAEpC;AAAA,EAEQ,kBAAkB,OAA6C;AACtE,UAAM,mBAAmB,OAAO,KAAK,KAAK,EAAE,OAAO,CAAC,KAAK,WAAW,EAAE,GAAG,KAAK,CAAC,KAAK,GAAG,CAAA,EAAG,IAAI,CAAA,CAAE;AAEhG,WAAO,OAAO,OAAO,KAAK,EACxB,QAAQ,CAAA,OAAM,EAAE,EAChB,IAAI,CAAA,OAAMA,oBAAoB,oBAAA,QAAQ,GAAG,SAAS,CAAC,EACnD,OAAO,gBAAgB,EACvB,OAAO,CAAC,KAAK,cAAcC,iBAAAA,iBAAiB,MAAM,KAAK,SAAS,GAAG,CAAE,CAAA;AAAA,EACxE;AACD;;"}
|
|
@@ -107,7 +107,7 @@ class InputPreValidator {
|
|
|
107
107
|
}
|
|
108
108
|
async validateRelations(entity, visitor) {
|
|
109
109
|
const validateRelationsResult = acceptEveryFieldVisitor(this.model, entity, visitor);
|
|
110
|
-
return (await Promise.all(Object.values(validateRelationsResult))).
|
|
110
|
+
return (await Promise.all(Object.values(validateRelationsResult))).flatMap((it) => it.flat());
|
|
111
111
|
}
|
|
112
112
|
getApplicableRules(changedFields, entityRules) {
|
|
113
113
|
return Object.fromEntries(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InputPreValidator.js","sources":["../../../../../../packages/engine-content-api/src/input-validation/preValidation/InputPreValidator.ts"],"sourcesContent":["import { acceptEveryFieldVisitor } from '@contember/schema-utils'\nimport { isIt, tuple } from '../../utils'\nimport { Input, Model, Validation, Value } from '@contember/schema'\nimport { InputValidation } from '@contember/schema-definition'\nimport { CreateInputVisitor, UpdateInputVisitor } from '../../inputProcessing'\nimport { CreateInputPreValidationProcessor } from './CreateInputPreValidationProcessor'\nimport { ValidationContext } from '../ValidationContext'\nimport { evaluateValidation } from '../ValidationEvaluation'\nimport { ValidationPath } from '../ValidationPath'\nimport { EntityRulesResolver } from '../EntityRulesResolver'\nimport { FieldValidationResult, ValidationResult } from '../InputValidator'\nimport { UpdateInputPreValidationProcessor } from './UpdateInputPreValidationProcessor'\nimport { ColumnValueResolver } from '../ColumnValueResolver'\nimport { Mapper } from '../../mapper'\nimport { Dependencies, DependencyCollector } from '../dependencies'\nimport { DependencyMerger } from '../dependencies'\nimport { NotSupportedError } from '../exceptions'\nimport { ValidationDataSelector } from '../ValidationDataSelector'\n\nexport interface CreateValidationArgs {\n\tmapper: Mapper\n\tentity: Model.Entity\n\tdata: Input.CreateDataInput\n\tpath: ValidationPath\n\toverRelation: Model.AnyRelation | null\n}\n\nexport interface UpdateValidationArgs {\n\tmapper: Mapper\n\tentity: Model.Entity\n\twhere: Input.UniqueWhere\n\tdata: Input.UpdateDataInput\n\tpath: ValidationPath\n}\n\nexport class InputPreValidator {\n\tconstructor(\n\t\tprivate readonly model: Model.Schema,\n\t\tprivate readonly entityRulesResolver: EntityRulesResolver,\n\t\tprivate readonly columnValueResolver: ColumnValueResolver,\n\t\tprivate readonly dataSelector: ValidationDataSelector,\n\t) {}\n\n\tasync validateCreate({ entity, data, path, mapper, overRelation }: CreateValidationArgs): Promise<ValidationResult> {\n\t\tconst rules = this.entityRulesResolver.getSimpleRules(entity.name)\n\n\t\tconst dataWithRelation = overRelation\n\t\t\t? {\n\t\t\t\t...data,\n\t\t\t\t[overRelation.name]: { create: {} },\n\t\t\t }\n\t\t\t: data\n\t\tconst context = this.createContextForCreate(entity, dataWithRelation)\n\n\t\tconst fieldsResult = this.validateFields(rules, context, path)\n\n\t\tconst processor = new CreateInputPreValidationProcessor(this, path, mapper)\n\t\tconst visitor = new CreateInputVisitor(processor, this.model, data)\n\t\tconst relationResult = await this.validateRelations(entity, visitor)\n\n\t\treturn [...fieldsResult, ...relationResult]\n\t}\n\n\tasync validateUpdate({ entity, data, path, mapper, where }: UpdateValidationArgs): Promise<ValidationResult> {\n\t\tconst simpleRules = this.entityRulesResolver.getSimpleRules(entity.name)\n\t\tconst rules = this.getApplicableRules(Object.keys(data), simpleRules)\n\t\tconst dependencies = this.buildDependencies(rules)\n\n\t\tconst context = await this.createContextForUpdate(mapper, entity, where, data, dependencies)\n\t\tconst fieldsResult: ValidationResult = this.validateFields(rules, context, path)\n\n\t\tconst processor = new UpdateInputPreValidationProcessor(this, path, mapper)\n\t\tconst visitor = new UpdateInputVisitor(processor, this.model, data)\n\t\tconst relationResult = await this.validateRelations(entity, visitor)\n\n\t\treturn [...fieldsResult, ...relationResult]\n\t}\n\n\tprivate createContextForCreate(entity: Model.Entity, data: Input.CreateDataInput): ValidationContext.NodeContext {\n\t\tconst nodeData = acceptEveryFieldVisitor(this.model, entity, {\n\t\t\tvisitColumn: ({ entity, column }) => {\n\t\t\t\tconst value = data[column.name] as Input.ColumnValue | undefined\n\t\t\t\tconst validationValue = this.columnValueResolver.getDefaultValidationValue({ entity, column, input: value })\n\t\t\t\treturn validationValue === undefined ? null : validationValue\n\t\t\t},\n\t\t\tvisitHasOne: ({ relation }) => {\n\t\t\t\tconst value = data[relation.name] as Input.CreateOneRelationInput | undefined\n\t\t\t\treturn value ? true : null\n\t\t\t},\n\t\t\t// more complex validation on relations are not possible in pre-validation phase\n\t\t\tvisitHasMany: () => null,\n\t\t})\n\n\t\treturn ValidationContext.createRootContext(nodeData)\n\t}\n\tprivate async createContextForUpdate(\n\t\tmapper: Mapper,\n\t\tentity: Model.Entity,\n\t\twhere: Input.UniqueWhere,\n\t\tdata: Input.UpdateDataInput,\n\t\tdependencies: Dependencies,\n\t): Promise<ValidationContext.NodeContext> {\n\t\tconst inputNodeData = acceptEveryFieldVisitor(this.model, entity, {\n\t\t\tvisitColumn: ({ column }) => {\n\t\t\t\treturn data[column.name] as Input.ColumnValue | undefined\n\t\t\t},\n\t\t\tvisitHasOne: ({ relation }) => {\n\t\t\t\tconst value = data[relation.name] as Input.CreateOneRelationInput | Input.UpdateOneRelationInput | undefined | null\n\t\t\t\tif (value === undefined || value === null) {\n\t\t\t\t\treturn undefined\n\t\t\t\t}\n\t\t\t\tif ('disconnect' in value) {\n\t\t\t\t\treturn null\n\t\t\t\t}\n\t\t\t\tif ('delete' in value) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tisIt<Model.JoiningColumnRelation>(relation, 'joiningColumn') &&\n\t\t\t\t\t\trelation.joiningColumn.onDelete === Model.OnDelete.cascade\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn true\n\t\t\t\t\t}\n\t\t\t\t\treturn null\n\t\t\t\t}\n\t\t\t\treturn true\n\t\t\t},\n\t\t\t// more complex validation on relations are not possible in pre-validation phase\n\t\t\tvisitHasMany: () => null,\n\t\t})\n\n\t\tconst missingDependencies = Object.keys(dependencies).filter(it => inputNodeData[it] === undefined)\n\t\tmissingDependencies.forEach(it => {\n\t\t\tif (Object.keys(dependencies[it]).length !== 0) {\n\t\t\t\tthrow new NotSupportedError()\n\t\t\t}\n\t\t})\n\n\t\tconst dbData = await this.dataSelector.select(\n\t\t\tmapper,\n\t\t\tentity,\n\t\t\twhere,\n\t\t\tmissingDependencies.reduce((acc, field) => ({ ...acc, [field]: {} }), {}),\n\t\t)\n\n\t\treturn ValidationContext.createRootContext({ ...(inputNodeData as Value.Object), ...(dbData || {}) })\n\t}\n\n\tprivate validateFields(rules: Validation.EntityRules, context: ValidationContext.NodeContext, path: ValidationPath) {\n\t\treturn Object.entries(rules)\n\t\t\t.map(([field, fieldRules]) =>\n\t\t\t\ttuple(\n\t\t\t\t\tfield,\n\t\t\t\t\tfieldRules.find(it => evaluateValidation(context, InputValidation.rules.on(field, it.validator)) === false),\n\t\t\t\t),\n\t\t\t)\n\t\t\t.filter((arg): arg is [string, Validation.ValidationRule] => !!arg[1])\n\t\t\t.map(([field, { message }]) => ({ path: [...path, { field }], message }))\n\t}\n\n\tprivate async validateRelations(\n\t\tentity: Model.Entity,\n\t\tvisitor: Model.FieldVisitor<Promise<ValidationResult | ValidationResult[] | undefined>>,\n\t): Promise<FieldValidationResult[]> {\n\t\tconst validateRelationsResult = acceptEveryFieldVisitor(this.model, entity, visitor)\n\n\t\treturn (await Promise.all(Object.values(validateRelationsResult)))\n\t\t\t.filter((value): value is FieldValidationResult[] | FieldValidationResult[][] => value !== undefined)\n\t\t\t.reduce<(FieldValidationResult[] | FieldValidationResult)[]>((res, it) => [...res, ...it], [])\n\t\t\t.reduce<FieldValidationResult[]>((res, it) => [...res, ...(Array.isArray(it) ? it : [it])], [])\n\t}\n\n\tprivate getApplicableRules(changedFields: string[], entityRules: Validation.EntityRules): Validation.EntityRules {\n\t\treturn Object.fromEntries(\n\t\t\tObject.entries(entityRules)\n\t\t\t\t.map(([field, fieldRules]) => {\n\t\t\t\t\treturn tuple(\n\t\t\t\t\t\tfield,\n\t\t\t\t\t\tchangedFields.includes(field)\n\t\t\t\t\t\t\t? fieldRules\n\t\t\t\t\t\t\t: fieldRules.filter(rule =>\n\t\t\t\t\t\t\t\tObject.keys(DependencyCollector.collect(rule.validator)).find(it => changedFields.includes(it)),\n\t\t\t\t\t\t\t ),\n\t\t\t\t\t)\n\t\t\t\t})\n\t\t\t\t.filter(([, it]) => it.length > 0),\n\t\t)\n\t}\n\n\tprivate buildDependencies(rules: Validation.EntityRules): Dependencies {\n\t\tconst baseFieldsAsDeps = Object.keys(rules).reduce((acc, field) => ({ ...acc, [field]: {} }), {})\n\n\t\treturn Object.values(rules)\n\t\t\t.flatMap(it => it)\n\t\t\t.map(it => DependencyCollector.collect(it.validator))\n\t\t\t.concat(baseFieldsAsDeps)\n\t\t\t.reduce((acc, dependecy) => DependencyMerger.merge(acc, dependecy), {})\n\t}\n}\n"],"names":["entity"],"mappings":";;;;;;;;;;;;;;AAmCO,MAAM,kBAAkB;AAAA,EAC9B,YACkB,OACA,qBACA,qBACA,cAChB;AAJgB,SAAA,QAAA;AACA,SAAA,sBAAA;AACA,SAAA,sBAAA;AACA,SAAA,eAAA;AAAA,EACf;AAAA,EAEH,MAAM,eAAe,EAAE,QAAQ,M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K,IACzB,aACA,WAAW;AAAA,YAAO,CACnB,SAAA,OAAO,KAAK,oBAAoB,QAAQ,KAAK,SAAS,CAAC,EAAE,KAAK,CAAA,OAAM,cAAc,SAAS,EAAE,CAAC;AAAA,UAC7F;AAAA,QAAA;AAAA,MACJ,CACA,EACA,OAAO,CAAC,CAAG,EAAA,EAAE,MAAM,GAAG,SAAS,CAAC;AAAA,IAAA;AAAA,EAEpC;AAAA,EAEQ,kBAAkB,OAA6C;AACtE,UAAM,mBAAmB,OAAO,KAAK,KAAK,EAAE,OAAO,CAAC,KAAK,WAAW,EAAE,GAAG,KAAK,CAAC,KAAK,GAAG,CAAA,EAAG,IAAI,CAAA,CAAE;AAEhG,WAAO,OAAO,OAAO,KAAK,EACxB,QAAQ,CAAA,OAAM,EAAE,EAChB,IAAI,CAAA,OAAM,oBAAoB,QAAQ,GAAG,SAAS,CAAC,EACnD,OAAO,gBAAgB,EACvB,OAAO,CAAC,KAAK,cAAc,iBAAiB,MAAM,KAAK,SAAS,GAAG,CAAE,CAAA;AAAA,EACxE;AACD;"}
|
|
1
|
+
{"version":3,"file":"InputPreValidator.js","sources":["../../../../../../packages/engine-content-api/src/input-validation/preValidation/InputPreValidator.ts"],"sourcesContent":["import { acceptEveryFieldVisitor } from '@contember/schema-utils'\nimport { isIt, tuple } from '../../utils'\nimport { Input, Model, Validation, Value } from '@contember/schema'\nimport { InputValidation } from '@contember/schema-definition'\nimport { CreateInputVisitor, UpdateInputVisitor } from '../../inputProcessing'\nimport { CreateInputPreValidationProcessor } from './CreateInputPreValidationProcessor'\nimport { ValidationContext } from '../ValidationContext'\nimport { evaluateValidation } from '../ValidationEvaluation'\nimport { ValidationPath } from '../ValidationPath'\nimport { EntityRulesResolver } from '../EntityRulesResolver'\nimport { FieldValidationResult, ValidationResult } from '../InputValidator'\nimport { UpdateInputPreValidationProcessor } from './UpdateInputPreValidationProcessor'\nimport { ColumnValueResolver } from '../ColumnValueResolver'\nimport { Mapper } from '../../mapper'\nimport { Dependencies, DependencyCollector } from '../dependencies'\nimport { DependencyMerger } from '../dependencies'\nimport { NotSupportedError } from '../exceptions'\nimport { ValidationDataSelector } from '../ValidationDataSelector'\n\nexport interface CreateValidationArgs {\n\tmapper: Mapper\n\tentity: Model.Entity\n\tdata: Input.CreateDataInput\n\tpath: ValidationPath\n\toverRelation: Model.AnyRelation | null\n}\n\nexport interface UpdateValidationArgs {\n\tmapper: Mapper\n\tentity: Model.Entity\n\twhere: Input.UniqueWhere\n\tdata: Input.UpdateDataInput\n\tpath: ValidationPath\n}\n\nexport class InputPreValidator {\n\tconstructor(\n\t\tprivate readonly model: Model.Schema,\n\t\tprivate readonly entityRulesResolver: EntityRulesResolver,\n\t\tprivate readonly columnValueResolver: ColumnValueResolver,\n\t\tprivate readonly dataSelector: ValidationDataSelector,\n\t) {}\n\n\tasync validateCreate({ entity, data, path, mapper, overRelation }: CreateValidationArgs): Promise<ValidationResult> {\n\t\tconst rules = this.entityRulesResolver.getSimpleRules(entity.name)\n\n\t\tconst dataWithRelation = overRelation\n\t\t\t? {\n\t\t\t\t...data,\n\t\t\t\t[overRelation.name]: { create: {} },\n\t\t\t }\n\t\t\t: data\n\t\tconst context = this.createContextForCreate(entity, dataWithRelation)\n\n\t\tconst fieldsResult = this.validateFields(rules, context, path)\n\n\t\tconst processor = new CreateInputPreValidationProcessor(this, path, mapper)\n\t\tconst visitor = new CreateInputVisitor(processor, this.model, data)\n\t\tconst relationResult = await this.validateRelations(entity, visitor)\n\n\t\treturn [...fieldsResult, ...relationResult]\n\t}\n\n\tasync validateUpdate({ entity, data, path, mapper, where }: UpdateValidationArgs): Promise<ValidationResult> {\n\t\tconst simpleRules = this.entityRulesResolver.getSimpleRules(entity.name)\n\t\tconst rules = this.getApplicableRules(Object.keys(data), simpleRules)\n\t\tconst dependencies = this.buildDependencies(rules)\n\n\t\tconst context = await this.createContextForUpdate(mapper, entity, where, data, dependencies)\n\t\tconst fieldsResult: ValidationResult = this.validateFields(rules, context, path)\n\n\t\tconst processor = new UpdateInputPreValidationProcessor(this, path, mapper)\n\t\tconst visitor = new UpdateInputVisitor(processor, this.model, data)\n\t\tconst relationResult = await this.validateRelations(entity, visitor)\n\n\t\treturn [...fieldsResult, ...relationResult]\n\t}\n\n\tprivate createContextForCreate(entity: Model.Entity, data: Input.CreateDataInput): ValidationContext.NodeContext {\n\t\tconst nodeData = acceptEveryFieldVisitor(this.model, entity, {\n\t\t\tvisitColumn: ({ entity, column }) => {\n\t\t\t\tconst value = data[column.name] as Input.ColumnValue | undefined\n\t\t\t\tconst validationValue = this.columnValueResolver.getDefaultValidationValue({ entity, column, input: value })\n\t\t\t\treturn validationValue === undefined ? null : validationValue\n\t\t\t},\n\t\t\tvisitHasOne: ({ relation }) => {\n\t\t\t\tconst value = data[relation.name] as Input.CreateOneRelationInput | undefined\n\t\t\t\treturn value ? true : null\n\t\t\t},\n\t\t\t// more complex validation on relations are not possible in pre-validation phase\n\t\t\tvisitHasMany: () => null,\n\t\t})\n\n\t\treturn ValidationContext.createRootContext(nodeData)\n\t}\n\tprivate async createContextForUpdate(\n\t\tmapper: Mapper,\n\t\tentity: Model.Entity,\n\t\twhere: Input.UniqueWhere,\n\t\tdata: Input.UpdateDataInput,\n\t\tdependencies: Dependencies,\n\t): Promise<ValidationContext.NodeContext> {\n\t\tconst inputNodeData = acceptEveryFieldVisitor(this.model, entity, {\n\t\t\tvisitColumn: ({ column }) => {\n\t\t\t\treturn data[column.name] as Input.ColumnValue | undefined\n\t\t\t},\n\t\t\tvisitHasOne: ({ relation }) => {\n\t\t\t\tconst value = data[relation.name] as Input.CreateOneRelationInput | Input.UpdateOneRelationInput | undefined | null\n\t\t\t\tif (value === undefined || value === null) {\n\t\t\t\t\treturn undefined\n\t\t\t\t}\n\t\t\t\tif ('disconnect' in value) {\n\t\t\t\t\treturn null\n\t\t\t\t}\n\t\t\t\tif ('delete' in value) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tisIt<Model.JoiningColumnRelation>(relation, 'joiningColumn') &&\n\t\t\t\t\t\trelation.joiningColumn.onDelete === Model.OnDelete.cascade\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn true\n\t\t\t\t\t}\n\t\t\t\t\treturn null\n\t\t\t\t}\n\t\t\t\treturn true\n\t\t\t},\n\t\t\t// more complex validation on relations are not possible in pre-validation phase\n\t\t\tvisitHasMany: () => null,\n\t\t})\n\n\t\tconst missingDependencies = Object.keys(dependencies).filter(it => inputNodeData[it] === undefined)\n\t\tmissingDependencies.forEach(it => {\n\t\t\tif (Object.keys(dependencies[it]).length !== 0) {\n\t\t\t\tthrow new NotSupportedError()\n\t\t\t}\n\t\t})\n\n\t\tconst dbData = await this.dataSelector.select(\n\t\t\tmapper,\n\t\t\tentity,\n\t\t\twhere,\n\t\t\tmissingDependencies.reduce((acc, field) => ({ ...acc, [field]: {} }), {}),\n\t\t)\n\n\t\treturn ValidationContext.createRootContext({ ...(inputNodeData as Value.Object), ...(dbData || {}) })\n\t}\n\n\tprivate validateFields(rules: Validation.EntityRules, context: ValidationContext.NodeContext, path: ValidationPath) {\n\t\treturn Object.entries(rules)\n\t\t\t.map(([field, fieldRules]) =>\n\t\t\t\ttuple(\n\t\t\t\t\tfield,\n\t\t\t\t\tfieldRules.find(it => evaluateValidation(context, InputValidation.rules.on(field, it.validator)) === false),\n\t\t\t\t),\n\t\t\t)\n\t\t\t.filter((arg): arg is [string, Validation.ValidationRule] => !!arg[1])\n\t\t\t.map(([field, { message }]) => ({ path: [...path, { field }], message }))\n\t}\n\n\tprivate async validateRelations(\n\t\tentity: Model.Entity,\n\t\tvisitor: Model.FieldVisitor<Promise<ValidationResult[]>>,\n\t): Promise<ValidationResult> {\n\t\tconst validateRelationsResult = acceptEveryFieldVisitor(this.model, entity, visitor)\n\n\t\treturn (await Promise.all(Object.values(validateRelationsResult)))\n\t\t\t.flatMap(it => it.flat())\n\t}\n\n\tprivate getApplicableRules(changedFields: string[], entityRules: Validation.EntityRules): Validation.EntityRules {\n\t\treturn Object.fromEntries(\n\t\t\tObject.entries(entityRules)\n\t\t\t\t.map(([field, fieldRules]) => {\n\t\t\t\t\treturn tuple(\n\t\t\t\t\t\tfield,\n\t\t\t\t\t\tchangedFields.includes(field)\n\t\t\t\t\t\t\t? fieldRules\n\t\t\t\t\t\t\t: fieldRules.filter(rule =>\n\t\t\t\t\t\t\t\tObject.keys(DependencyCollector.collect(rule.validator)).find(it => changedFields.includes(it)),\n\t\t\t\t\t\t\t ),\n\t\t\t\t\t)\n\t\t\t\t})\n\t\t\t\t.filter(([, it]) => it.length > 0),\n\t\t)\n\t}\n\n\tprivate buildDependencies(rules: Validation.EntityRules): Dependencies {\n\t\tconst baseFieldsAsDeps = Object.keys(rules).reduce((acc, field) => ({ ...acc, [field]: {} }), {})\n\n\t\treturn Object.values(rules)\n\t\t\t.flatMap(it => it)\n\t\t\t.map(it => DependencyCollector.collect(it.validator))\n\t\t\t.concat(baseFieldsAsDeps)\n\t\t\t.reduce((acc, dependecy) => DependencyMerger.merge(acc, dependecy), {})\n\t}\n}\n"],"names":["entity"],"mappings":";;;;;;;;;;;;;;AAmCO,MAAM,kBAAkB;AAAA,EAC9B,YACkB,OACA,qBACA,qBACA,cAChB;AAJgB,SAAA,QAAA;AACA,SAAA,sBAAA;AACA,SAAA,sBAAA;AACA,SAAA,eAAA;AAAA,EACf;AAAA,EAEH,MAAM,eAAe,EAAE,QAAQ,MAAM,MAAM,QAAQ,gBAAiE;AACnH,UAAM,QAAQ,KAAK,oBAAoB,eAAe,OAAO,IAAI;AAEjE,UAAM,mBAAmB,eACtB;AAAA,MACD,GAAG;AAAA,MACH,CAAC,aAAa,IAAI,GAAG,EAAE,QAAQ,CAAA,EAAG;AAAA,IAEjC,IAAA;AACH,UAAM,UAAU,KAAK,uBAAuB,QAAQ,gBAAgB;AAEpE,UAAM,eAAe,KAAK,eAAe,OAAO,SAAS,IAAI;AAE7D,UAAM,YAAY,IAAI,kCAAkC,MAAM,MAAM,MAAM;AAC1E,UAAM,UAAU,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AAgB,EACvB,OAAO,CAAC,KAAK,cAAc,iBAAiB,MAAM,KAAK,SAAS,GAAG,CAAE,CAAA;AAAA,EACxE;AACD;"}
|
|
@@ -11,11 +11,11 @@ class CreateInputVisitor {
|
|
|
11
11
|
this.schema = schema2;
|
|
12
12
|
this.data = data;
|
|
13
13
|
}
|
|
14
|
-
visitColumn(context) {
|
|
15
|
-
return this.createInputProcessor.column({
|
|
14
|
+
async visitColumn(context) {
|
|
15
|
+
return [await this.createInputProcessor.column({
|
|
16
16
|
...context,
|
|
17
17
|
input: this.data[context.column.name]
|
|
18
|
-
});
|
|
18
|
+
})];
|
|
19
19
|
}
|
|
20
20
|
visitManyHasManyInverse(context) {
|
|
21
21
|
return this.processManyRelationInput(
|
|
@@ -59,29 +59,29 @@ class CreateInputVisitor {
|
|
|
59
59
|
this.data[context.relation.name]
|
|
60
60
|
);
|
|
61
61
|
}
|
|
62
|
-
processRelationInput(processor, context, input) {
|
|
62
|
+
async processRelationInput(processor, context, input) {
|
|
63
63
|
if (input === void 0 || input === null) {
|
|
64
64
|
if (processor.nothing) {
|
|
65
|
-
return processor.nothing({ ...context, input: void 0 });
|
|
65
|
+
return [await processor.nothing({ ...context, input: void 0 })];
|
|
66
66
|
}
|
|
67
|
-
return Promise.resolve(
|
|
67
|
+
return Promise.resolve([]);
|
|
68
68
|
}
|
|
69
69
|
input = object.filterObject(input, (k, v) => v !== null && v !== void 0);
|
|
70
70
|
this.verifyOperations(input);
|
|
71
71
|
if (isIt.isIt(input, "connect")) {
|
|
72
|
-
return processor.connect({ ...context, input: input.connect });
|
|
72
|
+
return [await processor.connect({ ...context, input: input.connect })];
|
|
73
73
|
}
|
|
74
74
|
if (isIt.isIt(input, "create")) {
|
|
75
|
-
return processor.create({ ...context, input: input.create });
|
|
75
|
+
return [await processor.create({ ...context, input: input.create })];
|
|
76
76
|
}
|
|
77
77
|
if (isIt.isIt(input, "connectOrCreate")) {
|
|
78
|
-
return processor.connectOrCreate({ ...context, input: input.connectOrCreate });
|
|
78
|
+
return [await processor.connectOrCreate({ ...context, input: input.connectOrCreate })];
|
|
79
79
|
}
|
|
80
80
|
throw new exception.ImplementationException();
|
|
81
81
|
}
|
|
82
82
|
async processManyRelationInput(processor, context, input) {
|
|
83
83
|
if (input === void 0 || input === null) {
|
|
84
|
-
return Promise.resolve(
|
|
84
|
+
return Promise.resolve([]);
|
|
85
85
|
}
|
|
86
86
|
const results = [];
|
|
87
87
|
let i = 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CreateInputVisitor.cjs","sources":["../../../../../packages/engine-content-api/src/inputProcessing/CreateInputVisitor.ts"],"sourcesContent":["import { isIt } from '../utils'\nimport { Input, Model } from '@contember/schema'\nimport { CreateInputProcessor } from './CreateInputProcessor'\nimport { filterObject } from '../utils'\nimport { UserError } from '../exception'\nimport { ImplementationException } from '../exception'\n\nexport class CreateInputVisitor<Result> implements\n\tModel.ColumnVisitor<Promise<Result
|
|
1
|
+
{"version":3,"file":"CreateInputVisitor.cjs","sources":["../../../../../packages/engine-content-api/src/inputProcessing/CreateInputVisitor.ts"],"sourcesContent":["import { isIt } from '../utils'\nimport { Input, Model } from '@contember/schema'\nimport { CreateInputProcessor } from './CreateInputProcessor'\nimport { filterObject } from '../utils'\nimport { UserError } from '../exception'\nimport { ImplementationException } from '../exception'\n\nexport class CreateInputVisitor<Result> implements\n\tModel.ColumnVisitor<Promise<Result[]>>,\n\tModel.RelationByTypeVisitor<Promise<Result[]>> {\n\n\tconstructor(\n\t\tprivate readonly createInputProcessor: CreateInputProcessor<Result>,\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly data: Input.CreateDataInput,\n\t) {}\n\n\tpublic async visitColumn(context: Model.ColumnContext): Promise<Result[]> {\n\t\treturn [await this.createInputProcessor.column({\n\t\t\t...context,\n\t\t\tinput: this.data[context.column.name] as Input.ColumnValue,\n\t\t})]\n\t}\n\n\tpublic visitManyHasManyInverse(context: Model.ManyHasManyInverseContext) {\n\t\treturn this.processManyRelationInput(\n\t\t\tthis.createInputProcessor.manyHasManyInverse,\n\t\t\tcontext,\n\t\t\tthis.data[context.relation.name] as Input.CreateManyRelationInput,\n\t\t)\n\t}\n\n\tpublic visitManyHasManyOwning(context: Model.ManyHasManyOwningContext) {\n\t\treturn this.processManyRelationInput(\n\t\t\tthis.createInputProcessor.manyHasManyOwning,\n\t\t\tcontext,\n\t\t\tthis.data[context.relation.name] as Input.CreateManyRelationInput,\n\t\t)\n\t}\n\n\tpublic visitManyHasOne(context: Model.ManyHasOneContext) {\n\t\treturn this.processRelationInput(\n\t\t\tthis.createInputProcessor.manyHasOne,\n\t\t\tcontext,\n\t\t\tthis.data[context.relation.name] as Input.CreateOneRelationInput,\n\t\t)\n\t}\n\n\tpublic visitOneHasMany(context: Model.OneHasManyContext) {\n\t\treturn this.processManyRelationInput(\n\t\t\tthis.createInputProcessor.oneHasMany,\n\t\t\tcontext,\n\t\t\tthis.data[context.relation.name] as Input.CreateManyRelationInput,\n\t\t)\n\t}\n\n\tpublic visitOneHasOneInverse(context: Model.OneHasOneInverseContext) {\n\t\treturn this.processRelationInput(\n\t\t\tthis.createInputProcessor.oneHasOneInverse,\n\t\t\tcontext,\n\t\t\tthis.data[context.relation.name] as Input.CreateOneRelationInput,\n\t\t)\n\t}\n\n\tpublic visitOneHasOneOwning(context: Model.OneHasOneOwningContext) {\n\t\treturn this.processRelationInput(\n\t\t\tthis.createInputProcessor.oneHasOneOwning,\n\t\t\tcontext,\n\t\t\tthis.data[context.relation.name] as Input.CreateOneRelationInput,\n\t\t)\n\t}\n\n\tprivate async processRelationInput<Context>(\n\t\tprocessor: CreateInputProcessor.HasOneRelationProcessor<Context, Result>,\n\t\tcontext: Context,\n\t\tinput: Input.CreateOneRelationInput | undefined,\n\t): Promise<Result[]> {\n\t\tif (input === undefined || input === null) {\n\t\t\tif (processor.nothing) {\n\t\t\t\treturn [await processor.nothing({ ...context, input: undefined })]\n\t\t\t}\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 (isIt<Input.ConnectRelationInput>(input, 'connect')) {\n\t\t\treturn [await processor.connect({ ...context, input: input.connect })]\n\t\t}\n\t\tif (isIt<Input.CreateRelationInput>(input, 'create')) {\n\t\t\treturn [await processor.create({ ...context, input: input.create })]\n\t\t}\n\t\tif (isIt<Input.ConnectOrCreateRelationInput>(input, 'connectOrCreate')) {\n\t\t\treturn [await processor.connectOrCreate({ ...context, input: input.connectOrCreate })]\n\t\t}\n\t\tthrow new ImplementationException()\n\t}\n\n\tprivate async processManyRelationInput<Context>(\n\t\tprocessor: CreateInputProcessor.HasManyRelationProcessor<Context, Result>,\n\t\tcontext: Context,\n\t\tinput: Input.CreateManyRelationInput | 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: 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 (isIt<Input.ConnectRelationInput>(element, 'connect')) {\n\t\t\t\tresult = processor.connect({ ...context, input: element.connect, index: i++, alias })\n\t\t\t}\n\t\t\tif (isIt<Input.CreateRelationInput>(element, 'create')) {\n\t\t\t\tresult = processor.create({ ...context, input: element.create, index: i++, alias })\n\t\t\t}\n\t\t\tif (isIt<Input.ConnectOrCreateRelationInput>(element, 'connectOrCreate')) {\n\t\t\t\tresult = processor.connectOrCreate({ ...context, input: element.connectOrCreate, index: i++, alias })\n\t\t\t}\n\t\t\tif (result !== undefined) {\n\t\t\t\tresults.push(await result)\n\t\t\t}\n\t\t}\n\t\treturn Promise.all(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.CreateRelationOperation) 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","isIt","ImplementationException","Input","UserError"],"mappings":";;;;;;;AAOO,MAAM,mBAEmC;AAAA,EAE/C,YACkB,sBACAA,SACA,MAChB;AAHgB,SAAA,uBAAA;AACA,SAAA,SAAAA;AACA,SAAA,OAAA;AAAA,EACf;AAAA,EAEH,MAAa,YAAY,SAAiD;AACzE,WAAO,CAAC,MAAM,KAAK,qBAAqB,OAAO;AAAA,MAC9C,GAAG;AAAA,MACH,OAAO,KAAK,KAAK,QAAQ,OAAO,IAAI;AAAA,IACpC,CAAA,CAAC;AAAA,EACH;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;AAA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-
visitColumn(context) {
|
|
13
|
-
return this.createInputProcessor.column({
|
|
12
|
+
async visitColumn(context) {
|
|
13
|
+
return [await this.createInputProcessor.column({
|
|
14
14
|
...context,
|
|
15
15
|
input: this.data[context.column.name]
|
|
16
|
-
});
|
|
16
|
+
})];
|
|
17
17
|
}
|
|
18
18
|
visitManyHasManyInverse(context) {
|
|
19
19
|
return this.processManyRelationInput(
|
|
@@ -57,29 +57,29 @@ class CreateInputVisitor {
|
|
|
57
57
|
this.data[context.relation.name]
|
|
58
58
|
);
|
|
59
59
|
}
|
|
60
|
-
processRelationInput(processor, context, input) {
|
|
60
|
+
async processRelationInput(processor, context, input) {
|
|
61
61
|
if (input === void 0 || input === null) {
|
|
62
62
|
if (processor.nothing) {
|
|
63
|
-
return processor.nothing({ ...context, input: void 0 });
|
|
63
|
+
return [await processor.nothing({ ...context, input: void 0 })];
|
|
64
64
|
}
|
|
65
|
-
return Promise.resolve(
|
|
65
|
+
return Promise.resolve([]);
|
|
66
66
|
}
|
|
67
67
|
input = filterObject(input, (k, v) => v !== null && v !== void 0);
|
|
68
68
|
this.verifyOperations(input);
|
|
69
69
|
if (isIt(input, "connect")) {
|
|
70
|
-
return processor.connect({ ...context, input: input.connect });
|
|
70
|
+
return [await processor.connect({ ...context, input: input.connect })];
|
|
71
71
|
}
|
|
72
72
|
if (isIt(input, "create")) {
|
|
73
|
-
return processor.create({ ...context, input: input.create });
|
|
73
|
+
return [await processor.create({ ...context, input: input.create })];
|
|
74
74
|
}
|
|
75
75
|
if (isIt(input, "connectOrCreate")) {
|
|
76
|
-
return processor.connectOrCreate({ ...context, input: input.connectOrCreate });
|
|
76
|
+
return [await processor.connectOrCreate({ ...context, input: input.connectOrCreate })];
|
|
77
77
|
}
|
|
78
78
|
throw new ImplementationException();
|
|
79
79
|
}
|
|
80
80
|
async processManyRelationInput(processor, context, input) {
|
|
81
81
|
if (input === void 0 || input === null) {
|
|
82
|
-
return Promise.resolve(
|
|
82
|
+
return Promise.resolve([]);
|
|
83
83
|
}
|
|
84
84
|
const results = [];
|
|
85
85
|
let i = 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CreateInputVisitor.js","sources":["../../../../../packages/engine-content-api/src/inputProcessing/CreateInputVisitor.ts"],"sourcesContent":["import { isIt } from '../utils'\nimport { Input, Model } from '@contember/schema'\nimport { CreateInputProcessor } from './CreateInputProcessor'\nimport { filterObject } from '../utils'\nimport { UserError } from '../exception'\nimport { ImplementationException } from '../exception'\n\nexport class CreateInputVisitor<Result> implements\n\tModel.ColumnVisitor<Promise<Result
|
|
1
|
+
{"version":3,"file":"CreateInputVisitor.js","sources":["../../../../../packages/engine-content-api/src/inputProcessing/CreateInputVisitor.ts"],"sourcesContent":["import { isIt } from '../utils'\nimport { Input, Model } from '@contember/schema'\nimport { CreateInputProcessor } from './CreateInputProcessor'\nimport { filterObject } from '../utils'\nimport { UserError } from '../exception'\nimport { ImplementationException } from '../exception'\n\nexport class CreateInputVisitor<Result> implements\n\tModel.ColumnVisitor<Promise<Result[]>>,\n\tModel.RelationByTypeVisitor<Promise<Result[]>> {\n\n\tconstructor(\n\t\tprivate readonly createInputProcessor: CreateInputProcessor<Result>,\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly data: Input.CreateDataInput,\n\t) {}\n\n\tpublic async visitColumn(context: Model.ColumnContext): Promise<Result[]> {\n\t\treturn [await this.createInputProcessor.column({\n\t\t\t...context,\n\t\t\tinput: this.data[context.column.name] as Input.ColumnValue,\n\t\t})]\n\t}\n\n\tpublic visitManyHasManyInverse(context: Model.ManyHasManyInverseContext) {\n\t\treturn this.processManyRelationInput(\n\t\t\tthis.createInputProcessor.manyHasManyInverse,\n\t\t\tcontext,\n\t\t\tthis.data[context.relation.name] as Input.CreateManyRelationInput,\n\t\t)\n\t}\n\n\tpublic visitManyHasManyOwning(context: Model.ManyHasManyOwningContext) {\n\t\treturn this.processManyRelationInput(\n\t\t\tthis.createInputProcessor.manyHasManyOwning,\n\t\t\tcontext,\n\t\t\tthis.data[context.relation.name] as Input.CreateManyRelationInput,\n\t\t)\n\t}\n\n\tpublic visitManyHasOne(context: Model.ManyHasOneContext) {\n\t\treturn this.processRelationInput(\n\t\t\tthis.createInputProcessor.manyHasOne,\n\t\t\tcontext,\n\t\t\tthis.data[context.relation.name] as Input.CreateOneRelationInput,\n\t\t)\n\t}\n\n\tpublic visitOneHasMany(context: Model.OneHasManyContext) {\n\t\treturn this.processManyRelationInput(\n\t\t\tthis.createInputProcessor.oneHasMany,\n\t\t\tcontext,\n\t\t\tthis.data[context.relation.name] as Input.CreateManyRelationInput,\n\t\t)\n\t}\n\n\tpublic visitOneHasOneInverse(context: Model.OneHasOneInverseContext) {\n\t\treturn this.processRelationInput(\n\t\t\tthis.createInputProcessor.oneHasOneInverse,\n\t\t\tcontext,\n\t\t\tthis.data[context.relation.name] as Input.CreateOneRelationInput,\n\t\t)\n\t}\n\n\tpublic visitOneHasOneOwning(context: Model.OneHasOneOwningContext) {\n\t\treturn this.processRelationInput(\n\t\t\tthis.createInputProcessor.oneHasOneOwning,\n\t\t\tcontext,\n\t\t\tthis.data[context.relation.name] as Input.CreateOneRelationInput,\n\t\t)\n\t}\n\n\tprivate async processRelationInput<Context>(\n\t\tprocessor: CreateInputProcessor.HasOneRelationProcessor<Context, Result>,\n\t\tcontext: Context,\n\t\tinput: Input.CreateOneRelationInput | undefined,\n\t): Promise<Result[]> {\n\t\tif (input === undefined || input === null) {\n\t\t\tif (processor.nothing) {\n\t\t\t\treturn [await processor.nothing({ ...context, input: undefined })]\n\t\t\t}\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 (isIt<Input.ConnectRelationInput>(input, 'connect')) {\n\t\t\treturn [await processor.connect({ ...context, input: input.connect })]\n\t\t}\n\t\tif (isIt<Input.CreateRelationInput>(input, 'create')) {\n\t\t\treturn [await processor.create({ ...context, input: input.create })]\n\t\t}\n\t\tif (isIt<Input.ConnectOrCreateRelationInput>(input, 'connectOrCreate')) {\n\t\t\treturn [await processor.connectOrCreate({ ...context, input: input.connectOrCreate })]\n\t\t}\n\t\tthrow new ImplementationException()\n\t}\n\n\tprivate async processManyRelationInput<Context>(\n\t\tprocessor: CreateInputProcessor.HasManyRelationProcessor<Context, Result>,\n\t\tcontext: Context,\n\t\tinput: Input.CreateManyRelationInput | 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: 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 (isIt<Input.ConnectRelationInput>(element, 'connect')) {\n\t\t\t\tresult = processor.connect({ ...context, input: element.connect, index: i++, alias })\n\t\t\t}\n\t\t\tif (isIt<Input.CreateRelationInput>(element, 'create')) {\n\t\t\t\tresult = processor.create({ ...context, input: element.create, index: i++, alias })\n\t\t\t}\n\t\t\tif (isIt<Input.ConnectOrCreateRelationInput>(element, 'connectOrCreate')) {\n\t\t\t\tresult = processor.connectOrCreate({ ...context, input: element.connectOrCreate, index: i++, alias })\n\t\t\t}\n\t\t\tif (result !== undefined) {\n\t\t\t\tresults.push(await result)\n\t\t\t}\n\t\t}\n\t\treturn Promise.all(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.CreateRelationOperation) 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":";;;;;AAOO,MAAM,mBAEmC;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Q,GAAG;AAC9C,iBAAA,UAAU,OAAO,EAAE,GAAG,SAAS,OAAO,QAAQ,QAAQ,OAAO,KAAK,MAAO,CAAA;AAAA,MACnF;AACI,UAAA,KAAyC,SAAS,iBAAiB,GAAG;AAChE,iBAAA,UAAU,gBAAgB,EAAE,GAAG,SAAS,OAAO,QAAQ,iBAAiB,OAAO,KAAK,MAAO,CAAA;AAAA,MACrG;AACA,UAAI,WAAW,QAAW;AACjB,gBAAA,KAAK,MAAM,MAAM;AAAA,MAC1B;AAAA,IACD;AACO,WAAA,QAAQ,IAAI,OAAO;AAAA,EAC3B;AAAA,EAEQ,iBAAiB,OAAe;AACjC,UAAA,OAAO,OAAO,KAAK,KAAK,EAAE,OAAO,CAAA,OAAM,OAAO,OAAO;AAC3D,UAAM,MAAM,OAAO,OAAO,MAAM,uBAAuB;AACnD,QAAA,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;"}
|
|
@@ -11,12 +11,12 @@ class UpdateInputVisitor {
|
|
|
11
11
|
this.schema = schema2;
|
|
12
12
|
this.data = data;
|
|
13
13
|
}
|
|
14
|
-
visitColumn({ entity, column }) {
|
|
15
|
-
return this.updateInputProcessor.column({
|
|
14
|
+
async visitColumn({ entity, column }) {
|
|
15
|
+
return [await this.updateInputProcessor.column({
|
|
16
16
|
entity,
|
|
17
17
|
column,
|
|
18
18
|
input: this.data[column.name]
|
|
19
|
-
});
|
|
19
|
+
})];
|
|
20
20
|
}
|
|
21
21
|
visitManyHasManyInverse(context) {
|
|
22
22
|
return this.processManyRelationInput(
|
|
@@ -60,38 +60,38 @@ class UpdateInputVisitor {
|
|
|
60
60
|
this.data[context.relation.name]
|
|
61
61
|
);
|
|
62
62
|
}
|
|
63
|
-
processRelationInput(processor, context, input) {
|
|
63
|
+
async processRelationInput(processor, context, input) {
|
|
64
64
|
if (input === void 0 || input === null) {
|
|
65
|
-
return Promise.resolve(
|
|
65
|
+
return Promise.resolve([]);
|
|
66
66
|
}
|
|
67
67
|
input = object.filterObject(input, (k, v) => v !== null && v !== void 0);
|
|
68
68
|
this.verifyOperations(input);
|
|
69
69
|
if (isIt.isIt(input, "connect")) {
|
|
70
|
-
return processor.connect({ ...context, input: input.connect });
|
|
70
|
+
return [await processor.connect({ ...context, input: input.connect })];
|
|
71
71
|
}
|
|
72
72
|
if (isIt.isIt(input, "create")) {
|
|
73
|
-
return processor.create({ ...context, input: input.create });
|
|
73
|
+
return [await processor.create({ ...context, input: input.create })];
|
|
74
74
|
}
|
|
75
75
|
if (isIt.isIt(input, "connectOrCreate")) {
|
|
76
|
-
return processor.connectOrCreate({ ...context, input: input.connectOrCreate });
|
|
76
|
+
return [await processor.connectOrCreate({ ...context, input: input.connectOrCreate })];
|
|
77
77
|
}
|
|
78
78
|
if (isIt.isIt(input, "delete")) {
|
|
79
|
-
return processor.delete({ ...context, input: void 0 });
|
|
79
|
+
return [await processor.delete({ ...context, input: void 0 })];
|
|
80
80
|
}
|
|
81
81
|
if (isIt.isIt(input, "disconnect")) {
|
|
82
|
-
return processor.disconnect({ ...context, input: void 0 });
|
|
82
|
+
return [await processor.disconnect({ ...context, input: void 0 })];
|
|
83
83
|
}
|
|
84
84
|
if (isIt.isIt(input, "update")) {
|
|
85
|
-
return processor.update({ ...context, input: input.update });
|
|
85
|
+
return [await processor.update({ ...context, input: input.update })];
|
|
86
86
|
}
|
|
87
87
|
if (isIt.isIt(input, "upsert")) {
|
|
88
|
-
return processor.upsert({ ...context, input: input.upsert });
|
|
88
|
+
return [await processor.upsert({ ...context, input: input.upsert })];
|
|
89
89
|
}
|
|
90
90
|
throw new exception.ImplementationException();
|
|
91
91
|
}
|
|
92
92
|
async processManyRelationInput(processor, context, input) {
|
|
93
93
|
if (input === void 0 || input === null) {
|
|
94
|
-
return Promise.resolve(
|
|
94
|
+
return Promise.resolve([]);
|
|
95
95
|
}
|
|
96
96
|
const results = [];
|
|
97
97
|
let i = 0;
|
|
@@ -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, isIt } from '../utils'\nimport { UpdateInputProcessor } from './UpdateInputProcessor'\nimport { ImplementationException, UserError } from '../exception'\n\nexport class UpdateInputVisitor<Result> implements\n\tModel.ColumnVisitor<Promise<Result | Result[] | undefined>>,\n\tModel.RelationByTypeVisitor<Promise<Result | Result[] | undefined>> {\n\n\tconstructor(\n\t\tprivate readonly updateInputProcessor: UpdateInputProcessor<Result>,\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly data: Input.UpdateDataInput,\n\t) {}\n\n\tpublic visitColumn({ entity, column }: Model.ColumnContext): Promise<Result> {\n\t\treturn this.updateInputProcessor.column({\n\t\t\tentity,\n\t\t\tcolumn,\n\t\t\tinput: this.data[column.name] as Input.ColumnValue,\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 Input.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 Input.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 Input.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 Input.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 Input.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 Input.CreateOneRelationInput,\n\t\t)\n\t}\n\n\tprivate processRelationInput<Context>(\n\t\tprocessor: UpdateInputProcessor.HasOneRelationInputProcessor<Context, Result>,\n\t\tcontext: Context,\n\t\tinput: Input.UpdateOneRelationInput | undefined,\n\t): Promise<undefined | Result> {\n\t\tif (input === undefined || input === null) {\n\t\t\treturn Promise.resolve(undefined)\n\t\t}\n\t\tinput = filterObject(input, (k, v) => v !== null && v !== undefined)\n\t\tthis.verifyOperations(input)\n\t\tif (isIt<Input.ConnectRelationInput>(input, 'connect')) {\n\t\t\treturn processor.connect({ ...context, input: input.connect })\n\t\t}\n\t\tif (isIt<Input.CreateRelationInput>(input, 'create')) {\n\t\t\treturn processor.create({ ...context, input: input.create })\n\t\t}\n\t\tif (isIt<Input.ConnectOrCreateRelationInput>(input, 'connectOrCreate')) {\n\t\t\treturn processor.connectOrCreate({ ...context, input: input.connectOrCreate })\n\t\t}\n\t\tif (isIt<Input.DeleteRelationInput>(input, 'delete')) {\n\t\t\treturn processor.delete({ ...context, input: undefined })\n\t\t}\n\t\tif (isIt<Input.DisconnectRelationInput>(input, 'disconnect')) {\n\t\t\treturn processor.disconnect({ ...context, input: undefined })\n\t\t}\n\t\tif (isIt<Input.UpdateRelationInput>(input, 'update')) {\n\t\t\treturn processor.update({ ...context, input: input.update })\n\t\t}\n\t\tif (isIt<Input.UpsertRelationInput>(input, 'upsert')) {\n\t\t\treturn 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: Input.UpdateManyRelationInput | undefined,\n\t): Promise<undefined | Result[]> {\n\t\tif (input === undefined || input === null) {\n\t\t\treturn Promise.resolve(undefined)\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 (isIt<Input.ConnectRelationInput>(element, 'connect')) {\n\t\t\t\tresult = processor.connect({ ...context, input: element.connect, index: i, alias })\n\t\t\t}\n\t\t\tif (isIt<Input.CreateRelationInput>(element, 'create')) {\n\t\t\t\tresult = processor.create({ ...context, input: element.create, index: i, alias })\n\t\t\t}\n\t\t\tif (isIt<Input.ConnectOrCreateRelationInput>(element, 'connectOrCreate')) {\n\t\t\t\tresult = processor.connectOrCreate({ ...context, input: element.connectOrCreate, index: i, alias })\n\t\t\t}\n\t\t\tif (isIt<Input.DeleteSpecifiedRelationInput>(element, 'delete')) {\n\t\t\t\tresult = processor.delete({ ...context, input: element.delete, index: i, alias })\n\t\t\t}\n\t\t\tif (isIt<Input.DisconnectSpecifiedRelationInput>(element, 'disconnect')) {\n\t\t\t\tresult = processor.disconnect({ ...context, input: element.disconnect, index: i, alias })\n\t\t\t}\n\t\t\tif (isIt<Input.UpdateSpecifiedRelationInput>(element, 'update')) {\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 (isIt<Input.UpsertSpecifiedRelationInput>(element, 'upsert')) {\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","isIt","ImplementationException","Input","UserError"],"mappings":";;;;;;;AAKO,MAAM,mBAEwD;AAAA,EAEpE,YACkB,sBACAA,SACA,MAChB;AAHgB,SAAA,uBAAA;AACA,SAAA,SAAAA;AACA,SAAA,OAAA;AAAA,EACf;AAAA,EAEI,YAAY,EAAE,QAAQ,UAAgD;AACrE,WAAA,KAAK,qBAAqB,OAAO;AAAA,MACvC;AAAA,MACA;AAAA,MACA,OAAO,KAAK,KAAK,OAAO,IAAI;AAAA,IAAA,CAC5B;AAAA,EACF;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;AAA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AAK,IAAI;AACzD,YAAM,IAAIC,UAAA;AAAA,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, isIt } from '../utils'\nimport { UpdateInputProcessor } from './UpdateInputProcessor'\nimport { ImplementationException, UserError } from '../exception'\n\nexport class UpdateInputVisitor<Result> implements\n\tModel.ColumnVisitor<Promise<Result[]>>,\n\tModel.RelationByTypeVisitor<Promise<Result[]>> {\n\n\tconstructor(\n\t\tprivate readonly updateInputProcessor: UpdateInputProcessor<Result>,\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly data: Input.UpdateDataInput,\n\t) {}\n\n\tpublic async visitColumn({ entity, column }: Model.ColumnContext): Promise<Result[]> {\n\t\treturn [await this.updateInputProcessor.column({\n\t\t\tentity,\n\t\t\tcolumn,\n\t\t\tinput: this.data[column.name] as Input.ColumnValue,\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 Input.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 Input.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 Input.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 Input.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 Input.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 Input.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: Input.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 (isIt<Input.ConnectRelationInput>(input, 'connect')) {\n\t\t\treturn [await processor.connect({ ...context, input: input.connect })]\n\t\t}\n\t\tif (isIt<Input.CreateRelationInput>(input, 'create')) {\n\t\t\treturn [await processor.create({ ...context, input: input.create })]\n\t\t}\n\t\tif (isIt<Input.ConnectOrCreateRelationInput>(input, 'connectOrCreate')) {\n\t\t\treturn [await processor.connectOrCreate({ ...context, input: input.connectOrCreate })]\n\t\t}\n\t\tif (isIt<Input.DeleteRelationInput>(input, 'delete')) {\n\t\t\treturn [await processor.delete({ ...context, input: undefined })]\n\t\t}\n\t\tif (isIt<Input.DisconnectRelationInput>(input, 'disconnect')) {\n\t\t\treturn [await processor.disconnect({ ...context, input: undefined })]\n\t\t}\n\t\tif (isIt<Input.UpdateRelationInput>(input, 'update')) {\n\t\t\treturn [await processor.update({ ...context, input: input.update })]\n\t\t}\n\t\tif (isIt<Input.UpsertRelationInput>(input, 'upsert')) {\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: Input.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 (isIt<Input.ConnectRelationInput>(element, 'connect')) {\n\t\t\t\tresult = processor.connect({ ...context, input: element.connect, index: i, alias })\n\t\t\t}\n\t\t\tif (isIt<Input.CreateRelationInput>(element, 'create')) {\n\t\t\t\tresult = processor.create({ ...context, input: element.create, index: i, alias })\n\t\t\t}\n\t\t\tif (isIt<Input.ConnectOrCreateRelationInput>(element, 'connectOrCreate')) {\n\t\t\t\tresult = processor.connectOrCreate({ ...context, input: element.connectOrCreate, index: i, alias })\n\t\t\t}\n\t\t\tif (isIt<Input.DeleteSpecifiedRelationInput>(element, 'delete')) {\n\t\t\t\tresult = processor.delete({ ...context, input: element.delete, index: i, alias })\n\t\t\t}\n\t\t\tif (isIt<Input.DisconnectSpecifiedRelationInput>(element, 'disconnect')) {\n\t\t\t\tresult = processor.disconnect({ ...context, input: element.disconnect, index: i, alias })\n\t\t\t}\n\t\t\tif (isIt<Input.UpdateSpecifiedRelationInput>(element, 'update')) {\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 (isIt<Input.UpsertSpecifiedRelationInput>(element, 'upsert')) {\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","isIt","ImplementationException","Input","UserError"],"mappings":";;;;;;;AAKO,MAAM,mBAEmC;AAAA,EAE/C,YACkB,sBACAA,SACA,MAChB;AAHgB,SAAA,uBAAA;AACA,SAAA,SAAAA;AACA,SAAA,OAAA;AAAA,EACf;AAAA,EAEH,MAAa,YAAY,EAAE,QAAQ,UAAkD;AACpF,WAAO,CAAC,MAAM,KAAK,qBAAqB,OAAO;AAAA,MAC9C;AAAA,MACA;AAAA,MACA,OAAO,KAAK,KAAK,OAAO,IAAI;AAAA,IAC5B,CAAA,CAAC;AAAA,EACH;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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AAC3D,UAAM,MAAM,OAAO,OAAOE,OAAA,MAAM,uBAAuB;AACnD,QAAA,KAAK,WAAW,KAAK,CAAC,IAAI,SAAS,KAAK,CAAC,CAAC,GAAG;AAChD,YAAM,QAAQ,KAAK,WAAW,IAAI,SAAS,KAAK,KAAK,IAAI;AACzD,YAAM,IAAIC,UAAA;AAAA,QACT,4BAA4B,IAAI,KAAK,IAAI,CAAC,KAAK,KAAK;AAAA,MAAA;AAAA,IAEtD;AAAA,EACD;AACD;;"}
|
|
@@ -9,12 +9,12 @@ class UpdateInputVisitor {
|
|
|
9
9
|
this.schema = schema;
|
|
10
10
|
this.data = data;
|
|
11
11
|
}
|
|
12
|
-
visitColumn({ entity, column }) {
|
|
13
|
-
return this.updateInputProcessor.column({
|
|
12
|
+
async visitColumn({ entity, column }) {
|
|
13
|
+
return [await this.updateInputProcessor.column({
|
|
14
14
|
entity,
|
|
15
15
|
column,
|
|
16
16
|
input: this.data[column.name]
|
|
17
|
-
});
|
|
17
|
+
})];
|
|
18
18
|
}
|
|
19
19
|
visitManyHasManyInverse(context) {
|
|
20
20
|
return this.processManyRelationInput(
|
|
@@ -58,38 +58,38 @@ class UpdateInputVisitor {
|
|
|
58
58
|
this.data[context.relation.name]
|
|
59
59
|
);
|
|
60
60
|
}
|
|
61
|
-
processRelationInput(processor, context, input) {
|
|
61
|
+
async processRelationInput(processor, context, input) {
|
|
62
62
|
if (input === void 0 || input === null) {
|
|
63
|
-
return Promise.resolve(
|
|
63
|
+
return Promise.resolve([]);
|
|
64
64
|
}
|
|
65
65
|
input = filterObject(input, (k, v) => v !== null && v !== void 0);
|
|
66
66
|
this.verifyOperations(input);
|
|
67
67
|
if (isIt(input, "connect")) {
|
|
68
|
-
return processor.connect({ ...context, input: input.connect });
|
|
68
|
+
return [await processor.connect({ ...context, input: input.connect })];
|
|
69
69
|
}
|
|
70
70
|
if (isIt(input, "create")) {
|
|
71
|
-
return processor.create({ ...context, input: input.create });
|
|
71
|
+
return [await processor.create({ ...context, input: input.create })];
|
|
72
72
|
}
|
|
73
73
|
if (isIt(input, "connectOrCreate")) {
|
|
74
|
-
return processor.connectOrCreate({ ...context, input: input.connectOrCreate });
|
|
74
|
+
return [await processor.connectOrCreate({ ...context, input: input.connectOrCreate })];
|
|
75
75
|
}
|
|
76
76
|
if (isIt(input, "delete")) {
|
|
77
|
-
return processor.delete({ ...context, input: void 0 });
|
|
77
|
+
return [await processor.delete({ ...context, input: void 0 })];
|
|
78
78
|
}
|
|
79
79
|
if (isIt(input, "disconnect")) {
|
|
80
|
-
return processor.disconnect({ ...context, input: void 0 });
|
|
80
|
+
return [await processor.disconnect({ ...context, input: void 0 })];
|
|
81
81
|
}
|
|
82
82
|
if (isIt(input, "update")) {
|
|
83
|
-
return processor.update({ ...context, input: input.update });
|
|
83
|
+
return [await processor.update({ ...context, input: input.update })];
|
|
84
84
|
}
|
|
85
85
|
if (isIt(input, "upsert")) {
|
|
86
|
-
return processor.upsert({ ...context, input: input.upsert });
|
|
86
|
+
return [await processor.upsert({ ...context, input: input.upsert })];
|
|
87
87
|
}
|
|
88
88
|
throw new ImplementationException();
|
|
89
89
|
}
|
|
90
90
|
async processManyRelationInput(processor, context, input) {
|
|
91
91
|
if (input === void 0 || input === null) {
|
|
92
|
-
return Promise.resolve(
|
|
92
|
+
return Promise.resolve([]);
|
|
93
93
|
}
|
|
94
94
|
const results = [];
|
|
95
95
|
let i = 0;
|
|
@@ -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, isIt } from '../utils'\nimport { UpdateInputProcessor } from './UpdateInputProcessor'\nimport { ImplementationException, UserError } from '../exception'\n\nexport class UpdateInputVisitor<Result> implements\n\tModel.ColumnVisitor<Promise<Result | Result[] | undefined>>,\n\tModel.RelationByTypeVisitor<Promise<Result | Result[] | undefined>> {\n\n\tconstructor(\n\t\tprivate readonly updateInputProcessor: UpdateInputProcessor<Result>,\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly data: Input.UpdateDataInput,\n\t) {}\n\n\tpublic visitColumn({ entity, column }: Model.ColumnContext): Promise<Result> {\n\t\treturn this.updateInputProcessor.column({\n\t\t\tentity,\n\t\t\tcolumn,\n\t\t\tinput: this.data[column.name] as Input.ColumnValue,\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 Input.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 Input.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 Input.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 Input.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 Input.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 Input.CreateOneRelationInput,\n\t\t)\n\t}\n\n\tprivate processRelationInput<Context>(\n\t\tprocessor: UpdateInputProcessor.HasOneRelationInputProcessor<Context, Result>,\n\t\tcontext: Context,\n\t\tinput: Input.UpdateOneRelationInput | undefined,\n\t): Promise<undefined | Result> {\n\t\tif (input === undefined || input === null) {\n\t\t\treturn Promise.resolve(undefined)\n\t\t}\n\t\tinput = filterObject(input, (k, v) => v !== null && v !== undefined)\n\t\tthis.verifyOperations(input)\n\t\tif (isIt<Input.ConnectRelationInput>(input, 'connect')) {\n\t\t\treturn processor.connect({ ...context, input: input.connect })\n\t\t}\n\t\tif (isIt<Input.CreateRelationInput>(input, 'create')) {\n\t\t\treturn processor.create({ ...context, input: input.create })\n\t\t}\n\t\tif (isIt<Input.ConnectOrCreateRelationInput>(input, 'connectOrCreate')) {\n\t\t\treturn processor.connectOrCreate({ ...context, input: input.connectOrCreate })\n\t\t}\n\t\tif (isIt<Input.DeleteRelationInput>(input, 'delete')) {\n\t\t\treturn processor.delete({ ...context, input: undefined })\n\t\t}\n\t\tif (isIt<Input.DisconnectRelationInput>(input, 'disconnect')) {\n\t\t\treturn processor.disconnect({ ...context, input: undefined })\n\t\t}\n\t\tif (isIt<Input.UpdateRelationInput>(input, 'update')) {\n\t\t\treturn processor.update({ ...context, input: input.update })\n\t\t}\n\t\tif (isIt<Input.UpsertRelationInput>(input, 'upsert')) {\n\t\t\treturn 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: Input.UpdateManyRelationInput | undefined,\n\t): Promise<undefined | Result[]> {\n\t\tif (input === undefined || input === null) {\n\t\t\treturn Promise.resolve(undefined)\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 (isIt<Input.ConnectRelationInput>(element, 'connect')) {\n\t\t\t\tresult = processor.connect({ ...context, input: element.connect, index: i, alias })\n\t\t\t}\n\t\t\tif (isIt<Input.CreateRelationInput>(element, 'create')) {\n\t\t\t\tresult = processor.create({ ...context, input: element.create, index: i, alias })\n\t\t\t}\n\t\t\tif (isIt<Input.ConnectOrCreateRelationInput>(element, 'connectOrCreate')) {\n\t\t\t\tresult = processor.connectOrCreate({ ...context, input: element.connectOrCreate, index: i, alias })\n\t\t\t}\n\t\t\tif (isIt<Input.DeleteSpecifiedRelationInput>(element, 'delete')) {\n\t\t\t\tresult = processor.delete({ ...context, input: element.delete, index: i, alias })\n\t\t\t}\n\t\t\tif (isIt<Input.DisconnectSpecifiedRelationInput>(element, 'disconnect')) {\n\t\t\t\tresult = processor.disconnect({ ...context, input: element.disconnect, index: i, alias })\n\t\t\t}\n\t\t\tif (isIt<Input.UpdateSpecifiedRelationInput>(element, 'update')) {\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 (isIt<Input.UpsertSpecifiedRelationInput>(element, 'upsert')) {\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":";;;;;AAKO,MAAM,mBAEwD;AAAA,EAEpE,YACkB,sBACA,QACA,MAChB;AAHgB,SAAA,uBAAA;AACA,SAAA,SAAA;AACA,SAAA,OAAA;AAAA,EACf;AAAA,EAEI,YAAY,EAAE,QAAQ,UAAgD;AACrE,WAAA,KAAK,qBAAqB,OAAO;AAAA,MACvC;AAAA,MACA;AAAA,MACA,OAAO,KAAK,KAAK,OAAO,IAAI;AAAA,IAAA,CAC5B;AAAA,EACF;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,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BAAS,UAAU,OAAO;AAAA,UACzB,GAAG;AAAA,UACH,OAAO,EAAE,OAAO,QAAQ,OAAO,IAAI,QAAQ,QAAQ,OAAO,QAAQ,QAAQ,QAAQ,OAAO,OAAO;AAAA,UAChG,OAAO;AAAA,UACP;AAAA,QAAA,CACA;AAAA,MACF;AAEA,UAAI,WAAW,QAAW;AACjB,gBAAA,KAAK,MAAM,MAAM;AAAA,MAC1B;AAAA,IACD;AACO,WAAA;AAAA,EACR;AAAA,EAEQ,iBAAiB,OAAe;AACjC,UAAA,OAAO,OAAO,KAAK,KAAK,EAAE,OAAO,CAAA,OAAM,OAAO,OAAO;AAC3D,UAAM,MAAM,OAAO,OAAO,MAAM,uBAAuB;AACnD,QAAA,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, isIt } from '../utils'\nimport { UpdateInputProcessor } from './UpdateInputProcessor'\nimport { ImplementationException, UserError } from '../exception'\n\nexport class UpdateInputVisitor<Result> implements\n\tModel.ColumnVisitor<Promise<Result[]>>,\n\tModel.RelationByTypeVisitor<Promise<Result[]>> {\n\n\tconstructor(\n\t\tprivate readonly updateInputProcessor: UpdateInputProcessor<Result>,\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly data: Input.UpdateDataInput,\n\t) {}\n\n\tpublic async visitColumn({ entity, column }: Model.ColumnContext): Promise<Result[]> {\n\t\treturn [await this.updateInputProcessor.column({\n\t\t\tentity,\n\t\t\tcolumn,\n\t\t\tinput: this.data[column.name] as Input.ColumnValue,\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 Input.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 Input.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 Input.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 Input.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 Input.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 Input.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: Input.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 (isIt<Input.ConnectRelationInput>(input, 'connect')) {\n\t\t\treturn [await processor.connect({ ...context, input: input.connect })]\n\t\t}\n\t\tif (isIt<Input.CreateRelationInput>(input, 'create')) {\n\t\t\treturn [await processor.create({ ...context, input: input.create })]\n\t\t}\n\t\tif (isIt<Input.ConnectOrCreateRelationInput>(input, 'connectOrCreate')) {\n\t\t\treturn [await processor.connectOrCreate({ ...context, input: input.connectOrCreate })]\n\t\t}\n\t\tif (isIt<Input.DeleteRelationInput>(input, 'delete')) {\n\t\t\treturn [await processor.delete({ ...context, input: undefined })]\n\t\t}\n\t\tif (isIt<Input.DisconnectRelationInput>(input, 'disconnect')) {\n\t\t\treturn [await processor.disconnect({ ...context, input: undefined })]\n\t\t}\n\t\tif (isIt<Input.UpdateRelationInput>(input, 'update')) {\n\t\t\treturn [await processor.update({ ...context, input: input.update })]\n\t\t}\n\t\tif (isIt<Input.UpsertRelationInput>(input, 'upsert')) {\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: Input.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 (isIt<Input.ConnectRelationInput>(element, 'connect')) {\n\t\t\t\tresult = processor.connect({ ...context, input: element.connect, index: i, alias })\n\t\t\t}\n\t\t\tif (isIt<Input.CreateRelationInput>(element, 'create')) {\n\t\t\t\tresult = processor.create({ ...context, input: element.create, index: i, alias })\n\t\t\t}\n\t\t\tif (isIt<Input.ConnectOrCreateRelationInput>(element, 'connectOrCreate')) {\n\t\t\t\tresult = processor.connectOrCreate({ ...context, input: element.connectOrCreate, index: i, alias })\n\t\t\t}\n\t\t\tif (isIt<Input.DeleteSpecifiedRelationInput>(element, 'delete')) {\n\t\t\t\tresult = processor.delete({ ...context, input: element.delete, index: i, alias })\n\t\t\t}\n\t\t\tif (isIt<Input.DisconnectSpecifiedRelationInput>(element, 'disconnect')) {\n\t\t\t\tresult = processor.disconnect({ ...context, input: element.disconnect, index: i, alias })\n\t\t\t}\n\t\t\tif (isIt<Input.UpdateSpecifiedRelationInput>(element, 'update')) {\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 (isIt<Input.UpsertSpecifiedRelationInput>(element, 'upsert')) {\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":";;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