@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.
Files changed (93) 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/RelationFetcher.cjs +1 -1
  14. package/dist/development/src/mapper/select/RelationFetcher.cjs.map +1 -1
  15. package/dist/development/src/mapper/select/RelationFetcher.js +1 -1
  16. package/dist/development/src/mapper/select/RelationFetcher.js.map +1 -1
  17. package/dist/development/src/mapper/select/SelectBuilder.cjs +5 -5
  18. package/dist/development/src/mapper/select/SelectBuilder.cjs.map +1 -1
  19. package/dist/development/src/mapper/select/SelectBuilder.js +5 -5
  20. package/dist/development/src/mapper/select/SelectBuilder.js.map +1 -1
  21. package/dist/development/src/resolvers/MutationResolver.cjs +1 -0
  22. package/dist/development/src/resolvers/MutationResolver.cjs.map +1 -1
  23. package/dist/development/src/resolvers/MutationResolver.js +1 -0
  24. package/dist/development/src/resolvers/MutationResolver.js.map +1 -1
  25. package/dist/production/src/mapper/ErrorUtils.cjs +7 -1
  26. package/dist/production/src/mapper/ErrorUtils.cjs.map +1 -1
  27. package/dist/production/src/mapper/ErrorUtils.js +7 -1
  28. package/dist/production/src/mapper/ErrorUtils.js.map +1 -1
  29. package/dist/production/src/mapper/Mapper.cjs +2 -1
  30. package/dist/production/src/mapper/Mapper.cjs.map +1 -1
  31. package/dist/production/src/mapper/Mapper.js +2 -1
  32. package/dist/production/src/mapper/Mapper.js.map +1 -1
  33. package/dist/production/src/mapper/select/Path.cjs +23 -3
  34. package/dist/production/src/mapper/select/Path.cjs.map +1 -1
  35. package/dist/production/src/mapper/select/Path.js +23 -3
  36. package/dist/production/src/mapper/select/Path.js.map +1 -1
  37. package/dist/production/src/mapper/select/RelationFetcher.cjs +1 -1
  38. package/dist/production/src/mapper/select/RelationFetcher.cjs.map +1 -1
  39. package/dist/production/src/mapper/select/RelationFetcher.js +1 -1
  40. package/dist/production/src/mapper/select/RelationFetcher.js.map +1 -1
  41. package/dist/production/src/mapper/select/SelectBuilder.cjs +5 -5
  42. package/dist/production/src/mapper/select/SelectBuilder.cjs.map +1 -1
  43. package/dist/production/src/mapper/select/SelectBuilder.js +5 -5
  44. package/dist/production/src/mapper/select/SelectBuilder.js.map +1 -1
  45. package/dist/production/src/resolvers/MutationResolver.cjs +1 -0
  46. package/dist/production/src/resolvers/MutationResolver.cjs.map +1 -1
  47. package/dist/production/src/resolvers/MutationResolver.js +1 -0
  48. package/dist/production/src/resolvers/MutationResolver.js.map +1 -1
  49. package/dist/tests/cases/unit/mutationSqlError.test.d.ts +2 -0
  50. package/dist/tests/cases/unit/mutationSqlError.test.d.ts.map +1 -0
  51. package/dist/tests/cases/unit/pathAlias.test.d.ts +2 -0
  52. package/dist/tests/cases/unit/pathAlias.test.d.ts.map +1 -0
  53. package/dist/tests/tsconfig.tsbuildinfo +1 -1
  54. package/dist/types/mapper/ErrorUtils.d.ts.map +1 -1
  55. package/dist/types/mapper/select/Path.d.ts +1 -0
  56. package/dist/types/mapper/select/Path.d.ts.map +1 -1
  57. package/dist/types/mapper/select/RelationFetcher.d.ts.map +1 -1
  58. package/dist/types/mapper/select/SelectBuilder.d.ts.map +1 -1
  59. package/dist/types/tsconfig.tsbuildinfo +1 -1
  60. package/package.json +11 -11
  61. package/src/mapper/ErrorUtils.ts +11 -1
  62. package/src/mapper/Mapper.ts +1 -1
  63. package/src/mapper/select/Path.ts +25 -5
  64. package/src/mapper/select/RelationFetcher.ts +1 -3
  65. package/src/mapper/select/SelectBuilder.ts +10 -5
  66. package/tests/cases/bugs/bug102.test.ts +4 -4
  67. package/tests/cases/integration/graphQlRequests/delete/deleteById.test.ts +7 -6
  68. package/tests/cases/integration/graphQlRequests/query/acl/differentRowAndFieldPredicate.test.ts +8 -8
  69. package/tests/cases/integration/graphQlRequests/query/acl/fieldRestrictedByLocale.test.ts +26 -24
  70. package/tests/cases/integration/graphQlRequests/query/acl/nestedPredicate.test.ts +11 -10
  71. package/tests/cases/integration/graphQlRequests/query/acl/predicateElimination.test.ts +7 -6
  72. package/tests/cases/integration/graphQlRequests/query/acl/relationAcl.test.ts +22 -19
  73. package/tests/cases/integration/graphQlRequests/query/acl/rowPredicateSubset.test.ts +12 -12
  74. package/tests/cases/integration/graphQlRequests/query/filter/backReferencedFilter.test.ts +5 -3
  75. package/tests/cases/integration/graphQlRequests/query/graphqlFeatures/alias.test.ts +6 -6
  76. package/tests/cases/integration/graphQlRequests/query/graphqlFeatures/fragments.test.ts +8 -8
  77. package/tests/cases/integration/graphQlRequests/query/misc/reducedHasMany.test.ts +10 -10
  78. package/tests/cases/integration/graphQlRequests/query/pagination/hasManyLimit.test.ts +53 -8
  79. package/tests/cases/integration/graphQlRequests/query/pagination/paginate.test.ts +13 -10
  80. package/tests/cases/integration/graphQlRequests/query/pagination/paginateAliased.test.ts +13 -10
  81. package/tests/cases/integration/graphQlRequests/query/relations/advanced.test.ts +34 -25
  82. package/tests/cases/integration/graphQlRequests/query/relations/manyHasManyInverse.test.ts +6 -6
  83. package/tests/cases/integration/graphQlRequests/query/relations/manyHasManyOwning.test.ts +6 -6
  84. package/tests/cases/integration/graphQlRequests/query/relations/manyHasOne.test.ts +21 -18
  85. package/tests/cases/integration/graphQlRequests/query/relations/oneHasMany.test.ts +15 -15
  86. package/tests/cases/integration/graphQlRequests/query/relations/oneHasOneInverse.test.ts +14 -12
  87. package/tests/cases/integration/graphQlRequests/query/relations/oneHasOneOwner.test.ts +14 -12
  88. package/tests/cases/integration/graphQlRequests/query/sorting/defaultOrdering.test.ts +4 -4
  89. package/tests/cases/integration/graphQlRequests/query/sorting/randomSort.test.ts +4 -4
  90. package/tests/cases/integration/graphQlRequests/query/sorting/sortedHasMany.test.ts +2 -2
  91. package/tests/cases/integration/graphQlRequests/query/view/view.test.ts +10 -10
  92. package/tests/cases/unit/mutationSqlError.test.ts +30 -0
  93. package/tests/cases/unit/pathAlias.test.ts +26 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contember/engine-content-api",
3
- "version": "2.0.9",
3
+ "version": "2.0.11",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./dist/production/index.js",
6
6
  "typings": "./dist/types/index.d.ts",
@@ -26,21 +26,21 @@
26
26
  "generate": "gql-gen --config graphql.codegen.yml"
27
27
  },
28
28
  "dependencies": {
29
- "@contember/database": "2.0.9",
30
- "@contember/dic": "2.0.9",
31
- "@contember/graphql-utils": "2.0.9",
32
- "@contember/logger": "2.0.9",
33
- "@contember/schema": "2.0.9",
34
- "@contember/schema-definition": "2.0.9",
35
- "@contember/schema-utils": "2.0.9",
29
+ "@contember/database": "2.0.11",
30
+ "@contember/dic": "2.0.11",
31
+ "@contember/graphql-utils": "2.0.11",
32
+ "@contember/logger": "2.0.11",
33
+ "@contember/schema": "2.0.11",
34
+ "@contember/schema-definition": "2.0.11",
35
+ "@contember/schema-utils": "2.0.11",
36
36
  "fast-deep-equal": "^3.1.3"
37
37
  },
38
38
  "devDependencies": {
39
- "@contember/database-tester": "2.0.9",
40
- "@contember/schema-definition": "2.0.9",
39
+ "@contember/database-tester": "2.0.11",
40
+ "@contember/schema-definition": "2.0.11",
41
41
  "@types/node": "^20.16.11",
42
42
  "graphql": "^16.9.0",
43
- "pg": "^8.12.0"
43
+ "pg": "^8.20.0"
44
44
  },
