@contember/engine-http 2.2.0-alpha.17 → 2.2.0-alpha.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/development/index.cjs +3 -1
- package/dist/development/index.cjs.map +1 -1
- package/dist/development/index.js +4 -2
- package/dist/development/index.js.map +1 -1
- package/dist/development/src/MasterContainer.cjs +5 -4
- package/dist/development/src/MasterContainer.cjs.map +1 -1
- package/dist/development/src/MasterContainer.js +5 -4
- package/dist/development/src/MasterContainer.js.map +1 -1
- package/dist/development/src/application/PanelApiMount.cjs.map +1 -1
- package/dist/development/src/application/PanelApiMount.js.map +1 -1
- package/dist/development/src/application/application.cjs +27 -21
- package/dist/development/src/application/application.cjs.map +1 -1
- package/dist/development/src/application/application.js +27 -21
- package/dist/development/src/application/application.js.map +1 -1
- package/dist/development/src/application/compression.cjs +99 -0
- package/dist/development/src/application/compression.cjs.map +1 -0
- package/dist/development/src/application/compression.js +82 -0
- package/dist/development/src/application/compression.js.map +1 -0
- package/dist/development/src/application/cors.cjs +52 -0
- package/dist/development/src/application/cors.cjs.map +1 -0
- package/dist/development/src/application/cors.js +52 -0
- package/dist/development/src/application/cors.js.map +1 -0
- package/dist/development/src/application/requestBody.cjs +242 -0
- package/dist/development/src/application/requestBody.cjs.map +1 -0
- package/dist/development/src/application/requestBody.js +242 -0
- package/dist/development/src/application/requestBody.js.map +1 -0
- package/dist/development/src/application/requestBodyMasking.cjs +97 -0
- package/dist/development/src/application/requestBodyMasking.cjs.map +1 -0
- package/dist/development/src/application/requestBodyMasking.js +97 -0
- package/dist/development/src/application/requestBodyMasking.js.map +1 -0
- package/dist/development/src/config/configSchema.cjs +36 -1
- package/dist/development/src/config/configSchema.cjs.map +1 -1
- package/dist/development/src/config/configSchema.js +36 -1
- package/dist/development/src/config/configSchema.js.map +1 -1
- package/dist/development/src/config/configTemplate.cjs +5 -0
- package/dist/development/src/config/configTemplate.cjs.map +1 -1
- package/dist/development/src/config/configTemplate.js +5 -0
- package/dist/development/src/config/configTemplate.js.map +1 -1
- package/dist/development/src/content/ProjectMembershipResolver.cjs +10 -3
- package/dist/development/src/content/ProjectMembershipResolver.cjs.map +1 -1
- package/dist/development/src/content/ProjectMembershipResolver.js +10 -3
- package/dist/development/src/content/ProjectMembershipResolver.js.map +1 -1
- package/dist/development/src/graphql/execution.cjs +3 -9
- package/dist/development/src/graphql/execution.cjs.map +1 -1
- package/dist/development/src/graphql/execution.js +3 -9
- package/dist/development/src/graphql/execution.js.map +1 -1
- package/dist/development/src/project/ProjectContainer.cjs +1 -1
- package/dist/development/src/project/ProjectContainer.js +1 -1
- package/dist/development/src/projectGroup/ProjectGroupContainer.cjs +3 -2
- package/dist/development/src/projectGroup/ProjectGroupContainer.cjs.map +1 -1
- package/dist/development/src/projectGroup/ProjectGroupContainer.js +3 -2
- package/dist/development/src/projectGroup/ProjectGroupContainer.js.map +1 -1
- package/dist/development/src/providers.cjs +2 -2
- package/dist/development/src/providers.cjs.map +1 -1
- package/dist/development/src/providers.js +2 -2
- package/dist/development/src/providers.js.map +1 -1
- package/dist/development/src/transfer/ImportApiMiddlewareFactory.cjs +2 -2
- package/dist/development/src/transfer/ImportApiMiddlewareFactory.cjs.map +1 -1
- package/dist/development/src/transfer/ImportExecutor.cjs +33 -5
- package/dist/development/src/transfer/ImportExecutor.cjs.map +1 -1
- package/dist/development/src/transfer/ImportExecutor.js +33 -5
- package/dist/development/src/transfer/ImportExecutor.js.map +1 -1
- package/dist/development/src/utils/CryptoWrapper.cjs +11 -0
- package/dist/development/src/utils/CryptoWrapper.cjs.map +1 -1
- package/dist/development/src/utils/CryptoWrapper.js +11 -0
- package/dist/development/src/utils/CryptoWrapper.js.map +1 -1
- package/dist/development/src/utils/sentry.cjs +32 -49
- package/dist/development/src/utils/sentry.cjs.map +1 -1
- package/dist/development/src/utils/sentry.js +33 -33
- package/dist/development/src/utils/sentry.js.map +1 -1
- package/dist/development/src/utils/serverStartup.cjs +5 -3
- package/dist/development/src/utils/serverStartup.cjs.map +1 -1
- package/dist/development/src/utils/serverStartup.js +5 -3
- package/dist/development/src/utils/serverStartup.js.map +1 -1
- package/dist/production/index.cjs +3 -1
- package/dist/production/index.cjs.map +1 -1
- package/dist/production/index.js +4 -2
- package/dist/production/index.js.map +1 -1
- package/dist/production/src/MasterContainer.cjs +5 -4
- package/dist/production/src/MasterContainer.cjs.map +1 -1
- package/dist/production/src/MasterContainer.js +5 -4
- package/dist/production/src/MasterContainer.js.map +1 -1
- package/dist/production/src/application/PanelApiMount.cjs.map +1 -1
- package/dist/production/src/application/PanelApiMount.js.map +1 -1
- package/dist/production/src/application/application.cjs +27 -21
- package/dist/production/src/application/application.cjs.map +1 -1
- package/dist/production/src/application/application.js +27 -21
- package/dist/production/src/application/application.js.map +1 -1
- package/dist/production/src/application/compression.cjs +99 -0
- package/dist/production/src/application/compression.cjs.map +1 -0
- package/dist/production/src/application/compression.js +82 -0
- package/dist/production/src/application/compression.js.map +1 -0
- package/dist/production/src/application/cors.cjs +52 -0
- package/dist/production/src/application/cors.cjs.map +1 -0
- package/dist/production/src/application/cors.js +52 -0
- package/dist/production/src/application/cors.js.map +1 -0
- package/dist/production/src/application/requestBody.cjs +242 -0
- package/dist/production/src/application/requestBody.cjs.map +1 -0
- package/dist/production/src/application/requestBody.js +242 -0
- package/dist/production/src/application/requestBody.js.map +1 -0
- package/dist/production/src/application/requestBodyMasking.cjs +97 -0
- package/dist/production/src/application/requestBodyMasking.cjs.map +1 -0
- package/dist/production/src/application/requestBodyMasking.js +97 -0
- package/dist/production/src/application/requestBodyMasking.js.map +1 -0
- package/dist/production/src/config/configSchema.cjs +36 -1
- package/dist/production/src/config/configSchema.cjs.map +1 -1
- package/dist/production/src/config/configSchema.js +36 -1
- package/dist/production/src/config/configSchema.js.map +1 -1
- package/dist/production/src/config/configTemplate.cjs +5 -0
- package/dist/production/src/config/configTemplate.cjs.map +1 -1
- package/dist/production/src/config/configTemplate.js +5 -0
- package/dist/production/src/config/configTemplate.js.map +1 -1
- package/dist/production/src/content/ProjectMembershipResolver.cjs +10 -3
- package/dist/production/src/content/ProjectMembershipResolver.cjs.map +1 -1
- package/dist/production/src/content/ProjectMembershipResolver.js +10 -3
- package/dist/production/src/content/ProjectMembershipResolver.js.map +1 -1
- package/dist/production/src/graphql/execution.cjs +3 -9
- package/dist/production/src/graphql/execution.cjs.map +1 -1
- package/dist/production/src/graphql/execution.js +3 -9
- package/dist/production/src/graphql/execution.js.map +1 -1
- package/dist/production/src/project/ProjectContainer.cjs +1 -1
- package/dist/production/src/project/ProjectContainer.js +1 -1
- package/dist/production/src/projectGroup/ProjectGroupContainer.cjs +3 -2
- package/dist/production/src/projectGroup/ProjectGroupContainer.cjs.map +1 -1
- package/dist/production/src/projectGroup/ProjectGroupContainer.js +3 -2
- package/dist/production/src/projectGroup/ProjectGroupContainer.js.map +1 -1
- package/dist/production/src/providers.cjs +2 -2
- package/dist/production/src/providers.cjs.map +1 -1
- package/dist/production/src/providers.js +2 -2
- package/dist/production/src/providers.js.map +1 -1
- package/dist/production/src/transfer/ImportApiMiddlewareFactory.cjs +2 -2
- package/dist/production/src/transfer/ImportApiMiddlewareFactory.cjs.map +1 -1
- package/dist/production/src/transfer/ImportExecutor.cjs +33 -5
- package/dist/production/src/transfer/ImportExecutor.cjs.map +1 -1
- package/dist/production/src/transfer/ImportExecutor.js +33 -5
- package/dist/production/src/transfer/ImportExecutor.js.map +1 -1
- package/dist/production/src/utils/CryptoWrapper.cjs +11 -0
- package/dist/production/src/utils/CryptoWrapper.cjs.map +1 -1
- package/dist/production/src/utils/CryptoWrapper.js +11 -0
- package/dist/production/src/utils/CryptoWrapper.js.map +1 -1
- package/dist/production/src/utils/sentry.cjs +32 -49
- package/dist/production/src/utils/sentry.cjs.map +1 -1
- package/dist/production/src/utils/sentry.js +33 -33
- package/dist/production/src/utils/sentry.js.map +1 -1
- package/dist/production/src/utils/serverStartup.cjs +5 -3
- package/dist/production/src/utils/serverStartup.cjs.map +1 -1
- package/dist/production/src/utils/serverStartup.js +5 -3
- package/dist/production/src/utils/serverStartup.js.map +1 -1
- package/dist/tests/cases/unit/compression.test.d.ts +2 -0
- package/dist/tests/cases/unit/compression.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/cors.test.d.ts +2 -0
- package/dist/tests/cases/unit/cors.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/requestBody.test.d.ts +2 -0
- package/dist/tests/cases/unit/requestBody.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/requestBodyLogging.test.d.ts +2 -0
- package/dist/tests/cases/unit/requestBodyLogging.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/requestBodyMasking.test.d.ts +2 -0
- package/dist/tests/cases/unit/requestBodyMasking.test.d.ts.map +1 -0
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/dist/types/MasterContainer.d.ts +8 -1
- package/dist/types/MasterContainer.d.ts.map +1 -1
- package/dist/types/application/PanelApiMount.d.ts +2 -0
- package/dist/types/application/PanelApiMount.d.ts.map +1 -1
- package/dist/types/application/application.d.ts +7 -1
- package/dist/types/application/application.d.ts.map +1 -1
- package/dist/types/application/compression.d.ts +19 -0
- package/dist/types/application/compression.d.ts.map +1 -0
- package/dist/types/application/cors.d.ts +10 -0
- package/dist/types/application/cors.d.ts.map +1 -0
- package/dist/types/application/index.d.ts +1 -0
- package/dist/types/application/index.d.ts.map +1 -1
- package/dist/types/application/requestBody.d.ts +45 -0
- package/dist/types/application/requestBody.d.ts.map +1 -0
- package/dist/types/application/requestBodyMasking.d.ts +10 -0
- package/dist/types/application/requestBodyMasking.d.ts.map +1 -0
- package/dist/types/config/configSchema.d.ts +13 -3
- package/dist/types/config/configSchema.d.ts.map +1 -1
- package/dist/types/config/configTemplate.d.ts.map +1 -1
- package/dist/types/content/ProjectMembershipResolver.d.ts.map +1 -1
- package/dist/types/graphql/execution.d.ts.map +1 -1
- package/dist/types/projectGroup/ProjectGroupContainer.d.ts.map +1 -1
- package/dist/types/transfer/ImportExecutor.d.ts +2 -0
- package/dist/types/transfer/ImportExecutor.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/dist/types/utils/CryptoWrapper.d.ts +5 -0
- package/dist/types/utils/CryptoWrapper.d.ts.map +1 -1
- package/dist/types/utils/sentry.d.ts +13 -6
- package/dist/types/utils/sentry.d.ts.map +1 -1
- package/dist/types/utils/serverStartup.d.ts.map +1 -1
- package/package.json +18 -24
- package/src/MasterContainer.ts +5 -3
- package/src/application/PanelApiMount.ts +2 -0
- package/src/application/application.ts +38 -20
- package/src/application/compression.ts +118 -0
- package/src/application/cors.ts +61 -0
- package/src/application/index.ts +1 -0
- package/src/application/requestBody.ts +295 -0
- package/src/application/requestBodyMasking.ts +117 -0
- package/src/config/configSchema.ts +38 -1
- package/src/config/configTemplate.ts +5 -0
- package/src/content/ProjectMembershipResolver.ts +13 -5
- package/src/graphql/execution.ts +3 -9
- package/src/projectGroup/ProjectGroupContainer.ts +1 -0
- package/src/providers.ts +2 -2
- package/src/transfer/ImportExecutor.ts +37 -5
- package/src/tsconfig.json +3 -1
- package/src/utils/CryptoWrapper.ts +12 -0
- package/src/utils/sentry.ts +42 -39
- package/src/utils/serverStartup.ts +7 -5
- package/tests/cases/unit/compression.test.ts +172 -0
- package/tests/cases/unit/cors.test.ts +106 -0
- package/tests/cases/unit/crypto.test.ts +16 -0
- package/tests/cases/unit/projectMembershipResolver.test.ts +50 -0
- package/tests/cases/unit/requestBody.test.ts +333 -0
- package/tests/cases/unit/requestBodyLogging.test.ts +89 -0
- package/tests/cases/unit/requestBodyMasking.test.ts +102 -0
- package/tests/cases/unit/sentryLoggerHandler.test.ts +74 -20
- package/tests/cases/unit/serverConfig.test.ts +42 -0
- package/dist/tests/cases/unit/sentryIntegrations.test.d.ts +0 -2
- package/dist/tests/cases/unit/sentryIntegrations.test.d.ts.map +0 -1
- package/tests/cases/unit/sentryIntegrations.test.ts +0 -15
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProjectGroupContainer.js","sources":["../../../../../packages/engine-http/src/projectGroup/ProjectGroupContainer.ts"],"sourcesContent":["import { Builder } from '@contember/dic'\nimport { Connection } from '@contember/database'\nimport {\n\tProjectInitializer as ProjectInitializerInterface,\n\tProjectSchemaResolver as ProjectSchemaResolverInterface,\n\tTenantContainer,\n\tTenantContainerFactory,\n} from '@contember/engine-tenant-api'\nimport { TenantConfig } from '../config/config.js'\nimport {\n\tProjectContainerFactoryFactory,\n\tProjectContainerResolver,\n\tProjectInitializer,\n\tProjectInitializerProxy,\n\tProjectSchemaResolver,\n\tProjectSchemaResolverProxy,\n} from '../project/index.js'\nimport { SystemContainer, SystemContainerFactory } from '@contember/engine-system-api'\nimport { ProjectConfigResolver } from '../config/projectConfigResolver.js'\nimport { createSecretKey } from 'node:crypto'\nimport { Logger } from '@contember/logger'\nimport { TenantGraphQLHandler, TenantGraphQLHandlerFactory } from '../tenant/index.js'\nimport { SystemGraphQLHandler, SystemGraphQLHandlerFactory } from '../system/index.js'\nimport { Authenticator } from '../common/index.js'\nimport { ProjectMembershipFetcher, ProjectMembershipResolver } from '../content/index.js'\nimport { Providers } from '../providers.js'\nimport { CryptoWrapper } from '../utils/CryptoWrapper.js'\n\n/**\n * Normalizes a token list that may be provided either as an array (JSON config)\n * or as a comma/whitespace-separated string (env-based config) into an array of\n * non-empty tokens.\n */\nconst normalizeTokenList = (value: string | readonly string[] | undefined): readonly string[] | undefined => {\n\tif (value === undefined) {\n\t\treturn undefined\n\t}\n\tconst items = (Array.isArray(value) ? value : (value as string).split(/[\\s,]+/))\n\t\t.map(it => it.trim())\n\t\t.filter(it => it.length > 0)\n\treturn items.length > 0 ? items : undefined\n}\n\nexport interface ProjectGroupContainer {\n\tslug: string | undefined\n\n\tlogger: Logger\n\tauthenticator: Authenticator\n\tprojectMembershipResolver: ProjectMembershipResolver\n\n\tprojectContainerResolver: ProjectContainerResolver\n\tprojectSchemaResolver: ProjectSchemaResolverInterface\n\tprojectInitializer: ProjectInitializerInterface\n\n\ttenantContainer: TenantContainer\n\ttenantGraphQLHandler: TenantGraphQLHandler\n\n\tsystemContainer: SystemContainer\n\tsystemGraphQLHandler: SystemGraphQLHandler\n}\n\ninterface ProjectGroupContainerFactoryArgs {\n\tconfig: TenantConfig\n\tslug: string | undefined\n}\n\nexport class ProjectGroupContainerFactory {\n\tconstructor(\n\t\tprivate readonly debug: boolean,\n\t\tprivate readonly providers: Providers,\n\t\tprivate readonly systemContainerFactory: SystemContainerFactory,\n\t\tprivate readonly tenantContainerFactory: TenantContainerFactory,\n\t\tprivate readonly projectContainerFactoryFactory: ProjectContainerFactoryFactory,\n\t\tprivate readonly projectConfigResolver: ProjectConfigResolver,\n\t\tprivate readonly tenantGraphQLHandlerFactory: TenantGraphQLHandlerFactory,\n\t\tprivate readonly systemGraphQLHandlerFactory: SystemGraphQLHandlerFactory,\n\t\tprivate readonly logger: Logger,\n\t\t/** A03: configured trusted geo-country header name, or undefined when off. */\n\t\tprivate readonly geoCountryHeader?: string,\n\t) {}\n\n\tpublic create({ config, slug }: ProjectGroupContainerFactoryArgs): ProjectGroupContainer {\n\t\treturn new Builder({})\n\t\t\t.addService('slug', () => slug)\n\t\t\t.addService('logger', ({ slug }) => this.logger.child({ projectGroup: slug }))\n\t\t\t.addService('providers', () => this.providers)\n\t\t\t.addService('tenantDbCredentials', () => config.db)\n\t\t\t.addService(\n\t\t\t\t'tenantConnection',\n\t\t\t\t({ tenantDbCredentials, logger }): Connection.ConnectionType => Connection.create(tenantDbCredentials, err => logger.error(err)),\n\t\t\t)\n\t\t\t.addService('tenantReadConnection', ({ tenantDbCredentials, logger, tenantConnection }) => {\n\t\t\t\tif (!tenantDbCredentials.read) {\n\t\t\t\t\treturn tenantConnection\n\t\t\t\t}\n\t\t\t\treturn Connection.create(\n\t\t\t\t\t{\n\t\t\t\t\t\t...tenantDbCredentials,\n\t\t\t\t\t\t...tenantDbCredentials.read,\n\t\t\t\t\t\tpool: {\n\t\t\t\t\t\t\t...tenantDbCredentials.pool,\n\t\t\t\t\t\t\t...tenantDbCredentials.read.pool,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\terr => logger.error(err),\n\t\t\t\t\t{ retryStaleConnection: true },\n\t\t\t\t)\n\t\t\t})\n\t\t\t.addService('projectSchemaResolver', () => new ProjectSchemaResolverProxy())\n\t\t\t.addService('projectInitializer', () => new ProjectInitializerProxy())\n\t\t\t.addService(\n\t\t\t\t'tenantContainer',\n\t\t\t\t({ tenantConnection, tenantReadConnection, tenantDbCredentials, projectSchemaResolver, projectInitializer, logger }) => {\n\t\t\t\t\tconst encryptionKey = config.secrets.encryptionKey\n\t\t\t\t\t\t? createSecretKey(Buffer.from(config.secrets.encryptionKey, 'hex'))\n\t\t\t\t\t\t: undefined\n\n\t\t\t\t\tconst cryptoWrapper = new CryptoWrapper(encryptionKey)\n\t\t\t\t\treturn this.tenantContainerFactory.create({\n\t\t\t\t\t\tconnection: tenantConnection,\n\t\t\t\t\t\treadConnection: tenantReadConnection,\n\t\t\t\t\t\tdbCredentials: tenantDbCredentials,\n\t\t\t\t\t\tmailOptions: config.mailer,\n\t\t\t\t\t\ttenantCredentials: {\n\t\t\t\t\t\t\t...config.credentials,\n\t\t\t\t\t\t\trootTokens: normalizeTokenList(config.credentials.rootTokens),\n\t\t\t\t\t\t\trootTokenHashes: normalizeTokenList(config.credentials.rootTokenHashes),\n\t\t\t\t\t\t},\n\t\t\t\t\t\tprojectInitializer,\n\t\t\t\t\t\tprojectSchemaResolver,\n\t\t\t\t\t\tlogger,\n\t\t\t\t\t\tcryptoProviders: {\n\t\t\t\t\t\t\tdecrypt: cryptoWrapper.decrypt.bind(cryptoWrapper),\n\t\t\t\t\t\t\tencrypt: cryptoWrapper.encrypt.bind(cryptoWrapper),\n\t\t\t\t\t\t\tencryptionEnabled: cryptoWrapper.enabled,\n\t\t\t\t\t\t},\n\t\t\t\t\t})\n\t\t\t\t},\n\t\t\t)\n\t\t\t.addService('tenantDatabase', ({ tenantContainer }) => tenantContainer.databaseContext)\n\t\t\t.addService('tenantReadDatabase', ({ tenantContainer }) => tenantContainer.readDatabaseContext)\n\t\t\t.addService('identityFetcher', ({ tenantContainer: { identityFetcher } }) => identityFetcher)\n\t\t\t.addService('systemContainer', ({ identityFetcher }) => this.systemContainerFactory.create({ identityFetcher }))\n\t\t\t.addService('schemaProvider', ({ systemContainer }) => systemContainer.schemaProvider)\n\t\t\t.addService('projectContainerFactory', ({ schemaProvider, logger }) => this.projectContainerFactoryFactory.create(schemaProvider, logger))\n\t\t\t.addService('tenantProjectManager', ({ tenantContainer }) => tenantContainer.projectManager)\n\t\t\t.addService('tenantProjectMemberManager', ({ tenantContainer }) => tenantContainer.projectMemberManager)\n\t\t\t.addService('projectContainerResolver', ({ projectContainerFactory, tenantProjectManager, tenantReadDatabase }) =>\n\t\t\t\tnew ProjectContainerResolver(\n\t\t\t\t\tprojectContainerFactory,\n\t\t\t\t\tthis.projectConfigResolver,\n\t\t\t\t\ttenantProjectManager,\n\t\t\t\t\ttenantReadDatabase,\n\t\t\t\t\tconfig,\n\t\t\t\t))\n\t\t\t.setupService('projectSchemaResolver', (it, { projectContainerResolver }) => {\n\t\t\t\tit.setResolver(new ProjectSchemaResolver(projectContainerResolver))\n\t\t\t})\n\t\t\t.setupService('projectInitializer', (it, { projectContainerResolver }) => {\n\t\t\t\tit.setInitializer(new ProjectInitializer(projectContainerResolver))\n\t\t\t})\n\t\t\t.addService('tenantGraphQLHandler', ({ tenantContainer }) => this.tenantGraphQLHandlerFactory.create(tenantContainer.resolvers))\n\t\t\t.addService('systemGraphQLHandler', ({ systemContainer }) => this.systemGraphQLHandlerFactory.create(systemContainer.systemResolversFactory))\n\t\t\t.addService(\n\t\t\t\t'authenticator',\n\t\t\t\t({ tenantDatabase, tenantReadDatabase, tenantContainer }) =>\n\t\t\t\t\tnew Authenticator(tenantDatabase, tenantReadDatabase, tenantContainer.apiKeyManager, this.geoCountryHeader),\n\t\t\t)\n\t\t\t.addService(\n\t\t\t\t'projectMembershipResolver',\n\t\t\t\t({ tenantProjectMemberManager, tenantReadDatabase }) =>\n\t\t\t\t\tnew ProjectMembershipResolver(this.debug, new ProjectMembershipFetcher(tenantProjectMemberManager, tenantReadDatabase)),\n\t\t\t)\n\t\t\t.build()\n\t\t\t.pick(\n\t\t\t\t'projectContainerResolver',\n\t\t\t\t'projectSchemaResolver',\n\t\t\t\t'projectInitializer',\n\t\t\t\t'systemContainer',\n\t\t\t\t'systemGraphQLHandler',\n\t\t\t\t'tenantContainer',\n\t\t\t\t'authenticator',\n\t\t\t\t'projectMembershipResolver',\n\t\t\t\t'tenantGraphQLHandler',\n\t\t\t\t'slug',\n\t\t\t\t'logger',\n\t\t\t)\n\t}\n}\n"],"names":["slug"],"mappings":";;;;;;;;;;;;;;;;;;AAiCA,MAAM,qBAAqB,CAAC,UAAiF;AAC5G,MAAI,UAAU,QAAW;AACxB,WAAO;AAAA,EACR;AACA,QAAM,SAAS,MAAM,QAAQ,KAAK,IAAI,QAAS,MAAiB,MAAM,QAAQ,GAC5E,IAAI,CAAA,OAAM,GAAG,MAAM,EACnB,OAAO,CAAA,OAAM,GAAG,SAAS,CAAC;AAC5B,SAAO,MAAM,SAAS,IAAI,QAAQ;AACnC;AAyBO,MAAM,6BAA6B;AAAA,EACzC,YACkB,OACA,WACA,wBACA,wBACA,gCACA,uBACA,6BACA,6BACA,QAEA,kBAChB;AAXgB,SAAA,QAAA;AACA,SAAA,YAAA;AACA,SAAA,yBAAA;AACA,SAAA,yBAAA;AACA,SAAA,iCAAA;AACA,SAAA,wBAAA;AACA,SAAA,8BAAA;AACA,SAAA,8BAAA;AACA,SAAA,SAAA;AAEA,SAAA,mBAAA;AAAA,EACf;AAAA,EAEI,OAAO,EAAE,QAAQ,QAAiE;AACxF,WAAO,IAAI,QAAQ,CAAA,CAAE,EACnB,WAAW,QAAQ,MAAM,IAAI,EAC7B,WAAW,UAAU,CAAC,EAAE,MAAAA,YAAW,KAA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AAC,EAAE,sBAAsB,KAAK,4BAA4B,OAAO,gBAAgB,sBAAsB,CAAC,EAC3I;AAAA,MACA;AAAA,MACA,CAAC,EAAE,gBAAgB,oBAAoB,gBAAA,MACtC,IAAI,cAAc,gBAAgB,oBAAoB,gBAAgB,eAAe,KAAK,gBAAgB;AAAA,IAAA,EAE3G;AAAA,MACA;AAAA,MACA,CAAC,EAAE,4BAA4B,mBAAA,MAC9B,IAAI,0BAA0B,KAAK,OAAO,IAAI,yBAAyB,4BAA4B,kBAAkB,CAAC;AAAA,IAAA,EAEvH,QACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA;AAAA,EAEH;AACD;"}
|
|
1
|
+
{"version":3,"file":"ProjectGroupContainer.js","sources":["../../../../../packages/engine-http/src/projectGroup/ProjectGroupContainer.ts"],"sourcesContent":["import { Builder } from '@contember/dic'\nimport { Connection } from '@contember/database'\nimport {\n\tProjectInitializer as ProjectInitializerInterface,\n\tProjectSchemaResolver as ProjectSchemaResolverInterface,\n\tTenantContainer,\n\tTenantContainerFactory,\n} from '@contember/engine-tenant-api'\nimport { TenantConfig } from '../config/config.js'\nimport {\n\tProjectContainerFactoryFactory,\n\tProjectContainerResolver,\n\tProjectInitializer,\n\tProjectInitializerProxy,\n\tProjectSchemaResolver,\n\tProjectSchemaResolverProxy,\n} from '../project/index.js'\nimport { SystemContainer, SystemContainerFactory } from '@contember/engine-system-api'\nimport { ProjectConfigResolver } from '../config/projectConfigResolver.js'\nimport { createSecretKey } from 'node:crypto'\nimport { Logger } from '@contember/logger'\nimport { TenantGraphQLHandler, TenantGraphQLHandlerFactory } from '../tenant/index.js'\nimport { SystemGraphQLHandler, SystemGraphQLHandlerFactory } from '../system/index.js'\nimport { Authenticator } from '../common/index.js'\nimport { ProjectMembershipFetcher, ProjectMembershipResolver } from '../content/index.js'\nimport { Providers } from '../providers.js'\nimport { CryptoWrapper } from '../utils/CryptoWrapper.js'\n\n/**\n * Normalizes a token list that may be provided either as an array (JSON config)\n * or as a comma/whitespace-separated string (env-based config) into an array of\n * non-empty tokens.\n */\nconst normalizeTokenList = (value: string | readonly string[] | undefined): readonly string[] | undefined => {\n\tif (value === undefined) {\n\t\treturn undefined\n\t}\n\tconst items = (Array.isArray(value) ? value : (value as string).split(/[\\s,]+/))\n\t\t.map(it => it.trim())\n\t\t.filter(it => it.length > 0)\n\treturn items.length > 0 ? items : undefined\n}\n\nexport interface ProjectGroupContainer {\n\tslug: string | undefined\n\n\tlogger: Logger\n\tauthenticator: Authenticator\n\tprojectMembershipResolver: ProjectMembershipResolver\n\n\tprojectContainerResolver: ProjectContainerResolver\n\tprojectSchemaResolver: ProjectSchemaResolverInterface\n\tprojectInitializer: ProjectInitializerInterface\n\n\ttenantContainer: TenantContainer\n\ttenantGraphQLHandler: TenantGraphQLHandler\n\n\tsystemContainer: SystemContainer\n\tsystemGraphQLHandler: SystemGraphQLHandler\n}\n\ninterface ProjectGroupContainerFactoryArgs {\n\tconfig: TenantConfig\n\tslug: string | undefined\n}\n\nexport class ProjectGroupContainerFactory {\n\tconstructor(\n\t\tprivate readonly debug: boolean,\n\t\tprivate readonly providers: Providers,\n\t\tprivate readonly systemContainerFactory: SystemContainerFactory,\n\t\tprivate readonly tenantContainerFactory: TenantContainerFactory,\n\t\tprivate readonly projectContainerFactoryFactory: ProjectContainerFactoryFactory,\n\t\tprivate readonly projectConfigResolver: ProjectConfigResolver,\n\t\tprivate readonly tenantGraphQLHandlerFactory: TenantGraphQLHandlerFactory,\n\t\tprivate readonly systemGraphQLHandlerFactory: SystemGraphQLHandlerFactory,\n\t\tprivate readonly logger: Logger,\n\t\t/** A03: configured trusted geo-country header name, or undefined when off. */\n\t\tprivate readonly geoCountryHeader?: string,\n\t) {}\n\n\tpublic create({ config, slug }: ProjectGroupContainerFactoryArgs): ProjectGroupContainer {\n\t\treturn new Builder({})\n\t\t\t.addService('slug', () => slug)\n\t\t\t.addService('logger', ({ slug }) => this.logger.child({ projectGroup: slug }))\n\t\t\t.addService('providers', () => this.providers)\n\t\t\t.addService('tenantDbCredentials', () => config.db)\n\t\t\t.addService(\n\t\t\t\t'tenantConnection',\n\t\t\t\t({ tenantDbCredentials, logger }): Connection.ConnectionType => Connection.create(tenantDbCredentials, err => logger.error(err)),\n\t\t\t)\n\t\t\t.addService('tenantReadConnection', ({ tenantDbCredentials, logger, tenantConnection }) => {\n\t\t\t\tif (!tenantDbCredentials.read) {\n\t\t\t\t\treturn tenantConnection\n\t\t\t\t}\n\t\t\t\treturn Connection.create(\n\t\t\t\t\t{\n\t\t\t\t\t\t...tenantDbCredentials,\n\t\t\t\t\t\t...tenantDbCredentials.read,\n\t\t\t\t\t\tpool: {\n\t\t\t\t\t\t\t...tenantDbCredentials.pool,\n\t\t\t\t\t\t\t...tenantDbCredentials.read.pool,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\terr => logger.error(err),\n\t\t\t\t\t{ retryStaleConnection: true },\n\t\t\t\t)\n\t\t\t})\n\t\t\t.addService('projectSchemaResolver', () => new ProjectSchemaResolverProxy())\n\t\t\t.addService('projectInitializer', () => new ProjectInitializerProxy())\n\t\t\t.addService(\n\t\t\t\t'tenantContainer',\n\t\t\t\t({ tenantConnection, tenantReadConnection, tenantDbCredentials, projectSchemaResolver, projectInitializer, logger }) => {\n\t\t\t\t\tconst encryptionKey = config.secrets.encryptionKey\n\t\t\t\t\t\t? createSecretKey(Buffer.from(config.secrets.encryptionKey, 'hex'))\n\t\t\t\t\t\t: undefined\n\n\t\t\t\t\tconst cryptoWrapper = new CryptoWrapper(encryptionKey)\n\t\t\t\t\treturn this.tenantContainerFactory.create({\n\t\t\t\t\t\tconnection: tenantConnection,\n\t\t\t\t\t\treadConnection: tenantReadConnection,\n\t\t\t\t\t\tdbCredentials: tenantDbCredentials,\n\t\t\t\t\t\tmailOptions: config.mailer,\n\t\t\t\t\t\ttenantCredentials: {\n\t\t\t\t\t\t\t...config.credentials,\n\t\t\t\t\t\t\trootTokens: normalizeTokenList(config.credentials.rootTokens),\n\t\t\t\t\t\t\trootTokenHashes: normalizeTokenList(config.credentials.rootTokenHashes),\n\t\t\t\t\t\t},\n\t\t\t\t\t\tprojectInitializer,\n\t\t\t\t\t\tprojectSchemaResolver,\n\t\t\t\t\t\tlogger,\n\t\t\t\t\t\tcryptoProviders: {\n\t\t\t\t\t\t\tdecrypt: cryptoWrapper.decrypt.bind(cryptoWrapper),\n\t\t\t\t\t\t\tencrypt: cryptoWrapper.encrypt.bind(cryptoWrapper),\n\t\t\t\t\t\t\tencryptionEnabled: cryptoWrapper.enabled,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tdataSigner: cryptoWrapper.enabled ? (purpose, value) => cryptoWrapper.sign(purpose, value) : null,\n\t\t\t\t\t})\n\t\t\t\t},\n\t\t\t)\n\t\t\t.addService('tenantDatabase', ({ tenantContainer }) => tenantContainer.databaseContext)\n\t\t\t.addService('tenantReadDatabase', ({ tenantContainer }) => tenantContainer.readDatabaseContext)\n\t\t\t.addService('identityFetcher', ({ tenantContainer: { identityFetcher } }) => identityFetcher)\n\t\t\t.addService('systemContainer', ({ identityFetcher }) => this.systemContainerFactory.create({ identityFetcher }))\n\t\t\t.addService('schemaProvider', ({ systemContainer }) => systemContainer.schemaProvider)\n\t\t\t.addService('projectContainerFactory', ({ schemaProvider, logger }) => this.projectContainerFactoryFactory.create(schemaProvider, logger))\n\t\t\t.addService('tenantProjectManager', ({ tenantContainer }) => tenantContainer.projectManager)\n\t\t\t.addService('tenantProjectMemberManager', ({ tenantContainer }) => tenantContainer.projectMemberManager)\n\t\t\t.addService('projectContainerResolver', ({ projectContainerFactory, tenantProjectManager, tenantReadDatabase }) =>\n\t\t\t\tnew ProjectContainerResolver(\n\t\t\t\t\tprojectContainerFactory,\n\t\t\t\t\tthis.projectConfigResolver,\n\t\t\t\t\ttenantProjectManager,\n\t\t\t\t\ttenantReadDatabase,\n\t\t\t\t\tconfig,\n\t\t\t\t))\n\t\t\t.setupService('projectSchemaResolver', (it, { projectContainerResolver }) => {\n\t\t\t\tit.setResolver(new ProjectSchemaResolver(projectContainerResolver))\n\t\t\t})\n\t\t\t.setupService('projectInitializer', (it, { projectContainerResolver }) => {\n\t\t\t\tit.setInitializer(new ProjectInitializer(projectContainerResolver))\n\t\t\t})\n\t\t\t.addService('tenantGraphQLHandler', ({ tenantContainer }) => this.tenantGraphQLHandlerFactory.create(tenantContainer.resolvers))\n\t\t\t.addService('systemGraphQLHandler', ({ systemContainer }) => this.systemGraphQLHandlerFactory.create(systemContainer.systemResolversFactory))\n\t\t\t.addService(\n\t\t\t\t'authenticator',\n\t\t\t\t({ tenantDatabase, tenantReadDatabase, tenantContainer }) =>\n\t\t\t\t\tnew Authenticator(tenantDatabase, tenantReadDatabase, tenantContainer.apiKeyManager, this.geoCountryHeader),\n\t\t\t)\n\t\t\t.addService(\n\t\t\t\t'projectMembershipResolver',\n\t\t\t\t({ tenantProjectMemberManager, tenantReadDatabase }) =>\n\t\t\t\t\tnew ProjectMembershipResolver(this.debug, new ProjectMembershipFetcher(tenantProjectMemberManager, tenantReadDatabase)),\n\t\t\t)\n\t\t\t.build()\n\t\t\t.pick(\n\t\t\t\t'projectContainerResolver',\n\t\t\t\t'projectSchemaResolver',\n\t\t\t\t'projectInitializer',\n\t\t\t\t'systemContainer',\n\t\t\t\t'systemGraphQLHandler',\n\t\t\t\t'tenantContainer',\n\t\t\t\t'authenticator',\n\t\t\t\t'projectMembershipResolver',\n\t\t\t\t'tenantGraphQLHandler',\n\t\t\t\t'slug',\n\t\t\t\t'logger',\n\t\t\t)\n\t}\n}\n"],"names":["slug"],"mappings":";;;;;;;;;;;;;;;;;;AAiCA,MAAM,qBAAqB,CAAC,UAAiF;AAC5G,MAAI,UAAU,QAAW;AACxB,WAAO;AAAA,EACR;AACA,QAAM,SAAS,MAAM,QAAQ,KAAK,IAAI,QAA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2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const
|
|
3
|
+
const utilities = require("@contember/utilities");
|
|
4
4
|
const bcrypt = require("bcryptjs");
|
|
5
5
|
const crypto = require("node:crypto");
|
|
6
6
|
const createProviders = () => ({
|
|
7
|
-
uuid: ({ version = 4 } = {}) => version === 4 ?
|
|
7
|
+
uuid: ({ version = 4 } = {}) => version === 4 ? utilities.generateUuidV4() : utilities.generateUuidV7(),
|
|
8
8
|
now: () => /* @__PURE__ */ new Date(),
|
|
9
9
|
bcrypt: async (value) => await bcrypt.hash(value, 10),
|
|
10
10
|
bcryptCompare: (data, hash) => bcrypt.compare(data, hash),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"providers.cjs","sources":["../../../../packages/engine-http/src/providers.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"providers.cjs","sources":["../../../../packages/engine-http/src/providers.ts"],"sourcesContent":["import { generateUuidV4, generateUuidV7 } from '@contember/utilities'\nimport bcrypt from 'bcryptjs'\nimport crypto, { BinaryLike } from 'node:crypto'\n\nexport const createProviders = () => ({\n\tuuid: ({ version = 4 }: { version?: 4 | 7 } = {}) => version === 4 ? generateUuidV4() : generateUuidV7(),\n\tnow: () => new Date(),\n\tbcrypt: async (value: string) => await bcrypt.hash(value, 10),\n\tbcryptCompare: (data: any, hash: string) => bcrypt.compare(data, hash),\n\trandomBytes: async (bytes: number) =>\n\t\tawait new Promise<Buffer>((resolve, reject) => {\n\t\t\tcrypto.randomBytes(bytes, (error, buffer) => {\n\t\t\t\tif (error) {\n\t\t\t\t\treject(error)\n\t\t\t\t} else {\n\t\t\t\t\tresolve(buffer)\n\t\t\t\t}\n\t\t\t})\n\t\t}),\n\thash: (value: BinaryLike, algo: string): Buffer => (\n\t\tcrypto.createHash(algo).update(value).digest()\n\t),\n})\n\nexport type Providers = ReturnType<typeof createProviders>\n"],"names":["generateUuidV4","generateUuidV7"],"mappings":";;;;;AAIO,MAAM,kBAAkB,OAAO;AAAA,EACrC,MAAM,CAAC,EAAE,UAAU,EAAA,IAA2B,OAAO,YAAY,IAAIA,yBAAA,IAAmBC,yBAAA;AAAA,EACxF,KAAK,MAAM,oBAAI,KAAA;AAAA,EACf,QAAQ,OAAO,UAAkB,MAAM,OAAO,KAAK,OAAO,EAAE;AAAA,EAC5D,eAAe,CAAC,MAAW,SAAiB,OAAO,QAAQ,MAAM,IAAI;AAAA,EACrE,aAAa,OAAO,UACnB,MAAM,IAAI,QAAgB,CAAC,SAAS,WAAW;AAC9C,WAAO,YAAY,OAAO,CAAC,OAAO,WAAW;AAC5C,UAAI,OAAO;AACV,eAAO,KAAK;AAAA,MACb,OAAO;AACN,gBAAQ,MAAM;AAAA,MACf;AAAA,IACD,CAAC;AAAA,EACF,CAAC;AAAA,EACF,MAAM,CAAC,OAAmB,SACzB,OAAO,WAAW,IAAI,EAAE,OAAO,KAAK,EAAE,OAAA;AAExC;;"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { generateUuidV4, generateUuidV7 } from "@contember/utilities";
|
|
2
2
|
import bcrypt from "bcryptjs";
|
|
3
3
|
import crypto__default from "node:crypto";
|
|
4
4
|
const createProviders = () => ({
|
|
5
|
-
uuid: ({ version = 4 } = {}) => version === 4 ?
|
|
5
|
+
uuid: ({ version = 4 } = {}) => version === 4 ? generateUuidV4() : generateUuidV7(),
|
|
6
6
|
now: () => /* @__PURE__ */ new Date(),
|
|
7
7
|
bcrypt: async (value) => await bcrypt.hash(value, 10),
|
|
8
8
|
bcryptCompare: (data, hash) => bcrypt.compare(data, hash),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"providers.js","sources":["../../../../packages/engine-http/src/providers.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"providers.js","sources":["../../../../packages/engine-http/src/providers.ts"],"sourcesContent":["import { generateUuidV4, generateUuidV7 } from '@contember/utilities'\nimport bcrypt from 'bcryptjs'\nimport crypto, { BinaryLike } from 'node:crypto'\n\nexport const createProviders = () => ({\n\tuuid: ({ version = 4 }: { version?: 4 | 7 } = {}) => version === 4 ? generateUuidV4() : generateUuidV7(),\n\tnow: () => new Date(),\n\tbcrypt: async (value: string) => await bcrypt.hash(value, 10),\n\tbcryptCompare: (data: any, hash: string) => bcrypt.compare(data, hash),\n\trandomBytes: async (bytes: number) =>\n\t\tawait new Promise<Buffer>((resolve, reject) => {\n\t\t\tcrypto.randomBytes(bytes, (error, buffer) => {\n\t\t\t\tif (error) {\n\t\t\t\t\treject(error)\n\t\t\t\t} else {\n\t\t\t\t\tresolve(buffer)\n\t\t\t\t}\n\t\t\t})\n\t\t}),\n\thash: (value: BinaryLike, algo: string): Buffer => (\n\t\tcrypto.createHash(algo).update(value).digest()\n\t),\n})\n\nexport type Providers = ReturnType<typeof createProviders>\n"],"names":["crypto"],"mappings":";;;AAIO,MAAM,kBAAkB,OAAO;AAAA,EACrC,MAAM,CAAC,EAAE,UAAU,EAAA,IAA2B,OAAO,YAAY,IAAI,eAAA,IAAmB,eAAA;AAAA,EACxF,KAAK,MAAM,oBAAI,KAAA;AAAA,EACf,QAAQ,OAAO,UAAkB,MAAM,OAAO,KAAK,OAAO,EAAE;AAAA,EAC5D,eAAe,CAAC,MAAW,SAAiB,OAAO,QAAQ,MAAM,IAAI;AAAA,EACrE,aAAa,OAAO,UACnB,MAAM,IAAI,QAAgB,CAAC,SAAS,WAAW;AAC9CA,oBAAO,YAAY,OAAO,CAAC,OAAO,WAAW;AAC5C,UAAI,OAAO;AACV,eAAO,KAAK;AAAA,MACb,OAAO;AACN,gBAAQ,MAAM;AAAA,MACf;AAAA,IACD,CAAC;AAAA,EACF,CAAC;AAAA,EACF,MAAM,CAAC,OAAmB,SACzBA,gBAAO,WAAW,IAAI,EAAE,OAAO,KAAK,EAAE,OAAA;AAExC;"}
|
|
@@ -5,10 +5,10 @@ require("ipaddr.js");
|
|
|
5
5
|
require("@contember/engine-tenant-api");
|
|
6
6
|
const CommandStream = require("./CommandStream.cjs");
|
|
7
7
|
const ImportExecutor = require("./ImportExecutor.cjs");
|
|
8
|
-
const
|
|
8
|
+
const zlib = require("node:zlib");
|
|
9
9
|
const node_stream = require("node:stream");
|
|
10
10
|
const readImportCommands = (body, isGzip) => {
|
|
11
|
-
return CommandStream.fromBuffer(isGzip ? node_stream.pipeline(body,
|
|
11
|
+
return CommandStream.fromBuffer(isGzip ? node_stream.pipeline(body, zlib.createGunzip(), () => {
|
|
12
12
|
}) : body);
|
|
13
13
|
};
|
|
14
14
|
class ImportApiMiddlewareFactory {
|
|
@@ -1 +1 @@
|
|
|
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 { pipeline, Readable } from 'node:stream'\nimport { ProjectGroupResolver } from '../projectGroup/ProjectGroupResolver.js'\nimport { Command } from './Command.js'\n\nexport const readImportCommands = (body: Readable, isGzip: boolean): AsyncIterable<Command> => {\n\t// pipe() would not pass on an aborted request, and the import would wait for the rest of the body forever;\n\t// pipeline() destroys the gunzip with the error, which rejects the read. The callback only satisfies the API.\n\treturn fromBuffer(isGzip ? pipeline(body, createGunzip(), () => {}) : body)\n}\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 = readImportCommands(request.req, isGzip)\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":["fromBuffer","pipeline","createGunzip","HttpErrorResponse","ImportError"],"mappings":";;;;;;;;;AASO,MAAM,qBAAqB,CAAC,MAAgB,WAA4C;AAG9F,SAAOA,cAAAA,WAAW,SAASC,YAAAA,SAAS,MAAMC,
|
|
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 { pipeline, Readable } from 'node:stream'\nimport { ProjectGroupResolver } from '../projectGroup/ProjectGroupResolver.js'\nimport { Command } from './Command.js'\n\nexport const readImportCommands = (body: Readable, isGzip: boolean): AsyncIterable<Command> => {\n\t// pipe() would not pass on an aborted request, and the import would wait for the rest of the body forever;\n\t// pipeline() destroys the gunzip with the error, which rejects the read. The callback only satisfies the API.\n\treturn fromBuffer(isGzip ? pipeline(body, createGunzip(), () => {}) : body)\n}\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 = readImportCommands(request.req, isGzip)\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":["fromBuffer","pipeline","createGunzip","HttpErrorResponse","ImportError"],"mappings":";;;;;;;;;AASO,MAAM,qBAAqB,CAAC,MAAgB,WAA4C;AAG9F,SAAOA,cAAAA,WAAW,SAASC,YAAAA,SAAS,MAAMC,KAAAA,aAAA,GAAgB,MAAM;AAAA,EAAC,CAAC,IAAI,IAAI;AAC3E;AAEO,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,IAAIC,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,WAAW,mBAAmB,QAAQ,KAAK,MAAM;AACvD,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;;;"}
|
|
@@ -4,6 +4,7 @@ const Database = require("@contember/database");
|
|
|
4
4
|
const schema = require("@contember/schema");
|
|
5
5
|
const Typesafe = require("@contember/typesafe");
|
|
6
6
|
const engineSystemApi = require("@contember/engine-system-api");
|
|
7
|
+
const engineContentApi = require("@contember/engine-content-api");
|
|
7
8
|
const HttpResponse = require("../common/HttpResponse.cjs");
|
|
8
9
|
require("ipaddr.js");
|
|
9
10
|
require("@contember/engine-tenant-api");
|
|
@@ -65,6 +66,13 @@ const listType = (arrayType) => {
|
|
|
65
66
|
return arrayType(input, path);
|
|
66
67
|
};
|
|
67
68
|
};
|
|
69
|
+
const calendarDate = (input, path = []) => {
|
|
70
|
+
const value = Typesafe__namespace.string(input, path);
|
|
71
|
+
if (engineContentApi.isImpossibleCalendarDate(value)) {
|
|
72
|
+
throw new Typesafe.ParseError(path, `${JSON.stringify(value)} is not a valid date`);
|
|
73
|
+
}
|
|
74
|
+
return value;
|
|
75
|
+
};
|
|
68
76
|
class CommandIterator {
|
|
69
77
|
constructor(commandName, commandArgs, commandIterator) {
|
|
70
78
|
this.commandName = commandName;
|
|
@@ -131,6 +139,7 @@ class ImportExecutor {
|
|
|
131
139
|
await this.requireImportAccess(groupContainer, contentSchema.schema, authResult, options.project, "content");
|
|
132
140
|
const contentDatabaseClient = projectContainer.connection.createClient(stage.schema, {});
|
|
133
141
|
const mapping = this.contentSchemaTransferMappingFactory.createContentSchemaMapping(contentSchema.schema);
|
|
142
|
+
this.requireMappedTables(mapping, options.tables, `content schema of project ${options.project}`);
|
|
134
143
|
return await contentDatabaseClient.transaction(async (db) => {
|
|
135
144
|
await this.disableTimeouts(db);
|
|
136
145
|
await this.disableTriggers(db, options.tables);
|
|
@@ -158,6 +167,7 @@ class ImportExecutor {
|
|
|
158
167
|
await this.requireImportAccess(groupContainer, schema2, authResult, options.project, "system");
|
|
159
168
|
const systemDatabaseContext = projectContainer.systemDatabaseContext;
|
|
160
169
|
const mapping = this.systemSchemaTransferMappingFactory.build();
|
|
170
|
+
this.requireMappedTables(mapping, options.tables, `system schema of project ${options.project}`);
|
|
161
171
|
return await systemDatabaseContext.client.transaction(async (db) => {
|
|
162
172
|
await this.disableTimeouts(db);
|
|
163
173
|
await this.truncateTables(db, options.tables);
|
|
@@ -171,6 +181,9 @@ class ImportExecutor {
|
|
|
171
181
|
}
|
|
172
182
|
async importSequence(db, mapping, it) {
|
|
173
183
|
const [options] = it.commandArgs;
|
|
184
|
+
if (!Object.hasOwn(mapping.tables, options.table) || !Object.hasOwn(mapping.tables[options.table].columns, options.column)) {
|
|
185
|
+
throw new ImportError(`Unknown column ${options.table}.${options.column}`);
|
|
186
|
+
}
|
|
174
187
|
await db.query(
|
|
175
188
|
"SELECT setval(pg_get_serial_sequence(?, ?), ?)",
|
|
176
189
|
[`${db.schema}.${options.table}`, options.column, options.value]
|
|
@@ -189,7 +202,13 @@ class ImportExecutor {
|
|
|
189
202
|
insertContext.rows.push(insertContext.rowParser(values));
|
|
190
203
|
} catch (e) {
|
|
191
204
|
if (e instanceof Typesafe.ParseError) {
|
|
192
|
-
|
|
205
|
+
const rowNumber = insertContext.insertedRowCount + insertContext.rows.length + 1;
|
|
206
|
+
const [columnIndex, ...valuePath] = e.path;
|
|
207
|
+
const columnName = columnIndex !== void 0 ? options.columns[Number(columnIndex)] : void 0;
|
|
208
|
+
const elementLocation = valuePath.length > 0 ? `, element /${valuePath.map(String).join("/")}` : "";
|
|
209
|
+
const location = columnName !== void 0 ? `table ${options.table}, column ${columnName}${elementLocation}` : `table ${options.table}`;
|
|
210
|
+
const reason = columnName !== void 0 ? e.reason : e.message;
|
|
211
|
+
throw new ImportError(`Invalid row #${rowNumber} ${JSON.stringify(values)} for ${location}: ${reason}`);
|
|
193
212
|
} else {
|
|
194
213
|
throw e;
|
|
195
214
|
}
|
|
@@ -237,6 +256,14 @@ class ImportExecutor {
|
|
|
237
256
|
throw new HttpResponse.HttpErrorResponse(403, `You are not allowed to import ${kind} in ${projectSlug}`);
|
|
238
257
|
}
|
|
239
258
|
}
|
|
259
|
+
/** The tables an import truncates must come from the same mapping an export of this schema lists. */
|
|
260
|
+
requireMappedTables(mapping, tableNames, target) {
|
|
261
|
+
for (const tableName of tableNames) {
|
|
262
|
+
if (!Object.hasOwn(mapping.tables, tableName)) {
|
|
263
|
+
throw new ImportError(`Table ${tableName} is not part of the ${target}`);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
240
267
|
async fetchStageBySlug(systemDatabaseContext, projectSlug, stageSlug) {
|
|
241
268
|
const stage = await systemDatabaseContext.queryHandler.fetch(new engineSystemApi.StageBySlugQuery(stageSlug));
|
|
242
269
|
if (stage === null) {
|
|
@@ -280,13 +307,13 @@ class ImportExecutor {
|
|
|
280
307
|
return await db.query(sql, parameters);
|
|
281
308
|
}
|
|
282
309
|
async buildInsertContext(db, mapping, schema2, tableName, columnNames) {
|
|
283
|
-
const tableMapping = mapping.tables[tableName];
|
|
310
|
+
const tableMapping = Object.hasOwn(mapping.tables, tableName) ? mapping.tables[tableName] : void 0;
|
|
284
311
|
const columns = [];
|
|
285
312
|
if (tableMapping === void 0) {
|
|
286
313
|
throw new ImportError(`Unknown table ${tableName}`);
|
|
287
314
|
}
|
|
288
315
|
for (const columnName of columnNames) {
|
|
289
|
-
const column = tableMapping.columns[columnName];
|
|
316
|
+
const column = Object.hasOwn(tableMapping.columns, columnName) ? tableMapping.columns[columnName] : void 0;
|
|
290
317
|
if (column === void 0) {
|
|
291
318
|
throw new ImportError(`Unknown column ${tableName}.${columnName}`);
|
|
292
319
|
}
|
|
@@ -325,13 +352,14 @@ class ImportExecutor {
|
|
|
325
352
|
case schema.Model.ColumnType.Uuid:
|
|
326
353
|
case schema.Model.ColumnType.String:
|
|
327
354
|
case schema.Model.ColumnType.Enum:
|
|
328
|
-
case schema.Model.ColumnType.DateTime:
|
|
329
355
|
case schema.Model.ColumnType.Time:
|
|
330
|
-
case schema.Model.ColumnType.Date:
|
|
331
356
|
case schema.Model.ColumnType.Json:
|
|
332
357
|
// Numeric is transferred as a string to avoid JS float precision loss.
|
|
333
358
|
case schema.Model.ColumnType.Numeric:
|
|
334
359
|
return column.list ? listType(Typesafe__namespace.array(Typesafe__namespace.string)) : Typesafe__namespace.string;
|
|
360
|
+
case schema.Model.ColumnType.Date:
|
|
361
|
+
case schema.Model.ColumnType.DateTime:
|
|
362
|
+
return column.list ? listType(Typesafe__namespace.array(calendarDate)) : calendarDate;
|
|
335
363
|
case schema.Model.ColumnType.Int:
|
|
336
364
|
case schema.Model.ColumnType.Double:
|
|
337
365
|
return column.list ? listType(Typesafe__namespace.array(Typesafe__namespace.number)) : Typesafe__namespace.number;
|
|
@@ -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.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;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BAAS,MAAMA,oBAAS,OAAO,CAAC,IAAIA,oBAAS;AAAA,IAAA;AAAA,EAE9E;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 { isImpossibleCalendarDate } from '@contember/engine-content-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\n// PostgreSQL would fail the whole batch insert on an impossible date with a server error that names neither column nor row.\nconst calendarDate: Typesafe.Type<string> = (input: unknown, path: PropertyKey[] = []) => {\n\tconst value = Typesafe.string(input, path)\n\tif (isImpossibleCalendarDate(value)) {\n\t\tthrow new ParseError(path, `${JSON.stringify(value)} is not a valid date`)\n\t}\n\treturn value\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\t\tthis.requireMappedTables(mapping, options.tables, `content schema of project ${options.project}`)\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\t\tthis.requireMappedTables(mapping, options.tables, `system schema of project ${options.project}`)\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\t\tif (!Object.hasOwn(mapping.tables, options.table) || !Object.hasOwn(mapping.tables[options.table].columns, options.column)) {\n\t\t\tthrow new ImportError(`Unknown column ${options.table}.${options.column}`)\n\t\t}\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\tconst rowNumber = insertContext.insertedRowCount + insertContext.rows.length + 1\n\t\t\t\t\t\t// The row parser is a tuple over the insertBegin columns, so the first path segment is the column index.\n\t\t\t\t\t\tconst [columnIndex, ...valuePath] = e.path\n\t\t\t\t\t\tconst columnName = columnIndex !== undefined ? options.columns[Number(columnIndex)] : undefined\n\t\t\t\t\t\tconst elementLocation = valuePath.length > 0 ? `, element /${valuePath.map(String).join('/')}` : ''\n\t\t\t\t\t\tconst location = columnName !== undefined ? `table ${options.table}, column ${columnName}${elementLocation}` : `table ${options.table}`\n\t\t\t\t\t\tconst reason = columnName !== undefined ? e.reason : e.message\n\t\t\t\t\t\tthrow new ImportError(`Invalid row #${rowNumber} ${JSON.stringify(values)} for ${location}: ${reason}`)\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\t/** The tables an import truncates must come from the same mapping an export of this schema lists. */\n\tprivate requireMappedTables(mapping: TransferMapping, tableNames: readonly string[], target: string) {\n\t\tfor (const tableName of tableNames) {\n\t\t\tif (!Object.hasOwn(mapping.tables, tableName)) {\n\t\t\t\tthrow new ImportError(`Table ${tableName} is not part of the ${target}`)\n\t\t\t}\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 = Object.hasOwn(mapping.tables, tableName) ? mapping.tables[tableName] : undefined\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 = Object.hasOwn(tableMapping.columns, columnName) ? tableMapping.columns[columnName] : undefined\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.Time:\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.Date:\n\t\t\tcase Model.ColumnType.DateTime:\n\t\t\t\treturn column.list ? listType(Typesafe.array(calendarDate)) : calendarDate\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","Typesafe","isImpossibleCalendarDate","it","ConstraintHelper","schema","HttpErrorResponse","StageBySlugQuery","wrapIdentifier","Model"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBO,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,MAA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IA,oBAAS;AAAA,MAC3E,KAAKQ,OAAAA,MAAM,WAAW;AACrB,eAAO,OAAO,OAAO,SAASR,oBAAS,MAAMA,oBAAS,OAAO,CAAC,IAAIA,oBAAS;AAAA,IAAA;AAAA,EAE9E;AACD;;;"}
|
|
@@ -3,6 +3,7 @@ import { Model } from "@contember/schema";
|
|
|
3
3
|
import * as Typesafe from "@contember/typesafe";
|
|
4
4
|
import { ParseError } from "@contember/typesafe";
|
|
5
5
|
import { StageBySlugQuery } from "@contember/engine-system-api";
|
|
6
|
+
import { isImpossibleCalendarDate } from "@contember/engine-content-api";
|
|
6
7
|
import { HttpErrorResponse } from "../common/HttpResponse.js";
|
|
7
8
|
import "ipaddr.js";
|
|
8
9
|
import "@contember/engine-tenant-api";
|
|
@@ -47,6 +48,13 @@ const listType = (arrayType) => {
|
|
|
47
48
|
return arrayType(input, path);
|
|
48
49
|
};
|
|
49
50
|
};
|
|
51
|
+
const calendarDate = (input, path = []) => {
|
|
52
|
+
const value = Typesafe.string(input, path);
|
|
53
|
+
if (isImpossibleCalendarDate(value)) {
|
|
54
|
+
throw new ParseError(path, `${JSON.stringify(value)} is not a valid date`);
|
|
55
|
+
}
|
|
56
|
+
return value;
|
|
57
|
+
};
|
|
50
58
|
class CommandIterator {
|
|
51
59
|
constructor(commandName, commandArgs, commandIterator) {
|
|
52
60
|
this.commandName = commandName;
|
|
@@ -113,6 +121,7 @@ class ImportExecutor {
|
|
|
113
121
|
await this.requireImportAccess(groupContainer, contentSchema.schema, authResult, options.project, "content");
|
|
114
122
|
const contentDatabaseClient = projectContainer.connection.createClient(stage.schema, {});
|
|
115
123
|
const mapping = this.contentSchemaTransferMappingFactory.createContentSchemaMapping(contentSchema.schema);
|
|
124
|
+
this.requireMappedTables(mapping, options.tables, `content schema of project ${options.project}`);
|
|
116
125
|
return await contentDatabaseClient.transaction(async (db) => {
|
|
117
126
|
await this.disableTimeouts(db);
|
|
118
127
|
await this.disableTriggers(db, options.tables);
|
|
@@ -140,6 +149,7 @@ class ImportExecutor {
|
|
|
140
149
|
await this.requireImportAccess(groupContainer, schema, authResult, options.project, "system");
|
|
141
150
|
const systemDatabaseContext = projectContainer.systemDatabaseContext;
|
|
142
151
|
const mapping = this.systemSchemaTransferMappingFactory.build();
|
|
152
|
+
this.requireMappedTables(mapping, options.tables, `system schema of project ${options.project}`);
|
|
143
153
|
return await systemDatabaseContext.client.transaction(async (db) => {
|
|
144
154
|
await this.disableTimeouts(db);
|
|
145
155
|
await this.truncateTables(db, options.tables);
|
|
@@ -153,6 +163,9 @@ class ImportExecutor {
|
|
|
153
163
|
}
|
|
154
164
|
async importSequence(db, mapping, it) {
|
|
155
165
|
const [options] = it.commandArgs;
|
|
166
|
+
if (!Object.hasOwn(mapping.tables, options.table) || !Object.hasOwn(mapping.tables[options.table].columns, options.column)) {
|
|
167
|
+
throw new ImportError(`Unknown column ${options.table}.${options.column}`);
|
|
168
|
+
}
|
|
156
169
|
await db.query(
|
|
157
170
|
"SELECT setval(pg_get_serial_sequence(?, ?), ?)",
|
|
158
171
|
[`${db.schema}.${options.table}`, options.column, options.value]
|
|
@@ -171,7 +184,13 @@ class ImportExecutor {
|
|
|
171
184
|
insertContext.rows.push(insertContext.rowParser(values));
|
|
172
185
|
} catch (e) {
|
|
173
186
|
if (e instanceof ParseError) {
|
|
174
|
-
|
|
187
|
+
const rowNumber = insertContext.insertedRowCount + insertContext.rows.length + 1;
|
|
188
|
+
const [columnIndex, ...valuePath] = e.path;
|
|
189
|
+
const columnName = columnIndex !== void 0 ? options.columns[Number(columnIndex)] : void 0;
|
|
190
|
+
const elementLocation = valuePath.length > 0 ? `, element /${valuePath.map(String).join("/")}` : "";
|
|
191
|
+
const location = columnName !== void 0 ? `table ${options.table}, column ${columnName}${elementLocation}` : `table ${options.table}`;
|
|
192
|
+
const reason = columnName !== void 0 ? e.reason : e.message;
|
|
193
|
+
throw new ImportError(`Invalid row #${rowNumber} ${JSON.stringify(values)} for ${location}: ${reason}`);
|
|
175
194
|
} else {
|
|
176
195
|
throw e;
|
|
177
196
|
}
|
|
@@ -219,6 +238,14 @@ class ImportExecutor {
|
|
|
219
238
|
throw new HttpErrorResponse(403, `You are not allowed to import ${kind} in ${projectSlug}`);
|
|
220
239
|
}
|
|
221
240
|
}
|
|
241
|
+
/** The tables an import truncates must come from the same mapping an export of this schema lists. */
|
|
242
|
+
requireMappedTables(mapping, tableNames, target) {
|
|
243
|
+
for (const tableName of tableNames) {
|
|
244
|
+
if (!Object.hasOwn(mapping.tables, tableName)) {
|
|
245
|
+
throw new ImportError(`Table ${tableName} is not part of the ${target}`);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
222
249
|
async fetchStageBySlug(systemDatabaseContext, projectSlug, stageSlug) {
|
|
223
250
|
const stage = await systemDatabaseContext.queryHandler.fetch(new StageBySlugQuery(stageSlug));
|
|
224
251
|
if (stage === null) {
|
|
@@ -262,13 +289,13 @@ class ImportExecutor {
|
|
|
262
289
|
return await db.query(sql, parameters);
|
|
263
290
|
}
|
|
264
291
|
async buildInsertContext(db, mapping, schema, tableName, columnNames) {
|
|
265
|
-
const tableMapping = mapping.tables[tableName];
|
|
292
|
+
const tableMapping = Object.hasOwn(mapping.tables, tableName) ? mapping.tables[tableName] : void 0;
|
|
266
293
|
const columns = [];
|
|
267
294
|
if (tableMapping === void 0) {
|
|
268
295
|
throw new ImportError(`Unknown table ${tableName}`);
|
|
269
296
|
}
|
|
270
297
|
for (const columnName of columnNames) {
|
|
271
|
-
const column = tableMapping.columns[columnName];
|
|
298
|
+
const column = Object.hasOwn(tableMapping.columns, columnName) ? tableMapping.columns[columnName] : void 0;
|
|
272
299
|
if (column === void 0) {
|
|
273
300
|
throw new ImportError(`Unknown column ${tableName}.${columnName}`);
|
|
274
301
|
}
|
|
@@ -307,13 +334,14 @@ class ImportExecutor {
|
|
|
307
334
|
case Model.ColumnType.Uuid:
|
|
308
335
|
case Model.ColumnType.String:
|
|
309
336
|
case Model.ColumnType.Enum:
|
|
310
|
-
case Model.ColumnType.DateTime:
|
|
311
337
|
case Model.ColumnType.Time:
|
|
312
|
-
case Model.ColumnType.Date:
|
|
313
338
|
case Model.ColumnType.Json:
|
|
314
339
|
// Numeric is transferred as a string to avoid JS float precision loss.
|
|
315
340
|
case Model.ColumnType.Numeric:
|
|
316
341
|
return column.list ? listType(Typesafe.array(Typesafe.string)) : Typesafe.string;
|
|
342
|
+
case Model.ColumnType.Date:
|
|
343
|
+
case Model.ColumnType.DateTime:
|
|
344
|
+
return column.list ? listType(Typesafe.array(calendarDate)) : calendarDate;
|
|
317
345
|
case Model.ColumnType.Int:
|
|
318
346
|
case Model.ColumnType.Double:
|
|
319
347
|
return column.list ? listType(Typesafe.array(Typesafe.number)) : Typesafe.number;
|