@contember/engine-content-api 2.1.0-alpha.1 → 2.1.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/development/index.cjs +1 -0
- package/dist/development/index.cjs.map +1 -1
- package/dist/development/index.js +1 -0
- package/dist/development/index.js.map +1 -1
- package/dist/development/src/ExecutionContainer.cjs +5 -3
- package/dist/development/src/ExecutionContainer.cjs.map +1 -1
- package/dist/development/src/ExecutionContainer.js +5 -3
- package/dist/development/src/ExecutionContainer.js.map +1 -1
- package/dist/development/src/acl/Authorizator.cjs +5 -1
- package/dist/development/src/acl/Authorizator.cjs.map +1 -1
- package/dist/development/src/acl/Authorizator.js +5 -1
- package/dist/development/src/acl/Authorizator.js.map +1 -1
- package/dist/development/src/input-validation/dependencies/DependencyCollector.cjs +3 -0
- package/dist/development/src/input-validation/dependencies/DependencyCollector.cjs.map +1 -1
- package/dist/development/src/input-validation/dependencies/DependencyCollector.js +3 -0
- package/dist/development/src/input-validation/dependencies/DependencyCollector.js.map +1 -1
- package/dist/development/src/mapper/Mapper.cjs +1 -0
- package/dist/development/src/mapper/Mapper.cjs.map +1 -1
- package/dist/development/src/mapper/Mapper.js +1 -0
- package/dist/development/src/mapper/Mapper.js.map +1 -1
- package/dist/development/src/mapper/select/handlers/FieldsVisitor.cjs +30 -3
- package/dist/development/src/mapper/select/handlers/FieldsVisitor.cjs.map +1 -1
- package/dist/development/src/mapper/select/handlers/FieldsVisitor.js +30 -3
- package/dist/development/src/mapper/select/handlers/FieldsVisitor.js.map +1 -1
- package/dist/development/src/mapper/select/handlers/FieldsVisitorFactory.cjs +6 -2
- package/dist/development/src/mapper/select/handlers/FieldsVisitorFactory.cjs.map +1 -1
- package/dist/development/src/mapper/select/handlers/FieldsVisitorFactory.js +6 -2
- package/dist/development/src/mapper/select/handlers/FieldsVisitorFactory.js.map +1 -1
- package/dist/development/src/resolvers/MutationResolver.cjs +1 -0
- package/dist/development/src/resolvers/MutationResolver.cjs.map +1 -1
- package/dist/development/src/resolvers/MutationResolver.js +1 -0
- package/dist/development/src/resolvers/MutationResolver.js.map +1 -1
- package/dist/development/src/resolvers/RefreshViewResolver.cjs +20 -0
- package/dist/development/src/resolvers/RefreshViewResolver.cjs.map +1 -0
- package/dist/development/src/resolvers/RefreshViewResolver.js +20 -0
- package/dist/development/src/resolvers/RefreshViewResolver.js.map +1 -0
- package/dist/development/src/schema/GraphQlSchemaBuilder.cjs +6 -1
- package/dist/development/src/schema/GraphQlSchemaBuilder.cjs.map +1 -1
- package/dist/development/src/schema/GraphQlSchemaBuilder.js +6 -1
- package/dist/development/src/schema/GraphQlSchemaBuilder.js.map +1 -1
- package/dist/development/src/schema/GraphQlSchemaBuilderFactory.cjs +2 -1
- package/dist/development/src/schema/GraphQlSchemaBuilderFactory.cjs.map +1 -1
- package/dist/development/src/schema/GraphQlSchemaBuilderFactory.js +2 -1
- package/dist/development/src/schema/GraphQlSchemaBuilderFactory.js.map +1 -1
- package/dist/development/src/schema/RefreshViewMutationProvider.cjs +35 -0
- package/dist/development/src/schema/RefreshViewMutationProvider.cjs.map +1 -0
- package/dist/development/src/schema/RefreshViewMutationProvider.js +35 -0
- package/dist/development/src/schema/RefreshViewMutationProvider.js.map +1 -0
- package/dist/development/src/utils/viewComputedId.cjs +16 -0
- package/dist/development/src/utils/viewComputedId.cjs.map +1 -0
- package/dist/development/src/utils/viewComputedId.js +16 -0
- package/dist/development/src/utils/viewComputedId.js.map +1 -0
- package/dist/production/index.cjs +1 -0
- package/dist/production/index.cjs.map +1 -1
- package/dist/production/index.js +1 -0
- package/dist/production/index.js.map +1 -1
- package/dist/production/src/ExecutionContainer.cjs +5 -3
- package/dist/production/src/ExecutionContainer.cjs.map +1 -1
- package/dist/production/src/ExecutionContainer.js +5 -3
- package/dist/production/src/ExecutionContainer.js.map +1 -1
- package/dist/production/src/acl/Authorizator.cjs +5 -1
- package/dist/production/src/acl/Authorizator.cjs.map +1 -1
- package/dist/production/src/acl/Authorizator.js +5 -1
- package/dist/production/src/acl/Authorizator.js.map +1 -1
- package/dist/production/src/input-validation/dependencies/DependencyCollector.cjs +3 -0
- package/dist/production/src/input-validation/dependencies/DependencyCollector.cjs.map +1 -1
- package/dist/production/src/input-validation/dependencies/DependencyCollector.js +3 -0
- package/dist/production/src/input-validation/dependencies/DependencyCollector.js.map +1 -1
- package/dist/production/src/mapper/Mapper.cjs +1 -0
- package/dist/production/src/mapper/Mapper.cjs.map +1 -1
- package/dist/production/src/mapper/Mapper.js +1 -0
- package/dist/production/src/mapper/Mapper.js.map +1 -1
- package/dist/production/src/mapper/select/handlers/FieldsVisitor.cjs +30 -3
- package/dist/production/src/mapper/select/handlers/FieldsVisitor.cjs.map +1 -1
- package/dist/production/src/mapper/select/handlers/FieldsVisitor.js +30 -3
- package/dist/production/src/mapper/select/handlers/FieldsVisitor.js.map +1 -1
- package/dist/production/src/mapper/select/handlers/FieldsVisitorFactory.cjs +6 -2
- package/dist/production/src/mapper/select/handlers/FieldsVisitorFactory.cjs.map +1 -1
- package/dist/production/src/mapper/select/handlers/FieldsVisitorFactory.js +6 -2
- package/dist/production/src/mapper/select/handlers/FieldsVisitorFactory.js.map +1 -1
- package/dist/production/src/resolvers/MutationResolver.cjs +1 -0
- package/dist/production/src/resolvers/MutationResolver.cjs.map +1 -1
- package/dist/production/src/resolvers/MutationResolver.js +1 -0
- package/dist/production/src/resolvers/MutationResolver.js.map +1 -1
- package/dist/production/src/resolvers/RefreshViewResolver.cjs +20 -0
- package/dist/production/src/resolvers/RefreshViewResolver.cjs.map +1 -0
- package/dist/production/src/resolvers/RefreshViewResolver.js +20 -0
- package/dist/production/src/resolvers/RefreshViewResolver.js.map +1 -0
- package/dist/production/src/schema/GraphQlSchemaBuilder.cjs +6 -1
- package/dist/production/src/schema/GraphQlSchemaBuilder.cjs.map +1 -1
- package/dist/production/src/schema/GraphQlSchemaBuilder.js +6 -1
- package/dist/production/src/schema/GraphQlSchemaBuilder.js.map +1 -1
- package/dist/production/src/schema/GraphQlSchemaBuilderFactory.cjs +2 -1
- package/dist/production/src/schema/GraphQlSchemaBuilderFactory.cjs.map +1 -1
- package/dist/production/src/schema/GraphQlSchemaBuilderFactory.js +2 -1
- package/dist/production/src/schema/GraphQlSchemaBuilderFactory.js.map +1 -1
- package/dist/production/src/schema/RefreshViewMutationProvider.cjs +35 -0
- package/dist/production/src/schema/RefreshViewMutationProvider.cjs.map +1 -0
- package/dist/production/src/schema/RefreshViewMutationProvider.js +35 -0
- package/dist/production/src/schema/RefreshViewMutationProvider.js.map +1 -0
- package/dist/production/src/utils/viewComputedId.cjs +16 -0
- package/dist/production/src/utils/viewComputedId.cjs.map +1 -0
- package/dist/production/src/utils/viewComputedId.js +16 -0
- package/dist/production/src/utils/viewComputedId.js.map +1 -0
- package/dist/tests/cases/integration/graphQlRequests/validation/utils.d.ts.map +1 -1
- package/dist/tests/src/tags.d.ts.map +1 -1
- package/dist/tests/src/test.d.ts.map +1 -1
- package/dist/tests/src/testGraphql.d.ts.map +1 -1
- package/dist/tests/src/testUuid.d.ts.map +1 -1
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/dist/types/ExecutionContainer.d.ts +8 -2
- package/dist/types/ExecutionContainer.d.ts.map +1 -1
- package/dist/types/acl/Authorizator.d.ts +3 -1
- package/dist/types/acl/Authorizator.d.ts.map +1 -1
- package/dist/types/acl/VariableUtils.d.ts.map +1 -1
- package/dist/types/input-validation/ValidationContext.d.ts.map +1 -1
- package/dist/types/input-validation/ValidationEvaluation.d.ts.map +1 -1
- package/dist/types/input-validation/ValidationPath.d.ts.map +1 -1
- package/dist/types/introspection/introspection.schema.d.ts.map +1 -1
- package/dist/types/mapper/ColumnValue.d.ts.map +1 -1
- package/dist/types/mapper/ErrorUtils.d.ts.map +1 -1
- package/dist/types/mapper/EventManager.d.ts.map +1 -1
- package/dist/types/mapper/MutationProcessorHelper.d.ts.map +1 -1
- package/dist/types/mapper/Result.d.ts.map +1 -1
- package/dist/types/mapper/delete/helpers.d.ts.map +1 -1
- package/dist/types/mapper/select/handlers/FieldsVisitor.d.ts +4 -1
- package/dist/types/mapper/select/handlers/FieldsVisitor.d.ts.map +1 -1
- package/dist/types/mapper/select/handlers/FieldsVisitorFactory.d.ts +5 -2
- package/dist/types/mapper/select/handlers/FieldsVisitorFactory.d.ts.map +1 -1
- package/dist/types/mapper/select/optimizer/WhereReplacer.d.ts.map +1 -1
- package/dist/types/mapper/select/optimizer/helpers.d.ts.map +1 -1
- package/dist/types/resolvers/ReadHelpers.d.ts.map +1 -1
- package/dist/types/resolvers/RefreshViewResolver.d.ts +11 -0
- package/dist/types/resolvers/RefreshViewResolver.d.ts.map +1 -0
- package/dist/types/schema/GraphQlSchemaBuilder.d.ts +3 -1
- package/dist/types/schema/GraphQlSchemaBuilder.d.ts.map +1 -1
- package/dist/types/schema/GraphQlSchemaBuilderFactory.d.ts +3 -0
- package/dist/types/schema/GraphQlSchemaBuilderFactory.d.ts.map +1 -1
- package/dist/types/schema/OperationExtension.d.ts.map +1 -1
- package/dist/types/schema/RefreshViewMutationProvider.d.ts +11 -0
- package/dist/types/schema/RefreshViewMutationProvider.d.ts.map +1 -0
- package/dist/types/schema/utils.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/dist/types/utils/isIt.d.ts.map +1 -1
- package/dist/types/utils/paginationUtils.d.ts.map +1 -1
- package/dist/types/utils/promises.d.ts.map +1 -1
- package/dist/types/utils/singletonFactory.d.ts.map +1 -1
- package/dist/types/utils/strings.d.ts.map +1 -1
- package/dist/types/utils/tuple.d.ts.map +1 -1
- package/dist/types/utils/uniqueWhereFields.d.ts.map +1 -1
- package/dist/types/utils/viewComputedId.d.ts +2 -0
- package/dist/types/utils/viewComputedId.d.ts.map +1 -0
- package/package.json +11 -11
- package/src/ExecutionContainer.ts +8 -4
- package/src/acl/Authorizator.ts +5 -0
- package/src/mapper/select/handlers/FieldsVisitor.ts +33 -1
- package/src/mapper/select/handlers/FieldsVisitorFactory.ts +6 -1
- package/src/resolvers/RefreshViewResolver.ts +23 -0
- package/src/schema/GraphQlSchemaBuilder.ts +8 -0
- package/src/schema/GraphQlSchemaBuilderFactory.ts +5 -2
- package/src/schema/RefreshViewMutationProvider.ts +40 -0
- package/src/utils/viewComputedId.ts +23 -0
- package/tests/cases/integration/graphQlSchema/graphQlSchemaBuilder.test.ts +1 -1
- package/tests/src/test.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DependencyCollector.cjs","sources":["../../../../../../packages/engine-content-api/src/input-validation/dependencies/DependencyCollector.ts"],"sourcesContent":["import { Validation } from '@contember/schema'\nimport { assertNever } from '../../utils'\nimport { InputValidation } from '@contember/schema-definition'\n\nexport class DependencyCollector {\n\tpublic static collect(validator: Validation.Validator): Dependencies {\n\t\tconst dependenciesList = DependencyCollector.doCollect(validator, [])\n\t\treturn dependenciesList.reduce((acc, deps) => this.withDependency(acc, deps), {})\n\t}\n\n\tprivate static withDependency(object: Dependencies, dependency: string[]): Dependencies {\n\t\tconst part = dependency.shift()\n\t\tif (!part) {\n\t\t\treturn object\n\t\t}\n\n\t\treturn {\n\t\t\t...object,\n\t\t\t[part]: this.withDependency(object[part] || {}, [...dependency]),\n\t\t}\n\t}\n\n\tprivate static doCollect(validator: Validation.Validator, prefix: string[]): DependenciesList {\n\t\tif (validator.operation === InputValidation.InContextOperation) {\n\t\t\tconst [pathArg, validatorArg] = validator.args\n\t\t\tconst newPrefix = [...prefix, ...pathArg.path]\n\t\t\tconst dependencies = DependencyCollector.doCollect(validatorArg.validator, newPrefix)\n\n\t\t\treturn [newPrefix, ...dependencies]\n\t\t}\n\n\t\tconst result: DependenciesList = []\n\t\tfor (const arg of validator.args) {\n\t\t\tswitch (arg.type) {\n\t\t\t\t//case Validation.ArgumentType.path:\n\t\t\t\t//\tresult.push([...prefix, ...arg.path])\n\t\t\t\t//\tbreak\n\t\t\t\tcase Validation.ArgumentType.validator:\n\t\t\t\t\tresult.push(...DependencyCollector.doCollect(arg.validator, prefix))\n\t\t\t\t\tbreak\n\t\t\t\tcase Validation.ArgumentType.literal:\n\t\t\t\t\tbreak\n\t\t\t\tdefault:\n\t\t\t\t\tassertNever(arg)\n\t\t\t}\n\t\t}\n\t\treturn result\n\t}\n}\n\nexport type DependenciesList = string[][]\n\nexport interface Dependencies {\n\t[field: string]: Dependencies\n}\n"],"names":["InputValidation","Validation","assertNever"],"mappings":";;;;;;AAIO,MAAM,oBAAoB;AAAA,EAChC,OAAc,QAAQ,WAA+C;AACpE,UAAM,mBAAmB,oBAAoB,UAAU,WAAW,CAAA,CAAE;AAC7D,WAAA,iBAAiB,OAAO,CAAC,KAAK,SAAS,KAAK,eAAe,KAAK,IAAI,GAAG,EAAE;AAAA,EAAA;AAAA,EAGjF,OAAe,eAAe,QAAsB,YAAoC;AACjF,UAAA,OAAO,WAAW,MAAM;AAC9B,QAAI,CAAC,MAAM;AACH,aAAA;AAAA,IAAA;AAGD,WAAA;AAAA,MACN,GAAG;AAAA,MACH,CAAC,IAAI,GAAG,KAAK,eAAe,OAAO,IAAI,KAAK,CAAA,GAAI,CAAC,GAAG,UAAU,CAAC;AAAA,IAChE;AAAA,EAAA;AAAA,EAGD,OAAe,UAAU,WAAiC,QAAoC;AACzF,QAAA,UAAU,cAAcA,iBAAA,gBAAgB,oBAAoB;AAC/D,YAAM,CAAC,SAAS,YAAY,IAAI,UAAU;AAC1C,YAAM,YAAY,CAAC,GAAG,QAAQ,GAAG,QAAQ,IAAI;AAC7C,YAAM,eAAe,oBAAoB,UAAU,aAAa,WAAW,SAAS;AAE7E,aAAA,CAAC,WAAW,GAAG,YAAY;AAAA,IAAA;AAGnC,UAAM,SAA2B,CAAC;AACvB,eAAA,OAAO,UAAU,MAAM;AACjC,cAAQ,IAAI,MAAM;AAAA,QAIjB,KAAKC,OAAAA,WAAW,aAAa;AAC5B,iBAAO,KAAK,GAAG,oBAAoB,UAAU,IAAI,WAAW,MAAM,CAAC;AACnE;AAAA,QACD,KAAKA,OAAAA,WAAW,aAAa;AAC5B;AAAA,QACD;AACCC,sBAAAA,YAAe;AAAA,MAAA;AAAA,IACjB;AAEM,WAAA;AAAA,EAAA;AAET;;"}
|
|
1
|
+
{"version":3,"file":"DependencyCollector.cjs","sources":["../../../../../../packages/engine-content-api/src/input-validation/dependencies/DependencyCollector.ts"],"sourcesContent":["import { Validation } from '@contember/schema'\nimport { assertNever } from '../../utils'\nimport { InputValidation } from '@contember/schema-definition'\n\nexport class DependencyCollector {\n\tpublic static collect(validator: Validation.Validator): Dependencies {\n\t\tconst dependenciesList = DependencyCollector.doCollect(validator, [])\n\t\treturn dependenciesList.reduce((acc, deps) => this.withDependency(acc, deps), {})\n\t}\n\n\tprivate static withDependency(object: Dependencies, dependency: string[]): Dependencies {\n\t\tconst part = dependency.shift()\n\t\tif (!part) {\n\t\t\treturn object\n\t\t}\n\n\t\treturn {\n\t\t\t...object,\n\t\t\t[part]: this.withDependency(object[part] || {}, [...dependency]),\n\t\t}\n\t}\n\n\tprivate static doCollect(validator: Validation.Validator, prefix: string[]): DependenciesList {\n\t\tif (validator.operation === InputValidation.InContextOperation) {\n\t\t\tconst [pathArg, validatorArg] = validator.args\n\t\t\tconst newPrefix = [...prefix, ...pathArg.path]\n\t\t\tconst dependencies = DependencyCollector.doCollect(validatorArg.validator, newPrefix)\n\n\t\t\treturn [newPrefix, ...dependencies]\n\t\t}\n\n\t\tconst result: DependenciesList = []\n\t\tfor (const arg of validator.args) {\n\t\t\tswitch (arg.type) {\n\t\t\t\t//case Validation.ArgumentType.path:\n\t\t\t\t//\tresult.push([...prefix, ...arg.path])\n\t\t\t\t//\tbreak\n\t\t\t\tcase Validation.ArgumentType.validator:\n\t\t\t\t\tresult.push(...DependencyCollector.doCollect(arg.validator, prefix))\n\t\t\t\t\tbreak\n\t\t\t\tcase Validation.ArgumentType.literal:\n\t\t\t\t\tbreak\n\t\t\t\tdefault:\n\t\t\t\t\tassertNever(arg)\n\t\t\t}\n\t\t}\n\t\treturn result\n\t}\n}\n\nexport type DependenciesList = string[][]\n\nexport interface Dependencies {\n\t[field: string]: Dependencies\n}\n"],"names":["InputValidation","Validation","assertNever"],"mappings":";;;;;;AAIO,MAAM,oBAAoB;AAAA,EAChC,OAAc,QAAQ,WAA+C;AACpE,UAAM,mBAAmB,oBAAoB,UAAU,WAAW,CAAA,CAAE;AAC7D,WAAA,iBAAiB,OAAO,CAAC,KAAK,SAAS,KAAK,eAAe,KAAK,IAAI,GAAG,EAAE;AAAA,EAAA;AAAA,EAGjF,OAAe,eAAe,QAAsB,YAAoC;AACjF,UAAA,OAAO,WAAW,MAAM;AAC9B,QAAI,CAAC,MAAM;AACH,aAAA;AAAA,IAAA;AAGD,WAAA;AAAA,MACN,GAAG;AAAA,MACH,CAAC,IAAI,GAAG,KAAK,eAAe,OAAO,IAAI,KAAK,CAAA,GAAI,CAAC,GAAG,UAAU,CAAC;AAAA,IAChE;AAAA,EAAA;AAAA,EAGD,OAAe,UAAU,WAAiC,QAAoC;AACzF,QAAA,UAAU,cAAcA,iBAAA,gBAAgB,oBAAoB;AAC/D,YAAM,CAAC,SAAS,YAAY,IAAI,UAAU;AAC1C,YAAM,YAAY,CAAC,GAAG,QAAQ,GAAG,QAAQ,IAAI;AAC7C,YAAM,eAAe,oBAAoB,UAAU,aAAa,WAAW,SAAS;AAE7E,aAAA,CAAC,WAAW,GAAG,YAAY;AAAA,IAAA;AAGnC,UAAM,SAA2B,CAAC;AACvB,eAAA,OAAO,UAAU,MAAM;AACjC,cAAQ,IAAI,MAAM;AAAA;AAAA;AAAA;AAAA,QAIjB,KAAKC,OAAAA,WAAW,aAAa;AAC5B,iBAAO,KAAK,GAAG,oBAAoB,UAAU,IAAI,WAAW,MAAM,CAAC;AACnE;AAAA,QACD,KAAKA,OAAAA,WAAW,aAAa;AAC5B;AAAA,QACD;AACCC,sBAAAA,YAAe;AAAA,MAAA;AAAA,IACjB;AAEM,WAAA;AAAA,EAAA;AAET;;"}
|
|
@@ -27,6 +27,9 @@ class DependencyCollector {
|
|
|
27
27
|
const result = [];
|
|
28
28
|
for (const arg of validator.args) {
|
|
29
29
|
switch (arg.type) {
|
|
30
|
+
//case Validation.ArgumentType.path:
|
|
31
|
+
// result.push([...prefix, ...arg.path])
|
|
32
|
+
// break
|
|
30
33
|
case Validation.ArgumentType.validator:
|
|
31
34
|
result.push(...DependencyCollector.doCollect(arg.validator, prefix));
|
|
32
35
|
break;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DependencyCollector.js","sources":["../../../../../../packages/engine-content-api/src/input-validation/dependencies/DependencyCollector.ts"],"sourcesContent":["import { Validation } from '@contember/schema'\nimport { assertNever } from '../../utils'\nimport { InputValidation } from '@contember/schema-definition'\n\nexport class DependencyCollector {\n\tpublic static collect(validator: Validation.Validator): Dependencies {\n\t\tconst dependenciesList = DependencyCollector.doCollect(validator, [])\n\t\treturn dependenciesList.reduce((acc, deps) => this.withDependency(acc, deps), {})\n\t}\n\n\tprivate static withDependency(object: Dependencies, dependency: string[]): Dependencies {\n\t\tconst part = dependency.shift()\n\t\tif (!part) {\n\t\t\treturn object\n\t\t}\n\n\t\treturn {\n\t\t\t...object,\n\t\t\t[part]: this.withDependency(object[part] || {}, [...dependency]),\n\t\t}\n\t}\n\n\tprivate static doCollect(validator: Validation.Validator, prefix: string[]): DependenciesList {\n\t\tif (validator.operation === InputValidation.InContextOperation) {\n\t\t\tconst [pathArg, validatorArg] = validator.args\n\t\t\tconst newPrefix = [...prefix, ...pathArg.path]\n\t\t\tconst dependencies = DependencyCollector.doCollect(validatorArg.validator, newPrefix)\n\n\t\t\treturn [newPrefix, ...dependencies]\n\t\t}\n\n\t\tconst result: DependenciesList = []\n\t\tfor (const arg of validator.args) {\n\t\t\tswitch (arg.type) {\n\t\t\t\t//case Validation.ArgumentType.path:\n\t\t\t\t//\tresult.push([...prefix, ...arg.path])\n\t\t\t\t//\tbreak\n\t\t\t\tcase Validation.ArgumentType.validator:\n\t\t\t\t\tresult.push(...DependencyCollector.doCollect(arg.validator, prefix))\n\t\t\t\t\tbreak\n\t\t\t\tcase Validation.ArgumentType.literal:\n\t\t\t\t\tbreak\n\t\t\t\tdefault:\n\t\t\t\t\tassertNever(arg)\n\t\t\t}\n\t\t}\n\t\treturn result\n\t}\n}\n\nexport type DependenciesList = string[][]\n\nexport interface Dependencies {\n\t[field: string]: Dependencies\n}\n"],"names":[],"mappings":";;;;AAIO,MAAM,oBAAoB;AAAA,EAChC,OAAc,QAAQ,WAA+C;AACpE,UAAM,mBAAmB,oBAAoB,UAAU,WAAW,CAAA,CAAE;AAC7D,WAAA,iBAAiB,OAAO,CAAC,KAAK,SAAS,KAAK,eAAe,KAAK,IAAI,GAAG,EAAE;AAAA,EAAA;AAAA,EAGjF,OAAe,eAAe,QAAsB,YAAoC;AACjF,UAAA,OAAO,WAAW,MAAM;AAC9B,QAAI,CAAC,MAAM;AACH,aAAA;AAAA,IAAA;AAGD,WAAA;AAAA,MACN,GAAG;AAAA,MACH,CAAC,IAAI,GAAG,KAAK,eAAe,OAAO,IAAI,KAAK,CAAA,GAAI,CAAC,GAAG,UAAU,CAAC;AAAA,IAChE;AAAA,EAAA;AAAA,EAGD,OAAe,UAAU,WAAiC,QAAoC;AACzF,QAAA,UAAU,cAAc,gBAAgB,oBAAoB;AAC/D,YAAM,CAAC,SAAS,YAAY,IAAI,UAAU;AAC1C,YAAM,YAAY,CAAC,GAAG,QAAQ,GAAG,QAAQ,IAAI;AAC7C,YAAM,eAAe,oBAAoB,UAAU,aAAa,WAAW,SAAS;AAE7E,aAAA,CAAC,WAAW,GAAG,YAAY;AAAA,IAAA;AAGnC,UAAM,SAA2B,CAAC;AACvB,eAAA,OAAO,UAAU,MAAM;AACjC,cAAQ,IAAI,MAAM;AAAA,QAIjB,KAAK,WAAW,aAAa;AAC5B,iBAAO,KAAK,GAAG,oBAAoB,UAAU,IAAI,WAAW,MAAM,CAAC;AACnE;AAAA,QACD,KAAK,WAAW,aAAa;AAC5B;AAAA,QACD;AACC,sBAAe;AAAA,MAAA;AAAA,IACjB;AAEM,WAAA;AAAA,EAAA;AAET;"}
|
|
1
|
+
{"version":3,"file":"DependencyCollector.js","sources":["../../../../../../packages/engine-content-api/src/input-validation/dependencies/DependencyCollector.ts"],"sourcesContent":["import { Validation } from '@contember/schema'\nimport { assertNever } from '../../utils'\nimport { InputValidation } from '@contember/schema-definition'\n\nexport class DependencyCollector {\n\tpublic static collect(validator: Validation.Validator): Dependencies {\n\t\tconst dependenciesList = DependencyCollector.doCollect(validator, [])\n\t\treturn dependenciesList.reduce((acc, deps) => this.withDependency(acc, deps), {})\n\t}\n\n\tprivate static withDependency(object: Dependencies, dependency: string[]): Dependencies {\n\t\tconst part = dependency.shift()\n\t\tif (!part) {\n\t\t\treturn object\n\t\t}\n\n\t\treturn {\n\t\t\t...object,\n\t\t\t[part]: this.withDependency(object[part] || {}, [...dependency]),\n\t\t}\n\t}\n\n\tprivate static doCollect(validator: Validation.Validator, prefix: string[]): DependenciesList {\n\t\tif (validator.operation === InputValidation.InContextOperation) {\n\t\t\tconst [pathArg, validatorArg] = validator.args\n\t\t\tconst newPrefix = [...prefix, ...pathArg.path]\n\t\t\tconst dependencies = DependencyCollector.doCollect(validatorArg.validator, newPrefix)\n\n\t\t\treturn [newPrefix, ...dependencies]\n\t\t}\n\n\t\tconst result: DependenciesList = []\n\t\tfor (const arg of validator.args) {\n\t\t\tswitch (arg.type) {\n\t\t\t\t//case Validation.ArgumentType.path:\n\t\t\t\t//\tresult.push([...prefix, ...arg.path])\n\t\t\t\t//\tbreak\n\t\t\t\tcase Validation.ArgumentType.validator:\n\t\t\t\t\tresult.push(...DependencyCollector.doCollect(arg.validator, prefix))\n\t\t\t\t\tbreak\n\t\t\t\tcase Validation.ArgumentType.literal:\n\t\t\t\t\tbreak\n\t\t\t\tdefault:\n\t\t\t\t\tassertNever(arg)\n\t\t\t}\n\t\t}\n\t\treturn result\n\t}\n}\n\nexport type DependenciesList = string[][]\n\nexport interface Dependencies {\n\t[field: string]: Dependencies\n}\n"],"names":[],"mappings":";;;;AAIO,MAAM,oBAAoB;AAAA,EAChC,OAAc,QAAQ,WAA+C;AACpE,UAAM,mBAAmB,oBAAoB,UAAU,WAAW,CAAA,CAAE;AAC7D,WAAA,iBAAiB,OAAO,CAAC,KAAK,SAAS,KAAK,eAAe,KAAK,IAAI,GAAG,EAAE;AAAA,EAAA;AAAA,EAGjF,OAAe,eAAe,QAAsB,YAAoC;AACjF,UAAA,OAAO,WAAW,MAAM;AAC9B,QAAI,CAAC,MAAM;AACH,aAAA;AAAA,IAAA;AAGD,WAAA;AAAA,MACN,GAAG;AAAA,MACH,CAAC,IAAI,GAAG,KAAK,eAAe,OAAO,IAAI,KAAK,CAAA,GAAI,CAAC,GAAG,UAAU,CAAC;AAAA,IAChE;AAAA,EAAA;AAAA,EAGD,OAAe,UAAU,WAAiC,QAAoC;AACzF,QAAA,UAAU,cAAc,gBAAgB,oBAAoB;AAC/D,YAAM,CAAC,SAAS,YAAY,IAAI,UAAU;AAC1C,YAAM,YAAY,CAAC,GAAG,QAAQ,GAAG,QAAQ,IAAI;AAC7C,YAAM,eAAe,oBAAoB,UAAU,aAAa,WAAW,SAAS;AAE7E,aAAA,CAAC,WAAW,GAAG,YAAY;AAAA,IAAA;AAGnC,UAAM,SAA2B,CAAC;AACvB,eAAA,OAAO,UAAU,MAAM;AACjC,cAAQ,IAAI,MAAM;AAAA;AAAA;AAAA;AAAA,QAIjB,KAAK,WAAW,aAAa;AAC5B,iBAAO,KAAK,GAAG,oBAAoB,UAAU,IAAI,WAAW,MAAM,CAAC;AACnE;AAAA,QACD,KAAK,WAAW,aAAa;AAC5B;AAAA,QACD;AACC,sBAAe;AAAA,MAAA;AAAA,IACjB;AAEM,WAAA;AAAA,EAAA;AAET;"}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
3
3
|
const schemaUtils = require("@contember/schema-utils");
|
|
4
4
|
require("@contember/schema");
|
|
5
5
|
const Database = require("@contember/database");
|
|
6
|
+
require("node:crypto");
|
|
6
7
|
const exception = require("../exception.cjs");
|
|
7
8
|
const OrderByHelper = require("./select/OrderByHelper.cjs");
|
|
8
9
|
const Mutex = require("../utils/Mutex.cjs");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Mapper.cjs","sources":["../../../../../packages/engine-content-api/src/mapper/Mapper.ts"],"sourcesContent":["import { Input, Model } from '@contember/schema'\nimport { acceptFieldVisitor, getColumnName } from '@contember/schema-utils'\nimport {\n\tOrderByHelper,\n\tPathFactory,\n\tSelectBuilderFactory,\n\tSelectGroupedObjects,\n\tSelectHydrator,\n\tSelectIndexedResultObjects,\n\tSelectResultObject,\n\tWhereBuilder,\n} from './select'\nimport { Client, Connection, ConstraintHelper, DatabaseMetadata, SelectBuilder } from '@contember/database'\nimport { PredicatesInjector } from '../acl'\nimport { JunctionTableManager } from './JunctionTableManager'\nimport { DeletedEntitiesStorage, DeleteExecutor } from './delete'\nimport { MutationEntryNotFoundError, MutationResultList } from './Result'\nimport { UpdateBuilder, Updater } from './update'\nimport { InsertBuilder, Inserter } from './insert'\nimport { tryMutation } from './ErrorUtils'\nimport { ObjectNode, UniqueWhereExpander } from '../inputProcessing'\nimport { Mutex } from '../utils'\nimport { CheckedPrimary } from './CheckedPrimary'\nimport { ImplementationException } from '../exception'\nimport { EventManager } from './EventManager'\nimport { MapperInput } from './types'\n\nexport class Mapper<ConnectionType extends Connection.ConnectionLike = Connection.ConnectionLike> {\n\tprivate systemVariablesSetupDone: Promise<void> | undefined\n\tpublic readonly deletedEntities = new DeletedEntitiesStorage()\n\tpublic readonly mutex = new Mutex()\n\tpublic readonly constraintHelper: ConstraintHelper\n\n\tpublic readonly eventManager: EventManager\n\n\tconstructor(\n\t\tpublic readonly db: Client<ConnectionType>,\n\t\tpublic readonly identityId: string,\n\t\tpublic readonly transactionId: string,\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly schemaDatabaseMetadata: DatabaseMetadata,\n\t\tprivate readonly predicatesInjector: PredicatesInjector,\n\t\tprivate readonly selectBuilderFactory: SelectBuilderFactory,\n\t\tprivate readonly uniqueWhereExpander: UniqueWhereExpander,\n\t\tprivate readonly whereBuilder: WhereBuilder,\n\t\tprivate readonly junctionTableManager: JunctionTableManager,\n\t\tprivate readonly deleteExecutor: DeleteExecutor,\n\t\tprivate readonly updater: Updater,\n\t\tprivate readonly inserter: Inserter,\n\t\tprivate readonly pathFactory: PathFactory,\n\t) {\n\t\tthis.constraintHelper = new ConstraintHelper(db, this.schemaDatabaseMetadata)\n\t\tthis.eventManager = new EventManager(this)\n\t}\n\n\tpublic async selectField(entity: Model.Entity, where: Input.UniqueWhere | CheckedPrimary, fieldName: string) {\n\t\tconst columnName = getColumnName(this.schema, entity, fieldName)\n\n\t\tconst qb = SelectBuilder.create() //\n\t\t\t.from(entity.tableName, 'root_')\n\t\t\t.select(['root_', columnName])\n\t\tconst expandedWhere = this.uniqueWhereExpander.expand(entity, where)\n\t\tconst withPredicates = this.predicatesInjector.inject(entity, expandedWhere)\n\t\tconst builtQb = this.whereBuilder.build(qb, entity, this.pathFactory.create([]), withPredicates)\n\t\tconst result = await builtQb.getResult(this.db)\n\n\t\treturn result[0] !== undefined ? result[0][columnName] : undefined\n\t}\n\n\tpublic async selectAssoc(\n\t\tentity: Model.Entity,\n\t\tinput: ObjectNode<Input.ListQueryInput>,\n\t\trelationPath: Model.AnyRelationContext[],\n\t\tindexBy: string,\n\t): Promise<SelectIndexedResultObjects> {\n\t\tconst hydrator = new SelectHydrator()\n\t\tconst path = this.pathFactory.create([])\n\t\tconst indexByAlias: string = path.for(indexBy).alias\n\t\tconst qb: SelectBuilder = SelectBuilder.create()\n\t\t\t.select([path.alias, getColumnName(this.schema, entity, indexBy)], indexByAlias)\n\t\tconst rows = await this.selectRows(hydrator, qb, entity, input, relationPath)\n\t\treturn await hydrator.hydrateAll(rows, indexByAlias)\n\t}\n\n\tpublic async select(entity: Model.Entity, input: ObjectNode<Input.ListQueryInput>, relationPath: Model.AnyRelationContext[]): Promise<SelectResultObject[]> {\n\t\tconst hydrator = new SelectHydrator()\n\t\tconst qb: SelectBuilder<SelectBuilder.Result> = SelectBuilder.create()\n\n\t\tconst rows = await this.selectRows(hydrator, qb, entity, input, relationPath)\n\n\t\treturn await hydrator.hydrateAll(rows)\n\t}\n\n\tpublic async selectUnique(\n\t\tentity: Model.Entity,\n\t\tquery: ObjectNode<Input.UniqueQueryInput>,\n\t\trelationPath: Model.AnyRelationContext[],\n\t): Promise<SelectResultObject | null> {\n\t\tconst uniqueWhere = this.uniqueWhereExpander.expand(entity, query.args.by)\n\t\tconst where = query.args.filter ? { and: [uniqueWhere, query.args.filter] } : uniqueWhere\n\t\tconst queryExpanded = query.withArg<Input.ListQueryInput>('filter', where)\n\n\t\tconst rows = await this.select(entity, queryExpanded, relationPath)\n\n\t\treturn rows[0] ?? null\n\t}\n\n\tpublic async selectGrouped(\n\t\tentity: Model.Entity,\n\t\tinput: ObjectNode<Input.ListQueryInput>,\n\t\trelation: Model.JoiningColumnRelation & Model.AnyRelation,\n\t\trelationPath: Model.AnyRelationContext[],\n\t): Promise<SelectGroupedObjects> {\n\t\tconst hydrator = new SelectHydrator()\n\t\tconst path = this.pathFactory.create([])\n\t\tconst groupingKey = '__grouping_key'\n\t\tconst qb: SelectBuilder = SelectBuilder.create()\n\t\t\t.select([path.alias, relation.joiningColumn.columnName], groupingKey)\n\n\t\tconst rows = await this.selectRows(hydrator, qb, entity, input, relationPath, relation.name)\n\n\t\treturn await hydrator.hydrateGroups(rows, groupingKey)\n\t}\n\n\tprivate async selectRows(\n\t\thydrator: SelectHydrator,\n\t\tqb: SelectBuilder<SelectBuilder.Result>,\n\t\tentity: Model.Entity,\n\t\tinput: ObjectNode<Input.ListQueryInput>,\n\t\trelationPath: Model.AnyRelationContext[],\n\t\tgroupBy?: string,\n\t) {\n\t\tconst inputWithOrder = OrderByHelper.appendDefaultOrderBy(entity, input, undefined)\n\t\tconst path = this.pathFactory.create([])\n\t\tconst augmentedBuilder = qb.from(entity.tableName, path.alias).meta('path', [...input.path, input.alias])\n\n\t\tconst selector = this.selectBuilderFactory.create(augmentedBuilder, hydrator, relationPath)\n\t\tconst filterWithPredicates = this.predicatesInjector.inject(entity, inputWithOrder.args.filter || {}, relationPath[relationPath.length - 1])\n\t\tconst inputWithPredicates = inputWithOrder.withArg('filter', filterWithPredicates)\n\t\tselector.select(this, entity, inputWithPredicates, path, groupBy)\n\t\treturn await selector.execute(this.db)\n\t}\n\n\tpublic async count(entity: Model.Entity, filter: Input.OptionalWhere) {\n\t\tconst path = this.pathFactory.create([])\n\t\tconst qb = SelectBuilder.create()\n\t\t\t.from(entity.tableName, path.alias)\n\t\t\t.select(expr => expr.raw('count(*)'), 'row_count')\n\t\tconst withPredicates = this.predicatesInjector.inject(entity, filter)\n\t\tconst qbWithWhere = this.whereBuilder.build(qb, entity, path, withPredicates)\n\t\tconst result = await qbWithWhere.getResult(this.db)\n\t\treturn result[0].row_count\n\t}\n\n\tpublic async countGrouped(\n\t\tentity: Model.Entity,\n\t\tfilter: Input.OptionalWhere,\n\t\trelation: Model.JoiningColumnRelation & Model.Relation,\n\t\trelationPath: Model.AnyRelationContext[],\n\t): Promise<Record<string, number>> {\n\t\tconst path = this.pathFactory.create([])\n\t\tconst qb = SelectBuilder.create()\n\t\t\t.from(entity.tableName, path.alias)\n\t\t\t.select(expr => expr.raw('count(*)'), 'row_count')\n\t\t\t.select([path.alias, relation.joiningColumn.columnName])\n\t\t\t.groupBy([path.alias, relation.joiningColumn.columnName])\n\t\tconst withPredicates = this.predicatesInjector.inject(entity, filter, relationPath[relationPath.length - 1])\n\t\tconst qbWithWhere = this.whereBuilder.build(qb, entity, path, withPredicates, { relationPath })\n\t\tconst rows = await qbWithWhere.getResult(this.db)\n\t\tconst result = new Map<string, number>()\n\t\tfor (const row of rows) {\n\t\t\tresult.set(String(row[relation.joiningColumn.columnName]), Number(row.row_count))\n\t\t}\n\t\treturn Object.fromEntries(result)\n\t}\n\n\tpublic async insert(\n\t\tentity: Model.Entity,\n\t\tdata: MapperInput.CreateDataInput,\n\t\tbuilderCb: (builder: InsertBuilder) => void = () => {},\n\t): Promise<MutationResultList> {\n\t\tif (entity.view) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\tawait this.setupSystemVariables()\n\t\treturn tryMutation(this.schema, this.schemaDatabaseMetadata, () =>\n\t\t\tthis.insertInternal(entity, data, builderCb),\n\t\t)\n\t}\n\n\tpublic async update(\n\t\tentity: Model.Entity,\n\t\tby: Input.UniqueWhere | CheckedPrimary,\n\t\tdata: MapperInput.UpdateDataInput,\n\t\tfilter?: Input.OptionalWhere,\n\t): Promise<MutationResultList> {\n\t\tif (entity.view) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\tawait this.setupSystemVariables()\n\t\treturn tryMutation(this.schema, this.schemaDatabaseMetadata, async () => {\n\t\t\tconst [primaryValue, err] = await this.getPrimaryValue(entity, by)\n\t\t\tif (err) return [err]\n\n\t\t\treturn await this.updater.update(this, entity, primaryValue, data, filter)\n\t\t})\n\t}\n\n\tpublic async updateInternal(\n\t\tentity: Model.Entity,\n\t\tby: Input.UniqueWhere | CheckedPrimary,\n\t\tbuilderCb: (builder: UpdateBuilder) => void,\n\t): Promise<MutationResultList> {\n\t\tif (entity.view) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\tawait this.setupSystemVariables()\n\t\treturn tryMutation(this.schema, this.schemaDatabaseMetadata, async () => {\n\t\t\tconst [primaryValue, err] = await this.getPrimaryValue(entity, by)\n\t\t\tif (err) return [err]\n\n\t\t\treturn await this.updater.updateCb(this, entity, primaryValue, builderCb)\n\t\t})\n\t}\n\tpublic async upsert(\n\t\tentity: Model.Entity,\n\t\tby: Input.UniqueWhere | CheckedPrimary,\n\t\tupdate: MapperInput.UpdateDataInput,\n\t\tcreate: MapperInput.CreateDataInput,\n\t\tfilter?: Input.OptionalWhere,\n\t): Promise<MutationResultList> {\n\t\tif (entity.view) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\tawait this.setupSystemVariables()\n\t\treturn tryMutation(this.schema, this.schemaDatabaseMetadata, async () => {\n\t\t\tconst [primaryValue] = await this.getPrimaryValue(entity, by)\n\t\t\tif (primaryValue === undefined) {\n\t\t\t\treturn await this.insertInternal(entity, create)\n\t\t\t}\n\t\t\treturn await this.updater.update(this, entity, primaryValue, update, filter)\n\t\t})\n\t}\n\n\tprivate insertInternal(entity: Model.Entity, data: MapperInput.CreateDataInput, builderCb: (builder: InsertBuilder) => void = () => {}) {\n\t\treturn this.inserter.insert(this, entity, data, id => {\n\t\t}, builderCb)\n\t}\n\n\tpublic async delete(\n\t\tentity: Model.Entity,\n\t\tby: Input.UniqueWhere | CheckedPrimary,\n\t\tfilter?: Input.OptionalWhere,\n\t): Promise<MutationResultList> {\n\t\tif (entity.view) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\tawait this.setupSystemVariables()\n\t\treturn tryMutation(this.schema, this.schemaDatabaseMetadata, () => {\n\t\t\treturn this.deleteExecutor.execute(this, entity, by, filter)\n\t\t})\n\t}\n\n\tpublic async connectJunction(\n\t\tentity: Model.Entity,\n\t\trelation: Model.ManyHasManyOwningRelation | Model.ManyHasManyInverseRelation,\n\t\tthisPrimary: Input.PrimaryValue,\n\t\totherPrimary: Input.PrimaryValue,\n\t): Promise<MutationResultList> {\n\t\tawait this.setupSystemVariables()\n\t\tconst err = () => {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\treturn await acceptFieldVisitor(this.schema, entity, relation, {\n\t\t\tvisitManyHasManyOwning: ({ entity, relation }) => {\n\t\t\t\treturn this.junctionTableManager.connectJunction(this, entity, relation, thisPrimary, otherPrimary)\n\t\t\t},\n\t\t\tvisitManyHasManyInverse: ({ targetEntity, targetRelation }) => {\n\t\t\t\treturn this.junctionTableManager.connectJunction(this, targetEntity, targetRelation, otherPrimary, thisPrimary)\n\t\t\t},\n\t\t\tvisitColumn: err,\n\t\t\tvisitOneHasMany: err,\n\t\t\tvisitOneHasOneInverse: err,\n\t\t\tvisitOneHasOneOwning: err,\n\t\t\tvisitManyHasOne: err,\n\t\t})\n\t}\n\n\tpublic async disconnectJunction(\n\t\tentity: Model.Entity,\n\t\trelation: Model.ManyHasManyOwningRelation | Model.ManyHasManyInverseRelation,\n\t\tthisPrimary: Input.PrimaryValue,\n\t\totherPrimary: Input.PrimaryValue,\n\t): Promise<MutationResultList> {\n\t\tawait this.setupSystemVariables()\n\t\tconst err = () => {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\treturn await acceptFieldVisitor(this.schema, entity, relation, {\n\t\t\tvisitManyHasManyOwning: ({ entity, relation }) => {\n\t\t\t\treturn this.junctionTableManager.disconnectJunction(this, entity, relation, thisPrimary, otherPrimary)\n\t\t\t},\n\t\t\tvisitManyHasManyInverse: ({ targetEntity, targetRelation }) => {\n\t\t\t\treturn this.junctionTableManager.disconnectJunction(this, targetEntity, targetRelation, otherPrimary, thisPrimary)\n\t\t\t},\n\t\t\tvisitColumn: err,\n\t\t\tvisitOneHasMany: err,\n\t\t\tvisitOneHasOneInverse: err,\n\t\t\tvisitOneHasOneOwning: err,\n\t\t\tvisitManyHasOne: err,\n\t\t})\n\t}\n\n\tpublic async getPrimaryValue(\n\t\tentity: Model.Entity,\n\t\twhere: Input.UniqueWhere | CheckedPrimary,\n\t): Promise<[Input.PrimaryValue, undefined] | [undefined, MutationEntryNotFoundError]> {\n\t\tif (where instanceof CheckedPrimary) {\n\t\t\treturn [where.primaryValue, undefined]\n\t\t}\n\t\tconst result = await this.selectField(entity, where, entity.primary)\n\t\treturn result ? [result, undefined] : [undefined, new MutationEntryNotFoundError([], where)]\n\t}\n\n\tprivate async setupSystemVariables() {\n\t\tthis.systemVariablesSetupDone ??= (async () => {\n\t\t\tawait this.db.query('SELECT set_config(?, ?, false)', ['tenant.identity_id', this.identityId]) // todo rename to system.identity_id\n\t\t\tawait this.db.query('SELECT set_config(?, ?, false)', ['system.transaction_id', this.transactionId])\n\t\t})()\n\t\tawait this.systemVariablesSetupDone\n\t}\n}\n"],"names":["DeletedEntitiesStorage","Mutex","ConstraintHelper","EventManager","getColumnName","SelectBuilder","SelectHydrator","OrderByHelper","ImplementationException","tryMutation","acceptFieldVisitor","entity","relation","CheckedPrimary","MutationEntryNotFoundError"],"mappings":";;;;;;;;;;;;;;;;;AA2BO,MAAM,OAAqF;AAAA,EAQjG,YACiB,IACA,YACA,eACC,QACA,wBACA,oBACA,sBACA,qBACA,cACA,sBACA,gBACA,SACA,UACA,aAChB;AAde,SAAA,KAAA;AACA,SAAA,aAAA;AACA,SAAA,gBAAA;AACC,SAAA,SAAA;AACA,SAAA,yBAAA;AACA,SAAA,qBAAA;AACA,SAAA,uBAAA;AACA,SAAA,sBAAA;AACA,SAAA,eAAA;AACA,SAAA,uBAAA;AACA,SAAA,iBAAA;AACA,SAAA,UAAA;AACA,SAAA,WAAA;AACA,SAAA,cAAA;AArBV,kBAAA,MAAA,0BAAA;AACQ,kBAAA,MAAA,mBAAkB,IAAIA,uBAAuB,uBAAA,CAAA;AAC7C,kBAAA,MAAA,SAAQ,IAAIC,MAAM,MAAA,CAAA;AAClB,kBAAA,MAAA,kBAAA;AAEA,kBAAA,MAAA,cAAA;AAkBf,SAAK,mBAAmB,IAAIC,SAAAA,iBAAiB,IAAI,KAAK,sBAAsB;AACvE,SAAA,eAAe,IAAIC,aAAA,aAAa,IAAI;AAAA,EAAA;AAAA,EAG1C,MAAa,YAAY,QAAsB,OAA2C,WAAmB;AAC5G,UAAM,aAAaC,YAAAA,cAAc,KAAK,QAAQ,QAAQ,SAAS;AAE/D,UAAM,KAAKC,SAAA,cAAc,OAAO,EAC9B,KAAK,OAAO,WAAW,OAAO,EAC9B,OAAO,CAAC,SAAS,UAAU,CAAC;AAC9B,UAAM,gBAAgB,KAAK,oBAAoB,OAAO,QAAQ,KAAK;AACnE,UAAM,iBAAiB,K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AACA,WAAO,MAAME,YAAAA,mBAAmB,KAAK,QAAQ,QAAQ,UAAU;AAAA,MAC9D,wBAAwB,CAAC,EAAE,QAAAC,SAAQ,UAAAC,gBAAe;AACjD,eAAO,KAAK,qBAAqB,mBAAmB,MAAMD,SAAQC,WAAU,aAAa,YAAY;AAAA,MACtG;AAAA,MACA,yBAAyB,CAAC,EAAE,cAAc,qBAAqB;AAC9D,eAAO,KAAK,qBAAqB,mBAAmB,MAAM,cAAc,gBAAgB,cAAc,WAAW;AAAA,MAClH;AAAA,MACA,aAAa;AAAA,MACb,iBAAiB;AAAA,MACjB,uBAAuB;AAAA,MACvB,sBAAsB;AAAA,MACtB,iBAAiB;AAAA,IAAA,CACjB;AAAA,EAAA;AAAA,EAGF,MAAa,gBACZ,QACA,OACqF;AACrF,QAAI,iBAAiBC,eAAAA,gBAAgB;AAC7B,aAAA,CAAC,MAAM,cAAc,MAAS;AAAA,IAAA;AAEtC,UAAM,SAAS,MAAM,KAAK,YAAY,QAAQ,OAAO,OAAO,OAAO;AACnE,WAAO,SAAS,CAAC,QAAQ,MAAS,IAAI,CAAC,QAAW,IAAIC,OAAAA,2BAA2B,CAAI,GAAA,KAAK,CAAC;AAAA,EAAA;AAAA,EAG5F,MAAc,uBAAuB;AAC/B,SAAA,6BAAL,KAAK,4BAA8B,YAAY;AACxC,YAAA,KAAK,GAAG,MAAM,kCAAkC,CAAC,sBAAsB,KAAK,UAAU,CAAC;AACvF,YAAA,KAAK,GAAG,MAAM,kCAAkC,CAAC,yBAAyB,KAAK,aAAa,CAAC;AAAA,IAAA;AAEpG,UAAM,KAAK;AAAA,EAAA;AAEb;;"}
|
|
1
|
+
{"version":3,"file":"Mapper.cjs","sources":["../../../../../packages/engine-content-api/src/mapper/Mapper.ts"],"sourcesContent":["import { Input, Model } from '@contember/schema'\nimport { acceptFieldVisitor, getColumnName } from '@contember/schema-utils'\nimport {\n\tOrderByHelper,\n\tPathFactory,\n\tSelectBuilderFactory,\n\tSelectGroupedObjects,\n\tSelectHydrator,\n\tSelectIndexedResultObjects,\n\tSelectResultObject,\n\tWhereBuilder,\n} from './select'\nimport { Client, Connection, ConstraintHelper, DatabaseMetadata, SelectBuilder } from '@contember/database'\nimport { PredicatesInjector } from '../acl'\nimport { JunctionTableManager } from './JunctionTableManager'\nimport { DeletedEntitiesStorage, DeleteExecutor } from './delete'\nimport { MutationEntryNotFoundError, MutationResultList } from './Result'\nimport { UpdateBuilder, Updater } from './update'\nimport { InsertBuilder, Inserter } from './insert'\nimport { tryMutation } from './ErrorUtils'\nimport { ObjectNode, UniqueWhereExpander } from '../inputProcessing'\nimport { Mutex } from '../utils'\nimport { CheckedPrimary } from './CheckedPrimary'\nimport { ImplementationException } from '../exception'\nimport { EventManager } from './EventManager'\nimport { MapperInput } from './types'\n\nexport class Mapper<ConnectionType extends Connection.ConnectionLike = Connection.ConnectionLike> {\n\tprivate systemVariablesSetupDone: Promise<void> | undefined\n\tpublic readonly deletedEntities = new DeletedEntitiesStorage()\n\tpublic readonly mutex = new Mutex()\n\tpublic readonly constraintHelper: ConstraintHelper\n\n\tpublic readonly eventManager: EventManager\n\n\tconstructor(\n\t\tpublic readonly db: Client<ConnectionType>,\n\t\tpublic readonly identityId: string,\n\t\tpublic readonly transactionId: string,\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly schemaDatabaseMetadata: DatabaseMetadata,\n\t\tprivate readonly predicatesInjector: PredicatesInjector,\n\t\tprivate readonly selectBuilderFactory: SelectBuilderFactory,\n\t\tprivate readonly uniqueWhereExpander: UniqueWhereExpander,\n\t\tprivate readonly whereBuilder: WhereBuilder,\n\t\tprivate readonly junctionTableManager: JunctionTableManager,\n\t\tprivate readonly deleteExecutor: DeleteExecutor,\n\t\tprivate readonly updater: Updater,\n\t\tprivate readonly inserter: Inserter,\n\t\tprivate readonly pathFactory: PathFactory,\n\t) {\n\t\tthis.constraintHelper = new ConstraintHelper(db, this.schemaDatabaseMetadata)\n\t\tthis.eventManager = new EventManager(this)\n\t}\n\n\tpublic async selectField(entity: Model.Entity, where: Input.UniqueWhere | CheckedPrimary, fieldName: string) {\n\t\tconst columnName = getColumnName(this.schema, entity, fieldName)\n\n\t\tconst qb = SelectBuilder.create() //\n\t\t\t.from(entity.tableName, 'root_')\n\t\t\t.select(['root_', columnName])\n\t\tconst expandedWhere = this.uniqueWhereExpander.expand(entity, where)\n\t\tconst withPredicates = this.predicatesInjector.inject(entity, expandedWhere)\n\t\tconst builtQb = this.whereBuilder.build(qb, entity, this.pathFactory.create([]), withPredicates)\n\t\tconst result = await builtQb.getResult(this.db)\n\n\t\treturn result[0] !== undefined ? result[0][columnName] : undefined\n\t}\n\n\tpublic async selectAssoc(\n\t\tentity: Model.Entity,\n\t\tinput: ObjectNode<Input.ListQueryInput>,\n\t\trelationPath: Model.AnyRelationContext[],\n\t\tindexBy: string,\n\t): Promise<SelectIndexedResultObjects> {\n\t\tconst hydrator = new SelectHydrator()\n\t\tconst path = this.pathFactory.create([])\n\t\tconst indexByAlias: string = path.for(indexBy).alias\n\t\tconst qb: SelectBuilder = SelectBuilder.create()\n\t\t\t.select([path.alias, getColumnName(this.schema, entity, indexBy)], indexByAlias)\n\t\tconst rows = await this.selectRows(hydrator, qb, entity, input, relationPath)\n\t\treturn await hydrator.hydrateAll(rows, indexByAlias)\n\t}\n\n\tpublic async select(entity: Model.Entity, input: ObjectNode<Input.ListQueryInput>, relationPath: Model.AnyRelationContext[]): Promise<SelectResultObject[]> {\n\t\tconst hydrator = new SelectHydrator()\n\t\tconst qb: SelectBuilder<SelectBuilder.Result> = SelectBuilder.create()\n\n\t\tconst rows = await this.selectRows(hydrator, qb, entity, input, relationPath)\n\n\t\treturn await hydrator.hydrateAll(rows)\n\t}\n\n\tpublic async selectUnique(\n\t\tentity: Model.Entity,\n\t\tquery: ObjectNode<Input.UniqueQueryInput>,\n\t\trelationPath: Model.AnyRelationContext[],\n\t): Promise<SelectResultObject | null> {\n\t\tconst uniqueWhere = this.uniqueWhereExpander.expand(entity, query.args.by)\n\t\tconst where = query.args.filter ? { and: [uniqueWhere, query.args.filter] } : uniqueWhere\n\t\tconst queryExpanded = query.withArg<Input.ListQueryInput>('filter', where)\n\n\t\tconst rows = await this.select(entity, queryExpanded, relationPath)\n\n\t\treturn rows[0] ?? null\n\t}\n\n\tpublic async selectGrouped(\n\t\tentity: Model.Entity,\n\t\tinput: ObjectNode<Input.ListQueryInput>,\n\t\trelation: Model.JoiningColumnRelation & Model.AnyRelation,\n\t\trelationPath: Model.AnyRelationContext[],\n\t): Promise<SelectGroupedObjects> {\n\t\tconst hydrator = new SelectHydrator()\n\t\tconst path = this.pathFactory.create([])\n\t\tconst groupingKey = '__grouping_key'\n\t\tconst qb: SelectBuilder = SelectBuilder.create()\n\t\t\t.select([path.alias, relation.joiningColumn.columnName], groupingKey)\n\n\t\tconst rows = await this.selectRows(hydrator, qb, entity, input, relationPath, relation.name)\n\n\t\treturn await hydrator.hydrateGroups(rows, groupingKey)\n\t}\n\n\tprivate async selectRows(\n\t\thydrator: SelectHydrator,\n\t\tqb: SelectBuilder<SelectBuilder.Result>,\n\t\tentity: Model.Entity,\n\t\tinput: ObjectNode<Input.ListQueryInput>,\n\t\trelationPath: Model.AnyRelationContext[],\n\t\tgroupBy?: string,\n\t) {\n\t\tconst inputWithOrder = OrderByHelper.appendDefaultOrderBy(entity, input, undefined)\n\t\tconst path = this.pathFactory.create([])\n\t\tconst augmentedBuilder = qb.from(entity.tableName, path.alias).meta('path', [...input.path, input.alias])\n\n\t\tconst selector = this.selectBuilderFactory.create(augmentedBuilder, hydrator, relationPath)\n\t\tconst filterWithPredicates = this.predicatesInjector.inject(entity, inputWithOrder.args.filter || {}, relationPath[relationPath.length - 1])\n\t\tconst inputWithPredicates = inputWithOrder.withArg('filter', filterWithPredicates)\n\t\tselector.select(this, entity, inputWithPredicates, path, groupBy)\n\t\treturn await selector.execute(this.db)\n\t}\n\n\tpublic async count(entity: Model.Entity, filter: Input.OptionalWhere) {\n\t\tconst path = this.pathFactory.create([])\n\t\tconst qb = SelectBuilder.create()\n\t\t\t.from(entity.tableName, path.alias)\n\t\t\t.select(expr => expr.raw('count(*)'), 'row_count')\n\t\tconst withPredicates = this.predicatesInjector.inject(entity, filter)\n\t\tconst qbWithWhere = this.whereBuilder.build(qb, entity, path, withPredicates)\n\t\tconst result = await qbWithWhere.getResult(this.db)\n\t\treturn result[0].row_count\n\t}\n\n\tpublic async countGrouped(\n\t\tentity: Model.Entity,\n\t\tfilter: Input.OptionalWhere,\n\t\trelation: Model.JoiningColumnRelation & Model.Relation,\n\t\trelationPath: Model.AnyRelationContext[],\n\t): Promise<Record<string, number>> {\n\t\tconst path = this.pathFactory.create([])\n\t\tconst qb = SelectBuilder.create()\n\t\t\t.from(entity.tableName, path.alias)\n\t\t\t.select(expr => expr.raw('count(*)'), 'row_count')\n\t\t\t.select([path.alias, relation.joiningColumn.columnName])\n\t\t\t.groupBy([path.alias, relation.joiningColumn.columnName])\n\t\tconst withPredicates = this.predicatesInjector.inject(entity, filter, relationPath[relationPath.length - 1])\n\t\tconst qbWithWhere = this.whereBuilder.build(qb, entity, path, withPredicates, { relationPath })\n\t\tconst rows = await qbWithWhere.getResult(this.db)\n\t\tconst result = new Map<string, number>()\n\t\tfor (const row of rows) {\n\t\t\tresult.set(String(row[relation.joiningColumn.columnName]), Number(row.row_count))\n\t\t}\n\t\treturn Object.fromEntries(result)\n\t}\n\n\tpublic async insert(\n\t\tentity: Model.Entity,\n\t\tdata: MapperInput.CreateDataInput,\n\t\tbuilderCb: (builder: InsertBuilder) => void = () => {},\n\t): Promise<MutationResultList> {\n\t\tif (entity.view) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\tawait this.setupSystemVariables()\n\t\treturn tryMutation(this.schema, this.schemaDatabaseMetadata, () =>\n\t\t\tthis.insertInternal(entity, data, builderCb),\n\t\t)\n\t}\n\n\tpublic async update(\n\t\tentity: Model.Entity,\n\t\tby: Input.UniqueWhere | CheckedPrimary,\n\t\tdata: MapperInput.UpdateDataInput,\n\t\tfilter?: Input.OptionalWhere,\n\t): Promise<MutationResultList> {\n\t\tif (entity.view) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\tawait this.setupSystemVariables()\n\t\treturn tryMutation(this.schema, this.schemaDatabaseMetadata, async () => {\n\t\t\tconst [primaryValue, err] = await this.getPrimaryValue(entity, by)\n\t\t\tif (err) return [err]\n\n\t\t\treturn await this.updater.update(this, entity, primaryValue, data, filter)\n\t\t})\n\t}\n\n\tpublic async updateInternal(\n\t\tentity: Model.Entity,\n\t\tby: Input.UniqueWhere | CheckedPrimary,\n\t\tbuilderCb: (builder: UpdateBuilder) => void,\n\t): Promise<MutationResultList> {\n\t\tif (entity.view) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\tawait this.setupSystemVariables()\n\t\treturn tryMutation(this.schema, this.schemaDatabaseMetadata, async () => {\n\t\t\tconst [primaryValue, err] = await this.getPrimaryValue(entity, by)\n\t\t\tif (err) return [err]\n\n\t\t\treturn await this.updater.updateCb(this, entity, primaryValue, builderCb)\n\t\t})\n\t}\n\tpublic async upsert(\n\t\tentity: Model.Entity,\n\t\tby: Input.UniqueWhere | CheckedPrimary,\n\t\tupdate: MapperInput.UpdateDataInput,\n\t\tcreate: MapperInput.CreateDataInput,\n\t\tfilter?: Input.OptionalWhere,\n\t): Promise<MutationResultList> {\n\t\tif (entity.view) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\tawait this.setupSystemVariables()\n\t\treturn tryMutation(this.schema, this.schemaDatabaseMetadata, async () => {\n\t\t\tconst [primaryValue] = await this.getPrimaryValue(entity, by)\n\t\t\tif (primaryValue === undefined) {\n\t\t\t\treturn await this.insertInternal(entity, create)\n\t\t\t}\n\t\t\treturn await this.updater.update(this, entity, primaryValue, update, filter)\n\t\t})\n\t}\n\n\tprivate insertInternal(entity: Model.Entity, data: MapperInput.CreateDataInput, builderCb: (builder: InsertBuilder) => void = () => {}) {\n\t\treturn this.inserter.insert(this, entity, data, id => {\n\t\t}, builderCb)\n\t}\n\n\tpublic async delete(\n\t\tentity: Model.Entity,\n\t\tby: Input.UniqueWhere | CheckedPrimary,\n\t\tfilter?: Input.OptionalWhere,\n\t): Promise<MutationResultList> {\n\t\tif (entity.view) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\tawait this.setupSystemVariables()\n\t\treturn tryMutation(this.schema, this.schemaDatabaseMetadata, () => {\n\t\t\treturn this.deleteExecutor.execute(this, entity, by, filter)\n\t\t})\n\t}\n\n\tpublic async connectJunction(\n\t\tentity: Model.Entity,\n\t\trelation: Model.ManyHasManyOwningRelation | Model.ManyHasManyInverseRelation,\n\t\tthisPrimary: Input.PrimaryValue,\n\t\totherPrimary: Input.PrimaryValue,\n\t): Promise<MutationResultList> {\n\t\tawait this.setupSystemVariables()\n\t\tconst err = () => {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\treturn await acceptFieldVisitor(this.schema, entity, relation, {\n\t\t\tvisitManyHasManyOwning: ({ entity, relation }) => {\n\t\t\t\treturn this.junctionTableManager.connectJunction(this, entity, relation, thisPrimary, otherPrimary)\n\t\t\t},\n\t\t\tvisitManyHasManyInverse: ({ targetEntity, targetRelation }) => {\n\t\t\t\treturn this.junctionTableManager.connectJunction(this, targetEntity, targetRelation, otherPrimary, thisPrimary)\n\t\t\t},\n\t\t\tvisitColumn: err,\n\t\t\tvisitOneHasMany: err,\n\t\t\tvisitOneHasOneInverse: err,\n\t\t\tvisitOneHasOneOwning: err,\n\t\t\tvisitManyHasOne: err,\n\t\t})\n\t}\n\n\tpublic async disconnectJunction(\n\t\tentity: Model.Entity,\n\t\trelation: Model.ManyHasManyOwningRelation | Model.ManyHasManyInverseRelation,\n\t\tthisPrimary: Input.PrimaryValue,\n\t\totherPrimary: Input.PrimaryValue,\n\t): Promise<MutationResultList> {\n\t\tawait this.setupSystemVariables()\n\t\tconst err = () => {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\treturn await acceptFieldVisitor(this.schema, entity, relation, {\n\t\t\tvisitManyHasManyOwning: ({ entity, relation }) => {\n\t\t\t\treturn this.junctionTableManager.disconnectJunction(this, entity, relation, thisPrimary, otherPrimary)\n\t\t\t},\n\t\t\tvisitManyHasManyInverse: ({ targetEntity, targetRelation }) => {\n\t\t\t\treturn this.junctionTableManager.disconnectJunction(this, targetEntity, targetRelation, otherPrimary, thisPrimary)\n\t\t\t},\n\t\t\tvisitColumn: err,\n\t\t\tvisitOneHasMany: err,\n\t\t\tvisitOneHasOneInverse: err,\n\t\t\tvisitOneHasOneOwning: err,\n\t\t\tvisitManyHasOne: err,\n\t\t})\n\t}\n\n\tpublic async getPrimaryValue(\n\t\tentity: Model.Entity,\n\t\twhere: Input.UniqueWhere | CheckedPrimary,\n\t): Promise<[Input.PrimaryValue, undefined] | [undefined, MutationEntryNotFoundError]> {\n\t\tif (where instanceof CheckedPrimary) {\n\t\t\treturn [where.primaryValue, undefined]\n\t\t}\n\t\tconst result = await this.selectField(entity, where, entity.primary)\n\t\treturn result ? [result, undefined] : [undefined, new MutationEntryNotFoundError([], where)]\n\t}\n\n\tprivate async setupSystemVariables() {\n\t\tthis.systemVariablesSetupDone ??= (async () => {\n\t\t\tawait this.db.query('SELECT set_config(?, ?, false)', ['tenant.identity_id', this.identityId]) // todo rename to system.identity_id\n\t\t\tawait this.db.query('SELECT set_config(?, ?, false)', ['system.transaction_id', this.transactionId])\n\t\t})()\n\t\tawait this.systemVariablesSetupDone\n\t}\n}\n"],"names":["DeletedEntitiesStorage","Mutex","ConstraintHelper","EventManager","getColumnName","SelectBuilder","SelectHydrator","OrderByHelper","ImplementationException","tryMutation","acceptFieldVisitor","entity","relation","CheckedPrimary","MutationEntryNotFoundError"],"mappings":";;;;;;;;;;;;;;;;;;AA2BO,MAAM,OAAqF;AAAA,EAQjG,YACiB,IACA,YACA,eACC,QACA,wBACA,oBACA,sBACA,qBACA,cACA,sBACA,gBACA,SACA,UACA,aAChB;AAde,SAAA,KAAA;AACA,SAAA,aAA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AiB;AAAA,IAAA,CACjB;AAAA,EAAA;AAAA,EAGF,MAAa,gBACZ,QACA,OACqF;AACrF,QAAI,iBAAiBC,eAAAA,gBAAgB;AAC7B,aAAA,CAAC,MAAM,cAAc,MAAS;AAAA,IAAA;AAEtC,UAAM,SAAS,MAAM,KAAK,YAAY,QAAQ,OAAO,OAAO,OAAO;AACnE,WAAO,SAAS,CAAC,QAAQ,MAAS,IAAI,CAAC,QAAW,IAAIC,OAAAA,2BAA2B,CAAI,GAAA,KAAK,CAAC;AAAA,EAAA;AAAA,EAG5F,MAAc,uBAAuB;AAC/B,SAAA,6BAAL,KAAK,4BAA8B,YAAY;AACxC,YAAA,KAAK,GAAG,MAAM,kCAAkC,CAAC,sBAAsB,KAAK,UAAU,CAAC;AACvF,YAAA,KAAK,GAAG,MAAM,kCAAkC,CAAC,yBAAyB,KAAK,aAAa,CAAC;AAAA,IAAA;AAEpG,UAAM,KAAK;AAAA,EAAA;AAEb;;"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getColumnName, acceptFieldVisitor } from "@contember/schema-utils";
|
|
2
2
|
import "@contember/schema";
|
|
3
3
|
import { ConstraintHelper, SelectBuilder } from "@contember/database";
|
|
4
|
+
import "node:crypto";
|
|
4
5
|
import { ImplementationException } from "../exception.js";
|
|
5
6
|
import { OrderByHelper } from "./select/OrderByHelper.js";
|
|
6
7
|
import { Mutex } from "../utils/Mutex.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Mapper.js","sources":["../../../../../packages/engine-content-api/src/mapper/Mapper.ts"],"sourcesContent":["import { Input, Model } from '@contember/schema'\nimport { acceptFieldVisitor, getColumnName } from '@contember/schema-utils'\nimport {\n\tOrderByHelper,\n\tPathFactory,\n\tSelectBuilderFactory,\n\tSelectGroupedObjects,\n\tSelectHydrator,\n\tSelectIndexedResultObjects,\n\tSelectResultObject,\n\tWhereBuilder,\n} from './select'\nimport { Client, Connection, ConstraintHelper, DatabaseMetadata, SelectBuilder } from '@contember/database'\nimport { PredicatesInjector } from '../acl'\nimport { JunctionTableManager } from './JunctionTableManager'\nimport { DeletedEntitiesStorage, DeleteExecutor } from './delete'\nimport { MutationEntryNotFoundError, MutationResultList } from './Result'\nimport { UpdateBuilder, Updater } from './update'\nimport { InsertBuilder, Inserter } from './insert'\nimport { tryMutation } from './ErrorUtils'\nimport { ObjectNode, UniqueWhereExpander } from '../inputProcessing'\nimport { Mutex } from '../utils'\nimport { CheckedPrimary } from './CheckedPrimary'\nimport { ImplementationException } from '../exception'\nimport { EventManager } from './EventManager'\nimport { MapperInput } from './types'\n\nexport class Mapper<ConnectionType extends Connection.ConnectionLike = Connection.ConnectionLike> {\n\tprivate systemVariablesSetupDone: Promise<void> | undefined\n\tpublic readonly deletedEntities = new DeletedEntitiesStorage()\n\tpublic readonly mutex = new Mutex()\n\tpublic readonly constraintHelper: ConstraintHelper\n\n\tpublic readonly eventManager: EventManager\n\n\tconstructor(\n\t\tpublic readonly db: Client<ConnectionType>,\n\t\tpublic readonly identityId: string,\n\t\tpublic readonly transactionId: string,\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly schemaDatabaseMetadata: DatabaseMetadata,\n\t\tprivate readonly predicatesInjector: PredicatesInjector,\n\t\tprivate readonly selectBuilderFactory: SelectBuilderFactory,\n\t\tprivate readonly uniqueWhereExpander: UniqueWhereExpander,\n\t\tprivate readonly whereBuilder: WhereBuilder,\n\t\tprivate readonly junctionTableManager: JunctionTableManager,\n\t\tprivate readonly deleteExecutor: DeleteExecutor,\n\t\tprivate readonly updater: Updater,\n\t\tprivate readonly inserter: Inserter,\n\t\tprivate readonly pathFactory: PathFactory,\n\t) {\n\t\tthis.constraintHelper = new ConstraintHelper(db, this.schemaDatabaseMetadata)\n\t\tthis.eventManager = new EventManager(this)\n\t}\n\n\tpublic async selectField(entity: Model.Entity, where: Input.UniqueWhere | CheckedPrimary, fieldName: string) {\n\t\tconst columnName = getColumnName(this.schema, entity, fieldName)\n\n\t\tconst qb = SelectBuilder.create() //\n\t\t\t.from(entity.tableName, 'root_')\n\t\t\t.select(['root_', columnName])\n\t\tconst expandedWhere = this.uniqueWhereExpander.expand(entity, where)\n\t\tconst withPredicates = this.predicatesInjector.inject(entity, expandedWhere)\n\t\tconst builtQb = this.whereBuilder.build(qb, entity, this.pathFactory.create([]), withPredicates)\n\t\tconst result = await builtQb.getResult(this.db)\n\n\t\treturn result[0] !== undefined ? result[0][columnName] : undefined\n\t}\n\n\tpublic async selectAssoc(\n\t\tentity: Model.Entity,\n\t\tinput: ObjectNode<Input.ListQueryInput>,\n\t\trelationPath: Model.AnyRelationContext[],\n\t\tindexBy: string,\n\t): Promise<SelectIndexedResultObjects> {\n\t\tconst hydrator = new SelectHydrator()\n\t\tconst path = this.pathFactory.create([])\n\t\tconst indexByAlias: string = path.for(indexBy).alias\n\t\tconst qb: SelectBuilder = SelectBuilder.create()\n\t\t\t.select([path.alias, getColumnName(this.schema, entity, indexBy)], indexByAlias)\n\t\tconst rows = await this.selectRows(hydrator, qb, entity, input, relationPath)\n\t\treturn await hydrator.hydrateAll(rows, indexByAlias)\n\t}\n\n\tpublic async select(entity: Model.Entity, input: ObjectNode<Input.ListQueryInput>, relationPath: Model.AnyRelationContext[]): Promise<SelectResultObject[]> {\n\t\tconst hydrator = new SelectHydrator()\n\t\tconst qb: SelectBuilder<SelectBuilder.Result> = SelectBuilder.create()\n\n\t\tconst rows = await this.selectRows(hydrator, qb, entity, input, relationPath)\n\n\t\treturn await hydrator.hydrateAll(rows)\n\t}\n\n\tpublic async selectUnique(\n\t\tentity: Model.Entity,\n\t\tquery: ObjectNode<Input.UniqueQueryInput>,\n\t\trelationPath: Model.AnyRelationContext[],\n\t): Promise<SelectResultObject | null> {\n\t\tconst uniqueWhere = this.uniqueWhereExpander.expand(entity, query.args.by)\n\t\tconst where = query.args.filter ? { and: [uniqueWhere, query.args.filter] } : uniqueWhere\n\t\tconst queryExpanded = query.withArg<Input.ListQueryInput>('filter', where)\n\n\t\tconst rows = await this.select(entity, queryExpanded, relationPath)\n\n\t\treturn rows[0] ?? null\n\t}\n\n\tpublic async selectGrouped(\n\t\tentity: Model.Entity,\n\t\tinput: ObjectNode<Input.ListQueryInput>,\n\t\trelation: Model.JoiningColumnRelation & Model.AnyRelation,\n\t\trelationPath: Model.AnyRelationContext[],\n\t): Promise<SelectGroupedObjects> {\n\t\tconst hydrator = new SelectHydrator()\n\t\tconst path = this.pathFactory.create([])\n\t\tconst groupingKey = '__grouping_key'\n\t\tconst qb: SelectBuilder = SelectBuilder.create()\n\t\t\t.select([path.alias, relation.joiningColumn.columnName], groupingKey)\n\n\t\tconst rows = await this.selectRows(hydrator, qb, entity, input, relationPath, relation.name)\n\n\t\treturn await hydrator.hydrateGroups(rows, groupingKey)\n\t}\n\n\tprivate async selectRows(\n\t\thydrator: SelectHydrator,\n\t\tqb: SelectBuilder<SelectBuilder.Result>,\n\t\tentity: Model.Entity,\n\t\tinput: ObjectNode<Input.ListQueryInput>,\n\t\trelationPath: Model.AnyRelationContext[],\n\t\tgroupBy?: string,\n\t) {\n\t\tconst inputWithOrder = OrderByHelper.appendDefaultOrderBy(entity, input, undefined)\n\t\tconst path = this.pathFactory.create([])\n\t\tconst augmentedBuilder = qb.from(entity.tableName, path.alias).meta('path', [...input.path, input.alias])\n\n\t\tconst selector = this.selectBuilderFactory.create(augmentedBuilder, hydrator, relationPath)\n\t\tconst filterWithPredicates = this.predicatesInjector.inject(entity, inputWithOrder.args.filter || {}, relationPath[relationPath.length - 1])\n\t\tconst inputWithPredicates = inputWithOrder.withArg('filter', filterWithPredicates)\n\t\tselector.select(this, entity, inputWithPredicates, path, groupBy)\n\t\treturn await selector.execute(this.db)\n\t}\n\n\tpublic async count(entity: Model.Entity, filter: Input.OptionalWhere) {\n\t\tconst path = this.pathFactory.create([])\n\t\tconst qb = SelectBuilder.create()\n\t\t\t.from(entity.tableName, path.alias)\n\t\t\t.select(expr => expr.raw('count(*)'), 'row_count')\n\t\tconst withPredicates = this.predicatesInjector.inject(entity, filter)\n\t\tconst qbWithWhere = this.whereBuilder.build(qb, entity, path, withPredicates)\n\t\tconst result = await qbWithWhere.getResult(this.db)\n\t\treturn result[0].row_count\n\t}\n\n\tpublic async countGrouped(\n\t\tentity: Model.Entity,\n\t\tfilter: Input.OptionalWhere,\n\t\trelation: Model.JoiningColumnRelation & Model.Relation,\n\t\trelationPath: Model.AnyRelationContext[],\n\t): Promise<Record<string, number>> {\n\t\tconst path = this.pathFactory.create([])\n\t\tconst qb = SelectBuilder.create()\n\t\t\t.from(entity.tableName, path.alias)\n\t\t\t.select(expr => expr.raw('count(*)'), 'row_count')\n\t\t\t.select([path.alias, relation.joiningColumn.columnName])\n\t\t\t.groupBy([path.alias, relation.joiningColumn.columnName])\n\t\tconst withPredicates = this.predicatesInjector.inject(entity, filter, relationPath[relationPath.length - 1])\n\t\tconst qbWithWhere = this.whereBuilder.build(qb, entity, path, withPredicates, { relationPath })\n\t\tconst rows = await qbWithWhere.getResult(this.db)\n\t\tconst result = new Map<string, number>()\n\t\tfor (const row of rows) {\n\t\t\tresult.set(String(row[relation.joiningColumn.columnName]), Number(row.row_count))\n\t\t}\n\t\treturn Object.fromEntries(result)\n\t}\n\n\tpublic async insert(\n\t\tentity: Model.Entity,\n\t\tdata: MapperInput.CreateDataInput,\n\t\tbuilderCb: (builder: InsertBuilder) => void = () => {},\n\t): Promise<MutationResultList> {\n\t\tif (entity.view) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\tawait this.setupSystemVariables()\n\t\treturn tryMutation(this.schema, this.schemaDatabaseMetadata, () =>\n\t\t\tthis.insertInternal(entity, data, builderCb),\n\t\t)\n\t}\n\n\tpublic async update(\n\t\tentity: Model.Entity,\n\t\tby: Input.UniqueWhere | CheckedPrimary,\n\t\tdata: MapperInput.UpdateDataInput,\n\t\tfilter?: Input.OptionalWhere,\n\t): Promise<MutationResultList> {\n\t\tif (entity.view) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\tawait this.setupSystemVariables()\n\t\treturn tryMutation(this.schema, this.schemaDatabaseMetadata, async () => {\n\t\t\tconst [primaryValue, err] = await this.getPrimaryValue(entity, by)\n\t\t\tif (err) return [err]\n\n\t\t\treturn await this.updater.update(this, entity, primaryValue, data, filter)\n\t\t})\n\t}\n\n\tpublic async updateInternal(\n\t\tentity: Model.Entity,\n\t\tby: Input.UniqueWhere | CheckedPrimary,\n\t\tbuilderCb: (builder: UpdateBuilder) => void,\n\t): Promise<MutationResultList> {\n\t\tif (entity.view) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\tawait this.setupSystemVariables()\n\t\treturn tryMutation(this.schema, this.schemaDatabaseMetadata, async () => {\n\t\t\tconst [primaryValue, err] = await this.getPrimaryValue(entity, by)\n\t\t\tif (err) return [err]\n\n\t\t\treturn await this.updater.updateCb(this, entity, primaryValue, builderCb)\n\t\t})\n\t}\n\tpublic async upsert(\n\t\tentity: Model.Entity,\n\t\tby: Input.UniqueWhere | CheckedPrimary,\n\t\tupdate: MapperInput.UpdateDataInput,\n\t\tcreate: MapperInput.CreateDataInput,\n\t\tfilter?: Input.OptionalWhere,\n\t): Promise<MutationResultList> {\n\t\tif (entity.view) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\tawait this.setupSystemVariables()\n\t\treturn tryMutation(this.schema, this.schemaDatabaseMetadata, async () => {\n\t\t\tconst [primaryValue] = await this.getPrimaryValue(entity, by)\n\t\t\tif (primaryValue === undefined) {\n\t\t\t\treturn await this.insertInternal(entity, create)\n\t\t\t}\n\t\t\treturn await this.updater.update(this, entity, primaryValue, update, filter)\n\t\t})\n\t}\n\n\tprivate insertInternal(entity: Model.Entity, data: MapperInput.CreateDataInput, builderCb: (builder: InsertBuilder) => void = () => {}) {\n\t\treturn this.inserter.insert(this, entity, data, id => {\n\t\t}, builderCb)\n\t}\n\n\tpublic async delete(\n\t\tentity: Model.Entity,\n\t\tby: Input.UniqueWhere | CheckedPrimary,\n\t\tfilter?: Input.OptionalWhere,\n\t): Promise<MutationResultList> {\n\t\tif (entity.view) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\tawait this.setupSystemVariables()\n\t\treturn tryMutation(this.schema, this.schemaDatabaseMetadata, () => {\n\t\t\treturn this.deleteExecutor.execute(this, entity, by, filter)\n\t\t})\n\t}\n\n\tpublic async connectJunction(\n\t\tentity: Model.Entity,\n\t\trelation: Model.ManyHasManyOwningRelation | Model.ManyHasManyInverseRelation,\n\t\tthisPrimary: Input.PrimaryValue,\n\t\totherPrimary: Input.PrimaryValue,\n\t): Promise<MutationResultList> {\n\t\tawait this.setupSystemVariables()\n\t\tconst err = () => {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\treturn await acceptFieldVisitor(this.schema, entity, relation, {\n\t\t\tvisitManyHasManyOwning: ({ entity, relation }) => {\n\t\t\t\treturn this.junctionTableManager.connectJunction(this, entity, relation, thisPrimary, otherPrimary)\n\t\t\t},\n\t\t\tvisitManyHasManyInverse: ({ targetEntity, targetRelation }) => {\n\t\t\t\treturn this.junctionTableManager.connectJunction(this, targetEntity, targetRelation, otherPrimary, thisPrimary)\n\t\t\t},\n\t\t\tvisitColumn: err,\n\t\t\tvisitOneHasMany: err,\n\t\t\tvisitOneHasOneInverse: err,\n\t\t\tvisitOneHasOneOwning: err,\n\t\t\tvisitManyHasOne: err,\n\t\t})\n\t}\n\n\tpublic async disconnectJunction(\n\t\tentity: Model.Entity,\n\t\trelation: Model.ManyHasManyOwningRelation | Model.ManyHasManyInverseRelation,\n\t\tthisPrimary: Input.PrimaryValue,\n\t\totherPrimary: Input.PrimaryValue,\n\t): Promise<MutationResultList> {\n\t\tawait this.setupSystemVariables()\n\t\tconst err = () => {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\treturn await acceptFieldVisitor(this.schema, entity, relation, {\n\t\t\tvisitManyHasManyOwning: ({ entity, relation }) => {\n\t\t\t\treturn this.junctionTableManager.disconnectJunction(this, entity, relation, thisPrimary, otherPrimary)\n\t\t\t},\n\t\t\tvisitManyHasManyInverse: ({ targetEntity, targetRelation }) => {\n\t\t\t\treturn this.junctionTableManager.disconnectJunction(this, targetEntity, targetRelation, otherPrimary, thisPrimary)\n\t\t\t},\n\t\t\tvisitColumn: err,\n\t\t\tvisitOneHasMany: err,\n\t\t\tvisitOneHasOneInverse: err,\n\t\t\tvisitOneHasOneOwning: err,\n\t\t\tvisitManyHasOne: err,\n\t\t})\n\t}\n\n\tpublic async getPrimaryValue(\n\t\tentity: Model.Entity,\n\t\twhere: Input.UniqueWhere | CheckedPrimary,\n\t): Promise<[Input.PrimaryValue, undefined] | [undefined, MutationEntryNotFoundError]> {\n\t\tif (where instanceof CheckedPrimary) {\n\t\t\treturn [where.primaryValue, undefined]\n\t\t}\n\t\tconst result = await this.selectField(entity, where, entity.primary)\n\t\treturn result ? [result, undefined] : [undefined, new MutationEntryNotFoundError([], where)]\n\t}\n\n\tprivate async setupSystemVariables() {\n\t\tthis.systemVariablesSetupDone ??= (async () => {\n\t\t\tawait this.db.query('SELECT set_config(?, ?, false)', ['tenant.identity_id', this.identityId]) // todo rename to system.identity_id\n\t\t\tawait this.db.query('SELECT set_config(?, ?, false)', ['system.transaction_id', this.transactionId])\n\t\t})()\n\t\tawait this.systemVariablesSetupDone\n\t}\n}\n"],"names":["entity","relation"],"mappings":";;;;;;;;;;;;;;;AA2BO,MAAM,OAAqF;AAAA,EAQjG,YACiB,IACA,YACA,eACC,QACA,wBACA,oBACA,sBACA,qBACA,cACA,sBACA,gBACA,SACA,UACA,aAChB;AAde,SAAA,KAAA;AACA,SAAA,aAAA;AACA,SAAA,gBAAA;AACC,SAAA,SAAA;AACA,SAAA,yBAAA;AACA,SAAA,qBAAA;AACA,SAAA,uBAAA;AACA,SAAA,sBAAA;AACA,SAAA,eAAA;AACA,SAAA,uBAAA;AACA,SAAA,iBAAA;AACA,SAAA,UAAA;AACA,SAAA,WAAA;AACA,SAAA,cAAA;AArBV,kBAAA,MAAA,0BAAA;AACQ,kBAA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,YAAA,KAAK,GAAG,MAAM,kCAAkC,CAAC,yBAAyB,KAAK,aAAa,CAAC;AAAA,IAAA;AAEpG,UAAM,KAAK;AAAA,EAAA;AAEb;"}
|
|
1
|
+
{"version":3,"file":"Mapper.js","sources":["../../../../../packages/engine-content-api/src/mapper/Mapper.ts"],"sourcesContent":["import { Input, Model } from '@contember/schema'\nimport { acceptFieldVisitor, getColumnName } from '@contember/schema-utils'\nimport {\n\tOrderByHelper,\n\tPathFactory,\n\tSelectBuilderFactory,\n\tSelectGroupedObjects,\n\tSelectHydrator,\n\tSelectIndexedResultObjects,\n\tSelectResultObject,\n\tWhereBuilder,\n} from './select'\nimport { Client, Connection, ConstraintHelper, DatabaseMetadata, SelectBuilder } from '@contember/database'\nimport { PredicatesInjector } from '../acl'\nimport { JunctionTableManager } from './JunctionTableManager'\nimport { DeletedEntitiesStorage, DeleteExecutor } from './delete'\nimport { MutationEntryNotFoundError, MutationResultList } from './Result'\nimport { UpdateBuilder, Updater } from './update'\nimport { InsertBuilder, Inserter } from './insert'\nimport { tryMutation } from './ErrorUtils'\nimport { ObjectNode, UniqueWhereExpander } from '../inputProcessing'\nimport { Mutex } from '../utils'\nimport { CheckedPrimary } from './CheckedPrimary'\nimport { ImplementationException } from '../exception'\nimport { EventManager } from './EventManager'\nimport { MapperInput } from './types'\n\nexport class Mapper<ConnectionType extends Connection.ConnectionLike = Connection.ConnectionLike> {\n\tprivate systemVariablesSetupDone: Promise<void> | undefined\n\tpublic readonly deletedEntities = new DeletedEntitiesStorage()\n\tpublic readonly mutex = new Mutex()\n\tpublic readonly constraintHelper: ConstraintHelper\n\n\tpublic readonly eventManager: EventManager\n\n\tconstructor(\n\t\tpublic readonly db: Client<ConnectionType>,\n\t\tpublic readonly identityId: string,\n\t\tpublic readonly transactionId: string,\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly schemaDatabaseMetadata: DatabaseMetadata,\n\t\tprivate readonly predicatesInjector: PredicatesInjector,\n\t\tprivate readonly selectBuilderFactory: SelectBuilderFactory,\n\t\tprivate readonly uniqueWhereExpander: UniqueWhereExpander,\n\t\tprivate readonly whereBuilder: WhereBuilder,\n\t\tprivate readonly junctionTableManager: JunctionTableManager,\n\t\tprivate readonly deleteExecutor: DeleteExecutor,\n\t\tprivate readonly updater: Updater,\n\t\tprivate readonly inserter: Inserter,\n\t\tprivate readonly pathFactory: PathFactory,\n\t) {\n\t\tthis.constraintHelper = new ConstraintHelper(db, this.schemaDatabaseMetadata)\n\t\tthis.eventManager = new EventManager(this)\n\t}\n\n\tpublic async selectField(entity: Model.Entity, where: Input.UniqueWhere | CheckedPrimary, fieldName: string) {\n\t\tconst columnName = getColumnName(this.schema, entity, fieldName)\n\n\t\tconst qb = SelectBuilder.create() //\n\t\t\t.from(entity.tableName, 'root_')\n\t\t\t.select(['root_', columnName])\n\t\tconst expandedWhere = this.uniqueWhereExpander.expand(entity, where)\n\t\tconst withPredicates = this.predicatesInjector.inject(entity, expandedWhere)\n\t\tconst builtQb = this.whereBuilder.build(qb, entity, this.pathFactory.create([]), withPredicates)\n\t\tconst result = await builtQb.getResult(this.db)\n\n\t\treturn result[0] !== undefined ? result[0][columnName] : undefined\n\t}\n\n\tpublic async selectAssoc(\n\t\tentity: Model.Entity,\n\t\tinput: ObjectNode<Input.ListQueryInput>,\n\t\trelationPath: Model.AnyRelationContext[],\n\t\tindexBy: string,\n\t): Promise<SelectIndexedResultObjects> {\n\t\tconst hydrator = new SelectHydrator()\n\t\tconst path = this.pathFactory.create([])\n\t\tconst indexByAlias: string = path.for(indexBy).alias\n\t\tconst qb: SelectBuilder = SelectBuilder.create()\n\t\t\t.select([path.alias, getColumnName(this.schema, entity, indexBy)], indexByAlias)\n\t\tconst rows = await this.selectRows(hydrator, qb, entity, input, relationPath)\n\t\treturn await hydrator.hydrateAll(rows, indexByAlias)\n\t}\n\n\tpublic async select(entity: Model.Entity, input: ObjectNode<Input.ListQueryInput>, relationPath: Model.AnyRelationContext[]): Promise<SelectResultObject[]> {\n\t\tconst hydrator = new SelectHydrator()\n\t\tconst qb: SelectBuilder<SelectBuilder.Result> = SelectBuilder.create()\n\n\t\tconst rows = await this.selectRows(hydrator, qb, entity, input, relationPath)\n\n\t\treturn await hydrator.hydrateAll(rows)\n\t}\n\n\tpublic async selectUnique(\n\t\tentity: Model.Entity,\n\t\tquery: ObjectNode<Input.UniqueQueryInput>,\n\t\trelationPath: Model.AnyRelationContext[],\n\t): Promise<SelectResultObject | null> {\n\t\tconst uniqueWhere = this.uniqueWhereExpander.expand(entity, query.args.by)\n\t\tconst where = query.args.filter ? { and: [uniqueWhere, query.args.filter] } : uniqueWhere\n\t\tconst queryExpanded = query.withArg<Input.ListQueryInput>('filter', where)\n\n\t\tconst rows = await this.select(entity, queryExpanded, relationPath)\n\n\t\treturn rows[0] ?? null\n\t}\n\n\tpublic async selectGrouped(\n\t\tentity: Model.Entity,\n\t\tinput: ObjectNode<Input.ListQueryInput>,\n\t\trelation: Model.JoiningColumnRelation & Model.AnyRelation,\n\t\trelationPath: Model.AnyRelationContext[],\n\t): Promise<SelectGroupedObjects> {\n\t\tconst hydrator = new SelectHydrator()\n\t\tconst path = this.pathFactory.create([])\n\t\tconst groupingKey = '__grouping_key'\n\t\tconst qb: SelectBuilder = SelectBuilder.create()\n\t\t\t.select([path.alias, relation.joiningColumn.columnName], groupingKey)\n\n\t\tconst rows = await this.selectRows(hydrator, qb, entity, input, relationPath, relation.name)\n\n\t\treturn await hydrator.hydrateGroups(rows, groupingKey)\n\t}\n\n\tprivate async selectRows(\n\t\thydrator: SelectHydrator,\n\t\tqb: SelectBuilder<SelectBuilder.Result>,\n\t\tentity: Model.Entity,\n\t\tinput: ObjectNode<Input.ListQueryInput>,\n\t\trelationPath: Model.AnyRelationContext[],\n\t\tgroupBy?: string,\n\t) {\n\t\tconst inputWithOrder = OrderByHelper.appendDefaultOrderBy(entity, input, undefined)\n\t\tconst path = this.pathFactory.create([])\n\t\tconst augmentedBuilder = qb.from(entity.tableName, path.alias).meta('path', [...input.path, input.alias])\n\n\t\tconst selector = this.selectBuilderFactory.create(augmentedBuilder, hydrator, relationPath)\n\t\tconst filterWithPredicates = this.predicatesInjector.inject(entity, inputWithOrder.args.filter || {}, relationPath[relationPath.length - 1])\n\t\tconst inputWithPredicates = inputWithOrder.withArg('filter', filterWithPredicates)\n\t\tselector.select(this, entity, inputWithPredicates, path, groupBy)\n\t\treturn await selector.execute(this.db)\n\t}\n\n\tpublic async count(entity: Model.Entity, filter: Input.OptionalWhere) {\n\t\tconst path = this.pathFactory.create([])\n\t\tconst qb = SelectBuilder.create()\n\t\t\t.from(entity.tableName, path.alias)\n\t\t\t.select(expr => expr.raw('count(*)'), 'row_count')\n\t\tconst withPredicates = this.predicatesInjector.inject(entity, filter)\n\t\tconst qbWithWhere = this.whereBuilder.build(qb, entity, path, withPredicates)\n\t\tconst result = await qbWithWhere.getResult(this.db)\n\t\treturn result[0].row_count\n\t}\n\n\tpublic async countGrouped(\n\t\tentity: Model.Entity,\n\t\tfilter: Input.OptionalWhere,\n\t\trelation: Model.JoiningColumnRelation & Model.Relation,\n\t\trelationPath: Model.AnyRelationContext[],\n\t): Promise<Record<string, number>> {\n\t\tconst path = this.pathFactory.create([])\n\t\tconst qb = SelectBuilder.create()\n\t\t\t.from(entity.tableName, path.alias)\n\t\t\t.select(expr => expr.raw('count(*)'), 'row_count')\n\t\t\t.select([path.alias, relation.joiningColumn.columnName])\n\t\t\t.groupBy([path.alias, relation.joiningColumn.columnName])\n\t\tconst withPredicates = this.predicatesInjector.inject(entity, filter, relationPath[relationPath.length - 1])\n\t\tconst qbWithWhere = this.whereBuilder.build(qb, entity, path, withPredicates, { relationPath })\n\t\tconst rows = await qbWithWhere.getResult(this.db)\n\t\tconst result = new Map<string, number>()\n\t\tfor (const row of rows) {\n\t\t\tresult.set(String(row[relation.joiningColumn.columnName]), Number(row.row_count))\n\t\t}\n\t\treturn Object.fromEntries(result)\n\t}\n\n\tpublic async insert(\n\t\tentity: Model.Entity,\n\t\tdata: MapperInput.CreateDataInput,\n\t\tbuilderCb: (builder: InsertBuilder) => void = () => {},\n\t): Promise<MutationResultList> {\n\t\tif (entity.view) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\tawait this.setupSystemVariables()\n\t\treturn tryMutation(this.schema, this.schemaDatabaseMetadata, () =>\n\t\t\tthis.insertInternal(entity, data, builderCb),\n\t\t)\n\t}\n\n\tpublic async update(\n\t\tentity: Model.Entity,\n\t\tby: Input.UniqueWhere | CheckedPrimary,\n\t\tdata: MapperInput.UpdateDataInput,\n\t\tfilter?: Input.OptionalWhere,\n\t): Promise<MutationResultList> {\n\t\tif (entity.view) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\tawait this.setupSystemVariables()\n\t\treturn tryMutation(this.schema, this.schemaDatabaseMetadata, async () => {\n\t\t\tconst [primaryValue, err] = await this.getPrimaryValue(entity, by)\n\t\t\tif (err) return [err]\n\n\t\t\treturn await this.updater.update(this, entity, primaryValue, data, filter)\n\t\t})\n\t}\n\n\tpublic async updateInternal(\n\t\tentity: Model.Entity,\n\t\tby: Input.UniqueWhere | CheckedPrimary,\n\t\tbuilderCb: (builder: UpdateBuilder) => void,\n\t): Promise<MutationResultList> {\n\t\tif (entity.view) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\tawait this.setupSystemVariables()\n\t\treturn tryMutation(this.schema, this.schemaDatabaseMetadata, async () => {\n\t\t\tconst [primaryValue, err] = await this.getPrimaryValue(entity, by)\n\t\t\tif (err) return [err]\n\n\t\t\treturn await this.updater.updateCb(this, entity, primaryValue, builderCb)\n\t\t})\n\t}\n\tpublic async upsert(\n\t\tentity: Model.Entity,\n\t\tby: Input.UniqueWhere | CheckedPrimary,\n\t\tupdate: MapperInput.UpdateDataInput,\n\t\tcreate: MapperInput.CreateDataInput,\n\t\tfilter?: Input.OptionalWhere,\n\t): Promise<MutationResultList> {\n\t\tif (entity.view) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\tawait this.setupSystemVariables()\n\t\treturn tryMutation(this.schema, this.schemaDatabaseMetadata, async () => {\n\t\t\tconst [primaryValue] = await this.getPrimaryValue(entity, by)\n\t\t\tif (primaryValue === undefined) {\n\t\t\t\treturn await this.insertInternal(entity, create)\n\t\t\t}\n\t\t\treturn await this.updater.update(this, entity, primaryValue, update, filter)\n\t\t})\n\t}\n\n\tprivate insertInternal(entity: Model.Entity, data: MapperInput.CreateDataInput, builderCb: (builder: InsertBuilder) => void = () => {}) {\n\t\treturn this.inserter.insert(this, entity, data, id => {\n\t\t}, builderCb)\n\t}\n\n\tpublic async delete(\n\t\tentity: Model.Entity,\n\t\tby: Input.UniqueWhere | CheckedPrimary,\n\t\tfilter?: Input.OptionalWhere,\n\t): Promise<MutationResultList> {\n\t\tif (entity.view) {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\tawait this.setupSystemVariables()\n\t\treturn tryMutation(this.schema, this.schemaDatabaseMetadata, () => {\n\t\t\treturn this.deleteExecutor.execute(this, entity, by, filter)\n\t\t})\n\t}\n\n\tpublic async connectJunction(\n\t\tentity: Model.Entity,\n\t\trelation: Model.ManyHasManyOwningRelation | Model.ManyHasManyInverseRelation,\n\t\tthisPrimary: Input.PrimaryValue,\n\t\totherPrimary: Input.PrimaryValue,\n\t): Promise<MutationResultList> {\n\t\tawait this.setupSystemVariables()\n\t\tconst err = () => {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\treturn await acceptFieldVisitor(this.schema, entity, relation, {\n\t\t\tvisitManyHasManyOwning: ({ entity, relation }) => {\n\t\t\t\treturn this.junctionTableManager.connectJunction(this, entity, relation, thisPrimary, otherPrimary)\n\t\t\t},\n\t\t\tvisitManyHasManyInverse: ({ targetEntity, targetRelation }) => {\n\t\t\t\treturn this.junctionTableManager.connectJunction(this, targetEntity, targetRelation, otherPrimary, thisPrimary)\n\t\t\t},\n\t\t\tvisitColumn: err,\n\t\t\tvisitOneHasMany: err,\n\t\t\tvisitOneHasOneInverse: err,\n\t\t\tvisitOneHasOneOwning: err,\n\t\t\tvisitManyHasOne: err,\n\t\t})\n\t}\n\n\tpublic async disconnectJunction(\n\t\tentity: Model.Entity,\n\t\trelation: Model.ManyHasManyOwningRelation | Model.ManyHasManyInverseRelation,\n\t\tthisPrimary: Input.PrimaryValue,\n\t\totherPrimary: Input.PrimaryValue,\n\t): Promise<MutationResultList> {\n\t\tawait this.setupSystemVariables()\n\t\tconst err = () => {\n\t\t\tthrow new ImplementationException()\n\t\t}\n\t\treturn await acceptFieldVisitor(this.schema, entity, relation, {\n\t\t\tvisitManyHasManyOwning: ({ entity, relation }) => {\n\t\t\t\treturn this.junctionTableManager.disconnectJunction(this, entity, relation, thisPrimary, otherPrimary)\n\t\t\t},\n\t\t\tvisitManyHasManyInverse: ({ targetEntity, targetRelation }) => {\n\t\t\t\treturn this.junctionTableManager.disconnectJunction(this, targetEntity, targetRelation, otherPrimary, thisPrimary)\n\t\t\t},\n\t\t\tvisitColumn: err,\n\t\t\tvisitOneHasMany: err,\n\t\t\tvisitOneHasOneInverse: err,\n\t\t\tvisitOneHasOneOwning: err,\n\t\t\tvisitManyHasOne: err,\n\t\t})\n\t}\n\n\tpublic async getPrimaryValue(\n\t\tentity: Model.Entity,\n\t\twhere: Input.UniqueWhere | CheckedPrimary,\n\t): Promise<[Input.PrimaryValue, undefined] | [undefined, MutationEntryNotFoundError]> {\n\t\tif (where instanceof CheckedPrimary) {\n\t\t\treturn [where.primaryValue, undefined]\n\t\t}\n\t\tconst result = await this.selectField(entity, where, entity.primary)\n\t\treturn result ? [result, undefined] : [undefined, new MutationEntryNotFoundError([], where)]\n\t}\n\n\tprivate async setupSystemVariables() {\n\t\tthis.systemVariablesSetupDone ??= (async () => {\n\t\t\tawait this.db.query('SELECT set_config(?, ?, false)', ['tenant.identity_id', this.identityId]) // todo rename to system.identity_id\n\t\t\tawait this.db.query('SELECT set_config(?, ?, false)', ['system.transaction_id', this.transactionId])\n\t\t})()\n\t\tawait this.systemVariablesSetupDone\n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A,CACjB;AAAA,EAAA;AAAA,EAGF,MAAa,gBACZ,QACA,OACqF;AACrF,QAAI,iBAAiB,gBAAgB;AAC7B,aAAA,CAAC,MAAM,cAAc,MAAS;AAAA,IAAA;AAEtC,UAAM,SAAS,MAAM,KAAK,YAAY,QAAQ,OAAO,OAAO,OAAO;AACnE,WAAO,SAAS,CAAC,QAAQ,MAAS,IAAI,CAAC,QAAW,IAAI,2BAA2B,CAAI,GAAA,KAAK,CAAC;AAAA,EAAA;AAAA,EAG5F,MAAc,uBAAuB;AAC/B,SAAA,6BAAL,KAAK,4BAA8B,YAAY;AACxC,YAAA,KAAK,GAAG,MAAM,kCAAkC,CAAC,sBAAsB,KAAK,UAAU,CAAC;AACvF,YAAA,KAAK,GAAG,MAAM,kCAAkC,CAAC,yBAAyB,KAAK,aAAa,CAAC;AAAA,IAAA;AAEpG,UAAM,KAAK;AAAA,EAAA;AAEb;"}
|
|
@@ -2,18 +2,23 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const schema = require("@contember/schema");
|
|
4
4
|
const Database = require("@contember/database");
|
|
5
|
+
const schemaUtils = require("@contember/schema-utils");
|
|
6
|
+
const viewComputedId = require("../../../utils/viewComputedId.cjs");
|
|
5
7
|
class FieldsVisitor {
|
|
6
|
-
constructor(relationFetcher, predicateFactory, mapper, executionContext, relationPath, settings) {
|
|
8
|
+
constructor(schema2, relationFetcher, predicateFactory, mapper, executionContext, relationPath, settings, providers) {
|
|
9
|
+
this.schema = schema2;
|
|
7
10
|
this.relationFetcher = relationFetcher;
|
|
8
11
|
this.predicateFactory = predicateFactory;
|
|
9
12
|
this.mapper = mapper;
|
|
10
13
|
this.executionContext = executionContext;
|
|
11
14
|
this.relationPath = relationPath;
|
|
12
15
|
this.settings = settings;
|
|
16
|
+
this.providers = providers;
|
|
13
17
|
}
|
|
14
18
|
visitColumn({ entity, column }) {
|
|
15
19
|
const columnPath = this.executionContext.path;
|
|
16
|
-
const
|
|
20
|
+
const tablePath = columnPath.back();
|
|
21
|
+
const tableAlias = tablePath.alias;
|
|
17
22
|
const columnAlias = columnPath.alias;
|
|
18
23
|
let selectFrom = Database.wrapIdentifier(tableAlias) + "." + Database.wrapIdentifier(column.columnName);
|
|
19
24
|
if (column.type === schema.Model.ColumnType.Date && this.settings.shortDateResponse) {
|
|
@@ -25,9 +30,31 @@ class FieldsVisitor {
|
|
|
25
30
|
if (column.type === schema.Model.ColumnType.Enum && column.list) {
|
|
26
31
|
selectFrom += "::text[]";
|
|
27
32
|
}
|
|
33
|
+
let columnValueGetter = void 0;
|
|
34
|
+
if (entity.view && column.name === entity.primary && column.type === schema.Model.ColumnType.Uuid) {
|
|
35
|
+
if (entity.view.idSource) {
|
|
36
|
+
const aliases = [];
|
|
37
|
+
for (const source of entity.view.idSource) {
|
|
38
|
+
const columnName = schemaUtils.getColumnName(this.schema, entity, source);
|
|
39
|
+
const idSrcPath = columnPath.for(source + "__id_src");
|
|
40
|
+
aliases.push(idSrcPath.alias);
|
|
41
|
+
this.executionContext.addColumn({
|
|
42
|
+
query: (qb) => qb.select([tableAlias, columnName], idSrcPath.alias)
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
columnValueGetter = (row) => {
|
|
46
|
+
return viewComputedId.viewComputedId(aliases.map((it) => row[it]?.toString() || ""));
|
|
47
|
+
};
|
|
48
|
+
} else {
|
|
49
|
+
columnValueGetter = (row) => {
|
|
50
|
+
return row[columnAlias] ?? this.providers.uuid({ version: this.settings.uuidVersion });
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
28
54
|
this.executionContext.addColumn({
|
|
29
55
|
query: (qb) => qb.select(new Database.Literal(selectFrom), columnAlias),
|
|
30
|
-
predicate: this.getRequiredPredicate(entity, column)
|
|
56
|
+
predicate: this.getRequiredPredicate(entity, column),
|
|
57
|
+
valueGetter: columnValueGetter
|
|
31
58
|
});
|
|
32
59
|
}
|
|
33
60
|
visitManyHasManyInverse(relationContext) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldsVisitor.cjs","sources":["../../../../../../../packages/engine-content-api/src/mapper/select/handlers/FieldsVisitor.ts"],"sourcesContent":["import { Acl, Input, Model, Settings } from '@contember/schema'\nimport { Mapper } from '../../Mapper'\nimport { RelationFetcher } from '../RelationFetcher'\nimport { SelectExecutionHandlerContext } from '../SelectExecutionHandler'\nimport { PredicateFactory } from '../../../acl'\nimport { Literal, wrapIdentifier } from '@contember/database'\n\nexport class FieldsVisitor implements Model.RelationByTypeVisitor<void>, Model.ColumnVisitor<void> {\n\tconstructor(\n\t\tprivate readonly relationFetcher: RelationFetcher,\n\t\tprivate readonly predicateFactory: PredicateFactory,\n\t\tprivate readonly mapper: Mapper,\n\t\tprivate readonly executionContext: SelectExecutionHandlerContext,\n\t\tprivate readonly relationPath: Model.AnyRelationContext[],\n\t\tprivate readonly settings: Settings.ContentSettings,\n\t) {}\n\n\tvisitColumn({ entity, column }: Model.ColumnContext): void {\n\t\tconst columnPath = this.executionContext.path\n\t\tconst tableAlias = columnPath.back().alias\n\t\tconst columnAlias = columnPath.alias\n\n\t\tlet selectFrom = wrapIdentifier(tableAlias) + '.' + wrapIdentifier(column.columnName)\n\t\tif (column.type === Model.ColumnType.Date && this.settings.shortDateResponse) {\n\t\t\tselectFrom += '::text'\n\t\t}\n\t\tif (column.type === Model.ColumnType.DateTime && this.settings.fullDateTimeResponse) {\n\t\t\tselectFrom += '::text'\n\t\t}\n\t\tif (column.type === Model.ColumnType.Enum && column.list) {\n\t\t\tselectFrom += '::text[]'\n\t\t}\n\n\t\tthis.executionContext.addColumn({\n\t\t\tquery: qb => qb.select(new Literal(selectFrom), columnAlias),\n\t\t\tpredicate: this.getRequiredPredicate(entity, column),\n\t\t})\n\t}\n\n\tpublic visitManyHasManyInverse(relationContext: Model.ManyHasManyInverseContext): void {\n\t\tconst field = this.executionContext.objectNode\n\t\tif (!field) {\n\t\t\tthrow new Error()\n\t\t}\n\t\tthis.executionContext.addData({\n\t\t\tfield: relationContext.entity.primary,\n\t\t\tdataProvider: async ids =>\n\t\t\t\tthis.relationFetcher.fetchManyHasManyGroups({\n\t\t\t\t\tmapper: this.mapper,\n\t\t\t\t\tfield: field,\n\t\t\t\t\trelationContext,\n\t\t\t\t\trelationPath: this.relationPath,\n\t\t\t\t\tids: ids,\n\t\t\t\t}),\n\t\t\tdefaultValue: [],\n\t\t\tpredicate: this.getRequiredPredicate(relationContext.entity, relationContext.relation),\n\t\t})\n\t}\n\n\tpublic visitManyHasManyOwning(relationContext: Model.ManyHasManyOwningContext): void {\n\t\tconst field = this.executionContext.objectNode\n\t\tif (!field) {\n\t\t\tthrow new Error()\n\t\t}\n\n\t\tthis.executionContext.addData({\n\t\t\tfield: relationContext.entity.primary,\n\t\t\tdataProvider: async ids =>\n\t\t\t\tthis.relationFetcher.fetchManyHasManyGroups({\n\t\t\t\t\tmapper: this.mapper,\n\t\t\t\t\tfield: field,\n\t\t\t\t\trelationContext,\n\t\t\t\t\trelationPath: this.relationPath,\n\t\t\t\t\tids: ids,\n\t\t\t\t}),\n\t\t\tdefaultValue: [],\n\t\t\tpredicate: this.getRequiredPredicate(relationContext.entity, relationContext.relation),\n\t\t})\n\t}\n\n\tpublic visitOneHasMany(relationContext: Model.OneHasManyContext): void {\n\t\tconst field = this.executionContext.objectNode\n\t\tif (!field) {\n\t\t\tthrow new Error()\n\t\t}\n\n\t\tthis.executionContext.addData({\n\t\t\tfield: relationContext.entity.primary,\n\t\t\tdataProvider: async ids =>\n\t\t\t\tthis.relationFetcher.fetchOneHasManyGroups({\n\t\t\t\t\tmapper: this.mapper,\n\t\t\t\t\tobjectNode: field,\n\t\t\t\t\trelationContext,\n\t\t\t\t\trelationPath: this.relationPath,\n\t\t\t\t\tids: ids,\n\t\t\t\t}),\n\t\t\tdefaultValue: [],\n\t\t\tpredicate: this.getRequiredPredicate(relationContext.entity, relationContext.relation),\n\t\t})\n\t}\n\n\tpublic visitOneHasOneInverse(relationContext: Model.OneHasOneInverseContext): void {\n\t\tconst { entity, targetRelation, targetEntity } = relationContext\n\t\tthis.executionContext.addData({\n\t\t\tfield: entity.primary,\n\t\t\tdataProvider: async ids => {\n\t\t\t\tconst idsWhere: Input.Where = {\n\t\t\t\t\t[targetRelation.name]: {\n\t\t\t\t\t\t[entity.primary]: {\n\t\t\t\t\t\t\tin: ids,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t\tconst field = this.executionContext.objectNode\n\t\t\t\tif (!field) {\n\t\t\t\t\tthrow new Error()\n\t\t\t\t}\n\t\t\t\tconst where: Input.Where = {\n\t\t\t\t\tand: [idsWhere, field.args.filter].filter((it): it is Input.Where => it !== undefined),\n\t\t\t\t}\n\t\t\t\tconst objectWithWhere = field.withArg('filter', where)\n\n\t\t\t\treturn this.mapper.selectAssoc(targetEntity, objectWithWhere, [\n\t\t\t\t\t...this.relationPath,\n\t\t\t\t\trelationContext,\n\t\t\t\t], targetRelation.name)\n\t\t\t},\n\t\t\tdefaultValue: null,\n\t\t\tpredicate: this.getRequiredPredicate(relationContext.entity, relationContext.relation),\n\t\t})\n\t}\n\n\tpublic visitOneHasOneOwning(relationContext: Model.OneHasOneOwningContext): void {\n\t\tconst { relation, targetEntity } = relationContext\n\t\tthis.executionContext.addData({\n\t\t\tfield: relation.name,\n\t\t\tdataProvider: async ids => {\n\t\t\t\tconst idsWhere: Input.Where = {\n\t\t\t\t\t[targetEntity.primary]: {\n\t\t\t\t\t\tin: ids,\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t\tconst objectNode = this.executionContext.objectNode\n\t\t\t\tif (!objectNode) {\n\t\t\t\t\tthrow new Error()\n\t\t\t\t}\n\t\t\t\tconst where: Input.Where = {\n\t\t\t\t\tand: [idsWhere, objectNode.args.filter].filter((it): it is Input.Where => it !== undefined),\n\t\t\t\t}\n\t\t\t\tconst objectWithWhere = objectNode.withArg('filter', where)\n\n\t\t\t\treturn this.mapper.selectAssoc(targetEntity, objectWithWhere, [\n\t\t\t\t\t...this.relationPath,\n\t\t\t\t\trelationContext,\n\t\t\t\t], targetEntity.primary)\n\t\t\t},\n\t\t\tdefaultValue: null,\n\t\t\tpredicate: this.getRequiredPredicate(relationContext.entity, relationContext.relation),\n\t\t})\n\t}\n\n\tpublic visitManyHasOne(relationContext: Model.ManyHasOneContext): void {\n\t\tconst { relation, targetEntity } = relationContext\n\t\tthis.executionContext.addData({\n\t\t\tfield: relation.name,\n\t\t\tdataProvider: async ids => {\n\t\t\t\tconst idsWhere: Input.Where = {\n\t\t\t\t\t[targetEntity.primary]: {\n\t\t\t\t\t\tin: ids,\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t\tconst objectNode = this.executionContext.objectNode\n\t\t\t\tif (!objectNode) {\n\t\t\t\t\tthrow new Error()\n\t\t\t\t}\n\t\t\t\tconst where: Input.Where = {\n\t\t\t\t\tand: [idsWhere, objectNode.args.filter].filter((it): it is Input.Where => it !== undefined),\n\t\t\t\t}\n\t\t\t\tconst objectWithWhere = objectNode.withArg('filter', where)\n\n\t\t\t\treturn this.mapper.selectAssoc(targetEntity, objectWithWhere, [\n\t\t\t\t\t...this.relationPath,\n\t\t\t\t\trelationContext,\n\t\t\t\t], targetEntity.primary)\n\t\t\t},\n\t\t\tdefaultValue: null,\n\t\t\tpredicate: this.getRequiredPredicate(relationContext.entity, relationContext.relation),\n\t\t})\n\t}\n\n\tprivate getRequiredPredicate(entity: Model.Entity, field: Model.AnyField): Acl.Predicate | undefined {\n\t\tconst fieldPredicate = this.predicateFactory.getFieldPredicate(entity, Acl.Operation.read, field.name)\n\t\treturn fieldPredicate.isSameAsPrimary ? undefined : fieldPredicate.predicate\n\t}\n}\n"],"names":["wrapIdentifier","Model","Literal","Acl"],"mappings":";;;;AAOO,MAAM,cAAsF;AAAA,EAClG,YACkB,iBACA,kBACA,QACA,kBACA,cACA,UAChB;AANgB,SAAA,kBAAA;AACA,SAAA,mBAAA;AACA,SAAA,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K,iBAAiB,QAAQ;AAAA,MAC7B,OAAO,SAAS;AAAA,MAChB,cAAc,OAAM,QAAO;AAC1B,cAAM,WAAwB;AAAA,UAC7B,CAAC,aAAa,OAAO,GAAG;AAAA,YACvB,IAAI;AAAA,UAAA;AAAA,QAEN;AACM,cAAA,aAAa,KAAK,iBAAiB;AACzC,YAAI,CAAC,YAAY;AAChB,gBAAM,IAAI,MAAM;AAAA,QAAA;AAEjB,cAAM,QAAqB;AAAA,UAC1B,KAAK,CAAC,UAAU,WAAW,KAAK,MAAM,EAAE,OAAO,CAAC,OAA0B,OAAO,MAAS;AAAA,QAC3F;AACA,cAAM,kBAAkB,WAAW,QAAQ,UAAU,KAAK;AAE1D,eAAO,KAAK,OAAO,YAAY,cAAc,iBAAiB;AAAA,UAC7D,GAAG,KAAK;AAAA,UACR;AAAA,QAAA,GACE,aAAa,OAAO;AAAA,MACxB;AAAA,MACA,cAAc;AAAA,MACd,WAAW,KAAK,qBAAqB,gBAAgB,QAAQ,gBAAgB,QAAQ;AAAA,IAAA,CACrF;AAAA,EAAA;AAAA,EAGM,qBAAqB,QAAsB,OAAkD;AAC9F,UAAA,iBAAiB,KAAK,iBAAiB,kBAAkB,QAAQC,OAAI,IAAA,UAAU,MAAM,MAAM,IAAI;AAC9F,WAAA,eAAe,kBAAkB,SAAY,eAAe;AAAA,EAAA;AAErE;;"}
|
|
1
|
+
{"version":3,"file":"FieldsVisitor.cjs","sources":["../../../../../../../packages/engine-content-api/src/mapper/select/handlers/FieldsVisitor.ts"],"sourcesContent":["import { Acl, Input, Model, Settings } from '@contember/schema'\nimport { Mapper } from '../../Mapper'\nimport { RelationFetcher } from '../RelationFetcher'\nimport { SelectExecutionHandlerContext } from '../SelectExecutionHandler'\nimport { PredicateFactory } from '../../../acl'\nimport { Literal, wrapIdentifier } from '@contember/database'\nimport { ColumnValueGetter } from '../SelectHydrator'\nimport { Providers } from '@contember/schema-utils'\nimport { getColumnName } from '@contember/schema-utils'\nimport { viewComputedId } from '../../../utils/viewComputedId'\n\nexport class FieldsVisitor implements Model.RelationByTypeVisitor<void>, Model.ColumnVisitor<void> {\n\tconstructor(\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly relationFetcher: RelationFetcher,\n\t\tprivate readonly predicateFactory: PredicateFactory,\n\t\tprivate readonly mapper: Mapper,\n\t\tprivate readonly executionContext: SelectExecutionHandlerContext,\n\t\tprivate readonly relationPath: Model.AnyRelationContext[],\n\t\tprivate readonly settings: Settings.ContentSettings,\n\t\tprivate readonly providers: Providers,\n\t) {}\n\n\tvisitColumn({ entity, column }: Model.ColumnContext): void {\n\t\tconst columnPath = this.executionContext.path\n\t\tconst tablePath = columnPath.back()\n\t\tconst tableAlias = tablePath.alias\n\t\tconst columnAlias = columnPath.alias\n\n\t\tlet selectFrom = wrapIdentifier(tableAlias) + '.' + wrapIdentifier(column.columnName)\n\t\tif (column.type === Model.ColumnType.Date && this.settings.shortDateResponse) {\n\t\t\tselectFrom += '::text'\n\t\t}\n\t\tif (column.type === Model.ColumnType.DateTime && this.settings.fullDateTimeResponse) {\n\t\t\tselectFrom += '::text'\n\t\t}\n\t\tif (column.type === Model.ColumnType.Enum && column.list) {\n\t\t\tselectFrom += '::text[]'\n\t\t}\n\n\t\tlet columnValueGetter: ColumnValueGetter | undefined = undefined\n\t\tif (entity.view && column.name === entity.primary && column.type === Model.ColumnType.Uuid) {\n\t\t\tif (entity.view.idSource) {\n\t\t\t\tconst aliases: string[] = []\n\t\t\t\tfor (const source of entity.view.idSource) {\n\t\t\t\t\tconst columnName = getColumnName(this.schema, entity, source)\n\t\t\t\t\tconst idSrcPath = columnPath.for(source + '__id_src')\n\t\t\t\t\taliases.push(idSrcPath.alias)\n\t\t\t\t\tthis.executionContext.addColumn({\n\t\t\t\t\t\tquery: qb => qb.select([tableAlias, columnName], idSrcPath.alias),\n\t\t\t\t\t})\n\t\t\t\t}\n\n\t\t\t\tcolumnValueGetter = row => {\n\t\t\t\t\treturn viewComputedId(aliases.map(it => row[it]?.toString() || ''))\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tcolumnValueGetter = row => {\n\t\t\t\t\treturn row[columnAlias] ?? (this.providers.uuid({ version: this.settings.uuidVersion }))\n\t\t\t\t}\n\n\t\t\t}\n\t\t}\n\n\t\tthis.executionContext.addColumn({\n\t\t\tquery: qb => qb.select(new Literal(selectFrom), columnAlias),\n\t\t\tpredicate: this.getRequiredPredicate(entity, column),\n\t\t\tvalueGetter: columnValueGetter,\n\t\t})\n\t}\n\n\tpublic visitManyHasManyInverse(relationContext: Model.ManyHasManyInverseContext): void {\n\t\tconst field = this.executionContext.objectNode\n\t\tif (!field) {\n\t\t\tthrow new Error()\n\t\t}\n\t\tthis.executionContext.addData({\n\t\t\tfield: relationContext.entity.primary,\n\t\t\tdataProvider: async ids =>\n\t\t\t\tthis.relationFetcher.fetchManyHasManyGroups({\n\t\t\t\t\tmapper: this.mapper,\n\t\t\t\t\tfield: field,\n\t\t\t\t\trelationContext,\n\t\t\t\t\trelationPath: this.relationPath,\n\t\t\t\t\tids: ids,\n\t\t\t\t}),\n\t\t\tdefaultValue: [],\n\t\t\tpredicate: this.getRequiredPredicate(relationContext.entity, relationContext.relation),\n\t\t})\n\t}\n\n\tpublic visitManyHasManyOwning(relationContext: Model.ManyHasManyOwningContext): void {\n\t\tconst field = this.executionContext.objectNode\n\t\tif (!field) {\n\t\t\tthrow new Error()\n\t\t}\n\n\t\tthis.executionContext.addData({\n\t\t\tfield: relationContext.entity.primary,\n\t\t\tdataProvider: async ids =>\n\t\t\t\tthis.relationFetcher.fetchManyHasManyGroups({\n\t\t\t\t\tmapper: this.mapper,\n\t\t\t\t\tfield: field,\n\t\t\t\t\trelationContext,\n\t\t\t\t\trelationPath: this.relationPath,\n\t\t\t\t\tids: ids,\n\t\t\t\t}),\n\t\t\tdefaultValue: [],\n\t\t\tpredicate: this.getRequiredPredicate(relationContext.entity, relationContext.relation),\n\t\t})\n\t}\n\n\tpublic visitOneHasMany(relationContext: Model.OneHasManyContext): void {\n\t\tconst field = this.executionContext.objectNode\n\t\tif (!field) {\n\t\t\tthrow new Error()\n\t\t}\n\n\t\tthis.executionContext.addData({\n\t\t\tfield: relationContext.entity.primary,\n\t\t\tdataProvider: async ids =>\n\t\t\t\tthis.relationFetcher.fetchOneHasManyGroups({\n\t\t\t\t\tmapper: this.mapper,\n\t\t\t\t\tobjectNode: field,\n\t\t\t\t\trelationContext,\n\t\t\t\t\trelationPath: this.relationPath,\n\t\t\t\t\tids: ids,\n\t\t\t\t}),\n\t\t\tdefaultValue: [],\n\t\t\tpredicate: this.getRequiredPredicate(relationContext.entity, relationContext.relation),\n\t\t})\n\t}\n\n\tpublic visitOneHasOneInverse(relationContext: Model.OneHasOneInverseContext): void {\n\t\tconst { entity, targetRelation, targetEntity } = relationContext\n\t\tthis.executionContext.addData({\n\t\t\tfield: entity.primary,\n\t\t\tdataProvider: async ids => {\n\t\t\t\tconst idsWhere: Input.Where = {\n\t\t\t\t\t[targetRelation.name]: {\n\t\t\t\t\t\t[entity.primary]: {\n\t\t\t\t\t\t\tin: ids,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t\tconst field = this.executionContext.objectNode\n\t\t\t\tif (!field) {\n\t\t\t\t\tthrow new Error()\n\t\t\t\t}\n\t\t\t\tconst where: Input.Where = {\n\t\t\t\t\tand: [idsWhere, field.args.filter].filter((it): it is Input.Where => it !== undefined),\n\t\t\t\t}\n\t\t\t\tconst objectWithWhere = field.withArg('filter', where)\n\n\t\t\t\treturn this.mapper.selectAssoc(targetEntity, objectWithWhere, [\n\t\t\t\t\t...this.relationPath,\n\t\t\t\t\trelationContext,\n\t\t\t\t], targetRelation.name)\n\t\t\t},\n\t\t\tdefaultValue: null,\n\t\t\tpredicate: this.getRequiredPredicate(relationContext.entity, relationContext.relation),\n\t\t})\n\t}\n\n\tpublic visitOneHasOneOwning(relationContext: Model.OneHasOneOwningContext): void {\n\t\tconst { relation, targetEntity } = relationContext\n\t\tthis.executionContext.addData({\n\t\t\tfield: relation.name,\n\t\t\tdataProvider: async ids => {\n\t\t\t\tconst idsWhere: Input.Where = {\n\t\t\t\t\t[targetEntity.primary]: {\n\t\t\t\t\t\tin: ids,\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t\tconst objectNode = this.executionContext.objectNode\n\t\t\t\tif (!objectNode) {\n\t\t\t\t\tthrow new Error()\n\t\t\t\t}\n\t\t\t\tconst where: Input.Where = {\n\t\t\t\t\tand: [idsWhere, objectNode.args.filter].filter((it): it is Input.Where => it !== undefined),\n\t\t\t\t}\n\t\t\t\tconst objectWithWhere = objectNode.withArg('filter', where)\n\n\t\t\t\treturn this.mapper.selectAssoc(targetEntity, objectWithWhere, [\n\t\t\t\t\t...this.relationPath,\n\t\t\t\t\trelationContext,\n\t\t\t\t], targetEntity.primary)\n\t\t\t},\n\t\t\tdefaultValue: null,\n\t\t\tpredicate: this.getRequiredPredicate(relationContext.entity, relationContext.relation),\n\t\t})\n\t}\n\n\tpublic visitManyHasOne(relationContext: Model.ManyHasOneContext): void {\n\t\tconst { relation, targetEntity } = relationContext\n\t\tthis.executionContext.addData({\n\t\t\tfield: relation.name,\n\t\t\tdataProvider: async ids => {\n\t\t\t\tconst idsWhere: Input.Where = {\n\t\t\t\t\t[targetEntity.primary]: {\n\t\t\t\t\t\tin: ids,\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t\tconst objectNode = this.executionContext.objectNode\n\t\t\t\tif (!objectNode) {\n\t\t\t\t\tthrow new Error()\n\t\t\t\t}\n\t\t\t\tconst where: Input.Where = {\n\t\t\t\t\tand: [idsWhere, objectNode.args.filter].filter((it): it is Input.Where => it !== undefined),\n\t\t\t\t}\n\t\t\t\tconst objectWithWhere = objectNode.withArg('filter', where)\n\n\t\t\t\treturn this.mapper.selectAssoc(targetEntity, objectWithWhere, [\n\t\t\t\t\t...this.relationPath,\n\t\t\t\t\trelationContext,\n\t\t\t\t], targetEntity.primary)\n\t\t\t},\n\t\t\tdefaultValue: null,\n\t\t\tpredicate: this.getRequiredPredicate(relationContext.entity, relationContext.relation),\n\t\t})\n\t}\n\n\tprivate getRequiredPredicate(entity: Model.Entity, field: Model.AnyField): Acl.Predicate | undefined {\n\t\tconst fieldPredicate = this.predicateFactory.getFieldPredicate(entity, Acl.Operation.read, field.name)\n\t\treturn fieldPredicate.isSameAsPrimary ? undefined : fieldPredicate.predicate\n\t}\n}\n"],"names":["schema","wrapIdentifier","Model","getColumnName","viewComputedId","Literal","Acl"],"mappings":";;;;;;AAWO,MAAM,cAAsF;AAAA,EAClG,YACkBA,SACA,iBACA,kBACA,QACA,kBACA,cACA,UACA,WAChB;AARgB,SAAA,SAAAA;AACA,SAAA,kBAAA;AACA,SAAA,mBAAA;AACA,SAAA,SAAA;AACA,SAAA,mBAAA;AACA,SAAA,eAAA;AACA,SAAA,WAAA;AACA,SAAA,YAAA;AAAA,EAAA;AAAA,EAGlB,YAAY,EAAE,QAAQ,UAAqC;AACpD,UAAA,aAAa,KAAK,iBAAiB;AACnC,UAAA,YAAY,WAAW,KAAK;AAClC,UAAM,aAAa,UAAU;AAC7B,UAAM,cAAc,WAAW;AAE/B,QAAI,aAAaC,SAAAA,eAAe,UAAU,IAAI,MAAMA,SAAA,eAAe,OAAO,UAAU;AACpF,QAAI,OAAO,SAASC,aAAM,WAAW,QAAQ,KAAK,SAAS,mBAAmB;AAC/D,oBAAA;AAAA,IAAA;AAEf,QAAI,OAAO,SAASA,aAAM,WAAW,YAAY,KAAK,SAAS,sBAAsB;AACtE,oBAAA;AAAA,IAAA;AAEf,QAAI,OAAO,SAASA,OAAA,MAAM,WAAW,QAAQ,OAAO,MAAM;AAC3C,oBAAA;AAAA,IAAA;AAGf,QAAI,oBAAmD;AACnD,QAAA,OAAO,QAAQ,OAAO,SAAS,OAAO,WAAW,OAAO,SAASA,aAAM,WAAW,MAAM;AACvF,UAAA,OAAO,KAAK,UAAU;AACzB,cAAM,UAAoB,CAAC;AAChB,mBAA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AgD;AAChE,UAAA,EAAE,UAAU,aAAA,IAAiB;AACnC,SAAK,iBAAiB,QAAQ;AAAA,MAC7B,OAAO,SAAS;AAAA,MAChB,cAAc,OAAM,QAAO;AAC1B,cAAM,WAAwB;AAAA,UAC7B,CAAC,aAAa,OAAO,GAAG;AAAA,YACvB,IAAI;AAAA,UAAA;AAAA,QAEN;AACM,cAAA,aAAa,KAAK,iBAAiB;AACzC,YAAI,CAAC,YAAY;AAChB,gBAAM,IAAI,MAAM;AAAA,QAAA;AAEjB,cAAM,QAAqB;AAAA,UAC1B,KAAK,CAAC,UAAU,WAAW,KAAK,MAAM,EAAE,OAAO,CAAC,OAA0B,OAAO,MAAS;AAAA,QAC3F;AACA,cAAM,kBAAkB,WAAW,QAAQ,UAAU,KAAK;AAE1D,eAAO,KAAK,OAAO,YAAY,cAAc,iBAAiB;AAAA,UAC7D,GAAG,KAAK;AAAA,UACR;AAAA,QAAA,GACE,aAAa,OAAO;AAAA,MACxB;AAAA,MACA,cAAc;AAAA,MACd,WAAW,KAAK,qBAAqB,gBAAgB,QAAQ,gBAAgB,QAAQ;AAAA,IAAA,CACrF;AAAA,EAAA;AAAA,EAGM,qBAAqB,QAAsB,OAAkD;AAC9F,UAAA,iBAAiB,KAAK,iBAAiB,kBAAkB,QAAQC,OAAI,IAAA,UAAU,MAAM,MAAM,IAAI;AAC9F,WAAA,eAAe,kBAAkB,SAAY,eAAe;AAAA,EAAA;AAErE;;"}
|
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
import { Model, Acl } from "@contember/schema";
|
|
2
2
|
import { wrapIdentifier, Literal } from "@contember/database";
|
|
3
|
+
import { getColumnName } from "@contember/schema-utils";
|
|
4
|
+
import { viewComputedId } from "../../../utils/viewComputedId.js";
|
|
3
5
|
class FieldsVisitor {
|
|
4
|
-
constructor(relationFetcher, predicateFactory, mapper, executionContext, relationPath, settings) {
|
|
6
|
+
constructor(schema, relationFetcher, predicateFactory, mapper, executionContext, relationPath, settings, providers) {
|
|
7
|
+
this.schema = schema;
|
|
5
8
|
this.relationFetcher = relationFetcher;
|
|
6
9
|
this.predicateFactory = predicateFactory;
|
|
7
10
|
this.mapper = mapper;
|
|
8
11
|
this.executionContext = executionContext;
|
|
9
12
|
this.relationPath = relationPath;
|
|
10
13
|
this.settings = settings;
|
|
14
|
+
this.providers = providers;
|
|
11
15
|
}
|
|
12
16
|
visitColumn({ entity, column }) {
|
|
13
17
|
const columnPath = this.executionContext.path;
|
|
14
|
-
const
|
|
18
|
+
const tablePath = columnPath.back();
|
|
19
|
+
const tableAlias = tablePath.alias;
|
|
15
20
|
const columnAlias = columnPath.alias;
|
|
16
21
|
let selectFrom = wrapIdentifier(tableAlias) + "." + wrapIdentifier(column.columnName);
|
|
17
22
|
if (column.type === Model.ColumnType.Date && this.settings.shortDateResponse) {
|
|
@@ -23,9 +28,31 @@ class FieldsVisitor {
|
|
|
23
28
|
if (column.type === Model.ColumnType.Enum && column.list) {
|
|
24
29
|
selectFrom += "::text[]";
|
|
25
30
|
}
|
|
31
|
+
let columnValueGetter = void 0;
|
|
32
|
+
if (entity.view && column.name === entity.primary && column.type === Model.ColumnType.Uuid) {
|
|
33
|
+
if (entity.view.idSource) {
|
|
34
|
+
const aliases = [];
|
|
35
|
+
for (const source of entity.view.idSource) {
|
|
36
|
+
const columnName = getColumnName(this.schema, entity, source);
|
|
37
|
+
const idSrcPath = columnPath.for(source + "__id_src");
|
|
38
|
+
aliases.push(idSrcPath.alias);
|
|
39
|
+
this.executionContext.addColumn({
|
|
40
|
+
query: (qb) => qb.select([tableAlias, columnName], idSrcPath.alias)
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
columnValueGetter = (row) => {
|
|
44
|
+
return viewComputedId(aliases.map((it) => row[it]?.toString() || ""));
|
|
45
|
+
};
|
|
46
|
+
} else {
|
|
47
|
+
columnValueGetter = (row) => {
|
|
48
|
+
return row[columnAlias] ?? this.providers.uuid({ version: this.settings.uuidVersion });
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
26
52
|
this.executionContext.addColumn({
|
|
27
53
|
query: (qb) => qb.select(new Literal(selectFrom), columnAlias),
|
|
28
|
-
predicate: this.getRequiredPredicate(entity, column)
|
|
54
|
+
predicate: this.getRequiredPredicate(entity, column),
|
|
55
|
+
valueGetter: columnValueGetter
|
|
29
56
|
});
|
|
30
57
|
}
|
|
31
58
|
visitManyHasManyInverse(relationContext) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldsVisitor.js","sources":["../../../../../../../packages/engine-content-api/src/mapper/select/handlers/FieldsVisitor.ts"],"sourcesContent":["import { Acl, Input, Model, Settings } from '@contember/schema'\nimport { Mapper } from '../../Mapper'\nimport { RelationFetcher } from '../RelationFetcher'\nimport { SelectExecutionHandlerContext } from '../SelectExecutionHandler'\nimport { PredicateFactory } from '../../../acl'\nimport { Literal, wrapIdentifier } from '@contember/database'\n\nexport class FieldsVisitor implements Model.RelationByTypeVisitor<void>, Model.ColumnVisitor<void> {\n\tconstructor(\n\t\tprivate readonly relationFetcher: RelationFetcher,\n\t\tprivate readonly predicateFactory: PredicateFactory,\n\t\tprivate readonly mapper: Mapper,\n\t\tprivate readonly executionContext: SelectExecutionHandlerContext,\n\t\tprivate readonly relationPath: Model.AnyRelationContext[],\n\t\tprivate readonly settings: Settings.ContentSettings,\n\t) {}\n\n\tvisitColumn({ entity, column }: Model.ColumnContext): void {\n\t\tconst columnPath = this.executionContext.path\n\t\tconst tableAlias = columnPath.back().alias\n\t\tconst columnAlias = columnPath.alias\n\n\t\tlet selectFrom = wrapIdentifier(tableAlias) + '.' + wrapIdentifier(column.columnName)\n\t\tif (column.type === Model.ColumnType.Date && this.settings.shortDateResponse) {\n\t\t\tselectFrom += '::text'\n\t\t}\n\t\tif (column.type === Model.ColumnType.DateTime && this.settings.fullDateTimeResponse) {\n\t\t\tselectFrom += '::text'\n\t\t}\n\t\tif (column.type === Model.ColumnType.Enum && column.list) {\n\t\t\tselectFrom += '::text[]'\n\t\t}\n\n\t\tthis.executionContext.addColumn({\n\t\t\tquery: qb => qb.select(new Literal(selectFrom), columnAlias),\n\t\t\tpredicate: this.getRequiredPredicate(entity, column),\n\t\t})\n\t}\n\n\tpublic visitManyHasManyInverse(relationContext: Model.ManyHasManyInverseContext): void {\n\t\tconst field = this.executionContext.objectNode\n\t\tif (!field) {\n\t\t\tthrow new Error()\n\t\t}\n\t\tthis.executionContext.addData({\n\t\t\tfield: relationContext.entity.primary,\n\t\t\tdataProvider: async ids =>\n\t\t\t\tthis.relationFetcher.fetchManyHasManyGroups({\n\t\t\t\t\tmapper: this.mapper,\n\t\t\t\t\tfield: field,\n\t\t\t\t\trelationContext,\n\t\t\t\t\trelationPath: this.relationPath,\n\t\t\t\t\tids: ids,\n\t\t\t\t}),\n\t\t\tdefaultValue: [],\n\t\t\tpredicate: this.getRequiredPredicate(relationContext.entity, relationContext.relation),\n\t\t})\n\t}\n\n\tpublic visitManyHasManyOwning(relationContext: Model.ManyHasManyOwningContext): void {\n\t\tconst field = this.executionContext.objectNode\n\t\tif (!field) {\n\t\t\tthrow new Error()\n\t\t}\n\n\t\tthis.executionContext.addData({\n\t\t\tfield: relationContext.entity.primary,\n\t\t\tdataProvider: async ids =>\n\t\t\t\tthis.relationFetcher.fetchManyHasManyGroups({\n\t\t\t\t\tmapper: this.mapper,\n\t\t\t\t\tfield: field,\n\t\t\t\t\trelationContext,\n\t\t\t\t\trelationPath: this.relationPath,\n\t\t\t\t\tids: ids,\n\t\t\t\t}),\n\t\t\tdefaultValue: [],\n\t\t\tpredicate: this.getRequiredPredicate(relationContext.entity, relationContext.relation),\n\t\t})\n\t}\n\n\tpublic visitOneHasMany(relationContext: Model.OneHasManyContext): void {\n\t\tconst field = this.executionContext.objectNode\n\t\tif (!field) {\n\t\t\tthrow new Error()\n\t\t}\n\n\t\tthis.executionContext.addData({\n\t\t\tfield: relationContext.entity.primary,\n\t\t\tdataProvider: async ids =>\n\t\t\t\tthis.relationFetcher.fetchOneHasManyGroups({\n\t\t\t\t\tmapper: this.mapper,\n\t\t\t\t\tobjectNode: field,\n\t\t\t\t\trelationContext,\n\t\t\t\t\trelationPath: this.relationPath,\n\t\t\t\t\tids: ids,\n\t\t\t\t}),\n\t\t\tdefaultValue: [],\n\t\t\tpredicate: this.getRequiredPredicate(relationContext.entity, relationContext.relation),\n\t\t})\n\t}\n\n\tpublic visitOneHasOneInverse(relationContext: Model.OneHasOneInverseContext): void {\n\t\tconst { entity, targetRelation, targetEntity } = relationContext\n\t\tthis.executionContext.addData({\n\t\t\tfield: entity.primary,\n\t\t\tdataProvider: async ids => {\n\t\t\t\tconst idsWhere: Input.Where = {\n\t\t\t\t\t[targetRelation.name]: {\n\t\t\t\t\t\t[entity.primary]: {\n\t\t\t\t\t\t\tin: ids,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t\tconst field = this.executionContext.objectNode\n\t\t\t\tif (!field) {\n\t\t\t\t\tthrow new Error()\n\t\t\t\t}\n\t\t\t\tconst where: Input.Where = {\n\t\t\t\t\tand: [idsWhere, field.args.filter].filter((it): it is Input.Where => it !== undefined),\n\t\t\t\t}\n\t\t\t\tconst objectWithWhere = field.withArg('filter', where)\n\n\t\t\t\treturn this.mapper.selectAssoc(targetEntity, objectWithWhere, [\n\t\t\t\t\t...this.relationPath,\n\t\t\t\t\trelationContext,\n\t\t\t\t], targetRelation.name)\n\t\t\t},\n\t\t\tdefaultValue: null,\n\t\t\tpredicate: this.getRequiredPredicate(relationContext.entity, relationContext.relation),\n\t\t})\n\t}\n\n\tpublic visitOneHasOneOwning(relationContext: Model.OneHasOneOwningContext): void {\n\t\tconst { relation, targetEntity } = relationContext\n\t\tthis.executionContext.addData({\n\t\t\tfield: relation.name,\n\t\t\tdataProvider: async ids => {\n\t\t\t\tconst idsWhere: Input.Where = {\n\t\t\t\t\t[targetEntity.primary]: {\n\t\t\t\t\t\tin: ids,\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t\tconst objectNode = this.executionContext.objectNode\n\t\t\t\tif (!objectNode) {\n\t\t\t\t\tthrow new Error()\n\t\t\t\t}\n\t\t\t\tconst where: Input.Where = {\n\t\t\t\t\tand: [idsWhere, objectNode.args.filter].filter((it): it is Input.Where => it !== undefined),\n\t\t\t\t}\n\t\t\t\tconst objectWithWhere = objectNode.withArg('filter', where)\n\n\t\t\t\treturn this.mapper.selectAssoc(targetEntity, objectWithWhere, [\n\t\t\t\t\t...this.relationPath,\n\t\t\t\t\trelationContext,\n\t\t\t\t], targetEntity.primary)\n\t\t\t},\n\t\t\tdefaultValue: null,\n\t\t\tpredicate: this.getRequiredPredicate(relationContext.entity, relationContext.relation),\n\t\t})\n\t}\n\n\tpublic visitManyHasOne(relationContext: Model.ManyHasOneContext): void {\n\t\tconst { relation, targetEntity } = relationContext\n\t\tthis.executionContext.addData({\n\t\t\tfield: relation.name,\n\t\t\tdataProvider: async ids => {\n\t\t\t\tconst idsWhere: Input.Where = {\n\t\t\t\t\t[targetEntity.primary]: {\n\t\t\t\t\t\tin: ids,\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t\tconst objectNode = this.executionContext.objectNode\n\t\t\t\tif (!objectNode) {\n\t\t\t\t\tthrow new Error()\n\t\t\t\t}\n\t\t\t\tconst where: Input.Where = {\n\t\t\t\t\tand: [idsWhere, objectNode.args.filter].filter((it): it is Input.Where => it !== undefined),\n\t\t\t\t}\n\t\t\t\tconst objectWithWhere = objectNode.withArg('filter', where)\n\n\t\t\t\treturn this.mapper.selectAssoc(targetEntity, objectWithWhere, [\n\t\t\t\t\t...this.relationPath,\n\t\t\t\t\trelationContext,\n\t\t\t\t], targetEntity.primary)\n\t\t\t},\n\t\t\tdefaultValue: null,\n\t\t\tpredicate: this.getRequiredPredicate(relationContext.entity, relationContext.relation),\n\t\t})\n\t}\n\n\tprivate getRequiredPredicate(entity: Model.Entity, field: Model.AnyField): Acl.Predicate | undefined {\n\t\tconst fieldPredicate = this.predicateFactory.getFieldPredicate(entity, Acl.Operation.read, field.name)\n\t\treturn fieldPredicate.isSameAsPrimary ? undefined : fieldPredicate.predicate\n\t}\n}\n"],"names":[],"mappings":";;AAOO,MAAM,cAAsF;AAAA,EAClG,YACkB,iBACA,kBACA,QACA,kBACA,cACA,UAChB;AANgB,SAAA,kBAAA;AACA,SAAA,mBAAA;AACA,SAAA,SAAA;AACA,SAAA,mBAAA;AACA,SAAA,eAAA;AACA,SAAA,WAAA;AAAA,EAAA;AAAA,EAGlB,YAAY,EAAE,QAAQ,UAAqC;AACpD,UAAA,aAAa,KAAK,iBAAiB;AACnC,UAAA,aAAa,WAAW,KAAA,EAAO;AACrC,UAAM,cAAc,WAAW;AAE/B,QAAI,aAAa,eAAe,UAAU,IAAI,MAAM,eAAe,OAAO,UAAU;AACpF,QAAI,OAAO,SAAS,MAAM,WAAW,QAAQ,KAAK,SAAS,mBAAmB;AAC/D,oBAAA;AAAA,IAAA;AAEf,QAAI,OAAO,SAAS,MAAM,WAAW,YAAY,KAAK,SAAS,sBAAsB;AACtE,oBAAA;AAAA,IAAA;AAEf,QAAI,OAAO,SAAS,MAAM,WAAW,QAAQ,OAAO,MAAM;AAC3C,oBAAA;AAAA,IAAA;AAGf,SAAK,iBAAiB,UAAU;AAAA,MAC/B,OAAO,QAAM,GAAG,OAAO,IAAI,QAAQ,UAAU,GAAG,WAAW;AAAA,MAC3D,WAAW,KAAK,qBAAqB,QAAQ,MAAM;AAAA,IAAA,CACnD;AAAA,EAAA;AAAA,EAGK,wBAAwB,iBAAwD;AAChF,UAAA,QAAQ,KAAK,iBAAiB;AACpC,QAAI,CAAC,OAAO;AACX,YAAM,IAAI,MAAM;AAAA,IAAA;AAEjB,SAAK,iBAAiB,QAAQ;AAAA,MAC7B,OAAO,gBAAgB,OAAO;AAAA,MAC9B,cAAc,OAAM,QACnB,KAAK,gBAAgB,uBAAuB;AAAA,QAC3C,QAAQ,KAAK;AAAA,QACb;AAAA,QACA;AAAA,QACA,cAAc,KA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Aa,OAAO;AAAA,MACxB;AAAA,MACA,cAAc;AAAA,MACd,WAAW,KAAK,qBAAqB,gBAAgB,QAAQ,gBAAgB,QAAQ;AAAA,IAAA,CACrF;AAAA,EAAA;AAAA,EAGK,gBAAgB,iBAAgD;AAChE,UAAA,EAAE,UAAU,aAAA,IAAiB;AACnC,SAAK,iBAAiB,QAAQ;AAAA,MAC7B,OAAO,SAAS;AAAA,MAChB,cAAc,OAAM,QAAO;AAC1B,cAAM,WAAwB;AAAA,UAC7B,CAAC,aAAa,OAAO,GAAG;AAAA,YACvB,IAAI;AAAA,UAAA;AAAA,QAEN;AACM,cAAA,aAAa,KAAK,iBAAiB;AACzC,YAAI,CAAC,YAAY;AAChB,gBAAM,IAAI,MAAM;AAAA,QAAA;AAEjB,cAAM,QAAqB;AAAA,UAC1B,KAAK,CAAC,UAAU,WAAW,KAAK,MAAM,EAAE,OAAO,CAAC,OAA0B,OAAO,MAAS;AAAA,QAC3F;AACA,cAAM,kBAAkB,WAAW,QAAQ,UAAU,KAAK;AAE1D,eAAO,KAAK,OAAO,YAAY,cAAc,iBAAiB;AAAA,UAC7D,GAAG,KAAK;AAAA,UACR;AAAA,QAAA,GACE,aAAa,OAAO;AAAA,MACxB;AAAA,MACA,cAAc;AAAA,MACd,WAAW,KAAK,qBAAqB,gBAAgB,QAAQ,gBAAgB,QAAQ;AAAA,IAAA,CACrF;AAAA,EAAA;AAAA,EAGM,qBAAqB,QAAsB,OAAkD;AAC9F,UAAA,iBAAiB,KAAK,iBAAiB,kBAAkB,QAAQ,IAAI,UAAU,MAAM,MAAM,IAAI;AAC9F,WAAA,eAAe,kBAAkB,SAAY,eAAe;AAAA,EAAA;AAErE;"}
|
|
1
|
+
{"version":3,"file":"FieldsVisitor.js","sources":["../../../../../../../packages/engine-content-api/src/mapper/select/handlers/FieldsVisitor.ts"],"sourcesContent":["import { Acl, Input, Model, Settings } from '@contember/schema'\nimport { Mapper } from '../../Mapper'\nimport { RelationFetcher } from '../RelationFetcher'\nimport { SelectExecutionHandlerContext } from '../SelectExecutionHandler'\nimport { PredicateFactory } from '../../../acl'\nimport { Literal, wrapIdentifier } from '@contember/database'\nimport { ColumnValueGetter } from '../SelectHydrator'\nimport { Providers } from '@contember/schema-utils'\nimport { getColumnName } from '@contember/schema-utils'\nimport { viewComputedId } from '../../../utils/viewComputedId'\n\nexport class FieldsVisitor implements Model.RelationByTypeVisitor<void>, Model.ColumnVisitor<void> {\n\tconstructor(\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly relationFetcher: RelationFetcher,\n\t\tprivate readonly predicateFactory: PredicateFactory,\n\t\tprivate readonly mapper: Mapper,\n\t\tprivate readonly executionContext: SelectExecutionHandlerContext,\n\t\tprivate readonly relationPath: Model.AnyRelationContext[],\n\t\tprivate readonly settings: Settings.ContentSettings,\n\t\tprivate readonly providers: Providers,\n\t) {}\n\n\tvisitColumn({ entity, column }: Model.ColumnContext): void {\n\t\tconst columnPath = this.executionContext.path\n\t\tconst tablePath = columnPath.back()\n\t\tconst tableAlias = tablePath.alias\n\t\tconst columnAlias = columnPath.alias\n\n\t\tlet selectFrom = wrapIdentifier(tableAlias) + '.' + wrapIdentifier(column.columnName)\n\t\tif (column.type === Model.ColumnType.Date && this.settings.shortDateResponse) {\n\t\t\tselectFrom += '::text'\n\t\t}\n\t\tif (column.type === Model.ColumnType.DateTime && this.settings.fullDateTimeResponse) {\n\t\t\tselectFrom += '::text'\n\t\t}\n\t\tif (column.type === Model.ColumnType.Enum && column.list) {\n\t\t\tselectFrom += '::text[]'\n\t\t}\n\n\t\tlet columnValueGetter: ColumnValueGetter | undefined = undefined\n\t\tif (entity.view && column.name === entity.primary && column.type === Model.ColumnType.Uuid) {\n\t\t\tif (entity.view.idSource) {\n\t\t\t\tconst aliases: string[] = []\n\t\t\t\tfor (const source of entity.view.idSource) {\n\t\t\t\t\tconst columnName = getColumnName(this.schema, entity, source)\n\t\t\t\t\tconst idSrcPath = columnPath.for(source + '__id_src')\n\t\t\t\t\taliases.push(idSrcPath.alias)\n\t\t\t\t\tthis.executionContext.addColumn({\n\t\t\t\t\t\tquery: qb => qb.select([tableAlias, columnName], idSrcPath.alias),\n\t\t\t\t\t})\n\t\t\t\t}\n\n\t\t\t\tcolumnValueGetter = row => {\n\t\t\t\t\treturn viewComputedId(aliases.map(it => row[it]?.toString() || ''))\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tcolumnValueGetter = row => {\n\t\t\t\t\treturn row[columnAlias] ?? (this.providers.uuid({ version: this.settings.uuidVersion }))\n\t\t\t\t}\n\n\t\t\t}\n\t\t}\n\n\t\tthis.executionContext.addColumn({\n\t\t\tquery: qb => qb.select(new Literal(selectFrom), columnAlias),\n\t\t\tpredicate: this.getRequiredPredicate(entity, column),\n\t\t\tvalueGetter: columnValueGetter,\n\t\t})\n\t}\n\n\tpublic visitManyHasManyInverse(relationContext: Model.ManyHasManyInverseContext): void {\n\t\tconst field = this.executionContext.objectNode\n\t\tif (!field) {\n\t\t\tthrow new Error()\n\t\t}\n\t\tthis.executionContext.addData({\n\t\t\tfield: relationContext.entity.primary,\n\t\t\tdataProvider: async ids =>\n\t\t\t\tthis.relationFetcher.fetchManyHasManyGroups({\n\t\t\t\t\tmapper: this.mapper,\n\t\t\t\t\tfield: field,\n\t\t\t\t\trelationContext,\n\t\t\t\t\trelationPath: this.relationPath,\n\t\t\t\t\tids: ids,\n\t\t\t\t}),\n\t\t\tdefaultValue: [],\n\t\t\tpredicate: this.getRequiredPredicate(relationContext.entity, relationContext.relation),\n\t\t})\n\t}\n\n\tpublic visitManyHasManyOwning(relationContext: Model.ManyHasManyOwningContext): void {\n\t\tconst field = this.executionContext.objectNode\n\t\tif (!field) {\n\t\t\tthrow new Error()\n\t\t}\n\n\t\tthis.executionContext.addData({\n\t\t\tfield: relationContext.entity.primary,\n\t\t\tdataProvider: async ids =>\n\t\t\t\tthis.relationFetcher.fetchManyHasManyGroups({\n\t\t\t\t\tmapper: this.mapper,\n\t\t\t\t\tfield: field,\n\t\t\t\t\trelationContext,\n\t\t\t\t\trelationPath: this.relationPath,\n\t\t\t\t\tids: ids,\n\t\t\t\t}),\n\t\t\tdefaultValue: [],\n\t\t\tpredicate: this.getRequiredPredicate(relationContext.entity, relationContext.relation),\n\t\t})\n\t}\n\n\tpublic visitOneHasMany(relationContext: Model.OneHasManyContext): void {\n\t\tconst field = this.executionContext.objectNode\n\t\tif (!field) {\n\t\t\tthrow new Error()\n\t\t}\n\n\t\tthis.executionContext.addData({\n\t\t\tfield: relationContext.entity.primary,\n\t\t\tdataProvider: async ids =>\n\t\t\t\tthis.relationFetcher.fetchOneHasManyGroups({\n\t\t\t\t\tmapper: this.mapper,\n\t\t\t\t\tobjectNode: field,\n\t\t\t\t\trelationContext,\n\t\t\t\t\trelationPath: this.relationPath,\n\t\t\t\t\tids: ids,\n\t\t\t\t}),\n\t\t\tdefaultValue: [],\n\t\t\tpredicate: this.getRequiredPredicate(relationContext.entity, relationContext.relation),\n\t\t})\n\t}\n\n\tpublic visitOneHasOneInverse(relationContext: Model.OneHasOneInverseContext): void {\n\t\tconst { entity, targetRelation, targetEntity } = relationContext\n\t\tthis.executionContext.addData({\n\t\t\tfield: entity.primary,\n\t\t\tdataProvider: async ids => {\n\t\t\t\tconst idsWhere: Input.Where = {\n\t\t\t\t\t[targetRelation.name]: {\n\t\t\t\t\t\t[entity.primary]: {\n\t\t\t\t\t\t\tin: ids,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t\tconst field = this.executionContext.objectNode\n\t\t\t\tif (!field) {\n\t\t\t\t\tthrow new Error()\n\t\t\t\t}\n\t\t\t\tconst where: Input.Where = {\n\t\t\t\t\tand: [idsWhere, field.args.filter].filter((it): it is Input.Where => it !== undefined),\n\t\t\t\t}\n\t\t\t\tconst objectWithWhere = field.withArg('filter', where)\n\n\t\t\t\treturn this.mapper.selectAssoc(targetEntity, objectWithWhere, [\n\t\t\t\t\t...this.relationPath,\n\t\t\t\t\trelationContext,\n\t\t\t\t], targetRelation.name)\n\t\t\t},\n\t\t\tdefaultValue: null,\n\t\t\tpredicate: this.getRequiredPredicate(relationContext.entity, relationContext.relation),\n\t\t})\n\t}\n\n\tpublic visitOneHasOneOwning(relationContext: Model.OneHasOneOwningContext): void {\n\t\tconst { relation, targetEntity } = relationContext\n\t\tthis.executionContext.addData({\n\t\t\tfield: relation.name,\n\t\t\tdataProvider: async ids => {\n\t\t\t\tconst idsWhere: Input.Where = {\n\t\t\t\t\t[targetEntity.primary]: {\n\t\t\t\t\t\tin: ids,\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t\tconst objectNode = this.executionContext.objectNode\n\t\t\t\tif (!objectNode) {\n\t\t\t\t\tthrow new Error()\n\t\t\t\t}\n\t\t\t\tconst where: Input.Where = {\n\t\t\t\t\tand: [idsWhere, objectNode.args.filter].filter((it): it is Input.Where => it !== undefined),\n\t\t\t\t}\n\t\t\t\tconst objectWithWhere = objectNode.withArg('filter', where)\n\n\t\t\t\treturn this.mapper.selectAssoc(targetEntity, objectWithWhere, [\n\t\t\t\t\t...this.relationPath,\n\t\t\t\t\trelationContext,\n\t\t\t\t], targetEntity.primary)\n\t\t\t},\n\t\t\tdefaultValue: null,\n\t\t\tpredicate: this.getRequiredPredicate(relationContext.entity, relationContext.relation),\n\t\t})\n\t}\n\n\tpublic visitManyHasOne(relationContext: Model.ManyHasOneContext): void {\n\t\tconst { relation, targetEntity } = relationContext\n\t\tthis.executionContext.addData({\n\t\t\tfield: relation.name,\n\t\t\tdataProvider: async ids => {\n\t\t\t\tconst idsWhere: Input.Where = {\n\t\t\t\t\t[targetEntity.primary]: {\n\t\t\t\t\t\tin: ids,\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t\tconst objectNode = this.executionContext.objectNode\n\t\t\t\tif (!objectNode) {\n\t\t\t\t\tthrow new Error()\n\t\t\t\t}\n\t\t\t\tconst where: Input.Where = {\n\t\t\t\t\tand: [idsWhere, objectNode.args.filter].filter((it): it is Input.Where => it !== undefined),\n\t\t\t\t}\n\t\t\t\tconst objectWithWhere = objectNode.withArg('filter', where)\n\n\t\t\t\treturn this.mapper.selectAssoc(targetEntity, objectWithWhere, [\n\t\t\t\t\t...this.relationPath,\n\t\t\t\t\trelationContext,\n\t\t\t\t], targetEntity.primary)\n\t\t\t},\n\t\t\tdefaultValue: null,\n\t\t\tpredicate: this.getRequiredPredicate(relationContext.entity, relationContext.relation),\n\t\t})\n\t}\n\n\tprivate getRequiredPredicate(entity: Model.Entity, field: Model.AnyField): Acl.Predicate | undefined {\n\t\tconst fieldPredicate = this.predicateFactory.getFieldPredicate(entity, Acl.Operation.read, field.name)\n\t\treturn fieldPredicate.isSameAsPrimary ? undefined : fieldPredicate.predicate\n\t}\n}\n"],"names":[],"mappings":";;;;AAWO,MAAM,cAAsF;AAAA,EAClG,YACkB,QACA,iBACA,kBACA,QACA,kBACA,cACA,UACA,WAChB;AARgB,SAAA,SAAA;AACA,SAAA,kBAAA;AACA,SAAA,mBAAA;AACA,SAAA,SAAA;AACA,SAAA,mBAAA;AACA,SAAA,eAAA;AACA,SAAA,WAAA;AACA,SAAA,YAAA;AAAA,EAAA;AAAA,EAGlB,YAAY,EAAE,QAAQ,UAAqC;AACpD,UAAA,aAAa,KAAK,iBAAiB;AACnC,UAAA,YAAY,WAAW,KAAK;AAClC,UAAM,aAAa,UAAU;AAC7B,UAAM,cAAc,WAAW;AAE/B,QAAI,aAAa,eAAe,UAAU,IAAI,MAAM,eAAe,OAAO,UAAU;AACpF,QAAI,OAAO,SAAS,MAAM,WAAW,QAAQ,KAAK,SAAS,mBAAmB;AAC/D,oBAAA;AAAA,IAAA;AAEf,QAAI,OAAO,SAAS,MAAM,WAAW,YAAY,KAAK,SAAS,sBAAsB;AACtE,oBAAA;AAAA,IAAA;AAEf,QAAI,OAAO,SAAS,MAAM,WAAW,QAAQ,OAAO,MAAM;AAC3C,oBAAA;AAAA,IAAA;AAGf,QAAI,oBAAmD;AACnD,QAAA,OAAO,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AA,MACd,WAAW,KAAK,qBAAqB,gBAAgB,QAAQ,gBAAgB,QAAQ;AAAA,IAAA,CACrF;AAAA,EAAA;AAAA,EAGK,gBAAgB,iBAAgD;AAChE,UAAA,EAAE,UAAU,aAAA,IAAiB;AACnC,SAAK,iBAAiB,QAAQ;AAAA,MAC7B,OAAO,SAAS;AAAA,MAChB,cAAc,OAAM,QAAO;AAC1B,cAAM,WAAwB;AAAA,UAC7B,CAAC,aAAa,OAAO,GAAG;AAAA,YACvB,IAAI;AAAA,UAAA;AAAA,QAEN;AACM,cAAA,aAAa,KAAK,iBAAiB;AACzC,YAAI,CAAC,YAAY;AAChB,gBAAM,IAAI,MAAM;AAAA,QAAA;AAEjB,cAAM,QAAqB;AAAA,UAC1B,KAAK,CAAC,UAAU,WAAW,KAAK,MAAM,EAAE,OAAO,CAAC,OAA0B,OAAO,MAAS;AAAA,QAC3F;AACA,cAAM,kBAAkB,WAAW,QAAQ,UAAU,KAAK;AAE1D,eAAO,KAAK,OAAO,YAAY,cAAc,iBAAiB;AAAA,UAC7D,GAAG,KAAK;AAAA,UACR;AAAA,QAAA,GACE,aAAa,OAAO;AAAA,MACxB;AAAA,MACA,cAAc;AAAA,MACd,WAAW,KAAK,qBAAqB,gBAAgB,QAAQ,gBAAgB,QAAQ;AAAA,IAAA,CACrF;AAAA,EAAA;AAAA,EAGM,qBAAqB,QAAsB,OAAkD;AAC9F,UAAA,iBAAiB,KAAK,iBAAiB,kBAAkB,QAAQ,IAAI,UAAU,MAAM,MAAM,IAAI;AAC9F,WAAA,eAAe,kBAAkB,SAAY,eAAe;AAAA,EAAA;AAErE;"}
|
|
@@ -2,19 +2,23 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const FieldsVisitor = require("./FieldsVisitor.cjs");
|
|
4
4
|
class FieldsVisitorFactory {
|
|
5
|
-
constructor(relationFetcher, predicateFactory, settings) {
|
|
5
|
+
constructor(schema, relationFetcher, predicateFactory, settings, providers) {
|
|
6
|
+
this.schema = schema;
|
|
6
7
|
this.relationFetcher = relationFetcher;
|
|
7
8
|
this.predicateFactory = predicateFactory;
|
|
8
9
|
this.settings = settings;
|
|
10
|
+
this.providers = providers;
|
|
9
11
|
}
|
|
10
12
|
create(mapper, context) {
|
|
11
13
|
return new FieldsVisitor.FieldsVisitor(
|
|
14
|
+
this.schema,
|
|
12
15
|
this.relationFetcher,
|
|
13
16
|
this.predicateFactory,
|
|
14
17
|
mapper,
|
|
15
18
|
context,
|
|
16
19
|
context.relationPath,
|
|
17
|
-
this.settings
|
|
20
|
+
this.settings,
|
|
21
|
+
this.providers
|
|
18
22
|
);
|
|
19
23
|
}
|
|
20
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldsVisitorFactory.cjs","sources":["../../../../../../../packages/engine-content-api/src/mapper/select/handlers/FieldsVisitorFactory.ts"],"sourcesContent":["import { FieldsVisitor } from './FieldsVisitor'\nimport { RelationFetcher } from '../RelationFetcher'\nimport { Mapper } from '../../Mapper'\nimport { SelectExecutionHandlerContext } from '../SelectExecutionHandler'\nimport { PredicateFactory } from '../../../acl'\nimport { Settings } from '@contember/schema'\n\nexport class FieldsVisitorFactory {\n\tconstructor(\n\t\tprivate readonly relationFetcher: RelationFetcher,\n\t\tprivate readonly predicateFactory: PredicateFactory,\n\t\tprivate readonly settings: Settings.ContentSettings,\n\t) {}\n\n\tcreate(mapper: Mapper, context: SelectExecutionHandlerContext): FieldsVisitor {\n\t\treturn new FieldsVisitor(\n\t\t\tthis.relationFetcher,\n\t\t\tthis.predicateFactory,\n\t\t\tmapper,\n\t\t\tcontext,\n\t\t\tcontext.relationPath,\n\t\t\tthis.settings,\n\t\t)\n\t}\n}\n"],"names":["FieldsVisitor"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"FieldsVisitorFactory.cjs","sources":["../../../../../../../packages/engine-content-api/src/mapper/select/handlers/FieldsVisitorFactory.ts"],"sourcesContent":["import { FieldsVisitor } from './FieldsVisitor'\nimport { RelationFetcher } from '../RelationFetcher'\nimport { Mapper } from '../../Mapper'\nimport { SelectExecutionHandlerContext } from '../SelectExecutionHandler'\nimport { PredicateFactory } from '../../../acl'\nimport { Model, Settings } from '@contember/schema'\nimport { Providers } from '@contember/schema-utils'\n\nexport class FieldsVisitorFactory {\n\tconstructor(\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly relationFetcher: RelationFetcher,\n\t\tprivate readonly predicateFactory: PredicateFactory,\n\t\tprivate readonly settings: Settings.ContentSettings,\n\t\tprivate readonly providers: Providers,\n\t) {}\n\n\tcreate(mapper: Mapper, context: SelectExecutionHandlerContext): FieldsVisitor {\n\t\treturn new FieldsVisitor(\n\t\t\tthis.schema,\n\t\t\tthis.relationFetcher,\n\t\t\tthis.predicateFactory,\n\t\t\tmapper,\n\t\t\tcontext,\n\t\t\tcontext.relationPath,\n\t\t\tthis.settings,\n\t\t\tthis.providers,\n\t\t)\n\t}\n}\n"],"names":["FieldsVisitor"],"mappings":";;;AAQO,MAAM,qBAAqB;AAAA,EACjC,YACkB,QACA,iBACA,kBACA,UACA,WAChB;AALgB,SAAA,SAAA;AACA,SAAA,kBAAA;AACA,SAAA,mBAAA;AACA,SAAA,WAAA;AACA,SAAA,YAAA;AAAA,EAAA;AAAA,EAGlB,OAAO,QAAgB,SAAuD;AAC7E,WAAO,IAAIA,cAAA;AAAA,MACV,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL;AAAA,MACA;AAAA,MACA,QAAQ;AAAA,MACR,KAAK;AAAA,MACL,KAAK;AAAA,IACN;AAAA,EAAA;AAEF;;"}
|
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
import { FieldsVisitor } from "./FieldsVisitor.js";
|
|
2
2
|
class FieldsVisitorFactory {
|
|
3
|
-
constructor(relationFetcher, predicateFactory, settings) {
|
|
3
|
+
constructor(schema, relationFetcher, predicateFactory, settings, providers) {
|
|
4
|
+
this.schema = schema;
|
|
4
5
|
this.relationFetcher = relationFetcher;
|
|
5
6
|
this.predicateFactory = predicateFactory;
|
|
6
7
|
this.settings = settings;
|
|
8
|
+
this.providers = providers;
|
|
7
9
|
}
|
|
8
10
|
create(mapper, context) {
|
|
9
11
|
return new FieldsVisitor(
|
|
12
|
+
this.schema,
|
|
10
13
|
this.relationFetcher,
|
|
11
14
|
this.predicateFactory,
|
|
12
15
|
mapper,
|
|
13
16
|
context,
|
|
14
17
|
context.relationPath,
|
|
15
|
-
this.settings
|
|
18
|
+
this.settings,
|
|
19
|
+
this.providers
|
|
16
20
|
);
|
|
17
21
|
}
|
|
18
22
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldsVisitorFactory.js","sources":["../../../../../../../packages/engine-content-api/src/mapper/select/handlers/FieldsVisitorFactory.ts"],"sourcesContent":["import { FieldsVisitor } from './FieldsVisitor'\nimport { RelationFetcher } from '../RelationFetcher'\nimport { Mapper } from '../../Mapper'\nimport { SelectExecutionHandlerContext } from '../SelectExecutionHandler'\nimport { PredicateFactory } from '../../../acl'\nimport { Settings } from '@contember/schema'\n\nexport class FieldsVisitorFactory {\n\tconstructor(\n\t\tprivate readonly relationFetcher: RelationFetcher,\n\t\tprivate readonly predicateFactory: PredicateFactory,\n\t\tprivate readonly settings: Settings.ContentSettings,\n\t) {}\n\n\tcreate(mapper: Mapper, context: SelectExecutionHandlerContext): FieldsVisitor {\n\t\treturn new FieldsVisitor(\n\t\t\tthis.relationFetcher,\n\t\t\tthis.predicateFactory,\n\t\t\tmapper,\n\t\t\tcontext,\n\t\t\tcontext.relationPath,\n\t\t\tthis.settings,\n\t\t)\n\t}\n}\n"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"FieldsVisitorFactory.js","sources":["../../../../../../../packages/engine-content-api/src/mapper/select/handlers/FieldsVisitorFactory.ts"],"sourcesContent":["import { FieldsVisitor } from './FieldsVisitor'\nimport { RelationFetcher } from '../RelationFetcher'\nimport { Mapper } from '../../Mapper'\nimport { SelectExecutionHandlerContext } from '../SelectExecutionHandler'\nimport { PredicateFactory } from '../../../acl'\nimport { Model, Settings } from '@contember/schema'\nimport { Providers } from '@contember/schema-utils'\n\nexport class FieldsVisitorFactory {\n\tconstructor(\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly relationFetcher: RelationFetcher,\n\t\tprivate readonly predicateFactory: PredicateFactory,\n\t\tprivate readonly settings: Settings.ContentSettings,\n\t\tprivate readonly providers: Providers,\n\t) {}\n\n\tcreate(mapper: Mapper, context: SelectExecutionHandlerContext): FieldsVisitor {\n\t\treturn new FieldsVisitor(\n\t\t\tthis.schema,\n\t\t\tthis.relationFetcher,\n\t\t\tthis.predicateFactory,\n\t\t\tmapper,\n\t\t\tcontext,\n\t\t\tcontext.relationPath,\n\t\t\tthis.settings,\n\t\t\tthis.providers,\n\t\t)\n\t}\n}\n"],"names":[],"mappings":";AAQO,MAAM,qBAAqB;AAAA,EACjC,YACkB,QACA,iBACA,kBACA,UACA,WAChB;AALgB,SAAA,SAAA;AACA,SAAA,kBAAA;AACA,SAAA,mBAAA;AACA,SAAA,WAAA;AACA,SAAA,YAAA;AAAA,EAAA;AAAA,EAGlB,OAAO,QAAgB,SAAuD;AAC7E,WAAO,IAAI;AAAA,MACV,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK;AAAA,MACL;AAAA,MACA;AAAA,MACA,QAAQ;AAAA,MACR,KAAK;AAAA,MACL,KAAK;AAAA,IACN;AAAA,EAAA;AAEF;"}
|
|
@@ -8,6 +8,7 @@ const Database = require("@contember/database");
|
|
|
8
8
|
const Result = require("../mapper/Result.cjs");
|
|
9
9
|
const EventManager = require("../mapper/EventManager.cjs");
|
|
10
10
|
const ObjectNode = require("../inputProcessing/ObjectNode.cjs");
|
|
11
|
+
require("node:crypto");
|
|
11
12
|
const logger = require("@contember/logger");
|
|
12
13
|
const ErrorUtils = require("../mapper/ErrorUtils.cjs");
|
|
13
14
|
require("fast-deep-equal");
|