Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public appendItemIfLocallyAuthorized(): Expression {
return iff(
parens(
or([
equals(ref(ResourceConstants.SNIPPETS.IsLocalDynamicGroupAuthorizedVariable), raw('true')),
equals(ref(ResourceConstants.SNIPPETS.IsLocalOwnerAuthorizedVariable), raw('true')),
])
),
qref('$items.add($item)')
);
}
const setup: Expression[] = [
set(ref('limit'), ref(`util.defaultIfNull($context.args.limit, ${defaultPageLimit})`)),
set(ref('query'), makeExpression(keySchema, connectionAttributes))
];
if (keySchema[1] && !connectionAttributes[1]) {
let sortKeyType = relatedType.fields.find(f => f.name.value === keySchema[1].AttributeName).type;
let sortKeyAttType = attributeTypeFromScalar(sortKeyType);
setup.push(applyKeyConditionExpression(keySchema[1].AttributeName, sortKeyAttType, 'query'));
}
var queryArguments : { query, filter, scanIndexForward, limit, nextToken, index? } = {
query: raw('$util.toJson($query)'),
scanIndexForward: ifElse(
ref('context.args.sortDirection'),
ifElse(
equals(ref('context.args.sortDirection'), str('ASC')),
bool(true),
bool(false)
),
bool(true)
),
filter: ifElse(
ref('context.args.filter'),
ref('util.transform.toDynamoDBFilterExpression($ctx.args.filter)'),
nul()
),
limit: ref('limit'),
nextToken: ifElse(
ref('context.args.nextToken'),
str('$context.args.nextToken'),
nul()
)
public appendItemIfLocallyAuthorized(): Expression {
return iff(
parens(
or([
equals(ref(ResourceConstants.SNIPPETS.IsLocalDynamicGroupAuthorizedVariable), raw('true')),
equals(ref(ResourceConstants.SNIPPETS.IsLocalOwnerAuthorizedVariable), raw('true'))
])
), qref('$items.add($item)')
)
}
setup.push(applyKeyConditionExpression(String(keySchema[1].AttributeName),
attributeTypeFromScalar(sortKeyField.type), 'query'));
} else {
setup.push(applyCompositeKeyConditionExpression(this.getSortKeyNames(String(keySchema[1].AttributeName)),
'query',
this.makeCompositeSortKeyName(String(keySchema[1].AttributeName)),
String(keySchema[1].AttributeName)));
}
}
let queryArguments = {
query: raw('$util.toJson($query)'),
scanIndexForward: ifElse(
ref('context.args.sortDirection'),
ifElse(
equals(ref('context.args.sortDirection'), str('ASC')),
bool(true),
bool(false)
),
bool(true)
),
filter: ifElse(
ref('context.args.filter'),
ref('util.transform.toDynamoDBFilterExpression($ctx.args.filter)'),
nul()
),
limit: ref('limit'),
nextToken: ifElse(
ref('context.args.nextToken'),
str('$context.args.nextToken'),
nul()
),
setup.push(applyKeyConditionExpression(sortKeyInfo.fieldName, sortKeyInfo.attributeType, 'query'));
}
return new Resolver({
ApiId: Fn.GetAtt(ResourceConstants.RESOURCES.GraphQLAPILogicalID, 'ApiId'),
DataSourceName: Fn.GetAtt(ModelResourceIDs.ModelTableDataSourceID(relatedType), 'Name'),
FieldName: field,
TypeName: type,
RequestMappingTemplate: print(
compoundExpression([
...setup,
DynamoDBMappingTemplate.query({
query: raw('$util.toJson($query)'),
scanIndexForward: ifElse(
ref('context.args.sortDirection'),
ifElse(
equals(ref('context.args.sortDirection'), str('ASC')),
bool(true),
bool(false)
),
bool(true)
),
filter: ifElse(
ref('context.args.filter'),
ref('util.transform.toDynamoDBFilterExpression($ctx.args.filter)'),
nul()
),
limit: ref('limit'),
nextToken: ifElse(
ref('context.args.nextToken'),
str('$context.args.nextToken'),
nul()
),
public throwIfSubscriptionUnauthorized(): Expression {
const ifUnauthThrow = iff(
not(
parens(
or([
equals(ref(ResourceConstants.SNIPPETS.IsStaticGroupAuthorizedVariable), raw('true')),
equals(ref(ResourceConstants.SNIPPETS.IsOwnerAuthorizedVariable), raw('true')),
])
)
),
raw('$util.unauthorized()')
);
return block('Throw if unauthorized', [ifUnauthThrow]);
}
public throwIfNotStaticGroupAuthorizedOrAuthConditionIsEmpty(): Expression {
const ifUnauthThrow = iff(
not(parens(
or([
equals(ref(ResourceConstants.SNIPPETS.IsStaticGroupAuthorizedVariable), raw('true')),
parens(raw('$authCondition && $authCondition.expression != ""'))
])
)), raw('$util.unauthorized()')
)
return block('Throw if unauthorized', [
ifUnauthThrow,
])
}
public throwIfUnauthorized(): Expression {
const ifUnauthThrow = iff(
not(parens(
or([
equals(ref(ResourceConstants.SNIPPETS.IsStaticGroupAuthorizedVariable), raw('true')),
equals(ref(ResourceConstants.SNIPPETS.IsDynamicGroupAuthorizedVariable), raw('true')),
equals(ref(ResourceConstants.SNIPPETS.IsOwnerAuthorizedVariable), raw('true'))
])
)), raw('$util.unauthorized()')
)
return block('Throw if unauthorized', [
ifUnauthThrow,
])
}