@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.
- package/CLAUDE.md +2 -0
- package/dist/development/src/mapper/ErrorUtils.cjs +7 -1
- package/dist/development/src/mapper/ErrorUtils.cjs.map +1 -1
- package/dist/development/src/mapper/ErrorUtils.js +7 -1
- package/dist/development/src/mapper/ErrorUtils.js.map +1 -1
- package/dist/development/src/mapper/Mapper.cjs +2 -1
- package/dist/development/src/mapper/Mapper.cjs.map +1 -1
- package/dist/development/src/mapper/Mapper.js +2 -1
- package/dist/development/src/mapper/Mapper.js.map +1 -1
- package/dist/development/src/mapper/select/Path.cjs +23 -3
- package/dist/development/src/mapper/select/Path.cjs.map +1 -1
- package/dist/development/src/mapper/select/Path.js +23 -3
- package/dist/development/src/mapper/select/Path.js.map +1 -1
- package/dist/development/src/mapper/select/SelectBuilder.cjs +13 -10
- package/dist/development/src/mapper/select/SelectBuilder.cjs.map +1 -1
- package/dist/development/src/mapper/select/SelectBuilder.js +13 -10
- package/dist/development/src/mapper/select/SelectBuilder.js.map +1 -1
- package/dist/development/src/mapper/select/handlers/FieldsVisitor.cjs +1 -1
- package/dist/development/src/mapper/select/handlers/FieldsVisitor.cjs.map +1 -1
- package/dist/development/src/mapper/select/handlers/FieldsVisitor.js +1 -1
- package/dist/development/src/mapper/select/handlers/FieldsVisitor.js.map +1 -1
- package/dist/development/src/mapper/select/handlers/MetaHandler.cjs +4 -3
- package/dist/development/src/mapper/select/handlers/MetaHandler.cjs.map +1 -1
- package/dist/development/src/mapper/select/handlers/MetaHandler.js +4 -3
- package/dist/development/src/mapper/select/handlers/MetaHandler.js.map +1 -1
- package/dist/development/src/resolvers/MutationResolver.cjs +1 -0
- package/dist/development/src/resolvers/MutationResolver.cjs.map +1 -1
- package/dist/development/src/resolvers/MutationResolver.js +1 -0
- package/dist/development/src/resolvers/MutationResolver.js.map +1 -1
- package/dist/production/src/mapper/ErrorUtils.cjs +7 -1
- package/dist/production/src/mapper/ErrorUtils.cjs.map +1 -1
- package/dist/production/src/mapper/ErrorUtils.js +7 -1
- package/dist/production/src/mapper/ErrorUtils.js.map +1 -1
- package/dist/production/src/mapper/Mapper.cjs +2 -1
- package/dist/production/src/mapper/Mapper.cjs.map +1 -1
- package/dist/production/src/mapper/Mapper.js +2 -1
- package/dist/production/src/mapper/Mapper.js.map +1 -1
- package/dist/production/src/mapper/select/Path.cjs +23 -3
- package/dist/production/src/mapper/select/Path.cjs.map +1 -1
- package/dist/production/src/mapper/select/Path.js +23 -3
- package/dist/production/src/mapper/select/Path.js.map +1 -1
- package/dist/production/src/mapper/select/SelectBuilder.cjs +13 -10
- package/dist/production/src/mapper/select/SelectBuilder.cjs.map +1 -1
- package/dist/production/src/mapper/select/SelectBuilder.js +13 -10
- package/dist/production/src/mapper/select/SelectBuilder.js.map +1 -1
- package/dist/production/src/mapper/select/handlers/FieldsVisitor.cjs +1 -1
- package/dist/production/src/mapper/select/handlers/FieldsVisitor.cjs.map +1 -1
- package/dist/production/src/mapper/select/handlers/FieldsVisitor.js +1 -1
- package/dist/production/src/mapper/select/handlers/FieldsVisitor.js.map +1 -1
- package/dist/production/src/mapper/select/handlers/MetaHandler.cjs +4 -3
- package/dist/production/src/mapper/select/handlers/MetaHandler.cjs.map +1 -1
- package/dist/production/src/mapper/select/handlers/MetaHandler.js +4 -3
- package/dist/production/src/mapper/select/handlers/MetaHandler.js.map +1 -1
- package/dist/production/src/resolvers/MutationResolver.cjs +1 -0
- package/dist/production/src/resolvers/MutationResolver.cjs.map +1 -1
- package/dist/production/src/resolvers/MutationResolver.js +1 -0
- package/dist/production/src/resolvers/MutationResolver.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/query/acl/nestedThroughPredicate.test.d.ts +2 -0
- package/dist/tests/cases/integration/graphQlRequests/query/acl/nestedThroughPredicate.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/mutationSqlError.test.d.ts +2 -0
- package/dist/tests/cases/unit/mutationSqlError.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/pathAlias.test.d.ts +2 -0
- package/dist/tests/cases/unit/pathAlias.test.d.ts.map +1 -0
- package/dist/tests/src/test.d.ts +1 -0
- package/dist/tests/src/test.d.ts.map +1 -1
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/dist/types/mapper/ErrorUtils.d.ts.map +1 -1
- package/dist/types/mapper/select/Path.d.ts +1 -0
- package/dist/types/mapper/select/Path.d.ts.map +1 -1
- package/dist/types/mapper/select/SelectBuilder.d.ts.map +1 -1
- package/dist/types/mapper/select/SelectExecutionHandler.d.ts +11 -1
- package/dist/types/mapper/select/SelectExecutionHandler.d.ts.map +1 -1
- package/dist/types/mapper/select/handlers/MetaHandler.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -9
- package/src/mapper/ErrorUtils.ts +11 -1
- package/src/mapper/Mapper.ts +1 -1
- package/src/mapper/select/Path.ts +25 -5
- package/src/mapper/select/SelectBuilder.ts +22 -11
- package/src/mapper/select/SelectExecutionHandler.ts +9 -1
- package/src/mapper/select/handlers/FieldsVisitor.ts +1 -1
- package/src/mapper/select/handlers/MetaHandler.ts +8 -3
- package/tests/cases/bugs/bug102.test.ts +4 -4
- package/tests/cases/integration/graphQlRequests/delete/deleteById.test.ts +4 -3
- package/tests/cases/integration/graphQlRequests/query/acl/differentRowAndFieldPredicate.test.ts +4 -4
- package/tests/cases/integration/graphQlRequests/query/acl/fieldRestrictedByLocale.test.ts +12 -10
- package/tests/cases/integration/graphQlRequests/query/acl/nestedPredicate.test.ts +7 -6
- package/tests/cases/integration/graphQlRequests/query/acl/nestedThroughPredicate.test.ts +345 -0
- package/tests/cases/integration/graphQlRequests/query/acl/predicateElimination.test.ts +25 -23
- package/tests/cases/integration/graphQlRequests/query/acl/relationAcl.test.ts +12 -9
- package/tests/cases/integration/graphQlRequests/query/acl/rowPredicateSubset.test.ts +6 -6
- package/tests/cases/integration/graphQlRequests/query/filter/backReferencedFilter.test.ts +3 -1
- package/tests/cases/integration/graphQlRequests/query/graphqlFeatures/alias.test.ts +2 -2
- package/tests/cases/integration/graphQlRequests/query/graphqlFeatures/fragments.test.ts +8 -8
- package/tests/cases/integration/graphQlRequests/query/misc/reducedHasMany.test.ts +10 -10
- package/tests/cases/integration/graphQlRequests/query/pagination/hasManyLimit.test.ts +8 -8
- package/tests/cases/integration/graphQlRequests/query/pagination/paginate.test.ts +5 -4
- package/tests/cases/integration/graphQlRequests/query/pagination/paginateAliased.test.ts +5 -4
- package/tests/cases/integration/graphQlRequests/query/relations/advanced.test.ts +17 -8
- package/tests/cases/integration/graphQlRequests/query/relations/manyHasManyInverse.test.ts +6 -6
- package/tests/cases/integration/graphQlRequests/query/relations/manyHasManyOwning.test.ts +6 -6
- package/tests/cases/integration/graphQlRequests/query/relations/manyHasOne.test.ts +12 -9
- package/tests/cases/integration/graphQlRequests/query/relations/oneHasMany.test.ts +12 -12
- package/tests/cases/integration/graphQlRequests/query/relations/oneHasOneInverse.test.ts +6 -4
- package/tests/cases/integration/graphQlRequests/query/relations/oneHasOneOwner.test.ts +6 -4
- package/tests/cases/integration/graphQlRequests/query/sorting/defaultOrdering.test.ts +4 -4
- package/tests/cases/integration/graphQlRequests/query/sorting/randomSort.test.ts +5 -5
- package/tests/cases/integration/graphQlRequests/query/sorting/sortedHasMany.test.ts +2 -2
- package/tests/cases/integration/graphQlRequests/query/view/view.test.ts +6 -6
- package/tests/cases/unit/mutationSqlError.test.ts +30 -0
- package/tests/cases/unit/pathAlias.test.ts +26 -0
- package/tests/src/test.ts +5 -1
|
@@ -0,0 +1,345 @@
|
|
|
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 nested entity is masked with the through-inclusive `all` permission set. Merging roles renames predicates
|
|
9
|
+
// (`__merge__a__b`) and a `through` grant exists only in `all`, so the predicate a nested cell references
|
|
10
|
+
// must be resolved against `all` too, never against the root set.
|
|
11
|
+
|
|
12
|
+
const schema = new SchemaBuilder()
|
|
13
|
+
.entity('Post', entityBuilder => entityBuilder.oneHasMany('locales', c => c.target('PostLocale').ownedBy('post')))
|
|
14
|
+
.entity('PostLocale', entity =>
|
|
15
|
+
entity
|
|
16
|
+
.column('title', column => column.type(Model.ColumnType.String))
|
|
17
|
+
.column('locale', column => column.type(Model.ColumnType.String))
|
|
18
|
+
.column('visible', column => column.type(Model.ColumnType.Bool)))
|
|
19
|
+
.buildSchema()
|
|
20
|
+
|
|
21
|
+
const postPermissions: Acl.EntityPermissions = {
|
|
22
|
+
predicates: {},
|
|
23
|
+
operations: {
|
|
24
|
+
read: { id: true, locales: true },
|
|
25
|
+
},
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const listPostQuery = {
|
|
29
|
+
sql: SQL`select "root_"."id" as "root_$key_id", "root_"."id" as "root_id" from "public"."post" as "root_"`,
|
|
30
|
+
parameters: [],
|
|
31
|
+
response: {
|
|
32
|
+
rows: [{ root_id: testUuid(1), 'root_$key_id': testUuid(1) }],
|
|
33
|
+
},
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
test('nested cell predicate that exists only in the through set is resolved against it', async () => {
|
|
37
|
+
const permissions: Acl.Permissions = {
|
|
38
|
+
Post: postPermissions,
|
|
39
|
+
PostLocale: {
|
|
40
|
+
predicates: {},
|
|
41
|
+
operations: {
|
|
42
|
+
read: { id: true, post: true, title: false },
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
}
|
|
46
|
+
const allPermissions: Acl.Permissions = {
|
|
47
|
+
Post: postPermissions,
|
|
48
|
+
PostLocale: {
|
|
49
|
+
predicates: { __merge__throughTitle: { visible: { eq: true } } },
|
|
50
|
+
operations: {
|
|
51
|
+
read: { id: true, post: true, title: '__merge__throughTitle' },
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
}
|
|
55
|
+
await execute({
|
|
56
|
+
schema,
|
|
57
|
+
permissions,
|
|
58
|
+
allPermissions,
|
|
59
|
+
query: GQL`
|
|
60
|
+
query {
|
|
61
|
+
listPost {
|
|
62
|
+
locales {
|
|
63
|
+
id
|
|
64
|
+
title
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}`,
|
|
68
|
+
executes: [
|
|
69
|
+
listPostQuery,
|
|
70
|
+
{
|
|
71
|
+
sql: SQL`
|
|
72
|
+
select "root_"."post_id" as "__grouping_key",
|
|
73
|
+
"root_"."id" as "root_id",
|
|
74
|
+
"root_"."visible" = ? as "root_$predicate___merge__throughTitle",
|
|
75
|
+
"root_"."title" as "root_title"
|
|
76
|
+
from "public"."post_locale" as "root_" where "root_"."post_id" in (?)`,
|
|
77
|
+
parameters: [true, testUuid(1)],
|
|
78
|
+
response: {
|
|
79
|
+
rows: [
|
|
80
|
+
{ __grouping_key: testUuid(1), root_id: testUuid(2), root_title: 'foo', 'root_$predicate___merge__throughTitle': true },
|
|
81
|
+
{ __grouping_key: testUuid(1), root_id: testUuid(3), root_title: 'bar', 'root_$predicate___merge__throughTitle': false },
|
|
82
|
+
],
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
return: {
|
|
87
|
+
data: {
|
|
88
|
+
listPost: [
|
|
89
|
+
{
|
|
90
|
+
locales: [
|
|
91
|
+
{ id: testUuid(2), title: 'foo' },
|
|
92
|
+
{ id: testUuid(3), title: null },
|
|
93
|
+
],
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
})
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
test('nested cell predicate is not simplified against the root row predicate', async () => {
|
|
102
|
+
// The same names denote different definitions in the two sets. The nested rows are filtered with the
|
|
103
|
+
// through row predicate (`locale = 'cs'`), so the cell predicate must not be eliminated against the root
|
|
104
|
+
// row predicate (`visible = true`), which the returned rows were never filtered by.
|
|
105
|
+
const permissions: Acl.Permissions = {
|
|
106
|
+
Post: postPermissions,
|
|
107
|
+
PostLocale: {
|
|
108
|
+
predicates: {
|
|
109
|
+
row: { visible: { eq: true } },
|
|
110
|
+
title: { visible: { eq: true } },
|
|
111
|
+
},
|
|
112
|
+
operations: {
|
|
113
|
+
read: { id: 'row', post: 'row', title: 'title', locale: 'row', visible: 'row' },
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
}
|
|
117
|
+
const allPermissions: Acl.Permissions = {
|
|
118
|
+
Post: postPermissions,
|
|
119
|
+
PostLocale: {
|
|
120
|
+
predicates: {
|
|
121
|
+
row: { locale: { eq: 'cs' } },
|
|
122
|
+
title: { visible: { eq: true } },
|
|
123
|
+
},
|
|
124
|
+
operations: {
|
|
125
|
+
read: { id: 'row', post: 'row', title: 'title', locale: 'row', visible: 'row' },
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
}
|
|
129
|
+
await execute({
|
|
130
|
+
schema,
|
|
131
|
+
permissions,
|
|
132
|
+
allPermissions,
|
|
133
|
+
query: GQL`
|
|
134
|
+
query {
|
|
135
|
+
listPost {
|
|
136
|
+
locales {
|
|
137
|
+
id
|
|
138
|
+
title
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}`,
|
|
142
|
+
executes: [
|
|
143
|
+
listPostQuery,
|
|
144
|
+
{
|
|
145
|
+
sql: SQL`
|
|
146
|
+
select "root_"."post_id" as "__grouping_key",
|
|
147
|
+
"root_"."id" as "root_id",
|
|
148
|
+
"root_"."visible" = ? as "root_$predicate_title",
|
|
149
|
+
"root_"."title" as "root_title"
|
|
150
|
+
from "public"."post_locale" as "root_" where "root_"."post_id" in (?) and "root_"."locale" = ?`,
|
|
151
|
+
parameters: [true, testUuid(1), 'cs'],
|
|
152
|
+
response: {
|
|
153
|
+
rows: [
|
|
154
|
+
{ __grouping_key: testUuid(1), root_id: testUuid(2), root_title: 'foo', 'root_$predicate_title': true },
|
|
155
|
+
{ __grouping_key: testUuid(1), root_id: testUuid(3), root_title: 'bar', 'root_$predicate_title': false },
|
|
156
|
+
],
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
],
|
|
160
|
+
return: {
|
|
161
|
+
data: {
|
|
162
|
+
listPost: [
|
|
163
|
+
{
|
|
164
|
+
locales: [
|
|
165
|
+
{ id: testUuid(2), title: 'foo' },
|
|
166
|
+
{ id: testUuid(3), title: null },
|
|
167
|
+
],
|
|
168
|
+
},
|
|
169
|
+
],
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
})
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
test('nested _meta resolves readable against the through set and updatable against the root set', async () => {
|
|
176
|
+
// `readable` must agree with value masking (through set); `updatable` follows write enforcement (root set).
|
|
177
|
+
// Each name exists only in its own set, so resolving either against the other one throws.
|
|
178
|
+
const permissions: Acl.Permissions = {
|
|
179
|
+
Post: postPermissions,
|
|
180
|
+
PostLocale: {
|
|
181
|
+
predicates: { rootUpdatable: { visible: { eq: true } } },
|
|
182
|
+
operations: {
|
|
183
|
+
read: { id: true, post: true, title: false },
|
|
184
|
+
update: { id: 'rootUpdatable', post: true, title: 'rootUpdatable' },
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
}
|
|
188
|
+
const allPermissions: Acl.Permissions = {
|
|
189
|
+
Post: postPermissions,
|
|
190
|
+
PostLocale: {
|
|
191
|
+
predicates: {
|
|
192
|
+
throughReadable: { locale: { eq: 'cs' } },
|
|
193
|
+
throughUpdatable: { visible: { eq: false } },
|
|
194
|
+
},
|
|
195
|
+
operations: {
|
|
196
|
+
read: { id: true, post: true, title: 'throughReadable' },
|
|
197
|
+
update: { id: 'throughUpdatable', post: true, title: 'throughUpdatable' },
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
}
|
|
201
|
+
await execute({
|
|
202
|
+
schema,
|
|
203
|
+
permissions,
|
|
204
|
+
allPermissions,
|
|
205
|
+
query: GQL`
|
|
206
|
+
query {
|
|
207
|
+
listPost {
|
|
208
|
+
locales {
|
|
209
|
+
id
|
|
210
|
+
_meta {
|
|
211
|
+
title {
|
|
212
|
+
readable
|
|
213
|
+
updatable
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}`,
|
|
219
|
+
executes: [
|
|
220
|
+
listPostQuery,
|
|
221
|
+
{
|
|
222
|
+
sql: SQL`
|
|
223
|
+
select "root_"."post_id" as "__grouping_key",
|
|
224
|
+
"root_"."id" as "root_id",
|
|
225
|
+
"root_"."locale" = ? as "root_$predicate_throughReadable",
|
|
226
|
+
"root_"."visible" = ? as "root_$predicateRoot_rootUpdatable"
|
|
227
|
+
from "public"."post_locale" as "root_" where "root_"."post_id" in (?)`,
|
|
228
|
+
parameters: ['cs', true, testUuid(1)],
|
|
229
|
+
response: {
|
|
230
|
+
rows: [
|
|
231
|
+
{
|
|
232
|
+
__grouping_key: testUuid(1),
|
|
233
|
+
root_id: testUuid(2),
|
|
234
|
+
'root_$predicate_throughReadable': true,
|
|
235
|
+
'root_$predicateRoot_rootUpdatable': false,
|
|
236
|
+
},
|
|
237
|
+
],
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
|
+
],
|
|
241
|
+
return: {
|
|
242
|
+
data: {
|
|
243
|
+
listPost: [
|
|
244
|
+
{
|
|
245
|
+
locales: [
|
|
246
|
+
{ id: testUuid(2), _meta: { title: { readable: true, updatable: false } } },
|
|
247
|
+
],
|
|
248
|
+
},
|
|
249
|
+
],
|
|
250
|
+
},
|
|
251
|
+
},
|
|
252
|
+
})
|
|
253
|
+
})
|
|
254
|
+
|
|
255
|
+
// The value mask and `readable` use the read predicate from the through set; `updatable` uses the update predicate
|
|
256
|
+
// from the root set. Each must get its own column whatever the names are and whichever field is selected first.
|
|
257
|
+
const rootOnlyColumnCases: { name: string; readPredicate: string; allPermissions: Acl.Permissions }[] = [
|
|
258
|
+
{
|
|
259
|
+
name: 'the same name with a different definition in each set',
|
|
260
|
+
readPredicate: 'check',
|
|
261
|
+
allPermissions: {
|
|
262
|
+
Post: postPermissions,
|
|
263
|
+
PostLocale: {
|
|
264
|
+
predicates: { check: { locale: { eq: 'cs' } } },
|
|
265
|
+
operations: {
|
|
266
|
+
read: { id: true, post: true, title: 'check' },
|
|
267
|
+
update: { id: true, post: true, title: 'check' },
|
|
268
|
+
},
|
|
269
|
+
},
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
name: 'a read predicate name that ends like a root-only key',
|
|
274
|
+
readPredicate: 'check__rootPerms',
|
|
275
|
+
allPermissions: {
|
|
276
|
+
Post: postPermissions,
|
|
277
|
+
PostLocale: {
|
|
278
|
+
predicates: { check__rootPerms: { locale: { eq: 'cs' } } },
|
|
279
|
+
operations: {
|
|
280
|
+
read: { id: true, post: true, title: 'check__rootPerms' },
|
|
281
|
+
update: { id: true, post: true, title: 'check__rootPerms' },
|
|
282
|
+
},
|
|
283
|
+
},
|
|
284
|
+
},
|
|
285
|
+
},
|
|
286
|
+
]
|
|
287
|
+
|
|
288
|
+
const rootOnlyColumnPermissions: Acl.Permissions = {
|
|
289
|
+
Post: postPermissions,
|
|
290
|
+
PostLocale: {
|
|
291
|
+
predicates: { check: { visible: { eq: true } } },
|
|
292
|
+
operations: {
|
|
293
|
+
read: { id: true, post: true, title: false },
|
|
294
|
+
update: { id: true, post: true, title: 'check' },
|
|
295
|
+
},
|
|
296
|
+
},
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
for (const { name, readPredicate, allPermissions } of rootOnlyColumnCases) {
|
|
300
|
+
for (const metaFirst of [false, true]) {
|
|
301
|
+
test(`nested root-only _meta.updatable gets its own column: ${name}, ${metaFirst ? '_meta' : 'value'} selected first`, async () => {
|
|
302
|
+
const readAlias = `root_$predicate_${readPredicate}`
|
|
303
|
+
const updateAlias = 'root_$predicateRoot_check'
|
|
304
|
+
const readColumn = `"root_"."locale" = ? as "${readAlias}"`
|
|
305
|
+
const updateColumn = `"root_"."visible" = ? as "${updateAlias}"`
|
|
306
|
+
const columns = metaFirst
|
|
307
|
+
? [readColumn, updateColumn, '"root_"."title" as "root_title"']
|
|
308
|
+
: [readColumn, '"root_"."title" as "root_title"', updateColumn]
|
|
309
|
+
const meta = '_meta { title { readable updatable } }'
|
|
310
|
+
await execute({
|
|
311
|
+
schema,
|
|
312
|
+
permissions: rootOnlyColumnPermissions,
|
|
313
|
+
allPermissions,
|
|
314
|
+
query: `query { listPost { locales { id ${metaFirst ? `${meta} title` : `title ${meta}`} } } }`,
|
|
315
|
+
executes: [
|
|
316
|
+
listPostQuery,
|
|
317
|
+
{
|
|
318
|
+
sql: SQL`
|
|
319
|
+
select "root_"."post_id" as "__grouping_key", "root_"."id" as "root_id", ${columns.join(', ')}
|
|
320
|
+
from "public"."post_locale" as "root_" where "root_"."post_id" in (?)`,
|
|
321
|
+
parameters: ['cs', true, testUuid(1)],
|
|
322
|
+
response: {
|
|
323
|
+
rows: [
|
|
324
|
+
{ __grouping_key: testUuid(1), root_id: testUuid(2), root_title: 'foo', [readAlias]: true, [updateAlias]: false },
|
|
325
|
+
{ __grouping_key: testUuid(1), root_id: testUuid(3), root_title: 'bar', [readAlias]: false, [updateAlias]: true },
|
|
326
|
+
],
|
|
327
|
+
},
|
|
328
|
+
},
|
|
329
|
+
],
|
|
330
|
+
return: {
|
|
331
|
+
data: {
|
|
332
|
+
listPost: [
|
|
333
|
+
{
|
|
334
|
+
locales: [
|
|
335
|
+
{ id: testUuid(2), title: 'foo', _meta: { title: { readable: true, updatable: false } } },
|
|
336
|
+
{ id: testUuid(3), title: null, _meta: { title: { readable: false, updatable: true } } },
|
|
337
|
+
],
|
|
338
|
+
},
|
|
339
|
+
],
|
|
340
|
+
},
|
|
341
|
+
},
|
|
342
|
+
})
|
|
343
|
+
})
|
|
344
|
+
}
|
|
345
|
+
}
|
|
@@ -87,7 +87,7 @@ test('predicate with OR', async () => {
|
|
|
87
87
|
}`,
|
|
88
88
|
executes: [
|
|
89
89
|
{
|
|
90
|
-
sql: SQL`SELECT "root_"."id" AS "root_id", "root_"."image_id"
|
|
90
|
+
sql: SQL`SELECT "root_"."id" AS "root_id", "root_"."image_id" as "root_$key_image"
|
|
91
91
|
FROM "public"."author" AS "root_"
|
|
92
92
|
WHERE "root_"."is_public" = ?`,
|
|
93
93
|
parameters: [true],
|
|
@@ -95,19 +95,20 @@ test('predicate with OR', async () => {
|
|
|
95
95
|
rows: [
|
|
96
96
|
{
|
|
97
97
|
root_id: testUuid(1),
|
|
98
|
-
|
|
98
|
+
'root_$key_image': testUuid(2),
|
|
99
99
|
},
|
|
100
100
|
],
|
|
101
101
|
},
|
|
102
102
|
},
|
|
103
103
|
{
|
|
104
104
|
sql:
|
|
105
|
-
`select "root_"."id" as "
|
|
105
|
+
`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 (?)`,
|
|
106
106
|
parameters: [testUuid(2)],
|
|
107
107
|
response: {
|
|
108
108
|
rows: [
|
|
109
109
|
{
|
|
110
110
|
root_id: testUuid(2),
|
|
111
|
+
'root_$index_id': testUuid(2),
|
|
111
112
|
root_url: 'abcd',
|
|
112
113
|
},
|
|
113
114
|
],
|
|
@@ -189,12 +190,13 @@ test('does apply primary filter even if relation predicate eliminates it', async
|
|
|
189
190
|
executes: [
|
|
190
191
|
{
|
|
191
192
|
sql:
|
|
192
|
-
SQL`select "root_"."title" as "root_title", "root_"."id" as "
|
|
193
|
+
SQL`select "root_"."title" as "root_title", "root_"."id" as "root_$key_id", "root_"."id" as "root_$key_id", "root_"."id" as "root_id" from "public"."article" as "root_" where "root_"."id" = ? and "root_"."id" in (?)`,
|
|
193
194
|
parameters: [testUuid(1), testUuid(1)],
|
|
194
195
|
response: {
|
|
195
196
|
rows: [
|
|
196
197
|
{
|
|
197
198
|
root_id: testUuid(1),
|
|
199
|
+
'root_$key_id': testUuid(1),
|
|
198
200
|
root_title: 'Article A',
|
|
199
201
|
},
|
|
200
202
|
],
|
|
@@ -210,7 +212,7 @@ test('does apply primary filter even if relation predicate eliminates it', async
|
|
|
210
212
|
},
|
|
211
213
|
{
|
|
212
214
|
sql:
|
|
213
|
-
SQL`select "root_"."article_id" as "
|
|
215
|
+
SQL`select "root_"."article_id" as "root_$index_article", "root_"."views" as "root_views", "root_"."id" as "root_id" from "public"."article_stats" as "root_" where "root_"."article_id" in (?)`,
|
|
214
216
|
parameters: [testUuid(1)],
|
|
215
217
|
response: {
|
|
216
218
|
rows: [],
|
|
@@ -266,11 +268,11 @@ test('self-referencing: children should have their own predicate applied', async
|
|
|
266
268
|
{
|
|
267
269
|
// Parent categories - must have isActive = true
|
|
268
270
|
sql:
|
|
269
|
-
SQL`select "root_"."name" as "root_name", "root_"."id" as "
|
|
271
|
+
SQL`select "root_"."name" as "root_name", "root_"."id" as "root_$key_id", "root_"."id" as "root_id" from "public"."category" as "root_" where "root_"."is_active" = ?`,
|
|
270
272
|
parameters: [true],
|
|
271
273
|
response: {
|
|
272
274
|
rows: [
|
|
273
|
-
{ root_id: testUuid(1), root_name: 'Parent Category' },
|
|
275
|
+
{ root_id: testUuid(1), 'root_$key_id': testUuid(1), root_name: 'Parent Category' },
|
|
274
276
|
],
|
|
275
277
|
},
|
|
276
278
|
},
|
|
@@ -350,11 +352,11 @@ test('multiple relations: articles via author should apply article predicate', a
|
|
|
350
352
|
{
|
|
351
353
|
// Persons - must have isActive = true
|
|
352
354
|
sql:
|
|
353
|
-
SQL`select "root_"."name" as "root_name", "root_"."id" as "
|
|
355
|
+
SQL`select "root_"."name" as "root_name", "root_"."id" as "root_$key_id", "root_"."id" as "root_id" from "public"."person" as "root_" where "root_"."is_active" = ?`,
|
|
354
356
|
parameters: [true],
|
|
355
357
|
response: {
|
|
356
358
|
rows: [
|
|
357
|
-
{ root_id: testUuid(1), root_name: 'John' },
|
|
359
|
+
{ root_id: testUuid(1), 'root_$key_id': testUuid(1), root_name: 'John' },
|
|
358
360
|
],
|
|
359
361
|
},
|
|
360
362
|
},
|
|
@@ -431,11 +433,11 @@ test('back-reference predicate should be eliminated but join filter preserved',
|
|
|
431
433
|
{
|
|
432
434
|
// Articles - must have isPublished = true
|
|
433
435
|
sql:
|
|
434
|
-
SQL`select "root_"."title" as "root_title", "root_"."id" as "
|
|
436
|
+
SQL`select "root_"."title" as "root_title", "root_"."id" as "root_$key_id", "root_"."id" as "root_id" from "public"."article" as "root_" where "root_"."is_published" = ?`,
|
|
435
437
|
parameters: [true],
|
|
436
438
|
response: {
|
|
437
439
|
rows: [
|
|
438
|
-
{ root_id: testUuid(1), root_title: 'Published Article' },
|
|
440
|
+
{ root_id: testUuid(1), 'root_$key_id': testUuid(1), root_title: 'Published Article' },
|
|
439
441
|
],
|
|
440
442
|
},
|
|
441
443
|
},
|
|
@@ -526,22 +528,22 @@ test('deep nesting: predicates should be properly eliminated at each level', asy
|
|
|
526
528
|
{
|
|
527
529
|
// Companies - must have isActive = true
|
|
528
530
|
sql:
|
|
529
|
-
SQL`select "root_"."name" as "root_name", "root_"."id" as "
|
|
531
|
+
SQL`select "root_"."name" as "root_name", "root_"."id" as "root_$key_id", "root_"."id" as "root_id" from "public"."company" as "root_" where "root_"."is_active" = ?`,
|
|
530
532
|
parameters: [true],
|
|
531
533
|
response: {
|
|
532
534
|
rows: [
|
|
533
|
-
{ root_id: testUuid(1), root_name: 'Acme Corp' },
|
|
535
|
+
{ root_id: testUuid(1), 'root_$key_id': testUuid(1), root_name: 'Acme Corp' },
|
|
534
536
|
],
|
|
535
537
|
},
|
|
536
538
|
},
|
|
537
539
|
{
|
|
538
540
|
// Departments - back-reference predicate eliminated, join filter preserved
|
|
539
541
|
sql:
|
|
540
|
-
SQL`select "root_"."company_id" as "__grouping_key", "root_"."name" as "root_name", "root_"."id" as "
|
|
542
|
+
SQL`select "root_"."company_id" as "__grouping_key", "root_"."name" as "root_name", "root_"."id" as "root_$key_id", "root_"."id" as "root_id" from "public"."department" as "root_" where "root_"."company_id" in (?)`,
|
|
541
543
|
parameters: [testUuid(1)],
|
|
542
544
|
response: {
|
|
543
545
|
rows: [
|
|
544
|
-
{ __grouping_key: testUuid(1), root_id: testUuid(2), root_name: 'Engineering' },
|
|
546
|
+
{ __grouping_key: testUuid(1), root_id: testUuid(2), 'root_$key_id': testUuid(2), root_name: 'Engineering' },
|
|
545
547
|
],
|
|
546
548
|
},
|
|
547
549
|
},
|
|
@@ -676,11 +678,11 @@ test('multi-level back-reference: predicates should be eliminated at each level'
|
|
|
676
678
|
{
|
|
677
679
|
// Companies - must have isActive = true
|
|
678
680
|
sql:
|
|
679
|
-
SQL`select "root_"."name" as "root_name", "root_"."id" as "
|
|
681
|
+
SQL`select "root_"."name" as "root_name", "root_"."id" as "root_$key_id", "root_"."id" as "root_id" from "public"."company" as "root_" where "root_"."is_active" = ?`,
|
|
680
682
|
parameters: [true],
|
|
681
683
|
response: {
|
|
682
684
|
rows: [
|
|
683
|
-
{ root_id: testUuid(1), root_name: 'Acme Corp' },
|
|
685
|
+
{ root_id: testUuid(1), 'root_$key_id': testUuid(1), root_name: 'Acme Corp' },
|
|
684
686
|
],
|
|
685
687
|
},
|
|
686
688
|
},
|
|
@@ -688,11 +690,11 @@ test('multi-level back-reference: predicates should be eliminated at each level'
|
|
|
688
690
|
// Departments - back-reference predicate (company.isActive) should be eliminated
|
|
689
691
|
// Only join filter preserved
|
|
690
692
|
sql:
|
|
691
|
-
SQL`select "root_"."company_id" as "__grouping_key", "root_"."name" as "root_name", "root_"."id" as "
|
|
693
|
+
SQL`select "root_"."company_id" as "__grouping_key", "root_"."name" as "root_name", "root_"."id" as "root_$key_id", "root_"."id" as "root_id" from "public"."department" as "root_" where "root_"."company_id" in (?)`,
|
|
692
694
|
parameters: [testUuid(1)],
|
|
693
695
|
response: {
|
|
694
696
|
rows: [
|
|
695
|
-
{ __grouping_key: testUuid(1), root_id: testUuid(2), root_name: 'Engineering' },
|
|
697
|
+
{ __grouping_key: testUuid(1), root_id: testUuid(2), 'root_$key_id': testUuid(2), root_name: 'Engineering' },
|
|
696
698
|
],
|
|
697
699
|
},
|
|
698
700
|
},
|
|
@@ -700,11 +702,11 @@ test('multi-level back-reference: predicates should be eliminated at each level'
|
|
|
700
702
|
// Employees - multi-level back-reference predicate (department.company.isActive) should be eliminated
|
|
701
703
|
// Only join filter preserved
|
|
702
704
|
sql:
|
|
703
|
-
SQL`select "root_"."department_id" as "__grouping_key", "root_"."name" as "root_name", "root_"."id" as "
|
|
705
|
+
SQL`select "root_"."department_id" as "__grouping_key", "root_"."name" as "root_name", "root_"."id" as "root_$key_id", "root_"."id" as "root_id" from "public"."employee" as "root_" where "root_"."department_id" in (?)`,
|
|
704
706
|
parameters: [testUuid(2)],
|
|
705
707
|
response: {
|
|
706
708
|
rows: [
|
|
707
|
-
{ __grouping_key: testUuid(2), root_id: testUuid(3), root_name: 'Alice' },
|
|
709
|
+
{ __grouping_key: testUuid(2), root_id: testUuid(3), 'root_$key_id': testUuid(3), root_name: 'Alice' },
|
|
708
710
|
],
|
|
709
711
|
},
|
|
710
712
|
},
|
|
@@ -768,11 +770,11 @@ test('user filter on has-many should be preserved alongside join filter', async
|
|
|
768
770
|
executes: [
|
|
769
771
|
{
|
|
770
772
|
sql:
|
|
771
|
-
SQL`select "root_"."name" as "root_name", "root_"."id" as "
|
|
773
|
+
SQL`select "root_"."name" as "root_name", "root_"."id" as "root_$key_id", "root_"."id" as "root_id" from "public"."company" as "root_" where "root_"."id" in (?)`,
|
|
772
774
|
parameters: [testUuid(1)],
|
|
773
775
|
response: {
|
|
774
776
|
rows: [
|
|
775
|
-
{ root_id: testUuid(1), root_name: 'Acme Corp' },
|
|
777
|
+
{ root_id: testUuid(1), 'root_$key_id': testUuid(1), root_name: 'Acme Corp' },
|
|
776
778
|
],
|
|
777
779
|
},
|
|
778
780
|
},
|
|
@@ -50,33 +50,34 @@ test('can read same entity only over relation of some rows - many has one', asyn
|
|
|
50
50
|
executes: [
|
|
51
51
|
{
|
|
52
52
|
sql:
|
|
53
|
-
SQL`select "root_"."title" as "root_title", "root_"."disclose_author" = ? as "
|
|
53
|
+
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"
|
|
54
54
|
from "public"."article" as "root_"`,
|
|
55
55
|
response: {
|
|
56
56
|
rows: [
|
|
57
57
|
{
|
|
58
58
|
root_id: testUuid(1),
|
|
59
59
|
root_title: 'Article A',
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
'root_$predicate_discloseAuthor_eq_true': true,
|
|
61
|
+
'root_$key_author': testUuid(10),
|
|
62
62
|
},
|
|
63
63
|
{
|
|
64
64
|
root_id: testUuid(2),
|
|
65
65
|
root_title: 'Article B',
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
'root_$predicate_discloseAuthor_eq_true': false,
|
|
67
|
+
'root_$key_author': testUuid(10),
|
|
68
68
|
},
|
|
69
69
|
],
|
|
70
70
|
},
|
|
71
71
|
},
|
|
72
72
|
{
|
|
73
73
|
sql:
|
|
74
|
-
SQL`select "root_"."id" as "
|
|
74
|
+
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
79
|
root_id: testUuid(10),
|
|
80
|
+
'root_$index_id': testUuid(10),
|
|
80
81
|
root_name: 'John doe',
|
|
81
82
|
},
|
|
82
83
|
],
|
|
@@ -147,19 +148,21 @@ test('can read same entity only over relation of some rows - many has many', asy
|
|
|
147
148
|
executes: [
|
|
148
149
|
{
|
|
149
150
|
sql:
|
|
150
|
-
SQL`select "root_"."title" as "root_title", "root_"."disclose_author" = ? as "
|
|
151
|
+
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"
|
|
151
152
|
from "public"."article" as "root_"`,
|
|
152
153
|
response: {
|
|
153
154
|
rows: [
|
|
154
155
|
{
|
|
155
156
|
root_id: testUuid(1),
|
|
157
|
+
'root_$key_id': testUuid(1),
|
|
156
158
|
root_title: 'Article A',
|
|
157
|
-
|
|
159
|
+
'root_$predicate_discloseAuthor_eq_true': true,
|
|
158
160
|
},
|
|
159
161
|
{
|
|
160
162
|
root_id: testUuid(2),
|
|
163
|
+
'root_$key_id': testUuid(2),
|
|
161
164
|
root_title: 'Article B',
|
|
162
|
-
|
|
165
|
+
'root_$predicate_discloseAuthor_eq_true': false,
|
|
163
166
|
},
|
|
164
167
|
],
|
|
165
168
|
},
|
|
@@ -53,9 +53,9 @@ test('row level predicate includes main predicate', async () => {
|
|
|
53
53
|
{
|
|
54
54
|
sql: SQL`SELECT
|
|
55
55
|
"root_"."id" AS "root_id",
|
|
56
|
-
TRUE
|
|
56
|
+
TRUE as "root_$predicate_isPublished_eq_true",
|
|
57
57
|
"root_"."title" AS "root_title",
|
|
58
|
-
"root_"."is_unlocked" = ?
|
|
58
|
+
"root_"."is_unlocked" = ? as "root_$predicate_and_isUnlocked_eq_true_isPubl",
|
|
59
59
|
"root_"."content" AS "root_content"
|
|
60
60
|
FROM "public"."article" AS "root_"
|
|
61
61
|
WHERE "root_"."is_published" = ?`,
|
|
@@ -64,16 +64,16 @@ test('row level predicate includes main predicate', async () => {
|
|
|
64
64
|
rows: [
|
|
65
65
|
{
|
|
66
66
|
root_id: testUuid(1),
|
|
67
|
-
|
|
67
|
+
'root_$predicate_isPublished_eq_true': true,
|
|
68
68
|
root_title: 'Hello',
|
|
69
|
-
|
|
69
|
+
'root_$predicate_and_isUnlocked_eq_true_isPubl': false,
|
|
70
70
|
root_content: 'Foo bar',
|
|
71
71
|
},
|
|
72
72
|
{
|
|
73
73
|
root_id: testUuid(2),
|
|
74
|
-
|
|
74
|
+
'root_$predicate_isPublished_eq_true': true,
|
|
75
75
|
root_title: 'Hello 2',
|
|
76
|
-
|
|
76
|
+
'root_$predicate_and_isUnlocked_eq_true_isPubl': true,
|
|
77
77
|
root_content: 'Lorem ipsum',
|
|
78
78
|
},
|
|
79
79
|
],
|
|
@@ -22,15 +22,17 @@ test('Categories with children filtered by back-referenced parent', async () =>
|
|
|
22
22
|
{
|
|
23
23
|
sql: SQL`select
|
|
24
24
|
"root_"."id" as "root_id",
|
|
25
|
-
"root_"."id" as "
|
|
25
|
+
"root_"."id" as "root_$key_id"
|
|
26
26
|
from "public"."category" as "root_"`,
|
|
27
27
|
response: {
|
|
28
28
|
rows: [
|
|
29
29
|
{
|
|
30
30
|
root_id: testUuid(1),
|
|
31
|
+
'root_$key_id': testUuid(1),
|
|
31
32
|
},
|
|
32
33
|
{
|
|
33
34
|
root_id: testUuid(2),
|
|
35
|
+
'root_$key_id': testUuid(2),
|
|
34
36
|
},
|
|
35
37
|
],
|
|
36
38
|
},
|
|
@@ -81,7 +81,7 @@ 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" = ?
|
|
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'],
|
|
@@ -92,7 +92,7 @@ test('aliases', async () => {
|
|
|
92
92
|
root_idx: testUuid(1),
|
|
93
93
|
root_name1: 'John',
|
|
94
94
|
root_name2: 'John',
|
|
95
|
-
|
|
95
|
+
'root_$predicate_name_eq': true,
|
|
96
96
|
},
|
|
97
97
|
],
|
|
98
98
|
},
|