@contember/engine-server 0.12.0-beta.2 → 1.0.0-alpha.0
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/alpine.dockerfile +2 -2
- package/debian.dockerfile +1 -1
- package/dist/src/MasterContainer.d.ts +4 -1
- package/dist/src/MasterContainer.d.ts.map +1 -1
- package/dist/src/MasterContainer.js +60 -31
- package/dist/src/MasterContainer.js.map +1 -1
- package/dist/src/bootstrap/Initializer.d.ts +4 -6
- package/dist/src/bootstrap/Initializer.d.ts.map +1 -1
- package/dist/src/bootstrap/Initializer.js +10 -11
- package/dist/src/bootstrap/Initializer.js.map +1 -1
- package/dist/src/config/config.d.ts +43 -22
- package/dist/src/config/config.d.ts.map +1 -1
- package/dist/src/config/config.js +135 -241
- package/dist/src/config/config.js.map +1 -1
- package/dist/src/http/ShowMetricsMiddleware.js +1 -1
- package/dist/src/http/ShowMetricsMiddleware.js.map +1 -1
- package/dist/src/http/index.d.ts +0 -1
- package/dist/src/http/index.d.ts.map +1 -1
- package/dist/src/http/index.js +0 -1
- package/dist/src/http/index.js.map +1 -1
- package/dist/src/project/ProjectContainer.d.ts +1 -1
- package/dist/src/project/ProjectContainer.d.ts.map +1 -1
- package/dist/src/project/ProjectContainerResolver.d.ts +13 -10
- package/dist/src/project/ProjectContainerResolver.d.ts.map +1 -1
- package/dist/src/project/ProjectContainerResolver.js +48 -33
- package/dist/src/project/ProjectContainerResolver.js.map +1 -1
- package/dist/src/project/ProjectGroupState.d.ts +18 -0
- package/dist/src/project/ProjectGroupState.d.ts.map +1 -0
- package/dist/src/project/ProjectGroupState.js +30 -0
- package/dist/src/project/ProjectGroupState.js.map +1 -0
- package/dist/src/project/ProjectInitializer.d.ts +4 -10
- package/dist/src/project/ProjectInitializer.d.ts.map +1 -1
- package/dist/src/project/ProjectInitializer.js +5 -19
- package/dist/src/project/ProjectInitializer.js.map +1 -1
- package/dist/src/project/ProjectSchemaResolver.d.ts +5 -5
- package/dist/src/project/ProjectSchemaResolver.d.ts.map +1 -1
- package/dist/src/project/ProjectSchemaResolver.js +4 -4
- package/dist/src/project/ProjectSchemaResolver.js.map +1 -1
- package/dist/src/start.js +22 -14
- package/dist/src/start.js.map +1 -1
- package/dist/src/tsconfig.tsbuildinfo +1 -1
- package/dist/src/utils/cluster.js +1 -1
- package/dist/src/utils/cluster.js.map +1 -1
- package/dist/tests/cases/http.js +12 -11
- package/dist/tests/cases/http.js.map +1 -1
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/package.json +21 -21
- package/src/MasterContainer.ts +106 -55
- package/src/bootstrap/Initializer.ts +10 -17
- package/src/config/config.ts +159 -289
- package/src/http/index.ts +0 -1
- package/src/project/ProjectContainerResolver.ts +58 -35
- package/src/project/ProjectGroupState.ts +33 -0
- package/src/project/ProjectInitializer.ts +9 -23
- package/src/project/ProjectSchemaResolver.ts +12 -7
- package/src/start.ts +13 -6
- package/tests/cases/http.ts +7 -2
- package/dist/src/http/RootMiddleware.d.ts +0 -9
- package/dist/src/http/RootMiddleware.d.ts.map +0 -1
- package/dist/src/http/RootMiddleware.js +0 -33
- package/dist/src/http/RootMiddleware.js.map +0 -1
- package/src/http/RootMiddleware.ts +0 -53
|
@@ -1,31 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
ProjectGroup,
|
|
3
|
+
ProjectInitializer as ProjectInitializerInterface,
|
|
4
|
+
ProjectWithSecrets,
|
|
5
|
+
} from '@contember/engine-tenant-api'
|
|
3
6
|
import { ProjectContainerResolver } from './ProjectContainerResolver'
|
|
4
|
-
import { ProjectInitializer as SystemProjectInitializer } from '@contember/engine-system-api'
|
|
5
7
|
|
|
6
8
|
export class ProjectInitializer implements ProjectInitializerInterface {
|
|
7
9
|
constructor(
|
|
8
10
|
private readonly projectContainerResolver: ProjectContainerResolver,
|
|
9
|
-
private readonly systemProjectInitializer: SystemProjectInitializer,
|
|
10
11
|
) {}
|
|
11
12
|
|
|
12
|
-
async initializeProject(project: ProjectWithSecrets) {
|
|
13
|
-
|
|
14
|
-
if (!container) {
|
|
15
|
-
throw new Error('Should not happen')
|
|
16
|
-
}
|
|
17
|
-
const log: string[] = []
|
|
18
|
-
try {
|
|
19
|
-
await this.systemProjectInitializer.initialize(
|
|
20
|
-
container.systemDatabaseContextFactory,
|
|
21
|
-
container.project,
|
|
22
|
-
new Logger(log.push),
|
|
23
|
-
)
|
|
24
|
-
} catch (e) {
|
|
25
|
-
await this.projectContainerResolver.destroyContainer(project.slug)
|
|
26
|
-
throw e
|
|
27
|
-
}
|
|
28
|
-
return { log }
|
|
13
|
+
async initializeProject(projectGroup: ProjectGroup, project: ProjectWithSecrets) {
|
|
14
|
+
await this.projectContainerResolver.createProjectContainer(projectGroup, project)
|
|
29
15
|
}
|
|
30
16
|
}
|
|
31
17
|
|
|
@@ -36,10 +22,10 @@ export class ProjectInitializerProxy implements ProjectInitializerInterface {
|
|
|
36
22
|
this.initializer = initializer
|
|
37
23
|
}
|
|
38
24
|
|
|
39
|
-
initializeProject(project: ProjectWithSecrets) {
|
|
25
|
+
initializeProject(projectGroup: ProjectGroup, project: ProjectWithSecrets) {
|
|
40
26
|
if (!this.initializer) {
|
|
41
27
|
throw new Error('Initializer is not set')
|
|
42
28
|
}
|
|
43
|
-
return this.initializer.initializeProject(project)
|
|
29
|
+
return this.initializer.initializeProject(projectGroup, project)
|
|
44
30
|
}
|
|
45
31
|
}
|
|
@@ -1,15 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
DatabaseContext,
|
|
3
|
+
ProjectGroup,
|
|
4
|
+
ProjectSchemaResolver as ProjectSchemaResolverInterface,
|
|
5
|
+
} from '@contember/engine-tenant-api'
|
|
2
6
|
import { SchemaVersionBuilder } from '@contember/engine-system-api'
|
|
3
|
-
import {
|
|
7
|
+
import { ProjectContainerResolver } from '@contember/engine-http'
|
|
4
8
|
import { Schema } from '@contember/schema'
|
|
5
9
|
|
|
6
10
|
export class ProjectSchemaResolver implements ProjectSchemaResolverInterface {
|
|
7
11
|
constructor(
|
|
8
|
-
private readonly projectContainerResolver:
|
|
12
|
+
private readonly projectContainerResolver: ProjectContainerResolver,
|
|
9
13
|
private readonly schemaVersionBuilder: SchemaVersionBuilder,
|
|
10
14
|
) {}
|
|
11
|
-
|
|
12
|
-
|
|
15
|
+
|
|
16
|
+
async getSchema(projectGroup: ProjectGroup, slug: string) {
|
|
17
|
+
const container = await this.projectContainerResolver.getProjectContainer(projectGroup, slug)
|
|
13
18
|
if (!container) {
|
|
14
19
|
return undefined
|
|
15
20
|
}
|
|
@@ -25,10 +30,10 @@ export class ProjectSchemaResolverProxy implements ProjectSchemaResolverInterfac
|
|
|
25
30
|
this.resolver = resolver
|
|
26
31
|
}
|
|
27
32
|
|
|
28
|
-
getSchema(projectSlug: string): Promise<Schema | undefined> {
|
|
33
|
+
getSchema(projectGroup: ProjectGroup, projectSlug: string): Promise<Schema | undefined> {
|
|
29
34
|
if (!this.resolver) {
|
|
30
35
|
throw new Error('Resolved is not set')
|
|
31
36
|
}
|
|
32
|
-
return this.resolver.getSchema(projectSlug)
|
|
37
|
+
return this.resolver.getSchema(projectGroup, projectSlug)
|
|
33
38
|
}
|
|
34
39
|
}
|
package/src/start.ts
CHANGED
|
@@ -68,7 +68,7 @@ const createServerTerminator = (): Server[] => {
|
|
|
68
68
|
if (process.argv[2] === 'validate') {
|
|
69
69
|
process.exit(0)
|
|
70
70
|
}
|
|
71
|
-
initSentry(config.server.logging.sentry?.dsn)
|
|
71
|
+
'sentry' in config.server.logging && initSentry(config.server.logging.sentry?.dsn)
|
|
72
72
|
const workerConfig = config.server.workerCount || 1
|
|
73
73
|
|
|
74
74
|
const workerCount = workerConfig === 'auto' ? os.cpus().length : Number(workerConfig)
|
|
@@ -95,15 +95,22 @@ const createServerTerminator = (): Server[] => {
|
|
|
95
95
|
console.log(`Monitoring running on http://localhost:${monitoringPort}`)
|
|
96
96
|
}),
|
|
97
97
|
)
|
|
98
|
-
|
|
98
|
+
if (!config.server.projectGroup) {
|
|
99
|
+
initializedProjects = await container.initializer.initialize()
|
|
100
|
+
}
|
|
99
101
|
}
|
|
100
102
|
|
|
101
103
|
const port = config.server.port
|
|
102
104
|
const printStarted = () => {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
if (config.server.projectGroup) {
|
|
106
|
+
// eslint-disable-next-line no-console
|
|
107
|
+
console.log('Contember Cloud running')
|
|
108
|
+
} else {
|
|
109
|
+
// eslint-disable-next-line no-console
|
|
110
|
+
console.log(`Contember API running on http://localhost:${port}`)
|
|
111
|
+
// eslint-disable-next-line no-console
|
|
112
|
+
console.log(initializedProjects.length ? `Initialized projects: ${initializedProjects.join(', ')}` : 'No project initialized')
|
|
113
|
+
}
|
|
107
114
|
}
|
|
108
115
|
|
|
109
116
|
if (isClusterMode && cluster.isMaster) {
|
package/tests/cases/http.ts
CHANGED
|
@@ -6,6 +6,10 @@ import * as assert from 'uvu/assert'
|
|
|
6
6
|
import { test } from 'uvu'
|
|
7
7
|
import prom from 'prom-client'
|
|
8
8
|
import { MigrationFilesManager, MigrationsResolver } from '@contember/schema-migrations'
|
|
9
|
+
import { Logger } from '@contember/engine-common'
|
|
10
|
+
import { CreateProjectCommand, DatabaseContext } from '@contember/engine-tenant-api'
|
|
11
|
+
import { ConflictActionType, InsertBuilder } from '@contember/database'
|
|
12
|
+
import uuid from 'uuid'
|
|
9
13
|
|
|
10
14
|
const dbCredentials = (dbName: string) => {
|
|
11
15
|
return {
|
|
@@ -44,6 +48,7 @@ const createContainer = (debug: boolean) => {
|
|
|
44
48
|
rootToken,
|
|
45
49
|
loginToken,
|
|
46
50
|
},
|
|
51
|
+
secrets: {},
|
|
47
52
|
},
|
|
48
53
|
server: {
|
|
49
54
|
logging: {},
|
|
@@ -98,14 +103,14 @@ test.before(async () => {
|
|
|
98
103
|
try {
|
|
99
104
|
const connection = await recreateDatabase(String(process.env.TEST_DB_NAME))
|
|
100
105
|
await connection.end()
|
|
101
|
-
const
|
|
102
|
-
await connection2.end()
|
|
106
|
+
const tenantConnection = await recreateDatabase(String(process.env.TEST_DB_NAME_TENANT))
|
|
103
107
|
const migrationsResolver = new MigrationsResolver(
|
|
104
108
|
MigrationFilesManager.createForProject(getExampleProjectDirectory(), 'sample'),
|
|
105
109
|
)
|
|
106
110
|
const container = createContainer(false)
|
|
107
111
|
await container.initializer.initialize()
|
|
108
112
|
await container.initializer.createProject(projectConfig, await migrationsResolver.getMigrations())
|
|
113
|
+
await tenantConnection.end()
|
|
109
114
|
} catch (e) {
|
|
110
115
|
// eslint-disable-next-line no-console
|
|
111
116
|
console.error(e)
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { KoaMiddleware, ServicesState } from '@contember/engine-http';
|
|
2
|
-
import prom from 'prom-client';
|
|
3
|
-
import { Config } from '../config/config';
|
|
4
|
-
import { SystemGraphQLMiddlewareFactory, TenantGraphQLMiddlewareFactory } from '@contember/engine-http';
|
|
5
|
-
export declare const createRootMiddleware: (debug: boolean, version: string, services: ServicesState & {
|
|
6
|
-
tenantGraphQlMiddlewareFactory: TenantGraphQLMiddlewareFactory;
|
|
7
|
-
systemGraphQLMiddlewareFactory: SystemGraphQLMiddlewareFactory;
|
|
8
|
-
}, prometheusRegistry: prom.Registry, httpConfig: Config['server']['http']) => KoaMiddleware<any>;
|
|
9
|
-
//# sourceMappingURL=RootMiddleware.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RootMiddleware.d.ts","sourceRoot":"","sources":["../../../src/http/RootMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAYN,aAAa,EAEb,aAAa,EACb,MAAM,wBAAwB,CAAA;AAC/B,OAAO,IAAI,MAAM,aAAa,CAAA;AAI9B,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACzC,OAAO,EAAE,8BAA8B,EAAE,8BAA8B,EAAE,MAAM,wBAAwB,CAAA;AAEvG,eAAO,MAAM,oBAAoB,UACzB,OAAO,WACL,MAAM,YACL,aAAa,GAAG;IACzB,8BAA8B,EAAE,8BAA8B,CAAA;IAC9D,8BAA8B,EAAE,8BAA8B,CAAA;CAC9D,sBACmB,KAAK,QAAQ,cACrB,MAAM,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAClC,cAAc,GAAG,CAoBnB,CAAA"}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createRootMiddleware = void 0;
|
|
7
|
-
const engine_http_1 = require("@contember/engine-http");
|
|
8
|
-
const koa_compress_1 = __importDefault(require("koa-compress"));
|
|
9
|
-
const koa_bodyparser_1 = __importDefault(require("koa-bodyparser"));
|
|
10
|
-
const CollectHttpMetricsMiddelware_1 = require("./CollectHttpMetricsMiddelware");
|
|
11
|
-
const createRootMiddleware = (debug, version, services, prometheusRegistry, httpConfig) => {
|
|
12
|
-
return engine_http_1.compose([
|
|
13
|
-
koa_compress_1.default({
|
|
14
|
-
br: false,
|
|
15
|
-
}),
|
|
16
|
-
koa_bodyparser_1.default({
|
|
17
|
-
jsonLimit: httpConfig.requestBodySize || '1mb',
|
|
18
|
-
}),
|
|
19
|
-
engine_http_1.createPoweredByHeaderMiddleware(debug, version),
|
|
20
|
-
CollectHttpMetricsMiddelware_1.createColllectHttpMetricsMiddleware(prometheusRegistry),
|
|
21
|
-
engine_http_1.createDebugInfoMiddleware(debug),
|
|
22
|
-
engine_http_1.createServicesProviderMiddleware(services),
|
|
23
|
-
engine_http_1.createErrorResponseMiddleware(),
|
|
24
|
-
engine_http_1.createTimerMiddleware(),
|
|
25
|
-
engine_http_1.route('/playground$', engine_http_1.createPlaygroundMiddleware()),
|
|
26
|
-
engine_http_1.createHomepageMiddleware(),
|
|
27
|
-
engine_http_1.createContentMiddleware(),
|
|
28
|
-
engine_http_1.createTenantMiddleware(services.tenantGraphQlMiddlewareFactory),
|
|
29
|
-
engine_http_1.createSystemMiddleware(services.systemGraphQLMiddlewareFactory),
|
|
30
|
-
]);
|
|
31
|
-
};
|
|
32
|
-
exports.createRootMiddleware = createRootMiddleware;
|
|
33
|
-
//# sourceMappingURL=RootMiddleware.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RootMiddleware.js","sourceRoot":"","sources":["../../../src/http/RootMiddleware.ts"],"names":[],"mappings":";;;;;;AAAA,wDAe+B;AAE/B,gEAAsC;AACtC,oEAAuC;AACvC,iFAAoF;AAI7E,MAAM,oBAAoB,GAAG,CACnC,KAAc,EACd,OAAe,EACf,QAGC,EACD,kBAAiC,EACjC,UAAoC,EACf,EAAE;IACvB,OAAO,qBAAO,CAAC;QACd,sBAAW,CAAC;YACX,EAAE,EAAE,KAAK;SACT,CAAC;QACF,wBAAU,CAAC;YACV,SAAS,EAAE,UAAU,CAAC,eAAe,IAAI,KAAK;SAC9C,CAAC;QACF,6CAA+B,CAAC,KAAK,EAAE,OAAO,CAAC;QAC/C,kEAAmC,CAAC,kBAAkB,CAAC;QACvD,uCAAyB,CAAC,KAAK,CAAC;QAChC,8CAAgC,CAAC,QAAQ,CAAC;QAC1C,2CAA6B,EAAE;QAC/B,mCAAqB,EAAE;QACvB,mBAAK,CAAC,cAAc,EAAE,wCAA0B,EAAE,CAAC;QACnD,sCAAwB,EAAE;QAC1B,qCAAuB,EAAE;QACzB,oCAAsB,CAAC,QAAQ,CAAC,8BAA8B,CAAC;QAC/D,oCAAsB,CAAC,QAAQ,CAAC,8BAA8B,CAAC;KAC/D,CAAC,CAAA;AACH,CAAC,CAAA;AA7BY,QAAA,oBAAoB,wBA6BhC"}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
compose,
|
|
3
|
-
createContentMiddleware,
|
|
4
|
-
createDebugInfoMiddleware,
|
|
5
|
-
createErrorResponseMiddleware,
|
|
6
|
-
createHomepageMiddleware,
|
|
7
|
-
createPlaygroundMiddleware,
|
|
8
|
-
createPoweredByHeaderMiddleware,
|
|
9
|
-
createServicesProviderMiddleware,
|
|
10
|
-
createSystemMiddleware,
|
|
11
|
-
createTenantMiddleware,
|
|
12
|
-
createTimerMiddleware,
|
|
13
|
-
KoaMiddleware,
|
|
14
|
-
route,
|
|
15
|
-
ServicesState,
|
|
16
|
-
} from '@contember/engine-http'
|
|
17
|
-
import prom from 'prom-client'
|
|
18
|
-
import koaCompress from 'koa-compress'
|
|
19
|
-
import bodyParser from 'koa-bodyparser'
|
|
20
|
-
import { createColllectHttpMetricsMiddleware } from './CollectHttpMetricsMiddelware'
|
|
21
|
-
import { Config } from '../config/config'
|
|
22
|
-
import { SystemGraphQLMiddlewareFactory, TenantGraphQLMiddlewareFactory } from '@contember/engine-http'
|
|
23
|
-
|
|
24
|
-
export const createRootMiddleware = (
|
|
25
|
-
debug: boolean,
|
|
26
|
-
version: string,
|
|
27
|
-
services: ServicesState & {
|
|
28
|
-
tenantGraphQlMiddlewareFactory: TenantGraphQLMiddlewareFactory
|
|
29
|
-
systemGraphQLMiddlewareFactory: SystemGraphQLMiddlewareFactory
|
|
30
|
-
},
|
|
31
|
-
prometheusRegistry: prom.Registry,
|
|
32
|
-
httpConfig: Config['server']['http'],
|
|
33
|
-
): KoaMiddleware<any> => {
|
|
34
|
-
return compose([
|
|
35
|
-
koaCompress({
|
|
36
|
-
br: false,
|
|
37
|
-
}),
|
|
38
|
-
bodyParser({
|
|
39
|
-
jsonLimit: httpConfig.requestBodySize || '1mb',
|
|
40
|
-
}),
|
|
41
|
-
createPoweredByHeaderMiddleware(debug, version),
|
|
42
|
-
createColllectHttpMetricsMiddleware(prometheusRegistry),
|
|
43
|
-
createDebugInfoMiddleware(debug),
|
|
44
|
-
createServicesProviderMiddleware(services),
|
|
45
|
-
createErrorResponseMiddleware(),
|
|
46
|
-
createTimerMiddleware(),
|
|
47
|
-
route('/playground$', createPlaygroundMiddleware()),
|
|
48
|
-
createHomepageMiddleware(),
|
|
49
|
-
createContentMiddleware(),
|
|
50
|
-
createTenantMiddleware(services.tenantGraphQlMiddlewareFactory),
|
|
51
|
-
createSystemMiddleware(services.systemGraphQLMiddlewareFactory),
|
|
52
|
-
])
|
|
53
|
-
}
|