Coverage for functions \ flipdare \ search \ core \ search_definition.py: 96%
24 statements
« prev ^ index » next coverage.py v7.13.0, created at 2026-05-08 12:22 +1000
« prev ^ index » next coverage.py v7.13.0, created at 2026-05-08 12:22 +1000
1#!/usr/bin/env python
2# Copyright (c) 2026 Flipdare Pty Ltd. All rights reserved.
3#
4# This file is part of Flipdare's proprietary software and contains
5# confidential and copyrighted material. Unauthorised copying,
6# modification, distribution, or use of this file is strictly
7# prohibited without prior written permission from Flipdare Pty Ltd.
8#
9# This software includes third-party components licensed under MIT,
10# BSD, and Apache 2.0 licences. See THIRD_PARTY_NOTICES for details.
11#
13from __future__ import annotations
15from typing import Any
17from flipdare.app_env import get_app_environment
18from flipdare.generated.shared.search.search_collections import SearchCollections
19from flipdare.search.constants import FRIEND_DEFINITION, GENERAL_DEFINITION
21__all__ = ["SearchDefinition"]
24class SearchDefinition:
25 def __init__(self, collection_name: str) -> None:
26 self._collection_name = collection_name
28 @classmethod
29 def from_collection(cls, collection: str | SearchCollections) -> SearchDefinition:
30 match collection:
31 case SearchCollections():
32 return cls(collection.value)
33 case str():
34 if get_app_environment().in_cloud:
35 msg = "Custom search definitions are NOT allowed in the cloud."
36 raise RuntimeError(msg)
37 return cls(collection)
39 def definition(self) -> dict[str, Any]:
40 col_name = self._collection_name
41 schema = (col_name.startswith("friend") and FRIEND_DEFINITION) or GENERAL_DEFINITION
43 schema["name"] = col_name
44 return schema