45
45
  "peerDependencies": {
46
46
  "graphql": ">= 14.6.0",
@@ -134,13 +134,23 @@ export const convertError = (
134
134
  if (e instanceof Database.TransactionAbortedError) {
135
135
  return new MutationSqlError([], e.originalMessage, [MutationResultHint.subSequentSqlError])
136
136
  }
137
- if (e instanceof Database.QueryError || e instanceof Database.CannotCommitError) {
137
+ if (e instanceof Database.CannotCommitError) {
138
138
  logger.error(e, { loc: 'convertError' })
139
139
  return new MutationSqlError([], e.originalMessage, [MutationResultHint.sqlError])
140
140
  }
141
+ if (e instanceof Database.QueryError) {
142
+ logger.error(e, { loc: 'convertError' })
143
+ const message = hasClientFacingMessage(e.code) ? e.originalMessage : 'Database query failed'
144
+ return new MutationSqlError([], message, [MutationResultHint.sqlError])
145
+ }
141
146
  throw e
142
147
  }
143
148
 
149
+ // Data (22) and integrity (23) errors and project trigger exceptions (P0001) carry messages clients act on. Other
150
+ // messages (e.g. class 42) can quote internal SQL identifiers.
151
+ const hasClientFacingMessage = (code: string | undefined): boolean =>
152
+ code !== undefined && (code.startsWith('22') || code.startsWith('23') || code === 'P0001')
153
+
144
154
  export const tryMutation = async (schema: Model.Schema, databaseMetadata: DatabaseMetadata, cb: () => Promise<MutationResultList>): Promise<MutationResultList> => {
145
155
  try {
146
156
  return await cb()
@@ -75,7 +75,7 @@ export class Mapper<ConnectionType extends Connection.ConnectionLike = Connectio
75
75
  ): Promise<SelectIndexedResultObjects> {
76
76
  const hydrator = new SelectHydrator()
77
77
  const path = this.pathFactory.create([])
78
- const indexByAlias: string = path.for(indexBy).alias
78
+ const indexByAlias: string = path.forInternal('index').for(indexBy).alias
79
79
  const qb: SelectBuilder = SelectBuilder.create()
80
80
  .select([path.alias, getColumnName(this.schema, entity, indexBy)], indexByAlias)
81
81
  const rows = await this.selectRows(hydrator, qb, entity, input, relationPath)
@@ -1,5 +1,8 @@
1
1
  const MAX_IDENTIFIER_LENGTH = 63
2
2
 
3
+ const utf8Encoder = new TextEncoder()
4
+ const byteLength = (value: string): number => utf8Encoder.encode(value).length
5
+
3
6
  export class AliasContext {
4
7
  private aliasIndex = new Map<string, number>()
5
8
 
@@ -49,14 +52,31 @@ export class Path {
49
52
  return new Path([...this.path, path], this.aliasContext, this.rootAlias)
50
53
  }
51
54
 
55
+ // Segment for a column the engine selects for itself. `$` cannot occur in a GraphQL alias, so these aliases stay
56
+ // distinct from those of selected fields; `kind` must not contain `_`.
57
+ public forInternal(kind: string) {
58
+ return this.for('$' + kind)
59
+ }
60
+
61
+ // PostgreSQL limits identifiers in bytes. Untruncated aliases stay below the limit and truncated ones fill it
62
+ // exactly (padded when a multi-byte character does not fit), so the two can never coincide.
52
63
  private createAlias(): string {
53
64
  const alias = this.fullAlias
54
-
55
- // intentionally not allowing == MAX_IDENTIFIER_LENGTH
56
- if (alias.length < MAX_IDENTIFIER_LENGTH) {
65
+ if (byteLength(alias) < MAX_IDENTIFIER_LENGTH) {
57
66
  return alias
58
67
  }
59
- const index = this.aliasContext.getAliasIndex(alias).toString()
60
- return alias.substring(0, MAX_IDENTIFIER_LENGTH - index.length - 1) + '_' + index
68
+ const suffix = '_' + this.aliasContext.getAliasIndex(alias).toString()
69
+ const prefixBytes = MAX_IDENTIFIER_LENGTH - suffix.length
70
+ let prefix = ''
71
+ let usedBytes = 0
72
+ for (const char of alias) {
73
+ const charBytes = byteLength(char)
74
+ if (usedBytes + charBytes > prefixBytes) {
75
+ break
76
+ }
77
+ prefix += char
78
+ usedBytes += charBytes
79
+ }
80
+ return prefix + '_'.repeat(prefixBytes - usedBytes) + suffix
61
81
  }
62
82
  }
@@ -163,9 +163,7 @@ export class RelationFetcher {
163
163
 
164
164
  const primaryField = new FieldNode(targetEntity.primary, targetEntity.primary, {})
165
165
  const inverseJoiningColumn = joiningColumns.targetColumn.columnName
166
- const inverseIds = junctionValues
167
- .map(it => it[inverseJoiningColumn])
168
- .filter((it, index, arr) => arr.indexOf(it) === index)
166
+ const inverseIds = [...new Set(junctionValues.map(it => it[inverseJoiningColumn]))]
169
167
 
170
168
  const queryWithWhere = objectNode
171
169
  .withArgs({
@@ -91,7 +91,7 @@ export class SelectBuilder {
91
91
  if (typeof predicate === 'boolean') {
92
92
  return () => predicate
93
93
  }
94
- const predicatePath = path.for('__predicate').for(predicate)
94
+ const predicatePath = path.forInternal('predicate').for(predicate)
95
95
 
96
96
  if (!fetchedPredicates.has(predicate)) {
97
97
  const relationContext = this.relationPath[this.relationPath.length - 1]
@@ -143,8 +143,8 @@ export class SelectBuilder {
143
143
  }
144
144
  const predicateGetter = predicate !== undefined && predicate !== true ? addPredicate(predicate) : null
145
145
  const columnName = getColumnName(this.schema, entity, field)
146
- const parentValuePath = path.for(field)
147
- let ids = await this.getColumnValues(parentValuePath, columnName, predicateGetter)
146
+ const parentValuePath = path.forInternal('key').for(field)
147
+ let ids = await this.getColumnValues(path, parentValuePath, columnName, predicateGetter)
148
148
 
149
149
  const data = ids.length > 0 ? dataProvider(ids) : Promise.resolve({})
150
150
  this.hydrator.addPromise(
@@ -198,8 +198,13 @@ export class SelectBuilder {
198
198
  }
199
199
  }
200
200
 
201
- private async getColumnValues(columnPath: Path, columnName: string, predicateGetter: null | ColumnValueGetter<boolean>): Promise<Input.PrimaryValue[]> {
202
- this.qb = this.qb.select([columnPath.back().alias, columnName], columnPath.alias)
201
+ private async getColumnValues(
202
+ tablePath: Path,
203
+ columnPath: Path,
204
+ columnName: string,
205
+ predicateGetter: null | ColumnValueGetter<boolean>,
206
+ ): Promise<Input.PrimaryValue[]> {
207
+ this.qb = this.qb.select([tablePath.alias, columnName], columnPath.alias)
203
208
  const rows = await this.rows
204
209
  const filteredRows = predicateGetter === null ? rows : rows.filter(predicateGetter)
205
210
  const columnAlias = columnPath.alias
@@ -48,23 +48,23 @@ test('Filter by has many with additional join', async () => {
48
48
  executes: [
49
49
  {
50
50
  sql: SQL`
51
- select "root_"."id" as "root_id", "root_"."short_name" as "root_shortName", "root_"."id" as "root_id"
51
+ select "root_"."id" as "root_id", "root_"."short_name" as "root_shortName", "root_"."id" as "root_$key_id"
52
52
  from "public"."person" as "root_"
53
53
  where exists (select 1
54
54
  from "public"."person_locale" as "root_locales"
55
55
  left join "public"."language" as "root_locales_locale" on "root_locales"."locale_id" = "root_locales_locale"."id"
56
56
  where "root_"."id" = "root_locales"."person_id" and "root_locales_locale"."slug" = ? and not("root_locales"."url_slug" is null))`,
57
- response: { rows: [{ root_id: testUuid(1), root_shortName: 'John' }] },
57
+ response: { rows: [{ 'root_id': testUuid(1), 'root_$key_id': testUuid(1), 'root_shortName': 'John' }] },
58
58
  parameters: ['cs'],
59
59
  },
60
60
  {
61
- sql: SQL`select "root_"."person_id" as "root_person", "root_"."url_slug" as "root_urlSlug", "root_"."id" as "root_id"
61
+ sql: SQL`select "root_"."person_id" as "root_$index_person", "root_"."url_slug" as "root_urlSlug", "root_"."id" as "root_id"
62
62
  from "public"."person_locale" as "root_"
63
63
  left join "public"."language" as "root_locale" on "root_"."locale_id" = "root_locale"."id"
64
64
  where "root_locale"."slug" = ? and "root_"."person_id" in (?)`,
65
65
  parameters: ['cs', testUuid(1)],
66
66
  response: {
67
- rows: [{ root_person: testUuid(1), root_urlSlug: 'john', root_id: testUuid(2) }],
67
+ rows: [{ 'root_$index_person': testUuid(1), 'root_urlSlug': 'john', 'root_id': testUuid(2) }],
68
68
  },
69
69
  },
70
70
  ],
@@ -27,22 +27,22 @@ test('delete post by id', async () => {
27
27
  {
28
28
  sql: SQL`select
29
29
  "root_"."id" as "root_id",
30
- "root_"."author_id" as "root_author"
30
+ "root_"."author_id" as "root_$key_author"
31
31
  from "public"."post" as "root_"
32
32
  where "root_"."id" = ?`,
33
33
  parameters: [testUuid(1)],
34
34
  response: {
35
35
  rows: [
36
36
  {
37
- root_id: testUuid(1),
38
- root_author: testUuid(2),
37
+ 'root_id': testUuid(1),
38
+ 'root_$key_author': testUuid(2),
39
39
  },
40
40
  ],
41
41
  },
42
42
  },
43
43
  {
44
44
  sql: SQL`select
45
- "root_"."id" as "root_id",
45
+ "root_"."id" as "root_$index_id",
46
46
  "root_"."name" as "root_name",
47
47
  "root_"."id" as "root_id"
48
48
  from "public"."author" as "root_"
@@ -51,8 +51,9 @@ test('delete post by id', async () => {
51
51
  response: {
52
52
  rows: [
53
53
  {
54
- root_id: testUuid(2),
55
- root_name: 'John',
54
+ 'root_id': testUuid(2),
55
+ 'root_$index_id': testUuid(2),
56
+ 'root_name': 'John',
56
57
  },
57
58
  ],
58
59
  },
@@ -43,7 +43,7 @@ test('different predicate on row and field level', async () => {
43
43
  sql: SQL`
44
44
  select
45
45
  "root_"."id" as "root_id",
46
- "root_"."username" = ? as "root___predicate_authorPredicate",
46
+ "root_"."username" = ? as "root_$predicate_authorPredicate",
47
47
  "root_"."username" as "root_username"
48
48
  from "public"."author" as "root_" where not("root_"."username" is null)
49
49
  `,
@@ -51,9 +51,9 @@ test('different predicate on row and field level', async () => {
51
51
  response: {
52
52
  rows: [
53
53
  {
54
- root_id: testUuid(1),
55
- root___predicate_authorPredicate: true,
56
- root_username: 'johndoe',
54
+ 'root_id': testUuid(1),
55
+ 'root_$predicate_authorPredicate': true,
56
+ 'root_username': 'johndoe',
57
57
  },
58
58
  ],
59
59
  },
@@ -91,7 +91,7 @@ test('different predicate on row and field level - false', async () => {
91
91
  sql: SQL`
92
92
  select
93
93
  "root_"."id" as "root_id",
94
- "root_"."username" = ? as "root___predicate_authorPredicate",
94
+ "root_"."username" = ? as "root_$predicate_authorPredicate",
95
95
  "root_"."username" as "root_username"
96
96
  from "public"."author" as "root_" where not("root_"."username" is null)
97
97
  `,
@@ -99,9 +99,9 @@ test('different predicate on row and field level - false', async () => {
99
99
  response: {
100
100
  rows: [
101
101
  {
102
- root_id: testUuid(1),
103
- root___predicate_authorPredicate: false,
104
- root_username: 'johndoe',
102
+ 'root_id': testUuid(1),
103
+ 'root_$predicate_authorPredicate': false,
104
+ 'root_username': 'johndoe',
105
105
  },
106
106
  ],
107
107
  },
@@ -65,21 +65,21 @@ test('querying id and title', async () => {
65
65
  {
66
66
  sql: SQL`SELECT
67
67
  "root_"."id" AS "root_id",
68
- "root_"."locale" IN (?) AS "root___predicate_localePredicate",
68
+ "root_"."locale" IN (?) as "root_$predicate_localePredicate",
69
69
  "root_"."title" AS "root_title"
70
70
  FROM "public"."post_locale" AS "root_"`,
71
71
  parameters: ['cs'],
72
72
  response: {
73
73
  rows: [
74
74
  {
75
- root_id: testUuid(1),
76
- root_title: null,
77
- root___predicate_localePredicate: false,
75
+ 'root_id': testUuid(1),
76
+ 'root_title': null,
77
+ 'root_$predicate_localePredicate': false,
78
78
  },
79
79
  {
80
- root_id: testUuid(2),
81
- root_title: 'bar',
82
- root___predicate_localePredicate: true,
80
+ 'root_id': testUuid(2),
81
+ 'root_title': 'bar',
82
+ 'root_$predicate_localePredicate': true,
83
83
  },
84
84
  ],
85
85
  },
@@ -132,7 +132,7 @@ test('querying with extra where', async () => {
132
132
  {
133
133
  sql: SQL`select
134
134
  "root_"."id" as "root_id",
135
- "root_"."locale" in (?) as "root___predicate_localePredicate",
135
+ "root_"."locale" in (?) as "root_$predicate_localePredicate",
136
136
  "root_"."title" as "root_title"
137
137
  from "public"."post_locale" as "root_"
138
138
  where "root_"."title" = ? and "root_"."locale" in (?)`,
@@ -140,9 +140,9 @@ test('querying with extra where', async () => {
140
140
  response: {
141
141
  rows: [
142
142
  {
143
- root_id: testUuid(1),
144
- root_title: 'foo',
145
- root___predicate_localePredicate: true,
143
+ 'root_id': testUuid(1),
144
+ 'root_title': 'foo',
145
+ 'root_$predicate_localePredicate': true,
146
146
  },
147
147
  ],
148
148
  },
@@ -217,7 +217,7 @@ test('not defined acl variable', async () => {
217
217
  {
218
218
  sql: SQL`
219
219
  select "root_"."id" as "root_id",
220
- false as "root___predicate_localePredicate",
220
+ false as "root_$predicate_localePredicate",
221
221
  "root_"."title" as "root_title"
222
222
  from "public"."post_locale" as "root_"`,
223
223
  parameters: [],
@@ -253,17 +253,19 @@ test('querying on nested field', async () => {
253
253
  executes: [
254
254
  {
255
255
  sql: SQL`select
256
- "root_"."id" as "root_id",
256
+ "root_"."id" as "root_$key_id",
257
257
  "root_"."id" as "root_id"
258
258
  from "public"."post" as "root_"`,
259
259
  parameters: [],
260
260
  response: {
261
261
  rows: [
262
262
  {
263
- root_id: testUuid(1),
263
+ 'root_id': testUuid(1),
264
+ 'root_$key_id': testUuid(1),
264
265
  },
265
266
  {
266
- root_id: testUuid(2),
267
+ 'root_id': testUuid(2),
268
+ 'root_$key_id': testUuid(2),
267
269
  },
268
270
  ],
269
271
  },
@@ -272,23 +274,23 @@ test('querying on nested field', async () => {
272
274
  sql: SQL`
273
275
  select "root_"."post_id" as "__grouping_key",
274
276
  "root_"."id" as "root_id",
275
- "root_"."locale" in (?) as "root___predicate_localePredicate",
277
+ "root_"."locale" in (?) as "root_$predicate_localePredicate",
276
278
  "root_"."title" as "root_title"
277
279
  from "public"."post_locale" as "root_" where "root_"."post_id" in (?, ?)`,
278
280
  parameters: ['cs', testUuid(1), testUuid(2)],
279
281
  response: {
280
282
  rows: [
281
283
  {
282
- __grouping_key: testUuid(1),
283
- root_id: testUuid(3),
284
- root___predicate_localePredicate: false,
285
- root_title: 'foo',
284
+ '__grouping_key': testUuid(1),
285
+ 'root_id': testUuid(3),
286
+ 'root_$predicate_localePredicate': false,
287
+ 'root_title': 'foo',
286
288
  },
287
289
  {
288
- __grouping_key: testUuid(2),
289
- root_id: testUuid(4),
290
- root___predicate_localePredicate: true,
291
- root_title: 'bar',
290
+ '__grouping_key': testUuid(2),
291
+ 'root_id': testUuid(4),
292
+ 'root_$predicate_localePredicate': true,
293
+ 'root_title': 'bar',
292
294
  },
293
295
  ],
294
296
  },
@@ -73,26 +73,26 @@ test('querying post + author name', async () => {
73
73
  {
74
74
  sql: SQL`select
75
75
  "root_"."id" as "root_id",
76
- "root_"."author_id" as "root_author"
76
+ "root_"."author_id" as "root_$key_author"
77
77
  from "public"."post" as "root_"`,
78
78
  parameters: [],
79
79
  response: {
80
80
  rows: [
81
81
  {
82
- root_id: testUuid(1),
83
- root_author: testUuid(3),
82
+ 'root_id': testUuid(1),
83
+ 'root_$key_author': testUuid(3),
84
84
  },
85
85
  {
86
- root_id: testUuid(2),
87
- root_author: testUuid(4),
86
+ 'root_id': testUuid(2),
87
+ 'root_$key_author': testUuid(4),
88
88
  },
89
89
  ],
90
90
  },
91
91
  },
92
92
  {
93
93
  sql: SQL`SELECT
94
- "root_"."id" AS "root_id",
95
- "root_country"."name" IN (?) AS "root___predicate_countryPredicate",
94
+ "root_"."id" as "root_$index_id",
95
+ "root_country"."name" IN (?) as "root_$predicate_countryPredicate",
96
96
  "root_"."name" AS "root_name",
97
97
  "root_"."id" AS "root_id"
98
98
  FROM "public"."author" AS "root_"
@@ -102,9 +102,10 @@ test('querying post + author name', async () => {
102
102
  response: {
103
103
  rows: [
104
104
  {
105
- root_id: testUuid(3),
106
- root___predicate_countryPredicate: true,
107
- root_name: 'John',
105
+ 'root_id': testUuid(3),
106
+ 'root_$index_id': testUuid(3),
107
+ 'root_$predicate_countryPredicate': true,
108
+ 'root_name': 'John',
108
109
  },
109
110
  ],
110
111
  },
@@ -86,27 +86,28 @@ test('predicate with OR', async () => {
86
86
  }`,
87
87
  executes: [
88
88
  {
89
- sql: SQL`SELECT "root_"."id" AS "root_id", "root_"."image_id" AS "root_image"
89
+ sql: SQL`SELECT "root_"."id" AS "root_id", "root_"."image_id" as "root_$key_image"
90
90
  FROM "public"."author" AS "root_"
91
91
  WHERE "root_"."is_public" = ?`,
92
92
  parameters: [true],
93
93
  response: {
94
94
  rows: [
95
95
  {
96
- root_id: testUuid(1),
97
- root_image: testUuid(2),
96
+ 'root_id': testUuid(1),
97
+ 'root_$key_image': testUuid(2),
98
98
  },
99
99
  ],
100
100
  },
101
101
  },
102
102
  {
103
- sql: `select "root_"."id" as "root_id", "root_"."url" as "root_url", "root_"."id" as "root_id" from "public"."image" as "root_" where "root_"."id" in (?)`,
103
+ sql: `select "root_"."id" as "root_$index_id", "root_"."url" as "root_url", "root_"."id" as "root_id" from "public"."image" as "root_" where "root_"."id" in (?)`,
104
104
  parameters: [testUuid(2)],
105
105
  response: {
106
106
  rows: [
107
107
  {
108
- root_id: testUuid(2),
109
- root_url: 'abcd',
108
+ 'root_id': testUuid(2),
109
+ 'root_$index_id': testUuid(2),
110
+ 'root_url': 'abcd',
110
111
  },
111
112
  ],
112
113
  },
@@ -51,33 +51,34 @@ test('can read same entity only over relation of some rows - many has one', asyn
51
51
  }`,
52
52
  executes: [
53
53
  {
54
- sql: SQL`select "root_"."title" as "root_title", "root_"."disclose_author" = ? as "root___predicate_discloseAuthor_eq_true", "root_"."author_id" as "root_author", "root_"."id" as "root_id"
54
+ sql: SQL`select "root_"."title" as "root_title", "root_"."disclose_author" = ? as "root_$predicate_discloseAuthor_eq_true", "root_"."author_id" as "root_$key_author", "root_"."id" as "root_id"
55
55
  from "public"."article" as "root_"`,
56
56
  response: {
57
57
  rows: [
58
58
  {
59
- root_id: testUuid(1),
60
- root_title: 'Article A',
61
- root___predicate_discloseAuthor_eq_true: true,
62
- root_author: testUuid(10),
59
+ 'root_id': testUuid(1),
60
+ 'root_title': 'Article A',
61
+ 'root_$predicate_discloseAuthor_eq_true': true,
62
+ 'root_$key_author': testUuid(10),
63
63
  },
64
64
  {
65
- root_id: testUuid(2),
66
- root_title: 'Article B',
67
- root___predicate_discloseAuthor_eq_true: false,
68
- root_author: testUuid(10),
65
+ 'root_id': testUuid(2),
66
+ 'root_title': 'Article B',
67
+ 'root_$predicate_discloseAuthor_eq_true': false,
68
+ 'root_$key_author': testUuid(10),
69
69
  },
70
70
  ],
71
71
  },
72
72
  },
73
73
  {
74
- sql: SQL`select "root_"."id" as "root_id", "root_"."name" as "root_name", "root_"."id" as "root_id" from "public"."author" as "root_" where "root_"."id" in (?)`,
74
+ sql: SQL`select "root_"."id" as "root_$index_id", "root_"."name" as "root_name", "root_"."id" as "root_id" from "public"."author" as "root_" where "root_"."id" in (?)`,
75
75
  parameters: [testUuid(10)],
76
76
  response: {
77
77
  rows: [
78
78
  {
79
- root_id: testUuid(10),
80
- root_name: 'John doe',
79
+ 'root_id': testUuid(10),
80
+ 'root_$index_id': testUuid(10),
81
+ 'root_name': 'John doe',
81
82
  },
82
83
  ],
83
84
  },
@@ -149,19 +150,21 @@ test('can read same entity only over relation of some rows - many has many', asy
149
150
  }`,
150
151
  executes: [
151
152
  {
152
- sql: SQL`select "root_"."title" as "root_title", "root_"."disclose_author" = ? as "root___predicate_discloseauthor_eq_true", "root_"."id" as "root_id", "root_"."id" as "root_id"
153
+ sql: SQL`select "root_"."title" as "root_title", "root_"."disclose_author" = ? as "root_$predicate_discloseAuthor_eq_true", "root_"."id" as "root_$key_id", "root_"."id" as "root_id"
153
154
  from "public"."article" as "root_"`,
154
155
  response: {
155
156
  rows: [
156
157
  {
157
- root_id: testUuid(1),
158
- root_title: 'Article A',
159
- root___predicate_discloseAuthor_eq_true: true,
158
+ 'root_id': testUuid(1),
159
+ 'root_$key_id': testUuid(1),
160
+ 'root_title': 'Article A',
161
+ 'root_$predicate_discloseAuthor_eq_true': true,
160
162
  },
161
163
  {
162
- root_id: testUuid(2),
163
- root_title: 'Article B',
164
- root___predicate_discloseAuthor_eq_true: false,
164
+ 'root_id': testUuid(2),
165
+ 'root_$key_id': testUuid(2),
166
+ 'root_title': 'Article B',
167
+ 'root_$predicate_discloseAuthor_eq_true': false,
165
168
  },
166
169
  ],
167
170
  },
@@ -55,9 +55,9 @@ test('row level predicate includes main predicate', async () => {
55
55
  {
56
56
  sql: SQL`SELECT
57
57
  "root_"."id" AS "root_id",
58
- TRUE AS "root___predicate_isPublished_eq_true",
58
+ TRUE as "root_$predicate_isPublished_eq_true",
59
59
  "root_"."title" AS "root_title",
60
- "root_"."is_unlocked" = ? AS "root___predicate_and_isUnlocked_eq_true_isPubl",
60
+ "root_"."is_unlocked" = ? as "root_$predicate_and_isUnlocked_eq_true_isPubl",
61
61
  "root_"."content" AS "root_content"
62
62
  FROM "public"."article" AS "root_"
63
63
  WHERE "root_"."is_published" = ?`,
@@ -65,18 +65,18 @@ test('row level predicate includes main predicate', async () => {
65
65
  response: {
66
66
  rows: [
67
67
  {
68
- root_id: testUuid(1),
69
- root___predicate_isPublished_eq_true: true,
70
- root_title: 'Hello',
71
- root___predicate_and_isUnlocked_eq_true_isPubl: false,
72
- root_content: 'Foo bar',
68
+ 'root_id': testUuid(1),
69
+ 'root_$predicate_isPublished_eq_true': true,
70
+ 'root_title': 'Hello',
71
+ 'root_$predicate_and_isUnlocked_eq_true_isPubl': false,
72
+ 'root_content': 'Foo bar',
73
73
  },
74
74
  {
75
- root_id: testUuid(2),
76
- root___predicate_isPublished_eq_true: true,
77
- root_title: 'Hello 2',
78
- root___predicate_and_isUnlocked_eq_true_isPubl: true,
79
- root_content: 'Lorem ipsum',
75
+ 'root_id': testUuid(2),
76
+ 'root_$predicate_isPublished_eq_true': true,
77
+ 'root_title': 'Hello 2',
78
+ 'root_$predicate_and_isUnlocked_eq_true_isPubl': true,
79
+ 'root_content': 'Lorem ipsum',
80
80
  },
81
81
  ],
82
82
  },
@@ -24,15 +24,17 @@ test('Categories with children filtered by back-referenced parent', async () =>
24
24
  {
25
25
  sql: SQL`select
26
26
  "root_"."id" as "root_id",
27
- "root_"."id" as "root_id"
27
+ "root_"."id" as "root_$key_id"
28
28
  from "public"."category" as "root_"`,
29
29
  response: {
30
30
  rows: [
31
31
  {
32
- root_id: testUuid(1),
32
+ 'root_id': testUuid(1),
33
+ 'root_$key_id': testUuid(1),
33
34
  },
34
35
  {
35
- root_id: testUuid(2),
36
+ 'root_id': testUuid(2),
37
+ 'root_$key_id': testUuid(2),
36
38
  },
37
39
  ],
38
40
  },
@@ -81,18 +81,18 @@ test('aliases', async () => {
81
81
  "root_"."id" AS "root_idx",
82
82
  "root_"."name" AS "root_name1",
83
83
  "root_"."name" AS "root_name2",
84
- "root_"."name" = ? AS "root___predicate_name_eq",
84
+ "root_"."name" = ? as "root_$predicate_name_eq",
85
85
  "root_"."id" AS "root_id"
86
86
  FROM "public"."author" AS "root_"`,
87
87
  parameters: ['John'],
88
88
  response: {
89
89
  rows: [
90
90
  {
91
- root_id: testUuid(1),
92
- root_idx: testUuid(1),
93
- root_name1: 'John',
94
- root_name2: 'John',
95
- root___predicate_name_eq: true,
91
+ 'root_id': testUuid(1),
92
+ 'root_idx': testUuid(1),
93
+ 'root_name1': 'John',
94
+ 'root_name2': 'John',
95
+ 'root_$predicate_name_eq': true,
96
96
  },
97
97
  ],
98
98
  },