@contember/engine-content-api 2.1.0-rc.6 → 2.1.0-rc.7

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 (112) hide show
  1. package/CLAUDE.md +2 -0
  2. package/dist/development/src/mapper/ErrorUtils.cjs +7 -1
  3. package/dist/development/src/mapper/ErrorUtils.cjs.map +1 -1
  4. package/dist/development/src/mapper/ErrorUtils.js +7 -1
  5. package/dist/development/src/mapper/ErrorUtils.js.map +1 -1
  6. package/dist/development/src/mapper/Mapper.cjs +2 -1
  7. package/dist/development/src/mapper/Mapper.cjs.map +1 -1
  8. package/dist/development/src/mapper/Mapper.js +2 -1
  9. package/dist/development/src/mapper/Mapper.js.map +1 -1
  10. package/dist/development/src/mapper/select/Path.cjs +23 -3
  11. package/dist/development/src/mapper/select/Path.cjs.map +1 -1
  12. package/dist/development/src/mapper/select/Path.js +23 -3
  13. package/dist/development/src/mapper/select/Path.js.map +1 -1
  14. package/dist/development/src/mapper/select/SelectBuilder.cjs +13 -10
  15. package/dist/development/src/mapper/select/SelectBuilder.cjs.map +1 -1
  16. package/dist/development/src/mapper/select/SelectBuilder.js +13 -10
  17. package/dist/development/src/mapper/select/SelectBuilder.js.map +1 -1
  18. package/dist/development/src/mapper/select/handlers/FieldsVisitor.cjs +1 -1
  19. package/dist/development/src/mapper/select/handlers/FieldsVisitor.cjs.map +1 -1
  20. package/dist/development/src/mapper/select/handlers/FieldsVisitor.js +1 -1
  21. package/dist/development/src/mapper/select/handlers/FieldsVisitor.js.map +1 -1
  22. package/dist/development/src/mapper/select/handlers/MetaHandler.cjs +4 -3
  23. package/dist/development/src/mapper/select/handlers/MetaHandler.cjs.map +1 -1
  24. package/dist/development/src/mapper/select/handlers/MetaHandler.js +4 -3
  25. package/dist/development/src/mapper/select/handlers/MetaHandler.js.map +1 -1
  26. package/dist/development/src/resolvers/MutationResolver.cjs +1 -0
  27. package/dist/development/src/resolvers/MutationResolver.cjs.map +1 -1
  28. package/dist/development/src/resolvers/MutationResolver.js +1 -0
  29. package/dist/development/src/resolvers/MutationResolver.js.map +1 -1
  30. package/dist/production/src/mapper/ErrorUtils.cjs +7 -1
  31. package/dist/production/src/mapper/ErrorUtils.cjs.map +1 -1
  32. package/dist/production/src/mapper/ErrorUtils.js +7 -1
  33. package/dist/production/src/mapper/ErrorUtils.js.map +1 -1
  34. package/dist/production/src/mapper/Mapper.cjs +2 -1
  35. package/dist/production/src/mapper/Mapper.cjs.map +1 -1
  36. package/dist/production/src/mapper/Mapper.js +2 -1
  37. package/dist/production/src/mapper/Mapper.js.map +1 -1
  38. package/dist/production/src/mapper/select/Path.cjs +23 -3
  39. package/dist/production/src/mapper/select/Path.cjs.map +1 -1
  40. package/dist/production/src/mapper/select/Path.js +23 -3
  41. package/dist/production/src/mapper/select/Path.js.map +1 -1
  42. package/dist/production/src/mapper/select/SelectBuilder.cjs +13 -10
  43. package/dist/production/src/mapper/select/SelectBuilder.cjs.map +1 -1
  44. package/dist/production/src/mapper/select/SelectBuilder.js +13 -10
  45. package/dist/production/src/mapper/select/SelectBuilder.js.map +1 -1
  46. package/dist/production/src/mapper/select/handlers/FieldsVisitor.cjs +1 -1
  47. package/dist/production/src/mapper/select/handlers/FieldsVisitor.cjs.map +1 -1
  48. package/dist/production/src/mapper/select/handlers/FieldsVisitor.js +1 -1
  49. package/dist/production/src/mapper/select/handlers/FieldsVisitor.js.map +1 -1
  50. package/dist/production/src/mapper/select/handlers/MetaHandler.cjs +4 -3
  51. package/dist/production/src/mapper/select/handlers/MetaHandler.cjs.map +1 -1
  52. package/dist/production/src/mapper/select/handlers/MetaHandler.js +4 -3
  53. package/dist/production/src/mapper/select/handlers/MetaHandler.js.map +1 -1
  54. package/dist/production/src/resolvers/MutationResolver.cjs +1 -0
  55. package/dist/production/src/resolvers/MutationResolver.cjs.map +1 -1
  56. package/dist/production/src/resolvers/MutationResolver.js +1 -0
  57. package/dist/production/src/resolvers/MutationResolver.js.map +1 -1
  58. package/dist/tests/cases/integration/graphQlRequests/query/acl/nestedThroughPredicate.test.d.ts +2 -0
  59. package/dist/tests/cases/integration/graphQlRequests/query/acl/nestedThroughPredicate.test.d.ts.map +1 -0
  60. package/dist/tests/cases/unit/mutationSqlError.test.d.ts +2 -0
  61. package/dist/tests/cases/unit/mutationSqlError.test.d.ts.map +1 -0
  62. package/dist/tests/cases/unit/pathAlias.test.d.ts +2 -0
  63. package/dist/tests/cases/unit/pathAlias.test.d.ts.map +1 -0
  64. package/dist/tests/src/test.d.ts +1 -0
  65. package/dist/tests/src/test.d.ts.map +1 -1
  66. package/dist/tests/tsconfig.tsbuildinfo +1 -1
  67. package/dist/types/mapper/ErrorUtils.d.ts.map +1 -1
  68. package/dist/types/mapper/select/Path.d.ts +1 -0
  69. package/dist/types/mapper/select/Path.d.ts.map +1 -1
  70. package/dist/types/mapper/select/SelectBuilder.d.ts.map +1 -1
  71. package/dist/types/mapper/select/SelectExecutionHandler.d.ts +11 -1
  72. package/dist/types/mapper/select/SelectExecutionHandler.d.ts.map +1 -1
  73. package/dist/types/mapper/select/handlers/MetaHandler.d.ts.map +1 -1
  74. package/dist/types/tsconfig.tsbuildinfo +1 -1
  75. package/package.json +9 -9
  76. package/src/mapper/ErrorUtils.ts +11 -1
  77. package/src/mapper/Mapper.ts +1 -1
  78. package/src/mapper/select/Path.ts +25 -5
  79. package/src/mapper/select/SelectBuilder.ts +22 -11
  80. package/src/mapper/select/SelectExecutionHandler.ts +9 -1
  81. package/src/mapper/select/handlers/FieldsVisitor.ts +1 -1
  82. package/src/mapper/select/handlers/MetaHandler.ts +8 -3
  83. package/tests/cases/bugs/bug102.test.ts +4 -4
  84. package/tests/cases/integration/graphQlRequests/delete/deleteById.test.ts +4 -3
  85. package/tests/cases/integration/graphQlRequests/query/acl/differentRowAndFieldPredicate.test.ts +4 -4
  86. package/tests/cases/integration/graphQlRequests/query/acl/fieldRestrictedByLocale.test.ts +12 -10
  87. package/tests/cases/integration/graphQlRequests/query/acl/nestedPredicate.test.ts +7 -6
  88. package/tests/cases/integration/graphQlRequests/query/acl/nestedThroughPredicate.test.ts +345 -0
  89. package/tests/cases/integration/graphQlRequests/query/acl/predicateElimination.test.ts +25 -23
  90. package/tests/cases/integration/graphQlRequests/query/acl/relationAcl.test.ts +12 -9
  91. package/tests/cases/integration/graphQlRequests/query/acl/rowPredicateSubset.test.ts +6 -6
  92. package/tests/cases/integration/graphQlRequests/query/filter/backReferencedFilter.test.ts +3 -1
  93. package/tests/cases/integration/graphQlRequests/query/graphqlFeatures/alias.test.ts +2 -2
  94. package/tests/cases/integration/graphQlRequests/query/graphqlFeatures/fragments.test.ts +8 -8
  95. package/tests/cases/integration/graphQlRequests/query/misc/reducedHasMany.test.ts +10 -10
  96. package/tests/cases/integration/graphQlRequests/query/pagination/hasManyLimit.test.ts +8 -8
  97. package/tests/cases/integration/graphQlRequests/query/pagination/paginate.test.ts +5 -4
  98. package/tests/cases/integration/graphQlRequests/query/pagination/paginateAliased.test.ts +5 -4
  99. package/tests/cases/integration/graphQlRequests/query/relations/advanced.test.ts +17 -8
  100. package/tests/cases/integration/graphQlRequests/query/relations/manyHasManyInverse.test.ts +6 -6
  101. package/tests/cases/integration/graphQlRequests/query/relations/manyHasManyOwning.test.ts +6 -6
  102. package/tests/cases/integration/graphQlRequests/query/relations/manyHasOne.test.ts +12 -9
  103. package/tests/cases/integration/graphQlRequests/query/relations/oneHasMany.test.ts +12 -12
  104. package/tests/cases/integration/graphQlRequests/query/relations/oneHasOneInverse.test.ts +6 -4
  105. package/tests/cases/integration/graphQlRequests/query/relations/oneHasOneOwner.test.ts +6 -4
  106. package/tests/cases/integration/graphQlRequests/query/sorting/defaultOrdering.test.ts +4 -4
  107. package/tests/cases/integration/graphQlRequests/query/sorting/randomSort.test.ts +5 -5
  108. package/tests/cases/integration/graphQlRequests/query/sorting/sortedHasMany.test.ts +2 -2
  109. package/tests/cases/integration/graphQlRequests/query/view/view.test.ts +6 -6
  110. package/tests/cases/unit/mutationSqlError.test.ts +30 -0
  111. package/tests/cases/unit/pathAlias.test.ts +26 -0
  112. package/tests/src/test.ts +5 -1
