Rename terminology to industry standard terms
- Grove → Project - Tree → Package - Fruit → Artifact - Graft → Tag - Cultivate → Upload - Harvest → Download Updated across: - Backend models, schemas, and routes - Frontend types, API client, and components - README documentation - API endpoints now use /project/:project/packages pattern 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
113
README.md
113
README.md
@@ -2,7 +2,7 @@
|
||||
|
||||
**Content-Addressable Storage System**
|
||||
|
||||
Orchard is a centralized binary artifact storage system that provides content-addressable storage with automatic deduplication, flexible access control, and multi-format package support. Like an orchard that cultivates and distributes fruit, Orchard nurtures and distributes the products of software builds.
|
||||
Orchard is a centralized binary artifact storage system that provides content-addressable storage with automatic deduplication, flexible access control, and multi-format package support.
|
||||
|
||||
## Tech Stack
|
||||
|
||||
@@ -17,11 +17,11 @@ Orchard is a centralized binary artifact storage system that provides content-ad
|
||||
### Currently Implemented
|
||||
|
||||
- **Content-Addressable Storage** - Artifacts are stored and referenced by their SHA256 hash, ensuring deduplication and data integrity
|
||||
- **Grove/Tree/Fruit Hierarchy** - Organized storage structure:
|
||||
- **Grove** - Top-level project container
|
||||
- **Tree** - Named package within a grove
|
||||
- **Fruit** - Specific artifact instance identified by SHA256
|
||||
- **Grafts (Tags/Versions)** - Alias system for referencing artifacts by human-readable names (e.g., `v1.0.0`, `latest`, `stable`)
|
||||
- **Project/Package/Artifact Hierarchy** - Organized storage structure:
|
||||
- **Project** - Top-level organizational container
|
||||
- **Package** - Named collection within a project
|
||||
- **Artifact** - Specific content instance identified by SHA256
|
||||
- **Tags** - Alias system for referencing artifacts by human-readable names (e.g., `v1.0.0`, `latest`, `stable`)
|
||||
- **S3-Compatible Backend** - Uses MinIO (or any S3-compatible storage) for artifact storage
|
||||
- **PostgreSQL Metadata** - Relational database for metadata, access control, and audit trails
|
||||
- **REST API** - Full HTTP API for all operations
|
||||
@@ -35,17 +35,17 @@ Orchard is a centralized binary artifact storage system that provides content-ad
|
||||
|--------|----------|-------------|
|
||||
| `GET` | `/` | Web UI |
|
||||
| `GET` | `/health` | Health check |
|
||||
| `GET` | `/api/v1/groves` | List all groves |
|
||||
| `POST` | `/api/v1/groves` | Create a new grove |
|
||||
| `GET` | `/api/v1/groves/:grove` | Get grove details |
|
||||
| `GET` | `/api/v1/grove/:grove/trees` | List trees in a grove |
|
||||
| `POST` | `/api/v1/grove/:grove/trees` | Create a new tree |
|
||||
| `POST` | `/api/v1/grove/:grove/:tree/cultivate` | Upload an artifact |
|
||||
| `GET` | `/api/v1/grove/:grove/:tree/+/:ref` | Download an artifact |
|
||||
| `GET` | `/api/v1/grove/:grove/:tree/grafts` | List all tags/versions |
|
||||
| `POST` | `/api/v1/grove/:grove/:tree/graft` | Create a tag |
|
||||
| `GET` | `/api/v1/grove/:grove/:tree/consumers` | List consumers of a tree |
|
||||
| `GET` | `/api/v1/fruit/:id` | Get fruit metadata by hash |
|
||||
| `GET` | `/api/v1/projects` | List all projects |
|
||||
| `POST` | `/api/v1/projects` | Create a new project |
|
||||
| `GET` | `/api/v1/projects/:project` | Get project details |
|
||||
| `GET` | `/api/v1/project/:project/packages` | List packages in a project |
|
||||
| `POST` | `/api/v1/project/:project/packages` | Create a new package |
|
||||
| `POST` | `/api/v1/project/:project/:package/upload` | Upload an artifact |
|
||||
| `GET` | `/api/v1/project/:project/:package/+/:ref` | Download an artifact |
|
||||
| `GET` | `/api/v1/project/:project/:package/tags` | List all tags |
|
||||
| `POST` | `/api/v1/project/:project/:package/tags` | Create a tag |
|
||||
| `GET` | `/api/v1/project/:project/:package/consumers` | List consumers of a package |
|
||||
| `GET` | `/api/v1/artifact/:id` | Get artifact metadata by hash |
|
||||
|
||||
### Reference Formats
|
||||
|
||||
@@ -55,7 +55,7 @@ When downloading artifacts, the `:ref` parameter supports multiple formats:
|
||||
- `v1.0.0` - Version tag
|
||||
- `tag:stable` - Explicit tag reference
|
||||
- `version:2024.1` - Version reference
|
||||
- `fruit:a3f5d8e12b4c6789...` - Direct SHA256 hash reference
|
||||
- `artifact:a3f5d8e12b4c6789...` - Direct SHA256 hash reference
|
||||
|
||||
## Quick Start
|
||||
|
||||
@@ -115,26 +115,26 @@ The frontend dev server proxies API requests to `localhost:8080`.
|
||||
|
||||
## Usage Examples
|
||||
|
||||
### Create a Grove
|
||||
### Create a Project
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:8080/api/v1/groves \
|
||||
curl -X POST http://localhost:8080/api/v1/projects \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"name": "my-project", "description": "My project artifacts", "is_public": true}'
|
||||
```
|
||||
|
||||
### Create a Tree
|
||||
### Create a Package
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:8080/api/v1/grove/my-project/trees \
|
||||
curl -X POST http://localhost:8080/api/v1/project/my-project/packages \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"name": "releases", "description": "Release builds"}'
|
||||
```
|
||||
|
||||
### Upload an Artifact (Cultivate)
|
||||
### Upload an Artifact
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:8080/api/v1/grove/my-project/releases/cultivate \
|
||||
curl -X POST http://localhost:8080/api/v1/project/my-project/releases/upload \
|
||||
-F "file=@./build/app-v1.0.0.tar.gz" \
|
||||
-F "tag=v1.0.0"
|
||||
```
|
||||
@@ -142,39 +142,39 @@ curl -X POST http://localhost:8080/api/v1/grove/my-project/releases/cultivate \
|
||||
Response:
|
||||
```json
|
||||
{
|
||||
"fruit_id": "a3f5d8e12b4c67890abcdef1234567890abcdef1234567890abcdef12345678",
|
||||
"artifact_id": "a3f5d8e12b4c67890abcdef1234567890abcdef1234567890abcdef12345678",
|
||||
"size": 1048576,
|
||||
"grove": "my-project",
|
||||
"tree": "releases",
|
||||
"project": "my-project",
|
||||
"package": "releases",
|
||||
"tag": "v1.0.0"
|
||||
}
|
||||
```
|
||||
|
||||
### Download an Artifact (Harvest)
|
||||
### Download an Artifact
|
||||
|
||||
```bash
|
||||
# By tag
|
||||
curl -O http://localhost:8080/api/v1/grove/my-project/releases/+/v1.0.0
|
||||
curl -O http://localhost:8080/api/v1/project/my-project/releases/+/v1.0.0
|
||||
|
||||
# By fruit ID
|
||||
curl -O http://localhost:8080/api/v1/grove/my-project/releases/+/fruit:a3f5d8e12b4c6789...
|
||||
# By artifact ID
|
||||
curl -O http://localhost:8080/api/v1/project/my-project/releases/+/artifact:a3f5d8e12b4c6789...
|
||||
|
||||
# Using the spec-compliant URL pattern
|
||||
curl -O http://localhost:8080/grove/my-project/releases/+/latest
|
||||
# Using the short URL pattern
|
||||
curl -O http://localhost:8080/project/my-project/releases/+/latest
|
||||
```
|
||||
|
||||
### Create a Tag (Graft)
|
||||
### Create a Tag
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:8080/api/v1/grove/my-project/releases/graft \
|
||||
curl -X POST http://localhost:8080/api/v1/project/my-project/releases/tags \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"name": "stable", "fruit_id": "a3f5d8e12b4c6789..."}'
|
||||
-d '{"name": "stable", "artifact_id": "a3f5d8e12b4c6789..."}'
|
||||
```
|
||||
|
||||
### Search by Fruit ID
|
||||
### Get Artifact by ID
|
||||
|
||||
```bash
|
||||
curl http://localhost:8080/api/v1/fruit/a3f5d8e12b4c67890abcdef1234567890abcdef1234567890abcdef12345678
|
||||
curl http://localhost:8080/api/v1/artifact/a3f5d8e12b4c67890abcdef1234567890abcdef1234567890abcdef12345678
|
||||
```
|
||||
|
||||
## Project Structure
|
||||
@@ -206,8 +206,6 @@ orchard/
|
||||
│ └── vite.config.ts
|
||||
├── helm/
|
||||
│ └── orchard/ # Helm chart
|
||||
├── migrations/
|
||||
│ └── 001_initial.sql # Database schema
|
||||
├── Dockerfile # Multi-stage build (Node + Python)
|
||||
├── docker-compose.yml # Local development stack
|
||||
└── .gitlab-ci.yml # CI/CD pipeline
|
||||
@@ -257,39 +255,26 @@ See `helm/orchard/values.yaml` for all configuration options.
|
||||
|
||||
### Core Tables
|
||||
|
||||
- **groves** - Top-level project containers
|
||||
- **trees** - Packages within groves
|
||||
- **fruits** - Content-addressable artifacts (SHA256)
|
||||
- **grafts** - Tags/aliases pointing to fruits
|
||||
- **graft_history** - Audit trail for tag changes
|
||||
- **harvests** - Upload event records
|
||||
- **projects** - Top-level organizational containers
|
||||
- **packages** - Collections within projects
|
||||
- **artifacts** - Content-addressable artifacts (SHA256)
|
||||
- **tags** - Aliases pointing to artifacts
|
||||
- **tag_history** - Audit trail for tag changes
|
||||
- **uploads** - Upload event records
|
||||
- **consumers** - Dependency tracking
|
||||
- **access_permissions** - Grove-level access control
|
||||
- **access_permissions** - Project-level access control
|
||||
- **api_keys** - Programmatic access tokens
|
||||
- **audit_logs** - Immutable operation logs
|
||||
|
||||
## Terminology
|
||||
|
||||
| Orchard Term | Traditional Term | Description |
|
||||
|--------------|------------------|-------------|
|
||||
| Grove | Project | Top-level organizational unit |
|
||||
| Tree | Package | Named collection of related artifacts |
|
||||
| Fruit | Instance | Specific content identified by SHA256 |
|
||||
| Seed | Dependency | Required package specification |
|
||||
| Harvest | Download/Fetch | Retrieve dependencies |
|
||||
| Cultivate | Upload/Publish | Store new artifact |
|
||||
| Graft | Alias/Tag | Alternative name for content |
|
||||
| Prune | Clean/GC | Remove unused local cache |
|
||||
|
||||
## Future Work
|
||||
|
||||
The following features from the specification are planned but not yet implemented:
|
||||
The following features are planned but not yet implemented:
|
||||
|
||||
- [ ] CLI tool (`orchard` command)
|
||||
- [ ] `orchard.ensure` file parsing
|
||||
- [ ] Lock file generation (`orchard.lock`)
|
||||
- [ ] Dependency file parsing
|
||||
- [ ] Lock file generation
|
||||
- [ ] Export/Import for air-gapped systems
|
||||
- [ ] Consumer notification (pollination)
|
||||
- [ ] Consumer notification
|
||||
- [ ] Automated update propagation
|
||||
- [ ] OIDC/SAML authentication
|
||||
- [ ] API key management
|
||||
|
||||
@@ -11,8 +11,8 @@ import uuid
|
||||
Base = declarative_base()
|
||||
|
||||
|
||||
class Grove(Base):
|
||||
__tablename__ = "groves"
|
||||
class Project(Base):
|
||||
__tablename__ = "projects"
|
||||
|
||||
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
name = Column(String(255), unique=True, nullable=False)
|
||||
@@ -22,39 +22,39 @@ class Grove(Base):
|
||||
updated_at = Column(DateTime(timezone=True), default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
created_by = Column(String(255), nullable=False)
|
||||
|
||||
trees = relationship("Tree", back_populates="grove", cascade="all, delete-orphan")
|
||||
permissions = relationship("AccessPermission", back_populates="grove", cascade="all, delete-orphan")
|
||||
packages = relationship("Package", back_populates="project", cascade="all, delete-orphan")
|
||||
permissions = relationship("AccessPermission", back_populates="project", cascade="all, delete-orphan")
|
||||
|
||||
__table_args__ = (
|
||||
Index("idx_groves_name", "name"),
|
||||
Index("idx_groves_created_by", "created_by"),
|
||||
Index("idx_projects_name", "name"),
|
||||
Index("idx_projects_created_by", "created_by"),
|
||||
)
|
||||
|
||||
|
||||
class Tree(Base):
|
||||
__tablename__ = "trees"
|
||||
class Package(Base):
|
||||
__tablename__ = "packages"
|
||||
|
||||
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
grove_id = Column(UUID(as_uuid=True), ForeignKey("groves.id", ondelete="CASCADE"), nullable=False)
|
||||
project_id = Column(UUID(as_uuid=True), ForeignKey("projects.id", ondelete="CASCADE"), nullable=False)
|
||||
name = Column(String(255), nullable=False)
|
||||
description = Column(Text)
|
||||
created_at = Column(DateTime(timezone=True), default=datetime.utcnow)
|
||||
updated_at = Column(DateTime(timezone=True), default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
|
||||
grove = relationship("Grove", back_populates="trees")
|
||||
grafts = relationship("Graft", back_populates="tree", cascade="all, delete-orphan")
|
||||
harvests = relationship("Harvest", back_populates="tree", cascade="all, delete-orphan")
|
||||
consumers = relationship("Consumer", back_populates="tree", cascade="all, delete-orphan")
|
||||
project = relationship("Project", back_populates="packages")
|
||||
tags = relationship("Tag", back_populates="package", cascade="all, delete-orphan")
|
||||
uploads = relationship("Upload", back_populates="package", cascade="all, delete-orphan")
|
||||
consumers = relationship("Consumer", back_populates="package", cascade="all, delete-orphan")
|
||||
|
||||
__table_args__ = (
|
||||
Index("idx_trees_grove_id", "grove_id"),
|
||||
Index("idx_trees_name", "name"),
|
||||
Index("idx_packages_project_id", "project_id"),
|
||||
Index("idx_packages_name", "name"),
|
||||
{"extend_existing": True},
|
||||
)
|
||||
|
||||
|
||||
class Fruit(Base):
|
||||
__tablename__ = "fruits"
|
||||
class Artifact(Base):
|
||||
__tablename__ = "artifacts"
|
||||
|
||||
id = Column(String(64), primary_key=True) # SHA256 hash
|
||||
size = Column(BigInteger, nullable=False)
|
||||
@@ -65,70 +65,70 @@ class Fruit(Base):
|
||||
ref_count = Column(Integer, default=1)
|
||||
s3_key = Column(String(1024), nullable=False)
|
||||
|
||||
grafts = relationship("Graft", back_populates="fruit")
|
||||
harvests = relationship("Harvest", back_populates="fruit")
|
||||
tags = relationship("Tag", back_populates="artifact")
|
||||
uploads = relationship("Upload", back_populates="artifact")
|
||||
|
||||
__table_args__ = (
|
||||
Index("idx_fruits_created_at", "created_at"),
|
||||
Index("idx_fruits_created_by", "created_by"),
|
||||
Index("idx_artifacts_created_at", "created_at"),
|
||||
Index("idx_artifacts_created_by", "created_by"),
|
||||
)
|
||||
|
||||
|
||||
class Graft(Base):
|
||||
__tablename__ = "grafts"
|
||||
class Tag(Base):
|
||||
__tablename__ = "tags"
|
||||
|
||||
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
tree_id = Column(UUID(as_uuid=True), ForeignKey("trees.id", ondelete="CASCADE"), nullable=False)
|
||||
package_id = Column(UUID(as_uuid=True), ForeignKey("packages.id", ondelete="CASCADE"), nullable=False)
|
||||
name = Column(String(255), nullable=False)
|
||||
fruit_id = Column(String(64), ForeignKey("fruits.id"), nullable=False)
|
||||
artifact_id = Column(String(64), ForeignKey("artifacts.id"), nullable=False)
|
||||
created_at = Column(DateTime(timezone=True), default=datetime.utcnow)
|
||||
created_by = Column(String(255), nullable=False)
|
||||
|
||||
tree = relationship("Tree", back_populates="grafts")
|
||||
fruit = relationship("Fruit", back_populates="grafts")
|
||||
history = relationship("GraftHistory", back_populates="graft", cascade="all, delete-orphan")
|
||||
package = relationship("Package", back_populates="tags")
|
||||
artifact = relationship("Artifact", back_populates="tags")
|
||||
history = relationship("TagHistory", back_populates="tag", cascade="all, delete-orphan")
|
||||
|
||||
__table_args__ = (
|
||||
Index("idx_grafts_tree_id", "tree_id"),
|
||||
Index("idx_grafts_fruit_id", "fruit_id"),
|
||||
Index("idx_tags_package_id", "package_id"),
|
||||
Index("idx_tags_artifact_id", "artifact_id"),
|
||||
)
|
||||
|
||||
|
||||
class GraftHistory(Base):
|
||||
__tablename__ = "graft_history"
|
||||
class TagHistory(Base):
|
||||
__tablename__ = "tag_history"
|
||||
|
||||
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
graft_id = Column(UUID(as_uuid=True), ForeignKey("grafts.id", ondelete="CASCADE"), nullable=False)
|
||||
old_fruit_id = Column(String(64), ForeignKey("fruits.id"))
|
||||
new_fruit_id = Column(String(64), ForeignKey("fruits.id"), nullable=False)
|
||||
tag_id = Column(UUID(as_uuid=True), ForeignKey("tags.id", ondelete="CASCADE"), nullable=False)
|
||||
old_artifact_id = Column(String(64), ForeignKey("artifacts.id"))
|
||||
new_artifact_id = Column(String(64), ForeignKey("artifacts.id"), nullable=False)
|
||||
changed_at = Column(DateTime(timezone=True), default=datetime.utcnow)
|
||||
changed_by = Column(String(255), nullable=False)
|
||||
|
||||
graft = relationship("Graft", back_populates="history")
|
||||
tag = relationship("Tag", back_populates="history")
|
||||
|
||||
__table_args__ = (
|
||||
Index("idx_graft_history_graft_id", "graft_id"),
|
||||
Index("idx_tag_history_tag_id", "tag_id"),
|
||||
)
|
||||
|
||||
|
||||
class Harvest(Base):
|
||||
__tablename__ = "harvests"
|
||||
class Upload(Base):
|
||||
__tablename__ = "uploads"
|
||||
|
||||
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
fruit_id = Column(String(64), ForeignKey("fruits.id"), nullable=False)
|
||||
tree_id = Column(UUID(as_uuid=True), ForeignKey("trees.id"), nullable=False)
|
||||
artifact_id = Column(String(64), ForeignKey("artifacts.id"), nullable=False)
|
||||
package_id = Column(UUID(as_uuid=True), ForeignKey("packages.id"), nullable=False)
|
||||
original_name = Column(String(1024))
|
||||
harvested_at = Column(DateTime(timezone=True), default=datetime.utcnow)
|
||||
harvested_by = Column(String(255), nullable=False)
|
||||
uploaded_at = Column(DateTime(timezone=True), default=datetime.utcnow)
|
||||
uploaded_by = Column(String(255), nullable=False)
|
||||
source_ip = Column(String(45))
|
||||
|
||||
fruit = relationship("Fruit", back_populates="harvests")
|
||||
tree = relationship("Tree", back_populates="harvests")
|
||||
artifact = relationship("Artifact", back_populates="uploads")
|
||||
package = relationship("Package", back_populates="uploads")
|
||||
|
||||
__table_args__ = (
|
||||
Index("idx_harvests_fruit_id", "fruit_id"),
|
||||
Index("idx_harvests_tree_id", "tree_id"),
|
||||
Index("idx_harvests_harvested_at", "harvested_at"),
|
||||
Index("idx_uploads_artifact_id", "artifact_id"),
|
||||
Index("idx_uploads_package_id", "package_id"),
|
||||
Index("idx_uploads_uploaded_at", "uploaded_at"),
|
||||
)
|
||||
|
||||
|
||||
@@ -136,15 +136,15 @@ class Consumer(Base):
|
||||
__tablename__ = "consumers"
|
||||
|
||||
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
tree_id = Column(UUID(as_uuid=True), ForeignKey("trees.id", ondelete="CASCADE"), nullable=False)
|
||||
package_id = Column(UUID(as_uuid=True), ForeignKey("packages.id", ondelete="CASCADE"), nullable=False)
|
||||
project_url = Column(String(2048), nullable=False)
|
||||
last_access = Column(DateTime(timezone=True), default=datetime.utcnow)
|
||||
created_at = Column(DateTime(timezone=True), default=datetime.utcnow)
|
||||
|
||||
tree = relationship("Tree", back_populates="consumers")
|
||||
package = relationship("Package", back_populates="consumers")
|
||||
|
||||
__table_args__ = (
|
||||
Index("idx_consumers_tree_id", "tree_id"),
|
||||
Index("idx_consumers_package_id", "package_id"),
|
||||
Index("idx_consumers_last_access", "last_access"),
|
||||
)
|
||||
|
||||
@@ -153,17 +153,17 @@ class AccessPermission(Base):
|
||||
__tablename__ = "access_permissions"
|
||||
|
||||
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
grove_id = Column(UUID(as_uuid=True), ForeignKey("groves.id", ondelete="CASCADE"), nullable=False)
|
||||
project_id = Column(UUID(as_uuid=True), ForeignKey("projects.id", ondelete="CASCADE"), nullable=False)
|
||||
user_id = Column(String(255), nullable=False)
|
||||
level = Column(String(20), nullable=False)
|
||||
created_at = Column(DateTime(timezone=True), default=datetime.utcnow)
|
||||
expires_at = Column(DateTime(timezone=True))
|
||||
|
||||
grove = relationship("Grove", back_populates="permissions")
|
||||
project = relationship("Project", back_populates="permissions")
|
||||
|
||||
__table_args__ = (
|
||||
CheckConstraint("level IN ('read', 'write', 'admin')", name="check_level"),
|
||||
Index("idx_access_permissions_grove_id", "grove_id"),
|
||||
Index("idx_access_permissions_project_id", "project_id"),
|
||||
Index("idx_access_permissions_user_id", "user_id"),
|
||||
)
|
||||
|
||||
|
||||
@@ -7,13 +7,13 @@ import re
|
||||
|
||||
from .database import get_db
|
||||
from .storage import get_storage, S3Storage
|
||||
from .models import Grove, Tree, Fruit, Graft, Harvest, Consumer
|
||||
from .models import Project, Package, Artifact, Tag, Upload, Consumer
|
||||
from .schemas import (
|
||||
GroveCreate, GroveResponse,
|
||||
TreeCreate, TreeResponse,
|
||||
FruitResponse,
|
||||
GraftCreate, GraftResponse,
|
||||
CultivateResponse,
|
||||
ProjectCreate, ProjectResponse,
|
||||
PackageCreate, PackageResponse,
|
||||
ArtifactResponse,
|
||||
TagCreate, TagResponse,
|
||||
UploadResponse,
|
||||
ConsumerResponse,
|
||||
HealthResponse,
|
||||
)
|
||||
@@ -38,81 +38,81 @@ def health_check():
|
||||
return HealthResponse(status="ok")
|
||||
|
||||
|
||||
# Grove routes
|
||||
@router.get("/api/v1/groves", response_model=List[GroveResponse])
|
||||
def list_groves(request: Request, db: Session = Depends(get_db)):
|
||||
# Project routes
|
||||
@router.get("/api/v1/projects", response_model=List[ProjectResponse])
|
||||
def list_projects(request: Request, db: Session = Depends(get_db)):
|
||||
user_id = get_user_id(request)
|
||||
groves = db.query(Grove).filter(
|
||||
or_(Grove.is_public == True, Grove.created_by == user_id)
|
||||
).order_by(Grove.name).all()
|
||||
return groves
|
||||
projects = db.query(Project).filter(
|
||||
or_(Project.is_public == True, Project.created_by == user_id)
|
||||
).order_by(Project.name).all()
|
||||
return projects
|
||||
|
||||
|
||||
@router.post("/api/v1/groves", response_model=GroveResponse)
|
||||
def create_grove(grove: GroveCreate, request: Request, db: Session = Depends(get_db)):
|
||||
@router.post("/api/v1/projects", response_model=ProjectResponse)
|
||||
def create_project(project: ProjectCreate, request: Request, db: Session = Depends(get_db)):
|
||||
user_id = get_user_id(request)
|
||||
|
||||
existing = db.query(Grove).filter(Grove.name == grove.name).first()
|
||||
existing = db.query(Project).filter(Project.name == project.name).first()
|
||||
if existing:
|
||||
raise HTTPException(status_code=400, detail="Grove already exists")
|
||||
raise HTTPException(status_code=400, detail="Project already exists")
|
||||
|
||||
db_grove = Grove(
|
||||
name=grove.name,
|
||||
description=grove.description,
|
||||
is_public=grove.is_public,
|
||||
db_project = Project(
|
||||
name=project.name,
|
||||
description=project.description,
|
||||
is_public=project.is_public,
|
||||
created_by=user_id,
|
||||
)
|
||||
db.add(db_grove)
|
||||
db.add(db_project)
|
||||
db.commit()
|
||||
db.refresh(db_grove)
|
||||
return db_grove
|
||||
db.refresh(db_project)
|
||||
return db_project
|
||||
|
||||
|
||||
@router.get("/api/v1/groves/{grove_name}", response_model=GroveResponse)
|
||||
def get_grove(grove_name: str, db: Session = Depends(get_db)):
|
||||
grove = db.query(Grove).filter(Grove.name == grove_name).first()
|
||||
if not grove:
|
||||
raise HTTPException(status_code=404, detail="Grove not found")
|
||||
return grove
|
||||
@router.get("/api/v1/projects/{project_name}", response_model=ProjectResponse)
|
||||
def get_project(project_name: str, db: Session = Depends(get_db)):
|
||||
project = db.query(Project).filter(Project.name == project_name).first()
|
||||
if not project:
|
||||
raise HTTPException(status_code=404, detail="Project not found")
|
||||
return project
|
||||
|
||||
|
||||
# Tree routes
|
||||
@router.get("/api/v1/grove/{grove_name}/trees", response_model=List[TreeResponse])
|
||||
def list_trees(grove_name: str, db: Session = Depends(get_db)):
|
||||
grove = db.query(Grove).filter(Grove.name == grove_name).first()
|
||||
if not grove:
|
||||
raise HTTPException(status_code=404, detail="Grove not found")
|
||||
# Package routes
|
||||
@router.get("/api/v1/project/{project_name}/packages", response_model=List[PackageResponse])
|
||||
def list_packages(project_name: str, db: Session = Depends(get_db)):
|
||||
project = db.query(Project).filter(Project.name == project_name).first()
|
||||
if not project:
|
||||
raise HTTPException(status_code=404, detail="Project not found")
|
||||
|
||||
trees = db.query(Tree).filter(Tree.grove_id == grove.id).order_by(Tree.name).all()
|
||||
return trees
|
||||
packages = db.query(Package).filter(Package.project_id == project.id).order_by(Package.name).all()
|
||||
return packages
|
||||
|
||||
|
||||
@router.post("/api/v1/grove/{grove_name}/trees", response_model=TreeResponse)
|
||||
def create_tree(grove_name: str, tree: TreeCreate, db: Session = Depends(get_db)):
|
||||
grove = db.query(Grove).filter(Grove.name == grove_name).first()
|
||||
if not grove:
|
||||
raise HTTPException(status_code=404, detail="Grove not found")
|
||||
@router.post("/api/v1/project/{project_name}/packages", response_model=PackageResponse)
|
||||
def create_package(project_name: str, package: PackageCreate, db: Session = Depends(get_db)):
|
||||
project = db.query(Project).filter(Project.name == project_name).first()
|
||||
if not project:
|
||||
raise HTTPException(status_code=404, detail="Project not found")
|
||||
|
||||
existing = db.query(Tree).filter(Tree.grove_id == grove.id, Tree.name == tree.name).first()
|
||||
existing = db.query(Package).filter(Package.project_id == project.id, Package.name == package.name).first()
|
||||
if existing:
|
||||
raise HTTPException(status_code=400, detail="Tree already exists in this grove")
|
||||
raise HTTPException(status_code=400, detail="Package already exists in this project")
|
||||
|
||||
db_tree = Tree(
|
||||
grove_id=grove.id,
|
||||
name=tree.name,
|
||||
description=tree.description,
|
||||
db_package = Package(
|
||||
project_id=project.id,
|
||||
name=package.name,
|
||||
description=package.description,
|
||||
)
|
||||
db.add(db_tree)
|
||||
db.add(db_package)
|
||||
db.commit()
|
||||
db.refresh(db_tree)
|
||||
return db_tree
|
||||
db.refresh(db_package)
|
||||
return db_package
|
||||
|
||||
|
||||
# Cultivate (upload)
|
||||
@router.post("/api/v1/grove/{grove_name}/{tree_name}/cultivate", response_model=CultivateResponse)
|
||||
def cultivate(
|
||||
grove_name: str,
|
||||
tree_name: str,
|
||||
# Upload artifact
|
||||
@router.post("/api/v1/project/{project_name}/{package_name}/upload", response_model=UploadResponse)
|
||||
def upload_artifact(
|
||||
project_name: str,
|
||||
package_name: str,
|
||||
request: Request,
|
||||
file: UploadFile = File(...),
|
||||
tag: Optional[str] = Form(None),
|
||||
@@ -121,24 +121,24 @@ def cultivate(
|
||||
):
|
||||
user_id = get_user_id(request)
|
||||
|
||||
# Get grove and tree
|
||||
grove = db.query(Grove).filter(Grove.name == grove_name).first()
|
||||
if not grove:
|
||||
raise HTTPException(status_code=404, detail="Grove not found")
|
||||
# Get project and package
|
||||
project = db.query(Project).filter(Project.name == project_name).first()
|
||||
if not project:
|
||||
raise HTTPException(status_code=404, detail="Project not found")
|
||||
|
||||
tree = db.query(Tree).filter(Tree.grove_id == grove.id, Tree.name == tree_name).first()
|
||||
if not tree:
|
||||
raise HTTPException(status_code=404, detail="Tree not found")
|
||||
package = db.query(Package).filter(Package.project_id == project.id, Package.name == package_name).first()
|
||||
if not package:
|
||||
raise HTTPException(status_code=404, detail="Package not found")
|
||||
|
||||
# Store file
|
||||
sha256_hash, size, s3_key = storage.store(file.file)
|
||||
|
||||
# Create or update fruit record
|
||||
fruit = db.query(Fruit).filter(Fruit.id == sha256_hash).first()
|
||||
if fruit:
|
||||
fruit.ref_count += 1
|
||||
# Create or update artifact record
|
||||
artifact = db.query(Artifact).filter(Artifact.id == sha256_hash).first()
|
||||
if artifact:
|
||||
artifact.ref_count += 1
|
||||
else:
|
||||
fruit = Fruit(
|
||||
artifact = Artifact(
|
||||
id=sha256_hash,
|
||||
size=size,
|
||||
content_type=file.content_type,
|
||||
@@ -146,188 +146,188 @@ def cultivate(
|
||||
created_by=user_id,
|
||||
s3_key=s3_key,
|
||||
)
|
||||
db.add(fruit)
|
||||
db.add(artifact)
|
||||
|
||||
# Record harvest
|
||||
harvest = Harvest(
|
||||
fruit_id=sha256_hash,
|
||||
tree_id=tree.id,
|
||||
# Record upload
|
||||
upload = Upload(
|
||||
artifact_id=sha256_hash,
|
||||
package_id=package.id,
|
||||
original_name=file.filename,
|
||||
harvested_by=user_id,
|
||||
uploaded_by=user_id,
|
||||
source_ip=request.client.host if request.client else None,
|
||||
)
|
||||
db.add(harvest)
|
||||
db.add(upload)
|
||||
|
||||
# Create tag if provided
|
||||
if tag:
|
||||
existing_graft = db.query(Graft).filter(Graft.tree_id == tree.id, Graft.name == tag).first()
|
||||
if existing_graft:
|
||||
existing_graft.fruit_id = sha256_hash
|
||||
existing_graft.created_by = user_id
|
||||
existing_tag = db.query(Tag).filter(Tag.package_id == package.id, Tag.name == tag).first()
|
||||
if existing_tag:
|
||||
existing_tag.artifact_id = sha256_hash
|
||||
existing_tag.created_by = user_id
|
||||
else:
|
||||
graft = Graft(
|
||||
tree_id=tree.id,
|
||||
new_tag = Tag(
|
||||
package_id=package.id,
|
||||
name=tag,
|
||||
fruit_id=sha256_hash,
|
||||
artifact_id=sha256_hash,
|
||||
created_by=user_id,
|
||||
)
|
||||
db.add(graft)
|
||||
db.add(new_tag)
|
||||
|
||||
db.commit()
|
||||
|
||||
return CultivateResponse(
|
||||
fruit_id=sha256_hash,
|
||||
return UploadResponse(
|
||||
artifact_id=sha256_hash,
|
||||
size=size,
|
||||
grove=grove_name,
|
||||
tree=tree_name,
|
||||
project=project_name,
|
||||
package=package_name,
|
||||
tag=tag,
|
||||
)
|
||||
|
||||
|
||||
# Harvest (download)
|
||||
@router.get("/api/v1/grove/{grove_name}/{tree_name}/+/{ref}")
|
||||
def harvest(
|
||||
grove_name: str,
|
||||
tree_name: str,
|
||||
# Download artifact
|
||||
@router.get("/api/v1/project/{project_name}/{package_name}/+/{ref}")
|
||||
def download_artifact(
|
||||
project_name: str,
|
||||
package_name: str,
|
||||
ref: str,
|
||||
db: Session = Depends(get_db),
|
||||
storage: S3Storage = Depends(get_storage),
|
||||
):
|
||||
# Get grove and tree
|
||||
grove = db.query(Grove).filter(Grove.name == grove_name).first()
|
||||
if not grove:
|
||||
raise HTTPException(status_code=404, detail="Grove not found")
|
||||
# Get project and package
|
||||
project = db.query(Project).filter(Project.name == project_name).first()
|
||||
if not project:
|
||||
raise HTTPException(status_code=404, detail="Project not found")
|
||||
|
||||
tree = db.query(Tree).filter(Tree.grove_id == grove.id, Tree.name == tree_name).first()
|
||||
if not tree:
|
||||
raise HTTPException(status_code=404, detail="Tree not found")
|
||||
package = db.query(Package).filter(Package.project_id == project.id, Package.name == package_name).first()
|
||||
if not package:
|
||||
raise HTTPException(status_code=404, detail="Package not found")
|
||||
|
||||
# Resolve reference to fruit
|
||||
fruit = None
|
||||
# Resolve reference to artifact
|
||||
artifact = None
|
||||
|
||||
# Check for explicit prefixes
|
||||
if ref.startswith("fruit:"):
|
||||
fruit_id = ref[6:]
|
||||
fruit = db.query(Fruit).filter(Fruit.id == fruit_id).first()
|
||||
if ref.startswith("artifact:"):
|
||||
artifact_id = ref[9:]
|
||||
artifact = db.query(Artifact).filter(Artifact.id == artifact_id).first()
|
||||
elif ref.startswith("tag:") or ref.startswith("version:"):
|
||||
tag_name = ref.split(":", 1)[1]
|
||||
graft = db.query(Graft).filter(Graft.tree_id == tree.id, Graft.name == tag_name).first()
|
||||
if graft:
|
||||
fruit = db.query(Fruit).filter(Fruit.id == graft.fruit_id).first()
|
||||
tag = db.query(Tag).filter(Tag.package_id == package.id, Tag.name == tag_name).first()
|
||||
if tag:
|
||||
artifact = db.query(Artifact).filter(Artifact.id == tag.artifact_id).first()
|
||||
else:
|
||||
# Try as tag name first
|
||||
graft = db.query(Graft).filter(Graft.tree_id == tree.id, Graft.name == ref).first()
|
||||
if graft:
|
||||
fruit = db.query(Fruit).filter(Fruit.id == graft.fruit_id).first()
|
||||
tag = db.query(Tag).filter(Tag.package_id == package.id, Tag.name == ref).first()
|
||||
if tag:
|
||||
artifact = db.query(Artifact).filter(Artifact.id == tag.artifact_id).first()
|
||||
else:
|
||||
# Try as direct fruit ID
|
||||
fruit = db.query(Fruit).filter(Fruit.id == ref).first()
|
||||
# Try as direct artifact ID
|
||||
artifact = db.query(Artifact).filter(Artifact.id == ref).first()
|
||||
|
||||
if not fruit:
|
||||
if not artifact:
|
||||
raise HTTPException(status_code=404, detail="Artifact not found")
|
||||
|
||||
# Stream from S3
|
||||
stream = storage.get_stream(fruit.s3_key)
|
||||
stream = storage.get_stream(artifact.s3_key)
|
||||
|
||||
filename = fruit.original_name or f"{fruit.id}"
|
||||
filename = artifact.original_name or f"{artifact.id}"
|
||||
|
||||
return StreamingResponse(
|
||||
stream,
|
||||
media_type=fruit.content_type or "application/octet-stream",
|
||||
media_type=artifact.content_type or "application/octet-stream",
|
||||
headers={"Content-Disposition": f'attachment; filename="{filename}"'},
|
||||
)
|
||||
|
||||
|
||||
# Compatibility route
|
||||
@router.get("/grove/{grove_name}/{tree_name}/+/{ref}")
|
||||
def harvest_compat(
|
||||
grove_name: str,
|
||||
tree_name: str,
|
||||
@router.get("/project/{project_name}/{package_name}/+/{ref}")
|
||||
def download_artifact_compat(
|
||||
project_name: str,
|
||||
package_name: str,
|
||||
ref: str,
|
||||
db: Session = Depends(get_db),
|
||||
storage: S3Storage = Depends(get_storage),
|
||||
):
|
||||
return harvest(grove_name, tree_name, ref, db, storage)
|
||||
return download_artifact(project_name, package_name, ref, db, storage)
|
||||
|
||||
|
||||
# Graft routes
|
||||
@router.get("/api/v1/grove/{grove_name}/{tree_name}/grafts", response_model=List[GraftResponse])
|
||||
def list_grafts(grove_name: str, tree_name: str, db: Session = Depends(get_db)):
|
||||
grove = db.query(Grove).filter(Grove.name == grove_name).first()
|
||||
if not grove:
|
||||
raise HTTPException(status_code=404, detail="Grove not found")
|
||||
# Tag routes
|
||||
@router.get("/api/v1/project/{project_name}/{package_name}/tags", response_model=List[TagResponse])
|
||||
def list_tags(project_name: str, package_name: str, db: Session = Depends(get_db)):
|
||||
project = db.query(Project).filter(Project.name == project_name).first()
|
||||
if not project:
|
||||
raise HTTPException(status_code=404, detail="Project not found")
|
||||
|
||||
tree = db.query(Tree).filter(Tree.grove_id == grove.id, Tree.name == tree_name).first()
|
||||
if not tree:
|
||||
raise HTTPException(status_code=404, detail="Tree not found")
|
||||
package = db.query(Package).filter(Package.project_id == project.id, Package.name == package_name).first()
|
||||
if not package:
|
||||
raise HTTPException(status_code=404, detail="Package not found")
|
||||
|
||||
grafts = db.query(Graft).filter(Graft.tree_id == tree.id).order_by(Graft.name).all()
|
||||
return grafts
|
||||
tags = db.query(Tag).filter(Tag.package_id == package.id).order_by(Tag.name).all()
|
||||
return tags
|
||||
|
||||
|
||||
@router.post("/api/v1/grove/{grove_name}/{tree_name}/graft", response_model=GraftResponse)
|
||||
def create_graft(
|
||||
grove_name: str,
|
||||
tree_name: str,
|
||||
graft: GraftCreate,
|
||||
@router.post("/api/v1/project/{project_name}/{package_name}/tags", response_model=TagResponse)
|
||||
def create_tag(
|
||||
project_name: str,
|
||||
package_name: str,
|
||||
tag: TagCreate,
|
||||
request: Request,
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
user_id = get_user_id(request)
|
||||
|
||||
grove = db.query(Grove).filter(Grove.name == grove_name).first()
|
||||
if not grove:
|
||||
raise HTTPException(status_code=404, detail="Grove not found")
|
||||
project = db.query(Project).filter(Project.name == project_name).first()
|
||||
if not project:
|
||||
raise HTTPException(status_code=404, detail="Project not found")
|
||||
|
||||
tree = db.query(Tree).filter(Tree.grove_id == grove.id, Tree.name == tree_name).first()
|
||||
if not tree:
|
||||
raise HTTPException(status_code=404, detail="Tree not found")
|
||||
package = db.query(Package).filter(Package.project_id == project.id, Package.name == package_name).first()
|
||||
if not package:
|
||||
raise HTTPException(status_code=404, detail="Package not found")
|
||||
|
||||
# Verify fruit exists
|
||||
fruit = db.query(Fruit).filter(Fruit.id == graft.fruit_id).first()
|
||||
if not fruit:
|
||||
raise HTTPException(status_code=404, detail="Fruit not found")
|
||||
# Verify artifact exists
|
||||
artifact = db.query(Artifact).filter(Artifact.id == tag.artifact_id).first()
|
||||
if not artifact:
|
||||
raise HTTPException(status_code=404, detail="Artifact not found")
|
||||
|
||||
# Create or update graft
|
||||
existing = db.query(Graft).filter(Graft.tree_id == tree.id, Graft.name == graft.name).first()
|
||||
# Create or update tag
|
||||
existing = db.query(Tag).filter(Tag.package_id == package.id, Tag.name == tag.name).first()
|
||||
if existing:
|
||||
existing.fruit_id = graft.fruit_id
|
||||
existing.artifact_id = tag.artifact_id
|
||||
existing.created_by = user_id
|
||||
db.commit()
|
||||
db.refresh(existing)
|
||||
return existing
|
||||
|
||||
db_graft = Graft(
|
||||
tree_id=tree.id,
|
||||
name=graft.name,
|
||||
fruit_id=graft.fruit_id,
|
||||
db_tag = Tag(
|
||||
package_id=package.id,
|
||||
name=tag.name,
|
||||
artifact_id=tag.artifact_id,
|
||||
created_by=user_id,
|
||||
)
|
||||
db.add(db_graft)
|
||||
db.add(db_tag)
|
||||
db.commit()
|
||||
db.refresh(db_graft)
|
||||
return db_graft
|
||||
db.refresh(db_tag)
|
||||
return db_tag
|
||||
|
||||
|
||||
# Consumer routes
|
||||
@router.get("/api/v1/grove/{grove_name}/{tree_name}/consumers", response_model=List[ConsumerResponse])
|
||||
def get_consumers(grove_name: str, tree_name: str, db: Session = Depends(get_db)):
|
||||
grove = db.query(Grove).filter(Grove.name == grove_name).first()
|
||||
if not grove:
|
||||
raise HTTPException(status_code=404, detail="Grove not found")
|
||||
@router.get("/api/v1/project/{project_name}/{package_name}/consumers", response_model=List[ConsumerResponse])
|
||||
def get_consumers(project_name: str, package_name: str, db: Session = Depends(get_db)):
|
||||
project = db.query(Project).filter(Project.name == project_name).first()
|
||||
if not project:
|
||||
raise HTTPException(status_code=404, detail="Project not found")
|
||||
|
||||
tree = db.query(Tree).filter(Tree.grove_id == grove.id, Tree.name == tree_name).first()
|
||||
if not tree:
|
||||
raise HTTPException(status_code=404, detail="Tree not found")
|
||||
package = db.query(Package).filter(Package.project_id == project.id, Package.name == package_name).first()
|
||||
if not package:
|
||||
raise HTTPException(status_code=404, detail="Package not found")
|
||||
|
||||
consumers = db.query(Consumer).filter(Consumer.tree_id == tree.id).order_by(Consumer.last_access.desc()).all()
|
||||
consumers = db.query(Consumer).filter(Consumer.package_id == package.id).order_by(Consumer.last_access.desc()).all()
|
||||
return consumers
|
||||
|
||||
|
||||
# Fruit by ID
|
||||
@router.get("/api/v1/fruit/{fruit_id}", response_model=FruitResponse)
|
||||
def get_fruit(fruit_id: str, db: Session = Depends(get_db)):
|
||||
fruit = db.query(Fruit).filter(Fruit.id == fruit_id).first()
|
||||
if not fruit:
|
||||
raise HTTPException(status_code=404, detail="Fruit not found")
|
||||
return fruit
|
||||
# Artifact by ID
|
||||
@router.get("/api/v1/artifact/{artifact_id}", response_model=ArtifactResponse)
|
||||
def get_artifact(artifact_id: str, db: Session = Depends(get_db)):
|
||||
artifact = db.query(Artifact).filter(Artifact.id == artifact_id).first()
|
||||
if not artifact:
|
||||
raise HTTPException(status_code=404, detail="Artifact not found")
|
||||
return artifact
|
||||
|
||||
@@ -4,14 +4,14 @@ from pydantic import BaseModel
|
||||
from uuid import UUID
|
||||
|
||||
|
||||
# Grove schemas
|
||||
class GroveCreate(BaseModel):
|
||||
# Project schemas
|
||||
class ProjectCreate(BaseModel):
|
||||
name: str
|
||||
description: Optional[str] = None
|
||||
is_public: bool = True
|
||||
|
||||
|
||||
class GroveResponse(BaseModel):
|
||||
class ProjectResponse(BaseModel):
|
||||
id: UUID
|
||||
name: str
|
||||
description: Optional[str]
|
||||
@@ -24,15 +24,15 @@ class GroveResponse(BaseModel):
|
||||
from_attributes = True
|
||||
|
||||
|
||||
# Tree schemas
|
||||
class TreeCreate(BaseModel):
|
||||
# Package schemas
|
||||
class PackageCreate(BaseModel):
|
||||
name: str
|
||||
description: Optional[str] = None
|
||||
|
||||
|
||||
class TreeResponse(BaseModel):
|
||||
class PackageResponse(BaseModel):
|
||||
id: UUID
|
||||
grove_id: UUID
|
||||
project_id: UUID
|
||||
name: str
|
||||
description: Optional[str]
|
||||
created_at: datetime
|
||||
@@ -42,8 +42,8 @@ class TreeResponse(BaseModel):
|
||||
from_attributes = True
|
||||
|
||||
|
||||
# Fruit schemas
|
||||
class FruitResponse(BaseModel):
|
||||
# Artifact schemas
|
||||
class ArtifactResponse(BaseModel):
|
||||
id: str
|
||||
size: int
|
||||
content_type: Optional[str]
|
||||
@@ -56,17 +56,17 @@ class FruitResponse(BaseModel):
|
||||
from_attributes = True
|
||||
|
||||
|
||||
# Graft schemas
|
||||
class GraftCreate(BaseModel):
|
||||
# Tag schemas
|
||||
class TagCreate(BaseModel):
|
||||
name: str
|
||||
fruit_id: str
|
||||
artifact_id: str
|
||||
|
||||
|
||||
class GraftResponse(BaseModel):
|
||||
class TagResponse(BaseModel):
|
||||
id: UUID
|
||||
tree_id: UUID
|
||||
package_id: UUID
|
||||
name: str
|
||||
fruit_id: str
|
||||
artifact_id: str
|
||||
created_at: datetime
|
||||
created_by: str
|
||||
|
||||
@@ -74,19 +74,19 @@ class GraftResponse(BaseModel):
|
||||
from_attributes = True
|
||||
|
||||
|
||||
# Cultivate response (upload)
|
||||
class CultivateResponse(BaseModel):
|
||||
fruit_id: str
|
||||
# Upload response
|
||||
class UploadResponse(BaseModel):
|
||||
artifact_id: str
|
||||
size: int
|
||||
grove: str
|
||||
tree: str
|
||||
project: str
|
||||
package: str
|
||||
tag: Optional[str]
|
||||
|
||||
|
||||
# Consumer schemas
|
||||
class ConsumerResponse(BaseModel):
|
||||
id: UUID
|
||||
tree_id: UUID
|
||||
package_id: UUID
|
||||
project_url: str
|
||||
last_access: datetime
|
||||
created_at: datetime
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import { Routes, Route } from 'react-router-dom';
|
||||
import Layout from './components/Layout';
|
||||
import Home from './pages/Home';
|
||||
import GrovePage from './pages/GrovePage';
|
||||
import TreePage from './pages/TreePage';
|
||||
import ProjectPage from './pages/ProjectPage';
|
||||
import PackagePage from './pages/PackagePage';
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<Layout>
|
||||
<Routes>
|
||||
<Route path="/" element={<Home />} />
|
||||
<Route path="/grove/:groveName" element={<GrovePage />} />
|
||||
<Route path="/grove/:groveName/:treeName" element={<TreePage />} />
|
||||
<Route path="/project/:projectName" element={<ProjectPage />} />
|
||||
<Route path="/project/:projectName/:packageName" element={<PackagePage />} />
|
||||
</Routes>
|
||||
</Layout>
|
||||
);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Grove, Tree, Graft, Fruit, CultivateResponse } from './types';
|
||||
import { Project, Package, Tag, Artifact, UploadResponse } from './types';
|
||||
|
||||
const API_BASE = '/api/v1';
|
||||
|
||||
@@ -10,78 +10,78 @@ async function handleResponse<T>(response: Response): Promise<T> {
|
||||
return response.json();
|
||||
}
|
||||
|
||||
// Grove API
|
||||
export async function listGroves(): Promise<Grove[]> {
|
||||
const response = await fetch(`${API_BASE}/groves`);
|
||||
return handleResponse<Grove[]>(response);
|
||||
// Project API
|
||||
export async function listProjects(): Promise<Project[]> {
|
||||
const response = await fetch(`${API_BASE}/projects`);
|
||||
return handleResponse<Project[]>(response);
|
||||
}
|
||||
|
||||
export async function createGrove(data: { name: string; description?: string; is_public?: boolean }): Promise<Grove> {
|
||||
const response = await fetch(`${API_BASE}/groves`, {
|
||||
export async function createProject(data: { name: string; description?: string; is_public?: boolean }): Promise<Project> {
|
||||
const response = await fetch(`${API_BASE}/projects`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
return handleResponse<Grove>(response);
|
||||
return handleResponse<Project>(response);
|
||||
}
|
||||
|
||||
export async function getGrove(name: string): Promise<Grove> {
|
||||
const response = await fetch(`${API_BASE}/groves/${name}`);
|
||||
return handleResponse<Grove>(response);
|
||||
export async function getProject(name: string): Promise<Project> {
|
||||
const response = await fetch(`${API_BASE}/projects/${name}`);
|
||||
return handleResponse<Project>(response);
|
||||
}
|
||||
|
||||
// Tree API
|
||||
export async function listTrees(groveName: string): Promise<Tree[]> {
|
||||
const response = await fetch(`${API_BASE}/grove/${groveName}/trees`);
|
||||
return handleResponse<Tree[]>(response);
|
||||
// Package API
|
||||
export async function listPackages(projectName: string): Promise<Package[]> {
|
||||
const response = await fetch(`${API_BASE}/project/${projectName}/packages`);
|
||||
return handleResponse<Package[]>(response);
|
||||
}
|
||||
|
||||
export async function createTree(groveName: string, data: { name: string; description?: string }): Promise<Tree> {
|
||||
const response = await fetch(`${API_BASE}/grove/${groveName}/trees`, {
|
||||
export async function createPackage(projectName: string, data: { name: string; description?: string }): Promise<Package> {
|
||||
const response = await fetch(`${API_BASE}/project/${projectName}/packages`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
return handleResponse<Tree>(response);
|
||||
return handleResponse<Package>(response);
|
||||
}
|
||||
|
||||
// Graft API
|
||||
export async function listGrafts(groveName: string, treeName: string): Promise<Graft[]> {
|
||||
const response = await fetch(`${API_BASE}/grove/${groveName}/${treeName}/grafts`);
|
||||
return handleResponse<Graft[]>(response);
|
||||
// Tag API
|
||||
export async function listTags(projectName: string, packageName: string): Promise<Tag[]> {
|
||||
const response = await fetch(`${API_BASE}/project/${projectName}/${packageName}/tags`);
|
||||
return handleResponse<Tag[]>(response);
|
||||
}
|
||||
|
||||
export async function createGraft(groveName: string, treeName: string, data: { name: string; fruit_id: string }): Promise<Graft> {
|
||||
const response = await fetch(`${API_BASE}/grove/${groveName}/${treeName}/graft`, {
|
||||
export async function createTag(projectName: string, packageName: string, data: { name: string; artifact_id: string }): Promise<Tag> {
|
||||
const response = await fetch(`${API_BASE}/project/${projectName}/${packageName}/tags`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
return handleResponse<Graft>(response);
|
||||
return handleResponse<Tag>(response);
|
||||
}
|
||||
|
||||
// Fruit API
|
||||
export async function getFruit(fruitId: string): Promise<Fruit> {
|
||||
const response = await fetch(`${API_BASE}/fruit/${fruitId}`);
|
||||
return handleResponse<Fruit>(response);
|
||||
// Artifact API
|
||||
export async function getArtifact(artifactId: string): Promise<Artifact> {
|
||||
const response = await fetch(`${API_BASE}/artifact/${artifactId}`);
|
||||
return handleResponse<Artifact>(response);
|
||||
}
|
||||
|
||||
// Upload
|
||||
export async function cultivate(groveName: string, treeName: string, file: File, tag?: string): Promise<CultivateResponse> {
|
||||
export async function uploadArtifact(projectName: string, packageName: string, file: File, tag?: string): Promise<UploadResponse> {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
if (tag) {
|
||||
formData.append('tag', tag);
|
||||
}
|
||||
|
||||
const response = await fetch(`${API_BASE}/grove/${groveName}/${treeName}/cultivate`, {
|
||||
const response = await fetch(`${API_BASE}/project/${projectName}/${packageName}/upload`, {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
});
|
||||
return handleResponse<CultivateResponse>(response);
|
||||
return handleResponse<UploadResponse>(response);
|
||||
}
|
||||
|
||||
// Download URL
|
||||
export function getDownloadUrl(groveName: string, treeName: string, ref: string): string {
|
||||
return `${API_BASE}/grove/${groveName}/${treeName}/+/${ref}`;
|
||||
export function getDownloadUrl(projectName: string, packageName: string, ref: string): string {
|
||||
return `${API_BASE}/project/${projectName}/${packageName}/+/${ref}`;
|
||||
}
|
||||
|
||||
@@ -129,36 +129,36 @@
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.grove-grid {
|
||||
.project-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.grove-card {
|
||||
.project-card {
|
||||
display: block;
|
||||
color: inherit;
|
||||
transition: transform 0.2s, box-shadow 0.2s;
|
||||
}
|
||||
|
||||
.grove-card:hover {
|
||||
.project-card:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.grove-card h3 {
|
||||
.project-card h3 {
|
||||
color: var(--primary);
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.grove-card p {
|
||||
.project-card p {
|
||||
color: var(--text-light);
|
||||
font-size: 0.875rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.grove-meta {
|
||||
.project-meta {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
|
||||
@@ -1,74 +1,74 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { Grove } from '../types';
|
||||
import { listGroves, createGrove } from '../api';
|
||||
import { Project } from '../types';
|
||||
import { listProjects, createProject } from '../api';
|
||||
import './Home.css';
|
||||
|
||||
function Home() {
|
||||
const [groves, setGroves] = useState<Grove[]>([]);
|
||||
const [projects, setProjects] = useState<Project[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [showForm, setShowForm] = useState(false);
|
||||
const [newGrove, setNewGrove] = useState({ name: '', description: '', is_public: true });
|
||||
const [newProject, setNewProject] = useState({ name: '', description: '', is_public: true });
|
||||
const [creating, setCreating] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
loadGroves();
|
||||
loadProjects();
|
||||
}, []);
|
||||
|
||||
async function loadGroves() {
|
||||
async function loadProjects() {
|
||||
try {
|
||||
setLoading(true);
|
||||
const data = await listGroves();
|
||||
setGroves(data);
|
||||
const data = await listProjects();
|
||||
setProjects(data);
|
||||
setError(null);
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Failed to load groves');
|
||||
setError(err instanceof Error ? err.message : 'Failed to load projects');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleCreateGrove(e: React.FormEvent) {
|
||||
async function handleCreateProject(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
try {
|
||||
setCreating(true);
|
||||
await createGrove(newGrove);
|
||||
setNewGrove({ name: '', description: '', is_public: true });
|
||||
await createProject(newProject);
|
||||
setNewProject({ name: '', description: '', is_public: true });
|
||||
setShowForm(false);
|
||||
loadGroves();
|
||||
loadProjects();
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Failed to create grove');
|
||||
setError(err instanceof Error ? err.message : 'Failed to create project');
|
||||
} finally {
|
||||
setCreating(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (loading) {
|
||||
return <div className="loading">Loading groves...</div>;
|
||||
return <div className="loading">Loading projects...</div>;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="home">
|
||||
<div className="page-header">
|
||||
<h1>Groves</h1>
|
||||
<h1>Projects</h1>
|
||||
<button className="btn btn-primary" onClick={() => setShowForm(!showForm)}>
|
||||
{showForm ? 'Cancel' : '+ New Grove'}
|
||||
{showForm ? 'Cancel' : '+ New Project'}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{error && <div className="error-message">{error}</div>}
|
||||
|
||||
{showForm && (
|
||||
<form className="form card" onSubmit={handleCreateGrove}>
|
||||
<h3>Create New Grove</h3>
|
||||
<form className="form card" onSubmit={handleCreateProject}>
|
||||
<h3>Create New Project</h3>
|
||||
<div className="form-group">
|
||||
<label htmlFor="name">Name</label>
|
||||
<input
|
||||
id="name"
|
||||
type="text"
|
||||
value={newGrove.name}
|
||||
onChange={(e) => setNewGrove({ ...newGrove, name: e.target.value })}
|
||||
value={newProject.name}
|
||||
onChange={(e) => setNewProject({ ...newProject, name: e.target.value })}
|
||||
placeholder="my-project"
|
||||
required
|
||||
/>
|
||||
@@ -78,8 +78,8 @@ function Home() {
|
||||
<input
|
||||
id="description"
|
||||
type="text"
|
||||
value={newGrove.description}
|
||||
onChange={(e) => setNewGrove({ ...newGrove, description: e.target.value })}
|
||||
value={newProject.description}
|
||||
onChange={(e) => setNewProject({ ...newProject, description: e.target.value })}
|
||||
placeholder="Optional description"
|
||||
/>
|
||||
</div>
|
||||
@@ -87,34 +87,34 @@ function Home() {
|
||||
<label>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={newGrove.is_public}
|
||||
onChange={(e) => setNewGrove({ ...newGrove, is_public: e.target.checked })}
|
||||
checked={newProject.is_public}
|
||||
onChange={(e) => setNewProject({ ...newProject, is_public: e.target.checked })}
|
||||
/>
|
||||
Public
|
||||
</label>
|
||||
</div>
|
||||
<button type="submit" className="btn btn-primary" disabled={creating}>
|
||||
{creating ? 'Creating...' : 'Create Grove'}
|
||||
{creating ? 'Creating...' : 'Create Project'}
|
||||
</button>
|
||||
</form>
|
||||
)}
|
||||
|
||||
{groves.length === 0 ? (
|
||||
{projects.length === 0 ? (
|
||||
<div className="empty-state">
|
||||
<p>No groves yet. Create your first grove to get started!</p>
|
||||
<p>No projects yet. Create your first project to get started!</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="grove-grid">
|
||||
{groves.map((grove) => (
|
||||
<Link to={`/grove/${grove.name}`} key={grove.id} className="grove-card card">
|
||||
<h3>{grove.name}</h3>
|
||||
{grove.description && <p>{grove.description}</p>}
|
||||
<div className="grove-meta">
|
||||
<span className={`badge ${grove.is_public ? 'badge-public' : 'badge-private'}`}>
|
||||
{grove.is_public ? 'Public' : 'Private'}
|
||||
<div className="project-grid">
|
||||
{projects.map((project) => (
|
||||
<Link to={`/project/${project.name}`} key={project.id} className="project-card card">
|
||||
<h3>{project.name}</h3>
|
||||
{project.description && <p>{project.description}</p>}
|
||||
<div className="project-meta">
|
||||
<span className={`badge ${project.is_public ? 'badge-public' : 'badge-private'}`}>
|
||||
{project.is_public ? 'Public' : 'Private'}
|
||||
</span>
|
||||
<span className="date">
|
||||
Created {new Date(grove.created_at).toLocaleDateString()}
|
||||
Created {new Date(project.created_at).toLocaleDateString()}
|
||||
</span>
|
||||
</div>
|
||||
</Link>
|
||||
|
||||
@@ -54,7 +54,7 @@ h2 {
|
||||
color: var(--primary-dark);
|
||||
}
|
||||
|
||||
.grafts-table {
|
||||
.tags-table {
|
||||
background-color: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
@@ -62,19 +62,19 @@ h2 {
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.grafts-table table {
|
||||
.tags-table table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
.grafts-table th,
|
||||
.grafts-table td {
|
||||
.tags-table th,
|
||||
.tags-table td {
|
||||
padding: 0.875rem 1rem;
|
||||
text-align: left;
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.grafts-table th {
|
||||
.tags-table th {
|
||||
background-color: #f9f9f9;
|
||||
font-weight: 600;
|
||||
font-size: 0.75rem;
|
||||
@@ -82,15 +82,15 @@ h2 {
|
||||
color: var(--text-light);
|
||||
}
|
||||
|
||||
.grafts-table tr:last-child td {
|
||||
.tags-table tr:last-child td {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.grafts-table tr:hover {
|
||||
.tags-table tr:hover {
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
|
||||
.fruit-id {
|
||||
.artifact-id {
|
||||
font-family: monospace;
|
||||
font-size: 0.875rem;
|
||||
color: var(--text-light);
|
||||
@@ -1,13 +1,13 @@
|
||||
import { useState, useEffect, useRef } from 'react';
|
||||
import { useParams, Link } from 'react-router-dom';
|
||||
import { Graft } from '../types';
|
||||
import { listGrafts, cultivate, getDownloadUrl } from '../api';
|
||||
import { Tag } from '../types';
|
||||
import { listTags, uploadArtifact, getDownloadUrl } from '../api';
|
||||
import './Home.css';
|
||||
import './TreePage.css';
|
||||
import './PackagePage.css';
|
||||
|
||||
function TreePage() {
|
||||
const { groveName, treeName } = useParams<{ groveName: string; treeName: string }>();
|
||||
const [grafts, setGrafts] = useState<Graft[]>([]);
|
||||
function PackagePage() {
|
||||
const { projectName, packageName } = useParams<{ projectName: string; packageName: string }>();
|
||||
const [tags, setTags] = useState<Tag[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [uploading, setUploading] = useState(false);
|
||||
@@ -16,19 +16,19 @@ function TreePage() {
|
||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (groveName && treeName) {
|
||||
loadGrafts();
|
||||
if (projectName && packageName) {
|
||||
loadTags();
|
||||
}
|
||||
}, [groveName, treeName]);
|
||||
}, [projectName, packageName]);
|
||||
|
||||
async function loadGrafts() {
|
||||
async function loadTags() {
|
||||
try {
|
||||
setLoading(true);
|
||||
const data = await listGrafts(groveName!, treeName!);
|
||||
setGrafts(data);
|
||||
const data = await listTags(projectName!, packageName!);
|
||||
setTags(data);
|
||||
setError(null);
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Failed to load grafts');
|
||||
setError(err instanceof Error ? err.message : 'Failed to load tags');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -45,13 +45,13 @@ function TreePage() {
|
||||
try {
|
||||
setUploading(true);
|
||||
setError(null);
|
||||
const result = await cultivate(groveName!, treeName!, file, tag || undefined);
|
||||
setUploadResult(`Uploaded successfully! Fruit ID: ${result.fruit_id}`);
|
||||
const result = await uploadArtifact(projectName!, packageName!, file, tag || undefined);
|
||||
setUploadResult(`Uploaded successfully! Artifact ID: ${result.artifact_id}`);
|
||||
setTag('');
|
||||
if (fileInputRef.current) {
|
||||
fileInputRef.current.value = '';
|
||||
}
|
||||
loadGrafts();
|
||||
loadTags();
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Upload failed');
|
||||
} finally {
|
||||
@@ -66,11 +66,11 @@ function TreePage() {
|
||||
return (
|
||||
<div className="home">
|
||||
<nav className="breadcrumb">
|
||||
<Link to="/">Groves</Link> / <Link to={`/grove/${groveName}`}>{groveName}</Link> / <span>{treeName}</span>
|
||||
<Link to="/">Projects</Link> / <Link to={`/project/${projectName}`}>{projectName}</Link> / <span>{packageName}</span>
|
||||
</nav>
|
||||
|
||||
<div className="page-header">
|
||||
<h1>📦 {treeName}</h1>
|
||||
<h1>{packageName}</h1>
|
||||
</div>
|
||||
|
||||
{error && <div className="error-message">{error}</div>}
|
||||
@@ -105,30 +105,30 @@ function TreePage() {
|
||||
</div>
|
||||
|
||||
<h2>Tags / Versions</h2>
|
||||
{grafts.length === 0 ? (
|
||||
{tags.length === 0 ? (
|
||||
<div className="empty-state">
|
||||
<p>No tags yet. Upload an artifact with a tag to create one!</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="grafts-table">
|
||||
<div className="tags-table">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Tag</th>
|
||||
<th>Fruit ID</th>
|
||||
<th>Artifact ID</th>
|
||||
<th>Created</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{grafts.map((graft) => (
|
||||
<tr key={graft.id}>
|
||||
<td><strong>{graft.name}</strong></td>
|
||||
<td className="fruit-id">{graft.fruit_id.substring(0, 12)}...</td>
|
||||
<td>{new Date(graft.created_at).toLocaleString()}</td>
|
||||
{tags.map((t) => (
|
||||
<tr key={t.id}>
|
||||
<td><strong>{t.name}</strong></td>
|
||||
<td className="artifact-id">{t.artifact_id.substring(0, 12)}...</td>
|
||||
<td>{new Date(t.created_at).toLocaleString()}</td>
|
||||
<td>
|
||||
<a
|
||||
href={getDownloadUrl(groveName!, treeName!, graft.name)}
|
||||
href={getDownloadUrl(projectName!, packageName!, t.name)}
|
||||
className="btn btn-secondary btn-small"
|
||||
download
|
||||
>
|
||||
@@ -146,15 +146,15 @@ function TreePage() {
|
||||
<h3>Usage</h3>
|
||||
<p>Download artifacts using:</p>
|
||||
<pre>
|
||||
<code>curl -O {window.location.origin}/api/v1/grove/{groveName}/{treeName}/+/latest</code>
|
||||
<code>curl -O {window.location.origin}/api/v1/project/{projectName}/{packageName}/+/latest</code>
|
||||
</pre>
|
||||
<p>Or with a specific tag:</p>
|
||||
<pre>
|
||||
<code>curl -O {window.location.origin}/api/v1/grove/{groveName}/{treeName}/+/v1.0.0</code>
|
||||
<code>curl -O {window.location.origin}/api/v1/project/{projectName}/{packageName}/+/v1.0.0</code>
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default TreePage;
|
||||
export default PackagePage;
|
||||
@@ -1,34 +1,34 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useParams, Link } from 'react-router-dom';
|
||||
import { Grove, Tree } from '../types';
|
||||
import { getGrove, listTrees, createTree } from '../api';
|
||||
import { Project, Package } from '../types';
|
||||
import { getProject, listPackages, createPackage } from '../api';
|
||||
import './Home.css';
|
||||
|
||||
function GrovePage() {
|
||||
const { groveName } = useParams<{ groveName: string }>();
|
||||
const [grove, setGrove] = useState<Grove | null>(null);
|
||||
const [trees, setTrees] = useState<Tree[]>([]);
|
||||
function ProjectPage() {
|
||||
const { projectName } = useParams<{ projectName: string }>();
|
||||
const [project, setProject] = useState<Project | null>(null);
|
||||
const [packages, setPackages] = useState<Package[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [showForm, setShowForm] = useState(false);
|
||||
const [newTree, setNewTree] = useState({ name: '', description: '' });
|
||||
const [newPackage, setNewPackage] = useState({ name: '', description: '' });
|
||||
const [creating, setCreating] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (groveName) {
|
||||
if (projectName) {
|
||||
loadData();
|
||||
}
|
||||
}, [groveName]);
|
||||
}, [projectName]);
|
||||
|
||||
async function loadData() {
|
||||
try {
|
||||
setLoading(true);
|
||||
const [groveData, treesData] = await Promise.all([
|
||||
getGrove(groveName!),
|
||||
listTrees(groveName!),
|
||||
const [projectData, packagesData] = await Promise.all([
|
||||
getProject(projectName!),
|
||||
listPackages(projectName!),
|
||||
]);
|
||||
setGrove(groveData);
|
||||
setTrees(treesData);
|
||||
setProject(projectData);
|
||||
setPackages(packagesData);
|
||||
setError(null);
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Failed to load data');
|
||||
@@ -37,16 +37,16 @@ function GrovePage() {
|
||||
}
|
||||
}
|
||||
|
||||
async function handleCreateTree(e: React.FormEvent) {
|
||||
async function handleCreatePackage(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
try {
|
||||
setCreating(true);
|
||||
await createTree(groveName!, newTree);
|
||||
setNewTree({ name: '', description: '' });
|
||||
await createPackage(projectName!, newPackage);
|
||||
setNewPackage({ name: '', description: '' });
|
||||
setShowForm(false);
|
||||
loadData();
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : 'Failed to create tree');
|
||||
setError(err instanceof Error ? err.message : 'Failed to create package');
|
||||
} finally {
|
||||
setCreating(false);
|
||||
}
|
||||
@@ -56,38 +56,38 @@ function GrovePage() {
|
||||
return <div className="loading">Loading...</div>;
|
||||
}
|
||||
|
||||
if (!grove) {
|
||||
return <div className="error-message">Grove not found</div>;
|
||||
if (!project) {
|
||||
return <div className="error-message">Project not found</div>;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="home">
|
||||
<nav className="breadcrumb">
|
||||
<Link to="/">Groves</Link> / <span>{grove.name}</span>
|
||||
<Link to="/">Projects</Link> / <span>{project.name}</span>
|
||||
</nav>
|
||||
|
||||
<div className="page-header">
|
||||
<div>
|
||||
<h1>{grove.name}</h1>
|
||||
{grove.description && <p className="description">{grove.description}</p>}
|
||||
<h1>{project.name}</h1>
|
||||
{project.description && <p className="description">{project.description}</p>}
|
||||
</div>
|
||||
<button className="btn btn-primary" onClick={() => setShowForm(!showForm)}>
|
||||
{showForm ? 'Cancel' : '+ New Tree'}
|
||||
{showForm ? 'Cancel' : '+ New Package'}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{error && <div className="error-message">{error}</div>}
|
||||
|
||||
{showForm && (
|
||||
<form className="form card" onSubmit={handleCreateTree}>
|
||||
<h3>Create New Tree</h3>
|
||||
<form className="form card" onSubmit={handleCreatePackage}>
|
||||
<h3>Create New Package</h3>
|
||||
<div className="form-group">
|
||||
<label htmlFor="name">Name</label>
|
||||
<input
|
||||
id="name"
|
||||
type="text"
|
||||
value={newTree.name}
|
||||
onChange={(e) => setNewTree({ ...newTree, name: e.target.value })}
|
||||
value={newPackage.name}
|
||||
onChange={(e) => setNewPackage({ ...newPackage, name: e.target.value })}
|
||||
placeholder="releases"
|
||||
required
|
||||
/>
|
||||
@@ -97,30 +97,30 @@ function GrovePage() {
|
||||
<input
|
||||
id="description"
|
||||
type="text"
|
||||
value={newTree.description}
|
||||
onChange={(e) => setNewTree({ ...newTree, description: e.target.value })}
|
||||
value={newPackage.description}
|
||||
onChange={(e) => setNewPackage({ ...newPackage, description: e.target.value })}
|
||||
placeholder="Optional description"
|
||||
/>
|
||||
</div>
|
||||
<button type="submit" className="btn btn-primary" disabled={creating}>
|
||||
{creating ? 'Creating...' : 'Create Tree'}
|
||||
{creating ? 'Creating...' : 'Create Package'}
|
||||
</button>
|
||||
</form>
|
||||
)}
|
||||
|
||||
{trees.length === 0 ? (
|
||||
{packages.length === 0 ? (
|
||||
<div className="empty-state">
|
||||
<p>No trees yet. Create your first tree to start uploading artifacts!</p>
|
||||
<p>No packages yet. Create your first package to start uploading artifacts!</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="grove-grid">
|
||||
{trees.map((tree) => (
|
||||
<Link to={`/grove/${groveName}/${tree.name}`} key={tree.id} className="grove-card card">
|
||||
<h3>📦 {tree.name}</h3>
|
||||
{tree.description && <p>{tree.description}</p>}
|
||||
<div className="grove-meta">
|
||||
<div className="project-grid">
|
||||
{packages.map((pkg) => (
|
||||
<Link to={`/project/${projectName}/${pkg.name}`} key={pkg.id} className="project-card card">
|
||||
<h3>{pkg.name}</h3>
|
||||
{pkg.description && <p>{pkg.description}</p>}
|
||||
<div className="project-meta">
|
||||
<span className="date">
|
||||
Created {new Date(tree.created_at).toLocaleDateString()}
|
||||
Created {new Date(pkg.created_at).toLocaleDateString()}
|
||||
</span>
|
||||
</div>
|
||||
</Link>
|
||||
@@ -131,4 +131,4 @@ function GrovePage() {
|
||||
);
|
||||
}
|
||||
|
||||
export default GrovePage;
|
||||
export default ProjectPage;
|
||||
@@ -1,4 +1,4 @@
|
||||
export interface Grove {
|
||||
export interface Project {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string | null;
|
||||
@@ -8,16 +8,16 @@ export interface Grove {
|
||||
created_by: string;
|
||||
}
|
||||
|
||||
export interface Tree {
|
||||
export interface Package {
|
||||
id: string;
|
||||
grove_id: string;
|
||||
project_id: string;
|
||||
name: string;
|
||||
description: string | null;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
export interface Fruit {
|
||||
export interface Artifact {
|
||||
id: string;
|
||||
size: number;
|
||||
content_type: string | null;
|
||||
@@ -27,27 +27,27 @@ export interface Fruit {
|
||||
ref_count: number;
|
||||
}
|
||||
|
||||
export interface Graft {
|
||||
export interface Tag {
|
||||
id: string;
|
||||
tree_id: string;
|
||||
package_id: string;
|
||||
name: string;
|
||||
fruit_id: string;
|
||||
artifact_id: string;
|
||||
created_at: string;
|
||||
created_by: string;
|
||||
}
|
||||
|
||||
export interface Consumer {
|
||||
id: string;
|
||||
tree_id: string;
|
||||
package_id: string;
|
||||
project_url: string;
|
||||
last_access: string;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface CultivateResponse {
|
||||
fruit_id: string;
|
||||
export interface UploadResponse {
|
||||
artifact_id: string;
|
||||
size: number;
|
||||
grove: string;
|
||||
tree: string;
|
||||
project: string;
|
||||
package: string;
|
||||
tag: string | null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user