@contember/engine-content-api 2.1.0-rc.6 → 2.1.0-rc.8
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/internalColumnAliases.test.d.ts +2 -0
- package/dist/tests/cases/integration/graphQlRequests/query/acl/internalColumnAliases.test.d.ts.map +1 -0
- package/dist/tests/cases/integration/graphQlRequests/query/acl/mergedRolePredicate.test.d.ts +2 -0
- package/dist/tests/cases/integration/graphQlRequests/query/acl/mergedRolePredicate.test.d.ts.map +1 -0
- 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/internalColumnAliases.test.d.ts +2 -0
- package/dist/tests/cases/unit/internalColumnAliases.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/internalColumnAliases.test.ts +326 -0
- package/tests/cases/integration/graphQlRequests/query/acl/mergedRolePredicate.test.ts +124 -0
- 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/internalColumnAliases.test.ts +41 -0
- 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
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.8",
|
|
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-rc.
|
|
30
|
-
"@contember/dic": "2.1.0-rc.
|
|
31
|
-
"@contember/graphql-utils": "2.1.0-rc.
|
|
32
|
-
"@contember/logger": "2.1.0-rc.
|
|
33
|
-
"@contember/schema": "2.1.0-rc.
|
|
34
|
-
"@contember/schema-definition": "2.1.0-rc.
|
|
35
|
-
"@contember/schema-utils": "2.1.0-rc.
|
|
29
|
+
"@contember/database": "2.1.0-rc.8",
|
|
30
|
+
"@contember/dic": "2.1.0-rc.8",
|
|
31
|
+
"@contember/graphql-utils": "2.1.0-rc.8",
|
|
32
|
+
"@contember/logger": "2.1.0-rc.8",
|
|
33
|
+
"@contember/schema": "2.1.0-rc.8",
|
|
34
|
+
"@contember/schema-definition": "2.1.0-rc.8",
|
|
35
|
+
"@contember/schema-utils": "2.1.0-rc.8",
|
|
36
36
|
"fast-deep-equal": "^3.1.3"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@contember/database-tester": "2.1.0-rc.
|
|
39
|
+
"@contember/database-tester": "2.1.0-rc.8",
|
|
40
40
|
"@types/node": "^24.12.0",
|
|
41
41
|
"graphql": "^16.13.1",
|
|
42
42
|
"pg": "^8.20.0"
|
package/src/mapper/ErrorUtils.ts
CHANGED
|
@@ -142,13 +142,23 @@ export const convertError = (
|
|
|
142
142
|
if (e instanceof Database.TransactionAbortedError) {
|
|
143
143
|
return new MutationSqlError([], e.originalMessage, [MutationResultHint.subSequentSqlError])
|
|
144
144
|
}
|
|
145
|
-
if (e instanceof Database.
|
|
145
|
+
if (e instanceof Database.CannotCommitError) {
|
|
146
146
|
logger.error(e, { loc: 'convertError' })
|
|
147
147
|
return new MutationSqlError([], e.originalMessage, [MutationResultHint.sqlError])
|
|
148
148
|
}
|
|
149
|
+
if (e instanceof Database.QueryError) {
|
|
150
|
+
logger.error(e, { loc: 'convertError' })
|
|
151
|
+
const message = hasClientFacingMessage(e.code) ? e.originalMessage : 'Database query failed'
|
|
152
|
+
return new MutationSqlError([], message, [MutationResultHint.sqlError])
|
|
153
|
+
}
|
|
149
154
|
throw e
|
|
150
155
|
}
|
|
151
156
|
|
|
157
|
+
// Data (22) and integrity (23) errors and project trigger exceptions (P0001) carry messages clients act on. Other
|
|
158
|
+
// messages (e.g. class 42) can quote internal SQL identifiers, which embed ACL predicate names.
|
|
159
|
+
const hasClientFacingMessage = (code: string | undefined): boolean =>
|
|
160
|
+
code !== undefined && (code.startsWith('22') || code.startsWith('23') || code === 'P0001')
|
|
161
|
+
|
|
152
162
|
export const tryMutation = async (
|
|
153
163
|
schema: Model.Schema,
|
|
154
164
|
databaseMetadata: DatabaseMetadata,
|
package/src/mapper/Mapper.ts
CHANGED
|
@@ -75,7 +75,7 @@ export class Mapper<ConnectionType extends Connection.ConnectionLike = Connectio
|
|
|
75
75
|
): Promise<SelectIndexedResultObjects> {
|
|
76
76
|
const hydrator = new SelectHydrator()
|
|
77
77
|
const path = this.pathFactory.create([])
|
|
78
|
-
const indexByAlias: string = path.for(indexBy).alias
|
|
78
|
+
const indexByAlias: string = path.forInternal('index').for(indexBy).alias
|
|
79
79
|
const qb: SelectBuilder = SelectBuilder.create()
|
|
80
80
|
.select([path.alias, getColumnName(this.schema, entity, indexBy)], indexByAlias)
|
|
81
81
|
const rows = await this.selectRows(hydrator, qb, entity, input, relationPath)
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
const MAX_IDENTIFIER_LENGTH = 63
|
|
2
2
|
|
|
3
|
+
const utf8Encoder = new TextEncoder()
|
|
4
|
+
const byteLength = (value: string): number => utf8Encoder.encode(value).length
|
|
5
|
+
|
|
3
6
|
export class AliasContext {
|
|
4
7
|
private aliasIndex = new Map<string, number>()
|
|
5
8
|
|
|
@@ -47,14 +50,31 @@ export class Path {
|
|
|
47
50
|
return new Path([...this.path, path], this.aliasContext, this.rootAlias)
|
|
48
51
|
}
|
|
49
52
|
|
|
53
|
+
// Engine-owned columns share the alias namespace with client GraphQL aliases. `$` is outside the GraphQL Name
|
|
54
|
+
// grammar, so no client alias (nor `_`-joined aliases) can produce the segment; `kind` must not contain `_`.
|
|
55
|
+
public forInternal(kind: string) {
|
|
56
|
+
return this.for('$' + kind)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// PostgreSQL limits identifiers in bytes. Untruncated aliases stay below the limit and truncated ones fill it
|
|
60
|
+
// exactly (padded when a multi-byte character does not fit), so the two can never coincide.
|
|
50
61
|
private createAlias(): string {
|
|
51
62
|
const alias = this.fullAlias
|
|
52
|
-
|
|
53
|
-
// intentionally not allowing == MAX_IDENTIFIER_LENGTH
|
|
54
|
-
if (alias.length < MAX_IDENTIFIER_LENGTH) {
|
|
63
|
+
if (byteLength(alias) < MAX_IDENTIFIER_LENGTH) {
|
|
55
64
|
return alias
|
|
56
65
|
}
|
|
57
|
-
const
|
|
58
|
-
|
|
66
|
+
const suffix = '_' + this.aliasContext.getAliasIndex(alias).toString()
|
|
67
|
+
const prefixBytes = MAX_IDENTIFIER_LENGTH - suffix.length
|
|
68
|
+
let prefix = ''
|
|
69
|
+
let usedBytes = 0
|
|
70
|
+
for (const char of alias) {
|
|
71
|
+
const charBytes = byteLength(char)
|
|
72
|
+
if (usedBytes + charBytes > prefixBytes) {
|
|
73
|
+
break
|
|
74
|
+
}
|
|
75
|
+
prefix += char
|
|
76
|
+
usedBytes += charBytes
|
|
77
|
+
}
|
|
78
|
+
return prefix + '_'.repeat(prefixBytes - usedBytes) + suffix
|
|
59
79
|
}
|
|
60
80
|
}
|
|
@@ -86,18 +86,28 @@ export class SelectBuilder {
|
|
|
86
86
|
input = input.withField(new FieldNode(entity.primary, entity.primary, {}))
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
const fetchedPredicates = new Set()
|
|
90
|
-
const addPredicate = (predicate: Acl.Predicate): ColumnValueGetter<boolean> => {
|
|
89
|
+
const fetchedPredicates = new Set<string>()
|
|
90
|
+
const addPredicate = (predicate: Acl.Predicate, options?: { rootOnly?: boolean }): ColumnValueGetter<boolean> => {
|
|
91
91
|
if (typeof predicate === 'boolean') {
|
|
92
92
|
return () => predicate
|
|
93
93
|
}
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
const isRoot = this.relationPath.length === 0
|
|
95
|
+
// A root-resolved name may denote a different definition than the same name in the `all` set, so the
|
|
96
|
+
// two must not share a column. The override gets its own path segment, keeping every other alias unchanged.
|
|
97
|
+
const rootOnly = options?.rootOnly === true && !isRoot
|
|
98
|
+
const predicatePath = path.forInternal(rootOnly ? 'predicateRoot' : 'predicate').for(predicate)
|
|
99
|
+
// Keyed by the column, so two definitions can never be served from one column.
|
|
100
|
+
const predicateKey = predicatePath.fullAlias
|
|
101
|
+
|
|
102
|
+
if (!fetchedPredicates.has(predicateKey)) {
|
|
97
103
|
const relationContext = this.relationPath[this.relationPath.length - 1]
|
|
98
104
|
|
|
99
|
-
const primaryPredicate = this.predicateFactory.create(entity, Acl.Operation.read, undefined, relationContext)
|
|
100
|
-
const fieldPredicate =
|
|
105
|
+
const primaryPredicate = this.predicateFactory.create(entity, Acl.Operation.read, undefined, relationContext, isRoot)
|
|
106
|
+
const fieldPredicate = rootOnly
|
|
107
|
+
// No relation context: `optimizePredicates` would eliminate parts against the root set, but the
|
|
108
|
+
// parent rows may have been filtered with the `all` set — an unsound elimination. Skip it instead.
|
|
109
|
+
? this.predicateFactory.buildPredicates(entity, [predicate], undefined, true)
|
|
110
|
+
: this.predicateFactory.buildPredicates(entity, [predicate], relationContext, isRoot)
|
|
101
111
|
|
|
102
112
|
this.qb = this.whereBuilder.buildAdvanced(
|
|
103
113
|
entity,
|
|
@@ -114,7 +124,7 @@ export class SelectBuilder {
|
|
|
114
124
|
}), predicatePath.alias),
|
|
115
125
|
{ relationPath: this.relationPath, evaluatedPredicates: [primaryPredicate] },
|
|
116
126
|
)
|
|
117
|
-
fetchedPredicates.add(
|
|
127
|
+
fetchedPredicates.add(predicateKey)
|
|
118
128
|
}
|
|
119
129
|
return row => row[predicatePath.alias] === true
|
|
120
130
|
}
|
|
@@ -141,8 +151,8 @@ export class SelectBuilder {
|
|
|
141
151
|
}
|
|
142
152
|
const predicateGetter = predicate !== undefined && predicate !== true ? addPredicate(predicate) : null
|
|
143
153
|
const columnName = getColumnName(this.schema, entity, field)
|
|
144
|
-
const parentValuePath = path.for(field)
|
|
145
|
-
let ids = await this.getColumnValues(parentValuePath, columnName, predicateGetter)
|
|
154
|
+
const parentValuePath = path.forInternal('key').for(field)
|
|
155
|
+
let ids = await this.getColumnValues(path, parentValuePath, columnName, predicateGetter)
|
|
146
156
|
|
|
147
157
|
const data = ids.length > 0 ? dataProvider(ids) : Promise.resolve({})
|
|
148
158
|
this.hydrator.addPromise(
|
|
@@ -197,11 +207,12 @@ export class SelectBuilder {
|
|
|
197
207
|
}
|
|
198
208
|
|
|
199
209
|
private async getColumnValues(
|
|
210
|
+
tablePath: Path,
|
|
200
211
|
columnPath: Path,
|
|
201
212
|
columnName: string,
|
|
202
213
|
predicateGetter: null | ColumnValueGetter<boolean>,
|
|
203
214
|
): Promise<Input.PrimaryValue[]> {
|
|
204
|
-
this.qb = this.qb.select([
|
|
215
|
+
this.qb = this.qb.select([tablePath.alias, columnName], columnPath.alias)
|
|
205
216
|
const rows = await this.rows
|
|
206
217
|
const filteredRows = predicateGetter === null ? rows : rows.filter(predicateGetter)
|
|
207
218
|
const columnAlias = columnPath.alias
|
|
@@ -23,7 +23,15 @@ export type SelectExecutionHandlerContext<
|
|
|
23
23
|
path: Path
|
|
24
24
|
entity: Model.Entity
|
|
25
25
|
relationPath: Model.AnyRelationContext[]
|
|
26
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Compiles a predicate REFERENCE into a per-row boolean (and selects the backing column).
|
|
28
|
+
*
|
|
29
|
+
* The reference is resolved against the permission set the query path implies — the through-inclusive
|
|
30
|
+
* `all` set for anything nested. Pass `rootOnly` when the name was taken from the root set instead:
|
|
31
|
+
* merging roles renames predicates (`__merge__a__b`) and drops `noRoot` ones, so resolving a root name
|
|
32
|
+
* against `all` either throws `Undefined predicate` or silently picks a different definition.
|
|
33
|
+
*/
|
|
34
|
+
addPredicate: (predicate: Acl.Predicate, options?: { rootOnly?: boolean }) => (row: SelectRow) => boolean
|
|
27
35
|
addColumn: (args: {
|
|
28
36
|
predicate?: Acl.Predicate
|
|
29
37
|
query?: (qb: SelectBuilder<SelectBuilder.Result>) => SelectBuilder<SelectBuilder.Result>
|
|
@@ -55,7 +55,7 @@ export class FieldsVisitor implements Model.RelationByTypeVisitor<void>, Model.C
|
|
|
55
55
|
const aliases: string[] = []
|
|
56
56
|
for (const source of entity.view.idSource) {
|
|
57
57
|
const columnName = getColumnName(this.schema, entity, source)
|
|
58
|
-
const idSrcPath = columnPath.
|
|
58
|
+
const idSrcPath = columnPath.forInternal('idSrc').for(source)
|
|
59
59
|
aliases.push(idSrcPath.alias)
|
|
60
60
|
this.executionContext.addColumn({
|
|
61
61
|
query: qb => qb.select([tableAlias, columnName], idSrcPath.alias),
|
|
@@ -32,14 +32,19 @@ export class MetaHandler implements SelectExecutionHandler<{}> {
|
|
|
32
32
|
metaPath: Path,
|
|
33
33
|
operation: Acl.Operation.read | Acl.Operation.update,
|
|
34
34
|
): void {
|
|
35
|
-
const { entity } = context
|
|
35
|
+
const { entity, relationPath } = context
|
|
36
36
|
if (entity.primary === fieldName) {
|
|
37
37
|
return
|
|
38
38
|
}
|
|
39
|
-
|
|
39
|
+
// `readable` mirrors value masking in FieldsVisitor (context-aware). `updatable` stays root-only because
|
|
40
|
+
// update enforcement is not context-aware; the predicate name and its definition must come from the same set.
|
|
41
|
+
const isRead = operation === Acl.Operation.read
|
|
42
|
+
const fieldPredicate = isRead
|
|
43
|
+
? this.predicateFactory.getFieldPredicate(entity, operation, fieldName, relationPath.length === 0)
|
|
44
|
+
: this.predicateFactory.getFieldPredicate(entity, operation, fieldName)
|
|
40
45
|
context.addColumn({
|
|
41
46
|
path: metaPath,
|
|
42
|
-
valueGetter: context.addPredicate(fieldPredicate.predicate),
|
|
47
|
+
valueGetter: context.addPredicate(fieldPredicate.predicate, { rootOnly: !isRead }),
|
|
43
48
|
})
|
|
44
49
|
}
|
|
45
50
|
}
|
|
@@ -43,23 +43,23 @@ test('Filter by has many with additional join', async () => {
|
|
|
43
43
|
executes: [
|
|
44
44
|
{
|
|
45
45
|
sql: SQL`
|
|
46
|
-
select "root_"."id" as "root_id", "root_"."short_name" as "root_shortName", "root_"."id" as "
|
|
46
|
+
select "root_"."id" as "root_id", "root_"."short_name" as "root_shortName", "root_"."id" as "root_$key_id"
|
|
47
47
|
from "public"."person" as "root_"
|
|
48
48
|
where exists (select 1
|
|
49
49
|
from "public"."person_locale" as "root_locales"
|
|
50
50
|
left join "public"."language" as "root_locales_locale" on "root_locales"."locale_id" = "root_locales_locale"."id"
|
|
51
51
|
where "root_"."id" = "root_locales"."person_id" and "root_locales_locale"."slug" = ? and not("root_locales"."url_slug" is null))`,
|
|
52
|
-
response: { rows: [{ root_id: testUuid(1), root_shortName: 'John' }] },
|
|
52
|
+
response: { rows: [{ root_id: testUuid(1), 'root_$key_id': testUuid(1), root_shortName: 'John' }] },
|
|
53
53
|
parameters: ['cs'],
|
|
54
54
|
},
|
|
55
55
|
{
|
|
56
|
-
sql: SQL`select "root_"."person_id" as "
|
|
56
|
+
sql: SQL`select "root_"."person_id" as "root_$index_person", "root_"."url_slug" as "root_urlSlug", "root_"."id" as "root_id"
|
|
57
57
|
from "public"."person_locale" as "root_"
|
|
58
58
|
left join "public"."language" as "root_locale" on "root_"."locale_id" = "root_locale"."id"
|
|
59
59
|
where "root_locale"."slug" = ? and "root_"."person_id" in (?)`,
|
|
60
60
|
parameters: ['cs', testUuid(1)],
|
|
61
61
|
response: {
|
|
62
|
-
rows: [{
|
|
62
|
+
rows: [{ 'root_$index_person': testUuid(1), root_urlSlug: 'john', root_id: testUuid(2) }],
|
|
63
63
|
},
|
|
64
64
|
},
|
|
65
65
|
],
|
|
@@ -27,7 +27,7 @@ test('delete post by id', async () => {
|
|
|
27
27
|
{
|
|
28
28
|
sql: SQL`select
|
|
29
29
|
"root_"."id" as "root_id",
|
|
30
|
-
"root_"."author_id" as "
|
|
30
|
+
"root_"."author_id" as "root_$key_author"
|
|
31
31
|
from "public"."post" as "root_"
|
|
32
32
|
where "root_"."id" = ?`,
|
|
33
33
|
parameters: [testUuid(1)],
|
|
@@ -35,14 +35,14 @@ test('delete post by id', async () => {
|
|
|
35
35
|
rows: [
|
|
36
36
|
{
|
|
37
37
|
root_id: testUuid(1),
|
|
38
|
-
|
|
38
|
+
'root_$key_author': testUuid(2),
|
|
39
39
|
},
|
|
40
40
|
],
|
|
41
41
|
},
|
|
42
42
|
},
|
|
43
43
|
{
|
|
44
44
|
sql: SQL`select
|
|
45
|
-
"root_"."id" as "
|
|
45
|
+
"root_"."id" as "root_$index_id",
|
|
46
46
|
"root_"."name" as "root_name",
|
|
47
47
|
"root_"."id" as "root_id"
|
|
48
48
|
from "public"."author" as "root_"
|
|
@@ -52,6 +52,7 @@ test('delete post by id', async () => {
|
|
|
52
52
|
rows: [
|
|
53
53
|
{
|
|
54
54
|
root_id: testUuid(2),
|
|
55
|
+
'root_$index_id': testUuid(2),
|
|
55
56
|
root_name: 'John',
|
|
56
57
|
},
|
|
57
58
|
],
|
package/tests/cases/integration/graphQlRequests/query/acl/differentRowAndFieldPredicate.test.ts
CHANGED
|
@@ -43,7 +43,7 @@ test('different predicate on row and field level', async () => {
|
|
|
43
43
|
sql: SQL`
|
|
44
44
|
select
|
|
45
45
|
"root_"."id" as "root_id",
|
|
46
|
-
"root_"."username" = ? as "
|
|
46
|
+
"root_"."username" = ? as "root_$predicate_authorPredicate",
|
|
47
47
|
"root_"."username" as "root_username"
|
|
48
48
|
from "public"."author" as "root_" where not("root_"."username" is null)
|
|
49
49
|
`,
|
|
@@ -52,7 +52,7 @@ test('different predicate on row and field level', async () => {
|
|
|
52
52
|
rows: [
|
|
53
53
|
{
|
|
54
54
|
root_id: testUuid(1),
|
|
55
|
-
|
|
55
|
+
'root_$predicate_authorPredicate': true,
|
|
56
56
|
root_username: 'johndoe',
|
|
57
57
|
},
|
|
58
58
|
],
|
|
@@ -89,7 +89,7 @@ test('different predicate on row and field level - false', async () => {
|
|
|
89
89
|
sql: SQL`
|
|
90
90
|
select
|
|
91
91
|
"root_"."id" as "root_id",
|
|
92
|
-
"root_"."username" = ? as "
|
|
92
|
+
"root_"."username" = ? as "root_$predicate_authorPredicate",
|
|
93
93
|
"root_"."username" as "root_username"
|
|
94
94
|
from "public"."author" as "root_" where not("root_"."username" is null)
|
|
95
95
|
`,
|
|
@@ -98,7 +98,7 @@ test('different predicate on row and field level - false', async () => {
|
|
|
98
98
|
rows: [
|
|
99
99
|
{
|
|
100
100
|
root_id: testUuid(1),
|
|
101
|
-
|
|
101
|
+
'root_$predicate_authorPredicate': false,
|
|
102
102
|
root_username: 'johndoe',
|
|
103
103
|
},
|
|
104
104
|
],
|
|
@@ -64,7 +64,7 @@ test('querying id and title', async () => {
|
|
|
64
64
|
{
|
|
65
65
|
sql: SQL`SELECT
|
|
66
66
|
"root_"."id" AS "root_id",
|
|
67
|
-
"root_"."locale" IN (?)
|
|
67
|
+
"root_"."locale" IN (?) as "root_$predicate_localePredicate",
|
|
68
68
|
"root_"."title" AS "root_title"
|
|
69
69
|
FROM "public"."post_locale" AS "root_"`,
|
|
70
70
|
parameters: ['cs'],
|
|
@@ -73,12 +73,12 @@ test('querying id and title', async () => {
|
|
|
73
73
|
{
|
|
74
74
|
root_id: testUuid(1),
|
|
75
75
|
root_title: null,
|
|
76
|
-
|
|
76
|
+
'root_$predicate_localePredicate': false,
|
|
77
77
|
},
|
|
78
78
|
{
|
|
79
79
|
root_id: testUuid(2),
|
|
80
80
|
root_title: 'bar',
|
|
81
|
-
|
|
81
|
+
'root_$predicate_localePredicate': true,
|
|
82
82
|
},
|
|
83
83
|
],
|
|
84
84
|
},
|
|
@@ -131,7 +131,7 @@ test('querying with extra where', async () => {
|
|
|
131
131
|
{
|
|
132
132
|
sql: SQL`select
|
|
133
133
|
"root_"."id" as "root_id",
|
|
134
|
-
"root_"."locale" in (?) as "
|
|
134
|
+
"root_"."locale" in (?) as "root_$predicate_localePredicate",
|
|
135
135
|
"root_"."title" as "root_title"
|
|
136
136
|
from "public"."post_locale" as "root_"
|
|
137
137
|
where "root_"."title" = ? and "root_"."locale" in (?)`,
|
|
@@ -141,7 +141,7 @@ test('querying with extra where', async () => {
|
|
|
141
141
|
{
|
|
142
142
|
root_id: testUuid(1),
|
|
143
143
|
root_title: 'foo',
|
|
144
|
-
|
|
144
|
+
'root_$predicate_localePredicate': true,
|
|
145
145
|
},
|
|
146
146
|
],
|
|
147
147
|
},
|
|
@@ -216,7 +216,7 @@ test('not defined acl variable', async () => {
|
|
|
216
216
|
{
|
|
217
217
|
sql: SQL`
|
|
218
218
|
select "root_"."id" as "root_id",
|
|
219
|
-
false as "
|
|
219
|
+
false as "root_$predicate_localePredicate",
|
|
220
220
|
"root_"."title" as "root_title"
|
|
221
221
|
from "public"."post_locale" as "root_"`,
|
|
222
222
|
parameters: [],
|
|
@@ -252,7 +252,7 @@ test('querying on nested field', async () => {
|
|
|
252
252
|
executes: [
|
|
253
253
|
{
|
|
254
254
|
sql: SQL`select
|
|
255
|
-
"root_"."id" as "
|
|
255
|
+
"root_"."id" as "root_$key_id",
|
|
256
256
|
"root_"."id" as "root_id"
|
|
257
257
|
from "public"."post" as "root_"`,
|
|
258
258
|
parameters: [],
|
|
@@ -260,9 +260,11 @@ test('querying on nested field', async () => {
|
|
|
260
260
|
rows: [
|
|
261
261
|
{
|
|
262
262
|
root_id: testUuid(1),
|
|
263
|
+
'root_$key_id': testUuid(1),
|
|
263
264
|
},
|
|
264
265
|
{
|
|
265
266
|
root_id: testUuid(2),
|
|
267
|
+
'root_$key_id': testUuid(2),
|
|
266
268
|
},
|
|
267
269
|
],
|
|
268
270
|
},
|
|
@@ -271,7 +273,7 @@ test('querying on nested field', async () => {
|
|
|
271
273
|
sql: SQL`
|
|
272
274
|
select "root_"."post_id" as "__grouping_key",
|
|
273
275
|
"root_"."id" as "root_id",
|
|
274
|
-
"root_"."locale" in (?) as "
|
|
276
|
+
"root_"."locale" in (?) as "root_$predicate_localePredicate",
|
|
275
277
|
"root_"."title" as "root_title"
|
|
276
278
|
from "public"."post_locale" as "root_" where "root_"."post_id" in (?, ?)`,
|
|
277
279
|
parameters: ['cs', testUuid(1), testUuid(2)],
|
|
@@ -280,13 +282,13 @@ test('querying on nested field', async () => {
|
|
|
280
282
|
{
|
|
281
283
|
__grouping_key: testUuid(1),
|
|
282
284
|
root_id: testUuid(3),
|
|
283
|
-
|
|
285
|
+
'root_$predicate_localePredicate': false,
|
|
284
286
|
root_title: 'foo',
|
|
285
287
|
},
|
|
286
288
|
{
|
|
287
289
|
__grouping_key: testUuid(2),
|
|
288
290
|
root_id: testUuid(4),
|
|
289
|
-
|
|
291
|
+
'root_$predicate_localePredicate': true,
|
|
290
292
|
root_title: 'bar',
|
|
291
293
|
},
|
|
292
294
|
],
|