mdb-engine 0.2.1__py3-none-any.whl → 0.2.4__py3-none-any.whl
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.
- mdb_engine/__init__.py +7 -1
- mdb_engine/auth/README.md +6 -0
- mdb_engine/auth/audit.py +40 -40
- mdb_engine/auth/base.py +3 -3
- mdb_engine/auth/casbin_factory.py +6 -6
- mdb_engine/auth/config_defaults.py +5 -5
- mdb_engine/auth/config_helpers.py +12 -12
- mdb_engine/auth/cookie_utils.py +9 -9
- mdb_engine/auth/csrf.py +9 -8
- mdb_engine/auth/decorators.py +7 -6
- mdb_engine/auth/dependencies.py +22 -21
- mdb_engine/auth/integration.py +9 -9
- mdb_engine/auth/jwt.py +9 -9
- mdb_engine/auth/middleware.py +4 -3
- mdb_engine/auth/oso_factory.py +6 -6
- mdb_engine/auth/provider.py +4 -4
- mdb_engine/auth/rate_limiter.py +12 -11
- mdb_engine/auth/restrictions.py +16 -15
- mdb_engine/auth/session_manager.py +11 -13
- mdb_engine/auth/shared_middleware.py +344 -132
- mdb_engine/auth/shared_users.py +20 -20
- mdb_engine/auth/token_lifecycle.py +10 -12
- mdb_engine/auth/token_store.py +4 -5
- mdb_engine/auth/users.py +51 -52
- mdb_engine/auth/utils.py +29 -33
- mdb_engine/cli/commands/generate.py +6 -6
- mdb_engine/cli/utils.py +4 -4
- mdb_engine/config.py +6 -7
- mdb_engine/core/app_registration.py +12 -12
- mdb_engine/core/app_secrets.py +1 -2
- mdb_engine/core/connection.py +3 -4
- mdb_engine/core/encryption.py +1 -2
- mdb_engine/core/engine.py +43 -44
- mdb_engine/core/manifest.py +80 -58
- mdb_engine/core/ray_integration.py +10 -9
- mdb_engine/core/seeding.py +3 -3
- mdb_engine/core/service_initialization.py +10 -9
- mdb_engine/core/types.py +40 -40
- mdb_engine/database/abstraction.py +15 -16
- mdb_engine/database/connection.py +40 -12
- mdb_engine/database/query_validator.py +8 -8
- mdb_engine/database/resource_limiter.py +7 -7
- mdb_engine/database/scoped_wrapper.py +51 -58
- mdb_engine/dependencies.py +14 -13
- mdb_engine/di/container.py +12 -13
- mdb_engine/di/providers.py +14 -13
- mdb_engine/di/scopes.py +5 -5
- mdb_engine/embeddings/dependencies.py +2 -2
- mdb_engine/embeddings/service.py +67 -50
- mdb_engine/exceptions.py +20 -20
- mdb_engine/indexes/helpers.py +11 -11
- mdb_engine/indexes/manager.py +9 -9
- mdb_engine/memory/README.md +93 -2
- mdb_engine/memory/service.py +361 -1109
- mdb_engine/observability/health.py +10 -9
- mdb_engine/observability/logging.py +10 -10
- mdb_engine/observability/metrics.py +8 -7
- mdb_engine/repositories/base.py +25 -25
- mdb_engine/repositories/mongo.py +17 -17
- mdb_engine/repositories/unit_of_work.py +6 -6
- mdb_engine/routing/websockets.py +19 -18
- mdb_engine/utils/__init__.py +3 -1
- mdb_engine/utils/mongo.py +117 -0
- {mdb_engine-0.2.1.dist-info → mdb_engine-0.2.4.dist-info}/METADATA +88 -13
- mdb_engine-0.2.4.dist-info/RECORD +97 -0
- {mdb_engine-0.2.1.dist-info → mdb_engine-0.2.4.dist-info}/WHEEL +1 -1
- mdb_engine-0.2.1.dist-info/RECORD +0 -96
- {mdb_engine-0.2.1.dist-info → mdb_engine-0.2.4.dist-info}/entry_points.txt +0 -0
- {mdb_engine-0.2.1.dist-info → mdb_engine-0.2.4.dist-info}/licenses/LICENSE +0 -0
- {mdb_engine-0.2.1.dist-info → mdb_engine-0.2.4.dist-info}/top_level.txt +0 -0
mdb_engine/core/manifest.py
CHANGED
|
@@ -32,7 +32,8 @@ For Scale:
|
|
|
32
32
|
import asyncio
|
|
33
33
|
import hashlib
|
|
34
34
|
import logging
|
|
35
|
-
from
|
|
35
|
+
from collections.abc import Awaitable, Callable
|
|
36
|
+
from typing import Any
|
|
36
37
|
|
|
37
38
|
from jsonschema import SchemaError, ValidationError, validate
|
|
38
39
|
|
|
@@ -48,10 +49,10 @@ from ..constants import (
|
|
|
48
49
|
logger = logging.getLogger(__name__)
|
|
49
50
|
|
|
50
51
|
# Schema registry: maps version -> schema definition
|
|
51
|
-
SCHEMA_REGISTRY:
|
|
52
|
+
SCHEMA_REGISTRY: dict[str, dict[str, Any]] = {}
|
|
52
53
|
|
|
53
54
|
# Validation cache: maps (manifest_hash, version) -> validation_result
|
|
54
|
-
_validation_cache:
|
|
55
|
+
_validation_cache: dict[str, tuple[bool, str | None, list[str] | None]] = {}
|
|
55
56
|
_cache_lock = asyncio.Lock()
|
|
56
57
|
|
|
57
58
|
|
|
@@ -86,7 +87,7 @@ def _convert_tuples_to_lists(obj: Any) -> Any:
|
|
|
86
87
|
return obj
|
|
87
88
|
|
|
88
89
|
|
|
89
|
-
def _get_manifest_hash(manifest_data:
|
|
90
|
+
def _get_manifest_hash(manifest_data: dict[str, Any]) -> str:
|
|
90
91
|
"""Generate a hash for manifest caching."""
|
|
91
92
|
import json
|
|
92
93
|
|
|
@@ -183,6 +184,27 @@ MANIFEST_SCHEMA_V2 = {
|
|
|
183
184
|
"Works in both auth modes."
|
|
184
185
|
),
|
|
185
186
|
},
|
|
187
|
+
"auth_hub_url": {
|
|
188
|
+
"type": "string",
|
|
189
|
+
"format": "uri",
|
|
190
|
+
"description": (
|
|
191
|
+
"URL of the authentication hub for SSO apps (shared mode only). "
|
|
192
|
+
"Used for redirecting unauthenticated users to login. "
|
|
193
|
+
"Example: 'http://localhost:8000' or 'https://auth.example.com'. "
|
|
194
|
+
"Can be overridden via AUTH_HUB_URL environment variable."
|
|
195
|
+
),
|
|
196
|
+
},
|
|
197
|
+
"related_apps": {
|
|
198
|
+
"type": "object",
|
|
199
|
+
"additionalProperties": {"type": "string", "format": "uri"},
|
|
200
|
+
"description": (
|
|
201
|
+
"Map of related app slugs to their URLs for cross-app navigation "
|
|
202
|
+
"(useful in shared auth mode). Keys are app slugs, values are URLs. "
|
|
203
|
+
"Example: {'dashboard': 'http://localhost:8001', "
|
|
204
|
+
"'click_tracker': 'http://localhost:8000'}. "
|
|
205
|
+
"Can be overridden via {APP_SLUG_UPPER}_URL environment variables."
|
|
206
|
+
),
|
|
207
|
+
},
|
|
186
208
|
"policy": {
|
|
187
209
|
"type": "object",
|
|
188
210
|
"properties": {
|
|
@@ -2083,7 +2105,7 @@ SCHEMA_REGISTRY["default"] = MANIFEST_SCHEMA_V2
|
|
|
2083
2105
|
MANIFEST_SCHEMA = MANIFEST_SCHEMA_V2 # Backward compatibility
|
|
2084
2106
|
|
|
2085
2107
|
|
|
2086
|
-
def get_schema_version(manifest_data:
|
|
2108
|
+
def get_schema_version(manifest_data: dict[str, Any]) -> str:
|
|
2087
2109
|
"""
|
|
2088
2110
|
Detect schema version from manifest.
|
|
2089
2111
|
|
|
@@ -2096,7 +2118,7 @@ def get_schema_version(manifest_data: Dict[str, Any]) -> str:
|
|
|
2096
2118
|
Raises:
|
|
2097
2119
|
ValueError: If schema version format is invalid
|
|
2098
2120
|
"""
|
|
2099
|
-
version:
|
|
2121
|
+
version: str | None = manifest_data.get("schema_version")
|
|
2100
2122
|
if version:
|
|
2101
2123
|
# Validate version format
|
|
2102
2124
|
if not isinstance(version, str) or not version.replace(".", "").isdigit():
|
|
@@ -2118,8 +2140,8 @@ def get_schema_version(manifest_data: Dict[str, Any]) -> str:
|
|
|
2118
2140
|
|
|
2119
2141
|
|
|
2120
2142
|
def migrate_manifest(
|
|
2121
|
-
manifest_data:
|
|
2122
|
-
) ->
|
|
2143
|
+
manifest_data: dict[str, Any], target_version: str = CURRENT_SCHEMA_VERSION
|
|
2144
|
+
) -> dict[str, Any]:
|
|
2123
2145
|
"""
|
|
2124
2146
|
Migrate manifest from one schema version to another.
|
|
2125
2147
|
|
|
@@ -2168,7 +2190,7 @@ def migrate_manifest(
|
|
|
2168
2190
|
return migrated
|
|
2169
2191
|
|
|
2170
2192
|
|
|
2171
|
-
def get_schema_for_version(version: str) ->
|
|
2193
|
+
def get_schema_for_version(version: str) -> dict[str, Any]:
|
|
2172
2194
|
"""
|
|
2173
2195
|
Get schema definition for a specific version.
|
|
2174
2196
|
|
|
@@ -2201,8 +2223,8 @@ def get_schema_for_version(version: str) -> Dict[str, Any]:
|
|
|
2201
2223
|
|
|
2202
2224
|
|
|
2203
2225
|
async def _validate_manifest_async(
|
|
2204
|
-
manifest_data:
|
|
2205
|
-
) ->
|
|
2226
|
+
manifest_data: dict[str, Any], use_cache: bool = True
|
|
2227
|
+
) -> tuple[bool, str | None, list[str] | None]:
|
|
2206
2228
|
"""
|
|
2207
2229
|
Validate a manifest against the JSON Schema with versioning and caching support.
|
|
2208
2230
|
|
|
@@ -2329,8 +2351,8 @@ def clear_validation_cache():
|
|
|
2329
2351
|
|
|
2330
2352
|
|
|
2331
2353
|
async def validate_manifests_parallel(
|
|
2332
|
-
manifests:
|
|
2333
|
-
) ->
|
|
2354
|
+
manifests: list[dict[str, Any]], use_cache: bool = True
|
|
2355
|
+
) -> list[tuple[bool, str | None, list[str] | None, str | None]]:
|
|
2334
2356
|
"""
|
|
2335
2357
|
Validate multiple manifests in parallel for scale.
|
|
2336
2358
|
|
|
@@ -2344,8 +2366,8 @@ async def validate_manifests_parallel(
|
|
|
2344
2366
|
"""
|
|
2345
2367
|
|
|
2346
2368
|
async def validate_one(
|
|
2347
|
-
manifest:
|
|
2348
|
-
) ->
|
|
2369
|
+
manifest: dict[str, Any],
|
|
2370
|
+
) -> tuple[bool, str | None, list[str] | None, str | None]:
|
|
2349
2371
|
slug = manifest.get("slug", "unknown")
|
|
2350
2372
|
is_valid, error, paths = await _validate_manifest_async(manifest, use_cache=use_cache)
|
|
2351
2373
|
return (is_valid, error, paths, slug)
|
|
@@ -2366,8 +2388,8 @@ async def validate_manifests_parallel(
|
|
|
2366
2388
|
|
|
2367
2389
|
|
|
2368
2390
|
async def validate_developer_id(
|
|
2369
|
-
developer_id: str, db_validator:
|
|
2370
|
-
) ->
|
|
2391
|
+
developer_id: str, db_validator: Callable[[str], Awaitable[bool]] | None = None
|
|
2392
|
+
) -> tuple[bool, str | None]:
|
|
2371
2393
|
"""
|
|
2372
2394
|
Validate that a developer_id exists in the system and has developer role.
|
|
2373
2395
|
|
|
@@ -2411,10 +2433,10 @@ async def validate_developer_id(
|
|
|
2411
2433
|
|
|
2412
2434
|
|
|
2413
2435
|
async def validate_manifest_with_db(
|
|
2414
|
-
manifest_data:
|
|
2436
|
+
manifest_data: dict[str, Any],
|
|
2415
2437
|
db_validator: Callable[[str], Awaitable[bool]],
|
|
2416
2438
|
use_cache: bool = True,
|
|
2417
|
-
) ->
|
|
2439
|
+
) -> tuple[bool, str | None, list[str] | None]:
|
|
2418
2440
|
"""
|
|
2419
2441
|
Validate a manifest against the JSON Schema (with versioning) and check
|
|
2420
2442
|
developer_id exists in system.
|
|
@@ -2455,8 +2477,8 @@ async def validate_manifest_with_db(
|
|
|
2455
2477
|
# Public API: Synchronous wrapper for backward compatibility
|
|
2456
2478
|
# Most callers use this synchronously, so we provide a sync wrapper
|
|
2457
2479
|
def validate_manifest(
|
|
2458
|
-
manifest_data:
|
|
2459
|
-
) ->
|
|
2480
|
+
manifest_data: dict[str, Any], use_cache: bool = True
|
|
2481
|
+
) -> tuple[bool, str | None, list[str] | None]:
|
|
2460
2482
|
"""
|
|
2461
2483
|
Validate a manifest against the JSON Schema with versioning and caching
|
|
2462
2484
|
support (synchronous wrapper).
|
|
@@ -2495,8 +2517,8 @@ def validate_manifest(
|
|
|
2495
2517
|
|
|
2496
2518
|
|
|
2497
2519
|
def _validate_regular_index(
|
|
2498
|
-
index_def:
|
|
2499
|
-
) ->
|
|
2520
|
+
index_def: dict[str, Any], collection_name: str, index_name: str
|
|
2521
|
+
) -> tuple[bool, str | None]:
|
|
2500
2522
|
"""Validate a regular index definition."""
|
|
2501
2523
|
if "keys" not in index_def:
|
|
2502
2524
|
return (
|
|
@@ -2533,8 +2555,8 @@ def _validate_regular_index(
|
|
|
2533
2555
|
|
|
2534
2556
|
|
|
2535
2557
|
def _validate_ttl_index(
|
|
2536
|
-
index_def:
|
|
2537
|
-
) ->
|
|
2558
|
+
index_def: dict[str, Any], collection_name: str, index_name: str
|
|
2559
|
+
) -> tuple[bool, str | None]:
|
|
2538
2560
|
"""Validate a TTL index definition."""
|
|
2539
2561
|
if "keys" not in index_def:
|
|
2540
2562
|
return (
|
|
@@ -2567,8 +2589,8 @@ def _validate_ttl_index(
|
|
|
2567
2589
|
|
|
2568
2590
|
|
|
2569
2591
|
def _validate_partial_index(
|
|
2570
|
-
index_def:
|
|
2571
|
-
) ->
|
|
2592
|
+
index_def: dict[str, Any], collection_name: str, index_name: str
|
|
2593
|
+
) -> tuple[bool, str | None]:
|
|
2572
2594
|
"""Validate a partial index definition."""
|
|
2573
2595
|
if "keys" not in index_def:
|
|
2574
2596
|
return (
|
|
@@ -2588,8 +2610,8 @@ def _validate_partial_index(
|
|
|
2588
2610
|
|
|
2589
2611
|
|
|
2590
2612
|
def _validate_text_index(
|
|
2591
|
-
index_def:
|
|
2592
|
-
) ->
|
|
2613
|
+
index_def: dict[str, Any], collection_name: str, index_name: str
|
|
2614
|
+
) -> tuple[bool, str | None]:
|
|
2593
2615
|
"""Validate a text index definition."""
|
|
2594
2616
|
if "keys" not in index_def:
|
|
2595
2617
|
return (
|
|
@@ -2614,8 +2636,8 @@ def _validate_text_index(
|
|
|
2614
2636
|
|
|
2615
2637
|
|
|
2616
2638
|
def _validate_geospatial_index(
|
|
2617
|
-
index_def:
|
|
2618
|
-
) ->
|
|
2639
|
+
index_def: dict[str, Any], collection_name: str, index_name: str
|
|
2640
|
+
) -> tuple[bool, str | None]:
|
|
2619
2641
|
"""Validate a geospatial index definition."""
|
|
2620
2642
|
if "keys" not in index_def:
|
|
2621
2643
|
return (
|
|
@@ -2641,8 +2663,8 @@ def _validate_geospatial_index(
|
|
|
2641
2663
|
|
|
2642
2664
|
|
|
2643
2665
|
def _validate_vector_search_index(
|
|
2644
|
-
index_def:
|
|
2645
|
-
) ->
|
|
2666
|
+
index_def: dict[str, Any], collection_name: str, index_name: str, index_type: str
|
|
2667
|
+
) -> tuple[bool, str | None]:
|
|
2646
2668
|
"""Validate a vectorSearch or search index definition."""
|
|
2647
2669
|
if "definition" not in index_def:
|
|
2648
2670
|
return (
|
|
@@ -2689,8 +2711,8 @@ def _validate_vector_search_index(
|
|
|
2689
2711
|
|
|
2690
2712
|
|
|
2691
2713
|
def _validate_hybrid_index(
|
|
2692
|
-
index_def:
|
|
2693
|
-
) ->
|
|
2714
|
+
index_def: dict[str, Any], collection_name: str, index_name: str
|
|
2715
|
+
) -> tuple[bool, str | None]:
|
|
2694
2716
|
"""Validate a hybrid index definition."""
|
|
2695
2717
|
if "hybrid" not in index_def:
|
|
2696
2718
|
return (
|
|
@@ -2753,8 +2775,8 @@ def _validate_hybrid_index(
|
|
|
2753
2775
|
|
|
2754
2776
|
|
|
2755
2777
|
def validate_index_definition(
|
|
2756
|
-
index_def:
|
|
2757
|
-
) ->
|
|
2778
|
+
index_def: dict[str, Any], collection_name: str, index_name: str
|
|
2779
|
+
) -> tuple[bool, str | None]:
|
|
2758
2780
|
"""
|
|
2759
2781
|
Validate a single index definition with context-specific checks.
|
|
2760
2782
|
|
|
@@ -2797,8 +2819,8 @@ def validate_index_definition(
|
|
|
2797
2819
|
|
|
2798
2820
|
|
|
2799
2821
|
def validate_managed_indexes(
|
|
2800
|
-
managed_indexes:
|
|
2801
|
-
) ->
|
|
2822
|
+
managed_indexes: dict[str, list[dict[str, Any]]],
|
|
2823
|
+
) -> tuple[bool, str | None]:
|
|
2802
2824
|
"""
|
|
2803
2825
|
Validate all managed indexes with collection and index context.
|
|
2804
2826
|
|
|
@@ -2866,8 +2888,8 @@ class ManifestValidator:
|
|
|
2866
2888
|
|
|
2867
2889
|
@staticmethod
|
|
2868
2890
|
def validate(
|
|
2869
|
-
manifest:
|
|
2870
|
-
) ->
|
|
2891
|
+
manifest: dict[str, Any], use_cache: bool = True
|
|
2892
|
+
) -> tuple[bool, str | None, list[str] | None]:
|
|
2871
2893
|
"""
|
|
2872
2894
|
Validate manifest against schema.
|
|
2873
2895
|
|
|
@@ -2882,8 +2904,8 @@ class ManifestValidator:
|
|
|
2882
2904
|
|
|
2883
2905
|
@staticmethod
|
|
2884
2906
|
async def validate_async(
|
|
2885
|
-
manifest:
|
|
2886
|
-
) ->
|
|
2907
|
+
manifest: dict[str, Any], use_cache: bool = True
|
|
2908
|
+
) -> tuple[bool, str | None, list[str] | None]:
|
|
2887
2909
|
"""
|
|
2888
2910
|
Validate manifest asynchronously.
|
|
2889
2911
|
|
|
@@ -2902,10 +2924,10 @@ class ManifestValidator:
|
|
|
2902
2924
|
|
|
2903
2925
|
@staticmethod
|
|
2904
2926
|
async def validate_with_db(
|
|
2905
|
-
manifest:
|
|
2927
|
+
manifest: dict[str, Any],
|
|
2906
2928
|
db_validator: Callable[[str], Awaitable[bool]],
|
|
2907
2929
|
use_cache: bool = True,
|
|
2908
|
-
) ->
|
|
2930
|
+
) -> tuple[bool, str | None, list[str] | None]:
|
|
2909
2931
|
"""
|
|
2910
2932
|
Validate manifest and check developer_id exists in database.
|
|
2911
2933
|
|
|
@@ -2921,8 +2943,8 @@ class ManifestValidator:
|
|
|
2921
2943
|
|
|
2922
2944
|
@staticmethod
|
|
2923
2945
|
def validate_managed_indexes(
|
|
2924
|
-
managed_indexes:
|
|
2925
|
-
) ->
|
|
2946
|
+
managed_indexes: dict[str, list[dict[str, Any]]],
|
|
2947
|
+
) -> tuple[bool, str | None]:
|
|
2926
2948
|
"""
|
|
2927
2949
|
Validate managed indexes configuration.
|
|
2928
2950
|
|
|
@@ -2936,8 +2958,8 @@ class ManifestValidator:
|
|
|
2936
2958
|
|
|
2937
2959
|
@staticmethod
|
|
2938
2960
|
def validate_index_definition(
|
|
2939
|
-
index_def:
|
|
2940
|
-
) ->
|
|
2961
|
+
index_def: dict[str, Any], collection_name: str, index_name: str
|
|
2962
|
+
) -> tuple[bool, str | None]:
|
|
2941
2963
|
"""
|
|
2942
2964
|
Validate a single index definition.
|
|
2943
2965
|
|
|
@@ -2952,7 +2974,7 @@ class ManifestValidator:
|
|
|
2952
2974
|
return validate_index_definition(index_def, collection_name, index_name)
|
|
2953
2975
|
|
|
2954
2976
|
@staticmethod
|
|
2955
|
-
def get_schema_version(manifest:
|
|
2977
|
+
def get_schema_version(manifest: dict[str, Any]) -> str:
|
|
2956
2978
|
"""
|
|
2957
2979
|
Get schema version from manifest.
|
|
2958
2980
|
|
|
@@ -2966,8 +2988,8 @@ class ManifestValidator:
|
|
|
2966
2988
|
|
|
2967
2989
|
@staticmethod
|
|
2968
2990
|
def migrate(
|
|
2969
|
-
manifest:
|
|
2970
|
-
) ->
|
|
2991
|
+
manifest: dict[str, Any], target_version: str = CURRENT_SCHEMA_VERSION
|
|
2992
|
+
) -> dict[str, Any]:
|
|
2971
2993
|
"""
|
|
2972
2994
|
Migrate manifest to target schema version.
|
|
2973
2995
|
|
|
@@ -2994,7 +3016,7 @@ class ManifestParser:
|
|
|
2994
3016
|
with automatic validation and migration.
|
|
2995
3017
|
"""
|
|
2996
3018
|
|
|
2997
|
-
def __init__(self, validator:
|
|
3019
|
+
def __init__(self, validator: ManifestValidator | None = None):
|
|
2998
3020
|
"""
|
|
2999
3021
|
Initialize parser.
|
|
3000
3022
|
|
|
@@ -3004,7 +3026,7 @@ class ManifestParser:
|
|
|
3004
3026
|
self.validator = validator or ManifestValidator()
|
|
3005
3027
|
|
|
3006
3028
|
@staticmethod
|
|
3007
|
-
async def load_from_file(path: Any, validate: bool = True) ->
|
|
3029
|
+
async def load_from_file(path: Any, validate: bool = True) -> dict[str, Any]:
|
|
3008
3030
|
"""
|
|
3009
3031
|
Load and validate manifest from file.
|
|
3010
3032
|
|
|
@@ -3041,7 +3063,7 @@ class ManifestParser:
|
|
|
3041
3063
|
return manifest_data
|
|
3042
3064
|
|
|
3043
3065
|
@staticmethod
|
|
3044
|
-
async def load_from_dict(data:
|
|
3066
|
+
async def load_from_dict(data: dict[str, Any], validate: bool = True) -> dict[str, Any]:
|
|
3045
3067
|
"""
|
|
3046
3068
|
Load and validate manifest from dictionary.
|
|
3047
3069
|
|
|
@@ -3065,7 +3087,7 @@ class ManifestParser:
|
|
|
3065
3087
|
return data.copy()
|
|
3066
3088
|
|
|
3067
3089
|
@staticmethod
|
|
3068
|
-
async def load_from_string(content: str, validate: bool = True) ->
|
|
3090
|
+
async def load_from_string(content: str, validate: bool = True) -> dict[str, Any]:
|
|
3069
3091
|
"""
|
|
3070
3092
|
Load and validate manifest from JSON string.
|
|
3071
3093
|
|
|
@@ -3087,8 +3109,8 @@ class ManifestParser:
|
|
|
3087
3109
|
|
|
3088
3110
|
@staticmethod
|
|
3089
3111
|
async def load_and_migrate(
|
|
3090
|
-
manifest:
|
|
3091
|
-
) ->
|
|
3112
|
+
manifest: dict[str, Any], target_version: str = CURRENT_SCHEMA_VERSION
|
|
3113
|
+
) -> dict[str, Any]:
|
|
3092
3114
|
"""
|
|
3093
3115
|
Load manifest and migrate to target version.
|
|
3094
3116
|
|
|
@@ -25,7 +25,8 @@ This module is part of MDB_ENGINE - MongoDB Engine.
|
|
|
25
25
|
|
|
26
26
|
import logging
|
|
27
27
|
import os
|
|
28
|
-
from
|
|
28
|
+
from collections.abc import Callable
|
|
29
|
+
from typing import TYPE_CHECKING, Any, TypeVar
|
|
29
30
|
|
|
30
31
|
if TYPE_CHECKING:
|
|
31
32
|
pass
|
|
@@ -132,7 +133,7 @@ class AppRayActor:
|
|
|
132
133
|
else:
|
|
133
134
|
raise
|
|
134
135
|
|
|
135
|
-
async def get_app_db(self, app_token:
|
|
136
|
+
async def get_app_db(self, app_token: str | None = None) -> Any:
|
|
136
137
|
"""
|
|
137
138
|
Get scoped database for this app.
|
|
138
139
|
|
|
@@ -191,11 +192,11 @@ class AppRayActor:
|
|
|
191
192
|
async def get_ray_actor_handle(
|
|
192
193
|
app_slug: str,
|
|
193
194
|
namespace: str = "modular_labs",
|
|
194
|
-
mongo_uri:
|
|
195
|
-
db_name:
|
|
195
|
+
mongo_uri: str | None = None,
|
|
196
|
+
db_name: str | None = None,
|
|
196
197
|
create_if_missing: bool = True,
|
|
197
|
-
actor_class:
|
|
198
|
-
) ->
|
|
198
|
+
actor_class: type | None = None,
|
|
199
|
+
) -> Any | None:
|
|
199
200
|
"""
|
|
200
201
|
Get or create a Ray actor handle for an app.
|
|
201
202
|
|
|
@@ -294,7 +295,7 @@ async def get_ray_actor_handle(
|
|
|
294
295
|
|
|
295
296
|
|
|
296
297
|
def ray_actor_decorator(
|
|
297
|
-
app_slug:
|
|
298
|
+
app_slug: str | None = None,
|
|
298
299
|
namespace: str = "modular_labs",
|
|
299
300
|
isolated: bool = True,
|
|
300
301
|
lifetime: str = "detached",
|
|
@@ -369,8 +370,8 @@ def ray_actor_decorator(
|
|
|
369
370
|
def spawn(
|
|
370
371
|
cls,
|
|
371
372
|
*args,
|
|
372
|
-
mongo_uri:
|
|
373
|
-
db_name:
|
|
373
|
+
mongo_uri: str | None = None,
|
|
374
|
+
db_name: str | None = None,
|
|
374
375
|
**kwargs,
|
|
375
376
|
):
|
|
376
377
|
"""
|
mdb_engine/core/seeding.py
CHANGED
|
@@ -8,7 +8,7 @@ This module is part of MDB_ENGINE - MongoDB Engine.
|
|
|
8
8
|
|
|
9
9
|
import logging
|
|
10
10
|
from datetime import datetime
|
|
11
|
-
from typing import Any
|
|
11
|
+
from typing import Any
|
|
12
12
|
|
|
13
13
|
from pymongo.errors import (
|
|
14
14
|
ConnectionFailure,
|
|
@@ -20,8 +20,8 @@ logger = logging.getLogger(__name__)
|
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
async def seed_initial_data(
|
|
23
|
-
db, app_slug: str, initial_data:
|
|
24
|
-
) ->
|
|
23
|
+
db, app_slug: str, initial_data: dict[str, list[dict[str, Any]]]
|
|
24
|
+
) -> dict[str, int]:
|
|
25
25
|
"""
|
|
26
26
|
Seed initial data into collections.
|
|
27
27
|
|
|
@@ -11,7 +11,8 @@ This module is part of MDB_ENGINE - MongoDB Engine.
|
|
|
11
11
|
"""
|
|
12
12
|
|
|
13
13
|
import logging
|
|
14
|
-
from
|
|
14
|
+
from collections.abc import Callable
|
|
15
|
+
from typing import Any
|
|
15
16
|
|
|
16
17
|
from pymongo.errors import (
|
|
17
18
|
ConnectionFailure,
|
|
@@ -50,10 +51,10 @@ class ServiceInitializer:
|
|
|
50
51
|
self.mongo_uri = mongo_uri
|
|
51
52
|
self.db_name = db_name
|
|
52
53
|
self.get_scoped_db_fn = get_scoped_db_fn
|
|
53
|
-
self._memory_services:
|
|
54
|
-
self._websocket_configs:
|
|
54
|
+
self._memory_services: dict[str, Any] = {}
|
|
55
|
+
self._websocket_configs: dict[str, dict[str, Any]] = {}
|
|
55
56
|
|
|
56
|
-
async def initialize_memory_service(self, slug: str, memory_config:
|
|
57
|
+
async def initialize_memory_service(self, slug: str, memory_config: dict[str, Any]) -> None:
|
|
57
58
|
"""
|
|
58
59
|
Initialize Mem0 memory service for an app.
|
|
59
60
|
|
|
@@ -151,7 +152,7 @@ class ServiceInitializer:
|
|
|
151
152
|
exc_info=True,
|
|
152
153
|
)
|
|
153
154
|
|
|
154
|
-
async def register_websockets(self, slug: str, websockets_config:
|
|
155
|
+
async def register_websockets(self, slug: str, websockets_config: dict[str, Any]) -> None:
|
|
155
156
|
"""
|
|
156
157
|
Register WebSocket endpoints for an app.
|
|
157
158
|
|
|
@@ -195,7 +196,7 @@ class ServiceInitializer:
|
|
|
195
196
|
)
|
|
196
197
|
|
|
197
198
|
async def seed_initial_data(
|
|
198
|
-
self, slug: str, initial_data:
|
|
199
|
+
self, slug: str, initial_data: dict[str, list[dict[str, Any]]]
|
|
199
200
|
) -> None:
|
|
200
201
|
"""
|
|
201
202
|
Seed initial data into collections for an app.
|
|
@@ -240,7 +241,7 @@ class ServiceInitializer:
|
|
|
240
241
|
)
|
|
241
242
|
|
|
242
243
|
async def setup_observability(
|
|
243
|
-
self, slug: str, manifest:
|
|
244
|
+
self, slug: str, manifest: dict[str, Any], observability_config: dict[str, Any]
|
|
244
245
|
) -> None:
|
|
245
246
|
"""
|
|
246
247
|
Set up observability features (health checks, metrics, logging) from manifest.
|
|
@@ -296,7 +297,7 @@ class ServiceInitializer:
|
|
|
296
297
|
f"Could not set up observability for {slug}: {e}", exc_info=True
|
|
297
298
|
)
|
|
298
299
|
|
|
299
|
-
def get_websocket_config(self, slug: str) ->
|
|
300
|
+
def get_websocket_config(self, slug: str) -> dict[str, Any] | None:
|
|
300
301
|
"""
|
|
301
302
|
Get WebSocket configuration for an app.
|
|
302
303
|
|
|
@@ -308,7 +309,7 @@ class ServiceInitializer:
|
|
|
308
309
|
"""
|
|
309
310
|
return self._websocket_configs.get(slug)
|
|
310
311
|
|
|
311
|
-
def get_memory_service(self, slug: str) ->
|
|
312
|
+
def get_memory_service(self, slug: str) -> Any | None:
|
|
312
313
|
"""
|
|
313
314
|
Get Mem0 memory service for an app.
|
|
314
315
|
|