mirror of
https://github.com/VectifyAI/PageIndex.git
synced 2026-07-24 21:41:04 +02:00
fix: track pageindex/_validation.py
360ab66and0a78f1dmoved collection-name validation into this new module and import it from cloud.py/local.py/sqlite.py, but the file itself was never added — a fresh checkout of dev fails at import.
This commit is contained in:
parent
0a78f1d85d
commit
0584ac8bc5
1 changed files with 33 additions and 0 deletions
33
pageindex/_validation.py
Normal file
33
pageindex/_validation.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from .errors import PageIndexError
|
||||
|
||||
|
||||
MAX_COLLECTION_NAME_LENGTH = 255
|
||||
|
||||
|
||||
def validate_collection_name(name: str) -> None:
|
||||
"""Validate the collection-name contract shared by local and cloud modes.
|
||||
|
||||
Collection names are logical identifiers, not filesystem paths. Keep this
|
||||
in sync with the cloud folder API, which accepts any non-empty Unicode
|
||||
string up to 255 characters.
|
||||
"""
|
||||
invalid = (
|
||||
not isinstance(name, str)
|
||||
or not name
|
||||
or len(name) > MAX_COLLECTION_NAME_LENGTH
|
||||
)
|
||||
if not invalid:
|
||||
try:
|
||||
name.encode("utf-8")
|
||||
except UnicodeEncodeError:
|
||||
# JSON/database boundaries require Unicode scalar values; lone UTF-16
|
||||
# surrogates are Python strings but cannot be encoded as valid UTF-8.
|
||||
invalid = True
|
||||
if invalid:
|
||||
raise PageIndexError(
|
||||
f"Invalid collection name: {name!r}. "
|
||||
f"Must be a non-empty string of valid Unicode with at most "
|
||||
f"{MAX_COLLECTION_NAME_LENGTH} characters."
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue