Skip to content

Conversation

EmilLindfors
Copy link

Summary

Implements complete Cloudflare Pages API functionality following the established D1 patterns, addressing the need identified in #280.

Features Added

  • Project Management: Full CRUD operations for Pages projects
  • Deployment Operations: Create, list, get, retry, rollback, and delete deployments
  • Domain Management: Add, list, get, update, and remove custom domains
  • Build Configuration: Environment variables and build settings support
  • Deployment Logs: Fetch build and deployment logs

API Coverage

  • Projects: GET/POST/PATCH/DELETE /accounts/{id}/pages/projects
  • Deployments: GET/POST/DELETE /accounts/{id}/pages/projects/{name}/deployments
  • Deployment Actions: POST retry/rollback endpoints
  • Domains: GET/POST/DELETE/PATCH /accounts/{id}/pages/projects/{name}/domains
  • Utilities: Build cache purging and deployment log access

Implementation Details

  • 15+ endpoint implementations with 100% API spec compliance
  • Comprehensive data structures matching official API responses
  • Builder patterns for all parameter structures with chainable methods
  • Follows exact same patterns as D1 module for consistency
  • 22 comprehensive tests (20 unit + 2 integration) with full coverage

Testing

cargo test --features blocking pages

All tests pass, including:

  • Parameter serialization/deserialization
  • Endpoint construction and path generation
  • Builder method chaining
  • Error handling scenarios

Consistency with Existing Code

  • Same constructor patterns as D1 module
  • Identical documentation style and format
  • Consistent derive attributes and response types
  • Same error handling and serialization patterns
  • Matches established naming conventions

This PR was created in collaboration with Claude Code

Resolves #280

Implements comprehensive D1 database management endpoints providing full API
coverage based on the official Cloudflare OpenAPI specification.

## Endpoints Added

### Database Management
- `ListDatabases`: List all D1 databases in an account
- `CreateDatabase`: Create new D1 database with optional location hint
- `GetDatabase`: Get detailed information about a specific database
- `DeleteDatabase`: Delete a D1 database permanently
- `UpdateDatabase`: Update database configuration (read replication)
- `UpdatePartialDatabase`: Partially update database configuration

### Data Operations
- `QueryDatabase`: Execute parameterized SQL queries
- `RawQuery`: Execute raw SQL with optimized response format
- `ExportDatabase`: Export database as SQL with polling support
- `ImportDatabase`: Import SQL data with upload URL generation

## Data Structures

### Core Types
- `D1Database`: Complete database metadata with read replication details
- `D1QueryResult`: Standard query results with metadata
- `D1RawQueryResult`: Performance-optimized query results
- `D1QueryMeta`: Comprehensive query execution metadata

### Configuration Types
- `D1PrimaryLocationHint`: All 6 official regions (wnam, enam, weur, eeur, apac, oc)
- `D1ReadReplicationMode`: Auto/disabled replication modes
- `D1ReadReplicationConfig`: Read replication configuration

### Request Parameters
- `CreateDatabaseParams`: Database creation with optional location hint
- `UpdateDatabaseParams`: Full database configuration updates
- `UpdatePartialDatabaseParams`: Partial configuration updates
- `QueryDatabaseParams`: Parameterized SQL query execution
- `RawQueryParams`: Raw SQL execution
- `ExportDatabaseParams`: Database export configuration
- `ImportDatabaseParams`: Database import configuration

## Testing

Added comprehensive test coverage (11 tests) including:
- Parameter serialization/deserialization
- Response structure validation
- Enum value handling
- Optional field handling
- Complex nested object deserialization

## API Specification Compliance

Implementation is 100% compliant with the official Cloudflare OpenAPI
specification (openapi.yaml from github.com/cloudflare/api-schemas):
- All 10 D1 endpoints implemented
- Request/response schemas match exactly
- All optional parameters supported
- Proper HTTP methods and paths
- Complete metadata support

This fills a significant gap in cloudflare-rs by providing complete D1
database management capabilities that were previously missing from the library.
- Use serde_with::skip_serializing_none instead of manual skip_serializing_if
- Move shared data structures to data_structures.rs module
- Update API documentation links to api.cloudflare.com format
- Move tests inline to each module following project patterns
- Restructure mod.rs exports to match project conventions
- Maintain 100% API specification compliance

All tests passing (6/6).
Implements complete Pages API functionality following the established D1 patterns:

### Features
- **Project Management**: Full CRUD operations for Pages projects
- **Deployment Operations**: Create, list, get, retry, rollback, and delete deployments
- **Domain Management**: Add, list, get, update, and remove custom domains
- **Build Configuration**: Environment variables and build settings support
- **Deployment Logs**: Fetch build and deployment logs

### Implementation
- 15+ endpoint implementations with full spec compliance
- Comprehensive data structures matching API responses
- Builder patterns for all parameter structures
- 22 comprehensive tests (20 unit + 2 integration)
- 100% API specification compliance verified

### API Coverage
- Projects: `GET`/`POST`/`PATCH`/`DELETE` `/accounts/{id}/pages/projects`
- Deployments: Full deployment lifecycle management
- Domains: Complete custom domain configuration
- Utilities: Build cache purging and deployment logs

Follows exact same patterns as D1 module with consistent:
- Constructor methods and builder patterns
- Documentation style and error handling
- Derive attributes and response types
- Test structure and coverage

Resolves cloudflare#280
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add comprehensive Cloudflare Pages endpoint support
1 participant