@contember/engine-content-api 1.2.0-alpha.3 → 1.2.0-alpha.6
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/dist/src/acl/EvaluatedPredicateReplacer.d.ts +10 -0
- package/dist/src/acl/EvaluatedPredicateReplacer.d.ts.map +1 -0
- package/dist/src/acl/EvaluatedPredicateReplacer.js +40 -0
- package/dist/src/acl/EvaluatedPredicateReplacer.js.map +1 -0
- package/dist/src/acl/PredicateFactory.d.ts +4 -2
- package/dist/src/acl/PredicateFactory.d.ts.map +1 -1
- package/dist/src/acl/PredicateFactory.js +24 -6
- package/dist/src/acl/PredicateFactory.js.map +1 -1
- package/dist/src/acl/PredicatesInjector.d.ts +1 -1
- package/dist/src/acl/PredicatesInjector.d.ts.map +1 -1
- package/dist/src/acl/PredicatesInjector.js +14 -11
- package/dist/src/acl/PredicatesInjector.js.map +1 -1
- package/dist/src/acl/VariableInjector.d.ts +0 -1
- package/dist/src/acl/VariableInjector.d.ts.map +1 -1
- package/dist/src/acl/VariableInjector.js +4 -16
- package/dist/src/acl/VariableInjector.js.map +1 -1
- package/dist/src/acl/VariableUtils.d.ts +2 -13
- package/dist/src/acl/VariableUtils.d.ts.map +1 -1
- package/dist/src/acl/VariableUtils.js +6 -23
- package/dist/src/acl/VariableUtils.js.map +1 -1
- package/dist/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.js +1 -1
- package/dist/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.js.map +1 -1
- package/dist/src/extensions/paginatedHasMany/PaginatedHasManyCountVisitor.d.ts.map +1 -1
- package/dist/src/extensions/paginatedHasMany/PaginatedHasManyCountVisitor.js +25 -13
- package/dist/src/extensions/paginatedHasMany/PaginatedHasManyCountVisitor.js.map +1 -1
- package/dist/src/extensions/paginatedHasMany/PaginatedHasManyNodesVisitor.d.ts.map +1 -1
- package/dist/src/extensions/paginatedHasMany/PaginatedHasManyNodesVisitor.js +26 -13
- package/dist/src/extensions/paginatedHasMany/PaginatedHasManyNodesVisitor.js.map +1 -1
- package/dist/src/input-validation/EntityRulesResolver.js +3 -3
- package/dist/src/input-validation/EntityRulesResolver.js.map +1 -1
- package/dist/src/input-validation/ValidationContext.d.ts +2 -2
- package/dist/src/input-validation/ValidationContext.d.ts.map +1 -1
- package/dist/src/input-validation/ValidationContext.js.map +1 -1
- package/dist/src/input-validation/ValidationDataSelector.d.ts.map +1 -1
- package/dist/src/input-validation/ValidationDataSelector.js +1 -1
- package/dist/src/input-validation/ValidationDataSelector.js.map +1 -1
- package/dist/src/mapper/Mapper.d.ts +4 -4
- package/dist/src/mapper/Mapper.d.ts.map +1 -1
- package/dist/src/mapper/Mapper.js +7 -7
- package/dist/src/mapper/Mapper.js.map +1 -1
- package/dist/src/mapper/MapperContainer.d.ts.map +1 -1
- package/dist/src/mapper/MapperContainer.js +5 -2
- package/dist/src/mapper/MapperContainer.js.map +1 -1
- package/dist/src/mapper/select/RelationFetcher.d.ts +40 -5
- package/dist/src/mapper/select/RelationFetcher.d.ts.map +1 -1
- package/dist/src/mapper/select/RelationFetcher.js +19 -6
- package/dist/src/mapper/select/RelationFetcher.js.map +1 -1
- package/dist/src/mapper/select/WhereBuilder.d.ts +3 -1
- package/dist/src/mapper/select/WhereBuilder.d.ts.map +1 -1
- package/dist/src/mapper/select/WhereBuilder.js +4 -2
- package/dist/src/mapper/select/WhereBuilder.js.map +1 -1
- package/dist/src/mapper/select/handlers/FieldsVisitor.d.ts +2 -2
- package/dist/src/mapper/select/handlers/FieldsVisitor.d.ts.map +1 -1
- package/dist/src/mapper/select/handlers/FieldsVisitor.js +31 -18
- package/dist/src/mapper/select/handlers/FieldsVisitor.js.map +1 -1
- package/dist/src/mapper/select/optimizer/ConditionOptimizer.d.ts +5 -0
- package/dist/src/mapper/select/optimizer/ConditionOptimizer.d.ts.map +1 -0
- package/dist/src/mapper/select/optimizer/ConditionOptimizer.js +33 -0
- package/dist/src/mapper/select/optimizer/ConditionOptimizer.js.map +1 -0
- package/dist/src/mapper/select/optimizer/WhereOptimizer.d.ts +11 -0
- package/dist/src/mapper/select/optimizer/WhereOptimizer.d.ts.map +1 -0
- package/dist/src/mapper/select/optimizer/WhereOptimizer.js +57 -0
- package/dist/src/mapper/select/optimizer/WhereOptimizer.js.map +1 -0
- package/dist/src/mapper/select/optimizer/helpers.d.ts +10 -0
- package/dist/src/mapper/select/optimizer/helpers.d.ts.map +1 -0
- package/dist/src/mapper/select/optimizer/helpers.js +65 -0
- package/dist/src/mapper/select/optimizer/helpers.js.map +1 -0
- package/dist/src/resolvers/MutationResolver.js +1 -1
- package/dist/src/resolvers/MutationResolver.js.map +1 -1
- package/dist/src/resolvers/ReadHelpers.js +3 -3
- package/dist/src/resolvers/ReadHelpers.js.map +1 -1
- package/dist/src/resolvers/ReadResolver.js +2 -2
- package/dist/src/resolvers/ReadResolver.js.map +1 -1
- package/dist/src/tsconfig.tsbuildinfo +1 -1
- package/dist/tests/cases/integration/graphQlDb/insert/insertSequence.test.d.ts +2 -0
- package/dist/tests/cases/integration/graphQlDb/insert/insertSequence.test.d.ts.map +1 -0
- package/dist/tests/cases/integration/graphQlDb/insert/insertSequence.test.js +38 -0
- package/dist/tests/cases/integration/graphQlDb/insert/insertSequence.test.js.map +1 -0
- package/dist/tests/cases/integration/graphQlRequests/delete/aclDelete.test.js +1 -6
- package/dist/tests/cases/integration/graphQlRequests/delete/aclDelete.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/insert/acl/setField.test.js +2 -12
- package/dist/tests/cases/integration/graphQlRequests/insert/acl/setField.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/insert/aclInsert.test.js +1 -6
- package/dist/tests/cases/integration/graphQlRequests/insert/aclInsert.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/query/acl/fieldRestrictedByLocale.test.js +7 -26
- package/dist/tests/cases/integration/graphQlRequests/query/acl/fieldRestrictedByLocale.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/query/acl/nestedPredicate.test.js +1 -6
- package/dist/tests/cases/integration/graphQlRequests/query/acl/nestedPredicate.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/query/acl/predicateElimination.test.d.ts +2 -0
- package/dist/tests/cases/integration/graphQlRequests/query/acl/predicateElimination.test.d.ts.map +1 -0
- package/dist/tests/cases/integration/graphQlRequests/query/acl/predicateElimination.test.js +137 -0
- package/dist/tests/cases/integration/graphQlRequests/query/acl/predicateElimination.test.js.map +1 -0
- package/dist/tests/cases/integration/graphQlRequests/query/filter/complexCondition.test.js +1 -1
- package/dist/tests/cases/integration/graphQlRequests/query/filter/composedFilter.test.js +1 -1
- package/dist/tests/cases/integration/graphQlRequests/query/filter/composedFilter.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/query/relations/manyHasManyInverse.test.js +73 -0
- package/dist/tests/cases/integration/graphQlRequests/query/relations/manyHasManyInverse.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/query/relations/manyHasManyOwning.test.js +73 -0
- package/dist/tests/cases/integration/graphQlRequests/query/relations/manyHasManyOwning.test.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/update/acl/aclUpdate.test.js +6 -26
- package/dist/tests/cases/integration/graphQlRequests/update/acl/aclUpdate.test.js.map +1 -1
- package/dist/tests/cases/unit/aclVariablesFactory.test.js +4 -32
- package/dist/tests/cases/unit/aclVariablesFactory.test.js.map +1 -1
- package/dist/tests/cases/unit/conditionOptimizer.test.d.ts +2 -0
- package/dist/tests/cases/unit/conditionOptimizer.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/conditionOptimizer.test.js +113 -0
- package/dist/tests/cases/unit/conditionOptimizer.test.js.map +1 -0
- package/dist/tests/cases/unit/orderbyHelper.test.js +1 -0
- package/dist/tests/cases/unit/orderbyHelper.test.js.map +1 -1
- package/dist/tests/cases/unit/predicatesFactory.test.d.ts +2 -0
- package/dist/tests/cases/unit/predicatesFactory.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/predicatesFactory.test.js +103 -0
- package/dist/tests/cases/unit/predicatesFactory.test.js.map +1 -0
- package/dist/tests/cases/unit/predicatesInjector.test.js +9 -18
- package/dist/tests/cases/unit/predicatesInjector.test.js.map +1 -1
- package/dist/tests/cases/unit/variableInjector.test.js +2 -13
- package/dist/tests/cases/unit/variableInjector.test.js.map +1 -1
- package/dist/tests/cases/unit/whereOptimizer.test.d.ts +2 -0
- package/dist/tests/cases/unit/whereOptimizer.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/whereOptimizer.test.js +81 -0
- package/dist/tests/cases/unit/whereOptimizer.test.js.map +1 -0
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -10
- package/src/acl/EvaluatedPredicateReplacer.ts +38 -0
- package/src/acl/PredicateFactory.ts +30 -7
- package/src/acl/PredicatesInjector.ts +18 -10
- package/src/acl/VariableInjector.ts +2 -17
- package/src/acl/VariableUtils.ts +7 -28
- package/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.ts +3 -3
- package/src/extensions/paginatedHasMany/PaginatedHasManyCountVisitor.ts +26 -28
- package/src/extensions/paginatedHasMany/PaginatedHasManyNodesVisitor.ts +27 -31
- package/src/input-validation/EntityRulesResolver.ts +3 -3
- package/src/input-validation/ValidationContext.ts +2 -2
- package/src/input-validation/ValidationDataSelector.ts +2 -2
- package/src/mapper/Mapper.ts +10 -6
- package/src/mapper/MapperContainer.ts +7 -3
- package/src/mapper/select/RelationFetcher.ts +95 -34
- package/src/mapper/select/WhereBuilder.ts +5 -2
- package/src/mapper/select/handlers/FieldsVisitor.ts +31 -24
- package/src/mapper/select/optimizer/ConditionOptimizer.ts +35 -0
- package/src/mapper/select/optimizer/WhereOptimizer.ts +67 -0
- package/src/mapper/select/optimizer/helpers.ts +54 -0
- package/src/resolvers/MutationResolver.ts +1 -1
- package/src/resolvers/ReadHelpers.ts +3 -3
- package/src/resolvers/ReadResolver.ts +2 -2
- package/tests/cases/integration/graphQlDb/insert/insertSequence.test.ts +34 -0
- package/tests/cases/integration/graphQlRequests/delete/aclDelete.test.ts +1 -6
- package/tests/cases/integration/graphQlRequests/insert/acl/setField.test.ts +2 -12
- package/tests/cases/integration/graphQlRequests/insert/aclInsert.test.ts +1 -6
- package/tests/cases/integration/graphQlRequests/query/acl/fieldRestrictedByLocale.test.ts +7 -26
- package/tests/cases/integration/graphQlRequests/query/acl/nestedPredicate.test.ts +1 -6
- package/tests/cases/integration/graphQlRequests/query/acl/predicateElimination.test.ts +130 -0
- package/tests/cases/integration/graphQlRequests/query/filter/complexCondition.test.ts +1 -1
- package/tests/cases/integration/graphQlRequests/query/filter/composedFilter.test.ts +1 -1
- package/tests/cases/integration/graphQlRequests/query/relations/manyHasManyInverse.test.ts +74 -0
- package/tests/cases/integration/graphQlRequests/query/relations/manyHasManyOwning.test.ts +77 -0
- package/tests/cases/integration/graphQlRequests/update/acl/aclUpdate.test.ts +7 -27
- package/tests/cases/unit/aclVariablesFactory.test.ts +5 -34
- package/tests/cases/unit/conditionOptimizer.test.ts +129 -0
- package/tests/cases/unit/orderbyHelper.test.ts +1 -0
- package/tests/cases/unit/predicatesFactory.test.ts +97 -0
- package/tests/cases/unit/predicatesInjector.test.ts +9 -18
- package/tests/cases/unit/variableInjector.test.ts +2 -13
- package/tests/cases/unit/whereOptimizer.test.ts +77 -0
|
@@ -7,7 +7,7 @@ import { testUuid } from '../../../../../src/testUuid'
|
|
|
7
7
|
|
|
8
8
|
const schema = new SchemaBuilder()
|
|
9
9
|
.enum('locale', ['cs', 'en'])
|
|
10
|
-
.entity('Post', entityBuilder => entityBuilder.oneHasMany('locales', c => c.target('PostLocale')))
|
|
10
|
+
.entity('Post', entityBuilder => entityBuilder.oneHasMany('locales', c => c.target('PostLocale').ownedBy('post')))
|
|
11
11
|
.entity('PostLocale', entity =>
|
|
12
12
|
entity
|
|
13
13
|
.column('title', column => column.type(Model.ColumnType.String))
|
|
@@ -34,6 +34,7 @@ const permissions: Acl.Permissions = {
|
|
|
34
34
|
operations: {
|
|
35
35
|
read: {
|
|
36
36
|
id: true,
|
|
37
|
+
post: true,
|
|
37
38
|
title: 'localePredicate',
|
|
38
39
|
},
|
|
39
40
|
},
|
|
@@ -45,12 +46,7 @@ test('querying id and title', async () => {
|
|
|
45
46
|
schema: schema,
|
|
46
47
|
permissions: permissions,
|
|
47
48
|
variables: {
|
|
48
|
-
localeVariable: {
|
|
49
|
-
definition: {
|
|
50
|
-
type: Acl.VariableType.condition,
|
|
51
|
-
},
|
|
52
|
-
value: [{ in: ['cs'] }],
|
|
53
|
-
},
|
|
49
|
+
localeVariable: { in: ['cs'] },
|
|
54
50
|
},
|
|
55
51
|
query: GQL`
|
|
56
52
|
query {
|
|
@@ -126,12 +122,7 @@ test('querying with extra where', async () => {
|
|
|
126
122
|
schema: schema,
|
|
127
123
|
permissions: permissions,
|
|
128
124
|
variables: {
|
|
129
|
-
localeVariable: {
|
|
130
|
-
definition: {
|
|
131
|
-
type: Acl.VariableType.condition,
|
|
132
|
-
},
|
|
133
|
-
value: [{ in: ['cs'] }],
|
|
134
|
-
},
|
|
125
|
+
localeVariable: { in: ['cs'] },
|
|
135
126
|
},
|
|
136
127
|
query: GQL`
|
|
137
128
|
query {
|
|
@@ -177,12 +168,7 @@ test('querying only id', async () => {
|
|
|
177
168
|
schema: schema,
|
|
178
169
|
permissions: permissions,
|
|
179
170
|
variables: {
|
|
180
|
-
localeVariable: {
|
|
181
|
-
definition: {
|
|
182
|
-
type: Acl.VariableType.condition,
|
|
183
|
-
},
|
|
184
|
-
value: [{ in: ['cs'] }],
|
|
185
|
-
},
|
|
171
|
+
localeVariable: { in: ['cs'] },
|
|
186
172
|
},
|
|
187
173
|
query: GQL`
|
|
188
174
|
query {
|
|
@@ -254,12 +240,7 @@ test('querying on nested field', async () => {
|
|
|
254
240
|
schema: schema,
|
|
255
241
|
permissions: permissions,
|
|
256
242
|
variables: {
|
|
257
|
-
localeVariable: {
|
|
258
|
-
definition: {
|
|
259
|
-
type: Acl.VariableType.condition,
|
|
260
|
-
},
|
|
261
|
-
value: [{ in: ['cs'] }],
|
|
262
|
-
},
|
|
243
|
+
localeVariable: { in: ['cs'] },
|
|
263
244
|
},
|
|
264
245
|
query: GQL`
|
|
265
246
|
query {
|
|
@@ -294,7 +275,7 @@ test('querying on nested field', async () => {
|
|
|
294
275
|
"root_"."id" as "root_id",
|
|
295
276
|
case when "root_"."locale" in (?) then "root_"."title" else null end as "root_title"
|
|
296
277
|
from "public"."post_locale" as "root_"
|
|
297
|
-
where "root_"."post_id" in (?, ?)
|
|
278
|
+
where "root_"."post_id" in (?, ?)`,
|
|
298
279
|
parameters: ['cs', testUuid(1), testUuid(2)],
|
|
299
280
|
response: {
|
|
300
281
|
rows: [
|
|
@@ -58,12 +58,7 @@ test('querying post + author name', async () => {
|
|
|
58
58
|
schema: schema,
|
|
59
59
|
permissions: permissions,
|
|
60
60
|
variables: {
|
|
61
|
-
countryVariable: {
|
|
62
|
-
definition: {
|
|
63
|
-
type: Acl.VariableType.condition,
|
|
64
|
-
},
|
|
65
|
-
value: [{ in: ['Czechia'] }],
|
|
66
|
-
},
|
|
61
|
+
countryVariable: { in: ['Czechia'] },
|
|
67
62
|
},
|
|
68
63
|
query: GQL`
|
|
69
64
|
query {
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { SchemaDefinition as def } from '@contember/schema-definition'
|
|
2
|
+
import { Acl } from '@contember/schema'
|
|
3
|
+
import { test } from 'vitest'
|
|
4
|
+
import { execute } from '../../../../../src/test'
|
|
5
|
+
import { GQL, SQL } from '../../../../../src/tags'
|
|
6
|
+
import { testUuid } from '../../../../../src/testUuid'
|
|
7
|
+
|
|
8
|
+
namespace TestModel {
|
|
9
|
+
export class Author {
|
|
10
|
+
name = def.stringColumn()
|
|
11
|
+
isPublic = def.boolColumn().notNull()
|
|
12
|
+
image = def.manyHasOne(Image, 'authors')
|
|
13
|
+
}
|
|
14
|
+
export class Article {
|
|
15
|
+
title = def.stringColumn()
|
|
16
|
+
isPublic = def.boolColumn().notNull()
|
|
17
|
+
image = def.manyHasOne(Image, 'articles')
|
|
18
|
+
}
|
|
19
|
+
export class Image {
|
|
20
|
+
url = def.stringColumn().notNull()
|
|
21
|
+
|
|
22
|
+
articles = def.oneHasMany(Article, 'image')
|
|
23
|
+
authors = def.oneHasMany(Author, 'image')
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const permissions: Acl.Permissions = {
|
|
27
|
+
Author: {
|
|
28
|
+
predicates: {
|
|
29
|
+
authorPredicate: {
|
|
30
|
+
isPublic: { eq: true },
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
operations: {
|
|
34
|
+
read: {
|
|
35
|
+
id: 'authorPredicate',
|
|
36
|
+
name: 'authorPredicate',
|
|
37
|
+
image: 'authorPredicate',
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
Article: {
|
|
42
|
+
predicates: {
|
|
43
|
+
articlePredicate: {
|
|
44
|
+
isPublic: { eq: true },
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
operations: {
|
|
48
|
+
read: {
|
|
49
|
+
id: 'articlePredicate',
|
|
50
|
+
title: 'articlePredicate',
|
|
51
|
+
image: 'articlePredicate',
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
Image: {
|
|
56
|
+
predicates: {
|
|
57
|
+
imagePredicate: {
|
|
58
|
+
or: [
|
|
59
|
+
{ authors: { isPublic: { eq: true } } },
|
|
60
|
+
{ articles: { isPublic: { eq: true } } },
|
|
61
|
+
],
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
operations: {
|
|
65
|
+
read: {
|
|
66
|
+
id: 'imagePredicate',
|
|
67
|
+
url: 'imagePredicate',
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
test('predicate with OR', async () => {
|
|
74
|
+
await execute({
|
|
75
|
+
schema: def.createModel(TestModel),
|
|
76
|
+
permissions: permissions,
|
|
77
|
+
variables: {},
|
|
78
|
+
query: GQL`
|
|
79
|
+
query {
|
|
80
|
+
listAuthor {
|
|
81
|
+
id
|
|
82
|
+
image {
|
|
83
|
+
url
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}`,
|
|
87
|
+
executes: [
|
|
88
|
+
{
|
|
89
|
+
sql: SQL`SELECT "root_"."id" AS "root_id", "root_"."image_id" AS "root_image"
|
|
90
|
+
FROM "public"."author" AS "root_"
|
|
91
|
+
WHERE "root_"."is_public" = ?`,
|
|
92
|
+
parameters: [true],
|
|
93
|
+
response: {
|
|
94
|
+
rows: [
|
|
95
|
+
{
|
|
96
|
+
root_id: testUuid(1),
|
|
97
|
+
root_image: testUuid(2),
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
},
|
|
101
|
+
},
|
|
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 (?)`,
|
|
104
|
+
parameters: [testUuid(2)],
|
|
105
|
+
response: {
|
|
106
|
+
rows: [
|
|
107
|
+
{
|
|
108
|
+
root_id: testUuid(2),
|
|
109
|
+
root_url: 'abcd',
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
return: {
|
|
116
|
+
data: {
|
|
117
|
+
listAuthor: [
|
|
118
|
+
{
|
|
119
|
+
id: testUuid(1),
|
|
120
|
+
image: {
|
|
121
|
+
url: 'abcd',
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
})
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
|
|
@@ -25,7 +25,7 @@ test('Complex condition', async () => {
|
|
|
25
25
|
{
|
|
26
26
|
sql: SQL`select "root_"."id" as "root_id"
|
|
27
27
|
from "public"."post" as "root_"
|
|
28
|
-
where (
|
|
28
|
+
where ("root_"."title" = ? or "root_"."title" = ?
|
|
29
29
|
or not("root_"."title" < ?)
|
|
30
30
|
or "root_"."title" is null and not("root_"."title" is null))`,
|
|
31
31
|
parameters: ['A', 'B', 'X'],
|
|
@@ -19,7 +19,7 @@ test('Composed filter with nulls', async () => {
|
|
|
19
19
|
`,
|
|
20
20
|
executes: [
|
|
21
21
|
{
|
|
22
|
-
sql: SQL`select "root_"."id" as "root_id" from "public"."post" as "root_" where
|
|
22
|
+
sql: SQL`select "root_"."id" as "root_id" from "public"."post" as "root_" where "root_"."title" = ?`,
|
|
23
23
|
parameters: ['John'],
|
|
24
24
|
response: { rows: [{ root_id: testUuid(1) }] },
|
|
25
25
|
},
|
|
@@ -171,3 +171,77 @@ test('empty many-has-many inverse relation', async () => {
|
|
|
171
171
|
})
|
|
172
172
|
|
|
173
173
|
|
|
174
|
+
test('Posts with filtered tags', async () => {
|
|
175
|
+
await execute({
|
|
176
|
+
schema: new SchemaBuilder()
|
|
177
|
+
.entity('Post', entity => entity)
|
|
178
|
+
.entity('Tag', entity => entity.column('name').manyHasMany('posts', relation => relation.target('Post').inversedBy('tags')))
|
|
179
|
+
.buildSchema(),
|
|
180
|
+
query: GQL`
|
|
181
|
+
query {
|
|
182
|
+
listPost {
|
|
183
|
+
id
|
|
184
|
+
tags(filter: {name: {eq: "Foo"}}) {
|
|
185
|
+
name
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
`,
|
|
190
|
+
executes: [
|
|
191
|
+
{
|
|
192
|
+
sql: SQL`select "root_"."id" as "root_id",
|
|
193
|
+
"root_"."id" as "root_id"
|
|
194
|
+
from "public"."post" as "root_"`,
|
|
195
|
+
response: {
|
|
196
|
+
rows: [{ root_id: testUuid(1) }, { root_id: testUuid(2) }],
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
sql: SQL`select "junction_"."post_id", "junction_"."tag_id" from "public"."tag_posts" as "junction_" inner join "public"."tag" as "root_" on "junction_"."tag_id" = "root_"."id" where "junction_"."post_id" in (?, ?) and "root_"."name" = ?`,
|
|
201
|
+
parameters: [testUuid(1), testUuid(2), 'Foo'],
|
|
202
|
+
response: {
|
|
203
|
+
rows: [
|
|
204
|
+
{ post_id: testUuid(1), tag_id: testUuid(3) },
|
|
205
|
+
{ post_id: testUuid(2), tag_id: testUuid(3) },
|
|
206
|
+
],
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
sql: SQL`
|
|
211
|
+
select "root_"."name" as "root_name",
|
|
212
|
+
"root_"."id" as "root_id"
|
|
213
|
+
from "public"."tag" as "root_"
|
|
214
|
+
where "root_"."id" in (?)`,
|
|
215
|
+
parameters: [testUuid(3)],
|
|
216
|
+
response: {
|
|
217
|
+
rows: [
|
|
218
|
+
{ root_id: testUuid(3), root_name: 'foo' },
|
|
219
|
+
],
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
],
|
|
223
|
+
return: {
|
|
224
|
+
data: {
|
|
225
|
+
listPost: [
|
|
226
|
+
{
|
|
227
|
+
id: testUuid(1),
|
|
228
|
+
tags: [
|
|
229
|
+
{
|
|
230
|
+
name: 'foo',
|
|
231
|
+
},
|
|
232
|
+
],
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
id: testUuid(2),
|
|
236
|
+
tags: [
|
|
237
|
+
{
|
|
238
|
+
name: 'foo',
|
|
239
|
+
},
|
|
240
|
+
],
|
|
241
|
+
},
|
|
242
|
+
],
|
|
243
|
+
},
|
|
244
|
+
},
|
|
245
|
+
})
|
|
246
|
+
})
|
|
247
|
+
|
|
@@ -4,6 +4,83 @@ import { SchemaBuilder } from '@contember/schema-definition'
|
|
|
4
4
|
import { GQL, SQL } from '../../../../../src/tags'
|
|
5
5
|
import { testUuid } from '../../../../../src/testUuid'
|
|
6
6
|
|
|
7
|
+
|
|
8
|
+
test('Posts with filtered tags', async () => {
|
|
9
|
+
await execute({
|
|
10
|
+
schema: new SchemaBuilder()
|
|
11
|
+
.entity('Post', entity => entity.manyHasMany('tags', relation => relation.target('Tag')))
|
|
12
|
+
.entity('Tag', entity => entity.column('name'))
|
|
13
|
+
.buildSchema(),
|
|
14
|
+
query: GQL`
|
|
15
|
+
query {
|
|
16
|
+
listPost {
|
|
17
|
+
id
|
|
18
|
+
tags(filter: {name: {eq: "Foo"}}) {
|
|
19
|
+
name
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
`,
|
|
24
|
+
executes: [
|
|
25
|
+
{
|
|
26
|
+
sql: SQL`select "root_"."id" as "root_id",
|
|
27
|
+
"root_"."id" as "root_id"
|
|
28
|
+
from "public"."post" as "root_"`,
|
|
29
|
+
response: {
|
|
30
|
+
rows: [{ root_id: testUuid(1) }, { root_id: testUuid(2) }],
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
sql: SQL`select "junction_"."tag_id", "junction_"."post_id" from "public"."post_tags" as "junction_" inner join "public"."tag" as "root_" on "junction_"."tag_id" = "root_"."id" where "junction_"."post_id" in (?, ?) and "root_"."name" = ?`,
|
|
35
|
+
parameters: [testUuid(1), testUuid(2), 'Foo'],
|
|
36
|
+
response: {
|
|
37
|
+
rows: [
|
|
38
|
+
{ post_id: testUuid(1), tag_id: testUuid(3) },
|
|
39
|
+
{ post_id: testUuid(2), tag_id: testUuid(3) },
|
|
40
|
+
],
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
sql: SQL`
|
|
45
|
+
select "root_"."name" as "root_name",
|
|
46
|
+
"root_"."id" as "root_id"
|
|
47
|
+
from "public"."tag" as "root_"
|
|
48
|
+
where "root_"."id" in (?)`,
|
|
49
|
+
parameters: [testUuid(3)],
|
|
50
|
+
response: {
|
|
51
|
+
rows: [
|
|
52
|
+
{ root_id: testUuid(3), root_name: 'foo' },
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
return: {
|
|
58
|
+
data: {
|
|
59
|
+
listPost: [
|
|
60
|
+
{
|
|
61
|
+
id: testUuid(1),
|
|
62
|
+
tags: [
|
|
63
|
+
{
|
|
64
|
+
name: 'foo',
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
id: testUuid(2),
|
|
70
|
+
tags: [
|
|
71
|
+
{
|
|
72
|
+
name: 'foo',
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
})
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
7
84
|
test('Posts with paginated tags (many has many owning)', async () => {
|
|
8
85
|
await execute({
|
|
9
86
|
schema: new SchemaBuilder()
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { test } from 'vitest'
|
|
2
2
|
import { execute, failedTransaction, sqlTransaction } from '../../../../../src/test'
|
|
3
3
|
import { SchemaBuilder } from '@contember/schema-definition'
|
|
4
|
-
import {
|
|
4
|
+
import { Model } from '@contember/schema'
|
|
5
5
|
import { GQL, SQL } from '../../../../../src/tags'
|
|
6
6
|
import { testUuid } from '../../../../../src/testUuid'
|
|
7
7
|
|
|
@@ -35,12 +35,7 @@ test('update name', async () => {
|
|
|
35
35
|
},
|
|
36
36
|
},
|
|
37
37
|
variables: {
|
|
38
|
-
name_variable: {
|
|
39
|
-
definition: {
|
|
40
|
-
type: Acl.VariableType.condition,
|
|
41
|
-
},
|
|
42
|
-
value: [{ in: ['John', 'Jack'] }],
|
|
43
|
-
},
|
|
38
|
+
name_variable: { in: ['John', 'Jack'] },
|
|
44
39
|
},
|
|
45
40
|
executes: [
|
|
46
41
|
...sqlTransaction([
|
|
@@ -103,12 +98,7 @@ test('update name - denied', async () => {
|
|
|
103
98
|
},
|
|
104
99
|
},
|
|
105
100
|
variables: {
|
|
106
|
-
name_variable: {
|
|
107
|
-
definition: {
|
|
108
|
-
type: Acl.VariableType.condition,
|
|
109
|
-
},
|
|
110
|
-
value: [{ in: ['John', 'Jack'] }],
|
|
111
|
-
},
|
|
101
|
+
name_variable: { in: ['John', 'Jack'] },
|
|
112
102
|
},
|
|
113
103
|
executes: [
|
|
114
104
|
...failedTransaction([
|
|
@@ -123,10 +113,10 @@ test('update name - denied', async () => {
|
|
|
123
113
|
? :: text as "name",
|
|
124
114
|
"root_"."id"
|
|
125
115
|
from "public"."author" as "root_"
|
|
126
|
-
where
|
|
116
|
+
where false) update "public"."author"
|
|
127
117
|
set "name" = "newData_"."name" from "newData_"
|
|
128
118
|
where "author"."id" = "newData_"."id" and false`,
|
|
129
|
-
parameters: ['John'
|
|
119
|
+
parameters: ['John'],
|
|
130
120
|
response: 0,
|
|
131
121
|
},
|
|
132
122
|
]),
|
|
@@ -186,18 +176,8 @@ test('update m:n', async () => {
|
|
|
186
176
|
},
|
|
187
177
|
},
|
|
188
178
|
variables: {
|
|
189
|
-
post_name_variable: {
|
|
190
|
-
|
|
191
|
-
type: Acl.VariableType.condition,
|
|
192
|
-
},
|
|
193
|
-
value: [{ in: ['Lorem ipsum', 'Dolor sit'] }],
|
|
194
|
-
},
|
|
195
|
-
category_name_variable: {
|
|
196
|
-
definition: {
|
|
197
|
-
type: Acl.VariableType.condition,
|
|
198
|
-
},
|
|
199
|
-
value: [{ in: ['foo', 'bar'] }],
|
|
200
|
-
},
|
|
179
|
+
post_name_variable: { in: ['Lorem ipsum', 'Dolor sit'] },
|
|
180
|
+
category_name_variable: { in: ['foo', 'bar'] },
|
|
201
181
|
},
|
|
202
182
|
query: GQL`mutation {
|
|
203
183
|
updatePost(by: {id: "${testUuid(1)}"}, data: {categories: [
|
|
@@ -18,12 +18,8 @@ describe('create acl variables', () => {
|
|
|
18
18
|
},
|
|
19
19
|
},
|
|
20
20
|
},
|
|
21
|
-
}, {
|
|
22
|
-
|
|
23
|
-
personId: null,
|
|
24
|
-
memberships: [{ role: 'author', variables: [{ name: 'authorID', values: [testUuid(2)] }] }],
|
|
25
|
-
}), {
|
|
26
|
-
author__authorID: { definition, value: [testUuid(2)] },
|
|
21
|
+
}, [{ role: 'author', variables: [{ name: 'authorID', condition: { in: [testUuid(2)] } }] }]), {
|
|
22
|
+
author__authorID: { in: [testUuid(2)] },
|
|
27
23
|
})
|
|
28
24
|
})
|
|
29
25
|
|
|
@@ -39,34 +35,9 @@ describe('create acl variables', () => {
|
|
|
39
35
|
entities: {},
|
|
40
36
|
},
|
|
41
37
|
},
|
|
42
|
-
}, {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
memberships: [{ role: 'author', variables: [] }],
|
|
46
|
-
}), {
|
|
47
|
-
author__authorID: { definition, value: [] },
|
|
48
|
-
})
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
it('predefined', () => {
|
|
53
|
-
const definition: Acl.PredefinedVariable = { type: Acl.VariableType.predefined, value: 'identityID' }
|
|
54
|
-
assert.deepStrictEqual(createAclVariables({
|
|
55
|
-
roles: {
|
|
56
|
-
author: {
|
|
57
|
-
stages: '*',
|
|
58
|
-
variables: {
|
|
59
|
-
authorIdentity: definition,
|
|
60
|
-
},
|
|
61
|
-
entities: {},
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
}, {
|
|
65
|
-
identityId: testUuid(1),
|
|
66
|
-
personId: null,
|
|
67
|
-
memberships: [{ role: 'author', variables: [] }],
|
|
68
|
-
}), {
|
|
69
|
-
author__authorIdentity: { definition, value: [testUuid(1)] },
|
|
38
|
+
}, [{ role: 'author', variables: [] }],
|
|
39
|
+
), {
|
|
40
|
+
author__authorID: { never: true },
|
|
70
41
|
})
|
|
71
42
|
})
|
|
72
43
|
})
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { describe, it, assert } from 'vitest'
|
|
2
|
+
import { ConditionOptimizer } from '../../../src/mapper/select/optimizer/ConditionOptimizer'
|
|
3
|
+
|
|
4
|
+
describe('condition optimizer', () => {
|
|
5
|
+
const optimizer = new ConditionOptimizer()
|
|
6
|
+
|
|
7
|
+
it('remove OR when only 1', () => {
|
|
8
|
+
assert.deepStrictEqual(optimizer.optimize({
|
|
9
|
+
or: [{ eq: 1 }],
|
|
10
|
+
}), { eq: 1 })
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
it('keep OR when > 1', () => {
|
|
14
|
+
assert.deepStrictEqual(optimizer.optimize({
|
|
15
|
+
or: [{ eq: 1 }, { eq: 2 }],
|
|
16
|
+
}), {
|
|
17
|
+
or: [{ eq: 1 }, { eq: 2 }],
|
|
18
|
+
})
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
it('optimizes OR with never', () => {
|
|
22
|
+
assert.deepStrictEqual(optimizer.optimize({
|
|
23
|
+
or: [{ eq: 1 }, { never: true }],
|
|
24
|
+
}), { eq: 1 })
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
it('optimizes OR with always', () => {
|
|
28
|
+
assert.deepStrictEqual(optimizer.optimize({
|
|
29
|
+
or: [{ eq: 1 }, { always: true }],
|
|
30
|
+
}), true)
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it('optimizes AND with never', () => {
|
|
34
|
+
assert.deepStrictEqual(optimizer.optimize({
|
|
35
|
+
and: [{ eq: 1 }, { never: true }],
|
|
36
|
+
}), false)
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
it('optimizes AND with always', () => {
|
|
40
|
+
assert.deepStrictEqual(optimizer.optimize({
|
|
41
|
+
and: [{ eq: 1 }, { always: true }],
|
|
42
|
+
}), { eq: 1 })
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('optimizes NOT with never', () => {
|
|
46
|
+
assert.deepStrictEqual(optimizer.optimize({
|
|
47
|
+
not: { never: true },
|
|
48
|
+
}), true)
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
it('optimizes NOT with always', () => {
|
|
52
|
+
assert.deepStrictEqual(optimizer.optimize({
|
|
53
|
+
not: { always: true },
|
|
54
|
+
}), false)
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
it('optimizes empty AND', () => {
|
|
58
|
+
assert.deepStrictEqual(optimizer.optimize({
|
|
59
|
+
and: [],
|
|
60
|
+
}), {})
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('optimizes empty OR', () => {
|
|
64
|
+
assert.deepStrictEqual(optimizer.optimize({
|
|
65
|
+
or: [],
|
|
66
|
+
}), {})
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
it('flattens AND', () => {
|
|
71
|
+
assert.deepStrictEqual(optimizer.optimize({
|
|
72
|
+
eq: 0,
|
|
73
|
+
and: [
|
|
74
|
+
{ eq: 1 },
|
|
75
|
+
{
|
|
76
|
+
eq: 2,
|
|
77
|
+
and: [
|
|
78
|
+
{ eq: 3 },
|
|
79
|
+
{
|
|
80
|
+
eq: 4,
|
|
81
|
+
and: [{ eq: 5 }, { eq: 6 }],
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
}), { and: [{ eq: 0 }, { eq: 1 }, { eq: 2 }, { eq: 3 }, { eq: 4 }, { eq: 5 }, { eq: 6 }] })
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
it('flattens OR', () => {
|
|
90
|
+
assert.deepStrictEqual(optimizer.optimize({
|
|
91
|
+
or: [
|
|
92
|
+
{ eq: 1 },
|
|
93
|
+
{
|
|
94
|
+
|
|
95
|
+
or: [
|
|
96
|
+
{ eq: 2 },
|
|
97
|
+
{ or: [{ eq: 3 }, { eq: 4 }] },
|
|
98
|
+
],
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
}), { or: [{ eq: 1 }, { eq: 2 }, { eq: 3 }, { eq: 4 }] })
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
it('flattens NOT', () => {
|
|
105
|
+
assert.deepStrictEqual(optimizer.optimize({
|
|
106
|
+
not: { not: { not: { eq: 1 } } },
|
|
107
|
+
}), { not: { eq: 1 } })
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
it('combine AND and OR', () => {
|
|
111
|
+
assert.deepStrictEqual(optimizer.optimize({
|
|
112
|
+
or: [
|
|
113
|
+
{ and: [{ eq: 1 }, { eq: 2 }] },
|
|
114
|
+
{ and: [{ eq: 3 }, { eq: 4 }], eq: 5 },
|
|
115
|
+
],
|
|
116
|
+
}), { or: [
|
|
117
|
+
{ and: [{ eq: 1 }, { eq: 2 }] },
|
|
118
|
+
{ and: [{ eq: 3 }, { eq: 4 }, { eq: 5 }] },
|
|
119
|
+
] })
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
it('remove conditions with null value', () => {
|
|
123
|
+
assert.deepStrictEqual(optimizer.optimize({ eq: null }), {})
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
it('remove conditions with undefined value', () => {
|
|
127
|
+
assert.deepStrictEqual(optimizer.optimize({ eq: undefined }), {})
|
|
128
|
+
})
|
|
129
|
+
})
|