@contember/engine-content-api 2.0.2 → 2.1.0-alpha.10
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 +6 -4
- package/dist/development/src/ExecutionContainer.cjs.map +1 -1
- package/dist/development/src/ExecutionContainer.js +6 -4
- 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/ColumnValueResolver.cjs +1 -1
- package/dist/development/src/input-validation/ColumnValueResolver.cjs.map +1 -1
- package/dist/development/src/input-validation/ColumnValueResolver.js +1 -1
- package/dist/development/src/input-validation/ColumnValueResolver.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/insert/Inserter.cjs +3 -2
- package/dist/development/src/mapper/insert/Inserter.cjs.map +1 -1
- package/dist/development/src/mapper/insert/Inserter.js +3 -2
- package/dist/development/src/mapper/insert/Inserter.js.map +1 -1
- package/dist/development/src/mapper/insert/SqlCreateInputProcessor.cjs +3 -2
- package/dist/development/src/mapper/insert/SqlCreateInputProcessor.cjs.map +1 -1
- package/dist/development/src/mapper/insert/SqlCreateInputProcessor.js +3 -2
- package/dist/development/src/mapper/insert/SqlCreateInputProcessor.js.map +1 -1
- package/dist/development/src/mapper/select/ConditionBuilder.cjs +9 -2
- package/dist/development/src/mapper/select/ConditionBuilder.cjs.map +1 -1
- package/dist/development/src/mapper/select/ConditionBuilder.js +10 -3
- package/dist/development/src/mapper/select/ConditionBuilder.js.map +1 -1
- package/dist/development/src/mapper/select/WhereBuilder.cjs +3 -3
- package/dist/development/src/mapper/select/WhereBuilder.cjs.map +1 -1
- package/dist/development/src/mapper/select/WhereBuilder.js +3 -3
- package/dist/development/src/mapper/select/WhereBuilder.js.map +1 -1
- package/dist/development/src/mapper/select/handlers/FieldsVisitor.cjs +33 -3
- package/dist/development/src/mapper/select/handlers/FieldsVisitor.cjs.map +1 -1
- package/dist/development/src/mapper/select/handlers/FieldsVisitor.js +33 -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 +21 -0
- package/dist/development/src/resolvers/RefreshViewResolver.cjs.map +1 -0
- package/dist/development/src/resolvers/RefreshViewResolver.js +21 -0
- package/dist/development/src/resolvers/RefreshViewResolver.js.map +1 -0
- package/dist/development/src/schema/ColumnTypeResolver.cjs +9 -0
- package/dist/development/src/schema/ColumnTypeResolver.cjs.map +1 -1
- package/dist/development/src/schema/ColumnTypeResolver.js +10 -1
- package/dist/development/src/schema/ColumnTypeResolver.js.map +1 -1
- package/dist/development/src/schema/ConditionTypeProvider.cjs +35 -23
- package/dist/development/src/schema/ConditionTypeProvider.cjs.map +1 -1
- package/dist/development/src/schema/ConditionTypeProvider.js +36 -24
- package/dist/development/src/schema/ConditionTypeProvider.js.map +1 -1
- package/dist/development/src/schema/CustomTypesProvider.cjs +30 -0
- package/dist/development/src/schema/CustomTypesProvider.cjs.map +1 -1
- package/dist/development/src/schema/CustomTypesProvider.js +30 -0
- package/dist/development/src/schema/CustomTypesProvider.js.map +1 -1
- 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/OrderByTypeProvider.cjs +6 -1
- package/dist/development/src/schema/OrderByTypeProvider.cjs.map +1 -1
- package/dist/development/src/schema/OrderByTypeProvider.js +6 -1
- package/dist/development/src/schema/OrderByTypeProvider.js.map +1 -1
- package/dist/development/src/schema/RefreshViewMutationProvider.cjs +42 -0
- package/dist/development/src/schema/RefreshViewMutationProvider.cjs.map +1 -0
- package/dist/development/src/schema/RefreshViewMutationProvider.js +42 -0
- package/dist/development/src/schema/RefreshViewMutationProvider.js.map +1 -0
- package/dist/development/src/schema/WhereTypeProvider.cjs +1 -1
- package/dist/development/src/schema/WhereTypeProvider.cjs.map +1 -1
- package/dist/development/src/schema/WhereTypeProvider.js +1 -1
- package/dist/development/src/schema/WhereTypeProvider.js.map +1 -1
- package/dist/development/src/schema/entities/FieldTypeVisitor.cjs +3 -3
- package/dist/development/src/schema/entities/FieldTypeVisitor.cjs.map +1 -1
- package/dist/development/src/schema/entities/FieldTypeVisitor.js +3 -3
- package/dist/development/src/schema/entities/FieldTypeVisitor.js.map +1 -1
- package/dist/development/src/schema/mutations/CreateEntityInputFieldVisitor.cjs +1 -1
- package/dist/development/src/schema/mutations/CreateEntityInputFieldVisitor.cjs.map +1 -1
- package/dist/development/src/schema/mutations/CreateEntityInputFieldVisitor.js +1 -1
- package/dist/development/src/schema/mutations/CreateEntityInputFieldVisitor.js.map +1 -1
- package/dist/development/src/schema/mutations/UpdateEntityInputFieldVisitor.cjs +1 -1
- package/dist/development/src/schema/mutations/UpdateEntityInputFieldVisitor.cjs.map +1 -1
- package/dist/development/src/schema/mutations/UpdateEntityInputFieldVisitor.js +1 -1
- package/dist/development/src/schema/mutations/UpdateEntityInputFieldVisitor.js.map +1 -1
- 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 +6 -4
- package/dist/production/src/ExecutionContainer.cjs.map +1 -1
- package/dist/production/src/ExecutionContainer.js +6 -4
- 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/ColumnValueResolver.cjs +1 -1
- package/dist/production/src/input-validation/ColumnValueResolver.cjs.map +1 -1
- package/dist/production/src/input-validation/ColumnValueResolver.js +1 -1
- package/dist/production/src/input-validation/ColumnValueResolver.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/insert/Inserter.cjs +3 -2
- package/dist/production/src/mapper/insert/Inserter.cjs.map +1 -1
- package/dist/production/src/mapper/insert/Inserter.js +3 -2
- package/dist/production/src/mapper/insert/Inserter.js.map +1 -1
- package/dist/production/src/mapper/insert/SqlCreateInputProcessor.cjs +3 -2
- package/dist/production/src/mapper/insert/SqlCreateInputProcessor.cjs.map +1 -1
- package/dist/production/src/mapper/insert/SqlCreateInputProcessor.js +3 -2
- package/dist/production/src/mapper/insert/SqlCreateInputProcessor.js.map +1 -1
- package/dist/production/src/mapper/select/ConditionBuilder.cjs +9 -2
- package/dist/production/src/mapper/select/ConditionBuilder.cjs.map +1 -1
- package/dist/production/src/mapper/select/ConditionBuilder.js +10 -3
- package/dist/production/src/mapper/select/ConditionBuilder.js.map +1 -1
- package/dist/production/src/mapper/select/WhereBuilder.cjs +3 -3
- package/dist/production/src/mapper/select/WhereBuilder.cjs.map +1 -1
- package/dist/production/src/mapper/select/WhereBuilder.js +3 -3
- package/dist/production/src/mapper/select/WhereBuilder.js.map +1 -1
- package/dist/production/src/mapper/select/handlers/FieldsVisitor.cjs +33 -3
- package/dist/production/src/mapper/select/handlers/FieldsVisitor.cjs.map +1 -1
- package/dist/production/src/mapper/select/handlers/FieldsVisitor.js +33 -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 +21 -0
- package/dist/production/src/resolvers/RefreshViewResolver.cjs.map +1 -0
- package/dist/production/src/resolvers/RefreshViewResolver.js +21 -0
- package/dist/production/src/resolvers/RefreshViewResolver.js.map +1 -0
- package/dist/production/src/schema/ColumnTypeResolver.cjs +9 -0
- package/dist/production/src/schema/ColumnTypeResolver.cjs.map +1 -1
- package/dist/production/src/schema/ColumnTypeResolver.js +10 -1
- package/dist/production/src/schema/ColumnTypeResolver.js.map +1 -1
- package/dist/production/src/schema/ConditionTypeProvider.cjs +35 -23
- package/dist/production/src/schema/ConditionTypeProvider.cjs.map +1 -1
- package/dist/production/src/schema/ConditionTypeProvider.js +36 -24
- package/dist/production/src/schema/ConditionTypeProvider.js.map +1 -1
- package/dist/production/src/schema/CustomTypesProvider.cjs +30 -0
- package/dist/production/src/schema/CustomTypesProvider.cjs.map +1 -1
- package/dist/production/src/schema/CustomTypesProvider.js +30 -0
- package/dist/production/src/schema/CustomTypesProvider.js.map +1 -1
- 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/OrderByTypeProvider.cjs +6 -1
- package/dist/production/src/schema/OrderByTypeProvider.cjs.map +1 -1
- package/dist/production/src/schema/OrderByTypeProvider.js +6 -1
- package/dist/production/src/schema/OrderByTypeProvider.js.map +1 -1
- package/dist/production/src/schema/RefreshViewMutationProvider.cjs +42 -0
- package/dist/production/src/schema/RefreshViewMutationProvider.cjs.map +1 -0
- package/dist/production/src/schema/RefreshViewMutationProvider.js +42 -0
- package/dist/production/src/schema/RefreshViewMutationProvider.js.map +1 -0
- package/dist/production/src/schema/WhereTypeProvider.cjs +1 -1
- package/dist/production/src/schema/WhereTypeProvider.cjs.map +1 -1
- package/dist/production/src/schema/WhereTypeProvider.js +1 -1
- package/dist/production/src/schema/WhereTypeProvider.js.map +1 -1
- package/dist/production/src/schema/entities/FieldTypeVisitor.cjs +3 -3
- package/dist/production/src/schema/entities/FieldTypeVisitor.cjs.map +1 -1
- package/dist/production/src/schema/entities/FieldTypeVisitor.js +3 -3
- package/dist/production/src/schema/entities/FieldTypeVisitor.js.map +1 -1
- package/dist/production/src/schema/mutations/CreateEntityInputFieldVisitor.cjs +1 -1
- package/dist/production/src/schema/mutations/CreateEntityInputFieldVisitor.cjs.map +1 -1
- package/dist/production/src/schema/mutations/CreateEntityInputFieldVisitor.js +1 -1
- package/dist/production/src/schema/mutations/CreateEntityInputFieldVisitor.js.map +1 -1
- package/dist/production/src/schema/mutations/UpdateEntityInputFieldVisitor.cjs +1 -1
- package/dist/production/src/schema/mutations/UpdateEntityInputFieldVisitor.cjs.map +1 -1
- package/dist/production/src/schema/mutations/UpdateEntityInputFieldVisitor.js +1 -1
- package/dist/production/src/schema/mutations/UpdateEntityInputFieldVisitor.js.map +1 -1
- 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/insert/Inserter.d.ts +4 -1
- package/dist/types/mapper/insert/Inserter.d.ts.map +1 -1
- package/dist/types/mapper/insert/SqlCreateInputProcessor.d.ts +4 -1
- package/dist/types/mapper/insert/SqlCreateInputProcessor.d.ts.map +1 -1
- package/dist/types/mapper/select/ConditionBuilder.d.ts +2 -2
- package/dist/types/mapper/select/ConditionBuilder.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 +13 -0
- package/dist/types/resolvers/RefreshViewResolver.d.ts.map +1 -0
- package/dist/types/schema/ColumnTypeResolver.d.ts +5 -5
- package/dist/types/schema/ColumnTypeResolver.d.ts.map +1 -1
- package/dist/types/schema/ConditionTypeProvider.d.ts +1 -0
- package/dist/types/schema/ConditionTypeProvider.d.ts.map +1 -1
- package/dist/types/schema/CustomTypesProvider.d.ts +1 -0
- package/dist/types/schema/CustomTypesProvider.d.ts.map +1 -1
- 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/OrderByTypeProvider.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/mutations/UpdateEntityInputFieldVisitor.d.ts +1 -1
- 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 +9 -5
- package/src/acl/Authorizator.ts +5 -0
- package/src/input-validation/ColumnValueResolver.ts +1 -1
- package/src/mapper/insert/Inserter.ts +2 -1
- package/src/mapper/insert/SqlCreateInputProcessor.ts +2 -1
- package/src/mapper/select/ConditionBuilder.ts +19 -5
- package/src/mapper/select/WhereBuilder.ts +3 -3
- package/src/mapper/select/handlers/FieldsVisitor.ts +36 -1
- package/src/mapper/select/handlers/FieldsVisitorFactory.ts +6 -1
- package/src/resolvers/RefreshViewResolver.ts +23 -0
- package/src/schema/ColumnTypeResolver.ts +15 -3
- package/src/schema/ConditionTypeProvider.ts +40 -25
- package/src/schema/CustomTypesProvider.ts +37 -0
- package/src/schema/GraphQlSchemaBuilder.ts +8 -0
- package/src/schema/GraphQlSchemaBuilderFactory.ts +5 -2
- package/src/schema/OrderByTypeProvider.ts +6 -1
- package/src/schema/RefreshViewMutationProvider.ts +47 -0
- package/src/schema/WhereTypeProvider.ts +1 -1
- package/src/schema/entities/FieldTypeVisitor.ts +3 -3
- package/src/schema/mutations/CreateEntityInputFieldVisitor.ts +1 -1
- package/src/schema/mutations/UpdateEntityInputFieldVisitor.ts +1 -1
- package/src/utils/viewComputedId.ts +23 -0
- package/tests/cases/integration/graphQlSchema/graphQlSchemaBuilder.test.ts +38 -2
- package/tests/cases/integration/graphQlSchema/schema-aliased-type.gql +6 -0
- package/tests/cases/integration/graphQlSchema/schema-array.gql +257 -0
- package/tests/cases/integration/graphQlSchema/schema-column-types.gql +420 -0
- package/tests/src/test.ts +1 -1
|
@@ -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;A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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,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,Q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AA,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,kBAAA,MAAA,mBAAkB,IAAI,uBAAuB,CAAA;AAC7C,kBAAA,MAAA,SAAQ,IAAI,MAAM,CAAA;AAClB,kBAAA,MAAA,kBAAA;AAEA,kBAAA,MAAA,cAAA;AAkBf,SAAK,mBAAmB,IAAI,iBAAiB,IAAI,KAAK,sBAAsB;AACvE,SAAA,eAAe,IAAI,aAAa,IAAI;AAAA,EAAA;AAAA,EAG1C,MAAa,YAAY,QAAsB,OAA2C,WAAmB;AAC5G,UAAM,aAAa,cAAc,KAAK,QAAQ,QAAQ,SAAS;AAE/D,UAAM,KAAK,cAAc,OAAO,EAC9B,KAAK,OAAO,WAAW,OAAO,EAC9B,OAAO,CAAC,SAAS,UAAU,CAAC;AAC9B,UAAM,gBAAgB,KAAK,oBAAoB,OAAO,QAAQ,KAAK;AACnE,UAAM,iBAAiB,KAAK,mBAAmB,OAAO,QAAQ,aAAa;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tG;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,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;"}
|
|
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,kBAAA,MAAA,mBAAkB,IAAI,uBAAuB,CAAA;AAC7C,kBAAA,MAAA,SAAQ,IAAI,MAAM,CAAA;AAClB,kBAAA,MAA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AA,EAAA;AAEb;"}
|
|
@@ -7,17 +7,18 @@ require("@contember/schema");
|
|
|
7
7
|
const SqlCreateInputProcessor = require("./SqlCreateInputProcessor.cjs");
|
|
8
8
|
const ColumnValue = require("../ColumnValue.cjs");
|
|
9
9
|
class Inserter {
|
|
10
|
-
constructor(schema, schemaDatabaseMetadata, insertBuilderFactory, providers) {
|
|
10
|
+
constructor(schema, schemaDatabaseMetadata, insertBuilderFactory, providers, options) {
|
|
11
11
|
this.schema = schema;
|
|
12
12
|
this.schemaDatabaseMetadata = schemaDatabaseMetadata;
|
|
13
13
|
this.insertBuilderFactory = insertBuilderFactory;
|
|
14
14
|
this.providers = providers;
|
|
15
|
+
this.options = options;
|
|
15
16
|
}
|
|
16
17
|
async insert(mapper, entity, data, insertIdCallback, builderCb) {
|
|
17
18
|
const insertBuilder = this.insertBuilderFactory.create(entity);
|
|
18
19
|
insertBuilder.addPredicates(Object.keys(data));
|
|
19
20
|
const visitor = new CreateInputVisitor.CreateInputVisitor(
|
|
20
|
-
new SqlCreateInputProcessor.SqlCreateInputProcessor(insertBuilder, mapper, this.providers),
|
|
21
|
+
new SqlCreateInputProcessor.SqlCreateInputProcessor(insertBuilder, mapper, this.providers, this.options),
|
|
21
22
|
this.schema,
|
|
22
23
|
data
|
|
23
24
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Inserter.cjs","sources":["../../../../../../packages/engine-content-api/src/mapper/insert/Inserter.ts"],"sourcesContent":["import { MutationCreateOk, MutationNoResultError, MutationResultList } from '../Result'\nimport { CreateInputVisitor } from '../../inputProcessing'\nimport { SqlCreateInputProcessor, SqlCreateInputProcessorResult } from './SqlCreateInputProcessor'\nimport { Mapper } from '../Mapper'\nimport { Model } from '@contember/schema'\nimport { acceptFieldVisitor, Providers } from '@contember/schema-utils'\nimport { InsertBuilderFactory } from './InsertBuilderFactory'\nimport { InsertBuilder } from './InsertBuilder'\nimport { rowDataToFieldValues } from '../ColumnValue'\nimport { DatabaseMetadata } from '@contember/database'\nimport { MapperInput } from '../types'\n\nexport class Inserter {\n\tconstructor(\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly schemaDatabaseMetadata: DatabaseMetadata,\n\t\tprivate readonly insertBuilderFactory: InsertBuilderFactory,\n\t\tprivate readonly providers: Providers,\n\t) {}\n\n\tpublic async insert(\n\t\tmapper: Mapper,\n\t\tentity: Model.Entity,\n\t\tdata: MapperInput.CreateDataInput,\n\t\tinsertIdCallback: (id: string) => void,\n\t\tbuilderCb: (builder: InsertBuilder) => void,\n\t): Promise<MutationResultList> {\n\t\tconst insertBuilder = this.insertBuilderFactory.create(entity)\n\n\t\tinsertBuilder.addPredicates(Object.keys(data))\n\n\t\tconst visitor = new CreateInputVisitor<SqlCreateInputProcessorResult>(\n\t\t\tnew SqlCreateInputProcessor(insertBuilder, mapper, this.providers),\n\t\t\tthis.schema,\n\t\t\tdata,\n\t\t)\n\n\t\tconst resultList: MutationResultList = []\n\t\tconst postInserts: Exclude<SqlCreateInputProcessorResult, MutationResultList>[] = []\n\n\t\tconst keys = new Set([\n\t\t\tentity.primary,\n\t\t\t...Object.keys(data),\n\t\t\t...Object.keys(entity.fields),\n\t\t])\n\n\t\tfor (const key of keys.values()) {\n\t\t\tconst resultSet = await acceptFieldVisitor(\n\t\t\t\tthis.schema,\n\t\t\t\tentity,\n\t\t\t\tkey,\n\t\t\t\tvisitor,\n\t\t\t)\n\t\t\tfor (const result of resultSet) {\n\t\t\t\tif (typeof result === 'function') {\n\t\t\t\t\tpostInserts.push(result)\n\t\t\t\t} else {\n\t\t\t\t\tfor (const resultItem of await result) {\n\t\t\t\t\t\tresultList.push(resultItem)\n\t\t\t\t\t\tif (resultItem.error) {\n\t\t\t\t\t\t\treturn resultList\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tbuilderCb(insertBuilder)\n\t\tconst insertResult = await insertBuilder.execute(mapper)\n\n\t\tif (insertResult.primaryValue === null) {\n\t\t\treturn [new MutationNoResultError([]), ...resultList]\n\t\t}\n\t\tinsertIdCallback(String(insertResult.primaryValue))\n\n\t\tconst okResult = new MutationCreateOk([], entity, insertResult.primaryValue, data, rowDataToFieldValues(insertResult.values))\n\t\tresultList.unshift(okResult)\n\n\t\tfor (const postInsert of postInserts) {\n\t\t\tconst postInsertResult = await postInsert({ primary: insertResult.primaryValue })\n\t\t\tfor (const result of postInsertResult) {\n\t\t\t\tresultList.push(result)\n\t\t\t\tif (result.error) {\n\t\t\t\t\treturn resultList\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn resultList\n\t}\n}\n\n"],"names":["CreateInputVisitor","SqlCreateInputProcessor","acceptFieldVisitor","MutationNoResultError","MutationCreateOk","rowDataToFieldValues"],"mappings":";;;;;;;;AAYO,MAAM,SAAS;AAAA,EACrB,YACkB,QACA,wBACA,sBACA,
|
|
1
|
+
{"version":3,"file":"Inserter.cjs","sources":["../../../../../../packages/engine-content-api/src/mapper/insert/Inserter.ts"],"sourcesContent":["import { MutationCreateOk, MutationNoResultError, MutationResultList } from '../Result'\nimport { CreateInputVisitor } from '../../inputProcessing'\nimport { SqlCreateInputProcessor, SqlCreateInputProcessorResult } from './SqlCreateInputProcessor'\nimport { Mapper } from '../Mapper'\nimport { Model } from '@contember/schema'\nimport { acceptFieldVisitor, Providers } from '@contember/schema-utils'\nimport { InsertBuilderFactory } from './InsertBuilderFactory'\nimport { InsertBuilder } from './InsertBuilder'\nimport { rowDataToFieldValues } from '../ColumnValue'\nimport { DatabaseMetadata } from '@contember/database'\nimport { MapperInput } from '../types'\n\nexport class Inserter {\n\tconstructor(\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly schemaDatabaseMetadata: DatabaseMetadata,\n\t\tprivate readonly insertBuilderFactory: InsertBuilderFactory,\n\t\tprivate readonly providers: Providers,\n\t\tprivate readonly options: { uuidVersion?: 4 | 7 },\n\t) {}\n\n\tpublic async insert(\n\t\tmapper: Mapper,\n\t\tentity: Model.Entity,\n\t\tdata: MapperInput.CreateDataInput,\n\t\tinsertIdCallback: (id: string) => void,\n\t\tbuilderCb: (builder: InsertBuilder) => void,\n\t): Promise<MutationResultList> {\n\t\tconst insertBuilder = this.insertBuilderFactory.create(entity)\n\n\t\tinsertBuilder.addPredicates(Object.keys(data))\n\n\t\tconst visitor = new CreateInputVisitor<SqlCreateInputProcessorResult>(\n\t\t\tnew SqlCreateInputProcessor(insertBuilder, mapper, this.providers, this.options),\n\t\t\tthis.schema,\n\t\t\tdata,\n\t\t)\n\n\t\tconst resultList: MutationResultList = []\n\t\tconst postInserts: Exclude<SqlCreateInputProcessorResult, MutationResultList>[] = []\n\n\t\tconst keys = new Set([\n\t\t\tentity.primary,\n\t\t\t...Object.keys(data),\n\t\t\t...Object.keys(entity.fields),\n\t\t])\n\n\t\tfor (const key of keys.values()) {\n\t\t\tconst resultSet = await acceptFieldVisitor(\n\t\t\t\tthis.schema,\n\t\t\t\tentity,\n\t\t\t\tkey,\n\t\t\t\tvisitor,\n\t\t\t)\n\t\t\tfor (const result of resultSet) {\n\t\t\t\tif (typeof result === 'function') {\n\t\t\t\t\tpostInserts.push(result)\n\t\t\t\t} else {\n\t\t\t\t\tfor (const resultItem of await result) {\n\t\t\t\t\t\tresultList.push(resultItem)\n\t\t\t\t\t\tif (resultItem.error) {\n\t\t\t\t\t\t\treturn resultList\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tbuilderCb(insertBuilder)\n\t\tconst insertResult = await insertBuilder.execute(mapper)\n\n\t\tif (insertResult.primaryValue === null) {\n\t\t\treturn [new MutationNoResultError([]), ...resultList]\n\t\t}\n\t\tinsertIdCallback(String(insertResult.primaryValue))\n\n\t\tconst okResult = new MutationCreateOk([], entity, insertResult.primaryValue, data, rowDataToFieldValues(insertResult.values))\n\t\tresultList.unshift(okResult)\n\n\t\tfor (const postInsert of postInserts) {\n\t\t\tconst postInsertResult = await postInsert({ primary: insertResult.primaryValue })\n\t\t\tfor (const result of postInsertResult) {\n\t\t\t\tresultList.push(result)\n\t\t\t\tif (result.error) {\n\t\t\t\t\treturn resultList\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn resultList\n\t}\n}\n\n"],"names":["CreateInputVisitor","SqlCreateInputProcessor","acceptFieldVisitor","MutationNoResultError","MutationCreateOk","rowDataToFieldValues"],"mappings":";;;;;;;;AAYO,MAAM,SAAS;AAAA,EACrB,YACkB,QACA,wBACA,sBACA,WACA,SAChB;AALgB,SAAA,SAAA;AACA,SAAA,yBAAA;AACA,SAAA,uBAAA;AACA,SAAA,YAAA;AACA,SAAA,UAAA;AAAA,EAAA;AAAA,EAGlB,MAAa,OACZ,QACA,QACA,MACA,kBACA,WAC8B;AAC9B,UAAM,gBAAgB,KAAK,qBAAqB,OAAO,MAAM;AAE7D,kBAAc,cAAc,OAAO,KAAK,IAAI,CAAC;AAE7C,UAAM,UAAU,IAAIA,mBAAA;AAAA,MACnB,IAAIC,wBAAAA,wBAAwB,eAAe,QAAQ,KAAK,WAAW,KAAK,OAAO;AAAA,MAC/E,KAAK;AAAA,MACL;AAAA,IACD;AAEA,UAAM,aAAiC,CAAC;AACxC,UAAM,cAA4E,CAAC;AAE7E,UAAA,2BAAW,IAAI;AAAA,MACpB,OAAO;AAAA,MACP,GAAG,OAAO,KAAK,IAAI;AAAA,MACnB,GAAG,OAAO,KAAK,OAAO,MAAM;AAAA,IAAA,CAC5B;AAEU,eAAA,OAAO,KAAK,UAAU;AAChC,YAAM,YAAY,MAAMC,YAAA;AAAA,QACvB,KAAK;AAAA,QACL;AAAA,QACA;AAAA,QACA;AAAA,MACD;AACA,iBAAW,UAAU,WAAW;AAC3B,YAAA,OAAO,WAAW,YAAY;AACjC,sBAAY,KAAK,MAAM;AAAA,QAAA,OACjB;AACK,qBAAA,cAAc,MAAM,QAAQ;AACtC,uBAAW,KAAK,UAAU;AAC1B,gBAAI,WAAW,OAAO;AACd,qBAAA;AAAA,YAAA;AAAA,UACR;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAGD,cAAU,aAAa;AACvB,UAAM,eAAe,MAAM,cAAc,QAAQ,MAAM;AAEnD,QAAA,aAAa,iBAAiB,MAAM;AACvC,aAAO,CAAC,IAAIC,OAAA,sBAAsB,EAAE,GAAG,GAAG,UAAU;AAAA,IAAA;AAEpC,qBAAA,OAAO,aAAa,YAAY,CAAC;AAElD,UAAM,WAAW,IAAIC,wBAAiB,CAAA,GAAI,QAAQ,aAAa,cAAc,MAAMC,YAAAA,qBAAqB,aAAa,MAAM,CAAC;AAC5H,eAAW,QAAQ,QAAQ;AAE3B,eAAW,cAAc,aAAa;AACrC,YAAM,mBAAmB,MAAM,WAAW,EAAE,SAAS,aAAa,cAAc;AAChF,iBAAW,UAAU,kBAAkB;AACtC,mBAAW,KAAK,MAAM;AACtB,YAAI,OAAO,OAAO;AACV,iBAAA;AAAA,QAAA;AAAA,MACR;AAAA,IACD;AAGM,WAAA;AAAA,EAAA;AAET;;"}
|
|
@@ -5,17 +5,18 @@ import "@contember/schema";
|
|
|
5
5
|
import { SqlCreateInputProcessor } from "./SqlCreateInputProcessor.js";
|
|
6
6
|
import { rowDataToFieldValues } from "../ColumnValue.js";
|
|
7
7
|
class Inserter {
|
|
8
|
-
constructor(schema, schemaDatabaseMetadata, insertBuilderFactory, providers) {
|
|
8
|
+
constructor(schema, schemaDatabaseMetadata, insertBuilderFactory, providers, options) {
|
|
9
9
|
this.schema = schema;
|
|
10
10
|
this.schemaDatabaseMetadata = schemaDatabaseMetadata;
|
|
11
11
|
this.insertBuilderFactory = insertBuilderFactory;
|
|
12
12
|
this.providers = providers;
|
|
13
|
+
this.options = options;
|
|
13
14
|
}
|
|
14
15
|
async insert(mapper, entity, data, insertIdCallback, builderCb) {
|
|
15
16
|
const insertBuilder = this.insertBuilderFactory.create(entity);
|
|
16
17
|
insertBuilder.addPredicates(Object.keys(data));
|
|
17
18
|
const visitor = new CreateInputVisitor(
|
|
18
|
-
new SqlCreateInputProcessor(insertBuilder, mapper, this.providers),
|
|
19
|
+
new SqlCreateInputProcessor(insertBuilder, mapper, this.providers, this.options),
|
|
19
20
|
this.schema,
|
|
20
21
|
data
|
|
21
22
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Inserter.js","sources":["../../../../../../packages/engine-content-api/src/mapper/insert/Inserter.ts"],"sourcesContent":["import { MutationCreateOk, MutationNoResultError, MutationResultList } from '../Result'\nimport { CreateInputVisitor } from '../../inputProcessing'\nimport { SqlCreateInputProcessor, SqlCreateInputProcessorResult } from './SqlCreateInputProcessor'\nimport { Mapper } from '../Mapper'\nimport { Model } from '@contember/schema'\nimport { acceptFieldVisitor, Providers } from '@contember/schema-utils'\nimport { InsertBuilderFactory } from './InsertBuilderFactory'\nimport { InsertBuilder } from './InsertBuilder'\nimport { rowDataToFieldValues } from '../ColumnValue'\nimport { DatabaseMetadata } from '@contember/database'\nimport { MapperInput } from '../types'\n\nexport class Inserter {\n\tconstructor(\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly schemaDatabaseMetadata: DatabaseMetadata,\n\t\tprivate readonly insertBuilderFactory: InsertBuilderFactory,\n\t\tprivate readonly providers: Providers,\n\t) {}\n\n\tpublic async insert(\n\t\tmapper: Mapper,\n\t\tentity: Model.Entity,\n\t\tdata: MapperInput.CreateDataInput,\n\t\tinsertIdCallback: (id: string) => void,\n\t\tbuilderCb: (builder: InsertBuilder) => void,\n\t): Promise<MutationResultList> {\n\t\tconst insertBuilder = this.insertBuilderFactory.create(entity)\n\n\t\tinsertBuilder.addPredicates(Object.keys(data))\n\n\t\tconst visitor = new CreateInputVisitor<SqlCreateInputProcessorResult>(\n\t\t\tnew SqlCreateInputProcessor(insertBuilder, mapper, this.providers),\n\t\t\tthis.schema,\n\t\t\tdata,\n\t\t)\n\n\t\tconst resultList: MutationResultList = []\n\t\tconst postInserts: Exclude<SqlCreateInputProcessorResult, MutationResultList>[] = []\n\n\t\tconst keys = new Set([\n\t\t\tentity.primary,\n\t\t\t...Object.keys(data),\n\t\t\t...Object.keys(entity.fields),\n\t\t])\n\n\t\tfor (const key of keys.values()) {\n\t\t\tconst resultSet = await acceptFieldVisitor(\n\t\t\t\tthis.schema,\n\t\t\t\tentity,\n\t\t\t\tkey,\n\t\t\t\tvisitor,\n\t\t\t)\n\t\t\tfor (const result of resultSet) {\n\t\t\t\tif (typeof result === 'function') {\n\t\t\t\t\tpostInserts.push(result)\n\t\t\t\t} else {\n\t\t\t\t\tfor (const resultItem of await result) {\n\t\t\t\t\t\tresultList.push(resultItem)\n\t\t\t\t\t\tif (resultItem.error) {\n\t\t\t\t\t\t\treturn resultList\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tbuilderCb(insertBuilder)\n\t\tconst insertResult = await insertBuilder.execute(mapper)\n\n\t\tif (insertResult.primaryValue === null) {\n\t\t\treturn [new MutationNoResultError([]), ...resultList]\n\t\t}\n\t\tinsertIdCallback(String(insertResult.primaryValue))\n\n\t\tconst okResult = new MutationCreateOk([], entity, insertResult.primaryValue, data, rowDataToFieldValues(insertResult.values))\n\t\tresultList.unshift(okResult)\n\n\t\tfor (const postInsert of postInserts) {\n\t\t\tconst postInsertResult = await postInsert({ primary: insertResult.primaryValue })\n\t\t\tfor (const result of postInsertResult) {\n\t\t\t\tresultList.push(result)\n\t\t\t\tif (result.error) {\n\t\t\t\t\treturn resultList\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn resultList\n\t}\n}\n\n"],"names":[],"mappings":";;;;;;AAYO,MAAM,SAAS;AAAA,EACrB,YACkB,QACA,wBACA,sBACA,
|
|
1
|
+
{"version":3,"file":"Inserter.js","sources":["../../../../../../packages/engine-content-api/src/mapper/insert/Inserter.ts"],"sourcesContent":["import { MutationCreateOk, MutationNoResultError, MutationResultList } from '../Result'\nimport { CreateInputVisitor } from '../../inputProcessing'\nimport { SqlCreateInputProcessor, SqlCreateInputProcessorResult } from './SqlCreateInputProcessor'\nimport { Mapper } from '../Mapper'\nimport { Model } from '@contember/schema'\nimport { acceptFieldVisitor, Providers } from '@contember/schema-utils'\nimport { InsertBuilderFactory } from './InsertBuilderFactory'\nimport { InsertBuilder } from './InsertBuilder'\nimport { rowDataToFieldValues } from '../ColumnValue'\nimport { DatabaseMetadata } from '@contember/database'\nimport { MapperInput } from '../types'\n\nexport class Inserter {\n\tconstructor(\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly schemaDatabaseMetadata: DatabaseMetadata,\n\t\tprivate readonly insertBuilderFactory: InsertBuilderFactory,\n\t\tprivate readonly providers: Providers,\n\t\tprivate readonly options: { uuidVersion?: 4 | 7 },\n\t) {}\n\n\tpublic async insert(\n\t\tmapper: Mapper,\n\t\tentity: Model.Entity,\n\t\tdata: MapperInput.CreateDataInput,\n\t\tinsertIdCallback: (id: string) => void,\n\t\tbuilderCb: (builder: InsertBuilder) => void,\n\t): Promise<MutationResultList> {\n\t\tconst insertBuilder = this.insertBuilderFactory.create(entity)\n\n\t\tinsertBuilder.addPredicates(Object.keys(data))\n\n\t\tconst visitor = new CreateInputVisitor<SqlCreateInputProcessorResult>(\n\t\t\tnew SqlCreateInputProcessor(insertBuilder, mapper, this.providers, this.options),\n\t\t\tthis.schema,\n\t\t\tdata,\n\t\t)\n\n\t\tconst resultList: MutationResultList = []\n\t\tconst postInserts: Exclude<SqlCreateInputProcessorResult, MutationResultList>[] = []\n\n\t\tconst keys = new Set([\n\t\t\tentity.primary,\n\t\t\t...Object.keys(data),\n\t\t\t...Object.keys(entity.fields),\n\t\t])\n\n\t\tfor (const key of keys.values()) {\n\t\t\tconst resultSet = await acceptFieldVisitor(\n\t\t\t\tthis.schema,\n\t\t\t\tentity,\n\t\t\t\tkey,\n\t\t\t\tvisitor,\n\t\t\t)\n\t\t\tfor (const result of resultSet) {\n\t\t\t\tif (typeof result === 'function') {\n\t\t\t\t\tpostInserts.push(result)\n\t\t\t\t} else {\n\t\t\t\t\tfor (const resultItem of await result) {\n\t\t\t\t\t\tresultList.push(resultItem)\n\t\t\t\t\t\tif (resultItem.error) {\n\t\t\t\t\t\t\treturn resultList\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tbuilderCb(insertBuilder)\n\t\tconst insertResult = await insertBuilder.execute(mapper)\n\n\t\tif (insertResult.primaryValue === null) {\n\t\t\treturn [new MutationNoResultError([]), ...resultList]\n\t\t}\n\t\tinsertIdCallback(String(insertResult.primaryValue))\n\n\t\tconst okResult = new MutationCreateOk([], entity, insertResult.primaryValue, data, rowDataToFieldValues(insertResult.values))\n\t\tresultList.unshift(okResult)\n\n\t\tfor (const postInsert of postInserts) {\n\t\t\tconst postInsertResult = await postInsert({ primary: insertResult.primaryValue })\n\t\t\tfor (const result of postInsertResult) {\n\t\t\t\tresultList.push(result)\n\t\t\t\tif (result.error) {\n\t\t\t\t\treturn resultList\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn resultList\n\t}\n}\n\n"],"names":[],"mappings":";;;;;;AAYO,MAAM,SAAS;AAAA,EACrB,YACkB,QACA,wBACA,sBACA,WACA,SAChB;AALgB,SAAA,SAAA;AACA,SAAA,yBAAA;AACA,SAAA,uBAAA;AACA,SAAA,YAAA;AACA,SAAA,UAAA;AAAA,EAAA;AAAA,EAGlB,MAAa,OACZ,QACA,QACA,MACA,kBACA,WAC8B;AAC9B,UAAM,gBAAgB,KAAK,qBAAqB,OAAO,MAAM;AAE7D,kBAAc,cAAc,OAAO,KAAK,IAAI,CAAC;AAE7C,UAAM,UAAU,IAAI;AAAA,MACnB,IAAI,wBAAwB,eAAe,QAAQ,KAAK,WAAW,KAAK,OAAO;AAAA,MAC/E,KAAK;AAAA,MACL;AAAA,IACD;AAEA,UAAM,aAAiC,CAAC;AACxC,UAAM,cAA4E,CAAC;AAE7E,UAAA,2BAAW,IAAI;AAAA,MACpB,OAAO;AAAA,MACP,GAAG,OAAO,KAAK,IAAI;AAAA,MACnB,GAAG,OAAO,KAAK,OAAO,MAAM;AAAA,IAAA,CAC5B;AAEU,eAAA,OAAO,KAAK,UAAU;AAChC,YAAM,YAAY,MAAM;AAAA,QACvB,KAAK;AAAA,QACL;AAAA,QACA;AAAA,QACA;AAAA,MACD;AACA,iBAAW,UAAU,WAAW;AAC3B,YAAA,OAAO,WAAW,YAAY;AACjC,sBAAY,KAAK,MAAM;AAAA,QAAA,OACjB;AACK,qBAAA,cAAc,MAAM,QAAQ;AACtC,uBAAW,KAAK,UAAU;AAC1B,gBAAI,WAAW,OAAO;AACd,qBAAA;AAAA,YAAA;AAAA,UACR;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAGD,cAAU,aAAa;AACvB,UAAM,eAAe,MAAM,cAAc,QAAQ,MAAM;AAEnD,QAAA,aAAa,iBAAiB,MAAM;AACvC,aAAO,CAAC,IAAI,sBAAsB,EAAE,GAAG,GAAG,UAAU;AAAA,IAAA;AAEpC,qBAAA,OAAO,aAAa,YAAY,CAAC;AAElD,UAAM,WAAW,IAAI,iBAAiB,CAAA,GAAI,QAAQ,aAAa,cAAc,MAAM,qBAAqB,aAAa,MAAM,CAAC;AAC5H,eAAW,QAAQ,QAAQ;AAE3B,eAAW,cAAc,aAAa;AACrC,YAAM,mBAAmB,MAAM,WAAW,EAAE,SAAS,aAAa,cAAc;AAChF,iBAAW,UAAU,kBAAkB;AACtC,mBAAW,KAAK,MAAM;AACtB,YAAI,OAAO,OAAO;AACV,iBAAA;AAAA,QAAA;AAAA,MACR;AAAA,IACD;AAGM,WAAA;AAAA,EAAA;AAET;"}
|
|
@@ -11,10 +11,11 @@ var __defProp = Object.defineProperty;
|
|
|
11
11
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
12
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
13
13
|
class SqlCreateInputProcessor {
|
|
14
|
-
constructor(insertBuilder, mapper, providers) {
|
|
14
|
+
constructor(insertBuilder, mapper, providers, options = {}) {
|
|
15
15
|
this.insertBuilder = insertBuilder;
|
|
16
16
|
this.mapper = mapper;
|
|
17
17
|
this.providers = providers;
|
|
18
|
+
this.options = options;
|
|
18
19
|
__publicField(this, "oneHasOneInverseCreateInputProcessor");
|
|
19
20
|
__publicField(this, "oneHasOneOwningCreateInputProcessor");
|
|
20
21
|
__publicField(this, "oneHasManyCreateInputProcessor");
|
|
@@ -67,7 +68,7 @@ class SqlCreateInputProcessor {
|
|
|
67
68
|
async column(context) {
|
|
68
69
|
this.insertBuilder.addFieldValue(
|
|
69
70
|
context.column.name,
|
|
70
|
-
schemaUtils.resolveColumnValue(context, this.providers)
|
|
71
|
+
schemaUtils.resolveColumnValue(context, this.providers, this.options)
|
|
71
72
|
);
|
|
72
73
|
return [];
|
|
73
74
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SqlCreateInputProcessor.cjs","sources":["../../../../../../packages/engine-content-api/src/mapper/insert/SqlCreateInputProcessor.ts"],"sourcesContent":["import { Input, Model, Value } from '@contember/schema'\nimport { Mapper } from '../Mapper'\nimport { InsertBuilder } from './InsertBuilder'\nimport { Providers, resolveColumnValue } from '@contember/schema-utils'\nimport { CreateInputProcessor } from '../../inputProcessing'\nimport { MutationResultList } from '../Result'\nimport { hasManyProcessor, hasOneProcessor } from '../MutationProcessorHelper'\nimport { OneHasOneInverseCreateInputProcessor } from './relations/OneHasOneInverseCreateInputProcessor'\nimport { OneHasOneOwningCreateInputProcessor } from './relations/OneHasOneOwningCreateInputProcessor'\nimport { OneHasManyCreateInputProcessor } from './relations/OneHasManyCreateInputProcessor'\nimport { ManyHasOneCreateInputProcessor } from './relations/ManyHasOneCreateInputProcessor'\nimport { ManyHasManyCreateInputProcessor } from './relations/ManyHasManyCreateInputProcessor'\n\n\nexport type SqlCreateInputProcessorResult = MutationResultList | ((ctx: { primary: Input.PrimaryValue }) => Promise<MutationResultList>)\nexport class SqlCreateInputProcessor implements CreateInputProcessor<SqlCreateInputProcessorResult> {\n\n\tprivate oneHasOneInverseCreateInputProcessor: OneHasOneInverseCreateInputProcessor\n\tprivate oneHasOneOwningCreateInputProcessor: OneHasOneOwningCreateInputProcessor\n\tprivate oneHasManyCreateInputProcessor: OneHasManyCreateInputProcessor\n\tprivate manyHasOneCreateInputProcessor: ManyHasOneCreateInputProcessor\n\tprivate manyHasManyCreateInputProcessor: ManyHasManyCreateInputProcessor\n\n\tconstructor(\n\t\tprivate readonly insertBuilder: InsertBuilder,\n\t\tprivate readonly mapper: Mapper,\n\t\tprivate readonly providers: Providers,\n\t) {\n\t\tthis.oneHasOneInverseCreateInputProcessor = new OneHasOneInverseCreateInputProcessor(this.mapper)\n\t\tthis.oneHasOneOwningCreateInputProcessor = new OneHasOneOwningCreateInputProcessor(this.mapper, this.insertBuilder)\n\t\tthis.oneHasManyCreateInputProcessor = new OneHasManyCreateInputProcessor(this.mapper)\n\t\tthis.manyHasOneCreateInputProcessor = new ManyHasOneCreateInputProcessor(this.mapper, this.insertBuilder)\n\t\tthis.manyHasManyCreateInputProcessor = new ManyHasManyCreateInputProcessor(this.mapper)\n\t}\n\n\tpublic async column(context: Model.ColumnContext & { input: Input.ColumnValue | undefined }): Promise<SqlCreateInputProcessorResult> {\n\t\tthis.insertBuilder.addFieldValue(\n\t\t\tcontext.column.name,\n\t\t\tresolveColumnValue(context, this.providers),\n\t\t)\n\t\treturn []\n\t}\n\n\tmanyHasManyInverse: CreateInputProcessor<SqlCreateInputProcessorResult>['manyHasManyInverse'] = {\n\t\tconnect: hasManyProcessor(ctx => this.manyHasManyCreateInputProcessor.connect(ctx)),\n\t\tcreate: hasManyProcessor(ctx => this.manyHasManyCreateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasManyProcessor(ctx => this.manyHasManyCreateInputProcessor.connectOrCreate(ctx)),\n\t}\n\n\tmanyHasManyOwning: CreateInputProcessor<SqlCreateInputProcessorResult>['manyHasManyOwning'] = {\n\t\tconnect: hasManyProcessor(ctx => this.manyHasManyCreateInputProcessor.connect(ctx)),\n\t\tcreate: hasManyProcessor(ctx => this.manyHasManyCreateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasManyProcessor(ctx => this.manyHasManyCreateInputProcessor.connectOrCreate(ctx)),\n\t}\n\n\tmanyHasOne: CreateInputProcessor<SqlCreateInputProcessorResult>['manyHasOne'] = {\n\t\tnothing: async ctx => {\n\t\t\tthis.insertBuilder.addFieldValue(ctx.relation.name, null)\n\t\t\treturn []\n\t\t},\n\t\tconnect: hasOneProcessor(ctx => this.manyHasOneCreateInputProcessor.connect(ctx)),\n\t\tcreate: hasOneProcessor(ctx => this.manyHasOneCreateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasOneProcessor(ctx => this.manyHasOneCreateInputProcessor.connectOrCreate(ctx)),\n\t}\n\n\toneHasMany: CreateInputProcessor<SqlCreateInputProcessorResult>['oneHasMany'] = {\n\t\tconnect: hasManyProcessor(ctx => this.oneHasManyCreateInputProcessor.connect(ctx)),\n\t\tcreate: hasManyProcessor(ctx => this.oneHasManyCreateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasManyProcessor(ctx => this.oneHasManyCreateInputProcessor.connectOrCreate(ctx)),\n\t}\n\n\n\toneHasOneOwning: CreateInputProcessor<SqlCreateInputProcessorResult>['oneHasOneOwning'] = {\n\t\tnothing: async ctx => {\n\t\t\tthis.insertBuilder.addFieldValue(ctx.relation.name, null)\n\t\t\treturn []\n\t\t},\n\t\tconnect: hasOneProcessor(ctx => this.oneHasOneOwningCreateInputProcessor.connect(ctx)),\n\t\tcreate: hasOneProcessor(ctx => this.oneHasOneOwningCreateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasOneProcessor(ctx => this.oneHasOneOwningCreateInputProcessor.connectOrCreate(ctx)),\n\t}\n\n\toneHasOneInverse: CreateInputProcessor<SqlCreateInputProcessorResult>['oneHasOneInverse'] = {\n\t\tconnect: hasOneProcessor(ctx => this.oneHasOneInverseCreateInputProcessor.connect(ctx)),\n\t\tcreate: hasOneProcessor(ctx => this.oneHasOneInverseCreateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasOneProcessor(ctx => this.oneHasOneInverseCreateInputProcessor.connectOrCreate(ctx)),\n\t}\n}\n"],"names":["hasManyProcessor","hasOneProcessor","OneHasOneInverseCreateInputProcessor","OneHasOneOwningCreateInputProcessor","OneHasManyCreateInputProcessor","ManyHasOneCreateInputProcessor","ManyHasManyCreateInputProcessor","resolveColumnValue"],"mappings":";;;;;;;;;;;;AAeO,MAAM,wBAAuF;AAAA,EAQnG,YACkB,eACA,QACA,
|
|
1
|
+
{"version":3,"file":"SqlCreateInputProcessor.cjs","sources":["../../../../../../packages/engine-content-api/src/mapper/insert/SqlCreateInputProcessor.ts"],"sourcesContent":["import { Input, Model, Value } from '@contember/schema'\nimport { Mapper } from '../Mapper'\nimport { InsertBuilder } from './InsertBuilder'\nimport { Providers, resolveColumnValue } from '@contember/schema-utils'\nimport { CreateInputProcessor } from '../../inputProcessing'\nimport { MutationResultList } from '../Result'\nimport { hasManyProcessor, hasOneProcessor } from '../MutationProcessorHelper'\nimport { OneHasOneInverseCreateInputProcessor } from './relations/OneHasOneInverseCreateInputProcessor'\nimport { OneHasOneOwningCreateInputProcessor } from './relations/OneHasOneOwningCreateInputProcessor'\nimport { OneHasManyCreateInputProcessor } from './relations/OneHasManyCreateInputProcessor'\nimport { ManyHasOneCreateInputProcessor } from './relations/ManyHasOneCreateInputProcessor'\nimport { ManyHasManyCreateInputProcessor } from './relations/ManyHasManyCreateInputProcessor'\n\n\nexport type SqlCreateInputProcessorResult = MutationResultList | ((ctx: { primary: Input.PrimaryValue }) => Promise<MutationResultList>)\nexport class SqlCreateInputProcessor implements CreateInputProcessor<SqlCreateInputProcessorResult> {\n\n\tprivate oneHasOneInverseCreateInputProcessor: OneHasOneInverseCreateInputProcessor\n\tprivate oneHasOneOwningCreateInputProcessor: OneHasOneOwningCreateInputProcessor\n\tprivate oneHasManyCreateInputProcessor: OneHasManyCreateInputProcessor\n\tprivate manyHasOneCreateInputProcessor: ManyHasOneCreateInputProcessor\n\tprivate manyHasManyCreateInputProcessor: ManyHasManyCreateInputProcessor\n\n\tconstructor(\n\t\tprivate readonly insertBuilder: InsertBuilder,\n\t\tprivate readonly mapper: Mapper,\n\t\tprivate readonly providers: Providers,\n\t\tprivate readonly options: { uuidVersion?: 4 | 7 } = {},\n\t) {\n\t\tthis.oneHasOneInverseCreateInputProcessor = new OneHasOneInverseCreateInputProcessor(this.mapper)\n\t\tthis.oneHasOneOwningCreateInputProcessor = new OneHasOneOwningCreateInputProcessor(this.mapper, this.insertBuilder)\n\t\tthis.oneHasManyCreateInputProcessor = new OneHasManyCreateInputProcessor(this.mapper)\n\t\tthis.manyHasOneCreateInputProcessor = new ManyHasOneCreateInputProcessor(this.mapper, this.insertBuilder)\n\t\tthis.manyHasManyCreateInputProcessor = new ManyHasManyCreateInputProcessor(this.mapper)\n\t}\n\n\tpublic async column(context: Model.ColumnContext & { input: Input.ColumnValue | undefined }): Promise<SqlCreateInputProcessorResult> {\n\t\tthis.insertBuilder.addFieldValue(\n\t\t\tcontext.column.name,\n\t\t\tresolveColumnValue(context, this.providers, this.options),\n\t\t)\n\t\treturn []\n\t}\n\n\tmanyHasManyInverse: CreateInputProcessor<SqlCreateInputProcessorResult>['manyHasManyInverse'] = {\n\t\tconnect: hasManyProcessor(ctx => this.manyHasManyCreateInputProcessor.connect(ctx)),\n\t\tcreate: hasManyProcessor(ctx => this.manyHasManyCreateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasManyProcessor(ctx => this.manyHasManyCreateInputProcessor.connectOrCreate(ctx)),\n\t}\n\n\tmanyHasManyOwning: CreateInputProcessor<SqlCreateInputProcessorResult>['manyHasManyOwning'] = {\n\t\tconnect: hasManyProcessor(ctx => this.manyHasManyCreateInputProcessor.connect(ctx)),\n\t\tcreate: hasManyProcessor(ctx => this.manyHasManyCreateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasManyProcessor(ctx => this.manyHasManyCreateInputProcessor.connectOrCreate(ctx)),\n\t}\n\n\tmanyHasOne: CreateInputProcessor<SqlCreateInputProcessorResult>['manyHasOne'] = {\n\t\tnothing: async ctx => {\n\t\t\tthis.insertBuilder.addFieldValue(ctx.relation.name, null)\n\t\t\treturn []\n\t\t},\n\t\tconnect: hasOneProcessor(ctx => this.manyHasOneCreateInputProcessor.connect(ctx)),\n\t\tcreate: hasOneProcessor(ctx => this.manyHasOneCreateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasOneProcessor(ctx => this.manyHasOneCreateInputProcessor.connectOrCreate(ctx)),\n\t}\n\n\toneHasMany: CreateInputProcessor<SqlCreateInputProcessorResult>['oneHasMany'] = {\n\t\tconnect: hasManyProcessor(ctx => this.oneHasManyCreateInputProcessor.connect(ctx)),\n\t\tcreate: hasManyProcessor(ctx => this.oneHasManyCreateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasManyProcessor(ctx => this.oneHasManyCreateInputProcessor.connectOrCreate(ctx)),\n\t}\n\n\n\toneHasOneOwning: CreateInputProcessor<SqlCreateInputProcessorResult>['oneHasOneOwning'] = {\n\t\tnothing: async ctx => {\n\t\t\tthis.insertBuilder.addFieldValue(ctx.relation.name, null)\n\t\t\treturn []\n\t\t},\n\t\tconnect: hasOneProcessor(ctx => this.oneHasOneOwningCreateInputProcessor.connect(ctx)),\n\t\tcreate: hasOneProcessor(ctx => this.oneHasOneOwningCreateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasOneProcessor(ctx => this.oneHasOneOwningCreateInputProcessor.connectOrCreate(ctx)),\n\t}\n\n\toneHasOneInverse: CreateInputProcessor<SqlCreateInputProcessorResult>['oneHasOneInverse'] = {\n\t\tconnect: hasOneProcessor(ctx => this.oneHasOneInverseCreateInputProcessor.connect(ctx)),\n\t\tcreate: hasOneProcessor(ctx => this.oneHasOneInverseCreateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasOneProcessor(ctx => this.oneHasOneInverseCreateInputProcessor.connectOrCreate(ctx)),\n\t}\n}\n"],"names":["hasManyProcessor","hasOneProcessor","OneHasOneInverseCreateInputProcessor","OneHasOneOwningCreateInputProcessor","OneHasManyCreateInputProcessor","ManyHasOneCreateInputProcessor","ManyHasManyCreateInputProcessor","resolveColumnValue"],"mappings":";;;;;;;;;;;;AAeO,MAAM,wBAAuF;AAAA,EAQnG,YACkB,eACA,QACA,WACA,UAAmC,CAAA,GACnD;AAJgB,SAAA,gBAAA;AACA,SAAA,SAAA;AACA,SAAA,YAAA;AACA,SAAA,UAAA;AAVV,kBAAA,MAAA,sCAAA;AACA,kBAAA,MAAA,qCAAA;AACA,kBAAA,MAAA,gCAAA;AACA,kBAAA,MAAA,gCAAA;AACA,kBAAA,MAAA,iCAAA;AAuBwF,kBAAA,MAAA,sBAAA;AAAA,MAC/F,SAASA,wBAAiB,iBAAA,CAAA,QAAO,KAAK,gCAAgC,QAAQ,GAAG,CAAC;AAAA,MAClF,QAAQA,wBAAiB,iBAAA,CAAA,QAAO,KAAK,gCAAgC,OAAO,GAAG,CAAC;AAAA,MAChF,iBAAiBA,wBAAiB,iBAAA,CAAA,QAAO,KAAK,gCAAgC,gBAAgB,GAAG,CAAC;AAAA,IAAA,CACnG;AAE8F,kBAAA,MAAA,qBAAA;AAAA,MAC7F,SAASA,wBAAiB,iBAAA,CAAA,QAAO,KAAK,gCAAgC,QAAQ,GAAG,CAAC;AAAA,MAClF,QAAQA,wBAAiB,iBAAA,CAAA,QAAO,KAAK,gCAAgC,OAAO,GAAG,CAAC;AAAA,MAChF,iBAAiBA,wBAAiB,iBAAA,CAAA,QAAO,KAAK,gCAAgC,gBAAgB,GAAG,CAAC;AAAA,IAAA,CACnG;AAEgF,kBAAA,MAAA,cAAA;AAAA,MAC/E,SAAS,OAAM,QAAO;AACrB,aA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gBAAA,CAAA,QAAO,KAAK,qCAAqC,gBAAgB,GAAG,CAAC;AAAA,IAAA,CACvG;AA1DC,SAAK,uCAAuC,IAAIC,0EAAqC,KAAK,MAAM;AAChG,SAAK,sCAAsC,IAAIC,oCAAA,oCAAoC,KAAK,QAAQ,KAAK,aAAa;AAClH,SAAK,iCAAiC,IAAIC,8DAA+B,KAAK,MAAM;AACpF,SAAK,iCAAiC,IAAIC,+BAAA,+BAA+B,KAAK,QAAQ,KAAK,aAAa;AACxG,SAAK,kCAAkC,IAAIC,gEAAgC,KAAK,MAAM;AAAA,EAAA;AAAA,EAGvF,MAAa,OAAO,SAAiH;AACpI,SAAK,cAAc;AAAA,MAClB,QAAQ,OAAO;AAAA,MACfC,YAAAA,mBAAmB,SAAS,KAAK,WAAW,KAAK,OAAO;AAAA,IACzD;AACA,WAAO,CAAC;AAAA,EAAA;AA+CV;;"}
|
|
@@ -9,10 +9,11 @@ var __defProp = Object.defineProperty;
|
|
|
9
9
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
10
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
11
11
|
class SqlCreateInputProcessor {
|
|
12
|
-
constructor(insertBuilder, mapper, providers) {
|
|
12
|
+
constructor(insertBuilder, mapper, providers, options = {}) {
|
|
13
13
|
this.insertBuilder = insertBuilder;
|
|
14
14
|
this.mapper = mapper;
|
|
15
15
|
this.providers = providers;
|
|
16
|
+
this.options = options;
|
|
16
17
|
__publicField(this, "oneHasOneInverseCreateInputProcessor");
|
|
17
18
|
__publicField(this, "oneHasOneOwningCreateInputProcessor");
|
|
18
19
|
__publicField(this, "oneHasManyCreateInputProcessor");
|
|
@@ -65,7 +66,7 @@ class SqlCreateInputProcessor {
|
|
|
65
66
|
async column(context) {
|
|
66
67
|
this.insertBuilder.addFieldValue(
|
|
67
68
|
context.column.name,
|
|
68
|
-
resolveColumnValue(context, this.providers)
|
|
69
|
+
resolveColumnValue(context, this.providers, this.options)
|
|
69
70
|
);
|
|
70
71
|
return [];
|
|
71
72
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SqlCreateInputProcessor.js","sources":["../../../../../../packages/engine-content-api/src/mapper/insert/SqlCreateInputProcessor.ts"],"sourcesContent":["import { Input, Model, Value } from '@contember/schema'\nimport { Mapper } from '../Mapper'\nimport { InsertBuilder } from './InsertBuilder'\nimport { Providers, resolveColumnValue } from '@contember/schema-utils'\nimport { CreateInputProcessor } from '../../inputProcessing'\nimport { MutationResultList } from '../Result'\nimport { hasManyProcessor, hasOneProcessor } from '../MutationProcessorHelper'\nimport { OneHasOneInverseCreateInputProcessor } from './relations/OneHasOneInverseCreateInputProcessor'\nimport { OneHasOneOwningCreateInputProcessor } from './relations/OneHasOneOwningCreateInputProcessor'\nimport { OneHasManyCreateInputProcessor } from './relations/OneHasManyCreateInputProcessor'\nimport { ManyHasOneCreateInputProcessor } from './relations/ManyHasOneCreateInputProcessor'\nimport { ManyHasManyCreateInputProcessor } from './relations/ManyHasManyCreateInputProcessor'\n\n\nexport type SqlCreateInputProcessorResult = MutationResultList | ((ctx: { primary: Input.PrimaryValue }) => Promise<MutationResultList>)\nexport class SqlCreateInputProcessor implements CreateInputProcessor<SqlCreateInputProcessorResult> {\n\n\tprivate oneHasOneInverseCreateInputProcessor: OneHasOneInverseCreateInputProcessor\n\tprivate oneHasOneOwningCreateInputProcessor: OneHasOneOwningCreateInputProcessor\n\tprivate oneHasManyCreateInputProcessor: OneHasManyCreateInputProcessor\n\tprivate manyHasOneCreateInputProcessor: ManyHasOneCreateInputProcessor\n\tprivate manyHasManyCreateInputProcessor: ManyHasManyCreateInputProcessor\n\n\tconstructor(\n\t\tprivate readonly insertBuilder: InsertBuilder,\n\t\tprivate readonly mapper: Mapper,\n\t\tprivate readonly providers: Providers,\n\t) {\n\t\tthis.oneHasOneInverseCreateInputProcessor = new OneHasOneInverseCreateInputProcessor(this.mapper)\n\t\tthis.oneHasOneOwningCreateInputProcessor = new OneHasOneOwningCreateInputProcessor(this.mapper, this.insertBuilder)\n\t\tthis.oneHasManyCreateInputProcessor = new OneHasManyCreateInputProcessor(this.mapper)\n\t\tthis.manyHasOneCreateInputProcessor = new ManyHasOneCreateInputProcessor(this.mapper, this.insertBuilder)\n\t\tthis.manyHasManyCreateInputProcessor = new ManyHasManyCreateInputProcessor(this.mapper)\n\t}\n\n\tpublic async column(context: Model.ColumnContext & { input: Input.ColumnValue | undefined }): Promise<SqlCreateInputProcessorResult> {\n\t\tthis.insertBuilder.addFieldValue(\n\t\t\tcontext.column.name,\n\t\t\tresolveColumnValue(context, this.providers),\n\t\t)\n\t\treturn []\n\t}\n\n\tmanyHasManyInverse: CreateInputProcessor<SqlCreateInputProcessorResult>['manyHasManyInverse'] = {\n\t\tconnect: hasManyProcessor(ctx => this.manyHasManyCreateInputProcessor.connect(ctx)),\n\t\tcreate: hasManyProcessor(ctx => this.manyHasManyCreateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasManyProcessor(ctx => this.manyHasManyCreateInputProcessor.connectOrCreate(ctx)),\n\t}\n\n\tmanyHasManyOwning: CreateInputProcessor<SqlCreateInputProcessorResult>['manyHasManyOwning'] = {\n\t\tconnect: hasManyProcessor(ctx => this.manyHasManyCreateInputProcessor.connect(ctx)),\n\t\tcreate: hasManyProcessor(ctx => this.manyHasManyCreateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasManyProcessor(ctx => this.manyHasManyCreateInputProcessor.connectOrCreate(ctx)),\n\t}\n\n\tmanyHasOne: CreateInputProcessor<SqlCreateInputProcessorResult>['manyHasOne'] = {\n\t\tnothing: async ctx => {\n\t\t\tthis.insertBuilder.addFieldValue(ctx.relation.name, null)\n\t\t\treturn []\n\t\t},\n\t\tconnect: hasOneProcessor(ctx => this.manyHasOneCreateInputProcessor.connect(ctx)),\n\t\tcreate: hasOneProcessor(ctx => this.manyHasOneCreateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasOneProcessor(ctx => this.manyHasOneCreateInputProcessor.connectOrCreate(ctx)),\n\t}\n\n\toneHasMany: CreateInputProcessor<SqlCreateInputProcessorResult>['oneHasMany'] = {\n\t\tconnect: hasManyProcessor(ctx => this.oneHasManyCreateInputProcessor.connect(ctx)),\n\t\tcreate: hasManyProcessor(ctx => this.oneHasManyCreateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasManyProcessor(ctx => this.oneHasManyCreateInputProcessor.connectOrCreate(ctx)),\n\t}\n\n\n\toneHasOneOwning: CreateInputProcessor<SqlCreateInputProcessorResult>['oneHasOneOwning'] = {\n\t\tnothing: async ctx => {\n\t\t\tthis.insertBuilder.addFieldValue(ctx.relation.name, null)\n\t\t\treturn []\n\t\t},\n\t\tconnect: hasOneProcessor(ctx => this.oneHasOneOwningCreateInputProcessor.connect(ctx)),\n\t\tcreate: hasOneProcessor(ctx => this.oneHasOneOwningCreateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasOneProcessor(ctx => this.oneHasOneOwningCreateInputProcessor.connectOrCreate(ctx)),\n\t}\n\n\toneHasOneInverse: CreateInputProcessor<SqlCreateInputProcessorResult>['oneHasOneInverse'] = {\n\t\tconnect: hasOneProcessor(ctx => this.oneHasOneInverseCreateInputProcessor.connect(ctx)),\n\t\tcreate: hasOneProcessor(ctx => this.oneHasOneInverseCreateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasOneProcessor(ctx => this.oneHasOneInverseCreateInputProcessor.connectOrCreate(ctx)),\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;AAeO,MAAM,wBAAuF;AAAA,EAQnG,YACkB,eACA,QACA,
|
|
1
|
+
{"version":3,"file":"SqlCreateInputProcessor.js","sources":["../../../../../../packages/engine-content-api/src/mapper/insert/SqlCreateInputProcessor.ts"],"sourcesContent":["import { Input, Model, Value } from '@contember/schema'\nimport { Mapper } from '../Mapper'\nimport { InsertBuilder } from './InsertBuilder'\nimport { Providers, resolveColumnValue } from '@contember/schema-utils'\nimport { CreateInputProcessor } from '../../inputProcessing'\nimport { MutationResultList } from '../Result'\nimport { hasManyProcessor, hasOneProcessor } from '../MutationProcessorHelper'\nimport { OneHasOneInverseCreateInputProcessor } from './relations/OneHasOneInverseCreateInputProcessor'\nimport { OneHasOneOwningCreateInputProcessor } from './relations/OneHasOneOwningCreateInputProcessor'\nimport { OneHasManyCreateInputProcessor } from './relations/OneHasManyCreateInputProcessor'\nimport { ManyHasOneCreateInputProcessor } from './relations/ManyHasOneCreateInputProcessor'\nimport { ManyHasManyCreateInputProcessor } from './relations/ManyHasManyCreateInputProcessor'\n\n\nexport type SqlCreateInputProcessorResult = MutationResultList | ((ctx: { primary: Input.PrimaryValue }) => Promise<MutationResultList>)\nexport class SqlCreateInputProcessor implements CreateInputProcessor<SqlCreateInputProcessorResult> {\n\n\tprivate oneHasOneInverseCreateInputProcessor: OneHasOneInverseCreateInputProcessor\n\tprivate oneHasOneOwningCreateInputProcessor: OneHasOneOwningCreateInputProcessor\n\tprivate oneHasManyCreateInputProcessor: OneHasManyCreateInputProcessor\n\tprivate manyHasOneCreateInputProcessor: ManyHasOneCreateInputProcessor\n\tprivate manyHasManyCreateInputProcessor: ManyHasManyCreateInputProcessor\n\n\tconstructor(\n\t\tprivate readonly insertBuilder: InsertBuilder,\n\t\tprivate readonly mapper: Mapper,\n\t\tprivate readonly providers: Providers,\n\t\tprivate readonly options: { uuidVersion?: 4 | 7 } = {},\n\t) {\n\t\tthis.oneHasOneInverseCreateInputProcessor = new OneHasOneInverseCreateInputProcessor(this.mapper)\n\t\tthis.oneHasOneOwningCreateInputProcessor = new OneHasOneOwningCreateInputProcessor(this.mapper, this.insertBuilder)\n\t\tthis.oneHasManyCreateInputProcessor = new OneHasManyCreateInputProcessor(this.mapper)\n\t\tthis.manyHasOneCreateInputProcessor = new ManyHasOneCreateInputProcessor(this.mapper, this.insertBuilder)\n\t\tthis.manyHasManyCreateInputProcessor = new ManyHasManyCreateInputProcessor(this.mapper)\n\t}\n\n\tpublic async column(context: Model.ColumnContext & { input: Input.ColumnValue | undefined }): Promise<SqlCreateInputProcessorResult> {\n\t\tthis.insertBuilder.addFieldValue(\n\t\t\tcontext.column.name,\n\t\t\tresolveColumnValue(context, this.providers, this.options),\n\t\t)\n\t\treturn []\n\t}\n\n\tmanyHasManyInverse: CreateInputProcessor<SqlCreateInputProcessorResult>['manyHasManyInverse'] = {\n\t\tconnect: hasManyProcessor(ctx => this.manyHasManyCreateInputProcessor.connect(ctx)),\n\t\tcreate: hasManyProcessor(ctx => this.manyHasManyCreateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasManyProcessor(ctx => this.manyHasManyCreateInputProcessor.connectOrCreate(ctx)),\n\t}\n\n\tmanyHasManyOwning: CreateInputProcessor<SqlCreateInputProcessorResult>['manyHasManyOwning'] = {\n\t\tconnect: hasManyProcessor(ctx => this.manyHasManyCreateInputProcessor.connect(ctx)),\n\t\tcreate: hasManyProcessor(ctx => this.manyHasManyCreateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasManyProcessor(ctx => this.manyHasManyCreateInputProcessor.connectOrCreate(ctx)),\n\t}\n\n\tmanyHasOne: CreateInputProcessor<SqlCreateInputProcessorResult>['manyHasOne'] = {\n\t\tnothing: async ctx => {\n\t\t\tthis.insertBuilder.addFieldValue(ctx.relation.name, null)\n\t\t\treturn []\n\t\t},\n\t\tconnect: hasOneProcessor(ctx => this.manyHasOneCreateInputProcessor.connect(ctx)),\n\t\tcreate: hasOneProcessor(ctx => this.manyHasOneCreateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasOneProcessor(ctx => this.manyHasOneCreateInputProcessor.connectOrCreate(ctx)),\n\t}\n\n\toneHasMany: CreateInputProcessor<SqlCreateInputProcessorResult>['oneHasMany'] = {\n\t\tconnect: hasManyProcessor(ctx => this.oneHasManyCreateInputProcessor.connect(ctx)),\n\t\tcreate: hasManyProcessor(ctx => this.oneHasManyCreateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasManyProcessor(ctx => this.oneHasManyCreateInputProcessor.connectOrCreate(ctx)),\n\t}\n\n\n\toneHasOneOwning: CreateInputProcessor<SqlCreateInputProcessorResult>['oneHasOneOwning'] = {\n\t\tnothing: async ctx => {\n\t\t\tthis.insertBuilder.addFieldValue(ctx.relation.name, null)\n\t\t\treturn []\n\t\t},\n\t\tconnect: hasOneProcessor(ctx => this.oneHasOneOwningCreateInputProcessor.connect(ctx)),\n\t\tcreate: hasOneProcessor(ctx => this.oneHasOneOwningCreateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasOneProcessor(ctx => this.oneHasOneOwningCreateInputProcessor.connectOrCreate(ctx)),\n\t}\n\n\toneHasOneInverse: CreateInputProcessor<SqlCreateInputProcessorResult>['oneHasOneInverse'] = {\n\t\tconnect: hasOneProcessor(ctx => this.oneHasOneInverseCreateInputProcessor.connect(ctx)),\n\t\tcreate: hasOneProcessor(ctx => this.oneHasOneInverseCreateInputProcessor.create(ctx)),\n\t\tconnectOrCreate: hasOneProcessor(ctx => this.oneHasOneInverseCreateInputProcessor.connectOrCreate(ctx)),\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;AAeO,MAAM,wBAAuF;AAAA,EAQnG,YACkB,eACA,QACA,WACA,UAAmC,CAAA,GACnD;AAJgB,SAAA,gBAAA;AACA,SAAA,SAAA;AACA,SAAA,YAAA;AACA,SAAA,UAAA;AAVV,kBAAA,MAAA,sCAAA;AACA,kBAAA,MAAA,qCAAA;AACA,kBAAA,MAAA,gCAAA;AACA,kBAAA,MAAA,gCAAA;AACA,kBAAA,MAAA,iCAAA;AAuBwF,kBAAA,MAAA,sBAAA;AAAA,MAC/F,SAAS,iBAAiB,CAAA,QAAO,KAAK,gCAAgC,QAAQ,GAAG,CAAC;AAAA,MAClF,QAAQ,iBAAiB,CAAA,QAAO,KAAK,gCAAgC,OAAO,GAAG,CAAC;AAAA,MAChF,iBAAiB,iBAA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oC,OAAO,GAAG,CAAC;AAAA,MACnF,iBAAiB,gBAAgB,CAAA,QAAO,KAAK,oCAAoC,gBAAgB,GAAG,CAAC;AAAA,IAAA,CACtG;AAE4F,kBAAA,MAAA,oBAAA;AAAA,MAC3F,SAAS,gBAAgB,CAAA,QAAO,KAAK,qCAAqC,QAAQ,GAAG,CAAC;AAAA,MACtF,QAAQ,gBAAgB,CAAA,QAAO,KAAK,qCAAqC,OAAO,GAAG,CAAC;AAAA,MACpF,iBAAiB,gBAAgB,CAAA,QAAO,KAAK,qCAAqC,gBAAgB,GAAG,CAAC;AAAA,IAAA,CACvG;AA1DC,SAAK,uCAAuC,IAAI,qCAAqC,KAAK,MAAM;AAChG,SAAK,sCAAsC,IAAI,oCAAoC,KAAK,QAAQ,KAAK,aAAa;AAClH,SAAK,iCAAiC,IAAI,+BAA+B,KAAK,MAAM;AACpF,SAAK,iCAAiC,IAAI,+BAA+B,KAAK,QAAQ,KAAK,aAAa;AACxG,SAAK,kCAAkC,IAAI,gCAAgC,KAAK,MAAM;AAAA,EAAA;AAAA,EAGvF,MAAa,OAAO,SAAiH;AACpI,SAAK,cAAc;AAAA,MAClB,QAAQ,OAAO;AAAA,MACf,mBAAmB,SAAS,KAAK,WAAW,KAAK,OAAO;AAAA,IACzD;AACA,WAAO,CAAC;AAAA,EAAA;AA+CV;"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const schema = require("@contember/schema");
|
|
3
4
|
const Database = require("@contember/database");
|
|
4
5
|
const exception = require("../../exception.cjs");
|
|
5
6
|
class ConditionBuilder {
|
|
@@ -23,15 +24,21 @@ class ConditionBuilder {
|
|
|
23
24
|
and: (builder2, expressions) => builder2.and((builder22) => expressions.reduce((builder3, expr) => this.build(builder3, tableName, columnName, columnType, expr), builder22)),
|
|
24
25
|
or: (builder2, expressions) => builder2.or((builder22) => expressions.reduce((builder3, expr) => this.build(builder3, tableName, columnName, columnType, expr), builder22)),
|
|
25
26
|
not: (builder2, expression) => builder2.not((builder22) => this.build(builder22, tableName, columnName, columnType, expression)),
|
|
27
|
+
isNull: (builder2, value) => value ? builder2.isNull(columnIdentifier) : builder2.not((clause) => clause.isNull(columnIdentifier)),
|
|
26
28
|
eq: (builder2, value) => builder2.compare(columnIdentifier, Database.Operator.eq, value),
|
|
27
29
|
notEq: (builder2, value) => builder2.compare(columnIdentifier, Database.Operator.notEq, value),
|
|
28
|
-
|
|
29
|
-
in: (builder2, values) => builder2.in(columnIdentifier, values, columnType),
|
|
30
|
+
in: (builder2, values) => builder2.in(columnIdentifier, values, columnType.columnType),
|
|
30
31
|
notIn: (builder2, values) => builder2.not((builder22) => builder22.in(columnIdentifier, values)),
|
|
31
32
|
lt: (builder2, value) => builder2.compare(columnIdentifier, Database.Operator.lt, value),
|
|
32
33
|
lte: (builder2, value) => builder2.compare(columnIdentifier, Database.Operator.lte, value),
|
|
33
34
|
gt: (builder2, value) => builder2.compare(columnIdentifier, Database.Operator.gt, value),
|
|
34
35
|
gte: (builder2, value) => builder2.compare(columnIdentifier, Database.Operator.gte, value),
|
|
36
|
+
includes: (builder2, value) => {
|
|
37
|
+
const cast = columnType.type === schema.Model.ColumnType.Enum ? `${Database.Compiler.SCHEMA_PLACEHOLDER}."${columnType.columnType}"` : columnType.columnType;
|
|
38
|
+
return builder2.raw(`${Database.formatColumnIdentifier(columnIdentifier)} @> ARRAY[?]::${cast}[]`, value);
|
|
39
|
+
},
|
|
40
|
+
maxLength: (builder2, value) => builder2.raw(`array_length(${Database.formatColumnIdentifier(columnIdentifier)}, 1) <= ?`, value),
|
|
41
|
+
minLength: (builder2, value) => builder2.raw(`array_length(${Database.formatColumnIdentifier(columnIdentifier)}, 1) >= ?`, value),
|
|
35
42
|
contains: (builder2, value) => builder2.compare(columnIdentifier, Database.Operator.contains, value),
|
|
36
43
|
startsWith: (builder2, value) => builder2.compare(columnIdentifier, Database.Operator.startsWith, value),
|
|
37
44
|
endsWith: (builder2, value) => builder2.compare(columnIdentifier, Database.Operator.endsWith, value),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConditionBuilder.cjs","sources":["../../../../../../packages/engine-content-api/src/mapper/select/ConditionBuilder.ts"],"sourcesContent":["import { Input } from '@contember/schema'\nimport { QueryBuilder, ConditionBuilder as SqlConditionBuilder, Operator } from '@contember/database'\nimport { UserError } from '../../exception'\n\nexport class ConditionBuilder {\n\tpublic build(\n\t\tbuilder: SqlConditionBuilder,\n\t\ttableName: string,\n\t\tcolumnName: string,\n\t\tcolumnType:
|
|
1
|
+
{"version":3,"file":"ConditionBuilder.cjs","sources":["../../../../../../packages/engine-content-api/src/mapper/select/ConditionBuilder.ts"],"sourcesContent":["import { Input, Model } from '@contember/schema'\nimport { QueryBuilder, ConditionBuilder as SqlConditionBuilder, Operator, Literal, formatColumnIdentifier, Compiler } from '@contember/database'\nimport { UserError } from '../../exception'\n\nexport class ConditionBuilder {\n\tpublic build(\n\t\tbuilder: SqlConditionBuilder,\n\t\ttableName: string,\n\t\tcolumnName: string,\n\t\tcolumnType: Pick<Model.AnyColumn, 'type' | 'list' | 'columnType'>,\n\t\tcondition: Input.Condition<any> | null,\n\t): SqlConditionBuilder {\n\t\tif (condition === null) {\n\t\t\treturn builder\n\t\t}\n\t\tconst entries = Object.entries(condition)\n\t\t\t.filter(<T extends keyof Input.Condition>(it: [string, any]): it is [T, Input.Condition[T]] =>\n\t\t\t\tit[1] !== null,\n\t\t\t)\n\t\tif (entries.length === 0) {\n\t\t\treturn builder\n\t\t}\n\t\tif (entries.length > 1) {\n\t\t\tthrow new UserError(\n\t\t\t\t'Only single field is allowed. If you want to combine multiple conditions, use \"and\" or \"or\". Got: ' +\n\t\t\t\t\tJSON.stringify(condition),\n\t\t\t)\n\t\t}\n\t\tconst columnIdentifier: QueryBuilder.ColumnIdentifier = [tableName, columnName]\n\n\t\tconst handler: {\n\t\t\t[K in keyof Required<Input.Condition<any>>]: (\n\t\t\t\tbuilder: SqlConditionBuilder,\n\t\t\t\tparam: Exclude<Input.Condition<any>[K], undefined>,\n\t\t\t) => SqlConditionBuilder\n\t\t} = {\n\t\t\tand: (builder, expressions) => builder.and(builder2 => expressions.reduce((builder3, expr) => this.build(builder3, tableName, columnName, columnType, expr), builder2)),\n\t\t\tor: (builder, expressions) => builder.or(builder2 => expressions.reduce((builder3, expr) => this.build(builder3, tableName, columnName, columnType, expr), builder2)),\n\t\t\tnot: (builder, expression) => builder.not(builder2 => this.build(builder2, tableName, columnName, columnType, expression)),\n\n\t\t\tisNull: (builder, value) => value ? builder.isNull(columnIdentifier) : builder.not(clause => clause.isNull(columnIdentifier)),\n\n\t\t\teq: (builder, value) => builder.compare(columnIdentifier, Operator.eq, value),\n\t\t\tnotEq: (builder, value) => builder.compare(columnIdentifier, Operator.notEq, value),\n\t\t\tin: (builder, values) => builder.in(columnIdentifier, values, columnType.columnType),\n\t\t\tnotIn: (builder, values) => builder.not(builder2 => builder2.in(columnIdentifier, values)),\n\t\t\tlt: (builder, value) => builder.compare(columnIdentifier, Operator.lt, value),\n\t\t\tlte: (builder, value) => builder.compare(columnIdentifier, Operator.lte, value),\n\t\t\tgt: (builder, value) => builder.compare(columnIdentifier, Operator.gt, value),\n\t\t\tgte: (builder, value) => builder.compare(columnIdentifier, Operator.gte, value),\n\n\t\t\tincludes: (builder, value) => {\n\t\t\t\tconst cast = columnType.type === Model.ColumnType.Enum\n\t\t\t\t\t? `${Compiler.SCHEMA_PLACEHOLDER}.\"${columnType.columnType}\"`\n\t\t\t\t\t: columnType.columnType\n\n\t\t\t\treturn builder.raw(`${formatColumnIdentifier(columnIdentifier)} @> ARRAY[?]::${cast}[]`, value)\n\t\t\t},\n\t\t\tmaxLength: (builder, value) => builder.raw(`array_length(${formatColumnIdentifier(columnIdentifier)}, 1) <= ?`, value),\n\t\t\tminLength: (builder, value) => builder.raw(`array_length(${formatColumnIdentifier(columnIdentifier)}, 1) >= ?`, value),\n\n\t\t\tcontains: (builder, value) => builder.compare(columnIdentifier, Operator.contains, value),\n\t\t\tstartsWith: (builder, value) => builder.compare(columnIdentifier, Operator.startsWith, value),\n\t\t\tendsWith: (builder, value) => builder.compare(columnIdentifier, Operator.endsWith, value),\n\t\t\tcontainsCI: (builder, value) => builder.compare(columnIdentifier, Operator.containsCI, value),\n\t\t\tstartsWithCI: (builder, value) => builder.compare(columnIdentifier, Operator.startsWithCI, value),\n\t\t\tendsWithCI: (builder, value) => builder.compare(columnIdentifier, Operator.endsWithCI, value),\n\n\t\t\tnever: builder => builder.raw('false'),\n\t\t\talways: builder => builder.raw('true'),\n\n\t\t\t// deprecated\n\t\t\tnull: (builder, value) => value ? builder.isNull(columnIdentifier) : builder.not(clause => clause.isNull(columnIdentifier)),\n\t\t}\n\n\t\treturn handler[entries[0][0]](builder, entries[0][1])\n\t}\n}\n"],"names":["UserError","builder","builder2","Operator","Model","Compiler","formatColumnIdentifier"],"mappings":";;;;;AAIO,MAAM,iBAAiB;AAAA,EACtB,MACN,SACA,WACA,YACA,YACA,WACsB;AACtB,QAAI,cAAc,MAAM;AAChB,aAAA;AAAA,IAAA;AAER,UAAM,UAAU,OAAO,QAAQ,SAAS,EACtC;AAAA,MAAO,CAAkC,OACzC,GAAG,CAAC,MAAM;AAAA,IACX;AACG,QAAA,QAAQ,WAAW,GAAG;AAClB,aAAA;AAAA,IAAA;AAEJ,QAAA,QAAQ,SAAS,GAAG;AACvB,YAAM,IAAIA,UAAA;AAAA,QACT,uGACC,KAAK,UAAU,SAAS;AAAA,MAC1B;AAAA,IAAA;AAEK,UAAA,mBAAkD,CAAC,WAAW,UAAU;AAE9E,UAAM,UAKF;AAAA,MACH,KAAK,CAACC,UAAS,gBAAgBA,SAAQ,IAAI,CAAAC,cAAY,YAAY,OAAO,CAAC,UAAU,SAAS,KAAK,MAAM,UAAU,WAAW,YAAY,YAAY,IAAI,GAAGA,SAAQ,CAAC;AAAA,MACtK,IAAI,CAACD,U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1
|
+
import { Model } from "@contember/schema";
|
|
2
|
+
import { Operator, Compiler, formatColumnIdentifier } from "@contember/database";
|
|
2
3
|
import { UserError } from "../../exception.js";
|
|
3
4
|
class ConditionBuilder {
|
|
4
5
|
build(builder, tableName, columnName, columnType, condition) {
|
|
@@ -21,15 +22,21 @@ class ConditionBuilder {
|
|
|
21
22
|
and: (builder2, expressions) => builder2.and((builder22) => expressions.reduce((builder3, expr) => this.build(builder3, tableName, columnName, columnType, expr), builder22)),
|
|
22
23
|
or: (builder2, expressions) => builder2.or((builder22) => expressions.reduce((builder3, expr) => this.build(builder3, tableName, columnName, columnType, expr), builder22)),
|
|
23
24
|
not: (builder2, expression) => builder2.not((builder22) => this.build(builder22, tableName, columnName, columnType, expression)),
|
|
25
|
+
isNull: (builder2, value) => value ? builder2.isNull(columnIdentifier) : builder2.not((clause) => clause.isNull(columnIdentifier)),
|
|
24
26
|
eq: (builder2, value) => builder2.compare(columnIdentifier, Operator.eq, value),
|
|
25
27
|
notEq: (builder2, value) => builder2.compare(columnIdentifier, Operator.notEq, value),
|
|
26
|
-
|
|
27
|
-
in: (builder2, values) => builder2.in(columnIdentifier, values, columnType),
|
|
28
|
+
in: (builder2, values) => builder2.in(columnIdentifier, values, columnType.columnType),
|
|
28
29
|
notIn: (builder2, values) => builder2.not((builder22) => builder22.in(columnIdentifier, values)),
|
|
29
30
|
lt: (builder2, value) => builder2.compare(columnIdentifier, Operator.lt, value),
|
|
30
31
|
lte: (builder2, value) => builder2.compare(columnIdentifier, Operator.lte, value),
|
|
31
32
|
gt: (builder2, value) => builder2.compare(columnIdentifier, Operator.gt, value),
|
|
32
33
|
gte: (builder2, value) => builder2.compare(columnIdentifier, Operator.gte, value),
|
|
34
|
+
includes: (builder2, value) => {
|
|
35
|
+
const cast = columnType.type === Model.ColumnType.Enum ? `${Compiler.SCHEMA_PLACEHOLDER}."${columnType.columnType}"` : columnType.columnType;
|
|
36
|
+
return builder2.raw(`${formatColumnIdentifier(columnIdentifier)} @> ARRAY[?]::${cast}[]`, value);
|
|
37
|
+
},
|
|
38
|
+
maxLength: (builder2, value) => builder2.raw(`array_length(${formatColumnIdentifier(columnIdentifier)}, 1) <= ?`, value),
|
|
39
|
+
minLength: (builder2, value) => builder2.raw(`array_length(${formatColumnIdentifier(columnIdentifier)}, 1) >= ?`, value),
|
|
33
40
|
contains: (builder2, value) => builder2.compare(columnIdentifier, Operator.contains, value),
|
|
34
41
|
startsWith: (builder2, value) => builder2.compare(columnIdentifier, Operator.startsWith, value),
|
|
35
42
|
endsWith: (builder2, value) => builder2.compare(columnIdentifier, Operator.endsWith, value),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConditionBuilder.js","sources":["../../../../../../packages/engine-content-api/src/mapper/select/ConditionBuilder.ts"],"sourcesContent":["import { Input } from '@contember/schema'\nimport { QueryBuilder, ConditionBuilder as SqlConditionBuilder, Operator } from '@contember/database'\nimport { UserError } from '../../exception'\n\nexport class ConditionBuilder {\n\tpublic build(\n\t\tbuilder: SqlConditionBuilder,\n\t\ttableName: string,\n\t\tcolumnName: string,\n\t\tcolumnType:
|
|
1
|
+
{"version":3,"file":"ConditionBuilder.js","sources":["../../../../../../packages/engine-content-api/src/mapper/select/ConditionBuilder.ts"],"sourcesContent":["import { Input, Model } from '@contember/schema'\nimport { QueryBuilder, ConditionBuilder as SqlConditionBuilder, Operator, Literal, formatColumnIdentifier, Compiler } from '@contember/database'\nimport { UserError } from '../../exception'\n\nexport class ConditionBuilder {\n\tpublic build(\n\t\tbuilder: SqlConditionBuilder,\n\t\ttableName: string,\n\t\tcolumnName: string,\n\t\tcolumnType: Pick<Model.AnyColumn, 'type' | 'list' | 'columnType'>,\n\t\tcondition: Input.Condition<any> | null,\n\t): SqlConditionBuilder {\n\t\tif (condition === null) {\n\t\t\treturn builder\n\t\t}\n\t\tconst entries = Object.entries(condition)\n\t\t\t.filter(<T extends keyof Input.Condition>(it: [string, any]): it is [T, Input.Condition[T]] =>\n\t\t\t\tit[1] !== null,\n\t\t\t)\n\t\tif (entries.length === 0) {\n\t\t\treturn builder\n\t\t}\n\t\tif (entries.length > 1) {\n\t\t\tthrow new UserError(\n\t\t\t\t'Only single field is allowed. If you want to combine multiple conditions, use \"and\" or \"or\". Got: ' +\n\t\t\t\t\tJSON.stringify(condition),\n\t\t\t)\n\t\t}\n\t\tconst columnIdentifier: QueryBuilder.ColumnIdentifier = [tableName, columnName]\n\n\t\tconst handler: {\n\t\t\t[K in keyof Required<Input.Condition<any>>]: (\n\t\t\t\tbuilder: SqlConditionBuilder,\n\t\t\t\tparam: Exclude<Input.Condition<any>[K], undefined>,\n\t\t\t) => SqlConditionBuilder\n\t\t} = {\n\t\t\tand: (builder, expressions) => builder.and(builder2 => expressions.reduce((builder3, expr) => this.build(builder3, tableName, columnName, columnType, expr), builder2)),\n\t\t\tor: (builder, expressions) => builder.or(builder2 => expressions.reduce((builder3, expr) => this.build(builder3, tableName, columnName, columnType, expr), builder2)),\n\t\t\tnot: (builder, expression) => builder.not(builder2 => this.build(builder2, tableName, columnName, columnType, expression)),\n\n\t\t\tisNull: (builder, value) => value ? builder.isNull(columnIdentifier) : builder.not(clause => clause.isNull(columnIdentifier)),\n\n\t\t\teq: (builder, value) => builder.compare(columnIdentifier, Operator.eq, value),\n\t\t\tnotEq: (builder, value) => builder.compare(columnIdentifier, Operator.notEq, value),\n\t\t\tin: (builder, values) => builder.in(columnIdentifier, values, columnType.columnType),\n\t\t\tnotIn: (builder, values) => builder.not(builder2 => builder2.in(columnIdentifier, values)),\n\t\t\tlt: (builder, value) => builder.compare(columnIdentifier, Operator.lt, value),\n\t\t\tlte: (builder, value) => builder.compare(columnIdentifier, Operator.lte, value),\n\t\t\tgt: (builder, value) => builder.compare(columnIdentifier, Operator.gt, value),\n\t\t\tgte: (builder, value) => builder.compare(columnIdentifier, Operator.gte, value),\n\n\t\t\tincludes: (builder, value) => {\n\t\t\t\tconst cast = columnType.type === Model.ColumnType.Enum\n\t\t\t\t\t? `${Compiler.SCHEMA_PLACEHOLDER}.\"${columnType.columnType}\"`\n\t\t\t\t\t: columnType.columnType\n\n\t\t\t\treturn builder.raw(`${formatColumnIdentifier(columnIdentifier)} @> ARRAY[?]::${cast}[]`, value)\n\t\t\t},\n\t\t\tmaxLength: (builder, value) => builder.raw(`array_length(${formatColumnIdentifier(columnIdentifier)}, 1) <= ?`, value),\n\t\t\tminLength: (builder, value) => builder.raw(`array_length(${formatColumnIdentifier(columnIdentifier)}, 1) >= ?`, value),\n\n\t\t\tcontains: (builder, value) => builder.compare(columnIdentifier, Operator.contains, value),\n\t\t\tstartsWith: (builder, value) => builder.compare(columnIdentifier, Operator.startsWith, value),\n\t\t\tendsWith: (builder, value) => builder.compare(columnIdentifier, Operator.endsWith, value),\n\t\t\tcontainsCI: (builder, value) => builder.compare(columnIdentifier, Operator.containsCI, value),\n\t\t\tstartsWithCI: (builder, value) => builder.compare(columnIdentifier, Operator.startsWithCI, value),\n\t\t\tendsWithCI: (builder, value) => builder.compare(columnIdentifier, Operator.endsWithCI, value),\n\n\t\t\tnever: builder => builder.raw('false'),\n\t\t\talways: builder => builder.raw('true'),\n\n\t\t\t// deprecated\n\t\t\tnull: (builder, value) => value ? builder.isNull(columnIdentifier) : builder.not(clause => clause.isNull(columnIdentifier)),\n\t\t}\n\n\t\treturn handler[entries[0][0]](builder, entries[0][1])\n\t}\n}\n"],"names":["builder","builder2"],"mappings":";;;AAIO,MAAM,iBAAiB;AAAA,EACtB,MACN,SACA,WACA,YACA,YACA,WACsB;AACtB,QAAI,cAAc,MAAM;AAChB,aAAA;AAAA,IAAA;AAER,UAAM,UAAU,OAAO,QAAQ,SAAS,EACtC;AAAA,MAAO,CAAkC,OACzC,GAAG,CAAC,MAAM;AAAA,IACX;AACG,QAAA,QAAQ,WAAW,GAAG;AAClB,aAAA;AAAA,IAAA;AAEJ,QAAA,QAAQ,SAAS,GAAG;AACvB,YAAM,IAAI;AAAA,QACT,uGACC,KAAK,UAAU,SAAS;AAAA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