bridge-compile

1.0.38 • Public • Published

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-compile

This will automatically generate:

  • TypeScript SDK in ./sdk/ directory
  • Swift SDK as ./sdk.swift file
  • 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:8080

Swift 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 APIError type
  • 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: "john@example.com"
))

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")
}

Package Sidebar

Install

npm i bridge-compile

Homepage

bridge.codes

Weekly Downloads

0

Version

1.0.38

License

MIT

Unpacked Size

156 kB

Total Files

75

Last publish

Collaborators

  • nabil-stw