@contember/engine-content-api 2.0.10 → 2.0.11
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/mapper/ErrorUtils.cjs +7 -1
- package/dist/development/src/mapper/ErrorUtils.cjs.map +1 -1
- package/dist/development/src/mapper/ErrorUtils.js +7 -1
- package/dist/development/src/mapper/ErrorUtils.js.map +1 -1
- package/dist/development/src/mapper/Mapper.cjs +2 -1
- package/dist/development/src/mapper/Mapper.cjs.map +1 -1
- package/dist/development/src/mapper/Mapper.js +2 -1
- package/dist/development/src/mapper/Mapper.js.map +1 -1
- package/dist/development/src/mapper/select/Path.cjs +23 -3
- package/dist/development/src/mapper/select/Path.cjs.map +1 -1
- package/dist/development/src/mapper/select/Path.js +23 -3
- package/dist/development/src/mapper/select/Path.js.map +1 -1
- package/dist/development/src/mapper/select/SelectBuilder.cjs +5 -5
- package/dist/development/src/mapper/select/SelectBuilder.cjs.map +1 -1
- package/dist/development/src/mapper/select/SelectBuilder.js +5 -5
- package/dist/development/src/mapper/select/SelectBuilder.js.map +1 -1
- package/dist/development/src/resolvers/MutationResolver.cjs +1 -0
- package/dist/development/src/resolvers/MutationResolver.cjs.map +1 -1
- package/dist/development/src/resolvers/MutationResolver.js +1 -0
- package/dist/development/src/resolvers/MutationResolver.js.map +1 -1
- package/dist/production/src/mapper/ErrorUtils.cjs +7 -1
- package/dist/production/src/mapper/ErrorUtils.cjs.map +1 -1
- package/dist/production/src/mapper/ErrorUtils.js +7 -1
- package/dist/production/src/mapper/ErrorUtils.js.map +1 -1
- package/dist/production/src/mapper/Mapper.cjs +2 -1
- package/dist/production/src/mapper/Mapper.cjs.map +1 -1
- package/dist/production/src/mapper/Mapper.js +2 -1
- package/dist/production/src/mapper/Mapper.js.map +1 -1
- package/dist/production/src/mapper/select/Path.cjs +23 -3
- package/dist/production/src/mapper/select/Path.cjs.map +1 -1
- package/dist/production/src/mapper/select/Path.js +23 -3
- package/dist/production/src/mapper/select/Path.js.map +1 -1
- package/dist/production/src/mapper/select/SelectBuilder.cjs +5 -5
- package/dist/production/src/mapper/select/SelectBuilder.cjs.map +1 -1
- package/dist/production/src/mapper/select/SelectBuilder.js +5 -5
- package/dist/production/src/mapper/select/SelectBuilder.js.map +1 -1
- package/dist/production/src/resolvers/MutationResolver.cjs +1 -0
- package/dist/production/src/resolvers/MutationResolver.cjs.map +1 -1
- package/dist/production/src/resolvers/MutationResolver.js +1 -0
- package/dist/production/src/resolvers/MutationResolver.js.map +1 -1
- package/dist/tests/cases/unit/mutationSqlError.test.d.ts +2 -0
- package/dist/tests/cases/unit/mutationSqlError.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/pathAlias.test.d.ts +2 -0
- package/dist/tests/cases/unit/pathAlias.test.d.ts.map +1 -0
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/dist/types/mapper/ErrorUtils.d.ts.map +1 -1
- package/dist/types/mapper/select/Path.d.ts +1 -0
- package/dist/types/mapper/select/Path.d.ts.map +1 -1
- package/dist/types/mapper/select/SelectBuilder.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -10
- package/src/mapper/ErrorUtils.ts +11 -1
- package/src/mapper/Mapper.ts +1 -1
- package/src/mapper/select/Path.ts +25 -5
- package/src/mapper/select/SelectBuilder.ts +10 -5
- package/tests/cases/bugs/bug102.test.ts +4 -4
- package/tests/cases/integration/graphQlRequests/delete/deleteById.test.ts +7 -6
- package/tests/cases/integration/graphQlRequests/query/acl/differentRowAndFieldPredicate.test.ts +8 -8
- package/tests/cases/integration/graphQlRequests/query/acl/fieldRestrictedByLocale.test.ts +26 -24
- package/tests/cases/integration/graphQlRequests/query/acl/nestedPredicate.test.ts +11 -10
- package/tests/cases/integration/graphQlRequests/query/acl/predicateElimination.test.ts +7 -6
- package/tests/cases/integration/graphQlRequests/query/acl/relationAcl.test.ts +22 -19
- package/tests/cases/integration/graphQlRequests/query/acl/rowPredicateSubset.test.ts +12 -12
- package/tests/cases/integration/graphQlRequests/query/filter/backReferencedFilter.test.ts +5 -3
- package/tests/cases/integration/graphQlRequests/query/graphqlFeatures/alias.test.ts +6 -6
- package/tests/cases/integration/graphQlRequests/query/graphqlFeatures/fragments.test.ts +8 -8
- package/tests/cases/integration/graphQlRequests/query/misc/reducedHasMany.test.ts +10 -10
- package/tests/cases/integration/graphQlRequests/query/pagination/hasManyLimit.test.ts +8 -8
- package/tests/cases/integration/graphQlRequests/query/pagination/paginate.test.ts +13 -10
- package/tests/cases/integration/graphQlRequests/query/pagination/paginateAliased.test.ts +13 -10
- package/tests/cases/integration/graphQlRequests/query/relations/advanced.test.ts +34 -25
- package/tests/cases/integration/graphQlRequests/query/relations/manyHasManyInverse.test.ts +6 -6
- package/tests/cases/integration/graphQlRequests/query/relations/manyHasManyOwning.test.ts +6 -6
- package/tests/cases/integration/graphQlRequests/query/relations/manyHasOne.test.ts +21 -18
- package/tests/cases/integration/graphQlRequests/query/relations/oneHasMany.test.ts +12 -12
- package/tests/cases/integration/graphQlRequests/query/relations/oneHasOneInverse.test.ts +14 -12
- package/tests/cases/integration/graphQlRequests/query/relations/oneHasOneOwner.test.ts +14 -12
- package/tests/cases/integration/graphQlRequests/query/sorting/defaultOrdering.test.ts +4 -4
- package/tests/cases/integration/graphQlRequests/query/sorting/randomSort.test.ts +3 -3
- package/tests/cases/integration/graphQlRequests/query/sorting/sortedHasMany.test.ts +2 -2
- package/tests/cases/integration/graphQlRequests/query/view/view.test.ts +10 -10
- package/tests/cases/unit/mutationSqlError.test.ts +30 -0
- package/tests/cases/unit/pathAlias.test.ts +26 -0
|
@@ -30,24 +30,26 @@ test('Settings with sites (one-has-one inverse)', async () => {
|
|
|
30
30
|
sql: SQL`select
|
|
31
31
|
"root_"."id" as "root_id",
|
|
32
32
|
"root_"."url" as "root_url",
|
|
33
|
-
"root_"."id" as "
|
|
33
|
+
"root_"."id" as "root_$key_id"
|
|
34
34
|
from "public"."site_setting" as "root_"`,
|
|
35
35
|
response: {
|
|
36
36
|
rows: [
|
|
37
37
|
{
|
|
38
|
-
root_id: testUuid(1),
|
|
39
|
-
|
|
38
|
+
'root_id': testUuid(1),
|
|
39
|
+
'root_$key_id': testUuid(1),
|
|
40
|
+
'root_url': 'http://site1.cz',
|
|
40
41
|
},
|
|
41
42
|
{
|
|
42
|
-
root_id: testUuid(3),
|
|
43
|
-
|
|
43
|
+
'root_id': testUuid(3),
|
|
44
|
+
'root_$key_id': testUuid(3),
|
|
45
|
+
'root_url': 'http://site2.cz',
|
|
44
46
|
},
|
|
45
47
|
],
|
|
46
48
|
},
|
|
47
49
|
},
|
|
48
50
|
{
|
|
49
51
|
sql: SQL`select
|
|
50
|
-
"root_"."setting_id" as "
|
|
52
|
+
"root_"."setting_id" as "root_$index_setting",
|
|
51
53
|
"root_"."id" as "root_id",
|
|
52
54
|
"root_"."name" as "root_name"
|
|
53
55
|
from "public"."site" as "root_"
|
|
@@ -56,14 +58,14 @@ test('Settings with sites (one-has-one inverse)', async () => {
|
|
|
56
58
|
response: {
|
|
57
59
|
rows: [
|
|
58
60
|
{
|
|
59
|
-
root_id: testUuid(2),
|
|
60
|
-
|
|
61
|
-
root_name: 'Site 1',
|
|
61
|
+
'root_id': testUuid(2),
|
|
62
|
+
'root_$index_setting': testUuid(1),
|
|
63
|
+
'root_name': 'Site 1',
|
|
62
64
|
},
|
|
63
65
|
{
|
|
64
|
-
root_id: testUuid(4),
|
|
65
|
-
|
|
66
|
-
root_name: 'Site 2',
|
|
66
|
+
'root_id': testUuid(4),
|
|
67
|
+
'root_$index_setting': testUuid(3),
|
|
68
|
+
'root_name': 'Site 2',
|
|
67
69
|
},
|
|
68
70
|
],
|
|
69
71
|
},
|
|
@@ -31,20 +31,20 @@ test('Sites with settings (one-has-one owning)', async () => {
|
|
|
31
31
|
select
|
|
32
32
|
"root_"."id" as "root_id",
|
|
33
33
|
"root_"."name" as "root_name",
|
|
34
|
-
"root_"."setting_id" as "
|
|
34
|
+
"root_"."setting_id" as "root_$key_setting"
|
|
35
35
|
from "public"."site" as "root_"`,
|
|
36
36
|
|
|
37
37
|
response: {
|
|
38
38
|
rows: [
|
|
39
39
|
{
|
|
40
|
-
root_id: testUuid(1),
|
|
41
|
-
root_name: 'Site 1',
|
|
42
|
-
|
|
40
|
+
'root_id': testUuid(1),
|
|
41
|
+
'root_name': 'Site 1',
|
|
42
|
+
'root_$key_setting': testUuid(2),
|
|
43
43
|
},
|
|
44
44
|
{
|
|
45
|
-
root_id: testUuid(3),
|
|
46
|
-
root_name: 'Site 2',
|
|
47
|
-
|
|
45
|
+
'root_id': testUuid(3),
|
|
46
|
+
'root_name': 'Site 2',
|
|
47
|
+
'root_$key_setting': testUuid(4),
|
|
48
48
|
},
|
|
49
49
|
],
|
|
50
50
|
},
|
|
@@ -52,7 +52,7 @@ test('Sites with settings (one-has-one owning)', async () => {
|
|
|
52
52
|
{
|
|
53
53
|
sql: SQL`
|
|
54
54
|
select
|
|
55
|
-
"root_"."id" as "
|
|
55
|
+
"root_"."id" as "root_$index_id",
|
|
56
56
|
"root_"."id" as "root_id",
|
|
57
57
|
"root_"."url" as "root_url"
|
|
58
58
|
from "public"."site_setting" as "root_"
|
|
@@ -62,12 +62,14 @@ test('Sites with settings (one-has-one owning)', async () => {
|
|
|
62
62
|
response: {
|
|
63
63
|
rows: [
|
|
64
64
|
{
|
|
65
|
-
root_id: testUuid(2),
|
|
66
|
-
|
|
65
|
+
'root_id': testUuid(2),
|
|
66
|
+
'root_$index_id': testUuid(2),
|
|
67
|
+
'root_url': 'http://site1.cz',
|
|
67
68
|
},
|
|
68
69
|
{
|
|
69
|
-
root_id: testUuid(4),
|
|
70
|
-
|
|
70
|
+
'root_id': testUuid(4),
|
|
71
|
+
'root_$index_id': testUuid(4),
|
|
72
|
+
'root_url': 'http://site2.cz',
|
|
71
73
|
},
|
|
72
74
|
],
|
|
73
75
|
},
|
|
@@ -28,10 +28,10 @@ test('one has many - default ordering', async () => {
|
|
|
28
28
|
}`,
|
|
29
29
|
executes: [
|
|
30
30
|
{
|
|
31
|
-
sql: SQL`select "root_"."id" as "root_id", "root_"."id" as "
|
|
31
|
+
sql: SQL`select "root_"."id" as "root_id", "root_"."id" as "root_$key_id" from "public"."menu" as "root_"`,
|
|
32
32
|
parameters: [],
|
|
33
33
|
response: {
|
|
34
|
-
rows: [{ root_id: testUuid(1) }, { root_id: testUuid(2) }],
|
|
34
|
+
rows: [{ 'root_id': testUuid(1), 'root_$key_id': testUuid(1) }, { 'root_id': testUuid(2), 'root_$key_id': testUuid(2) }],
|
|
35
35
|
},
|
|
36
36
|
},
|
|
37
37
|
{
|
|
@@ -96,10 +96,10 @@ test('many has many - default ordering', async () => {
|
|
|
96
96
|
}`,
|
|
97
97
|
executes: [
|
|
98
98
|
{
|
|
99
|
-
sql: SQL`select "root_"."id" as "root_id", "root_"."id" as "
|
|
99
|
+
sql: SQL`select "root_"."id" as "root_id", "root_"."id" as "root_$key_id" from "public"."post" as "root_"`,
|
|
100
100
|
parameters: [],
|
|
101
101
|
response: {
|
|
102
|
-
rows: [{ root_id: testUuid(1) }, { root_id: testUuid(2) }],
|
|
102
|
+
rows: [{ 'root_id': testUuid(1), 'root_$key_id': testUuid(1) }, { 'root_id': testUuid(2), 'root_$key_id': testUuid(2) }],
|
|
103
103
|
},
|
|
104
104
|
},
|
|
105
105
|
{
|
|
@@ -117,13 +117,13 @@ test('sorts posts by random on has many relation', async () => {
|
|
|
117
117
|
sql: SQL`select
|
|
118
118
|
"root_"."id" as "root_id",
|
|
119
119
|
"root_"."title" as "root_title",
|
|
120
|
-
"root_"."id" as "
|
|
120
|
+
"root_"."id" as "root_$key_id"
|
|
121
121
|
from "public"."category" as "root_"`,
|
|
122
122
|
parameters: [],
|
|
123
123
|
response: {
|
|
124
124
|
rows: [
|
|
125
|
-
{ root_id: testUuid(1), root_title: 'Hello' },
|
|
126
|
-
{ root_id: testUuid(2), root_title: 'World' },
|
|
125
|
+
{ 'root_id': testUuid(1), 'root_$key_id': testUuid(1), 'root_title': 'Hello' },
|
|
126
|
+
{ 'root_id': testUuid(2), 'root_$key_id': testUuid(2), 'root_title': 'World' },
|
|
127
127
|
],
|
|
128
128
|
},
|
|
129
129
|
},
|
|
@@ -22,10 +22,10 @@ test('Post with ordered locales', async () => {
|
|
|
22
22
|
{
|
|
23
23
|
sql: SQL`select
|
|
24
24
|
"root_"."id" as "root_id",
|
|
25
|
-
"root_"."id" as "
|
|
25
|
+
"root_"."id" as "root_$key_id"
|
|
26
26
|
from "public"."post" as "root_"`,
|
|
27
27
|
response: {
|
|
28
|
-
rows: [{ root_id: testUuid(1) }, { root_id: testUuid(2) }],
|
|
28
|
+
rows: [{ 'root_id': testUuid(1), 'root_$key_id': testUuid(1) }, { 'root_id': testUuid(2), 'root_$key_id': testUuid(2) }],
|
|
29
29
|
},
|
|
30
30
|
},
|
|
31
31
|
{
|
|
@@ -31,33 +31,33 @@ test('query a view through a relation', async () => {
|
|
|
31
31
|
}`,
|
|
32
32
|
executes: [
|
|
33
33
|
{
|
|
34
|
-
sql: SQL`select "root_"."name" as "root_name", "root_"."id" as "
|
|
34
|
+
sql: SQL`select "root_"."name" as "root_name", "root_"."id" as "root_$key_id", "root_"."id" as "root_id"
|
|
35
35
|
from "public"."author" as "root_"`,
|
|
36
36
|
response: {
|
|
37
37
|
rows: [
|
|
38
|
-
{ root_id: testUuid(1), root_name: 'John' },
|
|
39
|
-
{ root_id: testUuid(2), root_name: 'Jack' },
|
|
38
|
+
{ 'root_id': testUuid(1), 'root_$key_id': testUuid(1), 'root_name': 'John' },
|
|
39
|
+
{ 'root_id': testUuid(2), 'root_$key_id': testUuid(2), 'root_name': 'Jack' },
|
|
40
40
|
],
|
|
41
41
|
},
|
|
42
42
|
parameters: [],
|
|
43
43
|
},
|
|
44
44
|
{
|
|
45
45
|
sql: SQL`
|
|
46
|
-
select "root_"."author_id" as "
|
|
46
|
+
select "root_"."author_id" as "root_$index_author", "root_"."post_count" as "root_postCount", "root_"."id" as "root_id"
|
|
47
47
|
from "public"."author_stats" as "root_"
|
|
48
48
|
where "root_"."author_id" in (?, ?)`,
|
|
49
49
|
parameters: [testUuid(1), testUuid(2)],
|
|
50
50
|
response: {
|
|
51
51
|
rows: [
|
|
52
52
|
{
|
|
53
|
-
root_id: null,
|
|
54
|
-
|
|
55
|
-
root_postCount: 2,
|
|
53
|
+
'root_id': null,
|
|
54
|
+
'root_$index_author': testUuid(1),
|
|
55
|
+
'root_postCount': 2,
|
|
56
56
|
},
|
|
57
57
|
{
|
|
58
|
-
root_id: null,
|
|
59
|
-
|
|
60
|
-
root_postCount: 3,
|
|
58
|
+
'root_id': null,
|
|
59
|
+
'root_$index_author': testUuid(2),
|
|
60
|
+
'root_postCount': 3,
|
|
61
61
|
},
|
|
62
62
|
],
|
|
63
63
|
},
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test'
|
|
2
|
+
import { emptyDatabaseMetadata, QueryError } from '@contember/database'
|
|
3
|
+
import { createLogger, TestLoggerHandler, withLogger } from '@contember/logger'
|
|
4
|
+
import { emptySchema } from '@contember/schema-utils'
|
|
5
|
+
import { convertError, MutationSqlError } from '../../../src/mapper'
|
|
6
|
+
|
|
7
|
+
const convert = (code: string, message: string) => {
|
|
8
|
+
const error = new QueryError('select 1', [], Object.assign(new Error(message), { code }))
|
|
9
|
+
const handler = new TestLoggerHandler()
|
|
10
|
+
const result = withLogger(createLogger(handler), () => convertError(emptySchema.model, emptyDatabaseMetadata, error))
|
|
11
|
+
if (!(result instanceof MutationSqlError)) {
|
|
12
|
+
throw new Error('expected a MutationSqlError')
|
|
13
|
+
}
|
|
14
|
+
return { message: result.message, logged: handler.messages.map(it => it.error), error }
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
describe('mutation SQL error', () => {
|
|
18
|
+
it('returns a generic message for an error that can quote internal identifiers, and logs the original', () => {
|
|
19
|
+
const { message, logged, error } = convert('42702', 'column reference "root_$predicate_rule" is ambiguous')
|
|
20
|
+
expect(message).toBe('Database query failed')
|
|
21
|
+
expect(logged).toContain(error)
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it('keeps the message of data, integrity and trigger errors', () => {
|
|
25
|
+
expect(convert('23514', 'new row for relation "order" violates check constraint "order_total_check"').message)
|
|
26
|
+
.toBe('new row for relation "order" violates check constraint "order_total_check"')
|
|
27
|
+
expect(convert('22001', 'value too long for type character varying(10)').message).toBe('value too long for type character varying(10)')
|
|
28
|
+
expect(convert('P0001', 'Order total must be positive').message).toBe('Order total must be positive')
|
|
29
|
+
})
|
|
30
|
+
})
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test'
|
|
2
|
+
import { PathFactory } from '../../../src/mapper'
|
|
3
|
+
|
|
4
|
+
describe('select path aliases', () => {
|
|
5
|
+
it('keep engine-owned columns apart from field aliases after truncation', () => {
|
|
6
|
+
const factory = new PathFactory()
|
|
7
|
+
const name = 'p'.repeat(80)
|
|
8
|
+
const internal = factory.create([]).forInternal('predicate').for(name).alias
|
|
9
|
+
const field = factory.create([]).for(name).for(name).alias
|
|
10
|
+
expect(internal.length).toBe(63)
|
|
11
|
+
expect(field.length).toBe(63)
|
|
12
|
+
expect(field).not.toBe(internal)
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
it('stay unique within the PostgreSQL byte limit for multi-byte names', () => {
|
|
16
|
+
const factory = new PathFactory()
|
|
17
|
+
const name = 'x' + 'é'.repeat(23)
|
|
18
|
+
// 63 and 64 bytes untruncated: PostgreSQL would cut the second to the first
|
|
19
|
+
const first = factory.create([]).forInternal('predicate').for(name).alias
|
|
20
|
+
const second = factory.create([]).forInternal('predicate').for(name + 'x').alias
|
|
21
|
+
const encoder = new TextEncoder()
|
|
22
|
+
expect(encoder.encode(first).length).toBe(63)
|
|
23
|
+
expect(encoder.encode(second).length).toBe(63)
|
|
24
|
+
expect(second).not.toBe(first)
|
|
25
|
+
})
|
|
26
|
+
})
|