@contember/engine-content-api 2.0.0-alpha.16 → 2.0.0-alpha.18
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/src/inputProcessing/UpdateInputVisitor.cjs +3 -0
- package/dist/development/src/inputProcessing/UpdateInputVisitor.cjs.map +1 -1
- package/dist/development/src/inputProcessing/UpdateInputVisitor.js +3 -0
- package/dist/development/src/inputProcessing/UpdateInputVisitor.js.map +1 -1
- package/dist/development/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.cjs +2 -0
- package/dist/development/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.cjs.map +1 -1
- package/dist/development/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.js +2 -0
- package/dist/development/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.js.map +1 -1
- package/dist/production/src/inputProcessing/UpdateInputVisitor.cjs +3 -0
- package/dist/production/src/inputProcessing/UpdateInputVisitor.cjs.map +1 -1
- package/dist/production/src/inputProcessing/UpdateInputVisitor.js +3 -0
- package/dist/production/src/inputProcessing/UpdateInputVisitor.js.map +1 -1
- package/dist/production/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.cjs +2 -0
- package/dist/production/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.cjs.map +1 -1
- package/dist/production/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.js +2 -0
- package/dist/production/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/update/manyHasManyOwning/connectOrCreate.test.d.ts +2 -0
- package/dist/tests/cases/integration/graphQlRequests/update/manyHasManyOwning/connectOrCreate.test.d.ts.map +1 -0
- package/dist/tests/cases/integration/graphQlRequests/update/oneHasMany/connectOrCreate.test.d.ts +2 -0
- package/dist/tests/cases/integration/graphQlRequests/update/oneHasMany/connectOrCreate.test.d.ts.map +1 -0
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/dist/types/inputProcessing/UpdateInputVisitor.d.ts.map +1 -1
- package/dist/types/schema/mutations/UpdateEntityRelationInputFieldVisitor.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -10
- package/src/inputProcessing/UpdateInputVisitor.ts +3 -0
- package/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.ts +5 -0
- package/tests/cases/integration/graphQlRequests/update/manyHasManyOwning/connectOrCreate.test.ts +100 -0
- package/tests/cases/integration/graphQlRequests/update/oneHasMany/connectOrCreate.test.ts +90 -0
- package/tests/cases/integration/graphQlSchema/schema-acl-allowed.gql +1 -0
- package/tests/cases/integration/graphQlSchema/schema-acl-restricted-delete.gql +1 -0
- package/tests/cases/integration/graphQlSchema/schema-basic.gql +4 -0
- package/tests/cases/integration/graphQlSchema/schema-bug-66.gql +1 -0
- package/tests/cases/integration/graphQlSchema/schema-custom-primary.gql +4 -0
- package/tests/cases/integration/graphQlSchema/schema-has-many-reduction.gql +1 -0
- package/tests/cases/integration/graphQlSchema/schema-new-builder.gql +4 -0
|
@@ -106,6 +106,9 @@ class UpdateInputVisitor {
|
|
|
106
106
|
if (isIt.isIt(element, "create")) {
|
|
107
107
|
result = processor.create({ ...context, input: element.create, index: i, alias });
|
|
108
108
|
}
|
|
109
|
+
if (isIt.isIt(element, "connectOrCreate")) {
|
|
110
|
+
result = processor.connectOrCreate({ ...context, input: element.connectOrCreate, index: i, alias });
|
|
111
|
+
}
|
|
109
112
|
if (isIt.isIt(element, "delete")) {
|
|
110
113
|
result = processor.delete({ ...context, input: element.delete, index: i, alias });
|
|
111
114
|
}
|
|
@@ -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.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;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,KAA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AAChE,iBAAS,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,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;;"}
|
|
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}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A,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,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;;"}
|
|
@@ -104,6 +104,9 @@ class UpdateInputVisitor {
|
|
|
104
104
|
if (isIt(element, "create")) {
|
|
105
105
|
result = processor.create({ ...context, input: element.create, index: i, alias });
|
|
106
106
|
}
|
|
107
|
+
if (isIt(element, "connectOrCreate")) {
|
|
108
|
+
result = processor.connectOrCreate({ ...context, input: element.connectOrCreate, index: i, alias });
|
|
109
|
+
}
|
|
107
110
|
if (isIt(element, "delete")) {
|
|
108
111
|
result = processor.delete({ ...context, input: element.delete, index: i, alias });
|
|
109
112
|
}
|
|
@@ -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.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,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O,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 | 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,E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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;"}
|
|
@@ -84,11 +84,13 @@ class UpdateEntityRelationInputFieldVisitor {
|
|
|
84
84
|
})
|
|
85
85
|
})
|
|
86
86
|
} : void 0;
|
|
87
|
+
const connectOrCreateInput = createInput && whereInputType ? { type: this.connectOrCreateRelationInputProvider.getInput(entity.name, relation.name) } : void 0;
|
|
87
88
|
const fields = {
|
|
88
89
|
[schema.Input.UpdateRelationOperation.create]: createInput,
|
|
89
90
|
[schema.Input.UpdateRelationOperation.update]: updateSpecifiedInput,
|
|
90
91
|
[schema.Input.UpdateRelationOperation.upsert]: upsertInput,
|
|
91
92
|
[schema.Input.UpdateRelationOperation.connect]: whereInput,
|
|
93
|
+
[schema.Input.UpdateRelationOperation.connectOrCreate]: connectOrCreateInput,
|
|
92
94
|
[schema.Input.UpdateRelationOperation.disconnect]: whereInput,
|
|
93
95
|
[schema.Input.UpdateRelationOperation.delete]: whereInput
|
|
94
96
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UpdateEntityRelationInputFieldVisitor.cjs","sources":["../../../../../../packages/engine-content-api/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.ts"],"sourcesContent":["import {\n\tGraphQLBoolean,\n\tGraphQLInputFieldConfig,\n\tGraphQLInputFieldConfigMap,\n\tGraphQLInputObjectType, GraphQLNonNull,\n\tGraphQLString,\n} from 'graphql'\nimport { Acl, Input, Model } from '@contember/schema'\nimport { GqlTypeName } from '../utils'\nimport { WhereTypeProvider } from '../WhereTypeProvider'\nimport { Accessor, filterObject } from '../../utils'\nimport { EntityInputProvider, EntityInputType } from './EntityInputProvider'\nimport { acceptFieldVisitor } from '@contember/schema-utils'\nimport { UpdateEntityRelationAllowedOperationsVisitor } from './UpdateEntityRelationAllowedOperationsVisitor'\nimport { Authorizator } from '../../acl'\nimport { ImplementationException } from '../../exception'\nimport { ConnectOrCreateRelationInputProvider } from './ConnectOrCreateRelationInputProvider'\n\nexport class UpdateEntityRelationInputFieldVisitor implements Model.ColumnVisitor<never>,\n\tModel.RelationByGenericTypeVisitor<GraphQLInputObjectType | undefined> {\n\n\tconstructor(\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly authorizator: Authorizator,\n\t\tprivate readonly whereTypeBuilder: WhereTypeProvider,\n\t\tprivate readonly updateEntityInputProviderAccessor: Accessor<EntityInputProvider<EntityInputType.update>>,\n\t\tprivate readonly createEntityInputProvider: EntityInputProvider<EntityInputType.create>,\n\t\tprivate readonly updateEntityRelationAllowedOperationsVisitor: UpdateEntityRelationAllowedOperationsVisitor,\n\t\tprivate readonly connectOrCreateRelationInputProvider: ConnectOrCreateRelationInputProvider,\n\t) {\n\t}\n\n\tpublic visitColumn(): never {\n\t\tthrow new Error('UpdateEntityRelationInputFieldVisitor: Not applicable for a column')\n\t}\n\n\tpublic visitHasOne({ targetRelation, targetEntity, relation, entity }: Model.AnyHasOneRelationContext) {\n\t\tconst withoutRelation = targetRelation ? targetRelation.name : undefined\n\n\t\tconst whereInputType = this.createUniqueWhereInput(targetEntity)\n\t\tconst whereInput = whereInputType ? { type: whereInputType } : undefined\n\n\t\tconst createInputType = this.createEntityInputProvider.getInput(targetEntity.name, withoutRelation)\n\t\tconst createInput = createInputType ? { type: createInputType } : undefined\n\n\t\tconst updateInputType = this.updateEntityInputProviderAccessor.get().getInput(targetEntity.name, withoutRelation)\n\t\tconst updateInput = updateInputType ? { type: updateInputType } : undefined\n\n\t\tconst upsertInput = updateInputType && createInputType\n\t\t\t? {\n\t\t\t\ttype: new GraphQLInputObjectType({\n\t\t\t\t\tname: GqlTypeName`${entity.name}Upsert${relation.name}RelationInput`,\n\t\t\t\t\tfields: () => ({\n\t\t\t\t\t\tupdate: { type: new GraphQLNonNull(updateInputType) },\n\t\t\t\t\t\tcreate: { type: new GraphQLNonNull(createInputType) },\n\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t\t}\n\t\t\t: undefined\n\n\t\tconst booleanInput = {\n\t\t\ttype: GraphQLBoolean,\n\t\t}\n\n\t\tconst connectOrCreateInput = createInput && whereInputType\n\t\t\t? { type: this.connectOrCreateRelationInputProvider.getInput(entity.name, relation.name) }\n\t\t\t: undefined\n\n\t\tconst fields = {\n\t\t\t[Input.UpdateRelationOperation.connect]: whereInput,\n\t\t\t[Input.UpdateRelationOperation.create]: createInput,\n\t\t\t[Input.UpdateRelationOperation.connectOrCreate]: connectOrCreateInput,\n\t\t\t[Input.UpdateRelationOperation.update]: updateInput,\n\t\t\t[Input.UpdateRelationOperation.upsert]: upsertInput,\n\t\t\t[Input.UpdateRelationOperation.disconnect]: booleanInput,\n\t\t\t[Input.UpdateRelationOperation.delete]: booleanInput,\n\t\t}\n\n\t\tconst filteredFields = this.filterAllowedOperations(entity, relation, fields)\n\t\tif (Object.keys(filteredFields).length === 0) {\n\t\t\treturn undefined\n\t\t}\n\n\t\treturn new GraphQLInputObjectType({\n\t\t\tname: GqlTypeName`${entity.name}Update${relation.name}EntityRelationInput`,\n\t\t\tfields: () => filteredFields,\n\t\t})\n\t}\n\n\tpublic visitHasMany({ entity, relation, targetEntity, targetRelation }: Model.AnyHasManyRelationContext) {\n\t\tconst withoutRelation = targetRelation ? targetRelation.name : undefined\n\n\t\tconst whereInputType = this.createUniqueWhereInput(targetEntity)\n\t\tconst whereInput = whereInputType ? { type: whereInputType } : undefined\n\n\t\tconst createInputType = this.createEntityInputProvider.getInput(targetEntity.name, withoutRelation)\n\t\tconst createInput = createInputType ? { type: createInputType } : undefined\n\n\t\tconst updateInputType = this.updateEntityInputProviderAccessor.get().getInput(targetEntity.name, withoutRelation)\n\n\t\tconst updateSpecifiedInput = updateInputType && whereInputType\n\t\t\t? {\n\t\t\t\ttype: new GraphQLInputObjectType({\n\t\t\t\t\tname: GqlTypeName`${entity.name}Update${relation.name}RelationInput`,\n\t\t\t\t\tfields: () => ({\n\t\t\t\t\t\tby: { type: new GraphQLNonNull(whereInputType) },\n\t\t\t\t\t\tdata: { type: new GraphQLNonNull(updateInputType) },\n\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t\t}\n\t\t\t: undefined\n\n\t\tconst upsertInput = updateInputType && createInputType && whereInputType\n\t\t\t? {\n\t\t\t\ttype: new GraphQLInputObjectType({\n\t\t\t\t\tname: GqlTypeName`${entity.name}Upsert${relation.name}RelationInput`,\n\t\t\t\t\tfields: () => ({\n\t\t\t\t\t\tby: { type: new GraphQLNonNull(whereInputType) },\n\t\t\t\t\t\tupdate: { type: new GraphQLNonNull(updateInputType) },\n\t\t\t\t\t\tcreate: { type: new GraphQLNonNull(createInputType) },\n\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t\t}\n\t\t\t: undefined\n\n\t\tconst fields = {\n\t\t\t[Input.UpdateRelationOperation.create]: createInput,\n\t\t\t[Input.UpdateRelationOperation.update]: updateSpecifiedInput,\n\t\t\t[Input.UpdateRelationOperation.upsert]: upsertInput,\n\t\t\t[Input.UpdateRelationOperation.connect]: whereInput,\n\t\t\t[Input.UpdateRelationOperation.disconnect]: whereInput,\n\t\t\t[Input.UpdateRelationOperation.delete]: whereInput,\n\t\t}\n\n\t\tconst filteredFields = this.filterAllowedOperations(entity, relation, fields)\n\t\tif (Object.keys(filteredFields).length === 0) {\n\t\t\treturn undefined\n\t\t}\n\n\t\treturn new GraphQLInputObjectType({\n\t\t\tname: GqlTypeName`${entity.name}Update${relation.name}EntityRelationInput`,\n\t\t\tfields: () => ({\n\t\t\t\t...filteredFields,\n\t\t\t\talias: { type: GraphQLString },\n\t\t\t}),\n\t\t})\n\t}\n\n\tprivate filterAllowedOperations(\n\t\tentity: Model.Entity,\n\t\trelation: Model.Relation,\n\t\tgraphQlFields: { [key: string]: GraphQLInputFieldConfig | undefined },\n\t): GraphQLInputFieldConfigMap {\n\t\tconst allowedOperations = acceptFieldVisitor(\n\t\t\tthis.schema,\n\t\t\tentity,\n\t\t\trelation.name,\n\t\t\tthis.updateEntityRelationAllowedOperationsVisitor,\n\t\t)\n\t\treturn filterObject(\n\t\t\tgraphQlFields,\n\t\t\t(key, value): value is GraphQLInputFieldConfig =>\n\t\t\t\tallowedOperations.includes(key as Input.UpdateRelationOperation) && value !== undefined,\n\t\t)\n\t}\n\n\tprivate createUniqueWhereInput(targetEntity: Model.Entity): GraphQLInputObjectType | undefined {\n\t\tif (this.authorizator.getEntityPermission(Acl.Operation.read, targetEntity.name) === 'no') {\n\t\t\treturn undefined\n\t\t}\n\t\tconst uniqueWhere = this.whereTypeBuilder.getEntityUniqueWhereType(targetEntity.name)\n\t\tif (!uniqueWhere) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\treturn uniqueWhere\n\t}\n}\n"],"names":["schema","GraphQLInputObjectType","GqlTypeName","GraphQLNonNull","GraphQLBoolean","Input","GraphQLString","acceptFieldVisitor","filterObject","Acl","ImplementationException"],"mappings":";;;;;;;;AAkBO,MAAM,sCAC2D;AAAA,EAEvE,YACkBA,SACA,cACA,kBACA,mCACA,2BACA,8CACA,sCAChB;AAPgB,SAAA,SAAAA;AACA,SAAA,eAAA;AACA,SAAA,mBAAA;AACA,SAAA,oCAAA;AACA,SAAA,4BAAA;AACA,SAAA,+CAAA;AACA,SAAA,uCAAA;AAAA,EAElB;AAAA,EAEO,cAAqB;AACrB,UAAA,IAAI,MAAM,oEAAoE;AAAA,EACrF;AAAA,EAEO,YAAY,EAAE,gBAAgB,cAAc,UAAU,UAA0C;AAChG,UAAA,kBAAkB,iBAAiB,eAAe,OAAO;AAEzD,UAAA,iBAAi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;AACjB,YAAM,IAAIC,UAAwB,wBAAA;AAAA,IACnC;AACO,WAAA;AAAA,EACR;AACD;;"}
|
|
1
|
+
{"version":3,"file":"UpdateEntityRelationInputFieldVisitor.cjs","sources":["../../../../../../packages/engine-content-api/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.ts"],"sourcesContent":["import {\n\tGraphQLBoolean,\n\tGraphQLInputFieldConfig,\n\tGraphQLInputFieldConfigMap,\n\tGraphQLInputObjectType, GraphQLNonNull,\n\tGraphQLString,\n} from 'graphql'\nimport { Acl, Input, Model } from '@contember/schema'\nimport { GqlTypeName } from '../utils'\nimport { WhereTypeProvider } from '../WhereTypeProvider'\nimport { Accessor, filterObject } from '../../utils'\nimport { EntityInputProvider, EntityInputType } from './EntityInputProvider'\nimport { acceptFieldVisitor } from '@contember/schema-utils'\nimport { UpdateEntityRelationAllowedOperationsVisitor } from './UpdateEntityRelationAllowedOperationsVisitor'\nimport { Authorizator } from '../../acl'\nimport { ImplementationException } from '../../exception'\nimport { ConnectOrCreateRelationInputProvider } from './ConnectOrCreateRelationInputProvider'\n\nexport class UpdateEntityRelationInputFieldVisitor implements Model.ColumnVisitor<never>,\n\tModel.RelationByGenericTypeVisitor<GraphQLInputObjectType | undefined> {\n\n\tconstructor(\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly authorizator: Authorizator,\n\t\tprivate readonly whereTypeBuilder: WhereTypeProvider,\n\t\tprivate readonly updateEntityInputProviderAccessor: Accessor<EntityInputProvider<EntityInputType.update>>,\n\t\tprivate readonly createEntityInputProvider: EntityInputProvider<EntityInputType.create>,\n\t\tprivate readonly updateEntityRelationAllowedOperationsVisitor: UpdateEntityRelationAllowedOperationsVisitor,\n\t\tprivate readonly connectOrCreateRelationInputProvider: ConnectOrCreateRelationInputProvider,\n\t) {\n\t}\n\n\tpublic visitColumn(): never {\n\t\tthrow new Error('UpdateEntityRelationInputFieldVisitor: Not applicable for a column')\n\t}\n\n\tpublic visitHasOne({ targetRelation, targetEntity, relation, entity }: Model.AnyHasOneRelationContext) {\n\t\tconst withoutRelation = targetRelation ? targetRelation.name : undefined\n\n\t\tconst whereInputType = this.createUniqueWhereInput(targetEntity)\n\t\tconst whereInput = whereInputType ? { type: whereInputType } : undefined\n\n\t\tconst createInputType = this.createEntityInputProvider.getInput(targetEntity.name, withoutRelation)\n\t\tconst createInput = createInputType ? { type: createInputType } : undefined\n\n\t\tconst updateInputType = this.updateEntityInputProviderAccessor.get().getInput(targetEntity.name, withoutRelation)\n\t\tconst updateInput = updateInputType ? { type: updateInputType } : undefined\n\n\t\tconst upsertInput = updateInputType && createInputType\n\t\t\t? {\n\t\t\t\ttype: new GraphQLInputObjectType({\n\t\t\t\t\tname: GqlTypeName`${entity.name}Upsert${relation.name}RelationInput`,\n\t\t\t\t\tfields: () => ({\n\t\t\t\t\t\tupdate: { type: new GraphQLNonNull(updateInputType) },\n\t\t\t\t\t\tcreate: { type: new GraphQLNonNull(createInputType) },\n\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t\t}\n\t\t\t: undefined\n\n\t\tconst booleanInput = {\n\t\t\ttype: GraphQLBoolean,\n\t\t}\n\n\t\tconst connectOrCreateInput = createInput && whereInputType\n\t\t\t? { type: this.connectOrCreateRelationInputProvider.getInput(entity.name, relation.name) }\n\t\t\t: undefined\n\n\t\tconst fields = {\n\t\t\t[Input.UpdateRelationOperation.connect]: whereInput,\n\t\t\t[Input.UpdateRelationOperation.create]: createInput,\n\t\t\t[Input.UpdateRelationOperation.connectOrCreate]: connectOrCreateInput,\n\t\t\t[Input.UpdateRelationOperation.update]: updateInput,\n\t\t\t[Input.UpdateRelationOperation.upsert]: upsertInput,\n\t\t\t[Input.UpdateRelationOperation.disconnect]: booleanInput,\n\t\t\t[Input.UpdateRelationOperation.delete]: booleanInput,\n\t\t}\n\n\t\tconst filteredFields = this.filterAllowedOperations(entity, relation, fields)\n\t\tif (Object.keys(filteredFields).length === 0) {\n\t\t\treturn undefined\n\t\t}\n\n\t\treturn new GraphQLInputObjectType({\n\t\t\tname: GqlTypeName`${entity.name}Update${relation.name}EntityRelationInput`,\n\t\t\tfields: () => filteredFields,\n\t\t})\n\t}\n\n\tpublic visitHasMany({ entity, relation, targetEntity, targetRelation }: Model.AnyHasManyRelationContext) {\n\t\tconst withoutRelation = targetRelation ? targetRelation.name : undefined\n\n\t\tconst whereInputType = this.createUniqueWhereInput(targetEntity)\n\t\tconst whereInput = whereInputType ? { type: whereInputType } : undefined\n\n\t\tconst createInputType = this.createEntityInputProvider.getInput(targetEntity.name, withoutRelation)\n\t\tconst createInput = createInputType ? { type: createInputType } : undefined\n\n\t\tconst updateInputType = this.updateEntityInputProviderAccessor.get().getInput(targetEntity.name, withoutRelation)\n\n\t\tconst updateSpecifiedInput = updateInputType && whereInputType\n\t\t\t? {\n\t\t\t\ttype: new GraphQLInputObjectType({\n\t\t\t\t\tname: GqlTypeName`${entity.name}Update${relation.name}RelationInput`,\n\t\t\t\t\tfields: () => ({\n\t\t\t\t\t\tby: { type: new GraphQLNonNull(whereInputType) },\n\t\t\t\t\t\tdata: { type: new GraphQLNonNull(updateInputType) },\n\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t\t}\n\t\t\t: undefined\n\n\t\tconst upsertInput = updateInputType && createInputType && whereInputType\n\t\t\t? {\n\t\t\t\ttype: new GraphQLInputObjectType({\n\t\t\t\t\tname: GqlTypeName`${entity.name}Upsert${relation.name}RelationInput`,\n\t\t\t\t\tfields: () => ({\n\t\t\t\t\t\tby: { type: new GraphQLNonNull(whereInputType) },\n\t\t\t\t\t\tupdate: { type: new GraphQLNonNull(updateInputType) },\n\t\t\t\t\t\tcreate: { type: new GraphQLNonNull(createInputType) },\n\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t\t}\n\t\t\t: undefined\n\n\t\tconst connectOrCreateInput = createInput && whereInputType\n\t\t\t? { type: this.connectOrCreateRelationInputProvider.getInput(entity.name, relation.name) }\n\t\t\t: undefined\n\n\t\tconst fields = {\n\t\t\t[Input.UpdateRelationOperation.create]: createInput,\n\t\t\t[Input.UpdateRelationOperation.update]: updateSpecifiedInput,\n\t\t\t[Input.UpdateRelationOperation.upsert]: upsertInput,\n\t\t\t[Input.UpdateRelationOperation.connect]: whereInput,\n\t\t\t[Input.UpdateRelationOperation.connectOrCreate]: connectOrCreateInput,\n\t\t\t[Input.UpdateRelationOperation.disconnect]: whereInput,\n\t\t\t[Input.UpdateRelationOperation.delete]: whereInput,\n\t\t}\n\n\t\tconst filteredFields = this.filterAllowedOperations(entity, relation, fields)\n\t\tif (Object.keys(filteredFields).length === 0) {\n\t\t\treturn undefined\n\t\t}\n\n\t\treturn new GraphQLInputObjectType({\n\t\t\tname: GqlTypeName`${entity.name}Update${relation.name}EntityRelationInput`,\n\t\t\tfields: () => ({\n\t\t\t\t...filteredFields,\n\t\t\t\talias: { type: GraphQLString },\n\t\t\t}),\n\t\t})\n\t}\n\n\tprivate filterAllowedOperations(\n\t\tentity: Model.Entity,\n\t\trelation: Model.Relation,\n\t\tgraphQlFields: { [key: string]: GraphQLInputFieldConfig | undefined },\n\t): GraphQLInputFieldConfigMap {\n\t\tconst allowedOperations = acceptFieldVisitor(\n\t\t\tthis.schema,\n\t\t\tentity,\n\t\t\trelation.name,\n\t\t\tthis.updateEntityRelationAllowedOperationsVisitor,\n\t\t)\n\t\treturn filterObject(\n\t\t\tgraphQlFields,\n\t\t\t(key, value): value is GraphQLInputFieldConfig =>\n\t\t\t\tallowedOperations.includes(key as Input.UpdateRelationOperation) && value !== undefined,\n\t\t)\n\t}\n\n\tprivate createUniqueWhereInput(targetEntity: Model.Entity): GraphQLInputObjectType | undefined {\n\t\tif (this.authorizator.getEntityPermission(Acl.Operation.read, targetEntity.name) === 'no') {\n\t\t\treturn undefined\n\t\t}\n\t\tconst uniqueWhere = this.whereTypeBuilder.getEntityUniqueWhereType(targetEntity.name)\n\t\tif (!uniqueWhere) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\treturn uniqueWhere\n\t}\n}\n"],"names":["schema","GraphQLInputObjectType","GqlTypeName","GraphQLNonNull","GraphQLBoolean","Input","GraphQLString","acceptFieldVisitor","filterObject","Acl","ImplementationException"],"mappings":";;;;;;;;AAkBO,MAAM,sCAC2D;AAAA,EAEvE,YACkBA,SACA,cACA,kBACA,mCACA,2BACA,8CACA,sCAChB;AAPgB,SAAA,SAAAA;AACA,SAAA,eAAA;AACA,SAAA,mBAAA;AACA,SAAA,oCAAA;AACA,SAAA,4BAAA;AACA,SAAA,+CAAA;AACA,SAAA,uCAAA;AAAA,EAElB;AAAA,EAEO,cAAqB;AACrB,UAAA,IAAI,MAAM,oEAAoE;AAAA,EACrF;AAAA,EAEO,YAAY,EAAE,gBAAgB,cAAc,UAAU,UAA0C;AAChG,UAAA,kBAAkB,iBAAiB,eAAe,OAAO;AAEzD,UAAA,iBAAiB,KAAK,uBAAuB,YAAY;AAC/D,UAAM,aAAa,iBAAiB,EAAE,MAAM,mBAAmB;AAE/D,UAAM,kBAAkB,KAAK,0BAA0B,SAAS,aAAa,MAAM,eAAe;AAClG,UAAM,cAAc,kBAAkB,EAAE,MAAM,oBAAoB;AAE5D,UAAA,kBAAkB,KAAK,kCAAkC,IAAA,EAAM,SAAS,aAAa,MAAM,eAAe;AAChH,UAAM,cAAc,kBAAkB,EAAG,MAAM,oBAAoB;AAE7D,UAAA,cAAc,mBAAmB,kBACpC;AAAA,MACD,MAAM,IAAIC,QAAAA,uBAAuB;AAAA,QAChC,MAAMC,MAAAA,cAAc,OAAO,IAAI,SAAS,SAAS,IAAI;AAAA,QACrD,QAAQ,OAAO;AAAA,UACd,QAAQ,EAAE,MAAM,IAAIC,QAAA,eAAe,eAAe,EAAE;AAAA,UACpD,QAAQ,EAAE,MAAM,IAAIA,QAAA,eAAe,eAAe,EAAE;AAAA,QAAA;AAAA,MACrD,CACA;AAAA,IAEA,IAAA;AAEH,UAAM,eAAe;AAAA,MACpB,MAAMC,QAAA;AAAA,IAAA;AAGP,UAAM,uBAAuB,eAAe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,IAAIJ,QAAAA,uBAAuB;AAAA,MACjC,MAAMC,MAAAA,cAAc,OAAO,IAAI,SAAS,SAAS,IAAI;AAAA,MACrD,QAAQ,OAAO;AAAA,QACd,GAAG;AAAA,QACH,OAAO,EAAE,MAAMI,sBAAc;AAAA,MAAA;AAAA,IAC9B,CACA;AAAA,EACF;AAAA,EAEQ,wBACP,QACA,UACA,eAC6B;AAC7B,UAAM,oBAAoBC,YAAA;AAAA,MACzB,KAAK;AAAA,MACL;AAAA,MACA,SAAS;AAAA,MACT,KAAK;AAAA,IAAA;AAEC,WAAAC,OAAA;AAAA,MACN;AAAA,MACA,CAAC,KAAK,UACL,kBAAkB,SAAS,GAAoC,KAAK,UAAU;AAAA,IAAA;AAAA,EAEjF;AAAA,EAEQ,uBAAuB,cAAgE;AAC1F,QAAA,KAAK,aAAa,oBAAoBC,OAAA,IAAI,UAAU,MAAM,aAAa,IAAI,MAAM,MAAM;AACnF,aAAA;AAAA,IACR;AACA,UAAM,cAAc,KAAK,iBAAiB,yBAAyB,aAAa,IAAI;AACpF,QAAI,CAAC,aAAa;AACjB,YAAM,IAAIC,UAAwB,wBAAA;AAAA,IACnC;AACO,WAAA;AAAA,EACR;AACD;;"}
|
|
@@ -82,11 +82,13 @@ class UpdateEntityRelationInputFieldVisitor {
|
|
|
82
82
|
})
|
|
83
83
|
})
|
|
84
84
|
} : void 0;
|
|
85
|
+
const connectOrCreateInput = createInput && whereInputType ? { type: this.connectOrCreateRelationInputProvider.getInput(entity.name, relation.name) } : void 0;
|
|
85
86
|
const fields = {
|
|
86
87
|
[Input.UpdateRelationOperation.create]: createInput,
|
|
87
88
|
[Input.UpdateRelationOperation.update]: updateSpecifiedInput,
|
|
88
89
|
[Input.UpdateRelationOperation.upsert]: upsertInput,
|
|
89
90
|
[Input.UpdateRelationOperation.connect]: whereInput,
|
|
91
|
+
[Input.UpdateRelationOperation.connectOrCreate]: connectOrCreateInput,
|
|
90
92
|
[Input.UpdateRelationOperation.disconnect]: whereInput,
|
|
91
93
|
[Input.UpdateRelationOperation.delete]: whereInput
|
|
92
94
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UpdateEntityRelationInputFieldVisitor.js","sources":["../../../../../../packages/engine-content-api/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.ts"],"sourcesContent":["import {\n\tGraphQLBoolean,\n\tGraphQLInputFieldConfig,\n\tGraphQLInputFieldConfigMap,\n\tGraphQLInputObjectType, GraphQLNonNull,\n\tGraphQLString,\n} from 'graphql'\nimport { Acl, Input, Model } from '@contember/schema'\nimport { GqlTypeName } from '../utils'\nimport { WhereTypeProvider } from '../WhereTypeProvider'\nimport { Accessor, filterObject } from '../../utils'\nimport { EntityInputProvider, EntityInputType } from './EntityInputProvider'\nimport { acceptFieldVisitor } from '@contember/schema-utils'\nimport { UpdateEntityRelationAllowedOperationsVisitor } from './UpdateEntityRelationAllowedOperationsVisitor'\nimport { Authorizator } from '../../acl'\nimport { ImplementationException } from '../../exception'\nimport { ConnectOrCreateRelationInputProvider } from './ConnectOrCreateRelationInputProvider'\n\nexport class UpdateEntityRelationInputFieldVisitor implements Model.ColumnVisitor<never>,\n\tModel.RelationByGenericTypeVisitor<GraphQLInputObjectType | undefined> {\n\n\tconstructor(\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly authorizator: Authorizator,\n\t\tprivate readonly whereTypeBuilder: WhereTypeProvider,\n\t\tprivate readonly updateEntityInputProviderAccessor: Accessor<EntityInputProvider<EntityInputType.update>>,\n\t\tprivate readonly createEntityInputProvider: EntityInputProvider<EntityInputType.create>,\n\t\tprivate readonly updateEntityRelationAllowedOperationsVisitor: UpdateEntityRelationAllowedOperationsVisitor,\n\t\tprivate readonly connectOrCreateRelationInputProvider: ConnectOrCreateRelationInputProvider,\n\t) {\n\t}\n\n\tpublic visitColumn(): never {\n\t\tthrow new Error('UpdateEntityRelationInputFieldVisitor: Not applicable for a column')\n\t}\n\n\tpublic visitHasOne({ targetRelation, targetEntity, relation, entity }: Model.AnyHasOneRelationContext) {\n\t\tconst withoutRelation = targetRelation ? targetRelation.name : undefined\n\n\t\tconst whereInputType = this.createUniqueWhereInput(targetEntity)\n\t\tconst whereInput = whereInputType ? { type: whereInputType } : undefined\n\n\t\tconst createInputType = this.createEntityInputProvider.getInput(targetEntity.name, withoutRelation)\n\t\tconst createInput = createInputType ? { type: createInputType } : undefined\n\n\t\tconst updateInputType = this.updateEntityInputProviderAccessor.get().getInput(targetEntity.name, withoutRelation)\n\t\tconst updateInput = updateInputType ? { type: updateInputType } : undefined\n\n\t\tconst upsertInput = updateInputType && createInputType\n\t\t\t? {\n\t\t\t\ttype: new GraphQLInputObjectType({\n\t\t\t\t\tname: GqlTypeName`${entity.name}Upsert${relation.name}RelationInput`,\n\t\t\t\t\tfields: () => ({\n\t\t\t\t\t\tupdate: { type: new GraphQLNonNull(updateInputType) },\n\t\t\t\t\t\tcreate: { type: new GraphQLNonNull(createInputType) },\n\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t\t}\n\t\t\t: undefined\n\n\t\tconst booleanInput = {\n\t\t\ttype: GraphQLBoolean,\n\t\t}\n\n\t\tconst connectOrCreateInput = createInput && whereInputType\n\t\t\t? { type: this.connectOrCreateRelationInputProvider.getInput(entity.name, relation.name) }\n\t\t\t: undefined\n\n\t\tconst fields = {\n\t\t\t[Input.UpdateRelationOperation.connect]: whereInput,\n\t\t\t[Input.UpdateRelationOperation.create]: createInput,\n\t\t\t[Input.UpdateRelationOperation.connectOrCreate]: connectOrCreateInput,\n\t\t\t[Input.UpdateRelationOperation.update]: updateInput,\n\t\t\t[Input.UpdateRelationOperation.upsert]: upsertInput,\n\t\t\t[Input.UpdateRelationOperation.disconnect]: booleanInput,\n\t\t\t[Input.UpdateRelationOperation.delete]: booleanInput,\n\t\t}\n\n\t\tconst filteredFields = this.filterAllowedOperations(entity, relation, fields)\n\t\tif (Object.keys(filteredFields).length === 0) {\n\t\t\treturn undefined\n\t\t}\n\n\t\treturn new GraphQLInputObjectType({\n\t\t\tname: GqlTypeName`${entity.name}Update${relation.name}EntityRelationInput`,\n\t\t\tfields: () => filteredFields,\n\t\t})\n\t}\n\n\tpublic visitHasMany({ entity, relation, targetEntity, targetRelation }: Model.AnyHasManyRelationContext) {\n\t\tconst withoutRelation = targetRelation ? targetRelation.name : undefined\n\n\t\tconst whereInputType = this.createUniqueWhereInput(targetEntity)\n\t\tconst whereInput = whereInputType ? { type: whereInputType } : undefined\n\n\t\tconst createInputType = this.createEntityInputProvider.getInput(targetEntity.name, withoutRelation)\n\t\tconst createInput = createInputType ? { type: createInputType } : undefined\n\n\t\tconst updateInputType = this.updateEntityInputProviderAccessor.get().getInput(targetEntity.name, withoutRelation)\n\n\t\tconst updateSpecifiedInput = updateInputType && whereInputType\n\t\t\t? {\n\t\t\t\ttype: new GraphQLInputObjectType({\n\t\t\t\t\tname: GqlTypeName`${entity.name}Update${relation.name}RelationInput`,\n\t\t\t\t\tfields: () => ({\n\t\t\t\t\t\tby: { type: new GraphQLNonNull(whereInputType) },\n\t\t\t\t\t\tdata: { type: new GraphQLNonNull(updateInputType) },\n\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t\t}\n\t\t\t: undefined\n\n\t\tconst upsertInput = updateInputType && createInputType && whereInputType\n\t\t\t? {\n\t\t\t\ttype: new GraphQLInputObjectType({\n\t\t\t\t\tname: GqlTypeName`${entity.name}Upsert${relation.name}RelationInput`,\n\t\t\t\t\tfields: () => ({\n\t\t\t\t\t\tby: { type: new GraphQLNonNull(whereInputType) },\n\t\t\t\t\t\tupdate: { type: new GraphQLNonNull(updateInputType) },\n\t\t\t\t\t\tcreate: { type: new GraphQLNonNull(createInputType) },\n\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t\t}\n\t\t\t: undefined\n\n\t\tconst fields = {\n\t\t\t[Input.UpdateRelationOperation.create]: createInput,\n\t\t\t[Input.UpdateRelationOperation.update]: updateSpecifiedInput,\n\t\t\t[Input.UpdateRelationOperation.upsert]: upsertInput,\n\t\t\t[Input.UpdateRelationOperation.connect]: whereInput,\n\t\t\t[Input.UpdateRelationOperation.disconnect]: whereInput,\n\t\t\t[Input.UpdateRelationOperation.delete]: whereInput,\n\t\t}\n\n\t\tconst filteredFields = this.filterAllowedOperations(entity, relation, fields)\n\t\tif (Object.keys(filteredFields).length === 0) {\n\t\t\treturn undefined\n\t\t}\n\n\t\treturn new GraphQLInputObjectType({\n\t\t\tname: GqlTypeName`${entity.name}Update${relation.name}EntityRelationInput`,\n\t\t\tfields: () => ({\n\t\t\t\t...filteredFields,\n\t\t\t\talias: { type: GraphQLString },\n\t\t\t}),\n\t\t})\n\t}\n\n\tprivate filterAllowedOperations(\n\t\tentity: Model.Entity,\n\t\trelation: Model.Relation,\n\t\tgraphQlFields: { [key: string]: GraphQLInputFieldConfig | undefined },\n\t): GraphQLInputFieldConfigMap {\n\t\tconst allowedOperations = acceptFieldVisitor(\n\t\t\tthis.schema,\n\t\t\tentity,\n\t\t\trelation.name,\n\t\t\tthis.updateEntityRelationAllowedOperationsVisitor,\n\t\t)\n\t\treturn filterObject(\n\t\t\tgraphQlFields,\n\t\t\t(key, value): value is GraphQLInputFieldConfig =>\n\t\t\t\tallowedOperations.includes(key as Input.UpdateRelationOperation) && value !== undefined,\n\t\t)\n\t}\n\n\tprivate createUniqueWhereInput(targetEntity: Model.Entity): GraphQLInputObjectType | undefined {\n\t\tif (this.authorizator.getEntityPermission(Acl.Operation.read, targetEntity.name) === 'no') {\n\t\t\treturn undefined\n\t\t}\n\t\tconst uniqueWhere = this.whereTypeBuilder.getEntityUniqueWhereType(targetEntity.name)\n\t\tif (!uniqueWhere) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\treturn uniqueWhere\n\t}\n}\n"],"names":[],"mappings":";;;;;;AAkBO,MAAM,sCAC2D;AAAA,EAEvE,YACkB,QACA,cACA,kBACA,mCACA,2BACA,8CACA,sCAChB;AAPgB,SAAA,SAAA;AACA,SAAA,eAAA;AACA,SAAA,m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pF,QAAI,CAAC,aAAa;AACjB,YAAM,IAAI,wBAAwB;AAAA,IACnC;AACO,WAAA;AAAA,EACR;AACD;"}
|
|
1
|
+
{"version":3,"file":"UpdateEntityRelationInputFieldVisitor.js","sources":["../../../../../../packages/engine-content-api/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.ts"],"sourcesContent":["import {\n\tGraphQLBoolean,\n\tGraphQLInputFieldConfig,\n\tGraphQLInputFieldConfigMap,\n\tGraphQLInputObjectType, GraphQLNonNull,\n\tGraphQLString,\n} from 'graphql'\nimport { Acl, Input, Model } from '@contember/schema'\nimport { GqlTypeName } from '../utils'\nimport { WhereTypeProvider } from '../WhereTypeProvider'\nimport { Accessor, filterObject } from '../../utils'\nimport { EntityInputProvider, EntityInputType } from './EntityInputProvider'\nimport { acceptFieldVisitor } from '@contember/schema-utils'\nimport { UpdateEntityRelationAllowedOperationsVisitor } from './UpdateEntityRelationAllowedOperationsVisitor'\nimport { Authorizator } from '../../acl'\nimport { ImplementationException } from '../../exception'\nimport { ConnectOrCreateRelationInputProvider } from './ConnectOrCreateRelationInputProvider'\n\nexport class UpdateEntityRelationInputFieldVisitor implements Model.ColumnVisitor<never>,\n\tModel.RelationByGenericTypeVisitor<GraphQLInputObjectType | undefined> {\n\n\tconstructor(\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly authorizator: Authorizator,\n\t\tprivate readonly whereTypeBuilder: WhereTypeProvider,\n\t\tprivate readonly updateEntityInputProviderAccessor: Accessor<EntityInputProvider<EntityInputType.update>>,\n\t\tprivate readonly createEntityInputProvider: EntityInputProvider<EntityInputType.create>,\n\t\tprivate readonly updateEntityRelationAllowedOperationsVisitor: UpdateEntityRelationAllowedOperationsVisitor,\n\t\tprivate readonly connectOrCreateRelationInputProvider: ConnectOrCreateRelationInputProvider,\n\t) {\n\t}\n\n\tpublic visitColumn(): never {\n\t\tthrow new Error('UpdateEntityRelationInputFieldVisitor: Not applicable for a column')\n\t}\n\n\tpublic visitHasOne({ targetRelation, targetEntity, relation, entity }: Model.AnyHasOneRelationContext) {\n\t\tconst withoutRelation = targetRelation ? targetRelation.name : undefined\n\n\t\tconst whereInputType = this.createUniqueWhereInput(targetEntity)\n\t\tconst whereInput = whereInputType ? { type: whereInputType } : undefined\n\n\t\tconst createInputType = this.createEntityInputProvider.getInput(targetEntity.name, withoutRelation)\n\t\tconst createInput = createInputType ? { type: createInputType } : undefined\n\n\t\tconst updateInputType = this.updateEntityInputProviderAccessor.get().getInput(targetEntity.name, withoutRelation)\n\t\tconst updateInput = updateInputType ? { type: updateInputType } : undefined\n\n\t\tconst upsertInput = updateInputType && createInputType\n\t\t\t? {\n\t\t\t\ttype: new GraphQLInputObjectType({\n\t\t\t\t\tname: GqlTypeName`${entity.name}Upsert${relation.name}RelationInput`,\n\t\t\t\t\tfields: () => ({\n\t\t\t\t\t\tupdate: { type: new GraphQLNonNull(updateInputType) },\n\t\t\t\t\t\tcreate: { type: new GraphQLNonNull(createInputType) },\n\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t\t}\n\t\t\t: undefined\n\n\t\tconst booleanInput = {\n\t\t\ttype: GraphQLBoolean,\n\t\t}\n\n\t\tconst connectOrCreateInput = createInput && whereInputType\n\t\t\t? { type: this.connectOrCreateRelationInputProvider.getInput(entity.name, relation.name) }\n\t\t\t: undefined\n\n\t\tconst fields = {\n\t\t\t[Input.UpdateRelationOperation.connect]: whereInput,\n\t\t\t[Input.UpdateRelationOperation.create]: createInput,\n\t\t\t[Input.UpdateRelationOperation.connectOrCreate]: connectOrCreateInput,\n\t\t\t[Input.UpdateRelationOperation.update]: updateInput,\n\t\t\t[Input.UpdateRelationOperation.upsert]: upsertInput,\n\t\t\t[Input.UpdateRelationOperation.disconnect]: booleanInput,\n\t\t\t[Input.UpdateRelationOperation.delete]: booleanInput,\n\t\t}\n\n\t\tconst filteredFields = this.filterAllowedOperations(entity, relation, fields)\n\t\tif (Object.keys(filteredFields).length === 0) {\n\t\t\treturn undefined\n\t\t}\n\n\t\treturn new GraphQLInputObjectType({\n\t\t\tname: GqlTypeName`${entity.name}Update${relation.name}EntityRelationInput`,\n\t\t\tfields: () => filteredFields,\n\t\t})\n\t}\n\n\tpublic visitHasMany({ entity, relation, targetEntity, targetRelation }: Model.AnyHasManyRelationContext) {\n\t\tconst withoutRelation = targetRelation ? targetRelation.name : undefined\n\n\t\tconst whereInputType = this.createUniqueWhereInput(targetEntity)\n\t\tconst whereInput = whereInputType ? { type: whereInputType } : undefined\n\n\t\tconst createInputType = this.createEntityInputProvider.getInput(targetEntity.name, withoutRelation)\n\t\tconst createInput = createInputType ? { type: createInputType } : undefined\n\n\t\tconst updateInputType = this.updateEntityInputProviderAccessor.get().getInput(targetEntity.name, withoutRelation)\n\n\t\tconst updateSpecifiedInput = updateInputType && whereInputType\n\t\t\t? {\n\t\t\t\ttype: new GraphQLInputObjectType({\n\t\t\t\t\tname: GqlTypeName`${entity.name}Update${relation.name}RelationInput`,\n\t\t\t\t\tfields: () => ({\n\t\t\t\t\t\tby: { type: new GraphQLNonNull(whereInputType) },\n\t\t\t\t\t\tdata: { type: new GraphQLNonNull(updateInputType) },\n\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t\t}\n\t\t\t: undefined\n\n\t\tconst upsertInput = updateInputType && createInputType && whereInputType\n\t\t\t? {\n\t\t\t\ttype: new GraphQLInputObjectType({\n\t\t\t\t\tname: GqlTypeName`${entity.name}Upsert${relation.name}RelationInput`,\n\t\t\t\t\tfields: () => ({\n\t\t\t\t\t\tby: { type: new GraphQLNonNull(whereInputType) },\n\t\t\t\t\t\tupdate: { type: new GraphQLNonNull(updateInputType) },\n\t\t\t\t\t\tcreate: { type: new GraphQLNonNull(createInputType) },\n\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t\t}\n\t\t\t: undefined\n\n\t\tconst connectOrCreateInput = createInput && whereInputType\n\t\t\t? { type: this.connectOrCreateRelationInputProvider.getInput(entity.name, relation.name) }\n\t\t\t: undefined\n\n\t\tconst fields = {\n\t\t\t[Input.UpdateRelationOperation.create]: createInput,\n\t\t\t[Input.UpdateRelationOperation.update]: updateSpecifiedInput,\n\t\t\t[Input.UpdateRelationOperation.upsert]: upsertInput,\n\t\t\t[Input.UpdateRelationOperation.connect]: whereInput,\n\t\t\t[Input.UpdateRelationOperation.connectOrCreate]: connectOrCreateInput,\n\t\t\t[Input.UpdateRelationOperation.disconnect]: whereInput,\n\t\t\t[Input.UpdateRelationOperation.delete]: whereInput,\n\t\t}\n\n\t\tconst filteredFields = this.filterAllowedOperations(entity, relation, fields)\n\t\tif (Object.keys(filteredFields).length === 0) {\n\t\t\treturn undefined\n\t\t}\n\n\t\treturn new GraphQLInputObjectType({\n\t\t\tname: GqlTypeName`${entity.name}Update${relation.name}EntityRelationInput`,\n\t\t\tfields: () => ({\n\t\t\t\t...filteredFields,\n\t\t\t\talias: { type: GraphQLString },\n\t\t\t}),\n\t\t})\n\t}\n\n\tprivate filterAllowedOperations(\n\t\tentity: Model.Entity,\n\t\trelation: Model.Relation,\n\t\tgraphQlFields: { [key: string]: GraphQLInputFieldConfig | undefined },\n\t): GraphQLInputFieldConfigMap {\n\t\tconst allowedOperations = acceptFieldVisitor(\n\t\t\tthis.schema,\n\t\t\tentity,\n\t\t\trelation.name,\n\t\t\tthis.updateEntityRelationAllowedOperationsVisitor,\n\t\t)\n\t\treturn filterObject(\n\t\t\tgraphQlFields,\n\t\t\t(key, value): value is GraphQLInputFieldConfig =>\n\t\t\t\tallowedOperations.includes(key as Input.UpdateRelationOperation) && value !== undefined,\n\t\t)\n\t}\n\n\tprivate createUniqueWhereInput(targetEntity: Model.Entity): GraphQLInputObjectType | undefined {\n\t\tif (this.authorizator.getEntityPermission(Acl.Operation.read, targetEntity.name) === 'no') {\n\t\t\treturn undefined\n\t\t}\n\t\tconst uniqueWhere = this.whereTypeBuilder.getEntityUniqueWhereType(targetEntity.name)\n\t\tif (!uniqueWhere) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\treturn uniqueWhere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,KAAK;AAAA,IAAA;AAEC,WAAA;AAAA,MACN;AAAA,MACA,CAAC,KAAK,UACL,kBAAkB,SAAS,GAAoC,KAAK,UAAU;AAAA,IAAA;AAAA,EAEjF;AAAA,EAEQ,uBAAuB,cAAgE;AAC1F,QAAA,KAAK,aAAa,oBAAoB,IAAI,UAAU,MAAM,aAAa,IAAI,MAAM,MAAM;AACnF,aAAA;AAAA,IACR;AACA,UAAM,cAAc,KAAK,iBAAiB,yBAAyB,aAAa,IAAI;AACpF,QAAI,CAAC,aAAa;AACjB,YAAM,IAAI,wBAAwB;AAAA,IACnC;AACO,WAAA;AAAA,EACR;AACD;"}
|
|
@@ -106,6 +106,9 @@ class UpdateInputVisitor {
|
|
|
106
106
|
if (isIt.isIt(element, "create")) {
|
|
107
107
|
result = processor.create({ ...context, input: element.create, index: i, alias });
|
|
108
108
|
}
|
|
109
|
+
if (isIt.isIt(element, "connectOrCreate")) {
|
|
110
|
+
result = processor.connectOrCreate({ ...context, input: element.connectOrCreate, index: i, alias });
|
|
111
|
+
}
|
|
109
112
|
if (isIt.isIt(element, "delete")) {
|
|
110
113
|
result = processor.delete({ ...context, input: element.delete, index: i, alias });
|
|
111
114
|
}
|
|
@@ -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.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,mBAE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M;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,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;;"}
|
|
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;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O,WAAA;AAAA,EACR;AAAA,EAEQ,iBAAiB,OAAe;AACjC,UAAA,OAAO,OAAO,KAAK,KAAK,EAAE,OAAO,CAAA,OAAM,OAAO,OAAO;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;;"}
|
|
@@ -104,6 +104,9 @@ class UpdateInputVisitor {
|
|
|
104
104
|
if (isIt(element, "create")) {
|
|
105
105
|
result = processor.create({ ...context, input: element.create, index: i, alias });
|
|
106
106
|
}
|
|
107
|
+
if (isIt(element, "connectOrCreate")) {
|
|
108
|
+
result = processor.connectOrCreate({ ...context, input: element.connectOrCreate, index: i, alias });
|
|
109
|
+
}
|
|
107
110
|
if (isIt(element, "delete")) {
|
|
108
111
|
result = processor.delete({ ...context, input: element.delete, index: i, alias });
|
|
109
112
|
}
|
|
@@ -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.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,YAC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AAO,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 | 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,KA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I;AAAA,QACT,4BAA4B,IAAI,KAAK,IAAI,CAAC,KAAK,KAAK;AAAA,MAAA;AAAA,IAEtD;AAAA,EACD;AACD;"}
|
|
@@ -84,11 +84,13 @@ class UpdateEntityRelationInputFieldVisitor {
|
|
|
84
84
|
})
|
|
85
85
|
})
|
|
86
86
|
} : void 0;
|
|
87
|
+
const connectOrCreateInput = createInput && whereInputType ? { type: this.connectOrCreateRelationInputProvider.getInput(entity.name, relation.name) } : void 0;
|
|
87
88
|
const fields = {
|
|
88
89
|
[schema.Input.UpdateRelationOperation.create]: createInput,
|
|
89
90
|
[schema.Input.UpdateRelationOperation.update]: updateSpecifiedInput,
|
|
90
91
|
[schema.Input.UpdateRelationOperation.upsert]: upsertInput,
|
|
91
92
|
[schema.Input.UpdateRelationOperation.connect]: whereInput,
|
|
93
|
+
[schema.Input.UpdateRelationOperation.connectOrCreate]: connectOrCreateInput,
|
|
92
94
|
[schema.Input.UpdateRelationOperation.disconnect]: whereInput,
|
|
93
95
|
[schema.Input.UpdateRelationOperation.delete]: whereInput
|
|
94
96
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UpdateEntityRelationInputFieldVisitor.cjs","sources":["../../../../../../packages/engine-content-api/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.ts"],"sourcesContent":["import {\n\tGraphQLBoolean,\n\tGraphQLInputFieldConfig,\n\tGraphQLInputFieldConfigMap,\n\tGraphQLInputObjectType, GraphQLNonNull,\n\tGraphQLString,\n} from 'graphql'\nimport { Acl, Input, Model } from '@contember/schema'\nimport { GqlTypeName } from '../utils'\nimport { WhereTypeProvider } from '../WhereTypeProvider'\nimport { Accessor, filterObject } from '../../utils'\nimport { EntityInputProvider, EntityInputType } from './EntityInputProvider'\nimport { acceptFieldVisitor } from '@contember/schema-utils'\nimport { UpdateEntityRelationAllowedOperationsVisitor } from './UpdateEntityRelationAllowedOperationsVisitor'\nimport { Authorizator } from '../../acl'\nimport { ImplementationException } from '../../exception'\nimport { ConnectOrCreateRelationInputProvider } from './ConnectOrCreateRelationInputProvider'\n\nexport class UpdateEntityRelationInputFieldVisitor implements Model.ColumnVisitor<never>,\n\tModel.RelationByGenericTypeVisitor<GraphQLInputObjectType | undefined> {\n\n\tconstructor(\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly authorizator: Authorizator,\n\t\tprivate readonly whereTypeBuilder: WhereTypeProvider,\n\t\tprivate readonly updateEntityInputProviderAccessor: Accessor<EntityInputProvider<EntityInputType.update>>,\n\t\tprivate readonly createEntityInputProvider: EntityInputProvider<EntityInputType.create>,\n\t\tprivate readonly updateEntityRelationAllowedOperationsVisitor: UpdateEntityRelationAllowedOperationsVisitor,\n\t\tprivate readonly connectOrCreateRelationInputProvider: ConnectOrCreateRelationInputProvider,\n\t) {\n\t}\n\n\tpublic visitColumn(): never {\n\t\tthrow new Error('UpdateEntityRelationInputFieldVisitor: Not applicable for a column')\n\t}\n\n\tpublic visitHasOne({ targetRelation, targetEntity, relation, entity }: Model.AnyHasOneRelationContext) {\n\t\tconst withoutRelation = targetRelation ? targetRelation.name : undefined\n\n\t\tconst whereInputType = this.createUniqueWhereInput(targetEntity)\n\t\tconst whereInput = whereInputType ? { type: whereInputType } : undefined\n\n\t\tconst createInputType = this.createEntityInputProvider.getInput(targetEntity.name, withoutRelation)\n\t\tconst createInput = createInputType ? { type: createInputType } : undefined\n\n\t\tconst updateInputType = this.updateEntityInputProviderAccessor.get().getInput(targetEntity.name, withoutRelation)\n\t\tconst updateInput = updateInputType ? { type: updateInputType } : undefined\n\n\t\tconst upsertInput = updateInputType && createInputType\n\t\t\t? {\n\t\t\t\ttype: new GraphQLInputObjectType({\n\t\t\t\t\tname: GqlTypeName`${entity.name}Upsert${relation.name}RelationInput`,\n\t\t\t\t\tfields: () => ({\n\t\t\t\t\t\tupdate: { type: new GraphQLNonNull(updateInputType) },\n\t\t\t\t\t\tcreate: { type: new GraphQLNonNull(createInputType) },\n\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t\t}\n\t\t\t: undefined\n\n\t\tconst booleanInput = {\n\t\t\ttype: GraphQLBoolean,\n\t\t}\n\n\t\tconst connectOrCreateInput = createInput && whereInputType\n\t\t\t? { type: this.connectOrCreateRelationInputProvider.getInput(entity.name, relation.name) }\n\t\t\t: undefined\n\n\t\tconst fields = {\n\t\t\t[Input.UpdateRelationOperation.connect]: whereInput,\n\t\t\t[Input.UpdateRelationOperation.create]: createInput,\n\t\t\t[Input.UpdateRelationOperation.connectOrCreate]: connectOrCreateInput,\n\t\t\t[Input.UpdateRelationOperation.update]: updateInput,\n\t\t\t[Input.UpdateRelationOperation.upsert]: upsertInput,\n\t\t\t[Input.UpdateRelationOperation.disconnect]: booleanInput,\n\t\t\t[Input.UpdateRelationOperation.delete]: booleanInput,\n\t\t}\n\n\t\tconst filteredFields = this.filterAllowedOperations(entity, relation, fields)\n\t\tif (Object.keys(filteredFields).length === 0) {\n\t\t\treturn undefined\n\t\t}\n\n\t\treturn new GraphQLInputObjectType({\n\t\t\tname: GqlTypeName`${entity.name}Update${relation.name}EntityRelationInput`,\n\t\t\tfields: () => filteredFields,\n\t\t})\n\t}\n\n\tpublic visitHasMany({ entity, relation, targetEntity, targetRelation }: Model.AnyHasManyRelationContext) {\n\t\tconst withoutRelation = targetRelation ? targetRelation.name : undefined\n\n\t\tconst whereInputType = this.createUniqueWhereInput(targetEntity)\n\t\tconst whereInput = whereInputType ? { type: whereInputType } : undefined\n\n\t\tconst createInputType = this.createEntityInputProvider.getInput(targetEntity.name, withoutRelation)\n\t\tconst createInput = createInputType ? { type: createInputType } : undefined\n\n\t\tconst updateInputType = this.updateEntityInputProviderAccessor.get().getInput(targetEntity.name, withoutRelation)\n\n\t\tconst updateSpecifiedInput = updateInputType && whereInputType\n\t\t\t? {\n\t\t\t\ttype: new GraphQLInputObjectType({\n\t\t\t\t\tname: GqlTypeName`${entity.name}Update${relation.name}RelationInput`,\n\t\t\t\t\tfields: () => ({\n\t\t\t\t\t\tby: { type: new GraphQLNonNull(whereInputType) },\n\t\t\t\t\t\tdata: { type: new GraphQLNonNull(updateInputType) },\n\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t\t}\n\t\t\t: undefined\n\n\t\tconst upsertInput = updateInputType && createInputType && whereInputType\n\t\t\t? {\n\t\t\t\ttype: new GraphQLInputObjectType({\n\t\t\t\t\tname: GqlTypeName`${entity.name}Upsert${relation.name}RelationInput`,\n\t\t\t\t\tfields: () => ({\n\t\t\t\t\t\tby: { type: new GraphQLNonNull(whereInputType) },\n\t\t\t\t\t\tupdate: { type: new GraphQLNonNull(updateInputType) },\n\t\t\t\t\t\tcreate: { type: new GraphQLNonNull(createInputType) },\n\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t\t}\n\t\t\t: undefined\n\n\t\tconst fields = {\n\t\t\t[Input.UpdateRelationOperation.create]: createInput,\n\t\t\t[Input.UpdateRelationOperation.update]: updateSpecifiedInput,\n\t\t\t[Input.UpdateRelationOperation.upsert]: upsertInput,\n\t\t\t[Input.UpdateRelationOperation.connect]: whereInput,\n\t\t\t[Input.UpdateRelationOperation.disconnect]: whereInput,\n\t\t\t[Input.UpdateRelationOperation.delete]: whereInput,\n\t\t}\n\n\t\tconst filteredFields = this.filterAllowedOperations(entity, relation, fields)\n\t\tif (Object.keys(filteredFields).length === 0) {\n\t\t\treturn undefined\n\t\t}\n\n\t\treturn new GraphQLInputObjectType({\n\t\t\tname: GqlTypeName`${entity.name}Update${relation.name}EntityRelationInput`,\n\t\t\tfields: () => ({\n\t\t\t\t...filteredFields,\n\t\t\t\talias: { type: GraphQLString },\n\t\t\t}),\n\t\t})\n\t}\n\n\tprivate filterAllowedOperations(\n\t\tentity: Model.Entity,\n\t\trelation: Model.Relation,\n\t\tgraphQlFields: { [key: string]: GraphQLInputFieldConfig | undefined },\n\t): GraphQLInputFieldConfigMap {\n\t\tconst allowedOperations = acceptFieldVisitor(\n\t\t\tthis.schema,\n\t\t\tentity,\n\t\t\trelation.name,\n\t\t\tthis.updateEntityRelationAllowedOperationsVisitor,\n\t\t)\n\t\treturn filterObject(\n\t\t\tgraphQlFields,\n\t\t\t(key, value): value is GraphQLInputFieldConfig =>\n\t\t\t\tallowedOperations.includes(key as Input.UpdateRelationOperation) && value !== undefined,\n\t\t)\n\t}\n\n\tprivate createUniqueWhereInput(targetEntity: Model.Entity): GraphQLInputObjectType | undefined {\n\t\tif (this.authorizator.getEntityPermission(Acl.Operation.read, targetEntity.name) === 'no') {\n\t\t\treturn undefined\n\t\t}\n\t\tconst uniqueWhere = this.whereTypeBuilder.getEntityUniqueWhereType(targetEntity.name)\n\t\tif (!uniqueWhere) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\treturn uniqueWhere\n\t}\n}\n"],"names":["schema","GraphQLInputObjectType","GqlTypeName","GraphQLNonNull","GraphQLBoolean","Input","GraphQLString","acceptFieldVisitor","filterObject","Acl","ImplementationException"],"mappings":";;;;;;;;AAkBO,MAAM,sCAC2D;AAAA,EAEvE,YACkBA,SACA,cACA,kBACA,mCACA,2BACA,8CACA,sCAChB;AAPgB,SAAA,SAAAA;AACA,SAAA,eAAA;AACA,SAAA,mBAAA;AACA,SAAA,oCAAA;AACA,SAAA,4BAAA;AACA,SAAA,+CAAA;AACA,SAAA,uCAAA;AAAA,EAElB;AAAA,EAEO,cAAqB;AACrB,UAAA,IAAI,MAAM,oEAAoE;AAAA,EACrF;AAAA,EAEO,YAAY,EAAE,gBAAgB,cAAc,UAAU,UAA0C;AAChG,UAAA,kBAAkB,iBAAiB,eAAe,OAAO;AAEzD,UAAA,iBAAiB,KAAK,uBAAuB,YAAY;AAC/D,UAAM,aAAa,iBAAiB,EAAE,MAAM,mBAAmB;AAE/D,UAAM,kBAAkB,KAAK,0BAA0B,SAAS,aAAa,MAAM,eAAe;AAClG,UAAM,cAAc,kBAAkB,EAAE,MAAM,oBAAoB;AAE5D,UAAA,kBAAkB,KAAK,kCAAkC,IAAA,EAAM,SAAS,aAAa,MAAM,eAAe;AAChH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AAAA,MACxC,CAACA,OAAA,MAAM,wBAAwB,OAAO,GAAG;AAAA,MACzC,CAACA,OAAA,MAAM,wBAAwB,UAAU,GAAG;AAAA,MAC5C,CAACA,OAAA,MAAM,wBAAwB,MAAM,GAAG;AAAA,IAAA;AAGzC,UAAM,iBAAiB,KAAK,wBAAwB,QAAQ,UAAU,MAAM;AAC5E,QAAI,OAAO,KAAK,cAAc,EAAE,WAAW,GAAG;AACtC,aAAA;AAAA,IACR;AAEA,WAAO,IAAIJ,QAAAA,uBAAuB;AAAA,MACjC,MAAMC,MAAAA,cAAc,OAAO,IAAI,SAAS,SAAS,IAAI;AAAA,MACrD,QAAQ,OAAO;AAAA,QACd,GAAG;AAAA,QACH,OAAO,EAAE,MAAMI,sBAAc;AAAA,MAAA;AAAA,IAC9B,CACA;AAAA,EACF;AAAA,EAEQ,wBACP,QACA,UACA,eAC6B;AAC7B,UAAM,oBAAoBC,YAAA;AAAA,MACzB,KAAK;AAAA,MACL;AAAA,MACA,SAAS;AAAA,MACT,KAAK;AAAA,IAAA;AAEC,WAAAC,OAAA;AAAA,MACN;AAAA,MACA,CAAC,KAAK,UACL,kBAAkB,SAAS,GAAoC,KAAK,UAAU;AAAA,IAAA;AAAA,EAEjF;AAAA,EAEQ,uBAAuB,cAAgE;AAC1F,QAAA,KAAK,aAAa,oBAAoBC,OAAA,IAAI,UAAU,MAAM,aAAa,IAAI,MAAM,MAAM;AACnF,aAAA;AAAA,IACR;AACA,UAAM,cAAc,KAAK,iBAAiB,yBAAyB,aAAa,IAAI;AACpF,QAAI,CAAC,aAAa;AACjB,YAAM,IAAIC,UAAwB,wBAAA;AAAA,IACnC;AACO,WAAA;AAAA,EACR;AACD;;"}
|
|
1
|
+
{"version":3,"file":"UpdateEntityRelationInputFieldVisitor.cjs","sources":["../../../../../../packages/engine-content-api/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.ts"],"sourcesContent":["import {\n\tGraphQLBoolean,\n\tGraphQLInputFieldConfig,\n\tGraphQLInputFieldConfigMap,\n\tGraphQLInputObjectType, GraphQLNonNull,\n\tGraphQLString,\n} from 'graphql'\nimport { Acl, Input, Model } from '@contember/schema'\nimport { GqlTypeName } from '../utils'\nimport { WhereTypeProvider } from '../WhereTypeProvider'\nimport { Accessor, filterObject } from '../../utils'\nimport { EntityInputProvider, EntityInputType } from './EntityInputProvider'\nimport { acceptFieldVisitor } from '@contember/schema-utils'\nimport { UpdateEntityRelationAllowedOperationsVisitor } from './UpdateEntityRelationAllowedOperationsVisitor'\nimport { Authorizator } from '../../acl'\nimport { ImplementationException } from '../../exception'\nimport { ConnectOrCreateRelationInputProvider } from './ConnectOrCreateRelationInputProvider'\n\nexport class UpdateEntityRelationInputFieldVisitor implements Model.ColumnVisitor<never>,\n\tModel.RelationByGenericTypeVisitor<GraphQLInputObjectType | undefined> {\n\n\tconstructor(\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly authorizator: Authorizator,\n\t\tprivate readonly whereTypeBuilder: WhereTypeProvider,\n\t\tprivate readonly updateEntityInputProviderAccessor: Accessor<EntityInputProvider<EntityInputType.update>>,\n\t\tprivate readonly createEntityInputProvider: EntityInputProvider<EntityInputType.create>,\n\t\tprivate readonly updateEntityRelationAllowedOperationsVisitor: UpdateEntityRelationAllowedOperationsVisitor,\n\t\tprivate readonly connectOrCreateRelationInputProvider: ConnectOrCreateRelationInputProvider,\n\t) {\n\t}\n\n\tpublic visitColumn(): never {\n\t\tthrow new Error('UpdateEntityRelationInputFieldVisitor: Not applicable for a column')\n\t}\n\n\tpublic visitHasOne({ targetRelation, targetEntity, relation, entity }: Model.AnyHasOneRelationContext) {\n\t\tconst withoutRelation = targetRelation ? targetRelation.name : undefined\n\n\t\tconst whereInputType = this.createUniqueWhereInput(targetEntity)\n\t\tconst whereInput = whereInputType ? { type: whereInputType } : undefined\n\n\t\tconst createInputType = this.createEntityInputProvider.getInput(targetEntity.name, withoutRelation)\n\t\tconst createInput = createInputType ? { type: createInputType } : undefined\n\n\t\tconst updateInputType = this.updateEntityInputProviderAccessor.get().getInput(targetEntity.name, withoutRelation)\n\t\tconst updateInput = updateInputType ? { type: updateInputType } : undefined\n\n\t\tconst upsertInput = updateInputType && createInputType\n\t\t\t? {\n\t\t\t\ttype: new GraphQLInputObjectType({\n\t\t\t\t\tname: GqlTypeName`${entity.name}Upsert${relation.name}RelationInput`,\n\t\t\t\t\tfields: () => ({\n\t\t\t\t\t\tupdate: { type: new GraphQLNonNull(updateInputType) },\n\t\t\t\t\t\tcreate: { type: new GraphQLNonNull(createInputType) },\n\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t\t}\n\t\t\t: undefined\n\n\t\tconst booleanInput = {\n\t\t\ttype: GraphQLBoolean,\n\t\t}\n\n\t\tconst connectOrCreateInput = createInput && whereInputType\n\t\t\t? { type: this.connectOrCreateRelationInputProvider.getInput(entity.name, relation.name) }\n\t\t\t: undefined\n\n\t\tconst fields = {\n\t\t\t[Input.UpdateRelationOperation.connect]: whereInput,\n\t\t\t[Input.UpdateRelationOperation.create]: createInput,\n\t\t\t[Input.UpdateRelationOperation.connectOrCreate]: connectOrCreateInput,\n\t\t\t[Input.UpdateRelationOperation.update]: updateInput,\n\t\t\t[Input.UpdateRelationOperation.upsert]: upsertInput,\n\t\t\t[Input.UpdateRelationOperation.disconnect]: booleanInput,\n\t\t\t[Input.UpdateRelationOperation.delete]: booleanInput,\n\t\t}\n\n\t\tconst filteredFields = this.filterAllowedOperations(entity, relation, fields)\n\t\tif (Object.keys(filteredFields).length === 0) {\n\t\t\treturn undefined\n\t\t}\n\n\t\treturn new GraphQLInputObjectType({\n\t\t\tname: GqlTypeName`${entity.name}Update${relation.name}EntityRelationInput`,\n\t\t\tfields: () => filteredFields,\n\t\t})\n\t}\n\n\tpublic visitHasMany({ entity, relation, targetEntity, targetRelation }: Model.AnyHasManyRelationContext) {\n\t\tconst withoutRelation = targetRelation ? targetRelation.name : undefined\n\n\t\tconst whereInputType = this.createUniqueWhereInput(targetEntity)\n\t\tconst whereInput = whereInputType ? { type: whereInputType } : undefined\n\n\t\tconst createInputType = this.createEntityInputProvider.getInput(targetEntity.name, withoutRelation)\n\t\tconst createInput = createInputType ? { type: createInputType } : undefined\n\n\t\tconst updateInputType = this.updateEntityInputProviderAccessor.get().getInput(targetEntity.name, withoutRelation)\n\n\t\tconst updateSpecifiedInput = updateInputType && whereInputType\n\t\t\t? {\n\t\t\t\ttype: new GraphQLInputObjectType({\n\t\t\t\t\tname: GqlTypeName`${entity.name}Update${relation.name}RelationInput`,\n\t\t\t\t\tfields: () => ({\n\t\t\t\t\t\tby: { type: new GraphQLNonNull(whereInputType) },\n\t\t\t\t\t\tdata: { type: new GraphQLNonNull(updateInputType) },\n\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t\t}\n\t\t\t: undefined\n\n\t\tconst upsertInput = updateInputType && createInputType && whereInputType\n\t\t\t? {\n\t\t\t\ttype: new GraphQLInputObjectType({\n\t\t\t\t\tname: GqlTypeName`${entity.name}Upsert${relation.name}RelationInput`,\n\t\t\t\t\tfields: () => ({\n\t\t\t\t\t\tby: { type: new GraphQLNonNull(whereInputType) },\n\t\t\t\t\t\tupdate: { type: new GraphQLNonNull(updateInputType) },\n\t\t\t\t\t\tcreate: { type: new GraphQLNonNull(createInputType) },\n\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t\t}\n\t\t\t: undefined\n\n\t\tconst connectOrCreateInput = createInput && whereInputType\n\t\t\t? { type: this.connectOrCreateRelationInputProvider.getInput(entity.name, relation.name) }\n\t\t\t: undefined\n\n\t\tconst fields = {\n\t\t\t[Input.UpdateRelationOperation.create]: createInput,\n\t\t\t[Input.UpdateRelationOperation.update]: updateSpecifiedInput,\n\t\t\t[Input.UpdateRelationOperation.upsert]: upsertInput,\n\t\t\t[Input.UpdateRelationOperation.connect]: whereInput,\n\t\t\t[Input.UpdateRelationOperation.connectOrCreate]: connectOrCreateInput,\n\t\t\t[Input.UpdateRelationOperation.disconnect]: whereInput,\n\t\t\t[Input.UpdateRelationOperation.delete]: whereInput,\n\t\t}\n\n\t\tconst filteredFields = this.filterAllowedOperations(entity, relation, fields)\n\t\tif (Object.keys(filteredFields).length === 0) {\n\t\t\treturn undefined\n\t\t}\n\n\t\treturn new GraphQLInputObjectType({\n\t\t\tname: GqlTypeName`${entity.name}Update${relation.name}EntityRelationInput`,\n\t\t\tfields: () => ({\n\t\t\t\t...filteredFields,\n\t\t\t\talias: { type: GraphQLString },\n\t\t\t}),\n\t\t})\n\t}\n\n\tprivate filterAllowedOperations(\n\t\tentity: Model.Entity,\n\t\trelation: Model.Relation,\n\t\tgraphQlFields: { [key: string]: GraphQLInputFieldConfig | undefined },\n\t): GraphQLInputFieldConfigMap {\n\t\tconst allowedOperations = acceptFieldVisitor(\n\t\t\tthis.schema,\n\t\t\tentity,\n\t\t\trelation.name,\n\t\t\tthis.updateEntityRelationAllowedOperationsVisitor,\n\t\t)\n\t\treturn filterObject(\n\t\t\tgraphQlFields,\n\t\t\t(key, value): value is GraphQLInputFieldConfig =>\n\t\t\t\tallowedOperations.includes(key as Input.UpdateRelationOperation) && value !== undefined,\n\t\t)\n\t}\n\n\tprivate createUniqueWhereInput(targetEntity: Model.Entity): GraphQLInputObjectType | undefined {\n\t\tif (this.authorizator.getEntityPermission(Acl.Operation.read, targetEntity.name) === 'no') {\n\t\t\treturn undefined\n\t\t}\n\t\tconst uniqueWhere = this.whereTypeBuilder.getEntityUniqueWhereType(targetEntity.name)\n\t\tif (!uniqueWhere) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\treturn uniqueWhere\n\t}\n}\n"],"names":["schema","GraphQLInputObjectType","GqlTypeName","GraphQLNonNull","GraphQLBoolean","Input","GraphQLString","acceptFieldVisitor","filterObject","Acl","ImplementationException"],"mappings":";;;;;;;;AAkBO,MAAM,sCAC2D;AAAA,EAEvE,YACkBA,SACA,cACA,kBACA,mCACA,2BACA,8CACA,sCAChB;AAPgB,SAAA,SAAAA;AACA,SAAA,eAAA;AACA,SAAA,m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M,oBAAoBC,YAAA;AAAA,MACzB,KAAK;AAAA,MACL;AAAA,MACA,SAAS;AAAA,MACT,KAAK;AAAA,IAAA;AAEC,WAAAC,OAAA;AAAA,MACN;AAAA,MACA,CAAC,KAAK,UACL,kBAAkB,SAAS,GAAoC,KAAK,UAAU;AAAA,IAAA;AAAA,EAEjF;AAAA,EAEQ,uBAAuB,cAAgE;AAC1F,QAAA,KAAK,aAAa,oBAAoBC,OAAA,IAAI,UAAU,MAAM,aAAa,IAAI,MAAM,MAAM;AACnF,aAAA;AAAA,IACR;AACA,UAAM,cAAc,KAAK,iBAAiB,yBAAyB,aAAa,IAAI;AACpF,QAAI,CAAC,aAAa;AACjB,YAAM,IAAIC,UAAwB,wBAAA;AAAA,IACnC;AACO,WAAA;AAAA,EACR;AACD;;"}
|
|
@@ -82,11 +82,13 @@ class UpdateEntityRelationInputFieldVisitor {
|
|
|
82
82
|
})
|
|
83
83
|
})
|
|
84
84
|
} : void 0;
|
|
85
|
+
const connectOrCreateInput = createInput && whereInputType ? { type: this.connectOrCreateRelationInputProvider.getInput(entity.name, relation.name) } : void 0;
|
|
85
86
|
const fields = {
|
|
86
87
|
[Input.UpdateRelationOperation.create]: createInput,
|
|
87
88
|
[Input.UpdateRelationOperation.update]: updateSpecifiedInput,
|
|
88
89
|
[Input.UpdateRelationOperation.upsert]: upsertInput,
|
|
89
90
|
[Input.UpdateRelationOperation.connect]: whereInput,
|
|
91
|
+
[Input.UpdateRelationOperation.connectOrCreate]: connectOrCreateInput,
|
|
90
92
|
[Input.UpdateRelationOperation.disconnect]: whereInput,
|
|
91
93
|
[Input.UpdateRelationOperation.delete]: whereInput
|
|
92
94
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UpdateEntityRelationInputFieldVisitor.js","sources":["../../../../../../packages/engine-content-api/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.ts"],"sourcesContent":["import {\n\tGraphQLBoolean,\n\tGraphQLInputFieldConfig,\n\tGraphQLInputFieldConfigMap,\n\tGraphQLInputObjectType, GraphQLNonNull,\n\tGraphQLString,\n} from 'graphql'\nimport { Acl, Input, Model } from '@contember/schema'\nimport { GqlTypeName } from '../utils'\nimport { WhereTypeProvider } from '../WhereTypeProvider'\nimport { Accessor, filterObject } from '../../utils'\nimport { EntityInputProvider, EntityInputType } from './EntityInputProvider'\nimport { acceptFieldVisitor } from '@contember/schema-utils'\nimport { UpdateEntityRelationAllowedOperationsVisitor } from './UpdateEntityRelationAllowedOperationsVisitor'\nimport { Authorizator } from '../../acl'\nimport { ImplementationException } from '../../exception'\nimport { ConnectOrCreateRelationInputProvider } from './ConnectOrCreateRelationInputProvider'\n\nexport class UpdateEntityRelationInputFieldVisitor implements Model.ColumnVisitor<never>,\n\tModel.RelationByGenericTypeVisitor<GraphQLInputObjectType | undefined> {\n\n\tconstructor(\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly authorizator: Authorizator,\n\t\tprivate readonly whereTypeBuilder: WhereTypeProvider,\n\t\tprivate readonly updateEntityInputProviderAccessor: Accessor<EntityInputProvider<EntityInputType.update>>,\n\t\tprivate readonly createEntityInputProvider: EntityInputProvider<EntityInputType.create>,\n\t\tprivate readonly updateEntityRelationAllowedOperationsVisitor: UpdateEntityRelationAllowedOperationsVisitor,\n\t\tprivate readonly connectOrCreateRelationInputProvider: ConnectOrCreateRelationInputProvider,\n\t) {\n\t}\n\n\tpublic visitColumn(): never {\n\t\tthrow new Error('UpdateEntityRelationInputFieldVisitor: Not applicable for a column')\n\t}\n\n\tpublic visitHasOne({ targetRelation, targetEntity, relation, entity }: Model.AnyHasOneRelationContext) {\n\t\tconst withoutRelation = targetRelation ? targetRelation.name : undefined\n\n\t\tconst whereInputType = this.createUniqueWhereInput(targetEntity)\n\t\tconst whereInput = whereInputType ? { type: whereInputType } : undefined\n\n\t\tconst createInputType = this.createEntityInputProvider.getInput(targetEntity.name, withoutRelation)\n\t\tconst createInput = createInputType ? { type: createInputType } : undefined\n\n\t\tconst updateInputType = this.updateEntityInputProviderAccessor.get().getInput(targetEntity.name, withoutRelation)\n\t\tconst updateInput = updateInputType ? { type: updateInputType } : undefined\n\n\t\tconst upsertInput = updateInputType && createInputType\n\t\t\t? {\n\t\t\t\ttype: new GraphQLInputObjectType({\n\t\t\t\t\tname: GqlTypeName`${entity.name}Upsert${relation.name}RelationInput`,\n\t\t\t\t\tfields: () => ({\n\t\t\t\t\t\tupdate: { type: new GraphQLNonNull(updateInputType) },\n\t\t\t\t\t\tcreate: { type: new GraphQLNonNull(createInputType) },\n\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t\t}\n\t\t\t: undefined\n\n\t\tconst booleanInput = {\n\t\t\ttype: GraphQLBoolean,\n\t\t}\n\n\t\tconst connectOrCreateInput = createInput && whereInputType\n\t\t\t? { type: this.connectOrCreateRelationInputProvider.getInput(entity.name, relation.name) }\n\t\t\t: undefined\n\n\t\tconst fields = {\n\t\t\t[Input.UpdateRelationOperation.connect]: whereInput,\n\t\t\t[Input.UpdateRelationOperation.create]: createInput,\n\t\t\t[Input.UpdateRelationOperation.connectOrCreate]: connectOrCreateInput,\n\t\t\t[Input.UpdateRelationOperation.update]: updateInput,\n\t\t\t[Input.UpdateRelationOperation.upsert]: upsertInput,\n\t\t\t[Input.UpdateRelationOperation.disconnect]: booleanInput,\n\t\t\t[Input.UpdateRelationOperation.delete]: booleanInput,\n\t\t}\n\n\t\tconst filteredFields = this.filterAllowedOperations(entity, relation, fields)\n\t\tif (Object.keys(filteredFields).length === 0) {\n\t\t\treturn undefined\n\t\t}\n\n\t\treturn new GraphQLInputObjectType({\n\t\t\tname: GqlTypeName`${entity.name}Update${relation.name}EntityRelationInput`,\n\t\t\tfields: () => filteredFields,\n\t\t})\n\t}\n\n\tpublic visitHasMany({ entity, relation, targetEntity, targetRelation }: Model.AnyHasManyRelationContext) {\n\t\tconst withoutRelation = targetRelation ? targetRelation.name : undefined\n\n\t\tconst whereInputType = this.createUniqueWhereInput(targetEntity)\n\t\tconst whereInput = whereInputType ? { type: whereInputType } : undefined\n\n\t\tconst createInputType = this.createEntityInputProvider.getInput(targetEntity.name, withoutRelation)\n\t\tconst createInput = createInputType ? { type: createInputType } : undefined\n\n\t\tconst updateInputType = this.updateEntityInputProviderAccessor.get().getInput(targetEntity.name, withoutRelation)\n\n\t\tconst updateSpecifiedInput = updateInputType && whereInputType\n\t\t\t? {\n\t\t\t\ttype: new GraphQLInputObjectType({\n\t\t\t\t\tname: GqlTypeName`${entity.name}Update${relation.name}RelationInput`,\n\t\t\t\t\tfields: () => ({\n\t\t\t\t\t\tby: { type: new GraphQLNonNull(whereInputType) },\n\t\t\t\t\t\tdata: { type: new GraphQLNonNull(updateInputType) },\n\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t\t}\n\t\t\t: undefined\n\n\t\tconst upsertInput = updateInputType && createInputType && whereInputType\n\t\t\t? {\n\t\t\t\ttype: new GraphQLInputObjectType({\n\t\t\t\t\tname: GqlTypeName`${entity.name}Upsert${relation.name}RelationInput`,\n\t\t\t\t\tfields: () => ({\n\t\t\t\t\t\tby: { type: new GraphQLNonNull(whereInputType) },\n\t\t\t\t\t\tupdate: { type: new GraphQLNonNull(updateInputType) },\n\t\t\t\t\t\tcreate: { type: new GraphQLNonNull(createInputType) },\n\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t\t}\n\t\t\t: undefined\n\n\t\tconst fields = {\n\t\t\t[Input.UpdateRelationOperation.create]: createInput,\n\t\t\t[Input.UpdateRelationOperation.update]: updateSpecifiedInput,\n\t\t\t[Input.UpdateRelationOperation.upsert]: upsertInput,\n\t\t\t[Input.UpdateRelationOperation.connect]: whereInput,\n\t\t\t[Input.UpdateRelationOperation.disconnect]: whereInput,\n\t\t\t[Input.UpdateRelationOperation.delete]: whereInput,\n\t\t}\n\n\t\tconst filteredFields = this.filterAllowedOperations(entity, relation, fields)\n\t\tif (Object.keys(filteredFields).length === 0) {\n\t\t\treturn undefined\n\t\t}\n\n\t\treturn new GraphQLInputObjectType({\n\t\t\tname: GqlTypeName`${entity.name}Update${relation.name}EntityRelationInput`,\n\t\t\tfields: () => ({\n\t\t\t\t...filteredFields,\n\t\t\t\talias: { type: GraphQLString },\n\t\t\t}),\n\t\t})\n\t}\n\n\tprivate filterAllowedOperations(\n\t\tentity: Model.Entity,\n\t\trelation: Model.Relation,\n\t\tgraphQlFields: { [key: string]: GraphQLInputFieldConfig | undefined },\n\t): GraphQLInputFieldConfigMap {\n\t\tconst allowedOperations = acceptFieldVisitor(\n\t\t\tthis.schema,\n\t\t\tentity,\n\t\t\trelation.name,\n\t\t\tthis.updateEntityRelationAllowedOperationsVisitor,\n\t\t)\n\t\treturn filterObject(\n\t\t\tgraphQlFields,\n\t\t\t(key, value): value is GraphQLInputFieldConfig =>\n\t\t\t\tallowedOperations.includes(key as Input.UpdateRelationOperation) && value !== undefined,\n\t\t)\n\t}\n\n\tprivate createUniqueWhereInput(targetEntity: Model.Entity): GraphQLInputObjectType | undefined {\n\t\tif (this.authorizator.getEntityPermission(Acl.Operation.read, targetEntity.name) === 'no') {\n\t\t\treturn undefined\n\t\t}\n\t\tconst uniqueWhere = this.whereTypeBuilder.getEntityUniqueWhereType(targetEntity.name)\n\t\tif (!uniqueWhere) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\treturn uniqueWhere\n\t}\n}\n"],"names":[],"mappings":";;;;;;AAkBO,MAAM,sCAC2D;AAAA,EAEvE,YACkB,QACA,cACA,kBACA,mCACA,2BACA,8CACA,sCAChB;AAPgB,SAAA,SAAA;AACA,SAAA,eAAA;AACA,SAAA,mBAAA;AACA,SAAA,oCAAA;AACA,SAAA,4BAAA;AACA,SAAA,+CAAA;AACA,SAAA,uCAAA;AAAA,EAElB;AAAA,EAEO,cAAqB;AACrB,UAAA,IAAI,MAAM,oEAAoE;AAAA,EACrF;AAAA,EAEO,YAAY,EAAE,gBAAgB,cAAc,UAAU,UAA0C;AAChG,UAAA,kBAAkB,iBAAiB,eAAe,OAAO;AAEzD,U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xC,CAAC,MAAM,wBAAwB,MAAM,GAAG;AAAA,MACxC,CAAC,MAAM,wBAAwB,MAAM,GAAG;AAAA,MACxC,CAAC,MAAM,wBAAwB,OAAO,GAAG;AAAA,MACzC,CAAC,MAAM,wBAAwB,UAAU,GAAG;AAAA,MAC5C,CAAC,MAAM,wBAAwB,MAAM,GAAG;AAAA,IAAA;AAGzC,UAAM,iBAAiB,KAAK,wBAAwB,QAAQ,UAAU,MAAM;AAC5E,QAAI,OAAO,KAAK,cAAc,EAAE,WAAW,GAAG;AACtC,aAAA;AAAA,IACR;AAEA,WAAO,IAAI,uBAAuB;AAAA,MACjC,MAAM,cAAc,OAAO,IAAI,SAAS,SAAS,IAAI;AAAA,MACrD,QAAQ,OAAO;AAAA,QACd,GAAG;AAAA,QACH,OAAO,EAAE,MAAM,cAAc;AAAA,MAAA;AAAA,IAC9B,CACA;AAAA,EACF;AAAA,EAEQ,wBACP,QACA,UACA,eAC6B;AAC7B,UAAM,oBAAoB;AAAA,MACzB,KAAK;AAAA,MACL;AAAA,MACA,SAAS;AAAA,MACT,KAAK;AAAA,IAAA;AAEC,WAAA;AAAA,MACN;AAAA,MACA,CAAC,KAAK,UACL,kBAAkB,SAAS,GAAoC,KAAK,UAAU;AAAA,IAAA;AAAA,EAEjF;AAAA,EAEQ,uBAAuB,cAAgE;AAC1F,QAAA,KAAK,aAAa,oBAAoB,IAAI,UAAU,MAAM,aAAa,IAAI,MAAM,MAAM;AACnF,aAAA;AAAA,IACR;AACA,UAAM,cAAc,KAAK,iBAAiB,yBAAyB,aAAa,IAAI;AACpF,QAAI,CAAC,aAAa;AACjB,YAAM,IAAI,wBAAwB;AAAA,IACnC;AACO,WAAA;AAAA,EACR;AACD;"}
|
|
1
|
+
{"version":3,"file":"UpdateEntityRelationInputFieldVisitor.js","sources":["../../../../../../packages/engine-content-api/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.ts"],"sourcesContent":["import {\n\tGraphQLBoolean,\n\tGraphQLInputFieldConfig,\n\tGraphQLInputFieldConfigMap,\n\tGraphQLInputObjectType, GraphQLNonNull,\n\tGraphQLString,\n} from 'graphql'\nimport { Acl, Input, Model } from '@contember/schema'\nimport { GqlTypeName } from '../utils'\nimport { WhereTypeProvider } from '../WhereTypeProvider'\nimport { Accessor, filterObject } from '../../utils'\nimport { EntityInputProvider, EntityInputType } from './EntityInputProvider'\nimport { acceptFieldVisitor } from '@contember/schema-utils'\nimport { UpdateEntityRelationAllowedOperationsVisitor } from './UpdateEntityRelationAllowedOperationsVisitor'\nimport { Authorizator } from '../../acl'\nimport { ImplementationException } from '../../exception'\nimport { ConnectOrCreateRelationInputProvider } from './ConnectOrCreateRelationInputProvider'\n\nexport class UpdateEntityRelationInputFieldVisitor implements Model.ColumnVisitor<never>,\n\tModel.RelationByGenericTypeVisitor<GraphQLInputObjectType | undefined> {\n\n\tconstructor(\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly authorizator: Authorizator,\n\t\tprivate readonly whereTypeBuilder: WhereTypeProvider,\n\t\tprivate readonly updateEntityInputProviderAccessor: Accessor<EntityInputProvider<EntityInputType.update>>,\n\t\tprivate readonly createEntityInputProvider: EntityInputProvider<EntityInputType.create>,\n\t\tprivate readonly updateEntityRelationAllowedOperationsVisitor: UpdateEntityRelationAllowedOperationsVisitor,\n\t\tprivate readonly connectOrCreateRelationInputProvider: ConnectOrCreateRelationInputProvider,\n\t) {\n\t}\n\n\tpublic visitColumn(): never {\n\t\tthrow new Error('UpdateEntityRelationInputFieldVisitor: Not applicable for a column')\n\t}\n\n\tpublic visitHasOne({ targetRelation, targetEntity, relation, entity }: Model.AnyHasOneRelationContext) {\n\t\tconst withoutRelation = targetRelation ? targetRelation.name : undefined\n\n\t\tconst whereInputType = this.createUniqueWhereInput(targetEntity)\n\t\tconst whereInput = whereInputType ? { type: whereInputType } : undefined\n\n\t\tconst createInputType = this.createEntityInputProvider.getInput(targetEntity.name, withoutRelation)\n\t\tconst createInput = createInputType ? { type: createInputType } : undefined\n\n\t\tconst updateInputType = this.updateEntityInputProviderAccessor.get().getInput(targetEntity.name, withoutRelation)\n\t\tconst updateInput = updateInputType ? { type: updateInputType } : undefined\n\n\t\tconst upsertInput = updateInputType && createInputType\n\t\t\t? {\n\t\t\t\ttype: new GraphQLInputObjectType({\n\t\t\t\t\tname: GqlTypeName`${entity.name}Upsert${relation.name}RelationInput`,\n\t\t\t\t\tfields: () => ({\n\t\t\t\t\t\tupdate: { type: new GraphQLNonNull(updateInputType) },\n\t\t\t\t\t\tcreate: { type: new GraphQLNonNull(createInputType) },\n\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t\t}\n\t\t\t: undefined\n\n\t\tconst booleanInput = {\n\t\t\ttype: GraphQLBoolean,\n\t\t}\n\n\t\tconst connectOrCreateInput = createInput && whereInputType\n\t\t\t? { type: this.connectOrCreateRelationInputProvider.getInput(entity.name, relation.name) }\n\t\t\t: undefined\n\n\t\tconst fields = {\n\t\t\t[Input.UpdateRelationOperation.connect]: whereInput,\n\t\t\t[Input.UpdateRelationOperation.create]: createInput,\n\t\t\t[Input.UpdateRelationOperation.connectOrCreate]: connectOrCreateInput,\n\t\t\t[Input.UpdateRelationOperation.update]: updateInput,\n\t\t\t[Input.UpdateRelationOperation.upsert]: upsertInput,\n\t\t\t[Input.UpdateRelationOperation.disconnect]: booleanInput,\n\t\t\t[Input.UpdateRelationOperation.delete]: booleanInput,\n\t\t}\n\n\t\tconst filteredFields = this.filterAllowedOperations(entity, relation, fields)\n\t\tif (Object.keys(filteredFields).length === 0) {\n\t\t\treturn undefined\n\t\t}\n\n\t\treturn new GraphQLInputObjectType({\n\t\t\tname: GqlTypeName`${entity.name}Update${relation.name}EntityRelationInput`,\n\t\t\tfields: () => filteredFields,\n\t\t})\n\t}\n\n\tpublic visitHasMany({ entity, relation, targetEntity, targetRelation }: Model.AnyHasManyRelationContext) {\n\t\tconst withoutRelation = targetRelation ? targetRelation.name : undefined\n\n\t\tconst whereInputType = this.createUniqueWhereInput(targetEntity)\n\t\tconst whereInput = whereInputType ? { type: whereInputType } : undefined\n\n\t\tconst createInputType = this.createEntityInputProvider.getInput(targetEntity.name, withoutRelation)\n\t\tconst createInput = createInputType ? { type: createInputType } : undefined\n\n\t\tconst updateInputType = this.updateEntityInputProviderAccessor.get().getInput(targetEntity.name, withoutRelation)\n\n\t\tconst updateSpecifiedInput = updateInputType && whereInputType\n\t\t\t? {\n\t\t\t\ttype: new GraphQLInputObjectType({\n\t\t\t\t\tname: GqlTypeName`${entity.name}Update${relation.name}RelationInput`,\n\t\t\t\t\tfields: () => ({\n\t\t\t\t\t\tby: { type: new GraphQLNonNull(whereInputType) },\n\t\t\t\t\t\tdata: { type: new GraphQLNonNull(updateInputType) },\n\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t\t}\n\t\t\t: undefined\n\n\t\tconst upsertInput = updateInputType && createInputType && whereInputType\n\t\t\t? {\n\t\t\t\ttype: new GraphQLInputObjectType({\n\t\t\t\t\tname: GqlTypeName`${entity.name}Upsert${relation.name}RelationInput`,\n\t\t\t\t\tfields: () => ({\n\t\t\t\t\t\tby: { type: new GraphQLNonNull(whereInputType) },\n\t\t\t\t\t\tupdate: { type: new GraphQLNonNull(updateInputType) },\n\t\t\t\t\t\tcreate: { type: new GraphQLNonNull(createInputType) },\n\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t\t}\n\t\t\t: undefined\n\n\t\tconst connectOrCreateInput = createInput && whereInputType\n\t\t\t? { type: this.connectOrCreateRelationInputProvider.getInput(entity.name, relation.name) }\n\t\t\t: undefined\n\n\t\tconst fields = {\n\t\t\t[Input.UpdateRelationOperation.create]: createInput,\n\t\t\t[Input.UpdateRelationOperation.update]: updateSpecifiedInput,\n\t\t\t[Input.UpdateRelationOperation.upsert]: upsertInput,\n\t\t\t[Input.UpdateRelationOperation.connect]: whereInput,\n\t\t\t[Input.UpdateRelationOperation.connectOrCreate]: connectOrCreateInput,\n\t\t\t[Input.UpdateRelationOperation.disconnect]: whereInput,\n\t\t\t[Input.UpdateRelationOperation.delete]: whereInput,\n\t\t}\n\n\t\tconst filteredFields = this.filterAllowedOperations(entity, relation, fields)\n\t\tif (Object.keys(filteredFields).length === 0) {\n\t\t\treturn undefined\n\t\t}\n\n\t\treturn new GraphQLInputObjectType({\n\t\t\tname: GqlTypeName`${entity.name}Update${relation.name}EntityRelationInput`,\n\t\t\tfields: () => ({\n\t\t\t\t...filteredFields,\n\t\t\t\talias: { type: GraphQLString },\n\t\t\t}),\n\t\t})\n\t}\n\n\tprivate filterAllowedOperations(\n\t\tentity: Model.Entity,\n\t\trelation: Model.Relation,\n\t\tgraphQlFields: { [key: string]: GraphQLInputFieldConfig | undefined },\n\t): GraphQLInputFieldConfigMap {\n\t\tconst allowedOperations = acceptFieldVisitor(\n\t\t\tthis.schema,\n\t\t\tentity,\n\t\t\trelation.name,\n\t\t\tthis.updateEntityRelationAllowedOperationsVisitor,\n\t\t)\n\t\treturn filterObject(\n\t\t\tgraphQlFields,\n\t\t\t(key, value): value is GraphQLInputFieldConfig =>\n\t\t\t\tallowedOperations.includes(key as Input.UpdateRelationOperation) && value !== undefined,\n\t\t)\n\t}\n\n\tprivate createUniqueWhereInput(targetEntity: Model.Entity): GraphQLInputObjectType | undefined {\n\t\tif (this.authorizator.getEntityPermission(Acl.Operation.read, targetEntity.name) === 'no') {\n\t\t\treturn undefined\n\t\t}\n\t\tconst uniqueWhere = this.whereTypeBuilder.getEntityUniqueWhereType(targetEntity.name)\n\t\tif (!uniqueWhere) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\treturn uniqueWhere\n\t}\n}\n"],"names":[],"mappings":";;;;;;AAkBO,MAAM,sCAC2D;AAAA,EAEvE,YACkB,QACA,cACA,kBACA,mCACA,2BACA,8CACA,sCAChB;AAPgB,SAAA,SAAA;AACA,SAAA,eAAA;AACA,SAAA,mBAAA;AACA,SAAA,oCAAA;AACA,SAAA,4BAAA;AACA,SAAA,+CAAA;AACA,SAAA,uCAAA;AAAA,EAElB;A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;AACA,UAAM,cAAc,KAAK,iBAAiB,yBAAyB,aAAa,IAAI;AACpF,QAAI,CAAC,aAAa;AACjB,YAAM,IAAI,wBAAwB;AAAA,IACnC;AACO,WAAA;AAAA,EACR;AACD;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connectOrCreate.test.d.ts","sourceRoot":"","sources":["../../../../../../../tests/cases/integration/graphQlRequests/update/manyHasManyOwning/connectOrCreate.test.ts"],"names":[],"mappings":""}
|
package/dist/tests/cases/integration/graphQlRequests/update/oneHasMany/connectOrCreate.test.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connectOrCreate.test.d.ts","sourceRoot":"","sources":["../../../../../../../tests/cases/integration/graphQlRequests/update/oneHasMany/connectOrCreate.test.ts"],"names":[],"mappings":""}
|