def __init__( self, fqn: str, min_length: Optional[int] = None, max_length: Optional[int] = None, pattern: Optional[str] = None, enum: Optional[Set[str]] = None, ): super().__init__(fqn, "string") self.min_length = min_length self.max_length = max_length self.pattern = pattern self.pattern_compiled = if_set(pattern, re.compile) self.enum = enum self.valid_fn = validate_fn( check_type_fn(str, "string"), check_fn( self.pattern_compiled, lambda p, obj: p.fullmatch(obj) is not None, f"does not conform to regex: {self.pattern}", ), check_fn(self.enum, lambda x, obj: obj in x, f"should be one of: {self.enum}"), check_fn(self.min_length, lambda x, obj: len(obj) >= x, f"does not have minimal length: {self.min_length}"), check_fn(self.max_length, lambda x, obj: len(obj) <= x, f"is too long! Allowed: {self.max_length}"), )
async def query_graph_stream(self, request: Request) -> StreamResponse: graph_db, query_model = await self.graph_query_model_from_request( request) count = request.query.get("count", "true").lower() != "false" timeout = if_set(request.query.get("search_timeout"), duration) async with await graph_db.search_graph_gen(query_model, count, timeout) as cursor: return await self.stream_response_from_gen(request, cursor, cursor.count())