@contember/engine-content-api 2.0.9 → 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/RelationFetcher.cjs +1 -1
- package/dist/development/src/mapper/select/RelationFetcher.cjs.map +1 -1
- package/dist/development/src/mapper/select/RelationFetcher.js +1 -1
- package/dist/development/src/mapper/select/RelationFetcher.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/RelationFetcher.cjs +1 -1
- package/dist/production/src/mapper/select/RelationFetcher.cjs.map +1 -1
- package/dist/production/src/mapper/select/RelationFetcher.js +1 -1
- package/dist/production/src/mapper/select/RelationFetcher.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/RelationFetcher.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 +11 -11
- 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/RelationFetcher.ts +1 -3
- 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 +53 -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 +15 -15
- 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 +4 -4
- 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
|
@@ -31,9 +31,9 @@ test('Posts with locales query (one has many)', async () => {
|
|
|
31
31
|
{
|
|
32
32
|
sql: SQL`select
|
|
33
33
|
"root_"."id" as "root_id",
|
|
34
|
-
"root_"."id" as "
|
|
34
|
+
"root_"."id" as "root_$key_id"
|
|
35
35
|
from "public"."post" as "root_"`,
|
|
36
|
-
response: { rows: [{ root_id: testUuid(1) }, { root_id: testUuid(2) }] },
|
|
36
|
+
response: { rows: [{ 'root_id': testUuid(1), 'root_$key_id': testUuid(1) }, { 'root_id': testUuid(2), 'root_$key_id': testUuid(2) }] },
|
|
37
37
|
},
|
|
38
38
|
{
|
|
39
39
|
sql: SQL`select
|
|
@@ -113,10 +113,10 @@ test('Posts with locales query with where (one has many)', async () => {
|
|
|
113
113
|
{
|
|
114
114
|
sql: SQL`select
|
|
115
115
|
"root_"."id" as "root_id",
|
|
116
|
-
"root_"."id" as "
|
|
116
|
+
"root_"."id" as "root_$key_id"
|
|
117
117
|
from "public"."post" as "root_"`,
|
|
118
118
|
response: {
|
|
119
|
-
rows: [{ root_id: testUuid(1) }, { root_id: testUuid(2) }],
|
|
119
|
+
rows: [{ 'root_id': testUuid(1), 'root_$key_id': testUuid(1) }, { 'root_id': testUuid(2), 'root_$key_id': testUuid(2) }],
|
|
120
120
|
},
|
|
121
121
|
},
|
|
122
122
|
{
|
|
@@ -192,10 +192,10 @@ test('Posts with paginated comments (one has many)', async () => {
|
|
|
192
192
|
{
|
|
193
193
|
sql: SQL`select
|
|
194
194
|
"root_"."id" as "root_id",
|
|
195
|
-
"root_"."id" as "
|
|
195
|
+
"root_"."id" as "root_$key_id"
|
|
196
196
|
from "public"."post" as "root_"`,
|
|
197
197
|
response: {
|
|
198
|
-
rows: [{ root_id: testUuid(1) }, { root_id: testUuid(2) }],
|
|
198
|
+
rows: [{ 'root_id': testUuid(1), 'root_$key_id': testUuid(1) }, { 'root_id': testUuid(2), 'root_$key_id': testUuid(2) }],
|
|
199
199
|
},
|
|
200
200
|
},
|
|
201
201
|
{
|
|
@@ -223,7 +223,7 @@ test('Posts with paginated comments (one has many)', async () => {
|
|
|
223
223
|
where "root_"."deleted_at" is null
|
|
224
224
|
and "root_"."post_id" in (?, ?)
|
|
225
225
|
order by "root_"."id" asc)
|
|
226
|
-
select "data".* from "data" where "data"."rowNumber_" <=
|
|
226
|
+
select "data".* from "data" where "data"."rowNumber_" <= ? order by "data"."rowNumber_" asc`,
|
|
227
227
|
parameters: [testUuid(1), testUuid(2), 1],
|
|
228
228
|
response: {
|
|
229
229
|
rows: [
|
|
@@ -290,10 +290,10 @@ test('Posts with comment count (one has many)', async () => {
|
|
|
290
290
|
{
|
|
291
291
|
sql: SQL`select
|
|
292
292
|
"root_"."id" as "root_id",
|
|
293
|
-
"root_"."id" as "
|
|
293
|
+
"root_"."id" as "root_$key_id"
|
|
294
294
|
from "public"."post" as "root_"`,
|
|
295
295
|
response: {
|
|
296
|
-
rows: [{ root_id: testUuid(1) }, { root_id: testUuid(2) }],
|
|
296
|
+
rows: [{ 'root_id': testUuid(1), 'root_$key_id': testUuid(1) }, { 'root_id': testUuid(2), 'root_$key_id': testUuid(2) }],
|
|
297
297
|
},
|
|
298
298
|
},
|
|
299
299
|
{
|
|
@@ -360,10 +360,10 @@ test('Posts with paginated comments without count (one has many)', async () => {
|
|
|
360
360
|
{
|
|
361
361
|
sql: SQL`select
|
|
362
362
|
"root_"."id" as "root_id",
|
|
363
|
-
"root_"."id" as "
|
|
363
|
+
"root_"."id" as "root_$key_id"
|
|
364
364
|
from "public"."post" as "root_"`,
|
|
365
365
|
response: {
|
|
366
|
-
rows: [{ root_id: testUuid(1) }, { root_id: testUuid(2) }],
|
|
366
|
+
rows: [{ 'root_id': testUuid(1), 'root_$key_id': testUuid(1) }, { 'root_id': testUuid(2), 'root_$key_id': testUuid(2) }],
|
|
367
367
|
},
|
|
368
368
|
},
|
|
369
369
|
{
|
|
@@ -377,7 +377,7 @@ test('Posts with paginated comments without count (one has many)', async () => {
|
|
|
377
377
|
where "root_"."deleted_at" is null
|
|
378
378
|
and "root_"."post_id" in (?, ?)
|
|
379
379
|
order by "root_"."id" asc)
|
|
380
|
-
select "data".* from "data" where "data"."rowNumber_" <=
|
|
380
|
+
select "data".* from "data" where "data"."rowNumber_" <= ? order by "data"."rowNumber_" asc`,
|
|
381
381
|
parameters: [testUuid(1), testUuid(2), 1],
|
|
382
382
|
response: {
|
|
383
383
|
rows: [
|
|
@@ -444,10 +444,10 @@ test('Posts with paginated comments (one has many)', async () => {
|
|
|
444
444
|
{
|
|
445
445
|
sql: SQL`select
|
|
446
446
|
"root_"."id" as "root_id",
|
|
447
|
-
"root_"."id" as "
|
|
447
|
+
"root_"."id" as "root_$key_id"
|
|
448
448
|
from "public"."post" as "root_"`,
|
|
449
449
|
response: {
|
|
450
|
-
rows: [{ root_id: testUuid(1) }],
|
|
450
|
+
rows: [{ 'root_id': testUuid(1), 'root_$key_id': testUuid(1) }],
|
|
451
451
|
},
|
|
452
452
|
},
|
|
453
453
|
{
|
|
@@ -474,7 +474,7 @@ test('Posts with paginated comments (one has many)', async () => {
|
|
|
474
474
|
where "root_"."deleted_at" is null
|
|
475
475
|
and "root_"."post_id" in (?)
|
|
476
476
|
order by "root_"."id" asc)
|
|
477
|
-
select "data".* from "data" where "data"."rowNumber_" <=
|
|
477
|
+
select "data".* from "data" where "data"."rowNumber_" <= ? order by "data"."rowNumber_" asc`,
|
|
478
478
|
parameters: [testUuid(1), 1],
|
|
479
479
|
response: {
|
|
480
480
|
rows: [
|
|
@@ -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
|
},
|
|
@@ -139,7 +139,7 @@ test('sorts posts by random on has many relation', async () => {
|
|
|
139
139
|
inner join "rand_seed" on true
|
|
140
140
|
where "junction_"."category_id" in (?, ?)
|
|
141
141
|
order by random() asc)
|
|
142
|
-
select "data".* from "data" where "data"."rownumber_" <=
|
|
142
|
+
select "data".* from "data" where "data"."rownumber_" <= ? order by "data"."rownumber_" asc`,
|
|
143
143
|
parameters: [4555 / Math.pow(2, 31), testUuid(1), testUuid(2), 1],
|
|
144
144
|
response: {
|
|
145
145
|
rows: [
|
|
@@ -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
|
+
})
|