bridge-compile
v1.0.38
Published
Compile the sdk of your Bridge project with one command locally
Downloads
94
Maintainers
Readme
Bridge Studio
Compile a completely typed sdk of your Bridge project with one command.
Features
- TypeScript SDK Generation: Generates a TypeScript SDK with typed API methods
- Swift SDK Generation: Generates a Swift SDK with async/await support and proper error handling
- OpenAPI Specification: Automatically generates OpenAPI documentation
Usage
Run the compiler in your Bridge project:
npx bridge-compileThis will automatically generate:
- TypeScript SDK in
./sdk/directory - Swift SDK as
./sdk.swiftfile - OpenAPI documentation as
./openapi.json
You'll only be prompted for your server URL if no configuration file exists.
Configuration
You can create a bridge.config.json file to avoid the server URL prompt:
{
"serverUrl": "http://localhost:8080"
}You can also pass the server URL as a command line argument:
npx bridge-compile http://localhost:8080Swift SDK
The Swift SDK generates a single sdk.swift file that includes:
- Foundation networking code with async/await support
- Strongly typed request/response models
- Error handling with custom
APIErrortype - Support for GET, POST, PUT, PATCH, DELETE methods
- Query parameters, headers, and body support
Swift SDK Structure
// Base networking layer
struct APIError: Error { ... }
struct Result<T: Decodable> { ... }
func fetch<R: Decodable>(...) async -> Result<R> { ... }
// Generated API classes
class User {
struct CreateBody: Encodable { ... }
struct CreateResponse: Decodable { ... }
func create(body: CreateBody) async -> Result<CreateResponse> { ... }
}
// Main API entry point
public class API {
let user = User()
}Using the Swift SDK
let api = API()
// Create a user
let result = await api.user.create(body: User.CreateBody(
name: User.CreateBody.Name(first: "John", last: "Doe"),
email: "[email protected]"
))
switch result {
case let (data?, nil):
print("User created: \(data.user.name)")
case let (nil, error?):
print("Error: \(error.name) - \(error.status)")
default:
print("Unknown error")
}