strapi-kit 0.0.1__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.
- strapi_kit/__init__.py +97 -0
- strapi_kit/__version__.py +15 -0
- strapi_kit/_version.py +34 -0
- strapi_kit/auth/__init__.py +7 -0
- strapi_kit/auth/api_token.py +48 -0
- strapi_kit/cache/__init__.py +5 -0
- strapi_kit/cache/schema_cache.py +211 -0
- strapi_kit/client/__init__.py +11 -0
- strapi_kit/client/async_client.py +1032 -0
- strapi_kit/client/base.py +460 -0
- strapi_kit/client/sync_client.py +980 -0
- strapi_kit/config_provider.py +368 -0
- strapi_kit/exceptions/__init__.py +37 -0
- strapi_kit/exceptions/errors.py +205 -0
- strapi_kit/export/__init__.py +10 -0
- strapi_kit/export/exporter.py +384 -0
- strapi_kit/export/importer.py +619 -0
- strapi_kit/export/media_handler.py +322 -0
- strapi_kit/export/relation_resolver.py +172 -0
- strapi_kit/models/__init__.py +104 -0
- strapi_kit/models/bulk.py +69 -0
- strapi_kit/models/config.py +174 -0
- strapi_kit/models/enums.py +97 -0
- strapi_kit/models/export_format.py +166 -0
- strapi_kit/models/import_options.py +142 -0
- strapi_kit/models/request/__init__.py +1 -0
- strapi_kit/models/request/fields.py +65 -0
- strapi_kit/models/request/filters.py +611 -0
- strapi_kit/models/request/pagination.py +168 -0
- strapi_kit/models/request/populate.py +281 -0
- strapi_kit/models/request/query.py +429 -0
- strapi_kit/models/request/sort.py +147 -0
- strapi_kit/models/response/__init__.py +1 -0
- strapi_kit/models/response/base.py +75 -0
- strapi_kit/models/response/component.py +67 -0
- strapi_kit/models/response/media.py +91 -0
- strapi_kit/models/response/meta.py +44 -0
- strapi_kit/models/response/normalized.py +168 -0
- strapi_kit/models/response/relation.py +48 -0
- strapi_kit/models/response/v4.py +70 -0
- strapi_kit/models/response/v5.py +57 -0
- strapi_kit/models/schema.py +93 -0
- strapi_kit/operations/__init__.py +16 -0
- strapi_kit/operations/media.py +226 -0
- strapi_kit/operations/streaming.py +144 -0
- strapi_kit/parsers/__init__.py +5 -0
- strapi_kit/parsers/version_detecting.py +171 -0
- strapi_kit/protocols.py +455 -0
- strapi_kit/utils/__init__.py +15 -0
- strapi_kit/utils/rate_limiter.py +201 -0
- strapi_kit/utils/uid.py +88 -0
- strapi_kit-0.0.1.dist-info/METADATA +1098 -0
- strapi_kit-0.0.1.dist-info/RECORD +55 -0
- strapi_kit-0.0.1.dist-info/WHEEL +4 -0
- strapi_kit-0.0.1.dist-info/licenses/LICENSE +21 -0
strapi_kit/utils/uid.py
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"""Content type UID utilities.
|
|
2
|
+
|
|
3
|
+
This module provides centralized functions for handling Strapi content type UIDs,
|
|
4
|
+
including conversion to API endpoints with proper pluralization.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def uid_to_endpoint(uid: str) -> str:
|
|
9
|
+
"""Convert content type UID to API endpoint.
|
|
10
|
+
|
|
11
|
+
Handles common English pluralization patterns. For custom pluralization
|
|
12
|
+
(e.g., "person" -> "people"), use the schema's plural_name instead.
|
|
13
|
+
|
|
14
|
+
Args:
|
|
15
|
+
uid: Content type UID (e.g., "api::article.article", "api::blog.post")
|
|
16
|
+
|
|
17
|
+
Returns:
|
|
18
|
+
API endpoint (e.g., "articles", "posts")
|
|
19
|
+
|
|
20
|
+
Examples:
|
|
21
|
+
>>> uid_to_endpoint("api::article.article")
|
|
22
|
+
'articles'
|
|
23
|
+
>>> uid_to_endpoint("api::category.category")
|
|
24
|
+
'categories'
|
|
25
|
+
>>> uid_to_endpoint("api::class.class")
|
|
26
|
+
'classes'
|
|
27
|
+
>>> uid_to_endpoint("api::blog.post")
|
|
28
|
+
'posts'
|
|
29
|
+
"""
|
|
30
|
+
# Extract the model name (after the dot) and pluralize it
|
|
31
|
+
# For "api::blog.post", we want "post" -> "posts", not "blog" -> "blogs"
|
|
32
|
+
parts = uid.split("::")
|
|
33
|
+
if len(parts) == 2:
|
|
34
|
+
api_model = parts[1]
|
|
35
|
+
# Get model name (after the dot if present)
|
|
36
|
+
if "." in api_model:
|
|
37
|
+
name = api_model.split(".")[1]
|
|
38
|
+
else:
|
|
39
|
+
name = api_model
|
|
40
|
+
# Handle common irregular plurals
|
|
41
|
+
if name.endswith("y") and not name.endswith(("ay", "ey", "oy", "uy")):
|
|
42
|
+
return name[:-1] + "ies" # category -> categories
|
|
43
|
+
if name.endswith(("s", "x", "z", "ch", "sh")):
|
|
44
|
+
return name + "es" # class -> classes
|
|
45
|
+
if not name.endswith("s"):
|
|
46
|
+
return name + "s"
|
|
47
|
+
return name
|
|
48
|
+
return uid
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def extract_model_name(uid: str) -> str:
|
|
52
|
+
"""Extract the model name from a content type UID.
|
|
53
|
+
|
|
54
|
+
Args:
|
|
55
|
+
uid: Content type UID (e.g., "api::article.article")
|
|
56
|
+
|
|
57
|
+
Returns:
|
|
58
|
+
Model name (e.g., "article")
|
|
59
|
+
|
|
60
|
+
Examples:
|
|
61
|
+
>>> extract_model_name("api::article.article")
|
|
62
|
+
'article'
|
|
63
|
+
>>> extract_model_name("plugin::users-permissions.user")
|
|
64
|
+
'user'
|
|
65
|
+
"""
|
|
66
|
+
parts = uid.split("::")
|
|
67
|
+
if len(parts) == 2:
|
|
68
|
+
model_parts = parts[1].split(".")
|
|
69
|
+
return model_parts[-1] if model_parts else parts[1]
|
|
70
|
+
return uid
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def is_api_content_type(uid: str) -> bool:
|
|
74
|
+
"""Check if UID is an API content type (vs plugin).
|
|
75
|
+
|
|
76
|
+
Args:
|
|
77
|
+
uid: Content type UID
|
|
78
|
+
|
|
79
|
+
Returns:
|
|
80
|
+
True if API content type, False if plugin or other
|
|
81
|
+
|
|
82
|
+
Examples:
|
|
83
|
+
>>> is_api_content_type("api::article.article")
|
|
84
|
+
True
|
|
85
|
+
>>> is_api_content_type("plugin::users-permissions.user")
|
|
86
|
+
False
|
|
87
|
+
"""
|
|
88
|
+
return uid.startswith("api::")
|