createResourceMatcher function
Builds the matches predicate for a ResourceAction from exactly one of
a fixed uri or a simple URI template (e.g. file://{path}).
Throws a GenkitException when both or neither are given, or when the
template uses an RFC 6570 operator ({+path}, {?q}, ...), which is not
supported.
Implementation
bool Function(ResourceInput input) createResourceMatcher({
required String? uri,
required String? template,
}) {
if (uri != null) {
if (template == null) {
return (input) => input.uri == uri;
}
} else if (template != null) {
final regex = _buildSimpleTemplateRegex(template);
return (input) => regex.hasMatch(input.uri);
}
throw GenkitException(
'Resource must specify exactly one of uri or template.',
status: StatusCode.invalidArgument,
);
}