@contember/engine-content-api 2.0.0-alpha.20 → 2.0.0-alpha.22
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
|
@@ -20,36 +20,64 @@ class Updater {
|
|
|
20
20
|
if (filter && Object.keys(filter).length > 0) {
|
|
21
21
|
updateBuilder.addOldWhere(filter);
|
|
22
22
|
}
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
const visitor = new UpdateInputVisitor.UpdateInputVisitor(
|
|
24
|
+
new SqlUpdateInputProcessor.SqlUpdateInputProcessor(primaryValue, data, updateBuilder, mapper),
|
|
25
|
+
this.schema,
|
|
26
|
+
data
|
|
27
|
+
);
|
|
28
|
+
const resultList = [];
|
|
29
|
+
const postUpdates = [];
|
|
30
|
+
for (const key of Object.keys(data)) {
|
|
31
|
+
const resultSet = await schemaUtils.acceptFieldVisitor(
|
|
32
|
+
this.schema,
|
|
33
|
+
entity,
|
|
34
|
+
key,
|
|
35
|
+
visitor
|
|
36
|
+
);
|
|
37
|
+
for (const result2 of resultSet) {
|
|
38
|
+
if (typeof result2 === "function") {
|
|
39
|
+
postUpdates.push(result2);
|
|
40
|
+
} else {
|
|
41
|
+
for (const resultItem of await result2) {
|
|
42
|
+
resultList.push(resultItem);
|
|
43
|
+
if (resultItem.error) {
|
|
44
|
+
return resultList;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const result = await updateBuilder.execute(mapper);
|
|
51
|
+
if (!result.executed) {
|
|
52
|
+
resultList.unshift(new Result.MutationNothingToDo([], Result.NothingToDoReason.noData));
|
|
53
|
+
} else if (result.affectedRows !== 1) {
|
|
54
|
+
return [new Result.MutationNoResultError([])];
|
|
31
55
|
} else {
|
|
32
|
-
|
|
56
|
+
const okResult = new Result.MutationUpdateOk([], entity, primaryValue, data, ColumnValue.rowDataToFieldValues(result.values));
|
|
57
|
+
resultList.unshift(okResult);
|
|
33
58
|
}
|
|
59
|
+
for (const postUpdate of postUpdates) {
|
|
60
|
+
const postInsertResult = await postUpdate({ primary: primaryValue });
|
|
61
|
+
for (const result2 of postInsertResult) {
|
|
62
|
+
resultList.push(result2);
|
|
63
|
+
if (result2.error) {
|
|
64
|
+
return resultList;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return resultList;
|
|
34
69
|
}
|
|
35
70
|
async updateCb(mapper, entity, primaryValue, builderCb) {
|
|
36
71
|
const updateBuilder = this.updateBuilderFactory.create(entity, primaryValue);
|
|
37
|
-
const okResultFactory = (values) => new Result.MutationUpdateOk([], entity, primaryValue, {}, values);
|
|
38
72
|
builderCb(updateBuilder);
|
|
39
|
-
return Updater.executeUpdate(updateBuilder, mapper, okResultFactory);
|
|
40
|
-
}
|
|
41
|
-
static async executeUpdate(updateBuilder, mapper, okResultFactory) {
|
|
42
73
|
const result = await updateBuilder.execute(mapper);
|
|
43
|
-
if (result.aborted) {
|
|
44
|
-
return [new Result.MutationNothingToDo([], Result.NothingToDoReason.aborted)];
|
|
45
|
-
}
|
|
46
74
|
if (!result.executed) {
|
|
47
75
|
return [new Result.MutationNothingToDo([], Result.NothingToDoReason.noData)];
|
|
48
76
|
}
|
|
49
77
|
if (result.affectedRows !== 1) {
|
|
50
78
|
return [new Result.MutationNoResultError([])];
|
|
51
79
|
}
|
|
52
|
-
return [
|
|
80
|
+
return [new Result.MutationUpdateOk([], entity, primaryValue, {}, ColumnValue.rowDataToFieldValues(result.values))];
|
|
53
81
|
}
|
|
54
82
|
}
|
|
55
83
|
exports.Updater = Updater;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Updater.cjs","sources":["../../../../../../packages/engine-content-api/src/mapper/update/Updater.ts"],"sourcesContent":["import { SqlUpdateInputProcessor } from './SqlUpdateInputProcessor'\nimport { UpdateInputVisitor } from '../../inputProcessing'\nimport { Input, Model } from '@contember/schema'\nimport { PredicateFactory } from '../../acl'\nimport { UpdateBuilderFactory } from './UpdateBuilderFactory'\nimport { Mapper } from '../Mapper'\nimport {
|
|
1
|
+
{"version":3,"file":"Updater.cjs","sources":["../../../../../../packages/engine-content-api/src/mapper/update/Updater.ts"],"sourcesContent":["import { SqlUpdateInputProcessor, SqlUpdateInputProcessorResult } from './SqlUpdateInputProcessor'\nimport { UpdateInputVisitor } from '../../inputProcessing'\nimport { Input, Model } from '@contember/schema'\nimport { PredicateFactory } from '../../acl'\nimport { UpdateBuilderFactory } from './UpdateBuilderFactory'\nimport { Mapper } from '../Mapper'\nimport { acceptFieldVisitor } from '@contember/schema-utils'\nimport { MutationNoResultError, MutationNothingToDo, MutationResultList, MutationUpdateOk, NothingToDoReason, RowValues } from '../Result'\nimport { UpdateBuilder } from './UpdateBuilder'\nimport { rowDataToFieldValues } from '../ColumnValue'\nimport { DatabaseMetadata } from '@contember/database'\n\nexport class Updater {\n\tconstructor(\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly schemaDatabaseMetadata: DatabaseMetadata,\n\t\tprivate readonly predicateFactory: PredicateFactory,\n\t\tprivate readonly updateBuilderFactory: UpdateBuilderFactory,\n\t) {}\n\n\tpublic async update(\n\t\tmapper: Mapper,\n\t\tentity: Model.Entity,\n\t\tprimaryValue: Input.PrimaryValue,\n\t\tdata: Input.UpdateDataInput,\n\t\tfilter?: Input.OptionalWhere,\n\t): Promise<MutationResultList> {\n\t\tconst updateBuilder = this.updateBuilderFactory.create(entity, primaryValue)\n\n\t\tconst predicateFields = Object.keys(data)\n\t\tupdateBuilder.addPredicates(predicateFields)\n\t\tif (filter && Object.keys(filter).length > 0) {\n\t\t\tupdateBuilder.addOldWhere(filter)\n\t\t}\n\n\t\tconst visitor = new UpdateInputVisitor<SqlUpdateInputProcessorResult>(\n\t\t\tnew SqlUpdateInputProcessor(primaryValue, data, updateBuilder, mapper),\n\t\t\tthis.schema,\n\t\t\tdata,\n\t\t)\n\t\tconst resultList: MutationResultList = []\n\t\tconst postUpdates: Exclude<SqlUpdateInputProcessorResult, MutationResultList>[] = []\n\n\t\tfor (const key of Object.keys(data)) {\n\t\t\tconst resultSet = await acceptFieldVisitor(\n\t\t\t\tthis.schema,\n\t\t\t\tentity,\n\t\t\t\tkey,\n\t\t\t\tvisitor,\n\t\t\t)\n\t\t\tfor (const result of resultSet) {\n\t\t\t\tif (typeof result === 'function') {\n\t\t\t\t\tpostUpdates.push(result)\n\t\t\t\t} else {\n\t\t\t\t\tfor (const resultItem of await result) {\n\t\t\t\t\t\tresultList.push(resultItem)\n\t\t\t\t\t\tif (resultItem.error) {\n\t\t\t\t\t\t\treturn resultList\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst result = await updateBuilder.execute(mapper)\n\n\t\tif (!result.executed) {\n\t\t\tresultList.unshift(new MutationNothingToDo([], NothingToDoReason.noData))\n\t\t} else if (result.affectedRows !== 1) {\n\t\t\treturn [new MutationNoResultError([])]\n\t\t} else {\n\t\t\tconst okResult = new MutationUpdateOk([], entity, primaryValue, data, rowDataToFieldValues(result.values))\n\t\t\tresultList.unshift(okResult)\n\t\t}\n\n\t\tfor (const postUpdate of postUpdates) {\n\t\t\tconst postInsertResult = await postUpdate({ primary: primaryValue })\n\t\t\tfor (const result of postInsertResult) {\n\t\t\t\tresultList.push(result)\n\t\t\t\tif (result.error) {\n\t\t\t\t\treturn resultList\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn resultList\n\t}\n\n\tpublic async updateCb(\n\t\tmapper: Mapper,\n\t\tentity: Model.Entity,\n\t\tprimaryValue: Input.PrimaryValue,\n\t\tbuilderCb: (builder: UpdateBuilder) => void,\n\t): Promise<MutationResultList> {\n\t\tconst updateBuilder = this.updateBuilderFactory.create(entity, primaryValue)\n\n\t\tbuilderCb(updateBuilder)\n\n\t\tconst result = await updateBuilder.execute(mapper)\n\n\t\tif (!result.executed) {\n\t\t\treturn [new MutationNothingToDo([], NothingToDoReason.noData)]\n\t\t}\n\t\tif (result.affectedRows !== 1) {\n\t\t\treturn [new MutationNoResultError([])]\n\t\t}\n\t\treturn [new MutationUpdateOk([], entity, primaryValue, {}, rowDataToFieldValues(result.values))]\n\t}\n}\n"],"names":["UpdateInputVisitor","SqlUpdateInputProcessor","acceptFieldVisitor","result","MutationNothingToDo","NothingToDoReason","MutationNoResultError","MutationUpdateOk","rowDataToFieldValues"],"mappings":";;;;;;;;AAYO,MAAM,QAAQ;AAAA,EACpB,YACkB,QACA,wBACA,kBACA,sBAChB;AAJgB,SAAA,SAAA;AACA,SAAA,yBAAA;AACA,SAAA,mBAAA;AACA,SAAA,uBAAA;AAAA,EACf;AAAA,EAEH,MAAa,OACZ,QACA,QACA,cACA,MACA,QAC8B;AAC9B,UAAM,gBAAgB,KAAK,qBAAqB,OAAO,QAAQ,YAAY;AAErE,UAAA,kBAAkB,OAAO,KAAK,IAAI;AACxC,kBAAc,cAAc,eAAe;AAC3C,QAAI,UAAU,OAAO,KAAK,MAAM,EAAE,SAAS,GAAG;AAC7C,oBAAc,YAAY,MAAM;AAAA,IACjC;AAEA,UAAM,UAAU,IAAIA,m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AC9B,UAAM,gBAAgB,KAAK,qBAAqB,OAAO,QAAQ,YAAY;AAE3E,cAAU,aAAa;AAEvB,UAAM,SAAS,MAAM,cAAc,QAAQ,MAAM;AAE7C,QAAA,CAAC,OAAO,UAAU;AACrB,aAAO,CAAC,IAAIC,OAAAA,oBAAoB,CAAA,GAAIC,OAAAA,kBAAkB,MAAM,CAAC;AAAA,IAC9D;AACI,QAAA,OAAO,iBAAiB,GAAG;AAC9B,aAAO,CAAC,IAAIC,OAAAA,sBAAsB,CAAE,CAAA,CAAC;AAAA,IACtC;AACA,WAAO,CAAC,IAAIC,OAAAA,iBAAiB,CAAI,GAAA,QAAQ,cAAc,CAAI,GAAAC,iCAAqB,OAAO,MAAM,CAAC,CAAC;AAAA,EAChG;AACD;;"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { SqlUpdateInputProcessor } from "./SqlUpdateInputProcessor.js";
|
|
2
|
-
import {
|
|
2
|
+
import { acceptFieldVisitor } from "@contember/schema-utils";
|
|
3
3
|
import "@contember/schema";
|
|
4
4
|
import { UpdateInputVisitor } from "../../inputProcessing/UpdateInputVisitor.js";
|
|
5
|
-
import {
|
|
5
|
+
import { MutationNothingToDo, NothingToDoReason, MutationNoResultError, MutationUpdateOk } from "../Result.js";
|
|
6
6
|
import { rowDataToFieldValues } from "../ColumnValue.js";
|
|
7
7
|
class Updater {
|
|
8
8
|
constructor(schema, schemaDatabaseMetadata, predicateFactory, updateBuilderFactory) {
|
|
@@ -18,36 +18,64 @@ class Updater {
|
|
|
18
18
|
if (filter && Object.keys(filter).length > 0) {
|
|
19
19
|
updateBuilder.addOldWhere(filter);
|
|
20
20
|
}
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
21
|
+
const visitor = new UpdateInputVisitor(
|
|
22
|
+
new SqlUpdateInputProcessor(primaryValue, data, updateBuilder, mapper),
|
|
23
|
+
this.schema,
|
|
24
|
+
data
|
|
25
|
+
);
|
|
26
|
+
const resultList = [];
|
|
27
|
+
const postUpdates = [];
|
|
28
|
+
for (const key of Object.keys(data)) {
|
|
29
|
+
const resultSet = await acceptFieldVisitor(
|
|
30
|
+
this.schema,
|
|
31
|
+
entity,
|
|
32
|
+
key,
|
|
33
|
+
visitor
|
|
34
|
+
);
|
|
35
|
+
for (const result2 of resultSet) {
|
|
36
|
+
if (typeof result2 === "function") {
|
|
37
|
+
postUpdates.push(result2);
|
|
38
|
+
} else {
|
|
39
|
+
for (const resultItem of await result2) {
|
|
40
|
+
resultList.push(resultItem);
|
|
41
|
+
if (resultItem.error) {
|
|
42
|
+
return resultList;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const result = await updateBuilder.execute(mapper);
|
|
49
|
+
if (!result.executed) {
|
|
50
|
+
resultList.unshift(new MutationNothingToDo([], NothingToDoReason.noData));
|
|
51
|
+
} else if (result.affectedRows !== 1) {
|
|
52
|
+
return [new MutationNoResultError([])];
|
|
29
53
|
} else {
|
|
30
|
-
|
|
54
|
+
const okResult = new MutationUpdateOk([], entity, primaryValue, data, rowDataToFieldValues(result.values));
|
|
55
|
+
resultList.unshift(okResult);
|
|
31
56
|
}
|
|
57
|
+
for (const postUpdate of postUpdates) {
|
|
58
|
+
const postInsertResult = await postUpdate({ primary: primaryValue });
|
|
59
|
+
for (const result2 of postInsertResult) {
|
|
60
|
+
resultList.push(result2);
|
|
61
|
+
if (result2.error) {
|
|
62
|
+
return resultList;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return resultList;
|
|
32
67
|
}
|
|
33
68
|
async updateCb(mapper, entity, primaryValue, builderCb) {
|
|
34
69
|
const updateBuilder = this.updateBuilderFactory.create(entity, primaryValue);
|
|
35
|
-
const okResultFactory = (values) => new MutationUpdateOk([], entity, primaryValue, {}, values);
|
|
36
70
|
builderCb(updateBuilder);
|
|
37
|
-
return Updater.executeUpdate(updateBuilder, mapper, okResultFactory);
|
|
38
|
-
}
|
|
39
|
-
static async executeUpdate(updateBuilder, mapper, okResultFactory) {
|
|
40
71
|
const result = await updateBuilder.execute(mapper);
|
|
41
|
-
if (result.aborted) {
|
|
42
|
-
return [new MutationNothingToDo([], NothingToDoReason.aborted)];
|
|
43
|
-
}
|
|
44
72
|
if (!result.executed) {
|
|
45
73
|
return [new MutationNothingToDo([], NothingToDoReason.noData)];
|
|
46
74
|
}
|
|
47
75
|
if (result.affectedRows !== 1) {
|
|
48
76
|
return [new MutationNoResultError([])];
|
|
49
77
|
}
|
|
50
|
-
return [
|
|
78
|
+
return [new MutationUpdateOk([], entity, primaryValue, {}, rowDataToFieldValues(result.values))];
|
|
51
79
|
}
|
|
52
80
|
}
|
|
53
81
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Updater.js","sources":["../../../../../../packages/engine-content-api/src/mapper/update/Updater.ts"],"sourcesContent":["import { SqlUpdateInputProcessor } from './SqlUpdateInputProcessor'\nimport { UpdateInputVisitor } from '../../inputProcessing'\nimport { Input, Model } from '@contember/schema'\nimport { PredicateFactory } from '../../acl'\nimport { UpdateBuilderFactory } from './UpdateBuilderFactory'\nimport { Mapper } from '../Mapper'\nimport {
|
|
1
|
+
{"version":3,"file":"Updater.js","sources":["../../../../../../packages/engine-content-api/src/mapper/update/Updater.ts"],"sourcesContent":["import { SqlUpdateInputProcessor, SqlUpdateInputProcessorResult } from './SqlUpdateInputProcessor'\nimport { UpdateInputVisitor } from '../../inputProcessing'\nimport { Input, Model } from '@contember/schema'\nimport { PredicateFactory } from '../../acl'\nimport { UpdateBuilderFactory } from './UpdateBuilderFactory'\nimport { Mapper } from '../Mapper'\nimport { acceptFieldVisitor } from '@contember/schema-utils'\nimport { MutationNoResultError, MutationNothingToDo, MutationResultList, MutationUpdateOk, NothingToDoReason, RowValues } from '../Result'\nimport { UpdateBuilder } from './UpdateBuilder'\nimport { rowDataToFieldValues } from '../ColumnValue'\nimport { DatabaseMetadata } from '@contember/database'\n\nexport class Updater {\n\tconstructor(\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly schemaDatabaseMetadata: DatabaseMetadata,\n\t\tprivate readonly predicateFactory: PredicateFactory,\n\t\tprivate readonly updateBuilderFactory: UpdateBuilderFactory,\n\t) {}\n\n\tpublic async update(\n\t\tmapper: Mapper,\n\t\tentity: Model.Entity,\n\t\tprimaryValue: Input.PrimaryValue,\n\t\tdata: Input.UpdateDataInput,\n\t\tfilter?: Input.OptionalWhere,\n\t): Promise<MutationResultList> {\n\t\tconst updateBuilder = this.updateBuilderFactory.create(entity, primaryValue)\n\n\t\tconst predicateFields = Object.keys(data)\n\t\tupdateBuilder.addPredicates(predicateFields)\n\t\tif (filter && Object.keys(filter).length > 0) {\n\t\t\tupdateBuilder.addOldWhere(filter)\n\t\t}\n\n\t\tconst visitor = new UpdateInputVisitor<SqlUpdateInputProcessorResult>(\n\t\t\tnew SqlUpdateInputProcessor(primaryValue, data, updateBuilder, mapper),\n\t\t\tthis.schema,\n\t\t\tdata,\n\t\t)\n\t\tconst resultList: MutationResultList = []\n\t\tconst postUpdates: Exclude<SqlUpdateInputProcessorResult, MutationResultList>[] = []\n\n\t\tfor (const key of Object.keys(data)) {\n\t\t\tconst resultSet = await acceptFieldVisitor(\n\t\t\t\tthis.schema,\n\t\t\t\tentity,\n\t\t\t\tkey,\n\t\t\t\tvisitor,\n\t\t\t)\n\t\t\tfor (const result of resultSet) {\n\t\t\t\tif (typeof result === 'function') {\n\t\t\t\t\tpostUpdates.push(result)\n\t\t\t\t} else {\n\t\t\t\t\tfor (const resultItem of await result) {\n\t\t\t\t\t\tresultList.push(resultItem)\n\t\t\t\t\t\tif (resultItem.error) {\n\t\t\t\t\t\t\treturn resultList\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst result = await updateBuilder.execute(mapper)\n\n\t\tif (!result.executed) {\n\t\t\tresultList.unshift(new MutationNothingToDo([], NothingToDoReason.noData))\n\t\t} else if (result.affectedRows !== 1) {\n\t\t\treturn [new MutationNoResultError([])]\n\t\t} else {\n\t\t\tconst okResult = new MutationUpdateOk([], entity, primaryValue, data, rowDataToFieldValues(result.values))\n\t\t\tresultList.unshift(okResult)\n\t\t}\n\n\t\tfor (const postUpdate of postUpdates) {\n\t\t\tconst postInsertResult = await postUpdate({ primary: primaryValue })\n\t\t\tfor (const result of postInsertResult) {\n\t\t\t\tresultList.push(result)\n\t\t\t\tif (result.error) {\n\t\t\t\t\treturn resultList\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn resultList\n\t}\n\n\tpublic async updateCb(\n\t\tmapper: Mapper,\n\t\tentity: Model.Entity,\n\t\tprimaryValue: Input.PrimaryValue,\n\t\tbuilderCb: (builder: UpdateBuilder) => void,\n\t): Promise<MutationResultList> {\n\t\tconst updateBuilder = this.updateBuilderFactory.create(entity, primaryValue)\n\n\t\tbuilderCb(updateBuilder)\n\n\t\tconst result = await updateBuilder.execute(mapper)\n\n\t\tif (!result.executed) {\n\t\t\treturn [new MutationNothingToDo([], NothingToDoReason.noData)]\n\t\t}\n\t\tif (result.affectedRows !== 1) {\n\t\t\treturn [new MutationNoResultError([])]\n\t\t}\n\t\treturn [new MutationUpdateOk([], entity, primaryValue, {}, rowDataToFieldValues(result.values))]\n\t}\n}\n"],"names":["result"],"mappings":";;;;;;AAYO,MAAM,QAAQ;AAAA,EACpB,YACkB,QACA,wBACA,kBACA,sBAChB;AAJgB,SAAA,SAAA;AACA,SAAA,yBAAA;AACA,SAAA,mBAAA;AACA,SAAA,uBAAA;AAAA,EACf;AAAA,EAEH,MAAa,OACZ,QACA,QACA,cACA,MACA,QAC8B;AAC9B,UAAM,gBAAgB,KAAK,qBAAqB,OAAO,QAAQ,YAAY;AAErE,UAAA,kBAAkB,OAAO,KAAK,IAAI;AACxC,kBAAc,cAAc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D;AAEO,WAAA;AAAA,EACR;AAAA,EAEA,MAAa,SACZ,QACA,QACA,cACA,WAC8B;AAC9B,UAAM,gBAAgB,KAAK,qBAAqB,OAAO,QAAQ,YAAY;AAE3E,cAAU,aAAa;AAEvB,UAAM,SAAS,MAAM,cAAc,QAAQ,MAAM;AAE7C,QAAA,CAAC,OAAO,UAAU;AACrB,aAAO,CAAC,IAAI,oBAAoB,CAAA,GAAI,kBAAkB,MAAM,CAAC;AAAA,IAC9D;AACI,QAAA,OAAO,iBAAiB,GAAG;AAC9B,aAAO,CAAC,IAAI,sBAAsB,CAAE,CAAA,CAAC;AAAA,IACtC;AACA,WAAO,CAAC,IAAI,iBAAiB,CAAI,GAAA,QAAQ,cAAc,CAAI,GAAA,qBAAqB,OAAO,MAAM,CAAC,CAAC;AAAA,EAChG;AACD;"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const Result = require("../../Result.cjs");
|
|
4
|
+
class ManyHasManyUpdateInputProcessor {
|
|
5
|
+
constructor(mapper) {
|
|
6
|
+
this.mapper = mapper;
|
|
7
|
+
}
|
|
8
|
+
async connect({ entity, targetEntity, relation, targetRelation, input }) {
|
|
9
|
+
return async ({ primary }) => {
|
|
10
|
+
const otherPrimary = await this.mapper.getPrimaryValue(targetEntity, input);
|
|
11
|
+
if (!otherPrimary) {
|
|
12
|
+
return [new Result.MutationEntryNotFoundError([], input)];
|
|
13
|
+
}
|
|
14
|
+
return await this.mapper.connectJunction(entity, relation, primary, otherPrimary);
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
async create({ entity, targetEntity, relation, input }) {
|
|
18
|
+
return async ({ primary }) => {
|
|
19
|
+
const insertResult = await this.mapper.insert(targetEntity, input);
|
|
20
|
+
const insertPrimary = Result.getInsertPrimary(insertResult);
|
|
21
|
+
if (!insertPrimary) {
|
|
22
|
+
return insertResult;
|
|
23
|
+
}
|
|
24
|
+
return [
|
|
25
|
+
...insertResult,
|
|
26
|
+
...await this.mapper.connectJunction(entity, relation, primary, insertPrimary)
|
|
27
|
+
];
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
async connectOrCreate(context) {
|
|
31
|
+
return async ({ primary }) => {
|
|
32
|
+
let otherPrimary = await this.mapper.getPrimaryValue(context.targetEntity, context.input.connect);
|
|
33
|
+
if (!otherPrimary) {
|
|
34
|
+
const insertResult = await this.mapper.insert(context.targetEntity, context.input.create);
|
|
35
|
+
otherPrimary = Result.getInsertPrimary(insertResult);
|
|
36
|
+
if (!otherPrimary) {
|
|
37
|
+
return insertResult;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return await this.mapper.connectJunction(context.entity, context.relation, primary, otherPrimary);
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
async update({ entity, targetEntity, relation, input: { where, data } }) {
|
|
44
|
+
return async ({ primary }) => {
|
|
45
|
+
const otherPrimary = await this.mapper.getPrimaryValue(targetEntity, where);
|
|
46
|
+
if (!otherPrimary) {
|
|
47
|
+
return [new Result.MutationEntryNotFoundError([], where)];
|
|
48
|
+
}
|
|
49
|
+
return [
|
|
50
|
+
...await this.mapper.update(targetEntity, { [targetEntity.primary]: otherPrimary }, data),
|
|
51
|
+
...await this.mapper.connectJunction(entity, relation, primary, otherPrimary)
|
|
52
|
+
];
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
async upsert({ entity, relation, targetEntity, input: { create, update, where } }) {
|
|
56
|
+
return async ({ primary }) => {
|
|
57
|
+
const otherPrimary = await this.mapper.getPrimaryValue(targetEntity, where);
|
|
58
|
+
if (otherPrimary) {
|
|
59
|
+
const updateResult = await this.mapper.update(targetEntity, { [targetEntity.primary]: otherPrimary }, update);
|
|
60
|
+
const connectResult = await this.mapper.connectJunction(entity, relation, primary, otherPrimary);
|
|
61
|
+
return [...updateResult, ...connectResult];
|
|
62
|
+
} else {
|
|
63
|
+
const insertResult = await this.mapper.insert(targetEntity, create);
|
|
64
|
+
const primaryValue = Result.getInsertPrimary(insertResult);
|
|
65
|
+
if (!primaryValue) {
|
|
66
|
+
return insertResult;
|
|
67
|
+
}
|
|
68
|
+
const connectResult = await this.mapper.connectJunction(entity, relation, primary, primaryValue);
|
|
69
|
+
return [...insertResult, ...connectResult];
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
async disconnect({ entity, targetEntity, relation, input }) {
|
|
74
|
+
return async ({ primary }) => {
|
|
75
|
+
const otherPrimary = await this.mapper.getPrimaryValue(targetEntity, input);
|
|
76
|
+
if (!otherPrimary) {
|
|
77
|
+
return [new Result.MutationEntryNotFoundError([], input)];
|
|
78
|
+
}
|
|
79
|
+
return await this.mapper.disconnectJunction(entity, relation, primary, otherPrimary);
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
async delete({ entity, targetEntity, relation, targetRelation, input }) {
|
|
83
|
+
return async ({ primary }) => {
|
|
84
|
+
return await this.mapper.delete(targetEntity, input);
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.ManyHasManyUpdateInputProcessor = ManyHasManyUpdateInputProcessor;
|
|
89
|
+
//# sourceMappingURL=ManyHasManyUpdateInputProcessor.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ManyHasManyUpdateInputProcessor.cjs","sources":["../../../../../../../packages/engine-content-api/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.ts"],"sourcesContent":["import { UpdateInputProcessor } from '../../../inputProcessing'\nimport { Input, Model } from '@contember/schema'\nimport { getInsertPrimary, MutationEntryNotFoundError } from '../../Result'\nimport { Mapper } from '../../Mapper'\nimport { SqlUpdateInputProcessorResult } from '../../update'\n\ntype Context = Model.ManyHasManyOwningContext | Model.ManyHasManyInverseContext\n\nexport class ManyHasManyUpdateInputProcessor implements UpdateInputProcessor.HasManyRelationInputProcessor<Context, SqlUpdateInputProcessorResult> {\n\tconstructor(\n\t\tprivate readonly mapper: Mapper,\n\t) {\n\t}\n\n\tpublic async connect(\n\t\t{ entity, targetEntity, relation, targetRelation, input }: Context & { input: Input.UniqueWhere },\n\t) {\n\t\treturn async ({ primary }: { primary: Input.PrimaryValue }) => {\n\t\t\tconst otherPrimary = await this.mapper.getPrimaryValue(targetEntity, input)\n\t\t\tif (!otherPrimary) {\n\t\t\t\treturn [new MutationEntryNotFoundError([], input)]\n\t\t\t}\n\t\t\treturn await this.mapper.connectJunction(entity, relation, primary, otherPrimary)\n\t\t}\n\t}\n\n\tpublic async create(\n\t\t{ entity, targetEntity, relation, input }: Context & { input: Input.CreateDataInput },\n\t) {\n\t\treturn async ({ primary }: { primary: Input.PrimaryValue }) => {\n\t\t\tconst insertResult = await this.mapper.insert(targetEntity, input)\n\t\t\tconst insertPrimary = getInsertPrimary(insertResult)\n\t\t\tif (!insertPrimary) {\n\t\t\t\treturn insertResult\n\t\t\t}\n\t\t\treturn [\n\t\t\t\t...insertResult,\n\t\t\t\t...(await this.mapper.connectJunction(entity, relation, primary, insertPrimary)),\n\t\t\t]\n\t\t}\n\t}\n\n\tpublic async connectOrCreate(\n\t\tcontext: Context & { input: Input.ConnectOrCreateInput },\n\t) {\n\t\treturn async ({ primary }: { primary: Input.PrimaryValue }) => {\n\t\t\tlet otherPrimary = await this.mapper.getPrimaryValue(context.targetEntity, context.input.connect)\n\t\t\tif (!otherPrimary) {\n\t\t\t\tconst insertResult = await this.mapper.insert(context.targetEntity, context.input.create)\n\t\t\t\totherPrimary = getInsertPrimary(insertResult)\n\t\t\t\tif (!otherPrimary) {\n\t\t\t\t\treturn insertResult\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn await this.mapper.connectJunction(context.entity, context.relation, primary, otherPrimary)\n\t\t}\n\t}\n\n\tpublic async update(\n\t\t{ entity, targetEntity, relation, input: { where, data } }: Context & { input: UpdateInputProcessor.UpdateManyInput },\n\t) {\n\t\treturn async ({ primary }: { primary: Input.PrimaryValue }) => {\n\t\t\tconst otherPrimary = await this.mapper.getPrimaryValue(targetEntity, where)\n\t\t\tif (!otherPrimary) {\n\t\t\t\treturn [new MutationEntryNotFoundError([], where)]\n\t\t\t}\n\t\t\treturn [\n\t\t\t\t...(await this.mapper.update(targetEntity, { [targetEntity.primary]: otherPrimary }, data)),\n\t\t\t\t...(await this.mapper.connectJunction(entity, relation, primary, otherPrimary)),\n\t\t\t]\n\t\t}\n\t}\n\n\tpublic async upsert(\n\t\t{ entity, relation, targetEntity, input: { create, update, where } }: Context & { input: UpdateInputProcessor.UpsertManyInput },\n\t) {\n\t\treturn async ({ primary }: { primary: Input.PrimaryValue }) => {\n\t\t\tconst otherPrimary = await this.mapper.getPrimaryValue(targetEntity, where)\n\t\t\tif (otherPrimary) {\n\t\t\t\tconst updateResult = await this.mapper.update(targetEntity, { [targetEntity.primary]: otherPrimary }, update)\n\t\t\t\tconst connectResult = await this.mapper.connectJunction(entity, relation, primary, otherPrimary)\n\t\t\t\treturn [...updateResult, ...connectResult]\n\t\t\t} else {\n\t\t\t\tconst insertResult = await this.mapper.insert(targetEntity, create)\n\n\t\t\t\tconst primaryValue = getInsertPrimary(insertResult)\n\t\t\t\tif (!primaryValue) {\n\t\t\t\t\treturn insertResult\n\t\t\t\t}\n\t\t\t\tconst connectResult = await this.mapper.connectJunction(entity, relation, primary, primaryValue)\n\t\t\t\treturn [...insertResult, ...connectResult]\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic async disconnect(\n\t\t{ entity, targetEntity, relation, input }: Context & { input: Input.UniqueWhere },\n\t) {\n\t\treturn async ({ primary }: { primary: Input.PrimaryValue }) => {\n\t\t\tconst otherPrimary = await this.mapper.getPrimaryValue(targetEntity, input)\n\t\t\tif (!otherPrimary) {\n\t\t\t\treturn [new MutationEntryNotFoundError([], input)]\n\t\t\t}\n\n\t\t\treturn await this.mapper.disconnectJunction(entity, relation, primary, otherPrimary)\n\t\t}\n\t}\n\n\tpublic async delete(\n\t\t{ entity, targetEntity, relation, targetRelation, input }: Context & { input: Input.UniqueWhere },\n\t) {\n\t\treturn async ({ primary }: { primary: Input.PrimaryValue }) => {\n\t\t\treturn await this.mapper.delete(targetEntity, input)\n\t\t}\n\t}\n}\n"],"names":["MutationEntryNotFoundError","getInsertPrimary"],"mappings":";;;AAQO,MAAM,gCAAsI;AAAA,EAClJ,YACkB,QAChB;AADgB,SAAA,SAAA;AAAA,EAElB;AAAA,EAEA,MAAa,QACZ,EAAE,QAAQ,cAAc,UAAU,gBAAgB,SACjD;AACM,WAAA,OAAO,EAAE,cAA+C;AAC9D,YAAM,eAAe,MAAM,KAAK,OAAO,gBAAgB,cAAc,KAAK;AAC1E,UAAI,CAAC,cAAc;AAClB,eAAO,CAAC,IAAIA,OAAA,2BAA2B,IAAI,KAAK,CAAC;AAAA,MAClD;AACA,aAAO,MAAM,KAAK,OAAO,gBAAgB,QAAQ,UAAU,SAAS,YAAY;AAAA,IAAA;AAAA,EAElF;AAAA,EAEA,MAAa,OACZ,EAAE,QAAQ,cAAc,UAAU,SACjC;AACM,WAAA,OAAO,EAAE,cAA+C;AAC9D,YAAM,eAAe,MAAM,KAAK,OAAO,OAAO,cAAc,KAAK;AAC3D,YAAA,gBAAgBC,wBAAiB,YAAY;AACnD,UAAI,CAAC,eAAe;AACZ,eAAA;AAAA,MACR;AACO,aAAA;AAAA,QACN,GAAG;AAAA,QACH,GAAI,MAAM,KAAK,OAAO,gBAAgB,QAAQ,UAAU,SAAS,aAAa;AAAA,MAAA;AAAA,IAC/E;AAAA,EAEF;AAAA,EAEA,MAAa,gBACZ,SACC;AACM,WAAA,OAAO,EAAE,cAA+C;AAC1D,UAAA,eAAe,MAAM,KAAK,OAAO,gBAAgB,QAAQ,cAAc,QAAQ,MAAM,OAAO;AAChG,UAAI,CAAC,cAAc;AACZ,cAAA,eAAe,MAAM,KAAK,OAAO,OAAO,QAAQ,cAAc,QAAQ,MAAM,MAAM;AACxF,uBAAeA,OAAAA,iBAAiB,YAA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B,QAAQ,UAAU,SAAS,YAAY;AAC/F,eAAO,CAAC,GAAG,cAAc,GAAG,aAAa;AAAA,MAC1C;AAAA,IAAA;AAAA,EAEF;AAAA,EAEA,MAAa,WACZ,EAAE,QAAQ,cAAc,UAAU,SACjC;AACM,WAAA,OAAO,EAAE,cAA+C;AAC9D,YAAM,eAAe,MAAM,KAAK,OAAO,gBAAgB,cAAc,KAAK;AAC1E,UAAI,CAAC,cAAc;AAClB,eAAO,CAAC,IAAID,OAAA,2BAA2B,IAAI,KAAK,CAAC;AAAA,MAClD;AAEA,aAAO,MAAM,KAAK,OAAO,mBAAmB,QAAQ,UAAU,SAAS,YAAY;AAAA,IAAA;AAAA,EAErF;AAAA,EAEA,MAAa,OACZ,EAAE,QAAQ,cAAc,UAAU,gBAAgB,SACjD;AACM,WAAA,OAAO,EAAE,cAA+C;AAC9D,aAAO,MAAM,KAAK,OAAO,OAAO,cAAc,KAAK;AAAA,IAAA;AAAA,EAErD;AACD;;"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { MutationEntryNotFoundError, getInsertPrimary } from "../../Result.js";
|
|
2
|
+
class ManyHasManyUpdateInputProcessor {
|
|
3
|
+
constructor(mapper) {
|
|
4
|
+
this.mapper = mapper;
|
|
5
|
+
}
|
|
6
|
+
async connect({ entity, targetEntity, relation, targetRelation, input }) {
|
|
7
|
+
return async ({ primary }) => {
|
|
8
|
+
const otherPrimary = await this.mapper.getPrimaryValue(targetEntity, input);
|
|
9
|
+
if (!otherPrimary) {
|
|
10
|
+
return [new MutationEntryNotFoundError([], input)];
|
|
11
|
+
}
|
|
12
|
+
return await this.mapper.connectJunction(entity, relation, primary, otherPrimary);
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
async create({ entity, targetEntity, relation, input }) {
|
|
16
|
+
return async ({ primary }) => {
|
|
17
|
+
const insertResult = await this.mapper.insert(targetEntity, input);
|
|
18
|
+
const insertPrimary = getInsertPrimary(insertResult);
|
|
19
|
+
if (!insertPrimary) {
|
|
20
|
+
return insertResult;
|
|
21
|
+
}
|
|
22
|
+
return [
|
|
23
|
+
...insertResult,
|
|
24
|
+
...await this.mapper.connectJunction(entity, relation, primary, insertPrimary)
|
|
25
|
+
];
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
async connectOrCreate(context) {
|
|
29
|
+
return async ({ primary }) => {
|
|
30
|
+
let otherPrimary = await this.mapper.getPrimaryValue(context.targetEntity, context.input.connect);
|
|
31
|
+
if (!otherPrimary) {
|
|
32
|
+
const insertResult = await this.mapper.insert(context.targetEntity, context.input.create);
|
|
33
|
+
otherPrimary = getInsertPrimary(insertResult);
|
|
34
|
+
if (!otherPrimary) {
|
|
35
|
+
return insertResult;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return await this.mapper.connectJunction(context.entity, context.relation, primary, otherPrimary);
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
async update({ entity, targetEntity, relation, input: { where, data } }) {
|
|
42
|
+
return async ({ primary }) => {
|
|
43
|
+
const otherPrimary = await this.mapper.getPrimaryValue(targetEntity, where);
|
|
44
|
+
if (!otherPrimary) {
|
|
45
|
+
return [new MutationEntryNotFoundError([], where)];
|
|
46
|
+
}
|
|
47
|
+
return [
|
|
48
|
+
...await this.mapper.update(targetEntity, { [targetEntity.primary]: otherPrimary }, data),
|
|
49
|
+
...await this.mapper.connectJunction(entity, relation, primary, otherPrimary)
|
|
50
|
+
];
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
async upsert({ entity, relation, targetEntity, input: { create, update, where } }) {
|
|
54
|
+
return async ({ primary }) => {
|
|
55
|
+
const otherPrimary = await this.mapper.getPrimaryValue(targetEntity, where);
|
|
56
|
+
if (otherPrimary) {
|
|
57
|
+
const updateResult = await this.mapper.update(targetEntity, { [targetEntity.primary]: otherPrimary }, update);
|
|
58
|
+
const connectResult = await this.mapper.connectJunction(entity, relation, primary, otherPrimary);
|
|
59
|
+
return [...updateResult, ...connectResult];
|
|
60
|
+
} else {
|
|
61
|
+
const insertResult = await this.mapper.insert(targetEntity, create);
|
|
62
|
+
const primaryValue = getInsertPrimary(insertResult);
|
|
63
|
+
if (!primaryValue) {
|
|
64
|
+
return insertResult;
|
|
65
|
+
}
|
|
66
|
+
const connectResult = await this.mapper.connectJunction(entity, relation, primary, primaryValue);
|
|
67
|
+
return [...insertResult, ...connectResult];
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
async disconnect({ entity, targetEntity, relation, input }) {
|
|
72
|
+
return async ({ primary }) => {
|
|
73
|
+
const otherPrimary = await this.mapper.getPrimaryValue(targetEntity, input);
|
|
74
|
+
if (!otherPrimary) {
|
|
75
|
+
return [new MutationEntryNotFoundError([], input)];
|
|
76
|
+
}
|
|
77
|
+
return await this.mapper.disconnectJunction(entity, relation, primary, otherPrimary);
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
async delete({ entity, targetEntity, relation, targetRelation, input }) {
|
|
81
|
+
return async ({ primary }) => {
|
|
82
|
+
return await this.mapper.delete(targetEntity, input);
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
export {
|
|
87
|
+
ManyHasManyUpdateInputProcessor
|
|
88
|
+
};
|
|
89
|
+
//# sourceMappingURL=ManyHasManyUpdateInputProcessor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ManyHasManyUpdateInputProcessor.js","sources":["../../../../../../../packages/engine-content-api/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.ts"],"sourcesContent":["import { UpdateInputProcessor } from '../../../inputProcessing'\nimport { Input, Model } from '@contember/schema'\nimport { getInsertPrimary, MutationEntryNotFoundError } from '../../Result'\nimport { Mapper } from '../../Mapper'\nimport { SqlUpdateInputProcessorResult } from '../../update'\n\ntype Context = Model.ManyHasManyOwningContext | Model.ManyHasManyInverseContext\n\nexport class ManyHasManyUpdateInputProcessor implements UpdateInputProcessor.HasManyRelationInputProcessor<Context, SqlUpdateInputProcessorResult> {\n\tconstructor(\n\t\tprivate readonly mapper: Mapper,\n\t) {\n\t}\n\n\tpublic async connect(\n\t\t{ entity, targetEntity, relation, targetRelation, input }: Context & { input: Input.UniqueWhere },\n\t) {\n\t\treturn async ({ primary }: { primary: Input.PrimaryValue }) => {\n\t\t\tconst otherPrimary = await this.mapper.getPrimaryValue(targetEntity, input)\n\t\t\tif (!otherPrimary) {\n\t\t\t\treturn [new MutationEntryNotFoundError([], input)]\n\t\t\t}\n\t\t\treturn await this.mapper.connectJunction(entity, relation, primary, otherPrimary)\n\t\t}\n\t}\n\n\tpublic async create(\n\t\t{ entity, targetEntity, relation, input }: Context & { input: Input.CreateDataInput },\n\t) {\n\t\treturn async ({ primary }: { primary: Input.PrimaryValue }) => {\n\t\t\tconst insertResult = await this.mapper.insert(targetEntity, input)\n\t\t\tconst insertPrimary = getInsertPrimary(insertResult)\n\t\t\tif (!insertPrimary) {\n\t\t\t\treturn insertResult\n\t\t\t}\n\t\t\treturn [\n\t\t\t\t...insertResult,\n\t\t\t\t...(await this.mapper.connectJunction(entity, relation, primary, insertPrimary)),\n\t\t\t]\n\t\t}\n\t}\n\n\tpublic async connectOrCreate(\n\t\tcontext: Context & { input: Input.ConnectOrCreateInput },\n\t) {\n\t\treturn async ({ primary }: { primary: Input.PrimaryValue }) => {\n\t\t\tlet otherPrimary = await this.mapper.getPrimaryValue(context.targetEntity, context.input.connect)\n\t\t\tif (!otherPrimary) {\n\t\t\t\tconst insertResult = await this.mapper.insert(context.targetEntity, context.input.create)\n\t\t\t\totherPrimary = getInsertPrimary(insertResult)\n\t\t\t\tif (!otherPrimary) {\n\t\t\t\t\treturn insertResult\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn await this.mapper.connectJunction(context.entity, context.relation, primary, otherPrimary)\n\t\t}\n\t}\n\n\tpublic async update(\n\t\t{ entity, targetEntity, relation, input: { where, data } }: Context & { input: UpdateInputProcessor.UpdateManyInput },\n\t) {\n\t\treturn async ({ primary }: { primary: Input.PrimaryValue }) => {\n\t\t\tconst otherPrimary = await this.mapper.getPrimaryValue(targetEntity, where)\n\t\t\tif (!otherPrimary) {\n\t\t\t\treturn [new MutationEntryNotFoundError([], where)]\n\t\t\t}\n\t\t\treturn [\n\t\t\t\t...(await this.mapper.update(targetEntity, { [targetEntity.primary]: otherPrimary }, data)),\n\t\t\t\t...(await this.mapper.connectJunction(entity, relation, primary, otherPrimary)),\n\t\t\t]\n\t\t}\n\t}\n\n\tpublic async upsert(\n\t\t{ entity, relation, targetEntity, input: { create, update, where } }: Context & { input: UpdateInputProcessor.UpsertManyInput },\n\t) {\n\t\treturn async ({ primary }: { primary: Input.PrimaryValue }) => {\n\t\t\tconst otherPrimary = await this.mapper.getPrimaryValue(targetEntity, where)\n\t\t\tif (otherPrimary) {\n\t\t\t\tconst updateResult = await this.mapper.update(targetEntity, { [targetEntity.primary]: otherPrimary }, update)\n\t\t\t\tconst connectResult = await this.mapper.connectJunction(entity, relation, primary, otherPrimary)\n\t\t\t\treturn [...updateResult, ...connectResult]\n\t\t\t} else {\n\t\t\t\tconst insertResult = await this.mapper.insert(targetEntity, create)\n\n\t\t\t\tconst primaryValue = getInsertPrimary(insertResult)\n\t\t\t\tif (!primaryValue) {\n\t\t\t\t\treturn insertResult\n\t\t\t\t}\n\t\t\t\tconst connectResult = await this.mapper.connectJunction(entity, relation, primary, primaryValue)\n\t\t\t\treturn [...insertResult, ...connectResult]\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic async disconnect(\n\t\t{ entity, targetEntity, relation, input }: Context & { input: Input.UniqueWhere },\n\t) {\n\t\treturn async ({ primary }: { primary: Input.PrimaryValue }) => {\n\t\t\tconst otherPrimary = await this.mapper.getPrimaryValue(targetEntity, input)\n\t\t\tif (!otherPrimary) {\n\t\t\t\treturn [new MutationEntryNotFoundError([], input)]\n\t\t\t}\n\n\t\t\treturn await this.mapper.disconnectJunction(entity, relation, primary, otherPrimary)\n\t\t}\n\t}\n\n\tpublic async delete(\n\t\t{ entity, targetEntity, relation, targetRelation, input }: Context & { input: Input.UniqueWhere },\n\t) {\n\t\treturn async ({ primary }: { primary: Input.PrimaryValue }) => {\n\t\t\treturn await this.mapper.delete(targetEntity, input)\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";AAQO,MAAM,gCAAsI;AAAA,EAClJ,YACkB,QAChB;AADgB,SAAA,SAAA;AAAA,EAElB;AAAA,EAEA,MAAa,QACZ,EAAE,QAAQ,cAAc,UAAU,gBAAgB,SACjD;AACM,WAAA,OAAO,EAAE,cAA+C;AAC9D,YAAM,eAAe,MAAM,KAAK,OAAO,gBAAgB,cAAc,KAAK;AAC1E,UAAI,CAAC,cAAc;AAClB,eAAO,CAAC,IAAI,2BAA2B,IAAI,KAAK,CAAC;AAAA,MAClD;AACA,aAAO,MAAM,KAAK,OAAO,gBAAgB,QAAQ,UAAU,SAAS,YAAY;AAAA,IAAA;AAAA,EAElF;AAAA,EAEA,MAAa,OACZ,EAAE,QAAQ,cAAc,UAAU,SACjC;AACM,WAAA,OAAO,EAAE,cAA+C;AAC9D,YAAM,eAAe,MAAM,KAAK,OAAO,OAAO,cAAc,KAAK;AAC3D,YAAA,gBAAgB,iBAAiB,YAAY;AACnD,UAAI,CAAC,eAAe;AACZ,eAAA;AAAA,MACR;AACO,aAAA;AAAA,QACN,GAAG;AAAA,QACH,GAAI,MAAM,KAAK,OAAO,gBAAgB,QAAQ,UAAU,SAAS,aAAa;AAAA,MAAA;AAAA,IAC/E;AAAA,EAEF;AAAA,EAEA,MAAa,gBACZ,SACC;AACM,WAAA,OAAO,EAAE,cAA+C;AAC1D,UAAA,eAAe,MAAM,KAAK,OAAO,gBAAgB,QAAQ,cAAc,QAAQ,MAAM,OAAO;AAChG,UAAI,CAAC,cAAc;AACZ,cAAA,eAAe,MAAM,KAAK,OAAO,OAAO,QAAQ,cAAc,QAAQ,MAAM,MAAM;AACxF,uBAAe,iBAAiB,YAAY;AAC5C,YAAI,CAAC,c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C/F,eAAO,CAAC,GAAG,cAAc,GAAG,aAAa;AAAA,MAC1C;AAAA,IAAA;AAAA,EAEF;AAAA,EAEA,MAAa,WACZ,EAAE,QAAQ,cAAc,UAAU,SACjC;AACM,WAAA,OAAO,EAAE,cAA+C;AAC9D,YAAM,eAAe,MAAM,KAAK,OAAO,gBAAgB,cAAc,KAAK;AAC1E,UAAI,CAAC,cAAc;AAClB,eAAO,CAAC,IAAI,2BAA2B,IAAI,KAAK,CAAC;AAAA,MAClD;AAEA,aAAO,MAAM,KAAK,OAAO,mBAAmB,QAAQ,UAAU,SAAS,YAAY;AAAA,IAAA;AAAA,EAErF;AAAA,EAEA,MAAa,OACZ,EAAE,QAAQ,cAAc,UAAU,gBAAgB,SACjD;AACM,WAAA,OAAO,EAAE,cAA+C;AAC9D,aAAO,MAAM,KAAK,OAAO,OAAO,cAAc,KAAK;AAAA,IAAA;AAAA,EAErD;AACD;"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const schema = require("@contember/schema");
|
|
4
|
+
const Result = require("../../Result.cjs");
|
|
5
|
+
class ManyHasOneUpdateInputProcessor {
|
|
6
|
+
constructor(mapper, builder, primary) {
|
|
7
|
+
this.mapper = mapper;
|
|
8
|
+
this.builder = builder;
|
|
9
|
+
this.primary = primary;
|
|
10
|
+
}
|
|
11
|
+
async connect({ targetEntity, relation, input }) {
|
|
12
|
+
const value = await this.mapper.getPrimaryValue(targetEntity, input);
|
|
13
|
+
if (!value) {
|
|
14
|
+
return [new Result.MutationEntryNotFoundError([], input)];
|
|
15
|
+
}
|
|
16
|
+
this.builder.addFieldValue(relation.name, value);
|
|
17
|
+
return [];
|
|
18
|
+
}
|
|
19
|
+
async create({ relation, targetEntity, input }) {
|
|
20
|
+
const insertResult = await this.mapper.insert(targetEntity, input);
|
|
21
|
+
const value = Result.getInsertPrimary(insertResult);
|
|
22
|
+
if (!value) {
|
|
23
|
+
return insertResult;
|
|
24
|
+
}
|
|
25
|
+
this.builder.addFieldValue(relation.name, value);
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
async connectOrCreate({ input: { connect, create }, relation, targetEntity }) {
|
|
29
|
+
const value = await this.mapper.getPrimaryValue(targetEntity, connect);
|
|
30
|
+
if (value) {
|
|
31
|
+
this.builder.addFieldValue(relation.name, value);
|
|
32
|
+
} else {
|
|
33
|
+
const insertResult = await this.mapper.insert(targetEntity, create);
|
|
34
|
+
const primary = Result.getInsertPrimary(insertResult);
|
|
35
|
+
if (!primary) {
|
|
36
|
+
return insertResult;
|
|
37
|
+
}
|
|
38
|
+
this.builder.addFieldValue(relation.name, primary);
|
|
39
|
+
}
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
42
|
+
async update({ entity, relation, targetEntity, targetRelation, input }) {
|
|
43
|
+
return async ({ primary }) => {
|
|
44
|
+
const inversePrimary = await this.mapper.selectField(
|
|
45
|
+
entity,
|
|
46
|
+
{ [entity.primary]: primary },
|
|
47
|
+
relation.name
|
|
48
|
+
);
|
|
49
|
+
if (!inversePrimary) {
|
|
50
|
+
return [new Result.MutationNothingToDo([], Result.NothingToDoReason.emptyRelation)];
|
|
51
|
+
}
|
|
52
|
+
return await this.mapper.update(targetEntity, { [targetEntity.primary]: inversePrimary }, input);
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
async upsert({ entity, relation, targetEntity, input: { create, update } }) {
|
|
56
|
+
const inversePrimary = await this.mapper.selectField(entity, { [entity.primary]: this.primary }, relation.name);
|
|
57
|
+
if (!inversePrimary) {
|
|
58
|
+
const insertResult = await this.mapper.insert(targetEntity, create);
|
|
59
|
+
const insertPrimary = Result.getInsertPrimary(insertResult);
|
|
60
|
+
if (insertPrimary) {
|
|
61
|
+
this.builder.addFieldValue(relation.name, insertPrimary);
|
|
62
|
+
}
|
|
63
|
+
return insertResult;
|
|
64
|
+
}
|
|
65
|
+
return async () => await this.mapper.update(targetEntity, { [targetEntity.primary]: inversePrimary }, update);
|
|
66
|
+
}
|
|
67
|
+
async disconnect({ entity, targetEntity, relation, targetRelation }) {
|
|
68
|
+
if (!relation.nullable) {
|
|
69
|
+
return [new Result.MutationConstraintViolationError([], Result.ConstraintType.notNull)];
|
|
70
|
+
}
|
|
71
|
+
this.builder.addFieldValue(relation.name, null);
|
|
72
|
+
return [];
|
|
73
|
+
}
|
|
74
|
+
async delete({ entity, targetEntity, relation, targetRelation }) {
|
|
75
|
+
if (!relation.nullable && relation.joiningColumn.onDelete !== schema.Model.OnDelete.cascade) {
|
|
76
|
+
return [new Result.MutationConstraintViolationError([], Result.ConstraintType.notNull)];
|
|
77
|
+
}
|
|
78
|
+
return async ({ primary }) => {
|
|
79
|
+
const inversePrimary = await this.mapper.selectField(
|
|
80
|
+
entity,
|
|
81
|
+
{ [entity.primary]: primary },
|
|
82
|
+
relation.name
|
|
83
|
+
);
|
|
84
|
+
return await this.mapper.delete(targetEntity, { [targetEntity.primary]: inversePrimary });
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.ManyHasOneUpdateInputProcessor = ManyHasOneUpdateInputProcessor;
|
|
89
|
+
//# sourceMappingURL=ManyHasOneUpdateInputProcessor.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ManyHasOneUpdateInputProcessor.cjs","sources":["../../../../../../../packages/engine-content-api/src/mapper/update/relations/ManyHasOneUpdateInputProcessor.ts"],"sourcesContent":["import { UpdateInputProcessor } from '../../../inputProcessing'\nimport { Input, Model } from '@contember/schema'\nimport {\n\tConstraintType,\n\tgetInsertPrimary,\n\tMutationConstraintViolationError,\n\tMutationEntryNotFoundError,\n\tMutationNothingToDo,\n\tNothingToDoReason,\n} from '../../Result'\nimport { Mapper } from '../../Mapper'\nimport { SqlUpdateInputProcessorResult } from '../SqlUpdateInputProcessor'\nimport { UpdateBuilder } from '../UpdateBuilder'\n\ntype Context = Model.ManyHasOneContext\n\nexport class ManyHasOneUpdateInputProcessor implements UpdateInputProcessor.HasOneRelationInputProcessor<Context, SqlUpdateInputProcessorResult>{\n\n\tconstructor(\n\t\tprivate readonly mapper: Mapper,\n\t\tprivate readonly builder: UpdateBuilder,\n\t\tprivate readonly primary: Input.PrimaryValue,\n\t) {\n\t}\n\n\tpublic async connect(\n\t\t{ targetEntity, relation, input }: Context & { input: Input.UniqueWhere },\n\t) {\n\t\tconst value = await this.mapper.getPrimaryValue(targetEntity, input)\n\t\tif (!value) {\n\t\t\treturn [new MutationEntryNotFoundError([], input)]\n\t\t}\n\t\tthis.builder.addFieldValue(relation.name, value)\n\t\treturn []\n\t}\n\n\tpublic async create(\n\t\t{ relation, targetEntity, input }: Context & { input: Input.CreateDataInput },\n\t) {\n\t\tconst insertResult = await this.mapper.insert(targetEntity, input)\n\t\tconst value = getInsertPrimary(insertResult)\n\t\tif (!value) {\n\t\t\treturn insertResult\n\t\t}\n\t\tthis.builder.addFieldValue(relation.name, value)\n\t\treturn []\n\t}\n\n\tpublic async connectOrCreate(\n\t\t{ input: { connect, create }, relation, targetEntity }: Context & { input: Input.ConnectOrCreateInput },\n\t) {\n\t\tconst value = await this.mapper.getPrimaryValue(targetEntity, connect)\n\t\tif (value) {\n\t\t\tthis.builder.addFieldValue(relation.name, value)\n\t\t} else {\n\t\t\tconst insertResult = await this.mapper.insert(targetEntity, create)\n\t\t\tconst primary = getInsertPrimary(insertResult)\n\t\t\tif (!primary) {\n\t\t\t\treturn insertResult\n\t\t\t}\n\n\t\t\tthis.builder.addFieldValue(relation.name, primary)\n\t\t}\n\t\treturn []\n\t}\n\n\tpublic async update(\n\t\t{ entity, relation, targetEntity, targetRelation, input }: Context & { input: Input.UpdateDataInput },\n\t) {\n\t\treturn async ({ primary }: { primary: Input.PrimaryValue }) => {\n\t\t\tconst inversePrimary = await this.mapper.selectField(\n\t\t\t\tentity,\n\t\t\t\t{ [entity.primary]: primary },\n\t\t\t\trelation.name,\n\t\t\t)\n\t\t\tif (!inversePrimary) {\n\t\t\t\treturn [new MutationNothingToDo([], NothingToDoReason.emptyRelation)]\n\t\t\t}\n\t\t\treturn await this.mapper.update(targetEntity, { [targetEntity.primary]: inversePrimary }, input)\n\t\t}\n\t}\n\n\tpublic async upsert(\n\t\t{ entity, relation, targetEntity, input: { create, update } }: Context & { input: UpdateInputProcessor.UpsertInput },\n\t) {\n\t\tconst inversePrimary = await this.mapper.selectField(entity, { [entity.primary]: this.primary }, relation.name)\n\t\tif (!inversePrimary) {\n\t\t\tconst insertResult = await this.mapper.insert(targetEntity, create)\n\t\t\tconst insertPrimary = getInsertPrimary(insertResult)\n\t\t\tif (insertPrimary) {\n\t\t\t\tthis.builder.addFieldValue(relation.name, insertPrimary)\n\t\t\t}\n\t\t\treturn insertResult\n\t\t}\n\n\t\treturn async () =>\n\t\t\tawait this.mapper.update(targetEntity, { [targetEntity.primary]: inversePrimary }, update)\n\t}\n\n\tpublic async disconnect(\n\t\t{ entity, targetEntity, relation, targetRelation }: Context & { input: undefined },\n\t) {\n\t\tif (!relation.nullable) {\n\t\t\treturn [new MutationConstraintViolationError([], ConstraintType.notNull)]\n\t\t}\n\t\tthis.builder.addFieldValue(relation.name, null)\n\t\treturn []\n\t}\n\n\tpublic async delete(\n\t\t{ entity, targetEntity, relation, targetRelation }: Context & { input: undefined },\n\t) {\n\t\tif (!relation.nullable && relation.joiningColumn.onDelete !== Model.OnDelete.cascade) {\n\t\t\treturn [new MutationConstraintViolationError([], ConstraintType.notNull)]\n\t\t}\n\t\treturn async ({ primary }: { primary: Input.PrimaryValue }) => {\n\t\t\tconst inversePrimary = await this.mapper.selectField(\n\t\t\t\tentity,\n\t\t\t\t{ [entity.primary]: primary },\n\t\t\t\trelation.name,\n\t\t\t)\n\t\t\treturn await this.mapper.delete(targetEntity, { [targetEntity.primary]: inversePrimary })\n\t\t}\n\t}\n}\n"],"names":["MutationEntryNotFoundError","getInsertPrimary","MutationNothingToDo","NothingToDoReason","MutationCon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