@contember/engine-http 2.1.0-beta.1 → 2.2.0-alpha.1
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/CLAUDE.md +2 -0
- package/dist/development/index.cjs +11 -0
- package/dist/development/index.cjs.map +1 -1
- package/dist/development/index.js +12 -1
- package/dist/development/index.js.map +1 -1
- package/dist/development/src/MasterContainer.cjs +48 -7
- package/dist/development/src/MasterContainer.cjs.map +1 -1
- package/dist/development/src/MasterContainer.js +48 -7
- package/dist/development/src/MasterContainer.js.map +1 -1
- package/dist/development/src/application/application.cjs +36 -7
- package/dist/development/src/application/application.cjs.map +1 -1
- package/dist/development/src/application/application.js +36 -7
- package/dist/development/src/application/application.js.map +1 -1
- package/dist/development/src/application/forceHttpOk.cjs +34 -0
- package/dist/development/src/application/forceHttpOk.cjs.map +1 -0
- package/dist/development/src/application/forceHttpOk.js +34 -0
- package/dist/development/src/application/forceHttpOk.js.map +1 -0
- package/dist/development/src/bootstrap/Initializer.cjs.map +1 -1
- package/dist/development/src/bootstrap/Initializer.js.map +1 -1
- package/dist/development/src/common/Authorizator.cjs +61 -4
- package/dist/development/src/common/Authorizator.cjs.map +1 -1
- package/dist/development/src/common/Authorizator.js +61 -4
- package/dist/development/src/common/Authorizator.js.map +1 -1
- package/dist/development/src/common/ModuleInfoMiddleware.cjs.map +1 -1
- package/dist/development/src/common/ModuleInfoMiddleware.js.map +1 -1
- package/dist/development/src/common/NotFoundMiddleware.cjs +15 -0
- package/dist/development/src/common/NotFoundMiddleware.cjs.map +1 -0
- package/dist/development/src/common/NotFoundMiddleware.js +15 -0
- package/dist/development/src/common/NotFoundMiddleware.js.map +1 -0
- package/dist/development/src/config/config.cjs.map +1 -1
- package/dist/development/src/config/config.js.map +1 -1
- package/dist/development/src/config/configSchema.cjs +64 -2
- package/dist/development/src/config/configSchema.cjs.map +1 -1
- package/dist/development/src/config/configSchema.js +64 -2
- package/dist/development/src/config/configSchema.js.map +1 -1
- package/dist/development/src/config/configTemplate.cjs +13 -2
- package/dist/development/src/config/configTemplate.cjs.map +1 -1
- package/dist/development/src/config/configTemplate.js +13 -2
- package/dist/development/src/config/configTemplate.js.map +1 -1
- package/dist/development/src/config/projectConfigResolver.cjs.map +1 -1
- package/dist/development/src/config/projectConfigResolver.js.map +1 -1
- package/dist/development/src/config/tenantConfigResolver.cjs.map +1 -1
- package/dist/development/src/config/tenantConfigResolver.js.map +1 -1
- package/dist/development/src/content/ContentApiControllerFactory.cjs +28 -5
- package/dist/development/src/content/ContentApiControllerFactory.cjs.map +1 -1
- package/dist/development/src/content/ContentApiControllerFactory.js +28 -5
- package/dist/development/src/content/ContentApiControllerFactory.js.map +1 -1
- package/dist/development/src/content/ContentQueryHandlerFactory.cjs +2 -0
- package/dist/development/src/content/ContentQueryHandlerFactory.cjs.map +1 -1
- package/dist/development/src/content/ContentQueryHandlerFactory.js +2 -0
- package/dist/development/src/content/ContentQueryHandlerFactory.js.map +1 -1
- package/dist/development/src/content/ContentSchemaResolver.cjs.map +1 -1
- package/dist/development/src/content/ContentSchemaResolver.js.map +1 -1
- package/dist/development/src/content/GraphQlSchemaFactory.cjs +3 -3
- package/dist/development/src/content/GraphQlSchemaFactory.cjs.map +1 -1
- package/dist/development/src/content/GraphQlSchemaFactory.js +3 -3
- package/dist/development/src/content/GraphQlSchemaFactory.js.map +1 -1
- package/dist/development/src/content/NotModifiedChecker.cjs.map +1 -1
- package/dist/development/src/content/NotModifiedChecker.js.map +1 -1
- package/dist/development/src/content/ProjectMembershipResolver.cjs +1 -0
- package/dist/development/src/content/ProjectMembershipResolver.cjs.map +1 -1
- package/dist/development/src/content/ProjectMembershipResolver.js +1 -0
- package/dist/development/src/content/ProjectMembershipResolver.js.map +1 -1
- package/dist/development/src/content/triggeredActionsListener.cjs +18 -0
- package/dist/development/src/content/triggeredActionsListener.cjs.map +1 -0
- package/dist/development/src/content/triggeredActionsListener.js +18 -0
- package/dist/development/src/content/triggeredActionsListener.js.map +1 -0
- package/dist/development/src/graphql/dbQueriesListener.cjs.map +1 -1
- package/dist/development/src/graphql/dbQueriesListener.js.map +1 -1
- package/dist/development/src/misc/HomepageMiddlewareFactory.cjs +1 -0
- package/dist/development/src/misc/HomepageMiddlewareFactory.cjs.map +1 -1
- package/dist/development/src/misc/HomepageMiddlewareFactory.js +1 -0
- package/dist/development/src/misc/HomepageMiddlewareFactory.js.map +1 -1
- package/dist/development/src/project/ProjectContainer.cjs +1 -0
- package/dist/development/src/project/ProjectContainer.cjs.map +1 -1
- package/dist/development/src/project/ProjectContainer.js +1 -0
- package/dist/development/src/project/ProjectContainer.js.map +1 -1
- package/dist/development/src/project/ProjectContainerResolver.cjs.map +1 -1
- package/dist/development/src/project/ProjectContainerResolver.js.map +1 -1
- package/dist/development/src/project/ProjectContainerStore.cjs.map +1 -1
- package/dist/development/src/project/ProjectContainerStore.js.map +1 -1
- package/dist/development/src/project/ProjectInitializer.cjs.map +1 -1
- package/dist/development/src/project/ProjectInitializer.js.map +1 -1
- package/dist/development/src/project/ProjectSchemaResolver.cjs.map +1 -1
- package/dist/development/src/project/ProjectSchemaResolver.js.map +1 -1
- package/dist/development/src/project-common/ProjectContextResolver.cjs +1 -0
- package/dist/development/src/project-common/ProjectContextResolver.cjs.map +1 -1
- package/dist/development/src/project-common/ProjectContextResolver.js +1 -0
- package/dist/development/src/project-common/ProjectContextResolver.js.map +1 -1
- package/dist/development/src/projectGroup/ProjectGroupContainer.cjs +17 -4
- package/dist/development/src/projectGroup/ProjectGroupContainer.cjs.map +1 -1
- package/dist/development/src/projectGroup/ProjectGroupContainer.js +17 -4
- package/dist/development/src/projectGroup/ProjectGroupContainer.js.map +1 -1
- package/dist/development/src/projectGroup/ProjectGroupContainerResolver.cjs.map +1 -1
- package/dist/development/src/projectGroup/ProjectGroupContainerResolver.js.map +1 -1
- package/dist/development/src/projectGroup/ProjectGroupResolver.cjs +1 -0
- package/dist/development/src/projectGroup/ProjectGroupResolver.cjs.map +1 -1
- package/dist/development/src/projectGroup/ProjectGroupResolver.js +1 -0
- package/dist/development/src/projectGroup/ProjectGroupResolver.js.map +1 -1
- package/dist/development/src/prometheus/CollectHttpMetricsMiddelware.cjs.map +1 -1
- package/dist/development/src/prometheus/CollectHttpMetricsMiddelware.js.map +1 -1
- package/dist/development/src/prometheus/CustomMetric.cjs +17 -4
- package/dist/development/src/prometheus/CustomMetric.cjs.map +1 -1
- package/dist/development/src/prometheus/CustomMetric.js +17 -4
- package/dist/development/src/prometheus/CustomMetric.js.map +1 -1
- package/dist/development/src/prometheus/ProjectGroupContainerMetricsHook.cjs.map +1 -1
- package/dist/development/src/prometheus/ProjectGroupContainerMetricsHook.js.map +1 -1
- package/dist/development/src/prometheus/PrometheusRegistryFactory.cjs.map +1 -1
- package/dist/development/src/prometheus/PrometheusRegistryFactory.js.map +1 -1
- package/dist/development/src/prometheus/ShowMetricsMiddleware.cjs.map +1 -1
- package/dist/development/src/prometheus/ShowMetricsMiddleware.js.map +1 -1
- package/dist/development/src/prometheus/dbMetrics.cjs.map +1 -1
- package/dist/development/src/prometheus/dbMetrics.js.map +1 -1
- package/dist/development/src/system/ContentQueryExecutor.cjs.map +1 -1
- package/dist/development/src/system/ContentQueryExecutor.js.map +1 -1
- package/dist/development/src/system/SystemApiMiddlewareFactory.cjs +1 -0
- package/dist/development/src/system/SystemApiMiddlewareFactory.cjs.map +1 -1
- package/dist/development/src/system/SystemApiMiddlewareFactory.js +1 -0
- package/dist/development/src/system/SystemApiMiddlewareFactory.js.map +1 -1
- package/dist/development/src/system/SystemGraphQLContextFactory.cjs.map +1 -1
- package/dist/development/src/system/SystemGraphQLContextFactory.js.map +1 -1
- package/dist/development/src/system/SystemGraphQLHandlerFactory.cjs.map +1 -1
- package/dist/development/src/system/SystemGraphQLHandlerFactory.js.map +1 -1
- package/dist/development/src/tenant/OidcBackchannelLogoutMiddlewareFactory.cjs +46 -0
- package/dist/development/src/tenant/OidcBackchannelLogoutMiddlewareFactory.cjs.map +1 -0
- package/dist/development/src/tenant/OidcBackchannelLogoutMiddlewareFactory.js +46 -0
- package/dist/development/src/tenant/OidcBackchannelLogoutMiddlewareFactory.js.map +1 -0
- package/dist/development/src/tenant/TenantApiMiddlewareFactory.cjs +8 -1
- package/dist/development/src/tenant/TenantApiMiddlewareFactory.cjs.map +1 -1
- package/dist/development/src/tenant/TenantApiMiddlewareFactory.js +8 -1
- package/dist/development/src/tenant/TenantApiMiddlewareFactory.js.map +1 -1
- package/dist/development/src/tenant/TenantGraphQLHandlerFactory.cjs.map +1 -1
- package/dist/development/src/tenant/TenantGraphQLHandlerFactory.js.map +1 -1
- package/dist/development/src/testing/TestTransactions.cjs +144 -0
- package/dist/development/src/testing/TestTransactions.cjs.map +1 -0
- package/dist/development/src/testing/TestTransactions.js +144 -0
- package/dist/development/src/testing/TestTransactions.js.map +1 -0
- package/dist/development/src/transfer/CommandStream.cjs.map +1 -1
- package/dist/development/src/transfer/CommandStream.js.map +1 -1
- package/dist/development/src/transfer/ContentSchemaTransferMappingFactory.cjs +5 -2
- package/dist/development/src/transfer/ContentSchemaTransferMappingFactory.cjs.map +1 -1
- package/dist/development/src/transfer/ContentSchemaTransferMappingFactory.js +5 -2
- package/dist/development/src/transfer/ContentSchemaTransferMappingFactory.js.map +1 -1
- package/dist/development/src/transfer/ExportApiControllerFactory.cjs +1 -0
- package/dist/development/src/transfer/ExportApiControllerFactory.cjs.map +1 -1
- package/dist/development/src/transfer/ExportApiControllerFactory.js +1 -0
- package/dist/development/src/transfer/ExportApiControllerFactory.js.map +1 -1
- package/dist/development/src/transfer/ExportExecutor.cjs +8 -1
- package/dist/development/src/transfer/ExportExecutor.cjs.map +1 -1
- package/dist/development/src/transfer/ExportExecutor.js +8 -1
- package/dist/development/src/transfer/ExportExecutor.js.map +1 -1
- package/dist/development/src/transfer/ImportApiMiddlewareFactory.cjs +1 -0
- package/dist/development/src/transfer/ImportApiMiddlewareFactory.cjs.map +1 -1
- package/dist/development/src/transfer/ImportApiMiddlewareFactory.js +1 -0
- package/dist/development/src/transfer/ImportApiMiddlewareFactory.js.map +1 -1
- package/dist/development/src/transfer/ImportExecutor.cjs +55 -25
- package/dist/development/src/transfer/ImportExecutor.cjs.map +1 -1
- package/dist/development/src/transfer/ImportExecutor.js +55 -25
- package/dist/development/src/transfer/ImportExecutor.js.map +1 -1
- package/dist/development/src/transfer/SystemSchemaTransferMappingFactory.cjs.map +1 -1
- package/dist/development/src/transfer/SystemSchemaTransferMappingFactory.js.map +1 -1
- package/dist/development/src/utils/CryptoWrapper.cjs +4 -0
- package/dist/development/src/utils/CryptoWrapper.cjs.map +1 -1
- package/dist/development/src/utils/CryptoWrapper.js +4 -0
- package/dist/development/src/utils/CryptoWrapper.js.map +1 -1
- package/dist/development/src/utils/remoteAddress.cjs +5 -4
- package/dist/development/src/utils/remoteAddress.cjs.map +1 -1
- package/dist/development/src/utils/remoteAddress.js +5 -4
- package/dist/development/src/utils/remoteAddress.js.map +1 -1
- package/dist/development/src/utils/sentry.cjs.map +1 -1
- package/dist/development/src/utils/sentry.js.map +1 -1
- package/dist/development/src/utils/serverStartup.cjs +2 -2
- package/dist/development/src/utils/serverStartup.cjs.map +1 -1
- package/dist/development/src/utils/serverStartup.js.map +1 -1
- package/dist/production/index.cjs +11 -0
- package/dist/production/index.cjs.map +1 -1
- package/dist/production/index.js +12 -1
- package/dist/production/index.js.map +1 -1
- package/dist/production/src/MasterContainer.cjs +48 -7
- package/dist/production/src/MasterContainer.cjs.map +1 -1
- package/dist/production/src/MasterContainer.js +48 -7
- package/dist/production/src/MasterContainer.js.map +1 -1
- package/dist/production/src/application/application.cjs +36 -7
- package/dist/production/src/application/application.cjs.map +1 -1
- package/dist/production/src/application/application.js +36 -7
- package/dist/production/src/application/application.js.map +1 -1
- package/dist/production/src/application/forceHttpOk.cjs +34 -0
- package/dist/production/src/application/forceHttpOk.cjs.map +1 -0
- package/dist/production/src/application/forceHttpOk.js +34 -0
- package/dist/production/src/application/forceHttpOk.js.map +1 -0
- package/dist/production/src/bootstrap/Initializer.cjs.map +1 -1
- package/dist/production/src/bootstrap/Initializer.js.map +1 -1
- package/dist/production/src/common/Authorizator.cjs +61 -4
- package/dist/production/src/common/Authorizator.cjs.map +1 -1
- package/dist/production/src/common/Authorizator.js +61 -4
- package/dist/production/src/common/Authorizator.js.map +1 -1
- package/dist/production/src/common/ModuleInfoMiddleware.cjs.map +1 -1
- package/dist/production/src/common/ModuleInfoMiddleware.js.map +1 -1
- package/dist/production/src/common/NotFoundMiddleware.cjs +15 -0
- package/dist/production/src/common/NotFoundMiddleware.cjs.map +1 -0
- package/dist/production/src/common/NotFoundMiddleware.js +15 -0
- package/dist/production/src/common/NotFoundMiddleware.js.map +1 -0
- package/dist/production/src/config/config.cjs.map +1 -1
- package/dist/production/src/config/config.js.map +1 -1
- package/dist/production/src/config/configSchema.cjs +64 -2
- package/dist/production/src/config/configSchema.cjs.map +1 -1
- package/dist/production/src/config/configSchema.js +64 -2
- package/dist/production/src/config/configSchema.js.map +1 -1
- package/dist/production/src/config/configTemplate.cjs +13 -2
- package/dist/production/src/config/configTemplate.cjs.map +1 -1
- package/dist/production/src/config/configTemplate.js +13 -2
- package/dist/production/src/config/configTemplate.js.map +1 -1
- package/dist/production/src/config/projectConfigResolver.cjs.map +1 -1
- package/dist/production/src/config/projectConfigResolver.js.map +1 -1
- package/dist/production/src/config/tenantConfigResolver.cjs.map +1 -1
- package/dist/production/src/config/tenantConfigResolver.js.map +1 -1
- package/dist/production/src/content/ContentApiControllerFactory.cjs +28 -5
- package/dist/production/src/content/ContentApiControllerFactory.cjs.map +1 -1
- package/dist/production/src/content/ContentApiControllerFactory.js +28 -5
- package/dist/production/src/content/ContentApiControllerFactory.js.map +1 -1
- package/dist/production/src/content/ContentQueryHandlerFactory.cjs +2 -0
- package/dist/production/src/content/ContentQueryHandlerFactory.cjs.map +1 -1
- package/dist/production/src/content/ContentQueryHandlerFactory.js +2 -0
- package/dist/production/src/content/ContentQueryHandlerFactory.js.map +1 -1
- package/dist/production/src/content/ContentSchemaResolver.cjs.map +1 -1
- package/dist/production/src/content/ContentSchemaResolver.js.map +1 -1
- package/dist/production/src/content/GraphQlSchemaFactory.cjs +3 -3
- package/dist/production/src/content/GraphQlSchemaFactory.cjs.map +1 -1
- package/dist/production/src/content/GraphQlSchemaFactory.js +3 -3
- package/dist/production/src/content/GraphQlSchemaFactory.js.map +1 -1
- package/dist/production/src/content/NotModifiedChecker.cjs.map +1 -1
- package/dist/production/src/content/NotModifiedChecker.js.map +1 -1
- package/dist/production/src/content/ProjectMembershipResolver.cjs +1 -0
- package/dist/production/src/content/ProjectMembershipResolver.cjs.map +1 -1
- package/dist/production/src/content/ProjectMembershipResolver.js +1 -0
- package/dist/production/src/content/ProjectMembershipResolver.js.map +1 -1
- package/dist/production/src/content/triggeredActionsListener.cjs +18 -0
- package/dist/production/src/content/triggeredActionsListener.cjs.map +1 -0
- package/dist/production/src/content/triggeredActionsListener.js +18 -0
- package/dist/production/src/content/triggeredActionsListener.js.map +1 -0
- package/dist/production/src/graphql/dbQueriesListener.cjs.map +1 -1
- package/dist/production/src/graphql/dbQueriesListener.js.map +1 -1
- package/dist/production/src/misc/HomepageMiddlewareFactory.cjs +1 -0
- package/dist/production/src/misc/HomepageMiddlewareFactory.cjs.map +1 -1
- package/dist/production/src/misc/HomepageMiddlewareFactory.js +1 -0
- package/dist/production/src/misc/HomepageMiddlewareFactory.js.map +1 -1
- package/dist/production/src/project/ProjectContainer.cjs +1 -0
- package/dist/production/src/project/ProjectContainer.cjs.map +1 -1
- package/dist/production/src/project/ProjectContainer.js +1 -0
- package/dist/production/src/project/ProjectContainer.js.map +1 -1
- package/dist/production/src/project/ProjectContainerResolver.cjs.map +1 -1
- package/dist/production/src/project/ProjectContainerResolver.js.map +1 -1
- package/dist/production/src/project/ProjectContainerStore.cjs.map +1 -1
- package/dist/production/src/project/ProjectContainerStore.js.map +1 -1
- package/dist/production/src/project/ProjectInitializer.cjs.map +1 -1
- package/dist/production/src/project/ProjectInitializer.js.map +1 -1
- package/dist/production/src/project/ProjectSchemaResolver.cjs.map +1 -1
- package/dist/production/src/project/ProjectSchemaResolver.js.map +1 -1
- package/dist/production/src/project-common/ProjectContextResolver.cjs +1 -0
- package/dist/production/src/project-common/ProjectContextResolver.cjs.map +1 -1
- package/dist/production/src/project-common/ProjectContextResolver.js +1 -0
- package/dist/production/src/project-common/ProjectContextResolver.js.map +1 -1
- package/dist/production/src/projectGroup/ProjectGroupContainer.cjs +17 -4
- package/dist/production/src/projectGroup/ProjectGroupContainer.cjs.map +1 -1
- package/dist/production/src/projectGroup/ProjectGroupContainer.js +17 -4
- package/dist/production/src/projectGroup/ProjectGroupContainer.js.map +1 -1
- package/dist/production/src/projectGroup/ProjectGroupContainerResolver.cjs.map +1 -1
- package/dist/production/src/projectGroup/ProjectGroupContainerResolver.js.map +1 -1
- package/dist/production/src/projectGroup/ProjectGroupResolver.cjs +1 -0
- package/dist/production/src/projectGroup/ProjectGroupResolver.cjs.map +1 -1
- package/dist/production/src/projectGroup/ProjectGroupResolver.js +1 -0
- package/dist/production/src/projectGroup/ProjectGroupResolver.js.map +1 -1
- package/dist/production/src/prometheus/CollectHttpMetricsMiddelware.cjs.map +1 -1
- package/dist/production/src/prometheus/CollectHttpMetricsMiddelware.js.map +1 -1
- package/dist/production/src/prometheus/CustomMetric.cjs +17 -4
- package/dist/production/src/prometheus/CustomMetric.cjs.map +1 -1
- package/dist/production/src/prometheus/CustomMetric.js +17 -4
- package/dist/production/src/prometheus/CustomMetric.js.map +1 -1
- package/dist/production/src/prometheus/ProjectGroupContainerMetricsHook.cjs.map +1 -1
- package/dist/production/src/prometheus/ProjectGroupContainerMetricsHook.js.map +1 -1
- package/dist/production/src/prometheus/PrometheusRegistryFactory.cjs.map +1 -1
- package/dist/production/src/prometheus/PrometheusRegistryFactory.js.map +1 -1
- package/dist/production/src/prometheus/ShowMetricsMiddleware.cjs.map +1 -1
- package/dist/production/src/prometheus/ShowMetricsMiddleware.js.map +1 -1
- package/dist/production/src/prometheus/dbMetrics.cjs.map +1 -1
- package/dist/production/src/prometheus/dbMetrics.js.map +1 -1
- package/dist/production/src/system/ContentQueryExecutor.cjs.map +1 -1
- package/dist/production/src/system/ContentQueryExecutor.js.map +1 -1
- package/dist/production/src/system/SystemApiMiddlewareFactory.cjs +1 -0
- package/dist/production/src/system/SystemApiMiddlewareFactory.cjs.map +1 -1
- package/dist/production/src/system/SystemApiMiddlewareFactory.js +1 -0
- package/dist/production/src/system/SystemApiMiddlewareFactory.js.map +1 -1
- package/dist/production/src/system/SystemGraphQLContextFactory.cjs.map +1 -1
- package/dist/production/src/system/SystemGraphQLContextFactory.js.map +1 -1
- package/dist/production/src/system/SystemGraphQLHandlerFactory.cjs.map +1 -1
- package/dist/production/src/system/SystemGraphQLHandlerFactory.js.map +1 -1
- package/dist/production/src/tenant/OidcBackchannelLogoutMiddlewareFactory.cjs +46 -0
- package/dist/production/src/tenant/OidcBackchannelLogoutMiddlewareFactory.cjs.map +1 -0
- package/dist/production/src/tenant/OidcBackchannelLogoutMiddlewareFactory.js +46 -0
- package/dist/production/src/tenant/OidcBackchannelLogoutMiddlewareFactory.js.map +1 -0
- package/dist/production/src/tenant/TenantApiMiddlewareFactory.cjs +8 -1
- package/dist/production/src/tenant/TenantApiMiddlewareFactory.cjs.map +1 -1
- package/dist/production/src/tenant/TenantApiMiddlewareFactory.js +8 -1
- package/dist/production/src/tenant/TenantApiMiddlewareFactory.js.map +1 -1
- package/dist/production/src/tenant/TenantGraphQLHandlerFactory.cjs.map +1 -1
- package/dist/production/src/tenant/TenantGraphQLHandlerFactory.js.map +1 -1
- package/dist/production/src/testing/TestTransactions.cjs +144 -0
- package/dist/production/src/testing/TestTransactions.cjs.map +1 -0
- package/dist/production/src/testing/TestTransactions.js +144 -0
- package/dist/production/src/testing/TestTransactions.js.map +1 -0
- package/dist/production/src/transfer/CommandStream.cjs.map +1 -1
- package/dist/production/src/transfer/CommandStream.js.map +1 -1
- package/dist/production/src/transfer/ContentSchemaTransferMappingFactory.cjs +5 -2
- package/dist/production/src/transfer/ContentSchemaTransferMappingFactory.cjs.map +1 -1
- package/dist/production/src/transfer/ContentSchemaTransferMappingFactory.js +5 -2
- package/dist/production/src/transfer/ContentSchemaTransferMappingFactory.js.map +1 -1
- package/dist/production/src/transfer/ExportApiControllerFactory.cjs +1 -0
- package/dist/production/src/transfer/ExportApiControllerFactory.cjs.map +1 -1
- package/dist/production/src/transfer/ExportApiControllerFactory.js +1 -0
- package/dist/production/src/transfer/ExportApiControllerFactory.js.map +1 -1
- package/dist/production/src/transfer/ExportExecutor.cjs +8 -1
- package/dist/production/src/transfer/ExportExecutor.cjs.map +1 -1
- package/dist/production/src/transfer/ExportExecutor.js +8 -1
- package/dist/production/src/transfer/ExportExecutor.js.map +1 -1
- package/dist/production/src/transfer/ImportApiMiddlewareFactory.cjs +1 -0
- package/dist/production/src/transfer/ImportApiMiddlewareFactory.cjs.map +1 -1
- package/dist/production/src/transfer/ImportApiMiddlewareFactory.js +1 -0
- package/dist/production/src/transfer/ImportApiMiddlewareFactory.js.map +1 -1
- package/dist/production/src/transfer/ImportExecutor.cjs +55 -25
- package/dist/production/src/transfer/ImportExecutor.cjs.map +1 -1
- package/dist/production/src/transfer/ImportExecutor.js +55 -25
- package/dist/production/src/transfer/ImportExecutor.js.map +1 -1
- package/dist/production/src/transfer/SystemSchemaTransferMappingFactory.cjs.map +1 -1
- package/dist/production/src/transfer/SystemSchemaTransferMappingFactory.js.map +1 -1
- package/dist/production/src/utils/CryptoWrapper.cjs +4 -0
- package/dist/production/src/utils/CryptoWrapper.cjs.map +1 -1
- package/dist/production/src/utils/CryptoWrapper.js +4 -0
- package/dist/production/src/utils/CryptoWrapper.js.map +1 -1
- package/dist/production/src/utils/remoteAddress.cjs +5 -4
- package/dist/production/src/utils/remoteAddress.cjs.map +1 -1
- package/dist/production/src/utils/remoteAddress.js +5 -4
- package/dist/production/src/utils/remoteAddress.js.map +1 -1
- package/dist/production/src/utils/sentry.cjs.map +1 -1
- package/dist/production/src/utils/sentry.js.map +1 -1
- package/dist/production/src/utils/serverStartup.cjs +2 -2
- package/dist/production/src/utils/serverStartup.cjs.map +1 -1
- package/dist/production/src/utils/serverStartup.js.map +1 -1
- package/dist/tests/cases/unit/authenticatorGeoCountry.test.d.ts +2 -0
- package/dist/tests/cases/unit/authenticatorGeoCountry.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/forceHttpOk.test.d.ts +2 -0
- package/dist/tests/cases/unit/forceHttpOk.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/notFoundResponse.test.d.ts +2 -0
- package/dist/tests/cases/unit/notFoundResponse.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/oidcBackchannelLogout.test.d.ts +2 -0
- package/dist/tests/cases/unit/oidcBackchannelLogout.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/remoteAddress.test.d.ts +2 -0
- package/dist/tests/cases/unit/remoteAddress.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/serverConfig.test.d.ts +2 -0
- package/dist/tests/cases/unit/serverConfig.test.d.ts.map +1 -0
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/dist/types/MasterContainer.d.ts +34 -22
- package/dist/types/MasterContainer.d.ts.map +1 -1
- package/dist/types/application/application.d.ts +14 -5
- package/dist/types/application/application.d.ts.map +1 -1
- package/dist/types/application/forceHttpOk.d.ts +41 -0
- package/dist/types/application/forceHttpOk.d.ts.map +1 -0
- package/dist/types/application/index.d.ts +3 -2
- package/dist/types/application/index.d.ts.map +1 -1
- package/dist/types/bootstrap/Initializer.d.ts +1 -1
- package/dist/types/bootstrap/Initializer.d.ts.map +1 -1
- package/dist/types/bootstrap/index.d.ts +1 -1
- package/dist/types/bootstrap/index.d.ts.map +1 -1
- package/dist/types/common/Authorizator.d.ts +14 -3
- package/dist/types/common/Authorizator.d.ts.map +1 -1
- package/dist/types/common/ModuleInfoMiddleware.d.ts +1 -1
- package/dist/types/common/ModuleInfoMiddleware.d.ts.map +1 -1
- package/dist/types/common/NotFoundMiddleware.d.ts +8 -0
- package/dist/types/common/NotFoundMiddleware.d.ts.map +1 -0
- package/dist/types/common/index.d.ts +4 -3
- package/dist/types/common/index.d.ts.map +1 -1
- package/dist/types/config/ConfigProcessor.d.ts +1 -1
- package/dist/types/config/ConfigProcessor.d.ts.map +1 -1
- package/dist/types/config/config.d.ts +4 -4
- package/dist/types/config/config.d.ts.map +1 -1
- package/dist/types/config/configSchema.d.ts +37 -0
- package/dist/types/config/configSchema.d.ts.map +1 -1
- package/dist/types/config/configTemplate.d.ts.map +1 -1
- package/dist/types/config/projectConfigResolver.d.ts +3 -3
- package/dist/types/config/projectConfigResolver.d.ts.map +1 -1
- package/dist/types/config/tenantConfigResolver.d.ts +1 -1
- package/dist/types/config/tenantConfigResolver.d.ts.map +1 -1
- package/dist/types/content/ContentApiControllerFactory.d.ts +8 -6
- package/dist/types/content/ContentApiControllerFactory.d.ts.map +1 -1
- package/dist/types/content/ContentQueryHandlerFactory.d.ts +2 -2
- package/dist/types/content/ContentQueryHandlerFactory.d.ts.map +1 -1
- package/dist/types/content/GraphQLSchemaContributor.d.ts +2 -2
- package/dist/types/content/GraphQLSchemaContributor.d.ts.map +1 -1
- package/dist/types/content/GraphQlSchemaFactory.d.ts +5 -4
- package/dist/types/content/GraphQlSchemaFactory.d.ts.map +1 -1
- package/dist/types/content/NotModifiedChecker.d.ts +1 -1
- package/dist/types/content/NotModifiedChecker.d.ts.map +1 -1
- package/dist/types/content/ProjectMembershipResolver.d.ts +1 -1
- package/dist/types/content/ProjectMembershipResolver.d.ts.map +1 -1
- package/dist/types/content/index.d.ts +9 -9
- package/dist/types/content/index.d.ts.map +1 -1
- package/dist/types/content/triggeredActionsListener.d.ts +4 -0
- package/dist/types/content/triggeredActionsListener.d.ts.map +1 -0
- package/dist/types/graphql/dbQueriesListener.d.ts +1 -1
- package/dist/types/graphql/dbQueriesListener.d.ts.map +1 -1
- package/dist/types/graphql/index.d.ts +3 -3
- package/dist/types/graphql/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +29 -28
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/misc/HomepageMiddlewareFactory.d.ts +1 -1
- package/dist/types/misc/HomepageMiddlewareFactory.d.ts.map +1 -1
- package/dist/types/misc/index.d.ts +1 -1
- package/dist/types/misc/index.d.ts.map +1 -1
- package/dist/types/plugin/Plugin.d.ts +4 -4
- package/dist/types/plugin/Plugin.d.ts.map +1 -1
- package/dist/types/project/ProjectContainer.d.ts +5 -5
- package/dist/types/project/ProjectContainer.d.ts.map +1 -1
- package/dist/types/project/ProjectContainerResolver.d.ts +3 -3
- package/dist/types/project/ProjectContainerResolver.d.ts.map +1 -1
- package/dist/types/project/ProjectContainerStore.d.ts +1 -1
- package/dist/types/project/ProjectContainerStore.d.ts.map +1 -1
- package/dist/types/project/ProjectInitializer.d.ts +1 -1
- package/dist/types/project/ProjectInitializer.d.ts.map +1 -1
- package/dist/types/project/ProjectSchemaResolver.d.ts +1 -1
- package/dist/types/project/ProjectSchemaResolver.d.ts.map +1 -1
- package/dist/types/project/config.d.ts +6 -0
- package/dist/types/project/config.d.ts.map +1 -1
- package/dist/types/project/index.d.ts +4 -4
- package/dist/types/project/index.d.ts.map +1 -1
- package/dist/types/project-common/ProjectContextResolver.d.ts +3 -3
- package/dist/types/project-common/ProjectContextResolver.d.ts.map +1 -1
- package/dist/types/project-common/index.d.ts +2 -2
- package/dist/types/project-common/index.d.ts.map +1 -1
- package/dist/types/projectGroup/ProjectGroupContainer.d.ts +13 -9
- package/dist/types/projectGroup/ProjectGroupContainer.d.ts.map +1 -1
- package/dist/types/projectGroup/ProjectGroupContainerResolver.d.ts +2 -2
- package/dist/types/projectGroup/ProjectGroupContainerResolver.d.ts.map +1 -1
- package/dist/types/projectGroup/ProjectGroupResolver.d.ts +3 -3
- package/dist/types/projectGroup/ProjectGroupResolver.d.ts.map +1 -1
- package/dist/types/prometheus/CollectHttpMetricsMiddelware.d.ts +4 -4
- package/dist/types/prometheus/CollectHttpMetricsMiddelware.d.ts.map +1 -1
- package/dist/types/prometheus/CustomMetric.d.ts +1 -0
- package/dist/types/prometheus/CustomMetric.d.ts.map +1 -1
- package/dist/types/prometheus/ProjectGroupContainerMetricsHook.d.ts +1 -1
- package/dist/types/prometheus/ProjectGroupContainerMetricsHook.d.ts.map +1 -1
- package/dist/types/prometheus/PrometheusRegistryFactory.d.ts +1 -1
- package/dist/types/prometheus/PrometheusRegistryFactory.d.ts.map +1 -1
- package/dist/types/prometheus/ShowMetricsMiddleware.d.ts +1 -1
- package/dist/types/prometheus/ShowMetricsMiddleware.d.ts.map +1 -1
- package/dist/types/prometheus/index.d.ts +2 -2
- package/dist/types/prometheus/index.d.ts.map +1 -1
- package/dist/types/system/SystemApiMiddlewareFactory.d.ts +3 -3
- package/dist/types/system/SystemApiMiddlewareFactory.d.ts.map +1 -1
- package/dist/types/system/SystemGraphQLContextFactory.d.ts +3 -3
- package/dist/types/system/SystemGraphQLContextFactory.d.ts.map +1 -1
- package/dist/types/system/SystemGraphQLHandlerFactory.d.ts +1 -1
- package/dist/types/system/SystemGraphQLHandlerFactory.d.ts.map +1 -1
- package/dist/types/system/index.d.ts +3 -3
- package/dist/types/system/index.d.ts.map +1 -1
- package/dist/types/tenant/OidcBackchannelLogoutMiddlewareFactory.d.ts +18 -0
- package/dist/types/tenant/OidcBackchannelLogoutMiddlewareFactory.d.ts.map +1 -0
- package/dist/types/tenant/TenantApiMiddlewareFactory.d.ts +1 -1
- package/dist/types/tenant/TenantApiMiddlewareFactory.d.ts.map +1 -1
- package/dist/types/tenant/TenantGraphQLHandlerFactory.d.ts +1 -1
- package/dist/types/tenant/TenantGraphQLHandlerFactory.d.ts.map +1 -1
- package/dist/types/tenant/index.d.ts +3 -2
- package/dist/types/tenant/index.d.ts.map +1 -1
- package/dist/types/testing/TestTransactions.d.ts +22 -0
- package/dist/types/testing/TestTransactions.d.ts.map +1 -0
- package/dist/types/testing/index.d.ts +2 -0
- package/dist/types/testing/index.d.ts.map +1 -0
- package/dist/types/transfer/CommandStream.d.ts +1 -1
- package/dist/types/transfer/CommandStream.d.ts.map +1 -1
- package/dist/types/transfer/ContentSchemaTransferMappingFactory.d.ts +1 -1
- package/dist/types/transfer/ContentSchemaTransferMappingFactory.d.ts.map +1 -1
- package/dist/types/transfer/ExportApiControllerFactory.d.ts +3 -3
- package/dist/types/transfer/ExportApiControllerFactory.d.ts.map +1 -1
- package/dist/types/transfer/ExportExecutor.d.ts +4 -4
- package/dist/types/transfer/ExportExecutor.d.ts.map +1 -1
- package/dist/types/transfer/ImportApiMiddlewareFactory.d.ts +3 -3
- package/dist/types/transfer/ImportApiMiddlewareFactory.d.ts.map +1 -1
- package/dist/types/transfer/ImportExecutor.d.ts +6 -6
- package/dist/types/transfer/ImportExecutor.d.ts.map +1 -1
- package/dist/types/transfer/SystemSchemaTransferMappingFactory.d.ts +1 -1
- package/dist/types/transfer/SystemSchemaTransferMappingFactory.d.ts.map +1 -1
- package/dist/types/transfer/TransferMapping.d.ts +5 -1
- package/dist/types/transfer/TransferMapping.d.ts.map +1 -1
- package/dist/types/transfer/index.d.ts +6 -6
- package/dist/types/transfer/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/dist/types/utils/CryptoWrapper.d.ts +2 -0
- package/dist/types/utils/CryptoWrapper.d.ts.map +1 -1
- package/dist/types/utils/remoteAddress.d.ts.map +1 -1
- package/dist/types/utils/serverStartup.d.ts +4 -4
- package/dist/types/utils/serverStartup.d.ts.map +1 -1
- package/dist/types/workers/index.d.ts +1 -1
- package/dist/types/workers/index.d.ts.map +1 -1
- package/package.json +15 -17
- package/src/MasterContainer.ts +75 -27
- package/src/application/application.ts +44 -13
- package/src/application/forceHttpOk.ts +70 -0
- package/src/application/index.ts +3 -2
- package/src/bootstrap/Initializer.ts +1 -1
- package/src/bootstrap/index.ts +1 -1
- package/src/common/Authorizator.ts +93 -5
- package/src/common/ModuleInfoMiddleware.ts +1 -1
- package/src/common/NotFoundMiddleware.ts +18 -0
- package/src/common/index.ts +4 -3
- package/src/config/ConfigProcessor.ts +1 -1
- package/src/config/config.ts +5 -5
- package/src/config/configSchema.ts +67 -1
- package/src/config/configTemplate.ts +11 -0
- package/src/config/projectConfigResolver.ts +4 -4
- package/src/config/tenantConfigResolver.ts +2 -2
- package/src/content/ContentApiControllerFactory.ts +45 -11
- package/src/content/ContentQueryHandlerFactory.ts +4 -2
- package/src/content/ContentSchemaResolver.ts +2 -2
- package/src/content/GraphQLSchemaContributor.ts +2 -2
- package/src/content/GraphQlSchemaFactory.ts +8 -7
- package/src/content/NotModifiedChecker.ts +1 -1
- package/src/content/ProjectMembershipResolver.ts +2 -2
- package/src/content/index.ts +9 -9
- package/src/content/triggeredActionsListener.ts +17 -0
- package/src/graphql/dbQueriesListener.ts +1 -1
- package/src/graphql/index.ts +3 -3
- package/src/index.ts +28 -27
- package/src/misc/HomepageMiddlewareFactory.ts +2 -2
- package/src/misc/index.ts +1 -1
- package/src/plugin/Plugin.ts +4 -4
- package/src/project/ProjectContainer.ts +6 -6
- package/src/project/ProjectContainerResolver.ts +4 -4
- package/src/project/ProjectContainerStore.ts +1 -1
- package/src/project/ProjectInitializer.ts +1 -1
- package/src/project/ProjectSchemaResolver.ts +1 -1
- package/src/project/config.ts +6 -0
- package/src/project/index.ts +4 -4
- package/src/project-common/ProjectContextResolver.ts +2 -2
- package/src/project-common/index.ts +2 -2
- package/src/projectGroup/ProjectGroupContainer.ts +34 -11
- package/src/projectGroup/ProjectGroupContainerResolver.ts +2 -2
- package/src/projectGroup/ProjectGroupResolver.ts +4 -4
- package/src/prometheus/CollectHttpMetricsMiddelware.ts +4 -4
- package/src/prometheus/CustomMetric.ts +18 -4
- package/src/prometheus/ProjectGroupContainerMetricsHook.ts +2 -2
- package/src/prometheus/PrometheusRegistryFactory.ts +2 -2
- package/src/prometheus/ShowMetricsMiddleware.ts +1 -1
- package/src/prometheus/dbMetrics.ts +1 -1
- package/src/prometheus/index.ts +2 -2
- package/src/system/ContentQueryExecutor.ts +2 -2
- package/src/system/SystemApiMiddlewareFactory.ts +5 -5
- package/src/system/SystemGraphQLContextFactory.ts +3 -3
- package/src/system/SystemGraphQLHandlerFactory.ts +1 -1
- package/src/system/index.ts +3 -3
- package/src/tenant/OidcBackchannelLogoutMiddlewareFactory.ts +63 -0
- package/src/tenant/TenantApiMiddlewareFactory.ts +10 -4
- package/src/tenant/TenantGraphQLHandlerFactory.ts +1 -1
- package/src/tenant/index.ts +3 -2
- package/src/testing/TestTransactions.ts +237 -0
- package/src/testing/index.ts +1 -0
- package/src/transfer/CommandStream.ts +2 -2
- package/src/transfer/ContentSchemaTransferMappingFactory.ts +4 -1
- package/src/transfer/ExportApiControllerFactory.ts +6 -6
- package/src/transfer/ExportExecutor.ts +20 -6
- package/src/transfer/ImportApiMiddlewareFactory.ts +5 -5
- package/src/transfer/ImportExecutor.ts +63 -26
- package/src/transfer/SystemSchemaTransferMappingFactory.ts +2 -2
- package/src/transfer/TransferMapping.ts +10 -5
- package/src/transfer/index.ts +6 -6
- package/src/utils/CryptoWrapper.ts +5 -0
- package/src/utils/remoteAddress.ts +3 -1
- package/src/utils/sentry.ts +1 -1
- package/src/utils/serverStartup.ts +3 -3
- package/src/workers/index.ts +1 -1
- package/tests/cases/unit/authenticatorGeoCountry.test.ts +100 -0
- package/tests/cases/unit/configResolver.test.ts +33 -3
- package/tests/cases/unit/contentApiSpecificCache.tst.js +1 -1
- package/tests/cases/unit/crypto.test.ts +1 -1
- package/tests/cases/unit/forceHttpOk.test.ts +92 -0
- package/tests/cases/unit/notFoundResponse.test.ts +39 -0
- package/tests/cases/unit/oidcBackchannelLogout.test.ts +113 -0
- package/tests/cases/unit/projectMembershipResolver.test.ts +2 -2
- package/tests/cases/unit/remoteAddress.test.ts +90 -0
- package/tests/cases/unit/serverConfig.test.ts +70 -0
- package/vitest.config.ts +0 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExportExecutor.cjs","sources":["../../../../../packages/engine-http/src/transfer/ExportExecutor.ts"],"sourcesContent":["import { asyncIterableTransaction, Client, Compiler, Connection, wrapIdentifier } from '@contember/database'\nimport { Command } from './Command'\nimport { TransferMapping, TransferTableMapping } from './TransferMapping'\nimport { Model } from '@contember/schema'\nimport { ContentSchemaTransferMappingFactory } from './ContentSchemaTransferMappingFactory'\nimport { SystemSchemaTransferMappingFactory } from './SystemSchemaTransferMappingFactory'\nimport * as Typesafe from '@contember/typesafe'\nimport { StagesQuery } from '@contember/engine-system-api'\nimport { ProjectContainer } from '../project'\n\nexport type ExportRequest = ReturnType<typeof ExportRequest>\nexport const ExportRequest = Typesafe.object({\n\t// tenant: Typesafe.boolean,\n\tprojects: Typesafe.array(Typesafe.intersection(\n\t\tTypesafe.object({\n\t\t\tslug: Typesafe.string,\n\t\t\tsystem: Typesafe.boolean,\n\t\t}),\n\t\tTypesafe.partial({\n\t\t\ttargetSlug: Typesafe.string,\n\t\t\texcludeTables: Typesafe.array(Typesafe.string),\n\t\t}),\n\t)),\n})\n\nexport class ExportExecutor {\n\tconstructor(\n\t\tprivate readonly contentSchemaTransferMappingFactory: ContentSchemaTransferMappingFactory,\n\t\tprivate readonly systemSchemaTransferMappingFactory: SystemSchemaTransferMappingFactory,\n\t) {\n\t}\n\n\tasync *export(request: ExportRequest, projectContainers: Record<string, ProjectContainer>): AsyncIterable<Command> {\n\t\tfor (const project of request.projects) {\n\t\t\tconst projectContainer = projectContainers[project.slug]\n\t\t\tconst systemContext = projectContainer.systemDatabaseContext\n\n\t\t\tif (project.system) {\n\t\t\t\tconst systemMapping = this.systemSchemaTransferMappingFactory.build({\n\t\t\t\t\texcludeTables: project.excludeTables ?? [],\n\t\t\t\t})\n\t\t\t\tyield ['importSystemSchemaBegin', { project: project.targetSlug ?? project.slug, tables: Object.keys(systemMapping.tables) }]\n\t\t\t\tyield* this.exportSchema(systemContext.client, systemMapping)\n\t\t\t}\n\n\t\t\tfor (const stage of await systemContext.queryHandler.fetch(new StagesQuery())) {\n\t\t\t\tconst contentSchema = await projectContainer.contentSchemaResolver.getSchema({ db: systemContext, stage: stage.slug })\n\t\t\t\tconst contentMapping = this.contentSchemaTransferMappingFactory.createContentSchemaMapping(contentSchema.schema, {\n\t\t\t\t\texcludeTables: project.excludeTables ?? [],\n\t\t\t\t})\n\t\t\t\tconst contentDatabaseClient = projectContainer.connection.createClient(stage.schema, {})\n\n\t\t\t\tyield [\n\t\t\t\t\t'importContentSchemaBegin',\n\t\t\t\t\t{\n\t\t\t\t\t\tproject: project.targetSlug ?? project.slug,\n\t\t\t\t\t\tstage: stage.slug,\n\t\t\t\t\t\tschemaVersion: contentSchema.meta.version ?? '0000-00-00-000000',\n\t\t\t\t\t\ttables: Object.keys(contentMapping.tables),\n\t\t\t\t\t},\n\t\t\t\t]\n\n\t\t\t\tyield* this.exportSchema(contentDatabaseClient, contentMapping)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async *exportSchema(db: Client, mapping: TransferMapping): AsyncIterable<Command> {\n\t\tconst that = this\n\t\tyield* asyncIterableTransaction(db, async function*(db) {\n\t\t\tawait db.query('SET LOCAL statement_timeout = 0')\n\t\t\tawait db.query('SET TRANSACTION ISOLATION LEVEL SERIALIZABLE READ ONLY DEFERRABLE')\n\t\t\tfor (const table of Object.values(mapping.tables)) {\n\t\t\t\tyield* that.exportSequences(db, table)\n\t\t\t\tyield* that.exportTable(db, table)\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate async *exportSequences(db: Client<Connection.TransactionLike>, table: TransferTableMapping): AsyncIterable<Command> {\n\t\tfor (const column of Object.values(table.columns)) {\n\t\t\tif (column.type === Model.ColumnType.Int && column.sequence) {\n\t\t\t\tconst seqNameResult = await db.query<{ name: string }>(\n\t\t\t\t\t'SELECT pg_get_serial_sequence(?, ?) AS name',\n\t\t\t\t\t[`${db.schema}.${table.name}`, column.name],\n\t\t\t\t)\n\n\t\t\t\tconst seqNameQuoted = seqNameResult.rows[0].name.split('.').map(it => wrapIdentifier(it)).join('.')\n\t\t\t\tconst seqValueResult = await db.query<{ last_value: number | string }>(`SELECT last_value FROM ${seqNameQuoted}`)\n\t\t\t\tconst seqValue = seqValueResult.rows[0].last_value\n\t\t\t\tyield ['importSequence', { table: table.name, column: column.name, value: Number(seqValue) }]\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async *exportTable(db: Client<Connection.TransactionLike>, table: TransferTableMapping): AsyncIterable<Command> {\n\t\tconst DB_FETCH_BATCH_SIZE = 100\n\t\tconst query = (table.createSelect ?? this.buildQuery)(db, table)\n\t\tlet empty = true\n\n\t\tfor await (const row of this.cursorQuery(db, DB_FETCH_BATCH_SIZE, query.sql, query.parameters)) {\n\t\t\tif (empty) {\n\t\t\t\tyield ['insertBegin', { table: table.name, columns: Object.keys(table.columns) }]\n\t\t\t\tempty = false\n\t\t\t}\n\n\t\t\tyield ['insertRow', Object.values(row)]\n\t\t}\n\n\t\tif (!empty) {\n\t\t\tyield ['insertEnd']\n\t\t}\n\t}\n\n\tprivate buildQuery(db: Client<Connection.TransactionLike>, table: TransferTableMapping) {\n\t\tlet builder = db.selectBuilder().from(table.name)\n\n\t\tfor (const column of Object.values(table.columns)) {\n\t\t\tif (column.type === Model.ColumnType.Json || column.type === Model.ColumnType.Date || column.type === Model.ColumnType.DateTime) {\n\t\t\t\tbuilder = builder.select(expr => expr.raw(`${wrapIdentifier(column.name)}::text`))\n\t\t\t} else {\n\t\t\t\tbuilder = builder.select(column.name)\n\t\t\t}\n\t\t}\n\n\t\tconst namespaceContext = new Compiler.Context(db.schema, new Set())\n\t\treturn builder.createQuery(namespaceContext)\n\t}\n\n\tprivate async *cursorQuery(db: Client<Connection.TransactionLike>, batchSize: number, sql: string, parameters: readonly any[] = []) {\n\t\tawait db.query(`DECLARE contember_cursor NO SCROLL CURSOR FOR ${sql}`, parameters)\n\n\t\tconst fetchSql = `FETCH ${Number(batchSize)} FROM contember_cursor`\n\t\tlet resultPromise: Promise<Connection.Result> | null = db.query(fetchSql)\n\n\t\twhile (resultPromise !== null) {\n\t\t\tconst result: Connection.Result = await resultPromise\n\t\t\tresultPromise = (result.rowCount ?? 0) < batchSize ? null : db.query(fetchSql) // pipeline\n\t\t\tyield* result.rows\n\t\t}\n\n\t\tawait db.query(`CLOSE contember_cursor`)\n\t}\n}\n"],"names":["Typesafe","StagesQuery","asyncIterableTransaction","db","Model","wrapIdentifier","Compiler"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAWO,MAAM,gBAAgBA,oBAAS,OAAO;AAAA;AAAA,EAE5C,UAAUA,oBAAS,MAAMA,oBAAS;AAAA,IACjCA,oBAAS,OAAO;AAAA,MACf,MAAMA,oBAAS;AAAA,MACf,QAAQA,oBAAS;AAAA,IAAA,CACjB;AAAA,IACDA,oBAAS,QAAQ;AAAA,MAChB,YAAYA,oBAAS;AAAA,MACrB,eAAeA,oBAAS,MAAMA,oBAAS,MAAM;AAAA,IAAA,CAC7C;AAAA,EAAA,CACD;AACF,CAAC;AAEM,MAAM,eAAe;AAAA,EAC3B,YACkB,qCACA,oCAChB;AAFgB,SAAA,sCAAA;AACA,SAAA,qCAAA;AAAA,EAElB;AAAA,EAEA,OAAO,OAAO,SAAwB,mBAA6E;AAClH,eAAW,WAAW,QAAQ,UAAU;AACvC,YAAM,mBAAmB,kBAAkB,QAAQ,IAAI;AACvD,YAAM,gBAAgB,iBAAiB;AAEvC,UAAI,QAAQ,QAAQ;AACnB,cAAM,gBAAgB,KAAK,mCAAmC,MAAM;AAAA,UACnE,eAAe,QAAQ,iBAAiB,CAAA;AAAA,QAAC,CACzC;AACD,cAAM,CAAC,2BAA2B,EAAE,SAAS,QAAQ,cAAc,QAAQ,MAAM,QAAQ,OAAO,KAAK,cAAc,MAAM,GAAG;AAC5H,eAAO,KAAK,aAAa,cAAc,QAAQ,aAAa;AAAA,MAC7D;AAEA,iBAAW,SAAS,MAAM,cAAc,aAAa,MAAM,IAAIC,gBAAAA,YAAA,CAAa,GAAG;AAC9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IC,kBAAS,QAAQ,GAAG,QAAQ,oBAAI,KAAK;AAClE,WAAO,QAAQ,YAAY,gBAAgB;AAAA,EAC5C;AAAA,EAEA,OAAe,YAAY,IAAwC,WAAmB,KAAa,aAA6B,CAAA,GAAI;AACnI,UAAM,GAAG,MAAM,iDAAiD,GAAG,IAAI,UAAU;AAEjF,UAAM,WAAW,SAAS,OAAO,SAAS,CAAC;AAC3C,QAAI,gBAAmD,GAAG,MAAM,QAAQ;AAExE,WAAO,kBAAkB,MAAM;AAC9B,YAAM,SAA4B,MAAM;AACxC,uBAAiB,OAAO,YAAY,KAAK,YAAY,OAAO,GAAG,MAAM,QAAQ;AAC7E,aAAO,OAAO;AAAA,IACf;AAEA,UAAM,GAAG,MAAM,wBAAwB;AAAA,EACxC;AACD;;;"}
|
|
1
|
+
{"version":3,"file":"ExportExecutor.cjs","sources":["../../../../../packages/engine-http/src/transfer/ExportExecutor.ts"],"sourcesContent":["import { asyncIterableTransaction, Client, Compiler, Connection, wrapIdentifier } from '@contember/database'\nimport { Command } from './Command.js'\nimport { TransferMapping, TransferTableMapping } from './TransferMapping.js'\nimport { Model } from '@contember/schema'\nimport { ContentSchemaTransferMappingFactory } from './ContentSchemaTransferMappingFactory.js'\nimport { SystemSchemaTransferMappingFactory } from './SystemSchemaTransferMappingFactory.js'\nimport * as Typesafe from '@contember/typesafe'\nimport { StagesQuery } from '@contember/engine-system-api'\nimport { ProjectContainer } from '../project/index.js'\n\nexport type ExportRequest = ReturnType<typeof ExportRequest>\nexport const ExportRequest = Typesafe.object({\n\t// tenant: Typesafe.boolean,\n\tprojects: Typesafe.array(Typesafe.intersection(\n\t\tTypesafe.object({\n\t\t\tslug: Typesafe.string,\n\t\t\tsystem: Typesafe.boolean,\n\t\t}),\n\t\tTypesafe.partial({\n\t\t\ttargetSlug: Typesafe.string,\n\t\t\texcludeTables: Typesafe.array(Typesafe.string),\n\t\t}),\n\t)),\n})\n\nexport class ExportExecutor {\n\tconstructor(\n\t\tprivate readonly contentSchemaTransferMappingFactory: ContentSchemaTransferMappingFactory,\n\t\tprivate readonly systemSchemaTransferMappingFactory: SystemSchemaTransferMappingFactory,\n\t) {\n\t}\n\n\tasync *export(request: ExportRequest, projectContainers: Record<string, ProjectContainer>): AsyncIterable<Command> {\n\t\tfor (const project of request.projects) {\n\t\t\tconst projectContainer = projectContainers[project.slug]\n\t\t\tconst systemContext = projectContainer.systemDatabaseContext\n\n\t\t\tif (project.system) {\n\t\t\t\tconst systemMapping = this.systemSchemaTransferMappingFactory.build({\n\t\t\t\t\texcludeTables: project.excludeTables ?? [],\n\t\t\t\t})\n\t\t\t\tyield ['importSystemSchemaBegin', { project: project.targetSlug ?? project.slug, tables: Object.keys(systemMapping.tables) }]\n\t\t\t\tyield* this.exportSchema(systemContext.client, systemMapping)\n\t\t\t}\n\n\t\t\tfor (const stage of await systemContext.queryHandler.fetch(new StagesQuery())) {\n\t\t\t\tconst contentSchema = await projectContainer.contentSchemaResolver.getSchema({ db: systemContext, stage: stage.slug })\n\t\t\t\tconst contentMapping = this.contentSchemaTransferMappingFactory.createContentSchemaMapping(contentSchema.schema, {\n\t\t\t\t\texcludeTables: project.excludeTables ?? [],\n\t\t\t\t})\n\t\t\t\tconst contentDatabaseClient = projectContainer.connection.createClient(stage.schema, {})\n\n\t\t\t\tyield [\n\t\t\t\t\t'importContentSchemaBegin',\n\t\t\t\t\t{\n\t\t\t\t\t\tproject: project.targetSlug ?? project.slug,\n\t\t\t\t\t\tstage: stage.slug,\n\t\t\t\t\t\tschemaVersion: contentSchema.meta.version ?? '0000-00-00-000000',\n\t\t\t\t\t\ttables: Object.keys(contentMapping.tables),\n\t\t\t\t\t},\n\t\t\t\t]\n\n\t\t\t\tyield* this.exportSchema(contentDatabaseClient, contentMapping)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async *exportSchema(db: Client, mapping: TransferMapping): AsyncIterable<Command> {\n\t\tconst that = this\n\t\tyield* asyncIterableTransaction(db, async function*(db) {\n\t\t\tawait db.query('SET LOCAL statement_timeout = 0')\n\t\t\tawait db.query('SET LOCAL lock_timeout = 0')\n\t\t\tawait db.query('SET TRANSACTION ISOLATION LEVEL SERIALIZABLE READ ONLY DEFERRABLE')\n\t\t\tfor (const table of Object.values(mapping.tables)) {\n\t\t\t\tyield* that.exportSequences(db, table)\n\t\t\t\tyield* that.exportTable(db, table)\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate async *exportSequences(db: Client<Connection.TransactionLike>, table: TransferTableMapping): AsyncIterable<Command> {\n\t\tfor (const column of Object.values(table.columns)) {\n\t\t\tif (column.type === Model.ColumnType.Int && column.sequence) {\n\t\t\t\tconst seqNameResult = await db.query<{ name: string }>(\n\t\t\t\t\t'SELECT pg_get_serial_sequence(?, ?) AS name',\n\t\t\t\t\t[`${db.schema}.${table.name}`, column.name],\n\t\t\t\t)\n\n\t\t\t\tconst seqNameQuoted = seqNameResult.rows[0].name.split('.').map(it => wrapIdentifier(it)).join('.')\n\t\t\t\tconst seqValueResult = await db.query<{ last_value: number | string }>(`SELECT last_value FROM ${seqNameQuoted}`)\n\t\t\t\tconst seqValue = seqValueResult.rows[0].last_value\n\t\t\t\tyield ['importSequence', { table: table.name, column: column.name, value: Number(seqValue) }]\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async *exportTable(db: Client<Connection.TransactionLike>, table: TransferTableMapping): AsyncIterable<Command> {\n\t\tconst DB_FETCH_BATCH_SIZE = 100\n\t\tconst query = (table.createSelect ?? this.buildQuery)(db, table)\n\t\tlet empty = true\n\n\t\tfor await (const row of this.cursorQuery(db, DB_FETCH_BATCH_SIZE, query.sql, query.parameters)) {\n\t\t\tif (empty) {\n\t\t\t\tyield ['insertBegin', { table: table.name, columns: Object.keys(table.columns) }]\n\t\t\t\tempty = false\n\t\t\t}\n\n\t\t\tyield ['insertRow', Object.values(row)]\n\t\t}\n\n\t\tif (!empty) {\n\t\t\tyield ['insertEnd']\n\t\t}\n\t}\n\n\tprivate buildQuery(db: Client<Connection.TransactionLike>, table: TransferTableMapping) {\n\t\tlet builder = db.selectBuilder().from(table.name)\n\n\t\tfor (const column of Object.values(table.columns)) {\n\t\t\tif (\n\t\t\t\tcolumn.list\n\t\t\t\t&& (column.type === Model.ColumnType.Enum || column.type === Model.ColumnType.Json || column.type === Model.ColumnType.Date\n\t\t\t\t\t|| column.type === Model.ColumnType.DateTime)\n\t\t\t) {\n\t\t\t\tbuilder = builder.select(expr => expr.raw(`${wrapIdentifier(column.name)}::text[]`))\n\t\t\t} else if (column.list && column.type === Model.ColumnType.Numeric) {\n\t\t\t\tbuilder = builder.select(expr => expr.raw(`${wrapIdentifier(column.name)}::text[]`))\n\t\t\t} else if (column.list) {\n\t\t\t\tbuilder = builder.select(column.name)\n\t\t\t} else if (\n\t\t\t\tcolumn.type === Model.ColumnType.Json || column.type === Model.ColumnType.Date || column.type === Model.ColumnType.DateTime\n\t\t\t\t|| column.type === Model.ColumnType.Numeric\n\t\t\t) {\n\t\t\t\tbuilder = builder.select(expr => expr.raw(`${wrapIdentifier(column.name)}::text`))\n\t\t\t} else {\n\t\t\t\tbuilder = builder.select(column.name)\n\t\t\t}\n\t\t}\n\n\t\tconst namespaceContext = new Compiler.Context(db.schema, new Set())\n\t\treturn builder.createQuery(namespaceContext)\n\t}\n\n\tprivate async *cursorQuery(db: Client<Connection.TransactionLike>, batchSize: number, sql: string, parameters: readonly any[] = []) {\n\t\tawait db.query(`DECLARE contember_cursor NO SCROLL CURSOR FOR ${sql}`, parameters)\n\n\t\tconst fetchSql = `FETCH ${Number(batchSize)} FROM contember_cursor`\n\t\tlet resultPromise: Promise<Connection.Result> | null = db.query(fetchSql)\n\n\t\twhile (resultPromise !== null) {\n\t\t\tconst result: Connection.Result = await resultPromise\n\t\t\tresultPromise = (result.rowCount ?? 0) < batchSize ? null : db.query(fetchSql) // pipeline\n\t\t\tyield* result.rows\n\t\t}\n\n\t\tawait db.query(`CLOSE contember_cursor`)\n\t}\n}\n"],"names":["Typesafe","StagesQuery","asyncI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,SAASD,OAAAA,MAAM,WAAW,QAAQ,OAAO,SAASA,OAAAA,MAAM,WAAW,QAAQ,OAAO,SAASA,OAAAA,MAAM,WAAW,YAChH,OAAO,SAASA,OAAAA,MAAM,WAAW,SACnC;AACD,kBAAU,QAAQ,OAAO,CAAA,SAAQ,KAAK,IAAI,GAAGC,SAAAA,eAAe,OAAO,IAAI,CAAC,QAAQ,CAAC;AAAA,MAClF,OAAO;AACN,kBAAU,QAAQ,OAAO,OAAO,IAAI;AAAA,MACrC;AAAA,IACD;AAEA,UAAM,mBAAmB,IAAIC,kBAAS,QAAQ,GAAG,QAAQ,oBAAI,KAAK;AAClE,WAAO,QAAQ,YAAY,gBAAgB;AAAA,EAC5C;AAAA,EAEA,OAAe,YAAY,IAAwC,WAAmB,KAAa,aAA6B,CAAA,GAAI;AACnI,UAAM,GAAG,MAAM,iDAAiD,GAAG,IAAI,UAAU;AAEjF,UAAM,WAAW,SAAS,OAAO,SAAS,CAAC;AAC3C,QAAI,gBAAmD,GAAG,MAAM,QAAQ;AAExE,WAAO,kBAAkB,MAAM;AAC9B,YAAM,SAA4B,MAAM;AACxC,uBAAiB,OAAO,YAAY,KAAK,YAAY,OAAO,GAAG,MAAM,QAAQ;AAC7E,aAAO,OAAO;AAAA,IACf;AAEA,UAAM,GAAG,MAAM,wBAAwB;AAAA,EACxC;AACD;;;"}
|
|
@@ -54,6 +54,7 @@ class ExportExecutor {
|
|
|
54
54
|
const that = this;
|
|
55
55
|
yield* asyncIterableTransaction(db, async function* (db2) {
|
|
56
56
|
await db2.query("SET LOCAL statement_timeout = 0");
|
|
57
|
+
await db2.query("SET LOCAL lock_timeout = 0");
|
|
57
58
|
await db2.query("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE READ ONLY DEFERRABLE");
|
|
58
59
|
for (const table of Object.values(mapping.tables)) {
|
|
59
60
|
yield* that.exportSequences(db2, table);
|
|
@@ -93,7 +94,13 @@ class ExportExecutor {
|
|
|
93
94
|
buildQuery(db, table) {
|
|
94
95
|
let builder = db.selectBuilder().from(table.name);
|
|
95
96
|
for (const column of Object.values(table.columns)) {
|
|
96
|
-
if (column.type === Model.ColumnType.Json || column.type === Model.ColumnType.Date || column.type === Model.ColumnType.DateTime) {
|
|
97
|
+
if (column.list && (column.type === Model.ColumnType.Enum || column.type === Model.ColumnType.Json || column.type === Model.ColumnType.Date || column.type === Model.ColumnType.DateTime)) {
|
|
98
|
+
builder = builder.select((expr) => expr.raw(`${wrapIdentifier(column.name)}::text[]`));
|
|
99
|
+
} else if (column.list && column.type === Model.ColumnType.Numeric) {
|
|
100
|
+
builder = builder.select((expr) => expr.raw(`${wrapIdentifier(column.name)}::text[]`));
|
|
101
|
+
} else if (column.list) {
|
|
102
|
+
builder = builder.select(column.name);
|
|
103
|
+
} else if (column.type === Model.ColumnType.Json || column.type === Model.ColumnType.Date || column.type === Model.ColumnType.DateTime || column.type === Model.ColumnType.Numeric) {
|
|
97
104
|
builder = builder.select((expr) => expr.raw(`${wrapIdentifier(column.name)}::text`));
|
|
98
105
|
} else {
|
|
99
106
|
builder = builder.select(column.name);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExportExecutor.js","sources":["../../../../../packages/engine-http/src/transfer/ExportExecutor.ts"],"sourcesContent":["import { asyncIterableTransaction, Client, Compiler, Connection, wrapIdentifier } from '@contember/database'\nimport { Command } from './Command'\nimport { TransferMapping, TransferTableMapping } from './TransferMapping'\nimport { Model } from '@contember/schema'\nimport { ContentSchemaTransferMappingFactory } from './ContentSchemaTransferMappingFactory'\nimport { SystemSchemaTransferMappingFactory } from './SystemSchemaTransferMappingFactory'\nimport * as Typesafe from '@contember/typesafe'\nimport { StagesQuery } from '@contember/engine-system-api'\nimport { ProjectContainer } from '../project'\n\nexport type ExportRequest = ReturnType<typeof ExportRequest>\nexport const ExportRequest = Typesafe.object({\n\t// tenant: Typesafe.boolean,\n\tprojects: Typesafe.array(Typesafe.intersection(\n\t\tTypesafe.object({\n\t\t\tslug: Typesafe.string,\n\t\t\tsystem: Typesafe.boolean,\n\t\t}),\n\t\tTypesafe.partial({\n\t\t\ttargetSlug: Typesafe.string,\n\t\t\texcludeTables: Typesafe.array(Typesafe.string),\n\t\t}),\n\t)),\n})\n\nexport class ExportExecutor {\n\tconstructor(\n\t\tprivate readonly contentSchemaTransferMappingFactory: ContentSchemaTransferMappingFactory,\n\t\tprivate readonly systemSchemaTransferMappingFactory: SystemSchemaTransferMappingFactory,\n\t) {\n\t}\n\n\tasync *export(request: ExportRequest, projectContainers: Record<string, ProjectContainer>): AsyncIterable<Command> {\n\t\tfor (const project of request.projects) {\n\t\t\tconst projectContainer = projectContainers[project.slug]\n\t\t\tconst systemContext = projectContainer.systemDatabaseContext\n\n\t\t\tif (project.system) {\n\t\t\t\tconst systemMapping = this.systemSchemaTransferMappingFactory.build({\n\t\t\t\t\texcludeTables: project.excludeTables ?? [],\n\t\t\t\t})\n\t\t\t\tyield ['importSystemSchemaBegin', { project: project.targetSlug ?? project.slug, tables: Object.keys(systemMapping.tables) }]\n\t\t\t\tyield* this.exportSchema(systemContext.client, systemMapping)\n\t\t\t}\n\n\t\t\tfor (const stage of await systemContext.queryHandler.fetch(new StagesQuery())) {\n\t\t\t\tconst contentSchema = await projectContainer.contentSchemaResolver.getSchema({ db: systemContext, stage: stage.slug })\n\t\t\t\tconst contentMapping = this.contentSchemaTransferMappingFactory.createContentSchemaMapping(contentSchema.schema, {\n\t\t\t\t\texcludeTables: project.excludeTables ?? [],\n\t\t\t\t})\n\t\t\t\tconst contentDatabaseClient = projectContainer.connection.createClient(stage.schema, {})\n\n\t\t\t\tyield [\n\t\t\t\t\t'importContentSchemaBegin',\n\t\t\t\t\t{\n\t\t\t\t\t\tproject: project.targetSlug ?? project.slug,\n\t\t\t\t\t\tstage: stage.slug,\n\t\t\t\t\t\tschemaVersion: contentSchema.meta.version ?? '0000-00-00-000000',\n\t\t\t\t\t\ttables: Object.keys(contentMapping.tables),\n\t\t\t\t\t},\n\t\t\t\t]\n\n\t\t\t\tyield* this.exportSchema(contentDatabaseClient, contentMapping)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async *exportSchema(db: Client, mapping: TransferMapping): AsyncIterable<Command> {\n\t\tconst that = this\n\t\tyield* asyncIterableTransaction(db, async function*(db) {\n\t\t\tawait db.query('SET LOCAL statement_timeout = 0')\n\t\t\tawait db.query('SET TRANSACTION ISOLATION LEVEL SERIALIZABLE READ ONLY DEFERRABLE')\n\t\t\tfor (const table of Object.values(mapping.tables)) {\n\t\t\t\tyield* that.exportSequences(db, table)\n\t\t\t\tyield* that.exportTable(db, table)\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate async *exportSequences(db: Client<Connection.TransactionLike>, table: TransferTableMapping): AsyncIterable<Command> {\n\t\tfor (const column of Object.values(table.columns)) {\n\t\t\tif (column.type === Model.ColumnType.Int && column.sequence) {\n\t\t\t\tconst seqNameResult = await db.query<{ name: string }>(\n\t\t\t\t\t'SELECT pg_get_serial_sequence(?, ?) AS name',\n\t\t\t\t\t[`${db.schema}.${table.name}`, column.name],\n\t\t\t\t)\n\n\t\t\t\tconst seqNameQuoted = seqNameResult.rows[0].name.split('.').map(it => wrapIdentifier(it)).join('.')\n\t\t\t\tconst seqValueResult = await db.query<{ last_value: number | string }>(`SELECT last_value FROM ${seqNameQuoted}`)\n\t\t\t\tconst seqValue = seqValueResult.rows[0].last_value\n\t\t\t\tyield ['importSequence', { table: table.name, column: column.name, value: Number(seqValue) }]\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async *exportTable(db: Client<Connection.TransactionLike>, table: TransferTableMapping): AsyncIterable<Command> {\n\t\tconst DB_FETCH_BATCH_SIZE = 100\n\t\tconst query = (table.createSelect ?? this.buildQuery)(db, table)\n\t\tlet empty = true\n\n\t\tfor await (const row of this.cursorQuery(db, DB_FETCH_BATCH_SIZE, query.sql, query.parameters)) {\n\t\t\tif (empty) {\n\t\t\t\tyield ['insertBegin', { table: table.name, columns: Object.keys(table.columns) }]\n\t\t\t\tempty = false\n\t\t\t}\n\n\t\t\tyield ['insertRow', Object.values(row)]\n\t\t}\n\n\t\tif (!empty) {\n\t\t\tyield ['insertEnd']\n\t\t}\n\t}\n\n\tprivate buildQuery(db: Client<Connection.TransactionLike>, table: TransferTableMapping) {\n\t\tlet builder = db.selectBuilder().from(table.name)\n\n\t\tfor (const column of Object.values(table.columns)) {\n\t\t\tif (column.type === Model.ColumnType.Json || column.type === Model.ColumnType.Date || column.type === Model.ColumnType.DateTime) {\n\t\t\t\tbuilder = builder.select(expr => expr.raw(`${wrapIdentifier(column.name)}::text`))\n\t\t\t} else {\n\t\t\t\tbuilder = builder.select(column.name)\n\t\t\t}\n\t\t}\n\n\t\tconst namespaceContext = new Compiler.Context(db.schema, new Set())\n\t\treturn builder.createQuery(namespaceContext)\n\t}\n\n\tprivate async *cursorQuery(db: Client<Connection.TransactionLike>, batchSize: number, sql: string, parameters: readonly any[] = []) {\n\t\tawait db.query(`DECLARE contember_cursor NO SCROLL CURSOR FOR ${sql}`, parameters)\n\n\t\tconst fetchSql = `FETCH ${Number(batchSize)} FROM contember_cursor`\n\t\tlet resultPromise: Promise<Connection.Result> | null = db.query(fetchSql)\n\n\t\twhile (resultPromise !== null) {\n\t\t\tconst result: Connection.Result = await resultPromise\n\t\t\tresultPromise = (result.rowCount ?? 0) < batchSize ? null : db.query(fetchSql) // pipeline\n\t\t\tyield* result.rows\n\t\t}\n\n\t\tawait db.query(`CLOSE contember_cursor`)\n\t}\n}\n"],"names":["db"],"mappings":";;;;AAWO,MAAM,gBAAgB,SAAS,OAAO;AAAA;AAAA,EAE5C,UAAU,SAAS,MAAM,SAAS;AAAA,IACjC,SAAS,OAAO;AAAA,MACf,MAAM,SAAS;AAAA,MACf,QAAQ,SAAS;AAAA,IAAA,CACjB;AAAA,IACD,SAAS,QAAQ;AAAA,MAChB,YAAY,SAAS;AAAA,MACrB,eAAe,SAAS,MAAM,SAAS,MAAM;AAAA,IAAA,CAC7C;AAAA,EAAA,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AM,CAAC,aAAa,OAAO,OAAO,GAAG,CAAC;AAAA,IACvC;AAEA,QAAI,CAAC,OAAO;AACX,YAAM,CAAC,WAAW;AAAA,IACnB;AAAA,EACD;AAAA,EAEQ,WAAW,IAAwC,OAA6B;AACvF,QAAI,UAAU,GAAG,cAAA,EAAgB,KAAK,MAAM,IAAI;AAEhD,eAAW,UAAU,OAAO,OAAO,MAAM,OAAO,GAAG;AAClD,UAAI,OAAO,SAAS,MAAM,WAAW,QAAQ,OAAO,SAAS,MAAM,WAAW,QAAQ,OAAO,SAAS,MAAM,WAAW,UAAU;AAChI,kBAAU,QAAQ,OAAO,CAAA,SAAQ,KAAK,IAAI,GAAG,eAAe,OAAO,IAAI,CAAC,QAAQ,CAAC;AAAA,MAClF,OAAO;AACN,kBAAU,QAAQ,OAAO,OAAO,IAAI;AAAA,MACrC;AAAA,IACD;AAEA,UAAM,mBAAmB,IAAI,SAAS,QAAQ,GAAG,QAAQ,oBAAI,KAAK;AAClE,WAAO,QAAQ,YAAY,gBAAgB;AAAA,EAC5C;AAAA,EAEA,OAAe,YAAY,IAAwC,WAAmB,KAAa,aAA6B,CAAA,GAAI;AACnI,UAAM,GAAG,MAAM,iDAAiD,GAAG,IAAI,UAAU;AAEjF,UAAM,WAAW,SAAS,OAAO,SAAS,CAAC;AAC3C,QAAI,gBAAmD,GAAG,MAAM,QAAQ;AAExE,WAAO,kBAAkB,MAAM;AAC9B,YAAM,SAA4B,MAAM;AACxC,uBAAiB,OAAO,YAAY,KAAK,YAAY,OAAO,GAAG,MAAM,QAAQ;AAC7E,aAAO,OAAO;AAAA,IACf;AAEA,UAAM,GAAG,MAAM,wBAAwB;AAAA,EACxC;AACD;"}
|
|
1
|
+
{"version":3,"file":"ExportExecutor.js","sources":["../../../../../packages/engine-http/src/transfer/ExportExecutor.ts"],"sourcesContent":["import { asyncIterableTransaction, Client, Compiler, Connection, wrapIdentifier } from '@contember/database'\nimport { Command } from './Command.js'\nimport { TransferMapping, TransferTableMapping } from './TransferMapping.js'\nimport { Model } from '@contember/schema'\nimport { ContentSchemaTransferMappingFactory } from './ContentSchemaTransferMappingFactory.js'\nimport { SystemSchemaTransferMappingFactory } from './SystemSchemaTransferMappingFactory.js'\nimport * as Typesafe from '@contember/typesafe'\nimport { StagesQuery } from '@contember/engine-system-api'\nimport { ProjectContainer } from '../project/index.js'\n\nexport type ExportRequest = ReturnType<typeof ExportRequest>\nexport const ExportRequest = Typesafe.object({\n\t// tenant: Typesafe.boolean,\n\tprojects: Typesafe.array(Typesafe.intersection(\n\t\tTypesafe.object({\n\t\t\tslug: Typesafe.string,\n\t\t\tsystem: Typesafe.boolean,\n\t\t}),\n\t\tTypesafe.partial({\n\t\t\ttargetSlug: Typesafe.string,\n\t\t\texcludeTables: Typesafe.array(Typesafe.string),\n\t\t}),\n\t)),\n})\n\nexport class ExportExecutor {\n\tconstructor(\n\t\tprivate readonly contentSchemaTransferMappingFactory: ContentSchemaTransferMappingFactory,\n\t\tprivate readonly systemSchemaTransferMappingFactory: SystemSchemaTransferMappingFactory,\n\t) {\n\t}\n\n\tasync *export(request: ExportRequest, projectContainers: Record<string, ProjectContainer>): AsyncIterable<Command> {\n\t\tfor (const project of request.projects) {\n\t\t\tconst projectContainer = projectContainers[project.slug]\n\t\t\tconst systemContext = projectContainer.systemDatabaseContext\n\n\t\t\tif (project.system) {\n\t\t\t\tconst systemMapping = this.systemSchemaTransferMappingFactory.build({\n\t\t\t\t\texcludeTables: project.excludeTables ?? [],\n\t\t\t\t})\n\t\t\t\tyield ['importSystemSchemaBegin', { project: project.targetSlug ?? project.slug, tables: Object.keys(systemMapping.tables) }]\n\t\t\t\tyield* this.exportSchema(systemContext.client, systemMapping)\n\t\t\t}\n\n\t\t\tfor (const stage of await systemContext.queryHandler.fetch(new StagesQuery())) {\n\t\t\t\tconst contentSchema = await projectContainer.contentSchemaResolver.getSchema({ db: systemContext, stage: stage.slug })\n\t\t\t\tconst contentMapping = this.contentSchemaTransferMappingFactory.createContentSchemaMapping(contentSchema.schema, {\n\t\t\t\t\texcludeTables: project.excludeTables ?? [],\n\t\t\t\t})\n\t\t\t\tconst contentDatabaseClient = projectContainer.connection.createClient(stage.schema, {})\n\n\t\t\t\tyield [\n\t\t\t\t\t'importContentSchemaBegin',\n\t\t\t\t\t{\n\t\t\t\t\t\tproject: project.targetSlug ?? project.slug,\n\t\t\t\t\t\tstage: stage.slug,\n\t\t\t\t\t\tschemaVersion: contentSchema.meta.version ?? '0000-00-00-000000',\n\t\t\t\t\t\ttables: Object.keys(contentMapping.tables),\n\t\t\t\t\t},\n\t\t\t\t]\n\n\t\t\t\tyield* this.exportSchema(contentDatabaseClient, contentMapping)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async *exportSchema(db: Client, mapping: TransferMapping): AsyncIterable<Command> {\n\t\tconst that = this\n\t\tyield* asyncIterableTransaction(db, async function*(db) {\n\t\t\tawait db.query('SET LOCAL statement_timeout = 0')\n\t\t\tawait db.query('SET LOCAL lock_timeout = 0')\n\t\t\tawait db.query('SET TRANSACTION ISOLATION LEVEL SERIALIZABLE READ ONLY DEFERRABLE')\n\t\t\tfor (const table of Object.values(mapping.tables)) {\n\t\t\t\tyield* that.exportSequences(db, table)\n\t\t\t\tyield* that.exportTable(db, table)\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate async *exportSequences(db: Client<Connection.TransactionLike>, table: TransferTableMapping): AsyncIterable<Command> {\n\t\tfor (const column of Object.values(table.columns)) {\n\t\t\tif (column.type === Model.ColumnType.Int && column.sequence) {\n\t\t\t\tconst seqNameResult = await db.query<{ name: string }>(\n\t\t\t\t\t'SELECT pg_get_serial_sequence(?, ?) AS name',\n\t\t\t\t\t[`${db.schema}.${table.name}`, column.name],\n\t\t\t\t)\n\n\t\t\t\tconst seqNameQuoted = seqNameResult.rows[0].name.split('.').map(it => wrapIdentifier(it)).join('.')\n\t\t\t\tconst seqValueResult = await db.query<{ last_value: number | string }>(`SELECT last_value FROM ${seqNameQuoted}`)\n\t\t\t\tconst seqValue = seqValueResult.rows[0].last_value\n\t\t\t\tyield ['importSequence', { table: table.name, column: column.name, value: Number(seqValue) }]\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async *exportTable(db: Client<Connection.TransactionLike>, table: TransferTableMapping): AsyncIterable<Command> {\n\t\tconst DB_FETCH_BATCH_SIZE = 100\n\t\tconst query = (table.createSelect ?? this.buildQuery)(db, table)\n\t\tlet empty = true\n\n\t\tfor await (const row of this.cursorQuery(db, DB_FETCH_BATCH_SIZE, query.sql, query.parameters)) {\n\t\t\tif (empty) {\n\t\t\t\tyield ['insertBegin', { table: table.name, columns: Object.keys(table.columns) }]\n\t\t\t\tempty = false\n\t\t\t}\n\n\t\t\tyield ['insertRow', Object.values(row)]\n\t\t}\n\n\t\tif (!empty) {\n\t\t\tyield ['insertEnd']\n\t\t}\n\t}\n\n\tprivate buildQuery(db: Client<Connection.TransactionLike>, table: TransferTableMapping) {\n\t\tlet builder = db.selectBuilder().from(table.name)\n\n\t\tfor (const column of Object.values(table.columns)) {\n\t\t\tif (\n\t\t\t\tcolumn.list\n\t\t\t\t&& (column.type === Model.ColumnType.Enum || column.type === Model.ColumnType.Json || column.type === Model.ColumnType.Date\n\t\t\t\t\t|| column.type === Model.ColumnType.DateTime)\n\t\t\t) {\n\t\t\t\tbuilder = builder.select(expr => expr.raw(`${wrapIdentifier(column.name)}::text[]`))\n\t\t\t} else if (column.list && column.type === Model.ColumnType.Numeric) {\n\t\t\t\tbuilder = builder.select(expr => expr.raw(`${wrapIdentifier(column.name)}::text[]`))\n\t\t\t} else if (column.list) {\n\t\t\t\tbuilder = builder.select(column.name)\n\t\t\t} else if (\n\t\t\t\tcolumn.type === Model.ColumnType.Json || column.type === Model.ColumnType.Date || column.type === Model.ColumnType.DateTime\n\t\t\t\t|| column.type === Model.ColumnType.Numeric\n\t\t\t) {\n\t\t\t\tbuilder = builder.select(expr => expr.raw(`${wrapIdentifier(column.name)}::text`))\n\t\t\t} else {\n\t\t\t\tbuilder = builder.select(column.name)\n\t\t\t}\n\t\t}\n\n\t\tconst namespaceContext = new Compiler.Context(db.schema, new Set())\n\t\treturn builder.createQuery(namespaceContext)\n\t}\n\n\tprivate async *cursorQuery(db: Client<Connection.TransactionLike>, batchSize: number, sql: string, parameters: readonly any[] = []) {\n\t\tawait db.query(`DECLARE contember_cursor NO SCROLL CURSOR FOR ${sql}`, parameters)\n\n\t\tconst fetchSql = `FETCH ${Number(batchSize)} FROM contember_cursor`\n\t\tlet resultPromise: Promise<Connection.Result> | null = db.query(fetchSql)\n\n\t\twhile (resultPromise !== null) {\n\t\t\tconst result: Connection.Result = await resultPromise\n\t\t\tresultPromise = (result.rowCount ?? 0) < batchSize ? null : db.query(fetchSql) // pipeline\n\t\t\tyield* result.rows\n\t\t}\n\n\t\tawait db.query(`CLOSE contember_cursor`)\n\t}\n}\n"],"names":["db"],"mappings":";;;;AAWO,MAAM,gBAAgB,SAAS,OAAO;AAAA;AAAA,EAE5C,UAAU,SAAS,MAAM,SAAS;AAAA,IACjC,SAAS,OAAO;AAAA,MACf,MAAM,SAAS;AAAA,MACf,QAAQ,SAAS;AAAA,IAAA,CACjB;AAAA,IACD,SAAS,QAAQ;AAAA,MAChB,YAAY,SAAS;AAAA,MACrB,eAAe,SAAS,MAAM,SAAS,MAAM;AAAA,IAAA,CAC7C;AAAA,EAAA,CACD;AACF,CAAC;AAEM,MAAM,eAAe;AAAA,EAC3B,YACkB,qCACA,oCAChB;AAFgB,SAAA,sCAAA;AACA,SAAA,qCAAA;AAAA,EAElB;AAAA,EAEA,OAAO,OAAO,SAAwB,mBAA6E;AAClH,eAAW,WAAW,QAAQ,UAAU;AACvC,YAAM,mBAAmB,kBAAkB,QAAQ,IAAI;AACvD,YAAM,gBAAgB,iBAAiB;AAEvC,UAAI,QAAQ,QAAQ;AACnB,cAAM,gBAAgB,KAAK,mCAAmC,MAAM;AAAA,UACnE,eAAe,QAAQ,iBAAiB,CAAA;AAAA,QAAC,CACzC;AACD,cAAM,C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2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const HttpResponse = require("../common/HttpResponse.cjs");
|
|
4
|
+
require("ipaddr.js");
|
|
4
5
|
const CommandStream = require("./CommandStream.cjs");
|
|
5
6
|
const ImportExecutor = require("./ImportExecutor.cjs");
|
|
6
7
|
const node_zlib = require("node:zlib");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ImportApiMiddlewareFactory.cjs","sources":["../../../../../packages/engine-http/src/transfer/ImportApiMiddlewareFactory.ts"],"sourcesContent":["import { HttpController } from '../application'\nimport { HttpErrorResponse } from '../common'\nimport { fromBuffer } from './CommandStream'\nimport { ImportError, ImportExecutor } from './ImportExecutor'\nimport { createGunzip } from 'node:zlib'\nimport { ProjectGroupResolver } from '../projectGroup/ProjectGroupResolver'\n\nexport class ImportApiMiddlewareFactory {\n\tconstructor(\n\t\tprivate readonly projectGroupResolver: ProjectGroupResolver,\n\t\tprivate readonly importExecutor: ImportExecutor,\n\t) {\n\t}\n\n\tcreate(): HttpController {\n\t\treturn async ctx => {\n\t\t\tconst { projectGroup, authResult, koa } = ctx\n\t\t\tconst { request, response } = koa\n\t\t\tif (!authResult) {\n\t\t\t\treturn new HttpErrorResponse(401, 'Authentication required')\n\t\t\t}\n\n\t\t\tif (request.headers['content-type'] !== 'application/x-ndjson') {\n\t\t\t\tthrow new HttpErrorResponse(400, `Unsupported content type`)\n\t\t\t}\n\n\t\t\tif (request.headers['content-encoding'] !== undefined && request.headers['content-encoding'] !== 'gzip') {\n\t\t\t\tthrow new HttpErrorResponse(415, `Unsupported content encoding`)\n\t\t\t}\n\n\t\t\tresponse.headers['Content-Type'] = 'application/json'\n\n\t\t\ttry {\n\t\t\t\tconst isGzip = request.headers['content-encoding'] === 'gzip'\n\t\t\t\tconst commands = fromBuffer(isGzip ? request.req.pipe(createGunzip()) : request.req)\n\t\t\t\tawait this.importExecutor.import(projectGroup, authResult, commands)\n\t\t\t\tresponse.status = 200\n\t\t\t\tresponse.body = { ok: true }\n\t\t\t} catch (e) {\n\t\t\t\tif (e instanceof ImportError) {\n\t\t\t\t\tresponse.status = 400\n\t\t\t\t\tresponse.body = { ok: false, error: e.message }\n\t\t\t\t} else {\n\t\t\t\t\tthrow e\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n"],"names":["HttpErrorResponse","fromBuffer","createGunzip","ImportError"],"mappings":"
|
|
1
|
+
{"version":3,"file":"ImportApiMiddlewareFactory.cjs","sources":["../../../../../packages/engine-http/src/transfer/ImportApiMiddlewareFactory.ts"],"sourcesContent":["import { HttpController } from '../application/index.js'\nimport { HttpErrorResponse } from '../common/index.js'\nimport { fromBuffer } from './CommandStream.js'\nimport { ImportError, ImportExecutor } from './ImportExecutor.js'\nimport { createGunzip } from 'node:zlib'\nimport { ProjectGroupResolver } from '../projectGroup/ProjectGroupResolver.js'\n\nexport class ImportApiMiddlewareFactory {\n\tconstructor(\n\t\tprivate readonly projectGroupResolver: ProjectGroupResolver,\n\t\tprivate readonly importExecutor: ImportExecutor,\n\t) {\n\t}\n\n\tcreate(): HttpController {\n\t\treturn async ctx => {\n\t\t\tconst { projectGroup, authResult, koa } = ctx\n\t\t\tconst { request, response } = koa\n\t\t\tif (!authResult) {\n\t\t\t\treturn new HttpErrorResponse(401, 'Authentication required')\n\t\t\t}\n\n\t\t\tif (request.headers['content-type'] !== 'application/x-ndjson') {\n\t\t\t\tthrow new HttpErrorResponse(400, `Unsupported content type`)\n\t\t\t}\n\n\t\t\tif (request.headers['content-encoding'] !== undefined && request.headers['content-encoding'] !== 'gzip') {\n\t\t\t\tthrow new HttpErrorResponse(415, `Unsupported content encoding`)\n\t\t\t}\n\n\t\t\tresponse.headers['Content-Type'] = 'application/json'\n\n\t\t\ttry {\n\t\t\t\tconst isGzip = request.headers['content-encoding'] === 'gzip'\n\t\t\t\tconst commands = fromBuffer(isGzip ? request.req.pipe(createGunzip()) : request.req)\n\t\t\t\tawait this.importExecutor.import(projectGroup, authResult, commands)\n\t\t\t\tresponse.status = 200\n\t\t\t\tresponse.body = { ok: true }\n\t\t\t} catch (e) {\n\t\t\t\tif (e instanceof ImportError) {\n\t\t\t\t\tresponse.status = 400\n\t\t\t\t\tresponse.body = { ok: false, error: e.message }\n\t\t\t\t} else {\n\t\t\t\t\tthrow e\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n"],"names":["HttpErrorResponse","fromBuffer","createGunzip","ImportError"],"mappings":";;;;;;;AAOO,MAAM,2BAA2B;AAAA,EACvC,YACkB,sBACA,gBAChB;AAFgB,SAAA,uBAAA;AACA,SAAA,iBAAA;AAAA,EAElB;AAAA,EAEA,SAAyB;AACxB,WAAO,OAAM,QAAO;AACnB,YAAM,EAAE,cAAc,YAAY,IAAA,IAAQ;AAC1C,YAAM,EAAE,SAAS,SAAA,IAAa;AAC9B,UAAI,CAAC,YAAY;AAChB,eAAO,IAAIA,aAAAA,kBAAkB,KAAK,yBAAyB;AAAA,MAC5D;AAEA,UAAI,QAAQ,QAAQ,cAAc,MAAM,wBAAwB;AAC/D,cAAM,IAAIA,aAAAA,kBAAkB,KAAK,0BAA0B;AAAA,MAC5D;AAEA,UAAI,QAAQ,QAAQ,kBAAkB,MAAM,UAAa,QAAQ,QAAQ,kBAAkB,MAAM,QAAQ;AACxG,cAAM,IAAIA,aAAAA,kBAAkB,KAAK,8BAA8B;AAAA,MAChE;AAEA,eAAS,QAAQ,cAAc,IAAI;AAEnC,UAAI;AACH,cAAM,SAAS,QAAQ,QAAQ,kBAAkB,MAAM;AACvD,cAAM,WAAWC,cAAAA,WAAW,SAAS,QAAQ,IAAI,KAAKC,uBAAA,CAAc,IAAI,QAAQ,GAAG;AACnF,cAAM,KAAK,eAAe,OAAO,cAAc,YAAY,QAAQ;AACnE,iBAAS,SAAS;AAClB,iBAAS,OAAO,EAAE,IAAI,KAAA;AAAA,MACvB,SAAS,GAAG;AACX,YAAI,aAAaC,eAAAA,aAAa;AAC7B,mBAAS,SAAS;AAClB,mBAAS,OAAO,EAAE,IAAI,OAAO,OAAO,EAAE,QAAA;AAAA,QACvC,OAAO;AACN,gBAAM;AAAA,QACP;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACD;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ImportApiMiddlewareFactory.js","sources":["../../../../../packages/engine-http/src/transfer/ImportApiMiddlewareFactory.ts"],"sourcesContent":["import { HttpController } from '../application'\nimport { HttpErrorResponse } from '../common'\nimport { fromBuffer } from './CommandStream'\nimport { ImportError, ImportExecutor } from './ImportExecutor'\nimport { createGunzip } from 'node:zlib'\nimport { ProjectGroupResolver } from '../projectGroup/ProjectGroupResolver'\n\nexport class ImportApiMiddlewareFactory {\n\tconstructor(\n\t\tprivate readonly projectGroupResolver: ProjectGroupResolver,\n\t\tprivate readonly importExecutor: ImportExecutor,\n\t) {\n\t}\n\n\tcreate(): HttpController {\n\t\treturn async ctx => {\n\t\t\tconst { projectGroup, authResult, koa } = ctx\n\t\t\tconst { request, response } = koa\n\t\t\tif (!authResult) {\n\t\t\t\treturn new HttpErrorResponse(401, 'Authentication required')\n\t\t\t}\n\n\t\t\tif (request.headers['content-type'] !== 'application/x-ndjson') {\n\t\t\t\tthrow new HttpErrorResponse(400, `Unsupported content type`)\n\t\t\t}\n\n\t\t\tif (request.headers['content-encoding'] !== undefined && request.headers['content-encoding'] !== 'gzip') {\n\t\t\t\tthrow new HttpErrorResponse(415, `Unsupported content encoding`)\n\t\t\t}\n\n\t\t\tresponse.headers['Content-Type'] = 'application/json'\n\n\t\t\ttry {\n\t\t\t\tconst isGzip = request.headers['content-encoding'] === 'gzip'\n\t\t\t\tconst commands = fromBuffer(isGzip ? request.req.pipe(createGunzip()) : request.req)\n\t\t\t\tawait this.importExecutor.import(projectGroup, authResult, commands)\n\t\t\t\tresponse.status = 200\n\t\t\t\tresponse.body = { ok: true }\n\t\t\t} catch (e) {\n\t\t\t\tif (e instanceof ImportError) {\n\t\t\t\t\tresponse.status = 400\n\t\t\t\t\tresponse.body = { ok: false, error: e.message }\n\t\t\t\t} else {\n\t\t\t\t\tthrow e\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ImportApiMiddlewareFactory.js","sources":["../../../../../packages/engine-http/src/transfer/ImportApiMiddlewareFactory.ts"],"sourcesContent":["import { HttpController } from '../application/index.js'\nimport { HttpErrorResponse } from '../common/index.js'\nimport { fromBuffer } from './CommandStream.js'\nimport { ImportError, ImportExecutor } from './ImportExecutor.js'\nimport { createGunzip } from 'node:zlib'\nimport { ProjectGroupResolver } from '../projectGroup/ProjectGroupResolver.js'\n\nexport class ImportApiMiddlewareFactory {\n\tconstructor(\n\t\tprivate readonly projectGroupResolver: ProjectGroupResolver,\n\t\tprivate readonly importExecutor: ImportExecutor,\n\t) {\n\t}\n\n\tcreate(): HttpController {\n\t\treturn async ctx => {\n\t\t\tconst { projectGroup, authResult, koa } = ctx\n\t\t\tconst { request, response } = koa\n\t\t\tif (!authResult) {\n\t\t\t\treturn new HttpErrorResponse(401, 'Authentication required')\n\t\t\t}\n\n\t\t\tif (request.headers['content-type'] !== 'application/x-ndjson') {\n\t\t\t\tthrow new HttpErrorResponse(400, `Unsupported content type`)\n\t\t\t}\n\n\t\t\tif (request.headers['content-encoding'] !== undefined && request.headers['content-encoding'] !== 'gzip') {\n\t\t\t\tthrow new HttpErrorResponse(415, `Unsupported content encoding`)\n\t\t\t}\n\n\t\t\tresponse.headers['Content-Type'] = 'application/json'\n\n\t\t\ttry {\n\t\t\t\tconst isGzip = request.headers['content-encoding'] === 'gzip'\n\t\t\t\tconst commands = fromBuffer(isGzip ? request.req.pipe(createGunzip()) : request.req)\n\t\t\t\tawait this.importExecutor.import(projectGroup, authResult, commands)\n\t\t\t\tresponse.status = 200\n\t\t\t\tresponse.body = { ok: true }\n\t\t\t} catch (e) {\n\t\t\t\tif (e instanceof ImportError) {\n\t\t\t\t\tresponse.status = 400\n\t\t\t\t\tresponse.body = { ok: false, error: e.message }\n\t\t\t\t} else {\n\t\t\t\t\tthrow e\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;;;;AAOO,MAAM,2BAA2B;AAAA,EACvC,YACkB,sBACA,gBAChB;AAFgB,SAAA,uBAAA;AACA,SAAA,iBAAA;AAAA,EAElB;AAAA,EAEA,SAAyB;AACxB,WAAO,OAAM,QAAO;AACnB,YAAM,EAAE,cAAc,YAAY,IAAA,IAAQ;AAC1C,YAAM,EAAE,SAAS,SAAA,IAAa;AAC9B,UAAI,CAAC,YAAY;AAChB,eAAO,IAAI,kBAAkB,KAAK,yBAAyB;AAAA,MAC5D;AAEA,UAAI,QAAQ,QAAQ,cAAc,MAAM,wBAAwB;AAC/D,cAAM,IAAI,kBAAkB,KAAK,0BAA0B;AAAA,MAC5D;AAEA,UAAI,QAAQ,QAAQ,kBAAkB,MAAM,UAAa,QAAQ,QAAQ,kBAAkB,MAAM,QAAQ;AACxG,cAAM,IAAI,kBAAkB,KAAK,8BAA8B;AAAA,MAChE;AAEA,eAAS,QAAQ,cAAc,IAAI;AAEnC,UAAI;AACH,cAAM,SAAS,QAAQ,QAAQ,kBAAkB,MAAM;AACvD,cAAM,WAAW,WAAW,SAAS,QAAQ,IAAI,KAAK,aAAA,CAAc,IAAI,QAAQ,GAAG;AACnF,cAAM,KAAK,eAAe,OAAO,cAAc,YAAY,QAAQ;AACnE,iBAAS,SAAS;AAClB,iBAAS,OAAO,EAAE,IAAI,KAAA;AAAA,MACvB,SAAS,GAAG;AACX,YAAI,aAAa,aAAa;AAC7B,mBAAS,SAAS;AAClB,mBAAS,OAAO,EAAE,IAAI,OAAO,OAAO,EAAE,QAAA;AAAA,QACvC,OAAO;AACN,gBAAM;AAAA,QACP;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACD;"}
|
|
@@ -5,6 +5,7 @@ const schema = require("@contember/schema");
|
|
|
5
5
|
const Typesafe = require("@contember/typesafe");
|
|
6
6
|
const engineSystemApi = require("@contember/engine-system-api");
|
|
7
7
|
const HttpResponse = require("../common/HttpResponse.cjs");
|
|
8
|
+
require("ipaddr.js");
|
|
8
9
|
function _interopNamespaceDefault(e) {
|
|
9
10
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
10
11
|
if (e) {
|
|
@@ -24,6 +25,45 @@ function _interopNamespaceDefault(e) {
|
|
|
24
25
|
const Typesafe__namespace = /* @__PURE__ */ _interopNamespaceDefault(Typesafe);
|
|
25
26
|
class ImportError extends Error {
|
|
26
27
|
}
|
|
28
|
+
const parsePgTextArray = (value) => {
|
|
29
|
+
if (value === "{}") return [];
|
|
30
|
+
if (!value.startsWith("{") || !value.endsWith("}")) {
|
|
31
|
+
throw new Typesafe.ParseError([], `invalid PostgreSQL array literal: ${value}`);
|
|
32
|
+
}
|
|
33
|
+
const inner = value.slice(1, -1);
|
|
34
|
+
const result = [];
|
|
35
|
+
let current = "";
|
|
36
|
+
let inQuotes = false;
|
|
37
|
+
let escaped = false;
|
|
38
|
+
for (const ch of inner) {
|
|
39
|
+
if (escaped) {
|
|
40
|
+
current += ch;
|
|
41
|
+
escaped = false;
|
|
42
|
+
} else if (ch === "\\") {
|
|
43
|
+
escaped = true;
|
|
44
|
+
} else if (ch === '"') {
|
|
45
|
+
inQuotes = !inQuotes;
|
|
46
|
+
} else if (ch === "," && !inQuotes) {
|
|
47
|
+
result.push(current);
|
|
48
|
+
current = "";
|
|
49
|
+
} else {
|
|
50
|
+
current += ch;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
result.push(current);
|
|
54
|
+
return result;
|
|
55
|
+
};
|
|
56
|
+
const listType = (arrayType) => {
|
|
57
|
+
return (input, path = []) => {
|
|
58
|
+
if (Array.isArray(input)) {
|
|
59
|
+
return arrayType(input, path);
|
|
60
|
+
}
|
|
61
|
+
if (typeof input === "string" && input.startsWith("{")) {
|
|
62
|
+
return arrayType(parsePgTextArray(input), path);
|
|
63
|
+
}
|
|
64
|
+
return arrayType(input, path);
|
|
65
|
+
};
|
|
66
|
+
};
|
|
27
67
|
class CommandIterator {
|
|
28
68
|
constructor(commandName, commandArgs, commandIterator) {
|
|
29
69
|
this.commandName = commandName;
|
|
@@ -91,7 +131,7 @@ class ImportExecutor {
|
|
|
91
131
|
const contentDatabaseClient = projectContainer.connection.createClient(stage.schema, {});
|
|
92
132
|
const mapping = this.contentSchemaTransferMappingFactory.createContentSchemaMapping(contentSchema.schema);
|
|
93
133
|
return await contentDatabaseClient.transaction(async (db) => {
|
|
94
|
-
await this.
|
|
134
|
+
await this.disableTimeouts(db);
|
|
95
135
|
await this.disableTriggers(db, options.tables);
|
|
96
136
|
await this.lockTables(db, options.tables);
|
|
97
137
|
await this.truncateTables(db, options.tables);
|
|
@@ -118,7 +158,7 @@ class ImportExecutor {
|
|
|
118
158
|
const systemDatabaseContext = projectContainer.systemDatabaseContext;
|
|
119
159
|
const mapping = this.systemSchemaTransferMappingFactory.build();
|
|
120
160
|
return await systemDatabaseContext.client.transaction(async (db) => {
|
|
121
|
-
await this.
|
|
161
|
+
await this.disableTimeouts(db);
|
|
122
162
|
await this.truncateTables(db, options.tables);
|
|
123
163
|
const metadata = await this.databaseMetadataResolver.resolveMetadata(db, db.schema);
|
|
124
164
|
const constraintHelper = new Database.ConstraintHelper(db, metadata);
|
|
@@ -223,8 +263,9 @@ class ImportExecutor {
|
|
|
223
263
|
const tableNamesQuoted = tableNames.map((it) => `${Database.wrapIdentifier(db.schema)}.${Database.wrapIdentifier(it)}`);
|
|
224
264
|
await db.query(`TRUNCATE ${tableNamesQuoted.join(", ")}`);
|
|
225
265
|
}
|
|
226
|
-
async
|
|
266
|
+
async disableTimeouts(db) {
|
|
227
267
|
await db.query("SET LOCAL statement_timeout = 0");
|
|
268
|
+
await db.query("SET LOCAL lock_timeout = 0");
|
|
228
269
|
}
|
|
229
270
|
async insertRows(db, context) {
|
|
230
271
|
const rowsFragment = context.rows.map((_) => context.rowFragment).join(",\n");
|
|
@@ -270,7 +311,7 @@ class ImportExecutor {
|
|
|
270
311
|
}
|
|
271
312
|
async buildRowParser(db, tableMapping, columns) {
|
|
272
313
|
const baseType = Typesafe__namespace.tuple(...columns.map((it) => {
|
|
273
|
-
const base = this.buildColumnRuntimeType(it
|
|
314
|
+
const base = this.buildColumnRuntimeType(it);
|
|
274
315
|
return it.nullable ? Typesafe__namespace.nullable(base) : base;
|
|
275
316
|
}));
|
|
276
317
|
if (tableMapping.createRowParser === void 0) {
|
|
@@ -278,34 +319,23 @@ class ImportExecutor {
|
|
|
278
319
|
}
|
|
279
320
|
return await tableMapping.createRowParser(db, columns.map((it) => it.name), baseType);
|
|
280
321
|
}
|
|
281
|
-
buildColumnRuntimeType(
|
|
282
|
-
switch (
|
|
322
|
+
buildColumnRuntimeType(column) {
|
|
323
|
+
switch (column.type) {
|
|
283
324
|
case schema.Model.ColumnType.Uuid:
|
|
284
|
-
return Typesafe__namespace.string;
|
|
285
|
-
// TODO
|
|
286
325
|
case schema.Model.ColumnType.String:
|
|
287
|
-
return Typesafe__namespace.string;
|
|
288
|
-
case schema.Model.ColumnType.Int:
|
|
289
|
-
return Typesafe__namespace.number;
|
|
290
|
-
// TODO
|
|
291
|
-
case schema.Model.ColumnType.Double:
|
|
292
|
-
return Typesafe__namespace.number;
|
|
293
|
-
case schema.Model.ColumnType.Bool:
|
|
294
|
-
return Typesafe__namespace.boolean;
|
|
295
326
|
case schema.Model.ColumnType.Enum:
|
|
296
|
-
return Typesafe__namespace.string;
|
|
297
|
-
// TODO
|
|
298
327
|
case schema.Model.ColumnType.DateTime:
|
|
299
|
-
return Typesafe__namespace.string;
|
|
300
|
-
// TODO
|
|
301
328
|
case schema.Model.ColumnType.Time:
|
|
302
|
-
return Typesafe__namespace.string;
|
|
303
|
-
// TODO
|
|
304
329
|
case schema.Model.ColumnType.Date:
|
|
305
|
-
return Typesafe__namespace.string;
|
|
306
|
-
// TODO
|
|
307
330
|
case schema.Model.ColumnType.Json:
|
|
308
|
-
|
|
331
|
+
// Numeric is transferred as a string to avoid JS float precision loss.
|
|
332
|
+
case schema.Model.ColumnType.Numeric:
|
|
333
|
+
return column.list ? listType(Typesafe__namespace.array(Typesafe__namespace.string)) : Typesafe__namespace.string;
|
|
334
|
+
case schema.Model.ColumnType.Int:
|
|
335
|
+
case schema.Model.ColumnType.Double:
|
|
336
|
+
return column.list ? listType(Typesafe__namespace.array(Typesafe__namespace.number)) : Typesafe__namespace.number;
|
|
337
|
+
case schema.Model.ColumnType.Bool:
|
|
338
|
+
return column.list ? listType(Typesafe__namespace.array(Typesafe__namespace.boolean)) : Typesafe__namespace.boolean;
|
|
309
339
|
}
|
|
310
340
|
}
|
|
311
341
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ImportExecutor.cjs","sources":["../../../../../packages/engine-http/src/transfer/ImportExecutor.ts"],"sourcesContent":["import { Client, Connection, ConstraintHelper, DatabaseMetadataResolver, wrapIdentifier } from '@contember/database'\nimport { Model, Schema } from '@contember/schema'\nimport * as Typesafe from '@contember/typesafe'\nimport { ParseError } from '@contember/typesafe'\nimport { Command, CommandArgsMap, CommandName } from './Command'\nimport { DatabaseContext, StageBySlugQuery } from '@contember/engine-system-api'\nimport { DbColumnSchema, TransferMapping, TransferTableMapping } from './TransferMapping'\nimport { ContentSchemaTransferMappingFactory } from './ContentSchemaTransferMappingFactory'\nimport { SystemSchemaTransferMappingFactory } from './SystemSchemaTransferMappingFactory'\nimport { AuthResult, HttpErrorResponse } from '../common'\nimport { ProjectGroupContainer } from '../projectGroup/ProjectGroupContainer'\n\ntype Cell = boolean | number | string | null\ntype Row = readonly Cell[]\n\ntype InsertContext = {\n\ttableName: string\n\tinsertStartFragment: string\n\trowFragment: string\n\trowParser: Typesafe.Type<Row>\n\trows: Array<Row>\n\tinsertedRowCount: number\n}\n\nexport class ImportError extends Error {\n}\n\ntype CommandProcessor<T extends CommandName> = (it: CommandIterator<T>) => Promise<CommandIterator | null>\ntype CommandProcessorMap<T extends CommandName> = { [N in CommandName]?: N extends T ? CommandProcessor<N> : undefined }\n\nclass CommandIterator<T extends CommandName = CommandName> {\n\tprivate constructor(\n\t\tpublic readonly commandName: T,\n\t\tpublic readonly commandArgs: CommandArgsMap[T],\n\t\tprivate readonly commandIterator: AsyncIterator<Command>,\n\t) {\n\t}\n\n\tpublic static async create(commands: AsyncIterable<Command>): Promise<CommandIterator | null> {\n\t\tconst commandIterator = commands[Symbol.asyncIterator]()\n\t\tconst result = await commandIterator.next()\n\n\t\tif (result.done) {\n\t\t\treturn null\n\t\t}\n\n\t\tconst [name, ...args] = result.value\n\t\treturn new CommandIterator(name, args, commandIterator)\n\t}\n\n\tasync next(): Promise<CommandIterator | null> {\n\t\tconst result = await this.commandIterator.next()\n\n\t\tif (result.done) {\n\t\t\treturn null\n\t\t}\n\n\t\tconst [name, ...args] = result.value\n\t\treturn new CommandIterator(name, args, this.commandIterator)\n\t}\n}\n\nexport class ImportExecutor {\n\tconstructor(\n\t\tprivate readonly contentSchemaTransferMappingFactory: ContentSchemaTransferMappingFactory,\n\t\tprivate readonly systemSchemaTransferMappingFactory: SystemSchemaTransferMappingFactory,\n\t\tprivate readonly databaseMetadataResolver: DatabaseMetadataResolver,\n\t) {\n\t}\n\n\tasync import(groupContainer: ProjectGroupContainer, authResult: AuthResult, commands: AsyncIterable<Command>) {\n\t\tconst it = await CommandIterator.create(commands)\n\n\t\tconst final = await this.match(it, {\n\t\t\timportContentSchemaBegin: it => this.importContentSchemaBegin(groupContainer, authResult, it),\n\t\t\timportSystemSchemaBegin: it => this.importSystemSchemaBegin(groupContainer, authResult, it),\n\t\t})\n\n\t\tif (final !== null) {\n\t\t\tthrow new ImportError(`Unexpected ${final.commandName}`)\n\t\t}\n\t}\n\n\tprivate async match<T extends CommandName>(it: CommandIterator<T> | null, processors: CommandProcessorMap<T>) {\n\t\tlet next: CommandIterator | null = it\n\n\t\twhile (next !== null) {\n\t\t\tconst processor = processors[next.commandName]\n\n\t\t\tif (processor) {\n\t\t\t\tnext = await processor(next as any)\n\t\t\t} else {\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\treturn next\n\t}\n\n\tprivate async importContentSchemaBegin(\n\t\tgroupContainer: ProjectGroupContainer,\n\t\tauthResult: AuthResult,\n\t\tit: CommandIterator<'importContentSchemaBegin'>,\n\t) {\n\t\tconst [options] = it.commandArgs\n\t\tconst projectContainer = await this.createProjectContainer(groupContainer, options.project)\n\t\tconst systemDatabaseContext = projectContainer.systemDatabaseContext\n\t\tconst stage = await this.fetchStageBySlug(systemDatabaseContext, options.project, options.stage)\n\n\t\tconst contentSchema = await projectContainer.contentSchemaResolver.getSchema({ db: systemDatabaseContext, stage: stage.slug, normalize: true })\n\n\t\tif (contentSchema.meta.version !== options.schemaVersion) {\n\t\t\tthrow new ImportError(\n\t\t\t\t`Incompatible schema version (import version ${options.schemaVersion} does not match server version ${contentSchema.meta.version})`,\n\t\t\t)\n\t\t}\n\n\t\tawait this.requireImportAccess(groupContainer, contentSchema.schema, authResult, options.project, 'content')\n\t\tconst contentDatabaseClient = projectContainer.connection.createClient(stage.schema, {})\n\t\tconst mapping = this.contentSchemaTransferMappingFactory.createContentSchemaMapping(contentSchema.schema)\n\n\t\treturn await contentDatabaseClient.transaction(async db => {\n\t\t\tawait this.disableStatementTimeout(db)\n\t\t\tawait this.disableTriggers(db, options.tables)\n\t\t\tawait this.lockTables(db, options.tables)\n\t\t\tawait this.truncateTables(db, options.tables)\n\n\t\t\tconst metadata = await this.databaseMetadataResolver.resolveMetadata(db, db.schema)\n\t\t\tconst constraintHelper = new ConstraintHelper(db, metadata)\n\t\t\tawait constraintHelper.setConstraintsDeferred('foreignKey')\n\n\t\t\tconst result = await this.match(await it.next(), {\n\t\t\t\timportSequence: it => this.importSequence(db, mapping, it),\n\t\t\t\tinsertBegin: it => this.insertBegin(db, mapping, it),\n\t\t\t})\n\n\t\t\tawait constraintHelper.setConstraintsImmediate('foreignKey')\n\t\t\tawait this.enableTriggers(db, options.tables)\n\n\t\t\treturn result\n\t\t})\n\t}\n\n\tprivate async importSystemSchemaBegin(\n\t\tgroupContainer: ProjectGroupContainer,\n\t\tauthResult: AuthResult,\n\t\tit: CommandIterator<'importSystemSchemaBegin'>,\n\t) {\n\t\tconst [options] = it.commandArgs\n\t\tconst projectContainer = await this.createProjectContainer(groupContainer, options.project)\n\t\tconst schema = await groupContainer.projectSchemaResolver.getSchema(options.project)\n\n\t\tif (schema === undefined) {\n\t\t\tthrow new ImportError(`Project ${options.project} does not have schema`)\n\t\t}\n\n\t\tawait this.requireImportAccess(groupContainer, schema, authResult, options.project, 'system')\n\t\tconst systemDatabaseContext = projectContainer.systemDatabaseContext\n\t\tconst mapping = this.systemSchemaTransferMappingFactory.build()\n\n\t\treturn await systemDatabaseContext.client.transaction(async db => {\n\t\t\tawait this.disableStatementTimeout(db)\n\t\t\tawait this.truncateTables(db, options.tables)\n\n\t\t\tconst metadata = await this.databaseMetadataResolver.resolveMetadata(db, db.schema)\n\t\t\tconst constraintHelper = new ConstraintHelper(db, metadata)\n\t\t\tawait constraintHelper.setConstraintsDeferred('foreignKey')\n\n\t\t\treturn await this.match(await it.next(), {\n\t\t\t\tinsertBegin: it => this.insertBegin(db, mapping, it),\n\t\t\t})\n\t\t})\n\t}\n\n\tprivate async importSequence(\n\t\tdb: Client<Connection.TransactionLike>,\n\t\tmapping: TransferMapping,\n\t\tit: CommandIterator<'importSequence'>,\n\t): Promise<CommandIterator | null> {\n\t\tconst [options] = it.commandArgs\n\n\t\tawait db.query(\n\t\t\t'SELECT setval(pg_get_serial_sequence(?, ?), ?)',\n\t\t\t[`${db.schema}.${options.table}`, options.column, options.value],\n\t\t)\n\n\t\treturn it.next()\n\t}\n\n\tprivate async insertBegin(\n\t\tdb: Client<Connection.TransactionLike>,\n\t\tmapping: TransferMapping,\n\t\tit: CommandIterator<'insertBegin'>,\n\t): Promise<CommandIterator | null> {\n\t\tconst [options] = it.commandArgs\n\t\tconst insertContext = await this.buildInsertContext(db, mapping, db.schema, options.table, options.columns)\n\t\tlet insertRowsPromise: Promise<Connection.Result> | null = null\n\n\t\t// postgresql has a limit of 65535 parameters per query\n\t\tconst batchSize = Math.max(1, Math.min(1000, Math.floor(65500 / options.columns.length)))\n\n\t\tconst result = await this.match(await it.next(), {\n\t\t\tinsertRow: async it => {\n\t\t\t\tconst [values] = it.commandArgs\n\n\t\t\t\ttry {\n\t\t\t\t\tinsertContext.rows.push(insertContext.rowParser(values))\n\t\t\t\t} catch (e) {\n\t\t\t\t\tif (e instanceof ParseError) {\n\t\t\t\t\t\tthrow new ImportError(`Invalid row ${JSON.stringify(values)} for table ${options.table}: ${e.message}`)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow e\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (insertContext.rows.length === batchSize) {\n\t\t\t\t\tawait insertRowsPromise\n\t\t\t\t\tinsertRowsPromise = this.insertRows(db, insertContext)\n\t\t\t\t\tinsertContext.insertedRowCount += insertContext.rows.length\n\t\t\t\t\tinsertContext.rows = []\n\t\t\t\t}\n\n\t\t\t\treturn await it.next()\n\t\t\t},\n\t\t})\n\n\t\tif (insertContext.rows.length > 0) {\n\t\t\tawait insertRowsPromise\n\t\t\tawait this.insertRows(db, insertContext)\n\t\t\tinsertContext.insertedRowCount += insertContext.rows.length\n\t\t\tinsertContext.rows = []\n\t\t}\n\n\t\tif (result === null || result.commandName !== 'insertEnd') {\n\t\t\tthrow new ImportError(`Missing insertEnd command`)\n\t\t}\n\n\t\treturn await result.next()\n\t}\n\n\tprivate async createProjectContainer(groupContainer: ProjectGroupContainer, projectSlug: string) {\n\t\tconst projectContainerResolver = groupContainer.projectContainerResolver\n\t\tconst projectContainer = await projectContainerResolver.getProjectContainer(projectSlug, { alias: true })\n\n\t\tif (projectContainer === undefined) {\n\t\t\tthrow new ImportError(`Project ${projectSlug} does not exists.`)\n\t\t}\n\n\t\treturn projectContainer\n\t}\n\n\tprivate async requireImportAccess(\n\t\tgroupContainer: ProjectGroupContainer,\n\t\tschema: Schema,\n\t\tauthResult: AuthResult,\n\t\tprojectSlug: string,\n\t\tkind: 'content' | 'system',\n\t) {\n\t\tconst { effective: memberships } = await groupContainer.projectMembershipResolver.resolveMemberships({\n\t\t\trequest: { get: () => '' },\n\t\t\tacl: schema.acl,\n\t\t\tprojectSlug: projectSlug,\n\t\t\tidentity: {\n\t\t\t\tidentityId: authResult.identityId,\n\t\t\t\troles: authResult.roles,\n\t\t\t},\n\t\t})\n\n\t\tconst projectRoles = memberships.map(it => it.role)\n\n\t\tif (!projectRoles.some(role => schema.acl.roles[role]?.[kind]?.import)) {\n\t\t\tthrow new HttpErrorResponse(403, `You are not allowed to import ${kind} in ${projectSlug}`)\n\t\t}\n\t}\n\n\tprivate async fetchStageBySlug(systemDatabaseContext: DatabaseContext, projectSlug: string, stageSlug: string) {\n\t\tconst stage = await systemDatabaseContext.queryHandler.fetch(new StageBySlugQuery(stageSlug))\n\n\t\tif (stage === null) {\n\t\t\tthrow new ImportError(`Project ${projectSlug} does not have stage ${stageSlug}.`)\n\t\t}\n\n\t\treturn stage\n\t}\n\n\tprivate async disableTriggers(db: Client, tableNames: readonly string[]) {\n\t\tfor (const tableName of tableNames) {\n\t\t\tconst tableNameQuoted = `${wrapIdentifier(db.schema)}.${wrapIdentifier(tableName)}`\n\t\t\tawait db.query(`ALTER TABLE ${tableNameQuoted} DISABLE TRIGGER USER`)\n\t\t}\n\t}\n\n\tprivate async enableTriggers(db: Client, tableNames: readonly string[]) {\n\t\tfor (const tableName of tableNames) {\n\t\t\tconst tableNameQuoted = `${wrapIdentifier(db.schema)}.${wrapIdentifier(tableName)}`\n\t\t\tawait db.query(`ALTER TABLE ${tableNameQuoted} ENABLE TRIGGER USER`)\n\t\t}\n\t}\n\n\tprivate async lockTables(db: Client, tableNames: readonly string[]) {\n\t\tconst tableNamesQuoted = tableNames.map(it => `${wrapIdentifier(db.schema)}.${wrapIdentifier(it)}`)\n\t\tawait db.query(`LOCK ${tableNamesQuoted.join(', ')} IN EXCLUSIVE MODE`)\n\t}\n\n\tprivate async truncateTables(db: Client, tableNames: readonly string[]) {\n\t\tconst tableNamesQuoted = tableNames.map(it => `${wrapIdentifier(db.schema)}.${wrapIdentifier(it)}`)\n\t\tawait db.query(`TRUNCATE ${tableNamesQuoted.join(', ')}`)\n\t}\n\n\tprivate async disableStatementTimeout(db: Client) {\n\t\tawait db.query('SET LOCAL statement_timeout = 0')\n\t}\n\n\tprivate async insertRows(db: Client, context: InsertContext) {\n\t\tconst rowsFragment = context.rows.map(_ => context.rowFragment).join(',\\n')\n\t\tconst sql = context.insertStartFragment + rowsFragment\n\t\tconst parameters: Cell[] = []\n\n\t\tfor (const row of context.rows) {\n\t\t\tfor (const cell of row) {\n\t\t\t\tparameters.push(cell)\n\t\t\t}\n\t\t}\n\n\t\treturn await db.query(sql, parameters)\n\t}\n\n\tprivate async buildInsertContext(\n\t\tdb: Client,\n\t\tmapping: TransferMapping,\n\t\tschema: string,\n\t\ttableName: string,\n\t\tcolumnNames: readonly string[],\n\t): Promise<InsertContext> {\n\t\tconst tableMapping = mapping.tables[tableName]\n\t\tconst columns = []\n\n\t\tif (tableMapping === undefined) {\n\t\t\tthrow new ImportError(`Unknown table ${tableName}`)\n\t\t}\n\n\t\tfor (const columnName of columnNames) {\n\t\t\tconst column = tableMapping.columns[columnName]\n\n\t\t\tif (column === undefined) {\n\t\t\t\tthrow new ImportError(`Unknown column ${tableName}.${columnName}`)\n\t\t\t}\n\n\t\t\tcolumns.push(column)\n\t\t}\n\n\t\tconst insertStartFragment = (tableMapping.createInsertStartFragment ?? this.createInsertStartFragment)(schema, tableName, columnNames)\n\t\tconst rowFragment = '(' + columns.map(_ => '?').join(', ') + ')'\n\t\tconst rowParser = await this.buildRowParser(db, tableMapping, columns)\n\n\t\treturn {\n\t\t\ttableName,\n\t\t\tinsertStartFragment,\n\t\t\trowFragment,\n\t\t\trowParser,\n\t\t\trows: [],\n\t\t\tinsertedRowCount: 0,\n\t\t}\n\t}\n\n\tprivate createInsertStartFragment(schema: string, tableName: string, columnNames: readonly string[]): string {\n\t\tconst tableQuoted = `${wrapIdentifier(schema)}.${wrapIdentifier(tableName)}`\n\t\tconst columnsQuoted = '(' + columnNames.map(it => wrapIdentifier(it)).join(', ') + ')'\n\t\treturn `INSERT INTO ${tableQuoted} ${columnsQuoted} VALUES\\n`\n\t}\n\n\tprivate async buildRowParser(db: Client, tableMapping: TransferTableMapping, columns: DbColumnSchema[]): Promise<Typesafe.Type<readonly Cell[]>> {\n\t\tconst baseType = Typesafe.tuple(...columns.map(it => {\n\t\t\tconst base = this.buildColumnRuntimeType(it.type)\n\t\t\treturn it.nullable ? Typesafe.nullable(base) : base\n\t\t}))\n\n\t\tif (tableMapping.createRowParser === undefined) {\n\t\t\treturn baseType\n\t\t}\n\n\t\treturn await tableMapping.createRowParser(db, columns.map(it => it.name), baseType)\n\t}\n\n\tprivate buildColumnRuntimeType(columnType: Model.ColumnType): Typesafe.Type<Exclude<Cell, null>> {\n\t\tswitch (columnType) {\n\t\t\tcase Model.ColumnType.Uuid:\n\t\t\t\treturn Typesafe.string // TODO\n\t\t\tcase Model.ColumnType.String:\n\t\t\t\treturn Typesafe.string\n\t\t\tcase Model.ColumnType.Int:\n\t\t\t\treturn Typesafe.number // TODO\n\t\t\tcase Model.ColumnType.Double:\n\t\t\t\treturn Typesafe.number\n\t\t\tcase Model.ColumnType.Bool:\n\t\t\t\treturn Typesafe.boolean\n\t\t\tcase Model.ColumnType.Enum:\n\t\t\t\treturn Typesafe.string // TODO\n\t\t\tcase Model.ColumnType.DateTime:\n\t\t\t\treturn Typesafe.string // TODO\n\t\t\tcase Model.ColumnType.Time:\n\t\t\t\treturn Typesafe.string // TODO\n\t\t\tcase Model.ColumnType.Date:\n\t\t\t\treturn Typesafe.string // TODO\n\t\t\tcase Model.ColumnType.Json:\n\t\t\t\treturn Typesafe.string\n\t\t}\n\t}\n}\n"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AA,OAAM;AACpD,YAAM,OAAO,KAAK,uBAAuB,GAAG,IAAI;AAChD,aAAO,GAAG,WAAWA,oBAAS,SAAS,IAAI,IAAI;AAAA,IAChD,CAAC,CAAC;AAEF,QAAI,aAAa,oBAAoB,QAAW;AAC/C,aAAO;AAAA,IACR;AAEA,WAAO,MAAM,aAAa,gBAAgB,IAAI,QAAQ,IAAI,CAAA,OAAM,GAAG,IAAI,GAAG,QAAQ;AAAA,EACnF;AAAA,EAEQ,uBAAuB,YAAkE;AAChG,YAAQ,YAAA;AAAA,MACP,KAAKC,OAAAA,MAAM,WAAW;AACrB,eAAOD,oBAAS;AAAA;AAAA,MACjB,KAAKC,OAAAA,MAAM,WAAW;AACrB,eAAOD,oBAAS;AAAA,MACjB,KAAKC,OAAAA,MAAM,WAAW;AACrB,eAAOD,oBAAS;AAAA;AAAA,MACjB,KAAKC,OAAAA,MAAM,WAAW;AACrB,eAAOD,oBAAS;AAAA,MACjB,KAAKC,OAAAA,MAAM,WAAW;AACrB,eAAOD,oBAAS;AAAA,MACjB,KAAKC,OAAAA,MAAM,WAAW;AACrB,eAAOD,oBAAS;AAAA;AAAA,MACjB,KAAKC,OAAAA,MAAM,WAAW;AACrB,eAAOD,oBAAS;AAAA;AAAA,MACjB,KAAKC,OAAAA,MAAM,WAAW;AACrB,eAAOD,oBAAS;AAAA;AAAA,MACjB,KAAKC,OAAAA,MAAM,WAAW;AACrB,eAAOD,oBAAS;AAAA;AAAA,MACjB,KAAKC,OAAAA,MAAM,WAAW;AACrB,eAAOD,oBAAS;AAAA,IAAA;AAAA,EAEnB;AACD;;;"}
|
|
1
|
+
{"version":3,"file":"ImportExecutor.cjs","sources":["../../../../../packages/engine-http/src/transfer/ImportExecutor.ts"],"sourcesContent":["import { Client, Connection, ConstraintHelper, DatabaseMetadataResolver, wrapIdentifier } from '@contember/database'\nimport { Model, Schema } from '@contember/schema'\nimport * as Typesafe from '@contember/typesafe'\nimport { ParseError } from '@contember/typesafe'\nimport { Command, CommandArgsMap, CommandName } from './Command.js'\nimport { DatabaseContext, StageBySlugQuery } from '@contember/engine-system-api'\nimport { DbColumnSchema, TransferMapping, TransferTableMapping } from './TransferMapping.js'\nimport { ContentSchemaTransferMappingFactory } from './ContentSchemaTransferMappingFactory.js'\nimport { SystemSchemaTransferMappingFactory } from './SystemSchemaTransferMappingFactory.js'\nimport { AuthResult, HttpErrorResponse } from '../common/index.js'\nimport { ProjectGroupContainer } from '../projectGroup/ProjectGroupContainer.js'\n\ntype Cell = boolean | number | string | readonly string[] | readonly number[] | readonly boolean[] | null\ntype Row = readonly Cell[]\n\ntype InsertContext = {\n\ttableName: string\n\tinsertStartFragment: string\n\trowFragment: string\n\trowParser: Typesafe.Type<Row>\n\trows: Array<Row>\n\tinsertedRowCount: number\n}\n\nexport class ImportError extends Error {\n}\n\nconst parsePgTextArray = (value: string): string[] => {\n\tif (value === '{}') return []\n\tif (!value.startsWith('{') || !value.endsWith('}')) {\n\t\tthrow new ParseError([], `invalid PostgreSQL array literal: ${value}`)\n\t}\n\tconst inner = value.slice(1, -1)\n\tconst result: string[] = []\n\tlet current = ''\n\tlet inQuotes = false\n\tlet escaped = false\n\tfor (const ch of inner) {\n\t\tif (escaped) {\n\t\t\tcurrent += ch\n\t\t\tescaped = false\n\t\t} else if (ch === '\\\\') {\n\t\t\tescaped = true\n\t\t} else if (ch === '\"') {\n\t\t\tinQuotes = !inQuotes\n\t\t} else if (ch === ',' && !inQuotes) {\n\t\t\tresult.push(current)\n\t\t\tcurrent = ''\n\t\t} else {\n\t\t\tcurrent += ch\n\t\t}\n\t}\n\tresult.push(current)\n\treturn result\n}\n\nconst listType = <T extends Typesafe.Json>(arrayType: Typesafe.Type<T>): Typesafe.Type<T> => {\n\treturn (input: unknown, path: PropertyKey[] = []) => {\n\t\tif (Array.isArray(input)) {\n\t\t\treturn arrayType(input, path)\n\t\t}\n\t\tif (typeof input === 'string' && input.startsWith('{')) {\n\t\t\treturn arrayType(parsePgTextArray(input), path)\n\t\t}\n\t\treturn arrayType(input, path)\n\t}\n}\n\ntype CommandProcessor<T extends CommandName> = (it: CommandIterator<T>) => Promise<CommandIterator | null>\ntype CommandProcessorMap<T extends CommandName> = { [N in CommandName]?: N extends T ? CommandProcessor<N> : undefined }\n\nclass CommandIterator<T extends CommandName = CommandName> {\n\tprivate constructor(\n\t\tpublic readonly commandName: T,\n\t\tpublic readonly commandArgs: CommandArgsMap[T],\n\t\tprivate readonly commandIterator: AsyncIterator<Command>,\n\t) {\n\t}\n\n\tpublic static async create(commands: AsyncIterable<Command>): Promise<CommandIterator | null> {\n\t\tconst commandIterator = commands[Symbol.asyncIterator]()\n\t\tconst result = await commandIterator.next()\n\n\t\tif (result.done) {\n\t\t\treturn null\n\t\t}\n\n\t\tconst [name, ...args] = result.value\n\t\treturn new CommandIterator(name, args, commandIterator)\n\t}\n\n\tasync next(): Promise<CommandIterator | null> {\n\t\tconst result = await this.commandIterator.next()\n\n\t\tif (result.done) {\n\t\t\treturn null\n\t\t}\n\n\t\tconst [name, ...args] = result.value\n\t\treturn new CommandIterator(name, args, this.commandIterator)\n\t}\n}\n\nexport class ImportExecutor {\n\tconstructor(\n\t\tprivate readonly contentSchemaTransferMappingFactory: ContentSchemaTransferMappingFactory,\n\t\tprivate readonly systemSchemaTransferMappingFactory: SystemSchemaTransferMappingFactory,\n\t\tprivate readonly databaseMetadataResolver: DatabaseMetadataResolver,\n\t) {\n\t}\n\n\tasync import(groupContainer: ProjectGroupContainer, authResult: AuthResult, commands: AsyncIterable<Command>) {\n\t\tconst it = await CommandIterator.create(commands)\n\n\t\tconst final = await this.match(it, {\n\t\t\timportContentSchemaBegin: it => this.importContentSchemaBegin(groupContainer, authResult, it),\n\t\t\timportSystemSchemaBegin: it => this.importSystemSchemaBegin(groupContainer, authResult, it),\n\t\t})\n\n\t\tif (final !== null) {\n\t\t\tthrow new ImportError(`Unexpected ${final.commandName}`)\n\t\t}\n\t}\n\n\tprivate async match<T extends CommandName>(it: CommandIterator<T> | null, processors: CommandProcessorMap<T>) {\n\t\tlet next: CommandIterator | null = it\n\n\t\twhile (next !== null) {\n\t\t\tconst processor = processors[next.commandName]\n\n\t\t\tif (processor) {\n\t\t\t\tnext = await processor(next as any)\n\t\t\t} else {\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\treturn next\n\t}\n\n\tprivate async importContentSchemaBegin(\n\t\tgroupContainer: ProjectGroupContainer,\n\t\tauthResult: AuthResult,\n\t\tit: CommandIterator<'importContentSchemaBegin'>,\n\t) {\n\t\tconst [options] = it.commandArgs\n\t\tconst projectContainer = await this.createProjectContainer(groupContainer, options.project)\n\t\tconst systemDatabaseContext = projectContainer.systemDatabaseContext\n\t\tconst stage = await this.fetchStageBySlug(systemDatabaseContext, options.project, options.stage)\n\n\t\tconst contentSchema = await projectContainer.contentSchemaResolver.getSchema({ db: systemDatabaseContext, stage: stage.slug, normalize: true })\n\n\t\tif (contentSchema.meta.version !== options.schemaVersion) {\n\t\t\tthrow new ImportError(\n\t\t\t\t`Incompatible schema version (import version ${options.schemaVersion} does not match server version ${contentSchema.meta.version})`,\n\t\t\t)\n\t\t}\n\n\t\tawait this.requireImportAccess(groupContainer, contentSchema.schema, authResult, options.project, 'content')\n\t\tconst contentDatabaseClient = projectContainer.connection.createClient(stage.schema, {})\n\t\tconst mapping = this.contentSchemaTransferMappingFactory.createContentSchemaMapping(contentSchema.schema)\n\n\t\treturn await contentDatabaseClient.transaction(async db => {\n\t\t\tawait this.disableTimeouts(db)\n\t\t\tawait this.disableTriggers(db, options.tables)\n\t\t\tawait this.lockTables(db, options.tables)\n\t\t\tawait this.truncateTables(db, options.tables)\n\n\t\t\tconst metadata = await this.databaseMetadataResolver.resolveMetadata(db, db.schema)\n\t\t\tconst constraintHelper = new ConstraintHelper(db, metadata)\n\t\t\tawait constraintHelper.setConstraintsDeferred('foreignKey')\n\n\t\t\tconst result = await this.match(await it.next(), {\n\t\t\t\timportSequence: it => this.importSequence(db, mapping, it),\n\t\t\t\tinsertBegin: it => this.insertBegin(db, mapping, it),\n\t\t\t})\n\n\t\t\tawait constraintHelper.setConstraintsImmediate('foreignKey')\n\t\t\tawait this.enableTriggers(db, options.tables)\n\n\t\t\treturn result\n\t\t})\n\t}\n\n\tprivate async importSystemSchemaBegin(\n\t\tgroupContainer: ProjectGroupContainer,\n\t\tauthResult: AuthResult,\n\t\tit: CommandIterator<'importSystemSchemaBegin'>,\n\t) {\n\t\tconst [options] = it.commandArgs\n\t\tconst projectContainer = await this.createProjectContainer(groupContainer, options.project)\n\t\tconst schema = await groupContainer.projectSchemaResolver.getSchema(options.project)\n\n\t\tif (schema === undefined) {\n\t\t\tthrow new ImportError(`Project ${options.project} does not have schema`)\n\t\t}\n\n\t\tawait this.requireImportAccess(groupContainer, schema, authResult, options.project, 'system')\n\t\tconst systemDatabaseContext = projectContainer.systemDatabaseContext\n\t\tconst mapping = this.systemSchemaTransferMappingFactory.build()\n\n\t\treturn await systemDatabaseContext.client.transaction(async db => {\n\t\t\tawait this.disableTimeouts(db)\n\t\t\tawait this.truncateTables(db, options.tables)\n\n\t\t\tconst metadata = await this.databaseMetadataResolver.resolveMetadata(db, db.schema)\n\t\t\tconst constraintHelper = new ConstraintHelper(db, metadata)\n\t\t\tawait constraintHelper.setConstraintsDeferred('foreignKey')\n\n\t\t\treturn await this.match(await it.next(), {\n\t\t\t\tinsertBegin: it => this.insertBegin(db, mapping, it),\n\t\t\t})\n\t\t})\n\t}\n\n\tprivate async importSequence(\n\t\tdb: Client<Connection.TransactionLike>,\n\t\tmapping: TransferMapping,\n\t\tit: CommandIterator<'importSequence'>,\n\t): Promise<CommandIterator | null> {\n\t\tconst [options] = it.commandArgs\n\n\t\tawait db.query(\n\t\t\t'SELECT setval(pg_get_serial_sequence(?, ?), ?)',\n\t\t\t[`${db.schema}.${options.table}`, options.column, options.value],\n\t\t)\n\n\t\treturn it.next()\n\t}\n\n\tprivate async insertBegin(\n\t\tdb: Client<Connection.TransactionLike>,\n\t\tmapping: TransferMapping,\n\t\tit: CommandIterator<'insertBegin'>,\n\t): Promise<CommandIterator | null> {\n\t\tconst [options] = it.commandArgs\n\t\tconst insertContext = await this.buildInsertContext(db, mapping, db.schema, options.table, options.columns)\n\t\tlet insertRowsPromise: Promise<Connection.Result> | null = null\n\n\t\t// postgresql has a limit of 65535 parameters per query\n\t\tconst batchSize = Math.max(1, Math.min(1000, Math.floor(65500 / options.columns.length)))\n\n\t\tconst result = await this.match(await it.next(), {\n\t\t\tinsertRow: async it => {\n\t\t\t\tconst [values] = it.commandArgs\n\n\t\t\t\ttry {\n\t\t\t\t\tinsertContext.rows.push(insertContext.rowParser(values))\n\t\t\t\t} catch (e) {\n\t\t\t\t\tif (e instanceof ParseError) {\n\t\t\t\t\t\tthrow new ImportError(`Invalid row ${JSON.stringify(values)} for table ${options.table}: ${e.message}`)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow e\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (insertContext.rows.length === batchSize) {\n\t\t\t\t\tawait insertRowsPromise\n\t\t\t\t\tinsertRowsPromise = this.insertRows(db, insertContext)\n\t\t\t\t\tinsertContext.insertedRowCount += insertContext.rows.length\n\t\t\t\t\tinsertContext.rows = []\n\t\t\t\t}\n\n\t\t\t\treturn await it.next()\n\t\t\t},\n\t\t})\n\n\t\tif (insertContext.rows.length > 0) {\n\t\t\tawait insertRowsPromise\n\t\t\tawait this.insertRows(db, insertContext)\n\t\t\tinsertContext.insertedRowCount += insertContext.rows.length\n\t\t\tinsertContext.rows = []\n\t\t}\n\n\t\tif (result === null || result.commandName !== 'insertEnd') {\n\t\t\tthrow new ImportError(`Missing insertEnd command`)\n\t\t}\n\n\t\treturn await result.next()\n\t}\n\n\tprivate async createProjectContainer(groupContainer: ProjectGroupContainer, projectSlug: string) {\n\t\tconst projectContainerResolver = groupContainer.projectContainerResolver\n\t\tconst projectContainer = await projectContainerResolver.getProjectContainer(projectSlug, { alias: true })\n\n\t\tif (projectContainer === undefined) {\n\t\t\tthrow new ImportError(`Project ${projectSlug} does not exists.`)\n\t\t}\n\n\t\treturn projectContainer\n\t}\n\n\tprivate async requireImportAccess(\n\t\tgroupContainer: ProjectGroupContainer,\n\t\tschema: Schema,\n\t\tauthResult: AuthResult,\n\t\tprojectSlug: string,\n\t\tkind: 'content' | 'system',\n\t) {\n\t\tconst { effective: memberships } = await groupContainer.projectMembershipResolver.resolveMemberships({\n\t\t\trequest: { get: () => '' },\n\t\t\tacl: schema.acl,\n\t\t\tprojectSlug: projectSlug,\n\t\t\tidentity: {\n\t\t\t\tidentityId: authResult.identityId,\n\t\t\t\troles: authResult.roles,\n\t\t\t},\n\t\t})\n\n\t\tconst projectRoles = memberships.map(it => it.role)\n\n\t\tif (!projectRoles.some(role => schema.acl.roles[role]?.[kind]?.import)) {\n\t\t\tthrow new HttpErrorResponse(403, `You are not allowed to import ${kind} in ${projectSlug}`)\n\t\t}\n\t}\n\n\tprivate async fetchStageBySlug(systemDatabaseContext: DatabaseContext, projectSlug: string, stageSlug: string) {\n\t\tconst stage = await systemDatabaseContext.queryHandler.fetch(new StageBySlugQuery(stageSlug))\n\n\t\tif (stage === null) {\n\t\t\tthrow new ImportError(`Project ${projectSlug} does not have stage ${stageSlug}.`)\n\t\t}\n\n\t\treturn stage\n\t}\n\n\tprivate async disableTriggers(db: Client, tableNames: readonly string[]) {\n\t\tfor (const tableName of tableNames) {\n\t\t\tconst tableNameQuoted = `${wrapIdentifier(db.schema)}.${wrapIdentifier(tableName)}`\n\t\t\tawait db.query(`ALTER TABLE ${tableNameQuoted} DISABLE TRIGGER USER`)\n\t\t}\n\t}\n\n\tprivate async enableTriggers(db: Client, tableNames: readonly string[]) {\n\t\tfor (const tableName of tableNames) {\n\t\t\tconst tableNameQuoted = `${wrapIdentifier(db.schema)}.${wrapIdentifier(tableName)}`\n\t\t\tawait db.query(`ALTER TABLE ${tableNameQuoted} ENABLE TRIGGER USER`)\n\t\t}\n\t}\n\n\tprivate async lockTables(db: Client, tableNames: readonly string[]) {\n\t\tconst tableNamesQuoted = tableNames.map(it => `${wrapIdentifier(db.schema)}.${wrapIdentifier(it)}`)\n\t\tawait db.query(`LOCK ${tableNamesQuoted.join(', ')} IN EXCLUSIVE MODE`)\n\t}\n\n\tprivate async truncateTables(db: Client, tableNames: readonly string[]) {\n\t\tconst tableNamesQuoted = tableNames.map(it => `${wrapIdentifier(db.schema)}.${wrapIdentifier(it)}`)\n\t\tawait db.query(`TRUNCATE ${tableNamesQuoted.join(', ')}`)\n\t}\n\n\tprivate async disableTimeouts(db: Client) {\n\t\tawait db.query('SET LOCAL statement_timeout = 0')\n\t\tawait db.query('SET LOCAL lock_timeout = 0')\n\t}\n\n\tprivate async insertRows(db: Client, context: InsertContext) {\n\t\tconst rowsFragment = context.rows.map(_ => context.rowFragment).join(',\\n')\n\t\tconst sql = context.insertStartFragment + rowsFragment\n\t\tconst parameters: Cell[] = []\n\n\t\tfor (const row of context.rows) {\n\t\t\tfor (const cell of row) {\n\t\t\t\tparameters.push(cell)\n\t\t\t}\n\t\t}\n\n\t\treturn await db.query(sql, parameters)\n\t}\n\n\tprivate async buildInsertContext(\n\t\tdb: Client,\n\t\tmapping: TransferMapping,\n\t\tschema: string,\n\t\ttableName: string,\n\t\tcolumnNames: readonly string[],\n\t): Promise<InsertContext> {\n\t\tconst tableMapping = mapping.tables[tableName]\n\t\tconst columns = []\n\n\t\tif (tableMapping === undefined) {\n\t\t\tthrow new ImportError(`Unknown table ${tableName}`)\n\t\t}\n\n\t\tfor (const columnName of columnNames) {\n\t\t\tconst column = tableMapping.columns[columnName]\n\n\t\t\tif (column === undefined) {\n\t\t\t\tthrow new ImportError(`Unknown column ${tableName}.${columnName}`)\n\t\t\t}\n\n\t\t\tcolumns.push(column)\n\t\t}\n\n\t\tconst insertStartFragment = (tableMapping.createInsertStartFragment ?? this.createInsertStartFragment)(schema, tableName, columnNames)\n\t\tconst rowFragment = '(' + columns.map(_ => '?').join(', ') + ')'\n\t\tconst rowParser = await this.buildRowParser(db, tableMapping, columns)\n\n\t\treturn {\n\t\t\ttableName,\n\t\t\tinsertStartFragment,\n\t\t\trowFragment,\n\t\t\trowParser,\n\t\t\trows: [],\n\t\t\tinsertedRowCount: 0,\n\t\t}\n\t}\n\n\tprivate createInsertStartFragment(schema: string, tableName: string, columnNames: readonly string[]): string {\n\t\tconst tableQuoted = `${wrapIdentifier(schema)}.${wrapIdentifier(tableName)}`\n\t\tconst columnsQuoted = '(' + columnNames.map(it => wrapIdentifier(it)).join(', ') + ')'\n\t\treturn `INSERT INTO ${tableQuoted} ${columnsQuoted} VALUES\\n`\n\t}\n\n\tprivate async buildRowParser(db: Client, tableMapping: TransferTableMapping, columns: DbColumnSchema[]): Promise<Typesafe.Type<readonly Cell[]>> {\n\t\tconst baseType = Typesafe.tuple(...columns.map(it => {\n\t\t\tconst base = this.buildColumnRuntimeType(it)\n\t\t\treturn it.nullable ? Typesafe.nullable(base) : base\n\t\t}))\n\n\t\tif (tableMapping.createRowParser === undefined) {\n\t\t\treturn baseType\n\t\t}\n\n\t\treturn await tableMapping.createRowParser(db, columns.map(it => it.name), baseType)\n\t}\n\n\tprivate buildColumnRuntimeType(column: DbColumnSchema): Typesafe.Type<Exclude<Cell, null>> {\n\t\tswitch (column.type) {\n\t\t\tcase Model.ColumnType.Uuid:\n\t\t\tcase Model.ColumnType.String:\n\t\t\tcase Model.ColumnType.Enum:\n\t\t\tcase Model.ColumnType.DateTime:\n\t\t\tcase Model.ColumnType.Time:\n\t\t\tcase Model.ColumnType.Date:\n\t\t\tcase Model.ColumnType.Json:\n\t\t\t// Numeric is transferred as a string to avoid JS float precision loss.\n\t\t\tcase Model.ColumnType.Numeric:\n\t\t\t\treturn column.list ? listType(Typesafe.array(Typesafe.string)) : Typesafe.string\n\t\t\tcase Model.ColumnType.Int:\n\t\t\tcase Model.ColumnType.Double:\n\t\t\t\treturn column.list ? listType(Typesafe.array(Typesafe.number)) : Typesafe.number\n\t\t\tcase Model.ColumnType.Bool:\n\t\t\t\treturn column.list ? listType(Typesafe.array(Typesafe.boolean)) : Typesafe.boolean\n\t\t}\n\t}\n}\n"],"names":["ParseError","it","ConstraintHelper","schema","HttpErrorResponse","StageBySlugQuery","wrapIdentifier","Typesafe","Model"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAwBO,MAAM,oBAAoB,MAAM;AACvC;AAEA,MAAM,mBAAmB,CAAC,UAA4B;AACrD,MAAI,UAAU,KAAM,QAAO,CAAA;AAC3B,MAAI,CAAC,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,SAAS,GAAG,GAAG;AACnD,UAAM,IAAIA,SAAAA,WAAW,CAAA,GAAI,qCAAqC,KAAK,EAAE;AAAA,EACtE;AACA,QAAM,QAAQ,MAAM,MAAM,GAAG,EAAE;AAC/B,QAAM,SAAmB,CAAA;AACzB,MAAI,UAAU;AACd,MAAI,WAAW;AACf,MAAI,UAAU;AACd,aAAW,MAAM,OAAO;AACvB,QAAI,SAAS;AACZ,iBAAW;AACX,gBAAU;AAAA,IACX,WAAW,OAAO,MAAM;AACvB,gBAAU;AAAA,IACX,WAAW,OAAO,KAAK;AACtB,iBAAW,CAAC;AAAA,IACb,WAAW,OAAO,OAAO,CAAC,UAAU;AACnC,aAAO,KAAK,OAAO;AACnB,gBAAU;AAAA,IACX,OAAO;AACN,iBAAW;AAAA,IACZ;AAAA,EACD;AACA,SAAO,KAAK,OAAO;AACnB,SAAO;AACR;AAEA,MAAM,WAAW,CAA0B,cAAkD;AAC5F,SAAO,CAAC,OAAgB,OAAsB,OAAO;AACpD,QAAI,MAAM,QAAQ,KAAK,GAAG;AACzB,aAAO,UAAU,OAAO,IAAI;AAAA,IAC7B;AACA,QAAI,OAAO,UAAU,YAAY,MAAM,WAAW,GAAG,GAAG;AACvD,aAAO,UAAU,iBAAiB,KAAK,GAAG,IAAI;AAAA,IAC/C;AACA,WAAO,UAAU,OAAO,IAAI;AAAA,EAC7B;AACD;AAKA,MAAM,gBAAqD;AAAA,EA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Aa,oBAAoB,QAAW;AAC/C,aAAO;AAAA,IACR;AAEA,WAAO,MAAM,aAAa,gBAAgB,IAAI,QAAQ,IAAI,CAAA,OAAM,GAAG,IAAI,GAAG,QAAQ;AAAA,EACnF;AAAA,EAEQ,uBAAuB,QAA4D;AAC1F,YAAQ,OAAO,MAAA;AAAA,MACd,KAAKC,OAAAA,MAAM,WAAW;AAAA,MACtB,KAAKA,OAAAA,MAAM,WAAW;AAAA,MACtB,KAAKA,OAAAA,MAAM,WAAW;AAAA,MACtB,KAAKA,OAAAA,MAAM,WAAW;AAAA,MACtB,KAAKA,OAAAA,MAAM,WAAW;AAAA,MACtB,KAAKA,OAAAA,MAAM,WAAW;AAAA,MACtB,KAAKA,OAAAA,MAAM,WAAW;AAAA;AAAA,MAEtB,KAAKA,OAAAA,MAAM,WAAW;AACrB,eAAO,OAAO,OAAO,SAASD,oBAAS,MAAMA,oBAAS,MAAM,CAAC,IAAIA,oBAAS;AAAA,MAC3E,KAAKC,OAAAA,MAAM,WAAW;AAAA,MACtB,KAAKA,OAAAA,MAAM,WAAW;AACrB,eAAO,OAAO,OAAO,SAASD,oBAAS,MAAMA,oBAAS,MAAM,CAAC,IAAIA,oBAAS;AAAA,MAC3E,KAAKC,OAAAA,MAAM,WAAW;AACrB,eAAO,OAAO,OAAO,SAASD,oBAAS,MAAMA,oBAAS,OAAO,CAAC,IAAIA,oBAAS;AAAA,IAAA;AAAA,EAE9E;AACD;;;"}
|
|
@@ -4,8 +4,48 @@ import * as Typesafe from "@contember/typesafe";
|
|
|
4
4
|
import { ParseError } from "@contember/typesafe";
|
|
5
5
|
import { StageBySlugQuery } from "@contember/engine-system-api";
|
|
6
6
|
import { HttpErrorResponse } from "../common/HttpResponse.js";
|
|
7
|
+
import "ipaddr.js";
|
|
7
8
|
class ImportError extends Error {
|
|
8
9
|
}
|
|
10
|
+
const parsePgTextArray = (value) => {
|
|
11
|
+
if (value === "{}") return [];
|
|
12
|
+
if (!value.startsWith("{") || !value.endsWith("}")) {
|
|
13
|
+
throw new ParseError([], `invalid PostgreSQL array literal: ${value}`);
|
|
14
|
+
}
|
|
15
|
+
const inner = value.slice(1, -1);
|
|
16
|
+
const result = [];
|
|
17
|
+
let current = "";
|
|
18
|
+
let inQuotes = false;
|
|
19
|
+
let escaped = false;
|
|
20
|
+
for (const ch of inner) {
|
|
21
|
+
if (escaped) {
|
|
22
|
+
current += ch;
|
|
23
|
+
escaped = false;
|
|
24
|
+
} else if (ch === "\\") {
|
|
25
|
+
escaped = true;
|
|
26
|
+
} else if (ch === '"') {
|
|
27
|
+
inQuotes = !inQuotes;
|
|
28
|
+
} else if (ch === "," && !inQuotes) {
|
|
29
|
+
result.push(current);
|
|
30
|
+
current = "";
|
|
31
|
+
} else {
|
|
32
|
+
current += ch;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
result.push(current);
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
const listType = (arrayType) => {
|
|
39
|
+
return (input, path = []) => {
|
|
40
|
+
if (Array.isArray(input)) {
|
|
41
|
+
return arrayType(input, path);
|
|
42
|
+
}
|
|
43
|
+
if (typeof input === "string" && input.startsWith("{")) {
|
|
44
|
+
return arrayType(parsePgTextArray(input), path);
|
|
45
|
+
}
|
|
46
|
+
return arrayType(input, path);
|
|
47
|
+
};
|
|
48
|
+
};
|
|
9
49
|
class CommandIterator {
|
|
10
50
|
constructor(commandName, commandArgs, commandIterator) {
|
|
11
51
|
this.commandName = commandName;
|
|
@@ -73,7 +113,7 @@ class ImportExecutor {
|
|
|
73
113
|
const contentDatabaseClient = projectContainer.connection.createClient(stage.schema, {});
|
|
74
114
|
const mapping = this.contentSchemaTransferMappingFactory.createContentSchemaMapping(contentSchema.schema);
|
|
75
115
|
return await contentDatabaseClient.transaction(async (db) => {
|
|
76
|
-
await this.
|
|
116
|
+
await this.disableTimeouts(db);
|
|
77
117
|
await this.disableTriggers(db, options.tables);
|
|
78
118
|
await this.lockTables(db, options.tables);
|
|
79
119
|
await this.truncateTables(db, options.tables);
|
|
@@ -100,7 +140,7 @@ class ImportExecutor {
|
|
|
100
140
|
const systemDatabaseContext = projectContainer.systemDatabaseContext;
|
|
101
141
|
const mapping = this.systemSchemaTransferMappingFactory.build();
|
|
102
142
|
return await systemDatabaseContext.client.transaction(async (db) => {
|
|
103
|
-
await this.
|
|
143
|
+
await this.disableTimeouts(db);
|
|
104
144
|
await this.truncateTables(db, options.tables);
|
|
105
145
|
const metadata = await this.databaseMetadataResolver.resolveMetadata(db, db.schema);
|
|
106
146
|
const constraintHelper = new ConstraintHelper(db, metadata);
|
|
@@ -205,8 +245,9 @@ class ImportExecutor {
|
|
|
205
245
|
const tableNamesQuoted = tableNames.map((it) => `${wrapIdentifier(db.schema)}.${wrapIdentifier(it)}`);
|
|
206
246
|
await db.query(`TRUNCATE ${tableNamesQuoted.join(", ")}`);
|
|
207
247
|
}
|
|
208
|
-
async
|
|
248
|
+
async disableTimeouts(db) {
|
|
209
249
|
await db.query("SET LOCAL statement_timeout = 0");
|
|
250
|
+
await db.query("SET LOCAL lock_timeout = 0");
|
|
210
251
|
}
|
|
211
252
|
async insertRows(db, context) {
|
|
212
253
|
const rowsFragment = context.rows.map((_) => context.rowFragment).join(",\n");
|
|
@@ -252,7 +293,7 @@ class ImportExecutor {
|
|
|
252
293
|
}
|
|
253
294
|
async buildRowParser(db, tableMapping, columns) {
|
|
254
295
|
const baseType = Typesafe.tuple(...columns.map((it) => {
|
|
255
|
-
const base = this.buildColumnRuntimeType(it
|
|
296
|
+
const base = this.buildColumnRuntimeType(it);
|
|
256
297
|
return it.nullable ? Typesafe.nullable(base) : base;
|
|
257
298
|
}));
|
|
258
299
|
if (tableMapping.createRowParser === void 0) {
|
|
@@ -260,34 +301,23 @@ class ImportExecutor {
|
|
|
260
301
|
}
|
|
261
302
|
return await tableMapping.createRowParser(db, columns.map((it) => it.name), baseType);
|
|
262
303
|
}
|
|
263
|
-
buildColumnRuntimeType(
|
|
264
|
-
switch (
|
|
304
|
+
buildColumnRuntimeType(column) {
|
|
305
|
+
switch (column.type) {
|
|
265
306
|
case Model.ColumnType.Uuid:
|
|
266
|
-
return Typesafe.string;
|
|
267
|
-
// TODO
|
|
268
307
|
case Model.ColumnType.String:
|
|
269
|
-
return Typesafe.string;
|
|
270
|
-
case Model.ColumnType.Int:
|
|
271
|
-
return Typesafe.number;
|
|
272
|
-
// TODO
|
|
273
|
-
case Model.ColumnType.Double:
|
|
274
|
-
return Typesafe.number;
|
|
275
|
-
case Model.ColumnType.Bool:
|
|
276
|
-
return Typesafe.boolean;
|
|
277
308
|
case Model.ColumnType.Enum:
|
|
278
|
-
return Typesafe.string;
|
|
279
|
-
// TODO
|
|
280
309
|
case Model.ColumnType.DateTime:
|
|
281
|
-
return Typesafe.string;
|
|
282
|
-
// TODO
|
|
283
310
|
case Model.ColumnType.Time:
|
|
284
|
-
return Typesafe.string;
|
|
285
|
-
// TODO
|
|
286
311
|
case Model.ColumnType.Date:
|
|
287
|
-
return Typesafe.string;
|
|
288
|
-
// TODO
|
|
289
312
|
case Model.ColumnType.Json:
|
|
290
|
-
|
|
313
|
+
// Numeric is transferred as a string to avoid JS float precision loss.
|
|
314
|
+
case Model.ColumnType.Numeric:
|
|
315
|
+
return column.list ? listType(Typesafe.array(Typesafe.string)) : Typesafe.string;
|
|
316
|
+
case Model.ColumnType.Int:
|
|
317
|
+
case Model.ColumnType.Double:
|
|
318
|
+
return column.list ? listType(Typesafe.array(Typesafe.number)) : Typesafe.number;
|
|
319
|
+
case Model.ColumnType.Bool:
|
|
320
|
+
return column.list ? listType(Typesafe.array(Typesafe.boolean)) : Typesafe.boolean;
|
|
291
321
|
}
|
|
292
322
|
}
|
|
293
323
|
}
|