§22 S2: collection read helpers (list/get/subfolder)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -48,3 +48,39 @@ def collection_type(collection_id: str) -> str:
|
||||
"SELECT type FROM collections WHERE id = ?", (collection_id,)
|
||||
).fetchone()
|
||||
return row["type"] if row and row["type"] else "document"
|
||||
|
||||
|
||||
def subfolder_of(collection_id: str) -> str:
|
||||
"""The content-repo subfolder a collection lives under (§22.3). Empty string
|
||||
for the default collection (entries at the repo root `rfcs/`)."""
|
||||
row = db.conn().execute(
|
||||
"SELECT subfolder FROM collections WHERE id = ?", (collection_id,)
|
||||
).fetchone()
|
||||
return (row["subfolder"] if row else "") or ""
|
||||
|
||||
|
||||
def get_collection(collection_id: str) -> dict | None:
|
||||
"""The full collection row as a dict, or None if unknown."""
|
||||
row = db.conn().execute(
|
||||
"SELECT id, project_id, type, subfolder, initial_state, visibility, name "
|
||||
"FROM collections WHERE id = ?",
|
||||
(collection_id,),
|
||||
).fetchone()
|
||||
return dict(row) if row else None
|
||||
|
||||
|
||||
def list_collections(project_id: str, include_unlisted: bool = False) -> list[dict]:
|
||||
"""Collections in a project, the default first then by name (§22.5). `unlisted`
|
||||
is omitted from enumeration unless include_unlisted (a direct-id read or the
|
||||
corpus mirror, which serves every collection)."""
|
||||
rows = db.conn().execute(
|
||||
"SELECT id, project_id, type, subfolder, initial_state, visibility, name "
|
||||
"FROM collections WHERE project_id = ? ORDER BY (id != 'default'), name, id",
|
||||
(project_id,),
|
||||
).fetchall()
|
||||
out: list[dict] = []
|
||||
for r in rows:
|
||||
if not include_unlisted and r["visibility"] == "unlisted":
|
||||
continue
|
||||
out.append(dict(r))
|
||||
return out
|
||||
|
||||
Reference in New Issue
Block a user