@contember/engine-content-api 2.0.10 → 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 (83) 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/unit/mutationSqlError.test.d.ts +2 -0
  42. package/dist/tests/cases/unit/mutationSqlError.test.d.ts.map +1 -0
  43. package/dist/tests/cases/unit/pathAlias.test.d.ts +2 -0
  44. package/dist/tests/cases/unit/pathAlias.test.d.ts.map +1 -0
  45. package/dist/tests/tsconfig.tsbuildinfo +1 -1
  46. package/dist/types/mapper/ErrorUtils.d.ts.map +1 -1
  47. package/dist/types/mapper/select/Path.d.ts +1 -0
  48. package/dist/types/mapper/select/Path.d.ts.map +1 -1
  49. package/dist/types/mapper/select/SelectBuilder.d.ts.map +1 -1
  50. package/dist/types/tsconfig.tsbuildinfo +1 -1
  51. package/package.json +10 -10
  52. package/src/mapper/ErrorUtils.ts +11 -1
  53. package/src/mapper/Mapper.ts +1 -1
  54. package/src/mapper/select/Path.ts +25 -5
  55. package/src/mapper/select/SelectBuilder.ts +10 -5
  56. package/tests/cases/bugs/bug102.test.ts +4 -4
  57. package/tests/cases/integration/graphQlRequests/delete/deleteById.test.ts +7 -6
  58. package/tests/cases/integration/graphQlRequests/query/acl/differentRowAndFieldPredicate.test.ts +8 -8
  59. package/tests/cases/integration/graphQlRequests/query/acl/fieldRestrictedByLocale.test.ts +26 -24
  60. package/tests/cases/integration/graphQlRequests/query/acl/nestedPredicate.test.ts +11 -10
  61. package/tests/cases/integration/graphQlRequests/query/acl/predicateElimination.test.ts +7 -6
  62. package/tests/cases/integration/graphQlRequests/query/acl/relationAcl.test.ts +22 -19
  63. package/tests/cases/integration/graphQlRequests/query/acl/rowPredicateSubset.test.ts +12 -12
  64. package/tests/cases/integration/graphQlRequests/query/filter/backReferencedFilter.test.ts +5 -3
  65. package/tests/cases/integration/graphQlRequests/query/graphqlFeatures/alias.test.ts +6 -6
  66. package/tests/cases/integration/graphQlRequests/query/graphqlFeatures/fragments.test.ts +8 -8
  67. package/tests/cases/integration/graphQlRequests/query/misc/reducedHasMany.test.ts +10 -10
  68. package/tests/cases/integration/graphQlRequests/query/pagination/hasManyLimit.test.ts +8 -8
  69. package/tests/cases/integration/graphQlRequests/query/pagination/paginate.test.ts +13 -10
  70. package/tests/cases/integration/graphQlRequests/query/pagination/paginateAliased.test.ts +13 -10
  71. package/tests/cases/integration/graphQlRequests/query/relations/advanced.test.ts +34 -25
  72. package/tests/cases/integration/graphQlRequests/query/relations/manyHasManyInverse.test.ts +6 -6
  73. package/tests/cases/integration/graphQlRequests/query/relations/manyHasManyOwning.test.ts +6 -6
  74. package/tests/cases/integration/graphQlRequests/query/relations/manyHasOne.test.ts +21 -18
  75. package/tests/cases/integration/graphQlRequests/query/relations/oneHasMany.test.ts +12 -12
  76. package/tests/cases/integration/graphQlRequests/query/relations/oneHasOneInverse.test.ts +14 -12
  77. package/tests/cases/integration/graphQlRequests/query/relations/oneHasOneOwner.test.ts +14 -12
  78. package/tests/cases/integration/graphQlRequests/query/sorting/defaultOrdering.test.ts +4 -4
  79. package/tests/cases/integration/graphQlRequests/query/sorting/randomSort.test.ts +3 -3
  80. package/tests/cases/integration/graphQlRequests/query/sorting/sortedHasMany.test.ts +2 -2
  81. package/tests/cases/integration/graphQlRequests/query/view/view.test.ts +10 -10
  82. package/tests/cases/unit/mutationSqlError.test.ts +30 -0
  83. package/tests/cases/unit/pathAlias.test.ts +26 -0
@@ -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
+ })