@contember/engine-content-api 2.2.0-alpha.14 → 2.2.0-alpha.16

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 (156) hide show
  1. package/CLAUDE.md +1 -0
  2. package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.cjs +1 -0
  3. package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.cjs.map +1 -1
  4. package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.js +1 -0
  5. package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.js.map +1 -1
  6. package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.cjs +1 -0
  7. package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.cjs.map +1 -1
  8. package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.js +1 -0
  9. package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.js.map +1 -1
  10. package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.cjs +1 -0
  11. package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.cjs.map +1 -1
  12. package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.js +1 -0
  13. package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.js.map +1 -1
  14. package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.cjs +1 -0
  15. package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.cjs.map +1 -1
  16. package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.js +1 -0
  17. package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.js.map +1 -1
  18. package/dist/development/src/mapper/ErrorUtils.cjs +7 -1
  19. package/dist/development/src/mapper/ErrorUtils.cjs.map +1 -1
  20. package/dist/development/src/mapper/ErrorUtils.js +7 -1
  21. package/dist/development/src/mapper/ErrorUtils.js.map +1 -1
  22. package/dist/development/src/mapper/Mapper.cjs +2 -1
  23. package/dist/development/src/mapper/Mapper.cjs.map +1 -1
  24. package/dist/development/src/mapper/Mapper.js +2 -1
  25. package/dist/development/src/mapper/Mapper.js.map +1 -1
  26. package/dist/development/src/mapper/select/Path.cjs +23 -3
  27. package/dist/development/src/mapper/select/Path.cjs.map +1 -1
  28. package/dist/development/src/mapper/select/Path.js +23 -3
  29. package/dist/development/src/mapper/select/Path.js.map +1 -1
  30. package/dist/development/src/mapper/select/SelectBuilder.cjs +5 -5
  31. package/dist/development/src/mapper/select/SelectBuilder.cjs.map +1 -1
  32. package/dist/development/src/mapper/select/SelectBuilder.js +5 -5
  33. package/dist/development/src/mapper/select/SelectBuilder.js.map +1 -1
  34. package/dist/development/src/mapper/select/handlers/FieldsVisitor.cjs +1 -1
  35. package/dist/development/src/mapper/select/handlers/FieldsVisitor.cjs.map +1 -1
  36. package/dist/development/src/mapper/select/handlers/FieldsVisitor.js +1 -1
  37. package/dist/development/src/mapper/select/handlers/FieldsVisitor.js.map +1 -1
  38. package/dist/development/src/resolvers/MutationResolver.cjs +1 -0
  39. package/dist/development/src/resolvers/MutationResolver.cjs.map +1 -1
  40. package/dist/development/src/resolvers/MutationResolver.js +1 -0
  41. package/dist/development/src/resolvers/MutationResolver.js.map +1 -1
  42. package/dist/development/src/resolvers/ReadHelpers.cjs +1 -0
  43. package/dist/development/src/resolvers/ReadHelpers.cjs.map +1 -1
  44. package/dist/development/src/resolvers/ReadHelpers.js +1 -0
  45. package/dist/development/src/resolvers/ReadHelpers.js.map +1 -1
  46. package/dist/development/src/resolvers/ReadResolver.cjs +21 -7
  47. package/dist/development/src/resolvers/ReadResolver.cjs.map +1 -1
  48. package/dist/development/src/resolvers/ReadResolver.js +21 -7
  49. package/dist/development/src/resolvers/ReadResolver.js.map +1 -1
  50. package/dist/development/src/schema/GraphQlSchemaBuilderFactory.cjs +1 -0
  51. package/dist/development/src/schema/GraphQlSchemaBuilderFactory.cjs.map +1 -1
  52. package/dist/development/src/schema/GraphQlSchemaBuilderFactory.js +1 -0
  53. package/dist/development/src/schema/GraphQlSchemaBuilderFactory.js.map +1 -1
  54. package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.cjs +1 -0
  55. package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.cjs.map +1 -1
  56. package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.js +1 -0
  57. package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.js.map +1 -1
  58. package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.cjs +1 -0
  59. package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.cjs.map +1 -1
  60. package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.js +1 -0
  61. package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.js.map +1 -1
  62. package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.cjs +1 -0
  63. package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.cjs.map +1 -1
  64. package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.js +1 -0
  65. package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.js.map +1 -1
  66. package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.cjs +1 -0
  67. package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.cjs.map +1 -1
  68. package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.js +1 -0
  69. package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.js.map +1 -1
  70. package/dist/production/src/mapper/ErrorUtils.cjs +7 -1
  71. package/dist/production/src/mapper/ErrorUtils.cjs.map +1 -1
  72. package/dist/production/src/mapper/ErrorUtils.js +7 -1
  73. package/dist/production/src/mapper/ErrorUtils.js.map +1 -1
  74. package/dist/production/src/mapper/Mapper.cjs +2 -1
  75. package/dist/production/src/mapper/Mapper.cjs.map +1 -1
  76. package/dist/production/src/mapper/Mapper.js +2 -1
  77. package/dist/production/src/mapper/Mapper.js.map +1 -1
  78. package/dist/production/src/mapper/select/Path.cjs +23 -3
  79. package/dist/production/src/mapper/select/Path.cjs.map +1 -1
  80. package/dist/production/src/mapper/select/Path.js +23 -3
  81. package/dist/production/src/mapper/select/Path.js.map +1 -1
  82. package/dist/production/src/mapper/select/SelectBuilder.cjs +5 -5
  83. package/dist/production/src/mapper/select/SelectBuilder.cjs.map +1 -1
  84. package/dist/production/src/mapper/select/SelectBuilder.js +5 -5
  85. package/dist/production/src/mapper/select/SelectBuilder.js.map +1 -1
  86. package/dist/production/src/mapper/select/handlers/FieldsVisitor.cjs +1 -1
  87. package/dist/production/src/mapper/select/handlers/FieldsVisitor.cjs.map +1 -1
  88. package/dist/production/src/mapper/select/handlers/FieldsVisitor.js +1 -1
  89. package/dist/production/src/mapper/select/handlers/FieldsVisitor.js.map +1 -1
  90. package/dist/production/src/resolvers/MutationResolver.cjs +1 -0
  91. package/dist/production/src/resolvers/MutationResolver.cjs.map +1 -1
  92. package/dist/production/src/resolvers/MutationResolver.js +1 -0
  93. package/dist/production/src/resolvers/MutationResolver.js.map +1 -1
  94. package/dist/production/src/resolvers/ReadHelpers.cjs +1 -0
  95. package/dist/production/src/resolvers/ReadHelpers.cjs.map +1 -1
  96. package/dist/production/src/resolvers/ReadHelpers.js +1 -0
  97. package/dist/production/src/resolvers/ReadHelpers.js.map +1 -1
  98. package/dist/production/src/resolvers/ReadResolver.cjs +21 -7
  99. package/dist/production/src/resolvers/ReadResolver.cjs.map +1 -1
  100. package/dist/production/src/resolvers/ReadResolver.js +21 -7
  101. package/dist/production/src/resolvers/ReadResolver.js.map +1 -1
  102. package/dist/production/src/schema/GraphQlSchemaBuilderFactory.cjs +1 -0
  103. package/dist/production/src/schema/GraphQlSchemaBuilderFactory.cjs.map +1 -1
  104. package/dist/production/src/schema/GraphQlSchemaBuilderFactory.js +1 -0
  105. package/dist/production/src/schema/GraphQlSchemaBuilderFactory.js.map +1 -1
  106. package/dist/tests/cases/unit/mutationSqlError.test.d.ts +2 -0
  107. package/dist/tests/cases/unit/mutationSqlError.test.d.ts.map +1 -0
  108. package/dist/tests/cases/unit/pathAlias.test.d.ts +2 -0
  109. package/dist/tests/cases/unit/pathAlias.test.d.ts.map +1 -0
  110. package/dist/tests/tsconfig.tsbuildinfo +1 -1
  111. package/dist/types/mapper/ErrorUtils.d.ts.map +1 -1
  112. package/dist/types/mapper/select/Path.d.ts +1 -0
  113. package/dist/types/mapper/select/Path.d.ts.map +1 -1
  114. package/dist/types/mapper/select/SelectBuilder.d.ts.map +1 -1
  115. package/dist/types/resolvers/ReadResolver.d.ts.map +1 -1
  116. package/dist/types/tsconfig.tsbuildinfo +1 -1
  117. package/package.json +9 -9
  118. package/src/mapper/ErrorUtils.ts +11 -1
  119. package/src/mapper/Mapper.ts +1 -1
  120. package/src/mapper/select/Path.ts +25 -5
  121. package/src/mapper/select/SelectBuilder.ts +5 -4
  122. package/src/mapper/select/handlers/FieldsVisitor.ts +1 -1
  123. package/src/resolvers/ReadResolver.ts +24 -7
  124. package/tests/cases/bugs/bug102.test.ts +4 -4
  125. package/tests/cases/integration/graphQlRequests/delete/deleteById.test.ts +4 -3
  126. package/tests/cases/integration/graphQlRequests/query/acl/differentRowAndFieldPredicate.test.ts +4 -4
  127. package/tests/cases/integration/graphQlRequests/query/acl/fieldRestrictedByLocale.test.ts +12 -10
  128. package/tests/cases/integration/graphQlRequests/query/acl/metaReadableThroughContext.test.ts +15 -15
  129. package/tests/cases/integration/graphQlRequests/query/acl/nestedPredicate.test.ts +7 -6
  130. package/tests/cases/integration/graphQlRequests/query/acl/nonAdjacentBackReference.test.ts +6 -6
  131. package/tests/cases/integration/graphQlRequests/query/acl/orderByCellPredicate.test.ts +6 -6
  132. package/tests/cases/integration/graphQlRequests/query/acl/predicateElimination.test.ts +25 -23
  133. package/tests/cases/integration/graphQlRequests/query/acl/relationAcl.test.ts +12 -9
  134. package/tests/cases/integration/graphQlRequests/query/acl/rowPredicateSubset.test.ts +6 -6
  135. package/tests/cases/integration/graphQlRequests/query/acl/throughScope.test.ts +14 -12
  136. package/tests/cases/integration/graphQlRequests/query/acl/throughScopeNullability.test.ts +4 -4
  137. package/tests/cases/integration/graphQlRequests/query/filter/backReferencedFilter.test.ts +3 -1
  138. package/tests/cases/integration/graphQlRequests/query/graphqlFeatures/alias.test.ts +2 -2
  139. package/tests/cases/integration/graphQlRequests/query/graphqlFeatures/fragments.test.ts +8 -8
  140. package/tests/cases/integration/graphQlRequests/query/misc/reducedHasMany.test.ts +10 -10
  141. package/tests/cases/integration/graphQlRequests/query/pagination/hasManyLimit.test.ts +8 -8
  142. package/tests/cases/integration/graphQlRequests/query/pagination/paginate.test.ts +5 -4
  143. package/tests/cases/integration/graphQlRequests/query/pagination/paginateAliased.test.ts +5 -4
  144. package/tests/cases/integration/graphQlRequests/query/relations/advanced.test.ts +17 -8
  145. package/tests/cases/integration/graphQlRequests/query/relations/manyHasManyInverse.test.ts +6 -6
  146. package/tests/cases/integration/graphQlRequests/query/relations/manyHasManyOwning.test.ts +6 -6
  147. package/tests/cases/integration/graphQlRequests/query/relations/manyHasOne.test.ts +12 -9
  148. package/tests/cases/integration/graphQlRequests/query/relations/oneHasMany.test.ts +12 -12
  149. package/tests/cases/integration/graphQlRequests/query/relations/oneHasOneInverse.test.ts +6 -4
  150. package/tests/cases/integration/graphQlRequests/query/relations/oneHasOneOwner.test.ts +6 -4
  151. package/tests/cases/integration/graphQlRequests/query/sorting/defaultOrdering.test.ts +4 -4
  152. package/tests/cases/integration/graphQlRequests/query/sorting/randomSort.test.ts +5 -5
  153. package/tests/cases/integration/graphQlRequests/query/sorting/sortedHasMany.test.ts +2 -2
  154. package/tests/cases/integration/graphQlRequests/query/view/view.test.ts +6 -6
  155. package/tests/cases/unit/mutationSqlError.test.ts +30 -0
  156. package/tests/cases/unit/pathAlias.test.ts +26 -0