@@ -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'
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
+ })
package/tests/src/test.ts CHANGED
@@ -17,6 +17,7 @@ export interface Test {
17
17
  settings?: Settings.Schema
18
18
  validation?: Validation.Schema
19
19
  permissions?: Acl.Permissions
20
+ allPermissions?: Acl.Permissions
20
21
  variables?: Acl.VariablesMap
21
22
  query: string
22
23
  queryVariables?: Record<string, any>
@@ -76,7 +77,9 @@ export const failedTransaction = (executes: SqlQuery[]): SqlQuery[] => {
76
77
 
77
78
  export const execute = async (test: Test) => {
78
79
  const permissions: Acl.Permissions = test.permissions || new AllowAllPermissionFactory().create(test.schema)
79
- const authorizator = new Authorizator(permissions, false, false)
80
+ // Mirror production (GraphQlSchemaFactory): the GraphQL schema is built from the through-inclusive `all` set,
81
+ // so fields granted only through a relation are still exposed.
82
+ const authorizator = new Authorizator(test.allPermissions ?? permissions, false, false)
80
83
  const builder = new GraphQlSchemaBuilderFactory().create(test.schema, authorizator)
81
84
  const graphQLSchema = builder.build()
82
85
 
@@ -103,6 +106,7 @@ export const execute = async (test: Test) => {
103
106
  executionContainer: executionContainerFactory
104
107
  .create({
105
108
  permissions,
109
+ allPermissions: test.allPermissions,
106
110
  schema,
107
111
  schemaMeta: {
108
112
  id: 1,