@contember/engine-content-api 2.0.11 → 2.0.13

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contember/engine-content-api",
3
- "version": "2.0.11",
3
+ "version": "2.0.13",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./dist/production/index.js",
6
6
  "typings": "./dist/types/index.d.ts",
@@ -26,18 +26,18 @@
26
26
  "generate": "gql-gen --config graphql.codegen.yml"
27
27
  },
28
28
  "dependencies": {
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",
29
+ "@contember/database": "2.0.13",
30
+ "@contember/dic": "2.0.13",
31
+ "@contember/graphql-utils": "2.0.13",
32
+ "@contember/logger": "2.0.13",
33
+ "@contember/schema": "2.0.13",
34
+ "@contember/schema-definition": "2.0.13",
35
+ "@contember/schema-utils": "2.0.13",
36
36
  "fast-deep-equal": "^3.1.3"
37
37
  },
38
38
  "devDependencies": {
39
- "@contember/database-tester": "2.0.11",
40
- "@contember/schema-definition": "2.0.11",
39
+ "@contember/database-tester": "2.0.13",
40
+ "@contember/schema-definition": "2.0.13",
41
41
  "@types/node": "^20.16.11",
42
42
  "graphql": "^16.9.0",
43
43
  "pg": "^8.20.0"
@@ -0,0 +1,278 @@
1
+ import { SchemaBuilder } from '@contember/schema-definition'
2
+ import { Acl, Model } from '@contember/schema'
3
+ import { test } from 'bun:test'
4
+ import { execute } from '../../../../../src/test'
5
+ import { GQL, SQL } from '../../../../../src/tags'
6
+ import { testUuid } from '../../../../../src/testUuid'
7
+
8
+ // A client chooses GraphQL aliases freely, and they become SQL column aliases. Engine-owned columns (ACL predicate
9
+ // results, relation keys) must stay in a namespace no alias can reach, otherwise the client's column is read instead.
10
+
11
+ const schema = new SchemaBuilder()
12
+ .entity('Author', entity =>
13
+ entity
14
+ .column('name', column => column.type(Model.ColumnType.String))
15
+ .column('verified', column => column.type(Model.ColumnType.Bool)))
16
+ .entity('Post', entity =>
17
+ entity
18
+ .column('externalId', column => column.type(Model.ColumnType.Uuid))
19
+ .manyHasOne('author', relation => relation.target('Author')))
20
+ .buildSchema()
21
+
22
+ const longPredicateName = 'nameVisible' + 'Long'.repeat(13)
23
+
24
+ const permissions: Acl.Permissions = {
25
+ Author: {
26
+ predicates: {
27
+ nameVisible: { verified: { eq: true } },
28
+ [longPredicateName]: { verified: { eq: true } },
29
+ },
30
+ operations: {
31
+ read: { id: true, verified: true, name: 'nameVisible' },
32
+ update: { name: 'nameVisible' },
33
+ },
34
+ },
35
+ Post: {
36
+ predicates: {},
37
+ operations: {
38
+ read: { id: true, externalId: true, author: true },
39
+ },
40
+ },
41
+ }
42
+
43
+ test('a root alias equal to a predicate column does not unmask the field', async () => {
44
+ await execute({
45
+ schema,
46
+ permissions,
47
+ query: GQL`
48
+ query {
49
+ listAuthor {
50
+ id
51
+ name
52
+ __predicate_nameVisible: verified
53
+ }
54
+ }`,
55
+ executes: [
56
+ {
57
+ sql: SQL`
58
+ select "root_"."id" as "root_id",
59
+ "root_"."verified" = ? as "root_$predicate_nameVisible",
60
+ "root_"."name" as "root_name",
61
+ "root_"."verified" as "root___predicate_nameVisible"
62
+ from "public"."author" as "root_"`,
63
+ parameters: [true],
64
+ response: {
65
+ rows: [
66
+ {
67
+ 'root_id': testUuid(1),
68
+ 'root_$predicate_nameVisible': false,
69
+ 'root_name': 'masked',
70
+ 'root___predicate_nameVisible': true,
71
+ },
72
+ ],
73
+ },
74
+ },
75
+ ],
76
+ return: {
77
+ data: {
78
+ listAuthor: [{ id: testUuid(1), name: null, __predicate_nameVisible: true }],
79
+ },
80
+ },
81
+ })
82
+ })
83
+
84
+ test('a nested alias equal to a predicate column does not unmask the field', async () => {
85
+ await execute({
86
+ schema,
87
+ permissions,
88
+ query: GQL`
89
+ query {
90
+ listPost {
91
+ id
92
+ author {
93
+ id
94
+ name
95
+ __predicate_nameVisible: verified
96
+ }
97
+ }
98
+ }`,
99
+ executes: [
100
+ {
101
+ sql: SQL`
102
+ select "root_"."id" as "root_id",
103
+ "root_"."author_id" as "root_$key_author"
104
+ from "public"."post" as "root_"`,
105
+ parameters: [],
106
+ response: {
107
+ rows: [{ 'root_id': testUuid(1), 'root_$key_author': testUuid(2) }],
108
+ },
109
+ },
110
+ {
111
+ sql: SQL`
112
+ select "root_"."id" as "root_$index_id",
113
+ "root_"."id" as "root_id",
114
+ "root_"."verified" = ? as "root_$predicate_nameVisible",
115
+ "root_"."name" as "root_name",
116
+ "root_"."verified" as "root___predicate_nameVisible"
117
+ from "public"."author" as "root_"
118
+ where "root_"."id" in (?)`,
119
+ parameters: [true, testUuid(2)],
120
+ response: {
121
+ rows: [
122
+ {
123
+ 'root_$index_id': testUuid(2),
124
+ 'root_id': testUuid(2),
125
+ 'root_$predicate_nameVisible': false,
126
+ 'root_name': 'masked',
127
+ 'root___predicate_nameVisible': true,
128
+ },
129
+ ],
130
+ },
131
+ },
132
+ ],
133
+ return: {
134
+ data: {
135
+ listPost: [{ id: testUuid(1), author: { id: testUuid(2), name: null, __predicate_nameVisible: true } }],
136
+ },
137
+ },
138
+ })
139
+ })
140
+
141
+ test('an alias equal to a predicate column does not change _meta.updatable', async () => {
142
+ await execute({
143
+ schema,
144
+ permissions,
145
+ query: GQL`
146
+ query {
147
+ listAuthor {
148
+ id
149
+ __predicate_nameVisible: verified
150
+ _meta {
151
+ name {
152
+ updatable
153
+ }
154
+ }
155
+ }
156
+ }`,
157
+ executes: [
158
+ {
159
+ sql: SQL`
160
+ select "root_"."id" as "root_id",
161
+ "root_"."verified" as "root___predicate_nameVisible",
162
+ "root_"."verified" = ? as "root_$predicate_nameVisible"
163
+ from "public"."author" as "root_"`,
164
+ parameters: [true],
165
+ response: {
166
+ rows: [
167
+ {
168
+ 'root_id': testUuid(1),
169
+ 'root___predicate_nameVisible': true,
170
+ 'root_$predicate_nameVisible': false,
171
+ },
172
+ ],
173
+ },
174
+ },
175
+ ],
176
+ return: {
177
+ data: {
178
+ listAuthor: [{ id: testUuid(1), __predicate_nameVisible: true, _meta: { name: { updatable: false } } }],
179
+ },
180
+ },
181
+ })
182
+ })
183
+
184
+ test('aliases over the identifier length limit stay apart from predicate columns', async () => {
185
+ const longPermissions: Acl.Permissions = {
186
+ ...permissions,
187
+ Author: {
188
+ ...permissions.Author,
189
+ operations: {
190
+ read: { id: true, verified: true, name: longPredicateName },
191
+ },
192
+ },
193
+ }
194
+ await execute({
195
+ schema,
196
+ permissions: longPermissions,
197
+ query: `
198
+ query {
199
+ listAuthor {
200
+ id
201
+ name
202
+ __predicate_${longPredicateName}: verified
203
+ }
204
+ }`,
205
+ executes: [
206
+ {
207
+ sql: SQL`
208
+ select "root_"."id" as "root_id",
209
+ "root_"."verified" = ? as "root_$predicate_nameVisibleLongLongLongLongLongLongLongLongLo_1",
210
+ "root_"."name" as "root_name",
211
+ "root_"."verified" as "root___predicate_nameVisibleLongLongLongLongLongLongLongLongL_2"
212
+ from "public"."author" as "root_"`,
213
+ parameters: [true],
214
+ response: {
215
+ rows: [
216
+ {
217
+ 'root_id': testUuid(1),
218
+ 'root_$predicate_nameVisibleLongLongLongLongLongLongLongLongLo_1': false,
219
+ 'root_name': 'masked',
220
+ 'root___predicate_nameVisibleLongLongLongLongLongLongLongLongL_2': true,
221
+ },
222
+ ],
223
+ },
224
+ },
225
+ ],
226
+ return: {
227
+ data: {
228
+ listAuthor: [{ id: testUuid(1), name: null, [`__predicate_${longPredicateName}`]: true }],
229
+ },
230
+ },
231
+ })
232
+ })
233
+
234
+ test('an alias equal to a relation field does not replace the relation key', async () => {
235
+ await execute({
236
+ schema,
237
+ permissions,
238
+ query: GQL`
239
+ query {
240
+ listPost {
241
+ id
242
+ writer: author {
243
+ id
244
+ }
245
+ author: externalId
246
+ }
247
+ }`,
248
+ executes: [
249
+ {
250
+ sql: SQL`
251
+ select "root_"."id" as "root_id",
252
+ "root_"."author_id" as "root_$key_author",
253
+ "root_"."external_id" as "root_author"
254
+ from "public"."post" as "root_"`,
255
+ parameters: [],
256
+ response: {
257
+ rows: [{ 'root_id': testUuid(1), 'root_$key_author': testUuid(2), 'root_author': testUuid(9) }],
258
+ },
259
+ },
260
+ {
261
+ sql: SQL`
262
+ select "root_"."id" as "root_$index_id",
263
+ "root_"."id" as "root_id"
264
+ from "public"."author" as "root_"
265
+ where "root_"."id" in (?)`,
266
+ parameters: [testUuid(2)],
267
+ response: {
268
+ rows: [{ 'root_$index_id': testUuid(2), 'root_id': testUuid(2) }],
269
+ },
270
+ },
271
+ ],
272
+ return: {
273
+ data: {
274
+ listPost: [{ id: testUuid(1), writer: { id: testUuid(2) }, author: testUuid(9) }],
275
+ },
276
+ },
277
+ })
278
+ })