@contember/engine-http 2.2.0-alpha.11 → 2.2.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/index.cjs +1 -0
- package/dist/development/index.cjs.map +1 -1
- package/dist/development/index.js +2 -1
- package/dist/development/src/content/GraphQlSchemaFactory.cjs +5 -6
- package/dist/development/src/content/GraphQlSchemaFactory.cjs.map +1 -1
- package/dist/development/src/content/GraphQlSchemaFactory.js +5 -6
- package/dist/development/src/content/GraphQlSchemaFactory.js.map +1 -1
- package/dist/development/src/project/ProjectContainer.cjs +12 -8
- package/dist/development/src/project/ProjectContainer.cjs.map +1 -1
- package/dist/development/src/project/ProjectContainer.js +12 -8
- package/dist/development/src/project/ProjectContainer.js.map +1 -1
- package/dist/development/src/projectGroup/ProjectGroupContainer.cjs +12 -8
- package/dist/development/src/projectGroup/ProjectGroupContainer.cjs.map +1 -1
- package/dist/development/src/projectGroup/ProjectGroupContainer.js +12 -8
- package/dist/development/src/projectGroup/ProjectGroupContainer.js.map +1 -1
- package/dist/development/src/system/ContentQueryExecutor.cjs +1 -1
- package/dist/development/src/system/ContentQueryExecutor.cjs.map +1 -1
- package/dist/development/src/system/ContentQueryExecutor.js +1 -1
- package/dist/development/src/system/ContentQueryExecutor.js.map +1 -1
- package/dist/development/src/transfer/ImportApiMiddlewareFactory.cjs +7 -1
- package/dist/development/src/transfer/ImportApiMiddlewareFactory.cjs.map +1 -1
- package/dist/development/src/transfer/ImportApiMiddlewareFactory.js +8 -2
- package/dist/development/src/transfer/ImportApiMiddlewareFactory.js.map +1 -1
- package/dist/production/index.cjs +1 -0
- package/dist/production/index.cjs.map +1 -1
- package/dist/production/index.js +2 -1
- package/dist/production/src/content/GraphQlSchemaFactory.cjs +5 -6
- package/dist/production/src/content/GraphQlSchemaFactory.cjs.map +1 -1
- package/dist/production/src/content/GraphQlSchemaFactory.js +5 -6
- package/dist/production/src/content/GraphQlSchemaFactory.js.map +1 -1
- package/dist/production/src/project/ProjectContainer.cjs +12 -8
- package/dist/production/src/project/ProjectContainer.cjs.map +1 -1
- package/dist/production/src/project/ProjectContainer.js +12 -8
- package/dist/production/src/project/ProjectContainer.js.map +1 -1
- package/dist/production/src/projectGroup/ProjectGroupContainer.cjs +12 -8
- package/dist/production/src/projectGroup/ProjectGroupContainer.cjs.map +1 -1
- package/dist/production/src/projectGroup/ProjectGroupContainer.js +12 -8
- package/dist/production/src/projectGroup/ProjectGroupContainer.js.map +1 -1
- package/dist/production/src/system/ContentQueryExecutor.cjs +1 -1
- package/dist/production/src/system/ContentQueryExecutor.cjs.map +1 -1
- package/dist/production/src/system/ContentQueryExecutor.js +1 -1
- package/dist/production/src/system/ContentQueryExecutor.js.map +1 -1
- package/dist/production/src/transfer/ImportApiMiddlewareFactory.cjs +7 -1
- package/dist/production/src/transfer/ImportApiMiddlewareFactory.cjs.map +1 -1
- package/dist/production/src/transfer/ImportApiMiddlewareFactory.js +8 -2
- package/dist/production/src/transfer/ImportApiMiddlewareFactory.js.map +1 -1
- package/dist/tests/cases/unit/importClientAbort.fixture.d.ts +2 -0
- package/dist/tests/cases/unit/importClientAbort.fixture.d.ts.map +1 -0
- package/dist/tests/cases/unit/importClientAbort.test.d.ts +2 -0
- package/dist/tests/cases/unit/importClientAbort.test.d.ts.map +1 -0
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/dist/types/content/GraphQlSchemaFactory.d.ts.map +1 -1
- package/dist/types/project/ProjectContainer.d.ts.map +1 -1
- package/dist/types/projectGroup/ProjectGroupContainer.d.ts.map +1 -1
- package/dist/types/transfer/ImportApiMiddlewareFactory.d.ts +3 -0
- package/dist/types/transfer/ImportApiMiddlewareFactory.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +16 -16
- package/src/content/GraphQlSchemaFactory.ts +7 -6
- package/src/project/ProjectContainer.ts +11 -7
- package/src/projectGroup/ProjectGroupContainer.ts +11 -7
- package/src/system/ContentQueryExecutor.ts +1 -1
- package/src/transfer/ImportApiMiddlewareFactory.ts +9 -1
- package/tests/cases/unit/importClientAbort.fixture.ts +43 -0
- package/tests/cases/unit/importClientAbort.test.ts +24 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contember/engine-http",
|
|
3
|
-
"version": "2.2.0-alpha.
|
|
3
|
+
"version": "2.2.0-alpha.13",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "./dist/production/index.js",
|
|
6
6
|
"typings": "./dist/types/index.d.ts",
|
|
@@ -26,21 +26,21 @@
|
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@contember/config-loader": "2.2.0-alpha.
|
|
30
|
-
"@contember/database": "2.2.0-alpha.
|
|
31
|
-
"@contember/database-migrations": "2.2.0-alpha.
|
|
32
|
-
"@contember/dic": "2.2.0-alpha.
|
|
33
|
-
"@contember/engine-common": "2.2.0-alpha.
|
|
34
|
-
"@contember/engine-content-api": "2.2.0-alpha.
|
|
35
|
-
"@contember/engine-system-api": "2.2.0-alpha.
|
|
36
|
-
"@contember/engine-tenant-api": "2.2.0-alpha.
|
|
37
|
-
"@contember/graphql-utils": "2.2.0-alpha.
|
|
38
|
-
"@contember/logger": "2.2.0-alpha.
|
|
39
|
-
"@contember/schema": "2.2.0-alpha.
|
|
40
|
-
"@contember/schema-migrations": "2.2.0-alpha.
|
|
41
|
-
"@contember/schema-utils": "2.2.0-alpha.
|
|
42
|
-
"@contember/telemetry": "2.2.0-alpha.
|
|
43
|
-
"@contember/typesafe": "2.2.0-alpha.
|
|
29
|
+
"@contember/config-loader": "2.2.0-alpha.13",
|
|
30
|
+
"@contember/database": "2.2.0-alpha.13",
|
|
31
|
+
"@contember/database-migrations": "2.2.0-alpha.13",
|
|
32
|
+
"@contember/dic": "2.2.0-alpha.13",
|
|
33
|
+
"@contember/engine-common": "2.2.0-alpha.13",
|
|
34
|
+
"@contember/engine-content-api": "2.2.0-alpha.13",
|
|
35
|
+
"@contember/engine-system-api": "2.2.0-alpha.13",
|
|
36
|
+
"@contember/engine-tenant-api": "2.2.0-alpha.13",
|
|
37
|
+
"@contember/graphql-utils": "2.2.0-alpha.13",
|
|
38
|
+
"@contember/logger": "2.2.0-alpha.13",
|
|
39
|
+
"@contember/schema": "2.2.0-alpha.13",
|
|
40
|
+
"@contember/schema-migrations": "2.2.0-alpha.13",
|
|
41
|
+
"@contember/schema-utils": "2.2.0-alpha.13",
|
|
42
|
+
"@contember/telemetry": "2.2.0-alpha.13",
|
|
43
|
+
"@contember/typesafe": "2.2.0-alpha.13",
|
|
44
44
|
"@graphql-tools/merge": "^9.1.7",
|
|
45
45
|
"@graphql-tools/schema": "^10.0.31",
|
|
46
46
|
"@koa/cors": "^5.0.0",
|
|
@@ -40,12 +40,13 @@ export class GraphQlSchemaFactory {
|
|
|
40
40
|
return this.cache.fetch(schema, cacheKey, () => {
|
|
41
41
|
const { root: permissions, all: allPermissions } = computedPermissions ?? this.permissionFactory.createContextual(schema, identity.projectRoles)
|
|
42
42
|
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
)
|
|
48
|
-
const
|
|
43
|
+
const customPrimary = schema.acl.customPrimary ?? false
|
|
44
|
+
const refreshMaterializedView = Object.values(schema.acl.roles).some(it => it.content?.refreshMaterializedView)
|
|
45
|
+
// Types are shaped by the nested set, so a field granted only through a relation still exists
|
|
46
|
+
// on the shared type; the root query and mutation fields are gated on the root set alone.
|
|
47
|
+
const authorizator = new Authorizator(allPermissions, customPrimary, refreshMaterializedView)
|
|
48
|
+
const rootAuthorizator = new Authorizator(permissions, customPrimary, refreshMaterializedView)
|
|
49
|
+
const dataSchemaBuilder = this.graphqlSchemaBuilderFactory.create(schema.model, authorizator, rootAuthorizator)
|
|
49
50
|
const introspectionSchemaFactory = new IntrospectionSchemaDefinitionFactory(
|
|
50
51
|
new IntrospectionSchemaFactory(
|
|
51
52
|
schema.model,
|
|
@@ -88,14 +88,18 @@ export class ProjectContainerFactory {
|
|
|
88
88
|
if (!project.db.read) {
|
|
89
89
|
return connection
|
|
90
90
|
}
|
|
91
|
-
return Connection.create(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
91
|
+
return Connection.create(
|
|
92
|
+
{
|
|
93
|
+
...project.db,
|
|
94
|
+
...project.db.read,
|
|
95
|
+
pool: {
|
|
96
|
+
...project.db.pool,
|
|
97
|
+
...project.db.read.pool,
|
|
98
|
+
},
|
|
97
99
|
},
|
|
98
|
-
|
|
100
|
+
err => logger.error(err),
|
|
101
|
+
{ retryStaleConnection: true },
|
|
102
|
+
)
|
|
99
103
|
})
|
|
100
104
|
.addService('contentSchemaResolver', () => new ContentSchemaResolver(this.schemaProvider))
|
|
101
105
|
.addService('systemSchemaName', ({ project }) => project.db.systemSchema ?? 'system')
|
|
@@ -93,14 +93,18 @@ export class ProjectGroupContainerFactory {
|
|
|
93
93
|
if (!tenantDbCredentials.read) {
|
|
94
94
|
return tenantConnection
|
|
95
95
|
}
|
|
96
|
-
return Connection.create(
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
96
|
+
return Connection.create(
|
|
97
|
+
{
|
|
98
|
+
...tenantDbCredentials,
|
|
99
|
+
...tenantDbCredentials.read,
|
|
100
|
+
pool: {
|
|
101
|
+
...tenantDbCredentials.pool,
|
|
102
|
+
...tenantDbCredentials.read.pool,
|
|
103
|
+
},
|
|
102
104
|
},
|
|
103
|
-
|
|
105
|
+
err => logger.error(err),
|
|
106
|
+
{ retryStaleConnection: true },
|
|
107
|
+
)
|
|
104
108
|
})
|
|
105
109
|
.addService('projectSchemaResolver', () => new ProjectSchemaResolverProxy())
|
|
106
110
|
.addService('projectInitializer', () => new ProjectInitializerProxy())
|
|
@@ -24,7 +24,7 @@ export class ContentQueryExecutorImpl implements ContentQueryExecutor {
|
|
|
24
24
|
): Promise<ContentQueryExecutorResult> {
|
|
25
25
|
const permissions = new AllowAllPermissionFactory().create(schema.model, true)
|
|
26
26
|
const authorizator = new Authorizator(permissions, true, false)
|
|
27
|
-
const dataSchemaBuilder = this.graphqlSchemaBuilderFactory.create(schema.model, authorizator)
|
|
27
|
+
const dataSchemaBuilder = this.graphqlSchemaBuilderFactory.create(schema.model, authorizator, authorizator)
|
|
28
28
|
const dataSchema = dataSchemaBuilder.build()
|
|
29
29
|
|
|
30
30
|
const identityId = identity.id
|
|
@@ -3,7 +3,15 @@ import { HttpErrorResponse } from '../common/index.js'
|
|
|
3
3
|
import { fromBuffer } from './CommandStream.js'
|
|
4
4
|
import { ImportError, ImportExecutor } from './ImportExecutor.js'
|
|
5
5
|
import { createGunzip } from 'node:zlib'
|
|
6
|
+
import { pipeline, Readable } from 'node:stream'
|
|
6
7
|
import { ProjectGroupResolver } from '../projectGroup/ProjectGroupResolver.js'
|
|
8
|
+
import { Command } from './Command.js'
|
|
9
|
+
|
|
10
|
+
export const readImportCommands = (body: Readable, isGzip: boolean): AsyncIterable<Command> => {
|
|
11
|
+
// pipe() would not pass on an aborted request, and the import would wait for the rest of the body forever;
|
|
12
|
+
// pipeline() destroys the gunzip with the error, which rejects the read. The callback only satisfies the API.
|
|
13
|
+
return fromBuffer(isGzip ? pipeline(body, createGunzip(), () => {}) : body)
|
|
14
|
+
}
|
|
7
15
|
|
|
8
16
|
export class ImportApiMiddlewareFactory {
|
|
9
17
|
constructor(
|
|
@@ -32,7 +40,7 @@ export class ImportApiMiddlewareFactory {
|
|
|
32
40
|
|
|
33
41
|
try {
|
|
34
42
|
const isGzip = request.headers['content-encoding'] === 'gzip'
|
|
35
|
-
const commands =
|
|
43
|
+
const commands = readImportCommands(request.req, isGzip)
|
|
36
44
|
await this.importExecutor.import(projectGroup, authResult, commands)
|
|
37
45
|
response.status = 200
|
|
38
46
|
response.body = { ok: true }
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { createServer, request } from 'node:http'
|
|
2
|
+
import { gzipSync } from 'node:zlib'
|
|
3
|
+
import { readImportCommands } from '../../../src/transfer/ImportApiMiddlewareFactory.js'
|
|
4
|
+
|
|
5
|
+
// Driven by importClientAbort.test.ts: uploads an import, whole or half of it and then drops the connection,
|
|
6
|
+
// and prints how reading the commands ended — COMPLETED, REJECTED, or HANGING when it neither ends nor fails.
|
|
7
|
+
const isGzip = process.argv[2] === 'gzip'
|
|
8
|
+
const dropsConnection = process.argv[3] === 'abort'
|
|
9
|
+
const ndjson = Buffer.from(
|
|
10
|
+
Array.from({ length: 2000 }, (_, i) => JSON.stringify(['insertRow', [i, 'x'.repeat(100)]]) + '\n').join(''),
|
|
11
|
+
)
|
|
12
|
+
const body = isGzip ? gzipSync(ndjson, { level: 0 }) : ndjson
|
|
13
|
+
|
|
14
|
+
const finish = (outcome: string) => {
|
|
15
|
+
console.log(outcome)
|
|
16
|
+
process.exit(0)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const server = createServer(async req => {
|
|
20
|
+
try {
|
|
21
|
+
for await (const _ of readImportCommands(req, isGzip)) {
|
|
22
|
+
}
|
|
23
|
+
finish('COMPLETED')
|
|
24
|
+
} catch {
|
|
25
|
+
finish('REJECTED')
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
server.listen(0, '127.0.0.1', () => {
|
|
30
|
+
const address = server.address()
|
|
31
|
+
if (address === null || typeof address === 'string') {
|
|
32
|
+
throw new Error('The server does not listen on a TCP port')
|
|
33
|
+
}
|
|
34
|
+
const client = request({ host: '127.0.0.1', port: address.port, method: 'POST', headers: { 'Content-Length': body.length } })
|
|
35
|
+
client.on('error', () => {})
|
|
36
|
+
if (dropsConnection) {
|
|
37
|
+
client.write(body.subarray(0, body.length / 2))
|
|
38
|
+
setTimeout(() => client.destroy(), 100)
|
|
39
|
+
} else {
|
|
40
|
+
client.end(body)
|
|
41
|
+
}
|
|
42
|
+
setTimeout(() => finish('HANGING'), 2000)
|
|
43
|
+
})
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { expect, test } from 'bun:test'
|
|
2
|
+
import { join } from 'node:path'
|
|
3
|
+
|
|
4
|
+
// A subprocess, because the happy-dom globals of the test preload keep an in-process server from seeing the abort.
|
|
5
|
+
const fixture = join(import.meta.dir, 'importClientAbort.fixture.ts')
|
|
6
|
+
|
|
7
|
+
const readUpload = async (encoding: 'gzip' | 'plain', upload: 'abort' | 'complete'): Promise<string> => {
|
|
8
|
+
const proc = Bun.spawn(['bun', '--conditions=typescript', fixture, encoding, upload], { stdout: 'pipe', stderr: 'inherit' })
|
|
9
|
+
const output = await new Response(proc.stdout).text()
|
|
10
|
+
await proc.exited
|
|
11
|
+
return output.trim()
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
test('stops reading a gzip import when the client drops the connection mid-upload', async () => {
|
|
15
|
+
expect(await readUpload('gzip', 'abort')).toBe('REJECTED')
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
test('stops reading a plain import when the client drops the connection mid-upload', async () => {
|
|
19
|
+
expect(await readUpload('plain', 'abort')).toBe('REJECTED')
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
test('reads a complete gzip import to the end', async () => {
|
|
23
|
+
expect(await readUpload('gzip', 'complete')).toBe('COMPLETED')
|
|
24
|
+
})
|