@@ -41,7 +41,7 @@ where "root_author"."name" = ?`,
41
41
  response: { rows: [{ row_count: 10 }] },
42
42
  },
43
43
  {
44
- sql: SQL`select "root_"."id" as "root_id", "root_"."title" as "root_title", "root_"."author_id" as "root_author"
44
+ sql: SQL`select "root_"."id" as "root_id", "root_"."title" as "root_title", "root_"."author_id" as "root_$key_author"
45
45
  from "public"."post" as "root_"
46
46
  left join "public"."author" as "root_author" on "root_"."author_id" = "root_author"."id"
47
47
  where "root_author"."name" = ? order by "root_"."id" asc limit 2 offset 1`,
@@ -50,12 +50,12 @@ where "root_author"."name" = ? order by "root_"."id" asc limit 2 offset 1`,
50
50
  {
51
51
  root_id: testUuid(1),
52
52
  root_title: 'Foo',
53
- root_author: testUuid(2),
53
+ 'root_$key_author': testUuid(2),
54
54
  },
55
55
  {
56
56
  root_id: testUuid(3),
57
57
  root_title: 'Bar',
58
- root_author: testUuid(2),
58
+ 'root_$key_author': testUuid(2),
59
59
  },
60
60
  ],
61
61
  },
@@ -63,7 +63,7 @@ where "root_author"."name" = ? order by "root_"."id" asc limit 2 offset 1`,
63
63
  {
64
64
  sql: SQL`
65
65
  select
66
- "root_"."id" as "root_id",
66
+ "root_"."id" as "root_$index_id",
67
67
  "root_"."name" as "root_name",
68
68
  "root_"."id" as "root_id"
69
69
  from "public"."author" as "root_"
@@ -74,6 +74,7 @@ where "root_author"."name" = ? order by "root_"."id" asc limit 2 offset 1`,
74
74
  rows: [
75
75
  {
76
76
  root_id: testUuid(2),
77
+ 'root_$index_id': testUuid(2),
77
78
  root_name: 'jack',
78
79
  },
79
80
  ],
@@ -37,15 +37,17 @@ test('Posts with categories and its cz locale (many has many owning + one has ma
37
37
  {
38
38
  sql: SQL`select
39
39
  "root_"."id" as "root_id",
40
- "root_"."id" as "root_id"
40
+ "root_"."id" as "root_$key_id"
41
41
  from "public"."post" as "root_"`,
42
42
  response: {
43
43
  rows: [
44
44
  {
45
45
  root_id: testUuid(1),
46
+ 'root_$key_id': testUuid(1),
46
47
  },
47
48
  {
48
49
  root_id: testUuid(2),
50
+ 'root_$key_id': testUuid(2),
49
51
  },
50
52
  ],
51
53
  },
@@ -81,7 +83,7 @@ test('Posts with categories and its cz locale (many has many owning + one has ma
81
83
  {
82
84
  sql: SQL`select
83
85
  "root_"."visible" as "root_visible",
84
- "root_"."id" as "root_id",
86
+ "root_"."id" as "root_$key_id",
85
87
  "root_"."id" as "root_id"
86
88
  from "public"."category" as "root_"
87
89
  where "root_"."id" in (?, ?, ?)`,
@@ -90,14 +92,17 @@ test('Posts with categories and its cz locale (many has many owning + one has ma
90
92
  rows: [
91
93
  {
92
94
  root_id: testUuid(3),
95
+ 'root_$key_id': testUuid(3),
93
96
  root_visible: true,
94
97
  },
95
98
  {
96
99
  root_id: testUuid(4),
100
+ 'root_$key_id': testUuid(4),
97
101
  root_visible: true,
98
102
  },
99
103
  {
100
104
  root_id: testUuid(5),
105
+ 'root_$key_id': testUuid(5),
101
106
  root_visible: true,
102
107
  },
103
108
  ],
@@ -219,15 +224,17 @@ test('Categories with posts and author (many has many inverse + many has one)',
219
224
  {
220
225
  sql: SQL`select
221
226
  "root_"."id" as "root_id",
222
- "root_"."id" as "root_id"
227
+ "root_"."id" as "root_$key_id"
223
228
  from "public"."category" as "root_"`,
224
229
  response: {
225
230
  rows: [
226
231
  {
227
232
  root_id: testUuid(1),
233
+ 'root_$key_id': testUuid(1),
228
234
  },
229
235
  {
230
236
  root_id: testUuid(2),
237
+ 'root_$key_id': testUuid(2),
231
238
  },
232
239
  ],
233
240
  },
@@ -262,7 +269,7 @@ test('Categories with posts and author (many has many inverse + many has one)',
262
269
  },
263
270
  {
264
271
  sql: SQL`select
265
- "root_"."author_id" as "root_author",
272
+ "root_"."author_id" as "root_$key_author",
266
273
  "root_"."id" as "root_id"
267
274
  from "public"."post" as "root_"
268
275
  where "root_"."id" in (?, ?, ?)
@@ -272,22 +279,22 @@ test('Categories with posts and author (many has many inverse + many has one)',
272
279
  rows: [
273
280
  {
274
281
  root_id: testUuid(3),
275
- root_author: testUuid(6),
282
+ 'root_$key_author': testUuid(6),
276
283
  },
277
284
  {
278
285
  root_id: testUuid(4),
279
- root_author: testUuid(7),
286
+ 'root_$key_author': testUuid(7),
280
287
  },
281
288
  {
282
289
  root_id: testUuid(5),
283
- root_author: testUuid(7),
290
+ 'root_$key_author': testUuid(7),
284
291
  },
285
292
  ],
286
293
  },
287
294
  },
288
295
  {
289
296
  sql: SQL`select
290
- "root_"."id" as "root_id",
297
+ "root_"."id" as "root_$index_id",
291
298
  "root_"."name" as "root_name",
292
299
  "root_"."id" as "root_id"
293
300
  from "public"."author" as "root_"
@@ -298,10 +305,12 @@ test('Categories with posts and author (many has many inverse + many has one)',
298
305
  rows: [
299
306
  {
300
307
  root_id: testUuid(6),
308
+ 'root_$index_id': testUuid(6),
301
309
  root_name: 'John',
302
310
  },
303
311
  {
304
312
  root_id: testUuid(7),
313
+ 'root_$index_id': testUuid(7),
305
314
  root_name: 'Jack',
306
315
  },
307
316
  ],
@@ -30,10 +30,10 @@ test('Tags with paginated posts (many has many inverse)', async () => {
30
30
  executes: [
31
31
  {
32
32
  sql: SQL`select "root_"."id" as "root_id",
33
- "root_"."id" as "root_id"
33
+ "root_"."id" as "root_$key_id"
34
34
  from "public"."tag" as "root_"`,
35
35
  response: {
36
- rows: [{ root_id: testUuid(1) }, { root_id: testUuid(2) }],
36
+ 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
  {
@@ -135,10 +135,10 @@ test('empty many-has-many inverse relation', async () => {
135
135
  executes: [
136
136
  {
137
137
  sql: SQL`select "root_"."id" as "root_id",
138
- "root_"."id" as "root_id"
138
+ "root_"."id" as "root_$key_id"
139
139
  from "public"."tag" as "root_"`,
140
140
  response: {
141
- rows: [{ root_id: testUuid(1) }, { root_id: testUuid(2) }],
141
+ rows: [{ root_id: testUuid(1), 'root_$key_id': testUuid(1) }, { root_id: testUuid(2), 'root_$key_id': testUuid(2) }],
142
142
  },
143
143
  },
144
144
  {
@@ -185,10 +185,10 @@ test('Posts with filtered tags', async () => {
185
185
  executes: [
186
186
  {
187
187
  sql: SQL`select "root_"."id" as "root_id",
188
- "root_"."id" as "root_id"
188
+ "root_"."id" as "root_$key_id"
189
189
  from "public"."post" as "root_"`,
190
190
  response: {
191
- rows: [{ root_id: testUuid(1) }, { root_id: testUuid(2) }],
191
+ rows: [{ root_id: testUuid(1), 'root_$key_id': testUuid(1) }, { root_id: testUuid(2), 'root_$key_id': testUuid(2) }],
192
192
  },
193
193
  },
194
194
  {
@@ -23,10 +23,10 @@ test('Posts with filtered tags', async () => {
23
23
  executes: [
24
24
  {
25
25
  sql: SQL`select "root_"."id" as "root_id",
26
- "root_"."id" as "root_id"
26
+ "root_"."id" as "root_$key_id"
27
27
  from "public"."post" as "root_"`,
28
28
  response: {
29
- rows: [{ root_id: testUuid(1) }, { root_id: testUuid(2) }],
29
+ rows: [{ root_id: testUuid(1), 'root_$key_id': testUuid(1) }, { root_id: testUuid(2), 'root_$key_id': testUuid(2) }],
30
30
  },
31
31
  },
32
32
  {
@@ -105,10 +105,10 @@ test('Posts with paginated tags (many has many owning)', async () => {
105
105
  executes: [
106
106
  {
107
107
  sql: SQL`select "root_"."id" as "root_id",
108
- "root_"."id" as "root_id"
108
+ "root_"."id" as "root_$key_id"
109
109
  from "public"."post" as "root_"`,
110
110
  response: {
111
- rows: [{ root_id: testUuid(1) }, { root_id: testUuid(2) }],
111
+ rows: [{ root_id: testUuid(1), 'root_$key_id': testUuid(1) }, { root_id: testUuid(2), 'root_$key_id': testUuid(2) }],
112
112
  },
113
113
  },
114
114
  {
@@ -211,10 +211,10 @@ test('large number of posts - use array', async () => {
211
211
  executes: [
212
212
  {
213
213
  sql: SQL`select "root_"."id" as "root_id",
214
- "root_"."id" as "root_id"
214
+ "root_"."id" as "root_$key_id"
215
215
  from "public"."post" as "root_"`,
216
216
  response: {
217
- rows: ids.map(id => ({ root_id: id })),
217
+ rows: ids.map(id => ({ root_id: id, 'root_$key_id': id })),
218
218
  },
219
219
  },
220
220
  {
@@ -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
35
  root_id: testUuid(1),
36
- root_author: testUuid(2),
36
+ 'root_$key_author': testUuid(2),
37
37
  },
38
38
  {
39
39
  root_id: testUuid(3),
40
- root_author: testUuid(4),
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_"
@@ -56,10 +56,12 @@ test('Post with author query (many has one)', async () => {
56
56
  rows: [
57
57
  {
58
58
  root_id: testUuid(2),
59
+ 'root_$index_id': testUuid(2),
59
60
  root_name: 'John',
60
61
  },
61
62
  {
62
63
  root_id: testUuid(4),
64
+ 'root_$index_id': testUuid(4),
63
65
  root_name: 'Jack',
64
66
  },
65
67
  ],
@@ -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
155
  root_id: testUuid(1),
154
- root_author: testUuid(2),
156
+ 'root_$key_author': testUuid(2),
155
157
  },
156
158
  {
157
159
  root_id: testUuid(3),
158
- root_author: testUuid(4),
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" = ?`,
@@ -171,6 +173,7 @@ test('Post with author filtered by name (where many has one)', async () => {
171
173
  rows: [
172
174
  {
173
175
  root_id: testUuid(2),
176
+ 'root_$index_id': testUuid(2),
174
177
  },
175
178
  ],
176
179
  },
@@ -30,9 +30,9 @@ test('Posts with locales query (one has many)', async () => {
30
30
  {
31
31
  sql: SQL`select
32
32
  "root_"."id" as "root_id",
33
- "root_"."id" as "root_id"
33
+ "root_"."id" as "root_$key_id"
34
34
  from "public"."post" as "root_"`,
35
- response: { rows: [{ root_id: testUuid(1) }, { root_id: testUuid(2) }] },
35
+ response: { rows: [{ root_id: testUuid(1), 'root_$key_id': testUuid(1) }, { root_id: testUuid(2), 'root_$key_id': testUuid(2) }] },
36
36
  },
37
37
  {
38
38
  sql: SQL`select
@@ -111,10 +111,10 @@ test('Posts with locales query with where (one has many)', async () => {
111
111
  {
112
112
  sql: SQL`select
113
113
  "root_"."id" as "root_id",
114
- "root_"."id" as "root_id"
114
+ "root_"."id" as "root_$key_id"
115
115
  from "public"."post" as "root_"`,
116
116
  response: {
117
- rows: [{ root_id: testUuid(1) }, { root_id: testUuid(2) }],
117
+ rows: [{ root_id: testUuid(1), 'root_$key_id': testUuid(1) }, { root_id: testUuid(2), 'root_$key_id': testUuid(2) }],
118
118
  },
119
119
  },
120
120
  {
@@ -190,10 +190,10 @@ test('Posts with paginated comments (one has many)', async () => {
190
190
  {
191
191
  sql: SQL`select
192
192
  "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
  {
@@ -288,10 +288,10 @@ test('Posts with comment count (one has many)', async () => {
288
288
  {
289
289
  sql: SQL`select
290
290
  "root_"."id" as "root_id",
291
- "root_"."id" as "root_id"
291
+ "root_"."id" as "root_$key_id"
292
292
  from "public"."post" as "root_"`,
293
293
  response: {
294
- rows: [{ root_id: testUuid(1) }, { root_id: testUuid(2) }],
294
+ rows: [{ root_id: testUuid(1), 'root_$key_id': testUuid(1) }, { root_id: testUuid(2), 'root_$key_id': testUuid(2) }],
295
295
  },
296
296
  },
297
297
  {
@@ -358,10 +358,10 @@ test('Posts with paginated comments without count (one has many)', async () => {
358
358
  {
359
359
  sql: SQL`select
360
360
  "root_"."id" as "root_id",
361
- "root_"."id" as "root_id"
361
+ "root_"."id" as "root_$key_id"
362
362
  from "public"."post" as "root_"`,
363
363
  response: {
364
- rows: [{ root_id: testUuid(1) }, { root_id: testUuid(2) }],
364
+ rows: [{ root_id: testUuid(1), 'root_$key_id': testUuid(1) }, { root_id: testUuid(2), 'root_$key_id': testUuid(2) }],
365
365
  },
366
366
  },
367
367
  {
@@ -441,10 +441,10 @@ test('Posts with paginated comments (one has many)', async () => {
441
441
  {
442
442
  sql: SQL`select
443
443
  "root_"."id" as "root_id",
444
- "root_"."id" as "root_id"
444
+ "root_"."id" as "root_$key_id"
445
445
  from "public"."post" as "root_"`,
446
446
  response: {
447
- rows: [{ root_id: testUuid(1) }],
447
+ rows: [{ root_id: testUuid(1), 'root_$key_id': testUuid(1) }],
448
448
  },
449
449
  },
450
450
  {
@@ -29,16 +29,18 @@ test('Settings with sites (one-has-one inverse)', async () => {
29
29
  sql: SQL`select
30
30
  "root_"."id" as "root_id",
31
31
  "root_"."url" as "root_url",
32
- "root_"."id" as "root_id"
32
+ "root_"."id" as "root_$key_id"
33
33
  from "public"."site_setting" as "root_"`,
34
34
  response: {
35
35
  rows: [
36
36
  {
37
37
  root_id: testUuid(1),
38
+ 'root_$key_id': testUuid(1),
38
39
  root_url: 'http://site1.cz',
39
40
  },
40
41
  {
41
42
  root_id: testUuid(3),
43
+ 'root_$key_id': testUuid(3),
42
44
  root_url: 'http://site2.cz',
43
45
  },
44
46
  ],
@@ -46,7 +48,7 @@ test('Settings with sites (one-has-one inverse)', async () => {
46
48
  },
47
49
  {
48
50
  sql: SQL`select
49
- "root_"."setting_id" as "root_setting",
51
+ "root_"."setting_id" as "root_$index_setting",
50
52
  "root_"."id" as "root_id",
51
53
  "root_"."name" as "root_name"
52
54
  from "public"."site" as "root_"
@@ -56,12 +58,12 @@ test('Settings with sites (one-has-one inverse)', async () => {
56
58
  rows: [
57
59
  {
58
60
  root_id: testUuid(2),
59
- root_setting: testUuid(1),
61
+ 'root_$index_setting': testUuid(1),
60
62
  root_name: 'Site 1',
61
63
  },
62
64
  {
63
65
  root_id: testUuid(4),
64
- root_setting: testUuid(3),
66
+ 'root_$index_setting': testUuid(3),
65
67
  root_name: 'Site 2',
66
68
  },
67
69
  ],
@@ -30,7 +30,7 @@ test('Sites with settings (one-has-one owning)', async () => {
30
30
  select
31
31
  "root_"."id" as "root_id",
32
32
  "root_"."name" as "root_name",
33
- "root_"."setting_id" as "root_setting"
33
+ "root_"."setting_id" as "root_$key_setting"
34
34
  from "public"."site" as "root_"`,
35
35
 
36
36
  response: {
@@ -38,12 +38,12 @@ test('Sites with settings (one-has-one owning)', async () => {
38
38
  {
39
39
  root_id: testUuid(1),
40
40
  root_name: 'Site 1',
41
- root_setting: testUuid(2),
41
+ 'root_$key_setting': testUuid(2),
42
42
  },
43
43
  {
44
44
  root_id: testUuid(3),
45
45
  root_name: 'Site 2',
46
- root_setting: testUuid(4),
46
+ 'root_$key_setting': testUuid(4),
47
47
  },
48
48
  ],
49
49
  },
@@ -51,7 +51,7 @@ test('Sites with settings (one-has-one owning)', async () => {
51
51
  {
52
52
  sql: SQL`
53
53
  select
54
- "root_"."id" as "root_id",
54
+ "root_"."id" as "root_$index_id",
55
55
  "root_"."id" as "root_id",
56
56
  "root_"."url" as "root_url"
57
57
  from "public"."site_setting" as "root_"
@@ -62,10 +62,12 @@ test('Sites with settings (one-has-one owning)', async () => {
62
62
  rows: [
63
63
  {
64
64
  root_id: testUuid(2),
65
+ 'root_$index_id': testUuid(2),
65
66
  root_url: 'http://site1.cz',
66
67
  },
67
68
  {
68
69
  root_id: testUuid(4),
70
+ 'root_$index_id': testUuid(4),
69
71
  root_url: 'http://site2.cz',
70
72
  },
71
73
  ],
@@ -26,10 +26,10 @@ test('one has many - default ordering', async () => {
26
26
  }`,
27
27
  executes: [
28
28
  {
29
- sql: SQL`select "root_"."id" as "root_id", "root_"."id" as "root_id" from "public"."menu" as "root_"`,
29
+ sql: SQL`select "root_"."id" as "root_id", "root_"."id" as "root_$key_id" from "public"."menu" as "root_"`,
30
30
  parameters: [],
31
31
  response: {
32
- rows: [{ root_id: testUuid(1) }, { root_id: testUuid(2) }],
32
+ rows: [{ root_id: testUuid(1), 'root_$key_id': testUuid(1) }, { root_id: testUuid(2), 'root_$key_id': testUuid(2) }],
33
33
  },
34
34
  },
35
35
  {
@@ -97,10 +97,10 @@ test('many has many - default ordering', async () => {
97
97
  }`,
98
98
  executes: [
99
99
  {
100
- sql: SQL`select "root_"."id" as "root_id", "root_"."id" as "root_id" from "public"."post" as "root_"`,
100
+ sql: SQL`select "root_"."id" as "root_id", "root_"."id" as "root_$key_id" from "public"."post" as "root_"`,
101
101
  parameters: [],
102
102
  response: {
103
- rows: [{ root_id: testUuid(1) }, { root_id: testUuid(2) }],
103
+ rows: [{ root_id: testUuid(1), 'root_$key_id': testUuid(1) }, { root_id: testUuid(2), 'root_$key_id': testUuid(2) }],
104
104
  },
105
105
  },
106
106
  {
@@ -114,13 +114,13 @@ test('sorts posts by random on has many relation', async () => {
114
114
  sql: SQL`select
115
115
  "root_"."id" as "root_id",
116
116
  "root_"."title" as "root_title",
117
- "root_"."id" as "root_id"
117
+ "root_"."id" as "root_$key_id"
118
118
  from "public"."category" as "root_"`,
119
119
  parameters: [],
120
120
  response: {
121
121
  rows: [
122
- { root_id: testUuid(1), root_title: 'Hello' },
123
- { root_id: testUuid(2), root_title: 'World' },
122
+ { root_id: testUuid(1), 'root_$key_id': testUuid(1), root_title: 'Hello' },
123
+ { root_id: testUuid(2), 'root_$key_id': testUuid(2), root_title: 'World' },
124
124
  ],
125
125
  },
126
126
  },
@@ -273,9 +273,9 @@ test('joins the has-many target for a field key that follows a random key', asyn
273
273
  }`,
274
274
  executes: [
275
275
  {
276
- sql: SQL`select "root_"."id" as "root_id", "root_"."id" as "root_id" from "public"."category" as "root_"`,
276
+ sql: SQL`select "root_"."id" as "root_id", "root_"."id" as "root_$key_id" from "public"."category" as "root_"`,
277
277
  parameters: [],
278
- response: { rows: [{ root_id: testUuid(1) }] },
278
+ response: { rows: [{ root_id: testUuid(1), 'root_$key_id': testUuid(1) }] },
279
279
  },
280
280
  {
281
281
  sql: SQL`
@@ -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,19 +31,19 @@ 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)],
@@ -51,12 +51,12 @@ test('query a view through a relation', async () => {
51
51
  rows: [
52
52
  {
53
53
  root_id: null,
54
- root_author: testUuid(1),
54
+ 'root_$index_author': testUuid(1),
55
55
  root_postCount: 2,
56
56
  },
57
57
  {
58
58
  root_id: null,
59
- root_author: testUuid(2),
59
+ 'root_$index_author': testUuid(2),
60
60
  root_postCount: 3,
61
61
  },
62
62
  ],
@@ -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/index.js'
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/index.js'
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
+ })