mdb-engine 0.1.6__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/README.md +144 -0
- mdb_engine/__init__.py +37 -0
- mdb_engine/auth/README.md +631 -0
- mdb_engine/auth/__init__.py +128 -0
- mdb_engine/auth/casbin_factory.py +199 -0
- mdb_engine/auth/casbin_models.py +46 -0
- mdb_engine/auth/config_defaults.py +71 -0
- mdb_engine/auth/config_helpers.py +213 -0
- mdb_engine/auth/cookie_utils.py +158 -0
- mdb_engine/auth/decorators.py +350 -0
- mdb_engine/auth/dependencies.py +747 -0
- mdb_engine/auth/helpers.py +64 -0
- mdb_engine/auth/integration.py +578 -0
- mdb_engine/auth/jwt.py +225 -0
- mdb_engine/auth/middleware.py +241 -0
- mdb_engine/auth/oso_factory.py +323 -0
- mdb_engine/auth/provider.py +570 -0
- mdb_engine/auth/restrictions.py +271 -0
- mdb_engine/auth/session_manager.py +477 -0
- mdb_engine/auth/token_lifecycle.py +213 -0
- mdb_engine/auth/token_store.py +289 -0
- mdb_engine/auth/users.py +1516 -0
- mdb_engine/auth/utils.py +614 -0
- mdb_engine/cli/__init__.py +13 -0
- mdb_engine/cli/commands/__init__.py +7 -0
- mdb_engine/cli/commands/generate.py +105 -0
- mdb_engine/cli/commands/migrate.py +83 -0
- mdb_engine/cli/commands/show.py +70 -0
- mdb_engine/cli/commands/validate.py +63 -0
- mdb_engine/cli/main.py +41 -0
- mdb_engine/cli/utils.py +92 -0
- mdb_engine/config.py +217 -0
- mdb_engine/constants.py +160 -0
- mdb_engine/core/README.md +542 -0
- mdb_engine/core/__init__.py +42 -0
- mdb_engine/core/app_registration.py +392 -0
- mdb_engine/core/connection.py +243 -0
- mdb_engine/core/engine.py +749 -0
- mdb_engine/core/index_management.py +162 -0
- mdb_engine/core/manifest.py +2793 -0
- mdb_engine/core/seeding.py +179 -0
- mdb_engine/core/service_initialization.py +355 -0
- mdb_engine/core/types.py +413 -0
- mdb_engine/database/README.md +522 -0
- mdb_engine/database/__init__.py +31 -0
- mdb_engine/database/abstraction.py +635 -0
- mdb_engine/database/connection.py +387 -0
- mdb_engine/database/scoped_wrapper.py +1721 -0
- mdb_engine/embeddings/README.md +184 -0
- mdb_engine/embeddings/__init__.py +62 -0
- mdb_engine/embeddings/dependencies.py +193 -0
- mdb_engine/embeddings/service.py +759 -0
- mdb_engine/exceptions.py +167 -0
- mdb_engine/indexes/README.md +651 -0
- mdb_engine/indexes/__init__.py +21 -0
- mdb_engine/indexes/helpers.py +145 -0
- mdb_engine/indexes/manager.py +895 -0
- mdb_engine/memory/README.md +451 -0
- mdb_engine/memory/__init__.py +30 -0
- mdb_engine/memory/service.py +1285 -0
- mdb_engine/observability/README.md +515 -0
- mdb_engine/observability/__init__.py +42 -0
- mdb_engine/observability/health.py +296 -0
- mdb_engine/observability/logging.py +161 -0
- mdb_engine/observability/metrics.py +297 -0
- mdb_engine/routing/README.md +462 -0
- mdb_engine/routing/__init__.py +73 -0
- mdb_engine/routing/websockets.py +813 -0
- mdb_engine/utils/__init__.py +7 -0
- mdb_engine-0.1.6.dist-info/METADATA +213 -0
- mdb_engine-0.1.6.dist-info/RECORD +75 -0
- mdb_engine-0.1.6.dist-info/WHEEL +5 -0
- mdb_engine-0.1.6.dist-info/entry_points.txt +2 -0
- mdb_engine-0.1.6.dist-info/licenses/LICENSE +661 -0
- mdb_engine-0.1.6.dist-info/top_level.txt +1 -0
mdb_engine/core/types.py
ADDED
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Type definitions for MDB_ENGINE core structures.
|
|
3
|
+
|
|
4
|
+
This module provides TypedDict definitions for manifest structures,
|
|
5
|
+
app configurations, and service configurations to improve type safety
|
|
6
|
+
throughout the codebase.
|
|
7
|
+
|
|
8
|
+
This module is part of MDB_ENGINE - MongoDB Engine.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from typing import (TYPE_CHECKING, Any, Dict, List, Literal, Optional,
|
|
12
|
+
TypedDict, Union)
|
|
13
|
+
|
|
14
|
+
if TYPE_CHECKING:
|
|
15
|
+
from ..memory import Mem0MemoryService
|
|
16
|
+
else:
|
|
17
|
+
Mem0MemoryService = Any
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
# ============================================================================
|
|
21
|
+
# Index Definition Types
|
|
22
|
+
# ============================================================================
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class IndexKeysDict(TypedDict, total=False):
|
|
26
|
+
"""Index keys definition - field name to sort order."""
|
|
27
|
+
|
|
28
|
+
pass # Dynamic keys: field names -> 1, -1, "text", "2dsphere", etc.
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class IndexDefinitionDict(TypedDict, total=False):
|
|
32
|
+
"""Index definition structure."""
|
|
33
|
+
|
|
34
|
+
name: str
|
|
35
|
+
type: Literal[
|
|
36
|
+
"regular",
|
|
37
|
+
"vectorSearch",
|
|
38
|
+
"search",
|
|
39
|
+
"text",
|
|
40
|
+
"geospatial",
|
|
41
|
+
"ttl",
|
|
42
|
+
"partial",
|
|
43
|
+
"hybrid",
|
|
44
|
+
]
|
|
45
|
+
keys: Union[Dict[str, Union[int, str]], List[List[Union[str, int]]]]
|
|
46
|
+
unique: bool
|
|
47
|
+
sparse: bool
|
|
48
|
+
background: bool
|
|
49
|
+
expireAfterSeconds: int
|
|
50
|
+
partialFilterExpression: Dict[str, Any]
|
|
51
|
+
weights: Dict[str, int] # For text indexes
|
|
52
|
+
default_language: str # For text indexes
|
|
53
|
+
language_override: str # For text indexes
|
|
54
|
+
textIndexVersion: int # For text indexes
|
|
55
|
+
# Vector search specific
|
|
56
|
+
fields: List[Dict[str, Any]] # For vectorSearch indexes
|
|
57
|
+
# Search index specific
|
|
58
|
+
mappings: Dict[str, Any] # For search indexes
|
|
59
|
+
# Geospatial specific
|
|
60
|
+
bucketSize: float # For geoHaystack
|
|
61
|
+
# TTL specific
|
|
62
|
+
expireAfter: int # Alias for expireAfterSeconds
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class ManagedIndexesDict(TypedDict):
|
|
66
|
+
"""Managed indexes - collection name to list of index definitions."""
|
|
67
|
+
|
|
68
|
+
pass # Dynamic: collection_name -> List[IndexDefinitionDict]
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
# ============================================================================
|
|
72
|
+
# Auth Configuration Types
|
|
73
|
+
# ============================================================================
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class AuthAuthorizationDict(TypedDict, total=False):
|
|
77
|
+
"""Authorization configuration."""
|
|
78
|
+
|
|
79
|
+
# Casbin-specific
|
|
80
|
+
model: str
|
|
81
|
+
policies_collection: str
|
|
82
|
+
link_users_roles: bool
|
|
83
|
+
default_roles: List[str]
|
|
84
|
+
# OSO-specific
|
|
85
|
+
api_key: Optional[str]
|
|
86
|
+
url: Optional[str]
|
|
87
|
+
initial_roles: List[Dict[str, str]]
|
|
88
|
+
initial_policies: List[Dict[str, str]]
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
class AuthPolicyDict(TypedDict, total=False):
|
|
92
|
+
"""Authorization policy configuration."""
|
|
93
|
+
|
|
94
|
+
required: bool
|
|
95
|
+
provider: Literal["casbin", "oso", "custom"]
|
|
96
|
+
authorization: AuthAuthorizationDict
|
|
97
|
+
allowed_roles: List[str]
|
|
98
|
+
allowed_users: List[str]
|
|
99
|
+
denied_users: List[str]
|
|
100
|
+
required_permissions: List[str]
|
|
101
|
+
custom_resource: str
|
|
102
|
+
custom_actions: List[Literal["access", "read", "write", "admin"]]
|
|
103
|
+
allow_anonymous: bool
|
|
104
|
+
owner_can_access: bool
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
class DemoUserDict(TypedDict, total=False):
|
|
108
|
+
"""Demo user configuration."""
|
|
109
|
+
|
|
110
|
+
email: str
|
|
111
|
+
password: str
|
|
112
|
+
role: str
|
|
113
|
+
auto_create: bool
|
|
114
|
+
link_to_platform: bool
|
|
115
|
+
extra_data: Dict[str, Any]
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
class UsersConfigDict(TypedDict, total=False):
|
|
119
|
+
"""User management configuration."""
|
|
120
|
+
|
|
121
|
+
enabled: bool
|
|
122
|
+
strategy: Literal["app_users", "anonymous_session"]
|
|
123
|
+
collection_name: str
|
|
124
|
+
session_cookie_name: str
|
|
125
|
+
session_ttl_seconds: int
|
|
126
|
+
allow_registration: bool
|
|
127
|
+
link_platform_users: bool
|
|
128
|
+
anonymous_user_prefix: str
|
|
129
|
+
user_id_field: str
|
|
130
|
+
demo_users: List[DemoUserDict]
|
|
131
|
+
auto_link_platform_demo: bool
|
|
132
|
+
demo_user_seed_strategy: Literal["auto", "manual", "disabled"]
|
|
133
|
+
enable_demo_user_access: bool
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
class AuthConfigDict(TypedDict, total=False):
|
|
137
|
+
"""Authentication and authorization configuration."""
|
|
138
|
+
|
|
139
|
+
policy: AuthPolicyDict
|
|
140
|
+
users: UsersConfigDict
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
# ============================================================================
|
|
144
|
+
# Token Management Types
|
|
145
|
+
# ============================================================================
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
class RateLimitingConfigDict(TypedDict, total=False):
|
|
149
|
+
"""Rate limiting configuration for an endpoint."""
|
|
150
|
+
|
|
151
|
+
max_attempts: int
|
|
152
|
+
window_seconds: int
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
class RateLimitingDict(TypedDict, total=False):
|
|
156
|
+
"""Rate limiting configuration."""
|
|
157
|
+
|
|
158
|
+
login: RateLimitingConfigDict
|
|
159
|
+
register: RateLimitingConfigDict
|
|
160
|
+
refresh: RateLimitingConfigDict
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
class PasswordPolicyDict(TypedDict, total=False):
|
|
164
|
+
"""Password policy configuration."""
|
|
165
|
+
|
|
166
|
+
allow_plain_text: bool
|
|
167
|
+
min_length: int
|
|
168
|
+
require_uppercase: bool
|
|
169
|
+
require_lowercase: bool
|
|
170
|
+
require_numbers: bool
|
|
171
|
+
require_special: bool
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
class SessionFingerprintingDict(TypedDict, total=False):
|
|
175
|
+
"""Session fingerprinting configuration."""
|
|
176
|
+
|
|
177
|
+
enabled: bool
|
|
178
|
+
validate_on_login: bool
|
|
179
|
+
validate_on_refresh: bool
|
|
180
|
+
validate_on_request: bool
|
|
181
|
+
strict_mode: bool
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
class AccountLockoutDict(TypedDict, total=False):
|
|
185
|
+
"""Account lockout configuration."""
|
|
186
|
+
|
|
187
|
+
enabled: bool
|
|
188
|
+
max_failed_attempts: int
|
|
189
|
+
lockout_duration_seconds: int
|
|
190
|
+
reset_on_success: bool
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
class IPValidationDict(TypedDict, total=False):
|
|
194
|
+
"""IP validation configuration."""
|
|
195
|
+
|
|
196
|
+
enabled: bool
|
|
197
|
+
strict: bool
|
|
198
|
+
allow_ip_change: bool
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
class TokenFingerprintingDict(TypedDict, total=False):
|
|
202
|
+
"""Token fingerprinting configuration."""
|
|
203
|
+
|
|
204
|
+
enabled: bool
|
|
205
|
+
bind_to_device: bool
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
class SecurityConfigDict(TypedDict, total=False):
|
|
209
|
+
"""Security configuration."""
|
|
210
|
+
|
|
211
|
+
require_https: bool
|
|
212
|
+
cookie_secure: Literal["auto", "true", "false"]
|
|
213
|
+
cookie_samesite: Literal["strict", "lax", "none"]
|
|
214
|
+
cookie_httponly: bool
|
|
215
|
+
csrf_protection: bool
|
|
216
|
+
rate_limiting: RateLimitingDict
|
|
217
|
+
password_policy: PasswordPolicyDict
|
|
218
|
+
session_fingerprinting: SessionFingerprintingDict
|
|
219
|
+
account_lockout: AccountLockoutDict
|
|
220
|
+
ip_validation: IPValidationDict
|
|
221
|
+
token_fingerprinting: TokenFingerprintingDict
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
class TokenManagementDict(TypedDict, total=False):
|
|
225
|
+
"""Token management configuration."""
|
|
226
|
+
|
|
227
|
+
enabled: bool
|
|
228
|
+
access_token_ttl: int
|
|
229
|
+
refresh_token_ttl: int
|
|
230
|
+
token_rotation: bool
|
|
231
|
+
max_sessions_per_user: int
|
|
232
|
+
session_inactivity_timeout: int
|
|
233
|
+
security: SecurityConfigDict
|
|
234
|
+
auto_setup: bool
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
# ============================================================================
|
|
238
|
+
# WebSocket Configuration Types
|
|
239
|
+
# ============================================================================
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
class WebSocketAuthDict(TypedDict, total=False):
|
|
243
|
+
"""WebSocket authentication configuration."""
|
|
244
|
+
|
|
245
|
+
required: bool
|
|
246
|
+
allow_anonymous: bool
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
class WebSocketEndpointDict(TypedDict, total=False):
|
|
250
|
+
"""WebSocket endpoint configuration."""
|
|
251
|
+
|
|
252
|
+
path: str
|
|
253
|
+
auth: WebSocketAuthDict
|
|
254
|
+
description: str
|
|
255
|
+
ping_interval: int
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
class WebSocketsDict(TypedDict):
|
|
259
|
+
"""WebSocket endpoints configuration."""
|
|
260
|
+
|
|
261
|
+
pass # Dynamic: endpoint_name -> WebSocketEndpointDict
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
# ============================================================================
|
|
265
|
+
# Memory Configuration Types
|
|
266
|
+
# ============================================================================
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
class MemoryConfigDict(TypedDict, total=False):
|
|
270
|
+
"""Mem0 memory service configuration."""
|
|
271
|
+
|
|
272
|
+
enabled: bool
|
|
273
|
+
collection_name: str
|
|
274
|
+
embedding_model_dims: int
|
|
275
|
+
enable_graph: bool
|
|
276
|
+
infer: bool
|
|
277
|
+
embedding_model: str
|
|
278
|
+
chat_model: str
|
|
279
|
+
temperature: float
|
|
280
|
+
async_mode: bool
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
# ============================================================================
|
|
284
|
+
# Embedding Configuration Types
|
|
285
|
+
# ============================================================================
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
class EmbeddingConfigDict(TypedDict, total=False):
|
|
289
|
+
"""Embedding service configuration."""
|
|
290
|
+
|
|
291
|
+
enabled: bool
|
|
292
|
+
max_tokens_per_chunk: int
|
|
293
|
+
tokenizer_model: str
|
|
294
|
+
default_embedding_model: str
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
# ============================================================================
|
|
298
|
+
# Observability Configuration Types
|
|
299
|
+
# ============================================================================
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
class HealthChecksConfigDict(TypedDict, total=False):
|
|
303
|
+
"""Health check configuration."""
|
|
304
|
+
|
|
305
|
+
enabled: bool
|
|
306
|
+
endpoint: str
|
|
307
|
+
interval_seconds: int
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
class MetricsConfigDict(TypedDict, total=False):
|
|
311
|
+
"""Metrics collection configuration."""
|
|
312
|
+
|
|
313
|
+
enabled: bool
|
|
314
|
+
collect_operation_metrics: bool
|
|
315
|
+
collect_performance_metrics: bool
|
|
316
|
+
custom_metrics: List[str]
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
class LoggingConfigDict(TypedDict, total=False):
|
|
320
|
+
"""Logging configuration."""
|
|
321
|
+
|
|
322
|
+
level: Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]
|
|
323
|
+
format: Literal["json", "text"]
|
|
324
|
+
include_request_id: bool
|
|
325
|
+
log_sensitive_data: bool
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
class ObservabilityConfigDict(TypedDict, total=False):
|
|
329
|
+
"""Observability configuration."""
|
|
330
|
+
|
|
331
|
+
health_checks: HealthChecksConfigDict
|
|
332
|
+
metrics: MetricsConfigDict
|
|
333
|
+
logging: LoggingConfigDict
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
# ============================================================================
|
|
337
|
+
# CORS Configuration Types
|
|
338
|
+
# ============================================================================
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
class CORSConfigDict(TypedDict, total=False):
|
|
342
|
+
"""CORS configuration."""
|
|
343
|
+
|
|
344
|
+
enabled: bool
|
|
345
|
+
allow_origins: List[str]
|
|
346
|
+
allow_credentials: bool
|
|
347
|
+
allow_methods: List[
|
|
348
|
+
Literal["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS", "HEAD", "*"]
|
|
349
|
+
]
|
|
350
|
+
allow_headers: List[str]
|
|
351
|
+
expose_headers: List[str]
|
|
352
|
+
max_age: int
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
# ============================================================================
|
|
356
|
+
# Initial Data Types
|
|
357
|
+
# ============================================================================
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
class InitialDataDict(TypedDict):
|
|
361
|
+
"""Initial data seeding configuration."""
|
|
362
|
+
|
|
363
|
+
pass # Dynamic: collection_name -> List[Dict[str, Any]]
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
# ============================================================================
|
|
367
|
+
# Main Manifest Type
|
|
368
|
+
# ============================================================================
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
class ManifestDict(TypedDict, total=False):
|
|
372
|
+
"""Main manifest structure."""
|
|
373
|
+
|
|
374
|
+
schema_version: str
|
|
375
|
+
slug: str
|
|
376
|
+
name: str
|
|
377
|
+
description: Optional[str]
|
|
378
|
+
status: Literal["active", "draft", "archived", "inactive"]
|
|
379
|
+
auth_required: bool # Backward compatibility
|
|
380
|
+
auth: Optional[AuthConfigDict]
|
|
381
|
+
token_management: Optional[TokenManagementDict]
|
|
382
|
+
data_scope: List[str]
|
|
383
|
+
pip_deps: List[str]
|
|
384
|
+
managed_indexes: Optional[ManagedIndexesDict]
|
|
385
|
+
collection_settings: Optional[Dict[str, Dict[str, Any]]]
|
|
386
|
+
websockets: Optional[WebSocketsDict]
|
|
387
|
+
embedding_config: Optional[EmbeddingConfigDict]
|
|
388
|
+
memory_config: Optional[MemoryConfigDict]
|
|
389
|
+
cors: Optional[CORSConfigDict]
|
|
390
|
+
observability: Optional[ObservabilityConfigDict]
|
|
391
|
+
initial_data: Optional[InitialDataDict]
|
|
392
|
+
developer_id: Optional[str]
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
# ============================================================================
|
|
396
|
+
# Health and Metrics Types
|
|
397
|
+
# ============================================================================
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
class HealthStatusDict(TypedDict, total=False):
|
|
401
|
+
"""Health status response."""
|
|
402
|
+
|
|
403
|
+
status: Literal["healthy", "degraded", "unhealthy"]
|
|
404
|
+
checks: Dict[str, Dict[str, Any]]
|
|
405
|
+
timestamp: str
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
class MetricsDict(TypedDict, total=False):
|
|
409
|
+
"""Metrics response."""
|
|
410
|
+
|
|
411
|
+
operations: Dict[str, Dict[str, Any]]
|
|
412
|
+
summary: Dict[str, Any]
|
|
413
|
+
timestamp: str
|