@contember/engine-content-api 2.0.10 → 2.0.12

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.
Files changed (86) hide show
  1. package/dist/development/src/mapper/ErrorUtils.cjs +7 -1
  2. package/dist/development/src/mapper/ErrorUtils.cjs.map +1 -1
  3. package/dist/development/src/mapper/ErrorUtils.js +7 -1
  4. package/dist/development/src/mapper/ErrorUtils.js.map +1 -1
  5. package/dist/development/src/mapper/Mapper.cjs +2 -1
  6. package/dist/development/src/mapper/Mapper.cjs.map +1 -1
  7. package/dist/development/src/mapper/Mapper.js +2 -1
  8. package/dist/development/src/mapper/Mapper.js.map +1 -1
  9. package/dist/development/src/mapper/select/Path.cjs +23 -3
  10. package/dist/development/src/mapper/select/Path.cjs.map +1 -1
  11. package/dist/development/src/mapper/select/Path.js +23 -3
  12. package/dist/development/src/mapper/select/Path.js.map +1 -1
  13. package/dist/development/src/mapper/select/SelectBuilder.cjs +5 -5
  14. package/dist/development/src/mapper/select/SelectBuilder.cjs.map +1 -1
  15. package/dist/development/src/mapper/select/SelectBuilder.js +5 -5
  16. package/dist/development/src/mapper/select/SelectBuilder.js.map +1 -1
  17. package/dist/development/src/resolvers/MutationResolver.cjs +1 -0
  18. package/dist/development/src/resolvers/MutationResolver.cjs.map +1 -1
  19. package/dist/development/src/resolvers/MutationResolver.js +1 -0
  20. package/dist/development/src/resolvers/MutationResolver.js.map +1 -1
  21. package/dist/production/src/mapper/ErrorUtils.cjs +7 -1
  22. package/dist/production/src/mapper/ErrorUtils.cjs.map +1 -1
  23. package/dist/production/src/mapper/ErrorUtils.js +7 -1
  24. package/dist/production/src/mapper/ErrorUtils.js.map +1 -1
  25. package/dist/production/src/mapper/Mapper.cjs +2 -1
  26. package/dist/production/src/mapper/Mapper.cjs.map +1 -1
  27. package/dist/production/src/mapper/Mapper.js +2 -1
  28. package/dist/production/src/mapper/Mapper.js.map +1 -1
  29. package/dist/production/src/mapper/select/Path.cjs +23 -3
  30. package/dist/production/src/mapper/select/Path.cjs.map +1 -1
  31. package/dist/production/src/mapper/select/Path.js +23 -3
  32. package/dist/production/src/mapper/select/Path.js.map +1 -1
  33. package/dist/production/src/mapper/select/SelectBuilder.cjs +5 -5
  34. package/dist/production/src/mapper/select/SelectBuilder.cjs.map +1 -1
  35. package/dist/production/src/mapper/select/SelectBuilder.js +5 -5
  36. package/dist/production/src/mapper/select/SelectBuilder.js.map +1 -1
  37. package/dist/production/src/resolvers/MutationResolver.cjs +1 -0
  38. package/dist/production/src/resolvers/MutationResolver.cjs.map +1 -1
  39. package/dist/production/src/resolvers/MutationResolver.js +1 -0
  40. package/dist/production/src/resolvers/MutationResolver.js.map +1 -1
  41. package/dist/tests/cases/integration/graphQlRequests/query/acl/internalColumnAliases.test.d.ts +2 -0
  42. package/dist/tests/cases/integration/graphQlRequests/query/acl/internalColumnAliases.test.d.ts.map +1 -0
  43. package/dist/tests/cases/unit/mutationSqlError.test.d.ts +2 -0
  44. package/dist/tests/cases/unit/mutationSqlError.test.d.ts.map +1 -0
  45. package/dist/tests/cases/unit/pathAlias.test.d.ts +2 -0
  46. package/dist/tests/cases/unit/pathAlias.test.d.ts.map +1 -0
  47. package/dist/tests/tsconfig.tsbuildinfo +1 -1
  48. package/dist/types/mapper/ErrorUtils.d.ts.map +1 -1
  49. package/dist/types/mapper/select/Path.d.ts +1 -0
  50. package/dist/types/mapper/select/Path.d.ts.map +1 -1
  51. package/dist/types/mapper/select/SelectBuilder.d.ts.map +1 -1
  52. package/dist/types/tsconfig.tsbuildinfo +1 -1
  53. package/package.json +10 -10
  54. package/src/mapper/ErrorUtils.ts +11 -1
  55. package/src/mapper/Mapper.ts +1 -1
  56. package/src/mapper/select/Path.ts +25 -5
  57. package/src/mapper/select/SelectBuilder.ts +10 -5
  58. package/tests/cases/bugs/bug102.test.ts +4 -4
  59. package/tests/cases/integration/graphQlRequests/delete/deleteById.test.ts +7 -6
  60. package/tests/cases/integration/graphQlRequests/query/acl/differentRowAndFieldPredicate.test.ts +8 -8
  61. package/tests/cases/integration/graphQlRequests/query/acl/fieldRestrictedByLocale.test.ts +26 -24
  62. package/tests/cases/integration/graphQlRequests/query/acl/internalColumnAliases.test.ts +278 -0
  63. package/tests/cases/integration/graphQlRequests/query/acl/nestedPredicate.test.ts +11 -10
  64. package/tests/cases/integration/graphQlRequests/query/acl/predicateElimination.test.ts +7 -6
  65. package/tests/cases/integration/graphQlRequests/query/acl/relationAcl.test.ts +22 -19
  66. package/tests/cases/integration/graphQlRequests/query/acl/rowPredicateSubset.test.ts +12 -12
  67. package/tests/cases/integration/graphQlRequests/query/filter/backReferencedFilter.test.ts +5 -3
  68. package/tests/cases/integration/graphQlRequests/query/graphqlFeatures/alias.test.ts +6 -6
  69. package/tests/cases/integration/graphQlRequests/query/graphqlFeatures/fragments.test.ts +8 -8
  70. package/tests/cases/integration/graphQlRequests/query/misc/reducedHasMany.test.ts +10 -10
  71. package/tests/cases/integration/graphQlRequests/query/pagination/hasManyLimit.test.ts +8 -8
  72. package/tests/cases/integration/graphQlRequests/query/pagination/paginate.test.ts +13 -10
  73. package/tests/cases/integration/graphQlRequests/query/pagination/paginateAliased.test.ts +13 -10
  74. package/tests/cases/integration/graphQlRequests/query/relations/advanced.test.ts +34 -25
  75. package/tests/cases/integration/graphQlRequests/query/relations/manyHasManyInverse.test.ts +6 -6
  76. package/tests/cases/integration/graphQlRequests/query/relations/manyHasManyOwning.test.ts +6 -6
  77. package/tests/cases/integration/graphQlRequests/query/relations/manyHasOne.test.ts +21 -18
  78. package/tests/cases/integration/graphQlRequests/query/relations/oneHasMany.test.ts +12 -12
  79. package/tests/cases/integration/graphQlRequests/query/relations/oneHasOneInverse.test.ts +14 -12
  80. package/tests/cases/integration/graphQlRequests/query/relations/oneHasOneOwner.test.ts +14 -12
  81. package/tests/cases/integration/graphQlRequests/query/sorting/defaultOrdering.test.ts +4 -4
  82. package/tests/cases/integration/graphQlRequests/query/sorting/randomSort.test.ts +3 -3
  83. package/tests/cases/integration/graphQlRequests/query/sorting/sortedHasMany.test.ts +2 -2
  84. package/tests/cases/integration/graphQlRequests/query/view/view.test.ts +10 -10
  85. package/tests/cases/unit/mutationSqlError.test.ts +30 -0
  86. package/tests/cases/unit/pathAlias.test.ts +26 -0
