@contember/engine-content-api 2.1.0-rc.2 → 2.1.0-rc.4
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/development/src/acl/PermissionFactory.cjs +5 -2
- package/dist/development/src/acl/PermissionFactory.cjs.map +1 -1
- package/dist/development/src/acl/PermissionFactory.js +5 -2
- package/dist/development/src/acl/PermissionFactory.js.map +1 -1
- package/dist/development/src/acl/PredicatesInjector.cjs +1 -68
- package/dist/development/src/acl/PredicatesInjector.cjs.map +1 -1
- package/dist/development/src/acl/PredicatesInjector.js +1 -68
- package/dist/development/src/acl/PredicatesInjector.js.map +1 -1
- package/dist/development/src/mapper/select/RelationFetcher.cjs +1 -1
- package/dist/development/src/mapper/select/RelationFetcher.cjs.map +1 -1
- package/dist/development/src/mapper/select/RelationFetcher.js +1 -1
- package/dist/development/src/mapper/select/RelationFetcher.js.map +1 -1
- package/dist/development/src/mapper/select/handlers/FieldsVisitor.cjs +6 -1
- package/dist/development/src/mapper/select/handlers/FieldsVisitor.cjs.map +1 -1
- package/dist/development/src/mapper/select/handlers/FieldsVisitor.js +6 -1
- package/dist/development/src/mapper/select/handlers/FieldsVisitor.js.map +1 -1
- package/dist/production/src/acl/PermissionFactory.cjs +5 -2
- package/dist/production/src/acl/PermissionFactory.cjs.map +1 -1
- package/dist/production/src/acl/PermissionFactory.js +5 -2
- package/dist/production/src/acl/PermissionFactory.js.map +1 -1
- package/dist/production/src/acl/PredicatesInjector.cjs +1 -68
- package/dist/production/src/acl/PredicatesInjector.cjs.map +1 -1
- package/dist/production/src/acl/PredicatesInjector.js +1 -68
- package/dist/production/src/acl/PredicatesInjector.js.map +1 -1
- package/dist/production/src/mapper/select/RelationFetcher.cjs +1 -1
- package/dist/production/src/mapper/select/RelationFetcher.cjs.map +1 -1
- package/dist/production/src/mapper/select/RelationFetcher.js +1 -1
- package/dist/production/src/mapper/select/RelationFetcher.js.map +1 -1
- package/dist/production/src/mapper/select/handlers/FieldsVisitor.cjs +6 -1
- package/dist/production/src/mapper/select/handlers/FieldsVisitor.cjs.map +1 -1
- package/dist/production/src/mapper/select/handlers/FieldsVisitor.js +6 -1
- package/dist/production/src/mapper/select/handlers/FieldsVisitor.js.map +1 -1
- package/dist/tests/src/test.d.ts +2 -1
- package/dist/tests/src/test.d.ts.map +1 -1
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/dist/types/acl/PermissionFactory.d.ts.map +1 -1
- package/dist/types/acl/PredicatesInjector.d.ts +0 -6
- package/dist/types/acl/PredicatesInjector.d.ts.map +1 -1
- package/dist/types/mapper/select/RelationFetcher.d.ts.map +1 -1
- package/dist/types/mapper/select/handlers/FieldsVisitor.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -9
- package/src/acl/PermissionFactory.ts +6 -2
- package/src/acl/PredicatesInjector.ts +1 -104
- package/src/mapper/select/RelationFetcher.ts +1 -3
- package/src/mapper/select/handlers/FieldsVisitor.ts +12 -1
- package/tests/cases/integration/graphQlRequests/query/formatting/dateFormat.test.ts +132 -1
- package/tests/cases/integration/graphQlRequests/query/pagination/hasManyLimit.test.ts +48 -2
- package/tests/cases/integration/graphQlRequests/query/relations/oneHasMany.test.ts +3 -3
- package/tests/cases/integration/graphQlRequests/query/sorting/randomSort.test.ts +1 -1
- package/tests/cases/unit/permissionMerger.test.ts +191 -0
- package/tests/cases/unit/predicatesInjector.test.ts +15 -67
- package/tests/src/test.ts +3 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contember/engine-content-api",
|
|
3
|
-
"version": "2.1.0-rc.
|
|
3
|
+
"version": "2.1.0-rc.4",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "./dist/production/index.js",
|
|
6
6
|
"typings": "./dist/types/index.d.ts",
|
|
@@ -26,17 +26,17 @@
|
|
|
26
26
|
"generate": "gql-gen --config graphql.codegen.yml"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@contember/database": "2.1.0-
|
|
30
|
-
"@contember/dic": "2.1.0-
|
|
31
|
-
"@contember/graphql-utils": "2.1.0-
|
|
32
|
-
"@contember/logger": "2.1.0-
|
|
33
|
-
"@contember/schema": "2.1.0-
|
|
34
|
-
"@contember/schema-definition": "2.1.0-
|
|
35
|
-
"@contember/schema-utils": "2.1.0-
|
|
29
|
+
"@contember/database": "2.1.0-rc.4",
|
|
30
|
+
"@contember/dic": "2.1.0-rc.4",
|
|
31
|
+
"@contember/graphql-utils": "2.1.0-rc.4",
|
|
32
|
+
"@contember/logger": "2.1.0-rc.4",
|
|
33
|
+
"@contember/schema": "2.1.0-rc.4",
|
|
34
|
+
"@contember/schema-definition": "2.1.0-rc.4",
|
|
35
|
+
"@contember/schema-utils": "2.1.0-rc.4",
|
|
36
36
|
"fast-deep-equal": "^3.1.3"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@contember/database-tester": "2.1.0-
|
|
39
|
+
"@contember/database-tester": "2.1.0-rc.4",
|
|
40
40
|
"@types/node": "^24.12.0",
|
|
41
41
|
"graphql": "^16.13.1",
|
|
42
42
|
"pg": "^8.20.0"
|
|
@@ -129,8 +129,12 @@ export class PermissionFactory {
|
|
|
129
129
|
private mergeEntityPermissions(left: Acl.EntityPermissions, right: Acl.EntityPermissions, includeThrough = false): Acl.EntityPermissions {
|
|
130
130
|
let predicates: Writable<Acl.PredicateMap> = {}
|
|
131
131
|
const operations: Writable<Acl.EntityOperations> = {}
|
|
132
|
-
|
|
133
|
-
|
|
132
|
+
// Three-state: unstated stays unstated so the role-level default still applies, an explicit `false` survives, and `true` wins across roles.
|
|
133
|
+
if (left.operations.customPrimary !== undefined || right.operations.customPrimary !== undefined) {
|
|
134
|
+
operations.customPrimary = (left.operations.customPrimary ?? false) || (right.operations.customPrimary ?? false)
|
|
135
|
+
}
|
|
136
|
+
if (left.operations.refreshMaterializedView !== undefined || right.operations.refreshMaterializedView !== undefined) {
|
|
137
|
+
operations.refreshMaterializedView = (left.operations.refreshMaterializedView ?? false) || (right.operations.refreshMaterializedView ?? false)
|
|
134
138
|
}
|
|
135
139
|
const noRoot: `${Acl.Operation}`[] = []
|
|
136
140
|
|
|
@@ -57,15 +57,7 @@ export class PredicatesInjector {
|
|
|
57
57
|
if (shouldSimplify) {
|
|
58
58
|
predicatesWhere = { [entity.primary]: { always: true } }
|
|
59
59
|
} else {
|
|
60
|
-
|
|
61
|
-
// Process the predicate to inject nested entity predicates
|
|
62
|
-
predicatesWhere = this.injectPredicatesToPredicate(
|
|
63
|
-
rawPredicate,
|
|
64
|
-
entity,
|
|
65
|
-
isBackReferenceContext ?? false,
|
|
66
|
-
ancestorPath ?? [],
|
|
67
|
-
isQueryRoot,
|
|
68
|
-
)
|
|
60
|
+
predicatesWhere = this.predicateFactory.create(entity, Acl.Operation.read, fieldNames, relationContext, isQueryRoot)
|
|
69
61
|
}
|
|
70
62
|
|
|
71
63
|
const and = [where, predicatesWhere].filter(it => Object.keys(it).length > 0)
|
|
@@ -78,101 +70,6 @@ export class PredicatesInjector {
|
|
|
78
70
|
return { and: and }
|
|
79
71
|
}
|
|
80
72
|
|
|
81
|
-
/**
|
|
82
|
-
* Processes a predicate and injects nested entity predicates for any relation traversals.
|
|
83
|
-
* This ensures that when a predicate like { department: { company: { name: 'Acme' } } }
|
|
84
|
-
* is used, the predicates of Department and Company are also applied.
|
|
85
|
-
*/
|
|
86
|
-
private injectPredicatesToPredicate(
|
|
87
|
-
where: Input.OptionalWhere,
|
|
88
|
-
entity: Model.Entity,
|
|
89
|
-
isBackReferenceContext: boolean,
|
|
90
|
-
ancestorPath: readonly Model.AnyRelationContext[],
|
|
91
|
-
isQueryRoot?: boolean,
|
|
92
|
-
): Input.OptionalWhere {
|
|
93
|
-
const resultWhere: Writable<Input.OptionalWhere> = {}
|
|
94
|
-
|
|
95
|
-
if (where.and) {
|
|
96
|
-
resultWhere.and = where.and
|
|
97
|
-
.filter((it): it is Input.Where => !!it)
|
|
98
|
-
.map(it => this.injectPredicatesToPredicate(it, entity, isBackReferenceContext, ancestorPath, isQueryRoot))
|
|
99
|
-
}
|
|
100
|
-
if (where.or) {
|
|
101
|
-
resultWhere.or = where.or
|
|
102
|
-
.filter((it): it is Input.Where => !!it)
|
|
103
|
-
.map(it => this.injectPredicatesToPredicate(it, entity, isBackReferenceContext, ancestorPath, isQueryRoot))
|
|
104
|
-
}
|
|
105
|
-
if (where.not) {
|
|
106
|
-
resultWhere.not = this.injectPredicatesToPredicate(where.not, entity, isBackReferenceContext, ancestorPath, isQueryRoot)
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const fields = Object.keys(where).filter(it => !['and', 'or', 'not'].includes(it))
|
|
110
|
-
|
|
111
|
-
for (const field of fields) {
|
|
112
|
-
resultWhere[field] = acceptFieldVisitor(this.schema, entity, field, {
|
|
113
|
-
visitColumn: () => where[field],
|
|
114
|
-
visitRelation: context => {
|
|
115
|
-
const relationWhere = where[field] as Input.OptionalWhere | null
|
|
116
|
-
if (relationWhere === null) {
|
|
117
|
-
return null
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// Check if this relation is a back-reference to somewhere in our ancestor path
|
|
121
|
-
const isBackReference = this.findBackReferencedAncestor(
|
|
122
|
-
ancestorPath,
|
|
123
|
-
context.relation.name,
|
|
124
|
-
context.entity.name,
|
|
125
|
-
) !== undefined
|
|
126
|
-
const nestedIsBackReferenceContext = isBackReference || isBackReferenceContext
|
|
127
|
-
const nestedAncestorPath: readonly Model.AnyRelationContext[] = [...ancestorPath, context]
|
|
128
|
-
|
|
129
|
-
// Recursively process the nested where (always do this to handle deeper nesting)
|
|
130
|
-
const processedNestedWhere = this.injectPredicatesToPredicate(
|
|
131
|
-
relationWhere,
|
|
132
|
-
context.targetEntity,
|
|
133
|
-
nestedIsBackReferenceContext,
|
|
134
|
-
nestedAncestorPath,
|
|
135
|
-
isQueryRoot,
|
|
136
|
-
)
|
|
137
|
-
|
|
138
|
-
// Check if we should simplify the target entity's predicate
|
|
139
|
-
const shouldSimplifyNested = nestedIsBackReferenceContext
|
|
140
|
-
&& this.findBackReferencedAncestor(nestedAncestorPath, context.relation.name, context.entity.name) !== undefined
|
|
141
|
-
|
|
142
|
-
// Get target entity's predicate (simplified if back-reference)
|
|
143
|
-
const targetPredicate = shouldSimplifyNested
|
|
144
|
-
? { [context.targetEntity.primary]: { always: true } }
|
|
145
|
-
: this.predicateFactory.create(context.targetEntity, Acl.Operation.read, undefined, context, isQueryRoot)
|
|
146
|
-
|
|
147
|
-
// Optimization: avoid duplicate { id: always } when both are simplified
|
|
148
|
-
const primaryKey = context.targetEntity.primary
|
|
149
|
-
const nestedIsAlwaysTrue = Object.keys(processedNestedWhere).length === 1
|
|
150
|
-
&& (processedNestedWhere as Record<string, unknown>)[primaryKey] !== undefined
|
|
151
|
-
&& (processedNestedWhere as Record<string, Record<string, unknown>>)[primaryKey]?.always === true
|
|
152
|
-
const targetIsAlwaysTrue = Object.keys(targetPredicate).length === 1
|
|
153
|
-
&& (targetPredicate as Record<string, unknown>)[primaryKey] !== undefined
|
|
154
|
-
&& (targetPredicate as Record<string, Record<string, unknown>>)[primaryKey]?.always === true
|
|
155
|
-
|
|
156
|
-
if (nestedIsAlwaysTrue && targetIsAlwaysTrue) {
|
|
157
|
-
return processedNestedWhere
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// Combine the processed nested where with target entity's predicate
|
|
161
|
-
const parts = [processedNestedWhere, targetPredicate].filter(it => Object.keys(it).length > 0)
|
|
162
|
-
if (parts.length === 0) {
|
|
163
|
-
return {}
|
|
164
|
-
}
|
|
165
|
-
if (parts.length === 1) {
|
|
166
|
-
return parts[0]
|
|
167
|
-
}
|
|
168
|
-
return { and: parts }
|
|
169
|
-
},
|
|
170
|
-
})
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
return resultWhere
|
|
174
|
-
}
|
|
175
|
-
|
|
176
73
|
private injectToWhere(
|
|
177
74
|
where: Input.OptionalWhere,
|
|
178
75
|
entity: Model.Entity,
|
|
@@ -162,9 +162,7 @@ export class RelationFetcher {
|
|
|
162
162
|
|
|
163
163
|
const primaryField = new FieldNode(targetEntity.primary, targetEntity.primary, {})
|
|
164
164
|
const inverseJoiningColumn = joiningColumns.targetColumn.columnName
|
|
165
|
-
const inverseIds = junctionValues
|
|
166
|
-
.map(it => it[inverseJoiningColumn])
|
|
167
|
-
.filter((it, index, arr) => arr.indexOf(it) === index)
|
|
165
|
+
const inverseIds = [...new Set(junctionValues.map(it => it[inverseJoiningColumn]))]
|
|
168
166
|
|
|
169
167
|
const queryWithWhere = objectNode
|
|
170
168
|
.withArgs({
|
|
@@ -32,7 +32,18 @@ export class FieldsVisitor implements Model.RelationByTypeVisitor<void>, Model.C
|
|
|
32
32
|
selectFrom += '::text'
|
|
33
33
|
}
|
|
34
34
|
if (column.type === Model.ColumnType.DateTime && this.settings.fullDateTimeResponse) {
|
|
35
|
-
|
|
35
|
+
if (this.settings.dateTimeResponseFormat === 'iso8601') {
|
|
36
|
+
// Format SQL-side to a valid ISO 8601 string (with "T" separator and "Z" suffix)
|
|
37
|
+
// instead of relying on JS Date, which would lose sub-second precision.
|
|
38
|
+
const format = `'YYYY-MM-DD"T"HH24:MI:SS.US"Z"'`
|
|
39
|
+
selectFrom = column.list
|
|
40
|
+
? `(select array_agg(to_char(elem AT TIME ZONE 'UTC', ${format}) order by ord) from unnest(${selectFrom}) with ordinality as t(elem, ord))`
|
|
41
|
+
: `to_char(${selectFrom} AT TIME ZONE 'UTC', ${format})`
|
|
42
|
+
} else {
|
|
43
|
+
// Legacy (backward-compatible) format: emit the raw PostgreSQL text
|
|
44
|
+
// representation, e.g. "2024-01-01 11:22:33.444444+00".
|
|
45
|
+
selectFrom += '::text'
|
|
46
|
+
}
|
|
36
47
|
}
|
|
37
48
|
if (column.type === Model.ColumnType.Enum && column.list) {
|
|
38
49
|
selectFrom += '::text[]'
|
|
@@ -1,10 +1,141 @@
|
|
|
1
1
|
import { test } from 'bun:test'
|
|
2
2
|
import { execute } from '../../../../../src/test'
|
|
3
|
-
import { SchemaBuilder } from '@contember/schema-definition'
|
|
3
|
+
import { SchemaBuilder, SchemaDefinition } from '@contember/schema-definition'
|
|
4
4
|
import { Model } from '@contember/schema'
|
|
5
5
|
import { GQL, SQL } from '../../../../../src/tags'
|
|
6
6
|
import { testUuid } from '../../../../../src/testUuid'
|
|
7
7
|
|
|
8
|
+
namespace DateTimeListModel {
|
|
9
|
+
export class Post {
|
|
10
|
+
publishedAt = SchemaDefinition.dateTimeColumn().list()
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
test('Format dateTime query with fullDateTimeResponse (legacy format, default)', async () => {
|
|
15
|
+
await execute({
|
|
16
|
+
schema: new SchemaBuilder()
|
|
17
|
+
.entity('Post', entity => entity.column('publishedAt', column => column.type(Model.ColumnType.DateTime)))
|
|
18
|
+
.buildSchema(),
|
|
19
|
+
settings: { content: { fullDateTimeResponse: true } },
|
|
20
|
+
query: GQL`
|
|
21
|
+
query {
|
|
22
|
+
getPost(by: {id: "${testUuid(1)}"}) {
|
|
23
|
+
publishedAt
|
|
24
|
+
}
|
|
25
|
+
}`,
|
|
26
|
+
executes: [
|
|
27
|
+
{
|
|
28
|
+
sql: SQL`select "root_"."published_at"::text as "root_publishedAt", "root_"."id" as "root_id"
|
|
29
|
+
from "public"."post" as "root_"
|
|
30
|
+
where "root_"."id" = ?`,
|
|
31
|
+
response: { rows: [{ root_id: testUuid(1), root_publishedAt: '2019-11-01 05:00:00.000000+00' }] },
|
|
32
|
+
parameters: [testUuid(1)],
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
return: {
|
|
36
|
+
data: {
|
|
37
|
+
getPost: {
|
|
38
|
+
publishedAt: '2019-11-01 05:00:00.000000+00',
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
})
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
test('Format dateTime query with fullDateTimeResponse (iso8601 format)', async () => {
|
|
46
|
+
await execute({
|
|
47
|
+
schema: new SchemaBuilder()
|
|
48
|
+
.entity('Post', entity => entity.column('publishedAt', column => column.type(Model.ColumnType.DateTime)))
|
|
49
|
+
.buildSchema(),
|
|
50
|
+
settings: { content: { fullDateTimeResponse: true, dateTimeResponseFormat: 'iso8601' } },
|
|
51
|
+
query: GQL`
|
|
52
|
+
query {
|
|
53
|
+
getPost(by: {id: "${testUuid(1)}"}) {
|
|
54
|
+
publishedAt
|
|
55
|
+
}
|
|
56
|
+
}`,
|
|
57
|
+
executes: [
|
|
58
|
+
{
|
|
59
|
+
sql:
|
|
60
|
+
SQL`select to_char("root_"."published_at" AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS.US"Z"') as "root_publishedAt", "root_"."id" as "root_id"
|
|
61
|
+
from "public"."post" as "root_"
|
|
62
|
+
where "root_"."id" = ?`,
|
|
63
|
+
response: { rows: [{ root_id: testUuid(1), root_publishedAt: '2019-11-01T05:00:00.000000Z' }] },
|
|
64
|
+
parameters: [testUuid(1)],
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
return: {
|
|
68
|
+
data: {
|
|
69
|
+
getPost: {
|
|
70
|
+
publishedAt: '2019-11-01T05:00:00.000000Z',
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
})
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
test('Format dateTime query with fullDateTimeResponse (iso8601, null value)', async () => {
|
|
78
|
+
await execute({
|
|
79
|
+
schema: new SchemaBuilder()
|
|
80
|
+
.entity('Post', entity => entity.column('publishedAt', column => column.type(Model.ColumnType.DateTime)))
|
|
81
|
+
.buildSchema(),
|
|
82
|
+
settings: { content: { fullDateTimeResponse: true, dateTimeResponseFormat: 'iso8601' } },
|
|
83
|
+
query: GQL`
|
|
84
|
+
query {
|
|
85
|
+
getPost(by: {id: "${testUuid(1)}"}) {
|
|
86
|
+
publishedAt
|
|
87
|
+
}
|
|
88
|
+
}`,
|
|
89
|
+
executes: [
|
|
90
|
+
{
|
|
91
|
+
sql:
|
|
92
|
+
SQL`select to_char("root_"."published_at" AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS.US"Z"') as "root_publishedAt", "root_"."id" as "root_id"
|
|
93
|
+
from "public"."post" as "root_"
|
|
94
|
+
where "root_"."id" = ?`,
|
|
95
|
+
response: { rows: [{ root_id: testUuid(1), root_publishedAt: null }] },
|
|
96
|
+
parameters: [testUuid(1)],
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
return: {
|
|
100
|
+
data: {
|
|
101
|
+
getPost: {
|
|
102
|
+
publishedAt: null,
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
})
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
test('Format dateTime[] query with fullDateTimeResponse (iso8601 list)', async () => {
|
|
110
|
+
await execute({
|
|
111
|
+
schema: SchemaDefinition.createModel(DateTimeListModel),
|
|
112
|
+
settings: { content: { fullDateTimeResponse: true, dateTimeResponseFormat: 'iso8601' } },
|
|
113
|
+
query: GQL`
|
|
114
|
+
query {
|
|
115
|
+
getPost(by: {id: "${testUuid(1)}"}) {
|
|
116
|
+
publishedAt
|
|
117
|
+
}
|
|
118
|
+
}`,
|
|
119
|
+
executes: [
|
|
120
|
+
{
|
|
121
|
+
sql:
|
|
122
|
+
SQL`select (select array_agg(to_char(elem AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS.US"Z"') order by ord) from unnest("root_"."published_at") with ordinality as t(elem, ord)) as "root_publishedAt", "root_"."id" as "root_id"
|
|
123
|
+
from "public"."post" as "root_"
|
|
124
|
+
where "root_"."id" = ?`,
|
|
125
|
+
response: { rows: [{ root_id: testUuid(1), root_publishedAt: ['2019-11-01T05:00:00.000000Z', '2020-01-15T08:30:00.000000Z'] }] },
|
|
126
|
+
parameters: [testUuid(1)],
|
|
127
|
+
},
|
|
128
|
+
],
|
|
129
|
+
return: {
|
|
130
|
+
data: {
|
|
131
|
+
getPost: {
|
|
132
|
+
publishedAt: ['2019-11-01T05:00:00.000000Z', '2020-01-15T08:30:00.000000Z'],
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
})
|
|
137
|
+
})
|
|
138
|
+
|
|
8
139
|
test('Format date query', async () => {
|
|
9
140
|
await execute({
|
|
10
141
|
schema: new SchemaBuilder()
|
|
@@ -55,7 +55,8 @@ test('many has many with where, limit and orderBy', async () => {
|
|
|
55
55
|
"data".*
|
|
56
56
|
from "data"
|
|
57
57
|
where
|
|
58
|
-
|
|
58
|
+
"data"."rowNumber_" > ? and "data"."rowNumber_" <= ?
|
|
59
|
+
order by "data"."rowNumber_" asc`,
|
|
59
60
|
parameters: [testUuid(1), testUuid(2), 'cs', 1, 3],
|
|
60
61
|
response: {
|
|
61
62
|
rows: [
|
|
@@ -173,7 +174,8 @@ test('one has many with where, limit and orderBy', async () => {
|
|
|
173
174
|
order by "root_"."title" asc, "root_"."id" asc)
|
|
174
175
|
select "data".*
|
|
175
176
|
from "data"
|
|
176
|
-
|
|
177
|
+
where "data"."rowNumber_" > ? and "data"."rowNumber_" <= ?
|
|
178
|
+
order by "data"."rowNumber_" asc`,
|
|
177
179
|
parameters: ['cs', testUuid(1), testUuid(2), 1, 3],
|
|
178
180
|
response: {
|
|
179
181
|
rows: [
|
|
@@ -216,3 +218,47 @@ test('one has many with where, limit and orderBy', async () => {
|
|
|
216
218
|
},
|
|
217
219
|
})
|
|
218
220
|
})
|
|
221
|
+
|
|
222
|
+
test('one has many with nulls first in a limited page', async () => {
|
|
223
|
+
await execute({
|
|
224
|
+
schema: new SchemaBuilder()
|
|
225
|
+
.entity('Author', entity => entity.oneHasMany('posts', relation => relation.target('Post', entity => entity.column('title')).ownedBy('author')))
|
|
226
|
+
.buildSchema(),
|
|
227
|
+
query: GQL`
|
|
228
|
+
query {
|
|
229
|
+
listAuthor {
|
|
230
|
+
posts(orderBy: [{title: ascNullsFirst}], limit: 1) {
|
|
231
|
+
id
|
|
232
|
+
title
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}`,
|
|
236
|
+
executes: [
|
|
237
|
+
{
|
|
238
|
+
sql: SQL`select "root_"."id" as "root_id", "root_"."id" as "root_id" from "public"."author" as "root_"`,
|
|
239
|
+
response: { rows: [{ root_id: testUuid(1) }] },
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
sql: SQL`with "data" as
|
|
243
|
+
(select "root_"."author_id" as "__grouping_key",
|
|
244
|
+
"root_"."id" as "root_id",
|
|
245
|
+
"root_"."title" as "root_title",
|
|
246
|
+
row_number() over(partition by "root_"."author_id"
|
|
247
|
+
order by "root_"."title" asc nulls first, "root_"."id" asc) as "rowNumber_"
|
|
248
|
+
from "public"."post" as "root_"
|
|
249
|
+
where "root_"."author_id" in (?)
|
|
250
|
+
order by "root_"."title" asc nulls first, "root_"."id" asc)
|
|
251
|
+
select "data".* from "data"
|
|
252
|
+
where "data"."rowNumber_" <= ?
|
|
253
|
+
order by "data"."rowNumber_" asc`,
|
|
254
|
+
parameters: [testUuid(1), 1],
|
|
255
|
+
response: { rows: [{ __grouping_key: testUuid(1), root_id: testUuid(2), root_title: null }] },
|
|
256
|
+
},
|
|
257
|
+
],
|
|
258
|
+
return: {
|
|
259
|
+
data: {
|
|
260
|
+
listAuthor: [{ posts: [{ id: testUuid(2), title: null }] }],
|
|
261
|
+
},
|
|
262
|
+
},
|
|
263
|
+
})
|
|
264
|
+
})
|
|
@@ -221,7 +221,7 @@ test('Posts with paginated comments (one has many)', async () => {
|
|
|
221
221
|
where "root_"."deleted_at" is null
|
|
222
222
|
and "root_"."post_id" in (?, ?)
|
|
223
223
|
order by "root_"."id" asc)
|
|
224
|
-
select "data".* from "data" where "data"."rowNumber_" <=
|
|
224
|
+
select "data".* from "data" where "data"."rowNumber_" <= ? order by "data"."rowNumber_" asc`,
|
|
225
225
|
parameters: [testUuid(1), testUuid(2), 1],
|
|
226
226
|
response: {
|
|
227
227
|
rows: [
|
|
@@ -375,7 +375,7 @@ test('Posts with paginated comments without count (one has many)', async () => {
|
|
|
375
375
|
where "root_"."deleted_at" is null
|
|
376
376
|
and "root_"."post_id" in (?, ?)
|
|
377
377
|
order by "root_"."id" asc)
|
|
378
|
-
select "data".* from "data" where "data"."rowNumber_" <=
|
|
378
|
+
select "data".* from "data" where "data"."rowNumber_" <= ? order by "data"."rowNumber_" asc`,
|
|
379
379
|
parameters: [testUuid(1), testUuid(2), 1],
|
|
380
380
|
response: {
|
|
381
381
|
rows: [
|
|
@@ -471,7 +471,7 @@ test('Posts with paginated comments (one has many)', async () => {
|
|
|
471
471
|
where "root_"."deleted_at" is null
|
|
472
472
|
and "root_"."post_id" in (?)
|
|
473
473
|
order by "root_"."id" asc)
|
|
474
|
-
select "data".* from "data" where "data"."rowNumber_" <=
|
|
474
|
+
select "data".* from "data" where "data"."rowNumber_" <= ? order by "data"."rowNumber_" asc`,
|
|
475
475
|
parameters: [testUuid(1), 1],
|
|
476
476
|
response: {
|
|
477
477
|
rows: [
|
|
@@ -136,7 +136,7 @@ test('sorts posts by random on has many relation', async () => {
|
|
|
136
136
|
inner join "rand_seed" on true
|
|
137
137
|
where "junction_"."category_id" in (?, ?)
|
|
138
138
|
order by random() asc)
|
|
139
|
-
select "data".* from "data" where "data"."rownumber_" <=
|
|
139
|
+
select "data".* from "data" where "data"."rownumber_" <= ? order by "data"."rownumber_" asc`,
|
|
140
140
|
parameters: [4555 / Math.pow(2, 31), testUuid(1), testUuid(2), 1],
|
|
141
141
|
response: {
|
|
142
142
|
rows: [
|
|
@@ -1007,3 +1007,194 @@ describe('Contextual permission merger', () => {
|
|
|
1007
1007
|
})
|
|
1008
1008
|
})
|
|
1009
1009
|
})
|
|
1010
|
+
|
|
1011
|
+
describe('Contextual permission merger - entity flags', () => {
|
|
1012
|
+
it('two roles: refreshMaterializedView is granted if any role grants it', () => {
|
|
1013
|
+
const result: Acl.Permissions = {
|
|
1014
|
+
Entity1: {
|
|
1015
|
+
operations: {
|
|
1016
|
+
refreshMaterializedView: true,
|
|
1017
|
+
read: {
|
|
1018
|
+
title: true,
|
|
1019
|
+
description: true,
|
|
1020
|
+
id: true,
|
|
1021
|
+
},
|
|
1022
|
+
},
|
|
1023
|
+
predicates: {},
|
|
1024
|
+
},
|
|
1025
|
+
}
|
|
1026
|
+
executeContextual({
|
|
1027
|
+
acl: {
|
|
1028
|
+
roles: {
|
|
1029
|
+
viewRole: {
|
|
1030
|
+
variables: {},
|
|
1031
|
+
entities: {
|
|
1032
|
+
Entity1: {
|
|
1033
|
+
predicates: {},
|
|
1034
|
+
operations: {
|
|
1035
|
+
refreshMaterializedView: true,
|
|
1036
|
+
read: { title: true },
|
|
1037
|
+
},
|
|
1038
|
+
},
|
|
1039
|
+
},
|
|
1040
|
+
},
|
|
1041
|
+
otherRole: {
|
|
1042
|
+
variables: {},
|
|
1043
|
+
entities: {
|
|
1044
|
+
Entity1: {
|
|
1045
|
+
predicates: {},
|
|
1046
|
+
operations: {
|
|
1047
|
+
read: { description: true },
|
|
1048
|
+
},
|
|
1049
|
+
},
|
|
1050
|
+
},
|
|
1051
|
+
},
|
|
1052
|
+
},
|
|
1053
|
+
},
|
|
1054
|
+
roles: ['viewRole', 'otherRole'],
|
|
1055
|
+
rootResult: result,
|
|
1056
|
+
allResult: result,
|
|
1057
|
+
})
|
|
1058
|
+
})
|
|
1059
|
+
|
|
1060
|
+
it('two roles: an explicit customPrimary and refreshMaterializedView denial survives the merge', () => {
|
|
1061
|
+
// A dropped `false` would not stay denied: Authorizator resolves the flags with `??`, so an absent
|
|
1062
|
+
// key falls back to the role-level default instead of denying.
|
|
1063
|
+
const result: Acl.Permissions = {
|
|
1064
|
+
Entity1: {
|
|
1065
|
+
operations: {
|
|
1066
|
+
customPrimary: false,
|
|
1067
|
+
refreshMaterializedView: false,
|
|
1068
|
+
read: {
|
|
1069
|
+
title: true,
|
|
1070
|
+
description: true,
|
|
1071
|
+
id: true,
|
|
1072
|
+
},
|
|
1073
|
+
},
|
|
1074
|
+
predicates: {},
|
|
1075
|
+
},
|
|
1076
|
+
}
|
|
1077
|
+
executeContextual({
|
|
1078
|
+
acl: {
|
|
1079
|
+
roles: {
|
|
1080
|
+
denyingRole: {
|
|
1081
|
+
variables: {},
|
|
1082
|
+
entities: {
|
|
1083
|
+
Entity1: {
|
|
1084
|
+
predicates: {},
|
|
1085
|
+
operations: {
|
|
1086
|
+
customPrimary: false,
|
|
1087
|
+
refreshMaterializedView: false,
|
|
1088
|
+
read: { title: true },
|
|
1089
|
+
},
|
|
1090
|
+
},
|
|
1091
|
+
},
|
|
1092
|
+
},
|
|
1093
|
+
otherRole: {
|
|
1094
|
+
variables: {},
|
|
1095
|
+
entities: {
|
|
1096
|
+
Entity1: {
|
|
1097
|
+
predicates: {},
|
|
1098
|
+
operations: {
|
|
1099
|
+
read: { description: true },
|
|
1100
|
+
},
|
|
1101
|
+
},
|
|
1102
|
+
},
|
|
1103
|
+
},
|
|
1104
|
+
},
|
|
1105
|
+
},
|
|
1106
|
+
roles: ['denyingRole', 'otherRole'],
|
|
1107
|
+
rootResult: result,
|
|
1108
|
+
allResult: result,
|
|
1109
|
+
})
|
|
1110
|
+
})
|
|
1111
|
+
|
|
1112
|
+
it('two roles: an explicit denial loses to another role granting the flag', () => {
|
|
1113
|
+
const result: Acl.Permissions = {
|
|
1114
|
+
Entity1: {
|
|
1115
|
+
operations: {
|
|
1116
|
+
customPrimary: true,
|
|
1117
|
+
refreshMaterializedView: true,
|
|
1118
|
+
read: {
|
|
1119
|
+
title: true,
|
|
1120
|
+
description: true,
|
|
1121
|
+
id: true,
|
|
1122
|
+
},
|
|
1123
|
+
},
|
|
1124
|
+
predicates: {},
|
|
1125
|
+
},
|
|
1126
|
+
}
|
|
1127
|
+
executeContextual({
|
|
1128
|
+
acl: {
|
|
1129
|
+
roles: {
|
|
1130
|
+
denyingRole: {
|
|
1131
|
+
variables: {},
|
|
1132
|
+
entities: {
|
|
1133
|
+
Entity1: {
|
|
1134
|
+
predicates: {},
|
|
1135
|
+
operations: {
|
|
1136
|
+
customPrimary: false,
|
|
1137
|
+
refreshMaterializedView: false,
|
|
1138
|
+
read: { title: true },
|
|
1139
|
+
},
|
|
1140
|
+
},
|
|
1141
|
+
},
|
|
1142
|
+
},
|
|
1143
|
+
grantingRole: {
|
|
1144
|
+
variables: {},
|
|
1145
|
+
entities: {
|
|
1146
|
+
Entity1: {
|
|
1147
|
+
predicates: {},
|
|
1148
|
+
operations: {
|
|
1149
|
+
customPrimary: true,
|
|
1150
|
+
refreshMaterializedView: true,
|
|
1151
|
+
read: { description: true },
|
|
1152
|
+
},
|
|
1153
|
+
},
|
|
1154
|
+
},
|
|
1155
|
+
},
|
|
1156
|
+
},
|
|
1157
|
+
},
|
|
1158
|
+
roles: ['denyingRole', 'grantingRole'],
|
|
1159
|
+
rootResult: result,
|
|
1160
|
+
allResult: result,
|
|
1161
|
+
})
|
|
1162
|
+
})
|
|
1163
|
+
|
|
1164
|
+
it('flags no role states stay absent, leaving the role-level default in charge', () => {
|
|
1165
|
+
const model: Model.Schema = new SchemaBuilder()
|
|
1166
|
+
.entity('Entity1', e => e.column('lorem').column('bar'))
|
|
1167
|
+
.buildSchema()
|
|
1168
|
+
const acl: Acl.Schema = {
|
|
1169
|
+
roles: {
|
|
1170
|
+
role1: {
|
|
1171
|
+
variables: {},
|
|
1172
|
+
entities: {
|
|
1173
|
+
Entity1: {
|
|
1174
|
+
predicates: {},
|
|
1175
|
+
operations: {
|
|
1176
|
+
read: { title: true },
|
|
1177
|
+
},
|
|
1178
|
+
},
|
|
1179
|
+
},
|
|
1180
|
+
},
|
|
1181
|
+
role2: {
|
|
1182
|
+
variables: {},
|
|
1183
|
+
entities: {
|
|
1184
|
+
Entity1: {
|
|
1185
|
+
predicates: {},
|
|
1186
|
+
operations: {
|
|
1187
|
+
read: { description: true },
|
|
1188
|
+
},
|
|
1189
|
+
},
|
|
1190
|
+
},
|
|
1191
|
+
},
|
|
1192
|
+
},
|
|
1193
|
+
}
|
|
1194
|
+
const { root, all } = new PermissionFactory().createContextual({ ...emptySchema, model, acl }, ['role1', 'role2'])
|
|
1195
|
+
|
|
1196
|
+
// Asserted on the key list, because a `customPrimary: undefined` would compare equal to an absent one.
|
|
1197
|
+
assert.deepStrictEqual(Object.keys(root.Entity1.operations), ['read'])
|
|
1198
|
+
assert.deepStrictEqual(Object.keys(all.Entity1.operations), ['read'])
|
|
1199
|
+
})
|
|
1200
|
+
})
|