@contember/engine-http 2.0.0-alpha.12 → 2.0.0-alpha.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/development/src/MasterContainer.cjs +1 -1
- package/dist/development/src/MasterContainer.js +1 -1
- package/dist/development/src/content/ContentApiControllerFactory.cjs +3 -1
- package/dist/development/src/content/ContentApiControllerFactory.cjs.map +1 -1
- package/dist/development/src/content/ContentApiControllerFactory.js +3 -1
- package/dist/development/src/content/ContentApiControllerFactory.js.map +1 -1
- package/dist/development/src/content/ContentGraphQLContextFactory.cjs +2 -1
- package/dist/development/src/content/ContentGraphQLContextFactory.cjs.map +1 -1
- package/dist/development/src/content/ContentGraphQLContextFactory.js +2 -1
- package/dist/development/src/content/ContentGraphQLContextFactory.js.map +1 -1
- package/dist/development/src/content/ContentSchemaResolver.cjs +27 -17
- package/dist/development/src/content/ContentSchemaResolver.cjs.map +1 -1
- package/dist/development/src/content/ContentSchemaResolver.js +28 -18
- package/dist/development/src/content/ContentSchemaResolver.js.map +1 -1
- package/dist/development/src/project/ProjectContainer.cjs +5 -5
- package/dist/development/src/project/ProjectContainer.cjs.map +1 -1
- package/dist/development/src/project/ProjectContainer.js +5 -5
- package/dist/development/src/project/ProjectContainer.js.map +1 -1
- package/dist/development/src/project/ProjectSchemaResolver.cjs +2 -2
- package/dist/development/src/project/ProjectSchemaResolver.cjs.map +1 -1
- package/dist/development/src/project/ProjectSchemaResolver.js +2 -2
- package/dist/development/src/project/ProjectSchemaResolver.js.map +1 -1
- package/dist/development/src/projectGroup/ProjectGroupContainer.cjs +2 -2
- package/dist/development/src/projectGroup/ProjectGroupContainer.cjs.map +1 -1
- package/dist/development/src/projectGroup/ProjectGroupContainer.js +2 -2
- package/dist/development/src/projectGroup/ProjectGroupContainer.js.map +1 -1
- package/dist/development/src/system/ContentQueryExecutor.cjs +2 -1
- package/dist/development/src/system/ContentQueryExecutor.cjs.map +1 -1
- package/dist/development/src/system/ContentQueryExecutor.js +2 -1
- package/dist/development/src/system/ContentQueryExecutor.js.map +1 -1
- package/dist/development/src/system/SystemGraphQLContextFactory.cjs +9 -8
- package/dist/development/src/system/SystemGraphQLContextFactory.cjs.map +1 -1
- package/dist/development/src/system/SystemGraphQLContextFactory.js +9 -8
- package/dist/development/src/system/SystemGraphQLContextFactory.js.map +1 -1
- package/dist/development/src/transfer/ContentSchemaTransferMappingFactory.cjs.map +1 -1
- package/dist/development/src/transfer/ContentSchemaTransferMappingFactory.js.map +1 -1
- package/dist/development/src/transfer/ExportApiControllerFactory.cjs +3 -1
- package/dist/development/src/transfer/ExportApiControllerFactory.cjs.map +1 -1
- package/dist/development/src/transfer/ExportApiControllerFactory.js +3 -1
- package/dist/development/src/transfer/ExportApiControllerFactory.js.map +1 -1
- package/dist/development/src/transfer/ExportExecutor.cjs +3 -3
- package/dist/development/src/transfer/ExportExecutor.cjs.map +1 -1
- package/dist/development/src/transfer/ExportExecutor.js +3 -3
- package/dist/development/src/transfer/ExportExecutor.js.map +1 -1
- package/dist/development/src/transfer/ImportExecutor.cjs +5 -5
- package/dist/development/src/transfer/ImportExecutor.cjs.map +1 -1
- package/dist/development/src/transfer/ImportExecutor.js +5 -5
- package/dist/development/src/transfer/ImportExecutor.js.map +1 -1
- package/dist/production/src/MasterContainer.cjs +1 -1
- package/dist/production/src/MasterContainer.js +1 -1
- package/dist/production/src/content/ContentApiControllerFactory.cjs +3 -1
- package/dist/production/src/content/ContentApiControllerFactory.cjs.map +1 -1
- package/dist/production/src/content/ContentApiControllerFactory.js +3 -1
- package/dist/production/src/content/ContentApiControllerFactory.js.map +1 -1
- package/dist/production/src/content/ContentGraphQLContextFactory.cjs +2 -1
- package/dist/production/src/content/ContentGraphQLContextFactory.cjs.map +1 -1
- package/dist/production/src/content/ContentGraphQLContextFactory.js +2 -1
- package/dist/production/src/content/ContentGraphQLContextFactory.js.map +1 -1
- package/dist/production/src/content/ContentSchemaResolver.cjs +27 -17
- package/dist/production/src/content/ContentSchemaResolver.cjs.map +1 -1
- package/dist/production/src/content/ContentSchemaResolver.js +28 -18
- package/dist/production/src/content/ContentSchemaResolver.js.map +1 -1
- package/dist/production/src/project/ProjectContainer.cjs +5 -5
- package/dist/production/src/project/ProjectContainer.cjs.map +1 -1
- package/dist/production/src/project/ProjectContainer.js +5 -5
- package/dist/production/src/project/ProjectContainer.js.map +1 -1
- package/dist/production/src/project/ProjectSchemaResolver.cjs +2 -2
- package/dist/production/src/project/ProjectSchemaResolver.cjs.map +1 -1
- package/dist/production/src/project/ProjectSchemaResolver.js +2 -2
- package/dist/production/src/project/ProjectSchemaResolver.js.map +1 -1
- package/dist/production/src/projectGroup/ProjectGroupContainer.cjs +2 -2
- package/dist/production/src/projectGroup/ProjectGroupContainer.cjs.map +1 -1
- package/dist/production/src/projectGroup/ProjectGroupContainer.js +2 -2
- package/dist/production/src/projectGroup/ProjectGroupContainer.js.map +1 -1
- package/dist/production/src/system/ContentQueryExecutor.cjs +2 -1
- package/dist/production/src/system/ContentQueryExecutor.cjs.map +1 -1
- package/dist/production/src/system/ContentQueryExecutor.js +2 -1
- package/dist/production/src/system/ContentQueryExecutor.js.map +1 -1
- package/dist/production/src/system/SystemGraphQLContextFactory.cjs +9 -8
- package/dist/production/src/system/SystemGraphQLContextFactory.cjs.map +1 -1
- package/dist/production/src/system/SystemGraphQLContextFactory.js +9 -8
- package/dist/production/src/system/SystemGraphQLContextFactory.js.map +1 -1
- package/dist/production/src/transfer/ContentSchemaTransferMappingFactory.cjs.map +1 -1
- package/dist/production/src/transfer/ContentSchemaTransferMappingFactory.js.map +1 -1
- package/dist/production/src/transfer/ExportApiControllerFactory.cjs +3 -1
- package/dist/production/src/transfer/ExportApiControllerFactory.cjs.map +1 -1
- package/dist/production/src/transfer/ExportApiControllerFactory.js +3 -1
- package/dist/production/src/transfer/ExportApiControllerFactory.js.map +1 -1
- package/dist/production/src/transfer/ExportExecutor.cjs +3 -3
- package/dist/production/src/transfer/ExportExecutor.cjs.map +1 -1
- package/dist/production/src/transfer/ExportExecutor.js +3 -3
- package/dist/production/src/transfer/ExportExecutor.js.map +1 -1
- package/dist/production/src/transfer/ImportExecutor.cjs +5 -5
- package/dist/production/src/transfer/ImportExecutor.cjs.map +1 -1
- package/dist/production/src/transfer/ImportExecutor.js +5 -5
- package/dist/production/src/transfer/ImportExecutor.js.map +1 -1
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/dist/types/content/ContentApiControllerFactory.d.ts.map +1 -1
- package/dist/types/content/ContentGraphQLContextFactory.d.ts +4 -3
- package/dist/types/content/ContentGraphQLContextFactory.d.ts.map +1 -1
- package/dist/types/content/ContentSchemaResolver.d.ts +8 -5
- package/dist/types/content/ContentSchemaResolver.d.ts.map +1 -1
- package/dist/types/project/ProjectContainer.d.ts +4 -4
- package/dist/types/project/ProjectContainer.d.ts.map +1 -1
- package/dist/types/project/ProjectSchemaResolver.d.ts +1 -1
- package/dist/types/project/ProjectSchemaResolver.d.ts.map +1 -1
- package/dist/types/projectGroup/ProjectGroupContainer.d.ts +1 -1
- package/dist/types/projectGroup/ProjectGroupContainer.d.ts.map +1 -1
- package/dist/types/system/ContentQueryExecutor.d.ts +1 -1
- package/dist/types/system/ContentQueryExecutor.d.ts.map +1 -1
- package/dist/types/system/SystemGraphQLContextFactory.d.ts.map +1 -1
- package/dist/types/transfer/ContentSchemaTransferMappingFactory.d.ts +2 -2
- package/dist/types/transfer/ContentSchemaTransferMappingFactory.d.ts.map +1 -1
- package/dist/types/transfer/ExportApiControllerFactory.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +15 -15
- package/src/content/ContentApiControllerFactory.ts +3 -2
- package/src/content/ContentGraphQLContextFactory.ts +4 -2
- package/src/content/ContentSchemaResolver.ts +32 -16
- package/src/project/ProjectContainer.ts +6 -6
- package/src/project/ProjectSchemaResolver.ts +3 -3
- package/src/projectGroup/ProjectGroupContainer.ts +15 -7
- package/src/system/ContentQueryExecutor.ts +2 -1
- package/src/system/SystemGraphQLContextFactory.ts +8 -7
- package/src/transfer/ContentSchemaTransferMappingFactory.ts +2 -3
- package/src/transfer/ExportApiControllerFactory.ts +3 -1
- package/src/transfer/ExportExecutor.ts +3 -3
- package/src/transfer/ImportExecutor.ts +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProjectSchemaResolver.js","sources":["../../../../../packages/engine-http/src/project/ProjectSchemaResolver.ts"],"sourcesContent":["import { ProjectSchemaResolver as ProjectSchemaResolverInterface } from '@contember/engine-tenant-api'\nimport { Schema } from '@contember/schema'\nimport { ProjectContainerResolver } from './ProjectContainerResolver'\n\nexport class ProjectSchemaResolver implements ProjectSchemaResolverInterface {\n\tconstructor(\n\t\tprivate readonly projectContainerResolver: ProjectContainerResolver,\n\t) {}\n\n\tasync getSchema(slug: string) {\n\t\tconst container = await this.projectContainerResolver.getProjectContainer(slug)\n\t\tif (!container) {\n\t\t\treturn undefined\n\t\t}\n\t\tconst db = container.systemReadDatabaseContext\n\t\treturn container.contentSchemaResolver.getSchema(db)\n\t}\n}\n\nexport class ProjectSchemaResolverProxy implements ProjectSchemaResolverInterface {\n\tprivate resolver: ProjectSchemaResolver | undefined\n\n\tsetResolver(resolver: ProjectSchemaResolver): void {\n\t\tthis.resolver = resolver\n\t}\n\n\
|
|
1
|
+
{"version":3,"file":"ProjectSchemaResolver.js","sources":["../../../../../packages/engine-http/src/project/ProjectSchemaResolver.ts"],"sourcesContent":["import { ProjectSchemaResolver as ProjectSchemaResolverInterface } from '@contember/engine-tenant-api'\nimport { Schema } from '@contember/schema'\nimport { ProjectContainerResolver } from './ProjectContainerResolver'\n\nexport class ProjectSchemaResolver implements ProjectSchemaResolverInterface {\n\tconstructor(\n\t\tprivate readonly projectContainerResolver: ProjectContainerResolver,\n\t) {}\n\n\tasync getSchema(slug: string): Promise<Schema | undefined> {\n\t\tconst container = await this.projectContainerResolver.getProjectContainer(slug)\n\t\tif (!container) {\n\t\t\treturn undefined\n\t\t}\n\t\tconst db = container.systemReadDatabaseContext\n\t\treturn (await container.contentSchemaResolver.getSchema({ db, normalize: true }))?.schema\n\t}\n}\n\nexport class ProjectSchemaResolverProxy implements ProjectSchemaResolverInterface {\n\tprivate resolver: ProjectSchemaResolver | undefined\n\n\tsetResolver(resolver: ProjectSchemaResolver): void {\n\t\tthis.resolver = resolver\n\t}\n\n\tasync getSchema(projectSlug: string): Promise<Schema | undefined> {\n\t\tif (!this.resolver) {\n\t\t\tthrow new Error('Resolved is not set')\n\t\t}\n\t\treturn this.resolver.getSchema(projectSlug)\n\t}\n}\n"],"names":[],"mappings":";;;AAIO,MAAM,sBAAgE;AAAA,EAC5E,YACkB,0BAChB;AADgB,SAAA,2BAAA;AAAA,EACf;AAAA,EAEH,MAAM,UAAU,MAA2C;AAC1D,UAAM,YAAY,MAAM,KAAK,yBAAyB,oBAAoB,IAAI;AAC9E,QAAI,CAAC,WAAW;AACR,aAAA;AAAA,IACR;AACA,UAAM,KAAK,UAAU;AACb,YAAA,MAAM,UAAU,sBAAsB,UAAU,EAAE,IAAI,WAAW,MAAM,IAAI;AAAA,EACpF;AACD;AAEO,MAAM,2BAAqE;AAAA,EAA3E,cAAA;AACE,kBAAA,MAAA,UAAA;AAAA,EAAA;AAAA,EAER,YAAY,UAAuC;AAClD,SAAK,WAAW;AAAA,EACjB;AAAA,EAEA,MAAM,UAAU,aAAkD;AAC7D,QAAA,CAAC,KAAK,UAAU;AACb,YAAA,IAAI,MAAM,qBAAqB;AAAA,IACtC;AACO,WAAA,KAAK,SAAS,UAAU,WAAW;AAAA,EAC3C;AACD;"}
|
|
@@ -12,7 +12,7 @@ require("lru-cache");
|
|
|
12
12
|
const crypto = require("node:crypto");
|
|
13
13
|
require("@contember/logger");
|
|
14
14
|
require("@contember/graphql-utils");
|
|
15
|
-
require("
|
|
15
|
+
require("../content/ContentSchemaResolver.cjs");
|
|
16
16
|
const ProjectMembershipFetcher = require("../content/ProjectMembershipFetcher.cjs");
|
|
17
17
|
const ProjectMembershipResolver = require("../content/ProjectMembershipResolver.cjs");
|
|
18
18
|
require("node:timers");
|
|
@@ -59,7 +59,7 @@ class ProjectGroupContainerFactory {
|
|
|
59
59
|
encrypt: cryptoWrapper.encrypt.bind(cryptoWrapper)
|
|
60
60
|
}
|
|
61
61
|
});
|
|
62
|
-
}).addService("tenantDatabase", ({ tenantContainer }) => tenantContainer.databaseContext).addService("tenantReadDatabase", ({ tenantContainer }) => tenantContainer.readDatabaseContext).addService("identityFetcher", ({ tenantContainer: { identityFetcher } }) => identityFetcher).addService("systemContainer", ({ identityFetcher }) => this.systemContainerFactory.create({ identityFetcher })).addService("
|
|
62
|
+
}).addService("tenantDatabase", ({ tenantContainer }) => tenantContainer.databaseContext).addService("tenantReadDatabase", ({ tenantContainer }) => tenantContainer.readDatabaseContext).addService("identityFetcher", ({ tenantContainer: { identityFetcher } }) => identityFetcher).addService("systemContainer", ({ identityFetcher }) => this.systemContainerFactory.create({ identityFetcher })).addService("schemaProvider", ({ systemContainer }) => systemContainer.schemaProvider).addService("projectContainerFactory", ({ schemaProvider, logger }) => this.projectContainerFactoryFactory.create(schemaProvider, logger)).addService("tenantProjectManager", ({ tenantContainer }) => tenantContainer.projectManager).addService("tenantProjectMemberManager", ({ tenantContainer }) => tenantContainer.projectMemberManager).addService("projectContainerResolver", ({ projectContainerFactory, tenantProjectManager, tenantReadDatabase }) => new ProjectContainerResolver.ProjectContainerResolver(
|
|
63
63
|
projectContainerFactory,
|
|
64
64
|
this.projectConfigResolver,
|
|
65
65
|
tenantProjectManager,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProjectGroupContainer.cjs","sources":["../../../../../packages/engine-http/src/projectGroup/ProjectGroupContainer.ts"],"sourcesContent":["import { Builder } from '@contember/dic'\nimport { Connection } from '@contember/database'\nimport { DatabaseContext, TenantContainer, TenantContainerFactory, ProjectSchemaResolver as ProjectSchemaResolverInterface, ProjectInitializer as ProjectInitializerInterface } from '@contember/engine-tenant-api'\nimport { TenantConfig } from '../config/config'\nimport {\n\tProjectContainerFactoryFactory, ProjectContainerResolver, ProjectInitializer,\n\tProjectInitializerProxy, ProjectSchemaResolver,\n\tProjectSchemaResolverProxy,\n} from '../project'\nimport { SystemContainer, SystemContainerFactory } from '@contember/engine-system-api'\nimport { ProjectConfigResolver } from '../config/projectConfigResolver'\nimport { createSecretKey } from 'node:crypto'\nimport { Logger } from '@contember/logger'\nimport { TenantGraphQLHandler, TenantGraphQLHandlerFactory } from '../tenant'\nimport { SystemGraphQLHandler, SystemGraphQLHandlerFactory } from '../system'\nimport { Authenticator } from '../common'\nimport { ProjectMembershipFetcher, ProjectMembershipResolver } from '../content'\nimport { Providers } from '../providers'\nimport { CryptoWrapper } from '../utils/CryptoWrapper'\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\n\ninterface ProjectGroupContainerFactoryArgs\n{\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) {}\n\n\tpublic create({ config, slug }: ProjectGroupContainerFactoryArgs): ProjectGroupContainer {\n\t\treturn new Builder({})\n\t\t\t.addService('slug', () =>\n\t\t\t\tslug)\n\t\t\t.addService('logger', ({ slug }) =>\n\t\t\t\tthis.logger.child({ projectGroup: slug }))\n\t\t\t.addService('providers', () =>\n\t\t\t\tthis.providers)\n\t\t\t.addService('tenantDbCredentials', () =>\n\t\t\t\tconfig.db)\n\t\t\t.addService('tenantConnection', ({ tenantDbCredentials, logger }): Connection.ConnectionType =>\n\t\t\t\tConnection.create(tenantDbCredentials, err => logger.error(err)))\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...tenantDbCredentials,\n\t\t\t\t\t...tenantDbCredentials.read,\n\t\t\t\t\tpool: {\n\t\t\t\t\t\t...tenantDbCredentials.pool,\n\t\t\t\t\t\t...tenantDbCredentials.read.pool,\n\t\t\t\t\t},\n\t\t\t\t}, err => logger.error(err))\n\t\t\t})\n\t\t\t.addService('projectSchemaResolver', () =>\n\t\t\t\tnew ProjectSchemaResolverProxy())\n\t\t\t.addService('projectInitializer', () =>\n\t\t\t\tnew ProjectInitializerProxy())\n\t\t\t.addService('tenantContainer', ({ tenantConnection, tenantReadConnection, tenantDbCredentials, projectSchemaResolver, projectInitializer }) => {\n\t\t\t\tconst encryptionKey = config.secrets.encryptionKey\n\t\t\t\t\t? createSecretKey(Buffer.from(config.secrets.encryptionKey, 'hex'))\n\t\t\t\t\t: undefined\n\n\t\t\t\tconst cryptoWrapper = new CryptoWrapper(encryptionKey)\n\t\t\t\treturn this.tenantContainerFactory.create({\n\t\t\t\t\tconnection: tenantConnection,\n\t\t\t\t\treadConnection: tenantReadConnection,\n\t\t\t\t\tdbCredentials: tenantDbCredentials,\n\t\t\t\t\tmailOptions: config.mailer,\n\t\t\t\t\ttenantCredentials: config.credentials,\n\t\t\t\t\tprojectInitializer,\n\t\t\t\t\tprojectSchemaResolver,\n\t\t\t\t\tcryptoProviders: {\n\t\t\t\t\t\tdecrypt: cryptoWrapper.decrypt.bind(cryptoWrapper),\n\t\t\t\t\t\tencrypt: cryptoWrapper.encrypt.bind(cryptoWrapper),\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t})\n\t\t\t.addService('tenantDatabase', ({ tenantContainer }) =>\n\t\t\t\ttenantContainer.databaseContext)\n\t\t\t.addService('tenantReadDatabase', ({ tenantContainer }) =>\n\t\t\t\ttenantContainer.readDatabaseContext)\n\t\t\t.addService('identityFetcher', ({ tenantContainer: { identityFetcher } }) =>\n\t\t\t\tidentityFetcher)\n\t\t\t.addService('systemContainer', ({ identityFetcher }) =>\n\t\t\t\tthis.systemContainerFactory.create({ identityFetcher }))\n\t\t\t.addService('schemaVersionBuilder', ({ systemContainer }) =>\n\t\t\t\tsystemContainer.schemaVersionBuilder)\n\t\t\t.addService('projectContainerFactory', ({ schemaVersionBuilder, logger }) =>\n\t\t\t\tthis.projectContainerFactoryFactory.create(schemaVersionBuilder, logger))\n\t\t\t.addService('tenantProjectManager', ({ tenantContainer }) =>\n\t\t\t\ttenantContainer.projectManager)\n\t\t\t.addService('tenantProjectMemberManager', ({ tenantContainer }) =>\n\t\t\t\ttenantContainer.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\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 }) =>\n\t\t\t\tthis.tenantGraphQLHandlerFactory.create(tenantContainer.resolvers))\n\t\t\t.addService('systemGraphQLHandler', ({ systemContainer }) =>\n\t\t\t\tthis.systemGraphQLHandlerFactory.create(systemContainer.systemResolversFactory))\n\t\t\t.addService('authenticator', ({ tenantDatabase, tenantReadDatabase, tenantContainer }) =>\n\t\t\t\tnew Authenticator(tenantDatabase, tenantReadDatabase, tenantContainer.apiKeyManager))\n\t\t\t.addService('projectMembershipResolver', ({ tenantProjectMemberManager, tenantReadDatabase }) =>\n\t\t\t\tnew ProjectMembershipResolver(this.debug, new ProjectMembershipFetcher(tenantProjectMemberManager, tenantReadDatabase)))\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":["Builder","slug","Connection","ProjectSchemaResolverProxy","ProjectInitializerProxy","createSecretKey","CryptoWrapper","ProjectContainerResolver","ProjectSchemaResolver","ProjectInitializer","Authenticator","ProjectMembershipResolver","ProjectMembershipFetcher"],"mappings":";;;;;;;;;;;;;;;;;;;;AA6CO,MAAM,6BAA6B;AAAA,EACzC,YACkB,OACA,WACA,wBACA,wBACA,gCACA,uBACA,6BACA,6BACA,QAChB;AATgB,SAAA,QAAA;AACA,SAAA,YAAA;AACA,SAAA,yBAAA;AACA,SAAA,yBAAA;AACA,SAAA,iCAAA;AACA,SAAA,wBAAA;AACA,SAAA,8BAAA;AACA,SAAA,8BAAA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E,sBACtC,KAAK,4BAA4B,OAAO,gBAAgB,sBAAsB,CAAC,EAC/E,WAAW,iBAAiB,CAAC,EAAE,gBAAgB,oBAAoB,gBAAA,MACnE,IAAIC,aAAAA,cAAc,gBAAgB,oBAAoB,gBAAgB,aAAa,CAAC,EACpF,WAAW,6BAA6B,CAAC,EAAE,4BAA4B,yBACvE,IAAIC,oDAA0B,KAAK,OAAO,IAAIC,kDAAyB,4BAA4B,kBAAkB,CAAC,CAAC,EACvH,MACA,EAAA;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.cjs","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'\nimport {\n\tProjectContainerFactoryFactory,\n\tProjectContainerResolver,\n\tProjectInitializer,\n\tProjectInitializerProxy,\n\tProjectSchemaResolver,\n\tProjectSchemaResolverProxy,\n} from '../project'\nimport { SystemContainer, SystemContainerFactory } from '@contember/engine-system-api'\nimport { ProjectConfigResolver } from '../config/projectConfigResolver'\nimport { createSecretKey } from 'node:crypto'\nimport { Logger } from '@contember/logger'\nimport { TenantGraphQLHandler, TenantGraphQLHandlerFactory } from '../tenant'\nimport { SystemGraphQLHandler, SystemGraphQLHandlerFactory } from '../system'\nimport { Authenticator } from '../common'\nimport { ProjectMembershipFetcher, ProjectMembershipResolver } from '../content'\nimport { Providers } from '../providers'\nimport { CryptoWrapper } from '../utils/CryptoWrapper'\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\n\ninterface ProjectGroupContainerFactoryArgs\n{\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) {}\n\n\tpublic create({ config, slug }: ProjectGroupContainerFactoryArgs): ProjectGroupContainer {\n\t\treturn new Builder({})\n\t\t\t.addService('slug', () =>\n\t\t\t\tslug)\n\t\t\t.addService('logger', ({ slug }) =>\n\t\t\t\tthis.logger.child({ projectGroup: slug }))\n\t\t\t.addService('providers', () =>\n\t\t\t\tthis.providers)\n\t\t\t.addService('tenantDbCredentials', () =>\n\t\t\t\tconfig.db)\n\t\t\t.addService('tenantConnection', ({ tenantDbCredentials, logger }): Connection.ConnectionType =>\n\t\t\t\tConnection.create(tenantDbCredentials, err => logger.error(err)))\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...tenantDbCredentials,\n\t\t\t\t\t...tenantDbCredentials.read,\n\t\t\t\t\tpool: {\n\t\t\t\t\t\t...tenantDbCredentials.pool,\n\t\t\t\t\t\t...tenantDbCredentials.read.pool,\n\t\t\t\t\t},\n\t\t\t\t}, err => logger.error(err))\n\t\t\t})\n\t\t\t.addService('projectSchemaResolver', () =>\n\t\t\t\tnew ProjectSchemaResolverProxy())\n\t\t\t.addService('projectInitializer', () =>\n\t\t\t\tnew ProjectInitializerProxy())\n\t\t\t.addService('tenantContainer', ({ tenantConnection, tenantReadConnection, tenantDbCredentials, projectSchemaResolver, projectInitializer }) => {\n\t\t\t\tconst encryptionKey = config.secrets.encryptionKey\n\t\t\t\t\t? createSecretKey(Buffer.from(config.secrets.encryptionKey, 'hex'))\n\t\t\t\t\t: undefined\n\n\t\t\t\tconst cryptoWrapper = new CryptoWrapper(encryptionKey)\n\t\t\t\treturn this.tenantContainerFactory.create({\n\t\t\t\t\tconnection: tenantConnection,\n\t\t\t\t\treadConnection: tenantReadConnection,\n\t\t\t\t\tdbCredentials: tenantDbCredentials,\n\t\t\t\t\tmailOptions: config.mailer,\n\t\t\t\t\ttenantCredentials: config.credentials,\n\t\t\t\t\tprojectInitializer,\n\t\t\t\t\tprojectSchemaResolver,\n\t\t\t\t\tcryptoProviders: {\n\t\t\t\t\t\tdecrypt: cryptoWrapper.decrypt.bind(cryptoWrapper),\n\t\t\t\t\t\tencrypt: cryptoWrapper.encrypt.bind(cryptoWrapper),\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t})\n\t\t\t.addService('tenantDatabase', ({ tenantContainer }) =>\n\t\t\t\ttenantContainer.databaseContext)\n\t\t\t.addService('tenantReadDatabase', ({ tenantContainer }) =>\n\t\t\t\ttenantContainer.readDatabaseContext)\n\t\t\t.addService('identityFetcher', ({ tenantContainer: { identityFetcher } }) =>\n\t\t\t\tidentityFetcher)\n\t\t\t.addService('systemContainer', ({ identityFetcher }) =>\n\t\t\t\tthis.systemContainerFactory.create({ identityFetcher }))\n\t\t\t.addService('schemaProvider', ({ systemContainer }) =>\n\t\t\t\tsystemContainer.schemaProvider)\n\t\t\t.addService('projectContainerFactory', ({ schemaProvider, logger }) =>\n\t\t\t\tthis.projectContainerFactoryFactory.create(schemaProvider, logger))\n\t\t\t.addService('tenantProjectManager', ({ tenantContainer }) =>\n\t\t\t\ttenantContainer.projectManager)\n\t\t\t.addService('tenantProjectMemberManager', ({ tenantContainer }) =>\n\t\t\t\ttenantContainer.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\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 }) =>\n\t\t\t\tthis.tenantGraphQLHandlerFactory.create(tenantContainer.resolvers))\n\t\t\t.addService('systemGraphQLHandler', ({ systemContainer }) =>\n\t\t\t\tthis.systemGraphQLHandlerFactory.create(systemContainer.systemResolversFactory))\n\t\t\t.addService('authenticator', ({ tenantDatabase, tenantReadDatabase, tenantContainer }) =>\n\t\t\t\tnew Authenticator(tenantDatabase, tenantReadDatabase, tenantContainer.apiKeyManager))\n\t\t\t.addService('projectMembershipResolver', ({ tenantProjectMemberManager, tenantReadDatabase }) =>\n\t\t\t\tnew ProjectMembershipResolver(this.debug, new ProjectMembershipFetcher(tenantProjectMemberManager, tenantReadDatabase)))\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":["Builder","slug","Connection","ProjectSchemaResolverProxy","ProjectInitializerProxy","createSecretKey","CryptoWrapper","ProjectContainerResolver","ProjectSchemaResolver","ProjectInitializer","Authenticator","ProjectMembershipResolver","ProjectMembershipFetcher"],"mappings":";;;;;;;;;;;;;;;;;;;;AAqDO,MAAM,6BAA6B;AAAA,EACzC,YACkB,OACA,WACA,wBACA,wBACA,gCACA,uBACA,6BACA,6BACA,QAChB;AATgB,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;AAAA,EACf;AAAA,EAEI,OAAO,EAAE,QAAQ,QAAiE;AACxF,WAAO,IAAIA,IAAA,QAAQ,EAAE,EACnB,WAAW,QAAQ,MACnB,IAAI,EACJ,WAAW,UAAU,CAAC,EAAE,MAAAC,YACxB,KAAK,OAAO,MAAM,EAAE,cAAcA,MAAK,CAAC,CAAC,EACzC,WAAW,aAAa,MACxB,KAAK,SAAS,EACd,WAAW,uBAAuB,MAClC,OAAO,EAAE,EACT,WAAW,oBAAoB,CAAC,EAAE,qBAAqB,aACvDC,SAAAA,WAAW,OAAO,qBAAqB,CAAA,QAAO,OAAO,MAAM,GAAG,CAAC,CAAC,EAChE,WAAW,wBAAwB,CAAC,EAAE,qBAAqB,QAAQ,uBAAuB;AACtF,UAAA,CAAC,oBAAoB,MAAM;AACvB,eAAA;A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} from "node:crypto";
|
|
11
11
|
import "@contember/logger";
|
|
12
12
|
import "@contember/graphql-utils";
|
|
13
|
-
import "
|
|
13
|
+
import "../content/ContentSchemaResolver.js";
|
|
14
14
|
import { ProjectMembershipFetcher } from "../content/ProjectMembershipFetcher.js";
|
|
15
15
|
import { ProjectMembershipResolver } from "../content/ProjectMembershipResolver.js";
|
|
16
16
|
import "node:timers";
|
|
@@ -57,7 +57,7 @@ class ProjectGroupContainerFactory {
|
|
|
57
57
|
encrypt: cryptoWrapper.encrypt.bind(cryptoWrapper)
|
|
58
58
|
}
|
|
59
59
|
});
|
|
60
|
-
}).addService("tenantDatabase", ({ tenantContainer }) => tenantContainer.databaseContext).addService("tenantReadDatabase", ({ tenantContainer }) => tenantContainer.readDatabaseContext).addService("identityFetcher", ({ tenantContainer: { identityFetcher } }) => identityFetcher).addService("systemContainer", ({ identityFetcher }) => this.systemContainerFactory.create({ identityFetcher })).addService("
|
|
60
|
+
}).addService("tenantDatabase", ({ tenantContainer }) => tenantContainer.databaseContext).addService("tenantReadDatabase", ({ tenantContainer }) => tenantContainer.readDatabaseContext).addService("identityFetcher", ({ tenantContainer: { identityFetcher } }) => identityFetcher).addService("systemContainer", ({ identityFetcher }) => this.systemContainerFactory.create({ identityFetcher })).addService("schemaProvider", ({ systemContainer }) => systemContainer.schemaProvider).addService("projectContainerFactory", ({ schemaProvider, logger }) => this.projectContainerFactoryFactory.create(schemaProvider, logger)).addService("tenantProjectManager", ({ tenantContainer }) => tenantContainer.projectManager).addService("tenantProjectMemberManager", ({ tenantContainer }) => tenantContainer.projectMemberManager).addService("projectContainerResolver", ({ projectContainerFactory, tenantProjectManager, tenantReadDatabase }) => new ProjectContainerResolver(
|
|
61
61
|
projectContainerFactory,
|
|
62
62
|
this.projectConfigResolver,
|
|
63
63
|
tenantProjectManager,
|
|
@@ -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 { DatabaseContext, TenantContainer, TenantContainerFactory, ProjectSchemaResolver as ProjectSchemaResolverInterface, ProjectInitializer as ProjectInitializerInterface } from '@contember/engine-tenant-api'\nimport { TenantConfig } from '../config/config'\nimport {\n\tProjectContainerFactoryFactory, ProjectContainerResolver, ProjectInitializer,\n\tProjectInitializerProxy, ProjectSchemaResolver,\n\tProjectSchemaResolverProxy,\n} from '../project'\nimport { SystemContainer, SystemContainerFactory } from '@contember/engine-system-api'\nimport { ProjectConfigResolver } from '../config/projectConfigResolver'\nimport { createSecretKey } from 'node:crypto'\nimport { Logger } from '@contember/logger'\nimport { TenantGraphQLHandler, TenantGraphQLHandlerFactory } from '../tenant'\nimport { SystemGraphQLHandler, SystemGraphQLHandlerFactory } from '../system'\nimport { Authenticator } from '../common'\nimport { ProjectMembershipFetcher, ProjectMembershipResolver } from '../content'\nimport { Providers } from '../providers'\nimport { CryptoWrapper } from '../utils/CryptoWrapper'\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\n\ninterface ProjectGroupContainerFactoryArgs\n{\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) {}\n\n\tpublic create({ config, slug }: ProjectGroupContainerFactoryArgs): ProjectGroupContainer {\n\t\treturn new Builder({})\n\t\t\t.addService('slug', () =>\n\t\t\t\tslug)\n\t\t\t.addService('logger', ({ slug }) =>\n\t\t\t\tthis.logger.child({ projectGroup: slug }))\n\t\t\t.addService('providers', () =>\n\t\t\t\tthis.providers)\n\t\t\t.addService('tenantDbCredentials', () =>\n\t\t\t\tconfig.db)\n\t\t\t.addService('tenantConnection', ({ tenantDbCredentials, logger }): Connection.ConnectionType =>\n\t\t\t\tConnection.create(tenantDbCredentials, err => logger.error(err)))\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...tenantDbCredentials,\n\t\t\t\t\t...tenantDbCredentials.read,\n\t\t\t\t\tpool: {\n\t\t\t\t\t\t...tenantDbCredentials.pool,\n\t\t\t\t\t\t...tenantDbCredentials.read.pool,\n\t\t\t\t\t},\n\t\t\t\t}, err => logger.error(err))\n\t\t\t})\n\t\t\t.addService('projectSchemaResolver', () =>\n\t\t\t\tnew ProjectSchemaResolverProxy())\n\t\t\t.addService('projectInitializer', () =>\n\t\t\t\tnew ProjectInitializerProxy())\n\t\t\t.addService('tenantContainer', ({ tenantConnection, tenantReadConnection, tenantDbCredentials, projectSchemaResolver, projectInitializer }) => {\n\t\t\t\tconst encryptionKey = config.secrets.encryptionKey\n\t\t\t\t\t? createSecretKey(Buffer.from(config.secrets.encryptionKey, 'hex'))\n\t\t\t\t\t: undefined\n\n\t\t\t\tconst cryptoWrapper = new CryptoWrapper(encryptionKey)\n\t\t\t\treturn this.tenantContainerFactory.create({\n\t\t\t\t\tconnection: tenantConnection,\n\t\t\t\t\treadConnection: tenantReadConnection,\n\t\t\t\t\tdbCredentials: tenantDbCredentials,\n\t\t\t\t\tmailOptions: config.mailer,\n\t\t\t\t\ttenantCredentials: config.credentials,\n\t\t\t\t\tprojectInitializer,\n\t\t\t\t\tprojectSchemaResolver,\n\t\t\t\t\tcryptoProviders: {\n\t\t\t\t\t\tdecrypt: cryptoWrapper.decrypt.bind(cryptoWrapper),\n\t\t\t\t\t\tencrypt: cryptoWrapper.encrypt.bind(cryptoWrapper),\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t})\n\t\t\t.addService('tenantDatabase', ({ tenantContainer }) =>\n\t\t\t\ttenantContainer.databaseContext)\n\t\t\t.addService('tenantReadDatabase', ({ tenantContainer }) =>\n\t\t\t\ttenantContainer.readDatabaseContext)\n\t\t\t.addService('identityFetcher', ({ tenantContainer: { identityFetcher } }) =>\n\t\t\t\tidentityFetcher)\n\t\t\t.addService('systemContainer', ({ identityFetcher }) =>\n\t\t\t\tthis.systemContainerFactory.create({ identityFetcher }))\n\t\t\t.addService('schemaVersionBuilder', ({ systemContainer }) =>\n\t\t\t\tsystemContainer.schemaVersionBuilder)\n\t\t\t.addService('projectContainerFactory', ({ schemaVersionBuilder, logger }) =>\n\t\t\t\tthis.projectContainerFactoryFactory.create(schemaVersionBuilder, logger))\n\t\t\t.addService('tenantProjectManager', ({ tenantContainer }) =>\n\t\t\t\ttenantContainer.projectManager)\n\t\t\t.addService('tenantProjectMemberManager', ({ tenantContainer }) =>\n\t\t\t\ttenantContainer.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\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 }) =>\n\t\t\t\tthis.tenantGraphQLHandlerFactory.create(tenantContainer.resolvers))\n\t\t\t.addService('systemGraphQLHandler', ({ systemContainer }) =>\n\t\t\t\tthis.systemGraphQLHandlerFactory.create(systemContainer.systemResolversFactory))\n\t\t\t.addService('authenticator', ({ tenantDatabase, tenantReadDatabase, tenantContainer }) =>\n\t\t\t\tnew Authenticator(tenantDatabase, tenantReadDatabase, tenantContainer.apiKeyManager))\n\t\t\t.addService('projectMembershipResolver', ({ tenantProjectMemberManager, tenantReadDatabase }) =>\n\t\t\t\tnew ProjectMembershipResolver(this.debug, new ProjectMembershipFetcher(tenantProjectMemberManager, tenantReadDatabase)))\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":";;;;;;;;;;;;;;;;;;AA6CO,MAAM,6BAA6B;AAAA,EACzC,YACkB,OACA,WACA,wBACA,wBACA,gCACA,uBACA,6BACA,6BACA,QAChB;AATgB,SAAA,QAAA;AACA,SAAA,YAAA;AACA,SAAA,yBAAA;AACA,SAAA,yBAAA;AACA,SAAA,iCAAA;AACA,SAAA,wBAAA;AACA,SAAA,8BA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AsB,CAAC,EAC/E,WAAW,iBAAiB,CAAC,EAAE,gBAAgB,oBAAoB,gBAAA,MACnE,IAAI,cAAc,gBAAgB,oBAAoB,gBAAgB,aAAa,CAAC,EACpF,WAAW,6BAA6B,CAAC,EAAE,4BAA4B,yBACvE,IAAI,0BAA0B,KAAK,OAAO,IAAI,yBAAyB,4BAA4B,kBAAkB,CAAC,CAAC,EACvH,MACA,EAAA;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'\nimport {\n\tProjectContainerFactoryFactory,\n\tProjectContainerResolver,\n\tProjectInitializer,\n\tProjectInitializerProxy,\n\tProjectSchemaResolver,\n\tProjectSchemaResolverProxy,\n} from '../project'\nimport { SystemContainer, SystemContainerFactory } from '@contember/engine-system-api'\nimport { ProjectConfigResolver } from '../config/projectConfigResolver'\nimport { createSecretKey } from 'node:crypto'\nimport { Logger } from '@contember/logger'\nimport { TenantGraphQLHandler, TenantGraphQLHandlerFactory } from '../tenant'\nimport { SystemGraphQLHandler, SystemGraphQLHandlerFactory } from '../system'\nimport { Authenticator } from '../common'\nimport { ProjectMembershipFetcher, ProjectMembershipResolver } from '../content'\nimport { Providers } from '../providers'\nimport { CryptoWrapper } from '../utils/CryptoWrapper'\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\n\ninterface ProjectGroupContainerFactoryArgs\n{\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) {}\n\n\tpublic create({ config, slug }: ProjectGroupContainerFactoryArgs): ProjectGroupContainer {\n\t\treturn new Builder({})\n\t\t\t.addService('slug', () =>\n\t\t\t\tslug)\n\t\t\t.addService('logger', ({ slug }) =>\n\t\t\t\tthis.logger.child({ projectGroup: slug }))\n\t\t\t.addService('providers', () =>\n\t\t\t\tthis.providers)\n\t\t\t.addService('tenantDbCredentials', () =>\n\t\t\t\tconfig.db)\n\t\t\t.addService('tenantConnection', ({ tenantDbCredentials, logger }): Connection.ConnectionType =>\n\t\t\t\tConnection.create(tenantDbCredentials, err => logger.error(err)))\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...tenantDbCredentials,\n\t\t\t\t\t...tenantDbCredentials.read,\n\t\t\t\t\tpool: {\n\t\t\t\t\t\t...tenantDbCredentials.pool,\n\t\t\t\t\t\t...tenantDbCredentials.read.pool,\n\t\t\t\t\t},\n\t\t\t\t}, err => logger.error(err))\n\t\t\t})\n\t\t\t.addService('projectSchemaResolver', () =>\n\t\t\t\tnew ProjectSchemaResolverProxy())\n\t\t\t.addService('projectInitializer', () =>\n\t\t\t\tnew ProjectInitializerProxy())\n\t\t\t.addService('tenantContainer', ({ tenantConnection, tenantReadConnection, tenantDbCredentials, projectSchemaResolver, projectInitializer }) => {\n\t\t\t\tconst encryptionKey = config.secrets.encryptionKey\n\t\t\t\t\t? createSecretKey(Buffer.from(config.secrets.encryptionKey, 'hex'))\n\t\t\t\t\t: undefined\n\n\t\t\t\tconst cryptoWrapper = new CryptoWrapper(encryptionKey)\n\t\t\t\treturn this.tenantContainerFactory.create({\n\t\t\t\t\tconnection: tenantConnection,\n\t\t\t\t\treadConnection: tenantReadConnection,\n\t\t\t\t\tdbCredentials: tenantDbCredentials,\n\t\t\t\t\tmailOptions: config.mailer,\n\t\t\t\t\ttenantCredentials: config.credentials,\n\t\t\t\t\tprojectInitializer,\n\t\t\t\t\tprojectSchemaResolver,\n\t\t\t\t\tcryptoProviders: {\n\t\t\t\t\t\tdecrypt: cryptoWrapper.decrypt.bind(cryptoWrapper),\n\t\t\t\t\t\tencrypt: cryptoWrapper.encrypt.bind(cryptoWrapper),\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t})\n\t\t\t.addService('tenantDatabase', ({ tenantContainer }) =>\n\t\t\t\ttenantContainer.databaseContext)\n\t\t\t.addService('tenantReadDatabase', ({ tenantContainer }) =>\n\t\t\t\ttenantContainer.readDatabaseContext)\n\t\t\t.addService('identityFetcher', ({ tenantContainer: { identityFetcher } }) =>\n\t\t\t\tidentityFetcher)\n\t\t\t.addService('systemContainer', ({ identityFetcher }) =>\n\t\t\t\tthis.systemContainerFactory.create({ identityFetcher }))\n\t\t\t.addService('schemaProvider', ({ systemContainer }) =>\n\t\t\t\tsystemContainer.schemaProvider)\n\t\t\t.addService('projectContainerFactory', ({ schemaProvider, logger }) =>\n\t\t\t\tthis.projectContainerFactoryFactory.create(schemaProvider, logger))\n\t\t\t.addService('tenantProjectManager', ({ tenantContainer }) =>\n\t\t\t\ttenantContainer.projectManager)\n\t\t\t.addService('tenantProjectMemberManager', ({ tenantContainer }) =>\n\t\t\t\ttenantContainer.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\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 }) =>\n\t\t\t\tthis.tenantGraphQLHandlerFactory.create(tenantContainer.resolvers))\n\t\t\t.addService('systemGraphQLHandler', ({ systemContainer }) =>\n\t\t\t\tthis.systemGraphQLHandlerFactory.create(systemContainer.systemResolversFactory))\n\t\t\t.addService('authenticator', ({ tenantDatabase, tenantReadDatabase, tenantContainer }) =>\n\t\t\t\tnew Authenticator(tenantDatabase, tenantReadDatabase, tenantContainer.apiKeyManager))\n\t\t\t.addService('projectMembershipResolver', ({ tenantProjectMemberManager, tenantReadDatabase }) =>\n\t\t\t\tnew ProjectMembershipResolver(this.debug, new ProjectMembershipFetcher(tenantProjectMemberManager, tenantReadDatabase)))\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":";;;;;;;;;;;;;;;;;;AAqDO,MAAM,6BAA6B;AAAA,EACzC,YACkB,OACA,WACA,wBACA,wBACA,gCACA,uBACA,6BACA,6BACA,QAChB;AATgB,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;AAAA,EACf;AAAA,EAEI,OAAO,EAAE,QAAQ,QAAiE;AACxF,WAAO,IAAI,QAAQ,EAAE,EACnB,WAAW,QAAQ,MACnB,IAAI,EACJ,WAAW,UAAU,CAAC,EAAE,MAAAA,YACxB,KAAK,OAAO,MAAM,EAAE,cAAcA,MAAK,CAAC,CAAC,EACzC,WAAW,aAAa,MACxB,KAAK,SAAS,EACd,WAAW,uBAAuB,MAClC,OAAO,EAAE,EACT,WAAW,oBAAoB,CAAC,EAAE,qBAAqB,aACvD,WAAW,OAAO,qBAAqB,CAAA,QAAO,OAAO,MAAM,GAAG,CAAC,CAAC,EAChE,WAAW,wBAAwB,CAAC,EAAE,qBAAqB,QAAQ,uBAAuB;AACtF,UAAA,CAAC,oBAAoB,MAAM;AACvB,eAAA;AAAA,MACR;AACA,aAAO,WAAW,OAAO;AAAA,QACxB,GAAG;AAAA,QACH,GAAG,oBAAoB;AAAA,QACvB,MAAM;AAAA,UACL,GAAG,oBAAoB;AAAA,UACvB,GAAG,oBAAoB,KAAK;AAAA,QAC7B;AAAA,MACE,GAAA,CAAA,QAAO,OAAO,MAAM,GAAG,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yB,sBAAsB,mBAAmB,MAC5G,IAAI;AAAA,MACH;AAAA,MACA,KAAK;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,IAAA,CACA,EAED,aAAa,yBAAyB,CAAC,IAAI,EAAE,+BAA+B;AAC5E,SAAG,YAAY,IAAI,sBAAsB,wBAAwB,CAAC;AAAA,IAAA,CAClE,EACA,aAAa,sBAAsB,CAAC,IAAI,EAAE,+BAA+B;AACzE,SAAG,eAAe,IAAI,mBAAmB,wBAAwB,CAAC;AAAA,IAClE,CAAA,EACA,WAAW,wBAAwB,CAAC,EAAE,gBAAgB,MACtD,KAAK,4BAA4B,OAAO,gBAAgB,SAAS,CAAC,EAClE,WAAW,wBAAwB,CAAC,EAAE,sBACtC,KAAK,4BAA4B,OAAO,gBAAgB,sBAAsB,CAAC,EAC/E,WAAW,iBAAiB,CAAC,EAAE,gBAAgB,oBAAoB,gBAAA,MACnE,IAAI,cAAc,gBAAgB,oBAAoB,gBAAgB,aAAa,CAAC,EACpF,WAAW,6BAA6B,CAAC,EAAE,4BAA4B,yBACvE,IAAI,0BAA0B,KAAK,OAAO,IAAI,yBAAyB,4BAA4B,kBAAkB,CAAC,CAAC,EACvH,MACA,EAAA;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;"}
|
|
@@ -11,7 +11,7 @@ class ContentQueryExecutorImpl {
|
|
|
11
11
|
this.executionContainerFactory = executionContainerFactory;
|
|
12
12
|
this.graphqlSchemaBuilderFactory = graphqlSchemaBuilderFactory;
|
|
13
13
|
}
|
|
14
|
-
async execute({ db, schema, databaseMetadata, stage, project, identity }, { query, variables }) {
|
|
14
|
+
async execute({ db, schema, schemaMeta, databaseMetadata, stage, project, identity }, { query, variables }) {
|
|
15
15
|
const permissions = new schemaUtils.AllowAllPermissionFactory().create(schema.model, true);
|
|
16
16
|
const authorizator = new engineContentApi.Authorizator(permissions, true);
|
|
17
17
|
const dataSchemaBuilder = this.graphqlSchemaBuilderFactory.create(schema.model, authorizator);
|
|
@@ -22,6 +22,7 @@ class ContentQueryExecutorImpl {
|
|
|
22
22
|
identityVariables: {},
|
|
23
23
|
identityId,
|
|
24
24
|
schema,
|
|
25
|
+
schemaMeta,
|
|
25
26
|
schemaDatabaseMetadata: databaseMetadata,
|
|
26
27
|
permissions,
|
|
27
28
|
systemSchema: project.systemSchema,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContentQueryExecutor.cjs","sources":["../../../../../packages/engine-http/src/system/ContentQueryExecutor.ts"],"sourcesContent":["import {\n\tContentQueryExecutor,\n\tContentQueryExecutorContext,\n\tContentQueryExecutorQuery,\n\tContentQueryExecutorResult,\n} from '@contember/engine-system-api'\nimport { Authorizator, ExecutionContainerFactory, GraphQlSchemaBuilderFactory } from '@contember/engine-content-api'\nimport { AllowAllPermissionFactory } from '@contember/schema-utils'\nimport { graphql, GraphQLError } from 'graphql'\nimport { ExtendedGraphqlContext } from '../content'\nimport { extractOriginalError } from '../graphql'\nimport { logger } from '@contember/logger'\n\nexport class ContentQueryExecutorImpl implements ContentQueryExecutor {\n\tconstructor(\n\t\tprivate readonly executionContainerFactory: ExecutionContainerFactory,\n\t\tprivate readonly graphqlSchemaBuilderFactory: GraphQlSchemaBuilderFactory,\n\t) {\n\t}\n\n\tpublic async execute({ db, schema, databaseMetadata, stage, project, identity }: ContentQueryExecutorContext, { query, variables }: ContentQueryExecutorQuery): Promise<ContentQueryExecutorResult> {\n\t\tconst permissions = new AllowAllPermissionFactory().create(schema.model, true)\n\t\tconst authorizator = new Authorizator(permissions, true)\n\t\tconst dataSchemaBuilder = this.graphqlSchemaBuilderFactory.create(schema.model, authorizator)\n\t\tconst dataSchema = dataSchemaBuilder.build()\n\n\t\tconst identityId = identity.id\n\n\t\tconst executionContainer = this.executionContainerFactory.create({\n\t\t\tdb: db.client.forSchema(stage.schema),\n\t\t\tidentityVariables: {},\n\t\t\tidentityId,\n\t\t\tschema,\n\t\t\tschemaDatabaseMetadata: databaseMetadata,\n\t\t\tpermissions,\n\t\t\tsystemSchema: project.systemSchema,\n\t\t\tstage,\n\t\t\tproject: project,\n\t\t})\n\n\t\tconst ctx: ExtendedGraphqlContext = {\n\t\t\tdb: db.client.forSchema(stage.schema),\n\t\t\tidentityVariables: {},\n\t\t\tidentityId,\n\t\t\trequestDebug: false,\n\t\t\texecutionContainer,\n\t\t\ttimer: (label, cb) => cb(),\n\t\t}\n\n\t\ttry {\n\t\t\tconst result = await graphql({\n\t\t\t\tschema: dataSchema,\n\t\t\t\tsource: query,\n\t\t\t\tvariableValues: variables,\n\t\t\t\tcontextValue: ctx,\n\t\t\t})\n\t\t\tif (result.errors?.length) {\n\t\t\t\treturn { ok: false, errors: result.errors.map(formatErrorMessage) }\n\t\t\t}\n\t\t\treturn { ok: true, result }\n\t\t} catch (e) {\n\t\t\treturn { ok: false, errors: [formatErrorMessage(e)] }\n\t\t}\n\t}\n}\n\nconst formatErrorMessage = (e: any): string => {\n\tconst originalError = extractOriginalError(e)\n\tif (originalError instanceof GraphQLError) {\n\t\treturn originalError.message\n\t}\n\tconst errorDetails = typeof originalError === 'object'\n\t\t&& originalError !== null\n\t\t&& 'message' in originalError ? `: ${originalError.message}` : ''\n\n\tlogger.error(e)\n\n\treturn `Internal error${errorDetails}`\n}\n"],"names":["AllowAllPermissionFactory","Authorizator","graphql","extractOriginalError","GraphQLError","logger"],"mappings":";;;;;;;;AAaO,MAAM,yBAAyD;AAAA,EACrE,YACkB,2BACA,6BAChB;AAFgB,SAAA,4BAAA;AACA,SAAA,8BAAA;AAAA,EAElB;AAAA,EAEA,MAAa,QAAQ,EAAE,IAAI,QAAQ,kBAAkB,OAAO,SAAS,SAAS,GAAgC,EAAE,OAAO,aAA6E;
|
|
1
|
+
{"version":3,"file":"ContentQueryExecutor.cjs","sources":["../../../../../packages/engine-http/src/system/ContentQueryExecutor.ts"],"sourcesContent":["import {\n\tContentQueryExecutor,\n\tContentQueryExecutorContext,\n\tContentQueryExecutorQuery,\n\tContentQueryExecutorResult,\n} from '@contember/engine-system-api'\nimport { Authorizator, ExecutionContainerFactory, GraphQlSchemaBuilderFactory } from '@contember/engine-content-api'\nimport { AllowAllPermissionFactory } from '@contember/schema-utils'\nimport { graphql, GraphQLError } from 'graphql'\nimport { ExtendedGraphqlContext } from '../content'\nimport { extractOriginalError } from '../graphql'\nimport { logger } from '@contember/logger'\n\nexport class ContentQueryExecutorImpl implements ContentQueryExecutor {\n\tconstructor(\n\t\tprivate readonly executionContainerFactory: ExecutionContainerFactory,\n\t\tprivate readonly graphqlSchemaBuilderFactory: GraphQlSchemaBuilderFactory,\n\t) {\n\t}\n\n\tpublic async execute({ db, schema, schemaMeta, databaseMetadata, stage, project, identity }: ContentQueryExecutorContext, { query, variables }: ContentQueryExecutorQuery): Promise<ContentQueryExecutorResult> {\n\t\tconst permissions = new AllowAllPermissionFactory().create(schema.model, true)\n\t\tconst authorizator = new Authorizator(permissions, true)\n\t\tconst dataSchemaBuilder = this.graphqlSchemaBuilderFactory.create(schema.model, authorizator)\n\t\tconst dataSchema = dataSchemaBuilder.build()\n\n\t\tconst identityId = identity.id\n\n\t\tconst executionContainer = this.executionContainerFactory.create({\n\t\t\tdb: db.client.forSchema(stage.schema),\n\t\t\tidentityVariables: {},\n\t\t\tidentityId,\n\t\t\tschema,\n\t\t\tschemaMeta,\n\t\t\tschemaDatabaseMetadata: databaseMetadata,\n\t\t\tpermissions,\n\t\t\tsystemSchema: project.systemSchema,\n\t\t\tstage,\n\t\t\tproject: project,\n\t\t})\n\n\t\tconst ctx: ExtendedGraphqlContext = {\n\t\t\tdb: db.client.forSchema(stage.schema),\n\t\t\tidentityVariables: {},\n\t\t\tidentityId,\n\t\t\trequestDebug: false,\n\t\t\texecutionContainer,\n\t\t\ttimer: (label, cb) => cb(),\n\t\t}\n\n\t\ttry {\n\t\t\tconst result = await graphql({\n\t\t\t\tschema: dataSchema,\n\t\t\t\tsource: query,\n\t\t\t\tvariableValues: variables,\n\t\t\t\tcontextValue: ctx,\n\t\t\t})\n\t\t\tif (result.errors?.length) {\n\t\t\t\treturn { ok: false, errors: result.errors.map(formatErrorMessage) }\n\t\t\t}\n\t\t\treturn { ok: true, result }\n\t\t} catch (e) {\n\t\t\treturn { ok: false, errors: [formatErrorMessage(e)] }\n\t\t}\n\t}\n}\n\nconst formatErrorMessage = (e: any): string => {\n\tconst originalError = extractOriginalError(e)\n\tif (originalError instanceof GraphQLError) {\n\t\treturn originalError.message\n\t}\n\tconst errorDetails = typeof originalError === 'object'\n\t\t&& originalError !== null\n\t\t&& 'message' in originalError ? `: ${originalError.message}` : ''\n\n\tlogger.error(e)\n\n\treturn `Internal error${errorDetails}`\n}\n"],"names":["AllowAllPermissionFactory","Authorizator","graphql","extractOriginalError","GraphQLError","logger"],"mappings":";;;;;;;;AAaO,MAAM,yBAAyD;AAAA,EACrE,YACkB,2BACA,6BAChB;AAFgB,SAAA,4BAAA;AACA,SAAA,8BAAA;AAAA,EAElB;AAAA,EAEA,MAAa,QAAQ,EAAE,IAAI,QAAQ,YAAY,kBAAkB,OAAO,SAAS,SAAS,GAAgC,EAAE,OAAO,aAA6E;AAC/M,UAAM,cAAc,IAAIA,wCAA4B,OAAO,OAAO,OAAO,IAAI;AAC7E,UAAM,eAAe,IAAIC,iBAAAA,aAAa,aAAa,IAAI;AACvD,UAAM,oBAAoB,KAAK,4BAA4B,OAAO,OAAO,OAAO,YAAY;AACtF,UAAA,aAAa,kBAAkB;AAErC,UAAM,aAAa,SAAS;AAEtB,UAAA,qBAAqB,KAAK,0BAA0B,OAAO;AAAA,MAChE,IAAI,GAAG,OAAO,UAAU,MAAM,MAAM;AAAA,MACpC,mBAAmB,CAAC;AAAA,MACpB;AAAA,MACA;AAAA,MACA;AAAA,MACA,wBAAwB;AAAA,MACxB;AAAA,MACA,cAAc,QAAQ;AAAA,MACtB;AAAA,MACA;AAAA,IAAA,CACA;AAED,UAAM,MAA8B;AAAA,MACnC,IAAI,GAAG,OAAO,UAAU,MAAM,MAAM;AAAA,MACpC,mBAAmB,CAAC;AAAA,MACpB;AAAA,MACA,cAAc;AAAA,MACd;AAAA,MACA,OAAO,CAAC,OAAO,OAAO,GAAG;AAAA,IAAA;AAGtB,QAAA;AACG,YAAA,SAAS,MAAMC,gBAAQ;AAAA,QAC5B,QAAQ;AAAA,QACR,QAAQ;AAAA,QACR,gBAAgB;AAAA,QAChB,cAAc;AAAA,MAAA,CACd;AACG,UAAA,OAAO,QAAQ,QAAQ;AACnB,eAAA,EAAE,IAAI,OAAO,QAAQ,OAAO,OAAO,IAAI,kBAAkB;MACjE;AACO,aAAA,EAAE,IAAI,MAAM;aACX,GAAG;AACJ,aAAA,EAAE,IAAI,OAAO,QAAQ,CAAC,mBAAmB,CAAC,CAAC;IACnD;AAAA,EACD;AACD;AAEA,MAAM,qBAAqB,CAAC,MAAmB;AACxC,QAAA,gBAAgBC,+BAAqB,CAAC;AAC5C,MAAI,yBAAyBC,QAAAA,cAAc;AAC1C,WAAO,cAAc;AAAA,EACtB;AACM,QAAA,eAAe,OAAO,kBAAkB,YAC1C,kBAAkB,QAClB,aAAa,gBAAgB,KAAK,cAAc,OAAO,KAAK;AAEhEC,gBAAO,MAAM,CAAC;AAEd,SAAO,iBAAiB,YAAY;AACrC;;"}
|
|
@@ -9,7 +9,7 @@ class ContentQueryExecutorImpl {
|
|
|
9
9
|
this.executionContainerFactory = executionContainerFactory;
|
|
10
10
|
this.graphqlSchemaBuilderFactory = graphqlSchemaBuilderFactory;
|
|
11
11
|
}
|
|
12
|
-
async execute({ db, schema, databaseMetadata, stage, project, identity }, { query, variables }) {
|
|
12
|
+
async execute({ db, schema, schemaMeta, databaseMetadata, stage, project, identity }, { query, variables }) {
|
|
13
13
|
const permissions = new AllowAllPermissionFactory().create(schema.model, true);
|
|
14
14
|
const authorizator = new Authorizator(permissions, true);
|
|
15
15
|
const dataSchemaBuilder = this.graphqlSchemaBuilderFactory.create(schema.model, authorizator);
|
|
@@ -20,6 +20,7 @@ class ContentQueryExecutorImpl {
|
|
|
20
20
|
identityVariables: {},
|
|
21
21
|
identityId,
|
|
22
22
|
schema,
|
|
23
|
+
schemaMeta,
|
|
23
24
|
schemaDatabaseMetadata: databaseMetadata,
|
|
24
25
|
permissions,
|
|
25
26
|
systemSchema: project.systemSchema,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContentQueryExecutor.js","sources":["../../../../../packages/engine-http/src/system/ContentQueryExecutor.ts"],"sourcesContent":["import {\n\tContentQueryExecutor,\n\tContentQueryExecutorContext,\n\tContentQueryExecutorQuery,\n\tContentQueryExecutorResult,\n} from '@contember/engine-system-api'\nimport { Authorizator, ExecutionContainerFactory, GraphQlSchemaBuilderFactory } from '@contember/engine-content-api'\nimport { AllowAllPermissionFactory } from '@contember/schema-utils'\nimport { graphql, GraphQLError } from 'graphql'\nimport { ExtendedGraphqlContext } from '../content'\nimport { extractOriginalError } from '../graphql'\nimport { logger } from '@contember/logger'\n\nexport class ContentQueryExecutorImpl implements ContentQueryExecutor {\n\tconstructor(\n\t\tprivate readonly executionContainerFactory: ExecutionContainerFactory,\n\t\tprivate readonly graphqlSchemaBuilderFactory: GraphQlSchemaBuilderFactory,\n\t) {\n\t}\n\n\tpublic async execute({ db, schema, databaseMetadata, stage, project, identity }: ContentQueryExecutorContext, { query, variables }: ContentQueryExecutorQuery): Promise<ContentQueryExecutorResult> {\n\t\tconst permissions = new AllowAllPermissionFactory().create(schema.model, true)\n\t\tconst authorizator = new Authorizator(permissions, true)\n\t\tconst dataSchemaBuilder = this.graphqlSchemaBuilderFactory.create(schema.model, authorizator)\n\t\tconst dataSchema = dataSchemaBuilder.build()\n\n\t\tconst identityId = identity.id\n\n\t\tconst executionContainer = this.executionContainerFactory.create({\n\t\t\tdb: db.client.forSchema(stage.schema),\n\t\t\tidentityVariables: {},\n\t\t\tidentityId,\n\t\t\tschema,\n\t\t\tschemaDatabaseMetadata: databaseMetadata,\n\t\t\tpermissions,\n\t\t\tsystemSchema: project.systemSchema,\n\t\t\tstage,\n\t\t\tproject: project,\n\t\t})\n\n\t\tconst ctx: ExtendedGraphqlContext = {\n\t\t\tdb: db.client.forSchema(stage.schema),\n\t\t\tidentityVariables: {},\n\t\t\tidentityId,\n\t\t\trequestDebug: false,\n\t\t\texecutionContainer,\n\t\t\ttimer: (label, cb) => cb(),\n\t\t}\n\n\t\ttry {\n\t\t\tconst result = await graphql({\n\t\t\t\tschema: dataSchema,\n\t\t\t\tsource: query,\n\t\t\t\tvariableValues: variables,\n\t\t\t\tcontextValue: ctx,\n\t\t\t})\n\t\t\tif (result.errors?.length) {\n\t\t\t\treturn { ok: false, errors: result.errors.map(formatErrorMessage) }\n\t\t\t}\n\t\t\treturn { ok: true, result }\n\t\t} catch (e) {\n\t\t\treturn { ok: false, errors: [formatErrorMessage(e)] }\n\t\t}\n\t}\n}\n\nconst formatErrorMessage = (e: any): string => {\n\tconst originalError = extractOriginalError(e)\n\tif (originalError instanceof GraphQLError) {\n\t\treturn originalError.message\n\t}\n\tconst errorDetails = typeof originalError === 'object'\n\t\t&& originalError !== null\n\t\t&& 'message' in originalError ? `: ${originalError.message}` : ''\n\n\tlogger.error(e)\n\n\treturn `Internal error${errorDetails}`\n}\n"],"names":[],"mappings":";;;;;;AAaO,MAAM,yBAAyD;AAAA,EACrE,YACkB,2BACA,6BAChB;AAFgB,SAAA,4BAAA;AACA,SAAA,8BAAA;AAAA,EAElB;AAAA,EAEA,MAAa,QAAQ,EAAE,IAAI,QAAQ,kBAAkB,OAAO,SAAS,SAAS,GAAgC,EAAE,OAAO,aAA6E;
|
|
1
|
+
{"version":3,"file":"ContentQueryExecutor.js","sources":["../../../../../packages/engine-http/src/system/ContentQueryExecutor.ts"],"sourcesContent":["import {\n\tContentQueryExecutor,\n\tContentQueryExecutorContext,\n\tContentQueryExecutorQuery,\n\tContentQueryExecutorResult,\n} from '@contember/engine-system-api'\nimport { Authorizator, ExecutionContainerFactory, GraphQlSchemaBuilderFactory } from '@contember/engine-content-api'\nimport { AllowAllPermissionFactory } from '@contember/schema-utils'\nimport { graphql, GraphQLError } from 'graphql'\nimport { ExtendedGraphqlContext } from '../content'\nimport { extractOriginalError } from '../graphql'\nimport { logger } from '@contember/logger'\n\nexport class ContentQueryExecutorImpl implements ContentQueryExecutor {\n\tconstructor(\n\t\tprivate readonly executionContainerFactory: ExecutionContainerFactory,\n\t\tprivate readonly graphqlSchemaBuilderFactory: GraphQlSchemaBuilderFactory,\n\t) {\n\t}\n\n\tpublic async execute({ db, schema, schemaMeta, databaseMetadata, stage, project, identity }: ContentQueryExecutorContext, { query, variables }: ContentQueryExecutorQuery): Promise<ContentQueryExecutorResult> {\n\t\tconst permissions = new AllowAllPermissionFactory().create(schema.model, true)\n\t\tconst authorizator = new Authorizator(permissions, true)\n\t\tconst dataSchemaBuilder = this.graphqlSchemaBuilderFactory.create(schema.model, authorizator)\n\t\tconst dataSchema = dataSchemaBuilder.build()\n\n\t\tconst identityId = identity.id\n\n\t\tconst executionContainer = this.executionContainerFactory.create({\n\t\t\tdb: db.client.forSchema(stage.schema),\n\t\t\tidentityVariables: {},\n\t\t\tidentityId,\n\t\t\tschema,\n\t\t\tschemaMeta,\n\t\t\tschemaDatabaseMetadata: databaseMetadata,\n\t\t\tpermissions,\n\t\t\tsystemSchema: project.systemSchema,\n\t\t\tstage,\n\t\t\tproject: project,\n\t\t})\n\n\t\tconst ctx: ExtendedGraphqlContext = {\n\t\t\tdb: db.client.forSchema(stage.schema),\n\t\t\tidentityVariables: {},\n\t\t\tidentityId,\n\t\t\trequestDebug: false,\n\t\t\texecutionContainer,\n\t\t\ttimer: (label, cb) => cb(),\n\t\t}\n\n\t\ttry {\n\t\t\tconst result = await graphql({\n\t\t\t\tschema: dataSchema,\n\t\t\t\tsource: query,\n\t\t\t\tvariableValues: variables,\n\t\t\t\tcontextValue: ctx,\n\t\t\t})\n\t\t\tif (result.errors?.length) {\n\t\t\t\treturn { ok: false, errors: result.errors.map(formatErrorMessage) }\n\t\t\t}\n\t\t\treturn { ok: true, result }\n\t\t} catch (e) {\n\t\t\treturn { ok: false, errors: [formatErrorMessage(e)] }\n\t\t}\n\t}\n}\n\nconst formatErrorMessage = (e: any): string => {\n\tconst originalError = extractOriginalError(e)\n\tif (originalError instanceof GraphQLError) {\n\t\treturn originalError.message\n\t}\n\tconst errorDetails = typeof originalError === 'object'\n\t\t&& originalError !== null\n\t\t&& 'message' in originalError ? `: ${originalError.message}` : ''\n\n\tlogger.error(e)\n\n\treturn `Internal error${errorDetails}`\n}\n"],"names":[],"mappings":";;;;;;AAaO,MAAM,yBAAyD;AAAA,EACrE,YACkB,2BACA,6BAChB;AAFgB,SAAA,4BAAA;AACA,SAAA,8BAAA;AAAA,EAElB;AAAA,EAEA,MAAa,QAAQ,EAAE,IAAI,QAAQ,YAAY,kBAAkB,OAAO,SAAS,SAAS,GAAgC,EAAE,OAAO,aAA6E;AAC/M,UAAM,cAAc,IAAI,4BAA4B,OAAO,OAAO,OAAO,IAAI;AAC7E,UAAM,eAAe,IAAI,aAAa,aAAa,IAAI;AACvD,UAAM,oBAAoB,KAAK,4BAA4B,OAAO,OAAO,OAAO,YAAY;AACtF,UAAA,aAAa,kBAAkB;AAErC,UAAM,aAAa,SAAS;AAEtB,UAAA,qBAAqB,KAAK,0BAA0B,OAAO;AAAA,MAChE,IAAI,GAAG,OAAO,UAAU,MAAM,MAAM;AAAA,MACpC,mBAAmB,CAAC;AAAA,MACpB;AAAA,MACA;AAAA,MACA;AAAA,MACA,wBAAwB;AAAA,MACxB;AAAA,MACA,cAAc,QAAQ;AAAA,MACtB;AAAA,MACA;AAAA,IAAA,CACA;AAED,UAAM,MAA8B;AAAA,MACnC,IAAI,GAAG,OAAO,UAAU,MAAM,MAAM;AAAA,MACpC,mBAAmB,CAAC;AAAA,MACpB;AAAA,MACA,cAAc;AAAA,MACd;AAAA,MACA,OAAO,CAAC,OAAO,OAAO,GAAG;AAAA,IAAA;AAGtB,QAAA;AACG,YAAA,SAAS,MAAM,QAAQ;AAAA,QAC5B,QAAQ;AAAA,QACR,QAAQ;AAAA,QACR,gBAAgB;AAAA,QAChB,cAAc;AAAA,MAAA,CACd;AACG,UAAA,OAAO,QAAQ,QAAQ;AACnB,eAAA,EAAE,IAAI,OAAO,QAAQ,OAAO,OAAO,IAAI,kBAAkB;MACjE;AACO,aAAA,EAAE,IAAI,MAAM;aACX,GAAG;AACJ,aAAA,EAAE,IAAI,OAAO,QAAQ,CAAC,mBAAmB,CAAC,CAAC;IACnD;AAAA,EACD;AACD;AAEA,MAAM,qBAAqB,CAAC,MAAmB;AACxC,QAAA,gBAAgB,qBAAqB,CAAC;AAC5C,MAAI,yBAAyB,cAAc;AAC1C,WAAO,cAAc;AAAA,EACtB;AACM,QAAA,eAAe,OAAO,kBAAkB,YAC1C,kBAAkB,QAClB,aAAa,gBAAgB,KAAK,cAAc,OAAO,KAAK;AAEhE,SAAO,MAAM,CAAC;AAEd,SAAO,iBAAiB,YAAY;AACrC;"}
|
|
@@ -7,14 +7,15 @@ class SystemGraphQLContextFactory {
|
|
|
7
7
|
authResult.identityId,
|
|
8
8
|
memberships.map((it) => it.role)
|
|
9
9
|
);
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
const db = projectContainer.systemDatabaseContext;
|
|
11
|
+
const systemContext = await systemContainer.resolverContextFactory.create({
|
|
12
|
+
db,
|
|
13
|
+
identity,
|
|
14
|
+
project: { ...projectContainer.project, systemSchema: db.client.schema },
|
|
15
|
+
getSchema: async (options) => {
|
|
16
|
+
return (await projectContainer.contentSchemaResolver.getSchema({ db, ...options })).schema;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
18
19
|
return {
|
|
19
20
|
...systemContext,
|
|
20
21
|
onClearCache
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SystemGraphQLContextFactory.cjs","sources":["../../../../../packages/engine-http/src/system/SystemGraphQLContextFactory.ts"],"sourcesContent":["import { Identity, SystemContainer } from '@contember/engine-system-api'\nimport { SystemGraphQLContext } from './SystemGraphQLHandlerFactory'\nimport { AuthResult } from '../common'\nimport { Acl } from '@contember/schema'\nimport { ProjectContainer } from '../project'\n\nexport class SystemGraphQLContextFactory {\n\tpublic async create({ authResult, memberships, projectContainer, systemContainer, onClearCache }: {\n\t\tauthResult: AuthResult\n\t\tmemberships: readonly Acl.Membership[]\n\t\tprojectContainer: ProjectContainer\n\t\tsystemContainer: SystemContainer\n\t\tonClearCache: () => void\n\t}): Promise<SystemGraphQLContext> {\n\t\tconst identity = new Identity(\n\t\t\tauthResult.identityId,\n\t\t\tmemberships.map(it => it.role),\n\t\t)\n\n\t\tconst
|
|
1
|
+
{"version":3,"file":"SystemGraphQLContextFactory.cjs","sources":["../../../../../packages/engine-http/src/system/SystemGraphQLContextFactory.ts"],"sourcesContent":["import { Identity, SystemContainer } from '@contember/engine-system-api'\nimport { SystemGraphQLContext } from './SystemGraphQLHandlerFactory'\nimport { AuthResult } from '../common'\nimport { Acl } from '@contember/schema'\nimport { ProjectContainer } from '../project'\n\nexport class SystemGraphQLContextFactory {\n\tpublic async create({ authResult, memberships, projectContainer, systemContainer, onClearCache }: {\n\t\tauthResult: AuthResult\n\t\tmemberships: readonly Acl.Membership[]\n\t\tprojectContainer: ProjectContainer\n\t\tsystemContainer: SystemContainer\n\t\tonClearCache: () => void\n\t}): Promise<SystemGraphQLContext> {\n\t\tconst identity = new Identity(\n\t\t\tauthResult.identityId,\n\t\t\tmemberships.map(it => it.role),\n\t\t)\n\n\t\tconst db = projectContainer.systemDatabaseContext\n\t\tconst systemContext = await systemContainer.resolverContextFactory.create({\n\t\t\tdb,\n\t\t\tidentity,\n\t\t\tproject: { ...projectContainer.project, systemSchema: db.client.schema },\n\t\t\tgetSchema: async options => {\n\t\t\t\t return (await projectContainer.contentSchemaResolver.getSchema({ db, ...options })).schema\n\t\t\t},\n\t\t})\n\t\treturn {\n\t\t\t...systemContext,\n\t\t\tonClearCache,\n\t\t}\n\t}\n}\n"],"names":["Identity"],"mappings":";;;AAMO,MAAM,4BAA4B;AAAA,EACxC,MAAa,OAAO,EAAE,YAAY,aAAc,kBAAkB,iBAAiB,gBAMjD;AACjC,UAAM,WAAW,IAAIA,gBAAA;AAAA,MACpB,WAAW;AAAA,MACX,YAAY,IAAI,CAAM,OAAA,GAAG,IAAI;AAAA,IAAA;AAG9B,UAAM,KAAK,iBAAiB;AAC5B,UAAM,gBAAgB,MAAM,gBAAgB,uBAAuB,OAAO;AAAA,MACzE;AAAA,MACA;AAAA,MACA,SAAS,EAAE,GAAG,iBAAiB,SAAS,cAAc,GAAG,OAAO,OAAO;AAAA,MACvE,WAAW,OAAM,YAAW;AAClB,gBAAA,MAAM,iBAAiB,sBAAsB,UAAU,EAAE,IAAI,GAAG,SAAS,GAAG;AAAA,MACtF;AAAA,IAAA,CACA;AACM,WAAA;AAAA,MACN,GAAG;AAAA,MACH;AAAA,IAAA;AAAA,EAEF;AACD;;"}
|
|
@@ -5,14 +5,15 @@ class SystemGraphQLContextFactory {
|
|
|
5
5
|
authResult.identityId,
|
|
6
6
|
memberships.map((it) => it.role)
|
|
7
7
|
);
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
const db = projectContainer.systemDatabaseContext;
|
|
9
|
+
const systemContext = await systemContainer.resolverContextFactory.create({
|
|
10
|
+
db,
|
|
11
|
+
identity,
|
|
12
|
+
project: { ...projectContainer.project, systemSchema: db.client.schema },
|
|
13
|
+
getSchema: async (options) => {
|
|
14
|
+
return (await projectContainer.contentSchemaResolver.getSchema({ db, ...options })).schema;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
16
17
|
return {
|
|
17
18
|
...systemContext,
|
|
18
19
|
onClearCache
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SystemGraphQLContextFactory.js","sources":["../../../../../packages/engine-http/src/system/SystemGraphQLContextFactory.ts"],"sourcesContent":["import { Identity, SystemContainer } from '@contember/engine-system-api'\nimport { SystemGraphQLContext } from './SystemGraphQLHandlerFactory'\nimport { AuthResult } from '../common'\nimport { Acl } from '@contember/schema'\nimport { ProjectContainer } from '../project'\n\nexport class SystemGraphQLContextFactory {\n\tpublic async create({ authResult, memberships, projectContainer, systemContainer, onClearCache }: {\n\t\tauthResult: AuthResult\n\t\tmemberships: readonly Acl.Membership[]\n\t\tprojectContainer: ProjectContainer\n\t\tsystemContainer: SystemContainer\n\t\tonClearCache: () => void\n\t}): Promise<SystemGraphQLContext> {\n\t\tconst identity = new Identity(\n\t\t\tauthResult.identityId,\n\t\t\tmemberships.map(it => it.role),\n\t\t)\n\n\t\tconst
|
|
1
|
+
{"version":3,"file":"SystemGraphQLContextFactory.js","sources":["../../../../../packages/engine-http/src/system/SystemGraphQLContextFactory.ts"],"sourcesContent":["import { Identity, SystemContainer } from '@contember/engine-system-api'\nimport { SystemGraphQLContext } from './SystemGraphQLHandlerFactory'\nimport { AuthResult } from '../common'\nimport { Acl } from '@contember/schema'\nimport { ProjectContainer } from '../project'\n\nexport class SystemGraphQLContextFactory {\n\tpublic async create({ authResult, memberships, projectContainer, systemContainer, onClearCache }: {\n\t\tauthResult: AuthResult\n\t\tmemberships: readonly Acl.Membership[]\n\t\tprojectContainer: ProjectContainer\n\t\tsystemContainer: SystemContainer\n\t\tonClearCache: () => void\n\t}): Promise<SystemGraphQLContext> {\n\t\tconst identity = new Identity(\n\t\t\tauthResult.identityId,\n\t\t\tmemberships.map(it => it.role),\n\t\t)\n\n\t\tconst db = projectContainer.systemDatabaseContext\n\t\tconst systemContext = await systemContainer.resolverContextFactory.create({\n\t\t\tdb,\n\t\t\tidentity,\n\t\t\tproject: { ...projectContainer.project, systemSchema: db.client.schema },\n\t\t\tgetSchema: async options => {\n\t\t\t\t return (await projectContainer.contentSchemaResolver.getSchema({ db, ...options })).schema\n\t\t\t},\n\t\t})\n\t\treturn {\n\t\t\t...systemContext,\n\t\t\tonClearCache,\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";AAMO,MAAM,4BAA4B;AAAA,EACxC,MAAa,OAAO,EAAE,YAAY,aAAc,kBAAkB,iBAAiB,gBAMjD;AACjC,UAAM,WAAW,IAAI;AAAA,MACpB,WAAW;AAAA,MACX,YAAY,IAAI,CAAM,OAAA,GAAG,IAAI;AAAA,IAAA;AAG9B,UAAM,KAAK,iBAAiB;AAC5B,UAAM,gBAAgB,MAAM,gBAAgB,uBAAuB,OAAO;AAAA,MACzE;AAAA,MACA;AAAA,MACA,SAAS,EAAE,GAAG,iBAAiB,SAAS,cAAc,GAAG,OAAO,OAAO;AAAA,MACvE,WAAW,OAAM,YAAW;AAClB,gBAAA,MAAM,iBAAiB,sBAAsB,UAAU,EAAE,IAAI,GAAG,SAAS,GAAG;AAAA,MACtF;AAAA,IAAA,CACA;AACM,WAAA;AAAA,MACN,GAAG;AAAA,MACH;AAAA,IAAA;AAAA,EAEF;AACD;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContentSchemaTransferMappingFactory.cjs","sources":["../../../../../packages/engine-http/src/transfer/ContentSchemaTransferMappingFactory.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"ContentSchemaTransferMappingFactory.cjs","sources":["../../../../../packages/engine-http/src/transfer/ContentSchemaTransferMappingFactory.ts"],"sourcesContent":["import { Model, Schema } from '@contember/schema'\nimport { acceptFieldVisitor } from '@contember/schema-utils'\nimport { DbColumnSchema, DbColumnSchemaMap, TransferMapping, TransferTableMapping } from './TransferMapping'\n\nexport class ContentSchemaTransferMappingFactory {\n\tcreateContentSchemaMapping(contentSchema: Schema): TransferMapping {\n\t\tconst tables: Record<string, TransferTableMapping> = {}\n\n\t\tfor (const entity of Object.values(contentSchema.model.entities)) {\n\t\t\tif (entity.view === undefined) {\n\t\t\t\ttables[entity.tableName] = {\n\t\t\t\t\tname: entity.tableName,\n\t\t\t\t\tcolumns: this.buildDbColumnSchemaMap(contentSchema.model, entity),\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (const entity of Object.values(contentSchema.model.entities)) {\n\t\t\tfor (const joiningTable of this.collectManyHasManyOwned(contentSchema.model, entity)) {\n\t\t\t\ttables[joiningTable.name] = joiningTable\n\t\t\t}\n\t\t}\n\n\t\treturn { tables }\n\t}\n\n\tprivate buildDbColumnSchemaMap(schema: Model.Schema, entity: Model.Entity): DbColumnSchemaMap {\n\t\tconst columns: DbColumnSchemaMap = {}\n\n\t\tfor (const field of Object.values(entity.fields)) {\n\t\t\tconst column = acceptFieldVisitor<DbColumnSchema | null>(schema, entity, field, {\n\t\t\t\tvisitColumn: ({ column }) => {\n\t\t\t\t\tif (column.type === Model.ColumnType.Enum) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tname: column.columnName,\n\t\t\t\t\t\t\ttype: column.type,\n\t\t\t\t\t\t\tnullable: column.nullable,\n\t\t\t\t\t\t\tvalues: schema.enums[column.columnType],\n\t\t\t\t\t\t}\n\n\t\t\t\t\t} else if (column.type === Model.ColumnType.Int) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tname: column.columnName,\n\t\t\t\t\t\t\ttype: column.type,\n\t\t\t\t\t\t\tnullable: column.nullable,\n\t\t\t\t\t\t\tsequence: column.sequence !== undefined,\n\t\t\t\t\t\t}\n\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tname: column.columnName,\n\t\t\t\t\t\t\ttype: column.type,\n\t\t\t\t\t\t\tnullable: column.nullable,\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tvisitOneHasOneOwning: ({ relation, targetEntity }) => ({\n\t\t\t\t\tname: relation.joiningColumn.columnName,\n\t\t\t\t\ttype: targetEntity.fields[targetEntity.primary].type as (Model.ColumnType.Uuid | Model.ColumnType.Int),\n\t\t\t\t\tnullable: relation.nullable,\n\t\t\t\t}),\n\t\t\t\tvisitManyHasOne: ({ relation, targetEntity }) => ({\n\t\t\t\t\tname: relation.joiningColumn.columnName,\n\t\t\t\t\ttype: targetEntity.fields[targetEntity.primary].type as (Model.ColumnType.Uuid | Model.ColumnType.Int),\n\t\t\t\t\tnullable: relation.nullable,\n\t\t\t\t}),\n\t\t\t\tvisitManyHasManyOwning: () => null,\n\t\t\t\tvisitManyHasManyInverse: () => null,\n\t\t\t\tvisitOneHasMany: () => null,\n\t\t\t\tvisitOneHasOneInverse: () => null,\n\t\t\t})\n\n\t\t\tif (column !== null) {\n\t\t\t\tcolumns[column.name] = column\n\t\t\t}\n\t\t}\n\n\t\treturn columns\n\t}\n\n\tprivate collectManyHasManyOwned(schema: Model.Schema, entity: Model.Entity): TransferTableMapping[] {\n\t\tconst joiningTables = []\n\n\t\tfor (const field of Object.values(entity.fields)) {\n\t\t\tconst joiningTable = acceptFieldVisitor<TransferTableMapping | null>(schema, entity, field, {\n\t\t\t\tvisitColumn: () => null,\n\t\t\t\tvisitOneHasOneOwning: () => null,\n\t\t\t\tvisitManyHasOne: () => null,\n\t\t\t\tvisitManyHasManyOwning: ({ entity, relation, targetEntity }) => ({\n\t\t\t\t\tname: relation.joiningTable.tableName,\n\t\t\t\t\tcolumns: {\n\t\t\t\t\t\t[relation.joiningTable.joiningColumn.columnName]: {\n\t\t\t\t\t\t\tname: relation.joiningTable.joiningColumn.columnName,\n\t\t\t\t\t\t\ttype: entity.fields[entity.primary].type as (Model.ColumnType.Uuid | Model.ColumnType.Int),\n\t\t\t\t\t\t\tnullable: false,\n\t\t\t\t\t\t},\n\t\t\t\t\t\t[relation.joiningTable.inverseJoiningColumn.columnName]: {\n\t\t\t\t\t\t\tname: relation.joiningTable.inverseJoiningColumn.columnName,\n\t\t\t\t\t\t\ttype: targetEntity.fields[targetEntity.primary].type as (Model.ColumnType.Uuid | Model.ColumnType.Int),\n\t\t\t\t\t\t\tnullable: false,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t\tvisitManyHasManyInverse: () => null,\n\t\t\t\tvisitOneHasMany: () => null,\n\t\t\t\tvisitOneHasOneInverse: () => null,\n\t\t\t})\n\n\t\t\tif (joiningTable !== null) {\n\t\t\t\tjoiningTables.push(joiningTable)\n\t\t\t}\n\t\t}\n\n\t\treturn joiningTables\n\t}\n}\n"],"names":["schema","acceptFieldVisitor","column","Model","entity"],"mappings":";;;;AAIO,MAAM,oCAAoC;AAAA,EAChD,2BAA2B,eAAwC;AAClE,UAAM,SAA+C,CAAA;AAErD,eAAW,UAAU,OAAO,OAAO,cAAc,MAAM,QAAQ,GAAG;AAC7D,UAAA,OAAO,SAAS,QAAW;AACvB,eAAA,OAAO,SAAS,IAAI;AAAA,UAC1B,MAAM,OAAO;AAAA,UACb,SAAS,KAAK,uBAAuB,cAAc,OAAO,MAAM;AAAA,QAAA;AAAA,MAElE;AAAA,IACD;AAEA,eAAW,UAAU,OAAO,OAAO,cAAc,MAAM,QAAQ,GAAG;AACjE,iBAAW,gBAAgB,KAAK,wBAAwB,cAAc,OAAO,MAAM,GAAG;AAC9E,eAAA,aAAa,IAAI,IAAI;AAAA,MAC7B;AAAA,IACD;AAEA,WAAO,EAAE,OAAO;AAAA,EACjB;AAAA,EAEQ,uBAAuBA,UAAsB,QAAyC;AAC7F,UAAM,UAA6B,CAAA;AAEnC,eAAW,SAAS,OAAO,OAAO,OAAO,MAAM,GAAG;AACjD,YAAM,SAASC,YAAA,mBAA0CD,UAAQ,QAAQ,OAAO;AAAA,QAC/E,aAAa,CAAC,EAAE,QAAAE,cAAa;AAC5B,cAAIA,QAAO,SAASC,aAAM,WAAW,MAAM;AACnC,mBAAA;AAAA,cACN,MAAMD,QAAO;AAAA,cACb,MAAMA,QAAO;AAAA,cACb,UAAUA,QAAO;AA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U,oBAAoB;AAAA,UAChE,MAAM,SAAS,aAAa;AAAA,UAC5B,SAAS;AAAA,YACR,CAAC,SAAS,aAAa,cAAc,UAAU,GAAG;AAAA,cACjD,MAAM,SAAS,aAAa,cAAc;AAAA,cAC1C,MAAMA,QAAO,OAAOA,QAAO,OAAO,EAAE;AAAA,cACpC,UAAU;AAAA,YACX;AAAA,YACA,CAAC,SAAS,aAAa,qBAAqB,UAAU,GAAG;AAAA,cACxD,MAAM,SAAS,aAAa,qBAAqB;AAAA,cACjD,MAAM,aAAa,OAAO,aAAa,OAAO,EAAE;AAAA,cAChD,UAAU;AAAA,YACX;AAAA,UACD;AAAA,QAAA;AAAA,QAED,yBAAyB,MAAM;AAAA,QAC/B,iBAAiB,MAAM;AAAA,QACvB,uBAAuB,MAAM;AAAA,MAAA,CAC7B;AAED,UAAI,iBAAiB,MAAM;AAC1B,sBAAc,KAAK,YAAY;AAAA,MAChC;AAAA,IACD;AAEO,WAAA;AAAA,EACR;AACD;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContentSchemaTransferMappingFactory.js","sources":["../../../../../packages/engine-http/src/transfer/ContentSchemaTransferMappingFactory.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"ContentSchemaTransferMappingFactory.js","sources":["../../../../../packages/engine-http/src/transfer/ContentSchemaTransferMappingFactory.ts"],"sourcesContent":["import { Model, Schema } from '@contember/schema'\nimport { acceptFieldVisitor } from '@contember/schema-utils'\nimport { DbColumnSchema, DbColumnSchemaMap, TransferMapping, TransferTableMapping } from './TransferMapping'\n\nexport class ContentSchemaTransferMappingFactory {\n\tcreateContentSchemaMapping(contentSchema: Schema): TransferMapping {\n\t\tconst tables: Record<string, TransferTableMapping> = {}\n\n\t\tfor (const entity of Object.values(contentSchema.model.entities)) {\n\t\t\tif (entity.view === undefined) {\n\t\t\t\ttables[entity.tableName] = {\n\t\t\t\t\tname: entity.tableName,\n\t\t\t\t\tcolumns: this.buildDbColumnSchemaMap(contentSchema.model, entity),\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (const entity of Object.values(contentSchema.model.entities)) {\n\t\t\tfor (const joiningTable of this.collectManyHasManyOwned(contentSchema.model, entity)) {\n\t\t\t\ttables[joiningTable.name] = joiningTable\n\t\t\t}\n\t\t}\n\n\t\treturn { tables }\n\t}\n\n\tprivate buildDbColumnSchemaMap(schema: Model.Schema, entity: Model.Entity): DbColumnSchemaMap {\n\t\tconst columns: DbColumnSchemaMap = {}\n\n\t\tfor (const field of Object.values(entity.fields)) {\n\t\t\tconst column = acceptFieldVisitor<DbColumnSchema | null>(schema, entity, field, {\n\t\t\t\tvisitColumn: ({ column }) => {\n\t\t\t\t\tif (column.type === Model.ColumnType.Enum) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tname: column.columnName,\n\t\t\t\t\t\t\ttype: column.type,\n\t\t\t\t\t\t\tnullable: column.nullable,\n\t\t\t\t\t\t\tvalues: schema.enums[column.columnType],\n\t\t\t\t\t\t}\n\n\t\t\t\t\t} else if (column.type === Model.ColumnType.Int) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tname: column.columnName,\n\t\t\t\t\t\t\ttype: column.type,\n\t\t\t\t\t\t\tnullable: column.nullable,\n\t\t\t\t\t\t\tsequence: column.sequence !== undefined,\n\t\t\t\t\t\t}\n\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tname: column.columnName,\n\t\t\t\t\t\t\ttype: column.type,\n\t\t\t\t\t\t\tnullable: column.nullable,\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tvisitOneHasOneOwning: ({ relation, targetEntity }) => ({\n\t\t\t\t\tname: relation.joiningColumn.columnName,\n\t\t\t\t\ttype: targetEntity.fields[targetEntity.primary].type as (Model.ColumnType.Uuid | Model.ColumnType.Int),\n\t\t\t\t\tnullable: relation.nullable,\n\t\t\t\t}),\n\t\t\t\tvisitManyHasOne: ({ relation, targetEntity }) => ({\n\t\t\t\t\tname: relation.joiningColumn.columnName,\n\t\t\t\t\ttype: targetEntity.fields[targetEntity.primary].type as (Model.ColumnType.Uuid | Model.ColumnType.Int),\n\t\t\t\t\tnullable: relation.nullable,\n\t\t\t\t}),\n\t\t\t\tvisitManyHasManyOwning: () => null,\n\t\t\t\tvisitManyHasManyInverse: () => null,\n\t\t\t\tvisitOneHasMany: () => null,\n\t\t\t\tvisitOneHasOneInverse: () => null,\n\t\t\t})\n\n\t\t\tif (column !== null) {\n\t\t\t\tcolumns[column.name] = column\n\t\t\t}\n\t\t}\n\n\t\treturn columns\n\t}\n\n\tprivate collectManyHasManyOwned(schema: Model.Schema, entity: Model.Entity): TransferTableMapping[] {\n\t\tconst joiningTables = []\n\n\t\tfor (const field of Object.values(entity.fields)) {\n\t\t\tconst joiningTable = acceptFieldVisitor<TransferTableMapping | null>(schema, entity, field, {\n\t\t\t\tvisitColumn: () => null,\n\t\t\t\tvisitOneHasOneOwning: () => null,\n\t\t\t\tvisitManyHasOne: () => null,\n\t\t\t\tvisitManyHasManyOwning: ({ entity, relation, targetEntity }) => ({\n\t\t\t\t\tname: relation.joiningTable.tableName,\n\t\t\t\t\tcolumns: {\n\t\t\t\t\t\t[relation.joiningTable.joiningColumn.columnName]: {\n\t\t\t\t\t\t\tname: relation.joiningTable.joiningColumn.columnName,\n\t\t\t\t\t\t\ttype: entity.fields[entity.primary].type as (Model.ColumnType.Uuid | Model.ColumnType.Int),\n\t\t\t\t\t\t\tnullable: false,\n\t\t\t\t\t\t},\n\t\t\t\t\t\t[relation.joiningTable.inverseJoiningColumn.columnName]: {\n\t\t\t\t\t\t\tname: relation.joiningTable.inverseJoiningColumn.columnName,\n\t\t\t\t\t\t\ttype: targetEntity.fields[targetEntity.primary].type as (Model.ColumnType.Uuid | Model.ColumnType.Int),\n\t\t\t\t\t\t\tnullable: false,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t\tvisitManyHasManyInverse: () => null,\n\t\t\t\tvisitOneHasMany: () => null,\n\t\t\t\tvisitOneHasOneInverse: () => null,\n\t\t\t})\n\n\t\t\tif (joiningTable !== null) {\n\t\t\t\tjoiningTables.push(joiningTable)\n\t\t\t}\n\t\t}\n\n\t\treturn joiningTables\n\t}\n}\n"],"names":["column","entity"],"mappings":";;AAIO,MAAM,oCAAoC;AAAA,EAChD,2BAA2B,eAAwC;AAClE,UAAM,SAA+C,CAAA;AAErD,eAAW,UAAU,OAAO,OAAO,cAAc,MAAM,QAAQ,GAAG;AAC7D,UAAA,OAAO,SAAS,QAAW;AACvB,eAAA,OAAO,SAAS,IAAI;AAAA,UAC1B,MAAM,OAAO;AAAA,UACb,SAAS,KAAK,uBAAuB,cAAc,OAAO,MAAM;AAAA,QAAA;AAAA,MAElE;AAAA,IACD;AAEA,eAAW,UAAU,OAAO,OAAO,cAAc,MAAM,QAAQ,GAAG;AACjE,iBAAW,gBAAgB,KAAK,wBAAwB,cAAc,OAAO,MAAM,GAAG;AAC9E,eAAA,aAAa,IAAI,IAAI;AAAA,MAC7B;AAAA,IACD;AAEA,WAAO,EAAE,OAAO;AAAA,EACjB;AAAA,EAEQ,uBAAuB,QAAsB,QAAyC;AAC7F,UAAM,UAA6B,CAAA;AAEnC,eAAW,SAAS,OAAO,OAAO,OAAO,MAAM,GAAG;AACjD,YAAM,SAAS,mBAA0C,QAAQ,QAAQ,OAAO;AAAA,QAC/E,aAAa,CAAC,EAAE,QAAAA,cAAa;AAC5B,cAAIA,QAAO,SAAS,MAAM,WAAW,MAAM;AACnC,mBAAA;AAAA,cACN,MAAMA,QAAO;AAAA,cACb,MAAMA,QAAO;AAAA,cACb,UAAUA,QAAO;AAAA,cACjB,QAAQ,OAAO,MAAMA,QAAO,UAAU;AAAA,YAAA;AAAA,UAG7BA,WAAAA,QAAO,SAAS,MAAM,WAAW,KAAK;AACzC,mBAAA;AAAA,cACN,MAAMA,QAAO;AAAA,cACb,MAAMA,QAA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O,OAAO,EAAE;AAAA,cACpC,UAAU;AAAA,YACX;AAAA,YACA,CAAC,SAAS,aAAa,qBAAqB,UAAU,GAAG;AAAA,cACxD,MAAM,SAAS,aAAa,qBAAqB;AAAA,cACjD,MAAM,aAAa,OAAO,aAAa,OAAO,EAAE;AAAA,cAChD,UAAU;AAAA,YACX;AAAA,UACD;AAAA,QAAA;AAAA,QAED,yBAAyB,MAAM;AAAA,QAC/B,iBAAiB,MAAM;AAAA,QACvB,uBAAuB,MAAM;AAAA,MAAA,CAC7B;AAED,UAAI,iBAAiB,MAAM;AAC1B,sBAAc,KAAK,YAAY;AAAA,MAChC;AAAA,IACD;AAEO,WAAA;AAAA,EACR;AACD;"}
|
|
@@ -5,6 +5,7 @@ const node_stream = require("node:stream");
|
|
|
5
5
|
const CommandStream = require("./CommandStream.cjs");
|
|
6
6
|
const ExportExecutor = require("./ExportExecutor.cjs");
|
|
7
7
|
const Typesafe = require("@contember/typesafe");
|
|
8
|
+
const schemaUtils = require("@contember/schema-utils");
|
|
8
9
|
class ExportApiControllerFactory {
|
|
9
10
|
constructor(projectGroupResolver, exportExecutor) {
|
|
10
11
|
this.projectGroupResolver = projectGroupResolver;
|
|
@@ -34,7 +35,8 @@ class ExportApiControllerFactory {
|
|
|
34
35
|
throw new HttpResponse.HttpErrorResponse(400, `Project ${project.slug} NOT found`);
|
|
35
36
|
}
|
|
36
37
|
const systemContext = projectContainer.systemReadDatabaseContext;
|
|
37
|
-
const
|
|
38
|
+
const schemaWithMeta = await projectContainer.contentSchemaResolver.getSchema({ db: systemContext, normalize: true });
|
|
39
|
+
const schema = schemaWithMeta?.schema ?? schemaUtils.emptySchema;
|
|
38
40
|
const { effective: memberships } = await timer("MembershipFetch", () => projectGroup.projectMembershipResolver.resolveMemberships({
|
|
39
41
|
request: { get: () => "" },
|
|
40
42
|
acl: schema.acl,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExportApiControllerFactory.cjs","sources":["../../../../../packages/engine-http/src/transfer/ExportApiControllerFactory.ts"],"sourcesContent":["import { HttpController } from '../application'\nimport { HttpErrorResponse } from '../common'\nimport { Readable } from 'node:stream'\nimport { toBuffer } from './CommandStream'\nimport { ExportExecutor, ExportRequest } from './ExportExecutor'\nimport { ParseError } from '@contember/typesafe'\nimport { ProjectGroupResolver } from '../projectGroup/ProjectGroupResolver'\nimport { ProjectContainer } from '../project'\n\nexport class ExportApiControllerFactory {\n\tconstructor(\n\t\tprivate readonly projectGroupResolver: ProjectGroupResolver,\n\t\tprivate readonly exportExecutor: ExportExecutor,\n\t) {\n\t}\n\n\tcreate(): HttpController {\n\t\treturn async ctx => {\n\t\t\tconst { timer, 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\tlet exportRequest: ExportRequest\n\n\t\t\ttry {\n\t\t\t\texportRequest = ExportRequest(request.body)\n\n\t\t\t} catch (e) {\n\t\t\t\tif (e instanceof ParseError) {\n\t\t\t\t\treturn new HttpErrorResponse(400, `Invalid request body: ${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\n\t\t\tconst projectContainers: Record<string, ProjectContainer> = {}\n\n\t\t\tfor (const project of exportRequest.projects) {\n\t\t\t\tconst projectContainer = await projectGroup.projectContainerResolver.getProjectContainer(project.slug, { alias: true })\n\n\t\t\t\tif (projectContainer === undefined) {\n\t\t\t\t\tthrow new HttpErrorResponse(400, `Project ${project.slug} NOT found`)\n\t\t\t\t}\n\n\t\t\t\tconst systemContext = projectContainer.systemReadDatabaseContext\n\t\t\t\tconst
|
|
1
|
+
{"version":3,"file":"ExportApiControllerFactory.cjs","sources":["../../../../../packages/engine-http/src/transfer/ExportApiControllerFactory.ts"],"sourcesContent":["import { HttpController } from '../application'\nimport { HttpErrorResponse } from '../common'\nimport { Readable } from 'node:stream'\nimport { toBuffer } from './CommandStream'\nimport { ExportExecutor, ExportRequest } from './ExportExecutor'\nimport { ParseError } from '@contember/typesafe'\nimport { ProjectGroupResolver } from '../projectGroup/ProjectGroupResolver'\nimport { ProjectContainer } from '../project'\nimport { emptySchema } from '@contember/schema-utils'\n\nexport class ExportApiControllerFactory {\n\tconstructor(\n\t\tprivate readonly projectGroupResolver: ProjectGroupResolver,\n\t\tprivate readonly exportExecutor: ExportExecutor,\n\t) {\n\t}\n\n\tcreate(): HttpController {\n\t\treturn async ctx => {\n\t\t\tconst { timer, 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\tlet exportRequest: ExportRequest\n\n\t\t\ttry {\n\t\t\t\texportRequest = ExportRequest(request.body)\n\n\t\t\t} catch (e) {\n\t\t\t\tif (e instanceof ParseError) {\n\t\t\t\t\treturn new HttpErrorResponse(400, `Invalid request body: ${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\n\t\t\tconst projectContainers: Record<string, ProjectContainer> = {}\n\n\t\t\tfor (const project of exportRequest.projects) {\n\t\t\t\tconst projectContainer = await projectGroup.projectContainerResolver.getProjectContainer(project.slug, { alias: true })\n\n\t\t\t\tif (projectContainer === undefined) {\n\t\t\t\t\tthrow new HttpErrorResponse(400, `Project ${project.slug} NOT found`)\n\t\t\t\t}\n\n\t\t\t\tconst systemContext = projectContainer.systemReadDatabaseContext\n\t\t\t\tconst schemaWithMeta = await projectContainer.contentSchemaResolver.getSchema({ db: systemContext, normalize: true })\n\t\t\t\tconst schema = schemaWithMeta?.schema ?? emptySchema\n\t\t\t\tconst { effective: memberships } = await timer('MembershipFetch', () => projectGroup.projectMembershipResolver.resolveMemberships({\n\t\t\t\t\trequest: { get: () => '' },\n\t\t\t\t\tacl: schema.acl,\n\t\t\t\t\tprojectSlug: project.slug,\n\t\t\t\t\tidentity: {\n\t\t\t\t\t\tidentityId: authResult.identityId,\n\t\t\t\t\t\troles: authResult.roles,\n\t\t\t\t\t},\n\t\t\t\t}))\n\n\t\t\t\tconst projectRoles = memberships.map(it => it.role)\n\n\t\t\t\tif (!projectRoles.some(role => schema.acl.roles[role]?.content?.export)) {\n\t\t\t\t\tthrow new HttpErrorResponse(403, `Not allowed`)\n\t\t\t\t}\n\n\t\t\t\tif (project.system && !projectRoles.some(role => schema.acl.roles[role]?.system?.export)) {\n\t\t\t\t\tthrow new HttpErrorResponse(403, `Not allowed`)\n\t\t\t\t}\n\n\t\t\t\tprojectContainers[project.slug] = projectContainer\n\t\t\t}\n\n\t\t\tkoa.compress = true\n\t\t\tresponse.status = 200\n\t\t\tresponse.res.setHeader('Content-Type', 'application/x-ndjson') // https://github.com/ndjson/ndjson-spec\n\t\t\tresponse.body = Readable.from(toBuffer(this.exportExecutor.export(exportRequest, projectContainers)))\n\t\t}\n\t}\n}\n"],"names":["HttpErrorResponse","ExportRequest","ParseError","emptySchema","Readable","toBuffer"],"mappings":";;;;;;;;AAUO,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,OAAO,cAAc,YAAY,QAAQ;AAC3C,YAAA,EAAE,SAAS,SAAa,IAAA;AAC9B,UAAI,CAAC,YAAY;AACT,eAAA,IAAIA,aAAkB,kBAAA,KAAK,yBAAyB;AAAA,MAC5D;AAEI,UAAA;AAEA,UAAA;AACa,wBAAAC,eAAA,cAAc,QAAQ,IAAI;AAAA,eAElC,GAAG;AACX,YAAI,aAAaC,SAAAA,YAAY;AAC5B,iBAAO,IAAIF,aAAkB,kBAAA,KAAK,yBAAyB,EAAE,OAAO,EAAE;AAAA,QAAA,OAChE;AACA,gBAAA;AAAA,QACP;AAAA,MACD;AAEA,YAAM,oBAAsD,CA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CAAC,CAAC;AAAA,IAAA;AAAA,EAEtG;AACD;;"}
|
|
@@ -3,6 +3,7 @@ import { Readable } from "node:stream";
|
|
|
3
3
|
import { toBuffer } from "./CommandStream.js";
|
|
4
4
|
import { ExportRequest } from "./ExportExecutor.js";
|
|
5
5
|
import { ParseError } from "@contember/typesafe";
|
|
6
|
+
import { emptySchema } from "@contember/schema-utils";
|
|
6
7
|
class ExportApiControllerFactory {
|
|
7
8
|
constructor(projectGroupResolver, exportExecutor) {
|
|
8
9
|
this.projectGroupResolver = projectGroupResolver;
|
|
@@ -32,7 +33,8 @@ class ExportApiControllerFactory {
|
|
|
32
33
|
throw new HttpErrorResponse(400, `Project ${project.slug} NOT found`);
|
|
33
34
|
}
|
|
34
35
|
const systemContext = projectContainer.systemReadDatabaseContext;
|
|
35
|
-
const
|
|
36
|
+
const schemaWithMeta = await projectContainer.contentSchemaResolver.getSchema({ db: systemContext, normalize: true });
|
|
37
|
+
const schema = schemaWithMeta?.schema ?? emptySchema;
|
|
36
38
|
const { effective: memberships } = await timer("MembershipFetch", () => projectGroup.projectMembershipResolver.resolveMemberships({
|
|
37
39
|
request: { get: () => "" },
|
|
38
40
|
acl: schema.acl,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExportApiControllerFactory.js","sources":["../../../../../packages/engine-http/src/transfer/ExportApiControllerFactory.ts"],"sourcesContent":["import { HttpController } from '../application'\nimport { HttpErrorResponse } from '../common'\nimport { Readable } from 'node:stream'\nimport { toBuffer } from './CommandStream'\nimport { ExportExecutor, ExportRequest } from './ExportExecutor'\nimport { ParseError } from '@contember/typesafe'\nimport { ProjectGroupResolver } from '../projectGroup/ProjectGroupResolver'\nimport { ProjectContainer } from '../project'\n\nexport class ExportApiControllerFactory {\n\tconstructor(\n\t\tprivate readonly projectGroupResolver: ProjectGroupResolver,\n\t\tprivate readonly exportExecutor: ExportExecutor,\n\t) {\n\t}\n\n\tcreate(): HttpController {\n\t\treturn async ctx => {\n\t\t\tconst { timer, 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\tlet exportRequest: ExportRequest\n\n\t\t\ttry {\n\t\t\t\texportRequest = ExportRequest(request.body)\n\n\t\t\t} catch (e) {\n\t\t\t\tif (e instanceof ParseError) {\n\t\t\t\t\treturn new HttpErrorResponse(400, `Invalid request body: ${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\n\t\t\tconst projectContainers: Record<string, ProjectContainer> = {}\n\n\t\t\tfor (const project of exportRequest.projects) {\n\t\t\t\tconst projectContainer = await projectGroup.projectContainerResolver.getProjectContainer(project.slug, { alias: true })\n\n\t\t\t\tif (projectContainer === undefined) {\n\t\t\t\t\tthrow new HttpErrorResponse(400, `Project ${project.slug} NOT found`)\n\t\t\t\t}\n\n\t\t\t\tconst systemContext = projectContainer.systemReadDatabaseContext\n\t\t\t\tconst
|
|
1
|
+
{"version":3,"file":"ExportApiControllerFactory.js","sources":["../../../../../packages/engine-http/src/transfer/ExportApiControllerFactory.ts"],"sourcesContent":["import { HttpController } from '../application'\nimport { HttpErrorResponse } from '../common'\nimport { Readable } from 'node:stream'\nimport { toBuffer } from './CommandStream'\nimport { ExportExecutor, ExportRequest } from './ExportExecutor'\nimport { ParseError } from '@contember/typesafe'\nimport { ProjectGroupResolver } from '../projectGroup/ProjectGroupResolver'\nimport { ProjectContainer } from '../project'\nimport { emptySchema } from '@contember/schema-utils'\n\nexport class ExportApiControllerFactory {\n\tconstructor(\n\t\tprivate readonly projectGroupResolver: ProjectGroupResolver,\n\t\tprivate readonly exportExecutor: ExportExecutor,\n\t) {\n\t}\n\n\tcreate(): HttpController {\n\t\treturn async ctx => {\n\t\t\tconst { timer, 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\tlet exportRequest: ExportRequest\n\n\t\t\ttry {\n\t\t\t\texportRequest = ExportRequest(request.body)\n\n\t\t\t} catch (e) {\n\t\t\t\tif (e instanceof ParseError) {\n\t\t\t\t\treturn new HttpErrorResponse(400, `Invalid request body: ${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\n\t\t\tconst projectContainers: Record<string, ProjectContainer> = {}\n\n\t\t\tfor (const project of exportRequest.projects) {\n\t\t\t\tconst projectContainer = await projectGroup.projectContainerResolver.getProjectContainer(project.slug, { alias: true })\n\n\t\t\t\tif (projectContainer === undefined) {\n\t\t\t\t\tthrow new HttpErrorResponse(400, `Project ${project.slug} NOT found`)\n\t\t\t\t}\n\n\t\t\t\tconst systemContext = projectContainer.systemReadDatabaseContext\n\t\t\t\tconst schemaWithMeta = await projectContainer.contentSchemaResolver.getSchema({ db: systemContext, normalize: true })\n\t\t\t\tconst schema = schemaWithMeta?.schema ?? emptySchema\n\t\t\t\tconst { effective: memberships } = await timer('MembershipFetch', () => projectGroup.projectMembershipResolver.resolveMemberships({\n\t\t\t\t\trequest: { get: () => '' },\n\t\t\t\t\tacl: schema.acl,\n\t\t\t\t\tprojectSlug: project.slug,\n\t\t\t\t\tidentity: {\n\t\t\t\t\t\tidentityId: authResult.identityId,\n\t\t\t\t\t\troles: authResult.roles,\n\t\t\t\t\t},\n\t\t\t\t}))\n\n\t\t\t\tconst projectRoles = memberships.map(it => it.role)\n\n\t\t\t\tif (!projectRoles.some(role => schema.acl.roles[role]?.content?.export)) {\n\t\t\t\t\tthrow new HttpErrorResponse(403, `Not allowed`)\n\t\t\t\t}\n\n\t\t\t\tif (project.system && !projectRoles.some(role => schema.acl.roles[role]?.system?.export)) {\n\t\t\t\t\tthrow new HttpErrorResponse(403, `Not allowed`)\n\t\t\t\t}\n\n\t\t\t\tprojectContainers[project.slug] = projectContainer\n\t\t\t}\n\n\t\t\tkoa.compress = true\n\t\t\tresponse.status = 200\n\t\t\tresponse.res.setHeader('Content-Type', 'application/x-ndjson') // https://github.com/ndjson/ndjson-spec\n\t\t\tresponse.body = Readable.from(toBuffer(this.exportExecutor.export(exportRequest, projectContainers)))\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;;;;;AAUO,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,OAAO,cAAc,YAAY,QAAQ;AAC3C,YAAA,EAAE,SAAS,SAAa,IAAA;AAC9B,UAAI,CAAC,YAAY;AACT,eAAA,IAAI,kBAAkB,KAAK,yBAAyB;AAAA,MAC5D;AAEI,UAAA;AAEA,UAAA;AACa,wBAAA,cAAc,QAAQ,IAAI;AAAA,eAElC,GAAG;AACX,YAAI,aAAa,YAAY;AAC5B,iBAAO,IAAI,kBAAkB,KAAK,yBAAyB,EAAE,OAAO,EAAE;AAAA,QAAA,OAChE;AACA,gBAAA;AAAA,QACP;AAAA,MACD;AAEA,YAAM,oBAAsD,CAAA;AAEjD,iBAAA,WAAW,cAAc,UAAU;AACvC,cAAA,mBAAmB,MAAM,aAAa,yBAAyB,oBAAoB,QAAQ,MAAM,EAAE,OAAO,KAAA,CAAM;AAEtH,YAAI,qBAAqB,QAAW;AACnC,gBAAM,IAAI,kBAAkB,KAAK,WAAW,QAAQ,IAAI,YAAY;AAAA,QACrE;AAEA,cAAM,gBAAgB,iBAAiB;AACjC,cAAA,iBAAiB,MAAM,iBAAiB,sBAAsB,UAAU,EAAE,IAAI,eAAe,WAAW,KAAA,CAAM;AAC9G,cAAA,SAAS,gBAAgB,UAAU;AACnC,cAAA,EAAE,WAAW,YAAA,IAAgB,MAAM,MAAM,mBAAmB,MAAM,aAAa,0BAA0B,mBAAmB;AAAA,UACjI,SAAS,EAAE,KAAK,MAAM,GAAG;AAAA,UACzB,KAAK,OAAO;AAAA,UACZ,aAAa,QAAQ;AAAA,UACrB,UAAU;AAAA,YACT,YAAY,WAAW;AAAA,YACvB,OAAO,WAAW;AAAA,UACnB;AAAA,QACA,CAAA,CAAC;AAEF,cAAM,eAAe,YAAY,IAAI,CAAA,OAAM,GAAG,IAAI;AAE9C,YAAA,CAAC,aAAa,KAAK,CAAQ,SAAA,OAAO,IAAI,MAAM,IAAI,GAAG,SAAS,MAAM,GAAG;AAClE,gBAAA,IAAI,kBAAkB,KAAK,aAAa;AAAA,QAC/C;AAEA,YAAI,QAAQ,UAAU,CAAC,aAAa,KAAK,CAAA,SAAQ,OAAO,IAAI,MAAM,IAAI,GAAG,QAAQ,MAAM,GAAG;AACnF,gBAAA,IAAI,kBAAkB,KAAK,aAAa;AAAA,QAC/C;AAEkB,0BAAA,QAAQ,IAAI,IAAI;AAAA,MACnC;AAEA,UAAI,WAAW;AACf,eAAS,SAAS;AACT,eAAA,IAAI,UAAU,gBAAgB,sBAAsB;AACpD,eAAA,OAAO,SAAS,KAAK,SAAS,KAAK,eAAe,OAAO,eAAe,iBAAiB,CAAC,CAAC;AAAA,IAAA;AAAA,EAEtG;AACD;"}
|
|
@@ -48,15 +48,15 @@ class ExportExecutor {
|
|
|
48
48
|
yield* this.exportSchema(systemContext.client, systemMapping);
|
|
49
49
|
}
|
|
50
50
|
for (const stage of await systemContext.queryHandler.fetch(new engineSystemApi.StagesQuery())) {
|
|
51
|
-
const contentSchema = await projectContainer.contentSchemaResolver.getSchema(systemContext, stage.slug);
|
|
52
|
-
const contentMapping = this.contentSchemaTransferMappingFactory.createContentSchemaMapping(contentSchema);
|
|
51
|
+
const contentSchema = await projectContainer.contentSchemaResolver.getSchema({ db: systemContext, stage: stage.slug });
|
|
52
|
+
const contentMapping = this.contentSchemaTransferMappingFactory.createContentSchemaMapping(contentSchema.schema);
|
|
53
53
|
const contentDatabaseClient = projectContainer.connection.createClient(stage.schema, {});
|
|
54
54
|
yield [
|
|
55
55
|
"importContentSchemaBegin",
|
|
56
56
|
{
|
|
57
57
|
project: project.targetSlug ?? project.slug,
|
|
58
58
|
stage: stage.slug,
|
|
59
|
-
schemaVersion: contentSchema.version,
|
|
59
|
+
schemaVersion: contentSchema.meta.version ?? "0000-00-00-000000",
|
|
60
60
|
tables: Object.keys(contentMapping.tables)
|
|
61
61
|
}
|
|
62
62
|
];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExportExecutor.cjs","sources":["../../../../../packages/engine-http/src/transfer/ExportExecutor.ts"],"sourcesContent":["import { asyncIterableTransaction, Client, Compiler, Connection, wrapIdentifier } from '@contember/database'\nimport { Command } from './Command'\nimport { TransferMapping, TransferTableMapping } from './TransferMapping'\nimport { Model } from '@contember/schema'\nimport { ContentSchemaTransferMappingFactory } from './ContentSchemaTransferMappingFactory'\nimport { SystemSchemaTransferMappingFactory } from './SystemSchemaTransferMappingFactory'\nimport * as Typesafe from '@contember/typesafe'\nimport { StagesQuery } from '@contember/engine-system-api'\nimport { ProjectContainer } from '../project'\n\nexport type ExportRequest = ReturnType<typeof ExportRequest>\nexport const ExportRequest = Typesafe.object({\n\t// tenant: Typesafe.boolean,\n\tprojects: Typesafe.array(Typesafe.intersection(\n\t\tTypesafe.object({\n\t\t\tslug: Typesafe.string,\n\t\t\tsystem: Typesafe.boolean,\n\t\t}),\n\t\tTypesafe.partial({\n\t\t\ttargetSlug: Typesafe.string,\n\t\t}),\n\t)),\n})\n\nexport class ExportExecutor {\n\tconstructor(\n\t\tprivate readonly contentSchemaTransferMappingFactory: ContentSchemaTransferMappingFactory,\n\t\tprivate readonly systemSchemaTransferMappingFactory: SystemSchemaTransferMappingFactory,\n\t) {\n\t}\n\n\tasync* export(request: ExportRequest, projectContainers: Record<string, ProjectContainer>): AsyncIterable<Command> {\n\t\tfor (const project of request.projects) {\n\t\t\tconst projectContainer = projectContainers[project.slug]\n\t\t\tconst systemContext = projectContainer.systemDatabaseContext\n\n\t\t\tif (project.system) {\n\t\t\t\tconst systemMapping = this.systemSchemaTransferMappingFactory.build()\n\t\t\t\tyield ['importSystemSchemaBegin', { project: project.targetSlug ?? project.slug, tables: Object.keys(systemMapping.tables) }]\n\t\t\t\tyield* this.exportSchema(systemContext.client, systemMapping)\n\t\t\t}\n\n\t\t\tfor (const stage of await systemContext.queryHandler.fetch(new StagesQuery())) {\n\t\t\t\tconst contentSchema = await projectContainer.contentSchemaResolver.getSchema(systemContext, stage.slug)\n\t\t\t\tconst contentMapping = this.contentSchemaTransferMappingFactory.createContentSchemaMapping(contentSchema)\n\t\t\t\tconst contentDatabaseClient = projectContainer.connection.createClient(stage.schema, {})\n\n\t\t\t\tyield [\n\t\t\t\t\t'importContentSchemaBegin', {\n\t\t\t\t\t\tproject: project.targetSlug ?? project.slug,\n\t\t\t\t\t\tstage: stage.slug,\n\t\t\t\t\t\tschemaVersion: contentSchema.version,\n\t\t\t\t\t\ttables: Object.keys(contentMapping.tables),\n\t\t\t\t\t},\n\t\t\t\t]\n\n\t\t\t\tyield* this.exportSchema(contentDatabaseClient, contentMapping)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async* exportSchema(db: Client, mapping: TransferMapping): AsyncIterable<Command> {\n\t\t// eslint-disable-next-line @typescript-eslint/no-this-alias\n\t\tconst that = this\n\t\tyield* asyncIterableTransaction(db, async function* (db) {\n\t\t\tawait db.query('SET TRANSACTION ISOLATION LEVEL SERIALIZABLE READ ONLY DEFERRABLE')\n\t\t\tfor (const table of Object.values(mapping.tables)) {\n\t\t\t\tyield* that.exportSequences(db, table)\n\t\t\t\tyield* that.exportTable(db, table)\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate async* exportSequences(db: Client<Connection.TransactionLike>, table: TransferTableMapping): AsyncIterable<Command> {\n\t\tfor (const column of Object.values(table.columns)) {\n\t\t\tif (column.type === Model.ColumnType.Int && column.sequence) {\n\t\t\t\tconst seqNameResult = await db.query<{ name: string }>(\n\t\t\t\t\t'SELECT pg_get_serial_sequence(?, ?) AS name',\n\t\t\t\t\t[`${db.schema}.${table.name}`, column.name],\n\t\t\t\t)\n\n\t\t\t\tconst seqNameQuoted = seqNameResult.rows[0].name.split('.').map(it => wrapIdentifier(it)).join('.')\n\t\t\t\tconst seqValueResult = await db.query<{ last_value: number|string }>(`SELECT last_value FROM ${seqNameQuoted}`)\n\t\t\t\tconst seqValue = seqValueResult.rows[0].last_value\n\t\t\t\tyield ['importSequence', { table: table.name, column: column.name, value: Number(seqValue) }]\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async* exportTable(db: Client<Connection.TransactionLike>, table: TransferTableMapping): AsyncIterable<Command> {\n\t\tconst DB_FETCH_BATCH_SIZE = 100\n\t\tconst query = (table.createSelect ?? this.buildQuery)(db, table)\n\t\tlet empty = true\n\n\t\tfor await (const row of this.cursorQuery(db, DB_FETCH_BATCH_SIZE, query.sql, query.parameters)) {\n\t\t\tif (empty) {\n\t\t\t\tyield ['insertBegin', { table: table.name, columns: Object.keys(table.columns) }]\n\t\t\t\tempty = false\n\t\t\t}\n\n\t\t\tyield ['insertRow', Object.values(row)]\n\t\t}\n\n\t\tif (!empty) {\n\t\t\tyield ['insertEnd']\n\t\t}\n\t}\n\n\tprivate buildQuery(db: Client<Connection.TransactionLike>, table: TransferTableMapping) {\n\t\tlet builder = db.selectBuilder().from(table.name)\n\n\t\tfor (const column of Object.values(table.columns)) {\n\t\t\tif (column.type === Model.ColumnType.Json || column.type === Model.ColumnType.Date || column.type === Model.ColumnType.DateTime) {\n\t\t\t\tbuilder = builder.select(expr => expr.raw(`${wrapIdentifier(column.name)}::text`))\n\n\t\t\t} else {\n\t\t\t\tbuilder = builder.select(column.name)\n\t\t\t}\n\t\t}\n\n\t\tconst namespaceContext = new Compiler.Context(db.schema, new Set())\n\t\treturn builder.createQuery(namespaceContext)\n\t}\n\n\tprivate async* cursorQuery(db: Client<Connection.TransactionLike>, batchSize: number, sql: string, parameters: readonly any[] = []) {\n\t\tawait db.query(`DECLARE contember_cursor NO SCROLL CURSOR FOR ${sql}`, parameters)\n\n\t\tconst fetchSql = `FETCH ${Number(batchSize)} FROM contember_cursor`\n\t\tlet resultPromise: Promise<Connection.Result> | null = db.query(fetchSql)\n\n\t\twhile (resultPromise !== null) {\n\t\t\tconst result: Connection.Result = await resultPromise\n\t\t\tresultPromise = result.rowCount < batchSize ? null : db.query(fetchSql) // pipeline\n\t\t\tyield* result.rows\n\t\t}\n\n\t\tawait db.query(`CLOSE contember_cursor`)\n\t}\n}\n"],"names":["Typesafe","StagesQuery","asyncIterableTransaction","db","Model","wrapIdentifier","Compiler"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAWa,MAAA,gBAAgBA,oBAAS,OAAO;AAAA;AAAA,EAE5C,UAAUA,oBAAS,MAAMA,oBAAS;AAAA,IACjCA,oBAAS,OAAO;AAAA,MACf,MAAMA,oBAAS;AAAA,MACf,QAAQA,oBAAS;AAAA,IAAA,CACjB;AAAA,IACDA,oBAAS,QAAQ;AAAA,MAChB,YAAYA,oBAAS;AAAA,IAAA,CACrB;AAAA,EAAA,CACD;AACF,CAAC;AAEM,MAAM,eAAe;AAAA,EAC3B,YACkB,qCACA,oCAChB;AAFgB,SAAA,sCAAA;AACA,SAAA,qCAAA;AAAA,EAElB;AAAA,EAEA,OAAO,OAAO,SAAwB,mBAA6E;AACvG,eAAA,WAAW,QAAQ,UAAU;AACjC,YAAA,mBAAmB,kBAAkB,QAAQ,IAAI;AACvD,YAAM,gBAAgB,iBAAiB;AAEvC,UAAI,QAAQ,QAAQ;AACb,cAAA,gBAAgB,KAAK,mCAAmC,MAAM;AACpE,cAAM,CAAC,2BAA2B,EAAE,SAAS,QAAQ,cAAc,QAAQ,MAAM,QAAQ,OAAO,KAAK,cAAc,MAAM,EAAG,CAAA;AAC5H,eAAO,KAAK,aAAa,cAAc,QAAQ,aAAa;AAAA,MAC7D;AAEW,iBAAA,SAAS,MAAM,cAAc,aAAa,MAAM,IAAIC,gBAAA,YAAA,CAAa,GAAG;
|
|
1
|
+
{"version":3,"file":"ExportExecutor.cjs","sources":["../../../../../packages/engine-http/src/transfer/ExportExecutor.ts"],"sourcesContent":["import { asyncIterableTransaction, Client, Compiler, Connection, wrapIdentifier } from '@contember/database'\nimport { Command } from './Command'\nimport { TransferMapping, TransferTableMapping } from './TransferMapping'\nimport { Model } from '@contember/schema'\nimport { ContentSchemaTransferMappingFactory } from './ContentSchemaTransferMappingFactory'\nimport { SystemSchemaTransferMappingFactory } from './SystemSchemaTransferMappingFactory'\nimport * as Typesafe from '@contember/typesafe'\nimport { StagesQuery } from '@contember/engine-system-api'\nimport { ProjectContainer } from '../project'\n\nexport type ExportRequest = ReturnType<typeof ExportRequest>\nexport const ExportRequest = Typesafe.object({\n\t// tenant: Typesafe.boolean,\n\tprojects: Typesafe.array(Typesafe.intersection(\n\t\tTypesafe.object({\n\t\t\tslug: Typesafe.string,\n\t\t\tsystem: Typesafe.boolean,\n\t\t}),\n\t\tTypesafe.partial({\n\t\t\ttargetSlug: Typesafe.string,\n\t\t}),\n\t)),\n})\n\nexport class ExportExecutor {\n\tconstructor(\n\t\tprivate readonly contentSchemaTransferMappingFactory: ContentSchemaTransferMappingFactory,\n\t\tprivate readonly systemSchemaTransferMappingFactory: SystemSchemaTransferMappingFactory,\n\t) {\n\t}\n\n\tasync* export(request: ExportRequest, projectContainers: Record<string, ProjectContainer>): AsyncIterable<Command> {\n\t\tfor (const project of request.projects) {\n\t\t\tconst projectContainer = projectContainers[project.slug]\n\t\t\tconst systemContext = projectContainer.systemDatabaseContext\n\n\t\t\tif (project.system) {\n\t\t\t\tconst systemMapping = this.systemSchemaTransferMappingFactory.build()\n\t\t\t\tyield ['importSystemSchemaBegin', { project: project.targetSlug ?? project.slug, tables: Object.keys(systemMapping.tables) }]\n\t\t\t\tyield* this.exportSchema(systemContext.client, systemMapping)\n\t\t\t}\n\n\t\t\tfor (const stage of await systemContext.queryHandler.fetch(new StagesQuery())) {\n\t\t\t\tconst contentSchema = await projectContainer.contentSchemaResolver.getSchema({ db: systemContext, stage: stage.slug })\n\t\t\t\tconst contentMapping = this.contentSchemaTransferMappingFactory.createContentSchemaMapping(contentSchema.schema)\n\t\t\t\tconst contentDatabaseClient = projectContainer.connection.createClient(stage.schema, {})\n\n\t\t\t\tyield [\n\t\t\t\t\t'importContentSchemaBegin', {\n\t\t\t\t\t\tproject: project.targetSlug ?? project.slug,\n\t\t\t\t\t\tstage: stage.slug,\n\t\t\t\t\t\tschemaVersion: contentSchema.meta.version ?? '0000-00-00-000000',\n\t\t\t\t\t\ttables: Object.keys(contentMapping.tables),\n\t\t\t\t\t},\n\t\t\t\t]\n\n\t\t\t\tyield* this.exportSchema(contentDatabaseClient, contentMapping)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async* exportSchema(db: Client, mapping: TransferMapping): AsyncIterable<Command> {\n\t\t// eslint-disable-next-line @typescript-eslint/no-this-alias\n\t\tconst that = this\n\t\tyield* asyncIterableTransaction(db, async function* (db) {\n\t\t\tawait db.query('SET TRANSACTION ISOLATION LEVEL SERIALIZABLE READ ONLY DEFERRABLE')\n\t\t\tfor (const table of Object.values(mapping.tables)) {\n\t\t\t\tyield* that.exportSequences(db, table)\n\t\t\t\tyield* that.exportTable(db, table)\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate async* exportSequences(db: Client<Connection.TransactionLike>, table: TransferTableMapping): AsyncIterable<Command> {\n\t\tfor (const column of Object.values(table.columns)) {\n\t\t\tif (column.type === Model.ColumnType.Int && column.sequence) {\n\t\t\t\tconst seqNameResult = await db.query<{ name: string }>(\n\t\t\t\t\t'SELECT pg_get_serial_sequence(?, ?) AS name',\n\t\t\t\t\t[`${db.schema}.${table.name}`, column.name],\n\t\t\t\t)\n\n\t\t\t\tconst seqNameQuoted = seqNameResult.rows[0].name.split('.').map(it => wrapIdentifier(it)).join('.')\n\t\t\t\tconst seqValueResult = await db.query<{ last_value: number|string }>(`SELECT last_value FROM ${seqNameQuoted}`)\n\t\t\t\tconst seqValue = seqValueResult.rows[0].last_value\n\t\t\t\tyield ['importSequence', { table: table.name, column: column.name, value: Number(seqValue) }]\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async* exportTable(db: Client<Connection.TransactionLike>, table: TransferTableMapping): AsyncIterable<Command> {\n\t\tconst DB_FETCH_BATCH_SIZE = 100\n\t\tconst query = (table.createSelect ?? this.buildQuery)(db, table)\n\t\tlet empty = true\n\n\t\tfor await (const row of this.cursorQuery(db, DB_FETCH_BATCH_SIZE, query.sql, query.parameters)) {\n\t\t\tif (empty) {\n\t\t\t\tyield ['insertBegin', { table: table.name, columns: Object.keys(table.columns) }]\n\t\t\t\tempty = false\n\t\t\t}\n\n\t\t\tyield ['insertRow', Object.values(row)]\n\t\t}\n\n\t\tif (!empty) {\n\t\t\tyield ['insertEnd']\n\t\t}\n\t}\n\n\tprivate buildQuery(db: Client<Connection.TransactionLike>, table: TransferTableMapping) {\n\t\tlet builder = db.selectBuilder().from(table.name)\n\n\t\tfor (const column of Object.values(table.columns)) {\n\t\t\tif (column.type === Model.ColumnType.Json || column.type === Model.ColumnType.Date || column.type === Model.ColumnType.DateTime) {\n\t\t\t\tbuilder = builder.select(expr => expr.raw(`${wrapIdentifier(column.name)}::text`))\n\n\t\t\t} else {\n\t\t\t\tbuilder = builder.select(column.name)\n\t\t\t}\n\t\t}\n\n\t\tconst namespaceContext = new Compiler.Context(db.schema, new Set())\n\t\treturn builder.createQuery(namespaceContext)\n\t}\n\n\tprivate async* cursorQuery(db: Client<Connection.TransactionLike>, batchSize: number, sql: string, parameters: readonly any[] = []) {\n\t\tawait db.query(`DECLARE contember_cursor NO SCROLL CURSOR FOR ${sql}`, parameters)\n\n\t\tconst fetchSql = `FETCH ${Number(batchSize)} FROM contember_cursor`\n\t\tlet resultPromise: Promise<Connection.Result> | null = db.query(fetchSql)\n\n\t\twhile (resultPromise !== null) {\n\t\t\tconst result: Connection.Result = await resultPromise\n\t\t\tresultPromise = result.rowCount < batchSize ? null : db.query(fetchSql) // pipeline\n\t\t\tyield* result.rows\n\t\t}\n\n\t\tawait db.query(`CLOSE contember_cursor`)\n\t}\n}\n"],"names":["Typesafe","StagesQuery","asyncIterableTransaction","db","Model","wrapIdentifier","Compiler"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAWa,MAAA,gBAAgBA,oBAAS,OAAO;AAAA;AAAA,EAE5C,UAAUA,oBAAS,MAAMA,oBAAS;AAAA,IACjCA,oBAAS,OAAO;AAAA,MACf,MAAMA,oBAAS;AAAA,MACf,QAAQA,oBAAS;AAAA,IAAA,CACjB;AAAA,IACDA,oBAAS,QAAQ;AAAA,MAChB,YAAYA,oBAAS;AAAA,IAAA,CACrB;AAAA,EAAA,CACD;AACF,CAAC;AAEM,MAAM,eAAe;AAAA,EAC3B,YACkB,qCACA,oCAChB;AAFgB,SAAA,sCAAA;AACA,SAAA,qCAAA;AAAA,EAElB;AAAA,EAEA,OAAO,OAAO,SAAwB,mBAA6E;AACvG,eAAA,WAAW,QAAQ,UAAU;AACjC,YAAA,mBAAmB,kBAAkB,QAAQ,IAAI;AACvD,YAAM,gBAAgB,iBAAiB;AAEvC,UAAI,QAAQ,QAAQ;AACb,cAAA,gBAAgB,KAAK,mCAAmC,MAAM;AACpE,cAAM,CAAC,2BAA2B,EAAE,SAAS,QAAQ,cAAc,QAAQ,MAAM,QAAQ,OAAO,KAAK,cAAc,MAAM,EAAG,CAAA;AAC5H,eAAO,KAAK,aAAa,cAAc,QAAQ,aAAa;AAAA,MAC7D;AAEW,iBAAA,SAAS,MAAM,cAAc,aAAa,MAAM,IAAIC,gBAAA,YAAA,CAAa,GAAG;AACxE,cAAA,gBAAgB,MAAM,iBAAiB,sBAAsB,UAAU,EAAE,IAAI,eAAe,OAAO,MAAM,KAAM,CAAA;AACrH,cAAM,iBAAiB,KAAK,oCAAoC,2BAA2B,cAAc,MAAM;AAC/G,cAAM,wBAAwB,iBAAiB,WAAW,aAAa,MAAM,QAAQ,CAAA,CAAE;AAEjF,cAAA;AAA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BAAkB,MAAM;AAC9B,YAAM,SAA4B,MAAM;AACxC,sBAAgB,OAAO,WAAW,YAAY,OAAO,GAAG,MAAM,QAAQ;AACtE,aAAO,OAAO;AAAA,IACf;AAEM,UAAA,GAAG,MAAM,wBAAwB;AAAA,EACxC;AACD;;;"}
|
|
@@ -29,15 +29,15 @@ class ExportExecutor {
|
|
|
29
29
|
yield* this.exportSchema(systemContext.client, systemMapping);
|
|
30
30
|
}
|
|
31
31
|
for (const stage of await systemContext.queryHandler.fetch(new StagesQuery())) {
|
|
32
|
-
const contentSchema = await projectContainer.contentSchemaResolver.getSchema(systemContext, stage.slug);
|
|
33
|
-
const contentMapping = this.contentSchemaTransferMappingFactory.createContentSchemaMapping(contentSchema);
|
|
32
|
+
const contentSchema = await projectContainer.contentSchemaResolver.getSchema({ db: systemContext, stage: stage.slug });
|
|
33
|
+
const contentMapping = this.contentSchemaTransferMappingFactory.createContentSchemaMapping(contentSchema.schema);
|
|
34
34
|
const contentDatabaseClient = projectContainer.connection.createClient(stage.schema, {});
|
|
35
35
|
yield [
|
|
36
36
|
"importContentSchemaBegin",
|
|
37
37
|
{
|
|
38
38
|
project: project.targetSlug ?? project.slug,
|
|
39
39
|
stage: stage.slug,
|
|
40
|
-
schemaVersion: contentSchema.version,
|
|
40
|
+
schemaVersion: contentSchema.meta.version ?? "0000-00-00-000000",
|
|
41
41
|
tables: Object.keys(contentMapping.tables)
|
|
42
42
|
}
|
|
43
43
|
];
|