@@ -32,10 +32,10 @@ test('Tags with paginated posts (many has many inverse)', async () => {
32
32
  executes: [
33
33
  {
34
34
  sql: SQL`select "root_"."id" as "root_id",
35
- "root_"."id" as "root_id"
35
+ "root_"."id" as "root_$key_id"
36
36
  from "public"."tag" as "root_"`,
37
37
  response: {
38
- rows: [{ root_id: testUuid(1) }, { root_id: testUuid(2) }],
38
+ rows: [{ 'root_id': testUuid(1), 'root_$key_id': testUuid(1) }, { 'root_id': testUuid(2), 'root_$key_id': testUuid(2) }],
39
39
  },
40
40
  },
41
41
  {
@@ -139,10 +139,10 @@ test('empty many-has-many inverse relation', async () => {
139
139
  executes: [
140
140
  {
141
141
  sql: SQL`select "root_"."id" as "root_id",
142
- "root_"."id" as "root_id"
142
+ "root_"."id" as "root_$key_id"
143
143
  from "public"."tag" as "root_"`,
144
144
  response: {
145
- rows: [{ root_id: testUuid(1) }, { root_id: testUuid(2) }],
145
+ rows: [{ 'root_id': testUuid(1), 'root_$key_id': testUuid(1) }, { 'root_id': testUuid(2), 'root_$key_id': testUuid(2) }],
146
146
  },
147
147
  },
148
148
  {
@@ -190,10 +190,10 @@ test('Posts with filtered tags', async () => {
190
190
  executes: [
191
191
  {
192
192
  sql: SQL`select "root_"."id" as "root_id",
193
- "root_"."id" as "root_id"
193
+ "root_"."id" as "root_$key_id"
194
194
  from "public"."post" as "root_"`,
195
195
  response: {
196
- rows: [{ root_id: testUuid(1) }, { root_id: testUuid(2) }],
196
+ rows: [{ 'root_id': testUuid(1), 'root_$key_id': testUuid(1) }, { 'root_id': testUuid(2), 'root_$key_id': testUuid(2) }],
197
197
  },
198
198
  },
199
199
  {
@@ -24,10 +24,10 @@ test('Posts with filtered tags', async () => {
24
24
  executes: [
25
25
  {
26
26
  sql: SQL`select "root_"."id" as "root_id",
27
- "root_"."id" as "root_id"
27
+ "root_"."id" as "root_$key_id"
28
28
  from "public"."post" as "root_"`,
29
29
  response: {
30
- rows: [{ root_id: testUuid(1) }, { root_id: testUuid(2) }],
30
+ rows: [{ 'root_id': testUuid(1), 'root_$key_id': testUuid(1) }, { 'root_id': testUuid(2), 'root_$key_id': testUuid(2) }],
31
31
  },
32
32
  },
33
33
  {
@@ -107,10 +107,10 @@ test('Posts with paginated tags (many has many owning)', async () => {
107
107
  executes: [
108
108
  {
109
109
  sql: SQL`select "root_"."id" as "root_id",
110
- "root_"."id" as "root_id"
110
+ "root_"."id" as "root_$key_id"
111
111
  from "public"."post" as "root_"`,
112
112
  response: {
113
- rows: [{ root_id: testUuid(1) }, { root_id: testUuid(2) }],
113
+ rows: [{ 'root_id': testUuid(1), 'root_$key_id': testUuid(1) }, { 'root_id': testUuid(2), 'root_$key_id': testUuid(2) }],
114
114
  },
115
115
  },
116
116
  {
@@ -214,10 +214,10 @@ test.only('large number of posts - use array', async () => {
214
214
  executes: [
215
215
  {
216
216
  sql: SQL`select "root_"."id" as "root_id",
217
- "root_"."id" as "root_id"
217
+ "root_"."id" as "root_$key_id"
218
218
  from "public"."post" as "root_"`,
219
219
  response: {
220
- rows: ids.map(id => ({ root_id: id })),
220
+ rows: ids.map(id => ({ 'root_id': id, 'root_$key_id': id })),
221
221
  },
222
222
  },
223
223
  {
@@ -26,18 +26,18 @@ test('Post with author query (many has one)', async () => {
26
26
  sql: SQL`
27
27
  select
28
28
  "root_"."id" as "root_id",
29
- "root_"."author_id" as "root_author"
29
+ "root_"."author_id" as "root_$key_author"
30
30
  from "public"."post" as "root_"
31
31
  `,
32
32
  response: {
33
33
  rows: [
34
34
  {
35
- root_id: testUuid(1),
36
- root_author: testUuid(2),
35
+ 'root_id': testUuid(1),
36
+ 'root_$key_author': testUuid(2),
37
37
  },
38
38
  {
39
- root_id: testUuid(3),
40
- root_author: testUuid(4),
39
+ 'root_id': testUuid(3),
40
+ 'root_$key_author': testUuid(4),
41
41
  },
42
42
  ],
43
43
  },
@@ -45,7 +45,7 @@ test('Post with author query (many has one)', async () => {
45
45
  {
46
46
  sql: SQL`
47
47
  select
48
- "root_"."id" as "root_id",
48
+ "root_"."id" as "root_$index_id",
49
49
  "root_"."id" as "root_id",
50
50
  "root_"."name" as "root_name"
51
51
  from "public"."author" as "root_"
@@ -55,12 +55,14 @@ test('Post with author query (many has one)', async () => {
55
55
  response: {
56
56
  rows: [
57
57
  {
58
- root_id: testUuid(2),
59
- root_name: 'John',
58
+ 'root_id': testUuid(2),
59
+ 'root_$index_id': testUuid(2),
60
+ 'root_name': 'John',
60
61
  },
61
62
  {
62
- root_id: testUuid(4),
63
- root_name: 'Jack',
63
+ 'root_id': testUuid(4),
64
+ 'root_$index_id': testUuid(4),
65
+ 'root_name': 'Jack',
64
66
  },
65
67
  ],
66
68
  },
@@ -110,7 +112,7 @@ test('Post with author query with no result', async () => {
110
112
  sql: SQL`
111
113
  select
112
114
  "root_"."id" as "root_id",
113
- "root_"."author_id" as "root_author"
115
+ "root_"."author_id" as "root_$key_author"
114
116
  from "public"."post" as "root_"
115
117
  `,
116
118
  response: {
@@ -145,24 +147,24 @@ test('Post with author filtered by name (where many has one)', async () => {
145
147
  {
146
148
  sql: SQL`select
147
149
  "root_"."id" as "root_id",
148
- "root_"."author_id" as "root_author"
150
+ "root_"."author_id" as "root_$key_author"
149
151
  from "public"."post" as "root_"`,
150
152
  response: {
151
153
  rows: [
152
154
  {
153
- root_id: testUuid(1),
154
- root_author: testUuid(2),
155
+ 'root_id': testUuid(1),
156
+ 'root_$key_author': testUuid(2),
155
157
  },
156
158
  {
157
- root_id: testUuid(3),
158
- root_author: testUuid(4),
159
+ 'root_id': testUuid(3),
160
+ 'root_$key_author': testUuid(4),
159
161
  },
160
162
  ],
161
163
  },
162
164
  },
163
165
  {
164
166
  sql: SQL`select
165
- "root_"."id" as "root_id",
167
+ "root_"."id" as "root_$index_id",
166
168
  "root_"."id" as "root_id"
167
169
  from "public"."author" as "root_"
168
170
  where "root_"."id" in (?, ?) and "root_"."name" = ?`,
@@ -170,7 +172,8 @@ test('Post with author filtered by name (where many has one)', async () => {
170
172
  response: {
171
173
  rows: [
172
174
  {
173
- root_id: testUuid(2),
175
+ 'root_id': testUuid(2),
176
+ 'root_$index_id': testUuid(2),
174
177
  },
175
178
  ],
176
179
  },
@@ -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 "root_id"
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 "root_id"
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 "root_id"
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
  {
@@ -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 "root_id"
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 "root_id"
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
  {
@@ -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 "root_id"
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
  {
@@ -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 "root_id"
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
- root_url: 'http://site1.cz',
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
- root_url: 'http://site2.cz',
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 "root_setting",
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
- root_setting: testUuid(1),
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
- root_setting: testUuid(3),
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 "root_setting"
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
- root_setting: testUuid(2),
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
- root_setting: testUuid(4),
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 "root_id",
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
- root_url: 'http://site1.cz',
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
- root_url: 'http://site2.cz',
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 "root_id" from "public"."menu" as "root_"`,
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 "root_id" from "public"."post" as "root_"`,
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 "root_id"
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 "root_id"
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 "root_id", "root_"."id" as "root_id"
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 "root_author", "root_"."post_count" as "root_postCount", "root_"."id" as "root_id"
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
- root_author: testUuid(1),
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
- root_author: testUuid(2),
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
+ })